@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.
Files changed (126) hide show
  1. package/README.md +619 -35
  2. package/dist/audit/audit.module.d.ts +23 -0
  3. package/dist/audit/audit.options.d.ts +16 -0
  4. package/dist/audit/audit.port.d.ts +37 -0
  5. package/dist/audit/audit.service.d.ts +29 -0
  6. package/dist/audit/index.cjs +72 -0
  7. package/dist/audit/index.d.ts +7 -0
  8. package/dist/audit/index.js +72 -0
  9. package/dist/audit/sinks.d.ts +18 -0
  10. package/dist/auth/index.cjs +12 -10
  11. package/dist/auth/index.js +5 -3
  12. package/dist/auth/oauth/http.d.ts +10 -3
  13. package/dist/auth/oauth/index.cjs +189 -29
  14. package/dist/auth/oauth/index.d.ts +6 -4
  15. package/dist/auth/oauth/index.js +169 -9
  16. package/dist/auth/oauth/magic-link.dto.d.ts +6 -0
  17. package/dist/auth/oauth/memory-magic-link.store.d.ts +19 -0
  18. package/dist/auth/oauth/oauth-auth.service.d.ts +46 -5
  19. package/dist/auth/oauth/oauth.controller.d.ts +5 -1
  20. package/dist/auth/oauth/oauth.options.d.ts +34 -1
  21. package/dist/auth/oauth/oauth.ports.d.ts +38 -0
  22. package/dist/bootstrap/index.cjs +9 -6
  23. package/dist/bootstrap/index.js +8 -5
  24. package/dist/{chunk-TJHRABML.cjs → chunk-3AUOOEQO.cjs} +12 -7
  25. package/dist/{chunk-NVCI3CQI.cjs → chunk-4HHZFOVC.cjs} +10 -5
  26. package/dist/{chunk-EYURGACO.js → chunk-4PFAKLT3.js} +1 -1
  27. package/dist/chunk-52IOOHNX.cjs +205 -0
  28. package/dist/chunk-6RAPVLJM.js +212 -0
  29. package/dist/{chunk-7I2Y7V52.js → chunk-A2DGK4ZL.js} +26 -3
  30. package/dist/chunk-APUFKA4K.cjs +212 -0
  31. package/dist/chunk-AXMW5JF7.cjs +83 -0
  32. package/dist/{chunk-KDAA6GFF.js → chunk-DYHSOULW.js} +12 -7
  33. package/dist/chunk-ETRUVZTJ.js +43 -0
  34. package/dist/{chunk-54ZXIB5T.cjs → chunk-FNUZGYUF.cjs} +4 -4
  35. package/dist/{chunk-FDNGAYTZ.cjs → chunk-HDFPSA2V.cjs} +6 -6
  36. package/dist/{chunk-V2M75FN3.cjs → chunk-HVHYZXBB.cjs} +2 -2
  37. package/dist/chunk-IFNYRZP2.js +205 -0
  38. package/dist/{chunk-A3B2EY4V.js → chunk-IKXSVEJ7.js} +7 -2
  39. package/dist/{chunk-YFYHLYHN.js → chunk-M3GQDRWR.js} +7 -1
  40. package/dist/{chunk-J7TURDAL.cjs → chunk-MSTXS3MU.cjs} +28 -5
  41. package/dist/chunk-PNK5WMPP.cjs +30 -0
  42. package/dist/chunk-Q5Y33L7B.cjs +19 -0
  43. package/dist/{chunk-ZA56XBCK.cjs → chunk-SDWHKPXI.cjs} +23 -0
  44. package/dist/chunk-TCAMLNUZ.js +27 -0
  45. package/dist/{chunk-AOCF5QCZ.js → chunk-UNEVXCFW.js} +2 -2
  46. package/dist/chunk-VVMRZEIW.js +30 -0
  47. package/dist/chunk-W2T2VFLC.cjs +57 -0
  48. package/dist/chunk-X4PQJZ4G.js +83 -0
  49. package/dist/chunk-Y72D5L6I.cjs +27 -0
  50. package/dist/{chunk-ORWJ7LES.js → chunk-ZFIDAX7K.js} +1 -1
  51. package/dist/chunk-ZJMLEP5H.js +57 -0
  52. package/dist/crud/crud.controller.d.ts +3 -1
  53. package/dist/crud/crud.service.d.ts +63 -4
  54. package/dist/crud/index.cjs +7 -2
  55. package/dist/crud/index.d.ts +2 -1
  56. package/dist/crud/index.js +6 -1
  57. package/dist/crud/list-query.dto.d.ts +23 -0
  58. package/dist/crud/repository.port.d.ts +33 -1
  59. package/dist/errors/app.exception.d.ts +9 -1
  60. package/dist/errors/common.exceptions.d.ts +6 -5
  61. package/dist/errors/global-exception.filter.d.ts +9 -0
  62. package/dist/errors/index.cjs +8 -5
  63. package/dist/errors/index.js +9 -6
  64. package/dist/i18n/i18n.interceptor.d.ts +16 -0
  65. package/dist/i18n/i18n.module.d.ts +49 -3
  66. package/dist/i18n/index.cjs +26 -2
  67. package/dist/i18n/index.d.ts +8 -0
  68. package/dist/i18n/index.js +25 -1
  69. package/dist/i18n/locale.d.ts +53 -0
  70. package/dist/i18n/message.d.ts +36 -0
  71. package/dist/i18n/nestjs-i18n.translator.d.ts +9 -0
  72. package/dist/i18n/runtime.d.ts +55 -0
  73. package/dist/i18n/translator.port.d.ts +29 -0
  74. package/dist/idempotency/idempotency.interceptor.d.ts +35 -0
  75. package/dist/idempotency/idempotency.module.d.ts +27 -0
  76. package/dist/idempotency/idempotency.options.d.ts +29 -0
  77. package/dist/idempotency/idempotency.port.d.ts +43 -0
  78. package/dist/idempotency/index.cjs +207 -0
  79. package/dist/idempotency/index.d.ts +7 -0
  80. package/dist/idempotency/index.js +207 -0
  81. package/dist/idempotency/memory.store.d.ts +24 -0
  82. package/dist/index.cjs +48 -15
  83. package/dist/index.js +51 -18
  84. package/dist/invoicing/adapters/facturama.invoicing.d.ts +50 -0
  85. package/dist/invoicing/adapters/facturapi.invoicing.d.ts +35 -0
  86. package/dist/invoicing/amounts.d.ts +52 -0
  87. package/dist/invoicing/index.cjs +578 -0
  88. package/dist/invoicing/index.d.ts +11 -0
  89. package/dist/invoicing/index.js +578 -0
  90. package/dist/invoicing/invoicing.module.d.ts +42 -0
  91. package/dist/invoicing/invoicing.options.d.ts +51 -0
  92. package/dist/invoicing/invoicing.port.d.ts +156 -0
  93. package/dist/invoicing/lines.d.ts +21 -0
  94. package/dist/invoicing/provider-http.d.ts +21 -0
  95. package/dist/payments/adapters/clip.terminal.d.ts +101 -0
  96. package/dist/payments/adapters/mercadopago.terminal.d.ts +74 -0
  97. package/dist/payments/index.cjs +796 -0
  98. package/dist/payments/index.d.ts +12 -0
  99. package/dist/payments/index.js +796 -0
  100. package/dist/payments/money.d.ts +20 -0
  101. package/dist/payments/payments-webhook.controller.d.ts +30 -0
  102. package/dist/payments/payments.module.d.ts +45 -0
  103. package/dist/payments/payments.options.d.ts +84 -0
  104. package/dist/payments/payments.port.d.ts +174 -0
  105. package/dist/payments/provider-http.d.ts +26 -0
  106. package/dist/response/api-response.d.ts +7 -0
  107. package/dist/response/index.cjs +12 -4
  108. package/dist/response/index.d.ts +2 -0
  109. package/dist/response/index.js +12 -4
  110. package/dist/response/paginated.d.ts +25 -0
  111. package/dist/response/response.interceptor.d.ts +4 -0
  112. package/dist/stripe/index.cjs +4 -3
  113. package/dist/stripe/index.js +3 -2
  114. package/dist/tracking/index.cjs +3 -3
  115. package/dist/tracking/index.d.ts +1 -1
  116. package/dist/tracking/index.js +2 -2
  117. package/dist/tracking/request-context.d.ts +32 -0
  118. package/package.json +25 -3
  119. package/dist/chunk-3CLYZC3T.cjs +0 -104
  120. package/dist/chunk-EBO6UKHL.js +0 -20
  121. package/dist/chunk-IYUUYCP5.js +0 -36
  122. package/dist/chunk-JOVBJDJ2.js +0 -104
  123. package/dist/chunk-M3EL5O6T.cjs +0 -36
  124. package/dist/chunk-R7BVS6CI.cjs +0 -13
  125. /package/dist/{chunk-MR2IFCZE.cjs → chunk-H2EHN366.cjs} +0 -0
  126. /package/dist/{chunk-NAK4WDKS.js → chunk-ODPSIFOB.js} +0 -0
