@wise/dynamic-flow-client 4.3.6 → 4.3.7

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.js +263 -480
  2. package/build/main.mjs +263 -480
  3. package/build/types/revamp/domain/components/StatusListComponent.d.ts +0 -2
  4. package/build/types/revamp/domain/components/StepDomainComponent.d.ts +3 -3
  5. package/build/types/revamp/domain/components/searchComponent/SearchComponent.d.ts +2 -2
  6. package/build/types/revamp/domain/features/polling/getStepPolling.d.ts +3 -3
  7. package/build/types/revamp/domain/mappers/layout/alertLayoutToComponent.d.ts +1 -2
  8. package/build/types/revamp/domain/mappers/layout/decisionLayoutToComponent.d.ts +1 -1
  9. package/build/types/revamp/domain/mappers/layout/listLayoutToComponent.d.ts +1 -2
  10. package/build/types/revamp/domain/mappers/layout/reviewLayoutToComponent.d.ts +1 -1
  11. package/build/types/revamp/domain/mappers/layout/statusListLayoutToComponent.d.ts +1 -1
  12. package/build/types/revamp/domain/mappers/mapStepToComponent.d.ts +1 -1
  13. package/build/types/revamp/domain/mappers/schema/tests/test-utils.d.ts +3 -2
  14. package/build/types/revamp/domain/mappers/schema/types.d.ts +2 -3
  15. package/build/types/revamp/domain/mappers/utils/behavior-utils.d.ts +8 -0
  16. package/build/types/revamp/domain/mappers/utils/call-to-action-utils.d.ts +22 -0
  17. package/build/types/revamp/domain/types.d.ts +10 -4
  18. package/build/types/revamp/flow/executePoll.d.ts +5 -4
  19. package/build/types/revamp/renderers/stepComponentToProps.d.ts +1 -1
  20. package/build/types/revamp/useDynamicFlowCore.d.ts +1 -1
  21. package/package.json +3 -3
  22. package/build/types/revamp/domain/mappers/utils/inlineAction.d.ts +0 -2
