@spiffcommerce/core 29.1.2 → 29.2.0-beta.c2f233cf-0c8a-5f9b-b1db-025730373034

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.mjs CHANGED
@@ -9631,6 +9631,7 @@ const re = v`
9631
9631
  value
9632
9632
  type
9633
9633
  channel
9634
+ mandatoryFulfilled
9634
9635
  storage {
9635
9636
  ... on GlobalPropertyStateColorOptionStorage {
9636
9637
  customColor
@@ -9760,6 +9761,7 @@ const re = v`
9760
9761
  title
9761
9762
  description
9762
9763
  entityId
9764
+ mandatory
9763
9765
  conditions {
9764
9766
  targetAspectName
9765
9767
  action
@@ -9771,6 +9773,9 @@ const re = v`
9771
9773
  pmsPickerEnabled
9772
9774
  colorOptionId
9773
9775
  }
9776
+ text {
9777
+ templatingEnabled
9778
+ }
9774
9779
  }
9775
9780
  }
9776
9781
  }
@@ -13565,13 +13570,13 @@ class Pa {
13565
13570
  return this.property.name;
13566
13571
  }
13567
13572
  /**
13568
- * @returns A human friendly title.
13573
+ * @returns A human-friendly title.
13569
13574
  */
13570
13575
  getTitle() {
13571
13576
  return this.property.title;
13572
13577
  }
13573
13578
  /**
13574
- * @returns A human friendly description.
13579
+ * @returns A human-friendly description.
13575
13580
  */
13576
13581
  getDescription() {
13577
13582
  return this.property.description;
@@ -13588,6 +13593,18 @@ class Pa {
13588
13593
  getRawProperty() {
13589
13594
  return this.property;
13590
13595
  }
13596
+ /**
13597
+ * @returns Whether this aspect has been marked as required to be completed before the user can continue.
13598
+ */
13599
+ isMandatory() {
13600
+ return !!this.property.mandatory;
13601
+ }
13602
+ /**
13603
+ * @returns Whether this aspect has been marked as `completed` for mandatory checks. Note that this function always returns `true` if the aspect has not been marked as mandatory.
13604
+ */
13605
+ isMandatoryFulfilled() {
13606
+ return !this.property.mandatory || !!this.bundle.getGlobalPropertyStateManager().getAspectMandatoryFulfilled(this.property.name);
13607
+ }
13591
13608
  /**
13592
13609
  * Returns all steps that share this property.
13593
13610
  * @param targetExperiences Optionally filter the steps to only those in the given experiences.
@@ -13649,12 +13666,18 @@ class cl extends Pa {
13649
13666
  async selectImage(t) {
13650
13667
  const e = this.bundle.getGlobalPropertyStateManager();
13651
13668
  await Promise.all([
13652
- e.setAspect(this.property.name, t.key, {
13653
- ...e.getAspectStorage(this.property.name) || {},
13654
- originalAssetKey: t.key,
13655
- backgroundRemovedAssetKey: void 0,
13656
- useOriginalAsset: void 0
13657
- }),
13669
+ e.setAspect(
13670
+ this.property.name,
13671
+ t.key,
13672
+ {
13673
+ ...e.getAspectStorage(this.property.name) || {},
13674
+ originalAssetKey: t.key,
13675
+ backgroundRemovedAssetKey: void 0,
13676
+ useOriginalAsset: void 0
13677
+ },
13678
+ void 0,
13679
+ !0
13680
+ ),
13658
13681
  this.applyImageSelection(t),
13659
13682
  this.loadImageData()
13660
13683
  ]);
@@ -13850,6 +13873,14 @@ class dl extends Pa {
13850
13873
  constructor(t, e) {
13851
13874
  super(t, e);
13852
13875
  }
13876
+ /**
13877
+ * If this returns false, you should not display any templating tools.
13878
+ * Note: Templates will currently still be rendered, regardless of what this function returns.
13879
+ */
13880
+ isTemplatingEnabled() {
13881
+ var t, e;
13882
+ return ((e = (t = this.property.data) == null ? void 0 : t.text) == null ? void 0 : e.templatingEnabled) || !1;
13883
+ }
13853
13884
  /**
13854
13885
  * Gets the current text
13855
13886
  */
@@ -13862,7 +13893,7 @@ class dl extends Pa {
13862
13893
  */
13863
13894
  async setText(t) {
13864
13895
  await Promise.all([
13865
- this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name, t),
13896
+ this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name, t, void 0, void 0, t.trim() !== ""),
13866
13897
  this.applyTextSelection(t)
13867
13898
  ]);
13868
13899
  }
@@ -13937,7 +13968,7 @@ class er extends Pa {
13937
13968
  */
13938
13969
  async selectVariant(t, e) {
13939
13970
  await Promise.all([
13940
- this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name, t.getId(), void 0, e),
13971
+ this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name, t.getId(), void 0, e, !0),
13941
13972
  this.applyVariantSelection(t)
13942
13973
  ]);
13943
13974
  }
@@ -13964,7 +13995,7 @@ class Ka extends er {
13964
13995
  */
13965
13996
  async selectVariant(t, e) {
13966
13997
  await Promise.all([
13967
- this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name, t.getId(), void 0, e),
13998
+ this.bundle.getGlobalPropertyStateManager().setAspect(this.property.name, t.getId(), void 0, e, !0),
13968
13999
  this.applyColorVariant(t, void 0, e)
13969
14000
  ]);
13970
14001
  }
@@ -14067,73 +14098,85 @@ class hl {
14067
14098
  throw new Error("Global property state not initialized");
14068
14099
  return (a = this.globalPropertyState.aspects.find((n) => n.name === t && n.channel === e)) == null ? void 0 : a.storage;
14069
14100
  }
14070
- async setAspect(t, e, a, n) {
14101
+ getAspectMandatoryFulfilled(t) {
14102
+ if (!this.globalPropertyState)
14103
+ throw new Error("Global property state not initialized");
14104
+ const e = this.globalPropertyState.aspects.filter((a) => a.name === t);
14105
+ if (e)
14106
+ return e.some((a) => !!a.mandatoryFulfilled);
14107
+ }
14108
+ async setAspect(t, e, a, n, i) {
14071
14109
  if (!this.globalPropertyState)
14072
14110
  throw new Error("Global property state not initialized");
14073
14111
  if (!this.configuration)
14074
14112
  throw new Error("Global property configuration not linked to the state manager.");
14075
- const i = this.configuration.aspects.find((l) => l.name === t);
14076
- if (!i)
14113
+ const s = this.configuration.aspects.find((c) => c.name === t);
14114
+ if (!s)
14077
14115
  throw new Error(`Failed to find configuration aspect with name: ${t}`);
14078
- const s = yt(this.globalPropertyState), o = this.globalPropertyState.aspects.filter((l) => l.name === t);
14079
- if (o.length > 0)
14116
+ const o = yt(this.globalPropertyState), l = this.globalPropertyState.aspects.filter((c) => c.name === t);
14117
+ if (l.length > 0)
14080
14118
  if (n) {
14081
- const l = o.find((c) => c.channel === n);
14082
- if (l)
14083
- l.value = e, l.type = i.type, l.channel = n, a !== void 0 && (l.storage = a !== null ? a : void 0);
14119
+ const c = l.find((d) => d.channel === n);
14120
+ if (c)
14121
+ c.value = e, c.type = s.type, c.channel = n, a !== void 0 && (c.storage = a !== null ? a : void 0), i !== void 0 && (c.mandatoryFulfilled = i);
14084
14122
  else {
14085
14123
  if (n === 1) {
14086
- const c = this.globalPropertyState.aspects.findIndex((d) => !d.channel && d.name === t);
14087
- c && c > 0 && this.globalPropertyState.aspects.splice(c, 1);
14124
+ const d = this.globalPropertyState.aspects.findIndex(
14125
+ (A) => !A.channel && A.name === t
14126
+ );
14127
+ d && d > 0 && this.globalPropertyState.aspects.splice(d, 1);
14088
14128
  }
14089
14129
  this.globalPropertyState.aspects.push({
14090
14130
  name: t,
14091
14131
  value: e,
14092
- type: i.type,
14132
+ type: s.type,
14093
14133
  storage: a !== null ? a : void 0,
14094
- channel: n
14134
+ channel: n,
14135
+ mandatoryFulfilled: i
14095
14136
  });
14096
14137
  }
14097
14138
  } else {
14098
- const l = o[0];
14099
- l.value = e, l.type = i.type, a !== void 0 && (l.storage = a !== null ? a : void 0);
14139
+ const c = l[0];
14140
+ c.value = e, c.type = s.type, a !== void 0 && (c.storage = a !== null ? a : void 0), i !== void 0 && (c.mandatoryFulfilled = i);
14100
14141
  }
14101
14142
  else
14102
14143
  this.globalPropertyState.aspects.push({
14103
14144
  name: t,
14104
14145
  value: e,
14105
- type: i.type,
14146
+ type: s.type,
14106
14147
  storage: a !== null ? a : void 0,
14107
- channel: n
14148
+ channel: n,
14149
+ mandatoryFulfilled: i
14108
14150
  });
14109
- await this.updateGlobalPropertyState(), await this.onGlobalPropertyStateChange(s, this.globalPropertyState);
14151
+ await this.updateGlobalPropertyState(), await this.onGlobalPropertyStateChange(o, this.globalPropertyState);
14110
14152
  }
14111
- async setAspectStorage(t, e, a) {
14153
+ async setAspectStorage(t, e, a, n) {
14112
14154
  if (!this.globalPropertyState)
14113
14155
  throw new Error("Global property state not initialized");
14114
14156
  if (!this.configuration)
14115
14157
  throw new Error("Global property configuration not linked to the state manager.");
14116
- const n = this.configuration.aspects.find((o) => o.name === t);
14117
- if (!n)
14158
+ const i = this.configuration.aspects.find((l) => l.name === t);
14159
+ if (!i)
14118
14160
  throw new Error(`Failed to find configuration aspect with name: ${t}`);
14119
- const i = yt(this.globalPropertyState), s = this.globalPropertyState.aspects.filter((o) => o.name === t);
14120
- if (s.length > 0)
14161
+ const s = yt(this.globalPropertyState), o = this.globalPropertyState.aspects.filter((l) => l.name === t);
14162
+ if (o.length > 0)
14121
14163
  if (a) {
14122
- const o = s.find((l) => l.channel === a);
14123
- o && (o.storage = e !== null ? e : void 0, o.type = n.type);
14164
+ const l = o.find((c) => c.channel === a);
14165
+ l && (l.storage = e !== null ? e : void 0, l.type = i.type, n !== void 0 && (l.mandatoryFulfilled = n));
14124
14166
  } else {
14125
- const o = s[0];
14126
- o.storage = e !== null ? e : void 0, o.type = n.type;
14167
+ const l = o[0];
14168
+ l.storage = e !== null ? e : void 0, l.type = i.type, n !== void 0 && (l.mandatoryFulfilled = n);
14127
14169
  }
14128
14170
  else
14129
14171
  this.globalPropertyState.aspects.push({
14130
14172
  name: t,
14131
14173
  value: "",
14132
- type: n.type,
14174
+ type: i.type,
14133
14175
  storage: e !== null ? e : void 0,
14134
- channel: a
14176
+ channel: a,
14177
+ mandatoryFulfilled: n
14135
14178
  });
14136
- await this.updateGlobalPropertyState(), await this.onGlobalPropertyStateChange(i, this.globalPropertyState);
14179
+ await this.updateGlobalPropertyState(), await this.onGlobalPropertyStateChange(s, this.globalPropertyState);
14137
14180
  }
14138
14181
  async updateGlobalPropertyState() {
14139
14182
  var e, a;
@@ -14839,7 +14882,7 @@ class Ke {
14839
14882
  this.id,
14840
14883
  this.ownerId,
14841
14884
  o,
14842
- this.checkConditionalHandlesChanged.bind(this),
14885
+ this.onGlobalPropertiesChanged.bind(this),
14843
14886
  s
14844
14887
  ), this.globalPropertyHandleService = new ll(this), this.setPreviewService(a);
14845
14888
  const l = new Promise((u, h) => {
@@ -15497,22 +15540,36 @@ class Ke {
15497
15540
  }
15498
15541
  });
15499
15542
  }
15500
- async checkConditionalHandlesChanged(t, e) {
15543
+ async onGlobalPropertiesChanged(t, e) {
15501
15544
  const a = await this.globalPropertyHandleService.getHandles(), n = this.globalPropertyHandleService.applyConditionsFromState(a, t), i = this.globalPropertyHandleService.applyConditionsFromState(a, e);
15502
- if ((() => {
15503
- if (n.length !== i.length)
15545
+ this.checkConditionalHandlesChanged(n, i), this.checkMandatoryHandlesChanged(n, i);
15546
+ const s = i.filter((o) => !n.includes(o));
15547
+ await Promise.all(s.map((o) => o.applyGlobalState()));
15548
+ }
15549
+ checkConditionalHandlesChanged(t, e) {
15550
+ (() => {
15551
+ if (t.length !== e.length)
15504
15552
  return !0;
15505
- for (let o = 0; o < n.length; o++)
15506
- if (n[o].getName() !== i[o].getName())
15553
+ for (let n = 0; n < t.length; n++)
15554
+ if (t[n].getName() !== e[n].getName())
15507
15555
  return !0;
15508
15556
  return !1;
15509
- })()) {
15510
- this.fireEvent("conditional-global-properties-changed", {
15511
- globalProperties: i
15512
- });
15513
- const o = i.filter((l) => !n.includes(l));
15514
- await Promise.all(o.map((l) => l.applyGlobalState()));
15515
- }
15557
+ })() && this.fireEvent("conditional-global-properties-changed", {
15558
+ globalProperties: e
15559
+ });
15560
+ }
15561
+ checkMandatoryHandlesChanged(t, e) {
15562
+ const a = [], n = [], i = [];
15563
+ for (const s of e)
15564
+ if (s.isMandatory()) {
15565
+ const o = t.find((c) => c.getName() == s.getName()), l = s.isMandatoryFulfilled();
15566
+ l ? n.push(s) : i.push(s), (!o || o.isMandatoryFulfilled() !== l) && a.push(s);
15567
+ }
15568
+ a.length > 0 && this.fireEvent("global-properties-mandatory-changed", {
15569
+ changed: a,
15570
+ completed: n,
15571
+ remaining: i
15572
+ });
15516
15573
  }
15517
15574
  fireEvent(t, e) {
15518
15575
  this.eventEmitter.emit(t, e);
@@ -16113,7 +16170,7 @@ class gd {
16113
16170
  } catch (a) {
16114
16171
  throw console.error(a), new ut("Critical - Unable to synchronize workflow state with server.");
16115
16172
  }
16116
- }, this.options = t, this.options.applicationKey && Lr(this.options.applicationKey), console.debug("------------------------"), console.debug("Spiff Commerce Core SDK"), console.debug("Version: 29.1.2"), console.debug(`Application Key Provided: ${!!this.options.applicationKey}`), console.debug("------------------------");
16173
+ }, this.options = t, this.options.applicationKey && Lr(this.options.applicationKey), console.debug("------------------------"), console.debug("Spiff Commerce Core SDK"), console.debug("Version: 29.2.0-beta.d6eca60e-99f1-5e8b-b469-3e390879560c"), console.debug(`Application Key Provided: ${!!this.options.applicationKey}`), console.debug("------------------------");
16117
16174
  }
16118
16175
  configure(t) {
16119
16176
  mt.setHubUrl(t.hubUrl), mt.setServerUrl(t.serverUrl), mt.setServicesApiUrl(t.servicesApiUrl), this.marketplaceThemeInstallId = t.marketplaceThemeInstallId, this.marketplaceThemeInstallConfigurationId = t.marketplaceThemeInstallConfigurationId, this.userPoolClientId = t.userPoolClientId, this.userPoolRegion = t.userPoolRegion, this.spiffRegion = t.spiffRegion, t.bearerAuthenticationToken && zr(t.bearerAuthenticationToken), this.options.applicationKey && this.getIntegration(), this.spiffRegion && this.userPoolRegion && this.userPoolClientId && Lt.init(this.spiffRegion, this.userPoolRegion, this.userPoolClientId);