'use strict';
import { fdHeaders, fdCookies } from '../../../../fd-toolbox/server/framework/index.js';
import { headerNames } from '../../../../fd-toolbox/constants/header-names.js';
import { getBooleanEnvSetting } from '../../../../fd-toolbox/infra/env-functions.js';
import { metaEnvSettingKeys } from '../../infra/meta-env-setting-keys.js';
import { tryGetObjectFromCoreCache, setCoreCache } from '../../../../fd-toolbox/server/cachings/core-cache.js';
import { fdServerCacheKeys } from '../../../../fd-toolbox/server/constants/fd-server-cache-keys.js';
import { readBearerToken, sessionCookieName, validateSession } from './session-validation.js';

var __defProp=Object['defineProperty'],__name=(_0xec30ba,_0xbd1855)=>__defProp(_0xec30ba,'name',{'value':_0xbd1855,'configurable':!![]});async function getSessionToken(){if(getBooleanEnvSetting(metaEnvSettingKeys['storeSessionInHeader'])){const _0x3bfbbc=await fdHeaders(),_0x3de7f0=_0x3bfbbc['get'](headerNames['authHeaderName']);return _0x3de7f0?readBearerToken(_0x3de7f0):void(-0x9*0x41f+-0x15b0+0x1*0x3ac7);}const _0x2ba93c=await fdCookies(),_0x3ce426=_0x2ba93c['get'](sessionCookieName);return _0x3ce426?.['value'];}__name(getSessionToken,'getSessionToken');async function getCurrentWorkspaceIdFromSession(_0x226ba0){const _0x38c6b1=await getSession(_0x226ba0);return _0x38c6b1?.['currentWorkspaceId'];}__name(getCurrentWorkspaceIdFromSession,'getCurrentWorkspaceIdFromSession');async function getSession(_0x3a3f74){const _0x1a726a=await getSessionFromCache(_0x3a3f74);if(_0x1a726a)return _0x1a726a;const _0x5ecdb9=await validateAndCacheSession(_0x3a3f74);return _0x5ecdb9;}__name(getSession,'getSession');async function getUserIdFromSession(_0x4456d7){const _0x5b10f1=await getSession(_0x4456d7);return _0x5b10f1?.['userId'];}__name(getUserIdFromSession,'getUserIdFromSession');async function getSessionFromCache(_0x4f0eae){const _0x5e6082=await tryGetObjectFromCoreCache(_0x4f0eae);if(_0x5e6082===void(0x1455+-0x1cf+-0x1286))return void(-0x2*0x99b+-0x1085*-0x1+-0x35*-0xd);if(_0x5e6082['isValid']===![])return void(-0xad4+-0x3de+-0x759*-0x2);return _0x5e6082;}__name(getSessionFromCache,'getSessionFromCache');async function validateAndCacheSession(_0x30b640){const _0x29ec2d=await validateSession(_0x30b640);return await setCoreCache(_0x30b640,_0x29ec2d??{'isValid':![]},{'absoluteExpirationRelativeToNowSeconds':fdServerCacheKeys['secondsInFifteenMinutes']}),_0x29ec2d;}__name(validateAndCacheSession,'validateAndCacheSession');

export { getCurrentWorkspaceIdFromSession, getSession, getSessionFromCache, getSessionToken, getUserIdFromSession };
