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
package/README.md CHANGED
@@ -8,11 +8,7 @@ Self-hosted notification infrastructure for product notifications. One API call
8
8
 
9
9
  [![npm version](https://img.shields.io/npm/v/notifkit.svg?style=flat-square&color=6366f1)](https://www.npmjs.com/package/notifkit) [![npm downloads](https://img.shields.io/npm/dm/notifkit.svg?style=flat-square&color=6366f1)](https://www.npmjs.com/package/notifkit) [![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/devkitshq/notifkit/badges/coverage.json&style=flat-square)](https://github.com/devkitshq/notifkit/actions/workflows/ci.yml) [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-3178c6.svg?style=flat-square)](https://www.typescriptlang.org/) [![Node.js](https://img.shields.io/badge/node-%3E%3D22.0.0-339933.svg?style=flat-square)](https://nodejs.org) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](./LICENSE)
10
10
 
11
- [Documentation](https://notifkit.dev/docs/) · [Quickstart](https://notifkit.dev/docs/quickstart.html) · [Examples](https://notifkit.dev/docs/examples.html) · [notifkit.dev](https://notifkit.dev)
12
-
13
- https://github.com/user-attachments/assets/ad8955bd-4205-4d47-8dfc-9010abd3ad62
14
-
15
- (note: this video is generated using claude)
11
+ [Documentation](https://notifkit.dev/docs/) · [Quickstart](https://notifkit.dev/docs/quickstart.html) · [Examples](https://notifkit.dev/docs/examples.html) · [Production support](#production-support) · [notifkit.dev](https://notifkit.dev)
16
12
 
17
13
  </div>
18
14
 
@@ -140,6 +136,10 @@ To sign in, set `ADMIN_EMAIL` and `ADMIN_PASSWORD` before starting the server, t
140
136
 
141
137
  Everything lives at **[notifkit.dev/docs](https://notifkit.dev/docs/)**: [concepts](https://notifkit.dev/docs/concepts.html), [routing and fallback](https://notifkit.dev/docs/guides/routing.html), [preferences](https://notifkit.dev/docs/guides/preferences.html), [workflows](https://notifkit.dev/docs/guides/workflows.html), [architecture](https://notifkit.dev/docs/architecture.html), [operations](https://notifkit.dev/docs/operations.html) and the [API reference](https://notifkit.dev/docs/reference.html).
142
138
 
139
+ ## Production support
140
+
141
+ Need help running notifkit in production? We can deploy it on your infrastructure, migrate your templates from Knock, Courier, Novu or your custom engine, and give you priority support. Email [contact.devkitshq@gmail.com](mailto:contact.devkitshq@gmail.com?subject=notifkit%20production%20support).
142
+
143
143
  ## Contributing
144
144
 
145
145
  Issues and pull requests are welcome.
@@ -1,4 +1,4 @@
1
- import { J as StreamProducer, K as PendingMessageScanner, Z as createLogger, et as createDatabase, q as StreamConsumer, tn as STREAMS, z as RedisClient } from "./src-BRatuWJS.mjs";
1
+ import { $t as STREAMS, G as StreamConsumer, K as StreamProducer, L as RedisClient, Q as createDatabase, W as PendingMessageScanner, Y as createLogger } from "./src-aiRAj2xr.mjs";
2
2
  //#region src/workers/bootstrap.ts
3
3
  /** Logger, shared Redis connection and Postgres pool for one service. */
4
4
  function createWorkerRuntime(config, name, loggerName = name) {
@@ -1,4 +1,4 @@
1
- import { at as deliveryOutbox, ot as messageLogs } from "./src-BRatuWJS.mjs";
1
+ import { it as messageLogs, rt as deliveryOutbox } from "./src-aiRAj2xr.mjs";
2
2
  import { sql } from "drizzle-orm";
3
3
  //#region src/db/bulk.ts
4
4
  function rawClient(db) {
package/dist/index.d.mts CHANGED
@@ -37,9 +37,11 @@ declare const baseConfigSchema: z.ZodObject<{
37
37
  PIPELINE_FUSED: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<boolean, string | undefined>>;
38
38
  QUEUE_MAX_LEN: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
39
39
  IDEMPOTENCY_TTL_SECONDS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
40
+ RATE_LIMIT_PER_HOUR: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
40
41
  DB_MAX_CONNECTIONS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
41
42
  DB_SCHEMA: z.ZodDefault<z.ZodString>;
42
43
  LOG_FLUSH_INTERVAL_MS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
44
+ LOG_RETENTION_DAYS: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
43
45
  LOG_BUFFER_MAX_SIZE: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
44
46
  SEGMENT_MAX_USERS: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
45
47
  PUBLIC_URL: z.ZodOptional<z.ZodString>;
@@ -3978,31 +3980,19 @@ interface IdempotencyOptions {
3978
3980
  ttlSeconds?: number;
3979
3981
  }
3980
3982
  type LeaseResult = "acquired" | "locked" | "completed";
3981
- /**
3982
- * SET NX-based idempotency guard.
3983
- * One key per id: `L` while leased, `1` once processed.
3984
- */
3983
+ /** One Redis key per id: `L` while a worker holds it, `1` once processed. */
3985
3984
  declare class IdempotencyGuard {
3986
3985
  private readonly redis;
3987
3986
  private readonly keyPrefix;
3988
3987
  private readonly ttlSeconds;
3989
3988
  constructor({ redis, keyPrefix, ttlSeconds }: IdempotencyOptions);
3990
3989
  private key;
3991
- /** @deprecated Nothing writes `:lock` keys any more; read only for markers from older versions. Remove in the next minor. */
3992
- private lockKey;
3993
- /** @deprecated Nothing writes `:sent` keys any more; read only for markers from older versions. Remove in the next minor. */
3994
- private completedKey;
3995
- /**
3996
- * Leases the id with SET NX. One key per id: `L` while leased, `1` once processed.
3997
- * Returns "completed" if already processed, "locked" if another worker holds the lease.
3998
- */
3999
3990
  acquireLease(id: string, lockTtlSeconds?: number): Promise<LeaseResult>;
4000
- /** Atomically mark id as processed. Returns true on first call; false if already seen. */
3991
+ /** Marks the id processed. Returns false if it was already seen. */
4001
3992
  checkAndMark(id: string, customTtlSeconds?: number): Promise<boolean>;
4002
- /** Unconditionally mark id as processed (upgrades lock to completed "1" with full TTL). */
3993
+ /** Marks the id processed, replacing a lease with the full TTL. */
4003
3994
  markProcessed(id: string, customTtlSeconds?: number): Promise<void>;
4004
3995
  isProcessed(id: string): Promise<boolean>;
4005
- /** Remove the idempotency marker (useful in tests or manual rollbacks). */
4006
3996
  unmark(id: string): Promise<void>;
4007
3997
  }
4008
3998
  //#endregion
@@ -4166,26 +4156,14 @@ interface ProjectSettingsCacheOptions {
4166
4156
  ttlMs?: number;
4167
4157
  }
4168
4158
  /**
4169
- * Caches per-project throttle overrides for the engine.
4170
- *
4171
- * The throttle check runs once per notification, so an uncached lookup here
4172
- * would put a Postgres round trip on the hot path. Projects with no overrides
4173
- * are cached as well — the common case must not cost a query per message.
4174
- *
4175
- * The TTL bounds staleness on its own; `invalidate()` exists so a settings
4176
- * change published over pub/sub applies immediately rather than at expiry.
4159
+ * Per-project throttle overrides, read once per notification. Projects with no
4160
+ * overrides are cached too. `invalidate()` lets a settings change apply before
4161
+ * the TTL runs out.
4177
4162
  */
4178
4163
  declare class ProjectSettingsCache {
4179
4164
  private readonly load;
4180
4165
  private readonly cache;
4181
- /**
4182
- * Lookups already on the wire, keyed by project.
4183
- *
4184
- * The cache only fills once a query has come back, so without this a cold
4185
- * project at the start of a campaign puts one query per in-flight message on
4186
- * Postgres before the first answer lands — exactly when the database is
4187
- * busiest. Followers wait on the leader's promise instead.
4188
- */
4166
+ /** Lookups in flight, so a cold project at the start of a campaign costs one query. */
4189
4167
  private readonly inFlight;
4190
4168
  constructor(load: (projectId: string) => Promise<ProjectThrottleSettings | null>, { maxSize, ttlMs }?: ProjectSettingsCacheOptions);
4191
4169
  /**
@@ -4245,11 +4223,7 @@ interface ApiRateLimiterOptions {
4245
4223
  /** Redis key namespace. Distinct limiters must not share one. */
4246
4224
  keyPrefix?: string;
4247
4225
  }
4248
- /**
4249
- * Computes dynamic token lease batch size based on RPM.
4250
- * Targets ~5s of limit capacity so Redis is contacted at most ~12 times/min
4251
- * regardless of instantaneous request rate. Bounded between 1 and maxBatchSize.
4252
- */
4226
+ /** About five seconds' worth of the limit, so Redis is asked ~12 times a minute. */
4253
4227
  declare function calculateTokenBatchSize(limitRpm: number, maxBatchSize?: number): number;
4254
4228
  declare class ApiRateLimiter {
4255
4229
  private readonly redis;
@@ -4259,17 +4233,10 @@ declare class ApiRateLimiter {
4259
4233
  private readonly keyPrefix;
4260
4234
  private readonly leases;
4261
4235
  constructor({ redis, windowMs, maxBatchSize, logger, keyPrefix }: ApiRateLimiterOptions);
4262
- /**
4263
- * Evaluates if a request for `projectId` is allowed within its `limitRpm`.
4264
- * Fast-path uses local in-memory token lease (0ms Redis network latency).
4265
- * Refills in the background before tokens are depleted.
4266
- */
4267
4236
  check(projectId: string, limitRpm: number): Promise<boolean>;
4268
4237
  private refill;
4269
4238
  private maybePrune;
4270
- /** Reset all local cached leases */
4271
4239
  clear(): void;
4272
- /** Invalidate local lease for a specific project */
4273
4240
  invalidate(projectId: string): void;
4274
4241
  }
4275
4242
  //#endregion
@@ -4321,16 +4288,6 @@ declare const LUA_SCHEDULER_POLL = "\n local key = KEYS[1]\n local maxScore =
4321
4288
  * address it counted stayed over its limit for good.
4322
4289
  */
4323
4290
  declare const LUA_COUNT_REQUEST = "\n local count = redis.call('INCR', KEYS[1])\n if redis.call('TTL', KEYS[1]) < 0 then\n redis.call('EXPIRE', KEYS[1], ARGV[1])\n end\n return count\n";
4324
- /**
4325
- * Two-phase idempotency lease acquisition. Checks sent/legacy, then attempts SET NX lock.
4326
- * @deprecated Nothing calls the `acquireLease` command; removed in the next minor version.
4327
- */
4328
- declare const LUA_ACQUIRE_LEASE = "\n if redis.call('EXISTS', KEYS[1]) == 1 or redis.call('EXISTS', KEYS[3]) == 1 then\n return 'completed'\n end\n local lockAcquired = redis.call('SET', KEYS[2], '1', 'EX', ARGV[1], 'NX')\n if lockAcquired then\n return 'acquired'\n end\n if redis.call('EXISTS', KEYS[1]) == 1 or redis.call('EXISTS', KEYS[3]) == 1 then\n return 'completed'\n end\n return 'locked'\n";
4329
- /**
4330
- * Two-phase idempotency completion marker. Atomically sets completed + legacy and deletes lock.
4331
- * @deprecated Nothing calls the `markProcessed` command; removed in the next minor version.
4332
- */
4333
- declare const LUA_MARK_PROCESSED = "\n redis.call('SET', KEYS[1], '1', 'EX', ARGV[1])\n redis.call('SET', KEYS[2], '1', 'EX', ARGV[1])\n redis.call('DEL', KEYS[3])\n return 1\n";
4334
4291
  /**
4335
4292
  * Registers pre-compiled custom commands on an ioredis instance.
4336
4293
  * Calls defineCommand so ioredis uses EVALSHA rather than re-transmitting
@@ -4346,17 +4303,9 @@ interface RedisClientOptions {
4346
4303
  declare class RedisClient {
4347
4304
  readonly native: Redis;
4348
4305
  /**
4349
- * One command connection per Redis URL for every service in this process.
4350
- *
4351
- * Each service used to open its own, so a single notification's commands
4352
- * reached Redis over three or four sockets, one round trip each. Sharing a
4353
- * connection lets auto-pipelining merge whatever the services issue in the
4354
- * same tick into one write, and Redis spends most of its time per round trip
4355
- * rather than per command. Blocking reads and subscribers still duplicate
4356
- * their own connections.
4357
- *
4358
- * The handle's `disconnect()` releases this caller's reference; the
4359
- * connection closes when the last service lets go.
4306
+ * One command connection per URL for every service in the process, so
4307
+ * auto-pipelining can batch what they send in the same tick. `disconnect()`
4308
+ * drops this caller's reference; the last one closes the connection.
4360
4309
  */
4361
4310
  static shared(options: RedisClientOptions): RedisClient;
4362
4311
  private readonly logger?;
@@ -4591,14 +4540,8 @@ declare class LRUCache<K, V> {
4591
4540
  //#region src/shared/utils.d.ts
4592
4541
  declare function getPriorityBucket(priority: string | undefined): "critical" | "normal" | "low";
4593
4542
  /**
4594
- * Canonical form of a destination, for suppression lookups.
4595
- *
4596
- * Both the writer (the provider webhook) and the reader (the engine's
4597
- * pre-dispatch gate) must agree on this, or an unsubscribe recorded as
4598
- * `Bob@Example.com` will not match a send addressed to `bob@example.com` and
4599
- * the person keeps receiving mail. Case folding is safe for email domains and
4600
- * for the local part in every mailbox provider in practice; phone numbers and
4601
- * push tokens are case-sensitive and are only trimmed.
4543
+ * Canonical address for suppression lookups; writers and readers must both use
4544
+ * it. Emails are lower-cased; phone numbers and push tokens are case-sensitive.
4602
4545
  */
4603
4546
  declare function normaliseTarget(target: string): string;
4604
4547
  //#endregion
@@ -4620,13 +4563,9 @@ interface BatchItem<T, R> {
4620
4563
  reject: (reason?: any) => void;
4621
4564
  }
4622
4565
  /**
4623
- * Coalesces individual `add()` calls into batched `flushFn` calls.
4624
- *
4625
- * A batch goes out when `maxSize` items are waiting or `maxWaitMs` has passed
4626
- * since the first one arrived. Up to `maxConcurrent` flushes may be in flight
4627
- * at once: with a single flight, every caller queued behind a slow flush holds
4628
- * its worker slot for the whole round trip, which caps a worker's throughput at
4629
- * `maxSize / flushLatency` no matter how much concurrency it was given.
4566
+ * Batches `add()` calls into `flushFn` calls, at `maxSize` items or after
4567
+ * `maxWaitMs`. Several flushes may run at once so one slow flush doesn't cap
4568
+ * the worker's throughput.
4630
4569
  */
4631
4570
  declare class BatchProcessor<T, R = void> {
4632
4571
  private readonly maxSize;
@@ -4753,33 +4692,20 @@ declare abstract class BaseWorker {
4753
4692
  recover(): Promise<void>;
4754
4693
  health(): WorkerHealth;
4755
4694
  /**
4756
- * Processes an event produced by an upstream stage in this same process,
4757
- * skipping the stream hop in between.
4758
- *
4759
- * The caller is still holding its own stream entry, and does not ack it until
4760
- * this returns. A thrown error therefore leaves that entry pending and the
4761
- * whole chain is replayed from the upstream stage; the idempotency keys each
4762
- * stage already checks make the replay safe. Non-retryable failures go to the
4763
- * dead-letter stream here, as they would have from this worker's own stream,
4764
- * so they do not send the upstream message there instead.
4695
+ * Processes an event from an upstream stage in this process, skipping the stream.
4696
+ * A throw leaves the caller's entry pending, so the chain replays from upstream.
4697
+ * Non-retryable failures are dead-lettered here so the upstream message isn't.
4765
4698
  */
4766
4699
  processInline(event: StreamEvent): Promise<void>;
4767
4700
  private processWithTracking;
4768
4701
  /**
4769
- * Runs `process` while keeping the entry's idle time below the reclaim
4770
- * threshold. Without this, a handler that outlasts `recoveryIntervalMs` (a
4771
- * large segment fan-out) is reclaimed mid-run and started again elsewhere,
4772
- * over and over, until it is dead-lettered while the first run still works.
4773
- * If this process dies the touches stop, so the entry is reclaimed as before.
4702
+ * Keeps the entry's idle time under the reclaim threshold while `process` runs,
4703
+ * so a long fan-out isn't reclaimed mid-run. If this process dies, the touches stop.
4774
4704
  */
4775
4705
  private processHoldingLease;
4776
4706
  /**
4777
- * `recoveryIntervalMs` is how long an entry must sit idle before it is
4778
- * claimed, not how often to look. Scanning only once per interval, timed from
4779
- * this worker's start, meant a worker restarted more often than that (a crash
4780
- * loop, an eager autoscaler) never scanned at all, and whatever its
4781
- * predecessors held stayed pending for good. So scan on start and then
4782
- * several times per interval; the idle threshold alone decides what is taken.
4707
+ * `recoveryIntervalMs` is the idle time before a claim, not the scan period.
4708
+ * Scan on start and several times per interval so crash-looping workers still recover.
4783
4709
  */
4784
4710
  private startRecoveryLoop;
4785
4711
  private stopRecoveryLoop;
@@ -4893,18 +4819,10 @@ declare function registerTransport(transport: Transport, priority?: number): voi
4893
4819
  //#endregion
4894
4820
  //#region src/unsubscribe/index.d.ts
4895
4821
  /**
4896
- * One-click unsubscribe (RFC 8058).
4897
- *
4898
- * Gmail and Yahoo have required `List-Unsubscribe` + `List-Unsubscribe-Post` on
4899
- * bulk mail since early 2024; without them bulk sends get throttled or junked,
4900
- * and because deliverability is reputation on the *sending domain*, that
4901
- * eventually drags transactional mail down with it.
4822
+ * One-click unsubscribe (RFC 8058), required by Gmail and Yahoo for bulk mail.
4902
4823
  *
4903
- * The link has to work from an inbox, years later, with no session — so the
4904
- * token carries its own claim and is signed rather than looked up. Nothing is
4905
- * stored per message, and there is no expiry: an unsubscribe link that has
4906
- * stopped working is worse than useless, because the recipient's next move is
4907
- * the spam button.
4824
+ * The token is signed, not stored, and never expires: the link has to keep
4825
+ * working from an old email, and a dead one sends people to the spam button.
4908
4826
  */
4909
4827
  interface UnsubscribeClaim {
4910
4828
  /** Project the send belonged to. */
@@ -5305,4 +5223,4 @@ declare class NotifkitServer extends EventEmitter {
5305
5223
  stop(): Promise<void>;
5306
5224
  }
5307
5225
  //#endregion
5308
- export { AI_DEFAULTS, AddContactInput, AddContactSchema, AddUserInput, AddUserSchema, AdminUserRecord, AdminUserRepository, AiConfig, ApiRateLimiter, ApiRateLimiterOptions, AppError, AsyncSemaphore, BaseConfig, BaseWorker, BatchAddContactsInput, BatchAddContactsSchema, BatchItem, BatchProcessor, CONSUMER_GROUPS, CircuitBreaker, CircuitBreakerOptions, ConsumerGroup, ContactChannel, ContactChannelSchema, ContactRepository, CreateWorkflowInput, CreateWorkflowSchema, CreatedProjectKeyRecord, DLQMessageRecord, DataLoader, DataLoaderOptions, DatabaseClients, DatabaseOptions, Db, DeliveryOptions, DeliveryOptionsSchema, DeliveryResult, DevicePlatform, DeviceToken, DispatchedTaskPayload, ENRICHED_STREAMS, EscapeMode, EventEnvelope, EventEnvelopeSchema, EventMetadata, EventMetadataSchema, EventPayloadMap, EventRegistry, INBOUND_STREAMS, IdempotencyGuard, IdempotencyOptions, IngestEventInput, IngestEventSchema, InlineUser, InlineUserSchema, KnownEventType, LRUCache, LUA_ACQUIRE_LEASE, LUA_COUNT_REQUEST, LUA_LEASE_API_RATE_LIMIT, LUA_MARK_PROCESSED, LUA_RELEASE_LOCK, LUA_RENEW_LOCK, LUA_SCHEDULER_POLL, LUA_USER_THROTTLE, LeaseResult, LockHeldError, LogLevel, Logger, LoggerOptions, MigrationOptions, NonRetryableError, NotificationAiPendingPayload, NotificationAiPendingPayloadSchema, NotificationCanceledPayload, NotificationCanceledPayloadSchema, NotificationChannel, NotificationChannelSchema, NotificationCreatedPayload, NotificationCreatedPayloadSchema, NotificationDeliveredPayload, NotificationDeliveredPayloadSchema, NotificationDispatchedPayload, NotificationDispatchedPayloadSchema, NotificationEnrichedPayload, NotificationEnrichedPayloadSchema, NotificationFailedPayload, NotificationFailedPayloadSchema, NotificationLogRecord, NotificationPreference, NotificationPriority, NotificationPrioritySchema, NotificationRequestedPayload, NotificationRequestedPayloadSchema, NotificationScheduledPayload, NotificationScheduledPayloadSchema, NotificationSkippedPayload, NotificationSkippedPayloadSchema, NotificationStatus, NotificationStatusSchema, NotificationTarget, NotificationTargetSchema, NotifkitClient, NotifkitClientOptions, NotifkitOptions, NotifkitServer, NotifyRequestInput, NotifyRequestSchema, OUTBOUND_STREAMS, PUBSUB_CHANNELS, ParseResult, PendingEntry, PendingMessageScanner, PendingMessageScannerOptions, PreferenceRepository, Preferences, PreferencesSchema, ProcessResult, ProjectKeyRecord, ProjectRecord, ProjectRepository, ProjectSettingsCache, ProjectSettingsCacheOptions, ProjectThrottleSettings, PubSubChannel, QuietHours, QuietHoursSchema, RateLimitConfig, RecipientProfile, RecipientProfileSchema, Redis, RedisClient, RedisClientOptions, type RedisOptions, RenderedContent, RenderedContentSchema, STREAMS, SegmentRepository, Sql, StreamConsumer, StreamConsumerOptions, StreamEvent, StreamEventMetadata, StreamEventMetadataSchema, StreamEventSchema, StreamMessage, StreamName, StreamProducer, StreamProducerOptions, SuppressionRecord, SuspendExecutionError, SyncTemplatesInput, SyncTemplatesSchema, SystemHealthRecord, SystemMetricsRecord, TemplateCache, TemplateInput, TemplateRecord, TemplateRecordResponse, TemplateRepository, TemplateSchema, ThrottleCheckOptions, ThrottleResult, Transport, TriggerWorkflowInput, TriggerWorkflowSchema, TypedEventEnvelope, UnsubscribeClaim, UnsubscribeHeaderOptions, UpdateProjectInput, UpdateProjectSchema, UpdateUserInput, UpdateUserSchema, UserContact, UserContactInput, UserContactInputSchema, UserContactResponse, UserDetailResponse, UserProfile, UserProfileResponse, UserRecord, UserRepository, UserResponse, UserThrottle, UserThrottleOptions, ValidationError, WebhookEvent, WorkerHealth, WorkerOptions, WorkerState, WorkflowContext, WorkflowDefinitionRecord, WorkflowEvent, WorkflowInstanceRecord, WorkflowNotifyInput, WorkflowNotifyPayloadSchema, WorkflowNotifyResult, WorkflowRepository, WorkflowStepContext, WorkflowStepDef, WorkflowStepRecord, WorkflowStepSchema, WorkflowWaiterRecord, assertTablesInSchema, baseConfigSchema, buildStepNotifyPayload, buildStreamEvent, buildUnsubscribeHeaders, calculateTokenBatchSize, createDatabase, createLogger, escapeHeader, escapeHtml, generateId, getAiConfig, getMetricsRegistry, getPriorityBucket, globalEmitter, interpolate, loadEnv, metrics, migrateDatabase, normaliseTarget, notifkitTableNames, parseConfig, qualifyMigrationSql, readBaseConfig, redactUrl, registerCustomCommands, registerTransport, registry, renderWithTemplate, resolveStepTarget, runMigrations, setAiConfig, setGlobalConfig, signUnsubscribeToken, sleep, startHealthReporter, transportRegistry, verifyUnsubscribeToken, workflow, workflowRegistry };
5226
+ export { AI_DEFAULTS, AddContactInput, AddContactSchema, AddUserInput, AddUserSchema, AdminUserRecord, AdminUserRepository, AiConfig, ApiRateLimiter, ApiRateLimiterOptions, AppError, AsyncSemaphore, BaseConfig, BaseWorker, BatchAddContactsInput, BatchAddContactsSchema, BatchItem, BatchProcessor, CONSUMER_GROUPS, CircuitBreaker, CircuitBreakerOptions, ConsumerGroup, ContactChannel, ContactChannelSchema, ContactRepository, CreateWorkflowInput, CreateWorkflowSchema, CreatedProjectKeyRecord, DLQMessageRecord, DataLoader, DataLoaderOptions, DatabaseClients, DatabaseOptions, Db, DeliveryOptions, DeliveryOptionsSchema, DeliveryResult, DevicePlatform, DeviceToken, DispatchedTaskPayload, ENRICHED_STREAMS, EscapeMode, EventEnvelope, EventEnvelopeSchema, EventMetadata, EventMetadataSchema, EventPayloadMap, EventRegistry, INBOUND_STREAMS, IdempotencyGuard, IdempotencyOptions, IngestEventInput, IngestEventSchema, InlineUser, InlineUserSchema, KnownEventType, LRUCache, LUA_COUNT_REQUEST, LUA_LEASE_API_RATE_LIMIT, LUA_RELEASE_LOCK, LUA_RENEW_LOCK, LUA_SCHEDULER_POLL, LUA_USER_THROTTLE, LeaseResult, LockHeldError, LogLevel, Logger, LoggerOptions, MigrationOptions, NonRetryableError, NotificationAiPendingPayload, NotificationAiPendingPayloadSchema, NotificationCanceledPayload, NotificationCanceledPayloadSchema, NotificationChannel, NotificationChannelSchema, NotificationCreatedPayload, NotificationCreatedPayloadSchema, NotificationDeliveredPayload, NotificationDeliveredPayloadSchema, NotificationDispatchedPayload, NotificationDispatchedPayloadSchema, NotificationEnrichedPayload, NotificationEnrichedPayloadSchema, NotificationFailedPayload, NotificationFailedPayloadSchema, NotificationLogRecord, NotificationPreference, NotificationPriority, NotificationPrioritySchema, NotificationRequestedPayload, NotificationRequestedPayloadSchema, NotificationScheduledPayload, NotificationScheduledPayloadSchema, NotificationSkippedPayload, NotificationSkippedPayloadSchema, NotificationStatus, NotificationStatusSchema, NotificationTarget, NotificationTargetSchema, NotifkitClient, NotifkitClientOptions, NotifkitOptions, NotifkitServer, NotifyRequestInput, NotifyRequestSchema, OUTBOUND_STREAMS, PUBSUB_CHANNELS, ParseResult, PendingEntry, PendingMessageScanner, PendingMessageScannerOptions, PreferenceRepository, Preferences, PreferencesSchema, ProcessResult, ProjectKeyRecord, ProjectRecord, ProjectRepository, ProjectSettingsCache, ProjectSettingsCacheOptions, ProjectThrottleSettings, PubSubChannel, QuietHours, QuietHoursSchema, RateLimitConfig, RecipientProfile, RecipientProfileSchema, Redis, RedisClient, RedisClientOptions, type RedisOptions, RenderedContent, RenderedContentSchema, STREAMS, SegmentRepository, Sql, StreamConsumer, StreamConsumerOptions, StreamEvent, StreamEventMetadata, StreamEventMetadataSchema, StreamEventSchema, StreamMessage, StreamName, StreamProducer, StreamProducerOptions, SuppressionRecord, SuspendExecutionError, SyncTemplatesInput, SyncTemplatesSchema, SystemHealthRecord, SystemMetricsRecord, TemplateCache, TemplateInput, TemplateRecord, TemplateRecordResponse, TemplateRepository, TemplateSchema, ThrottleCheckOptions, ThrottleResult, Transport, TriggerWorkflowInput, TriggerWorkflowSchema, TypedEventEnvelope, UnsubscribeClaim, UnsubscribeHeaderOptions, UpdateProjectInput, UpdateProjectSchema, UpdateUserInput, UpdateUserSchema, UserContact, UserContactInput, UserContactInputSchema, UserContactResponse, UserDetailResponse, UserProfile, UserProfileResponse, UserRecord, UserRepository, UserResponse, UserThrottle, UserThrottleOptions, ValidationError, WebhookEvent, WorkerHealth, WorkerOptions, WorkerState, WorkflowContext, WorkflowDefinitionRecord, WorkflowEvent, WorkflowInstanceRecord, WorkflowNotifyInput, WorkflowNotifyPayloadSchema, WorkflowNotifyResult, WorkflowRepository, WorkflowStepContext, WorkflowStepDef, WorkflowStepRecord, WorkflowStepSchema, WorkflowWaiterRecord, assertTablesInSchema, baseConfigSchema, buildStepNotifyPayload, buildStreamEvent, buildUnsubscribeHeaders, calculateTokenBatchSize, createDatabase, createLogger, escapeHeader, escapeHtml, generateId, getAiConfig, getMetricsRegistry, getPriorityBucket, globalEmitter, interpolate, loadEnv, metrics, migrateDatabase, normaliseTarget, notifkitTableNames, parseConfig, qualifyMigrationSql, readBaseConfig, redactUrl, registerCustomCommands, registerTransport, registry, renderWithTemplate, resolveStepTarget, runMigrations, setAiConfig, setGlobalConfig, signUnsubscribeToken, sleep, startHealthReporter, transportRegistry, verifyUnsubscribeToken, workflow, workflowRegistry };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as assertTablesInSchema, $t as OUTBOUND_STREAMS, A as LUA_ACQUIRE_LEASE, An as globalEmitter, At as NotificationTargetSchema, B as redactUrl, Bt as QuietHoursSchema, C as SegmentRepository, Cn as DataLoader, Ct as NotificationDispatchedPayloadSchema, D as ContactRepository, Dn as getPriorityBucket, Dt as RecipientProfileSchema, E as TemplateRepository, En as AsyncSemaphore, Et as NotificationEnrichedPayloadSchema, F as LUA_RENEW_LOCK, Ft as CreateWorkflowSchema, G as ProjectSettingsCache, Gt as UpdateUserSchema, H as ApiRateLimiter, Ht as TemplateSchema, I as LUA_SCHEDULER_POLL, It as IngestEventSchema, J as StreamProducer, Jt as WorkflowStepSchema, K as PendingMessageScanner, Kt as UserContactInputSchema, L as LUA_USER_THROTTLE, Lt as InlineUserSchema, M as LUA_LEASE_API_RATE_LIMIT, Mt as AddUserSchema, N as LUA_MARK_PROCESSED, Nt as BatchAddContactsSchema, O as PreferenceRepository, On as normaliseTarget, Ot as NotificationCreatedPayloadSchema, P as LUA_RELEASE_LOCK, Pt as ContactChannelSchema, Q as IdempotencyGuard, Qt as INBOUND_STREAMS, R as Redis, Rt as NotifyRequestSchema, S as AdminUserRepository, Sn as sleep, St as DeliveryOptionsSchema, T as ProjectRepository, Tn as BatchProcessor, Tt as NotificationScheduledPayloadSchema, U as calculateTokenBatchSize, Ut as TriggerWorkflowSchema, V as registerCustomCommands, Vt as SyncTemplatesSchema, W as UserThrottle, Wt as UpdateProjectSchema, X as metrics, Xt as CONSUMER_GROUPS, Y as getMetricsRegistry, Yt as buildStreamEvent, Z as createLogger, Zt as ENRICHED_STREAMS, _ as TemplateCache, _n as setAiConfig, _t as NotificationAiPendingPayloadSchema, a as SuspendExecutionError, an as EventRegistry, b as interpolate, bn as ValidationError, bt as NotificationFailedPayloadSchema, c as BaseWorker, cn as NotificationChannelSchema, d as startHealthReporter, dn as AI_DEFAULTS, en as PUBSUB_CHANNELS, et as createDatabase, f as buildUnsubscribeHeaders, fn as baseConfigSchema, g as transportRegistry, gn as readBaseConfig, h as registerTransport, hn as parseConfig, i as workflowRegistry, in as StreamEventSchema, it as runMigrations, j as LUA_COUNT_REQUEST, jt as AddContactSchema, k as UserRepository, kn as LRUCache, kt as NotificationRequestedPayloadSchema, l as LockHeldError, ln as NotificationPrioritySchema, m as verifyUnsubscribeToken, mn as loadEnv, n as NotifkitClient, nn as EventEnvelopeSchema, nt as notifkitTableNames, o as buildStepNotifyPayload, on as registry, p as signUnsubscribeToken, pn as getAiConfig, q as StreamConsumer, qt as WorkflowNotifyPayloadSchema, r as workflow, rn as StreamEventMetadataSchema, rt as qualifyMigrationSql, s as resolveStepTarget, sn as EventMetadataSchema, t as NotifkitServer, tn as STREAMS, tt as migrateDatabase, u as NonRetryableError, un as NotificationStatusSchema, v as escapeHeader, vn as setGlobalConfig, vt as NotificationCanceledPayloadSchema, w as WorkflowRepository, wn as CircuitBreaker, wt as RenderedContentSchema, x as renderWithTemplate, xn as generateId, xt as NotificationDeliveredPayloadSchema, y as escapeHtml, yn as AppError, yt as NotificationSkippedPayloadSchema, z as RedisClient, zt as PreferencesSchema } from "./src-BRatuWJS.mjs";
2
- export { AI_DEFAULTS, AddContactSchema, AddUserSchema, AdminUserRepository, ApiRateLimiter, AppError, AsyncSemaphore, BaseWorker, BatchAddContactsSchema, BatchProcessor, CONSUMER_GROUPS, CircuitBreaker, ContactChannelSchema, ContactRepository, CreateWorkflowSchema, DataLoader, DeliveryOptionsSchema, ENRICHED_STREAMS, EventEnvelopeSchema, EventMetadataSchema, EventRegistry, INBOUND_STREAMS, IdempotencyGuard, IngestEventSchema, InlineUserSchema, LRUCache, LUA_ACQUIRE_LEASE, LUA_COUNT_REQUEST, LUA_LEASE_API_RATE_LIMIT, LUA_MARK_PROCESSED, LUA_RELEASE_LOCK, LUA_RENEW_LOCK, LUA_SCHEDULER_POLL, LUA_USER_THROTTLE, LockHeldError, NonRetryableError, NotificationAiPendingPayloadSchema, NotificationCanceledPayloadSchema, NotificationChannelSchema, NotificationCreatedPayloadSchema, NotificationDeliveredPayloadSchema, NotificationDispatchedPayloadSchema, NotificationEnrichedPayloadSchema, NotificationFailedPayloadSchema, NotificationPrioritySchema, NotificationRequestedPayloadSchema, NotificationScheduledPayloadSchema, NotificationSkippedPayloadSchema, NotificationStatusSchema, NotificationTargetSchema, NotifkitClient, NotifkitServer, NotifyRequestSchema, OUTBOUND_STREAMS, PUBSUB_CHANNELS, PendingMessageScanner, PreferenceRepository, PreferencesSchema, ProjectRepository, ProjectSettingsCache, QuietHoursSchema, RecipientProfileSchema, Redis, RedisClient, RenderedContentSchema, STREAMS, SegmentRepository, StreamConsumer, StreamEventMetadataSchema, StreamEventSchema, StreamProducer, SuspendExecutionError, SyncTemplatesSchema, TemplateCache, TemplateRepository, TemplateSchema, TriggerWorkflowSchema, UpdateProjectSchema, UpdateUserSchema, UserContactInputSchema, UserRepository, UserThrottle, ValidationError, WorkflowNotifyPayloadSchema, WorkflowRepository, WorkflowStepSchema, assertTablesInSchema, baseConfigSchema, buildStepNotifyPayload, buildStreamEvent, buildUnsubscribeHeaders, calculateTokenBatchSize, createDatabase, createLogger, escapeHeader, escapeHtml, generateId, getAiConfig, getMetricsRegistry, getPriorityBucket, globalEmitter, interpolate, loadEnv, metrics, migrateDatabase, normaliseTarget, notifkitTableNames, parseConfig, qualifyMigrationSql, readBaseConfig, redactUrl, registerCustomCommands, registerTransport, registry, renderWithTemplate, resolveStepTarget, runMigrations, setAiConfig, setGlobalConfig, signUnsubscribeToken, sleep, startHealthReporter, transportRegistry, verifyUnsubscribeToken, workflow, workflowRegistry };
1
+ import { $ as migrateDatabase, $t as STREAMS, A as LUA_COUNT_REQUEST, At as AddUserSchema, B as ApiRateLimiter, Bt as TemplateSchema, C as SegmentRepository, Cn as BatchProcessor, Ct as NotificationScheduledPayloadSchema, D as ContactRepository, Dn as LRUCache, Dt as NotificationRequestedPayloadSchema, E as TemplateRepository, En as normaliseTarget, Et as NotificationCreatedPayloadSchema, F as LUA_USER_THROTTLE, Ft as InlineUserSchema, G as StreamConsumer, Gt as WorkflowNotifyPayloadSchema, H as UserThrottle, Ht as UpdateProjectSchema, I as Redis, It as NotifyRequestSchema, J as metrics, Jt as CONSUMER_GROUPS, K as StreamProducer, Kt as WorkflowStepSchema, L as RedisClient, Lt as PreferencesSchema, M as LUA_RELEASE_LOCK, Mt as ContactChannelSchema, N as LUA_RENEW_LOCK, Nt as CreateWorkflowSchema, O as PreferenceRepository, On as globalEmitter, Ot as NotificationTargetSchema, P as LUA_SCHEDULER_POLL, Pt as IngestEventSchema, Q as createDatabase, Qt as PUBSUB_CHANNELS, R as redactUrl, Rt as QuietHoursSchema, S as AdminUserRepository, Sn as CircuitBreaker, St as RenderedContentSchema, T as ProjectRepository, Tn as getPriorityBucket, Tt as RecipientProfileSchema, U as ProjectSettingsCache, Ut as UpdateUserSchema, V as calculateTokenBatchSize, Vt as TriggerWorkflowSchema, W as PendingMessageScanner, Wt as UserContactInputSchema, X as IdempotencyGuard, Xt as INBOUND_STREAMS, Y as createLogger, Yt as ENRICHED_STREAMS, Z as assertTablesInSchema, Zt as OUTBOUND_STREAMS, _ as TemplateCache, _n as AppError, _t as NotificationSkippedPayloadSchema, a as SuspendExecutionError, an as EventMetadataSchema, b as interpolate, bn as sleep, bt as DeliveryOptionsSchema, c as BaseWorker, cn as NotificationStatusSchema, d as startHealthReporter, dn as getAiConfig, en as EventEnvelopeSchema, et as notifkitTableNames, f as buildUnsubscribeHeaders, fn as loadEnv, g as transportRegistry, gn as setGlobalConfig, gt as NotificationCanceledPayloadSchema, h as registerTransport, hn as setAiConfig, ht as NotificationAiPendingPayloadSchema, i as workflowRegistry, in as registry, j as LUA_LEASE_API_RATE_LIMIT, jt as BatchAddContactsSchema, k as UserRepository, kt as AddContactSchema, l as LockHeldError, ln as AI_DEFAULTS, m as verifyUnsubscribeToken, mn as readBaseConfig, n as NotifkitClient, nn as StreamEventSchema, nt as runMigrations, o as buildStepNotifyPayload, on as NotificationChannelSchema, p as signUnsubscribeToken, pn as parseConfig, q as getMetricsRegistry, qt as buildStreamEvent, r as workflow, rn as EventRegistry, s as resolveStepTarget, sn as NotificationPrioritySchema, t as NotifkitServer, tn as StreamEventMetadataSchema, tt as qualifyMigrationSql, u as NonRetryableError, un as baseConfigSchema, v as escapeHeader, vn as ValidationError, vt as NotificationFailedPayloadSchema, w as WorkflowRepository, wn as AsyncSemaphore, wt as NotificationEnrichedPayloadSchema, x as renderWithTemplate, xn as DataLoader, xt as NotificationDispatchedPayloadSchema, y as escapeHtml, yn as generateId, yt as NotificationDeliveredPayloadSchema, z as registerCustomCommands, zt as SyncTemplatesSchema } from "./src-aiRAj2xr.mjs";
2
+ export { AI_DEFAULTS, AddContactSchema, AddUserSchema, AdminUserRepository, ApiRateLimiter, AppError, AsyncSemaphore, BaseWorker, BatchAddContactsSchema, BatchProcessor, CONSUMER_GROUPS, CircuitBreaker, ContactChannelSchema, ContactRepository, CreateWorkflowSchema, DataLoader, DeliveryOptionsSchema, ENRICHED_STREAMS, EventEnvelopeSchema, EventMetadataSchema, EventRegistry, INBOUND_STREAMS, IdempotencyGuard, IngestEventSchema, InlineUserSchema, LRUCache, LUA_COUNT_REQUEST, LUA_LEASE_API_RATE_LIMIT, LUA_RELEASE_LOCK, LUA_RENEW_LOCK, LUA_SCHEDULER_POLL, LUA_USER_THROTTLE, LockHeldError, NonRetryableError, NotificationAiPendingPayloadSchema, NotificationCanceledPayloadSchema, NotificationChannelSchema, NotificationCreatedPayloadSchema, NotificationDeliveredPayloadSchema, NotificationDispatchedPayloadSchema, NotificationEnrichedPayloadSchema, NotificationFailedPayloadSchema, NotificationPrioritySchema, NotificationRequestedPayloadSchema, NotificationScheduledPayloadSchema, NotificationSkippedPayloadSchema, NotificationStatusSchema, NotificationTargetSchema, NotifkitClient, NotifkitServer, NotifyRequestSchema, OUTBOUND_STREAMS, PUBSUB_CHANNELS, PendingMessageScanner, PreferenceRepository, PreferencesSchema, ProjectRepository, ProjectSettingsCache, QuietHoursSchema, RecipientProfileSchema, Redis, RedisClient, RenderedContentSchema, STREAMS, SegmentRepository, StreamConsumer, StreamEventMetadataSchema, StreamEventSchema, StreamProducer, SuspendExecutionError, SyncTemplatesSchema, TemplateCache, TemplateRepository, TemplateSchema, TriggerWorkflowSchema, UpdateProjectSchema, UpdateUserSchema, UserContactInputSchema, UserRepository, UserThrottle, ValidationError, WorkflowNotifyPayloadSchema, WorkflowRepository, WorkflowStepSchema, assertTablesInSchema, baseConfigSchema, buildStepNotifyPayload, buildStreamEvent, buildUnsubscribeHeaders, calculateTokenBatchSize, createDatabase, createLogger, escapeHeader, escapeHtml, generateId, getAiConfig, getMetricsRegistry, getPriorityBucket, globalEmitter, interpolate, loadEnv, metrics, migrateDatabase, normaliseTarget, notifkitTableNames, parseConfig, qualifyMigrationSql, readBaseConfig, redactUrl, registerCustomCommands, registerTransport, registry, renderWithTemplate, resolveStepTarget, runMigrations, setAiConfig, setGlobalConfig, signUnsubscribeToken, sleep, startHealthReporter, transportRegistry, verifyUnsubscribeToken, workflow, workflowRegistry };
@@ -1,14 +1,10 @@
1
- import { An as globalEmitter, D as ContactRepository, Dn as getPriorityBucket, E as TemplateRepository, Q as IdempotencyGuard, Qt as INBOUND_STREAMS, Xt as CONSUMER_GROUPS, Yt as buildStreamEvent, _ as TemplateCache, c as BaseWorker, d as startHealthReporter, gn as readBaseConfig, k as UserRepository, mn as loadEnv, on as registry } from "./src-BRatuWJS.mjs";
2
- import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime, t as createPriorityProducers } from "./bootstrap-P63acBG9.mjs";
1
+ import { D as ContactRepository, E as TemplateRepository, Jt as CONSUMER_GROUPS, On as globalEmitter, Tn as getPriorityBucket, X as IdempotencyGuard, Xt as INBOUND_STREAMS, _ as TemplateCache, c as BaseWorker, d as startHealthReporter, fn as loadEnv, in as registry, k as UserRepository, mn as readBaseConfig, qt as buildStreamEvent } from "./src-aiRAj2xr.mjs";
2
+ import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime, t as createPriorityProducers } from "./bootstrap-CHOj1rDv.mjs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  //#region src/services/enricher/main.ts
5
5
  loadEnv();
6
6
  const config = readBaseConfig();
7
- /**
8
- * A caller's own idempotency key (X-Idempotency-Key, or a workflow step's) is a
9
- * documented 24-hour promise. Without one the key is the event's id, which only
10
- * a redelivery can bring back, so the guard's shorter TTL is enough.
11
- */
7
+ const chunkArray = (arr, size) => Array.from({ length: Math.ceil(arr.length / size) }, (_, i) => arr.slice(i * size, i * size + size));
12
8
  const CALLER_KEY_TTL_SECONDS = 86400;
13
9
  const dedupeTtl = (raw) => raw.idempotencyKey ? CALLER_KEY_TTL_SECONDS : void 0;
14
10
  let logger;
@@ -77,10 +73,8 @@ var EnricherWorker = class extends BaseWorker {
77
73
  this.flushTimer = setInterval(() => void this.flushWorkerBuffers(), 5);
78
74
  }
79
75
  /**
80
- * Hands enriched events for single-user notifications straight to `next`
81
- * instead of the enriched stream. Fan-outs still go through the stream: an
82
- * inline chain holds this worker's slot until the last send completes, and a
83
- * segment would hold one slot for thousands of them.
76
+ * Single-user notifications skip the enriched stream. Fan-outs keep it, since an
77
+ * inline chain holds this worker's slot until its last send completes.
84
78
  */
85
79
  setInlineNext(next) {
86
80
  this.inlineNext = next;
@@ -270,7 +264,6 @@ var EnricherWorker = class extends BaseWorker {
270
264
  const topics = (raw.templateId ? await this.templateCache.getCachedTemplate(raw.projectId, raw.templateId) : null)?.topics ?? [];
271
265
  const channels = raw.channels && raw.channels.length > 0 ? raw.channels : ["email"];
272
266
  const isFallback = raw.fallback === true;
273
- const chunkArray = (arr, size) => Array.from({ length: Math.ceil(arr.length / size) }, (v, i) => arr.slice(i * size, i * size + size));
274
267
  const chunks = chunkArray(userIds, 500);
275
268
  const inline = raw.target.type === "user" ? this.inlineNext : null;
276
269
  for (const chunk of chunks) {
@@ -1,23 +1,12 @@
1
- import { An as globalEmitter, D as ContactRepository, Dn as getPriorityBucket, E as TemplateRepository, On as normaliseTarget, Xt as CONSUMER_GROUPS, Yt as buildStreamEvent, c as BaseWorker, d as startHealthReporter, gn as readBaseConfig, k as UserRepository, lt as scheduledPayloads, mn as loadEnv, on as registry, tn as STREAMS, ut as suppressions } from "./src-BRatuWJS.mjs";
2
- import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime, t as createPriorityProducers } from "./bootstrap-P63acBG9.mjs";
1
+ import { $t as STREAMS, D as ContactRepository, E as TemplateRepository, En as normaliseTarget, Jt as CONSUMER_GROUPS, On as globalEmitter, Tn as getPriorityBucket, c as BaseWorker, ct as suppressions, d as startHealthReporter, fn as loadEnv, in as registry, it as messageLogs, k as UserRepository, mn as readBaseConfig, qt as buildStreamEvent, rt as deliveryOutbox, st as scheduledPayloads } from "./src-aiRAj2xr.mjs";
2
+ import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime, t as createPriorityProducers } from "./bootstrap-CHOj1rDv.mjs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { and, asc, eq, gt, inArray, or, sql } from "drizzle-orm";
5
5
  //#region src/services/scheduler/send-gate.ts
6
6
  /**
7
- * Re-checks parked sends at the moment they are released.
8
- *
9
- * The engine clears a message against suppressions, opt-outs and contacts when
10
- * it first sees it. A send parked for later — a `sendAt`, a quiet-hours
11
- * deferral, a retry — can sit for hours or days, and whatever the person did in
12
- * between (unsubscribed, complained, hard-bounced, removed the address) must
13
- * still stop it. Without this the scheduler sent to them anyway.
14
- *
15
- * Reads Postgres directly rather than through the repositories' caches: this
16
- * runs once per poll, not once per message, and a stale "still subscribed" is
17
- * the very thing it exists to prevent.
18
- *
19
- * Returns the blocked tasks with the reason. Throws if a lookup fails, so the
20
- * caller holds the batch rather than sending it unchecked.
7
+ * Re-checks parked sends at release: an unsubscribe, bounce or removed address
8
+ * since parking must still stop them. Reads Postgres, not the caches, and
9
+ * throws on a failed lookup so the batch is held rather than sent unchecked.
21
10
  */
22
11
  async function findBlockedAtRelease(db, tasks) {
23
12
  const blocked = /* @__PURE__ */ new Map();
@@ -64,6 +53,35 @@ function decide(t, topics, suppressed, user, contactsByUser) {
64
53
  }
65
54
  }
66
55
  //#endregion
56
+ //#region src/services/scheduler/retention.ts
57
+ const BATCH = 5e3;
58
+ const PRUNE_LOCK_KEY = "notif:lock:scheduler:prune";
59
+ /** Deletes delivery log and outbox rows older than `retentionDays`, in batches. */
60
+ async function pruneDeliveryLogs(db, retentionDays) {
61
+ const cutoff = (/* @__PURE__ */ new Date(Date.now() - retentionDays * 864e5)).toISOString();
62
+ const tables = [[messageLogs, messageLogs.timestamp], [deliveryOutbox, deliveryOutbox.createdAt]];
63
+ let total = 0;
64
+ for (const [table, column] of tables) for (;;) {
65
+ const rows = await db.execute(sql`DELETE FROM ${table} WHERE ctid IN (SELECT ctid FROM ${table} WHERE ${column} < ${cutoff}::timestamptz LIMIT ${BATCH}) RETURNING 1`);
66
+ total += rows.length;
67
+ if (rows.length < BATCH) break;
68
+ }
69
+ return total;
70
+ }
71
+ /** Runs the prune once per hour across all scheduler processes. */
72
+ async function maybePruneDeliveryLogs(redis, db, logger, retentionDays) {
73
+ try {
74
+ if (await redis.set(PRUNE_LOCK_KEY, "1", "EX", 3600, "NX") !== "OK") return;
75
+ const deleted = await pruneDeliveryLogs(db, retentionDays);
76
+ if (deleted > 0) logger.info({
77
+ deleted,
78
+ retentionDays
79
+ }, "pruned old delivery logs");
80
+ } catch (err) {
81
+ logger.error({ err }, "delivery log prune failed");
82
+ }
83
+ }
84
+ //#endregion
67
85
  //#region src/services/scheduler/main.ts
68
86
  loadEnv();
69
87
  const config = readBaseConfig();
@@ -282,6 +300,7 @@ async function startSchedulerWorker() {
282
300
  if (!isPolling) return;
283
301
  try {
284
302
  if (!await redis.native.exists("notif:scheduler:intact")) await rebuildScheduledQueue(redis.native, db, logger);
303
+ if (config.LOG_RETENTION_DAYS) maybePruneDeliveryLogs(redis.native, db, logger, config.LOG_RETENTION_DAYS);
285
304
  const hasMore = await executeSchedulerPoll(redis.native, outboundProducers, logger, db);
286
305
  if (isPolling) pollTimeout = setTimeout(() => void pollLoop(), hasMore ? 0 : 5e3);
287
306
  } catch (err) {
@@ -1,6 +1,6 @@
1
- import { An as globalEmitter, B as redactUrl, E as TemplateRepository, J as StreamProducer, Q as IdempotencyGuard, Xt as CONSUMER_GROUPS, _ as TemplateCache, c as BaseWorker, d as startHealthReporter, dn as AI_DEFAULTS, en as PUBSUB_CHANNELS, gn as readBaseConfig, mn as loadEnv, on as registry, pn as getAiConfig, tn as STREAMS, x as renderWithTemplate } from "./src-BRatuWJS.mjs";
2
- import { t as scheduleOrDispatch } from "./schedule-or-dispatch-C5qfxQCv.mjs";
3
- import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime, t as createPriorityProducers } from "./bootstrap-P63acBG9.mjs";
1
+ import { $t as STREAMS, E as TemplateRepository, Jt as CONSUMER_GROUPS, K as StreamProducer, On as globalEmitter, Qt as PUBSUB_CHANNELS, R as redactUrl, X as IdempotencyGuard, _ as TemplateCache, c as BaseWorker, d as startHealthReporter, dn as getAiConfig, fn as loadEnv, in as registry, ln as AI_DEFAULTS, mn as readBaseConfig, x as renderWithTemplate } from "./src-aiRAj2xr.mjs";
2
+ import { t as scheduleOrDispatch } from "./schedule-or-dispatch-BF85qhMh.mjs";
3
+ import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime, t as createPriorityProducers } from "./bootstrap-CHOj1rDv.mjs";
4
4
  import { generateText } from "ai";
5
5
  //#region src/services/ai/main.ts
6
6
  loadEnv();
@@ -1,6 +1,6 @@
1
- import { J as StreamProducer, Xt as CONSUMER_GROUPS, Yt as buildStreamEvent, c as BaseWorker, d as startHealthReporter, gn as readBaseConfig, gt as workflowWaiters, ht as workflowSteps, mn as loadEnv, mt as workflowInstances, tn as STREAMS } from "./src-BRatuWJS.mjs";
2
- import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime } from "./bootstrap-P63acBG9.mjs";
3
- import { t as insertMessageLogs } from "./bulk-Beblt3ny.mjs";
1
+ import { $t as STREAMS, Jt as CONSUMER_GROUPS, K as StreamProducer, c as BaseWorker, d as startHealthReporter, fn as loadEnv, ft as workflowInstances, mn as readBaseConfig, mt as workflowWaiters, pt as workflowSteps, qt as buildStreamEvent } from "./src-aiRAj2xr.mjs";
2
+ import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime } from "./bootstrap-CHOj1rDv.mjs";
3
+ import { t as insertMessageLogs } from "./bulk-CAsYwF-9.mjs";
4
4
  import { and, eq, gt, isNull, or } from "drizzle-orm";
5
5
  //#region src/services/events/main.ts
6
6
  loadEnv();
@@ -1,5 +1,5 @@
1
- import { J as StreamProducer, Xt as CONSUMER_GROUPS, Yt as buildStreamEvent, a as SuspendExecutionError, c as BaseWorker, d as startHealthReporter, gn as readBaseConfig, gt as workflowWaiters, ht as workflowSteps, i as workflowRegistry, mn as loadEnv, mt as workflowInstances, o as buildStepNotifyPayload, pt as workflowDefinitions, tn as STREAMS } from "./src-BRatuWJS.mjs";
2
- import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime } from "./bootstrap-P63acBG9.mjs";
1
+ import { $t as STREAMS, Jt as CONSUMER_GROUPS, K as StreamProducer, a as SuspendExecutionError, c as BaseWorker, d as startHealthReporter, dt as workflowDefinitions, fn as loadEnv, ft as workflowInstances, i as workflowRegistry, mn as readBaseConfig, mt as workflowWaiters, o as buildStepNotifyPayload, pt as workflowSteps, qt as buildStreamEvent } from "./src-aiRAj2xr.mjs";
2
+ import { a as uniqueConsumerId, i as shutdownWorker, n as createStreamConsumer, r as createWorkerRuntime } from "./bootstrap-CHOj1rDv.mjs";
3
3
  import { randomUUID } from "node:crypto";
4
4
  import { and, eq } from "drizzle-orm";
5
5
  //#region src/services/workflow/timers.ts
@@ -51,7 +51,7 @@ async function reapStuckInstances({ redis, db, logger }) {
51
51
  for (const inst of runningInstances) {
52
52
  const lockKey = `lock:workflow:${inst.id}`;
53
53
  if (!await redis.native.exists(lockKey)) {
54
- await db.update(workflowInstances).set({ status: "pending" }).where(eq(workflowInstances.id, inst.id));
54
+ await db.update(workflowInstances).set({ status: "pending" }).where(and(eq(workflowInstances.id, inst.id), eq(workflowInstances.status, "running")));
55
55
  logger.info({ instanceId: inst.id }, "Reaped stuck workflow instance (lock expired)");
56
56
  }
57
57
  }
@@ -69,12 +69,7 @@ const DURATION_UNIT_SECONDS = {
69
69
  h: 3600,
70
70
  d: 86400
71
71
  };
72
- /**
73
- * `"500ms"`, `"0.5s"`, `"15m"`, `"1.5h"`, `"2.5d"` to seconds. Decimals are
74
- * read exactly; anything that is not a number and a unit throws. The old
75
- * parser matched on the last character, so "500ms" meant 500 seconds, and ran
76
- * parseInt, so "1.5h" meant one hour.
77
- */
72
+ /** `"500ms"`, `"1.5h"`, `"2.5d"` to seconds. Anything else throws. */
78
73
  function parseDurationSeconds(value, what) {
79
74
  const match = /^(\d+(?:\.\d+)?|\.\d+)(ms|s|m|h|d)$/.exec(value.trim());
80
75
  if (!match) throw new Error(`Invalid ${what}: ${value}`);