Verificador de webhooks
@feitpay/webhooks verifica as entregas exatamente como descrito em
Verificar assinaturas de webhook e retorna um evento tipado.
pnpm add @feitpay/webhooksWebCrypto (qualquer runtime moderno)
Seção intitulada “WebCrypto (qualquer runtime moderno)”import { verifyWebhook, WebhookVerificationError, type WebhookEvent } from '@feitpay/webhooks';
const event = await verifyWebhook({ payload: rawBody, // string ou Uint8Array — o corpo bruto header: request.headers.get('feitpay-signature'), secrets: [process.env.FEITPAY_WEBHOOK_SECRET!, process.env.FEITPAY_WEBHOOK_SECRET_PREVIOUS!].filter(Boolean), toleranceSeconds: 300, // padrão});
if (event.event_type === 'payment.confirmed' && event.data.fulfillable) { // tipado: event.data.quote?.asset_amount, event.data.totals?.confirmed_base_units …}Node.js, de forma síncrona
Seção intitulada “Node.js, de forma síncrona”import { verifyWebhookSync } from '@feitpay/webhooks/node';
const event = verifyWebhookSync({ payload: rawBodyBuffer, header, secret });WebhookVerificationError.reason é um de malformed_header, no_signatures, signature_mismatch,
timestamp_outside_tolerance ou invalid_payload. Responda 400. Um segredo ausente ou uma tolerância não
positiva lança um TypeError (um erro de configuração, não uma requisição inválida).
Helpers de teste
Seção intitulada “Helpers de teste”import { generateTestHeader } from '@feitpay/webhooks';
const header = await generateTestHeader({ payload: body, secret: 'whsec_test_only' });A própria suíte de testes do pacote executa todos os casos do arquivo de vetores compartilhado entre linguagens.