@dropins/storefront-auth 2.2.0-alpha007 → 2.2.0-alpha009

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{Initializer as u,Config as h,getCookie as l}from"@dropins/tools/lib.js";import{events as c}from"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{C as g,v as C}from"./verifyToken.js";import{f as p}from"./network-error.js";const a=new h(void 0),m=new u({init:async e=>{const t={...{authHeaderConfig:{header:"Authorization",tokenPrefix:"Bearer"}},...e};m.config.setConfig(t);const n=l(g.auth_dropin_user_token),[r]=await Promise.all([C(t.authHeaderConfig.header,t.authHeaderConfig.tokenPrefix),n?d():Promise.resolve()]);a.setConfig(r)},listeners:()=>[c.on("authenticated",e=>{const i=a.getConfig();i!==void 0&&e!==i&&(a.setConfig(e),d())})]}),k=m.config,P=`
3
+ import{Initializer as u,Config as h}from"@dropins/tools/lib.js";import{a as l,v as g,C}from"./verifyToken.js";import{events as c}from"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{f as p}from"./network-error.js";const a=new h(void 0),m=new u({init:async e=>{const t={...{authHeaderConfig:{header:"Authorization",tokenPrefix:"Bearer"}},...e};m.config.setConfig(t);const n=l(C.auth_dropin_user_token),[r]=await Promise.all([g(t.authHeaderConfig.header,t.authHeaderConfig.tokenPrefix),n?d():Promise.resolve()]);a.setConfig(r)},listeners:()=>[c.on("authenticated",e=>{const i=a.getConfig();i!==void 0&&e!==i&&(a.setConfig(e),d())})]}),k=m.config,P=`
4
4
  query GET_CUSTOMER_ROLE_PERMISSIONS {
5
5
  customer {
6
6
  role {
@@ -1 +1 @@
1
- {"version":3,"file":"getCustomerRolePermissions.js","sources":["/@dropins/storefront-auth/src/api/initialize/initialize.ts","/@dropins/storefront-auth/src/api/getCustomerRolePermissions/graphql/getCustomerRolePermissions.graphql.ts","/@dropins/storefront-auth/src/api/getCustomerRolePermissions/getCustomerRolePermissions.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Initializer, Model, Config, getCookie } from '@adobe-commerce/elsie/lib';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { CustomerModel } from '@/auth/data/models';\nimport { verifyToken, getCustomerRolePermissions } from '@/auth/api';\nimport { events } from '@adobe-commerce/event-bus';\nimport { COOKIE_NAMES } from '@/auth/configs/cookieConfigs';\n\ntype ConfigProps = {\n langDefinitions?: Lang;\n authHeaderConfig: {\n header: string;\n tokenPrefix: string;\n };\n models?: {\n CustomerModel?: Model<CustomerModel>;\n };\n};\n\nconst _authenticated = new Config<boolean | undefined>(undefined);\n\nexport const initialize = new Initializer<ConfigProps>({\n init: async (config) => {\n const defaultConfig = {\n authHeaderConfig: {\n header: 'Authorization',\n tokenPrefix: 'Bearer',\n },\n };\n\n const mergedConfig = { ...defaultConfig, ...config };\n\n initialize.config.setConfig(mergedConfig);\n\n const token = getCookie(COOKIE_NAMES.auth_dropin_user_token);\n\n const [authenticated] = await Promise.all([\n verifyToken(\n mergedConfig.authHeaderConfig.header,\n mergedConfig.authHeaderConfig.tokenPrefix\n ),\n token ? getCustomerRolePermissions() : Promise.resolve(),\n ]) ;\n\n _authenticated.setConfig(authenticated);\n\n },\n\n listeners: () => [\n events.on('authenticated', (next) => {\n const prev = _authenticated.getConfig();\n\n if (prev !== undefined && next !== prev) {\n _authenticated.setConfig(next);\n getCustomerRolePermissions();\n }\n }),\n ],\n});\n\nexport const config = initialize.config;\n","export const GET_CUSTOMER_ROLE_PERMISSIONS = `\n query GET_CUSTOMER_ROLE_PERMISSIONS {\n customer {\n role {\n id\n name\n permissions {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n }\n }\n }\n }\n }\n }\n }\n }\n }\n`;\n","/********************************************************************\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport { events } from \"@adobe-commerce/event-bus\";\nimport { fetchGraphQl } from \"@/auth/api/fetch-graphql\";\nimport { PermissionsModel } from \"@/auth/data/models\";\nimport { GET_CUSTOMER_ROLE_PERMISSIONS } from \"./graphql/getCustomerRolePermissions.graphql\";\n\n// TypeScript interfaces\ninterface Permission {\n id: string;\n text: string;\n children?: Permission[];\n}\n\ninterface Role {\n id: string;\n name: string;\n permissions?: Permission[];\n}\n\ninterface GetCustomerRolePermissionsResponse {\n data?: {\n customer?: {\n role?: Role;\n };\n };\n errors?: {\n message: string;\n }[];\n}\n\n// Module-level cache\nlet permissionsCache: PermissionsModel | null = null;\nlet fetchPromise: Promise<PermissionsModel> | null = null;\n\n/**\n * Recursively flattens permission tree into a flat object\n */\nconst flattenPermissionTree = (permissions: Permission[]): Record<string, boolean> => {\n const flattened: Record<string, boolean> = {};\n\n const processPermissions = (perms: Permission[]): void => {\n perms.forEach(permission => {\n flattened[permission.id] = true;\n if (permission.children?.length) {\n processPermissions(permission.children);\n }\n });\n };\n\n processPermissions(permissions);\n return flattened;\n};\n\n/**\n * Determines if user has admin privileges\n * Admin is only when user has role ID 'MA==' AND has an empty permissions array\n */\nconst isAdminUser = (role?: Role): boolean => {\n return role?.id === 'MA==' &&\n Array.isArray(role.permissions) &&\n role.permissions.length === 0;\n};\n\n/**\n * Processes role data into flattened permissions\n */\nconst processUserPermissions = (role?: Role): PermissionsModel => {\n if (isAdminUser(role)) {\n return { admin: true };\n }\n\n const basePermissions: PermissionsModel = { all: true };\n \n if (role?.permissions?.length) {\n const flattenedPerms = flattenPermissionTree(role.permissions);\n return { ...basePermissions, ...flattenedPerms };\n }\n\n return basePermissions;\n};\n\n/**\n * Fetches user role permissions from GraphQL API\n */\nconst fetchUserRolePermissions = async (): Promise<PermissionsModel> => {\n try {\n const response = await fetchGraphQl(GET_CUSTOMER_ROLE_PERMISSIONS, {\n method: 'GET'\n }) as GetCustomerRolePermissionsResponse;\n\n const permissions = processUserPermissions(response.data?.customer?.role);\n\n // Update cache\n permissionsCache = permissions;\n fetchPromise = null;\n\n return permissions;\n } catch (error) {\n fetchPromise = null;\n throw error;\n }\n};\n\n/**\n * Gets user role permissions with caching\n */\nexport const getCustomerRolePermissions = (): Promise<PermissionsModel> => {\n // Return cached data as resolved promise if available\n if (permissionsCache) {\n events.emit('auth/permissions', permissionsCache);\n return Promise.resolve(permissionsCache);\n }\n\n // No cache available - create and return fetch promise if not already fetching\n if (!fetchPromise) {\n fetchPromise = fetchUserRolePermissions().then(permissions => {\n events.emit('auth/permissions', permissions);\n return permissions;\n });\n }\n\n return fetchPromise;\n};\n\n/**\n * Resets the permissions cache\n * @internal\n */\nexport const _resetCache = (): void => {\n permissionsCache = null;\n fetchPromise = null;\n};\n"],"names":["_authenticated","Config","initialize","Initializer","config","mergedConfig","token","getCookie","COOKIE_NAMES","authenticated","verifyToken","getCustomerRolePermissions","events","next","prev","GET_CUSTOMER_ROLE_PERMISSIONS","permissionsCache","fetchPromise","flattenPermissionTree","permissions","flattened","processPermissions","perms","permission","_a","isAdminUser","role","processUserPermissions","basePermissions","flattenedPerms","fetchUserRolePermissions","response","fetchGraphQl","_b","error","_resetCache"],"mappings":"2PAmCA,MAAMA,EAAiB,IAAIC,EAA4B,MAAS,EAEnDC,EAAa,IAAIC,EAAyB,CACrD,KAAM,MAAOC,GAAW,CAQtB,MAAMC,EAAe,CAAE,GAPD,CACpB,iBAAkB,CAChB,OAAQ,gBACR,YAA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AAA,EAEjD,IAAIJ,EAAAE,GAAA,YAAAA,EAAM,cAAN,MAAAF,EAAmB,OAAQ,CAC7B,MAAMK,EAAiBX,EAAsBQ,EAAK,WAAW,EAC7D,MAAO,CAAE,GAAGE,EAAiB,GAAGC,CAAA,CAClC,CAEA,OAAOD,CACT,EAKME,EAA2B,SAAuC,SACtE,GAAI,CACF,MAAMC,EAAW,MAAMC,EAAajB,EAA+B,CACjE,OAAQ,KAAA,CACT,EAEKI,EAAcQ,GAAuBM,GAAAT,EAAAO,EAAS,OAAT,YAAAP,EAAe,WAAf,YAAAS,EAAyB,IAAI,EAGxE,OAAAjB,EAAmBG,EACnBF,EAAe,KAERE,CACT,OAASe,EAAO,CACd,MAAAjB,EAAe,KACTiB,CACR,CACF,EAKavB,EAA6B,IAEpCK,GACFJ,EAAO,KAAK,mBAAoBI,CAAgB,EACzC,QAAQ,QAAQA,CAAgB,IAIpCC,IACHA,EAAea,EAAA,EAA2B,KAAKX,IAC7CP,EAAO,KAAK,mBAAoBO,CAAW,EACpCA,EACR,GAGIF,GAOIkB,EAAc,IAAY,CACrCnB,EAAmB,KACnBC,EAAe,IACjB"}
1
+ {"version":3,"file":"getCustomerRolePermissions.js","sources":["/@dropins/storefront-auth/src/api/initialize/initialize.ts","/@dropins/storefront-auth/src/api/getCustomerRolePermissions/graphql/getCustomerRolePermissions.graphql.ts","/@dropins/storefront-auth/src/api/getCustomerRolePermissions/getCustomerRolePermissions.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { Initializer, Model, Config } from '@adobe-commerce/elsie/lib';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { getCookie } from '@/auth/lib/cookieUtils';\nimport { CustomerModel } from '@/auth/data/models';\nimport { verifyToken, getCustomerRolePermissions } from '@/auth/api';\nimport { events } from '@adobe-commerce/event-bus';\nimport { COOKIE_NAMES } from '@/auth/configs/cookieConfigs';\n\ntype ConfigProps = {\n langDefinitions?: Lang;\n authHeaderConfig: {\n header: string;\n tokenPrefix: string;\n };\n models?: {\n CustomerModel?: Model<CustomerModel>;\n };\n};\n\nconst _authenticated = new Config<boolean | undefined>(undefined);\n\nexport const initialize = new Initializer<ConfigProps>({\n init: async (config) => {\n const defaultConfig = {\n authHeaderConfig: {\n header: 'Authorization',\n tokenPrefix: 'Bearer',\n },\n };\n\n const mergedConfig = { ...defaultConfig, ...config };\n\n initialize.config.setConfig(mergedConfig);\n\n const token = getCookie(COOKIE_NAMES.auth_dropin_user_token);\n\n const [authenticated] = await Promise.all([\n verifyToken(\n mergedConfig.authHeaderConfig.header,\n mergedConfig.authHeaderConfig.tokenPrefix\n ),\n token ? getCustomerRolePermissions() : Promise.resolve(),\n ]) ;\n\n _authenticated.setConfig(authenticated);\n\n },\n\n listeners: () => [\n events.on('authenticated', (next) => {\n const prev = _authenticated.getConfig();\n\n if (prev !== undefined && next !== prev) {\n _authenticated.setConfig(next);\n getCustomerRolePermissions();\n }\n }),\n ],\n});\n\nexport const config = initialize.config;\n","export const GET_CUSTOMER_ROLE_PERMISSIONS = `\n query GET_CUSTOMER_ROLE_PERMISSIONS {\n customer {\n role {\n id\n name\n permissions {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n children {\n id\n text\n }\n }\n }\n }\n }\n }\n }\n }\n }\n`;\n","/********************************************************************\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport { events } from \"@adobe-commerce/event-bus\";\nimport { fetchGraphQl } from \"@/auth/api/fetch-graphql\";\nimport { PermissionsModel } from \"@/auth/data/models\";\nimport { GET_CUSTOMER_ROLE_PERMISSIONS } from \"./graphql/getCustomerRolePermissions.graphql\";\n\n// TypeScript interfaces\ninterface Permission {\n id: string;\n text: string;\n children?: Permission[];\n}\n\ninterface Role {\n id: string;\n name: string;\n permissions?: Permission[];\n}\n\ninterface GetCustomerRolePermissionsResponse {\n data?: {\n customer?: {\n role?: Role;\n };\n };\n errors?: {\n message: string;\n }[];\n}\n\n// Module-level cache\nlet permissionsCache: PermissionsModel | null = null;\nlet fetchPromise: Promise<PermissionsModel> | null = null;\n\n/**\n * Recursively flattens permission tree into a flat object\n */\nconst flattenPermissionTree = (permissions: Permission[]): Record<string, boolean> => {\n const flattened: Record<string, boolean> = {};\n\n const processPermissions = (perms: Permission[]): void => {\n perms.forEach(permission => {\n flattened[permission.id] = true;\n if (permission.children?.length) {\n processPermissions(permission.children);\n }\n });\n };\n\n processPermissions(permissions);\n return flattened;\n};\n\n/**\n * Determines if user has admin privileges\n * Admin is only when user has role ID 'MA==' AND has an empty permissions array\n */\nconst isAdminUser = (role?: Role): boolean => {\n return role?.id === 'MA==' &&\n Array.isArray(role.permissions) &&\n role.permissions.length === 0;\n};\n\n/**\n * Processes role data into flattened permissions\n */\nconst processUserPermissions = (role?: Role): PermissionsModel => {\n if (isAdminUser(role)) {\n return { admin: true };\n }\n\n const basePermissions: PermissionsModel = { all: true };\n \n if (role?.permissions?.length) {\n const flattenedPerms = flattenPermissionTree(role.permissions);\n return { ...basePermissions, ...flattenedPerms };\n }\n\n return basePermissions;\n};\n\n/**\n * Fetches user role permissions from GraphQL API\n */\nconst fetchUserRolePermissions = async (): Promise<PermissionsModel> => {\n try {\n const response = await fetchGraphQl(GET_CUSTOMER_ROLE_PERMISSIONS, {\n method: 'GET'\n }) as GetCustomerRolePermissionsResponse;\n\n const permissions = processUserPermissions(response.data?.customer?.role);\n\n // Update cache\n permissionsCache = permissions;\n fetchPromise = null;\n\n return permissions;\n } catch (error) {\n fetchPromise = null;\n throw error;\n }\n};\n\n/**\n * Gets user role permissions with caching\n */\nexport const getCustomerRolePermissions = (): Promise<PermissionsModel> => {\n // Return cached data as resolved promise if available\n if (permissionsCache) {\n events.emit('auth/permissions', permissionsCache);\n return Promise.resolve(permissionsCache);\n }\n\n // No cache available - create and return fetch promise if not already fetching\n if (!fetchPromise) {\n fetchPromise = fetchUserRolePermissions().then(permissions => {\n events.emit('auth/permissions', permissions);\n return permissions;\n });\n }\n\n return fetchPromise;\n};\n\n/**\n * Resets the permissions cache\n * @internal\n */\nexport const _resetCache = (): void => {\n permissionsCache = null;\n fetchPromise = null;\n};\n"],"names":["_authenticated","Config","initialize","Initializer","config","mergedConfig","token","getCookie","COOKIE_NAMES","authenticated","verifyToken","getCustomerRolePermissions","events","next","prev","GET_CUSTOMER_ROLE_PERMISSIONS","permissionsCache","fetchPromise","flattenPermissionTree","permissions","flattened","processPermissions","perms","permission","_a","isAdminUser","role","processUserPermissions","basePermissions","flattenedPerms","fetchUserRolePermissions","response","fetchGraphQl","_b","error","_resetCache"],"mappings":"8OAoCA,MAAMA,EAAiB,IAAIC,EAA4B,MAAS,EAEnDC,EAAa,IAAIC,EAAyB,CACrD,KAAM,MAAOC,GAAW,CAQtB,MAAMC,EAAe,CAAE,GAPD,CACpB,iBAAkB,CAChB,OAAQ,gBACR,YAAa,QAAA,CACf,EAGuC,GAAGD,CAAAA,EAE5CF,EAAW,OAAO,UAAUG,CAAY,EAExC,MAAMC,EAAQC,EAAUC,EAAa,sBAAsB,EAErD,CAACC,CAAa,EAAI,MAAM,QAAQ,IAAI,CACxCC,EACEL,EAAa,iBAAiB,OAC9BA,EAAa,iBAAiB,WAAA,EAEhCC,EAAQK,IAA+B,QAAQ,QAAA,CAAQ,CACxD,EAEDX,EAAe,UAAUS,CAAa,CAExC,EAEA,UAAW,IAAM,CACfG,EAAO,GAAG,gBAAkBC,GAAS,CACnC,MAAMC,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AAAS,EAAyB,IAAI,EAGxE,OAAAjB,EAAmBG,EACnBF,EAAe,KAERE,CACT,OAASe,EAAO,CACd,MAAAjB,EAAe,KACTiB,CACR,CACF,EAKavB,EAA6B,IAEpCK,GACFJ,EAAO,KAAK,mBAAoBI,CAAgB,EACzC,QAAQ,QAAQA,CAAgB,IAIpCC,IACHA,EAAea,EAAA,EAA2B,KAAKX,IAC7CP,EAAO,KAAK,mBAAoBO,CAAW,EACpCA,EACR,GAGIF,GAOIkB,EAAc,IAAY,CACrCnB,EAAmB,KACnBC,EAAe,IACjB"}
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{a as G,f as h,h as $}from"./network-error.js";import"@dropins/tools/recaptcha.js";import{events as w}from"@dropins/tools/event-bus.js";import{merge as k}from"@dropins/tools/lib.js";import{c as R}from"./getCustomerRolePermissions.js";import{CUSTOMER_INFORMATION_FRAGMENT as C}from"../fragments.js";import{a as U,C as O}from"./verifyToken.js";import{p as x,E as y}from"./acdl.js";import{s as F}from"./setReCaptchaToken.js";const v=t=>{var f,o,i,a,c,m,u,s,T,r,g;const e={email:((o=(f=t==null?void 0:t.data)==null?void 0:f.customer)==null?void 0:o.email)??"",firstName:((a=(i=t==null?void 0:t.data)==null?void 0:i.customer)==null?void 0:a.firstname)??"",lastName:((m=(c=t==null?void 0:t.data)==null?void 0:c.customer)==null?void 0:m.lastname)??""};return k(e,(g=(r=(T=(s=(u=R)==null?void 0:u.getConfig())==null?void 0:s.models)==null?void 0:T.CustomerModel)==null?void 0:r.transformer)==null?void 0:g.call(r,t.data))},D=`
3
+ import{a as G,f as h,h as $}from"./network-error.js";import"@dropins/tools/recaptcha.js";import{events as w}from"@dropins/tools/event-bus.js";import{merge as k}from"@dropins/tools/lib.js";import{c as R}from"./getCustomerRolePermissions.js";import{CUSTOMER_INFORMATION_FRAGMENT as C}from"../fragments.js";import{b as U,C as O}from"./verifyToken.js";import{p as x,E as y}from"./acdl.js";import{s as F}from"./setReCaptchaToken.js";const v=t=>{var f,o,i,a,c,m,u,s,T,r,g;const e={email:((o=(f=t==null?void 0:t.data)==null?void 0:f.customer)==null?void 0:o.email)??"",firstName:((a=(i=t==null?void 0:t.data)==null?void 0:i.customer)==null?void 0:a.firstname)??"",lastName:((m=(c=t==null?void 0:t.data)==null?void 0:c.customer)==null?void 0:m.lastname)??""};return k(e,(g=(r=(T=(s=(u=R)==null?void 0:u.getConfig())==null?void 0:s.models)==null?void 0:T.CustomerModel)==null?void 0:r.transformer)==null?void 0:g.call(r,t.data))},D=`
4
4
  query GET_CUSTOMER_DATA {
5
5
  customer {
6
6
  ...CUSTOMER_INFORMATION_FRAGMENT
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{events as f}from"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{f as d,h as g,a as l,r as C}from"./network-error.js";const h={auth_dropin_user_token:"auth_dropin_user_token",auth_dropin_firstname:"auth_dropin_firstname"},s=3600,k=t=>{var o,e,r,c,a,i,n,u,_,m;return{autocompleteOnStorefront:((e=(o=t==null?void 0:t.data)==null?void 0:o.storeConfig)==null?void 0:e.autocomplete_on_storefront)||!1,minLength:((c=(r=t==null?void 0:t.data)==null?void 0:r.storeConfig)==null?void 0:c.minimum_password_length)||3,requiredCharacterClasses:+((i=(a=t==null?void 0:t.data)==null?void 0:a.storeConfig)==null?void 0:i.required_character_classes_number)||0,createAccountConfirmation:((u=(n=t==null?void 0:t.data)==null?void 0:n.storeConfig)==null?void 0:u.create_account_confirmation)||!1,customerAccessTokenLifetime:((m=(_=t==null?void 0:t.data)==null?void 0:_.storeConfig)==null?void 0:m.customer_access_token_lifetime)*s||s}},E=t=>{const o=t.map(e=>e.message).join(" ");throw Error(o)},T=t=>{const o=document.cookie.split(";");let e;return o.forEach(r=>{const[c,a]=r.trim().split("=");c===t&&(e=decodeURIComponent(a))}),e},O=t=>{document.cookie=`${t}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`},N=async()=>{try{const t=sessionStorage.getItem("storeConfig");let e=(t?JSON.parse(t):{}).customerAccessTokenLifetime;if(!e){const r=await A();sessionStorage.setItem("storeConfig",JSON.stringify(r)),e=(r==null?void 0:r.customerAccessTokenLifetime)||s}return`Max-Age=${e}`}catch(t){return console.error("getCookiesLifetime() Error:",t),`Max-Age=${s}`}},S=`
3
+ import{events as f}from"@dropins/tools/event-bus.js";import"@dropins/tools/recaptcha.js";import{f as d,h as g,a as l,r as C}from"./network-error.js";const h={auth_dropin_user_token:"auth_dropin_user_token",auth_dropin_firstname:"auth_dropin_firstname"},s=3600,k=t=>{const o=document.cookie.split(";");let e;return o.forEach(r=>{const[c,a]=r.trim().split("=");c===t&&(e=decodeURIComponent(a))}),e},E=t=>{document.cookie=`${t}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`},N=async()=>{try{const t=sessionStorage.getItem("storeConfig");let e=(t?JSON.parse(t):{}).customerAccessTokenLifetime;if(!e){const r=await A();sessionStorage.setItem("storeConfig",JSON.stringify(r)),e=(r==null?void 0:r.customerAccessTokenLifetime)||s}return`Max-Age=${e}`}catch(t){return console.error("getCookiesLifetime() Error:",t),`Max-Age=${s}`}},T=t=>{var o,e,r,c,a,i,n,u,_,m;return{autocompleteOnStorefront:((e=(o=t==null?void 0:t.data)==null?void 0:o.storeConfig)==null?void 0:e.autocomplete_on_storefront)||!1,minLength:((c=(r=t==null?void 0:t.data)==null?void 0:r.storeConfig)==null?void 0:c.minimum_password_length)||3,requiredCharacterClasses:+((i=(a=t==null?void 0:t.data)==null?void 0:a.storeConfig)==null?void 0:i.required_character_classes_number)||0,createAccountConfirmation:((u=(n=t==null?void 0:t.data)==null?void 0:n.storeConfig)==null?void 0:u.create_account_confirmation)||!1,customerAccessTokenLifetime:((m=(_=t==null?void 0:t.data)==null?void 0:_.storeConfig)==null?void 0:m.customer_access_token_lifetime)*s||s}},O=t=>{const o=t.map(e=>e.message).join(" ");throw Error(o)},S=`
4
4
  query GET_STORE_CONFIG {
5
5
  storeConfig {
6
6
  autocomplete_on_storefront
@@ -14,11 +14,11 @@ import{events as f}from"@dropins/tools/event-bus.js";import"@dropins/tools/recap
14
14
  customer_access_token_lifetime
15
15
  }
16
16
  }
17
- `,A=async()=>await d(S,{method:"GET",cache:"force-cache"}).then(t=>{var o;return(o=t.errors)!=null&&o.length?E(t.errors):k(t)}).catch(g),I=`
17
+ `,A=async()=>await d(S,{method:"GET",cache:"force-cache"}).then(t=>{var o;return(o=t.errors)!=null&&o.length?O(t.errors):T(t)}).catch(g),I=`
18
18
  query VALIDATE_TOKEN {
19
19
  customerCart {
20
20
  id
21
21
  }
22
22
  }
23
- `,q=async(t="Authorization",o="Bearer")=>{const e=T(h.auth_dropin_user_token);return f.emit("authenticated",!!e),e?(l(t,`${o} ${e}`),d(I).then(r=>{var a;return!((a=r.errors)!=null&&a.find(i=>{var n;return((n=i.extensions)==null?void 0:n.category)==="graphql-authentication"}))?!0:(O(h.auth_dropin_user_token),C(t),f.emit("authenticated",!1),!1)})):!1};export{h as C,N as a,O as d,A as g,E as h,q as v};
23
+ `,q=async(t="Authorization",o="Bearer")=>{const e=k(h.auth_dropin_user_token);return f.emit("authenticated",!!e),e?(l(t,`${o} ${e}`),d(I).then(r=>{var a;return!((a=r.errors)!=null&&a.find(i=>{var n;return((n=i.extensions)==null?void 0:n.category)==="graphql-authentication"}))?!0:(E(h.auth_dropin_user_token),C(t),f.emit("authenticated",!1),!1)})):!1};export{h as C,k as a,N as b,E as d,A as g,O as h,q as v};
24
24
  //# sourceMappingURL=verifyToken.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verifyToken.js","sources":["/@dropins/storefront-auth/src/configs/cookieConfigs.ts","/@dropins/storefront-auth/src/data/transforms/transform-store-config.ts","/@dropins/storefront-auth/src/lib/fetch-error.ts","/@dropins/storefront-auth/src/lib/cookieUtils.ts","/@dropins/storefront-auth/src/api/getStoreConfig/graphql/getStoreConfig.graphql.ts","/@dropins/storefront-auth/src/api/getStoreConfig/getStoreConfig.ts","/@dropins/storefront-auth/src/api/verifyToken/graphql/verifyToken.graphql.ts","/@dropins/storefront-auth/src/api/verifyToken/verifyToken.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nconst COOKIE_NAMES = {\n auth_dropin_user_token: 'auth_dropin_user_token',\n auth_dropin_firstname: 'auth_dropin_firstname',\n};\n\nconst COOKIE_LIFETIME = 3600;\n\nexport { COOKIE_NAMES, COOKIE_LIFETIME };\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getStoreConfigResponse } from '@/auth/types';\nimport { COOKIE_LIFETIME } from '@/auth/configs/cookieConfigs';\nimport { StoreConfigModel } from '../models';\n\nexport const transformStoreConfig = (\n response: getStoreConfigResponse\n): StoreConfigModel => {\n return {\n autocompleteOnStorefront:\n response?.data?.storeConfig?.autocomplete_on_storefront || false,\n // Need information about min length in response undefined\n minLength: response?.data?.storeConfig?.minimum_password_length || 3,\n requiredCharacterClasses:\n +response?.data?.storeConfig?.required_character_classes_number || 0,\n createAccountConfirmation:\n response?.data?.storeConfig?.create_account_confirmation || false,\n customerAccessTokenLifetime:\n response?.data?.storeConfig?.customer_access_token_lifetime *\n COOKIE_LIFETIME || COOKIE_LIFETIME,\n };\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\n/** Actions */\nexport const handleFetchError = (errors: Array<{ message: string }>) => {\n const errorMessage = errors.map((e: any) => e.message).join(' ');\n\n throw Error(errorMessage);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\n/* eslint-disable no-useless-escape */\nimport { getStoreConfig } from '@/auth/api';\nimport { COOKIE_LIFETIME } from '@/auth/configs/cookieConfigs';\n\nexport const getCookie = (cookieName: string) => {\n const cookies = document.cookie.split(';');\n let foundValue;\n\n cookies.forEach((cookie) => {\n const [name, value] = cookie.trim().split('=');\n if (name === cookieName) {\n foundValue = decodeURIComponent(value);\n }\n });\n\n return foundValue;\n};\n\nexport const deleteCookie = (cookieName: string) => {\n document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;\n};\n\nexport const getCookiesLifetime = async () => {\n try {\n const storeConfigString = sessionStorage.getItem('storeConfig');\n const cachedStoreConfig = storeConfigString\n ? JSON.parse(storeConfigString)\n : {};\n\n let accessTokenLifeTime = cachedStoreConfig.customerAccessTokenLifetime;\n\n if (!accessTokenLifeTime) {\n const storeConfig = await getStoreConfig();\n\n sessionStorage.setItem('storeConfig', JSON.stringify(storeConfig));\n\n accessTokenLifeTime =\n storeConfig?.customerAccessTokenLifetime || COOKIE_LIFETIME;\n }\n\n return `Max-Age=${accessTokenLifeTime}`;\n } catch (error) {\n console.error('getCookiesLifetime() Error:', error);\n return `Max-Age=${COOKIE_LIFETIME}`;\n }\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nexport const GET_STORE_CONFIG = /* GraphQL */ `\n query GET_STORE_CONFIG {\n storeConfig {\n autocomplete_on_storefront\n minimum_password_length\n required_character_classes_number\n store_code\n store_name\n store_group_code\n locale\n create_account_confirmation\n customer_access_token_lifetime\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getStoreConfigResponse } from '@/auth/types';\nimport { fetchGraphQl } from '../fetch-graphql';\nimport { GET_STORE_CONFIG } from './graphql/getStoreConfig.graphql';\nimport { handleNetworkError } from '@/auth/lib/network-error';\nimport { transformStoreConfig } from '@/auth/data/transforms';\nimport { StoreConfigModel } from '@/auth/data/models';\nimport { handleFetchError } from '@/auth/lib/fetch-error';\n\nexport const getStoreConfig = async (): Promise<StoreConfigModel> => {\n return await fetchGraphQl(GET_STORE_CONFIG, {\n method: 'GET',\n cache: 'force-cache',\n })\n .then((response: getStoreConfigResponse) => {\n if (response.errors?.length) return handleFetchError(response.errors);\n\n return transformStoreConfig(response);\n })\n .catch(handleNetworkError);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nexport const VALIDATE_CUSTOMER_TOKEN = /* GraphQL */ `\n query VALIDATE_TOKEN {\n customerCart {\n id\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { events } from '@adobe-commerce/event-bus';\nimport {\n fetchGraphQl,\n removeFetchGraphQlHeader,\n setFetchGraphQlHeader,\n} from '../fetch-graphql';\nimport { deleteCookie, getCookie } from '@/auth/lib/cookieUtils';\nimport { COOKIE_NAMES } from '@/auth/configs/cookieConfigs';\nimport { VALIDATE_CUSTOMER_TOKEN } from './graphql/verifyToken.graphql';\n\nexport const verifyToken = async (\n authType = 'Authorization',\n type = 'Bearer'\n) => {\n const token = getCookie(COOKIE_NAMES.auth_dropin_user_token);\n\n events.emit('authenticated', !!token);\n\n if (!token) return false;\n\n setFetchGraphQlHeader(authType, `${type} ${token}`);\n\n return fetchGraphQl(VALIDATE_CUSTOMER_TOKEN).then((res) => {\n const unauthenticated = !!res.errors?.find(\n (error) => error.extensions?.category === 'graphql-authentication'\n );\n\n if (!unauthenticated) return true;\n\n deleteCookie(COOKIE_NAMES.auth_dropin_user_token);\n removeFetchGraphQlHeader(authType);\n events.emit('authenticated', false);\n return false;\n });\n};\n"],"names":["COOKIE_NAMES","COOKIE_LIFETIME","transformStoreConfig","response","_b","_a","_d","_c","_f","_e","_h","_g","_j","_i","handleFetchError","errors","errorMessage","getCookie","cookieName","cookies","foundValue","cookie","name","value","deleteCookie","getCookiesLifetime","storeConfigString","accessTokenLifeTime","storeConfig","getStoreConfig","error","GET_STORE_CONFIG","fetchGraphQl","handleNetworkError","VALIDATE_CUSTOMER_TOKEN","verifyToken","authType","type","token","events","setFetchGraphQlHeader","res","removeFetchGraphQlHeader"],"mappings":"qJAiBA,MAAMA,EAAe,CACnB,uBAAwB,yBACxB,sBAAuB,uBACzB,EAEMC,EAAkB,KCDXC,EACXC,GACqB,yBACrB,MAAO,CACL,2BACEC,GAAAC,EAAAF,GAAA,YAAAA,EAAU,OAAV,YAAAE,EAAgB,cAAhB,YAAAD,EAA6B,6BAA8B,GAE7D,YAAWE,GAAAC,EAAAJ,GAAA,YAAAA,EAAU,OAAV,YAAAI,EAAgB,cAAhB,YAAAD,EAA6B,0BAA2B,EACnE,yBACE,GAACE,GAAAC,EAAAN,GAAA,YAAAA,EAAU,OAAV,YAAAM,EAAgB,cAAhB,YAAAD,EAA6B,oCAAqC,EACrE,4BACEE,GAAAC,EAAAR,GAAA,YAAAA,EAAU,OAAV,YAAAQ,EAAgB,cAAhB,YAAAD,EAA6B,8BAA+B,GAC9D,8BACEE,GAAAC,EAAAV,GAAA,YAAAA,EAAU,OAAV,YAAAU,EAAgB,cAAhB,YAAAD,EAA6B,gCAC3BX,GAAmBA,CAAA,CAE3B,ECnBaa,EAA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CC,EAAc,MACzBC,EAAW,gBACXC,EAAO,WACJ,CACH,MAAMC,EAAQrB,EAAUjB,EAAa,sBAAsB,EAI3D,OAFAuC,EAAO,KAAK,gBAAiB,CAAC,CAACD,CAAK,EAE/BA,GAELE,EAAsBJ,EAAU,GAAGC,CAAI,IAAIC,CAAK,EAAE,EAE3CN,EAAaE,CAAuB,EAAE,KAAMO,GAAQ,OAKzD,MAJyB,GAACpC,EAAAoC,EAAI,SAAJ,MAAApC,EAAY,KACnCyB,GAAA,OAAU,QAAAzB,EAAAyB,EAAM,aAAN,YAAAzB,EAAkB,YAAa,4BAGf,IAE7BmB,EAAaxB,EAAa,sBAAsB,EAChD0C,EAAyBN,CAAQ,EACjCG,EAAO,KAAK,gBAAiB,EAAK,EAC3B,GACT,CAAC,GAfkB,EAgBrB"}
1
+ {"version":3,"file":"verifyToken.js","sources":["/@dropins/storefront-auth/src/configs/cookieConfigs.ts","/@dropins/storefront-auth/src/lib/cookieUtils.ts","/@dropins/storefront-auth/src/data/transforms/transform-store-config.ts","/@dropins/storefront-auth/src/lib/fetch-error.ts","/@dropins/storefront-auth/src/api/getStoreConfig/graphql/getStoreConfig.graphql.ts","/@dropins/storefront-auth/src/api/getStoreConfig/getStoreConfig.ts","/@dropins/storefront-auth/src/api/verifyToken/graphql/verifyToken.graphql.ts","/@dropins/storefront-auth/src/api/verifyToken/verifyToken.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nconst COOKIE_NAMES = {\n auth_dropin_user_token: 'auth_dropin_user_token',\n auth_dropin_firstname: 'auth_dropin_firstname',\n};\n\nconst COOKIE_LIFETIME = 3600;\n\nexport { COOKIE_NAMES, COOKIE_LIFETIME };\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\n/* eslint-disable no-useless-escape */\nimport { getStoreConfig } from '@/auth/api';\nimport { COOKIE_LIFETIME } from '@/auth/configs/cookieConfigs';\n\nexport const getCookie = (cookieName: string) => {\n const cookies = document.cookie.split(';');\n let foundValue;\n\n cookies.forEach((cookie) => {\n const [name, value] = cookie.trim().split('=');\n if (name === cookieName) {\n foundValue = decodeURIComponent(value);\n }\n });\n\n return foundValue;\n};\n\nexport const deleteCookie = (cookieName: string) => {\n document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;\n};\n\nexport const getCookiesLifetime = async () => {\n try {\n const storeConfigString = sessionStorage.getItem('storeConfig');\n const cachedStoreConfig = storeConfigString\n ? JSON.parse(storeConfigString)\n : {};\n\n let accessTokenLifeTime = cachedStoreConfig.customerAccessTokenLifetime;\n\n if (!accessTokenLifeTime) {\n const storeConfig = await getStoreConfig();\n\n sessionStorage.setItem('storeConfig', JSON.stringify(storeConfig));\n\n accessTokenLifeTime =\n storeConfig?.customerAccessTokenLifetime || COOKIE_LIFETIME;\n }\n\n return `Max-Age=${accessTokenLifeTime}`;\n } catch (error) {\n console.error('getCookiesLifetime() Error:', error);\n return `Max-Age=${COOKIE_LIFETIME}`;\n }\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getStoreConfigResponse } from '@/auth/types';\nimport { COOKIE_LIFETIME } from '@/auth/configs/cookieConfigs';\nimport { StoreConfigModel } from '../models';\n\nexport const transformStoreConfig = (\n response: getStoreConfigResponse\n): StoreConfigModel => {\n return {\n autocompleteOnStorefront:\n response?.data?.storeConfig?.autocomplete_on_storefront || false,\n // Need information about min length in response undefined\n minLength: response?.data?.storeConfig?.minimum_password_length || 3,\n requiredCharacterClasses:\n +response?.data?.storeConfig?.required_character_classes_number || 0,\n createAccountConfirmation:\n response?.data?.storeConfig?.create_account_confirmation || false,\n customerAccessTokenLifetime:\n response?.data?.storeConfig?.customer_access_token_lifetime *\n COOKIE_LIFETIME || COOKIE_LIFETIME,\n };\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\n/** Actions */\nexport const handleFetchError = (errors: Array<{ message: string }>) => {\n const errorMessage = errors.map((e: any) => e.message).join(' ');\n\n throw Error(errorMessage);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nexport const GET_STORE_CONFIG = /* GraphQL */ `\n query GET_STORE_CONFIG {\n storeConfig {\n autocomplete_on_storefront\n minimum_password_length\n required_character_classes_number\n store_code\n store_name\n store_group_code\n locale\n create_account_confirmation\n customer_access_token_lifetime\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { getStoreConfigResponse } from '@/auth/types';\nimport { fetchGraphQl } from '../fetch-graphql';\nimport { GET_STORE_CONFIG } from './graphql/getStoreConfig.graphql';\nimport { handleNetworkError } from '@/auth/lib/network-error';\nimport { transformStoreConfig } from '@/auth/data/transforms';\nimport { StoreConfigModel } from '@/auth/data/models';\nimport { handleFetchError } from '@/auth/lib/fetch-error';\n\nexport const getStoreConfig = async (): Promise<StoreConfigModel> => {\n return await fetchGraphQl(GET_STORE_CONFIG, {\n method: 'GET',\n cache: 'force-cache',\n })\n .then((response: getStoreConfigResponse) => {\n if (response.errors?.length) return handleFetchError(response.errors);\n\n return transformStoreConfig(response);\n })\n .catch(handleNetworkError);\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nexport const VALIDATE_CUSTOMER_TOKEN = /* GraphQL */ `\n query VALIDATE_TOKEN {\n customerCart {\n id\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { events } from '@adobe-commerce/event-bus';\nimport {\n fetchGraphQl,\n removeFetchGraphQlHeader,\n setFetchGraphQlHeader,\n} from '../fetch-graphql';\nimport { deleteCookie, getCookie } from '@/auth/lib/cookieUtils';\nimport { COOKIE_NAMES } from '@/auth/configs/cookieConfigs';\nimport { VALIDATE_CUSTOMER_TOKEN } from './graphql/verifyToken.graphql';\n\nexport const verifyToken = async (\n authType = 'Authorization',\n type = 'Bearer'\n) => {\n const token = getCookie(COOKIE_NAMES.auth_dropin_user_token);\n\n events.emit('authenticated', !!token);\n\n if (!token) return false;\n\n setFetchGraphQlHeader(authType, `${type} ${token}`);\n\n return fetchGraphQl(VALIDATE_CUSTOMER_TOKEN).then((res) => {\n const unauthenticated = !!res.errors?.find(\n (error) => error.extensions?.category === 'graphql-authentication'\n );\n\n if (!unauthenticated) return true;\n\n deleteCookie(COOKIE_NAMES.auth_dropin_user_token);\n removeFetchGraphQlHeader(authType);\n events.emit('authenticated', false);\n return false;\n });\n};\n"],"names":["COOKIE_NAMES","COOKIE_LIFETIME","getCookie","cookieName","cookies","foundValue","cookie","name","value","deleteCookie","getCookiesLifetime","storeConfigString","accessTokenLifeTime","storeConfig","getStoreConfig","error","transformStoreConfig","response","_b","_a","_d","_c","_f","_e","_h","_g","_j","_i","handleFetchError","errors","errorMessage","GET_STORE_CONFIG","fetchGraphQl","handleNetworkError","VALIDATE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-1 +1 @@
1
- {"name": "@dropins/storefront-auth", "version": "2.2.0-alpha007", "@dropins/tools": "1.5.0-beta4", "license": "SEE LICENSE IN LICENSE.md"}
1
+ {"name": "@dropins/storefront-auth", "version": "2.2.0-alpha009", "@dropins/tools": "1.5.0-beta4", "license": "SEE LICENSE IN LICENSE.md"}