Skip to content

Commit 37aa363

Browse files
committed
Document the validateWebhook interface on Node 18
1 parent 2d42001 commit 37aa363

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ const requestData = {
264264
const webhookIsValid = await validateWebhook(requestData);
265265
```
266266

267+
> [!NOTE]
268+
> The `validateWebhook` function uses the global `crypto` API available in most JavaScript runtimes. Node <= 18 does not provide this global so in this case you need to either call node with the `--no-experimental-global-webcrypto` or provide the `webcrypto` module manually.
269+
> ```js
270+
> const crypto = require("node:crypto").webcrypto;
271+
> const webhookIsValid = await valdiateWebhook(requestData, crypto);
272+
> ```
273+
267274
## TypeScript
268275
269276
The `Replicate` constructor and all `replicate.*` methods are fully typed.

lib/util.js

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ async function validateWebhook(requestData, secretOrCrypto, customCrypto) {
5353
signature = requestData.headers["webhook-signature"];
5454
}
5555
body = requestData.body;
56+
if (typeof secretOrCrypto !== "string") {
57+
throw new Error(
58+
"Unexpected value for secret passed to validateWebhook, expected a string"
59+
);
60+
}
61+
5662
secret = secretOrCrypto;
5763
if (customCrypto) {
5864
crypto = customCrypto;

0 commit comments

Comments
 (0)