@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
@@ -0,0 +1,212 @@
1
+ import {
2
+ getI18nRuntime,
3
+ setI18nRuntime,
4
+ translateDeep
5
+ } from "./chunk-X4PQJZ4G.js";
6
+ import {
7
+ RequestContext
8
+ } from "./chunk-ETRUVZTJ.js";
9
+ import {
10
+ __decorateClass,
11
+ __decorateParam
12
+ } from "./chunk-4MGIQFAJ.js";
13
+
14
+ // src/i18n/i18n.module.ts
15
+ import {
16
+ Inject,
17
+ Module,
18
+ Optional
19
+ } from "@nestjs/common";
20
+ import { APP_INTERCEPTOR } from "@nestjs/core";
21
+ import {
22
+ I18nModule as BaseI18nModule,
23
+ I18nJsonLoader,
24
+ I18nService
25
+ } from "nestjs-i18n";
26
+
27
+ // src/i18n/i18n.interceptor.ts
28
+ import { Injectable } from "@nestjs/common";
29
+ import { map } from "rxjs/operators";
30
+ var I18nInterceptor = class {
31
+ intercept(context, next) {
32
+ const runtime = getI18nRuntime();
33
+ if (!runtime || context.getType() !== "http") return next.handle();
34
+ const lang = runtime.resolveLocale(context.switchToHttp().getRequest()) ?? runtime.fallbackLanguage;
35
+ RequestContext.setLang(lang);
36
+ return next.handle().pipe(map((data) => translateDeep(data, lang)));
37
+ }
38
+ };
39
+ I18nInterceptor = __decorateClass([
40
+ Injectable()
41
+ ], I18nInterceptor);
42
+
43
+ // src/i18n/locale.ts
44
+ var DEFAULT_SOURCES = ["query", "header", "cookie", "accept-language"];
45
+ function buildLocaleResolver(options, supportedLanguages) {
46
+ const sources = options.from ?? DEFAULT_SOURCES;
47
+ const queryName = options.query ?? "lang";
48
+ const headerName = (options.header ?? "x-lang").toLowerCase();
49
+ const cookieName = options.cookie ?? "lang";
50
+ const readers = sources.map((source) => {
51
+ if (typeof source === "function") return source;
52
+ switch (source) {
53
+ case "query":
54
+ return (req) => first(req.query?.[queryName]);
55
+ case "header":
56
+ return (req) => first(req.headers?.[headerName]);
57
+ case "cookie":
58
+ return (req) => req.cookies?.[cookieName] ?? readCookie(first(req.headers?.cookie), cookieName);
59
+ case "accept-language":
60
+ return (req) => first(req.headers?.["accept-language"]);
61
+ }
62
+ });
63
+ return (req) => {
64
+ const supported = supportedLanguages();
65
+ for (const read of readers) {
66
+ const candidate = read(req);
67
+ if (!candidate) continue;
68
+ const lang = matchLanguage(candidate, supported);
69
+ if (lang) return lang;
70
+ }
71
+ return void 0;
72
+ };
73
+ }
74
+ function matchLanguage(raw, supported) {
75
+ const preferences = parseAcceptLanguage(raw);
76
+ if (supported.length === 0) return preferences[0];
77
+ const byLower = new Map(supported.map((lang) => [lang.toLowerCase(), lang]));
78
+ for (const tag of preferences) {
79
+ const exact = byLower.get(tag.toLowerCase());
80
+ if (exact) return exact;
81
+ const base = tag.split("-")[0]?.toLowerCase();
82
+ const loose = base && byLower.get(base);
83
+ if (loose) return loose;
84
+ }
85
+ return void 0;
86
+ }
87
+ var LANGUAGE_TAG = /^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i;
88
+ function parseAcceptLanguage(raw) {
89
+ return raw.split(",").map((part, index) => {
90
+ const [tag = "", ...params] = part.trim().split(";");
91
+ const q = params.map((p) => p.trim()).find((p) => p.startsWith("q="))?.slice(2);
92
+ const weight = q === void 0 ? 1 : Number(q);
93
+ return { tag: tag.trim(), weight: Number.isFinite(weight) ? weight : 0, index };
94
+ }).filter((p) => p.weight > 0 && LANGUAGE_TAG.test(p.tag)).sort((a, b) => b.weight - a.weight || a.index - b.index).map((p) => p.tag);
95
+ }
96
+ function first(value) {
97
+ const single = Array.isArray(value) ? value[0] : value;
98
+ return typeof single === "string" && single.length > 0 ? single : void 0;
99
+ }
100
+ function readCookie(header, name) {
101
+ if (!header) return void 0;
102
+ for (const pair of header.split(";")) {
103
+ const eq = pair.indexOf("=");
104
+ if (eq === -1) continue;
105
+ if (pair.slice(0, eq).trim() !== name) continue;
106
+ try {
107
+ return decodeURIComponent(pair.slice(eq + 1).trim());
108
+ } catch {
109
+ return void 0;
110
+ }
111
+ }
112
+ return void 0;
113
+ }
114
+
115
+ // src/i18n/nestjs-i18n.translator.ts
116
+ var MISSING = "\0nestkit:missing\0";
117
+ var NestI18nTranslator = class {
118
+ constructor(service) {
119
+ this.service = service;
120
+ }
121
+ translate(key, options = {}) {
122
+ const result = this.service.t(key, {
123
+ lang: options.lang,
124
+ args: options.args,
125
+ defaultValue: MISSING
126
+ });
127
+ return typeof result === "string" && result !== MISSING ? result : void 0;
128
+ }
129
+ supportedLanguages() {
130
+ return this.service.getSupportedLanguages();
131
+ }
132
+ };
133
+
134
+ // src/i18n/i18n.module.ts
135
+ var NESTKIT_I18N_OPTIONS = /* @__PURE__ */ Symbol("nestkit:i18n:options");
136
+ var I18nModule = class {
137
+ constructor(options, i18n) {
138
+ this.options = options;
139
+ this.i18n = i18n;
140
+ }
141
+ static forRoot(options = {}) {
142
+ const providers = [{ provide: NESTKIT_I18N_OPTIONS, useValue: options }];
143
+ if (options.interceptor !== false) {
144
+ providers.push({ provide: APP_INTERCEPTOR, useClass: I18nInterceptor });
145
+ }
146
+ if (options.translator) {
147
+ return { module: I18nModule, providers };
148
+ }
149
+ return {
150
+ module: I18nModule,
151
+ imports: [
152
+ BaseI18nModule.forRoot({
153
+ fallbackLanguage: options.fallbackLanguage ?? "es",
154
+ loaderOptions: {
155
+ path: options.path ?? "./i18n/",
156
+ watch: options.watch ?? process.env.NODE_ENV !== "production"
157
+ },
158
+ loader: options.loader ?? I18nJsonLoader,
159
+ resolvers: [new RuntimeResolver()]
160
+ })
161
+ ],
162
+ providers
163
+ };
164
+ }
165
+ onModuleInit() {
166
+ const translator = this.options.translator ?? new NestI18nTranslator(this.requireService());
167
+ setI18nRuntime({
168
+ translator,
169
+ fallbackLanguage: this.options.fallbackLanguage ?? "es",
170
+ resolveLocale: buildLocaleResolver(this.options.locale ?? {}, () => translator.supportedLanguages()),
171
+ errorCodes: this.options.errorCodes ?? "errors"
172
+ });
173
+ }
174
+ onModuleDestroy() {
175
+ setI18nRuntime(void 0);
176
+ }
177
+ requireService() {
178
+ if (!this.i18n) {
179
+ throw new Error("I18nModule: nestjs-i18n did not provide I18nService; pass `translator` or check the import");
180
+ }
181
+ return this.i18n;
182
+ }
183
+ };
184
+ I18nModule = __decorateClass([
185
+ Module({}),
186
+ __decorateParam(0, Inject(NESTKIT_I18N_OPTIONS)),
187
+ __decorateParam(1, Optional()),
188
+ __decorateParam(1, Inject(I18nService))
189
+ ], I18nModule);
190
+ var RuntimeResolver = class {
191
+ resolve(context) {
192
+ if (context.getType() !== "http") return void 0;
193
+ return getI18nRuntime()?.resolveLocale(context.switchToHttp().getRequest());
194
+ }
195
+ };
196
+
197
+ // src/i18n/translate.helper.ts
198
+ function translateOr(i18n, key, fallback, args) {
199
+ try {
200
+ return i18n.t(key, { args, defaultValue: fallback });
201
+ } catch {
202
+ return fallback;
203
+ }
204
+ }
205
+
206
+ export {
207
+ I18nInterceptor,
208
+ matchLanguage,
209
+ NestI18nTranslator,
210
+ I18nModule,
211
+ translateOr
212
+ };
@@ -1,9 +1,14 @@
1
+ import {
2
+ getI18nRuntime,
3
+ translate,
4
+ translateDeep
5
+ } from "./chunk-X4PQJZ4G.js";
1
6
  import {
2
7
  RequestContext
3
- } from "./chunk-KP2ZHJSR.js";
8
+ } from "./chunk-ETRUVZTJ.js";
4
9
  import {
5
10
  AppException
6
- } from "./chunk-YFYHLYHN.js";
11
+ } from "./chunk-M3GQDRWR.js";
7
12
  import {
8
13
  __decorateClass
9
14
  } from "./chunk-4MGIQFAJ.js";
