safeer-pdf-generator
Version:
Framework-agnostic PDF generation library with chunking, merging, S3 upload, and email delivery
78 lines • 2.26 kB
TypeScript
import { LoggingAdapter } from '../../types.js';
/**
* Configuration for webhook dispatch
*/
export interface WebhookDispatchPayload {
/** S3 URL of the generated PDF (if S3 was configured) */
s3Url?: string;
/** S3 key of the generated PDF */
s3Key?: string;
/** Original PDF generation title */
title: string;
/** File name of the generated PDF */
fileName: string;
/** Size in bytes */
sizeBytes: number;
/** Number of pages */
pageCount: number;
/** Generation duration in milliseconds */
durationMs: number;
/** ISO timestamp of generation */
generatedAt: string;
/** Pass-through metadata from the caller */
metadata?: Record<string, any>;
}
/**
* Dispatches webhook HTTP POST requests upon PDF generation completion.
*
* Uses Node.js native fetch (Node 18+) and HMAC-SHA256 signing.
*
* @example
* ```typescript
* const dispatcher = new WebhookDispatcher(
* 'https://api.example.com/webhooks/pdf',
* 'my-secret',
* logger
* );
*
* await dispatcher.dispatch({
* s3Url: 'https://s3.../report.pdf',
* title: 'Quarterly Report',
* fileName: 'report.pdf',
* sizeBytes: 1024000,
* pageCount: 15,
* durationMs: 5000,
* generatedAt: new Date().toISOString(),
* metadata: { tenantId: 'abc', userId: '123' },
* });
* ```
*/
export declare class WebhookDispatcher {
private readonly url;
private readonly secret?;
private readonly timeoutMs;
private readonly logger;
constructor(url: string, secret?: string, logger?: LoggingAdapter, timeoutMs?: number);
/**
* Dispatch a webhook with the given payload.
* Includes one automatic retry on failure.
*/
dispatch(payload: WebhookDispatchPayload): Promise<{
success: boolean;
statusCode?: number;
error?: string;
}>;
/**
* Send the actual HTTP request
*/
private sendRequest;
/**
* Sign the payload body with HMAC-SHA256
*/
private signPayload;
}
/**
* Create a WebhookDispatcher from configuration
*/
export declare function createWebhookDispatcher(url: string, secret?: string, logger?: LoggingAdapter, timeoutMs?: number): WebhookDispatcher;
//# sourceMappingURL=WebhookDispatcher.d.ts.map