@happyvertical/smrt-webhooks 0.61.3 → 0.61.4

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/dist/admin.js CHANGED
@@ -1,2 +1,2 @@
1
- import { n as webhookAdminView, t as WebhookAdminService } from "./chunks/admin-DogkNqij.js";
1
+ import { n as webhookAdminView, t as WebhookAdminService } from "./chunks/admin-ySI79PC3.js";
2
2
  export { WebhookAdminService, webhookAdminView };
@@ -103,14 +103,16 @@ __publicField(WebhookSubscription, "__smrtPackage__", "@happyvertical/smrt-webho
103
103
  __decorateClass([tenantId()], WebhookSubscription.prototype, "tenantId", 2);
104
104
  __decorateClass([field({
105
105
  type: "text",
106
- required: true
106
+ required: true,
107
+ requiredFor: "system-table"
107
108
  })], WebhookSubscription.prototype, "url", 2);
108
109
  __decorateClass([field({ type: "json" })], WebhookSubscription.prototype, "events", 2);
109
110
  __decorateClass([field({ type: "json" })], WebhookSubscription.prototype, "models", 2);
110
111
  __decorateClass([field({
111
112
  type: "text",
112
113
  sensitive: true,
113
- required: true
114
+ required: true,
115
+ requiredFor: "system-table"
114
116
  })], WebhookSubscription.prototype, "secret", 2);
115
117
  __decorateClass([field({
116
118
  type: "boolean",
@@ -146,7 +148,8 @@ __decorateClass([foreignKey(WebhookSubscription, {
146
148
  })], WebhookDelivery.prototype, "subscriptionId", 2);
147
149
  __decorateClass([field({
148
150
  type: "text",
149
- required: true
151
+ required: true,
152
+ requiredFor: "identity"
150
153
  })], WebhookDelivery.prototype, "eventId", 2);
151
154
  __decorateClass([field({
152
155
  type: "text",
@@ -202,7 +205,7 @@ var WebhookDeliveryCollection = class extends SmrtCollection {
202
205
  };
203
206
  var WebhookDeliveryTask = class extends SmrtObject {
204
207
  async deliver(args = {}, _context) {
205
- const { runWebhookDeliveryJob } = await import("./dispatcher-D0HRqbky.js").then((n) => n.r);
208
+ const { runWebhookDeliveryJob } = await import("./dispatcher-BmwcfQvY.js").then((n) => n.r);
206
209
  await runWebhookDeliveryJob(args);
207
210
  }
208
211
  };
@@ -223,7 +226,8 @@ __publicField(WebhookCursor, "__smrtPackage__", "@happyvertical/smrt-webhooks");
223
226
  __decorateClass([tenantId()], WebhookCursor.prototype, "tenantId", 2);
224
227
  __decorateClass([field({
225
228
  type: "text",
226
- required: true
229
+ required: true,
230
+ requiredFor: "identity"
227
231
  })], WebhookCursor.prototype, "runtime", 2);
228
232
  __decorateClass([field({
229
233
  type: "integer",
@@ -315,4 +319,4 @@ var WebhookAdminService = class {
315
319
  //#endregion
316
320
  export { WebhookDeliveryCollection as a, WebhookSubscriptionCollection as c, isPublicAddress as d, sendPublicWebhook as f, WebhookDelivery as i, assertHmacSecret as l, webhookAdminView as n, WebhookDeliveryTask as o, WebhookCursor as r, WebhookSubscription as s, WebhookAdminService as t, assertWebhookUrl as u };
317
321
 
318
- //# sourceMappingURL=admin-DogkNqij.js.map
322
+ //# sourceMappingURL=admin-ySI79PC3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-ySI79PC3.js","names":[],"sources":["../../src/security.ts","../../src/models.ts","../../src/admin.ts"],"sourcesContent":["import { lookup } from 'node:dns/promises';\nimport { request } from 'node:https';\nimport { isIP } from 'node:net';\n\n/** Conservative public-unicast allowlist. Transition/mapped IPv6 is excluded. */\nexport function isPublicAddress(address: string): boolean {\n if (isIP(address) === 4) {\n const [a, b, c] = address.split('.').map(Number);\n return !(\n a === 0 ||\n a === 10 ||\n a === 127 ||\n a >= 224 ||\n (a === 100 && b >= 64 && b <= 127) ||\n (a === 169 && b === 254) ||\n (a === 172 && b >= 16 && b <= 31) ||\n (a === 192 && (b === 0 || b === 168 || (b === 88 && c === 99))) ||\n (a === 198 && (b === 18 || b === 19 || (b === 51 && c === 100))) ||\n (a === 203 && b === 0 && c === 113)\n );\n }\n if (isIP(address) !== 6) return false;\n const normalized = new URL(`https://[${address}]/`).hostname.slice(1, -1);\n // Only global unicast 2000::/3; exclude IETF special-purpose, documentation,\n // 6to4, and the newer documentation block (3fff::/20).\n const first = Number.parseInt(normalized.split(':')[0], 16);\n return (\n first >= 0x2000 &&\n first < 0x4000 &&\n first !== 0x2002 &&\n !(\n first === 0x2001 &&\n Number.parseInt(normalized.split(':')[1] || '0', 16) < 0x200\n ) &&\n !normalized.startsWith('2001:db8:') &&\n first !== 0x3fff\n );\n}\n\nexport function assertWebhookUrl(value: string): URL {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n throw new Error('Webhook URL must be an absolute HTTPS URL.');\n }\n const host = url.hostname.replace(/^\\[|\\]$/g, '');\n if (\n url.protocol !== 'https:' ||\n url.username ||\n url.password ||\n url.hash ||\n (url.port && url.port !== '443') ||\n host === 'localhost' ||\n host.endsWith('.localhost') ||\n (isIP(host) && !isPublicAddress(host))\n ) {\n throw new Error(\n 'Webhook URL must use public HTTPS on port 443 without credentials or a fragment.',\n );\n }\n return url;\n}\n\nexport function assertHmacSecret(secret: string): void {\n if (\n typeof secret !== 'string' ||\n Buffer.byteLength(secret) < 32 ||\n Buffer.byteLength(secret) > 4096\n ) {\n throw new Error('Webhook signing secret must contain 32 to 4096 bytes.');\n }\n}\n\nexport interface WebhookRequest {\n url: string;\n body: string;\n headers: Record<string, string>;\n}\nexport type WebhookTransport = (request: WebhookRequest) => Promise<number>;\n\n/** Validate every DNS answer, then pin the socket lookup; TLS still verifies the hostname.\n * No proxy, redirects, pooled sockets, response body buffering, or second DNS lookup.\n */\nexport const sendPublicWebhook: WebhookTransport = async ({\n url,\n body,\n headers,\n}) => {\n const target = assertWebhookUrl(url);\n const host = target.hostname.replace(/^\\[|\\]$/g, '');\n let dnsTimer: ReturnType<typeof setTimeout> | undefined;\n const answers = isIP(host)\n ? [{ address: host, family: isIP(host) }]\n : await Promise.race([\n lookup(host, { all: true, verbatim: true }),\n new Promise<never>((_, reject) => {\n dnsTimer = setTimeout(\n () => reject(new Error('Webhook DNS timeout.')),\n 5000,\n );\n dnsTimer.unref();\n }),\n ]).finally(() => clearTimeout(dnsTimer));\n if (\n !answers.length ||\n answers.some(({ address }) => !isPublicAddress(address))\n ) {\n throw new Error('Webhook destination is not public.');\n }\n const pinned = answers[0];\n return new Promise<number>((resolve, reject) => {\n const req = request(\n target,\n {\n method: 'POST',\n agent: false,\n headers: {\n ...headers,\n 'content-length': Buffer.byteLength(body).toString(),\n },\n lookup: (_hostname, options, callback) => {\n if (options.all) callback(null, [pinned]);\n else callback(null, pinned.address, pinned.family);\n },\n },\n (response) => {\n const status = response.statusCode ?? 0;\n response.destroy();\n resolve(status);\n },\n );\n const timer = setTimeout(\n () => req.destroy(new Error('Webhook request timeout.')),\n 10000,\n );\n req.on('close', () => clearTimeout(timer));\n req.on('error', () => reject(new Error('Webhook transport failed.')));\n req.end(body);\n });\n};\n","import {\n field,\n foreignKey,\n SmrtCollection,\n SmrtObject,\n type SmrtSaveOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n backgroundEligible,\n type JobExecutionContext,\n} from '@happyvertical/smrt-jobs';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport { assertHmacSecret, assertWebhookUrl } from './security.js';\n\n/** Server-only subscription. Hosts authorize administration before accessing it. */\n@smrt({\n tableName: '_smrt_webhook_subscriptions',\n api: false,\n cli: false,\n mcp: false,\n})\n@TenantScoped({ mode: 'required' })\nexport class WebhookSubscription extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @tenantId() tenantId: string = '';\n @field({ type: 'text', required: true, requiredFor: 'system-table' })\n url: string = '';\n @field({ type: 'json' }) events: string[] = [];\n @field({ type: 'json' }) models: string[] = [];\n @field({\n type: 'text',\n sensitive: true,\n required: true,\n requiredFor: 'system-table',\n })\n secret: string = '';\n @field({ type: 'boolean', default: true }) enabled: boolean = true;\n\n override async save(options?: SmrtSaveOptions): Promise<this> {\n assertWebhookUrl(this.url);\n assertHmacSecret(this.secret);\n for (const values of [this.events, this.models]) {\n if (\n !Array.isArray(values) ||\n values.length > 100 ||\n values.some((v) => typeof v !== 'string' || !v || v.length > 200)\n ) {\n throw new Error('Webhook filters must be lists of nonempty names.');\n }\n }\n return super.save(options);\n }\n}\nexport class WebhookSubscriptionCollection extends SmrtCollection<WebhookSubscription> {\n static readonly _itemClass = WebhookSubscription;\n}\n\n/** Durable outbox and safe outcome metadata; payload never appears in public projections. */\n@smrt({\n tableName: '_smrt_webhook_deliveries',\n api: false,\n cli: false,\n mcp: false,\n indexes: [\n {\n name: '_smrt_webhook_delivery_identity',\n columns: ['tenantId', 'subscriptionId', 'eventId'],\n unique: true,\n },\n ],\n})\n@TenantScoped({ mode: 'required' })\nexport class WebhookDelivery extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @tenantId() tenantId: string = '';\n @foreignKey(WebhookSubscription, {\n onUpdate: 'RESTRICT',\n onDelete: 'RESTRICT',\n })\n subscriptionId: string = '';\n @field({ type: 'text', required: true, requiredFor: 'identity' })\n eventId: string = '';\n @field({ type: 'text', required: true, sensitive: true }) payload: string =\n '';\n @field({ type: 'text', default: 'pending' }) status: string = 'pending';\n @field({ type: 'integer', default: 0 }) generation: number = 0;\n @field({ type: 'integer', default: 0 }) attempts: number = 0;\n @field({ type: 'integer', nullable: true }) responseStatus: number | null =\n null;\n @field({ type: 'text', nullable: true }) error: string | null = null;\n @field({ type: 'text', nullable: true, sensitive: true }) leaseToken:\n | string\n | null = null;\n @field({ type: 'datetime', nullable: true }) leaseUntil: Date | null = null;\n}\nexport class WebhookDeliveryCollection extends SmrtCollection<WebhookDelivery> {\n static readonly _itemClass = WebhookDelivery;\n}\n\n/** Jobs queue entry point; persisted arguments contain IDs only. */\n@smrt({\n tableName: '_smrt_webhook_delivery_tasks',\n api: false,\n cli: false,\n mcp: false,\n})\nexport class WebhookDeliveryTask extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @backgroundEligible()\n async deliver(\n args: Record<string, unknown> = {},\n _context?: JobExecutionContext,\n ): Promise<void> {\n const { runWebhookDeliveryJob } = await import('./dispatcher.js');\n await runWebhookDeliveryJob(args);\n }\n}\n\n/** Tenant-bound durable cursor for replayable model change-feed publication. */\n@smrt({\n tableName: '_smrt_webhook_cursors',\n api: false,\n cli: false,\n mcp: false,\n indexes: [\n {\n name: '_smrt_webhook_cursor_identity',\n columns: ['tenantId', 'runtime'],\n unique: true,\n },\n ],\n})\n@TenantScoped({ mode: 'required' })\nexport class WebhookCursor extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @tenantId() tenantId: string = '';\n @field({ type: 'text', required: true, requiredFor: 'identity' })\n runtime: string = '';\n @field({ type: 'integer', default: 0 }) position: number = 0;\n}\n","import { requireTenant } from '@happyvertical/smrt-tenancy';\nimport { WebhookSubscriptionCollection } from './models.js';\nimport type { WebhookStore } from './store.js';\nimport type {\n WebhookDeliveryRecord,\n WebhookSubscriptionRecord,\n} from './types.js';\nexport interface WebhookAdminView {\n subscriptions: WebhookSubscriptionRecord[];\n deliveries: WebhookDeliveryRecord[];\n}\n/** Allowlisted projection; never spread persistence objects into a browser response. */\nexport function webhookAdminView(\n subscriptions: WebhookSubscriptionRecord[],\n deliveries: WebhookDeliveryRecord[],\n): WebhookAdminView {\n return {\n subscriptions: subscriptions.map((s) => ({\n id: s.id,\n tenantId: s.tenantId,\n url: s.url,\n models: s.models,\n events: s.events,\n enabled: s.enabled,\n })),\n deliveries: deliveries.map((d) => ({\n id: d.id,\n tenantId: d.tenantId,\n subscriptionId: d.subscriptionId,\n eventId: d.eventId,\n status: d.status,\n attempts: d.attempts,\n responseStatus: d.responseStatus,\n error: d.error,\n })),\n };\n}\n/** Host supplies its administrator permission check and authenticated tenant context. */\nexport class WebhookAdminService {\n constructor(\n private readonly store: WebhookStore,\n private readonly authorize: () => Promise<boolean>,\n ) {}\n private async guard() {\n requireTenant();\n if (!(await this.authorize()))\n throw new Error('Webhook administration forbidden.');\n }\n async view(): Promise<WebhookAdminView> {\n await this.guard();\n await this.store.reconcile();\n const subscriptions = await this.store.subscriptions();\n const deliveries = await this.store.deliveries();\n return webhookAdminView(\n subscriptions.map((s) => ({ ...s, id: s.id ?? '' })),\n deliveries.map((d) => ({ ...d, id: d.id ?? '' })),\n );\n }\n async create(input: {\n url: string;\n events: string[];\n models: string[];\n secret: string;\n }): Promise<void> {\n await this.guard();\n const collection = await WebhookSubscriptionCollection.create({\n db: this.store.db,\n });\n const sub = await collection.create({\n tenantId: requireTenant().tenantId,\n url: input.url,\n events: input.events,\n models: input.models,\n secret: input.secret,\n enabled: true,\n });\n await sub.save();\n }\n async toggle(id: string, enabled: boolean): Promise<void> {\n await this.guard();\n if (typeof enabled !== 'boolean') throw new Error('Invalid enabled value.');\n const sub = await this.store.subscription(id);\n if (!sub) throw new Error('Webhook subscription not found.');\n sub.enabled = enabled;\n await sub.save();\n }\n async replay(id: string): Promise<boolean> {\n await this.guard();\n return this.store.replay(id);\n }\n}\n"],"mappings":";;;;;;;AAKO,SAAS,gBAAgB,SAA0B;CACxD,IAAI,KAAK,OAAO,MAAM,GAAG;EACvB,MAAM,CAAC,GAAG,GAAG,KAAK,QAAQ,MAAM,GAAG,CAAA,CAAE,IAAI,MAAM;EAC/C,OAAO,EACL,MAAM,KACN,MAAM,MACN,MAAM,OACN,KAAK,OACJ,MAAM,OAAO,KAAK,MAAM,KAAK,OAC7B,MAAM,OAAO,MAAM,OACnB,MAAM,OAAO,KAAK,MAAM,KAAK,MAC7B,MAAM,QAAQ,MAAM,KAAK,MAAM,OAAQ,MAAM,MAAM,MAAM,OACzD,MAAM,QAAQ,MAAM,MAAM,MAAM,MAAO,MAAM,MAAM,MAAM,QACzD,MAAM,OAAO,MAAM,KAAK,MAAM;CAEnC;CACA,IAAI,KAAK,OAAO,MAAM,GAAG,OAAO;CAChC,MAAM,aAAa,IAAI,IAAI,YAAY,QAAO,GAAI,CAAA,CAAE,SAAS,MAAM,GAAG,EAAE;CAGxE,MAAM,QAAQ,OAAO,SAAS,WAAW,MAAM,GAAG,CAAA,CAAE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M,IAAI,KAAK;CACjB;CACA,MAAM,OAAO,IAA8B;EACzC,MAAM,KAAK,MAAM;EACjB,OAAO,KAAK,MAAM,OAAO,EAAE;CAC7B;AACF"}
@@ -1,4 +1,4 @@
1
- import { a as WebhookDeliveryCollection, c as WebhookSubscriptionCollection, f as sendPublicWebhook, l as assertHmacSecret } from "./admin-DogkNqij.js";
1
+ import { a as WebhookDeliveryCollection, c as WebhookSubscriptionCollection, f as sendPublicWebhook, l as assertHmacSecret } from "./admin-ySI79PC3.js";
2
2
  import { requireTenant } from "@happyvertical/smrt-tenancy";
3
3
  import { SmrtJobCollection } from "@happyvertical/smrt-jobs";
4
4
  import { createHmac, randomUUID, timingSafeEqual } from "node:crypto";
@@ -281,4 +281,4 @@ async function runWebhookDeliveryJob(args) {
281
281
  //#endregion
282
282
  export { runWebhookDeliveryJob as a, DEFAULT_WEBHOOK_TOLERANCE_MS as c, registerWebhookRuntime as i, signWebhookPayload as l, assertWebhookEvent as n, unregisterWebhookRuntime as o, dispatcher_exports as r, WebhookStore as s, WebhookDispatcher as t, verifyWebhookSignature as u };
283
283
 
284
- //# sourceMappingURL=dispatcher-D0HRqbky.js.map
284
+ //# sourceMappingURL=dispatcher-BmwcfQvY.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher-D0HRqbky.js","names":[],"sources":["../../src/signing.ts","../../src/store.ts","../../src/dispatcher.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto';\n\n/** Default replay window: reject timestamps older or newer than five minutes. */\nexport const DEFAULT_WEBHOOK_TOLERANCE_MS = 5 * 60 * 1000;\n\n/** Exact format the dispatcher emits (`Date#toISOString`); blocks `.`-split ambiguity. */\nconst TIMESTAMP_FORMAT = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\n\n/** Signature header value for `timestamp` (the exact `x-smrt-timestamp` string) and body. */\nexport function signWebhookPayload(\n secret: string,\n timestamp: string,\n body: string | Uint8Array,\n): string {\n // Hash the bytes exactly as received; never decode bytes to a string first.\n const hmac = createHmac('sha256', secret).update(`${timestamp}.`);\n hmac.update(typeof body === 'string' ? Buffer.from(body, 'utf8') : body);\n return `sha256=${hmac.digest('hex')}`;\n}\n\nexport interface VerifyWebhookOptions {\n /** Shared signing secret, or several during rotation; any match passes. */\n secret: string | readonly string[];\n /** Exact raw request body (UTF-8 string or bytes). Never a re-serialized object. */\n body: string | Uint8Array;\n /** `x-smrt-timestamp` header value (`YYYY-MM-DDTHH:mm:ss.sssZ`, as sent). */\n timestamp: string | null | undefined;\n /** `x-smrt-signature` header value (`sha256=<hex>`). */\n signature: string | null | undefined;\n /** Maximum accepted clock skew/age in ms (default 5 minutes). */\n toleranceMs?: number;\n /** Injectable clock for tests. */\n now?: Date;\n}\n\nexport type VerifyWebhookResult =\n | { ok: true }\n | { ok: false; reason: 'malformed' | 'expired' | 'mismatch' };\n\n/**\n * Verify a delivery (the sender signs with a single secret; the receiver may\n * hold several during rotation) in constant time with replay protection. Callers must\n * still deduplicate the `x-smrt-delivery` id (at-least-once delivery).\n */\nexport function verifyWebhookSignature(\n options: VerifyWebhookOptions,\n): VerifyWebhookResult {\n const { timestamp, signature } = options ?? ({} as VerifyWebhookOptions);\n const body: unknown = options?.body;\n const given: unknown = options?.secret;\n const secrets: unknown[] =\n typeof given === 'string'\n ? [given]\n : Array.isArray(given)\n ? [...given]\n : [];\n if (\n typeof timestamp !== 'string' ||\n typeof signature !== 'string' ||\n (typeof body !== 'string' && !(body instanceof Uint8Array)) ||\n !secrets.length ||\n secrets.some((s) => typeof s !== 'string' || !s) ||\n !/^sha256=[0-9a-f]{64}$/.test(signature) ||\n !TIMESTAMP_FORMAT.test(timestamp)\n )\n return { ok: false, reason: 'malformed' };\n const sent = Date.parse(timestamp);\n const tolerance = options.toleranceMs ?? DEFAULT_WEBHOOK_TOLERANCE_MS;\n const nowMs = (options.now ?? new Date()).getTime();\n if (\n !Number.isFinite(sent) ||\n !Number.isFinite(tolerance) ||\n tolerance < 0 ||\n !Number.isFinite(nowMs)\n )\n return { ok: false, reason: 'malformed' };\n if (Math.abs(nowMs - sent) > tolerance)\n return { ok: false, reason: 'expired' };\n const received = Buffer.from(signature);\n let matched = false;\n for (const secret of secrets) {\n const expected = Buffer.from(\n signWebhookPayload(\n secret as string,\n timestamp,\n body as string | Uint8Array,\n ),\n );\n if (timingSafeEqual(expected, received)) matched = true;\n }\n return matched ? { ok: true } : { ok: false, reason: 'mismatch' };\n}\n","import { randomUUID } from 'node:crypto';\nimport { SmrtJobCollection } from '@happyvertical/smrt-jobs';\nimport { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport {\n WebhookDeliveryCollection,\n type WebhookSubscription,\n WebhookSubscriptionCollection,\n} from './models.js';\nimport type { WebhookEventEnvelope } from './types.js';\n\n/** Explicit tenant predicates also protect deployments that have not enabled interceptors. */\nexport class WebhookStore {\n constructor(\n readonly db: DatabaseInterface,\n readonly runtime: string,\n ) {\n if (!runtime) throw new Error('Webhook runtime is required.');\n }\n async subscriptions() {\n const tenantId = requireTenant().tenantId;\n const collection = await WebhookSubscriptionCollection.create({\n db: this.db,\n });\n const result: WebhookSubscription[] = [];\n for (let offset = 0; ; offset += 1000) {\n const page = await collection.list({\n where: { tenantId },\n orderBy: 'id ASC',\n limit: 1000,\n offset,\n });\n result.push(...page);\n if (page.length < 1000) return result;\n }\n }\n async subscription(id: string) {\n const tenantId = requireTenant().tenantId;\n return (await WebhookSubscriptionCollection.create({ db: this.db })).get({\n id,\n tenantId,\n });\n }\n async delivery(id: string) {\n const tenantId = requireTenant().tenantId;\n return (await WebhookDeliveryCollection.create({ db: this.db })).get({\n id,\n tenantId,\n });\n }\n async deliveries() {\n const tenantId = requireTenant().tenantId;\n return (await WebhookDeliveryCollection.create({ db: this.db })).list({\n where: { tenantId },\n orderBy: 'created_at DESC',\n limit: 100,\n });\n }\n\n /** The unique outbox identity and jobs enqueue commit or roll back together. */\n async accept(\n subscriptionId: string,\n event: WebhookEventEnvelope,\n ): Promise<string> {\n const tenantId = requireTenant().tenantId;\n if (!(await this.subscription(subscriptionId)))\n throw new Error('Webhook subscription not found.');\n if (!this.db.transaction)\n throw new Error('Webhooks require a transactional database.');\n return this.db.transaction(async (tx) => {\n const id = randomUUID();\n const now = new Date().toISOString();\n const inserted = await tx.query(\n `INSERT INTO _smrt_webhook_deliveries\n (id, slug, context, tenant_id, subscription_id, event_id, payload, status, attempts, generation, created_at, updated_at)\n VALUES (?, ?, '', ?, ?, ?, ?, 'pending', 0, 0, ?, ?)\n ON CONFLICT (tenant_id, subscription_id, event_id) DO NOTHING RETURNING id`,\n id,\n id,\n tenantId,\n subscriptionId,\n event.id,\n JSON.stringify(event),\n now,\n now,\n );\n if (inserted.rows.length) {\n await this.enqueue(tx, tenantId, id);\n return id;\n }\n const existing = await tx.query(\n 'SELECT CAST(id AS VARCHAR) AS id FROM _smrt_webhook_deliveries WHERE tenant_id = ? AND subscription_id = ? AND event_id = ?',\n tenantId,\n subscriptionId,\n event.id,\n );\n return (existing.rows[0] as { id: string }).id;\n });\n }\n private async enqueue(\n db: DatabaseInterface,\n tenantId: string,\n deliveryId: string,\n generation = 0,\n ) {\n const jobs = await SmrtJobCollection.create({ db });\n await jobs.enqueueJob({\n tenantId,\n queue: 'webhooks',\n objectType: '@happyvertical/smrt-webhooks:WebhookDeliveryTask',\n objectId: null,\n method: 'deliver',\n args: { runtime: this.runtime, tenantId, deliveryId, generation },\n maxAttempts: 5,\n timeout: 30000,\n retryStrategy: {\n type: 'exponential',\n config: { initialDelay: 1000, multiplier: 2, maxDelay: 300000 },\n },\n });\n }\n /** A bounded lease prevents overlapping jobs; expired leases recover after process death. */\n async claim(id: string, generation = 0): Promise<string | null> {\n const tenantId = requireTenant().tenantId;\n const token = randomUUID();\n const now = new Date();\n const result = await this.db.query(\n `UPDATE _smrt_webhook_deliveries SET lease_token = ?, lease_until = ?, attempts = attempts + 1\n WHERE id = ? AND tenant_id = ? AND generation = ? AND status IN ('pending', 'retrying')\n AND (lease_until IS NULL OR lease_until <= ?) RETURNING id`,\n token,\n new Date(now.getTime() + 20000).toISOString(),\n id,\n tenantId,\n generation,\n now.toISOString(),\n );\n return result.rows.length ? token : null;\n }\n async finish(\n id: string,\n token: string,\n status: string,\n responseStatus: number | null,\n error: string | null,\n ) {\n const tenantId = requireTenant().tenantId;\n const result = await this.db.query(\n `UPDATE _smrt_webhook_deliveries SET status = ?, response_status = ?, error = ?, lease_token = NULL, lease_until = NULL, updated_at = ?\n WHERE id = ? AND tenant_id = ? AND lease_token = ? RETURNING id`,\n status,\n responseStatus,\n error,\n new Date().toISOString(),\n id,\n tenantId,\n token,\n );\n if (!result.rows.length) throw new Error('Webhook delivery lease lost.');\n }\n /** Reconcile exhausted/cancelled jobs, including process death before an attempt starts.\n * Tenant-scoped and lease-aware; safe to call on each admin refresh or operator sweep.\n */\n async reconcile(): Promise<void> {\n const tenantId = requireTenant().tenantId;\n const jobs = await SmrtJobCollection.create({ db: this.db });\n for (let offset = 0; ; offset += 1000) {\n const terminal = await jobs.list({\n where: { tenantId, queue: 'webhooks', status: ['failed', 'cancelled'] },\n orderBy: 'id ASC',\n limit: 1000,\n offset,\n });\n for (const job of terminal) {\n if (\n job.args.runtime !== this.runtime ||\n typeof job.args.deliveryId !== 'string'\n )\n continue;\n await this.db.query(\n `UPDATE _smrt_webhook_deliveries SET status = 'failed', error = 'Webhook job exhausted.', lease_token = NULL, lease_until = NULL\n WHERE id = ? AND tenant_id = ? AND generation = ? AND status IN ('pending', 'retrying') AND (lease_until IS NULL OR lease_until <= ?)`,\n job.args.deliveryId,\n tenantId,\n job.args.generation ?? 0,\n new Date().toISOString(),\n );\n }\n if (terminal.length < 1000) return;\n }\n }\n\n /** Explicit operator recovery for exhausted jobs. Repeated/concurrent replay is a no-op. */\n async replay(id: string): Promise<boolean> {\n const tenantId = requireTenant().tenantId;\n if (!this.db.transaction)\n throw new Error('Webhooks require a transactional database.');\n return this.db.transaction(async (tx) => {\n const changed = await tx.query(\n `UPDATE _smrt_webhook_deliveries SET status = 'pending', attempts = 0, generation = generation + 1, error = NULL, lease_token = NULL, lease_until = NULL\n WHERE id = ? AND tenant_id = ? AND status = 'failed' RETURNING generation`,\n id,\n tenantId,\n );\n if (!changed.rows.length) return false;\n await this.enqueue(\n tx,\n tenantId,\n id,\n Number((changed.rows[0] as { generation: number }).generation),\n );\n return true;\n });\n }\n}\n","import { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport {\n assertHmacSecret,\n sendPublicWebhook,\n type WebhookTransport,\n} from './security.js';\nimport { signWebhookPayload } from './signing.js';\nimport { WebhookStore } from './store.js';\nimport type { WebhookEventEnvelope } from './types.js';\n\nexport interface WebhookDispatcherOptions {\n db: DatabaseInterface;\n runtime: string;\n /** Trusted server integration seam. Default transport pins validated public DNS answers. */\n transport?: WebhookTransport;\n}\nconst runtimes = new Map<string, WebhookDispatcher>();\nexport function registerWebhookRuntime(\n name: string,\n dispatcher: WebhookDispatcher,\n): void {\n if (!name || runtimes.has(name))\n throw new Error('Webhook runtime already registered or invalid.');\n runtimes.set(name, dispatcher);\n}\nexport function unregisterWebhookRuntime(name: string): void {\n runtimes.delete(name);\n}\n\nexport function assertWebhookEvent(event: WebhookEventEnvelope): void {\n if (\n !event ||\n typeof event !== 'object' ||\n !event.data ||\n Array.isArray(event.data) ||\n typeof event.data !== 'object' ||\n [event.id, event.event, event.model].some(\n (v) => typeof v !== 'string' || !v || v.length > 200 || /[\\r\\n]/.test(v),\n ) ||\n typeof event.occurredAt !== 'string' ||\n !Number.isFinite(Date.parse(event.occurredAt)) ||\n Buffer.byteLength(JSON.stringify(event)) > 262144\n )\n throw new Error('Invalid webhook event.');\n}\n\n/** Durable tenant-scoped outbound events. Receivers deduplicate x-smrt-delivery. */\nexport class WebhookDispatcher {\n readonly store: WebhookStore;\n private readonly transport: WebhookTransport;\n constructor(options: WebhookDispatcherOptions) {\n this.store = new WebhookStore(options.db, options.runtime);\n this.transport = options.transport ?? sendPublicWebhook;\n }\n async dispatch(event: WebhookEventEnvelope): Promise<string[]> {\n requireTenant();\n assertWebhookEvent(event);\n const ids: string[] = [];\n for (const sub of await this.store.subscriptions()) {\n if (\n sub.enabled &&\n (!sub.events.length || sub.events.includes(event.event)) &&\n (!sub.models.length || sub.models.includes(event.model))\n ) {\n ids.push(await this.store.accept(sub.id ?? '', event));\n }\n }\n return ids;\n }\n async deliver(\n deliveryId: string,\n expectedGeneration?: number,\n ): Promise<void> {\n requireTenant();\n const before = await this.store.delivery(deliveryId);\n if (\n !before ||\n (expectedGeneration !== undefined &&\n before.generation !== expectedGeneration) ||\n ['delivered', 'failed', 'cancelled'].includes(before.status)\n )\n return;\n const token = await this.store.claim(deliveryId, before.generation);\n if (!token) throw new Error('Webhook delivery is already leased.');\n const delivery = await this.store.delivery(deliveryId);\n if (!delivery) throw new Error('Webhook delivery unavailable.');\n let responseStatus: number | null = null;\n try {\n const sub = await this.store.subscription(delivery.subscriptionId);\n if (!sub?.enabled) {\n await this.store.finish(\n deliveryId,\n token,\n 'cancelled',\n null,\n 'Subscription disabled.',\n );\n return;\n }\n assertHmacSecret(sub.secret);\n const event = JSON.parse(delivery.payload) as WebhookEventEnvelope;\n assertWebhookEvent(event);\n const timestamp = new Date().toISOString();\n responseStatus = await this.transport({\n url: sub.url,\n body: delivery.payload,\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'smrt-webhooks/1',\n 'x-smrt-event': event.event,\n 'x-smrt-delivery': deliveryId,\n 'x-smrt-timestamp': timestamp,\n 'x-smrt-signature': signWebhookPayload(\n sub.secret,\n timestamp,\n delivery.payload,\n ),\n },\n });\n if (responseStatus < 200 || responseStatus >= 300)\n throw new Error('Webhook rejected.');\n await this.store.finish(\n deliveryId,\n token,\n 'delivered',\n responseStatus,\n null,\n );\n } catch {\n // Never persist/rethrow endpoint errors: URLs, response bodies and secrets may be embedded.\n await this.store.finish(\n deliveryId,\n token,\n delivery.attempts >= 5 ? 'failed' : 'retrying',\n responseStatus,\n 'Webhook delivery failed.',\n );\n throw new Error('Webhook delivery failed.');\n }\n }\n}\nexport async function runWebhookDeliveryJob(\n args: Record<string, unknown>,\n): Promise<void> {\n const runtime =\n typeof args.runtime === 'string' ? runtimes.get(args.runtime) : undefined;\n if (\n !runtime ||\n typeof args.deliveryId !== 'string' ||\n args.tenantId !== requireTenant().tenantId\n ) {\n throw new Error('Invalid webhook job or unavailable runtime.');\n }\n await runtime.deliver(\n args.deliveryId,\n typeof args.generation === 'number' ? args.generation : 0,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGO,IAAM,+BAA+B,MAAS;AAGrD,IAAM,mBAAmB;AAGlB,SAAS,mBACd,QACA,WACA,MACQ;CAER,MAAM,OAAO,WAAW,UAAU,MAAM,CAAA,CAAE,OAAO,GAAG,UAAS,EAAG;CAChE,KAAK,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK,MAAM,MAAM,IAAI,IAAI;CACvE,OAAO,UAAU,KAAK,OAAO,KAAK;AACpC;AA0BO,SAAS,uBACd,SACqB;CACrB,MAAM,EAAE,WAAW,cAAc,WAAY,CAAC;CAC9C,MAAM,OAAgB,SAAS;CAC/B,MAAM,QAAiB,SAAS;CAChC,MAAM,UACJ,OAAO,UAAU,WACb,CAAC,KAAK,IACN,MAAM,QAAQ,KAAK,IACjB,CAAC,GAAG,KAAK,IACT,CAAC;CACT,IACE,OAAO,cAAc,YACrB,OAAO,cAAc,YACpB,OAAO,SAAS,YAAY,EAAE,gBAAgB,eAC/C,CAAC,QAAQ,UACT,QAAQ,MAAM,MAAM,OAAO,MAAM,YAAY,CAAC,CAAC,KAC/C,CAAC,wBAAwB,KAAK,SAAS,KACvC,CAAC,iBAAiB,KAAK,SAAS,GAEhC,OAAO;EAAE,IAAI;EAAO,QAAQ;CAAY;CAC1C,MAAM,OAAO,KAAK,MAAM,SAAS;CACjC,MAAM,YAAY,Q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ACtB,mBAAmB;KACnB,oBAAoB;KACpB,oBAAoB,mBAClB,IAAI,QACJ,WACA,SAAS,OACX;IACF;GACF,CAAC;GACD,IAAI,iBAAiB,OAAO,kBAAkB,KAC5C,MAAM,IAAI,MAAM,mBAAmB;GACrC,MAAM,KAAK,MAAM,OACf,YACA,OACA,aACA,gBACA,IACF;EACF,QAAQ;GAEN,MAAM,KAAK,MAAM,OACf,YACA,OACA,SAAS,YAAY,IAAI,WAAW,YACpC,gBACA,0BACF;GACA,MAAM,IAAI,MAAM,0BAA0B;EAC5C;CACF;AACF;AACA,eAAsB,sBACpB,MACe;CACf,MAAM,UACJ,OAAO,KAAK,YAAY,WAAW,SAAS,IAAI,KAAK,OAAO,IAAI,KAAA;CAClE,IACE,CAAC,WACD,OAAO,KAAK,eAAe,YAC3B,KAAK,aAAa,cAAc,CAAA,CAAE,UAElC,MAAM,IAAI,MAAM,6CAA6C;CAE/D,MAAM,QAAQ,QACZ,KAAK,YACL,OAAO,KAAK,eAAe,WAAW,KAAK,aAAa,CAC1D;AACF"}
1
+ {"version":3,"file":"dispatcher-BmwcfQvY.js","names":[],"sources":["../../src/signing.ts","../../src/store.ts","../../src/dispatcher.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from 'node:crypto';\n\n/** Default replay window: reject timestamps older or newer than five minutes. */\nexport const DEFAULT_WEBHOOK_TOLERANCE_MS = 5 * 60 * 1000;\n\n/** Exact format the dispatcher emits (`Date#toISOString`); blocks `.`-split ambiguity. */\nconst TIMESTAMP_FORMAT = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\n\n/** Signature header value for `timestamp` (the exact `x-smrt-timestamp` string) and body. */\nexport function signWebhookPayload(\n secret: string,\n timestamp: string,\n body: string | Uint8Array,\n): string {\n // Hash the bytes exactly as received; never decode bytes to a string first.\n const hmac = createHmac('sha256', secret).update(`${timestamp}.`);\n hmac.update(typeof body === 'string' ? Buffer.from(body, 'utf8') : body);\n return `sha256=${hmac.digest('hex')}`;\n}\n\nexport interface VerifyWebhookOptions {\n /** Shared signing secret, or several during rotation; any match passes. */\n secret: string | readonly string[];\n /** Exact raw request body (UTF-8 string or bytes). Never a re-serialized object. */\n body: string | Uint8Array;\n /** `x-smrt-timestamp` header value (`YYYY-MM-DDTHH:mm:ss.sssZ`, as sent). */\n timestamp: string | null | undefined;\n /** `x-smrt-signature` header value (`sha256=<hex>`). */\n signature: string | null | undefined;\n /** Maximum accepted clock skew/age in ms (default 5 minutes). */\n toleranceMs?: number;\n /** Injectable clock for tests. */\n now?: Date;\n}\n\nexport type VerifyWebhookResult =\n | { ok: true }\n | { ok: false; reason: 'malformed' | 'expired' | 'mismatch' };\n\n/**\n * Verify a delivery (the sender signs with a single secret; the receiver may\n * hold several during rotation) in constant time with replay protection. Callers must\n * still deduplicate the `x-smrt-delivery` id (at-least-once delivery).\n */\nexport function verifyWebhookSignature(\n options: VerifyWebhookOptions,\n): VerifyWebhookResult {\n const { timestamp, signature } = options ?? ({} as VerifyWebhookOptions);\n const body: unknown = options?.body;\n const given: unknown = options?.secret;\n const secrets: unknown[] =\n typeof given === 'string'\n ? [given]\n : Array.isArray(given)\n ? [...given]\n : [];\n if (\n typeof timestamp !== 'string' ||\n typeof signature !== 'string' ||\n (typeof body !== 'string' && !(body instanceof Uint8Array)) ||\n !secrets.length ||\n secrets.some((s) => typeof s !== 'string' || !s) ||\n !/^sha256=[0-9a-f]{64}$/.test(signature) ||\n !TIMESTAMP_FORMAT.test(timestamp)\n )\n return { ok: false, reason: 'malformed' };\n const sent = Date.parse(timestamp);\n const tolerance = options.toleranceMs ?? DEFAULT_WEBHOOK_TOLERANCE_MS;\n const nowMs = (options.now ?? new Date()).getTime();\n if (\n !Number.isFinite(sent) ||\n !Number.isFinite(tolerance) ||\n tolerance < 0 ||\n !Number.isFinite(nowMs)\n )\n return { ok: false, reason: 'malformed' };\n if (Math.abs(nowMs - sent) > tolerance)\n return { ok: false, reason: 'expired' };\n const received = Buffer.from(signature);\n let matched = false;\n for (const secret of secrets) {\n const expected = Buffer.from(\n signWebhookPayload(\n secret as string,\n timestamp,\n body as string | Uint8Array,\n ),\n );\n if (timingSafeEqual(expected, received)) matched = true;\n }\n return matched ? { ok: true } : { ok: false, reason: 'mismatch' };\n}\n","import { randomUUID } from 'node:crypto';\nimport { SmrtJobCollection } from '@happyvertical/smrt-jobs';\nimport { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport {\n WebhookDeliveryCollection,\n type WebhookSubscription,\n WebhookSubscriptionCollection,\n} from './models.js';\nimport type { WebhookEventEnvelope } from './types.js';\n\n/** Explicit tenant predicates also protect deployments that have not enabled interceptors. */\nexport class WebhookStore {\n constructor(\n readonly db: DatabaseInterface,\n readonly runtime: string,\n ) {\n if (!runtime) throw new Error('Webhook runtime is required.');\n }\n async subscriptions() {\n const tenantId = requireTenant().tenantId;\n const collection = await WebhookSubscriptionCollection.create({\n db: this.db,\n });\n const result: WebhookSubscription[] = [];\n for (let offset = 0; ; offset += 1000) {\n const page = await collection.list({\n where: { tenantId },\n orderBy: 'id ASC',\n limit: 1000,\n offset,\n });\n result.push(...page);\n if (page.length < 1000) return result;\n }\n }\n async subscription(id: string) {\n const tenantId = requireTenant().tenantId;\n return (await WebhookSubscriptionCollection.create({ db: this.db })).get({\n id,\n tenantId,\n });\n }\n async delivery(id: string) {\n const tenantId = requireTenant().tenantId;\n return (await WebhookDeliveryCollection.create({ db: this.db })).get({\n id,\n tenantId,\n });\n }\n async deliveries() {\n const tenantId = requireTenant().tenantId;\n return (await WebhookDeliveryCollection.create({ db: this.db })).list({\n where: { tenantId },\n orderBy: 'created_at DESC',\n limit: 100,\n });\n }\n\n /** The unique outbox identity and jobs enqueue commit or roll back together. */\n async accept(\n subscriptionId: string,\n event: WebhookEventEnvelope,\n ): Promise<string> {\n const tenantId = requireTenant().tenantId;\n if (!(await this.subscription(subscriptionId)))\n throw new Error('Webhook subscription not found.');\n if (!this.db.transaction)\n throw new Error('Webhooks require a transactional database.');\n return this.db.transaction(async (tx) => {\n const id = randomUUID();\n const now = new Date().toISOString();\n const inserted = await tx.query(\n `INSERT INTO _smrt_webhook_deliveries\n (id, slug, context, tenant_id, subscription_id, event_id, payload, status, attempts, generation, created_at, updated_at)\n VALUES (?, ?, '', ?, ?, ?, ?, 'pending', 0, 0, ?, ?)\n ON CONFLICT (tenant_id, subscription_id, event_id) DO NOTHING RETURNING id`,\n id,\n id,\n tenantId,\n subscriptionId,\n event.id,\n JSON.stringify(event),\n now,\n now,\n );\n if (inserted.rows.length) {\n await this.enqueue(tx, tenantId, id);\n return id;\n }\n const existing = await tx.query(\n 'SELECT CAST(id AS VARCHAR) AS id FROM _smrt_webhook_deliveries WHERE tenant_id = ? AND subscription_id = ? AND event_id = ?',\n tenantId,\n subscriptionId,\n event.id,\n );\n return (existing.rows[0] as { id: string }).id;\n });\n }\n private async enqueue(\n db: DatabaseInterface,\n tenantId: string,\n deliveryId: string,\n generation = 0,\n ) {\n const jobs = await SmrtJobCollection.create({ db });\n await jobs.enqueueJob({\n tenantId,\n queue: 'webhooks',\n objectType: '@happyvertical/smrt-webhooks:WebhookDeliveryTask',\n objectId: null,\n method: 'deliver',\n args: { runtime: this.runtime, tenantId, deliveryId, generation },\n maxAttempts: 5,\n timeout: 30000,\n retryStrategy: {\n type: 'exponential',\n config: { initialDelay: 1000, multiplier: 2, maxDelay: 300000 },\n },\n });\n }\n /** A bounded lease prevents overlapping jobs; expired leases recover after process death. */\n async claim(id: string, generation = 0): Promise<string | null> {\n const tenantId = requireTenant().tenantId;\n const token = randomUUID();\n const now = new Date();\n const result = await this.db.query(\n `UPDATE _smrt_webhook_deliveries SET lease_token = ?, lease_until = ?, attempts = attempts + 1\n WHERE id = ? AND tenant_id = ? AND generation = ? AND status IN ('pending', 'retrying')\n AND (lease_until IS NULL OR lease_until <= ?) RETURNING id`,\n token,\n new Date(now.getTime() + 20000).toISOString(),\n id,\n tenantId,\n generation,\n now.toISOString(),\n );\n return result.rows.length ? token : null;\n }\n async finish(\n id: string,\n token: string,\n status: string,\n responseStatus: number | null,\n error: string | null,\n ) {\n const tenantId = requireTenant().tenantId;\n const result = await this.db.query(\n `UPDATE _smrt_webhook_deliveries SET status = ?, response_status = ?, error = ?, lease_token = NULL, lease_until = NULL, updated_at = ?\n WHERE id = ? AND tenant_id = ? AND lease_token = ? RETURNING id`,\n status,\n responseStatus,\n error,\n new Date().toISOString(),\n id,\n tenantId,\n token,\n );\n if (!result.rows.length) throw new Error('Webhook delivery lease lost.');\n }\n /** Reconcile exhausted/cancelled jobs, including process death before an attempt starts.\n * Tenant-scoped and lease-aware; safe to call on each admin refresh or operator sweep.\n */\n async reconcile(): Promise<void> {\n const tenantId = requireTenant().tenantId;\n const jobs = await SmrtJobCollection.create({ db: this.db });\n for (let offset = 0; ; offset += 1000) {\n const terminal = await jobs.list({\n where: { tenantId, queue: 'webhooks', status: ['failed', 'cancelled'] },\n orderBy: 'id ASC',\n limit: 1000,\n offset,\n });\n for (const job of terminal) {\n if (\n job.args.runtime !== this.runtime ||\n typeof job.args.deliveryId !== 'string'\n )\n continue;\n await this.db.query(\n `UPDATE _smrt_webhook_deliveries SET status = 'failed', error = 'Webhook job exhausted.', lease_token = NULL, lease_until = NULL\n WHERE id = ? AND tenant_id = ? AND generation = ? AND status IN ('pending', 'retrying') AND (lease_until IS NULL OR lease_until <= ?)`,\n job.args.deliveryId,\n tenantId,\n job.args.generation ?? 0,\n new Date().toISOString(),\n );\n }\n if (terminal.length < 1000) return;\n }\n }\n\n /** Explicit operator recovery for exhausted jobs. Repeated/concurrent replay is a no-op. */\n async replay(id: string): Promise<boolean> {\n const tenantId = requireTenant().tenantId;\n if (!this.db.transaction)\n throw new Error('Webhooks require a transactional database.');\n return this.db.transaction(async (tx) => {\n const changed = await tx.query(\n `UPDATE _smrt_webhook_deliveries SET status = 'pending', attempts = 0, generation = generation + 1, error = NULL, lease_token = NULL, lease_until = NULL\n WHERE id = ? AND tenant_id = ? AND status = 'failed' RETURNING generation`,\n id,\n tenantId,\n );\n if (!changed.rows.length) return false;\n await this.enqueue(\n tx,\n tenantId,\n id,\n Number((changed.rows[0] as { generation: number }).generation),\n );\n return true;\n });\n }\n}\n","import { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { DatabaseInterface } from '@happyvertical/sql';\nimport {\n assertHmacSecret,\n sendPublicWebhook,\n type WebhookTransport,\n} from './security.js';\nimport { signWebhookPayload } from './signing.js';\nimport { WebhookStore } from './store.js';\nimport type { WebhookEventEnvelope } from './types.js';\n\nexport interface WebhookDispatcherOptions {\n db: DatabaseInterface;\n runtime: string;\n /** Trusted server integration seam. Default transport pins validated public DNS answers. */\n transport?: WebhookTransport;\n}\nconst runtimes = new Map<string, WebhookDispatcher>();\nexport function registerWebhookRuntime(\n name: string,\n dispatcher: WebhookDispatcher,\n): void {\n if (!name || runtimes.has(name))\n throw new Error('Webhook runtime already registered or invalid.');\n runtimes.set(name, dispatcher);\n}\nexport function unregisterWebhookRuntime(name: string): void {\n runtimes.delete(name);\n}\n\nexport function assertWebhookEvent(event: WebhookEventEnvelope): void {\n if (\n !event ||\n typeof event !== 'object' ||\n !event.data ||\n Array.isArray(event.data) ||\n typeof event.data !== 'object' ||\n [event.id, event.event, event.model].some(\n (v) => typeof v !== 'string' || !v || v.length > 200 || /[\\r\\n]/.test(v),\n ) ||\n typeof event.occurredAt !== 'string' ||\n !Number.isFinite(Date.parse(event.occurredAt)) ||\n Buffer.byteLength(JSON.stringify(event)) > 262144\n )\n throw new Error('Invalid webhook event.');\n}\n\n/** Durable tenant-scoped outbound events. Receivers deduplicate x-smrt-delivery. */\nexport class WebhookDispatcher {\n readonly store: WebhookStore;\n private readonly transport: WebhookTransport;\n constructor(options: WebhookDispatcherOptions) {\n this.store = new WebhookStore(options.db, options.runtime);\n this.transport = options.transport ?? sendPublicWebhook;\n }\n async dispatch(event: WebhookEventEnvelope): Promise<string[]> {\n requireTenant();\n assertWebhookEvent(event);\n const ids: string[] = [];\n for (const sub of await this.store.subscriptions()) {\n if (\n sub.enabled &&\n (!sub.events.length || sub.events.includes(event.event)) &&\n (!sub.models.length || sub.models.includes(event.model))\n ) {\n ids.push(await this.store.accept(sub.id ?? '', event));\n }\n }\n return ids;\n }\n async deliver(\n deliveryId: string,\n expectedGeneration?: number,\n ): Promise<void> {\n requireTenant();\n const before = await this.store.delivery(deliveryId);\n if (\n !before ||\n (expectedGeneration !== undefined &&\n before.generation !== expectedGeneration) ||\n ['delivered', 'failed', 'cancelled'].includes(before.status)\n )\n return;\n const token = await this.store.claim(deliveryId, before.generation);\n if (!token) throw new Error('Webhook delivery is already leased.');\n const delivery = await this.store.delivery(deliveryId);\n if (!delivery) throw new Error('Webhook delivery unavailable.');\n let responseStatus: number | null = null;\n try {\n const sub = await this.store.subscription(delivery.subscriptionId);\n if (!sub?.enabled) {\n await this.store.finish(\n deliveryId,\n token,\n 'cancelled',\n null,\n 'Subscription disabled.',\n );\n return;\n }\n assertHmacSecret(sub.secret);\n const event = JSON.parse(delivery.payload) as WebhookEventEnvelope;\n assertWebhookEvent(event);\n const timestamp = new Date().toISOString();\n responseStatus = await this.transport({\n url: sub.url,\n body: delivery.payload,\n headers: {\n 'content-type': 'application/json',\n 'user-agent': 'smrt-webhooks/1',\n 'x-smrt-event': event.event,\n 'x-smrt-delivery': deliveryId,\n 'x-smrt-timestamp': timestamp,\n 'x-smrt-signature': signWebhookPayload(\n sub.secret,\n timestamp,\n delivery.payload,\n ),\n },\n });\n if (responseStatus < 200 || responseStatus >= 300)\n throw new Error('Webhook rejected.');\n await this.store.finish(\n deliveryId,\n token,\n 'delivered',\n responseStatus,\n null,\n );\n } catch {\n // Never persist/rethrow endpoint errors: URLs, response bodies and secrets may be embedded.\n await this.store.finish(\n deliveryId,\n token,\n delivery.attempts >= 5 ? 'failed' : 'retrying',\n responseStatus,\n 'Webhook delivery failed.',\n );\n throw new Error('Webhook delivery failed.');\n }\n }\n}\nexport async function runWebhookDeliveryJob(\n args: Record<string, unknown>,\n): Promise<void> {\n const runtime =\n typeof args.runtime === 'string' ? runtimes.get(args.runtime) : undefined;\n if (\n !runtime ||\n typeof args.deliveryId !== 'string' ||\n args.tenantId !== requireTenant().tenantId\n ) {\n throw new Error('Invalid webhook job or unavailable runtime.');\n }\n await runtime.deliver(\n args.deliveryId,\n typeof args.generation === 'number' ? args.generation : 0,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAGO,IAAM,+BAA+B,MAAS;AAGrD,IAAM,mBAAmB;AAGlB,SAAS,mBACd,QACA,WACA,MACQ;CAER,MAAM,OAAO,WAAW,UAAU,MAAM,CAAA,CAAE,OAAO,GAAG,UAAS,EAAG;CAChE,KAAK,OAAO,OAAO,SAAS,WAAW,OAAO,KAAK,MAAM,MAAM,IAAI,IAAI;CACvE,OAAO,UAAU,KAAK,OAAO,KAAK;AACpC;AA0BO,SAAS,uBACd,SACqB;CACrB,MAAM,EAAE,WAAW,cAAc,WAAY,CAAC;CAC9C,MAAM,OAAgB,SAAS;CAC/B,MAAM,QAAiB,SAAS;CAChC,MAAM,UACJ,OAAO,UAAU,WACb,CAAC,KAAK,IACN,MAAM,QAAQ,KAAK,IACjB,CAAC,GAAG,KAAK,IACT,CAAC;CACT,IACE,OAAO,cAAc,YACrB,OAAO,cAAc,YACpB,OAAO,SAAS,YAAY,EAAE,gBAAgB,eAC/C,CAAC,QAAQ,UACT,QAAQ,MAAM,MAAM,OAAO,MAAM,YAAY,CAAC,CAAC,KAC/C,CAAC,wBAAwB,KAAK,SAAS,KACvC,CAAC,iBAAiB,KAAK,SAAS,GAEhC,OAAO;EAAE,IAAI;EAAO,QAAQ;CAAY;CAC1C,MAAM,OAAO,KAAK,MAAM,SAAS;CACjC,MAAM,YAAY,QAAQ,eAAA;CAC1B,MAAM,SAAS,QAAQ,uBAAO,IAAI,KAAK,EAAA,CAAG,QAAQ;CAClD,IACE,CAAC,OAAO,SAAS,IAAI,KACrB,CAAC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kB,KAC5C,MAAM,IAAI,MAAM,mBAAmB;GACrC,MAAM,KAAK,MAAM,OACf,YACA,OACA,aACA,gBACA,IACF;EACF,QAAQ;GAEN,MAAM,KAAK,MAAM,OACf,YACA,OACA,SAAS,YAAY,IAAI,WAAW,YACpC,gBACA,0BACF;GACA,MAAM,IAAI,MAAM,0BAA0B;EAC5C;CACF;AACF;AACA,eAAsB,sBACpB,MACe;CACf,MAAM,UACJ,OAAO,KAAK,YAAY,WAAW,SAAS,IAAI,KAAK,OAAO,IAAI,KAAA;CAClE,IACE,CAAC,WACD,OAAO,KAAK,eAAe,YAC3B,KAAK,aAAa,cAAc,CAAA,CAAE,UAElC,MAAM,IAAI,MAAM,6CAA6C;CAE/D,MAAM,QAAQ,QACZ,KAAK,YACL,OAAO,KAAK,eAAe,WAAW,KAAK,aAAa,CAC1D;AACF"}
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { a as runWebhookDeliveryJob, c as DEFAULT_WEBHOOK_TOLERANCE_MS, i as registerWebhookRuntime, l as signWebhookPayload, n as assertWebhookEvent, o as unregisterWebhookRuntime, s as WebhookStore, t as WebhookDispatcher, u as verifyWebhookSignature } from "./chunks/dispatcher-D0HRqbky.js";
2
- import { a as WebhookDeliveryCollection, c as WebhookSubscriptionCollection, d as isPublicAddress, f as sendPublicWebhook, i as WebhookDelivery, l as assertHmacSecret, n as webhookAdminView, o as WebhookDeliveryTask, r as WebhookCursor, s as WebhookSubscription, t as WebhookAdminService, u as assertWebhookUrl } from "./chunks/admin-DogkNqij.js";
1
+ import { a as runWebhookDeliveryJob, c as DEFAULT_WEBHOOK_TOLERANCE_MS, i as registerWebhookRuntime, l as signWebhookPayload, n as assertWebhookEvent, o as unregisterWebhookRuntime, s as WebhookStore, t as WebhookDispatcher, u as verifyWebhookSignature } from "./chunks/dispatcher-BmwcfQvY.js";
2
+ import { a as WebhookDeliveryCollection, c as WebhookSubscriptionCollection, d as isPublicAddress, f as sendPublicWebhook, i as WebhookDelivery, l as assertHmacSecret, n as webhookAdminView, o as WebhookDeliveryTask, r as WebhookCursor, s as WebhookSubscription, t as WebhookAdminService, u as assertWebhookUrl } from "./chunks/admin-ySI79PC3.js";
3
3
  import { GlobalInterceptors, ObjectRegistry, SmrtRecipe, getChangesSince } from "@happyvertical/smrt-core";
4
4
  import { requireTenant } from "@happyvertical/smrt-tenancy";
5
5
  import { randomUUID } from "node:crypto";
6
6
  //#region src/__smrt-register__.ts
7
- ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-webhooks","packageVersion":"0.61.3","objects":{"@happyvertical/smrt-webhooks:WebhookSubscription":{"name":"webhooksubscription","className":"WebhookSubscription","qualifiedName":"@happyvertical/smrt-webhooks:WebhookSubscription","collection":"webhooksubscriptions","description":"Server-only subscription. Hosts authorize administration before accessing it.","filePath":"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"url":{"type":"text","required":true,"_meta":{"required":true}},"events":{"type":"json","required":false,"_meta":{}},"models":{"type":"json","required":false,"_meta":{}},"secret":{"type":"text","required":true,"_meta":{"sensitive":true,"required":true},"sensitive":true},"enabled":{"type":"boolean","required":false,"default":true,"_meta":{"default":true}}},"methods":{"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_webhook_subscriptions","api":false,"cli":false,"mcp":false,"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"WebhookSubscription","collectionExportName":"WebhookSubscriptionCollection","validationRules":[{"field":"url","rule":"required","fieldType":"text"},{"field":"secret","rule":"required","fieldType":"text"}],"schema":{"tableName":"_smrt_webhook_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"url\\" TEXT NOT NULL,\\n \\"events\\" JSON,\\n \\"models\\" JSON,\\n \\"secret\\" TEXT NOT NULL,\\n \\"enabled\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"url":{"type":"TEXT","notNull":true,"unique":false},"events":{"type":"JSON","notNull":false,"unique":false},"models":{"type":"JSON","notNull":false,"unique":false},"secret":{"type":"TEXT","notNull":true,"unique":false},"enabled":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_webhook_subscriptions_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"1979c7f5"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection":{"name":"webhooksubscriptioncollection","className":"WebhookSubscriptionCollection","qualifiedName":"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection","collection":"webhooksubscriptions","filePath":"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_subscriptions","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"WebhookSubscription","exportName":"WebhookSubscriptionCollection","collectionExportName":"WebhookSubscriptionCollectionCollection","collectionOf":"@happyvertical/smrt-webhooks:WebhookSubscription","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_webhook_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"url\\" TEXT NOT NULL,\\n \\"events\\" JSON,\\n \\"models\\" JSON,\\n \\"secret\\" TEXT NOT NULL,\\n \\"enabled\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"url":{"type":"TEXT","notNull":true,"unique":false},"events":{"type":"JSON","notNull":false,"unique":false},"models":{"type":"JSON","notNull":false,"unique":false},"secret":{"type":"TEXT","notNull":true,"unique":false},"enabled":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_webhook_subscriptions_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"1979c7f5"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookDelivery":{"name":"webhookdelivery","className":"WebhookDelivery","qualifiedName":"@happyvertical/smrt-webhooks:WebhookDelivery","collection":"webhookdeliveries","description":"Durable outbox and safe outcome metadata; payload never appears in public projections.","filePath":"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"subscriptionId":{"type":"foreignKey","required":false,"related":"WebhookSubscription","_meta":{"onDelete":"RESTRICT","onUpdate":"RESTRICT"}},"eventId":{"type":"text","required":true,"_meta":{"required":true}},"payload":{"type":"text","required":true,"_meta":{"required":true,"sensitive":true},"sensitive":true},"status":{"type":"text","required":false,"default":"pending","_meta":{"default":"pending"}},"generation":{"type":"integer","required":false,"default":0,"_meta":{"default":0}},"attempts":{"type":"integer","required":false,"default":0,"_meta":{"default":0}},"responseStatus":{"type":"integer","required":false,"_meta":{"nullable":true}},"error":{"type":"text","required":false,"_meta":{"nullable":true}},"leaseToken":{"type":"text","required":false,"_meta":{"nullable":true,"sensitive":true},"sensitive":true},"leaseUntil":{"type":"datetime","required":false,"_meta":{"nullable":true}}},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_deliveries","api":false,"cli":false,"mcp":false,"indexes":[{"name":"_smrt_webhook_delivery_identity","columns":["tenantId","subscriptionId","eventId"],"unique":true}],"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"WebhookDelivery","collectionExportName":"WebhookDeliveryCollection","validationRules":[{"field":"eventId","rule":"required","fieldType":"text"},{"field":"payload","rule":"required","fieldType":"text"}],"schema":{"tableName":"_smrt_webhook_deliveries","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_deliveries\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscription_id\\" UUID,\\n \\"event_id\\" TEXT NOT NULL,\\n \\"payload\\" TEXT NOT NULL,\\n \\"status\\" TEXT DEFAULT 'pending',\\n \\"generation\\" INTEGER DEFAULT 0,\\n \\"attempts\\" INTEGER DEFAULT 0,\\n \\"response_status\\" INTEGER,\\n \\"error\\" TEXT,\\n \\"lease_token\\" TEXT,\\n \\"lease_until\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscription_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_webhook_subscriptions","column":"id","onDelete":"RESTRICT","onUpdate":"RESTRICT"}},"event_id":{"type":"TEXT","notNull":true,"unique":false},"payload":{"type":"TEXT","notNull":true,"unique":false},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"pending"},"generation":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"attempts":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"response_status":{"type":"INTEGER","notNull":false,"unique":false},"error":{"type":"TEXT","notNull":false,"unique":false},"lease_token":{"type":"TEXT","notNull":false,"unique":false},"lease_until":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_webhook_deliveries_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_delivery_identity","columns":["tenant_id","subscription_id","event_id"],"unique":true},{"name":"_smrt_webhook_deliveries_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_webhook_deliveries_subscription_id_idx","columns":["subscription_id"]}],"version":"ed54179d"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookDeliveryCollection":{"name":"webhookdeliverycollection","className":"WebhookDeliveryCollection","qualifiedName":"@happyvertical/smrt-webhooks:WebhookDeliveryCollection","collection":"webhookdeliveries","filePath":"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_deliveries","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"WebhookDelivery","exportName":"WebhookDeliveryCollection","collectionExportName":"WebhookDeliveryCollectionCollection","collectionOf":"@happyvertical/smrt-webhooks:WebhookDelivery","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_webhook_deliveries","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_deliveries\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscription_id\\" UUID,\\n \\"event_id\\" TEXT NOT NULL,\\n \\"payload\\" TEXT NOT NULL,\\n \\"status\\" TEXT DEFAULT 'pending',\\n \\"generation\\" INTEGER DEFAULT 0,\\n \\"attempts\\" INTEGER DEFAULT 0,\\n \\"response_status\\" INTEGER,\\n \\"error\\" TEXT,\\n \\"lease_token\\" TEXT,\\n \\"lease_until\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscription_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_webhook_subscriptions","column":"id","onDelete":"RESTRICT","onUpdate":"RESTRICT"}},"event_id":{"type":"TEXT","notNull":true,"unique":false},"payload":{"type":"TEXT","notNull":true,"unique":false},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"pending"},"generation":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"attempts":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"response_status":{"type":"INTEGER","notNull":false,"unique":false},"error":{"type":"TEXT","notNull":false,"unique":false},"lease_token":{"type":"TEXT","notNull":false,"unique":false},"lease_until":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_webhook_deliveries_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_delivery_identity","columns":["tenant_id","subscription_id","event_id"],"unique":true},{"name":"_smrt_webhook_deliveries_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_webhook_deliveries_subscription_id_idx","columns":["subscription_id"]}],"version":"ed54179d"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookDeliveryTask":{"name":"webhookdeliverytask","className":"WebhookDeliveryTask","qualifiedName":"@happyvertical/smrt-webhooks:WebhookDeliveryTask","collection":"webhookdeliverytasks","description":"Jobs queue entry point; persisted arguments contain IDs only.","filePath":"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{},"methods":{"deliver":{"name":"deliver","async":true,"parameters":[{"name":"args","type":"Record<string, unknown>","optional":true},{"name":"_context","type":"JobExecutionContext","optional":true}],"returnType":"Promise<void>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_webhook_delivery_tasks","api":false,"cli":false,"mcp":false},"extends":"SmrtObject","exportName":"WebhookDeliveryTask","collectionExportName":"WebhookDeliveryTaskCollection","schema":{"tableName":"_smrt_webhook_delivery_tasks","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_delivery_tasks\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"}},"indexes":[{"name":"_smrt_webhook_delivery_tasks_slug_context_idx","columns":["slug","context"],"unique":true},{"name":"_smrt_webhook_delivery_tasks_created_at_idx","columns":["created_at"]}],"version":"268c614c"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookCursor":{"name":"webhookcursor","className":"WebhookCursor","qualifiedName":"@happyvertical/smrt-webhooks:WebhookCursor","collection":"webhookcursors","description":"Tenant-bound durable cursor for replayable model change-feed publication.","filePath":"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{"tenantId":{"type":"text","required":true,"_meta":{"sqlType":"UUID","__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false}}},"runtime":{"type":"text","required":true,"_meta":{"required":true}},"position":{"type":"integer","required":false,"default":0,"_meta":{"default":0}}},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_cursors","api":false,"cli":false,"mcp":false,"indexes":[{"name":"_smrt_webhook_cursor_identity","columns":["tenantId","runtime"],"unique":true}],"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"WebhookCursor","collectionExportName":"WebhookCursorCollection","validationRules":[{"field":"runtime","rule":"required","fieldType":"text"}],"schema":{"tableName":"_smrt_webhook_cursors","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_cursors\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"runtime\\" TEXT NOT NULL,\\n \\"position\\" INTEGER DEFAULT 0\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"runtime":{"type":"TEXT","notNull":true,"unique":false},"position":{"type":"INTEGER","notNull":false,"unique":false,"default":0}},"indexes":[{"name":"_smrt_webhook_cursors_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_cursor_identity","columns":["tenant_id","runtime"],"unique":true},{"name":"_smrt_webhook_cursors_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"f46a5a8e"},"importPath":"@happyvertical/smrt-webhooks"}},"moduleType":"smrt","recipes":[{"id":"integrations.webhooks","className":"WebhooksRecipe","label":"Outbound webhooks","summary":"Deliver signed model events and inspect delivery attempts from a server.","synonyms":[],"models":["@happyvertical/smrt-webhooks:WebhookSubscription","@happyvertical/smrt-webhooks:WebhookDelivery","@happyvertical/smrt-webhooks:WebhookDeliveryTask","@happyvertical/smrt-webhooks:WebhookCursor"],"nav":[],"requires":[],"group":{"id":"integrations","label":"Integrations","summary":"Connect your application to external services."},"help":{"markdown":"## Overview\\n\\nSend signed event notifications to an external HTTPS endpoint. Administrators\\ncan pause subscriptions and inspect delivery attempts. This integration requires\\na server and a running background worker.\\n\\n## Tasks\\n\\n- Add a subscription with a public HTTPS endpoint, signing secret, and event/model filters.\\n- Disable a subscription to cancel unsent deliveries.\\n- Inspect the delivery log, then retry failed deliveries after correcting their endpoint.\\n- Ask the endpoint owner to verify signatures and deduplicate delivery IDs.\\n","fieldRefs":[]},"surfaces":[{"kind":"settings-panel","export":"@happyvertical/smrt-webhooks/svelte#WebhookAdmin","label":"Outbound webhooks"}],"runtime":"server","demo":{"mode":"server","reasons":["The recipe declares runtime \\"server\\".","Needs a server because its package does not build for a browser: Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.; and its package depends on @happyvertical/smrt-jobs, @happyvertical/smrt-tenancy, which do not build for a browser (#3615, #3624, #3627, #3717)."]}}],"smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-jobs","@happyvertical/smrt-tenancy"],"browser":{"status":"server-only","issues":["#3615","#3624","#3627","#3717"],"reason":"Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.","via":["@happyvertical/smrt-jobs","@happyvertical/smrt-tenancy"]},"stampsConstructors":true}`));
7
+ ObjectRegistry.registerPackageManifest(JSON.parse(`{"version":"1.0.0","timestamp":0,"packageName":"@happyvertical/smrt-webhooks","packageVersion":"0.61.4","objects":{"@happyvertical/smrt-webhooks:WebhookSubscription":{"name":"webhooksubscription","className":"WebhookSubscription","qualifiedName":"@happyvertical/smrt-webhooks:WebhookSubscription","collection":"webhooksubscriptions","description":"Server-only subscription. Hosts authorize administration before accessing it.","filePath":"src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"url":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"system-table"},"required":true},"events":{"type":"json","_meta":{"__statedOptions":[]},"required":false},"models":{"type":"json","_meta":{"__statedOptions":[]},"required":false},"secret":{"type":"text","_meta":{"__statedOptions":["sensitive","required","requiredFor"],"required":true,"sensitive":true,"requiredFor":"system-table"},"required":true,"sensitive":true},"enabled":{"type":"boolean","_meta":{"__statedOptions":["default"],"default":true},"required":false,"default":true}},"methods":{"save":{"name":"save","async":true,"parameters":[{"name":"options","type":"SmrtSaveOptions","optional":true}],"returnType":"Promise<this>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_webhook_subscriptions","api":false,"cli":false,"mcp":false,"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"WebhookSubscription","collectionExportName":"WebhookSubscriptionCollection","validationRules":[{"field":"url","rule":"required","fieldType":"text"},{"field":"secret","rule":"required","fieldType":"text"}],"schema":{"tableName":"_smrt_webhook_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"url\\" TEXT NOT NULL,\\n \\"events\\" JSON,\\n \\"models\\" JSON,\\n \\"secret\\" TEXT NOT NULL,\\n \\"enabled\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"url":{"type":"TEXT","notNull":true,"unique":false},"events":{"type":"JSON","notNull":false,"unique":false},"models":{"type":"JSON","notNull":false,"unique":false},"secret":{"type":"TEXT","notNull":true,"unique":false},"enabled":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_webhook_subscriptions_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"1979c7f5"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection":{"name":"webhooksubscriptioncollection","className":"WebhookSubscriptionCollection","qualifiedName":"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection","collection":"webhooksubscriptions","filePath":"src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_subscriptions","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"WebhookSubscription","exportName":"WebhookSubscriptionCollection","collectionExportName":"WebhookSubscriptionCollectionCollection","collectionOf":"@happyvertical/smrt-webhooks:WebhookSubscription","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_webhook_subscriptions","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_subscriptions\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"url\\" TEXT NOT NULL,\\n \\"events\\" JSON,\\n \\"models\\" JSON,\\n \\"secret\\" TEXT NOT NULL,\\n \\"enabled\\" BOOLEAN DEFAULT TRUE\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"url":{"type":"TEXT","notNull":true,"unique":false},"events":{"type":"JSON","notNull":false,"unique":false},"models":{"type":"JSON","notNull":false,"unique":false},"secret":{"type":"TEXT","notNull":true,"unique":false},"enabled":{"type":"BOOLEAN","notNull":false,"unique":false,"default":true}},"indexes":[{"name":"_smrt_webhook_subscriptions_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_subscriptions_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"1979c7f5"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookDelivery":{"name":"webhookdelivery","className":"WebhookDelivery","qualifiedName":"@happyvertical/smrt-webhooks:WebhookDelivery","collection":"webhookdeliveries","description":"Durable outbox and safe outcome metadata; payload never appears in public projections.","filePath":"src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"subscriptionId":{"type":"foreignKey","_meta":{"__statedOptions":["onUpdate","onDelete","related"],"onUpdate":"RESTRICT","onDelete":"RESTRICT"},"required":false,"related":"WebhookSubscription"},"eventId":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"identity"},"required":true},"payload":{"type":"text","_meta":{"__statedOptions":["required","sensitive"],"required":true,"sensitive":true},"required":true,"sensitive":true},"status":{"type":"text","_meta":{"__statedOptions":["default"],"default":"pending"},"required":false,"default":"pending"},"generation":{"type":"integer","_meta":{"__statedOptions":["default"],"default":0},"required":false,"default":0},"attempts":{"type":"integer","_meta":{"__statedOptions":["default"],"default":0},"required":false,"default":0},"responseStatus":{"type":"integer","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"error":{"type":"text","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false},"leaseToken":{"type":"text","_meta":{"__statedOptions":["nullable","sensitive","required"],"sensitive":true,"nullable":true,"required":false},"required":false,"sensitive":true},"leaseUntil":{"type":"datetime","_meta":{"__statedOptions":["nullable","required"],"nullable":true,"required":false},"required":false}},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_deliveries","api":false,"cli":false,"mcp":false,"indexes":[{"name":"_smrt_webhook_delivery_identity","columns":["tenantId","subscriptionId","eventId"],"unique":true}],"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"WebhookDelivery","collectionExportName":"WebhookDeliveryCollection","validationRules":[{"field":"eventId","rule":"required","fieldType":"text"},{"field":"payload","rule":"required","fieldType":"text"}],"schema":{"tableName":"_smrt_webhook_deliveries","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_deliveries\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscription_id\\" UUID,\\n \\"event_id\\" TEXT NOT NULL,\\n \\"payload\\" TEXT NOT NULL,\\n \\"status\\" TEXT DEFAULT 'pending',\\n \\"generation\\" INTEGER DEFAULT 0,\\n \\"attempts\\" INTEGER DEFAULT 0,\\n \\"response_status\\" INTEGER,\\n \\"error\\" TEXT,\\n \\"lease_token\\" TEXT,\\n \\"lease_until\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscription_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_webhook_subscriptions","column":"id","onDelete":"RESTRICT","onUpdate":"RESTRICT"}},"event_id":{"type":"TEXT","notNull":true,"unique":false},"payload":{"type":"TEXT","notNull":true,"unique":false},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"pending"},"generation":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"attempts":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"response_status":{"type":"INTEGER","notNull":false,"unique":false},"error":{"type":"TEXT","notNull":false,"unique":false},"lease_token":{"type":"TEXT","notNull":false,"unique":false},"lease_until":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_webhook_deliveries_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_delivery_identity","columns":["tenant_id","subscription_id","event_id"],"unique":true},{"name":"_smrt_webhook_deliveries_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_webhook_deliveries_subscription_id_idx","columns":["subscription_id"]}],"version":"ed54179d"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookDeliveryCollection":{"name":"webhookdeliverycollection","className":"WebhookDeliveryCollection","qualifiedName":"@happyvertical/smrt-webhooks:WebhookDeliveryCollection","collection":"webhookdeliveries","filePath":"src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_deliveries","api":false,"mcp":false,"cli":false},"extends":"SmrtCollection","extendsTypeArg":"WebhookDelivery","exportName":"WebhookDeliveryCollection","collectionExportName":"WebhookDeliveryCollectionCollection","collectionOf":"@happyvertical/smrt-webhooks:WebhookDelivery","inheritedExposure":["api","mcp","cli"],"schema":{"tableName":"_smrt_webhook_deliveries","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_deliveries\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"subscription_id\\" UUID,\\n \\"event_id\\" TEXT NOT NULL,\\n \\"payload\\" TEXT NOT NULL,\\n \\"status\\" TEXT DEFAULT 'pending',\\n \\"generation\\" INTEGER DEFAULT 0,\\n \\"attempts\\" INTEGER DEFAULT 0,\\n \\"response_status\\" INTEGER,\\n \\"error\\" TEXT,\\n \\"lease_token\\" TEXT,\\n \\"lease_until\\" TIMESTAMP\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"subscription_id":{"type":"UUID","referenceKind":"foreignKey","notNull":false,"unique":false,"foreignKey":{"table":"_smrt_webhook_subscriptions","column":"id","onDelete":"RESTRICT","onUpdate":"RESTRICT"}},"event_id":{"type":"TEXT","notNull":true,"unique":false},"payload":{"type":"TEXT","notNull":true,"unique":false},"status":{"type":"TEXT","notNull":false,"unique":false,"default":"pending"},"generation":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"attempts":{"type":"INTEGER","notNull":false,"unique":false,"default":0},"response_status":{"type":"INTEGER","notNull":false,"unique":false},"error":{"type":"TEXT","notNull":false,"unique":false},"lease_token":{"type":"TEXT","notNull":false,"unique":false},"lease_until":{"type":"TIMESTAMP","notNull":false,"unique":false}},"indexes":[{"name":"_smrt_webhook_deliveries_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_delivery_identity","columns":["tenant_id","subscription_id","event_id"],"unique":true},{"name":"_smrt_webhook_deliveries_tenant_id_created_at_idx","columns":["tenant_id","created_at"]},{"name":"_smrt_webhook_deliveries_subscription_id_idx","columns":["subscription_id"]}],"version":"ed54179d"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookDeliveryTask":{"name":"webhookdeliverytask","className":"WebhookDeliveryTask","qualifiedName":"@happyvertical/smrt-webhooks:WebhookDeliveryTask","collection":"webhookdeliverytasks","description":"Jobs queue entry point; persisted arguments contain IDs only.","filePath":"src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{},"methods":{"deliver":{"name":"deliver","async":true,"parameters":[{"name":"args","type":"Record<string, unknown>","optional":true},{"name":"_context","type":"JobExecutionContext","optional":true}],"returnType":"Promise<void>","isStatic":false,"isPublic":true}},"decoratorConfig":{"tableName":"_smrt_webhook_delivery_tasks","api":false,"cli":false,"mcp":false},"extends":"SmrtObject","exportName":"WebhookDeliveryTask","collectionExportName":"WebhookDeliveryTaskCollection","schema":{"tableName":"_smrt_webhook_delivery_tasks","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_delivery_tasks\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"}},"indexes":[{"name":"_smrt_webhook_delivery_tasks_slug_context_idx","columns":["slug","context"],"unique":true},{"name":"_smrt_webhook_delivery_tasks_created_at_idx","columns":["created_at"]}],"version":"268c614c"},"importPath":"@happyvertical/smrt-webhooks"},"@happyvertical/smrt-webhooks:WebhookCursor":{"name":"webhookcursor","className":"WebhookCursor","qualifiedName":"@happyvertical/smrt-webhooks:WebhookCursor","collection":"webhookcursors","description":"Tenant-bound durable cursor for replayable model change-feed publication.","filePath":"src/models.ts","packageName":"@happyvertical/smrt-webhooks","fields":{"tenantId":{"type":"text","_meta":{"__tenancy":{"isTenantIdField":true,"autoFilter":true,"required":true,"autoPopulate":true,"nullable":false,"mode":"required","field":"tenantId","allowSuperAdminBypass":false},"__statedOptions":["sqlType","requiredFor","__tenancy"],"sqlType":"UUID","requiredFor":"tenant-scope"},"required":true},"runtime":{"type":"text","_meta":{"__statedOptions":["required","requiredFor"],"required":true,"requiredFor":"identity"},"required":true},"position":{"type":"integer","_meta":{"__statedOptions":["default"],"default":0},"required":false,"default":0}},"methods":{},"decoratorConfig":{"tableName":"_smrt_webhook_cursors","api":false,"cli":false,"mcp":false,"indexes":[{"name":"_smrt_webhook_cursor_identity","columns":["tenantId","runtime"],"unique":true}],"tenantScoped":{"mode":"required"},"conflictColumns":["tenant_id","slug","context"]},"extends":"SmrtObject","exportName":"WebhookCursor","collectionExportName":"WebhookCursorCollection","validationRules":[{"field":"runtime","rule":"required","fieldType":"text"}],"schema":{"tableName":"_smrt_webhook_cursors","ddl":"CREATE TABLE IF NOT EXISTS \\"_smrt_webhook_cursors\\" (\\n \\"_sync_origin_device_id\\" TEXT,\\n \\"_sync_revision\\" INTEGER,\\n \\"id\\" UUID PRIMARY KEY NOT NULL,\\n \\"slug\\" TEXT NOT NULL,\\n \\"context\\" TEXT NOT NULL DEFAULT '',\\n \\"created_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"updated_at\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\n \\"tenant_id\\" UUID NOT NULL,\\n \\"runtime\\" TEXT NOT NULL,\\n \\"position\\" INTEGER DEFAULT 0\\n);","columns":{"_sync_origin_device_id":{"type":"TEXT"},"_sync_revision":{"type":"INTEGER"},"id":{"type":"UUID","primaryKey":true,"referenceKind":"id","notNull":true},"slug":{"type":"TEXT","notNull":true},"context":{"type":"TEXT","notNull":true,"default":""},"created_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"updated_at":{"type":"TIMESTAMP","notNull":true,"default":"current_timestamp"},"tenant_id":{"type":"UUID","referenceKind":"tenantId","notNull":true,"unique":false},"runtime":{"type":"TEXT","notNull":true,"unique":false},"position":{"type":"INTEGER","notNull":false,"unique":false,"default":0}},"indexes":[{"name":"_smrt_webhook_cursors_slug_context_idx","columns":["tenant_id","slug","context"],"unique":true},{"name":"_smrt_webhook_cursor_identity","columns":["tenant_id","runtime"],"unique":true},{"name":"_smrt_webhook_cursors_tenant_id_created_at_idx","columns":["tenant_id","created_at"]}],"version":"f46a5a8e"},"importPath":"@happyvertical/smrt-webhooks"}},"moduleType":"smrt","recipes":[{"id":"integrations.webhooks","className":"WebhooksRecipe","label":"Outbound webhooks","summary":"Deliver signed model events and inspect delivery attempts from a server.","synonyms":[],"models":["@happyvertical/smrt-webhooks:WebhookSubscription","@happyvertical/smrt-webhooks:WebhookDelivery","@happyvertical/smrt-webhooks:WebhookDeliveryTask","@happyvertical/smrt-webhooks:WebhookCursor"],"nav":[],"requires":[],"group":{"id":"integrations","label":"Integrations","summary":"Connect your application to external services."},"help":{"markdown":"## Overview\\n\\nSend signed event notifications to an external HTTPS endpoint. Administrators\\ncan pause subscriptions and inspect delivery attempts. This integration requires\\na server and a running background worker.\\n\\n## Tasks\\n\\n- Add a subscription with a public HTTPS endpoint, signing secret, and event/model filters.\\n- Disable a subscription to cancel unsent deliveries.\\n- Inspect the delivery log, then retry failed deliveries after correcting their endpoint.\\n- Ask the endpoint owner to verify signatures and deduplicate delivery IDs.\\n","fieldRefs":[]},"surfaces":[{"kind":"settings-panel","export":"@happyvertical/smrt-webhooks/svelte#WebhookAdmin","label":"Outbound webhooks"}],"runtime":"server","demo":{"mode":"server","reasons":["The recipe declares runtime \\"server\\".","Needs a server because its package does not build for a browser: Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.; and its package depends on @happyvertical/smrt-jobs, @happyvertical/smrt-tenancy, which do not build for a browser (#3615, #3624, #3627, #3717)."]}}],"smrtDependencies":["@happyvertical/smrt-core","@happyvertical/smrt-jobs","@happyvertical/smrt-tenancy"],"browser":{"status":"server-only","issues":["#3615","#3624","#3627","#3717"],"reason":"Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.","via":["@happyvertical/smrt-jobs","@happyvertical/smrt-tenancy"]},"stampsConstructors":true}`));
8
8
  //#endregion
9
9
  //#region src/change-feed.ts
10
10
  var WebhookHistoryExpiredError = class extends Error {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/__smrt-register__.ts","../src/change-feed.ts","../src/events.ts","../src/recipes.ts"],"sourcesContent":["// Generated by @happyvertical/smrt-core smrtPlugin at library build time.\n// The package manifest is inlined so self-registration cannot miss when a\n// downstream bundler relocates this module away from dist/manifest.json\n// (https://github.com/happyvertical/smrt/issues/1506,\n// https://github.com/happyvertical/smrt/issues/1507).\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\nObjectRegistry.registerPackageManifest(JSON.parse(\"{\\\"version\\\":\\\"1.0.0\\\",\\\"timestamp\\\":0,\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"packageVersion\\\":\\\"0.61.3\\\",\\\"objects\\\":{\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\":{\\\"name\\\":\\\"webhooksubscription\\\",\\\"className\\\":\\\"WebhookSubscription\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\",\\\"collection\\\":\\\"webhooksubscriptions\\\",\\\"description\\\":\\\"Server-only subscription. Hosts authorize administration before accessing it.\\\",\\\"filePath\\\":\\\"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"sqlType\\\":\\\"UUID\\\",\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":true,\\\"autoPopulate\\\":true,\\\"nullable\\\":false,\\\"mode\\\":\\\"required\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false}}},\\\"url\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"required\\\":true}},\\\"events\\\":{\\\"type\\\":\\\"json\\\",\\\"required\\\":false,\\\"_meta\\\":{}},\\\"models\\\":{\\\"type\\\":\\\"json\\\",\\\"required\\\":false,\\\"_meta\\\":{}},\\\"secret\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"sensitive\\\":true,\\\"required\\\":true},\\\"sensitive\\\":true},\\\"enabled\\\":{\\\"type\\\":\\\"boolean\\\",\\\"required\\\":false,\\\"default\\\":true,\\\"_meta\\\":{\\\"default\\\":true}}},\\\"methods\\\":{\\\"save\\\":{\\\"name\\\":\\\"save\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"options\\\",\\\"type\\\":\\\"SmrtSaveOptions\\\",\\\"optional\\\":true}],\\\"returnType\\\":\\\"Promise<this>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"tenantScoped\\\":{\\\"mode\\\":\\\"required\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookSubscription\\\",\\\"collectionExportName\\\":\\\"WebhookSubscriptionCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"url\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"secret\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_subscriptions\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"url\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"events\\\\\\\" JSON,\\\\n \\\\\\\"models\\\\\\\" JSON,\\\\n \\\\\\\"secret\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"enabled\\\\\\\" BOOLEAN DEFAULT TRUE\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"url\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"events\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"models\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"secret\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"enabled\\\":{\\\"type\\\":\\\"BOOLEAN\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":true}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_subscriptions_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_subscriptions_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"1979c7f5\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection\\\":{\\\"name\\\":\\\"webhooksubscriptioncollection\\\",\\\"className\\\":\\\"WebhookSubscriptionCollection\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection\\\",\\\"collection\\\":\\\"webhooksubscriptions\\\",\\\"filePath\\\":\\\"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false},\\\"extends\\\":\\\"SmrtCollection\\\",\\\"extendsTypeArg\\\":\\\"WebhookSubscription\\\",\\\"exportName\\\":\\\"WebhookSubscriptionCollection\\\",\\\"collectionExportName\\\":\\\"WebhookSubscriptionCollectionCollection\\\",\\\"collectionOf\\\":\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\",\\\"inheritedExposure\\\":[\\\"api\\\",\\\"mcp\\\",\\\"cli\\\"],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_subscriptions\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"url\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"events\\\\\\\" JSON,\\\\n \\\\\\\"models\\\\\\\" JSON,\\\\n \\\\\\\"secret\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"enabled\\\\\\\" BOOLEAN DEFAULT TRUE\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"url\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"events\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"models\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"secret\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"enabled\\\":{\\\"type\\\":\\\"BOOLEAN\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":true}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_subscriptions_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_subscriptions_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"1979c7f5\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\":{\\\"name\\\":\\\"webhookdelivery\\\",\\\"className\\\":\\\"WebhookDelivery\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\",\\\"collection\\\":\\\"webhookdeliveries\\\",\\\"description\\\":\\\"Durable outbox and safe outcome metadata; payload never appears in public projections.\\\",\\\"filePath\\\":\\\"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"sqlType\\\":\\\"UUID\\\",\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":true,\\\"autoPopulate\\\":true,\\\"nullable\\\":false,\\\"mode\\\":\\\"required\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false}}},\\\"subscriptionId\\\":{\\\"type\\\":\\\"foreignKey\\\",\\\"required\\\":false,\\\"related\\\":\\\"WebhookSubscription\\\",\\\"_meta\\\":{\\\"onDelete\\\":\\\"RESTRICT\\\",\\\"onUpdate\\\":\\\"RESTRICT\\\"}},\\\"eventId\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"required\\\":true}},\\\"payload\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"required\\\":true,\\\"sensitive\\\":true},\\\"sensitive\\\":true},\\\"status\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":false,\\\"default\\\":\\\"pending\\\",\\\"_meta\\\":{\\\"default\\\":\\\"pending\\\"}},\\\"generation\\\":{\\\"type\\\":\\\"integer\\\",\\\"required\\\":false,\\\"default\\\":0,\\\"_meta\\\":{\\\"default\\\":0}},\\\"attempts\\\":{\\\"type\\\":\\\"integer\\\",\\\"required\\\":false,\\\"default\\\":0,\\\"_meta\\\":{\\\"default\\\":0}},\\\"responseStatus\\\":{\\\"type\\\":\\\"integer\\\",\\\"required\\\":false,\\\"_meta\\\":{\\\"nullable\\\":true}},\\\"error\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":false,\\\"_meta\\\":{\\\"nullable\\\":true}},\\\"leaseToken\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":false,\\\"_meta\\\":{\\\"nullable\\\":true,\\\"sensitive\\\":true},\\\"sensitive\\\":true},\\\"leaseUntil\\\":{\\\"type\\\":\\\"datetime\\\",\\\"required\\\":false,\\\"_meta\\\":{\\\"nullable\\\":true}}},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_delivery_identity\\\",\\\"columns\\\":[\\\"tenantId\\\",\\\"subscriptionId\\\",\\\"eventId\\\"],\\\"unique\\\":true}],\\\"tenantScoped\\\":{\\\"mode\\\":\\\"required\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookDelivery\\\",\\\"collectionExportName\\\":\\\"WebhookDeliveryCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"eventId\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"payload\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_deliveries\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"subscription_id\\\\\\\" UUID,\\\\n \\\\\\\"event_id\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"payload\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"status\\\\\\\" TEXT DEFAULT 'pending',\\\\n \\\\\\\"generation\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"attempts\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"response_status\\\\\\\" INTEGER,\\\\n \\\\\\\"error\\\\\\\" TEXT,\\\\n \\\\\\\"lease_token\\\\\\\" TEXT,\\\\n \\\\\\\"lease_until\\\\\\\" TIMESTAMP\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"subscription_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"foreignKey\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"foreignKey\\\":{\\\"table\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"column\\\":\\\"id\\\",\\\"onDelete\\\":\\\"RESTRICT\\\",\\\"onUpdate\\\":\\\"RESTRICT\\\"}},\\\"event_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"payload\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"status\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":\\\"pending\\\"},\\\"generation\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"attempts\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"response_status\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"error\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_token\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_until\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":false,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_deliveries_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_delivery_identity\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"subscription_id\\\",\\\"event_id\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_deliveries_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]},{\\\"name\\\":\\\"_smrt_webhook_deliveries_subscription_id_idx\\\",\\\"columns\\\":[\\\"subscription_id\\\"]}],\\\"version\\\":\\\"ed54179d\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookDeliveryCollection\\\":{\\\"name\\\":\\\"webhookdeliverycollection\\\",\\\"className\\\":\\\"WebhookDeliveryCollection\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookDeliveryCollection\\\",\\\"collection\\\":\\\"webhookdeliveries\\\",\\\"filePath\\\":\\\"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false},\\\"extends\\\":\\\"SmrtCollection\\\",\\\"extendsTypeArg\\\":\\\"WebhookDelivery\\\",\\\"exportName\\\":\\\"WebhookDeliveryCollection\\\",\\\"collectionExportName\\\":\\\"WebhookDeliveryCollectionCollection\\\",\\\"collectionOf\\\":\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\",\\\"inheritedExposure\\\":[\\\"api\\\",\\\"mcp\\\",\\\"cli\\\"],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_deliveries\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"subscription_id\\\\\\\" UUID,\\\\n \\\\\\\"event_id\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"payload\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"status\\\\\\\" TEXT DEFAULT 'pending',\\\\n \\\\\\\"generation\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"attempts\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"response_status\\\\\\\" INTEGER,\\\\n \\\\\\\"error\\\\\\\" TEXT,\\\\n \\\\\\\"lease_token\\\\\\\" TEXT,\\\\n \\\\\\\"lease_until\\\\\\\" TIMESTAMP\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"subscription_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"foreignKey\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"foreignKey\\\":{\\\"table\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"column\\\":\\\"id\\\",\\\"onDelete\\\":\\\"RESTRICT\\\",\\\"onUpdate\\\":\\\"RESTRICT\\\"}},\\\"event_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"payload\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"status\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":\\\"pending\\\"},\\\"generation\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"attempts\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"response_status\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"error\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_token\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_until\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":false,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_deliveries_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_delivery_identity\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"subscription_id\\\",\\\"event_id\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_deliveries_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]},{\\\"name\\\":\\\"_smrt_webhook_deliveries_subscription_id_idx\\\",\\\"columns\\\":[\\\"subscription_id\\\"]}],\\\"version\\\":\\\"ed54179d\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookDeliveryTask\\\":{\\\"name\\\":\\\"webhookdeliverytask\\\",\\\"className\\\":\\\"WebhookDeliveryTask\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookDeliveryTask\\\",\\\"collection\\\":\\\"webhookdeliverytasks\\\",\\\"description\\\":\\\"Jobs queue entry point; persisted arguments contain IDs only.\\\",\\\"filePath\\\":\\\"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{},\\\"methods\\\":{\\\"deliver\\\":{\\\"name\\\":\\\"deliver\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"args\\\",\\\"type\\\":\\\"Record<string, unknown>\\\",\\\"optional\\\":true},{\\\"name\\\":\\\"_context\\\",\\\"type\\\":\\\"JobExecutionContext\\\",\\\"optional\\\":true}],\\\"returnType\\\":\\\"Promise<void>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_delivery_tasks\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookDeliveryTask\\\",\\\"collectionExportName\\\":\\\"WebhookDeliveryTaskCollection\\\",\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_delivery_tasks\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_delivery_tasks\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_delivery_tasks_slug_context_idx\\\",\\\"columns\\\":[\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_delivery_tasks_created_at_idx\\\",\\\"columns\\\":[\\\"created_at\\\"]}],\\\"version\\\":\\\"268c614c\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookCursor\\\":{\\\"name\\\":\\\"webhookcursor\\\",\\\"className\\\":\\\"WebhookCursor\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookCursor\\\",\\\"collection\\\":\\\"webhookcursors\\\",\\\"description\\\":\\\"Tenant-bound durable cursor for replayable model change-feed publication.\\\",\\\"filePath\\\":\\\"/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"sqlType\\\":\\\"UUID\\\",\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":true,\\\"autoPopulate\\\":true,\\\"nullable\\\":false,\\\"mode\\\":\\\"required\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false}}},\\\"runtime\\\":{\\\"type\\\":\\\"text\\\",\\\"required\\\":true,\\\"_meta\\\":{\\\"required\\\":true}},\\\"position\\\":{\\\"type\\\":\\\"integer\\\",\\\"required\\\":false,\\\"default\\\":0,\\\"_meta\\\":{\\\"default\\\":0}}},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_cursors\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_cursor_identity\\\",\\\"columns\\\":[\\\"tenantId\\\",\\\"runtime\\\"],\\\"unique\\\":true}],\\\"tenantScoped\\\":{\\\"mode\\\":\\\"required\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookCursor\\\",\\\"collectionExportName\\\":\\\"WebhookCursorCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"runtime\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_cursors\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_cursors\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"runtime\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"position\\\\\\\" INTEGER DEFAULT 0\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"runtime\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"position\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_cursors_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_cursor_identity\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"runtime\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_cursors_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"f46a5a8e\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"}},\\\"moduleType\\\":\\\"smrt\\\",\\\"recipes\\\":[{\\\"id\\\":\\\"integrations.webhooks\\\",\\\"className\\\":\\\"WebhooksRecipe\\\",\\\"label\\\":\\\"Outbound webhooks\\\",\\\"summary\\\":\\\"Deliver signed model events and inspect delivery attempts from a server.\\\",\\\"synonyms\\\":[],\\\"models\\\":[\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\",\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\",\\\"@happyvertical/smrt-webhooks:WebhookDeliveryTask\\\",\\\"@happyvertical/smrt-webhooks:WebhookCursor\\\"],\\\"nav\\\":[],\\\"requires\\\":[],\\\"group\\\":{\\\"id\\\":\\\"integrations\\\",\\\"label\\\":\\\"Integrations\\\",\\\"summary\\\":\\\"Connect your application to external services.\\\"},\\\"help\\\":{\\\"markdown\\\":\\\"## Overview\\\\n\\\\nSend signed event notifications to an external HTTPS endpoint. Administrators\\\\ncan pause subscriptions and inspect delivery attempts. This integration requires\\\\na server and a running background worker.\\\\n\\\\n## Tasks\\\\n\\\\n- Add a subscription with a public HTTPS endpoint, signing secret, and event/model filters.\\\\n- Disable a subscription to cancel unsent deliveries.\\\\n- Inspect the delivery log, then retry failed deliveries after correcting their endpoint.\\\\n- Ask the endpoint owner to verify signatures and deduplicate delivery IDs.\\\\n\\\",\\\"fieldRefs\\\":[]},\\\"surfaces\\\":[{\\\"kind\\\":\\\"settings-panel\\\",\\\"export\\\":\\\"@happyvertical/smrt-webhooks/svelte#WebhookAdmin\\\",\\\"label\\\":\\\"Outbound webhooks\\\"}],\\\"runtime\\\":\\\"server\\\",\\\"demo\\\":{\\\"mode\\\":\\\"server\\\",\\\"reasons\\\":[\\\"The recipe declares runtime \\\\\\\"server\\\\\\\".\\\",\\\"Needs a server because its package does not build for a browser: Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.; and its package depends on @happyvertical/smrt-jobs, @happyvertical/smrt-tenancy, which do not build for a browser (#3615, #3624, #3627, #3717).\\\"]}}],\\\"smrtDependencies\\\":[\\\"@happyvertical/smrt-core\\\",\\\"@happyvertical/smrt-jobs\\\",\\\"@happyvertical/smrt-tenancy\\\"],\\\"browser\\\":{\\\"status\\\":\\\"server-only\\\",\\\"issues\\\":[\\\"#3615\\\",\\\"#3624\\\",\\\"#3627\\\",\\\"#3717\\\"],\\\"reason\\\":\\\"Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.\\\",\\\"via\\\":[\\\"@happyvertical/smrt-jobs\\\",\\\"@happyvertical/smrt-tenancy\\\"]},\\\"stampsConstructors\\\":true}\"));\n","import { randomUUID } from 'node:crypto';\nimport { getChangesSince } from '@happyvertical/smrt-core';\nimport { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { WebhookDispatcher } from './dispatcher.js';\n\nexport class WebhookHistoryExpiredError extends Error {\n constructor(readonly resumeCursor: number) {\n super(\n 'Webhook change history expired; reconcile source state before resetting the cursor.',\n );\n }\n}\n\n/** Durable, replayable lifecycle publication from SMRT's committed change feed.\n * Host scheduling calls poll() in each authenticated tenant context. The mapping\n * is an explicit physical-table allowlist; shared STI tables represent the base model.\n */\nexport class WebhookChangeFeed {\n constructor(\n private readonly dispatcher: WebhookDispatcher,\n private readonly models: Readonly<Record<string, string>>,\n ) {\n if (\n !Object.keys(models).length ||\n Object.keys(models).some((table) => table.startsWith('_smrt_')) ||\n Object.values(models).some((model) => !model)\n )\n throw new Error('Explicit application model tables are required.');\n }\n /** Cursor only advances after all matched changes have durable outbox/jobs.\n * A crash or partial failure replays the same stable identities on the next poll.\n * History pruning fails loudly: the host must reconcile source state before reset.\n */\n async poll(): Promise<{ cursor: number; published: number }> {\n const tenantId = requireTenant().tenantId;\n const { db, runtime } = this.dispatcher.store;\n const now = new Date().toISOString();\n const id = randomUUID();\n await db.query(\n `INSERT INTO _smrt_webhook_cursors (id, slug, context, tenant_id, runtime, position, created_at, updated_at)\n VALUES (?, ?, '', ?, ?, 0, ?, ?) ON CONFLICT (tenant_id, runtime) DO NOTHING`,\n id,\n id,\n tenantId,\n runtime,\n now,\n now,\n );\n const rows = await db.query(\n 'SELECT position FROM _smrt_webhook_cursors WHERE tenant_id = ? AND runtime = ?',\n tenantId,\n runtime,\n );\n const since = Number((rows.rows[0] as { position: number }).position);\n const page = await getChangesSince(db, {\n since,\n tenantId,\n tables: Object.keys(this.models),\n limit: 500,\n });\n if (page.resyncRequired)\n throw new WebhookHistoryExpiredError(page.resyncCursor ?? page.cursor);\n let published = 0;\n for (const change of page.changes) {\n // Core's tenant feed includes global rows; webhooks deliberately do not.\n if (\n change.tenantId !== tenantId ||\n !change.rowId ||\n !this.models[change.table]\n )\n continue;\n await this.dispatcher.dispatch({\n id: `change:${change.seq}`,\n event: change.operation,\n model: this.models[change.table],\n occurredAt: change.timestamp,\n data: { id: change.rowId },\n });\n published++;\n }\n await db.query(\n 'UPDATE _smrt_webhook_cursors SET position = ?, updated_at = ? WHERE tenant_id = ? AND runtime = ? AND position = ?',\n page.cursor,\n new Date().toISOString(),\n tenantId,\n runtime,\n since,\n );\n return { cursor: page.cursor, published };\n }\n /** Operator-only recovery: call after reconciling retained source state externally. */\n async resumeAfterResync(cursor: number): Promise<void> {\n if (!Number.isSafeInteger(cursor) || cursor < 0)\n throw new Error('Invalid webhook change cursor.');\n const tenantId = requireTenant().tenantId;\n const { db, runtime } = this.dispatcher.store;\n await db.query(\n 'UPDATE _smrt_webhook_cursors SET position = ? WHERE tenant_id = ? AND runtime = ?',\n cursor,\n tenantId,\n runtime,\n );\n }\n}\n","import { randomUUID } from 'node:crypto';\nimport {\n GlobalInterceptors,\n type InterceptorContext,\n type SmrtObject,\n} from '@happyvertical/smrt-core';\nimport { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { WebhookDispatcher } from './dispatcher.js';\n\n/** Opt-in lifecycle binding. Explicit model allowlist prevents recursive/internal data publication.\n * Payloads contain record identity only; use dispatch() for authorized custom projections.\n */\nexport function registerWebhookModelEvents(\n dispatcher: WebhookDispatcher,\n models: readonly string[],\n): () => void {\n const internal = new Set([\n 'WebhookSubscription',\n 'WebhookDelivery',\n 'WebhookDeliveryTask',\n 'WebhookCursor',\n 'SmrtJob',\n 'SmrtJobEvent',\n 'SmrtWorker',\n ]);\n if (models.some((name) => internal.has(name.split(':').at(-1) ?? name))) {\n throw new Error(\n 'Internal queue and webhook models cannot publish lifecycle webhooks.',\n );\n }\n const allowed = new Set(models);\n const pending = new WeakMap<\n InterceptorContext,\n { event: string; id: string }\n >();\n const matches = (context: InterceptorContext) =>\n allowed.has(context.qualifiedClassName ?? context.className);\n async function emit(\n instance: SmrtObject,\n context: InterceptorContext,\n event: string,\n ) {\n if (!matches(context)) return;\n const tenantId = requireTenant().tenantId;\n if ('tenantId' in instance && instance.tenantId !== tenantId)\n throw new Error('Webhook model tenant mismatch.');\n await dispatcher.dispatch({\n id: pending.get(context)?.id ?? randomUUID(),\n event,\n model: context.qualifiedClassName ?? context.className,\n occurredAt: context.timestamp.toISOString(),\n data: { id: instance.id },\n });\n }\n const interceptor = {\n name: `webhook-model-events:${randomUUID()}`,\n beforeSave(instance: SmrtObject, context: InterceptorContext) {\n if (matches(context))\n pending.set(context, {\n event: instance.isPersisted ? 'update' : 'create',\n id: randomUUID(),\n });\n },\n async afterSave(instance: SmrtObject, context: InterceptorContext) {\n await emit(instance, context, pending.get(context)?.event ?? 'update');\n },\n async afterDelete(instance: SmrtObject, context: InterceptorContext) {\n await emit(instance, context, 'delete');\n },\n };\n GlobalInterceptors.register(interceptor);\n return () => {\n GlobalInterceptors.unregister(interceptor);\n };\n}\n","import { SmrtRecipe } from '@happyvertical/smrt-core';\nimport {\n WebhookCursor,\n WebhookDelivery,\n WebhookDeliveryTask,\n WebhookSubscription,\n} from './models.js';\n/** Server-backed administration through authenticated host callbacks. */\nexport class WebhooksRecipe extends SmrtRecipe {\n static id = 'integrations.webhooks';\n static label = 'Outbound webhooks';\n static summary =\n 'Deliver signed model events and inspect delivery attempts from a server.';\n static models = [\n WebhookSubscription,\n WebhookDelivery,\n WebhookDeliveryTask,\n WebhookCursor,\n ];\n static group = {\n id: 'integrations',\n label: 'Integrations',\n summary: 'Connect your application to external services.',\n };\n static runtime = 'server' as const;\n static surfaces = [\n {\n kind: 'settings-panel',\n export: '@happyvertical/smrt-webhooks/svelte#WebhookAdmin',\n label: 'Outbound webhooks',\n },\n ] as const;\n // Administration uses the authorized service, never generated model CRUD.\n static nav = [];\n static help = './webhooks.recipe.md';\n}\n"],"mappings":";;;;;;AAOA,eAAe,wBAAwB,KAAK,MAAM,6rpBAAmkuB,CAAC;;;ACF/muB,IAAM,6BAAN,cAAyC,MAAM;CACpD,YAAqB,cAAsB;EACzC,MACE,qFACF;EAHmB,KAAA,eAAA;CAIrB;CAJqB;AAKvB;AAMO,IAAM,oBAAN,MAAwB;CAC7B,YACmB,YACA,QACjB;EAFiB,KAAA,aAAA;EACA,KAAA,SAAA;EAEjB,IACE,CAAC,OAAO,KAAK,MAAM,CAAA,CAAE,UACrB,OAAO,KAAK,MAAM,CAAA,CAAE,MAAM,UAAU,MAAM,WAAW,QAAQ,CAAC,KAC9D,OAAO,OAAO,MAAM,CAAA,CAAE,MAAM,UAAU,CAAC,KAAK,GAE5C,MAAM,IAAI,MAAM,iDAAiD;CACrE;CATmB;CACA;;;;;CAanB,MAAM,OAAuD;EAC3D,MAAM,WAAW,cAAc,CAAA,CAAE;EACjC,MAAM,EAAE,IAAI,YAAY,KAAK,WAAW;EACxC,MAAM,uBAAM,IAAI,KAAK,EAAA,CAAE,YAAY;EACnC,MAAM,KAAK,WAAW;EACtB,MAAM,GAAG,MACP;sFAEA,IACA,IACA,UACA,SACA,KACA,GACF;EACA,MAAM,OAAO,MAAM,GAAG,MACpB,kFACA,UACA,OACF;EACA,MAAM,QAAQ,OAAQ,KAAK,KAAK,EAAC,CAA2B,QAAQ;EACpE,MAAM,OAAO,MAAM,gBAAgB,IAAI;GACrC;GACA;GACA,QAAQ,OAAO,KAAK,KAAK,MAAM;GAC/B,OAAO;EACT,CAAC;EACD,IAAI,KAAK,gBACP,MAAM,IAAI,2BAA2B,KAAK,gBAAgB,KAAK,MAAM;EACvE,IAAI,YAAY;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,WAAW,SAAS;GACxB,IAAI,QAAQ,IAAI,OAAO,CAAA,EAAG,MAAM,WAAW;GAC3C;GACA,OAAO,QAAQ,sBAAsB,QAAQ;GAC7C,YAAY,QAAQ,UAAU,YAAY;GAC1C,MAAM,EAAE,IAAI,SAAS,GAAG;EAC1B,CAAC;CACH;CACA,MAAM,cAAc;EAClB,MAAM,wBAAwB,WAAW;EACzC,WAAW,UAAsB,SAA6B;GAC5D,IAAI,QAAQ,OAAO,GACjB,QAAQ,IAAI,SAAS;IACnB,OAAO,SAAS,cAAc,WAAW;IACzC,IAAI,WAAW;GACjB,CAAC;EACL;EACA,MAAM,UAAU,UAAsB,SAA6B;GACjE,MAAM,KAAK,UAAU,SAAS,QAAQ,IAAI,OAAO,CAAA,EAAG,SAAS,QAAQ;EACvE;EACA,MAAM,YAAY,UAAsB,SAA6B;GACnE,MAAM,KAAK,UAAU,SAAS,QAAQ;EACxC;CACF;CACA,mBAAmB,SAAS,WAAW;CACvC,aAAa;EACX,mBAAmB,WAAW,WAAW;CAC3C;AACF;;;AClEO,IAAM,iBAAN,cAA6B,WAAW;CAC7C,OAAO,KAAK;CACZ,OAAO,QAAQ;CACf,OAAO,UACL;CACF,OAAO,SAAS;EACd;EACA;EACA;EACA;CACF;CACA,OAAO,QAAQ;EACb,IAAI;EACJ,OAAO;EACP,SAAS;CACX;CACA,OAAO,UAAU;CACjB,OAAO,WAAW,CAChB;EACE,MAAM;EACN,QAAQ;EACR,OAAO;CACT,CACF;CAEA,OAAO,MAAM,CAAC;CACd,OAAO,OAAO;AAChB"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/__smrt-register__.ts","../src/change-feed.ts","../src/events.ts","../src/recipes.ts"],"sourcesContent":["// Generated by @happyvertical/smrt-core smrtPlugin at library build time.\n// The package manifest is inlined so self-registration cannot miss when a\n// downstream bundler relocates this module away from dist/manifest.json\n// (https://github.com/happyvertical/smrt/issues/1506,\n// https://github.com/happyvertical/smrt/issues/1507).\nimport { ObjectRegistry } from '@happyvertical/smrt-core';\n\nObjectRegistry.registerPackageManifest(JSON.parse(\"{\\\"version\\\":\\\"1.0.0\\\",\\\"timestamp\\\":0,\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"packageVersion\\\":\\\"0.61.4\\\",\\\"objects\\\":{\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\":{\\\"name\\\":\\\"webhooksubscription\\\",\\\"className\\\":\\\"WebhookSubscription\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\",\\\"collection\\\":\\\"webhooksubscriptions\\\",\\\"description\\\":\\\"Server-only subscription. Hosts authorize administration before accessing it.\\\",\\\"filePath\\\":\\\"src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":true,\\\"autoPopulate\\\":true,\\\"nullable\\\":false,\\\"mode\\\":\\\"required\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false},\\\"__statedOptions\\\":[\\\"sqlType\\\",\\\"requiredFor\\\",\\\"__tenancy\\\"],\\\"sqlType\\\":\\\"UUID\\\",\\\"requiredFor\\\":\\\"tenant-scope\\\"},\\\"required\\\":true},\\\"url\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\"],\\\"required\\\":true,\\\"requiredFor\\\":\\\"system-table\\\"},\\\"required\\\":true},\\\"events\\\":{\\\"type\\\":\\\"json\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[]},\\\"required\\\":false},\\\"models\\\":{\\\"type\\\":\\\"json\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[]},\\\"required\\\":false},\\\"secret\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"sensitive\\\",\\\"required\\\",\\\"requiredFor\\\"],\\\"required\\\":true,\\\"sensitive\\\":true,\\\"requiredFor\\\":\\\"system-table\\\"},\\\"required\\\":true,\\\"sensitive\\\":true},\\\"enabled\\\":{\\\"type\\\":\\\"boolean\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"default\\\"],\\\"default\\\":true},\\\"required\\\":false,\\\"default\\\":true}},\\\"methods\\\":{\\\"save\\\":{\\\"name\\\":\\\"save\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"options\\\",\\\"type\\\":\\\"SmrtSaveOptions\\\",\\\"optional\\\":true}],\\\"returnType\\\":\\\"Promise<this>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"tenantScoped\\\":{\\\"mode\\\":\\\"required\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookSubscription\\\",\\\"collectionExportName\\\":\\\"WebhookSubscriptionCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"url\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"secret\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_subscriptions\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"url\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"events\\\\\\\" JSON,\\\\n \\\\\\\"models\\\\\\\" JSON,\\\\n \\\\\\\"secret\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"enabled\\\\\\\" BOOLEAN DEFAULT TRUE\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"url\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"events\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"models\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"secret\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"enabled\\\":{\\\"type\\\":\\\"BOOLEAN\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":true}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_subscriptions_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_subscriptions_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"1979c7f5\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection\\\":{\\\"name\\\":\\\"webhooksubscriptioncollection\\\",\\\"className\\\":\\\"WebhookSubscriptionCollection\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookSubscriptionCollection\\\",\\\"collection\\\":\\\"webhooksubscriptions\\\",\\\"filePath\\\":\\\"src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false},\\\"extends\\\":\\\"SmrtCollection\\\",\\\"extendsTypeArg\\\":\\\"WebhookSubscription\\\",\\\"exportName\\\":\\\"WebhookSubscriptionCollection\\\",\\\"collectionExportName\\\":\\\"WebhookSubscriptionCollectionCollection\\\",\\\"collectionOf\\\":\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\",\\\"inheritedExposure\\\":[\\\"api\\\",\\\"mcp\\\",\\\"cli\\\"],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_subscriptions\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"url\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"events\\\\\\\" JSON,\\\\n \\\\\\\"models\\\\\\\" JSON,\\\\n \\\\\\\"secret\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"enabled\\\\\\\" BOOLEAN DEFAULT TRUE\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"url\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"events\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"models\\\":{\\\"type\\\":\\\"JSON\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"secret\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"enabled\\\":{\\\"type\\\":\\\"BOOLEAN\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":true}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_subscriptions_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_subscriptions_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"1979c7f5\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\":{\\\"name\\\":\\\"webhookdelivery\\\",\\\"className\\\":\\\"WebhookDelivery\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\",\\\"collection\\\":\\\"webhookdeliveries\\\",\\\"description\\\":\\\"Durable outbox and safe outcome metadata; payload never appears in public projections.\\\",\\\"filePath\\\":\\\"src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":true,\\\"autoPopulate\\\":true,\\\"nullable\\\":false,\\\"mode\\\":\\\"required\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false},\\\"__statedOptions\\\":[\\\"sqlType\\\",\\\"requiredFor\\\",\\\"__tenancy\\\"],\\\"sqlType\\\":\\\"UUID\\\",\\\"requiredFor\\\":\\\"tenant-scope\\\"},\\\"required\\\":true},\\\"subscriptionId\\\":{\\\"type\\\":\\\"foreignKey\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"onUpdate\\\",\\\"onDelete\\\",\\\"related\\\"],\\\"onUpdate\\\":\\\"RESTRICT\\\",\\\"onDelete\\\":\\\"RESTRICT\\\"},\\\"required\\\":false,\\\"related\\\":\\\"WebhookSubscription\\\"},\\\"eventId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\"],\\\"required\\\":true,\\\"requiredFor\\\":\\\"identity\\\"},\\\"required\\\":true},\\\"payload\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"sensitive\\\"],\\\"required\\\":true,\\\"sensitive\\\":true},\\\"required\\\":true,\\\"sensitive\\\":true},\\\"status\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"default\\\"],\\\"default\\\":\\\"pending\\\"},\\\"required\\\":false,\\\"default\\\":\\\"pending\\\"},\\\"generation\\\":{\\\"type\\\":\\\"integer\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"default\\\"],\\\"default\\\":0},\\\"required\\\":false,\\\"default\\\":0},\\\"attempts\\\":{\\\"type\\\":\\\"integer\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"default\\\"],\\\"default\\\":0},\\\"required\\\":false,\\\"default\\\":0},\\\"responseStatus\\\":{\\\"type\\\":\\\"integer\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"error\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false},\\\"leaseToken\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"sensitive\\\",\\\"required\\\"],\\\"sensitive\\\":true,\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false,\\\"sensitive\\\":true},\\\"leaseUntil\\\":{\\\"type\\\":\\\"datetime\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"nullable\\\",\\\"required\\\"],\\\"nullable\\\":true,\\\"required\\\":false},\\\"required\\\":false}},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_delivery_identity\\\",\\\"columns\\\":[\\\"tenantId\\\",\\\"subscriptionId\\\",\\\"eventId\\\"],\\\"unique\\\":true}],\\\"tenantScoped\\\":{\\\"mode\\\":\\\"required\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookDelivery\\\",\\\"collectionExportName\\\":\\\"WebhookDeliveryCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"eventId\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"},{\\\"field\\\":\\\"payload\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_deliveries\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"subscription_id\\\\\\\" UUID,\\\\n \\\\\\\"event_id\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"payload\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"status\\\\\\\" TEXT DEFAULT 'pending',\\\\n \\\\\\\"generation\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"attempts\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"response_status\\\\\\\" INTEGER,\\\\n \\\\\\\"error\\\\\\\" TEXT,\\\\n \\\\\\\"lease_token\\\\\\\" TEXT,\\\\n \\\\\\\"lease_until\\\\\\\" TIMESTAMP\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"subscription_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"foreignKey\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"foreignKey\\\":{\\\"table\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"column\\\":\\\"id\\\",\\\"onDelete\\\":\\\"RESTRICT\\\",\\\"onUpdate\\\":\\\"RESTRICT\\\"}},\\\"event_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"payload\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"status\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":\\\"pending\\\"},\\\"generation\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"attempts\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"response_status\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"error\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_token\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_until\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":false,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_deliveries_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_delivery_identity\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"subscription_id\\\",\\\"event_id\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_deliveries_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]},{\\\"name\\\":\\\"_smrt_webhook_deliveries_subscription_id_idx\\\",\\\"columns\\\":[\\\"subscription_id\\\"]}],\\\"version\\\":\\\"ed54179d\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookDeliveryCollection\\\":{\\\"name\\\":\\\"webhookdeliverycollection\\\",\\\"className\\\":\\\"WebhookDeliveryCollection\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookDeliveryCollection\\\",\\\"collection\\\":\\\"webhookdeliveries\\\",\\\"filePath\\\":\\\"src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"api\\\":false,\\\"mcp\\\":false,\\\"cli\\\":false},\\\"extends\\\":\\\"SmrtCollection\\\",\\\"extendsTypeArg\\\":\\\"WebhookDelivery\\\",\\\"exportName\\\":\\\"WebhookDeliveryCollection\\\",\\\"collectionExportName\\\":\\\"WebhookDeliveryCollectionCollection\\\",\\\"collectionOf\\\":\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\",\\\"inheritedExposure\\\":[\\\"api\\\",\\\"mcp\\\",\\\"cli\\\"],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_deliveries\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_deliveries\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"subscription_id\\\\\\\" UUID,\\\\n \\\\\\\"event_id\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"payload\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"status\\\\\\\" TEXT DEFAULT 'pending',\\\\n \\\\\\\"generation\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"attempts\\\\\\\" INTEGER DEFAULT 0,\\\\n \\\\\\\"response_status\\\\\\\" INTEGER,\\\\n \\\\\\\"error\\\\\\\" TEXT,\\\\n \\\\\\\"lease_token\\\\\\\" TEXT,\\\\n \\\\\\\"lease_until\\\\\\\" TIMESTAMP\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"subscription_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"foreignKey\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"foreignKey\\\":{\\\"table\\\":\\\"_smrt_webhook_subscriptions\\\",\\\"column\\\":\\\"id\\\",\\\"onDelete\\\":\\\"RESTRICT\\\",\\\"onUpdate\\\":\\\"RESTRICT\\\"}},\\\"event_id\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"payload\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"status\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":\\\"pending\\\"},\\\"generation\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"attempts\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0},\\\"response_status\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"error\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_token\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":false,\\\"unique\\\":false},\\\"lease_until\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":false,\\\"unique\\\":false}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_deliveries_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_delivery_identity\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"subscription_id\\\",\\\"event_id\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_deliveries_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]},{\\\"name\\\":\\\"_smrt_webhook_deliveries_subscription_id_idx\\\",\\\"columns\\\":[\\\"subscription_id\\\"]}],\\\"version\\\":\\\"ed54179d\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookDeliveryTask\\\":{\\\"name\\\":\\\"webhookdeliverytask\\\",\\\"className\\\":\\\"WebhookDeliveryTask\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookDeliveryTask\\\",\\\"collection\\\":\\\"webhookdeliverytasks\\\",\\\"description\\\":\\\"Jobs queue entry point; persisted arguments contain IDs only.\\\",\\\"filePath\\\":\\\"src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{},\\\"methods\\\":{\\\"deliver\\\":{\\\"name\\\":\\\"deliver\\\",\\\"async\\\":true,\\\"parameters\\\":[{\\\"name\\\":\\\"args\\\",\\\"type\\\":\\\"Record<string, unknown>\\\",\\\"optional\\\":true},{\\\"name\\\":\\\"_context\\\",\\\"type\\\":\\\"JobExecutionContext\\\",\\\"optional\\\":true}],\\\"returnType\\\":\\\"Promise<void>\\\",\\\"isStatic\\\":false,\\\"isPublic\\\":true}},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_delivery_tasks\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookDeliveryTask\\\",\\\"collectionExportName\\\":\\\"WebhookDeliveryTaskCollection\\\",\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_delivery_tasks\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_delivery_tasks\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_delivery_tasks_slug_context_idx\\\",\\\"columns\\\":[\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_delivery_tasks_created_at_idx\\\",\\\"columns\\\":[\\\"created_at\\\"]}],\\\"version\\\":\\\"268c614c\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"},\\\"@happyvertical/smrt-webhooks:WebhookCursor\\\":{\\\"name\\\":\\\"webhookcursor\\\",\\\"className\\\":\\\"WebhookCursor\\\",\\\"qualifiedName\\\":\\\"@happyvertical/smrt-webhooks:WebhookCursor\\\",\\\"collection\\\":\\\"webhookcursors\\\",\\\"description\\\":\\\"Tenant-bound durable cursor for replayable model change-feed publication.\\\",\\\"filePath\\\":\\\"src/models.ts\\\",\\\"packageName\\\":\\\"@happyvertical/smrt-webhooks\\\",\\\"fields\\\":{\\\"tenantId\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__tenancy\\\":{\\\"isTenantIdField\\\":true,\\\"autoFilter\\\":true,\\\"required\\\":true,\\\"autoPopulate\\\":true,\\\"nullable\\\":false,\\\"mode\\\":\\\"required\\\",\\\"field\\\":\\\"tenantId\\\",\\\"allowSuperAdminBypass\\\":false},\\\"__statedOptions\\\":[\\\"sqlType\\\",\\\"requiredFor\\\",\\\"__tenancy\\\"],\\\"sqlType\\\":\\\"UUID\\\",\\\"requiredFor\\\":\\\"tenant-scope\\\"},\\\"required\\\":true},\\\"runtime\\\":{\\\"type\\\":\\\"text\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"required\\\",\\\"requiredFor\\\"],\\\"required\\\":true,\\\"requiredFor\\\":\\\"identity\\\"},\\\"required\\\":true},\\\"position\\\":{\\\"type\\\":\\\"integer\\\",\\\"_meta\\\":{\\\"__statedOptions\\\":[\\\"default\\\"],\\\"default\\\":0},\\\"required\\\":false,\\\"default\\\":0}},\\\"methods\\\":{},\\\"decoratorConfig\\\":{\\\"tableName\\\":\\\"_smrt_webhook_cursors\\\",\\\"api\\\":false,\\\"cli\\\":false,\\\"mcp\\\":false,\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_cursor_identity\\\",\\\"columns\\\":[\\\"tenantId\\\",\\\"runtime\\\"],\\\"unique\\\":true}],\\\"tenantScoped\\\":{\\\"mode\\\":\\\"required\\\"},\\\"conflictColumns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"]},\\\"extends\\\":\\\"SmrtObject\\\",\\\"exportName\\\":\\\"WebhookCursor\\\",\\\"collectionExportName\\\":\\\"WebhookCursorCollection\\\",\\\"validationRules\\\":[{\\\"field\\\":\\\"runtime\\\",\\\"rule\\\":\\\"required\\\",\\\"fieldType\\\":\\\"text\\\"}],\\\"schema\\\":{\\\"tableName\\\":\\\"_smrt_webhook_cursors\\\",\\\"ddl\\\":\\\"CREATE TABLE IF NOT EXISTS \\\\\\\"_smrt_webhook_cursors\\\\\\\" (\\\\n \\\\\\\"_sync_origin_device_id\\\\\\\" TEXT,\\\\n \\\\\\\"_sync_revision\\\\\\\" INTEGER,\\\\n \\\\\\\"id\\\\\\\" UUID PRIMARY KEY NOT NULL,\\\\n \\\\\\\"slug\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"context\\\\\\\" TEXT NOT NULL DEFAULT '',\\\\n \\\\\\\"created_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"updated_at\\\\\\\" TIMESTAMP NOT NULL DEFAULT current_timestamp,\\\\n \\\\\\\"tenant_id\\\\\\\" UUID NOT NULL,\\\\n \\\\\\\"runtime\\\\\\\" TEXT NOT NULL,\\\\n \\\\\\\"position\\\\\\\" INTEGER DEFAULT 0\\\\n);\\\",\\\"columns\\\":{\\\"_sync_origin_device_id\\\":{\\\"type\\\":\\\"TEXT\\\"},\\\"_sync_revision\\\":{\\\"type\\\":\\\"INTEGER\\\"},\\\"id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"primaryKey\\\":true,\\\"referenceKind\\\":\\\"id\\\",\\\"notNull\\\":true},\\\"slug\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true},\\\"context\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"\\\"},\\\"created_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"updated_at\\\":{\\\"type\\\":\\\"TIMESTAMP\\\",\\\"notNull\\\":true,\\\"default\\\":\\\"current_timestamp\\\"},\\\"tenant_id\\\":{\\\"type\\\":\\\"UUID\\\",\\\"referenceKind\\\":\\\"tenantId\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"runtime\\\":{\\\"type\\\":\\\"TEXT\\\",\\\"notNull\\\":true,\\\"unique\\\":false},\\\"position\\\":{\\\"type\\\":\\\"INTEGER\\\",\\\"notNull\\\":false,\\\"unique\\\":false,\\\"default\\\":0}},\\\"indexes\\\":[{\\\"name\\\":\\\"_smrt_webhook_cursors_slug_context_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"slug\\\",\\\"context\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_cursor_identity\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"runtime\\\"],\\\"unique\\\":true},{\\\"name\\\":\\\"_smrt_webhook_cursors_tenant_id_created_at_idx\\\",\\\"columns\\\":[\\\"tenant_id\\\",\\\"created_at\\\"]}],\\\"version\\\":\\\"f46a5a8e\\\"},\\\"importPath\\\":\\\"@happyvertical/smrt-webhooks\\\"}},\\\"moduleType\\\":\\\"smrt\\\",\\\"recipes\\\":[{\\\"id\\\":\\\"integrations.webhooks\\\",\\\"className\\\":\\\"WebhooksRecipe\\\",\\\"label\\\":\\\"Outbound webhooks\\\",\\\"summary\\\":\\\"Deliver signed model events and inspect delivery attempts from a server.\\\",\\\"synonyms\\\":[],\\\"models\\\":[\\\"@happyvertical/smrt-webhooks:WebhookSubscription\\\",\\\"@happyvertical/smrt-webhooks:WebhookDelivery\\\",\\\"@happyvertical/smrt-webhooks:WebhookDeliveryTask\\\",\\\"@happyvertical/smrt-webhooks:WebhookCursor\\\"],\\\"nav\\\":[],\\\"requires\\\":[],\\\"group\\\":{\\\"id\\\":\\\"integrations\\\",\\\"label\\\":\\\"Integrations\\\",\\\"summary\\\":\\\"Connect your application to external services.\\\"},\\\"help\\\":{\\\"markdown\\\":\\\"## Overview\\\\n\\\\nSend signed event notifications to an external HTTPS endpoint. Administrators\\\\ncan pause subscriptions and inspect delivery attempts. This integration requires\\\\na server and a running background worker.\\\\n\\\\n## Tasks\\\\n\\\\n- Add a subscription with a public HTTPS endpoint, signing secret, and event/model filters.\\\\n- Disable a subscription to cancel unsent deliveries.\\\\n- Inspect the delivery log, then retry failed deliveries after correcting their endpoint.\\\\n- Ask the endpoint owner to verify signatures and deduplicate delivery IDs.\\\\n\\\",\\\"fieldRefs\\\":[]},\\\"surfaces\\\":[{\\\"kind\\\":\\\"settings-panel\\\",\\\"export\\\":\\\"@happyvertical/smrt-webhooks/svelte#WebhookAdmin\\\",\\\"label\\\":\\\"Outbound webhooks\\\"}],\\\"runtime\\\":\\\"server\\\",\\\"demo\\\":{\\\"mode\\\":\\\"server\\\",\\\"reasons\\\":[\\\"The recipe declares runtime \\\\\\\"server\\\\\\\".\\\",\\\"Needs a server because its package does not build for a browser: Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.; and its package depends on @happyvertical/smrt-jobs, @happyvertical/smrt-tenancy, which do not build for a browser (#3615, #3624, #3627, #3717).\\\"]}}],\\\"smrtDependencies\\\":[\\\"@happyvertical/smrt-core\\\",\\\"@happyvertical/smrt-jobs\\\",\\\"@happyvertical/smrt-tenancy\\\"],\\\"browser\\\":{\\\"status\\\":\\\"server-only\\\",\\\"issues\\\":[\\\"#3615\\\",\\\"#3624\\\",\\\"#3627\\\",\\\"#3717\\\"],\\\"reason\\\":\\\"Intentionally server-only outbound delivery: node:crypto HMAC and node:https/dns/net pinned transport enforce signing and SSRF protection. Browser hosts use the separate /svelte admin export with authenticated server callbacks.\\\",\\\"via\\\":[\\\"@happyvertical/smrt-jobs\\\",\\\"@happyvertical/smrt-tenancy\\\"]},\\\"stampsConstructors\\\":true}\"));\n","import { randomUUID } from 'node:crypto';\nimport { getChangesSince } from '@happyvertical/smrt-core';\nimport { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { WebhookDispatcher } from './dispatcher.js';\n\nexport class WebhookHistoryExpiredError extends Error {\n constructor(readonly resumeCursor: number) {\n super(\n 'Webhook change history expired; reconcile source state before resetting the cursor.',\n );\n }\n}\n\n/** Durable, replayable lifecycle publication from SMRT's committed change feed.\n * Host scheduling calls poll() in each authenticated tenant context. The mapping\n * is an explicit physical-table allowlist; shared STI tables represent the base model.\n */\nexport class WebhookChangeFeed {\n constructor(\n private readonly dispatcher: WebhookDispatcher,\n private readonly models: Readonly<Record<string, string>>,\n ) {\n if (\n !Object.keys(models).length ||\n Object.keys(models).some((table) => table.startsWith('_smrt_')) ||\n Object.values(models).some((model) => !model)\n )\n throw new Error('Explicit application model tables are required.');\n }\n /** Cursor only advances after all matched changes have durable outbox/jobs.\n * A crash or partial failure replays the same stable identities on the next poll.\n * History pruning fails loudly: the host must reconcile source state before reset.\n */\n async poll(): Promise<{ cursor: number; published: number }> {\n const tenantId = requireTenant().tenantId;\n const { db, runtime } = this.dispatcher.store;\n const now = new Date().toISOString();\n const id = randomUUID();\n await db.query(\n `INSERT INTO _smrt_webhook_cursors (id, slug, context, tenant_id, runtime, position, created_at, updated_at)\n VALUES (?, ?, '', ?, ?, 0, ?, ?) ON CONFLICT (tenant_id, runtime) DO NOTHING`,\n id,\n id,\n tenantId,\n runtime,\n now,\n now,\n );\n const rows = await db.query(\n 'SELECT position FROM _smrt_webhook_cursors WHERE tenant_id = ? AND runtime = ?',\n tenantId,\n runtime,\n );\n const since = Number((rows.rows[0] as { position: number }).position);\n const page = await getChangesSince(db, {\n since,\n tenantId,\n tables: Object.keys(this.models),\n limit: 500,\n });\n if (page.resyncRequired)\n throw new WebhookHistoryExpiredError(page.resyncCursor ?? page.cursor);\n let published = 0;\n for (const change of page.changes) {\n // Core's tenant feed includes global rows; webhooks deliberately do not.\n if (\n change.tenantId !== tenantId ||\n !change.rowId ||\n !this.models[change.table]\n )\n continue;\n await this.dispatcher.dispatch({\n id: `change:${change.seq}`,\n event: change.operation,\n model: this.models[change.table],\n occurredAt: change.timestamp,\n data: { id: change.rowId },\n });\n published++;\n }\n await db.query(\n 'UPDATE _smrt_webhook_cursors SET position = ?, updated_at = ? WHERE tenant_id = ? AND runtime = ? AND position = ?',\n page.cursor,\n new Date().toISOString(),\n tenantId,\n runtime,\n since,\n );\n return { cursor: page.cursor, published };\n }\n /** Operator-only recovery: call after reconciling retained source state externally. */\n async resumeAfterResync(cursor: number): Promise<void> {\n if (!Number.isSafeInteger(cursor) || cursor < 0)\n throw new Error('Invalid webhook change cursor.');\n const tenantId = requireTenant().tenantId;\n const { db, runtime } = this.dispatcher.store;\n await db.query(\n 'UPDATE _smrt_webhook_cursors SET position = ? WHERE tenant_id = ? AND runtime = ?',\n cursor,\n tenantId,\n runtime,\n );\n }\n}\n","import { randomUUID } from 'node:crypto';\nimport {\n GlobalInterceptors,\n type InterceptorContext,\n type SmrtObject,\n} from '@happyvertical/smrt-core';\nimport { requireTenant } from '@happyvertical/smrt-tenancy';\nimport type { WebhookDispatcher } from './dispatcher.js';\n\n/** Opt-in lifecycle binding. Explicit model allowlist prevents recursive/internal data publication.\n * Payloads contain record identity only; use dispatch() for authorized custom projections.\n */\nexport function registerWebhookModelEvents(\n dispatcher: WebhookDispatcher,\n models: readonly string[],\n): () => void {\n const internal = new Set([\n 'WebhookSubscription',\n 'WebhookDelivery',\n 'WebhookDeliveryTask',\n 'WebhookCursor',\n 'SmrtJob',\n 'SmrtJobEvent',\n 'SmrtWorker',\n ]);\n if (models.some((name) => internal.has(name.split(':').at(-1) ?? name))) {\n throw new Error(\n 'Internal queue and webhook models cannot publish lifecycle webhooks.',\n );\n }\n const allowed = new Set(models);\n const pending = new WeakMap<\n InterceptorContext,\n { event: string; id: string }\n >();\n const matches = (context: InterceptorContext) =>\n allowed.has(context.qualifiedClassName ?? context.className);\n async function emit(\n instance: SmrtObject,\n context: InterceptorContext,\n event: string,\n ) {\n if (!matches(context)) return;\n const tenantId = requireTenant().tenantId;\n if ('tenantId' in instance && instance.tenantId !== tenantId)\n throw new Error('Webhook model tenant mismatch.');\n await dispatcher.dispatch({\n id: pending.get(context)?.id ?? randomUUID(),\n event,\n model: context.qualifiedClassName ?? context.className,\n occurredAt: context.timestamp.toISOString(),\n data: { id: instance.id },\n });\n }\n const interceptor = {\n name: `webhook-model-events:${randomUUID()}`,\n beforeSave(instance: SmrtObject, context: InterceptorContext) {\n if (matches(context))\n pending.set(context, {\n event: instance.isPersisted ? 'update' : 'create',\n id: randomUUID(),\n });\n },\n async afterSave(instance: SmrtObject, context: InterceptorContext) {\n await emit(instance, context, pending.get(context)?.event ?? 'update');\n },\n async afterDelete(instance: SmrtObject, context: InterceptorContext) {\n await emit(instance, context, 'delete');\n },\n };\n GlobalInterceptors.register(interceptor);\n return () => {\n GlobalInterceptors.unregister(interceptor);\n };\n}\n","import { SmrtRecipe } from '@happyvertical/smrt-core';\nimport {\n WebhookCursor,\n WebhookDelivery,\n WebhookDeliveryTask,\n WebhookSubscription,\n} from './models.js';\n/** Server-backed administration through authenticated host callbacks. */\nexport class WebhooksRecipe extends SmrtRecipe {\n static id = 'integrations.webhooks';\n static label = 'Outbound webhooks';\n static summary =\n 'Deliver signed model events and inspect delivery attempts from a server.';\n static models = [\n WebhookSubscription,\n WebhookDelivery,\n WebhookDeliveryTask,\n WebhookCursor,\n ];\n static group = {\n id: 'integrations',\n label: 'Integrations',\n summary: 'Connect your application to external services.',\n };\n static runtime = 'server' as const;\n static surfaces = [\n {\n kind: 'settings-panel',\n export: '@happyvertical/smrt-webhooks/svelte#WebhookAdmin',\n label: 'Outbound webhooks',\n },\n ] as const;\n // Administration uses the authorized service, never generated model CRUD.\n static nav = [];\n static help = './webhooks.recipe.md';\n}\n"],"mappings":";;;;;;AAOA,eAAe,wBAAwB,KAAK,MAAM,y+qBAAqgwB,CAAC;;;ACFjjwB,IAAM,6BAAN,cAAyC,MAAM;CACpD,YAAqB,cAAsB;EACzC,MACE,qFACF;EAHmB,KAAA,eAAA;CAIrB;CAJqB;AAKvB;AAMO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AC;EACL;EACA,MAAM,UAAU,UAAsB,SAA6B;GACjE,MAAM,KAAK,UAAU,SAAS,QAAQ,IAAI,OAAO,CAAA,EAAG,SAAS,QAAQ;EACvE;EACA,MAAM,YAAY,UAAsB,SAA6B;GACnE,MAAM,KAAK,UAAU,SAAS,QAAQ;EACxC;CACF;CACA,mBAAmB,SAAS,WAAW;CACvC,aAAa;EACX,mBAAmB,WAAW,WAAW;CAC3C;AACF;;;AClEO,IAAM,iBAAN,cAA6B,WAAW;CAC7C,OAAO,KAAK;CACZ,OAAO,QAAQ;CACf,OAAO,UACL;CACF,OAAO,SAAS;EACd;EACA;EACA;EACA;CACF;CACA,OAAO,QAAQ;EACb,IAAI;EACJ,OAAO;EACP,SAAS;CACX;CACA,OAAO,UAAU;CACjB,OAAO,WAAW,CAChB;EACE,MAAM;EACN,QAAQ;EACR,OAAO;CACT,CACF;CAEA,OAAO,MAAM,CAAC;CACd,OAAO,OAAO;AAChB"}
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-webhooks",
5
- "packageVersion": "0.61.3",
5
+ "packageVersion": "0.61.4",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-webhooks:WebhookSubscription": {
8
8
  "name": "webhooksubscription",
@@ -10,14 +10,12 @@
10
10
  "qualifiedName": "@happyvertical/smrt-webhooks:WebhookSubscription",
11
11
  "collection": "webhooksubscriptions",
12
12
  "description": "Server-only subscription. Hosts authorize administration before accessing it.",
13
- "filePath": "/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts",
13
+ "filePath": "src/models.ts",
14
14
  "packageName": "@happyvertical/smrt-webhooks",
15
15
  "fields": {
16
16
  "tenantId": {
17
17
  "type": "text",
18
- "required": true,
19
18
  "_meta": {
20
- "sqlType": "UUID",
21
19
  "__tenancy": {
22
20
  "isTenantIdField": true,
23
21
  "autoFilter": true,
@@ -27,42 +25,68 @@
27
25
  "mode": "required",
28
26
  "field": "tenantId",
29
27
  "allowSuperAdminBypass": false
30
- }
31
- }
28
+ },
29
+ "__statedOptions": [
30
+ "sqlType",
31
+ "requiredFor",
32
+ "__tenancy"
33
+ ],
34
+ "sqlType": "UUID",
35
+ "requiredFor": "tenant-scope"
36
+ },
37
+ "required": true
32
38
  },
33
39
  "url": {
34
40
  "type": "text",
35
- "required": true,
36
41
  "_meta": {
37
- "required": true
38
- }
42
+ "__statedOptions": [
43
+ "required",
44
+ "requiredFor"
45
+ ],
46
+ "required": true,
47
+ "requiredFor": "system-table"
48
+ },
49
+ "required": true
39
50
  },
40
51
  "events": {
41
52
  "type": "json",
42
- "required": false,
43
- "_meta": {}
53
+ "_meta": {
54
+ "__statedOptions": []
55
+ },
56
+ "required": false
44
57
  },
45
58
  "models": {
46
59
  "type": "json",
47
- "required": false,
48
- "_meta": {}
60
+ "_meta": {
61
+ "__statedOptions": []
62
+ },
63
+ "required": false
49
64
  },
50
65
  "secret": {
51
66
  "type": "text",
52
- "required": true,
53
67
  "_meta": {
68
+ "__statedOptions": [
69
+ "sensitive",
70
+ "required",
71
+ "requiredFor"
72
+ ],
73
+ "required": true,
54
74
  "sensitive": true,
55
- "required": true
75
+ "requiredFor": "system-table"
56
76
  },
77
+ "required": true,
57
78
  "sensitive": true
58
79
  },
59
80
  "enabled": {
60
81
  "type": "boolean",
61
- "required": false,
62
- "default": true,
63
82
  "_meta": {
83
+ "__statedOptions": [
84
+ "default"
85
+ ],
64
86
  "default": true
65
- }
87
+ },
88
+ "required": false,
89
+ "default": true
66
90
  }
67
91
  },
68
92
  "methods": {
@@ -205,7 +229,7 @@
205
229
  "className": "WebhookSubscriptionCollection",
206
230
  "qualifiedName": "@happyvertical/smrt-webhooks:WebhookSubscriptionCollection",
207
231
  "collection": "webhooksubscriptions",
208
- "filePath": "/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts",
232
+ "filePath": "src/models.ts",
209
233
  "packageName": "@happyvertical/smrt-webhooks",
210
234
  "fields": {},
211
235
  "methods": {},
@@ -321,14 +345,12 @@
321
345
  "qualifiedName": "@happyvertical/smrt-webhooks:WebhookDelivery",
322
346
  "collection": "webhookdeliveries",
323
347
  "description": "Durable outbox and safe outcome metadata; payload never appears in public projections.",
324
- "filePath": "/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts",
348
+ "filePath": "src/models.ts",
325
349
  "packageName": "@happyvertical/smrt-webhooks",
326
350
  "fields": {
327
351
  "tenantId": {
328
352
  "type": "text",
329
- "required": true,
330
353
  "_meta": {
331
- "sqlType": "UUID",
332
354
  "__tenancy": {
333
355
  "isTenantIdField": true,
334
356
  "autoFilter": true,
@@ -338,87 +360,139 @@
338
360
  "mode": "required",
339
361
  "field": "tenantId",
340
362
  "allowSuperAdminBypass": false
341
- }
342
- }
363
+ },
364
+ "__statedOptions": [
365
+ "sqlType",
366
+ "requiredFor",
367
+ "__tenancy"
368
+ ],
369
+ "sqlType": "UUID",
370
+ "requiredFor": "tenant-scope"
371
+ },
372
+ "required": true
343
373
  },
344
374
  "subscriptionId": {
345
375
  "type": "foreignKey",
346
- "required": false,
347
- "related": "WebhookSubscription",
348
376
  "_meta": {
349
- "onDelete": "RESTRICT",
350
- "onUpdate": "RESTRICT"
351
- }
377
+ "__statedOptions": [
378
+ "onUpdate",
379
+ "onDelete",
380
+ "related"
381
+ ],
382
+ "onUpdate": "RESTRICT",
383
+ "onDelete": "RESTRICT"
384
+ },
385
+ "required": false,
386
+ "related": "WebhookSubscription"
352
387
  },
353
388
  "eventId": {
354
389
  "type": "text",
355
- "required": true,
356
390
  "_meta": {
357
- "required": true
358
- }
391
+ "__statedOptions": [
392
+ "required",
393
+ "requiredFor"
394
+ ],
395
+ "required": true,
396
+ "requiredFor": "identity"
397
+ },
398
+ "required": true
359
399
  },
360
400
  "payload": {
361
401
  "type": "text",
362
- "required": true,
363
402
  "_meta": {
403
+ "__statedOptions": [
404
+ "required",
405
+ "sensitive"
406
+ ],
364
407
  "required": true,
365
408
  "sensitive": true
366
409
  },
410
+ "required": true,
367
411
  "sensitive": true
368
412
  },
369
413
  "status": {
370
414
  "type": "text",
371
- "required": false,
372
- "default": "pending",
373
415
  "_meta": {
416
+ "__statedOptions": [
417
+ "default"
418
+ ],
374
419
  "default": "pending"
375
- }
420
+ },
421
+ "required": false,
422
+ "default": "pending"
376
423
  },
377
424
  "generation": {
378
425
  "type": "integer",
379
- "required": false,
380
- "default": 0,
381
426
  "_meta": {
427
+ "__statedOptions": [
428
+ "default"
429
+ ],
382
430
  "default": 0
383
- }
431
+ },
432
+ "required": false,
433
+ "default": 0
384
434
  },
385
435
  "attempts": {
386
436
  "type": "integer",
387
- "required": false,
388
- "default": 0,
389
437
  "_meta": {
438
+ "__statedOptions": [
439
+ "default"
440
+ ],
390
441
  "default": 0
391
- }
442
+ },
443
+ "required": false,
444
+ "default": 0
392
445
  },
393
446
  "responseStatus": {
394
447
  "type": "integer",
395
- "required": false,
396
448
  "_meta": {
397
- "nullable": true
398
- }
449
+ "__statedOptions": [
450
+ "nullable",
451
+ "required"
452
+ ],
453
+ "nullable": true,
454
+ "required": false
455
+ },
456
+ "required": false
399
457
  },
400
458
  "error": {
401
459
  "type": "text",
402
- "required": false,
403
460
  "_meta": {
404
- "nullable": true
405
- }
461
+ "__statedOptions": [
462
+ "nullable",
463
+ "required"
464
+ ],
465
+ "nullable": true,
466
+ "required": false
467
+ },
468
+ "required": false
406
469
  },
407
470
  "leaseToken": {
408
471
  "type": "text",
409
- "required": false,
410
472
  "_meta": {
473
+ "__statedOptions": [
474
+ "nullable",
475
+ "sensitive",
476
+ "required"
477
+ ],
478
+ "sensitive": true,
411
479
  "nullable": true,
412
- "sensitive": true
480
+ "required": false
413
481
  },
482
+ "required": false,
414
483
  "sensitive": true
415
484
  },
416
485
  "leaseUntil": {
417
486
  "type": "datetime",
418
- "required": false,
419
487
  "_meta": {
420
- "nullable": true
421
- }
488
+ "__statedOptions": [
489
+ "nullable",
490
+ "required"
491
+ ],
492
+ "nullable": true,
493
+ "required": false
494
+ },
495
+ "required": false
422
496
  }
423
497
  },
424
498
  "methods": {},
@@ -606,7 +680,7 @@
606
680
  "className": "WebhookDeliveryCollection",
607
681
  "qualifiedName": "@happyvertical/smrt-webhooks:WebhookDeliveryCollection",
608
682
  "collection": "webhookdeliveries",
609
- "filePath": "/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts",
683
+ "filePath": "src/models.ts",
610
684
  "packageName": "@happyvertical/smrt-webhooks",
611
685
  "fields": {},
612
686
  "methods": {},
@@ -771,7 +845,7 @@
771
845
  "qualifiedName": "@happyvertical/smrt-webhooks:WebhookDeliveryTask",
772
846
  "collection": "webhookdeliverytasks",
773
847
  "description": "Jobs queue entry point; persisted arguments contain IDs only.",
774
- "filePath": "/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts",
848
+ "filePath": "src/models.ts",
775
849
  "packageName": "@happyvertical/smrt-webhooks",
776
850
  "fields": {},
777
851
  "methods": {
@@ -866,14 +940,12 @@
866
940
  "qualifiedName": "@happyvertical/smrt-webhooks:WebhookCursor",
867
941
  "collection": "webhookcursors",
868
942
  "description": "Tenant-bound durable cursor for replayable model change-feed publication.",
869
- "filePath": "/home/runner/work/smrt/smrt/packages/webhooks/src/models.ts",
943
+ "filePath": "src/models.ts",
870
944
  "packageName": "@happyvertical/smrt-webhooks",
871
945
  "fields": {
872
946
  "tenantId": {
873
947
  "type": "text",
874
- "required": true,
875
948
  "_meta": {
876
- "sqlType": "UUID",
877
949
  "__tenancy": {
878
950
  "isTenantIdField": true,
879
951
  "autoFilter": true,
@@ -883,23 +955,39 @@
883
955
  "mode": "required",
884
956
  "field": "tenantId",
885
957
  "allowSuperAdminBypass": false
886
- }
887
- }
958
+ },
959
+ "__statedOptions": [
960
+ "sqlType",
961
+ "requiredFor",
962
+ "__tenancy"
963
+ ],
964
+ "sqlType": "UUID",
965
+ "requiredFor": "tenant-scope"
966
+ },
967
+ "required": true
888
968
  },
889
969
  "runtime": {
890
970
  "type": "text",
891
- "required": true,
892
971
  "_meta": {
893
- "required": true
894
- }
972
+ "__statedOptions": [
973
+ "required",
974
+ "requiredFor"
975
+ ],
976
+ "required": true,
977
+ "requiredFor": "identity"
978
+ },
979
+ "required": true
895
980
  },
896
981
  "position": {
897
982
  "type": "integer",
898
- "required": false,
899
- "default": 0,
900
983
  "_meta": {
984
+ "__statedOptions": [
985
+ "default"
986
+ ],
901
987
  "default": 0
902
- }
988
+ },
989
+ "required": false,
990
+ "default": 0
903
991
  }
904
992
  },
905
993
  "methods": {},
@@ -1082,5 +1170,6 @@
1082
1170
  "@happyvertical/smrt-tenancy"
1083
1171
  ]
1084
1172
  },
1173
+ "schemaFingerprint": "4085621932cf236ae4754fda187767445e0bcf294534b949e1a132d2d52fa830",
1085
1174
  "stampsConstructors": true
1086
1175
  }
@@ -1 +1 @@
1
- {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,cAAc,EACd,UAAU,EACV,KAAK,eAAe,EAErB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAIlC,oFAAoF;AACpF,qBAOa,mBAAoB,SAAQ,UAAU;IACrC,QAAQ,EAAE,MAAM,CAAM;IACO,GAAG,EAAE,MAAM,CAAM;IACjC,MAAM,EAAE,MAAM,EAAE,CAAM;IACtB,MAAM,EAAE,MAAM,EAAE,CAAM;IACW,MAAM,EAAE,MAAM,CAAM;IACnC,OAAO,EAAE,OAAO,CAAQ;IAEpD,IAAI,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAc9D;AACD,qBAAa,6BAA8B,SAAQ,cAAc,CAAC,mBAAmB,CAAC;IACpF,MAAM,CAAC,QAAQ,CAAC,UAAU,6BAAuB;CAClD;AAED,6FAA6F;AAC7F,qBAca,eAAgB,SAAQ,UAAU;IACjC,QAAQ,EAAE,MAAM,CAAM;IAKlC,cAAc,EAAE,MAAM,CAA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CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAc9D;AACD,qBAAa,6BAA8B,SAAQ,cAAc,CAAC,mBAAmB,CAAC;IACpF,MAAM,CAAC,QAAQ,CAAC,UAAU,6BAAuB;CAClD;AAED,6FAA6F;AAC7F,qBAca,eAAgB,SAAQ,UAAU;IACjC,QAAQ,EAAE,MAAM,CAAM;IAKlC,cAAc,EAAE,MAAM,CAAM;IAE5B,OAAO,EAAE,MAAM,CAAM;IACqC,OAAO,EAAE,MAAM,CACpE;IACwC,MAAM,EAAE,MAAM,CAAa;IAChC,UAAU,EAAE,MAAM,CAAK;IACvB,QAAQ,EAAE,MAAM,CAAK;IACjB,cAAc,EAAE,MAAM,GAAG,IAAI,CAClE;IACkC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAQ;IACX,UAAU,EAChE,MAAM,GACN,IAAI,CAAQ;IAC6B,UAAU,EAAE,IAAI,GAAG,IAAI,CAAQ;CAC7E;AACD,qBAAa,yBAA0B,SAAQ,cAAc,CAAC,eAAe,CAAC;IAC5E,MAAM,CAAC,QAAQ,CAAC,UAAU,yBAAmB;CAC9C;AAED,oEAAoE;AACpE,qBAMa,mBAAoB,SAAQ,UAAU;IAE3C,OAAO,CACX,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAClC,QAAQ,CAAC,EAAE,mBAAmB,GAC7B,OAAO,CAAC,IAAI,CAAC;CAIjB;AAED,gFAAgF;AAChF,qBAca,aAAc,SAAQ,UAAU;IAC/B,QAAQ,EAAE,MAAM,CAAM;IAElC,OAAO,EAAE,MAAM,CAAM;IACmB,QAAQ,EAAE,MAAM,CAAK;CAC9D"}
@@ -3,12 +3,12 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-webhooks",
6
- "packageVersion": "0.61.3",
6
+ "packageVersion": "0.61.4",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "8c36b0724590da9f8d19cfec067eadafd3ca368a7bb5d77248f607c8349163f1",
11
- "packageJson": "59881b1fcf39f0a278134c20c059f412a2ea07ad4e8314b12621578aba189256",
10
+ "manifest": "0beff3223707ad126a80e3305b0b2d0d900bb88ce22011a3aeb55b1ece7b42f7",
11
+ "packageJson": "9e1f88fdc4b11807f84e41e629b4fd900a3759f6bff8d09c6f462f3d91f62540",
12
12
  "agents": "f67b2a340106cf4b4b44c6b2bf918086286236ac3cf34b03b24b1db6e17b40a5"
13
13
  },
14
14
  "exports": [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-webhooks",
3
3
  "author": "HappyVertical",
4
- "version": "0.61.3",
4
+ "version": "0.61.4",
5
5
  "smrtJsdoc": "strict",
6
6
  "description": "Outbound webhook subscriptions, signed delivery, and durable retries",
7
7
  "type": "module",
@@ -30,11 +30,11 @@
30
30
  "./manifest.json": "./dist/manifest.json"
31
31
  },
32
32
  "dependencies": {
33
- "@happyvertical/smrt-core": "0.61.3",
34
- "@happyvertical/smrt-jobs": "0.61.3",
35
- "@happyvertical/smrt-tenancy": "0.61.3",
36
- "@happyvertical/sql": "^0.112.3",
37
- "@happyvertical/smrt-ui": "0.61.3"
33
+ "@happyvertical/smrt-core": "0.61.4",
34
+ "@happyvertical/smrt-jobs": "0.61.4",
35
+ "@happyvertical/smrt-tenancy": "0.61.4",
36
+ "@happyvertical/sql": "^0.113.0",
37
+ "@happyvertical/smrt-ui": "0.61.4"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "svelte": "^5.57.0"
@@ -45,7 +45,7 @@
45
45
  }
46
46
  },
47
47
  "devDependencies": {
48
- "@happyvertical/smrt-vitest": "0.61.3",
48
+ "@happyvertical/smrt-vitest": "0.61.4",
49
49
  "@sveltejs/package": "^2.5.8",
50
50
  "@types/node": "24.13.6",
51
51
  "svelte": "^5.57.1",
@@ -1 +0,0 @@
1
- {"version":3,"file":"admin-DogkNqij.js","names":[],"sources":["../../src/security.ts","../../src/models.ts","../../src/admin.ts"],"sourcesContent":["import { lookup } from 'node:dns/promises';\nimport { request } from 'node:https';\nimport { isIP } from 'node:net';\n\n/** Conservative public-unicast allowlist. Transition/mapped IPv6 is excluded. */\nexport function isPublicAddress(address: string): boolean {\n if (isIP(address) === 4) {\n const [a, b, c] = address.split('.').map(Number);\n return !(\n a === 0 ||\n a === 10 ||\n a === 127 ||\n a >= 224 ||\n (a === 100 && b >= 64 && b <= 127) ||\n (a === 169 && b === 254) ||\n (a === 172 && b >= 16 && b <= 31) ||\n (a === 192 && (b === 0 || b === 168 || (b === 88 && c === 99))) ||\n (a === 198 && (b === 18 || b === 19 || (b === 51 && c === 100))) ||\n (a === 203 && b === 0 && c === 113)\n );\n }\n if (isIP(address) !== 6) return false;\n const normalized = new URL(`https://[${address}]/`).hostname.slice(1, -1);\n // Only global unicast 2000::/3; exclude IETF special-purpose, documentation,\n // 6to4, and the newer documentation block (3fff::/20).\n const first = Number.parseInt(normalized.split(':')[0], 16);\n return (\n first >= 0x2000 &&\n first < 0x4000 &&\n first !== 0x2002 &&\n !(\n first === 0x2001 &&\n Number.parseInt(normalized.split(':')[1] || '0', 16) < 0x200\n ) &&\n !normalized.startsWith('2001:db8:') &&\n first !== 0x3fff\n );\n}\n\nexport function assertWebhookUrl(value: string): URL {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n throw new Error('Webhook URL must be an absolute HTTPS URL.');\n }\n const host = url.hostname.replace(/^\\[|\\]$/g, '');\n if (\n url.protocol !== 'https:' ||\n url.username ||\n url.password ||\n url.hash ||\n (url.port && url.port !== '443') ||\n host === 'localhost' ||\n host.endsWith('.localhost') ||\n (isIP(host) && !isPublicAddress(host))\n ) {\n throw new Error(\n 'Webhook URL must use public HTTPS on port 443 without credentials or a fragment.',\n );\n }\n return url;\n}\n\nexport function assertHmacSecret(secret: string): void {\n if (\n typeof secret !== 'string' ||\n Buffer.byteLength(secret) < 32 ||\n Buffer.byteLength(secret) > 4096\n ) {\n throw new Error('Webhook signing secret must contain 32 to 4096 bytes.');\n }\n}\n\nexport interface WebhookRequest {\n url: string;\n body: string;\n headers: Record<string, string>;\n}\nexport type WebhookTransport = (request: WebhookRequest) => Promise<number>;\n\n/** Validate every DNS answer, then pin the socket lookup; TLS still verifies the hostname.\n * No proxy, redirects, pooled sockets, response body buffering, or second DNS lookup.\n */\nexport const sendPublicWebhook: WebhookTransport = async ({\n url,\n body,\n headers,\n}) => {\n const target = assertWebhookUrl(url);\n const host = target.hostname.replace(/^\\[|\\]$/g, '');\n let dnsTimer: ReturnType<typeof setTimeout> | undefined;\n const answers = isIP(host)\n ? [{ address: host, family: isIP(host) }]\n : await Promise.race([\n lookup(host, { all: true, verbatim: true }),\n new Promise<never>((_, reject) => {\n dnsTimer = setTimeout(\n () => reject(new Error('Webhook DNS timeout.')),\n 5000,\n );\n dnsTimer.unref();\n }),\n ]).finally(() => clearTimeout(dnsTimer));\n if (\n !answers.length ||\n answers.some(({ address }) => !isPublicAddress(address))\n ) {\n throw new Error('Webhook destination is not public.');\n }\n const pinned = answers[0];\n return new Promise<number>((resolve, reject) => {\n const req = request(\n target,\n {\n method: 'POST',\n agent: false,\n headers: {\n ...headers,\n 'content-length': Buffer.byteLength(body).toString(),\n },\n lookup: (_hostname, options, callback) => {\n if (options.all) callback(null, [pinned]);\n else callback(null, pinned.address, pinned.family);\n },\n },\n (response) => {\n const status = response.statusCode ?? 0;\n response.destroy();\n resolve(status);\n },\n );\n const timer = setTimeout(\n () => req.destroy(new Error('Webhook request timeout.')),\n 10000,\n );\n req.on('close', () => clearTimeout(timer));\n req.on('error', () => reject(new Error('Webhook transport failed.')));\n req.end(body);\n });\n};\n","import {\n field,\n foreignKey,\n SmrtCollection,\n SmrtObject,\n type SmrtSaveOptions,\n smrt,\n} from '@happyvertical/smrt-core';\nimport {\n backgroundEligible,\n type JobExecutionContext,\n} from '@happyvertical/smrt-jobs';\nimport { TenantScoped, tenantId } from '@happyvertical/smrt-tenancy';\nimport { assertHmacSecret, assertWebhookUrl } from './security.js';\n\n/** Server-only subscription. Hosts authorize administration before accessing it. */\n@smrt({\n tableName: '_smrt_webhook_subscriptions',\n api: false,\n cli: false,\n mcp: false,\n})\n@TenantScoped({ mode: 'required' })\nexport class WebhookSubscription extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @tenantId() tenantId: string = '';\n @field({ type: 'text', required: true }) url: string = '';\n @field({ type: 'json' }) events: string[] = [];\n @field({ type: 'json' }) models: string[] = [];\n @field({ type: 'text', sensitive: true, required: true }) secret: string = '';\n @field({ type: 'boolean', default: true }) enabled: boolean = true;\n\n override async save(options?: SmrtSaveOptions): Promise<this> {\n assertWebhookUrl(this.url);\n assertHmacSecret(this.secret);\n for (const values of [this.events, this.models]) {\n if (\n !Array.isArray(values) ||\n values.length > 100 ||\n values.some((v) => typeof v !== 'string' || !v || v.length > 200)\n ) {\n throw new Error('Webhook filters must be lists of nonempty names.');\n }\n }\n return super.save(options);\n }\n}\nexport class WebhookSubscriptionCollection extends SmrtCollection<WebhookSubscription> {\n static readonly _itemClass = WebhookSubscription;\n}\n\n/** Durable outbox and safe outcome metadata; payload never appears in public projections. */\n@smrt({\n tableName: '_smrt_webhook_deliveries',\n api: false,\n cli: false,\n mcp: false,\n indexes: [\n {\n name: '_smrt_webhook_delivery_identity',\n columns: ['tenantId', 'subscriptionId', 'eventId'],\n unique: true,\n },\n ],\n})\n@TenantScoped({ mode: 'required' })\nexport class WebhookDelivery extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @tenantId() tenantId: string = '';\n @foreignKey(WebhookSubscription, {\n onUpdate: 'RESTRICT',\n onDelete: 'RESTRICT',\n })\n subscriptionId: string = '';\n @field({ type: 'text', required: true }) eventId: string = '';\n @field({ type: 'text', required: true, sensitive: true }) payload: string =\n '';\n @field({ type: 'text', default: 'pending' }) status: string = 'pending';\n @field({ type: 'integer', default: 0 }) generation: number = 0;\n @field({ type: 'integer', default: 0 }) attempts: number = 0;\n @field({ type: 'integer', nullable: true }) responseStatus: number | null =\n null;\n @field({ type: 'text', nullable: true }) error: string | null = null;\n @field({ type: 'text', nullable: true, sensitive: true }) leaseToken:\n | string\n | null = null;\n @field({ type: 'datetime', nullable: true }) leaseUntil: Date | null = null;\n}\nexport class WebhookDeliveryCollection extends SmrtCollection<WebhookDelivery> {\n static readonly _itemClass = WebhookDelivery;\n}\n\n/** Jobs queue entry point; persisted arguments contain IDs only. */\n@smrt({\n tableName: '_smrt_webhook_delivery_tasks',\n api: false,\n cli: false,\n mcp: false,\n})\nexport class WebhookDeliveryTask extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @backgroundEligible()\n async deliver(\n args: Record<string, unknown> = {},\n _context?: JobExecutionContext,\n ): Promise<void> {\n const { runWebhookDeliveryJob } = await import('./dispatcher.js');\n await runWebhookDeliveryJob(args);\n }\n}\n\n/** Tenant-bound durable cursor for replayable model change-feed publication. */\n@smrt({\n tableName: '_smrt_webhook_cursors',\n api: false,\n cli: false,\n mcp: false,\n indexes: [\n {\n name: '_smrt_webhook_cursor_identity',\n columns: ['tenantId', 'runtime'],\n unique: true,\n },\n ],\n})\n@TenantScoped({ mode: 'required' })\nexport class WebhookCursor extends SmrtObject { static __smrtPackage__ = \"@happyvertical/smrt-webhooks\";\n @tenantId() tenantId: string = '';\n @field({ type: 'text', required: true }) runtime: string = '';\n @field({ type: 'integer', default: 0 }) position: number = 0;\n}\n","import { requireTenant } from '@happyvertical/smrt-tenancy';\nimport { WebhookSubscriptionCollection } from './models.js';\nimport type { WebhookStore } from './store.js';\nimport type {\n WebhookDeliveryRecord,\n WebhookSubscriptionRecord,\n} from './types.js';\nexport interface WebhookAdminView {\n subscriptions: WebhookSubscriptionRecord[];\n deliveries: WebhookDeliveryRecord[];\n}\n/** Allowlisted projection; never spread persistence objects into a browser response. */\nexport function webhookAdminView(\n subscriptions: WebhookSubscriptionRecord[],\n deliveries: WebhookDeliveryRecord[],\n): WebhookAdminView {\n return {\n subscriptions: subscriptions.map((s) => ({\n id: s.id,\n tenantId: s.tenantId,\n url: s.url,\n models: s.models,\n events: s.events,\n enabled: s.enabled,\n })),\n deliveries: deliveries.map((d) => ({\n id: d.id,\n tenantId: d.tenantId,\n subscriptionId: d.subscriptionId,\n eventId: d.eventId,\n status: d.status,\n attempts: d.attempts,\n responseStatus: d.responseStatus,\n error: d.error,\n })),\n };\n}\n/** Host supplies its administrator permission check and authenticated tenant context. */\nexport class WebhookAdminService {\n constructor(\n private readonly store: WebhookStore,\n private readonly authorize: () => Promise<boolean>,\n ) {}\n private async guard() {\n requireTenant();\n if (!(await this.authorize()))\n throw new Error('Webhook administration forbidden.');\n }\n async view(): Promise<WebhookAdminView> {\n await this.guard();\n await this.store.reconcile();\n const subscriptions = await this.store.subscriptions();\n const deliveries = await this.store.deliveries();\n return webhookAdminView(\n subscriptions.map((s) => ({ ...s, id: s.id ?? '' })),\n deliveries.map((d) => ({ ...d, id: d.id ?? '' })),\n );\n }\n async create(input: {\n url: string;\n events: string[];\n models: string[];\n secret: string;\n }): Promise<void> {\n await this.guard();\n const collection = await WebhookSubscriptionCollection.create({\n db: this.store.db,\n });\n const sub = await collection.create({\n tenantId: requireTenant().tenantId,\n url: input.url,\n events: input.events,\n models: input.models,\n secret: input.secret,\n enabled: true,\n });\n await sub.save();\n }\n async toggle(id: string, enabled: boolean): Promise<void> {\n await this.guard();\n if (typeof enabled !== 'boolean') throw new Error('Invalid enabled value.');\n const sub = await this.store.subscription(id);\n if (!sub) throw new Error('Webhook subscription not found.');\n sub.enabled = enabled;\n await sub.save();\n }\n async replay(id: string): Promise<boolean> {\n await this.guard();\n return this.store.replay(id);\n }\n}\n"],"mappings":";;;;;;;AAKO,SAAS,gBAAgB,SAA0B;CACxD,IAAI,KAAK,OAAO,MAAM,GAAG;EACvB,MAAM,CAAC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