@marktiderman/genesis-notifications 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/{chunk-EWZB35V6.js → chunk-EI3MOH2K.js} +2 -2
- package/dist/{chunk-EWZB35V6.js.map → chunk-EI3MOH2K.js.map} +1 -1
- package/dist/{chunk-2BG336II.js → chunk-NTDTU4T7.js} +5 -4
- package/dist/chunk-NTDTU4T7.js.map +1 -0
- package/dist/native.js +2 -2
- package/dist/react.js +2 -2
- package/dist/runner.d.ts +43 -168
- package/dist/runner.js +12 -1
- package/dist/runner.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/supabase.js +1 -1
- package/dist/web.js +2 -2
- package/package.json +13 -6
- package/src/react/index.tsx +2 -1
- package/src/runner/index.ts +45 -295
- package/src/server/runner.ts +2 -2
- package/src/supabase/index.ts +1 -0
- package/dist/chunk-2BG336II.js.map +0 -1
- package/dist/chunk-UXNWI7OS.js +0 -118
- package/dist/chunk-UXNWI7OS.js.map +0 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ for a domain are in [docs/NOTIFICATIONS.md](../../docs/NOTIFICATIONS.md).
|
|
|
18
18
|
| Import | What |
|
|
19
19
|
|---|---|
|
|
20
20
|
| `@marktiderman/genesis-notifications` (`/core`) | `defineNotifications`, the shared types, `MESSAGE_ACTIONS`, `GENESIS_TEST_TYPE`. No dependencies. |
|
|
21
|
-
| `/runner` |
|
|
21
|
+
| `/runner` | **Deprecated:** the outbox engine moved to `@marktiderman/genesis-supabase/runner`. This path re-exports the same values and types for at least one more minor; import from genesis-supabase instead. |
|
|
22
22
|
| `/server` | `notify()`, `syncNotificationTypes`, `createNotificationRunner`, `createNotificationsHandler`, `expoPushProvider`, `resendProvider`, `resolveSecretLink`, `checkSenderDomain`, unsubscribe tokens, webhook verification. Service role only. |
|
|
23
23
|
| `/email` | React Email: `BrandLayout`, `EmailText`, `EmailButton`, `reactEmailTemplate`, `brandedDefaultTemplate`. |
|
|
24
24
|
| `/supabase` | `NOTIFICATIONS_MIGRATIONS` and `notificationsClient(supabase)`, the browser and phone side under row level security. |
|
|
@@ -94,6 +94,11 @@ test, and the `functions/genesis-notifications` Edge Function template.
|
|
|
94
94
|
settings screen then reads and saves this package's preferences row (each category switch is that
|
|
95
95
|
category's push channel; quiet hours and previews are the row's own columns).
|
|
96
96
|
|
|
97
|
+
If the provider can't listen for feed changes (the realtime subscription throws), the feed still
|
|
98
|
+
works without live updates and the error is reported through `reportError` from
|
|
99
|
+
`@marktiderman/genesis-core/errors` (`notifications:realtime-subscribe`), which the native
|
|
100
|
+
observability block sends to Sentry. `/react` needs `@marktiderman/genesis-core` (a peer).
|
|
101
|
+
|
|
97
102
|
## Sending
|
|
98
103
|
|
|
99
104
|
```ts
|
|
@@ -109,5 +109,5 @@ function notificationsClient(client) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
export { FEED_COLUMNS, NOTIFICATIONS_MIGRATIONS, NOTIFICATIONS_PACKAGE, NotificationsClientError, choicesOf, notificationsClient };
|
|
112
|
-
//# sourceMappingURL=chunk-
|
|
113
|
-
//# sourceMappingURL=chunk-
|
|
112
|
+
//# sourceMappingURL=chunk-EI3MOH2K.js.map
|
|
113
|
+
//# sourceMappingURL=chunk-EI3MOH2K.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/supabase/index.ts"],"names":[],"mappings":";AAWO,IAAM,qBAAA,GAAwB;AAG9B,IAAM,wBAAA,GAA2B;AAAA,EACtC,EAAE,OAAA,EAAS,qBAAA,EAAuB,IAAA,EAAM,2CAAA,EAA6C,MAAM,sDAAA;AAC7F;AA+BO,IAAM,wBAAA,GAAN,cAAuC,KAAA,CAAM;AAAA,EAClD,WAAA,CACW,WACA,IAAA,EACT;AACA,IAAA,KAAA,CAAM,CAAA,EAAG,SAAS,C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0CAAA,EAA4C,EAAE,YAAA,EAAc,SAAA,EAAW,UAAA,EAAY,QAAA,EAAU,CAAC,CAAA;AACjL,MAAA,OAAO,QAAQ,IAAI,CAAA;AAAA,IACrB,CAAA;AAAA,IACA,MAAM,QAAA,CAAS,QAAA,GAAW,IAAA,EAAM;AAC9B,MAAA,MAAM,EAAE,IAAA,EAAK,GAAI,IAAA,CAAK,iCAAA,EAAmC,MAAM,MAAA,CAAO,GAAA,CAAI,iCAAA,EAAmC,EAAE,QAAA,EAAU,QAAA,EAAU,CAAC,CAAA;AACpI,MAAA,OAAQ,IAAA,IAA0B,IAAA;AAAA,IACpC;AAAA,GACF;AACF","file":"chunk-EWZB35V6.js","sourcesContent":["/**\n * `@marktiderman/genesis-notifications/supabase`: the migration this package\n * ships (`migrations/0001_genesis_notifications.sql`, with its pgTAP test),\n * and `notificationsClient(supabase)`, the browser and phone side over it:\n * the person's feed, unread count, marks and preferences under row level\n * security, the realtime nudge on `user:<id>`, and the admin views.\n *\n * @packageDocumentation\n */\nimport type { Channel, ChannelChoices, NotificationRow } from \"../core/index\";\n\nexport const NOTIFICATIONS_PACKAGE = \"@marktiderman/genesis-notifications\";\n\n/** The migrations to copy, in order, with their tests. */\nexport const NOTIFICATIONS_MIGRATIONS = [\n { package: NOTIFICATIONS_PACKAGE, file: \"migrations/0001_genesis_notifications.sql\", test: \"migrations/tests/0001_genesis_notifications.test.sql\" },\n] as const;\n\ntype Result = { data: unknown; error: { message?: string; code?: string | null } | null; count?: number | null };\n\ninterface Query extends PromiseLike<Result> {\n select(columns: string, options?: { count?: \"exact\"; head?: boolean }): Query;\n eq(column: string, value: unknown): Query;\n is(column: string, value: null): Query;\n not(column: string, op: string, value: unknown): Query;\n lt(column: string, value: unknown): Query;\n order(column: string, options?: { ascending?: boolean }): Query;\n limit(n: number): Query;\n maybeSingle(): PromiseLike<Result>;\n}\n\ninterface Channel_ {\n on(type: \"broadcast\", filter: { event: string }, callback: (payload: unknown) => void): Channel_;\n subscribe(callback?: (status: string) => void): Channel_;\n}\n\n/** The parts of a Supabase client used here; a `SupabaseClient` fits, typed by your Database or not. */\nexport interface NotificationsSupabaseLike {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rpc: (fn: any, args?: any) => PromiseLike<Result>;\n from(table: string): unknown;\n channel(name: string, options?: { config?: { private?: boolean } }): unknown;\n removeChannel(channel: unknown): unknown;\n realtime?: { setAuth?: (token?: string | null) => unknown };\n}\n\n/** A database refusal, with its SQLSTATE. */\nexport class NotificationsClientError extends Error {\n constructor(\n readonly operation: string,\n readonly code: string | null,\n ) {\n super(`${operation} failed${code ? ` (${code})` : \"\"}`);\n this.name = \"NotificationsClientError\";\n }\n}\n\nexport type FeedFilter = \"all\" | \"unread\" | \"archived\";\n\n/** One row of the admin's delivery log: no content, a masked address. */\nexport interface DeliveryLogRow {\n id: string;\n notification_id: string;\n tenant_id: string | null;\n type: string;\n channel: \"push\" | \"email\";\n status: string;\n attempts: number;\n error: string | null;\n skip_reason: string | null;\n recipient_masked: string | null;\n created_at: string;\n sent_at: string | null;\n}\n\nexport interface SuppressionRow {\n email_hash: string;\n category: string;\n reason: \"bounce\" | \"complaint\" | \"unsubscribe\" | \"manual\";\n email_masked: string | null;\n created_at: string;\n}\n\nexport interface NotificationsClient {\n feed(options?: { filter?: FeedFilter; limit?: number; before?: string }): Promise<NotificationRow[]>;\n unreadCount(): Promise<number>;\n mark(ids: readonly string[], state: \"seen\" | \"read\" | \"unread\" | \"archived\" | \"unarchived\"): Promise<number>;\n markAll(state: \"seen\" | \"read\"): Promise<number>;\n /** The signed-in person's choices (category → channel → on); `{}` before they chose. */\n choices(userId: string): Promise<ChannelChoices>;\n /** One category and channel; `null` returns it to the default. Resolves the person's choices after. */\n setChoice(category: string, channel: Channel, on: boolean | null): Promise<ChannelChoices>;\n /** Calls `onChange` whenever the person's feed changes (a broadcast on `user:<id>`). Returns the stop. */\n subscribe(userId: string, onChange: () => void): () => void;\n /** Admin: the delivery log (row level security shows an admin their tenants'). */\n deliveryLog(options?: { tenantId?: string | null; status?: string; limit?: number }): Promise<DeliveryLogRow[]>;\n /** Admin: the suppression list (platform admins). */\n suppressions(options?: { limit?: number }): Promise<SuppressionRow[]>;\n removeSuppression(emailHash: string, category?: string): Promise<boolean>;\n /** Admin: a test notification to yourself, on every channel you have. */\n sendTest(tenantId?: string | null): Promise<string | null>;\n}\n\n/**\n * A preferences row as category → channel → on: `channels`, with the push\n * and email of a category switched off as a whole (migration 0005's\n * `categories`) filled in where no channel was chosen, as the server reads it.\n */\nexport function choicesOf(row: { channels?: unknown; categories?: unknown } | null): ChannelChoices {\n const object = (v: unknown): Record<string, unknown> => (v && typeof v === \"object\" && !Array.isArray(v) ? (v as Record<string, unknown>) : {});\n const out: ChannelChoices = {};\n for (const [category, chosen] of Object.entries(object(row?.channels))) {\n const cell: Partial<Record<Channel, boolean>> = {};\n for (const [ch, on] of Object.entries(object(chosen))) if (typeof on === \"boolean\" && (ch === \"in_app\" || ch === \"push\" || ch === \"email\")) cell[ch] = on;\n out[category] = cell;\n }\n for (const [category, on] of Object.entries(object(row?.categories))) {\n if (on !== false) continue;\n const cell = { ...out[category] };\n cell.push ??= false;\n cell.email ??= false;\n out[category] = cell;\n }\n return out;\n}\n\nexport const FEED_COLUMNS = \"id, type, category, tenant_id, data, thread_key, created_at, seen_at, read_at, archived_at\";\nconst LOG_COLUMNS = \"id, notification_id, tenant_id, type, channel, status, attempts, error, skip_reason, recipient_masked, created_at, sent_at\";\n\n/**\n * The browser and phone side of the notifier, under the signed-in person's\n * row level security.\n *\n * @stability Beta\n */\nexport function notificationsClient(client: NotificationsSupabaseLike): NotificationsClient {\n const must = (operation: string, result: Result) => {\n if (result.error) throw new NotificationsClientError(operation, result.error.code ?? null);\n return result;\n };\n const table = (name: string) => client.from(name) as Query;\n return {\n async feed({ filter = \"all\", limit = 50, before } = {}) {\n let q = table(\"notifications\").select(FEED_COLUMNS).eq(\"in_feed\", true);\n q = filter === \"archived\" ? q.not(\"archived_at\", \"is\", null) : q.is(\"archived_at\", null);\n if (filter === \"unread\") q = q.is(\"read_at\", null);\n if (before) q = q.lt(\"created_at\", before);\n const { data } = must(\"notifications\", await q.order(\"created_at\", { ascending: false }).limit(Math.min(Math.max(1, limit), 200)));\n return (data as NotificationRow[] | null) ?? [];\n },\n async unreadCount() {\n const { count } = must(\n \"notifications\",\n await table(\"notifications\").select(\"id\", { count: \"exact\", head: true }).eq(\"in_feed\", true).is(\"read_at\", null).is(\"archived_at\", null),\n );\n return count ?? 0;\n },\n async mark(ids, state) {\n if (!ids.length) return 0;\n const { data } = must(\"genesis_notifications_mark\", await client.rpc(\"genesis_notifications_mark\", { p_ids: ids, p_state: state }));\n return Number(data ?? 0);\n },\n async markAll(state) {\n const { data } = must(\"genesis_notifications_mark_all\", await client.rpc(\"genesis_notifications_mark_all\", { p_state: state }));\n return Number(data ?? 0);\n },\n async choices(userId) {\n const { data } = must(\"notification_preferences\", await table(\"notification_preferences\").select(\"channels, categories\").eq(\"user_id\", userId).maybeSingle());\n return choicesOf(data as { channels?: unknown; categories?: unknown } | null);\n },\n async setChoice(category, channel, on) {\n const { data } = must(\"genesis_notifications_set_preference\", await client.rpc(\"genesis_notifications_set_preference\", { p_category: category, p_channel: channel, p_on: on }));\n return (data as ChannelChoices | null) ?? {};\n },\n subscribe(userId, onChange) {\n if (typeof client.channel !== \"function\") {\n // Loud, not fatal: without realtime the feed still refetches on focus and pull to refresh.\n console.warn(\"[genesis-notifications] this Supabase client has no realtime (client.channel); the feed won't update live.\");\n return () => {};\n }\n const channel = client.channel(`user:${userId}`, { config: { private: true } }) as Channel_;\n channel.on(\"broadcast\", { event: \"notification\" }, () => onChange()).subscribe();\n return () => {\n client.removeChannel(channel);\n };\n },\n async deliveryLog({ tenantId, status, limit = 100 } = {}) {\n let q = table(\"notification_deliveries\").select(LOG_COLUMNS);\n if (tenantId !== undefined) q = tenantId === null ? q.is(\"tenant_id\", null) : q.eq(\"tenant_id\", tenantId);\n if (status) q = q.eq(\"status\", status);\n const { data } = must(\"notification_deliveries\", await q.order(\"created_at\", { ascending: false }).limit(Math.min(Math.max(1, limit), 500)));\n return (data as DeliveryLogRow[] | null) ?? [];\n },\n async suppressions({ limit = 200 } = {}) {\n const { data } = must(\n \"notification_suppressions\",\n await table(\"notification_suppressions\").select(\"email_hash, category, reason, email_masked, created_at\").order(\"created_at\", { ascending: false }).limit(Math.min(Math.max(1, limit), 1000)),\n );\n return (data as SuppressionRow[] | null) ?? [];\n },\n async removeSuppression(emailHash, category = \"*\") {\n const { data } = must(\"genesis_notifications_remove_suppression\", await client.rpc(\"genesis_notifications_remove_suppression\", { p_email_hash: emailHash, p_category: category }));\n return Boolean(data);\n },\n async sendTest(tenantId = null) {\n const { data } = must(\"genesis_notifications_send_test\", await client.rpc(\"genesis_notifications_send_test\", { p_tenant: tenantId }));\n return (data as string | null) ?? null;\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/supabase/index.ts"],"names":[],"mappings":";AAWO,IAAM,qBAAA,GAAwB;AAG9B,IAAM,wBAAA,GAA2B;AAAA,EACtC,EAAE,OAAA,EAAS,qBAAA,EAAuB,IAAA,EAAM,2CAAA,EAA6C,MAAM,sDAAA;AAC7F;AA+BO,IAAM,wBAAA,GAAN,cAAuC,KAAA,CAAM;AAAA,EAClD,WAAA,CACW,WACA,IAAA,EACT;AACA,IAAA,KAAA,CAAM,CAAA,EAAG,SAAS,CAAA,OAAA,EAAU,IAAA,GAAO,KAAK,IAAI,CAAA,CAAA,CAAA,GAAM,EAAE,CAAA,CAAE,CAAA;AAH7C,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAGT,IAAA,IAAA,CAAK,IAAA,GAAO,0BAAA;AAAA,EACd;AAAA,EALW,SAAA;AAAA,EACA,IAAA;AAKb;AAqDO,SAAS,UAAU,GAAA,EAA0E;AAClG,EAAA,MAAM,MAAA,GAAS,CAAC,CAAA,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AAA;AACpI,MAAA,OAAQ,IAAA,IAA0B,IAAA;AAAA,IACpC;AAAA,GACF;AACF","file":"chunk-EI3MOH2K.js","sourcesContent":["/**\n * `@marktiderman/genesis-notifications/supabase`: the migration this package\n * ships (`migrations/0001_genesis_notifications.sql`, with its pgTAP test),\n * and `notificationsClient(supabase)`, the browser and phone side over it:\n * the person's feed, unread count, marks and preferences under row level\n * security, the realtime nudge on `user:<id>`, and the admin views.\n *\n * @packageDocumentation\n */\nimport type { Channel, ChannelChoices, NotificationRow } from \"../core/index\";\n\nexport const NOTIFICATIONS_PACKAGE = \"@marktiderman/genesis-notifications\";\n\n/** The migrations to copy, in order, with their tests. */\nexport const NOTIFICATIONS_MIGRATIONS = [\n { package: NOTIFICATIONS_PACKAGE, file: \"migrations/0001_genesis_notifications.sql\", test: \"migrations/tests/0001_genesis_notifications.test.sql\" },\n] as const;\n\ntype Result = { data: unknown; error: { message?: string; code?: string | null } | null; count?: number | null };\n\ninterface Query extends PromiseLike<Result> {\n select(columns: string, options?: { count?: \"exact\"; head?: boolean }): Query;\n eq(column: string, value: unknown): Query;\n is(column: string, value: null): Query;\n not(column: string, op: string, value: unknown): Query;\n lt(column: string, value: unknown): Query;\n order(column: string, options?: { ascending?: boolean }): Query;\n limit(n: number): Query;\n maybeSingle(): PromiseLike<Result>;\n}\n\ninterface Channel_ {\n on(type: \"broadcast\", filter: { event: string }, callback: (payload: unknown) => void): Channel_;\n subscribe(callback?: (status: string) => void): Channel_;\n}\n\n/** The parts of a Supabase client used here; a `SupabaseClient` fits, typed by your Database or not. */\nexport interface NotificationsSupabaseLike {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n rpc: (fn: any, args?: any) => PromiseLike<Result>;\n from(table: string): unknown;\n channel(name: string, options?: { config?: { private?: boolean } }): unknown;\n removeChannel(channel: unknown): unknown;\n realtime?: { setAuth?: (token?: string | null) => unknown };\n}\n\n/** A database refusal, with its SQLSTATE. */\nexport class NotificationsClientError extends Error {\n constructor(\n readonly operation: string,\n readonly code: string | null,\n ) {\n super(`${operation} failed${code ? ` (${code})` : \"\"}`);\n this.name = \"NotificationsClientError\";\n }\n}\n\nexport type FeedFilter = \"all\" | \"unread\" | \"archived\";\n\n/** One row of the admin's delivery log: no content, a masked address. */\nexport interface DeliveryLogRow {\n id: string;\n notification_id: string;\n tenant_id: string | null;\n type: string;\n channel: \"push\" | \"email\";\n status: string;\n attempts: number;\n error: string | null;\n skip_reason: string | null;\n recipient_masked: string | null;\n created_at: string;\n sent_at: string | null;\n}\n\nexport interface SuppressionRow {\n email_hash: string;\n category: string;\n reason: \"bounce\" | \"complaint\" | \"unsubscribe\" | \"manual\";\n email_masked: string | null;\n created_at: string;\n}\n\nexport interface NotificationsClient {\n feed(options?: { filter?: FeedFilter; limit?: number; before?: string }): Promise<NotificationRow[]>;\n unreadCount(): Promise<number>;\n mark(ids: readonly string[], state: \"seen\" | \"read\" | \"unread\" | \"archived\" | \"unarchived\"): Promise<number>;\n markAll(state: \"seen\" | \"read\"): Promise<number>;\n /** The signed-in person's choices (category → channel → on); `{}` before they chose. */\n choices(userId: string): Promise<ChannelChoices>;\n /** One category and channel; `null` returns it to the default. Resolves the person's choices after. */\n setChoice(category: string, channel: Channel, on: boolean | null): Promise<ChannelChoices>;\n /** Calls `onChange` whenever the person's feed changes (a broadcast on `user:<id>`). Returns the stop. */\n subscribe(userId: string, onChange: () => void): () => void;\n /** Admin: the delivery log (row level security shows an admin their tenants'). */\n deliveryLog(options?: { tenantId?: string | null; status?: string; limit?: number }): Promise<DeliveryLogRow[]>;\n /** Admin: the suppression list (platform admins). */\n suppressions(options?: { limit?: number }): Promise<SuppressionRow[]>;\n removeSuppression(emailHash: string, category?: string): Promise<boolean>;\n /** Admin: a test notification to yourself, on every channel you have. */\n sendTest(tenantId?: string | null): Promise<string | null>;\n}\n\n/**\n * A preferences row as category → channel → on: `channels`, with the push\n * and email of a category switched off as a whole (migration 0005's\n * `categories`) filled in where no channel was chosen, as the server reads it.\n */\nexport function choicesOf(row: { channels?: unknown; categories?: unknown } | null): ChannelChoices {\n const object = (v: unknown): Record<string, unknown> => (v && typeof v === \"object\" && !Array.isArray(v) ? (v as Record<string, unknown>) : {});\n const out: ChannelChoices = {};\n for (const [category, chosen] of Object.entries(object(row?.channels))) {\n const cell: Partial<Record<Channel, boolean>> = {};\n for (const [ch, on] of Object.entries(object(chosen))) if (typeof on === \"boolean\" && (ch === \"in_app\" || ch === \"push\" || ch === \"email\")) cell[ch] = on;\n out[category] = cell;\n }\n for (const [category, on] of Object.entries(object(row?.categories))) {\n if (on !== false) continue;\n const cell = { ...out[category] };\n cell.push ??= false;\n cell.email ??= false;\n out[category] = cell;\n }\n return out;\n}\n\nexport const FEED_COLUMNS = \"id, type, category, tenant_id, data, thread_key, created_at, seen_at, read_at, archived_at\";\nconst LOG_COLUMNS = \"id, notification_id, tenant_id, type, channel, status, attempts, error, skip_reason, recipient_masked, created_at, sent_at\";\n\n/**\n * The browser and phone side of the notifier, under the signed-in person's\n * row level security.\n *\n * @stability Beta\n */\nexport function notificationsClient(client: NotificationsSupabaseLike): NotificationsClient {\n const must = (operation: string, result: Result) => {\n if (result.error) throw new NotificationsClientError(operation, result.error.code ?? null);\n return result;\n };\n const table = (name: string) => client.from(name) as Query;\n return {\n async feed({ filter = \"all\", limit = 50, before } = {}) {\n let q = table(\"notifications\").select(FEED_COLUMNS).eq(\"in_feed\", true);\n q = filter === \"archived\" ? q.not(\"archived_at\", \"is\", null) : q.is(\"archived_at\", null);\n if (filter === \"unread\") q = q.is(\"read_at\", null);\n if (before) q = q.lt(\"created_at\", before);\n const { data } = must(\"notifications\", await q.order(\"created_at\", { ascending: false }).limit(Math.min(Math.max(1, limit), 200)));\n return (data as NotificationRow[] | null) ?? [];\n },\n async unreadCount() {\n const { count } = must(\n \"notifications\",\n await table(\"notifications\").select(\"id\", { count: \"exact\", head: true }).eq(\"in_feed\", true).is(\"read_at\", null).is(\"archived_at\", null),\n );\n return count ?? 0;\n },\n async mark(ids, state) {\n if (!ids.length) return 0;\n const { data } = must(\"genesis_notifications_mark\", await client.rpc(\"genesis_notifications_mark\", { p_ids: ids, p_state: state }));\n return Number(data ?? 0);\n },\n async markAll(state) {\n const { data } = must(\"genesis_notifications_mark_all\", await client.rpc(\"genesis_notifications_mark_all\", { p_state: state }));\n return Number(data ?? 0);\n },\n async choices(userId) {\n const { data } = must(\"notification_preferences\", await table(\"notification_preferences\").select(\"channels, categories\").eq(\"user_id\", userId).maybeSingle());\n return choicesOf(data as { channels?: unknown; categories?: unknown } | null);\n },\n async setChoice(category, channel, on) {\n const { data } = must(\"genesis_notifications_set_preference\", await client.rpc(\"genesis_notifications_set_preference\", { p_category: category, p_channel: channel, p_on: on }));\n return (data as ChannelChoices | null) ?? {};\n },\n subscribe(userId, onChange) {\n if (typeof client.channel !== \"function\") {\n // Loud, not fatal: without realtime the feed still refetches on focus and pull to refresh.\n // genesis-allow-console: a set-up hint (a client without realtime), not an error.\n console.warn(\"[genesis-notifications] this Supabase client has no realtime (client.channel); the feed won't update live.\");\n return () => {};\n }\n const channel = client.channel(`user:${userId}`, { config: { private: true } }) as Channel_;\n channel.on(\"broadcast\", { event: \"notification\" }, () => onChange()).subscribe();\n return () => {\n client.removeChannel(channel);\n };\n },\n async deliveryLog({ tenantId, status, limit = 100 } = {}) {\n let q = table(\"notification_deliveries\").select(LOG_COLUMNS);\n if (tenantId !== undefined) q = tenantId === null ? q.is(\"tenant_id\", null) : q.eq(\"tenant_id\", tenantId);\n if (status) q = q.eq(\"status\", status);\n const { data } = must(\"notification_deliveries\", await q.order(\"created_at\", { ascending: false }).limit(Math.min(Math.max(1, limit), 500)));\n return (data as DeliveryLogRow[] | null) ?? [];\n },\n async suppressions({ limit = 200 } = {}) {\n const { data } = must(\n \"notification_suppressions\",\n await table(\"notification_suppressions\").select(\"email_hash, category, reason, email_masked, created_at\").order(\"created_at\", { ascending: false }).limit(Math.min(Math.max(1, limit), 1000)),\n );\n return (data as SuppressionRow[] | null) ?? [];\n },\n async removeSuppression(emailHash, category = \"*\") {\n const { data } = must(\"genesis_notifications_remove_suppression\", await client.rpc(\"genesis_notifications_remove_suppression\", { p_email_hash: emailHash, p_category: category }));\n return Boolean(data);\n },\n async sendTest(tenantId = null) {\n const { data } = must(\"genesis_notifications_send_test\", await client.rpc(\"genesis_notifications_send_test\", { p_tenant: tenantId }));\n return (data as string | null) ?? null;\n },\n };\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { notificationsClient } from './chunk-
|
|
1
|
+
import { notificationsClient } from './chunk-EI3MOH2K.js';
|
|
2
2
|
import { createContext, useMemo, useEffect, useContext } from 'react';
|
|
3
3
|
import { useQueryClient, useQuery, useMutation } from '@tanstack/react-query';
|
|
4
|
+
import { reportError } from '@marktiderman/genesis-core/errors';
|
|
4
5
|
import { jsx } from 'react/jsx-runtime';
|
|
5
6
|
|
|
6
7
|
var NotificationsContext = createContext(null);
|
|
@@ -21,7 +22,7 @@ function NotificationsProvider({ client, registry, userId, realtime = true, chil
|
|
|
21
22
|
void queryClient.invalidateQueries({ queryKey: notificationKeys.all(userId) });
|
|
22
23
|
});
|
|
23
24
|
} catch (error) {
|
|
24
|
-
|
|
25
|
+
reportError(error, "notifications:realtime-subscribe");
|
|
25
26
|
return void 0;
|
|
26
27
|
}
|
|
27
28
|
}, [resolved, userId, realtime, queryClient]);
|
|
@@ -120,5 +121,5 @@ function usePreferences() {
|
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
export { NotificationsProvider, notificationKeys, preferenceRows, useNotifications, useNotificationsContext, usePreferences, useUnreadCount };
|
|
123
|
-
//# sourceMappingURL=chunk-
|
|
124
|
-
//# sourceMappingURL=chunk-
|
|
124
|
+
//# sourceMappingURL=chunk-NTDTU4T7.js.map
|
|
125
|
+
//# sourceMappingURL=chunk-NTDTU4T7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react/index.tsx"],"names":[],"mappings":";;;;;;AA0B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AAA,EAAI,EAAA,EAAI,YAAY,WAAA,CAAY,YAAA,CAAa,GAAA,EAAK,OAAA,EAAS,MAAM,CAAA;AAAA;AAAA,IAE3E,WAAW,MAAM,WAAA,CAAY,kBAAkB,EAAE,QAAA,EAAU,KAAK;AAAA,GACjE,CAAA;AACD,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,MAAM,cAAA,CAAe,UAAU,KAAA,CAAM,IAAA,IAAQ,EAAE,CAAA,EAAG,CAAC,QAAA,EAAU,KAAA,CAAM,IAAI,CAAC,CAAA;AAC7F,EAAA,OAAO;AAAA,IACL,IAAA;AAAA,IACA,QAAQ,KAAA,CAAM,OAAA,GAAU,OAAA,GAAU,KAAA,CAAM,YAAY,OAAA,GAAU,SAAA;AAAA,IAC9D,KAAA,EAAS,KAAA,CAAM,KAAA,IAAS,IAAA,CAAK,KAAA,IAA2B,IAAA;AAAA,IACxD,QAAQ,IAAA,CAAK,SAAA;AAAA,IACb,GAAA,EAAK,OAAO,QAAA,EAAU,OAAA,EAAS,EAAA,KAAO;AACpC,MAAA,MAAM,MAAM,IAAA,CAAK,IAAA,CAAK,CAAC,CAAA,KAAM,CAAA,CAAE,OAAO,QAAQ,CAAA;AAC9C,MAAA,IAAI,CAAC,GAAA,IAAO,CAAC,GAAA,CAAI,QAAA,CAAS,QAAA,CAAS,OAAO,CAAA,IAAM,GAAA,CAAI,QAAA,IAAY,EAAA,KAAO,KAAA,EAAQ;AAC/E,MAAA,MAAM,KAAK,WAAA,CAAY,EAAE,QAAA,EAAU,OAAA,EAAS,IAAI,CAAA;AAAA,IAClD;AAAA,GACF;AACF","file":"chunk-NTDTU4T7.js","sourcesContent":["/**\n * `@marktiderman/genesis-notifications/react`: the hooks every screen uses,\n * on web and native alike. `NotificationsProvider` holds the client, the\n * registry and the signed-in user, and listens on the person's private\n * realtime channel: any change refetches (the broadcast carries ids only).\n *\n * useNotifications() the feed, each row rendered by the registry, plus mark read / archive\n * useUnreadCount() the unread count, for a bell or a tab badge\n * usePreferences() the category × channel matrix and its switches\n *\n * Built on TanStack Query (a peer): the app's QueryClientProvider must be above.\n *\n * @packageDocumentation\n */\nimport { createContext, useContext, useEffect, useMemo, type ReactNode } from \"react\";\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport { reportError } from \"@marktiderman/genesis-core/errors\";\nimport type { Channel, ChannelChoices, MatrixRow, NotificationRegistry, NotificationRow } from \"../core/index\";\nimport { notificationsClient, type FeedFilter, type NotificationsClient, type NotificationsSupabaseLike } from \"../supabase/index\";\n\ninterface Context {\n client: NotificationsClient;\n registry: NotificationRegistry;\n userId: string | null;\n}\n\nconst NotificationsContext = createContext<Context | null>(null);\n\nexport interface NotificationsProviderProps {\n /** A Supabase client signed in as the person (or a `notificationsClient`). */\n client: NotificationsSupabaseLike | NotificationsClient;\n registry: NotificationRegistry;\n /** The signed-in user; null while signed out (nothing is read). */\n userId: string | null;\n /** Listen on `user:<id>` and refetch on a change. Default true. */\n realtime?: boolean;\n children?: ReactNode;\n}\n\nconst isClient = (c: NotificationsSupabaseLike | NotificationsClient): c is NotificationsClient => typeof (c as NotificationsClient).feed === \"function\";\n\n/** The query keys, for an app that invalidates them itself. */\nexport const notificationKeys = {\n all: (userId: string | null) => [\"genesis-notifications\", userId] as const,\n feed: (userId: string | null, filter: FeedFilter, limit: number) => [\"genesis-notifications\", userId, \"feed\", filter, limit] as const,\n unread: (userId: string | null) => [\"genesis-notifications\", userId, \"unread\"] as const,\n choices: (userId: string | null) => [\"genesis-notifications\", userId, \"choices\"] as const,\n};\n\n/**\n * Provides the notifier to the hooks.\n *\n * @stability Beta\n */\nexport function NotificationsProvider({ client, registry, userId, realtime = true, children }: NotificationsProviderProps) {\n const resolved = useMemo(() => (isClient(client) ? client : notificationsClient(client)), [client]);\n const queryClient = useQueryClient();\n useEffect(() => {\n if (!realtime || !userId) return;\n try {\n return resolved.subscribe(userId, () => {\n void queryClient.invalidateQueries({ queryKey: notificationKeys.all(userId) });\n });\n } catch (error) {\n reportError(error, \"notifications:realtime-subscribe\");\n return undefined;\n }\n }, [resolved, userId, realtime, queryClient]);\n const value = useMemo(() => ({ client: resolved, registry, userId }), [resolved, registry, userId]);\n return <NotificationsContext.Provider value={value}>{children}</NotificationsContext.Provider>;\n}\n\n/** The provider's client, registry and user. Throws outside one. */\nexport function useNotificationsContext(): Context {\n const ctx = useContext(NotificationsContext);\n if (!ctx) throw new Error(\"useNotifications: wrap the screen in <NotificationsProvider>.\");\n return ctx;\n}\n\n/** A feed row with what the registry says about it. */\nexport interface FeedItem extends NotificationRow {\n title: string;\n body?: string;\n url?: string;\n unread: boolean;\n}\n\nexport interface UseNotificationsResult {\n items: FeedItem[];\n isLoading: boolean;\n isRefetching: boolean;\n error: Error | null;\n refetch: () => Promise<unknown>;\n markRead: (ids: string | readonly string[]) => Promise<void>;\n markUnread: (ids: string | readonly string[]) => Promise<void>;\n markAllRead: () => Promise<void>;\n archive: (ids: string | readonly string[]) => Promise<void>;\n /** Mark everything shown as seen (opening the feed); the unread count is about read, not seen. */\n markAllSeen: () => Promise<void>;\n}\n\n/**\n * The person's feed.\n *\n * @stability Beta\n */\nexport function useNotifications(options: { filter?: FeedFilter; limit?: number } = {}): UseNotificationsResult {\n const { client, registry, userId } = useNotificationsContext();\n const filter = options.filter ?? \"all\";\n const limit = options.limit ?? 50;\n const queryClient = useQueryClient();\n const query = useQuery({\n queryKey: notificationKeys.feed(userId, filter, limit),\n queryFn: () => client.feed({ filter, limit }),\n enabled: userId !== null,\n });\n const items = useMemo<FeedItem[]>(\n () =>\n (query.data ?? []).map((row) => {\n const text = registry.render(row.type, row.data ?? {});\n return { ...row, ...text, unread: row.read_at === null };\n }),\n [query.data, registry],\n );\n const changed = () => queryClient.invalidateQueries({ queryKey: notificationKeys.all(userId) });\n const mark = useMutation({\n mutationFn: ({ ids, state }: { ids: readonly string[]; state: \"seen\" | \"read\" | \"unread\" | \"archived\" }) => client.mark(ids, state),\n onSettled: changed,\n });\n const all = useMutation({ mutationFn: (state: \"seen\" | \"read\") => client.markAll(state), onSettled: changed });\n const list = (ids: string | readonly string[]) => (typeof ids === \"string\" ? [ids] : ids);\n return {\n items,\n isLoading: query.isLoading,\n isRefetching: query.isRefetching,\n error: (query.error as Error | null) ?? null,\n refetch: () => query.refetch(),\n markRead: async (ids) => void (await mark.mutateAsync({ ids: list(ids), state: \"read\" })),\n markUnread: async (ids) => void (await mark.mutateAsync({ ids: list(ids), state: \"unread\" })),\n archive: async (ids) => void (await mark.mutateAsync({ ids: list(ids), state: \"archived\" })),\n markAllRead: async () => void (await all.mutateAsync(\"read\")),\n markAllSeen: async () => void (await all.mutateAsync(\"seen\")),\n };\n}\n\n/**\n * The unread count (0 while signed out).\n *\n * @stability Beta\n */\nexport function useUnreadCount(): number {\n const { client, userId } = useNotificationsContext();\n const query = useQuery({ queryKey: notificationKeys.unread(userId), queryFn: () => client.unreadCount(), enabled: userId !== null });\n return query.data ?? 0;\n}\n\n/** One category's row in the matrix. */\nexport interface PreferenceRow extends MatrixRow {\n /** What each offered channel is now: the person's choice, else the default. */\n values: Partial<Record<Channel, boolean>>;\n /** Which values the person chose (the rest are defaults). */\n chosen: Partial<Record<Channel, boolean>>;\n}\n\nexport interface UsePreferencesResult {\n rows: PreferenceRow[];\n status: \"loading\" | \"ready\" | \"error\";\n error: Error | null;\n saving: boolean;\n /** Turn one category's channel on or off; `null` goes back to the default. Critical rows can't be turned off. */\n set: (category: string, channel: Channel, on: boolean | null) => Promise<void>;\n}\n\n/** The matrix with the person's choices applied. Exported for tests and custom screens. */\nexport function preferenceRows(registry: NotificationRegistry, choices: ChannelChoices): PreferenceRow[] {\n return registry.matrix().map((row) => {\n const chosen = choices[row.id] ?? {};\n const values: Partial<Record<Channel, boolean>> = {};\n for (const ch of row.channels) values[ch] = row.critical ? Boolean(row.defaults[ch]) : (chosen[ch] ?? Boolean(row.defaults[ch]));\n return { ...row, values, chosen: row.critical ? {} : chosen };\n });\n}\n\n/**\n * The person's preferences by category and channel. A tenant's default\n * isn't shown here (the server applies it); what shows for a channel the\n * person never chose is the type's default.\n *\n * @stability Beta\n */\nexport function usePreferences(): UsePreferencesResult {\n const { client, registry, userId } = useNotificationsContext();\n const queryClient = useQueryClient();\n const key = notificationKeys.choices(userId);\n const query = useQuery({ queryKey: key, queryFn: () => client.choices(userId!), enabled: userId !== null });\n const save = useMutation({\n mutationFn: ({ category, channel, on }: { category: string; channel: Channel; on: boolean | null }) => client.setChoice(category, channel, on),\n onMutate: async ({ category, channel, on }) => {\n await queryClient.cancelQueries({ queryKey: key });\n const before = queryClient.getQueryData<ChannelChoices>(key);\n const next: ChannelChoices = { ...(before ?? {}) };\n const row = { ...(next[category] ?? {}) };\n if (on === null) delete row[channel];\n else row[channel] = on;\n next[category] = row;\n queryClient.setQueryData(key, next);\n return { before };\n },\n onError: (_e, _v, context) => queryClient.setQueryData(key, context?.before),\n // Read back through `choices()` (which folds in 0005's category switches), never the raw row the save returns.\n onSettled: () => queryClient.invalidateQueries({ queryKey: key }),\n });\n const rows = useMemo(() => preferenceRows(registry, query.data ?? {}), [registry, query.data]);\n return {\n rows,\n status: query.isError ? \"error\" : query.isSuccess ? \"ready\" : \"loading\",\n error: ((query.error ?? save.error) as Error | null) ?? null,\n saving: save.isPending,\n set: async (category, channel, on) => {\n const row = rows.find((r) => r.id === category);\n if (!row || !row.channels.includes(channel) || (row.critical && on === false)) return;\n await save.mutateAsync({ category, channel, on });\n },\n };\n}\n\nexport { notificationsClient, type NotificationsClient } from \"../supabase/index\";\n"]}
|
package/dist/native.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useNotifications, usePreferences } from './chunk-
|
|
2
|
-
import { choicesOf } from './chunk-
|
|
1
|
+
import { useNotifications, usePreferences } from './chunk-NTDTU4T7.js';
|
|
2
|
+
import { choicesOf } from './chunk-EI3MOH2K.js';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import { NativeListItem, NativeSwitch } from '@marktiderman/genesis-ui-native/components';
|
|
5
5
|
import { NotificationsPage, getNotificationsPageStackOptions } from '@marktiderman/genesis-ui-native/layouts';
|
package/dist/react.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { NotificationsProvider, notificationKeys, preferenceRows, useNotifications, useNotificationsContext, usePreferences, useUnreadCount } from './chunk-
|
|
2
|
-
export { notificationsClient } from './chunk-
|
|
1
|
+
export { NotificationsProvider, notificationKeys, preferenceRows, useNotifications, useNotificationsContext, usePreferences, useUnreadCount } from './chunk-NTDTU4T7.js';
|
|
2
|
+
export { notificationsClient } from './chunk-EI3MOH2K.js';
|
|
3
3
|
//# sourceMappingURL=react.js.map
|
|
4
4
|
//# sourceMappingURL=react.js.map
|
package/dist/runner.d.ts
CHANGED
|
@@ -1,174 +1,49 @@
|
|
|
1
|
+
import * as engine from '@marktiderman/genesis-supabase/runner';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
* `@marktiderman/genesis-notifications/runner`:
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* queue): `claim` hands over leased jobs and `record` takes back outcomes.
|
|
8
|
-
* The runner owns the rest: turning each send result into an outcome with a
|
|
9
|
-
* retry time, jittered backoff, the deferral cap, and never throwing for one
|
|
10
|
-
* job's failure. The notifier's push and email channels run on it, and so do
|
|
11
|
-
* genesis-forms' destinations (Sheets, webhooks), each with its own claim.
|
|
12
|
-
*
|
|
13
|
-
* Outcomes:
|
|
14
|
-
* - `sent`: delivered (or already there, on a redelivery: `alreadyThere`).
|
|
15
|
-
* - `filtered`: the sender decided it doesn't apply; nothing sent, nothing to retry.
|
|
16
|
-
* - `skipped`: deliberately not sent (`notSent`: a reason safe to store); never retried.
|
|
17
|
-
* - `retry`: a retryable failure. With the service's own Retry-After it is
|
|
18
|
-
* deferred without counting an attempt (`counted: false`), until
|
|
19
|
-
* `maxDeferrals`; otherwise it backs off by attempt (`counted: true`), until
|
|
20
|
-
* `maxAttempts`.
|
|
21
|
-
* - `failed`: permanent, or out of attempts. With `disable: true` the receiver
|
|
22
|
-
* asked to be switched off (a 410 Gone): stop sending to it.
|
|
23
|
-
*
|
|
24
|
-
* It never logs content, addresses or secrets: only what `label` gives and
|
|
25
|
-
* the senders' safe error messages.
|
|
4
|
+
* `@marktiderman/genesis-notifications/runner`: deprecated. The outbox engine
|
|
5
|
+
* moved to `@marktiderman/genesis-supabase/runner`, where the background-job
|
|
6
|
+
* queue runs on it too. Everything here is the same value or type as there,
|
|
7
|
+
* re-exported so existing imports keep working for at least one more minor
|
|
8
|
+
* release. Import from `@marktiderman/genesis-supabase/runner` instead.
|
|
26
9
|
*
|
|
10
|
+
* @deprecated Import from `@marktiderman/genesis-supabase/runner`.
|
|
27
11
|
* @packageDocumentation
|
|
28
12
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
status: "filtered";
|
|
65
|
-
} | {
|
|
66
|
-
status: "skipped";
|
|
67
|
-
reason: string;
|
|
68
|
-
} | {
|
|
69
|
-
status: "retry";
|
|
70
|
-
error: string;
|
|
71
|
-
retryAt: Date;
|
|
72
|
-
retryAfterSeconds: number;
|
|
73
|
-
/** Whether this attempt counts toward `maxAttempts`. False when the service said when to come back. */
|
|
74
|
-
counted: boolean;
|
|
75
|
-
httpStatus?: number;
|
|
76
|
-
} | {
|
|
77
|
-
status: "failed";
|
|
78
|
-
error: string;
|
|
79
|
-
httpStatus?: number;
|
|
80
|
-
disable?: true;
|
|
81
|
-
};
|
|
82
|
-
interface RunReport {
|
|
83
|
-
claimed: number;
|
|
84
|
-
sent: number;
|
|
85
|
-
filtered: number;
|
|
86
|
-
skipped: number;
|
|
87
|
-
/** Retryable failures, backed off by attempt. */
|
|
88
|
-
retrying: number;
|
|
89
|
-
/** Retryable failures the service said when to retry; no attempt used. */
|
|
90
|
-
deferred: number;
|
|
91
|
-
failed: number;
|
|
92
|
-
/** Recorded after the claim was lost (`record` resolved false). */
|
|
93
|
-
stale: number;
|
|
94
|
-
/** `record` threw. */
|
|
95
|
-
unrecorded: number;
|
|
96
|
-
}
|
|
97
|
-
interface ClaimRequest<Filter> {
|
|
98
|
-
limit: number;
|
|
99
|
-
filter?: Filter | undefined;
|
|
100
|
-
}
|
|
101
|
-
interface SendContext {
|
|
102
|
-
signal?: AbortSignal | undefined;
|
|
103
|
-
}
|
|
104
|
-
interface RunnerOptions<J extends RunnerJob, Filter = undefined> {
|
|
105
|
-
/** Claims up to `limit` due jobs, each leased so no other runner sends it meanwhile. */
|
|
106
|
-
claim(request: ClaimRequest<Filter>): Promise<readonly J[]>;
|
|
107
|
-
/**
|
|
108
|
-
* Sends one group of jobs (those with the same `group` key) and resolves one
|
|
109
|
-
* result per job, in order, or `"filtered"`. A throw fails the whole group
|
|
110
|
-
* with a retryable error.
|
|
111
|
-
*/
|
|
112
|
-
send(group: readonly J[], context: SendContext): Promise<readonly (JobResult | "filtered")[]>;
|
|
113
|
-
/** Jobs with the same key are sent together. Default: each job alone. */
|
|
114
|
-
group?: ((job: J) => string) | undefined;
|
|
115
|
-
/**
|
|
116
|
-
* Records an outcome. Resolve `false` when the claim was no longer held: it
|
|
117
|
-
* is counted as stale. A rejection is counted as unrecorded; the lease runs
|
|
118
|
-
* out and the job comes back on its own.
|
|
119
|
-
*/
|
|
120
|
-
record(job: J, outcome: JobOutcome): Promise<void | boolean>;
|
|
121
|
-
now?: (() => number) | undefined;
|
|
122
|
-
/** Safe lines (ids, kinds, short reasons). Default: nothing is logged. */
|
|
123
|
-
log?: ((message: string) => void) | undefined;
|
|
124
|
-
/** How a job is named in a log line, capitalised ("Delivery d1 (email)"). Default `Job <id>`. */
|
|
125
|
-
label?: ((job: J) => string) | undefined;
|
|
126
|
-
/** How a job is named when recording it failed ("delivery d1"). Default `job <id>`. */
|
|
127
|
-
recordLabel?: ((job: J) => string) | undefined;
|
|
128
|
-
/** Jobs claimed per run. Default 25. */
|
|
129
|
-
batchSize?: number | undefined;
|
|
130
|
-
/** Counted attempts before a retryable failure is given up. Default 8. */
|
|
131
|
-
maxAttempts?: number | undefined;
|
|
132
|
-
/** Deferrals allowed before a further one counts as an attempt. Default 24. */
|
|
133
|
-
maxDeferrals?: number | undefined;
|
|
134
|
-
/** Seconds to wait after a counted failed attempt. Default `defaultBackoff`. */
|
|
135
|
-
backoff?: ((attempt: number) => number) | undefined;
|
|
136
|
-
}
|
|
137
|
-
interface RunOptions<Filter> {
|
|
138
|
-
filter?: Filter | undefined;
|
|
139
|
-
/** Overrides `batchSize` for this run. */
|
|
140
|
-
limit?: number | undefined;
|
|
141
|
-
/** Aborts the sends in flight. */
|
|
142
|
-
signal?: AbortSignal | undefined;
|
|
143
|
-
}
|
|
144
|
-
interface Runner<Filter = undefined> {
|
|
145
|
-
/** One claim, its sends and their records. Never rejects for a job's failure; a failing `claim` rejects. */
|
|
146
|
-
run(options?: RunOptions<Filter>): Promise<RunReport>;
|
|
147
|
-
}
|
|
148
|
-
declare const DEFAULT_MAX_ATTEMPTS = 8;
|
|
149
|
-
declare const DEFAULT_MAX_DEFERRALS = 24;
|
|
150
|
-
declare const DEFAULT_BATCH_SIZE = 25;
|
|
151
|
-
/**
|
|
152
|
-
* 5 minutes, quadrupling each attempt, at most 24 hours: 5m, 20m, 80m, 5h20m,
|
|
153
|
-
* 21h20m, then 24h; about 3 days across 8 attempts. Each wait is jittered by
|
|
154
|
-
* up to ±20%, so jobs that failed together don't all come back at once.
|
|
155
|
-
*/
|
|
156
|
-
declare function defaultBackoff(attempt: number, random?: () => number): number;
|
|
157
|
-
/** Turns a send result into an outcome for a job on its `attempt`. */
|
|
158
|
-
declare function jobOutcome(result: JobResult, attempt: number, options?: {
|
|
159
|
-
now?: number | undefined;
|
|
160
|
-
maxAttempts?: number | undefined;
|
|
161
|
-
backoff?: ((attempt: number) => number) | undefined;
|
|
162
|
-
deferrals?: number | undefined;
|
|
163
|
-
maxDeferrals?: number | undefined;
|
|
164
|
-
}): JobOutcome;
|
|
165
|
-
/** A thrown error as a retryable failure with a safe message. */
|
|
166
|
-
declare function failureOf(error: unknown): JobFailure;
|
|
167
|
-
/**
|
|
168
|
-
* The runner.
|
|
169
|
-
*
|
|
170
|
-
* @stability Beta
|
|
171
|
-
*/
|
|
172
|
-
declare function createRunner<J extends RunnerJob, Filter = undefined>(options: RunnerOptions<J, Filter>): Runner<Filter>;
|
|
13
|
+
|
|
14
|
+
/** @deprecated Import `RunnerJob` from `@marktiderman/genesis-supabase/runner`. */
|
|
15
|
+
type RunnerJob = engine.RunnerJob;
|
|
16
|
+
/** @deprecated Import `JobResult` from `@marktiderman/genesis-supabase/runner`. */
|
|
17
|
+
type JobResult = engine.JobResult;
|
|
18
|
+
/** @deprecated Import `JobFailure` from `@marktiderman/genesis-supabase/runner`. */
|
|
19
|
+
type JobFailure = engine.JobFailure;
|
|
20
|
+
/** @deprecated Import `JobOutcome` from `@marktiderman/genesis-supabase/runner`. */
|
|
21
|
+
type JobOutcome = engine.JobOutcome;
|
|
22
|
+
/** @deprecated Import `RunReport` from `@marktiderman/genesis-supabase/runner`. */
|
|
23
|
+
type RunReport = engine.RunReport;
|
|
24
|
+
/** @deprecated Import `ClaimRequest` from `@marktiderman/genesis-supabase/runner`. */
|
|
25
|
+
type ClaimRequest<Filter> = engine.ClaimRequest<Filter>;
|
|
26
|
+
/** @deprecated Import `SendContext` from `@marktiderman/genesis-supabase/runner`. */
|
|
27
|
+
type SendContext = engine.SendContext;
|
|
28
|
+
/** @deprecated Import `RunnerOptions` from `@marktiderman/genesis-supabase/runner`. */
|
|
29
|
+
type RunnerOptions<J extends engine.RunnerJob, Filter = undefined> = engine.RunnerOptions<J, Filter>;
|
|
30
|
+
/** @deprecated Import `RunOptions` from `@marktiderman/genesis-supabase/runner`. */
|
|
31
|
+
type RunOptions<Filter> = engine.RunOptions<Filter>;
|
|
32
|
+
/** @deprecated Import `Runner` from `@marktiderman/genesis-supabase/runner`. */
|
|
33
|
+
type Runner<Filter = undefined> = engine.Runner<Filter>;
|
|
34
|
+
/** @deprecated Import `DEFAULT_MAX_ATTEMPTS` from `@marktiderman/genesis-supabase/runner`. */
|
|
35
|
+
declare const DEFAULT_MAX_ATTEMPTS: typeof engine.DEFAULT_MAX_ATTEMPTS;
|
|
36
|
+
/** @deprecated Import `DEFAULT_MAX_DEFERRALS` from `@marktiderman/genesis-supabase/runner`. */
|
|
37
|
+
declare const DEFAULT_MAX_DEFERRALS: typeof engine.DEFAULT_MAX_DEFERRALS;
|
|
38
|
+
/** @deprecated Import `DEFAULT_BATCH_SIZE` from `@marktiderman/genesis-supabase/runner`. */
|
|
39
|
+
declare const DEFAULT_BATCH_SIZE: typeof engine.DEFAULT_BATCH_SIZE;
|
|
40
|
+
/** @deprecated Import `defaultBackoff` from `@marktiderman/genesis-supabase/runner`. */
|
|
41
|
+
declare const defaultBackoff: typeof engine.defaultBackoff;
|
|
42
|
+
/** @deprecated Import `jobOutcome` from `@marktiderman/genesis-supabase/runner`. */
|
|
43
|
+
declare const jobOutcome: typeof engine.jobOutcome;
|
|
44
|
+
/** @deprecated Import `failureOf` from `@marktiderman/genesis-supabase/runner`. */
|
|
45
|
+
declare const failureOf: typeof engine.failureOf;
|
|
46
|
+
/** @deprecated Import `createRunner` from `@marktiderman/genesis-supabase/runner`. */
|
|
47
|
+
declare const createRunner: typeof engine.createRunner;
|
|
173
48
|
|
|
174
49
|
export { type ClaimRequest, DEFAULT_BATCH_SIZE, DEFAULT_MAX_ATTEMPTS, DEFAULT_MAX_DEFERRALS, type JobFailure, type JobOutcome, type JobResult, type RunOptions, type RunReport, type Runner, type RunnerJob, type RunnerOptions, type SendContext, createRunner, defaultBackoff, failureOf, jobOutcome };
|
package/dist/runner.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import * as engine from '@marktiderman/genesis-supabase/runner';
|
|
2
|
+
|
|
3
|
+
// src/runner/index.ts
|
|
4
|
+
var DEFAULT_MAX_ATTEMPTS2 = engine.DEFAULT_MAX_ATTEMPTS;
|
|
5
|
+
var DEFAULT_MAX_DEFERRALS2 = engine.DEFAULT_MAX_DEFERRALS;
|
|
6
|
+
var DEFAULT_BATCH_SIZE2 = engine.DEFAULT_BATCH_SIZE;
|
|
7
|
+
var defaultBackoff2 = engine.defaultBackoff;
|
|
8
|
+
var jobOutcome2 = engine.jobOutcome;
|
|
9
|
+
var failureOf2 = engine.failureOf;
|
|
10
|
+
var createRunner2 = engine.createRunner;
|
|
11
|
+
|
|
12
|
+
export { DEFAULT_BATCH_SIZE2 as DEFAULT_BATCH_SIZE, DEFAULT_MAX_ATTEMPTS2 as DEFAULT_MAX_ATTEMPTS, DEFAULT_MAX_DEFERRALS2 as DEFAULT_MAX_DEFERRALS, createRunner2 as createRunner, defaultBackoff2 as defaultBackoff, failureOf2 as failureOf, jobOutcome2 as jobOutcome };
|
|
2
13
|
//# sourceMappingURL=runner.js.map
|
|
3
14
|
//# sourceMappingURL=runner.js.map
|
package/dist/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"runner.js"}
|
|
1
|
+
{"version":3,"sources":["../src/runner/index.ts"],"names":["DEFAULT_MAX_ATTEMPTS","DEFAULT_MAX_DEFERRALS","DEFAULT_BATCH_SIZE","defaultBackoff","jobOutcome","failureOf","createRunner"],"mappings":";;;AAoCO,IAAMA,qBAAAA,GAAkE,MAAA,CAAA;AAExE,IAAMC,sBAAAA,GAAoE,MAAA,CAAA;AAE1E,IAAMC,mBAAAA,GAA8D,MAAA,CAAA;AAEpE,IAAMC,eAAAA,GAAsD,MAAA,CAAA;AAE5D,IAAMC,WAAAA,GAA8C,MAAA,CAAA;AAEpD,IAAMC,UAAAA,GAA4C,MAAA,CAAA;AAElD,IAAMC,aAAAA,GAAkD,MAAA,CAAA","file":"runner.js","sourcesContent":["/**\n * `@marktiderman/genesis-notifications/runner`: deprecated. The outbox engine\n * moved to `@marktiderman/genesis-supabase/runner`, where the background-job\n * queue runs on it too. Everything here is the same value or type as there,\n * re-exported so existing imports keep working for at least one more minor\n * release. Import from `@marktiderman/genesis-supabase/runner` instead.\n *\n * @deprecated Import from `@marktiderman/genesis-supabase/runner`.\n * @packageDocumentation\n */\nimport * as engine from \"@marktiderman/genesis-supabase/runner\";\n\n// Each name is declared here (not `export *`), so editors can show it as deprecated.\n\n/** @deprecated Import `RunnerJob` from `@marktiderman/genesis-supabase/runner`. */\nexport type RunnerJob = engine.RunnerJob;\n/** @deprecated Import `JobResult` from `@marktiderman/genesis-supabase/runner`. */\nexport type JobResult = engine.JobResult;\n/** @deprecated Import `JobFailure` from `@marktiderman/genesis-supabase/runner`. */\nexport type JobFailure = engine.JobFailure;\n/** @deprecated Import `JobOutcome` from `@marktiderman/genesis-supabase/runner`. */\nexport type JobOutcome = engine.JobOutcome;\n/** @deprecated Import `RunReport` from `@marktiderman/genesis-supabase/runner`. */\nexport type RunReport = engine.RunReport;\n/** @deprecated Import `ClaimRequest` from `@marktiderman/genesis-supabase/runner`. */\nexport type ClaimRequest<Filter> = engine.ClaimRequest<Filter>;\n/** @deprecated Import `SendContext` from `@marktiderman/genesis-supabase/runner`. */\nexport type SendContext = engine.SendContext;\n/** @deprecated Import `RunnerOptions` from `@marktiderman/genesis-supabase/runner`. */\nexport type RunnerOptions<J extends engine.RunnerJob, Filter = undefined> = engine.RunnerOptions<J, Filter>;\n/** @deprecated Import `RunOptions` from `@marktiderman/genesis-supabase/runner`. */\nexport type RunOptions<Filter> = engine.RunOptions<Filter>;\n/** @deprecated Import `Runner` from `@marktiderman/genesis-supabase/runner`. */\nexport type Runner<Filter = undefined> = engine.Runner<Filter>;\n\n/** @deprecated Import `DEFAULT_MAX_ATTEMPTS` from `@marktiderman/genesis-supabase/runner`. */\nexport const DEFAULT_MAX_ATTEMPTS: typeof engine.DEFAULT_MAX_ATTEMPTS = engine.DEFAULT_MAX_ATTEMPTS;\n/** @deprecated Import `DEFAULT_MAX_DEFERRALS` from `@marktiderman/genesis-supabase/runner`. */\nexport const DEFAULT_MAX_DEFERRALS: typeof engine.DEFAULT_MAX_DEFERRALS = engine.DEFAULT_MAX_DEFERRALS;\n/** @deprecated Import `DEFAULT_BATCH_SIZE` from `@marktiderman/genesis-supabase/runner`. */\nexport const DEFAULT_BATCH_SIZE: typeof engine.DEFAULT_BATCH_SIZE = engine.DEFAULT_BATCH_SIZE;\n/** @deprecated Import `defaultBackoff` from `@marktiderman/genesis-supabase/runner`. */\nexport const defaultBackoff: typeof engine.defaultBackoff = engine.defaultBackoff;\n/** @deprecated Import `jobOutcome` from `@marktiderman/genesis-supabase/runner`. */\nexport const jobOutcome: typeof engine.jobOutcome = engine.jobOutcome;\n/** @deprecated Import `failureOf` from `@marktiderman/genesis-supabase/runner`. */\nexport const failureOf: typeof engine.failureOf = engine.failureOf;\n/** @deprecated Import `createRunner` from `@marktiderman/genesis-supabase/runner`. */\nexport const createRunner: typeof engine.createRunner = engine.createRunner;\n"]}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as Channel, p as NotificationTypeRow, R as Recipient, l as NotificationRegistry, r as NotifyInput, s as NotifyResult } from './types-ygEEDJSM.js';
|
|
2
|
-
import { RunReport } from '
|
|
2
|
+
import { RunReport } from '@marktiderman/genesis-supabase/runner';
|
|
3
3
|
import { a as EmailTemplate } from './email-render-DsJ1cM5P.js';
|
|
4
4
|
export { b as EmailContent, E as EmailTemplateContext, c as canonicalJson, d as defaultEmailTemplate, e as displayName, f as escapeHtml, h as headerSafe, i as isSafeAddress } from './email-render-DsJ1cM5P.js';
|
|
5
5
|
|
|
@@ -410,7 +410,7 @@ declare const SECRET_LINK_PLACEHOLDER = "https://genesis-secret-link.invalid/";
|
|
|
410
410
|
|
|
411
411
|
/**
|
|
412
412
|
* `createNotificationRunner`: sends what `notify()` queued, on the shared
|
|
413
|
-
*
|
|
413
|
+
* engine (`@marktiderman/genesis-supabase/runner`). Run `run()` every
|
|
414
414
|
* minute and `checkReceipts()` every 15 minutes (pg_cron with pg_net calling
|
|
415
415
|
* the handler, or any scheduler).
|
|
416
416
|
*
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assertNoSecrets, recipientsToJson } from './chunk-7PHA3WVG.js';
|
|
2
|
-
import { createRunner, failureOf } from '
|
|
2
|
+
import { createRunner, failureOf } from '@marktiderman/genesis-supabase/runner';
|
|
3
3
|
|
|
4
4
|
// src/server/store.ts
|
|
5
5
|
var NotificationStoreError = class extends Error {
|