From a8f6d7860225fe30ed1746ac5481fa1072920f65 Mon Sep 17 00:00:00 2001 From: jakedahn Date: Tue, 27 Aug 2024 20:28:04 -0600 Subject: [PATCH 1/2] Use backward compatible syntax for accessing object keys on requestData.headers --- lib/util.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/util.js b/lib/util.js index b4483ae..68e0716 100644 --- a/lib/util.js +++ b/lib/util.js @@ -35,9 +35,15 @@ async function validateWebhook(requestData, secret) { const signingSecret = secret || requestData.secret; if (requestData && requestData.headers && requestData.body) { - id = requestData.headers.get("webhook-id"); - timestamp = requestData.headers.get("webhook-timestamp"); - signature = requestData.headers.get("webhook-signature"); + id = + requestData.headers["webhook-id"] || + requestData.headers.get?.("webhook-id"); + timestamp = + requestData.headers["webhook-timestamp"] || + requestData.headers.get?.("webhook-timestamp"); + signature = + requestData.headers["webhook-signature"] || + requestData.headers.get?.("webhook-signature"); body = requestData.body; } From 5f9ecb9c33a9e2272df6ca3e0b2449d7878a376e Mon Sep 17 00:00:00 2001 From: jakedahn Date: Tue, 27 Aug 2024 20:30:06 -0600 Subject: [PATCH 2/2] Stringifying requestData.body when it is of type object. This is backward compatibility for Next.js 12.1.x / Node.js v18 --- lib/util.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/util.js b/lib/util.js index 68e0716..a36c480 100644 --- a/lib/util.js +++ b/lib/util.js @@ -55,6 +55,8 @@ async function validateWebhook(requestData, secret) { } } else if (isTypedArray(body)) { body = await new Blob([body]).text(); + } else if (typeof body === "object") { + body = JSON.stringify(body); } else if (typeof body !== "string") { throw new Error("Invalid body type"); }