unified-notification-core 0.1.7 → 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 +34 -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 -1787
- 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
|
@@ -0,0 +1,526 @@
|
|
|
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 delivery_store_exports = {};
|
|
20
|
+
__export(delivery_store_exports, {
|
|
21
|
+
DeliveryStore: () => DeliveryStore
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(delivery_store_exports);
|
|
24
|
+
var import_dispatch_control = require("./dispatch-control.js");
|
|
25
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
26
|
+
var import_keys = require("./keys.js");
|
|
27
|
+
var import_types = require("./types.js");
|
|
28
|
+
var import_context = require("./context.js");
|
|
29
|
+
var import_validation = require("./validation.js");
|
|
30
|
+
class DeliveryStore {
|
|
31
|
+
constructor(context) {
|
|
32
|
+
this.context = context;
|
|
33
|
+
}
|
|
34
|
+
context;
|
|
35
|
+
async finalizeBuiltInInApp(deliveries) {
|
|
36
|
+
const { notificationDeliveries } = this.context.schema;
|
|
37
|
+
const deliveryIds = deliveries.map((delivery) => delivery.deliveryId);
|
|
38
|
+
const claimTokens = deliveries.map((delivery) => delivery.claimToken);
|
|
39
|
+
const now = deliveries[0]?.claimedAt;
|
|
40
|
+
if (!now) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const persisted = await (0, import_dispatch_control.persistOutcome)(
|
|
44
|
+
async () => this.context.db.update(notificationDeliveries).set({
|
|
45
|
+
status: "sent",
|
|
46
|
+
nextAttemptAt: null,
|
|
47
|
+
lockedAt: null,
|
|
48
|
+
lockedBy: null,
|
|
49
|
+
sentAt: now,
|
|
50
|
+
providerMessageId: null,
|
|
51
|
+
metadata: null,
|
|
52
|
+
errorCode: null,
|
|
53
|
+
errorMessage: null,
|
|
54
|
+
updatedAt: now
|
|
55
|
+
}).where(
|
|
56
|
+
(0, import_drizzle_orm.and)(
|
|
57
|
+
(0, import_drizzle_orm.inArray)(notificationDeliveries.id, deliveryIds),
|
|
58
|
+
(0, import_drizzle_orm.inArray)(notificationDeliveries.lockedBy, claimTokens),
|
|
59
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.status, "processing")
|
|
60
|
+
)
|
|
61
|
+
).returning({
|
|
62
|
+
id: notificationDeliveries.id,
|
|
63
|
+
status: notificationDeliveries.status,
|
|
64
|
+
attempts: notificationDeliveries.attempts,
|
|
65
|
+
errorCode: notificationDeliveries.errorCode,
|
|
66
|
+
errorMessage: notificationDeliveries.errorMessage
|
|
67
|
+
})
|
|
68
|
+
);
|
|
69
|
+
const persistedById = new Map(
|
|
70
|
+
persisted.map((row) => [
|
|
71
|
+
row.id,
|
|
72
|
+
{
|
|
73
|
+
status: row.status,
|
|
74
|
+
attempts: row.attempts,
|
|
75
|
+
errorCode: row.errorCode,
|
|
76
|
+
errorMessage: row.errorMessage
|
|
77
|
+
}
|
|
78
|
+
])
|
|
79
|
+
);
|
|
80
|
+
const results = [];
|
|
81
|
+
for (const delivery of deliveries) {
|
|
82
|
+
results.push(
|
|
83
|
+
await this.durableDispatchResult(
|
|
84
|
+
delivery,
|
|
85
|
+
persistedById.get(delivery.deliveryId)
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return results;
|
|
90
|
+
}
|
|
91
|
+
/** Admission locks follow the package-wide channel -> notification -> delivery
|
|
92
|
+
* order. Only time measured after every lock can establish a live lease. */
|
|
93
|
+
async admit(delivery) {
|
|
94
|
+
const { notifications, notificationDeliveries, notificationDispatchState } = this.context.schema;
|
|
95
|
+
return this.context.db.transaction(async (tx) => {
|
|
96
|
+
const [state] = await tx.select().from(notificationDispatchState).where(
|
|
97
|
+
(0, import_drizzle_orm.eq)(notificationDispatchState.key, (0, import_validation.dispatchStateKey)(delivery.channel))
|
|
98
|
+
).for("update");
|
|
99
|
+
if (!state)
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Missing dispatch state for channel "${delivery.channel}"`
|
|
102
|
+
);
|
|
103
|
+
const [notification] = await tx.select({
|
|
104
|
+
canceledAt: notifications.canceledAt,
|
|
105
|
+
fallbackEnabled: notifications.fallbackEnabled,
|
|
106
|
+
readAt: notifications.readAt
|
|
107
|
+
}).from(notifications).where((0, import_drizzle_orm.eq)(notifications.id, delivery.notificationId)).for("update");
|
|
108
|
+
const [current] = await tx.select({
|
|
109
|
+
lockedAt: notificationDeliveries.lockedAt,
|
|
110
|
+
lockedBy: notificationDeliveries.lockedBy,
|
|
111
|
+
status: notificationDeliveries.status
|
|
112
|
+
}).from(notificationDeliveries).where((0, import_drizzle_orm.eq)(notificationDeliveries.id, delivery.deliveryId)).for("update");
|
|
113
|
+
const now = this.elapsedClaimTime(delivery);
|
|
114
|
+
if (!notification || notification.canceledAt || notification.fallbackEnabled && notification.readAt || state.cooldownUntil && state.cooldownUntil > now || !current || current.lockedBy !== delivery.claimToken || current.status !== "processing" || !current.lockedAt || current.lockedAt.getTime() < now.getTime() - this.context.lockTimeoutMs)
|
|
115
|
+
return void 0;
|
|
116
|
+
const renewedAt = new Date(
|
|
117
|
+
Math.max(now.getTime(), current.lockedAt.getTime())
|
|
118
|
+
);
|
|
119
|
+
await tx.update(notificationDeliveries).set({ lockedAt: renewedAt, updatedAt: renewedAt }).where(
|
|
120
|
+
(0, import_drizzle_orm.and)(
|
|
121
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.id, delivery.deliveryId),
|
|
122
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.lockedBy, delivery.claimToken)
|
|
123
|
+
)
|
|
124
|
+
);
|
|
125
|
+
return now;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/** Renewal checks ownership and lease freshness after its delivery lock wait.
|
|
129
|
+
* A late renewal cannot revive an expired claim or backdate a newer lease. */
|
|
130
|
+
async renew(delivery, stillActive) {
|
|
131
|
+
const { notificationDeliveries } = this.context.schema;
|
|
132
|
+
return this.context.db.transaction(async (tx) => {
|
|
133
|
+
const [current] = await tx.select({
|
|
134
|
+
lockedAt: notificationDeliveries.lockedAt,
|
|
135
|
+
lockedBy: notificationDeliveries.lockedBy,
|
|
136
|
+
status: notificationDeliveries.status
|
|
137
|
+
}).from(notificationDeliveries).where((0, import_drizzle_orm.eq)(notificationDeliveries.id, delivery.deliveryId)).for("update");
|
|
138
|
+
if (!stillActive()) return false;
|
|
139
|
+
const now = this.elapsedClaimTime(delivery);
|
|
140
|
+
if (!current || current.lockedBy !== delivery.claimToken || current.status !== "processing" && current.status !== "canceled" || !current.lockedAt || current.lockedAt.getTime() < now.getTime() - this.context.lockTimeoutMs)
|
|
141
|
+
return false;
|
|
142
|
+
const renewedAt = new Date(
|
|
143
|
+
Math.max(now.getTime(), current.lockedAt.getTime())
|
|
144
|
+
);
|
|
145
|
+
await tx.update(notificationDeliveries).set({ lockedAt: renewedAt, updatedAt: renewedAt }).where(
|
|
146
|
+
(0, import_drizzle_orm.and)(
|
|
147
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.id, delivery.deliveryId),
|
|
148
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.lockedBy, delivery.claimToken)
|
|
149
|
+
)
|
|
150
|
+
);
|
|
151
|
+
return true;
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
/** Anchor elapsed work to the validated pre-provider clock, never application code. */
|
|
155
|
+
elapsedClaimTime(delivery) {
|
|
156
|
+
return new Date(
|
|
157
|
+
Math.min(
|
|
158
|
+
864e13,
|
|
159
|
+
delivery.claimedAt.getTime() + Math.max(0, (0, import_validation.MONOTONIC_NOW)() - delivery.claimedMonotonicAt)
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
/** Return work that never reached an adapter without consuming an attempt. */
|
|
164
|
+
async releaseUnstarted(delivery) {
|
|
165
|
+
const { notifications, notificationDeliveries } = this.context.schema;
|
|
166
|
+
await (0, import_dispatch_control.persistOutcome)(
|
|
167
|
+
() => this.context.db.transaction(async (tx) => {
|
|
168
|
+
const [notification] = await tx.select({
|
|
169
|
+
fallbackEnabled: notifications.fallbackEnabled,
|
|
170
|
+
readAt: notifications.readAt
|
|
171
|
+
}).from(notifications).where((0, import_drizzle_orm.eq)(notifications.id, delivery.notificationId)).for("update");
|
|
172
|
+
const satisfied = Boolean(
|
|
173
|
+
notification?.fallbackEnabled && notification.readAt
|
|
174
|
+
);
|
|
175
|
+
return tx.update(notificationDeliveries).set({
|
|
176
|
+
status: import_drizzle_orm.sql`case when ${notificationDeliveries.status} = 'canceled' then 'canceled' when ${satisfied} then 'skipped' else 'retrying' end`,
|
|
177
|
+
attempts: import_drizzle_orm.sql`greatest(0, ${notificationDeliveries.attempts} - 1)`,
|
|
178
|
+
nextAttemptAt: import_drizzle_orm.sql`case when ${notificationDeliveries.status} = 'canceled' or ${satisfied} then null::timestamptz else ${delivery.claimedAt}::timestamptz end`,
|
|
179
|
+
errorCode: import_drizzle_orm.sql`case when ${satisfied} then 'fallback_satisfied' else ${notificationDeliveries.errorCode} end`,
|
|
180
|
+
errorMessage: import_drizzle_orm.sql`case when ${satisfied} then 'Notification already read' else ${notificationDeliveries.errorMessage} end`,
|
|
181
|
+
lockedAt: null,
|
|
182
|
+
lockedBy: null,
|
|
183
|
+
updatedAt: delivery.claimedAt
|
|
184
|
+
}).where(
|
|
185
|
+
(0, import_drizzle_orm.and)(
|
|
186
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.id, delivery.deliveryId),
|
|
187
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.lockedBy, delivery.claimToken),
|
|
188
|
+
(0, import_drizzle_orm.inArray)(notificationDeliveries.status, [
|
|
189
|
+
"processing",
|
|
190
|
+
"canceled"
|
|
191
|
+
])
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
async claimDue(input) {
|
|
198
|
+
const { notifications, notificationDeliveries, notificationDispatchState } = this.context.schema;
|
|
199
|
+
const now = input.now ?? this.context.currentTime();
|
|
200
|
+
const claimedMonotonicAt = (0, import_validation.MONOTONIC_NOW)();
|
|
201
|
+
const supportedChannels = input.channels ? [...input.channels] : [import_types.BUILT_IN_CHANNELS.IN_APP, ...Object.keys(this.context.adapters)];
|
|
202
|
+
const supportedChannelFilter = (0, import_drizzle_orm.inArray)(
|
|
203
|
+
notificationDeliveries.channel,
|
|
204
|
+
supportedChannels
|
|
205
|
+
);
|
|
206
|
+
const staleBefore = new Date(now.getTime() - this.context.lockTimeoutMs);
|
|
207
|
+
return this.context.db.transaction(async (tx) => {
|
|
208
|
+
const claimed = [];
|
|
209
|
+
let deferredUntil;
|
|
210
|
+
const configuredChannels = [...new Set(supportedChannels)].sort();
|
|
211
|
+
if (!configuredChannels.length) return { claimed };
|
|
212
|
+
await tx.insert(notificationDispatchState).values(
|
|
213
|
+
configuredChannels.map((channel) => ({
|
|
214
|
+
key: (0, import_validation.dispatchStateKey)(channel),
|
|
215
|
+
channel,
|
|
216
|
+
rateLimitCount: 0,
|
|
217
|
+
createdAt: now,
|
|
218
|
+
updatedAt: now
|
|
219
|
+
}))
|
|
220
|
+
).onConflictDoNothing({ target: notificationDispatchState.key });
|
|
221
|
+
const policyRows = await tx.select().from(notificationDispatchState).where(
|
|
222
|
+
(0, import_drizzle_orm.inArray)(
|
|
223
|
+
notificationDispatchState.key,
|
|
224
|
+
configuredChannels.map(import_validation.dispatchStateKey)
|
|
225
|
+
)
|
|
226
|
+
).orderBy((0, import_drizzle_orm.asc)(notificationDispatchState.key)).for("update");
|
|
227
|
+
const policyStates = new Map(
|
|
228
|
+
policyRows.map((state) => [state.channel, state])
|
|
229
|
+
);
|
|
230
|
+
const rateState = /* @__PURE__ */ new Map();
|
|
231
|
+
const noteDeferred = (availableAt) => {
|
|
232
|
+
if (availableAt && Number.isFinite(availableAt.getTime()) && (!deferredUntil || availableAt.getTime() < deferredUntil.getTime())) {
|
|
233
|
+
deferredUntil = availableAt;
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
await tx.update(notificationDeliveries).set({
|
|
237
|
+
status: "failed",
|
|
238
|
+
nextAttemptAt: null,
|
|
239
|
+
lockedAt: null,
|
|
240
|
+
lockedBy: null,
|
|
241
|
+
errorCode: "max_attempts_exhausted",
|
|
242
|
+
errorMessage: "Maximum delivery attempts exhausted",
|
|
243
|
+
updatedAt: now
|
|
244
|
+
}).where(
|
|
245
|
+
(0, import_drizzle_orm.and)(
|
|
246
|
+
supportedChannelFilter,
|
|
247
|
+
input.notificationIds?.length ? (0, import_drizzle_orm.inArray)(notificationDeliveries.notificationId, [
|
|
248
|
+
...input.notificationIds
|
|
249
|
+
]) : void 0,
|
|
250
|
+
input.deliveryIds?.length ? (0, import_drizzle_orm.inArray)(notificationDeliveries.id, [...input.deliveryIds]) : void 0,
|
|
251
|
+
(0, import_drizzle_orm.or)(
|
|
252
|
+
import_drizzle_orm.sql`${notificationDeliveries.attempts} >= ${notificationDeliveries.maxAttempts}`,
|
|
253
|
+
import_drizzle_orm.sql`${notificationDeliveries.attempts} >= ${import_validation.MAX_ATTEMPTS}`
|
|
254
|
+
),
|
|
255
|
+
(0, import_drizzle_orm.or)(
|
|
256
|
+
(0, import_drizzle_orm.and)(
|
|
257
|
+
(0, import_drizzle_orm.inArray)(notificationDeliveries.status, ["pending", "retrying"]),
|
|
258
|
+
(0, import_drizzle_orm.lte)(notificationDeliveries.nextAttemptAt, now)
|
|
259
|
+
),
|
|
260
|
+
(0, import_drizzle_orm.and)(
|
|
261
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.status, "processing"),
|
|
262
|
+
(0, import_drizzle_orm.or)(
|
|
263
|
+
(0, import_drizzle_orm.isNull)(notificationDeliveries.lockedAt),
|
|
264
|
+
(0, import_drizzle_orm.lt)(notificationDeliveries.lockedAt, staleBefore)
|
|
265
|
+
)
|
|
266
|
+
)
|
|
267
|
+
)
|
|
268
|
+
)
|
|
269
|
+
);
|
|
270
|
+
const selectDue = async (channelPredicate, rowLimit) => {
|
|
271
|
+
if (rowLimit <= 0) {
|
|
272
|
+
return [];
|
|
273
|
+
}
|
|
274
|
+
return tx.select({
|
|
275
|
+
deliveryId: notificationDeliveries.id,
|
|
276
|
+
notificationId: notifications.id,
|
|
277
|
+
recipientId: notifications.recipientId,
|
|
278
|
+
topic: notifications.topic,
|
|
279
|
+
channel: notificationDeliveries.channel,
|
|
280
|
+
payload: notifications.payload,
|
|
281
|
+
attempts: notificationDeliveries.attempts,
|
|
282
|
+
maxAttempts: notificationDeliveries.maxAttempts,
|
|
283
|
+
createdAt: notifications.createdAt,
|
|
284
|
+
scheduledFor: notifications.scheduledFor,
|
|
285
|
+
actorId: notifications.actorId,
|
|
286
|
+
entityType: notifications.entityType,
|
|
287
|
+
entityId: notifications.entityId
|
|
288
|
+
}).from(notificationDeliveries).innerJoin(
|
|
289
|
+
notifications,
|
|
290
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.notificationId, notifications.id)
|
|
291
|
+
).where(
|
|
292
|
+
(0, import_drizzle_orm.and)(
|
|
293
|
+
(0, import_drizzle_orm.isNull)(notifications.canceledAt),
|
|
294
|
+
(0, import_drizzle_orm.or)(
|
|
295
|
+
(0, import_drizzle_orm.eq)(notifications.fallbackEnabled, false),
|
|
296
|
+
(0, import_drizzle_orm.isNull)(notifications.readAt)
|
|
297
|
+
),
|
|
298
|
+
(0, import_drizzle_orm.lte)(notifications.scheduledFor, now),
|
|
299
|
+
input.notificationIds?.length ? (0, import_drizzle_orm.inArray)(notifications.id, [...input.notificationIds]) : void 0,
|
|
300
|
+
input.deliveryIds?.length ? (0, import_drizzle_orm.inArray)(notificationDeliveries.id, [...input.deliveryIds]) : void 0,
|
|
301
|
+
supportedChannelFilter,
|
|
302
|
+
input.excludeDeliveryIds?.length ? (0, import_drizzle_orm.notInArray)(notificationDeliveries.id, [
|
|
303
|
+
...input.excludeDeliveryIds
|
|
304
|
+
]) : void 0,
|
|
305
|
+
channelPredicate,
|
|
306
|
+
import_drizzle_orm.sql`${notificationDeliveries.attempts} < ${notificationDeliveries.maxAttempts}`,
|
|
307
|
+
import_drizzle_orm.sql`${notificationDeliveries.attempts} < ${import_validation.MAX_ATTEMPTS}`,
|
|
308
|
+
(0, import_drizzle_orm.or)(
|
|
309
|
+
(0, import_drizzle_orm.and)(
|
|
310
|
+
(0, import_drizzle_orm.inArray)(notificationDeliveries.status, [
|
|
311
|
+
"pending",
|
|
312
|
+
"retrying"
|
|
313
|
+
]),
|
|
314
|
+
(0, import_drizzle_orm.lte)(notificationDeliveries.nextAttemptAt, now)
|
|
315
|
+
),
|
|
316
|
+
(0, import_drizzle_orm.and)(
|
|
317
|
+
(0, import_drizzle_orm.eq)(notificationDeliveries.status, "processing"),
|
|
318
|
+
(0, import_drizzle_orm.or)(
|
|
319
|
+
(0, import_drizzle_orm.isNull)(notificationDeliveries.lockedAt),
|
|
320
|
+
(0, import_drizzle_orm.lt)(notificationDeliveries.lockedAt, staleBefore)
|
|
321
|
+
)
|
|
322
|
+
)
|
|
323
|
+
)
|
|
324
|
+
)
|
|
325
|
+
).orderBy(
|
|
326
|
+
(0, import_drizzle_orm.asc)(notificationDeliveries.nextAttemptAt),
|
|
327
|
+
(0, import_drizzle_orm.asc)(notificationDeliveries.createdAt)
|
|
328
|
+
).limit(rowLimit).for("update", { of: notificationDeliveries, skipLocked: true });
|
|
329
|
+
};
|
|
330
|
+
const policyBudget = async (channel, requested) => {
|
|
331
|
+
if (requested <= 0) {
|
|
332
|
+
return { allowed: requested };
|
|
333
|
+
}
|
|
334
|
+
const policy = (0, import_keys.getOwnRecordValue)(this.context.channelPolicies, channel);
|
|
335
|
+
const state = policyStates.get(channel);
|
|
336
|
+
if (!state)
|
|
337
|
+
throw new Error(
|
|
338
|
+
`Dispatch state for channel "${channel}" could not be locked`
|
|
339
|
+
);
|
|
340
|
+
if (state.cooldownUntil && state.cooldownUntil.getTime() > now.getTime()) {
|
|
341
|
+
return { allowed: 0, deferredUntil: state.cooldownUntil };
|
|
342
|
+
}
|
|
343
|
+
if (!policy) {
|
|
344
|
+
return { allowed: requested };
|
|
345
|
+
}
|
|
346
|
+
if (!policy.rateLimit) {
|
|
347
|
+
return { allowed: requested };
|
|
348
|
+
}
|
|
349
|
+
let windowStartedAt = state.rateLimitWindowStartedAt;
|
|
350
|
+
let count = state.rateLimitCount;
|
|
351
|
+
if (!windowStartedAt || windowStartedAt.getTime() + policy.rateLimit.windowMs <= now.getTime()) {
|
|
352
|
+
windowStartedAt = state.rateLimitWindowStartedAt ? now : input.policyWindowStartedAt ?? now;
|
|
353
|
+
count = 0;
|
|
354
|
+
await tx.update(notificationDispatchState).set({
|
|
355
|
+
channel,
|
|
356
|
+
rateLimitWindowStartedAt: windowStartedAt,
|
|
357
|
+
rateLimitCount: count,
|
|
358
|
+
updatedAt: now
|
|
359
|
+
}).where(
|
|
360
|
+
(0, import_drizzle_orm.eq)(notificationDispatchState.key, (0, import_validation.dispatchStateKey)(channel))
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
rateState.set(channel, {
|
|
364
|
+
count,
|
|
365
|
+
windowStartedAt,
|
|
366
|
+
windowMs: policy.rateLimit.windowMs
|
|
367
|
+
});
|
|
368
|
+
const remaining = policy.rateLimit.max - count;
|
|
369
|
+
const nextWindowAt = new Date(
|
|
370
|
+
windowStartedAt.getTime() + policy.rateLimit.windowMs
|
|
371
|
+
);
|
|
372
|
+
if (remaining <= 0) {
|
|
373
|
+
return { allowed: 0, deferredUntil: nextWindowAt };
|
|
374
|
+
}
|
|
375
|
+
return {
|
|
376
|
+
allowed: Math.min(requested, remaining),
|
|
377
|
+
deferredAfterClaim: remaining <= requested ? nextWindowAt : void 0
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
const recordPolicyClaims = async (channel, count) => {
|
|
381
|
+
if (count <= 0) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
const state = rateState.get(channel);
|
|
385
|
+
if (!state) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
state.count += count;
|
|
389
|
+
await tx.update(notificationDispatchState).set({
|
|
390
|
+
channel,
|
|
391
|
+
rateLimitCount: state.count,
|
|
392
|
+
updatedAt: now
|
|
393
|
+
}).where((0, import_drizzle_orm.eq)(notificationDispatchState.key, (0, import_validation.dispatchStateKey)(channel)));
|
|
394
|
+
};
|
|
395
|
+
const claimRows = async (due) => {
|
|
396
|
+
if (due.length === 0) return [];
|
|
397
|
+
const tokens = due.map((item) => ({
|
|
398
|
+
id: item.deliveryId,
|
|
399
|
+
token: `${input.workerId}:${crypto.randomUUID()}`
|
|
400
|
+
}));
|
|
401
|
+
const tokenCases = import_drizzle_orm.sql.join(
|
|
402
|
+
tokens.map(({ id, token }) => import_drizzle_orm.sql`WHEN ${id} THEN ${token}`),
|
|
403
|
+
import_drizzle_orm.sql` `
|
|
404
|
+
);
|
|
405
|
+
const updated = await tx.update(notificationDeliveries).set({
|
|
406
|
+
status: "processing",
|
|
407
|
+
attempts: import_drizzle_orm.sql`${notificationDeliveries.attempts} + 1`,
|
|
408
|
+
lastAttemptAt: now,
|
|
409
|
+
lockedAt: now,
|
|
410
|
+
lockedBy: import_drizzle_orm.sql`CASE ${notificationDeliveries.id} ${tokenCases} END`,
|
|
411
|
+
updatedAt: now
|
|
412
|
+
}).where((0, import_drizzle_orm.and)(
|
|
413
|
+
(0, import_drizzle_orm.inArray)(notificationDeliveries.id, tokens.map(({ id }) => id)),
|
|
414
|
+
import_drizzle_orm.sql`${notificationDeliveries.attempts} < ${notificationDeliveries.maxAttempts}`,
|
|
415
|
+
import_drizzle_orm.sql`${notificationDeliveries.attempts} < ${import_validation.MAX_ATTEMPTS}`
|
|
416
|
+
)).returning({
|
|
417
|
+
id: notificationDeliveries.id,
|
|
418
|
+
attempts: notificationDeliveries.attempts,
|
|
419
|
+
maxAttempts: notificationDeliveries.maxAttempts
|
|
420
|
+
});
|
|
421
|
+
const byId = new Map(updated.map((row) => [row.id, row]));
|
|
422
|
+
const claimedRows = due.map((item, index) => {
|
|
423
|
+
const row = byId.get(item.deliveryId);
|
|
424
|
+
if (!row) throw new Error(`delivery ${item.deliveryId} could not be claimed`);
|
|
425
|
+
return {
|
|
426
|
+
...item,
|
|
427
|
+
attempts: row.attempts,
|
|
428
|
+
maxAttempts: row.maxAttempts,
|
|
429
|
+
channel: item.channel,
|
|
430
|
+
payload: item.payload,
|
|
431
|
+
claimToken: tokens[index].token,
|
|
432
|
+
claimedAt: now,
|
|
433
|
+
claimedMonotonicAt
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
claimed.push(...claimedRows);
|
|
437
|
+
return claimedRows;
|
|
438
|
+
};
|
|
439
|
+
for (const channel of configuredChannels) {
|
|
440
|
+
const remainingLimit = input.limit - claimed.length;
|
|
441
|
+
if (remainingLimit <= 0) {
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
const budget = await policyBudget(channel, remainingLimit);
|
|
445
|
+
const channelPredicate = (0, import_drizzle_orm.eq)(notificationDeliveries.channel, channel);
|
|
446
|
+
if (budget.allowed <= 0) {
|
|
447
|
+
const due = await selectDue(channelPredicate, 1);
|
|
448
|
+
if (due.length > 0) {
|
|
449
|
+
noteDeferred(budget.deferredUntil);
|
|
450
|
+
}
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
const claimedForChannel = await claimRows(
|
|
454
|
+
await selectDue(channelPredicate, budget.allowed)
|
|
455
|
+
);
|
|
456
|
+
await recordPolicyClaims(channel, claimedForChannel.length);
|
|
457
|
+
if (claimedForChannel.length === budget.allowed && budget.deferredAfterClaim) {
|
|
458
|
+
const due = await selectDue(channelPredicate, 1);
|
|
459
|
+
if (due.length > 0) {
|
|
460
|
+
noteDeferred(budget.deferredAfterClaim);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
claimed,
|
|
466
|
+
...deferredUntil ? { deferredUntil } : {}
|
|
467
|
+
};
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
async openChannelCooldown(channel, cooldownUntil, now) {
|
|
471
|
+
const { notificationDispatchState } = this.context.schema;
|
|
472
|
+
const key = (0, import_validation.dispatchStateKey)(channel);
|
|
473
|
+
if (!Number.isFinite(cooldownUntil.getTime())) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
await this.context.db.transaction(async (tx) => {
|
|
477
|
+
await tx.insert(notificationDispatchState).values({
|
|
478
|
+
key,
|
|
479
|
+
channel,
|
|
480
|
+
rateLimitCount: 0,
|
|
481
|
+
cooldownUntil,
|
|
482
|
+
createdAt: now,
|
|
483
|
+
updatedAt: now
|
|
484
|
+
}).onConflictDoNothing({
|
|
485
|
+
target: notificationDispatchState.key
|
|
486
|
+
});
|
|
487
|
+
await tx.update(notificationDispatchState).set({
|
|
488
|
+
channel,
|
|
489
|
+
cooldownUntil: import_drizzle_orm.sql`case when ${notificationDispatchState.cooldownUntil} is null or ${notificationDispatchState.cooldownUntil} < ${cooldownUntil}::timestamptz then ${cooldownUntil}::timestamptz else ${notificationDispatchState.cooldownUntil} end`,
|
|
490
|
+
updatedAt: now
|
|
491
|
+
}).where((0, import_drizzle_orm.eq)(notificationDispatchState.key, key));
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
async durableDispatchResult(delivery, persisted) {
|
|
495
|
+
let state = persisted;
|
|
496
|
+
if (!state) {
|
|
497
|
+
const { notificationDeliveries } = this.context.schema;
|
|
498
|
+
[state] = await this.context.db.select({
|
|
499
|
+
status: notificationDeliveries.status,
|
|
500
|
+
attempts: notificationDeliveries.attempts,
|
|
501
|
+
errorCode: notificationDeliveries.errorCode,
|
|
502
|
+
errorMessage: notificationDeliveries.errorMessage
|
|
503
|
+
}).from(notificationDeliveries).where((0, import_drizzle_orm.eq)(notificationDeliveries.id, delivery.deliveryId)).limit(1);
|
|
504
|
+
}
|
|
505
|
+
if (!state) {
|
|
506
|
+
throw new Error(
|
|
507
|
+
`delivery ${delivery.deliveryId} no longer has a durable state`
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
deliveryId: delivery.deliveryId,
|
|
512
|
+
notificationId: delivery.notificationId,
|
|
513
|
+
recipientId: delivery.recipientId,
|
|
514
|
+
channel: delivery.channel,
|
|
515
|
+
status: state.status,
|
|
516
|
+
attempt: state.attempts,
|
|
517
|
+
...state.errorCode ? { errorCode: state.errorCode } : {},
|
|
518
|
+
...state.errorMessage ? { errorMessage: (0, import_validation.capDiagnosticMessage)(state.errorMessage) } : {}
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
523
|
+
0 && (module.exports = {
|
|
524
|
+
DeliveryStore
|
|
525
|
+
});
|
|
526
|
+
//# sourceMappingURL=delivery-store.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/delivery-store.ts"],
|
|
4
|
+
"sourcesContent": ["import type { DeliveryStatus } from \"./types.js\";\nimport { persistOutcome } from \"./dispatch-control.js\";\nimport {\n and,\n asc,\n eq,\n inArray,\n isNull,\n lt,\n lte,\n notInArray,\n or,\n sql,\n} from \"drizzle-orm\";\n\nimport { getOwnRecordValue } from \"./keys.js\";\nimport {\n BUILT_IN_CHANNELS,\n type DispatchResult,\n type JsonObject,\n} from \"./types.js\";\n\nimport { CoreContext } from \"./context.js\";\nimport type { ClaimedDelivery, DurableDispatchState } from \"./contracts.js\";\nimport {\n capDiagnosticMessage,\n dispatchStateKey,\n MAX_ATTEMPTS,\n MONOTONIC_NOW,\n} from \"./validation.js\";\n\nexport class DeliveryStore<\n TChannel extends string,\n TData extends JsonObject = JsonObject,\n> {\n constructor(readonly context: CoreContext<TChannel, TData>) {}\n async finalizeBuiltInInApp(\n deliveries: Array<ClaimedDelivery<TChannel, TData>>,\n ): Promise<Array<DispatchResult<TChannel>>> {\n const { notificationDeliveries } = this.context.schema;\n const deliveryIds = deliveries.map((delivery) => delivery.deliveryId);\n const claimTokens = deliveries.map((delivery) => delivery.claimToken);\n const now = deliveries[0]?.claimedAt;\n if (!now) {\n return [];\n }\n\n const persisted = await persistOutcome(async () =>\n this.context.db\n .update(notificationDeliveries)\n .set({\n status: \"sent\",\n nextAttemptAt: null,\n lockedAt: null,\n lockedBy: null,\n sentAt: now,\n providerMessageId: null,\n metadata: null,\n errorCode: null,\n errorMessage: null,\n updatedAt: now,\n })\n .where(\n and(\n inArray(notificationDeliveries.id, deliveryIds),\n inArray(notificationDeliveries.lockedBy, claimTokens),\n eq(notificationDeliveries.status, \"processing\"),\n ),\n )\n .returning({\n id: notificationDeliveries.id,\n status: notificationDeliveries.status,\n attempts: notificationDeliveries.attempts,\n errorCode: notificationDeliveries.errorCode,\n errorMessage: notificationDeliveries.errorMessage,\n }),\n );\n const persistedById = new Map(\n persisted.map((row) => [\n row.id,\n {\n status: row.status,\n attempts: row.attempts,\n errorCode: row.errorCode,\n errorMessage: row.errorMessage,\n },\n ]),\n );\n\n const results: Array<DispatchResult<TChannel>> = [];\n for (const delivery of deliveries) {\n results.push(\n await this.durableDispatchResult(\n delivery,\n persistedById.get(delivery.deliveryId),\n ),\n );\n }\n return results;\n }\n\n /** Admission locks follow the package-wide channel -> notification -> delivery\n * order. Only time measured after every lock can establish a live lease. */\n async admit(\n delivery: ClaimedDelivery<TChannel, TData>,\n ): Promise<Date | undefined> {\n const { notifications, notificationDeliveries, notificationDispatchState } =\n this.context.schema;\n return this.context.db.transaction(async (tx) => {\n const [state] = await tx\n .select()\n .from(notificationDispatchState)\n .where(\n eq(notificationDispatchState.key, dispatchStateKey(delivery.channel)),\n )\n .for(\"update\");\n if (!state)\n throw new Error(\n `Missing dispatch state for channel \"${delivery.channel}\"`,\n );\n const [notification] = await tx\n .select({\n canceledAt: notifications.canceledAt,\n fallbackEnabled: notifications.fallbackEnabled,\n readAt: notifications.readAt,\n })\n .from(notifications)\n .where(eq(notifications.id, delivery.notificationId))\n .for(\"update\");\n const [current] = await tx\n .select({\n lockedAt: notificationDeliveries.lockedAt,\n lockedBy: notificationDeliveries.lockedBy,\n status: notificationDeliveries.status,\n })\n .from(notificationDeliveries)\n .where(eq(notificationDeliveries.id, delivery.deliveryId))\n .for(\"update\");\n const now = this.elapsedClaimTime(delivery);\n if (\n !notification ||\n notification.canceledAt ||\n (notification.fallbackEnabled && notification.readAt) ||\n (state.cooldownUntil && state.cooldownUntil > now) ||\n !current ||\n current.lockedBy !== delivery.claimToken ||\n current.status !== \"processing\" ||\n !current.lockedAt ||\n current.lockedAt.getTime() < now.getTime() - this.context.lockTimeoutMs\n )\n return undefined;\n // A later lock timestamp from another database operation must never regress.\n const renewedAt = new Date(\n Math.max(now.getTime(), current.lockedAt.getTime()),\n );\n await tx\n .update(notificationDeliveries)\n .set({ lockedAt: renewedAt, updatedAt: renewedAt })\n .where(\n and(\n eq(notificationDeliveries.id, delivery.deliveryId),\n eq(notificationDeliveries.lockedBy, delivery.claimToken),\n ),\n );\n return now;\n });\n }\n\n /** Renewal checks ownership and lease freshness after its delivery lock wait.\n * A late renewal cannot revive an expired claim or backdate a newer lease. */\n async renew(\n delivery: ClaimedDelivery<TChannel, TData>,\n stillActive: () => boolean,\n ): Promise<boolean> {\n const { notificationDeliveries } = this.context.schema;\n return this.context.db.transaction(async (tx) => {\n const [current] = await tx\n .select({\n lockedAt: notificationDeliveries.lockedAt,\n lockedBy: notificationDeliveries.lockedBy,\n status: notificationDeliveries.status,\n })\n .from(notificationDeliveries)\n .where(eq(notificationDeliveries.id, delivery.deliveryId))\n .for(\"update\");\n if (!stillActive()) return false;\n const now = this.elapsedClaimTime(delivery);\n if (\n !current ||\n current.lockedBy !== delivery.claimToken ||\n (current.status !== \"processing\" && current.status !== \"canceled\") ||\n !current.lockedAt ||\n current.lockedAt.getTime() < now.getTime() - this.context.lockTimeoutMs\n )\n return false;\n const renewedAt = new Date(\n Math.max(now.getTime(), current.lockedAt.getTime()),\n );\n await tx\n .update(notificationDeliveries)\n .set({ lockedAt: renewedAt, updatedAt: renewedAt })\n .where(\n and(\n eq(notificationDeliveries.id, delivery.deliveryId),\n eq(notificationDeliveries.lockedBy, delivery.claimToken),\n ),\n );\n return true;\n });\n }\n\n /** Anchor elapsed work to the validated pre-provider clock, never application code. */\n elapsedClaimTime(delivery: ClaimedDelivery<TChannel, TData>): Date {\n return new Date(\n Math.min(\n 8_640_000_000_000_000,\n delivery.claimedAt.getTime() +\n Math.max(0, MONOTONIC_NOW() - delivery.claimedMonotonicAt),\n ),\n );\n }\n\n /** Return work that never reached an adapter without consuming an attempt. */\n async releaseUnstarted(\n delivery: ClaimedDelivery<TChannel, TData>,\n ): Promise<void> {\n const { notifications, notificationDeliveries } = this.context.schema;\n await persistOutcome(() =>\n this.context.db.transaction(async (tx) => {\n const [notification] = await tx\n .select({\n fallbackEnabled: notifications.fallbackEnabled,\n readAt: notifications.readAt,\n })\n .from(notifications)\n .where(eq(notifications.id, delivery.notificationId))\n .for(\"update\");\n const satisfied = Boolean(\n notification?.fallbackEnabled && notification.readAt,\n );\n return tx\n .update(notificationDeliveries)\n .set({\n status: sql<DeliveryStatus>`case when ${notificationDeliveries.status} = 'canceled' then 'canceled' when ${satisfied} then 'skipped' else 'retrying' end`,\n attempts: sql`greatest(0, ${notificationDeliveries.attempts} - 1)`,\n nextAttemptAt: sql<Date | null>`case when ${notificationDeliveries.status} = 'canceled' or ${satisfied} then null::timestamptz else ${delivery.claimedAt}::timestamptz end`,\n errorCode: sql`case when ${satisfied} then 'fallback_satisfied' else ${notificationDeliveries.errorCode} end`,\n errorMessage: sql`case when ${satisfied} then 'Notification already read' else ${notificationDeliveries.errorMessage} end`,\n lockedAt: null,\n lockedBy: null,\n updatedAt: delivery.claimedAt,\n })\n .where(\n and(\n eq(notificationDeliveries.id, delivery.deliveryId),\n eq(notificationDeliveries.lockedBy, delivery.claimToken),\n inArray(notificationDeliveries.status, [\n \"processing\",\n \"canceled\",\n ]),\n ),\n );\n }),\n );\n }\n\n async claimDue(input: {\n limit: number;\n workerId: string;\n deliveryIds?: readonly string[];\n notificationIds?: readonly string[];\n channels?: readonly string[];\n now?: Date;\n policyWindowStartedAt?: Date;\n excludeDeliveryIds?: readonly string[];\n }): Promise<{\n claimed: Array<ClaimedDelivery<TChannel, TData>>;\n deferredUntil?: Date;\n }> {\n const { notifications, notificationDeliveries, notificationDispatchState } =\n this.context.schema;\n const now = input.now ?? this.context.currentTime();\n const claimedMonotonicAt = MONOTONIC_NOW();\n const supportedChannels = input.channels\n ? [...input.channels]\n : [BUILT_IN_CHANNELS.IN_APP, ...Object.keys(this.context.adapters)];\n const supportedChannelFilter = inArray(\n notificationDeliveries.channel,\n supportedChannels,\n );\n const staleBefore = new Date(now.getTime() - this.context.lockTimeoutMs);\n\n return this.context.db.transaction(async (tx) => {\n const claimed: Array<ClaimedDelivery<TChannel, TData>> = [];\n let deferredUntil: Date | undefined;\n // Lock every supported channel in a stable order before delivery rows.\n // A snapshot of only currently active cooldowns races newly opened ones.\n const configuredChannels = [...new Set(supportedChannels)].sort();\n if (!configuredChannels.length) return { claimed };\n await tx\n .insert(notificationDispatchState)\n .values(\n configuredChannels.map((channel) => ({\n key: dispatchStateKey(channel),\n channel,\n rateLimitCount: 0,\n createdAt: now,\n updatedAt: now,\n })),\n )\n .onConflictDoNothing({ target: notificationDispatchState.key });\n const policyRows = await tx\n .select()\n .from(notificationDispatchState)\n .where(\n inArray(\n notificationDispatchState.key,\n configuredChannels.map(dispatchStateKey),\n ),\n )\n .orderBy(asc(notificationDispatchState.key))\n .for(\"update\");\n const policyStates = new Map(\n policyRows.map((state) => [state.channel, state]),\n );\n const rateState = new Map<\n string,\n {\n count: number;\n windowStartedAt: Date;\n windowMs: number;\n }\n >();\n const noteDeferred = (availableAt: Date | undefined) => {\n if (\n availableAt &&\n Number.isFinite(availableAt.getTime()) &&\n (!deferredUntil || availableAt.getTime() < deferredUntil.getTime())\n ) {\n deferredUntil = availableAt;\n }\n };\n\n await tx\n .update(notificationDeliveries)\n .set({\n status: \"failed\",\n nextAttemptAt: null,\n lockedAt: null,\n lockedBy: null,\n errorCode: \"max_attempts_exhausted\",\n errorMessage: \"Maximum delivery attempts exhausted\",\n updatedAt: now,\n })\n .where(\n and(\n supportedChannelFilter,\n input.notificationIds?.length\n ? inArray(notificationDeliveries.notificationId, [\n ...input.notificationIds,\n ])\n : undefined,\n input.deliveryIds?.length\n ? inArray(notificationDeliveries.id, [...input.deliveryIds])\n : undefined,\n or(\n sql`${notificationDeliveries.attempts} >= ${notificationDeliveries.maxAttempts}`,\n sql`${notificationDeliveries.attempts} >= ${MAX_ATTEMPTS}`,\n ),\n or(\n and(\n inArray(notificationDeliveries.status, [\"pending\", \"retrying\"]),\n lte(notificationDeliveries.nextAttemptAt, now),\n ),\n and(\n eq(notificationDeliveries.status, \"processing\"),\n or(\n isNull(notificationDeliveries.lockedAt),\n lt(notificationDeliveries.lockedAt, staleBefore),\n ),\n ),\n ),\n ),\n );\n\n const selectDue = async (\n channelPredicate:\n ReturnType<typeof eq> | ReturnType<typeof notInArray> | undefined,\n rowLimit: number,\n ) => {\n if (rowLimit <= 0) {\n return [];\n }\n return tx\n .select({\n deliveryId: notificationDeliveries.id,\n notificationId: notifications.id,\n recipientId: notifications.recipientId,\n topic: notifications.topic,\n channel: notificationDeliveries.channel,\n payload: notifications.payload,\n attempts: notificationDeliveries.attempts,\n maxAttempts: notificationDeliveries.maxAttempts,\n createdAt: notifications.createdAt,\n scheduledFor: notifications.scheduledFor,\n actorId: notifications.actorId,\n entityType: notifications.entityType,\n entityId: notifications.entityId,\n })\n .from(notificationDeliveries)\n .innerJoin(\n notifications,\n eq(notificationDeliveries.notificationId, notifications.id),\n )\n .where(\n and(\n isNull(notifications.canceledAt),\n or(\n eq(notifications.fallbackEnabled, false),\n isNull(notifications.readAt),\n ),\n lte(notifications.scheduledFor, now),\n input.notificationIds?.length\n ? inArray(notifications.id, [...input.notificationIds])\n : undefined,\n input.deliveryIds?.length\n ? inArray(notificationDeliveries.id, [...input.deliveryIds])\n : undefined,\n supportedChannelFilter,\n input.excludeDeliveryIds?.length\n ? notInArray(notificationDeliveries.id, [\n ...input.excludeDeliveryIds,\n ])\n : undefined,\n channelPredicate,\n sql`${notificationDeliveries.attempts} < ${notificationDeliveries.maxAttempts}`,\n sql`${notificationDeliveries.attempts} < ${MAX_ATTEMPTS}`,\n or(\n and(\n inArray(notificationDeliveries.status, [\n \"pending\",\n \"retrying\",\n ]),\n lte(notificationDeliveries.nextAttemptAt, now),\n ),\n and(\n eq(notificationDeliveries.status, \"processing\"),\n or(\n isNull(notificationDeliveries.lockedAt),\n lt(notificationDeliveries.lockedAt, staleBefore),\n ),\n ),\n ),\n ),\n )\n .orderBy(\n asc(notificationDeliveries.nextAttemptAt),\n asc(notificationDeliveries.createdAt),\n )\n .limit(rowLimit)\n .for(\"update\", { of: notificationDeliveries, skipLocked: true });\n };\n\n const policyBudget = async (channel: string, requested: number) => {\n if (requested <= 0) {\n return { allowed: requested };\n }\n const policy = getOwnRecordValue(this.context.channelPolicies, channel);\n const state = policyStates.get(channel);\n if (!state)\n throw new Error(\n `Dispatch state for channel \"${channel}\" could not be locked`,\n );\n if (\n state.cooldownUntil &&\n state.cooldownUntil.getTime() > now.getTime()\n ) {\n return { allowed: 0, deferredUntil: state.cooldownUntil };\n }\n if (!policy) {\n return { allowed: requested };\n }\n if (!policy.rateLimit) {\n return { allowed: requested };\n }\n\n let windowStartedAt = state.rateLimitWindowStartedAt;\n let count = state.rateLimitCount;\n if (\n !windowStartedAt ||\n windowStartedAt.getTime() + policy.rateLimit.windowMs <= now.getTime()\n ) {\n windowStartedAt = state.rateLimitWindowStartedAt\n ? now\n : (input.policyWindowStartedAt ?? now);\n count = 0;\n await tx\n .update(notificationDispatchState)\n .set({\n channel,\n rateLimitWindowStartedAt: windowStartedAt,\n rateLimitCount: count,\n updatedAt: now,\n })\n .where(\n eq(notificationDispatchState.key, dispatchStateKey(channel)),\n );\n }\n\n rateState.set(channel, {\n count,\n windowStartedAt,\n windowMs: policy.rateLimit.windowMs,\n });\n\n const remaining = policy.rateLimit.max - count;\n const nextWindowAt = new Date(\n windowStartedAt.getTime() + policy.rateLimit.windowMs,\n );\n if (remaining <= 0) {\n return { allowed: 0, deferredUntil: nextWindowAt };\n }\n return {\n allowed: Math.min(requested, remaining),\n deferredAfterClaim: remaining <= requested ? nextWindowAt : undefined,\n };\n };\n\n const recordPolicyClaims = async (channel: string, count: number) => {\n if (count <= 0) {\n return;\n }\n const state = rateState.get(channel);\n if (!state) {\n return;\n }\n state.count += count;\n await tx\n .update(notificationDispatchState)\n .set({\n channel,\n rateLimitCount: state.count,\n updatedAt: now,\n })\n .where(eq(notificationDispatchState.key, dispatchStateKey(channel)));\n };\n\n const claimRows = async (due: Awaited<ReturnType<typeof selectDue>>) => {\n if (due.length === 0) return [];\n const tokens = due.map((item) => ({\n id: item.deliveryId,\n token: `${input.workerId}:${crypto.randomUUID()}`,\n }));\n const tokenCases = sql.join(\n tokens.map(({ id, token }) => sql`WHEN ${id} THEN ${token}`),\n sql` `,\n );\n const updated = await tx\n .update(notificationDeliveries)\n .set({\n status: \"processing\",\n attempts: sql`${notificationDeliveries.attempts} + 1`,\n lastAttemptAt: now,\n lockedAt: now,\n lockedBy: sql`CASE ${notificationDeliveries.id} ${tokenCases} END`,\n updatedAt: now,\n })\n .where(and(\n inArray(notificationDeliveries.id, tokens.map(({ id }) => id)),\n sql`${notificationDeliveries.attempts} < ${notificationDeliveries.maxAttempts}`,\n sql`${notificationDeliveries.attempts} < ${MAX_ATTEMPTS}`,\n ))\n .returning({\n id: notificationDeliveries.id,\n attempts: notificationDeliveries.attempts,\n maxAttempts: notificationDeliveries.maxAttempts,\n });\n const byId = new Map(updated.map((row) => [row.id, row]));\n const claimedRows: Array<ClaimedDelivery<TChannel, TData>> = due.map((item, index) => {\n const row = byId.get(item.deliveryId);\n if (!row) throw new Error(`delivery ${item.deliveryId} could not be claimed`);\n return {\n ...item,\n attempts: row.attempts,\n maxAttempts: row.maxAttempts,\n channel: item.channel as TChannel,\n payload: item.payload as ClaimedDelivery<TChannel, TData>[\"payload\"],\n claimToken: tokens[index]!.token,\n claimedAt: now,\n claimedMonotonicAt,\n };\n });\n claimed.push(...claimedRows);\n return claimedRows;\n };\n\n for (const channel of configuredChannels) {\n const remainingLimit = input.limit - claimed.length;\n if (remainingLimit <= 0) {\n break;\n }\n const budget = await policyBudget(channel, remainingLimit);\n const channelPredicate = eq(notificationDeliveries.channel, channel);\n if (budget.allowed <= 0) {\n const due = await selectDue(channelPredicate, 1);\n if (due.length > 0) {\n noteDeferred(budget.deferredUntil);\n }\n continue;\n }\n const claimedForChannel = await claimRows(\n await selectDue(channelPredicate, budget.allowed),\n );\n await recordPolicyClaims(channel, claimedForChannel.length);\n if (\n claimedForChannel.length === budget.allowed &&\n budget.deferredAfterClaim\n ) {\n const due = await selectDue(channelPredicate, 1);\n if (due.length > 0) {\n noteDeferred(budget.deferredAfterClaim);\n }\n }\n }\n\n return {\n claimed,\n ...(deferredUntil ? { deferredUntil } : {}),\n };\n });\n }\n\n async openChannelCooldown(\n channel: string,\n cooldownUntil: Date,\n now: Date,\n ): Promise<void> {\n const { notificationDispatchState } = this.context.schema;\n const key = dispatchStateKey(channel);\n if (!Number.isFinite(cooldownUntil.getTime())) {\n return;\n }\n await this.context.db.transaction(async (tx) => {\n await tx\n .insert(notificationDispatchState)\n .values({\n key,\n channel,\n rateLimitCount: 0,\n cooldownUntil,\n createdAt: now,\n updatedAt: now,\n })\n .onConflictDoNothing({\n target: notificationDispatchState.key,\n });\n await tx\n .update(notificationDispatchState)\n .set({\n channel,\n cooldownUntil: sql<Date | null>`case when ${notificationDispatchState.cooldownUntil} is null or ${notificationDispatchState.cooldownUntil} < ${cooldownUntil}::timestamptz then ${cooldownUntil}::timestamptz else ${notificationDispatchState.cooldownUntil} end`,\n updatedAt: now,\n })\n .where(eq(notificationDispatchState.key, key));\n });\n }\n\n async durableDispatchResult(\n delivery: ClaimedDelivery<TChannel, TData>,\n persisted: DurableDispatchState | undefined,\n ): Promise<DispatchResult<TChannel>> {\n let state = persisted;\n if (!state) {\n const { notificationDeliveries } = this.context.schema;\n [state] = await this.context.db\n .select({\n status: notificationDeliveries.status,\n attempts: notificationDeliveries.attempts,\n errorCode: notificationDeliveries.errorCode,\n errorMessage: notificationDeliveries.errorMessage,\n })\n .from(notificationDeliveries)\n .where(eq(notificationDeliveries.id, delivery.deliveryId))\n .limit(1);\n }\n if (!state) {\n throw new Error(\n `delivery ${delivery.deliveryId} no longer has a durable state`,\n );\n }\n return {\n deliveryId: delivery.deliveryId,\n notificationId: delivery.notificationId,\n recipientId: delivery.recipientId,\n channel: delivery.channel,\n status: state.status,\n attempt: state.attempts,\n ...(state.errorCode ? { errorCode: state.errorCode } : {}),\n ...(state.errorMessage\n ? { errorMessage: capDiagnosticMessage(state.errorMessage) }\n : {}),\n };\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,8BAA+B;AAC/B,yBAWO;AAEP,kBAAkC;AAClC,mBAIO;AAEP,qBAA4B;AAE5B,wBAKO;AAEA,MAAM,cAGX;AAAA,EACA,YAAqB,SAAuC;AAAvC;AAAA,EAAwC;AAAA,EAAxC;AAAA,EACrB,MAAM,qBACJ,YAC0C;AAC1C,UAAM,EAAE,uBAAuB,IAAI,KAAK,QAAQ;AAChD,UAAM,cAAc,WAAW,IAAI,CAAC,aAAa,SAAS,UAAU;AACpE,UAAM,cAAc,WAAW,IAAI,CAAC,aAAa,SAAS,UAAU;AACpE,UAAM,MAAM,WAAW,CAAC,GAAG;AAC3B,QAAI,CAAC,KAAK;AACR,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,YAAY,UAAM;AAAA,MAAe,YACrC,KAAK,QAAQ,GACV,OAAO,sBAAsB,EAC7B,IAAI;AAAA,QACH,QAAQ;AAAA,QACR,eAAe;AAAA,QACf,UAAU;AAAA,QACV,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,mBAAmB;AAAA,QACnB,U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AAC,EACxD,MAAM,CAAC;AAAA,IACZ;AACA,QAAI,CAAC,OAAO;AACV,YAAM,IAAI;AAAA,QACR,YAAY,SAAS,UAAU;AAAA,MACjC;AAAA,IACF;AACA,WAAO;AAAA,MACL,YAAY,SAAS;AAAA,MACrB,gBAAgB,SAAS;AAAA,MACzB,aAAa,SAAS;AAAA,MACtB,SAAS,SAAS;AAAA,MAClB,QAAQ,MAAM;AAAA,MACd,SAAS,MAAM;AAAA,MACf,GAAI,MAAM,YAAY,EAAE,WAAW,MAAM,UAAU,IAAI,CAAC;AAAA,MACxD,GAAI,MAAM,eACN,EAAE,kBAAc,wCAAqB,MAAM,YAAY,EAAE,IACzD,CAAC;AAAA,IACP;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DispatchResult } from "./types.js";
|
|
2
|
+
/** Brand-check native signals without invoking application getters or methods. */
|
|
3
|
+
export declare function normalizeAbortSignal(value: unknown): AbortSignal | undefined;
|
|
4
|
+
export declare function signalAborted(signal: AbortSignal | undefined): boolean;
|
|
5
|
+
/** Internal fan-in uses captured intrinsics even after application callbacks run. */
|
|
6
|
+
export declare function observeInternal<T, U>(promise: Promise<T>, map: (value: T) => U): Promise<U>;
|
|
7
|
+
export declare function raceInternal<T>(promises: Array<Promise<T>>): Promise<T>;
|
|
8
|
+
export declare function joinInternal(promises: Array<Promise<void>>): Promise<void>;
|
|
9
|
+
export type DispatchStopReason = "aborted" | "deadline" | "infrastructure";
|
|
10
|
+
/** One explicit dispatch call owns this cancellation scope; no recurring worker. */
|
|
11
|
+
export declare class DispatchControl {
|
|
12
|
+
#private;
|
|
13
|
+
readonly deadlineMs: number | undefined;
|
|
14
|
+
readonly controller: AbortController;
|
|
15
|
+
readonly startedAt: number;
|
|
16
|
+
readonly stopped: Promise<void>;
|
|
17
|
+
reason: DispatchStopReason | undefined;
|
|
18
|
+
cause: unknown;
|
|
19
|
+
constructor(signal: AbortSignal | undefined, deadlineMs: number | undefined);
|
|
20
|
+
get signal(): AbortSignal;
|
|
21
|
+
get admitting(): boolean;
|
|
22
|
+
stop(reason: DispatchStopReason, cause?: unknown): void;
|
|
23
|
+
/** Join active work, allowing cooperative providers 100ms to settle on stop.
|
|
24
|
+
* Uncooperative callbacks remain visible through the error's `settled` promise.
|
|
25
|
+
* They may persist their outcome, but cannot admit any additional work.
|
|
26
|
+
*/
|
|
27
|
+
join<TChannel extends string>(settled: Promise<Array<DispatchResult<TChannel>>>, completed: Array<DispatchResult<TChannel>>, pending: Set<string>): Promise<void>;
|
|
28
|
+
onStop(cleanup: () => void): () => void;
|
|
29
|
+
close(): void;
|
|
30
|
+
}
|
|
31
|
+
/** Retry the database operation, never the provider callback. */
|
|
32
|
+
export declare function persistOutcome<T>(operation: () => Promise<T>): Promise<T>;
|
|
33
|
+
/** Preserve outcomes from earlier pages when a later page cannot finish. */
|
|
34
|
+
export declare function includePreviousResults<TChannel extends string>(error: unknown, previous: Array<DispatchResult<TChannel>>): never;
|
|
35
|
+
export declare function withPreviousResults<T, TChannel extends string>(operation: Promise<T>, previous: Array<DispatchResult<TChannel>>): Promise<T>;
|
|
36
|
+
//# sourceMappingURL=dispatch-control.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch-control.d.ts","sourceRoot":"","sources":["../../src/dispatch-control.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAgBjD,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,SAAS,CAQ5E;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO,CAEtE;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAClC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,GAAG,EAAE,CAAC,K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