@wise/dynamic-flow-client 4.19.4 → 4.20.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.
Files changed (21) hide show
  1. package/build/main.js +487 -184
  2. package/build/main.mjs +487 -184
  3. package/build/types/revamp/domain/components/MarkdownComponent.d.ts +3 -1
  4. package/build/types/revamp/domain/components/MoneyInputComponent.d.ts +22 -0
  5. package/build/types/revamp/domain/components/ParagraphComponent.d.ts +3 -1
  6. package/build/types/revamp/domain/components/SelectInputComponent.d.ts +1 -0
  7. package/build/types/revamp/domain/features/validation/value-checks.d.ts +2 -0
  8. package/build/types/revamp/domain/mappers/layout/markdownLayoutToComponent.d.ts +1 -1
  9. package/build/types/revamp/domain/mappers/layout/paragraphLayoutToComponent.d.ts +1 -1
  10. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/assertDisplayOrder.d.ts +3 -0
  11. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.d.ts +5 -0
  12. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.d.ts +9 -0
  13. package/build/types/revamp/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.d.ts +36 -0
  14. package/build/types/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.d.ts +36 -0
  15. package/build/types/revamp/domain/mappers/types.d.ts +2 -2
  16. package/build/types/revamp/domain/types.d.ts +2 -1
  17. package/build/types/revamp/renderers/mappers/moneyInputComponentToProps.d.ts +4 -0
  18. package/build/types/revamp/renderers/mappers/utils/getValidationState.d.ts +3 -0
  19. package/build/types/revamp/renderers/mappers/utils/inputComponentToProps.d.ts +2 -3
  20. package/package.json +15 -15
  21. package/build/types/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToComponent.d.ts +0 -5
package/build/main.js CHANGED
@@ -1227,6 +1227,7 @@ var getChildren = (node) => {
1227
1227
  case "input-multi-select":
1228
1228
  case "input-upload-multi":
1229
1229
  case "input-number":
1230
+ case "money-input":
1230
1231
  case "paragraph":
1231
1232
  case "progress":
1232
1233
  case "review":
@@ -1419,6 +1420,19 @@ var mapErrorsToValidationState = (errors) => {
1419
1420
  return void 0;
1420
1421
  };
1421
1422
 
1423
+ // src/revamp/renderers/mappers/utils/getValidationState.ts
1424
+ var getValidationState = (errors, validationAsyncState) => {
1425
+ if (validationAsyncState) {
1426
+ if (validationAsyncState == null ? void 0 : validationAsyncState.messages.error) {
1427
+ return { status: "invalid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.error };
1428
+ }
1429
+ if (validationAsyncState == null ? void 0 : validationAsyncState.messages.success) {
1430
+ return { status: "valid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.success };
1431
+ }
1432
+ }
1433
+ return mapErrorsToValidationState(errors);
1434
+ };
1435
+
1422
1436
  // src/revamp/renderers/mappers/utils/inputComponentToProps.ts
1423
1437
  var inputComponentToProps = (component, type) => {
1424
1438
  var _a;
@@ -1461,17 +1475,6 @@ var inputComponentToProps = (component, type) => {
1461
1475
  onFocus: onFocus.bind(component)
1462
1476
  }, mapMediaToLegacyProps(media));
1463
1477
  };
1464
- var getValidationState = (errors, validationAsyncState) => {
1465
- if (validationAsyncState) {
1466
- if (validationAsyncState == null ? void 0 : validationAsyncState.messages.error) {
1467
- return { status: "invalid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.error };
1468
- }
1469
- if (validationAsyncState == null ? void 0 : validationAsyncState.messages.success) {
1470
- return { status: "valid", message: validationAsyncState == null ? void 0 : validationAsyncState.messages.success };
1471
- }
1472
- }
1473
- return mapErrorsToValidationState(errors);
1474
- };
1475
1478
 
1476
1479
  // src/revamp/renderers/mappers/booleanInputComponentToProps.ts
1477
1480
  var booleanInputComponentToProps = (component, rendererMapperProps) => {
@@ -1711,7 +1714,18 @@ var mapItem = (item) => {
1711
1714
  var loadingIndicatorComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "size", "tags")), rendererMapperProps);
1712
1715
 
1713
1716
  // src/revamp/renderers/mappers/markdownComponentToProps.ts
1714
- var markdownComponentToProps = (control, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(control, "uid", "analyticsId", "type", "align", "margin", "content", "control", "tags")), rendererMapperProps);
1717
+ var markdownComponentToProps = (control, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(
1718
+ control,
1719
+ "uid",
1720
+ "analyticsId",
1721
+ "type",
1722
+ "align",
1723
+ "margin",
1724
+ "content",
1725
+ "control",
1726
+ "tags",
1727
+ "size"
1728
+ )), rendererMapperProps);
1715
1729
 
1716
1730
  // src/revamp/renderers/mappers/modalComponentToProps.ts
