pi-spi-sdk 0.1.1 → 0.1.3

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.
Files changed (114) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +36 -8
  3. package/dist/config.js +2 -1
  4. package/dist/error-handler.js +11 -8
  5. package/dist/errors.js +13 -5
  6. package/dist/examples.js +11 -9
  7. package/dist/generated/core/ApiError.js +5 -1
  8. package/dist/generated/core/ApiRequestOptions.js +2 -1
  9. package/dist/generated/core/ApiResult.js +2 -1
  10. package/dist/generated/core/CancelablePromise.js +7 -2
  11. package/dist/generated/core/OpenAPI.js +4 -1
  12. package/dist/generated/core/request.js +75 -52
  13. package/dist/generated/index.js +82 -39
  14. package/dist/generated/models/AliasCreationReponse.js +2 -1
  15. package/dist/generated/models/AliasCreationRequest.js +2 -1
  16. package/dist/generated/models/AliasReponseListe.js +2 -1
  17. package/dist/generated/models/AnnulationStatut.js +5 -2
  18. package/dist/generated/models/Champs.js +2 -1
  19. package/dist/generated/models/CompteOperation.js +5 -2
  20. package/dist/generated/models/CompteOperationListe.js +2 -1
  21. package/dist/generated/models/CompteSolde.js +5 -2
  22. package/dist/generated/models/CompteTransfertIntraReponse.js +5 -2
  23. package/dist/generated/models/CompteTransfertIntraRequest.js +2 -1
  24. package/dist/generated/models/DemandePaiementConfirmationAnnulationRaison.js +5 -2
  25. package/dist/generated/models/DemandePaiementConfirmationReponse.js +5 -2
  26. package/dist/generated/models/DemandePaiementConfirmationRequest.js +2 -1
  27. package/dist/generated/models/DemandePaiementConfirmationRequestAccepter.js +2 -1
  28. package/dist/generated/models/DemandePaiementConfirmationRequestRejeter.js +2 -1
  29. package/dist/generated/models/DemandePaiementConsultationReponse.js +5 -2
  30. package/dist/generated/models/DemandePaiementEnMasseConfirmationRequest.js +2 -1
  31. package/dist/generated/models/DemandePaiementEnMasseConfirmationRequestAccepter.js +2 -1
  32. package/dist/generated/models/DemandePaiementEnMasseConfirmationRequestRejeter.js +2 -1
  33. package/dist/generated/models/DemandePaiementEnMasseRequest.js +2 -1
  34. package/dist/generated/models/DemandePaiementEnMasseStatutReponse.js +5 -2
  35. package/dist/generated/models/DemandePaiementListe.js +2 -1
  36. package/dist/generated/models/DemandePaiementListeItem.js +5 -2
  37. package/dist/generated/models/DemandePaiementReponse.js +2 -1
  38. package/dist/generated/models/DemandePaiementReponseRequest.js +5 -2
  39. package/dist/generated/models/DemandePaiementRequest.js +5 -2
  40. package/dist/generated/models/DemandePaiementRequestBase.js +2 -1
  41. package/dist/generated/models/DemandePaiementRequestCategorie.js +5 -2
  42. package/dist/generated/models/DemandePaiementStatut.js +5 -2
  43. package/dist/generated/models/DemandePaiementStatutRaison.js +5 -2
  44. package/dist/generated/models/ListeMeta.js +2 -1
  45. package/dist/generated/models/Paiement.js +5 -2
  46. package/dist/generated/models/PaiementAnnulationMotif.js +5 -2
  47. package/dist/generated/models/PaiementAnnulationReponseRequest.js +2 -1
  48. package/dist/generated/models/PaiementAnnulationReponseRequestAccepter.js +2 -1
  49. package/dist/generated/models/PaiementAnnulationReponseRequestRejeter.js +2 -1
  50. package/dist/generated/models/PaiementAnnulationRequest.js +2 -1
  51. package/dist/generated/models/PaiementAnnulationStatutRaison.js +5 -2
  52. package/dist/generated/models/PaiementEnMasseConfirmationRequest.js +2 -1
  53. package/dist/generated/models/PaiementEnMasseConfirmationRequestAccepter.js +2 -1
  54. package/dist/generated/models/PaiementEnMasseConfirmationRequestRejeter.js +2 -1
  55. package/dist/generated/models/PaiementEnMasseReponseStatut.js +5 -2
  56. package/dist/generated/models/PaiementEnMasseRequest.js +2 -1
  57. package/dist/generated/models/PaiementImmediatConfirmationReponse.js +5 -2
  58. package/dist/generated/models/PaiementImmediatConfirmationRequest.js +2 -1
  59. package/dist/generated/models/PaiementImmediatConfirmationRequestAccepter.js +2 -1
  60. package/dist/generated/models/PaiementImmediatConfirmationRequestRejeter.js +2 -1
  61. package/dist/generated/models/PaiementImmediatReponse.js +5 -2
  62. package/dist/generated/models/PaiementImmediatRequest.js +2 -1
  63. package/dist/generated/models/PaiementListe.js +2 -1
  64. package/dist/generated/models/PaiementRequest.js +2 -1
  65. package/dist/generated/models/PaiementStatut.js +5 -2
  66. package/dist/generated/models/PaiementStatutRaison.js +5 -2
  67. package/dist/generated/models/Problem7807.js +2 -1
  68. package/dist/generated/models/RefDocType.js +5 -2
  69. package/dist/generated/models/RetourStatut.js +5 -2
  70. package/dist/generated/models/RetourStatutRaison.js +5 -2
  71. package/dist/generated/models/WebhookCreationRequest.js +2 -1
  72. package/dist/generated/models/WebhookCreationResponse.js +2 -1
  73. package/dist/generated/models/WebhookData.js +2 -1
  74. package/dist/generated/models/WebhookEvent.js +5 -2
  75. package/dist/generated/models/WebhookEventsList.js +2 -1
  76. package/dist/generated/models/WebhookList.js +2 -1
  77. package/dist/generated/models/WebhookModificationRequest.js +2 -1
  78. package/dist/generated/models/WebhooksEvents.js +5 -2
  79. package/dist/generated/services/AliasService.js +10 -6
  80. package/dist/generated/services/ComptesService.js +10 -6
  81. package/dist/generated/services/DemandeAnnulationService.js +9 -5
  82. package/dist/generated/services/DemandesDePaiementEnMasseService.js +10 -6
  83. package/dist/generated/services/DemandesDePaiementService.js +12 -8
  84. package/dist/generated/services/NotificationService.js +12 -8
  85. package/dist/generated/services/PaiementEnMasseService.js +10 -6
  86. package/dist/generated/services/PaiementImmediatService.js +12 -8
  87. package/dist/generated/services/RetoursdeFondsService.js +8 -4
  88. package/dist/index.d.ts +1 -0
  89. package/dist/index.js +57 -8
  90. package/dist/qrcode/index.d.ts +62 -0
  91. package/dist/qrcode/index.js +541 -0
  92. package/dist/qrcode/logo.d.ts +3 -0
  93. package/dist/qrcode/logo.js +142 -0
  94. package/dist/query-builder.js +5 -1
  95. package/dist/sdk.d.ts +16 -0
  96. package/dist/sdk.js +81 -41
  97. package/dist/services/alias.d.ts +7 -3
  98. package/dist/services/alias.js +13 -15
  99. package/dist/services/base.d.ts +12 -1
  100. package/dist/services/base.js +54 -4
  101. package/dist/services/comptes.js +6 -2
  102. package/dist/services/demandes-annulation.js +6 -2
  103. package/dist/services/demandes-paiement-en-masse.d.ts +4 -110
  104. package/dist/services/demandes-paiement-en-masse.js +21 -116
  105. package/dist/services/demandes-paiement.d.ts +5 -1
  106. package/dist/services/demandes-paiement.js +7 -5
  107. package/dist/services/paiements-en-masse.js +6 -2
  108. package/dist/services/paiements.js +6 -2
  109. package/dist/services/retours-fonds.js +6 -2
  110. package/dist/services/webhooks.js +6 -2
  111. package/dist/types/alias.js +12 -7
  112. package/dist/utils/constants.js +12 -9
  113. package/dist/utils/index.js +20 -9
  114. package/package.json +23 -19
