@miguelmorales13/nestkit 0.1.0 → 0.3.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 (76) hide show
  1. package/README.md +305 -1
  2. package/dist/auth/auth-user.entity.d.ts +8 -0
  3. package/dist/auth/auth-user.port.d.ts +16 -0
  4. package/dist/auth/auth.controller.d.ts +25 -0
  5. package/dist/auth/auth.dto.d.ts +13 -0
  6. package/dist/auth/auth.service.d.ts +24 -0
  7. package/dist/auth/authenticated-user.d.ts +7 -0
  8. package/dist/auth/current-tenant.decorator.d.ts +2 -0
  9. package/dist/auth/current-user.decorator.d.ts +1 -0
  10. package/dist/auth/hash.util.d.ts +2 -0
  11. package/dist/auth/index.cjs +265 -0
  12. package/dist/auth/index.d.ts +16 -0
  13. package/dist/auth/index.js +265 -0
  14. package/dist/auth/jwt-auth.guard.d.ts +5 -0
  15. package/dist/auth/require-tenant.guard.d.ts +9 -0
  16. package/dist/auth/roles.decorator.d.ts +3 -0
  17. package/dist/auth/roles.guard.d.ts +11 -0
  18. package/dist/auth/token.service.d.ts +7 -0
  19. package/dist/bootstrap/index.cjs +11 -0
  20. package/dist/bootstrap/index.js +3 -2
  21. package/dist/chunk-2REOCMUD.cjs +16 -0
  22. package/dist/chunk-3CLYZC3T.cjs +104 -0
  23. package/dist/chunk-7FQQDWOZ.cjs +73 -0
  24. package/dist/chunk-7SOM7EZP.cjs +1 -0
  25. package/dist/chunk-DQYAIQQ5.js +0 -0
  26. package/dist/chunk-FDNGAYTZ.cjs +39 -0
  27. package/dist/chunk-KVBQBT3D.cjs +1 -0
  28. package/dist/chunk-M3EL5O6T.cjs +36 -0
  29. package/dist/chunk-MR2IFCZE.cjs +1 -0
  30. package/dist/chunk-O2ZMI3EK.cjs +32 -0
  31. package/dist/{chunk-HGJX2GPE.js → chunk-ORWJ7LES.js} +1 -1
  32. package/dist/{chunk-EQXYK6AL.js → chunk-Q45IEPWU.js} +5 -13
  33. package/dist/chunk-QS2W5XCQ.cjs +12 -0
  34. package/dist/chunk-R7BVS6CI.cjs +13 -0
  35. package/dist/chunk-RF75KC63.cjs +50 -0
  36. package/dist/{chunk-KP7GRCZW.js → chunk-RHNQGTAT.js} +3 -3
  37. package/dist/chunk-SPTDXUED.cjs +39 -0
  38. package/dist/chunk-TJHRABML.cjs +29 -0
  39. package/dist/chunk-V2M75FN3.cjs +40 -0
  40. package/dist/chunk-YFYHLYHN.js +13 -0
  41. package/dist/chunk-ZA56XBCK.cjs +20 -0
  42. package/dist/crud/index.cjs +9 -0
  43. package/dist/database/mongo/index.cjs +1 -0
  44. package/dist/database/postgres/index.cjs +11 -0
  45. package/dist/database/supabase/index.cjs +11 -0
  46. package/dist/email/nodemailer/index.cjs +40 -0
  47. package/dist/email/nodemailer/index.d.ts +1 -0
  48. package/dist/email/nodemailer/index.js +40 -0
  49. package/dist/email/nodemailer/nodemailer.module.d.ts +4 -0
  50. package/dist/email/resend/index.cjs +31 -0
  51. package/dist/email/resend/index.d.ts +1 -0
  52. package/dist/email/resend/index.js +31 -0
  53. package/dist/email/resend/resend.module.d.ts +4 -0
  54. package/dist/entities/index.cjs +7 -0
  55. package/dist/errors/index.cjs +25 -0
  56. package/dist/errors/index.js +6 -3
  57. package/dist/i18n/index.cjs +9 -0
  58. package/dist/index.cjs +78 -0
  59. package/dist/index.js +26 -23
  60. package/dist/response/index.cjs +9 -0
  61. package/dist/stripe/index.cjs +78 -0
  62. package/dist/stripe/index.d.ts +3 -0
  63. package/dist/stripe/index.js +78 -0
  64. package/dist/stripe/stripe-webhook.controller.d.ts +20 -0
  65. package/dist/stripe/stripe.module.d.ts +4 -0
  66. package/dist/telegram/index.cjs +31 -0
  67. package/dist/telegram/index.d.ts +1 -0
  68. package/dist/telegram/index.js +31 -0
  69. package/dist/telegram/telegram.module.d.ts +8 -0
  70. package/dist/tracking/index.cjs +15 -0
  71. package/dist/whatsapp/index.cjs +68 -0
  72. package/dist/whatsapp/index.d.ts +3 -0
  73. package/dist/whatsapp/index.js +68 -0
  74. package/dist/whatsapp/whatsapp-client.d.ts +21 -0
  75. package/dist/whatsapp/whatsapp.module.d.ts +4 -0
  76. package/package.json +96 -21
