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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user