@spiffcommerce/core 15.2.0 → 15.2.1

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/main.js CHANGED
@@ -897,7 +897,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
897
897
  id
898
898
  }
899
899
  }
900
- `;function Cc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Qc{constructor(t){Cc(this,"bundle",void 0),Cc(this,"handleCache",{}),this.bundle=t}async getHandle(t){if(this.handleCache[t.name])return this.handleCache[t.name];const e=await this.createHandle(t);return this.handleCache[t.name]=e,e}async getHandles(){if(!this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration)return[];const t=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(t.aspects.map((t=>this.getHandle(t))))}applyConditionsFromState(t,e){return e?t.filter((t=>this.aspectConditionsSatisfied(t.getRawProperty(),e))):t}aspectConditionsSatisfied(t,e){return!t.conditions||0===t.conditions.length||t.conditions.some((t=>{const i=e.aspects.find((e=>e.name===t.targetAspectName));return!!i&&t.requiredVariantSelections.some((t=>t===i.value))}))}async createHandle(t){switch(t.type){case ei.FileUpload:return new Ic(this.bundle,t);case ei.Option:{const e=t.entityId?await Ja.getOption(t.entityId):void 0;return"Color"===e?.type?new vc(this.bundle,t,e):new xc(this.bundle,t,e)}case ei.Text:return new Dc(this.bundle,t)}}}class yc{constructor(t,e){Cc(this,"bundle",void 0),Cc(this,"property",void 0),this.bundle=t,this.property=e}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(t){return(t??this.bundle.getWorkflowExperiences()).flatMap((t=>t.getSteps().filter((t=>t.getRaw().globalPropertyAspectConfigurations?.some((t=>t.globalPropertyConfigurationId===this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration?.id&&t.aspectName===this.property.name))))))}}class Ic extends yc{constructor(t,e){super(t,e)}async selectImage(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.key),this.applyImageSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=await ka.getLocalOrFromServer(e);return i?this.applyImageSelection(i,t):Promise.resolve()}async applyImageSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectImage(t)));await Promise.all(i)}}class Dc extends yc{constructor(t,e){super(t,e)}getText(){const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);return t||""}async setText(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t),this.applyTextSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();await this.applyTextSelection(e,t)}async applyTextSelection(t,e){const i=this.getSharedSteps(e).map((e=>{e.setText(t)}));await Promise.all(i)}}class xc extends yc{constructor(t,e,i){super(t,e),Cc(this,"optionResource",void 0),this.optionResource=i}getCurrentVariant(){if(!this.optionResource)return;const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!t)return;const e=this.optionResource.variants?.find((e=>e.id===t));return e?new bs(e):void 0}getAvailableVariants(){return(this.optionResource?.variants?.filter((t=>t.enabled))||[]).map((t=>new bs(t)))}getAllVariants(){return(this.optionResource?.variants||[]).map((t=>new bs(t)))}async selectVariant(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.getId()),this.applyVariantSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=this.optionResource?.variants?.find((t=>t.id===e));return i?this.applyVariantSelection(new bs(i),t):Promise.resolve()}async applyVariantSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectVariant(t)));await Promise.all(i)}}class vc extends xc{constructor(t,e,i){super(t,e,i)}setCustomColor(t){this.getSharedSteps().forEach((e=>e.setCustomColor(t)))}getCustomColor(){return this.getSharedSteps()[0].getCustomColor()}}const Mc=v.gql`
900
+ `;function Cc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Qc{constructor(t){Cc(this,"bundle",void 0),Cc(this,"handleCache",{}),this.bundle=t}async getHandle(t){if(this.handleCache[t.name])return this.handleCache[t.name];const e=await this.createHandle(t);return this.handleCache[t.name]=e,e}async getHandles(){if(!this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration)return[];const t=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(t.aspects.map((t=>this.getHandle(t))))}applyConditionsFromState(t,e){return e?t.filter((t=>this.aspectConditionsSatisfied(t.getRawProperty(),e))):t}aspectConditionsSatisfied(t,e){return!t.conditions||0===t.conditions.length||t.conditions.some((t=>{const i=e.aspects.find((e=>e.name===t.targetAspectName));return!!i&&t.requiredVariantSelections.some((t=>t===i.value))}))}async createHandle(t){switch(t.type){case ei.FileUpload:return new Ic(this.bundle,t);case ei.Option:{const e=t.entityId?await Ja.getOption(t.entityId):void 0;return"Color"===e?.type?new vc(this.bundle,t,e):new xc(this.bundle,t,e)}case ei.Text:return new Dc(this.bundle,t)}}}class yc{constructor(t,e){Cc(this,"bundle",void 0),Cc(this,"property",void 0),this.bundle=t,this.property=e}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(t){return(t??this.bundle.getWorkflowExperiences()).flatMap((t=>t.getSteps().filter((t=>t.getRaw().globalPropertyAspectConfigurations?.some((t=>t.globalPropertyConfigurationId===this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration?.id&&t.aspectName===this.property.name))))))}}class Ic extends yc{constructor(t,e){super(t,e)}async selectImage(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.key),this.applyImageSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=await ka.getLocalOrFromServer(e);return i?this.applyImageSelection(i,t):Promise.resolve()}async applyImageSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectImage(t)));await Promise.all(i)}}class Dc extends yc{constructor(t,e){super(t,e)}getText(){const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);return t||""}async setText(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t),this.applyTextSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();await this.applyTextSelection(e,t)}async applyTextSelection(t,e){const i=this.getSharedSteps(e).map((e=>{e.setText(t)}));await Promise.all(i)}}class xc extends yc{constructor(t,e,i){super(t,e),Cc(this,"optionResource",void 0),this.optionResource=i}getCurrentVariant(){if(!this.optionResource)return;const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(t){const e=this.optionResource.variants?.find((e=>e.id===t));if(!e)return;return new bs(e)}{const t=this.optionResource.variants?.find((t=>t.default));if(!t)return;return new bs(t)}}getAvailableVariants(){return(this.optionResource?.variants?.filter((t=>t.enabled))||[]).map((t=>new bs(t)))}getAllVariants(){return(this.optionResource?.variants||[]).map((t=>new bs(t)))}async selectVariant(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.getId()),this.applyVariantSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const i=this.optionResource?.variants?.find((t=>t.id===e));return i?this.applyVariantSelection(new bs(i),t):Promise.resolve()}async applyVariantSelection(t,e){const i=this.getSharedSteps(e).map((e=>e.selectVariant(t)));await Promise.all(i)}}class vc extends xc{constructor(t,e,i){super(t,e,i)}setCustomColor(t){this.getSharedSteps().forEach((e=>e.setCustomColor(t)))}getCustomColor(){return this.getSharedSteps()[0].getCustomColor()}}const Mc=v.gql`
901
901
  mutation CreateGlobalPropertyState($bundleId: String!) {
902
902
  globalPropertyStateCreate(bundleId: $bundleId) {
903
903
  id
@@ -927,7 +927,7 @@ var t=require("@apollo/client"),e=require("lodash.clonedeep"),i=require("react/j
927
927
  }
928
928
  }
929
929
  }
