@dropins/storefront-company-switcher 1.0.1 → 1.0.2-alpha1000

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,18 @@
1
1
  /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
2
5
  * Copyright 2025 Adobe
3
6
  * All Rights Reserved.
4
7
  *
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
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
8
16
  *******************************************************************/
9
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";
10
18
  //# sourceMappingURL=customerCompanyContext.graphql.d.ts.map
@@ -1,10 +1,18 @@
1
1
  /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
2
5
  * Copyright 2025 Adobe
3
6
  * All Rights Reserved.
4
7
  *
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
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
8
16
  *******************************************************************/
9
17
  export declare const GET_CUSTOMER_GROUP_CONTEXT = "\n query GET_CUSTOMER_GROUP {\n customerGroup {\n uid\n }\n }\n";
10
18
  //# sourceMappingURL=customerGroupContext.graphql.d.ts.map
@@ -1,10 +1,18 @@
1
1
  /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
2
5
  * Copyright 2025 Adobe
3
6
  * All Rights Reserved.
4
7
  *
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
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
8
16
  *******************************************************************/
9
17
  export * from './customerCompanyContext';
10
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,39 @@
1
- export declare const setEndpoint: (endpoint: string) => void, setFetchGraphQlHeader: (key: string, value: string | null) => void, removeFetchGraphQlHeader: (key: string) => void, setFetchGraphQlHeaders: (header: import('@adobe-commerce/fetch-graphql').Header | ((prev: import('@adobe-commerce/fetch-graphql').Header) => import('@adobe-commerce/fetch-graphql').Header)) => void, fetchGraphQl: <T = any>(query: string, options?: import('@adobe-commerce/fetch-graphql').FetchOptions | undefined) => Promise<{
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+ /**
18
+ * GraphQL client methods for making API requests.
19
+ * Provides methods to configure endpoints, headers, and execute GraphQL queries.
20
+ */
21
+ export declare const
22
+ /** Sets the GraphQL endpoint URL */
23
+ setEndpoint: (endpoint: string) => void,
24
+ /** Sets a single GraphQL header */
25
+ setFetchGraphQlHeader: (key: string, value: string | null) => void,
26
+ /** Removes a GraphQL header */
27
+ removeFetchGraphQlHeader: (key: string) => void,
28
+ /** Sets multiple GraphQL headers at once */
29
+ setFetchGraphQlHeaders: (header: import('@adobe-commerce/fetch-graphql').Header | ((prev: import('@adobe-commerce/fetch-graphql').Header) => import('@adobe-commerce/fetch-graphql').Header)) => void,
30
+ /** Executes a GraphQL query or mutation */
31
+ fetchGraphQl: <T = any>(query: string, options?: import('@adobe-commerce/fetch-graphql').FetchOptions | undefined) => Promise<{
2
32
  errors?: import('@adobe-commerce/fetch-graphql').FetchQueryError | undefined;
3
33
  data: T;
4
- }>, getConfig: () => {
34
+ }>,
35
+ /** Gets the current configuration */
36
+ getConfig: () => {
5
37
  endpoint: string | undefined;
6
38
  fetchGraphQlHeaders: import('@adobe-commerce/fetch-graphql').Header;
7
39
  };
@@ -1,2 +1,18 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
1
17
  export * from './fetch-graphql';
2
18
  //# sourceMappingURL=index.d.ts.map
package/api/index.d.ts CHANGED
@@ -1,3 +1,19 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
1
17
  export * from './initialize';
2
18
  export * from './fetch-graphql';
3
19
  export * from './customerCompanyContext';
@@ -1,4 +1,3 @@
1
- export * from './initialize';
2
1
  /********************************************************************
3
2
  * ADOBE CONFIDENTIAL
4
3
  * __________________
@@ -15,4 +14,5 @@ export * from './initialize';
15
14
  * is strictly forbidden unless prior written permission is obtained
16
15
  * from Adobe.
17
16
  *******************************************************************/
17
+ export * from './initialize';
18
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,17 +1,35 @@
1
+ import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';
1
2
  import { Initializer } from '@dropins/tools/types/elsie/src/lib';
2
3
  import { Lang } from '@dropins/tools/types/elsie/src/i18n';
3
- import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';
4
4
 
5
- type ConfigProps = {
5
+ /**
6
+ * Configuration properties for the company switcher initialization
7
+ */
8
+ interface ConfigProps {
9
+ /** Optional language definitions for internationalization */
6
10
  langDefinitions?: Lang;
11
+ /** HTTP header name for company identification */
7
12
  companyHeader: string;
13
+ /** HTTP header name for customer group identification */
8
14
  customerGroupHeader: string;
15
+ /** Session storage key for persisting company context */
9
16
  companySessionStorageKey: string;
17
+ /** Session storage key for persisting group context */
10
18
  groupSessionStorageKey: string;
19
+ /** GraphQL modules that will have company headers applied */
11
20
  fetchGraphQlModules: FetchGraphQL[];
21
+ /** GraphQL modules that will have group headers applied */
12
22
  groupGraphQlModules: FetchGraphQL[];
13
- };
23
+ }
24
+ /**
25
+ * Initializer for the company switcher drop-in.
26
+ * Configures headers, storage, and GraphQL modules for company management.
27
+ */
14
28
  export declare const initialize: Initializer<ConfigProps>;
29
+ /**
30
+ * Configuration object for getting and setting company switcher configuration.
31
+ * Provides methods to access and update the current configuration.
32
+ */
15
33
  export declare const config: import('@dropins/tools/types/elsie/src/lib').Config<ConfigProps>;
16
34
  export {};
17
35
  //# sourceMappingURL=initialize.d.ts.map
@@ -1,10 +1,18 @@
1
1
  /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
2
5
  * Copyright 2025 Adobe
3
6
  * All Rights Reserved.
4
7
  *
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
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
8
16
  *******************************************************************/
9
17
  export * from './setCompanyHeaders';
10
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,17 +1,44 @@
1
1
  import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';
2
2
 
3
+ /**
4
+ * Manages company-specific headers for GraphQL requests.
5
+ * Singleton class that handles setting and removing company headers across multiple GraphQL modules.
6
+ */
3
7
  declare class CompanyHeaderManager {
4
8
  private companyHeaderSet;
5
9
  private companyHeaderAppliers;
6
10
  private companyHeaderRemovers;
7
11
  private headerKey;
8
12
  constructor();
13
+ /**
14
+ * Sets the header key used for company identification
15
+ * @param headerKey - The header name to use for company ID
16
+ */
9
17
  setHeaderKey(headerKey: string): void;
18
+ /**
19
+ * Configures GraphQL modules that will have company headers applied
20
+ * @param modules - Array of GraphQL modules with header management functions
21
+ */
10
22
  setFetchGraphQlModules(modules: FetchGraphQL[]): void;
23
+ /**
24
+ * Sets company headers for all configured GraphQL modules
25
+ * @param companyId - The company ID to set in headers, or null to remove headers
26
+ */
11
27
  setCompanyHeaders(companyId: string | null): void;
28
+ /**
29
+ * Removes company headers from all configured GraphQL modules
30
+ */
12
31
  removeCompanyHeaders(): void;
32
+ /**
33
+ * Checks if company headers are currently set
34
+ * @returns true if company headers are set, false otherwise
35
+ */
13
36
  isCompanyHeaderSet(): boolean;
14
37
  }
38
+ /**
39
+ * Gets the singleton instance of CompanyHeaderManager
40
+ * @returns The CompanyHeaderManager instance
41
+ */
15
42
  export declare const getCompanyHeaderManager: () => CompanyHeaderManager;
16
43
  export {};
17
44
  //# sourceMappingURL=setCompanyHeaders.d.ts.map
@@ -1,10 +1,18 @@
1
1
  /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
2
5
  * Copyright 2025 Adobe
3
6
  * All Rights Reserved.
4
7
  *
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
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
8
16
  *******************************************************************/
9
17
  export * from './setGroupHeaders';
10
18
  //# sourceMappingURL=index.d.ts.map
@@ -1,17 +1,45 @@
1
1
  import { FetchGraphQL } from '@adobe-commerce/fetch-graphql';
2
2
 
3
+ /**
4
+ * Manages customer group headers for GraphQL requests.
5
+ * Singleton class that handles setting and removing group headers across multiple GraphQL modules.
6
+ */
3
7
  declare class GroupHeaderManager {
4
8
  private groupHeaderSet;
5
9
  private groupHeaderAppliers;
6
10
  private groupHeaderRemovers;
7
11
  private headerKey;
8
12
  constructor();
13
+ /**
14
+ * Sets the header key used for customer group identification
15
+ * @param headerKey - The header name to use for group ID
16
+ */
9
17
  setHeaderKey(headerKey: string): void;
18
+ /**
19
+ * Configures GraphQL modules that will have group headers applied
20
+ * @param modules - Array of GraphQL modules with header management functions
21
+ */
10
22
  setFetchGraphQlModules(modules: FetchGraphQL[]): void;
23
+ /**
24
+ * Sets customer group headers for all configured GraphQL modules.
25
+ * Always removes existing headers first before setting new ones.
26
+ * @param groupId - The group ID to set in headers, or null to only remove headers
27
+ */
11
28
  setGroupHeaders(groupId: string | null): void;
29
+ /**
30
+ * Removes customer group headers from all configured GraphQL modules
31
+ */
12
32
  removeGroupHeaders(): void;
33
+ /**
34
+ * Checks if customer group headers are currently set
35
+ * @returns true if group headers are set, false otherwise
36
+ */
13
37
  isGroupHeaderSet(): boolean;
14
38
  }
39
+ /**
40
+ * Gets the singleton instance of GroupHeaderManager
41
+ * @returns The GroupHeaderManager instance
42
+ */
15
43
  export declare const getGroupHeaderManager: () => GroupHeaderManager;
16
44
  export {};
17
45
  //# sourceMappingURL=setGroupHeaders.d.ts.map
@@ -1,6 +1,6 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- var G=Object.defineProperty;var S=(s,e,r)=>e in s?G(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var t=(s,e,r)=>S(s,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 T}from"@dropins/tools/fetch-graphql.js";class E{constructor(){t(this,"companyHeaderSet",!1);t(this,"companyHeaderAppliers",[]);t(this,"companyHeaderRemovers",[]);t(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(({setFetchGraphQlHeader:r,removeFetchGraphQlHeader:o})=>{this.companyHeaderAppliers.push(r),this.companyHeaderRemovers.push(o)})}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 E),l);class I{constructor(){t(this,"groupHeaderSet",!1);t(this,"groupHeaderAppliers",[]);t(this,"groupHeaderRemovers",[]);t(this,"headerKey");this.headerKey=h.getConfig().customerGroupHeader,this.setFetchGraphQlModules(h.getConfig().groupGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){e.forEach(({setFetchGraphQlHeader:r,removeFetchGraphQlHeader:o})=>{this.groupHeaderAppliers.push(r),this.groupHeaderRemovers.push(o)})}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 I),C),p=new M({init:async s=>{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,...s});const r=sessionStorage.getItem(p.config.getConfig().groupSessionStorageKey),o=sessionStorage.getItem(p.config.getConfig().companySessionStorageKey);o&&!c().isCompanyHeaderSet()&&(c().setCompanyHeaders(o),u.emit("companyContext/changed",o)),r&&!d().isGroupHeaderSet()&&d().setGroupHeaders(r),u.on("authenticated",async a=>{const i=p.config.getConfig();if(!a)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,H=g.customerGroupId;c().setCompanyHeaders(y),d().setGroupHeaders(H),sessionStorage.setItem(i.companySessionStorageKey,y),sessionStorage.setItem(i.groupSessionStorageKey,H),u.emit("companyContext/changed",y)}},{eager:!0})},listeners:()=>[]}),h=p.config,{setEndpoint:U,setFetchGraphQlHeader:w,removeFetchGraphQlHeader:F,setFetchGraphQlHeaders:Y,fetchGraphQl:f,getConfig:O}=new T().getMethods(),_=`
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 T}from"@dropins/tools/fetch-graphql.js";class E{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 E),l);class I{constructor(){o(this,"groupHeaderSet",!1);o(this,"groupHeaderAppliers",[]);o(this,"groupHeaderRemovers",[]);o(this,"headerKey");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.removeFetchGraphQlHeader(t))})}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 I),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,H=g.customerGroupId;c().setCompanyHeaders(y),d().setGroupHeaders(H),sessionStorage.setItem(i.companySessionStorageKey,y),sessionStorage.setItem(i.groupSessionStorageKey,H),u.emit("companyContext/changed",y)}},{eager:!0})},listeners:()=>[]}),h=p.config,{setEndpoint:U,setFetchGraphQlHeader:w,removeFetchGraphQlHeader:F,setFetchGraphQlHeaders:Y,fetchGraphQl:f,getConfig:O}=new T().getMethods(),_=`
4
4
  query GET_CUSTOMER_COMPANIES {
5
5
  customer {
6
6
  companies {
@@ -24,5 +24,5 @@ var G=Object.defineProperty;var S=(s,e,r)=>e in s?G(s,e,{enumerable:!0,configura
24
24
  uid
25
25
  }
26
26
  }
27
- `,n=class n{constructor(){t(this,"EMPTY_CUSTOMER_COMPANY_CONTEXT",{currentCompany:{id:"",name:""},customerCompanies:[],customerGroupId:""});t(this,"cache",null);t(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),a=>a.charCodeAt(0)),o=await crypto.subtle.digest("SHA-1",r);return Array.from(new Uint8Array(o)).map(a=>a.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 f(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 f(_);if(e.errors)return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;const r=e.data,o=await this.processCustomerGroupId(e.data.customerGroup.uid),a=r.customer.companies.items.map(this.transformCompanyToOption);return this.cache={currentCompany:r.company,customerCompanies:a,customerGroupId:o},this.cache}catch(e){return console.error(e),this.EMPTY_CUSTOMER_COMPANY_CONTEXT}}};t(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,f,O as g,d as h,p as i,F as r,U as s,X as u};
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 f(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 f(_);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,f,O as g,d as h,p as i,F as r,U as s,X as u};
28
28
  //# 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 * 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 { 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/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\nexport const config = initialize.config;\n","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 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","setFetchGraphQlHeader","removeFetchGraphQlHeader","companyId","setFn","removeFn","_companyHeaderManager","getCompanyHeaderManager","GroupHeaderManager","groupId","_groupHeaderManager","getGroupHeaderManager","initialize","Initializer","defaultConfig","events","authenticated","companyInfo","getCustomerCompanyInfo","currentCompanyId","setEndpoint","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":"4UAWA,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,yBAAAC,KAA+B,CACvE,KAAK,sBAAsB,KAAKD,CAAqB,EACrD,KAAK,sBAAsB,KAAKC,CAAwB,CAC1D,CAAC,CACH,CAEO,kBAAkBC,EAAgC,CACvD,GAAIA,IAAc,KAAM,CACtB,KAAK,qBAAA,EACL,MACF,CACA,KAAK,sBAAsB,QAASC,GAAU,CAC5CA,EAAM,KAAK,UAAWD,CAAS,CACjC,CAAC,EACD,KAAK,iBAAmB,EAC1B,CAEO,sBAA6B,CAClC,KAAK,sBAAsB,QAASE,GAAa,CAC/CA,EAAS,KAAK,SAAS,CACzB,CAAC,EACD,KAAK,iBAAmB,EAC1B,CAEO,oBAA8B,CACnC,OAAO,KAAK,gBACd,CACF,CAEA,IAAIC,EAAqD,KAClD,MAAMC,EAA0B,KAChCD,IACHA,EAAwB,IAAIV,GAEvBU,GCpDT,MAAME,CAAmB,CAMvB,aAAc,CALNX,EAAA,sBAA0B,IAC1BA,EAAA,2BAAsD,CAAA,GACtDA,EAAA,2BAAyD,CAAA,GACzDA,EAAA,kBAGN,KAAK,UAAYC,EAAO,UAAA,EAAY,oBACpC,KAAK,uBAAuBA,EAAO,UAAA,EAAY,mBAAmB,CACpE,CAEO,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,CACV,eAAQ,MAAM,CAAC,EACR,KAAK,8BACd,CACF,CACF,EAhHEzC,EADW8B,EACI,YADV,IAAMa,EAANb,EAmHA,MAAMT,EAAyB,IAC7BsB,EAAuB,YAAA,EAAc,uBAAA,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, removeFetchGraphQlHeader } 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: typeof removeFetchGraphQlHeader[] = [];\n private headerKey: string;\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.removeFetchGraphQlHeader(key)\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,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,qBAAA,EACL,MACF,CACA,KAAK,sBAAsB,QAASC,G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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,EACjFI,EAAoBF,EAAK,SAAS,UAAU,MAAM,IAAI,KAAK,wBAAwB,EAEzF,YAAK,MAAQ,CACX,eAAgBA,EAAK,QACrB,kBAAAE,EACA,gBAAiBD,CAAA,EAEZ,KAAK,KACd,OAAS,EAAG,CACV,eAAQ,MAAM,CAAC,EACR,KAAK,8BACd,CACF,CACF,EAhHE5C,EADWiC,EACI,YADV,IAAMa,EAANb,EAmHA,MAAMX,EAAyB,IAC7BwB,EAAuB,YAAA,EAAc,uBAAA,EAGjCC,EAAsB,IAC1BD,EAAuB,YAAA,EAAc,oBAAA"}
@@ -1,12 +1,19 @@
1
1
  /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
2
5
  * Copyright 2025 Adobe
3
6
  * All Rights Reserved.
4
7
  *
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
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
8
16
  *******************************************************************/
9
17
  export * from './CompanySwitcher';
10
- export * from './useCompanyData';
11
18
  export { CompanySwitcher as default } from './CompanySwitcher';
12
19
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
3
- import{jsx as h}from"@dropins/tools/preact-jsx-runtime.js";import{useState as d,useCallback as p,useEffect as x,useMemo as I}from"@dropins/tools/preact-hooks.js";import{Picker as k}from"@dropins/tools/components.js";import{events as C}from"@dropins/tools/event-bus.js";import{C as S,e as H,c as l,u as w,h as K}from"../chunks/customerCompanyContext.js";import"@dropins/tools/lib.js";import"@dropins/tools/fetch-graphql.js";const G=()=>{const[c,r]=d([]),[m,a]=d({text:"",value:""}),y=p(async()=>{var e,t;try{const n=await S.getInstance().getCustomerCompanyInfo();r(n.customerCompanies),(e=n.currentCompany)!=null&&e.name&&((t=n.currentCompany)!=null&&t.id)&&a({text:n.currentCompany.name,value:n.currentCompany.id})}catch(o){console.error("Failed to load company data:",o)}},[]),f=p(async e=>{const o=e.target.value,n=c.find(v=>v.value===o);n&&a(n),H().setCompanyHeaders(o),o?sessionStorage.setItem(l.getConfig().companySessionStorageKey,o):sessionStorage.removeItem(l.getConfig().companySessionStorageKey);const u=await w();K().setGroupHeaders(u),u?sessionStorage.setItem(l.getConfig().groupSessionStorageKey,u):sessionStorage.removeItem(l.getConfig().groupSessionStorageKey),C.emit("companyContext/changed",o)},[c]),s=p(()=>{S.getInstance().resetCache(),r([]),a({text:"",value:""})},[]),g=p(e=>{e?y():s()},[y,s]),i=p(e=>{if(!e){s();return}r(t=>{const o=t.find(n=>n.value===e);return o&&a(o),t})},[s,r,a]);return x(()=>{const e=C.on("authenticated",g,{eager:!0}),t=C.on("companyContext/changed",i,{eager:!0});return()=>{var o,n;(o=e==null?void 0:e.off)==null||o.call(e),(n=t==null?void 0:t.off)==null||n.call(t)}},[g,i]),{companies:c,currentCompany:m,handleCompanyChange:f}},F=({ariaLabel:c,...r})=>{const{companies:m,currentCompany:a,handleCompanyChange:y}=G(),[f,s]=d(!0),g=I(()=>m,[m]);return x(()=>{const i=()=>{s(!1)},e=C.on("checkout/initialized",i),t=C.on("checkout/updated",i);return()=>{e==null||e.off(),t==null||t.off()}},[]),m.length<2||!f?null:h("div",{...r,children:h(k,{options:g,value:a.value,onChange:y,"aria-label":c||"Select company","aria-describedby":"company-switcher-description"})})};export{F as CompanySwitcher,F as default,G as useCompanyData};
3
+ import{jsx as S}from"@dropins/tools/preact-jsx-runtime.js";import{useState as x,useCallback as p,useEffect as I,useMemo as k}from"@dropins/tools/preact-hooks.js";import{Picker as H}from"@dropins/tools/components.js";import{events as C}from"@dropins/tools/event-bus.js";import{C as v,e as w,c as u,u as K,h as G}from"../chunks/customerCompanyContext.js";import"@dropins/tools/lib.js";import"@dropins/tools/fetch-graphql.js";const M=()=>{const[y,s]=x([]),[g,r]=x({text:"",value:""}),l=p(async()=>{var e,o;try{const n=await v.getInstance().getCustomerCompanyInfo();s(n.customerCompanies),(e=n.currentCompany)!=null&&e.name&&((o=n.currentCompany)!=null&&o.id)&&r({text:n.currentCompany.name,value:n.currentCompany.id})}catch(t){console.error("Failed to load company data:",t)}},[]),h=p(async e=>{const t=e.target.value,n=y.find(i=>i.value===t);n&&r(n),w().setCompanyHeaders(t),t?sessionStorage.setItem(u.getConfig().companySessionStorageKey,t):sessionStorage.removeItem(u.getConfig().companySessionStorageKey);const a=await K();G().setGroupHeaders(a),a?sessionStorage.setItem(u.getConfig().groupSessionStorageKey,a):sessionStorage.removeItem(u.getConfig().groupSessionStorageKey),C.emit("companyContext/changed",t)},[y]),c=p(()=>{v.getInstance().resetCache(),s([]),r({text:"",value:""})},[]),d=p(e=>{e?l():c()},[l,c]),f=p(e=>{if(!e){c();return}s(o=>{const t=o.find(n=>n.value===e);return t&&r(t),o})},[c,s,r]),m=p(e=>{const{company:o}=e;s(t=>{const n=t.findIndex(a=>a.value===o.id);return n===-1?t:t.map((a,i)=>i===n?{...a,text:o.name}:a)}),r({text:o.name,value:o.id})},[]);return I(()=>{const e=C.on("authenticated",d,{eager:!0}),o=C.on("companyContext/changed",f,{eager:!0}),t=C.on("company/updated",m);return()=>{var n,a,i;(n=e==null?void 0:e.off)==null||n.call(e),(a=o==null?void 0:o.off)==null||a.call(o),(i=t==null?void 0:t.off)==null||i.call(t)}},[d,f,m]),{companies:y,currentCompany:g,handleCompanyChange:h}},q=({ariaLabel:y,...s})=>{const{companies:g,currentCompany:r,handleCompanyChange:l}=M(),[h,c]=x(!0),d=k(()=>g,[g]);return I(()=>{const f=()=>{c(!1)},m=C.on("checkout/initialized",f),e=C.on("checkout/updated",f);return()=>{m==null||m.off(),e==null||e.off()}},[]),g.length<2||!h?null:S("div",{...s,children:S(H,{options:d,value:r.value,onChange:l,"aria-label":y||"Select company","aria-describedby":"company-switcher-description"})})};export{q as CompanySwitcher,q as default};
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 { CustomerCompanyContext, updateCustomerGroup } from '@/company-switcher/api/customerCompanyContext';\nimport type { CompanyOption, CustomerCompanyInfo, UseCompanyDataReturn } from '@/company-switcher/types/company';\nimport { config } from '@/company-switcher/api/initialize';\nimport { getGroupHeaderManager } from '@/company-switcher/api/setGroupHeaders';\nimport { getCompanyHeaderManager } from '@/company-switcher/api/setCompanyHeaders';\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(async (event: Event): Promise<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 getCompanyHeaderManager().setCompanyHeaders(companyId);\n if (companyId) {\n sessionStorage.setItem(config.getConfig().companySessionStorageKey, companyId);\n } else {\n sessionStorage.removeItem(config.getConfig().companySessionStorageKey);\n }\n const groupId = await updateCustomerGroup();\n getGroupHeaderManager().setGroupHeaders(groupId);\n if (groupId) {\n sessionStorage.setItem(config.getConfig().groupSessionStorageKey, groupId);\n } else {\n sessionStorage.removeItem(config.getConfig().groupSessionStorageKey);\n }\n\n events.emit('companyContext/changed', 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 | null) => {\n if (!companyId) {\n clearCompanyContext();\n return;\n }\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 }, [clearCompanyContext, setCompanies, setCurrentCompany]);\n\n // Set up event listeners\n useEffect(() => {\n const unsubscribeAuth = events.on('authenticated', handleAuthenticationChange, { eager: true });\n const unsubscribeRestore = events.on('companyContext/changed', 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, useState, useEffect } from 'preact/hooks';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { Picker } from '@adobe-commerce/elsie/components';\nimport { events } from '@adobe-commerce/event-bus';\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 const [isVisible, setIsVisible] = useState(true);\n\n // Memoize the companies array to prevent unnecessary re-renders\n const memoizedCompanies = useMemo(() => companies, [companies]);\n\n // Listen for checkout/initialized and checkout/updated events to hide the picker\n useEffect(() => {\n const hidePickerHandler = () => {\n setIsVisible(false);\n };\n\n const unsubscribeInitialized = events.on('checkout/initialized', hidePickerHandler);\n const unsubscribeUpdated = events.on('checkout/updated', hidePickerHandler);\n\n return () => {\n unsubscribeInitialized?.off();\n unsubscribeUpdated?.off();\n };\n }, []);\n\n // Only render if user has access to multiple companies and picker is visible\n if (companies.length < 2 || !isVisible) {\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","getCompanyHeaderManager","config","groupId","updateCustomerGroup","getGroupHeaderManager","events","clearCompanyContext","handleAuthenticationChange","authenticated","handleCompanyContextRestored","prevCompanies","restoredCompany","company","useEffect","unsubscribeAuth","unsubscribeRestore","CompanySwitcher","ariaLabel","props","isVisible","setIsVisible","memoizedCompanies","useMemo","hidePickerHandler","unsubscribeInitialized","unsubscribeUpdated","jsx","Picker"],"mappings":"uaAqBO,MAAMA,EAAiB,IAA4B,CACxD,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAA0B,CAAA,CAAE,EACxD,CAACC,EAAgBC,CAAiB,EAAIF,EAAwB,CAAE,KAAM,GAAI,MAAO,GAAI,EAMrFG,EAAkBC,EAAY,SAA2B,SAC7D,GAAI,CAEF,MAAMC,EAAmC,MADVC,EAAuB,YAAA,EACgB,uBAAA,EACtEP,EAAaM,EAAY,iBAAiB,GAEtCE,EAAAF,EAAY,iBAAZ,MAAAE,EAA4B,QAAQC,EAAAH,EAAY,iBAAZ,MAAAG,EAA4B,KAClEN,EAAkB,CAChB,KAAMG,EAAY,eAAe,KACjC,MAAOA,EAAY,eAAe,EAAA,CACnC,CAEL,OAASI,EA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MAAO,GAAM,EACxFQ,EAAqBV,EAAO,GAAG,yBAA0BI,EAA8B,CAAE,MAAO,GAAM,EAE5G,MAAO,IAAM,UACXjB,EAAAsB,GAAA,YAAAA,EAAiB,MAAjB,MAAAtB,EAAA,KAAAsB,IACArB,EAAAsB,GAAA,YAAAA,EAAoB,MAApB,MAAAtB,EAAA,KAAAsB,EACF,CACF,EAAG,CAACR,EAA4BE,CAA4B,CAAC,EAEtD,CACL,UAAA1B,EACA,eAAAG,EACA,oBAAAS,CAAA,CAEJ,ECzGaqB,EAAmD,CAAC,CAC/D,UAAAC,EACA,GAAGC,CACL,IAAM,CACJ,KAAM,CAAE,UAAAnC,EAAW,eAAAG,EAAgB,oBAAAS,CAAA,EAAwBb,EAAA,EACrD,CAACqC,EAAWC,CAAY,EAAInC,EAAS,EAAI,EAGzCoC,EAAoBC,EAAQ,IAAMvC,EAAW,CAACA,CAAS,CAAC,EAkB9D,OAfA8B,EAAU,IAAM,CACd,MAAMU,EAAoB,IAAM,CAC9BH,EAAa,EAAK,CACpB,EAEMI,EAAyBnB,EAAO,GAAG,uBAAwBkB,CAAiB,EAC5EE,EAAqBpB,EAAO,GAAG,mBAAoBkB,CAAiB,EAE1E,MAAO,IAAM,CACXC,GAAA,MAAAA,EAAwB,MACxBC,GAAA,MAAAA,EAAoB,KACtB,CACF,EAAG,CAAA,CAAE,EAGD1C,EAAU,OAAS,GAAK,CAACoC,EACpB,KAIPO,EAAC,MAAA,CAAK,GAAGR,EACP,SAAAQ,EAACC,EAAA,CACC,QAASN,EACT,MAAOnC,EAAe,MACtB,SAAUS,EACV,aAAYsB,GAAa,iBACzB,mBAAiB,8BAAA,CAAA,EAErB,CAEJ"}
1
+ {"version":3,"file":"CompanySwitcher.js","sources":["/@dropins/storefront-company-switcher/src/hooks/useCompanyData.ts","/@dropins/storefront-company-switcher/src/containers/CompanySwitcher/CompanySwitcher.tsx"],"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 *******************************************************************/\n\nimport { useState, useCallback, useEffect } from 'preact/hooks';\nimport { events } from '@adobe-commerce/event-bus';\nimport { CustomerCompanyContext, updateCustomerGroup } from '@/company-switcher/api/customerCompanyContext';\nimport type { CompanyOption, CustomerCompanyInfo, UseCompanyDataReturn } from '@/company-switcher/types/company';\nimport { config } from '@/company-switcher/api/initialize';\nimport { getGroupHeaderManager } from '@/company-switcher/api/setGroupHeaders';\nimport { getCompanyHeaderManager } from '@/company-switcher/api/setCompanyHeaders';\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(async (event: Event): Promise<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 getCompanyHeaderManager().setCompanyHeaders(companyId);\n if (companyId) {\n sessionStorage.setItem(config.getConfig().companySessionStorageKey, companyId);\n } else {\n sessionStorage.removeItem(config.getConfig().companySessionStorageKey);\n }\n const groupId = await updateCustomerGroup();\n getGroupHeaderManager().setGroupHeaders(groupId);\n if (groupId) {\n sessionStorage.setItem(config.getConfig().groupSessionStorageKey, groupId);\n } else {\n sessionStorage.removeItem(config.getConfig().groupSessionStorageKey);\n }\n\n events.emit('companyContext/changed', 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 | null) => {\n if (!companyId) {\n clearCompanyContext();\n return;\n }\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 }, [clearCompanyContext, setCompanies, setCurrentCompany]);\n\n /**\n * Handles company updated event\n */\n const handleCompanyUpdated = useCallback((eventData: { company: { id: string; name: string; } }) => {\n const { company } = eventData;\n\n setCompanies(prevCompanies => {\n const companyIndex = prevCompanies.findIndex(c => c.value === company.id);\n if (companyIndex === -1) {\n return prevCompanies;\n }\n return prevCompanies.map((c, i) =>\n i === companyIndex ? { ...c, text: company.name } : c\n );\n });\n \n setCurrentCompany({\n text: company.name,\n value: company.id\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/changed', handleCompanyContextRestored, { eager: true });\n const unsubscribeCompanyUpdated = events.on('company/updated', handleCompanyUpdated);\n \n return () => {\n unsubscribeAuth?.off?.();\n unsubscribeRestore?.off?.();\n unsubscribeCompanyUpdated?.off?.();\n };\n }, [handleAuthenticationChange, handleCompanyContextRestored, handleCompanyUpdated]);\n\n return {\n companies,\n currentCompany,\n handleCompanyChange\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 { HTMLAttributes } from 'preact/compat';\nimport { useMemo, useState, useEffect } from 'preact/hooks';\nimport { Container } from '@adobe-commerce/elsie/lib';\nimport { Picker } from '@adobe-commerce/elsie/components';\nimport { events } from '@adobe-commerce/event-bus';\nimport { useCompanyData } from '@/company-switcher/hooks/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 const [isVisible, setIsVisible] = useState(true);\n\n // Memoize the companies array to prevent unnecessary re-renders\n const memoizedCompanies = useMemo(() => companies, [companies]);\n\n // Listen for checkout/initialized and checkout/updated events to hide the picker\n useEffect(() => {\n const hidePickerHandler = () => {\n setIsVisible(false);\n };\n\n const unsubscribeInitialized = events.on('checkout/initialized', hidePickerHandler);\n const unsubscribeUpdated = events.on('checkout/updated', hidePickerHandler);\n\n return () => {\n unsubscribeInitialized?.off();\n unsubscribeUpdated?.off();\n };\n }, []);\n\n // Only render if user has access to multiple companies and picker is visible\n if (companies.length < 2 || !isVisible) {\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","getCompanyHeaderManager","config","groupId","updateCustomerGroup","getGroupHeaderManager","events","clearCompanyContext","handleAuthenticationChange","authenticated","handleCompanyContextRestored","prevCompanies","restoredCompany","company","handleCompanyUpdated","eventData","companyIndex","useEffect","unsubscribeAuth","unsubscribeRestore","unsubscribeCompanyUpdated","_c","CompanySwitcher","ariaLabel","props","isVisible","setIsVisible","memoizedCompanies","useMemo","hidePickerHandler","unsubscribeInitialized","unsubscribeUpdated","jsx","Picker"],"mappings":"uaA6BO,MAAMA,EAAiB,IAA4B,CACxD,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAA0B,CAAA,CAAE,EACxD,CAACC,EAAgBC,CAAiB,EAAIF,EAAwB,CAAE,KAAM,GAAI,MAAO,GAAI,EAMrFG,EAAkBC,EAAY,SAA2B,SAC7D,GAAI,CAEF,MAAMC,EAAmC,MADVC,EAAuB,YAAA,EACgB,uBAAA,EACtEP,EAAaM,EAAY,iBAAiB,GAEtCE,EAAAF,EAAY,iBAAZ,MAAAE,EAA4B,QAAQC,EAAAH,EAAY,iBAAZ,MAAAG,EAA4B,KAClEN,EAAkB,CAChB,KAAMG,EAAY,eAAe,KACjC,MAAOA,EAAY,eAAe,EAAA,CACnC,CAEL,OAASI,EAAK,CACZ,QAAQ,MAAM,+BAAgCA,CAAG,CACnD,CACF,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,EAAwB,MACxBC,GAAA,MAAAA,EAAoB,KACtB,CACF,EAAG,CAAA,CAAE,EAGD/C,EAAU,OAAS,GAAK,CAACyC,EACpB,KAIPO,EAAC,MAAA,CAAK,GAAGR,EACP,SAAAQ,EAACC,EAAA,CACC,QAASN,EACT,MAAOxC,EAAe,MACtB,SAAUS,EACV,aAAY2B,GAAa,iBACzB,mBAAiB,8BAAA,CAAA,EAErB,CAEJ"}
@@ -1,2 +1,18 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
1
17
  export * from './CompanySwitcher';
2
18
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
17
+ export { useCompanyData } from './useCompanyData';
18
+ //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,4 @@
1
- import { UseCompanyDataReturn } from '../../types/company';
1
+ import { UseCompanyDataReturn } from '../types/company';
2
2
 
3
3
  /**
4
4
  * Custom hook that manages company data fetching and state management
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name": "@dropins/storefront-company-switcher", "version": "1.0.1", "@dropins/tools": "^1.3.0", "license": "SEE LICENSE IN LICENSE.md"}
1
+ {"name": "@dropins/storefront-company-switcher", "version": "1.0.2-alpha1000", "@dropins/tools": "1.5.0-beta3", "license": "SEE LICENSE IN LICENSE.md"}
@@ -1,8 +1,8 @@
1
- import { FunctionComponent } from 'preact';
1
+ import { FunctionComponent, ComponentChildren } from 'preact';
2
2
 
3
- interface CartProviderProps {
4
- children?: any;
3
+ interface ProviderProps {
4
+ children?: ComponentChildren;
5
5
  }
6
- export declare const Provider: FunctionComponent<CartProviderProps>;
6
+ export declare const Provider: FunctionComponent<ProviderProps>;
7
7
  export {};
8
8
  //# sourceMappingURL=Provider.d.ts.map
package/render/index.d.ts CHANGED
@@ -1,2 +1,19 @@
1
+ /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
5
+ * Copyright 2025 Adobe
6
+ * All Rights Reserved.
7
+ *
8
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
16
+ *******************************************************************/
1
17
  export * from './render';
18
+ export * from './Provider';
2
19
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,8 @@
1
1
  import { Render } from '@dropins/tools/types/elsie/src/lib';
2
2
 
3
+ /**
4
+ * Render instance for the company switcher drop-in.
5
+ * Wraps the Provider component to handle initialization and rendering.
6
+ */
3
7
  export declare const render: Render;
4
8
  //# sourceMappingURL=render.d.ts.map
package/render.js CHANGED
@@ -1,4 +1,4 @@
1
1
  /*! Copyright 2025 Adobe
2
2
  All Rights Reserved. */
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{x as render};
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
package/render.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"render.js","sources":["/@dropins/storefront-company-switcher/src/render/Provider.tsx","/@dropins/storefront-company-switcher/src/render/render.tsx"],"sourcesContent":["import { FunctionComponent } from 'preact';\nimport { useState, useEffect } from 'preact/hooks';\nimport { UIProvider } from '@adobe-commerce/elsie/components';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { events } from '@adobe-commerce/event-bus';\n\nimport en_US from '../i18n/en_US.json';\n\n// Langs\nconst langDefinitions = {\n default: en_US,\n};\n\ninterface CartProviderProps {\n children?: any;\n}\n\nexport const Provider: FunctionComponent<CartProviderProps> = ({\n children,\n}) => {\n const [lang, setLang] = useState<Lang>('en_US');\n\n // Events\n useEffect(() => {\n const localeEvent = events.on(\n 'locale',\n (locale: string) => {\n setLang(locale as Lang);\n },\n { eager: true }\n );\n return () => {\n localeEvent?.off();\n };\n }, []);\n\n return (\n <UIProvider lang={lang} langDefinitions={langDefinitions}>\n {children}\n </UIProvider>\n );\n};\n","import { Render } from '@adobe-commerce/elsie/lib';\nimport { Provider } from './Provider';\n\nexport const render = new Render(<Provider />);\n"],"names":["langDefinitions","en_US","Provider","children","lang","setLang","useState","useEffect","localeEvent","events","locale","jsx","UIProvider","render","Render"],"mappings":"kTASMA,EAAkB,CACtB,QAASC,CACX,EAMaC,EAAiD,CAAC,CAC7D,SAAAC,CACF,IAAM,CACJ,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAAe,OAAO,EAG9C,OAAAC,EAAU,IAAM,CACd,MAAMC,EAAcC,EAAO,GACzB,SACCC,GAAmB,CAClBL,EAAQK,CAAc,CACxB,EACA,CAAE,MAAO,EAAA,CAAK,EAEhB,MAAO,IAAM,CACXF,GAAA,MAAAA,EAAa,KACf,CACF,EAAG,CAAA,CAAE,EAGHG,EAACC,EAAA,CAAW,KAAAR,EAAY,gBAAAJ,EACrB,SAAAG,CAAA,CACH,CAEJ,ECtCaU,EAAS,IAAIC,EAAOH,EAACT,IAAS,CAAE"}
1
+ {"version":3,"file":"render.js","sources":["/@dropins/storefront-company-switcher/src/render/Provider.tsx","/@dropins/storefront-company-switcher/src/render/render.tsx"],"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 *******************************************************************/\n\nimport { FunctionComponent, ComponentChildren } from 'preact';\nimport { useState, useEffect } from 'preact/hooks';\nimport { UIProvider } from '@adobe-commerce/elsie/components';\nimport { Lang } from '@adobe-commerce/elsie/i18n';\nimport { events } from '@adobe-commerce/event-bus';\nimport en_US from '@/company-switcher/i18n/en_US.json';\n\n// Langs\nconst langDefinitions = {\n default: en_US,\n};\n\ninterface ProviderProps {\n children?: ComponentChildren;\n}\n\nexport const Provider: FunctionComponent<ProviderProps> = ({\n children,\n}) => {\n const [lang, setLang] = useState<Lang>('en_US');\n\n // Events\n useEffect(() => {\n const localeEvent = events.on(\n 'locale',\n (locale: string) => {\n setLang(locale as Lang);\n },\n { eager: true }\n );\n return () => {\n localeEvent?.off();\n };\n }, []);\n\n return (\n <UIProvider lang={lang} langDefinitions={langDefinitions}>\n {children}\n </UIProvider>\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 { Render } from '@adobe-commerce/elsie/lib';\nimport { Provider } from '@/company-switcher/render/Provider';\n\n/**\n * Render instance for the company switcher drop-in.\n * Wraps the Provider component to handle initialization and rendering.\n */\nexport const render = new Render(<Provider />);\n"],"names":["langDefinitions","en_US","Provider","children","lang","setLang","useState","useEffect","localeEvent","events","locale","jsx","UIProvider","render","Render"],"mappings":"kTAyBMA,EAAkB,CACtB,QAASC,CACX,EAMaC,EAA6C,CAAC,CACzD,SAAAC,CACF,IAAM,CACJ,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAAe,OAAO,EAG9C,OAAAC,EAAU,IAAM,CACd,MAAMC,EAAcC,EAAO,GACzB,SACCC,GAAmB,CAClBL,EAAQK,CAAc,CACxB,EACA,CAAE,MAAO,EAAA,CAAK,EAEhB,MAAO,IAAM,CACXF,GAAA,MAAAA,EAAa,KACf,CACF,EAAG,CAAA,CAAE,EAGHG,EAACC,EAAA,CAAW,KAAAR,EAAY,gBAAAJ,EACrB,SAAAG,CAAA,CACH,CAEJ,ECjCaU,EAAS,IAAIC,EAAOH,EAACT,IAAS,CAAE"}
@@ -1,10 +1,18 @@
1
1
  /********************************************************************
2
+ * ADOBE CONFIDENTIAL
3
+ * __________________
4
+ *
2
5
  * Copyright 2025 Adobe
3
6
  * All Rights Reserved.
4
7
  *
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
+ * NOTICE: All information contained herein is, and remains
9
+ * the property of Adobe and its suppliers, if any. The intellectual
10
+ * and technical concepts contained herein are proprietary to Adobe
11
+ * and its suppliers and are protected by all applicable intellectual
12
+ * property laws, including trade secret and copyright laws.
13
+ * Dissemination of this information or reproduction of this material
14
+ * is strictly forbidden unless prior written permission is obtained
15
+ * from Adobe.
8
16
  *******************************************************************/
9
17
  /**
10
18
  * Represents a company entity
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map