@@ -0,0 +1,30 @@
1
+ // src/i18n/message.ts
2
+ var I18N_MESSAGE = /* @__PURE__ */ Symbol.for("nestkit.i18n.message");
3
+ var _a;
4
+ _a = I18N_MESSAGE;
5
+ var I18nMessage = class {
6
+ constructor(key, args, fallback) {
7
+ this.key = key;
8
+ this.args = args;
9
+ this.fallback = fallback;
10
+ this[_a] = true;
11
+ }
12
+ toJSON() {
13
+ return this.fallback ?? this.key;
14
+ }
15
+ toString() {
16
+ return this.toJSON();
17
+ }
18
+ };
19
+ function t(key, args, fallback) {
20
+ return new I18nMessage(key, args, fallback);
21
+ }
22
+ function isI18nMessage(value) {
23
+ return typeof value === "object" && value !== null && value[I18N_MESSAGE] === true;
24
+ }
25
+
26
+ export {
27
+ I18nMessage,
28
+ t,
29
+ isI18nMessage
30
+ };
@@ -0,0 +1,57 @@
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
+ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
4
+
5
+
6
+
7
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
8
+
9
+ // src/audit/audit.port.ts
10
+ var AUDIT_SINK = /* @__PURE__ */ Symbol("AUDIT_SINK");
11
+
12
+ // src/audit/audit.options.ts
13
+ var AUDIT_OPTIONS = /* @__PURE__ */ Symbol("AUDIT_OPTIONS");
14
+
15
+ // src/audit/audit.service.ts
16
+ var _common = require('@nestjs/common');
17
+ function withRequestContext(event) {
18
+ const actor = _chunkSDWHKPXIcjs.RequestContext.getActor();
19
+ return {
20
+ ...event,
21
+ actorId: _nullishCoalesce(event.actorId, () => ( _optionalChain([actor, 'optionalAccess', _ => _.id]))),
22
+ tenantId: _nullishCoalesce(event.tenantId, () => ( _optionalChain([actor, 'optionalAccess', _2 => _2.tenantId]))),
23
+ requestId: _nullishCoalesce(event.requestId, () => ( _chunkSDWHKPXIcjs.RequestContext.getRequestId())),
24
+ at: _nullishCoalesce(event.at, () => ( /* @__PURE__ */ new Date()))
25
+ };
26
+ }
27
+ var AuditService = class {
28
+ constructor(sink, options = {}) {
29
+ this.sink = sink;
30
+ this.options = options;
31
+ this.logger = new (0, _common.Logger)(AuditService.name);
32
+ }
33
+ async record(event) {
34
+ const complete = withRequestContext(event);
35
+ try {
36
+ await this.sink.record(complete);
37
+ } catch (error) {
38
+ if (this.options.onError === "fail") throw error;
39
+ this.logger.error(
40
+ `Audit sink failed for ${complete.action} ${complete.resource}: ${error instanceof Error ? error.message : String(error)}`
41
+ );
42
+ }
43
+ }
44
+ };
45
+ AuditService = exports.AuditService = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
46
+ _common.Injectable.call(void 0, ),
47
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, AUDIT_SINK)),
48
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Optional.call(void 0, )),
49
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, AUDIT_OPTIONS))
50
+ ], AuditService);
51
+
52
+
53
+
54
+
55
+
56
+
57
+ exports.AUDIT_SINK = AUDIT_SINK; exports.AUDIT_OPTIONS = AUDIT_OPTIONS; exports.withRequestContext = withRequestContext; exports.AuditService = AuditService;
@@ -0,0 +1,83 @@
1
+ import {
2
+ isPaginated,
3
+ paginated
4
+ } from "./chunk-TCAMLNUZ.js";
5
+ import {
6
+ RequestContext
7
+ } from "./chunk-ETRUVZTJ.js";
8
+ import {
9
+ I18nMessage,
10
+ isI18nMessage
11
+ } from "./chunk-VVMRZEIW.js";
12
+
13
+ // src/i18n/runtime.ts
14
+ var runtime;
15
+ function setI18nRuntime(next) {
16
+ runtime = next;
17
+ }
18
+ function getI18nRuntime() {
19
+ return runtime;
20
+ }
21
+ function currentLanguage() {
22
+ return RequestContext.getLang() ?? runtime?.fallbackLanguage;
23
+ }
24
+ function translate(input, options = {}) {
25
+ const message = typeof input === "string" ? new I18nMessage(input, options.args) : input;
26
+ const fallback = message.fallback ?? options.defaultValue ?? message.key;
27
+ if (!runtime) return fallback;
28
+ const lang = options.lang ?? currentLanguage();
29
+ try {
30
+ return runtime.translator.translate(message.key, { lang, args: message.args }) ?? fallback;
31
+ } catch {
32
+ return fallback;
33
+ }
34
+ }
35
+ function translateDeep(value, lang) {
36
+ if (!runtime) return value;
37
+ return walk(value, lang, /* @__PURE__ */ new WeakSet());
38
+ }
39
+ function walk(value, lang, seen) {
40
+ if (isI18nMessage(value)) return translate(value, { lang });
41
+ if (typeof value !== "object" || value === null) return value;
42
+ if (seen.has(value)) return value;
43
+ if (Array.isArray(value)) {
44
+ seen.add(value);
45
+ let copy2;
46
+ value.forEach((item, index) => {
47
+ const next = walk(item, lang, seen);
48
+ if (next !== item) {
49
+ copy2 ??= [...value];
50
+ copy2[index] = next;
51
+ }
52
+ });
53
+ return copy2 ?? value;
54
+ }
55
+ if (isPaginated(value)) {
56
+ seen.add(value);
57
+ const items = walk(value.items, lang, seen);
58
+ return items === value.items ? value : paginated(items, value.meta);
59
+ }
60
+ if (!isPlainObject(value)) return value;
61
+ seen.add(value);
62
+ let copy;
63
+ for (const [key, item] of Object.entries(value)) {
64
+ const next = walk(item, lang, seen);
65
+ if (next !== item) {
66
+ copy ??= { ...value };
67
+ copy[key] = next;
68
+ }
69
+ }
70
+ return copy ?? value;
71
+ }
72
+ function isPlainObject(value) {
73
+ const proto = Object.getPrototypeOf(value);
74
+ return proto === Object.prototype || proto === null;
75
+ }
76
+
77
+ export {
78
+ setI18nRuntime,
79
+ getI18nRuntime,
80
+ currentLanguage,
81
+ translate,
82
+ translateDeep
83
+ };
@@ -0,0 +1,27 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// 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
+
24
+
25
+
26
+
27
+ exports.buildPageMeta = buildPageMeta; exports.paginated = paginated; exports.isPaginated = isPaginated;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AppException
3
- } from "./chunk-YFYHLYHN.js";
3
+ } from "./chunk-M3GQDRWR.js";
4
4
 
