@miguelmorales13/nestkit 0.26.0 → 0.28.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/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-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-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 +19 -18
- package/dist/index.js +32 -31
- 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/index.cjs +7 -7
- package/dist/payments/index.js +1 -1
- 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 +119 -2
- package/dist/security/index.d.ts +5 -0
- package/dist/security/index.js +119 -2
- 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 +107 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DeletionRequestStorePort } from './privacy.port.js';
|
|
2
|
+
import type { DeletionRequest, RuleProgress, Subject } from './privacy.types.js';
|
|
3
|
+
/** In-process store: single instance, lost on restart. For tests and prototypes. */
|
|
4
|
+
export declare class MemoryDeletionStore implements DeletionRequestStorePort {
|
|
5
|
+
readonly requests: Map<string, DeletionRequest>;
|
|
6
|
+
private readonly leases;
|
|
7
|
+
create(request: DeletionRequest): Promise<void>;
|
|
8
|
+
get(id: string): Promise<DeletionRequest | null>;
|
|
9
|
+
findOpen(subject: Subject): Promise<DeletionRequest | null>;
|
|
10
|
+
private isDue;
|
|
11
|
+
listDue(now: Date, limit: number, maxAttempts: number): Promise<DeletionRequest[]>;
|
|
12
|
+
claim(id: string, now: Date, leaseMs: number, maxAttempts: number): Promise<DeletionRequest | null>;
|
|
13
|
+
saveProgress(id: string, rule: string, progress: RuleProgress): Promise<void>;
|
|
14
|
+
finish(id: string, patch: Parameters<DeletionRequestStorePort['finish']>[1]): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { type PrivacyOptions } from './privacy.options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Right to erasure and data export (LFPDPPP / GDPR).
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* PrivacyModule.forRoot({
|
|
8
|
+
* db: dataSource,
|
|
9
|
+
* graceDays: 30,
|
|
10
|
+
* runner: 'cron',
|
|
11
|
+
* store: new SqlDeletionRequestStore(dataSource),
|
|
12
|
+
* registry: {
|
|
13
|
+
* person: [
|
|
14
|
+
* { table: 'push_device', action: 'delete', where: 'user_id = $1' },
|
|
15
|
+
* { table: 'account', action: 'anonymize', where: 'id = $1', requires: ['push_device'],
|
|
16
|
+
* columns: { email: { hash: { suffix: '@anon.invalid' } }, name: 'null' } },
|
|
17
|
+
* ],
|
|
18
|
+
* },
|
|
19
|
+
* onDone: (req) => mailer.send(...),
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare class PrivacyModule {
|
|
24
|
+
static forRoot(options: PrivacyOptions): DynamicModule;
|
|
25
|
+
static forRootAsync(config: {
|
|
26
|
+
imports?: any[];
|
|
27
|
+
inject?: any[];
|
|
28
|
+
useFactory: (...args: any[]) => PrivacyOptions | Promise<PrivacyOptions>;
|
|
29
|
+
}): DynamicModule;
|
|
30
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DeletionRequestStorePort } from './privacy.port.js';
|
|
2
|
+
import type { DeletionRequest, PrivacyAudit, RetentionRule, SqlClient, TableRegistry } from './privacy.types.js';
|
|
3
|
+
export declare const PRIVACY_OPTIONS: unique symbol;
|
|
4
|
+
export interface PrivacyOptions {
|
|
5
|
+
/** SQL client the rules run on (a TypeORM `DataSource` fits). */
|
|
6
|
+
db: SqlClient;
|
|
7
|
+
/** What to erase or anonymize, per subject type, with its dependency order. */
|
|
8
|
+
registry: TableRegistry;
|
|
9
|
+
/** Where requests live. Defaults to an in-process store (lost on restart): use `SqlDeletionRequestStore`. */
|
|
10
|
+
store?: DeletionRequestStorePort;
|
|
11
|
+
/** Days between the request and the erasure, during which it can be cancelled. Defaults to 30. */
|
|
12
|
+
graceDays?: number;
|
|
13
|
+
/** `cron`: the module polls `runDue()` itself. `manual`: you call it (your own scheduler). Defaults to `manual`. */
|
|
14
|
+
runner?: 'cron' | 'manual';
|
|
15
|
+
/** Polling period for `runner: 'cron'`, ms. Defaults to 1 hour. */
|
|
16
|
+
intervalMs?: number;
|
|
17
|
+
/** Requests handled per pass. Defaults to 25. */
|
|
18
|
+
batchSize?: number;
|
|
19
|
+
/** A claimed request is held this long; a crashed worker's claim expires after it. Defaults to 10 minutes. */
|
|
20
|
+
leaseMs?: number;
|
|
21
|
+
/** After this many failed passes the request stops being retried and `onFailed` fires. Defaults to 10. */
|
|
22
|
+
maxAttempts?: number;
|
|
23
|
+
/** Rows per page when exporting or anonymizing row by row. Defaults to 500. */
|
|
24
|
+
pageSize?: number;
|
|
25
|
+
/** Secret salt for `hash` strategies. Without it hashes are unkeyed. */
|
|
26
|
+
anonymizeSalt?: string;
|
|
27
|
+
/** Called once when every step of a request is done. A throw is logged and does not undo the erasure. */
|
|
28
|
+
onDone?: (request: DeletionRequest) => void | Promise<void>;
|
|
29
|
+
/** Called when a request exhausts `maxAttempts`: page a human. */
|
|
30
|
+
onFailed?: (request: DeletionRequest) => void | Promise<void>;
|
|
31
|
+
/** Data that expires by age (not tied to a request). Swept by `runRetention()` and by the cron runner. */
|
|
32
|
+
retention?: RetentionRule[];
|
|
33
|
+
/** Audit sink (the real `AuditService` fits). Events carry ids and counts, never content. */
|
|
34
|
+
audit?: PrivacyAudit;
|
|
35
|
+
/** Clock, for tests. */
|
|
36
|
+
now?: () => Date;
|
|
37
|
+
}
|
|
38
|
+
export declare const DEFAULT_GRACE_DAYS = 30;
|
|
39
|
+
export declare const DEFAULT_INTERVAL_MS = 3600000;
|
|
40
|
+
export declare const DEFAULT_BATCH_SIZE = 25;
|
|
41
|
+
export declare const DEFAULT_LEASE_MS = 600000;
|
|
42
|
+
export declare const DEFAULT_MAX_ATTEMPTS = 10;
|
|
43
|
+
export declare const DEFAULT_PAGE_SIZE = 500;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DeletionRequest, RuleProgress, Subject } from './privacy.types.js';
|
|
2
|
+
export declare const PRIVACY_STORE: unique symbol;
|
|
3
|
+
/**
|
|
4
|
+
* Where deletion requests (and their progress) live. The library keeps nothing itself:
|
|
5
|
+
* the record of what was erased belongs in the consumer's database.
|
|
6
|
+
*/
|
|
7
|
+
export interface DeletionRequestStorePort {
|
|
8
|
+
create(request: DeletionRequest): Promise<void>;
|
|
9
|
+
get(id: string): Promise<DeletionRequest | null>;
|
|
10
|
+
/** The request of this subject that is not `done`/`cancelled`, if any. */
|
|
11
|
+
findOpen(subject: Subject): Promise<DeletionRequest | null>;
|
|
12
|
+
/**
|
|
13
|
+
* Pending requests past `dueAt`, failed ones past `nextAttemptAt` that still have attempts left
|
|
14
|
+
* (`attempts < maxAttempts`), and `running` ones whose lease expired. Oldest first.
|
|
15
|
+
*/
|
|
16
|
+
listDue(now: Date, limit: number, maxAttempts: number): Promise<DeletionRequest[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Atomically take the request for `leaseMs` (status → `running`). `null` if someone else holds it or it
|
|
19
|
+
* is no longer due. A crashed worker's lease simply expires.
|
|
20
|
+
*/
|
|
21
|
+
claim(id: string, now: Date, leaseMs: number, maxAttempts: number): Promise<DeletionRequest | null>;
|
|
22
|
+
saveProgress(id: string, rule: string, progress: RuleProgress): Promise<void>;
|
|
23
|
+
/** Close a pass: `done`, `failed` (with `nextAttemptAt`) or `cancelled`. */
|
|
24
|
+
finish(id: string, patch: Pick<DeletionRequest, 'status'> & Partial<Pick<DeletionRequest, 'lastError' | 'nextAttemptAt' | 'completedAt' | 'attempts'>>): Promise<void>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Readable } from 'node:stream';
|
|
2
|
+
import type { Writable } from 'node:stream';
|
|
3
|
+
import { type OnModuleDestroy, type OnModuleInit } from '@nestjs/common';
|
|
4
|
+
import { type PrivacyOptions } from './privacy.options.js';
|
|
5
|
+
import { type DeletionRequestStorePort } from './privacy.port.js';
|
|
6
|
+
import type { DeletionRequest, RunReport, Subject, TableRule } from './privacy.types.js';
|
|
7
|
+
type Planned = TableRule & {
|
|
8
|
+
name: string;
|
|
9
|
+
};
|
|
10
|
+
/** Validate the registry and order every subject type's rules so `requires` always come first. */
|
|
11
|
+
export declare function planRegistry(registry: PrivacyOptions['registry']): Map<string, Planned[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Right to erasure and to a copy of your data.
|
|
14
|
+
*
|
|
15
|
+
* - `requestDeletion` records the request and starts the grace period; `cancel` undoes it while nothing has been erased.
|
|
16
|
+
* - `runDue` erases what is due, step by step in dependency order. Each step's result is persisted, so a
|
|
17
|
+
* failure only repeats the steps that did not finish (with backoff); steps that finished never run twice.
|
|
18
|
+
* - `exportStream` streams a ZIP of the subject's data without holding it in memory.
|
|
19
|
+
*/
|
|
20
|
+
export declare class PrivacyService implements OnModuleInit, OnModuleDestroy {
|
|
21
|
+
private readonly options;
|
|
22
|
+
private readonly store;
|
|
23
|
+
private readonly log;
|
|
24
|
+
private readonly plans;
|
|
25
|
+
private readonly anonymizer;
|
|
26
|
+
private timer?;
|
|
27
|
+
private running;
|
|
28
|
+
constructor(options: PrivacyOptions, store: DeletionRequestStorePort);
|
|
29
|
+
onModuleInit(): void;
|
|
30
|
+
onModuleDestroy(): void;
|
|
31
|
+
private now;
|
|
32
|
+
private audit;
|
|
33
|
+
/** Idempotent: a subject with an open request gets that one back (`created: false`). */
|
|
34
|
+
requestDeletion(subject: Subject, opts?: {
|
|
35
|
+
reason?: string;
|
|
36
|
+
}): Promise<{
|
|
37
|
+
request: DeletionRequest;
|
|
38
|
+
created: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Cancel by request id or by subject. Only while nothing has been erased: once a step finished the erasure is
|
|
42
|
+
* irreversible and cancelling is refused (`reason: 'irreversible'`).
|
|
43
|
+
*/
|
|
44
|
+
cancel(ref: string | Subject): Promise<{
|
|
45
|
+
cancelled: boolean;
|
|
46
|
+
reason?: 'not_found' | 'running' | 'irreversible' | 'closed';
|
|
47
|
+
request?: DeletionRequest;
|
|
48
|
+
}>;
|
|
49
|
+
/** The open request of a subject (pending, running or failed), if any. */
|
|
50
|
+
status(subject: Subject): Promise<DeletionRequest | null>;
|
|
51
|
+
/** A request with its step-by-step progress: what was erased or anonymized, and how many rows. The audit trail. */
|
|
52
|
+
report(id: string): Promise<DeletionRequest | null>;
|
|
53
|
+
/** Process every due request. Safe to call from several instances and to call again after a crash. */
|
|
54
|
+
runDue(): Promise<RunReport[]>;
|
|
55
|
+
private process;
|
|
56
|
+
private runRule;
|
|
57
|
+
private execRule;
|
|
58
|
+
/** Delete data that outlived its retention period. A failing rule does not stop the others. */
|
|
59
|
+
runRetention(): Promise<Record<string, number>>;
|
|
60
|
+
/**
|
|
61
|
+
* ZIP of the subject's data: `<step>/part-0001.json`… (one file per page of rows), extra files of each rule, and a
|
|
62
|
+
* `manifest.json`. Built entry by entry as a stream, so memory is bounded by `pageSize`, not by the data.
|
|
63
|
+
*/
|
|
64
|
+
exportStream(subject: Subject): Readable;
|
|
65
|
+
/** Pipe the export into any writable (an HTTP response, a file, an upload). Resolves when it is flushed. */
|
|
66
|
+
exportTo(subject: Subject, out: Writable): Promise<void>;
|
|
67
|
+
private exportChunks;
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** The slice of a SQL client the module needs. A TypeORM `DataSource` / `EntityManager` fits as is. */
|
|
2
|
+
export interface SqlClient {
|
|
3
|
+
query(sql: string, params?: unknown[]): Promise<any>;
|
|
4
|
+
/** Optional. When present, each rule runs in its own transaction (all or nothing per table). */
|
|
5
|
+
transaction?<T>(fn: (tx: SqlClient) => Promise<T>): Promise<T>;
|
|
6
|
+
}
|
|
7
|
+
/** Whose data: `type` picks the rule list in the registry (`tenant`, `person`…), `id` fills `$1`. */
|
|
8
|
+
export interface Subject {
|
|
9
|
+
type: string;
|
|
10
|
+
id: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What to do with one column of an anonymized row.
|
|
14
|
+
* - `'null'`: set NULL. `{ value }`: set a constant. Both run as one idempotent UPDATE.
|
|
15
|
+
* - `'hash'` / `{ hash }`: one-way keyed hash, idempotent (already-hashed values are left alone).
|
|
16
|
+
* - `'mask'` / `{ mask }`: keep the ends, hide the middle.
|
|
17
|
+
* - a function: full control; receives the current value and the whole row.
|
|
18
|
+
*/
|
|
19
|
+
export type ColumnStrategy = 'null' | 'hash' | 'mask' | {
|
|
20
|
+
value: unknown;
|
|
21
|
+
} | {
|
|
22
|
+
hash: HashOptions;
|
|
23
|
+
} | {
|
|
24
|
+
mask: MaskOptions;
|
|
25
|
+
} | ((value: unknown, row: Record<string, unknown>) => unknown);
|
|
26
|
+
export interface HashOptions {
|
|
27
|
+
/** Prefix of the result; also how an already-hashed value is recognised. Defaults to `anon_`. */
|
|
28
|
+
prefix?: string;
|
|
29
|
+
/** Appended after the hash, e.g. `@anon.invalid` to keep the column shaped like an e-mail. */
|
|
30
|
+
suffix?: string;
|
|
31
|
+
/** Hex characters kept. Defaults to 24. */
|
|
32
|
+
length?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface MaskOptions {
|
|
35
|
+
keepStart?: number;
|
|
36
|
+
keepEnd?: number;
|
|
37
|
+
char?: string;
|
|
38
|
+
/** Mask only the local part of an e-mail and keep the domain. */
|
|
39
|
+
email?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface ExportSpec {
|
|
42
|
+
/** Columns to export. Defaults to every column except `exclude`. */
|
|
43
|
+
columns?: string[];
|
|
44
|
+
/** Columns that never leave (password hashes, secrets). */
|
|
45
|
+
exclude?: string[];
|
|
46
|
+
/** Extra files for this rule (objects in a bucket…). Yielded as they are read: nothing is held. */
|
|
47
|
+
files?: (subject: Subject) => AsyncIterable<{
|
|
48
|
+
name: string;
|
|
49
|
+
content: Buffer | Uint8Array;
|
|
50
|
+
}>;
|
|
51
|
+
}
|
|
52
|
+
/** One step of the erasure of a subject. */
|
|
53
|
+
export interface TableRule {
|
|
54
|
+
/** Unique within the subject type. Defaults to `table`. Names the step in progress and audit. */
|
|
55
|
+
name?: string;
|
|
56
|
+
/** Table name. Letters, digits and `_` (optionally `schema.table`): it is interpolated. */
|
|
57
|
+
table?: string;
|
|
58
|
+
/** `delete` removes the rows; `anonymize` keeps them and rewrites `columns`; `custom` runs `run`. */
|
|
59
|
+
action: 'delete' | 'anonymize' | 'custom';
|
|
60
|
+
/** WHERE clause (code you wrote, not user input). `$1` is the subject id. Defaults to none for `custom`. */
|
|
61
|
+
where?: string;
|
|
62
|
+
/** For `anonymize`: column → strategy. */
|
|
63
|
+
columns?: Record<string, ColumnStrategy>;
|
|
64
|
+
/** Primary key used to page through rows. Defaults to `id`. */
|
|
65
|
+
pk?: string;
|
|
66
|
+
/** Names of rules that must finish first (usually the child tables that reference this one). */
|
|
67
|
+
requires?: string[];
|
|
68
|
+
/** For `custom`: do the work (files, third parties…) and return how many items it touched. Must be idempotent. */
|
|
69
|
+
run?: (tx: SqlClient, subject: Subject) => Promise<number>;
|
|
70
|
+
/** Included in the export unless `false`. Defaults to on for `delete`/`anonymize` with a `table`. */
|
|
71
|
+
export?: ExportSpec | false;
|
|
72
|
+
}
|
|
73
|
+
/** Rules per subject type. */
|
|
74
|
+
export type TableRegistry = Record<string, TableRule[]>;
|
|
75
|
+
export type RequestStatus = 'pending' | 'running' | 'done' | 'failed' | 'cancelled';
|
|
76
|
+
export interface RuleProgress {
|
|
77
|
+
done: boolean;
|
|
78
|
+
/** Rows deleted / rewritten (a count, never content). */
|
|
79
|
+
rows: number;
|
|
80
|
+
attempts: number;
|
|
81
|
+
error?: string;
|
|
82
|
+
at?: Date;
|
|
83
|
+
}
|
|
84
|
+
export interface DeletionRequest {
|
|
85
|
+
id: string;
|
|
86
|
+
subject: Subject;
|
|
87
|
+
reason?: string;
|
|
88
|
+
status: RequestStatus;
|
|
89
|
+
requestedAt: Date;
|
|
90
|
+
/** Nothing is erased before this moment. */
|
|
91
|
+
dueAt: Date;
|
|
92
|
+
attempts: number;
|
|
93
|
+
lastError?: string;
|
|
94
|
+
/** Failed requests are retried from this moment on. */
|
|
95
|
+
nextAttemptAt?: Date;
|
|
96
|
+
/** What was erased or anonymized, step by step: the audit trail. */
|
|
97
|
+
progress: Record<string, RuleProgress>;
|
|
98
|
+
completedAt?: Date;
|
|
99
|
+
}
|
|
100
|
+
export interface RetentionRule {
|
|
101
|
+
name: string;
|
|
102
|
+
table: string;
|
|
103
|
+
/** Timestamp column compared against the cutoff. */
|
|
104
|
+
column: string;
|
|
105
|
+
maxAgeDays: number;
|
|
106
|
+
/** Extra condition (code you wrote). */
|
|
107
|
+
where?: string;
|
|
108
|
+
}
|
|
109
|
+
export interface RunReport {
|
|
110
|
+
requestId: string;
|
|
111
|
+
subject: Subject;
|
|
112
|
+
status: RequestStatus;
|
|
113
|
+
/** Rows touched in this pass, by step. */
|
|
114
|
+
rows: Record<string, number>;
|
|
115
|
+
failed: string[];
|
|
116
|
+
}
|
|
117
|
+
/** Anything with `record(event)`: the real `AuditService`, or a stub. */
|
|
118
|
+
export interface PrivacyAudit {
|
|
119
|
+
record(event: {
|
|
120
|
+
action: string;
|
|
121
|
+
resource: string;
|
|
122
|
+
resourceId?: string;
|
|
123
|
+
metadata?: Record<string, unknown>;
|
|
124
|
+
}): Promise<unknown>;
|
|
125
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SqlClient } from './privacy.types.js';
|
|
2
|
+
/** Quote an identifier (`schema.table` allowed). Throws on anything that is not letters, digits, `_`. */
|
|
3
|
+
export declare function quoteIdent(name: string): string;
|
|
4
|
+
/** Rows of a result, whether the driver returns an array or `{ rows }`. */
|
|
5
|
+
export declare function rowsOf(result: any): Record<string, any>[];
|
|
6
|
+
/** Count rows affected by a DELETE/UPDATE body, portable across pg and TypeORM. */
|
|
7
|
+
export declare function countAffected(db: SqlClient, statement: string, params: unknown[]): Promise<number>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { DeletionRequestStorePort } from './privacy.port.js';
|
|
2
|
+
import type { DeletionRequest, RuleProgress, SqlClient, Subject } from './privacy.types.js';
|
|
3
|
+
export interface SqlDeletionRequestStoreOptions {
|
|
4
|
+
/** Table name. Defaults to `privacy_deletion_request`. */
|
|
5
|
+
table?: string;
|
|
6
|
+
}
|
|
7
|
+
/** DDL for the Postgres table behind {@link SqlDeletionRequestStore}. Run it in your migrations. */
|
|
8
|
+
export declare function privacyTableSql(table?: string): string;
|
|
9
|
+
/** Postgres store over any `{ query(sql, params) }`. Create the table with {@link privacyTableSql}. */
|
|
10
|
+
export declare class SqlDeletionRequestStore implements DeletionRequestStorePort {
|
|
11
|
+
private readonly db;
|
|
12
|
+
private readonly t;
|
|
13
|
+
constructor(db: SqlClient, options?: SqlDeletionRequestStoreOptions);
|
|
14
|
+
create(r: DeletionRequest): Promise<void>;
|
|
15
|
+
get(id: string): Promise<DeletionRequest | null>;
|
|
16
|
+
findOpen(subject: Subject): Promise<DeletionRequest | null>;
|
|
17
|
+
listDue(now: Date, limit: number, maxAttempts: number): Promise<DeletionRequest[]>;
|
|
18
|
+
claim(id: string, now: Date, leaseMs: number, maxAttempts: number): Promise<DeletionRequest | null>;
|
|
19
|
+
saveProgress(id: string, rule: string, progress: RuleProgress): Promise<void>;
|
|
20
|
+
finish(id: string, patch: Parameters<DeletionRequestStorePort['finish']>[1]): Promise<void>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ZipEntry {
|
|
2
|
+
/** Path inside the ZIP, with `/`. */
|
|
3
|
+
name: string;
|
|
4
|
+
content: Buffer;
|
|
5
|
+
date?: Date;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Minimal streaming ZIP writer (PKZIP 2.0, deflate, UTF-8 names), no dependency. `add()` returns the bytes of ONE
|
|
9
|
+
* entry to write right away and keeps only its central-directory row (~100 B); `close()` returns the central
|
|
10
|
+
* directory and the end record. No ZIP64: under 4 GB and 65 535 entries.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ZipWriter {
|
|
13
|
+
private readonly centrals;
|
|
14
|
+
private offset;
|
|
15
|
+
private entries;
|
|
16
|
+
private closed;
|
|
17
|
+
/** Bytes of the entry, ready to write; the content is not retained. */
|
|
18
|
+
add(e: ZipEntry): Buffer;
|
|
19
|
+
/** Central directory + end record: the last thing written. */
|
|
20
|
+
close(): Buffer;
|
|
21
|
+
}
|
|
22
|
+
/** The whole ZIP in memory (few small files). Same bytes as writing with `ZipWriter`. */
|
|
23
|
+
export declare function createZip(entries: ZipEntry[]): Buffer;
|
package/dist/push/index.cjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
var _chunkCU4FUIVJcjs = require('../chunk-CU4FUIVJ.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
3
7
|
var _chunkAXMW5JF7cjs = require('../chunk-AXMW5JF7.cjs');
|
|
4
8
|
require('../chunk-Y72D5L6I.cjs');
|
|
5
9
|
require('../chunk-SDWHKPXI.cjs');
|
|
@@ -8,11 +12,7 @@ require('../chunk-SDWHKPXI.cjs');
|
|
|
8
12
|
var _chunkPNK5WMPPcjs = require('../chunk-PNK5WMPP.cjs');
|
|
9
13
|
|
|
10
14
|
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
// src/push/push.port.ts
|
|
14
|
-
var PUSH = /* @__PURE__ */ Symbol("PUSH");
|
|
15
|
-
var PUSH_DEVICE_STORE = /* @__PURE__ */ Symbol("PUSH_DEVICE_STORE");
|
|
15
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
16
16
|
|
|
17
17
|
// src/push/push.options.ts
|
|
18
18
|
var PUSH_OPTIONS = /* @__PURE__ */ Symbol("PUSH_OPTIONS");
|
|
@@ -409,27 +409,27 @@ var PushModule = class {
|
|
|
409
409
|
{ provide: PUSH_OPTIONS, useValue: pushOptions },
|
|
410
410
|
...deviceStore ? [deviceStore] : [],
|
|
411
411
|
{
|
|
412
|
-
provide: PUSH,
|
|
412
|
+
provide: _chunkCU4FUIVJcjs.PUSH,
|
|
413
413
|
useFactory: (store) => new PushService(createPushChannels(pushOptions), _nullishCoalesce(store, () => ( void 0))),
|
|
414
|
-
inject: [{ token: PUSH_DEVICE_STORE, optional: true }]
|
|
414
|
+
inject: [{ token: _chunkCU4FUIVJcjs.PUSH_DEVICE_STORE, optional: true }]
|
|
415
415
|
}
|
|
416
416
|
];
|
|
417
|
-
return { module: PushModule, imports: _nullishCoalesce(imports, () => ( [])), providers, exports: [PUSH, PUSH_OPTIONS] };
|
|
417
|
+
return { module: PushModule, imports: _nullishCoalesce(imports, () => ( [])), providers, exports: [_chunkCU4FUIVJcjs.PUSH, PUSH_OPTIONS] };
|
|
418
418
|
}
|
|
419
419
|
static forRootAsync(config) {
|
|
420
420
|
const providers = [
|
|
421
421
|
{ provide: PUSH_OPTIONS, useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) },
|
|
422
422
|
...config.deviceStore ? [config.deviceStore] : [],
|
|
423
423
|
{
|
|
424
|
-
provide: PUSH,
|
|
424
|
+
provide: _chunkCU4FUIVJcjs.PUSH,
|
|
425
425
|
useFactory: (options, store) => new PushService(createPushChannels(options), _nullishCoalesce(store, () => ( void 0))),
|
|
426
|
-
inject: [PUSH_OPTIONS, { token: PUSH_DEVICE_STORE, optional: true }]
|
|
426
|
+
inject: [PUSH_OPTIONS, { token: _chunkCU4FUIVJcjs.PUSH_DEVICE_STORE, optional: true }]
|
|
427
427
|
}
|
|
428
428
|
];
|
|
429
|
-
return { module: PushModule, imports: _nullishCoalesce(config.imports, () => ( [])), providers, exports: [PUSH, PUSH_OPTIONS] };
|
|
429
|
+
return { module: PushModule, imports: _nullishCoalesce(config.imports, () => ( [])), providers, exports: [_chunkCU4FUIVJcjs.PUSH, PUSH_OPTIONS] };
|
|
430
430
|
}
|
|
431
431
|
};
|
|
432
|
-
PushModule = exports.PushModule =
|
|
432
|
+
PushModule = exports.PushModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
433
433
|
_common.Global.call(void 0, ),
|
|
434
434
|
_common.Module.call(void 0, {})
|
|
435
435
|
], PushModule);
|
|
@@ -446,4 +446,4 @@ PushModule = exports.PushModule = _chunk2REOCMUDcjs.__decorateClass.call(void 0,
|
|
|
446
446
|
|
|
447
447
|
|
|
448
448
|
|
|
449
|
-
exports.FcmChannel = FcmChannel; exports.PUSH = PUSH; exports.PUSH_DEVICE_STORE = PUSH_DEVICE_STORE; exports.PUSH_OPTIONS = PUSH_OPTIONS; exports.PushModule = PushModule; exports.PushService = PushService; exports.WebPushChannel = WebPushChannel; exports.createPushChannels = createPushChannels; exports.parseServiceAccount = parseServiceAccount; exports.resolveMessage = resolveMessage; exports.resolvePushOptions = resolvePushOptions; exports.toFcmMessage = toFcmMessage;
|
|
449
|
+
exports.FcmChannel = FcmChannel; exports.PUSH = _chunkCU4FUIVJcjs.PUSH; exports.PUSH_DEVICE_STORE = _chunkCU4FUIVJcjs.PUSH_DEVICE_STORE; exports.PUSH_OPTIONS = PUSH_OPTIONS; exports.PushModule = PushModule; exports.PushService = PushService; exports.WebPushChannel = WebPushChannel; exports.createPushChannels = createPushChannels; exports.parseServiceAccount = parseServiceAccount; exports.resolveMessage = resolveMessage; exports.resolvePushOptions = resolvePushOptions; exports.toFcmMessage = toFcmMessage;
|
package/dist/push/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PUSH,
|
|
3
|
+
PUSH_DEVICE_STORE
|
|
4
|
+
} from "../chunk-DVGPEBUL.js";
|
|
1
5
|
import {
|
|
2
6
|
translate
|
|
3
7
|
} from "../chunk-X4PQJZ4G.js";
|
|
@@ -8,11 +12,7 @@ import {
|
|
|
8
12
|
} from "../chunk-VVMRZEIW.js";
|
|
9
13
|
import {
|
|
10
14
|
__decorateClass
|
|
11
|
-
} from "../chunk-
|
|
12
|
-
|
|
13
|
-
// src/push/push.port.ts
|
|
14
|
-
var PUSH = /* @__PURE__ */ Symbol("PUSH");
|
|
15
|
-
var PUSH_DEVICE_STORE = /* @__PURE__ */ Symbol("PUSH_DEVICE_STORE");
|
|
15
|
+
} from "../chunk-D3DDJWUD.js";
|
|
16
16
|
|
|
17
17
|
// src/push/push.options.ts
|
|
18
18
|
var PUSH_OPTIONS = /* @__PURE__ */ Symbol("PUSH_OPTIONS");
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AlertChannelPort, AlertMessage } from './resilience.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* POST JSON a una URL (sirve para Slack, Discord, n8n…). Usa `fetch` a pelo A PROPÓSITO: un fallo
|
|
4
|
+
* al avisar no debe pasar por `fetchResiliente` ni generar otra alerta.
|
|
5
|
+
*/
|
|
6
|
+
export declare class WebhookAlertChannel implements AlertChannelPort {
|
|
7
|
+
private readonly config;
|
|
8
|
+
constructor(config: {
|
|
9
|
+
url: string;
|
|
10
|
+
headers?: Record<string, string>;
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
/** Da forma al cuerpo. Por defecto `{ text, content, ...message }`. */
|
|
13
|
+
body?: (message: AlertMessage) => unknown;
|
|
14
|
+
fetchImpl?: typeof fetch;
|
|
15
|
+
});
|
|
16
|
+
send(message: AlertMessage): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
/** Puerto de envío de correo. Adáptalo a `EmailPort` de nestkit/email, Resend, SMTP… */
|
|
19
|
+
export interface AlertMailerPort {
|
|
20
|
+
send(mail: {
|
|
21
|
+
to: string[];
|
|
22
|
+
subject: string;
|
|
23
|
+
text: string;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** Aviso por correo a una lista de destinatarios, a través de un {@link AlertMailerPort}. */
|
|
27
|
+
export declare class EmailAlertChannel implements AlertChannelPort {
|
|
28
|
+
private readonly config;
|
|
29
|
+
constructor(config: {
|
|
30
|
+
to: string[];
|
|
31
|
+
mailer: AlertMailerPort;
|
|
32
|
+
});
|
|
33
|
+
send(message: AlertMessage): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** Guarda los avisos en memoria (pruebas). */
|
|
36
|
+
export declare class MemoryAlertChannel implements AlertChannelPort {
|
|
37
|
+
readonly messages: AlertMessage[];
|
|
38
|
+
send(message: AlertMessage): Promise<void>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CallHandler, type ExecutionContext, type NestInterceptor } from '@nestjs/common';
|
|
2
|
+
import { type Observable } from 'rxjs';
|
|
3
|
+
/**
|
|
4
|
+
* Avisa de los errores NO controlados de una ruta (todo lo que termine en 5xx; un 4xx es esperado
|
|
5
|
+
* y no alerta). Solo observa: relanza el mismo error para que el filtro de excepciones conteste
|
|
6
|
+
* igual que antes. El aviso se deduplica por ruta + mensaje.
|
|
7
|
+
*/
|
|
8
|
+
export declare class AlertErrorsInterceptor implements NestInterceptor {
|
|
9
|
+
intercept(ctx: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function errorInfo(e: unknown): {
|
|
2
|
+
name?: string;
|
|
3
|
+
message: string;
|
|
4
|
+
stack?: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Para métodos de cron/jobs: si fallan, avisa a los canales (nivel `error`) y relanza el error
|
|
8
|
+
* igual que antes. Va debajo de `@Cron(...)`. Mismo job fallando seguido = un aviso por ventana.
|
|
9
|
+
*/
|
|
10
|
+
export declare function AlertarFallo(name: string): MethodDecorator;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { type OnModuleDestroy, type OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { type ResolvedResilienceOptions } from './resilience.options.js';
|
|
3
|
+
import { type AlertNotifier } from './runtime.js';
|
|
4
|
+
import type { AlertMessage, AlertRecord, AlertStore, ProviderFailure, ProviderSink } from './resilience.types.js';
|
|
5
|
+
export interface NewAlert {
|
|
6
|
+
provider: string;
|
|
7
|
+
type: string;
|
|
8
|
+
message: string;
|
|
9
|
+
details?: Record<string, unknown>;
|
|
10
|
+
/** Con tenant, la alerta es de ámbito tenant (no despierta a nadie de la plataforma). */
|
|
11
|
+
tenantId?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ProviderState {
|
|
14
|
+
lastSuccess: Date | null;
|
|
15
|
+
lastFailure: Date | null;
|
|
16
|
+
consecutiveFailures: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const ALERT_UNAVAILABLE = "unavailable";
|
|
19
|
+
export declare const ALERT_CREDENTIALS = "credentials";
|
|
20
|
+
/**
|
|
21
|
+
* Registro y aviso de alertas. NUNCA lanza: una alerta que no se pudo guardar o avisar se anota
|
|
22
|
+
* en el log y la operación que la originó sigue su curso.
|
|
23
|
+
*
|
|
24
|
+
* Una alerta abierta por (proveedor, tipo, tenant) acumula `times` (×N en el aviso). Se avisa al
|
|
25
|
+
* abrirla y, si sigue abierta, una vez por ventana de deduplicación; al resolverse, una vez más.
|
|
26
|
+
* Un tope global por minuto protege a los canales de una inundación.
|
|
27
|
+
*/
|
|
28
|
+
export declare class AlertService implements ProviderSink, AlertNotifier, OnModuleInit, OnModuleDestroy {
|
|
29
|
+
private readonly store;
|
|
30
|
+
private readonly options;
|
|
31
|
+
private readonly log;
|
|
32
|
+
private readonly state;
|
|
33
|
+
private readonly seen;
|
|
34
|
+
private sentAt;
|
|
35
|
+
constructor(store: AlertStore, options: ResolvedResilienceOptions);
|
|
36
|
+
/** Reloj; se reemplaza en pruebas. */
|
|
37
|
+
now: () => number;
|
|
38
|
+
onModuleInit(): void;
|
|
39
|
+
onModuleDestroy(): void;
|
|
40
|
+
success(provider: string): void;
|
|
41
|
+
failure(provider: string, info: ProviderFailure): void;
|
|
42
|
+
credentials(provider: string, info: ProviderFailure): void;
|
|
43
|
+
/** Abre la alerta o acumula sobre la abierta; avisa según la ventana. */
|
|
44
|
+
report(a: NewAlert): Promise<void>;
|
|
45
|
+
/** El proveedor volvió: cierra sus alertas de los tipos dados y avisa una vez. */
|
|
46
|
+
recovered(provider: string, types?: string[]): Promise<void>;
|
|
47
|
+
/** El tenant arregló sus credenciales: cierra sus alertas de ese tipo. Nunca lanza. */
|
|
48
|
+
resolveForTenant(tenantId: string, providers: string[], type: string): Promise<void>;
|
|
49
|
+
openAlerts(): Promise<AlertRecord[]>;
|
|
50
|
+
list(opts: {
|
|
51
|
+
onlyOpen: boolean;
|
|
52
|
+
cursor?: string;
|
|
53
|
+
limit?: number;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
items: AlertRecord[];
|
|
56
|
+
next: string | null;
|
|
57
|
+
}>;
|
|
58
|
+
/** Cierre manual desde una pantalla de administración. */
|
|
59
|
+
resolveManual(id: string): Promise<void>;
|
|
60
|
+
stateOf(provider: string): ProviderState;
|
|
61
|
+
/**
|
|
62
|
+
* Aviso ad hoc (errores no controlados, jobs) sin pasar por el almacén. Dispara y olvida.
|
|
63
|
+
* Con `dedupeKey`, el mismo aviso sale a lo sumo una vez por ventana; lo omitido se cuenta en
|
|
64
|
+
* `repeated` del siguiente.
|
|
65
|
+
*/
|
|
66
|
+
notify(message: AlertMessage & {
|
|
67
|
+
dedupeKey?: string;
|
|
68
|
+
}): void;
|
|
69
|
+
/** Versión esperable de {@link notify}; `true` si salió. Nunca rechaza. */
|
|
70
|
+
notifyNow(message: AlertMessage & {
|
|
71
|
+
dedupeKey?: string;
|
|
72
|
+
}): Promise<boolean>;
|
|
73
|
+
private nameOf;
|
|
74
|
+
private toMessage;
|
|
75
|
+
/** Manda a todos los canales respetando el tope por minuto. `true` si salió (aunque un canal falle). */
|
|
76
|
+
private dispatch;
|
|
77
|
+
}
|