@dropins/storefront-company-switcher 1.0.6-beta4 → 1.0.6-beta6

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.
@@ -14,5 +14,5 @@
14
14
  * is strictly forbidden unless prior written permission is obtained
15
15
  * from Adobe.
16
16
  *******************************************************************/
17
- export declare const GET_CUSTOMER_COMPANY_CONTEXT = "\n query GET_CUSTOMER_COMPANIES {\n customer {\n companies {\n items {\n name\n id\n }\n }\n }\n company {\n name\n id\n }\n customerGroup {\n uid\n }\n }\n";
17
+ export declare const GET_CUSTOMER_COMPANY_CONTEXT = "\n query GET_CUSTOMER_COMPANIES {\n customer {\n companies {\n items {\n name\n id\n status\n }\n }\n }\n company {\n name\n id\n status\n }\n customerGroup {\n uid\n }\n }\n";
18
18
  //# sourceMappingURL=customerCompanyContext.graphql.d.ts.map
package/api.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Copyright 2025 Adobe
1
+ /*! Copyright 2026 Adobe
2
2
  All Rights Reserved. */
3
3
  import{C as o,c as p,f as n,e as i,g as m,d as g,h,i as C,r as d,s as u,a as c,b as f,u as G}from"./chunks/customerCompanyContext.js";import"@dropins/tools/lib.js";import"@dropins/tools/event-bus.js";import"@dropins/tools/fetch-graphql.js";export{o as CustomerCompanyContext,p as config,n as fetchGraphQl,i as getCompanyHeaderManager,m as getConfig,g as getCustomerCompanyInfo,h as getGroupHeaderManager,C as initialize,d as removeFetchGraphQlHeader,u as setEndpoint,c as setFetchGraphQlHeader,f as setFetchGraphQlHeaders,G as updateCustomerGroup};
4
4
  //# sourceMappingURL=api.js.map
@@ -1,28 +1,30 @@
1
- /*! Copyright 2025 Adobe
1
+ /*! Copyright 2026 Adobe
2
2
  All Rights Reserved. */
