UNPKG

@upstash/qstash

Version:

Official Typescript client for QStash

57 lines (55 loc) 1.8 kB
import "./chunk-5PQP3YLP.mjs"; import { Receiver, serve } from "./chunk-RQPZUJXG.mjs"; // platforms/solidjs.ts var verifySignatureSolidjs = (handler, config) => { const currentSigningKey = config?.currentSigningKey ?? process.env.QSTASH_CURRENT_SIGNING_KEY; if (!currentSigningKey) { throw new Error("currentSigningKey is required, either in the config or from the env"); } const nextSigningKey = config?.nextSigningKey ?? process.env.QSTASH_NEXT_SIGNING_KEY; if (!nextSigningKey) { throw new Error("nextSigningKey is required, either in the config or from the env"); } const receiver = new Receiver({ currentSigningKey, nextSigningKey }); return 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); }; }; var serve2 = (routeFunction, options) => { const handler = async (event) => { const method = event.request.method; if (method.toUpperCase() !== "POST") { return new Response("Only POST requests are allowed in worklfows", { status: 405 }); } const serveHandler = serve(routeFunction, options); return await serveHandler(event.request); }; return handler; }; export { serve2 as serve, verifySignatureSolidjs };