UNPKG

@upstash/qstash

Version:

Official Typescript client for QStash

58 lines (56 loc) 1.94 kB
import "./chunk-M7SEEFAC.mjs"; import { Receiver, serve } from "./chunk-QYBCXZKB.mjs"; // platforms/solidjs.ts var verifySignatureSolidjs = (handler, config) => { const currentSigningKey = config?.currentSigningKey ?? process.env.QSTASH_CURRENT_SIGNING_KEY; const nextSigningKey = config?.nextSigningKey ?? process.env.QSTASH_NEXT_SIGNING_KEY; if (!currentSigningKey && !nextSigningKey && !process.env.QSTASH_REGION) { throw new Error( "currentSigningKey and nextSigningKey are required, either in the config or as env variables (QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY)" ); } 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 upstashRegion = event.request.headers.get("upstash-region"); const cloneRequest = event.request.clone(); const body = await cloneRequest.text(); const isValid = await receiver.verify({ signature, body, clockTolerance: config?.clockTolerance, upstashRegion: upstashRegion ?? void 0 }); 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 };