@@ -0,0 +1,104 @@
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 _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
5
+
6
+ // src/crud/crud.service.ts
7
+ var BaseCrudService = class {
8
+ constructor(repository, options = {}) {
9
+ this.repository = repository;
10
+ this.options = options;
11
+ }
12
+ findById(id, tenantId) {
13
+ return this.repository.findById(id, tenantId);
14
+ }
15
+ findAll(filter, tenantId) {
16
+ return this.repository.findAll(filter, tenantId);
17
+ }
18
+ create(data, tenantId) {
19
+ return this.repository.create(data, tenantId);
20
+ }
21
+ update(id, data, tenantId) {
22
+ return this.repository.update(id, data, tenantId);
23
+ }
24
+ async delete(id, tenantId) {
25
+ if (this.options.deleteStrategy === "soft") {
26
+ await this.repository.update(id, { deletedAt: /* @__PURE__ */ new Date() }, tenantId);
27
+ return;
28
+ }
29
+ await this.repository.delete(id, tenantId);
30
+ }
31
+ };
32
+
33
+ // src/crud/crud.controller.ts
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+ var _common = require('@nestjs/common');
46
+ function createCrudController(serviceToken, options = {}) {
47
+ const tenantIdOf = (req) => _optionalChain([options, 'access', _ => _.tenantIdExtractor, 'optionalCall', _2 => _2(req)]);
48
+ let CrudControllerHost = class {
49
+ constructor(service) {
50
+ this.service = service;
51
+ }
52
+ findAll(filter, req) {
53
+ return this.service.findAll(filter, tenantIdOf(req));
54
+ }
55
+ findById(id, req) {
56
+ return this.service.findById(id, tenantIdOf(req));
57
+ }
58
+ create(data, req) {
59
+ return this.service.create(data, tenantIdOf(req));
60
+ }
61
+ update(id, data, req) {
62
+ return this.service.update(id, data, tenantIdOf(req));
63
+ }
64
+ remove(id, req) {
65
+ return this.service.delete(id, tenantIdOf(req));
66
+ }
67
+ };
68
+ _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
69
+ _common.Get.call(void 0, ),
70
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Query.call(void 0, )),
71
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
72
+ ], CrudControllerHost.prototype, "findAll", 1);
73
+ _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
74
+ _common.Get.call(void 0, ":id"),
75
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
76
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
77
+ ], CrudControllerHost.prototype, "findById", 1);
78
+ _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
79
+ _common.Post.call(void 0, ),
80
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Body.call(void 0, )),
81
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
82
+ ], CrudControllerHost.prototype, "create", 1);
83
+ _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
84
+ _common.Patch.call(void 0, ":id"),
85
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
86
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Body.call(void 0, )),
87
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 2, _common.Req.call(void 0, ))
88
+ ], CrudControllerHost.prototype, "update", 1);
89
+ _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
90
+ _common.Delete.call(void 0, ":id"),
91
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
92
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 1, _common.Req.call(void 0, ))
93
+ ], CrudControllerHost.prototype, "remove", 1);
94
+ CrudControllerHost = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
95
+ _common.Controller.call(void 0, _nullishCoalesce(options.path, () => ( ""))),
96
+ _chunk2REOCMUDcjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, serviceToken))
97
+ ], CrudControllerHost);
98
+ return CrudControllerHost;
99
+ }
100
+
101
+
102
+
103
+
104
+ exports.BaseCrudService = BaseCrudService; exports.createCrudController = createCrudController;
@@ -0,0 +1,73 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
4
+
5
+
6
+ var _chunkZA56XBCKcjs = require('./chunk-ZA56XBCK.cjs');
7
+
8
+
9
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
10
+
11
+ // src/errors/global-exception.filter.ts
12
+
13
+
14
+
15
+
16
+
17
+ var _common = require('@nestjs/common');
18
+ var GlobalExceptionFilter = class {
19
+ constructor() {
20
+ this.logger = new (0, _common.Logger)(GlobalExceptionFilter.name);
21
+ }
22
+ catch(exception, host) {
23
+ const response = host.switchToHttp().getResponse();
24
+ const resolved = this.resolve(exception);
25
+ if (resolved.status >= _common.HttpStatus.INTERNAL_SERVER_ERROR) {
26
+ const stack = exception instanceof Error ? exception.stack : void 0;
27
+ this.logger.error(`Unhandled exception: ${resolved.message}`, stack);
28
+ }
29
+ const body = {
30
+ success: false,
31
+ requestId: _nullishCoalesce(_chunkZA56XBCKcjs.RequestContext.getRequestId(), () => ( "unknown")),
32
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
33
+ error: {
34
+ code: resolved.code,
35
+ message: resolved.message,
36
+ details: resolved.details
37
+ }
38
+ };
39
+ response.status(resolved.status).send(body);
40
+ }
41
+ resolve(exception) {
42
+ if (exception instanceof _chunkR7BVS6CIcjs.AppException) {
43
+ return {
44
+ status: exception.getStatus(),
45
+ code: exception.code,
46
+ message: exception.message,
47
+ details: exception.details
48
+ };
49
+ }
50
+ if (exception instanceof _common.HttpException) {
51
+ const status = exception.getStatus();
52
+ const payload = exception.getResponse();
53
+ const rawMessage = typeof payload === "string" ? payload : _nullishCoalesce(payload.message, () => ( exception.message));
54
+ return {
55
+ status,
56
+ code: _nullishCoalesce(_common.HttpStatus[status], () => ( "HTTP_ERROR")),
57
+ message: Array.isArray(rawMessage) ? rawMessage.join(", ") : rawMessage
58
+ };
59
+ }
60
+ return {
61
+ status: _common.HttpStatus.INTERNAL_SERVER_ERROR,
62
+ code: "INTERNAL_ERROR",
63
+ message: "Internal server error"
64
+ };
65
+ }
66
+ };
67
+ GlobalExceptionFilter = exports.GlobalExceptionFilter = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
68
+ _common.Catch.call(void 0, )
69
+ ], GlobalExceptionFilter);
70
+
71
+
72
+
73
+ exports.GlobalExceptionFilter = GlobalExceptionFilter;
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1,39 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkR7BVS6CIcjs = require('./chunk-R7BVS6CI.cjs');
4
+
5
+ // src/errors/common.exceptions.ts
6
+ var _common = require('@nestjs/common');
7
+ var NotFoundAppException = class extends _chunkR7BVS6CIcjs.AppException {
8
+ constructor(message = "Resource not found", details, code = "NOT_FOUND") {
9
+ super(code, message, _common.HttpStatus.NOT_FOUND, details);
10
+ }
11
+ };
12
+ var ConflictAppException = class extends _chunkR7BVS6CIcjs.AppException {
13
+ constructor(message = "Conflict", details, code = "CONFLICT") {
14
+ super(code, message, _common.HttpStatus.CONFLICT, details);
15
+ }
16
+ };
17
+ var ValidationAppException = class extends _chunkR7BVS6CIcjs.AppException {
18
+ constructor(message = "Validation failed", details, code = "VALIDATION_ERROR") {
19
+ super(code, message, _common.HttpStatus.BAD_REQUEST, details);
20
+ }
21
+ };
22
+ var UnauthorizedAppException = class extends _chunkR7BVS6CIcjs.AppException {
23
+ constructor(message = "Unauthorized", details, code = "UNAUTHORIZED") {
24
+ super(code, message, _common.HttpStatus.UNAUTHORIZED, details);
25
+ }
26
+ };
27
+ var ForbiddenAppException = class extends _chunkR7BVS6CIcjs.AppException {
28
+ constructor(message = "Forbidden", details, code = "FORBIDDEN") {
29
+ super(code, message, _common.HttpStatus.FORBIDDEN, details);
30
+ }
31
+ };
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+ exports.NotFoundAppException = NotFoundAppException; exports.ConflictAppException = ConflictAppException; exports.ValidationAppException = ValidationAppException; exports.UnauthorizedAppException = UnauthorizedAppException; exports.ForbiddenAppException = ForbiddenAppException;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,36 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
4
+
5
+ // src/i18n/i18n.module.ts
6
+ var _common = require('@nestjs/common');
7
+ var _nestjsi18n = require('nestjs-i18n');
8
+ var I18nModule = class {
9
+ static forRoot(options = {}) {
10
+ return _nestjsi18n.I18nModule.forRoot({
11
+ fallbackLanguage: _nullishCoalesce(options.fallbackLanguage, () => ( "es")),
12
+ loaderOptions: {
13
+ path: _nullishCoalesce(options.path, () => ( "./i18n/")),
14
+ watch: true
15
+ },
16
+ loader: _nestjsi18n.I18nJsonLoader
17
+ });
18
+ }
19
+ };
20
+ I18nModule = exports.I18nModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
21
+ _common.Module.call(void 0, {})
22
+ ], I18nModule);
23
+
24
+ // src/i18n/translate.helper.ts
25
+ function translateOr(i18n, key, fallback, args) {
26
+ try {
27
+ return i18n.t(key, { args, defaultValue: fallback });
28
+ } catch (e) {
29
+ return fallback;
30
+ }
31
+ }
32
+
33
+
34
+
35
+
36
+ exports.I18nModule = I18nModule; exports.translateOr = translateOr;
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,32 @@
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
+
3
+ var _chunk7FQQDWOZcjs = require('./chunk-7FQQDWOZ.cjs');
4
+
5
+
6
+ var _chunkTJHRABMLcjs = require('./chunk-TJHRABML.cjs');
7
+
8
+ // src/bootstrap/apply-defaults.ts
9
+
10
+
11
+ var _common = require('@nestjs/common');
12
+ var _swagger = require('@nestjs/swagger');
13
+ var _helmet = require('helmet'); var _helmet2 = _interopRequireDefault(_helmet);
14
+ function applyNestKitDefaults(app, options = {}) {
15
+ app.use(_helmet2.default.call(void 0, ));
16
+ app.enableCors(_nullishCoalesce(options.cors, () => ( { origin: _nullishCoalesce(_optionalChain([process, 'access', _ => _.env, 'access', _2 => _2.CORS_ORIGIN, 'optionalAccess', _3 => _3.split, 'call', _4 => _4(",")]), () => ( true)) })));
17
+ app.useGlobalPipes(
18
+ new (0, _common.ValidationPipe)({ whitelist: true, transform: true, ...options.validation })
19
+ );
20
+ app.useGlobalFilters(new (0, _chunk7FQQDWOZcjs.GlobalExceptionFilter)());
21
+ app.useGlobalInterceptors(new (0, _chunkTJHRABMLcjs.ResponseInterceptor)());
22
+ if (options.swagger !== false) {
23
+ const swaggerOptions = _nullishCoalesce(options.swagger, () => ( { title: "API" }));
24
+ const config = new (0, _swagger.DocumentBuilder)().setTitle(swaggerOptions.title).build();
25
+ const document = _swagger.SwaggerModule.createDocument(app, config);
26
+ _swagger.SwaggerModule.setup(_nullishCoalesce(swaggerOptions.path, () => ( "docs")), app, document);
27
+ }
28
+ }
29
+
30
+
31
+
32
+ exports.applyNestKitDefaults = applyNestKitDefaults;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  AppException
3
- } from "./chunk-EQXYK6AL.js";
3
+ } from "./chunk-YFYHLYHN.js";
4
4
 
