@spiffcommerce/core 21.5.0-alpha.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/CHANGELOG.md CHANGED
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [21.5.0] - 22-03-2024
9
+
10
+ ### Changed
11
+
12
+ - `StepHandle`: The override global property state setting now has a different value for each Global Property Aspect type. The get/set functions have been renamed and have an extra parameter to determine the Aspect Type.
13
+ - `getOverrideGlobalPreviewConfiguration` -> `getOverrideGlobalPropertyConfiguration(type: AspectType): boolean`.
14
+ - `setOverrideGlobalPreviewConfiguration` -> `setOverrideGlobalPropertyConfiguration(type: AspectType, value: boolean): void`
15
+
8
16
 
9
17
  ## [21.4.1] - 21-03-2024
10
18
 
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 breal.
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 quiting the experience.
950
+ * The client should allow the user to input details just before quitting the experience.
951
951
  */
952
952
  OnQuit = "OnQuit",
953
953
  /**
@@ -1306,14 +1306,14 @@ declare abstract class StepHandle<T extends AnyStepData> {
1306
1306
  * Only relevant when the Workflow Experience is associated with a Bundle that is using Global Properties,
1307
1307
  * and when this step is associated with one or more Global Property Aspects.
1308
1308
  */
1309
- getOverrideGlobalPreviewConfiguration(type: AspectType): boolean;
1309
+ getOverrideGlobalPropertyConfiguration(type: AspectType): boolean;
1310
1310
  /**
1311
1311
  * Sets whether or not this step should override Global Properties.
1312
1312
  * Only relevant when the Workflow Experience is associated with a Bundle that is using Global Properties,
1313
1313
  * and when this step is associated with one or more Global Property Aspects.
1314
1314
  * @param type The AspectType to override.
1315
1315
  */
1316
- setOverrideGlobalPreviewConfiguration(type: AspectType, value: boolean): void;
1316
+ setOverrideGlobalPropertyConfiguration(type: AspectType, value: boolean): void;
1317
1317
  /**
1318
1318
  * Retrieves the identifiers of all of the configured aspects for the specified Global Property Configuration.
1319
1319
  * @param configurationId The ID of the Global Property Configuration. You can usually find this with `bundle.getGlobalPropertyConfiguration()?.id`
@@ -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
@@ -5723,7 +5723,7 @@ const sA = class qe {
5723
5723
  * Only relevant when the Workflow Experience is associated with a Bundle that is using Global Properties,
5724
5724
  * and when this step is associated with one or more Global Property Aspects.
5725
5725
  */
5726
- getOverrideGlobalPreviewConfiguration(e) {
5726
+ getOverrideGlobalPropertyConfiguration(e) {
5727
5727
  var A;
5728
5728
  return (((A = this.manager.getStepStorage(this.step.stepName)) == null ? void 0 : A.overrideGlobalConfigurations) ?? {})[e.toString()] ?? !1;
5729
5729
  }
@@ -5733,7 +5733,7 @@ const sA = class qe {
5733
5733
  * and when this step is associated with one or more Global Property Aspects.
5734
5734
  * @param type The AspectType to override.
5735
5735
  */
5736
- setOverrideGlobalPreviewConfiguration(e, t) {
5736
+ setOverrideGlobalPropertyConfiguration(e, t) {
5737
5737
  var n;
5738
5738
  const A = ((n = this.manager.getStepStorage(this.step.stepName)) == null ? void 0 : n.overrideGlobalConfigurations) ?? {};
5739
5739
  A[e.toString()] = t, this.manager.updateStorage(this.step.stepName, { overrideGlobalConfigurations: A });
@@ -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(this.getWorkflowManager().getProduct().basePrice || 0, t);
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
- var n;
6764
- const e = (this.getWorkflowManager().getProduct().priceBreaks || []).sort((a, i) => -(a.minQty - i.minQty)), A = (((n = this.bundle) == null ? void 0 : n.getWorkflowExperiences()) || []).filter(
6765
- (a) => a.getWorkflowManager().getProduct().id === this.getWorkflowManager().getProduct().id
6766
- ).reduce((a, i) => a + i.getQuantity(), 0);
6767
- for (const a of e)
6768
- if (a.minQty <= A)
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,
@@ -8022,7 +8042,7 @@ class gt {
8022
8042
  return (e ?? this.bundle.getWorkflowExperiences()).flatMap(
8023
8043
  (n) => n.getSteps().filter((a) => {
8024
8044
  var i;
8025
- return a.getOverrideGlobalPreviewConfiguration(this.property.type) ? !1 : (i = a.getRaw().globalPropertyAspectConfigurations) == null ? void 0 : i.some(
8045
+ return a.getOverrideGlobalPropertyConfiguration(this.property.type) ? !1 : (i = a.getRaw().globalPropertyAspectConfigurations) == null ? void 0 : i.some(
8026
8046
  (s) => {
8027
8047
  var o, r;
8028
8048
  return s.globalPropertyConfigurationId === ((r = (o = this.bundle.getProductCollection()) == null ? void 0 : o.getResource().globalPropertyConfiguration) == null ? void 0 : r.id) && s.aspectName === this.property.name;
@@ -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]))), e.setBundle(this);
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()), e.setBundle(void 0);
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())), e.forEach((t) => t.setBundle(void 0));
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.previewService && A.forEach((n) => n.getWorkflowManager().ejectFromPreviewService()), e.forEach((n) => this.bundleStateManager.removeStateForTransaction(n.id)), await P.getShadowGraphqlClient().mutate({
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
  }