@wise/dynamic-flow-client 5.24.0 → 5.24.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
@@ -1651,17 +1651,58 @@ var debounce = (callback, waitMs) => {
1651
1651
  return debouncedFn;
1652
1652
  };
1653
1653
 
1654
+ // src/utils/recursiveMerge.ts
1655
+ function recursiveMerge(valueA, valueB) {
1656
+ if (valueA === null) {
1657
+ return valueB;
1658
+ }
1659
+ if (valueB === null) {
1660
+ return valueA;
1661
+ }
1662
+ if (isObject2(valueA) && isObject2(valueB)) {
1663
+ return mergeObjects(valueA, valueB);
1664
+ }
1665
+ if (Array.isArray(valueA) && Array.isArray(valueB)) {
1666
+ return mergeArrays(valueA, valueB);
1667
+ }
1668
+ return valueB;
1669
+ }
1670
+ function isObject2(value) {
1671
+ return value != null && typeof value === "object" && !Array.isArray(value) && !(value instanceof File);
1672
+ }
1673
+ function mergeObjects(valueA, valueB) {
1674
+ const allKeys = /* @__PURE__ */ new Set([...Object.keys(valueA), ...Object.keys(valueB)]);
1675
+ const entries = Array.from(allKeys).map((key) => {
1676
+ var _a, _b;
1677
+ const value = recursiveMerge((_a = valueA[key]) != null ? _a : null, (_b = valueB[key]) != null ? _b : null);
1678
+ return [key, value];
1679
+ });
1680
+ return Object.fromEntries(entries);
1681
+ }
1682
+ function mergeArrays(valueA, valueB) {
1683
+ const length = Math.max(valueA.length, valueB.length);
1684
+ return Array.from(
1685
+ { length },
1686
+ (_, index) => {
1687
+ var _a, _b;
1688
+ return recursiveMerge((_a = valueA[index]) != null ? _a : null, (_b = valueB[index]) != null ? _b : null);
1689
+ }
1690
+ );
1691
+ }
1692
+
1654
1693
  // src/domain/components/collectionComponent/CollectionComponent.ts
1655
1694
  var DEBOUNCE_TIME = 800;
1656
- var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1695
+ var createCollectionComponent = (props, onComponentUpdate, queryFunction, trackEvent) => {
1657
1696
  const { uid, analyticsId, control, margin, tags, state } = props;
1658
1697
  const update = getInputUpdateFunction(onComponentUpdate);
1659
1698
  let abortController = new AbortController();
1660
- const query = (mode) => {
1699
+ const trackCollectionEvent = (source, status) => trackEvent(getEventName(source, status), component.state.analytics);
1700
+ const query = (mode, source) => {
1661
1701
  var _a, _b;
1662
1702
  abortController.abort();
1663
1703
  abortController = new AbortController();
1664
1704
  const { signal } = abortController;
1705
+ trackCollectionEvent(source != null ? source : mode, "Triggered");
1665
1706
  queryFunction({
1666
1707
  searchParam: (_a = component.state.search) == null ? void 0 : _a.param,
1667
1708
  query: (_b = component.state.search) == null ? void 0 : _b.query,
@@ -1673,27 +1714,20 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1673
1714
  return;
1674
1715
  }
1675
1716
  update(component, (draft) => {
1676
- var _a2, _b2;
1677
- draft.state = {
1678
- sections: mode === "pagination" ? mergeSections(component.state.sections, response.sections) : response.sections,
1679
- nextCursor: response.nextCursor,
1680
- filters: response.filters ? mapFilters(response.filters) : component.state.filters,
1681
- search: response.search ? mapSearch(response.search) : component.state.search,
1682
- beforeSections: (_a2 = response.beforeSections) != null ? _a2 : component.state.beforeSections,
1683
- afterSections: (_b2 = response.afterSections) != null ? _b2 : component.state.afterSections
1684
- };
1717
+ draft.state = mergeState(mode, component.state, response);
1685
1718
  draft.status = {
1686
1719
  type: "idle",
1687
1720
  loadMore: response.nextCursor ? paginate : void 0
1688
1721
  };
1689
1722
  });
1723
+ trackCollectionEvent(source != null ? source : mode, "Succeeded");
1690
1724
  }).catch(() => {
1691
1725
  if (!signal.aborted) {
1692
1726
  const retry = () => {
1693
1727
  update(component, (draft) => {
1694
1728
  draft.status = { type: "loading", reason: mode };
1695
1729
  });
1696
- query(mode);
1730
+ query(mode, source);
1697
1731
  };
1698
1732
  update(component, (draft) => {
1699
1733
  if (mode === "search") {
@@ -1701,6 +1735,7 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1701
1735
  }
1702
1736
  draft.status = { type: "error", reason: mode, retry };
1703
1737
  });
1738
+ trackCollectionEvent(source != null ? source : mode, "Failed");
1704
1739
  }
1705
1740
  });
1706
1741
  };
@@ -1710,10 +1745,22 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1710
1745
  debouncedQuery("search");
1711
1746
  };
