@miguelmorales13/nestkit 0.11.0 → 0.16.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 (90) hide show
  1. package/README.md +469 -9
  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 +4 -3
  11. package/dist/auth/index.js +2 -1
  12. package/dist/auth/oauth/index.cjs +6 -5
  13. package/dist/auth/oauth/index.js +2 -1
  14. package/dist/bootstrap/index.cjs +6 -5
  15. package/dist/bootstrap/index.js +5 -4
  16. package/dist/chunk-47FXU74G.cjs +205 -0
  17. package/dist/{chunk-54ZXIB5T.cjs → chunk-4GT66KQS.cjs} +4 -4
  18. package/dist/{chunk-J7TURDAL.cjs → chunk-67B7IYAV.cjs} +2 -2
  19. package/dist/{chunk-NVCI3CQI.cjs → chunk-C5DV4RAX.cjs} +6 -1
  20. package/dist/{chunk-KDAA6GFF.js → chunk-DABTRWA6.js} +12 -7
  21. package/dist/{chunk-ZA56XBCK.cjs → chunk-EBPEMVZU.cjs} +15 -0
  22. package/dist/{chunk-EYURGACO.js → chunk-JV4EAOF2.js} +1 -1
  23. package/dist/chunk-KP2ZHJSR.js +35 -0
  24. package/dist/{chunk-7I2Y7V52.js → chunk-KRC47OX6.js} +1 -1
  25. package/dist/chunk-LK3OINS7.js +205 -0
  26. package/dist/{chunk-A3B2EY4V.js → chunk-MLOQDUBN.js} +6 -1
  27. package/dist/chunk-TCAMLNUZ.js +27 -0
  28. package/dist/{chunk-V2M75FN3.cjs → chunk-U7QK24HL.cjs} +2 -2
  29. package/dist/{chunk-AOCF5QCZ.js → chunk-UIVBPNH4.js} +4 -4
  30. package/dist/{chunk-TJHRABML.cjs → chunk-UWDHAZVE.cjs} +12 -7
  31. package/dist/chunk-XHW4CTBS.js +57 -0
  32. package/dist/chunk-XX5ROVSC.cjs +57 -0
  33. package/dist/chunk-Y72D5L6I.cjs +27 -0
  34. package/dist/crud/crud.controller.d.ts +3 -1
  35. package/dist/crud/crud.service.d.ts +63 -4
  36. package/dist/crud/index.cjs +7 -2
  37. package/dist/crud/index.d.ts +2 -1
  38. package/dist/crud/index.js +6 -1
  39. package/dist/crud/list-query.dto.d.ts +23 -0
  40. package/dist/crud/repository.port.d.ts +33 -1
  41. package/dist/errors/index.cjs +4 -4
  42. package/dist/errors/index.js +4 -4
  43. package/dist/idempotency/idempotency.interceptor.d.ts +35 -0
  44. package/dist/idempotency/idempotency.module.d.ts +27 -0
  45. package/dist/idempotency/idempotency.options.d.ts +29 -0
  46. package/dist/idempotency/idempotency.port.d.ts +43 -0
  47. package/dist/idempotency/index.cjs +206 -0
  48. package/dist/idempotency/index.d.ts +7 -0
  49. package/dist/idempotency/index.js +206 -0
  50. package/dist/idempotency/memory.store.d.ts +24 -0
  51. package/dist/index.cjs +26 -15
  52. package/dist/index.js +27 -16
  53. package/dist/invoicing/adapters/facturama.invoicing.d.ts +50 -0
  54. package/dist/invoicing/adapters/facturapi.invoicing.d.ts +35 -0
  55. package/dist/invoicing/amounts.d.ts +52 -0
  56. package/dist/invoicing/index.cjs +577 -0
  57. package/dist/invoicing/index.d.ts +11 -0
  58. package/dist/invoicing/index.js +577 -0
  59. package/dist/invoicing/invoicing.module.d.ts +42 -0
  60. package/dist/invoicing/invoicing.options.d.ts +51 -0
  61. package/dist/invoicing/invoicing.port.d.ts +156 -0
  62. package/dist/invoicing/lines.d.ts +21 -0
  63. package/dist/invoicing/provider-http.d.ts +21 -0
  64. package/dist/payments/adapters/clip.terminal.d.ts +101 -0
  65. package/dist/payments/adapters/mercadopago.terminal.d.ts +74 -0
  66. package/dist/payments/index.cjs +795 -0
  67. package/dist/payments/index.d.ts +12 -0
  68. package/dist/payments/index.js +795 -0
  69. package/dist/payments/money.d.ts +20 -0
  70. package/dist/payments/payments-webhook.controller.d.ts +30 -0
  71. package/dist/payments/payments.module.d.ts +45 -0
  72. package/dist/payments/payments.options.d.ts +84 -0
  73. package/dist/payments/payments.port.d.ts +174 -0
  74. package/dist/payments/provider-http.d.ts +26 -0
  75. package/dist/response/api-response.d.ts +7 -0
  76. package/dist/response/index.cjs +12 -4
  77. package/dist/response/index.d.ts +2 -0
  78. package/dist/response/index.js +12 -4
  79. package/dist/response/paginated.d.ts +25 -0
  80. package/dist/response/response.interceptor.d.ts +4 -0
  81. package/dist/tracking/index.cjs +3 -3
  82. package/dist/tracking/index.d.ts +1 -1
  83. package/dist/tracking/index.js +2 -2
  84. package/dist/tracking/request-context.d.ts +22 -0
  85. package/package.json +25 -3
  86. package/dist/chunk-3CLYZC3T.cjs +0 -104
  87. package/dist/chunk-EBO6UKHL.js +0 -20
  88. package/dist/chunk-JOVBJDJ2.js +0 -104
  89. /package/dist/{chunk-MR2IFCZE.cjs → chunk-H2EHN366.cjs} +0 -0
  90. /package/dist/{chunk-NAK4WDKS.js → chunk-ODPSIFOB.js} +0 -0
