@wise/dynamic-flow-client 4.19.4 → 4.20.1

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.
Files changed (22) hide show
  1. package/build/main.css +3 -2
  2. package/build/main.js +487 -184
  3. package/build/main.mjs +487 -184
  4. package/build/types/revamp/domain/components/MarkdownComponent.d.ts +3 -1
  5. package/build/types/revamp/domain/components/MoneyInputComponent.d.ts +22 -0
  6. package/build/types/revamp/domain/components/ParagraphComponent.d.ts +3 -1
  7. package/build/types/revamp/domain/components/SelectInputComponent.d.ts +1 -0
  8. package/build/types/revamp/domain/features/validation/value-checks.d.ts +2 -0
  9. package/build/types/revamp/domain/mappers/layout/markdownLayoutToComponent.d.ts +1 -1
  10. package/build/types/revamp/domain/mappers/layout/paragraphLayoutToComponent.d.ts +1 -1
  11. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/assertDisplayOrder.d.ts +3 -0
  12. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.d.ts +5 -0
  13. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.d.ts +9 -0
  14. package/build/types/revamp/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.d.ts +36 -0
  15. package/build/types/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.d.ts +36 -0
  16. package/build/types/revamp/domain/mappers/types.d.ts +2 -2
  17. package/build/types/revamp/domain/types.d.ts +2 -1
  18. package/build/types/revamp/renderers/mappers/moneyInputComponentToProps.d.ts +4 -0
  19. package/build/types/revamp/renderers/mappers/utils/getValidationState.d.ts +3 -0
  20. package/build/types/revamp/renderers/mappers/utils/inputComponentToProps.d.ts +2 -3
  21. package/package.json +19 -18
  22. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToComponent.d.ts +0 -5
package/build/main.mjs CHANGED
@@ -1184,6 +1184,7 @@ var getChildren = (node) => {
1184
1184
  case "input-multi-select":
1185
1185
  case "input-upload-multi":
1186
1186
  case "input-number":
1187
+ case "money-input":
1187
1188
  case "paragraph":
1188
1189
  case "progress":
1189
1190
  case "review":
@@ -1376,6 +1377,19 @@ var mapErrorsToValidationState = (errors) => {
1376
1377
  return void 0;
1377
1378
  };
1378
1379
 
1380
+ // src/revamp/renderers/mappers/utils/getValidationState.ts
1381
+ var getValidationState = (errors, validationAsyncState) => {
1382
+ if (validationAsyncState) {
1383
+ if (validationAsyncState == null ? void 0 : validationAsyncState.messages.error) {
1384
+ return { status: "invalid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.error };
1385
+ }
1386
+ if (validationAsyncState == null ? void 0 : validationAsyncState.messages.success) {
1387
+ return { status: "valid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.success };
1388
+ }
1389
+ }
1390
+ return mapErrorsToValidationState(errors);
1391
+ };
1392
+
1379
1393
  // src/revamp/renderers/mappers/utils/inputComponentToProps.ts
1380
1394
  var inputComponentToProps = (component, type) => {
1381
1395
  var _a;
@@ -1418,17 +1432,6 @@ var inputComponentToProps = (component, type) => {
1418
1432
  onFocus: onFocus.bind(component)
1419
1433
  }, mapMediaToLegacyProps(media));
1420
1434
  };
1421
- var getValidationState = (errors, validationAsyncState) => {
1422
- if (validationAsyncState) {
1423
- if (validationAsyncState == null ? void 0 : validationAsyncState.messages.error) {
1424
- return { status: "invalid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.error };
1425
- }
1426
- if (validationAsyncState == null ? void 0 : validationAsyncState.messages.success) {
1427
- return { status: "valid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.success };
1428
- }
1429
- }
1430
- return mapErrorsToValidationState(errors);
1431
- };
1432
1435
 
1433
1436
  // src/revamp/renderers/mappers/booleanInputComponentToProps.ts
1434
1437
  var booleanInputComponentToProps = (component, rendererMapperProps) => {
@@ -1668,7 +1671,18 @@ var mapItem = (item) => {
1668
1671
  var loadingIndicatorComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "size", "tags")), rendererMapperProps);
1669
1672
 
1670
1673
  // src/revamp/renderers/mappers/markdownComponentToProps.ts
1671
- var markdownComponentToProps = (control, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(control, "uid", "analyticsId", "type", "align", "margin", "content", "control", "tags")), rendererMapperProps);
1674
+ var markdownComponentToProps = (control, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(
1675
+ control,
1676
+ "uid",
1677
+ "analyticsId",
1678
+ "type",
1679
+ "align",
1680
+ "margin",
1681
+ "content",
1682
+ "control",
1683
+ "tags",
1684
+ "size"
1685
+ )), rendererMapperProps);
1672
1686
 
1673
1687
  // src/revamp/renderers/mappers/modalComponentToProps.ts
1674
1688
  var modalComponentToProps = (component, rendererMapperProps) => {
@@ -1707,6 +1721,48 @@ var modalLayoutComponentToProps = (component, rendererMapperProps) => {
1707
1721
  }, rendererMapperProps);
1708
1722
  };
