@spiffcommerce/core 21.1.1 → 21.2.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.2.0] - 15-03-2024
9
+
10
+ ### Added
11
+
12
+ - `FileUploadGlobalPropertyHandle`:
13
+ - `hasImage(): boolean`: Returns a boolean value indicating if the associated state has an image.
14
+ - `getImage(): Promise<Asset | undefined>`: Retrieves the current image from the server.
15
+
8
16
  ## [21.1.1] - 15-03-2024
9
17
 
10
18
  ### Fixed
package/dist/index.d.ts CHANGED
@@ -1666,6 +1666,86 @@ declare abstract class GlobalPropertyHandle {
1666
1666
  * @param targetExperiences Optionally filter the steps to only those in the given experiences.
1667
1667
  */
1668
1668
  protected getSharedSteps(targetExperiences?: WorkflowExperience[]): StepHandle<_spiffcommerce_papyrus.AnyStepData>[];
1669
+ protected getStateValue(): string | undefined;
1670
+ }
1671
+ /**
1672
+ * A file upload global property allows for setting a frame image against all shared steps.
1673
+ */
1674
+ declare class FileUploadGlobalPropertyHandle extends GlobalPropertyHandle {
1675
+ constructor(bundle: Bundle, property: GlobalPropertyConfigurationAspect);
1676
+ /**
1677
+ * Select an image to be used for all shared steps.
1678
+ * @param asset The asset to use.
1679
+ * @returns A promise resolving when all affected steps have been updated.
1680
+ */
1681
+ selectImage(asset: Asset): Promise<void>;
1682
+ /**
1683
+ * Returns `true` if the state has an image assigned, otherwise `false`.
1684
+ */
1685
+ hasImage(): boolean;
1686
+ /**
1687
+ * Retrieves the current image selection, if one exists.
1688
+ * @returns A promise that resolves with an `Asset` object if one is assigned to the state, otherwise `undefined`.
1689
+ */
1690
+ getImage(): Promise<Asset | undefined>;
1691
+ applyGlobalState(targetExperiences?: WorkflowExperience[]): Promise<void>;
1692
+ private applyImageSelection;
1693
+ }
1694
+ declare class TextGlobalPropertyHandle extends GlobalPropertyHandle {
1695
+ constructor(bundle: Bundle, property: GlobalPropertyConfigurationAspect);
1696
+ /**
1697
+ * Gets the current text
1698
+ */
1699
+ getText(): string;
1700
+ /**
1701
+ * Set the text.
1702
+ */
1703
+ setText(text: string): Promise<void>;
1704
+ applyGlobalState(targetExperiences?: WorkflowExperience[]): Promise<void>;
1705
+ private applyTextSelection;
1706
+ }
1707
+ /**
1708
+ * An option property handle represents a property that can
1709
+ * affect the option of steps across multiple transactions.
1710
+ */
1711
+ declare class OptionGlobalPropertyHandle extends GlobalPropertyHandle {
1712
+ protected optionResource?: OptionResource;
1713
+ constructor(bundle: Bundle, property: GlobalPropertyConfigurationAspect, optionResource: OptionResource | undefined);
1714
+ /**
1715
+ * Gets the currently selected variant, or undefined if no variant is selected.
1716
+ */
1717
+ getCurrentVariant(): Variant | undefined;
1718
+ /**
1719
+ * @returns A list of valid variants for this step. Does not include disabled variants.
1720
+ */
1721
+ getAvailableVariants(): Variant[];
1722
+ /**
1723
+ * @returns A list of all variants for this step, including disabled ones.
1724
+ */
1725
+ getAllVariants(): Variant[];
1726
+ /**
1727
+ * Select a given variant on the option for all shared steps.
1728
+ * @param variant The variant to select.
1729
+ */
1730
+ selectVariant(variant: Variant): Promise<void>;
1731
+ applyGlobalState(targetExperiences?: WorkflowExperience[]): Promise<void>;
1732
+ private applyVariantSelection;
1733
+ }
1734
+ /**
1735
+ * A color option property handle represents a property that can
1736
+ * affect the option of steps across multiple transactions. This class is a specialization of the OptionGlobalPropertyHandle which includes functionality for
1737
+ * setting custom color values when a custom color variant is selected.
1738
+ */
1739
+ declare class ColorOptionGlobalPropertyHandle extends OptionGlobalPropertyHandle {
1740
+ constructor(bundle: Bundle, property: GlobalPropertyConfigurationAspect, optionResource: OptionResource | undefined);
1741
+ /**
1742
+ * Sets a custom color on the global state.
1743
+ */
1744
+ setCustomColor(color: string): void;
1745
+ /**
1746
+ * Gets the custom color used by the global state.
1747
+ */
1748
+ getCustomColor(): string;
1669
1749
  }
