@factpulse/sdk 3.0.37 → 4.0.0

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 (110) hide show
  1. package/.openapi-generator/FILES +6 -6
  2. package/CHANGELOG.md +10 -13
  3. package/README.md +135 -148
  4. package/api/invoice-processing-api.ts +2 -2
  5. package/dist/esm/models/chorus-pro-credentials.d.ts +19 -7
  6. package/dist/esm/models/chorus-pro-destination.d.ts +2 -2
  7. package/dist/esm/models/{facture-electronique-rest-api-schemas-chorus-pro-chorus-pro-credentials.d.ts → facture-electronique-models-invoice-type-code.d.ts} +63 -18
  8. package/dist/{models/facture-electronique-rest-api-schemas-ereporting-invoice-type-code.js → esm/models/facture-electronique-models-invoice-type-code.js} +66 -10
  9. package/dist/esm/models/{facture-electronique-rest-api-schemas-validation-validation-error-response.d.ts → facture-electronique-rest-api-schemas-cdar-validation-error-response.d.ts} +13 -4
  10. package/dist/esm/models/{facture-electronique-rest-api-schemas-ereporting-invoice-type-code.d.ts → facture-electronique-rest-api-schemas-processing-chorus-pro-credentials.d.ts} +11 -9
  11. package/dist/esm/models/get-chorus-pro-id-request.d.ts +2 -2
  12. package/dist/esm/models/get-invoice-request.d.ts +2 -2
  13. package/dist/esm/models/get-structure-request.d.ts +2 -2
  14. package/dist/esm/models/index.d.ts +3 -3
  15. package/dist/esm/models/index.js +3 -3
  16. package/dist/esm/models/invoice-input.d.ts +2 -2
  17. package/dist/esm/models/invoice-type-code.d.ts +6 -65
  18. package/dist/esm/models/invoice-type-code.js +6 -65
  19. package/dist/esm/models/recipient.d.ts +1 -1
  20. package/dist/esm/models/scheme-id.d.ts +7 -7
  21. package/dist/esm/models/scheme-id.js +7 -7
  22. package/dist/esm/models/search-structure-request.d.ts +2 -2
  23. package/dist/esm/models/simplified-invoice-data.d.ts +2 -2
  24. package/dist/esm/models/submit-complete-invoice-response.d.ts +1 -1
  25. package/dist/esm/models/submit-invoice-request.d.ts +2 -2
  26. package/dist/esm/models/supplier.d.ts +1 -1
  27. package/dist/esm/models/validate-cdarresponse.d.ts +3 -3
  28. package/dist/esm/models/validation-error-response.d.ts +3 -12
  29. package/dist/esm/src/helpers/client.d.ts +43 -265
  30. package/dist/esm/src/helpers/client.js +196 -779
  31. package/dist/esm/src/helpers/index.d.ts +1 -2
  32. package/dist/esm/src/helpers/index.js +1 -3
  33. package/dist/models/chorus-pro-credentials.d.ts +19 -7
  34. package/dist/models/chorus-pro-destination.d.ts +2 -2
  35. package/dist/models/{facture-electronique-rest-api-schemas-chorus-pro-chorus-pro-credentials.d.ts → facture-electronique-models-invoice-type-code.d.ts} +63 -18
  36. package/dist/models/facture-electronique-models-invoice-type-code.js +85 -0
  37. package/dist/models/{facture-electronique-rest-api-schemas-validation-validation-error-response.d.ts → facture-electronique-rest-api-schemas-cdar-validation-error-response.d.ts} +13 -4
  38. package/dist/{esm/models/facture-electronique-rest-api-schemas-ereporting-invoice-type-code.js → models/facture-electronique-rest-api-schemas-processing-chorus-pro-credentials.d.ts} +11 -10
  39. package/dist/models/get-chorus-pro-id-request.d.ts +2 -2
  40. package/dist/models/get-invoice-request.d.ts +2 -2
  41. package/dist/models/get-structure-request.d.ts +2 -2
  42. package/dist/models/index.d.ts +3 -3
  43. package/dist/models/index.js +3 -3
  44. package/dist/models/invoice-input.d.ts +2 -2
  45. package/dist/models/invoice-type-code.d.ts +6 -65
  46. package/dist/models/invoice-type-code.js +6 -65
  47. package/dist/models/recipient.d.ts +1 -1
  48. package/dist/models/scheme-id.d.ts +7 -7
  49. package/dist/models/scheme-id.js +7 -7
  50. package/dist/models/search-structure-request.d.ts +2 -2
  51. package/dist/models/simplified-invoice-data.d.ts +2 -2
  52. package/dist/models/submit-complete-invoice-response.d.ts +1 -1
  53. package/dist/models/submit-invoice-request.d.ts +2 -2
  54. package/dist/models/supplier.d.ts +1 -1
  55. package/dist/models/validate-cdarresponse.d.ts +3 -3
  56. package/dist/models/validation-error-response.d.ts +3 -12
  57. package/dist/src/helpers/client.d.ts +43 -265
  58. package/dist/src/helpers/client.js +199 -823
  59. package/dist/src/helpers/index.d.ts +1 -2
  60. package/dist/src/helpers/index.js +2 -12
  61. package/docs/ChorusProCredentials.md +9 -9
  62. package/docs/ChorusProDestination.md +1 -1
  63. package/docs/FactureElectroniqueModelsInvoiceTypeCode.md +39 -0
  64. package/docs/FactureElectroniqueRestApiSchemasCdarValidationErrorResponse.md +27 -0
  65. package/docs/FactureElectroniqueRestApiSchemasProcessingChorusProCredentials.md +29 -0
  66. package/docs/GetChorusProIdRequest.md +1 -1
  67. package/docs/GetInvoiceRequest.md +1 -1
  68. package/docs/GetStructureRequest.md +1 -1
  69. package/docs/InvoiceInput.md +1 -1
  70. package/docs/InvoiceTypeCode.md +6 -28
  71. package/docs/Recipient.md +1 -1
  72. package/docs/SchemeID.md +4 -4
  73. package/docs/SearchStructureRequest.md +1 -1
  74. package/docs/SimplifiedInvoiceData.md +1 -1
  75. package/docs/SubmitCompleteInvoiceResponse.md +2 -2
  76. package/docs/SubmitInvoiceRequest.md +1 -1
  77. package/docs/Supplier.md +1 -1
  78. package/docs/ValidateCDARResponse.md +2 -2
  79. package/docs/ValidationErrorResponse.md +3 -9
  80. package/models/chorus-pro-credentials.ts +19 -7
  81. package/models/chorus-pro-destination.ts +2 -2
  82. package/models/{facture-electronique-rest-api-schemas-chorus-pro-chorus-pro-credentials.ts → facture-electronique-models-invoice-type-code.ts} +67 -18
  83. package/models/{facture-electronique-rest-api-schemas-validation-validation-error-response.ts → facture-electronique-rest-api-schemas-cdar-validation-error-response.ts} +13 -4
  84. package/models/{facture-electronique-rest-api-schemas-ereporting-invoice-type-code.ts → facture-electronique-rest-api-schemas-processing-chorus-pro-credentials.ts} +11 -13
  85. package/models/get-chorus-pro-id-request.ts +2 -2
  86. package/models/get-invoice-request.ts +2 -2
  87. package/models/get-structure-request.ts +2 -2
  88. package/models/index.ts +3 -3
  89. package/models/invoice-input.ts +2 -2
  90. package/models/invoice-type-code.ts +6 -65
  91. package/models/recipient.ts +1 -1
  92. package/models/scheme-id.ts +7 -7
  93. package/models/search-structure-request.ts +2 -2
  94. package/models/simplified-invoice-data.ts +2 -2
  95. package/models/submit-complete-invoice-response.ts +1 -1
  96. package/models/submit-invoice-request.ts +2 -2
  97. package/models/supplier.ts +1 -1
  98. package/models/validate-cdarresponse.ts +3 -3
  99. package/models/validation-error-response.ts +3 -12
  100. package/package.json +1 -1
  101. package/src/helpers/client.ts +211 -834
  102. package/src/helpers/index.ts +1 -3
  103. package/dist/models/facture-electronique-rest-api-schemas-ereporting-invoice-type-code.d.ts +0 -22
  104. package/docs/FactureElectroniqueRestApiSchemasChorusProChorusProCredentials.md +0 -29
  105. package/docs/FactureElectroniqueRestApiSchemasEreportingInvoiceTypeCode.md +0 -17
  106. package/docs/FactureElectroniqueRestApiSchemasValidationValidationErrorResponse.md +0 -21
  107. /package/dist/esm/models/{facture-electronique-rest-api-schemas-chorus-pro-chorus-pro-credentials.js → facture-electronique-rest-api-schemas-cdar-validation-error-response.js} +0 -0
  108. /package/dist/esm/models/{facture-electronique-rest-api-schemas-validation-validation-error-response.js → facture-electronique-rest-api-schemas-processing-chorus-pro-credentials.js} +0 -0
  109. /package/dist/models/{facture-electronique-rest-api-schemas-chorus-pro-chorus-pro-credentials.js → facture-electronique-rest-api-schemas-cdar-validation-error-response.js} +0 -0
  110. /package/dist/models/{facture-electronique-rest-api-schemas-validation-validation-error-response.js → facture-electronique-rest-api-schemas-processing-chorus-pro-credentials.js} +0 -0
