import { type Database } from "./database.js"; /** * App webhooks and app notifications (migration 1543, docs/app-webhooks.md). * Every read and write runs under the workspace's row-level security. A * delivery names its workspace in its address, so the public intake reads * its webhook in that workspace's context without an account. */ type Scope = { accountId: string; workspaceId: string; }; export type AppWebhookStatus = "active" | "paused"; export type AppWebhookRow = { id: string; accountId: string; workspaceId: string; siteId: string; name: string; collection: string; recordsPath: string | null; key: string | null; fields: string[] | null; status: AppWebhookStatus; secretHash: string; secretEncrypted: string; createdBySubjectId: string; createdAt: string; updatedAt: string; lastDeliveryAt: string | null; lastStatus: "succeeded" | "failed" | "rejected" | null; lastError: string | null; }; /** At most this many webhooks per app. */ export declare const APP_WEBHOOKS_PER_APP = 20; export type AppWebhookSettings = { name: string; collection: string; recordsPath: string | null; key: string | null; fields: string[] | null; status: AppWebhookStatus; }; export declare function createAppWebhook(db: Database, scope: Scope, input: AppWebhookSettings & { siteId: string; secretHash: string; secretEncrypted: string; createdBySubjectId: string; }): Promise; export declare function listAppWebhooks(db: Database, scope: Scope, siteId: string): Promise; /** One webhook, read in its workspace's context (the public intake knows only the workspace). */ export declare function getAppWebhook(db: Database, workspaceId: string, webhookId: string): Promise; export declare function updateAppWebhook(db: Database, scope: Scope, webhookId: string, input: AppWebhookSettings & { secretHash?: string; secretEncrypted?: string; /** The person saving it takes the webhook over. */ createdBySubjectId?: string; }): Promise; export declare function deleteAppWebhook(db: Database, scope: Scope, webhookId: string): Promise; /** * Count one delivery against the webhook's one-minute window, atomically. * False when the window is full. */ export declare function admitAppWebhookDelivery(db: Database, scope: Scope, webhookId: string, perMinute: number): Promise; /** Remember a delivery's outcome for the people managing the webhook. */ export declare function recordAppWebhookDelivery(db: Database, scope: Scope, webhookId: string, outcome: { status: "succeeded" | "failed" | "rejected"; error: string | null; }): Promise; export type AppNotificationInsert = { siteId: string; senderSubjectId: string; senderLabel: string; appTitle: string; audience: "people" | "workspace"; recipients: string[]; key: string; title: string; body: string; link: string; }; export type AppNotificationLimits = { /** Sends one person may make from one app per window. */ perSender: number; /** Of those, sends to everyone who can open the app. */ workspacePerSender: number; /** The window, in seconds. */ windowSeconds: number; }; /** * Record one send; the table's trigger delivers it. The sender's recent sends * from this app are counted under a transaction lock on the pair, so * concurrent sends can't pass the limit together. */ export declare function insertAppNotification(db: Database, scope: Scope, input: AppNotificationInsert, limits: AppNotificationLimits): Promise<{ id: string; } | { limited: "sender" | "workspace"; } | { unavailable: true; }>; export {};