@wise/dynamic-flow-client 5.22.2 → 5.23.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
@@ -1545,11 +1545,36 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
1545
1545
  )
1546
1546
  });
1547
1547
 
1548
+ // src/domain/mappers/utils/image.ts
1549
+ var mapSpecImage = (image) => {
1550
+ var _a, _b, _c;
1551
+ return image ? {
1552
+ uri: (_b = (_a = image.uri) != null ? _a : image.url) != null ? _b : "",
1553
+ accessibilityDescription: (_c = image.accessibilityDescription) != null ? _c : image.text
1554
+ } : void 0;
1555
+ };
1556
+
1557
+ // src/domain/mappers/utils/media-utils.ts
1558
+ var getDomainLayerMedia = ({ icon, image, media }) => {
1559
+ if (media) {
1560
+ return media;
1561
+ }
1562
+ if (icon || image) {
1563
+ return {
1564
+ type: "legacy",
1565
+ icon,
1566
+ image: mapSpecImage(image)
1567
+ };
1568
+ }
1569
+ return void 0;
1570
+ };
1571
+
1548
1572
  // src/domain/mappers/utils/utils.ts
1549
1573
  var mapInlineAlert = (alert) => {
1550
1574
  return alert ? {
1551
1575
  content: alert.content,
1552
- context: alert.context ? mapLegacyContext(alert.context) : "neutral"
1576
+ context: alert.context ? mapLegacyContext(alert.context) : "neutral",
1577
+ media: getDomainLayerMedia({ media: alert.media })
1553
1578
  } : void 0;
1554
1579
  };
1555
1580
  var mapAdditionalInfo = (info, mapperProps) => {
@@ -1576,7 +1601,8 @@ var mapAdditionalInfo = (info, mapperProps) => {
1576
1601
  var mapSchemaAlert = (alert) => {
1577
1602
  return alert ? {
1578
1603
  content: alert.markdown,
1579
- context: alert.context ? mapLegacyContext(alert.context) : "neutral"
1604
+ context: alert.context ? mapLegacyContext(alert.context) : "neutral",
1605
+ media: getDomainLayerMedia({ media: alert.media })
1580
1606
  } : void 0;
1581
1607
  };
1582
1608
 
@@ -1654,13 +1680,17 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1654
1680
  });
1655
1681
  }).catch(() => {
1656
1682
  if (!signal.aborted) {
1683
+ const retry = () => {
1684
+ update(component, (draft) => {
1685
+ draft.status = { type: "loading", reason: mode };
1686
+ });
1687
+ query(mode);
1688
+ };
1657
1689
  update(component, (draft) => {
1658
- draft.state = {
1659
- filters: component.state.filters,
1660
- search: component.state.search,
1661
- sections: []
1662
- };
1663
- draft.status = { type: "error", reason: mode, retry: () => query(mode) };
1690
+ if (mode === "search") {
1691
+ draft.state.sections = [];
1692
+ }
1693
+ draft.status = { type: "error", reason: mode, retry };
1664
1694
  });
1665
1695
  }
1666
1696
  });