@@ -0,0 +1,72 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+
4
+
5
+
6
+ var _chunkXX5ROVSCcjs = require('../chunk-XX5ROVSC.cjs');
7
+ require('../chunk-EBPEMVZU.cjs');
8
+
9
+
10
+ var _chunk2REOCMUDcjs = require('../chunk-2REOCMUD.cjs');
11
+
12
+ // src/audit/sinks.ts
13
+ var _common = require('@nestjs/common');
14
+ var LoggerAuditSink = class {
15
+ constructor() {
16
+ this.logger = new (0, _common.Logger)("Audit");
17
+ }
18
+ async record(event) {
19
+ this.logger.log(JSON.stringify({ ...event, at: (_nullishCoalesce(event.at, () => ( /* @__PURE__ */ new Date()))).toISOString() }));
20
+ }
21
+ };
22
+ var MemoryAuditSink = class {
23
+ constructor() {
24
+ this.events = [];
25
+ }
26
+ async record(event) {
27
+ this.events.push(event);
28
+ }
29
+ };
30
+
31
+ // src/audit/audit.module.ts
32
+
33
+ var AuditModule = class {
34
+ static forRoot(options = {}) {
35
+ const providers = [
36
+ { provide: _chunkXX5ROVSCcjs.AUDIT_OPTIONS, useValue: options },
37
+ { provide: _chunkXX5ROVSCcjs.AUDIT_SINK, useFactory: () => _nullishCoalesce(options.sink, () => ( new LoggerAuditSink())) },
38
+ _chunkXX5ROVSCcjs.AuditService
39
+ ];
40
+ return { module: AuditModule, providers, exports: [_chunkXX5ROVSCcjs.AUDIT_SINK, _chunkXX5ROVSCcjs.AUDIT_OPTIONS, _chunkXX5ROVSCcjs.AuditService] };
41
+ }
42
+ static forRootAsync(config) {
43
+ const providers = [
44
+ { provide: _chunkXX5ROVSCcjs.AUDIT_OPTIONS, useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) },
45
+ {
46
+ provide: _chunkXX5ROVSCcjs.AUDIT_SINK,
47
+ useFactory: (options) => _nullishCoalesce(options.sink, () => ( new LoggerAuditSink())),
48
+ inject: [_chunkXX5ROVSCcjs.AUDIT_OPTIONS]
49
+ },
50
+ _chunkXX5ROVSCcjs.AuditService
51
+ ];
52
+ return {
53
+ module: AuditModule,
54
+ imports: _nullishCoalesce(config.imports, () => ( [])),
55
+ providers,
56
+ exports: [_chunkXX5ROVSCcjs.AUDIT_SINK, _chunkXX5ROVSCcjs.AUDIT_OPTIONS, _chunkXX5ROVSCcjs.AuditService]
57
+ };
58
+ }
59
+ };
60
+ AuditModule = exports.AuditModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
61
+ _common.Global.call(void 0, ),
62
+ _common.Module.call(void 0, {})
63
+ ], AuditModule);
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+ exports.AUDIT_OPTIONS = _chunkXX5ROVSCcjs.AUDIT_OPTIONS; exports.AUDIT_SINK = _chunkXX5ROVSCcjs.AUDIT_SINK; exports.AuditModule = AuditModule; exports.AuditService = _chunkXX5ROVSCcjs.AuditService; exports.LoggerAuditSink = LoggerAuditSink; exports.MemoryAuditSink = MemoryAuditSink; exports.withRequestContext = _chunkXX5ROVSCcjs.withRequestContext;
@@ -0,0 +1,7 @@
1
+ export { AUDIT_SINK } from './audit.port.js';
2
+ export type { AuditEvent, AuditSinkPort } from './audit.port.js';
3
+ export { AUDIT_OPTIONS } from './audit.options.js';
4
+ export type { AuditOptions } from './audit.options.js';
5
+ export { AuditService, withRequestContext } from './audit.service.js';
6
+ export { LoggerAuditSink, MemoryAuditSink } from './sinks.js';
7
+ export { AuditModule } from './audit.module.js';
@@ -0,0 +1,72 @@
1
+ import {
2
+ AUDIT_OPTIONS,
3
+ AUDIT_SINK,
4
+ AuditService,
5
+ withRequestContext
6
+ } from "../chunk-XHW4CTBS.js";
7
+ import "../chunk-KP2ZHJSR.js";
8
+ import {
9
+ __decorateClass
10
+ } from "../chunk-4MGIQFAJ.js";
11
+
12
+ // src/audit/sinks.ts
13
+ import { Logger } from "@nestjs/common";
14
+ var LoggerAuditSink = class {
15
+ constructor() {
16
+ this.logger = new Logger("Audit");
17
+ }
18
+ async record(event) {
19
+ this.logger.log(JSON.stringify({ ...event, at: (event.at ?? /* @__PURE__ */ new Date()).toISOString() }));
20
+ }
21
+ };
22
+ var MemoryAuditSink = class {
23
+ constructor() {
24
+ this.events = [];
25
+ }
26
+ async record(event) {
27
+ this.events.push(event);
28
+ }
29
+ };
30
+
31
+ // src/audit/audit.module.ts
32
+ import { Global, Module } from "@nestjs/common";
33
+ var AuditModule = class {
34
+ static forRoot(options = {}) {
35
+ const providers = [
36
+ { provide: AUDIT_OPTIONS, useValue: options },
37
+ { provide: AUDIT_SINK, useFactory: () => options.sink ?? new LoggerAuditSink() },
38
+ AuditService
39
+ ];
40
+ return { module: AuditModule, providers, exports: [AUDIT_SINK, AUDIT_OPTIONS, AuditService] };
41
+ }
42
+ static forRootAsync(config) {
43
+ const providers = [
44
+ { provide: AUDIT_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },
45
+ {
46
+ provide: AUDIT_SINK,
47
+ useFactory: (options) => options.sink ?? new LoggerAuditSink(),
48
+ inject: [AUDIT_OPTIONS]
49
+ },
50
+ AuditService
51
+ ];
52
+ return {
53
+ module: AuditModule,
54
+ imports: config.imports ?? [],
55
+ providers,
56
+ exports: [AUDIT_SINK, AUDIT_OPTIONS, AuditService]
57
+ };
58
+ }
59
+ };
60
+ AuditModule = __decorateClass([
61
+ Global(),
62
+ Module({})
63
+ ], AuditModule);
64
+ export {
65
+ AUDIT_OPTIONS,
66
+ AUDIT_SINK,
67
+ AuditModule,
68
+ AuditService,
69
+ LoggerAuditSink,
70
+ MemoryAuditSink,
71
+ withRequestContext
72
+ };
@@ -0,0 +1,18 @@
1
+ import type { AuditEvent, AuditSinkPort } from './audit.port.js';
2
+ /**
3
+ * Writes the trail to the application log as one JSON line per event.
4
+ *
5
+ * A reasonable default and a poor final answer: logs rotate, and the question
6
+ * an audit trail exists to answer ("who deleted this, in March") is asked long
7
+ * after the log is gone. Good for development and for shipping to a log
8
+ * pipeline; not a substitute for a table.
9
+ */
10
+ export declare class LoggerAuditSink implements AuditSinkPort {
11
+ private readonly logger;
12
+ record(event: AuditEvent): Promise<void>;
13
+ }
14
+ /** Keeps events in memory. For tests, and for seeing the shape in development. */
15
+ export declare class MemoryAuditSink implements AuditSinkPort {
16
+ readonly events: AuditEvent[];
17
+ record(event: AuditEvent): Promise<void>;
18
+ }
@@ -2,7 +2,8 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkNVCI3CQIcjs = require('../chunk-NVCI3CQI.cjs');
5
+ var _chunkC5DV4RAXcjs = require('../chunk-C5DV4RAX.cjs');
6
+ require('../chunk-EBPEMVZU.cjs');
6
7
 
