@nuskin/react-search-sdk 1.1.0-pa-1255.2 → 1.1.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/dist/index.mjs CHANGED
@@ -104,6 +104,7 @@ async function fetchCommerceSearchConfig({
104
104
  }
105
105
 
106
106
  // src/hooks/useCommerceSearchConfig.ts
107
+ var MISSING_CLIENT_ID_HINT = "[search] The configuration could not be read and no clientId was passed to CommerceSearch, so the Configuration SDK used the run config of the page. If the page has none, pass the clientId prop: without a client id the search cannot read its configuration or its suggestions.";
107
108
  function useCommerceSearchConfig({
108
109
  country,
109
110
  language,
@@ -117,6 +118,7 @@ function useCommerceSearchConfig({
117
118
  currentMarket.current = market;
118
119
  }, [market]);
119
120
  const reading = useRef(null);
121
+ const hasHintedClientId = useRef(false);
120
122
  useEffect(() => {
121
123
  if (!isOpen || loaded?.market === market || reading.current === market) {
122
124
  return;
@@ -135,6 +137,10 @@ function useCommerceSearchConfig({
135
137
  "[search] Could not load the product search configuration:",
136
138
  error
137
139
  );
140
+ if (!clientId && !hasHintedClientId.current) {
141
+ hasHintedClientId.current = true;
142
+ console.error(MISSING_CLIENT_ID_HINT);
143
+ }
138
144
  }).finally(() => {
139
145
  if (reading.current === market) reading.current = null;
140
146
  });
@@ -551,6 +557,7 @@ function createSearchService(options) {
551
557
  return catalogRequestConfigPromise;
552
558
  }
553
559
  const service = {
560
+ maxSuggestions,
554
561
  async fetchSuggestions(searchTerm) {
555
562
  const trimmedSearchTerm = String(searchTerm ?? "").trim();
556
563
  if (!trimmedSearchTerm || trimmedSearchTerm.length < minimumSearchLength) {
@@ -629,7 +636,8 @@ var fetchMarketConfig = async ({
629
636
  // src/utils/gtmConstants.ts
630
637
  var SEARCH_GTM_EVENTS = {
631
638
  CHAT_ENTRY_POINT: "Begin_chat",
632
- PRODUCT_SEARCH: "ProductSearch"};
639
+ PRODUCT_SEARCH: "ProductSearch"
640
+ };
633
641
  var SEARCH_GTM_SEARCH_TYPES = {
634
642
  SEMANTIC: "semantic search"};
635
643
  var SEARCH_GTM_USER_STATUS = {
@@ -786,17 +794,6 @@ function useRecentSearches({
786
794
  }
787
795
 
788
796
  // src/utils/catalogStatus.ts
789
- var CART_DISABLED_PRODUCT_STATUSES = /* @__PURE__ */ new Set([
790
- "discontinued",
791
- "preview",
792
- "previewproduct",
793
- "test",
794
- "stopped",
795
- "replacement",
796
- "bundleonly",
797
- "inactive",
798
- "notavailable"
799
- ]);
800
797
  function normalizeProductStatusValue(value) {
801
798
  return String(value ?? "").trim().toLowerCase().replace(/\s+/g, "");
802
799
  }
@@ -809,9 +806,6 @@ function resolveSkuStatusValues(suggestionOption) {
809
806
  ].map(normalizeProductStatusValue).filter(Boolean);
810
807
  }
811
808
  function isNonSellableStatusValue(statusValue) {
812
- if (CART_DISABLED_PRODUCT_STATUSES.has(statusValue)) {
813
- return true;
814
- }
815
809
  return statusValue !== "sellable" && statusValue !== "active";
816
810
  }
817
811
  function isCartActionDisabled(suggestionOption) {
@@ -1049,38 +1043,21 @@ function getVisibleSuggestions(opts) {
1049
1043
 
1050
1044
  // src/hooks/useSearchSuggestions.ts
1051
1045
  function normalizeSuggestionsResponse(response) {
1052
- if (Array.isArray(response)) {
1046
+ if (Array.isArray(response.product)) {
1053
1047
  return {
1054
- suggestions: response,
1055
- didYouMean: []
1056
- };
1057
- }
1058
- if (!response || typeof response !== "object") {
1059
- return { suggestions: [], didYouMean: [] };
1060
- }
1061
- const r = response;
1062
- if (Array.isArray(r.product)) {
1063
- return {
1064
- suggestions: r.product.map(
1048
+ suggestions: response.product.map(
1065
1049
  (product, index) => mapCatalogProductToSuggestion(product, index)
1066
1050
  ).filter((item) => item !== null),
1067
- didYouMean: normalizeDidYouMean(r.didYouMean ?? r.did_you_mean)
1051
+ didYouMean: normalizeDidYouMean(
1052
+ response.didYouMean ?? response.did_you_mean
1053
+ )
1068
1054
  };
1069
1055
  }
1070
1056
  return {
1071
- suggestions: Array.isArray(r.suggestions) ? r.suggestions : [],
1072
- didYouMean: normalizeDidYouMean(r.didYouMean)
1057
+ suggestions: response.suggestions,
1058
+ didYouMean: normalizeDidYouMean(response.didYouMean)
1073
1059
  };
1074
1060
  }
1075
- function resolveTotalResultsCount2(response, fallback) {
1076
- if (typeof response.totalResultsCount === "number") {
1077
- return response.totalResultsCount;
1078
- }
1079
- if (typeof response.pageableInfo?.totalCount === "number") {
1080
- return response.pageableInfo.totalCount;
1081
- }
1082
- return fallback;
1083
- }
1084
1061
  var FETCH_FAILED = {
1085
1062
  suggestions: [],
1086
1063
  didYouMean: [],
@@ -1099,10 +1076,7 @@ function toSettledResults(response, maxSuggestions) {
1099
1076
  failed: false
1100
1077
  };
1101
1078
  }
1102
- const total = Math.max(
1103
- resolveTotalResultsCount2(response, allSuggestions.length),
1104
- allSuggestions.length
1105
- );
1079
+ const total = Math.max(response.totalResultsCount, allSuggestions.length);
1106
1080
  const suggestions = allSuggestions.slice(0, maxSuggestions);
1107
1081
  return {
1108
1082
  suggestions,
@@ -1114,9 +1088,9 @@ function toSettledResults(response, maxSuggestions) {
1114
1088
  }
1115
1089
  function useSearchSuggestions({
1116
1090
  service,
1117
- enabled = true,
1118
- maxSuggestions = DEFAULT_MAX_SUGGESTIONS
1091
+ enabled = true
1119
1092
  }) {
1093
+ const { maxSuggestions } = service;
1120
1094
  const [query, setQuery] = useState("");
1121
1095
  const [suggestions, setSuggestions] = useState([]);
1122
1096
  const [didYouMean, setDidYouMean] = useState([]);
@@ -1545,7 +1519,6 @@ function CommerceSearchView({
1545
1519
  agentProducts,
1546
1520
  logo,
1547
1521
  minimumSearchLength = MINIMUM_SEARCH_CHAR_LENGTH,
1548
- maxSuggestions = DEFAULT_MAX_SUGGESTIONS,
1549
1522
  gtmContext
1550
1523
  }) {
1551
1524
  const [handoff, setHandoff] = useState(null);
@@ -1553,7 +1526,6 @@ function CommerceSearchView({
1553
1526
  const [pendingTerm, setPendingTerm] = useState(null);
1554
1527
  const search = useSearchSuggestions({
1555
1528
  service,
1556
- maxSuggestions,
1557
1529
  enabled: isOpen && agentQuery === null
1558
1530
  });
1559
1531
  const {
@@ -1845,7 +1817,6 @@ function ValidMarketSearch({
1845
1817
  copy,
1846
1818
  logo,
1847
1819
  minimumSearchLength,
1848
- maxSuggestions,
1849
1820
  gtmContext
1850
1821
  }
1851
1822
  );