@miguelmorales13/nestkit 0.11.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.
- package/README.md +619 -35
- package/dist/audit/audit.module.d.ts +23 -0
- package/dist/audit/audit.options.d.ts +16 -0
- package/dist/audit/audit.port.d.ts +37 -0
- package/dist/audit/audit.service.d.ts +29 -0
- package/dist/audit/index.cjs +72 -0
- package/dist/audit/index.d.ts +7 -0
- package/dist/audit/index.js +72 -0
- package/dist/audit/sinks.d.ts +18 -0
- package/dist/auth/index.cjs +12 -10
- package/dist/auth/index.js +5 -3
- package/dist/auth/oauth/http.d.ts +10 -3
- package/dist/auth/oauth/index.cjs +189 -29
- package/dist/auth/oauth/index.d.ts +6 -4
- package/dist/auth/oauth/index.js +169 -9
- package/dist/auth/oauth/magic-link.dto.d.ts +6 -0
- package/dist/auth/oauth/memory-magic-link.store.d.ts +19 -0
- package/dist/auth/oauth/oauth-auth.service.d.ts +46 -5
- package/dist/auth/oauth/oauth.controller.d.ts +5 -1
- package/dist/auth/oauth/oauth.options.d.ts +34 -1
- package/dist/auth/oauth/oauth.ports.d.ts +38 -0
- package/dist/bootstrap/index.cjs +9 -6
- package/dist/bootstrap/index.js +8 -5
- package/dist/{chunk-TJHRABML.cjs → chunk-3AUOOEQO.cjs} +12 -7
- package/dist/{chunk-NVCI3CQI.cjs → chunk-4HHZFOVC.cjs} +10 -5
- package/dist/{chunk-EYURGACO.js → chunk-4PFAKLT3.js} +1 -1
- package/dist/chunk-52IOOHNX.cjs +205 -0
- package/dist/chunk-6RAPVLJM.js +212 -0
- package/dist/{chunk-7I2Y7V52.js → chunk-A2DGK4ZL.js} +26 -3
- package/dist/chunk-APUFKA4K.cjs +212 -0
- package/dist/chunk-AXMW5JF7.cjs +83 -0
- package/dist/{chunk-KDAA6GFF.js → chunk-DYHSOULW.js} +12 -7
- package/dist/chunk-ETRUVZTJ.js +43 -0
- package/dist/{chunk-54ZXIB5T.cjs → chunk-FNUZGYUF.cjs} +4 -4
- package/dist/{chunk-FDNGAYTZ.cjs → chunk-HDFPSA2V.cjs} +6 -6
- package/dist/{chunk-V2M75FN3.cjs → chunk-HVHYZXBB.cjs} +2 -2
- package/dist/chunk-IFNYRZP2.js +205 -0
- package/dist/{chunk-A3B2EY4V.js → chunk-IKXSVEJ7.js} +7 -2
- package/dist/{chunk-YFYHLYHN.js → chunk-M3GQDRWR.js} +7 -1
- package/dist/{chunk-J7TURDAL.cjs → chunk-MSTXS3MU.cjs} +28 -5
- package/dist/chunk-PNK5WMPP.cjs +30 -0
- package/dist/chunk-Q5Y33L7B.cjs +19 -0
- package/dist/{chunk-ZA56XBCK.cjs → chunk-SDWHKPXI.cjs} +23 -0
- package/dist/chunk-TCAMLNUZ.js +27 -0
- package/dist/{chunk-AOCF5QCZ.js → chunk-UNEVXCFW.js} +2 -2
- package/dist/chunk-VVMRZEIW.js +30 -0
- package/dist/chunk-W2T2VFLC.cjs +57 -0
- package/dist/chunk-X4PQJZ4G.js +83 -0
- package/dist/chunk-Y72D5L6I.cjs +27 -0
- package/dist/{chunk-ORWJ7LES.js → chunk-ZFIDAX7K.js} +1 -1
- package/dist/chunk-ZJMLEP5H.js +57 -0
- package/dist/crud/crud.controller.d.ts +3 -1
- package/dist/crud/crud.service.d.ts +63 -4
- package/dist/crud/index.cjs +7 -2
- package/dist/crud/index.d.ts +2 -1
- package/dist/crud/index.js +6 -1
- package/dist/crud/list-query.dto.d.ts +23 -0
- package/dist/crud/repository.port.d.ts +33 -1
- package/dist/errors/app.exception.d.ts +9 -1
- package/dist/errors/common.exceptions.d.ts +6 -5
- package/dist/errors/global-exception.filter.d.ts +9 -0
- package/dist/errors/index.cjs +8 -5
- package/dist/errors/index.js +9 -6
- package/dist/i18n/i18n.interceptor.d.ts +16 -0
- package/dist/i18n/i18n.module.d.ts +49 -3
- package/dist/i18n/index.cjs +26 -2
- package/dist/i18n/index.d.ts +8 -0
- package/dist/i18n/index.js +25 -1
- package/dist/i18n/locale.d.ts +53 -0
- package/dist/i18n/message.d.ts +36 -0
- package/dist/i18n/nestjs-i18n.translator.d.ts +9 -0
- package/dist/i18n/runtime.d.ts +55 -0
- package/dist/i18n/translator.port.d.ts +29 -0
- package/dist/idempotency/idempotency.interceptor.d.ts +35 -0
- package/dist/idempotency/idempotency.module.d.ts +27 -0
- package/dist/idempotency/idempotency.options.d.ts +29 -0
- package/dist/idempotency/idempotency.port.d.ts +43 -0
- package/dist/idempotency/index.cjs +207 -0
- package/dist/idempotency/index.d.ts +7 -0
- package/dist/idempotency/index.js +207 -0
- package/dist/idempotency/memory.store.d.ts +24 -0
- package/dist/index.cjs +48 -15
- package/dist/index.js +51 -18
- package/dist/invoicing/adapters/facturama.invoicing.d.ts +50 -0
- package/dist/invoicing/adapters/facturapi.invoicing.d.ts +35 -0
- package/dist/invoicing/amounts.d.ts +52 -0
- package/dist/invoicing/index.cjs +578 -0
- package/dist/invoicing/index.d.ts +11 -0
- package/dist/invoicing/index.js +578 -0
- package/dist/invoicing/invoicing.module.d.ts +42 -0
- package/dist/invoicing/invoicing.options.d.ts +51 -0
- package/dist/invoicing/invoicing.port.d.ts +156 -0
- package/dist/invoicing/lines.d.ts +21 -0
- package/dist/invoicing/provider-http.d.ts +21 -0
- package/dist/payments/adapters/clip.terminal.d.ts +101 -0
- package/dist/payments/adapters/mercadopago.terminal.d.ts +74 -0
- package/dist/payments/index.cjs +796 -0
- package/dist/payments/index.d.ts +12 -0
- package/dist/payments/index.js +796 -0
- package/dist/payments/money.d.ts +20 -0
- package/dist/payments/payments-webhook.controller.d.ts +30 -0
- package/dist/payments/payments.module.d.ts +45 -0
- package/dist/payments/payments.options.d.ts +84 -0
- package/dist/payments/payments.port.d.ts +174 -0
- package/dist/payments/provider-http.d.ts +26 -0
- package/dist/response/api-response.d.ts +7 -0
- package/dist/response/index.cjs +12 -4
- package/dist/response/index.d.ts +2 -0
- package/dist/response/index.js +12 -4
- package/dist/response/paginated.d.ts +25 -0
- package/dist/response/response.interceptor.d.ts +4 -0
- package/dist/stripe/index.cjs +4 -3
- package/dist/stripe/index.js +3 -2
- package/dist/tracking/index.cjs +3 -3
- package/dist/tracking/index.d.ts +1 -1
- package/dist/tracking/index.js +2 -2
- package/dist/tracking/request-context.d.ts +32 -0
- package/package.json +25 -3
- package/dist/chunk-3CLYZC3T.cjs +0 -104
- package/dist/chunk-EBO6UKHL.js +0 -20
- package/dist/chunk-IYUUYCP5.js +0 -36
- package/dist/chunk-JOVBJDJ2.js +0 -104
- package/dist/chunk-M3EL5O6T.cjs +0 -36
- package/dist/chunk-R7BVS6CI.cjs +0 -13
- /package/dist/{chunk-MR2IFCZE.cjs → chunk-H2EHN366.cjs} +0 -0
- /package/dist/{chunk-NAK4WDKS.js → chunk-ODPSIFOB.js} +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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
|
+
var _chunkW2T2VFLCcjs = require('./chunk-W2T2VFLC.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _chunkY72D5L6Icjs = require('./chunk-Y72D5L6I.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
|
|
12
|
+
|
|
13
|
+
// src/crud/list-query.dto.ts
|
|
14
|
+
var _classtransformer = require('class-transformer');
|
|
15
|
+
var _classvalidator = require('class-validator');
|
|
16
|
+
var ListQuery = class {
|
|
17
|
+
};
|
|
18
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
19
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
20
|
+
_classtransformer.Type.call(void 0, () => Number),
|
|
21
|
+
_classvalidator.IsInt.call(void 0, ),
|
|
22
|
+
_classvalidator.Min.call(void 0, 1)
|
|
23
|
+
], ListQuery.prototype, "page", 2);
|
|
24
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
25
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
26
|
+
_classtransformer.Type.call(void 0, () => Number),
|
|
27
|
+
_classvalidator.IsInt.call(void 0, ),
|
|
28
|
+
_classvalidator.Min.call(void 0, 1),
|
|
29
|
+
_classvalidator.Max.call(void 0, 200)
|
|
30
|
+
], ListQuery.prototype, "limit", 2);
|
|
31
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
32
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
33
|
+
_classvalidator.IsString.call(void 0, )
|
|
34
|
+
], ListQuery.prototype, "sortBy", 2);
|
|
35
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
36
|
+
_classvalidator.IsOptional.call(void 0, ),
|
|
37
|
+
_classvalidator.IsIn.call(void 0, ["asc", "desc"])
|
|
38
|
+
], ListQuery.prototype, "sortOrder", 2);
|
|
39
|
+
|
|
40
|
+
// src/crud/crud.service.ts
|
|
41
|
+
var BaseCrudService = class {
|
|
42
|
+
constructor(repository, options = {}) {
|
|
43
|
+
this.repository = repository;
|
|
44
|
+
this.options = options;
|
|
45
|
+
}
|
|
46
|
+
findById(id, tenantId) {
|
|
47
|
+
return this.repository.findById(id, tenantId);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* One page of rows.
|
|
51
|
+
*
|
|
52
|
+
* Everything a caller can influence is bounded here rather than in the
|
|
53
|
+
* controller, so calling the service directly is as safe as going through
|
|
54
|
+
* HTTP: the limit is capped, and filter and sort fields are checked against
|
|
55
|
+
* the allowlists before they reach the adapter.
|
|
56
|
+
*/
|
|
57
|
+
async findAll(query = {}, tenantId) {
|
|
58
|
+
const maxLimit = _nullishCoalesce(this.options.maxLimit, () => ( 100));
|
|
59
|
+
const limit = Math.min(Math.max(_nullishCoalesce(_nullishCoalesce(query.limit, () => ( this.options.defaultLimit)), () => ( 20)), 1), maxLimit);
|
|
60
|
+
const page = Math.max(_nullishCoalesce(query.page, () => ( 1)), 1);
|
|
61
|
+
const sortBy = query.sortBy && (_nullishCoalesce(this.options.sortable, () => ( []))).includes(query.sortBy) ? query.sortBy : void 0;
|
|
62
|
+
const { items, total } = await this.repository.findAll(
|
|
63
|
+
{
|
|
64
|
+
filter: this.allowedFilter(query),
|
|
65
|
+
limit,
|
|
66
|
+
offset: (page - 1) * limit,
|
|
67
|
+
sortBy,
|
|
68
|
+
sortOrder: sortBy ? _nullishCoalesce(query.sortOrder, () => ( "desc")) : void 0
|
|
69
|
+
},
|
|
70
|
+
tenantId
|
|
71
|
+
);
|
|
72
|
+
return _chunkY72D5L6Icjs.paginated.call(void 0, items, _chunkY72D5L6Icjs.buildPageMeta.call(void 0, total, page, limit));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Keeps only the query fields this service declares filterable. Anything
|
|
76
|
+
* else is dropped silently — a rejection would tell a caller which columns
|
|
77
|
+
* exist, which is the question they were asking.
|
|
78
|
+
*/
|
|
79
|
+
allowedFilter(query) {
|
|
80
|
+
const filterable = _nullishCoalesce(this.options.filterable, () => ( []));
|
|
81
|
+
if (filterable.length === 0) return void 0;
|
|
82
|
+
const filter = {};
|
|
83
|
+
for (const field of filterable) {
|
|
84
|
+
if (query[field] !== void 0) filter[field] = query[field];
|
|
85
|
+
}
|
|
86
|
+
return Object.keys(filter).length > 0 ? filter : void 0;
|
|
87
|
+
}
|
|
88
|
+
async create(data, tenantId) {
|
|
89
|
+
const created = await this.repository.create(data, tenantId);
|
|
90
|
+
await this.audit("created", created.id, { after: created, tenantId });
|
|
91
|
+
return created;
|
|
92
|
+
}
|
|
93
|
+
async update(id, data, tenantId) {
|
|
94
|
+
const before = await this.readBefore(id, tenantId);
|
|
95
|
+
const updated = await this.repository.update(id, data, tenantId);
|
|
96
|
+
await this.audit("updated", id, { before, after: updated, tenantId });
|
|
97
|
+
return updated;
|
|
98
|
+
}
|
|
99
|
+
async delete(id, tenantId) {
|
|
100
|
+
const before = await this.readBefore(id, tenantId);
|
|
101
|
+
if (this.options.deleteStrategy === "soft") {
|
|
102
|
+
await this.repository.update(id, { deletedAt: /* @__PURE__ */ new Date() }, tenantId);
|
|
103
|
+
} else {
|
|
104
|
+
await this.repository.delete(id, tenantId);
|
|
105
|
+
}
|
|
106
|
+
await this.audit(this.options.deleteStrategy === "soft" ? "soft-deleted" : "deleted", id, {
|
|
107
|
+
before,
|
|
108
|
+
tenantId
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Only when the trail is configured to want it — otherwise it is a query for nothing. */
|
|
112
|
+
async readBefore(id, tenantId) {
|
|
113
|
+
if (!_optionalChain([this, 'access', _ => _.options, 'access', _2 => _2.audit, 'optionalAccess', _3 => _3.includeBefore])) return void 0;
|
|
114
|
+
return await _asyncNullishCoalesce(await this.repository.findById(id, tenantId), async () => ( void 0));
|
|
115
|
+
}
|
|
116
|
+
async audit(action, resourceId, details) {
|
|
117
|
+
const audit = this.options.audit;
|
|
118
|
+
if (!audit) return;
|
|
119
|
+
await audit.recorder.record(
|
|
120
|
+
_chunkW2T2VFLCcjs.withRequestContext.call(void 0, {
|
|
121
|
+
action,
|
|
122
|
+
resource: audit.resource,
|
|
123
|
+
resourceId,
|
|
124
|
+
before: details.before,
|
|
125
|
+
after: details.after,
|
|
126
|
+
tenantId: details.tenantId
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// src/crud/crud.controller.ts
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
var _common = require('@nestjs/common');
|
|
145
|
+
function createCrudController(serviceToken, options = {}) {
|
|
146
|
+
const tenantIdOf = (req) => _optionalChain([options, 'access', _4 => _4.tenantIdExtractor, 'optionalCall', _5 => _5(req)]);
|
|
147
|
+
let CrudControllerHost = class {
|
|
148
|
+
constructor(service) {
|
|
149
|
+
this.service = service;
|
|
150
|
+
}
|
|
151
|
+
findAll(query, req) {
|
|
152
|
+
const raw = _nullishCoalesce(req.query, () => ( {}));
|
|
153
|
+
return this.service.findAll({ ...raw, ...query }, tenantIdOf(req));
|
|
154
|
+
}
|
|
155
|
+
findById(id, req) {
|
|
156
|
+
return this.service.findById(id, tenantIdOf(req));
|
|
157
|
+
}
|
|
158
|
+
create(data, req) {
|
|
159
|
+
return this.service.create(data, tenantIdOf(req));
|
|
160
|
+
}
|
|
161
|
+
update(id, data, req) {
|
|
162
|
+
return this.service.update(id, data, tenantIdOf(req));
|
|
163
|
+
}
|
|
164
|
+
remove(id, req) {
|
|
165
|
+
return this.service.delete(id, tenantIdOf(req));
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
169
|
+
_common.Get.call(void 0, ),
|
|
170
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Query.call(void 0, )),
|
|
171
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
172
|
+
], CrudControllerHost.prototype, "findAll", 1);
|
|
173
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
174
|
+
_common.Get.call(void 0, ":id"),
|
|
175
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
|
|
176
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
177
|
+
], CrudControllerHost.prototype, "findById", 1);
|
|
178
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
179
|
+
_common.Post.call(void 0, ),
|
|
180
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Body.call(void 0, )),
|
|
181
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
182
|
+
], CrudControllerHost.prototype, "create", 1);
|
|
183
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
184
|
+
_common.Patch.call(void 0, ":id"),
|
|
185
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
|
|
186
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Body.call(void 0, )),
|
|
187
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 2, _common.Req.call(void 0, ))
|
|
188
|
+
], CrudControllerHost.prototype, "update", 1);
|
|
189
|
+
_chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
190
|
+
_common.Delete.call(void 0, ":id"),
|
|
191
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
|
|
192
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
|
|
193
|
+
], CrudControllerHost.prototype, "remove", 1);
|
|
194
|
+
CrudControllerHost = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
195
|
+
_common.Controller.call(void 0, _nullishCoalesce(options.path, () => ( ""))),
|
|
196
|
+
_chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, serviceToken))
|
|
197
|
+
], CrudControllerHost);
|
|
198
|
+
return CrudControllerHost;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
exports.ListQuery = ListQuery; exports.BaseCrudService = BaseCrudService; exports.createCrudController = createCrudController;
|
|
@@ -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-
|
|
8
|
+
} from "./chunk-ETRUVZTJ.js";
|
|
4
9
|
import {
|
|
5
10
|
AppException
|
|
6
|
-
} from "./chunk-
|
|
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
|
|
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;
|