UNPKG

@upstash/qstash

Version:

Official Typescript client for QStash

54 lines (52 loc) 1.57 kB
import "./chunk-5PQP3YLP.mjs"; import { Receiver, serve } from "./chunk-RQPZUJXG.mjs"; // platforms/svelte.ts var verifySignatureSvelte = (handler, config) => { const currentSigningKey = config.currentSigningKey; if (!currentSigningKey) { throw new Error("currentSigningKey is required, either in the config or from the env"); } const nextSigningKey = config.nextSigningKey; if (!nextSigningKey) { throw new Error("nextSigningKey is required, either in the config or from the env"); } const receiver = new Receiver({ currentSigningKey, nextSigningKey }); const wrappedHandler = async (event) => { const signature = event.request.headers.get("upstash-signature"); if (!signature) { return new Response("`Upstash-Signature` header is missing", { status: 403 }); } if (typeof signature !== "string") { throw new TypeError("`Upstash-Signature` header is not a string"); } const cloneRequest = event.request.clone(); const body = await cloneRequest.text(); const isValid = await receiver.verify({ signature, body, clockTolerance: config.clockTolerance }); if (!isValid) { return new Response("invalid signature", { status: 403 }); } return handler(event); }; return wrappedHandler; }; var serve2 = (routeFunction, options) => { const handler = async ({ request }) => { const serveMethod = serve(routeFunction, options); return await serveMethod(request); }; return handler; }; export { serve2 as serve, verifySignatureSvelte };