5
5
  // src/errors/common.exceptions.ts
6
6
  import { HttpStatus } from "@nestjs/common";
@@ -0,0 +1,57 @@
1
+ import {
2
+ RequestContext
3
+ } from "./chunk-ETRUVZTJ.js";
4
+ import {
5
+ __decorateClass,
6
+ __decorateParam
7
+ } from "./chunk-4MGIQFAJ.js";
8
+
9
+ // src/audit/audit.port.ts
10
+ var AUDIT_SINK = /* @__PURE__ */ Symbol("AUDIT_SINK");
11
+
12
+ // src/audit/audit.options.ts
13
+ var AUDIT_OPTIONS = /* @__PURE__ */ Symbol("AUDIT_OPTIONS");
14
+
15
+ // src/audit/audit.service.ts
16
+ import { Inject, Injectable, Logger, Optional } from "@nestjs/common";
17
+ function withRequestContext(event) {
18
+ const actor = RequestContext.getActor();
19
+ return {
20
+ ...event,
21
+ actorId: event.actorId ?? actor?.id,
22
+ tenantId: event.tenantId ?? actor?.tenantId,
23
+ requestId: event.requestId ?? RequestContext.getRequestId(),
24
+ at: event.at ?? /* @__PURE__ */ new Date()
25
+ };
26
+ }
27
+ var AuditService = class {
28
+ constructor(sink, options = {}) {
29
+ this.sink = sink;
30
+ this.options = options;
31
+ this.logger = new Logger(AuditService.name);
32
+ }
33
+ async record(event) {
34
+ const complete = withRequestContext(event);
35
+ try {
36
+ await this.sink.record(complete);
37
+ } catch (error) {
38
+ if (this.options.onError === "fail") throw error;
39
+ this.logger.error(
40
+ `Audit sink failed for ${complete.action} ${complete.resource}: ${error instanceof Error ? error.message : String(error)}`
41
+ );
42
+ }
43
+ }
44
+ };
45
+ AuditService = __decorateClass([
46
+ Injectable(),
47
+ __decorateParam(0, Inject(AUDIT_SINK)),
48
+ __decorateParam(1, Optional()),
49
+ __decorateParam(1, Inject(AUDIT_OPTIONS))
50
+ ], AuditService);
51
+
52
+ export {
53
+ AUDIT_SINK,
54
+ AUDIT_OPTIONS,
55
+ withRequestContext,
56
+ AuditService
57
+ };
@@ -1,6 +1,8 @@
1
1
  import { type Type } from '@nestjs/common';
