Ir al contenido

tys.webhooks.constructEvent()

Esta página aún no está disponible en tu idioma.

Method@tryyoursize/node

Verifies a delivery’s TYS-Signature header against the raw request body and returns the parsed event. Also exported as a function: import { constructEvent } from "@tryyoursize/node".

constructEvent(
rawBody: RawBody,
signatureHeader: string | string[] | null | undefined,
secret: string,
opts?: ConstructEventOptions,
): WebhookEvent
rawBodyRawBodyObligatorio

The raw request body (string or Buffer), not parsed JSON. With Express use express.raw({ type: "application/json" }).

signatureHeaderstring | string[] | null | undefinedObligatorio

The TYS-Signature header.

secretstringObligatorio

The endpoint's signing secret (whsec_…) from Studio → Developers → Webhooks.

optsConstructEventOptionsOpcional
Propiedades
toleranceSecondsnumber | undefinedOpcional

Maximum |now − t| in seconds (default 300). 0 or less disables the check.

nownumber | Date | undefinedOpcional

The current time (unix seconds or a Date); for tests.

WebhookEvent: The event. Narrow on type to get typed data. Payloads never carry shopper identity or measurements.

SignatureVerificationError when no signature matches or the timestamp is outside the tolerance (5 minutes by default).

import express from "express";
app.post("/webhooks/tryyoursize", express.raw({ type: "application/json" }), (req, res) => {
let event;
try {
event = tys.webhooks.constructEvent(req.body, req.headers["tys-signature"], process.env.TYS_WEBHOOK_SECRET!);
} catch {
return res.sendStatus(400);
}
if (event.type === "garment.published") console.log(event.data.product_skus);
res.sendStatus(200);
});

¿Te ha resultado útil esta página?