7
8
 
8
9
 
@@ -106,7 +107,7 @@ _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
106
107
 
107
108
  // src/auth/auth.service.ts
108
109
  var BaseAuthService = class {
109
- constructor(users, tokens = new (0, _chunkNVCI3CQIcjs.TokenService)()) {
110
+ constructor(users, tokens = new (0, _chunkC5DV4RAXcjs.TokenService)()) {
110
111
  this.users = users;
111
112
  this.tokens = tokens;
112
113
  }
@@ -204,4 +205,4 @@ function createAuthController(serviceToken, options = {}) {
204
205
 
205
206
 
206
207
 
207
- exports.BaseAuthService = BaseAuthService; exports.CurrentTenant = CurrentTenant; exports.CurrentUser = _chunkNVCI3CQIcjs.CurrentUser; exports.JwtAuthGuard = _chunkNVCI3CQIcjs.JwtAuthGuard; exports.LoginDto = LoginDto; exports.ROLES_KEY = ROLES_KEY; exports.RefreshDto = RefreshDto; exports.RegisterDto = RegisterDto; exports.RequireTenantGuard = RequireTenantGuard; exports.Roles = Roles; exports.RolesGuard = RolesGuard; exports.TokenService = _chunkNVCI3CQIcjs.TokenService; exports.createAuthController = createAuthController; exports.hashPassword = hashPassword; exports.verifyPassword = verifyPassword;
208
+ exports.BaseAuthService = BaseAuthService; exports.CurrentTenant = CurrentTenant; exports.CurrentUser = _chunkC5DV4RAXcjs.CurrentUser; exports.JwtAuthGuard = _chunkC5DV4RAXcjs.JwtAuthGuard; exports.LoginDto = LoginDto; exports.ROLES_KEY = ROLES_KEY; exports.RefreshDto = RefreshDto; exports.RegisterDto = RegisterDto; exports.RequireTenantGuard = RequireTenantGuard; exports.Roles = Roles; exports.RolesGuard = RolesGuard; exports.TokenService = _chunkC5DV4RAXcjs.TokenService; exports.createAuthController = createAuthController; exports.hashPassword = hashPassword; exports.verifyPassword = verifyPassword;
@@ -2,7 +2,8 @@ import {
2
2
  CurrentUser,
3
3
  JwtAuthGuard,
4
4
  TokenService
5
- } from "../chunk-A3B2EY4V.js";
5
+ } from "../chunk-MLOQDUBN.js";
6
+ import "../chunk-KP2ZHJSR.js";
6
7
  import {
7
8
  ConflictAppException,
8
9
  ForbiddenAppException,
@@ -1,7 +1,8 @@
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(); } } 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
2
 
3
3
 
4
- var _chunkNVCI3CQIcjs = require('../../chunk-NVCI3CQI.cjs');
4
+ var _chunkC5DV4RAXcjs = require('../../chunk-C5DV4RAX.cjs');
5
+ require('../../chunk-EBPEMVZU.cjs');
5
6
 
6
7
 
7
8
 
@@ -511,7 +512,7 @@ OAuthCallbackFilter = exports.OAuthCallbackFilter = _chunk2REOCMUDcjs.__decorate
511
512
 
512
513
 
513
514
  function createOAuthController(options = {}) {
514
- const Guard = _nullishCoalesce(options.guard, () => ( _chunkNVCI3CQIcjs.JwtAuthGuard));
515
+ const Guard = _nullishCoalesce(options.guard, () => ( _chunkC5DV4RAXcjs.JwtAuthGuard));
515
516
  const userId = _nullishCoalesce(options.userId, () => ( ((user) => user.sub)));
516
517
  let OAuthControllerHost = class {
517
518
  constructor(auth) {
@@ -605,17 +606,17 @@ function createOAuthController(options = {}) {
605
606
  _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
606
607
  _common.UseGuards.call(void 0, Guard),
607
608
  _common.Get.call(void 0, "me"),
608
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkNVCI3CQIcjs.CurrentUser.call(void 0, ))
609
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkC5DV4RAXcjs.CurrentUser.call(void 0, ))
609
610
  ], OAuthControllerHost.prototype, "me", 1);
610
611
  _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
611
612
  _common.UseGuards.call(void 0, Guard),
612
613
  _common.Get.call(void 0, "linked-accounts"),
613
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkNVCI3CQIcjs.CurrentUser.call(void 0, ))
614
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkC5DV4RAXcjs.CurrentUser.call(void 0, ))
614
615
  ], OAuthControllerHost.prototype, "linkedAccounts", 1);
