@deuriib/dgii-ecf 0.4.0 → 0.5.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.
- package/dist/index.cjs +212 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -3
- package/dist/index.d.ts +92 -3
- package/dist/index.js +208 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -94,6 +94,12 @@ interface SummaryTrackingStatusResponse {
|
|
|
94
94
|
interface InvoiceResponse {
|
|
95
95
|
trackId?: string;
|
|
96
96
|
error?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Synchronous acknowledgement text. DGII sends this as a singular string on
|
|
99
|
+
* the general reception endpoint (`recepcion/api/FacturasElectronicas`).
|
|
100
|
+
*/
|
|
101
|
+
mensaje?: string;
|
|
102
|
+
/** Tolerated array form used by the RFCE and status endpoints. */
|
|
97
103
|
mensajes?: Mensaje[];
|
|
98
104
|
}
|
|
99
105
|
interface InvoiceSummaryResponse {
|
|
@@ -119,8 +125,9 @@ interface InquiryInvoiceSummary {
|
|
|
119
125
|
mensajes?: Mensaje[];
|
|
120
126
|
}
|
|
121
127
|
interface CommercialApprovalResponse {
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
/** `1` = approved, `2` = not found / not processed. */
|
|
129
|
+
codigo: '1' | '2';
|
|
130
|
+
estado: 'Aprobación comercial aprobada' | 'Aprobación comercial rechazada';
|
|
124
131
|
mensaje: string[];
|
|
125
132
|
}
|
|
126
133
|
interface VoidNCFResponse {
|
|
@@ -252,6 +259,10 @@ interface HttpClientOptions {
|
|
|
252
259
|
policies?: ResiliencePolicies;
|
|
253
260
|
timeoutMs?: number;
|
|
254
261
|
fetchImpl?: typeof fetch;
|
|
262
|
+
/** Runs before every authenticated request; may refresh credentials. */
|
|
263
|
+
beforeRequest?: () => Promise<void>;
|
|
264
|
+
/** Runs on a 401; return `true` to replay the request once. */
|
|
265
|
+
onUnauthorized?: () => Promise<boolean>;
|
|
255
266
|
}
|
|
256
267
|
interface RequestOptions {
|
|
257
268
|
method?: 'GET' | 'POST';
|
|
@@ -262,6 +273,8 @@ interface RequestOptions {
|
|
|
262
273
|
body?: BodyInit;
|
|
263
274
|
query?: Record<string, string | number | undefined>;
|
|
264
275
|
resource?: string;
|
|
276
|
+
/** Skip the auth hooks (used by the authentication round-trip itself). */
|
|
277
|
+
skipAuthHooks?: boolean;
|
|
265
278
|
}
|
|
266
279
|
/** Thin HTTP client over the native `fetch`, wrapped in resilience policies. */
|
|
267
280
|
declare class HttpClient {
|
|
@@ -269,17 +282,22 @@ declare class HttpClient {
|
|
|
269
282
|
private readonly policies;
|
|
270
283
|
private readonly fetchImpl;
|
|
271
284
|
private readonly baseUrl;
|
|
285
|
+
private readonly beforeRequest;
|
|
286
|
+
private readonly onUnauthorized;
|
|
272
287
|
constructor(options: HttpClientOptions);
|
|
273
288
|
setToken(token: string): void;
|
|
289
|
+
getToken(): string | undefined;
|
|
274
290
|
clearToken(): void;
|
|
275
291
|
private buildUrl;
|
|
276
292
|
private authHeaders;
|
|
277
293
|
private readBody;
|
|
278
294
|
private parseResponse;
|
|
279
295
|
request<T>(options: RequestOptions): Promise<Result<T, DgiiError>>;
|
|
296
|
+
private execute;
|
|
280
297
|
get<T>(path: string, query?: RequestOptions['query'], opts?: {
|
|
281
298
|
absoluteUrl?: boolean;
|
|
282
299
|
resource?: string;
|
|
300
|
+
skipAuthHooks?: boolean;
|
|
283
301
|
}): Promise<Result<T, DgiiError>>;
|
|
284
302
|
/**
|
|
285
303
|
* POST a signed XML as a multipart `xml` file part. The runtime computes
|
|
@@ -288,6 +306,7 @@ declare class HttpClient {
|
|
|
288
306
|
postMultipart<T>(path: string, fileName: string, xml: string, opts?: {
|
|
289
307
|
absoluteUrl?: boolean;
|
|
290
308
|
resource?: string;
|
|
309
|
+
skipAuthHooks?: boolean;
|
|
291
310
|
}): Promise<Result<T, DgiiError>>;
|
|
292
311
|
}
|
|
293
312
|
|
|
@@ -357,6 +376,45 @@ declare class Transformer {
|
|
|
357
376
|
xml2json<T>(xml: string): Result<T, DgiiError>;
|
|
358
377
|
}
|
|
359
378
|
|
|
379
|
+
/** Every e-CF type code defined by DGII. */
|
|
380
|
+
declare const ECF_TYPE_CODES: readonly ["31", "32", "33", "34", "41", "43", "44", "45", "46", "47"];
|
|
381
|
+
type EcfTypeCode = (typeof ECF_TYPE_CODES)[number];
|
|
382
|
+
/**
|
|
383
|
+
* Consumption invoices (E32) at or above this amount go to the general
|
|
384
|
+
* reception endpoint; below it they must be sent as an RFCE summary.
|
|
385
|
+
*/
|
|
386
|
+
declare const CONSUMPTION_SUMMARY_THRESHOLD = "250000";
|
|
387
|
+
interface GeneralReceptionRoute {
|
|
388
|
+
readonly kind: 'general';
|
|
389
|
+
readonly endpoint: Endpoint.SendInvoice;
|
|
390
|
+
}
|
|
391
|
+
interface SummaryReceptionRoute {
|
|
392
|
+
readonly kind: 'summary';
|
|
393
|
+
readonly endpoint: Endpoint.SendSummary;
|
|
394
|
+
}
|
|
395
|
+
type ReceptionRoute = GeneralReceptionRoute | SummaryReceptionRoute;
|
|
396
|
+
declare const isEcfTypeCode: (value: string) => value is EcfTypeCode;
|
|
397
|
+
/**
|
|
398
|
+
* Compare two non-negative decimal strings without going through `number`, so
|
|
399
|
+
* a money amount never picks up binary floating-point error.
|
|
400
|
+
*
|
|
401
|
+
* Returns a negative number when `a < b`, zero when equal, positive otherwise.
|
|
402
|
+
*/
|
|
403
|
+
declare const compareDecimal: (a: string, b: string) => number;
|
|
404
|
+
/**
|
|
405
|
+
* Decide which DGII reception endpoint a signed document belongs to.
|
|
406
|
+
*
|
|
407
|
+
* - `<RFCE>` → the consumption-summary reception (`recepcionfc`).
|
|
408
|
+
* - `<ECF>` with any type other than E32 → the general reception.
|
|
409
|
+
* - `<ECF>` type E32 at or above RD$250,000 → the general reception.
|
|
410
|
+
* - `<ECF>` type E32 below RD$250,000 → rejected: DGII only accepts the
|
|
411
|
+
* summary form for those, so the caller must run `convertECF32ToRFCE` first.
|
|
412
|
+
*
|
|
413
|
+
* The decision reads `TipoeCF` and `MontoTotal` from the signed document, so it
|
|
414
|
+
* cannot drift from what is actually being transmitted.
|
|
415
|
+
*/
|
|
416
|
+
declare const resolveReceptionRoute: (signedXml: string) => Result<ReceptionRoute, DgiiError>;
|
|
417
|
+
|
|
360
418
|
/** First 6 chars of the `<SignatureValue>` (DGII security code). */
|
|
361
419
|
declare const getCodeSixDigitfromSignature: (signedXml: string) => Result<string, DgiiError>;
|
|
362
420
|
/** QR URL for a factura de consumo (FC). */
|
|
@@ -387,6 +445,13 @@ interface EcfOptions {
|
|
|
387
445
|
timeoutMs?: number;
|
|
388
446
|
/** Injectable fetch (useful for tests). */
|
|
389
447
|
fetchImpl?: typeof fetch;
|
|
448
|
+
/**
|
|
449
|
+
* Refresh the token when its remaining lifetime falls below this window.
|
|
450
|
+
* Defaults to 5 minutes.
|
|
451
|
+
*/
|
|
452
|
+
tokenRefreshSkewMs?: number;
|
|
453
|
+
/** Injectable clock (epoch milliseconds); useful for tests. */
|
|
454
|
+
now?: () => number;
|
|
390
455
|
}
|
|
391
456
|
/**
|
|
392
457
|
* DGII e-CF client. Every method returns a `Result` — no thrown domain errors.
|
|
@@ -397,6 +462,10 @@ declare class ECF {
|
|
|
397
462
|
private readonly idempotency;
|
|
398
463
|
private readonly credentials;
|
|
399
464
|
private readonly inFlight;
|
|
465
|
+
private readonly tokenRefreshSkewMs;
|
|
466
|
+
private readonly now;
|
|
467
|
+
private tokenExpiresAt;
|
|
468
|
+
private refreshPromise;
|
|
400
469
|
constructor(credentials: P12ReaderData, environment?: Environment, options?: EcfOptions);
|
|
401
470
|
private buildIdempotencyKey;
|
|
402
471
|
/**
|
|
@@ -408,6 +477,17 @@ declare class ECF {
|
|
|
408
477
|
*/
|
|
409
478
|
private submitIdempotent;
|
|
410
479
|
private singleFlight;
|
|
480
|
+
/**
|
|
481
|
+
* Refresh the token when it is missing or about to expire.
|
|
482
|
+
*
|
|
483
|
+
* A pre-supplied `token` has no known expiry, so it is never refreshed
|
|
484
|
+
* proactively — only a 401 triggers a re-authentication for it.
|
|
485
|
+
*/
|
|
486
|
+
private ensureToken;
|
|
487
|
+
/** Authenticate, coalescing concurrent refreshes into a single round-trip. */
|
|
488
|
+
private refreshToken;
|
|
489
|
+
/** Drop the rejected token and authenticate once. Returns `true` on success. */
|
|
490
|
+
private reauthenticate;
|
|
411
491
|
/** Authenticate against DGII (or a buyer host) and store the bearer token. */
|
|
412
492
|
authenticate(buyerHost?: string): Promise<Result<AuthToken, DgiiError>>;
|
|
413
493
|
private getSeed;
|
|
@@ -419,6 +499,15 @@ declare class ECF {
|
|
|
419
499
|
sendElectronicDocument(signedXml: string, fileName: string, buyerHost?: string): Promise<Result<InvoiceResponse, DgiiError>>;
|
|
420
500
|
/** Submit a signed summary invoice (RFCE). Idempotent like submissions. */
|
|
421
501
|
sendSummary(signedXml: string, fileName: string): Promise<Result<InvoiceSummaryResponse, DgiiError>>;
|
|
502
|
+
/**
|
|
503
|
+
* Submit a signed document to the endpoint its own content belongs to.
|
|
504
|
+
*
|
|
505
|
+
* Reads the root element, `TipoeCF` and `MontoTotal` from the signed XML and
|
|
506
|
+
* dispatches to {@link sendSummary} for an RFCE or to
|
|
507
|
+
* {@link sendElectronicDocument} for an ECF. An E32 below RD$250,000 is
|
|
508
|
+
* rejected because DGII only accepts the summary form for those.
|
|
509
|
+
*/
|
|
510
|
+
sendDocument(signedXml: string, fileName: string, buyerHost?: string): Promise<Result<InvoiceResponse | InvoiceSummaryResponse, DgiiError>>;
|
|
422
511
|
statusTrackId(trackId: string): Promise<Result<TrackingStatusResponse, DgiiError>>;
|
|
423
512
|
inquiryStatus(rncEmisor: string, ncfElectronico: string, rncComprador?: string, codigoSeguridad?: string): Promise<Result<InquiryStatusResponse, DgiiError>>;
|
|
424
513
|
trackStatuses(rncEmisor: string, encf: string): Promise<Result<SummaryTrackingStatusResponse[], DgiiError>>;
|
|
@@ -438,4 +527,4 @@ declare class ECF {
|
|
|
438
527
|
voidENCF(signedXml: string, fileName: string): Promise<Result<VoidNCFResponse, DgiiError>>;
|
|
439
528
|
}
|
|
440
529
|
|
|
441
|
-
export { type AuthToken, BaseUrl, type BaseUrlKey, type CertificateInfo, type CommercialApprovalResponse, type DgiiDocumentType, DgiiError, type DgiiErrorCode, type DgiiErrorContext, type DgiiErrorOptions, type DgiiResult, ECF, type EcfOptions, Endpoint, Environment, HttpClient, type HttpClientOptions, type IdempotencyStore, InMemoryIdempotencyStore, type InMemoryIdempotencyStoreOptions, type InquiryInvoiceSummary, type InquiryStatus, type InquiryStatusCode, type InquiryStatusResponse, type InvoiceResponse, type InvoiceSummaryResponse, type Mensaje, P12Reader, type P12ReaderData, type RequestOptions, type ResilienceOptions, type ResiliencePolicies, SenderReceiverEndpoint, type ServiceDirectoryResponse, Signature, type SummaryTrackingStatusResponse, type TrackStatusCode, TrackStatusEnum, type TrackingStatusResponse, Transformer, type VoidNCFResponse, type XmlCertificateValidation, buildSenderReceiverUrl, buildUrl, convertECF32ToRFCE, createResiliencePolicies, defaultResilienceOptions, extractDgiiErrorMessage, generateEcfQRCodeURL, generateFcQRCodeURL, getCodeSixDigitfromSignature, getCurrentFormattedDate, getCurrentFormattedDateTime, getXmlFromBodyResponse, isRetryableError, isRetryableStatus, roundHalfUpToCents, toDgiiError, validateXMLCertificate };
|
|
530
|
+
export { type AuthToken, BaseUrl, type BaseUrlKey, CONSUMPTION_SUMMARY_THRESHOLD, type CertificateInfo, type CommercialApprovalResponse, type DgiiDocumentType, DgiiError, type DgiiErrorCode, type DgiiErrorContext, type DgiiErrorOptions, type DgiiResult, ECF, ECF_TYPE_CODES, type EcfOptions, type EcfTypeCode, Endpoint, Environment, type GeneralReceptionRoute, HttpClient, type HttpClientOptions, type IdempotencyStore, InMemoryIdempotencyStore, type InMemoryIdempotencyStoreOptions, type InquiryInvoiceSummary, type InquiryStatus, type InquiryStatusCode, type InquiryStatusResponse, type InvoiceResponse, type InvoiceSummaryResponse, type Mensaje, P12Reader, type P12ReaderData, type ReceptionRoute, type RequestOptions, type ResilienceOptions, type ResiliencePolicies, SenderReceiverEndpoint, type ServiceDirectoryResponse, Signature, type SummaryReceptionRoute, type SummaryTrackingStatusResponse, type TrackStatusCode, TrackStatusEnum, type TrackingStatusResponse, Transformer, type VoidNCFResponse, type XmlCertificateValidation, buildSenderReceiverUrl, buildUrl, compareDecimal, convertECF32ToRFCE, createResiliencePolicies, defaultResilienceOptions, extractDgiiErrorMessage, generateEcfQRCodeURL, generateFcQRCodeURL, getCodeSixDigitfromSignature, getCurrentFormattedDate, getCurrentFormattedDateTime, getXmlFromBodyResponse, isEcfTypeCode, isRetryableError, isRetryableStatus, resolveReceptionRoute, roundHalfUpToCents, toDgiiError, validateXMLCertificate };
|
package/dist/index.d.ts
CHANGED
|
@@ -94,6 +94,12 @@ interface SummaryTrackingStatusResponse {
|
|
|
94
94
|
interface InvoiceResponse {
|
|
95
95
|
trackId?: string;
|
|
96
96
|
error?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Synchronous acknowledgement text. DGII sends this as a singular string on
|
|
99
|
+
* the general reception endpoint (`recepcion/api/FacturasElectronicas`).
|
|
100
|
+
*/
|
|
101
|
+
mensaje?: string;
|
|
102
|
+
/** Tolerated array form used by the RFCE and status endpoints. */
|
|
97
103
|
mensajes?: Mensaje[];
|
|
98
104
|
}
|
|
99
105
|
interface InvoiceSummaryResponse {
|
|
@@ -119,8 +125,9 @@ interface InquiryInvoiceSummary {
|
|
|
119
125
|
mensajes?: Mensaje[];
|
|
120
126
|
}
|
|
121
127
|
interface CommercialApprovalResponse {
|
|
122
|
-
|
|
123
|
-
|
|
128
|
+
/** `1` = approved, `2` = not found / not processed. */
|
|
129
|
+
codigo: '1' | '2';
|
|
130
|
+
estado: 'Aprobación comercial aprobada' | 'Aprobación comercial rechazada';
|
|
124
131
|
mensaje: string[];
|
|
125
132
|
}
|
|
126
133
|
interface VoidNCFResponse {
|
|
@@ -252,6 +259,10 @@ interface HttpClientOptions {
|
|
|
252
259
|
policies?: ResiliencePolicies;
|
|
253
260
|
timeoutMs?: number;
|
|
254
261
|
fetchImpl?: typeof fetch;
|
|
262
|
+
/** Runs before every authenticated request; may refresh credentials. */
|
|
263
|
+
beforeRequest?: () => Promise<void>;
|
|
264
|
+
/** Runs on a 401; return `true` to replay the request once. */
|
|
265
|
+
onUnauthorized?: () => Promise<boolean>;
|
|
255
266
|
}
|
|
256
267
|
interface RequestOptions {
|
|
257
268
|
method?: 'GET' | 'POST';
|
|
@@ -262,6 +273,8 @@ interface RequestOptions {
|
|
|
262
273
|
body?: BodyInit;
|
|
263
274
|
query?: Record<string, string | number | undefined>;
|
|
264
275
|
resource?: string;
|
|
276
|
+
/** Skip the auth hooks (used by the authentication round-trip itself). */
|
|
277
|
+
skipAuthHooks?: boolean;
|
|
265
278
|
}
|
|
266
279
|
/** Thin HTTP client over the native `fetch`, wrapped in resilience policies. */
|
|
267
280
|
declare class HttpClient {
|
|
@@ -269,17 +282,22 @@ declare class HttpClient {
|
|
|
269
282
|
private readonly policies;
|
|
270
283
|
private readonly fetchImpl;
|
|
271
284
|
private readonly baseUrl;
|
|
285
|
+
private readonly beforeRequest;
|
|
286
|
+
private readonly onUnauthorized;
|
|
272
287
|
constructor(options: HttpClientOptions);
|
|
273
288
|
setToken(token: string): void;
|
|
289
|
+
getToken(): string | undefined;
|
|
274
290
|
clearToken(): void;
|
|
275
291
|
private buildUrl;
|
|
276
292
|
private authHeaders;
|
|
277
293
|
private readBody;
|
|
278
294
|
private parseResponse;
|
|
279
295
|
request<T>(options: RequestOptions): Promise<Result<T, DgiiError>>;
|
|
296
|
+
private execute;
|
|
280
297
|
get<T>(path: string, query?: RequestOptions['query'], opts?: {
|
|
281
298
|
absoluteUrl?: boolean;
|
|
282
299
|
resource?: string;
|
|
300
|
+
skipAuthHooks?: boolean;
|
|
283
301
|
}): Promise<Result<T, DgiiError>>;
|
|
284
302
|
/**
|
|
285
303
|
* POST a signed XML as a multipart `xml` file part. The runtime computes
|
|
@@ -288,6 +306,7 @@ declare class HttpClient {
|
|
|
288
306
|
postMultipart<T>(path: string, fileName: string, xml: string, opts?: {
|
|
289
307
|
absoluteUrl?: boolean;
|
|
290
308
|
resource?: string;
|
|
309
|
+
skipAuthHooks?: boolean;
|
|
291
310
|
}): Promise<Result<T, DgiiError>>;
|
|
292
311
|
}
|
|
293
312
|
|
|
@@ -357,6 +376,45 @@ declare class Transformer {
|
|
|
357
376
|
xml2json<T>(xml: string): Result<T, DgiiError>;
|
|
358
377
|
}
|
|
359
378
|
|
|
379
|
+
/** Every e-CF type code defined by DGII. */
|
|
380
|
+
declare const ECF_TYPE_CODES: readonly ["31", "32", "33", "34", "41", "43", "44", "45", "46", "47"];
|
|
381
|
+
type EcfTypeCode = (typeof ECF_TYPE_CODES)[number];
|
|
382
|
+
/**
|
|
383
|
+
* Consumption invoices (E32) at or above this amount go to the general
|
|
384
|
+
* reception endpoint; below it they must be sent as an RFCE summary.
|
|
385
|
+
*/
|
|
386
|
+
declare const CONSUMPTION_SUMMARY_THRESHOLD = "250000";
|
|
387
|
+
interface GeneralReceptionRoute {
|
|
388
|
+
readonly kind: 'general';
|
|
389
|
+
readonly endpoint: Endpoint.SendInvoice;
|
|
390
|
+
}
|
|
391
|
+
interface SummaryReceptionRoute {
|
|
392
|
+
readonly kind: 'summary';
|
|
393
|
+
readonly endpoint: Endpoint.SendSummary;
|
|
394
|
+
}
|
|
395
|
+
type ReceptionRoute = GeneralReceptionRoute | SummaryReceptionRoute;
|
|
396
|
+
declare const isEcfTypeCode: (value: string) => value is EcfTypeCode;
|
|
397
|
+
/**
|
|
398
|
+
* Compare two non-negative decimal strings without going through `number`, so
|
|
399
|
+
* a money amount never picks up binary floating-point error.
|
|
400
|
+
*
|
|
401
|
+
* Returns a negative number when `a < b`, zero when equal, positive otherwise.
|
|
402
|
+
*/
|
|
403
|
+
declare const compareDecimal: (a: string, b: string) => number;
|
|
404
|
+
/**
|
|
405
|
+
* Decide which DGII reception endpoint a signed document belongs to.
|
|
406
|
+
*
|
|
407
|
+
* - `<RFCE>` → the consumption-summary reception (`recepcionfc`).
|
|
408
|
+
* - `<ECF>` with any type other than E32 → the general reception.
|
|
409
|
+
* - `<ECF>` type E32 at or above RD$250,000 → the general reception.
|
|
410
|
+
* - `<ECF>` type E32 below RD$250,000 → rejected: DGII only accepts the
|
|
411
|
+
* summary form for those, so the caller must run `convertECF32ToRFCE` first.
|
|
412
|
+
*
|
|
413
|
+
* The decision reads `TipoeCF` and `MontoTotal` from the signed document, so it
|
|
414
|
+
* cannot drift from what is actually being transmitted.
|
|
415
|
+
*/
|
|
416
|
+
declare const resolveReceptionRoute: (signedXml: string) => Result<ReceptionRoute, DgiiError>;
|
|
417
|
+
|
|
360
418
|
/** First 6 chars of the `<SignatureValue>` (DGII security code). */
|
|
361
419
|
declare const getCodeSixDigitfromSignature: (signedXml: string) => Result<string, DgiiError>;
|
|
362
420
|
/** QR URL for a factura de consumo (FC). */
|
|
@@ -387,6 +445,13 @@ interface EcfOptions {
|
|
|
387
445
|
timeoutMs?: number;
|
|
388
446
|
/** Injectable fetch (useful for tests). */
|
|
389
447
|
fetchImpl?: typeof fetch;
|
|
448
|
+
/**
|
|
449
|
+
* Refresh the token when its remaining lifetime falls below this window.
|
|
450
|
+
* Defaults to 5 minutes.
|
|
451
|
+
*/
|
|
452
|
+
tokenRefreshSkewMs?: number;
|
|
453
|
+
/** Injectable clock (epoch milliseconds); useful for tests. */
|
|
454
|
+
now?: () => number;
|
|
390
455
|
}
|
|
391
456
|
/**
|
|
392
457
|
* DGII e-CF client. Every method returns a `Result` — no thrown domain errors.
|
|
@@ -397,6 +462,10 @@ declare class ECF {
|
|
|
397
462
|
private readonly idempotency;
|
|
398
463
|
private readonly credentials;
|
|
399
464
|
private readonly inFlight;
|
|
465
|
+
private readonly tokenRefreshSkewMs;
|
|
466
|
+
private readonly now;
|
|
467
|
+
private tokenExpiresAt;
|
|
468
|
+
private refreshPromise;
|
|
400
469
|
constructor(credentials: P12ReaderData, environment?: Environment, options?: EcfOptions);
|
|
401
470
|
private buildIdempotencyKey;
|
|
402
471
|
/**
|
|
@@ -408,6 +477,17 @@ declare class ECF {
|
|
|
408
477
|
*/
|
|
409
478
|
private submitIdempotent;
|
|
410
479
|
private singleFlight;
|
|
480
|
+
/**
|
|
481
|
+
* Refresh the token when it is missing or about to expire.
|
|
482
|
+
*
|
|
483
|
+
* A pre-supplied `token` has no known expiry, so it is never refreshed
|
|
484
|
+
* proactively — only a 401 triggers a re-authentication for it.
|
|
485
|
+
*/
|
|
486
|
+
private ensureToken;
|
|
487
|
+
/** Authenticate, coalescing concurrent refreshes into a single round-trip. */
|
|
488
|
+
private refreshToken;
|
|
489
|
+
/** Drop the rejected token and authenticate once. Returns `true` on success. */
|
|
490
|
+
private reauthenticate;
|
|
411
491
|
/** Authenticate against DGII (or a buyer host) and store the bearer token. */
|
|
412
492
|
authenticate(buyerHost?: string): Promise<Result<AuthToken, DgiiError>>;
|
|
413
493
|
private getSeed;
|
|
@@ -419,6 +499,15 @@ declare class ECF {
|
|
|
419
499
|
sendElectronicDocument(signedXml: string, fileName: string, buyerHost?: string): Promise<Result<InvoiceResponse, DgiiError>>;
|
|
420
500
|
/** Submit a signed summary invoice (RFCE). Idempotent like submissions. */
|
|
421
501
|
sendSummary(signedXml: string, fileName: string): Promise<Result<InvoiceSummaryResponse, DgiiError>>;
|
|
502
|
+
/**
|
|
503
|
+
* Submit a signed document to the endpoint its own content belongs to.
|
|
504
|
+
*
|
|
505
|
+
* Reads the root element, `TipoeCF` and `MontoTotal` from the signed XML and
|
|
506
|
+
* dispatches to {@link sendSummary} for an RFCE or to
|
|
507
|
+
* {@link sendElectronicDocument} for an ECF. An E32 below RD$250,000 is
|
|
508
|
+
* rejected because DGII only accepts the summary form for those.
|
|
509
|
+
*/
|
|
510
|
+
sendDocument(signedXml: string, fileName: string, buyerHost?: string): Promise<Result<InvoiceResponse | InvoiceSummaryResponse, DgiiError>>;
|
|
422
511
|
statusTrackId(trackId: string): Promise<Result<TrackingStatusResponse, DgiiError>>;
|
|
423
512
|
inquiryStatus(rncEmisor: string, ncfElectronico: string, rncComprador?: string, codigoSeguridad?: string): Promise<Result<InquiryStatusResponse, DgiiError>>;
|
|
424
513
|
trackStatuses(rncEmisor: string, encf: string): Promise<Result<SummaryTrackingStatusResponse[], DgiiError>>;
|
|
@@ -438,4 +527,4 @@ declare class ECF {
|
|
|
438
527
|
voidENCF(signedXml: string, fileName: string): Promise<Result<VoidNCFResponse, DgiiError>>;
|
|
439
528
|
}
|
|
440
529
|
|
|
441
|
-
export { type AuthToken, BaseUrl, type BaseUrlKey, type CertificateInfo, type CommercialApprovalResponse, type DgiiDocumentType, DgiiError, type DgiiErrorCode, type DgiiErrorContext, type DgiiErrorOptions, type DgiiResult, ECF, type EcfOptions, Endpoint, Environment, HttpClient, type HttpClientOptions, type IdempotencyStore, InMemoryIdempotencyStore, type InMemoryIdempotencyStoreOptions, type InquiryInvoiceSummary, type InquiryStatus, type InquiryStatusCode, type InquiryStatusResponse, type InvoiceResponse, type InvoiceSummaryResponse, type Mensaje, P12Reader, type P12ReaderData, type RequestOptions, type ResilienceOptions, type ResiliencePolicies, SenderReceiverEndpoint, type ServiceDirectoryResponse, Signature, type SummaryTrackingStatusResponse, type TrackStatusCode, TrackStatusEnum, type TrackingStatusResponse, Transformer, type VoidNCFResponse, type XmlCertificateValidation, buildSenderReceiverUrl, buildUrl, convertECF32ToRFCE, createResiliencePolicies, defaultResilienceOptions, extractDgiiErrorMessage, generateEcfQRCodeURL, generateFcQRCodeURL, getCodeSixDigitfromSignature, getCurrentFormattedDate, getCurrentFormattedDateTime, getXmlFromBodyResponse, isRetryableError, isRetryableStatus, roundHalfUpToCents, toDgiiError, validateXMLCertificate };
|
|
530
|
+
export { type AuthToken, BaseUrl, type BaseUrlKey, CONSUMPTION_SUMMARY_THRESHOLD, type CertificateInfo, type CommercialApprovalResponse, type DgiiDocumentType, DgiiError, type DgiiErrorCode, type DgiiErrorContext, type DgiiErrorOptions, type DgiiResult, ECF, ECF_TYPE_CODES, type EcfOptions, type EcfTypeCode, Endpoint, Environment, type GeneralReceptionRoute, HttpClient, type HttpClientOptions, type IdempotencyStore, InMemoryIdempotencyStore, type InMemoryIdempotencyStoreOptions, type InquiryInvoiceSummary, type InquiryStatus, type InquiryStatusCode, type InquiryStatusResponse, type InvoiceResponse, type InvoiceSummaryResponse, type Mensaje, P12Reader, type P12ReaderData, type ReceptionRoute, type RequestOptions, type ResilienceOptions, type ResiliencePolicies, SenderReceiverEndpoint, type ServiceDirectoryResponse, Signature, type SummaryReceptionRoute, type SummaryTrackingStatusResponse, type TrackStatusCode, TrackStatusEnum, type TrackingStatusResponse, Transformer, type VoidNCFResponse, type XmlCertificateValidation, buildSenderReceiverUrl, buildUrl, compareDecimal, convertECF32ToRFCE, createResiliencePolicies, defaultResilienceOptions, extractDgiiErrorMessage, generateEcfQRCodeURL, generateFcQRCodeURL, getCodeSixDigitfromSignature, getCurrentFormattedDate, getCurrentFormattedDateTime, getXmlFromBodyResponse, isEcfTypeCode, isRetryableError, isRetryableStatus, resolveReceptionRoute, roundHalfUpToCents, toDgiiError, validateXMLCertificate };
|