930
- `;function Fc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Pc{constructor(t,e){Fc(this,"bundleId",void 0),Fc(this,"globalPropertyState",void 0),Fc(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t)),this.onGlobalPropertyStateChange=e}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,i){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const n=b(e)(this.globalPropertyState),A=this.globalPropertyState.aspects.find((e=>e.name===t));A?A.value=i:this.globalPropertyState.aspects.push({name:t,value:i}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Ia.getShadowGraphqlClient().mutate({mutation:Sc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Ia.getShadowGraphqlClient().query({query:bc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Ia.getShadowGraphqlClient().mutate({mutation:Mc,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Yc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Nc{constructor(t){Yc(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const A=this.state.transactions.find((t=>t.transactionId===n));A?A.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function kc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Rc{constructor(t){kc(this,"collection",void 0),this.collection=t}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){return this.collection.products.map((t=>new Hc(t)))}getResource(){return this.collection}}class Hc{constructor(t){kc(this,"product",void 0),this.product=t}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(t){const e=(this.product.integrationProducts||[]).find((e=>!!e.integration?.type&&e.integration?.type===t));if(!e)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return e}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}}function Uc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Gc{constructor(t,e,i,n){Uc(this,"client",void 0),Uc(this,"id",void 0),Uc(this,"name",void 0),Uc(this,"metadata",void 0),Uc(this,"productCollection",void 0),Uc(this,"bundleStateManager",void 0),Uc(this,"globalConfiguration",void 0),Uc(this,"globalPropertyStateManager",void 0),Uc(this,"globalPropertyHandleService",void 0),Uc(this,"eventListeners",new Map),Uc(this,"initializationPromise",void 0),Uc(this,"workflowExperiences",[]),Uc(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new Nc(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new Pc(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Qc(this),this.setPreviewService(i),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const i=this.eventListeners.get(t)||[],n=i.indexOf(e);n>-1&&i.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}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((t=>t.getType()===ei.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection?new Rc(this.productCollection):void 0}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),i=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(i.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+i.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=da.getMap("transactionOwnerIds")||new Map,A=e.map((t=>n.get(t)));await Ia.getShadowGraphqlClient().mutate({mutation:wc,variables:{id:this.id,transactionIds:e,transactionOwnerIds:A}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t,e=!0){const i=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i)))throw new Error("Unable to add transaction to bundle - Already Exists!");const n=(da.getMap("transactionOwnerIds")||new Map).get(i);await Ia.getShadowGraphqlClient().mutate({mutation:uc,variables:{id:this.id,transactionId:i},context:{transactionOwnerId:n}}),e&&this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e,i=!0){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e.id));this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await Ia.getShadowGraphqlClient().mutate({mutation:Bc,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),i&&(this.workflowExperiences.splice(t,1),await this.updateTransactionOrder())}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,i)=>-1===e[i])).map((t=>t.id)).join(", "));const i=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&i.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await Ia.getShadowGraphqlClient().mutate({mutation:pc,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t,!1),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}async replaceWorkflowExperience(t,e){if(t<0||t>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const i=this.workflowExperiences[t];if(i.getWorkflowManager().getTransaction().id===e.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(t,i.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(e,!1)]),this.workflowExperiences[t]=e,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map((t=>t.applyGlobalState([e]))))})()])}async swapWorkflowExperiences(t,e){if(t<0||t>=this.workflowExperiences.length||e<0||e>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(t===e)return;const i=this.workflowExperiences[t];this.workflowExperiences[t]=this.workflowExperiences[e],this.workflowExperiences[e]=i,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){const i=await Ia.getShadowGraphqlClient().mutate({mutation:mc,variables:{id:this.id,details:t,type:e||gr.Owner}});if(!i.data?.bundleAddStakeholder)throw new Error("Bundle not found!");const n=i.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async updateStakeholders(t){const e=await Ia.getShadowGraphqlClient().mutate({mutation:Ec,variables:{id:this.id,input:t}});if(!e.data?.bundleUpdateStakeholders)throw new Error("Bundle not found!");const i=e.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(i)}async getAllStakeholders(){const t=await Ia.getShadowGraphqlClient().query({query:lc,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");const e=t.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(e),e}storeStakeholderCustomers(t){t.forEach((t=>{t.customer&&this.client.storeCustomer(t.customer)}))}async finish(t){return await ec(this.workflowExperiences.map((t=>({workflowManager:t.getWorkflowManager(),workflow:t.getWorkflowManager().getWorkflow(),layouts:t.getWorkflowManager().getLayouts(),getReducerState:()=>t.getCommandContext().getState(),product:t.getWorkflowManager().getProduct(),transaction:t.getWorkflowManager().getTransaction(),workflowSelections:t.getWorkflowManager().getWorkflowSelections(),designName:t.getWorkflowManager().getWorkflow().name,variationRecords:t.getWorkflowManager().getVariationRecords(),updateVariationRecords:e=>t.updateVariationRecords(e),workflowMetadata:t.getWorkflowManager().getWorkflowMetadata()}))),t??(()=>{}))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const i=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t,e){if(0===t.length)return;const i=await this.client.getWorkflowExperiences(t.map((t=>({type:"transaction",transactionId:t}))),e);if(this.workflowExperiences=i,this.previewService)for(const t of i)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await Ia.getShadowGraphqlClient().mutate({mutation:dc,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await Ia.getShadowGraphqlClient().mutate({mutation:fc,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const i=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(i,t),A=this.globalPropertyHandleService.applyConditionsFromState(i,e);(()=>{if(n.length!==A.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==A[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:A})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((i=>i({bundle:this,event:t,data:e})))}}function Tc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Oc=t.gql`
930
+ `;function Fc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Pc{constructor(t,e){Fc(this,"bundleId",void 0),Fc(this,"initPromise",void 0),Fc(this,"globalPropertyState",void 0),Fc(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.initPromise=this.getOrCreateGlobalPropertyState().then((t=>{this.globalPropertyState=t})),this.onGlobalPropertyStateChange=e}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,i){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const n=b(e)(this.globalPropertyState),A=this.globalPropertyState.aspects.find((e=>e.name===t));A?A.value=i:this.globalPropertyState.aspects.push({name:t,value:i}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await Ia.getShadowGraphqlClient().mutate({mutation:Sc,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await Ia.getShadowGraphqlClient().query({query:bc,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await Ia.getShadowGraphqlClient().mutate({mutation:Mc,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Yc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Nc{constructor(t){Yc(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const i=t.getWorkflowManager().getModelContainer();i.position=e.position,i.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},i.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const A=this.state.transactions.find((t=>t.transactionId===n));A?A.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function kc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Rc{constructor(t){kc(this,"collection",void 0),this.collection=t}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){return this.collection.products.map((t=>new Hc(t)))}getResource(){return this.collection}}class Hc{constructor(t){kc(this,"product",void 0),this.product=t}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(t){const e=(this.product.integrationProducts||[]).find((e=>!!e.integration?.type&&e.integration?.type===t));if(!e)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return e}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}}function Uc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class Gc{constructor(t,e,i,n){Uc(this,"client",void 0),Uc(this,"id",void 0),Uc(this,"name",void 0),Uc(this,"metadata",void 0),Uc(this,"productCollection",void 0),Uc(this,"bundleStateManager",void 0),Uc(this,"globalConfiguration",void 0),Uc(this,"globalPropertyStateManager",void 0),Uc(this,"globalPropertyHandleService",void 0),Uc(this,"eventListeners",new Map),Uc(this,"initializationPromise",void 0),Uc(this,"workflowExperiences",[]),Uc(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new Nc(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new Pc(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Qc(this),this.setPreviewService(i),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const i=this.eventListeners.get(t)||[],n=i.indexOf(e);n>-1&&i.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}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((t=>t.getType()===ei.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection?new Rc(this.productCollection):void 0}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),i=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(i.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+i.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=da.getMap("transactionOwnerIds")||new Map,A=e.map((t=>n.get(t)));await Ia.getShadowGraphqlClient().mutate({mutation:wc,variables:{id:this.id,transactionIds:e,transactionOwnerIds:A}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t,e=!0){const i=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i)))throw new Error("Unable to add transaction to bundle - Already Exists!");const n=(da.getMap("transactionOwnerIds")||new Map).get(i);await Ia.getShadowGraphqlClient().mutate({mutation:uc,variables:{id:this.id,transactionId:i},context:{transactionOwnerId:n}}),e&&this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e,i=!0){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e.id));this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await Ia.getShadowGraphqlClient().mutate({mutation:Bc,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),i&&(this.workflowExperiences.splice(t,1),await this.updateTransactionOrder())}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,i)=>-1===e[i])).map((t=>t.id)).join(", "));const i=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&i.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await Ia.getShadowGraphqlClient().mutate({mutation:pc,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t,!1),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}async replaceWorkflowExperience(t,e){if(t<0||t>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const i=this.workflowExperiences[t];if(i.getWorkflowManager().getTransaction().id===e.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(t,i.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(e,!1)]),this.workflowExperiences[t]=e,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map((t=>t.applyGlobalState([e]))))})()])}async swapWorkflowExperiences(t,e){if(t<0||t>=this.workflowExperiences.length||e<0||e>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(t===e)return;const i=this.workflowExperiences[t];this.workflowExperiences[t]=this.workflowExperiences[e],this.workflowExperiences[e]=i,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){const i=await Ia.getShadowGraphqlClient().mutate({mutation:mc,variables:{id:this.id,details:t,type:e||gr.Owner}});if(!i.data?.bundleAddStakeholder)throw new Error("Bundle not found!");const n=i.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async updateStakeholders(t){const e=await Ia.getShadowGraphqlClient().mutate({mutation:Ec,variables:{id:this.id,input:t}});if(!e.data?.bundleUpdateStakeholders)throw new Error("Bundle not found!");const i=e.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(i)}async getAllStakeholders(){const t=await Ia.getShadowGraphqlClient().query({query:lc,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");const e=t.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(e),e}storeStakeholderCustomers(t){t.forEach((t=>{t.customer&&this.client.storeCustomer(t.customer)}))}async finish(t){return await ec(this.workflowExperiences.map((t=>({workflowManager:t.getWorkflowManager(),workflow:t.getWorkflowManager().getWorkflow(),layouts:t.getWorkflowManager().getLayouts(),getReducerState:()=>t.getCommandContext().getState(),product:t.getWorkflowManager().getProduct(),transaction:t.getWorkflowManager().getTransaction(),workflowSelections:t.getWorkflowManager().getWorkflowSelections(),designName:t.getWorkflowManager().getWorkflow().name,variationRecords:t.getWorkflowManager().getVariationRecords(),updateVariationRecords:e=>t.updateVariationRecords(e),workflowMetadata:t.getWorkflowManager().getWorkflowMetadata()}))),t??(()=>{}))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const i=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===i.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t,e){if(0===t.length)return;const i=await this.client.getWorkflowExperiences(t.map((t=>({type:"transaction",transactionId:t}))),e);if(this.workflowExperiences=i,this.previewService)for(const t of i)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await Ia.getShadowGraphqlClient().mutate({mutation:dc,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await Ia.getShadowGraphqlClient().mutate({mutation:fc,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const i=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(i,t),A=this.globalPropertyHandleService.applyConditionsFromState(i,e);(()=>{if(n.length!==A.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==A[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:A})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((i=>i({bundle:this,event:t,data:e})))}}function Tc(t,e,i){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const Oc=t.gql`
931
931
  mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
