@wise/dynamic-flow-client 3.18.1 → 3.19.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/build/main.js CHANGED
@@ -1622,6 +1622,8 @@ var instructionsComponentToProps = ({
1622
1622
 
1623
1623
  // src/revamp/renderers/mappers/integerInputComponentToProps.ts
1624
1624
  var integerInputComponentToProps = (component) => __spreadProps(__spreadValues({}, inputComponentToProps(component, "input-integer")), {
1625
+ maximum: component.maximum,
1626
+ minimum: component.minimum,
1625
1627
  onChange: component.onChange.bind(component)
1626
1628
  });
1627
1629
 
@@ -1685,6 +1687,8 @@ var multiUploadInputComponentToProps = (component) => {
1685
1687
 
1686
1688
  // src/revamp/renderers/mappers/numberInputComponentToProps.ts
1687
1689
  var numberInputComponentToProps = (component) => __spreadProps(__spreadValues({}, inputComponentToProps(component, "input-number")), {
1690
+ maximum: component.maximum,
1691
+ minimum: component.minimum,
1688
1692
  onChange: component.onChange.bind(component)
1689
1693
  });
1690
1694
 
@@ -1721,6 +1725,8 @@ var repeatableComponentToProps = (component, children, editableItemChildren) =>
1721
1725
  description,
1722
1726
  editItemTitle,
1723
1727
  errors,
1728
+ maxItems,
1729
+ minItems,
1724
1730
  summaryDefaults,
1725
1731
  title = "",
1726
1732
  onEdit,
@@ -1743,13 +1749,15 @@ var repeatableComponentToProps = (component, children, editableItemChildren) =>
1743
1749
  return {
1744
1750
  type: "repeatable",
1745
1751
  children,
1752
+ addItemTitle,
1746
1753
  control,
1747
- items: itemProps,
1748
- editableItem: editableItemChildren,
1749
- title,
1750
1754
  description,
1751
- addItemTitle,
1755
+ editableItem: editableItemChildren,
1752
1756
  editItemTitle,
1757
+ items: itemProps,
1758
+ maxItems,
1759
+ minItems,
1760
+ title,
1753
1761
  error: errors[0],
1754
1762
  onAdd: onAdd.bind(component),
1755
1763
  onEdit: onEdit.bind(component),
@@ -1858,14 +1866,18 @@ var statusListComponentToProps = ({
1858
1866
  // src/revamp/renderers/mappers/textInputComponentToProps.ts
1859
1867
  var textInputComponentToProps = (component) => __spreadProps(__spreadValues({}, inputComponentToProps(component, "input-text")), {
1860
1868
  displayFormat: component.displayFormat,
1869
+ maxLength: component.maxLength,
1870
+ minLength: component.minLength,
1861
1871
  onChange: component.onChange.bind(component)
1862
1872
  });
1863
1873
 
1864
1874
  // src/revamp/renderers/mappers/multiSelectComponentToProps.ts
1865
1875
  var multiSelectInputComponentToProps = (component) => {
1866
- const { options, selectedIndices, onSelect } = component;
1867
- const _a = inputComponentToProps(component, "input-multi-select"), { value } = _a, props = __objRest(_a, ["value"]);
1876
+ const { maxItems, minItems, options, selectedIndices, onSelect } = component;
1877
+ const _a = inputComponentToProps(component, "input-multi-select"), { required, value } = _a, props = __objRest(_a, ["required", "value"]);
1868
1878
  return __spreadProps(__spreadValues({}, props), {
1879
+ maxItems,
1880
+ minItems,
1869
1881
  options,
1870
1882
  selectedIndices,
1871
1883
  onSelect: onSelect.bind(component)
@@ -6808,84 +6820,34 @@ var createStepComponent = (stepProps) => {
6808
6820
  });
6809
6821
  };
6810
6822
 
6811
- // src/revamp/flow/response-utils.ts
6812
- var assertResponseIsValid = (response) => {
6813
- if (!isResponse(response)) {
6814
- throw new Error("Incorrect type of response from fetch. Expected object of type Response.");
6815
- }
6816
- if (response.bodyUsed) {
6817
- throw new Error(
6818
- "The body of the provided Response object has already been used. Every request must respond with a new Response object."
6819
- );
6820
- }
6821
- };
6822
- var isResponse = (response) => typeof response === "object" && response !== null && "clone" in response && "bodyUsed" in response;
6823
- var parseResponseBodyAsJsonElement = async (response) => {
6824
- try {
6825
- return await response.json();
6826
- } catch (e) {
6827
- return null;
6828
- }
6829
- };
6830
- function isActionResponseBody(body) {
6831
- return validateActionResponse(body).valid;
6832
- }
6833
- function assertActionResponseBody(body) {
6834
- if (!isObject(body) || !isObject(body.action)) {
6835
- throw new Error(
6836
- "Incorrect response body in action response. Expected an object satisfying the type { action: Action }."
6837
- );
6838
- }
6839
- }
6840
- function isErrorResponseBody(body) {
6841
- return Boolean(
6842
- isObject(body) && (body.refreshFormUrl || body.refreshUrl || body.validation || body.error || body.analytics)
6843
- );
6844
- }
6845
- function assertStepResponseBody(body) {
6846
- if (!isObject(body)) {
6847
- throw new Error("Incorrect response body in step response. Expected an object.");
6848
- }
6849
- }
6850
-
6851
6823
  // src/revamp/domain/features/polling/getStepPolling.ts
6852
6824
  var getStepPolling = ({
6853
- httpClient,
6854
6825
  pollingConfig,
6855
- onAction
6826
+ onAction,
6827
+ onPoll
6856
6828
  }) => {
6857
6829
  const { interval, delay = interval, maxAttempts, url, onError } = pollingConfig;
6858
6830
  let abortController = new AbortController();
6859
6831
  if (delay == null) {
6860
6832
  throw new Error("Polling configuration must include delay or interval");
6861
6833
  }
6862
- const onFailure = () => {
6863
- stop();
6864
- void onAction(onError.action);
6865
- };
6866
6834
  let attempts = 0;
6867
6835
  const poll = () => {
6868
6836
  attempts += 1;
6869
6837
  abortController.abort();
6870
6838
  abortController = new AbortController();
6871
6839
  const { signal } = abortController;
6872
- httpClient(url, { signal }).then(async (response) => {
6873
- if (!response.ok) {
6874
- onFailure();
6840
+ onPoll(url, onError.action, signal).then((result) => {
6841
+ if (result) {
6842
+ stop();
6875
6843
  return;
6876
6844
  }
6877
- response.json().then((body) => {
6878
- if (isActionResponseBody(body)) {
6879
- void onAction(body.action);
6880
- stop();
6881
- }
6882
- }).catch(() => {
6883
- });
6845
+ if (attempts >= maxAttempts && !signal.aborted) {
6846
+ void onAction(onError.action);
6847
+ stop();
6848
+ }
6884
6849
  }).catch(() => {
6885
6850
  });
6886
- if (attempts >= maxAttempts && !signal.aborted) {
6887
- onFailure();
6888
- }
6889
6851
  };
6890
6852
  poll();
6891
6853
  const intervalRef = setInterval(poll, delay * 1e3);
@@ -7660,6 +7622,46 @@ var autocompleteTokenMap = {
7660
7622
  pager: "pager"
7661
7623
  };
7662
7624
 
7625
+ // src/revamp/flow/response-utils.ts
7626
+ var assertResponseIsValid = (response) => {
7627
+ if (!isResponse(response)) {
7628
+ throw new Error("Incorrect type of response from fetch. Expected object of type Response.");
7629
+ }
7630
+ if (response.bodyUsed) {
7631
+ throw new Error(
7632
+ "The body of the provided Response object has already been used. Every request must respond with a new Response object."
7633
+ );
7634
+ }
7635
+ };
7636
+ var isResponse = (response) => typeof response === "object" && response !== null && "clone" in response && "bodyUsed" in response;
7637
+ var parseResponseBodyAsJsonElement = async (response) => {
7638
+ try {
7639
+ return await response.json();
7640
+ } catch (e) {
7641
+ return null;
7642
+ }
7643
+ };
7644
+ function isActionResponseBody(body) {
7645
+ return validateActionResponse(body).valid;
7646
+ }
7647
+ function assertActionResponseBody(body) {
7648
+ if (!isObject(body) || !isObject(body.action)) {
7649
+ throw new Error(
7650
+ "Incorrect response body in action response. Expected an object satisfying the type { action: Action }."
7651
+ );
7652
+ }
7653
+ }
7654
+ function isErrorResponseBody(body) {
7655
+ return Boolean(
7656
+ isObject(body) && (body.refreshFormUrl || body.refreshUrl || body.validation || body.error || body.analytics)
7657
+ );
7658
+ }
7659
+ function assertStepResponseBody(body) {
7660
+ if (!isObject(body)) {
7661
+ throw new Error("Incorrect response body in step response. Expected an object.");
7662
+ }
7663
+ }
7664
+
7663
7665
  // src/revamp/domain/features/utils/response-utils.ts
7664
7666
  var getAnalyticsFromErrorResponse = (json) => {
7665
7667
  if (!isErrorResponseBody(json)) {
@@ -7860,7 +7862,7 @@ var schemaHasValidationAsync = (schema) => Boolean("validationAsync" in schema &
7860
7862
  // src/revamp/domain/mappers/schema/numberSchemaToComponent.ts
7861
7863
  var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
7862
7864
  const { schema, model, localValue, required = false } = schemaMapperProps;
7863
- const { autocompleteHint, validationMessages, default: defaultValue } = schema;
7865
+ const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
7864
7866
  const { getErrorMessageFunctions, updateComponent, onRefresh, onValueChange } = mapperProps;
7865
7867
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
7866
7868
  const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
@@ -7883,6 +7885,8 @@ var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
7883
7885
  getAboveMaximumCheck(schema, errorMessageFunctions)
7884
7886
  ],
7885
7887
  value,
7888
+ maximum,
7889
+ minimum,
7886
7890
  persistedState,
7887
7891
  validationState,
7888
7892
  performPersistAsync,
@@ -8207,7 +8211,7 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
8207
8211
  // src/revamp/domain/mappers/schema/integerSchemaToComponent.ts
8208
8212
  var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
8209
8213
  const { schema, localValue, model, required = false } = schemaMapperProps;
8210
- const { autocompleteHint, validationMessages, default: defaultValue } = schema;
8214
+ const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
8211
8215
  const { getErrorMessageFunctions, updateComponent, onRefresh, onValueChange } = mapperProps;
8212
8216
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
8213
8217
  const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
@@ -8230,6 +8234,8 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
8230
8234
  __spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
8231
8235
  autoComplete: getAutocompleteString(autocompleteHint),
8232
8236
  checks,
8237
+ maximum,
8238
+ minimum,
8233
8239
  persistedState,
8234
8240
  value,
8235
8241
  validationState,
@@ -8808,6 +8814,8 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
8808
8814
  default: defaultValue,
8809
8815
  displayFormat,
8810
8816
  format,
8817
+ maxLength,
8818
+ minLength,
8811
8819
  validationMessages
8812
8820
  } = schema;
8813
8821
  const { getErrorMessageFunctions, updateComponent, onRefresh, onValueChange } = mapperProps;
@@ -8835,6 +8843,8 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
8835
8843
  ],
8836
8844
  control: control != null ? control : controlForLegacyFormat,
8837
8845
  displayFormat,
8846
+ maxLength,
8847
+ minLength,
8838
8848
  value,
8839
8849
  persistedState,
8840
8850
  validationState,
@@ -9013,7 +9023,7 @@ var arraySchemaToRepeatableComponent = (schemaMapperProps, mapperProps) => {
9013
9023
  required = false,
9014
9024
  validationErrors
9015
9025
  } = schemaMapperProps;
9016
- const { items, addItemTitle, editItemTitle, summary } = schema;
9026
+ const { items, addItemTitle, editItemTitle, maxItems, minItems, summary } = schema;
9017
9027
  const value = isArray(localValue) ? localValue : [];
9018
9028
  const components = initialModel == null ? void 0 : initialModel.map(
9019
9029
  (item, index) => mapSchemaToComponent(
@@ -9050,6 +9060,8 @@ var arraySchemaToRepeatableComponent = (schemaMapperProps, mapperProps) => {
9050
9060
  ],
9051
9061
  components: components != null ? components : [],
9052
9062
  editItemTitle,
9063
+ maxItems,
9064
+ minItems,
9053
9065
  summary,
9054
9066
  createEditableComponent,
9055
9067
  onValueChange
@@ -9362,7 +9374,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
9362
9374
  )
9363
9375
  };
9364
9376
  });
9365
- const { title, validationMessages } = schema;
9377
+ const { maxItems, minItems, title, validationMessages } = schema;
9366
9378
  const { getErrorMessageFunctions, onRefresh, onValueChange, updateComponent } = mapperProps;
9367
9379
  const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
9368
9380
  const { performValidationAsync, validationState } = getValidationAsyncInitialState(
@@ -9379,6 +9391,8 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
9379
9391
  getBelowMinItemsCheck(schema, errorMessageFunctions)
9380
9392
  ],
9381
9393
  initialValue,
9394
+ maxItems,
9395
+ minItems,
9382
9396
  options,
9383
9397
  required,
9384
9398
  title,
@@ -10239,14 +10253,16 @@ var mapStepToComponent = (_a) => {
10239
10253
  var _b = _a, {
10240
10254
  loadingState,
10241
10255
  displayStepTitle,
10242
- trackEvent
10256
+ trackEvent,
10257
+ onPoll
10243
10258
  } = _b, restProps = __objRest(_b, [
10244
10259
  "loadingState",
10245
10260
  "displayStepTitle",
10246
- "trackEvent"
10261
+ "trackEvent",
10262
+ "onPoll"
10247
10263
  ]);
10248
10264
  var _a2, _b2;
10249
- const { httpClient, step, updateComponent } = restProps;
10265
+ const { step, updateComponent } = restProps;
10250
10266
  const { id, description, errors, external, key, layout = [], navigation, polling, title } = step;
10251
10267
  const backNavigation = (_a2 = navigation == null ? void 0 : navigation.back) != null ? _a2 : navigation == null ? void 0 : navigation.backButton;
10252
10268
  const back = backNavigation ? {
@@ -10276,7 +10292,7 @@ var mapStepToComponent = (_a) => {
10276
10292
  }
10277
10293
  };
10278
10294
  const onRefresh = async (schemaId, url) => restProps.onRefresh(schemaId, url != null ? url : refreshUrl);
10279
- const stepPolling = polling ? getStepPolling({ httpClient, pollingConfig: polling, onAction: restProps.onAction }) : void 0;
10295
+ const stepPolling = polling ? getStepPolling({ pollingConfig: polling, onAction: restProps.onAction, onPoll }) : void 0;
10280
10296
  const mapperProps = __spreadProps(__spreadValues({}, restProps), { trackEvent, onAction, onRefresh });
10281
10297
  const unreferencedSchemaFormComponents = mapUnreferencedSchemas(mapperProps);
10282
10298
  const layoutComponents = layout.map(
@@ -10342,8 +10358,19 @@ var executeRefresh = async (props) => {
10342
10358
  // src/revamp/flow/getResponseType.ts
10343
10359
  var responseTypes = ["step", "action", "exit"];
10344
10360
  var getResponseType = async (response) => {
10345
- var _a, _b;
10346
10361
  assertResponseIsValid(response);
10362
+ const headerResponseType = getResponseTypeFromHeader(response);
10363
+ if (headerResponseType) {
10364
+ return headerResponseType;
10365
+ }
10366
+ const jsonBody = await parseResponseBodyAsJsonElement(response.clone());
10367
+ if (isObject(jsonBody) && jsonBody.action) {
10368
+ return "action";
10369
+ }
10370
+ return "step";
10371
+ };
10372
+ var getResponseTypeFromHeader = (response) => {
10373
+ var _a, _b;
10347
10374
  if ((_a = response.headers) == null ? void 0 : _a.has("X-Df-Response-Type")) {
10348
10375
  const type = response.headers.get("X-Df-Response-Type");
10349
10376
  assertDFResponseType(type);
@@ -10352,11 +10379,7 @@ var getResponseType = async (response) => {
10352
10379
  if ((_b = response.headers) == null ? void 0 : _b.has("X-Df-Exit")) {
10353
10380
  return "exit";
10354
10381
  }
10355
- const jsonBody = await parseResponseBodyAsJsonElement(response.clone());
10356
- if (isObject(jsonBody) && jsonBody.action) {
10357
- return "action";
10358
- }
10359
- return "step";
10382
+ return void 0;
10360
10383
  };
10361
10384
  function assertDFResponseType(type) {
10362
10385
  if (!responseTypes.includes(type)) {
@@ -10647,6 +10670,48 @@ function useStableCallback(handler) {
10647
10670
  return (0, import_react2.useCallback)((...args) => ref.current ? ref.current(...args) : null, []);
10648
10671
  }
10649
10672
 
10673
+ // src/revamp/flow/executePoll.ts
10674
+ var executePoll = async (props) => {
10675
+ const { errorAction, signal, url, httpClient } = props;
10676
+ try {
10677
+ const response = await httpClient(url != null ? url : "", {
10678
+ method: "GET",
10679
+ signal
10680
+ });
10681
+ if (!response.ok) {
10682
+ return { type: "action", action: errorAction };
10683
+ }
10684
+ const responseType = getResponseTypeFromHeader(response);
10685
+ const body = await parseResponseBodyAsJsonElement(response);
10686
+ try {
10687
+ switch (responseType) {
10688
+ case "step": {
10689
+ const etag = response.headers.get("etag") || null;
10690
+ assertStepResponseBody(body);
10691
+ return { type: "replace-step", step: body, etag };
10692
+ }
10693
+ case "exit": {
10694
+ return { type: "complete", result: body };
10695
+ }
10696
+ case "action": {
10697
+ assertActionResponseBody(body);
10698
+ return { type: "action", action: body.action };
10699
+ }
10700
+ default: {
10701
+ if (isActionResponseBody(body)) {
10702
+ return { type: "action", action: body.action };
10703
+ }
10704
+ return { type: "continue" };
10705
+ }
10706
+ }
10707
+ } catch (error) {
10708
+ return { type: "action", action: errorAction };
10709
+ }
10710
+ } catch (error) {
10711
+ return { type: "continue" };
10712
+ }
10713
+ };
10714
+
10650
10715
  // src/revamp/useDynamicFlowCore.tsx
10651
10716
  function useDynamicFlowCore(props) {
10652
10717
  const _a = props, { flowId, initialAction, initialStep, displayStepTitle = true } = _a, rest = __objRest(_a, ["flowId", "initialAction", "initialStep", "displayStepTitle"]);
@@ -10715,6 +10780,7 @@ function useDynamicFlowCore(props) {
10715
10780
  httpClient,
10716
10781
  onAction,
10717
10782
  onRefresh,
10783
+ onPoll,
10718
10784
  onValueChange
10719
10785
  });
10720
10786
  setStepComponent(() => {
@@ -10848,6 +10914,31 @@ function useDynamicFlowCore(props) {
10848
10914
  // eslint-disable-next-line react-hooks/exhaustive-deps
10849
10915
  []
10850
10916
  );
10917
+ const onPoll = (0, import_react3.useCallback)(
10918
+ async (url, errorAction, signal) => {
10919
+ const command = await executePoll({
10920
+ httpClient,
10921
+ url,
10922
+ errorAction,
10923
+ signal
10924
+ });
10925
+ switch (command.type) {
10926
+ case "replace-step":
10927
+ initialiseWithStep(command.step, command.etag);
10928
+ return true;
10929
+ case "action":
10930
+ void onAction(command.action);
10931
+ return true;
10932
+ case "complete":
10933
+ onCompletion(command.result);
10934
+ return true;
10935
+ case "continue":
10936
+ return false;
10937
+ }
10938
+ },
10939
+ // eslint-disable-next-line react-hooks/exhaustive-deps
10940
+ []
10941
+ );
10851
10942
  return { stepComponentRef };
10852
10943
  }
10853
10944
 
@@ -12598,6 +12689,8 @@ var TextInputRenderer = {
12598
12689
  description,
12599
12690
  help,
12600
12691
  error,
12692
+ maxLength,
12693
+ minLength,
12601
12694
  type,
12602
12695
  value: initialValue
12603
12696
  } = _a, rest = __objRest(_a, [
@@ -12607,6 +12700,8 @@ var TextInputRenderer = {
12607
12700
  "description",
12608
12701
  "help",
12609
12702
  "error",
12703
+ "maxLength",
12704
+ "minLength",
12610
12705
  "type",
12611
12706
  "value"
12612
12707
  ]);