@spiffcommerce/core 21.15.2-0 → 21.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2246,6 +2246,11 @@ interface Transaction {
2246
2246
  printFileUrl3?: string;
2247
2247
  printFileUrl4?: string;
2248
2248
  printFileUrl5?: string;
2249
+ printFileName1?: string;
2250
+ printFileName2?: string;
2251
+ printFileName3?: string;
2252
+ printFileName4?: string;
2253
+ printFileName5?: string;
2249
2254
  }
2250
2255
  /**
2251
2256
  * An integration product represents the connection of a product in SpiffCommerce with
package/dist/index.js CHANGED
@@ -1082,6 +1082,11 @@ const oe = D`
1082
1082
  printFileUrl3
1083
1083
  printFileUrl4
1084
1084
  printFileUrl5
1085
+ printFileName1
1086
+ printFileName2
1087
+ printFileName3
1088
+ printFileName4
1089
+ printFileName5
1085
1090
  product {
1086
1091
  id
1087
1092
  basePrice
@@ -8824,12 +8829,10 @@ class je {
8824
8829
  * @returns The integration if found. Throws an error if not found as this data is typically a neccesity.
8825
8830
  */
8826
8831
  getIntegrationByType(e, t) {
8827
- const A = this.product.integrationProducts || [];
8828
- console.log(`TCC DEBUG: type ${e} extId ${t} ips: ${JSON.stringify(A, null, 2)}`);
8829
- const a = A.find((n) => {
8830
- var r, g, B, l;
8832
+ const a = (this.product.integrationProducts || []).find((n) => {
8833
+ var r, g, B;
8831
8834
  const i = (r = n.integration) == null ? void 0 : r.type, s = ((g = n.integration) == null ? void 0 : g.type) === e, o = t ? ((B = n.integration) == null ? void 0 : B.externalIntegrationId) === t : !0;
8832
- return console.log(`TCC DEBUG: ip ${n.id}, hasType ${i} matches ${s} extId to match ${(l = n.integration) == null ? void 0 : l.externalIntegrationId}, extIdMatches ${o}`), i && s && o;
8835
+ return i && s && o;
8833
8836
  });
8834
8837
  if (!a)
8835
8838
  throw new Error(
@@ -438,6 +438,11 @@
438
438
  printFileUrl3
439
439
  printFileUrl4
440
440
  printFileUrl5
441
+ printFileName1
442
+ printFileName2
443
+ printFileName3
444
+ printFileName4
445
+ printFileName5
441
446
  product {
442
447
  id
443
448
  basePrice
@@ -2370,7 +2375,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
2370
2375
  }
2371
2376
  }
2372
2377
  }
2373
- `;class ga{constructor(e,t,A,n,a){this.bundleId=e,this.bundleOwnerId=t,this.configuration=A,this.bundleOptions=a,this.initPromise=this.getOrCreateGlobalPropertyState().then(i=>{this.globalPropertyState=i}),this.onGlobalPropertyStateChange=n}setBundleOptions(e){this.bundleOptions=e}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=this.globalPropertyState.aspects.find(A=>A.name===e);if(t)return t.value}getAspectStorage(e){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");return(t=this.globalPropertyState.aspects.find(A=>A.name===e))==null?void 0:t.storage}async setAspect(e,t,A){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const n=this.configuration.aspects.find(o=>o.name===e);if(!n)throw new Error(`Failed to find configuration aspect with name: ${e}`);const a=se(this.globalPropertyState),i=this.globalPropertyState.aspects.find(o=>o.name===e);i?(i.value=t,A!==void 0&&(i.type=n.type,i.storage=A!==null?A:void 0)):this.globalPropertyState.aspects.push({name:e,value:t,...A===void 0?{}:{storage:A!==null?A:void 0,type:n.type}}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(a,this.globalPropertyState)}async setAspectStorage(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const A=this.configuration.aspects.find(i=>i.name===e);if(!A)throw new Error(`Failed to find configuration aspect with name: ${e}`);const n=se(this.globalPropertyState),a=this.globalPropertyState.aspects.find(i=>i.name===e);a?(a.storage=t!==null?t:void 0,a.type=A.type):this.globalPropertyState.aspects.push({name:e,value:"",type:A.type,storage:t!==null?t:void 0}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){var t,A;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:ra,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects.map(n=>{const a=n.type&&n.storage?{}:void 0;if(a)switch(n.type){case l.AspectType.FileUpload:{a.fileUpload=n.storage;break}}return{name:n.name,value:n.value,type:n.type,storage:a}})},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(t=this.bundleOptions)==null?void 0:t.additionalHeaders}}});if((A=e.data)!=null&&A.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A,n,a;const e=await N.getShadowGraphqlClient().query({query:ca,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(A=this.bundleOptions)==null?void 0:A.additionalHeaders}}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:sa,variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(n=this.bundleOptions)==null?void 0:n.additionalHeaders}}});if((a=t.data)!=null&&a.globalPropertyStateCreate&&t.data.globalPropertyStateCreate.id)return t.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}class la{constructor(e){this.setState(e)}setState(e){e&&(this.state=JSON.parse(e))}applyStateToWorkflowExperience(e){var i;if(!this.state||!((i=e==null?void 0:e.getWorkflowManager())!=null&&i.getModelContainer()))return;const t=this.state.transactions.find(o=>o.transactionId===e.getWorkflowManager().getTransaction().id);if(!t)return;const A=this.getTransformToApply(t);if(!A)return;const n=this.flipTransform(A,e.getWorkflowManager().getPreviewService()),a=e.getWorkflowManager().getModelContainer();a.position=n.position,a.rotation=n.rotation,a.scale=n.scale}getTransformToApply(e){return e.activeTransform&&e.transforms?e.transforms[e.activeTransform]:e.transform}updateWorkflowExperienceTransform(e,t,A){const n=e.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find(i=>i.transactionId===n);a?(a.transforms||(a.transforms={}),a.transforms[t]=A):this.state.transactions.push({transactionId:n,activeTransform:t,transforms:{[t]:A}})}activateWorkflowExperienceTransform(e,t){var s,r;if(!((s=e==null?void 0:e.getWorkflowManager())!=null&&s.getModelContainer())||!this.state)return;const A=e.getWorkflowManager().getTransaction().id,n=this.state.transactions.find(g=>g.transactionId===A),a=(r=n==null?void 0:n.transforms)==null?void 0:r[t];if(!a)return;const i=this.flipTransform(a,e.getWorkflowManager().getPreviewService()),o=e.getWorkflowManager().getModelContainer();o.position=i.position,o.rotation=i.rotation,o.scale=i.scale,n.activeTransform=t}removeStateForTransaction(e){if(!this.state||!this.state.transactions)return;const t=this.state.transactions.findIndex(A=>A.transactionId===e);t!==-1&&this.state.transactions.splice(t,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}flipTransform(e,t){return t&&t.flipTransform?t.flipTransform(e.position,{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},e.scale):{position:e.position,rotation:{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},scale:e.scale}}}class oA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.map(e=>new Ne(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new Ne(t));const e=await N.getShadowGraphqlClient().query({query:Xn,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new Ne(t))}getTransformCollection(){if(this.collection.transformCollection)return new sA(this.collection.transformCollection)}getResource(){return this.collection}}class Ne{constructor(e){this.product=e.product,this.productResource=e}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(e,t){const A=this.product.integrationProducts||[];console.log(`TCC DEBUG: type ${e} extId ${t} ips: ${JSON.stringify(A,null,2)}`);const n=A.find(a=>{var r,g,w,d;const i=(r=a.integration)==null?void 0:r.type,o=((g=a.integration)==null?void 0:g.type)===e,s=t?((w=a.integration)==null?void 0:w.externalIntegrationId)===t:!0;return console.log(`TCC DEBUG: ip ${a.id}, hasType ${i} matches ${o} extId to match ${(d=a.integration)==null?void 0:d.externalIntegrationId}, extIdMatches ${s}`),i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new v("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");const t=this.productResource.workflowId;if(t){const n=e.find(a=>a.workflowName===t);if(n)return new ie(n)}const A=e[0];return new ie(A)}getAllWorkflows(){if((this.product.workflows||[]).length===0)throw new v("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");return this.product.workflows.sort((t,A)=>(t.index??0)-(A.index??0)).map(t=>new ie(t))}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}getBasePrice(e){var n,a,i,o;const t=this.product.basePrice||0;if(!e)return t;if(!e.integrationType&&!e.externalId&&!e.integrationId)throw new Error("You must provide at least one of the following fields on the includeAdditionalProduct object: integrationType, externalId, integrationId");let A;return e.integrationId?A=(n=this.product.integrationProducts)==null?void 0:n.find(s=>{var r;return((r=s.integration)==null?void 0:r.id)===e.integrationId}):e.externalId?A=(a=this.product.integrationProducts)==null?void 0:a.find(s=>{var r;return((r=s.integration)==null?void 0:r.externalIntegrationId)===e.externalId}):A=(i=this.product.integrationProducts)==null?void 0:i.find(s=>{var r;return((r=s.integration)==null?void 0:r.type)===e.integrationType}),(o=A==null?void 0:A.additionalIntegrationProduct)!=null&&o.product?t+(A.additionalIntegrationProduct.product.basePrice||0):t}}class ie{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class sA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new rA(e))}}class rA{constructor(e){this.transform=e}getId(){return this.transform.id}getName(){return this.transform.name}get(){return{position:this.transform.position,rotation:this.transform.rotation,scale:this.transform.scale}}}class cA{constructor(e,t,A,n,a,i){var o,s,r;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((o=t.metadata)==null?void 0:o.map(g=>[g.key,g.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new la(t.bundleStateData),this.globalPropertyStateManager=new ga(this.id,this.ownerId,(s=this.productCollection)==null?void 0:s.globalPropertyConfiguration,this.checkConditionalHandlesChanged.bind(this),i),this.globalPropertyHandleService=new oa(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingWorkflowExperiences(((r=t.transactions)==null?void 0:r.map(g=>g.id))||[],n)}setBundleOptions(e){this.globalPropertyStateManager.setBundleOptions(e)}getInitializationPromise(){return this.initializationPromise}addEventListener(e,t){this.eventListeners.set(e,[...this.eventListeners.get(e)||[],t])}removeEventListener(e,t){const A=this.eventListeners.get(e)||[],n=A.indexOf(t);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(e){return this.name=e,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(e){return this.metadata=new Map(e),this.updateBundle()}setNameAndMetadata(e,t){return this.name=e,this.metadata=new Map(t),this.updateBundle()}hasGlobalProperties(){var e;return!!((e=this.productCollection)!=null&&e.globalPropertyConfiguration)}getGlobalPropertyConfiguration(){var e;return(e=this.productCollection)==null?void 0:e.globalPropertyConfiguration}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter(A=>A.getType()===l.AspectType.Option).map(A=>{var n;return((n=A.getCurrentVariant())==null?void 0:n.getPrice())||0}).reduce((A,n)=>A+n,0)}getTotalSubunits(){return this.workflowExperiences.map(e=>e.getTotalPriceSubunits()).reduce((e,t)=>e+t,0)}getProductCollection(){return this.productCollection?new oA(this.productCollection):void 0}async addWorkflowExperience(e){e.setBundle(this),await this.appendWorkflowExperience(e),await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map(A=>A.applyGlobalState([e])))}async addWorkflowExperiences(e){const t=e.map(i=>i.getWorkflowManager().getTransaction().id),A=t.map(i=>this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===i));if(A.some(i=>!!i))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter(i=>!!i).map(i=>i==null?void 0:i.getWorkflowManager().getTransaction().id).join(", "));const n=Y.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:_n,variables:{id:this.id,transactionIds:t,transactionOwnerIds:a},context:{bundleOwnerId:this.ownerId}}).catch(i=>{console.error(i)}),this.workflowExperiences.push(...e),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const o of e)await this.injectExperienceIntoPreviewService(o);const i=await this.getGlobalProperties();await Promise.all(i.map(o=>o.applyGlobalState(e)))})()]),this.workflowExperiences.forEach(i=>i.setBundle(this)),this.workflowExperiences.forEach(i=>i.checkForPriceBreakChanges())}async appendWorkflowExperience(e,t=!0){const A=e.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===A))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(Y.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:$n,variables:{id:this.id,transactionId:A},context:{bundleOwnerId:this.ownerId,transactionOwnerId:i}}),t&&(this.workflowExperiences.push(e),this.workflowExperiences.forEach(o=>o.checkForPriceBreakChanges()))}async removeWorkflowExperience(e){const t=this.workflowExperiences.indexOf(e);await this.removeTransaction(t,this.workflowExperiences[t].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(e){await this.removeTransactions(e.map(t=>t.getWorkflowManager().getTransaction()))}async removeWorkflowExperienceByTransaction(e){const t=this.workflowExperiences.findIndex(A=>A.getWorkflowManager().getTransaction().id===e.id);await this.removeTransaction(t,e)}async removeWorkflowExperiencesByTransactions(e){await this.removeTransactions(e)}async removeTransaction(e,t,A=!0){if(e>-1){const n=this.workflowExperiences.find(a=>a.getWorkflowManager().getTransaction().id===t.id);n.setBundle(void 0),this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(t.id),await N.getShadowGraphqlClient().mutate({mutation:ea,variables:{id:this.id,transactionId:t.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([a,i])=>({key:a,value:i})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),A&&(this.workflowExperiences.splice(e,1),this.workflowExperiences.forEach(a=>a.checkForPriceBreakChanges()),n.checkForPriceBreakChanges(),await this.updateTransactionOrder())}else throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+t.id)}async removeTransactions(e){const t=e.map(n=>this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id));if(t.some(n=>n===-1))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+e.filter((n,a)=>t[a]===-1).map(n=>n.id).join(", "));const A=e.map(n=>this.workflowExperiences.splice(this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id),1)[0]);A.forEach(n=>n.setBundle(void 0)),[...this.workflowExperiences,...A].forEach(n=>n.checkForPriceBreakChanges()),this.previewService&&A.forEach(n=>n.getWorkflowManager().ejectFromPreviewService()),e.forEach(n=>this.bundleStateManager.removeStateForTransaction(n.id)),await N.getShadowGraphqlClient().mutate({mutation:ta,variables:{id:this.id,transactionIds:e.map(n=>n.id),name:this.name,metadata:Array.from(this.metadata.entries()).map(([n,a])=>({key:n,value:a})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),await this.updateTransactionOrder()}async insertWorkflowExperience(e,t){await this.appendWorkflowExperience(e,!1),this.workflowExperiences.splice(t,0,e),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const A=await this.getGlobalProperties();await Promise.all(A.map(n=>n.applyGlobalState([e])))})()])}async replaceWorkflowExperience(e,t){if(e<0||e>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[e];if(A.getWorkflowManager().getTransaction().id===t.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(e,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(t,!1)]),this.workflowExperiences[e]=t,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const n=await this.getGlobalProperties();await Promise.all(n.map(a=>a.applyGlobalState([t])))})()])}async swapWorkflowExperiences(e,t){if(e<0||e>=this.workflowExperiences.length||t<0||t>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(e===t)return;const A=this.workflowExperiences[e];this.workflowExperiences[e]=this.workflowExperiences[t],this.workflowExperiences[t]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(e){this.workflowExperiences=this.workflowExperiences.sort(e),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(e,t){var a;const A=await N.getShadowGraphqlClient().mutate({mutation:Aa,variables:{id:this.id,details:e,type:t||Be.Owner},context:{bundleOwnerId:this.ownerId}});if(!((a=A.data)!=null&&a.bundleAddStakeholder))throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async removeStakeholder(e){var A;if(!((A=(await N.getShadowGraphqlClient().mutate({mutation:na,variables:{id:this.id,emailAddress:e},context:{bundleOwnerId:this.ownerId}})).data)!=null&&A.bundleRemoveStakeholder))throw new Error("Bundle not found!")}async updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:aa,variables:{id:this.id,input:e},context:{bundleOwnerId:this.ownerId}});if(!((n=t.data)!=null&&n.bundleUpdateStakeholders))throw new Error("Bundle not found!");const A=t.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const e=await N.getShadowGraphqlClient().query({query:Vn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:this.id},context:{bundleOwnerId:this.ownerId}});if(!e.data.bundles||e.data.bundles.length===0)throw new Error("Bundle not found!");const t=e.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(t),t}storeStakeholderCustomers(e){e.forEach(t=>{t.customer&&this.client.storeCustomer(t.customer)})}async finish(e,t){const A=await yn(this.workflowExperiences.map(n=>({workflowManager:n.getWorkflowManager(),workflow:n.getWorkflowManager().getWorkflow(),layouts:n.getWorkflowManager().getLayouts(),getReducerState:()=>n.getCommandContext().getState(),product:n.getWorkflowManager().getProduct(),transaction:n.getWorkflowManager().getTransaction(),workflowSelections:n.getWorkflowManager().getWorkflowSelections(),designName:n.getWorkflowManager().getWorkflow().name,workflowMetadata:n.getWorkflowManager().getWorkflowMetadata()})),e??(()=>{}),t?(n,a)=>{const i=this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===a);return i?t(i):(console.warn("SpiffCommerce - Bundle create design - Unable to find experience for transaction: "+a),Promise.resolve(void 0))}:void 0);return{bundleId:this.id,items:A}}getPreviewService(){return this.previewService}async setPreviewService(e){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach(t=>t.getWorkflowManager().ejectFromPreviewService()),e))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);e&&e.registerModelLoadEventListener&&e.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==e&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=e}updateWorkflowExperienceTransform(e,t,A){return this.bundleStateManager.updateWorkflowExperienceTransform(e,t,A),this.updateBundle()}activateWorkflowExperienceTransform(e,t){return this.bundleStateManager.activateWorkflowExperienceTransform(e,t),this.updateBundle()}onModelLoadEvent(e){e.eventType==="unload"||!e.modelContainer||(e.modelContainer.registerMaterialSelectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!0)),e.modelContainer.registerMaterialDeselectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!1)))}onModelSelectedEvent(e,t){if(e&&e.metadata&&e.metadata instanceof Map&&e.metadata.has("workflowManager")){const n=e.metadata.get("workflowManager").getTransaction(),a=this.workflowExperiences.find(i=>i.getWorkflowManager().getTransaction().id===n.id);a&&this.fireEvent(t?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:a})}}async injectExperienceIntoPreviewService(e){if(this.previewService){const t=e.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(e)}catch(A){console.error(`Unable to apply state to workflow experience: ${A}`)}await t}}async loadExistingWorkflowExperiences(e,t){if(e.length===0)return;const A=await this.client.getWorkflowExperiences(e.map(n=>({type:"transaction",transactionId:n})),t);if(A.forEach(n=>n.setBundle(this)),A.forEach(n=>n.checkForPriceBreakChanges()),this.workflowExperiences=A,this.previewService)for(const n of A)await this.injectExperienceIntoPreviewService(n)}async updateBundle(){var t;if(!((t=(await N.getShadowGraphqlClient().mutate({mutation:Zn,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([A,n])=>({key:A,value:n})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}})).data)!=null&&t.bundleUpdate))throw new Error("Bundle not found!")}async updateTransactionOrder(){await N.getShadowGraphqlClient().mutate({mutation:ia,variables:{id:this.id,transactionIds:this.workflowExperiences.map(e=>e.getWorkflowManager().getTransaction().id)},context:{bundleOwnerId:this.ownerId}})}async checkConditionalHandlesChanged(e,t){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,e),a=this.globalPropertyHandleService.applyConditionsFromState(A,t);(()=>{if(n.length!==a.length)return!0;for(let o=0;o<n.length;o++)if(n[o].getName()!==a[o].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:a})}fireEvent(e,t){(this.eventListeners.get(e)||[]).forEach(n=>n({bundle:this,event:e,data:t}))}}const da=M.gql`
2378
+ `;class ga{constructor(e,t,A,n,a){this.bundleId=e,this.bundleOwnerId=t,this.configuration=A,this.bundleOptions=a,this.initPromise=this.getOrCreateGlobalPropertyState().then(i=>{this.globalPropertyState=i}),this.onGlobalPropertyStateChange=n}setBundleOptions(e){this.bundleOptions=e}getInitializationPromise(){return this.initPromise}getGlobalPropertyState(){return this.globalPropertyState}getAspect(e){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const t=this.globalPropertyState.aspects.find(A=>A.name===e);if(t)return t.value}getAspectStorage(e){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");return(t=this.globalPropertyState.aspects.find(A=>A.name===e))==null?void 0:t.storage}async setAspect(e,t,A){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const n=this.configuration.aspects.find(o=>o.name===e);if(!n)throw new Error(`Failed to find configuration aspect with name: ${e}`);const a=se(this.globalPropertyState),i=this.globalPropertyState.aspects.find(o=>o.name===e);i?(i.value=t,A!==void 0&&(i.type=n.type,i.storage=A!==null?A:void 0)):this.globalPropertyState.aspects.push({name:e,value:t,...A===void 0?{}:{storage:A!==null?A:void 0,type:n.type}}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(a,this.globalPropertyState)}async setAspectStorage(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");if(!this.configuration)throw new Error("Global property configuration not linked to the state manager.");const A=this.configuration.aspects.find(i=>i.name===e);if(!A)throw new Error(`Failed to find configuration aspect with name: ${e}`);const n=se(this.globalPropertyState),a=this.globalPropertyState.aspects.find(i=>i.name===e);a?(a.storage=t!==null?t:void 0,a.type=A.type):this.globalPropertyState.aspects.push({name:e,value:"",type:A.type,storage:t!==null?t:void 0}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(n,this.globalPropertyState)}async updateGlobalPropertyState(){var t,A;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:ra,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects.map(n=>{const a=n.type&&n.storage?{}:void 0;if(a)switch(n.type){case l.AspectType.FileUpload:{a.fileUpload=n.storage;break}}return{name:n.name,value:n.value,type:n.type,storage:a}})},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(t=this.bundleOptions)==null?void 0:t.additionalHeaders}}});if((A=e.data)!=null&&A.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A,n,a;const e=await N.getShadowGraphqlClient().query({query:ca,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(A=this.bundleOptions)==null?void 0:A.additionalHeaders}}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:sa,variables:{bundleId:this.bundleId},context:{headers:{bundleOwnerId:this.bundleOwnerId,...(n=this.bundleOptions)==null?void 0:n.additionalHeaders}}});if((a=t.data)!=null&&a.globalPropertyStateCreate&&t.data.globalPropertyStateCreate.id)return t.data.globalPropertyStateCreate;throw new Error(`Unable to create global property state for bundle: ${this.bundleId}`)}}class la{constructor(e){this.setState(e)}setState(e){e&&(this.state=JSON.parse(e))}applyStateToWorkflowExperience(e){var i;if(!this.state||!((i=e==null?void 0:e.getWorkflowManager())!=null&&i.getModelContainer()))return;const t=this.state.transactions.find(o=>o.transactionId===e.getWorkflowManager().getTransaction().id);if(!t)return;const A=this.getTransformToApply(t);if(!A)return;const n=this.flipTransform(A,e.getWorkflowManager().getPreviewService()),a=e.getWorkflowManager().getModelContainer();a.position=n.position,a.rotation=n.rotation,a.scale=n.scale}getTransformToApply(e){return e.activeTransform&&e.transforms?e.transforms[e.activeTransform]:e.transform}updateWorkflowExperienceTransform(e,t,A){const n=e.getWorkflowManager().getTransaction().id;this.state?this.state.transactions||(this.state.transactions=[]):this.state={transactions:[]};const a=this.state.transactions.find(i=>i.transactionId===n);a?(a.transforms||(a.transforms={}),a.transforms[t]=A):this.state.transactions.push({transactionId:n,activeTransform:t,transforms:{[t]:A}})}activateWorkflowExperienceTransform(e,t){var s,r;if(!((s=e==null?void 0:e.getWorkflowManager())!=null&&s.getModelContainer())||!this.state)return;const A=e.getWorkflowManager().getTransaction().id,n=this.state.transactions.find(g=>g.transactionId===A),a=(r=n==null?void 0:n.transforms)==null?void 0:r[t];if(!a)return;const i=this.flipTransform(a,e.getWorkflowManager().getPreviewService()),o=e.getWorkflowManager().getModelContainer();o.position=i.position,o.rotation=i.rotation,o.scale=i.scale,n.activeTransform=t}removeStateForTransaction(e){if(!this.state||!this.state.transactions)return;const t=this.state.transactions.findIndex(A=>A.transactionId===e);t!==-1&&this.state.transactions.splice(t,1)}getSerializedState(){if(this.state)return JSON.stringify(this.state)}flipTransform(e,t){return t&&t.flipTransform?t.flipTransform(e.position,{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},e.scale):{position:e.position,rotation:{x:e.rotation.x*Math.PI/180,y:e.rotation.y*Math.PI/180,z:e.rotation.z*Math.PI/180},scale:e.scale}}}class oA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getProducts(){if(!this.collection.productCollectionProducts)throw new Error("Failed to find products on collection. Ensure you fetch them first!");return this.collection.productCollectionProducts.map(e=>new Ne(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new Ne(t));const e=await N.getShadowGraphqlClient().query({query:Xn,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new Ne(t))}getTransformCollection(){if(this.collection.transformCollection)return new sA(this.collection.transformCollection)}getResource(){return this.collection}}class Ne{constructor(e){this.product=e.product,this.productResource=e}getId(){return this.product.id}getName(){return this.product.name}getIntegrationByType(e,t){const n=(this.product.integrationProducts||[]).find(a=>{var r,g,w;const i=(r=a.integration)==null?void 0:r.type,o=((g=a.integration)==null?void 0:g.type)===e,s=t?((w=a.integration)==null?void 0:w.externalIntegrationId)===t:!0;return i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new v("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");const t=this.productResource.workflowId;if(t){const n=e.find(a=>a.workflowName===t);if(n)return new ie(n)}const A=e[0];return new ie(A)}getAllWorkflows(){if((this.product.workflows||[]).length===0)throw new v("No workflows found on product. This is generally due to a configuration error. Please confirm at least one workflow is configured for this product.");return this.product.workflows.sort((t,A)=>(t.index??0)-(A.index??0)).map(t=>new ie(t))}getIntegrations(){return this.product.integrationProducts||[]}getResource(){return this.product}getBasePrice(e){var n,a,i,o;const t=this.product.basePrice||0;if(!e)return t;if(!e.integrationType&&!e.externalId&&!e.integrationId)throw new Error("You must provide at least one of the following fields on the includeAdditionalProduct object: integrationType, externalId, integrationId");let A;return e.integrationId?A=(n=this.product.integrationProducts)==null?void 0:n.find(s=>{var r;return((r=s.integration)==null?void 0:r.id)===e.integrationId}):e.externalId?A=(a=this.product.integrationProducts)==null?void 0:a.find(s=>{var r;return((r=s.integration)==null?void 0:r.externalIntegrationId)===e.externalId}):A=(i=this.product.integrationProducts)==null?void 0:i.find(s=>{var r;return((r=s.integration)==null?void 0:r.type)===e.integrationType}),(o=A==null?void 0:A.additionalIntegrationProduct)!=null&&o.product?t+(A.additionalIntegrationProduct.product.basePrice||0):t}}class ie{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class sA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new rA(e))}}class rA{constructor(e){this.transform=e}getId(){return this.transform.id}getName(){return this.transform.name}get(){return{position:this.transform.position,rotation:this.transform.rotation,scale:this.transform.scale}}}class cA{constructor(e,t,A,n,a,i){var o,s,r;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((o=t.metadata)==null?void 0:o.map(g=>[g.key,g.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new la(t.bundleStateData),this.globalPropertyStateManager=new ga(this.id,this.ownerId,(s=this.productCollection)==null?void 0:s.globalPropertyConfiguration,this.checkConditionalHandlesChanged.bind(this),i),this.globalPropertyHandleService=new oa(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingWorkflowExperiences(((r=t.transactions)==null?void 0:r.map(g=>g.id))||[],n)}setBundleOptions(e){this.globalPropertyStateManager.setBundleOptions(e)}getInitializationPromise(){return this.initializationPromise}addEventListener(e,t){this.eventListeners.set(e,[...this.eventListeners.get(e)||[],t])}removeEventListener(e,t){const A=this.eventListeners.get(e)||[],n=A.indexOf(t);n>-1&&A.splice(n,1)}getClient(){return this.client}getId(){return this.id}getName(){return this.name}setName(e){return this.name=e,this.updateBundle()}getMetadata(){return new Map(this.metadata)}setMetadata(e){return this.metadata=new Map(e),this.updateBundle()}setNameAndMetadata(e,t){return this.name=e,this.metadata=new Map(t),this.updateBundle()}hasGlobalProperties(){var e;return!!((e=this.productCollection)!=null&&e.globalPropertyConfiguration)}getGlobalPropertyConfiguration(){var e;return(e=this.productCollection)==null?void 0:e.globalPropertyConfiguration}async getGlobalProperties(){return this.globalPropertyHandleService.applyConditionsFromState(await this.globalPropertyHandleService.getHandles(),this.getGlobalPropertyStateManager().getGlobalPropertyState())}getGlobalPropertyStateManager(){return this.globalPropertyStateManager}async getGlobalPropertyTotalSubunits(){return(await this.globalPropertyHandleService.getHandles()).filter(A=>A.getType()===l.AspectType.Option).map(A=>{var n;return((n=A.getCurrentVariant())==null?void 0:n.getPrice())||0}).reduce((A,n)=>A+n,0)}getTotalSubunits(){return this.workflowExperiences.map(e=>e.getTotalPriceSubunits()).reduce((e,t)=>e+t,0)}getProductCollection(){return this.productCollection?new oA(this.productCollection):void 0}async addWorkflowExperience(e){e.setBundle(this),await this.appendWorkflowExperience(e),await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map(A=>A.applyGlobalState([e])))}async addWorkflowExperiences(e){const t=e.map(i=>i.getWorkflowManager().getTransaction().id),A=t.map(i=>this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===i));if(A.some(i=>!!i))throw new Error("Unable to add transaction to bundle - Already Exists: "+A.filter(i=>!!i).map(i=>i==null?void 0:i.getWorkflowManager().getTransaction().id).join(", "));const n=Y.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:_n,variables:{id:this.id,transactionIds:t,transactionOwnerIds:a},context:{bundleOwnerId:this.ownerId}}).catch(i=>{console.error(i)}),this.workflowExperiences.push(...e),await Promise.all([this.updateTransactionOrder(),(async()=>{for(const o of e)await this.injectExperienceIntoPreviewService(o);const i=await this.getGlobalProperties();await Promise.all(i.map(o=>o.applyGlobalState(e)))})()]),this.workflowExperiences.forEach(i=>i.setBundle(this)),this.workflowExperiences.forEach(i=>i.checkForPriceBreakChanges())}async appendWorkflowExperience(e,t=!0){const A=e.getWorkflowManager().getTransaction().id;if(this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===A))throw new Error("Unable to add transaction to bundle - Already Exists!");const i=(Y.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:$n,variables:{id:this.id,transactionId:A},context:{bundleOwnerId:this.ownerId,transactionOwnerId:i}}),t&&(this.workflowExperiences.push(e),this.workflowExperiences.forEach(o=>o.checkForPriceBreakChanges()))}async removeWorkflowExperience(e){const t=this.workflowExperiences.indexOf(e);await this.removeTransaction(t,this.workflowExperiences[t].getWorkflowManager().getTransaction())}async removeWorkflowExperiences(e){await this.removeTransactions(e.map(t=>t.getWorkflowManager().getTransaction()))}async removeWorkflowExperienceByTransaction(e){const t=this.workflowExperiences.findIndex(A=>A.getWorkflowManager().getTransaction().id===e.id);await this.removeTransaction(t,e)}async removeWorkflowExperiencesByTransactions(e){await this.removeTransactions(e)}async removeTransaction(e,t,A=!0){if(e>-1){const n=this.workflowExperiences.find(a=>a.getWorkflowManager().getTransaction().id===t.id);n.setBundle(void 0),this.previewService&&n.getWorkflowManager().ejectFromPreviewService(),this.bundleStateManager.removeStateForTransaction(t.id),await N.getShadowGraphqlClient().mutate({mutation:ea,variables:{id:this.id,transactionId:t.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([a,i])=>({key:a,value:i})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),A&&(this.workflowExperiences.splice(e,1),this.workflowExperiences.forEach(a=>a.checkForPriceBreakChanges()),n.checkForPriceBreakChanges(),await this.updateTransactionOrder())}else throw new Error("Unable to remove workflow experience from bundle - Not Found! - "+t.id)}async removeTransactions(e){const t=e.map(n=>this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id));if(t.some(n=>n===-1))throw new Error("Unable to remove workflow experience from bundle - The following aren't included in the bundle: "+e.filter((n,a)=>t[a]===-1).map(n=>n.id).join(", "));const A=e.map(n=>this.workflowExperiences.splice(this.workflowExperiences.findIndex(a=>a.getWorkflowManager().getTransaction().id===n.id),1)[0]);A.forEach(n=>n.setBundle(void 0)),[...this.workflowExperiences,...A].forEach(n=>n.checkForPriceBreakChanges()),this.previewService&&A.forEach(n=>n.getWorkflowManager().ejectFromPreviewService()),e.forEach(n=>this.bundleStateManager.removeStateForTransaction(n.id)),await N.getShadowGraphqlClient().mutate({mutation:ta,variables:{id:this.id,transactionIds:e.map(n=>n.id),name:this.name,metadata:Array.from(this.metadata.entries()).map(([n,a])=>({key:n,value:a})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}}),await this.updateTransactionOrder()}async insertWorkflowExperience(e,t){await this.appendWorkflowExperience(e,!1),this.workflowExperiences.splice(t,0,e),await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(e);const A=await this.getGlobalProperties();await Promise.all(A.map(n=>n.applyGlobalState([e])))})()])}async replaceWorkflowExperience(e,t){if(e<0||e>=this.workflowExperiences.length)throw new Error("Unable to replace workflow experience in bundle - Index out of range!");const A=this.workflowExperiences[e];if(A.getWorkflowManager().getTransaction().id===t.getWorkflowManager().getTransaction().id)throw new Error("Unable to replace workflow experience in bundle - Same transaction!");await Promise.all([this.removeTransaction(e,A.getWorkflowManager().getTransaction(),!1),this.appendWorkflowExperience(t,!1)]),this.workflowExperiences[e]=t,await Promise.all([this.updateTransactionOrder(),(async()=>{await this.injectExperienceIntoPreviewService(t);const n=await this.getGlobalProperties();await Promise.all(n.map(a=>a.applyGlobalState([t])))})()])}async swapWorkflowExperiences(e,t){if(e<0||e>=this.workflowExperiences.length||t<0||t>=this.workflowExperiences.length)throw new Error("Unable to swap workflow experiences in bundle - Index out of range!");if(e===t)return;const A=this.workflowExperiences[e];this.workflowExperiences[e]=this.workflowExperiences[t],this.workflowExperiences[t]=A,await this.updateTransactionOrder()}getWorkflowExperiences(){return[...this.workflowExperiences]}async sortWorkflowExperiences(e){this.workflowExperiences=this.workflowExperiences.sort(e),await this.updateTransactionOrder()}getWorkflowExperienceCount(){return this.workflowExperiences.length}async addStakeholder(e,t){var a;const A=await N.getShadowGraphqlClient().mutate({mutation:Aa,variables:{id:this.id,details:e,type:t||Be.Owner},context:{bundleOwnerId:this.ownerId}});if(!((a=A.data)!=null&&a.bundleAddStakeholder))throw new Error("Bundle not found!");const n=A.data.bundleAddStakeholder.bundleStakeholders||[];this.storeStakeholderCustomers(n)}async removeStakeholder(e){var A;if(!((A=(await N.getShadowGraphqlClient().mutate({mutation:na,variables:{id:this.id,emailAddress:e},context:{bundleOwnerId:this.ownerId}})).data)!=null&&A.bundleRemoveStakeholder))throw new Error("Bundle not found!")}async updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:aa,variables:{id:this.id,input:e},context:{bundleOwnerId:this.ownerId}});if(!((n=t.data)!=null&&n.bundleUpdateStakeholders))throw new Error("Bundle not found!");const A=t.data.bundleUpdateStakeholders.bundleStakeholders||[];this.storeStakeholderCustomers(A)}async getAllStakeholders(){const e=await N.getShadowGraphqlClient().query({query:Vn,errorPolicy:"all",fetchPolicy:"no-cache",variables:{id:this.id},context:{bundleOwnerId:this.ownerId}});if(!e.data.bundles||e.data.bundles.length===0)throw new Error("Bundle not found!");const t=e.data.bundles[0].bundleStakeholders||[];return this.storeStakeholderCustomers(t),t}storeStakeholderCustomers(e){e.forEach(t=>{t.customer&&this.client.storeCustomer(t.customer)})}async finish(e,t){const A=await yn(this.workflowExperiences.map(n=>({workflowManager:n.getWorkflowManager(),workflow:n.getWorkflowManager().getWorkflow(),layouts:n.getWorkflowManager().getLayouts(),getReducerState:()=>n.getCommandContext().getState(),product:n.getWorkflowManager().getProduct(),transaction:n.getWorkflowManager().getTransaction(),workflowSelections:n.getWorkflowManager().getWorkflowSelections(),designName:n.getWorkflowManager().getWorkflow().name,workflowMetadata:n.getWorkflowManager().getWorkflowMetadata()})),e??(()=>{}),t?(n,a)=>{const i=this.workflowExperiences.find(o=>o.getWorkflowManager().getTransaction().id===a);return i?t(i):(console.warn("SpiffCommerce - Bundle create design - Unable to find experience for transaction: "+a),Promise.resolve(void 0))}:void 0);return{bundleId:this.id,items:A}}getPreviewService(){return this.previewService}async setPreviewService(e){if(this.workflowExperiences&&this.workflowExperiences.length>0&&(this.workflowExperiences.forEach(t=>t.getWorkflowManager().ejectFromPreviewService()),e))for(const t of this.workflowExperiences)await this.injectExperienceIntoPreviewService(t);e&&e.registerModelLoadEventListener&&e.registerModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService&&this.previewService!==e&&this.previewService.unregisterModelLoadEventListener&&this.previewService.unregisterModelLoadEventListener(this.onModelLoadEvent.bind(this)),this.previewService=e}updateWorkflowExperienceTransform(e,t,A){return this.bundleStateManager.updateWorkflowExperienceTransform(e,t,A),this.updateBundle()}activateWorkflowExperienceTransform(e,t){return this.bundleStateManager.activateWorkflowExperienceTransform(e,t),this.updateBundle()}onModelLoadEvent(e){e.eventType==="unload"||!e.modelContainer||(e.modelContainer.registerMaterialSelectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!0)),e.modelContainer.registerMaterialDeselectedCallback(()=>this.onModelSelectedEvent(e.modelContainer,!1)))}onModelSelectedEvent(e,t){if(e&&e.metadata&&e.metadata instanceof Map&&e.metadata.has("workflowManager")){const n=e.metadata.get("workflowManager").getTransaction(),a=this.workflowExperiences.find(i=>i.getWorkflowManager().getTransaction().id===n.id);a&&this.fireEvent(t?"workflow-experience-hover-enter":"workflow-experience-hover-exit",{workflowExperience:a})}}async injectExperienceIntoPreviewService(e){if(this.previewService){const t=e.getWorkflowManager().injectIntoPreviewService(this.previewService);try{this.bundleStateManager.applyStateToWorkflowExperience(e)}catch(A){console.error(`Unable to apply state to workflow experience: ${A}`)}await t}}async loadExistingWorkflowExperiences(e,t){if(e.length===0)return;const A=await this.client.getWorkflowExperiences(e.map(n=>({type:"transaction",transactionId:n})),t);if(A.forEach(n=>n.setBundle(this)),A.forEach(n=>n.checkForPriceBreakChanges()),this.workflowExperiences=A,this.previewService)for(const n of A)await this.injectExperienceIntoPreviewService(n)}async updateBundle(){var t;if(!((t=(await N.getShadowGraphqlClient().mutate({mutation:Zn,variables:{id:this.id,name:this.name,metadata:Array.from(this.metadata.entries()).map(([A,n])=>({key:A,value:n})),bundleStateData:this.bundleStateManager.getSerializedState()},context:{bundleOwnerId:this.ownerId}})).data)!=null&&t.bundleUpdate))throw new Error("Bundle not found!")}async updateTransactionOrder(){await N.getShadowGraphqlClient().mutate({mutation:ia,variables:{id:this.id,transactionIds:this.workflowExperiences.map(e=>e.getWorkflowManager().getTransaction().id)},context:{bundleOwnerId:this.ownerId}})}async checkConditionalHandlesChanged(e,t){const A=await this.globalPropertyHandleService.getHandles(),n=this.globalPropertyHandleService.applyConditionsFromState(A,e),a=this.globalPropertyHandleService.applyConditionsFromState(A,t);(()=>{if(n.length!==a.length)return!0;for(let o=0;o<n.length;o++)if(n[o].getName()!==a[o].getName())return!0;return!1})()&&this.fireEvent("conditional-global-properties-changed",{globalProperties:a})}fireEvent(e,t){(this.eventListeners.get(e)||[]).forEach(n=>n({bundle:this,event:e,data:t}))}}const da=M.gql`
2374
2379
  mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
2375
2380
  processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
2376
2381
  id
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spiffcommerce/core",
3
- "version": "21.15.2-0",
3
+ "version": "21.15.2",
4
4
  "description": "Core client API for interacting with the Spiff Commerce backend.",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.umd.cjs",