UNPKG

@snehal96/unimail

Version:

Unified email fetching & document extraction layer for modern web apps

77 lines (76 loc) 2.96 kB
import { IAdapter, PaginatedEmailsResponse } from './IAdapter.js'; import { NormalizedEmail, FetchOptions, OutlookCredentials, EmailStreamOptions, EmailStreamCallbacks } from '../interfaces.js'; export declare class OutlookAdapter implements IAdapter { private graphClient_?; private credentials_?; private emailParserService; private initialized; private oauthService?; private msalApp_?; private accessToken_?; constructor(); /** * Initialize the Outlook adapter with credentials. * This method supports both traditional refresh token authentication * and the new OAuth flow using an auth code. */ initialize(credentials: OutlookCredentials): Promise<void>; /** * Start the OAuth flow to get authorization from the user * @returns The authorization URL that the user should visit */ static startOAuthFlow(clientId: string, clientSecret: string, redirectUri: string, tenantId?: string, port?: number, callbackPath?: string): Promise<string>; /** * Handle the OAuth callback manually (for server-side applications) * @returns TokenData containing access and refresh tokens */ static handleOAuthCallback(code: string, clientId: string, clientSecret: string, redirectUri: string, tenantId?: string): Promise<{ accessToken: string; refreshToken?: string; }>; private ensureInitialized; authenticate(): Promise<void>; fetchEmails(options: FetchOptions): Promise<PaginatedEmailsResponse>; /** * Fetches a single page of emails with enhanced format support */ private fetchEmailPage; /** * Fetches all pages of emails up to the specified limit with enhanced format support */ private fetchAllEmailPages; /** * Helper method to build field selection based on fetch strategy */ private buildSelectFields; /** * Helper method to determine fetch strategy from options (similar to Gmail's format detection) */ private determineOutlookFetchStrategy; /** * Fetches attachments for a message */ private fetchAttachments; /** * Maps an Outlook message to our normalized email format */ private mapOutlookMessageToNormalized; /** * Extracts the skip token from Outlook's nextLink URL */ private extractSkipTokenFromNextLink; /** * Stream emails using async generator * This method provides memory-efficient streaming of emails */ streamEmails(options: EmailStreamOptions): AsyncGenerator<NormalizedEmail[], void, unknown>; /** * Stream emails with callback-based progress tracking * Provides detailed progress information and error handling */ fetchEmailsStream(options: EmailStreamOptions, callbacks: EmailStreamCallbacks): Promise<void>; /** * Helper method to build Outlook query from stream options */ private buildOutlookQueryFromStreamOptions; }