1670
1750
 
1671
1751
  interface GlobalPropertyStateManager {
@@ -3032,4 +3112,4 @@ declare class PromiseCache {
3032
3112
  }
3033
3113
  declare const promiseCache: PromiseCache;
3034
3114
 
3035
- export { ArrayInput, AssetNotFoundError, Bundle, BundleDesignCreationMessage, BundleEvent, BundleEventData, BundleEventType, CollectionProduct, ColorOption, ConditionalGlobalPropertiesChangedEventData, ConversionConfiguration, ConversionData, ConversionDataType, ConversionLocation, Customer, CustomerDetailsInput, DesignCreationMessage, DesignCreationProgressUpdate, DesignInputStep, EditedSteps, FlowExecutionNodeResult, FlowExecutionResult, FlowService, FrameService, FrameStep, FrameStepHandle, FrameThresholdSettings, GetNewWorkflowOptions, GetWorkflowOptions, GlobalPropertyHandle, IllustrationStepHandle, InformationMessageType, InformationResult, InformationStepHandle, IntegrationProduct, IntegrationType, LayoutNotFoundError, MandatorySteps, MaterialStepHandle, MisconfigurationError, MockWorkflowManager, ModelStepHandle, NodeType, ObjectInput, ObjectInputType, OptionNotFoundError, ParseError, PictureStepHandle, Product, ProductCameraRig, ProductCollection, ProductWorkflow, promiseCache as PromiseCache, PromiseQueue, QuestionStepHandle, QueueablePromise, RegionElement, RenderableScene, ResourceNotFoundError, SavedDesign, SelectionStorage, ShapeStepHandle, SilentIllustrationStepData, SpiffCommerceClient, Stakeholder, StakeholderType, StateMutationFunc, StepElements, StepHandle, TextInput, TextStepHandle, TextStepStorage, Transaction, Transform, TransformCollection, UnhandledBehaviorError, Variant, Vector3, WorkflowExperience, WorkflowExperienceEventType, WorkflowExperienceHoverEventData, WorkflowExperienceImpl, WorkflowManager, WorkflowMetadata, WorkflowScene, WorkflowSelections, WorkflowStorage, assetService, createDesign, designService, digitalContentStepService, frameStepService, generateCommands, generateStateFromDesignInputSteps, getBoundedOffsets, getWorkflow, getWorkflows, graphQlManager, illustrationStepService, materialStepService, modelStepService, moduleStepService, optionService, persistenceService, pictureStepService, questionStepService, shapeStepService, shortenUrl, spiffCoreConfiguration, stepAspectValuesToDesignInputSteps, textStepService, toast };
3115
+ export { ArrayInput, AssetNotFoundError, Bundle, BundleDesignCreationMessage, BundleEvent, BundleEventData, BundleEventType, CollectionProduct, ColorOption, ColorOptionGlobalPropertyHandle, ConditionalGlobalPropertiesChangedEventData, ConversionConfiguration, ConversionData, ConversionDataType, ConversionLocation, Customer, CustomerDetailsInput, DesignCreationMessage, DesignCreationProgressUpdate, DesignInputStep, EditedSteps, FileUploadGlobalPropertyHandle, FlowExecutionNodeResult, FlowExecutionResult, FlowService, FrameService, FrameStep, FrameStepHandle, FrameThresholdSettings, GetNewWorkflowOptions, GetWorkflowOptions, GlobalPropertyHandle, IllustrationStepHandle, InformationMessageType, InformationResult, InformationStepHandle, IntegrationProduct, IntegrationType, LayoutNotFoundError, MandatorySteps, MaterialStepHandle, MisconfigurationError, MockWorkflowManager, ModelStepHandle, NodeType, ObjectInput, ObjectInputType, OptionGlobalPropertyHandle, OptionNotFoundError, ParseError, PictureStepHandle, Product, ProductCameraRig, ProductCollection, ProductWorkflow, promiseCache as PromiseCache, PromiseQueue, QuestionStepHandle, QueueablePromise, RegionElement, RenderableScene, ResourceNotFoundError, SavedDesign, SelectionStorage, ShapeStepHandle, SilentIllustrationStepData, SpiffCommerceClient, Stakeholder, StakeholderType, StateMutationFunc, StepElements, StepHandle, TextGlobalPropertyHandle, TextInput, TextStepHandle, TextStepStorage, Transaction, Transform, TransformCollection, UnhandledBehaviorError, Variant, Vector3, WorkflowExperience, WorkflowExperienceEventType, WorkflowExperienceHoverEventData, WorkflowExperienceImpl, WorkflowManager, WorkflowMetadata, WorkflowScene, WorkflowSelections, WorkflowStorage, assetService, createDesign, designService, digitalContentStepService, frameStepService, generateCommands, generateStateFromDesignInputSteps, getBoundedOffsets, getWorkflow, getWorkflows, graphQlManager, illustrationStepService, materialStepService, modelStepService, moduleStepService, optionService, persistenceService, pictureStepService, questionStepService, shapeStepService, shortenUrl, spiffCoreConfiguration, stepAspectValuesToDesignInputSteps, textStepService, toast };
package/dist/index.js CHANGED
@@ -460,7 +460,7 @@ class $t {
460
460
  name: e.name,
461
461
  blob: new Blob([e], { type: e.type })
462
462
  };
463
- return await O.uploadAssetWithProgress(a, n, A, !0);
463
+ return await T.uploadAssetWithProgress(a, n, A, !0);
464
464
  }
