shiply-runtime
v0.1.0
Published
Runtime helpers for shiply Workers — Stripe signature verification, JSON helpers, common patterns. Designed for Cloudflare Workers V8 isolate.
Downloads
163
Maintainers
Readme
shiply-runtime
Tiny zero-dep helpers for shiply Workers.
Install
npm install shiply-runtimeUse
// worker.ts
import { verifyStripeSig, readJson, json } from 'shiply-runtime'
export default {
async fetch(request: Request, env: any): Promise<Response> {
const url = new URL(request.url)
if (url.pathname === '/api/webhooks/stripe' && request.method === 'POST') {
const body = await request.text()
const sig = request.headers.get('stripe-signature')
if (!await verifyStripeSig(body, sig, env.STRIPE_WEBHOOK_SECRET)) {
return new Response('bad sig', { status: 400 })
}
const event = JSON.parse(body)
// ... handle event
return new Response('ok')
}
return env.ASSETS.fetch(request) // fall through to static
}
}API
verifyStripeSig(body, sigHeader, secret, toleranceSeconds?)— true if Stripe webhook signature is validreadJson(request)— parse JSON body, returns null on errorjson(data, init?)— Response with application/json content-typeerrorResponse(message, status?)— Response with text/plain content-type
Designed for
- Cloudflare Workers V8 isolate (no Node APIs, no global Buffer)
- Web Crypto + Web Fetch only
- Tree-shakeable, ~1 KB compiled
