notifkit 0.1.15 → 0.1.17
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/dashboard/dist/assets/index-C-DJYu0_.css +1 -0
- package/dashboard/dist/assets/index-CzFZcEon.js +318 -0
- package/dashboard/dist/index.html +2 -2
- package/dist/{bootstrap-BOmT69OH.mjs → bootstrap-P63acBG9.mjs} +1 -1
- package/dist/{bulk-ZPiOJRx-.mjs → bulk-Beblt3ny.mjs} +1 -1
- package/dist/index.d.mts +84 -27
- package/dist/index.mjs +2 -2
- package/dist/{main-CTjaZ7ZD.mjs → main-BIahf4f9.mjs} +13 -15
- package/dist/{main-CCqcFDDe.mjs → main-C3XcLoCb.mjs} +21 -41
- package/dist/{main-g33jpia4.mjs → main-CktEylpL.mjs} +676 -582
- package/dist/{main-BdZvBgV7.mjs → main-DB0bUh2r.mjs} +22 -48
- package/dist/{main-JEXBLP2A.mjs → main-Dk92nti8.mjs} +8 -6
- package/dist/{main-C0m9-Eos.mjs → main-Lcbg7aEn.mjs} +183 -334
- package/dist/{main-C6S3EsJ3.mjs → main-NHUvynW2.mjs} +77 -64
- package/dist/{main-24J4U8yP.mjs → main-_I4b1cmP.mjs} +4 -4
- package/dist/schedule-or-dispatch-C5qfxQCv.mjs +52 -0
- package/dist/{src-9LXITcNi.mjs → src-BRatuWJS.mjs} +125 -95
- package/package.json +1 -1
- package/scripts/create-project.mjs +6 -2
- package/src/client.ts +3 -3
- package/src/config/index.ts +2 -1
- package/src/contracts/common.ts +2 -0
- package/src/contracts/envelope.ts +1 -1
- package/src/contracts/events/notification-created.ts +2 -0
- package/src/contracts/events/notification-delivered.ts +1 -1
- package/src/contracts/events/notification-failed.ts +1 -1
- package/src/contracts/events/notification-requested.ts +3 -2
- package/src/contracts/helpers.ts +1 -2
- package/src/contracts/index.ts +1 -0
- package/src/contracts/registry.ts +1 -0
- package/src/contracts/sdk.ts +8 -37
- package/src/db/schema.ts +8 -13
- package/src/idempotency/index.ts +6 -8
- package/src/metrics/index.ts +2 -0
- package/src/queue/index.ts +8 -0
- package/src/rate-limiter/api-rate-limiter.ts +208 -0
- package/src/rate-limiter/index.ts +3 -411
- package/src/rate-limiter/project-settings-cache.ts +99 -0
- package/src/rate-limiter/user-throttle.ts +100 -0
- package/src/redis/index.ts +10 -3
- package/src/repositories/admin-user.ts +83 -0
- package/src/repositories/contact.ts +359 -0
- package/src/repositories/index.ts +9 -1416
- package/src/repositories/preference.ts +35 -0
- package/src/repositories/project.ts +110 -0
- package/src/repositories/segment.ts +16 -0
- package/src/repositories/template.ts +72 -0
- package/src/repositories/types.ts +49 -0
- package/src/repositories/user.ts +644 -0
- package/src/repositories/workflow.ts +64 -0
- package/src/services/ai/main.ts +29 -71
- package/src/services/api/admin-static.ts +4 -1
- package/src/services/api/handlers/auth.ts +109 -0
- package/src/services/api/handlers/campaigns.ts +191 -0
- package/src/services/api/handlers/events.ts +99 -0
- package/src/services/api/handlers/notifications.ts +356 -0
- package/src/services/api/handlers/projects.ts +116 -0
- package/src/services/api/handlers/shared.ts +262 -0
- package/src/services/api/handlers/suppressions.ts +95 -0
- package/src/services/api/handlers/system.ts +314 -0
- package/src/services/api/handlers/templates.ts +97 -0
- package/src/services/api/handlers/unsubscribe.ts +215 -0
- package/src/services/api/handlers/users.ts +262 -0
- package/src/services/api/handlers/workflows.ts +150 -0
- package/src/services/api/handlers.ts +25 -2190
- package/src/services/api/health.ts +133 -0
- package/src/services/api/http.ts +12 -0
- package/src/services/api/main.ts +32 -322
- package/src/services/api/router.ts +1 -1
- package/src/services/api/webhooks.ts +172 -0
- package/src/services/delivery/main.ts +256 -498
- package/src/services/engine/main.ts +31 -247
- package/src/services/engine/quiet-hours.ts +151 -0
- package/src/services/engine/schedule-or-dispatch.ts +104 -0
- package/src/services/enricher/main.ts +9 -21
- package/src/services/events/main.ts +2 -2
- package/src/services/scheduler/main.ts +16 -25
- package/src/services/workflow/duration.ts +24 -0
- package/src/services/workflow/main.ts +6 -164
- package/src/services/workflow/timers.ts +157 -0
- package/src/shared/events.ts +3 -2
- package/src/templates/render.ts +1 -0
- package/src/workers/index.ts +34 -5
- package/src/workflows/sdk.ts +1 -0
- package/dashboard/dist/assets/index-ggpJKZqZ.js +0 -315
- package/dashboard/dist/assets/index-s-SXGIwv.css +0 -1
|
@@ -382,7 +382,7 @@ const baseConfigSchema = z.object({
|
|
|
382
382
|
DB_SCHEMA: z.string().trim().regex(/^[a-z_][a-z0-9_]{0,62}$/, "must be a lowercase PostgreSQL identifier").default("public"),
|
|
383
383
|
LOG_FLUSH_INTERVAL_MS: z.coerce.number().int().min(50).default(500),
|
|
384
384
|
LOG_BUFFER_MAX_SIZE: z.coerce.number().int().min(100).default(5e3),
|
|
385
|
-
SEGMENT_MAX_USERS: z.coerce.number().int().min(1).default(
|
|
385
|
+
SEGMENT_MAX_USERS: z.coerce.number().int().min(1).default(1e5),
|
|
386
386
|
/**
|
|
387
387
|
* Externally reachable base URL of this API. Unsubscribe links are built from
|
|
388
388
|
* it, so it must be what an inbox can actually reach — not `HOST`/`PORT`,
|
|
@@ -448,6 +448,7 @@ const NotificationPrioritySchema = z.enum([
|
|
|
448
448
|
"high",
|
|
449
449
|
"critical"
|
|
450
450
|
]);
|
|
451
|
+
/** @deprecated Unused; removed in the next minor version. */
|
|
451
452
|
const NotificationStatusSchema = z.enum([
|
|
452
453
|
"pending",
|
|
453
454
|
"queued",
|
|
@@ -601,8 +602,8 @@ function buildStreamEvent(type, payload, source, traceId) {
|
|
|
601
602
|
//#endregion
|
|
602
603
|
//#region src/contracts/sdk.ts
|
|
603
604
|
const QuietHoursSchema = z.object({
|
|
604
|
-
start: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "expected HH:MM (24h,
|
|
605
|
-
end: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "expected HH:MM (24h,
|
|
605
|
+
start: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "expected HH:MM (24h, user's timezone)"),
|
|
606
|
+
end: z.string().regex(/^([01]\d|2[0-3]):[0-5]\d$/, "expected HH:MM (24h, user's timezone)")
|
|
606
607
|
});
|
|
607
608
|
const PreferencesSchema = z.object({
|
|
608
609
|
channels: z.record(z.string(), z.boolean()).optional(),
|
|
@@ -610,17 +611,7 @@ const PreferencesSchema = z.object({
|
|
|
610
611
|
quietHours: z.array(QuietHoursSchema).optional()
|
|
611
612
|
});
|
|
612
613
|
/** Channels that carry an addressable target (email address, phone, push token, url, chat id). */
|
|
613
|
-
const ContactChannelSchema =
|
|
614
|
-
"email",
|
|
615
|
-
"sms",
|
|
616
|
-
"push",
|
|
617
|
-
"webhook",
|
|
618
|
-
"in-app",
|
|
619
|
-
"telegram",
|
|
620
|
-
"discord",
|
|
621
|
-
"whatsapp",
|
|
622
|
-
"slack"
|
|
623
|
-
]);
|
|
614
|
+
const ContactChannelSchema = NotificationChannelSchema;
|
|
624
615
|
/** Accept a single value or an array; always normalise to a non-empty array. */
|
|
625
616
|
const stringOrArray = z.union([z.string().min(1), z.array(z.string().min(1))]).transform((v) => Array.isArray(v) ? v : [v]);
|
|
626
617
|
const UserContactInputSchema = z.object({
|
|
@@ -659,35 +650,18 @@ const UpdateUserSchema = z.object({
|
|
|
659
650
|
preferences: PreferencesSchema.optional()
|
|
660
651
|
});
|
|
661
652
|
/** addUserContact(userId, channel, { target, preferences, label, isPrimary, enabled }) */
|
|
662
|
-
const AddContactSchema =
|
|
663
|
-
channel: ContactChannelSchema,
|
|
664
|
-
target: z.string().min(1),
|
|
665
|
-
label: z.string().optional(),
|
|
666
|
-
isPrimary: z.boolean().optional(),
|
|
667
|
-
enabled: z.boolean().optional(),
|
|
668
|
-
preferences: PreferencesSchema.optional()
|
|
669
|
-
});
|
|
653
|
+
const AddContactSchema = UserContactInputSchema;
|
|
670
654
|
const BatchAddContactsSchema = z.union([AddContactSchema, z.array(AddContactSchema).min(1)]);
|
|
671
655
|
const TemplateSchema = z.object({
|
|
672
656
|
id: z.string().min(1),
|
|
673
657
|
channel: NotificationChannelSchema,
|
|
674
|
-
topic:
|
|
658
|
+
topic: stringOrArray.optional(),
|
|
675
659
|
content: z.record(z.string(), z.unknown()),
|
|
676
660
|
aiPrompts: z.record(z.string(), z.string()).optional()
|
|
677
661
|
});
|
|
678
662
|
const SyncTemplatesSchema = z.object({ templates: z.array(TemplateSchema).min(1) });
|
|
679
663
|
/** Inline user object accepted by notify({ user: {...} }). */
|
|
680
|
-
const InlineUserSchema =
|
|
681
|
-
id: z.string().min(1),
|
|
682
|
-
language: z.string().optional(),
|
|
683
|
-
timezone: z.string().optional(),
|
|
684
|
-
contacts: z.array(UserContactInputSchema).optional(),
|
|
685
|
-
email: stringOrArray.optional(),
|
|
686
|
-
phone: stringOrArray.optional(),
|
|
687
|
-
pushToken: stringOrArray.optional(),
|
|
688
|
-
segments: z.array(z.string().min(1)).optional(),
|
|
689
|
-
preferences: PreferencesSchema.optional()
|
|
690
|
-
});
|
|
664
|
+
const InlineUserSchema = AddUserSchema;
|
|
691
665
|
/**
|
|
692
666
|
* notify(...) request body.
|
|
693
667
|
*
|
|
@@ -801,10 +775,11 @@ const UpdateProjectSchema = z.object({
|
|
|
801
775
|
/**
|
|
802
776
|
* A high-level notification request as issued by the SDK's `notify()` call.
|
|
803
777
|
*
|
|
804
|
-
* Unlike `notification.
|
|
778
|
+
* Unlike `notification.enriched` (which targets a single resolved address),
|
|
805
779
|
* this event carries the *unresolved* target — a user id, a segment, or a
|
|
806
780
|
* topic. A downstream resolver stage fans it out into one
|
|
807
|
-
* `notification.
|
|
781
|
+
* `notification.enriched` per matching address and channel, applying
|
|
782
|
+
* preference filters.
|
|
808
783
|
*/
|
|
809
784
|
const NotificationTargetSchema = z.discriminatedUnion("type", [
|
|
810
785
|
z.object({
|
|
@@ -841,6 +816,7 @@ const NotificationRequestedPayloadSchema = z.object({
|
|
|
841
816
|
});
|
|
842
817
|
//#endregion
|
|
843
818
|
//#region src/contracts/events/notification-created.ts
|
|
819
|
+
/** @deprecated Nothing publishes `notification.created`; removed in the next minor version. */
|
|
844
820
|
const NotificationCreatedPayloadSchema = z.object({
|
|
845
821
|
projectId: z.string().uuid(),
|
|
846
822
|
recipientId: z.string().min(1),
|
|
@@ -970,7 +946,7 @@ const NotificationDeliveredPayloadSchema = z.object({
|
|
|
970
946
|
deliveredAt: z.string().datetime(),
|
|
971
947
|
providerMessageId: z.string().optional(),
|
|
972
948
|
providerResponse: z.record(z.string(), z.unknown()).optional(),
|
|
973
|
-
templateId: z.string().
|
|
949
|
+
templateId: z.string().min(1).optional(),
|
|
974
950
|
workflowInstanceId: z.string().uuid().optional(),
|
|
975
951
|
/** Campaign this message belongs to, carried from the originating request. */
|
|
976
952
|
campaignId: z.string().min(1).max(128).optional(),
|
|
@@ -994,7 +970,7 @@ const NotificationFailedPayloadSchema = z.object({
|
|
|
994
970
|
retryable: z.boolean(),
|
|
995
971
|
attempt: z.number().int().positive(),
|
|
996
972
|
providerResponse: z.record(z.string(), z.unknown()).optional(),
|
|
997
|
-
templateId: z.string().
|
|
973
|
+
templateId: z.string().min(1).optional(),
|
|
998
974
|
workflowInstanceId: z.string().uuid().optional(),
|
|
999
975
|
/** Campaign this message belongs to, carried from the originating request. */
|
|
1000
976
|
campaignId: z.string().min(1).max(128).optional(),
|
|
@@ -1080,17 +1056,7 @@ var schema_exports = /* @__PURE__ */ __exportAll({
|
|
|
1080
1056
|
workflowSteps: () => workflowSteps,
|
|
1081
1057
|
workflowWaiters: () => workflowWaiters
|
|
1082
1058
|
});
|
|
1083
|
-
const channelEnum = pgEnum("channel",
|
|
1084
|
-
"email",
|
|
1085
|
-
"sms",
|
|
1086
|
-
"push",
|
|
1087
|
-
"webhook",
|
|
1088
|
-
"in-app",
|
|
1089
|
-
"telegram",
|
|
1090
|
-
"discord",
|
|
1091
|
-
"whatsapp",
|
|
1092
|
-
"slack"
|
|
1093
|
-
]);
|
|
1059
|
+
const channelEnum = pgEnum("channel", NotificationChannelSchema.options);
|
|
1094
1060
|
const projects = pgTable("projects", {
|
|
1095
1061
|
id: uuid("id").primaryKey().defaultRandom(),
|
|
1096
1062
|
name: varchar("name").notNull(),
|
|
@@ -1456,10 +1422,8 @@ async function migrateDatabase({ url, schema: dbSchema }) {
|
|
|
1456
1422
|
//#endregion
|
|
1457
1423
|
//#region src/idempotency/index.ts
|
|
1458
1424
|
/**
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1461
|
-
* - Phase 1 (:lock): Short lease acquired at the start of message processing.
|
|
1462
|
-
* - Phase 2 (:sent): Long-lived completion marker recorded when processing succeeds.
|
|
1425
|
+
* SET NX-based idempotency guard.
|
|
1426
|
+
* One key per id: `L` while leased, `1` once processed.
|
|
1463
1427
|
*/
|
|
1464
1428
|
var IdempotencyGuard = class {
|
|
1465
1429
|
redis;
|
|
@@ -1473,17 +1437,17 @@ var IdempotencyGuard = class {
|
|
|
1473
1437
|
key(id) {
|
|
1474
1438
|
return `${this.keyPrefix}:${id}`;
|
|
1475
1439
|
}
|
|
1440
|
+
/** @deprecated Nothing writes `:lock` keys any more; read only for markers from older versions. Remove in the next minor. */
|
|
1476
1441
|
lockKey(id) {
|
|
1477
1442
|
return `${this.keyPrefix}:${id}:lock`;
|
|
1478
1443
|
}
|
|
1444
|
+
/** @deprecated Nothing writes `:sent` keys any more; read only for markers from older versions. Remove in the next minor. */
|
|
1479
1445
|
completedKey(id) {
|
|
1480
1446
|
return `${this.keyPrefix}:${id}:sent`;
|
|
1481
1447
|
}
|
|
1482
1448
|
/**
|
|
1483
|
-
*
|
|
1484
|
-
*
|
|
1485
|
-
* - Happy path (new message): single native SET NX command storing "L" (lock lease).
|
|
1486
|
-
* - If already present: checks if "S" (sent/completed) or "L" (locked by another worker).
|
|
1449
|
+
* Leases the id with SET NX. One key per id: `L` while leased, `1` once processed.
|
|
1450
|
+
* Returns "completed" if already processed, "locked" if another worker holds the lease.
|
|
1487
1451
|
*/
|
|
1488
1452
|
async acquireLease(id, lockTtlSeconds = 30) {
|
|
1489
1453
|
const mainKey = this.key(id);
|
|
@@ -1584,6 +1548,7 @@ const metrics = {
|
|
|
1584
1548
|
labelNames: ["channel", "reason"],
|
|
1585
1549
|
registers: [register]
|
|
1586
1550
|
}),
|
|
1551
|
+
/** @deprecated Never set, so it always reads 0. Removed in the next minor version. */
|
|
1587
1552
|
workerActiveTasks: new promClient.Gauge({
|
|
1588
1553
|
name: "notifkit_worker_active_tasks",
|
|
1589
1554
|
help: "Number of currently active tasks per worker",
|
|
@@ -1596,6 +1561,7 @@ const metrics = {
|
|
|
1596
1561
|
labelNames: ["stream"],
|
|
1597
1562
|
registers: [register]
|
|
1598
1563
|
}),
|
|
1564
|
+
/** @deprecated Never set, so it always reads 0. Removed in the next minor version. */
|
|
1599
1565
|
pendingAcks: new promClient.Gauge({
|
|
1600
1566
|
name: "notifkit_pending_acks",
|
|
1601
1567
|
help: "Number of pending un-acked messages per group",
|
|
@@ -1978,6 +1944,13 @@ var PendingMessageScanner = class {
|
|
|
1978
1944
|
this.consumer = consumer;
|
|
1979
1945
|
this.logger = logger;
|
|
1980
1946
|
}
|
|
1947
|
+
/**
|
|
1948
|
+
* Resets a held entry's idle time so no scanner reclaims it while its
|
|
1949
|
+
* handler is still running. JUSTID leaves the delivery count alone.
|
|
1950
|
+
*/
|
|
1951
|
+
async touch(id, stream) {
|
|
1952
|
+
await this.redis.xclaim(stream, this.group, this.consumer, 0, id, "JUSTID");
|
|
1953
|
+
}
|
|
1981
1954
|
async getPendingCount() {
|
|
1982
1955
|
let total = 0;
|
|
1983
1956
|
for (const s of this.streams) {
|
|
@@ -2036,7 +2009,7 @@ var PendingMessageScanner = class {
|
|
|
2036
2009
|
}
|
|
2037
2010
|
};
|
|
2038
2011
|
//#endregion
|
|
2039
|
-
//#region src/rate-limiter/
|
|
2012
|
+
//#region src/rate-limiter/project-settings-cache.ts
|
|
2040
2013
|
const NO_OVERRIDES = {
|
|
2041
2014
|
throttleLimit: null,
|
|
2042
2015
|
throttleWindowHours: null
|
|
@@ -2096,6 +2069,8 @@ var ProjectSettingsCache = class {
|
|
|
2096
2069
|
this.inFlight.clear();
|
|
2097
2070
|
}
|
|
2098
2071
|
};
|
|
2072
|
+
//#endregion
|
|
2073
|
+
//#region src/rate-limiter/user-throttle.ts
|
|
2099
2074
|
/** Reject stored values that would make the window meaningless. */
|
|
2100
2075
|
function positiveOrNull(value) {
|
|
2101
2076
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
|
|
@@ -2143,6 +2118,8 @@ var UserThrottle = class {
|
|
|
2143
2118
|
};
|
|
2144
2119
|
}
|
|
2145
2120
|
};
|
|
2121
|
+
//#endregion
|
|
2122
|
+
//#region src/rate-limiter/api-rate-limiter.ts
|
|
2146
2123
|
/**
|
|
2147
2124
|
* Computes dynamic token lease batch size based on RPM.
|
|
2148
2125
|
* Targets ~5s of limit capacity so Redis is contacted at most ~12 times/min
|
|
@@ -2381,7 +2358,10 @@ const LUA_COUNT_REQUEST = `
|
|
|
2381
2358
|
end
|
|
2382
2359
|
return count
|
|
2383
2360
|
`;
|
|
2384
|
-
/**
|
|
2361
|
+
/**
|
|
2362
|
+
* Two-phase idempotency lease acquisition. Checks sent/legacy, then attempts SET NX lock.
|
|
2363
|
+
* @deprecated Nothing calls the `acquireLease` command; removed in the next minor version.
|
|
2364
|
+
*/
|
|
2385
2365
|
const LUA_ACQUIRE_LEASE = `
|
|
2386
2366
|
if redis.call('EXISTS', KEYS[1]) == 1 or redis.call('EXISTS', KEYS[3]) == 1 then
|
|
2387
2367
|
return 'completed'
|
|
@@ -2395,7 +2375,10 @@ const LUA_ACQUIRE_LEASE = `
|
|
|
2395
2375
|
end
|
|
2396
2376
|
return 'locked'
|
|
2397
2377
|
`;
|
|
2398
|
-
/**
|
|
2378
|
+
/**
|
|
2379
|
+
* Two-phase idempotency completion marker. Atomically sets completed + legacy and deletes lock.
|
|
2380
|
+
* @deprecated Nothing calls the `markProcessed` command; removed in the next minor version.
|
|
2381
|
+
*/
|
|
2399
2382
|
const LUA_MARK_PROCESSED = `
|
|
2400
2383
|
redis.call('SET', KEYS[1], '1', 'EX', ARGV[1])
|
|
2401
2384
|
redis.call('SET', KEYS[2], '1', 'EX', ARGV[1])
|
|
@@ -2544,7 +2527,7 @@ function redactUrl(url) {
|
|
|
2544
2527
|
}
|
|
2545
2528
|
}
|
|
2546
2529
|
//#endregion
|
|
2547
|
-
//#region src/repositories/
|
|
2530
|
+
//#region src/repositories/user.ts
|
|
2548
2531
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
2549
2532
|
/**
|
|
2550
2533
|
* Applied when a profile is read, not when it is written: an upsert that
|
|
@@ -2552,12 +2535,16 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
|
|
2552
2535
|
*/
|
|
2553
2536
|
const DEFAULT_LANGUAGE = "en";
|
|
2554
2537
|
const DEFAULT_TIMEZONE = "UTC";
|
|
2555
|
-
var UserRepository = class {
|
|
2538
|
+
var UserRepository = class UserRepository {
|
|
2556
2539
|
db;
|
|
2557
2540
|
recordCache = new LRUCache(5e3, 3e4);
|
|
2558
2541
|
constructor(db) {
|
|
2559
2542
|
this.db = db;
|
|
2560
2543
|
}
|
|
2544
|
+
/** A repository that runs its queries inside `tx`. */
|
|
2545
|
+
withTx(tx) {
|
|
2546
|
+
return new UserRepository(tx);
|
|
2547
|
+
}
|
|
2561
2548
|
async findById(projectId, userId) {
|
|
2562
2549
|
const rows = await this.db.select().from(users).where(and(eq(users.externalId, userId), eq(users.projectId, projectId))).limit(1);
|
|
2563
2550
|
if (!rows[0]) return null;
|
|
@@ -2882,6 +2869,9 @@ var UserRepository = class {
|
|
|
2882
2869
|
return (await this.db.select({ externalId: users.externalId }).from(users).innerJoin(userTopicPreferences, eq(users.id, userTopicPreferences.userId)).where(and(eq(userTopicPreferences.topic, topicName), eq(userTopicPreferences.enabled, true), eq(users.projectId, projectId)))).map((r) => r.externalId);
|
|
2883
2870
|
}
|
|
2884
2871
|
};
|
|
2872
|
+
//#endregion
|
|
2873
|
+
//#region src/repositories/preference.ts
|
|
2874
|
+
/** @deprecated Unused; removed in the next minor version. */
|
|
2885
2875
|
var PreferenceRepository = class {
|
|
2886
2876
|
db;
|
|
2887
2877
|
constructor(db) {
|
|
@@ -2901,12 +2891,18 @@ var PreferenceRepository = class {
|
|
|
2901
2891
|
}));
|
|
2902
2892
|
}
|
|
2903
2893
|
};
|
|
2904
|
-
|
|
2894
|
+
//#endregion
|
|
2895
|
+
//#region src/repositories/contact.ts
|
|
2896
|
+
var ContactRepository = class ContactRepository {
|
|
2905
2897
|
db;
|
|
2906
2898
|
activeContactsCache = new LRUCache(5e3, 3e4);
|
|
2907
2899
|
constructor(db) {
|
|
2908
2900
|
this.db = db;
|
|
2909
2901
|
}
|
|
2902
|
+
/** A repository that runs its queries inside `tx`. */
|
|
2903
|
+
withTx(tx) {
|
|
2904
|
+
return new ContactRepository(tx);
|
|
2905
|
+
}
|
|
2910
2906
|
async findByUserId(projectId, userId) {
|
|
2911
2907
|
const internalId = (await this.db.select({ id: users.id }).from(users).where(and(eq(users.externalId, userId), eq(users.projectId, projectId))))[0]?.id;
|
|
2912
2908
|
if (!internalId) return [];
|
|
@@ -3086,6 +3082,8 @@ var ContactRepository = class {
|
|
|
3086
3082
|
return (await this.db.delete(userContacts).where(and(eq(userContacts.userId, internalId), eq(userContacts.channel, channel), eq(userContacts.target, target))).returning()).length > 0;
|
|
3087
3083
|
}
|
|
3088
3084
|
};
|
|
3085
|
+
//#endregion
|
|
3086
|
+
//#region src/repositories/template.ts
|
|
3089
3087
|
var TemplateRepository = class {
|
|
3090
3088
|
db;
|
|
3091
3089
|
constructor(db) {
|
|
@@ -3137,6 +3135,8 @@ var TemplateRepository = class {
|
|
|
3137
3135
|
return (await this.db.delete(templates).where(and(eq(templates.id, id), eq(templates.projectId, projectId))).returning()).length > 0;
|
|
3138
3136
|
}
|
|
3139
3137
|
};
|
|
3138
|
+
//#endregion
|
|
3139
|
+
//#region src/repositories/project.ts
|
|
3140
3140
|
var ProjectRepository = class {
|
|
3141
3141
|
db;
|
|
3142
3142
|
constructor(db) {
|
|
@@ -3154,15 +3154,7 @@ var ProjectRepository = class {
|
|
|
3154
3154
|
}
|
|
3155
3155
|
async delete(id) {
|
|
3156
3156
|
return await this.db.transaction(async (tx) => {
|
|
3157
|
-
|
|
3158
|
-
if (userIds.length > 0) {
|
|
3159
|
-
await tx.delete(userContacts).where(inArray(userContacts.userId, userIds));
|
|
3160
|
-
await tx.delete(userSegments).where(inArray(userSegments.userId, userIds));
|
|
3161
|
-
await tx.delete(userTopicPreferences).where(inArray(userTopicPreferences.userId, userIds));
|
|
3162
|
-
await tx.delete(userChannelPreferences).where(inArray(userChannelPreferences.userId, userIds));
|
|
3163
|
-
await tx.delete(quietHours).where(inArray(quietHours.userId, userIds));
|
|
3164
|
-
await tx.delete(users).where(eq(users.projectId, id));
|
|
3165
|
-
}
|
|
3157
|
+
await tx.delete(users).where(eq(users.projectId, id));
|
|
3166
3158
|
await tx.delete(suppressions).where(eq(suppressions.projectId, id));
|
|
3167
3159
|
await tx.delete(messageLogs).where(eq(messageLogs.projectId, id));
|
|
3168
3160
|
await tx.delete(workflowInstances).where(eq(workflowInstances.projectId, id));
|
|
@@ -3201,6 +3193,8 @@ var ProjectRepository = class {
|
|
|
3201
3193
|
return (await this.db.delete(projectApiKeys).where(and(eq(projectApiKeys.id, keyId), eq(projectApiKeys.projectId, projectId))).returning()).length > 0;
|
|
3202
3194
|
}
|
|
3203
3195
|
};
|
|
3196
|
+
//#endregion
|
|
3197
|
+
//#region src/repositories/workflow.ts
|
|
3204
3198
|
var WorkflowRepository = class {
|
|
3205
3199
|
db;
|
|
3206
3200
|
constructor(db) {
|
|
@@ -3228,6 +3222,8 @@ var WorkflowRepository = class {
|
|
|
3228
3222
|
});
|
|
3229
3223
|
}
|
|
3230
3224
|
};
|
|
3225
|
+
//#endregion
|
|
3226
|
+
//#region src/repositories/segment.ts
|
|
3231
3227
|
var SegmentRepository = class {
|
|
3232
3228
|
db;
|
|
3233
3229
|
constructor(db) {
|
|
@@ -3242,6 +3238,8 @@ var SegmentRepository = class {
|
|
|
3242
3238
|
`)).map((r) => r.segment);
|
|
3243
3239
|
}
|
|
3244
3240
|
};
|
|
3241
|
+
//#endregion
|
|
3242
|
+
//#region src/repositories/admin-user.ts
|
|
3245
3243
|
var AdminUserRepository = class {
|
|
3246
3244
|
db;
|
|
3247
3245
|
constructor(db) {
|
|
@@ -3262,12 +3260,14 @@ var AdminUserRepository = class {
|
|
|
3262
3260
|
role: data.role || "admin"
|
|
3263
3261
|
}).returning())[0];
|
|
3264
3262
|
}
|
|
3263
|
+
/** @deprecated Unused; removed in the next minor version. */
|
|
3265
3264
|
async updatePassword(id, passwordHash) {
|
|
3266
3265
|
return (await this.db.update(adminUsers).set({
|
|
3267
3266
|
passwordHash,
|
|
3268
3267
|
updatedAt: /* @__PURE__ */ new Date()
|
|
3269
3268
|
}).where(eq(adminUsers.id, id)).returning()).length > 0;
|
|
3270
3269
|
}
|
|
3270
|
+
/** @deprecated Unused; removed in the next minor version. */
|
|
3271
3271
|
async list() {
|
|
3272
3272
|
return await this.db.select({
|
|
3273
3273
|
id: adminUsers.id,
|
|
@@ -3291,6 +3291,7 @@ function escapeHtml(unsafe) {
|
|
|
3291
3291
|
function escapeHeader(unsafe) {
|
|
3292
3292
|
return String(unsafe).replace(/[\r\n]+/g, " ").trim();
|
|
3293
3293
|
}
|
|
3294
|
+
/** @deprecated Unused; templates render through renderWithTemplate. Removed in the next minor version. */
|
|
3294
3295
|
function interpolate(tmpl, variables, sanitize = true) {
|
|
3295
3296
|
return tmpl.replace(/\{\{\{(\w+)\}\}\}/g, (_, k) => {
|
|
3296
3297
|
return String(variables[k] ?? "");
|
|
@@ -3584,7 +3585,12 @@ var BaseWorker = class {
|
|
|
3584
3585
|
this.state = "stopping";
|
|
3585
3586
|
await this.consumer.stop();
|
|
3586
3587
|
this.stopRecoveryLoop();
|
|
3587
|
-
if (this.runLoop)
|
|
3588
|
+
if (this.runLoop) {
|
|
3589
|
+
let timer;
|
|
3590
|
+
await Promise.race([this.runLoop, new Promise((_, reject) => {
|
|
3591
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("Worker stop timeout")), 3e4);
|
|
3592
|
+
})]).catch((err) => this.logger.warn({ err }, "Worker shutdown timeout or error")).finally(() => clearTimeout(timer));
|
|
3593
|
+
}
|
|
3588
3594
|
this.logger.info("worker shutdown complete");
|
|
3589
3595
|
}
|
|
3590
3596
|
async recover() {
|
|
@@ -3677,7 +3683,7 @@ var BaseWorker = class {
|
|
|
3677
3683
|
globalEmitter.emit("notification:failed", message.event.id, "Poison pill: max retries exceeded", message.event.type);
|
|
3678
3684
|
return;
|
|
3679
3685
|
}
|
|
3680
|
-
const result = await this.
|
|
3686
|
+
const result = await this.processHoldingLease(message, retryCount);
|
|
3681
3687
|
if (result && result.ack === false) {
|
|
3682
3688
|
this.logger.debug({
|
|
3683
3689
|
messageId: message.id,
|
|
@@ -3729,6 +3735,29 @@ var BaseWorker = class {
|
|
|
3729
3735
|
}
|
|
3730
3736
|
}
|
|
3731
3737
|
/**
|
|
3738
|
+
* Runs `process` while keeping the entry's idle time below the reclaim
|
|
3739
|
+
* threshold. Without this, a handler that outlasts `recoveryIntervalMs` (a
|
|
3740
|
+
* large segment fan-out) is reclaimed mid-run and started again elsewhere,
|
|
3741
|
+
* over and over, until it is dead-lettered while the first run still works.
|
|
3742
|
+
* If this process dies the touches stop, so the entry is reclaimed as before.
|
|
3743
|
+
*/
|
|
3744
|
+
async processHoldingLease(message, attempt) {
|
|
3745
|
+
const stream = message.stream;
|
|
3746
|
+
const timer = stream ? setInterval(() => {
|
|
3747
|
+
this.pendingScanner.touch(message.id, stream).catch((err) => {
|
|
3748
|
+
this.logger.warn({
|
|
3749
|
+
err,
|
|
3750
|
+
messageId: message.id
|
|
3751
|
+
}, "failed to extend message lease");
|
|
3752
|
+
});
|
|
3753
|
+
}, Math.max(Math.floor(this.recoveryIntervalMs / 2), 10)) : void 0;
|
|
3754
|
+
try {
|
|
3755
|
+
return await this.process(message, attempt);
|
|
3756
|
+
} finally {
|
|
3757
|
+
clearInterval(timer);
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
/**
|
|
3732
3761
|
* `recoveryIntervalMs` is how long an entry must sit idle before it is
|
|
3733
3762
|
* claimed, not how often to look. Scanning only once per interval, timed from
|
|
3734
3763
|
* this worker's start, meant a worker restarted more often than that (a crash
|
|
@@ -3817,6 +3846,7 @@ function buildStepNotifyPayload(args, instanceInput, projectId, idempotencyKey,
|
|
|
3817
3846
|
fallback: args.fallback ?? false,
|
|
3818
3847
|
scheduledAt: args.sendAt,
|
|
3819
3848
|
idempotencyKey,
|
|
3849
|
+
campaignId: args.campaign,
|
|
3820
3850
|
...workflowInstanceId ? { workflowInstanceId } : {}
|
|
3821
3851
|
};
|
|
3822
3852
|
}
|
|
@@ -3886,7 +3916,7 @@ var NotifkitClient = class {
|
|
|
3886
3916
|
return this.request("/v1/users", "POST", idOrInput);
|
|
3887
3917
|
}
|
|
3888
3918
|
async identify(idOrInput, contacts, options) {
|
|
3889
|
-
return this.addUser(idOrInput, contacts, options);
|
|
3919
|
+
return typeof idOrInput === "string" ? this.addUser(idOrInput, contacts, options) : this.addUser(idOrInput);
|
|
3890
3920
|
}
|
|
3891
3921
|
/** Update user profile. */
|
|
3892
3922
|
async updateUser(id, input) {
|
|
@@ -4194,35 +4224,35 @@ var NotifkitServer = class extends EventEmitter {
|
|
|
4194
4224
|
}
|
|
4195
4225
|
const startupPromises = [];
|
|
4196
4226
|
if (services.includes("api")) {
|
|
4197
|
-
const { startApiServer } = await import("./main-
|
|
4227
|
+
const { startApiServer } = await import("./main-CktEylpL.mjs");
|
|
4198
4228
|
startupPromises.push(startApiServer());
|
|
4199
4229
|
}
|
|
4200
4230
|
if (services.includes("delivery")) {
|
|
4201
|
-
const { startDeliveryWorker } = await import("./main-
|
|
4231
|
+
const { startDeliveryWorker } = await import("./main-Lcbg7aEn.mjs");
|
|
4202
4232
|
startupPromises.push(startDeliveryWorker());
|
|
4203
4233
|
}
|
|
4204
4234
|
if (services.includes("engine")) {
|
|
4205
|
-
const { startEngineWorker } = await import("./main-
|
|
4235
|
+
const { startEngineWorker } = await import("./main-DB0bUh2r.mjs");
|
|
4206
4236
|
startupPromises.push(startEngineWorker());
|
|
4207
4237
|
}
|
|
4208
4238
|
if (services.includes("enricher")) {
|
|
4209
|
-
const { startEnricherWorker } = await import("./main-
|
|
4239
|
+
const { startEnricherWorker } = await import("./main-Dk92nti8.mjs");
|
|
4210
4240
|
startupPromises.push(startEnricherWorker());
|
|
4211
4241
|
}
|
|
4212
4242
|
if (services.includes("scheduler")) {
|
|
4213
|
-
const { startSchedulerWorker } = await import("./main-
|
|
4243
|
+
const { startSchedulerWorker } = await import("./main-BIahf4f9.mjs");
|
|
4214
4244
|
startupPromises.push(startSchedulerWorker());
|
|
4215
4245
|
}
|
|
4216
4246
|
if (services.includes("ai")) {
|
|
4217
|
-
const { startAiWorker } = await import("./main-
|
|
4247
|
+
const { startAiWorker } = await import("./main-C3XcLoCb.mjs");
|
|
4218
4248
|
startupPromises.push(startAiWorker());
|
|
4219
4249
|
}
|
|
4220
4250
|
if (services.includes("workflow")) {
|
|
4221
|
-
const { startWorkflowWorker } = await import("./main-
|
|
4251
|
+
const { startWorkflowWorker } = await import("./main-NHUvynW2.mjs");
|
|
4222
4252
|
startupPromises.push(startWorkflowWorker());
|
|
4223
4253
|
}
|
|
4224
4254
|
if (services.includes("events")) {
|
|
4225
|
-
const { startEventWorker } = await import("./main-
|
|
4255
|
+
const { startEventWorker } = await import("./main-_I4b1cmP.mjs");
|
|
4226
4256
|
startupPromises.push(startEventWorker());
|
|
4227
4257
|
}
|
|
4228
4258
|
const handleSignal = async (signal) => {
|
|
@@ -4244,9 +4274,9 @@ var NotifkitServer = class extends EventEmitter {
|
|
|
4244
4274
|
await Promise.all(startupPromises);
|
|
4245
4275
|
if (readBaseConfig().PIPELINE_FUSED && services.includes("enricher") && services.includes("engine") && services.includes("delivery")) {
|
|
4246
4276
|
const [{ getEnricherWorker }, { getEngineWorker }, { getDeliveryWorker }] = await Promise.all([
|
|
4247
|
-
import("./main-
|
|
4248
|
-
import("./main-
|
|
4249
|
-
import("./main-
|
|
4277
|
+
import("./main-Dk92nti8.mjs"),
|
|
4278
|
+
import("./main-DB0bUh2r.mjs"),
|
|
4279
|
+
import("./main-Lcbg7aEn.mjs")
|
|
4250
4280
|
]);
|
|
4251
4281
|
const enricher = getEnricherWorker();
|
|
4252
4282
|
const engine = getEngineWorker();
|
|
@@ -4277,14 +4307,14 @@ var NotifkitServer = class extends EventEmitter {
|
|
|
4277
4307
|
"events"
|
|
4278
4308
|
] : this.options.services;
|
|
4279
4309
|
const shutdownOrder = [
|
|
4280
|
-
["api", async () => (await import("./main-
|
|
4281
|
-
["workflow", async () => (await import("./main-
|
|
4282
|
-
["enricher", async () => (await import("./main-
|
|
4283
|
-
["ai", async () => (await import("./main-
|
|
4284
|
-
["engine", async () => (await import("./main-
|
|
4285
|
-
["scheduler", async () => (await import("./main-
|
|
4286
|
-
["delivery", async () => (await import("./main-
|
|
4287
|
-
["events", async () => (await import("./main-
|
|
4310
|
+
["api", async () => (await import("./main-CktEylpL.mjs")).stopApiServer()],
|
|
4311
|
+
["workflow", async () => (await import("./main-NHUvynW2.mjs")).stopWorkflowWorker()],
|
|
4312
|
+
["enricher", async () => (await import("./main-Dk92nti8.mjs")).stopEnricherWorker()],
|
|
4313
|
+
["ai", async () => (await import("./main-C3XcLoCb.mjs")).stopAiWorker()],
|
|
4314
|
+
["engine", async () => (await import("./main-DB0bUh2r.mjs")).stopEngineWorker()],
|
|
4315
|
+
["scheduler", async () => (await import("./main-BIahf4f9.mjs")).stopSchedulerWorker()],
|
|
4316
|
+
["delivery", async () => (await import("./main-Lcbg7aEn.mjs")).stopDeliveryWorker()],
|
|
4317
|
+
["events", async () => (await import("./main-_I4b1cmP.mjs")).stopEventWorker()]
|
|
4288
4318
|
];
|
|
4289
4319
|
for (const [name, stop] of shutdownOrder) if (services.includes(name)) await stop();
|
|
4290
4320
|
if (this.pgContainer) {
|
|
@@ -4298,4 +4328,4 @@ var NotifkitServer = class extends EventEmitter {
|
|
|
4298
4328
|
}
|
|
4299
4329
|
};
|
|
4300
4330
|
//#endregion
|
|
4301
|
-
export {
|
|
4331
|
+
export { assertTablesInSchema as $, OUTBOUND_STREAMS as $t, LUA_ACQUIRE_LEASE as A, globalEmitter as An, NotificationTargetSchema as At, redactUrl as B, QuietHoursSchema as Bt, SegmentRepository as C, DataLoader as Cn, NotificationDispatchedPayloadSchema as Ct, ContactRepository as D, getPriorityBucket as Dn, RecipientProfileSchema as Dt, TemplateRepository as E, AsyncSemaphore as En, NotificationEnrichedPayloadSchema as Et, LUA_RENEW_LOCK as F, CreateWorkflowSchema as Ft, ProjectSettingsCache as G, UpdateUserSchema as Gt, ApiRateLimiter as H, TemplateSchema as Ht, LUA_SCHEDULER_POLL as I, IngestEventSchema as It, StreamProducer as J, WorkflowStepSchema as Jt, PendingMessageScanner as K, UserContactInputSchema as Kt, LUA_USER_THROTTLE as L, InlineUserSchema as Lt, LUA_LEASE_API_RATE_LIMIT as M, AddUserSchema as Mt, LUA_MARK_PROCESSED as N, BatchAddContactsSchema as Nt, PreferenceRepository as O, normaliseTarget as On, NotificationCreatedPayloadSchema as Ot, LUA_RELEASE_LOCK as P, ContactChannelSchema as Pt, IdempotencyGuard as Q, INBOUND_STREAMS as Qt, Redis as R, NotifyRequestSchema as Rt, AdminUserRepository as S, sleep as Sn, DeliveryOptionsSchema as St, ProjectRepository as T, BatchProcessor as Tn, NotificationScheduledPayloadSchema as Tt, calculateTokenBatchSize as U, TriggerWorkflowSchema as Ut, registerCustomCommands as V, SyncTemplatesSchema as Vt, UserThrottle as W, UpdateProjectSchema as Wt, metrics as X, CONSUMER_GROUPS as Xt, getMetricsRegistry as Y, buildStreamEvent as Yt, createLogger as Z, ENRICHED_STREAMS as Zt, TemplateCache as _, setAiConfig as _n, NotificationAiPendingPayloadSchema as _t, SuspendExecutionError as a, EventRegistry as an, deliveryOutbox as at, interpolate as b, ValidationError as bn, NotificationFailedPayloadSchema as bt, BaseWorker as c, NotificationChannelSchema as cn, projects as ct, startHealthReporter as d, AI_DEFAULTS as dn, userTopicPreferences as dt, PUBSUB_CHANNELS as en, createDatabase as et, buildUnsubscribeHeaders as f, baseConfigSchema as fn, users as ft, transportRegistry as g, readBaseConfig as gn, workflowWaiters as gt, registerTransport as h, parseConfig as hn, workflowSteps as ht, workflowRegistry as i, StreamEventSchema as in, runMigrations as it, LUA_COUNT_REQUEST as j, AddContactSchema as jt, UserRepository as k, LRUCache as kn, NotificationRequestedPayloadSchema as kt, LockHeldError as l, NotificationPrioritySchema as ln, scheduledPayloads as lt, verifyUnsubscribeToken as m, loadEnv as mn, workflowInstances as mt, NotifkitClient as n, EventEnvelopeSchema as nn, notifkitTableNames as nt, buildStepNotifyPayload as o, registry as on, messageLogs as ot, signUnsubscribeToken as p, getAiConfig as pn, workflowDefinitions as pt, StreamConsumer as q, WorkflowNotifyPayloadSchema as qt, workflow as r, StreamEventMetadataSchema as rn, qualifyMigrationSql as rt, resolveStepTarget as s, EventMetadataSchema as sn, projectApiKeys as st, NotifkitServer as t, STREAMS as tn, migrateDatabase as tt, NonRetryableError as u, NotificationStatusSchema as un, suppressions as ut, escapeHeader as v, setGlobalConfig as vn, NotificationCanceledPayloadSchema as vt, WorkflowRepository as w, CircuitBreaker as wn, RenderedContentSchema as wt, renderWithTemplate as x, generateId as xn, NotificationDeliveredPayloadSchema as xt, escapeHtml as y, AppError as yn, NotificationSkippedPayloadSchema as yt, RedisClient as z, PreferencesSchema as zt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notifkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Self-hosted notification infrastructure. One call delivers to email, SMS, push, and webhook — routed by preference, quiet hours, and consent.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "devkitshq",
|
|
@@ -41,11 +41,15 @@ try {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
if (res.status === 401) {
|
|
44
|
-
fail(
|
|
44
|
+
fail(
|
|
45
|
+
"admin credential rejected. It must match the server's ADMIN_API_KEY exactly, " +
|
|
46
|
+
"and the server must have been started with ADMIN_API_KEY set.",
|
|
47
|
+
);
|
|
45
48
|
}
|
|
46
49
|
|
|
50
|
+
// The server answers 403 only to a dashboard session whose user is read-only.
|
|
47
51
|
if (res.status === 403) {
|
|
48
|
-
fail("
|
|
52
|
+
fail("that credential is a read-only dashboard session. Use the server's ADMIN_API_KEY.");
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
if (!res.ok) {
|
package/src/client.ts
CHANGED
|
@@ -123,7 +123,9 @@ export class NotifkitClient {
|
|
|
123
123
|
contacts?: UserContactInput[],
|
|
124
124
|
options?: Omit<AddUserInput, "id" | "contacts">,
|
|
125
125
|
): Promise<{ id: string }> {
|
|
126
|
-
return
|
|
126
|
+
return typeof idOrInput === "string"
|
|
127
|
+
? this.addUser(idOrInput, contacts, options)
|
|
128
|
+
: this.addUser(idOrInput);
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
/** Update user profile. */
|
|
@@ -192,8 +194,6 @@ export class NotifkitClient {
|
|
|
192
194
|
return this.syncTemplates({ templates: this.options.templates });
|
|
193
195
|
}
|
|
194
196
|
|
|
195
|
-
// ─── Missing Endpoints additions ─────────────────────────────────────────────
|
|
196
|
-
|
|
197
197
|
/** List registered workflow definitions. */
|
|
198
198
|
async listWorkflows(options?: {
|
|
199
199
|
limit?: number;
|
package/src/config/index.ts
CHANGED
|
@@ -82,7 +82,7 @@ export const baseConfigSchema = z.object({
|
|
|
82
82
|
.default("public"),
|
|
83
83
|
LOG_FLUSH_INTERVAL_MS: z.coerce.number().int().min(50).default(500),
|
|
84
84
|
LOG_BUFFER_MAX_SIZE: z.coerce.number().int().min(100).default(5000),
|
|
85
|
-
SEGMENT_MAX_USERS: z.coerce.number().int().min(1).default(
|
|
85
|
+
SEGMENT_MAX_USERS: z.coerce.number().int().min(1).default(100_000),
|
|
86
86
|
/**
|
|
87
87
|
* Externally reachable base URL of this API. Unsubscribe links are built from
|
|
88
88
|
* it, so it must be what an inbox can actually reach — not `HOST`/`PORT`,
|
|
@@ -128,6 +128,7 @@ export function readBaseConfig(data: NodeJS.ProcessEnv = process.env): BaseConfi
|
|
|
128
128
|
return parseConfig(baseConfigSchema, data);
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/** @deprecated Unused; removed in the next minor version. */
|
|
131
132
|
export interface RateLimitConfig {
|
|
132
133
|
limit: number;
|
|
133
134
|
windowSeconds: number;
|
package/src/contracts/common.ts
CHANGED
|
@@ -16,6 +16,7 @@ export type NotificationChannel = z.infer<typeof NotificationChannelSchema>;
|
|
|
16
16
|
export const NotificationPrioritySchema = z.enum(["low", "normal", "high", "critical"]);
|
|
17
17
|
export type NotificationPriority = z.infer<typeof NotificationPrioritySchema>;
|
|
18
18
|
|
|
19
|
+
/** @deprecated Unused; removed in the next minor version. */
|
|
19
20
|
export const NotificationStatusSchema = z.enum([
|
|
20
21
|
"pending",
|
|
21
22
|
"queued",
|
|
@@ -25,4 +26,5 @@ export const NotificationStatusSchema = z.enum([
|
|
|
25
26
|
"bounced",
|
|
26
27
|
"suppressed",
|
|
27
28
|
]);
|
|
29
|
+
/** @deprecated Unused; removed in the next minor version. */
|
|
28
30
|
export type NotificationStatus = z.infer<typeof NotificationStatusSchema>;
|
|
@@ -24,7 +24,7 @@ export type TypedEventEnvelope<K extends KnownEventType> = Omit<
|
|
|
24
24
|
payload: EventPayloadMap[K];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
//
|
|
27
|
+
// The name the queue and workers use for an envelope.
|
|
28
28
|
export type StreamEvent = EventEnvelope;
|
|
29
29
|
export const StreamEventSchema = EventEnvelopeSchema;
|
|
30
30
|
export type StreamEventMetadata = EventMetadata;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { NotificationChannelSchema, NotificationPrioritySchema } from "@/contracts/common.js";
|
|
3
3
|
|
|
4
|
+
/** @deprecated Nothing publishes `notification.created`; removed in the next minor version. */
|
|
4
5
|
export const NotificationCreatedPayloadSchema = z.object({
|
|
5
6
|
projectId: z.string().uuid(),
|
|
6
7
|
recipientId: z.string().min(1),
|
|
@@ -11,4 +12,5 @@ export const NotificationCreatedPayloadSchema = z.object({
|
|
|
11
12
|
scheduledAt: z.string().datetime().optional(),
|
|
12
13
|
idempotencyKey: z.string().optional(),
|
|
13
14
|
});
|
|
15
|
+
/** @deprecated Nothing publishes `notification.created`; removed in the next minor version. */
|
|
14
16
|
export type NotificationCreatedPayload = z.infer<typeof NotificationCreatedPayloadSchema>;
|