@miguelmorales13/nestkit 0.16.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +212 -61
  2. package/dist/audit/index.cjs +12 -12
  3. package/dist/audit/index.js +2 -2
  4. package/dist/auth/index.cjs +12 -11
  5. package/dist/auth/index.js +5 -4
  6. package/dist/auth/oauth/http.d.ts +10 -3
  7. package/dist/auth/oauth/index.cjs +189 -30
  8. package/dist/auth/oauth/index.d.ts +6 -4
  9. package/dist/auth/oauth/index.js +169 -10
  10. package/dist/auth/oauth/magic-link.dto.d.ts +6 -0
  11. package/dist/auth/oauth/memory-magic-link.store.d.ts +19 -0
  12. package/dist/auth/oauth/oauth-auth.service.d.ts +46 -5
  13. package/dist/auth/oauth/oauth.controller.d.ts +5 -1
  14. package/dist/auth/oauth/oauth.options.d.ts +34 -1
  15. package/dist/auth/oauth/oauth.ports.d.ts +38 -0
  16. package/dist/bootstrap/index.cjs +8 -6
  17. package/dist/bootstrap/index.js +7 -5
  18. package/dist/{chunk-UWDHAZVE.cjs → chunk-3AUOOEQO.cjs} +2 -2
  19. package/dist/{chunk-JV4EAOF2.js → chunk-4PFAKLT3.js} +1 -1
  20. package/dist/{chunk-47FXU74G.cjs → chunk-52IOOHNX.cjs} +2 -2
  21. package/dist/chunk-6RAPVLJM.js +212 -0
  22. package/dist/{chunk-KRC47OX6.js → chunk-A2DGK4ZL.js} +26 -3
  23. package/dist/chunk-APUFKA4K.cjs +212 -0
  24. package/dist/chunk-AXMW5JF7.cjs +83 -0
  25. package/dist/{chunk-DABTRWA6.js → chunk-DYHSOULW.js} +1 -1
  26. package/dist/{chunk-KP2ZHJSR.js → chunk-ETRUVZTJ.js} +8 -0
  27. package/dist/{chunk-C5DV4RAX.cjs → chunk-FH5UNWWW.cjs} +6 -6
  28. package/dist/{chunk-4GT66KQS.cjs → chunk-FNUZGYUF.cjs} +4 -4
  29. package/dist/{chunk-FDNGAYTZ.cjs → chunk-HDFPSA2V.cjs} +6 -6
  30. package/dist/{chunk-U7QK24HL.cjs → chunk-HVHYZXBB.cjs} +2 -2
  31. package/dist/{chunk-LK3OINS7.js → chunk-IFNYRZP2.js} +1 -1
  32. package/dist/{chunk-YFYHLYHN.js → chunk-M3GQDRWR.js} +7 -1
  33. package/dist/{chunk-67B7IYAV.cjs → chunk-MSTXS3MU.cjs} +28 -5
  34. package/dist/chunk-PNK5WMPP.cjs +30 -0
  35. package/dist/chunk-Q5Y33L7B.cjs +19 -0
  36. package/dist/{chunk-EBPEMVZU.cjs → chunk-SDWHKPXI.cjs} +8 -0
  37. package/dist/{chunk-MLOQDUBN.js → chunk-TUNDBBQF.js} +4 -4
  38. package/dist/{chunk-UIVBPNH4.js → chunk-UNEVXCFW.js} +4 -4
  39. package/dist/chunk-VVMRZEIW.js +30 -0
  40. package/dist/{chunk-XX5ROVSC.cjs → chunk-W2T2VFLC.cjs} +3 -3
  41. package/dist/chunk-X4PQJZ4G.js +83 -0
  42. package/dist/{chunk-ORWJ7LES.js → chunk-ZFIDAX7K.js} +1 -1
  43. package/dist/{chunk-XHW4CTBS.js → chunk-ZJMLEP5H.js} +1 -1
  44. package/dist/crud/index.cjs +4 -4
  45. package/dist/crud/index.js +3 -3
  46. package/dist/email/adapters/brevo.email.d.ts +22 -0
  47. package/dist/email/adapters/memory.email.d.ts +14 -0
  48. package/dist/email/adapters/message.d.ts +13 -0
  49. package/dist/email/adapters/resend.email.d.ts +28 -0
  50. package/dist/email/adapters/smtp.email.d.ts +22 -0
  51. package/dist/email/address.d.ts +15 -0
  52. package/dist/email/email.module.d.ts +37 -0
  53. package/dist/email/email.options.d.ts +39 -0
  54. package/dist/email/email.port.d.ts +62 -0
  55. package/dist/email/index.cjs +314 -0
  56. package/dist/email/index.d.ts +12 -0
  57. package/dist/email/index.js +314 -0
  58. package/dist/errors/app.exception.d.ts +9 -1
  59. package/dist/errors/common.exceptions.d.ts +6 -5
  60. package/dist/errors/global-exception.filter.d.ts +9 -0
  61. package/dist/errors/index.cjs +8 -5
  62. package/dist/errors/index.js +9 -6
  63. package/dist/i18n/i18n.interceptor.d.ts +16 -0
  64. package/dist/i18n/i18n.module.d.ts +49 -3
  65. package/dist/i18n/index.cjs +26 -2
  66. package/dist/i18n/index.d.ts +8 -0
  67. package/dist/i18n/index.js +25 -1
  68. package/dist/i18n/locale.d.ts +53 -0
  69. package/dist/i18n/message.d.ts +36 -0
  70. package/dist/i18n/nestjs-i18n.translator.d.ts +9 -0
  71. package/dist/i18n/runtime.d.ts +55 -0
  72. package/dist/i18n/translator.port.d.ts +29 -0
  73. package/dist/idempotency/index.cjs +6 -5
  74. package/dist/idempotency/index.js +3 -2
  75. package/dist/index.cjs +38 -16
  76. package/dist/index.js +47 -25
  77. package/dist/invoicing/index.cjs +14 -13
  78. package/dist/invoicing/index.js +3 -2
  79. package/dist/payments/index.cjs +15 -14
  80. package/dist/payments/index.js +3 -2
  81. package/dist/response/index.cjs +3 -3
  82. package/dist/response/index.js +2 -2
  83. package/dist/stripe/index.cjs +4 -3
  84. package/dist/stripe/index.js +3 -2
  85. package/dist/tracking/index.cjs +3 -3
  86. package/dist/tracking/index.js +2 -2
  87. package/dist/tracking/request-context.d.ts +10 -0
  88. package/package.json +6 -1
  89. package/dist/chunk-IYUUYCP5.js +0 -36
  90. package/dist/chunk-M3EL5O6T.cjs +0 -36
  91. package/dist/chunk-R7BVS6CI.cjs +0 -13
