@miguelmorales13/nestkit 0.10.0 → 0.16.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/README.md +518 -12
- package/dist/audit/audit.module.d.ts +23 -0
- package/dist/audit/audit.options.d.ts +16 -0
- package/dist/audit/audit.port.d.ts +37 -0
- package/dist/audit/audit.service.d.ts +29 -0
- package/dist/audit/index.cjs +72 -0
- package/dist/audit/index.d.ts +7 -0
- package/dist/audit/index.js +72 -0
- package/dist/audit/sinks.d.ts +18 -0
- package/dist/auth/index.cjs +4 -3
- package/dist/auth/index.js +2 -1
- package/dist/auth/oauth/index.cjs +81 -13
- package/dist/auth/oauth/index.js +75 -7
- package/dist/auth/oauth/oauth-auth.service.d.ts +29 -1
- package/dist/auth/oauth/oauth.options.d.ts +11 -0
- package/dist/bootstrap/index.cjs +6 -5
- package/dist/bootstrap/index.js +5 -4
- package/dist/chunk-47FXU74G.cjs +205 -0
- package/dist/{chunk-54ZXIB5T.cjs → chunk-4GT66KQS.cjs} +4 -4
- package/dist/{chunk-J7TURDAL.cjs → chunk-67B7IYAV.cjs} +2 -2
- package/dist/{chunk-NVCI3CQI.cjs → chunk-C5DV4RAX.cjs} +6 -1
- package/dist/{chunk-KDAA6GFF.js → chunk-DABTRWA6.js} +12 -7
- package/dist/{chunk-ZA56XBCK.cjs → chunk-EBPEMVZU.cjs} +15 -0
- package/dist/{chunk-EYURGACO.js → chunk-JV4EAOF2.js} +1 -1
- package/dist/chunk-KP2ZHJSR.js +35 -0
- package/dist/{chunk-7I2Y7V52.js → chunk-KRC47OX6.js} +1 -1
- package/dist/chunk-LK3OINS7.js +205 -0
- package/dist/{chunk-A3B2EY4V.js → chunk-MLOQDUBN.js} +6 -1
- package/dist/chunk-TCAMLNUZ.js +27 -0
- package/dist/{chunk-V2M75FN3.cjs → chunk-U7QK24HL.cjs} +2 -2
- package/dist/{chunk-AOCF5QCZ.js → chunk-UIVBPNH4.js} +4 -4
- package/dist/{chunk-TJHRABML.cjs → chunk-UWDHAZVE.cjs} +12 -7
- package/dist/chunk-XHW4CTBS.js +57 -0
- package/dist/chunk-XX5ROVSC.cjs +57 -0
- package/dist/chunk-Y72D5L6I.cjs +27 -0
- package/dist/crud/crud.controller.d.ts +3 -1
- package/dist/crud/crud.service.d.ts +63 -4
- package/dist/crud/index.cjs +7 -2
- package/dist/crud/index.d.ts +2 -1
- package/dist/crud/index.js +6 -1
- package/dist/crud/list-query.dto.d.ts +23 -0
- package/dist/crud/repository.port.d.ts +33 -1
- package/dist/errors/index.cjs +4 -4
- package/dist/errors/index.js +4 -4
- package/dist/idempotency/idempotency.interceptor.d.ts +35 -0
- package/dist/idempotency/idempotency.module.d.ts +27 -0
- package/dist/idempotency/idempotency.options.d.ts +29 -0
- package/dist/idempotency/idempotency.port.d.ts +43 -0
- package/dist/idempotency/index.cjs +206 -0
- package/dist/idempotency/index.d.ts +7 -0
- package/dist/idempotency/index.js +206 -0
- package/dist/idempotency/memory.store.d.ts +24 -0
- package/dist/index.cjs +24 -13
- package/dist/index.js +29 -18
- package/dist/invoicing/adapters/facturama.invoicing.d.ts +50 -0
- package/dist/invoicing/adapters/facturapi.invoicing.d.ts +35 -0
- package/dist/invoicing/amounts.d.ts +52 -0
- package/dist/invoicing/index.cjs +577 -0
- package/dist/invoicing/index.d.ts +11 -0
- package/dist/invoicing/index.js +577 -0
- package/dist/invoicing/invoicing.module.d.ts +42 -0
- package/dist/invoicing/invoicing.options.d.ts +51 -0
- package/dist/invoicing/invoicing.port.d.ts +156 -0
- package/dist/invoicing/lines.d.ts +21 -0
- package/dist/invoicing/provider-http.d.ts +21 -0
- package/dist/media/index.cjs +57 -7
- package/dist/media/index.d.ts +2 -2
- package/dist/media/index.js +56 -6
- package/dist/media/media.options.d.ts +20 -0
- package/dist/media/media.service.d.ts +18 -1
- package/dist/payments/adapters/clip.terminal.d.ts +101 -0
- package/dist/payments/adapters/mercadopago.terminal.d.ts +74 -0
- package/dist/payments/index.cjs +795 -0
- package/dist/payments/index.d.ts +12 -0
- package/dist/payments/index.js +795 -0
- package/dist/payments/money.d.ts +20 -0
- package/dist/payments/payments-webhook.controller.d.ts +30 -0
- package/dist/payments/payments.module.d.ts +45 -0
- package/dist/payments/payments.options.d.ts +84 -0
- package/dist/payments/payments.port.d.ts +174 -0
- package/dist/payments/provider-http.d.ts +26 -0
- package/dist/response/api-response.d.ts +7 -0
- package/dist/response/index.cjs +12 -4
- package/dist/response/index.d.ts +2 -0
- package/dist/response/index.js +12 -4
- package/dist/response/paginated.d.ts +25 -0
- package/dist/response/response.interceptor.d.ts +4 -0
- package/dist/tracking/index.cjs +3 -3
- package/dist/tracking/index.d.ts +1 -1
- package/dist/tracking/index.js +2 -2
- package/dist/tracking/request-context.d.ts +22 -0
- package/package.json +25 -3
- package/dist/chunk-3CLYZC3T.cjs +0 -104
- package/dist/chunk-EBO6UKHL.js +0 -20
- package/dist/chunk-JOVBJDJ2.js +0 -104
- /package/dist/{chunk-MR2IFCZE.cjs → chunk-H2EHN366.cjs} +0 -0
- /package/dist/{chunk-NAK4WDKS.js → chunk-ODPSIFOB.js} +0 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunkFDNGAYTZcjs = require('../chunk-FDNGAYTZ.cjs');
|
|
5
|
+
require('../chunk-R7BVS6CI.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
|
|
10
|
+
|
|
11
|
+
// src/idempotency/idempotency.port.ts
|
|
12
|
+
var IDEMPOTENCY_STORE = /* @__PURE__ */ Symbol("IDEMPOTENCY_STORE");
|
|
13
|
+
|
|
14
|
+
// src/idempotency/idempotency.options.ts
|
|
15
|
+
var IDEMPOTENCY_OPTIONS = /* @__PURE__ */ Symbol("IDEMPOTENCY_OPTIONS");
|
|
16
|
+
|
|
17
|
+
// src/idempotency/memory.store.ts
|
|
18
|
+
var MemoryIdempotencyStore = class {
|
|
19
|
+
constructor(maxEntries = 1e4) {
|
|
20
|
+
this.maxEntries = maxEntries;
|
|
21
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
22
|
+
}
|
|
23
|
+
async begin(key, fingerprint, ttlMs) {
|
|
24
|
+
this.evictExpired();
|
|
25
|
+
const existing = this.entries.get(key);
|
|
26
|
+
if (existing) {
|
|
27
|
+
return existing.record ? { state: "completed", record: existing.record } : { state: "in_progress", fingerprint: existing.fingerprint };
|
|
28
|
+
}
|
|
29
|
+
if (this.entries.size >= this.maxEntries) {
|
|
30
|
+
const oldest = this.entries.keys().next();
|
|
31
|
+
if (!oldest.done) this.entries.delete(oldest.value);
|
|
32
|
+
}
|
|
33
|
+
this.entries.set(key, { fingerprint, expiresAt: Date.now() + ttlMs });
|
|
34
|
+
return { state: "claimed" };
|
|
35
|
+
}
|
|
36
|
+
async complete(key, record, ttlMs) {
|
|
37
|
+
this.entries.set(key, { fingerprint: record.fingerprint, expiresAt: Date.now() + ttlMs, record });
|
|
38
|
+
}
|
|
39
|
+
async release(key) {
|
|
40
|
+
this.entries.delete(key);
|
|
41
|
+
}
|
|
42
|
+
/** Visible for tests and for a health endpoint that wants to report size. */
|
|
43
|
+
get size() {
|
|
44
|
+
return this.entries.size;
|
|
45
|
+
}
|
|
46
|
+
evictExpired() {
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
for (const [key, entry] of this.entries) {
|
|
49
|
+
if (entry.expiresAt <= now) this.entries.delete(key);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/idempotency/idempotency.interceptor.ts
|
|
55
|
+
var _crypto = require('crypto');
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
var _common = require('@nestjs/common');
|
|
60
|
+
var _rxjs = require('rxjs');
|
|
61
|
+
var _operators = require('rxjs/operators');
|
|
62
|
+
var DEFAULT_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
63
|
+
var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
64
|
+
function headerOf(request, name) {
|
|
65
|
+
const value = _nullishCoalesce(_optionalChain([request, 'access', _ => _.headers, 'optionalAccess', _2 => _2[name]]), () => ( _optionalChain([request, 'access', _3 => _3.headers, 'optionalAccess', _4 => _4[name.toLowerCase()]])));
|
|
66
|
+
return Array.isArray(value) ? value[0] : value;
|
|
67
|
+
}
|
|
68
|
+
function stableStringify(value) {
|
|
69
|
+
if (value === null || typeof value !== "object") return _nullishCoalesce(JSON.stringify(value), () => ( "null"));
|
|
70
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
71
|
+
const entries = Object.entries(value).sort(([a], [b]) => a < b ? -1 : 1);
|
|
72
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`).join(",")}}`;
|
|
73
|
+
}
|
|
74
|
+
function setHeader(response, name, value) {
|
|
75
|
+
if (typeof _optionalChain([response, 'optionalAccess', _5 => _5.header]) === "function") response.header(name, value);
|
|
76
|
+
else if (typeof _optionalChain([response, 'optionalAccess', _6 => _6.setHeader]) === "function") response.setHeader(name, value);
|
|
77
|
+
}
|
|
78
|
+
var IdempotencyInterceptor = class {
|
|
79
|
+
constructor(store, options = {}) {
|
|
80
|
+
this.store = store;
|
|
81
|
+
this.options = options;
|
|
82
|
+
}
|
|
83
|
+
intercept(context, next) {
|
|
84
|
+
const http = context.switchToHttp();
|
|
85
|
+
const request = http.getRequest();
|
|
86
|
+
const response = http.getResponse();
|
|
87
|
+
const methods = _nullishCoalesce(this.options.methods, () => ( DEFAULT_METHODS));
|
|
88
|
+
const method = String(_nullishCoalesce(_optionalChain([request, 'optionalAccess', _7 => _7.method]), () => ( "GET"))).toUpperCase();
|
|
89
|
+
if (!methods.includes(method)) return next.handle();
|
|
90
|
+
const headerName = _nullishCoalesce(this.options.headerName, () => ( "idempotency-key"));
|
|
91
|
+
const key = headerOf(request, headerName);
|
|
92
|
+
if (!key) {
|
|
93
|
+
if (this.options.require) {
|
|
94
|
+
throw new (0, _chunkFDNGAYTZcjs.ValidationAppException)(
|
|
95
|
+
`This endpoint requires an ${headerName} header`,
|
|
96
|
+
{ header: headerName },
|
|
97
|
+
"IDEMPOTENCY_KEY_REQUIRED"
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return next.handle();
|
|
101
|
+
}
|
|
102
|
+
const ttlMs = _nullishCoalesce(this.options.ttlMs, () => ( DEFAULT_TTL_MS));
|
|
103
|
+
const scope = this.options.scope ? this.options.scope(request) : _optionalChain([request, 'optionalAccess', _8 => _8.user, 'optionalAccess', _9 => _9.sub]);
|
|
104
|
+
const storeKey = `${_nullishCoalesce(scope, () => ( "anonymous"))}:${key}`;
|
|
105
|
+
const path = _nullishCoalesce(_nullishCoalesce(_optionalChain([request, 'optionalAccess', _10 => _10.originalUrl]), () => ( _optionalChain([request, 'optionalAccess', _11 => _11.url]))), () => ( ""));
|
|
106
|
+
const fingerprint = _crypto.createHash.call(void 0, "sha256").update(`${method} ${path} ${stableStringify(_nullishCoalesce(_optionalChain([request, 'optionalAccess', _12 => _12.body]), () => ( null)))}`).digest("hex");
|
|
107
|
+
return _rxjs.from.call(void 0, this.store.begin(storeKey, fingerprint, ttlMs)).pipe(
|
|
108
|
+
_operators.switchMap.call(void 0, (begin) => {
|
|
109
|
+
if (begin.state === "completed") {
|
|
110
|
+
if (begin.record.fingerprint !== fingerprint) throw this.mismatch(headerName);
|
|
111
|
+
setHeader(response, "idempotent-replay", "true");
|
|
112
|
+
if (typeof _optionalChain([response, 'optionalAccess', _13 => _13.status]) === "function") response.status(begin.record.status);
|
|
113
|
+
return _rxjs.of.call(void 0, begin.record.body);
|
|
114
|
+
}
|
|
115
|
+
if (begin.state === "in_progress") {
|
|
116
|
+
if (begin.fingerprint !== fingerprint) throw this.mismatch(headerName);
|
|
117
|
+
throw new (0, _chunkFDNGAYTZcjs.ConflictAppException)(
|
|
118
|
+
"A request with this idempotency key is still being processed",
|
|
119
|
+
{ key },
|
|
120
|
+
"IDEMPOTENCY_IN_PROGRESS"
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return next.handle().pipe(
|
|
124
|
+
// Awaited, not fire-and-forget: an answer that has not been stored
|
|
125
|
+
// yet is not replayable, and the retry this protects against is
|
|
126
|
+
// exactly the one that arrives immediately.
|
|
127
|
+
_operators.concatMap.call(void 0, async (body) => {
|
|
128
|
+
await this.store.complete(
|
|
129
|
+
storeKey,
|
|
130
|
+
{ status: Number(_nullishCoalesce(_optionalChain([response, 'optionalAccess', _14 => _14.statusCode]), () => ( 200))), body, fingerprint, completedAt: /* @__PURE__ */ new Date() },
|
|
131
|
+
ttlMs
|
|
132
|
+
);
|
|
133
|
+
return body;
|
|
134
|
+
}),
|
|
135
|
+
_operators.catchError.call(void 0, (error) => {
|
|
136
|
+
return _rxjs.from.call(void 0, this.store.release(storeKey)).pipe(
|
|
137
|
+
_operators.switchMap.call(void 0, () => {
|
|
138
|
+
throw error;
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
mismatch(headerName) {
|
|
147
|
+
return new (0, _chunkFDNGAYTZcjs.ValidationAppException)(
|
|
148
|
+
`This ${headerName} was already used for a different request`,
|
|
149
|
+
void 0,
|
|
150
|
+
"IDEMPOTENCY_KEY_REUSED"
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
IdempotencyInterceptor = exports.IdempotencyInterceptor = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
155
|
+
_common.Injectable.call(void 0, ),
|
|
156
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, IDEMPOTENCY_STORE)),
|
|
157
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, IDEMPOTENCY_OPTIONS))
|
|
158
|
+
], IdempotencyInterceptor);
|
|
159
|
+
|
|
160
|
+
// src/idempotency/idempotency.module.ts
|
|
161
|
+
|
|
162
|
+
var IdempotencyModule = class {
|
|
163
|
+
static forRoot(options = {}) {
|
|
164
|
+
const providers = [
|
|
165
|
+
{ provide: IDEMPOTENCY_OPTIONS, useValue: options },
|
|
166
|
+
{
|
|
167
|
+
provide: IDEMPOTENCY_STORE,
|
|
168
|
+
useFactory: () => _nullishCoalesce(options.store, () => ( new MemoryIdempotencyStore()))
|
|
169
|
+
},
|
|
170
|
+
IdempotencyInterceptor
|
|
171
|
+
];
|
|
172
|
+
return {
|
|
173
|
+
module: IdempotencyModule,
|
|
174
|
+
providers,
|
|
175
|
+
exports: [IDEMPOTENCY_STORE, IDEMPOTENCY_OPTIONS, IdempotencyInterceptor]
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
static forRootAsync(config) {
|
|
179
|
+
const providers = [
|
|
180
|
+
{ provide: IDEMPOTENCY_OPTIONS, useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) },
|
|
181
|
+
{
|
|
182
|
+
provide: IDEMPOTENCY_STORE,
|
|
183
|
+
useFactory: (options) => _nullishCoalesce(options.store, () => ( new MemoryIdempotencyStore())),
|
|
184
|
+
inject: [IDEMPOTENCY_OPTIONS]
|
|
185
|
+
},
|
|
186
|
+
IdempotencyInterceptor
|
|
187
|
+
];
|
|
188
|
+
return {
|
|
189
|
+
module: IdempotencyModule,
|
|
190
|
+
imports: _nullishCoalesce(config.imports, () => ( [])),
|
|
191
|
+
providers,
|
|
192
|
+
exports: [IDEMPOTENCY_STORE, IDEMPOTENCY_OPTIONS, IdempotencyInterceptor]
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
IdempotencyModule = exports.IdempotencyModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
197
|
+
_common.Global.call(void 0, ),
|
|
198
|
+
_common.Module.call(void 0, {})
|
|
199
|
+
], IdempotencyModule);
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
exports.IDEMPOTENCY_OPTIONS = IDEMPOTENCY_OPTIONS; exports.IDEMPOTENCY_STORE = IDEMPOTENCY_STORE; exports.IdempotencyInterceptor = IdempotencyInterceptor; exports.IdempotencyModule = IdempotencyModule; exports.MemoryIdempotencyStore = MemoryIdempotencyStore;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { IDEMPOTENCY_STORE } from './idempotency.port.js';
|
|
2
|
+
export type { IdempotencyStorePort, IdempotencyRecord, BeginResult } from './idempotency.port.js';
|
|
3
|
+
export { IDEMPOTENCY_OPTIONS } from './idempotency.options.js';
|
|
4
|
+
export type { IdempotencyOptions } from './idempotency.options.js';
|
|
5
|
+
export { MemoryIdempotencyStore } from './memory.store.js';
|
|
6
|
+
export { IdempotencyInterceptor } from './idempotency.interceptor.js';
|
|
7
|
+
export { IdempotencyModule } from './idempotency.module.js';
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConflictAppException,
|
|
3
|
+
ValidationAppException
|
|
4
|
+
} from "../chunk-ORWJ7LES.js";
|
|
5
|
+
import "../chunk-YFYHLYHN.js";
|
|
6
|
+
import {
|
|
7
|
+
__decorateClass,
|
|
8
|
+
__decorateParam
|
|
9
|
+
} from "../chunk-4MGIQFAJ.js";
|
|
10
|
+
|
|
11
|
+
// src/idempotency/idempotency.port.ts
|
|
12
|
+
var IDEMPOTENCY_STORE = /* @__PURE__ */ Symbol("IDEMPOTENCY_STORE");
|
|
13
|
+
|
|
14
|
+
// src/idempotency/idempotency.options.ts
|
|
15
|
+
var IDEMPOTENCY_OPTIONS = /* @__PURE__ */ Symbol("IDEMPOTENCY_OPTIONS");
|
|
16
|
+
|
|
17
|
+
// src/idempotency/memory.store.ts
|
|
18
|
+
var MemoryIdempotencyStore = class {
|
|
19
|
+
constructor(maxEntries = 1e4) {
|
|
20
|
+
this.maxEntries = maxEntries;
|
|
21
|
+
this.entries = /* @__PURE__ */ new Map();
|
|
22
|
+
}
|
|
23
|
+
async begin(key, fingerprint, ttlMs) {
|
|
24
|
+
this.evictExpired();
|
|
25
|
+
const existing = this.entries.get(key);
|
|
26
|
+
if (existing) {
|
|
27
|
+
return existing.record ? { state: "completed", record: existing.record } : { state: "in_progress", fingerprint: existing.fingerprint };
|
|
28
|
+
}
|
|
29
|
+
if (this.entries.size >= this.maxEntries) {
|
|
30
|
+
const oldest = this.entries.keys().next();
|
|
31
|
+
if (!oldest.done) this.entries.delete(oldest.value);
|
|
32
|
+
}
|
|
33
|
+
this.entries.set(key, { fingerprint, expiresAt: Date.now() + ttlMs });
|
|
34
|
+
return { state: "claimed" };
|
|
35
|
+
}
|
|
36
|
+
async complete(key, record, ttlMs) {
|
|
37
|
+
this.entries.set(key, { fingerprint: record.fingerprint, expiresAt: Date.now() + ttlMs, record });
|
|
38
|
+
}
|
|
39
|
+
async release(key) {
|
|
40
|
+
this.entries.delete(key);
|
|
41
|
+
}
|
|
42
|
+
/** Visible for tests and for a health endpoint that wants to report size. */
|
|
43
|
+
get size() {
|
|
44
|
+
return this.entries.size;
|
|
45
|
+
}
|
|
46
|
+
evictExpired() {
|
|
47
|
+
const now = Date.now();
|
|
48
|
+
for (const [key, entry] of this.entries) {
|
|
49
|
+
if (entry.expiresAt <= now) this.entries.delete(key);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// src/idempotency/idempotency.interceptor.ts
|
|
55
|
+
import { createHash } from "crypto";
|
|
56
|
+
import {
|
|
57
|
+
Inject,
|
|
58
|
+
Injectable
|
|
59
|
+
} from "@nestjs/common";
|
|
60
|
+
import { from, of } from "rxjs";
|
|
61
|
+
import { catchError, concatMap, switchMap } from "rxjs/operators";
|
|
62
|
+
var DEFAULT_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
63
|
+
var DEFAULT_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
64
|
+
function headerOf(request, name) {
|
|
65
|
+
const value = request.headers?.[name] ?? request.headers?.[name.toLowerCase()];
|
|
66
|
+
return Array.isArray(value) ? value[0] : value;
|
|
67
|
+
}
|
|
68
|
+
function stableStringify(value) {
|
|
69
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? "null";
|
|
70
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
71
|
+
const entries = Object.entries(value).sort(([a], [b]) => a < b ? -1 : 1);
|
|
72
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`).join(",")}}`;
|
|
73
|
+
}
|
|
74
|
+
function setHeader(response, name, value) {
|
|
75
|
+
if (typeof response?.header === "function") response.header(name, value);
|
|
76
|
+
else if (typeof response?.setHeader === "function") response.setHeader(name, value);
|
|
77
|
+
}
|
|
78
|
+
var IdempotencyInterceptor = class {
|
|
79
|
+
constructor(store, options = {}) {
|
|
80
|
+
this.store = store;
|
|
81
|
+
this.options = options;
|
|
82
|
+
}
|
|
83
|
+
intercept(context, next) {
|
|
84
|
+
const http = context.switchToHttp();
|
|
85
|
+
const request = http.getRequest();
|
|
86
|
+
const response = http.getResponse();
|
|
87
|
+
const methods = this.options.methods ?? DEFAULT_METHODS;
|
|
88
|
+
const method = String(request?.method ?? "GET").toUpperCase();
|
|
89
|
+
if (!methods.includes(method)) return next.handle();
|
|
90
|
+
const headerName = this.options.headerName ?? "idempotency-key";
|
|
91
|
+
const key = headerOf(request, headerName);
|
|
92
|
+
if (!key) {
|
|
93
|
+
if (this.options.require) {
|
|
94
|
+
throw new ValidationAppException(
|
|
95
|
+
`This endpoint requires an ${headerName} header`,
|
|
96
|
+
{ header: headerName },
|
|
97
|
+
"IDEMPOTENCY_KEY_REQUIRED"
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return next.handle();
|
|
101
|
+
}
|
|
102
|
+
const ttlMs = this.options.ttlMs ?? DEFAULT_TTL_MS;
|
|
103
|
+
const scope = this.options.scope ? this.options.scope(request) : request?.user?.sub;
|
|
104
|
+
const storeKey = `${scope ?? "anonymous"}:${key}`;
|
|
105
|
+
const path = request?.originalUrl ?? request?.url ?? "";
|
|
106
|
+
const fingerprint = createHash("sha256").update(`${method} ${path} ${stableStringify(request?.body ?? null)}`).digest("hex");
|
|
107
|
+
return from(this.store.begin(storeKey, fingerprint, ttlMs)).pipe(
|
|
108
|
+
switchMap((begin) => {
|
|
109
|
+
if (begin.state === "completed") {
|
|
110
|
+
if (begin.record.fingerprint !== fingerprint) throw this.mismatch(headerName);
|
|
111
|
+
setHeader(response, "idempotent-replay", "true");
|
|
112
|
+
if (typeof response?.status === "function") response.status(begin.record.status);
|
|
113
|
+
return of(begin.record.body);
|
|
114
|
+
}
|
|
115
|
+
if (begin.state === "in_progress") {
|
|
116
|
+
if (begin.fingerprint !== fingerprint) throw this.mismatch(headerName);
|
|
117
|
+
throw new ConflictAppException(
|
|
118
|
+
"A request with this idempotency key is still being processed",
|
|
119
|
+
{ key },
|
|
120
|
+
"IDEMPOTENCY_IN_PROGRESS"
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return next.handle().pipe(
|
|
124
|
+
// Awaited, not fire-and-forget: an answer that has not been stored
|
|
125
|
+
// yet is not replayable, and the retry this protects against is
|
|
126
|
+
// exactly the one that arrives immediately.
|
|
127
|
+
concatMap(async (body) => {
|
|
128
|
+
await this.store.complete(
|
|
129
|
+
storeKey,
|
|
130
|
+
{ status: Number(response?.statusCode ?? 200), body, fingerprint, completedAt: /* @__PURE__ */ new Date() },
|
|
131
|
+
ttlMs
|
|
132
|
+
);
|
|
133
|
+
return body;
|
|
134
|
+
}),
|
|
135
|
+
catchError((error) => {
|
|
136
|
+
return from(this.store.release(storeKey)).pipe(
|
|
137
|
+
switchMap(() => {
|
|
138
|
+
throw error;
|
|
139
|
+
})
|
|
140
|
+
);
|
|
141
|
+
})
|
|
142
|
+
);
|
|
143
|
+
})
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
mismatch(headerName) {
|
|
147
|
+
return new ValidationAppException(
|
|
148
|
+
`This ${headerName} was already used for a different request`,
|
|
149
|
+
void 0,
|
|
150
|
+
"IDEMPOTENCY_KEY_REUSED"
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
IdempotencyInterceptor = __decorateClass([
|
|
155
|
+
Injectable(),
|
|
156
|
+
__decorateParam(0, Inject(IDEMPOTENCY_STORE)),
|
|
157
|
+
__decorateParam(1, Inject(IDEMPOTENCY_OPTIONS))
|
|
158
|
+
], IdempotencyInterceptor);
|
|
159
|
+
|
|
160
|
+
// src/idempotency/idempotency.module.ts
|
|
161
|
+
import { Global, Module } from "@nestjs/common";
|
|
162
|
+
var IdempotencyModule = class {
|
|
163
|
+
static forRoot(options = {}) {
|
|
164
|
+
const providers = [
|
|
165
|
+
{ provide: IDEMPOTENCY_OPTIONS, useValue: options },
|
|
166
|
+
{
|
|
167
|
+
provide: IDEMPOTENCY_STORE,
|
|
168
|
+
useFactory: () => options.store ?? new MemoryIdempotencyStore()
|
|
169
|
+
},
|
|
170
|
+
IdempotencyInterceptor
|
|
171
|
+
];
|
|
172
|
+
return {
|
|
173
|
+
module: IdempotencyModule,
|
|
174
|
+
providers,
|
|
175
|
+
exports: [IDEMPOTENCY_STORE, IDEMPOTENCY_OPTIONS, IdempotencyInterceptor]
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
static forRootAsync(config) {
|
|
179
|
+
const providers = [
|
|
180
|
+
{ provide: IDEMPOTENCY_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },
|
|
181
|
+
{
|
|
182
|
+
provide: IDEMPOTENCY_STORE,
|
|
183
|
+
useFactory: (options) => options.store ?? new MemoryIdempotencyStore(),
|
|
184
|
+
inject: [IDEMPOTENCY_OPTIONS]
|
|
185
|
+
},
|
|
186
|
+
IdempotencyInterceptor
|
|
187
|
+
];
|
|
188
|
+
return {
|
|
189
|
+
module: IdempotencyModule,
|
|
190
|
+
imports: config.imports ?? [],
|
|
191
|
+
providers,
|
|
192
|
+
exports: [IDEMPOTENCY_STORE, IDEMPOTENCY_OPTIONS, IdempotencyInterceptor]
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
IdempotencyModule = __decorateClass([
|
|
197
|
+
Global(),
|
|
198
|
+
Module({})
|
|
199
|
+
], IdempotencyModule);
|
|
200
|
+
export {
|
|
201
|
+
IDEMPOTENCY_OPTIONS,
|
|
202
|
+
IDEMPOTENCY_STORE,
|
|
203
|
+
IdempotencyInterceptor,
|
|
204
|
+
IdempotencyModule,
|
|
205
|
+
MemoryIdempotencyStore
|
|
206
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BeginResult, IdempotencyRecord, IdempotencyStorePort } from './idempotency.port.js';
|
|
2
|
+
/**
|
|
3
|
+
* In-process store. Correct for a single instance, and **wrong the moment
|
|
4
|
+
* there are two**: each process would hold its own keys, so the same retry
|
|
5
|
+
* landing on a different replica runs the handler again — which is the exact
|
|
6
|
+
* double charge this is meant to prevent. Behind a load balancer, back it with
|
|
7
|
+
* Redis or a table instead.
|
|
8
|
+
*
|
|
9
|
+
* Bounded, like `media`'s store, because it lives in the process heap. Unlike
|
|
10
|
+
* `media`, it **evicts the oldest** rather than rejecting: an evicted key only
|
|
11
|
+
* costs the protection of a retry that probably already happened, while
|
|
12
|
+
* refusing new keys would stop the API from accepting work at all.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MemoryIdempotencyStore implements IdempotencyStorePort {
|
|
15
|
+
private readonly maxEntries;
|
|
16
|
+
private readonly entries;
|
|
17
|
+
constructor(maxEntries?: number);
|
|
18
|
+
begin(key: string, fingerprint: string, ttlMs: number): Promise<BeginResult>;
|
|
19
|
+
complete(key: string, record: IdempotencyRecord, ttlMs: number): Promise<void>;
|
|
20
|
+
release(key: string): Promise<void>;
|
|
21
|
+
/** Visible for tests and for a health endpoint that wants to report size. */
|
|
22
|
+
get size(): number;
|
|
23
|
+
private evictExpired;
|
|
24
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkRF75KC63cjs = require('./chunk-RF75KC63.cjs');
|
|
2
6
|
|
|
3
7
|
|
|
4
8
|
|
|
@@ -8,23 +12,33 @@ var _chunkSPTDXUEDcjs = require('./chunk-SPTDXUED.cjs');
|
|
|
8
12
|
|
|
9
13
|
|
|
10
14
|
|
|
11
|
-
var
|
|
12
|
-
require('./chunk-
|
|
15
|
+
var _chunkU7QK24HLcjs = require('./chunk-U7QK24HL.cjs');
|
|
16
|
+
require('./chunk-KVBQBT3D.cjs');
|
|
17
|
+
require('./chunk-7SOM7EZP.cjs');
|
|
18
|
+
require('./chunk-H2EHN366.cjs');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var _chunk4GT66KQScjs = require('./chunk-4GT66KQS.cjs');
|
|
13
22
|
|
|
14
23
|
|
|
24
|
+
var _chunk67B7IYAVcjs = require('./chunk-67B7IYAV.cjs');
|
|
15
25
|
|
|
16
26
|
|
|
17
|
-
var
|
|
27
|
+
var _chunkUWDHAZVEcjs = require('./chunk-UWDHAZVE.cjs');
|
|
18
28
|
|
|
19
29
|
|
|
20
|
-
var _chunk54ZXIB5Tcjs = require('./chunk-54ZXIB5T.cjs');
|
|
21
30
|
|
|
22
31
|
|
|
23
|
-
var
|
|
32
|
+
var _chunk47FXU74Gcjs = require('./chunk-47FXU74G.cjs');
|
|
33
|
+
require('./chunk-XX5ROVSC.cjs');
|
|
24
34
|
|
|
25
35
|
|
|
26
36
|
|
|
27
|
-
|
|
37
|
+
|
|
38
|
+
var _chunkY72D5L6Icjs = require('./chunk-Y72D5L6I.cjs');
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
|
|
28
42
|
|
|
29
43
|
|
|
30
44
|
var _chunkQS2W5XCQcjs = require('./chunk-QS2W5XCQ.cjs');
|
|
@@ -32,7 +46,6 @@ var _chunkQS2W5XCQcjs = require('./chunk-QS2W5XCQ.cjs');
|
|
|
32
46
|
|
|
33
47
|
|
|
34
48
|
var _chunkM3EL5O6Tcjs = require('./chunk-M3EL5O6T.cjs');
|
|
35
|
-
require('./chunk-7SOM7EZP.cjs');
|
|
36
49
|
|
|
37
50
|
|
|
38
51
|
|
|
@@ -42,14 +55,12 @@ require('./chunk-7SOM7EZP.cjs');
|
|
|
42
55
|
var _chunkFDNGAYTZcjs = require('./chunk-FDNGAYTZ.cjs');
|
|
43
56
|
|
|
44
57
|
|
|
45
|
-
var
|
|
58
|
+
var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
|
|
59
|
+
require('./chunk-2REOCMUD.cjs');
|
|
46
60
|
|
|
47
61
|
|
|
48
|
-
var _chunkZA56XBCKcjs = require('./chunk-ZA56XBCK.cjs');
|
|
49
62
|
|
|
50
63
|
|
|
51
|
-
var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
|
|
52
|
-
require('./chunk-2REOCMUD.cjs');
|
|
53
64
|
|
|
54
65
|
|
|
55
66
|
|
|
@@ -75,4 +86,4 @@ require('./chunk-2REOCMUD.cjs');
|
|
|
75
86
|
|
|
76
87
|
|
|
77
88
|
|
|
78
|
-
exports.AppException = _chunkR7BVS6CIcjs.AppException; exports.BaseCrudService =
|
|
89
|
+
exports.AppException = _chunkR7BVS6CIcjs.AppException; exports.BaseCrudService = _chunk47FXU74Gcjs.BaseCrudService; exports.BaseResponseDto = _chunkQS2W5XCQcjs.BaseResponseDto; exports.ConflictAppException = _chunkFDNGAYTZcjs.ConflictAppException; exports.ForbiddenAppException = _chunkFDNGAYTZcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunk67B7IYAVcjs.GlobalExceptionFilter; exports.I18nModule = _chunkM3EL5O6Tcjs.I18nModule; exports.ListQuery = _chunk47FXU74Gcjs.ListQuery; exports.NotFoundAppException = _chunkFDNGAYTZcjs.NotFoundAppException; exports.PG_POOL = _chunkRF75KC63cjs.PG_POOL; exports.PgModule = _chunkRF75KC63cjs.PgModule; exports.REQUEST_ID_HEADER = _chunkU7QK24HLcjs.REQUEST_ID_HEADER; exports.RequestContext = _chunkEBPEMVZUcjs.RequestContext; exports.RequestIdMiddleware = _chunkU7QK24HLcjs.RequestIdMiddleware; exports.ResponseInterceptor = _chunkUWDHAZVEcjs.ResponseInterceptor; exports.SUPABASE_ANON_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_ANON_CLIENT; exports.SUPABASE_SERVICE_ROLE_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_SERVICE_ROLE_CLIENT; exports.SupabaseModule = _chunkSPTDXUEDcjs.SupabaseModule; exports.TrackingModule = _chunkU7QK24HLcjs.TrackingModule; exports.UnauthorizedAppException = _chunkFDNGAYTZcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkFDNGAYTZcjs.ValidationAppException; exports.applyNestKitDefaults = _chunk4GT66KQScjs.applyNestKitDefaults; exports.buildPageMeta = _chunkY72D5L6Icjs.buildPageMeta; exports.createCrudController = _chunk47FXU74Gcjs.createCrudController; exports.isPaginated = _chunkY72D5L6Icjs.isPaginated; exports.paginated = _chunkY72D5L6Icjs.paginated; exports.translateOr = _chunkM3EL5O6Tcjs.translateOr; exports.withTenantScope = _chunkRF75KC63cjs.withTenantScope;
|
package/dist/index.js
CHANGED
|
@@ -1,30 +1,44 @@
|
|
|
1
|
-
import "./chunk-EPVKCBPT.js";
|
|
2
|
-
import {
|
|
3
|
-
SUPABASE_ANON_CLIENT,
|
|
4
|
-
SUPABASE_SERVICE_ROLE_CLIENT,
|
|
5
|
-
SupabaseModule
|
|
6
|
-
} from "./chunk-PA24P76K.js";
|
|
7
1
|
import {
|
|
8
2
|
PG_POOL,
|
|
9
3
|
PgModule,
|
|
10
4
|
withTenantScope
|
|
11
5
|
} from "./chunk-VKOPDDCC.js";
|
|
12
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
SUPABASE_ANON_CLIENT,
|
|
8
|
+
SUPABASE_SERVICE_ROLE_CLIENT,
|
|
9
|
+
SupabaseModule
|
|
10
|
+
} from "./chunk-PA24P76K.js";
|
|
13
11
|
import {
|
|
14
12
|
REQUEST_ID_HEADER,
|
|
15
13
|
RequestIdMiddleware,
|
|
16
14
|
TrackingModule
|
|
17
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-JV4EAOF2.js";
|
|
16
|
+
import "./chunk-EPVKCBPT.js";
|
|
17
|
+
import "./chunk-DQYAIQQ5.js";
|
|
18
|
+
import "./chunk-ODPSIFOB.js";
|
|
18
19
|
import {
|
|
19
20
|
applyNestKitDefaults
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-UIVBPNH4.js";
|
|
22
|
+
import {
|
|
23
|
+
GlobalExceptionFilter
|
|
24
|
+
} from "./chunk-KRC47OX6.js";
|
|
21
25
|
import {
|
|
22
26
|
ResponseInterceptor
|
|
23
|
-
} from "./chunk-
|
|
27
|
+
} from "./chunk-DABTRWA6.js";
|
|
24
28
|
import {
|
|
25
29
|
BaseCrudService,
|
|
30
|
+
ListQuery,
|
|
26
31
|
createCrudController
|
|
27
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-LK3OINS7.js";
|
|
33
|
+
import "./chunk-XHW4CTBS.js";
|
|
34
|
+
import {
|
|
35
|
+
buildPageMeta,
|
|
36
|
+
isPaginated,
|
|
37
|
+
paginated
|
|
38
|
+
} from "./chunk-TCAMLNUZ.js";
|
|
39
|
+
import {
|
|
40
|
+
RequestContext
|
|
41
|
+
} from "./chunk-KP2ZHJSR.js";
|
|
28
42
|
import {
|
|
29
43
|
BaseResponseDto
|
|
30
44
|
} from "./chunk-XX2HPTRU.js";
|
|
@@ -32,7 +46,6 @@ import {
|
|
|
32
46
|
I18nModule,
|
|
33
47
|
translateOr
|
|
34
48
|
} from "./chunk-IYUUYCP5.js";
|
|
35
|
-
import "./chunk-DQYAIQQ5.js";
|
|
36
49
|
import {
|
|
37
50
|
ConflictAppException,
|
|
38
51
|
ForbiddenAppException,
|
|
@@ -40,12 +53,6 @@ import {
|
|
|
40
53
|
UnauthorizedAppException,
|
|
41
54
|
ValidationAppException
|
|
42
55
|
} from "./chunk-ORWJ7LES.js";
|
|
43
|
-
import {
|
|
44
|
-
GlobalExceptionFilter
|
|
45
|
-
} from "./chunk-7I2Y7V52.js";
|
|
46
|
-
import {
|
|
47
|
-
RequestContext
|
|
48
|
-
} from "./chunk-EBO6UKHL.js";
|
|
49
56
|
import {
|
|
50
57
|
AppException
|
|
51
58
|
} from "./chunk-YFYHLYHN.js";
|
|
@@ -58,6 +65,7 @@ export {
|
|
|
58
65
|
ForbiddenAppException,
|
|
59
66
|
GlobalExceptionFilter,
|
|
60
67
|
I18nModule,
|
|
68
|
+
ListQuery,
|
|
61
69
|
NotFoundAppException,
|
|
62
70
|
PG_POOL,
|
|
63
71
|
PgModule,
|
|
@@ -72,7 +80,10 @@ export {
|
|
|
72
80
|
UnauthorizedAppException,
|
|
73
81
|
ValidationAppException,
|
|
74
82
|
applyNestKitDefaults,
|
|
83
|
+
buildPageMeta,
|
|
75
84
|
createCrudController,
|
|
85
|
+
isPaginated,
|
|
86
|
+
paginated,
|
|
76
87
|
translateOr,
|
|
77
88
|
withTenantScope
|
|
78
89
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { FacturamaOptions } from '../invoicing.options.js';
|
|
2
|
+
import type { CancelMotive, Invoice, InvoiceDraft, InvoicingPort } from '../invoicing.port.js';
|
|
3
|
+
/**
|
|
4
|
+
* Facturama, over its API Web (single issuer).
|
|
5
|
+
*
|
|
6
|
+
* Two differences from Facturapi that shape this adapter:
|
|
7
|
+
*
|
|
8
|
+
* - **The environment is the host**, not the key: the sandbox is a different
|
|
9
|
+
* base URL with its own credentials. The default here is the sandbox, so
|
|
10
|
+
* forgetting to configure it cannot produce a real invoice.
|
|
11
|
+
* - **It prints the numbers it is given.** Subtotal, tax base, tax amount and
|
|
12
|
+
* total all travel on the request, and the SAT validates that they add up —
|
|
13
|
+
* which is exactly why the arithmetic lives in the port and not in each
|
|
14
|
+
* adapter.
|
|
15
|
+
*/
|
|
16
|
+
export declare class FacturamaInvoicing implements InvoicingPort {
|
|
17
|
+
private readonly options;
|
|
18
|
+
readonly provider = "facturama";
|
|
19
|
+
private readonly baseUrl;
|
|
20
|
+
private readonly fetchImpl;
|
|
21
|
+
private readonly token;
|
|
22
|
+
private readonly documentType;
|
|
23
|
+
constructor(options: FacturamaOptions);
|
|
24
|
+
/** True while this adapter points at the sandbox host. */
|
|
25
|
+
get isSandbox(): boolean;
|
|
26
|
+
private headers;
|
|
27
|
+
issue(draft: InvoiceDraft): Promise<Invoice>;
|
|
28
|
+
get(id: string): Promise<Invoice>;
|
|
29
|
+
/**
|
|
30
|
+
* Cancels with a motive.
|
|
31
|
+
*
|
|
32
|
+
* Facturama documents this route twice — once with the parameters in the path
|
|
33
|
+
* and once, in its how-to guide, with them in the query string. The guide's
|
|
34
|
+
* form is the one with a working example next to it, so it is the one used
|
|
35
|
+
* here.
|
|
36
|
+
*/
|
|
37
|
+
cancel(id: string, options: {
|
|
38
|
+
motive: CancelMotive;
|
|
39
|
+
substitutionId?: string;
|
|
40
|
+
}): Promise<Invoice>;
|
|
41
|
+
pdf(id: string): Promise<Uint8Array>;
|
|
42
|
+
xml(id: string): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* Facturama hands files back as base64 inside a JSON envelope rather than as
|
|
45
|
+
* bytes, so this decodes rather than streams.
|
|
46
|
+
*/
|
|
47
|
+
private download;
|
|
48
|
+
sendByEmail(_id: string, _to?: string): Promise<void>;
|
|
49
|
+
private toInvoice;
|
|
50
|
+
}
|