Skip to content
Snippets Groups Projects
index.ts 3.61 KiB
Newer Older
  • Learn to ignore specific revisions
  • Alexey Lunin's avatar
    Alexey Lunin committed
    import {
      Configuration,
      ConfigurationParameters,
      ActionMenuApi,
      BasicmessageApi,
      ConnectionApi,
      CredentialDefinitionApi,
      CredentialsApi,
      DidExchangeApi,
      DiscoverFeaturesApi,
      DiscoverFeaturesV20Api,
      EndorseTransactionApi,
      IntroductionApi,
      IssueCredentialV10Api,
      IssueCredentialV20Api,
      JsonldApi,
      LedgerApi,
      MediationApi,
      OutOfBandApi,
      PresentProofV10Api,
      PresentProofV20Api,
      ResolverApi,
      RevocationApi,
      SchemaApi,
      ServerApi,
      TrustpingApi,
      WalletApi,
    } from './swagger';
    
    class ApiAcapy {
      public actionMenu: ActionMenuApi;
      public basicmessage: BasicmessageApi;
      public connection: ConnectionApi;
      public credentialDefinition: CredentialDefinitionApi;
      public credentials: CredentialsApi;
      public didExchange: DidExchangeApi;
      public discoverFeatures: DiscoverFeaturesApi;
      public discoverFeaturesV20: DiscoverFeaturesV20Api;
      public endorseTransaction: EndorseTransactionApi;
      public introduction: IntroductionApi;
      public issueCredentialV10: IssueCredentialV10Api;
      public issueCredentialV20: IssueCredentialV20Api;
      public jsonld: JsonldApi;
      public ledger: LedgerApi;
      public mediation: MediationApi;
      public outOfBand: OutOfBandApi;
      public presentProofV10: PresentProofV10Api;
      public presentProofV20: PresentProofV20Api;
      public resolver: ResolverApi;
      public revocation: RevocationApi;
      public schema: SchemaApi;
      public server: ServerApi;
      public trustping: TrustpingApi;
      public wallet: WalletApi;
    
      constructor() {
    
      }
    
      public initialize = (getAccessToken: () => Promise<string>, baseUrl: string, subdomain: string) => {
        const cfg = new Configuration();
    
        const fetchPatched = async (url: string, init?: any) => {
          init = Object.assign({}, init);
          Object.assign(init.headers, {
            Authorization: `Bearer ${await getAccessToken()}`,
            'Agent-Domain': subdomain
          })
          return fetch(url, init);
        };
    
        this.actionMenu = new ActionMenuApi(cfg, baseUrl, fetchPatched);
        this.basicmessage = new BasicmessageApi(cfg, baseUrl, fetchPatched);
        this.connection = new ConnectionApi(cfg, baseUrl, fetchPatched);
        this.credentialDefinition = new CredentialDefinitionApi(cfg, baseUrl, fetchPatched);
        this.credentials = new CredentialsApi(cfg, baseUrl, fetchPatched);
        this.didExchange = new DidExchangeApi(cfg, baseUrl, fetchPatched);
        this.discoverFeatures = new DiscoverFeaturesApi(cfg, baseUrl, fetchPatched);
        this.discoverFeaturesV20 = new DiscoverFeaturesV20Api(cfg, baseUrl, fetchPatched);
        this.endorseTransaction = new EndorseTransactionApi(cfg, baseUrl, fetchPatched);
        this.introduction = new IntroductionApi(cfg, baseUrl, fetchPatched);
        this.issueCredentialV10 = new IssueCredentialV10Api(cfg, baseUrl, fetchPatched);
        this.issueCredentialV20 = new IssueCredentialV20Api(cfg, baseUrl, fetchPatched);
        this.jsonld = new JsonldApi(cfg, baseUrl, fetchPatched);
        this.ledger = new LedgerApi(cfg, baseUrl, fetchPatched);
        this.mediation = new MediationApi(cfg, baseUrl, fetchPatched);
        this.outOfBand = new OutOfBandApi(cfg, baseUrl, fetchPatched);
        this.presentProofV10 = new PresentProofV10Api(cfg, baseUrl, fetchPatched);
        this.presentProofV20 = new PresentProofV20Api(cfg, baseUrl, fetchPatched);
        this.resolver = new ResolverApi(cfg, baseUrl, fetchPatched);
        this.revocation = new RevocationApi(cfg, baseUrl, fetchPatched);
        this.schema = new SchemaApi(cfg, baseUrl, fetchPatched);
        this.server = new ServerApi(cfg, baseUrl, fetchPatched);
        this.trustping = new TrustpingApi(cfg, baseUrl, fetchPatched);
        this.wallet = new WalletApi(cfg, baseUrl, fetchPatched);
      }
    }
    
    export default new ApiAcapy();