@dropins/storefront-company-switcher 1.0.0-beta2 → 1.0.0-beta4

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.
@@ -0,0 +1,41 @@
1
+ import { CustomerCompanyInfo } from '../../types/company';
2
+
3
+ export declare class CustomerCompanyContext {
4
+ private static instance;
5
+ private readonly EMPTY_CUSTOMER_COMPANY_CONTEXT;
6
+ private cache;
7
+ /**
8
+ * Get singleton instance
9
+ */
10
+ static getInstance(): CustomerCompanyContext;
11
+ /**
12
+ * Transforms a company object into a company option for UI components
13
+ */
14
+ private transformCompanyToOption;
15
+ /**
16
+ * Decodes base64 string and returns SHA1 hash
17
+ */
18
+ private processCustomerGroupId;
19
+ /**
20
+ * Checks if the user is authenticated by verifying the Authorization header
21
+ */
22
+ private isUserAuthenticated;
23
+ resetCache(): void;
24
+ /**
25
+ * Fetches and updates only the customer group information in the cache
26
+ *
27
+ * @returns Promise containing the updated customer group ID
28
+ * @throws Will not throw errors - returns null on failure
29
+ */
30
+ updateCustomerGroup(): Promise<string | null>;
31
+ /**
32
+ * Fetches customer company information including the current company and all available companies
33
+ *
34
+ * @returns Promise containing current company and list of available companies
35
+ * @throws Will not throw errors - returns empty data on failure
36
+ */
37
+ getCustomerCompanyInfo(): Promise<CustomerCompanyInfo>;
38
+ }
39
+ export declare const getCustomerCompanyInfo: () => Promise<CustomerCompanyInfo>;
40
+ export declare const updateCustomerGroup: () => Promise<string | null>;
41
+ //# sourceMappingURL=customerCompanyContext.d.ts.map
@@ -0,0 +1,10 @@
1
+ /********************************************************************
2
+ * Copyright 2025 Adobe
3
+ * All Rights Reserved.
4
+ *
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
+ *******************************************************************/
9
+ 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";
10
+ //# sourceMappingURL=customerCompanyContext.graphql.d.ts.map
@@ -0,0 +1,10 @@
1
+ /********************************************************************
2
+ * Copyright 2025 Adobe
3
+ * All Rights Reserved.
4
+ *
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
+ *******************************************************************/
9
+ export declare const GET_CUSTOMER_GROUP_CONTEXT = "\n query GET_CUSTOMER_GROUP {\n customerGroup {\n uid\n }\n }\n";
10
+ //# sourceMappingURL=customerGroupContext.graphql.d.ts.map
@@ -0,0 +1,10 @@
1
+ /********************************************************************
2
+ * Copyright 2025 Adobe
3
+ * All Rights Reserved.
4
+ *
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
+ *******************************************************************/
9
+ export * from './customerCompanyContext';
10
+ //# sourceMappingURL=index.d.ts.map
package/api/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './initialize';
2
2
  export * from './fetch-graphql';
3
- export * from './customerCompanies';
3
+ export * from './customerCompanyContext';
4
+ export * from './setCompanyHeaders';
5
+ export * from './setGroupHeaders';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,8 +1,15 @@
1
1
  import { Initializer } from '@dropins/tools/types/elsie/src/lib';
2
2
  import { Lang } from '@dropins/tools/types/elsie/src/i18n';
3
+ import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';
3
4
 
4
5
  type ConfigProps = {
5
6
  langDefinitions?: Lang;
7
+ companyHeader: string;
8
+ customerGroupHeader: string;
9
+ companySessionStorageKey: string;
10
+ groupSessionStorageKey: string;
11
+ fetchGraphQlModules: FetchGraphQL[];
12
+ groupGraphQlModules: FetchGraphQL[];
6
13
  };
7
14
  export declare const initialize: Initializer<ConfigProps>;
8
15
  export declare const config: import('@dropins/tools/types/elsie/src/lib').Config<ConfigProps>;
@@ -6,5 +6,5 @@
6
6
  * file in accordance with the terms of the Adobe license agreement
7
7
  * accompanying it.
8
8
  *******************************************************************/