1717
1731
  var modalComponentToProps = (component, rendererMapperProps) => {
@@ -1750,6 +1764,48 @@ var modalLayoutComponentToProps = (component, rendererMapperProps) => {
1750
1764
  }, rendererMapperProps);
1751
1765
  };
1752
1766
 
1767
+ // src/revamp/renderers/mappers/moneyInputComponentToProps.ts
1768
+ var moneyInputComponentToProps = (component, rendererMapperProps) => {
1769
+ const { components, errors, validationAsyncState } = component;
1770
+ const amountComponent = components.amount;
1771
+ const currencyComponent = components.currency;
1772
+ const validationState = pickValidationState([
1773
+ getValidationState(amountComponent.errors, amountComponent.validationAsyncState),
1774
+ getValidationState(currencyComponent.errors, currencyComponent.validationAsyncState),
1775
+ getValidationState(errors, validationAsyncState)
1776
+ ]);
1777
+ const currencies = currencyComponent.options.map(
1778
+ ({ analyticsId, title, description, media, keywords, tags }, i) => ({
1779
+ currencyCode: currencyComponent.children[i].getLocalValue(),
1780
+ analyticsId,
1781
+ title,
1782
+ description,
1783
+ media,
1784
+ keywords,
1785
+ tags
1786
+ })
1787
+ );
1788
+ return __spreadValues(__spreadProps(__spreadValues({}, inputComponentToProps(component, "money-input")), {
1789
+ amountValue: amountComponent.getLocalValue(),
1790
+ selectedCurrencyIndex: currencyComponent.selectedIndex,
1791
+ onAmountChange: amountComponent.onChange.bind(amountComponent),
1792
+ onCurrencyChange: currencyComponent.onSelect.bind(currencyComponent),
1793
+ placeholder: amountComponent.placeholder,
1794
+ currencies,
1795
+ validationState
1796
+ }), rendererMapperProps);
1797
+ };
1798
+ var pickValidationState = (states) => {
1799
+ const definedStates = states.filter((state) => state !== void 0);
1800
+ if (definedStates.length === 0) {
1801
+ return void 0;
1802
+ }
1803
+ if (definedStates.some((state) => state.status === "invalid")) {
1804
+ return definedStates.find((state) => state.status === "invalid");
1805
+ }
1806
+ return definedStates[0];
1807
+ };
1808
+
1753
1809
  // src/revamp/renderers/mappers/multiSelectComponentToProps.ts
1754
1810
  var multiSelectInputComponentToProps = (component, rendererMapperProps) => {
1755
1811
  const { autoComplete, maxItems, minItems, options, selectedIndices, onSelect } = component;
@@ -1812,7 +1868,18 @@ var objectComponentToProps = (component, rendererMapperProps) => {
1812
1868
  };
1813
1869
 
1814
1870
  // src/revamp/renderers/mappers/paragraphComponentToProps.ts
1815
- var paragraphComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "align", "control", "margin", "tags", "text")), rendererMapperProps);
1871
+ var paragraphComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(
1872
+ component,
1873
+ "uid",
1874
+ "analyticsId",
1875
+ "type",
1876
+ "align",
1877
+ "control",
1878
+ "margin",
1879
+ "tags",
1880
+ "text",
1881
+ "size"
1882
+ )), rendererMapperProps);
1816
1883
 
1817
1884
  // src/revamp/renderers/mappers/persistAsyncComponentToProps.ts
