@miguelmorales13/nestkit 0.16.0 → 0.18.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 (79) hide show
  1. package/README.md +152 -28
  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-C5DV4RAX.cjs → chunk-4HHZFOVC.cjs} +6 -6
  20. package/dist/{chunk-JV4EAOF2.js → chunk-4PFAKLT3.js} +1 -1
  21. package/dist/{chunk-47FXU74G.cjs → chunk-52IOOHNX.cjs} +2 -2
  22. package/dist/chunk-6RAPVLJM.js +212 -0
  23. package/dist/{chunk-KRC47OX6.js → chunk-A2DGK4ZL.js} +26 -3
  24. package/dist/chunk-APUFKA4K.cjs +212 -0
  25. package/dist/chunk-AXMW5JF7.cjs +83 -0
  26. package/dist/{chunk-DABTRWA6.js → chunk-DYHSOULW.js} +1 -1
  27. package/dist/{chunk-KP2ZHJSR.js → chunk-ETRUVZTJ.js} +8 -0
  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-MLOQDUBN.js → chunk-IKXSVEJ7.js} +2 -2
  33. package/dist/{chunk-YFYHLYHN.js → chunk-M3GQDRWR.js} +7 -1
  34. package/dist/{chunk-67B7IYAV.cjs → chunk-MSTXS3MU.cjs} +28 -5
  35. package/dist/chunk-PNK5WMPP.cjs +30 -0
  36. package/dist/chunk-Q5Y33L7B.cjs +19 -0
  37. package/dist/{chunk-EBPEMVZU.cjs → chunk-SDWHKPXI.cjs} +8 -0
  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/errors/app.exception.d.ts +9 -1
  47. package/dist/errors/common.exceptions.d.ts +6 -5
  48. package/dist/errors/global-exception.filter.d.ts +9 -0
  49. package/dist/errors/index.cjs +8 -5
  50. package/dist/errors/index.js +7 -4
  51. package/dist/i18n/i18n.interceptor.d.ts +16 -0
  52. package/dist/i18n/i18n.module.d.ts +49 -3
  53. package/dist/i18n/index.cjs +26 -2
  54. package/dist/i18n/index.d.ts +8 -0
  55. package/dist/i18n/index.js +25 -1
  56. package/dist/i18n/locale.d.ts +53 -0
  57. package/dist/i18n/message.d.ts +36 -0
  58. package/dist/i18n/nestjs-i18n.translator.d.ts +9 -0
  59. package/dist/i18n/runtime.d.ts +55 -0
  60. package/dist/i18n/translator.port.d.ts +29 -0
  61. package/dist/idempotency/index.cjs +6 -5
  62. package/dist/idempotency/index.js +3 -2
  63. package/dist/index.cjs +36 -14
  64. package/dist/index.js +41 -19
  65. package/dist/invoicing/index.cjs +14 -13
  66. package/dist/invoicing/index.js +3 -2
  67. package/dist/payments/index.cjs +15 -14
  68. package/dist/payments/index.js +3 -2
  69. package/dist/response/index.cjs +3 -3
  70. package/dist/response/index.js +2 -2
  71. package/dist/stripe/index.cjs +4 -3
  72. package/dist/stripe/index.js +3 -2
  73. package/dist/tracking/index.cjs +3 -3
  74. package/dist/tracking/index.js +2 -2
  75. package/dist/tracking/request-context.d.ts +10 -0
  76. package/package.json +1 -1
  77. package/dist/chunk-IYUUYCP5.js +0 -36
  78. package/dist/chunk-M3EL5O6T.cjs +0 -36
  79. package/dist/chunk-R7BVS6CI.cjs +0 -13
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  RequestContext
3
- } from "./chunk-KP2ZHJSR.js";
3
+ } from "./chunk-ETRUVZTJ.js";
4
4
  import {
5
5
  UnauthorizedAppException
6
- } from "./chunk-ORWJ7LES.js";
6
+ } from "./chunk-ZFIDAX7K.js";
7
7
  import {
8
8
  __decorateClass
9
9
  } from "./chunk-4MGIQFAJ.js";
