unified-notification-core 0.1.8 → 0.1.9
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/CHANGELOG.md +27 -1
- package/README.md +81 -20
- package/dist/cjs/context.d.ts +24 -0
- package/dist/cjs/context.d.ts.map +1 -0
- package/dist/cjs/context.js +167 -0
- package/dist/cjs/context.js.map +7 -0
- package/dist/cjs/contracts.d.ts +109 -0
- package/dist/cjs/contracts.d.ts.map +1 -0
- package/dist/cjs/contracts.js +20 -0
- package/dist/cjs/contracts.js.map +7 -0
- package/dist/cjs/core.d.ts +39 -0
- package/dist/cjs/core.d.ts.map +1 -0
- package/dist/cjs/core.js +156 -0
- package/dist/cjs/core.js.map +7 -0
- package/dist/cjs/delivery-admin.d.ts +13 -0
- package/dist/cjs/delivery-admin.d.ts.map +1 -0
- package/dist/cjs/delivery-admin.js +144 -0
- package/dist/cjs/delivery-admin.js.map +7 -0
- package/dist/cjs/delivery-executor.d.ts +15 -0
- package/dist/cjs/delivery-executor.d.ts.map +1 -0
- package/dist/cjs/delivery-executor.js +338 -0
- package/dist/cjs/delivery-executor.js.map +7 -0
- package/dist/cjs/delivery-store.d.ts +34 -0
- package/dist/cjs/delivery-store.d.ts.map +1 -0
- package/dist/cjs/delivery-store.js +526 -0
- package/dist/cjs/delivery-store.js.map +7 -0
- package/dist/cjs/dispatch-control.d.ts +36 -0
- package/dist/cjs/dispatch-control.d.ts.map +1 -0
- package/dist/cjs/dispatch-control.js +218 -0
- package/dist/cjs/dispatch-control.js.map +7 -0
- package/dist/cjs/dispatcher.d.ts +22 -0
- package/dist/cjs/dispatcher.d.ts.map +1 -0
- package/dist/cjs/dispatcher.js +327 -0
- package/dist/cjs/dispatcher.js.map +7 -0
- package/dist/cjs/errors.d.ts +25 -0
- package/dist/cjs/errors.d.ts.map +1 -0
- package/dist/cjs/errors.js +193 -0
- package/dist/cjs/errors.js.map +7 -0
- package/dist/cjs/idempotency.d.ts +18 -0
- package/dist/cjs/idempotency.d.ts.map +1 -0
- package/dist/cjs/idempotency.js +69 -0
- package/dist/cjs/idempotency.js.map +7 -0
- package/dist/cjs/inbox.d.ts +24 -0
- package/dist/cjs/inbox.d.ts.map +1 -0
- package/dist/cjs/inbox.js +209 -0
- package/dist/cjs/inbox.js.map +7 -0
- package/dist/cjs/index.d.ts +12 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +63 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/json.d.ts +8 -0
- package/dist/cjs/json.d.ts.map +1 -0
- package/dist/cjs/json.js +265 -0
- package/dist/cjs/json.js.map +7 -0
- package/dist/cjs/keys.d.ts +10 -0
- package/dist/cjs/keys.d.ts.map +1 -0
- package/dist/cjs/keys.js +126 -0
- package/dist/cjs/keys.js.map +7 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/preference-store.d.ts +19 -0
- package/dist/cjs/preference-store.d.ts.map +1 -0
- package/dist/cjs/preference-store.js +247 -0
- package/dist/cjs/preference-store.js.map +7 -0
- package/dist/cjs/preferences.d.ts +23 -0
- package/dist/cjs/preferences.d.ts.map +1 -0
- package/dist/cjs/preferences.js +166 -0
- package/dist/cjs/preferences.js.map +7 -0
- package/dist/cjs/publication-input.d.ts +26 -0
- package/dist/cjs/publication-input.d.ts.map +1 -0
- package/dist/cjs/publication-input.js +171 -0
- package/dist/cjs/publication-input.js.map +7 -0
- package/dist/cjs/publication.d.ts +13 -0
- package/dist/cjs/publication.d.ts.map +1 -0
- package/dist/cjs/publication.js +228 -0
- package/dist/cjs/publication.js.map +7 -0
- package/dist/cjs/runtime.d.ts +4 -0
- package/dist/cjs/runtime.d.ts.map +1 -0
- package/dist/cjs/runtime.js +135 -0
- package/dist/cjs/runtime.js.map +7 -0
- package/dist/cjs/schedule.d.ts +5 -0
- package/dist/cjs/schedule.d.ts.map +1 -0
- package/dist/cjs/schedule.js +104 -0
- package/dist/cjs/schedule.js.map +7 -0
- package/dist/cjs/schema.d.ts +2734 -0
- package/dist/cjs/schema.d.ts.map +1 -0
- package/dist/cjs/schema.js +245 -0
- package/dist/cjs/schema.js.map +7 -0
- package/dist/cjs/strings.d.ts +5 -0
- package/dist/cjs/strings.d.ts.map +1 -0
- package/dist/cjs/strings.js +98 -0
- package/dist/cjs/strings.js.map +7 -0
- package/dist/cjs/types.d.ts +124 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +37 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/cjs/validation.d.ts +81 -0
- package/dist/cjs/validation.d.ts.map +1 -0
- package/dist/cjs/validation.js +611 -0
- package/dist/cjs/validation.js.map +7 -0
- package/dist/context.d.ts +24 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/contracts.d.ts +109 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/core.d.ts +26 -90
- package/dist/core.d.ts.map +1 -1
- package/dist/delivery-admin.d.ts +13 -0
- package/dist/delivery-admin.d.ts.map +1 -0
- package/dist/delivery-executor.d.ts +15 -0
- package/dist/delivery-executor.d.ts.map +1 -0
- package/dist/delivery-store.d.ts +34 -0
- package/dist/delivery-store.d.ts.map +1 -0
- package/dist/dispatch-control.d.ts +36 -0
- package/dist/dispatch-control.d.ts.map +1 -0
- package/dist/dispatcher.d.ts +22 -0
- package/dist/dispatcher.d.ts.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/idempotency.d.ts +18 -0
- package/dist/idempotency.d.ts.map +1 -0
- package/dist/inbox.d.ts +24 -0
- package/dist/inbox.d.ts.map +1 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/json.d.ts.map +1 -1
- package/dist/preference-store.d.ts +19 -0
- package/dist/preference-store.d.ts.map +1 -0
- package/dist/preferences.d.ts.map +1 -1
- package/dist/publication-input.d.ts +26 -0
- package/dist/publication-input.d.ts.map +1 -0
- package/dist/publication.d.ts +13 -0
- package/dist/publication.d.ts.map +1 -0
- package/dist/schedule.d.ts +5 -0
- package/dist/schedule.d.ts.map +1 -0
- package/dist/schema.d.ts +57 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -189
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/validation.d.ts +81 -0
- package/dist/validation.d.ts.map +1 -0
- package/docs/adoption-notes.md +59 -6
- package/docs/architecture.md +160 -225
- package/examples/basic.ts +31 -10
- package/package.json +37 -14
- package/dist/core.js +0 -1806
- package/dist/core.js.map +0 -1
- package/dist/errors.js +0 -119
- package/dist/errors.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json.js +0 -207
- package/dist/json.js.map +0 -1
- package/dist/keys.js +0 -68
- package/dist/keys.js.map +0 -1
- package/dist/preferences.js +0 -91
- package/dist/preferences.js.map +0 -1
- package/dist/runtime.js +0 -92
- package/dist/runtime.js.map +0 -1
- package/dist/schema.js.map +0 -1
- package/dist/strings.js +0 -63
- package/dist/strings.js.map +0 -1
- package/dist/types.js +0 -8
- package/dist/types.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 0.1.9 — 2026-10-29
|
|
4
|
+
|
|
5
|
+
- Expose `nextWakeAt()` as a read-only hint for event-driven application
|
|
6
|
+
workers, including retry, lease and channel-policy deadlines.
|
|
7
|
+
- Claim delivery pages with one bulk update while retaining distinct claim
|
|
8
|
+
tokens, attempt limits, and per-channel admission controls.
|
|
9
|
+
- Separate the public core into publication, inbox/preferences, delivery
|
|
10
|
+
persistence, adapter execution, dispatch orchestration, and input boundaries.
|
|
11
|
+
- Bind publication keys to immutable normalized intent and reject conflicting
|
|
12
|
+
replay atomically. Add `publication_fingerprint`; legacy keyed rows remain
|
|
13
|
+
deliverable but require explicit reconciliation before publication replay.
|
|
14
|
+
- Claim external work for available execution capacity, fence provider starts,
|
|
15
|
+
and maintain scoped leases. Canceled or stale queued work cannot start a send.
|
|
16
|
+
- Retry acknowledgment writes without replaying the provider, stop admission on
|
|
17
|
+
infrastructure failure, and account for already-started calls.
|
|
18
|
+
- Add dispatch abort signals and bounded provider waits with explicit unresolved
|
|
19
|
+
outcomes through `NotificationDispatchError`.
|
|
20
|
+
- Persist retry-after cooldowns promptly and remove short-batch false-idle
|
|
21
|
+
detection from worker drains.
|
|
22
|
+
- Serialize provider admission with concurrent cooldown writes, finalize failed
|
|
23
|
+
active fallbacks as skipped after a read, and clamp long-lease renewal timers.
|
|
24
|
+
- Build a shared CommonJS runtime with ESM wrappers and verify both entrypoints
|
|
25
|
+
on the minimum supported Node version, preserving class and schema identity.
|
|
26
|
+
- Add native PostgreSQL concurrency, migration, fault-injection, and process-kill
|
|
27
|
+
recovery tests alongside PGlite coverage checks.
|
|
28
|
+
- Correct upgrade guidance: dispatch state and fallback schema changes are
|
|
29
|
+
required even when their optional features are disabled.
|
|
4
30
|
|
|
5
31
|
- Fix inbox pagination skipping PostgreSQL submillisecond timestamps by using
|
|
6
32
|
consistent millisecond ordering and Date cursor comparisons.
|
package/README.md
CHANGED
|
@@ -21,25 +21,32 @@ Instead, register callbacks:
|
|
|
21
21
|
const notificationCore = createNotificationCore<AppChannel>({
|
|
22
22
|
db,
|
|
23
23
|
adapters: {
|
|
24
|
-
email: async ({ recipientId, payload }) => {
|
|
24
|
+
email: async ({ deliveryId, recipientId, payload, signal }) => {
|
|
25
25
|
const recipient = await users.findContact(recipientId);
|
|
26
26
|
const result = await sendMail({
|
|
27
27
|
to: recipient.email,
|
|
28
28
|
subject: payload.title,
|
|
29
29
|
text: payload.body,
|
|
30
|
+
idempotencyKey: deliveryId,
|
|
31
|
+
signal,
|
|
30
32
|
});
|
|
31
33
|
return { providerMessageId: result.messageId };
|
|
32
34
|
},
|
|
33
|
-
sms: async ({ recipientId, payload }) => {
|
|
35
|
+
sms: async ({ deliveryId, recipientId, payload, signal }) => {
|
|
34
36
|
const recipient = await users.findContact(recipientId);
|
|
35
37
|
const result = await sendSMS({
|
|
36
38
|
to: recipient.phone,
|
|
37
39
|
text: payload.body,
|
|
40
|
+
idempotencyKey: deliveryId,
|
|
41
|
+
signal,
|
|
38
42
|
});
|
|
39
43
|
return { providerMessageId: result.id };
|
|
40
44
|
},
|
|
41
|
-
push: async ({ recipientId, payload }) => {
|
|
42
|
-
const result = await sendPush(recipientId, payload
|
|
45
|
+
push: async ({ deliveryId, recipientId, payload, signal }) => {
|
|
46
|
+
const result = await sendPush(recipientId, payload, {
|
|
47
|
+
idempotencyKey: deliveryId,
|
|
48
|
+
signal,
|
|
49
|
+
});
|
|
43
50
|
return { metadata: { sentDevices: result.sent } };
|
|
44
51
|
},
|
|
45
52
|
},
|
|
@@ -51,6 +58,12 @@ The adapter resolves addresses/subscriptions at delivery time. Email addresses,
|
|
|
51
58
|
phone numbers, Push subscriptions, provider credentials, and provider-specific
|
|
52
59
|
retry queues stay where they belong: in the application.
|
|
53
60
|
|
|
61
|
+
The application transport functions must honor `idempotencyKey` through
|
|
62
|
+
provider-side deduplication or a durable application queue. Merely accepting the
|
|
63
|
+
argument does not prevent duplicate effects. Pass `signal` to provider operations
|
|
64
|
+
that support cancellation; aborting a request does not prove the provider
|
|
65
|
+
rejected it.
|
|
66
|
+
|
|
54
67
|
## Install
|
|
55
68
|
|
|
56
69
|
```sh
|
|
@@ -113,14 +126,20 @@ is applied, but legacy fallback reads can be slower.
|
|
|
113
126
|
Upgrading to `0.1.5` adds the `unc_dispatch_state` table, or the same suffix
|
|
114
127
|
under a custom prefix. That table stores provider-agnostic channel rate-limit
|
|
115
128
|
windows and cooldowns. Generate and apply the schema diff through the
|
|
116
|
-
application's normal reviewed migration workflow before
|
|
117
|
-
`channelPolicies`
|
|
118
|
-
at runtime.
|
|
129
|
+
application's normal reviewed migration workflow before deploying the upgraded
|
|
130
|
+
package, even when `channelPolicies` and adapter `retryAfterMs` hints are unused.
|
|
131
|
+
Every dispatch reads this table. UNC never creates it at runtime.
|
|
119
132
|
|
|
120
133
|
The fallback delivery feature adds `fallback_enabled boolean not null default
|
|
121
134
|
false` to `unc_notifications`. Generate and apply that schema diff through the
|
|
122
|
-
application's normal reviewed migration workflow before
|
|
123
|
-
`fallbackDelaysMs
|
|
135
|
+
application's normal reviewed migration workflow before deploying this version,
|
|
136
|
+
even when `fallbackDelaysMs` is unused. Ordinary publication and dispatch also
|
|
137
|
+
reference this column.
|
|
138
|
+
|
|
139
|
+
This refactor also adds nullable `publication_fingerprint varchar(67)` to
|
|
140
|
+
`unc_notifications`. Apply that migration before deployment. Existing keyed
|
|
141
|
+
rows remain deliverable, but publication replay requires reconciliation because
|
|
142
|
+
their original intent cannot be verified. See [Adoption notes](./docs/adoption-notes.md).
|
|
124
143
|
|
|
125
144
|
## Define channels
|
|
126
145
|
|
|
@@ -128,13 +147,7 @@ Channel names are plain text, not a PostgreSQL enum. Adding a future channel
|
|
|
128
147
|
does not require a core release or enum migration:
|
|
129
148
|
|
|
130
149
|
```ts
|
|
131
|
-
type AppChannel =
|
|
132
|
-
| "in_app"
|
|
133
|
-
| "email"
|
|
134
|
-
| "sms"
|
|
135
|
-
| "push"
|
|
136
|
-
| "whatsapp"
|
|
137
|
-
| "slack";
|
|
150
|
+
type AppChannel = "in_app" | "email" | "sms" | "push" | "whatsapp" | "slack";
|
|
138
151
|
```
|
|
139
152
|
|
|
140
153
|
`in_app` is built in. Every other channel must have an adapter, which makes a
|
|
@@ -183,7 +196,9 @@ await notificationCore.publishAndDispatch({
|
|
|
183
196
|
|
|
184
197
|
UNC attempts only due channels. Once the recipient calls `markRead()`, the
|
|
185
198
|
remaining pending or retrying deliveries in that fallback publication become
|
|
186
|
-
`skipped`; an already-processing provider call cannot be recalled.
|
|
199
|
+
`skipped`; an already-processing provider call cannot be recalled. If that call
|
|
200
|
+
later fails while the notification is read, its delivery also becomes `skipped`.
|
|
201
|
+
Successful calls retain their `sent` history. Omitting
|
|
187
202
|
`fallbackDelaysMs` preserves ordinary fan-out behavior.
|
|
188
203
|
|
|
189
204
|
`publish()` only persists. `publishAndDispatch()` persists and immediately
|
|
@@ -246,6 +261,7 @@ const result = await notificationCore.dispatchUntilIdle({
|
|
|
246
261
|
concurrency: 10,
|
|
247
262
|
maxBatches: 25,
|
|
248
263
|
deadlineMs: 30_000,
|
|
264
|
+
signal: shutdownController.signal,
|
|
249
265
|
});
|
|
250
266
|
```
|
|
251
267
|
|
|
@@ -265,8 +281,32 @@ channel policy defers some rows. Runtime values must be finite positive
|
|
|
265
281
|
integers; invalid values fail before publishing, claiming, or calling a
|
|
266
282
|
provider.
|
|
267
283
|
|
|
284
|
+
`nextWakeAt()` is a read-only scheduling hint for the same supported channels.
|
|
285
|
+
It returns the earliest time a pending, retrying, or abandoned processing
|
|
286
|
+
delivery may need a dispatch, accounting for scheduling, retry and lease times,
|
|
287
|
+
channel cooldowns and configured rate limits; it returns `null` when none are
|
|
288
|
+
known. A due time is returned as the current time. This does not claim work or
|
|
289
|
+
guarantee that another worker has not claimed it. Applications own the timer,
|
|
290
|
+
must wake and recompute when committed changes can introduce earlier work, and
|
|
291
|
+
must rescan after startup or listener reconnection. Notifications are only
|
|
292
|
+
wake-up signals, not a replacement for the durable rows or worker claims.
|
|
293
|
+
|
|
294
|
+
`signal` comes from the application's request or shutdown lifecycle. The
|
|
295
|
+
deadline, abort signal, and persistent infrastructure failures stop new work and
|
|
296
|
+
signal already-started adapters. UNC allows 100 ms for callbacks to cooperate.
|
|
297
|
+
An adapter that does not settle produces `NotificationDispatchError`, whose
|
|
298
|
+
`completed` results are durable and whose `unresolvedDeliveryIds` must not be
|
|
299
|
+
treated as failed sends. Its `settled` promise observes already-started calls;
|
|
300
|
+
late completion can finalize them but cannot start another provider call.
|
|
301
|
+
Stopping dispatch leaves unsent durable work available to a later worker. Use
|
|
302
|
+
`cancel(notificationId)` when the business action itself has been canceled.
|
|
303
|
+
Aborting the wait cannot undo a remote effect. Database query timeouts remain
|
|
304
|
+
part of the application's driver configuration.
|
|
305
|
+
|
|
268
306
|
This can run from a cron handler, queue consumer, scheduled function, or an
|
|
269
|
-
application-owned interval. The package starts no
|
|
307
|
+
application-owned interval. The package starts no background worker and exposes
|
|
308
|
+
no port. Deadline and lease timers exist only during explicit dispatch and are
|
|
309
|
+
cleaned up when it settles.
|
|
270
310
|
Concurrent workers claim rows with `FOR UPDATE SKIP LOCKED`; abandoned
|
|
271
311
|
`processing` rows become eligible again after the configured lock timeout.
|
|
272
312
|
`workerId` is diagnostic (maximum 154 characters). Every claimed delivery gets
|
|
@@ -541,8 +581,29 @@ unsafe PostgreSQL characters are replaced before the diagnostic is persisted.
|
|
|
541
581
|
|
|
542
582
|
## Idempotency and scheduling
|
|
543
583
|
|
|
544
|
-
An `idempotencyKey` is unique per recipient.
|
|
545
|
-
returns the original notification and deliveries with `created:
|
|
584
|
+
An `idempotencyKey` is unique per recipient. Repeating the same normalized
|
|
585
|
+
publication returns the original notification and deliveries with `created:
|
|
586
|
+
false`. The key binds to payload, topic, ordered channels, actor/entity context,
|
|
587
|
+
explicit schedule, fallback delays, preference policy, and resolved attempt
|
|
588
|
+
limits. Object property order does not matter, and omitting `scheduledFor`
|
|
589
|
+
remains the same “publish now” intent across retries. Changed configuration
|
|
590
|
+
defaults can change the resolved intent.
|
|
591
|
+
|
|
592
|
+
Reusing a key with conflicting intent throws `NotificationIdempotencyError`
|
|
593
|
+
with code `idempotency_conflict` and rolls back the whole batch. The error
|
|
594
|
+
includes `recipientId` and `notificationId`. Read state, preference changes,
|
|
595
|
+
delivery attempts, and requeue do not change the original fingerprint.
|
|
596
|
+
|
|
597
|
+
Upgraded legacy keyed rows without a fingerprint throw
|
|
598
|
+
`idempotency_legacy_unverifiable` on publication replay. Their existing deliveries
|
|
599
|
+
remain usable. Do not assign a new key merely to bypass this error: that can
|
|
600
|
+
duplicate a real notification. Reconcile the original application event before
|
|
601
|
+
replaying it. See [Adoption notes](./docs/adoption-notes.md).
|
|
602
|
+
|
|
603
|
+
Publication deduplication does not guarantee exactly-once provider effects.
|
|
604
|
+
Pass the stable `deliveryId` into downstream deduplication. A process can die
|
|
605
|
+
after provider acceptance and before durable acknowledgment; recovery must reuse
|
|
606
|
+
the same provider identity.
|
|
546
607
|
|
|
547
608
|
`scheduledFor` delays all selected channels. `cancel(notificationId)` cancels
|
|
548
609
|
pending/retrying/processing deliveries. A provider callback already in flight
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type NotificationSchema } from "./schema.js";
|
|
2
|
+
import { type DeliveryAdapter, type JsonObject, type NotificationLogger, type PreferenceDefaults } from "./types.js";
|
|
3
|
+
import type { AnyPgDatabase, NormalizedChannelDispatchPolicy, NotificationCoreConfig } from "./contracts.js";
|
|
4
|
+
/** Validated, shared package dependencies. No delivery state lives here. */
|
|
5
|
+
export declare class CoreContext<TChannel extends string, TData extends JsonObject = JsonObject> {
|
|
6
|
+
readonly db: AnyPgDatabase;
|
|
7
|
+
readonly schema: NotificationSchema;
|
|
8
|
+
readonly adapters: Readonly<Record<string, DeliveryAdapter<TChannel, TData> | undefined>>;
|
|
9
|
+
readonly defaultChannels: readonly TChannel[];
|
|
10
|
+
readonly preferenceDefaults: PreferenceDefaults<TChannel>;
|
|
11
|
+
readonly defaultPreferenceEnabled: boolean;
|
|
12
|
+
readonly defaultMaxAttempts: number;
|
|
13
|
+
readonly channelPolicies: Readonly<Record<string, NormalizedChannelDispatchPolicy | undefined>>;
|
|
14
|
+
readonly retryDelayMs: (attempt: number, error: unknown) => number | Promise<number>;
|
|
15
|
+
readonly lockTimeoutMs: number;
|
|
16
|
+
readonly now: () => Date;
|
|
17
|
+
readonly logger: NotificationLogger | undefined;
|
|
18
|
+
constructor(config: NotificationCoreConfig<TChannel, TData>);
|
|
19
|
+
safeLog(level: "debug" | "error", message: string, context: JsonObject): void;
|
|
20
|
+
validateChannels(channels: readonly TChannel[]): void;
|
|
21
|
+
currentTime(): Date;
|
|
22
|
+
maxAttemptsFor(channel: TChannel, configured: number | Partial<Record<TChannel, number>> | undefined): number;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACV,aAAa,EACb,+BAA+B,EAC/B,sBAAsB,EACvB,MAAM,gBAAgB,CAAC;AAcxB,4EAA4E;AAC5E,qBAAa,WAAW,CACtB,QAAQ,SAAS,MAAM,EACvB,KAAK,SAAS,UAAU,GAAG,UAAU;IAErC,QAAQ,CAAC,EAAE,EAAE,aAAa,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,CAAC;IACpC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CACzB,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,SAAS,CAAC,CAC7D,CAAC;IACF,QAAQ,CAAC,eAAe,EAAE,SAAS,QAAQ,EAAE,CAAC;IAC9C,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC1D,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAC;IAC3C,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAChC,MAAM,CAAC,MAAM,EAAE,+BAA+B,GAAG,SAAS,CAAC,CAC5D,CAAC;IACF,QAAQ,CAAC,YAAY,EAAE,CACrB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,OAAO,KACX,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,IAAI,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,CAAC;gBAEpC,MAAM,EAAE,sBAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC;IA8G3D,OAAO,CACL,KAAK,EAAE,OAAO,GAAG,OAAO,EACxB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,UAAU,GAClB,IAAI;IAeP,gBAAgB,CAAC,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAAG,IAAI;IAcrD,WAAW,IAAI,IAAI;IAUnB,cAAc,CACZ,OAAO,EAAE,QAAQ,EACjB,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,GAAG,SAAS,GACjE,MAAM;CAQV"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var context_exports = {};
|
|
20
|
+
__export(context_exports, {
|
|
21
|
+
CoreContext: () => CoreContext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(context_exports);
|
|
24
|
+
var import_errors = require("./errors.js");
|
|
25
|
+
var import_keys = require("./keys.js");
|
|
26
|
+
var import_runtime = require("./runtime.js");
|
|
27
|
+
var import_schema = require("./schema.js");
|
|
28
|
+
var import_types = require("./types.js");
|
|
29
|
+
var import_validation = require("./validation.js");
|
|
30
|
+
class CoreContext {
|
|
31
|
+
db;
|
|
32
|
+
schema;
|
|
33
|
+
adapters;
|
|
34
|
+
defaultChannels;
|
|
35
|
+
preferenceDefaults;
|
|
36
|
+
defaultPreferenceEnabled;
|
|
37
|
+
defaultMaxAttempts;
|
|
38
|
+
channelPolicies;
|
|
39
|
+
retryDelayMs;
|
|
40
|
+
lockTimeoutMs;
|
|
41
|
+
now;
|
|
42
|
+
logger;
|
|
43
|
+
constructor(config) {
|
|
44
|
+
config = (0, import_runtime.capturePlainRecord)(
|
|
45
|
+
config,
|
|
46
|
+
"config",
|
|
47
|
+
import_validation.CONFIG_KEYS
|
|
48
|
+
);
|
|
49
|
+
if (!config.db || typeof config.db !== "object") {
|
|
50
|
+
throw new import_errors.NotificationConfigurationError("db must be a database object");
|
|
51
|
+
}
|
|
52
|
+
this.db = config.db;
|
|
53
|
+
const schema = Object.hasOwn(config, "schema") ? config.schema : import_schema.notificationSchema;
|
|
54
|
+
if (!schema || typeof schema !== "object" || (0, import_runtime.inspectArray)(schema, "schema")) {
|
|
55
|
+
throw new import_errors.NotificationConfigurationError("schema must be an object");
|
|
56
|
+
}
|
|
57
|
+
this.schema = schema;
|
|
58
|
+
const adapters = Object.hasOwn(config, "adapters") ? config.adapters : {};
|
|
59
|
+
this.adapters = (0, import_keys.normalizeChannelRecord)(
|
|
60
|
+
adapters,
|
|
61
|
+
"adapters"
|
|
62
|
+
);
|
|
63
|
+
for (const channel of Object.keys(this.adapters)) {
|
|
64
|
+
if (typeof this.adapters[channel] !== "function") {
|
|
65
|
+
throw new import_errors.NotificationConfigurationError(
|
|
66
|
+
`adapters value for channel "${channel}" must be a function`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
this.defaultChannels = (0, import_keys.normalizeUniqueNotificationKeys)(
|
|
71
|
+
Object.hasOwn(config, "defaultChannels") ? config.defaultChannels : [import_types.BUILT_IN_CHANNELS.IN_APP],
|
|
72
|
+
"defaultChannels",
|
|
73
|
+
64
|
|
74
|
+
);
|
|
75
|
+
this.preferenceDefaults = (0, import_keys.normalizePreferenceDefaults)(
|
|
76
|
+
Object.hasOwn(config, "preferenceDefaults") ? config.preferenceDefaults : {}
|
|
77
|
+
);
|
|
78
|
+
this.defaultPreferenceEnabled = Object.hasOwn(
|
|
79
|
+
config,
|
|
80
|
+
"defaultPreferenceEnabled"
|
|
81
|
+
) ? (0, import_validation.normalizeBoolean)(
|
|
82
|
+
config.defaultPreferenceEnabled,
|
|
83
|
+
"defaultPreferenceEnabled"
|
|
84
|
+
) : true;
|
|
85
|
+
this.defaultMaxAttempts = Object.hasOwn(config, "defaultMaxAttempts") ? (0, import_validation.normalizeMaxAttempts)(config.defaultMaxAttempts, "defaultMaxAttempts") : 5;
|
|
86
|
+
this.channelPolicies = (0, import_validation.normalizeChannelPolicies)(
|
|
87
|
+
Object.hasOwn(config, "channelPolicies") ? config.channelPolicies : void 0
|
|
88
|
+
);
|
|
89
|
+
const retryDelayMs = Object.hasOwn(config, "retryDelayMs") ? config.retryDelayMs : import_validation.defaultRetryDelayMs;
|
|
90
|
+
if (typeof retryDelayMs !== "function") {
|
|
91
|
+
throw new import_errors.NotificationConfigurationError(
|
|
92
|
+
"retryDelayMs must be a function"
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
this.retryDelayMs = retryDelayMs;
|
|
96
|
+
this.lockTimeoutMs = Object.hasOwn(config, "lockTimeoutMs") ? (0, import_validation.normalizePositiveInteger)(config.lockTimeoutMs, "lockTimeoutMs", 1e3) : 5 * 6e4;
|
|
97
|
+
const now = Object.hasOwn(config, "now") ? config.now : () => /* @__PURE__ */ new Date();
|
|
98
|
+
if (typeof now !== "function") {
|
|
99
|
+
throw new import_errors.NotificationConfigurationError("now must be a function");
|
|
100
|
+
}
|
|
101
|
+
this.now = now;
|
|
102
|
+
const logger = Object.hasOwn(config, "logger") ? config.logger : void 0;
|
|
103
|
+
if (Object.hasOwn(config, "logger") && (!logger || typeof logger !== "object" || (0, import_runtime.inspectArray)(logger, "logger"))) {
|
|
104
|
+
throw new import_errors.NotificationConfigurationError("logger must be an object");
|
|
105
|
+
}
|
|
106
|
+
const loggerSnapshot = logger ? (0, import_runtime.capturePlainRecord)(
|
|
107
|
+
logger,
|
|
108
|
+
"logger",
|
|
109
|
+
/* @__PURE__ */ new Set(["debug", "error"])
|
|
110
|
+
) : void 0;
|
|
111
|
+
for (const level of ["debug", "error"]) {
|
|
112
|
+
if (!loggerSnapshot || !Object.hasOwn(loggerSnapshot, level)) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (typeof loggerSnapshot[level] !== "function") {
|
|
116
|
+
throw new import_errors.NotificationConfigurationError(
|
|
117
|
+
`logger.${level} must be a function`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
this.logger = loggerSnapshot;
|
|
122
|
+
this.validateChannels(this.defaultChannels);
|
|
123
|
+
this.validateChannels(Object.keys(this.channelPolicies));
|
|
124
|
+
}
|
|
125
|
+
safeLog(level, message, context) {
|
|
126
|
+
try {
|
|
127
|
+
const callback = this.logger?.[level];
|
|
128
|
+
if (!callback) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const returned = callback(message, context);
|
|
132
|
+
if ((0, import_validation.isExactNativePromise)(returned)) {
|
|
133
|
+
(0, import_validation.attachNativePromiseObservation)(returned, () => {
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
} catch {
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
validateChannels(channels) {
|
|
140
|
+
for (const channel of channels) {
|
|
141
|
+
(0, import_validation.assertBounded)(channel, "channel", 64);
|
|
142
|
+
if (channel !== import_types.BUILT_IN_CHANNELS.IN_APP && !Object.hasOwn(this.adapters, channel)) {
|
|
143
|
+
throw new import_errors.NotificationConfigurationError(
|
|
144
|
+
`No adapter is configured for channel "${channel}"`
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
currentTime() {
|
|
150
|
+
let value;
|
|
151
|
+
try {
|
|
152
|
+
value = this.now();
|
|
153
|
+
} catch {
|
|
154
|
+
throw new import_errors.NotificationConfigurationError("now must return a valid Date");
|
|
155
|
+
}
|
|
156
|
+
return (0, import_validation.normalizeDate)(value, "now result");
|
|
157
|
+
}
|
|
158
|
+
maxAttemptsFor(channel, configured) {
|
|
159
|
+
const value = typeof configured === "number" ? configured : (0, import_keys.getOwnRecordValue)(configured, channel) ?? this.defaultMaxAttempts;
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
164
|
+
0 && (module.exports = {
|
|
165
|
+
CoreContext
|
|
166
|
+
});
|
|
167
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/context.ts"],
|
|
4
|
+
"sourcesContent": ["import { NotificationConfigurationError } from \"./errors.js\";\nimport {\n getOwnRecordValue,\n normalizeChannelRecord,\n normalizePreferenceDefaults,\n normalizeUniqueNotificationKeys,\n} from \"./keys.js\";\nimport { capturePlainRecord, inspectArray } from \"./runtime.js\";\nimport {\n notificationSchema as defaultNotificationSchema,\n type NotificationSchema,\n} from \"./schema.js\";\nimport {\n BUILT_IN_CHANNELS,\n type DeliveryAdapter,\n type JsonObject,\n type NotificationLogger,\n type PreferenceDefaults,\n} from \"./types.js\";\n\nimport type {\n AnyPgDatabase,\n NormalizedChannelDispatchPolicy,\n NotificationCoreConfig,\n} from \"./contracts.js\";\nimport {\n assertBounded,\n attachNativePromiseObservation,\n CONFIG_KEYS,\n defaultRetryDelayMs,\n isExactNativePromise,\n normalizeBoolean,\n normalizeChannelPolicies,\n normalizeDate,\n normalizeMaxAttempts,\n normalizePositiveInteger,\n} from \"./validation.js\";\n\n/** Validated, shared package dependencies. No delivery state lives here. */\nexport class CoreContext<\n TChannel extends string,\n TData extends JsonObject = JsonObject,\n> {\n readonly db: AnyPgDatabase;\n readonly schema: NotificationSchema;\n readonly adapters: Readonly<\n Record<string, DeliveryAdapter<TChannel, TData> | undefined>\n >;\n readonly defaultChannels: readonly TChannel[];\n readonly preferenceDefaults: PreferenceDefaults<TChannel>;\n readonly defaultPreferenceEnabled: boolean;\n readonly defaultMaxAttempts: number;\n readonly channelPolicies: Readonly<\n Record<string, NormalizedChannelDispatchPolicy | undefined>\n >;\n readonly retryDelayMs: (\n attempt: number,\n error: unknown,\n ) => number | Promise<number>;\n readonly lockTimeoutMs: number;\n readonly now: () => Date;\n readonly logger: NotificationLogger | undefined;\n\n constructor(config: NotificationCoreConfig<TChannel, TData>) {\n config = capturePlainRecord(\n config,\n \"config\",\n CONFIG_KEYS,\n ) as NotificationCoreConfig<TChannel, TData>;\n if (!config.db || typeof config.db !== \"object\") {\n throw new NotificationConfigurationError(\"db must be a database object\");\n }\n this.db = config.db;\n const schema = Object.hasOwn(config, \"schema\")\n ? config.schema\n : defaultNotificationSchema;\n if (\n !schema ||\n typeof schema !== \"object\" ||\n inspectArray(schema, \"schema\")\n ) {\n throw new NotificationConfigurationError(\"schema must be an object\");\n }\n this.schema = schema;\n const adapters = Object.hasOwn(config, \"adapters\") ? config.adapters : {};\n this.adapters = normalizeChannelRecord<DeliveryAdapter<TChannel, TData>>(\n adapters as unknown as Readonly<\n Record<string, DeliveryAdapter<TChannel, TData> | undefined>\n >,\n \"adapters\",\n );\n for (const channel of Object.keys(this.adapters)) {\n if (typeof this.adapters[channel] !== \"function\") {\n throw new NotificationConfigurationError(\n `adapters value for channel \"${channel}\" must be a function`,\n );\n }\n }\n this.defaultChannels = normalizeUniqueNotificationKeys(\n Object.hasOwn(config, \"defaultChannels\")\n ? (config.defaultChannels as readonly TChannel[])\n : ([BUILT_IN_CHANNELS.IN_APP] as TChannel[]),\n \"defaultChannels\",\n 64,\n ) as TChannel[];\n this.preferenceDefaults = normalizePreferenceDefaults(\n Object.hasOwn(config, \"preferenceDefaults\")\n ? (config.preferenceDefaults as PreferenceDefaults<TChannel>)\n : {},\n );\n this.defaultPreferenceEnabled = Object.hasOwn(\n config,\n \"defaultPreferenceEnabled\",\n )\n ? normalizeBoolean(\n config.defaultPreferenceEnabled,\n \"defaultPreferenceEnabled\",\n )\n : true;\n this.defaultMaxAttempts = Object.hasOwn(config, \"defaultMaxAttempts\")\n ? normalizeMaxAttempts(config.defaultMaxAttempts, \"defaultMaxAttempts\")\n : 5;\n this.channelPolicies = normalizeChannelPolicies(\n Object.hasOwn(config, \"channelPolicies\")\n ? config.channelPolicies\n : undefined,\n );\n const retryDelayMs = Object.hasOwn(config, \"retryDelayMs\")\n ? config.retryDelayMs\n : defaultRetryDelayMs;\n if (typeof retryDelayMs !== \"function\") {\n throw new NotificationConfigurationError(\n \"retryDelayMs must be a function\",\n );\n }\n this.retryDelayMs = retryDelayMs;\n this.lockTimeoutMs = Object.hasOwn(config, \"lockTimeoutMs\")\n ? normalizePositiveInteger(config.lockTimeoutMs, \"lockTimeoutMs\", 1_000)\n : 5 * 60_000;\n const now = Object.hasOwn(config, \"now\") ? config.now : () => new Date();\n if (typeof now !== \"function\") {\n throw new NotificationConfigurationError(\"now must be a function\");\n }\n this.now = now;\n const logger = Object.hasOwn(config, \"logger\") ? config.logger : undefined;\n if (\n Object.hasOwn(config, \"logger\") &&\n (!logger || typeof logger !== \"object\" || inspectArray(logger, \"logger\"))\n ) {\n throw new NotificationConfigurationError(\"logger must be an object\");\n }\n const loggerSnapshot = logger\n ? (capturePlainRecord(\n logger,\n \"logger\",\n new Set([\"debug\", \"error\"]),\n ) as NotificationLogger)\n : undefined;\n for (const level of [\"debug\", \"error\"] as const) {\n if (!loggerSnapshot || !Object.hasOwn(loggerSnapshot, level)) {\n continue;\n }\n if (typeof loggerSnapshot[level] !== \"function\") {\n throw new NotificationConfigurationError(\n `logger.${level} must be a function`,\n );\n }\n }\n this.logger = loggerSnapshot;\n this.validateChannels(this.defaultChannels);\n this.validateChannels(Object.keys(this.channelPolicies) as TChannel[]);\n }\n\n safeLog(\n level: \"debug\" | \"error\",\n message: string,\n context: JsonObject,\n ): void {\n try {\n const callback = this.logger?.[level];\n if (!callback) {\n return;\n }\n const returned = callback(message, context) as unknown;\n if (isExactNativePromise(returned)) {\n attachNativePromiseObservation(returned, () => {});\n }\n } catch {\n // Observability is deliberately isolated from durable delivery state.\n }\n }\n\n validateChannels(channels: readonly TChannel[]): void {\n for (const channel of channels) {\n assertBounded(channel, \"channel\", 64);\n if (\n channel !== BUILT_IN_CHANNELS.IN_APP &&\n !Object.hasOwn(this.adapters, channel)\n ) {\n throw new NotificationConfigurationError(\n `No adapter is configured for channel \"${channel}\"`,\n );\n }\n }\n }\n\n currentTime(): Date {\n let value: unknown;\n try {\n value = this.now();\n } catch {\n throw new NotificationConfigurationError(\"now must return a valid Date\");\n }\n return normalizeDate(value, \"now result\");\n }\n\n maxAttemptsFor(\n channel: TChannel,\n configured: number | Partial<Record<TChannel, number>> | undefined,\n ): number {\n const value =\n typeof configured === \"number\"\n ? configured\n : (getOwnRecordValue<number>(configured, channel) ??\n this.defaultMaxAttempts);\n return value;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+C;AAC/C,kBAKO;AACP,qBAAiD;AACjD,oBAGO;AACP,mBAMO;AAOP,wBAWO;AAGA,MAAM,YAGX;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EAGA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M,WAAW,KAAK,SAAS,KAAK;AACpC,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AACA,YAAM,WAAW,SAAS,SAAS,OAAO;AAC1C,cAAI,wCAAqB,QAAQ,GAAG;AAClC,8DAA+B,UAAU,MAAM;AAAA,QAAC,CAAC;AAAA,MACnD;AAAA,IACF,QAAQ;AAAA,IAER;AAAA,EACF;AAAA,EAEA,iBAAiB,UAAqC;AACpD,eAAW,WAAW,UAAU;AAC9B,2CAAc,SAAS,WAAW,EAAE;AACpC,UACE,YAAY,+BAAkB,UAC9B,CAAC,OAAO,OAAO,KAAK,UAAU,OAAO,GACrC;AACA,cAAM,IAAI;AAAA,UACR,yCAAyC,OAAO;AAAA,QAClD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,cAAoB;AAClB,QAAI;AACJ,QAAI;AACF,cAAQ,KAAK,IAAI;AAAA,IACnB,QAAQ;AACN,YAAM,IAAI,6CAA+B,8BAA8B;AAAA,IACzE;AACA,eAAO,iCAAc,OAAO,YAAY;AAAA,EAC1C;AAAA,EAEA,eACE,SACA,YACQ;AACR,UAAM,QACJ,OAAO,eAAe,WAClB,iBACC,+BAA0B,YAAY,OAAO,KAC9C,KAAK;AACX,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["defaultNotificationSchema"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type PgDatabase } from "drizzle-orm/pg-core";
|
|
2
|
+
import { type NotificationSchema } from "./schema.js";
|
|
3
|
+
import { type DeliveryAdapters, type DeliveryStatus, type DispatchResult, type JsonObject, type JsonValue, type NotificationLogger, type PreferenceDefaults } from "./types.js";
|
|
4
|
+
export type AnyPgDatabase = PgDatabase<any, any, any>;
|
|
5
|
+
export type DispatchOptions = {
|
|
6
|
+
limit?: number;
|
|
7
|
+
workerId?: string;
|
|
8
|
+
concurrency?: number;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
deadlineMs?: number;
|
|
11
|
+
};
|
|
12
|
+
export type DispatchUntilIdleOptions = DispatchOptions & {
|
|
13
|
+
limit?: number;
|
|
14
|
+
workerId?: string;
|
|
15
|
+
concurrency?: number;
|
|
16
|
+
maxBatches?: number;
|
|
17
|
+
deadlineMs?: number;
|
|
18
|
+
stopOnFailureRatio?: number;
|
|
19
|
+
stopOnFailureCount?: number;
|
|
20
|
+
};
|
|
21
|
+
export type DispatchUntilIdleStopReason = "idle" | "maxBatches" | "deadline" | "aborted" | "failure-threshold" | "rate-limited";
|
|
22
|
+
export type DispatchUntilIdleResult<TChannel extends string = string> = {
|
|
23
|
+
batches: number;
|
|
24
|
+
reason: DispatchUntilIdleStopReason;
|
|
25
|
+
dispatched: Array<DispatchResult<TChannel>>;
|
|
26
|
+
deferredUntil?: Date;
|
|
27
|
+
};
|
|
28
|
+
export type ChannelRateLimitPolicy = {
|
|
29
|
+
max: number;
|
|
30
|
+
windowMs: number;
|
|
31
|
+
};
|
|
32
|
+
export type ChannelCircuitBreakerPolicy = {
|
|
33
|
+
failureRatio?: number;
|
|
34
|
+
minAttempts?: number;
|
|
35
|
+
cooldownMs?: number;
|
|
36
|
+
};
|
|
37
|
+
export type ChannelDispatchPolicy = {
|
|
38
|
+
rateLimit?: ChannelRateLimitPolicy;
|
|
39
|
+
circuitBreaker?: ChannelCircuitBreakerPolicy;
|
|
40
|
+
};
|
|
41
|
+
export type NotificationCoreConfig<TChannel extends string, TData extends JsonObject = JsonObject> = {
|
|
42
|
+
db: AnyPgDatabase;
|
|
43
|
+
schema?: NotificationSchema;
|
|
44
|
+
adapters?: DeliveryAdapters<TChannel, TData>;
|
|
45
|
+
defaultChannels?: readonly TChannel[];
|
|
46
|
+
preferenceDefaults?: PreferenceDefaults<TChannel>;
|
|
47
|
+
defaultPreferenceEnabled?: boolean;
|
|
48
|
+
defaultMaxAttempts?: number;
|
|
49
|
+
channelPolicies?: Partial<Record<TChannel, ChannelDispatchPolicy>>;
|
|
50
|
+
retryDelayMs?: (attempt: number, error: unknown) => number | Promise<number>;
|
|
51
|
+
lockTimeoutMs?: number;
|
|
52
|
+
now?: () => Date;
|
|
53
|
+
logger?: NotificationLogger;
|
|
54
|
+
};
|
|
55
|
+
export type ClaimedDelivery<TChannel extends string, TData extends JsonObject> = {
|
|
56
|
+
deliveryId: string;
|
|
57
|
+
notificationId: string;
|
|
58
|
+
recipientId: string;
|
|
59
|
+
topic: string;
|
|
60
|
+
channel: TChannel;
|
|
61
|
+
payload: {
|
|
62
|
+
title: string;
|
|
63
|
+
body: string;
|
|
64
|
+
actionUrl?: string;
|
|
65
|
+
data?: TData;
|
|
66
|
+
channelData?: Partial<Record<TChannel, JsonValue>>;
|
|
67
|
+
};
|
|
68
|
+
attempts: number;
|
|
69
|
+
maxAttempts: number;
|
|
70
|
+
createdAt: Date;
|
|
71
|
+
scheduledFor: Date;
|
|
72
|
+
actorId: string | null;
|
|
73
|
+
entityType: string | null;
|
|
74
|
+
entityId: string | null;
|
|
75
|
+
claimToken: string;
|
|
76
|
+
claimedAt: Date;
|
|
77
|
+
claimedMonotonicAt: number;
|
|
78
|
+
};
|
|
79
|
+
export type DurableDispatchState = {
|
|
80
|
+
status: DeliveryStatus;
|
|
81
|
+
attempts: number;
|
|
82
|
+
errorCode: string | null;
|
|
83
|
+
errorMessage: string | null;
|
|
84
|
+
};
|
|
85
|
+
export type NormalizedChannelDispatchPolicy = {
|
|
86
|
+
rateLimit?: {
|
|
87
|
+
max: number;
|
|
88
|
+
windowMs: number;
|
|
89
|
+
};
|
|
90
|
+
circuitBreaker?: {
|
|
91
|
+
failureRatio: number;
|
|
92
|
+
minAttempts: number;
|
|
93
|
+
cooldownMs: number;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
export type DispatchBatch<TChannel extends string> = {
|
|
97
|
+
results: Array<DispatchResult<TChannel>>;
|
|
98
|
+
deferredUntil?: Date;
|
|
99
|
+
stopped?: "deadline" | "aborted";
|
|
100
|
+
};
|
|
101
|
+
export type DispatchAttemptOutcome<TChannel extends string> = {
|
|
102
|
+
result: DispatchResult<TChannel>;
|
|
103
|
+
};
|
|
104
|
+
export type NormalizedAdapterResult = {
|
|
105
|
+
providerMessageId: string | null;
|
|
106
|
+
metadata: JsonObject | null;
|
|
107
|
+
diagnostic: string | null;
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEtD,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,eAAe,GAAG;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CA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ACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,SAAS,CAAC,EAAE;QACV,GAAG,EAAE,MAAM,CAAC;QACZ,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,cAAc,CAAC,EAAE;QACf,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,aAAa,CAAC,QAAQ,SAAS,MAAM,IAAI;IACnD,OAAO,EAAE,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,QAAQ,SAAS,MAAM,IAAI;IAC5D,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var contracts_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(contracts_exports);
|
|
17
|
+
var import_pg_core = require("drizzle-orm/pg-core");
|
|
18
|
+
var import_schema = require("./schema.js");
|
|
19
|
+
var import_types = require("./types.js");
|
|
20
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/contracts.ts"],
|
|
4
|
+
"sourcesContent": ["import { type PgDatabase } from \"drizzle-orm/pg-core\";\n\nimport { type NotificationSchema } from \"./schema.js\";\nimport {\n type DeliveryAdapters,\n type DeliveryStatus,\n type DispatchResult,\n type JsonObject,\n type JsonValue,\n type NotificationLogger,\n type PreferenceDefaults,\n} from \"./types.js\";\n\nexport type AnyPgDatabase = PgDatabase<any, any, any>;\n\nexport type DispatchOptions = {\n limit?: number;\n workerId?: string;\n concurrency?: number;\n signal?: AbortSignal;\n deadlineMs?: number;\n};\n\nexport type DispatchUntilIdleOptions = DispatchOptions & {\n limit?: number;\n workerId?: string;\n concurrency?: number;\n maxBatches?: number;\n deadlineMs?: number;\n stopOnFailureRatio?: number;\n stopOnFailureCount?: number;\n};\n\nexport type DispatchUntilIdleStopReason =\n | \"idle\"\n | \"maxBatches\"\n | \"deadline\"\n | \"aborted\"\n | \"failure-threshold\"\n | \"rate-limited\";\n\nexport type DispatchUntilIdleResult<TChannel extends string = string> = {\n batches: number;\n reason: DispatchUntilIdleStopReason;\n dispatched: Array<DispatchResult<TChannel>>;\n deferredUntil?: Date;\n};\n\nexport type ChannelRateLimitPolicy = {\n max: number;\n windowMs: number;\n};\n\nexport type ChannelCircuitBreakerPolicy = {\n failureRatio?: number;\n minAttempts?: number;\n cooldownMs?: number;\n};\n\nexport type ChannelDispatchPolicy = {\n rateLimit?: ChannelRateLimitPolicy;\n circuitBreaker?: ChannelCircuitBreakerPolicy;\n};\n\nexport type NotificationCoreConfig<\n TChannel extends string,\n TData extends JsonObject = JsonObject,\n> = {\n db: AnyPgDatabase;\n schema?: NotificationSchema;\n adapters?: DeliveryAdapters<TChannel, TData>;\n defaultChannels?: readonly TChannel[];\n preferenceDefaults?: PreferenceDefaults<TChannel>;\n defaultPreferenceEnabled?: boolean;\n defaultMaxAttempts?: number;\n channelPolicies?: Partial<Record<TChannel, ChannelDispatchPolicy>>;\n retryDelayMs?: (attempt: number, error: unknown) => number | Promise<number>;\n lockTimeoutMs?: number;\n now?: () => Date;\n logger?: NotificationLogger;\n};\n\nexport type ClaimedDelivery<\n TChannel extends string,\n TData extends JsonObject,\n> = {\n deliveryId: string;\n notificationId: string;\n recipientId: string;\n topic: string;\n channel: TChannel;\n payload: {\n title: string;\n body: string;\n actionUrl?: string;\n data?: TData;\n channelData?: Partial<Record<TChannel, JsonValue>>;\n };\n attempts: number;\n maxAttempts: number;\n createdAt: Date;\n scheduledFor: Date;\n actorId: string | null;\n entityType: string | null;\n entityId: string | null;\n claimToken: string;\n claimedAt: Date;\n claimedMonotonicAt: number;\n};\n\nexport type DurableDispatchState = {\n status: DeliveryStatus;\n attempts: number;\n errorCode: string | null;\n errorMessage: string | null;\n};\n\nexport type NormalizedChannelDispatchPolicy = {\n rateLimit?: {\n max: number;\n windowMs: number;\n };\n circuitBreaker?: {\n failureRatio: number;\n minAttempts: number;\n cooldownMs: number;\n };\n};\n\nexport type DispatchBatch<TChannel extends string> = {\n results: Array<DispatchResult<TChannel>>;\n deferredUntil?: Date;\n stopped?: \"deadline\" | \"aborted\";\n};\n\nexport type DispatchAttemptOutcome<TChannel extends string> = {\n result: DispatchResult<TChannel>;\n};\n\nexport type NormalizedAdapterResult = {\n providerMessageId: string | null;\n metadata: JsonObject | null;\n diagnostic: string | null;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA,qBAAgC;AAEhC,oBAAwC;AACxC,mBAQO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type DispatchResult, type JsonObject, type PublishedNotification, type PublishInput } from "./types.js";
|
|
2
|
+
import type { NotificationCoreConfig } from "./contracts.js";
|
|
3
|
+
import { DeliveryAdmin } from "./delivery-admin.js";
|
|
4
|
+
import { Dispatcher } from "./dispatcher.js";
|
|
5
|
+
import { InboxService } from "./inbox.js";
|
|
6
|
+
import { PreferenceStore } from "./preference-store.js";
|
|
7
|
+
import { PublicationService } from "./publication.js";
|
|
8
|
+
export type { ChannelCircuitBreakerPolicy, ChannelDispatchPolicy, ChannelRateLimitPolicy, DispatchUntilIdleOptions, DispatchUntilIdleResult, DispatchUntilIdleStopReason, NotificationCoreConfig, } from "./contracts.js";
|
|
9
|
+
/** Public facade. Each service owns one notification concern. */
|
|
10
|
+
export declare class UnifiedNotificationCore<TChannel extends string, TData extends JsonObject = JsonObject> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(config: NotificationCoreConfig<TChannel, TData>);
|
|
13
|
+
publish(...args: Parameters<PublicationService<TChannel, TData>["publish"]>): ReturnType<PublicationService<TChannel, TData>["publish"]>;
|
|
14
|
+
setPreference(...args: Parameters<PreferenceStore<TChannel, TData>["setPreference"]>): ReturnType<PreferenceStore<TChannel, TData>["setPreference"]>;
|
|
15
|
+
setPreferences(...args: Parameters<PreferenceStore<TChannel, TData>["setPreferences"]>): ReturnType<PreferenceStore<TChannel, TData>["setPreferences"]>;
|
|
16
|
+
clearPreference(...args: Parameters<PreferenceStore<TChannel, TData>["clearPreference"]>): ReturnType<PreferenceStore<TChannel, TData>["clearPreference"]>;
|
|
17
|
+
getPreferences(...args: Parameters<PreferenceStore<TChannel, TData>["getPreferences"]>): ReturnType<PreferenceStore<TChannel, TData>["getPreferences"]>;
|
|
18
|
+
listInbox(...args: Parameters<InboxService<TChannel, TData>["listInbox"]>): ReturnType<InboxService<TChannel, TData>["listInbox"]>;
|
|
19
|
+
unreadCount(...args: Parameters<InboxService<TChannel, TData>["unreadCount"]>): ReturnType<InboxService<TChannel, TData>["unreadCount"]>;
|
|
20
|
+
markRead(...args: Parameters<InboxService<TChannel, TData>["markRead"]>): ReturnType<InboxService<TChannel, TData>["markRead"]>;
|
|
21
|
+
archive(...args: Parameters<InboxService<TChannel, TData>["archive"]>): ReturnType<InboxService<TChannel, TData>["archive"]>;
|
|
22
|
+
cancel(...args: Parameters<DeliveryAdmin<TChannel, TData>["cancel"]>): ReturnType<DeliveryAdmin<TChannel, TData>["cancel"]>;
|
|
23
|
+
requeueDelivery(...args: Parameters<DeliveryAdmin<TChannel, TData>["requeueDelivery"]>): ReturnType<DeliveryAdmin<TChannel, TData>["requeueDelivery"]>;
|
|
24
|
+
dispatchDue(...args: Parameters<Dispatcher<TChannel, TData>["dispatchDue"]>): ReturnType<Dispatcher<TChannel, TData>["dispatchDue"]>;
|
|
25
|
+
dispatchUntilIdle(...args: Parameters<Dispatcher<TChannel, TData>["dispatchUntilIdle"]>): ReturnType<Dispatcher<TChannel, TData>["dispatchUntilIdle"]>;
|
|
26
|
+
/** Earliest time supported work can need dispatch; null means no known work. */
|
|
27
|
+
nextWakeAt(): Promise<Date | null>;
|
|
28
|
+
publishAndDispatch(input: PublishInput<TChannel, TData>, options?: {
|
|
29
|
+
workerId?: string;
|
|
30
|
+
concurrency?: number;
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
deadlineMs?: number;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
published: Array<PublishedNotification<TChannel>>;
|
|
35
|
+
dispatched: Array<DispatchResult<TChannel>>;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export declare function createNotificationCore<TChannel extends string, TData extends JsonObject = JsonObject>(config: NotificationCoreConfig<TChannel, TData>): UnifiedNotificationCore<TChannel, TData>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