Add shared printful webhook secret for authentication

This commit is contained in:
Dominic Ferrando
2026-07-18 00:44:54 -04:00
parent 169034a63c
commit 2c356e6707
3 changed files with 10 additions and 3 deletions
+8 -2
View File
@@ -322,8 +322,11 @@ export const app = new Elysia()
)
// WEBHOOKS
.post("/webhooks/printful", async ({ body }) => {
.post("/webhooks/printful", async ({ body, query }) => {
// https://webflow.com/integrations/printful
const verified = crypto.timingSafeEqual(Buffer.from(query.secret, "hex"), Buffer.from(env.PRINTFUL_WEBHOOK_SECRET, "hex"));
if (!verified) throw status(400, "Invalid secret");
const payload = body as Printful.Webhook.EventPayload;
switch (payload.type) {
@@ -360,6 +363,9 @@ export const app = new Elysia()
const shipment = payload.data.shipment;
log.info({ wOrderId, carrier: shipment.carrier, tracking: shipment.tracking_number }, "printful webhook: package shipped");
// TODO: possible to have multiple packages shipped
// order should NOT be immediately fulfulled in that case
await s.Commerce.Apparel.Orders.Queue.enqueue({
type: "apparel_order_fulfill",
source: "printful",
@@ -371,7 +377,7 @@ export const app = new Elysia()
default:
log.warn({ type: (payload as any).type }, "printful webhook: unhandled event type");
}
})
}, { query: t.Object({ secret: t.String() }) })
.post("/webhooks/webflow", async ({ request, body }) => {
if (!s.Commerce.Webflow.Util.verifyWebflowSignature(request, body))
throw status(400, "Invalid signature");