@pronesoft-rd/ecf-sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.openapi-generator/FILES +96 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +234 -0
- package/dist/apis/AssociatedCompaniesApi.d.ts +150 -0
- package/dist/apis/AssociatedCompaniesApi.js +229 -0
- package/dist/apis/AuthenticationApi.d.ts +64 -0
- package/dist/apis/AuthenticationApi.js +75 -0
- package/dist/apis/DigitalCertificatesApi.d.ts +70 -0
- package/dist/apis/DigitalCertificatesApi.js +113 -0
- package/dist/apis/ECFSubmissionApi.d.ts +70 -0
- package/dist/apis/ECFSubmissionApi.js +96 -0
- package/dist/apis/TaxSequencesApi.d.ts +152 -0
- package/dist/apis/TaxSequencesApi.js +214 -0
- package/dist/apis/WebhookConfigurationApi.d.ts +146 -0
- package/dist/apis/WebhookConfigurationApi.js +197 -0
- package/dist/apis/index.d.ts +6 -0
- package/dist/apis/index.js +24 -0
- package/dist/esm/apis/AssociatedCompaniesApi.d.ts +150 -0
- package/dist/esm/apis/AssociatedCompaniesApi.js +225 -0
- package/dist/esm/apis/AuthenticationApi.d.ts +64 -0
- package/dist/esm/apis/AuthenticationApi.js +71 -0
- package/dist/esm/apis/DigitalCertificatesApi.d.ts +70 -0
- package/dist/esm/apis/DigitalCertificatesApi.js +109 -0
- package/dist/esm/apis/ECFSubmissionApi.d.ts +70 -0
- package/dist/esm/apis/ECFSubmissionApi.js +92 -0
- package/dist/esm/apis/TaxSequencesApi.d.ts +152 -0
- package/dist/esm/apis/TaxSequencesApi.js +210 -0
- package/dist/esm/apis/WebhookConfigurationApi.d.ts +146 -0
- package/dist/esm/apis/WebhookConfigurationApi.js +193 -0
- package/dist/esm/apis/index.d.ts +6 -0
- package/dist/esm/apis/index.js +8 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/models/AccountType.d.ts +30 -0
- package/dist/esm/models/AccountType.js +48 -0
- package/dist/esm/models/AdditionalInfo.d.ts +50 -0
- package/dist/esm/models/AdditionalInfo.js +47 -0
- package/dist/esm/models/AlternativeCurrency.d.ts +46 -0
- package/dist/esm/models/AlternativeCurrency.js +49 -0
- package/dist/esm/models/AssociatedCompany.d.ts +125 -0
- package/dist/esm/models/AssociatedCompany.js +77 -0
- package/dist/esm/models/AssociatedCompanySubscription.d.ts +45 -0
- package/dist/esm/models/AssociatedCompanySubscription.js +46 -0
- package/dist/esm/models/AssociatedCompanySubscriptionPlan.d.ts +38 -0
- package/dist/esm/models/AssociatedCompanySubscriptionPlan.js +43 -0
- package/dist/esm/models/BillingIndicator.d.ts +34 -0
- package/dist/esm/models/BillingIndicator.js +52 -0
- package/dist/esm/models/Buyer.d.ts +68 -0
- package/dist/esm/models/Buyer.js +55 -0
- package/dist/esm/models/CreateAssociatedCompany201Response.d.ts +39 -0
- package/dist/esm/models/CreateAssociatedCompany201Response.js +44 -0
- package/dist/esm/models/CreateTaxSequenceRequest.d.ts +47 -0
- package/dist/esm/models/CreateTaxSequenceRequest.js +52 -0
- package/dist/esm/models/CreateWebhookConfig.d.ts +53 -0
- package/dist/esm/models/CreateWebhookConfig.js +52 -0
- package/dist/esm/models/DiscountOrSurcharge.d.ts +93 -0
- package/dist/esm/models/DiscountOrSurcharge.js +78 -0
- package/dist/esm/models/EcfSubmissionResponse.d.ts +56 -0
- package/dist/esm/models/EcfSubmissionResponse.js +53 -0
- package/dist/esm/models/ElectronicDocument.d.ts +252 -0
- package/dist/esm/models/ElectronicDocument.js +143 -0
- package/dist/esm/models/Environment.d.ts +30 -0
- package/dist/esm/models/Environment.js +48 -0
- package/dist/esm/models/ErrorResponse.d.ts +44 -0
- package/dist/esm/models/ErrorResponse.js +45 -0
- package/dist/esm/models/GetNextNumber200Response.d.ts +39 -0
- package/dist/esm/models/GetNextNumber200Response.js +44 -0
- package/dist/esm/models/GetNextNumber200ResponseData.d.ts +38 -0
- package/dist/esm/models/GetNextNumber200ResponseData.js +43 -0
- package/dist/esm/models/InvoiceType.d.ts +44 -0
- package/dist/esm/models/InvoiceType.js +62 -0
- package/dist/esm/models/Item.d.ts +106 -0
- package/dist/esm/models/Item.js +83 -0
- package/dist/esm/models/ItemAdditionalTax.d.ts +38 -0
- package/dist/esm/models/ItemAdditionalTax.js +47 -0
- package/dist/esm/models/ListTaxSequences200Response.d.ts +39 -0
- package/dist/esm/models/ListTaxSequences200Response.js +44 -0
- package/dist/esm/models/OAuthTokenRequest.d.ts +43 -0
- package/dist/esm/models/OAuthTokenRequest.js +47 -0
- package/dist/esm/models/OAuthTokenResponse.d.ts +46 -0
- package/dist/esm/models/OAuthTokenResponse.js +45 -0
- package/dist/esm/models/Page.d.ts +116 -0
- package/dist/esm/models/Page.js +75 -0
- package/dist/esm/models/PaymentMethod.d.ts +40 -0
- package/dist/esm/models/PaymentMethod.js +58 -0
- package/dist/esm/models/PrintFormat.d.ts +30 -0
- package/dist/esm/models/PrintFormat.js +48 -0
- package/dist/esm/models/ReferenceInfo.d.ts +76 -0
- package/dist/esm/models/ReferenceInfo.js +63 -0
- package/dist/esm/models/Subquantity.d.ts +38 -0
- package/dist/esm/models/Subquantity.js +47 -0
- package/dist/esm/models/Subtotal.d.ts +110 -0
- package/dist/esm/models/Subtotal.js +71 -0
- package/dist/esm/models/TaxSequence.d.ts +45 -0
- package/dist/esm/models/TaxSequence.js +46 -0
- package/dist/esm/models/Totals.d.ts +173 -0
- package/dist/esm/models/Totals.js +90 -0
- package/dist/esm/models/Transport.d.ts +62 -0
- package/dist/esm/models/Transport.js +51 -0
- package/dist/esm/models/UploadCertificate201Response.d.ts +44 -0
- package/dist/esm/models/UploadCertificate201Response.js +45 -0
- package/dist/esm/models/UploadCertificateResponse.d.ts +44 -0
- package/dist/esm/models/UploadCertificateResponse.js +45 -0
- package/dist/esm/models/WebhookConfigResponse.d.ts +63 -0
- package/dist/esm/models/WebhookConfigResponse.js +52 -0
- package/dist/esm/models/WebhookEventType.d.ts +40 -0
- package/dist/esm/models/WebhookEventType.js +58 -0
- package/dist/esm/models/WebhookNotificationPayload.d.ts +59 -0
- package/dist/esm/models/WebhookNotificationPayload.js +60 -0
- package/dist/esm/models/index.d.ts +37 -0
- package/dist/esm/models/index.js +39 -0
- package/dist/esm/runtime.d.ts +184 -0
- package/dist/esm/runtime.js +349 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +21 -0
- package/dist/models/AccountType.d.ts +30 -0
- package/dist/models/AccountType.js +56 -0
- package/dist/models/AdditionalInfo.d.ts +50 -0
- package/dist/models/AdditionalInfo.js +54 -0
- package/dist/models/AlternativeCurrency.d.ts +46 -0
- package/dist/models/AlternativeCurrency.js +56 -0
- package/dist/models/AssociatedCompany.d.ts +125 -0
- package/dist/models/AssociatedCompany.js +85 -0
- package/dist/models/AssociatedCompanySubscription.d.ts +45 -0
- package/dist/models/AssociatedCompanySubscription.js +53 -0
- package/dist/models/AssociatedCompanySubscriptionPlan.d.ts +38 -0
- package/dist/models/AssociatedCompanySubscriptionPlan.js +50 -0
- package/dist/models/BillingIndicator.d.ts +34 -0
- package/dist/models/BillingIndicator.js +60 -0
- package/dist/models/Buyer.d.ts +68 -0
- package/dist/models/Buyer.js +62 -0
- package/dist/models/CreateAssociatedCompany201Response.d.ts +39 -0
- package/dist/models/CreateAssociatedCompany201Response.js +51 -0
- package/dist/models/CreateTaxSequenceRequest.d.ts +47 -0
- package/dist/models/CreateTaxSequenceRequest.js +59 -0
- package/dist/models/CreateWebhookConfig.d.ts +53 -0
- package/dist/models/CreateWebhookConfig.js +59 -0
- package/dist/models/DiscountOrSurcharge.d.ts +93 -0
- package/dist/models/DiscountOrSurcharge.js +86 -0
- package/dist/models/EcfSubmissionResponse.d.ts +56 -0
- package/dist/models/EcfSubmissionResponse.js +60 -0
- package/dist/models/ElectronicDocument.d.ts +252 -0
- package/dist/models/ElectronicDocument.js +151 -0
- package/dist/models/Environment.d.ts +30 -0
- package/dist/models/Environment.js +56 -0
- package/dist/models/ErrorResponse.d.ts +44 -0
- package/dist/models/ErrorResponse.js +52 -0
- package/dist/models/GetNextNumber200Response.d.ts +39 -0
- package/dist/models/GetNextNumber200Response.js +51 -0
- package/dist/models/GetNextNumber200ResponseData.d.ts +38 -0
- package/dist/models/GetNextNumber200ResponseData.js +50 -0
- package/dist/models/InvoiceType.d.ts +44 -0
- package/dist/models/InvoiceType.js +70 -0
- package/dist/models/Item.d.ts +106 -0
- package/dist/models/Item.js +91 -0
- package/dist/models/ItemAdditionalTax.d.ts +38 -0
- package/dist/models/ItemAdditionalTax.js +54 -0
- package/dist/models/ListTaxSequences200Response.d.ts +39 -0
- package/dist/models/ListTaxSequences200Response.js +51 -0
- package/dist/models/OAuthTokenRequest.d.ts +43 -0
- package/dist/models/OAuthTokenRequest.js +54 -0
- package/dist/models/OAuthTokenResponse.d.ts +46 -0
- package/dist/models/OAuthTokenResponse.js +52 -0
- package/dist/models/Page.d.ts +116 -0
- package/dist/models/Page.js +82 -0
- package/dist/models/PaymentMethod.d.ts +40 -0
- package/dist/models/PaymentMethod.js +66 -0
- package/dist/models/PrintFormat.d.ts +30 -0
- package/dist/models/PrintFormat.js +56 -0
- package/dist/models/ReferenceInfo.d.ts +76 -0
- package/dist/models/ReferenceInfo.js +71 -0
- package/dist/models/Subquantity.d.ts +38 -0
- package/dist/models/Subquantity.js +54 -0
- package/dist/models/Subtotal.d.ts +110 -0
- package/dist/models/Subtotal.js +78 -0
- package/dist/models/TaxSequence.d.ts +45 -0
- package/dist/models/TaxSequence.js +53 -0
- package/dist/models/Totals.d.ts +173 -0
- package/dist/models/Totals.js +97 -0
- package/dist/models/Transport.d.ts +62 -0
- package/dist/models/Transport.js +58 -0
- package/dist/models/UploadCertificate201Response.d.ts +44 -0
- package/dist/models/UploadCertificate201Response.js +52 -0
- package/dist/models/UploadCertificateResponse.d.ts +44 -0
- package/dist/models/UploadCertificateResponse.js +52 -0
- package/dist/models/WebhookConfigResponse.d.ts +63 -0
- package/dist/models/WebhookConfigResponse.js +59 -0
- package/dist/models/WebhookEventType.d.ts +40 -0
- package/dist/models/WebhookEventType.js +66 -0
- package/dist/models/WebhookNotificationPayload.d.ts +59 -0
- package/dist/models/WebhookNotificationPayload.js +67 -0
- package/dist/models/index.d.ts +37 -0
- package/dist/models/index.js +55 -0
- package/dist/runtime.d.ts +184 -0
- package/dist/runtime.js +365 -0
- package/docs/AccountType.md +33 -0
- package/docs/AdditionalInfo.md +41 -0
- package/docs/AlternativeCurrency.md +39 -0
- package/docs/AssociatedCompaniesApi.md +207 -0
- package/docs/AssociatedCompany.md +63 -0
- package/docs/AssociatedCompanySubscription.md +38 -0
- package/docs/AssociatedCompanySubscriptionPlan.md +36 -0
- package/docs/AuthenticationApi.md +77 -0
- package/docs/BillingIndicator.md +33 -0
- package/docs/Buyer.md +47 -0
- package/docs/CreateAssociatedCompany201Response.md +36 -0
- package/docs/CreateTaxSequenceRequest.md +39 -0
- package/docs/CreateWebhookConfig.md +41 -0
- package/docs/DigitalCertificatesApi.md +90 -0
- package/docs/DiscountOrSurcharge.md +49 -0
- package/docs/ECFSubmissionApi.md +90 -0
- package/docs/EcfSubmissionResponse.md +43 -0
- package/docs/ElectronicDocument.md +87 -0
- package/docs/Environment.md +33 -0
- package/docs/ErrorResponse.md +39 -0
- package/docs/GetNextNumber200Response.md +36 -0
- package/docs/GetNextNumber200ResponseData.md +36 -0
- package/docs/InvoiceType.md +33 -0
- package/docs/Item.md +55 -0
- package/docs/ItemAdditionalTax.md +37 -0
- package/docs/ListTaxSequences200Response.md +36 -0
- package/docs/OAuthTokenRequest.md +37 -0
- package/docs/OAuthTokenResponse.md +39 -0
- package/docs/Page.md +63 -0
- package/docs/PaymentMethod.md +33 -0
- package/docs/PrintFormat.md +33 -0
- package/docs/ReferenceInfo.md +43 -0
- package/docs/Subquantity.md +37 -0
- package/docs/Subtotal.md +61 -0
- package/docs/TaxSequence.md +39 -0
- package/docs/TaxSequencesApi.md +246 -0
- package/docs/Totals.md +81 -0
- package/docs/Transport.md +45 -0
- package/docs/UploadCertificate201Response.md +38 -0
- package/docs/UploadCertificateResponse.md +39 -0
- package/docs/WebhookConfigResponse.md +45 -0
- package/docs/WebhookConfigurationApi.md +241 -0
- package/docs/WebhookEventType.md +33 -0
- package/docs/WebhookNotificationPayload.md +43 -0
- package/package.json +21 -0
- package/src/apis/AssociatedCompaniesApi.ts +415 -0
- package/src/apis/AuthenticationApi.ts +122 -0
- package/src/apis/DigitalCertificatesApi.ts +175 -0
- package/src/apis/ECFSubmissionApi.ts +163 -0
- package/src/apis/TaxSequencesApi.ts +374 -0
- package/src/apis/WebhookConfigurationApi.ts +332 -0
- package/src/apis/index.ts +8 -0
- package/src/index.ts +5 -0
- package/src/models/AccountType.ts +58 -0
- package/src/models/AdditionalInfo.ts +89 -0
- package/src/models/AlternativeCurrency.ts +85 -0
- package/src/models/AssociatedCompany.ts +196 -0
- package/src/models/AssociatedCompanySubscription.ts +89 -0
- package/src/models/AssociatedCompanySubscriptionPlan.ts +73 -0
- package/src/models/BillingIndicator.ts +62 -0
- package/src/models/Buyer.ts +114 -0
- package/src/models/CreateAssociatedCompany201Response.ts +81 -0
- package/src/models/CreateTaxSequenceRequest.ts +96 -0
- package/src/models/CreateWebhookConfig.ts +101 -0
- package/src/models/DiscountOrSurcharge.ts +155 -0
- package/src/models/EcfSubmissionResponse.ts +99 -0
- package/src/models/ElectronicDocument.ts +421 -0
- package/src/models/Environment.ts +58 -0
- package/src/models/ErrorResponse.ts +81 -0
- package/src/models/GetNextNumber200Response.ts +81 -0
- package/src/models/GetNextNumber200ResponseData.ts +73 -0
- package/src/models/InvoiceType.ts +72 -0
- package/src/models/Item.ts +187 -0
- package/src/models/ItemAdditionalTax.ts +75 -0
- package/src/models/ListTaxSequences200Response.ts +81 -0
- package/src/models/OAuthTokenRequest.ts +80 -0
- package/src/models/OAuthTokenResponse.ts +83 -0
- package/src/models/Page.ts +180 -0
- package/src/models/PaymentMethod.ts +68 -0
- package/src/models/PrintFormat.ts +58 -0
- package/src/models/ReferenceInfo.ts +122 -0
- package/src/models/Subquantity.ts +75 -0
- package/src/models/Subtotal.ts +171 -0
- package/src/models/TaxSequence.ts +91 -0
- package/src/models/Totals.ts +260 -0
- package/src/models/Transport.ts +105 -0
- package/src/models/UploadCertificate201Response.ts +81 -0
- package/src/models/UploadCertificateResponse.ts +81 -0
- package/src/models/WebhookConfigResponse.ts +113 -0
- package/src/models/WebhookEventType.ts +68 -0
- package/src/models/WebhookNotificationPayload.ts +114 -0
- package/src/models/index.ts +39 -0
- package/src/runtime.ts +450 -0
- package/tsconfig.esm.json +7 -0
- package/tsconfig.json +16 -0
package/src/runtime.ts
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* eCF-Pronesoft Integration API
|
|
5
|
+
* ## Overview Production-grade API for issuing Electronic Tax Receipts (e-CF) in the Dominican Republic through the Pronesoft platform, which handles all communication with the DGII on your behalf. ## Authentication — OAuth 2.0 Client Credentials This API uses the **OAuth 2.0 Client Credentials** flow. There is no user login — authentication is machine-to-machine using a `clientId` and `clientSecret` issued by the Pronesoft portal. ### Step-by-step 1. **Get credentials**: - Sandbox: https://ecf.sandbox.pronesoft.com - Production: https://ecf.pronesoft.com 2. **Request a token** — call `POST /oauth/token` with your credentials. The server returns an `accessToken` valid for `expiresIn` seconds. 3. **Authorize requests** — include the token in every subsequent request: ``` Authorization: Bearer <accessToken> ``` 4. **Identify your tenant** — include your company/branch UUID in every protected request: ``` x-tenant-id: <your-tenant-uuid> ``` 5. **Refresh** — when the token expires, simply call `POST /oauth/token` again. ### Scopes | Category | Scope | Description | |---|---|---| | **Business** | `business:read` | Read company data | | | `business:create` | Create a new company | | | `business:update` | Update company data | | **Members** | `members:read` | View team members | | | `members:invite` | Invite new members | | | `members:revoke` | Revoke member access | | **Certificates** | `certificates:read` | View digital certificates | | | `certificates:upload` | Upload new certificates | | | `certificates:update` | Update existing certificates | | **Documents** | `documents:read` | List and view documents | | | `documents:create` | Create drafts or internal documents | | | `documents:send` | Submit e-CF to DGII | | | `documents:receive` | Receive e-CF from third parties | | | `documents:update` | Modify document metadata | | **Approvals** | `approvals:read` | View approval statuses | | | `approvals:commercial` | Perform commercial approvals/rejections | | **Sequences** | `sequences:read` | View NCF/e-NCF ranges | | | `sequences:create` | Request new sequences | | | `sequences:update` | Modify sequence configurations | | | `sequences:cancel` | Cancel unused sequences | | **Dashboard** | `business_info:read` | Access dashboard stats and metrics | | **Certification** | `certification:read` | View certification progress | | | `certification:write` | Run automated DGII certification tests | | **Reports** | `reports:read` | Generate and export reports (e.g. 606) | ## Environments | Environment | Portal | API Host | Purpose | |---|---|---|---| | Sandbox | https://ecf.sandbox.pronesoft.com | `api.ecf.sandbox.pronesoft.com` | Development & testing | | Production | https://ecf.pronesoft.com | `api.ecf.pronesoft.com` | Live e-CF issuance | ## Invoice Types (e-NCF) | Code | Name | |---|---| | `31` | Tax Credit Invoice (Factura de Crédito Fiscal) | | `32` | Consumer Invoice (Factura de Consumo) | | `33` | Debit Note (Nota de Débito) | | `34` | Credit Note (Nota de Crédito) | | `41` | Purchases (Compras) | | `43` | Minor Expenses (Gastos Menores) | | `44` | Special Regimes (Regímenes Especiales) | | `45` | Governmental (Gubernamentales) | | `46` | Exports (Exportaciones) | | `47` | Overseas Payments (Pagos al Exterior) |
|
|
6
|
+
*
|
|
7
|
+
* The version of the OpenAPI document: 0.0.1
|
|
8
|
+
* Contact: contacto@pronesoft.com
|
|
9
|
+
*
|
|
10
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
11
|
+
* https://openapi-generator.tech
|
|
12
|
+
* Do not edit the class manually.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const BASE_PATH = "https://api.ecf.sandbox.pronesoft.com/api/v1".replace(/\/+$/, "");
|
|
17
|
+
|
|
18
|
+
export interface ConfigurationParameters {
|
|
19
|
+
basePath?: string; // override base path
|
|
20
|
+
fetchApi?: FetchAPI; // override for fetch implementation
|
|
21
|
+
middleware?: Middleware[]; // middleware to apply before/after fetch requests
|
|
22
|
+
queryParamsStringify?: (params: HTTPQuery) => string; // stringify function for query strings
|
|
23
|
+
username?: string; // parameter for basic security
|
|
24
|
+
password?: string; // parameter for basic security
|
|
25
|
+
apiKey?: string | Promise<string> | ((name: string) => string | Promise<string>); // parameter for apiKey security
|
|
26
|
+
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string | Promise<string>); // parameter for oauth2 security
|
|
27
|
+
headers?: HTTPHeaders; //header params we want to use on every request
|
|
28
|
+
credentials?: RequestCredentials; //value for the credentials param we want to use on each request
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class Configuration {
|
|
32
|
+
constructor(private configuration: ConfigurationParameters = {}) {}
|
|
33
|
+
|
|
34
|
+
set config(configuration: Configuration) {
|
|
35
|
+
this.configuration = configuration;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get basePath(): string {
|
|
39
|
+
return this.configuration.basePath != null ? this.configuration.basePath : BASE_PATH;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get fetchApi(): FetchAPI | undefined {
|
|
43
|
+
return this.configuration.fetchApi;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get middleware(): Middleware[] {
|
|
47
|
+
return this.configuration.middleware || [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get queryParamsStringify(): (params: HTTPQuery) => string {
|
|
51
|
+
return this.configuration.queryParamsStringify || querystring;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get username(): string | undefined {
|
|
55
|
+
return this.configuration.username;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get password(): string | undefined {
|
|
59
|
+
return this.configuration.password;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get apiKey(): ((name: string) => string | Promise<string>) | undefined {
|
|
63
|
+
const apiKey = this.configuration.apiKey;
|
|
64
|
+
if (apiKey) {
|
|
65
|
+
return typeof apiKey === 'function' ? apiKey : () => apiKey;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get accessToken(): ((name?: string, scopes?: string[]) => string | Promise<string>) | undefined {
|
|
71
|
+
const accessToken = this.configuration.accessToken;
|
|
72
|
+
if (accessToken) {
|
|
73
|
+
return typeof accessToken === 'function' ? accessToken : async () => accessToken;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get headers(): HTTPHeaders | undefined {
|
|
79
|
+
return this.configuration.headers;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get credentials(): RequestCredentials | undefined {
|
|
83
|
+
return this.configuration.credentials;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const DefaultConfig = new Configuration();
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* This is the base class for all generated API classes.
|
|
91
|
+
*/
|
|
92
|
+
export class BaseAPI {
|
|
93
|
+
|
|
94
|
+
private static readonly jsonRegex = new RegExp('^(:?application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(:?;.*)?$', 'i');
|
|
95
|
+
private middleware: Middleware[];
|
|
96
|
+
|
|
97
|
+
constructor(protected configuration = DefaultConfig) {
|
|
98
|
+
this.middleware = configuration.middleware;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
withMiddleware<T extends BaseAPI>(this: T, ...middlewares: Middleware[]) {
|
|
102
|
+
const next = this.clone<T>();
|
|
103
|
+
next.middleware = next.middleware.concat(...middlewares);
|
|
104
|
+
return next;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
withPreMiddleware<T extends BaseAPI>(this: T, ...preMiddlewares: Array<Middleware['pre']>) {
|
|
108
|
+
const middlewares = preMiddlewares.map((pre) => ({ pre }));
|
|
109
|
+
return this.withMiddleware<T>(...middlewares);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
withPostMiddleware<T extends BaseAPI>(this: T, ...postMiddlewares: Array<Middleware['post']>) {
|
|
113
|
+
const middlewares = postMiddlewares.map((post) => ({ post }));
|
|
114
|
+
return this.withMiddleware<T>(...middlewares);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Check if the given MIME is a JSON MIME.
|
|
119
|
+
* JSON MIME examples:
|
|
120
|
+
* application/json
|
|
121
|
+
* application/json; charset=UTF8
|
|
122
|
+
* APPLICATION/JSON
|
|
123
|
+
* application/vnd.company+json
|
|
124
|
+
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
|
125
|
+
* @return True if the given MIME is JSON, false otherwise.
|
|
126
|
+
*/
|
|
127
|
+
protected isJsonMime(mime: string | null | undefined): boolean {
|
|
128
|
+
if (!mime) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
return BaseAPI.jsonRegex.test(mime);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
protected async request(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction): Promise<Response> {
|
|
135
|
+
const { url, init } = await this.createFetchParams(context, initOverrides);
|
|
136
|
+
const response = await this.fetchApi(url, init);
|
|
137
|
+
if (response && (response.status >= 200 && response.status < 300)) {
|
|
138
|
+
return response;
|
|
139
|
+
}
|
|
140
|
+
throw new ResponseError(response, 'Response returned an error code');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private async createFetchParams(context: RequestOpts, initOverrides?: RequestInit | InitOverrideFunction) {
|
|
144
|
+
let url = this.configuration.basePath + context.path;
|
|
145
|
+
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
146
|
+
// only add the querystring to the URL if there are query parameters.
|
|
147
|
+
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
148
|
+
// do not handle correctly sometimes.
|
|
149
|
+
url += '?' + this.configuration.queryParamsStringify(context.query);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const headers = Object.assign({}, this.configuration.headers, context.headers);
|
|
153
|
+
Object.keys(headers).forEach(key => headers[key] === undefined ? delete headers[key] : {});
|
|
154
|
+
|
|
155
|
+
const initOverrideFn =
|
|
156
|
+
typeof initOverrides === "function"
|
|
157
|
+
? initOverrides
|
|
158
|
+
: async () => initOverrides;
|
|
159
|
+
|
|
160
|
+
const initParams = {
|
|
161
|
+
method: context.method,
|
|
162
|
+
headers,
|
|
163
|
+
body: context.body,
|
|
164
|
+
credentials: this.configuration.credentials,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const overriddenInit: RequestInit = {
|
|
168
|
+
...initParams,
|
|
169
|
+
...(await initOverrideFn({
|
|
170
|
+
init: initParams,
|
|
171
|
+
context,
|
|
172
|
+
}))
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
let body: any;
|
|
176
|
+
if (isFormData(overriddenInit.body)
|
|
177
|
+
|| (overriddenInit.body instanceof URLSearchParams)
|
|
178
|
+
|| isBlob(overriddenInit.body)) {
|
|
179
|
+
body = overriddenInit.body;
|
|
180
|
+
} else if (this.isJsonMime(headers['Content-Type'])) {
|
|
181
|
+
body = JSON.stringify(overriddenInit.body);
|
|
182
|
+
} else {
|
|
183
|
+
body = overriddenInit.body;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const init: RequestInit = {
|
|
187
|
+
...overriddenInit,
|
|
188
|
+
body
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
return { url, init };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private fetchApi = async (url: string, init: RequestInit) => {
|
|
195
|
+
let fetchParams = { url, init };
|
|
196
|
+
for (const middleware of this.middleware) {
|
|
197
|
+
if (middleware.pre) {
|
|
198
|
+
fetchParams = await middleware.pre({
|
|
199
|
+
fetch: this.fetchApi,
|
|
200
|
+
...fetchParams,
|
|
201
|
+
}) || fetchParams;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
let response: Response | undefined = undefined;
|
|
205
|
+
try {
|
|
206
|
+
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
|
|
207
|
+
} catch (e) {
|
|
208
|
+
for (const middleware of this.middleware) {
|
|
209
|
+
if (middleware.onError) {
|
|
210
|
+
response = await middleware.onError({
|
|
211
|
+
fetch: this.fetchApi,
|
|
212
|
+
url: fetchParams.url,
|
|
213
|
+
init: fetchParams.init,
|
|
214
|
+
error: e,
|
|
215
|
+
response: response ? response.clone() : undefined,
|
|
216
|
+
}) || response;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (response === undefined) {
|
|
220
|
+
if (e instanceof Error) {
|
|
221
|
+
throw new FetchError(e, 'The request failed and the interceptors did not return an alternative response');
|
|
222
|
+
} else {
|
|
223
|
+
throw e;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for (const middleware of this.middleware) {
|
|
228
|
+
if (middleware.post) {
|
|
229
|
+
response = await middleware.post({
|
|
230
|
+
fetch: this.fetchApi,
|
|
231
|
+
url: fetchParams.url,
|
|
232
|
+
init: fetchParams.init,
|
|
233
|
+
response: response.clone(),
|
|
234
|
+
}) || response;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return response;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Create a shallow clone of `this` by constructing a new instance
|
|
242
|
+
* and then shallow cloning data members.
|
|
243
|
+
*/
|
|
244
|
+
private clone<T extends BaseAPI>(this: T): T {
|
|
245
|
+
const constructor = this.constructor as any;
|
|
246
|
+
const next = new constructor(this.configuration);
|
|
247
|
+
next.middleware = this.middleware.slice();
|
|
248
|
+
return next;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
function isBlob(value: any): value is Blob {
|
|
253
|
+
return typeof Blob !== 'undefined' && value instanceof Blob;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function isFormData(value: any): value is FormData {
|
|
257
|
+
return typeof FormData !== "undefined" && value instanceof FormData;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export class ResponseError extends Error {
|
|
261
|
+
override name: "ResponseError" = "ResponseError";
|
|
262
|
+
constructor(public response: Response, msg?: string) {
|
|
263
|
+
super(msg);
|
|
264
|
+
|
|
265
|
+
// restore prototype chain
|
|
266
|
+
const actualProto = new.target.prototype;
|
|
267
|
+
if (Object.setPrototypeOf) {
|
|
268
|
+
Object.setPrototypeOf(this, actualProto);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export class FetchError extends Error {
|
|
274
|
+
override name: "FetchError" = "FetchError";
|
|
275
|
+
constructor(public cause: Error, msg?: string) {
|
|
276
|
+
super(msg);
|
|
277
|
+
|
|
278
|
+
// restore prototype chain
|
|
279
|
+
const actualProto = new.target.prototype;
|
|
280
|
+
if (Object.setPrototypeOf) {
|
|
281
|
+
Object.setPrototypeOf(this, actualProto);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export class RequiredError extends Error {
|
|
287
|
+
override name: "RequiredError" = "RequiredError";
|
|
288
|
+
constructor(public field: string, msg?: string) {
|
|
289
|
+
super(msg);
|
|
290
|
+
|
|
291
|
+
// restore prototype chain
|
|
292
|
+
const actualProto = new.target.prototype;
|
|
293
|
+
if (Object.setPrototypeOf) {
|
|
294
|
+
Object.setPrototypeOf(this, actualProto);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export const COLLECTION_FORMATS = {
|
|
300
|
+
csv: ",",
|
|
301
|
+
ssv: " ",
|
|
302
|
+
tsv: "\t",
|
|
303
|
+
pipes: "|",
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
export type FetchAPI = WindowOrWorkerGlobalScope['fetch'];
|
|
307
|
+
|
|
308
|
+
export type Json = any;
|
|
309
|
+
export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'HEAD';
|
|
310
|
+
export type HTTPHeaders = { [key: string]: string };
|
|
311
|
+
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
|
|
312
|
+
export type HTTPBody = Json | FormData | URLSearchParams;
|
|
313
|
+
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
|
|
314
|
+
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
|
|
315
|
+
|
|
316
|
+
export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
|
|
317
|
+
|
|
318
|
+
export interface FetchParams {
|
|
319
|
+
url: string;
|
|
320
|
+
init: RequestInit;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export interface RequestOpts {
|
|
324
|
+
path: string;
|
|
325
|
+
method: HTTPMethod;
|
|
326
|
+
headers: HTTPHeaders;
|
|
327
|
+
query?: HTTPQuery;
|
|
328
|
+
body?: HTTPBody;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export function querystring(params: HTTPQuery, prefix: string = ''): string {
|
|
332
|
+
return Object.keys(params)
|
|
333
|
+
.map(key => querystringSingleKey(key, params[key], prefix))
|
|
334
|
+
.filter(part => part.length > 0)
|
|
335
|
+
.join('&');
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function querystringSingleKey(key: string, value: string | number | null | undefined | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery, keyPrefix: string = ''): string {
|
|
339
|
+
const fullKey = keyPrefix + (keyPrefix.length ? `[${key}]` : key);
|
|
340
|
+
if (value instanceof Array) {
|
|
341
|
+
const multiValue = value.map(singleValue => encodeURIComponent(String(singleValue)))
|
|
342
|
+
.join(`&${encodeURIComponent(fullKey)}=`);
|
|
343
|
+
return `${encodeURIComponent(fullKey)}=${multiValue}`;
|
|
344
|
+
}
|
|
345
|
+
if (value instanceof Set) {
|
|
346
|
+
const valueAsArray = Array.from(value);
|
|
347
|
+
return querystringSingleKey(key, valueAsArray, keyPrefix);
|
|
348
|
+
}
|
|
349
|
+
if (value instanceof Date) {
|
|
350
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(value.toISOString())}`;
|
|
351
|
+
}
|
|
352
|
+
if (value instanceof Object) {
|
|
353
|
+
return querystring(value as HTTPQuery, fullKey);
|
|
354
|
+
}
|
|
355
|
+
return `${encodeURIComponent(fullKey)}=${encodeURIComponent(String(value))}`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export function exists(json: any, key: string) {
|
|
359
|
+
const value = json[key];
|
|
360
|
+
return value !== null && value !== undefined;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export function mapValues(data: any, fn: (item: any) => any) {
|
|
364
|
+
const result: { [key: string]: any } = {};
|
|
365
|
+
for (const key of Object.keys(data)) {
|
|
366
|
+
result[key] = fn(data[key]);
|
|
367
|
+
}
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function canConsumeForm(consumes: Consume[]): boolean {
|
|
372
|
+
for (const consume of consumes) {
|
|
373
|
+
if ('multipart/form-data' === consume.contentType) {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return false;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface Consume {
|
|
381
|
+
contentType: string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export interface RequestContext {
|
|
385
|
+
fetch: FetchAPI;
|
|
386
|
+
url: string;
|
|
387
|
+
init: RequestInit;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export interface ResponseContext {
|
|
391
|
+
fetch: FetchAPI;
|
|
392
|
+
url: string;
|
|
393
|
+
init: RequestInit;
|
|
394
|
+
response: Response;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface ErrorContext {
|
|
398
|
+
fetch: FetchAPI;
|
|
399
|
+
url: string;
|
|
400
|
+
init: RequestInit;
|
|
401
|
+
error: unknown;
|
|
402
|
+
response?: Response;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export interface Middleware {
|
|
406
|
+
pre?(context: RequestContext): Promise<FetchParams | void>;
|
|
407
|
+
post?(context: ResponseContext): Promise<Response | void>;
|
|
408
|
+
onError?(context: ErrorContext): Promise<Response | void>;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
export interface ApiResponse<T> {
|
|
412
|
+
raw: Response;
|
|
413
|
+
value(): Promise<T>;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export interface ResponseTransformer<T> {
|
|
417
|
+
(json: any): T;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export class JSONApiResponse<T> {
|
|
421
|
+
constructor(public raw: Response, private transformer: ResponseTransformer<T> = (jsonValue: any) => jsonValue) {}
|
|
422
|
+
|
|
423
|
+
async value(): Promise<T> {
|
|
424
|
+
return this.transformer(await this.raw.json());
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export class VoidApiResponse {
|
|
429
|
+
constructor(public raw: Response) {}
|
|
430
|
+
|
|
431
|
+
async value(): Promise<void> {
|
|
432
|
+
return undefined;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
export class BlobApiResponse {
|
|
437
|
+
constructor(public raw: Response) {}
|
|
438
|
+
|
|
439
|
+
async value(): Promise<Blob> {
|
|
440
|
+
return await this.raw.blob();
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export class TextApiResponse {
|
|
445
|
+
constructor(public raw: Response) {}
|
|
446
|
+
|
|
447
|
+
async value(): Promise<string> {
|
|
448
|
+
return await this.raw.text();
|
|
449
|
+
};
|
|
450
|
+
}
|
package/tsconfig.json
ADDED