9
- export * from './customerCompanies';
9
+ export * from './setCompanyHeaders';
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';
2
+
3
+ declare class CompanyHeaderManager {
4
+ private companyHeaderSet;
5
+ private companyHeaderAppliers;
6
+ private companyHeaderRemovers;
7
+ private headerKey;
8
+ constructor();
9
+ setHeaderKey(headerKey: string): void;
10
+ setFetchGraphQlModules(modules: FetchGraphQL[]): void;
11
+ setCompanyHeaders(companyId: string | null): void;
12
+ removeCompanyHeaders(): void;
13
+ isCompanyHeaderSet(): boolean;
14
+ }
15
+ export declare const getCompanyHeaderManager: () => CompanyHeaderManager;
16
+ export {};
17
+ //# sourceMappingURL=setCompanyHeaders.d.ts.map
@@ -0,0 +1,10 @@
1
+ /********************************************************************
2
+ * Copyright 2025 Adobe
3
+ * All Rights Reserved.
4
+ *
5
+ * NOTICE: Adobe permits you to use, modify, and distribute this
6
+ * file in accordance with the terms of the Adobe license agreement
7
+ * accompanying it.
8
+ *******************************************************************/
9
+ export * from './setGroupHeaders';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,17 @@
1
+ import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';
2
+
3
+ declare class GroupHeaderManager {
4
+ private groupHeaderSet;
5
+ private groupHeaderAppliers;
6
+ private groupHeaderRemovers;
7
+ private headerKey;
8
+ constructor();
9
+ setHeaderKey(headerKey: string): void;
10
+ setFetchGraphQlModules(modules: FetchGraphQL[]): void;
11
+ setGroupHeaders(groupId: string | null): void;
12
+ removeGroupHeaders(): void;
13
+ isGroupHeaderSet(): boolean;
14
+ }
15
+ export declare const getGroupHeaderManager: () => GroupHeaderManager;
16
+ export {};
17
+ //# sourceMappingURL=setGroupHeaders.d.ts.map
package/api.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{f,c as p,g,r as h,s as l,a as m,b as d}from"./chunks/customerCompanies.js";import{Initializer as o}from"@dropins/tools/lib.js";import"@dropins/tools/fetch-graphql.js";const e=new o({init:async t=>{const a={};e.config.setConfig({...a,...t})},listeners:()=>[]}),n=e.config;export{n as config,f as fetchGraphQl,p as getConfig,g as getCustomerCompanyInfo,e as initialize,h as removeFetchGraphQlHeader,l as setEndpoint,m as setFetchGraphQlHeader,d as setFetchGraphQlHeaders};
3
+ var f=Object.defineProperty;var l=(t,e,r)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var a=(t,e,r)=>l(t,typeof e!="symbol"?e+"":e,r);import{g as C,u as S}from"./chunks/customerCompanyContext.js";import{C as F,f as O,c as x,r as N,s as P,a as T,b as w}from"./chunks/customerCompanyContext.js";import{Initializer as G}from"@dropins/tools/lib.js";import{events as p}from"@dropins/tools/event-bus.js";import"@dropins/tools/fetch-graphql.js";class K{constructor(){a(this,"companyHeaderSet",!1);a(this,"companyHeaderAppliers",[]);a(this,"companyHeaderRemovers",[]);a(this,"headerKey");this.headerKey=m.getConfig().companyHeader,this.setFetchGraphQlModules(m.getConfig().fetchGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){this.companyHeaderAppliers=[],this.companyHeaderRemovers=[],e.forEach(({setFetchGraphQlHeader:r,removeFetchGraphQlHeader:s})=>{this.companyHeaderAppliers.push(r),this.companyHeaderRemovers.push(s)})}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 u=null;const n=()=>(u||(u=new K),u);class I{constructor(){a(this,"groupHeaderSet",!1);a(this,"groupHeaderAppliers",[]);a(this,"groupHeaderRemovers",[]);a(this,"headerKey");this.headerKey=m.getConfig().customerGroupHeader,this.setFetchGraphQlModules(m.getConfig().groupGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){e.forEach(({setFetchGraphQlHeader:r,removeFetchGraphQlHeader:s})=>{this.groupHeaderAppliers.push(r),this.groupHeaderRemovers.push(s)})}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 y=null;const g=()=>(y||(y=new I),y),o=new G({init:async t=>{const e={fetchGraphQlModules:[],groupGraphQlModules:[],companyHeader:"X-Adobe-Company",customerGroupHeader:"Magento-Customer-Group",companySessionStorageKey:"DROPIN__COMPANYSWITCHER__COMPANY__CONTEXT",groupSessionStorageKey:"DROPIN__COMPANYSWITCHER__GROUP__CONTEXT"};o.config.setConfig({...e,...t});const r=sessionStorage.getItem(o.config.getConfig().groupSessionStorageKey),s=sessionStorage.getItem(o.config.getConfig().companySessionStorageKey);s&&!n().isCompanyHeaderSet()&&(n().setCompanyHeaders(s),p.emit("companyContext/restored",s)),r&&!g().isGroupHeaderSet()&&g().setGroupHeaders(r),p.on("authenticated",async i=>{if(!i)sessionStorage.removeItem(o.config.getConfig().companySessionStorageKey),sessionStorage.removeItem(o.config.getConfig().groupSessionStorageKey),n().removeCompanyHeaders(),g().removeGroupHeaders();else{if(sessionStorage.getItem(o.config.getConfig().companySessionStorageKey)||n().isCompanyHeaderSet())return;const c=await C();if(c.customerCompanies.length<2)return;const h=c.currentCompany.id,H=c.customerGroupId;n().setCompanyHeaders(h),g().setGroupHeaders(H),sessionStorage.setItem(o.config.getConfig().companySessionStorageKey,h),sessionStorage.setItem(o.config.getConfig().groupSessionStorageKey,H),p.emit("companyContext/restored",h)}},{eager:!0}),p.on("companyContext/changing",async i=>{n().setCompanyHeaders(i),sessionStorage.setItem(o.config.getConfig().companySessionStorageKey,i);const d=await S();d&&(g().setGroupHeaders(d),sessionStorage.setItem(o.config.getConfig().groupSessionStorageKey,d)),p.emit("companyContext/changed",i)},{eager:!0})},listeners:()=>[]}),m=o.config;export{F as CustomerCompanyContext,m as config,O as fetchGraphQl,n as getCompanyHeaderManager,x as getConfig,C as getCustomerCompanyInfo,g as getGroupHeaderManager,o as initialize,N as removeFetchGraphQlHeader,P as setEndpoint,T as setFetchGraphQlHeader,w as setFetchGraphQlHeaders,S as updateCustomerGroup};
4
4
  //# sourceMappingURL=api.js.map
package/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sources":["/@dropins/storefront-company-switcher/src/api/initialize/initialize.ts"],"sourcesContent":["import { Initializer } from '@adobe-commerce/elsie/lib';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\n// import { events } from '@adobe-commerce/event-bus';\n\ntype ConfigProps = {\n langDefinitions?: Lang;\n};\n\nexport const initialize = new Initializer<ConfigProps>({\n init: async (config) => {\n const defaultConfig = {};\n\n initialize.config.setConfig({ ...defaultConfig, ...config });\n },\n\n listeners: () => [\n // events.on('authenticated', (authenticated) => {\n // console.log('authenticated', authenticated);\n // }),\n ],\n});\n\nexport const config = initialize.config;\n"],"names":["initialize","Initializer","config","defaultConfig"],"mappings":"8KAQO,MAAMA,EAAa,IAAIC,EAAyB,CACrD,KAAM,MAAOC,GAAW,CACtB,MAAMC,EAAgB,CAAA,EAEtBH,EAAW,OAAO,UAAU,CAAE,GAAGG,EAAe,GAAGD,EAAQ,CAC7D,EAEA,UAAW,IAAM,CAAA,CAKnB,CAAC,EAEYA,EAASF,EAAW"}
1
+ {"version":3,"file":"api.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"],"sourcesContent":["/********************************************************************\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 *******************************************************************/\nimport { config } from '../initialize/initialize';\nimport { setFetchGraphQlHeader, removeFetchGraphQlHeader, FetchGraphQL } from '@adobe-commerce/fetch-graphql';\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 public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n this.companyHeaderAppliers = [];\n this.companyHeaderRemovers = [];\n modules.forEach(({ setFetchGraphQlHeader, removeFetchGraphQlHeader }) => {\n this.companyHeaderAppliers.push(setFetchGraphQlHeader);\n this.companyHeaderRemovers.push(removeFetchGraphQlHeader);\n });\n }\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 public removeCompanyHeaders(): void {\n this.companyHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.companyHeaderSet = false;\n }\n\n public isCompanyHeaderSet(): boolean {\n return this.companyHeaderSet;\n }\n}\n\nlet _companyHeaderManager: CompanyHeaderManager | null = null;\nexport const getCompanyHeaderManager = () => {\n if (!_companyHeaderManager) {\n _companyHeaderManager = new CompanyHeaderManager();\n }\n return _companyHeaderManager;\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 *******************************************************************/\nimport { config } from '../initialize/initialize';\nimport { setFetchGraphQlHeader, removeFetchGraphQlHeader, FetchGraphQL } from '@adobe-commerce/fetch-graphql';\n\nclass GroupHeaderManager {\n private groupHeaderSet: boolean = false;\n private groupHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private groupHeaderRemovers: typeof removeFetchGraphQlHeader[] = [];\n private headerKey: string;\n\n constructor() {\n this.headerKey = config.getConfig().customerGroupHeader;\n this.setFetchGraphQlModules(config.getConfig().groupGraphQlModules);\n }\n\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n modules.forEach(({ setFetchGraphQlHeader, removeFetchGraphQlHeader }) => {\n this.groupHeaderAppliers.push(setFetchGraphQlHeader);\n this.groupHeaderRemovers.push(removeFetchGraphQlHeader);\n });\n }\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 public removeGroupHeaders(): void {\n this.groupHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.groupHeaderSet = false;\n }\n\n public isGroupHeaderSet(): boolean {\n return this.groupHeaderSet;\n }\n}\n\nlet _groupHeaderManager: GroupHeaderManager | null = null;\nexport const getGroupHeaderManager = () => {\n if (!_groupHeaderManager) {\n _groupHeaderManager = new GroupHeaderManager();\n }\n return _groupHeaderManager;\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 { Initializer } from '@adobe-commerce/elsie/lib';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { FetchGraphQL } from '@adobe-commerce/fetch-graphql';\nimport { getCompanyHeaderManager } from '../setCompanyHeaders/setCompanyHeaders';\nimport { getGroupHeaderManager } from '../setGroupHeaders/setGroupHeaders';\nimport { updateCustomerGroup, getCustomerCompanyInfo } from '../customerCompanyContext/customerCompanyContext';\nimport { events } from '@adobe-commerce/event-bus';\n\ntype ConfigProps = {\n langDefinitions?: Lang;\n companyHeader: string;\n customerGroupHeader: string;\n companySessionStorageKey: string;\n groupSessionStorageKey: string;\n fetchGraphQlModules: FetchGraphQL[];\n groupGraphQlModules: FetchGraphQL[];\n};\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/restored', companyId);\n }\n if (groupId && !getGroupHeaderManager().isGroupHeaderSet()) {\n getGroupHeaderManager().setGroupHeaders(groupId);\n }\n\n events.on('authenticated', async (authenticated: boolean) => {\n if (!authenticated) {\n sessionStorage.removeItem(initialize.config.getConfig().companySessionStorageKey);\n sessionStorage.removeItem(initialize.config.getConfig().groupSessionStorageKey);\n getCompanyHeaderManager().removeCompanyHeaders();\n getGroupHeaderManager().removeGroupHeaders();\n } else {\n const storedCompanyId = sessionStorage.getItem(initialize.config.getConfig().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(initialize.config.getConfig().companySessionStorageKey, currentCompanyId);\n sessionStorage.setItem(initialize.config.getConfig().groupSessionStorageKey, groupId);\n events.emit('companyContext/restored', currentCompanyId);\n }\n }, { eager: true });\n\n events.on('companyContext/changing', async (companyId: string) => {\n getCompanyHeaderManager().setCompanyHeaders(companyId);\n sessionStorage.setItem(initialize.config.getConfig().companySessionStorageKey, companyId);\n\n const groupId = await updateCustomerGroup();\n if (groupId) {\n getGroupHeaderManager().setGroupHeaders(groupId);\n sessionStorage.setItem(initialize.config.getConfig().groupSessionStorageKey, groupId);\n }\n events.emit('companyContext/changed', companyId);\n }, { eager: true });\n },\n listeners: () => [\n \n ],\n});\n\nexport const config = initialize.config;\n"],"names":["CompanyHeaderManager","__publicField","config","headerKey","modules","setFetchGraphQlHeader","removeFetchGraphQlHeader","companyId","setFn","removeFn","_companyHeaderManager","getCompanyHeaderManager","GroupHeaderManager","groupId","_groupHeaderManager","getGroupHeaderManager","initialize","Initializer","defaultConfig","events","authenticated","companyInfo","getCustomerCompanyInfo","currentCompanyId","updateCustomerGroup"],"mappings":"odAWA,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,CAEO,aAAaC,EAAyB,CAC3C,KAAK,UAAYA,CACnB,CAEO,uBAAuBC,EAA+B,CAC3D,KAAK,sBAAwB,CAAA,EAC7B,KAAK,sBAAwB,CAAA,EAC7BA,EAAQ,QAAQ,CAAC,CAAE,sBAAAC,EAAuB,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,CAAgB,EAC/F,eAAe,QAAQP,EAAW,OAAO,UAAA,EAAY,uBAAwBH,CAAO,EACpFM,EAAO,KAAK,0BAA2BI,CAAgB,CACzD,CACF,EAAG,CAAE,MAAO,GAAM,EAElBJ,EAAO,GAAG,0BAA2B,MAAOZ,GAAsB,CAChEI,EAAA,EAA0B,kBAAkBJ,CAAS,EACrD,eAAe,QAAQS,EAAW,OAAO,UAAA,EAAY,yBAA0BT,CAAS,EAExF,MAAMM,EAAU,MAAMW,EAAA,EAClBX,IACFE,EAAA,EAAwB,gBAAgBF,CAAO,EAC/C,eAAe,QAAQG,EAAW,OAAO,UAAA,EAAY,uBAAwBH,CAAO,GAEtFM,EAAO,KAAK,yBAA0BZ,CAAS,CACjD,EAAG,CAAE,MAAO,GAAM,CACpB,EACA,UAAW,IAAM,CAAA,CAGnB,CAAC,EAEYL,EAASc,EAAW"}
@@ -0,0 +1,28 @@
1
+ /*! Copyright 2025 Adobe
2
+ All Rights Reserved. */
3
+ var i=Object.defineProperty;var h=(s,t,e)=>t in s?i(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var o=(s,t,e)=>h(s,typeof t!="symbol"?t+"":t,e);import{FetchGraphQL as p}from"@dropins/tools/fetch-graphql.js";const{setEndpoint:E,setFetchGraphQlHeader:O,removeFetchGraphQlHeader:f,setFetchGraphQlHeaders:l,fetchGraphQl:u,getConfig:m}=new p().getMethods(),d=`
4
+ query GET_CUSTOMER_COMPANIES {
5
+ customer {
6
+ companies {
7
+ items {
8
+ name
9
+ id
10
+ }
11
+ }
12
+ }
13
+ company {
14
+ name
15
+ id
16
+ }
17
+ customerGroup {
18
+ uid
19
+ }
20
+ }
21
+ `,C=`
22
+ query GET_CUSTOMER_GROUP {
23
+ customerGroup {
24
+ uid
25
+ }
26
+ }
27
+ `,r=class r{constructor(){o(this,"EMPTY_CUSTOMER_COMPANY_CONTEXT",{currentCompany:{id:"",name:""},customerCompanies:[],customerGroupId:""});o(this,"cache",null);o(this,"transformCompanyToOption",t=>({text:t.name,value:t.id}))}static getInstance(){return r.instance??(r.instance=new r)}async processCustomerGroupId(t){const e=Uint8Array.from(atob(t),a=>a.charCodeAt(0)),n=await crypto.subtle.digest("SHA-1",e);return Array.from(new Uint8Array(n)).map(a=>a.toString(16).padStart(2,"0")).join("")}isUserAuthenticated(){var t;return!!((t=m().fetchGraphQlHeaders)!=null&&t.Authorization)}resetCache(){this.cache=null}async updateCustomerGroup(){if(!this.isUserAuthenticated())return null;try{const t=await u(C);if(t.errors)return null;const e=await this.processCustomerGroupId(t.data.customerGroup.uid);return this.cache&&(this.cache.customerGroupId=e),e}catch(t){return console.error(t),null}}async getCustomerCompanyInfo(){if(this.cache)return this.cache;if(!this.isUserAuthenticated())return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;try{const t=await u(d);if(t.errors)return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;const e=t.data,n=await this.processCustomerGroupId(t.data.customerGroup.uid),a=e.customer.companies.items.map(this.transformCompanyToOption);return this.cache={currentCompany:e.company,customerCompanies:a,customerGroupId:n},this.cache}catch{return this.EMPTY_CUSTOMER_COMPANY_CONTEXT}}};o(r,"instance");let c=r;const M=()=>c.getInstance().getCustomerCompanyInfo(),_=()=>c.getInstance().updateCustomerGroup();export{c as C,O as a,l as b,m as c,u as f,M as g,f as r,E as s,_ as u};
28
+ //# sourceMappingURL=customerCompanyContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customerCompanyContext.js","sources":["/@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":["import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';\n\nexport const {\n setEndpoint,\n setFetchGraphQlHeader,\n removeFetchGraphQlHeader,\n setFetchGraphQlHeaders,\n fetchGraphQl,\n getConfig,\n} = new FetchGraphQL().getMethods();\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\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 * 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\nexport const GET_CUSTOMER_GROUP_CONTEXT = `\n query GET_CUSTOMER_GROUP {\n customerGroup {\n uid\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 { 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 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":["setEndpoint","setFetchGraphQlHeader","removeFetchGraphQlHeader","setFetchGraphQlHeaders","fetchGraphQl","getConfig","FetchGraphQL","GET_CUSTOMER_COMPANY_CONTEXT","GET_CUSTOMER_GROUP_CONTEXT","_CustomerCompanyContext","__publicField","company","base64String","decoded","c","hashBuffer","b","_a","response","customerGroupId","e","data","customerGroup","customerCompanies","CustomerCompanyContext","getCustomerCompanyInfo","updateCustomerGroup"],"mappings":"mOAEO,KAAM,CACX,YAAAA,EACA,sBAAAC,EACA,yBAAAC,EACA,uBAAAC,EACA,aAAAC,EACA,UAAAC,CACF,EAAI,IAAIC,EAAA,EAAe,WAAA,ECAVC,EAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,ECA/BC,EAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,ECK7BC,EAAN,MAAMA,CAAuB,CAA7B,cAIYC,EAAA,sCAAsD,CACrE,eAAgB,CAAE,GAAI,GAAI,KAAM,EAAA,EAChC,kBAAmB,CAAA,EACnB,gBAAiB,EAAA,GAGXA,EAAA,aAAoC,MAYpCA,EAAA,gCAA4BC,IAAqC,CACvE,KAAMA,EAAQ,KACd,MAAOA,EAAQ,EAAA,IATjB,OAAO,aAAsC,CAC3C,OAAOF,EAAuB,WAAvBA,EAAuB,SAAa,IAAIA,EACjD,CAaA,MAAc,uBAAuBG,EAAuC,CA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,IAC7BD,EAAuB,YAAA,EAAc,uBAAA,EAGjCE,EAAsB,IAC1BF,EAAuB,YAAA,EAAc,oBAAA"}
@@ -1,4 +1,4 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsx as f}from"@dropins/tools/preact-jsx-runtime.js";import{useState as u,useCallback as p,useEffect as g,useMemo as v}from"@dropins/tools/preact-hooks.js";import{Picker as x}from"@dropins/tools/components.js";import{events as C}from"@dropins/tools/event-bus.js";import{g as w}from"../chunks/customerCompanies.js";import"@dropins/tools/fetch-graphql.js";const I=()=>{const[r,m]=u([]),[c,a]=u({text:"",value:""}),i=p(async()=>{var e,n;try{const t=await w();m(t.customerCompanies),(e=t.currentCompany)!=null&&e.name&&((n=t.currentCompany)!=null&&n.id)&&a({text:t.currentCompany.name,value:t.currentCompany.id})}catch(t){console.error("Failed to load company data:",t)}},[]),s=p(e=>{const t=e.target.value,o=r.find(h=>h.value===t);o&&a(o),C.emit("companyContext/changed",t)},[r]),l=p(()=>{m([]),a({text:"",value:""})},[]),y=p(e=>{e?i():l()},[i,l]),d=p(e=>{m(n=>{const t=n.find(o=>o.value===e);return t&&a(t),n})},[]);return g(()=>{const e=C.on("authenticated",y,{eager:!0}),n=C.on("companyContext/restored",d);return()=>{var t,o;(t=e==null?void 0:e.off)==null||t.call(e),(o=n==null?void 0:n.off)==null||o.call(n)}},[y,d]),{companies:r,currentCompany:c,handleCompanyChange:s}},F=({ariaLabel:r,...m})=>{const{companies:c,currentCompany:a,handleCompanyChange:i}=I(),s=v(()=>c,[c]);return c.length<2?null:f("div",{...m,children:f(x,{options:s,value:a.value,onChange:i,"aria-label":r||"Select company","aria-describedby":"company-switcher-description"})})};export{F as CompanySwitcher,F as default,I as useCompanyData};
3
+ import{jsx as u}from"@dropins/tools/preact-jsx-runtime.js";import{useState as f,useCallback as C,useEffect as x,useMemo as v}from"@dropins/tools/preact-hooks.js";import{Picker as I}from"@dropins/tools/components.js";import{events as i}from"@dropins/tools/event-bus.js";import{C as g}from"../chunks/customerCompanyContext.js";import"@dropins/tools/fetch-graphql.js";const w=()=>{const[r,m]=f([]),[c,a]=f({text:"",value:""}),p=C(async()=>{var t,n;try{const e=await g.getInstance().getCustomerCompanyInfo();m(e.customerCompanies),(t=e.currentCompany)!=null&&t.name&&((n=e.currentCompany)!=null&&n.id)&&a({text:e.currentCompany.name,value:e.currentCompany.id})}catch(o){console.error("Failed to load company data:",o)}},[]),s=C(t=>{const o=t.target.value,e=r.find(h=>h.value===o);e&&a(e),i.emit("companyContext/changing",o)},[r]),y=C(()=>{g.getInstance().resetCache(),m([]),a({text:"",value:""})},[]),l=C(t=>{t?p():y()},[p,y]),d=C(t=>{m(n=>{const o=n.find(e=>e.value===t);return o&&a(o),n})},[]);return x(()=>{const t=i.on("authenticated",l,{eager:!0}),n=i.on("companyContext/restored",d,{eager:!0});return()=>{var o,e;(o=t==null?void 0:t.off)==null||o.call(t),(e=n==null?void 0:n.off)==null||e.call(n)}},[l,d]),{companies:r,currentCompany:c,handleCompanyChange:s}},F=({ariaLabel:r,...m})=>{const{companies:c,currentCompany:a,handleCompanyChange:p}=w(),s=v(()=>c,[c]);return c.length<2?null:u("div",{...m,children:u(I,{options:s,value:a.value,onChange:p,"aria-label":r||"Select company","aria-describedby":"company-switcher-description"})})};export{F as CompanySwitcher,F as default,w as useCompanyData};
4
4
  //# sourceMappingURL=CompanySwitcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CompanySwitcher.js","sources":["/@dropins/storefront-company-switcher/src/containers/CompanySwitcher/useCompanyData.ts","/@dropins/storefront-company-switcher/src/containers/CompanySwitcher/CompanySwitcher.tsx"],"sourcesContent":["/********************************************************************\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 { useState, useCallback, useEffect } from 'preact/hooks';\nimport { events } from '@adobe-commerce/event-bus';\nimport { getCustomerCompanyInfo } from '@/company-switcher/api';\nimport type { CompanyOption, CustomerCompanyInfo, UseCompanyDataReturn } from '@/company-switcher/types/company';\n\n/**\n * Custom hook that manages company data fetching and state management\n * @returns {UseCompanyDataReturn} Company data and handlers\n */\nexport const useCompanyData = (): UseCompanyDataReturn => {\n const [companies, setCompanies] = useState<CompanyOption[]>([]);\n const [currentCompany, setCurrentCompany] = useState<CompanyOption>({ text: '', value: '' });\n\n\n /**\n * Loads company information from the API and updates state\n */\n const loadCompanyData = useCallback(async (): Promise<void> => {\n try {\n const companyInfo: CustomerCompanyInfo = await getCustomerCompanyInfo();\n setCompanies(companyInfo.customerCompanies);\n \n if (companyInfo.currentCompany?.name && companyInfo.currentCompany?.id) {\n setCurrentCompany({\n text: companyInfo.currentCompany.name, \n value: companyInfo.currentCompany.id\n });\n }\n } catch (err) {\n console.error('Failed to load company data:', err);\n }\n }, []);\n\n /**\n * Handles company selection change\n */\n const handleCompanyChange = useCallback((event: Event): void => {\n const target = event.target as HTMLSelectElement;\n const companyId = target.value;\n \n // Update local state\n const selectedCompany = companies.find(c => c.value === companyId);\n if (selectedCompany) {\n setCurrentCompany(selectedCompany);\n }\n \n // Emit event for other components to react to company change\n events.emit('companyContext/changed', companyId);\n }, [companies]);\n\n /**\n * Clears company context\n */\n const clearCompanyContext = useCallback((): void => {\n setCompanies([]);\n setCurrentCompany({ text: '', value: '' });\n }, []);\n\n /**\n * Handles authentication state changes\n */\n const handleAuthenticationChange = useCallback((authenticated: boolean) => {\n if (authenticated) {\n loadCompanyData();\n } else {\n clearCompanyContext();\n }\n }, [loadCompanyData, clearCompanyContext]);\n\n /**\n * Handles company context restoration\n */\n const handleCompanyContextRestored = useCallback((companyId: string) => {\n // Store the company ID to be restored when companies are loaded\n setCompanies(prevCompanies => {\n const restoredCompany = prevCompanies.find(company => company.value === companyId);\n if (restoredCompany) {\n setCurrentCompany(restoredCompany);\n }\n return prevCompanies;\n });\n }, []);\n\n // Set up event listeners\n useEffect(() => {\n const unsubscribeAuth = events.on('authenticated', handleAuthenticationChange, { eager: true });\n const unsubscribeRestore = events.on('companyContext/restored', handleCompanyContextRestored);\n \n return () => {\n unsubscribeAuth?.off?.();\n unsubscribeRestore?.off?.();\n };\n }, [handleAuthenticationChange, handleCompanyContextRestored]);\n\n return {\n companies,\n currentCompany,\n handleCompanyChange\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 { HTMLAttributes } from 'preact/compat';\nimport { useMemo } from 'preact/hooks';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { Picker } from '@adobe-commerce/elsie/components';\nimport { useCompanyData } from './useCompanyData';\n\nexport interface CompanySwitcherProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom aria-label for the picker */\n ariaLabel?: string;\n}\n\n/**\n * CompanySwitcher component allows users to switch between companies they have access to.\n * It only renders when a user has access to multiple companies.\n * This is a presentational component that uses the useCompanyData hook for all business logic.\n */\nexport const CompanySwitcher: Container<CompanySwitcherProps> = ({ \n ariaLabel,\n ...props \n}) => {\n const { companies, currentCompany, handleCompanyChange } = useCompanyData();\n\n // Memoize the companies array to prevent unnecessary re-renders\n const memoizedCompanies = useMemo(() => companies, [companies]);\n\n // Only render if user has access to multiple companies\n if (companies.length < 2) {\n return null;\n }\n\n return (\n <div {...props}>\n <Picker \n options={memoizedCompanies} \n value={currentCompany.value} \n onChange={handleCompanyChange}\n aria-label={ariaLabel || 'Select company'}\n aria-describedby=\"company-switcher-description\"\n />\n </div>\n );\n};\n"],"names":["useCompanyData","companies","setCompanies","useState","currentCompany","setCurrentCompany","loadCompanyData","useCallback","companyInfo","getCustomerCompanyInfo","_a","_b","err","handleCompanyChange","event","companyId","selectedCompany","c","events","clearCompanyContext","handleAuthenticationChange","authenticated","handleCompanyContextRestored","prevCompanies","restoredCompany","company","useEffect","unsub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GL,OAAAG,EAAU,IAAM,CACd,MAAMC,EAAkBT,EAAO,GAAG,gBAAiBE,EAA4B,CAAE,MAAO,GAAM,EACxFQ,EAAqBV,EAAO,GAAG,0BAA2BI,CAA4B,EAE5F,MAAO,IAAM,UACXZ,EAAAiB,GAAA,YAAAA,EAAiB,MAAjB,MAAAjB,EAAA,KAAAiB,IACAhB,EAAAiB,GAAA,YAAAA,EAAoB,MAApB,MAAAjB,EAAA,KAAAiB,EACF,CACF,EAAG,CAACR,EAA4BE,CAA4B,CAAC,EAEtD,CACL,UAAArB,EACA,eAAAG,EACA,oBAAAS,CAAA,CAEJ,ECnFagB,EAAmD,CAAC,CAC/D,UAAAC,EACA,GAAGC,CACL,IAAM,CACJ,KAAM,CAAE,UAAA9B,EAAW,eAAAG,EAAgB,oBAAAS,CAAA,EAAwBb,EAAA,EAGrDgC,EAAoBC,EAAQ,IAAMhC,EAAW,CAACA,CAAS,CAAC,EAG9D,OAAIA,EAAU,OAAS,EACd,KAIPiC,EAAC,MAAA,CAAK,GAAGH,EACP,SAAAG,EAACC,EAAA,CACC,QAASH,EACT,MAAO5B,EAAe,MACtB,SAAUS,EACV,aAAYiB,GAAa,iBACzB,mBAAiB,8BAAA,CAAA,EAErB,CAEJ"}
1
+ {"version":3,"file":"CompanySwitcher.js","sources":["/@dropins/storefront-company-switcher/src/containers/CompanySwitcher/useCompanyData.ts","/@dropins/storefront-company-switcher/src/containers/CompanySwitcher/CompanySwitcher.tsx"],"sourcesContent":["/********************************************************************\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 { useState, useCallback, useEffect } from 'preact/hooks';\nimport { events } from '@adobe-commerce/event-bus';\nimport { CustomerCompanyContext } from '@/company-switcher/api/customerCompanyContext';\nimport type { CompanyOption, CustomerCompanyInfo, UseCompanyDataReturn } from '@/company-switcher/types/company';\n\n/**\n * Custom hook that manages company data fetching and state management\n * @returns {UseCompanyDataReturn} Company data and handlers\n */\nexport const useCompanyData = (): UseCompanyDataReturn => {\n const [companies, setCompanies] = useState<CompanyOption[]>([]);\n const [currentCompany, setCurrentCompany] = useState<CompanyOption>({ text: '', value: '' });\n\n\n /**\n * Loads company information from the API and updates state\n */\n const loadCompanyData = useCallback(async (): Promise<void> => {\n try {\n const customerCompanyContext = CustomerCompanyContext.getInstance();\n const companyInfo: CustomerCompanyInfo = await customerCompanyContext.getCustomerCompanyInfo();\n setCompanies(companyInfo.customerCompanies);\n \n if (companyInfo.currentCompany?.name && companyInfo.currentCompany?.id) {\n setCurrentCompany({\n text: companyInfo.currentCompany.name, \n value: companyInfo.currentCompany.id\n });\n }\n } catch (err) {\n console.error('Failed to load company data:', err);\n }\n }, []);\n\n /**\n * Handles company selection change\n */\n const handleCompanyChange = useCallback((event: Event): void => {\n const target = event.target as HTMLSelectElement;\n const companyId = target.value;\n \n // Update local state\n const selectedCompany = companies.find(c => c.value === companyId);\n if (selectedCompany) {\n setCurrentCompany(selectedCompany);\n }\n \n // Emit event for other components to react to company change\n events.emit('companyContext/changing', companyId);\n }, [companies]);\n\n /**\n * Clears company context\n */\n const clearCompanyContext = useCallback((): void => {\n const customerCompanyContext = CustomerCompanyContext.getInstance();\n customerCompanyContext.resetCache();\n setCompanies([]);\n setCurrentCompany({ text: '', value: '' });\n }, []);\n\n /**\n * Handles authentication state changes\n */\n const handleAuthenticationChange = useCallback((authenticated: boolean) => {\n if (authenticated) {\n loadCompanyData();\n } else {\n clearCompanyContext();\n }\n }, [loadCompanyData, clearCompanyContext]);\n\n /**\n * Handles company context restoration\n */\n const handleCompanyContextRestored = useCallback((companyId: string) => {\n // Store the company ID to be restored when companies are loaded\n setCompanies(prevCompanies => {\n const restoredCompany = prevCompanies.find(company => company.value === companyId);\n if (restoredCompany) {\n setCurrentCompany(restoredCompany);\n }\n return prevCompanies;\n });\n }, []);\n\n // Set up event listeners\n useEffect(() => {\n const unsubscribeAuth = events.on('authenticated', handleAuthenticationChange, { eager: true });\n const unsubscribeRestore = events.on('companyContext/restored', handleCompanyContextRestored, { eager: true });\n \n return () => {\n unsubscribeAuth?.off?.();\n unsubscribeRestore?.off?.();\n };\n }, [handleAuthenticationChange, handleCompanyContextRestored]);\n\n return {\n companies,\n currentCompany,\n handleCompanyChange\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 { HTMLAttributes } from 'preact/compat';\nimport { useMemo } from 'preact/hooks';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { Picker } from '@adobe-commerce/elsie/components';\nimport { useCompanyData } from './useCompanyData';\n\nexport interface CompanySwitcherProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom aria-label for the picker */\n ariaLabel?: string;\n}\n\n/**\n * CompanySwitcher component allows users to switch between companies they have access to.\n * It only renders when a user has access to multiple companies.\n * This is a presentational component that uses the useCompanyData hook for all business logic.\n */\nexport const CompanySwitcher: Container<CompanySwitcherProps> = ({ \n ariaLabel,\n ...props \n}) => {\n const { companies, currentCompany, handleCompanyChange } = useCompanyData();\n\n // Memoize the companies array to prevent unnecessary re-renders\n const memoizedCompanies = useMemo(() => companies, [companies]);\n\n // Only render if user has access to multiple companies\n if (companies.length < 2) {\n return null;\n }\n\n return (\n <div {...props}>\n <Picker \n options={memoizedCompanies} \n value={currentCompany.value} \n onChange={handleCompanyChange}\n aria-label={ariaLabel || 'Select company'}\n aria-describedby=\"company-switcher-description\"\n />\n </div>\n );\n};\n"],"names":["useCompanyData","companies","setCompanies","useState","currentCompany","setCurrentCompany","loadCompanyData","useCallback","companyInfo","CustomerCompanyContext","_a","_b","err","handleCompanyChange","event","companyId","selectedCompany","c","events","clearCompanyContext","handleAuthenticationChange","authenticated","handleCompanyContextRestored","prevCompanies","restoredCompany","company","useEffect","unsubscribe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AAe,EAE5BD,CACT,CAAC,CACH,EAAG,CAAA,CAAE,EAGL,OAAAG,EAAU,IAAM,CACd,MAAMC,EAAkBT,EAAO,GAAG,gBAAiBE,EAA4B,CAAE,MAAO,GAAM,EACxFQ,EAAqBV,EAAO,GAAG,0BAA2BI,EAA8B,CAAE,MAAO,GAAM,EAE7G,MAAO,IAAM,UACXZ,EAAAiB,GAAA,YAAAA,EAAiB,MAAjB,MAAAjB,EAAA,KAAAiB,IACAhB,EAAAiB,GAAA,YAAAA,EAAoB,MAApB,MAAAjB,EAAA,KAAAiB,EACF,CACF,EAAG,CAACR,EAA4BE,CAA4B,CAAC,EAEtD,CACL,UAAArB,EACA,eAAAG,EACA,oBAAAS,CAAA,CAEJ,ECtFagB,EAAmD,CAAC,CAC/D,UAAAC,EACA,GAAGC,CACL,IAAM,CACJ,KAAM,CAAE,UAAA9B,EAAW,eAAAG,EAAgB,oBAAAS,CAAA,EAAwBb,EAAA,EAGrDgC,EAAoBC,EAAQ,IAAMhC,EAAW,CAACA,CAAS,CAAC,EAG9D,OAAIA,EAAU,OAAS,EACd,KAIPiC,EAAC,MAAA,CAAK,GAAGH,EACP,SAAAG,EAACC,EAAA,CACC,QAASH,EACT,MAAO5B,EAAe,MACtB,SAAUS,EACV,aAAYiB,GAAa,iBACzB,mBAAiB,8BAAA,CAAA,EAErB,CAEJ"}
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/storefront-company-switcher", "version": "1.0.0-beta2", "@dropins/tools": "^1.3.0", "license": "SEE LICENSE IN LICENSE.md"}
1
+ {"name": "@dropins/storefront-company-switcher", "version": "1.0.0-beta4", "@dropins/tools": "^1.3.0", "license": "SEE LICENSE IN LICENSE.md"}
@@ -24,8 +24,9 @@ export interface CompanyOption {
24
24
  * Contains customer's current company and available companies
25
25
  */
26
26
  export interface CustomerCompanyInfo {
27
- currentCompany: Company | null;
27
+ currentCompany: Company;
28
28
  customerCompanies: CompanyOption[];
29
+ customerGroupId: string;
29
30
  }
30
31
  /**
31
32
  * Return type for the useCompanyData hook
@@ -36,20 +37,17 @@ export interface UseCompanyDataReturn {
36
37
  handleCompanyChange: (event: Event) => void;
37
38
  }
38
39
  /**
39
- * GraphQL response data structure
40
+ * GraphQL response wrapper
40
41
  */
41
- export interface GraphQLResponseData {
42
- company: Company | null;
42
+ export interface GraphQLResponse {
43
+ company: Company;
43
44
  customer: {
44
45
  companies: {
45
46
  items: Company[];
46
47
  };
47
48
  };
48
- }
49
- /**
50
- * GraphQL response wrapper
51
- */
52
- export interface GraphQLResponse {
53
- data: GraphQLResponseData;
49
+ customerGroup: {
50
+ uid: string;
51
+ };
54
52
  }
55
53
  //# sourceMappingURL=company.d.ts.map
@@ -1,10 +0,0 @@
1
- import { CustomerCompanyInfo } from '../../types/company';
2
-
3
- /**
4
- * Fetches customer company information including the current company and all available companies
5
- *
6
- * @returns Promise containing current company and list of available companies
7
- * @throws Will not throw errors - returns empty data on failure
8
- */
9
- export declare const getCustomerCompanyInfo: () => Promise<CustomerCompanyInfo>;
10
- //# sourceMappingURL=customerCompanies.d.ts.map
@@ -1,19 +0,0 @@
1
- /*! Copyright 2025 Adobe
2
- All Rights Reserved. */
3
- import{FetchGraphQL as c}from"@dropins/tools/fetch-graphql.js";const{setEndpoint:f,setFetchGraphQlHeader:l,removeFetchGraphQlHeader:C,setFetchGraphQlHeaders:y,fetchGraphQl:i,getConfig:m}=new c().getMethods(),p=`
4
- query GET_CUSTOMER_COMPANIES {
5
- customer {
6
- companies {
7
- items {
8
- name
9
- id
10
- }
11
- }
12
- }
13
- company {
14
- name
15
- id
16
- }
17
- }
18
- `,a={currentCompany:null,customerCompanies:[]},u=t=>({text:t.name,value:t.id}),h=()=>{var o;return!!((o=m().fetchGraphQlHeaders)!=null&&o.Authorization)},E=async()=>{var t,o;if(!h())return a;try{const e=await i(p);if(!(e!=null&&e.data))return console.error("Invalid GraphQL response structure"),a;const n=e.data.company,r=e.data.customer,s=((o=(t=r==null?void 0:r.companies)==null?void 0:t.items)==null?void 0:o.map(u))||[];return{currentCompany:n,customerCompanies:s}}catch(e){return console.error("Failed to fetch customer company information:",e),a}};export{l as a,y as b,m as c,i as f,E as g,C as r,f as s};
19
- //# sourceMappingURL=customerCompanies.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"customerCompanies.js","sources":["/@dropins/storefront-company-switcher/src/api/fetch-graphql/fetch-graphql.ts","/@dropins/storefront-company-switcher/src/api/customerCompanies/customerCompanies.ts"],"sourcesContent":["import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';\n\nexport const {\n setEndpoint,\n setFetchGraphQlHeader,\n removeFetchGraphQlHeader,\n setFetchGraphQlHeaders,\n fetchGraphQl,\n getConfig,\n} = new FetchGraphQL().getMethods();\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 { fetchGraphQl, getConfig } from \"@/company-switcher/api\";\nimport type { Company, CompanyOption, CustomerCompanyInfo, GraphQLResponse } from '@/company-switcher/types/company';\n\n// GraphQL Query\nconst GET_CUSTOMER_COMPANIES_QUERY = `\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 }\n`;\n\n// Constants\nconst EMPTY_COMPANY_INFO: CustomerCompanyInfo = {\n currentCompany: null,\n customerCompanies: []\n};\n\n/**\n * Transforms a company object into a company option for UI components\n */\nconst transformCompanyToOption = (company: Company): CompanyOption => ({\n text: company.name,\n value: company.id\n});\n\n/**\n * Checks if the user is authenticated by verifying the Authorization header\n */\nconst isUserAuthenticated = (): boolean => {\n const config = getConfig();\n return Boolean(config.fetchGraphQlHeaders?.Authorization);\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 */\nexport const getCustomerCompanyInfo = async (): Promise<CustomerCompanyInfo> => {\n // Return empty data if user is not authenticated\n if (!isUserAuthenticated()) {\n return EMPTY_COMPANY_INFO;\n }\n\n try {\n // Fetch company data from GraphQL API\n const response = await fetchGraphQl<GraphQLResponse>(GET_CUSTOMER_COMPANIES_QUERY);\n \n if (!response?.data) {\n console.error('Invalid GraphQL response structure');\n return EMPTY_COMPANY_INFO;\n }\n\n const currentCompany = (response as any).data.company;\n const customer = (response as any).data.customer;\n \n // Transform company items to options for UI components\n const customerCompanies = customer?.companies?.items?.map(transformCompanyToOption) || [];\n\n return {\n currentCompany,\n customerCompanies\n };\n } catch (error) {\n // Log error for debugging but don't expose to UI\n console.error('Failed to fetch customer company information:', error);\n return EMPTY_COMPANY_INFO;\n }\n};\n\n"],"names":["setEndpoint","setFetchGraphQlHeader","removeFetchGraphQlHeader","setFetchGraphQlHeaders","fetchGraphQl","getConfig","FetchGraphQL","GET_CUSTOMER_COMPANIES_QUERY","EMPTY_COMPANY_INFO","transformCompanyToOption","company","isUserAuthenticated","_a","getCustomerCompanyInfo","response","currentCompany","customer","customerCompanies","_b","error"],"mappings":"+DAEO,KAAM,CACX,YAAAA,EACA,sBAAAC,EACA,yBAAAC,EACA,uBAAAC,EACA,aAAAC,EACA,UAAAC,CACF,EAAI,IAAIC,EAAA,EAAe,WAAA,ECIjBC,EAA+B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkB/BC,EAA0C,CAC9C,eAAgB,KAChB,kBAAmB,CAAA,CACrB,EAKMC,EAA4BC,IAAqC,CACrE,KAAMA,EAAQ,KACd,MAAOA,EAAQ,EACjB,GAKMC,EAAsB,IAAe,OAEzC,MAAO,IAAQC,EADAP,EAAA,EACO,sBAAP,MAAAO,EAA4B,cAC7C,EAQaC,EAAyB,SAA0C,SAE9E,GAAI,CAACF,IACH,OAAOH,EAGT,GAAI,CAEF,MAAMM,EAAW,MAAMV,EAA8BG,CAA4B,EAEjF,GAAI,EAACO,GAAA,MAAAA,EAAU,MACb,eAAQ,MAAM,oCAAoC,EAC3CN,EAGT,MAAMO,EAAkBD,EAAiB,KAAK,QACxCE,EAAYF,EAAiB,KAAK,SAGlCG,IAAoBC,GAAAN,EAAAI,GAAA,YAAAA,EAAU,YAAV,YAAAJ,EAAqB,QAArB,YAAAM,EAA4B,IAAIT,KAA6B,CAAA,EAEvF,MAAO,CACL,eAAAM,EACA,kBAAAE,CAAA,CAEJ,OAASE,EAAO,CAEd,eAAQ,MAAM,gDAAiDA,CAAK,EAC7DX,CACT,CACF"}