From 3396e8c324177a86368be13969bc030306eea8cd Mon Sep 17 00:00:00 2001 From: Justin Stayton Date: Thu, 19 Mar 2026 16:44:04 -0400 Subject: [PATCH] Add TypeScript declaration file --- package.json | 1 + src/main.d.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/main.d.ts diff --git a/package.json b/package.json index 75b0e36..4ffe136 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "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