@@ -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
+ };
@@ -1,11 +1,19 @@
1
1
  import { HttpException, type HttpStatus } from '@nestjs/common';
2
+ import { type I18nMessage } from '../i18n/message.js';
2
3
  /**
3
4
  * Base for all domain/application exceptions in nestkit-based services.
4
5
  * Carries a stable machine-readable `code` (independent from the HTTP
5
6
  * status) that clients can branch on, plus optional structured `details`.
7
+ *
8
+ * The message may be a lazy {@link I18nMessage}: `GlobalExceptionFilter`
9
+ * translates it in the request's language, and `message` (what Nest and the
10
+ * logs see) holds its fallback meanwhile. `details` may contain messages too
11
+ * — a per-field validation map, say — and is translated the same way.
6
12
  */
7
13
  export declare class AppException extends HttpException {
8
14
  readonly code: string;
9
15
  readonly details?: unknown;
10
- constructor(code: string, message: string, status: HttpStatus, details?: unknown);
16
+ /** The untranslated message, when one was given. */
17
+ readonly i18n?: I18nMessage;
18
+ constructor(code: string, message: string | I18nMessage, status: HttpStatus, details?: unknown);
11
19
  }
@@ -1,16 +1,17 @@
1
+ import type { I18nMessage } from '../i18n/message.js';
1
2
  import { AppException } from './app.exception.js';
