{"version":3,"file":"static/js/index.cc3e94c0.js","sources":["webpack://mw-frontend/./src/AuthenticationService.ts","webpack://mw-frontend/./src/fetchWebSiteConfiguration.ts","webpack://mw-frontend/./src/index.js"],"sourcesContent":["import Keycloak, { type KeycloakConfig, type KeycloakInitOptions } from 'keycloak-js';\n\nclass AuthenticationService {\n updateTokenTimeoutId: number | null = null;\n minValidity = 15;\n keycloak: Keycloak;\n\n constructor(config: KeycloakConfig) {\n this.keycloak = new Keycloak(config);\n this.keycloak.onTokenExpired = this.handleUpdateToken;\n this.keycloak.onAuthRefreshError = this.handleAuthRefreshError;\n }\n\n clearUpdateTokenTimeoutId = () => {\n window.removeEventListener('online', this.handleUpdateToken);\n if (this.updateTokenTimeoutId) {\n clearTimeout(this.updateTokenTimeoutId);\n this.updateTokenTimeoutId = null;\n }\n };\n\n handleUpdateToken = () => {\n this.clearUpdateTokenTimeoutId();\n this.keycloak.updateToken(this.minValidity);\n };\n\n handleAuthRefreshError = () => {\n this.clearUpdateTokenTimeoutId();\n\n if (!navigator.onLine) {\n console.error('AuthRefreshError: navigator.onLine = ' + navigator.onLine + ' wait for online event');\n window.addEventListener('online', this.handleUpdateToken);\n } else {\n this.updateTokenTimeoutId = window.setTimeout(this.handleUpdateToken, 10000);\n }\n };\n\n init(\n options: KeycloakInitOptions = {\n onLoad: 'login-required',\n enableLogging: false,\n },\n ) {\n return this.keycloak.init({ ...options, pkceMethod: 'S256' });\n }\n\n login() {\n this.keycloak.login();\n }\n\n logout() {\n let pathname = window.location.pathname;\n if (pathname !== '' && pathname[0] !== '/') {\n pathname = `/${pathname}`;\n }\n this.keycloak.logout({ redirectUri: window.location.origin + pathname });\n }\n\n get isTokenExpired() {\n return this.keycloak.isTokenExpired(this.minValidity);\n }\n\n updateToken() {\n return this.keycloak.updateToken(this.minValidity);\n }\n\n tokenAsync() {\n if (this.keycloak.isTokenExpired(this.minValidity)) {\n return this.updateToken().then(() => this.keycloak.token!);\n }\n return Promise.resolve(this.keycloak.token!);\n }\n\n tokenOrError() {\n if (!this.keycloak.token) {\n throw new Error('keycloak token is undefined');\n }\n return this.keycloak.token;\n }\n\n addTokenToUrl(originalUrl) {\n if (!originalUrl) return '';\n\n const url = new URL(originalUrl);\n url.searchParams.set('access_token', this.tokenOrError());\n\n return url.toString();\n }\n\n get fullName() {\n if (!this.keycloak || !this.keycloak.idTokenParsed) {\n return undefined;\n }\n\n const idToken = this.keycloak.idTokenParsed as Record;\n const firstName = idToken.given_name as string;\n let lastName = idToken.family_name as string;\n lastName = lastName === '-' ? '' : lastName; // handle photographers that have \"-\" as lastName\n\n if (!lastName || firstName.includes(lastName)) {\n return firstName;\n }\n\n return `${firstName} ${lastName}`;\n }\n\n get email() {\n if (!this.keycloak || !this.keycloak.idTokenParsed) {\n return undefined;\n }\n\n const idToken = this.keycloak.idTokenParsed as Record;\n return idToken.email as string;\n }\n\n get realm() {\n return this.keycloak.realm;\n }\n}\n\nexport let authenticationService: AuthenticationService;\n\nexport function createAuthenticationService({ url, realm, clientId }: KeycloakConfig) {\n authenticationService = new AuthenticationService({ url, realm, clientId });\n return authenticationService;\n}\n","// Be careful importing modules here, this is used in the index.js chunk and we want to avoid unneeded transitive dependencies !!!!\n\nexport async function fetchWebSiteConfiguration(baseUrlApi: string, token: string) {\n const response = await fetch(`${baseUrlApi}/WebSiteConfiguration/`, {\n credentials: 'include',\n headers: {\n Authorization: `Bearer ${token}`,\n },\n });\n\n return response.json();\n}\n","import { createAuthenticationService } from './AuthenticationService';\nimport { fetchWebSiteConfiguration } from './fetchWebSiteConfiguration';\n\nconst APPSETTINGS_JSON = `${import.meta.env.BASE_URL}/appsettings.json?v=${Date.now()}`;\n\nasync function fetchIdentityInformation(endpointApi, token) {\n const response = await fetch(endpointApi, {\n credentials: 'include',\n headers: {\n Authorization: `Bearer ${token}`,\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n body: JSON.stringify({\n query: `{\n viewer {\n identityInformation {\n primaryShopId\n }\n }\n }`,\n }),\n });\n\n return response.json();\n}\n\nasync function run() {\n try {\n window.MW_APP_SETTINGS = await (\n await fetch(APPSETTINGS_JSON, {\n credentials: 'include',\n })\n ).json();\n\n const constants = await import(/* webpackChunkName: \"constants\" */ './Constants');\n const {\n AUTH_URL,\n AUTH_REALM,\n AUTH_CLIENT_ID,\n BASE_URL_API,\n ENDPOINT_API,\n SETTINGS_PREFIX,\n updateDefaultShop,\n updateSettingsPrefix,\n } = constants;\n\n const authenticationService = createAuthenticationService({\n url: AUTH_URL,\n realm: AUTH_REALM,\n clientId: AUTH_CLIENT_ID,\n });\n\n await authenticationService.init();\n const token = await authenticationService.tokenAsync();\n\n const [{ data }, webSiteConfiguration] = await Promise.all([\n fetchIdentityInformation(ENDPOINT_API, token),\n fetchWebSiteConfiguration(BASE_URL_API, token),\n ]);\n\n updateDefaultShop(data.viewer.identityInformation.primaryShopId);\n updateSettingsPrefix(SETTINGS_PREFIX + data.viewer.identityInformation.primaryShopId + '.');\n\n const index2 = await import(/* webpackChunkName: \"index2\" */ './index2');\n index2.default(webSiteConfiguration);\n } catch (e) {\n if (\n e instanceof TypeError &&\n (e.message === 'Failed to fetch' || e.message === 'NetworkError when attempting to fetch resource')\n ) {\n return;\n }\n console.error('initialization failed', e);\n }\n}\n\nrun();\n"],"names":["authenticationService","AuthenticationService","config","window","clearTimeout","navigator","console","Keycloak","options","pathname","Promise","Error","originalUrl","url","URL","idToken","firstName","lastName","createAuthenticationService","realm","clientId","fetchWebSiteConfiguration","baseUrlApi","token","response","fetch","APPSETTINGS_JSON","Date","fetchIdentityInformation","endpointApi","JSON","run","AUTH_URL","AUTH_REALM","AUTH_CLIENT_ID","BASE_URL_API","ENDPOINT_API","SETTINGS_PREFIX","updateDefaultShop","updateSettingsPrefix","data","webSiteConfiguration","index2","e","TypeError"],"mappings":"oDAwHWA,E,uCAtHX,OAAMC,EAKJ,YAAYC,CAAsB,CAAE,C,KAJpC,oBAAoB,CAAkB,K,KACtC,WAAW,CAAG,G,KASd,yBAAyB,C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