@wise/dynamic-flow-client 5.23.0 → 5.24.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
@@ -1204,6 +1204,15 @@ var createRootDomainComponent = (onComponentUpdate, scrollToTop, backConfig, req
1204
1204
  const navigation = (_a = component.getStep()) == null ? void 0 : _a.step.navigation;
1205
1205
  const stepHasBehavior = Boolean((_b = navigation == null ? void 0 : navigation.back) != null ? _b : navigation == null ? void 0 : navigation.backButton);
1206
1206
  return component.backConfig.isFlowCancellable || component.stepStack.length > 1 && component.backConfig.isNativeBackEnabled || stepHasBehavior;
1207
+ },
1208
+ startDelay(delay) {
1209
+ var _a, _b;
1210
+ return (_b = (_a = component.getStep()) == null ? void 0 : _a.startDelay(delay)) != null ? _b : { abort: () => {
1211
+ } };
1212
+ },
1213
+ setExternalConfirmation(external) {
1214
+ var _a;
1215
+ (_a = component.getStep()) == null ? void 0 : _a.setExternalConfirmation(external);
1207
1216
  }
1208
1217
  };
1209
1218
  return component;
@@ -1346,10 +1355,10 @@ var normaliseBehavior = (behavior, stepActions) => {
1346
1355
  });
1347
1356
  }
1348
1357
  if (behavior.type === "delay") {
1349
- return {
1350
- type: "none",
1358
+ return __spreadProps(__spreadValues({}, behavior), {
1359
+ behavior: normaliseBehavior(behavior.behavior, stepActions),
1351
1360
  track: false
1352
- };
1361
+ });
1353
1362
  }
