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:
27
server.ts
27
server.ts
@@ -1,5 +1,10 @@
|
||||
import { Application, Router } from "@oak/oak";
|
||||
import { getNotes, getNotesByDid } from "./src/data/db.ts";
|
||||
import {
|
||||
addWebhookSubscription,
|
||||
deleteWebhooksByDid,
|
||||
getNotes,
|
||||
getNotesByDid,
|
||||
} from "./src/data/db.ts";
|
||||
import { log } from "./src/log.ts";
|
||||
|
||||
const router = new Router();
|
||||
@@ -23,6 +28,26 @@ router.get("/:did/notes", (ctx) => {
|
||||
ctx.response.body = getNotesByDid(did, cursor, limit);
|
||||
});
|
||||
|
||||
router.post("/:did/webhooks", async (ctx) => {
|
||||
const { did } = ctx.params;
|
||||
const body = await ctx.request.body.json();
|
||||
const { method, url } = body ?? {};
|
||||
if (!method || !url) {
|
||||
ctx.response.status = 400;
|
||||
ctx.response.body = { error: "method and url are required" };
|
||||
return;
|
||||
}
|
||||
const subscription = addWebhookSubscription({ did, method, url });
|
||||
ctx.response.status = 201;
|
||||
ctx.response.body = subscription;
|
||||
});
|
||||
|
||||
router.delete("/:did/webhooks", (ctx) => {
|
||||
const { did } = ctx.params;
|
||||
deleteWebhooksByDid(did);
|
||||
ctx.response.status = 204;
|
||||
});
|
||||
|
||||
// router.delete("/:did/:rkey", async (ctx) => {
|
||||
// const { did, rkey } = ctx.params;
|
||||
// let verifiedDid: string;
|
||||
|
||||
Reference in New Issue
Block a user