2
3
  export declare class NotFoundAppException extends AppException {
3
- constructor(message?: string, details?: unknown, code?: string);
4
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
4
5
  }
5
6
  export declare class ConflictAppException extends AppException {
6
- constructor(message?: string, details?: unknown, code?: string);
7
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
7
8
  }
8
9
  export declare class ValidationAppException extends AppException {
9
- constructor(message?: string, details?: unknown, code?: string);
10
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
10
11
  }
11
12
  export declare class UnauthorizedAppException extends AppException {
12
- constructor(message?: string, details?: unknown, code?: string);
13
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
13
14
  }
14
15
  export declare class ForbiddenAppException extends AppException {
15
- constructor(message?: string, details?: unknown, code?: string);
16
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
16
17
  }
@@ -5,9 +5,18 @@ import { type ArgumentsHost, type ExceptionFilter } from '@nestjs/common';
5
5
  * with `app.useGlobalFilters(new GlobalExceptionFilter())` (or via
6
6
  * `applyNestKitDefaults`). Never leaks a stack trace to the client — it only
7
7
  * goes to the Nest Logger.
8
+ *
9
+ * When `I18nModule` is wired, the error speaks the request's language: an
10
+ * `AppException` built with `t()` is translated, its `details` are walked for
11
+ * messages, and one built with a plain string is looked up by `code` under the
12
+ * configured namespace (`errors.NOT_FOUND`) so a consumer can translate every
13
+ * error the package itself throws without touching a single `throw`. The
14
+ * language is resolved here from the request rather than read from
15
+ * `RequestContext`, because a guard fails before `I18nInterceptor` runs.
8
16
  */
9
17
  export declare class GlobalExceptionFilter implements ExceptionFilter {
10
18
  private readonly logger;
11
19
  catch(exception: unknown, host: ArgumentsHost): void;
20
+ private localize;
12
21
  private resolve;
13
22
  }
@@ -1,18 +1,21 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-7SOM7EZP.cjs');
2
2
 
3
3
 
4
- var _chunk67B7IYAVcjs = require('../chunk-67B7IYAV.cjs');
5
- require('../chunk-EBPEMVZU.cjs');
6
4
 
7
5
 
8
6
 
9
7
 
8
+ var _chunkHDFPSA2Vcjs = require('../chunk-HDFPSA2V.cjs');
10
9
 
11
10
 
12
- var _chunkFDNGAYTZcjs = require('../chunk-FDNGAYTZ.cjs');
11
+ var _chunkMSTXS3MUcjs = require('../chunk-MSTXS3MU.cjs');
12
+ require('../chunk-AXMW5JF7.cjs');
13
+ require('../chunk-Y72D5L6I.cjs');
14
+ require('../chunk-SDWHKPXI.cjs');
13
15
 
14
16
 
15
- var _chunkR7BVS6CIcjs = require('../chunk-R7BVS6CI.cjs');
17
+ var _chunkQ5Y33L7Bcjs = require('../chunk-Q5Y33L7B.cjs');
18
+ require('../chunk-PNK5WMPP.cjs');
16
19
  require('../chunk-2REOCMUD.cjs');
17
20
 
18
21
 
@@ -22,4 +25,4 @@ require('../chunk-2REOCMUD.cjs');
22
25
 
23
26
 
24
27
 
25
- exports.AppException = _chunkR7BVS6CIcjs.AppException; exports.ConflictAppException = _chunkFDNGAYTZcjs.ConflictAppException; exports.ForbiddenAppException = _chunkFDNGAYTZcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunk67B7IYAVcjs.GlobalExceptionFilter; exports.NotFoundAppException = _chunkFDNGAYTZcjs.NotFoundAppException; exports.UnauthorizedAppException = _chunkFDNGAYTZcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkFDNGAYTZcjs.ValidationAppException;
28
+ exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunkMSTXS3MUcjs.GlobalExceptionFilter; exports.NotFoundAppException = _chunkHDFPSA2Vcjs.NotFoundAppException; exports.UnauthorizedAppException = _chunkHDFPSA2Vcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkHDFPSA2Vcjs.ValidationAppException;
@@ -1,18 +1,21 @@
1
1
  import "../chunk-DQYAIQQ5.js";
