From a825f66ed79d708875c6af6e7a8ad249ea03072c Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Fri, 3 Mar 2023 03:27:11 +0000 Subject: [PATCH] fix: unwrap webhooks into payload, not event --- README.md | 6 +++--- resources/webhooks.ts | 5 ++--- tests/api-resources/webhooks.test.ts | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d0505fa3..07da6343 100644 --- a/README.md +++ b/README.md @@ -155,12 +155,12 @@ async function fetchAllCards(params) { We provide helper methods for verifying that a webhook request came from Lithic, and not a malicious third party. -You can use `lithic.webhooks.verifySignature(body, headers, secret?) -> void` or `lithic.webhooks.unwrap(body, headers, secret?) -> Event` like so: +You can use `lithic.webhooks.verifySignature(body, headers, secret?) -> void` or `lithic.webhooks.unwrap(body, headers, secret?) -> Payload` like so: ```ts export default function handler(req, res) { - const event = lithic.webhooks.unwrap(req.body, req.headers, process.env['LITHIC_WEBHOOK_SECRET']); // env var used by default; explicit here. - console.log(event.token, event.payload); + const payload = lithic.webhooks.unwrap(req.body, req.headers, process.env['LITHIC_WEBHOOK_SECRET']); // env var used by default; explicit here. + console.log(payload); } ``` diff --git a/resources/webhooks.ts b/resources/webhooks.ts index e24bf7a2..c544bf50 100644 --- a/resources/webhooks.ts +++ b/resources/webhooks.ts @@ -1,7 +1,6 @@ // File generated from our OpenAPI spec by Stainless. import { APIResource } from '~/resource'; -import type { Event } from '~/resources/events'; import { createHmac } from 'crypto'; import { getHeader, HeadersLike } from '~/core'; @@ -13,9 +12,9 @@ export class Webhooks extends APIResource { payload: string, headers: HeadersLike, secret: string | undefined | null = this.client.webhookSecret, - ): Event { + ): Object { this.verifySignature(payload, headers, secret); - return JSON.parse(payload) as Event; + return JSON.parse(payload); } private parseSecret(secret: string | null | undefined): Uint8Array { diff --git a/tests/api-resources/webhooks.test.ts b/tests/api-resources/webhooks.test.ts index de444a2a..2d654031 100644 --- a/tests/api-resources/webhooks.test.ts +++ b/tests/api-resources/webhooks.test.ts @@ -25,7 +25,7 @@ describe('resource webhooks', () => { }); describe('unwrap', () => { - it('deserializes the event object', () => { + it('deserializes the payload object', () => { lithic.webhooks.unwrap(payload, headers, secret); }); });