package/build/main.mjs CHANGED
@@ -1650,7 +1650,7 @@ var stepComponentToProps = ({
1650
1650
  step,
1651
1651
  title,
1652
1652
  components,
1653
- onAction
1653
+ onBehavior
1654
1654
  }, rendererMapperProps) => {
1655
1655
  const childrenProps = components.map((c) => componentToRendererProps(c, rendererMapperProps));
1656
1656
  return __spreadValues({
@@ -1667,7 +1667,9 @@ var stepComponentToProps = ({
1667
1667
  title,
1668
1668
  children: childrenProps.map(rendererMapperProps.render),
1669
1669
  childrenProps,
1670
- onAction
1670
+ onAction: (action) => {
1671
+ void onBehavior({ type: "action", action });
1672
+ }
1671
1673
  }, rendererMapperProps);
1672
1674
  };
1673
1675
 
@@ -1768,6 +1770,48 @@ import { validateStep } from "@wise/dynamic-flow-types";
1768
1770
  import { useCallback as useCallback2, useEffect, useMemo, useRef as useRef2, useState } from "react";
1769
1771
  import { useIntl as useIntl2 } from "react-intl";
1770
1772
 
1773
+ // src/revamp/domain/components/RootDomainComponent.ts
1774
+ var createRootDomainComponent = () => ({
1775
+ type: "root",
1776
+ uid: "root",
1777
+ stepComponent: null,
1778
+ getChildren() {
1779
+ return this.stepComponent ? [this.stepComponent] : [];
1780
+ },
1781
+ getLocalValue() {
1782
+ return this.stepComponent ? this.stepComponent.getLocalValue() : null;
1783
+ },
1784
+ async getSubmittableValue() {
1785
+ return this.stepComponent ? this.stepComponent.getSubmittableValue() : null;
1786
+ },
1787
+ getSubmittableValueSync() {
1788
+ return this.stepComponent ? this.stepComponent.getSubmittableValueSync() : null;
1789
+ },
1790
+ getSummary() {
1791
+ return this.stepComponent ? this.stepComponent.getSummary() : {};
1792
+ },
1793
+ validate() {
1794
+ return this.stepComponent ? this.stepComponent.validate() : false;
1795
+ },
1796
+ setLoadingState(loadingState) {
1797
+ var _a;
1798
+ (_a = this.stepComponent) == null ? void 0 : _a.setLoadingState(loadingState);
1799
+ },
1800
+ getLoadingState() {
1801
+ return this.stepComponent ? this.stepComponent.loadingState : "initial";
1802
+ },
1803
+ getTrackEvent() {
1804
+ return this.stepComponent ? this.stepComponent.trackEvent : null;
1805
+ },
1806
+ hasStep() {
1807
+ return Boolean(this.stepComponent);
1808
+ },
1809
+ stop() {
1810
+ var _a;
1811
+ (_a = this.stepComponent) == null ? void 0 : _a.stop();
1812
+ }
1813
+ });
1814
+
1771
1815
  // src/revamp/utils/component-utils.ts
1772
1816
  var getSubmittableData = async (components) => Promise.all(components.map(async (component) => component.getSubmittableValue())).then(
1773
1817
  (values) => values.reduce((acc, value) => mergeModels(acc, value), null)
@@ -1885,10 +1929,49 @@ var createStepComponent = (stepProps) => {
1885
1929
  });
1886
1930
  };
1887
1931
 
1932
+ // src/revamp/domain/mappers/utils/behavior-utils.ts
1933
+ var getDomainLayerBehavior = ({
1934
+ action,
1935
+ behavior
1936
+ }, stepActions) => {
1937
+ if (behavior) {
1938
+ return normaliseBehavior(behavior, stepActions);
1939
+ }
1940
+ if (action) {
1941
+ return actionToBehavior(action, stepActions);
1942
+ }
1943
+ return { type: "none" };
1944
+ };
1945
+ var skipValidation = (behavior) => behavior.type === "action" ? __spreadProps(__spreadValues({}, behavior), { action: __spreadProps(__spreadValues({}, behavior.action), { skipValidation: true }) }) : behavior;
1946
+ var normaliseBehavior = (behavior, stepActions) => {
1947
+ if ("type" in behavior) {
1948
+ return behavior;
1949
+ }
1950
+ if ("action" in behavior && behavior.action) {
1951
+ return actionToBehavior(behavior.action, stepActions);
1952
+ }
1953
+ if ("link" in behavior && behavior.link) {
1954
+ return { type: "link", url: behavior.link.url };
1955
+ }
1956
+ return { type: "none" };
1957
+ };
1958
+ var actionToBehavior = (action, stepActions) => ({
1959
+ type: "action",
1960
+ action: inlineAction(action, stepActions)
1961
+ });
1962
+ var inlineAction = (action, stepActions = []) => action.$ref ? __spreadValues(__spreadValues({}, getActionByReference(action.$ref, stepActions)), action) : action;
1963
+ var getActionByReference = ($ref, actions = []) => {
1964
+ const action = actions.find((a) => a.$id === $ref);
1965
+ if (!action) {
1966
+ throw new Error("Action reference not found in actions array.");
1967
+ }
1968
+ return action;
1969
+ };
1970
+
1888
1971
  // src/revamp/domain/features/polling/getStepPolling.ts
1889
1972
  var getStepPolling = ({
1890
1973
  pollingConfig,
1891
- onAction,
1974
+ onBehavior,
1892
1975
  onPoll
1893
1976
  }) => {
1894
1977
  const { interval, delay = interval, maxAttempts, url, onError } = pollingConfig;
@@ -1896,20 +1979,20 @@ var getStepPolling = ({
1896
1979
  if (delay == null) {
1897
1980
  throw new Error("Polling configuration must include delay or interval");
1898
1981
  }
1899
- const onErrorAction = getOnErrorAction(onError);
1982
+ const onErrorBehavior = skipValidation(getDomainLayerBehavior(onError, []));
1900
1983
  let attempts = 0;
1901
1984
  const poll = () => {
1902
1985
  attempts += 1;
1903
1986
  abortController.abort();
1904
1987
  abortController = new AbortController();
1905
1988
  const { signal } = abortController;
1906
- onPoll(url, onErrorAction, signal).then((result) => {
1989
+ onPoll(url, onErrorBehavior, signal).then((result) => {
1907
1990
  if (result) {
1908
1991
  stop();
1909
1992
  return;
1910
1993
  }
1911
1994
  if (attempts >= maxAttempts && !signal.aborted) {
1912
- void onAction(onErrorAction);
1995
+ void onBehavior(onErrorBehavior);
1913
1996
  stop();
1914
1997
  }
1915
1998
  }).catch(() => {
@@ -1923,19 +2006,21 @@ var getStepPolling = ({
1923
2006
  poll();
1924
2007
  return { stop };
1925
2008
  };
1926
- var getOnErrorAction = (onError) => {
1927
- if ("behavior" in onError) {
1928
- if (onError.behavior && "type" in onError.behavior && onError.behavior.type === "action") {
1929
- return onError.behavior.action;
1930
- }
1931
- if (onError.behavior && "action" in onError.behavior && onError.behavior.action) {
1932
- return onError.behavior.action;
1933
- }
1934
- }
1935
- if ("action" in onError && onError.action) {
1936
- return onError.action;
2009
+
2010
+ // src/revamp/domain/features/refreshAfter/getStepRefreshAfter.ts
2011
+ var ONE_SECOND = 1e3;
2012
+ var getStepRefreshAfter = ({ refreshAfter, onRefresh }) => {
2013
+ const targetTime = new Date(refreshAfter).getTime();
2014
+ if (typeof refreshAfter !== "string" || Number.isNaN(targetTime)) {
2015
+ throw new Error(`Invalid refreshAfter value: ${String(refreshAfter)}`);
1937
2016
  }
1938
- return {};
2017
+ const timeLeft = Math.max(targetTime - Date.now(), ONE_SECOND);
2018
+ const timeout = setTimeout(() => {
2019
+ void onRefresh("refreshAfter");
2020
+ }, timeLeft);
2021
+ return {
2022
+ stop: () => clearTimeout(timeout)
2023
+ };
1939
2024
  };
1940
2025
 
1941
2026
  // src/revamp/domain/components/AlertComponent.ts
@@ -1950,6 +2035,45 @@ var createAlertComponent = (alertProps) => __spreadProps(__spreadValues({
1950
2035
  validate: () => true
1951
2036
  });
1952
2037
 
2038
+ // src/revamp/domain/mappers/utils/call-to-action-utils.ts
2039
+ var getDomainLayerCallToAction = (callToAction, onBehavior, stepActions) => {
2040
+ if (!callToAction) {
2041
+ return void 0;
2042
+ }
2043
+ const { title = "", accessibilityDescription, action, behavior } = callToAction;
2044
+ return getCallToAction(
2045
+ { title, accessibilityDescription },
2046
+ getDomainLayerBehavior({ action, behavior }, stepActions),
2047
+ onBehavior
2048
+ );
2049
+ };
2050
+ var getCallToAction = ({ title, accessibilityDescription }, behavior, onBehavior) => {
2051
+ const onClick = () => {
2052
+ void onBehavior(behavior);
2053
+ };
2054
+ switch (behavior.type) {
2055
+ case "action": {
2056
+ return {
2057
+ type: "action",
2058
+ title: title != null ? title : "",
2059
+ accessibilityDescription,
2060
+ onClick
2061
+ };
2062
+ }
2063
+ case "link": {
2064
+ return {
2065
+ type: "link",
2066
+ title: title != null ? title : "",
2067
+ href: behavior.url,
2068
+ accessibilityDescription,
2069
+ onClick
2070
+ };
2071
+ }
2072
+ default:
2073
+ return void 0;
2074
+ }
2075
+ };
2076
+
1953
2077
  // src/revamp/domain/mappers/utils/legacy-utils.ts
1954
2078
  var mapLegacyContext = (context) => {
1955
2079
  switch (context) {
@@ -2002,67 +2126,18 @@ var legacyActionTypeToControl = {
2002
2126
  var mapLegacyActionTypeToControl = (type) => type && type in legacyActionTypeToControl ? legacyActionTypeToControl[type] : "secondary";
2003
2127
 
2004
2128
  // src/revamp/domain/mappers/layout/alertLayoutToComponent.ts
2005
- var alertLayoutToComponent = (uid, { control, markdown, margin = "md", context = "neutral", callToAction }, { onAction }) => {
2129
+ var alertLayoutToComponent = (uid, { control, markdown, margin = "md", context = "neutral", callToAction }, { onBehavior, step }) => {
2130
+ var _a;
2131
+ const cta = callToAction ? getDomainLayerCallToAction(callToAction, onBehavior, (_a = step.actions) != null ? _a : []) : void 0;
2006
2132
  return createAlertComponent({
2007
2133
  uid,
2008
2134
  control,
2009
2135
  markdown,
2010
2136
  margin,
2011
- callToAction: getComponentCallToAction(callToAction, onAction),
2137
+ callToAction: cta,
2012
2138
  context: mapLegacyContext(context)
2013
2139
  });
2014
2140
  };
2015
- var getComponentCallToAction = (callToAction, onAction) => {
2016
- if (!callToAction) {
2017
- return void 0;
2018
- }
2019
- const { accessibilityDescription, behavior, title } = callToAction;
2020
- if ("type" in behavior) {
2021
- switch (behavior.type) {
2022
- case "action": {
2023
- const { action } = behavior;
2024
- return {
2025
- type: "action",
2026
- accessibilityDescription,
2027
- title,
2028
- onClick: () => {
2029
- void onAction(action);
2030
- }
2031
- };
2032
- }
2033
- case "link": {
2034
- return {
2035
- type: "link",
2036
- accessibilityDescription,
2037
- href: behavior.url,
2038
- title
2039
- };
2040
- }
2041
- default:
2042
- return void 0;
2043
- }
2044
- }
2045
- if (behavior.link) {
2046
- const { url } = behavior.link;
2047
- return {
2048
- type: "link",
2049
- accessibilityDescription,
2050
- href: url,
2051
- title
2052
- };
2053
- }
2054
- if (behavior.action) {
2055
- const { action } = behavior;
2056
- return {
2057
- type: "action",
2058
- accessibilityDescription,
2059
- title,
2060
- onClick: () => {
2061
- void onAction(action);
2062
- }
2063
- };
2064
- }
2065
- };
2066
2141
 
2067
2142
  // src/revamp/domain/components/BoxComponent.ts
2068
2143
  var createBoxComponent = (boxProps) => __spreadProps(__spreadValues({}, boxProps), {
@@ -2111,75 +2186,24 @@ var createButtonComponent = (buttonProps) => __spreadProps(__spreadValues({
2111
2186
  validate: () => true
2112
2187
  });
2113
2188
 
2114
- // src/revamp/domain/mappers/utils/inlineAction.ts
2115
- var inlineAction = (action, stepActions = []) => action.$ref ? __spreadValues(__spreadValues({}, getActionByReference(action.$ref, stepActions)), action) : action;
2116
- var getActionByReference = ($ref, actions = []) => {
2117
- const action = actions.find((a) => a.$id === $ref);
2118
- if (!action) {
2119
- throw new Error("Action reference not found in actions array.");
2120
- }
2121
- return action;
2122
- };
2123
-
2124
2189
  // src/revamp/domain/mappers/layout/buttonLayoutToComponent.ts
2125
2190
  var buttonLayoutToComponent = (uid, button, mapperProps) => {
2126
- if (button.behavior) {
2127
- return buttonLayoutToComponentWithBehavior(
2128
- uid,
2129
- __spreadProps(__spreadValues({}, button), { behavior: button.behavior }),
2130
- mapperProps
2131
- );
2132
- }
2133
- if (button.action) {
2191
+ if (!button.behavior && button.action) {
2134
2192
  return buttonLayoutToComponentWithAction(
2135
2193
  uid,
2136
2194
  __spreadProps(__spreadValues({}, button), { action: button.action }),
2137
2195
  mapperProps
2138
2196
  );
2139
2197
  }
2140
- return buttonLayoutToComponentWithNoop(uid, button);
2198
+ return buttonLayoutToComponentWithBehavior(uid, button, mapperProps);
2141
2199
  };
2142
2200
  var buttonLayoutToComponentWithBehavior = (uid, button, mapperProps) => {
2143
- const { onAction, onLink, step } = mapperProps;
2144
- const { context, control, disabled, margin = "md", pinOrder, size, title, behavior } = button;
2145
- const getOnClick2 = () => {
2146
- if (!behavior) {
2147
- return () => {
2148
- };
2149
- }
2150
- if ("type" in behavior) {
2151
- switch (behavior.type) {
2152
- case "action": {
2153
- const action2 = inlineAction(behavior.action, step == null ? void 0 : step.actions);
2154
- return () => {
2155
- void onAction(action2);
2156
- };
2157
- }
2158
- case "link": {
2159
- const { url } = behavior;
2160
- return () => {
2161
- onLink(url);
2162
- };
2163
- }
2164
- default:
2165
- return () => {
2166
- };
2167
- }
2168
- }
2169
- const { action, link } = behavior;
2170
- const inlinedAction = action ? inlineAction(action, step == null ? void 0 : step.actions) : null;
2171
- if (inlinedAction) {
2172
- return () => {
2173
- void onAction(inlinedAction);
2174
- };
2175
- }
2176
- if (link) {
2177
- return () => {
2178
- onLink(link.url);
2179
- };
2180
- }
2181
- return () => {
2182
- };
2201
+ var _a;
2202
+ const { onBehavior } = mapperProps;
2203
+ const { context, control, disabled, margin = "md", pinOrder, size, title } = button;
2204
+ const behavior = getDomainLayerBehavior(button, (_a = mapperProps.step.actions) != null ? _a : []);
2205
+ const onClick = () => {
2206
+ void onBehavior(behavior);
2183
2207
  };
2184
2208
  return createButtonComponent({
2185
2209
  uid,
@@ -2190,16 +2214,16 @@ var buttonLayoutToComponentWithBehavior = (uid, button, mapperProps) => {
2190
2214
  pinOrder,
2191
2215
  size,
2192
2216
  title: title != null ? title : "",
2193
- onClick: getOnClick2()
2217
+ onClick
2194
2218
  });
2195
2219
  };
2196
2220
  var buttonLayoutToComponentWithAction = (uid, button, mapperProps) => {
2197
- const { onAction, step } = mapperProps;
2221
+ const { onBehavior, step } = mapperProps;
2198
2222
  const { context, control, disabled, margin = "md", pinOrder, size, title } = button;
2199
2223
  const { action } = button;
2200
2224
  const inlinedAction = action ? inlineAction(action, step == null ? void 0 : step.actions) : {};
2201
2225
  const onClick = () => {
2202
- void onAction(inlinedAction);
2226
+ void onBehavior({ type: "action", action: inlinedAction });
2203
2227
  };
2204
2228
  return createButtonComponent({
2205
2229
  uid,
@@ -2213,21 +2237,6 @@ var buttonLayoutToComponentWithAction = (uid, button, mapperProps) => {
2213
2237
  onClick
2214
2238
  });
2215
2239
  };
2216
- var buttonLayoutToComponentWithNoop = (uid, button) => {
2217
- const { context, control, disabled, margin = "md", pinOrder, size, title } = button;
2218
- return createButtonComponent({
2219
- uid,
2220
- context: mapLegacyContext(context != null ? context : "neutral"),
2221
- control,
2222
- disabled: disabled != null ? disabled : false,
2223
- margin,
2224
- pinOrder,
2225
- size,
2226
- title: title != null ? title : "",
2227
- onClick: () => {
2228
- }
2229
- });
2230
- };
2231
2240
  var getButtonTitle = ({ title, action }) => {
2232
2241
  var _a;
2233
2242
  return (_a = title != null ? title : action == null ? void 0 : action.title) != null ? _a : "";
@@ -2307,54 +2316,24 @@ var decisionLayoutToComponent = (uid, {
2307
2316
  margin = "md",
2308
2317
  options,
2309
2318
  title
2310
- }, mapperProps) => createDecisionComponent({
2319
+ }, { onBehavior, step }) => createDecisionComponent({
2311
2320
  uid,
2312
2321
  control,
2313
2322
  margin,
2314
2323
  options: options.map((option) => {
2315
- var _a;
2324
+ var _a, _b;
2325
+ const behavior = getDomainLayerBehavior(option, (_a = step.actions) != null ? _a : []);
2316
2326
  return __spreadProps(__spreadValues({}, option), {
2317
- disabled: (_a = option.disabled) != null ? _a : false,
2318
- href: getHref(option),
2327
+ disabled: (_b = option.disabled) != null ? _b : false,
2328
+ href: behavior.type === "link" ? behavior.url : void 0,
2319
2329
  image: mapSpecImage(option.image),
2320
- onClick: getOnClick(option, mapperProps)
2330
+ onClick: () => {
2331
+ void onBehavior(behavior);
2332
+ }
2321
2333
  });
2322
2334
  }),
2323
2335
  title
2324
2336
  });
2325
- var getHref = (option) => {
2326
- const { behavior } = option;
2327
- if (behavior && "type" in behavior && behavior.type === "link") {
2328
- return behavior.url;
2329
- }
2330
- return void 0;
2331
- };
2332
- var getOnClick = (option, { step, onAction, onLink }) => {
2333
- const { behavior } = option;
2334
- if (!behavior && option.action) {
2335
- const action = inlineAction(option.action, step == null ? void 0 : step.actions);
2336
- return () => {
2337
- void onAction(action);
2338
- };
2339
- }
2340
- if (behavior && "type" in behavior) {
2341
- switch (behavior.type) {
2342
- case "action": {
2343
- const action = inlineAction(behavior.action, step == null ? void 0 : step.actions);
2344
- return () => {
2345
- void onAction(action);
2346
- };
2347
- }
2348
- case "link": {
2349
- return () => {
2350
- void onLink(behavior.url);
2351
- };
2352
- }
2353
- }
2354
- }
2355
- return () => {
2356
- };
2357
- };
2358
2337
 
2359
2338
  // src/revamp/domain/components/DividerComponent.ts
2360
2339
  var createDividerComponent = (props) => __spreadProps(__spreadValues({
@@ -5364,9 +5343,9 @@ var createReviewComponent = (reviewProps) => __spreadProps(__spreadValues({
5364
5343
  });
5365
5344
 
5366
5345
  // src/revamp/domain/mappers/layout/reviewLayoutToComponent.ts
5367
- var reviewLayoutToComponent = (uid, { fields, title, callToAction, control, margin = "md", orientation, action }, { onAction, onLink }) => createReviewComponent({
5346
+ var reviewLayoutToComponent = (uid, { fields, title, callToAction, control, margin = "md", orientation, action }, { onBehavior, step }) => createReviewComponent({
5368
5347
  uid,
5369
- callToAction: getReviewAction({ onAction, onLink, callToAction, action }),
5348
+ callToAction: getReviewAction({ onBehavior, callToAction, action, stepActions: step.actions }),
5370
5349
  control: getOrientationControl({ control, orientation }),
5371
5350
  fields: fields.map((field) => {
5372
5351
  var _a;
@@ -5375,83 +5354,20 @@ var reviewLayoutToComponent = (uid, { fields, title, callToAction, control, marg
5375
5354
  margin,
5376
5355
  title
5377
5356
  });
5378
- var getReviewAction = ({ onAction, onLink, callToAction, action }) => {
5357
+ var getReviewAction = ({
5358
+ onBehavior,
5359
+ callToAction,
5360
+ action,
5361
+ stepActions = []
5362
+ }) => {
5379
5363
  if (callToAction) {
5380
- const { accessibilityDescription, action: ctaAction, behavior, title } = callToAction;
5381
- if (behavior) {
5382
- if ("type" in behavior) {
5383
- switch (behavior.type) {
5384
- case "action": {
5385
- const { action: behaviorAction2 } = behavior;
5386
- return {
5387
- accessibilityDescription,
5388
- title,
5389
- onClick: () => {
5390
- void onAction(behaviorAction2);
5391
- }
5392
- };
5393
- }
5394
- case "link": {
5395
- const { url } = behavior;
5396
- return {
5397
- accessibilityDescription,
5398
- href: url,
5399
- title,
5400
- onClick: () => {
5401
- onLink(url);
5402
- }
5403
- };
5404
- }
5405
- default:
5406
- return void 0;
5407
- }
5408
- }
5409
- const { action: behaviorAction, link } = behavior;
5410
- if (behaviorAction) {
5411
- return {
5412
- accessibilityDescription,
5413
- title,
5414
- onClick: () => {
5415
- void onAction(behaviorAction);
5416
- }
5417
- };
5418
- }
5419
- if (link) {
5420
- return {
5421
- accessibilityDescription,
5422
- href: link.url,
5423
- title,
5424
- onClick: () => {
5425
- onLink(link.url);
5426
- }
5427
- };
5428
- }
5429
- return {
5430
- accessibilityDescription,
5431
- title,
5432
- onClick: () => {
5433
- }
5434
- };
5435
- }
5436
- if (ctaAction) {
5437
- return {
5438
- title,
5439
- onClick: () => {
5440
- void onAction(ctaAction);
5441
- }
5442
- };
5443
- }
5444
- return {
5445
- title,
5446
- onClick: () => {
5447
- }
5448
- };
5364
+ return getDomainLayerCallToAction(callToAction, onBehavior, stepActions);
5449
5365
  }
5450
5366
  if (action == null ? void 0 : action.title) {
5451
5367
  return {
5452
5368
  title: action.title,
5453
5369
  onClick: () => {
5454
- void onAction(action);
5370
+ void onBehavior({ type: "action", action });
5455
5371
  }
5456
5372
  };
5457
5373
  }
@@ -5472,7 +5388,7 @@ var getOrientationControl = ({
5472
5388
 
5473
5389
  // src/revamp/domain/components/searchComponent/SearchComponent.ts
5474
5390
  var DEBOUNCE_TIME = 400;
5475
- var createSearchComponent = (searchProps, performSearch, onAction, updateComponent) => {
5391
+ var createSearchComponent = (searchProps, performSearch, onBehavior, updateComponent) => {
5476
5392
  const { uid, control, emptyMessage, margin, title } = searchProps;
5477
5393
  const update = getInputUpdateFunction(uid, updateComponent);
5478
5394
  let abortController = new AbortController();
@@ -5503,7 +5419,7 @@ var createSearchComponent = (searchProps, performSearch, onAction, updateCompone
5503
5419
  };
5504
5420
  const onSelect = ({ type, value }) => {
5505
5421
  if (type === "action") {
5506
- void onAction(value);
5422
+ void onBehavior({ type: "action", action: value });
5507
5423
  } else {
5508
5424
  update((draft) => {
5509
5425
  draft.query = value.query;
@@ -5593,7 +5509,7 @@ var hashRequest = (query, config) => JSON.stringify({ query, config });
5593
5509
 
5594
5510
  // src/revamp/domain/mappers/layout/searchLayoutToComponent.ts
5595
5511
  var searchLayoutToComponent = (uid, { control, emptyMessage = "", method, param, title, url, margin = "md" }, mapperProps) => {
5596
- const { httpClient, onAction, updateComponent } = mapperProps;
5512
+ const { httpClient, onBehavior, updateComponent } = mapperProps;
5597
5513
  const search = getPerformSearchFunction(httpClient, { method, param, url });
5598
5514
  return createSearchComponent(
5599
5515
  {
@@ -5604,7 +5520,7 @@ var searchLayoutToComponent = (uid, { control, emptyMessage = "", method, param,
5604
5520
  title
5605
5521
  },
5606
5522
  search,
5607
- onAction,
5523
+ onBehavior,
5608
5524
  updateComponent
5609
5525
  );
5610
5526
  };
@@ -5622,87 +5538,21 @@ var createStatusListComponent = (statusListProps) => __spreadProps(__spreadValue
5622
5538
  });
5623
5539
 
5624
5540
  // src/revamp/domain/mappers/layout/statusListLayoutToComponent.ts
5625
- var statusListLayoutToComponent = (uid, { control, items, margin = "md", title }, { onAction, onLink }) => createStatusListComponent({
5541
+ var statusListLayoutToComponent = (uid, { control, items, margin = "md", title }, { onBehavior, step }) => createStatusListComponent({
5626
5542
  uid,
5627
5543
  control,
5628
- items: items.map((item) => __spreadProps(__spreadValues({}, item), {
5629
- href: getItemHref(item.callToAction),
5630
- callToAction: getItemCallToAction(item.callToAction, onAction, onLink)
5631
- })),
5544
+ items: items.map((item) => {
5545
+ var _a;
5546
+ const callToAction = getDomainLayerCallToAction(
5547
+ item.callToAction,
5548
+ onBehavior,
5549
+ (_a = step.actions) != null ? _a : []
5550
+ );
5551
+ return __spreadProps(__spreadValues({}, item), { callToAction });
5552
+ }),
5632
5553
  margin,
5633
5554
  title
5634
5555
  });
5635
- var getItemHref = (callToAction) => {
5636
- var _a;
5637
- if (!callToAction) {
5638
- return void 0;
5639
- }
5640
- const { behavior } = callToAction;
5641
- if ("type" in behavior) {
5642
- return void 0;
5643
- }
5644
- return (_a = behavior == null ? void 0 : behavior.link) == null ? void 0 : _a.url;
5645
- };
5646
- var getItemCallToAction = (callToAction, onAction, onLink) => {
5647
- if (!callToAction) {
5648
- return void 0;
5649
- }
5650
- const { accessibilityDescription, behavior, title } = callToAction;
5651
- if ("type" in behavior) {
5652
- switch (behavior.type) {
5653
- case "action": {
5654
- const { action } = behavior;
5655
- return {
5656
- accessibilityDescription,
5657
- title,
5658
- onClick: () => {
5659
- void onAction(action);
5660
- }
5661
- };
5662
- }
5663
- case "link": {
5664
- const { url } = behavior;
5665
- return {
5666
- accessibilityDescription,
5667
- href: url,
5668
- title,
5669
- onClick: () => {
5670
- void onLink(url);
5671
- }
5672
- };
5673
- }
5674
- default:
5675
- return void 0;
5676
- }
5677
- }
5678
- if (behavior.action) {
5679
- const { action } = behavior;
5680
- return {
5681
- accessibilityDescription,
5682
- title,
5683
- onClick: () => {
5684
- void onAction(action);
5685
- }
5686
- };
5687
- }
5688
- if (behavior.link) {
5689
- const { url } = behavior.link;
5690
- return {
5691
- accessibilityDescription,
5692
- href: url,
5693
- title,
5694
- onClick: () => {
5695
- void onLink(url);
5696
- }
5697
- };
5698
- }
5699
- return {
5700
- accessibilityDescription,
5701
- title,
5702
- onClick: () => {
5703
- }
5704
- };
5705
- };
5706
5556
 
5707
5557
  // src/revamp/domain/mappers/layout/deprecatedListLayoutToComponent.ts
5708
5558
  var deprecatedListLayoutToComponent = (uid, { control, items, margin = "md", title }) => createStatusListComponent({
@@ -5742,48 +5592,19 @@ var createListComponent = (listProps) => __spreadProps(__spreadValues({
5742
5592
  });
5743
5593
 
5744
5594
  // src/revamp/domain/mappers/layout/listLayoutToComponent.ts
5745
- var listLayoutToComponent = (uid, { callToAction, control, items, margin = "md", title }, mapperProps) => createListComponent({
5746
- uid,
5747
- control,
5748
- items: items.map((item) => __spreadProps(__spreadValues({}, item), {
5749
- image: mapSpecImage(item.image)
5750
- })),
5751
- callToAction: getListCallToAction(callToAction, mapperProps),
5752
- margin,
5753
- title
5754
- });
5755
- var getListCallToAction = (callToAction, { onAction, onLink }) => {
5756
- if (!callToAction) {
5757
- return void 0;
5758
- }
5759
- const { accessibilityDescription, behavior, title } = callToAction;
5760
- if ("type" in behavior) {
5761
- switch (behavior.type) {
5762
- case "action": {
5763
- const { action } = behavior;
5764
- return {
5765
- type: "action",
5766
- accessibilityDescription,
5767
- title,
5768
- onClick: () => {
5769
- void onAction(action);
5770
- }
5771
- };
5772
- }
5773
- case "link": {
5774
- return {
5775
- type: "link",
5776
- accessibilityDescription,
5777
- href: behavior.url,
5778
- title,
5779
- onClick: () => {
5780
- void onLink(behavior.url);
5781
- }
5782
- };
5783
- }
5784
- }
5785
- }
5786
- return void 0;
5595
+ var listLayoutToComponent = (uid, { callToAction, control, items, margin = "md", title }, mapperProps) => {
5596
+ var _a;
5597
+ const { step, onBehavior } = mapperProps;
5598
+ return createListComponent({
5599
+ uid,
5600
+ control,
5601
+ items: items.map((item) => __spreadProps(__spreadValues({}, item), {
5602
+ image: mapSpecImage(item.image)
5603
+ })),
5604
+ callToAction: getDomainLayerCallToAction(callToAction, onBehavior, (_a = step.actions) != null ? _a : []),
5605
+ margin,
5606
+ title
5607
+ });
5787
5608
  };
5788
5609
 
5789
5610
  // src/revamp/domain/mappers/mapLayoutToComponent.ts
@@ -5868,22 +5689,6 @@ var getUnreferencedSchemas = (step) => {
5868
5689
  );
5869
5690
  };
5870
5691
 
5871
- // src/revamp/domain/features/refreshAfter/getStepRefreshAfter.ts
5872
- var ONE_SECOND = 1e3;
5873
- var getStepRefreshAfter = ({ refreshAfter, onRefresh }) => {
5874
- const targetTime = new Date(refreshAfter).getTime();
5875
- if (typeof refreshAfter !== "string" || Number.isNaN(targetTime)) {
5876
- throw new Error(`Invalid refreshAfter value: ${String(refreshAfter)}`);
5877
- }
5878
- const timeLeft = Math.max(targetTime - Date.now(), ONE_SECOND);
5879
- const timeout = setTimeout(() => {
5880
- void onRefresh("refreshAfter");
5881
- }, timeLeft);
5882
- return {
5883
- stop: () => clearTimeout(timeout)
5884
- };
5885
- };
5886
-
5887
5692
  // src/revamp/domain/mappers/mapStepToComponent.ts
5888
5693
  var mapStepToComponent = (_a) => {
5889
5694
  var _b = _a, {
@@ -5891,13 +5696,15 @@ var mapStepToComponent = (_a) => {
5891
5696
  loadingState,
5892
5697
  displayStepTitle,
5893
5698
  trackEvent,
5894
- onPoll
5699
+ onPoll,
5700
+ onBehavior
5895
5701
  } = _b, restProps = __objRest(_b, [
5896
5702
  "uid",
5897
5703
  "loadingState",
5898
5704
  "displayStepTitle",
5899
5705
  "trackEvent",
5900
- "onPoll"
5706
+ "onPoll",
5707
+ "onBehavior"
5901
5708
  ]);
5902
5709
  var _a2, _b2;
5903
5710
  const { step, updateComponent } = restProps;
@@ -5918,7 +5725,10 @@ var mapStepToComponent = (_a) => {
5918
5725
  const back = backNavigation ? {
5919
5726
  title: backNavigation.title,
5920
5727
  onClick: () => {
5921
- void restProps.onAction(__spreadProps(__spreadValues({}, backNavigation.action), { skipValidation: true }));
5728
+ void onBehavior({
5729
+ type: "action",
5730
+ action: __spreadProps(__spreadValues({}, backNavigation.action), { skipValidation: true })
5731
+ });
5922
5732
  }
5923
5733
  } : void 0;
5924
5734
  const refreshUrl = (_b2 = step.refreshUrl) != null ? _b2 : step.refreshFormUrl;
@@ -5927,24 +5737,10 @@ var mapStepToComponent = (_a) => {
5927
5737
  throw new Error("Step must have an id or a key");
5928
5738
  }
5929
5739
  const uid = `${rootUid}.${stepId != null ? stepId : "step"}`;
5930
- const onAction = async (action) => {
5931
- try {
5932
- await stepComponent.getSubmittableValue();
5933
- const skipValidation = action.method === "GET" || Boolean(action.skipValidation);
5934
- const canSubmit = skipValidation || stepComponent.validate();
5935
- if (canSubmit) {
5936
- void restProps.onAction(action);
5937
- }
5938
- } catch (e) {
5939
- if (true) {
5940
- console.log("\u274C:", "Failed to get submittable data");
5941
- }
5942
- }
5943
- };
5944
5740
  const onRefresh = async (schemaId, url) => restProps.onRefresh(schemaId, url != null ? url : refreshUrl);
5945
- const stepPolling = polling ? getStepPolling({ pollingConfig: polling, onAction: restProps.onAction, onPoll }) : void 0;
5741
+ const stepPolling = polling ? getStepPolling({ pollingConfig: polling, onBehavior, onPoll }) : void 0;
5946
5742
  const stepRefreshAfter = refreshAfter ? getStepRefreshAfter({ refreshAfter, onRefresh }) : void 0;
5947
- const mapperProps = __spreadProps(__spreadValues({}, restProps), { trackEvent, onAction, onRefresh });
5743
+ const mapperProps = __spreadProps(__spreadValues({}, restProps), { trackEvent, onBehavior, onRefresh });
5948
5744
  const unreferencedSchemaFormComponents = mapUnreferencedSchemas(mapperProps);
5949
5745
  const layoutComponents = layout.map(
5950
5746
  (layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, mapperProps)
@@ -5965,7 +5761,7 @@ var mapStepToComponent = (_a) => {
5965
5761
  step,
5966
5762
  updateComponent,
5967
5763
  trackEvent,
5968
- onAction
5764
+ onBehavior
5969
5765
  });
5970
5766
  return stepComponent;
5971
5767
  };
@@ -6006,7 +5802,7 @@ function assertDFResponseType(type) {
6006
5802
 
6007
5803
  // src/revamp/flow/executePoll.ts
6008
5804
  var executePoll = async (props) => {
6009
- const { errorAction, signal, url, httpClient, trackEvent } = props;
5805
+ const { errorBehavior, signal, url, httpClient, trackEvent } = props;
6010
5806
  try {
6011
5807
  const response = await httpClient(url != null ? url : "", {
6012
5808
  method: "GET",
@@ -6014,7 +5810,7 @@ var executePoll = async (props) => {
6014
5810
  });
6015
5811
  if (!response.ok) {
6016
5812
  trackEvent("Polling Failed", { url, statusCode: response.status, variant: "revamp" });
6017
- return { type: "action", action: errorAction };
5813
+ return { type: "behavior", behavior: errorBehavior };
6018
5814
  }
6019
5815
  const responseType = getResponseTypeFromHeader(response);
6020
5816
  const body = await parseResponseBodyAsJsonElement(response);
@@ -6030,19 +5826,19 @@ var executePoll = async (props) => {
6030
5826
  }
6031
5827
  case "action": {
6032
5828
  assertActionResponseBody(body);
6033
- return { type: "action", action: body.action };
5829
+ return { type: "behavior", behavior: { type: "action", action: body.action } };
6034
5830
  }
6035
5831
  default: {
6036
5832
  if (isActionResponseBody(body)) {
6037
- return { type: "action", action: body.action };
5833
+ return { type: "behavior", behavior: { type: "action", action: body.action } };
6038
5834
  }
6039
5835
  return { type: "continue" };
6040
5836
  }
6041
5837
  }
6042
- } catch (error) {
6043
- return { type: "action", action: errorAction };
5838
+ } catch (e) {
5839
+ return { type: "behavior", behavior: errorBehavior };
6044
5840
  }
6045
- } catch (error) {
5841
+ } catch (e) {
6046
5842
  return { type: "continue" };
6047
5843
  }
6048
5844
  };
@@ -6421,48 +6217,6 @@ function useStableCallback(handler) {
6421
6217
  return useCallback((...args) => ref.current ? ref.current(...args) : null, []);
6422
6218
  }
6423
6219
 
6424
- // src/revamp/domain/components/RootDomainComponent.ts
6425
- var createRootDomainComponent = () => ({
6426
- type: "root",
6427
- uid: "root",
6428
- stepComponent: null,
6429
- getChildren() {
6430
- return this.stepComponent ? [this.stepComponent] : [];
6431
- },
6432
- getLocalValue() {
6433
- return this.stepComponent ? this.stepComponent.getLocalValue() : null;
6434
- },
6435
- async getSubmittableValue() {
6436
- return this.stepComponent ? this.stepComponent.getSubmittableValue() : null;
6437
- },
6438
- getSubmittableValueSync() {
6439
- return this.stepComponent ? this.stepComponent.getSubmittableValueSync() : null;
6440
- },
6441
- getSummary() {
6442
- return this.stepComponent ? this.stepComponent.getSummary() : {};
6443
- },
6444
- validate() {
6445
- return this.stepComponent ? this.stepComponent.validate() : false;
6446
- },
6447
- setLoadingState(loadingState) {
6448
- var _a;
6449
- (_a = this.stepComponent) == null ? void 0 : _a.setLoadingState(loadingState);
6450
- },
6451
- getLoadingState() {
6452
- return this.stepComponent ? this.stepComponent.loadingState : "initial";
6453
- },
6454
- getTrackEvent() {
6455
- return this.stepComponent ? this.stepComponent.trackEvent : null;
6456
- },
6457
- hasStep() {
6458
- return Boolean(this.stepComponent);
6459
- },
6460
- stop() {
6461
- var _a;
6462
- (_a = this.stepComponent) == null ? void 0 : _a.stop();
6463
- }
6464
- });
6465
-
6466
6220
  // src/revamp/useDynamicFlowCore.tsx
6467
6221
  function useDynamicFlowCore(props) {
6468
6222
  const _a = props, { flowId, initialAction, initialStep, displayStepTitle = true } = _a, rest = __objRest(_a, ["flowId", "initialAction", "initialStep", "displayStepTitle"]);
@@ -6543,10 +6297,9 @@ function useDynamicFlowCore(props) {
6543
6297
  trackEvent,
6544
6298
  logEvent,
6545
6299
  httpClient,
6546
- onAction,
6300
+ onBehavior,
6547
6301
  onRefresh,
6548
6302
  onPoll,
6549
- onLink,
6550
6303
  onValueChange
6551
6304
  });
6552
6305
  updateComponent(rootComponentRef.current.uid, (draft) => {
@@ -6600,6 +6353,36 @@ function useDynamicFlowCore(props) {
6600
6353
  // eslint-disable-next-line react-hooks/exhaustive-deps
6601
6354
  []
6602
6355
  );
6356
+ const onBehavior = useCallback2(async (behavior) => {
6357
+ switch (behavior.type) {
6358
+ case "action": {
6359
+ try {
6360
+ const { action } = behavior;
6361
+ await rootComponentRef.current.getSubmittableValue();
6362
+ const skipValidation2 = action.method === "GET" || Boolean(action.skipValidation);
6363
+ const canSubmit = skipValidation2 || rootComponentRef.current.validate();
6364
+ if (canSubmit) {
6365
+ void onAction(action);
6366
+ }
6367
+ } catch (e) {
6368
+ if (true) {
6369
+ console.log("\u274C:", "Failed to get submittable data");
6370
+ }
6371
+ }
6372
+ break;
6373
+ }
6374
+ case "link": {
6375
+ onLink(behavior.url);
6376
+ break;
6377
+ }
6378
+ // case 'modal':
6379
+ // return undefined;
6380
+ // case 'dismiss':
6381
+ // return undefined;
6382
+ case "none":
6383
+ break;
6384
+ }
6385
+ }, []);
6603
6386
  const onAction = useCallback2(async (action) => {
6604
6387
  var _a2;
6605
6388
  try {
@@ -6708,11 +6491,11 @@ function useDynamicFlowCore(props) {
6708
6491
  []
6709
6492
  );
6710
6493
  const onPoll = useCallback2(
6711
- async (url, errorAction, signal) => {
6494
+ async (url, errorBehavior, signal) => {
6712
6495
  const command = await executePoll({
6713
6496
  httpClient,
6714
6497
  url,
6715
- errorAction,
6498
+ errorBehavior,
6716
6499
  signal,
6717
6500
  trackEvent: trackCoreEvent
6718
6501
  });
@@ -6720,8 +6503,8 @@ function useDynamicFlowCore(props) {
6720
6503
  case "replace-step":
6721
6504
  createStep(command.step, command.etag);
6722
6505
  return true;
6723
- case "action":
6724
- void onAction(command.action);
6506
+ case "behavior":
6507
+ void onBehavior(command.behavior);
6725
6508
  return true;
6726
6509
  case "complete":
6727
6510
  onCompletion(command.result);
@@ -11709,7 +11492,7 @@ function DynamicReview({ component: review, onAction }) {
11709
11492
  const { action: behaviorAction2 } = behavior;
11710
11493
  return {
11711
11494
  text: title != null ? title : "",
11712
- onClick: behaviorAction2 ? getOnClick2(behaviorAction2) : void 0
11495
+ onClick: behaviorAction2 ? getOnClick(behaviorAction2) : void 0
11713
11496
  };
11714
11497
  }
11715
11498
  case "link": {
@@ -11724,7 +11507,7 @@ function DynamicReview({ component: review, onAction }) {
11724
11507
  if (behaviorAction) {
11725
11508
  return {
11726
11509
  text: title != null ? title : "",
11727
- onClick: behaviorAction ? getOnClick2(behaviorAction) : void 0
11510
+ onClick: behaviorAction ? getOnClick(behaviorAction) : void 0
11728
11511
  };
11729
11512
  }
11730
11513
  if (link) {
@@ -11736,10 +11519,10 @@ function DynamicReview({ component: review, onAction }) {
11736
11519
  }
11737
11520
  return {
11738
11521
  text: title != null ? title : "",
11739
- onClick: action ? getOnClick2(action) : void 0
11522
+ onClick: action ? getOnClick(action) : void 0
11740
11523
  };
11741
11524
  };
11742
- const getOnClick2 = (action) => {
11525
+ const getOnClick = (action) => {
11743
11526
  return (event) => {
11744
11527
  event.preventDefault();
11745
11528
  if (action) {
@@ -11749,7 +11532,7 @@ function DynamicReview({ component: review, onAction }) {
11749
11532
  };
11750
11533
  const orientation = getDefinitionListLayout(review);
11751
11534
  const callToAction = review.callToAction ? getReviewAction2(review.callToAction) : null;
11752
- const legacyCallToAction = !callToAction && review.action ? { text: (_a = review.action.title) != null ? _a : "", onClick: getOnClick2(review.action) } : null;
11535
+ const legacyCallToAction = !callToAction && review.action ? { text: (_a = review.action.title) != null ? _a : "", onClick: getOnClick(review.action) } : null;
11753
11536
  return /* @__PURE__ */ jsxs19("div", { className: margin, children: [
11754
11537
  review.title && /* @__PURE__ */ jsx57(Header8, { title: review.title, action: (_b = callToAction != null ? callToAction : legacyCallToAction) != null ? _b : void 0 }),
11755
11538
  /* @__PURE__ */ jsx57("div", { className: margin, children: /* @__PURE__ */ jsx57(DefinitionList2, { layout: orientation, definitions: getDefinitions(orientation, review) }) })
@@ -13807,14 +13590,14 @@ var DynamicFlowComponent = ({
13807
13590
  dispatchEventAndComplete(action.result);
13808
13591
  return;
13809
13592
  }
13810
- const { data, method, skipValidation } = action;
13593
+ const { data, method, skipValidation: skipValidation2 } = action;
13811
13594
  const submissionData = __spreadValues(__spreadValues({}, combineModels2(models)), data);
13812
13595
  if (isSubmissionMethod(method)) {
13813
13596
  setFormErrors(null);
13814
- if (!skipValidation) {
13597
+ if (!skipValidation2) {
13815
13598
  setSubmitted(true);
13816
13599
  }
13817
- if (modelIsValid || skipValidation) {
13600
+ if (modelIsValid || skipValidation2) {
13818
13601
  await performAction(action, submissionData);
13819
13602
  }
13820
13603
  } else {