615
616
  _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
616
617
  _common.UseGuards.call(void 0, Guard),
617
618
  _common.Post.call(void 0, "link-intent"),
618
- _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkNVCI3CQIcjs.CurrentUser.call(void 0, )),
619
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _chunkC5DV4RAXcjs.CurrentUser.call(void 0, )),
619
620
  _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Res.call(void 0, { passthrough: true }))
620
621
  ], OAuthControllerHost.prototype, "linkIntent", 1);
621
622
  _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  CurrentUser,
3
3
  JwtAuthGuard
4
- } from "../../chunk-A3B2EY4V.js";
4
+ } from "../../chunk-MLOQDUBN.js";
5
+ import "../../chunk-KP2ZHJSR.js";
5
6
  import {
6
7
  UnauthorizedAppException,
7
8
  ValidationAppException
@@ -1,11 +1,12 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk54ZXIB5Tcjs = require('../chunk-54ZXIB5T.cjs');
4
- require('../chunk-TJHRABML.cjs');
5
- require('../chunk-J7TURDAL.cjs');
6
- require('../chunk-ZA56XBCK.cjs');
3
+ var _chunk4GT66KQScjs = require('../chunk-4GT66KQS.cjs');
4
+ require('../chunk-67B7IYAV.cjs');
5
+ require('../chunk-UWDHAZVE.cjs');
6
+ require('../chunk-Y72D5L6I.cjs');
7
+ require('../chunk-EBPEMVZU.cjs');
7
8
  require('../chunk-R7BVS6CI.cjs');
8
9
  require('../chunk-2REOCMUD.cjs');
9
10
 
10
11
 
11
- exports.applyNestKitDefaults = _chunk54ZXIB5Tcjs.applyNestKitDefaults;
12
+ exports.applyNestKitDefaults = _chunk4GT66KQScjs.applyNestKitDefaults;
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  applyNestKitDefaults
3
- } from "../chunk-AOCF5QCZ.js";
4
- import "../chunk-KDAA6GFF.js";
5
- import "../chunk-7I2Y7V52.js";
6
- import "../chunk-EBO6UKHL.js";
3
+ } from "../chunk-UIVBPNH4.js";
4
+ import "../chunk-KRC47OX6.js";
5
+ import "../chunk-DABTRWA6.js";
6
+ import "../chunk-TCAMLNUZ.js";
7
+ import "../chunk-KP2ZHJSR.js";
7
8
  import "../chunk-YFYHLYHN.js";
