@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,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Release guard for the consent minimum. Pure functions, no I/O: wire them into
|
|
3
|
+
* a deploy script that reads the files and fetches the bundle.
|
|
4
|
+
*
|
|
5
|
+
* Origin: raising the enforced minimum on the API before the web and mobile
|
|
6
|
+
* clients shipped it locked everyone out (Cajón, 2026-10-16). Order is:
|
|
7
|
+
* clients first, API last.
|
|
8
|
+
*/
|
|
9
|
+
/** Pulls a version out of source text with a regex whose group 1 is the version. */
|
|
10
|
+
export declare function extractVersion(source: string, pattern: RegExp): string | null;
|
|
11
|
+
export interface ParityResult {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
}
|
|
15
|
+
/** The mobile client's constant must equal the server's minimum. */
|
|
16
|
+
export declare function checkParity(mobile: string | null, server: string | null): ParityResult;
|
|
17
|
+
/** Does a published web bundle (text) contain the minimum version? */
|
|
18
|
+
export declare function bundleContains(bundleText: string, minimum: string): ParityResult;
|
|
19
|
+
export interface GuardInput {
|
|
20
|
+
server: string | null;
|
|
21
|
+
mobile: string | null;
|
|
22
|
+
/** Text of the published web bundle(s). Omit to skip that check. */
|
|
23
|
+
webBundle?: string;
|
|
24
|
+
/** Version the operator confirms the store builds ship. Omit to skip. */
|
|
25
|
+
mobilePublished?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Runs every check; `ok` only if all pass. */
|
|
28
|
+
export declare function verifyRelease(input: GuardInput): {
|
|
29
|
+
ok: boolean;
|
|
30
|
+
results: ParityResult[];
|
|
31
|
+
};
|
|
@@ -0,0 +1,271 @@
|
|
|
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; } async function _asyncOptionalChain(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 = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
var _chunkUDACUMLOcjs = require('../chunk-UDACUMLO.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkA6YGIZCQcjs = require('../chunk-A6YGIZCQ.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkVALDHJOOcjs = require('../chunk-VALDHJOO.cjs');
|
|
12
|
+
require('../chunk-SDWHKPXI.cjs');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkHDFPSA2Vcjs = require('../chunk-HDFPSA2V.cjs');
|
|
17
|
+
require('../chunk-Q5Y33L7B.cjs');
|
|
18
|
+
require('../chunk-PNK5WMPP.cjs');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
23
|
+
|
|
24
|
+
// src/consent/consent.module.ts
|
|
25
|
+
var _common = require('@nestjs/common');
|
|
26
|
+
|
|
27
|
+
// src/consent/consent.interceptor.ts
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// src/consent/consent.options.ts
|
|
34
|
+
var CONSENT_OPTIONS = /* @__PURE__ */ Symbol("CONSENT_OPTIONS");
|
|
35
|
+
var DEFAULT_CONSENT_CODE = "CONSENT_PENDIENTE";
|
|
36
|
+
var DEFAULT_CONSENT_TTL_MS = 6e4;
|
|
37
|
+
var DEFAULT_CONSENT_TEXT = "Antes de continuar acepta los documentos legales vigentes.";
|
|
38
|
+
|
|
39
|
+
// src/consent/consent.service.ts
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
// src/consent/consent.port.ts
|
|
43
|
+
var CONSENT_STORE = /* @__PURE__ */ Symbol("CONSENT_STORE");
|
|
44
|
+
|
|
45
|
+
// src/consent/consent.service.ts
|
|
46
|
+
var ConsentService = class {
|
|
47
|
+
constructor(options, store, audit) {
|
|
48
|
+
this.options = options;
|
|
49
|
+
this.store = store;
|
|
50
|
+
this.audit = audit;
|
|
51
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
52
|
+
}
|
|
53
|
+
now() {
|
|
54
|
+
return (_nullishCoalesce(this.options.now, () => ( Date.now)))();
|
|
55
|
+
}
|
|
56
|
+
ttl() {
|
|
57
|
+
return _nullishCoalesce(this.options.ttlCache, () => ( DEFAULT_CONSENT_TTL_MS));
|
|
58
|
+
}
|
|
59
|
+
doc(docId) {
|
|
60
|
+
const d = this.options.documentos.find((x) => x.id === docId);
|
|
61
|
+
if (!d) throw new (0, _chunkHDFPSA2Vcjs.ValidationAppException)(`Unknown consent document: ${docId}`);
|
|
62
|
+
return d;
|
|
63
|
+
}
|
|
64
|
+
remember(userId, docId, version) {
|
|
65
|
+
if (this.ttl() > 0) this.cache.set(`${userId}\0${docId}`, { version, until: this.now() + this.ttl() });
|
|
66
|
+
}
|
|
67
|
+
/** Accepted version of one document (cached), or `null`. */
|
|
68
|
+
async acceptedVersion(userId, docId) {
|
|
69
|
+
const key = `${userId}\0${docId}`;
|
|
70
|
+
const hit = this.cache.get(key);
|
|
71
|
+
if (hit && hit.until > this.now()) return hit.version;
|
|
72
|
+
const version = await _asyncNullishCoalesce(await _asyncOptionalChain([(await this.store.get(userId, docId)), 'optionalAccess', async _ => _.version]), async () => ( null));
|
|
73
|
+
this.remember(userId, docId, version);
|
|
74
|
+
return version;
|
|
75
|
+
}
|
|
76
|
+
/** Pure check over a version: at or above the document's minimum. */
|
|
77
|
+
isValid(docId, version) {
|
|
78
|
+
return _chunkA6YGIZCQcjs.versionAceptadaVigente.call(void 0, version, this.doc(docId).minima);
|
|
79
|
+
}
|
|
80
|
+
/** Ids of the documents the user has not accepted at the minimum version. */
|
|
81
|
+
async pending(userId) {
|
|
82
|
+
const out = [];
|
|
83
|
+
for (const d of this.options.documentos) {
|
|
84
|
+
if (!this.isValid(d.id, await this.acceptedVersion(userId, d.id))) out.push(d.id);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** True when every document is accepted at >= its minimum. */
|
|
89
|
+
async hasAccepted(userId) {
|
|
90
|
+
return (await this.pending(userId)).length === 0;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Records the acceptance of the **current** version. Idempotent: if that
|
|
94
|
+
* version is already stored, the original receipt (date included) is kept
|
|
95
|
+
* and nothing is audited again.
|
|
96
|
+
*/
|
|
97
|
+
async accept(userId, docId, meta) {
|
|
98
|
+
const d = this.doc(docId);
|
|
99
|
+
const previous = await this.store.get(userId, docId);
|
|
100
|
+
if (previous && previous.version === d.version) {
|
|
101
|
+
this.remember(userId, docId, d.version);
|
|
102
|
+
return previous;
|
|
103
|
+
}
|
|
104
|
+
const record = { version: d.version, acceptedAt: new Date(this.now()), meta };
|
|
105
|
+
await this.store.save(userId, docId, record);
|
|
106
|
+
this.remember(userId, docId, d.version);
|
|
107
|
+
await _optionalChain([this, 'access', _2 => _2.audit, 'optionalAccess', _3 => _3.record, 'call', _4 => _4({
|
|
108
|
+
action: "consent.accepted",
|
|
109
|
+
resource: docId,
|
|
110
|
+
resourceId: userId,
|
|
111
|
+
after: { version: d.version },
|
|
112
|
+
metadata: meta
|
|
113
|
+
})]);
|
|
114
|
+
return record;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
ConsentService = exports.ConsentService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
118
|
+
_common.Injectable.call(void 0, ),
|
|
119
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, CONSENT_OPTIONS)),
|
|
120
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, CONSENT_STORE)),
|
|
121
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 2, _common.Optional.call(void 0, )),
|
|
122
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 2, _common.Inject.call(void 0, _chunkVALDHJOOcjs.AuditService))
|
|
123
|
+
], ConsentService);
|
|
124
|
+
|
|
125
|
+
// src/consent/consent.interceptor.ts
|
|
126
|
+
var ConsentInterceptor = class {
|
|
127
|
+
constructor(options, consent) {
|
|
128
|
+
this.options = options;
|
|
129
|
+
this.consent = consent;
|
|
130
|
+
}
|
|
131
|
+
async intercept(ctx, next) {
|
|
132
|
+
const req = ctx.switchToHttp().getRequest();
|
|
133
|
+
const userId = this.options.getUserId ? this.options.getUserId(req) : _optionalChain([req, 'optionalAccess', _5 => _5.user, 'optionalAccess', _6 => _6.sub]);
|
|
134
|
+
if (userId) {
|
|
135
|
+
const path = _nullishCoalesce(req.path, () => ( String(_nullishCoalesce(req.url, () => ( ""))).split("?")[0]));
|
|
136
|
+
const free = (_nullishCoalesce(this.options.rutasLibres, () => ( []))).some((r) => r.test(path));
|
|
137
|
+
if (!free) {
|
|
138
|
+
const pending = await this.consent.pending(userId);
|
|
139
|
+
if (pending.length > 0) {
|
|
140
|
+
const docs = this.options.documentos.filter((d) => pending.includes(d.id));
|
|
141
|
+
throw new (0, _chunkHDFPSA2Vcjs.ForbiddenAppException)(
|
|
142
|
+
_nullishCoalesce(this.options.textoError, () => ( DEFAULT_CONSENT_TEXT)),
|
|
143
|
+
{
|
|
144
|
+
pendientes: pending,
|
|
145
|
+
version: _optionalChain([docs, 'access', _7 => _7[0], 'optionalAccess', _8 => _8.version]),
|
|
146
|
+
versiones: Object.fromEntries(docs.map((d) => [d.id, d.version]))
|
|
147
|
+
},
|
|
148
|
+
_nullishCoalesce(this.options.codigoError, () => ( DEFAULT_CONSENT_CODE))
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return next.handle();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
ConsentInterceptor = exports.ConsentInterceptor = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
157
|
+
_common.Injectable.call(void 0, ),
|
|
158
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, CONSENT_OPTIONS))
|
|
159
|
+
], ConsentInterceptor);
|
|
160
|
+
|
|
161
|
+
// src/consent/memory.store.ts
|
|
162
|
+
var MemoryConsentStore = class {
|
|
163
|
+
constructor() {
|
|
164
|
+
this.rows = /* @__PURE__ */ new Map();
|
|
165
|
+
}
|
|
166
|
+
async get(userId, docId) {
|
|
167
|
+
return _nullishCoalesce(this.rows.get(`${userId}\0${docId}`), () => ( null));
|
|
168
|
+
}
|
|
169
|
+
async save(userId, docId, record) {
|
|
170
|
+
this.rows.set(`${userId}\0${docId}`, record);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/consent/consent.module.ts
|
|
175
|
+
var ConsentModule = class {
|
|
176
|
+
static forRoot(options) {
|
|
177
|
+
const providers = [
|
|
178
|
+
{ provide: CONSENT_OPTIONS, useValue: options },
|
|
179
|
+
{ provide: CONSENT_STORE, useValue: _nullishCoalesce(options.puertoDeAceptaciones, () => ( new MemoryConsentStore())) },
|
|
180
|
+
ConsentService,
|
|
181
|
+
ConsentInterceptor
|
|
182
|
+
];
|
|
183
|
+
return {
|
|
184
|
+
module: ConsentModule,
|
|
185
|
+
providers,
|
|
186
|
+
exports: [CONSENT_OPTIONS, CONSENT_STORE, ConsentService, ConsentInterceptor]
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
static forRootAsync(config) {
|
|
190
|
+
const providers = [
|
|
191
|
+
{ provide: CONSENT_OPTIONS, useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) },
|
|
192
|
+
{
|
|
193
|
+
provide: CONSENT_STORE,
|
|
194
|
+
useFactory: (o) => _nullishCoalesce(o.puertoDeAceptaciones, () => ( new MemoryConsentStore())),
|
|
195
|
+
inject: [CONSENT_OPTIONS]
|
|
196
|
+
},
|
|
197
|
+
ConsentService,
|
|
198
|
+
ConsentInterceptor
|
|
199
|
+
];
|
|
200
|
+
return {
|
|
201
|
+
module: ConsentModule,
|
|
202
|
+
imports: _nullishCoalesce(config.imports, () => ( [])),
|
|
203
|
+
providers,
|
|
204
|
+
exports: [CONSENT_OPTIONS, CONSENT_STORE, ConsentService, ConsentInterceptor]
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
ConsentModule = exports.ConsentModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
209
|
+
_common.Global.call(void 0, ),
|
|
210
|
+
_common.Module.call(void 0, {})
|
|
211
|
+
], ConsentModule);
|
|
212
|
+
|
|
213
|
+
// src/consent/typeorm.store.ts
|
|
214
|
+
var TypeOrmConsentStore = class {
|
|
215
|
+
constructor(db, options = {}) {
|
|
216
|
+
this.db = db;
|
|
217
|
+
this.table = assertIdent(_nullishCoalesce(options.table, () => ( "consent_acceptance")));
|
|
218
|
+
}
|
|
219
|
+
async get(userId, docId) {
|
|
220
|
+
const rows = await this.db.query(
|
|
221
|
+
`SELECT version, accepted_at, meta FROM "${this.table}" WHERE user_id = $1 AND doc_id = $2 LIMIT 1`,
|
|
222
|
+
[userId, docId]
|
|
223
|
+
);
|
|
224
|
+
const r = Array.isArray(rows) ? rows[0] : _optionalChain([rows, 'optionalAccess', _9 => _9.rows, 'optionalAccess', _10 => _10[0]]);
|
|
225
|
+
if (!r) return null;
|
|
226
|
+
return {
|
|
227
|
+
version: r.version,
|
|
228
|
+
acceptedAt: r.accepted_at instanceof Date ? r.accepted_at : new Date(r.accepted_at),
|
|
229
|
+
meta: _nullishCoalesce(r.meta, () => ( void 0))
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async save(userId, docId, record) {
|
|
233
|
+
await this.db.query(
|
|
234
|
+
`INSERT INTO "${this.table}" (user_id, doc_id, version, accepted_at, meta)
|
|
235
|
+
VALUES ($1, $2, $3, $4, $5)
|
|
236
|
+
ON CONFLICT (user_id, doc_id)
|
|
237
|
+
DO UPDATE SET version = EXCLUDED.version, accepted_at = EXCLUDED.accepted_at, meta = EXCLUDED.meta`,
|
|
238
|
+
[userId, docId, record.version, record.acceptedAt, record.meta ? JSON.stringify(record.meta) : null]
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
function consentTableSql(table = "consent_acceptance") {
|
|
243
|
+
const t = assertIdent(table);
|
|
244
|
+
return `CREATE TABLE IF NOT EXISTS "${t}" (
|
|
245
|
+
user_id text NOT NULL,
|
|
246
|
+
doc_id text NOT NULL,
|
|
247
|
+
version text NOT NULL,
|
|
248
|
+
accepted_at timestamptz NOT NULL,
|
|
249
|
+
meta jsonb,
|
|
250
|
+
PRIMARY KEY (user_id, doc_id)
|
|
251
|
+
);`;
|
|
252
|
+
}
|
|
253
|
+
function assertIdent(name) {
|
|
254
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid table name: ${name}`);
|
|
255
|
+
return name;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
exports.CONSENT_OPTIONS = CONSENT_OPTIONS; exports.CONSENT_STORE = CONSENT_STORE; exports.ConsentInterceptor = ConsentInterceptor; exports.ConsentModule = ConsentModule; exports.ConsentService = ConsentService; exports.DEFAULT_CONSENT_CODE = DEFAULT_CONSENT_CODE; exports.MemoryConsentStore = MemoryConsentStore; exports.TypeOrmConsentStore = TypeOrmConsentStore; exports.compareVersions = _chunkA6YGIZCQcjs.compareVersions; exports.consentGuard = _chunkUDACUMLOcjs.guard_exports; exports.consentTableSql = consentTableSql; exports.isAcceptedVersionValid = _chunkA6YGIZCQcjs.isAcceptedVersionValid; exports.versionAceptadaVigente = _chunkA6YGIZCQcjs.versionAceptadaVigente;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { ConsentModule } from './consent.module.js';
|
|
2
|
+
export { ConsentService } from './consent.service.js';
|
|
3
|
+
export type { ConsentAudit } from './consent.service.js';
|
|
4
|
+
export { ConsentInterceptor } from './consent.interceptor.js';
|
|
5
|
+
export { CONSENT_OPTIONS, DEFAULT_CONSENT_CODE } from './consent.options.js';
|
|
6
|
+
export type { ConsentOptions, ConsentDocument } from './consent.options.js';
|
|
7
|
+
export { CONSENT_STORE } from './consent.port.js';
|
|
8
|
+
export type { ConsentStore, ConsentRecord } from './consent.port.js';
|
|
9
|
+
export { MemoryConsentStore } from './memory.store.js';
|
|
10
|
+
export { TypeOrmConsentStore, consentTableSql } from './typeorm.store.js';
|
|
11
|
+
export type { SqlRunner, TypeOrmConsentStoreOptions } from './typeorm.store.js';
|
|
12
|
+
export { versionAceptadaVigente, isAcceptedVersionValid, compareVersions } from './shared/index.js';
|
|
13
|
+
export * as consentGuard from './guard/index.js';
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import {
|
|
2
|
+
guard_exports
|
|
3
|
+
} from "../chunk-A7FI6HXV.js";
|
|
4
|
+
import {
|
|
5
|
+
compareVersions,
|
|
6
|
+
isAcceptedVersionValid,
|
|
7
|
+
versionAceptadaVigente
|
|
8
|
+
} from "../chunk-3TUMVLPJ.js";
|
|
9
|
+
import {
|
|
10
|
+
AuditService
|
|
11
|
+
} from "../chunk-NJYLQDB3.js";
|
|
12
|
+
import "../chunk-ETRUVZTJ.js";
|
|
13
|
+
import {
|
|
14
|
+
ForbiddenAppException,
|
|
15
|
+
ValidationAppException
|
|
16
|
+
} from "../chunk-ZFIDAX7K.js";
|
|
17
|
+
import "../chunk-M3GQDRWR.js";
|
|
18
|
+
import "../chunk-VVMRZEIW.js";
|
|
19
|
+
import {
|
|
20
|
+
__decorateClass,
|
|
21
|
+
__decorateParam
|
|
22
|
+
} from "../chunk-D3DDJWUD.js";
|
|
23
|
+
|
|
24
|
+
// src/consent/consent.module.ts
|
|
25
|
+
import { Global, Module } from "@nestjs/common";
|
|
26
|
+
|
|
27
|
+
// src/consent/consent.interceptor.ts
|
|
28
|
+
import {
|
|
29
|
+
Inject as Inject2,
|
|
30
|
+
Injectable as Injectable2
|
|
31
|
+
} from "@nestjs/common";
|
|
32
|
+
|
|
33
|
+
// src/consent/consent.options.ts
|
|
34
|
+
var CONSENT_OPTIONS = /* @__PURE__ */ Symbol("CONSENT_OPTIONS");
|
|
35
|
+
var DEFAULT_CONSENT_CODE = "CONSENT_PENDIENTE";
|
|
36
|
+
var DEFAULT_CONSENT_TTL_MS = 6e4;
|
|
37
|
+
var DEFAULT_CONSENT_TEXT = "Antes de continuar acepta los documentos legales vigentes.";
|
|
38
|
+
|
|
39
|
+
// src/consent/consent.service.ts
|
|
40
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
41
|
+
|
|
42
|
+
// src/consent/consent.port.ts
|
|
43
|
+
var CONSENT_STORE = /* @__PURE__ */ Symbol("CONSENT_STORE");
|
|
44
|
+
|
|
45
|
+
// src/consent/consent.service.ts
|
|
46
|
+
var ConsentService = class {
|
|
47
|
+
constructor(options, store, audit) {
|
|
48
|
+
this.options = options;
|
|
49
|
+
this.store = store;
|
|
50
|
+
this.audit = audit;
|
|
51
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
52
|
+
}
|
|
53
|
+
now() {
|
|
54
|
+
return (this.options.now ?? Date.now)();
|
|
55
|
+
}
|
|
56
|
+
ttl() {
|
|
57
|
+
return this.options.ttlCache ?? DEFAULT_CONSENT_TTL_MS;
|
|
58
|
+
}
|
|
59
|
+
doc(docId) {
|
|
60
|
+
const d = this.options.documentos.find((x) => x.id === docId);
|
|
61
|
+
if (!d) throw new ValidationAppException(`Unknown consent document: ${docId}`);
|
|
62
|
+
return d;
|
|
63
|
+
}
|
|
64
|
+
remember(userId, docId, version) {
|
|
65
|
+
if (this.ttl() > 0) this.cache.set(`${userId}\0${docId}`, { version, until: this.now() + this.ttl() });
|
|
66
|
+
}
|
|
67
|
+
/** Accepted version of one document (cached), or `null`. */
|
|
68
|
+
async acceptedVersion(userId, docId) {
|
|
69
|
+
const key = `${userId}\0${docId}`;
|
|
70
|
+
const hit = this.cache.get(key);
|
|
71
|
+
if (hit && hit.until > this.now()) return hit.version;
|
|
72
|
+
const version = (await this.store.get(userId, docId))?.version ?? null;
|
|
73
|
+
this.remember(userId, docId, version);
|
|
74
|
+
return version;
|
|
75
|
+
}
|
|
76
|
+
/** Pure check over a version: at or above the document's minimum. */
|
|
77
|
+
isValid(docId, version) {
|
|
78
|
+
return versionAceptadaVigente(version, this.doc(docId).minima);
|
|
79
|
+
}
|
|
80
|
+
/** Ids of the documents the user has not accepted at the minimum version. */
|
|
81
|
+
async pending(userId) {
|
|
82
|
+
const out = [];
|
|
83
|
+
for (const d of this.options.documentos) {
|
|
84
|
+
if (!this.isValid(d.id, await this.acceptedVersion(userId, d.id))) out.push(d.id);
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** True when every document is accepted at >= its minimum. */
|
|
89
|
+
async hasAccepted(userId) {
|
|
90
|
+
return (await this.pending(userId)).length === 0;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Records the acceptance of the **current** version. Idempotent: if that
|
|
94
|
+
* version is already stored, the original receipt (date included) is kept
|
|
95
|
+
* and nothing is audited again.
|
|
96
|
+
*/
|
|
97
|
+
async accept(userId, docId, meta) {
|
|
98
|
+
const d = this.doc(docId);
|
|
99
|
+
const previous = await this.store.get(userId, docId);
|
|
100
|
+
if (previous && previous.version === d.version) {
|
|
101
|
+
this.remember(userId, docId, d.version);
|
|
102
|
+
return previous;
|
|
103
|
+
}
|
|
104
|
+
const record = { version: d.version, acceptedAt: new Date(this.now()), meta };
|
|
105
|
+
await this.store.save(userId, docId, record);
|
|
106
|
+
this.remember(userId, docId, d.version);
|
|
107
|
+
await this.audit?.record({
|
|
108
|
+
action: "consent.accepted",
|
|
109
|
+
resource: docId,
|
|
110
|
+
resourceId: userId,
|
|
111
|
+
after: { version: d.version },
|
|
112
|
+
metadata: meta
|
|
113
|
+
});
|
|
114
|
+
return record;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
ConsentService = __decorateClass([
|
|
118
|
+
Injectable(),
|
|
119
|
+
__decorateParam(0, Inject(CONSENT_OPTIONS)),
|
|
120
|
+
__decorateParam(1, Inject(CONSENT_STORE)),
|
|
121
|
+
__decorateParam(2, Optional()),
|
|
122
|
+
__decorateParam(2, Inject(AuditService))
|
|
123
|
+
], ConsentService);
|
|
124
|
+
|
|
125
|
+
// src/consent/consent.interceptor.ts
|
|
126
|
+
var ConsentInterceptor = class {
|
|
127
|
+
constructor(options, consent) {
|
|
128
|
+
this.options = options;
|
|
129
|
+
this.consent = consent;
|
|
130
|
+
}
|
|
131
|
+
async intercept(ctx, next) {
|
|
132
|
+
const req = ctx.switchToHttp().getRequest();
|
|
133
|
+
const userId = this.options.getUserId ? this.options.getUserId(req) : req?.user?.sub;
|
|
134
|
+
if (userId) {
|
|
135
|
+
const path = req.path ?? String(req.url ?? "").split("?")[0];
|
|
136
|
+
const free = (this.options.rutasLibres ?? []).some((r) => r.test(path));
|
|
137
|
+
if (!free) {
|
|
138
|
+
const pending = await this.consent.pending(userId);
|
|
139
|
+
if (pending.length > 0) {
|
|
140
|
+
const docs = this.options.documentos.filter((d) => pending.includes(d.id));
|
|
141
|
+
throw new ForbiddenAppException(
|
|
142
|
+
this.options.textoError ?? DEFAULT_CONSENT_TEXT,
|
|
143
|
+
{
|
|
144
|
+
pendientes: pending,
|
|
145
|
+
version: docs[0]?.version,
|
|
146
|
+
versiones: Object.fromEntries(docs.map((d) => [d.id, d.version]))
|
|
147
|
+
},
|
|
148
|
+
this.options.codigoError ?? DEFAULT_CONSENT_CODE
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return next.handle();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
ConsentInterceptor = __decorateClass([
|
|
157
|
+
Injectable2(),
|
|
158
|
+
__decorateParam(0, Inject2(CONSENT_OPTIONS))
|
|
159
|
+
], ConsentInterceptor);
|
|
160
|
+
|
|
161
|
+
// src/consent/memory.store.ts
|
|
162
|
+
var MemoryConsentStore = class {
|
|
163
|
+
constructor() {
|
|
164
|
+
this.rows = /* @__PURE__ */ new Map();
|
|
165
|
+
}
|
|
166
|
+
async get(userId, docId) {
|
|
167
|
+
return this.rows.get(`${userId}\0${docId}`) ?? null;
|
|
168
|
+
}
|
|
169
|
+
async save(userId, docId, record) {
|
|
170
|
+
this.rows.set(`${userId}\0${docId}`, record);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// src/consent/consent.module.ts
|
|
175
|
+
var ConsentModule = class {
|
|
176
|
+
static forRoot(options) {
|
|
177
|
+
const providers = [
|
|
178
|
+
{ provide: CONSENT_OPTIONS, useValue: options },
|
|
179
|
+
{ provide: CONSENT_STORE, useValue: options.puertoDeAceptaciones ?? new MemoryConsentStore() },
|
|
180
|
+
ConsentService,
|
|
181
|
+
ConsentInterceptor
|
|
182
|
+
];
|
|
183
|
+
return {
|
|
184
|
+
module: ConsentModule,
|
|
185
|
+
providers,
|
|
186
|
+
exports: [CONSENT_OPTIONS, CONSENT_STORE, ConsentService, ConsentInterceptor]
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
static forRootAsync(config) {
|
|
190
|
+
const providers = [
|
|
191
|
+
{ provide: CONSENT_OPTIONS, useFactory: config.useFactory, inject: config.inject ?? [] },
|
|
192
|
+
{
|
|
193
|
+
provide: CONSENT_STORE,
|
|
194
|
+
useFactory: (o) => o.puertoDeAceptaciones ?? new MemoryConsentStore(),
|
|
195
|
+
inject: [CONSENT_OPTIONS]
|
|
196
|
+
},
|
|
197
|
+
ConsentService,
|
|
198
|
+
ConsentInterceptor
|
|
199
|
+
];
|
|
200
|
+
return {
|
|
201
|
+
module: ConsentModule,
|
|
202
|
+
imports: config.imports ?? [],
|
|
203
|
+
providers,
|
|
204
|
+
exports: [CONSENT_OPTIONS, CONSENT_STORE, ConsentService, ConsentInterceptor]
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
ConsentModule = __decorateClass([
|
|
209
|
+
Global(),
|
|
210
|
+
Module({})
|
|
211
|
+
], ConsentModule);
|
|
212
|
+
|
|
213
|
+
// src/consent/typeorm.store.ts
|
|
214
|
+
var TypeOrmConsentStore = class {
|
|
215
|
+
constructor(db, options = {}) {
|
|
216
|
+
this.db = db;
|
|
217
|
+
this.table = assertIdent(options.table ?? "consent_acceptance");
|
|
218
|
+
}
|
|
219
|
+
async get(userId, docId) {
|
|
220
|
+
const rows = await this.db.query(
|
|
221
|
+
`SELECT version, accepted_at, meta FROM "${this.table}" WHERE user_id = $1 AND doc_id = $2 LIMIT 1`,
|
|
222
|
+
[userId, docId]
|
|
223
|
+
);
|
|
224
|
+
const r = Array.isArray(rows) ? rows[0] : rows?.rows?.[0];
|
|
225
|
+
if (!r) return null;
|
|
226
|
+
return {
|
|
227
|
+
version: r.version,
|
|
228
|
+
acceptedAt: r.accepted_at instanceof Date ? r.accepted_at : new Date(r.accepted_at),
|
|
229
|
+
meta: r.meta ?? void 0
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
async save(userId, docId, record) {
|
|
233
|
+
await this.db.query(
|
|
234
|
+
`INSERT INTO "${this.table}" (user_id, doc_id, version, accepted_at, meta)
|
|
235
|
+
VALUES ($1, $2, $3, $4, $5)
|
|
236
|
+
ON CONFLICT (user_id, doc_id)
|
|
237
|
+
DO UPDATE SET version = EXCLUDED.version, accepted_at = EXCLUDED.accepted_at, meta = EXCLUDED.meta`,
|
|
238
|
+
[userId, docId, record.version, record.acceptedAt, record.meta ? JSON.stringify(record.meta) : null]
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
function consentTableSql(table = "consent_acceptance") {
|
|
243
|
+
const t = assertIdent(table);
|
|
244
|
+
return `CREATE TABLE IF NOT EXISTS "${t}" (
|
|
245
|
+
user_id text NOT NULL,
|
|
246
|
+
doc_id text NOT NULL,
|
|
247
|
+
version text NOT NULL,
|
|
248
|
+
accepted_at timestamptz NOT NULL,
|
|
249
|
+
meta jsonb,
|
|
250
|
+
PRIMARY KEY (user_id, doc_id)
|
|
251
|
+
);`;
|
|
252
|
+
}
|
|
253
|
+
function assertIdent(name) {
|
|
254
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`Invalid table name: ${name}`);
|
|
255
|
+
return name;
|
|
256
|
+
}
|
|
257
|
+
export {
|
|
258
|
+
CONSENT_OPTIONS,
|
|
259
|
+
CONSENT_STORE,
|
|
260
|
+
ConsentInterceptor,
|
|
261
|
+
ConsentModule,
|
|
262
|
+
ConsentService,
|
|
263
|
+
DEFAULT_CONSENT_CODE,
|
|
264
|
+
MemoryConsentStore,
|
|
265
|
+
TypeOrmConsentStore,
|
|
266
|
+
compareVersions,
|
|
267
|
+
guard_exports as consentGuard,
|
|
268
|
+
consentTableSql,
|
|
269
|
+
isAcceptedVersionValid,
|
|
270
|
+
versionAceptadaVigente
|
|
271
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ConsentRecord, ConsentStore } from './consent.port.js';
|
|
2
|
+
/** In-process store: fine for tests and a single instance, lost on restart. */
|
|
3
|
+
export declare class MemoryConsentStore implements ConsentStore {
|
|
4
|
+
private readonly rows;
|
|
5
|
+
get(userId: string, docId: string): Promise<ConsentRecord | null>;
|
|
6
|
+
save(userId: string, docId: string, record: ConsentRecord): Promise<void>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkA6YGIZCQcjs = require('../../chunk-A6YGIZCQ.cjs');
|
|
6
|
+
require('../../chunk-LRX7AMSS.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.compareVersions = _chunkA6YGIZCQcjs.compareVersions; exports.isAcceptedVersionValid = _chunkA6YGIZCQcjs.isAcceptedVersionValid; exports.versionAceptadaVigente = _chunkA6YGIZCQcjs.versionAceptadaVigente;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency-free helpers, safe to import from a browser, a React app or a
|
|
3
|
+
* script (`@miguelmorales13/nestkit/consent/shared`). Nothing here touches Nest.
|
|
4
|
+
*
|
|
5
|
+
* Versions are ISO dates (`2026-10-15`), so lexicographic order is chronological
|
|
6
|
+
* order and they are compared as text.
|
|
7
|
+
*/
|
|
8
|
+
/** `-1 | 0 | 1` comparing two version strings as text. */
|
|
9
|
+
export declare function compareVersions(a: string, b: string): -1 | 0 | 1;
|
|
10
|
+
/**
|
|
11
|
+
* Is the accepted version still good? True when it is at or above the
|
|
12
|
+
* **minimum**. The minimum, not the current version, is what blocks: raising the
|
|
13
|
+
* current version for a minor wording change must not lock out clients that
|
|
14
|
+
* ship the older text and cannot render a new acceptance screen (the web in
|
|
15
|
+
* cache, an installed mobile app).
|
|
16
|
+
*/
|
|
17
|
+
export declare function versionAceptadaVigente(version: string | null | undefined, minima: string): boolean;
|
|
18
|
+
/** English alias of {@link versionAceptadaVigente}. */
|
|
19
|
+
export declare const isAcceptedVersionValid: typeof versionAceptadaVigente;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ConsentRecord, ConsentStore } from './consent.port.js';
|
|
2
|
+
/** The slice of a TypeORM `DataSource` (or any pg-like client) this store needs. */
|
|
3
|
+
export interface SqlRunner {
|
|
4
|
+
query(sql: string, params?: unknown[]): Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
export interface TypeOrmConsentStoreOptions {
|
|
7
|
+
/** Table name. Defaults to `consent_acceptance`. Letters, digits and `_` only (it is interpolated). */
|
|
8
|
+
table?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Postgres store over any `{ query(sql, params) }` (a TypeORM `DataSource` fits).
|
|
12
|
+
* One row per (user, document), upserted. Create the table with {@link consentTableSql}.
|
|
13
|
+
*/
|
|
14
|
+
export declare class TypeOrmConsentStore implements ConsentStore {
|
|
15
|
+
private readonly db;
|
|
16
|
+
private readonly table;
|
|
17
|
+
constructor(db: SqlRunner, options?: TypeOrmConsentStoreOptions);
|
|
18
|
+
get(userId: string, docId: string): Promise<ConsentRecord | null>;
|
|
19
|
+
save(userId: string, docId: string, record: ConsentRecord): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/** DDL for the table, to paste into a migration. */
|
|
22
|
+
export declare function consentTableSql(table?: string): string;
|