932
932
  processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
933
933
  id
package/dist/module.js CHANGED
@@ -897,7 +897,7 @@ import{CommandContext as t,AssetType as e,BringForwardCommand as A,BringToFrontC
897
897
  id
898
898
  }
899
899
  }
900
- `;function mi(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class fi{constructor(t){mi(this,"bundle",void 0),mi(this,"handleCache",{}),this.bundle=t}async getHandle(t){if(this.handleCache[t.name])return this.handleCache[t.name];const e=await this.createHandle(t);return this.handleCache[t.name]=e,e}async getHandles(){if(!this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration)return[];const t=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(t.aspects.map((t=>this.getHandle(t))))}applyConditionsFromState(t,e){return e?t.filter((t=>this.aspectConditionsSatisfied(t.getRawProperty(),e))):t}aspectConditionsSatisfied(t,e){return!t.conditions||0===t.conditions.length||t.conditions.some((t=>{const A=e.aspects.find((e=>e.name===t.targetAspectName));return!!A&&t.requiredVariantSelections.some((t=>t===A.value))}))}async createHandle(t){switch(t.type){case Dt.FileUpload:return new Ii(this.bundle,t);case Dt.Option:{const e=t.entityId?await Oe.getOption(t.entityId):void 0;return"Color"===e?.type?new Fi(this.bundle,t,e):new Mi(this.bundle,t,e)}case Dt.Text:return new yi(this.bundle,t)}}}class Di{constructor(t,e){mi(this,"bundle",void 0),mi(this,"property",void 0),this.bundle=t,this.property=e}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(t){return(t??this.bundle.getWorkflowExperiences()).flatMap((t=>t.getSteps().filter((t=>t.getRaw().globalPropertyAspectConfigurations?.some((t=>t.globalPropertyConfigurationId===this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration?.id&&t.aspectName===this.property.name))))))}}class Ii extends Di{constructor(t,e){super(t,e)}async selectImage(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.key),this.applyImageSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const A=await be.getLocalOrFromServer(e);return A?this.applyImageSelection(A,t):Promise.resolve()}async applyImageSelection(t,e){const A=this.getSharedSteps(e).map((e=>e.selectImage(t)));await Promise.all(A)}}class yi extends Di{constructor(t,e){super(t,e)}getText(){const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);return t||""}async setText(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t),this.applyTextSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();await this.applyTextSelection(e,t)}async applyTextSelection(t,e){const A=this.getSharedSteps(e).map((e=>{e.setText(t)}));await Promise.all(A)}}class Mi extends Di{constructor(t,e,A){super(t,e),mi(this,"optionResource",void 0),this.optionResource=A}getCurrentVariant(){if(!this.optionResource)return;const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!t)return;const e=this.optionResource.variants?.find((e=>e.id===t));return e?new xa(e):void 0}getAvailableVariants(){return(this.optionResource?.variants?.filter((t=>t.enabled))||[]).map((t=>new xa(t)))}getAllVariants(){return(this.optionResource?.variants||[]).map((t=>new xa(t)))}async selectVariant(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.getId()),this.applyVariantSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const A=this.optionResource?.variants?.find((t=>t.id===e));return A?this.applyVariantSelection(new xa(A),t):Promise.resolve()}async applyVariantSelection(t,e){const A=this.getSharedSteps(e).map((e=>e.selectVariant(t)));await Promise.all(A)}}class Fi extends Mi{constructor(t,e,A){super(t,e,A)}setCustomColor(t){this.getSharedSteps().forEach((e=>e.setCustomColor(t)))}getCustomColor(){return this.getSharedSteps()[0].getCustomColor()}}const Si=Zt`
900
+ `;function mi(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class fi{constructor(t){mi(this,"bundle",void 0),mi(this,"handleCache",{}),this.bundle=t}async getHandle(t){if(this.handleCache[t.name])return this.handleCache[t.name];const e=await this.createHandle(t);return this.handleCache[t.name]=e,e}async getHandles(){if(!this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration)return[];const t=this.bundle.getProductCollection().getResource().globalPropertyConfiguration;return Promise.all(t.aspects.map((t=>this.getHandle(t))))}applyConditionsFromState(t,e){return e?t.filter((t=>this.aspectConditionsSatisfied(t.getRawProperty(),e))):t}aspectConditionsSatisfied(t,e){return!t.conditions||0===t.conditions.length||t.conditions.some((t=>{const A=e.aspects.find((e=>e.name===t.targetAspectName));return!!A&&t.requiredVariantSelections.some((t=>t===A.value))}))}async createHandle(t){switch(t.type){case Dt.FileUpload:return new Ii(this.bundle,t);case Dt.Option:{const e=t.entityId?await Oe.getOption(t.entityId):void 0;return"Color"===e?.type?new Fi(this.bundle,t,e):new Mi(this.bundle,t,e)}case Dt.Text:return new yi(this.bundle,t)}}}class Di{constructor(t,e){mi(this,"bundle",void 0),mi(this,"property",void 0),this.bundle=t,this.property=e}getName(){return this.property.name}getTitle(){return this.property.title}getDescription(){return this.property.description}getType(){return this.property.type}getRawProperty(){return this.property}getSharedSteps(t){return(t??this.bundle.getWorkflowExperiences()).flatMap((t=>t.getSteps().filter((t=>t.getRaw().globalPropertyAspectConfigurations?.some((t=>t.globalPropertyConfigurationId===this.bundle.getProductCollection()?.getResource().globalPropertyConfiguration?.id&&t.aspectName===this.property.name))))))}}class Ii extends Di{constructor(t,e){super(t,e)}async selectImage(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.key),this.applyImageSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const A=await be.getLocalOrFromServer(e);return A?this.applyImageSelection(A,t):Promise.resolve()}async applyImageSelection(t,e){const A=this.getSharedSteps(e).map((e=>e.selectImage(t)));await Promise.all(A)}}class yi extends Di{constructor(t,e){super(t,e)}getText(){const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);return t||""}async setText(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t),this.applyTextSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();await this.applyTextSelection(e,t)}async applyTextSelection(t,e){const A=this.getSharedSteps(e).map((e=>{e.setText(t)}));await Promise.all(A)}}class Mi extends Di{constructor(t,e,A){super(t,e),mi(this,"optionResource",void 0),this.optionResource=A}getCurrentVariant(){if(!this.optionResource)return;const t=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(t){const e=this.optionResource.variants?.find((e=>e.id===t));if(!e)return;return new xa(e)}{const t=this.optionResource.variants?.find((t=>t.default));if(!t)return;return new xa(t)}}getAvailableVariants(){return(this.optionResource?.variants?.filter((t=>t.enabled))||[]).map((t=>new xa(t)))}getAllVariants(){return(this.optionResource?.variants||[]).map((t=>new xa(t)))}async selectVariant(t){await Promise.all([this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name,t.getId()),this.applyVariantSelection(t)])}async applyGlobalState(t){const e=this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);if(!e)return Promise.resolve();const A=this.optionResource?.variants?.find((t=>t.id===e));return A?this.applyVariantSelection(new xa(A),t):Promise.resolve()}async applyVariantSelection(t,e){const A=this.getSharedSteps(e).map((e=>e.selectVariant(t)));await Promise.all(A)}}class Fi extends Mi{constructor(t,e,A){super(t,e,A)}setCustomColor(t){this.getSharedSteps().forEach((e=>e.setCustomColor(t)))}getCustomColor(){return this.getSharedSteps()[0].getCustomColor()}}const Si=Zt`
901
901
  mutation CreateGlobalPropertyState($bundleId: String!) {
902
902
  globalPropertyStateCreate(bundleId: $bundleId) {
903
903
  id
@@ -927,7 +927,7 @@ import{CommandContext as t,AssetType as e,BringForwardCommand as A,BringToFrontC
927
927
  }
928
928
  }
929
929
  }
