UNPKG

@snehal96/unimail

Version:

Unified email fetching & document extraction layer for modern web apps

49 lines (48 loc) 1.4 kB
/** * Simple in-memory implementation of token storage. * Note: This is NOT suitable for production use as tokens are lost when the process exits. * It's intended for testing and demonstration purposes only. */ export class MemoryTokenStorage { constructor() { this.tokenStore = new Map(); } /** * Save tokens for a user */ async saveTokens(userId, tokens) { this.tokenStore.set(userId, tokens); } /** * Retrieve tokens for a user */ async getTokens(userId) { const tokens = this.tokenStore.get(userId); return tokens || null; } /** * Update tokens for a user */ async updateTokens(userId, tokens) { // Merge with existing tokens if they exist const existingTokens = this.tokenStore.get(userId); if (existingTokens) { this.tokenStore.set(userId, { ...existingTokens, ...tokens, // Preserve refresh token if not provided in update refreshToken: tokens.refreshToken || existingTokens.refreshToken }); } else { // If no existing tokens, just save the new ones this.tokenStore.set(userId, tokens); } } /** * Delete tokens for a user */ async deleteTokens(userId) { return this.tokenStore.delete(userId); } }