// src/utils/pendingHostAssigns.js // // In-memory store for pending Webex host-license assignment confirmation // cards. Identical shape to pendingOffboards — every entry is stamped with a // `timestamp` on insert, and a background sweep expires un-acted cards after // TTL_MS so the map never leaks. import { logger } from './logger.js'; const TTL_MS = 10 * 60 * 1000; // expire un-acted cards after 10 min const SWEEP_INTERVAL_MS = 60 * 1000; // check once a minute const _store = new Map(); export const pendingHostAssigns = { set(cardId, data) { _store.set(cardId, { ...data, timestamp: Date.now() }); return this; }, get(cardId) { return _store.get(cardId); }, has(cardId) { return _store.has(cardId); }, delete(cardId) { return _store.delete(cardId); }, get size() { return _store.size; }, entries() { return _store.entries(); }, }; const sweepHandle = setInterval(() => { const now = Date.now(); for (const [cardId, data] of _store.entries()) { const stamped = typeof data?.timestamp === 'number' ? data.timestamp : 0; if (now - stamped > TTL_MS) { logger('webexhost:cleanup', `Expired card ${cardId} for ${data?.email || 'unknown'}`); _store.delete(cardId); } } }, SWEEP_INTERVAL_MS); sweepHandle.unref?.();