@miguelmorales13/nestkit 0.26.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -0
- package/dist/alerts/alert-on-failure.decorator.d.ts +5 -0
- package/dist/alerts/alert-sinks.d.ts +29 -0
- package/dist/alerts/alerts.module.d.ts +19 -0
- package/dist/alerts/alerts.options.d.ts +1 -0
- package/dist/alerts/alerts.service.d.ts +28 -0
- package/dist/alerts/alerts.types.d.ts +66 -0
- package/dist/alerts/index.cjs +276 -0
- package/dist/alerts/index.d.ts +10 -0
- package/dist/alerts/index.js +276 -0
- package/dist/alerts/logger-with-alerts.d.ts +18 -0
- package/dist/alerts/process-guards.d.ts +21 -0
- package/dist/alerts/runtime.d.ts +4 -0
- package/dist/audit/index.cjs +13 -13
- package/dist/audit/index.js +2 -2
- package/dist/auth/index.cjs +21 -21
- package/dist/auth/index.js +3 -3
- package/dist/auth/oauth/index.cjs +101 -101
- package/dist/auth/oauth/index.js +3 -3
- package/dist/bootstrap/apply-defaults.d.ts +9 -0
- package/dist/bootstrap/index.cjs +7 -6
- package/dist/bootstrap/index.js +6 -5
- package/dist/chunk-33KFVAUZ.cjs +151 -0
- package/dist/chunk-3TUMVLPJ.js +14 -0
- package/dist/{chunk-PA24P76K.js → chunk-45SW7FBE.js} +1 -1
- package/dist/{chunk-RF75KC63.cjs → chunk-47IYXZHW.cjs} +2 -2
- package/dist/{chunk-TUNDBBQF.js → chunk-4WWOKZIO.js} +4 -4
- package/dist/{chunk-2DUEQKOI.js → chunk-5LVGCTJ3.js} +4 -4
- package/dist/chunk-A6YGIZCQ.cjs +14 -0
- package/dist/chunk-A7FI6HXV.js +40 -0
- package/dist/chunk-CU4FUIVJ.cjs +8 -0
- package/dist/{chunk-FH5UNWWW.cjs → chunk-D35TBVRO.cjs} +4 -4
- package/dist/{chunk-4MGIQFAJ.js → chunk-D3DDJWUD.js} +5 -0
- package/dist/chunk-DVGPEBUL.js +8 -0
- package/dist/{chunk-VKOPDDCC.js → chunk-ENZ7LQRE.js} +1 -1
- package/dist/{chunk-3AUOOEQO.cjs → chunk-F77X4QUN.cjs} +2 -2
- package/dist/chunk-FBNV5X6C.js +61 -0
- package/dist/{chunk-APUFKA4K.cjs → chunk-FDZQCLLK.cjs} +6 -6
- package/dist/{chunk-DYHSOULW.js → chunk-IGSNB5BX.js} +1 -1
- package/dist/chunk-IVWPA6QH.cjs +90 -0
- package/dist/{chunk-LSDY6ETG.cjs → chunk-JJKGQNGD.cjs} +5 -5
- package/dist/{chunk-ALIKVFOV.cjs → chunk-JRFE7NSO.cjs} +12 -4
- package/dist/{chunk-HVHYZXBB.cjs → chunk-KNU5RN3O.cjs} +3 -3
- package/dist/{chunk-52IOOHNX.cjs → chunk-KQPJCVN3.cjs} +26 -26
- package/dist/chunk-LGFHLAY3.cjs +61 -0
- package/dist/{chunk-2REOCMUD.cjs → chunk-LRX7AMSS.cjs} +6 -1
- package/dist/chunk-LU3HO7B3.js +151 -0
- package/dist/{chunk-4PFAKLT3.js → chunk-MUWHGBIB.js} +1 -1
- package/dist/{chunk-ZJMLEP5H.js → chunk-NJYLQDB3.js} +1 -1
- package/dist/{chunk-IFNYRZP2.js → chunk-OSRH6KYZ.js} +4 -4
- package/dist/{chunk-6RAPVLJM.js → chunk-OTE77ONL.js} +1 -1
- package/dist/chunk-UDACUMLO.cjs +40 -0
- package/dist/{chunk-PFHHLB7B.js → chunk-UGAAJRPO.js} +10 -2
- package/dist/{chunk-SPTDXUED.cjs → chunk-URLDTS2Q.cjs} +2 -2
- package/dist/{chunk-W2T2VFLC.cjs → chunk-VALDHJOO.cjs} +5 -5
- package/dist/chunk-WFCQDOSN.js +90 -0
- package/dist/consent/consent.interceptor.d.ts +20 -0
- package/dist/consent/consent.module.d.ts +25 -0
- package/dist/consent/consent.options.d.ts +30 -0
- package/dist/consent/consent.port.d.ts +17 -0
- package/dist/consent/consent.service.d.ts +44 -0
- package/dist/consent/guard/index.cjs +13 -0
- package/dist/consent/guard/index.d.ts +31 -0
- package/dist/consent/guard/index.js +13 -0
- package/dist/consent/index.cjs +271 -0
- package/dist/consent/index.d.ts +13 -0
- package/dist/consent/index.js +271 -0
- package/dist/consent/memory.store.d.ts +7 -0
- package/dist/consent/shared/index.cjs +11 -0
- package/dist/consent/shared/index.d.ts +19 -0
- package/dist/consent/shared/index.js +11 -0
- package/dist/consent/typeorm.store.d.ts +22 -0
- package/dist/crud/index.cjs +4 -4
- package/dist/crud/index.js +3 -3
- package/dist/database/postgres/index.cjs +3 -3
- package/dist/database/postgres/index.js +2 -2
- package/dist/database/supabase/index.cjs +3 -3
- package/dist/database/supabase/index.js +2 -2
- package/dist/database/typeorm/index.cjs +2 -2
- package/dist/database/typeorm/index.js +1 -1
- package/dist/devices/device-check.interceptor.d.ts +20 -0
- package/dist/devices/devices.module.d.ts +28 -0
- package/dist/devices/devices.options.d.ts +53 -0
- package/dist/devices/devices.port.d.ts +62 -0
- package/dist/devices/devices.service.d.ts +58 -0
- package/dist/devices/index.cjs +327 -0
- package/dist/devices/index.d.ts +8 -0
- package/dist/devices/index.js +327 -0
- package/dist/devices/memory.store.d.ts +12 -0
- package/dist/email/index.cjs +2 -2
- package/dist/email/index.js +1 -1
- package/dist/email/nodemailer/index.cjs +2 -2
- package/dist/email/nodemailer/index.js +1 -1
- package/dist/email/resend/index.cjs +2 -2
- package/dist/email/resend/index.js +1 -1
- package/dist/entities/index.cjs +1 -1
- package/dist/entities/index.js +1 -1
- package/dist/errors/index.cjs +7 -7
- package/dist/errors/index.js +7 -7
- package/dist/events/buses.d.ts +27 -0
- package/dist/events/events.controller.d.ts +15 -0
- package/dist/events/events.module.d.ts +29 -0
- package/dist/events/events.options.d.ts +50 -0
- package/dist/events/events.service.d.ts +49 -0
- package/dist/events/events.types.d.ts +77 -0
- package/dist/events/index.cjs +557 -0
- package/dist/events/index.d.ts +10 -0
- package/dist/events/index.js +557 -0
- package/dist/events/memory-ticket.store.d.ts +9 -0
- package/dist/google-business/google-business-http.d.ts +41 -0
- package/dist/google-business/google-business.errors.d.ts +75 -0
- package/dist/google-business/google-business.mappers.d.ts +52 -0
- package/dist/google-business/google-business.module.d.ts +26 -0
- package/dist/google-business/google-business.options.d.ts +40 -0
- package/dist/google-business/google-business.ports.d.ts +18 -0
- package/dist/google-business/google-business.service.d.ts +120 -0
- package/dist/google-business/google-business.types.d.ts +155 -0
- package/dist/google-business/index.cjs +1025 -0
- package/dist/google-business/index.d.ts +15 -0
- package/dist/google-business/index.js +1025 -0
- package/dist/google-business/testing/google-simulator.d.ts +61 -0
- package/dist/hardening/body-limits.d.ts +24 -0
- package/dist/hardening/http.types.d.ts +26 -0
- package/dist/hardening/index.cjs +179 -0
- package/dist/hardening/index.d.ts +19 -0
- package/dist/hardening/index.js +179 -0
- package/dist/hardening/memory-rate-limit.store.d.ts +10 -0
- package/dist/hardening/origin-secret.d.ts +29 -0
- package/dist/hardening/rate-limit.decorator.d.ts +8 -0
- package/dist/hardening/rate-limit.guard.d.ts +18 -0
- package/dist/hardening/rate-limit.module.d.ts +23 -0
- package/dist/hardening/rate-limit.options.d.ts +35 -0
- package/dist/hardening/rate-limit.port.d.ts +11 -0
- package/dist/hardening/redis-rate-limit.store.d.ts +23 -0
- package/dist/hardening/trust-proxy.d.ts +22 -0
- package/dist/health/health.controller.d.ts +32 -0
- package/dist/health/health.module.d.ts +15 -0
- package/dist/health/health.options.d.ts +24 -0
- package/dist/health/index.cjs +103 -0
- package/dist/health/index.d.ts +5 -0
- package/dist/health/index.js +103 -0
- package/dist/i18n/index.cjs +3 -3
- package/dist/i18n/index.js +2 -2
- package/dist/idempotency/idempotency.interceptor.d.ts +1 -0
- package/dist/idempotency/idempotency.options.d.ts +15 -0
- package/dist/idempotency/index.cjs +214 -7
- package/dist/idempotency/index.d.ts +5 -0
- package/dist/idempotency/index.js +210 -3
- package/dist/idempotency/no-idempotency.decorator.d.ts +8 -0
- package/dist/idempotency/postgres.store.d.ts +49 -0
- package/dist/idempotency/redis.store.d.ts +59 -0
- package/dist/index.cjs +21 -20
- package/dist/index.js +33 -32
- package/dist/invoicing/index.cjs +2 -2
- package/dist/invoicing/index.js +1 -1
- package/dist/jobs/defer-job.d.ts +10 -0
- package/dist/jobs/index.cjs +318 -0
- package/dist/jobs/index.d.ts +8 -0
- package/dist/jobs/index.js +318 -0
- package/dist/jobs/jobs-admin.controller.d.ts +18 -0
- package/dist/jobs/jobs.module.d.ts +33 -0
- package/dist/jobs/jobs.options.d.ts +62 -0
- package/dist/jobs/jobs.service.d.ts +53 -0
- package/dist/jobs/jobs.sql.d.ts +11 -0
- package/dist/media/index.cjs +14 -14
- package/dist/media/index.js +1 -1
- package/dist/meta/index.cjs +3 -3
- package/dist/meta/index.js +1 -1
- package/dist/notifications/index.cjs +375 -0
- package/dist/notifications/index.d.ts +8 -0
- package/dist/notifications/index.js +375 -0
- package/dist/notifications/memory.stores.d.ts +23 -0
- package/dist/notifications/notifications.controller.d.ts +11 -0
- package/dist/notifications/notifications.module.d.ts +31 -0
- package/dist/notifications/notifications.options.d.ts +33 -0
- package/dist/notifications/notifications.port.d.ts +97 -0
- package/dist/notifications/notifier.service.d.ts +31 -0
- package/dist/payments/connect/credentials-cipher.d.ts +14 -0
- package/dist/payments/connect/mercadopago-refund.d.ts +118 -0
- package/dist/payments/connect/mercadopago-signature.d.ts +6 -0
- package/dist/payments/connect/online-checkout.d.ts +69 -0
- package/dist/payments/connect/rejection.d.ts +7 -0
- package/dist/payments/connect/status.d.ts +20 -0
- package/dist/payments/connect/terminal-connections.d.ts +291 -0
- package/dist/payments/index.cjs +908 -10
- package/dist/payments/index.d.ts +10 -0
- package/dist/payments/index.js +900 -2
- package/dist/pinterest/index.cjs +3 -3
- package/dist/pinterest/index.js +1 -1
- package/dist/privacy/anonymizer.d.ts +14 -0
- package/dist/privacy/index.cjs +768 -0
- package/dist/privacy/index.d.ts +13 -0
- package/dist/privacy/index.js +768 -0
- package/dist/privacy/memory.store.d.ts +15 -0
- package/dist/privacy/privacy.module.d.ts +30 -0
- package/dist/privacy/privacy.options.d.ts +43 -0
- package/dist/privacy/privacy.port.d.ts +25 -0
- package/dist/privacy/privacy.service.d.ts +69 -0
- package/dist/privacy/privacy.types.d.ts +125 -0
- package/dist/privacy/sql.d.ts +7 -0
- package/dist/privacy/sql.store.d.ts +21 -0
- package/dist/privacy/zip.d.ts +23 -0
- package/dist/push/index.cjs +13 -13
- package/dist/push/index.js +5 -5
- package/dist/resilience/alert-channels.d.ts +39 -0
- package/dist/resilience/alert-errors.interceptor.d.ts +10 -0
- package/dist/resilience/alert-on-failure.decorator.d.ts +10 -0
- package/dist/resilience/alert.service.d.ts +77 -0
- package/dist/resilience/index.cjs +863 -0
- package/dist/resilience/index.d.ts +18 -0
- package/dist/resilience/index.js +863 -0
- package/dist/resilience/memory-alert-store.d.ts +26 -0
- package/dist/resilience/provider-health.controller.d.ts +14 -0
- package/dist/resilience/provider-unavailable.exception.d.ts +11 -0
- package/dist/resilience/resilience.module.d.ts +34 -0
- package/dist/resilience/resilience.options.d.ts +28 -0
- package/dist/resilience/resilience.types.d.ts +167 -0
- package/dist/resilience/resilient-fetch.d.ts +38 -0
- package/dist/resilience/runtime.d.ts +24 -0
- package/dist/resilience/typeorm/alert.entity.d.ts +21 -0
- package/dist/resilience/typeorm/index.cjs +102 -0
- package/dist/resilience/typeorm/index.d.ts +3 -0
- package/dist/resilience/typeorm/index.js +102 -0
- package/dist/resilience/typeorm/typeorm-alert-store.d.ts +39 -0
- package/dist/resilience/validate-destination.d.ts +63 -0
- package/dist/response/index.cjs +3 -3
- package/dist/response/index.js +2 -2
- package/dist/scheduling/cron-lock.service.d.ts +36 -0
- package/dist/scheduling/cron-unico.decorator.d.ts +27 -0
- package/dist/scheduling/fallback.store.d.ts +34 -0
- package/dist/scheduling/index.cjs +392 -0
- package/dist/scheduling/index.d.ts +18 -0
- package/dist/scheduling/index.js +392 -0
- package/dist/scheduling/lock-store.port.d.ts +19 -0
- package/dist/scheduling/memory.store.d.ts +15 -0
- package/dist/scheduling/redis.module.d.ts +31 -0
- package/dist/scheduling/redis.store.d.ts +24 -0
- package/dist/scheduling/scheduling.module.d.ts +24 -0
- package/dist/scheduling/scheduling.options.d.ts +27 -0
- package/dist/scheduling/sql.store.d.ts +26 -0
- package/dist/secrets/index.cjs +274 -0
- package/dist/secrets/index.d.ts +8 -0
- package/dist/secrets/index.js +274 -0
- package/dist/secrets/secrets.errors.d.ts +6 -0
- package/dist/secrets/secrets.module.d.ts +21 -0
- package/dist/secrets/secrets.options.d.ts +32 -0
- package/dist/secrets/secrets.service.d.ts +54 -0
- package/dist/secrets/secrets.transformer.d.ts +33 -0
- package/dist/security/hash.d.ts +8 -0
- package/dist/security/index.cjs +27 -35
- package/dist/security/index.d.ts +5 -0
- package/dist/security/index.js +24 -32
- package/dist/security/mask.d.ts +22 -0
- package/dist/security/signed-grant.d.ts +30 -0
- package/dist/storage/index.cjs +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/stripe/index.cjs +7 -7
- package/dist/stripe/index.js +1 -1
- package/dist/telegram/index.cjs +2 -2
- package/dist/telegram/index.js +1 -1
- package/dist/tenancy/app-role.d.ts +24 -0
- package/dist/tenancy/db-helpers.d.ts +12 -0
- package/dist/tenancy/index.cjs +205 -0
- package/dist/tenancy/index.d.ts +14 -0
- package/dist/tenancy/index.js +205 -0
- package/dist/tenancy/pg/index.cjs +34 -0
- package/dist/tenancy/pg/index.d.ts +2 -0
- package/dist/tenancy/pg/index.js +34 -0
- package/dist/tenancy/pg/with-tenant.d.ts +23 -0
- package/dist/tenancy/request-context.d.ts +18 -0
- package/dist/tenancy/rls-guardrail.d.ts +38 -0
- package/dist/tenancy/scope.d.ts +5 -0
- package/dist/tenancy/tenancy.errors.d.ts +5 -0
- package/dist/tenancy/tenancy.middleware.d.ts +8 -0
- package/dist/tenancy/tenancy.module.d.ts +37 -0
- package/dist/tenancy/tenancy.options.d.ts +34 -0
- package/dist/tenancy/typeorm/index.cjs +41 -0
- package/dist/tenancy/typeorm/index.d.ts +2 -0
- package/dist/tenancy/typeorm/index.js +41 -0
- package/dist/tenancy/typeorm/with-tenant.d.ts +23 -0
- package/dist/tiktok/index.cjs +3 -3
- package/dist/tiktok/index.js +1 -1
- package/dist/tracking/index.cjs +3 -3
- package/dist/tracking/index.js +2 -2
- package/dist/umami/index.cjs +4 -4
- package/dist/umami/index.js +1 -1
- package/dist/whatsapp/index.cjs +2 -2
- package/dist/whatsapp/index.js +1 -1
- package/package.json +108 -3
|
@@ -0,0 +1,61 @@
|
|
|
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; }// src/tenancy/tenancy.options.ts
|
|
2
|
+
var TENANCY_OPTIONS = /* @__PURE__ */ Symbol("TENANCY_OPTIONS");
|
|
3
|
+
var DEFAULT_GUCS = { tenant: "app.tenant_id", actor: "app.actor_id" };
|
|
4
|
+
|
|
5
|
+
// src/tenancy/request-context.ts
|
|
6
|
+
var _async_hooks = require('async_hooks');
|
|
7
|
+
var storage = new (0, _async_hooks.AsyncLocalStorage)();
|
|
8
|
+
var TenancyContext = {
|
|
9
|
+
run(fn, initial = {}) {
|
|
10
|
+
return storage.run({ ...initial }, fn);
|
|
11
|
+
},
|
|
12
|
+
setTenant(tenantId) {
|
|
13
|
+
const s = storage.getStore();
|
|
14
|
+
if (s) s.tenantId = tenantId;
|
|
15
|
+
},
|
|
16
|
+
setActor(actorId) {
|
|
17
|
+
const s = storage.getStore();
|
|
18
|
+
if (s) s.actorId = actorId;
|
|
19
|
+
},
|
|
20
|
+
tenantId() {
|
|
21
|
+
return _optionalChain([storage, 'access', _ => _.getStore, 'call', _2 => _2(), 'optionalAccess', _3 => _3.tenantId]);
|
|
22
|
+
},
|
|
23
|
+
actorId() {
|
|
24
|
+
return _optionalChain([storage, 'access', _4 => _4.getStore, 'call', _5 => _5(), 'optionalAccess', _6 => _6.actorId]);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/tenancy/tenancy.errors.ts
|
|
29
|
+
var TenantRequiredError = class extends Error {
|
|
30
|
+
constructor(message = "No tenant in scope: refusing to run a tenant query without one.") {
|
|
31
|
+
super(message);
|
|
32
|
+
this.code = "TENANT_REQUIRED";
|
|
33
|
+
this.name = "TenantRequiredError";
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/tenancy/scope.ts
|
|
38
|
+
var GUC_NAME = /^[a-zA-Z_][\w]*(\.[\w-]+)+$/;
|
|
39
|
+
async function applyScope(query, scope, options = {}) {
|
|
40
|
+
const gucs = _nullishCoalesce(options.gucs, () => ( DEFAULT_GUCS));
|
|
41
|
+
const tenantId = _nullishCoalesce(scope.tenantId, () => ( TenancyContext.tenantId()));
|
|
42
|
+
const actorId = _nullishCoalesce(scope.actorId, () => ( TenancyContext.actorId()));
|
|
43
|
+
if (!tenantId && options.failClosed !== false) throw new TenantRequiredError();
|
|
44
|
+
const pairs = [];
|
|
45
|
+
if (tenantId) pairs.push([gucs.tenant, tenantId]);
|
|
46
|
+
if (gucs.actor && actorId) pairs.push([gucs.actor, actorId]);
|
|
47
|
+
for (const [name] of pairs) {
|
|
48
|
+
if (!GUC_NAME.test(name)) throw new Error(`Invalid GUC name: ${name}`);
|
|
49
|
+
}
|
|
50
|
+
for (const [name, value] of pairs) {
|
|
51
|
+
await query("SELECT set_config($1, $2, true)", [name, value]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
exports.TENANCY_OPTIONS = TENANCY_OPTIONS; exports.DEFAULT_GUCS = DEFAULT_GUCS; exports.TenancyContext = TenancyContext; exports.TenantRequiredError = TenantRequiredError; exports.applyScope = applyScope;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
3
7
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
8
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
9
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -13,4 +17,5 @@ var __decorateParam = (index, decorator) => (target, key) => decorator(target, k
|
|
|
13
17
|
|
|
14
18
|
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
|
|
21
|
+
exports.__export = __export; exports.__decorateClass = __decorateClass; exports.__decorateParam = __decorateParam;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// src/security/signed-state.ts
|
|
2
|
+
import { createHmac, randomBytes, timingSafeEqual } from "crypto";
|
|
3
|
+
function signState(payload, options) {
|
|
4
|
+
const body = JSON.stringify({ ts: Date.now(), nonce: randomBytes(8).toString("hex"), ...payload });
|
|
5
|
+
const b64 = Buffer.from(body).toString("base64url");
|
|
6
|
+
const sig = createHmac("sha256", options.secret).update(b64).digest("base64url");
|
|
7
|
+
return `${b64}.${sig}`;
|
|
8
|
+
}
|
|
9
|
+
function readState(state, options) {
|
|
10
|
+
if (!state) return null;
|
|
11
|
+
const parts = state.split(".");
|
|
12
|
+
if (parts.length !== 2) return null;
|
|
13
|
+
const [b64, sig] = parts;
|
|
14
|
+
const expected = createHmac("sha256", options.secret).update(b64).digest("base64url");
|
|
15
|
+
const provided = Buffer.from(sig);
|
|
16
|
+
const wanted = Buffer.from(expected);
|
|
17
|
+
if (provided.length !== wanted.length || !timingSafeEqual(provided, wanted)) return null;
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = JSON.parse(Buffer.from(b64, "base64url").toString());
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const ts = parsed.ts;
|
|
25
|
+
const ttl = options.ttlMs ?? 10 * 6e4;
|
|
26
|
+
if (typeof ts !== "number" || !Number.isFinite(ts) || Date.now() - ts >= ttl) return null;
|
|
27
|
+
const { ts: _ts, nonce: _nonce, ...rest } = parsed;
|
|
28
|
+
return rest;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/security/mask.ts
|
|
32
|
+
function maskEmail(email) {
|
|
33
|
+
const clean = email.trim();
|
|
34
|
+
const at = clean.lastIndexOf("@");
|
|
35
|
+
if (at < 1) return "***";
|
|
36
|
+
return `${clean[0]}***${clean.slice(at)}`;
|
|
37
|
+
}
|
|
38
|
+
function maskPhone(phone, visible = 4) {
|
|
39
|
+
const digits = phone.replace(/\D/g, "");
|
|
40
|
+
if (digits.length <= visible) return "***";
|
|
41
|
+
return `***${digits.slice(-visible)}`;
|
|
42
|
+
}
|
|
43
|
+
function maskToken(token, keep = 2) {
|
|
44
|
+
if (token.length <= keep * 2) return "***";
|
|
45
|
+
return `${token.slice(0, keep)}***${token.slice(-keep)}`;
|
|
46
|
+
}
|
|
47
|
+
function shapeOf(value, depth = 4) {
|
|
48
|
+
if (value === null) return "null";
|
|
49
|
+
if (Array.isArray(value)) return depth <= 0 ? "array" : value.slice(0, 3).map((v) => shapeOf(v, depth - 1));
|
|
50
|
+
if (typeof value === "object") {
|
|
51
|
+
if (depth <= 0) return "object";
|
|
52
|
+
return Object.fromEntries(
|
|
53
|
+
Object.entries(value).map(([k, v]) => [k, shapeOf(v, depth - 1)])
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return typeof value;
|
|
57
|
+
}
|
|
58
|
+
var apply = (rule, value) => {
|
|
59
|
+
if (typeof rule === "function") return rule(value);
|
|
60
|
+
if (rule === "drop") return void 0;
|
|
61
|
+
if (rule === "redact" || typeof value !== "string") return "***";
|
|
62
|
+
if (rule === "email") return maskEmail(value);
|
|
63
|
+
if (rule === "phone") return maskPhone(value);
|
|
64
|
+
return maskToken(value);
|
|
65
|
+
};
|
|
66
|
+
function maskFields(value, rules, maxDepth = 8) {
|
|
67
|
+
const byKey = new Map(Object.entries(rules).map(([k, r]) => [k.toLowerCase(), r]));
|
|
68
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
69
|
+
const walk = (v, depth) => {
|
|
70
|
+
if (v === null || typeof v !== "object") return v;
|
|
71
|
+
if (depth > maxDepth || seen.has(v)) return "[\u2026]";
|
|
72
|
+
seen.add(v);
|
|
73
|
+
if (Array.isArray(v)) return v.map((x) => walk(x, depth + 1));
|
|
74
|
+
const out = {};
|
|
75
|
+
for (const [k, x] of Object.entries(v)) {
|
|
76
|
+
const rule = byKey.get(k.toLowerCase());
|
|
77
|
+
if (rule === void 0) out[k] = walk(x, depth + 1);
|
|
78
|
+
else {
|
|
79
|
+
try {
|
|
80
|
+
const masked = apply(rule, x);
|
|
81
|
+
if (masked !== void 0) out[k] = masked;
|
|
82
|
+
} catch {
|
|
83
|
+
out[k] = "***";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
};
|
|
89
|
+
return walk(value, 0);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/security/hash.ts
|
|
93
|
+
import { createHash, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
94
|
+
var hashSha256 = (value) => createHash("sha256").update(value).digest("hex");
|
|
95
|
+
function constantTimeEqual(a, b) {
|
|
96
|
+
const ba = Buffer.from(a);
|
|
97
|
+
const bb = Buffer.from(b);
|
|
98
|
+
if (ba.length !== bb.length) {
|
|
99
|
+
timingSafeEqual2(ba, ba);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
return timingSafeEqual2(ba, bb);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/security/signed-grant.ts
|
|
106
|
+
import { createHmac as createHmac2, randomBytes as randomBytes2 } from "crypto";
|
|
107
|
+
var sign = (b64, secret) => createHmac2("sha256", secret).update(b64).digest("base64url");
|
|
108
|
+
function signGrant(claims, secret, ttlMs = 6e4) {
|
|
109
|
+
const body = JSON.stringify({
|
|
110
|
+
a: claims.actor,
|
|
111
|
+
p: claims.permission,
|
|
112
|
+
r: claims.resource,
|
|
113
|
+
t: claims.tenant,
|
|
114
|
+
exp: Date.now() + ttlMs,
|
|
115
|
+
n: randomBytes2(8).toString("hex")
|
|
116
|
+
});
|
|
117
|
+
const b64 = Buffer.from(body).toString("base64url");
|
|
118
|
+
return `${b64}.${sign(b64, secret)}`;
|
|
119
|
+
}
|
|
120
|
+
function verifyGrant(token, secret, expected) {
|
|
121
|
+
if (!token) return null;
|
|
122
|
+
const parts = token.split(".");
|
|
123
|
+
if (parts.length !== 2) return null;
|
|
124
|
+
const [b64, sig] = parts;
|
|
125
|
+
if (!constantTimeEqual(sig, sign(b64, secret))) return null;
|
|
126
|
+
let p;
|
|
127
|
+
try {
|
|
128
|
+
p = JSON.parse(Buffer.from(b64, "base64url").toString());
|
|
129
|
+
} catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (typeof p.exp !== "number" || !Number.isFinite(p.exp) || Date.now() >= p.exp) return null;
|
|
133
|
+
if (typeof p.a !== "string" || typeof p.p !== "string" || typeof p.r !== "string" || typeof p.t !== "string") return null;
|
|
134
|
+
if (p.p !== expected.permission || p.r !== expected.resource || p.t !== expected.tenant) return null;
|
|
135
|
+
if (expected.actor !== void 0 && p.a !== expected.actor) return null;
|
|
136
|
+
return { actor: p.a, permission: p.p, resource: p.r, tenant: p.t };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export {
|
|
140
|
+
signState,
|
|
141
|
+
readState,
|
|
142
|
+
maskEmail,
|
|
143
|
+
maskPhone,
|
|
144
|
+
maskToken,
|
|
145
|
+
shapeOf,
|
|
146
|
+
maskFields,
|
|
147
|
+
hashSha256,
|
|
148
|
+
constantTimeEqual,
|
|
149
|
+
signGrant,
|
|
150
|
+
verifyGrant
|
|
151
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
withRequestContext
|
|
3
|
-
} from "./chunk-ZJMLEP5H.js";
|
|
4
1
|
import {
|
|
5
2
|
buildPageMeta,
|
|
6
3
|
paginated
|
|
7
4
|
} from "./chunk-TCAMLNUZ.js";
|
|
5
|
+
import {
|
|
6
|
+
withRequestContext
|
|
7
|
+
} from "./chunk-NJYLQDB3.js";
|
|
8
8
|
import {
|
|
9
9
|
__decorateClass,
|
|
10
10
|
__decorateParam
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-D3DDJWUD.js";
|
|
12
12
|
|
|
13
13
|
// src/crud/list-query.dto.ts
|
|
14
14
|
import { Type } from "class-transformer";
|
|
@@ -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(); } } 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 _chunkLRX7AMSScjs = require('./chunk-LRX7AMSS.cjs');
|
|
4
|
+
|
|
5
|
+
// src/consent/guard/index.ts
|
|
6
|
+
var guard_exports = {};
|
|
7
|
+
_chunkLRX7AMSScjs.__export.call(void 0, guard_exports, {
|
|
8
|
+
bundleContains: () => bundleContains,
|
|
9
|
+
checkParity: () => checkParity,
|
|
10
|
+
extractVersion: () => extractVersion,
|
|
11
|
+
verifyRelease: () => verifyRelease
|
|
12
|
+
});
|
|
13
|
+
function extractVersion(source, pattern) {
|
|
14
|
+
return _nullishCoalesce(_optionalChain([pattern, 'access', _ => _.exec, 'call', _2 => _2(source), 'optionalAccess', _3 => _3[1]]), () => ( null));
|
|
15
|
+
}
|
|
16
|
+
function checkParity(mobile, server) {
|
|
17
|
+
if (!mobile || !server) return { ok: false, message: "No se pudo leer la versi\xF3n m\xEDnima (m\xF3vil o servidor)." };
|
|
18
|
+
return mobile === server ? { ok: true, message: `Paridad correcta: ${server}.` } : { ok: false, message: `La m\xEDnima del m\xF3vil (${mobile}) no coincide con la del servidor (${server}).` };
|
|
19
|
+
}
|
|
20
|
+
function bundleContains(bundleText, minimum) {
|
|
21
|
+
return bundleText.includes(minimum) ? { ok: true, message: `El bundle web trae ${minimum}.` } : { ok: false, message: `El bundle web publicado NO trae ${minimum}: publ\xEDcalo antes de desplegar la API.` };
|
|
22
|
+
}
|
|
23
|
+
function verifyRelease(input) {
|
|
24
|
+
const results = [checkParity(input.mobile, input.server)];
|
|
25
|
+
if (input.webBundle !== void 0 && input.server)
|
|
26
|
+
results.push(bundleContains(input.webBundle, input.server));
|
|
27
|
+
if (input.mobilePublished !== void 0)
|
|
28
|
+
results.push(
|
|
29
|
+
input.mobilePublished === input.server ? { ok: true, message: "M\xF3vil publicado confirmado." } : { ok: false, message: `M\xF3vil publicado (${input.mobilePublished}) distinto de la m\xEDnima (${input.server}).` }
|
|
30
|
+
);
|
|
31
|
+
return { ok: results.every((r) => r.ok), results };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
exports.extractVersion = extractVersion; exports.checkParity = checkParity; exports.bundleContains = bundleContains; exports.verifyRelease = verifyRelease; exports.guard_exports = guard_exports;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ResponseInterceptor
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IGSNB5BX.js";
|
|
4
4
|
import {
|
|
5
5
|
GlobalExceptionFilter
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-5LVGCTJ3.js";
|
|
7
|
+
import {
|
|
8
|
+
applyBodyLimits,
|
|
9
|
+
applyTrustProxy,
|
|
10
|
+
originSecretMiddleware
|
|
11
|
+
} from "./chunk-WFCQDOSN.js";
|
|
7
12
|
|
|
8
13
|
// src/bootstrap/apply-defaults.ts
|
|
9
14
|
import {
|
|
@@ -12,6 +17,9 @@ import {
|
|
|
12
17
|
import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";
|
|
13
18
|
import helmet from "helmet";
|
|
14
19
|
function applyNestKitDefaults(app, options = {}) {
|
|
20
|
+
if (options.trustProxy !== void 0) applyTrustProxy(app, options.trustProxy);
|
|
21
|
+
if (options.originSecret) app.use(originSecretMiddleware(options.originSecret));
|
|
22
|
+
if (options.bodyLimits) applyBodyLimits(app, options.bodyLimits);
|
|
15
23
|
app.use(helmet());
|
|
16
24
|
app.enableCors(options.cors ?? { origin: process.env.CORS_ORIGIN?.split(",") ?? true });
|
|
17
25
|
app.useGlobalPipes(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLRX7AMSScjs = require('./chunk-LRX7AMSS.cjs');
|
|
4
4
|
|
|
5
5
|
// src/database/supabase/supabase.module.ts
|
|
6
6
|
var _common = require('@nestjs/common');
|
|
@@ -16,7 +16,7 @@ function requireEnv(name) {
|
|
|
16
16
|
}
|
|
17
17
|
var SupabaseModule = class {
|
|
18
18
|
};
|
|
19
|
-
SupabaseModule = exports.SupabaseModule =
|
|
19
|
+
SupabaseModule = exports.SupabaseModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
20
20
|
_common.Module.call(void 0, {
|
|
21
21
|
providers: [
|
|
22
22
|
{
|
|
@@ -4,7 +4,7 @@ var _chunkSDWHKPXIcjs = require('./chunk-SDWHKPXI.cjs');
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkLRX7AMSScjs = require('./chunk-LRX7AMSS.cjs');
|
|
8
8
|
|
|
9
9
|
// src/audit/audit.port.ts
|
|
10
10
|
var AUDIT_SINK = /* @__PURE__ */ Symbol("AUDIT_SINK");
|
|
@@ -42,11 +42,11 @@ var AuditService = class {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
AuditService = exports.AuditService =
|
|
45
|
+
AuditService = exports.AuditService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
46
46
|
_common.Injectable.call(void 0, ),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, AUDIT_SINK)),
|
|
48
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Optional.call(void 0, )),
|
|
49
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, AUDIT_OPTIONS))
|
|
50
50
|
], AuditService);
|
|
51
51
|
|
|
52
52
|
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// src/hardening/http.types.ts
|
|
2
|
+
function pathOf(req) {
|
|
3
|
+
const raw = req.path ?? req.originalUrl ?? req.url ?? "";
|
|
4
|
+
const q = raw.indexOf("?");
|
|
5
|
+
return q === -1 ? raw : raw.slice(0, q);
|
|
6
|
+
}
|
|
7
|
+
function headerOf(req, name) {
|
|
8
|
+
const v = req.headers?.[name.toLowerCase()];
|
|
9
|
+
return Array.isArray(v) ? v[0] : v;
|
|
10
|
+
}
|
|
11
|
+
function matchesPath(rule, path) {
|
|
12
|
+
if (rule instanceof RegExp) return rule.test(path);
|
|
13
|
+
if (rule.endsWith("*")) return path.startsWith(rule.slice(0, -1));
|
|
14
|
+
return path === rule;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// src/hardening/body-limits.ts
|
|
18
|
+
import { createRequire } from "module";
|
|
19
|
+
import { join } from "path";
|
|
20
|
+
var DEFAULT_BODY_LIMIT = "1mb";
|
|
21
|
+
var expressJson = (limit) => {
|
|
22
|
+
const req = createRequire(join(process.cwd(), "noop.js"));
|
|
23
|
+
return req("express").json({ limit });
|
|
24
|
+
};
|
|
25
|
+
function applyBodyLimits(app, options, factory = expressJson) {
|
|
26
|
+
const routes = options.routes ?? [];
|
|
27
|
+
if (routes.length) {
|
|
28
|
+
const parsers = /* @__PURE__ */ new Map();
|
|
29
|
+
const parserFor = (limit) => {
|
|
30
|
+
let p = parsers.get(limit);
|
|
31
|
+
if (!p) parsers.set(limit, p = factory(limit));
|
|
32
|
+
return p;
|
|
33
|
+
};
|
|
34
|
+
app.use((req, res, next) => {
|
|
35
|
+
const path = pathOf(req);
|
|
36
|
+
const rule = routes.find((r) => matchesPath(r.match, path));
|
|
37
|
+
return rule ? parserFor(rule.limit)(req, res, next) : next();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
app.useBodyParser?.("json", { limit: options.default ?? DEFAULT_BODY_LIMIT });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/hardening/origin-secret.ts
|
|
44
|
+
import { createHash, timingSafeEqual } from "crypto";
|
|
45
|
+
var digest = (v) => createHash("sha256").update(v).digest();
|
|
46
|
+
function sameSecret(received, expected) {
|
|
47
|
+
return typeof received === "string" && timingSafeEqual(digest(received), expected);
|
|
48
|
+
}
|
|
49
|
+
function originSecretMiddleware(options) {
|
|
50
|
+
const expected = options.value ? digest(options.value) : null;
|
|
51
|
+
const scoped = (options.scoped ?? []).filter((s) => s.value).map((s) => ({ header: s.header, paths: s.paths, expected: digest(s.value) }));
|
|
52
|
+
const exclude = options.exclude ?? [];
|
|
53
|
+
return (req, res, next) => {
|
|
54
|
+
if (!expected) return next();
|
|
55
|
+
const path = pathOf(req);
|
|
56
|
+
if (exclude.some((r) => matchesPath(r, path))) return next();
|
|
57
|
+
if (sameSecret(headerOf(req, options.header), expected)) return next();
|
|
58
|
+
if (scoped.some(
|
|
59
|
+
(s) => s.paths.some((r) => matchesPath(r, path)) && sameSecret(headerOf(req, s.header), s.expected)
|
|
60
|
+
))
|
|
61
|
+
return next();
|
|
62
|
+
res.status(options.status ?? 403).json({
|
|
63
|
+
success: false,
|
|
64
|
+
error: { code: options.code ?? "UNTRUSTED_ORIGIN", message: options.message ?? "Access not allowed." }
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/hardening/trust-proxy.ts
|
|
70
|
+
function trustedIp(req, options = {}) {
|
|
71
|
+
for (const name of options.trustedHeaders ?? []) {
|
|
72
|
+
const v = headerOf(req, name);
|
|
73
|
+
if (v) return v;
|
|
74
|
+
}
|
|
75
|
+
return req.ips?.length ? req.ips[0] : req.ip ?? "";
|
|
76
|
+
}
|
|
77
|
+
function applyTrustProxy(app, value) {
|
|
78
|
+
const instance = app.getHttpAdapter().getInstance();
|
|
79
|
+
instance.set?.("trust proxy", value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
pathOf,
|
|
84
|
+
matchesPath,
|
|
85
|
+
DEFAULT_BODY_LIMIT,
|
|
86
|
+
applyBodyLimits,
|
|
87
|
+
originSecretMiddleware,
|
|
88
|
+
trustedIp,
|
|
89
|
+
applyTrustProxy
|
|
90
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type CallHandler, type ExecutionContext, type NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import type { Observable } from 'rxjs';
|
|
3
|
+
import { type ConsentOptions } from './consent.options.js';
|
|
4
|
+
import { ConsentService } from './consent.service.js';
|
|
5
|
+
/**
|
|
6
|
+
* Blocks anyone who has not accepted a version >= the minimum of each document
|
|
7
|
+
* with a 403 and a stable code (`CONSENT_PENDIENTE` by default). The details
|
|
8
|
+
* carry the current version(s) so the client can show the right screen.
|
|
9
|
+
*
|
|
10
|
+
* An interceptor and not a guard on purpose: global guards run BEFORE the
|
|
11
|
+
* per-controller auth guard, so `req.user` does not exist yet; interceptors run
|
|
12
|
+
* after every guard. Mount it globally (`app.useGlobalInterceptors(app.get(ConsentInterceptor))`
|
|
13
|
+
* or `APP_INTERCEPTOR`).
|
|
14
|
+
*/
|
|
15
|
+
export declare class ConsentInterceptor implements NestInterceptor {
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly consent;
|
|
18
|
+
constructor(options: ConsentOptions, consent: ConsentService);
|
|
19
|
+
intercept(ctx: ExecutionContext, next: CallHandler): Promise<Observable<unknown>>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { type ConsentOptions } from './consent.options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Legal-consent gate.
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* ConsentModule.forRoot({
|
|
8
|
+
* documentos: [{ id: 'terminos', version: '2026-10-15', minima: '2026-09-12' }],
|
|
9
|
+
* rutasLibres: [/^\/api\/v1\/auth(\/|$)/, /^\/api\/v1\/cuenta(\/|$)/, /^\/(health|ready)$/],
|
|
10
|
+
* puertoDeAceptaciones: new TypeOrmConsentStore(dataSource),
|
|
11
|
+
* })
|
|
12
|
+
* // main.ts: app.useGlobalInterceptors(app.get(ConsentInterceptor));
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Not wired into `applyNestKitDefaults`: switching it on changes the contract
|
|
16
|
+
* of every endpoint at once, so mounting it is a decision.
|
|
17
|
+
*/
|
|
18
|
+
export declare class ConsentModule {
|
|
19
|
+
static forRoot(options: ConsentOptions): DynamicModule;
|
|
20
|
+
static forRootAsync(config: {
|
|
21
|
+
imports?: any[];
|
|
22
|
+
inject?: any[];
|
|
23
|
+
useFactory: (...args: any[]) => ConsentOptions | Promise<ConsentOptions>;
|
|
24
|
+
}): DynamicModule;
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ConsentStore } from './consent.port.js';
|
|
2
|
+
export declare const CONSENT_OPTIONS: unique symbol;
|
|
3
|
+
export interface ConsentDocument {
|
|
4
|
+
/** Stable id: `terminos`, `privacidad`. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Current version, the one shown and stored on acceptance. Raising it blocks nobody. */
|
|
7
|
+
version: string;
|
|
8
|
+
/** Minimum accepted version. This is what blocks (403). Raise only for a substantial legal change. */
|
|
9
|
+
minima: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ConsentOptions {
|
|
12
|
+
documentos: ConsentDocument[];
|
|
13
|
+
/** Paths that never require consent (login, the accept endpoint, health). Tested against `req.path`. */
|
|
14
|
+
rutasLibres?: RegExp[];
|
|
15
|
+
/** Where acceptances live. Defaults to an in-process store (single instance, lost on restart). */
|
|
16
|
+
puertoDeAceptaciones?: ConsentStore;
|
|
17
|
+
/** Stable error code of the 403. Defaults to `CONSENT_PENDIENTE`. */
|
|
18
|
+
codigoError?: string;
|
|
19
|
+
/** How long an accepted version is cached per user, ms. Defaults to 60 000. `0` disables. */
|
|
20
|
+
ttlCache?: number;
|
|
21
|
+
/** Message of the 403. */
|
|
22
|
+
textoError?: string;
|
|
23
|
+
/** Who is asking. Defaults to `req.user.sub`. Return `undefined` for anonymous (let through). */
|
|
24
|
+
getUserId?: (request: any) => string | undefined;
|
|
25
|
+
/** Clock, for tests. */
|
|
26
|
+
now?: () => number;
|
|
27
|
+
}
|
|
28
|
+
export declare const DEFAULT_CONSENT_CODE = "CONSENT_PENDIENTE";
|
|
29
|
+
export declare const DEFAULT_CONSENT_TTL_MS = 60000;
|
|
30
|
+
export declare const DEFAULT_CONSENT_TEXT = "Antes de continuar acepta los documentos legales vigentes.";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** DI token for the {@link ConsentStore}. */
|
|
2
|
+
export declare const CONSENT_STORE: unique symbol;
|
|
3
|
+
/** What was accepted, when, and anything the app wants to keep as evidence. */
|
|
4
|
+
export interface ConsentRecord {
|
|
5
|
+
version: string;
|
|
6
|
+
acceptedAt: Date;
|
|
7
|
+
/** Declared age of majority, IP, locale… whatever the app must be able to prove later. */
|
|
8
|
+
meta?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Where acceptances live. The library keeps nothing itself: a consent receipt
|
|
12
|
+
* belongs in the consumer's database, under its retention rules.
|
|
13
|
+
*/
|
|
14
|
+
export interface ConsentStore {
|
|
15
|
+
get(userId: string, docId: string): Promise<ConsentRecord | null>;
|
|
16
|
+
save(userId: string, docId: string, record: ConsentRecord): Promise<void>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ConsentOptions } from './consent.options.js';
|
|
2
|
+
import { type ConsentRecord, type ConsentStore } from './consent.port.js';
|
|
3
|
+
/** Anything with `record(event)`: the real `AuditService`, or a stub. */
|
|
4
|
+
export interface ConsentAudit {
|
|
5
|
+
record(event: {
|
|
6
|
+
action: string;
|
|
7
|
+
resource: string;
|
|
8
|
+
resourceId?: string;
|
|
9
|
+
after?: unknown;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
}): Promise<unknown>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Decides whether a user may use the API and records acceptances.
|
|
15
|
+
*
|
|
16
|
+
* `hasAccepted` reads the accepted version through a short per-user cache so
|
|
17
|
+
* the interceptor does not hit the store on every request; `accept` refreshes
|
|
18
|
+
* the entry, so the user sees the effect immediately.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ConsentService {
|
|
21
|
+
private readonly options;
|
|
22
|
+
private readonly store;
|
|
23
|
+
private readonly audit?;
|
|
24
|
+
private readonly cache;
|
|
25
|
+
constructor(options: ConsentOptions, store: ConsentStore, audit?: ConsentAudit | undefined);
|
|
26
|
+
private now;
|
|
27
|
+
private ttl;
|
|
28
|
+
private doc;
|
|
29
|
+
private remember;
|
|
30
|
+
/** Accepted version of one document (cached), or `null`. */
|
|
31
|
+
acceptedVersion(userId: string, docId: string): Promise<string | null>;
|
|
32
|
+
/** Pure check over a version: at or above the document's minimum. */
|
|
33
|
+
isValid(docId: string, version: string | null | undefined): boolean;
|
|
34
|
+
/** Ids of the documents the user has not accepted at the minimum version. */
|
|
35
|
+
pending(userId: string): Promise<string[]>;
|
|
36
|
+
/** True when every document is accepted at >= its minimum. */
|
|
37
|
+
hasAccepted(userId: string): Promise<boolean>;
|
|
38
|
+
/**
|
|
39
|
+
* Records the acceptance of the **current** version. Idempotent: if that
|
|
40
|
+
* version is already stored, the original receipt (date included) is kept
|
|
41
|
+
* and nothing is audited again.
|
|
42
|
+
*/
|
|
43
|
+
accept(userId: string, docId: string, meta?: Record<string, unknown>): Promise<ConsentRecord>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkUDACUMLOcjs = require('../../chunk-UDACUMLO.cjs');
|
|
7
|
+
require('../../chunk-LRX7AMSS.cjs');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.bundleContains = _chunkUDACUMLOcjs.bundleContains; exports.checkParity = _chunkUDACUMLOcjs.checkParity; exports.extractVersion = _chunkUDACUMLOcjs.extractVersion; exports.verifyRelease = _chunkUDACUMLOcjs.verifyRelease;
|