1712
1747
  const filter = () => {
1713
- debouncedQuery("search");
1748
+ debouncedQuery("search", "filter");
1714
1749
  debouncedQuery.flush();
1715
1750
  };
1716
1751
  const paginate = () => query("pagination");
1752
+ const mergeState = (mode, original, incoming) => {
1753
+ var _a, _b;
1754
+ return {
1755
+ sections: mode === "pagination" ? mergeSections(original.sections, incoming.sections) : incoming.sections,
1756
+ nextCursor: incoming.nextCursor,
1757
+ filters: incoming.filters ? mapFilters(incoming.filters) : original.filters,
1758
+ search: incoming.search ? mapSearch(incoming.search) : original.search,
1759
+ beforeSections: (_a = incoming.beforeSections) != null ? _a : original.beforeSections,
1760
+ afterSections: (_b = incoming.afterSections) != null ? _b : original.afterSections,
1761
+ analytics: mode === "pagination" ? recursiveMerge(original.analytics, incoming.analytics) : incoming.analytics
1762
+ };
1763
+ };
1717
1764
  const selectFilter = (filterIndex, optionIndex) => {
1718
1765
  var _a;
1719
1766
  const selected = (_a = component.state.filters) == null ? void 0 : _a[filterIndex];
@@ -1799,6 +1846,19 @@ var mergeSections = (existing, incoming) => {
1799
1846
  });
1800
1847
  return [...merged, ...newSections];
1801
1848
  };
1849
+ var getEventName = (mode, state) => {
1850
+ const getMode = () => {
1851
+ switch (mode) {
1852
+ case "pagination":
1853
+ return "Pagination";
1854
+ case "search":
1855
+ return "Search";
1856
+ case "filter":
1857
+ return "Filter";
1858
+ }
1859
+ };
1860
+ return `Collection ${getMode()} ${state}`;
1861
+ };
1802
1862
 
1803
1863
  // src/domain/features/collection/getPerformCollectionQuery.ts
1804
1864
  var getPerformCollectionQuery = (httpClient, baseRequest, mapState) => {
@@ -1892,7 +1952,7 @@ var hashRequest = ({
1892
1952
 
1893
1953
  // src/domain/mappers/layout/collectionLayoutToComponent.ts
1894
1954
  var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, margin, search, tags, baseRequest }, mapperProps) => {
1895
- const { httpClient, onComponentUpdate } = mapperProps;
1955
+ const { httpClient, onComponentUpdate, trackEvent } = mapperProps;
1896
1956
  const mapLayout = (layout, index) => mapLayoutToComponent(`${uid}-collection-response-${index}`, layout, mapperProps, []);
1897
1957
  const mapState = (state) => mapCollectionSpecToDomainState(state, mapperProps, mapLayout);
1898
1958
  const queryFunction = getPerformCollectionQuery(httpClient, baseRequest, mapState);
@@ -1907,12 +1967,20 @@ var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, ma
1907
1967
  search
1908
1968
  },
1909
1969
  onComponentUpdate,
1910
- queryFunction
1970
+ queryFunction,
1971
+ trackEvent
1911
1972
  );
