@snehal96/unimail
Version:
Unified email fetching & document extraction layer for modern web apps
54 lines (53 loc) • 2 kB
TypeScript
import { IOAuthProvider, OAuthOptions, TokenData, ITokenStorage, OAuthCallbackHandler } from './interfaces.js';
/**
* Service to manage OAuth flows for different email providers
*/
export declare class OAuthService {
private oauthProvider;
private tokenStorage;
private server;
private pendingCallbacks;
/**
* Create a new OAuthService
* @param provider - The OAuth provider to use (Google, Outlook, etc.)
* @param tokenStorage - Optional storage mechanism for tokens
*/
constructor(provider?: IOAuthProvider, tokenStorage?: ITokenStorage);
/**
* Start the OAuth flow by opening a browser window to the authorization URL
* Returns the authorization URL that was opened
*/
startOAuthFlow(options: OAuthOptions, userId?: string, callbackPath?: string, port?: number): Promise<string>;
/**
* Handle the OAuth callback manually (without running a local server)
* This is useful for server-side applications or when the callback is handled externally
*/
handleCallback(code: string, options: OAuthOptions, userId?: string): Promise<TokenData>;
/**
* Refresh an access token using a refresh token
*/
refreshToken(refreshToken: string, options: OAuthOptions, userId?: string): Promise<TokenData>;
/**
* Get tokens for a user from storage
*/
getTokens(userId: string): Promise<TokenData | null>;
/**
* Revoke a token
*/
revokeToken(token: string, options: OAuthOptions, userId?: string): Promise<boolean>;
/**
* Register a callback function to be called when the OAuth flow completes
* Can be used instead of running a local server
*/
registerCallback(state: string, callback: OAuthCallbackHandler): void;
/**
* Start a local server to handle the OAuth callback
* @private
*/
private startCallbackServer;
/**
* Stop the callback server if it's running
* @private
*/
private stopCallbackServer;
}