@wise/dynamic-flow-client 5.1.1 → 5.1.2

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
@@ -7,6 +7,9 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __typeError = (msg) => {
11
+ throw TypeError(msg);
12
+ };
10
13
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
14
  var __spreadValues = (a, b) => {
12
15
  for (var prop in b || (b = {}))
@@ -45,6 +48,10 @@ var __copyProps = (to, from, except, desc) => {
45
48
  return to;
46
49
  };
47
50
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
51
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
52
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
53
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
54
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
48
55
 
49
56
  // src/index.ts
50
57
  var index_exports = {};
@@ -5717,11 +5724,6 @@ var mapToolbarToComponent = (uid, toolbar, mapperProps) => {
5717
5724
  });
5718
5725
  };
5719
5726
 
5720
- // src/domain/mappers/utils/feature-utils.ts
5721
- var isFeatureEnabled = (features, featureName) => {
5722
- return features[featureName] !== void 0 && features[featureName] !== false;
5723
- };
5724
-
5725
5727
  // src/domain/mappers/utils/groupLayoutByPinned.ts
5726
5728
  var groupLayoutByPinned = (layouts) => {
5727
5729
  return layouts.reduce(groupLayout, { pinned: [], nonPinned: [] });
@@ -5807,7 +5809,7 @@ var mapStepToComponent = (_a) => {
5807
5809
  submissionBehaviors.push(behavior);
5808
5810
  }
5809
5811
  };
5810
- const back = mapBackNavigation(navigation, onBehavior, Boolean(features.nativeBack));
5812
+ const back = mapBackNavigation(navigation, onBehavior, features.isEnabled("nativeBack"));
5811
5813
  const stepId = id || key;