1912
1973
  return component;
1913
1974
  };
1914
1975
  var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1915
- const { sections, filters, beforeSections, afterSections, nextCursor } = specState;
1976
+ const {
1977
+ sections,
1978
+ filters,
1979
+ beforeSections,
1980
+ afterSections,
1981
+ nextCursor,
1982
+ analytics = {}
1983
+ } = specState;
1916
1984
  return {
1917
1985
  sections: sections.map((section) => {
1918
1986
  var _a;
@@ -1940,7 +2008,8 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1940
2008
  filters: filters == null ? void 0 : filters.map(mapFilter),
1941
2009
  beforeSections: beforeSections == null ? void 0 : beforeSections.map(mapLayout),
1942
2010
  afterSections: afterSections == null ? void 0 : afterSections.map(mapLayout),
1943
- nextCursor
2011
+ nextCursor,
2012
+ analytics
1944
2013
  };
1945
2014
  };
1946
2015
  var mapFilter = (filter) => {
@@ -3012,45 +3081,6 @@ var createExternalConfirmation = (uid, url, onLink, onComponentUpdate) => {
3012
3081
  return component;
3013
3082
  };
3014
3083
 
3015
- // src/utils/recursiveMerge.ts
3016
- function recursiveMerge(valueA, valueB) {
3017
- if (valueA === null) {
3018
- return valueB;
3019
- }
3020
- if (valueB === null) {
3021
- return valueA;
3022
- }
3023
- if (isObject2(valueA) && isObject2(valueB)) {
3024
- return mergeObjects(valueA, valueB);
3025
- }
3026
- if (Array.isArray(valueA) && Array.isArray(valueB)) {
3027
- return mergeArrays(valueA, valueB);
3028
- }
3029
- return valueB;
3030
- }
3031
- function isObject2(value) {
3032
- return value != null && typeof value === "object" && !Array.isArray(value) && !(value instanceof File);
3033
- }
3034
- function mergeObjects(valueA, valueB) {
3035
- const allKeys = /* @__PURE__ */ new Set([...Object.keys(valueA), ...Object.keys(valueB)]);
3036
- const entries = Array.from(allKeys).map((key) => {
3037
- var _a, _b;
3038
- const value = recursiveMerge((_a = valueA[key]) != null ? _a : null, (_b = valueB[key]) != null ? _b : null);
3039
- return [key, value];
3040
- });
3041
- return Object.fromEntries(entries);
3042
- }
3043
- function mergeArrays(valueA, valueB) {
3044
- const length = Math.max(valueA.length, valueB.length);
3045
- return Array.from(
3046
- { length },
3047
- (_, index) => {
3048
- var _a, _b;
3049
- return recursiveMerge((_a = valueA[index]) != null ? _a : null, (_b = valueB[index]) != null ? _b : null);
3050
- }
3051
- );
3052
- }
3053
-
3054
3084
  // src/utils/component-utils.ts
3055
3085
  var getSubmittableData = async (components) => Promise.all(components.map(async (component) => component.getSubmittableValue())).then(
3056
3086
  (values) => values.reduce((acc, value) => recursiveMerge(acc, value), null)
@@ -9524,7 +9554,16 @@ var eventNames = [
9524
9554
  "Native Subflow Succeeded",
9525
9555
  "Native Subflow Failed",
9526
9556
  "Native Subflow Cancelled",
9527
- "Behavior Triggered"
9557
+ "Behavior Triggered",
9558
+ "Collection Search Triggered",
9559
+ "Collection Search Succeeded",
9560
+ "Collection Search Failed",
9561
+ "Collection Filter Triggered",
9562
+ "Collection Filter Succeeded",
9563
+ "Collection Filter Failed",
9564
+ "Collection Pagination Triggered",
9565
+ "Collection Pagination Succeeded",
9566
+ "Collection Pagination Failed"
9528
9567
  ];
9529
9568
 
9530
9569
  // src/renderers/subflow/getDynamicSubflowRenderer.tsx
package/build/main.mjs CHANGED
@@ -1620,17 +1620,58 @@ var debounce = (callback, waitMs) => {
1620
1620
  return debouncedFn;
1621
1621
  };
1622
1622
 
1623
+ // src/utils/recursiveMerge.ts
1624
+ function recursiveMerge(valueA, valueB) {
1625
+ if (valueA === null) {
1626
+ return valueB;
1627
+ }
1628
+ if (valueB === null) {
1629
+ return valueA;
1630
+ }
1631
+ if (isObject2(valueA) && isObject2(valueB)) {
1632
+ return mergeObjects(valueA, valueB);
1633
+ }
1634
+ if (Array.isArray(valueA) && Array.isArray(valueB)) {
1635
+ return mergeArrays(valueA, valueB);
1636
+ }
1637
+ return valueB;
1638
+ }
1639
+ function isObject2(value) {
1640
+ return value != null && typeof value === "object" && !Array.isArray(value) && !(value instanceof File);
1641
+ }
1642
+ function mergeObjects(valueA, valueB) {
1643
+ const allKeys = /* @__PURE__ */ new Set([...Object.keys(valueA), ...Object.keys(valueB)]);
1644
+ const entries = Array.from(allKeys).map((key) => {
1645
+ var _a, _b;
1646
+ const value = recursiveMerge((_a = valueA[key]) != null ? _a : null, (_b = valueB[key]) != null ? _b : null);
1647
+ return [key, value];
1648
+ });
1649
+ return Object.fromEntries(entries);
1650
+ }
1651
+ function mergeArrays(valueA, valueB) {
1652
+ const length = Math.max(valueA.length, valueB.length);
1653
+ return Array.from(
1654
+ { length },
1655
+ (_, index) => {
1656
+ var _a, _b;
1657
+ return recursiveMerge((_a = valueA[index]) != null ? _a : null, (_b = valueB[index]) != null ? _b : null);
1658
+ }
1659
+ );
1660
+ }
1661
+
1623
1662
  // src/domain/components/collectionComponent/CollectionComponent.ts
1624
1663
  var DEBOUNCE_TIME = 800;
1625
- var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1664
+ var createCollectionComponent = (props, onComponentUpdate, queryFunction, trackEvent) => {
1626
1665
  const { uid, analyticsId, control, margin, tags, state } = props;
1627
1666
  const update = getInputUpdateFunction(onComponentUpdate);
1628
1667
  let abortController = new AbortController();
1629
- const query = (mode) => {
1668
+ const trackCollectionEvent = (source, status) => trackEvent(getEventName(source, status), component.state.analytics);
1669
+ const query = (mode, source) => {
1630
1670
  var _a, _b;
1631
1671
  abortController.abort();
1632
1672
  abortController = new AbortController();
1633
1673
  const { signal } = abortController;
1674
+ trackCollectionEvent(source != null ? source : mode, "Triggered");
1634
1675
  queryFunction({
1635
1676
  searchParam: (_a = component.state.search) == null ? void 0 : _a.param,
1636
1677
  query: (_b = component.state.search) == null ? void 0 : _b.query,
@@ -1642,27 +1683,20 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1642
1683
  return;
1643
1684
  }
1644
1685
  update(component, (draft) => {
1645
- var _a2, _b2;
1646
- draft.state = {
1647
- sections: mode === "pagination" ? mergeSections(component.state.sections, response.sections) : response.sections,
1648
- nextCursor: response.nextCursor,
1649
- filters: response.filters ? mapFilters(response.filters) : component.state.filters,
1650
- search: response.search ? mapSearch(response.search) : component.state.search,
1651
- beforeSections: (_a2 = response.beforeSections) != null ? _a2 : component.state.beforeSections,
1652
- afterSections: (_b2 = response.afterSections) != null ? _b2 : component.state.afterSections
1653
- };
1686
+ draft.state = mergeState(mode, component.state, response);
1654
1687
  draft.status = {
1655
1688
  type: "idle",
1656
1689
  loadMore: response.nextCursor ? paginate : void 0
1657
1690
  };
1658
1691
  });
1692
+ trackCollectionEvent(source != null ? source : mode, "Succeeded");
1659
1693
  }).catch(() => {
1660
1694
  if (!signal.aborted) {
1661
1695
  const retry = () => {
1662
1696
  update(component, (draft) => {
1663
1697
  draft.status = { type: "loading", reason: mode };
1664
1698
  });
1665
- query(mode);
1699
+ query(mode, source);
1666
1700
  };
1667
1701
  update(component, (draft) => {
1668
1702
  if (mode === "search") {
@@ -1670,6 +1704,7 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1670
1704
  }
1671
1705
  draft.status = { type: "error", reason: mode, retry };
1672
1706
  });
1707
+ trackCollectionEvent(source != null ? source : mode, "Failed");
1673
1708
  }
1674
1709
  });
1675
1710
  };
@@ -1679,10 +1714,22 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1679
1714
  debouncedQuery("search");
1680
1715
  };
1681
1716
  const filter = () => {
1682
- debouncedQuery("search");
1717
+ debouncedQuery("search", "filter");
1683
1718
  debouncedQuery.flush();
1684
1719
  };
1685
1720
  const paginate = () => query("pagination");
1721
+ const mergeState = (mode, original, incoming) => {
1722
+ var _a, _b;
1723
+ return {
1724
+ sections: mode === "pagination" ? mergeSections(original.sections, incoming.sections) : incoming.sections,
1725
+ nextCursor: incoming.nextCursor,
1726
+ filters: incoming.filters ? mapFilters(incoming.filters) : original.filters,
1727
+ search: incoming.search ? mapSearch(incoming.search) : original.search,
1728
+ beforeSections: (_a = incoming.beforeSections) != null ? _a : original.beforeSections,
1729
+ afterSections: (_b = incoming.afterSections) != null ? _b : original.afterSections,
1730
+ analytics: mode === "pagination" ? recursiveMerge(original.analytics, incoming.analytics) : incoming.analytics
1731
+ };
1732
+ };
1686
1733
  const selectFilter = (filterIndex, optionIndex) => {
1687
1734
  var _a;
1688
1735
  const selected = (_a = component.state.filters) == null ? void 0 : _a[filterIndex];
@@ -1768,6 +1815,19 @@ var mergeSections = (existing, incoming) => {
1768
1815
  });
1769
1816
  return [...merged, ...newSections];
1770
1817
  };
1818
+ var getEventName = (mode, state) => {
1819
+ const getMode = () => {
1820
+ switch (mode) {
1821
+ case "pagination":
1822
+ return "Pagination";
1823
+ case "search":
1824
+ return "Search";
1825
+ case "filter":
1826
+ return "Filter";
1827
+ }
1828
+ };
1829
+ return `Collection ${getMode()} ${state}`;
1830
+ };
1771
1831
 
1772
1832
  // src/domain/features/collection/getPerformCollectionQuery.ts
1773
1833
  var getPerformCollectionQuery = (httpClient, baseRequest, mapState) => {
@@ -1861,7 +1921,7 @@ var hashRequest = ({
1861
1921
 
1862
1922
  // src/domain/mappers/layout/collectionLayoutToComponent.ts
1863
1923
  var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, margin, search, tags, baseRequest }, mapperProps) => {
1864
- const { httpClient, onComponentUpdate } = mapperProps;
1924
+ const { httpClient, onComponentUpdate, trackEvent } = mapperProps;
1865
1925
  const mapLayout = (layout, index) => mapLayoutToComponent(`${uid}-collection-response-${index}`, layout, mapperProps, []);
1866
1926
  const mapState = (state) => mapCollectionSpecToDomainState(state, mapperProps, mapLayout);
1867
1927
  const queryFunction = getPerformCollectionQuery(httpClient, baseRequest, mapState);
@@ -1876,12 +1936,20 @@ var collectionLayoutToComponent = (uid, { analyticsId, control, initialState, ma
1876
1936
  search
1877
1937
  },
1878
1938
  onComponentUpdate,
1879
- queryFunction
1939
+ queryFunction,
1940
+ trackEvent
1880
1941
  );
1881
1942
  return component;
1882
1943
  };
1883
1944
  var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1884
- const { sections, filters, beforeSections, afterSections, nextCursor } = specState;
1945
+ const {
1946
+ sections,
1947
+ filters,
1948
+ beforeSections,
1949
+ afterSections,
1950
+ nextCursor,
1951
+ analytics = {}
1952
+ } = specState;
1885
1953
  return {
1886
1954
  sections: sections.map((section) => {
1887
1955
  var _a;
@@ -1909,7 +1977,8 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1909
1977
  filters: filters == null ? void 0 : filters.map(mapFilter),
1910
1978
  beforeSections: beforeSections == null ? void 0 : beforeSections.map(mapLayout),
1911
1979
  afterSections: afterSections == null ? void 0 : afterSections.map(mapLayout),
1912
- nextCursor
1980
+ nextCursor,
1981
+ analytics
1913
1982
  };
1914
1983
  };
1915
1984
  var mapFilter = (filter) => {
@@ -2981,45 +3050,6 @@ var createExternalConfirmation = (uid, url, onLink, onComponentUpdate) => {
2981
3050
  return component;
2982
3051
  };
2983
3052
 
2984
- // src/utils/recursiveMerge.ts
2985
- function recursiveMerge(valueA, valueB) {
2986
- if (valueA === null) {
2987
- return valueB;
2988
- }
2989
- if (valueB === null) {
2990
- return valueA;
2991
- }
2992
- if (isObject2(valueA) && isObject2(valueB)) {
2993
- return mergeObjects(valueA, valueB);
2994
- }
2995
- if (Array.isArray(valueA) && Array.isArray(valueB)) {
2996
- return mergeArrays(valueA, valueB);
2997
- }
2998
- return valueB;
2999
- }
3000
- function isObject2(value) {
3001
- return value != null && typeof value === "object" && !Array.isArray(value) && !(value instanceof File);
3002
- }
3003
- function mergeObjects(valueA, valueB) {
3004
- const allKeys = /* @__PURE__ */ new Set([...Object.keys(valueA), ...Object.keys(valueB)]);
3005
- const entries = Array.from(allKeys).map((key) => {
3006
- var _a, _b;
3007
- const value = recursiveMerge((_a = valueA[key]) != null ? _a : null, (_b = valueB[key]) != null ? _b : null);
3008
- return [key, value];
3009
- });
3010
- return Object.fromEntries(entries);
3011
- }
3012
- function mergeArrays(valueA, valueB) {
3013
- const length = Math.max(valueA.length, valueB.length);
3014
- return Array.from(
3015
- { length },
3016
- (_, index) => {
3017
- var _a, _b;
3018
- return recursiveMerge((_a = valueA[index]) != null ? _a : null, (_b = valueB[index]) != null ? _b : null);
3019
- }
3020
- );
3021
- }
3022
-
3023
3053
  // src/utils/component-utils.ts
3024
3054
  var getSubmittableData = async (components) => Promise.all(components.map(async (component) => component.getSubmittableValue())).then(
3025
3055
  (values) => values.reduce((acc, value) => recursiveMerge(acc, value), null)
@@ -9493,7 +9523,16 @@ var eventNames = [
9493
9523
  "Native Subflow Succeeded",
9494
9524
  "Native Subflow Failed",
9495
9525
  "Native Subflow Cancelled",
9496
- "Behavior Triggered"
9526
+ "Behavior Triggered",
9527
+ "Collection Search Triggered",
9528
+ "Collection Search Succeeded",
9529
+ "Collection Search Failed",
9530
+ "Collection Filter Triggered",
9531
+ "Collection Filter Succeeded",
9532
+ "Collection Filter Failed",
9533
+ "Collection Pagination Triggered",
9534
+ "Collection Pagination Succeeded",
9535
+ "Collection Pagination Failed"
9497
9536
  ];
9498
9537
 
9499
9538
  // src/renderers/subflow/getDynamicSubflowRenderer.tsx