5
5
  // src/errors/common.exceptions.ts
6
6
  import { HttpStatus } from "@nestjs/common";
@@ -1,3 +1,6 @@
1
+ import {
2
+ AppException
3
+ } from "./chunk-YFYHLYHN.js";
1
4
  import {
2
5
  RequestContext
3
6
  } from "./chunk-EBO6UKHL.js";
@@ -5,20 +8,10 @@ import {
5
8
  __decorateClass
6
9
  } from "./chunk-4MGIQFAJ.js";
7
10
 
8
- // src/errors/app.exception.ts
9
- import { HttpException } from "@nestjs/common";
10
- var AppException = class extends HttpException {
11
- constructor(code, message, status, details) {
12
- super({ code, message, details }, status);
13
- this.code = code;
14
- this.details = details;
15
- }
16
- };
17
-
18
11
  // src/errors/global-exception.filter.ts
19
12
  import {
20
13
  Catch,
21
- HttpException as HttpException2,
14
+ HttpException,
22
15
  HttpStatus,
23
16
  Logger
24
17
  } from "@nestjs/common";
@@ -54,7 +47,7 @@ var GlobalExceptionFilter = class {
54
47
  details: exception.details
55
48
  };
56
49
  }
57
- if (exception instanceof HttpException2) {
50
+ if (exception instanceof HttpException) {
58
51
  const status = exception.getStatus();
59
52
  const payload = exception.getResponse();
60
53
  const rawMessage = typeof payload === "string" ? payload : payload.message ?? exception.message;
@@ -76,6 +69,5 @@ GlobalExceptionFilter = __decorateClass([
76
69
  ], GlobalExceptionFilter);
77
70
 
78
71
  export {
79
- AppException,
80
72
  GlobalExceptionFilter
81
73
  };
@@ -0,0 +1,12 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/entities/base-response.dto.ts
2
+ var BaseResponseDto = class {
3
+ static fromEntity(entity) {
4
+ const dto = new this();
5
+ Object.assign(dto, entity);
6
+ return dto;
7
+ }
8
+ };
9
+
10
+
11
+
12
+ exports.BaseResponseDto = BaseResponseDto;
@@ -0,0 +1,13 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/errors/app.exception.ts
2
+ var _common = require('@nestjs/common');
3
+ var AppException = class extends _common.HttpException {
4
+ constructor(code, message, status, details) {
5
+ super({ code, message, details }, status);
6
+ this.code = code;
7
+ this.details = details;
8
+ }
9
+ };
10
+
11
+
12
+
13
+ exports.AppException = AppException;
@@ -0,0 +1,50 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
4
+
5
+ // src/database/postgres/postgres.module.ts
6
+ var _common = require('@nestjs/common');
7
+ var _pg = require('pg');
8
+ var PG_POOL = /* @__PURE__ */ Symbol("PG_POOL");
9
+ var PgModule = class {
10
+ };
11
+ PgModule = exports.PgModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
12
+ _common.Module.call(void 0, {
13
+ providers: [
14
+ {
15
+ provide: PG_POOL,
16
+ useFactory: () => {
17
+ const connectionString = process.env.DATABASE_URL;
18
+ if (!connectionString) {
19
+ throw new Error("PgModule: DATABASE_URL environment variable is not set");
20
+ }
21
+ return new (0, _pg.Pool)({ connectionString });
22
+ }
23
+ }
24
+ ],
25
+ exports: [PG_POOL]
26
+ })
27
+ ], PgModule);
28
+
29
+ // src/database/postgres/tenant-scope.ts
30
+ async function withTenantScope(pool, authUserId, fn) {
31
+ const client = await pool.connect();
32
+ try {
33
+ await client.query("BEGIN");
34
+ await client.query("SELECT set_config('request.jwt.claim.sub', $1, true)", [authUserId]);
35
+ const result = await fn(client);
36
+ await client.query("COMMIT");
37
+ return result;
38
+ } catch (error) {
39
+ await client.query("ROLLBACK");
40
+ throw error;
41
+ } finally {
42
+ client.release();
43
+ }
44
+ }
45
+
46
+
47
+
48
+
49
+
50
+ exports.PG_POOL = PG_POOL; exports.PgModule = PgModule; exports.withTenantScope = withTenantScope;
@@ -1,9 +1,9 @@
1
+ import {
2
+ GlobalExceptionFilter
3
+ } from "./chunk-Q45IEPWU.js";
1
4
  import {
2
5
  ResponseInterceptor
3
6
  } from "./chunk-KDAA6GFF.js";