2
+ import type { Paginated } from '../response/paginated.js';
2
3
  import type { BaseEntity } from '../entities/base.entity.js';
3
4
  import type { BaseCrudService } from './crud.service.js';
5
+ import { ListQuery } from './list-query.dto.js';
4
6
  export interface CreateCrudControllerOptions {
5
7
  /** Route prefix for the generated controller. Defaults to no prefix. */
6
8
  path?: string;
@@ -31,7 +33,7 @@ export interface CreateCrudControllerOptions {
31
33
  * }) {}
32
34
  */
33
35
  export declare function createCrudController<T extends BaseEntity>(serviceToken: Type<BaseCrudService<T>>, options?: CreateCrudControllerOptions): Type<{
34
- findAll(filter: Partial<T> | undefined, req: unknown): Promise<T[]>;
36
+ findAll(query: ListQuery, req: unknown): Promise<Paginated<T>>;
35
37
  findById(id: string, req: unknown): Promise<T | null>;
36
38
  create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>, req: unknown): Promise<T>;
37
39
  update(id: string, data: Partial<T>, req: unknown): Promise<T>;
@@ -1,6 +1,9 @@
1
+ import type { AuditSinkPort } from '../audit/audit.port.js';
2
+ import { type Paginated } from '../response/paginated.js';
1
3
  import type { BaseEntity } from '../entities/base.entity.js';
