@spiffcommerce/core 21.5.0 → 21.6.0-alpha.0
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 +13 -3
- package/dist/index.js +43 -21
- package/dist/index.umd.cjs +2 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -852,7 +852,7 @@ interface Product {
|
|
|
852
852
|
*/
|
|
853
853
|
interface ProductPriceBreak {
|
|
854
854
|
/**
|
|
855
|
-
* The id of this price
|
|
855
|
+
* The id of this price break.
|
|
856
856
|
*/
|
|
857
857
|
id: string;
|
|
858
858
|
/**
|
|
@@ -947,7 +947,7 @@ declare enum ConversionLocation {
|
|
|
947
947
|
*/
|
|
948
948
|
OnStart = "OnStart",
|
|
949
949
|
/**
|
|
950
|
-
* The client should allow the user to input details just before
|
|
950
|
+
* The client should allow the user to input details just before quitting the experience.
|
|
951
951
|
*/
|
|
952
952
|
OnQuit = "OnQuit",
|
|
953
953
|
/**
|
|
@@ -1547,6 +1547,11 @@ interface WorkflowExperience {
|
|
|
1547
1547
|
* The price break percentage that is expected to be applied in price calculations.
|
|
1548
1548
|
*/
|
|
1549
1549
|
priceBreakToBeApplied(): number;
|
|
1550
|
+
/**
|
|
1551
|
+
* Calculates the price break and fires the "PriceBreakChanged" event if required.
|
|
1552
|
+
* This function is primarily intended for internal use.
|
|
1553
|
+
*/
|
|
1554
|
+
checkForPriceBreakChanges(): void;
|
|
1550
1555
|
/**
|
|
1551
1556
|
* Takes selections made by the user in another workflow and applies them to this workflow. For
|
|
1552
1557
|
* selections to be copied they must both have a matching global property configuration.
|
|
@@ -1637,7 +1642,8 @@ interface WorkflowExperience {
|
|
|
1637
1642
|
removeEventListener(type: WorkflowExperienceEventType, callback: (workflowExperience: WorkflowExperience) => void): void;
|
|
1638
1643
|
}
|
|
1639
1644
|
declare enum WorkflowExperienceEventType {
|
|
1640
|
-
QuantityChanged = "QuantityChanged"
|
|
1645
|
+
QuantityChanged = "QuantityChanged",
|
|
1646
|
+
PriceBreakChanged = "PriceBreakChanged"
|
|
1641
1647
|
}
|
|
1642
1648
|
declare class WorkflowExperienceImpl implements WorkflowExperience {
|
|
1643
1649
|
readonly client: SpiffCommerceClient;
|
|
@@ -1649,6 +1655,7 @@ declare class WorkflowExperienceImpl implements WorkflowExperience {
|
|
|
1649
1655
|
* Bundle this experience has been added to.
|
|
1650
1656
|
*/
|
|
1651
1657
|
private bundle?;
|
|
1658
|
+
private currentPriceBreak;
|
|
1652
1659
|
private renderableScenes;
|
|
1653
1660
|
private renderableSceneCallbacks;
|
|
1654
1661
|
private eventCallbacks;
|
|
@@ -1669,6 +1676,9 @@ declare class WorkflowExperienceImpl implements WorkflowExperience {
|
|
|
1669
1676
|
getTotalPriceSubunits(disablePriceBreaks?: boolean): number;
|
|
1670
1677
|
private getPriceSubUnitsAfterPriceBreaks;
|
|
1671
1678
|
priceBreakToBeApplied(): number;
|
|
1679
|
+
checkForPriceBreakChanges(): void;
|
|
1680
|
+
private getMatchingExperiences;
|
|
1681
|
+
private updatePriceBreak;
|
|
1672
1682
|
copySelectionsViaGlobalConfiguration(bundle: Bundle, experience: WorkflowExperience, filter?: StepHandle<AnyStepData>[]): Promise<void>;
|
|
1673
1683
|
getStepByName(name: string): TextStepHandle | FrameStepHandle | ShapeStepHandle | InformationStepHandle | IllustrationStepHandle | MaterialStepHandle | ModelStepHandle | PictureStepHandle | QuestionStepHandle | undefined;
|
|
1674
1684
|
getStepsByType(type: StepType): StepHandle<AnyStepData>[];
|
package/dist/index.js
CHANGED
|
@@ -6589,11 +6589,11 @@ const Te = new da(), wa = F`
|
|
|
6589
6589
|
}
|
|
6590
6590
|
}
|
|
6591
6591
|
`;
|
|
6592
|
-
var Ea = /* @__PURE__ */ ((c) => (c.QuantityChanged = "QuantityChanged", c))(Ea || {});
|
|
6592
|
+
var Ea = /* @__PURE__ */ ((c) => (c.QuantityChanged = "QuantityChanged", c.PriceBreakChanged = "PriceBreakChanged", c))(Ea || {});
|
|
6593
6593
|
class he {
|
|
6594
6594
|
constructor(e, t) {
|
|
6595
6595
|
var n;
|
|
6596
|
-
if (this.cachedStepHandles = /* @__PURE__ */ new Map(), this.renderableScenes = [], this.renderableSceneCallbacks = [], this.eventCallbacks = /* @__PURE__ */ new Map(), this.debouncedSavedDesignUpdate = Jt(async () => {
|
|
6596
|
+
if (this.cachedStepHandles = /* @__PURE__ */ new Map(), this.currentPriceBreak = 1, this.renderableScenes = [], this.renderableSceneCallbacks = [], this.eventCallbacks = /* @__PURE__ */ new Map(), this.debouncedSavedDesignUpdate = Jt(async () => {
|
|
6597
6597
|
await Te.getSavedDesignByTransaction(
|
|
6598
6598
|
this.getWorkflowManager().getTransaction().id
|
|
6599
6599
|
) && this.save();
|
|
@@ -6646,7 +6646,7 @@ class he {
|
|
|
6646
6646
|
};
|
|
6647
6647
|
});
|
|
6648
6648
|
this.renderableScenes = i, this.renderableSceneCallbacks.forEach((s) => s(i));
|
|
6649
|
-
});
|
|
6649
|
+
}), this.currentPriceBreak = this.priceBreakToBeApplied();
|
|
6650
6650
|
}
|
|
6651
6651
|
getBundle() {
|
|
6652
6652
|
return this.bundle;
|
|
@@ -6737,7 +6737,10 @@ class he {
|
|
|
6737
6737
|
}), this.getPriceSubUnitsAfterPriceBreaks(A, e);
|
|
6738
6738
|
}
|
|
6739
6739
|
getBasePriceSubunits(e, t) {
|
|
6740
|
-
const A = this.getPriceSubUnitsAfterPriceBreaks(
|
|
6740
|
+
const A = this.getPriceSubUnitsAfterPriceBreaks(
|
|
6741
|
+
this.getWorkflowManager().getProduct().basePrice || 0,
|
|
6742
|
+
t
|
|
6743
|
+
);
|
|
6741
6744
|
if (e) {
|
|
6742
6745
|
const n = this.getAdditionalProductPriceSubunits(t) || 0;
|
|
6743
6746
|
return A + n;
|
|
@@ -6760,15 +6763,32 @@ class he {
|
|
|
6760
6763
|
return Math.ceil(n);
|
|
6761
6764
|
}
|
|
6762
6765
|
priceBreakToBeApplied() {
|
|
6763
|
-
|
|
6764
|
-
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
return a.percentage;
|
|
6766
|
+
const e = (this.getWorkflowManager().getProduct().priceBreaks || []).sort(
|
|
6767
|
+
(n, a) => -(n.minQty - a.minQty)
|
|
6768
|
+
), A = [...this.getMatchingExperiences(), this].reduce((n, a) => n + a.getQuantity(), 0);
|
|
6769
|
+
for (const n of e)
|
|
6770
|
+
if (n.minQty <= A)
|
|
6771
|
+
return n.percentage;
|
|
6770
6772
|
return 1;
|
|
6771
6773
|
}
|
|
6774
|
+
checkForPriceBreakChanges() {
|
|
6775
|
+
const e = this.priceBreakToBeApplied();
|
|
6776
|
+
this.currentPriceBreak !== e && (this.updatePriceBreak(e), this.getMatchingExperiences().forEach(
|
|
6777
|
+
(t) => t.updatePriceBreak(e)
|
|
6778
|
+
));
|
|
6779
|
+
}
|
|
6780
|
+
getMatchingExperiences() {
|
|
6781
|
+
var e;
|
|
6782
|
+
return (((e = this.bundle) == null ? void 0 : e.getWorkflowExperiences()) || []).filter(
|
|
6783
|
+
(t) => t.getWorkflowManager().getTransaction().id !== this.getWorkflowManager().getTransaction().id && t.getWorkflowManager().getProduct().id === this.getWorkflowManager().getProduct().id
|
|
6784
|
+
);
|
|
6785
|
+
}
|
|
6786
|
+
updatePriceBreak(e) {
|
|
6787
|
+
this.currentPriceBreak = e, this.callEvent(
|
|
6788
|
+
"PriceBreakChanged"
|
|
6789
|
+
/* PriceBreakChanged */
|
|
6790
|
+
);
|
|
6791
|
+
}
|
|
6772
6792
|
async copySelectionsViaGlobalConfiguration(e, t, A) {
|
|
6773
6793
|
const n = await e.getGlobalProperties(), a = A == null ? void 0 : A.map((r) => r.getId()), i = this.getSteps().filter((r) => a === void 0 || a.includes(r.getId())), s = t.getSteps(), o = (r) => n.find((g) => g.getRawProperty().name === r.aspectName);
|
|
6774
6794
|
i.forEach((r) => {
|
|
@@ -6923,7 +6943,7 @@ class he {
|
|
|
6923
6943
|
this.getWorkflowManager().getTransaction().quantity = e, this.callEvent(
|
|
6924
6944
|
"QuantityChanged"
|
|
6925
6945
|
/* QuantityChanged */
|
|
6926
|
-
);
|
|
6946
|
+
), this.checkForPriceBreakChanges();
|
|
6927
6947
|
const t = x.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map(), A = this.getWorkflowManager().getTransaction(), n = t.get(A.id) || void 0;
|
|
6928
6948
|
await P.getShadowGraphqlClient().mutate({
|
|
6929
6949
|
mutation: wn,
|
|
@@ -8683,9 +8703,9 @@ class Ft {
|
|
|
8683
8703
|
return this.productCollection ? new ei(this.productCollection) : void 0;
|
|
8684
8704
|
}
|
|
8685
8705
|
async addWorkflowExperience(e) {
|
|
8686
|
-
await this.appendWorkflowExperience(e), await this.injectExperienceIntoPreviewService(e);
|
|
8706
|
+
e.setBundle(this), await this.appendWorkflowExperience(e), await this.injectExperienceIntoPreviewService(e);
|
|
8687
8707
|
const t = await this.getGlobalProperties();
|
|
8688
|
-
await Promise.all(t.map((A) => A.applyGlobalState([e])))
|
|
8708
|
+
await Promise.all(t.map((A) => A.applyGlobalState([e])));
|
|
8689
8709
|
}
|
|
8690
8710
|
async addWorkflowExperiences(e) {
|
|
8691
8711
|
const t = e.map((i) => i.getWorkflowManager().getTransaction().id), A = t.map(
|
|
@@ -8716,7 +8736,7 @@ class Ft {
|
|
|
8716
8736
|
const i = await this.getGlobalProperties();
|
|
8717
8737
|
await Promise.all(i.map((s) => s.applyGlobalState(e)));
|
|
8718
8738
|
})()
|
|
8719
|
-
]), this.workflowExperiences.forEach((i) => i.setBundle(this));
|
|
8739
|
+
]), this.workflowExperiences.forEach((i) => i.setBundle(this)), this.workflowExperiences.forEach((i) => i.checkForPriceBreakChanges());
|
|
8720
8740
|
}
|
|
8721
8741
|
async appendWorkflowExperience(e, t = !0) {
|
|
8722
8742
|
const A = e.getWorkflowManager().getTransaction().id;
|
|
@@ -8735,14 +8755,14 @@ class Ft {
|
|
|
8735
8755
|
bundleOwnerId: this.ownerId,
|
|
8736
8756
|
transactionOwnerId: i
|
|
8737
8757
|
}
|
|
8738
|
-
}), t && this.workflowExperiences.push(e);
|
|
8758
|
+
}), t && (this.workflowExperiences.push(e), this.workflowExperiences.forEach((s) => s.checkForPriceBreakChanges()));
|
|
8739
8759
|
}
|
|
8740
8760
|
async removeWorkflowExperience(e) {
|
|
8741
8761
|
const t = this.workflowExperiences.indexOf(e);
|
|
8742
|
-
await this.removeTransaction(t, this.workflowExperiences[t].getWorkflowManager().getTransaction())
|
|
8762
|
+
await this.removeTransaction(t, this.workflowExperiences[t].getWorkflowManager().getTransaction());
|
|
8743
8763
|
}
|
|
8744
8764
|
async removeWorkflowExperiences(e) {
|
|
8745
|
-
await this.removeTransactions(e.map((t) => t.getWorkflowManager().getTransaction()))
|
|
8765
|
+
await this.removeTransactions(e.map((t) => t.getWorkflowManager().getTransaction()));
|
|
8746
8766
|
}
|
|
8747
8767
|
async removeWorkflowExperienceByTransaction(e) {
|
|
8748
8768
|
const t = this.workflowExperiences.findIndex(
|
|
@@ -8770,7 +8790,7 @@ class Ft {
|
|
|
8770
8790
|
context: {
|
|
8771
8791
|
bundleOwnerId: this.ownerId
|
|
8772
8792
|
}
|
|
8773
|
-
}), A && (this.workflowExperiences.splice(e, 1), await this.updateTransactionOrder());
|
|
8793
|
+
}), A && (this.workflowExperiences.splice(e, 1), this.workflowExperiences.forEach((a) => a.checkForPriceBreakChanges()), n.checkForPriceBreakChanges(), await this.updateTransactionOrder());
|
|
8774
8794
|
} else
|
|
8775
8795
|
throw new Error("Unable to remove workflow experience from bundle - Not Found! - " + t.id);
|
|
8776
8796
|
}
|
|
@@ -8788,7 +8808,9 @@ class Ft {
|
|
|
8788
8808
|
1
|
|
8789
8809
|
)[0]
|
|
8790
8810
|
);
|
|
8791
|
-
A.forEach((n) => n.setBundle(void 0)), this.
|
|
8811
|
+
A.forEach((n) => n.setBundle(void 0)), [...this.workflowExperiences, ...A].forEach(
|
|
8812
|
+
(n) => n.checkForPriceBreakChanges()
|
|
8813
|
+
), this.previewService && A.forEach((n) => n.getWorkflowManager().ejectFromPreviewService()), e.forEach((n) => this.bundleStateManager.removeStateForTransaction(n.id)), await P.getShadowGraphqlClient().mutate({
|
|
8792
8814
|
mutation: La,
|
|
8793
8815
|
variables: {
|
|
8794
8816
|
id: this.id,
|
|
@@ -8981,7 +9003,7 @@ class Ft {
|
|
|
8981
9003
|
})),
|
|
8982
9004
|
t
|
|
8983
9005
|
);
|
|
8984
|
-
if (A.forEach((n) => n.setBundle(this)), this.workflowExperiences = A, this.previewService)
|
|
9006
|
+
if (A.forEach((n) => n.setBundle(this)), A.forEach((n) => n.checkForPriceBreakChanges()), this.workflowExperiences = A, this.previewService)
|
|
8985
9007
|
for (const n of A)
|
|
8986
9008
|
await this.injectExperienceIntoPreviewService(n);
|
|
8987
9009
|
}
|
package/dist/index.umd.cjs
CHANGED
|
@@ -2009,7 +2009,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2009
2009
|
}
|
|
2010
2010
|
}
|
|
2011
2011
|
}
|
|
2012
|
-
`;var Kt=(c=>(c.QuantityChanged="QuantityChanged",c))(Kt||{});class le{constructor(e,t){var n;if(this.cachedStepHandles=new Map,this.renderableScenes=[],this.renderableSceneCallbacks=[],this.eventCallbacks=new Map,this.debouncedSavedDesignUpdate=tt(async()=>{await Fe.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()},2500),this.getCanvasObjectURLAsync=async a=>new Promise((i,o)=>{try{a.toBlob(s=>{if(s){const r=URL.createObjectURL(s);i(r)}})}catch(s){o(s)}}),!t.workflow)throw new Error("No Workflow ID provided.");this.client=e;const A=t.layouts;this.commandContext=new g.CommandContext,this.commandContext.initialize(A,t.reloadedState),this.isReadOnly=t.transaction.isOrdered||!!t.readOnly,this.workflowManager=new dn(t.workflow,((n=t.product.profanities)==null?void 0:n.map(a=>a.word))||[],A,this.commandContext,a=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return t.stateMutationFunc(a)},t.transaction,t.product,t.previewService,t.renderableContextService,t.reloadedState,t.readOnly,t.modelContainer,t.isReloadedTransaction,t.singleVariantsRenderable,t.delayWorkflowStateSync),this.workflowManager.addSelectionCallback(a=>{const i=a.traversableScenes.map(o=>{const s=o.renderableSteps.map(r=>r.stepName);return{id:o.name,title:o.title,renderableSteps:s,workflowScene:o}});this.renderableScenes=i,this.renderableSceneCallbacks.forEach(o=>o(i))})}getBundle(){return this.bundle}setBundle(e){this.bundle=e}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async createPreviewImage(e,t){var u,F;const A=this.workflowManager.getWorkflow(),n=(u=A==null?void 0:A.finalizeStepConfig)==null?void 0:u.lookAtAnimation;if(e){if(!n)throw new Error("Failed to generate cart preview image!");return await((F=this.workflowManager.getPreviewService())==null?void 0:F.renderSceneScreenshot(t??512,n))||""}let a=2048;t&&t<=2048&&(a=t);const i=g.createCanvas(a,a),o=this.commandContext.getAllLayouts(),s=A.defaultPreviewPanelIndex||0,r=A.panels[s],l=o.find(I=>{var f;return((f=I.layoutState)==null?void 0:f.layout.panelId)===(r==null?void 0:r.name)})||o[0],d=l.layoutState.layout.previewRegion?{x:l.layoutState.layout.previewRegion.left,y:l.layoutState.layout.previewRegion.top,width:l.layoutState.layout.previewRegion.width,height:l.layoutState.layout.previewRegion.height}:{x:0,y:0,width:l.layoutState.layout.width,height:l.layoutState.layout.height},B=this.commandContext.getLayoutById(l.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new Ce("Failed to obtain 2D context for preview image creation");const E=g.getSvgElement(B.layoutState.layout,B.layoutState.elements,{renderingConfiguration:{purpose:g.LayoutRenderingPurpose.Print,region:{left:d.x,top:d.y,width:d.width,height:d.height}}}),C=g.renderPapyrusComponentAsString(E);await(await et.Pith.from(w,C,{anonymousCrossOrigin:!0,ignoreDimensions:!1,createCanvas:g.createCanvas,createImage:g.loadImage,DOMParser:g.getDomParser(),fetch:g.fetch})).render();const m=await this.getCanvasObjectURLAsync(i);return i.toDataURL(m)}getStepById(e){const t=this.getWorkflowManager().getWorkflow().steps.find(a=>a.stepName===e);if(!t||!this.stepHasHandle(t))return;const A=this.cachedStepHandles.get(t.stepName);if(A)return A;const n=pe.get(this.getWorkflowManager(),t);return this.cachedStepHandles.set(t.stepName,n),n}getSteps(){return this.getScenes().flatMap(e=>this.getStepsByScene(e))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map(t=>({id:t.id,name:t.name,stepIds:t.stepNames}))}getSelectionPriceSubunits(e){const t=this.getWorkflowManager().getWorkflowSelections();let A=0;return Object.values(t).forEach(n=>{A+=n.selections.reduce((a,i)=>a+(i.priceModifier||0),0)}),this.getPriceSubUnitsAfterPriceBreaks(A,e)}getBasePriceSubunits(e,t){const A=this.getPriceSubUnitsAfterPriceBreaks(this.getWorkflowManager().getProduct().basePrice||0,t);if(e){const n=this.getAdditionalProductPriceSubunits(t)||0;return A+n}return A}getAdditionalProductPriceSubunits(e){var A;const t=this.getWorkflowManager().getTransaction().integrationProduct;if((A=t==null?void 0:t.additionalIntegrationProduct)!=null&&A.product){const n=t.additionalIntegrationProduct.product.basePrice||0;return this.getPriceSubUnitsAfterPriceBreaks(n,e)}}getTotalPriceSubunits(e){return this.getBasePriceSubunits(e)+this.getSelectionPriceSubunits(e)}getPriceSubUnitsAfterPriceBreaks(e,t){const A=t?1:this.priceBreakToBeApplied(),n=e*A;return Math.ceil(n)}priceBreakToBeApplied(){var n;const e=(this.getWorkflowManager().getProduct().priceBreaks||[]).sort((a,i)=>-(a.minQty-i.minQty)),A=(((n=this.bundle)==null?void 0:n.getWorkflowExperiences())||[]).filter(a=>a.getWorkflowManager().getProduct().id===this.getWorkflowManager().getProduct().id).reduce((a,i)=>a+i.getQuantity(),0);for(const a of e)if(a.minQty<=A)return a.percentage;return 1}async copySelectionsViaGlobalConfiguration(e,t,A){const n=await e.getGlobalProperties(),a=A==null?void 0:A.map(r=>r.getId()),i=this.getSteps().filter(r=>a===void 0||a.includes(r.getId())),o=t.getSteps(),s=r=>n.find(l=>l.getRawProperty().name===r.aspectName);i.forEach(r=>{const l=new Set,d=r.getRaw().globalPropertyAspectConfigurations;d!==void 0&&(d.forEach(B=>l.add(JSON.stringify(B))),o.forEach(B=>{const w=B.getRaw().globalPropertyAspectConfigurations;w!==void 0&&w.forEach(E=>{const C=s(E),h=l.has(JSON.stringify(E));if(h&&(C==null?void 0:C.getType())==="Option"){const m=B.getCurrentVariant();if(!m)return;r.selectVariant(m),l.delete(JSON.stringify(E))}else if(h&&(C==null?void 0:C.getType())==="Text"){const m=B.getText();r.setText(m),l.delete(JSON.stringify(E))}})}))})}getStepByName(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepTitle===e);if(!(!t||!this.stepHasHandle(t)))return pe.get(this.getWorkflowManager(),t)}getStepsByType(e){return this.getWorkflowManager().getWorkflow().steps.filter(t=>t.type===e).map(t=>pe.get(this.getWorkflowManager(),t))}getStepsByScene(e){if(!this.getWorkflowManager().getWorkflow().stepGroups.find(A=>A.name===e.name))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return e.stepIds.map(A=>this.getWorkflowManager().getWorkflow().steps.find(n=>n.stepName===A)).filter(A=>this.stepHasHandle(A)).map(A=>pe.get(this.getWorkflowManager(),A))}async attachCustomerDetails(e){return this.assignCustomerDetails({emailAddress:e.email})}async assignCustomerDetails(e){var i,o,s;const A=(P.getMap("transactionOwnerIds")||new Map).get(this.getWorkflowManager().getTransaction().id),a=(s=(o=(i=(await N.getShadowGraphqlClient().mutate({mutation:In,variables:{id:this.getWorkflowManager().getTransaction().id,details:e,type:"Owner"},context:{transactionOwnerId:A}})).data)==null?void 0:i.transactionAddStakeholder)==null?void 0:o.stakeholders)==null?void 0:s.find(r=>{var l;return((l=r.customer)==null?void 0:l.emailAddress)===e.emailAddress});if(a!=null&&a.customer){this.getWorkflowManager().setTransactionCustomer(a.customer);const r=P.getMap("transactionCustomerIds")||new Map;r.set(this.getWorkflowManager().getTransaction().id,a.customer.id),P.setMap("transactionCustomerIds",r)}}attachRenderableSceneListener(e){this.renderableSceneCallbacks.push(e),e(this.renderableScenes)}detachRenderableSceneListener(e){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter(t=>t!==e)}async save(e){if(!this.getCommandContext().getState())throw new v("State undefined!");const n={title:await(async()=>{var s;if(e)return e;const a=this.getWorkflowManager().getTransaction().id,o=(s=(await Fe.getSavedDesigns()).find(r=>r.transactionId===a))==null?void 0:s.title;return o||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await Fe.addDesign(n),n}async copy(){var o;const e=Ee(this.getCommandContext().getState());if(!e)throw new v("Internal state is undefined! Cannot copy experience!");const t=JSON.stringify(e.transaction),A=this.getWorkflowManager().getWorkflow(),n=new oA({}),a=(o=this.getWorkflowManager().getTransaction().integrationProduct)==null?void 0:o.id;if(!a)throw new v("Integration product id is undefined!");return await n.initFromIntegrationProduct(a),await n.getWorkflowExperience(A.id,t,void 0)}async onDesignFinished(e,t=!0){return jt(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),()=>this.commandContext.getState(),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,e||(()=>{}),A=>t?this.createPreviewImage(A,1024):Promise.resolve(void 0),this.workflowManager.getWorkflowMetadata())}stepHasHandle(e){return e.type!==g.StepType.SilentIllustration&&e.type!==g.StepType.ProductOverlay}getExportedData(){var n;const e=new Map,t=this.getWorkflowManager().getWorkflowMetadata(),A=this.getWorkflowManager().getWorkflowSelections();return Object.keys(t).forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(s=>s.stepName===a);if(!i)return;e.has(i.stepTitle)||e.set(i.stepTitle,{});const o=t[a];Object.keys(o).forEach(s=>{e.get(i.stepTitle)[s]=o[s]})}),(n=Object.keys(A))==null||n.forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(o=>o.stepName===a);i&&(e.has(i.stepTitle)||e.set(i.stepTitle,{}),e.get(i.stepTitle).selection=A[a].selections[0].name)}),e}getQuantity(){return this.getWorkflowManager().getTransaction().quantity||1}async setQuantity(e){if(e<1)throw new RangeError("WorkflowExperience quantity must be greater than zero.");if(this.isReadOnly)throw new Error("Cannot update quantity on a read-only WorkflowExperience");this.getWorkflowManager().getTransaction().quantity=e,this.callEvent("QuantityChanged");const t=P.getMap("transactionOwnerIds")||new Map,A=this.getWorkflowManager().getTransaction(),n=t.get(A.id)||void 0;await N.getShadowGraphqlClient().mutate({mutation:UA,variables:{id:A.id,quantity:e},context:{transactionOwnerId:n}})}addEventListener(e,t){const A=this.eventCallbacks.get(e)||[];A.push(t),this.eventCallbacks.set(e,A)}removeEventListener(e,t){const A=this.eventCallbacks.get(e)||[];this.eventCallbacks.set(e,A.filter(n=>n!==t))}callEvent(e){(this.eventCallbacks.get(e)||[]).forEach(t=>t(this))}}const fn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Dn=async(c,e,t)=>{const A=e.data,n=t.data.baseUrl,a=A.assetUrl.replace("localhost","localstack"),i=n.slice(0,4)==="http"?"":"https://",o=new URL(i+n);o.searchParams.append("video",g.toBase64(JSON.stringify([{href:a}]))),o.pathname=o.pathname+(o.pathname.slice(-1)==="/"?"":"/");const s=o.toString(),l=`data:image/svg+xml;base64,${g.toBase64(await nt.toString(s,{type:"svg"}))}`,d=w=>{const E=c.find(h=>h.panelId===w.panelId);if(!E)throw new J(w);const C=g.generate();return new g.CreateElementCommand({id:C,src:l,type:g.LayoutElementType.Image,y:w.top,x:w.left,width:w.width,height:w.height,rotation:0},E)},B=t.data.regions;try{return B.map(d)}catch(w){return console.error(w),[]}},pn=async(c,e,t,A)=>{const n=t.data,a=n.assetUrl,i=await g.getPatternImageData(a);try{const o=g.getVariant(n,A.option);o&&(e[A.stepName]={selectedVariants:[o]});const s=async r=>{var C;const l=await g.generateFrameSVG(r||{width:1,height:1},(C=o==null?void 0:o.asset)==null?void 0:C.fileLink),d=await g.getFrameData(l),B=g.generate(),w=c.find(h=>h.panelId===r.panelId);if(!w)throw new J(r);const E=g.calculateOffsets(i,d,{scale:n.scale,left:n.x,top:n.y});return[new g.CreateElementCommand({id:B,path:d.path,dataWidth:d.width,dataHeight:d.height,type:g.LayoutElementType.Frame,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,forceImageCover:A.data.forceImageCover,x:r.left,y:r.top,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,rotation:r.rotation,scaleX:r.width/d.width,scaleY:r.height/d.height,pattern:void 0},w),new g.UpdateFramePattern(B,i,E)]};return(await Promise.all(A.data.regions.map(r=>s(r)))).flat()}catch(o){return console.error(o),[]}},Fn=async(c,e,t,A)=>{var f,D;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((f=a.variants)==null?void 0:f.find(p=>p.id===n.illustrationVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.illustrationVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.illustrationVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(D=i.asset)==null?void 0:D.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.illustrationVariantId}`),[];const s=await g.fetchAsString(o,!0),r=/<svg.*?<\/svg>/s,l=s.match(r)||[],d=(l==null?void 0:l.length)>0?l[0]:"",E=g.domParser().parseFromString(d,"image/svg+xml").firstElementChild;if(!E)return console.error("Failed to read SVG."),[];g.sanitizeSvgTree(E);const C={};g.traverse(E,p=>{fn.includes(p.tagName)&&!p.attributes.getNamedItem("fill")&&p.setAttribute("fill","#000000");const S=p.attributes.getNamedItem("fill");if(S&&S.value!=="none"){const x=S.value,H=`spiff-fill-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}const y=p.attributes.getNamedItem("stroke");if(y&&y.value!=="none"){const x=y.value,H=`spiff-stroke-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}});const m=g.xmlSerializer().serializeToString(E),u=n.colors;if(u){for(const[p,S]of Object.entries(C))for(const y of Object.keys(u))if(S.browserValue===y){C[p]={browserValue:u[y]};break}}const F=p=>{const S=c.find(x=>x.panelId===p.panelId);if(!S)throw new J(p);const y=g.generate();return new g.CreateElementCommand({colors:C,id:y,svg:m,type:g.LayoutElementType.Illustration,y:p.top,x:p.left,rotation:p.rotation,width:p.width,height:p.height,layer:p.layer,layerIndex:p.layerIndex,immutable:p.immutable},S)},I=A.data.regions;try{return I.map(F)}catch(p){return console.error(p),[]}},Mn=async(c,e,t)=>{const A=await xt(t.data.module),n=e.data,a=(o,s)=>{const r=c.find(d=>d.panelId===s.panelId);if(!r)throw new J(s);const l=g.generate();return new g.CreateElementCommand({colors:{},id:l,svg:o,type:g.LayoutElementType.Illustration,y:s.top,x:s.left,rotation:s.rotation,width:s.width,height:s.height,layer:s.layer,layerIndex:s.layerIndex},r)},i=t.data.regions;try{return i.map(o=>a(A.svgPrint(n.text,o),o))}catch(o){return console.error(o),[]}},Sn=async(c,e,t,A)=>{var l,d;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((l=a.variants)==null?void 0:l.find(B=>B.id===n.pictureVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.pictureVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.pictureVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(d=i.asset)==null?void 0:d.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.pictureVariantId}`),[];const s=B=>{const w=c.find(C=>C.panelId===B.panelId);if(!w)throw new J(B);const E=g.generate();return new g.CreateElementCommand({id:E,src:o,type:g.LayoutElementType.Image,y:B.top,x:B.left,rotation:B.rotation,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,immutable:B.immutable,preserveAspectRatio:"none"},w)},r=A.data.regions;try{return r.map(s)}catch(B){return console.error(B),[]}},yn=async(c,e,t,A)=>{var r;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((r=a.variants)==null?void 0:r.find(l=>l.id===n.colorVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.colorVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=l=>{const d=c.find(h=>h.panelId===l.panelId);if(!d)throw new J(l);const B=`
|
|
2012
|
+
`;var Kt=(c=>(c.QuantityChanged="QuantityChanged",c.PriceBreakChanged="PriceBreakChanged",c))(Kt||{});class le{constructor(e,t){var n;if(this.cachedStepHandles=new Map,this.currentPriceBreak=1,this.renderableScenes=[],this.renderableSceneCallbacks=[],this.eventCallbacks=new Map,this.debouncedSavedDesignUpdate=tt(async()=>{await Fe.getSavedDesignByTransaction(this.getWorkflowManager().getTransaction().id)&&this.save()},2500),this.getCanvasObjectURLAsync=async a=>new Promise((i,o)=>{try{a.toBlob(s=>{if(s){const r=URL.createObjectURL(s);i(r)}})}catch(s){o(s)}}),!t.workflow)throw new Error("No Workflow ID provided.");this.client=e;const A=t.layouts;this.commandContext=new g.CommandContext,this.commandContext.initialize(A,t.reloadedState),this.isReadOnly=t.transaction.isOrdered||!!t.readOnly,this.workflowManager=new dn(t.workflow,((n=t.product.profanities)==null?void 0:n.map(a=>a.word))||[],A,this.commandContext,a=>{try{this.debouncedSavedDesignUpdate()}catch{console.error("Failed to update saved design details.")}return t.stateMutationFunc(a)},t.transaction,t.product,t.previewService,t.renderableContextService,t.reloadedState,t.readOnly,t.modelContainer,t.isReloadedTransaction,t.singleVariantsRenderable,t.delayWorkflowStateSync),this.workflowManager.addSelectionCallback(a=>{const i=a.traversableScenes.map(o=>{const s=o.renderableSteps.map(r=>r.stepName);return{id:o.name,title:o.title,renderableSteps:s,workflowScene:o}});this.renderableScenes=i,this.renderableSceneCallbacks.forEach(o=>o(i))}),this.currentPriceBreak=this.priceBreakToBeApplied()}getBundle(){return this.bundle}setBundle(e){this.bundle=e}getClient(){return this.client}getIsReadOnly(){return this.isReadOnly}getCommandContext(){return this.commandContext}getWorkflowManager(){return this.workflowManager}async createPreviewImage(e,t){var u,F;const A=this.workflowManager.getWorkflow(),n=(u=A==null?void 0:A.finalizeStepConfig)==null?void 0:u.lookAtAnimation;if(e){if(!n)throw new Error("Failed to generate cart preview image!");return await((F=this.workflowManager.getPreviewService())==null?void 0:F.renderSceneScreenshot(t??512,n))||""}let a=2048;t&&t<=2048&&(a=t);const i=g.createCanvas(a,a),o=this.commandContext.getAllLayouts(),s=A.defaultPreviewPanelIndex||0,r=A.panels[s],l=o.find(I=>{var f;return((f=I.layoutState)==null?void 0:f.layout.panelId)===(r==null?void 0:r.name)})||o[0],d=l.layoutState.layout.previewRegion?{x:l.layoutState.layout.previewRegion.left,y:l.layoutState.layout.previewRegion.top,width:l.layoutState.layout.previewRegion.width,height:l.layoutState.layout.previewRegion.height}:{x:0,y:0,width:l.layoutState.layout.width,height:l.layoutState.layout.height},B=this.commandContext.getLayoutById(l.layoutState.layout.id),w=i.getContext("2d");if(!w)throw new Ce("Failed to obtain 2D context for preview image creation");const E=g.getSvgElement(B.layoutState.layout,B.layoutState.elements,{renderingConfiguration:{purpose:g.LayoutRenderingPurpose.Print,region:{left:d.x,top:d.y,width:d.width,height:d.height}}}),C=g.renderPapyrusComponentAsString(E);await(await et.Pith.from(w,C,{anonymousCrossOrigin:!0,ignoreDimensions:!1,createCanvas:g.createCanvas,createImage:g.loadImage,DOMParser:g.getDomParser(),fetch:g.fetch})).render();const m=await this.getCanvasObjectURLAsync(i);return i.toDataURL(m)}getStepById(e){const t=this.getWorkflowManager().getWorkflow().steps.find(a=>a.stepName===e);if(!t||!this.stepHasHandle(t))return;const A=this.cachedStepHandles.get(t.stepName);if(A)return A;const n=pe.get(this.getWorkflowManager(),t);return this.cachedStepHandles.set(t.stepName,n),n}getSteps(){return this.getScenes().flatMap(e=>this.getStepsByScene(e))}getScenes(){return this.getWorkflowManager().getWorkflow().stepGroups.map(t=>({id:t.id,name:t.name,stepIds:t.stepNames}))}getSelectionPriceSubunits(e){const t=this.getWorkflowManager().getWorkflowSelections();let A=0;return Object.values(t).forEach(n=>{A+=n.selections.reduce((a,i)=>a+(i.priceModifier||0),0)}),this.getPriceSubUnitsAfterPriceBreaks(A,e)}getBasePriceSubunits(e,t){const A=this.getPriceSubUnitsAfterPriceBreaks(this.getWorkflowManager().getProduct().basePrice||0,t);if(e){const n=this.getAdditionalProductPriceSubunits(t)||0;return A+n}return A}getAdditionalProductPriceSubunits(e){var A;const t=this.getWorkflowManager().getTransaction().integrationProduct;if((A=t==null?void 0:t.additionalIntegrationProduct)!=null&&A.product){const n=t.additionalIntegrationProduct.product.basePrice||0;return this.getPriceSubUnitsAfterPriceBreaks(n,e)}}getTotalPriceSubunits(e){return this.getBasePriceSubunits(e)+this.getSelectionPriceSubunits(e)}getPriceSubUnitsAfterPriceBreaks(e,t){const A=t?1:this.priceBreakToBeApplied(),n=e*A;return Math.ceil(n)}priceBreakToBeApplied(){const e=(this.getWorkflowManager().getProduct().priceBreaks||[]).sort((n,a)=>-(n.minQty-a.minQty)),A=[...this.getMatchingExperiences(),this].reduce((n,a)=>n+a.getQuantity(),0);for(const n of e)if(n.minQty<=A)return n.percentage;return 1}checkForPriceBreakChanges(){const e=this.priceBreakToBeApplied();this.currentPriceBreak!==e&&(this.updatePriceBreak(e),this.getMatchingExperiences().forEach(t=>t.updatePriceBreak(e)))}getMatchingExperiences(){var e;return(((e=this.bundle)==null?void 0:e.getWorkflowExperiences())||[]).filter(t=>t.getWorkflowManager().getTransaction().id!==this.getWorkflowManager().getTransaction().id&&t.getWorkflowManager().getProduct().id===this.getWorkflowManager().getProduct().id)}updatePriceBreak(e){this.currentPriceBreak=e,this.callEvent("PriceBreakChanged")}async copySelectionsViaGlobalConfiguration(e,t,A){const n=await e.getGlobalProperties(),a=A==null?void 0:A.map(r=>r.getId()),i=this.getSteps().filter(r=>a===void 0||a.includes(r.getId())),o=t.getSteps(),s=r=>n.find(l=>l.getRawProperty().name===r.aspectName);i.forEach(r=>{const l=new Set,d=r.getRaw().globalPropertyAspectConfigurations;d!==void 0&&(d.forEach(B=>l.add(JSON.stringify(B))),o.forEach(B=>{const w=B.getRaw().globalPropertyAspectConfigurations;w!==void 0&&w.forEach(E=>{const C=s(E),h=l.has(JSON.stringify(E));if(h&&(C==null?void 0:C.getType())==="Option"){const m=B.getCurrentVariant();if(!m)return;r.selectVariant(m),l.delete(JSON.stringify(E))}else if(h&&(C==null?void 0:C.getType())==="Text"){const m=B.getText();r.setText(m),l.delete(JSON.stringify(E))}})}))})}getStepByName(e){const t=this.getWorkflowManager().getWorkflow().steps.find(A=>A.stepTitle===e);if(!(!t||!this.stepHasHandle(t)))return pe.get(this.getWorkflowManager(),t)}getStepsByType(e){return this.getWorkflowManager().getWorkflow().steps.filter(t=>t.type===e).map(t=>pe.get(this.getWorkflowManager(),t))}getStepsByScene(e){if(!this.getWorkflowManager().getWorkflow().stepGroups.find(A=>A.name===e.name))throw new Error("Given scene is not present on workflow! Be careful when persisting scenes that you only use them with the relevant workflow.");return e.stepIds.map(A=>this.getWorkflowManager().getWorkflow().steps.find(n=>n.stepName===A)).filter(A=>this.stepHasHandle(A)).map(A=>pe.get(this.getWorkflowManager(),A))}async attachCustomerDetails(e){return this.assignCustomerDetails({emailAddress:e.email})}async assignCustomerDetails(e){var i,o,s;const A=(P.getMap("transactionOwnerIds")||new Map).get(this.getWorkflowManager().getTransaction().id),a=(s=(o=(i=(await N.getShadowGraphqlClient().mutate({mutation:In,variables:{id:this.getWorkflowManager().getTransaction().id,details:e,type:"Owner"},context:{transactionOwnerId:A}})).data)==null?void 0:i.transactionAddStakeholder)==null?void 0:o.stakeholders)==null?void 0:s.find(r=>{var l;return((l=r.customer)==null?void 0:l.emailAddress)===e.emailAddress});if(a!=null&&a.customer){this.getWorkflowManager().setTransactionCustomer(a.customer);const r=P.getMap("transactionCustomerIds")||new Map;r.set(this.getWorkflowManager().getTransaction().id,a.customer.id),P.setMap("transactionCustomerIds",r)}}attachRenderableSceneListener(e){this.renderableSceneCallbacks.push(e),e(this.renderableScenes)}detachRenderableSceneListener(e){this.renderableSceneCallbacks=this.renderableSceneCallbacks.filter(t=>t!==e)}async save(e){if(!this.getCommandContext().getState())throw new v("State undefined!");const n={title:await(async()=>{var s;if(e)return e;const a=this.getWorkflowManager().getTransaction().id,o=(s=(await Fe.getSavedDesigns()).find(r=>r.transactionId===a))==null?void 0:s.title;return o||"My design"})(),thumbnail:await this.createPreviewImage(!1,256),transactionId:this.getWorkflowManager().getTransaction().id,productId:this.getWorkflowManager().getProduct().id,integrationProductId:this.getWorkflowManager().getTransaction().integrationProduct.id,workflowName:this.getWorkflowManager().getWorkflow().name,workflowId:this.getWorkflowManager().getWorkflow().id,lastEdited:new Date};return await Fe.addDesign(n),n}async copy(){var o;const e=Ee(this.getCommandContext().getState());if(!e)throw new v("Internal state is undefined! Cannot copy experience!");const t=JSON.stringify(e.transaction),A=this.getWorkflowManager().getWorkflow(),n=new oA({}),a=(o=this.getWorkflowManager().getTransaction().integrationProduct)==null?void 0:o.id;if(!a)throw new v("Integration product id is undefined!");return await n.initFromIntegrationProduct(a),await n.getWorkflowExperience(A.id,t,void 0)}async onDesignFinished(e,t=!0){return jt(this.workflowManager,this.workflowManager.getWorkflow(),this.workflowManager.getLayouts(),()=>this.commandContext.getState(),this.workflowManager.getProduct(),this.workflowManager.getTransaction(),this.workflowManager.getWorkflowSelections(),this.workflowManager.getWorkflow().name,e||(()=>{}),A=>t?this.createPreviewImage(A,1024):Promise.resolve(void 0),this.workflowManager.getWorkflowMetadata())}stepHasHandle(e){return e.type!==g.StepType.SilentIllustration&&e.type!==g.StepType.ProductOverlay}getExportedData(){var n;const e=new Map,t=this.getWorkflowManager().getWorkflowMetadata(),A=this.getWorkflowManager().getWorkflowSelections();return Object.keys(t).forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(s=>s.stepName===a);if(!i)return;e.has(i.stepTitle)||e.set(i.stepTitle,{});const o=t[a];Object.keys(o).forEach(s=>{e.get(i.stepTitle)[s]=o[s]})}),(n=Object.keys(A))==null||n.forEach(a=>{const i=this.workflowManager.getWorkflow().steps.find(o=>o.stepName===a);i&&(e.has(i.stepTitle)||e.set(i.stepTitle,{}),e.get(i.stepTitle).selection=A[a].selections[0].name)}),e}getQuantity(){return this.getWorkflowManager().getTransaction().quantity||1}async setQuantity(e){if(e<1)throw new RangeError("WorkflowExperience quantity must be greater than zero.");if(this.isReadOnly)throw new Error("Cannot update quantity on a read-only WorkflowExperience");this.getWorkflowManager().getTransaction().quantity=e,this.callEvent("QuantityChanged"),this.checkForPriceBreakChanges();const t=P.getMap("transactionOwnerIds")||new Map,A=this.getWorkflowManager().getTransaction(),n=t.get(A.id)||void 0;await N.getShadowGraphqlClient().mutate({mutation:UA,variables:{id:A.id,quantity:e},context:{transactionOwnerId:n}})}addEventListener(e,t){const A=this.eventCallbacks.get(e)||[];A.push(t),this.eventCallbacks.set(e,A)}removeEventListener(e,t){const A=this.eventCallbacks.get(e)||[];this.eventCallbacks.set(e,A.filter(n=>n!==t))}callEvent(e){(this.eventCallbacks.get(e)||[]).forEach(t=>t(this))}}const fn=["altGlyph","circle","ellipse","path","polygon","polyline","rect","text","textPath","tref","tspan"],Dn=async(c,e,t)=>{const A=e.data,n=t.data.baseUrl,a=A.assetUrl.replace("localhost","localstack"),i=n.slice(0,4)==="http"?"":"https://",o=new URL(i+n);o.searchParams.append("video",g.toBase64(JSON.stringify([{href:a}]))),o.pathname=o.pathname+(o.pathname.slice(-1)==="/"?"":"/");const s=o.toString(),l=`data:image/svg+xml;base64,${g.toBase64(await nt.toString(s,{type:"svg"}))}`,d=w=>{const E=c.find(h=>h.panelId===w.panelId);if(!E)throw new J(w);const C=g.generate();return new g.CreateElementCommand({id:C,src:l,type:g.LayoutElementType.Image,y:w.top,x:w.left,width:w.width,height:w.height,rotation:0},E)},B=t.data.regions;try{return B.map(d)}catch(w){return console.error(w),[]}},pn=async(c,e,t,A)=>{const n=t.data,a=n.assetUrl,i=await g.getPatternImageData(a);try{const o=g.getVariant(n,A.option);o&&(e[A.stepName]={selectedVariants:[o]});const s=async r=>{var C;const l=await g.generateFrameSVG(r||{width:1,height:1},(C=o==null?void 0:o.asset)==null?void 0:C.fileLink),d=await g.getFrameData(l),B=g.generate(),w=c.find(h=>h.panelId===r.panelId);if(!w)throw new J(r);const E=g.calculateOffsets(i,d,{scale:n.scale,left:n.x,top:n.y});return[new g.CreateElementCommand({id:B,path:d.path,dataWidth:d.width,dataHeight:d.height,type:g.LayoutElementType.Frame,focalBlur:A.data.focalBlur,focalBlurStrength:A.data.focalBlurStrength,focalBlurRadius:A.data.focalBlurRadius,forceImageCover:A.data.forceImageCover,x:r.left,y:r.top,width:r.width,height:r.height,layer:r.layer,layerIndex:r.layerIndex,rotation:r.rotation,scaleX:r.width/d.width,scaleY:r.height/d.height,pattern:void 0},w),new g.UpdateFramePattern(B,i,E)]};return(await Promise.all(A.data.regions.map(r=>s(r)))).flat()}catch(o){return console.error(o),[]}},Fn=async(c,e,t,A)=>{var f,D;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((f=a.variants)==null?void 0:f.find(p=>p.id===n.illustrationVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.illustrationVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.illustrationVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(D=i.asset)==null?void 0:D.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.illustrationVariantId}`),[];const s=await g.fetchAsString(o,!0),r=/<svg.*?<\/svg>/s,l=s.match(r)||[],d=(l==null?void 0:l.length)>0?l[0]:"",E=g.domParser().parseFromString(d,"image/svg+xml").firstElementChild;if(!E)return console.error("Failed to read SVG."),[];g.sanitizeSvgTree(E);const C={};g.traverse(E,p=>{fn.includes(p.tagName)&&!p.attributes.getNamedItem("fill")&&p.setAttribute("fill","#000000");const S=p.attributes.getNamedItem("fill");if(S&&S.value!=="none"){const x=S.value,H=`spiff-fill-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}const y=p.attributes.getNamedItem("stroke");if(y&&y.value!=="none"){const x=y.value,H=`spiff-stroke-${x.replace(/\W/g,"")}`;p.classList.add(H),C[H]={browserValue:x}}});const m=g.xmlSerializer().serializeToString(E),u=n.colors;if(u){for(const[p,S]of Object.entries(C))for(const y of Object.keys(u))if(S.browserValue===y){C[p]={browserValue:u[y]};break}}const F=p=>{const S=c.find(x=>x.panelId===p.panelId);if(!S)throw new J(p);const y=g.generate();return new g.CreateElementCommand({colors:C,id:y,svg:m,type:g.LayoutElementType.Illustration,y:p.top,x:p.left,rotation:p.rotation,width:p.width,height:p.height,layer:p.layer,layerIndex:p.layerIndex,immutable:p.immutable},S)},I=A.data.regions;try{return I.map(F)}catch(p){return console.error(p),[]}},Mn=async(c,e,t)=>{const A=await xt(t.data.module),n=e.data,a=(o,s)=>{const r=c.find(d=>d.panelId===s.panelId);if(!r)throw new J(s);const l=g.generate();return new g.CreateElementCommand({colors:{},id:l,svg:o,type:g.LayoutElementType.Illustration,y:s.top,x:s.left,rotation:s.rotation,width:s.width,height:s.height,layer:s.layer,layerIndex:s.layerIndex},r)},i=t.data.regions;try{return i.map(o=>a(A.svgPrint(n.text,o),o))}catch(o){return console.error(o),[]}},Sn=async(c,e,t,A)=>{var l,d;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((l=a.variants)==null?void 0:l.find(B=>B.id===n.pictureVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.pictureVariantId}`),[];if(!i.asset)return console.error(`No asset for variant with ID: ${n.pictureVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=(d=i.asset)==null?void 0:d.fileLink;if(!o)return console.error(`No asset link for variant with ID: ${n.pictureVariantId}`),[];const s=B=>{const w=c.find(C=>C.panelId===B.panelId);if(!w)throw new J(B);const E=g.generate();return new g.CreateElementCommand({id:E,src:o,type:g.LayoutElementType.Image,y:B.top,x:B.left,rotation:B.rotation,width:B.width,height:B.height,layer:B.layer,layerIndex:B.layerIndex,immutable:B.immutable,preserveAspectRatio:"none"},w)},r=A.data.regions;try{return r.map(s)}catch(B){return console.error(B),[]}},yn=async(c,e,t,A)=>{var r;const n=t.data,a=A.option;if(!a)return console.error(`No option for step ${A.stepName}.`),[];const i=((r=a.variants)==null?void 0:r.find(l=>l.id===n.colorVariantId))||g.getDefaultVariant(a);if(!i)return console.error(`No variant with ID: ${n.colorVariantId}`),[];e[A.stepName]={selectedVariants:[i]};const o=l=>{const d=c.find(h=>h.panelId===l.panelId);if(!d)throw new J(l);const B=`
|
|
2013
2013
|
<svg
|
|
2014
2014
|
xmlns="http://www.w3.org/2000/svg"
|
|
2015
2015
|
xmlnsXlink="http://www.w3.org/1999/xlink"
|
|
@@ -2344,7 +2344,7 @@ IfnI8vaNAAAAAElFTkSuQmCC" transform="matrix(0.13 0.0141 -0.0141 0.1301 104.926 1
|
|
|
2344
2344
|
}
|
|
2345
2345
|
}
|
|
2346
2346
|
}
|
|
2347
|
-
`;class ta{constructor(e,t,A){this.bundleId=e,this.bundleOwnerId=t,this.initPromise=this.getOrCreateGlobalPropertyState().then(n=>{this.globalPropertyState=n}),this.onGlobalPropertyStateChange=A}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}async setAspect(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=Ee(this.globalPropertyState),n=this.globalPropertyState.aspects.find(a=>a.name===e);n?n.value=t:this.globalPropertyState.aspects.push({name:e,value:t}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(A,this.globalPropertyState)}async updateGlobalPropertyState(){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:_n,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects},context:{bundleOwnerId:this.bundleOwnerId}});if((t=e.data)!=null&&t.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A;const e=await N.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:$n,variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});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 Aa{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(l=>l.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 _t{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 ye(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new ye(t));const e=await N.getShadowGraphqlClient().query({query:Tn,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new ye(t))}getTransformCollection(){if(this.collection.transformCollection)return new eA(this.collection.transformCollection)}getResource(){return this.collection}}class ye{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,l,d;const i=(r=a.integration)==null?void 0:r.type,o=((l=a.integration)==null?void 0:l.type)===e,s=t?((d=a.integration)==null?void 0:d.externalIntegrationId)===t:!0;return i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new G("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 Be(n)}const A=e[0];return new Be(A)}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 Be{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class eA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new tA(e))}}class tA{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 AA{constructor(e,t,A,n,a){var i,o;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((i=t.metadata)==null?void 0:i.map(s=>[s.key,s.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new Aa(t.bundleStateData),this.globalPropertyStateManager=new ta(this.id,this.ownerId,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Zn(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingWorkflowExperiences(((o=t.transactions)==null?void 0:o.map(s=>s.id))||[],n)}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()===g.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 _t(this.productCollection):void 0}async addWorkflowExperience(e){await this.appendWorkflowExperience(e),await this.injectExperienceIntoPreviewService(e);const t=await this.getGlobalProperties();await Promise.all(t.map(A=>A.applyGlobalState([e]))),e.setBundle(this)}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=P.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:jn,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))}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=(P.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:zn,variables:{id:this.id,transactionId:A},context:{bundleOwnerId:this.ownerId,transactionOwnerId:i}}),t&&this.workflowExperiences.push(e)}async removeWorkflowExperience(e){const t=this.workflowExperiences.indexOf(e);await this.removeTransaction(t,this.workflowExperiences[t].getWorkflowManager().getTransaction()),e.setBundle(void 0)}async removeWorkflowExperiences(e){await this.removeTransactions(e.map(t=>t.getWorkflowManager().getTransaction())),e.forEach(t=>t.setBundle(void 0))}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:Kn,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),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.previewService&&A.forEach(n=>n.getWorkflowManager().ejectFromPreviewService()),e.forEach(n=>this.bundleStateManager.removeStateForTransaction(n.id)),await N.getShadowGraphqlClient().mutate({mutation:Vn,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:Wn,variables:{id:this.id,details:e,type:t||se.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 updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:Xn,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:bn,errorPolicy:"all",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 un(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)),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:On,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:qn,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 na=M.gql`
|
|
2347
|
+
`;class ta{constructor(e,t,A){this.bundleId=e,this.bundleOwnerId=t,this.initPromise=this.getOrCreateGlobalPropertyState().then(n=>{this.globalPropertyState=n}),this.onGlobalPropertyStateChange=A}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}async setAspect(e,t){if(!this.globalPropertyState)throw new Error("Global property state not initialized");const A=Ee(this.globalPropertyState),n=this.globalPropertyState.aspects.find(a=>a.name===e);n?n.value=t:this.globalPropertyState.aspects.push({name:e,value:t}),await this.updateGlobalPropertyState(),await this.onGlobalPropertyStateChange(A,this.globalPropertyState)}async updateGlobalPropertyState(){var t;if(!this.globalPropertyState)throw new Error("Global property state not initialized");const e=await N.getShadowGraphqlClient().mutate({mutation:_n,variables:{id:this.globalPropertyState.id,aspects:this.globalPropertyState.aspects},context:{bundleOwnerId:this.bundleOwnerId}});if((t=e.data)!=null&&t.globalPropertyStateUpdate)this.globalPropertyState=e.data.globalPropertyStateUpdate;else throw new Error("Unable to update global property state")}async getOrCreateGlobalPropertyState(){var A;const e=await N.getShadowGraphqlClient().query({query:ea,errorPolicy:"all",fetchPolicy:"no-cache",variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});if(e.data.globalPropertyState&&e.data.globalPropertyState.id)return e.data.globalPropertyState;const t=await N.getShadowGraphqlClient().mutate({mutation:$n,variables:{bundleId:this.bundleId},context:{bundleOwnerId:this.bundleOwnerId}});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 Aa{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(l=>l.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 _t{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 ye(e))}async fetchProducts(){if(this.collection.productCollectionProducts)return this.collection.productCollectionProducts.map(t=>new ye(t));const e=await N.getShadowGraphqlClient().query({query:Tn,variables:{id:this.getId()},errorPolicy:"all",fetchPolicy:"no-cache"});return this.collection.productCollectionProducts=e.data.productCollections[0].productCollectionProducts||[],this.collection.productCollectionProducts.map(t=>new ye(t))}getTransformCollection(){if(this.collection.transformCollection)return new eA(this.collection.transformCollection)}getResource(){return this.collection}}class ye{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,l,d;const i=(r=a.integration)==null?void 0:r.type,o=((l=a.integration)==null?void 0:l.type)===e,s=t?((d=a.integration)==null?void 0:d.externalIntegrationId)===t:!0;return i&&o&&s});if(!n)throw new Error("Failed to find requested integration type on product. This is generally due to a configuration error");return n}getCurrentIntegration(){const t=(this.product.integrationProducts||[]).find(A=>{var n;return(n=A.integration)==null?void 0:n.isCurrent});if(!t)throw new Error(`Product: ${this.productResource.id} is not linked to this current integration. This is generally due to a configuration error.`);return t}getDefaultWorkflow(){const e=this.product.workflows||[];if(e.length===0)throw new G("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 Be(n)}const A=e[0];return new Be(A)}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 Be{constructor(e){this.workflow=e}getId(){return this.workflow.workflowName}getName(){return this.workflow.friendlyName}getThumbnail(){return this.workflow.imageUrl}}class eA{constructor(e){this.collection=e}getId(){return this.collection.id}getName(){return this.collection.name}getTransforms(){return this.collection.transforms.map(e=>new tA(e))}}class tA{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 AA{constructor(e,t,A,n,a){var i,o;this.eventListeners=new Map,this.workflowExperiences=[],this.client=e,this.id=t.id,this.name=t.name||"",this.ownerId=a,this.metadata=new Map(((i=t.metadata)==null?void 0:i.map(s=>[s.key,s.value]))||[]),this.productCollection=t.productCollection,this.bundleStateManager=new Aa(t.bundleStateData),this.globalPropertyStateManager=new ta(this.id,this.ownerId,this.checkConditionalHandlesChanged.bind(this)),this.globalPropertyHandleService=new Zn(this),this.setPreviewService(A),this.initializationPromise=this.loadExistingWorkflowExperiences(((o=t.transactions)==null?void 0:o.map(s=>s.id))||[],n)}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()===g.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 _t(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=P.getMap("transactionOwnerIds")||new Map,a=t.map(i=>n.get(i));await N.getShadowGraphqlClient().mutate({mutation:jn,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=(P.getMap("transactionOwnerIds")||new Map).get(A);await N.getShadowGraphqlClient().mutate({mutation:zn,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:Kn,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:Vn,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:Wn,variables:{id:this.id,details:e,type:t||se.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 updateStakeholders(e){var n;const t=await N.getShadowGraphqlClient().mutate({mutation:Xn,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:bn,errorPolicy:"all",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 un(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:On,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:qn,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 na=M.gql`
|
|
2348
2348
|
mutation processFlowCreate($processFlowId: String!, $inputs: [String]!) {
|
|
2349
2349
|
processExecutionCreate(processFlowId: $processFlowId, inputs: $inputs) {
|
|
2350
2350
|
id
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spiffcommerce/core",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.6.0-alpha.0",
|
|
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",
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"dev": "ladle serve",
|
|
12
12
|
"build": "vite build",
|
|
13
|
-
"test": "vitest
|
|
14
|
-
"test:
|
|
13
|
+
"test": "vitest",
|
|
14
|
+
"test:ci": "vitest --no-watch",
|
|
15
15
|
"test:nowatch": "vitest --no-watch",
|
|
16
16
|
"lint": "npx eslint src"
|
|
17
17
|
},
|