2
- import {
3
- GlobalExceptionFilter
4
- } from "../chunk-KRC47OX6.js";
5
- import "../chunk-KP2ZHJSR.js";
6
2
  import {
7
3
  ConflictAppException,
8
4
  ForbiddenAppException,
9
5
  NotFoundAppException,
10
6
  UnauthorizedAppException,
11
7
  ValidationAppException
12
- } from "../chunk-ORWJ7LES.js";
8
+ } from "../chunk-ZFIDAX7K.js";
9
+ import {
10
+ GlobalExceptionFilter
11
+ } from "../chunk-A2DGK4ZL.js";
12
+ import "../chunk-X4PQJZ4G.js";
13
+ import "../chunk-TCAMLNUZ.js";
14
+ import "../chunk-ETRUVZTJ.js";
13
15
  import {
14
16
  AppException
15
- } from "../chunk-YFYHLYHN.js";
17
+ } from "../chunk-M3GQDRWR.js";
18
+ import "../chunk-VVMRZEIW.js";
16
19
  import "../chunk-4MGIQFAJ.js";
17
20
  export {
18
21
  AppException,
@@ -0,0 +1,16 @@
1
+ import { type CallHandler, type ExecutionContext, type NestInterceptor } from '@nestjs/common';
2
+ import type { Observable } from 'rxjs';
3
+ /**
4
+ * Resolves the request's language from the sources `I18nModule` was
5
+ * configured with, records it in `RequestContext` for the handler's benefit,
6
+ * and translates every {@link I18nMessage} in whatever the handler returns.
7
+ *
8
+ * `I18nModule.forRoot` registers it as a global `APP_INTERCEPTOR`, which
9
+ * Nest runs *inside* the ones added with `useGlobalInterceptors` — so on the
10
+ * way out it sees the raw return value before `ResponseInterceptor` wraps it
11
+ * in the envelope. It is harmless without the module: with no runtime it
12
+ * passes everything through untouched.
13
+ */
14
+ export declare class I18nInterceptor implements NestInterceptor {
15
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
16
+ }
@@ -1,4 +1,7 @@
1
- import { type DynamicModule } from '@nestjs/common';
1
+ import { type DynamicModule, type OnModuleDestroy, type OnModuleInit, type Type } from '@nestjs/common';
2
+ import { I18nService, type I18nLoader } from 'nestjs-i18n';
3
+ import { type LocaleOptions } from './locale.js';
4
+ import type { TranslatorPort } from './translator.port.js';
2
5
  export interface NestKitI18nOptions {
3
6
  /**
4
7
  * Path to the folder containing per-language JSON namespaces, relative to
@@ -8,11 +11,54 @@ export interface NestKitI18nOptions {
8
11
  path?: string;
9
12
  /** Defaults to 'es'. */
10
13
  fallbackLanguage?: string;
14
+ /** Where the request's language comes from. See {@link LocaleOptions}. */
15
+ locale?: LocaleOptions;
16
+ /**
17
+ * Namespace for the automatic lookup of an `AppException` by its `code`:
18
+ * with the default, `errors.NOT_FOUND` in `{path}/{lang}/errors.json`
19
+ * translates every `NotFoundAppException` that carries no explicit key.
20
+ * `false` turns the lookup off.
21
+ */
22
+ errorCodes?: string | false;
23
+ /**
24
+ * Pass `false` to skip registering `I18nInterceptor` globally. Responses
25
+ * are then not translated unless the consumer mounts the interceptor where
26
+ * it wants it; errors still are, since the filter reads the runtime directly.
27
+ */
28
+ interceptor?: boolean;
29
+ /**
30
+ * Reload the JSON files when they change on disk. Defaults to `true`
31
+ * outside `NODE_ENV=production`.
32
+ */
33
+ watch?: boolean;
34
+ /** A different `nestjs-i18n` loader (YAML, say). Ignored when `translator` is given. */
35
+ loader?: Type<I18nLoader>;
36
+ /**
37
+ * Bring your own backend. `nestjs-i18n` is then not wired at all: no files,
38
+ * no `I18nService` to inject — only this port, the locale resolution and
39
+ * the interceptor.
40
+ */
41
+ translator?: TranslatorPort;
11
42
  }
12
43
  /**
13
44
  * Thin wrapper over nestjs-i18n so consumers don't have to know its
14
- * loader/resolver configuration shape — just point it at a folder.
45
+ * loader/resolver configuration shape — just point it at a folder and say
46
+ * where the language comes from.
47
+ *
48
+ * Once the app starts it publishes the {@link TranslatorPort}, the locale
49
+ * resolver and the error-code namespace to the i18n runtime — the registry
50
+ * `GlobalExceptionFilter`, `translate()` and `I18nInterceptor` read, none of
51
+ * which can be injected into — and mounts the interceptor globally.
52
+ * `nestjs-i18n` itself gets a single resolver that delegates to that same
53
+ * runtime, so a consumer injecting `I18nService` directly gets the same
54
+ * language as the rest of the package.
15
55
  */
16
- export declare class I18nModule {
56
+ export declare class I18nModule implements OnModuleInit, OnModuleDestroy {
57
+ private readonly options;
58
+ private readonly i18n?;
17
59
  static forRoot(options?: NestKitI18nOptions): DynamicModule;
60
+ constructor(options: NestKitI18nOptions, i18n?: I18nService | undefined);
61
+ onModuleInit(): void;
62
+ onModuleDestroy(): void;
63
+ private requireService;
18
64
  }
@@ -1,9 +1,33 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkM3EL5O6Tcjs = require('../chunk-M3EL5O6T.cjs');
4
+
5
+
6
+
7
+ var _chunkAPUFKA4Kcjs = require('../chunk-APUFKA4K.cjs');
8
+
9
+
10
+
11
+
12
+ var _chunkAXMW5JF7cjs = require('../chunk-AXMW5JF7.cjs');
13
+ require('../chunk-Y72D5L6I.cjs');
14
+ require('../chunk-SDWHKPXI.cjs');
15
+
16
+
17
+
18
+
19
+ var _chunkPNK5WMPPcjs = require('../chunk-PNK5WMPP.cjs');
5
20
  require('../chunk-2REOCMUD.cjs');
6
21
 
7
22
 
8
23
 
9
- exports.I18nModule = _chunkM3EL5O6Tcjs.I18nModule; exports.translateOr = _chunkM3EL5O6Tcjs.translateOr;
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+ exports.I18nInterceptor = _chunkAPUFKA4Kcjs.I18nInterceptor; exports.I18nMessage = _chunkPNK5WMPPcjs.I18nMessage; exports.I18nModule = _chunkAPUFKA4Kcjs.I18nModule; exports.NestI18nTranslator = _chunkAPUFKA4Kcjs.NestI18nTranslator; exports.currentLanguage = _chunkAXMW5JF7cjs.currentLanguage; exports.isI18nMessage = _chunkPNK5WMPPcjs.isI18nMessage; exports.matchLanguage = _chunkAPUFKA4Kcjs.matchLanguage; exports.t = _chunkPNK5WMPPcjs.t; exports.translate = _chunkAXMW5JF7cjs.translate; exports.translateDeep = _chunkAXMW5JF7cjs.translateDeep; exports.translateOr = _chunkAPUFKA4Kcjs.translateOr;
@@ -1,3 +1,11 @@
1
1
  export { I18nModule } from './i18n.module.js';
2
2
  export type { NestKitI18nOptions } from './i18n.module.js';
3
+ export { I18nInterceptor } from './i18n.interceptor.js';
4
+ export { I18nMessage, t, isI18nMessage } from './message.js';
5
+ export type { TranslatorPort, TranslateOptions } from './translator.port.js';
6
+ export { NestI18nTranslator } from './nestjs-i18n.translator.js';
7
+ export { translate, translateDeep, currentLanguage } from './runtime.js';
8
+ export type { TranslateCallOptions } from './runtime.js';
9
+ export { matchLanguage } from './locale.js';
10
+ export type { LocaleOptions, LocaleSource, LocaleRequest, LocaleResolver } from './locale.js';
3
11
  export { translateOr } from './translate.helper.js';
@@ -1,9 +1,33 @@
1
1
  import {
2
+ I18nInterceptor,
2
3
  I18nModule,
4
+ NestI18nTranslator,
5
+ matchLanguage,
3
6
  translateOr
4
- } from "../chunk-IYUUYCP5.js";
7
+ } from "../chunk-6RAPVLJM.js";
8
+ import {
9
+ currentLanguage,
10
+ translate,
11
+ translateDeep
12
+ } from "../chunk-X4PQJZ4G.js";
13
+ import "../chunk-TCAMLNUZ.js";
14
+ import "../chunk-ETRUVZTJ.js";
15
+ import {
16
+ I18nMessage,
17
+ isI18nMessage,
18
+ t
19
+ } from "../chunk-VVMRZEIW.js";
5
20
  import "../chunk-4MGIQFAJ.js";
6
21
  export {
22
+ I18nInterceptor,
23
+ I18nMessage,
7
24
  I18nModule,
25
+ NestI18nTranslator,
26
+ currentLanguage,
27
+ isI18nMessage,
28
+ matchLanguage,
29
+ t,
30
+ translate,
31
+ translateDeep,
8
32
  translateOr
9
33
  };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Structural request shape, so locale resolution works on Express and
3
+ * Fastify alike (Fastify exposes the raw headers on `raw`; both expose
4
+ * `headers` and `query` directly).
5
+ */
6
+ export interface LocaleRequest {
7
+ headers?: Record<string, string | string[] | undefined>;
8
+ query?: Record<string, unknown>;
9
+ cookies?: Record<string, string | undefined>;
10
+ }
11
+ /**
12
+ * Where the language comes from. Listed in order of precedence: the first
13
+ * source that yields a supported language wins.
14
+ *
15
+ * - `query` — `?lang=en`; the name comes from `LocaleOptions.query`.
16
+ * - `header` — a custom header such as `x-lang`; `LocaleOptions.header`.
17
+ * - `cookie` — `LocaleOptions.cookie`; read from the `Cookie` header
18
+ * directly, so it works without `cookie-parser`.
19
+ * - `accept-language` — the browser's header, with `q` weights and region
20
+ * fallback (`es-MX` matches `es`).
21
+ * - a function — anything else: the tenant's default language, a
22
+ * user preference read by a guard, a path prefix.
23
+ */
24
+ export type LocaleSource = 'query' | 'header' | 'cookie' | 'accept-language' | ((req: LocaleRequest) => string | undefined);
25
+ export interface LocaleOptions {
26
+ /** Defaults to `['query', 'header', 'cookie', 'accept-language']`. */
27
+ from?: LocaleSource[];
28
+ /** Query parameter name. Defaults to `lang`. */
29
+ query?: string;
30
+ /** Header name, case-insensitive. Defaults to `x-lang`. */
31
+ header?: string;
32
+ /** Cookie name. Defaults to `lang`. */
33
+ cookie?: string;
34
+ }
35
+ export type LocaleResolver = (req: LocaleRequest) => string | undefined;
36
+ /**
37
+ * Compiles the options into one function the interceptor and the filter can
38
+ * call per request. Every candidate goes through {@link matchLanguage}, so a
39
+ * value the backend cannot answer in is skipped rather than passed along —
40
+ * the next source gets its turn, and the fallback language is what remains.
41
+ */
42
+ export declare function buildLocaleResolver(options: LocaleOptions, supportedLanguages: () => string[]): LocaleResolver;
43
+ /**
44
+ * Picks the best supported language out of a raw value, which may be a single
45
+ * tag (`en`, `es-MX`) or a full `Accept-Language` header
46
+ * (`es-MX,es;q=0.9,en;q=0.8`). Exact match first, then the base language of a
47
+ * regional tag, in the order the client stated its preferences.
48
+ *
49
+ * With no supported list (a backend that cannot enumerate its languages) the
50
+ * first tag is returned as-is, but only if it looks like a language tag —
51
+ * that is the last line between a query string and an `Intl` constructor.
52
+ */
53
+ export declare function matchLanguage(raw: string, supported: string[]): string | undefined;