4
+ import type { ListQuery } from './list-query.dto.js';
2
5
  import type { Repository } from './repository.port.js';
3
- export interface BaseCrudServiceOptions {
6
+ export interface BaseCrudServiceOptions<T extends BaseEntity = BaseEntity> {
4
7
  /**
5
8
  * 'hard' (default): delete() calls repository.delete().
6
9
  * 'soft': delete() calls repository.update(id, { deletedAt: new Date() })
@@ -11,6 +14,45 @@ export interface BaseCrudServiceOptions {
11
14
  * if you always soft-delete.
12
15
  */
13
16
  deleteStrategy?: 'soft' | 'hard';
17
+ /** Page size when the caller does not ask for one. Defaults to 20. */
18
+ defaultLimit?: number;
19
+ /**
20
+ * Largest page this service will serve, whatever the query string says.
21
+ * Defaults to 100.
22
+ */
23
+ maxLimit?: number;
24
+ /**
25
+ * Fields a caller may filter by. **Empty by default, and that is the
26
+ * point**: the previous behaviour forwarded the whole query string to the
27
+ * repository, so any column — a password hash, an internal flag, another
28
+ * tenant's marker — could be used to probe rows one guess at a time.
29
+ * Opening a field is one line; leaving it open by accident is a leak.
30
+ */
31
+ filterable?: (keyof T & string)[];
32
+ /**
33
+ * Fields a caller may sort by. Empty by default for the same reason plus a
34
+ * sharper one: adapters interpolate this name into SQL.
35
+ */
36
+ sortable?: (keyof T & string)[];
37
+ /**
38
+ * Records every create, update and delete this service performs.
39
+ *
40
+ * `recorder` is anything with `record(event)`: the raw `AuditSinkPort`, or
41
+ * `AuditService` — pass the service to inherit its policy for a failing
42
+ * sink, because this class does not catch. One place decides whether a lost
43
+ * entry stops the operation, and it is not this one.
44
+ */
45
+ audit?: {
46
+ recorder: AuditSinkPort;
47
+ /** Name of the thing being changed, as the trail should read: `invoice`, `widget`. */
48
+ resource: string;
49
+ /**
50
+ * Read the row before updating or deleting it, so the entry carries what
51
+ * it used to say. Off by default: it is an extra query per write, and a
52
+ * trail without it still answers who and when.
53
+ */
54
+ includeBefore?: boolean;
55
+ };
14
56
  }
15
57
  /**
16
58
  * Generic CRUD orchestration on top of a Repository<T> port. Optional to
@@ -19,11 +61,28 @@ export interface BaseCrudServiceOptions {
19
61
  */
20
62
  export declare class BaseCrudService<T extends BaseEntity> {
21
63
  protected readonly repository: Repository<T>;
22
- protected readonly options: BaseCrudServiceOptions;
23
- constructor(repository: Repository<T>, options?: BaseCrudServiceOptions);
64
+ protected readonly options: BaseCrudServiceOptions<T>;
65
+ constructor(repository: Repository<T>, options?: BaseCrudServiceOptions<T>);
24
66
  findById(id: string, tenantId?: string): Promise<T | null>;
25
- findAll(filter?: Partial<T>, tenantId?: string): Promise<T[]>;
67
+ /**
68
+ * One page of rows.
69
+ *
70
+ * Everything a caller can influence is bounded here rather than in the
71
+ * controller, so calling the service directly is as safe as going through
72
+ * HTTP: the limit is capped, and filter and sort fields are checked against
73
+ * the allowlists before they reach the adapter.
74
+ */
75
+ findAll(query?: ListQuery, tenantId?: string): Promise<Paginated<T>>;
76
+ /**
77
+ * Keeps only the query fields this service declares filterable. Anything
78
+ * else is dropped silently — a rejection would tell a caller which columns
79
+ * exist, which is the question they were asking.
80
+ */
81
+ protected allowedFilter(query: Record<string, unknown>): Partial<T> | undefined;
26
82
  create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>, tenantId?: string): Promise<T>;
27
83
  update(id: string, data: Partial<T>, tenantId?: string): Promise<T>;
28
84
  delete(id: string, tenantId?: string): Promise<void>;
85
+ /** Only when the trail is configured to want it — otherwise it is a query for nothing. */
86
+ private readBefore;
87
+ private audit;
29
88
  }