4
- import {
5
- GlobalExceptionFilter
6
- } from "./chunk-EQXYK6AL.js";
7
7
 
8
8
  // src/bootstrap/apply-defaults.ts
9
9
  import {
@@ -0,0 +1,39 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
4
+
5
+ // src/database/supabase/supabase.module.ts
6
+ var _common = require('@nestjs/common');
7
+ var _supabasejs = require('@supabase/supabase-js');
8
+ var SUPABASE_ANON_CLIENT = /* @__PURE__ */ Symbol("SUPABASE_ANON_CLIENT");
9
+ var SUPABASE_SERVICE_ROLE_CLIENT = /* @__PURE__ */ Symbol("SUPABASE_SERVICE_ROLE_CLIENT");
10
+ function requireEnv(name) {
11
+ const value = process.env[name];
12
+ if (!value) {
13
+ throw new Error(`SupabaseModule: ${name} environment variable is not set`);
14
+ }
15
+ return value;
16
+ }
17
+ var SupabaseModule = class {
18
+ };
19
+ SupabaseModule = exports.SupabaseModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
20
+ _common.Module.call(void 0, {
21
+ providers: [
22
+ {
23
+ provide: SUPABASE_ANON_CLIENT,
24
+ useFactory: () => _supabasejs.createClient.call(void 0, requireEnv("SUPABASE_URL"), requireEnv("SUPABASE_ANON_KEY"))
25
+ },
26
+ {
27
+ provide: SUPABASE_SERVICE_ROLE_CLIENT,
28
+ useFactory: () => _supabasejs.createClient.call(void 0, requireEnv("SUPABASE_URL"), requireEnv("SUPABASE_SERVICE_ROLE_KEY"))
29
+ }
30
+ ],
31
+ exports: [SUPABASE_ANON_CLIENT, SUPABASE_SERVICE_ROLE_CLIENT]
32
+ })
33
+ ], SupabaseModule);
34
+
35
+
36
+
37
+
38
+
39
+ exports.SUPABASE_ANON_CLIENT = SUPABASE_ANON_CLIENT; exports.SUPABASE_SERVICE_ROLE_CLIENT = SUPABASE_SERVICE_ROLE_CLIENT; exports.SupabaseModule = SupabaseModule;
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkZA56XBCKcjs = require('./chunk-ZA56XBCK.cjs');
4
+
5
+
6
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
7
+
8
+ // src/response/response.interceptor.ts
9
+ var _common = require('@nestjs/common');
10
+ var _operators = require('rxjs/operators');
11
+ var ResponseInterceptor = class {
12
+ intercept(_context, next) {
13
+ return next.handle().pipe(
14
+ _operators.map.call(void 0, (data) => ({
15
+ success: true,
16
+ data,
17
+ requestId: _nullishCoalesce(_chunkZA56XBCKcjs.RequestContext.getRequestId(), () => ( "unknown")),
18
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
19
+ }))
20
+ );
21
+ }
22
+ };
23
+ ResponseInterceptor = exports.ResponseInterceptor = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
24
+ _common.Injectable.call(void 0, )
25
+ ], ResponseInterceptor);
26
+
27
+
28
+
29
+ exports.ResponseInterceptor = ResponseInterceptor;
@@ -0,0 +1,40 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunkZA56XBCKcjs = require('./chunk-ZA56XBCK.cjs');
4
+
5
+
6
+ var _chunk2REOCMUDcjs = require('./chunk-2REOCMUD.cjs');
7
+
8
+ // src/tracking/request-id.middleware.ts
9
+ var _crypto = require('crypto');
10
+ var _common = require('@nestjs/common');
11
+ var REQUEST_ID_HEADER = "x-request-id";
12
+ var RequestIdMiddleware = class {
13
+ use(req, res, next) {
14
+ const incoming = req.headers[REQUEST_ID_HEADER];
15
+ const requestId = _nullishCoalesce((Array.isArray(incoming) ? incoming[0] : incoming), () => ( _crypto.randomUUID.call(void 0, )));
16
+ req.requestId = requestId;
17
+ res.setHeader(REQUEST_ID_HEADER, requestId);
18
+ _chunkZA56XBCKcjs.RequestContext.run({ requestId }, () => next());
19
+ }
20
+ };
21
+ RequestIdMiddleware = exports.RequestIdMiddleware = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
22
+ _common.Injectable.call(void 0, )
23
+ ], RequestIdMiddleware);
24
+
25
+ // src/tracking/tracking.module.ts
26
+
27
+ var TrackingModule = class {
28
+ configure(consumer) {
29
+ consumer.apply(RequestIdMiddleware).forRoutes("*");
30
+ }
31
+ };
32
+ TrackingModule = exports.TrackingModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0, [
33
+ _common.Module.call(void 0, {})
34
+ ], TrackingModule);
35
+
36
+
37
+
38
+
39
+
40
+ exports.REQUEST_ID_HEADER = REQUEST_ID_HEADER; exports.RequestIdMiddleware = RequestIdMiddleware; exports.TrackingModule = TrackingModule;
@@ -0,0 +1,13 @@
1
+ // src/errors/app.exception.ts
2
+ import { HttpException } from "@nestjs/common";
3
+ var AppException = class extends HttpException {
4
+ constructor(code, message, status, details) {
5
+ super({ code, message, details }, status);
6
+ this.code = code;
7
+ this.details = details;
8
+ }
9
+ };
10
+
11
+ export {
12
+ AppException
13
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; }// src/tracking/request-context.ts
2
+ var _async_hooks = require('async_hooks');
3
+ var RequestContext = class {
4
+ static {
5
+ this.storage = new (0, _async_hooks.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 _optionalChain([this, 'access', _ => _.storage, 'access', _2 => _2.getStore, 'call', _3 => _3(), 'optionalAccess', _4 => _4.requestId]);
15
+ }
16
+ };
17
+
18
+
19
+
20
+ exports.RequestContext = RequestContext;
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunk3CLYZC3Tcjs = require('../chunk-3CLYZC3T.cjs');
5
+ require('../chunk-2REOCMUD.cjs');
6
+
7
+
8
+
9
+ exports.BaseCrudService = _chunk3CLYZC3Tcjs.BaseCrudService; exports.createCrudController = _chunk3CLYZC3Tcjs.createCrudController;
@@ -0,0 +1 @@
1
+ "use strict";require('../../chunk-KVBQBT3D.cjs');
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkRF75KC63cjs = require('../../chunk-RF75KC63.cjs');
6
+ require('../../chunk-2REOCMUD.cjs');
7
+
8
+
9
+
10
+
11
+ exports.PG_POOL = _chunkRF75KC63cjs.PG_POOL; exports.PgModule = _chunkRF75KC63cjs.PgModule; exports.withTenantScope = _chunkRF75KC63cjs.withTenantScope;
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkSPTDXUEDcjs = require('../../chunk-SPTDXUED.cjs');
6
+ require('../../chunk-2REOCMUD.cjs');
7
+
8
+
9
+
10
+
11
+ exports.SUPABASE_ANON_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_ANON_CLIENT; exports.SUPABASE_SERVICE_ROLE_CLIENT = _chunkSPTDXUEDcjs.SUPABASE_SERVICE_ROLE_CLIENT; exports.SupabaseModule = _chunkSPTDXUEDcjs.SupabaseModule;