1709
1723
 
1724
+ // src/revamp/renderers/mappers/moneyInputComponentToProps.ts
1725
+ var moneyInputComponentToProps = (component, rendererMapperProps) => {
1726
+ const { components, errors, validationAsyncState } = component;
1727
+ const amountComponent = components.amount;
1728
+ const currencyComponent = components.currency;
1729
+ const validationState = pickValidationState([
1730
+ getValidationState(amountComponent.errors, amountComponent.validationAsyncState),
1731
+ getValidationState(currencyComponent.errors, currencyComponent.validationAsyncState),
1732
+ getValidationState(errors, validationAsyncState)
1733
+ ]);
1734
+ const currencies = currencyComponent.options.map(
1735
+ ({ analyticsId, title, description, media, keywords, tags }, i) => ({
1736
+ currencyCode: currencyComponent.children[i].getLocalValue(),
1737
+ analyticsId,
1738
+ title,
1739
+ description,
1740
+ media,
1741
+ keywords,
1742
+ tags
1743
+ })
1744
+ );
1745
+ return __spreadValues(__spreadProps(__spreadValues({}, inputComponentToProps(component, "money-input")), {
1746
+ amountValue: amountComponent.getLocalValue(),
1747
+ selectedCurrencyIndex: currencyComponent.selectedIndex,
1748
+ onAmountChange: amountComponent.onChange.bind(amountComponent),
1749
+ onCurrencyChange: currencyComponent.onSelect.bind(currencyComponent),
1750
+ placeholder: amountComponent.placeholder,
1751
+ currencies,
1752
+ validationState
1753
+ }), rendererMapperProps);
1754
+ };
1755
+ var pickValidationState = (states) => {
1756
+ const definedStates = states.filter((state) => state !== void 0);
1757
+ if (definedStates.length === 0) {
1758
+ return void 0;
1759
+ }
1760
+ if (definedStates.some((state) => state.status === "invalid")) {
1761
+ return definedStates.find((state) => state.status === "invalid");
1762
+ }
1763
+ return definedStates[0];
1764
+ };
1765
+
1710
1766
  // src/revamp/renderers/mappers/multiSelectComponentToProps.ts
1711
1767
  var multiSelectInputComponentToProps = (component, rendererMapperProps) => {
1712
1768
  const { autoComplete, maxItems, minItems, options, selectedIndices, onSelect } = component;
@@ -1769,7 +1825,18 @@ var objectComponentToProps = (component, rendererMapperProps) => {
1769
1825
  };
1770
1826
 
1771
1827
  // src/revamp/renderers/mappers/paragraphComponentToProps.ts
1772
- var paragraphComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "align", "control", "margin", "tags", "text")), rendererMapperProps);
1828
+ var paragraphComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(
1829
+ component,
1830
+ "uid",
1831
+ "analyticsId",
1832
+ "type",
1833
+ "align",
1834
+ "control",
1835
+ "margin",
1836
+ "tags",
1837
+ "text",
1838
+ "size"
1839
+ )), rendererMapperProps);
1773
1840
 
1774
1841
  // src/revamp/renderers/mappers/persistAsyncComponentToProps.ts
