{"version":3,"sources":["../src/evaneos/utilities/locales.ts","../src/evaneos/utilities/authentication.ts"],"sourcesContent":["import cookie from 'js-cookie';\n\nconst DEFAULT_LOCALE = 'en';\n\nexport const availableLocales = ['fr', 'en', 'it', 'es', 'de'] as const;\nexport type Locale = (typeof availableLocales)[number];\n\nexport const LOCALE_COOKIE_KEY = 'evaneos_ets_locale';\n\nfunction getCurrentLocaleFromBrowser(): Locale | null {\n    const locale = navigator?.language;\n    if (!locale) {\n        return null;\n    }\n    const language = locale.split('-')[0];\n    return availableLocales.includes(language as Locale)\n        ? (language as Locale)\n        : null;\n}\n\nfunction getCurrentLocaleFromCookie(): Locale | null {\n    const locale = cookie.get(LOCALE_COOKIE_KEY);\n    if (!locale) return null;\n\n    return availableLocales.includes(locale as Locale)\n        ? (locale as Locale)\n        : null;\n}\n\nexport function getCurrentLocale(): Locale {\n    return (\n        getCurrentLocaleFromCookie() ||\n        getCurrentLocaleFromBrowser() ||\n        DEFAULT_LOCALE\n    );\n}\n\nexport const setLocaleCookie = (locale: Locale) => {\n    cookie.remove(LOCALE_COOKIE_KEY);\n    cookie.set(LOCALE_COOKIE_KEY, locale);\n};\n\ntype NestedMessages = { [key: string]: string | NestedMessages };\n\nexport const flattenMessages = (\n    nestedMessages: NestedMessages,\n    prefix = ''\n): { [key: string]: string } => {\n    return Object.keys(nestedMessages).reduce(\n        (messages: { [key: string]: string }, key) => {\n            const value = nestedMessages[key];\n            const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n            if (typeof value === 'string') {\n                messages[prefixedKey] = value;\n            } else {\n                Object.assign(messages, flattenMessages(value, prefixedKey));\n            }\n\n            return messages;\n        },\n        {} as { [key: string]: string }\n    );\n};\n","import Cookies from 'js-cookie';\nimport { jwtDecode, JwtPayload } from 'jwt-decode';\nimport memoizeOne from 'memoize-one';\n\ntype AgentDetails = {\n    /** Also known as agentId */\n    userId: number;\n    userName: string;\n    userEmail: string;\n    agencyId: number;\n    agencyName: string;\n};\n\ninterface EtsJWTPayload extends JwtPayload {\n    user_id: number;\n    user_name: string;\n    user_email: string;\n    agency_id: number;\n    agency_name: string;\n    iat: number;\n    exp: number;\n}\n\nconst memoizedDecode = /* #__PURE__ */ memoizeOne(jwtDecode<EtsJWTPayload>);\n\nexport const ETS_TOKEN_NAME = /* #__PURE__ */ 'ets_token';\n\nexport const getETSUserCookiePayload = (): AgentDetails | null => {\n    const authToken = Cookies.get(ETS_TOKEN_NAME);\n    if (!authToken) {\n        return null;\n    }\n\n    const { user_id, user_name, user_email, agency_id, agency_name } =\n        memoizedDecode(authToken);\n    return {\n        userId: user_id,\n        userName: user_name,\n        userEmail: user_email,\n        agencyId: agency_id,\n        agencyName: agency_name,\n    };\n};\n"],"mappings":";AAAA,OAAO,YAAY;AAEnB,IAAM,iBAAiB;AAEhB,IAAM,mBAAmB,CAAC,MAAM,MAAM,MAAM,MAAM,IAAI;AAGtD,IAAM,oBAAoB;AAEjC,SAAS,8BAA6C;AAClD,QAAM,SAAS,uCAAW;AAC1B,MAAI,CAAC,QAAQ;AACT,WAAO;AAAA,EACX;AACA,QAAM,WAAW,OAAO,MAAM,GAAG,EAAE,CAAC;AACpC,SAAO,iBAAiB,SAAS,QAAkB,IAC5C,WACD;AACV;AAEA,SAAS,6BAA4C;AACjD,QAAM,SAAS,OAAO,IAAI,iBAAiB;AAC3C,MAAI,CAAC;AAAQ,WAAO;AAEpB,SAAO,iBAAiB,SAAS,MAAgB,IAC1C,SACD;AACV;AAEO,SAAS,mBAA2B;AACvC,SACI,2BAA2B,KAC3B,4BAA4B,KAC5B;AAER;AAEO,IAAM,kBAAkB,CAAC,WAAmB;AAC/C,SAAO,OAAO,iBAAiB;AAC/B,SAAO,IAAI,mBAAmB,MAAM;AACxC;AAIO,IAAM,kBAAkB,CAC3B,gBACA,SAAS,OACmB;AAC5B,SAAO,OAAO,KAAK,cAAc,EAAE;AAAA,IAC/B,CAAC,UAAqC,QAAQ;AAC1C,YAAM,QAAQ,eAAe,GAAG;AAChC,Y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