notifkit 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/{bootstrap-P63acBG9.mjs → bootstrap-CHOj1rDv.mjs} +1 -1
- package/dist/{bulk-Beblt3ny.mjs → bulk-CAsYwF-9.mjs} +1 -1
- package/dist/index.d.mts +29 -111
- package/dist/index.mjs +2 -2
- package/dist/{main-Dk92nti8.mjs → main-B88bnGHO.mjs} +5 -12
- package/dist/{main-BIahf4f9.mjs → main-BDTDp4Bg.mjs} +35 -16
- package/dist/{main-C3XcLoCb.mjs → main-C9ekO6RS.mjs} +3 -3
- package/dist/{main-_I4b1cmP.mjs → main-CBeKd8wJ.mjs} +3 -3
- package/dist/{main-NHUvynW2.mjs → main-CVTZoGzA.mjs} +4 -9
- package/dist/{main-CktEylpL.mjs → main-CYxNbgX5.mjs} +23 -94
- package/dist/{main-DB0bUh2r.mjs → main-CcGiccDe.mjs} +5 -14
- package/dist/{main-Lcbg7aEn.mjs → main-DGF3WtFw.mjs} +8 -58
- package/dist/{schedule-or-dispatch-C5qfxQCv.mjs → schedule-or-dispatch-BF85qhMh.mjs} +1 -1
- package/dist/{src-BRatuWJS.mjs → src-aiRAj2xr.mjs} +72 -175
- package/drizzle/0009_retention_time_indexes.sql +4 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +1 -1
- package/src/client.ts +6 -6
- package/src/config/index.ts +8 -10
- package/src/contracts/sdk.ts +26 -11
- package/src/db/bulk.ts +3 -10
- package/src/db/schema.ts +3 -0
- package/src/idempotency/index.ts +12 -53
- package/src/queue/index.ts +1 -12
- package/src/rate-limiter/api-rate-limiter.ts +8 -27
- package/src/rate-limiter/project-settings-cache.ts +4 -16
- package/src/redis/index.ts +3 -51
- package/src/repositories/contact.ts +0 -2
- package/src/server.ts +1 -4
- package/src/services/api/handlers/auth.ts +3 -11
- package/src/services/api/handlers/campaigns.ts +4 -15
- package/src/services/api/handlers/events.ts +1 -2
- package/src/services/api/handlers/notifications.ts +6 -16
- package/src/services/api/handlers/projects.ts +1 -3
- package/src/services/api/handlers/shared.ts +7 -29
- package/src/services/api/handlers/system.ts +1 -1
- package/src/services/api/handlers/unsubscribe.ts +7 -30
- package/src/services/api/handlers/users.ts +1 -2
- package/src/services/api/http.ts +5 -10
- package/src/services/api/main.ts +27 -63
- package/src/services/api/webhooks.ts +8 -19
- package/src/services/auth/index.ts +2 -21
- package/src/services/delivery/main.ts +25 -89
- package/src/services/engine/main.ts +33 -69
- package/src/services/engine/schedule-or-dispatch.ts +7 -4
- package/src/services/enricher/main.ts +19 -49
- package/src/services/events/main.ts +3 -12
- package/src/services/scheduler/main.ts +26 -32
- package/src/services/scheduler/retention.ts +47 -0
- package/src/services/scheduler/send-gate.ts +6 -17
- package/src/services/workflow/duration.ts +1 -6
- package/src/services/workflow/main.ts +3 -9
- package/src/services/workflow/timers.ts +2 -1
- package/src/shared/batch-processor.ts +3 -7
- package/src/shared/utils.ts +2 -8
- package/src/transport/index.ts +0 -4
- package/src/unsubscribe/index.ts +3 -11
- package/src/workers/index.ts +8 -27
package/src/workers/index.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { globalEmitter, AsyncSemaphore } from "@/shared/index.js";
|
|
|
4
4
|
import { metrics } from "@/metrics/index.js";
|
|
5
5
|
export * from "./health.js";
|
|
6
6
|
|
|
7
|
-
// ─── Types ─────────────────────────────────────────────────────────────────
|
|
8
|
-
|
|
9
7
|
export class NonRetryableError extends Error {
|
|
10
8
|
readonly nonRetryable = true;
|
|
11
9
|
constructor(message: string) {
|
|
@@ -44,8 +42,6 @@ export interface WorkerOptions {
|
|
|
44
42
|
maxRetriesBeforeDlq?: number;
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
// ─── BaseWorker ────────────────────────────────────────────────────────────
|
|
48
|
-
|
|
49
45
|
export abstract class BaseWorker {
|
|
50
46
|
protected readonly logger: Logger;
|
|
51
47
|
|
|
@@ -193,21 +189,13 @@ export abstract class BaseWorker {
|
|
|
193
189
|
}
|
|
194
190
|
|
|
195
191
|
/**
|
|
196
|
-
* Processes an event
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* The caller is still holding its own stream entry, and does not ack it until
|
|
200
|
-
* this returns. A thrown error therefore leaves that entry pending and the
|
|
201
|
-
* whole chain is replayed from the upstream stage; the idempotency keys each
|
|
202
|
-
* stage already checks make the replay safe. Non-retryable failures go to the
|
|
203
|
-
* dead-letter stream here, as they would have from this worker's own stream,
|
|
204
|
-
* so they do not send the upstream message there instead.
|
|
192
|
+
* Processes an event from an upstream stage in this process, skipping the stream.
|
|
193
|
+
* A throw leaves the caller's entry pending, so the chain replays from upstream.
|
|
194
|
+
* Non-retryable failures are dead-lettered here so the upstream message isn't.
|
|
205
195
|
*/
|
|
206
196
|
async processInline(event: StreamEvent): Promise<void> {
|
|
207
197
|
try {
|
|
208
|
-
// `{ ack: false }
|
|
209
|
-
// own stream entry is what gets retried if it fails, so there is nothing
|
|
210
|
-
// for the caller to wait on.
|
|
198
|
+
// `{ ack: false }`: another holder owns it and its own entry gets retried.
|
|
211
199
|
await this.process({ id: event.id, event, deliveryCount: 1, inline: true }, 1);
|
|
212
200
|
this.processedCount += 1;
|
|
213
201
|
this.lastProcessedAt = new Date().toISOString();
|
|
@@ -312,11 +300,8 @@ export abstract class BaseWorker {
|
|
|
312
300
|
}
|
|
313
301
|
|
|
314
302
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* large segment fan-out) is reclaimed mid-run and started again elsewhere,
|
|
318
|
-
* over and over, until it is dead-lettered while the first run still works.
|
|
319
|
-
* If this process dies the touches stop, so the entry is reclaimed as before.
|
|
303
|
+
* Keeps the entry's idle time under the reclaim threshold while `process` runs,
|
|
304
|
+
* so a long fan-out isn't reclaimed mid-run. If this process dies, the touches stop.
|
|
320
305
|
*/
|
|
321
306
|
private async processHoldingLease(message: StreamMessage, attempt: number) {
|
|
322
307
|
const stream = message.stream;
|
|
@@ -338,12 +323,8 @@ export abstract class BaseWorker {
|
|
|
338
323
|
}
|
|
339
324
|
|
|
340
325
|
/**
|
|
341
|
-
* `recoveryIntervalMs` is
|
|
342
|
-
*
|
|
343
|
-
* this worker's start, meant a worker restarted more often than that (a crash
|
|
344
|
-
* loop, an eager autoscaler) never scanned at all, and whatever its
|
|
345
|
-
* predecessors held stayed pending for good. So scan on start and then
|
|
346
|
-
* several times per interval; the idle threshold alone decides what is taken.
|
|
326
|
+
* `recoveryIntervalMs` is the idle time before a claim, not the scan period.
|
|
327
|
+
* Scan on start and several times per interval so crash-looping workers still recover.
|
|
347
328
|
*/
|
|
348
329
|
private startRecoveryLoop(): void {
|
|
349
330
|
const scan = () => {
|