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.
Files changed (59) hide show
  1. package/README.md +5 -5
  2. package/dist/{bootstrap-P63acBG9.mjs → bootstrap-CHOj1rDv.mjs} +1 -1
  3. package/dist/{bulk-Beblt3ny.mjs → bulk-CAsYwF-9.mjs} +1 -1
  4. package/dist/index.d.mts +29 -111
  5. package/dist/index.mjs +2 -2
  6. package/dist/{main-Dk92nti8.mjs → main-B88bnGHO.mjs} +5 -12
  7. package/dist/{main-BIahf4f9.mjs → main-BDTDp4Bg.mjs} +35 -16
  8. package/dist/{main-C3XcLoCb.mjs → main-C9ekO6RS.mjs} +3 -3
  9. package/dist/{main-_I4b1cmP.mjs → main-CBeKd8wJ.mjs} +3 -3
  10. package/dist/{main-NHUvynW2.mjs → main-CVTZoGzA.mjs} +4 -9
  11. package/dist/{main-CktEylpL.mjs → main-CYxNbgX5.mjs} +23 -94
  12. package/dist/{main-DB0bUh2r.mjs → main-CcGiccDe.mjs} +5 -14
  13. package/dist/{main-Lcbg7aEn.mjs → main-DGF3WtFw.mjs} +8 -58
  14. package/dist/{schedule-or-dispatch-C5qfxQCv.mjs → schedule-or-dispatch-BF85qhMh.mjs} +1 -1
  15. package/dist/{src-BRatuWJS.mjs → src-aiRAj2xr.mjs} +72 -175
  16. package/drizzle/0009_retention_time_indexes.sql +4 -0
  17. package/drizzle/meta/_journal.json +7 -0
  18. package/package.json +1 -1
  19. package/src/client.ts +6 -6
  20. package/src/config/index.ts +8 -10
  21. package/src/contracts/sdk.ts +26 -11
  22. package/src/db/bulk.ts +3 -10
  23. package/src/db/schema.ts +3 -0
  24. package/src/idempotency/index.ts +12 -53
  25. package/src/queue/index.ts +1 -12
  26. package/src/rate-limiter/api-rate-limiter.ts +8 -27
  27. package/src/rate-limiter/project-settings-cache.ts +4 -16
  28. package/src/redis/index.ts +3 -51
  29. package/src/repositories/contact.ts +0 -2
  30. package/src/server.ts +1 -4
  31. package/src/services/api/handlers/auth.ts +3 -11
  32. package/src/services/api/handlers/campaigns.ts +4 -15
  33. package/src/services/api/handlers/events.ts +1 -2
  34. package/src/services/api/handlers/notifications.ts +6 -16
  35. package/src/services/api/handlers/projects.ts +1 -3
  36. package/src/services/api/handlers/shared.ts +7 -29
  37. package/src/services/api/handlers/system.ts +1 -1
  38. package/src/services/api/handlers/unsubscribe.ts +7 -30
  39. package/src/services/api/handlers/users.ts +1 -2
  40. package/src/services/api/http.ts +5 -10
  41. package/src/services/api/main.ts +27 -63
  42. package/src/services/api/webhooks.ts +8 -19
  43. package/src/services/auth/index.ts +2 -21
  44. package/src/services/delivery/main.ts +25 -89
  45. package/src/services/engine/main.ts +33 -69
  46. package/src/services/engine/schedule-or-dispatch.ts +7 -4
  47. package/src/services/enricher/main.ts +19 -49
  48. package/src/services/events/main.ts +3 -12
  49. package/src/services/scheduler/main.ts +26 -32
  50. package/src/services/scheduler/retention.ts +47 -0
  51. package/src/services/scheduler/send-gate.ts +6 -17
  52. package/src/services/workflow/duration.ts +1 -6
  53. package/src/services/workflow/main.ts +3 -9
  54. package/src/services/workflow/timers.ts +2 -1
  55. package/src/shared/batch-processor.ts +3 -7
  56. package/src/shared/utils.ts +2 -8
  57. package/src/transport/index.ts +0 -4
  58. package/src/unsubscribe/index.ts +3 -11
  59. package/src/workers/index.ts +8 -27
@@ -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 produced by an upstream stage in this same process,
197
- * skipping the stream hop in between.
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 }` means another holder owns this message right now. Its
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
- * Runs `process` while keeping the entry's idle time below the reclaim
316
- * threshold. Without this, a handler that outlasts `recoveryIntervalMs` (a
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 how long an entry must sit idle before it is
342
- * claimed, not how often to look. Scanning only once per interval, timed from
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 = () => {