diff --git a/package-lock.json b/package-lock.json index 5a1cc34..5837640 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@truepic/webhook-verifier", - "version": "2.3.0", + "version": "2.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@truepic/webhook-verifier", - "version": "2.3.0", + "version": "2.4.0", "license": "MIT", "devDependencies": { "@eslint/js": "^10.0.1", diff --git a/package.json b/package.json index 75b0e36..b5dac94 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "@truepic/webhook-verifier", - "version": "2.3.0", + "version": "2.4.0", "description": "Verify webhooks from Truepic Vision or Lens in your Node.js app", "homepage": "https://github.com/TRUEPIC/webhook-verifier-nodejs#readme", "bugs": "https://github.com/TRUEPIC/webhook-verifier-nodejs/issues", "license": "MIT", "main": "./src/main.js", + "types": "./src/main.d.ts", "repository": { "type": "git", "url": "git+https://github.com/TRUEPIC/webhook-verifier-nodejs.git" diff --git a/src/main.d.ts b/src/main.d.ts new file mode 100644 index 0000000..0e52416 --- /dev/null +++ b/src/main.d.ts @@ -0,0 +1,36 @@ +/** + * Options for verifying a Truepic webhook. + */ +interface VerifyTruepicWebhookOptions { + /** The full URL that received the request and is registered with Truepic. */ + url: string + /** The shared secret that's registered with Truepic. */ + secret: string + /** The value of the `truepic-signature` header from the request. */ + header: string + /** The raw body (unparsed JSON) from the request. */ + body: string + /** The number of minutes allowed between the request being sent and received. Defaults to `5`. */ + leewayMinutes?: number +} + +/** + * The custom error thrown when webhook verification fails. + */ +declare class TruepicWebhookVerifierError extends Error { + constructor(message: string) + name: 'TruepicWebhookVerifierError' +} + +/** + * Verify a webhook from Truepic Vision or Lens. + */ +declare function verifyTruepicWebhook( + options: VerifyTruepicWebhookOptions, +): true + +declare namespace verifyTruepicWebhook { + export { TruepicWebhookVerifierError } +} + +export = verifyTruepicWebhook