930
- `;function xi(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Pi{constructor(t,e){xi(this,"bundleId",void 0),xi(this,"globalPropertyState",void 0),xi(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.getOrCreateGlobalPropertyState().then((t=>this.globalPropertyState=t)),this.onGlobalPropertyStateChange=e}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=zt(this.globalPropertyState),n=this.globalPropertyState.aspects.find((e=>e.name===t));n?n.value=e:this.globalPropertyState.aspects.push({name:t,value:e}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(A,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await ye.getShadowGraphqlClient().mutate({mutation:Yi,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await ye.getShadowGraphqlClient().query({query:vi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await ye.getShadowGraphqlClient().mutate({mutation:Si,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Ni(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ri{constructor(t){Ni(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const A=t.getWorkflowManager().getModelContainer();A.position=e.position,A.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},A.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const A=t.getWorkflowManager().getModelContainer();A.position=e.position,A.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},A.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find((t=>t.transactionId===n));a?a.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function Hi(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class bi{constructor(t){Hi(this,"collection",void 0),this.collection=t}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){return this.collection.products.map((t=>new ki(t)))}getResource(){return this.collection}}class ki{constructor(t){Hi(this,"product",void 0),this.product=t}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(t){const e=(this.product.integrationProducts||[]).find((e=>!!e.integration?.type&&e.integration?.type===t));if(!e)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return e}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}}function Ui(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Gi{constructor(t,e,A,n){Ui(this,"client",void 0),Ui(this,"id",void 0),Ui(this,"name",void 0),Ui(this,"metadata",void 0),Ui(this,"productCollection",void 0),Ui(this,"bundleStateManager",void 0),Ui(this,"globalConfiguration",void 0),Ui(this,"globalPropertyStateManager",void 0),Ui(this,"globalPropertyHandleService",void 0),Ui(this,"eventListeners",new Map),Ui(this,"initializationPromise",void 0),Ui(this,"workflowExperiences",[]),Ui(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new Ri(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new Pi(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new fi(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const A=this.eventListeners.get(t)||[],n=A.indexOf(e);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}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((t=>t.getType()===Dt.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection?new bi(this.productCollection):void 0}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),A=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(A.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=we.getMap("transactionOwnerIds")||new Map,a=e.map((t=>n.get(t)));await ye.getShadowGraphqlClient().mutate({mutation:hi,variables:{id:this.id,transactionIds:e,transactionOwnerIds:a}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t,e=!0){const A=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===A)))throw new Error("Unable to add transaction to bundle - Already Exists!");const n=(we.getMap("transactionOwnerIds")||new Map).get(A);await ye.getShadowGraphqlClient().mutate({mutation:wi,variables:{id:this.id,transactionId:A},context:{transactionOwnerId:n}}),e&&this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e,A=!0){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e.id));this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await ye.getShadowGraphqlClient().mutate({mutation:Ei,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),A&&(this.workflowExperiences.splice(t,1),await this.updateTransactionOrder())}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,A)=>-1===e[A])).map((t=>t.id)).join(", "));const A=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&A.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await ye.getShadowGraphqlClient().mutate({mutation:ui,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t,!1),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}async replaceWorkflowExperience(t,e){if(t<0||t>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[t];if(A.getWorkflowManager().getTransaction().id===e.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(t,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(e,!1)]),this.workflowExperiences[t]=e,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map((t=>t.applyGlobalState([e]))))})()])}async swapWorkflowExperiences(t,e){if(t<0||t>=this.workflowExperiences.length||e<0||e>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(t===e)return;const A=this.workflowExperiences[t];this.workflowExperiences[t]=this.workflowExperiences[e],this.workflowExperiences[e]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){const A=await ye.getShadowGraphqlClient().mutate({mutation:Ci,variables:{id:this.id,details:t,type:e||BA.Owner}});if(!A.data?.bundleAddStakeholder)throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async updateStakeholders(t){const e=await ye.getShadowGraphqlClient().mutate({mutation:Qi,variables:{id:this.id,input:t}});if(!e.data?.bundleUpdateStakeholders)throw new Error("Bundle not found!");const A=e.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const t=await ye.getShadowGraphqlClient().query({query:gi,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");const e=t.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(e),e}storeStakeholderCustomers(t){t.forEach((t=>{t.customer&&this.client.storeCustomer(t.customer)}))}async finish(t){return await Ai(this.workflowExperiences.map((t=>({workflowManager:t.getWorkflowManager(),workflow:t.getWorkflowManager().getWorkflow(),layouts:t.getWorkflowManager().getLayouts(),getReducerState:()=>t.getCommandContext().getState(),product:t.getWorkflowManager().getProduct(),transaction:t.getWorkflowManager().getTransaction(),workflowSelections:t.getWorkflowManager().getWorkflowSelections(),designName:t.getWorkflowManager().getWorkflow().name,variationRecords:t.getWorkflowManager().getVariationRecords(),updateVariationRecords:e=>t.updateVariationRecords(e),workflowMetadata:t.getWorkflowManager().getWorkflowMetadata()}))),t??(()=>{}))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const A=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===A.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t,e){if(0===t.length)return;const A=await this.client.getWorkflowExperiences(t.map((t=>({type:"transaction",transactionId:t}))),e);if(this.workflowExperiences=A,this.previewService)for(const t of A)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await ye.getShadowGraphqlClient().mutate({mutation:di,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await ye.getShadowGraphqlClient().mutate({mutation:pi,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,t),a=this.globalPropertyHandleService.applyConditionsFromState(A,e);(()=>{if(n.length!==a.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==a[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:a})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((A=>A({bundle:this,event:t,data:e})))}}function Ji(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const Ti=It`
930
+ `;function xi(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Pi{constructor(t,e){xi(this,"bundleId",void 0),xi(this,"initPromise",void 0),xi(this,"globalPropertyState",void 0),xi(this,"onGlobalPropertyStateChange",void 0),this.bundleId=t,this.initPromise=this.getOrCreateGlobalPropertyState().then((t=>{this.globalPropertyState=t})),this.onGlobalPropertyStateChange=e}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=this.globalPropertyState.aspects.find((e=>e.name===t));if(e)return e.value}async setAspect(t,e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=zt(this.globalPropertyState),n=this.globalPropertyState.aspects.find((e=>e.name===t));n?n.value=e:this.globalPropertyState.aspects.push({name:t,value:e}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(A,this.globalPropertyState)}async updateGlobalPropertyState(){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=await ye.getShadowGraphqlClient().mutate({mutation:Yi,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects}});if(!t.data?.globalPropertyStateUpdate)throw new Error("Unable to update global property state");this.globalPropertyState=t.data.globalPropertyStateUpdate}async getOrCreateGlobalPropertyState(){const t=await ye.getShadowGraphqlClient().query({query:vi,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId}});if(t.data.globalPropertyState&&t.data.globalPropertyState.id)return t.data.globalPropertyState;const e=await ye.getShadowGraphqlClient().mutate({mutation:Si,variables:{bundleId:this.bundleId}});if(e.data?.globalPropertyStateCreate&&e.data.globalPropertyStateCreate.id)return e.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}function Ni(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Ri{constructor(t){Ni(this,"state",void 0),this.setState(t)}setState(t){t&&(this.state=JSON.parse(t))}applyStateToWorkflowExperience(t){if(!this.state||!t?.getWorkflowManager()?.getModelContainer())return;const e=this.state.transactions.find((e=>e.transactionId===t.getWorkflowManager().getTransaction().id&&e.transform))?.transform;if(!e)return;const A=t.getWorkflowManager().getModelContainer();A.position=e.position,A.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},A.scale=e.scale}setWorkflowExperienceTransform(t,e){if(!t?.getWorkflowManager()?.getModelContainer())return;const A=t.getWorkflowManager().getModelContainer();A.position=e.position,A.rotation={x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},A.scale=e.scale;const n=t.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find((t=>t.transactionId===n));a?a.transform=e:this.state.transactions.push({transactionId:n,transform:e})}removeStateForTransaction(t){if(!this.state||!this.state.transactions)return;const e=this.state.transactions.findIndex((e=>e.transactionId===t));-1!==e&&this.state.transactions.splice(e,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}}function Hi(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class bi{constructor(t){Hi(this,"collection",void 0),this.collection=t}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){return this.collection.products.map((t=>new ki(t)))}getResource(){return this.collection}}class ki{constructor(t){Hi(this,"product",void 0),this.product=t}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(t){const e=(this.product.integrationProducts||[]).find((e=>!!e.integration?.type&&e.integration?.type===t));if(!e)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return e}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}}function Ui(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}class Gi{constructor(t,e,A,n){Ui(this,"client",void 0),Ui(this,"id",void 0),Ui(this,"name",void 0),Ui(this,"metadata",void 0),Ui(this,"productCollection",void 0),Ui(this,"bundleStateManager",void 0),Ui(this,"globalConfiguration",void 0),Ui(this,"globalPropertyStateManager",void 0),Ui(this,"globalPropertyHandleService",void 0),Ui(this,"eventListeners",new Map),Ui(this,"initializationPromise",void 0),Ui(this,"workflowExperiences",[]),Ui(this,"previewService",void 0),this.client=t,this.id=e.id,this.name=e.name||"",this.metadata=new Map(e.metadata?.map((t=>[t.key,t.value]))||[]),this.productCollection=e.productCollection,this.bundleStateManager=new Ri(e.bundleStateData),this.globalConfiguration=this.productCollection?.globalPropertyConfiguration,this.globalPropertyStateManager=new Pi(this.id,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new fi(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingBundles(e.transactions?.map((t=>t.id))||[],n)}getInitializationPromise(){return this.initializationPromise}addEventListener(t,e){this.eventListeners.set(t,[...this.eventListeners.get(t)||[],e])}removeEventListener(t,e){const A=this.eventListeners.get(t)||[],n=A.indexOf(e);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(t){return this.name=t,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(t){return this.metadata=new Map(t),this.updateBundle()}setNameAndMetadata(t,e){return this.name=t,this.metadata=new Map(e),this.updateBundle()}hasGlobalProperties(){return!!this.globalConfiguration&&this.globalConfiguration.aspects.length>0}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((t=>t.getType()===Dt.Option)).map((t=>t.getCurrentVariant()?.getPrice()||0)).reduce(((t,e)=>t+e),0)}getTotalSubunits(){return this.workflowExperiences.map((t=>t.getTotalPriceSubunits())).reduce(((t,e)=>t+e),0)}getProductCollection(){return this.productCollection?new bi(this.productCollection):void 0}async addWorkflowExperience(t){await this.appendWorkflowExperience(t),await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))}async addWorkflowExperiences(t){const e=t.map((t=>t.getWorkflowManager().getTransaction().id)),A=e.map((t=>this.workflowExperiences.find((e=>e.getWorkflowManager().getTransaction().id===t))));if(A.some((t=>!!t)))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter((t=>!!t)).map((t=>t?.getWorkflowManager().getTransaction().id)).join(", "));const n=we.getMap("transactionOwnerIds")||new Map,a=e.map((t=>n.get(t)));await ye.getShadowGraphqlClient().mutate({mutation:hi,variables:{id:this.id,transactionIds:e,transactionOwnerIds:a}}).catch((t=>{console.error(t)})),this.workflowExperiences.push(...t),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const e of t)await this.injectExperienceIntoPreviewService(e);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState(t))))})()])}async appendWorkflowExperience(t,e=!0){const A=t.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===A)))throw new Error("Unable to add transaction to bundle - Already Exists!");const n=(we.getMap("transactionOwnerIds")||new Map).get(A);await ye.getShadowGraphqlClient().mutate({mutation:wi,variables:{id:this.id,transactionId:A},context:{transactionOwnerId:n}}),e&&this.workflowExperiences.push(t)}async removeWorkflowExperience(t){const e=this.workflowExperiences.indexOf(t);await this.removeTransaction(e,this.workflowExperiences[e].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(t){await this.removeTransactions(t.map((t=>t.getWorkflowManager().getTransaction())))}async removeWorkflowExperienceByTransaction(t){const e=this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id));await this.removeTransaction(e,t)}async removeWorkflowExperiencesByTransactions(t){await this.removeTransactions(t)}async removeTransaction(t,e,A=!0){if(!(t>-1))throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+e.id);{const n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===e.id));this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(e.id),await ye.getShadowGraphqlClient().mutate({mutation:Ei,variables:{id:this.id,transactionId:e.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),A&&(this.workflowExperiences.splice(t,1),await this.updateTransactionOrder())}}async removeTransactions(t){const e=t.map((t=>this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id))));if(e.some((t=>-1===t)))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+t.filter(((t,A)=>-1===e[A])).map((t=>t.id)).join(", "));const A=t.map((t=>this.workflowExperiences.splice(this.workflowExperiences.findIndex((e=>e.getWorkflowManager().getTransaction().id===t.id)),1)[0]));this.previewService&&A.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t.forEach((t=>this.bundleStateManager.removeStateForTransaction(t.id))),await ye.getShadowGraphqlClient().mutate({mutation:ui,variables:{id:this.id,transactionIds:t.map((t=>t.id)),name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}}),await this.updateTransactionOrder()}async insertWorkflowExperience(t,e){await this.appendWorkflowExperience(t,!1),this.workflowExperiences.splice(e,0,t),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const e=await this.getGlobalProperties();await Promise.all(e.map((e=>e.applyGlobalState([t]))))})()])}async replaceWorkflowExperience(t,e){if(t<0||t>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[t];if(A.getWorkflowManager().getTransaction().id===e.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(t,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(e,!1)]),this.workflowExperiences[t]=e,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map((t=>t.applyGlobalState([e]))))})()])}async swapWorkflowExperiences(t,e){if(t<0||t>=this.workflowExperiences.length||e<0||e>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(t===e)return;const A=this.workflowExperiences[t];this.workflowExperiences[t]=this.workflowExperiences[e],this.workflowExperiences[e]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(t){this.workflowExperiences=this.workflowExperiences.sort(t),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(t,e){const A=await ye.getShadowGraphqlClient().mutate({mutation:Ci,variables:{id:this.id,details:t,type:e||BA.Owner}});if(!A.data?.bundleAddStakeholder)throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async updateStakeholders(t){const e=await ye.getShadowGraphqlClient().mutate({mutation:Qi,variables:{id:this.id,input:t}});if(!e.data?.bundleUpdateStakeholders)throw new Error("Bundle not found!");const A=e.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const t=await ye.getShadowGraphqlClient().query({query:gi,errorPolicy:"all",variables:{id:this.id}});if(!t.data.bundles||0===t.data.bundles.length)throw new Error("Bundle not found!");const e=t.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(e),e}storeStakeholderCustomers(t){t.forEach((t=>{t.customer&&this.client.storeCustomer(t.customer)}))}async finish(t){return await Ai(this.workflowExperiences.map((t=>({workflowManager:t.getWorkflowManager(),workflow:t.getWorkflowManager().getWorkflow(),layouts:t.getWorkflowManager().getLayouts(),getReducerState:()=>t.getCommandContext().getState(),product:t.getWorkflowManager().getProduct(),transaction:t.getWorkflowManager().getTransaction(),workflowSelections:t.getWorkflowManager().getWorkflowSelections(),designName:t.getWorkflowManager().getWorkflow().name,variationRecords:t.getWorkflowManager().getVariationRecords(),updateVariationRecords:e=>t.updateVariationRecords(e),workflowMetadata:t.getWorkflowManager().getWorkflowMetadata()}))),t??(()=>{}))}getPreviewService(){return this.previewService}async setPreviewService(t){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach((t=>t.getWorkflowManager().ejectFromPreviewService())),t))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);t&&t.registerModelLoadEventListener&&t.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==t&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=t}setWorkflowExperienceTransform(t,e){return this.bundleStateManager.setWorkflowExperienceTransform(t,e),this.updateBundle()}onModelLoadEvent(t){"unload"!==t.eventType&&t.modelContainer&&(t.modelContainer.registerMaterialSelectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!0))),t.modelContainer.registerMaterialDeselectedCallback((()=>this.onModelSelectedEvent(t.modelContainer,!1))))}onModelSelectedEvent(t,e){if(t&&t.metadata&&t.metadata instanceof Map&&t.metadata.has("workflowManager")){const A=t.metadata.get("workflowManager").getTransaction(),n=this.workflowExperiences.find((t=>t.getWorkflowManager().getTransaction().id===A.id));n&&this.fireEvent(e?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:n})}}async injectExperienceIntoPreviewService(t){if(this.previewService){const e=t.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(t)}catch(t){console.error(`Unable to apply state to workflow experience: ${t}`)}await e}}async loadExistingBundles(t,e){if(0===t.length)return;const A=await this.client.getWorkflowExperiences(t.map((t=>({type:"transaction",transactionId:t}))),e);if(this.workflowExperiences=A,this.previewService)for(const t of A)await this.injectExperienceIntoPreviewService(t)}async updateBundle(){if(!(await ye.getShadowGraphqlClient().mutate({mutation:di,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map((([t,e])=>({key:t,value:e}))),bundleStateData:this.bundleStateManager.getSerializedState()}})).data?.bundleUpdate)throw new Error("Bundle not found!")}async updateTransactionOrder(){await ye.getShadowGraphqlClient().mutate({mutation:pi,variables:{id:this.id,transactionIds:this.workflowExperiences.map((t=>t.getWorkflowManager().getTransaction().id))}})}async checkConditionalHandlesChanged(t,e){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,t),a=this.globalPropertyHandleService.applyConditionsFromState(A,e);(()=>{if(n.length!==a.length)return!0;for(let t=0;t<n.length;t++)if(n[t].getName()!==a[t].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:a})}fireEvent(t,e){(this.eventListeners.get(t)||[]).forEach((A=>A({bundle:this,event:t,data:e})))}}function Ji(t,e,A){return(e=function(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var A=t[Symbol.toPrimitive];if(void 0!==A){var n=A.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}(e))in t?Object.defineProperty(t,e,{value:A,enumerable:!0,configurable:!0,writable:!0}):t[e]=A,t}const Ti=It`
931
931
  mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
932
932
  processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
933
933
  id
package/dist/types.d.ts CHANGED
@@ -2097,6 +2097,7 @@ export abstract class GlobalPropertyHandle {
2097
2097
  protected getSharedSteps(targetExperiences?: WorkflowExperience[]): import("stepHandles").StepHandle<import("index").AnyStepData>[];
2098
2098
  }
2099
2099
  interface GlobalPropertyStateManager {
2100
+ getInitializationPromise(): Promise<void>;
2100
2101
  getGlobalPropertyState(): GlobalPropertyState | undefined;
2101
2102
  getAspect(name: string): string | undefined;
2102
2103
  setAspect(name: string, value: string): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "15.2.0",
3
+ "version": "15.2.1",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",