@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,33 @@
|
|
|
1
|
+
import { type DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { type JobsAdminOptions } from './jobs-admin.controller.js';
|
|
3
|
+
import { type JobsOptions } from './jobs.options.js';
|
|
4
|
+
import { createTableSql } from './jobs.sql.js';
|
|
5
|
+
/**
|
|
6
|
+
* Durable job queue in Postgres.
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* JobsModule.forRoot({ pool, table: 'job', maxAttempts: 5, onDead: (job, err) => alerts.send(...) })
|
|
10
|
+
* JobsModule.forRoot({ pool, admin: { path: 'jobs', guards: [AuthGuard, CanAudit] } }) // failed tray
|
|
11
|
+
*
|
|
12
|
+
* jobs.register('billing.charge', async (job) => { ... });
|
|
13
|
+
* await jobs.enqueue('billing.charge', { id }, { dedupeKey: `charge:${id}`, tenantId });
|
|
14
|
+
* // inside a handler, on a 429: throw new DeferJob(retryAfterMs);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Create the table in a migration with `JobsModule.createTableSql()`.
|
|
18
|
+
*/
|
|
19
|
+
export declare class JobsModule {
|
|
20
|
+
/** The migration SQL (table + indexes). */
|
|
21
|
+
static createTableSql: typeof createTableSql;
|
|
22
|
+
static forRoot(options: JobsOptions & {
|
|
23
|
+
admin?: JobsAdminOptions | false;
|
|
24
|
+
}): DynamicModule;
|
|
25
|
+
static forRootAsync(config: {
|
|
26
|
+
imports?: any[];
|
|
27
|
+
inject?: any[];
|
|
28
|
+
useFactory: (...args: any[]) => JobsOptions | Promise<JobsOptions>;
|
|
29
|
+
/** Controllers cannot wait for async options, so the tray is configured here. */
|
|
30
|
+
admin?: JobsAdminOptions | false;
|
|
31
|
+
}): DynamicModule;
|
|
32
|
+
private static build;
|
|
33
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** DI token carrying the resolved {@link JobsOptions}. */
|
|
2
|
+
export declare const JOBS_OPTIONS: unique symbol;
|
|
3
|
+
/** Structural `pg` Pool/Client: only `query` is used, so `pg` is never imported. */
|
|
4
|
+
export interface JobsPool {
|
|
5
|
+
query(sql: string, params?: unknown[]): Promise<{
|
|
6
|
+
rows: any[];
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
/** A job as handed to a handler. */
|
|
10
|
+
export interface Job<P = Record<string, any>> {
|
|
11
|
+
id: string;
|
|
12
|
+
type: string;
|
|
13
|
+
payload: P;
|
|
14
|
+
/** Attempts used, counting this one (1 on the first run). */
|
|
15
|
+
attempts: number;
|
|
16
|
+
/** Times it was deferred with {@link DeferJob}. */
|
|
17
|
+
deferrals: number;
|
|
18
|
+
/** Only when `tenantColumn` is configured. */
|
|
19
|
+
tenantId?: string | null;
|
|
20
|
+
}
|
|
21
|
+
export type JobHandler<P = Record<string, any>> = (job: Job<P>) => Promise<void> | void;
|
|
22
|
+
export interface JobsOptions {
|
|
23
|
+
/** Table name (optionally `schema.table`). Defaults to `job`. */
|
|
24
|
+
table?: string;
|
|
25
|
+
/** A `pg` Pool or Client. Required. */
|
|
26
|
+
pool: JobsPool;
|
|
27
|
+
/** Idle poll interval. Defaults to 2000 ms. While there is work the worker does not wait. */
|
|
28
|
+
pollMs?: number;
|
|
29
|
+
/** Attempts before a job lands in the failed tray. Defaults to 5. */
|
|
30
|
+
maxAttempts?: number;
|
|
31
|
+
/** Wait before attempt `n + 1`, in ms. Defaults to exponential: 5 s · 2^(n-1), capped at 1 h. */
|
|
32
|
+
backoff?: (attempt: number) => number;
|
|
33
|
+
/** Deferrals before a deferred job counts as a failure. Defaults to 20. */
|
|
34
|
+
maxDeferrals?: number;
|
|
35
|
+
/** A job left `taken` longer than this (crashed worker) is taken again. Defaults to 10 min. */
|
|
36
|
+
lockTimeoutMs?: number;
|
|
37
|
+
/** Called once when a job exhausts its attempts (or deferrals). Must not throw; errors are logged. */
|
|
38
|
+
onDead?: (job: Job, error: unknown) => void | Promise<void>;
|
|
39
|
+
/** Name of the tenant column (e.g. `tenant_id`), or `false`/omitted for none. */
|
|
40
|
+
tenantColumn?: string | false;
|
|
41
|
+
/** Start the in-process worker on module init. Defaults to true; false for API-only instances. */
|
|
42
|
+
autoStart?: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface EnqueueOptions {
|
|
45
|
+
/** Not before this moment. Defaults to now. */
|
|
46
|
+
runAt?: Date;
|
|
47
|
+
/** Requires `tenantColumn`. */
|
|
48
|
+
tenantId?: string;
|
|
49
|
+
/**
|
|
50
|
+
* While a job with this key is pending or running, enqueueing it again does
|
|
51
|
+
* nothing (returns `null`). Once it finished or failed the key is free.
|
|
52
|
+
*/
|
|
53
|
+
dedupeKey?: string;
|
|
54
|
+
}
|
|
55
|
+
export interface FailedJob {
|
|
56
|
+
id: string;
|
|
57
|
+
type: string;
|
|
58
|
+
error: string | null;
|
|
59
|
+
attempts: number;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
tenantId?: string | null;
|
|
62
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type OnModuleDestroy, type OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { type EnqueueOptions, type FailedJob, type JobHandler, type JobsOptions } from './jobs.options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Durable queue in Postgres with the worker in the same process.
|
|
5
|
+
*
|
|
6
|
+
* Two properties are not style:
|
|
7
|
+
*
|
|
8
|
+
* 1. **It only takes types it has a handler for.** A job nobody can run waits
|
|
9
|
+
* in the queue instead of failing five times and dirtying the failed tray
|
|
10
|
+
* (another instance, or a later deploy, may know how to run it).
|
|
11
|
+
* 2. **A throwing handler does not lose the job**: it goes back with
|
|
12
|
+
* exponential backoff and, after `maxAttempts`, lands in the failed tray
|
|
13
|
+
* (`failed()` / `requeue()`), calling `onDead` once.
|
|
14
|
+
*
|
|
15
|
+
* Several instances can run workers: `FOR UPDATE SKIP LOCKED` hands each job
|
|
16
|
+
* to one. At-least-once: a handler that crashed after its side effect runs
|
|
17
|
+
* again, so handlers must be idempotent.
|
|
18
|
+
*/
|
|
19
|
+
export declare class JobsService implements OnModuleInit, OnModuleDestroy {
|
|
20
|
+
private readonly options;
|
|
21
|
+
private readonly log;
|
|
22
|
+
private readonly handlers;
|
|
23
|
+
private readonly table;
|
|
24
|
+
private readonly tenantColumn;
|
|
25
|
+
private timer?;
|
|
26
|
+
private running;
|
|
27
|
+
private stopped;
|
|
28
|
+
constructor(options: JobsOptions);
|
|
29
|
+
/** Registers (or replaces) the handler for a type. */
|
|
30
|
+
register<P = Record<string, any>>(type: string, handler: JobHandler<P>): void;
|
|
31
|
+
onModuleInit(): void;
|
|
32
|
+
onModuleDestroy(): void;
|
|
33
|
+
start(): void;
|
|
34
|
+
stop(): void;
|
|
35
|
+
/** Adds a job. Returns its id, or `null` if `dedupeKey` matched a live job. */
|
|
36
|
+
enqueue(type: string, payload?: unknown, opts?: EnqueueOptions): Promise<string | null>;
|
|
37
|
+
/** The failed tray, newest first. */
|
|
38
|
+
failed(limit?: number, tenantId?: string): Promise<FailedJob[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Puts a failed job back in the queue. Attempts reset: whoever requeues has
|
|
41
|
+
* fixed the cause, and keeping the counter would return it to the tray on
|
|
42
|
+
* the first stumble. `false` if it was not in the tray.
|
|
43
|
+
*/
|
|
44
|
+
requeue(id: string): Promise<boolean>;
|
|
45
|
+
/** Takes and runs ONE job. Returns true if it took one (whatever the outcome). */
|
|
46
|
+
processOne(): Promise<boolean>;
|
|
47
|
+
private lockCutoff;
|
|
48
|
+
private handleFailure;
|
|
49
|
+
private schedule;
|
|
50
|
+
private tick;
|
|
51
|
+
/** The migration for this configuration. */
|
|
52
|
+
createTableSql(): string;
|
|
53
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function checkIdentifier(value: string, what: string): string;
|
|
2
|
+
/**
|
|
3
|
+
* The jobs table. Put it in a migration (`JobsModule.createTableSql()`).
|
|
4
|
+
*
|
|
5
|
+
* - `status`: `pending` → `taken` → `done`, or `failed` (the tray).
|
|
6
|
+
* - A partial unique index on `dedupe_key` while the job is live makes
|
|
7
|
+
* `enqueue(..., { dedupeKey })` atomic.
|
|
8
|
+
* - `tenantColumn` adds a nullable `text` column of that name.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTableSql(table?: string, tenantColumn?: string | false): string;
|
|
11
|
+
export declare const WAIT: (n: number) => string;
|
package/dist/media/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
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
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
5
5
|
|
|
6
6
|
// src/media/media.module.ts
|
|
7
7
|
var _common = require('@nestjs/common');
|
|
@@ -91,10 +91,10 @@ var MediaService = class {
|
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
|
-
MediaService = exports.MediaService =
|
|
94
|
+
MediaService = exports.MediaService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
95
95
|
_common.Injectable.call(void 0, ),
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, MEDIA_TTL)),
|
|
97
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, MEDIA_LIMITS))
|
|
98
98
|
], MediaService);
|
|
99
99
|
|
|
100
100
|
// src/media/media.controller.ts
|
|
@@ -139,20 +139,20 @@ var MediaController = class {
|
|
|
139
139
|
reply.header("content-type", found.contentType).header("cache-control", "no-store").header("x-content-type-options", "nosniff").send(found.data);
|
|
140
140
|
}
|
|
141
141
|
};
|
|
142
|
-
|
|
142
|
+
_chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
143
143
|
_common.Post.call(void 0, "media"),
|
|
144
|
-
|
|
145
|
-
|
|
144
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, )),
|
|
145
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Headers.call(void 0, "x-media-secret"))
|
|
146
146
|
], MediaController.prototype, "upload", 1);
|
|
147
|
-
|
|
147
|
+
_chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
148
148
|
_common.Get.call(void 0, "media/:id"),
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Param.call(void 0, "id")),
|
|
150
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Res.call(void 0, ))
|
|
151
151
|
], MediaController.prototype, "serve", 1);
|
|
152
|
-
MediaController =
|
|
152
|
+
MediaController = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
153
153
|
_common.Controller.call(void 0, ),
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, MediaService)),
|
|
155
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, MEDIA_OPTIONS))
|
|
156
156
|
], MediaController);
|
|
157
157
|
|
|
158
158
|
// src/media/media.module.ts
|
|
@@ -173,7 +173,7 @@ var MediaModule = class {
|
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
|
-
MediaModule = exports.MediaModule =
|
|
176
|
+
MediaModule = exports.MediaModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
177
177
|
_common.Module.call(void 0, {})
|
|
178
178
|
], MediaModule);
|
|
179
179
|
|
package/dist/media/index.js
CHANGED
package/dist/meta/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
4
4
|
|
|
5
5
|
// src/meta/meta.module.ts
|
|
6
6
|
var _common = require('@nestjs/common');
|
|
@@ -124,7 +124,7 @@ var MetaService = class {
|
|
|
124
124
|
throw new Error(`Meta (${code}): ${message}${hint}`);
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
MetaService = exports.MetaService =
|
|
127
|
+
MetaService = exports.MetaService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
128
128
|
_common.Injectable.call(void 0, )
|
|
129
129
|
], MetaService);
|
|
130
130
|
|
|
@@ -155,7 +155,7 @@ var MetaModule = class {
|
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
};
|
|
158
|
-
MetaModule = exports.MetaModule =
|
|
158
|
+
MetaModule = exports.MetaModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
159
159
|
_common.Module.call(void 0, {})
|
|
160
160
|
], MetaModule);
|
|
161
161
|
|
package/dist/meta/index.js
CHANGED
|
@@ -0,0 +1,375 @@
|
|
|
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 _chunkCU4FUIVJcjs = require('../chunk-CU4FUIVJ.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkHDFPSA2Vcjs = require('../chunk-HDFPSA2V.cjs');
|
|
9
|
+
require('../chunk-Q5Y33L7B.cjs');
|
|
10
|
+
require('../chunk-PNK5WMPP.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _chunkLRX7AMSScjs = require('../chunk-LRX7AMSS.cjs');
|
|
15
|
+
|
|
16
|
+
// src/notifications/notifications.module.ts
|
|
17
|
+
var _common = require('@nestjs/common');
|
|
18
|
+
|
|
19
|
+
// src/notifications/memory.stores.ts
|
|
20
|
+
var _crypto = require('crypto');
|
|
21
|
+
var k = (...parts) => parts.map((p) => _nullishCoalesce(p, () => ( ""))).join("\0");
|
|
22
|
+
var MemoryPreferenceStore = class {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.rows = /* @__PURE__ */ new Map();
|
|
25
|
+
}
|
|
26
|
+
async list(userId, scope) {
|
|
27
|
+
const prefix = k(scope, userId, "");
|
|
28
|
+
const out = {};
|
|
29
|
+
for (const [key, value] of this.rows) if (key.startsWith(prefix)) out[key.slice(prefix.length)] = value;
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
async save(userId, key, enabled, scope) {
|
|
33
|
+
this.rows.set(k(scope, userId, key), enabled);
|
|
34
|
+
}
|
|
35
|
+
async listForUsers(userIds, key, scope) {
|
|
36
|
+
const out = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const id of userIds) {
|
|
38
|
+
const v = this.rows.get(k(scope, id, key));
|
|
39
|
+
if (v !== void 0) out.set(id, v);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var identity = (d) => d.kind === "fcm" ? `fcm:${d.token}` : `web:${d.endpoint}`;
|
|
45
|
+
var MemoryDeviceStore = class {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.rows = /* @__PURE__ */ new Map();
|
|
48
|
+
}
|
|
49
|
+
async listByUser(userId) {
|
|
50
|
+
return [...this.rows.entries()].filter(([, r]) => r.userId === userId && r.enabled).map(([id, r]) => ({ id, device: r.device }));
|
|
51
|
+
}
|
|
52
|
+
async remove(id) {
|
|
53
|
+
this.rows.delete(id);
|
|
54
|
+
}
|
|
55
|
+
async register(userId, device, meta = {}) {
|
|
56
|
+
const same = [...this.rows.entries()].find(([, r]) => r.userId === userId && identity(r.device) === identity(device));
|
|
57
|
+
if (same) {
|
|
58
|
+
same[1].device = device;
|
|
59
|
+
if (meta.enabled !== void 0) same[1].enabled = meta.enabled;
|
|
60
|
+
if (meta.platform !== void 0) same[1].platform = meta.platform;
|
|
61
|
+
return { id: same[0], enabled: same[1].enabled };
|
|
62
|
+
}
|
|
63
|
+
const id = _crypto.randomUUID.call(void 0, );
|
|
64
|
+
const enabled = _nullishCoalesce(meta.enabled, () => ( true));
|
|
65
|
+
this.rows.set(id, { userId, device, enabled, platform: _nullishCoalesce(meta.platform, () => ( null)) });
|
|
66
|
+
return { id, enabled };
|
|
67
|
+
}
|
|
68
|
+
async unregister(userId, id) {
|
|
69
|
+
const row = this.rows.get(id);
|
|
70
|
+
if (!row || row.userId !== userId) return false;
|
|
71
|
+
return this.rows.delete(id);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// src/notifications/notifications.controller.ts
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
// src/notifications/notifications.port.ts
|
|
79
|
+
var NOTIFICATIONS_OPTIONS = /* @__PURE__ */ Symbol("NOTIFICATIONS_OPTIONS");
|
|
80
|
+
var NOTIFICATION_PREFERENCES = /* @__PURE__ */ Symbol("NOTIFICATION_PREFERENCES");
|
|
81
|
+
var NOTIFICATION_DEVICES = /* @__PURE__ */ Symbol("NOTIFICATION_DEVICES");
|
|
82
|
+
|
|
83
|
+
// src/notifications/notifier.service.ts
|
|
84
|
+
|
|
85
|
+
function validateCatalog(catalog) {
|
|
86
|
+
const map = /* @__PURE__ */ new Map();
|
|
87
|
+
for (const n of catalog) {
|
|
88
|
+
if (!n.key) throw new Error("NotificationsModule: a notice without key.");
|
|
89
|
+
if (map.has(n.key)) throw new Error(`NotificationsModule: duplicate notice "${n.key}".`);
|
|
90
|
+
map.set(n.key, n);
|
|
91
|
+
}
|
|
92
|
+
for (const n of catalog) {
|
|
93
|
+
if (!n.governedBy) continue;
|
|
94
|
+
const owner = map.get(n.governedBy);
|
|
95
|
+
if (!owner) throw new Error(`NotificationsModule: "${n.key}" is governed by "${n.governedBy}", which is not in the catalog.`);
|
|
96
|
+
if (owner.governedBy) throw new Error(`NotificationsModule: "${n.key}" is governed by "${owner.key}", which is itself governed (one level only).`);
|
|
97
|
+
}
|
|
98
|
+
return map;
|
|
99
|
+
}
|
|
100
|
+
var NotifierService = class {
|
|
101
|
+
constructor(options, prefs, devices, push) {
|
|
102
|
+
this.options = options;
|
|
103
|
+
this.prefs = prefs;
|
|
104
|
+
this.devices = devices;
|
|
105
|
+
this.push = push;
|
|
106
|
+
this.logger = new (0, _common.Logger)("Notifier");
|
|
107
|
+
this.catalog = validateCatalog(options.catalog);
|
|
108
|
+
}
|
|
109
|
+
/** The key whose switch governs `notice`. */
|
|
110
|
+
governing(notice) {
|
|
111
|
+
return notice.governedBy ? this.catalog.get(notice.governedBy) : notice;
|
|
112
|
+
}
|
|
113
|
+
/** Switches the user can flip (entries that are not governed by another). */
|
|
114
|
+
async preferencesOf(userId, scope) {
|
|
115
|
+
const saved = await this.prefs.list(userId, scope);
|
|
116
|
+
return this.options.catalog.filter((n) => !n.governedBy).map((n) => ({
|
|
117
|
+
key: n.key,
|
|
118
|
+
group: n.group,
|
|
119
|
+
title: n.title,
|
|
120
|
+
description: n.description,
|
|
121
|
+
defaultOn: n.defaultOn,
|
|
122
|
+
enabled: _nullishCoalesce(saved[n.key], () => ( n.defaultOn))
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
/** Returns false when the key is not a user-facing switch (not in the catalog, or governed by another). */
|
|
126
|
+
async setPreference(userId, key, enabled, scope) {
|
|
127
|
+
const n = this.catalog.get(key);
|
|
128
|
+
if (!n || n.governedBy) return false;
|
|
129
|
+
await this.prefs.save(userId, key, enabled, scope);
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
async notify(key, input) {
|
|
133
|
+
try {
|
|
134
|
+
return await this.run(key, input);
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (this.options.neverThrow === false) throw error;
|
|
137
|
+
this.logger.warn(`notify("${key}") failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _ => _.message]), () => ( error))}`);
|
|
138
|
+
return { accepted: this.catalog.has(key), sent: 0, failed: 0, delivered: [], skipped: [{ reason: "error" }] };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async run(key, input) {
|
|
142
|
+
const result = { accepted: false, sent: 0, failed: 0, delivered: [], skipped: [] };
|
|
143
|
+
const notice = this.catalog.get(key);
|
|
144
|
+
if (!notice) {
|
|
145
|
+
this.logger.warn(`notice "${key}" is not in the catalog: not sent.`);
|
|
146
|
+
result.skipped.push({ reason: "not_in_catalog" });
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
result.accepted = true;
|
|
150
|
+
const exclude = new Set(_nullishCoalesce(input.exclude, () => ( [])));
|
|
151
|
+
const candidates = [...new Set(await this.resolveRecipients(input.to))].filter((id) => !exclude.has(id));
|
|
152
|
+
if (candidates.length === 0) {
|
|
153
|
+
result.skipped.push({ reason: "no_recipients" });
|
|
154
|
+
return result;
|
|
155
|
+
}
|
|
156
|
+
const owner = this.governing(notice);
|
|
157
|
+
const explicit = await this.explicitChoices(candidates, owner.key, input.preferenceScope);
|
|
158
|
+
const { to: _to, exclude: _x, preferenceScope: _p, lang, data, ...message } = input;
|
|
159
|
+
const payload = { ...message, data: { ...data, notice: key } };
|
|
160
|
+
for (const userId of candidates) {
|
|
161
|
+
if (!(_nullishCoalesce(explicit.get(userId), () => ( owner.defaultOn)))) {
|
|
162
|
+
result.skipped.push({ userId, reason: "disabled" });
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (this.options.gate && !await this.passesGate(userId, notice)) {
|
|
166
|
+
result.skipped.push({ userId, reason: "gate" });
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const reason = await this.deliver(userId, notice, payload, lang, result);
|
|
170
|
+
if (reason) result.skipped.push({ userId, reason });
|
|
171
|
+
}
|
|
172
|
+
return result;
|
|
173
|
+
}
|
|
174
|
+
async deliver(userId, notice, payload, lang, result) {
|
|
175
|
+
let stored;
|
|
176
|
+
try {
|
|
177
|
+
stored = await this.devices.listByUser(userId);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (this.options.neverThrow === false) throw error;
|
|
180
|
+
this.logger.warn(`devices of ${userId}: ${error.message}`);
|
|
181
|
+
return "error";
|
|
182
|
+
}
|
|
183
|
+
const allowed = notice.channels;
|
|
184
|
+
const targets = allowed ? stored.filter((s) => allowed.includes(s.device.kind)) : stored;
|
|
185
|
+
if (targets.length === 0) return "no_devices";
|
|
186
|
+
const out = await this.push.send(
|
|
187
|
+
targets.map((t) => t.device),
|
|
188
|
+
payload,
|
|
189
|
+
{ lang }
|
|
190
|
+
);
|
|
191
|
+
result.sent += out.sent;
|
|
192
|
+
result.failed += out.failed.length;
|
|
193
|
+
if (out.sent > 0) result.delivered.push(userId);
|
|
194
|
+
const dead = new Set(out.failed.filter((f) => f.stale).map((f) => f.device));
|
|
195
|
+
for (const t of targets) {
|
|
196
|
+
if (!dead.has(t.device)) continue;
|
|
197
|
+
await this.devices.remove(t.id).catch((e) => this.logger.warn(`could not prune device ${t.id}: ${_nullishCoalesce(_optionalChain([e, 'optionalAccess', _2 => _2.message]), () => ( e))}`));
|
|
198
|
+
}
|
|
199
|
+
return out.sent > 0 ? null : "error";
|
|
200
|
+
}
|
|
201
|
+
async passesGate(userId, notice) {
|
|
202
|
+
try {
|
|
203
|
+
return await this.options.gate(userId, notice);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
this.logger.warn(`gate failed for ${userId}/${notice.key}: ${error.message}`);
|
|
206
|
+
return (_nullishCoalesce(this.options.gateOnError, () => ( "allow"))) === "allow";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async resolveRecipients(to) {
|
|
210
|
+
if (typeof to === "string") return [to];
|
|
211
|
+
if (Array.isArray(to)) return to;
|
|
212
|
+
if (!this.options.recipients) throw new Error("NotificationsModule: notify({ to: { scope } }) needs the `recipients` option.");
|
|
213
|
+
return this.options.recipients(to.scope);
|
|
214
|
+
}
|
|
215
|
+
async explicitChoices(userIds, key, scope) {
|
|
216
|
+
if (this.prefs.listForUsers) return this.prefs.listForUsers(userIds, key, scope);
|
|
217
|
+
const out = /* @__PURE__ */ new Map();
|
|
218
|
+
for (const id of userIds) {
|
|
219
|
+
const v = (await this.prefs.list(id, scope))[key];
|
|
220
|
+
if (v !== void 0) out.set(id, v);
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
NotifierService = exports.NotifierService = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
226
|
+
_common.Injectable.call(void 0, ),
|
|
227
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Inject.call(void 0, NOTIFICATIONS_OPTIONS)),
|
|
228
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, NOTIFICATION_PREFERENCES)),
|
|
229
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 2, _common.Inject.call(void 0, NOTIFICATION_DEVICES)),
|
|
230
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 3, _common.Inject.call(void 0, _chunkCU4FUIVJcjs.PUSH))
|
|
231
|
+
], NotifierService);
|
|
232
|
+
|
|
233
|
+
// src/notifications/notifications.controller.ts
|
|
234
|
+
function parseDevice(body) {
|
|
235
|
+
if (body && typeof body.token === "string" && body.token) return { kind: "fcm", token: body.token };
|
|
236
|
+
if (body && typeof body.endpoint === "string" && body.endpoint && typeof _optionalChain([body, 'access', _3 => _3.keys, 'optionalAccess', _4 => _4.p256dh]) === "string" && typeof _optionalChain([body, 'access', _5 => _5.keys, 'optionalAccess', _6 => _6.auth]) === "string") {
|
|
237
|
+
return { kind: "webpush", endpoint: body.endpoint, keys: { p256dh: body.keys.p256dh, auth: body.keys.auth } };
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
function createNotificationsController(path, opts = {}) {
|
|
242
|
+
const userOf = (req) => {
|
|
243
|
+
const id = opts.getUserId ? opts.getUserId(req) : _optionalChain([req, 'optionalAccess', _7 => _7.user, 'optionalAccess', _8 => _8.sub]);
|
|
244
|
+
if (!id) throw new (0, _chunkHDFPSA2Vcjs.UnauthorizedAppException)();
|
|
245
|
+
return id;
|
|
246
|
+
};
|
|
247
|
+
const scopeOf = (req) => _optionalChain([opts, 'access', _9 => _9.getPreferenceScope, 'optionalCall', _10 => _10(req)]);
|
|
248
|
+
let NotificationsController = class {
|
|
249
|
+
constructor(notifier, devices, _options) {
|
|
250
|
+
this.notifier = notifier;
|
|
251
|
+
this.devices = devices;
|
|
252
|
+
}
|
|
253
|
+
async register(req, body) {
|
|
254
|
+
const userId = userOf(req);
|
|
255
|
+
const device = parseDevice(body);
|
|
256
|
+
if (!device) throw new (0, _chunkHDFPSA2Vcjs.ValidationAppException)("Send `token` (FCM) or `endpoint` + `keys` (Web Push).", void 0, "INVALID_DEVICE");
|
|
257
|
+
const enabled = typeof body.enabled === "boolean" ? body.enabled : void 0;
|
|
258
|
+
const platform = typeof body.platform === "string" ? body.platform : void 0;
|
|
259
|
+
return this.devices.register(userId, device, { platform, enabled });
|
|
260
|
+
}
|
|
261
|
+
async unregister(req, id) {
|
|
262
|
+
const removed = await this.devices.unregister(userOf(req), id);
|
|
263
|
+
if (!removed) throw new (0, _chunkHDFPSA2Vcjs.NotFoundAppException)("Device not found", void 0, "DEVICE_NOT_FOUND");
|
|
264
|
+
return { removed: true };
|
|
265
|
+
}
|
|
266
|
+
preferences(req) {
|
|
267
|
+
return this.notifier.preferencesOf(userOf(req), scopeOf(req));
|
|
268
|
+
}
|
|
269
|
+
async save(req, body) {
|
|
270
|
+
const userId = userOf(req);
|
|
271
|
+
if (typeof _optionalChain([body, 'optionalAccess', _11 => _11.key]) !== "string" || typeof _optionalChain([body, 'optionalAccess', _12 => _12.enabled]) !== "boolean") {
|
|
272
|
+
throw new (0, _chunkHDFPSA2Vcjs.ValidationAppException)("Send `key` (string) and `enabled` (boolean).", void 0, "INVALID_PREFERENCE");
|
|
273
|
+
}
|
|
274
|
+
const ok = await this.notifier.setPreference(userId, body.key, body.enabled, scopeOf(req));
|
|
275
|
+
if (!ok) throw new (0, _chunkHDFPSA2Vcjs.ValidationAppException)(`"${body.key}" is not a switch.`, void 0, "UNKNOWN_NOTICE");
|
|
276
|
+
return this.notifier.preferencesOf(userId, scopeOf(req));
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
_chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
280
|
+
_common.Post.call(void 0, "devices"),
|
|
281
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, )),
|
|
282
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Body.call(void 0, ))
|
|
283
|
+
], NotificationsController.prototype, "register", 1);
|
|
284
|
+
_chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
285
|
+
_common.Delete.call(void 0, "devices/:id"),
|
|
286
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, )),
|
|
287
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Param.call(void 0, "id"))
|
|
288
|
+
], NotificationsController.prototype, "unregister", 1);
|
|
289
|
+
_chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
290
|
+
_common.Get.call(void 0, "preferences"),
|
|
291
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, ))
|
|
292
|
+
], NotificationsController.prototype, "preferences", 1);
|
|
293
|
+
_chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
294
|
+
_common.Put.call(void 0, "preferences"),
|
|
295
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 0, _common.Req.call(void 0, )),
|
|
296
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Body.call(void 0, ))
|
|
297
|
+
], NotificationsController.prototype, "save", 1);
|
|
298
|
+
NotificationsController = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
299
|
+
_common.Controller.call(void 0, path),
|
|
300
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 1, _common.Inject.call(void 0, NOTIFICATION_DEVICES)),
|
|
301
|
+
_chunkLRX7AMSScjs.__decorateParam.call(void 0, 2, _common.Inject.call(void 0, NOTIFICATIONS_OPTIONS))
|
|
302
|
+
], NotificationsController);
|
|
303
|
+
return NotificationsController;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/notifications/notifications.options.ts
|
|
307
|
+
var DEFAULT_NOTIFICATIONS_PATH = "notifications";
|
|
308
|
+
|
|
309
|
+
// src/notifications/notifications.module.ts
|
|
310
|
+
function providers(optionsProvider) {
|
|
311
|
+
return [
|
|
312
|
+
optionsProvider,
|
|
313
|
+
{
|
|
314
|
+
provide: NOTIFICATION_PREFERENCES,
|
|
315
|
+
useFactory: (o) => _nullishCoalesce(o.preferences, () => ( new MemoryPreferenceStore())),
|
|
316
|
+
inject: [NOTIFICATIONS_OPTIONS]
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
provide: NOTIFICATION_DEVICES,
|
|
320
|
+
useFactory: (o) => _nullishCoalesce(o.devices, () => ( new MemoryDeviceStore())),
|
|
321
|
+
inject: [NOTIFICATIONS_OPTIONS]
|
|
322
|
+
},
|
|
323
|
+
NotifierService
|
|
324
|
+
];
|
|
325
|
+
}
|
|
326
|
+
function controllerOf(options) {
|
|
327
|
+
const c = options.controller;
|
|
328
|
+
if (!c) return [];
|
|
329
|
+
const opts = c === true ? {} : c;
|
|
330
|
+
const d = options.devices;
|
|
331
|
+
if (d && (typeof d.register !== "function" || typeof d.unregister !== "function")) {
|
|
332
|
+
throw new Error("NotificationsModule: the controller needs `devices` to implement register() and unregister() (DeviceRegistryPort).");
|
|
333
|
+
}
|
|
334
|
+
return [createNotificationsController(_nullishCoalesce(opts.path, () => ( DEFAULT_NOTIFICATIONS_PATH)), opts)];
|
|
335
|
+
}
|
|
336
|
+
var NotificationsModule = class {
|
|
337
|
+
static forRoot(options) {
|
|
338
|
+
return {
|
|
339
|
+
module: NotificationsModule,
|
|
340
|
+
controllers: controllerOf(options),
|
|
341
|
+
providers: providers({ provide: NOTIFICATIONS_OPTIONS, useValue: options }),
|
|
342
|
+
exports: [NOTIFICATIONS_OPTIONS, NOTIFICATION_PREFERENCES, NOTIFICATION_DEVICES, NotifierService]
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* `controller` and `devices` decide the controllers at registration time, so pass
|
|
347
|
+
* `controller` here (not in the factory) when you want it mounted.
|
|
348
|
+
*/
|
|
349
|
+
static forRootAsync(config) {
|
|
350
|
+
return {
|
|
351
|
+
module: NotificationsModule,
|
|
352
|
+
imports: _nullishCoalesce(config.imports, () => ( [])),
|
|
353
|
+
controllers: controllerOf({ controller: config.controller }),
|
|
354
|
+
providers: providers({ provide: NOTIFICATIONS_OPTIONS, useFactory: config.useFactory, inject: _nullishCoalesce(config.inject, () => ( [])) }),
|
|
355
|
+
exports: [NOTIFICATIONS_OPTIONS, NOTIFICATION_PREFERENCES, NOTIFICATION_DEVICES, NotifierService]
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
NotificationsModule = exports.NotificationsModule = _chunkLRX7AMSScjs.__decorateClass.call(void 0, [
|
|
360
|
+
_common.Global.call(void 0, ),
|
|
361
|
+
_common.Module.call(void 0, {})
|
|
362
|
+
], NotificationsModule);
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
exports.DEFAULT_NOTIFICATIONS_PATH = DEFAULT_NOTIFICATIONS_PATH; exports.MemoryDeviceStore = MemoryDeviceStore; exports.MemoryPreferenceStore = MemoryPreferenceStore; exports.NOTIFICATIONS_OPTIONS = NOTIFICATIONS_OPTIONS; exports.NOTIFICATION_DEVICES = NOTIFICATION_DEVICES; exports.NOTIFICATION_PREFERENCES = NOTIFICATION_PREFERENCES; exports.NotificationsModule = NotificationsModule; exports.NotifierService = NotifierService; exports.createNotificationsController = createNotificationsController; exports.parseDevice = parseDevice; exports.validateCatalog = validateCatalog;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { NotificationsModule } from './notifications.module.js';
|
|
2
|
+
export { NotifierService, validateCatalog } from './notifier.service.js';
|
|
3
|
+
export { createNotificationsController, parseDevice } from './notifications.controller.js';
|
|
4
|
+
export { MemoryPreferenceStore, MemoryDeviceStore } from './memory.stores.js';
|
|
5
|
+
export { NOTIFICATIONS_OPTIONS, NOTIFICATION_PREFERENCES, NOTIFICATION_DEVICES, } from './notifications.port.js';
|
|
6
|
+
export type { NoticeDefinition, PreferenceStorePort, DeviceRegistryPort, NotifyInput, NotifyResult, NotifierPort, PreferenceView, SkipReason, } from './notifications.port.js';
|
|
7
|
+
export { DEFAULT_NOTIFICATIONS_PATH } from './notifications.options.js';
|
|
8
|
+
export type { NotificationsOptions, NotificationsControllerOptions } from './notifications.options.js';
|