package/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.1.3] - 2026-06-26
8
+
9
+ ### Fixed
10
+
11
+ - Publish a CommonJS build so Node.js apps (e.g. NestJS) can `require('pi-spi-sdk')` without `ERR_PACKAGE_PATH_NOT_EXPORTED`
12
+ - Add dual `import` / `require` package exports for bundlers and Node runtimes
13
+ - Wire alias and payment-request service wrappers to the PI-SPI HTTP API instead of throwing placeholder errors
14
+ - Include generated OpenAPI client code in the TypeScript build output
15
+
7
16
  ## [0.1.0] - 2024-12-28
8
17
 
9
18
  [0.1.0]: https://github.com/lomiafrica/lomi./releases/tag/pi-spi-sdk-v0.1.0
package/README.md CHANGED
@@ -4,8 +4,7 @@
4
4
 
5
5
  The Interoperable Platform for the Instant Payment System (π-SPI) is a regional payment infrastructure designed and operated by the Central Bank of West African States (BCEAO).
6
6
 
7
- It enables instant fund transfers between different financial institutions across the region, including banks, electronic money issuers, microfinance institutions, and payment establishments.
8
-
7
+ It enables instant fund transfers between different financial institutions across the region, including banks, electronic money issuers, microfinance institutions, and payment service providers.
9
8
 