3
- var G=Object.defineProperty;var S=(a,e,r)=>e in a?G(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var o=(a,e,r)=>S(a,typeof e!="symbol"?e+"":e,r);import{Initializer as M}from"@dropins/tools/lib.js";import{events as u}from"@dropins/tools/event-bus.js";import{FetchGraphQL as I}from"@dropins/tools/fetch-graphql.js";class T{constructor(){o(this,"companyHeaderSet",!1);o(this,"companyHeaderAppliers",[]);o(this,"companyHeaderRemovers",[]);o(this,"headerKey");this.headerKey=h.getConfig().companyHeader,this.setFetchGraphQlModules(h.getConfig().fetchGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){this.companyHeaderAppliers=[],this.companyHeaderRemovers=[],e.forEach(r=>{this.companyHeaderAppliers.push((t,s)=>r.setFetchGraphQlHeader(t,s)),this.companyHeaderRemovers.push(t=>r.removeFetchGraphQlHeader(t))})}setCompanyHeaders(e){if(e===null){this.removeCompanyHeaders();return}this.companyHeaderAppliers.forEach(r=>{r(this.headerKey,e)}),this.companyHeaderSet=!0}removeCompanyHeaders(){this.companyHeaderRemovers.forEach(e=>{e(this.headerKey)}),this.companyHeaderSet=!1}isCompanyHeaderSet(){return this.companyHeaderSet}}let l=null;const c=()=>(l||(l=new T),l);class E{constructor(){o(this,"groupHeaderSet",!1);o(this,"groupHeaderAppliers",[]);o(this,"groupHeaderRemovers",[]);o(this,"headerKey");o(this,"defaultNLICustomerGroupId","b6589fc6ab0dc82cf12099d1c2d40ab994e8410c");this.headerKey=h.getConfig().customerGroupHeader,this.setFetchGraphQlModules(h.getConfig().groupGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){e.forEach(r=>{this.groupHeaderAppliers.push((t,s)=>r.setFetchGraphQlHeader(t,s)),this.groupHeaderRemovers.push(t=>r.setFetchGraphQlHeader(t,this.defaultNLICustomerGroupId))})}setGroupHeaders(e){this.removeGroupHeaders(),e!==null&&(this.groupHeaderAppliers.forEach(r=>{r(this.headerKey,e)}),this.groupHeaderSet=!0)}removeGroupHeaders(){this.groupHeaderRemovers.forEach(e=>{e(this.headerKey)}),this.groupHeaderSet=!1}isGroupHeaderSet(){return this.groupHeaderSet}}let C=null;const d=()=>(C||(C=new E),C),p=new M({init:async a=>{const e={fetchGraphQlModules:[],groupGraphQlModules:[],companyHeader:"X-Adobe-Company",customerGroupHeader:"Magento-Customer-Group",companySessionStorageKey:"DROPIN__COMPANYSWITCHER__COMPANY__CONTEXT",groupSessionStorageKey:"DROPIN__COMPANYSWITCHER__GROUP__CONTEXT"};p.config.setConfig({...e,...a});const r=sessionStorage.getItem(p.config.getConfig().groupSessionStorageKey),t=sessionStorage.getItem(p.config.getConfig().companySessionStorageKey);t&&!c().isCompanyHeaderSet()&&(c().setCompanyHeaders(t),u.emit("companyContext/changed",t)),r&&!d().isGroupHeaderSet()&&d().setGroupHeaders(r),u.on("authenticated",async s=>{const i=p.config.getConfig();if(!s)sessionStorage.removeItem(i.companySessionStorageKey),sessionStorage.removeItem(i.groupSessionStorageKey),c().removeCompanyHeaders(),d().removeGroupHeaders(),u.emit("companyContext/changed",null);else{if(sessionStorage.getItem(i.companySessionStorageKey)||c().isCompanyHeaderSet())return;const g=await R();if(g.customerCompanies.length<2)return;const y=g.currentCompany.id,f=g.customerGroupId;c().setCompanyHeaders(y),d().setGroupHeaders(f),sessionStorage.setItem(i.companySessionStorageKey,y),sessionStorage.setItem(i.groupSessionStorageKey,f),u.emit("companyContext/changed",y)}},{eager:!0})},listeners:()=>[]}),h=p.config,{setEndpoint:U,setFetchGraphQlHeader:w,removeFetchGraphQlHeader:F,setFetchGraphQlHeaders:Y,fetchGraphQl:H,getConfig:O}=new I().getMethods(),_=`
3
+ var S=Object.defineProperty;var M=(o,e,r)=>e in o?S(o,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[e]=r;var s=(o,e,r)=>M(o,typeof e!="symbol"?e+"":e,r);import{Initializer as E}from"@dropins/tools/lib.js";import{events as u}from"@dropins/tools/event-bus.js";import{FetchGraphQL as I}from"@dropins/tools/fetch-graphql.js";class T{constructor(){s(this,"companyHeaderSet",!1);s(this,"companyHeaderAppliers",[]);s(this,"companyHeaderRemovers",[]);s(this,"headerKey");this.headerKey=h.getConfig().companyHeader,this.setFetchGraphQlModules(h.getConfig().fetchGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){this.companyHeaderAppliers=[],this.companyHeaderRemovers=[],e.forEach(r=>{this.companyHeaderAppliers.push((t,a)=>r.setFetchGraphQlHeader(t,a)),this.companyHeaderRemovers.push(t=>r.removeFetchGraphQlHeader(t))})}setCompanyHeaders(e){if(e===null){this.removeCompanyHeaders();return}this.companyHeaderAppliers.forEach(r=>{r(this.headerKey,e)}),this.companyHeaderSet=!0}removeCompanyHeaders(){this.companyHeaderRemovers.forEach(e=>{e(this.headerKey)}),this.companyHeaderSet=!1}isCompanyHeaderSet(){return this.companyHeaderSet}}let C=null;const c=()=>(C||(C=new T),C);class O{constructor(){s(this,"groupHeaderSet",!1);s(this,"groupHeaderAppliers",[]);s(this,"groupHeaderRemovers",[]);s(this,"headerKey");s(this,"defaultNLICustomerGroupId","b6589fc6ab0dc82cf12099d1c2d40ab994e8410c");this.headerKey=h.getConfig().customerGroupHeader,this.setFetchGraphQlModules(h.getConfig().groupGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){e.forEach(r=>{this.groupHeaderAppliers.push((t,a)=>r.setFetchGraphQlHeader(t,a)),this.groupHeaderRemovers.push(t=>r.setFetchGraphQlHeader(t,this.defaultNLICustomerGroupId))})}setGroupHeaders(e){this.removeGroupHeaders(),e!==null&&(this.groupHeaderAppliers.forEach(r=>{r(this.headerKey,e)}),this.groupHeaderSet=!0)}removeGroupHeaders(){this.groupHeaderRemovers.forEach(e=>{e(this.headerKey)}),this.groupHeaderSet=!1}isGroupHeaderSet(){return this.groupHeaderSet}}let f=null;const d=()=>(f||(f=new O),f),p=new E({init:async o=>{const e={fetchGraphQlModules:[],groupGraphQlModules:[],companyHeader:"X-Adobe-Company",customerGroupHeader:"Magento-Customer-Group",companySessionStorageKey:"DROPIN__COMPANYSWITCHER__COMPANY__CONTEXT",groupSessionStorageKey:"DROPIN__COMPANYSWITCHER__GROUP__CONTEXT"};p.config.setConfig({...e,...o});const r=sessionStorage.getItem(p.config.getConfig().groupSessionStorageKey),t=sessionStorage.getItem(p.config.getConfig().companySessionStorageKey);t&&!c().isCompanyHeaderSet()&&(c().setCompanyHeaders(t),u.emit("companyContext/changed",t)),r&&!d().isGroupHeaderSet()&&d().setGroupHeaders(r),u.on("authenticated",async a=>{const n=p.config.getConfig();if(!a)sessionStorage.removeItem(n.companySessionStorageKey),sessionStorage.removeItem(n.groupSessionStorageKey),c().removeCompanyHeaders(),d().removeGroupHeaders(),u.emit("companyContext/changed",null);else{if(sessionStorage.getItem(n.companySessionStorageKey)||c().isCompanyHeaderSet())return;const y=await K();if(y.customerCompanies.length<2)return;const l=y.currentCompany.id,H=y.customerGroupId;c().setCompanyHeaders(l),d().setGroupHeaders(H),sessionStorage.setItem(n.companySessionStorageKey,l),sessionStorage.setItem(n.groupSessionStorageKey,H),u.emit("companyContext/changed",l)}},{eager:!0})},listeners:()=>[]}),h=p.config,{setEndpoint:U,setFetchGraphQlHeader:w,removeFetchGraphQlHeader:F,setFetchGraphQlHeaders:Y,fetchGraphQl:G,getConfig:_}=new I().getMethods(),A=`
4
4
  query GET_CUSTOMER_COMPANIES {
5
5
  customer {
6
6
  companies {
7
7
  items {
8
8
  name
9
9
  id
10
+ status
10
11
  }
11
12
  }
12
13
  }
13
14
  company {
14
15
  name
15
16
  id
17
+ status
16
18
  }
17
19
  customerGroup {
18
20
  uid
19
21
  }
20
22
  }
21
- `,A=`
23
+ `,R=`
22
24
  query GET_CUSTOMER_GROUP {
23
25
  customerGroup {
24
26
  uid
25
27
  }
26
28
  }
27
- `,n=class n{constructor(){o(this,"EMPTY_CUSTOMER_COMPANY_CONTEXT",{currentCompany:{id:"",name:""},customerCompanies:[],customerGroupId:""});o(this,"cache",null);o(this,"transformCompanyToOption",e=>({text:e.name,value:e.id}))}static getInstance(){return n.instance??(n.instance=new n)}async processCustomerGroupId(e){const r=Uint8Array.from(atob(e),s=>s.charCodeAt(0)),t=await crypto.subtle.digest("SHA-1",r);return Array.from(new Uint8Array(t)).map(s=>s.toString(16).padStart(2,"0")).join("")}isUserAuthenticated(){var e;return!!((e=O().fetchGraphQlHeaders)!=null&&e.Authorization)}resetCache(){this.cache=null}async updateCustomerGroup(){if(!this.isUserAuthenticated())return null;try{const e=await H(A);if(e.errors)return null;const r=await this.processCustomerGroupId(e.data.customerGroup.uid);return this.cache&&(this.cache.customerGroupId=r),r}catch(e){return console.error(e),null}}async getCustomerCompanyInfo(){if(this.cache)return this.cache;if(!this.isUserAuthenticated())return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;try{const e=await H(_);if(e.errors)return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;const r=e.data,t=await this.processCustomerGroupId(e.data.customerGroup.uid),s=r.customer.companies.items.map(this.transformCompanyToOption);return this.cache={currentCompany:r.company,customerCompanies:s,customerGroupId:t},this.cache}catch(e){return console.error(e),this.EMPTY_CUSTOMER_COMPANY_CONTEXT}}};o(n,"instance");let m=n;const R=()=>m.getInstance().getCustomerCompanyInfo(),X=()=>m.getInstance().updateCustomerGroup();export{m as C,w as a,Y as b,h as c,R as d,c as e,H as f,O as g,d as h,p as i,F as r,U as s,X as u};
29
+ `,i=class i{constructor(){s(this,"EMPTY_CUSTOMER_COMPANY_CONTEXT",{currentCompany:{id:"",name:""},customerCompanies:[],customerGroupId:""});s(this,"cache",null);s(this,"transformCompanyToOption",e=>({text:e.name,value:e.id}))}static getInstance(){return i.instance??(i.instance=new i)}async processCustomerGroupId(e){const r=Uint8Array.from(atob(e),a=>a.charCodeAt(0)),t=await crypto.subtle.digest("SHA-1",r);return Array.from(new Uint8Array(t)).map(a=>a.toString(16).padStart(2,"0")).join("")}isUserAuthenticated(){var e;return!!((e=_().fetchGraphQlHeaders)!=null&&e.Authorization)}resetCache(){this.cache=null}async updateCustomerGroup(){if(!this.isUserAuthenticated())return null;try{const e=await G(R);if(e.errors)return null;const r=await this.processCustomerGroupId(e.data.customerGroup.uid);return this.cache&&(this.cache.customerGroupId=r),r}catch(e){return console.error(e),null}}async getCustomerCompanyInfo(){if(this.cache)return this.cache;if(!this.isUserAuthenticated())return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;try{const e=await G(A);if(e.errors)return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;const r=e.data,t=await this.processCustomerGroupId(e.data.customerGroup.uid),n=r.customer.companies.items.filter(g=>g.status==="APPROVED"||g.status==="BLOCKED").map(this.transformCompanyToOption);return this.cache={currentCompany:r.company,customerCompanies:n,customerGroupId:t},this.cache}catch(e){return console.error(e),this.EMPTY_CUSTOMER_COMPANY_CONTEXT}}};s(i,"instance");let m=i;const K=()=>m.getInstance().getCustomerCompanyInfo(),X=()=>m.getInstance().updateCustomerGroup();export{m as C,w as a,Y as b,h as c,K as d,c as e,G as f,_ as g,d as h,p as i,F as r,U as s,X as u};
28
30
  //# sourceMappingURL=customerCompanyContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"customerCompanyContext.js","sources":["/@dropins/storefront-company-switcher/src/api/setCompanyHeaders/setCompanyHeaders.ts","/@dropins/storefront-company-switcher/src/api/setGroupHeaders/setGroupHeaders.ts","/@dropins/storefront-company-switcher/src/api/initialize/initialize.ts","/@dropins/storefront-company-switcher/src/api/fetch-graphql/fetch-graphql.ts","/@dropins/storefront-company-switcher/src/api/customerCompanyContext/graphql/customerCompanyContext.graphql.ts","/@dropins/storefront-company-switcher/src/api/customerCompanyContext/graphql/customerGroupContext.graphql.ts","/@dropins/storefront-company-switcher/src/api/customerCompanyContext/customerCompanyContext.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader, removeFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages company-specific headers for GraphQL requests.\n * Singleton class that handles setting and removing company headers across multiple GraphQL modules.\n */\nclass CompanyHeaderManager {\n private companyHeaderSet: boolean = false;\n private companyHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private companyHeaderRemovers: typeof removeFetchGraphQlHeader[] = [];\n private headerKey: string;\n\n constructor() {\n this.headerKey = config.getConfig().companyHeader;\n this.setFetchGraphQlModules(config.getConfig().fetchGraphQlModules);\n }\n\n /**\n * Sets the header key used for company identification\n * @param headerKey - The header name to use for company ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have company headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n this.companyHeaderAppliers = [];\n this.companyHeaderRemovers = [];\n modules.forEach((module: FetchGraphQL) => {\n this.companyHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.companyHeaderRemovers.push((key: string) => \n module.removeFetchGraphQlHeader(key)\n );\n });\n }\n\n /**\n * Sets company headers for all configured GraphQL modules\n * @param companyId - The company ID to set in headers, or null to remove headers\n */\n public setCompanyHeaders(companyId: string | null): void {\n if (companyId === null) {\n this.removeCompanyHeaders();\n return;\n }\n this.companyHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, companyId);\n });\n this.companyHeaderSet = true;\n }\n\n /**\n * Removes company headers from all configured GraphQL modules\n */\n public removeCompanyHeaders(): void {\n this.companyHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.companyHeaderSet = false;\n }\n\n /**\n * Checks if company headers are currently set\n * @returns true if company headers are set, false otherwise\n */\n public isCompanyHeaderSet(): boolean {\n return this.companyHeaderSet;\n }\n}\n\nlet _companyHeaderManager: CompanyHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of CompanyHeaderManager\n * @returns The CompanyHeaderManager instance\n */\nexport const getCompanyHeaderManager = () => {\n if (!_companyHeaderManager) {\n _companyHeaderManager = new CompanyHeaderManager();\n }\n return _companyHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages customer group headers for GraphQL requests.\n * Singleton class that handles setting and removing group headers across multiple GraphQL modules.\n */\nclass GroupHeaderManager {\n private groupHeaderSet: boolean = false;\n private groupHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private groupHeaderRemovers: ((key: string) => void)[] = [];\n private headerKey: string;\n private defaultNLICustomerGroupId = 'b6589fc6ab0dc82cf12099d1c2d40ab994e8410c';\n\n\n constructor() {\n this.headerKey = config.getConfig().customerGroupHeader;\n this.setFetchGraphQlModules(config.getConfig().groupGraphQlModules);\n }\n\n /**\n * Sets the header key used for customer group identification\n * @param headerKey - The header name to use for group ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have group headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n modules.forEach((module: FetchGraphQL) => {\n this.groupHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.groupHeaderRemovers.push((key: string) => \n module.setFetchGraphQlHeader(key, this.defaultNLICustomerGroupId)\n );\n });\n }\n\n /**\n * Sets customer group headers for all configured GraphQL modules.\n * Always removes existing headers first before setting new ones.\n * @param groupId - The group ID to set in headers, or null to only remove headers\n */\n public setGroupHeaders(groupId: string | null): void {\n this.removeGroupHeaders();\n if (groupId === null) {\n return;\n }\n this.groupHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, groupId);\n });\n this.groupHeaderSet = true;\n }\n\n /**\n * Removes customer group headers from all configured GraphQL modules\n */\n public removeGroupHeaders(): void {\n this.groupHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.groupHeaderSet = false;\n }\n\n /**\n * Checks if customer group headers are currently set\n * @returns true if group headers are set, false otherwise\n */\n public isGroupHeaderSet(): boolean {\n return this.groupHeaderSet;\n }\n}\n\nlet _groupHeaderManager: GroupHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of GroupHeaderManager\n * @returns The GroupHeaderManager instance\n */\nexport const getGroupHeaderManager = () => {\n if (!_groupHeaderManager) {\n _groupHeaderManager = new GroupHeaderManager();\n }\n return _groupHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 type { FetchGraphQL } from '@adobe-commerce/fetch-graphql';\nimport { Initializer } from '@adobe-commerce/elsie/lib';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { getCompanyHeaderManager } from '@/company-switcher/api/setCompanyHeaders/setCompanyHeaders';\nimport { getGroupHeaderManager } from '@/company-switcher/api/setGroupHeaders/setGroupHeaders';\nimport { getCustomerCompanyInfo } from '@/company-switcher/api/customerCompanyContext/customerCompanyContext';\nimport { events } from '@adobe-commerce/event-bus';\n\n/**\n * Configuration properties for the company switcher initialization\n */\ninterface ConfigProps {\n /** Optional language definitions for internationalization */\n langDefinitions?: Lang;\n /** HTTP header name for company identification */\n companyHeader: string;\n /** HTTP header name for customer group identification */\n customerGroupHeader: string;\n /** Session storage key for persisting company context */\n companySessionStorageKey: string;\n /** Session storage key for persisting group context */\n groupSessionStorageKey: string;\n /** GraphQL modules that will have company headers applied */\n fetchGraphQlModules: FetchGraphQL[];\n /** GraphQL modules that will have group headers applied */\n groupGraphQlModules: FetchGraphQL[];\n}\n\n/**\n * Initializer for the company switcher drop-in.\n * Configures headers, storage, and GraphQL modules for company management.\n */\nexport const initialize = new Initializer<ConfigProps>({\n init: async (config) => {\n const defaultConfig = {\n fetchGraphQlModules: [],\n groupGraphQlModules: [],\n companyHeader: 'X-Adobe-Company',\n customerGroupHeader: 'Magento-Customer-Group',\n companySessionStorageKey: 'DROPIN__COMPANYSWITCHER__COMPANY__CONTEXT',\n groupSessionStorageKey: 'DROPIN__COMPANYSWITCHER__GROUP__CONTEXT'\n };\n initialize.config.setConfig({ ...defaultConfig, ...config });\n\n const groupId = sessionStorage.getItem(initialize.config.getConfig().groupSessionStorageKey);\n const companyId = sessionStorage.getItem(initialize.config.getConfig().companySessionStorageKey);\n if (companyId && !getCompanyHeaderManager().isCompanyHeaderSet()) {\n getCompanyHeaderManager().setCompanyHeaders(companyId);\n events.emit('companyContext/changed', companyId);\n }\n if (groupId && !getGroupHeaderManager().isGroupHeaderSet()) {\n getGroupHeaderManager().setGroupHeaders(groupId);\n }\n\n events.on('authenticated', async (authenticated: boolean) => {\n const config = initialize.config.getConfig();\n if (!authenticated) {\n sessionStorage.removeItem(config.companySessionStorageKey);\n sessionStorage.removeItem(config.groupSessionStorageKey);\n getCompanyHeaderManager().removeCompanyHeaders();\n getGroupHeaderManager().removeGroupHeaders();\n events.emit('companyContext/changed', null);\n } else {\n const storedCompanyId = sessionStorage.getItem(config.companySessionStorageKey);\n if (storedCompanyId || getCompanyHeaderManager().isCompanyHeaderSet()) {\n return;\n }\n const companyInfo = await getCustomerCompanyInfo();\n if (companyInfo.customerCompanies.length < 2) {\n return;\n }\n\n const currentCompanyId = companyInfo.currentCompany.id;\n const groupId = companyInfo.customerGroupId;\n getCompanyHeaderManager().setCompanyHeaders(currentCompanyId);\n getGroupHeaderManager().setGroupHeaders(groupId);\n sessionStorage.setItem(config.companySessionStorageKey, currentCompanyId);\n sessionStorage.setItem(config.groupSessionStorageKey, groupId);\n events.emit('companyContext/changed', currentCompanyId);\n }\n }, { eager: true });\n },\n listeners: () => []\n});\n\n/**\n * Configuration object for getting and setting company switcher configuration.\n * Provides methods to access and update the current configuration.\n */\nexport const config = initialize.config;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 { FetchGraphQL } from '@adobe-commerce/fetch-graphql';\n\n/**\n * GraphQL client methods for making API requests.\n * Provides methods to configure endpoints, headers, and execute GraphQL queries.\n */\nexport const {\n /** Sets the GraphQL endpoint URL */\n setEndpoint,\n /** Sets a single GraphQL header */\n setFetchGraphQlHeader,\n /** Removes a GraphQL header */\n removeFetchGraphQlHeader,\n /** Sets multiple GraphQL headers at once */\n setFetchGraphQlHeaders,\n /** Executes a GraphQL query or mutation */\n fetchGraphQl,\n /** Gets the current configuration */\n getConfig,\n} = new FetchGraphQL().getMethods();\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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_CUSTOMER_COMPANY_CONTEXT = `\n query GET_CUSTOMER_COMPANIES {\n customer {\n companies {\n items {\n name\n id\n }\n }\n }\n company {\n name\n id\n }\n customerGroup {\n uid\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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_CUSTOMER_GROUP_CONTEXT = `\n query GET_CUSTOMER_GROUP {\n customerGroup {\n uid\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 { fetchGraphQl, getConfig } from \"@/company-switcher/api\";\nimport type { Company, CompanyOption, CustomerCompanyInfo, GraphQLResponse } from '@/company-switcher/types/company';\nimport { GET_CUSTOMER_COMPANY_CONTEXT } from './graphql/customerCompanyContext.graphql';\nimport { GET_CUSTOMER_GROUP_CONTEXT } from './graphql/customerGroupContext.graphql';\n\nexport class CustomerCompanyContext {\n private static instance: CustomerCompanyContext;\n\n // Constants\n private readonly EMPTY_CUSTOMER_COMPANY_CONTEXT: CustomerCompanyInfo = {\n currentCompany: { id: '', name: '' },\n customerCompanies: [],\n customerGroupId: '',\n };\n\n private cache: CustomerCompanyInfo | null = null;\n\n /**\n * Get singleton instance\n */\n static getInstance(): CustomerCompanyContext {\n return CustomerCompanyContext.instance ??= new CustomerCompanyContext();\n }\n\n /**\n * Transforms a company object into a company option for UI components\n */\n private transformCompanyToOption = (company: Company): CompanyOption => ({\n text: company.name,\n value: company.id\n });\n\n /**\n * Decodes base64 string and returns SHA1 hash\n */\n private async processCustomerGroupId(base64String: string): Promise<string> {\n const decoded = Uint8Array.from(atob(base64String), c => c.charCodeAt(0));\n const hashBuffer = await crypto.subtle.digest('SHA-1', decoded);\n return Array.from(new Uint8Array(hashBuffer)).map(b => b.toString(16).padStart(2, '0')).join('');\n }\n\n /**\n * Checks if the user is authenticated by verifying the Authorization header\n */\n private isUserAuthenticated(): boolean {\n return Boolean(getConfig().fetchGraphQlHeaders?.Authorization);\n }\n\n resetCache(): void {\n this.cache = null;\n }\n\n /**\n * Fetches and updates only the customer group information in the cache\n * \n * @returns Promise containing the updated customer group ID\n * @throws Will not throw errors - returns null on failure\n */\n async updateCustomerGroup(): Promise<string | null> {\n if (!this.isUserAuthenticated()) {\n return null;\n }\n\n try {\n const response = await fetchGraphQl<{ customerGroup: { uid: string } }>(GET_CUSTOMER_GROUP_CONTEXT);\n if (response.errors) {\n return null;\n }\n const customerGroupId = await this.processCustomerGroupId(response.data.customerGroup.uid);\n if (this.cache) {\n this.cache.customerGroupId = customerGroupId;\n }\n return customerGroupId;\n } catch (e) {\n console.error(e)\n return null;\n }\n }\n\n /**\n * Fetches customer company information including the current company and all available companies\n * \n * @returns Promise containing current company and list of available companies\n * @throws Will not throw errors - returns empty data on failure\n */\n async getCustomerCompanyInfo(): Promise<CustomerCompanyInfo> {\n // Return cached data if available\n if (this.cache) {\n return this.cache;\n }\n \n // Return empty data if user is not authenticated\n if (!this.isUserAuthenticated()) {\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n\n try {\n // Fetch company data from GraphQL API\n const response = (await fetchGraphQl<GraphQLResponse>(GET_CUSTOMER_COMPANY_CONTEXT));\n if (response.errors) {\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n\n const data = response.data;\n const customerGroup = await this.processCustomerGroupId(response.data.customerGroup.uid);\n const customerCompanies = data.customer.companies.items.map(this.transformCompanyToOption);\n\n this.cache = {\n currentCompany: data.company,\n customerCompanies,\n customerGroupId: customerGroup\n }\n return this.cache;\n } catch (e) {\n console.error(e);\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n }\n}\n\nexport const getCustomerCompanyInfo = (): Promise<CustomerCompanyInfo> => {\n return CustomerCompanyContext.getInstance().getCustomerCompanyInfo();\n};\n\nexport const updateCustomerGroup = (): Promise<string | null> => {\n return CustomerCompanyContext.getInstance().updateCustomerGroup();\n};"],"names":["CompanyHeaderManager","__publicField","config","headerKey","modules","module","key","value","companyId","setFn","removeFn","_companyHeaderManager","getCompanyHeaderManager","GroupHeaderManager","groupId","_groupHeaderManager","getGroupHeaderManager","initialize","Initializer","defaultConfig","events","authenticated","companyInfo","getCustomerCompanyInfo","currentCompanyId","setEndpoint","setFetchGraphQlHeader","removeFetchGraphQlHeader","setFetchGraphQlHeaders","fetchGraphQl","getConfig","FetchGraphQL","GET_CUSTOMER_COMPANY_CONTEXT","GET_CUSTOMER_GROUP_CONTEXT","_CustomerCompanyContext","company","base64String","decoded","c","hashBuffer","b","_a","response","customerGroupId","data","customerGroup","customerCompanies","CustomerCompanyContext","updateCustomerGroup"],"mappings":"4UAuBA,MAAMA,CAAqB,CAMzB,aAAc,CALNC,EAAA,wBAA4B,IAC5BA,EAAA,6BAAwD,CAAA,GACxDA,EAAA,6BAA2D,CAAA,GAC3DA,EAAA,kBAGN,KAAK,UAAYC,EAAO,UAAA,EAAY,cACpC,KAAK,uBAA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A,EAGjCC,EAAsB,IAC1BD,EAAuB,YAAA,EAAc,oBAAA"}
1
+ {"version":3,"file":"customerCompanyContext.js","sources":["/@dropins/storefront-company-switcher/src/api/setCompanyHeaders/setCompanyHeaders.ts","/@dropins/storefront-company-switcher/src/api/setGroupHeaders/setGroupHeaders.ts","/@dropins/storefront-company-switcher/src/api/initialize/initialize.ts","/@dropins/storefront-company-switcher/src/api/fetch-graphql/fetch-graphql.ts","/@dropins/storefront-company-switcher/src/api/customerCompanyContext/graphql/customerCompanyContext.graphql.ts","/@dropins/storefront-company-switcher/src/api/customerCompanyContext/graphql/customerGroupContext.graphql.ts","/@dropins/storefront-company-switcher/src/api/customerCompanyContext/customerCompanyContext.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader, removeFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages company-specific headers for GraphQL requests.\n * Singleton class that handles setting and removing company headers across multiple GraphQL modules.\n */\nclass CompanyHeaderManager {\n private companyHeaderSet: boolean = false;\n private companyHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private companyHeaderRemovers: typeof removeFetchGraphQlHeader[] = [];\n private headerKey: string;\n\n constructor() {\n this.headerKey = config.getConfig().companyHeader;\n this.setFetchGraphQlModules(config.getConfig().fetchGraphQlModules);\n }\n\n /**\n * Sets the header key used for company identification\n * @param headerKey - The header name to use for company ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have company headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n this.companyHeaderAppliers = [];\n this.companyHeaderRemovers = [];\n modules.forEach((module: FetchGraphQL) => {\n this.companyHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.companyHeaderRemovers.push((key: string) => \n module.removeFetchGraphQlHeader(key)\n );\n });\n }\n\n /**\n * Sets company headers for all configured GraphQL modules\n * @param companyId - The company ID to set in headers, or null to remove headers\n */\n public setCompanyHeaders(companyId: string | null): void {\n if (companyId === null) {\n this.removeCompanyHeaders();\n return;\n }\n this.companyHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, companyId);\n });\n this.companyHeaderSet = true;\n }\n\n /**\n * Removes company headers from all configured GraphQL modules\n */\n public removeCompanyHeaders(): void {\n this.companyHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.companyHeaderSet = false;\n }\n\n /**\n * Checks if company headers are currently set\n * @returns true if company headers are set, false otherwise\n */\n public isCompanyHeaderSet(): boolean {\n return this.companyHeaderSet;\n }\n}\n\nlet _companyHeaderManager: CompanyHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of CompanyHeaderManager\n * @returns The CompanyHeaderManager instance\n */\nexport const getCompanyHeaderManager = () => {\n if (!_companyHeaderManager) {\n _companyHeaderManager = new CompanyHeaderManager();\n }\n return _companyHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages customer group headers for GraphQL requests.\n * Singleton class that handles setting and removing group headers across multiple GraphQL modules.\n */\nclass GroupHeaderManager {\n private groupHeaderSet: boolean = false;\n private groupHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private groupHeaderRemovers: ((key: string) => void)[] = [];\n private headerKey: string;\n private defaultNLICustomerGroupId = 'b6589fc6ab0dc82cf12099d1c2d40ab994e8410c';\n\n\n constructor() {\n this.headerKey = config.getConfig().customerGroupHeader;\n this.setFetchGraphQlModules(config.getConfig().groupGraphQlModules);\n }\n\n /**\n * Sets the header key used for customer group identification\n * @param headerKey - The header name to use for group ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have group headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n modules.forEach((module: FetchGraphQL) => {\n this.groupHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.groupHeaderRemovers.push((key: string) => \n module.setFetchGraphQlHeader(key, this.defaultNLICustomerGroupId)\n );\n });\n }\n\n /**\n * Sets customer group headers for all configured GraphQL modules.\n * Always removes existing headers first before setting new ones.\n * @param groupId - The group ID to set in headers, or null to only remove headers\n */\n public setGroupHeaders(groupId: string | null): void {\n this.removeGroupHeaders();\n if (groupId === null) {\n return;\n }\n this.groupHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, groupId);\n });\n this.groupHeaderSet = true;\n }\n\n /**\n * Removes customer group headers from all configured GraphQL modules\n */\n public removeGroupHeaders(): void {\n this.groupHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.groupHeaderSet = false;\n }\n\n /**\n * Checks if customer group headers are currently set\n * @returns true if group headers are set, false otherwise\n */\n public isGroupHeaderSet(): boolean {\n return this.groupHeaderSet;\n }\n}\n\nlet _groupHeaderManager: GroupHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of GroupHeaderManager\n * @returns The GroupHeaderManager instance\n */\nexport const getGroupHeaderManager = () => {\n if (!_groupHeaderManager) {\n _groupHeaderManager = new GroupHeaderManager();\n }\n return _groupHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 type { FetchGraphQL } from '@adobe-commerce/fetch-graphql';\nimport { Initializer } from '@adobe-commerce/elsie/lib';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { getCompanyHeaderManager } from '@/company-switcher/api/setCompanyHeaders/setCompanyHeaders';\nimport { getGroupHeaderManager } from '@/company-switcher/api/setGroupHeaders/setGroupHeaders';\nimport { getCustomerCompanyInfo } from '@/company-switcher/api/customerCompanyContext/customerCompanyContext';\nimport { events } from '@adobe-commerce/event-bus';\n\n/**\n * Configuration properties for the company switcher initialization\n */\ninterface ConfigProps {\n /** Optional language definitions for internationalization */\n langDefinitions?: Lang;\n /** HTTP header name for company identification */\n companyHeader: string;\n /** HTTP header name for customer group identification */\n customerGroupHeader: string;\n /** Session storage key for persisting company context */\n companySessionStorageKey: string;\n /** Session storage key for persisting group context */\n groupSessionStorageKey: string;\n /** GraphQL modules that will have company headers applied */\n fetchGraphQlModules: FetchGraphQL[];\n /** GraphQL modules that will have group headers applied */\n groupGraphQlModules: FetchGraphQL[];\n}\n\n/**\n * Initializer for the company switcher drop-in.\n * Configures headers, storage, and GraphQL modules for company management.\n */\nexport const initialize = new Initializer<ConfigProps>({\n init: async (config) => {\n const defaultConfig = {\n fetchGraphQlModules: [],\n groupGraphQlModules: [],\n companyHeader: 'X-Adobe-Company',\n customerGroupHeader: 'Magento-Customer-Group',\n companySessionStorageKey: 'DROPIN__COMPANYSWITCHER__COMPANY__CONTEXT',\n groupSessionStorageKey: 'DROPIN__COMPANYSWITCHER__GROUP__CONTEXT'\n };\n initialize.config.setConfig({ ...defaultConfig, ...config });\n\n const groupId = sessionStorage.getItem(initialize.config.getConfig().groupSessionStorageKey);\n const companyId = sessionStorage.getItem(initialize.config.getConfig().companySessionStorageKey);\n if (companyId && !getCompanyHeaderManager().isCompanyHeaderSet()) {\n getCompanyHeaderManager().setCompanyHeaders(companyId);\n events.emit('companyContext/changed', companyId);\n }\n if (groupId && !getGroupHeaderManager().isGroupHeaderSet()) {\n getGroupHeaderManager().setGroupHeaders(groupId);\n }\n\n events.on('authenticated', async (authenticated: boolean) => {\n const config = initialize.config.getConfig();\n if (!authenticated) {\n sessionStorage.removeItem(config.companySessionStorageKey);\n sessionStorage.removeItem(config.groupSessionStorageKey);\n getCompanyHeaderManager().removeCompanyHeaders();\n getGroupHeaderManager().removeGroupHeaders();\n events.emit('companyContext/changed', null);\n } else {\n const storedCompanyId = sessionStorage.getItem(config.companySessionStorageKey);\n if (storedCompanyId || getCompanyHeaderManager().isCompanyHeaderSet()) {\n return;\n }\n const companyInfo = await getCustomerCompanyInfo();\n if (companyInfo.customerCompanies.length < 2) {\n return;\n }\n\n const currentCompanyId = companyInfo.currentCompany.id;\n const groupId = companyInfo.customerGroupId;\n getCompanyHeaderManager().setCompanyHeaders(currentCompanyId);\n getGroupHeaderManager().setGroupHeaders(groupId);\n sessionStorage.setItem(config.companySessionStorageKey, currentCompanyId);\n sessionStorage.setItem(config.groupSessionStorageKey, groupId);\n events.emit('companyContext/changed', currentCompanyId);\n }\n }, { eager: true });\n },\n listeners: () => []\n});\n\n/**\n * Configuration object for getting and setting company switcher configuration.\n * Provides methods to access and update the current configuration.\n */\nexport const config = initialize.config;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 { FetchGraphQL } from '@adobe-commerce/fetch-graphql';\n\n/**\n * GraphQL client methods for making API requests.\n * Provides methods to configure endpoints, headers, and execute GraphQL queries.\n */\nexport const {\n /** Sets the GraphQL endpoint URL */\n setEndpoint,\n /** Sets a single GraphQL header */\n setFetchGraphQlHeader,\n /** Removes a GraphQL header */\n removeFetchGraphQlHeader,\n /** Sets multiple GraphQL headers at once */\n setFetchGraphQlHeaders,\n /** Executes a GraphQL query or mutation */\n fetchGraphQl,\n /** Gets the current configuration */\n getConfig,\n} = new FetchGraphQL().getMethods();\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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_CUSTOMER_COMPANY_CONTEXT = `\n query GET_CUSTOMER_COMPANIES {\n customer {\n companies {\n items {\n name\n id\n status\n }\n }\n }\n company {\n name\n id\n status\n }\n customerGroup {\n uid\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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_CUSTOMER_GROUP_CONTEXT = `\n query GET_CUSTOMER_GROUP {\n customerGroup {\n uid\n }\n }\n`;\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 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 { fetchGraphQl, getConfig } from \"@/company-switcher/api\";\nimport type { Company, CompanyOption, CustomerCompanyInfo, GraphQLResponse } from '@/company-switcher/types/company';\nimport { GET_CUSTOMER_COMPANY_CONTEXT } from './graphql/customerCompanyContext.graphql';\nimport { GET_CUSTOMER_GROUP_CONTEXT } from './graphql/customerGroupContext.graphql';\n\nexport class CustomerCompanyContext {\n private static instance: CustomerCompanyContext;\n\n // Constants\n private readonly EMPTY_CUSTOMER_COMPANY_CONTEXT: CustomerCompanyInfo = {\n currentCompany: { id: '', name: '' },\n customerCompanies: [],\n customerGroupId: '',\n };\n\n private cache: CustomerCompanyInfo | null = null;\n\n /**\n * Get singleton instance\n */\n static getInstance(): CustomerCompanyContext {\n return CustomerCompanyContext.instance ??= new CustomerCompanyContext();\n }\n\n /**\n * Transforms a company object into a company option for UI components\n */\n private transformCompanyToOption = (company: Company): CompanyOption => ({\n text: company.name,\n value: company.id\n });\n\n /**\n * Decodes base64 string and returns SHA1 hash\n */\n private async processCustomerGroupId(base64String: string): Promise<string> {\n const decoded = Uint8Array.from(atob(base64String), c => c.charCodeAt(0));\n const hashBuffer = await crypto.subtle.digest('SHA-1', decoded);\n return Array.from(new Uint8Array(hashBuffer)).map(b => b.toString(16).padStart(2, '0')).join('');\n }\n\n /**\n * Checks if the user is authenticated by verifying the Authorization header\n */\n private isUserAuthenticated(): boolean {\n return Boolean(getConfig().fetchGraphQlHeaders?.Authorization);\n }\n\n resetCache(): void {\n this.cache = null;\n }\n\n /**\n * Fetches and updates only the customer group information in the cache\n * \n * @returns Promise containing the updated customer group ID\n * @throws Will not throw errors - returns null on failure\n */\n async updateCustomerGroup(): Promise<string | null> {\n if (!this.isUserAuthenticated()) {\n return null;\n }\n\n try {\n const response = await fetchGraphQl<{ customerGroup: { uid: string } }>(GET_CUSTOMER_GROUP_CONTEXT);\n if (response.errors) {\n return null;\n }\n const customerGroupId = await this.processCustomerGroupId(response.data.customerGroup.uid);\n if (this.cache) {\n this.cache.customerGroupId = customerGroupId;\n }\n return customerGroupId;\n } catch (e) {\n console.error(e)\n return null;\n }\n }\n\n /**\n * Fetches customer company information including the current company and all available companies\n * \n * @returns Promise containing current company and list of available companies\n * @throws Will not throw errors - returns empty data on failure\n */\n async getCustomerCompanyInfo(): Promise<CustomerCompanyInfo> {\n // Return cached data if available\n if (this.cache) {\n return this.cache;\n }\n \n // Return empty data if user is not authenticated\n if (!this.isUserAuthenticated()) {\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n\n try {\n // Fetch company data from GraphQL API\n const response = (await fetchGraphQl<GraphQLResponse>(GET_CUSTOMER_COMPANY_CONTEXT));\n if (response.errors) {\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n\n const data = response.data;\n const customerGroup = await this.processCustomerGroupId(response.data.customerGroup.uid);\n // Whitelist approach: only allow APPROVED and BLOCKED companies\n // BLOCKED companies allow users to log in and view but not perform actions\n const activeCompanies = data.customer.companies.items.filter(\n company => company.status === 'APPROVED' || company.status === 'BLOCKED'\n );\n const customerCompanies = activeCompanies.map(this.transformCompanyToOption);\n\n this.cache = {\n currentCompany: data.company,\n customerCompanies,\n customerGroupId: customerGroup\n }\n return this.cache;\n } catch (e) {\n console.error(e);\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n }\n}\n\nexport const getCustomerCompanyInfo = (): Promise<CustomerCompanyInfo> => {\n return CustomerCompanyContext.getInstance().getCustomerCompanyInfo();\n};\n\nexport const updateCustomerGroup = (): Promise<string | null> => {\n return CustomerCompanyContext.getInstance().updateCustomerGroup();\n};"],"names":["CompanyHeaderManager","__publicField","config","headerKey","modules","module","key","value","companyId","setFn","removeFn","_companyHeaderManager","getCompanyHeaderManager","GroupHeaderManager","groupId","_groupHeaderManager","getGroupHeaderManager","initialize","Initializer","defaultConfig","events","authenticated","companyInfo","getCustomerCompanyInfo","currentCompanyId","setEndpoint","setFetchGraphQlHeader","removeFetchGraphQlHeader","setFetchGraphQlHeaders","fetchGraphQl","getConfig","FetchGraphQL","GET_CUSTOMER_COMPANY_CONTEXT","GET_CUSTOMER_GROUP_CONTEXT","_CustomerCompanyContext","company","base64String","decoded","c","hashBuffer","b","_a","response","customerGroupId","data","customerGroup","customerCompanies","CustomerCompanyContext","updateCustomerGroup"],"mappings":"4UAuBA,MAAMA,CAAqB,CAMzB,aAAc,CALNC,EAAA,wBAA4B,IAC5BA,EAAA,6BAAwD,CAAA,GACxDA,EAAA,6BAA2D,CAAA,GAC3DA,EAAA,kBAGN,KAAK,UAAYC,EAAO,UAAA,EAAY,cACpC,KAAK,uBAAuBA,EAAO,UAAA,EAAY,mBAAmB,CACpE,CAMO,aAAaC,EAAyB,CAC3C,KAAK,UAAYA,CACnB,CAMO,uBAAuBC,EAA+B,CAC3D,KAAK,sBAAwB,CAAA,EAC7B,KAAK,sBAAwB,CAAA,EAC7BA,EAAQ,QAASC,GAAyB,CACxC,KAAK,sBAAsB,KAAK,CAACC,EAAaC,IAC5CF,EAAO,sBAAsBC,EAAKC,CAAK,CAAA,EAEzC,KAAK,sBAAsB,KAAMD,GAC/BD,EAAO,yBAAyBC,CAAG,CAAA,CAEvC,CAAC,CACH,CAMO,kBAAkBE,EAAgC,CACvD,GAAIA,IAAc,KAAM,CACtB,KAAK,q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,MAAMC,EAAW,MAAMb,EAAiDI,CAA0B,EAClG,GAAIS,EAAS,OACX,OAAO,KAET,MAAMC,EAAkB,MAAM,KAAK,uBAAuBD,EAAS,KAAK,cAAc,GAAG,EACzF,OAAI,KAAK,QACP,KAAK,MAAM,gBAAkBC,GAExBA,CACT,OAAS,EAAG,CACV,eAAQ,MAAM,CAAC,EACR,IACT,CACF,CAQA,MAAM,wBAAuD,CAE3D,GAAI,KAAK,MACP,OAAO,KAAK,MAId,GAAI,CAAC,KAAK,sBACR,OAAO,KAAK,+BAGd,GAAI,CAEF,MAAMD,EAAY,MAAMb,EAA8BG,CAA4B,EAClF,GAAIU,EAAS,OACX,OAAO,KAAK,+BAGd,MAAME,EAAOF,EAAS,KAChBG,EAAgB,MAAM,KAAK,uBAAuBH,EAAS,KAAK,cAAc,GAAG,EAMjFI,EAHkBF,EAAK,SAAS,UAAU,MAAM,OACpDT,GAAWA,EAAQ,SAAW,YAAcA,EAAQ,SAAW,SAAA,EAEvB,IAAI,KAAK,wBAAwB,EAE3E,YAAK,MAAQ,CACX,eAAgBS,EAAK,QACrB,kBAAAE,EACA,gBAAiBD,CAAA,EAEZ,KAAK,KACd,OAAS,EAAG,CACV,eAAQ,MAAM,CAAC,EACR,KAAK,8BACd,CACF,CACF,EArHE5C,EADWiC,EACI,YADV,IAAMa,EAANb,EAwHA,MAAMX,EAAyB,IAC7BwB,EAAuB,YAAA,EAAc,uBAAA,EAGjCC,EAAsB,IAC1BD,EAAuB,YAAA,EAAc,oBAAA"}
@@ -1,4 +1,4 @@
1
- /*! Copyright 2025 Adobe
1
+ /*! Copyright 2026 Adobe
2
2
  All Rights Reserved. */
3
3
  import{jsx as v}from"@dropins/tools/preact-jsx-runtime.js";import{useState as S,useCallback as f,useEffect as k,useMemo as H}from"@dropins/tools/preact-hooks.js";import{Picker as w}from"@dropins/tools/components.js";import{events as d}from"@dropins/tools/event-bus.js";import{C as I,e as K,c as x,u as G,h as M}from"../chunks/customerCompanyContext.js";import"@dropins/tools/lib.js";import"@dropins/tools/fetch-graphql.js";const D=({onCompanyChange:c}={})=>{const[l,s]=S([]),[g,r]=S({text:"",value:""}),C=f(async()=>{var e,n;try{const o=await I.getInstance().getCustomerCompanyInfo();s(o.customerCompanies),(e=o.currentCompany)!=null&&e.name&&((n=o.currentCompany)!=null&&n.id)&&r({text:o.currentCompany.name,value:o.currentCompany.id})}catch(t){console.error("Failed to load company data:",t)}},[]),h=f(async e=>{const t=e.target.value,o=l.find(p=>p.value===t);o&&r(o),K().setCompanyHeaders(t),t?sessionStorage.setItem(x.getConfig().companySessionStorageKey,t):sessionStorage.removeItem(x.getConfig().companySessionStorageKey);const a=await G();M().setGroupHeaders(a),a?sessionStorage.setItem(x.getConfig().groupSessionStorageKey,a):sessionStorage.removeItem(x.getConfig().groupSessionStorageKey),c==null||c({id:t,name:(o==null?void 0:o.text)||""}),d.emit("companyContext/changed",t)},[l,c]),m=f(()=>{I.getInstance().resetCache(),s([]),r({text:"",value:""})},[]),u=f(e=>{e?C():m()},[C,m]),y=f(e=>{if(!e){m();return}s(n=>{const t=n.find(o=>o.value===e);return t&&r(t),n})},[m,s,r]),i=f(e=>{const{company:n}=e;s(t=>{const o=t.findIndex(a=>a.value===n.id);return o===-1?t:t.map((a,p)=>p===o?{...a,text:n.name}:a)}),r({text:n.name,value:n.id})},[]);return k(()=>{const e=d.on("authenticated",u,{eager:!0}),n=d.on("companyContext/changed",y,{eager:!0}),t=d.on("company/updated",i);return()=>{var o,a,p;(o=e==null?void 0:e.off)==null||o.call(e),(a=n==null?void 0:n.off)==null||a.call(n),(p=t==null?void 0:t.off)==null||p.call(t)}},[u,y,i]),{companies:l,currentCompany:g,handleCompanyChange:h}},B=({ariaLabel:c,onCompanyChange:l,...s})=>{const{companies:g,currentCompany:r,handleCompanyChange:C}=D({onCompanyChange:l}),[h,m]=S(!0),u=H(()=>g,[g]);return k(()=>{const y=()=>{m(!1)},i=d.on("checkout/initialized",y),e=d.on("checkout/updated",y);return()=>{i==null||i.off(),e==null||e.off()}},[]),g.length<2||!h?null:v("div",{...s,children:v(w,{options:u,value:r.value,onChange:C,"aria-label":c||"Select company","aria-describedby":"company-switcher-description"})})};export{B as CompanySwitcher,B as default};
4
4
  //# sourceMappingURL=CompanySwitcher.js.map
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/storefront-company-switcher", "version": "1.0.6-beta4", "@dropins/tools": "^1.6.0-beta3", "license": "SEE LICENSE IN LICENSE.md"}
1
+ {"name": "@dropins/storefront-company-switcher", "version": "1.0.6-beta6", "@dropins/tools": "^1.6.0", "license": "SEE LICENSE IN LICENSE.md"}
package/render.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! Copyright 2025 Adobe
1
+ /*! Copyright 2026 Adobe
2
2
  All Rights Reserved. */
3
3
  import{jsx as e}from"@dropins/tools/preact-jsx-runtime.js";import{Render as f}from"@dropins/tools/lib.js";import{useState as i,useEffect as m}from"@dropins/tools/preact-hooks.js";import{UIProvider as c}from"@dropins/tools/components.js";import{events as a}from"@dropins/tools/event-bus.js";const p={"":{}},u={default:p},d=({children:o})=>{const[t,n]=i("en_US");return m(()=>{const r=a.on("locale",s=>{n(s)},{eager:!0});return()=>{r==null||r.off()}},[]),e(c,{lang:t,langDefinitions:u,children:o})},x=new f(e(d,{}));export{d as Provider,x as render};
4
4
  //# sourceMappingURL=render.js.map
@@ -14,12 +14,17 @@
14
14
  * is strictly forbidden unless prior written permission is obtained
15
15
  * from Adobe.
16
16
  *******************************************************************/
17
+ /**
18
+ * Company status enum values
19
+ */
20
+ export type CompanyStatusEnum = 'PENDING' | 'APPROVED' | 'REJECTED' | 'BLOCKED';
17
21
  /**
18
22
  * Represents a company entity
19
23
  */
20
24
  export interface Company {
21
25
  id: string;
22
26
  name: string;
27
+ status?: CompanyStatusEnum;
23
28
  }
24
29
  /**
25
30
  * Represents a company option for the picker component