UNPKG

safeer-pdf-generator

Version:

Framework-agnostic PDF generation library with chunking, merging, S3 upload, and email delivery

56 lines (49 loc) 1.94 kB
// Webhook Integration Example (v1.1.0) // Automatically POST to your backend when a PDF is generated import { generatePdf, consoleLogger } from 'safeer-pdf-generator'; async function main() { const result = await generatePdf({ title: 'Invoice #1042', data: [ { item: 'Widget A', qty: 10, price: 25.00, total: 250.00 }, { item: 'Widget B', qty: 5, price: 49.99, total: 249.95 }, { item: 'Service Fee', qty: 1, price: 50.00, total: 50.00 }, ], columns: [ { key: 'item', title: 'Item', dataIndex: 'item' }, { key: 'qty', title: 'Qty', dataIndex: 'qty' }, { key: 'price', title: 'Price', dataIndex: 'price' }, { key: 'total', title: 'Total', dataIndex: 'total' }, ], // Webhook: fires a POST after PDF generation completes webhook: { url: 'https://api.example.com/webhooks/pdf-ready', secret: process.env.WEBHOOK_SECRET || 'my-hmac-secret', metadata: { tenantId: 'acme-corp', userId: 'user-123', invoiceId: '1042', }, timeoutMs: 10000, // 10 second timeout }, // Optional: upload to S3 (the S3 URL will be included in the webhook payload) // s3: { // bucket: 'my-pdfs', // region: 'us-east-1', // }, logging: consoleLogger, }); console.log(`✅ PDF generated: ${result.fileName}`); // The webhook was dispatched in the background with this payload: // { // s3Url: "https://...", // title: "Invoice #1042", // fileName: "Invoice-1042-2025-...", // sizeBytes: ..., // pageCount: ..., // metadata: { tenantId: "acme-corp", userId: "user-123", invoiceId: "1042" } // } // // And the header X-Webhook-Signature contains: sha256=<hmac-hex> } main().catch(console.error);