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OC,EAAO,IAAI,QAAQ,EAC1BC,EAAYhC,EAAoB,WAAW,EAE3CiC,EAAU,CACf,GAAIH,EAAO,CAAE,KAAAA,CAAA,EAAS,CAAC,EACvB,GAAIE,EAAY,CAAE,UAAAA,CAAA,EAAc,CAAC,GAG3B,OAAAP,EAAa,yBAAyBQ,CAAO,CACrD,EACA,EACA,MAAOvB,GAAU,CACjB,QAAQ,MAAMA,CAAK,EACZ,gBAAS,QAAQ,GAAG,EAC3B,CACH,EAEM0B,EAAQhB,EAAwB,EACtCG,UAGC,OAAO,SAAS,KAAK,cAAc,SAAQf,mBAAoB,cAApBA,cAAiC,aAAa,IAAM,EAElFF,IACH,OAAO,SAAS,SAAS,gBAAkBM,EAC9C,gBAAS,QAAQwB,GAAS,GAAG,EAErBF","names":["config","createQueryStringFromObject","obj","queryString","item","getQueryStringValue","name","currentLocationDecoded","guestInit","__vitePreload","mainInit","completeAuth","TokenManagerFactory","tokenManagerConfig","activeRoute","error","continueAsGuestKey","continueAsGuestPath","getRelativeUri","absoluteUri","createContinueAsGuestRedirectUri","createContinueAsGuestSessionStorageKey","getUserContinuedAsGuestFromStorage","saveUserContinuedAsGuestToStorage","continueAsGuestToUrlStorageKey","getContinueAsGuestToUrl","setContinueAsGuestToUrl","value","clearContinueAsGuestToUrl","runGuestSignInFlow","tokenManager","currentLocation","currentLocationHasContinueAsGuestSearchParam","mod","cagRedirect","lang","cookie","getaquote","options","loadAppOrGuest","isAuthenticated","toUrl"],"sources":["../../../ClientApp/src/tokenManagerConfig.ts","../../../ClientApp/src/utils/queryUtils.ts","../../../ClientApp/src/loader.ts"],"sourcesContent":["// Copyright (c) 2023 Proto Labs, Inc. All Rights Reserved.\n\nimport { TokenManagerConfig } from '@protolabs/enterprise-token-manager';\n\nconst config: TokenManagerConfig = {\n\tacrValues: '',\n\tauthority: window.authorityUri,\n\tclientId: window.clientId,\n\tredirectUri: window.defaultReturnUri,\n\tpostLogoutRedirectUri: window.postLogoutUri,\n\tmonitorOnRedirectUri: false,\n\tfilterProtocolClaims: false,\n};\n\nif (import.meta.env.DEV) {\n\t// Increase renew window to 5 minutes before expiration.\n\tconfig.refreshAccessTokenExpireOffset = 300;\n\n\t// config.logLevel = LogLevel.DEBUG;\n\t// config.maxRefreshTokenExpireMinutes = 1;\n}\n\nexport default config;\n","// Copyright (c) 2022 Proto Labs, Inc. All Rights Reserved.\n\n/**\n * Get QueryString from key value pair\n * @param {Object} obj\n * @return {String}\n */\nexport function createQueryStringFromObject(obj: any) {\n\tlet queryString = '';\n\tif (obj && Object.keys(obj).length) {\n\t\tqueryString = `?${Object.keys(obj)\n\t\t\t.map((item) => `${item}=${encodeURIComponent(obj[item])}`)\n\t\t\t.join('&')}`;\n\t}\n\treturn queryString;\n}\n\n/**\n * Return querystring value from name\n * @param {String} name\n * @return {String}\n */\nexport function getQueryStringValue(name: string) {\n\tconst currentLocationDecoded = new URL(decodeURIComponent(window.location.href));\n\tconst params = new URLSearchParams(currentLocationDecoded.search);\n\treturn params.get(name);\n}\n\nexport default {\n\tcreateQueryStringFromObject,\n\tgetQueryStringValue,\n};\n","// Copyright (c) 2023 Proto Labs, Inc. All Rights Reserved.\n\n'use strict';\n\nimport { TokenManager, TokenManagerFactory } from '@protolabs/enterprise-token-manager';\nimport tokenManagerConfig from '@/tokenManagerConfig';\nimport cookie from 'js-cookie';\nimport { getQueryStringValue } from '@/utils/queryUtils';\n\n// allows us to split the guest/main flow without extra custom code\n// vite allows us to dynamically import these modules as an async method\n// and will only render one or the other depending on which gets called\nconst guestInit = async () => await import('./guest');\nconst mainInit = async () => await import('./main');\n\n/**\n * Invoke on a redirect handshake back to commerce.\n */\nconst completeAuth = () => {\n\tconst tokenManager = TokenManagerFactory.getOrCreateTokenManager(tokenManagerConfig);\n\ttokenManager\n\t\t.completeAuthenticationAsync()\n\t\t.then((activeRoute) => {\n\t\t\twindow.location.replace(activeRoute);\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error(error);\n\t\t\twindow.location.replace('/');\n\t\t});\n};\n\nconst continueAsGuestKey = 'cag';\nconst continueAsGuestPath = '/continue-as-guest';\n\nconst getRelativeUri = (absoluteUri: any) =>\n\t`${absoluteUri.pathname}${absoluteUri.search}${absoluteUri.hash}`;\n\nconst createContinueAsGuestRedirectUri = () => {\n\tconst currentLocation = new URL(window.location.href);\n\treturn `${currentLocation.origin}${continueAsGuestPath}`;\n};\n\nconst createContinueAsGuestSessionStorageKey = () =>\n\t`commerce:user-continued-as-guest-on-quote:${window.quoteId}`;\nconst getUserContinuedAsGuestFromStorage = () =>\n\t!!sessionStorage.getItem(createContinueAsGuestSessionStorageKey());\nconst saveUserContinuedAsGuestToStorage = () => {\n\tif (window.quoteId) {\n\t\tsessionStorage.setItem(createContinueAsGuestSessionStorageKey(), '1');\n\t}\n};\n\nconst continueAsGuestToUrlStorageKey = `commerce:continue-as-guest-to-url`;\nconst getContinueAsGuestToUrl = () => sessionStorage.getItem(continueAsGuestToUrlStorageKey);\nconst setContinueAsGuestToUrl = (value: any) =>\n\tsessionStorage.setItem(continueAsGuestToUrlStorageKey, value);\nconst clearContinueAsGuestToUrl = () => sessionStorage.removeItem(continueAsGuestToUrlStorageKey);\n\n/**\n * When an unauthenticated user attempts to access a publically available Quote\n * we want to prompt them to sign in first before allowing them to access the quote. This\n * is done to encourage signups. Requirements call for an inline login form alongside the\n * Continue as Guest option. To meet this requirement we must send them to Identity, requiring\n * a protocol to be established between the services. This function captures the interaction.\n *\n * The procedure is as follows:\n * 1. Commerce recognizes an unauthenticated user is attempting to access a publicly available\n * quote and executes this function;\n * 2. Commerce saves the current url to session storage with cag=1 added to the query string.\n * 3. Commerce starts authentation, passing a /continue-as-guest redirect url to Identity. This\n * manifests as a query string parameter named \"cag\";\n * 4. Identity receives this URL with the \"cag\" parameter and presents an alternate sign-in form\n * with an option to continue as guest;\n * 5. At this point the user may sign in as normal OR choose to Continue as a Guest. When they\n * continue as guest the user is redirected back to the /continue-as-guest path where Commerce\n * pulls the saved url and replaces the current.\n * 6. Commerce once again recognizes the unauthenticated user is attempting to access a publicly\n * available quote, this time with the \"cag\" parameter, the presence of which informs Commerce\n * to allow the guest through to the quote;\n * 7. Commerce strips the \"cag\" query string parameter from the URI and stores the fact that the\n * user opted to continue as guest on this quote to sessionStorage (allowing the user to refresh\n * the page without being prompted to continue as guest again);\n * 8. Commerce loads the guest experience.\n *\n * @param {TokenManager} tokenManager the token manager instance\n * @return {Promise}\n */\nexport const runGuestSignInFlow = (tokenManager: TokenManager) => {\n\tconst currentLocation = new URL(decodeURIComponent(window.location.href));\n\tconst currentLocationHasContinueAsGuestSearchParam =\n\t\tcurrentLocation.searchParams.has(continueAsGuestKey);\n\tif (currentLocationHasContinueAsGuestSearchParam || getUserContinuedAsGuestFromStorage()) {\n\t\tsaveUserContinuedAsGuestToStorage();\n\t\tif (currentLocationHasContinueAsGuestSearchParam) {\n\t\t\tcurrentLocation.searchParams.delete(continueAsGuestKey);\n\t\t\twindow.history.replaceState({}, document.title, getRelativeUri(currentLocation));\n\t\t}\n\n\t\tguestInit().then((mod) => mod.loadApp());\n\n\t\treturn Promise.resolve();\n\t} else {\n\t\tcurrentLocation.searchParams.append(continueAsGuestKey, '1');\n\t\tsetContinueAsGuestToUrl(currentLocation.href);\n\t\tconst cagRedirect = createContinueAsGuestRedirectUri();\n\t\tconst lang = cookie.get('locale');\n\t\tconst getaquote = getQueryStringValue('getaquote');\n\n\t\tconst options = {\n\t\t\t...(lang ? { lang } : {}),\n\t\t\t...(getaquote ? { getaquote } : {}),\n\t\t\t...(cagRedirect ? { [continueAsGuestKey]: cagRedirect } : {}),\n\t\t};\n\n\t\treturn tokenManager.startAuthenticationAsync(options);\n\t}\n};\n\n/**\n * Invoke to conditionally load the main app, guest app. Will trigger redirect\n * to sign in if the user is not authenticated.\n */\nconst loadAppOrGuest = () => {\n\tif (window.isDemoQuote || window.location.pathname.toLowerCase() === '/contactus') {\n\t\tguestInit().then((mod) => mod.loadApp());\n\t\treturn;\n\t}\n\n\tconst tokenManager = TokenManagerFactory.getOrCreateTokenManager(tokenManagerConfig);\n\ttokenManager\n\t\t.initializeAsync()\n\t\t.then((isAuthenticated: boolean) => {\n\t\t\tif (isAuthenticated) {\n\t\t\t\tmainInit().then((mod) => mod.loadApp());\n\t\t\t\treturn Promise.resolve();\n\t\t\t} else if (window.isPublic) {\n\t\t\t\treturn runGuestSignInFlow(tokenManager);\n\t\t\t} else {\n\t\t\t\tconst lang = cookie.get('locale');\n\t\t\t\tconst getaquote = getQueryStringValue('getaquote');\n\n\t\t\t\tconst options = {\n\t\t\t\t\t...(lang ? { lang } : {}),\n\t\t\t\t\t...(getaquote ? { getaquote } : {}),\n\t\t\t\t};\n\n\t\t\t\treturn tokenManager.startAuthenticationAsync(options);\n\t\t\t}\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error(error);\n\t\t\twindow.location.replace('/');\n\t\t});\n};\n\nconst toUrl = getContinueAsGuestToUrl();\nclearContinueAsGuestToUrl();\n\nif (\n\twindow.location.href.toLowerCase().indexOf(tokenManagerConfig?.redirectUri?.toLowerCase()) === 0\n) {\n\tcompleteAuth();\n} else if (window.location.pathname.toLowerCase() === continueAsGuestPath) {\n\twindow.location.replace(toUrl || '/');\n} else {\n\tloadAppOrGuest();\n}\n"],"file":"loader-8c3cbcfd.js"}