465
465
  }
466
466
  removePersistedAsset(e) {
@@ -533,7 +533,7 @@ class be {
533
533
  return e ? Array.from(e.entries()).map((A) => ({ assetKey: A[0], src: A[1] })) : [];
534
534
  }
535
535
  }
536
- const O = new $t();
536
+ const T = new $t();
537
537
  class _t {
538
538
  constructor() {
539
539
  this.cache = {}, this.disabled = !1;
@@ -625,8 +625,8 @@ const ge = new _t(), KA = F`
625
625
  });
626
626
  return e.data.options.forEach((A) => {
627
627
  var t, n;
628
- (t = A.defaultVariant) != null && t.asset && O.cacheAsset(A.defaultVariant.asset), A.colorProfile && O.cacheAsset(A.colorProfile), (n = A.variants) == null || n.forEach((a) => {
629
- a.asset && O.cacheAsset(a.asset), a.displayImage && O.cacheAsset(a.displayImage), a.thumbnail && O.cacheAsset(a.thumbnail), a.material && O.cacheMaterial(a.material);
628
+ (t = A.defaultVariant) != null && t.asset && T.cacheAsset(A.defaultVariant.asset), A.colorProfile && T.cacheAsset(A.colorProfile), (n = A.variants) == null || n.forEach((a) => {
629
+ a.asset && T.cacheAsset(a.asset), a.displayImage && T.cacheAsset(a.displayImage), a.thumbnail && T.cacheAsset(a.thumbnail), a.material && T.cacheMaterial(a.material);
630
630
  });
631
631
  }), e.data.options;
632
632
  }, tn = async (c, e) => (await e).find((t) => t.id === c), nn = async (c) => {
@@ -1852,11 +1852,11 @@ class Mn {
1852
1852
  new qA(
1853
1853
  async () => {
1854
1854
  var o;
1855
- const i = (o = (await O.getLocalOrFromServer(A.key || "")).versions) == null ? void 0 : o.find((r) => r.name === "svg");
1855
+ const i = (o = (await T.getLocalOrFromServer(A.key || "")).versions) == null ? void 0 : o.find((r) => r.name === "svg");
1856
1856
  return i ? (await fetch(i.link)).status === 200 : !1;
1857
1857
  },
1858
1858
  () => {
1859
- O.getLocalOrFromServer(A.key || "").then((a) => {
1859
+ T.getLocalOrFromServer(A.key || "").then((a) => {
1860
1860
  this.loadPatternFromAsset(a, e, t);
1861
1861
  });
1862
1862
  },
@@ -3224,8 +3224,8 @@ class kn {
3224
3224
  let Q;
3225
3225
  if (E && E.variants) {
3226
3226
  const N = E.variants.find((H) => {
3227
- var T;
3228
- return H.id === ((T = E.defaultVariant) == null ? void 0 : T.id);
3227
+ var O;
3228
+ return H.id === ((O = E.defaultVariant) == null ? void 0 : O.id);
3229
3229
  }) || E.variants[0];
3230
3230
  Q = this.createTextFillSpotColor(E, N), i.updateStorage(e, {
3231
3231
  colorProfileAssetKey: (h = E.colorProfile) == null ? void 0 : h.key
@@ -6280,7 +6280,7 @@ const ot = F`
6280
6280
  }, ct = async (c, e, A, t, n, a, i, s, o, r) => {
6281
6281
  var M;
6282
6282
  await (async () => {
6283
- var T;
6283
+ var O;
6284
6284
  if (r !== void 0)
6285
6285
  return r;
6286
6286
  await c.outstandingRequestsPromise();
@@ -6292,7 +6292,7 @@ const ot = F`
6292
6292
  context: {
6293
6293
  transactionOwnerId: S
6294
6294
  }
6295
- }), H = (T = N.data) == null ? void 0 : T.transactions[0].workflowState;
6295
+ }), H = (O = N.data) == null ? void 0 : O.transactions[0].workflowState;
6296
6296
  return N.errors ? (N.errors.forEach((b) => {
6297
6297
  N.errors && console.log("Server Error:", b.message);
6298
6298
  }), null) : H ?? null;
@@ -6302,11 +6302,11 @@ const ot = F`
6302
6302
  let Y = 0;
6303
6303
  if (Object.keys(a).length > 0)
6304
6304
  for (const N of Object.keys(a)) {
6305
- const H = a[N], T = e.steps.find((b) => b.stepName === N);
6305
+ const H = a[N], O = e.steps.find((b) => b.stepName === N);
6306
6306
  for (let b = 0; b < H.selections.length; ++b) {
6307
6307
  const V = H.selections[b];
6308
- if (T && (!y || T.option && (T.option.variants || []).length > 1 && !T.data.hideSelectionInCart && !T.data.hideSelectionsInCart)) {
6309
- const ke = T.stepTitle;
6308
+ if (O && (!y || O.option && (O.option.variants || []).length > 1 && !O.data.hideSelectionInCart && !O.data.hideSelectionsInCart)) {
6309
+ const ke = O.stepTitle;
6310
6310
  S[ke] ? S[ke].push({
6311
6311
  id: V.id || "",
6312
6312
  name: V.name,
@@ -7944,6 +7944,9 @@ class gA {
7944
7944
  })
7945
7945
  );
7946
7946
  }
7947
+ getStateValue() {
7948
+ return this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);
7949
+ }
7947
7950
  }
7948
7951
  class ja extends gA {
7949
7952
  constructor(e, A) {
@@ -7960,11 +7963,26 @@ class ja extends gA {
7960
7963
  this.applyImageSelection(e)
7961
7964
  ]);
7962
7965
  }
7966
+ /**
7967
+ * Returns `true` if the state has an image assigned, otherwise `false`.
7968
+ */
7969
+ hasImage() {
7970
+ return !!this.getStateValue();
7971
+ }
7972
+ /**
7973
+ * Retrieves the current image selection, if one exists.
7974
+ * @returns A promise that resolves with an `Asset` object if one is assigned to the state, otherwise `undefined`.
7975
+ */
7976
+ async getImage() {
7977
+ const e = this.getStateValue();
7978
+ if (e)
7979
+ return T.getLocalOrFromServer(e);
7980
+ }
7963
7981
  async applyGlobalState(e) {
7964
- const A = this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);
7982
+ const A = this.getStateValue();
7965
7983
  if (!A)
7966
7984
  return Promise.resolve();
7967
- const t = await O.getLocalOrFromServer(A);
7985
+ const t = await T.getLocalOrFromServer(A);
7968
7986
  return t ? this.applyImageSelection(t, e) : Promise.resolve();
7969
7987
  }
7970
7988
  async applyImageSelection(e, A) {
@@ -7980,7 +7998,7 @@ class Va extends gA {
7980
7998
  * Gets the current text
7981
7999
  */
7982
8000
  getText() {
7983
- const e = this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);
8001
+ const e = this.getStateValue();
7984
8002
  return e || "";
7985
8003
  }
7986
8004
  /**
@@ -7993,7 +8011,7 @@ class Va extends gA {
7993
8011
  ]);
7994
8012
  }
7995
8013
  async applyGlobalState(e) {
7996
- const A = this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);
8014
+ const A = this.getStateValue();
7997
8015
  if (!A)
7998
8016
  return Promise.resolve();
7999
8017
  await this.applyTextSelection(A, e);
@@ -8016,7 +8034,7 @@ class Bt extends gA {
8016
8034
  var A, t;
8017
8035
  if (!this.optionResource)
8018
8036
  return;
8019
- const e = this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);
8037
+ const e = this.getStateValue();
8020
8038
  if (e) {
8021
8039
  const n = (t = this.optionResource.variants) == null ? void 0 : t.find((a) => a.id === e);
8022
8040
  return n ? new X(n) : void 0;
@@ -8056,7 +8074,7 @@ class Bt extends gA {
8056
8074
  }
8057
8075
  async applyGlobalState(e) {
8058
8076
  var n, a;
8059
- const A = this.bundle.getGlobalPropertyStateManager().getAspect(this.property.name);
8077
+ const A = this.getStateValue();
8060
8078
  if (!A)
8061
8079
  return Promise.resolve();
8062
8080
  const t = (a = (n = this.optionResource) == null ? void 0 : n.variants) == null ? void 0 : a.find((i) => i.id === A);
@@ -9821,8 +9839,8 @@ const oi = F`
9821
9839
  return t.forEach((a) => {
9822
9840
  a.steps.forEach((i) => {
9823
9841
  var s, o, r;
9824
- delete i.data.__typename, (s = i.option) != null && s.id && ((o = i.option.defaultVariant) != null && o.asset && O.cacheAsset(i.option.defaultVariant.asset), i.option.colorProfile && O.cacheAsset(i.option.colorProfile), (r = i.option.variants) == null || r.forEach((g) => {
9825
- g.asset && O.cacheAsset(g.asset), g.displayImage && O.cacheAsset(g.displayImage), g.thumbnail && O.cacheAsset(g.thumbnail), g.material && O.cacheMaterial(g.material);
9842
+ delete i.data.__typename, (s = i.option) != null && s.id && ((o = i.option.defaultVariant) != null && o.asset && T.cacheAsset(i.option.defaultVariant.asset), i.option.colorProfile && T.cacheAsset(i.option.colorProfile), (r = i.option.variants) == null || r.forEach((g) => {
9843
+ g.asset && T.cacheAsset(g.asset), g.displayImage && T.cacheAsset(g.displayImage), g.thumbnail && T.cacheAsset(g.thumbnail), g.material && T.cacheMaterial(g.material);
9826
9844
  }), ge.set({ id: i.option.id }, Promise.resolve(i.option)));
9827
9845
  });
9828
9846
  }), t;
@@ -9874,7 +9892,7 @@ class fi {
9874
9892
  * and the Spiff Commerce platform.
9875
9893
  */
9876
9894
  getAssetManager() {
9877
- return O;
9895
+ return T;
9878
9896
  }
9879
9897
  getCurrencyCode() {
9880
9898
  if (this.currencyCode === void 0)
@@ -10307,7 +10325,7 @@ class fi {
10307
10325
  return {
10308
10326
  transaction: Y,
10309
10327
  workflowId: Y.workflowId,
10310
- readOnly: ((H = m.find((T) => T.option.transactionId === Y.id)) == null ? void 0 : H.option.readOnly) ?? !1,
10328
+ readOnly: ((H = m.find((O) => O.option.transactionId === Y.id)) == null ? void 0 : H.option.readOnly) ?? !1,
10311
10329
  index: m[N].index
10312
10330
  };
10313
10331
  });
@@ -10345,14 +10363,14 @@ class fi {
10345
10363
  ...r.map(n),
10346
10364
  ...g.map(a)
10347
10365
  ])).flat(), l = [...new Set(B.map((m) => m.workflowId))], d = await wt(l, A), w = new Map(d.map((m) => [m.id, m])), h = x.getMap("transactionOwnerIds") || /* @__PURE__ */ new Map(), E = B.map(async (m) => {
10348
- var T;
10366
+ var O;
10349
10367
  const { transaction: I, workflowId: p, readOnly: M, index: y } = m, S = w.get(p), Y = e[y];
10350
10368
  !h.get(I.id) && I.transactionOwnerId && h.set(I.id, I.transactionOwnerId);
10351
10369
  const N = h.get(I.id) || void 0, H = {
10352
10370
  product: I.product,
10353
10371
  transaction: I,
10354
10372
  layouts: [],
10355
- singleVariantsRenderable: (T = Y == null ? void 0 : Y.workflowConfiguration) == null ? void 0 : T.singleVariantsRenderable,
10373
+ singleVariantsRenderable: (O = Y == null ? void 0 : Y.workflowConfiguration) == null ? void 0 : O.singleVariantsRenderable,
10356
10374
  stateMutationFunc: M ? async () => {
10357
10375
  throw new k("State mutation is forbidden in read only mode!");
10358
10376
  } : async (b) => this.updateTransactionState({ ...b, context: { transactionOwnerId: N } }),
@@ -10789,12 +10807,14 @@ export {
10789
10807
  Xi as BringToFrontCommand,
10790
10808
  qi as CanvasCommand,
10791
10809
  Oe as CollectionProduct,
10810
+ Wa as ColorOptionGlobalPropertyHandle,
10792
10811
  Zi as CommandContext,
10793
10812
  cn as ConversionDataType,
10794
10813
  rn as ConversionLocation,
10795
10814
  $i as CreateElementCommand,
10796
10815
  _i as CreateLayoutCommand,
10797
10816
  es as DeleteElementCommand,
10817
+ ja as FileUploadGlobalPropertyHandle,
10798
10818
  Qe as FlowExecutionNodeResult,
10799
10819
  ii as FlowExecutionResult,
10800
10820
  ai as FlowService,
@@ -10822,6 +10842,7 @@ export {
10822
10842
  rs as MoveCommand,
10823
10843
  dt as ObjectInput,
10824
10844
  si as ObjectInputType,
10845
+ Bt as OptionGlobalPropertyHandle,
10825
10846
  Me as OptionNotFoundError,
10826
10847
  oe as ParseError,
10827
10848
  Aa as PictureStepHandle,
@@ -10843,6 +10864,7 @@ export {
10843
10864
  W as StepHandle,
10844
10865
  ds as StepType,
10845
10866
  ws as TextChangeCommand,
10867
+ Va as TextGlobalPropertyHandle,
10846
10868
  bi as TextInput,
10847
10869
  aa as TextStepHandle,
10848
10870
  ti as Transform,
@@ -10852,7 +10874,7 @@ export {
10852
10874
  X as Variant,
10853
10875
  Ea as WorkflowExperienceEventType,
10854
10876
  he as WorkflowExperienceImpl,
10855
- O as assetService,
10877
+ T as assetService,
10856
10878
  la as createDesign,
10857
10879
  hs as dataUrlFromExternalUrl,
10858
10880
  Te as designService,