UNPKG

safeer-pdf-generator

Version:

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

218 lines 6 kB
/** * Core type definitions for PDF Reporter */ export interface LoggingAdapter { debug(message: string, ...args: any[]): void; info(message: string, ...args: any[]): void; warn(message: string, ...args: any[]): void; error(message: string, ...args: any[]): void; } export interface ColumnDefinition { key: string; title: string; dataIndex: string; flex?: number; type?: 'image' | 'boolean' | 'text' | 'link'; } export interface UserInfo { name?: string; email?: string; mobile?: string; companyLogo?: string; companyName?: string; companyLogoBase64?: string; } export interface InfoSection { label: string; value: string; } export interface ChunkingOptions { enabled?: boolean; chunkSize?: number; maxConcurrency?: number; } export interface PuppeteerOptions { executablePath?: string; args?: string[]; headless?: boolean; protocolTimeout?: number; } export interface PdfOptions { format?: string; landscape?: boolean; printBackground?: boolean; margin?: { top?: string; left?: string; right?: string; bottom?: string; }; displayHeaderFooter?: boolean; } export interface LogoFetchOptions { inlineAsBase64?: boolean; fetcher?: (url: string) => Promise<string>; } export interface TotalsConfig { columns: string[]; aggregator?: (rows: any[], col: string) => any; } export interface HooksConfig { beforeChunkRender?: (params: any) => void | Promise<void>; afterChunkRender?: (result: Buffer, params: any) => void | Promise<void>; beforeMerge?: (chunks: Buffer[]) => void | Promise<void>; afterMerge?: (merged: Buffer) => void | Promise<void>; transformHtml?: (html: string, stage: 'pre' | 'post') => string; transformColumnValue?: (value: any, column: ColumnDefinition, row: any) => any; } export interface S3UploadConfig { bucket: string; region: string; accessKeyId?: string; secretAccessKey?: string; folder?: string; acl?: string; contentType?: string; endpoint?: string; } export interface EmailSendConfig { to: string; from?: string; subject?: string; transport?: any; smtp?: { host: string; port: number; secure?: boolean; auth: { user: string; pass: string; }; }; attachmentMode?: 'attachment' | 'link'; template?: string | EmailTemplateFunction; } export type EmailTemplateFunction = (context: EmailTemplateContext) => string; export interface EmailTemplateContext { title: string; generatedAt: string; downloadUrl?: string; fileSizeMB: number; user?: UserInfo; company?: { name?: string; }; } export interface TemplateCompilerFunction { (params: TemplateCompilerParams): TemplateCompilerResult; } export interface TemplateCompilerParams { title: string; data: any[]; columns: ColumnDefinition[]; locale?: string; userInfo?: UserInfo; infoSection?: InfoSection[]; pdfFilteredColumns?: string[]; translationFn?: (key: string) => string; chunkInfo?: { current: number; total: number; startRow: number; endRow: number; }; } export interface TemplateCompilerResult { html: string; header: string; footer: string; } export interface PdfGenerationOptions { title: string; data: any[]; columns: ColumnDefinition[]; locale?: string; userInfo?: UserInfo; infoSection?: InfoSection[]; filteredColumnKeys?: string[]; translationFn?: (key: string) => string; chunking?: ChunkingOptions; template?: string | TemplateCompilerFunction; headerTemplate?: string | ((ctx: any) => string); footerTemplate?: string | ((ctx: any) => string); includeTotals?: boolean; totalsConfig?: TotalsConfig; email?: EmailSendConfig | false; s3?: S3UploadConfig | false; return?: 'buffer' | 'stream' | 'file'; outputPath?: string; logoFetch?: LogoFetchOptions; hooks?: HooksConfig; timeoutMs?: number; puppeteer?: PuppeteerOptions; pdf?: PdfOptions; logging?: LoggingAdapter; } export interface PdfGenerationResult { buffer: Buffer; sizeBytes: number; pageCount: number; durationMs: number; fileName: string; metadata: { title: string; chunkCount: number; rows: number; generatedAt: string; }; s3?: { url: string; key: string; }; email?: { sent: boolean; to?: string; messageId?: string; error?: string; }; } export interface MergePdfsOptions { logging?: LoggingAdapter; } export interface S3UploadResult { url: string; key: string; } export interface EmailResult { sent: boolean; messageId?: string; error?: string; } export interface UploaderAdapter { upload(buffer: Buffer, filename: string, mimeType: string, options?: any): Promise<S3UploadResult>; } export interface EmailSenderAdapter { send(options: EmailSendConfig, buffer: Buffer, filename: string): Promise<EmailResult>; } export declare class PdfGenerationError extends Error { cause?: Error | undefined; constructor(message: string, cause?: Error | undefined); } export declare class TemplateError extends Error { cause?: Error | undefined; constructor(message: string, cause?: Error | undefined); } export declare class S3UploadError extends Error { cause?: Error | undefined; constructor(message: string, cause?: Error | undefined); } export declare class EmailError extends Error { cause?: Error | undefined; constructor(message: string, cause?: Error | undefined); } export declare class ChunkProcessingError extends Error { chunkIndex?: number | undefined; cause?: Error | undefined; constructor(message: string, chunkIndex?: number | undefined, cause?: Error | undefined); } //# sourceMappingURL=types.d.ts.map