@miguelmorales13/nestkit 0.18.0 → 0.20.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 +88 -40
- package/dist/auth/index.cjs +4 -4
- package/dist/auth/index.js +2 -2
- package/dist/auth/oauth/index.cjs +6 -6
- package/dist/auth/oauth/index.js +2 -2
- package/dist/bootstrap/index.cjs +4 -4
- package/dist/bootstrap/index.js +3 -3
- package/dist/{chunk-FNUZGYUF.cjs → chunk-FQRF37NG.cjs} +3 -3
- package/dist/{chunk-UNEVXCFW.js → chunk-PLEY5EZT.js} +3 -3
- package/dist/email/adapters/brevo.email.d.ts +22 -0
- package/dist/email/adapters/memory.email.d.ts +14 -0
- package/dist/email/adapters/message.d.ts +13 -0
- package/dist/email/adapters/resend.email.d.ts +28 -0
- package/dist/email/adapters/smtp.email.d.ts +22 -0
- package/dist/email/address.d.ts +15 -0
- package/dist/email/email.module.d.ts +37 -0
- package/dist/email/email.options.d.ts +39 -0
- package/dist/email/email.port.d.ts +62 -0
- package/dist/email/index.cjs +314 -0
- package/dist/email/index.d.ts +12 -0
- package/dist/email/index.js +314 -0
- package/dist/errors/index.cjs +6 -6
- package/dist/errors/index.js +6 -6
- package/dist/index.cjs +15 -15
- package/dist/index.js +16 -16
- package/dist/invoicing/adapters/facturama.invoicing.d.ts +1 -0
- package/dist/invoicing/index.cjs +7 -2
- package/dist/invoicing/index.js +7 -2
- package/dist/invoicing/invoicing.port.d.ts +10 -0
- package/package.json +6 -1
- package/dist/{chunk-A2DGK4ZL.js → chunk-2DUEQKOI.js} +3 -3
- package/dist/{chunk-4HHZFOVC.cjs → chunk-FH5UNWWW.cjs} +2 -2
- package/dist/{chunk-MSTXS3MU.cjs → chunk-LSDY6ETG.cjs} +3 -3
- package/dist/{chunk-IKXSVEJ7.js → chunk-TUNDBBQF.js} +3 -3
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppException
|
|
3
|
+
} from "../chunk-M3GQDRWR.js";
|
|
4
|
+
import "../chunk-VVMRZEIW.js";
|
|
5
|
+
import {
|
|
6
|
+
__decorateClass
|
|
7
|
+
} from "../chunk-4MGIQFAJ.js";
|
|
8
|
+
|
|
9
|
+
// src/email/email.port.ts
|
|
10
|
+
import { HttpStatus } from "@nestjs/common";
|
|
11
|
+
var EMAIL = /* @__PURE__ */ Symbol("EMAIL");
|
|
12
|
+
var EmailProviderException = class extends AppException {
|
|
13
|
+
constructor(provider, status, body, message) {
|
|
14
|
+
super(
|
|
15
|
+
"EMAIL_PROVIDER_ERROR",
|
|
16
|
+
message ?? `${provider} rejected the message (HTTP ${status})`,
|
|
17
|
+
HttpStatus.BAD_GATEWAY,
|
|
18
|
+
{ provider, status, body }
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/email/email.options.ts
|
|
24
|
+
var EMAIL_OPTIONS = /* @__PURE__ */ Symbol("EMAIL_OPTIONS");
|
|
25
|
+
|
|
26
|
+
// src/email/email.module.ts
|
|
27
|
+
import { Global, Module } from "@nestjs/common";
|
|
28
|
+
|
|
29
|
+
// src/email/address.ts
|
|
30
|
+
var NAMED = /^\s*(?:"?([^"]*)"?\s*)?<\s*([^<>\s]+)\s*>\s*$/;
|
|
31
|
+
function parseAddress(address) {
|
|
32
|
+
if (typeof address !== "string") {
|
|
33
|
+
return address.name ? { email: address.email.trim(), name: address.name } : { email: address.email.trim() };
|
|
34
|
+
}
|
|
35
|
+
const match = NAMED.exec(address);
|
|
36
|
+
if (match) {
|
|
37
|
+
const name = match[1]?.trim();
|
|
38
|
+
return name ? { email: match[2], name } : { email: match[2] };
|
|
39
|
+
}
|
|
40
|
+
return { email: address.trim() };
|
|
41
|
+
}
|
|
42
|
+
function formatAddress(address) {
|
|
43
|
+
const { email, name } = parseAddress(address);
|
|
44
|
+
if (!name) return email;
|
|
45
|
+
const safe = /[(),:;<>@[\]"]/.test(name) ? `"${name.replace(/"/g, '\\"')}"` : name;
|
|
46
|
+
return `${safe} <${email}>`;
|
|
47
|
+
}
|
|
48
|
+
function toList(value) {
|
|
49
|
+
if (value === void 0) return [];
|
|
50
|
+
return Array.isArray(value) ? value : [value];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/email/adapters/message.ts
|
|
54
|
+
function completeMessage(message, defaults) {
|
|
55
|
+
const from = message.from ?? defaults.from;
|
|
56
|
+
if (!from) {
|
|
57
|
+
throw new Error('EmailModule: the message has no "from" and no default was configured (EMAIL_FROM).');
|
|
58
|
+
}
|
|
59
|
+
if (!message.text && !message.html) {
|
|
60
|
+
throw new Error('EmailModule: a message needs "text" or "html".');
|
|
61
|
+
}
|
|
62
|
+
return { ...message, from, replyTo: message.replyTo ?? defaults.replyTo };
|
|
63
|
+
}
|
|
64
|
+
function attachmentBuffer(content) {
|
|
65
|
+
return Buffer.isBuffer(content) ? content : Buffer.from(content, "utf8");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/email/adapters/brevo.email.ts
|
|
69
|
+
var PROVIDER = "brevo";
|
|
70
|
+
var DEFAULT_BASE_URL = "https://api.brevo.com/v3";
|
|
71
|
+
var BrevoEmail = class {
|
|
72
|
+
constructor(options, defaults = {}) {
|
|
73
|
+
this.options = options;
|
|
74
|
+
this.defaults = defaults;
|
|
75
|
+
if (!options.apiKey) throw new Error('EmailModule: provider "brevo" selected but no apiKey / BREVO_API_KEY set.');
|
|
76
|
+
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
77
|
+
this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
78
|
+
}
|
|
79
|
+
async send(input) {
|
|
80
|
+
const message = completeMessage(input, this.defaults);
|
|
81
|
+
const body = {
|
|
82
|
+
sender: parseAddress(message.from),
|
|
83
|
+
to: toList(message.to).map(parseAddress),
|
|
84
|
+
subject: message.subject
|
|
85
|
+
};
|
|
86
|
+
const cc = toList(message.cc).map(parseAddress);
|
|
87
|
+
const bcc = toList(message.bcc).map(parseAddress);
|
|
88
|
+
if (cc.length) body.cc = cc;
|
|
89
|
+
if (bcc.length) body.bcc = bcc;
|
|
90
|
+
if (message.replyTo) body.replyTo = parseAddress(message.replyTo);
|
|
91
|
+
if (message.html) body.htmlContent = message.html;
|
|
92
|
+
if (message.text) body.textContent = message.text;
|
|
93
|
+
if (message.headers) body.headers = message.headers;
|
|
94
|
+
if (message.tags) body.tags = Object.entries(message.tags).map(([k, v]) => `${k}:${v}`);
|
|
95
|
+
if (message.attachments?.length) {
|
|
96
|
+
body.attachment = message.attachments.map((a) => ({
|
|
97
|
+
name: a.filename,
|
|
98
|
+
content: attachmentBuffer(a.content).toString("base64")
|
|
99
|
+
}));
|
|
100
|
+
}
|
|
101
|
+
let response;
|
|
102
|
+
try {
|
|
103
|
+
response = await this.fetchImpl(`${this.baseUrl}/smtp/email`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers: {
|
|
106
|
+
"api-key": this.options.apiKey,
|
|
107
|
+
"content-type": "application/json",
|
|
108
|
+
accept: "application/json"
|
|
109
|
+
},
|
|
110
|
+
body: JSON.stringify(body)
|
|
111
|
+
});
|
|
112
|
+
} catch (cause) {
|
|
113
|
+
throw new EmailProviderException(
|
|
114
|
+
PROVIDER,
|
|
115
|
+
0,
|
|
116
|
+
{ error: cause instanceof Error ? cause.message : String(cause) },
|
|
117
|
+
`${PROVIDER} is unreachable`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
const text = await response.text();
|
|
121
|
+
let parsed = text;
|
|
122
|
+
try {
|
|
123
|
+
parsed = text ? JSON.parse(text) : void 0;
|
|
124
|
+
} catch {
|
|
125
|
+
}
|
|
126
|
+
if (!response.ok) throw new EmailProviderException(PROVIDER, response.status, parsed);
|
|
127
|
+
const id = parsed?.messageId ?? null;
|
|
128
|
+
return { id, provider: PROVIDER };
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/email/adapters/memory.email.ts
|
|
133
|
+
var MemoryEmail = class {
|
|
134
|
+
constructor(defaults = {}) {
|
|
135
|
+
this.defaults = defaults;
|
|
136
|
+
this.sent = [];
|
|
137
|
+
}
|
|
138
|
+
async send(message) {
|
|
139
|
+
this.sent.push(completeMessage(message, this.defaults));
|
|
140
|
+
return { id: `memory_${this.sent.length}`, provider: "memory" };
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/email/adapters/resend.email.ts
|
|
145
|
+
var PROVIDER2 = "resend";
|
|
146
|
+
var ResendEmail = class {
|
|
147
|
+
constructor(options, defaults = {}, client) {
|
|
148
|
+
this.options = options;
|
|
149
|
+
this.defaults = defaults;
|
|
150
|
+
if (!options.apiKey) throw new Error('EmailModule: provider "resend" selected but no apiKey / RESEND_API_KEY set.');
|
|
151
|
+
if (client) this.clientPromise = Promise.resolve(client);
|
|
152
|
+
}
|
|
153
|
+
client() {
|
|
154
|
+
this.clientPromise ??= import("resend").then(({ Resend }) => new Resend(this.options.apiKey));
|
|
155
|
+
return this.clientPromise;
|
|
156
|
+
}
|
|
157
|
+
async send(input) {
|
|
158
|
+
const message = completeMessage(input, this.defaults);
|
|
159
|
+
const client = await this.client();
|
|
160
|
+
const { data, error } = await client.emails.send({
|
|
161
|
+
from: formatAddress(message.from),
|
|
162
|
+
to: toList(message.to).map(formatAddress),
|
|
163
|
+
cc: toList(message.cc).map(formatAddress),
|
|
164
|
+
bcc: toList(message.bcc).map(formatAddress),
|
|
165
|
+
replyTo: message.replyTo ? formatAddress(message.replyTo) : void 0,
|
|
166
|
+
subject: message.subject,
|
|
167
|
+
html: message.html,
|
|
168
|
+
text: message.text,
|
|
169
|
+
headers: message.headers,
|
|
170
|
+
tags: message.tags ? Object.entries(message.tags).map(([name, value]) => ({ name, value })) : void 0,
|
|
171
|
+
attachments: message.attachments?.map((a) => ({
|
|
172
|
+
filename: a.filename,
|
|
173
|
+
content: attachmentBuffer(a.content),
|
|
174
|
+
contentType: a.contentType
|
|
175
|
+
}))
|
|
176
|
+
});
|
|
177
|
+
if (error) {
|
|
178
|
+
throw new EmailProviderException(PROVIDER2, statusOf(error), error, `${PROVIDER2}: ${error.message}`);
|
|
179
|
+
}
|
|
180
|
+
return { id: data?.id ?? null, provider: PROVIDER2 };
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
function statusOf(error) {
|
|
184
|
+
return typeof error.statusCode === "number" ? error.statusCode : 0;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/email/adapters/smtp.email.ts
|
|
188
|
+
var PROVIDER3 = "smtp";
|
|
189
|
+
var SmtpEmail = class {
|
|
190
|
+
constructor(options, defaults = {}, transport) {
|
|
191
|
+
this.options = options;
|
|
192
|
+
this.defaults = defaults;
|
|
193
|
+
if (!options.host) throw new Error('EmailModule: provider "smtp" selected but no host / SMTP_HOST set.');
|
|
194
|
+
if (transport) this.transportPromise = Promise.resolve(transport);
|
|
195
|
+
}
|
|
196
|
+
transport() {
|
|
197
|
+
this.transportPromise ??= import("nodemailer").then(
|
|
198
|
+
({ default: nodemailer }) => nodemailer.createTransport({
|
|
199
|
+
host: this.options.host,
|
|
200
|
+
port: this.options.port,
|
|
201
|
+
secure: this.options.secure ?? false,
|
|
202
|
+
auth: this.options.user ? { user: this.options.user, pass: this.options.password } : void 0
|
|
203
|
+
})
|
|
204
|
+
);
|
|
205
|
+
return this.transportPromise;
|
|
206
|
+
}
|
|
207
|
+
async send(input) {
|
|
208
|
+
const message = completeMessage(input, this.defaults);
|
|
209
|
+
const transport = await this.transport();
|
|
210
|
+
const headers = { ...message.headers };
|
|
211
|
+
for (const [name, value] of Object.entries(message.tags ?? {})) headers[`X-Tag-${name}`] = value;
|
|
212
|
+
try {
|
|
213
|
+
const info = await transport.sendMail({
|
|
214
|
+
from: formatAddress(message.from),
|
|
215
|
+
to: toList(message.to).map(formatAddress),
|
|
216
|
+
cc: toList(message.cc).map(formatAddress),
|
|
217
|
+
bcc: toList(message.bcc).map(formatAddress),
|
|
218
|
+
replyTo: message.replyTo ? formatAddress(message.replyTo) : void 0,
|
|
219
|
+
subject: message.subject,
|
|
220
|
+
text: message.text,
|
|
221
|
+
html: message.html,
|
|
222
|
+
headers,
|
|
223
|
+
attachments: message.attachments?.map((a) => ({
|
|
224
|
+
filename: a.filename,
|
|
225
|
+
content: attachmentBuffer(a.content),
|
|
226
|
+
contentType: a.contentType
|
|
227
|
+
}))
|
|
228
|
+
});
|
|
229
|
+
return { id: info?.messageId ?? null, provider: PROVIDER3 };
|
|
230
|
+
} catch (cause) {
|
|
231
|
+
const status = cause.responseCode ?? 0;
|
|
232
|
+
throw new EmailProviderException(
|
|
233
|
+
PROVIDER3,
|
|
234
|
+
status,
|
|
235
|
+
{ error: cause instanceof Error ? cause.message : String(cause) },
|
|
236
|
+
`${PROVIDER3}: ${cause instanceof Error ? cause.message : "send failed"}`
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
// src/email/email.module.ts
|
|
243
|
+
var env = (k) => process.env[k] || void 0;
|
|
244
|
+
function resolveEmailOptions(options = {}) {
|
|
245
|
+
return {
|
|
246
|
+
provider: options.provider ?? env("EMAIL_PROVIDER"),
|
|
247
|
+
from: options.from ?? env("EMAIL_FROM"),
|
|
248
|
+
replyTo: options.replyTo ?? env("EMAIL_REPLY_TO"),
|
|
249
|
+
resend: options.resend ?? (env("RESEND_API_KEY") ? { apiKey: env("RESEND_API_KEY") } : void 0),
|
|
250
|
+
smtp: options.smtp ?? (env("SMTP_HOST") ? {
|
|
251
|
+
host: env("SMTP_HOST"),
|
|
252
|
+
port: Number(env("SMTP_PORT") ?? 587),
|
|
253
|
+
secure: env("SMTP_SECURE") === "true",
|
|
254
|
+
user: env("SMTP_USER"),
|
|
255
|
+
password: env("SMTP_PASSWORD")
|
|
256
|
+
} : void 0),
|
|
257
|
+
brevo: options.brevo ?? (env("BREVO_API_KEY") ? { apiKey: env("BREVO_API_KEY"), baseUrl: env("BREVO_BASE_URL") } : void 0)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function createEmailAdapter(options = {}) {
|
|
261
|
+
const resolved = resolveEmailOptions(options);
|
|
262
|
+
const defaults = { from: resolved.from, replyTo: resolved.replyTo };
|
|
263
|
+
switch (resolved.provider) {
|
|
264
|
+
case "resend":
|
|
265
|
+
if (!resolved.resend) throw new Error('EmailModule: provider "resend" selected but no resend options / RESEND_API_KEY set.');
|
|
266
|
+
return new ResendEmail(resolved.resend, defaults);
|
|
267
|
+
case "smtp":
|
|
268
|
+
if (!resolved.smtp) throw new Error('EmailModule: provider "smtp" selected but no smtp options / SMTP_* env set.');
|
|
269
|
+
return new SmtpEmail(resolved.smtp, defaults);
|
|
270
|
+
case "brevo":
|
|
271
|
+
if (!resolved.brevo) throw new Error('EmailModule: provider "brevo" selected but no brevo options / BREVO_API_KEY set.');
|
|
272
|
+
return new BrevoEmail(resolved.brevo, defaults);
|
|
273
|
+
case "memory":
|
|
274
|
+
return new MemoryEmail(defaults);
|
|
275
|
+
case void 0:
|
|
276
|
+
throw new Error("EmailModule: no provider selected. Pass `provider` or set EMAIL_PROVIDER (resend | smtp | brevo | memory).");
|
|
277
|
+
default:
|
|
278
|
+
throw new Error(`EmailModule: unknown provider "${String(resolved.provider)}".`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
var EmailModule = class {
|
|
282
|
+
static forRoot(options = {}) {
|
|
283
|
+
const providers = [
|
|
284
|
+
{ provide: EMAIL_OPTIONS, useValue: options },
|
|
285
|
+
{ provide: EMAIL, useFactory: () => createEmailAdapter(options) }
|
|
286
|
+
];
|
|
287
|
+
return { module: EmailModule, providers, exports: [EMAIL, EMAIL_OPTIONS] };
|
|
288
|
+
}
|
|
289
|
+
static forRootAsync(config) {
|
|
290
|
+
const providers = [
|
|
291
|
+
{ provide: EMAIL_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },
|
|
292
|
+
{ provide: EMAIL, useFactory: (options) => createEmailAdapter(options), inject: [EMAIL_OPTIONS] }
|
|
293
|
+
];
|
|
294
|
+
return { module: EmailModule, imports: config.imports ?? [], providers, exports: [EMAIL, EMAIL_OPTIONS] };
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
EmailModule = __decorateClass([
|
|
298
|
+
Global(),
|
|
299
|
+
Module({})
|
|
300
|
+
], EmailModule);
|
|
301
|
+
export {
|
|
302
|
+
BrevoEmail,
|
|
303
|
+
EMAIL,
|
|
304
|
+
EMAIL_OPTIONS,
|
|
305
|
+
EmailModule,
|
|
306
|
+
EmailProviderException,
|
|
307
|
+
MemoryEmail,
|
|
308
|
+
ResendEmail,
|
|
309
|
+
SmtpEmail,
|
|
310
|
+
createEmailAdapter,
|
|
311
|
+
formatAddress,
|
|
312
|
+
parseAddress,
|
|
313
|
+
resolveEmailOptions
|
|
314
|
+
};
|
package/dist/errors/index.cjs
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-7SOM7EZP.cjs');
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var _chunkMSTXS3MUcjs = require('../chunk-MSTXS3MU.cjs');
|
|
5
|
-
require('../chunk-AXMW5JF7.cjs');
|
|
6
|
-
require('../chunk-Y72D5L6I.cjs');
|
|
7
|
-
require('../chunk-SDWHKPXI.cjs');
|
|
8
4
|
|
|
9
5
|
|
|
10
6
|
|
|
11
7
|
|
|
8
|
+
var _chunkHDFPSA2Vcjs = require('../chunk-HDFPSA2V.cjs');
|
|
12
9
|
|
|
13
10
|
|
|
14
|
-
var
|
|
11
|
+
var _chunkLSDY6ETGcjs = require('../chunk-LSDY6ETG.cjs');
|
|
15
12
|
|
|
16
13
|
|
|
17
14
|
var _chunkQ5Y33L7Bcjs = require('../chunk-Q5Y33L7B.cjs');
|
|
15
|
+
require('../chunk-AXMW5JF7.cjs');
|
|
16
|
+
require('../chunk-Y72D5L6I.cjs');
|
|
17
|
+
require('../chunk-SDWHKPXI.cjs');
|
|
18
18
|
require('../chunk-PNK5WMPP.cjs');
|
|
19
19
|
require('../chunk-2REOCMUD.cjs');
|
|
20
20
|
|
|
@@ -25,4 +25,4 @@ require('../chunk-2REOCMUD.cjs');
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter =
|
|
28
|
+
exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunkLSDY6ETGcjs.GlobalExceptionFilter; exports.NotFoundAppException = _chunkHDFPSA2Vcjs.NotFoundAppException; exports.UnauthorizedAppException = _chunkHDFPSA2Vcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkHDFPSA2Vcjs.ValidationAppException;
|
package/dist/errors/index.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import "../chunk-DQYAIQQ5.js";
|
|
2
|
-
import {
|
|
3
|
-
GlobalExceptionFilter
|
|
4
|
-
} from "../chunk-A2DGK4ZL.js";
|
|
5
|
-
import "../chunk-X4PQJZ4G.js";
|
|
6
|
-
import "../chunk-TCAMLNUZ.js";
|
|
7
|
-
import "../chunk-ETRUVZTJ.js";
|
|
8
2
|
import {
|
|
9
3
|
ConflictAppException,
|
|
10
4
|
ForbiddenAppException,
|
|
@@ -12,9 +6,15 @@ import {
|
|
|
12
6
|
UnauthorizedAppException,
|
|
13
7
|
ValidationAppException
|
|
14
8
|
} from "../chunk-ZFIDAX7K.js";
|
|
9
|
+
import {
|
|
10
|
+
GlobalExceptionFilter
|
|
11
|
+
} from "../chunk-2DUEQKOI.js";
|
|
15
12
|
import {
|
|
16
13
|
AppException
|
|
17
14
|
} from "../chunk-M3GQDRWR.js";
|
|
15
|
+
import "../chunk-X4PQJZ4G.js";
|
|
16
|
+
import "../chunk-TCAMLNUZ.js";
|
|
17
|
+
import "../chunk-ETRUVZTJ.js";
|
|
18
18
|
import "../chunk-VVMRZEIW.js";
|
|
19
19
|
import "../chunk-4MGIQFAJ.js";
|
|
20
20
|
export {
|
package/dist/index.cjs
CHANGED
|
@@ -3,67 +3,67 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
var _chunkRF75KC63cjs = require('./chunk-RF75KC63.cjs');
|
|
6
|
+
require('./chunk-KVBQBT3D.cjs');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
var _chunkSPTDXUEDcjs = require('./chunk-SPTDXUED.cjs');
|
|
11
|
-
require('./chunk-H2EHN366.cjs');
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
var _chunkHVHYZXBBcjs = require('./chunk-HVHYZXBB.cjs');
|
|
17
|
-
require('./chunk-KVBQBT3D.cjs');
|
|
18
17
|
require('./chunk-7SOM7EZP.cjs');
|
|
18
|
+
require('./chunk-H2EHN366.cjs');
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var _chunkFNUZGYUFcjs = require('./chunk-FNUZGYUF.cjs');
|
|
22
21
|
|
|
23
22
|
|
|
24
|
-
var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
|
|
25
23
|
|
|
26
24
|
|
|
27
|
-
var
|
|
25
|
+
var _chunkHDFPSA2Vcjs = require('./chunk-HDFPSA2V.cjs');
|
|
28
26
|
|
|
29
27
|
|
|
28
|
+
var _chunkFQRF37NGcjs = require('./chunk-FQRF37NG.cjs');
|
|
30
29
|
|
|
31
30
|
|
|
32
|
-
var
|
|
33
|
-
require('./chunk-W2T2VFLC.cjs');
|
|
31
|
+
var _chunkLSDY6ETGcjs = require('./chunk-LSDY6ETG.cjs');
|
|
34
32
|
|
|
35
33
|
|
|
36
|
-
var
|
|
34
|
+
var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
|
|
37
35
|
|
|
38
36
|
|
|
39
37
|
|
|
40
38
|
|
|
39
|
+
var _chunk52IOOHNXcjs = require('./chunk-52IOOHNX.cjs');
|
|
40
|
+
require('./chunk-W2T2VFLC.cjs');
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
var
|
|
43
|
+
var _chunkQ5Y33L7Bcjs = require('./chunk-Q5Y33L7B.cjs');
|
|
44
44
|
|
|
45
45
|
|
|
46
|
+
var _chunkQS2W5XCQcjs = require('./chunk-QS2W5XCQ.cjs');
|
|
46
47
|
|
|
47
48
|
|
|
48
|
-
var _chunkAXMW5JF7cjs = require('./chunk-AXMW5JF7.cjs');
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
53
|
-
var
|
|
53
|
+
var _chunkAPUFKA4Kcjs = require('./chunk-APUFKA4K.cjs');
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
|
|
57
56
|
|
|
58
57
|
|
|
58
|
+
var _chunkAXMW5JF7cjs = require('./chunk-AXMW5JF7.cjs');
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
|
|
63
|
-
var
|
|
63
|
+
var _chunkY72D5L6Icjs = require('./chunk-Y72D5L6I.cjs');
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
var
|
|
66
|
+
var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
|
|
@@ -108,4 +108,4 @@ require('./chunk-2REOCMUD.cjs');
|
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
|
|
111
|
-
exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.BaseCrudService = _chunk52IOOHNXcjs.BaseCrudService; exports.BaseResponseDto = _chunkQS2W5XCQcjs.BaseResponseDto; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter =
|
|
111
|
+
exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.BaseCrudService = _chunk52IOOHNXcjs.BaseCrudService; exports.BaseResponseDto = _chunkQS2W5XCQcjs.BaseResponseDto; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunkLSDY6ETGcjs.GlobalExceptionFilter; exports.I18nInterceptor = _chunkAPUFKA4Kcjs.I18nInterceptor; exports.I18nMessage = _chunkPNK5WMPPcjs.I18nMessage; exports.I18nModule = _chunkAPUFKA4Kcjs.I18nModule; exports.ListQuery = _chunk52IOOHNXcjs.ListQuery; exports.NestI18nTranslator = _chunkAPUFKA4Kcjs.NestI18nTranslator; exports.NotFoundAppException = _chunkHDFPSA2Vcjs.NotFoundAppException; exports.PG_POOL = _chunkRF75KC63cjs.PG_POOL; exports.PgModule = _chunkRF75KC63cjs.PgModule; exports.REQUEST_ID_HEADER = _chunkHVHYZXBBcjs.REQUEST_ID_HEADER; exports.RequestContext = _chunkSDWHKPXIcjs.RequestContext; exports.RequestIdMiddleware = _chunkHVHYZXBBcjs.RequestIdMiddleware; exports.ResponseInterceptor = _chunk3AUOOEQOcjs.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 = _chunkHVHYZXBBcjs.TrackingModule; exports.UnauthorizedAppException = _chunkHDFPSA2Vcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkHDFPSA2Vcjs.ValidationAppException; exports.applyNestKitDefaults = _chunkFQRF37NGcjs.applyNestKitDefaults; exports.buildPageMeta = _chunkY72D5L6Icjs.buildPageMeta; exports.createCrudController = _chunk52IOOHNXcjs.createCrudController; exports.currentLanguage = _chunkAXMW5JF7cjs.currentLanguage; exports.isI18nMessage = _chunkPNK5WMPPcjs.isI18nMessage; exports.isPaginated = _chunkY72D5L6Icjs.isPaginated; exports.matchLanguage = _chunkAPUFKA4Kcjs.matchLanguage; exports.paginated = _chunkY72D5L6Icjs.paginated; exports.t = _chunkPNK5WMPPcjs.t; exports.translate = _chunkAXMW5JF7cjs.translate; exports.translateDeep = _chunkAXMW5JF7cjs.translateDeep; exports.translateOr = _chunkAPUFKA4Kcjs.translateOr; exports.withTenantScope = _chunkRF75KC63cjs.withTenantScope;
|
package/dist/index.js
CHANGED
|
@@ -3,34 +3,44 @@ import {
|
|
|
3
3
|
PgModule,
|
|
4
4
|
withTenantScope
|
|
5
5
|
} from "./chunk-VKOPDDCC.js";
|
|
6
|
+
import "./chunk-EPVKCBPT.js";
|
|
6
7
|
import {
|
|
7
8
|
SUPABASE_ANON_CLIENT,
|
|
8
9
|
SUPABASE_SERVICE_ROLE_CLIENT,
|
|
9
10
|
SupabaseModule
|
|
10
11
|
} from "./chunk-PA24P76K.js";
|
|
11
|
-
import "./chunk-ODPSIFOB.js";
|
|
12
12
|
import {
|
|
13
13
|
REQUEST_ID_HEADER,
|
|
14
14
|
RequestIdMiddleware,
|
|
15
15
|
TrackingModule
|
|
16
16
|
} from "./chunk-4PFAKLT3.js";
|
|
17
|
-
import "./chunk-EPVKCBPT.js";
|
|
18
17
|
import "./chunk-DQYAIQQ5.js";
|
|
18
|
+
import "./chunk-ODPSIFOB.js";
|
|
19
|
+
import {
|
|
20
|
+
ConflictAppException,
|
|
21
|
+
ForbiddenAppException,
|
|
22
|
+
NotFoundAppException,
|
|
23
|
+
UnauthorizedAppException,
|
|
24
|
+
ValidationAppException
|
|
25
|
+
} from "./chunk-ZFIDAX7K.js";
|
|
19
26
|
import {
|
|
20
27
|
applyNestKitDefaults
|
|
21
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-PLEY5EZT.js";
|
|
29
|
+
import {
|
|
30
|
+
GlobalExceptionFilter
|
|
31
|
+
} from "./chunk-2DUEQKOI.js";
|
|
22
32
|
import {
|
|
23
33
|
ResponseInterceptor
|
|
24
34
|
} from "./chunk-DYHSOULW.js";
|
|
25
|
-
import {
|
|
26
|
-
GlobalExceptionFilter
|
|
27
|
-
} from "./chunk-A2DGK4ZL.js";
|
|
28
35
|
import {
|
|
29
36
|
BaseCrudService,
|
|
30
37
|
ListQuery,
|
|
31
38
|
createCrudController
|
|
32
39
|
} from "./chunk-IFNYRZP2.js";
|
|
33
40
|
import "./chunk-ZJMLEP5H.js";
|
|
41
|
+
import {
|
|
42
|
+
AppException
|
|
43
|
+
} from "./chunk-M3GQDRWR.js";
|
|
34
44
|
import {
|
|
35
45
|
BaseResponseDto
|
|
36
46
|
} from "./chunk-XX2HPTRU.js";
|
|
@@ -54,16 +64,6 @@ import {
|
|
|
54
64
|
import {
|
|
55
65
|
RequestContext
|
|
56
66
|
} from "./chunk-ETRUVZTJ.js";
|
|
57
|
-
import {
|
|
58
|
-
ConflictAppException,
|
|
59
|
-
ForbiddenAppException,
|
|
60
|
-
NotFoundAppException,
|
|
61
|
-
UnauthorizedAppException,
|
|
62
|
-
ValidationAppException
|
|
63
|
-
} from "./chunk-ZFIDAX7K.js";
|
|
64
|
-
import {
|
|
65
|
-
AppException
|
|
66
|
-
} from "./chunk-M3GQDRWR.js";
|
|
67
67
|
import {
|
|
68
68
|
I18nMessage,
|
|
69
69
|
isI18nMessage,
|
|
@@ -24,6 +24,7 @@ export declare class FacturamaInvoicing implements InvoicingPort {
|
|
|
24
24
|
/** True while this adapter points at the sandbox host. */
|
|
25
25
|
get isSandbox(): boolean;
|
|
26
26
|
private headers;
|
|
27
|
+
/** `draft.idempotencyKey` is intentionally unused: Facturama's API has no equivalent. */
|
|
27
28
|
issue(draft: InvoiceDraft): Promise<Invoice>;
|
|
28
29
|
get(id: string): Promise<Invoice>;
|
|
29
30
|
/**
|
package/dist/invoicing/index.cjs
CHANGED
|
@@ -215,7 +215,10 @@ var FacturapiInvoicing = class {
|
|
|
215
215
|
const lines = computeLines(draft.items);
|
|
216
216
|
const invoice = await requestJson(PROVIDER, this.fetchImpl, `${this.baseUrl}/invoices`, {
|
|
217
217
|
method: "POST",
|
|
218
|
-
|
|
218
|
+
// The header is redundant with `idempotency_key` in the body — Facturapi only reads the
|
|
219
|
+
// body field — but it lets a generic resilience wrapper that sniffs for an
|
|
220
|
+
// `*idempotency*` header (rather than parsing the body) know this POST is safe to retry.
|
|
221
|
+
headers: draft.idempotencyKey ? { ...this.headers(), "idempotency-key": draft.idempotencyKey } : this.headers(),
|
|
219
222
|
body: JSON.stringify({
|
|
220
223
|
customer: typeof draft.customer === "string" ? draft.customer : {
|
|
221
224
|
legal_name: draft.customer.legalName,
|
|
@@ -251,7 +254,8 @@ var FacturapiInvoicing = class {
|
|
|
251
254
|
exchange: draft.exchangeRate,
|
|
252
255
|
series: draft.series,
|
|
253
256
|
folio_number: draft.folioNumber,
|
|
254
|
-
external_id: draft.externalId
|
|
257
|
+
external_id: draft.externalId,
|
|
258
|
+
idempotency_key: draft.idempotencyKey
|
|
255
259
|
})
|
|
256
260
|
});
|
|
257
261
|
return this.toInvoice(invoice);
|
|
@@ -357,6 +361,7 @@ var FacturamaInvoicing = class {
|
|
|
357
361
|
headers() {
|
|
358
362
|
return { authorization: `Basic ${this.token}`, "content-type": "application/json" };
|
|
359
363
|
}
|
|
364
|
+
/** `draft.idempotencyKey` is intentionally unused: Facturama's API has no equivalent. */
|
|
360
365
|
async issue(draft) {
|
|
361
366
|
if (typeof draft.customer === "string") {
|
|
362
367
|
throw new UnsupportedByProviderException(
|
package/dist/invoicing/index.js
CHANGED
|
@@ -215,7 +215,10 @@ var FacturapiInvoicing = class {
|
|
|
215
215
|
const lines = computeLines(draft.items);
|
|
216
216
|
const invoice = await requestJson(PROVIDER, this.fetchImpl, `${this.baseUrl}/invoices`, {
|
|
217
217
|
method: "POST",
|
|
218
|
-
|
|
218
|
+
// The header is redundant with `idempotency_key` in the body — Facturapi only reads the
|
|
219
|
+
// body field — but it lets a generic resilience wrapper that sniffs for an
|
|
220
|
+
// `*idempotency*` header (rather than parsing the body) know this POST is safe to retry.
|
|
221
|
+
headers: draft.idempotencyKey ? { ...this.headers(), "idempotency-key": draft.idempotencyKey } : this.headers(),
|
|
219
222
|
body: JSON.stringify({
|
|
220
223
|
customer: typeof draft.customer === "string" ? draft.customer : {
|
|
221
224
|
legal_name: draft.customer.legalName,
|
|
@@ -251,7 +254,8 @@ var FacturapiInvoicing = class {
|
|
|
251
254
|
exchange: draft.exchangeRate,
|
|
252
255
|
series: draft.series,
|
|
253
256
|
folio_number: draft.folioNumber,
|
|
254
|
-
external_id: draft.externalId
|
|
257
|
+
external_id: draft.externalId,
|
|
258
|
+
idempotency_key: draft.idempotencyKey
|
|
255
259
|
})
|
|
256
260
|
});
|
|
257
261
|
return this.toInvoice(invoice);
|
|
@@ -357,6 +361,7 @@ var FacturamaInvoicing = class {
|
|
|
357
361
|
headers() {
|
|
358
362
|
return { authorization: `Basic ${this.token}`, "content-type": "application/json" };
|
|
359
363
|
}
|
|
364
|
+
/** `draft.idempotencyKey` is intentionally unused: Facturama's API has no equivalent. */
|
|
360
365
|
async issue(draft) {
|
|
361
366
|
if (typeof draft.customer === "string") {
|
|
362
367
|
throw new UnsupportedByProviderException(
|
|
@@ -99,6 +99,16 @@ export interface InvoiceDraft {
|
|
|
99
99
|
folioNumber?: number;
|
|
100
100
|
/** Your own id for this invoice, echoed back by the provider. */
|
|
101
101
|
externalId?: string;
|
|
102
|
+
/**
|
|
103
|
+
* A key unique to this **attempt** to issue the invoice — not to the sale.
|
|
104
|
+
* When set, Facturapi returns the same invoice instead of stamping a second
|
|
105
|
+
* one if the request is sent twice (a timeout or a dropped connection after
|
|
106
|
+
* it already stamped). Generate a fresh one per call to `issue()`; reusing
|
|
107
|
+
* the same key across a deliberate re-issue (e.g. after cancelling) makes
|
|
108
|
+
* the provider hand back the old, cancelled document instead of a new one.
|
|
109
|
+
* Facturapi only — Facturama has no equivalent and ignores this field.
|
|
110
|
+
*/
|
|
111
|
+
idempotencyKey?: string;
|
|
102
112
|
}
|
|
103
113
|
export interface Invoice {
|
|
104
114
|
/** The provider's id — what every other method here takes. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miguelmorales13/nestkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -91,6 +91,11 @@
|
|
|
91
91
|
"import": "./dist/auth/oauth/index.js",
|
|
92
92
|
"require": "./dist/auth/oauth/index.cjs"
|
|
93
93
|
},
|
|
94
|
+
"./email": {
|
|
95
|
+
"types": "./dist/email/index.d.ts",
|
|
96
|
+
"import": "./dist/email/index.js",
|
|
97
|
+
"require": "./dist/email/index.cjs"
|
|
98
|
+
},
|
|
94
99
|
"./email/resend": {
|
|
95
100
|
"types": "./dist/email/resend/index.d.ts",
|
|
96
101
|
"import": "./dist/email/resend/index.js",
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AppException
|
|
3
|
+
} from "./chunk-M3GQDRWR.js";
|
|
1
4
|
import {
|
|
2
5
|
getI18nRuntime,
|
|
3
6
|
translate,
|
|
@@ -6,9 +9,6 @@ import {
|
|
|
6
9
|
import {
|
|
7
10
|
RequestContext
|
|
8
11
|
} from "./chunk-ETRUVZTJ.js";
|
|
9
|
-
import {
|
|
10
|
-
AppException
|
|
11
|
-
} from "./chunk-M3GQDRWR.js";
|
|
12
12
|
import {
|
|
13
13
|
__decorateClass
|
|
14
14
|
} from "./chunk-4MGIQFAJ.js";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkHDFPSA2Vcjs = require('./chunk-HDFPSA2V.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
|