@@ -1746,13 +1776,15 @@ var mergeSections = (existing, incoming) => {
1746
1776
  const knownIds = new Set(existing.map((section) => section.id));
1747
1777
  const newSections = incoming.filter((section) => !knownIds.has(section.id));
1748
1778
  const merged = existing.map((section) => {
1749
- var _a, _b;
1779
+ var _a, _b, _c, _d;
1750
1780
  const match = incoming.find((s) => s.id === section.id);
1751
1781
  if (!match) return section;
1752
1782
  return {
1753
1783
  id: match.id,
1754
1784
  title: (_a = match.title) != null ? _a : section.title,
1755
1785
  callToAction: (_b = match.callToAction) != null ? _b : section.callToAction,
1786
+ help: (_c = match.help) != null ? _c : section.help,
1787
+ inlineAlert: (_d = match.inlineAlert) != null ? _d : section.inlineAlert,
1756
1788
  items: [...section.items, ...match.items]
1757
1789
  };
1758
1790
  });
@@ -1874,10 +1906,11 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1874
1906
  var _a, _b, _c;
1875
1907
  return {
1876
1908
  sections: specState.sections.map((section) => {
1877
- return {
1878
- id: section.id,
1879
- title: section.title,
1909
+ var _a2;
1910
+ return __spreadProps(__spreadValues({}, section), {
1880
1911
  callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
1912
+ help: (_a2 = section.help) == null ? void 0 : _a2.markdown,
1913
+ inlineAlert: mapInlineAlert(section.inlineAlert),
1881
1914
  items: section.items.map((item) => {
1882
1915
  const behavior = getDomainLayerBehavior(
1883
1916
  { behavior: item.primaryBehavior },
@@ -1893,24 +1926,29 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1893
1926
  inlineAlert: mapInlineAlert(item.inlineAlert)
1894
1927
  });
1895
1928
  })
1896
- };
1929
+ });
1897
1930
  }),
1898
- filters: (_a = specState.filters) == null ? void 0 : _a.map((filter) => __spreadProps(__spreadValues({}, filter), {
1899
- options: filter.options.map((option) => {
1900
- var _a2;
1901
- return __spreadProps(__spreadValues({}, option), {
1902
- selected: (_a2 = option.selected) != null ? _a2 : false,
1903
- onSelect: () => {
1904
- }
1905
- // noop - this gets added during mapping
1906
- });
1907
- })
1908
- })),
1931
+ filters: (_a = specState.filters) == null ? void 0 : _a.map(mapFilter),
1909
1932
  beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
1910
1933
  afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
1911
1934
  nextCursor: specState.nextCursor
1912
1935
  };
1913
1936
  };
1937
+ var mapFilter = (filter) => {
1938
+ const anySelected = filter.options.some((option) => option.selected);
1939
+ return __spreadProps(__spreadValues({}, filter), {
1940
+ options: filter.options.map((option, index) => {
1941
+ var _a;
1942
+ return __spreadProps(__spreadValues({}, option), {
1943
+ // if a single select with no selection, we should default to selecting the first item
1944
+ selected: filter.multiSelect || anySelected ? (_a = option.selected) != null ? _a : false : index === 0,
1945
+ onSelect: () => {
1946
+ }
1947
+ // noop - this gets added during mapping in the component itself
1948
+ });
1949
+ })
1950
+ });
1951
+ };
1914
1952
 
1915
1953
  // src/domain/components/ButtonComponent.ts