10
9
  ## Installation
11
10
 
@@ -16,13 +15,12 @@ npm install pi-spi-sdk
16
15
  # or
17
16
  yarn add pi-spi-sdk
18
17
  ```
19
- π-SPI enables **cross-border transactions** within the West African Economic and Monetary Union (UEMOA), which spans eight countries: Benin, Burkina Faso, Côte d'Ivoire, Guinea-Bissau, Mali, Niger, Senegal, and Togo.
20
18
 
21
- The infrastructure operates on a single currency, the XOF (West African CFA Franc), and processes payments in real-time with instant confirmation. Users can send payments using alias-based methods, which means they don't need to share their actual account numbers.
19
+ π-SPI operates on a single currency, the XOF (West African CFA Franc), and processes payments in real-time with instant confirmation. It also enables **cross-border transactions** within the West African Economic and Monetary Union (UEMOA), which spans eight countries: Benin, Burkina Faso, Côte d'Ivoire, Guinea-Bissau, Mali, Niger, Senegal, and Togo.
22
20
 
23
- **Transaction types supported:**
21
+ Payments can flow between traditional bank accounts across UEMOA countries, from bank accounts to mobile money wallets like MTN, Orange Money, and Moov, from mobile wallets back to bank accounts, and even between mobile money wallets regardless of which provider each person uses.
24
22
 
25
- π-SPI supports seamless interoperability between different payment systems throughout the region. Payments can flow between traditional bank accounts across UEMOA countries, from bank accounts to mobile money wallets like MTN, Orange Money, and Moov, from mobile wallets back to bank accounts, and even between mobile money wallets regardless of which provider each person uses. All these transaction types work seamlessly through the unified infrastructure, enabling businesses and individuals to send and receive payments across different financial institutions and mobile money providers within the UEMOA region.
23
+ To use this SDK in a production ready application, you need to be connected to a certified PI-SPI participant or PSP.
26
24
 
27
25
  ## Usage example
28
26
 
@@ -30,7 +28,7 @@ The infrastructure operates on a single currency, the XOF (West African CFA Fran
30
28
  import { PiSpiSDK } from 'pi-spi-sdk';
31
29
 
32
30
  const sdk = new PiSpiSDK({
33
- baseUrl: 'https://sandbox.api.pi-bceao.com/piz/v1',
31
+ baseUrl: 'https://sandbox.api.pi-spi.bceao.int/piz/v1',
34
32
  accessToken: 'your-oauth2-access-token',
35
33
  });
36
34
 
@@ -48,7 +46,7 @@ const payment = await sdk.paiements.create({
48
46
 
49
47
  ## Features
50
48
 
51
- This SDK provides full TypeScript support with types generated from the official OpenAPI specification, ensuring type safety throughout your integration. It includes secure authentication through OAuth2 and mTLS, comprehensive coverage of all SPI endpoints, and custom error classes with detailed messages for easier debugging. The codebase is auto-generated from the official specification and includes developer-friendly utilities and constants to streamline your implementation.
49
+ This SDK provides full TypeScript support with types generated from the official OpenAPI specification, ensuring type safety throughout your integration. It includes secure authentication through OAuth2 and mTLS, comprehensive coverage of all SPI endpoints, and custom error classes with detailed messages for easier debugging. The codebase also includes developer-friendly utilities and constants to streamline your implementation.
52
50
 
53
51
  ## Utilities & Constants
54
52
 
@@ -162,6 +160,36 @@ await sdk.paiements.list({
162
160
  });
163
161
  ```
164
162
 
163
+ #### QR Codes
164
+
165
+ Generate EMV-compliant QR codes directly from the SDK.
166
+
167
+ ```typescript
168
+ // Generate raw payload string
169
+ const payload = sdk.qr.payload({
170
+ alias: '3497a720-ab11-4973-9619-534e04f263a1',
171
+ countryCode: 'CI',
172
+ qrType: 'STATIC',
173
+ referenceLabel: 'MA_BOUTIQUE_01',
174
+ });
175
+
176
+ // Generate SVG with official PI-SPI logo
177
+ const svg = await sdk.qr.svg({
178
+ alias: '3497a720-ab11-4973-9619-534e04f263a1',
179
+ countryCode: 'CI',
180
+ qrType: 'DYNAMIC',
181
+ referenceLabel: 'TX-12345',
182
+ amount: 5000
183
+ }, { size: 300 });
184
+
185
+ // Validate external QR code content
186
+ const check = sdk.qr.validate(someQrString);
187
+ if (check.valid) {
188
+ console.log("Valid QR for:", check.data?.alias);
189
+ }
190
+ ```
191
+
192
+
165
193
  #### Aliases
166
194
 
