@hookflo/tern
Version:
A robust, scalable webhook verification framework supporting multiple platforms and signature algorithms
51 lines (50 loc) • 1.53 kB
TypeScript
export type WebhookPlatform = 'custom' | 'clerk' | 'supabase' | 'github' | 'stripe' | 'shopify' | 'vercel' | 'polar' | 'dodopayments' | 'unknown';
export declare enum WebhookPlatformKeys {
GitHub = "github",
Stripe = "stripe",
Clerk = "clerk",
DodoPayments = "dodopayments",
Shopify = "shopify",
Vercel = "vercel",
Polar = "polar",
Supabase = "supabase",
Custom = "custom",
Unknown = "unknown"
}
export type SignatureAlgorithm = 'hmac-sha256' | 'hmac-sha1' | 'hmac-sha512' | 'rsa-sha256' | 'ed25519' | 'custom';
export interface SignatureConfig {
algorithm: SignatureAlgorithm;
headerName: string;
headerFormat?: 'raw' | 'prefixed' | 'comma-separated';
prefix?: string;
timestampHeader?: string;
timestampFormat?: 'unix' | 'iso' | 'custom';
payloadFormat?: 'raw' | 'timestamped' | 'custom';
customConfig?: Record<string, any>;
}
export interface WebhookVerificationResult {
isValid: boolean;
error?: string;
platform: WebhookPlatform;
payload?: any;
metadata?: {
timestamp?: string;
id?: string | null;
[key: string]: any;
};
}
export interface WebhookConfig {
platform: WebhookPlatform;
secret: string;
toleranceInSeconds?: number;
signatureConfig?: SignatureConfig;
}
export interface PlatformAlgorithmConfig {
platform: WebhookPlatform;
signatureConfig: SignatureConfig;
description?: string;
}
export interface TokenAuthConfig {
webhookId: string;
webhookToken: string;
}