@@ -1,9 +1,14 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunk3CLYZC3Tcjs = require('../chunk-3CLYZC3T.cjs');
4
+
5
+ var _chunk52IOOHNXcjs = require('../chunk-52IOOHNX.cjs');
6
+ require('../chunk-W2T2VFLC.cjs');
7
+ require('../chunk-Y72D5L6I.cjs');
8
+ require('../chunk-SDWHKPXI.cjs');
5
9
  require('../chunk-2REOCMUD.cjs');
6
10
 
7
11
 
8
12
 
9
- exports.BaseCrudService = _chunk3CLYZC3Tcjs.BaseCrudService; exports.createCrudController = _chunk3CLYZC3Tcjs.createCrudController;
13
+
14
+ exports.BaseCrudService = _chunk52IOOHNXcjs.BaseCrudService; exports.ListQuery = _chunk52IOOHNXcjs.ListQuery; exports.createCrudController = _chunk52IOOHNXcjs.createCrudController;
@@ -1,4 +1,5 @@
1
- export type { Repository } from './repository.port.js';
1
+ export type { Repository, FindAllOptions, PageResult } from './repository.port.js';
2
+ export { ListQuery } from './list-query.dto.js';
2
3
  export { BaseCrudService } from './crud.service.js';
3
4
  export type { BaseCrudServiceOptions } from './crud.service.js';
4
5
  export { createCrudController } from './crud.controller.js';
@@ -1,9 +1,14 @@
1
1
  import {
2
2
  BaseCrudService,
3
+ ListQuery,
3
4
  createCrudController
4
- } from "../chunk-JOVBJDJ2.js";
5
+ } from "../chunk-IFNYRZP2.js";
6
+ import "../chunk-ZJMLEP5H.js";
7
+ import "../chunk-TCAMLNUZ.js";
8
+ import "../chunk-ETRUVZTJ.js";
5
9
  import "../chunk-4MGIQFAJ.js";
6
10
  export {
7
11
  BaseCrudService,
12
+ ListQuery,
8
13
  createCrudController
9
14
  };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Query string of a list endpoint, as a real DTO.
3
+ *
4
+ * Being a class with decorators is the point: the global `ValidationPipe` runs
5
+ * with `whitelist: true`, which only strips unknown properties when there is a
6
+ * class to compare against. The previous signature typed the query as
7
+ * `Partial<T>`, and a bare type carries no metadata — so nothing was stripped
8
+ * and every column of the entity was filterable from the URL.
9
+ *
10
+ * `@Type(() => Number)` is not decoration: query values arrive as strings, and
11
+ * `?limit=20` without it is the string `"20"`, which `@IsInt()` rejects.
12
+ */
13
+ export declare class ListQuery {
14
+ page?: number;
15
+ /**
16
+ * Capped at 200 here and again, per service, by `maxLimit`. The hard cap
17
+ * exists so a forgotten configuration cannot turn into `?limit=1000000`.
18
+ */
19
+ limit?: number;
20
+ /** Ignored unless the service lists the field in `sortable`. */
21
+ sortBy?: string;
22
+ sortOrder?: 'asc' | 'desc';
23
+ }
@@ -1,4 +1,31 @@
1
1
  import type { BaseEntity } from '../entities/base.entity.js';
2
+ /** What a list query asks of the adapter, already validated and capped. */
3
+ export interface FindAllOptions<T> {
4
+ /** Equality filter. Only the fields the service allows ever reach here. */
5
+ filter?: Partial<T>;
6
+ /** How many rows to return. Always set by `BaseCrudService`. */
7
+ limit?: number;
8
+ offset?: number;
9
+ /**
10
+ * Column to order by — **already checked against an allowlist**. Adapters
11
+ * build SQL by interpolating this name, so an adapter must never accept one
12
+ * straight from a request.
13
+ */
14
+ sortBy?: string;
15
+ sortOrder?: 'asc' | 'desc';
16
+ }
17
+ /**
18
+ * One page of rows plus the total the filter matches.
19
+ *
20
+ * The total is what a pager needs and the one thing the adapter cannot skip:
21
+ * `items.length` only says how full the page is. An adapter that genuinely
22
+ * cannot count cheaply should still return something honest — the count of a
23
+ * bounded query — rather than a number nobody can act on.
24
+ */
25
+ export interface PageResult<T> {
26
+ items: T[];
27
+ total: number;
28
+ }
2
29
  /**
3
30
  * Persistence port every adapter (Postgres, Supabase, future Mongo, or a
4
31
  * hand-rolled one) implements. `tenantId` is optional so the same port
@@ -7,7 +34,12 @@ import type { BaseEntity } from '../entities/base.entity.js';
7
34
  */
