@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,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;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isPaginated
|
|
3
|
+
} from "./chunk-TCAMLNUZ.js";
|
|
1
4
|
import {
|
|
2
5
|
RequestContext
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ETRUVZTJ.js";
|
|
4
7
|
import {
|
|
5
8
|
__decorateClass
|
|
6
9
|
} from "./chunk-4MGIQFAJ.js";
|
|
@@ -11,12 +14,14 @@ import { map } from "rxjs/operators";
|
|
|
11
14
|
var ResponseInterceptor = class {
|
|
12
15
|
intercept(_context, next) {
|
|
13
16
|
return next.handle().pipe(
|
|
14
|
-
map((data) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
map((data) => {
|
|
18
|
+
const envelope = {
|
|
19
|
+
success: true,
|
|
20
|
+
requestId: RequestContext.getRequestId() ?? "unknown",
|
|
21
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
22
|
+
};
|
|
23
|
+
return isPaginated(data) ? { ...envelope, data: data.items, meta: data.meta } : { ...envelope, data };
|
|
24
|
+
})
|
|
20
25
|
);
|
|
21
26
|
}
|
|
22
27
|
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/tracking/request-context.ts
|
|
2
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
|
+
var RequestContext = class {
|
|
4
|
+
static {
|
|
5
|
+
this.storage = new AsyncLocalStorage();
|
|
6
|
+
}
|
|
7
|
+
static run(store, fn) {
|
|
8
|
+
return this.storage.run(store, fn);
|
|
9
|
+
}
|
|
10
|
+
static getStore() {
|
|
11
|
+
return this.storage.getStore();
|
|
12
|
+
}
|
|
13
|
+
static getRequestId() {
|
|
14
|
+
return this.storage.getStore()?.requestId;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Records who this request belongs to. Mutates the current store rather than
|
|
18
|
+
* opening a new scope: a guard runs inside the middleware's scope, and
|
|
19
|
+
* calling `run` again there would hide everything set before it.
|
|
20
|
+
*
|
|
21
|
+
* Silently does nothing outside a request — a queue worker has no store, and
|
|
22
|
+
* a guard should not explode because of where it was called from.
|
|
23
|
+
*/
|
|
24
|
+
static setActor(actor) {
|
|
25
|
+
const store = this.storage.getStore();
|
|
26
|
+
if (store) store.actor = actor;
|
|
27
|
+
}
|
|
28
|
+
static getActor() {
|
|
29
|
+
return this.storage.getStore()?.actor;
|
|
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
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
RequestContext
|
|
43
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk3AUOOEQOcjs = require('./chunk-3AUOOEQO.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
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,
|
|
21
|
-
app.useGlobalInterceptors(new (0,
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
18
|
+
_chunkSDWHKPXIcjs.RequestContext.run({ requestId }, () => next());
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
21
|
RequestIdMiddleware = exports.RequestIdMiddleware = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import {
|
|
2
|
+
withRequestContext
|
|
3
|
+
} from "./chunk-ZJMLEP5H.js";
|
|
4
|
+
import {
|
|
5
|
+
buildPageMeta,
|
|
6
|
+
paginated
|
|
7
|
+
} from "./chunk-TCAMLNUZ.js";
|
|
8
|
+
import {
|
|
9
|
+
__decorateClass,
|
|
10
|
+
__decorateParam
|
|
11
|
+
} from "./chunk-4MGIQFAJ.js";
|
|
12
|
+
|
|
13
|
+
// src/crud/list-query.dto.ts
|
|
14
|
+
import { Type } from "class-transformer";
|
|
15
|
+
import { IsIn, IsInt, IsOptional, IsString, Max, Min } from "class-validator";
|
|
16
|
+
var ListQuery = class {
|
|
17
|
+
};
|
|
18
|
+
__decorateClass([
|
|
19
|
+
IsOptional(),
|
|
20
|
+
Type(() => Number),
|
|
21
|
+
IsInt(),
|
|
22
|
+
Min(1)
|
|
23
|
+
], ListQuery.prototype, "page", 2);
|
|
24
|
+
__decorateClass([
|
|
25
|
+
IsOptional(),
|
|
26
|
+
Type(() => Number),
|
|
27
|
+
IsInt(),
|
|
28
|
+
Min(1),
|
|
29
|
+
Max(200)
|
|
30
|
+
], ListQuery.prototype, "limit", 2);
|
|
31
|
+
__decorateClass([
|
|
32
|
+
IsOptional(),
|
|
33
|
+
IsString()
|
|
34
|
+
], ListQuery.prototype, "sortBy", 2);
|
|
35
|
+
__decorateClass([
|
|
36
|
+
IsOptional(),
|
|
37
|
+
IsIn(["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 = this.options.maxLimit ?? 100;
|
|
59
|
+
const limit = Math.min(Math.max(query.limit ?? this.options.defaultLimit ?? 20, 1), maxLimit);
|
|
60
|
+
const page = Math.max(query.page ?? 1, 1);
|
|
61
|
+
const sortBy = query.sortBy && (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 ? query.sortOrder ?? "desc" : void 0
|
|
69
|
+
},
|
|
70
|
+
tenantId
|
|
71
|
+
);
|
|
72
|
+
return paginated(items, buildPageMeta(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 = 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 (!this.options.audit?.includeBefore) return void 0;
|
|
114
|
+
return await this.repository.findById(id, tenantId) ?? 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
|
+
withRequestContext({
|
|
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
|
+
import {
|
|
134
|
+
Body,
|
|
135
|
+
Controller,
|
|
136
|
+
Delete,
|
|
137
|
+
Get,
|
|
138
|
+
Inject,
|
|
139
|
+
Param,
|
|
140
|
+
Patch,
|
|
141
|
+
Post,
|
|
142
|
+
Query,
|
|
143
|
+
Req
|
|
144
|
+
} from "@nestjs/common";
|
|
145
|
+
function createCrudController(serviceToken, options = {}) {
|
|
146
|
+
const tenantIdOf = (req) => options.tenantIdExtractor?.(req);
|
|
147
|
+
let CrudControllerHost = class {
|
|
148
|
+
constructor(service) {
|
|
149
|
+
this.service = service;
|
|
150
|
+
}
|
|
151
|
+
findAll(query, req) {
|
|
152
|
+
const raw = 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
|
+
__decorateClass([
|
|
169
|
+
Get(),
|
|
170
|
+
__decorateParam(0, Query()),
|
|
171
|
+
__decorateParam(1, Req())
|
|
172
|
+
], CrudControllerHost.prototype, "findAll", 1);
|
|
173
|
+
__decorateClass([
|
|
174
|
+
Get(":id"),
|
|
175
|
+
__decorateParam(0, Param("id")),
|
|
176
|
+
__decorateParam(1, Req())
|
|
177
|
+
], CrudControllerHost.prototype, "findById", 1);
|
|
178
|
+
__decorateClass([
|
|
179
|
+
Post(),
|
|
180
|
+
__decorateParam(0, Body()),
|
|
181
|
+
__decorateParam(1, Req())
|
|
182
|
+
], CrudControllerHost.prototype, "create", 1);
|
|
183
|
+
__decorateClass([
|
|
184
|
+
Patch(":id"),
|
|
185
|
+
__decorateParam(0, Param("id")),
|
|
186
|
+
__decorateParam(1, Body()),
|
|
187
|
+
__decorateParam(2, Req())
|
|
188
|
+
], CrudControllerHost.prototype, "update", 1);
|
|
189
|
+
__decorateClass([
|
|
190
|
+
Delete(":id"),
|
|
191
|
+
__decorateParam(0, Param("id")),
|
|
192
|
+
__decorateParam(1, Req())
|
|
193
|
+
], CrudControllerHost.prototype, "remove", 1);
|
|
194
|
+
CrudControllerHost = __decorateClass([
|
|
195
|
+
Controller(options.path ?? ""),
|
|
196
|
+
__decorateParam(0, Inject(serviceToken))
|
|
197
|
+
], CrudControllerHost);
|
|
198
|
+
return CrudControllerHost;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export {
|
|
202
|
+
ListQuery,
|
|
203
|
+
BaseCrudService,
|
|
204
|
+
createCrudController
|
|
205
|
+
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RequestContext
|
|
3
|
+
} from "./chunk-ETRUVZTJ.js";
|
|
1
4
|
import {
|
|
2
5
|
UnauthorizedAppException
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZFIDAX7K.js";
|
|
4
7
|
import {
|
|
5
8
|
__decorateClass
|
|
6
9
|
} from "./chunk-4MGIQFAJ.js";
|
|
@@ -54,7 +57,9 @@ var JwtAuthGuard = class {
|
|
|
54
57
|
if (!token) {
|
|
55
58
|
throw new UnauthorizedAppException("Missing Authorization bearer token");
|
|
56
59
|
}
|
|
57
|
-
|
|
60
|
+
const user = this.tokens.verifyAccessToken(token);
|
|
61
|
+
req.user = user;
|
|
62
|
+
RequestContext.setActor({ id: user.sub, tenantId: user.tenantId, roles: user.roles });
|
|
58
63
|
return true;
|
|
59
64
|
}
|
|
60
65
|
};
|
|
@@ -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
|
-
|
|
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 _chunkZA56XBCKcjs = require('./chunk-ZA56XBCK.cjs');
|
|
4
3
|
|
|
5
4
|
|
|
6
|
-
var
|
|
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
|
|
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(
|
|
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
|
|
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;
|
|
@@ -13,6 +13,29 @@ var RequestContext = class {
|
|
|
13
13
|
static getRequestId() {
|
|
14
14
|
return _optionalChain([this, 'access', _ => _.storage, 'access', _2 => _2.getStore, 'call', _3 => _3(), 'optionalAccess', _4 => _4.requestId]);
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Records who this request belongs to. Mutates the current store rather than
|
|
18
|
+
* opening a new scope: a guard runs inside the middleware's scope, and
|
|
19
|
+
* calling `run` again there would hide everything set before it.
|
|
20
|
+
*
|
|
21
|
+
* Silently does nothing outside a request — a queue worker has no store, and
|
|
22
|
+
* a guard should not explode because of where it was called from.
|
|
23
|
+
*/
|
|
24
|
+
static setActor(actor) {
|
|
25
|
+
const store = this.storage.getStore();
|
|
26
|
+
if (store) store.actor = actor;
|
|
27
|
+
}
|
|
28
|
+
static getActor() {
|
|
29
|
+
return _optionalChain([this, 'access', _5 => _5.storage, 'access', _6 => _6.getStore, 'call', _7 => _7(), 'optionalAccess', _8 => _8.actor]);
|
|
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
|
+
}
|
|
16
39
|
};
|
|
17
40
|
|
|
18
41
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/response/paginated.ts
|
|
2
|
+
var PAGINATED = /* @__PURE__ */ Symbol.for("nestkit.paginated");
|
|
3
|
+
function buildPageMeta(total, page, limit) {
|
|
4
|
+
const pages = limit > 0 ? Math.ceil(total / limit) : 0;
|
|
5
|
+
return {
|
|
6
|
+
page,
|
|
7
|
+
limit,
|
|
8
|
+
total,
|
|
9
|
+
pages,
|
|
10
|
+
hasNext: page < pages,
|
|
11
|
+
hasPrevious: page > 1 && total > 0
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function paginated(items, meta) {
|
|
15
|
+
const page = { items, meta };
|
|
16
|
+
Object.defineProperty(page, PAGINATED, { value: true, enumerable: false });
|
|
17
|
+
return page;
|
|
18
|
+
}
|
|
19
|
+
function isPaginated(value) {
|
|
20
|
+
return typeof value === "object" && value !== null && value[PAGINATED] === true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
buildPageMeta,
|
|
25
|
+
paginated,
|
|
26
|
+
isPaginated
|
|
27
|
+
};
|