@spiffcommerce/core 22.1.3 → 22.1.4

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/dist/index.js CHANGED
@@ -12458,16 +12458,20 @@ class bt {
12458
12458
  }
12459
12459
  async checkConditionalHandlesChanged(e, t) {
12460
12460
  const A = await this.globalPropertyHandleService.getHandles(), a = this.globalPropertyHandleService.applyConditionsFromState(A, e), n = this.globalPropertyHandleService.applyConditionsFromState(A, t);
12461
- (() => {
12461
+ if ((() => {
12462
12462
  if (a.length !== n.length)
12463
12463
  return !0;
12464
12464
  for (let s = 0; s < a.length; s++)
12465
12465
  if (a[s].getName() !== n[s].getName())
12466
12466
  return !0;
12467
12467
  return !1;
12468
- })() && this.fireEvent("conditional-global-properties-changed", {
12469
- globalProperties: n
12470
- });
12468
+ })()) {
12469
+ this.fireEvent("conditional-global-properties-changed", {
12470
+ globalProperties: n
12471
+ });
12472
+ const s = n.filter((o) => !a.includes(o));
12473
+ await Promise.all(s.map((o) => o.applyGlobalState()));
12474
+ }
12471
12475
  }
12472
12476
  fireEvent(e, t) {
12473
12477
  (this.eventListeners.get(e) || []).forEach(
@@ -2445,7 +2445,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
2445
2445
  }
2446
2446
  }
2447
2447
  }