5812
5814
  if (stepId === void 0) {
5813
5815
  throw new Error("Step must have an id or a key");
@@ -5831,7 +5833,7 @@ var mapStepToComponent = (_a) => {
5831
5833
  mapperProps,
5832
5834
  referencedSchemaIds
5833
5835
  );
5834
- const shouldPinButtons = isFeatureEnabled(features, "pinnedButtons");
5836
+ const shouldPinButtons = features.isEnabled("pinnedButtons");
5835
5837
  const { pinned, nonPinned } = shouldPinButtons ? groupLayoutByPinned(layout) : { pinned: [], nonPinned: layout };
5836
5838
  const layoutComponents = nonPinned.map(
5837
5839
  (layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, mapperProps, schemaComponents)
@@ -5863,7 +5865,7 @@ var mapStepToComponent = (_a) => {
5863
5865
  loadingState,
5864
5866
  stepPolling,
5865
5867
  stepRefreshAfter,
5866
- title: !features.hideStepTitle ? title : void 0,
5868
+ title: !features.isEnabled("hideStepTitle") ? title : void 0,
5867
5869
  tags,
5868
5870
  stackBehavior: (_a2 = navigation == null ? void 0 : navigation.stackBehavior) != null ? _a2 : "default",
5869
5871
  submissionRequestsCache,
@@ -5915,6 +5917,19 @@ var executePrefetch = (props) => {
5915
5917
  });
5916
5918
  };
5917
5919
 
5920
+ // src/domain/mappers/utils/FeatureFlags.ts
5921
+ var _features;
5922
+ var FeatureFlags = class {
5923
+ constructor(features) {
5924
+ __privateAdd(this, _features);
5925
+ __privateSet(this, _features, features);
5926
+ }
5927
+ isEnabled(featureName) {
5928
+ return __privateGet(this, _features)[featureName] != null && __privateGet(this, _features)[featureName] !== false;
5929
+ }
5930
+ };
5931
+ _features = new WeakMap();
5932
+
5918
5933
  // src/flow/getResponseType.ts
5919
5934
  var responseTypes = ["step", "action", "exit", "modal"];
5920
5935
  var getResponseType = async (response) => {
@@ -6380,7 +6395,7 @@ function useStableCallback(handler) {
6380
6395
 
6381
6396
  // src/useDynamicFlowCore.tsx
6382
6397
  function useDynamicFlowCore(props) {
6383
- const _a = props, { flowId, initialAction, initialStep, features = {} } = _a, rest = __objRest(_a, ["flowId", "initialAction", "initialStep", "features"]);
6398
+ const _a = props, { flowId, initialAction, initialStep } = _a, rest = __objRest(_a, ["flowId", "initialAction", "initialStep"]);
6384
6399
  const httpClient = useStableCallback(rest.httpClient);
6385
6400
  const onCancellation = useStableCallback(rest.onCancellation);
6386
6401
  const onCompletion = useStableCallback(rest.onCompletion);
@@ -6396,10 +6411,14 @@ function useDynamicFlowCore(props) {
6396
6411
  () => getSchemaErrorMessageFunction(formatMessage, locale),
6397
6412
  [formatMessage, locale]
6398
6413
  );
6414
+ const features = (0, import_react3.useMemo)(() => {
6415
+ var _a2;
6416
+ return new FeatureFlags((_a2 = rest.features) != null ? _a2 : {});
6417
+ }, []);
6399
6418
  const rerender = useRerender();
6400
6419
  const rootComponentRef = (0, import_react3.useRef)(
6401
6420
  createRootDomainComponent(rerender, scrollToTop, {
6402
- isNativeBackEnabled: Boolean(features.nativeBack),
6421
+ isNativeBackEnabled: features.isEnabled("nativeBack"),
6403
6422
  isFlowCancellable: Boolean(rest.onCancellation)
6404
6423
  })
6405
6424
  );
@@ -6537,7 +6556,7 @@ function useDynamicFlowCore(props) {
6537
6556
  });
6538
6557
  break;
6539
6558
  }
6540
- if (isFeatureEnabled(features, "nativeBack")) {
6559
+ if (features.isEnabled("nativeBack")) {
6541
6560
  if (rootComponentRef.current.stepStack.length > 1) {
6542
6561
  rootComponentRef.current.navigateBack();
6543
6562
  } else {
package/build/main.mjs CHANGED
@@ -4,6 +4,9 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
7
10
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
11
  var __spreadValues = (a, b) => {
9
12
  for (var prop in b || (b = {}))
@@ -29,6 +32,10 @@ var __objRest = (source, exclude) => {
29
32
  }
30
33
  return target;
31
34
  };
35
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
36
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
37
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
38
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
32
39
 
33
40
  // src/common/makeHttpClient/api-utils.ts
34
41
  function isRelativePath(url = "") {
@@ -5690,11 +5697,6 @@ var mapToolbarToComponent = (uid, toolbar, mapperProps) => {
5690
5697
  });
5691
5698
  };
5692
5699
 
5693
- // src/domain/mappers/utils/feature-utils.ts
5694
- var isFeatureEnabled = (features, featureName) => {
5695
- return features[featureName] !== void 0 && features[featureName] !== false;
5696
- };
5697
-
5698
5700
  // src/domain/mappers/utils/groupLayoutByPinned.ts
5699
5701
  var groupLayoutByPinned = (layouts) => {
5700
5702
  return layouts.reduce(groupLayout, { pinned: [], nonPinned: [] });
@@ -5780,7 +5782,7 @@ var mapStepToComponent = (_a) => {
5780
5782
  submissionBehaviors.push(behavior);
5781
5783
  }
5782
5784
  };
5783
- const back = mapBackNavigation(navigation, onBehavior, Boolean(features.nativeBack));
5785
+ const back = mapBackNavigation(navigation, onBehavior, features.isEnabled("nativeBack"));
5784
5786
  const stepId = id || key;
5785
5787
  if (stepId === void 0) {
5786
5788
  throw new Error("Step must have an id or a key");
@@ -5804,7 +5806,7 @@ var mapStepToComponent = (_a) => {
5804
5806
  mapperProps,
5805
5807
  referencedSchemaIds
5806
5808
  );
5807
- const shouldPinButtons = isFeatureEnabled(features, "pinnedButtons");
5809
+ const shouldPinButtons = features.isEnabled("pinnedButtons");
5808
5810
  const { pinned, nonPinned } = shouldPinButtons ? groupLayoutByPinned(layout) : { pinned: [], nonPinned: layout };
5809
5811
  const layoutComponents = nonPinned.map(
5810
5812
  (layoutComponent, index) => mapLayoutToComponent(`${uid}.layout-${index}`, layoutComponent, mapperProps, schemaComponents)
@@ -5836,7 +5838,7 @@ var mapStepToComponent = (_a) => {
5836
5838
  loadingState,
5837
5839
  stepPolling,
5838
5840
  stepRefreshAfter,
5839
- title: !features.hideStepTitle ? title : void 0,
5841
+ title: !features.isEnabled("hideStepTitle") ? title : void 0,
5840
5842
  tags,
5841
5843
  stackBehavior: (_a2 = navigation == null ? void 0 : navigation.stackBehavior) != null ? _a2 : "default",
5842
5844
  submissionRequestsCache,
@@ -5888,6 +5890,19 @@ var executePrefetch = (props) => {
5888
5890
  });
5889
5891
  };
5890
5892
 
5893
+ // src/domain/mappers/utils/FeatureFlags.ts
5894
+ var _features;
5895
+ var FeatureFlags = class {
5896
+ constructor(features) {
5897
+ __privateAdd(this, _features);
5898
+ __privateSet(this, _features, features);
5899
+ }
5900
+ isEnabled(featureName) {
5901
+ return __privateGet(this, _features)[featureName] != null && __privateGet(this, _features)[featureName] !== false;
5902
+ }
5903
+ };
5904
+ _features = new WeakMap();
5905
+
5891
5906
  // src/flow/getResponseType.ts
5892
5907
  var responseTypes = ["step", "action", "exit", "modal"];
5893
5908
  var getResponseType = async (response) => {
@@ -6353,7 +6368,7 @@ function useStableCallback(handler) {
6353
6368
 
6354
6369
  // src/useDynamicFlowCore.tsx
6355
6370
  function useDynamicFlowCore(props) {
6356
- const _a = props, { flowId, initialAction, initialStep, features = {} } = _a, rest = __objRest(_a, ["flowId", "initialAction", "initialStep", "features"]);
6371
+ const _a = props, { flowId, initialAction, initialStep } = _a, rest = __objRest(_a, ["flowId", "initialAction", "initialStep"]);
6357
6372
  const httpClient = useStableCallback(rest.httpClient);
6358
6373
  const onCancellation = useStableCallback(rest.onCancellation);
6359
6374
  const onCompletion = useStableCallback(rest.onCompletion);
@@ -6369,10 +6384,14 @@ function useDynamicFlowCore(props) {
6369
6384
  () => getSchemaErrorMessageFunction(formatMessage, locale),
6370
6385
  [formatMessage, locale]
6371
6386
  );
6387
+ const features = useMemo(() => {
6388
+ var _a2;
6389
+ return new FeatureFlags((_a2 = rest.features) != null ? _a2 : {});
6390
+ }, []);
6372
6391
  const rerender = useRerender();
6373
6392
  const rootComponentRef = useRef2(
6374
6393
  createRootDomainComponent(rerender, scrollToTop, {
6375
- isNativeBackEnabled: Boolean(features.nativeBack),
6394
+ isNativeBackEnabled: features.isEnabled("nativeBack"),
6376
6395
  isFlowCancellable: Boolean(rest.onCancellation)
6377
6396
  })
6378
6397
  );
@@ -6510,7 +6529,7 @@ function useDynamicFlowCore(props) {
6510
6529
  });
6511
6530
  break;
6512
6531
  }
6513
- if (isFeatureEnabled(features, "nativeBack")) {
6532
+ if (features.isEnabled("nativeBack")) {
6514
6533
  if (rootComponentRef.current.stepStack.length > 1) {
6515
6534
  rootComponentRef.current.navigateBack();
6516
6535
  } else {
@@ -1,12 +1,13 @@
1
1
  import type { AnalyticsEventDispatcher } from '../features/events';
2
2
  import type { LoadingState, OnPoll } from '../types';
3
3
  import type { MapperProps } from './schema/types';
4
+ import { FeatureFlags } from './utils/FeatureFlags';
4
5
  export type StepMapperProps = Omit<MapperProps, 'trackEvent' | 'registerSubmissionBehavior'> & {
5
6
  uid: string;
6
7
  etag: string | null;
7
8
  loadingState: LoadingState;
8
9
  trackEvent: AnalyticsEventDispatcher<string>;
9
- features: Record<string, unknown>;
10
+ features: FeatureFlags;
10
11
  onPoll: OnPoll;
11
12
  };
12
13
  export declare const mapStepToComponent: ({ uid: rootUid, loadingState, features, trackEvent, onPoll, onBehavior, ...restProps }: StepMapperProps) => import("../components/step/StepDomainComponent").StepDomainComponent;
@@ -0,0 +1,7 @@
1
+ type FeatureName = 'pinnedButtons' | 'nativeBack' | 'hideStepTitle';
2
+ export declare class FeatureFlags {
3
+ #private;
4
+ constructor(features: Record<string, unknown>);
5
+ isEnabled(featureName: FeatureName): boolean;
6
+ }
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wise/dynamic-flow-client",
3
- "version": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "Dynamic Flow web client",
5
5
  "license": "Apache-2.0",
6
6
  "main": "./build/main.js",
@@ -32,29 +32,29 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@chromatic-com/storybook": "4.1.3",
35
- "@formatjs/cli": "^6.7.4",
36
- "@storybook/addon-a11y": "^10.1.8",
37
- "@storybook/addon-docs": "^10.1.8",
38
- "@storybook/addon-links": "^10.1.8",
39
- "@storybook/react-vite": "10.1.8",
35
+ "@formatjs/cli": "^6.9.0",
36
+ "@storybook/addon-a11y": "^10.1.11",
37
+ "@storybook/addon-docs": "^10.1.11",
38
+ "@storybook/addon-links": "^10.1.11",
39
+ "@storybook/react-vite": "10.1.11",
40
40
  "@testing-library/dom": "10.4.1",
41
41
  "@testing-library/jest-dom": "6.9.1",
42
- "@testing-library/react": "16.3.0",
42
+ "@testing-library/react": "16.3.1",
43
43
  "@testing-library/user-event": "14.6.1",
44
- "@transferwise/components": "^46.116.1",
44
+ "@transferwise/components": "^46.118.0",
45
45
  "@transferwise/formatting": "^2.13.4",
46
- "@transferwise/icons": "4.0.0",
46
+ "@transferwise/icons": "4.0.1",
47
47
  "@transferwise/navigation-ui": "4.41.0",
48
- "@transferwise/neptune-css": "14.25.2",
49
- "@types/node": "22.19.2",
48
+ "@transferwise/neptune-css": "14.26.0",
49
+ "@types/node": "22.19.3",
50
50
  "@types/react": "18.3.27",
51
51
  "@types/react-dom": "18.3.7",
52
52
  "@types/react-intl": "3.0.0",
53
53
  "@vitejs/plugin-react": "5.1.2",
54
- "@wise/art": "2.24.7",
54
+ "@wise/art": "2.25.0",
55
55
  "@wise/components-theming": "^1.9.1",
56
56
  "esbuild": "0.27.0",
57
- "eslint-plugin-storybook": "10.1.8",
57
+ "eslint-plugin-storybook": "10.1.11",
58
58
  "framer-motion": "^12.23.26",
59
59
  "npm-run-all2": "8.0.4",
60
60
  "postcss": "^8.5.6",
@@ -63,17 +63,17 @@
63
63
  "react": "18.3.1",
64
64
  "react-dom": "18.3.1",
65
65
  "react-intl": "6.8.9",
66
- "storybook": "^10.1.8",
66
+ "storybook": "^10.1.11",
67
67
  "stylelint": "16.26.1",
68
68
  "stylelint-config-standard": "36.0.1",
69
69
  "stylelint-no-unsupported-browser-features": "8.0.5",
70
- "stylelint-value-no-unknown-custom-properties": "6.0.1",
70
+ "stylelint-value-no-unknown-custom-properties": "6.1.0",
71
71
  "tsx": "4.21.0",
72
72
  "typescript": "5.9.3",
73
- "vitest": "4.0.15",
73
+ "vitest": "4.0.16",
74
74
  "vitest-fetch-mock": "0.4.5",
75
- "@wise/dynamic-flow-renderers": "0.0.0",
76
- "@wise/dynamic-flow-fixtures": "0.0.1"
75
+ "@wise/dynamic-flow-fixtures": "0.0.1",
76
+ "@wise/dynamic-flow-renderers": "0.0.0"
77
77
  },
78
78
  "peerDependencies": {
79
79
  "@transferwise/components": "^46.104.0",
@@ -86,7 +86,7 @@
86
86
  "react-intl": "^6"
87
87
  },
88
88
  "dependencies": {
89
- "@wise/dynamic-flow-types": "4.1.1"
89
+ "@wise/dynamic-flow-types": "4.1.2"
90
90
  },
91
91
  "scripts": {
92
92
  "dev": "EXCLUDE_VISUAL_TESTS=true pnpm storybook dev -p 3003",
@@ -1,3 +0,0 @@
1
- type Feature = 'pinnedButtons' | 'nativeBack';
2
- export declare const isFeatureEnabled: (features: Record<string, unknown>, featureName: Feature) => boolean;
3
- export {};