totem-otp-delivery-webhook
Version:
Webhook delivery agent for TotemOTP
57 lines (56 loc) • 1.64 kB
TypeScript
import type { IOTPValue, IDeliveryAgent } from 'totem-otp';
export interface WebhookDeliveryAgentOptions {
/**
* Webhook destination URL
*/
webhookUrl: string;
/**
* Optional callback function to compute the request body
* If not provided, a default body structure will be used
*/
bodyBuilder?: (otp: IOTPValue) => Record<string, any> | string;
/**
* Optional HTTP headers to include in the request
* @default { 'Content-Type': 'application/json' }
*/
headers?: Record<string, string>;
/**
* Optional HTTP method
* @default 'POST'
*/
method?: 'POST' | 'PUT' | 'PATCH';
/**
* Optional timeout in milliseconds
* @default 30000 (30 seconds)
*/
timeout?: number;
}
export declare class WebhookDeliveryAgent implements IDeliveryAgent {
private readonly webhookUrl;
private readonly bodyBuilder;
private readonly headers;
private readonly method;
private readonly timeout;
constructor(options: WebhookDeliveryAgentOptions);
sendMessageToAudience(otp: IOTPValue): Promise<string>;
/**
* Default body builder that creates a standard webhook payload
*/
private defaultBodyBuilder;
/**
* Make HTTP request using Node.js built-in modules
*/
private makeHttpRequest;
/**
* Extract receipt ID from webhook response
*/
private extractReceiptId;
/**
* Generate a fallback receipt ID if none is provided by the webhook
*/
private generateReceiptId;
/**
* Simple hash function for generating receipt IDs
*/
private simpleHash;
}