8
9
  import "../chunk-4MGIQFAJ.js";
9
10
  export {
@@ -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 _chunkXX5ROVSCcjs = require('./chunk-XX5ROVSC.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
+ _chunkXX5ROVSCcjs.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;
@@ -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 _chunkTJHRABMLcjs = require('./chunk-TJHRABML.cjs');
3
+ var _chunk67B7IYAVcjs = require('./chunk-67B7IYAV.cjs');
4
4
 
5
5
 
6
- var _chunkJ7TURDALcjs = require('./chunk-J7TURDAL.cjs');
6
+ var _chunkUWDHAZVEcjs = require('./chunk-UWDHAZVE.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, _chunkJ7TURDALcjs.GlobalExceptionFilter)());
21
- app.useGlobalInterceptors(new (0, _chunkTJHRABMLcjs.ResponseInterceptor)());
20
+ app.useGlobalFilters(new (0, _chunk67B7IYAVcjs.GlobalExceptionFilter)());
21
+ app.useGlobalInterceptors(new (0, _chunkUWDHAZVEcjs.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,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 _chunkZA56XBCKcjs = require('./chunk-ZA56XBCK.cjs');
3
+ var _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
4
4
 
5
5
 
6
6
  var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
@@ -28,7 +28,7 @@ var GlobalExceptionFilter = class {
28
28
  }
29
29
  const body = {
30
30
  success: false,
31
- requestId: _nullishCoalesce(_chunkZA56XBCKcjs.RequestContext.getRequestId(), () => ( "unknown")),
31
+ requestId: _nullishCoalesce(_chunkEBPEMVZUcjs.RequestContext.getRequestId(), () => ( "unknown")),
32
32
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
33
33
  error: {
34
34
  code: resolved.code,
@@ -1,5 +1,8 @@
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 _chunkEBPEMVZUcjs = require('./chunk-EBPEMVZU.cjs');
4
+
5
+
3
6
  var _chunkFDNGAYTZcjs = require('./chunk-FDNGAYTZ.cjs');
4
7
 
5
8
 
@@ -54,7 +57,9 @@ var JwtAuthGuard = class {
54
57
  if (!token) {
55
58
  throw new (0, _chunkFDNGAYTZcjs.UnauthorizedAppException)("Missing Authorization bearer token");
56
59
  }
57
- req.user = this.tokens.verifyAccessToken(token);
60
+ const user = this.tokens.verifyAccessToken(token);
61
+ req.user = user;
62
+ _chunkEBPEMVZUcjs.RequestContext.setActor({ id: user.sub, tenantId: user.tenantId, roles: user.roles });
58
63
  return true;
59
64
  }
60
65
  };
@@ -1,6 +1,9 @@
1
+ import {
2
+ isPaginated
3
+ } from "./chunk-TCAMLNUZ.js";
1
4
  import {
2
5
  RequestContext
3
- } from "./chunk-EBO6UKHL.js";
6
+ } from "./chunk-KP2ZHJSR.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
- success: true,
16
- data,
17
- requestId: RequestContext.getRequestId() ?? "unknown",
18
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
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
  };
@@ -13,6 +13,21 @@ 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
+ }
16
31
  };
17
32
 
18
33
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RequestContext
3
- } from "./chunk-EBO6UKHL.js";
3
+ } from "./chunk-KP2ZHJSR.js";
4
4
  import {
5
5
  __decorateClass
6
6
  } from "./chunk-4MGIQFAJ.js";
@@ -0,0 +1,35 @@
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
+ };
32
+
33
+ export {
34
+ RequestContext
35
+ };