
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="92b04938-d1b3-5f0a-91b8-1f970d760a41")}catch(e){}}();
import { createHash } from 'node:crypto';
import { USER_CACHE_MAX_SIZE, USER_CACHE_TTL_SECS } from '../const.js';
import { TTLLRUCache } from './ttl_lru.js';
// LRU cache with TTL for user info - stores the raw User object from API
const userIdCache = new TTLLRUCache(USER_CACHE_MAX_SIZE, USER_CACHE_TTL_SECS);
/**
 * Gets user ID from token, using cache to avoid repeated API calls
 * Token is hashed before caching to avoid storing raw tokens
 * Returns userId or null if not found
 */
export async function getUserIdFromTokenCached(token, apifyClient) {
    const tokenHash = createHash('sha256').update(token).digest('hex');
    const cachedId = userIdCache.get(tokenHash);
    if (cachedId)
        return cachedId;
    try {
        const user = await apifyClient.user('me').get();
        if (!user || !user.id) {
            return null;
        }
        userIdCache.set(tokenHash, user.id);
        return user.id;
    }
    catch {
        return null;
    }
}
//# sourceMappingURL=userid_cache.js.map
//# debugId=92b04938-d1b3-5f0a-91b8-1f970d760a41
