@dropins/storefront-company-switcher 1.2.0-beta.0 → 1.2.0-beta.2
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.
- package/CHANGELOG.md +12 -0
- package/api.js +4 -20
- package/api.js.map +1 -1
- package/containers/CompanySwitcher.js +1 -1
- package/containers/CompanySwitcher.js.map +1 -1
- package/fragments.js +17 -1
- package/fragments.js.map +1 -1
- package/package.json +1 -1
- package/render.js +1 -1
- package/render.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @dropins/storefront-company-switcher
|
|
2
2
|
|
|
3
|
+
## 1.2.0-beta.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4ba4949: Bump @adobe-commerce/elsie to v1.9.0-beta.3
|
|
8
|
+
|
|
9
|
+
## 1.2.0-beta.1
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 46ca833: Removed the `engines.node` constraint from `package.json`. This package targets browser environments exclusively and does not depend on a specific Node.js runtime version. The package is now built and distributed using Node.js 22 LTS.
|
|
14
|
+
|
|
3
15
|
## 1.2.0-beta.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/api.js
CHANGED
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
/*! Copyright 2026 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
var S=Object.defineProperty;var M=(s,e,r)=>e in s?S(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var o=(s,e,r)=>M(s,typeof e!="symbol"?e+"":e,r);import{
|
|
4
|
-
fragment COMPANY_FRAGMENT on Company {
|
|
5
|
-
name
|
|
6
|
-
id
|
|
7
|
-
status
|
|
8
|
-
}
|
|
9
|
-
`,A=`
|
|
10
|
-
fragment CUSTOMER_FRAGMENT on Customer {
|
|
11
|
-
companies(input: { pageSize: $pageSize }) {
|
|
12
|
-
items {
|
|
13
|
-
name
|
|
14
|
-
id
|
|
15
|
-
status
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
`,R=`
|
|
3
|
+
var S=Object.defineProperty;var M=(s,e,r)=>e in s?S(s,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[e]=r;var o=(s,e,r)=>M(s,typeof e!="symbol"?e+"":e,r);import{CUSTOMER_FRAGMENT as E,COMPANY_FRAGMENT as T}from"./fragments.js";import{FetchGraphQL as O}from"@dropins/tools/fetch-graphql.js";import{Initializer as I}from"@dropins/tools/lib.js";import{events as d}from"@dropins/tools/event-bus.js";class _{constructor(){o(this,"companyHeaderSet",!1);o(this,"companyHeaderAppliers",[]);o(this,"companyHeaderRemovers",[]);o(this,"headerKey");this.headerKey=g.getConfig().companyHeader,this.setFetchGraphQlModules(g.getConfig().fetchGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){this.companyHeaderAppliers=[],this.companyHeaderRemovers=[],e.forEach(r=>{this.companyHeaderAppliers.push((t,a)=>r.setFetchGraphQlHeader(t,a)),this.companyHeaderRemovers.push(t=>r.removeFetchGraphQlHeader(t))})}setCompanyHeaders(e){if(e===null){this.removeCompanyHeaders();return}this.companyHeaderAppliers.forEach(r=>{r(this.headerKey,e)}),this.companyHeaderSet=!0}removeCompanyHeaders(){this.companyHeaderRemovers.forEach(e=>{e(this.headerKey)}),this.companyHeaderSet=!1}isCompanyHeaderSet(){return this.companyHeaderSet}}let C=null;const p=()=>(C||(C=new _),C);class A{constructor(){o(this,"groupHeaderSet",!1);o(this,"groupHeaderAppliers",[]);o(this,"groupHeaderRemovers",[]);o(this,"headerKey");o(this,"defaultNLICustomerGroupId","b6589fc6ab0dc82cf12099d1c2d40ab994e8410c");this.headerKey=g.getConfig().customerGroupHeader,this.setFetchGraphQlModules(g.getConfig().groupGraphQlModules)}setHeaderKey(e){this.headerKey=e}setFetchGraphQlModules(e){e.forEach(r=>{this.groupHeaderAppliers.push((t,a)=>r.setFetchGraphQlHeader(t,a)),this.groupHeaderRemovers.push(t=>r.setFetchGraphQlHeader(t,this.defaultNLICustomerGroupId))})}setGroupHeaders(e){this.removeGroupHeaders(),e!==null&&(this.groupHeaderAppliers.forEach(r=>{r(this.headerKey,e)}),this.groupHeaderSet=!0)}removeGroupHeaders(){this.groupHeaderRemovers.forEach(e=>{e(this.headerKey)}),this.groupHeaderSet=!1}isGroupHeaderSet(){return this.groupHeaderSet}}let l=null;const h=()=>(l||(l=new A),l),R=`
|
|
20
4
|
query GET_CUSTOMER_COMPANIES($pageSize: Int) {
|
|
21
5
|
customer {
|
|
22
6
|
...CUSTOMER_FRAGMENT
|
|
@@ -29,13 +13,13 @@ var S=Object.defineProperty;var M=(s,e,r)=>e in s?S(s,e,{enumerable:!0,configura
|
|
|
29
13
|
}
|
|
30
14
|
}
|
|
31
15
|
|
|
32
|
-
${
|
|
33
|
-
${
|
|
16
|
+
${E}
|
|
17
|
+
${T}
|
|
34
18
|
`,N=`
|
|
35
19
|
query GET_CUSTOMER_GROUP {
|
|
36
20
|
customerGroup {
|
|
37
21
|
uid
|
|
38
22
|
}
|
|
39
23
|
}
|
|
40
|
-
`,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),a=>a.charCodeAt(0)),t=await crypto.subtle.digest("SHA-1",r);return Array.from(new Uint8Array(t)).map(a=>a.toString(16).padStart(2,"0")).join("")}isUserAuthenticated(){var e;return!!((e=
|
|
24
|
+
`,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),a=>a.charCodeAt(0)),t=await crypto.subtle.digest("SHA-1",r);return Array.from(new Uint8Array(t)).map(a=>a.toString(16).padStart(2,"0")).join("")}isUserAuthenticated(){var e;return!!((e=K().fetchGraphQlHeaders)!=null&&e.Authorization)}resetCache(){this.cache=null}async updateCustomerGroup(){if(!this.isUserAuthenticated())return null;try{const e=await G(N);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(e=100){if(this.cache)return this.cache;if(!this.isUserAuthenticated())return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;try{const r=await G(R,{variables:{pageSize:e}});if(r.errors)return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;const t=r.data,a=await this.processCustomerGroupId(r.data.customerGroup.uid),f=t.customer.companies.items.filter(c=>c.status==="APPROVED"||c.status==="BLOCKED").map(this.transformCompanyToOption);return this.cache={currentCompany:t.company,customerCompanies:f,customerGroupId:a},this.cache}catch(r){return console.error(r),this.EMPTY_CUSTOMER_COMPANY_CONTEXT}}};o(n,"instance");let m=n;const v=(s=100)=>m.getInstance().getCustomerCompanyInfo(s),w=()=>m.getInstance().updateCustomerGroup(),u=new I({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"};u.config.setConfig({...e,...s});const r=sessionStorage.getItem(u.config.getConfig().groupSessionStorageKey),t=sessionStorage.getItem(u.config.getConfig().companySessionStorageKey);t&&!p().isCompanyHeaderSet()&&(p().setCompanyHeaders(t),d.emit("companyContext/changed",t)),r&&!h().isGroupHeaderSet()&&h().setGroupHeaders(r),d.on("authenticated",async a=>{const i=u.config.getConfig();if(!a)sessionStorage.removeItem(i.companySessionStorageKey),sessionStorage.removeItem(i.groupSessionStorageKey),p().removeCompanyHeaders(),h().removeGroupHeaders(),d.emit("companyContext/changed",null);else{if(sessionStorage.getItem(i.companySessionStorageKey)||p().isCompanyHeaderSet())return;const c=await v();if(c.customerCompanies.length<2)return;const y=c.currentCompany.id,H=c.customerGroupId;p().setCompanyHeaders(y),h().setGroupHeaders(H),sessionStorage.setItem(i.companySessionStorageKey,y),sessionStorage.setItem(i.groupSessionStorageKey,H),d.emit("companyContext/changed",y)}},{eager:!0})},listeners:()=>[]}),g=u.config,{setEndpoint:X,setFetchGraphQlHeader:b,removeFetchGraphQlHeader:z,setFetchGraphQlHeaders:D,fetchGraphQl:G,getConfig:K}=new O().getMethods();export{m as CustomerCompanyContext,g as config,G as fetchGraphQl,p as getCompanyHeaderManager,K as getConfig,v as getCustomerCompanyInfo,h as getGroupHeaderManager,u as initialize,z as removeFetchGraphQlHeader,X as setEndpoint,b as setFetchGraphQlHeader,D as setFetchGraphQlHeaders,w as updateCustomerGroup};
|
|
41
25
|
//# sourceMappingURL=api.js.map
|
package/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sources":["/@dropins/storefront-company-switcher/src/api/setCompanyHeaders/setCompanyHeaders.ts","/@dropins/storefront-company-switcher/src/api/setGroupHeaders/setGroupHeaders.ts","/@dropins/storefront-company-switcher/src/api/graphql/CompanyFragment.graphql.ts","/@dropins/storefront-company-switcher/src/api/graphql/CustomerFragment.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","/@dropins/storefront-company-switcher/src/api/initialize/initialize.ts","/@dropins/storefront-company-switcher/src/api/fetch-graphql/fetch-graphql.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader, removeFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages company-specific headers for GraphQL requests.\n * Singleton class that handles setting and removing company headers across multiple GraphQL modules.\n */\nclass CompanyHeaderManager {\n private companyHeaderSet: boolean = false;\n private companyHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private companyHeaderRemovers: typeof removeFetchGraphQlHeader[] = [];\n private headerKey: string;\n\n constructor() {\n this.headerKey = config.getConfig().companyHeader;\n this.setFetchGraphQlModules(config.getConfig().fetchGraphQlModules);\n }\n\n /**\n * Sets the header key used for company identification\n * @param headerKey - The header name to use for company ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have company headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n this.companyHeaderAppliers = [];\n this.companyHeaderRemovers = [];\n modules.forEach((module: FetchGraphQL) => {\n this.companyHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.companyHeaderRemovers.push((key: string) => \n module.removeFetchGraphQlHeader(key)\n );\n });\n }\n\n /**\n * Sets company headers for all configured GraphQL modules\n * @param companyId - The company ID to set in headers, or null to remove headers\n */\n public setCompanyHeaders(companyId: string | null): void {\n if (companyId === null) {\n this.removeCompanyHeaders();\n return;\n }\n this.companyHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, companyId);\n });\n this.companyHeaderSet = true;\n }\n\n /**\n * Removes company headers from all configured GraphQL modules\n */\n public removeCompanyHeaders(): void {\n this.companyHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.companyHeaderSet = false;\n }\n\n /**\n * Checks if company headers are currently set\n * @returns true if company headers are set, false otherwise\n */\n public isCompanyHeaderSet(): boolean {\n return this.companyHeaderSet;\n }\n}\n\nlet _companyHeaderManager: CompanyHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of CompanyHeaderManager\n * @returns The CompanyHeaderManager instance\n */\nexport const getCompanyHeaderManager = () => {\n if (!_companyHeaderManager) {\n _companyHeaderManager = new CompanyHeaderManager();\n }\n return _companyHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages customer group headers for GraphQL requests.\n * Singleton class that handles setting and removing group headers across multiple GraphQL modules.\n */\nclass GroupHeaderManager {\n private groupHeaderSet: boolean = false;\n private groupHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private groupHeaderRemovers: ((key: string) => void)[] = [];\n private headerKey: string;\n private defaultNLICustomerGroupId = 'b6589fc6ab0dc82cf12099d1c2d40ab994e8410c';\n\n\n constructor() {\n this.headerKey = config.getConfig().customerGroupHeader;\n this.setFetchGraphQlModules(config.getConfig().groupGraphQlModules);\n }\n\n /**\n * Sets the header key used for customer group identification\n * @param headerKey - The header name to use for group ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have group headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n modules.forEach((module: FetchGraphQL) => {\n this.groupHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.groupHeaderRemovers.push((key: string) => \n module.setFetchGraphQlHeader(key, this.defaultNLICustomerGroupId)\n );\n });\n }\n\n /**\n * Sets customer group headers for all configured GraphQL modules.\n * Always removes existing headers first before setting new ones.\n * @param groupId - The group ID to set in headers, or null to only remove headers\n */\n public setGroupHeaders(groupId: string | null): void {\n this.removeGroupHeaders();\n if (groupId === null) {\n return;\n }\n this.groupHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, groupId);\n });\n this.groupHeaderSet = true;\n }\n\n /**\n * Removes customer group headers from all configured GraphQL modules\n */\n public removeGroupHeaders(): void {\n this.groupHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.groupHeaderSet = false;\n }\n\n /**\n * Checks if customer group headers are currently set\n * @returns true if group headers are set, false otherwise\n */\n public isGroupHeaderSet(): boolean {\n return this.groupHeaderSet;\n }\n}\n\nlet _groupHeaderManager: GroupHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of GroupHeaderManager\n * @returns The GroupHeaderManager instance\n */\nexport const getGroupHeaderManager = () => {\n if (!_groupHeaderManager) {\n _groupHeaderManager = new GroupHeaderManager();\n }\n return _groupHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nexport const COMPANY_FRAGMENT = /* GraphQL */ `\n fragment COMPANY_FRAGMENT on Company {\n name\n id\n status\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 CUSTOMER_FRAGMENT = /* GraphQL */ `\n fragment CUSTOMER_FRAGMENT on Customer {\n companies(input: { pageSize: $pageSize }) {\n items {\n name\n id\n status\n }\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 { COMPANY_FRAGMENT, CUSTOMER_FRAGMENT } from '@/company-switcher/api/fragments';\n\nexport const GET_CUSTOMER_COMPANY_CONTEXT = /* GraphQL */ `\n query GET_CUSTOMER_COMPANIES($pageSize: Int) {\n customer {\n ...CUSTOMER_FRAGMENT\n }\n company {\n ...COMPANY_FRAGMENT\n }\n customerGroup {\n uid\n }\n }\n\n ${CUSTOMER_FRAGMENT}\n ${COMPANY_FRAGMENT}\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(pageSize = 100): 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, { variables: { pageSize } }));\n if (response.errors) {\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n\n const data = response.data;\n const customerGroup = await this.processCustomerGroupId(response.data.customerGroup.uid);\n // Whitelist approach: only allow APPROVED and BLOCKED companies\n // BLOCKED companies allow users to log in and view but not perform actions\n const activeCompanies = data.customer.companies.items.filter(\n company => company.status === 'APPROVED' || company.status === 'BLOCKED'\n );\n const customerCompanies = activeCompanies.map(this.transformCompanyToOption);\n\n this.cache = {\n currentCompany: data.company,\n customerCompanies,\n customerGroupId: customerGroup\n }\n return this.cache;\n } catch (e) {\n console.error(e);\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n }\n}\n\nexport const getCustomerCompanyInfo = (pageSize = 100): Promise<CustomerCompanyInfo> => {\n return CustomerCompanyContext.getInstance().getCustomerCompanyInfo(pageSize);\n};\n\nexport const updateCustomerGroup = (): Promise<string | null> => {\n return CustomerCompanyContext.getInstance().updateCustomerGroup();\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"],"names":["CompanyHeaderManager","__publicField","config","headerKey","modules","module","key","value","companyId","setFn","removeFn","_companyHeaderManager","getCompanyHeaderManager","GroupHeaderManager","groupId","_groupHeaderManager","getGroupHeaderManager","COMPANY_FRAGMENT","CUSTOMER_FRAGMENT","GET_CUSTOMER_COMPANY_CONTEXT","GET_CUSTOMER_GROUP_CONTEXT","_CustomerCompanyContext","company","base64String","decoded","c","hashBuffer","b","_a","getConfig","response","fetchGraphQl","customerGroupId","pageSize","data","customerGroup","customerCompanies","e","CustomerCompanyContext","getCustomerCompanyInfo","updateCustomerGroup","initialize","Initializer","defaultConfig","events","authenticated","companyInfo","currentCompanyId","setEndpoint","setFetchGraphQlHeader","removeFetchGraphQlHeader","setFetchGraphQlHeaders","FetchGraphQL"],"mappings":"4UAuBA,MAAMA,CAAqB,CAMzB,aAAc,CALNC,EA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MAAMC,EAAmBD,EAAY,eAAe,GAC9ChC,EAAUgC,EAAY,gBAC5BlC,EAAA,EAA0B,kBAAkBmC,CAAgB,EAC5D/B,EAAA,EAAwB,gBAAgBF,CAAO,EAC/C,eAAe,QAAQZ,EAAO,yBAA0B6C,CAAgB,EACxE,eAAe,QAAQ7C,EAAO,uBAAwBY,CAAO,EAC7D8B,EAAO,KAAK,yBAA0BG,CAAgB,CACxD,CACF,EAAG,CAAE,MAAO,GAAM,CACpB,EACA,UAAW,IAAM,CAAA,CACnB,CAAC,EAMY7C,EAASuC,EAAW,OCnFpB,CAEX,YAAAO,EAEA,sBAAAC,EAEA,yBAAAC,EAEA,uBAAAC,EAEA,aAAApB,EAEA,UAAAF,CACF,EAAI,IAAIuB,EAAA,EAAe,WAAA"}
|
|
1
|
+
{"version":3,"file":"api.js","sources":["/@dropins/storefront-company-switcher/src/api/setCompanyHeaders/setCompanyHeaders.ts","/@dropins/storefront-company-switcher/src/api/setGroupHeaders/setGroupHeaders.ts","/@dropins/storefront-company-switcher/src/api/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","/@dropins/storefront-company-switcher/src/api/initialize/initialize.ts","/@dropins/storefront-company-switcher/src/api/fetch-graphql/fetch-graphql.ts"],"sourcesContent":["/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader, removeFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages company-specific headers for GraphQL requests.\n * Singleton class that handles setting and removing company headers across multiple GraphQL modules.\n */\nclass CompanyHeaderManager {\n private companyHeaderSet: boolean = false;\n private companyHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private companyHeaderRemovers: typeof removeFetchGraphQlHeader[] = [];\n private headerKey: string;\n\n constructor() {\n this.headerKey = config.getConfig().companyHeader;\n this.setFetchGraphQlModules(config.getConfig().fetchGraphQlModules);\n }\n\n /**\n * Sets the header key used for company identification\n * @param headerKey - The header name to use for company ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have company headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n this.companyHeaderAppliers = [];\n this.companyHeaderRemovers = [];\n modules.forEach((module: FetchGraphQL) => {\n this.companyHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.companyHeaderRemovers.push((key: string) => \n module.removeFetchGraphQlHeader(key)\n );\n });\n }\n\n /**\n * Sets company headers for all configured GraphQL modules\n * @param companyId - The company ID to set in headers, or null to remove headers\n */\n public setCompanyHeaders(companyId: string | null): void {\n if (companyId === null) {\n this.removeCompanyHeaders();\n return;\n }\n this.companyHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, companyId);\n });\n this.companyHeaderSet = true;\n }\n\n /**\n * Removes company headers from all configured GraphQL modules\n */\n public removeCompanyHeaders(): void {\n this.companyHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.companyHeaderSet = false;\n }\n\n /**\n * Checks if company headers are currently set\n * @returns true if company headers are set, false otherwise\n */\n public isCompanyHeaderSet(): boolean {\n return this.companyHeaderSet;\n }\n}\n\nlet _companyHeaderManager: CompanyHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of CompanyHeaderManager\n * @returns The CompanyHeaderManager instance\n */\nexport const getCompanyHeaderManager = () => {\n if (!_companyHeaderManager) {\n _companyHeaderManager = new CompanyHeaderManager();\n }\n return _companyHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\nimport type { FetchGraphQL, setFetchGraphQlHeader } from '@adobe-commerce/fetch-graphql';\nimport { config } from '@/company-switcher/api';\n\n/**\n * Manages customer group headers for GraphQL requests.\n * Singleton class that handles setting and removing group headers across multiple GraphQL modules.\n */\nclass GroupHeaderManager {\n private groupHeaderSet: boolean = false;\n private groupHeaderAppliers: typeof setFetchGraphQlHeader[] = [];\n private groupHeaderRemovers: ((key: string) => void)[] = [];\n private headerKey: string;\n private defaultNLICustomerGroupId = 'b6589fc6ab0dc82cf12099d1c2d40ab994e8410c';\n\n\n constructor() {\n this.headerKey = config.getConfig().customerGroupHeader;\n this.setFetchGraphQlModules(config.getConfig().groupGraphQlModules);\n }\n\n /**\n * Sets the header key used for customer group identification\n * @param headerKey - The header name to use for group ID\n */\n public setHeaderKey(headerKey: string): void {\n this.headerKey = headerKey;\n }\n\n /**\n * Configures GraphQL modules that will have group headers applied\n * @param modules - Array of GraphQL modules with header management functions\n */\n public setFetchGraphQlModules(modules: FetchGraphQL[]): void {\n modules.forEach((module: FetchGraphQL) => {\n this.groupHeaderAppliers.push((key: string, value: string) => \n module.setFetchGraphQlHeader(key, value)\n );\n this.groupHeaderRemovers.push((key: string) => \n module.setFetchGraphQlHeader(key, this.defaultNLICustomerGroupId)\n );\n });\n }\n\n /**\n * Sets customer group headers for all configured GraphQL modules.\n * Always removes existing headers first before setting new ones.\n * @param groupId - The group ID to set in headers, or null to only remove headers\n */\n public setGroupHeaders(groupId: string | null): void {\n this.removeGroupHeaders();\n if (groupId === null) {\n return;\n }\n this.groupHeaderAppliers.forEach((setFn) => {\n setFn(this.headerKey, groupId);\n });\n this.groupHeaderSet = true;\n }\n\n /**\n * Removes customer group headers from all configured GraphQL modules\n */\n public removeGroupHeaders(): void {\n this.groupHeaderRemovers.forEach((removeFn) => {\n removeFn(this.headerKey);\n });\n this.groupHeaderSet = false;\n }\n\n /**\n * Checks if customer group headers are currently set\n * @returns true if group headers are set, false otherwise\n */\n public isGroupHeaderSet(): boolean {\n return this.groupHeaderSet;\n }\n}\n\nlet _groupHeaderManager: GroupHeaderManager | null = null;\n\n/**\n * Gets the singleton instance of GroupHeaderManager\n * @returns The GroupHeaderManager instance\n */\nexport const getGroupHeaderManager = () => {\n if (!_groupHeaderManager) {\n _groupHeaderManager = new GroupHeaderManager();\n }\n return _groupHeaderManager;\n};\n","/********************************************************************\n * ADOBE CONFIDENTIAL\n * __________________\n *\n * Copyright 2025 Adobe\n * All Rights Reserved.\n *\n * NOTICE: All information contained herein is, and remains\n * the property of Adobe and its suppliers, if any. The intellectual\n * and technical concepts contained herein are proprietary to Adobe\n * and its suppliers and are protected by all applicable intellectual\n * property laws, including trade secret and copyright laws.\n * Dissemination of this information or reproduction of this material\n * is strictly forbidden unless prior written permission is obtained\n * from Adobe.\n *******************************************************************/\n\nimport { COMPANY_FRAGMENT, CUSTOMER_FRAGMENT } from '@/company-switcher/api/fragments';\n\nexport const GET_CUSTOMER_COMPANY_CONTEXT = /* GraphQL */ `\n query GET_CUSTOMER_COMPANIES($pageSize: Int) {\n customer {\n ...CUSTOMER_FRAGMENT\n }\n company {\n ...COMPANY_FRAGMENT\n }\n customerGroup {\n uid\n }\n }\n\n ${CUSTOMER_FRAGMENT}\n ${COMPANY_FRAGMENT}\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(pageSize = 100): 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, { variables: { pageSize } }));\n if (response.errors) {\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n\n const data = response.data;\n const customerGroup = await this.processCustomerGroupId(response.data.customerGroup.uid);\n // Whitelist approach: only allow APPROVED and BLOCKED companies\n // BLOCKED companies allow users to log in and view but not perform actions\n const activeCompanies = data.customer.companies.items.filter(\n company => company.status === 'APPROVED' || company.status === 'BLOCKED'\n );\n const customerCompanies = activeCompanies.map(this.transformCompanyToOption);\n\n this.cache = {\n currentCompany: data.company,\n customerCompanies,\n customerGroupId: customerGroup\n }\n return this.cache;\n } catch (e) {\n console.error(e);\n return this.EMPTY_CUSTOMER_COMPANY_CONTEXT;\n }\n }\n}\n\nexport const getCustomerCompanyInfo = (pageSize = 100): Promise<CustomerCompanyInfo> => {\n return CustomerCompanyContext.getInstance().getCustomerCompanyInfo(pageSize);\n};\n\nexport const updateCustomerGroup = (): Promise<string | null> => {\n return CustomerCompanyContext.getInstance().updateCustomerGroup();\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"],"names":["CompanyHeaderManager","__publicField","config","headerKey","modules","module","key","value","companyId","setFn","removeFn","_companyHeaderManager","getCompanyHeaderManager","GroupHeaderManager","groupId","_groupHeaderManager","getGroupHeaderManager","GET_CUSTOMER_COMPANY_CONTEXT","CUSTOMER_FRAGMENT","COMPANY_FRAGMENT","GET_CUSTOMER_GROUP_CONTEXT","_CustomerCompanyContext","company","base64String","decoded","c","hashBuffer","b","_a","getConfig","response","fetchGraphQl","customerGroupId","pageSize","data","customerGroup","customerCompanies","e","CustomerCompanyContext","getCustomerCompanyInfo","updateCustomerGroup","initialize","Initializer","defaultConfig","events","authenticated","companyInfo","currentCompanyId","setEndpoint","setFetchGraphQlHeader","removeF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9ChC,EAAUgC,EAAY,gBAC5BlC,EAAA,EAA0B,kBAAkBmC,CAAgB,EAC5D/B,EAAA,EAAwB,gBAAgBF,CAAO,EAC/C,eAAe,QAAQZ,EAAO,yBAA0B6C,CAAgB,EACxE,eAAe,QAAQ7C,EAAO,uBAAwBY,CAAO,EAC7D8B,EAAO,KAAK,yBAA0BG,CAAgB,CACxD,CACF,EAAG,CAAE,MAAO,GAAM,CACpB,EACA,UAAW,IAAM,CAAA,CACnB,CAAC,EAMY7C,EAASuC,EAAW,OCnFpB,CAEX,YAAAO,EAEA,sBAAAC,EAEA,yBAAAC,EAEA,uBAAAC,EAEA,aAAApB,EAEA,UAAAF,CACF,EAAI,IAAIuB,EAAA,EAAe,WAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2026 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as I}from"@dropins/tools/preact-jsx-runtime.js";import{useState as v,useCallback as f,useEffect as H,useMemo as w}from"@dropins/tools/preact-hooks.js";import{Picker as K}from"@dropins/tools/components.js";import{events as d}from"@dropins/tools/event-bus.js";import{CustomerCompanyContext as k,getCompanyHeaderManager as G,config as S,updateCustomerGroup as M,getGroupHeaderManager as D}from"../api.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";const P=({onCompanyChange:c,pageSize:C=100}={})=>{const[l,s]=v([]),[g,r]=v({text:"",value:""}),u=f(async()=>{var e,n;try{const o=await k.getInstance().getCustomerCompanyInfo(C);s(o.customerCompanies),(e=o.currentCompany)!=null&&e.name&&((n=o.currentCompany)!=null&&n.id)&&r({text:o.currentCompany.name,value:o.currentCompany.id})}catch(t){console.error("Failed to load company data:",t)}},[C]),h=f(async e=>{const t=e.target.value,o=l.find(p=>p.value===t);o&&r(o),G().setCompanyHeaders(t),t?sessionStorage.setItem(S.getConfig().companySessionStorageKey,t):sessionStorage.removeItem(S.getConfig().companySessionStorageKey);const a=await M();D().setGroupHeaders(a),a?sessionStorage.setItem(S.getConfig().groupSessionStorageKey,a):sessionStorage.removeItem(S.getConfig().groupSessionStorageKey),c==null||c({id:t,name:(o==null?void 0:o.text)||""}),d.emit("companyContext/changed",t)},[l,c]),m=f(()=>{k.getInstance().resetCache(),s([]),r({text:"",value:""})},[]),x=f(e=>{e?u():m()},[u,m]),y=f(e=>{if(!e){m();return}s(n=>{const t=n.find(o=>o.value===e);return t&&r(t),n})},[m,s,r]),i=f(e=>{const{company:n}=e;s(t=>{const o=t.findIndex(a=>a.value===n.id);return o===-1?t:t.map((a,p)=>p===o?{...a,text:n.name}:a)}),r({text:n.name,value:n.id})},[]);return H(()=>{const e=d.on("authenticated",x,{eager:!0}),n=d.on("companyContext/changed",y,{eager:!0}),t=d.on("company/updated",i);return()=>{var o,a,p;(o=e==null?void 0:e.off)==null||o.call(e),(a=n==null?void 0:n.off)==null||a.call(n),(p=t==null?void 0:t.off)==null||p.call(t)}},[x,y,i]),{companies:l,currentCompany:g,handleCompanyChange:h}},
|
|
3
|
+
import{jsx as I}from"@dropins/tools/preact-jsx-runtime.js";import{useState as v,useCallback as f,useEffect as H,useMemo as w}from"@dropins/tools/preact-hooks.js";import{Picker as K}from"@dropins/tools/components.js";import{events as d}from"@dropins/tools/event-bus.js";import{CustomerCompanyContext as k,getCompanyHeaderManager as G,config as S,updateCustomerGroup as M,getGroupHeaderManager as D}from"../api.js";import"../fragments.js";import"@dropins/tools/fetch-graphql.js";import"@dropins/tools/lib.js";const P=({onCompanyChange:c,pageSize:C=100}={})=>{const[l,s]=v([]),[g,r]=v({text:"",value:""}),u=f(async()=>{var e,n;try{const o=await k.getInstance().getCustomerCompanyInfo(C);s(o.customerCompanies),(e=o.currentCompany)!=null&&e.name&&((n=o.currentCompany)!=null&&n.id)&&r({text:o.currentCompany.name,value:o.currentCompany.id})}catch(t){console.error("Failed to load company data:",t)}},[C]),h=f(async e=>{const t=e.target.value,o=l.find(p=>p.value===t);o&&r(o),G().setCompanyHeaders(t),t?sessionStorage.setItem(S.getConfig().companySessionStorageKey,t):sessionStorage.removeItem(S.getConfig().companySessionStorageKey);const a=await M();D().setGroupHeaders(a),a?sessionStorage.setItem(S.getConfig().groupSessionStorageKey,a):sessionStorage.removeItem(S.getConfig().groupSessionStorageKey),c==null||c({id:t,name:(o==null?void 0:o.text)||""}),d.emit("companyContext/changed",t)},[l,c]),m=f(()=>{k.getInstance().resetCache(),s([]),r({text:"",value:""})},[]),x=f(e=>{e?u():m()},[u,m]),y=f(e=>{if(!e){m();return}s(n=>{const t=n.find(o=>o.value===e);return t&&r(t),n})},[m,s,r]),i=f(e=>{const{company:n}=e;s(t=>{const o=t.findIndex(a=>a.value===n.id);return o===-1?t:t.map((a,p)=>p===o?{...a,text:n.name}:a)}),r({text:n.name,value:n.id})},[]);return H(()=>{const e=d.on("authenticated",x,{eager:!0}),n=d.on("companyContext/changed",y,{eager:!0}),t=d.on("company/updated",i);return()=>{var o,a,p;(o=e==null?void 0:e.off)==null||o.call(e),(a=n==null?void 0:n.off)==null||a.call(n),(p=t==null?void 0:t.off)==null||p.call(t)}},[x,y,i]),{companies:l,currentCompany:g,handleCompanyChange:h}},L=({ariaLabel:c,onCompanyChange:C,size:l=100,...s})=>{const{companies:g,currentCompany:r,handleCompanyChange:u}=P({onCompanyChange:C,pageSize:l}),[h,m]=v(!0),x=w(()=>g,[g]);return H(()=>{const y=()=>{m(!1)},i=d.on("checkout/initialized",y),e=d.on("checkout/updated",y);return()=>{i==null||i.off(),e==null||e.off()}},[]),g.length<2||!h?null:I("div",{...s,children:I(K,{options:x,value:r.value,onChange:u,"aria-label":c||"Select company","aria-describedby":"company-switcher-description"})})};export{L as CompanySwitcher,L as default};
|
|
4
4
|
//# sourceMappingURL=CompanySwitcher.js.map
|
|
@@ -1 +1 @@
|
|
|
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, UseCompanyDataProps, 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 = ({ onCompanyChange, pageSize = 100 }: UseCompanyDataProps = {}): 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(pageSize);\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 }, [pageSize]);\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 onCompanyChange?.({ id: companyId, name: selectedCompany?.text || '' });\n\n events.emit('companyContext/changed', companyId);\n }, [companies, onCompanyChange]);\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';\nimport { Company } from '@/company-switcher/types/company';\n\nexport interface CompanySwitcherProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom aria-label for the picker */\n ariaLabel?: string;\n /** Callback function to be called when the company changes */\n onCompanyChange?: (company: Company) => void;\n /** Maximum number of companies to fetch for the picker */\n size?: number;\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 onCompanyChange,\n size = 100,\n ...props\n}) => {\n const { companies, currentCompany, handleCompanyChange } = useCompanyData({ onCompanyChange, pageSize: size });\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","onCompanyChange","pageSize","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","i","useEffect","unsubscribeAuth","unsubscribeRestore","unsubscribeCompanyUpdated","_c","CompanySwitcher","ariaLabel","size","props","isVisible","setIsVisible","memoizedCompanies","useMemo","hidePickerHandler","unsubscribeInitialized","unsubscribeUpdated","jsx","Picker"],"mappings":"meA6BO,MAAMA,EAAiB,CAAC,CAAE,gBAAAC,EAAiB,SAAAC,EAAW,GAAA,EAA6B,CAAA,IAA6B,CACrH,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAA0B,CAAA,CAAE,EACxD,CAACC,EAAgBC,CAAi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5E,CACL,UAAA9B,EACA,eAAAG,EACA,oBAAAS,CAAA,CAEJ,EC9Ha2B,EAAmD,CAAC,CAC/D,UAAAC,EACA,gBAAA1C,EACA,KAAA2C,EAAO,IACP,GAAGC,CACL,IAAM,CACJ,KAAM,CAAE,UAAA1C,EAAW,eAAAG,EAAgB,oBAAAS,CAAA,EAAwBf,EAAe,CAAE,gBAAAC,EAAiB,SAAU2C,EAAM,EACvG,CAACE,EAAWC,CAAY,EAAI1C,EAAS,EAAI,EAGzC2C,EAAoBC,EAAQ,IAAM9C,EAAW,CAACA,CAAS,CAAC,EAkB9D,OAfAkC,EAAU,IAAM,CACd,MAAMa,EAAoB,IAAM,CAC9BH,EAAa,EAAK,CACpB,EAEMI,EAAyB1B,EAAO,GAAG,uBAAwByB,CAAiB,EAC5EE,EAAqB3B,EAAO,GAAG,mBAAoByB,CAAiB,EAE1E,MAAO,IAAM,CACXC,GAAA,MAAAA,EAAwB,MACxBC,GAAA,MAAAA,EAAoB,KACtB,CACF,EAAG,CAAA,CAAE,EAGDjD,EAAU,OAAS,GAAK,CAAC2C,EACpB,KAIPO,EAAC,MAAA,CAAK,GAAGR,EACP,SAAAQ,EAACC,EAAA,CACC,QAASN,EACT,MAAO1C,EAAe,MACtB,SAAUS,EACV,aAAY4B,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, UseCompanyDataProps, 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 = ({ onCompanyChange, pageSize = 100 }: UseCompanyDataProps = {}): 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(pageSize);\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 }, [pageSize]);\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 onCompanyChange?.({ id: companyId, name: selectedCompany?.text || '' });\n\n events.emit('companyContext/changed', companyId);\n }, [companies, onCompanyChange]);\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';\nimport { Company } from '@/company-switcher/types/company';\n\nexport interface CompanySwitcherProps extends HTMLAttributes<HTMLDivElement> {\n /** Custom aria-label for the picker */\n ariaLabel?: string;\n /** Callback function to be called when the company changes */\n onCompanyChange?: (company: Company) => void;\n /** Maximum number of companies to fetch for the picker */\n size?: number;\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 onCompanyChange,\n size = 100,\n ...props\n}) => {\n const { companies, currentCompany, handleCompanyChange } = useCompanyData({ onCompanyChange, pageSize: size });\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","onCompanyChange","pageSize","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","i","useEffect","unsubscribeAuth","unsubscribeRestore","unsubscribeCompanyUpdated","_c","CompanySwitcher","ariaLabel","size","props","isVisible","setIsVisible","memoizedCompanies","useMemo","hidePickerHandler","unsubscribeInitialized","unsubscribeUpdated","jsx","Picker"],"mappings":"2fA6BO,MAAMA,EAAiB,CAAC,CAAE,gBAAAC,EAAiB,SAAAC,EAAW,GAAA,EAA6B,CAAA,IAA6B,CACrH,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,uBAAuBT,CAAQ,EACrGE,EAAaM,EAAY,iBAAiB,GAEtCE,EAAAF,EAAY,iBAAZ,MAAAE,EAA4B,QAAQC,EAAAH,EAAY,iBAAZ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C,EAAM,EACvG,CAACE,EAAWC,CAAY,EAAI1C,EAAS,EAAI,EAGzC2C,EAAoBC,EAAQ,IAAM9C,EAAW,CAACA,CAAS,CAAC,EAkB9D,OAfAkC,EAAU,IAAM,CACd,MAAMa,EAAoB,IAAM,CAC9BH,EAAa,EAAK,CACpB,EAEMI,EAAyB1B,EAAO,GAAG,uBAAwByB,CAAiB,EAC5EE,EAAqB3B,EAAO,GAAG,mBAAoByB,CAAiB,EAE1E,MAAO,IAAM,CACXC,GAAA,MAAAA,EAAwB,MACxBC,GAAA,MAAAA,EAAoB,KACtB,CACF,EAAG,CAAA,CAAE,EAGDjD,EAAU,OAAS,GAAK,CAAC2C,EACpB,KAIPO,EAAC,MAAA,CAAK,GAAGR,EACP,SAAAQ,EAACC,EAAA,CACC,QAASN,EACT,MAAO1C,EAAe,MACtB,SAAUS,EACV,aAAY4B,GAAa,iBACzB,mBAAiB,8BAAA,CAAA,EAErB,CAEJ"}
|
package/fragments.js
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
/*! Copyright 2026 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
|
|
3
|
+
const e=`
|
|
4
|
+
fragment COMPANY_FRAGMENT on Company {
|
|
5
|
+
name
|
|
6
|
+
id
|
|
7
|
+
status
|
|
8
|
+
}
|
|
9
|
+
`,t=`
|
|
10
|
+
fragment CUSTOMER_FRAGMENT on Customer {
|
|
11
|
+
companies(input: { pageSize: $pageSize }) {
|
|
12
|
+
items {
|
|
13
|
+
name
|
|
14
|
+
id
|
|
15
|
+
status
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`;export{e as COMPANY_FRAGMENT,t as CUSTOMER_FRAGMENT};
|
|
4
20
|
//# sourceMappingURL=fragments.js.map
|
package/fragments.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fragments.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"fragments.js","sources":["/@dropins/storefront-company-switcher/src/api/graphql/CompanyFragment.graphql.ts","/@dropins/storefront-company-switcher/src/api/graphql/CustomerFragment.graphql.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 *******************************************************************/\n\nexport const COMPANY_FRAGMENT = /* GraphQL */ `\n fragment COMPANY_FRAGMENT on Company {\n name\n id\n status\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 CUSTOMER_FRAGMENT = /* GraphQL */ `\n fragment CUSTOMER_FRAGMENT on Customer {\n companies(input: { pageSize: $pageSize }) {\n items {\n name\n id\n status\n }\n }\n }\n`;\n"],"names":["COMPANY_FRAGMENT","CUSTOMER_FRAGMENT"],"mappings":"AAiBO,MAAMA,EAAiC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,ECAjCC,EAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
|
package/package.json
CHANGED
package/render.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2026 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as
|
|
3
|
+
import{jsx as e}from"@dropins/tools/preact-jsx-runtime.js";import{deepmerge as g,Render as c}from"@dropins/tools/lib.js";import{useState as p,useEffect as a}from"@dropins/tools/preact-hooks.js";import{UIProvider as d}from"@dropins/tools/components.js";import{events as u}from"@dropins/tools/event-bus.js";import{config as l}from"./api.js";import"./fragments.js";import"@dropins/tools/fetch-graphql.js";const D={"":{}},S={default:D},U=({children:t})=>{var o;const[r,i]=p("en_US");a(()=>{const n=u.on("locale",m=>{i(m)},{eager:!0});return()=>{n==null||n.off()}},[]);const s=(o=l.getConfig())==null?void 0:o.langDefinitions,f=g(S,s??{});return e(d,{lang:r,langDefinitions:f,children:t})},I=new c(e(U,{}));export{U as Provider,I 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":["/********************************************************************\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 { deepmerge } from '@adobe-commerce/elsie/lib';\nimport { config } from '@/company-switcher/api';\n\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> = ({ children }) => {\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 const userLangDefinitions = config.getConfig()?.langDefinitions;\n\n const definitions = deepmerge(langDefinitions, userLangDefinitions ?? {});\n\n return (\n <UIProvider lang={lang} langDefinitions={definitions}>\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","userLangDefinitions","_a","config","definitions","deepmerge","jsx","UIProvider","render","Render"],"mappings":"
|
|
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 { deepmerge } from '@adobe-commerce/elsie/lib';\nimport { config } from '@/company-switcher/api';\n\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> = ({ children }) => {\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 const userLangDefinitions = config.getConfig()?.langDefinitions;\n\n const definitions = deepmerge(langDefinitions, userLangDefinitions ?? {});\n\n return (\n <UIProvider lang={lang} langDefinitions={definitions}>\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","userLangDefinitions","_a","config","definitions","deepmerge","jsx","UIProvider","render","Render"],"mappings":"kaA4BMA,EAAkB,CACtB,QAASC,CACX,EAMaC,EAA6C,CAAC,CAAE,SAAAC,KAAe,OAC1E,KAAM,CAACC,EAAMC,CAAO,EAAIC,EAAe,OAAO,EAG9CC,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,EAEL,MAAMG,GAAsBC,EAAAC,EAAO,UAAA,IAAP,YAAAD,EAAoB,gBAE1CE,EAAcC,EAAUf,EAAiBW,GAAuB,CAAA,CAAE,EAExE,OACEK,EAACC,EAAA,CAAW,KAAAb,EAAY,gBAAiBU,EACtC,SAAAX,EACH,CAEJ,ECtCae,EAAS,IAAIC,EAAOH,EAACd,IAAS,CAAE"}
|