@@ -1,10 +1,16 @@
1
+ import {
2
+ isI18nMessage
3
+ } from "./chunk-VVMRZEIW.js";
4
+
1
5
  // src/errors/app.exception.ts
2
6
  import { HttpException } from "@nestjs/common";
3
7
  var AppException = class extends HttpException {
4
8
  constructor(code, message, status, details) {
5
- super({ code, message, details }, status);
9
+ const text = isI18nMessage(message) ? message.toJSON() : message;
10
+ super({ code, message: text, details }, status);
6
11
  this.code = code;
7
12
  this.details = details;
13
+ if (isI18nMessage(message)) this.i18n = message;
8
14
  }
9
15
  };
10
16
 
@@ -1,9 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
2
 
3
- var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
4
3
 
5
4
 
6
- var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
5
+ var _chunkAXMW5JF7cjs = require('./chunk-AXMW5JF7.cjs');
6
+
7
+
8
+ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
9
+
10
+
11
+ var _chunkQ5Y33L7Bcjs = require('./chunk-Q5Y33L7B.cjs');
7
12
 
8
13
 
9
14
  var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
@@ -20,15 +25,19 @@ var GlobalExceptionFilter = class {
20
25
  this.logger = new (0, _common.Logger)(GlobalExceptionFilter.name);
21
26
  }