8
35
  export interface Repository<T extends BaseEntity, ID = string> {
9
36
  findById(id: ID, tenantId?: string): Promise<T | null>;
10
- findAll(filter?: Partial<T>, tenantId?: string): Promise<T[]>;
37
+ /**
38
+ * A page of rows. Always bounded: `BaseCrudService` fills in a limit even
39
+ * when the caller asked for none, because the unbounded version of this
40
+ * method is a table scan waiting for the table to grow.
41
+ */
42
+ findAll(options?: FindAllOptions<T>, tenantId?: string): Promise<PageResult<T>>;
11
43
  create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>, tenantId?: string): Promise<T>;
12
44
  update(id: ID, data: Partial<T>, tenantId?: string): Promise<T>;
13
45
  delete(id: ID, tenantId?: string): Promise<void>;
@@ -1,11 +1,19 @@
1
1
  import { HttpException, type HttpStatus } from '@nestjs/common';
2
+ import { type I18nMessage } from '../i18n/message.js';
2
3
  /**
3
4
  * Base for all domain/application exceptions in nestkit-based services.
4
5
  * Carries a stable machine-readable `code` (independent from the HTTP
5
6
  * status) that clients can branch on, plus optional structured `details`.
7
+ *
8
+ * The message may be a lazy {@link I18nMessage}: `GlobalExceptionFilter`
9
+ * translates it in the request's language, and `message` (what Nest and the
10
+ * logs see) holds its fallback meanwhile. `details` may contain messages too
11
+ * — a per-field validation map, say — and is translated the same way.
6
12
  */
7
13
  export declare class AppException extends HttpException {
8
14
  readonly code: string;
9
15
  readonly details?: unknown;
10
- constructor(code: string, message: string, status: HttpStatus, details?: unknown);
16
+ /** The untranslated message, when one was given. */
17
+ readonly i18n?: I18nMessage;
18
+ constructor(code: string, message: string | I18nMessage, status: HttpStatus, details?: unknown);
11
19
  }
@@ -1,16 +1,17 @@
1
+ import type { I18nMessage } from '../i18n/message.js';
1
2
  import { AppException } from './app.exception.js';
2
3
  export declare class NotFoundAppException extends AppException {
3
- constructor(message?: string, details?: unknown, code?: string);
4
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
4
5
  }
5
6
  export declare class ConflictAppException extends AppException {
6
- constructor(message?: string, details?: unknown, code?: string);
7
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
7
8
  }
8
9
  export declare class ValidationAppException extends AppException {
9
- constructor(message?: string, details?: unknown, code?: string);
10
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
10
11
  }
11
12
  export declare class UnauthorizedAppException extends AppException {
12
- constructor(message?: string, details?: unknown, code?: string);
13
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
13
14
  }
14
15
  export declare class ForbiddenAppException extends AppException {
15
- constructor(message?: string, details?: unknown, code?: string);
16
+ constructor(message?: string | I18nMessage, details?: unknown, code?: string);
16
17
  }
@@ -5,9 +5,18 @@ import { type ArgumentsHost, type ExceptionFilter } from '@nestjs/common';
5
5
  * with `app.useGlobalFilters(new GlobalExceptionFilter())` (or via
6
6
  * `applyNestKitDefaults`). Never leaks a stack trace to the client — it only
7
7
  * goes to the Nest Logger.
8
+ *
9
+ * When `I18nModule` is wired, the error speaks the request's language: an
10
+ * `AppException` built with `t()` is translated, its `details` are walked for
11
+ * messages, and one built with a plain string is looked up by `code` under the
12
+ * configured namespace (`errors.NOT_FOUND`) so a consumer can translate every
13
+ * error the package itself throws without touching a single `throw`. The
14
+ * language is resolved here from the request rather than read from
15
+ * `RequestContext`, because a guard fails before `I18nInterceptor` runs.
8
16
  */
9
17
  export declare class GlobalExceptionFilter implements ExceptionFilter {
10
18
  private readonly logger;
11
19
  catch(exception: unknown, host: ArgumentsHost): void;
20
+ private localize;
12
21
  private resolve;
13
22
  }