167
195
  ```typescript
package/dist/config.js CHANGED
@@ -1,4 +1,5 @@
1
+ "use strict";
1
2
  /**
2
3
  * PI-SPI SDK Configuration
3
4
  */
4
- export {};
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +1,14 @@
1
+ "use strict";
1
2
  /**
2
3
  * Error handler utility for converting API errors to SDK errors
3
4
  */
4
- import { PiSpiError, PiSpiValidationError, PiSpiAuthError, PiSpiNotFoundError, PiSpiRateLimitError, } from './errors';
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handleApiError = handleApiError;
7
+ const errors_1 = require("./errors");
5
8
  /**
6
9
  * Convert a generated API error to a SDK error
7
10
  */
8
- export function handleApiError(error) {
11
+ function handleApiError(error) {
9
12
  // Check if it's an ApiError-like object (from generated code)
10
13
  const isApiError = error &&
11
14
  typeof error === 'object' &&
@@ -24,28 +27,28 @@ export function handleApiError(error) {
24
27
  // Handle validation errors (400)
25
28
  if (status === 400) {
26
29
  const invalidParams = body?.invalidParams || body?.errors;
27
- throw new PiSpiValidationError(detail || title || 'Validation error', status, apiError.statusText, invalidParams, type, detail);
30
+ throw new errors_1.PiSpiValidationError(detail || title || 'Validation error', status, apiError.statusText, invalidParams, type, detail);
28
31
  }
29
32
  // Handle authentication errors (401)
30
33
  if (status === 401) {
31
- throw new PiSpiAuthError(detail || title || 'Authentication failed', status, apiError.statusText);
34
+ throw new errors_1.PiSpiAuthError(detail || title || 'Authentication failed', status, apiError.statusText);
32
35
  }
33
36
  // Handle forbidden errors (403)
34
37
  if (status === 403) {
35
- throw new PiSpiError(detail || title || 'Forbidden', status, apiError.statusText, type, detail, instance);
38
+ throw new errors_1.PiSpiError(detail || title || 'Forbidden', status, apiError.statusText, type, detail, instance);
36
39
  }
37
40
  // Handle not found errors (404)
38
41
  if (status === 404) {
39
- throw new PiSpiNotFoundError(detail || title || 'Resource not found', status, apiError.statusText);
42
+ throw new errors_1.PiSpiNotFoundError(detail || title || 'Resource not found', status, apiError.statusText);
40
43
  }
41
44
  // Handle rate limit errors (429)
42
45
  if (status === 429) {
43
46
  // Retry-After header would be in the response, but ApiError doesn't expose it
44
47
  // This can be enhanced if needed
45
- throw new PiSpiRateLimitError(detail || title || 'Rate limit exceeded', status, apiError.statusText);
48
+ throw new errors_1.PiSpiRateLimitError(detail || title || 'Rate limit exceeded', status, apiError.statusText);
46
49
  }
47
50
  // Handle other errors
48
- throw new PiSpiError(detail || title || apiError.message || 'API error', status, apiError.statusText, type, detail, instance);
51
+ throw new errors_1.PiSpiError(detail || title || apiError.message || 'API error', status, apiError.statusText, type, detail, instance);
49
52
  }
50
53
  // Re-throw if it's not an API error
51
54
  throw error;
package/dist/errors.js CHANGED
@@ -1,7 +1,10 @@
1
+ "use strict";
1
2
  /**
2
3
  * Custom error classes for PI-SPI SDK
3
4
  */
4
- export class PiSpiError extends Error {
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PiSpiRateLimitError = exports.PiSpiNotFoundError = exports.PiSpiAuthError = exports.PiSpiValidationError = exports.PiSpiError = void 0;
7
+ class PiSpiError extends Error {
5
8
  constructor(message, statusCode, statusText, type, detail, instance) {
6
9
  super(message);
7
10
  this.name = 'PiSpiError';
@@ -12,29 +15,34 @@ export class PiSpiError extends Error {
12
15
  this.instance = instance;
13
16
  }
14
17
  }
15
- export class PiSpiValidationError extends PiSpiError {
18
+ exports.PiSpiError = PiSpiError;
19
+ class PiSpiValidationError extends PiSpiError {
16
20
  constructor(message, statusCode, statusText, errors, type, detail) {
17
21
  super(message, statusCode, statusText, type, detail);
18
22
  this.name = 'PiSpiValidationError';
19
23
  this.errors = errors;
20
24
  }
21
25
  }
22
- export class PiSpiAuthError extends PiSpiError {
26
+ exports.PiSpiValidationError = PiSpiValidationError;
27
+ class PiSpiAuthError extends PiSpiError {
23
28
  constructor(message, statusCode, statusText) {
24
29
  super(message, statusCode, statusText);
25
30
  this.name = 'PiSpiAuthError';
26
31
  }
27
32
  }
28
- export class PiSpiNotFoundError extends PiSpiError {
33
+ exports.PiSpiAuthError = PiSpiAuthError;
34
+ class PiSpiNotFoundError extends PiSpiError {
29
35
  constructor(message, statusCode, statusText) {
30
36
  super(message, statusCode, statusText);
31
37
  this.name = 'PiSpiNotFoundError';
32
38
  }
33
39
  }
34
- export class PiSpiRateLimitError extends PiSpiError {
40
+ exports.PiSpiNotFoundError = PiSpiNotFoundError;
41
+ class PiSpiRateLimitError extends PiSpiError {
35
42
  constructor(message, statusCode, statusText, retryAfter) {
36
43
  super(message, statusCode, statusText);
37
44
  this.name = 'PiSpiRateLimitError';
38
45
  this.retryAfter = retryAfter;
39
46
  }
40
47
  }
48
+ exports.PiSpiRateLimitError = PiSpiRateLimitError;
package/dist/examples.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  /**
2
3
  * Usage Examples for PI-SPI SDK
3
4
  *
@@ -5,9 +6,10 @@
5
6
  *
6
7
  * @see {@link https://developers.pi-bceao.com} Official PI-SPI Documentation
7
8
  */
8
- import { PiSpiSDK, QueryBuilder, AliasType } from './index';
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ const index_1 = require("./index");
9
11
  // Initialize the SDK
10
- const sdk = new PiSpiSDK({
12
+ const sdk = new index_1.PiSpiSDK({
11
13
  baseUrl: 'https://sandbox.api.pi-bceao.com/piz/v1',
12
14
  accessToken: process.env.PI_SPI_ACCESS_TOKEN,
13
15
  });
@@ -29,19 +31,19 @@ async function createAliasExample() {
29
31
  // Create SHID alias (available for all client types)
30
32
  const shidAlias = await sdk.alias.create({
31
33
  compte: 'CIC2344256727788288822',
32
- type: AliasType.SHID,
34
+ type: index_1.AliasType.SHID,
33
35
  });
34
36
  // Returns: { cle: '8b1b2499-3e50-435b-b757-ac7a83d8aa7f', type: 'SHID', ... }
35
37
  // Create MCOD alias (business clients only)
36
38
  const mcodAlias = await sdk.alias.create({
37
39
  compte: 'SNC2344256727788288822',
38
- type: AliasType.MCOD,
40
+ type: index_1.AliasType.MCOD,
39
41
  });
40
42
  // Returns: { cle: 'SNF00_2E4TY', type: 'MCOD', ... }
41
43
  }
42
44
  // Example: Query builder usage
43
45
  async function queryExample() {
44
- const query = new QueryBuilder()
46
+ const query = new index_1.QueryBuilder()
45
47
  .filter('statut', 'eq', 'IRREVOCABLE')
46
48
  .filter('montant', 'gte', 150000) // 1,500 XOF minimum
47
49
  .sort('-dateCreation')
@@ -61,7 +63,7 @@ async function createPaymentExample() {
61
63
  });
62
64
  }
63
65
  // Example: Error handling
64
- import { PiSpiError, PiSpiValidationError, PiSpiAuthError } from './index';
66
+ const index_2 = require("./index");
65
67
  async function errorHandlingExample() {
66
68
  try {
67
69
  await sdk.paiements.create({
@@ -72,13 +74,13 @@ async function errorHandlingExample() {
72
74
  });
73
75
  }
74
76
  catch (error) {
75
- if (error instanceof PiSpiValidationError) {
77
+ if (error instanceof index_2.PiSpiValidationError) {
76
78
  console.error('Validation error:', error.errors);
77
79
  }
78
- else if (error instanceof PiSpiAuthError) {
80
+ else if (error instanceof index_2.PiSpiAuthError) {
79
81
  console.error('Authentication error:', error.message);
80
82
  }
81
- else if (error instanceof PiSpiError) {
83
+ else if (error instanceof index_2.PiSpiError) {
82
84
  console.error('API error:', error.message, error.statusCode);
83
85
  }
84
86
  else if (error instanceof Error) {
@@ -1,4 +1,7 @@
1
- export class ApiError extends Error {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiError = void 0;
4
+ class ApiError extends Error {
2
5
  constructor(request, response, message) {
3
6
  super(message);
4
7
  this.name = 'ApiError';
@@ -9,3 +12,4 @@ export class ApiError extends Error {
9
12
  this.request = request;
10
13
  }
11
14
  }
15
+ exports.ApiError = ApiError;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
3
  if (kind === "m") throw new TypeError("Private method is not writable");
3
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -10,11 +11,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
12
  };
12
13
  var _CancelablePromise_isResolved, _CancelablePromise_isRejected, _CancelablePromise_isCancelled, _CancelablePromise_cancelHandlers, _CancelablePromise_promise, _CancelablePromise_resolve, _CancelablePromise_reject;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.CancelablePromise = exports.CancelError = void 0;
13
16
  /* generated using openapi-typescript-codegen -- do not edit */
14
17
  /* istanbul ignore file */
15
18
  /* tslint:disable */
16
19
  /* eslint-disable */
17
- export class CancelError extends Error {
20
+ class CancelError extends Error {
18
21
  constructor(message) {
19
22
  super(message);
20
23
  this.name = 'CancelError';
@@ -23,7 +26,8 @@ export class CancelError extends Error {
23
26
  return true;
24
27
  }
25
28
  }
26
- export class CancelablePromise {
29
+ exports.CancelError = CancelError;
30
+ class CancelablePromise {
27
31
  constructor(executor) {
28
32
  _CancelablePromise_isResolved.set(this, void 0);
29
33
  _CancelablePromise_isRejected.set(this, void 0);
@@ -109,3 +113,4 @@ export class CancelablePromise {
109
113
  return __classPrivateFieldGet(this, _CancelablePromise_isCancelled, "f");
110
114
  }
111
115
  }
116
+ exports.CancelablePromise = CancelablePromise;
@@ -1,4 +1,7 @@
1
- export const OpenAPI = {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAPI = void 0;
4
+ exports.OpenAPI = {
2
5
  BASE: 'https://sandbox.api.pi-bceao.com/piz/v1',
3
6
  VERSION: '1.0.0',
4
7
  WITH_CREDENTIALS: false,
@@ -1,21 +1,30 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.request = exports.catchErrorCodes = exports.getResponseBody = exports.getResponseHeader = exports.sendRequest = exports.getRequestBody = exports.getHeaders = exports.resolve = exports.getFormData = exports.getQueryString = exports.base64 = exports.isSuccess = exports.isFormData = exports.isBlob = exports.isStringWithValue = exports.isString = exports.isDefined = void 0;
1
7
  /* generated using openapi-typescript-codegen -- do not edit */
2
8
  /* istanbul ignore file */
3
9
  /* tslint:disable */
4
10
  /* eslint-disable */
5
- import axios from 'axios';
6
- import FormData from 'form-data';
7
- import { ApiError } from './ApiError';
8
- import { CancelablePromise } from './CancelablePromise';
9
- export const isDefined = (value) => {
11
+ const axios_1 = __importDefault(require("axios"));
12
+ const form_data_1 = __importDefault(require("form-data"));
13
+ const ApiError_1 = require("./ApiError");
14
+ const CancelablePromise_1 = require("./CancelablePromise");
15
+ const isDefined = (value) => {
10
16
  return value !== undefined && value !== null;
11
17
  };
12
- export const isString = (value) => {
18
+ exports.isDefined = isDefined;
19
+ const isString = (value) => {
13
20
  return typeof value === 'string';
14
21
  };
15
- export const isStringWithValue = (value) => {
16
- return isString(value) && value !== '';
22
+ exports.isString = isString;
23
+ const isStringWithValue = (value) => {
24
+ return (0, exports.isString)(value) && value !== '';
17
25
  };
18
- export const isBlob = (value) => {
26
+ exports.isStringWithValue = isStringWithValue;
27
+ const isBlob = (value) => {
19
28
  return (typeof value === 'object' &&
20
29
  typeof value.type === 'string' &&
21
30
  typeof value.stream === 'function' &&
@@ -25,13 +34,16 @@ export const isBlob = (value) => {
25
34
  /^(Blob|File)$/.test(value.constructor.name) &&
26
35
  /^(Blob|File)$/.test(value[Symbol.toStringTag]));
27
36
  };
28
- export const isFormData = (value) => {
29
- return value instanceof FormData;
37
+ exports.isBlob = isBlob;
38
+ const isFormData = (value) => {
39
+ return value instanceof form_data_1.default;
30
40
  };
31
- export const isSuccess = (status) => {
41
+ exports.isFormData = isFormData;
42
+ const isSuccess = (status) => {
32
43
  return status >= 200 && status < 300;
33
44
  };
34
- export const base64 = (str) => {
45
+ exports.isSuccess = isSuccess;
46
+ const base64 = (str) => {
35
47
  try {
36
48
  return btoa(str);
37
49
  }
@@ -40,13 +52,14 @@ export const base64 = (str) => {
40
52
  return Buffer.from(str).toString('base64');
41
53
  }
42
54
  };
43
- export const getQueryString = (params) => {
55
+ exports.base64 = base64;
56
+ const getQueryString = (params) => {
44
57
  const qs = [];
45
58
  const append = (key, value) => {
46
59
  qs.push(`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`);
47
60
  };
48
61
  const process = (key, value) => {
49
- if (isDefined(value)) {
62
+ if ((0, exports.isDefined)(value)) {
50
63
  if (Array.isArray(value)) {
51
64
  value.forEach(v => {
52
65
  process(key, v);
@@ -70,6 +83,7 @@ export const getQueryString = (params) => {
70
83
  }
71
84
  return '';
72
85
  };
86
+ exports.getQueryString = getQueryString;
73
87
  const getUrl = (config, options) => {
74
88
  const encoder = config.ENCODE_PATH || encodeURI;
75
89
  const path = options.url
@@ -82,15 +96,15 @@ const getUrl = (config, options) => {
82
96
  });
83
97
  const url = `${config.BASE}${path}`;
84
98
  if (options.query) {
85
- return `${url}${getQueryString(options.query)}`;
99
+ return `${url}${(0, exports.getQueryString)(options.query)}`;
86
100
  }
87
101
  return url;
88
102
  };
89
- export const getFormData = (options) => {
103
+ const getFormData = (options) => {
90
104
  if (options.formData) {
91
- const formData = new FormData();
105
+ const formData = new form_data_1.default();
92
106
  const process = (key, value) => {
93
- if (isString(value) || isBlob(value)) {
107
+ if ((0, exports.isString)(value) || (0, exports.isBlob)(value)) {
94
108
  formData.append(key, value);
95
109
  }
96
110
  else {
@@ -98,7 +112,7 @@ export const getFormData = (options) => {
98
112
  }
99
113
  };
100
114
  Object.entries(options.formData)
101
- .filter(([_, value]) => isDefined(value))
115
+ .filter(([_, value]) => (0, exports.isDefined)(value))
102
116
  .forEach(([key, value]) => {
103
117
  if (Array.isArray(value)) {
104
118
  value.forEach(v => process(key, v));
@@ -111,18 +125,20 @@ export const getFormData = (options) => {
111
125
  }
112
126
  return undefined;
113
127
  };
114
- export const resolve = async (options, resolver) => {
128
+ exports.getFormData = getFormData;
129
+ const resolve = async (options, resolver) => {
115
130
  if (typeof resolver === 'function') {
116
131
  return resolver(options);
117
132
  }
118
133
  return resolver;
119
134
  };
120
- export const getHeaders = async (config, options, formData) => {
135
+ exports.resolve = resolve;
136
+ const getHeaders = async (config, options, formData) => {
121
137
  const [token, username, password, additionalHeaders] = await Promise.all([
122
- resolve(options, config.TOKEN),
123
- resolve(options, config.USERNAME),
124
- resolve(options, config.PASSWORD),
125
- resolve(options, config.HEADERS),
138
+ (0, exports.resolve)(options, config.TOKEN),
139
+ (0, exports.resolve)(options, config.USERNAME),
140
+ (0, exports.resolve)(options, config.PASSWORD),
141
+ (0, exports.resolve)(options, config.HEADERS),
126
142
  ]);
127
143
  const formHeaders = typeof formData?.getHeaders === 'function' && formData?.getHeaders() || {};
128
144
  const headers = Object.entries({
@@ -131,42 +147,44 @@ export const getHeaders = async (config, options, formData) => {
131
147
  ...options.headers,
132
148
  ...formHeaders,
133
149
  })
134
- .filter(([_, value]) => isDefined(value))
150
+ .filter(([_, value]) => (0, exports.isDefined)(value))
135
151
  .reduce((headers, [key, value]) => ({
136
152
  ...headers,
137
153
  [key]: String(value),
138
154
  }), {});
139
- if (isStringWithValue(token)) {
155
+ if ((0, exports.isStringWithValue)(token)) {
140
156
  headers['Authorization'] = `Bearer ${token}`;
141
157
  }
142
- if (isStringWithValue(username) && isStringWithValue(password)) {
143
- const credentials = base64(`${username}:${password}`);
158
+ if ((0, exports.isStringWithValue)(username) && (0, exports.isStringWithValue)(password)) {
159
+ const credentials = (0, exports.base64)(`${username}:${password}`);
144
160
  headers['Authorization'] = `Basic ${credentials}`;
145
161
  }
146
162
  if (options.body !== undefined) {
147
163
  if (options.mediaType) {
148
164
  headers['Content-Type'] = options.mediaType;
149
165
  }
150
- else if (isBlob(options.body)) {
166
+ else if ((0, exports.isBlob)(options.body)) {
151
167
  headers['Content-Type'] = options.body.type || 'application/octet-stream';
152
168
  }
153
- else if (isString(options.body)) {
169
+ else if ((0, exports.isString)(options.body)) {
154
170
  headers['Content-Type'] = 'text/plain';
155
171
  }
156
- else if (!isFormData(options.body)) {
172
+ else if (!(0, exports.isFormData)(options.body)) {
157
173
  headers['Content-Type'] = 'application/json';
158
174
  }
159
175
  }
160
176
  return headers;
161
177
  };
162
- export const getRequestBody = (options) => {
178
+ exports.getHeaders = getHeaders;
179
+ const getRequestBody = (options) => {
163
180
  if (options.body) {
164
181
  return options.body;
165
182
  }
166
183
  return undefined;
167
184
  };
168
- export const sendRequest = async (config, options, url, body, formData, headers, onCancel, axiosClient) => {
169
- const source = axios.CancelToken.source();
185
+ exports.getRequestBody = getRequestBody;
186
+ const sendRequest = async (config, options, url, body, formData, headers, onCancel, axiosClient) => {
187
+ const source = axios_1.default.CancelToken.source();
170
188
  const requestConfig = {
171
189
  url,
172
190
  headers,
@@ -188,22 +206,25 @@ export const sendRequest = async (config, options, url, body, formData, headers,
188
206
  throw error;
189
207
  }
190
208
  };
191
- export const getResponseHeader = (response, responseHeader) => {
209
+ exports.sendRequest = sendRequest;
210
+ const getResponseHeader = (response, responseHeader) => {
192
211
  if (responseHeader) {
193
212
  const content = response.headers[responseHeader];
194
- if (isString(content)) {
213
+ if ((0, exports.isString)(content)) {
195
214
  return content;
196
215
  }
197
216
  }
198
217
  return undefined;
199
218
  };
200
- export const getResponseBody = (response) => {
219
+ exports.getResponseHeader = getResponseHeader;
220
+ const getResponseBody = (response) => {
201
221
  if (response.status !== 204) {
202
222
  return response.data;
203
223
  }
204
224
  return undefined;
205
225
  };
206
- export const catchErrorCodes = (options, result) => {
226
+ exports.getResponseBody = getResponseBody;
227
+ const catchErrorCodes = (options, result) => {
207
228
  const errors = {
208
229
  400: 'Bad Request',
209
230
  401: 'Unauthorized',
@@ -216,7 +237,7 @@ export const catchErrorCodes = (options, result) => {
216
237
  };
217
238
  const error = errors[result.status];
218
239
  if (error) {
219
- throw new ApiError(options, result, error);
240
+ throw new ApiError_1.ApiError(options, result, error);
220
241
  }
221
242
  if (!result.ok) {
222
243
  const errorStatus = result.status ?? 'unknown';
@@ -229,9 +250,10 @@ export const catchErrorCodes = (options, result) => {
229
250
  return undefined;
230
251
  }
231
252
  })();
232
- throw new ApiError(options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`);
253
+ throw new ApiError_1.ApiError(options, result, `Generic Error: status: ${errorStatus}; status text: ${errorStatusText}; body: ${errorBody}`);
233
254
  }