22
27
  catch(exception, host) {
23
- const response = host.switchToHttp().getResponse();
28
+ const http = host.switchToHttp();
29
+ const response = http.getResponse();
24
30
  const resolved = this.resolve(exception);
25
31
  if (resolved.status >= _common.HttpStatus.INTERNAL_SERVER_ERROR) {
26
32
  const stack = exception instanceof Error ? exception.stack : void 0;
27
33
  this.logger.error(`Unhandled exception: ${resolved.message}`, stack);
28
34
  }
35
+ if (exception instanceof _chunkQ5Y33L7Bcjs.AppException) {
36
+ this.localize(resolved, exception, http.getRequest());
37
+ }
29
38
  const body = {
30
39
  success: false,
31
- requestId: _nullishCoalesce(_chunkEBPEMVZUcjs.RequestContext.getRequestId(), () => ( "unknown")),
40
+ requestId: _nullishCoalesce(_chunkSDWHKPXIcjs.RequestContext.getRequestId(), () => ( "unknown")),
32
41
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
33
42
  error: {
34
43
  code: resolved.code,
@@ -38,8 +47,22 @@ var GlobalExceptionFilter = class {
38
47
  };
39
48
  response.status(resolved.status).send(body);
40
49
  }
50
+ localize(resolved, exception, request) {
51
+ const runtime = _chunkAXMW5JF7cjs.getI18nRuntime.call(void 0, );
52
+ if (!runtime) return;
53
+ const lang = _nullishCoalesce(runtime.resolveLocale(request), () => ( runtime.fallbackLanguage));
54
+ if (exception.i18n) {
55
+ resolved.message = _chunkAXMW5JF7cjs.translate.call(void 0, exception.i18n, { lang, defaultValue: resolved.message });
56
+ } else if (runtime.errorCodes !== false) {
57
+ resolved.message = _chunkAXMW5JF7cjs.translate.call(void 0, `${runtime.errorCodes}.${exception.code}`, {
58
+ lang,
59
+ defaultValue: resolved.message
60
+ });
61
+ }
62
+ resolved.details = _chunkAXMW5JF7cjs.translateDeep.call(void 0, resolved.details, lang);
63
+ }
41
64
  resolve(exception) {
42
- if (exception instanceof _chunkR7BVS6CIcjs.AppException) {
65
+ if (exception instanceof _chunkQ5Y33L7Bcjs.AppException) {
43
66
  return {
44
67
  status: exception.getStatus(),
45
68
  code: exception.code,
@@ -0,0 +1,30 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/i18n/message.ts
2
+ var I18N_MESSAGE = /* @__PURE__ */ Symbol.for("nestkit.i18n.message");
3
+ var _a;
4
+ _a = I18N_MESSAGE;
5
+ var I18nMessage = class {
6
+ constructor(key, args, fallback) {
7
+ this.key = key;
8
+ this.args = args;
9
+ this.fallback = fallback;
10
+ this[_a] = true;
11
+ }
12
+ toJSON() {
13
+ return _nullishCoalesce(this.fallback, () => ( this.key));
14
+ }
15
+ toString() {
16
+ return this.toJSON();
17
+ }
18
+ };
19
+ function t(key, args, fallback) {
20
+ return new I18nMessage(key, args, fallback);
21
+ }
22
+ function isI18nMessage(value) {
23
+ return typeof value === "object" && value !== null && value[I18N_MESSAGE] === true;
24
+ }
25
+
26
+
27
+
28
+
29
+
30
+ exports.I18nMessage = I18nMessage; exports.t = t; exports.isI18nMessage = isI18nMessage;
@@ -0,0 +1,19 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkPNK5WMPPcjs = require('./chunk-PNK5WMPP.cjs');
4
+
5
+ // src/errors/app.exception.ts
6
+ var _common = require('@nestjs/common');
7
+ var AppException = class extends _common.HttpException {
8
+ constructor(code, message, status, details) {
9
+ const text = _chunkPNK5WMPPcjs.isI18nMessage.call(void 0, message) ? message.toJSON() : message;
10
+ super({ code, message: text, details }, status);
11
+ this.code = code;
12
+ this.details = details;
13
+ if (_chunkPNK5WMPPcjs.isI18nMessage.call(void 0, message)) this.i18n = message;
14
+ }
15
+ };
16
+
17
+
18
+
19
+ exports.AppException = AppException;
@@ -28,6 +28,14 @@ var RequestContext = class {
28
28
  static getActor() {
29
29
  return _optionalChain([this, 'access', _5 => _5.storage, 'access', _6 => _6.getStore, 'call', _7 => _7(), 'optionalAccess', _8 => _8.actor]);
30
30
  }
31
+ /** Same contract as {@link setActor}: mutates the current store, no-op outside a request. */
32
+ static setLang(lang) {
33
+ const store = this.storage.getStore();
34
+ if (store) store.lang = lang;
35
+ }
36
+ static getLang() {
37
+ return _optionalChain([this, 'access', _9 => _9.storage, 'access', _10 => _10.getStore, 'call', _11 => _11(), 'optionalAccess', _12 => _12.lang]);
38
+ }
31
39
  };
32
40
 
33
41
 
@@ -1,9 +1,9 @@
1
- import {
2
- GlobalExceptionFilter
3
- } from "./chunk-KRC47OX6.js";
4
1
  import {
5
2
  ResponseInterceptor
6
- } from "./chunk-DABTRWA6.js";
3
+ } from "./chunk-DYHSOULW.js";
4
+ import {
5
+ GlobalExceptionFilter
6
+ } from "./chunk-A2DGK4ZL.js";
7
7
 
8
8
  // src/bootstrap/apply-defaults.ts
9
9
  import {
@@ -0,0 +1,30 @@
1
+ // src/i18n/message.ts
2
+ var I18N_MESSAGE = /* @__PURE__ */ Symbol.for("nestkit.i18n.message");
3
+ var _a;
4
+ _a = I18N_MESSAGE;
5
+ var I18nMessage = class {
6
+ constructor(key, args, fallback) {
7
+ this.key = key;
8
+ this.args = args;
9
+ this.fallback = fallback;
10
+ this[_a] = true;
11
+ }
12
+ toJSON() {
13
+ return this.fallback ?? this.key;
14
+ }
15
+ toString() {
16
+ return this.toJSON();
17
+ }
18
+ };
19
+ function t(key, args, fallback) {
20
+ return new I18nMessage(key, args, fallback);
21
+ }
22
+ function isI18nMessage(value) {
23
+ return typeof value === "object" && value !== null && value[I18N_MESSAGE] === true;
24
+ }
25
+
26
+ export {
27
+ I18nMessage,
28
+ t,
29
+ isI18nMessage
30
+ };
@@ -1,6 +1,6 @@
1
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
2
 
3
- var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
3
+ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
4
4
 
5
5
 
6
6
 
@@ -15,12 +15,12 @@ var AUDIT_OPTIONS = /* @__PURE__ */ Symbol("AUDIT_OPTIONS");
15
15
  // src/audit/audit.service.ts
16
16
  var _common = require('@nestjs/common');
17
17
  function withRequestContext(event) {
18
- const actor = _chunkEBPEMVZUcjs.RequestContext.getActor();
18
+ const actor = _chunkSDWHKPXIcjs.RequestContext.getActor();
19
19
  return {
20
20
  ...event,
21
21
  actorId: _nullishCoalesce(event.actorId, () => ( _optionalChain([actor, 'optionalAccess', _ => _.id]))),
22
22
  tenantId: _nullishCoalesce(event.tenantId, () => ( _optionalChain([actor, 'optionalAccess', _2 => _2.tenantId]))),
23
- requestId: _nullishCoalesce(event.requestId, () => ( _chunkEBPEMVZUcjs.RequestContext.getRequestId())),
23
+ requestId: _nullishCoalesce(event.requestId, () => ( _chunkSDWHKPXIcjs.RequestContext.getRequestId())),
24
24
  at: _nullishCoalesce(event.at, () => ( /* @__PURE__ */ new Date()))
25
25
  };
26
26
  }
@@ -0,0 +1,83 @@
1
+ import {
2
+ isPaginated,
3
+ paginated
4
+ } from "./chunk-TCAMLNUZ.js";
5
+ import {
6
+ RequestContext
7
+ } from "./chunk-ETRUVZTJ.js";
8
+ import {
9
+ I18nMessage,
10
+ isI18nMessage
11
+ } from "./chunk-VVMRZEIW.js";
12
+
13
+ // src/i18n/runtime.ts
14
+ var runtime;
15
+ function setI18nRuntime(next) {
16
+ runtime = next;
17
+ }
18
+ function getI18nRuntime() {
19
+ return runtime;
20
+ }
21
+ function currentLanguage() {
22
+ return RequestContext.getLang() ?? runtime?.fallbackLanguage;
23
+ }
24
+ function translate(input, options = {}) {
25
+ const message = typeof input === "string" ? new I18nMessage(input, options.args) : input;
26
+ const fallback = message.fallback ?? options.defaultValue ?? message.key;
27
+ if (!runtime) return fallback;
28
+ const lang = options.lang ?? currentLanguage();
29
+ try {
30
+ return runtime.translator.translate(message.key, { lang, args: message.args }) ?? fallback;
31
+ } catch {
32
+ return fallback;
33
+ }
34
+ }
35
+ function translateDeep(value, lang) {
36
+ if (!runtime) return value;
37
+ return walk(value, lang, /* @__PURE__ */ new WeakSet());
38
+ }
39
+ function walk(value, lang, seen) {
40
+ if (isI18nMessage(value)) return translate(value, { lang });
41
+ if (typeof value !== "object" || value === null) return value;
42
+ if (seen.has(value)) return value;
43
+ if (Array.isArray(value)) {
44
+ seen.add(value);
45
+ let copy2;
46
+ value.forEach((item, index) => {
47
+ const next = walk(item, lang, seen);
48
+ if (next !== item) {
49
+ copy2 ??= [...value];
50
+ copy2[index] = next;
51
+ }
52
+ });
53
+ return copy2 ?? value;
54
+ }
55
+ if (isPaginated(value)) {
56
+ seen.add(value);
57
+ const items = walk(value.items, lang, seen);
58
+ return items === value.items ? value : paginated(items, value.meta);
59
+ }
60
+ if (!isPlainObject(value)) return value;
61
+ seen.add(value);
62
+ let copy;
63
+ for (const [key, item] of Object.entries(value)) {
64
+ const next = walk(item, lang, seen);
65
+ if (next !== item) {
66
+ copy ??= { ...value };
67
+ copy[key] = next;
68
+ }
69
+ }
70
+ return copy ?? value;
71
+ }
72
+ function isPlainObject(value) {
73
+ const proto = Object.getPrototypeOf(value);
74
+ return proto === Object.prototype || proto === null;
75
+ }
76
+
77
+ export {
78
+ setI18nRuntime,
79
+ getI18nRuntime,
80
+ currentLanguage,
81
+ translate,
82
+ translateDeep
83
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AppException
3
- } from "./chunk-YFYHLYHN.js";
3
+ } from "./chunk-M3GQDRWR.js";
4
4
 
5
5
  // src/errors/common.exceptions.ts
6
6
  import { HttpStatus } from "@nestjs/common";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RequestContext
3
- } from "./chunk-KP2ZHJSR.js";
3
+ } from "./chunk-ETRUVZTJ.js";
4
4
  import {
5
5
  __decorateClass,
6
6
  __decorateParam
@@ -2,13 +2,13 @@
2
2
 
3
3
 
4
4
 
5
- var _chunk47FXU74Gcjs = require('../chunk-47FXU74G.cjs');
6
- require('../chunk-XX5ROVSC.cjs');
5
+ var _chunk52IOOHNXcjs = require('../chunk-52IOOHNX.cjs');
6
+ require('../chunk-W2T2VFLC.cjs');
7
7
  require('../chunk-Y72D5L6I.cjs');
8
- require('../chunk-EBPEMVZU.cjs');
8
+ require('../chunk-SDWHKPXI.cjs');
9
9
  require('../chunk-2REOCMUD.cjs');
10
10
 
11
11
 
12
12
 
13
13
 
14
- exports.BaseCrudService = _chunk47FXU74Gcjs.BaseCrudService; exports.ListQuery = _chunk47FXU74Gcjs.ListQuery; exports.createCrudController = _chunk47FXU74Gcjs.createCrudController;
14
+ exports.BaseCrudService = _chunk52IOOHNXcjs.BaseCrudService; exports.ListQuery = _chunk52IOOHNXcjs.ListQuery; exports.createCrudController = _chunk52IOOHNXcjs.createCrudController;
@@ -2,10 +2,10 @@ import {
2
2
  BaseCrudService,
3
3
  ListQuery,
4
4
  createCrudController
5
- } from "../chunk-LK3OINS7.js";
6
- import "../chunk-XHW4CTBS.js";
5
+ } from "../chunk-IFNYRZP2.js";
6
+ import "../chunk-ZJMLEP5H.js";
7
7
  import "../chunk-TCAMLNUZ.js";
8
- import "../chunk-KP2ZHJSR.js";
8
+ import "../chunk-ETRUVZTJ.js";
9
9
  import "../chunk-4MGIQFAJ.js";
10
10
  export {
11
11
  BaseCrudService,
@@ -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');
4
+ var _chunkMSTXS3MUcjs = require('../chunk-MSTXS3MU.cjs');
5
+ require('../chunk-AXMW5JF7.cjs');
6
+ require('../chunk-Y72D5L6I.cjs');
7
+ require('../chunk-SDWHKPXI.cjs');
6
8
 
7
9
 
8
10
 
9
11
 
10
12
 
11
13
 
12
- var _chunkFDNGAYTZcjs = require('../chunk-FDNGAYTZ.cjs');
14
+ var _chunkHDFPSA2Vcjs = require('../chunk-HDFPSA2V.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
2
  import {
3
3
  GlobalExceptionFilter
4
- } from "../chunk-KRC47OX6.js";
5
- import "../chunk-KP2ZHJSR.js";
4
+ } from "../chunk-A2DGK4ZL.js";
5
+ import "../chunk-X4PQJZ4G.js";
6
+ import "../chunk-TCAMLNUZ.js";
7
+ import "../chunk-ETRUVZTJ.js";
6
8
  import {
7
9
  ConflictAppException,
8
10
  ForbiddenAppException,
9
11
  NotFoundAppException,
10
12
  UnauthorizedAppException,
11
13
  ValidationAppException
12
- } from "../chunk-ORWJ7LES.js";
14
+ } from "../chunk-ZFIDAX7K.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
  };