feat: add webhook_subscription table and CRUD endpoints

- Migration: CREATE TABLE webhook_subscription (id, did, method, url) with index on did
- db.ts: addWebhookSubscription and deleteWebhooksByDid helpers
- server.ts: POST /:did/webhooks (201) and DELETE /:did/webhooks (204)
This commit is contained in:
Julien Calixte
2026-02-25 22:46:45 +01:00
parent 6cc7866080
commit 373b7a6777
3 changed files with 65 additions and 1 deletions

View File

@@ -67,6 +67,31 @@ export const saveCursor = (cursor: number) => {
);
};
type WebhookSubscriptionRow = {
id: number;
did: string;
method: string;
url: string;
};
export const addWebhookSubscription = (
{ did, method, url }: Omit<WebhookSubscriptionRow, "id">,
): WebhookSubscriptionRow => {
db.exec(
"INSERT INTO webhook_subscription (did, method, url) VALUES (?, ?, ?)",
did,
method,
url,
);
return db.prepare(
"SELECT id, did, method, url FROM webhook_subscription WHERE id = last_insert_rowid()",
).get<WebhookSubscriptionRow>()!;
};
export const deleteWebhooksByDid = (did: string): void => {
db.exec("DELETE FROM webhook_subscription WHERE did = ?", did);
};
export const upsertNote = (note: Note) => {
const now = new Date().toISOString();
db.exec(