UNPKG

@snehal96/unimail

Version:

Unified email fetching & document extraction layer for modern web apps

199 lines (198 loc) 4.94 kB
export interface Attachment { filename: string; mimeType: string; size: number; buffer?: Buffer; contentId?: string; } export interface NormalizedEmail { id: string; threadId?: string; from: string; to: string[]; cc?: string[]; bcc?: string[]; subject?: string; bodyText?: string; bodyHtml?: string; attachments: Attachment[]; date: Date; labels?: string[]; provider: 'gmail' | 'outlook' | 'imap' | 'unknown'; raw?: any; } export interface FetchOptions { limit?: number; since?: Date | string; before?: Date | string; query?: string; includeBody?: boolean; includeAttachments?: boolean; attachmentDir?: string; unreadOnly?: boolean; format?: 'raw' | 'full' | 'metadata'; pageToken?: string; pageSize?: number; getAllPages?: boolean; } export interface EmailStreamOptions extends Omit<FetchOptions, 'getAllPages' | 'pageSize' | 'limit'> { batchSize?: number; maxEmails?: number; } export interface EmailStreamProgress { current: number; total?: number; batchCount: number; estimatedRemaining?: number; } export interface EmailStreamCallbacks { onBatch?: (emails: NormalizedEmail[], progress: EmailStreamProgress) => Promise<void> | void; onProgress?: (progress: EmailStreamProgress) => Promise<void> | void; onError?: (error: Error, progress: EmailStreamProgress) => Promise<void> | void; onComplete?: (summary: EmailStreamSummary) => Promise<void> | void; } export interface EmailStreamSummary { totalProcessed: number; totalBatches: number; errors: number; startTime: Date; endTime: Date; duration: number; } export interface EmailStreamBatch { emails: NormalizedEmail[]; batchNumber: number; progress: EmailStreamProgress; isLastBatch: boolean; } export interface GmailCredentials { clientId: string; clientSecret: string; refreshToken?: string; authCode?: string; redirectUri?: string; } export interface OutlookCredentials { clientId: string; clientSecret: string; refreshToken?: string; authCode?: string; redirectUri?: string; tenantId?: string; accessToken?: string; } export type AdapterCredentials = GmailCredentials | OutlookCredentials; /** * @deprecated Use TokenData from auth/interfaces instead. */ export interface TokenData { accessToken: string; refreshToken?: string; expiryDate: number; tokenType?: string; idToken?: string; } export interface HistoryRecord { id: string; messages?: Array<{ id: string; threadId: string; }>; messagesAdded?: Array<{ message: { id: string; threadId: string; labelIds?: string[]; }; }>; messagesDeleted?: Array<{ message: { id: string; threadId: string; }; }>; labelsAdded?: Array<{ message: { id: string; threadId: string; }; labelIds: string[]; }>; labelsRemoved?: Array<{ message: { id: string; threadId: string; }; labelIds: string[]; }>; } export interface HistoryResponse { history: HistoryRecord[]; nextPageToken?: string; historyId: string; } export interface PushNotificationConfig { topicName: string; webhookUrl: string; labelIds?: string[]; labelFilterAction?: 'include' | 'exclude'; } export interface PushNotificationSetup { historyId: string; expiration: number; topicName: string; } export interface SyncState { historyId: string; lastSyncTime: Date; totalChanges: number; } export interface SyncOptions { startHistoryId?: string; maxResults?: number; labelIds?: string[]; includeDeleted?: boolean; } export interface SyncResult { processedHistoryRecords: number; addedEmails: NormalizedEmail[]; deletedEmailIds: string[]; updatedEmails: NormalizedEmail[]; newHistoryId: string; hasMoreChanges: boolean; nextPageToken?: string; } export interface PaginationMetadata { currentPage: number; pageSize: number; totalCount?: number; estimatedTotalPages?: number; nextPageToken?: string; previousPageToken?: string; hasNextPage: boolean; hasPreviousPage: boolean; isFirstPage: boolean; isLastPage: boolean; } export interface PaginationOptions { pageSize?: number; pageToken?: string; limit?: number; getAllPages?: boolean; } export interface PaginatedResponse<T> { data: T[]; pagination: PaginationMetadata; query?: string; totalFetched: number; fetchTime: Date; } export interface PaginationState { currentPageToken?: string; previousPageTokens: string[]; currentPage: number; pageSize: number; totalFetched: number; query?: string; options: FetchOptions; }