1916
1954
  var createButtonComponent = (props) => __spreadValues({
@@ -1918,30 +1956,6 @@ var createButtonComponent = (props) => __spreadValues({
1918
1956
  kind: "layout"
1919
1957
  }, props);
1920
1958
 
1921
- // src/domain/mappers/utils/image.ts
1922
- var mapSpecImage = (image) => {
1923
- var _a, _b, _c;
1924
- return image ? {
1925
- uri: (_b = (_a = image.uri) != null ? _a : image.url) != null ? _b : "",
1926
- accessibilityDescription: (_c = image.accessibilityDescription) != null ? _c : image.text
1927
- } : void 0;
1928
- };
1929
-
1930
- // src/domain/mappers/utils/media-utils.ts
1931
- var getDomainLayerMedia = ({ icon, image, media }) => {
1932
- if (media) {
1933
- return media;
1934
- }
1935
- if (icon || image) {
1936
- return {
1937
- type: "legacy",
1938
- icon,
1939
- image: mapSpecImage(image)
1940
- };
1941
- }
1942
- return void 0;
1943
- };
1944
-
1945
1959
  // src/domain/mappers/layout/buttonLayoutToComponent.ts
1946
1960
  var buttonLayoutToComponent = (uid, button, mapperProps) => {
1947
1961
  if (!button.behavior && !button.action && mapperProps.features.isEnabled("strictButtonOperations")) {
package/build/main.mjs CHANGED
@@ -1514,11 +1514,36 @@ var boxLayoutToComponent = (uid, { border = false, components, control, margin,
1514
1514
  )
1515
1515
  });
1516
1516
 
1517
+ // src/domain/mappers/utils/image.ts
1518
+ var mapSpecImage = (image) => {
1519
+ var _a, _b, _c;
1520
+ return image ? {
1521
+ uri: (_b = (_a = image.uri) != null ? _a : image.url) != null ? _b : "",
1522
+ accessibilityDescription: (_c = image.accessibilityDescription) != null ? _c : image.text
1523
+ } : void 0;
1524
+ };
1525
+
1526
+ // src/domain/mappers/utils/media-utils.ts
1527
+ var getDomainLayerMedia = ({ icon, image, media }) => {
1528
+ if (media) {
1529
+ return media;
1530
+ }
1531
+ if (icon || image) {
1532
+ return {
1533
+ type: "legacy",
1534
+ icon,
1535
+ image: mapSpecImage(image)
1536
+ };
1537
+ }
1538
+ return void 0;
1539
+ };
1540
+
1517
1541
  // src/domain/mappers/utils/utils.ts
1518
1542
  var mapInlineAlert = (alert) => {
1519
1543
  return alert ? {
1520
1544
  content: alert.content,
1521
- context: alert.context ? mapLegacyContext(alert.context) : "neutral"
1545
+ context: alert.context ? mapLegacyContext(alert.context) : "neutral",
1546
+ media: getDomainLayerMedia({ media: alert.media })
1522
1547
  } : void 0;
1523
1548
  };
1524
1549
  var mapAdditionalInfo = (info, mapperProps) => {
@@ -1545,7 +1570,8 @@ var mapAdditionalInfo = (info, mapperProps) => {
1545
1570
  var mapSchemaAlert = (alert) => {
1546
1571
  return alert ? {
1547
1572
  content: alert.markdown,
1548
- context: alert.context ? mapLegacyContext(alert.context) : "neutral"
1573
+ context: alert.context ? mapLegacyContext(alert.context) : "neutral",
1574
+ media: getDomainLayerMedia({ media: alert.media })
1549
1575
  } : void 0;
1550
1576
  };
1551
1577
 
@@ -1623,13 +1649,17 @@ var createCollectionComponent = (props, onComponentUpdate, queryFunction) => {
1623
1649
  });
1624
1650
  }).catch(() => {
1625
1651
  if (!signal.aborted) {
1652
+ const retry = () => {
1653
+ update(component, (draft) => {
1654
+ draft.status = { type: "loading", reason: mode };
1655
+ });
1656
+ query(mode);
1657
+ };
1626
1658
  update(component, (draft) => {
1627
- draft.state = {
1628
- filters: component.state.filters,
1629
- search: component.state.search,
1630
- sections: []
1631
- };
1632
- draft.status = { type: "error", reason: mode, retry: () => query(mode) };
1659
+ if (mode === "search") {
1660
+ draft.state.sections = [];
1661
+ }
1662
+ draft.status = { type: "error", reason: mode, retry };
1633
1663
  });
1634
1664
  }
1635
1665
  });
@@ -1715,13 +1745,15 @@ var mergeSections = (existing, incoming) => {
1715
1745
  const knownIds = new Set(existing.map((section) => section.id));
1716
1746
  const newSections = incoming.filter((section) => !knownIds.has(section.id));
1717
1747
  const merged = existing.map((section) => {
1718
- var _a, _b;
1748
+ var _a, _b, _c, _d;
1719
1749
  const match = incoming.find((s) => s.id === section.id);
1720
1750
  if (!match) return section;
1721
1751
  return {
1722
1752
  id: match.id,
1723
1753
  title: (_a = match.title) != null ? _a : section.title,
1724
1754
  callToAction: (_b = match.callToAction) != null ? _b : section.callToAction,
1755
+ help: (_c = match.help) != null ? _c : section.help,
1756
+ inlineAlert: (_d = match.inlineAlert) != null ? _d : section.inlineAlert,
1725
1757
  items: [...section.items, ...match.items]
1726
1758
  };
1727
1759
  });
@@ -1843,10 +1875,11 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1843
1875
  var _a, _b, _c;
1844
1876
  return {
1845
1877
  sections: specState.sections.map((section) => {
1846
- return {
1847
- id: section.id,
1848
- title: section.title,
1878
+ var _a2;
1879
+ return __spreadProps(__spreadValues({}, section), {
1849
1880
  callToAction: getDomainLayerCallToAction(section.callToAction, mapperProps),
1881
+ help: (_a2 = section.help) == null ? void 0 : _a2.markdown,
1882
+ inlineAlert: mapInlineAlert(section.inlineAlert),
1850
1883
  items: section.items.map((item) => {
1851
1884
  const behavior = getDomainLayerBehavior(
1852
1885
  { behavior: item.primaryBehavior },
@@ -1862,24 +1895,29 @@ var mapCollectionSpecToDomainState = (specState, mapperProps, mapLayout) => {
1862
1895
  inlineAlert: mapInlineAlert(item.inlineAlert)
1863
1896
  });
1864
1897
  })
1865
- };
1898
+ });
1866
1899
  }),
1867
- filters: (_a = specState.filters) == null ? void 0 : _a.map((filter) => __spreadProps(__spreadValues({}, filter), {
1868
- options: filter.options.map((option) => {
1869
- var _a2;
1870
- return __spreadProps(__spreadValues({}, option), {
1871
- selected: (_a2 = option.selected) != null ? _a2 : false,
1872
- onSelect: () => {
1873
- }
1874
- // noop - this gets added during mapping
1875
- });
1876
- })
1877
- })),
1900
+ filters: (_a = specState.filters) == null ? void 0 : _a.map(mapFilter),
1878
1901
  beforeSections: (_b = specState.beforeSections) == null ? void 0 : _b.map(mapLayout),
1879
1902
  afterSections: (_c = specState.afterSections) == null ? void 0 : _c.map(mapLayout),
1880
1903
  nextCursor: specState.nextCursor
1881
1904
  };
1882
1905
  };
1906
+ var mapFilter = (filter) => {
1907
+ const anySelected = filter.options.some((option) => option.selected);
1908
+ return __spreadProps(__spreadValues({}, filter), {
1909
+ options: filter.options.map((option, index) => {
1910
+ var _a;
1911
+ return __spreadProps(__spreadValues({}, option), {
1912
+ // if a single select with no selection, we should default to selecting the first item
1913
+ selected: filter.multiSelect || anySelected ? (_a = option.selected) != null ? _a : false : index === 0,
1914
+ onSelect: () => {
1915
+ }
1916
+ // noop - this gets added during mapping in the component itself
1917
+ });
1918
+ })
1919
+ });
1920
+ };
1883
1921
 
1884
1922
  // src/domain/components/ButtonComponent.ts
1885
1923
  var createButtonComponent = (props) => __spreadValues({
@@ -1887,30 +1925,6 @@ var createButtonComponent = (props) => __spreadValues({
1887
1925
  kind: "layout"
1888
1926
  }, props);
1889
1927
 
1890
- // src/domain/mappers/utils/image.ts
1891
- var mapSpecImage = (image) => {
1892
- var _a, _b, _c;
1893
- return image ? {
1894
- uri: (_b = (_a = image.uri) != null ? _a : image.url) != null ? _b : "",
1895
- accessibilityDescription: (_c = image.accessibilityDescription) != null ? _c : image.text
1896
- } : void 0;
1897
- };
1898
-
1899
- // src/domain/mappers/utils/media-utils.ts
1900
- var getDomainLayerMedia = ({ icon, image, media }) => {
1901
- if (media) {
1902
- return media;
1903
- }
1904
- if (icon || image) {
1905
- return {
1906
- type: "legacy",
1907
- icon,
1908
- image: mapSpecImage(image)
1909
- };
1910
- }
1911
- return void 0;
1912
- };
1913
-
1914
1928
  // src/domain/mappers/layout/buttonLayoutToComponent.ts
1915
1929
  var buttonLayoutToComponent = (uid, button, mapperProps) => {
1916
1930
  if (!button.behavior && !button.action && mapperProps.features.isEnabled("strictButtonOperations")) {