1818
1885
  var persistAsyncComponentToProps = (component, rendererMapperProps) => {
@@ -2199,6 +2266,8 @@ var getComponentProps = (component, rendererMapperProps) => {
2199
2266
  return modalLayoutComponentToProps(component, rendererMapperProps);
2200
2267
  case "modal":
2201
2268
  return modalComponentToProps(component, rendererMapperProps);
2269
+ case "money-input":
2270
+ return moneyInputComponentToProps(component, rendererMapperProps);
2202
2271
  case "multi-select":
2203
2272
  return multiSelectInputComponentToProps(component, rendererMapperProps);
2204
2273
  case "multi-upload":
@@ -2926,7 +2995,8 @@ var infoLayoutToComponent = (uid, { analyticsId, align = "left", control, margin
2926
2995
  content,
2927
2996
  control,
2928
2997
  margin,
2929
- tags
2998
+ tags,
2999
+ size: "md"
2930
3000
  });
2931
3001
 
2932
3002
  // src/revamp/domain/components/InstructionsComponent.ts
@@ -3031,14 +3101,23 @@ var loadingIndicatorLayoutToComponent = (uid, { analyticsId, control, margin = "
3031
3101
  });
3032
3102
 
3033
3103
  // src/revamp/domain/mappers/layout/markdownLayoutToComponent.ts
3034
- var markdownLayoutToComponent = (uid, { analyticsId, align = "left", margin = "md", control, content, tags }) => createMarkdownComponent({
3104
+ var markdownLayoutToComponent = (uid, {
3105
+ analyticsId,
3106
+ align = "left",
3107
+ margin = "md",
3108
+ control,
3109
+ content,
3110
+ size = "md",
3111
+ tags
3112
+ }) => createMarkdownComponent({
3035
3113
  uid,
3036
3114
  analyticsId,
3037
3115
  align: mapLegacyAlign(align),
3038
3116
  control,
3039
3117
  content,
3040
3118
  margin,
3041
- tags
3119
+ tags,
3120
+ size
3042
3121
  });
3043
3122
 
3044
3123
  // src/revamp/domain/components/ModalLayoutComponent.ts
@@ -3077,14 +3156,15 @@ var createParagraphComponent = (paragraphProps) => __spreadValues({
3077
3156
  }, paragraphProps);
3078
3157
 
3079
3158
  // src/revamp/domain/mappers/layout/paragraphLayoutToComponent.ts
3080
- var paragraphLayoutToComponent = (uid, { analyticsId, align = "left", control, margin = "md", tags, text }) => createParagraphComponent({
3159
+ var paragraphLayoutToComponent = (uid, { analyticsId, align = "left", control, margin = "md", size = "md", tags, text }) => createParagraphComponent({
3081
3160
  uid,
3082
3161
  analyticsId,
3083
3162
  text,
3084
3163
  control,
3085
3164
  align: mapLegacyAlign(align),
3086
3165
  margin,
3087
- tags
3166
+ tags,
3167
+ size
3088
3168
  });
3089
3169
 
3090
3170
  // src/revamp/domain/components/ReviewComponent.ts
@@ -4057,6 +4137,22 @@ var getBelowMinimumCheck = ({ minimum }, messageFunctions) => (value) => {
4057
4137
  }
4058
4138
  return null;
4059
4139
  };
4140
+ var getAboveMaximumMoneyAmountCheck = ({ maximum }, messageFunctions) => (value) => {
4141
+ const numericValue = value != null ? Number.parseFloat(value) : null;
4142
+ const numericMax = maximum != null ? Number.parseFloat(maximum) : null;
4143
+ if (maximum != null && isNumber(numericMax) && isNumber(numericValue) && numericValue > numericMax) {
4144
+ return messageFunctions.maximum(maximum);
4145
+ }
4146
+ return null;
4147
+ };
4148
+ var getBelowMinimumMoneyAmountCheck = ({ minimum }, messageFunctions) => (value) => {
4149
+ const numericValue = value != null ? Number.parseFloat(value) : null;
4150
+ const numericMin = minimum != null ? Number.parseFloat(minimum) : null;
4151
+ if (minimum != null && isNumber(numericMin) && isNumber(numericValue) && numericValue < numericMin) {
4152
+ return messageFunctions.minimum(minimum);
4153
+ }
4154
+ return null;
4155
+ };
4060
4156
  var getAboveMaximumDateCheck = ({ maximum }, messageFunctions) => (value) => {
4061
4157
  if (isString(maximum) && isString(value) && value > maximum) {
4062
4158
  return messageFunctions.maximumDate(maximum);
@@ -5129,6 +5225,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
5129
5225
  } = schemaMapperProps;
5130
5226
  const initialModel = model != null ? model : null;
5131
5227
  const options = schema.items.oneOf.map((childSchema, index) => {
5228
+ var _a;
5132
5229
  const { title: title2 = "", description, image, icon, media, keywords = [], tags } = childSchema;
5133
5230
  return {
5134
5231
  title: title2,
@@ -5137,6 +5234,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
5137
5234
  keywords,
5138
5235
  tags,
5139
5236
  disabled: "disabled" in childSchema ? Boolean(childSchema.disabled) : false,
5237
+ analyticsId: (_a = childSchema.analyticsId) != null ? _a : childSchema.$id,
5140
5238
  component: mapSchemaToComponent(
5141
5239
  {
5142
5240
  uid: `${uid}.oneOf-${index}`,
@@ -5676,6 +5774,112 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
5676
5774
  );
5677
5775
  };
5678
5776
 
5777
+ // src/revamp/domain/components/MoneyInputComponent.ts
5778
+ var createMoneyInputComponent = (moneyInputProps, updateComponent) => {
5779
+ const _a = moneyInputProps, {
5780
+ id,
5781
+ uid,
5782
+ schemaId,
5783
+ analyticsId,
5784
+ amountKey,
5785
+ amountComponent,
5786
+ currencyKey,
5787
+ currencyComponent,
5788
+ control,
5789
+ description,
5790
+ help,
5791
+ hidden,
5792
+ media,
5793
+ summariser,
5794
+ title,
5795
+ tags,
5796
+ extraValues,
5797
+ checks
5798
+ } = _a, rest = __objRest(_a, [
5799
+ "id",
5800
+ "uid",
5801
+ "schemaId",
5802
+ "analyticsId",
5803
+ "amountKey",
5804
+ "amountComponent",
5805
+ "currencyKey",
5806
+ "currencyComponent",
5807
+ "control",
5808
+ "description",
5809
+ "help",
5810
+ "hidden",
5811
+ "media",
5812
+ "summariser",
5813
+ "title",
5814
+ "tags",
5815
+ "extraValues",
5816
+ "checks"
5817
+ ]);
5818
+ const getValidationErrors = getLocalValueValidator(checks);
5819
+ const update = getInputUpdateFunction(updateComponent);
5820
+ const moneyComponent = __spreadValues({
5821
+ type: "money-input",
5822
+ kind: "input",
5823
+ id,
5824
+ uid,
5825
+ schemaId,
5826
+ analyticsId,
5827
+ autoComplete: "off",
5828
+ control,
5829
+ description,
5830
+ help,
5831
+ hidden,
5832
+ media,
5833
+ title,
5834
+ tags,
5835
+ value: {
5836
+ [amountKey]: amountComponent.getLocalValue(),
5837
+ [currencyKey]: currencyComponent.getLocalValue()
5838
+ },
5839
+ _update(updateFn) {
5840
+ update(this, updateFn);
5841
+ },
5842
+ components: {
5843
+ amount: amountComponent,
5844
+ currency: currencyComponent
5845
+ },
5846
+ async getSubmittableValue() {
5847
+ return __spreadValues({
5848
+ [amountKey]: await amountComponent.getSubmittableValue(),
5849
+ [currencyKey]: await currencyComponent.getSubmittableValue()
5850
+ }, extraValues);
5851
+ },
5852
+ getSubmittableValueSync() {
5853
+ return __spreadValues({
5854
+ [amountKey]: amountComponent.getSubmittableValueSync(),
5855
+ [currencyKey]: currencyComponent.getSubmittableValueSync()
5856
+ }, extraValues);
5857
+ },
5858
+ getLocalValue() {
5859
+ return __spreadValues({
5860
+ [amountKey]: amountComponent.getLocalValue(),
5861
+ [currencyKey]: currencyComponent.getLocalValue()
5862
+ }, extraValues);
5863
+ },
5864
+ getSummary() {
5865
+ return summariser(this.getLocalValue());
5866
+ },
5867
+ validate() {
5868
+ const errors = getValidationErrors(amountComponent.getLocalValue());
5869
+ this._update((draft) => {
5870
+ draft.errors = errors;
5871
+ });
5872
+ return amountComponent.validate() && currencyComponent.validate() && errors.length === 0;
5873
+ },
5874
+ onBlur() {
5875
+ },
5876
+ // noop
5877
+ onFocus() {
5878
+ }
5879
+ }, rest);
5880
+ return moneyComponent;
5881
+ };
5882
+
5679
5883
  // src/revamp/domain/components/ObjectComponent.ts
5680
5884
  var createObjectComponent = (objectProps) => {
5681
5885
  const {
@@ -5751,12 +5955,45 @@ var mergeChildrenValues = (displayOrder, getComponentValue) => displayOrder.redu
5751
5955
  return __spreadValues(__spreadValues({}, acc), componentValue === null ? {} : { [propName]: componentValue });
5752
5956
  }, {});
5753
5957
 
5754
- // src/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToComponent.ts
5755
- var objectSchemaToComponent = (schemaMapperProps, mapperProps) => {
5958
+ // src/revamp/domain/mappers/schema/objectSchemaToComponent/assertDisplayOrder.ts
5959
+ var assertDisplayOrder = (schema, logEvent) => {
5960
+ const { $id, displayOrder, properties } = schema;
5961
+ if (!displayOrder) {
5962
+ const message = `Object schema ${$id} has no displayOrder property.`;
5963
+ logEvent("error", message);
5964
+ throw new Error(message);
5965
+ }
5966
+ const propertyNames = Object.keys(properties);
5967
+ displayOrder.forEach((propName) => {
5968
+ if (!properties[propName]) {
5969
+ const message = `Object schema ${$id} has no property named "${propName}", but it is listed in the displayOrder array.`;
5970
+ logEvent("error", message);
5971
+ throw new Error(message);
5972
+ }
5973
+ });
5974
+ propertyNames.forEach((propName) => {
5975
+ if (!displayOrder.includes(propName)) {
5976
+ const message = `Object schema ${$id} has a "${propName}" property which is missing in the displayOrder array.`;
5977
+ logEvent("error", message);
5978
+ throw new Error(message);
5979
+ }
5980
+ });
5981
+ };
5982
+
5983
+ // src/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToObjectComponent.ts
5984
+ var objectSchemaToObjectComponent = (schemaMapperProps, mapperProps) => {
5985
+ assertDisplayOrder(schemaMapperProps.schema, mapperProps.logEvent);
5986
+ const componentMap = createComponentMap(schemaMapperProps, mapperProps, "obj");
5987
+ return createObjectComponent(__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5988
+ displayOrder: schemaMapperProps.schema.displayOrder,
5989
+ componentMap
5990
+ }));
5991
+ };
5992
+ var createComponentMap = (schemaMapperProps, mapperProps, uidPrefix) => {
5756
5993
  const { uid, localValue, schema, model, validationErrors } = schemaMapperProps;
5757
5994
  const { $id, displayOrder, properties, required } = schema;
5758
- validateDisplayOrder($id, displayOrder, properties, mapperProps.logEvent);
5759
- const componentMap = displayOrder.reduce((acc, propName) => {
5995
+ const initialReducerValue = {};
5996
+ return displayOrder.reduce((acc, propName) => {
5760
5997
  var _a;
5761
5998
  const propSchema = properties[propName];
5762
5999
  if (propSchema === void 0) {
@@ -5765,7 +6002,7 @@ var objectSchemaToComponent = (schemaMapperProps, mapperProps) => {
5765
6002
  return __spreadProps(__spreadValues({}, acc), {
5766
6003
  [propName]: mapSchemaToComponent(
5767
6004
  {
5768
- uid: `${uid}.obj-${propName}`,
6005
+ uid: `${uid}.${uidPrefix}-${propName}`,
5769
6006
  schema: propSchema,
5770
6007
  model: isObjectModel(model) ? model[propName] : null,
5771
6008
  localValue: isObjectLocalValue(localValue) ? localValue[propName] : null,
@@ -5775,34 +6012,95 @@ var objectSchemaToComponent = (schemaMapperProps, mapperProps) => {
5775
6012
  mapperProps
5776
6013
  )
5777
6014
  });
5778
- }, {});
5779
- return createObjectComponent(__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
5780
- componentMap,
5781
- displayOrder
5782
- }));
6015
+ }, initialReducerValue);
5783
6016
  };
5784
- var validateDisplayOrder = ($id, displayOrder, properties, logEvent) => {
5785
- if (!displayOrder) {
5786
- const message = `Object schema ${$id} has no displayOrder property.`;
5787
- logEvent("error", message);
6017
+
6018
+ // src/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToMoneyInputComponent.ts
6019
+ var isAmountSchema = (schema) => isStringSchema(schema) && !schema.hidden && schema.format !== "date" && schema.format !== "base64url" && schema.persistAsync === void 0;
6020
+ var isCurrencyConstSchema = (schema) => isConstSchema(schema);
6021
+ var isCurrencySelectSchema = (schema) => isOneOfSchema(schema) && schema.oneOf.length > 0 && schema.oneOf.every((option) => isCurrencyConstSchema(option));
6022
+ var objectSchemaToMoneyInputComponent = (schemaMapperProps, mapperProps) => {
6023
+ return createMoneyInputComponent(
6024
+ __spreadValues(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), createMoneyInputSubComponents(schemaMapperProps, mapperProps)),
6025
+ mapperProps.updateComponent
6026
+ );
6027
+ };
6028
+ var createMoneyInputSubComponents = (schemaMapperProps, mapperProps) => {
6029
+ const { schema: objectSchema } = schemaMapperProps;
6030
+ const amountKey = getAmountSchemaKey(objectSchema, mapperProps);
6031
+ const currencyKey = getCurrencySchemaKey(objectSchema, mapperProps);
6032
+ const currencySchema = objectSchema.properties[currencyKey];
6033
+ const customSchemaMapperProps = __spreadProps(__spreadValues({}, schemaMapperProps), {
6034
+ schema: isOneOfSchema(currencySchema) ? objectSchema : replaceKeyInObjectSchema(objectSchema, currencyKey, { oneOf: [currencySchema] })
6035
+ });
6036
+ const componentMap = createComponentMap(customSchemaMapperProps, mapperProps, "money");
6037
+ const amountComponent = componentMap[amountKey];
6038
+ assertAmountComponent(amountComponent, mapperProps.logEvent);
6039
+ const currencyComponent = componentMap[currencyKey];
6040
+ assertCurrencyComponent(currencyComponent, mapperProps.logEvent);
6041
+ const extraValues = getExtraValues(componentMap, [amountKey, currencyKey]);
6042
+ const checks = getMinMaxChecks(objectSchema, amountKey, mapperProps);
6043
+ return { amountKey, amountComponent, currencyKey, currencyComponent, extraValues, checks };
6044
+ };
6045
+ var getAmountSchemaKey = ({ displayOrder, properties }, mapperProps) => {
6046
+ var _a;
6047
+ const entry = displayOrder.map((key) => ({ key, schema: properties[key] })).find(({ schema }) => isAmountSchema(schema));
6048
+ if (!entry) {
6049
+ 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.`;
6050
+ (_a = mapperProps.logEvent) == null ? void 0 : _a.call(mapperProps, "error", message);
5788
6051
  throw new Error(message);
5789
6052
  }
5790
- const propertyNames = Object.keys(properties);
5791
- displayOrder.forEach((propName) => {
5792
- if (!properties[propName]) {
5793
- const message = `Object schema ${$id} has no property named "${propName}", but it is listed in the displayOrder array.`;
5794
- logEvent("error", message);
5795
- throw new Error(message);
5796
- }
5797
- });
5798
- propertyNames.forEach((propName) => {
5799
- if (!displayOrder.includes(propName)) {
5800
- const message = `Object schema ${$id} has a "${propName}" property which is missing in the displayOrder array.`;
5801
- logEvent("error", message);
5802
- throw new Error(message);
5803
- }
6053
+ return entry.key;
6054
+ };
6055
+ var getCurrencySchemaKey = ({ displayOrder, properties }, mapperProps) => {
6056
+ var _a;
6057
+ const entry = displayOrder.map((key) => ({ key, schema: properties[key] })).find(({ schema }) => isCurrencyConstSchema(schema) || isCurrencySelectSchema(schema));
6058
+ if (!entry) {
6059
+ 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.`;
6060
+ (_a = mapperProps.logEvent) == null ? void 0 : _a.call(mapperProps, "error", message);
6061
+ throw new Error(message);
6062
+ }
6063
+ return entry.key;
6064
+ };
6065
+ var replaceKeyInObjectSchema = (objSchema, key, newSchema) => {
6066
+ return __spreadProps(__spreadValues({}, objSchema), {
6067
+ properties: __spreadProps(__spreadValues({}, objSchema.properties), {
6068
+ [key]: newSchema
6069
+ })
5804
6070
  });
5805
6071
  };
6072
+ var getMinMaxChecks = (objectSchema, amountKey, mapperProps) => {
6073
+ const amountSchema = objectSchema.properties[amountKey];
6074
+ const errorMessageFunctions = mapperProps.getErrorMessageFunctions(
6075
+ amountSchema.validationMessages
6076
+ );
6077
+ const checks = [
6078
+ getAboveMaximumMoneyAmountCheck(amountSchema, errorMessageFunctions),
6079
+ getBelowMinimumMoneyAmountCheck(amountSchema, errorMessageFunctions)
6080
+ ];
6081
+ return checks;
6082
+ };
6083
+ function getExtraValues(componentMap, excludeKeys) {
6084
+ return Object.fromEntries(
6085
+ Object.entries(componentMap).filter(
6086
+ ([key, component]) => !excludeKeys.includes(key) && (component.type === "const" || component.hidden)
6087
+ ).map(([key, component]) => [key, component.getSubmittableValueSync()])
6088
+ );
6089
+ }
6090
+ function assertAmountComponent(component, logEvent) {
6091
+ if (component.type !== "text") {
6092
+ const message = "A string schema was selected for amount but it was not successfully mapped into a TextInputComponent.";
6093
+ logEvent == null ? void 0 : logEvent("error", message);
6094
+ throw new Error(message);
6095
+ }
6096
+ }
6097
+ function assertCurrencyComponent(component, logEvent) {
6098
+ if (component.type !== "select") {
6099
+ const message = "A schema was selected for currency but it was not successfully mapped into a SelectInputComponent.";
6100
+ logEvent == null ? void 0 : logEvent("error", message);
6101
+ throw new Error(message);
6102
+ }
6103
+ }
5806
6104
 
5807
6105
  // src/revamp/domain/components/utils/isPartialModelMatch.ts
5808
6106
  var isPartialModelMatch = (localModel, incomingModel) => {
@@ -5928,6 +6226,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
5928
6226
  );
5929
6227
  }
5930
6228
  const options = schema.oneOf.map((childSchema, index) => {
6229
+ var _a2;
5931
6230
  const { title = "", description, image, icon, media, keywords = [], tags } = childSchema;
5932
6231
  return {
5933
6232
  title,
@@ -5936,6 +6235,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
5936
6235
  keywords,
5937
6236
  tags,
5938
6237
  disabled: "disabled" in childSchema ? Boolean(childSchema.disabled) : false,
6238
+ analyticsId: (_a2 = childSchema.analyticsId) != null ? _a2 : childSchema.$id,
5939
6239
  component: mapSchemaToComponent(
5940
6240
  {
5941
6241
  uid: `${uid}.oneOf-${index}`,
@@ -5971,6 +6271,143 @@ var supressSchemaTitleAndDescription = (schema) => {
5971
6271
  return headlessSchema;
5972
6272
  };
5973
6273
 
6274
+ // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
6275
+ var isExactLocalValueMatch = (valueA, valueB) => {
6276
+ if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
6277
+ return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
6278
+ }
6279
+ if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
6280
+ const keysA = Object.keys(valueA);
6281
+ const keysB = Object.keys(valueB);
6282
+ return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
6283
+ }
6284
+ return valueA === valueB;
6285
+ };
6286
+
6287
+ // src/revamp/domain/components/PersistAsyncComponent.ts
6288
+ var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
6289
+ const { uid, analyticsId, schemaId, component, hidden, model, localValue, tags } = props;
6290
+ const update = getInputUpdateFunction(updateComponent);
6291
+ const paComponent = {
6292
+ type: "persist-async",
6293
+ kind: "input",
6294
+ uid,
6295
+ analyticsId,
6296
+ schemaId,
6297
+ component,
6298
+ hidden,
6299
+ lastSubmitted: model != null ? localValue != null ? localValue : null : null,
6300
+ lastResponse: model != null ? model : null,
6301
+ submission: Promise.resolve(model != null ? model : null),
6302
+ abortController: new AbortController(),
6303
+ errors: [],
6304
+ tags,
6305
+ _update(updateFn) {
6306
+ update(this, updateFn);
6307
+ },
6308
+ validate() {
6309
+ return this.component.validate();
6310
+ },
6311
+ getLocalValue() {
6312
+ return this.component.getLocalValue();
6313
+ },
6314
+ async getSubmittableValue() {
6315
+ return this.persist();
6316
+ },
6317
+ getSubmittableValueSync() {
6318
+ return this.lastResponse;
6319
+ },
6320
+ getSummary() {
6321
+ return this.component.getSummary();
6322
+ },
6323
+ async persist() {
6324
+ const childLocalValue = this.component.getLocalValue();
6325
+ if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
6326
+ return this.submission;
6327
+ }
6328
+ const newAbortController = abortAndResetController(this.abortController);
6329
+ if (childLocalValue == null || childLocalValue === "") {
6330
+ const resolvedNull = Promise.resolve(null);
6331
+ this._update((draft) => {
6332
+ draft.abortController = newAbortController;
6333
+ draft.lastResponse = null;
6334
+ draft.lastSubmitted = childLocalValue;
6335
+ draft.submission = resolvedNull;
6336
+ draft.errors = [];
6337
+ });
6338
+ void (schemaOnChange == null ? void 0 : schemaOnChange());
6339
+ return resolvedNull;
6340
+ }
6341
+ const { signal } = newAbortController;
6342
+ const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
6343
+ this._update((draft) => {
6344
+ draft.lastResponse = token;
6345
+ draft.errors = [];
6346
+ });
6347
+ void (schemaOnChange == null ? void 0 : schemaOnChange());
6348
+ return token;
6349
+ }).catch((error) => {
6350
+ if (error instanceof DOMException && error.name === "AbortError") {
6351
+ return null;
6352
+ }
6353
+ this._update((draft) => {
6354
+ draft.lastResponse = null;
6355
+ draft.lastSubmitted = null;
6356
+ draft.submission = Promise.resolve(null);
6357
+ if (this.component.type !== "upload") {
6358
+ draft.errors = error instanceof Error ? [error.message] : [];
6359
+ }
6360
+ });
6361
+ throw error;
6362
+ });
6363
+ this._update((draft) => {
6364
+ draft.abortController = newAbortController;
6365
+ draft.lastSubmitted = childLocalValue;
6366
+ draft.lastResponse = null;
6367
+ draft.submission = newSubmission;
6368
+ draft.errors = [];
6369
+ });
6370
+ return newSubmission;
6371
+ }
6372
+ };
6373
+ return paComponent;
6374
+ };
6375
+
6376
+ // src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
6377
+ var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
6378
+ var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
6379
+ const { uid, schema, model, localValue } = schemaMapperProps;
6380
+ const { persistAsync, tags } = schema;
6381
+ const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
6382
+ const onPersistAsync = async () => paComponent.persist().then(() => {
6383
+ });
6384
+ const childComponent = mapSchemaToComponent(
6385
+ __spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
6386
+ mapperProps
6387
+ );
6388
+ if (!isSupported(childComponent.type)) {
6389
+ return childComponent;
6390
+ }
6391
+ const paComponent = createPersistAsyncComponent(
6392
+ {
6393
+ uid,
6394
+ // This should be `schema.hidden ?? false`
6395
+ // but some steps are setting PA schemas as hidden for no good reason
6396
+ // so we default to false here to avoid hiding the the children of the PA component
6397
+ hidden: false,
6398
+ component: childComponent,
6399
+ schemaId: schema.$id,
6400
+ model,
6401
+ localValue,
6402
+ tags
6403
+ },
6404
+ performPersistAsync,
6405
+ getSchemaOnChange(schema, mapperProps.onBehavior),
6406
+ mapperProps.updateComponent
6407
+ );
6408
+ return paComponent;
6409
+ };
6410
+
5974
6411
  // src/revamp/domain/components/DateInputComponent.ts
5975
6412
  var createDateInputComponent = (textInputProps, updateComponent) => {
5976
6413
  const _a = textInputProps, {
@@ -6310,143 +6747,6 @@ var isStringSchemaWithBase64 = (schema) => {
6310
6747
  return schema.format === "base64url" && !("persistAsync" in schema);
6311
6748
  };
6312
6749
 
6313
- // src/revamp/domain/components/utils/isExactLocalValueMatch.ts
6314
- var isExactLocalValueMatch = (valueA, valueB) => {
6315
- if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
6316
- return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
6317
- }
6318
- if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
6319
- const keysA = Object.keys(valueA);
6320
- const keysB = Object.keys(valueB);
6321
- return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
6322
- }
6323
- return valueA === valueB;
6324
- };
6325
-
6326
- // src/revamp/domain/components/PersistAsyncComponent.ts
6327
- var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
6328
- const { uid, analyticsId, schemaId, component, hidden, model, localValue, tags } = props;
6329
- const update = getInputUpdateFunction(updateComponent);
6330
- const paComponent = {
6331
- type: "persist-async",
6332
- kind: "input",
6333
- uid,
6334
- analyticsId,
6335
- schemaId,
6336
- component,
6337
- hidden,
6338
- lastSubmitted: model != null ? localValue != null ? localValue : null : null,
6339
- lastResponse: model != null ? model : null,
6340
- submission: Promise.resolve(model != null ? model : null),
6341
- abortController: new AbortController(),
6342
- errors: [],
6343
- tags,
6344
- _update(updateFn) {
6345
- update(this, updateFn);
6346
- },
6347
- validate() {
6348
- return this.component.validate();
6349
- },
6350
- getLocalValue() {
6351
- return this.component.getLocalValue();
6352
- },
6353
- async getSubmittableValue() {
6354
- return this.persist();
6355
- },
6356
- getSubmittableValueSync() {
6357
- return this.lastResponse;
6358
- },
6359
- getSummary() {
6360
- return this.component.getSummary();
6361
- },
6362
- async persist() {
6363
- const childLocalValue = this.component.getLocalValue();
6364
- if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
6365
- return this.submission;
6366
- }
6367
- const newAbortController = abortAndResetController(this.abortController);
6368
- if (childLocalValue == null || childLocalValue === "") {
6369
- const resolvedNull = Promise.resolve(null);
6370
- this._update((draft) => {
6371
- draft.abortController = newAbortController;
6372
- draft.lastResponse = null;
6373
- draft.lastSubmitted = childLocalValue;
6374
- draft.submission = resolvedNull;
6375
- draft.errors = [];
6376
- });
6377
- void (schemaOnChange == null ? void 0 : schemaOnChange());
6378
- return resolvedNull;
6379
- }
6380
- const { signal } = newAbortController;
6381
- const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
6382
- this._update((draft) => {
6383
- draft.lastResponse = token;
6384
- draft.errors = [];
6385
- });
6386
- void (schemaOnChange == null ? void 0 : schemaOnChange());
6387
- return token;
6388
- }).catch((error) => {
6389
- if (error instanceof DOMException && error.name === "AbortError") {
6390
- return null;
6391
- }
6392
- this._update((draft) => {
6393
- draft.lastResponse = null;
6394
- draft.lastSubmitted = null;
6395
- draft.submission = Promise.resolve(null);
6396
- if (this.component.type !== "upload") {
6397
- draft.errors = error instanceof Error ? [error.message] : [];
6398
- }
6399
- });
6400
- throw error;
6401
- });
6402
- this._update((draft) => {
6403
- draft.abortController = newAbortController;
6404
- draft.lastSubmitted = childLocalValue;
6405
- draft.lastResponse = null;
6406
- draft.submission = newSubmission;
6407
- draft.errors = [];
6408
- });
6409
- return newSubmission;
6410
- }
6411
- };
6412
- return paComponent;
6413
- };
6414
-
6415
- // src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
6416
- var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
6417
- var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
6418
- const { uid, schema, model, localValue } = schemaMapperProps;
6419
- const { persistAsync, tags } = schema;
6420
- const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
6421
- const onPersistAsync = async () => paComponent.persist().then(() => {
6422
- });
6423
- const childComponent = mapSchemaToComponent(
6424
- __spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
6425
- mapperProps
6426
- );
6427
- if (!isSupported(childComponent.type)) {
6428
- return childComponent;
6429
- }
6430
- const paComponent = createPersistAsyncComponent(
6431
- {
6432
- uid,
6433
- // This should be `schema.hidden ?? false`
6434
- // but some steps are setting PA schemas as hidden for no good reason
6435
- // so we default to false here to avoid hiding the the children of the PA component
6436
- hidden: false,
6437
- component: childComponent,
6438
- schemaId: schema.$id,
6439
- model,
6440
- localValue,
6441
- tags
6442
- },
6443
- performPersistAsync,
6444
- getSchemaOnChange(schema, mapperProps.onBehavior),
6445
- mapperProps.updateComponent
6446
- );
6447
- return paComponent;
6448
- };
6449
-
6450
6750
  // src/revamp/domain/mappers/mapSchemaToComponent.ts
6451
6751
  var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
6452
6752
  const { uid, schema } = schemaMapperProps;
@@ -6466,7 +6766,10 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
6466
6766
  return booleanSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6467
6767
  }
6468
6768
  if (isObjectSchema(schema)) {
6469
- return objectSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6769
+ if (schema.format === "money") {
6770
+ return objectSchemaToMoneyInputComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6771
+ }
6772
+ return objectSchemaToObjectComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
6470
6773
  }
6471
6774
  if (isIntegerSchema(schema)) {
6472
6775
  return integerSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);