@nuskin/react-search-sdk 1.0.0-trying-again.7 → 1.0.0-trying-again.9

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/README.md CHANGED
@@ -51,8 +51,11 @@ import { CommerceSearch } from '@nuskin/react-search-sdk';
51
51
  | `language` | yes | ISO 639-1 language, for example `en`. |
52
52
  | `logo` | no | An element shown at the top of the panel. |
53
53
 
54
- The NUi agent also needs the `enableNuiSearch` cookie, or `?enableNuiSearch=true` in the URL, while
55
- that is the on/off switch. It is for signed-in visitors only, unless the configuration sets
54
+ The NUi agent also needs the `enableNuiSearch` flag, while that is the on/off switch: either
55
+ `?enableNuiSearch=true` in the URL of the page the panel is opened on, or a cookie `enableNuiSearch=true`
56
+ that you set by hand. The library only reads them and never copies the parameter into the cookie, so the
57
+ parameter applies to that page alone. If both are present the parameter wins, so `?enableNuiSearch=false`
58
+ switches the agent off for a page. It is for signed-in visitors only, unless the configuration sets
56
59
  `allowGuestAgent` (today only the test environment does, so the handoff can be tried where signing in
57
60
  is not possible).
58
61
 
package/dist/index.d.mts CHANGED
@@ -58,6 +58,6 @@ interface CommerceSearchProps {
58
58
  * The package works out the rest itself: the market's catalog lookup, the minimum search length,
59
59
  * which NUi app to use, the panel's text and the analytics fields.
60
60
  */
61
- declare function CommerceSearch({ isOpen, onClose, navigate, customer, country, language, logo, }: Readonly<CommerceSearchProps>): ReactElement;
61
+ declare function CommerceSearch({ isOpen, onClose, navigate, customer, country, language, logo, }: Readonly<CommerceSearchProps>): ReactElement | null;
62
62
 
63
63
  export { CommerceSearch, type CommerceSearchCustomer, type CommerceSearchProps, type CustomerAccountType, type NavigationTarget };
package/dist/index.d.ts CHANGED
@@ -58,6 +58,6 @@ interface CommerceSearchProps {
58
58
  * The package works out the rest itself: the market's catalog lookup, the minimum search length,
59
59
  * which NUi app to use, the panel's text and the analytics fields.
60
60
  */
61
- declare function CommerceSearch({ isOpen, onClose, navigate, customer, country, language, logo, }: Readonly<CommerceSearchProps>): ReactElement;
61
+ declare function CommerceSearch({ isOpen, onClose, navigate, customer, country, language, logo, }: Readonly<CommerceSearchProps>): ReactElement | null;
62
62
 
63
63
  export { CommerceSearch, type CommerceSearchCustomer, type CommerceSearchProps, type CustomerAccountType, type NavigationTarget };
package/dist/index.js CHANGED
@@ -100,6 +100,65 @@ function useCommerceSearchConfig({
100
100
  return config;
101
101
  }
102
102
 
103
+ // src/copy/searchPanelCopy.ts
104
+ var SEARCH_PANEL_COPY_EN = {
105
+ cancel: "Cancel",
106
+ searchPlaceholder: "Search",
107
+ didYouMean: "Did You Mean?",
108
+ noSuggestions: "No suggestions",
109
+ seeMoreResults: "See More Results",
110
+ recentSearches: "Recent searches",
111
+ clearRecentSearches: "Clear all",
112
+ moreRecentSearches: (count) => `+${count} More`,
113
+ searchLabel: "Search",
114
+ submitSearch: "Submit search",
115
+ clearInput: "Clear search",
116
+ suggestionsLabel: "Suggestions",
117
+ addToCart: (productName) => `Add ${productName} to cart`,
118
+ openBundle: (productName) => `Open bundle action for ${productName}`,
119
+ suggestionsLoading: "Loading suggestions",
120
+ suggestionsCount: (count) => `${count} suggestions available`
121
+ };
122
+
123
+ // src/copy/fetchSearchPanelCopy.ts
124
+ async function fetchSearchPanelCopy(_options = {}) {
125
+ return SEARCH_PANEL_COPY_EN;
126
+ }
127
+
128
+ // src/copy/loadSearchPanelCopy.ts
129
+ var copyByLanguage = /* @__PURE__ */ new Map();
130
+ function loadSearchPanelCopy(language) {
131
+ const key = (language ?? "").toLowerCase();
132
+ const cached = copyByLanguage.get(key);
133
+ if (cached) return cached;
134
+ const pending = fetchSearchPanelCopy(language ? { } : {});
135
+ copyByLanguage.set(key, pending);
136
+ pending.catch(() => copyByLanguage.delete(key));
137
+ return pending;
138
+ }
139
+
140
+ // src/hooks/useSearchPanelCopy.ts
141
+ function useSearchPanelCopy({
142
+ language
143
+ }) {
144
+ const [copy, setCopy] = react.useState(void 0);
145
+ react.useEffect(() => {
146
+ let isStale = false;
147
+ loadSearchPanelCopy(language).then((next) => {
148
+ if (!isStale) setCopy(next);
149
+ }).catch((error) => {
150
+ console.warn(
151
+ "[search] Could not load the search panel text:",
152
+ error
153
+ );
154
+ });
155
+ return () => {
156
+ isStale = true;
157
+ };
158
+ }, [language]);
159
+ return copy;
160
+ }
161
+
103
162
  // src/services/SearchApiService.ts
104
163
  function canUseStorage(storage) {
105
164
  return Boolean(storage) && typeof storage.getItem === "function";
@@ -1013,9 +1072,10 @@ function readCookieFlag(cookie) {
1013
1072
  const separator = part.indexOf("=");
1014
1073
  if (separator < 0) continue;
1015
1074
  if (part.slice(0, separator).trim() !== NUI_SEARCH_FLAG) continue;
1016
- const rawValue = part.slice(separator + 1);
1017
1075
  try {
1018
- return parseFlagValue(decodeURIComponent(rawValue));
1076
+ return parseFlagValue(
1077
+ decodeURIComponent(part.slice(separator + 1))
1078
+ );
1019
1079
  } catch {
1020
1080
  return void 0;
1021
1081
  }
@@ -1026,20 +1086,7 @@ function resolveNuiSearchFlag(env = {}) {
1026
1086
  const inBrowser = typeof window !== "undefined" && typeof document !== "undefined";
1027
1087
  const search = env.search ?? (inBrowser ? window.location.search : "");
1028
1088
  const cookie = env.cookie ?? (inBrowser ? document.cookie : "");
1029
- const setCookie = env.setCookie ?? (inBrowser ? (value) => {
1030
- document.cookie = value;
1031
- } : void 0);
1032
- const fromQuery = parseFlagValue(
1033
- new URLSearchParams(search).get(NUI_SEARCH_FLAG)
1034
- );
1035
- if (fromQuery !== void 0) {
1036
- const secure = inBrowser && window.location.protocol === "https:" ? "; Secure" : "";
1037
- setCookie?.(
1038
- `${NUI_SEARCH_FLAG}=${fromQuery}; path=/; SameSite=Lax${secure}`
1039
- );
1040
- return fromQuery;
1041
- }
1042
- return readCookieFlag(cookie);
1089
+ return parseFlagValue(new URLSearchParams(search).get(NUI_SEARCH_FLAG)) ?? readCookieFlag(cookie);
1043
1090
  }
1044
1091
  function isNuiSearchEnabled({
1045
1092
  isAuthenticated,
@@ -1209,6 +1256,7 @@ function uniqueRecentSearches(queries) {
1209
1256
  });
1210
1257
  }
1211
1258
  function CommerceSearchView({
1259
+ copy,
1212
1260
  isOpen,
1213
1261
  onClose,
1214
1262
  service,
@@ -1435,10 +1483,11 @@ function CommerceSearchView({
1435
1483
  );
1436
1484
  }
1437
1485
  return /* @__PURE__ */ jsxRuntime.jsx(
1438
- reactSearchComponents.SearchModal,
1486
+ reactSearchComponents.SearchPanel,
1439
1487
  {
1440
1488
  isOpen,
1441
1489
  onClose: close,
1490
+ copy,
1442
1491
  logo,
1443
1492
  input: {
1444
1493
  value: query,
@@ -1479,6 +1528,7 @@ function CommerceSearch({
1479
1528
  react.useEffect(() => {
1480
1529
  if (isOpen) setHasOpened(true);
1481
1530
  }, [isOpen]);
1531
+ const copy = useSearchPanelCopy({ language });
1482
1532
  const { minimumSearchLength, agent, allowGuestAgent } = useCommerceSearchConfig({
1483
1533
  country,
1484
1534
  language,
@@ -1520,6 +1570,7 @@ function CommerceSearch({
1520
1570
  language: language.toLowerCase()
1521
1571
  } : void 0;
1522
1572
  }, [country, language]);
1573
+ if (!copy) return null;
1523
1574
  return /* @__PURE__ */ jsxRuntime.jsx(
1524
1575
  CommerceSearchView,
1525
1576
  {
@@ -1531,6 +1582,7 @@ function CommerceSearch({
1531
1582
  ...agent ? { agent } : {},
1532
1583
  ...allowGuestAgent ? { allowGuestAgent } : {},
1533
1584
  ...agentProducts ? { agentProducts } : {},
1585
+ copy,
1534
1586
  logo,
1535
1587
  minimumSearchLength,
1536
1588
  gtmContext