@@ -1,18 +1,21 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-7SOM7EZP.cjs');
2
2
 
3
3
 
4
+ var _chunkMSTXS3MUcjs = require('../chunk-MSTXS3MU.cjs');
5
+ require('../chunk-AXMW5JF7.cjs');
6
+ require('../chunk-Y72D5L6I.cjs');
7
+ require('../chunk-SDWHKPXI.cjs');
4
8
 
5
9
 
6
10
 
7
11
 
8
- var _chunkFDNGAYTZcjs = require('../chunk-FDNGAYTZ.cjs');
9
12
 
10
13
 
11
- var _chunkJ7TURDALcjs = require('../chunk-J7TURDAL.cjs');
12
- require('../chunk-ZA56XBCK.cjs');
14
+ var _chunkHDFPSA2Vcjs = require('../chunk-HDFPSA2V.cjs');
13
15
 
14
16
 
15
- var _chunkR7BVS6CIcjs = require('../chunk-R7BVS6CI.cjs');
17
+ var _chunkQ5Y33L7Bcjs = require('../chunk-Q5Y33L7B.cjs');
18
+ require('../chunk-PNK5WMPP.cjs');
16
19
  require('../chunk-2REOCMUD.cjs');
17
20
 
18
21
 
@@ -22,4 +25,4 @@ require('../chunk-2REOCMUD.cjs');
22
25
 
23
26
 
24
27
 
25
- exports.AppException = _chunkR7BVS6CIcjs.AppException; exports.ConflictAppException = _chunkFDNGAYTZcjs.ConflictAppException; exports.ForbiddenAppException = _chunkFDNGAYTZcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunkJ7TURDALcjs.GlobalExceptionFilter; exports.NotFoundAppException = _chunkFDNGAYTZcjs.NotFoundAppException; exports.UnauthorizedAppException = _chunkFDNGAYTZcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkFDNGAYTZcjs.ValidationAppException;
28
+ exports.AppException = _chunkQ5Y33L7Bcjs.AppException; exports.ConflictAppException = _chunkHDFPSA2Vcjs.ConflictAppException; exports.ForbiddenAppException = _chunkHDFPSA2Vcjs.ForbiddenAppException; exports.GlobalExceptionFilter = _chunkMSTXS3MUcjs.GlobalExceptionFilter; exports.NotFoundAppException = _chunkHDFPSA2Vcjs.NotFoundAppException; exports.UnauthorizedAppException = _chunkHDFPSA2Vcjs.UnauthorizedAppException; exports.ValidationAppException = _chunkHDFPSA2Vcjs.ValidationAppException;
@@ -1,18 +1,21 @@
1
1
  import "../chunk-DQYAIQQ5.js";
2
+ import {
3
+ GlobalExceptionFilter
4
+ } from "../chunk-A2DGK4ZL.js";
5
+ import "../chunk-X4PQJZ4G.js";
6
+ import "../chunk-TCAMLNUZ.js";
7
+ import "../chunk-ETRUVZTJ.js";
2
8
  import {
3
9
  ConflictAppException,
4
10
  ForbiddenAppException,
5
11
  NotFoundAppException,
6
12
  UnauthorizedAppException,
7
13
  ValidationAppException
8
- } from "../chunk-ORWJ7LES.js";
9
- import {
10
- GlobalExceptionFilter
11
- } from "../chunk-7I2Y7V52.js";
12
- import "../chunk-EBO6UKHL.js";
14
+ } from "../chunk-ZFIDAX7K.js";
13
15
  import {
14
16
  AppException
15
- } from "../chunk-YFYHLYHN.js";
17
+ } from "../chunk-M3GQDRWR.js";
18
+ import "../chunk-VVMRZEIW.js";
16
19
  import "../chunk-4MGIQFAJ.js";
17
20
  export {
18
21
  AppException,
@@ -0,0 +1,16 @@
1
+ import { type CallHandler, type ExecutionContext, type NestInterceptor } from '@nestjs/common';
2
+ import type { Observable } from 'rxjs';
3
+ /**
4
+ * Resolves the request's language from the sources `I18nModule` was
5
+ * configured with, records it in `RequestContext` for the handler's benefit,
6
+ * and translates every {@link I18nMessage} in whatever the handler returns.
7
+ *
8
+ * `I18nModule.forRoot` registers it as a global `APP_INTERCEPTOR`, which
9
+ * Nest runs *inside* the ones added with `useGlobalInterceptors` — so on the
10
+ * way out it sees the raw return value before `ResponseInterceptor` wraps it
11
+ * in the envelope. It is harmless without the module: with no runtime it
12
+ * passes everything through untouched.
13
+ */
14
+ export declare class I18nInterceptor implements NestInterceptor {
15
+ intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
16
+ }