@@ -20,12 +25,16 @@ var GlobalExceptionFilter = class {
20
25
  this.logger = new 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 >= 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 AppException) {
36
+ this.localize(resolved, exception, http.getRequest());
37
+ }
29
38
  const body = {
30
39
  success: false,
31
40
  requestId: RequestContext.getRequestId() ?? "unknown",
@@ -38,6 +47,20 @@ var GlobalExceptionFilter = class {
38
47
  };
39
48
  response.status(resolved.status).send(body);
40
49
  }
50
+ localize(resolved, exception, request) {
51
+ const runtime = getI18nRuntime();
52
+ if (!runtime) return;
53
+ const lang = runtime.resolveLocale(request) ?? runtime.fallbackLanguage;
54
+ if (exception.i18n) {
55
+ resolved.message = translate(exception.i18n, { lang, defaultValue: resolved.message });
56
+ } else if (runtime.errorCodes !== false) {
57
+ resolved.message = translate(`${runtime.errorCodes}.${exception.code}`, {
58
+ lang,
59
+ defaultValue: resolved.message
60
+ });
61
+ }
62
+ resolved.details = translateDeep(resolved.details, lang);
63
+ }
41
64
  resolve(exception) {
42
65
  if (exception instanceof AppException) {
43
66
  return {
@@ -0,0 +1,212 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+
5
+ var _chunkAXMW5JF7cjs = require('./chunk-AXMW5JF7.cjs');
6
+
7
+
8
+ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
9
+
10
+
11
+
12
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
13
+
14
+ // src/i18n/i18n.module.ts
15
+
16
+
17
+
18
+
19
+ var _common = require('@nestjs/common');
20
+ var _core = require('@nestjs/core');
21
+
22
+
23
+
24
+
25
+ var _nestjsi18n = require('nestjs-i18n');
26
+
27
+ // src/i18n/i18n.interceptor.ts
28
+
29
+ var _operators = require('rxjs/operators');
30
+ var I18nInterceptor = class {
31
+ intercept(context, next) {
32
+ const runtime = _chunkAXMW5JF7cjs.getI18nRuntime.call(void 0, );
33
+ if (!runtime || context.getType() !== "http") return next.handle();
34
+ const lang = _nullishCoalesce(runtime.resolveLocale(context.switchToHttp().getRequest()), () => ( runtime.fallbackLanguage));
35
+ _chunkSDWHKPXIcjs.RequestContext.setLang(lang);
36
+ return next.handle().pipe(_operators.map.call(void 0, (data) => _chunkAXMW5JF7cjs.translateDeep.call(void 0, data, lang)));
37
+ }
38
+ };
39
+ I18nInterceptor = exports.I18nInterceptor = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
40
+ _common.Injectable.call(void 0, )
41
+ ], I18nInterceptor);
42
+
43
+ // src/i18n/locale.ts
44
+ var DEFAULT_SOURCES = ["query", "header", "cookie", "accept-language"];
45
+ function buildLocaleResolver(options, supportedLanguages) {
46
+ const sources = _nullishCoalesce(options.from, () => ( DEFAULT_SOURCES));
47
+ const queryName = _nullishCoalesce(options.query, () => ( "lang"));
48
+ const headerName = (_nullishCoalesce(options.header, () => ( "x-lang"))).toLowerCase();
49
+ const cookieName = _nullishCoalesce(options.cookie, () => ( "lang"));
50
+ const readers = sources.map((source) => {
51
+ if (typeof source === "function") return source;
52
+ switch (source) {
53
+ case "query":
54
+ return (req) => first(_optionalChain([req, 'access', _ => _.query, 'optionalAccess', _2 => _2[queryName]]));
55
+ case "header":
56
+ return (req) => first(_optionalChain([req, 'access', _3 => _3.headers, 'optionalAccess', _4 => _4[headerName]]));
57
+ case "cookie":
58
+ return (req) => _nullishCoalesce(_optionalChain([req, 'access', _5 => _5.cookies, 'optionalAccess', _6 => _6[cookieName]]), () => ( readCookie(first(_optionalChain([req, 'access', _7 => _7.headers, 'optionalAccess', _8 => _8.cookie])), cookieName)));
59
+ case "accept-language":
60
+ return (req) => first(_optionalChain([req, 'access', _9 => _9.headers, 'optionalAccess', _10 => _10["accept-language"]]));
61
+ }
62
+ });
63
+ return (req) => {
64
+ const supported = supportedLanguages();
65
+ for (const read of readers) {
66
+ const candidate = read(req);
67
+ if (!candidate) continue;
68
+ const lang = matchLanguage(candidate, supported);
69
+ if (lang) return lang;
70
+ }
71
+ return void 0;
72
+ };
73
+ }
74
+ function matchLanguage(raw, supported) {
75
+ const preferences = parseAcceptLanguage(raw);
76
+ if (supported.length === 0) return preferences[0];
77
+ const byLower = new Map(supported.map((lang) => [lang.toLowerCase(), lang]));
78
+ for (const tag of preferences) {
79
+ const exact = byLower.get(tag.toLowerCase());
80
+ if (exact) return exact;
81
+ const base = _optionalChain([tag, 'access', _11 => _11.split, 'call', _12 => _12("-"), 'access', _13 => _13[0], 'optionalAccess', _14 => _14.toLowerCase, 'call', _15 => _15()]);
82
+ const loose = base && byLower.get(base);
83
+ if (loose) return loose;
84
+ }
85
+ return void 0;
86
+ }
87
+ var LANGUAGE_TAG = /^[a-z]{2,3}(?:-[a-z0-9]{2,8})*$/i;
88
+ function parseAcceptLanguage(raw) {
89
+ return raw.split(",").map((part, index) => {
90
+ const [tag = "", ...params] = part.trim().split(";");
91
+ const q = _optionalChain([params, 'access', _16 => _16.map, 'call', _17 => _17((p) => p.trim()), 'access', _18 => _18.find, 'call', _19 => _19((p) => p.startsWith("q=")), 'optionalAccess', _20 => _20.slice, 'call', _21 => _21(2)]);
92
+ const weight = q === void 0 ? 1 : Number(q);
93
+ return { tag: tag.trim(), weight: Number.isFinite(weight) ? weight : 0, index };
94
+ }).filter((p) => p.weight > 0 && LANGUAGE_TAG.test(p.tag)).sort((a, b) => b.weight - a.weight || a.index - b.index).map((p) => p.tag);
95
+ }
96
+ function first(value) {
97
+ const single = Array.isArray(value) ? value[0] : value;
98
+ return typeof single === "string" && single.length > 0 ? single : void 0;
99
+ }
100
+ function readCookie(header, name) {
101
+ if (!header) return void 0;
102
+ for (const pair of header.split(";")) {
103
+ const eq = pair.indexOf("=");
104
+ if (eq === -1) continue;
105
+ if (pair.slice(0, eq).trim() !== name) continue;
106
+ try {
107
+ return decodeURIComponent(pair.slice(eq + 1).trim());
108
+ } catch (e) {
109
+ return void 0;
110
+ }
111
+ }
112
+ return void 0;
113
+ }
114
+
115
+ // src/i18n/nestjs-i18n.translator.ts
116
+ var MISSING = "\0nestkit:missing\0";
117
+ var NestI18nTranslator = class {
118
+ constructor(service) {
119
+ this.service = service;
120
+ }
121
+ translate(key, options = {}) {
122
+ const result = this.service.t(key, {
123
+ lang: options.lang,
124
+ args: options.args,
125
+ defaultValue: MISSING
126
+ });
127
+ return typeof result === "string" && result !== MISSING ? result : void 0;
128
+ }
129
+ supportedLanguages() {
130
+ return this.service.getSupportedLanguages();
131
+ }
132
+ };
133
+
134
+ // src/i18n/i18n.module.ts
135
+ var NESTKIT_I18N_OPTIONS = /* @__PURE__ */ Symbol("nestkit:i18n:options");
136
+ var I18nModule = class {
137
+ constructor(options, i18n) {
138
+ this.options = options;
139
+ this.i18n = i18n;
140
+ }
141
+ static forRoot(options = {}) {
142
+ const providers = [{ provide: NESTKIT_I18N_OPTIONS, useValue: options }];
143
+ if (options.interceptor !== false) {
144
+ providers.push({ provide: _core.APP_INTERCEPTOR, useClass: I18nInterceptor });
145
+ }
146
+ if (options.translator) {
147
+ return { module: I18nModule, providers };
148
+ }
149
+ return {
150
+ module: I18nModule,
151
+ imports: [
152
+ _nestjsi18n.I18nModule.forRoot({
153
+ fallbackLanguage: _nullishCoalesce(options.fallbackLanguage, () => ( "es")),
154
+ loaderOptions: {
155
+ path: _nullishCoalesce(options.path, () => ( "./i18n/")),
156
+ watch: _nullishCoalesce(options.watch, () => ( process.env.NODE_ENV !== "production"))
157
+ },
158
+ loader: _nullishCoalesce(options.loader, () => ( _nestjsi18n.I18nJsonLoader)),
159
+ resolvers: [new RuntimeResolver()]
160
+ })
161
+ ],
162
+ providers
163
+ };
164
+ }
165
+ onModuleInit() {
166
+ const translator = _nullishCoalesce(this.options.translator, () => ( new NestI18nTranslator(this.requireService())));
167
+ _chunkAXMW5JF7cjs.setI18nRuntime.call(void 0, {
168
+ translator,
169
+ fallbackLanguage: _nullishCoalesce(this.options.fallbackLanguage, () => ( "es")),
170
+ resolveLocale: buildLocaleResolver(_nullishCoalesce(this.options.locale, () => ( {})), () => translator.supportedLanguages()),
171
+ errorCodes: _nullishCoalesce(this.options.errorCodes, () => ( "errors"))
172
+ });
173
+ }
174
+ onModuleDestroy() {
175
+ _chunkAXMW5JF7cjs.setI18nRuntime.call(void 0, void 0);
176
+ }
177
+ requireService() {
178
+ if (!this.i18n) {
179
+ throw new Error("I18nModule: nestjs-i18n did not provide I18nService; pass `translator` or check the import");
180
+ }
181
+ return this.i18n;
182
+ }
183
+ };
184
+ I18nModule = exports.I18nModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
185
+ _common.Module.call(void 0, {}),
186
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, NESTKIT_I18N_OPTIONS)),
187
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Optional.call(void 0, )),
188
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, _nestjsi18n.I18nService))
189
+ ], I18nModule);
190
+ var RuntimeResolver = class {
191
+ resolve(context) {
192
+ if (context.getType() !== "http") return void 0;
193
+ return _optionalChain([_chunkAXMW5JF7cjs.getI18nRuntime.call(void 0, ), 'optionalAccess', _22 => _22.resolveLocale, 'call', _23 => _23(context.switchToHttp().getRequest())]);
194
+ }
195
+ };
196
+
197
+ // src/i18n/translate.helper.ts
198
+ function translateOr(i18n, key, fallback, args) {
199
+ try {
200
+ return i18n.t(key, { args, defaultValue: fallback });
201
+ } catch (e2) {
202
+ return fallback;
203
+ }
204
+ }
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+ exports.I18nInterceptor = I18nInterceptor; exports.matchLanguage = matchLanguage; exports.NestI18nTranslator = NestI18nTranslator; exports.I18nModule = I18nModule; exports.translateOr = translateOr;
@@ -0,0 +1,83 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkY72D5L6Icjs = require('./chunk-Y72D5L6I.cjs');
5
+
6
+
7
+ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
8
+
9
+
10
+
11
+ var _chunkPNK5WMPPcjs = require('./chunk-PNK5WMPP.cjs');
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 _nullishCoalesce(_chunkSDWHKPXIcjs.RequestContext.getLang(), () => ( _optionalChain([runtime, 'optionalAccess', _ => _.fallbackLanguage])));
23
+ }
24
+ function translate(input, options = {}) {
25
+ const message = typeof input === "string" ? new (0, _chunkPNK5WMPPcjs.I18nMessage)(input, options.args) : input;
26
+ const fallback = _nullishCoalesce(_nullishCoalesce(message.fallback, () => ( options.defaultValue)), () => ( message.key));
27
+ if (!runtime) return fallback;
28
+ const lang = _nullishCoalesce(options.lang, () => ( currentLanguage()));
29
+ try {
30
+ return _nullishCoalesce(runtime.translator.translate(message.key, { lang, args: message.args }), () => ( fallback));
31
+ } catch (e) {
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 (_chunkPNK5WMPPcjs.isI18nMessage.call(void 0, 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 _nullishCoalesce(copy2, () => ( value));
54
+ }
55
+ if (_chunkY72D5L6Icjs.isPaginated.call(void 0, value)) {
56
+ seen.add(value);
57
+ const items = walk(value.items, lang, seen);
58
+ return items === value.items ? value : _chunkY72D5L6Icjs.paginated.call(void 0, 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 _nullishCoalesce(copy, () => ( value));
71
+ }
72
+ function isPlainObject(value) {
73
+ const proto = Object.getPrototypeOf(value);
74
+ return proto === Object.prototype || proto === null;
75
+ }
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+ exports.setI18nRuntime = setI18nRuntime; exports.getI18nRuntime = getI18nRuntime; exports.currentLanguage = currentLanguage; exports.translate = translate; exports.translateDeep = translateDeep;
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-TCAMLNUZ.js";
4
4
  import {
5
5
  RequestContext
6
- } from "./chunk-KP2ZHJSR.js";
6
+ } from "./chunk-ETRUVZTJ.js";
7
7
  import {
8
8
  __decorateClass
9
9
  } from "./chunk-4MGIQFAJ.js";
@@ -28,6 +28,14 @@ var RequestContext = class {
28
28
  static getActor() {
29
29
  return this.storage.getStore()?.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 this.storage.getStore()?.lang;
38
+ }
31
39
  };
32
40
 
33
41
  export {
@@ -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 _chunk67B7IYAVcjs = require('./chunk-67B7IYAV.cjs');
3
+ var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
4
4
 
5
5
 
6
- var _chunkUWDHAZVEcjs = require('./chunk-UWDHAZVE.cjs');
6
+ var _chunkMSTXS3MUcjs = require('./chunk-MSTXS3MU.cjs');
7
7
 
8
8
  // src/bootstrap/apply-defaults.ts
9
9
 
@@ -17,8 +17,8 @@ function applyNestKitDefaults(app, options = {}) {
17
17
  app.useGlobalPipes(
18
18
  new (0, _common.ValidationPipe)({ whitelist: true, transform: true, ...options.validation })
19
19
  );
20
- app.useGlobalFilters(new (0, _chunk67B7IYAVcjs.GlobalExceptionFilter)());
21
- app.useGlobalInterceptors(new (0, _chunkUWDHAZVEcjs.ResponseInterceptor)());
20
+ app.useGlobalFilters(new (0, _chunkMSTXS3MUcjs.GlobalExceptionFilter)());
21
+ app.useGlobalInterceptors(new (0, _chunk3AUOOEQOcjs.ResponseInterceptor)());
22
22
  if (options.swagger !== false) {
23
23
  const swaggerOptions = _nullishCoalesce(options.swagger, () => ( { title: "API" }));
24
24
  const config = new (0, _swagger.DocumentBuilder)().setTitle(swaggerOptions.title).build();
@@ -1,30 +1,30 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
3
+ var _chunkQ5Y33L7Bcjs = require('./chunk-Q5Y33L7B.cjs');
4
4
 
5
5
  // src/errors/common.exceptions.ts
6
6
  var _common = require('@nestjs/common');
7
- var NotFoundAppException = class extends _chunkR7BVS6CIcjs.AppException {
7
+ var NotFoundAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
8
8
  constructor(message = "Resource not found", details, code = "NOT_FOUND") {
9
9
  super(code, message, _common.HttpStatus.NOT_FOUND, details);
10
10
  }
11
11
  };
12
- var ConflictAppException = class extends _chunkR7BVS6CIcjs.AppException {
12
+ var ConflictAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
13
13
  constructor(message = "Conflict", details, code = "CONFLICT") {
14
14
  super(code, message, _common.HttpStatus.CONFLICT, details);
15
15
  }
16
16
  };
17
- var ValidationAppException = class extends _chunkR7BVS6CIcjs.AppException {
17
+ var ValidationAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
18
18
  constructor(message = "Validation failed", details, code = "VALIDATION_ERROR") {
19
19
  super(code, message, _common.HttpStatus.BAD_REQUEST, details);
20
20
  }
21
21
  };
22
- var UnauthorizedAppException = class extends _chunkR7BVS6CIcjs.AppException {
22
+ var UnauthorizedAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
23
23
  constructor(message = "Unauthorized", details, code = "UNAUTHORIZED") {
24
24
  super(code, message, _common.HttpStatus.UNAUTHORIZED, details);
25
25
  }
26
26
  };
27
- var ForbiddenAppException = class extends _chunkR7BVS6CIcjs.AppException {
27
+ var ForbiddenAppException = class extends _chunkQ5Y33L7Bcjs.AppException {
28
28
  constructor(message = "Forbidden", details, code = "FORBIDDEN") {
29
29
  super(code, message, _common.HttpStatus.FORBIDDEN, details);
30
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(); } }
2
2
 
3
- var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
3
+ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
4
4
 
5
5
 
6
6
  var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
@@ -15,7 +15,7 @@ var RequestIdMiddleware = class {
15
15
  const requestId = _nullishCoalesce((Array.isArray(incoming) ? incoming[0] : incoming), () => ( _crypto.randomUUID.call(void 0, )));
16
16
  req.requestId = requestId;
17
17
  res.setHeader(REQUEST_ID_HEADER, requestId);
18
- _chunkEBPEMVZUcjs.RequestContext.run({ requestId }, () => next());
18
+ _chunkSDWHKPXIcjs.RequestContext.run({ requestId }, () => next());
19
19
  }
20
20
  };
21
21
  RequestIdMiddleware = exports.RequestIdMiddleware = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  withRequestContext
3
- } from "./chunk-XHW4CTBS.js";
3
+ } from "./chunk-ZJMLEP5H.js";
4
4
  import {
5
5
  buildPageMeta,
6
6
  paginated