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AAQiB,CAAK,MAEZ,CACD,IAAMwB,EAAWF,EAAa,OAAQtB,GAAU,CAC5CjB,EAAQiB,CAAK,EACbwB,EAAS,CACb,CAAC,CACL,CACJ,CAAC,EAOQC,GAAsB,IACxBH,EAAa,IAAI","names":["Identity","Monetization","redirectStateKey","simplifiedLoginStateKey","getSessionStorage","getLocalStorage","redirectStateMap","setLoginFlowState","content","medium","campaign","term","returnUrl","origin","action","originString","callbackState","state","err","setLogoutFlowState","shouldShowSimplifiedLogin","simplifiedLogin","simplifiedLoginState","showAfterLoginInDays","showAfterLogoutInDays","showedOnLoginPageAt","showedOnRegularPageAt","loggedOutAt","showedRecentlyOnLoginPage","showedRecentlyOnRegularPage","loggedOutOnRecently","setSimplifiedLoginState","loggedOut","now","storeAutoLoginState","autoLoginStateKey","timestamp","autoLoginState","isAutoLoginAttemptTooSoon","days","lastAutoLogin","loggedInAt","atom","accountStore","getUserIdentifier","identity","identityInstance","autoLogin","config","options","autoLoginStateKey","expireDays","isAutoLoginAttemptTooSoon","identifier","storeAutoLoginState","state","setLoginFlowState","redirectUri","accountSiteConfigPro","accountSiteConfigDev","getSiteAccountConfig","initAccountOptions","site","env","config","isBrowser","identity","monetization","dispatchIdentityInitialized","getGlobalIdentityInstance","resolve","hasSessionSuccess","session","getUserInfo","error","getProductInfo","user","accountConfig","pids","userId","access","accessTo","hasAccessToProduct","pid","loginUser","config","options","state","setLoginFlowState","redirectUri","logoutUser","setSimplifiedLoginState","storeAutoLoginState","setLogoutFlowState","getIdentityLoginUrl","defaultState","showIdentitySimplifiedLoginWidget","shouldShowSimplifiedLogin","forceIdentitySimplifiedLoginWidget","widgetShown","identitySimplifiedLogin","initAccountSdk","initAccountOptions","getSiteAccountConfig","Identity","Monetization","getUser","autoLogin","initAccountStore","accountStore","getAccountStore","unlisten","getAccountStoreSync"],"sources":["../esm/npm/@schibsted/nanostores-account@0.1.6/node_modules/@schibsted/nanostores-account/dist/account.js","../esm/npm/@schibsted/nanostores-account@0.1.6/node_modules/@schibsted/nanostores-account/dist/helpers/login-flow.js","../esm/npm/@schibsted/nanostores-account@0.1.6/node_modules/@schibsted/nanostores-account/dist/store/account-store.js","../esm/npm/@schibsted/nanostores-account@0.1.6/node_modules/@schibsted/nanostores-account/dist/helpers/auto-login.js","../esm/npm/@schibsted/nanostores-account@0.1.6/node_modules/@schibsted/nanostores-account/dist/config/account-config.js"],"sourcesContent":["import { Identity, Monetization } from \"@schibsted/account-sdk-browser\";\nimport { setLoginFlowState, setLogoutFlowState, setSimplifiedLoginState, shouldShowSimplifiedLogin, storeAutoLoginState, } from \"./helpers/login-flow.js\";\nimport { accountStore } from \"./store/account-store.js\";\nimport { autoLogin as autoLoginUser } from \"./helpers/auto-login.js\";\nimport { getSiteAccountConfig } from \"./config/account-config.js\";\nconst isBrowser = typeof window !== \"undefined\";\nlet identity;\nlet monetization;\n/**\n * Dispatch a custom event when the identity is initialized\n * This is used to notify other parts of the application that the identity is ready\n */\nfunction dispatchIdentityInitialized() {\n    window.dispatchEvent(new window.CustomEvent(\"identity-initialized\", {\n        detail: { ready: true },\n    }));\n}\n/**\n * Get the global Identity instance from the window object\n * This is used to access the Identity instance in other parts of the application\n *\n * @returns {Promise\u003cIdentity | undefined\u003e} `Promise\u003cIdentity | undefined\u003e` - The global Identity instance or undefined if it is not available\n */\nexport const getGlobalIdentityInstance = () =\u003e new Promise((resolve) =\u003e {\n    if (typeof window === \"undefined\") {\n        return resolve(undefined);\n    }\n    if (!window.Identity) {\n        window.addEventListener(\"identity-initialized\", () =\u003e resolve(window.Identity), { once: true });\n    }\n    else {\n        resolve(window.Identity);\n    }\n});\n/**\n * Check if the session is a successful logged-in user session\n *\n * @param session - The session object to check\n * @returns `boolean` - Returns true if the session is a successful logged-in user session\n */\nexport const hasSessionSuccess = (session) =\u003e {\n    return \"result\" in session;\n};\nconst getUserInfo = async (identity) =\u003e {\n    try {\n        const session = await identity.hasSession();\n        if (hasSessionSuccess(session)) {\n            if (session.result) {\n                return {\n                    status: \"success\",\n                    session,\n                    isLoggedIn: true,\n                };\n            }\n            else {\n                return {\n                    status: \"failed\",\n                    session: undefined,\n                    isLoggedIn: false,\n                };\n            }\n        }\n        return {\n            status: \"error\",\n            session: undefined,\n            isLoggedIn: false,\n        };\n    }\n    catch (error) {\n        console.debug(`${error} - Failed to get user session`);\n        return {\n            status: \"error\",\n            session: undefined,\n            isLoggedIn: false,\n        };\n    }\n};\nconst getProductInfo = async ({ user, accountConfig, }) =\u003e {\n    const pids = accountConfig.productIds ?? [];\n    if (pids.length === 0) {\n        return {\n            ...user,\n            accessTo: [],\n            hasPlus: false,\n        };\n    }\n    if (user.status === \"success\" \u0026\u0026 user.session) {\n        const userId = user.session?.userId;\n        try {\n            const access = (await monetization.hasAccess(pids, userId));\n            if (!access) {\n                console.debug(\"Failed to check product access\");\n                return {\n                    ...user,\n                    accessTo: [],\n                    hasPlus: false,\n                };\n            }\n            const accessTo = access.entitled ? access.allowedFeatures : [];\n            const hasAccessToProduct = pids.some((pid) =\u003e accessTo?.includes(pid ?? \"\"));\n            return {\n                ...user,\n                accessTo,\n                hasPlus: hasAccessToProduct,\n            };\n        }\n        catch (error) {\n            console.debug(`${error} - Failed to check product access`);\n            return {\n                ...user,\n                accessTo: [],\n                hasPlus: false,\n            };\n        }\n    }\n    return {\n        ...user,\n        accessTo: [],\n        hasPlus: false,\n    };\n};\nconst loginUser = async (identity, config, options) =\u003e {\n    const state = setLoginFlowState({\n        content: options?.content,\n        medium: options?.medium,\n        campaign: options?.campaign,\n        term: options?.term,\n        returnUrl: options?.returnUrl,\n    });\n    const redirectUri = options?.redirectUri\n        ? options.redirectUri\n        : config.redirectUri;\n    return identity.login({ ...options, state, redirectUri });\n};\nconst logoutUser = async (identity, config, options) =\u003e {\n    if (config.simplifiedLogin) {\n        setSimplifiedLoginState({ loggedOut: true });\n    }\n    if (config.autoLogin) {\n        storeAutoLoginState({\n            action: \"logout\",\n            autoLoginStateKey: config.autoLogin.autoLoginStateKey,\n        });\n    }\n    setLogoutFlowState({\n        content: options?.content,\n        medium: options?.medium,\n        campaign: options?.campaign,\n        term: options?.term,\n        returnUrl: options?.returnUrl,\n    });\n    return identity.logout(config.redirectUri);\n};\nconst getIdentityLoginUrl = async (identity, accountConfig, state, options) =\u003e {\n    const defaultState = state\n        ? state\n        : setLoginFlowState({\n            content: options?.content,\n            medium: options?.medium,\n            campaign: options?.campaign,\n            term: options?.term,\n            returnUrl: options?.returnUrl,\n        });\n    const redirectUri = options?.redirectUri\n        ? options.redirectUri\n        : accountConfig.redirectUri;\n    return identity.loginUrl({\n        ...options,\n        redirectUri,\n        state: defaultState,\n    });\n};\nconst showIdentitySimplifiedLoginWidget = async (identity, accountConfig, options) =\u003e {\n    const showSimplifiedLogin = shouldShowSimplifiedLogin(accountConfig);\n    if (showSimplifiedLogin) {\n        try {\n            const redirectUri = options?.redirectUri\n                ? options.redirectUri\n                : accountConfig.redirectUri;\n            const widgetShown = await identity.showSimplifiedLoginWidget({\n                ...options,\n                redirectUri,\n                state: () =\u003e {\n                    return setLoginFlowState({\n                        content: options?.content,\n                        medium: options?.medium,\n                        campaign: options?.campaign,\n                        term: options?.term,\n                        returnUrl: options?.returnUrl,\n                    });\n                },\n            });\n            if (widgetShown) {\n                setSimplifiedLoginState({});\n            }\n        }\n        catch (error) {\n            console.debug(`${error} - Failed to show simplified login`);\n        }\n    }\n};\nconst forceIdentitySimplifiedLoginWidget = async (identity, config, options) =\u003e {\n    try {\n        const redirectUri = options?.redirectUri\n            ? options.redirectUri\n            : config.redirectUri;\n        const widgetShown = await identity.showSimplifiedLoginWidget({\n            ...options,\n            redirectUri,\n            state: () =\u003e {\n                return setLoginFlowState({\n                    content: options?.content,\n                    medium: options?.medium,\n                    campaign: options?.campaign,\n                    term: options?.term,\n                    returnUrl: options?.returnUrl,\n                });\n            },\n        });\n        if (!widgetShown) {\n            throw new Error(`Identity SDK return ${widgetShown}`);\n        }\n        return true;\n    }\n    catch (error) {\n        console.debug(`${error} - Failed to show simplified login`);\n        return false;\n    }\n};\nconst identitySimplifiedLogin = async (identity, config, options) =\u003e {\n    const didShowSimplifiedLogin = await forceIdentitySimplifiedLoginWidget(identity, config, options);\n    if (!didShowSimplifiedLogin) {\n        await loginUser(identity, config, options);\n    }\n};\n/**\n * Initialize the account SDK with the account configuration\n * and return the identity instance\n *\n * @param {InitAccountConfig} initAccountOptions - The account configuration options\n * @param {string} initAccountOptions.site - The site name (e.g., \"aftonbladet\", \"vg\")\n * @param {string} initAccountOptions.env - The deployment stage (e.g., \"pro\", \"dev\")\n *\n * @returns {Promise\u003cAccount\u003e} `Account` - Returns the initialized Account instance\n */\nconst initAccountSdk = (initAccountOptions) =\u003e {\n    const accountConfig = getSiteAccountConfig(initAccountOptions);\n    if (!identity) {\n        identity = new Identity(accountConfig);\n    }\n    // enable varnish cookie for identity if configured\n    if (accountConfig.varnish) {\n        identity.enableVarnishCookie({\n            domain: accountConfig.varnish.domain,\n            expiresIn: accountConfig.varnish.expiresIn,\n        });\n    }\n    identity.clearCachedUserSession();\n    monetization = new Monetization(accountConfig);\n    // set the identity and monetization instances to the window object\n    window.Identity = identity;\n    window.Monetization = monetization;\n    window.SPiD_Identity = identity;\n    window.SPiD_Monetization = monetization;\n    identity.on(\"logout\", () =\u003e {\n        if (accountConfig.simplifiedLogin) {\n            setSimplifiedLoginState({ loggedOut: true });\n        }\n        if (accountConfig.autoLogin) {\n            storeAutoLoginState({\n                action: \"logout\",\n                autoLoginStateKey: accountConfig.autoLogin?.autoLoginStateKey,\n            });\n        }\n        identity.clearCachedUserSession();\n    });\n    identity\n        .hasSession()\n        .finally(dispatchIdentityInitialized)\n        .catch(() =\u003e { });\n    const getUser = async () =\u003e {\n        return getUserInfo(identity);\n    };\n    const getUserWithProduct = async () =\u003e {\n        const user = await getUser();\n        return getProductInfo({ user, accountConfig });\n    };\n    const login = async (options) =\u003e {\n        if (accountConfig.autoLogin) {\n            await autoLoginUser(identity, accountConfig, options);\n        }\n        return loginUser(identity, accountConfig, options);\n    };\n    const simplifiedLogin = async (options) =\u003e {\n        return identitySimplifiedLogin(identity, accountConfig, options);\n    };\n    const logout = async (options) =\u003e {\n        return logoutUser(identity, accountConfig, options);\n    };\n    const getLoginUrl = async (state, options) =\u003e {\n        return getIdentityLoginUrl(identity, accountConfig, state, options);\n    };\n    const showSimplifiedLoginWidget = async (options) =\u003e {\n        return showIdentitySimplifiedLoginWidget(identity, accountConfig, options);\n    };\n    const forceSimplifiedLoginWidget = async (options) =\u003e {\n        return forceIdentitySimplifiedLoginWidget(identity, accountConfig, options);\n    };\n    const autoLogin = async (options) =\u003e {\n        if (accountConfig.autoLogin) {\n            await autoLoginUser(identity, accountConfig, options);\n        }\n        else {\n            console.debug(\"Auto login is not enabled in the account configuration\");\n        }\n    };\n    return {\n        identity,\n        monetization,\n        getUser,\n        getUserWithProduct,\n        login,\n        simplifiedLogin,\n        logout,\n        getLoginUrl,\n        showSimplifiedLoginWidget,\n        forceSimplifiedLoginWidget,\n        autoLogin,\n    };\n};\n/**\n * Initializes the account SDK and sets the account store state using nanoStores.\n *\n * @param {InitAccountConfig} config - The account configuration options\n * @param {string} config.site - The site name (e.g., \"aftonbladet\", \"vg\")\n * @param {string} config.env - The deployment stage (e.g., \"pro\", \"dev\")\n */\nexport function initAccountStore(config) {\n    if (isBrowser) {\n        accountStore.set(initAccountSdk(config));\n    }\n    return null;\n}\n/**\n * Get the current account store state\n *\n * @returns {Promise\u003cReadonly\u003cAccount\u003e | null\u003e} `Promise\u003cReadonly\u003cAccount\u003e | null\u003e` - Returns the current Account state or waits for it to be set\n * /**\n * Account interface\n *\n * The account interface provides methods to interact with the account SDK.\n * It includes methods to get user information, login, logout, and manage product access.\n *\n * Available properties and methods\n *\n * @property {identity}: The Identity instance used for authentication\n * @property {monetization}: The Monetization instance used for product access\n * @method {getUser}: Get logged-in user session information\n * @method {getUserWithProduct}: Get product information for the user\n * @method {getLoginUrl}: Get login URL for the user\n * @method {login}: Login user and return the window object\n * @method {simplifiedLogin}: Show the simplified login widget if enabled or show the regular login\n * @method {logout}: Logout the user\n * @method {showSimplifiedLoginWidget}: Show the simplified login widget (continue as prompt)\n * @method {forceSimplifiedLoginWidget}: Force to show the simplified login widget (continue as prompt)\n * @method {autoLogin}: Automatically log in the user if autoLogin is enabled\n * @method {getGlobalIdentityInstance}: Get the global Identity instance from the window object\n */\nexport const getAccountStore = async () =\u003e {\n    return new Promise((resolve) =\u003e {\n        const state = accountStore.get();\n        if (state) {\n            resolve(state);\n        }\n        else {\n            const unlisten = accountStore.listen((state) =\u003e {\n                resolve(state);\n                unlisten();\n            });\n        }\n    });\n};\n/**\n * Get the current account store state synchronously\n *\n * @returns {Readonly\u003cAccount\u003e | null} `Readonly\u003cAccount\u003e | null` - Returns the current Account state or null if not set\n */\nexport const getAccountStoreSync = () =\u003e {\n    return accountStore.get();\n};\n","const DAYS_TO_MILLISECONDS = 24 * 60 * 60 * 1000;\nconst redirectStateKey = \"auth_state\";\nconst simplifiedLoginStateKey = \"simplified_login_state\";\nconst getSessionStorage = () =\u003e window.sessionStorage;\nconst getLocalStorage = () =\u003e window.localStorage;\n/**\n * Map to store the redirect state\n */\nconst redirectStateMap = new Map();\n/**\n * Set the login flow state by updating the redirect state in local storage\n * This function generates a unique state for the login flow\n * and stores it in the session storage.\n *\n * @param {Partial\u003cSetFlowStateArgs\u003e} - The parameters to set for the login flow state\n * @param `content` - UTM content parameter\n * @param `medium` - UTM medium parameter\n * @param `campaign` - UTM campaign parameter\n * @param `term` - UTM term parameter\n * @param `returnUrl` - The URL to redirect to after login, defaults to current window location\n *\n * @returns {string} - The state to use for the login flow\n */\nexport const setLoginFlowState = ({ content, medium, campaign, term, returnUrl, }) =\u003e {\n    if (typeof window === \"undefined\") {\n        return \"\";\n    }\n    // Create URL from provided returnUrl or current window location\n    const origin = new URL(returnUrl || window.location.href);\n    const action = \"login\";\n    // Set UTM parameters with the action as the source\n    origin.searchParams.set(\"utm_source\", action);\n    if (content) {\n        origin.searchParams.set(\"utm_content\", content);\n    }\n    if (medium) {\n        origin.searchParams.set(\"utm_medium\", medium);\n    }\n    if (campaign) {\n        origin.searchParams.set(\"utm_campaign\", campaign);\n    }\n    if (term) {\n        origin.searchParams.set(\"utm_term\", term);\n    }\n    const originString = origin.toString();\n    let callbackState = redirectStateMap.get(originString);\n    if (!callbackState || callbackState.action !== \"login\") {\n        const state = crypto.randomUUID();\n        callbackState = {\n            origin: originString,\n            state,\n            action,\n        };\n        redirectStateMap.set(originString, callbackState);\n        try {\n            getSessionStorage().setItem(redirectStateKey, JSON.stringify(callbackState));\n            getSessionStorage().setItem(`${redirectStateKey}_${state}`, JSON.stringify(callbackState));\n        }\n        catch (err) {\n            console.debug(`${err} - Failed to set login flow state to storage`);\n        }\n    }\n    return callbackState.state || \"\";\n};\n/**\n * Set the logout flow state by updating the redirect state in local storage\n * This function generates a unique state for the logout flow\n * and stores it in the session storage.\n *\n * @param {Partial\u003cSetFlowStateArgs\u003e} - The parameters to set for the logout flow state\n * @param `content` - UTM content parameter\n * @param `medium` - UTM medium parameter\n * @param `campaign` - UTM campaign parameter\n * @param `term` - UTM term parameter\n * @param `returnUrl` - The URL to redirect to after logout, defaults to current window location\n *\n * @returns {string} - The state to use for the logout flow\n */\nexport const setLogoutFlowState = ({ content, medium, campaign, term, returnUrl, }) =\u003e {\n    if (typeof window === \"undefined\") {\n        return \"\";\n    }\n    // Create URL from provided returnUrl or current window location\n    const origin = new URL(returnUrl || window.location.href);\n    const action = \"logout\";\n    // Set UTM parameters with the action as the source\n    origin.searchParams.set(\"utm_source\", action);\n    if (content) {\n        origin.searchParams.set(\"utm_content\", content);\n    }\n    if (medium) {\n        origin.searchParams.set(\"utm_medium\", medium);\n    }\n    if (campaign) {\n        origin.searchParams.set(\"utm_campaign\", campaign);\n    }\n    if (term) {\n        origin.searchParams.set(\"utm_term\", term);\n    }\n    const originString = origin.toString();\n    const state = crypto.randomUUID();\n    const callbackState = {\n        origin: originString,\n        action,\n        state,\n    };\n    try {\n        getSessionStorage().setItem(redirectStateKey, JSON.stringify(callbackState));\n        getSessionStorage().setItem(`${redirectStateKey}_${callbackState.action}`, JSON.stringify(callbackState));\n    }\n    catch (err) {\n        console.debug(`${err} - 'Failed to set logout flow state to storage`);\n    }\n    return callbackState.state || \"\";\n};\n/**\n * Decide whether the simplified login should be shown or not\n *\n * @param enableSimplifiedLogin - Boolean to enable or disable the simplified login\n * @param showAfterLoginDays - Number of days after which the simplified login should be shown after login\n * @param showAfterLogoutDays - Number of days after which the simplified login should be shown after logout\n * @returns {boolean} - Boolean to decide whether the simplified login should be shown\n */\nexport const shouldShowSimplifiedLogin = ({ simplifiedLogin = undefined, }) =\u003e {\n    try {\n        if (!simplifiedLogin) {\n            return false;\n        }\n        const simplifiedLoginState = JSON.parse(getLocalStorage().getItem(simplifiedLoginStateKey) || \"{}\") || {};\n        const { showAfterLoginInDays = 2, showAfterLogoutInDays = 1 } = simplifiedLogin;\n        const showedOnLoginPageAt = simplifiedLoginState.showedOnLoginPageAt || 0;\n        const showedOnRegularPageAt = simplifiedLoginState.showedOnRegularPageAt || 0;\n        const loggedOutAt = simplifiedLoginState.loggedOutAt || 0;\n        const showedRecentlyOnLoginPage = showedOnLoginPageAt \u003e\n            new Date().getTime() - showAfterLoginInDays * DAYS_TO_MILLISECONDS;\n        const showedRecentlyOnRegularPage = showedOnRegularPageAt \u003e\n            new Date().getTime() - showAfterLoginInDays * DAYS_TO_MILLISECONDS;\n        const loggedOutOnRecently = loggedOutAt \u003e\n            new Date().getTime() - showAfterLogoutInDays * DAYS_TO_MILLISECONDS;\n        return (!showedRecentlyOnRegularPage \u0026\u0026\n            !showedRecentlyOnLoginPage \u0026\u0026\n            !loggedOutOnRecently);\n    }\n    catch (err) {\n        console.debug({ err }, \"Failed to set simplified login state to storage\");\n        return false;\n    }\n};\n/**\n * Set the simplified login state by updating the simplified login state in local storage\n *\n * @param {SetSimplifiedLoginState} - The state to set for the simplified login\n */\nexport const setSimplifiedLoginState = ({ loggedOut = false, }) =\u003e {\n    try {\n        const now = new Date().getTime();\n        const simplifiedLogin = getLocalStorage().getItem(simplifiedLoginStateKey) || {};\n        if (loggedOut) {\n            simplifiedLogin.loggedOutAt = now;\n            getLocalStorage().setItem(simplifiedLoginStateKey, JSON.stringify(simplifiedLogin));\n            return;\n        }\n        simplifiedLogin.showedOnRegularPageAt = now;\n        simplifiedLogin.showedOnLoginPageAt = now;\n        getLocalStorage().setItem(simplifiedLoginStateKey, JSON.stringify(simplifiedLogin));\n    }\n    catch (err) {\n        console.debug(`${err} - Failed to set simplified login state to storage`);\n    }\n};\n/**\n * Store the auto-login state in local storage.\n *\n * @param action - The action to perform, either \"login\" or \"logout\"\n * @param autoLoginStateKey - The key used to store the auto-login state (default is \"lastAutoLogin\")\n */\nexport const storeAutoLoginState = ({ action = \"login\", autoLoginStateKey = \"lastAutoLogin\", }) =\u003e {\n    const timestamp = new Date().getTime().toString();\n    const autoLoginState = {\n        loggedInAt: action === \"login\" ? timestamp : undefined,\n        loggedOutAt: action === \"logout\" ? timestamp : undefined,\n    };\n    getLocalStorage().setItem(autoLoginStateKey, JSON.stringify(autoLoginState));\n};\n/**\n * Check if the auto-login attempt is too soon based on the last login or logout time.\n *\n * @param autoLoginStateKey - The key used to store the auto-login state (default is \"lastAutoLogin\")\n * @param days - The number of days to check against\n * @returns {boolean} - Returns true if the auto-login attempt is too soon, otherwise false\n */\nexport const isAutoLoginAttemptTooSoon = (autoLoginStateKey, days) =\u003e {\n    const lastAutoLogin = JSON.parse(getLocalStorage().getItem(autoLoginStateKey) || \"{}\") || {};\n    const { loggedInAt, loggedOutAt } = lastAutoLogin ?? {};\n    const now = new Date().getTime();\n    if (loggedInAt \u0026\u0026 parseInt(loggedInAt) \u003e now - DAYS_TO_MILLISECONDS * days) {\n        console.debug(\"auto-login attempted too soon\");\n        return true;\n    }\n    if (loggedOutAt \u0026\u0026\n        parseInt(loggedOutAt) \u003e now - DAYS_TO_MILLISECONDS * days) {\n        console.debug(\"auto-login attempted too soon after logout\");\n        return true;\n    }\n    return false;\n};\n","import { atom } from \"nanostores\";\n/**\n * A store for the current account instance.\n * This store holds the current account instance or null if no account is set.\n *\n * @remarks\n * This store is used to manage the current account state in the application.\n * It allows components to reactively access the current account instance.\n * If the account is not set, it will be null.\n */\nexport const accountStore = atom(null);\n","import { isAutoLoginAttemptTooSoon, setLoginFlowState, storeAutoLoginState, } from \"./login-flow.js\";\n/**\n * Retrieves the user context data from the provided identity instance.\n * if no identity instance is provided, it defaults to the global `window.Identity`.\n *\n * @param identity [optional] - The Identity instance to use for retrieving user context data.\n * @returns A promise that resolves to the identifier from the user context data, or undefined if an error occurs.\n */\nexport const getUserIdentifier = async (identity) =\u003e {\n    try {\n        const identityInstance = identity || window.Identity;\n        if (!identityInstance) {\n            console.warn(\"No Identity instance found for auto-login.\");\n            return undefined;\n        }\n        const context = await identityInstance.getUserContextData();\n        return context?.identifier;\n    }\n    catch {\n        return undefined;\n    }\n};\n/**\n * Attempts to automatically log in the user using the provided identity instance.\n *\n * ❌ DO NOT USE THIS FUNCTION DIRECTLY. Use `nanostore account instance` instead and use login and autoLogin from that.\n *\n * @param identity - The Identity instance to use for logging in.\n * @param autLoginStatekey - The key used to store the auto-login state (default is \"auto_login_state\").\n * @param config - The account configuration object containing auto-login settings and redirect URI.\n */\nexport const autoLogin = async (identity, config, options) =\u003e {\n    const { autoLoginStateKey = \"auto_login_state\", expireDays = 3 } = config.autoLogin || {};\n    if (isAutoLoginAttemptTooSoon(autoLoginStateKey, expireDays)) {\n        return;\n    }\n    if (await identity.isLoggedIn()) {\n        return;\n    }\n    const identifier = await getUserIdentifier(identity);\n    if (identifier) {\n        storeAutoLoginState({\n            action: \"login\",\n            autoLoginStateKey: autoLoginStateKey,\n        });\n        const state = setLoginFlowState({\n            content: options?.content,\n            medium: options?.medium,\n            campaign: options?.campaign,\n            term: options?.term,\n            returnUrl: options?.returnUrl,\n        });\n        const redirectUri = options?.redirectUri\n            ? options.redirectUri\n            : config.redirectUri;\n        identity.login({\n            ...options,\n            state,\n            redirectUri,\n            loginHint: identifier,\n            originCampaign: \"autologin\",\n        });\n    }\n};\n","/**\n * Account configuration for different sites in production\n *\n * @remarks\n * This configuration is used to set up account-related features for each site.\n * It includes client IDs, environment settings, redirect URIs, session domains,\n * and product IDs.\n * @see {@link AccountConfig} for details on the configuration structure.\n * @see {@link InitAccountConfig} for the initialization options.\n */\nexport const accountSiteConfigPro = {\n    aftonbladet: {\n        clientId: \"5e4e6b8dba2d9d68e7f1ccdc\",\n        env: \"PRO\",\n        redirectUri: \"https://www.aftonbladet.se/callback\",\n        sessionDomain: \"https://id.aftonbladet.se\",\n        realm: \"schibsted.com\",\n        productIds: [\"FEA-AB-PLUSARTICLES\"],\n        varnish: {\n            domain: \"aftonbladet.se\",\n        },\n        autoLogin: {\n            expireDays: 3,\n            autoLoginStateKey: \"ab_auto_login\",\n        },\n        locale: \"sv\",\n    },\n    vg: {\n        clientId: \"4ef1cfb0e962dd2e0d8d0000\",\n        env: \"PRO_NO\",\n        redirectUri: \"https://www.vg.no/auth/callback\",\n        sessionDomain: \"https://id.vg.no\",\n        realm: \"spid.no\",\n        productIds: [\n            \"FEA-VG-PLUSARTICLES\", // vg-pluss\n            \"FEA-VG-SPORT\", // \"Feature\"-VG+ Sport\n            \"FEA-PODME\", // \"Feature\"-Podme\n        ],\n        varnish: {\n            domain: \"vg.no\",\n        },\n        autoLogin: {\n            expireDays: 3,\n            autoLoginStateKey: \"vg_auto_login\",\n        },\n        locale: \"nb\",\n    },\n    aftenposten: {\n        clientId: \"520204a6411c7a8838000000\",\n        env: \"PRO_NO\",\n        redirectUri: \"https://www.aftenposten.no/login-redirect\",\n        sessionDomain: \"https://id.aftenposten.no\",\n        realm: \"spid.no\",\n        productIds: [\"AP-BASIC\"],\n        varnish: {\n            domain: \"aftenposten.no\",\n        },\n        simplifiedLogin: {\n            showAfterLoginInDays: 3,\n            showAfterLogoutInDays: 1,\n        },\n        locale: \"nb\",\n    },\n    svd: {\n        clientId: \"5774e30f1f357a100e8b4567\",\n        env: \"PRO\",\n        redirectUri: \"https://login.svd.se/v2/login\",\n        sessionDomain: \"https://id.svd.se\",\n        realm: \"schibsted.com\",\n        productIds: [\n            \"eSvD\",\n            \"SvD.se\",\n            \"SVD-BASIC\",\n            \"SVD-EPAPER\",\n            \"SVD-CROSS\",\n            \"SVD-SUDOKU\",\n            \"SVD-ARCHIVE\",\n            \"SVD-VINMAT\",\n            \"SVD-KOMPAKT\",\n        ],\n        autoLogin: {\n            expireDays: 3,\n            autoLoginStateKey: \"svd_auto_login\",\n        },\n        locale: \"sv\",\n    },\n    bt: {\n        clientId: \"50cf3a14421c7a895d000004\",\n        env: \"PRO_NO\",\n        redirectUri: \"https://www.bt.no/login-redirect\",\n        sessionDomain: \"https://id.bt.no\",\n        realm: \"spid.no\",\n        productIds: [\"BT-BASIC\"],\n        varnish: {\n            domain: \"bt.no\",\n        },\n        simplifiedLogin: {\n            showAfterLoginInDays: 3,\n            showAfterLogoutInDays: 1,\n        },\n        locale: \"nb\",\n    },\n    aftenbladet: {\n        clientId: \"50cf3c40421c7a186400000e\",\n        env: \"PRO_NO\",\n        redirectUri: \"https://www.aftenbladet.no/login-redirect\",\n        sessionDomain: \"https://id.aftenbladet.no\",\n        realm: \"spid.no\",\n        productIds: [\"SA-BASIC\"],\n        varnish: {\n            domain: \"aftenbladet.no\",\n        },\n        simplifiedLogin: {\n            showAfterLoginInDays: 3,\n            showAfterLogoutInDays: 1,\n        },\n        locale: \"nb\",\n    },\n    e24: {\n        clientId: \"4d46b0cd74dea2fd799a0000\",\n        env: \"PRO_NO\",\n        redirectUri: \"https://e24.no/auth/callback\",\n        sessionDomain: \"https://id.e24.no\",\n        realm: \"spid.no\",\n        productIds: [\n            \"FEA-E24-PLUSARTICLES\",\n            \"FEA-VG-PLUSARTICLES\",\n            \"FEA-E24-PLUSS-DINE-PENGER\",\n        ],\n        varnish: {\n            domain: \"e24.no\",\n        },\n        autoLogin: {\n            expireDays: 3,\n            autoLoginStateKey: \"e24_auto_login\",\n        },\n        locale: \"nb\",\n    },\n};\n/**\n * Account configuration for different sites in development\n *\n * @remarks\n * This configuration is used to set up account-related features for each site\n * in a development environment. It includes client IDs, environment settings,\n * redirect URIs, session domains, and product IDs.\n * @see {@link AccountConfig} for details on the configuration structure.\n * @see {@link InitAccountConfig} for the initialization options.\n */\nexport const accountSiteConfigDev = {\n    aftonbladet: {\n        clientId: \"5e4e6e3e25b6493fd49dc40f\",\n        env: \"PRE\",\n        redirectUri: \"https://www.aftonbladet.dev/callback\",\n        sessionDomain: \"https://id-pre.aftonbladet.dev\",\n        realm: \"schibsted.com\",\n        productIds: [],\n        locale: \"sv\",\n    },\n    vg: {\n        clientId: \"4f0d95c6efd04b7c44000005\",\n        env: \"PRE\",\n        redirectUri: \"add_pre_redirect_uri\",\n        sessionDomain: \"https://id-pre.vg.no\",\n        realm: \"spid.no\",\n        productIds: [],\n        locale: \"nb\",\n    },\n    aftenposten: {\n        clientId: \"510fb7e1efd04bf00d000000\",\n        env: \"PRE\",\n        redirectUri: \"/login-redirect\",\n        sessionDomain: \"https://id-pre.aftenposten.no\",\n        realm: \"spid.no\",\n        productIds: [\"AP-BASIC\"],\n        locale: \"nb\",\n    },\n    svd: {\n        clientId: \"5420126f8e6b284d5baa71f7\",\n        env: \"PRE\",\n        redirectUri: \"https://login-dev.svd.se/v2/login\",\n        sessionDomain: \"https://id-pre.svd.se\",\n        realm: \"schibsted.com\",\n        productIds: [\n            \"eSvD\",\n            \"SvD.se\",\n            \"SVD-BASIC\",\n            \"SVD-EPAPER\",\n            \"SVD-CROSS\",\n            \"SVD-SUDOKU\",\n            \"SVD-ARCHIVE\",\n            \"SVD-VINMAT\",\n            \"SVD-KOMPAKT\",\n        ],\n        autoLogin: {\n            expireDays: 3,\n            autoLoginStateKey: \"svd_auto_login\",\n        },\n        locale: \"sv\",\n    },\n    bt: {\n        clientId: \"5037826aefd04b6471000000\",\n        env: \"PRE\",\n        redirectUri: \"/login-redirect\",\n        sessionDomain: \"https://id-pre.bt.no\",\n        realm: \"spid.no\",\n        productIds: [\"BT-BASIC\"],\n        locale: \"nb\",\n    },\n    aftenbladet: {\n        clientId: \"506c29eaefd04b147c000001\",\n        env: \"PRE\",\n        redirectUri: \"/login-redirect\",\n        sessionDomain: \"https://id-pre.aftenbladet.no\",\n        realm: \"spid.no\",\n        productIds: [\"SA-BASIC\"],\n        locale: \"nb\",\n    },\n    e24: {\n        clientId: \"4f33d9beefd04ba23b00001c\",\n        env: \"PRE\",\n        redirectUri: \"https://stage.e24.no/auth/callback\",\n        sessionDomain: \"https://id-pre.e24.no\",\n        realm: \"spid.no\",\n        productIds: [\"FEA-E24-REALTIME-V3-BASIC\"],\n        locale: \"nb\",\n        varnish: {\n            domain: \"stage.e24.no\",\n        },\n        autoLogin: {\n            expireDays: 3,\n            autoLoginStateKey: \"e24_auto_login\",\n        },\n    },\n};\n/**\n * Retrieves the account configuration for a specific site based on the deployment stage.\n *\n * @param initAccountOptions - The initialization options containing the site and deployment stage.\n * @returns The account configuration for the specified site and deployment stage.\n * @throws Will throw an error if no configuration is found for the specified site.\n */\nexport function getSiteAccountConfig(initAccountOptions) {\n    const { site, env } = initAccountOptions;\n    const config = env === \"pro\" ? accountSiteConfigPro[site] : accountSiteConfigDev[site];\n    if (!config) {\n        throw new Error(`No account config found for site: ${site}`);\n    }\n    if (initAccountOptions.redirectUri) {\n        return {\n            ...config,\n            redirectUri: initAccountOptions.redirectUri,\n        };\n    }\n    return config;\n}\n"],"version":3}