2448
- `;class Ya{constructor(e,t,A,n,a){this.bundleId=e,this.bundleOwnerId=t,this.configuration=A,this.bundleOptions=a,this.initPromise=this.getOrCreateGlobalPropertyState().then(i=>{this.globalPropertyState=i}),this.onGlobalPropertyStateChange=n}setBundleOptions(e){this.bundleOptions=e}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=this.globalPropertyState.aspects.find(A=>A.name===e);if(t)return t.value}getAspectStorage(e){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");return(t=this.globalPropertyState.aspects.find(A=>A.name===e))==null?void 0:t.storage}async setAspect(e,t,A){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const n=this.configuration.aspects.find(o=>o.name===e);if(!n)throw new Error(`Failed to find configuration aspect with name: ${e}`);const a=ce(this.globalPropertyState),i=this.globalPropertyState.aspects.find(o=>o.name===e);i?(i.value=t,A!==void 0&&(i.type=n.type,i.storage=A!==null?A:void 0)):this.globalPropertyState.aspects.push({name:e,value:t,...A===void 0?{}:{storage:A!==null?A:void 0,type:n.type}}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(a,this.globalPropertyState)}async setAspectStorage(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const A=this.configuration.aspects.find(i=>i.name===e);if(!A)throw new Error(`Failed to find configuration aspect with name: ${e}`);const n=ce(this.globalPropertyState),a=this.globalPropertyState.aspects.find(i=>i.name===e);a?(a.storage=t!==null?t:void 0,a.type=A.type):this.globalPropertyState.aspects.push({name:e,value:"",type:A.type,storage:t!==null?t:void 0}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){var t,A;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:ya,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects.map(n=>{const a=n.type&&n.storage?{}:void 0;if(a)switch(n.type){case l.AspectType.FileUpload:{a.fileUpload=n.storage;break}}return{name:n.name,value:n.value,type:n.type,storage:a}})},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(t=this.bundleOptions)==null?void 0:t.additionalHeaders}}});if((A=e.data)!=null&&A.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A,n,a;const e=await N.getShadowGraphqlClient().query({query:Sa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(A=this.bundleOptions)==null?void 0:A.additionalHeaders}}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:Ma,variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(n=this.bundleOptions)==null?void 0:n.additionalHeaders}}});if((a=t.data)!=null&&a.globalPropertyStateCreate&&t.data.globalPropertyStateCreate.id)return t.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}class Pa{constructor(e){this.setState(e)}setState(e){e&&(this.state=JSON.parse(e))}applyStateToWorkflowExperience(e){var i;if(!this.state||!((i=e==null?void 0:e.getWorkflowManager())!=null&&i.getModelContainer()))return;const t=this.state.transactions.find(o=>o.transactionId===e.getWorkflowManager().getTransaction().id);if(!t)return;const A=this.getTransformToApply(t);if(!A)return;const n=this.flipTransform(A,e.getWorkflowManager().getPreviewService()),a=e.getWorkflowManager().getModelContainer();a.position=n.position,a.rotation=n.rotation,a.scale=n.scale}getTransformToApply(e){return e.activeTransform&&e.transforms?e.transforms[e.activeTransform]:e.transform}updateWorkflowExperienceTransform(e,t,A){const n=e.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find(i=>i.transactionId===n);a?(a.transforms||(a.transforms={}),a.transforms[t]=A):this.state.transactions.push({transactionId:n,activeTransform:t,transforms:{[t]:A}})}activateWorkflowExperienceTransform(e,t){var s,r;if(!((s=e==null?void 0:e.getWorkflowManager())!=null&&s.getModelContainer())||!this.state)return;const A=e.getWorkflowManager().getTransaction().id,n=this.state.transactions.find(g=>g.transactionId===A),a=(r=n==null?void 0:n.transforms)==null?void 0:r[t];if(!a)return;const i=this.flipTransform(a,e.getWorkflowManager().getPreviewService()),o=e.getWorkflowManager().getModelContainer();o.position=i.position,o.rotation=i.rotation,o.scale=i.scale,n.activeTransform=t}removeStateForTransaction(e){if(!this.state||!this.state.transactions)return;const t=this.state.transactions.findIndex(A=>A.transactionId===e);t!==-1&&this.state.transactions.splice(t,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}flipTransform(e,t){return t&&t.flipTransform?t.flipTransform(e.position,{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},e.scale):{position:e.position,rotation:{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},scale:e.scale}}}class hA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.map(e=>new He(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new He(t));const e=await N.getShadowGraphqlClient().query({query:Ca,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new He(t))}getTransformCollection(){if(this.collection.transformCollection)return new uA(this.collection.transformCollection)}getResource(){return this.collection}}class He{constructor(e){this.product=e.product,this.productResource=e}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(e,t){const n=(this.product.integrationProducts||[]).find(a=>{var r,g,d;const i=(r=a.integration)==null?void 0:r.type,o=((g=a.integration)==null?void 0:g.type)===e,s=t?((d=a.integration)==null?void 0:d.externalIntegrationId)===t:!0;return i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new U("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");const t=this.productResource.workflowId;if(t){const n=e.find(a=>a.workflowName===t);if(n)return new se(n)}const A=e[0];return new se(A)}getAllWorkflows(){if((this.product.workflows||[]).length===0)throw new U("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");return this.product.workflows.sort((t,A)=>(t.index??0)-(A.index??0)).map(t=>new se(t))}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}getBasePrice(e){var n,a,i,o;const t=this.product.basePrice||0;if(!e)return t;if(!e.integrationType&&!e.externalId&&!e.integrationId)throw new Error("You must provide at least one of the following fields on the includeAdditionalProduct object: integrationType, externalId, integrationId");let A;return e.integrationId?A=(n=this.product.integrationProducts)==null?void 0:n.find(s=>{var r;return((r=s.integration)==null?void 0:r.id)===e.integrationId}):e.externalId?A=(a=this.product.integrationProducts)==null?void 0:a.find(s=>{var r;return((r=s.integration)==null?void 0:r.externalIntegrationId)===e.externalId}):A=(i=this.product.integrationProducts)==null?void 0:i.find(s=>{var r;return((r=s.integration)==null?void 0:r.type)===e.integrationType}),(o=A==null?void 0:A.additionalIntegrationProduct)!=null&&o.product?t+(A.additionalIntegrationProduct.product.basePrice||0):t}}class se{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class uA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new mA(e))}}class mA{constructor(e){this.transform=e}getId(){return this.transform.id}getName(){return this.transform.name}get(){return{position:this.transform.position,rotation:this.transform.rotation,scale:this.transform.scale}}}class QA{constructor(e,t,A,n,a,i){var o,s,r;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((o=t.metadata)==null?void 0:o.map(g=>[g.key,g.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new Pa(t.bundleStateData),this.globalPropertyStateManager=new Ya(this.id,this.ownerId,(s=this.productCollection)==null?void 0:s.globalPropertyConfiguration,this.checkConditionalHandlesChanged.bind(this),i),this.globalPropertyHandleService=new Fa(this),this.setPreviewService(A),this.initializationPromise=Promise.all([this.loadExistingWorkflowExperiences(((r=t.transactions)==null?void 0:r.map(g=>g.id))||[],n),this.globalPropertyStateManager.getInitializationPromise()])}setBundleOptions(e){this.globalPropertyStateManager.setBundleOptions(e)}getInitializationPromise(){return this.initializationPromise}addEventListener(e,t){this.eventListeners.set(e,[...this.eventListeners.get(e)||[],t])}removeEventListener(e,t){const A=this.eventListeners.get(e)||[],n=A.indexOf(t);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(e){return this.name=e,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(e){return this.metadata=new Map(e),this.updateBundle()}setNameAndMetadata(e,t){return this.name=e,this.metadata=new Map(t),this.updateBundle()}hasGlobalProperties(){var e;return!!((e=this.productCollection)!=null&&e.globalPropertyConfiguration)}getGlobalPropertyConfiguration(){var e;return(e=this.productCollection)==null?void 0:e.globalPropertyConfiguration}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter(A=>A.getType()===l.AspectType.Option).map(A=>{var n;return((n=A.getCurrentVariant())==null?void 0:n.getPrice())||0}).reduce((A,n)=>A+n,0)}getTotalSubunits(){return this.workflowExperiences.map(e=>e.getTotalPriceSubunits()).reduce((e,t)=>e+t,0)}getProductCollection(){return this.productCollection?new hA(this.productCollection):void 0}async addWorkflowExperience(e){e.setBundle(this),await this.appendWorkflowExperience(e),await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map(A=>A.applyGlobalState([e])))}async addWorkflowExperiences(e){const t=e.map(i=>i.getWorkflowManager().getTransaction().id),A=t.map(i=>this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===i));if(A.some(i=>!!i))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter(i=>!!i).map(i=>i==null?void 0:i.getWorkflowManager().getTransaction().id).join(", "));const n=Y.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:ua,variables:{id:this.id,transactionIds:t,transactionOwnerIds:a},context:{bundleOwnerId:this.ownerId}}).catch(i=>{console.error(i)}),this.workflowExperiences.push(...e),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const o of e)await this.injectExperienceIntoPreviewService(o);const i=await this.getGlobalProperties();await Promise.all(i.map(o=>o.applyGlobalState(e)))})()]),this.workflowExperiences.forEach(i=>i.setBundle(this)),this.workflowExperiences.forEach(i=>i.checkForPriceBreakChanges())}async appendWorkflowExperience(e,t=!0){const A=e.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===A))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(Y.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:ha,variables:{id:this.id,transactionId:A},context:{bundleOwnerId:this.ownerId,transactionOwnerId:i}}),t&&(this.workflowExperiences.push(e),this.workflowExperiences.forEach(o=>o.checkForPriceBreakChanges()))}async removeWorkflowExperience(e){const t=this.workflowExperiences.indexOf(e);await this.removeTransaction(t,this.workflowExperiences[t].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(e){await this.removeTransactions(e.map(t=>t.getWorkflowManager().getTransaction()))}async removeWorkflowExperienceByTransaction(e){const t=this.workflowExperiences.findIndex(A=>A.getWorkflowManager().getTransaction().id===e.id);await this.removeTransaction(t,e)}async removeWorkflowExperiencesByTransactions(e){await this.removeTransactions(e)}async removeTransaction(e,t,A=!0){if(e>-1){const n=this.workflowExperiences.find(a=>a.getWorkflowManager().getTransaction().id===t.id);n.setBundle(void 0),this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(t.id),await N.getShadowGraphqlClient().mutate({mutation:ma,variables:{id:this.id,transactionId:t.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([a,i])=>({key:a,value:i})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),A&&(this.workflowExperiences.splice(e,1),this.workflowExperiences.forEach(a=>a.checkForPriceBreakChanges()),n.checkForPriceBreakChanges(),await this.updateTransactionOrder())}else throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+t.id)}async removeTransactions(e){const t=e.map(n=>this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id));if(t.some(n=>n===-1))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+e.filter((n,a)=>t[a]===-1).map(n=>n.id).join(", "));const A=e.map(n=>this.workflowExperiences.splice(this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id),1)[0]);A.forEach(n=>n.setBundle(void 0)),[...this.workflowExperiences,...A].forEach(n=>n.checkForPriceBreakChanges()),this.previewService&&A.forEach(n=>n.getWorkflowManager().ejectFromPreviewService()),e.forEach(n=>this.bundleStateManager.removeStateForTransaction(n.id)),await N.getShadowGraphqlClient().mutate({mutation:Qa,variables:{id:this.id,transactionIds:e.map(n=>n.id),name:this.name,metadata:Array.from(this.metadata.entries()).map(([n,a])=>({key:n,value:a})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),await this.updateTransactionOrder()}async insertWorkflowExperience(e,t){await this.appendWorkflowExperience(e,!1),this.workflowExperiences.splice(t,0,e),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const A=await this.getGlobalProperties();await Promise.all(A.map(n=>n.applyGlobalState([e])))})()])}async replaceWorkflowExperience(e,t){if(e<0||e>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[e];if(A.getWorkflowManager().getTransaction().id===t.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(e,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(t,!1)]),this.workflowExperiences[e]=t,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const n=await this.getGlobalProperties();await Promise.all(n.map(a=>a.applyGlobalState([t])))})()])}async swapWorkflowExperiences(e,t){if(e<0||e>=this.workflowExperiences.length||t<0||t>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(e===t)return;const A=this.workflowExperiences[e];this.workflowExperiences[e]=this.workflowExperiences[t],this.workflowExperiences[t]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(e){this.workflowExperiences=this.workflowExperiences.sort(e),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(e,t){var a;const A=await N.getShadowGraphqlClient().mutate({mutation:Da,variables:{id:this.id,details:e,type:t||we.Owner},context:{bundleOwnerId:this.ownerId}});if(!((a=A.data)!=null&&a.bundleAddStakeholder))throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async removeStakeholder(e){var A;if(!((A=(await N.getShadowGraphqlClient().mutate({mutation:fa,variables:{id:this.id,emailAddress:e},context:{bundleOwnerId:this.ownerId}})).data)!=null&&A.bundleRemoveStakeholder))throw new Error("Bundle not found!")}async updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:Ia,variables:{id:this.id,input:e},context:{bundleOwnerId:this.ownerId}});if(!((n=t.data)!=null&&n.bundleUpdateStakeholders))throw new Error("Bundle not found!");const A=t.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const e=await N.getShadowGraphqlClient().query({query:Ba,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:this.id},context:{bundleOwnerId:this.ownerId}});if(!e.data.bundles||e.data.bundles.length===0)throw new Error("Bundle not found!");const t=e.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(t),t}storeStakeholderCustomers(e){e.forEach(t=>{t.customer&&this.client.storeCustomer(t.customer)})}async finish(e,t){const A=await Kn(this.workflowExperiences.map(n=>({workflowManager:n.getWorkflowManager(),workflow:n.getWorkflowManager().getWorkflow(),layouts:n.getWorkflowManager().getLayouts(),getReducerState:()=>n.getCommandContext().getState(),product:n.getWorkflowManager().getProduct(),transaction:n.getWorkflowManager().getTransaction(),workflowSelections:n.getWorkflowManager().getWorkflowSelections(),designName:n.getWorkflowManager().getWorkflow().name,workflowMetadata:n.getWorkflowManager().getWorkflowMetadata()})),e??(()=>{}),t?(n,a)=>{const i=this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===a);return i?t(i):(console.warn("SpiffCommerce - Bundle create design - Unable to find experience for transaction: "+a),Promise.resolve(void 0))}:void 0);return{bundleId:this.id,items:A}}getPreviewService(){return this.previewService}async setPreviewService(e){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach(t=>t.getWorkflowManager().ejectFromPreviewService()),e))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);e&&e.registerModelLoadEventListener&&e.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==e&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=e}updateWorkflowExperienceTransform(e,t,A){return this.bundleStateManager.updateWorkflowExperienceTransform(e,t,A),this.updateBundle()}activateWorkflowExperienceTransform(e,t){return this.bundleStateManager.activateWorkflowExperienceTransform(e,t),this.updateBundle()}onModelLoadEvent(e){e.eventType==="unload"||!e.modelContainer||(e.modelContainer.registerMaterialSelectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!0)),e.modelContainer.registerMaterialDeselectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!1)))}onModelSelectedEvent(e,t){if(e&&e.metadata&&e.metadata instanceof Map&&e.metadata.has("workflowManager")){const n=e.metadata.get("workflowManager").getTransaction(),a=this.workflowExperiences.find(i=>i.getWorkflowManager().getTransaction().id===n.id);a&&this.fireEvent(t?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:a})}}async injectExperienceIntoPreviewService(e){if(this.previewService){const t=e.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(e)}catch(A){console.error(`Unable to apply state to workflow experience: ${A}`)}await t}}async loadExistingWorkflowExperiences(e,t){if(e.length===0)return;const A=await this.client.getWorkflowExperiences(e.map(n=>({type:"transaction",transactionId:n})),t);if(A.forEach(n=>n.setBundle(this)),A.forEach(n=>n.checkForPriceBreakChanges()),this.workflowExperiences=A,this.previewService)for(const n of A)await this.injectExperienceIntoPreviewService(n)}async updateBundle(){var t;if(!((t=(await N.getShadowGraphqlClient().mutate({mutation:Ea,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([A,n])=>({key:A,value:n})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}})).data)!=null&&t.bundleUpdate))throw new Error("Bundle not found!")}async updateTransactionOrder(){await N.getShadowGraphqlClient().mutate({mutation:pa,variables:{id:this.id,transactionIds:this.workflowExperiences.map(e=>e.getWorkflowManager().getTransaction().id)},context:{bundleOwnerId:this.ownerId}})}async checkConditionalHandlesChanged(e,t){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,e),a=this.globalPropertyHandleService.applyConditionsFromState(A,t);(()=>{if(n.length!==a.length)return!0;for(let o=0;o<n.length;o++)if(n[o].getName()!==a[o].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:a})}fireEvent(e,t){(this.eventListeners.get(e)||[]).forEach(n=>n({bundle:this,event:e,data:t}))}}const xa=M.gql`
2448
+ `;class Ya{constructor(e,t,A,n,a){this.bundleId=e,this.bundleOwnerId=t,this.configuration=A,this.bundleOptions=a,this.initPromise=this.getOrCreateGlobalPropertyState().then(i=>{this.globalPropertyState=i}),this.onGlobalPropertyStateChange=n}setBundleOptions(e){this.bundleOptions=e}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=this.globalPropertyState.aspects.find(A=>A.name===e);if(t)return t.value}getAspectStorage(e){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");return(t=this.globalPropertyState.aspects.find(A=>A.name===e))==null?void 0:t.storage}async setAspect(e,t,A){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const n=this.configuration.aspects.find(o=>o.name===e);if(!n)throw new Error(`Failed to find configuration aspect with name: ${e}`);const a=ce(this.globalPropertyState),i=this.globalPropertyState.aspects.find(o=>o.name===e);i?(i.value=t,A!==void 0&&(i.type=n.type,i.storage=A!==null?A:void 0)):this.globalPropertyState.aspects.push({name:e,value:t,...A===void 0?{}:{storage:A!==null?A:void 0,type:n.type}}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(a,this.globalPropertyState)}async setAspectStorage(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const A=this.configuration.aspects.find(i=>i.name===e);if(!A)throw new Error(`Failed to find configuration aspect with name: ${e}`);const n=ce(this.globalPropertyState),a=this.globalPropertyState.aspects.find(i=>i.name===e);a?(a.storage=t!==null?t:void 0,a.type=A.type):this.globalPropertyState.aspects.push({name:e,value:"",type:A.type,storage:t!==null?t:void 0}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){var t,A;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:ya,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects.map(n=>{const a=n.type&&n.storage?{}:void 0;if(a)switch(n.type){case l.AspectType.FileUpload:{a.fileUpload=n.storage;break}}return{name:n.name,value:n.value,type:n.type,storage:a}})},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(t=this.bundleOptions)==null?void 0:t.additionalHeaders}}});if((A=e.data)!=null&&A.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A,n,a;const e=await N.getShadowGraphqlClient().query({query:Sa,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(A=this.bundleOptions)==null?void 0:A.additionalHeaders}}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:Ma,variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(n=this.bundleOptions)==null?void 0:n.additionalHeaders}}});if((a=t.data)!=null&&a.globalPropertyStateCreate&&t.data.globalPropertyStateCreate.id)return t.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}class Pa{constructor(e){this.setState(e)}setState(e){e&&(this.state=JSON.parse(e))}applyStateToWorkflowExperience(e){var i;if(!this.state||!((i=e==null?void 0:e.getWorkflowManager())!=null&&i.getModelContainer()))return;const t=this.state.transactions.find(o=>o.transactionId===e.getWorkflowManager().getTransaction().id);if(!t)return;const A=this.getTransformToApply(t);if(!A)return;const n=this.flipTransform(A,e.getWorkflowManager().getPreviewService()),a=e.getWorkflowManager().getModelContainer();a.position=n.position,a.rotation=n.rotation,a.scale=n.scale}getTransformToApply(e){return e.activeTransform&&e.transforms?e.transforms[e.activeTransform]:e.transform}updateWorkflowExperienceTransform(e,t,A){const n=e.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find(i=>i.transactionId===n);a?(a.transforms||(a.transforms={}),a.transforms[t]=A):this.state.transactions.push({transactionId:n,activeTransform:t,transforms:{[t]:A}})}activateWorkflowExperienceTransform(e,t){var s,r;if(!((s=e==null?void 0:e.getWorkflowManager())!=null&&s.getModelContainer())||!this.state)return;const A=e.getWorkflowManager().getTransaction().id,n=this.state.transactions.find(g=>g.transactionId===A),a=(r=n==null?void 0:n.transforms)==null?void 0:r[t];if(!a)return;const i=this.flipTransform(a,e.getWorkflowManager().getPreviewService()),o=e.getWorkflowManager().getModelContainer();o.position=i.position,o.rotation=i.rotation,o.scale=i.scale,n.activeTransform=t}removeStateForTransaction(e){if(!this.state||!this.state.transactions)return;const t=this.state.transactions.findIndex(A=>A.transactionId===e);t!==-1&&this.state.transactions.splice(t,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}flipTransform(e,t){return t&&t.flipTransform?t.flipTransform(e.position,{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},e.scale):{position:e.position,rotation:{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},scale:e.scale}}}class hA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.map(e=>new He(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new He(t));const e=await N.getShadowGraphqlClient().query({query:Ca,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new He(t))}getTransformCollection(){if(this.collection.transformCollection)return new uA(this.collection.transformCollection)}getResource(){return this.collection}}class He{constructor(e){this.product=e.product,this.productResource=e}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(e,t){const n=(this.product.integrationProducts||[]).find(a=>{var r,g,d;const i=(r=a.integration)==null?void 0:r.type,o=((g=a.integration)==null?void 0:g.type)===e,s=t?((d=a.integration)==null?void 0:d.externalIntegrationId)===t:!0;return i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new U("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");const t=this.productResource.workflowId;if(t){const n=e.find(a=>a.workflowName===t);if(n)return new se(n)}const A=e[0];return new se(A)}getAllWorkflows(){if((this.product.workflows||[]).length===0)throw new U("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");return this.product.workflows.sort((t,A)=>(t.index??0)-(A.index??0)).map(t=>new se(t))}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}getBasePrice(e){var n,a,i,o;const t=this.product.basePrice||0;if(!e)return t;if(!e.integrationType&&!e.externalId&&!e.integrationId)throw new Error("You must provide at least one of the following fields on the includeAdditionalProduct object: integrationType, externalId, integrationId");let A;return e.integrationId?A=(n=this.product.integrationProducts)==null?void 0:n.find(s=>{var r;return((r=s.integration)==null?void 0:r.id)===e.integrationId}):e.externalId?A=(a=this.product.integrationProducts)==null?void 0:a.find(s=>{var r;return((r=s.integration)==null?void 0:r.externalIntegrationId)===e.externalId}):A=(i=this.product.integrationProducts)==null?void 0:i.find(s=>{var r;return((r=s.integration)==null?void 0:r.type)===e.integrationType}),(o=A==null?void 0:A.additionalIntegrationProduct)!=null&&o.product?t+(A.additionalIntegrationProduct.product.basePrice||0):t}}class se{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class uA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new mA(e))}}class mA{constructor(e){this.transform=e}getId(){return this.transform.id}getName(){return this.transform.name}get(){return{position:this.transform.position,rotation:this.transform.rotation,scale:this.transform.scale}}}class QA{constructor(e,t,A,n,a,i){var o,s,r;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((o=t.metadata)==null?void 0:o.map(g=>[g.key,g.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new Pa(t.bundleStateData),this.globalPropertyStateManager=new Ya(this.id,this.ownerId,(s=this.productCollection)==null?void 0:s.globalPropertyConfiguration,this.checkConditionalHandlesChanged.bind(this),i),this.globalPropertyHandleService=new Fa(this),this.setPreviewService(A),this.initializationPromise=Promise.all([this.loadExistingWorkflowExperiences(((r=t.transactions)==null?void 0:r.map(g=>g.id))||[],n),this.globalPropertyStateManager.getInitializationPromise()])}setBundleOptions(e){this.globalPropertyStateManager.setBundleOptions(e)}getInitializationPromise(){return this.initializationPromise}addEventListener(e,t){this.eventListeners.set(e,[...this.eventListeners.get(e)||[],t])}removeEventListener(e,t){const A=this.eventListeners.get(e)||[],n=A.indexOf(t);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(e){return this.name=e,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(e){return this.metadata=new Map(e),this.updateBundle()}setNameAndMetadata(e,t){return this.name=e,this.metadata=new Map(t),this.updateBundle()}hasGlobalProperties(){var e;return!!((e=this.productCollection)!=null&&e.globalPropertyConfiguration)}getGlobalPropertyConfiguration(){var e;return(e=this.productCollection)==null?void 0:e.globalPropertyConfiguration}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter(A=>A.getType()===l.AspectType.Option).map(A=>{var n;return((n=A.getCurrentVariant())==null?void 0:n.getPrice())||0}).reduce((A,n)=>A+n,0)}getTotalSubunits(){return this.workflowExperiences.map(e=>e.getTotalPriceSubunits()).reduce((e,t)=>e+t,0)}getProductCollection(){return this.productCollection?new hA(this.productCollection):void 0}async addWorkflowExperience(e){e.setBundle(this),await this.appendWorkflowExperience(e),await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map(A=>A.applyGlobalState([e])))}async addWorkflowExperiences(e){const t=e.map(i=>i.getWorkflowManager().getTransaction().id),A=t.map(i=>this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===i));if(A.some(i=>!!i))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter(i=>!!i).map(i=>i==null?void 0:i.getWorkflowManager().getTransaction().id).join(", "));const n=Y.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:ua,variables:{id:this.id,transactionIds:t,transactionOwnerIds:a},context:{bundleOwnerId:this.ownerId}}).catch(i=>{console.error(i)}),this.workflowExperiences.push(...e),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const o of e)await this.injectExperienceIntoPreviewService(o);const i=await this.getGlobalProperties();await Promise.all(i.map(o=>o.applyGlobalState(e)))})()]),this.workflowExperiences.forEach(i=>i.setBundle(this)),this.workflowExperiences.forEach(i=>i.checkForPriceBreakChanges())}async appendWorkflowExperience(e,t=!0){const A=e.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===A))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(Y.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:ha,variables:{id:this.id,transactionId:A},context:{bundleOwnerId:this.ownerId,transactionOwnerId:i}}),t&&(this.workflowExperiences.push(e),this.workflowExperiences.forEach(o=>o.checkForPriceBreakChanges()))}async removeWorkflowExperience(e){const t=this.workflowExperiences.indexOf(e);await this.removeTransaction(t,this.workflowExperiences[t].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(e){await this.removeTransactions(e.map(t=>t.getWorkflowManager().getTransaction()))}async removeWorkflowExperienceByTransaction(e){const t=this.workflowExperiences.findIndex(A=>A.getWorkflowManager().getTransaction().id===e.id);await this.removeTransaction(t,e)}async removeWorkflowExperiencesByTransactions(e){await this.removeTransactions(e)}async removeTransaction(e,t,A=!0){if(e>-1){const n=this.workflowExperiences.find(a=>a.getWorkflowManager().getTransaction().id===t.id);n.setBundle(void 0),this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(t.id),await N.getShadowGraphqlClient().mutate({mutation:ma,variables:{id:this.id,transactionId:t.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([a,i])=>({key:a,value:i})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),A&&(this.workflowExperiences.splice(e,1),this.workflowExperiences.forEach(a=>a.checkForPriceBreakChanges()),n.checkForPriceBreakChanges(),await this.updateTransactionOrder())}else throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+t.id)}async removeTransactions(e){const t=e.map(n=>this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id));if(t.some(n=>n===-1))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+e.filter((n,a)=>t[a]===-1).map(n=>n.id).join(", "));const A=e.map(n=>this.workflowExperiences.splice(this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id),1)[0]);A.forEach(n=>n.setBundle(void 0)),[...this.workflowExperiences,...A].forEach(n=>n.checkForPriceBreakChanges()),this.previewService&&A.forEach(n=>n.getWorkflowManager().ejectFromPreviewService()),e.forEach(n=>this.bundleStateManager.removeStateForTransaction(n.id)),await N.getShadowGraphqlClient().mutate({mutation:Qa,variables:{id:this.id,transactionIds:e.map(n=>n.id),name:this.name,metadata:Array.from(this.metadata.entries()).map(([n,a])=>({key:n,value:a})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),await this.updateTransactionOrder()}async insertWorkflowExperience(e,t){await this.appendWorkflowExperience(e,!1),this.workflowExperiences.splice(t,0,e),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const A=await this.getGlobalProperties();await Promise.all(A.map(n=>n.applyGlobalState([e])))})()])}async replaceWorkflowExperience(e,t){if(e<0||e>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[e];if(A.getWorkflowManager().getTransaction().id===t.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(e,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(t,!1)]),this.workflowExperiences[e]=t,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const n=await this.getGlobalProperties();await Promise.all(n.map(a=>a.applyGlobalState([t])))})()])}async swapWorkflowExperiences(e,t){if(e<0||e>=this.workflowExperiences.length||t<0||t>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(e===t)return;const A=this.workflowExperiences[e];this.workflowExperiences[e]=this.workflowExperiences[t],this.workflowExperiences[t]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(e){this.workflowExperiences=this.workflowExperiences.sort(e),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(e,t){var a;const A=await N.getShadowGraphqlClient().mutate({mutation:Da,variables:{id:this.id,details:e,type:t||we.Owner},context:{bundleOwnerId:this.ownerId}});if(!((a=A.data)!=null&&a.bundleAddStakeholder))throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async removeStakeholder(e){var A;if(!((A=(await N.getShadowGraphqlClient().mutate({mutation:fa,variables:{id:this.id,emailAddress:e},context:{bundleOwnerId:this.ownerId}})).data)!=null&&A.bundleRemoveStakeholder))throw new Error("Bundle not found!")}async updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:Ia,variables:{id:this.id,input:e},context:{bundleOwnerId:this.ownerId}});if(!((n=t.data)!=null&&n.bundleUpdateStakeholders))throw new Error("Bundle not found!");const A=t.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const e=await N.getShadowGraphqlClient().query({query:Ba,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:this.id},context:{bundleOwnerId:this.ownerId}});if(!e.data.bundles||e.data.bundles.length===0)throw new Error("Bundle not found!");const t=e.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(t),t}storeStakeholderCustomers(e){e.forEach(t=>{t.customer&&this.client.storeCustomer(t.customer)})}async finish(e,t){const A=await Kn(this.workflowExperiences.map(n=>({workflowManager:n.getWorkflowManager(),workflow:n.getWorkflowManager().getWorkflow(),layouts:n.getWorkflowManager().getLayouts(),getReducerState:()=>n.getCommandContext().getState(),product:n.getWorkflowManager().getProduct(),transaction:n.getWorkflowManager().getTransaction(),workflowSelections:n.getWorkflowManager().getWorkflowSelections(),designName:n.getWorkflowManager().getWorkflow().name,workflowMetadata:n.getWorkflowManager().getWorkflowMetadata()})),e??(()=>{}),t?(n,a)=>{const i=this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===a);return i?t(i):(console.warn("SpiffCommerce - Bundle create design - Unable to find experience for transaction: "+a),Promise.resolve(void 0))}:void 0);return{bundleId:this.id,items:A}}getPreviewService(){return this.previewService}async setPreviewService(e){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach(t=>t.getWorkflowManager().ejectFromPreviewService()),e))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);e&&e.registerModelLoadEventListener&&e.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==e&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=e}updateWorkflowExperienceTransform(e,t,A){return this.bundleStateManager.updateWorkflowExperienceTransform(e,t,A),this.updateBundle()}activateWorkflowExperienceTransform(e,t){return this.bundleStateManager.activateWorkflowExperienceTransform(e,t),this.updateBundle()}onModelLoadEvent(e){e.eventType==="unload"||!e.modelContainer||(e.modelContainer.registerMaterialSelectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!0)),e.modelContainer.registerMaterialDeselectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!1)))}onModelSelectedEvent(e,t){if(e&&e.metadata&&e.metadata instanceof Map&&e.metadata.has("workflowManager")){const n=e.metadata.get("workflowManager").getTransaction(),a=this.workflowExperiences.find(i=>i.getWorkflowManager().getTransaction().id===n.id);a&&this.fireEvent(t?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:a})}}async injectExperienceIntoPreviewService(e){if(this.previewService){const t=e.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(e)}catch(A){console.error(`Unable to apply state to workflow experience: ${A}`)}await t}}async loadExistingWorkflowExperiences(e,t){if(e.length===0)return;const A=await this.client.getWorkflowExperiences(e.map(n=>({type:"transaction",transactionId:n})),t);if(A.forEach(n=>n.setBundle(this)),A.forEach(n=>n.checkForPriceBreakChanges()),this.workflowExperiences=A,this.previewService)for(const n of A)await this.injectExperienceIntoPreviewService(n)}async updateBundle(){var t;if(!((t=(await N.getShadowGraphqlClient().mutate({mutation:Ea,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([A,n])=>({key:A,value:n})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}})).data)!=null&&t.bundleUpdate))throw new Error("Bundle not found!")}async updateTransactionOrder(){await N.getShadowGraphqlClient().mutate({mutation:pa,variables:{id:this.id,transactionIds:this.workflowExperiences.map(e=>e.getWorkflowManager().getTransaction().id)},context:{bundleOwnerId:this.ownerId}})}async checkConditionalHandlesChanged(e,t){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,e),a=this.globalPropertyHandleService.applyConditionsFromState(A,t);if((()=>{if(n.length!==a.length)return!0;for(let o=0;o<n.length;o++)if(n[o].getName()!==a[o].getName())return!0;return!1})()){this.fireEvent("conditional-global-properties-changed",{globalProperties:a});const o=a.filter(s=>!n.includes(s));await Promise.all(o.map(s=>s.applyGlobalState()))}}fireEvent(e,t){(this.eventListeners.get(e)||[]).forEach(n=>n({bundle:this,event:e,data:t}))}}const xa=M.gql`
2449
2449
  mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
2450
2450
  processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
2451
2451
  id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "22.1.3",
3
+ "version": "22.1.4",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.umd.cjs",