1775
1842
  var persistAsyncComponentToProps = (component, rendererMapperProps) => {
@@ -2156,6 +2223,8 @@ var getComponentProps = (component, rendererMapperProps) => {
2156
2223
  return modalLayoutComponentToProps(component, rendererMapperProps);
2157
2224
  case "modal":
2158
2225
  return modalComponentToProps(component, rendererMapperProps);
2226
+ case "money-input":
2227
+ return moneyInputComponentToProps(component, rendererMapperProps);
2159
2228
  case "multi-select":
2160
2229
  return multiSelectInputComponentToProps(component, rendererMapperProps);
2161
2230
  case "multi-upload":
@@ -2883,7 +2952,8 @@ var infoLayoutToComponent = (uid, { analyticsId, align = "left", control, margin
2883
2952
  content,
2884
2953
  control,
2885
2954
  margin,
2886
- tags
2955
+ tags,
2956
+ size: "md"
2887
2957
  });
2888
2958
 
2889
2959
  // src/revamp/domain/components/InstructionsComponent.ts
@@ -2988,14 +3058,23 @@ var loadingIndicatorLayoutToComponent = (uid, { analyticsId, control, margin = "
2988
3058
  });
2989
3059
 
2990
3060
  // src/revamp/domain/mappers/layout/markdownLayoutToComponent.ts
2991
- var markdownLayoutToComponent = (uid, { analyticsId, align = "left", margin = "md", control, content, tags }) => createMarkdownComponent({
3061
+ var markdownLayoutToComponent = (uid, {
3062
+ analyticsId,
3063
+ align = "left",
3064
+ margin = "md",
3065
+ control,
3066
+ content,
3067
+ size = "md",
3068
+ tags
3069
+ }) => createMarkdownComponent({
2992
3070
  uid,
2993
3071
  analyticsId,
2994
3072
  align: mapLegacyAlign(align),
2995
3073
  control,
2996
3074
  content,
2997
3075
  margin,
2998
- tags
3076
+ tags,
3077
+ size
2999
3078
  });
3000
3079
 
3001
3080
  // src/revamp/domain/components/ModalLayoutComponent.ts
@@ -3034,14 +3113,15 @@ var createParagraphComponent = (paragraphProps) => __spreadValues({
3034
3113
  }, paragraphProps);
3035
3114
 
3036
3115
  // src/revamp/domain/mappers/layout/paragraphLayoutToComponent.ts
3037
- var paragraphLayoutToComponent = (uid, { analyticsId, align = "left", control, margin = "md", tags, text }) => createParagraphComponent({
3116
+ var paragraphLayoutToComponent = (uid, { analyticsId, align = "left", control, margin = "md", size = "md", tags, text }) => createParagraphComponent({
3038
3117
  uid,
3039
3118
  analyticsId,
3040
3119
  text,
3041
3120
  control,
3042
3121
  align: mapLegacyAlign(align),
3043
3122
  margin,
3044
- tags
3123
+ tags,
3124
+ size
3045
3125
  });
3046
3126
 
3047
3127
  // src/revamp/domain/components/ReviewComponent.ts
@@ -4014,6 +4094,22 @@ var getBelowMinimumCheck = ({ minimum }, messageFunctions) => (value) => {
4014
4094
  }
4015
4095
  return null;
4016
4096
  };
4097
+ var getAboveMaximumMoneyAmountCheck = ({ maximum }, messageFunctions) => (value) => {
4098
+ const numericValue = value != null ? Number.parseFloat(value) : null;
4099
+ const numericMax = maximum != null ? Number.parseFloat(maximum) : null;
4100
+ if (maximum != null && isNumber(numericMax) && isNumber(numericValue) && numericValue > numericMax) {
4101
+ return messageFunctions.maximum(maximum);
4102
+ }
4103
+ return null;
4104
+ };
4105
+ var getBelowMinimumMoneyAmountCheck = ({ minimum }, messageFunctions) => (value) => {
4106
+ const numericValue = value != null ? Number.parseFloat(value) : null;
4107
+ const numericMin = minimum != null ? Number.parseFloat(minimum) : null;
4108
+ if (minimum != null && isNumber(numericMin) && isNumber(numericValue) && numericValue < numericMin) {
4109
+ return messageFunctions.minimum(minimum);
4110
+ }
4111
+ return null;
4112
+ };
4017
4113
  var getAboveMaximumDateCheck = ({ maximum }, messageFunctions) => (value) => {
4018
4114
  if (isString(maximum) && isString(value) && value > maximum) {
4019
4115
  return messageFunctions.maximumDate(maximum);
@@ -5086,6 +5182,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
5086
5182
  } = schemaMapperProps;
5087
5183
  const initialModel = model != null ? model : null;
5088
5184
  const options = schema.items.oneOf.map((childSchema, index) => {
5185
+ var _a;
5089
5186
  const { title: title2 = "", description, image, icon, media, keywords = [], tags } = childSchema;
5090
5187
  return {
5091
5188
  title: title2,
@@ -5094,6 +5191,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
5094
5191
  keywords,
5095
5192
  tags,
5096
5193
  disabled: "disabled" in childSchema ? Boolean(childSchema.disabled) : false,
5194
+ analyticsId: (_a = childSchema.analyticsId) != null ? _a : childSchema.$id,
5097
5195
  component: mapSchemaToComponent(
5098
5196
  {
5099
5197
  uid: `${uid}.oneOf-${index}`,
@@ -5633,6 +5731,112 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5633
5731
  );
5634
5732
  };
5635
5733
 
5734
+ // src/revamp/domain/components/MoneyInputComponent.ts
5735
+ var createMoneyInputComponent = (moneyInputProps, updateComponent) => {
5736
+ const _a = moneyInputProps, {
5737
+ id,
5738
+ uid,
5739
+ schemaId,
5740
+ analyticsId,
5741
+ amountKey,
5742
+ amountComponent,
5743
+ currencyKey,
5744
+ currencyComponent,
5745
+ control,
5746
+ description,
5747
+ help,
5748
+ hidden,
5749
+ media,
5750
+ summariser,
5751
+ title,
5752
+ tags,
5753
+ extraValues,
5754
+ checks
5755
+ } = _a, rest = __objRest(_a, [
5756
+ "id",
5757
+ "uid",
5758
+ "schemaId",
5759
+ "analyticsId",
5760
+ "amountKey",
5761
+ "amountComponent",
5762
+ "currencyKey",
5763
+ "currencyComponent",
5764
+ "control",
5765
+ "description",
5766
+ "help",
5767
+ "hidden",
5768
+ "media",
5769
+ "summariser",
5770
+ "title",
5771
+ "tags",
5772
+ "extraValues",
5773
+ "checks"
5774
+ ]);
5775
+ const getValidationErrors = getLocalValueValidator(checks);
5776
+ const update = getInputUpdateFunction(updateComponent);
5777
+ const moneyComponent = __spreadValues({
5778
+ type: "money-input",
5779
+ kind: "input",
5780
+ id,
5781
+ uid,
5782
+ schemaId,
5783
+ analyticsId,
5784
+ autoComplete: "off",
5785
+ control,
5786
+ description,
5787
+ help,
5788
+ hidden,
5789
+ media,
5790
+ title,
5791
+ tags,
5792
+ value: {
5793
+ [amountKey]: amountComponent.getLocalValue(),
5794
+ [currencyKey]: currencyComponent.getLocalValue()
5795
+ },
5796
+ _update(updateFn) {
5797
+ update(this, updateFn);
5798
+ },
5799
+ components: {
5800
+ amount: amountComponent,
5801
+ currency: currencyComponent
5802
+ },
5803
+ async getSubmittableValue() {
5804
+ return __spreadValues({
5805
+ [amountKey]: await amountComponent.getSubmittableValue(),
5806
+ [currencyKey]: await currencyComponent.getSubmittableValue()
5807
+ }, extraValues);
5808
+ },
5809
+ getSubmittableValueSync() {
5810
+ return __spreadValues({
5811
+ [amountKey]: amountComponent.getSubmittableValueSync(),
5812
+ [currencyKey]: currencyComponent.getSubmittableValueSync()
5813
+ }, extraValues);
5814
+ },
5815
+ getLocalValue() {
5816
+ return __spreadValues({
5817
+ [amountKey]: amountComponent.getLocalValue(),
5818
+ [currencyKey]: currencyComponent.getLocalValue()
5819
+ }, extraValues);
5820
+ },
5821
+ getSummary() {
5822
+ return summariser(this.getLocalValue());
5823
+ },
5824
+ validate() {
5825
+ const errors = getValidationErrors(amountComponent.getLocalValue());
5826
+ this._update((draft) => {
5827
+ draft.errors = errors;
5828
+ });
5829
+ return amountComponent.validate() && currencyComponent.validate() && errors.length === 0;
5830
+ },
5831
+ onBlur() {
5832
+ },
5833
+ // noop
5834
+ onFocus() {
5835
+ }
5836
+ }, rest);
5837
+ return moneyComponent;
5838
+ };
5839
+
5636
5840
  // src/revamp/domain/components/ObjectComponent.ts
5637
5841
  var createObjectComponent = (objectProps) => {
5638
5842
  const {
@@ -5708,12 +5912,45 @@ var mergeChildrenValues = (displayOrder, getComponentValue) => displayOrder.redu
5708
5912
  return __spreadValues(__spreadValues({}, acc), componentValue === null ? {} : { [propName]: componentValue });
5709
5913
  }, {});
5710
5914
 
5711
- // src/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToComponent.ts
5712
- var objectSchemaToComponent = (schemaMapperProps, mapperProps) => {
5915
+ // src/revamp/domain/mappers/schema/objectSchemaToComponent/assertDisplayOrder.ts
5916
+ var assertDisplayOrder = (schema, logEvent) => {
5917
+ const { $id, displayOrder, properties } = schema;
5918
+ if (!displayOrder) {
5919
+ const message = `Object schema ${$id} has no displayOrder property.`;
5920
+ logEvent("error", message);
5921
+ throw new Error(message);
5922
+ }
5923
+ const propertyNames = Object.keys(properties);
5924
+ displayOrder.forEach((propName) => {
5925
+ if (!properties[propName]) {
5926
+ const message = `Object schema ${$id} has no property named "${propName}", but it is listed in the displayOrder array.`;
5927
+ logEvent("error", message);
5928
+ throw new Error(message);
5929
+ }
5930
+ });
5931
+ propertyNames.forEach((propName) => {
5932
+ if (!displayOrder.includes(propName)) {
5933
+ const message = `Object schema ${$id} has a "${propName}" property which is missing in the displayOrder array.`;
5934
+ logEvent("error", message);
5935
+ throw new Error(message);
5936
+ }
5937
+ });
5938
+ };
5939
+
5940
+ // src/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.ts
5941
+ var objectSchemaToObjectComponent = (schemaMapperProps, mapperProps) => {
5942
+ assertDisplayOrder(schemaMapperProps.schema, mapperProps.logEvent);
5943
+ const componentMap = createComponentMap(schemaMapperProps, mapperProps, "obj");
5944
+ return createObjectComponent(__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5945
+ displayOrder: schemaMapperProps.schema.displayOrder,
5946
+ componentMap
5947
+ }));
5948
+ };
5949
+ var createComponentMap = (schemaMapperProps, mapperProps, uidPrefix) => {
5713
5950
  const { uid, localValue, schema, model, validationErrors } = schemaMapperProps;
5714
5951
  const { $id, displayOrder, properties, required } = schema;
5715
- validateDisplayOrder($id, displayOrder, properties, mapperProps.logEvent);
5716
- const componentMap = displayOrder.reduce((acc, propName) => {
5952
+ const initialReducerValue = {};
5953
+ return displayOrder.reduce((acc, propName) => {
5717
5954
  var _a;
5718
5955
  const propSchema = properties[propName];
5719
5956
  if (propSchema === void 0) {
@@ -5722,7 +5959,7 @@ var objectSchemaToComponent = (schemaMapperProps, mapperProps) => {
5722
5959
  return __spreadProps(__spreadValues({}, acc), {
5723
5960
  [propName]: mapSchemaToComponent(
5724
5961
  {
5725
- uid: `${uid}.obj-${propName}`,
5962
+ uid: `${uid}.${uidPrefix}-${propName}`,
5726
5963
  schema: propSchema,
5727
5964
  model: isObjectModel(model) ? model[propName] : null,
5728
5965
  localValue: isObjectLocalValue(localValue) ? localValue[propName] : null,
@@ -5732,34 +5969,95 @@ var objectSchemaToComponent = (schemaMapperProps, mapperProps) => {
5732
5969
  mapperProps
5733
5970
  )
5734
5971
  });
5735
- }, {});
5736
- return createObjectComponent(__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5737
- componentMap,
5738
- displayOrder
5739
- }));
5972
+ }, initialReducerValue);
5740
5973
  };
5741
- var validateDisplayOrder = ($id, displayOrder, properties, logEvent) => {
5742
- if (!displayOrder) {
5743
- const message = `Object schema ${$id} has no displayOrder property.`;
5744
- logEvent("error", message);
5974
+
5975
+ // src/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.ts
5976
+ var isAmountSchema = (schema) => isStringSchema(schema) && !schema.hidden && schema.format !== "date" && schema.format !== "base64url" && schema.persistAsync === void 0;
5977
+ var isCurrencyConstSchema = (schema) => isConstSchema(schema);
5978
+ var isCurrencySelectSchema = (schema) => isOneOfSchema(schema) && schema.oneOf.length > 0 && schema.oneOf.every((option) => isCurrencyConstSchema(option));
5979
+ var objectSchemaToMoneyInputComponent = (schemaMapperProps, mapperProps) => {
5980
+ return createMoneyInputComponent(
5981
+ __spreadValues(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), createMoneyInputSubComponents(schemaMapperProps, mapperProps)),
5982
+ mapperProps.updateComponent
5983
+ );
5984
+ };
5985
+ var createMoneyInputSubComponents = (schemaMapperProps, mapperProps) => {
5986
+ const { schema: objectSchema } = schemaMapperProps;
5987
+ const amountKey = getAmountSchemaKey(objectSchema, mapperProps);
5988
+ const currencyKey = getCurrencySchemaKey(objectSchema, mapperProps);
5989
+ const currencySchema = objectSchema.properties[currencyKey];
5990
+ const customSchemaMapperProps = __spreadProps(__spreadValues({}, schemaMapperProps), {
5991
+ schema: isOneOfSchema(currencySchema) ? objectSchema : replaceKeyInObjectSchema(objectSchema, currencyKey, { oneOf: [currencySchema] })
5992
+ });
5993
+ const componentMap = createComponentMap(customSchemaMapperProps, mapperProps, "money");
5994
+ const amountComponent = componentMap[amountKey];
5995
+ assertAmountComponent(amountComponent, mapperProps.logEvent);
5996
+ const currencyComponent = componentMap[currencyKey];
5997
+ assertCurrencyComponent(currencyComponent, mapperProps.logEvent);
5998
+ const extraValues = getExtraValues(componentMap, [amountKey, currencyKey]);
5999
+ const checks = getMinMaxChecks(objectSchema, amountKey, mapperProps);
6000
+ return { amountKey, amountComponent, currencyKey, currencyComponent, extraValues, checks };
6001
+ };
6002
+ var getAmountSchemaKey = ({ displayOrder, properties }, mapperProps) => {
6003
+ var _a;
6004
+ const entry = displayOrder.map((key) => ({ key, schema: properties[key] })).find(({ schema }) => isAmountSchema(schema));
6005
+ if (!entry) {
6006
+ const message = `Object schema with format "money" is not properly configured. It must have one schema property of type "string" which is not hidden and has a valid format or no format at all.`;
6007
+ (_a = mapperProps.logEvent) == null ? void 0 : _a.call(mapperProps, "error", message);
5745
6008
  throw new Error(message);
5746
6009
  }
5747
- const propertyNames = Object.keys(properties);
5748
- displayOrder.forEach((propName) => {
5749
- if (!properties[propName]) {
5750
- const message = `Object schema ${$id} has no property named "${propName}", but it is listed in the displayOrder array.`;
5751
- logEvent("error", message);
5752
- throw new Error(message);
5753
- }
5754
- });
5755
- propertyNames.forEach((propName) => {
5756
- if (!displayOrder.includes(propName)) {
5757
- const message = `Object schema ${$id} has a "${propName}" property which is missing in the displayOrder array.`;
5758
- logEvent("error", message);
5759
- throw new Error(message);
5760
- }
6010
+ return entry.key;
6011
+ };
6012
+ var getCurrencySchemaKey = ({ displayOrder, properties }, mapperProps) => {
6013
+ var _a;
6014
+ const entry = displayOrder.map((key) => ({ key, schema: properties[key] })).find(({ schema }) => isCurrencyConstSchema(schema) || isCurrencySelectSchema(schema));
6015
+ if (!entry) {
6016
+ const message = `Object schema with format "money" is not properly configured. It must have one schema property representing the currency code. This property must be a const schema or a oneOf schema with at least one const schema options.`;
6017
+ (_a = mapperProps.logEvent) == null ? void 0 : _a.call(mapperProps, "error", message);
6018
+ throw new Error(message);
6019
+ }
6020
+ return entry.key;
6021
+ };
6022
+ var replaceKeyInObjectSchema = (objSchema, key, newSchema) => {
6023
+ return __spreadProps(__spreadValues({}, objSchema), {
6024
+ properties: __spreadProps(__spreadValues({}, objSchema.properties), {
6025
+ [key]: newSchema
6026
+ })
5761
6027
  });
5762
6028
  };
6029
+ var getMinMaxChecks = (objectSchema, amountKey, mapperProps) => {
6030
+ const amountSchema = objectSchema.properties[amountKey];
6031
+ const errorMessageFunctions = mapperProps.getErrorMessageFunctions(
6032
+ amountSchema.validationMessages
6033
+ );
6034
+ const checks = [
6035
+ getAboveMaximumMoneyAmountCheck(amountSchema, errorMessageFunctions),
6036
+ getBelowMinimumMoneyAmountCheck(amountSchema, errorMessageFunctions)
6037
+ ];
6038
+ return checks;
6039
+ };
6040
+ function getExtraValues(componentMap, excludeKeys) {
6041
+ return Object.fromEntries(
6042
+ Object.entries(componentMap).filter(
6043
+ ([key, component]) => !excludeKeys.includes(key) && (component.type === "const" || component.hidden)
6044
+ ).map(([key, component]) => [key, component.getSubmittableValueSync()])
6045
+ );
6046
+ }
6047
+ function assertAmountComponent(component, logEvent) {
6048
+ if (component.type !== "text") {
6049
+ const message = "A string schema was selected for amount but it was not successfully mapped into a TextInputComponent.";
6050
+ logEvent == null ? void 0 : logEvent("error", message);
6051
+ throw new Error(message);
6052
+ }
6053
+ }
6054
+ function assertCurrencyComponent(component, logEvent) {
6055
+ if (component.type !== "select") {
6056
+ const message = "A schema was selected for currency but it was not successfully mapped into a SelectInputComponent.";
6057
+ logEvent == null ? void 0 : logEvent("error", message);
6058
+ throw new Error(message);
6059
+ }
6060
+ }
5763
6061
 
5764
6062
  // src/revamp/domain/components/utils/isPartialModelMatch.ts
5765
6063
  var isPartialModelMatch = (localModel, incomingModel) => {
@@ -5885,6 +6183,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
5885
6183
  );
5886
6184
  }
5887
6185
  const options = schema.oneOf.map((childSchema, index) => {
6186
+ var _a2;
5888
6187
  const { title = "", description, image, icon, media, keywords = [], tags } = childSchema;
5889
6188
  return {
5890
6189
  title,
@@ -5893,6 +6192,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
5893
6192
  keywords,
5894
6193
  tags,
5895
6194
  disabled: "disabled" in childSchema ? Boolean(childSchema.disabled) : false,
6195
+ analyticsId: (_a2 = childSchema.analyticsId) != null ? _a2 : childSchema.$id,
5896
6196
  component: mapSchemaToComponent(
5897
6197
  {
5898
6198
  uid: `${uid}.oneOf-${index}`,
@@ -5928,6 +6228,143 @@ var supressSchemaTitleAndDescription = (schema) => {
5928
6228
  return headlessSchema;
5929
6229
  };
5930
6230
 
6231
+ // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
6232
+ var isExactLocalValueMatch = (valueA, valueB) => {
6233
+ if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
6234
+ return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
6235
+ }
6236
+ if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
6237
+ const keysA = Object.keys(valueA);
6238
+ const keysB = Object.keys(valueB);
6239
+ return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
6240
+ }
6241
+ return valueA === valueB;
6242
+ };
6243
+
6244
+ // src/revamp/domain/components/PersistAsyncComponent.ts
6245
+ var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
6246
+ const { uid, analyticsId, schemaId, component, hidden, model, localValue, tags } = props;
6247
+ const update = getInputUpdateFunction(updateComponent);
6248
+ const paComponent = {
6249
+ type: "persist-async",
6250
+ kind: "input",
6251
+ uid,
6252
+ analyticsId,
6253
+ schemaId,
6254
+ component,
6255
+ hidden,
6256
+ lastSubmitted: model != null ? localValue != null ? localValue : null : null,
6257
+ lastResponse: model != null ? model : null,
6258
+ submission: Promise.resolve(model != null ? model : null),
6259
+ abortController: new AbortController(),
6260
+ errors: [],
6261
+ tags,
6262
+ _update(updateFn) {
6263
+ update(this, updateFn);
6264
+ },
6265
+ validate() {
6266
+ return this.component.validate();
6267
+ },
6268
+ getLocalValue() {
6269
+ return this.component.getLocalValue();
6270
+ },
6271
+ async getSubmittableValue() {
6272
+ return this.persist();
6273
+ },
6274
+ getSubmittableValueSync() {
6275
+ return this.lastResponse;
6276
+ },
6277
+ getSummary() {
6278
+ return this.component.getSummary();
6279
+ },
6280
+ async persist() {
6281
+ const childLocalValue = this.component.getLocalValue();
6282
+ if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
6283
+ return this.submission;
6284
+ }
6285
+ const newAbortController = abortAndResetController(this.abortController);
6286
+ if (childLocalValue == null || childLocalValue === "") {
6287
+ const resolvedNull = Promise.resolve(null);
6288
+ this._update((draft) => {
6289
+ draft.abortController = newAbortController;
6290
+ draft.lastResponse = null;
6291
+ draft.lastSubmitted = childLocalValue;
6292
+ draft.submission = resolvedNull;
6293
+ draft.errors = [];
6294
+ });
6295
+ void (schemaOnChange == null ? void 0 : schemaOnChange());
6296
+ return resolvedNull;
6297
+ }
6298
+ const { signal } = newAbortController;
6299
+ const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
6300
+ this._update((draft) => {
6301
+ draft.lastResponse = token;
6302
+ draft.errors = [];
6303
+ });
6304
+ void (schemaOnChange == null ? void 0 : schemaOnChange());
6305
+ return token;
6306
+ }).catch((error) => {
6307
+ if (error instanceof DOMException && error.name === "AbortError") {
6308
+ return null;
6309
+ }
6310
+ this._update((draft) => {
6311
+ draft.lastResponse = null;
6312
+ draft.lastSubmitted = null;
6313
+ draft.submission = Promise.resolve(null);
6314
+ if (this.component.type !== "upload") {
6315
+ draft.errors = error instanceof Error ? [error.message] : [];
6316
+ }
6317
+ });
6318
+ throw error;
6319
+ });
6320
+ this._update((draft) => {
6321
+ draft.abortController = newAbortController;
6322
+ draft.lastSubmitted = childLocalValue;
6323
+ draft.lastResponse = null;
6324
+ draft.submission = newSubmission;
6325
+ draft.errors = [];
6326
+ });
6327
+ return newSubmission;
6328
+ }
6329
+ };
6330
+ return paComponent;
6331
+ };
6332
+
6333
+ // src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
6334
+ var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
6335
+ var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
6336
+ const { uid, schema, model, localValue } = schemaMapperProps;
6337
+ const { persistAsync, tags } = schema;
6338
+ const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
6339
+ const onPersistAsync = async () => paComponent.persist().then(() => {
6340
+ });
6341
+ const childComponent = mapSchemaToComponent(
6342
+ __spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
6343
+ mapperProps
6344
+ );
6345
+ if (!isSupported(childComponent.type)) {
6346
+ return childComponent;
6347
+ }
6348
+ const paComponent = createPersistAsyncComponent(
6349
+ {
6350
+ uid,
6351
+ // This should be `schema.hidden ?? false`
6352
+ // but some steps are setting PA schemas as hidden for no good reason
6353
+ // so we default to false here to avoid hiding the the children of the PA component
6354
+ hidden: false,
6355
+ component: childComponent,
6356
+ schemaId: schema.$id,
6357
+ model,
6358
+ localValue,
6359
+ tags
6360
+ },
6361
+ performPersistAsync,
6362
+ getSchemaOnChange(schema, mapperProps.onBehavior),
6363
+ mapperProps.updateComponent
6364
+ );
6365
+ return paComponent;
6366
+ };
6367
+
5931
6368
  // src/revamp/domain/components/DateInputComponent.ts
5932
6369
  var createDateInputComponent = (textInputProps, updateComponent) => {
5933
6370
  const _a = textInputProps, {
@@ -6267,143 +6704,6 @@ var isStringSchemaWithBase64 = (schema) => {
6267
6704
  return schema.format === "base64url" && !("persistAsync" in schema);
6268
6705
  };
6269
6706
 
6270
- // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
6271
- var isExactLocalValueMatch = (valueA, valueB) => {
6272
- if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
6273
- return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
6274
- }
6275
- if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
6276
- const keysA = Object.keys(valueA);
6277
- const keysB = Object.keys(valueB);
6278
- return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
6279
- }
6280
- return valueA === valueB;
6281
- };
6282
-
6283
- // src/revamp/domain/components/PersistAsyncComponent.ts
6284
- var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
6285
- const { uid, analyticsId, schemaId, component, hidden, model, localValue, tags } = props;
6286
- const update = getInputUpdateFunction(updateComponent);
6287
- const paComponent = {
6288
- type: "persist-async",
6289
- kind: "input",
6290
- uid,
6291
- analyticsId,
6292
- schemaId,
6293
- component,
6294
- hidden,
6295
- lastSubmitted: model != null ? localValue != null ? localValue : null : null,
6296
- lastResponse: model != null ? model : null,
6297
- submission: Promise.resolve(model != null ? model : null),
6298
- abortController: new AbortController(),
6299
- errors: [],
6300
- tags,
6301
- _update(updateFn) {
6302
- update(this, updateFn);
6303
- },
6304
- validate() {
6305
- return this.component.validate();
6306
- },
6307
- getLocalValue() {
6308
- return this.component.getLocalValue();
6309
- },
6310
- async getSubmittableValue() {
6311
- return this.persist();
6312
- },
6313
- getSubmittableValueSync() {
6314
- return this.lastResponse;
6315
- },
6316
- getSummary() {
6317
- return this.component.getSummary();
6318
- },
6319
- async persist() {
6320
- const childLocalValue = this.component.getLocalValue();
6321
- if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
6322
- return this.submission;
6323
- }
6324
- const newAbortController = abortAndResetController(this.abortController);
6325
- if (childLocalValue == null || childLocalValue === "") {
6326
- const resolvedNull = Promise.resolve(null);
6327
- this._update((draft) => {
6328
- draft.abortController = newAbortController;
6329
- draft.lastResponse = null;
6330
- draft.lastSubmitted = childLocalValue;
6331
- draft.submission = resolvedNull;
6332
- draft.errors = [];
6333
- });
6334
- void (schemaOnChange == null ? void 0 : schemaOnChange());
6335
- return resolvedNull;
6336
- }
6337
- const { signal } = newAbortController;
6338
- const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
6339
- this._update((draft) => {
6340
- draft.lastResponse = token;
6341
- draft.errors = [];
6342
- });
6343
- void (schemaOnChange == null ? void 0 : schemaOnChange());
6344
- return token;
6345
- }).catch((error) => {
6346
- if (error instanceof DOMException && error.name === "AbortError") {
6347
- return null;
6348
- }
6349
- this._update((draft) => {
6350
- draft.lastResponse = null;
6351
- draft.lastSubmitted = null;
6352
- draft.submission = Promise.resolve(null);
6353
- if (this.component.type !== "upload") {
6354
- draft.errors = error instanceof Error ? [error.message] : [];
6355
- }
6356
- });
6357
- throw error;
6358
- });
6359
- this._update((draft) => {
6360
- draft.abortController = newAbortController;
6361
- draft.lastSubmitted = childLocalValue;
6362
- draft.lastResponse = null;
6363
- draft.submission = newSubmission;
6364
- draft.errors = [];
6365
- });
6366
- return newSubmission;
6367
- }
6368
- };
6369
- return paComponent;
6370
- };
6371
-
6372
- // src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
6373
- var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
6374
- var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
6375
- const { uid, schema, model, localValue } = schemaMapperProps;
6376
- const { persistAsync, tags } = schema;
6377
- const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
6378
- const onPersistAsync = async () => paComponent.persist().then(() => {
6379
- });
6380
- const childComponent = mapSchemaToComponent(
6381
- __spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
6382
- mapperProps
6383
- );
6384
- if (!isSupported(childComponent.type)) {
6385
- return childComponent;
6386
- }
6387
- const paComponent = createPersistAsyncComponent(
6388
- {
6389
- uid,
6390
- // This should be `schema.hidden ?? false`
6391
- // but some steps are setting PA schemas as hidden for no good reason
6392
- // so we default to false here to avoid hiding the the children of the PA component
6393
- hidden: false,
6394
- component: childComponent,
6395
- schemaId: schema.$id,
6396
- model,
6397
- localValue,
6398
- tags
6399
- },
6400
- performPersistAsync,
6401
- getSchemaOnChange(schema, mapperProps.onBehavior),
6402
- mapperProps.updateComponent
6403
- );
6404
- return paComponent;
6405
- };
6406
-
6407
6707
  // src/revamp/domain/mappers/mapSchemaToComponent.ts
6408
6708
  var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
6409
6709
  const { uid, schema } = schemaMapperProps;
@@ -6423,7 +6723,10 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
6423
6723
  return booleanSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6424
6724
  }
6425
6725
  if (isObjectSchema(schema)) {
6426
- return objectSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6726
+ if (schema.format === "money") {
6727
+ return objectSchemaToMoneyInputComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6728
+ }
6729
+ return objectSchemaToObjectComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6427
6730
  }
6428
6731
  if (isIntegerSchema(schema)) {
6429
6732
  return integerSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);