@@ -15,21 +15,21 @@
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.SchemeID = void 0;
17
17
  /**
18
- * Identification scheme codes (Electronic Address Scheme - EAS), mainly for electronic invoice addressing. **Possible values:** - `0225`: FR_SIREN - French SIREN (most common for France) - `0009`: FR_SIRET - French SIRET - `0002`: FR_SIREN_OLD - French SIREN (old code, for legal organization ID) - `0088`: GLN - Global Location Number - `0060`: DUNS - Data Universal Numbering System - `9957`: FR_VAT_INTRA - French intra-community VAT number - `0199`: GLEIF - Global Legal Entity Identifier Foundation - `0231`: DT_DIRECTORY_ID - Directory ID for tax administration - `EM`: EMAIL - Email-based electronic address (BT-34/BT-49)
18
+ * Identification scheme codes (Electronic Address Scheme - EAS). **Electronic Address (routing for PDP/Chorus Pro):** - `0225`: FR_ELECTRONIC_ADDRESS - French electronic billing address (BT-34/BT-49) Format: SIREN or SIREN_SUFFIX (e.g., \"920195229_92019522900017\") **Legal Identifiers (entity identification):** - `0002`: FR_SIREN - French SIREN (9 digits) for BT-30/BT-47 - `0009`: FR_SIRET - French SIRET (14 digits) for BT-29/BT-46 **Other schemes:** - `0088`: GLN - Global Location Number - `0060`: DUNS - Data Universal Numbering System - `9957`: FR_VAT_INTRA - French intra-community VAT number - `0199`: GLEIF - Global Legal Entity Identifier Foundation - `0231`: DT_DIRECTORY_ID - Directory ID for tax administration - `EM`: EMAIL - Email-based electronic address
19
19
  */
