{"version":3,"sources":["webpack:///../node_modules/@ux/auth/dist/es/InfoProvider-a0a3f665.js","webpack:///../node_modules/@ux/auth/dist/es/di-1c3e4f7b.js"],"names":["basicToCustomer","idp","info_shopperId","username","kind","CUSTOMER","shopperId","convertIdpToUser","del","info_accountName","firstname","lastname","e2s","DELEGATE","firstName","lastName","customer","e2sToDelegate","Error","di","jpex","constant","factory","location","hostname","getHostname","window","getAppName","args","encodeURIComponent","path","level","getLevelupPath","getLoginPath","host","app","getLogoutPath","children","ref","current","commonDi","getCookieDomain$1","COOKIE_DOMAIN","e","getCookieDomain","APP_NAME","pathname","getPathname","cookieKeys","cookies","cookieKey","Promise","res","rej","cookie","get","JSON","parse","fetchInfo","domain","forEach","key","erase","clearAuth","fetch","convert","async","fetchAuth","url","href","redirectToLogin","redirectToLogout","redirect","logout"],"mappings":"8EAAA,mIAqBA,MAAMA,EAAkBC,IACtB,MAAM,eACJC,EAAc,SACdC,GACEF,EACJ,MAAO,CACLG,KAAM,IAAKC,SACXC,UAAWJ,EACXC,aAsBEI,EAAmBN,IACvB,GAAI,YAAYA,GACd,OAAOD,EAAgBC,GAGzB,GAAI,YAAUA,GACZ,MAxBkBA,KACpB,MACEO,KAAK,iBACHC,EAAgB,UAChBC,EAAS,SACTC,GACD,IACDC,GACEX,EACJ,MAAO,CACLG,KAAM,IAAKS,SACXV,SAAUM,EACVK,UAAWJ,EACXK,SAAUJ,EACVK,SAAUhB,EAAgBY,KAUnBK,CAAchB,GAGvB,MAAM,IAAIiB,MAAM,sBAmClB,IAAIC,EAAMC,IACR,YAASA,GACTA,EAAKC,SAAS,2BAA4B,CAAC,WAAY,aACvDD,EAAKE,QAAQ,4BAA6B,IAVxBC,IAAY,IAEjB,eADA,YAAcA,EAASC,UASYC,CAAYC,OAAOH,WACnEH,EAAKC,SAAS,kCAAmCd,GACjDa,EAAKE,QAAQ,+BAAgC,CAAC,2BAA4B,6BAA8B,CAACK,EAAYF,IArChG,EAACE,EAAYF,IAAgBG,GAM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HFoD,EAAI,IAAInC,MAAM,mBAIvB,MAAOyB,GACPU,EAAIV,MAoD8Ee,CAAU,IAASV,EAAW,KAClH5B,EAAKE,QAAQ,0BAA2B,CAAC,4BAA6B0B,GApFtD,EAACC,EAASL,EAAiBI,IAAe,KAC1D,MAAMW,EAASf,IACfI,EAAWY,QAAQC,IACjBZ,EAAQa,MAAMD,EAAK,CACjBF,cAgFgFI,CAAU,IAAStB,EAAmBO,IAC1H5B,EAAKE,QAAQ,0BAA2B,CAAC,0BAA2B,mCAAoC,CAAC0C,EAAOC,IA5EhG,EAACD,EAAOC,IAAYC,UACpC,MAAMjE,QAAY+D,IAElB,OADaC,EAAQhE,IA0EuGkE,CAAUH,EAAOC,IAC7I7C,EAAKE,QAAQ,gCAAiC,CAAC,6BAA8B,6BAA8B,CAACW,EAAcc,IAtCpG,EAACxB,EAAUU,EAAcc,IAAgB,EAC/DjB,QACE,MACF,MAAMsC,EAAMnC,EAAa,CACvBH,KAAMiB,EAAYjB,KAEpBP,EAAS8C,KAAOD,GAgC0HE,CAAgB5C,OAAOH,SAAUU,EAAcc,IACzL3B,EAAKE,QAAQ,iCAAkC,CAAC,8BAA+B,6BAA8B,CAACc,EAAeW,IA9BtG,EAACxB,EAAUa,EAAeW,IAAgB,EACjEjB,QACE,MACF,MAAMsC,EAAMhC,EAAc,CACxBN,KAAMiB,EAAYjB,KAEpBP,EAAS8C,KAAOD,GAwB6HG,CAAiB7C,OAAOH,SAAUa,EAAeW,IAC9L3B,EAAKE,QAAQ,uBAAwB,CAAC,0BAA2B,kCAAmC,CAACyC,EAAWS,IA7CnG,EAACT,EAAWS,IAAa5C,IACtCmC,IACAS,EAAS5C,IA2CoH6C,CAAOV,EAAWS","file":"pex-static/12/82.5d92a30945c40690a354.chunk.js","sourcesContent":["import '@ux/hooks';\nimport '@ux/promise';\nimport { resolve } from 'url';\nimport { useJpex } from 'react-jpex';\nimport { useRef } from 'react';\nimport 'react-query';\nimport { isBasicInfo, Kind, isE2sInfo, getRootDomain, useAuth } from './auth.js';\nimport 'jpex';\nimport 'react-with-suspense-lazy';\nimport '@team-griffin/rehook';\nimport '@ux/pure-enhance';\nimport '@ux/penders';\nimport '@ux/theme-utils';\nimport '@team-griffin/css-sides';\nimport '@ux/type-size';\nimport '@team-griffin/stylr';\nimport 'browser-cookies';\nimport { c as commonDi } from './di-1c3e4f7b.js';\n\n/* eslint-disable camelcase */\n\nconst basicToCustomer = idp => {\n const {\n info_shopperId,\n username\n } = idp;\n return {\n kind: Kind.CUSTOMER,\n shopperId: info_shopperId,\n username\n };\n};\n\nconst e2sToDelegate = idp => {\n const {\n del: {\n info_accountName,\n firstname,\n lastname\n },\n e2s\n } = idp;\n return {\n kind: Kind.DELEGATE,\n username: info_accountName,\n firstName: firstname,\n lastName: lastname,\n customer: basicToCustomer(e2s)\n };\n};\n\nconst convertIdpToUser = idp => {\n if (isBasicInfo(idp)) {\n return basicToCustomer(idp);\n }\n\n if (isE2sInfo(idp)) {\n return e2sToDelegate(idp);\n }\n\n throw new Error('Unknown auth type');\n};\n\nconst getLevelupPath = (getAppName, getHostname) => args => {\n const realm = 'idp';\n const host = getHostname();\n const app = encodeURIComponent(getAppName());\n const path = encodeURIComponent(args.path);\n const level = encodeURIComponent(args.level);\n return `${host}/identity-verification?app=${app}&path=${path}&realm=${realm}&hbi=${level}`;\n};\n\nconst getLoginPath = (getAppName, getHostname) => args => {\n const realm = 'idp';\n const host = getHostname();\n const app = encodeURIComponent(getAppName());\n const path = encodeURIComponent(args.path);\n return `${host}?app=${app}&path=${path}&realm=${realm}`;\n};\n\nconst getLogoutPath = (getAppName, getHostname) => args => {\n const realm = 'idp';\n const host = getHostname();\n const app = encodeURIComponent(getAppName());\n const path = encodeURIComponent(args.path);\n return resolve(host, `/logout?app=${app}&path=${path}&realm=${realm}`);\n};\n\nconst getHostname = location => () => {\n const root = getRootDomain(location.hostname);\n const host = `https://sso.${root}`;\n return host;\n};\n\n/* eslint-disable max-len */\nvar di = (jpex => {\n commonDi(jpex);\n jpex.constant(\"type:@ux/auth/CookieKeys\", ['info_idp', 'auth_idp']);\n jpex.factory(\"type:@ux/auth/GetHostname\", () => getHostname(window.location));\n jpex.constant(\"type:@ux/auth/ConvertInfoToUser\", convertIdpToUser);\n jpex.factory(\"type:@ux/auth/GetLevelupPath\", [\"type:@ux/auth/GetAppName\", \"type:@ux/auth/GetHostname\"], (getAppName, getHostname) => getLevelupPath(getAppName, getHostname));\n jpex.factory(\"type:@ux/auth/GetLoginPath\", [\"type:@ux/auth/GetAppName\", \"type:@ux/auth/GetHostname\"], (getAppName, getHostname) => getLoginPath(getAppName, getHostname));\n jpex.factory(\"type:@ux/auth/GetLogoutPath\", [\"type:@ux/auth/GetAppName\", \"type:@ux/auth/GetHostname\"], (getAppName, getHostname) => getLogoutPath(getAppName, getHostname));\n});\n\nconst IdpProvider = ({\n children\n}) => {\n const jpex = useJpex(); // we want to only do this once, but we want to do it _before_ the `useEffect` step\n\n const ref = useRef(false);\n\n if (!ref.current) {\n di(jpex);\n ref.current = true;\n } // fetch the auth tokens\n\n\n useAuth();\n return children;\n};\n\nexport default IdpProvider;\n","import cookies from 'browser-cookies';\n\nconst clearAuth = (cookies, getCookieDomain, cookieKeys) => () => {\n const domain = getCookieDomain();\n cookieKeys.forEach(key => {\n cookies.erase(key, {\n domain\n });\n });\n};\n\nconst fetchAuth = (fetch, convert) => async () => {\n const idp = await fetch();\n const user = convert(idp);\n return user;\n};\n\nconst fetchInfo = (cookies, cookieKey) => () => new Promise((res, rej) => {\n try {\n const cookie = cookies.get(cookieKey);\n\n if (!cookie) {\n return rej(new Error('no auth cookie'));\n }\n\n const idp = JSON.parse(cookie);\n\n if (!idp) {\n return rej(new Error('no auth cookie'));\n }\n\n return res(idp);\n } catch (e) {\n rej(e);\n }\n});\n\nconst getCookieDomain = () => () => {\n try {\n return COOKIE_DOMAIN;\n } catch (e) {\n return '';\n }\n};\n\nconst logout = (clearAuth, redirect) => args => {\n clearAuth();\n redirect(args);\n};\n\nconst redirectToLogin = (location, getLoginPath, getPathname) => ({\n path\n} = {}) => {\n const url = getLoginPath({\n path: getPathname(path)\n });\n location.href = url;\n};\n\nconst redirectToLogout = (location, getLogoutPath, getPathname) => ({\n path\n} = {}) => {\n const url = getLogoutPath({\n path: getPathname(path)\n });\n location.href = url;\n};\n\nconst getAppName = () => () => {\n try {\n return APP_NAME;\n } catch (e) {\n throw new Error('APP_NAME not set');\n }\n};\n\nconst getPathname = window => path => {\n return path != null ? path : window.location.pathname;\n};\n\n/* eslint-disable max-len */\nvar commonDi = (jpex => {\n const getCookieDomain$1 = getCookieDomain();\n jpex.constant(\"type:@ux/auth/GetAppName\", getAppName());\n jpex.factory(\"type:@ux/auth/GetPathname\", () => getPathname(window));\n jpex.factory(\"type:@ux/auth/FetchInfo\", [\"type:@ux/auth/CookieKeys\"], cookieKeys => fetchInfo(cookies, cookieKeys[0]));\n jpex.factory(\"type:@ux/auth/ClearAuth\", [\"type:@ux/auth/CookieKeys\"], cookieKeys => clearAuth(cookies, getCookieDomain$1, cookieKeys));\n jpex.factory(\"type:@ux/auth/FetchAuth\", [\"type:@ux/auth/FetchInfo\", \"type:@ux/auth/ConvertInfoToUser\"], (fetch, convert) => fetchAuth(fetch, convert));\n jpex.factory(\"type:@ux/auth/RedirectToLogin\", [\"type:@ux/auth/GetLoginPath\", \"type:@ux/auth/GetPathname\"], (getLoginPath, getPathname) => redirectToLogin(window.location, getLoginPath, getPathname));\n jpex.factory(\"type:@ux/auth/RedirectToLogout\", [\"type:@ux/auth/GetLogoutPath\", \"type:@ux/auth/GetPathname\"], (getLogoutPath, getPathname) => redirectToLogout(window.location, getLogoutPath, getPathname));\n jpex.factory(\"type:@ux/auth/Logout\", [\"type:@ux/auth/ClearAuth\", \"type:@ux/auth/RedirectToLogout\"], (clearAuth, redirect) => logout(clearAuth, redirect));\n});\n\nexport { commonDi as c };\n"],"sourceRoot":""}