234
255
  };
256
+ exports.catchErrorCodes = catchErrorCodes;
235
257
  /**
236
258
  * Request method
237
259
  * @param config The OpenAPI configuration object
@@ -240,25 +262,25 @@ export const catchErrorCodes = (options, result) => {
240
262
  * @returns CancelablePromise<T>
241
263
  * @throws ApiError
242
264
  */
243
- export const request = (config, options, axiosClient = axios) => {
244
- return new CancelablePromise(async (resolve, reject, onCancel) => {
265
+ const request = (config, options, axiosClient = axios_1.default) => {
266
+ return new CancelablePromise_1.CancelablePromise(async (resolve, reject, onCancel) => {
245
267
  try {
246
268
  const url = getUrl(config, options);
247
- const formData = getFormData(options);
248
- const body = getRequestBody(options);
249
- const headers = await getHeaders(config, options, formData);
269
+ const formData = (0, exports.getFormData)(options);
270
+ const body = (0, exports.getRequestBody)(options);
271
+ const headers = await (0, exports.getHeaders)(config, options, formData);
250
272
  if (!onCancel.isCancelled) {
251
- const response = await sendRequest(config, options, url, body, formData, headers, onCancel, axiosClient);
252
- const responseBody = getResponseBody(response);
253
- const responseHeader = getResponseHeader(response, options.responseHeader);
273
+ const response = await (0, exports.sendRequest)(config, options, url, body, formData, headers, onCancel, axiosClient);
274
+ const responseBody = (0, exports.getResponseBody)(response);
275
+ const responseHeader = (0, exports.getResponseHeader)(response, options.responseHeader);
254
276
  const result = {
255
277
  url,
256
- ok: isSuccess(response.status),
278
+ ok: (0, exports.isSuccess)(response.status),
257
279
  status: response.status,
258
280
  statusText: response.statusText,
259
281
  body: responseHeader ?? responseBody,
260
282
  };
261
- catchErrorCodes(options, result);
283
+ (0, exports.catchErrorCodes)(options, result);
262
284
  resolve(result.body);
263
285
  }
264
286
  }
@@ -267,3 +289,4 @@ export const request = (config, options, axiosClient = axios) => {
267
289
  }
268
290
  });
269
291
  };
292
+ exports.request = request;