UNPKG

synapse-react-client

Version:

[![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synapse-react-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettie

89 lines (88 loc) 2.6 kB
import { WebhookVerificationStatus as i } from "@sage-bionetworks/synapse-client/generated/models/WebhookVerificationStatus"; import { http as u, HttpResponse as s } from "msw"; import k from "../util/BasicMockedCrudService.js"; const n = new k({ initialData: [], idField: "id", autoGenerateId: !0 }); function c(r) { return [ u.get(`${r}/repo/v1/webhook/:webhookId`, ({ params: e }) => { const o = e.webhookId, t = n.getOneById(o); return t ? s.json(t, { status: 200 }) : s.json( { reason: `Webhook with ID ${o} not found` }, { status: 404 } ); }), u.post(`${r}/repo/v1/webhook/list`, () => { const e = { page: n.getAll() }; return s.json(e, { status: 200 }); }), u.post( `${r}/repo/v1/webhook`, async ({ request: e }) => { const o = await e.json(), t = n.create({ ...o, verificationStatus: i.CODE_SENT }); return s.json(t, { status: 201 }); } ), u.put( `${r}/repo/v1/webhook/:webhookId`, async ({ params: e, request: o }) => { const t = e.webhookId, h = await o.json(), a = n.getOneById(t); if (!a) return s.json( { reason: `Webhook with ID ${t} not found` }, { status: 404 } ); let w = a?.verificationStatus; a && a.invokeEndpoint !== h.invokeEndpoint && (w = i.CODE_SENT); const d = n.update(t, { ...h, verificationStatus: w }); return s.json(d, { status: 201 }); } ), u.post( `${r}/repo/v1/webhook/:webhookId/verify`, ({ params: e }) => { const o = e.webhookId, t = n.getOneById(o); if (!t) return s.json( { reason: `Webhook with ID ${o} not found` }, { status: 404 } ); const h = n.update(o, { ...t, verificationStatus: i.VERIFIED }); return s.json(h, { status: 201 }); } ), u.put( `${r}/repo/v1/webhook/:webhookId/verificationCode`, ({ params: e }) => { const o = e.webhookId, t = n.getOneById(o); return t ? s.json(t, { status: 201 }) : s.json( { reason: `Webhook with ID ${o} not found` }, { status: 404 } ); } ), u.delete(`${r}/repo/v1/webhook/:webhookId`, ({ params: e }) => { const o = e.webhookId; return n.delete(o), new Response("", { status: 200 }); }) ]; } export { c as getWebhookHandlers, n as webhookService }; //# sourceMappingURL=webhookHandlers.js.map