20
20
  exports.SchemeID = {
21
21
  /**
22
- * FR_SIREN - French SIREN (most common for France)
22
+ * FR_ELECTRONIC_ADDRESS - French electronic billing address (BT-34/BT-49)
23
23
  */
24
- FR_SIREN: '0225',
24
+ FR_ELECTRONIC_ADDRESS: '0225',
25
25
  /**
26
- * FR_SIRET - French SIRET
26
+ * FR_SIREN - French SIREN (9 digits) - Legal organization ID
27
27
  */
28
- FR_SIRET: '0009',
28
+ FR_SIREN: '0002',
29
29
  /**
30
- * FR_SIREN_OLD - French SIREN (old code, for legal organization ID)
30
+ * FR_SIRET - French SIRET (14 digits) - Establishment ID
31
31
  */
32
- FR_SIREN_OLD: '0002',
32
+ FR_SIRET: '0009',
33
33
  /**
34
34
  * GLN - Global Location Number (GLN)
35
35
  */
@@ -9,12 +9,12 @@
9
9
  * https://openapi-generator.tech
10
10
  * Do not edit the class manually.
11
11
  */
12
- import type { FactureElectroniqueRestApiSchemasChorusProChorusProCredentials } from './facture-electronique-rest-api-schemas-chorus-pro-chorus-pro-credentials';
12
+ import type { ChorusProCredentials } from './chorus-pro-credentials';
13
13
  /**
14
14
  * Search structures by criteria.
15
15
  */
16
16
  export interface SearchStructureRequest {
17
- 'credentials'?: FactureElectroniqueRestApiSchemasChorusProChorusProCredentials | null;
17
+ 'credentials'?: ChorusProCredentials | null;
18
18
  'structureIdentifier'?: string | null;
19
19
  'structureIdentifierType'?: string | null;
20
20
  'companyName'?: string | null;
@@ -9,7 +9,7 @@
9
9
  * https://openapi-generator.tech
10
10
  * Do not edit the class manually.
11
11
  */
12
- import type { InvoiceTypeCode } from './invoice-type-code';
12
+ import type { FactureElectroniqueModelsInvoiceTypeCode } from './facture-electronique-models-invoice-type-code';
13
13
  import type { InvoicingFrameworkCode } from './invoicing-framework-code';
14
14
  import type { OperationNature } from './operation-nature';
15
15
  /**
@@ -49,7 +49,7 @@ export interface SimplifiedInvoiceData {
49
49
  /**
50
50
  * Document type (UNTDID 1001). Default: 380 (Invoice).
51
51
  */
52
- 'invoiceType'?: InvoiceTypeCode;
52
+ 'invoiceType'?: FactureElectroniqueModelsInvoiceTypeCode;
53
53
  'precedingInvoiceReference'?: string | null;
54
54
  'operationNature'?: OperationNature | null;
55
55
  'invoicingFramework'?: InvoicingFrameworkCode | null;
@@ -40,7 +40,7 @@ export interface SubmitCompleteInvoiceResponse {
40
40
  /**
41
41
  * Generated Factur-X PDF (and signed if requested) base64-encoded
42
42
  */
43
- 'pdfBase64': string;
43
+ 'contentB64': string;
44
44
  /**
45
45
  * Return message
46
46
  */
@@ -9,7 +9,7 @@
9
9
  * https://openapi-generator.tech
10
10
  * Do not edit the class manually.
11
11
  */
12
- import type { FactureElectroniqueRestApiSchemasChorusProChorusProCredentials } from './facture-electronique-rest-api-schemas-chorus-pro-chorus-pro-credentials';
12
+ import type { ChorusProCredentials } from './chorus-pro-credentials';
13
13
  import type { SubmitGrossAmount } from './submit-gross-amount';
14
14
  import type { SubmitNetAmount } from './submit-net-amount';
15
15
  import type { SubmitVatAmount } from './submit-vat-amount';
@@ -17,7 +17,7 @@ import type { SubmitVatAmount } from './submit-vat-amount';
17
17
  * Submit an invoice to Chorus Pro.
18
18
  */
19
19
  export interface SubmitInvoiceRequest {
20
- 'credentials'?: FactureElectroniqueRestApiSchemasChorusProChorusProCredentials | null;
20
+ 'credentials'?: ChorusProCredentials | null;
21
21
  /**
22
22
  * Invoice number
23
23
  */
@@ -16,7 +16,7 @@ import type { PostalAddress } from './postal-address';
16
16
  * Information about the supplier / seller (BG-4).
17
17
  */
18
18
  export interface Supplier {
19
- 'electronic_address': ElectronicAddress | null;
19
+ 'electronic_address'?: ElectronicAddress | null;
20
20
  'supplier_id': number;
21
21
  'private_id'?: string | null;
22
22
  'supplier_bank_account_code'?: number | null;
@@ -9,7 +9,7 @@
9
9
  * https://openapi-generator.tech
10
10
  * Do not edit the class manually.
11
11
  */
12
- import type { ValidationErrorResponse } from './validation-error-response';
12
+ import type { FactureElectroniqueRestApiSchemasCdarValidationErrorResponse } from './facture-electronique-rest-api-schemas-cdar-validation-error-response';
13
13
  /**
14
14
  * Réponse de validation CDAR.
15
15
  */
@@ -21,9 +21,9 @@ export interface ValidateCDARResponse {
21
21
  /**
22
22
  * Liste des erreurs
23
23
  */
24
- 'errors'?: Array<ValidationErrorResponse>;
24
+ 'errors'?: Array<FactureElectroniqueRestApiSchemasCdarValidationErrorResponse>;
25
25
  /**
26
26
  * Liste des avertissements
27
27
  */
28
- 'warnings'?: Array<ValidationErrorResponse>;
28
+ 'warnings'?: Array<FactureElectroniqueRestApiSchemasCdarValidationErrorResponse>;
29
29
  }
@@ -10,20 +10,11 @@
10
10
  * Do not edit the class manually.
11
11
  */
12
12
  /**
13
- * Erreur de validation.
13
+ * Response for validation errors.
14
14
  */
15
15
  export interface ValidationErrorResponse {
16
16
  /**
17
- * Champ concerné
17
+ * List of detected validation errors.
18
18
  */
19
- 'field': string;
20
- /**
21
- * Message d\'erreur
22
- */
23
- 'message': string;
24
- 'rule'?: string | null;
25
- /**
26
- * Sévérité (error/warning)
27
- */
28
- 'severity'?: string;
19
+ 'detail': Array<string>;
29
20
  }
@@ -1,278 +1,56 @@
1
- /** Chorus Pro credentials for Zero-Trust mode. */
2
- export interface ChorusProCredentials {
3
- pisteClientId: string;
4
- pisteClientSecret: string;
5
- chorusProLogin: string;
6
- chorusProPassword: string;
7
- sandbox?: boolean;
8
- }
9
- /** AFNOR PDP credentials for Zero-Trust mode. The FactPulse API uses these credentials to authenticate with the AFNOR PDP. */
10
- export interface AFNORCredentials {
11
- flowServiceUrl: string;
12
- tokenUrl: string;
13
- clientId: string;
14
- clientSecret: string;
15
- directoryServiceUrl?: string;
1
+ export declare class FactPulseError extends Error {
2
+ statusCode?: number;
3
+ details?: unknown[];
4
+ constructor(message: string, statusCode?: number, details?: unknown[]);
16
5
  }
17
6
  export interface FactPulseClientConfig {
18
7
  email: string;
19
8
  password: string;
9
+ clientUid: string;
20
10
  apiUrl?: string;
21
- clientUid?: string;
22
- chorusCredentials?: ChorusProCredentials;
23
- afnorCredentials?: AFNORCredentials;
24
- pollingInterval?: number;
11
+ timeout?: number;
25
12
  pollingTimeout?: number;
26
13
  maxRetries?: number;
27
14
  }
28
- type AmountValue = string | number | null | undefined;
29
- /** Converts a value to an amount string for the API. */
30
- export declare function amount(value: AmountValue): string;
31
- /** Creates a simplified InvoiceTotals object. */
32
- export declare function invoiceTotals(exclTax: AmountValue, vat: AmountValue, inclTax: AmountValue, amountDue: AmountValue, options?: {
33
- globalAllowanceAmount?: AmountValue;
34
- globalAllowanceReason?: string;
35
- prepayment?: AmountValue;
36
- }): Record<string, unknown>;
37
- /** Creates an invoice line (aligned with InvoiceLine in models.py).
38
- * For VAT rate: either vatRate (code e.g.: "VAT20") or manualVatRate (value e.g.: 20.00) */
39
- export declare function invoiceLine(lineNumber: number, itemName: string, quantity: AmountValue, unitNetPrice: AmountValue, lineNetAmount: AmountValue, options?: {
40
- vatRate?: string;
41
- manualVatRate?: AmountValue;
42
- vatCategory?: string;
43
- unit?: string;
44
- reference?: string;
45
- lineAllowanceAmount?: AmountValue;
46
- allowanceReasonCode?: string;
47
- allowanceReason?: string;
48
- periodStartDate?: string;
49
- periodEndDate?: string;
50
- }): Record<string, unknown>;
51
- /** Creates a VAT line (aligned with VATLine in models.py).
52
- * For rate: either rate (code e.g.: "VAT20") or manualRate (value e.g.: 20.00) */
53
- export declare function vatLine(taxableAmount: AmountValue, vatAmount: AmountValue, options?: {
54
- rate?: string;
55
- manualRate?: AmountValue;
56
- category?: string;
57
- }): Record<string, unknown>;
58
- /** Creates a postal address for the FactPulse API. */
59
- export declare function postalAddress(lineOne: string, postalCode: string, city: string, options?: {
60
- countryCode?: string;
61
- lineTwo?: string;
62
- lineThree?: string;
63
- }): Record<string, unknown>;
64
- /** Creates an electronic address for the FactPulse API. schemeId: "0009"=SIREN, "0225"=SIRET */
65
- export declare function electronicAddress(identifier: string, schemeId?: string): Record<string, unknown>;
66
- /** Creates a supplier (issuer) with auto-computed SIREN, intra-EU VAT number and addresses. */
67
- export declare function supplier(name: string, siret: string, addressLine1: string, postalCode: string, city: string, options?: {
68
- supplierId?: number;
69
- siren?: string;
70
- vatNumber?: string;
71
- iban?: string;
72
- countryCode?: string;
73
- addressLine2?: string;
74
- supplierServiceId?: number;
75
- supplierBankDetailsCode?: number;
76
- }): Record<string, unknown>;
77
- /** Creates a recipient (customer) with auto-computed SIREN and addresses. */
78
- export declare function recipient(name: string, siret: string, addressLine1: string, postalCode: string, city: string, options?: {
79
- siren?: string;
80
- countryCode?: string;
81
- addressLine2?: string;
82
- executingServiceCode?: string;
83
- }): Record<string, unknown>;
84
- /**
85
- * Creates a beneficiary (factor) for factoring.
86
- *
87
- * The beneficiary (BG-10 / PayeeTradeParty) is used when payment
88
- * must be made to a third party different from the supplier, typically
89
- * a factor (factoring company).
90
- *
91
- * For factored invoices, you also need to:
92
- * - Use a factored document type (393, 396, 501, 502, 472, 473)
93
- * - Add an ACC note with the subrogation mention
94
- * - The beneficiary's IBAN will be used for payment
95
- *
96
- * @param name Factor's business name (BT-59)
97
- * @param options Options: siret (BT-60), siren (BT-61), iban, bic
98
- * @returns Dict ready to be used in a factored invoice
99
- *
100
- * @example
101
- * const factor = beneficiary('FACTOR SAS', {
102
- * siret: '30000000700033',
103
- * iban: 'FR76 3000 4000 0500 0012 3456 789',
104
- * });
105
- */
106
- export declare function beneficiary(name: string, options?: {
107
- siret?: string;
108
- siren?: string;
109
- iban?: string;
110
- bic?: string;
111
- }): Record<string, unknown>;
112
15
  export declare class FactPulseClient {
113
- private config;
114
- private httpClient;
115
- private accessToken;
116
- private refreshToken;
16
+ private readonly apiUrl;
17
+ private readonly email;
18
+ private readonly password;
19
+ private readonly clientUid;
20
+ private readonly timeout;
21
+ private readonly pollingTimeout;
22
+ private readonly httpClient;
23
+ private token;
117
24
  private tokenExpiresAt;
118
- readonly chorusCredentials?: ChorusProCredentials;
119
- readonly afnorCredentials?: AFNORCredentials;
120
25
  constructor(config: FactPulseClientConfig);
121
- getChorusCredentialsForApi(): Record<string, unknown> | undefined;
122
- getAfnorCredentialsForApi(): Record<string, unknown> | undefined;
123
- getChorusProCredentials(): Record<string, unknown> | undefined;
124
- getAfnorCredentials(): Record<string, unknown> | undefined;
125
- private obtainToken;
126
- ensureAuthenticated(forceRefresh?: boolean): Promise<void>;
127
- resetAuth(): void;
128
- pollTask(taskId: string, timeout?: number, interval?: number): Promise<Record<string, unknown>>;
129
- generateFacturx(invoiceData: Record<string, unknown> | string, pdfPath: string, profile?: string, outputFormat?: string, sync?: boolean, timeout?: number): Promise<Buffer | string>;
130
- static formatAmount(m: unknown): string;
131
- /**
132
- * Retrieves AFNOR credentials (stored or zero-trust mode).
133
- * Zero-trust mode: Returns the afnorCredentials provided to the constructor.
134
- * Stored mode: Retrieves credentials via GET /api/v1/afnor/credentials.
135
- */
136
- private getAfnorCredentialsInternal;
137
- /**
138
- * Obtains the AFNOR OAuth2 token and the PDP URL.
139
- * This method:
140
- * 1. Retrieves AFNOR credentials (stored or zero-trust mode)
141
- * 2. Performs AFNOR OAuth to obtain a token
142
- * 3. Returns the token and the PDP URL
143
- */
144
- private getAfnorTokenAndUrl;
145
- /**
146
- * Performs a request to the AFNOR API with auth and error handling.
147
- * IMPORTANT: This method uses the AFNOR OAuth token, NOT the FactPulse JWT!
148
- */
149
- private makeAfnorRequest;
150
- /** Gets a facility by SIRET in the AFNOR directory. */
151
- getSiretAfnor(siret: string): Promise<Record<string, unknown>>;
152
- /** Gets a legal unit by SIREN in the AFNOR directory. */
153
- getSirenAfnor(siren: string): Promise<Record<string, unknown>>;
154
- /** Searches for legal units (SIREN) in the AFNOR directory. */
155
- searchSirenAfnor(options?: {
156
- filters?: Record<string, unknown>;
157
- limit?: number;
158
- }): Promise<Record<string, unknown>>;
159
- /** Searches for routing codes in the AFNOR directory. */
160
- searchRoutingCodesAfnor(options?: {
161
- filters?: Record<string, unknown>;
162
- limit?: number;
163
- }): Promise<Record<string, unknown>>;
164
- /** Gets a routing code by SIRET and routing identifier. */
165
- getRoutingCodeAfnor(siret: string, routingIdentifier: string): Promise<Record<string, unknown>>;
166
- /**
167
- * Submits an invoice to a PDP via the AFNOR API.
168
- * Authentication uses the AFNOR OAuth token (obtained automatically),
169
- * either via stored credentials (stored mode), or via the afnorCredentials
170
- * provided to the constructor (zero-trust mode).
171
- *
172
- * @param pdfBuffer Buffer of the Factur-X PDF to submit
173
- * @param flowName Flow name (e.g.: "Invoice INV-2025-001")
174
- * @param options Options: trackingId, flowSyntax (CII/UBL), flowProfile
175
- */
176
- submitInvoiceAfnor(pdfBuffer: Buffer, flowName: string, options?: {
177
- trackingId?: string;
178
- flowSyntax?: string;
179
- flowProfile?: string;
180
- }): Promise<Record<string, unknown>>;
181
- searchFlowsAfnor(criteria?: {
182
- trackingId?: string;
183
- status?: string;
184
- offset?: number;
185
- limit?: number;
186
- }): Promise<Record<string, unknown>>;
187
- downloadFlowAfnor(flowId: string): Promise<Buffer>;
188
- /**
189
- * Retrieves JSON metadata of an incoming flow (supplier invoice).
190
- * Downloads an incoming flow from the AFNOR PDP and extracts invoice
191
- * metadata into a unified JSON format. Supports Factur-X, CII and UBL.
192
- *
193
- * Note: This endpoint uses FactPulse JWT authentication (not AFNOR OAuth).
194
- * The FactPulse server handles calling the PDP with stored credentials.
195
- *
196
- * @param flowId Flow identifier (UUID)
197
- * @param includeDocument If true, includes the original document encoded in base64
198
- * @returns Invoice metadata (supplier, amounts, dates, etc.)
199
- *
200
- * @example
201
- * const invoice = await client.getIncomingInvoiceAfnor("550e8400-...");
202
- * console.log(`Supplier: ${invoice.supplier.name}`);
203
- * console.log(`Total incl. tax: ${invoice.total_incl_tax} ${invoice.currency}`);
204
- */
205
- getIncomingInvoiceAfnor(flowId: string, includeDocument?: boolean): Promise<Record<string, unknown>>;
206
- healthcheckAfnor(): Promise<Record<string, unknown>>;
207
- rechercherStructureChorus(criteria: Record<string, unknown>): Promise<unknown[]>;
208
- consulterStructureChorus(idStructureCpp: number): Promise<Record<string, unknown>>;
209
- /**
210
- * Lists the services of a Chorus Pro structure.
211
- * @param idStructureCpp Chorus Pro ID of the structure
212
- * @returns Object with listeServices, total, codeRetour, libelle
213
- */
214
- listerServicesStructureChorus(idStructureCpp: number): Promise<Record<string, unknown>>;
215
- obtenirIdChorusDepuisSiret(siret: string): Promise<number | null>;
216
- submitInvoiceChorus(invoiceData: Record<string, unknown>): Promise<Record<string, unknown>>;
217
- lookupInvoiceChorus(invoiceIdCpp: number): Promise<Record<string, unknown>>;
218
- /**
219
- * Validates a Factur-X PDF.
220
- * @param pdfBuffer - PDF content as Buffer
221
- * @param options - Validation options
222
- * @param options.profile - Factur-X profile (MINIMUM, BASIC, EN16931, EXTENDED). If not specified, auto-detected.
223
- * @param options.useVerapdf - Enable strict PDF/A validation with VeraPDF (default: false)
224
- */
225
- validateFacturxPdf(pdfBuffer: Buffer, options?: {
226
- profile?: string;
227
- useVerapdf?: boolean;
228
- }): Promise<Record<string, unknown>>;
229
- validateFacturxXml(xmlContent: string, profile?: string): Promise<Record<string, unknown>>;
230
- validatePdfSignature(pdfBuffer: Buffer): Promise<Record<string, unknown>>;
231
- /**
232
- * Signs a PDF with the server-configured certificate (via JWT client_uid).
233
- * The certificate must be previously configured in Django Admin.
234
- */
235
- signPdf(pdfBuffer: Buffer, options?: {
236
- reason?: string;
237
- location?: string;
238
- contact?: string;
239
- usePadesLt?: boolean;
240
- useTimestamp?: boolean;
241
- }): Promise<Buffer>;
242
- /**
243
- * Generates a test certificate (NOT FOR PRODUCTION).
244
- * The certificate must then be configured in Django Admin.
245
- */
246
- generateTestCertificate(options?: {
247
- cn?: string;
248
- organisation?: string;
249
- email?: string;
250
- validityDays?: number;
251
- keySize?: number;
252
- }): Promise<Record<string, unknown>>;
253
- /**
254
- * Complete workflow: generation + validation + signature + AFNOR submission.
255
- * Note: Signature uses the server-configured certificate (via JWT client_uid).
256
- * @param invoiceData Invoice data
257
- * @param pdfPath Path to the source PDF
258
- * @param options Workflow options
259
- * @returns Result with pdfBytes, validation, signature and afnor
260
- */
261
- generateCompleteFacturx(invoiceData: Record<string, unknown>, pdfPath: string, options?: {
262
- profile?: string;
263
- validate?: boolean;
264
- sign?: boolean;
265
- submitAfnor?: boolean;
266
- afnorFlowName?: string;
267
- afnorTrackingId?: string;
268
- timeout?: number;
269
- }): Promise<{
270
- pdfBytes: Buffer;
271
- validation?: Record<string, unknown>;
272
- signature?: {
273
- signed: boolean;
274
- };
275
- afnor?: Record<string, unknown>;
276
- }>;
26
+ /** POST request to /api/v1/{path} */
27
+ post(path: string, data?: Record<string, unknown>): Promise<unknown>;
28
+ /** GET request to /api/v1/{path} */
29
+ get(path: string, params?: Record<string, unknown>): Promise<unknown>;
30
+ get processing(): Endpoint;
31
+ get chorus_pro(): Endpoint;
32
+ get afnor(): Endpoint;
33
+ private _endpoint;
34
+ _request(method: 'GET' | 'POST', path: string, data?: Record<string, unknown>): Promise<unknown>;
35
+ private _doRequest;
36
+ private _parseResponse;
37
+ private _poll;
38
+ private _ensureAuth;
39
+ private _refreshToken;
40
+ private _invalidateToken;
41
+ }
42
+ declare class Endpoint {
43
+ private client;
44
+ private path;
45
+ constructor(client: FactPulseClient, path: string);
46
+ private _child;
47
+ get invoices(): Endpoint;
48
+ get structures(): Endpoint;
49
+ get tasks(): Endpoint;
50
+ get validate_facturx_pdf(): Endpoint;
51
+ get submit_complete_async(): Endpoint;
52
+ [key: string]: unknown;
53
+ call(data?: Record<string, unknown>): Promise<unknown>;
54
+ get(params?: Record<string, unknown>): Promise<unknown>;
277
55
  }
278
56
  export {};