1354
1363
  if (behavior.type === "dispatch-event") {
1355
1364
  return {
@@ -1903,13 +1912,13 @@ var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, ma
1903
1912
  return component;
1904
1913
  };
1905
1914
  var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1906
- var _a, _b, _c;
1915
+ const { sections, filters, beforeSections, afterSections, nextCursor } = specState;
1907
1916
  return {
1908
- sections: specState.sections.map((section) => {
1909
- var _a2;
1917
+ sections: sections.map((section) => {
1918
+ var _a;
1910
1919
  return __spreadProps(__spreadValues({}, section), {
1911
1920
  callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
1912
- help: (_a2 = section.help) == null ? void 0 : _a2.markdown,
1921
+ help: (_a = section.help) == null ? void 0 : _a.markdown,
1913
1922
  inlineAlert: mapInlineAlert(section.inlineAlert),
1914
1923
  items: section.items.map((item) => {
1915
1924
  const behavior = getDomainLayerBehavior(
@@ -1928,10 +1937,10 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1928
1937
  })
1929
1938
  });
1930
1939
  }),
1931
- filters: (_a = specState.filters) == null ? void 0 : _a.map(mapFilter),
1932
- beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
1933
- afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
1934
- nextCursor: specState.nextCursor
1940
+ filters: filters == null ? void 0 : filters.map(mapFilter),
1941
+ beforeSections: beforeSections == null ? void 0 : beforeSections.map(mapLayout),
1942
+ afterSections: afterSections == null ? void 0 : afterSections.map(mapLayout),
1943
+ nextCursor
1935
1944
  };
1936
1945
  };
1937
1946
  var mapFilter = (filter) => {
@@ -3049,6 +3058,45 @@ var getSubmittableData = async (components) => Promise.all(components.map(async
3049
3058
  var getSubmittableDataSync = (components) => components.map((component) => component.getSubmittableValueSync()).reduce((acc, value) => recursiveMerge(acc, value), null);
3050
3059
  var getLocalValues = (components) => components.map((component) => component.getLocalValue()).reduce((acc, value) => recursiveMerge(acc, value), null);
3051
3060
 
3061
+ // src/domain/features/delay/getStepDelays.ts
3062
+ var getStepDelays = (onEmpty) => {
3063
+ let timeouts = [];
3064
+ const remove = (timeout) => {
3065
+ timeouts = timeouts.filter((pendingTimeout) => pendingTimeout !== timeout);
3066
+ };
3067
+ return {
3068
+ start({ duration, execute }) {
3069
+ const timeout = setTimeout(() => {
3070
+ if (timeouts.includes(timeout)) {
3071
+ remove(timeout);
3072
+ execute();
3073
+ }
3074
+ if (timeouts.length === 0) {
3075
+ onEmpty();
3076
+ }
3077
+ }, duration * 1e3);
3078
+ timeouts = [...timeouts, timeout];
3079
+ return {
3080
+ abort: () => {
3081
+ clearTimeout(timeout);
3082
+ remove(timeout);
3083
+ if (timeouts.length === 0) {
3084
+ onEmpty();
3085
+ }
3086
+ }
3087
+ };
3088
+ },
3089
+ stop() {
3090
+ if (timeouts.length === 0) {
3091
+ return;
3092
+ }
3093
+ timeouts.forEach(clearTimeout);
3094
+ timeouts = [];
3095
+ onEmpty();
3096
+ }
3097
+ };
3098
+ };
3099
+
3052
3100
  // src/domain/components/step/StepDomainComponent.ts
3053
3101
  var createStepComponent = (props) => {
3054
3102
  const _a = props, {
@@ -3071,6 +3119,14 @@ var createStepComponent = (props) => {
3071
3119
  "onLoad"
3072
3120
  ]);
3073
3121
  const update = getInputUpdateFunction(onComponentUpdate);
3122
+ const resetDelayState = () => {
3123
+ if (component.loadingState === "delay-pending") {
3124
+ update(component, (draft) => {
3125
+ draft.loadingState = "idle";
3126
+ });
3127
+ }
3128
+ };
3129
+ const stepDelays = getStepDelays(resetDelayState);
3074
3130
  const component = __spreadProps(__spreadValues({
3075
3131
  uid
3076
3132
  }, rest), {
@@ -3120,6 +3176,10 @@ var createStepComponent = (props) => {
3120
3176
  draft.loadingState = loadingState;
3121
3177
  });
3122
3178
  },
3179
+ startDelay(delay) {
3180
+ component.setLoadingState("delay-pending");
3181
+ return stepDelays.start(delay);
3182
+ },
3123
3183
  addSubflow(subflow) {
3124
3184
  update(component, (draft) => {
3125
3185
  draft.subflow = subflow;
@@ -3147,11 +3207,17 @@ var createStepComponent = (props) => {
3147
3207
  stop() {
3148
3208
  stepPolling == null ? void 0 : stepPolling.stop();
3149
3209
  stepRefreshAfter == null ? void 0 : stepRefreshAfter.stop();
3210
+ stepDelays.stop();
3150
3211
  stepPrefetch.stop();
3151
3212
  update(component, (draft) => {
3152
3213
  draft.state = "stopped";
3153
3214
  draft.modals = [];
3154
3215
  });
3216
+ },
3217
+ setExternalConfirmation(external) {
3218
+ update(component, (draft) => {
3219
+ draft.externalConfirmation = external;
3220
+ });
3155
3221
  }
3156
3222
  });
3157
3223
  return component;
@@ -7537,6 +7603,14 @@ var createFlowController = (props) => {
7537
7603
  var _a;
7538
7604
  trackBehaviorTriggered(trackEvent, behavior);
7539
7605
  switch (behavior.type) {
7606
+ case "delay": {
7607
+ return rootComponent.startDelay({
7608
+ duration: behavior.duration,
7609
+ execute: () => {
7610
+ void onBehavior(behavior.behavior);
7611
+ }
7612
+ });
7613
+ }
7540
7614
  case "download": {
7541
7615
  try {
7542
7616
  await executeDownload(behavior.request, httpClient);
@@ -7607,7 +7681,14 @@ var createFlowController = (props) => {
7607
7681
  };
7608
7682
  }
7609
7683
  case "link": {
7610
- onLink(behavior.url);
7684
+ rootComponent.setExternalConfirmation(
7685
+ createExternalConfirmation(
7686
+ `${rootComponent.uid}-external-confirmation`,
7687
+ behavior.url,
7688
+ onLink,
7689
+ onChange
7690
+ )
7691
+ );
7611
7692
  break;
7612
7693
  }
7613
7694
  case "modal": {
@@ -8307,17 +8388,18 @@ var mapBoxControl = ({
8307
8388
 
8308
8389
  // src/renderers/mappers/collectionComponentToProps.ts
8309
8390
  var collectionComponentToProps = (component, rendererMapperProps) => {
8310
- var _a, _b, _c;
8311
- const beforeSectionsProps = (_a = component.state.beforeSections) == null ? void 0 : _a.map(
8391
+ var _a, _b, _c, _d, _e;
8392
+ const { render } = rendererMapperProps;
8393
+ const beforeSectionsProps = (_b = (_a = component.state.beforeSections) == null ? void 0 : _a.map(
8312
8394
  (child) => componentToRendererProps(child, rendererMapperProps)
8313
- );
8314
- const afterSectionsProps = (_b = component.state.afterSections) == null ? void 0 : _b.map(
8395
+ )) != null ? _b : [];
8396
+ const afterSectionsProps = (_d = (_c = component.state.afterSections) == null ? void 0 : _c.map(
8315
8397
  (child) => componentToRendererProps(child, rendererMapperProps)
8316
- );
8398
+ )) != null ? _d : [];
8317
8399
  return __spreadProps(__spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "tags")), rendererMapperProps), {
8318
8400
  status: component.status,
8319
8401
  state: __spreadProps(__spreadValues({}, component.state), {
8320
- filters: (_c = component.state.filters) != null ? _c : [],
8402
+ filters: (_e = component.state.filters) != null ? _e : [],
8321
8403
  sections: component.state.sections.map((section) => __spreadProps(__spreadValues({}, section), {
8322
8404
  callToAction: mapCallToActionOptional(section.callToAction),
8323
8405
  items: section.items.map((item) => __spreadProps(__spreadValues({}, item), {
@@ -8327,9 +8409,9 @@ var collectionComponentToProps = (component, rendererMapperProps) => {
8327
8409
  }))
8328
8410
  })),
8329
8411
  beforeSectionsProps,
8330
- beforeSections: beforeSectionsProps == null ? void 0 : beforeSectionsProps.map(rendererMapperProps.render),
8412
+ beforeSections: beforeSectionsProps.map(render),
8331
8413
  afterSectionsProps,
8332
- afterSections: afterSectionsProps == null ? void 0 : afterSectionsProps.map(rendererMapperProps.render)
8414
+ afterSections: afterSectionsProps.map(render)
8333
8415
  })
8334
8416
  });
8335
8417
  };
@@ -9195,6 +9277,9 @@ var rootComponentToProps = (rootComponent, rendererMapperProps, nativeSubflowHan
9195
9277
  }, rendererMapperProps);
9196
9278
  };
9197
9279
 
9280
+ // src/renderers/mappers/utils/mapRendererLoadingState.ts
9281
+ var mapRendererLoadingState = (loadingState) => loadingState === "delay-pending" ? "submitting" : loadingState;
9282
+
9198
9283
  // src/renderers/subflow/getNativeSubflowRenderer.tsx
9199
9284
  var import_jsx_runtime7 = require("react/jsx-runtime");
9200
9285
  var getNativeSubflowRenderer = (handlers) => {
@@ -9311,7 +9396,7 @@ function useDynamicFlow(props) {
9311
9396
  httpClient,
9312
9397
  trackEvent: (_b = rootComponent.getTrackEvent()) != null ? _b : (() => {
9313
9398
  }),
9314
- stepLoadingState: rootComponent.getLoadingState()
9399
+ stepLoadingState: mapRendererLoadingState(rootComponent.getLoadingState())
9315
9400
  },
9316
9401
  (_c = props.nativeSubflowHandlers) != null ? _c : []
9317
9402
  );
package/build/main.mjs CHANGED
@@ -1173,6 +1173,15 @@ var createRootDomainComponent = (onComponentUpdate, scrollToTop, backConfig, req
1173
1173
  const navigation = (_a = component.getStep()) == null ? void 0 : _a.step.navigation;
1174
1174
  const stepHasBehavior = Boolean((_b = navigation == null ? void 0 : navigation.back) != null ? _b : navigation == null ? void 0 : navigation.backButton);
1175
1175
  return component.backConfig.isFlowCancellable || component.stepStack.length > 1 && component.backConfig.isNativeBackEnabled || stepHasBehavior;
1176
+ },
1177
+ startDelay(delay) {
1178
+ var _a, _b;
1179
+ return (_b = (_a = component.getStep()) == null ? void 0 : _a.startDelay(delay)) != null ? _b : { abort: () => {
1180
+ } };
1181
+ },
1182
+ setExternalConfirmation(external) {
1183
+ var _a;
1184
+ (_a = component.getStep()) == null ? void 0 : _a.setExternalConfirmation(external);
1176
1185
  }
1177
1186
  };
1178
1187
  return component;
@@ -1315,10 +1324,10 @@ var normaliseBehavior = (behavior, stepActions) => {
1315
1324
  });
1316
1325
  }
1317
1326
  if (behavior.type === "delay") {
1318
- return {
1319
- type: "none",
1327
+ return __spreadProps(__spreadValues({}, behavior), {
1328
+ behavior: normaliseBehavior(behavior.behavior, stepActions),
1320
1329
  track: false
1321
- };
1330
+ });
1322
1331
  }
1323
1332
  if (behavior.type === "dispatch-event") {
1324
1333
  return {
@@ -1872,13 +1881,13 @@ var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, ma
1872
1881
  return component;
1873
1882
  };
1874
1883
  var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1875
- var _a, _b, _c;
1884
+ const { sections, filters, beforeSections, afterSections, nextCursor } = specState;
1876
1885
  return {
1877
- sections: specState.sections.map((section) => {
1878
- var _a2;
1886
+ sections: sections.map((section) => {
1887
+ var _a;
1879
1888
  return __spreadProps(__spreadValues({}, section), {
1880
1889
  callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
1881
- help: (_a2 = section.help) == null ? void 0 : _a2.markdown,
1890
+ help: (_a = section.help) == null ? void 0 : _a.markdown,
1882
1891
  inlineAlert: mapInlineAlert(section.inlineAlert),
1883
1892
  items: section.items.map((item) => {
1884
1893
  const behavior = getDomainLayerBehavior(
@@ -1897,10 +1906,10 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1897
1906
  })
1898
1907
  });
1899
1908
  }),
1900
- filters: (_a = specState.filters) == null ? void 0 : _a.map(mapFilter),
1901
- beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
1902
- afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
1903
- nextCursor: specState.nextCursor
1909
+ filters: filters == null ? void 0 : filters.map(mapFilter),
1910
+ beforeSections: beforeSections == null ? void 0 : beforeSections.map(mapLayout),
1911
+ afterSections: afterSections == null ? void 0 : afterSections.map(mapLayout),
1912
+ nextCursor
1904
1913
  };
1905
1914
  };
1906
1915
  var mapFilter = (filter) => {
@@ -3018,6 +3027,45 @@ var getSubmittableData = async (components) => Promise.all(components.map(async
3018
3027
  var getSubmittableDataSync = (components) => components.map((component) => component.getSubmittableValueSync()).reduce((acc, value) => recursiveMerge(acc, value), null);
3019
3028
  var getLocalValues = (components) => components.map((component) => component.getLocalValue()).reduce((acc, value) => recursiveMerge(acc, value), null);
3020
3029
 
3030
+ // src/domain/features/delay/getStepDelays.ts
3031
+ var getStepDelays = (onEmpty) => {
3032
+ let timeouts = [];
3033
+ const remove = (timeout) => {
3034
+ timeouts = timeouts.filter((pendingTimeout) => pendingTimeout !== timeout);
3035
+ };
3036
+ return {
3037
+ start({ duration, execute }) {
3038
+ const timeout = setTimeout(() => {
3039
+ if (timeouts.includes(timeout)) {
3040
+ remove(timeout);
3041
+ execute();
3042
+ }
3043
+ if (timeouts.length === 0) {
3044
+ onEmpty();
3045
+ }
3046
+ }, duration * 1e3);
3047
+ timeouts = [...timeouts, timeout];
3048
+ return {
3049
+ abort: () => {
3050
+ clearTimeout(timeout);
3051
+ remove(timeout);
3052
+ if (timeouts.length === 0) {
3053
+ onEmpty();
3054
+ }
3055
+ }
3056
+ };
3057
+ },
3058
+ stop() {
3059
+ if (timeouts.length === 0) {
3060
+ return;
3061
+ }
3062
+ timeouts.forEach(clearTimeout);
3063
+ timeouts = [];
3064
+ onEmpty();
3065
+ }
3066
+ };
3067
+ };
3068
+
3021
3069
  // src/domain/components/step/StepDomainComponent.ts
3022
3070
  var createStepComponent = (props) => {
3023
3071
  const _a = props, {
@@ -3040,6 +3088,14 @@ var createStepComponent = (props) => {
3040
3088
  "onLoad"
3041
3089
  ]);
3042
3090
  const update = getInputUpdateFunction(onComponentUpdate);
3091
+ const resetDelayState = () => {
3092
+ if (component.loadingState === "delay-pending") {
3093
+ update(component, (draft) => {
3094
+ draft.loadingState = "idle";
3095
+ });
3096
+ }
3097
+ };
3098
+ const stepDelays = getStepDelays(resetDelayState);
3043
3099
  const component = __spreadProps(__spreadValues({
3044
3100
  uid
3045
3101
  }, rest), {
@@ -3089,6 +3145,10 @@ var createStepComponent = (props) => {
3089
3145
  draft.loadingState = loadingState;
3090
3146
  });
3091
3147
  },
3148
+ startDelay(delay) {
3149
+ component.setLoadingState("delay-pending");
3150
+ return stepDelays.start(delay);
3151
+ },
3092
3152
  addSubflow(subflow) {
3093
3153
  update(component, (draft) => {
3094
3154
  draft.subflow = subflow;
@@ -3116,11 +3176,17 @@ var createStepComponent = (props) => {
3116
3176
  stop() {
3117
3177
  stepPolling == null ? void 0 : stepPolling.stop();
3118
3178
  stepRefreshAfter == null ? void 0 : stepRefreshAfter.stop();
3179
+ stepDelays.stop();
3119
3180
  stepPrefetch.stop();
3120
3181
  update(component, (draft) => {
3121
3182
  draft.state = "stopped";
3122
3183
  draft.modals = [];
3123
3184
  });
3185
+ },
3186
+ setExternalConfirmation(external) {
3187
+ update(component, (draft) => {
3188
+ draft.externalConfirmation = external;
3189
+ });
3124
3190
  }
3125
3191
  });
3126
3192
  return component;
@@ -7506,6 +7572,14 @@ var createFlowController = (props) => {
7506
7572
  var _a;
7507
7573
  trackBehaviorTriggered(trackEvent, behavior);
7508
7574
  switch (behavior.type) {
7575
+ case "delay": {
7576
+ return rootComponent.startDelay({
7577
+ duration: behavior.duration,
7578
+ execute: () => {
7579
+ void onBehavior(behavior.behavior);
7580
+ }
7581
+ });
7582
+ }
7509
7583
  case "download": {
7510
7584
  try {
7511
7585
  await executeDownload(behavior.request, httpClient);
@@ -7576,7 +7650,14 @@ var createFlowController = (props) => {
7576
7650
  };
7577
7651
  }
7578
7652
  case "link": {
7579
- onLink(behavior.url);
7653
+ rootComponent.setExternalConfirmation(
7654
+ createExternalConfirmation(
7655
+ `${rootComponent.uid}-external-confirmation`,
7656
+ behavior.url,
7657
+ onLink,
7658
+ onChange
7659
+ )
7660
+ );
7580
7661
  break;
7581
7662
  }
7582
7663
  case "modal": {
@@ -8276,17 +8357,18 @@ var mapBoxControl = ({
8276
8357
 
8277
8358
  // src/renderers/mappers/collectionComponentToProps.ts
8278
8359
  var collectionComponentToProps = (component, rendererMapperProps) => {
8279
- var _a, _b, _c;
8280
- const beforeSectionsProps = (_a = component.state.beforeSections) == null ? void 0 : _a.map(
8360
+ var _a, _b, _c, _d, _e;
8361
+ const { render } = rendererMapperProps;
8362
+ const beforeSectionsProps = (_b = (_a = component.state.beforeSections) == null ? void 0 : _a.map(
8281
8363
  (child) => componentToRendererProps(child, rendererMapperProps)
8282
- );
8283
- const afterSectionsProps = (_b = component.state.afterSections) == null ? void 0 : _b.map(
8364
+ )) != null ? _b : [];
8365
+ const afterSectionsProps = (_d = (_c = component.state.afterSections) == null ? void 0 : _c.map(
8284
8366
  (child) => componentToRendererProps(child, rendererMapperProps)
8285
- );
8367
+ )) != null ? _d : [];
8286
8368
  return __spreadProps(__spreadValues(__spreadValues({}, pick(component, "uid", "analyticsId", "type", "control", "margin", "tags")), rendererMapperProps), {
8287
8369
  status: component.status,
8288
8370
  state: __spreadProps(__spreadValues({}, component.state), {
8289
- filters: (_c = component.state.filters) != null ? _c : [],
8371
+ filters: (_e = component.state.filters) != null ? _e : [],
8290
8372
  sections: component.state.sections.map((section) => __spreadProps(__spreadValues({}, section), {
8291
8373
  callToAction: mapCallToActionOptional(section.callToAction),
8292
8374
  items: section.items.map((item) => __spreadProps(__spreadValues({}, item), {
@@ -8296,9 +8378,9 @@ var collectionComponentToProps = (component, rendererMapperProps) => {
8296
8378
  }))
8297
8379
  })),
8298
8380
  beforeSectionsProps,
8299
- beforeSections: beforeSectionsProps == null ? void 0 : beforeSectionsProps.map(rendererMapperProps.render),
8381
+ beforeSections: beforeSectionsProps.map(render),
8300
8382
  afterSectionsProps,
8301
- afterSections: afterSectionsProps == null ? void 0 : afterSectionsProps.map(rendererMapperProps.render)
8383
+ afterSections: afterSectionsProps.map(render)
8302
8384
  })
8303
8385
  });
8304
8386
  };
@@ -9164,6 +9246,9 @@ var rootComponentToProps = (rootComponent, rendererMapperProps, nativeSubflowHan
9164
9246
  }, rendererMapperProps);
9165
9247
  };
9166
9248
 
9249
+ // src/renderers/mappers/utils/mapRendererLoadingState.ts
9250
+ var mapRendererLoadingState = (loadingState) => loadingState === "delay-pending" ? "submitting" : loadingState;
9251
+
9167
9252
  // src/renderers/subflow/getNativeSubflowRenderer.tsx
9168
9253
  import { Fragment as Fragment6, jsx as jsx7 } from "react/jsx-runtime";
9169
9254
  var getNativeSubflowRenderer = (handlers) => {
@@ -9280,7 +9365,7 @@ function useDynamicFlow(props) {
9280
9365
  httpClient,
9281
9366
  trackEvent: (_b = rootComponent.getTrackEvent()) != null ? _b : (() => {
9282
9367
  }),
9283
- stepLoadingState: rootComponent.getLoadingState()
9368
+ stepLoadingState: mapRendererLoadingState(rootComponent.getLoadingState())
9284
9369
  },
9285
9370
  (_c = props.nativeSubflowHandlers) != null ? _c : []
9286
9371
  );