@nuskin/react-search-sdk 1.0.0-trying-again.1 → 1.0.0-trying-again.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/README.md +59 -8
- package/dist/index.d.mts +43 -635
- package/dist/index.d.ts +43 -635
- package/dist/index.js +199 -213
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +196 -176
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
+
var configurationSdk = require('@nuskin/configuration-sdk');
|
|
4
5
|
var reactSearchComponents = require('@nuskin/react-search-components');
|
|
5
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var configurationSdk__default = /*#__PURE__*/_interopDefault(configurationSdk);
|
|
11
|
+
|
|
12
|
+
// src/components/CommerceSearch/CommerceSearch.tsx
|
|
13
|
+
var { getConfiguration, getEnvironmentCode } = configurationSdk__default.default;
|
|
14
|
+
|
|
7
15
|
// src/constants.ts
|
|
8
16
|
var STOREFRONT_SHOPPING_CONTEXT = "storefront";
|
|
9
17
|
var CATALOG_SUGGESTIONS_PATH = "/storefront/catalogs/search/suggestions";
|
|
@@ -13,13 +21,77 @@ var DEFAULT_SUGGESTION_PAGE = 1;
|
|
|
13
21
|
var DEFAULT_SUGGESTION_SIZE = 6;
|
|
14
22
|
var DEFAULT_SEARCH_PATH = "/search";
|
|
15
23
|
var DEBOUNCE_MS = 220;
|
|
24
|
+
var MINIMUM_SEARCH_CHAR_LENGTH = 2;
|
|
16
25
|
var MAX_VISIBLE_SUGGESTIONS = 6;
|
|
17
|
-
var
|
|
18
|
-
var
|
|
26
|
+
var EQUINOX_MARKETS_MAP = "Equinox_Markets";
|
|
27
|
+
var DEFAULT_EQUINOX_CLIENT_ID = "63056848d7532f9923f3d08cb48c423b";
|
|
28
|
+
|
|
29
|
+
// src/config/commerceSearchConfig.ts
|
|
30
|
+
var COMMERCE_SEARCH_CONFIG_DEFAULTS = Object.freeze({
|
|
31
|
+
minimumSearchLength: MINIMUM_SEARCH_CHAR_LENGTH
|
|
32
|
+
});
|
|
33
|
+
var TEST_ENVIRONMENT_VALUES = {
|
|
34
|
+
agent: {
|
|
35
|
+
appKey: "pk_commerce_product_advisor_624aea4305b09240e8c8f41d0f6527b2",
|
|
36
|
+
apiBaseUrl: "https://nui.tst.nuskin.ai/"
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
function nonEmptyString(value) {
|
|
40
|
+
return typeof value === "string" ? value.trim() : "";
|
|
41
|
+
}
|
|
42
|
+
function normalizeCommerceSearchConfig(raw, { language } = {}) {
|
|
43
|
+
const minimumSearchLength = Number(raw?.minimumSearchLength);
|
|
44
|
+
const appKey = nonEmptyString(raw?.agent?.appKey);
|
|
45
|
+
const apiBaseUrl = nonEmptyString(raw?.agent?.apiBaseUrl);
|
|
46
|
+
return {
|
|
47
|
+
minimumSearchLength: Number.isInteger(minimumSearchLength) && minimumSearchLength >= 1 ? minimumSearchLength : COMMERCE_SEARCH_CONFIG_DEFAULTS.minimumSearchLength,
|
|
48
|
+
...appKey && apiBaseUrl ? {
|
|
49
|
+
agent: {
|
|
50
|
+
appKey,
|
|
51
|
+
apiBaseUrl,
|
|
52
|
+
...language ? { language } : {}
|
|
53
|
+
}
|
|
54
|
+
} : {}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function fetchCommerceSearchConfig({
|
|
58
|
+
language
|
|
59
|
+
} = {}) {
|
|
60
|
+
const raw = getEnvironmentCode() === "test" ? TEST_ENVIRONMENT_VALUES : {};
|
|
61
|
+
return normalizeCommerceSearchConfig(raw, language ? { language } : {});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/hooks/useCommerceSearchConfig.ts
|
|
65
|
+
function useCommerceSearchConfig({
|
|
66
|
+
country,
|
|
67
|
+
language,
|
|
68
|
+
enabled
|
|
69
|
+
}) {
|
|
70
|
+
const [config, setConfig] = react.useState(
|
|
71
|
+
COMMERCE_SEARCH_CONFIG_DEFAULTS
|
|
72
|
+
);
|
|
73
|
+
react.useEffect(() => {
|
|
74
|
+
if (!enabled) return void 0;
|
|
75
|
+
let isStale = false;
|
|
76
|
+
fetchCommerceSearchConfig({
|
|
77
|
+
...country ? { country } : {},
|
|
78
|
+
...language ? { language } : {}
|
|
79
|
+
}).then((next) => {
|
|
80
|
+
if (!isStale) setConfig(next);
|
|
81
|
+
}).catch((error) => {
|
|
82
|
+
console.warn(
|
|
83
|
+
"[search] Could not load the product search configuration:",
|
|
84
|
+
error
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
return () => {
|
|
88
|
+
isStale = true;
|
|
89
|
+
};
|
|
90
|
+
}, [enabled, country, language]);
|
|
91
|
+
return config;
|
|
92
|
+
}
|
|
19
93
|
|
|
20
94
|
// src/services/SearchApiService.ts
|
|
21
|
-
var DEFAULT_SEARCH_PLACEHOLDER = TRIGGER_PLACEHOLDER;
|
|
22
|
-
var DEFAULT_INPUT_ARIA_LABEL = SEARCH_PLACEHOLDER;
|
|
23
95
|
function canUseStorage(storage) {
|
|
24
96
|
return Boolean(storage) && typeof storage.getItem === "function";
|
|
25
97
|
}
|
|
@@ -38,7 +110,7 @@ function normalizeLocaleParts({
|
|
|
38
110
|
country,
|
|
39
111
|
language,
|
|
40
112
|
locale
|
|
41
|
-
}
|
|
113
|
+
}) {
|
|
42
114
|
const normalizedCountry = String(country ?? "").trim().toUpperCase();
|
|
43
115
|
const normalizedLanguage = String(language ?? "").trim().toLowerCase();
|
|
44
116
|
const normalizedLocale = String(locale ?? "").trim() || "UNKNOWN";
|
|
@@ -229,14 +301,18 @@ function resolveOptionHref(option, localeParts) {
|
|
|
229
301
|
}
|
|
230
302
|
return "";
|
|
231
303
|
}
|
|
232
|
-
|
|
304
|
+
function resolveCustomerTypeHeaders(getCustomerType) {
|
|
305
|
+
const customerType = getCustomerType?.()?.trim();
|
|
306
|
+
return customerType ? { "X-Customer-Type": customerType } : void 0;
|
|
307
|
+
}
|
|
308
|
+
async function fetchJsonFromCandidates(fetchImpl, requestUrls, requestHeaders = {}) {
|
|
233
309
|
let lastError;
|
|
234
310
|
for (const requestUrl of requestUrls) {
|
|
235
311
|
try {
|
|
236
312
|
const response = await fetchImpl(requestUrl, {
|
|
237
313
|
method: "GET",
|
|
238
314
|
credentials: "include",
|
|
239
|
-
headers: { Accept: "application/json" }
|
|
315
|
+
headers: { Accept: "application/json", ...requestHeaders }
|
|
240
316
|
});
|
|
241
317
|
if (!response.ok) {
|
|
242
318
|
lastError = new Error(
|
|
@@ -261,9 +337,9 @@ function createSearchService(options = {}) {
|
|
|
261
337
|
country,
|
|
262
338
|
language,
|
|
263
339
|
locale,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
340
|
+
getMarketConfig,
|
|
341
|
+
getCustomerType,
|
|
342
|
+
minimumSearchLength = MINIMUM_SEARCH_CHAR_LENGTH
|
|
267
343
|
} = options;
|
|
268
344
|
const fetchImpl = fetchImplOption !== void 0 ? fetchImplOption : typeof fetch === "function" ? fetch.bind(globalThis) : null;
|
|
269
345
|
const locationLike = getBrowserLocation(providedLocation);
|
|
@@ -283,15 +359,9 @@ function createSearchService(options = {}) {
|
|
|
283
359
|
return catalogRequestConfigPromise;
|
|
284
360
|
}
|
|
285
361
|
const service = {
|
|
286
|
-
async getSearchChromeCopy() {
|
|
287
|
-
return {
|
|
288
|
-
placeholder: searchPlaceholder || DEFAULT_SEARCH_PLACEHOLDER,
|
|
289
|
-
inputAriaLabel: inputAriaLabel || DEFAULT_INPUT_ARIA_LABEL
|
|
290
|
-
};
|
|
291
|
-
},
|
|
292
362
|
async fetchSuggestions(searchTerm) {
|
|
293
363
|
const trimmedSearchTerm = String(searchTerm ?? "").trim();
|
|
294
|
-
if (!trimmedSearchTerm || !fetchImpl) {
|
|
364
|
+
if (!trimmedSearchTerm || trimmedSearchTerm.length < minimumSearchLength || !fetchImpl) {
|
|
295
365
|
return {
|
|
296
366
|
suggestions: [],
|
|
297
367
|
didYouMean: [],
|
|
@@ -316,7 +386,8 @@ function createSearchService(options = {}) {
|
|
|
316
386
|
const requestUrls = [`${suggestionsUrl}?${queryParams.toString()}`];
|
|
317
387
|
const responsePayload = await fetchJsonFromCandidates(
|
|
318
388
|
fetchImpl,
|
|
319
|
-
requestUrls
|
|
389
|
+
requestUrls,
|
|
390
|
+
resolveCustomerTypeHeaders(getCustomerType)
|
|
320
391
|
);
|
|
321
392
|
const suggestionsField = Array.isArray(responsePayload?.suggestions) ? responsePayload?.suggestions : [];
|
|
322
393
|
const productField = Array.isArray(responsePayload?.product) ? responsePayload?.product : null;
|
|
@@ -348,33 +419,6 @@ function createSearchService(options = {}) {
|
|
|
348
419
|
return stripLocalePrefix(targetPath, localeParts);
|
|
349
420
|
},
|
|
350
421
|
activateSuggestionAction(option) {
|
|
351
|
-
if (options.onSuggestionAction) {
|
|
352
|
-
const result = options.onSuggestionAction(option);
|
|
353
|
-
if (result instanceof Promise) {
|
|
354
|
-
result.then((handled) => {
|
|
355
|
-
if (!handled) {
|
|
356
|
-
const optionHref2 = resolveOptionHref(
|
|
357
|
-
option,
|
|
358
|
-
localeParts
|
|
359
|
-
);
|
|
360
|
-
if (!optionHref2) {
|
|
361
|
-
const optionQuery2 = option?.value ?? option?.label ?? option?.identifier ?? "";
|
|
362
|
-
service.submitProductSearch(
|
|
363
|
-
String(optionQuery2)
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}).catch((error) => {
|
|
368
|
-
console.error(
|
|
369
|
-
"Error in onSuggestionAction:",
|
|
370
|
-
error
|
|
371
|
-
);
|
|
372
|
-
});
|
|
373
|
-
return "action-pending";
|
|
374
|
-
} else if (result === true) {
|
|
375
|
-
return "action-handled";
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
422
|
const optionHref = resolveOptionHref(option, localeParts);
|
|
379
423
|
if (optionHref) {
|
|
380
424
|
return stripLocalePrefix(optionHref, localeParts);
|
|
@@ -401,6 +445,35 @@ function createSearchService(options = {}) {
|
|
|
401
445
|
return service;
|
|
402
446
|
}
|
|
403
447
|
|
|
448
|
+
// src/services/marketConfig.ts
|
|
449
|
+
var fetchMarketConfig = async ({ country }) => {
|
|
450
|
+
const countryCode = String(country ?? "").trim().toUpperCase() || "US";
|
|
451
|
+
const configuration = await getConfiguration([EQUINOX_MARKETS_MAP], {
|
|
452
|
+
country: countryCode,
|
|
453
|
+
...getEnvironmentCode() ? { environment: getEnvironmentCode() } : {},
|
|
454
|
+
clientId: DEFAULT_EQUINOX_CLIENT_ID,
|
|
455
|
+
shoppingContext: STOREFRONT_SHOPPING_CONTEXT
|
|
456
|
+
});
|
|
457
|
+
return configuration?.[EQUINOX_MARKETS_MAP] ?? null;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// src/utils/gtmConstants.ts
|
|
461
|
+
var SEARCH_GTM_EVENTS = {
|
|
462
|
+
CHAT_ENTRY_POINT: "Begin_chat",
|
|
463
|
+
PRODUCT_SEARCH: "ProductSearch"};
|
|
464
|
+
var SEARCH_GTM_SEARCH_TYPES = {
|
|
465
|
+
SEMANTIC: "semantic search"};
|
|
466
|
+
var SEARCH_GTM_USER_STATUS = {
|
|
467
|
+
GUEST: "guest",
|
|
468
|
+
LOGGED_IN: "logged_in"
|
|
469
|
+
};
|
|
470
|
+
var GTM_FALLBACK_NA = "NA";
|
|
471
|
+
|
|
472
|
+
// src/utils/navigationTarget.ts
|
|
473
|
+
function toNavigationTarget(path) {
|
|
474
|
+
return /^https?:\/\//i.test(path) ? { type: "external", url: path } : { type: "internal", path };
|
|
475
|
+
}
|
|
476
|
+
|
|
404
477
|
// src/utils/catalogHelpers.ts
|
|
405
478
|
var CART_DISABLED_PRODUCT_STATUSES = /* @__PURE__ */ new Set([
|
|
406
479
|
"discontinued",
|
|
@@ -416,9 +489,6 @@ var CART_DISABLED_PRODUCT_STATUSES = /* @__PURE__ */ new Set([
|
|
|
416
489
|
function normalizeProductStatusValue(value) {
|
|
417
490
|
return String(value ?? "").trim().toLowerCase().replace(/\s+/g, "");
|
|
418
491
|
}
|
|
419
|
-
function isSellableProductStatus(productStatus) {
|
|
420
|
-
return normalizeProductStatusValue(productStatus) === "sellable";
|
|
421
|
-
}
|
|
422
492
|
function resolveSkuStatusValues(suggestionOption) {
|
|
423
493
|
return [
|
|
424
494
|
suggestionOption["productStatus"],
|
|
@@ -663,14 +733,6 @@ function getVisibleSuggestions(opts) {
|
|
|
663
733
|
}
|
|
664
734
|
return opts.suggestions;
|
|
665
735
|
}
|
|
666
|
-
function getSeeMoreResultsPayload(query, totalResultsCount, suggestions) {
|
|
667
|
-
return {
|
|
668
|
-
query,
|
|
669
|
-
source: "autocomplete-footer",
|
|
670
|
-
totalResultsCount,
|
|
671
|
-
visibleResultsCount: suggestions.length
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
736
|
|
|
675
737
|
// src/hooks/useSearchSuggestions.ts
|
|
676
738
|
function normalizeSuggestionsResponse(response) {
|
|
@@ -828,26 +890,6 @@ function useSearchSuggestions({
|
|
|
828
890
|
};
|
|
829
891
|
}
|
|
830
892
|
|
|
831
|
-
// src/utils/gtmConstants.ts
|
|
832
|
-
var SEARCH_GTM_EVENTS = {
|
|
833
|
-
CHAT_ENTRY_POINT: "Begin_chat",
|
|
834
|
-
SEARCH_TYPE: "Search_Type",
|
|
835
|
-
PRODUCT_SEARCH: "ProductSearch",
|
|
836
|
-
ERROR_POPUP: "Error_popup"
|
|
837
|
-
};
|
|
838
|
-
var SEARCH_GTM_SEARCH_TYPES = {
|
|
839
|
-
SEMANTIC: "semantic search",
|
|
840
|
-
AI_AGENT: "AI agent"
|
|
841
|
-
};
|
|
842
|
-
var SEARCH_GTM_USER_STATUS = {
|
|
843
|
-
GUEST: "guest",
|
|
844
|
-
LOGGED_IN: "logged_in"
|
|
845
|
-
};
|
|
846
|
-
var IS_AUTHENTICATED_KEY = "IsAuthenticated";
|
|
847
|
-
var ACCOUNT_TYPE_KEY = "accountType";
|
|
848
|
-
var NUSKIN_ACCOUNT_DATA_KEY = "nuskin.account.data";
|
|
849
|
-
var GTM_FALLBACK_NA = "NA";
|
|
850
|
-
|
|
851
893
|
// src/utils/commonUtils.ts
|
|
852
894
|
var IS_BROWSER = typeof window !== "undefined";
|
|
853
895
|
function toEventString(value, fallback = " ") {
|
|
@@ -855,84 +897,24 @@ function toEventString(value, fallback = " ") {
|
|
|
855
897
|
const str = String(value).trim();
|
|
856
898
|
return str.length > 0 ? str : fallback;
|
|
857
899
|
}
|
|
858
|
-
function getLocaleFromUrl(pathname) {
|
|
859
|
-
const path = pathname ?? (IS_BROWSER ? window.location.pathname : "");
|
|
860
|
-
const [country, language] = path.split("/").filter(Boolean);
|
|
861
|
-
if (!/^[a-z]{2}$/i.test(country ?? "") || !/^[a-z]{2}$/i.test(language ?? "")) {
|
|
862
|
-
return {};
|
|
863
|
-
}
|
|
864
|
-
return {
|
|
865
|
-
countryCode: country.toUpperCase(),
|
|
866
|
-
language: language.toLowerCase()
|
|
867
|
-
};
|
|
868
|
-
}
|
|
869
|
-
function safeParse(raw) {
|
|
870
|
-
try {
|
|
871
|
-
return JSON.parse(raw);
|
|
872
|
-
} catch {
|
|
873
|
-
return raw;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
function getLocalStorage(key) {
|
|
877
|
-
if (!IS_BROWSER) return void 0;
|
|
878
|
-
try {
|
|
879
|
-
const raw = window.localStorage.getItem(key);
|
|
880
|
-
return raw === null ? void 0 : safeParse(raw);
|
|
881
|
-
} catch {
|
|
882
|
-
return void 0;
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
900
|
|
|
886
901
|
// src/utils/gtmTracking.ts
|
|
887
|
-
function readUserStatusFromStorage() {
|
|
888
|
-
const value = getLocalStorage(IS_AUTHENTICATED_KEY);
|
|
889
|
-
if (value === void 0) return void 0;
|
|
890
|
-
if (value === SEARCH_GTM_USER_STATUS.GUEST || value === SEARCH_GTM_USER_STATUS.LOGGED_IN) {
|
|
891
|
-
return value;
|
|
892
|
-
}
|
|
893
|
-
const isAuthenticated = value === true || typeof value === "string" && ["true", "1", "yes", "y"].includes(value.toLowerCase().trim());
|
|
894
|
-
return isAuthenticated ? SEARCH_GTM_USER_STATUS.LOGGED_IN : SEARCH_GTM_USER_STATUS.GUEST;
|
|
895
|
-
}
|
|
896
|
-
function readAccountTypeFromStorage() {
|
|
897
|
-
const value = getLocalStorage(ACCOUNT_TYPE_KEY);
|
|
898
|
-
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
899
|
-
}
|
|
900
|
-
function readUserIdFromStorage() {
|
|
901
|
-
const raw = getLocalStorage(NUSKIN_ACCOUNT_DATA_KEY);
|
|
902
|
-
if (!raw || typeof raw !== "object") return void 0;
|
|
903
|
-
const user = raw.user;
|
|
904
|
-
if (!user || typeof user !== "object") return void 0;
|
|
905
|
-
const id = user.id;
|
|
906
|
-
return typeof id === "string" && id.trim().length > 0 ? id : void 0;
|
|
907
|
-
}
|
|
908
902
|
function resolveUserId(explicit) {
|
|
909
|
-
return toEventString(explicit
|
|
903
|
+
return toEventString(explicit, GTM_FALLBACK_NA);
|
|
910
904
|
}
|
|
911
905
|
function baseEventPayload(ctx) {
|
|
912
|
-
const urlLocale = getLocaleFromUrl();
|
|
913
|
-
const userStatus = ctx.userStatus ?? readUserStatusFromStorage();
|
|
914
|
-
const accountType = ctx.accountType ?? readAccountTypeFromStorage();
|
|
915
|
-
const resolvedUserStatus = userStatus ?? SEARCH_GTM_USER_STATUS.GUEST;
|
|
916
|
-
const documentTitle = IS_BROWSER && typeof document?.title === "string" ? document.title : void 0;
|
|
917
906
|
return {
|
|
918
907
|
Chat_ID: toEventString(ctx.chatId, GTM_FALLBACK_NA),
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
),
|
|
923
|
-
|
|
924
|
-
ctx.countryCode ?? urlLocale.countryCode,
|
|
925
|
-
GTM_FALLBACK_NA
|
|
926
|
-
),
|
|
927
|
-
language: toEventString(
|
|
928
|
-
ctx.language ?? urlLocale.language,
|
|
929
|
-
GTM_FALLBACK_NA
|
|
930
|
-
),
|
|
908
|
+
// TODO: COMX-3277 puts `page_type` in every event but defines no values. Send `NA` until
|
|
909
|
+
// the data team says what it should hold (perhaps the page path).
|
|
910
|
+
page_type: GTM_FALLBACK_NA,
|
|
911
|
+
country_code: toEventString(ctx.countryCode, GTM_FALLBACK_NA),
|
|
912
|
+
language: toEventString(ctx.language, GTM_FALLBACK_NA),
|
|
931
913
|
user_status: toEventString(
|
|
932
|
-
|
|
914
|
+
ctx.userStatus ?? SEARCH_GTM_USER_STATUS.GUEST,
|
|
933
915
|
SEARCH_GTM_USER_STATUS.GUEST
|
|
934
916
|
),
|
|
935
|
-
account_type: toEventString(accountType, GTM_FALLBACK_NA)
|
|
917
|
+
account_type: toEventString(ctx.accountType, GTM_FALLBACK_NA)
|
|
936
918
|
};
|
|
937
919
|
}
|
|
938
920
|
function serializeProductResults(productResultsData, productResults) {
|
|
@@ -965,15 +947,6 @@ function trackChatEntryPoint(ctx) {
|
|
|
965
947
|
...baseEventPayload(ctx)
|
|
966
948
|
});
|
|
967
949
|
}
|
|
968
|
-
function trackSearchType(input) {
|
|
969
|
-
pushGtmEvent({
|
|
970
|
-
event: SEARCH_GTM_EVENTS.SEARCH_TYPE,
|
|
971
|
-
...baseEventPayload(input),
|
|
972
|
-
id: resolveUserId(input.userId),
|
|
973
|
-
type: input.searchType ?? SEARCH_GTM_SEARCH_TYPES.SEMANTIC,
|
|
974
|
-
search_response: toEventString(input.searchResponse, GTM_FALLBACK_NA)
|
|
975
|
-
});
|
|
976
|
-
}
|
|
977
950
|
function trackProductSearch(input) {
|
|
978
951
|
pushGtmEvent({
|
|
979
952
|
event: SEARCH_GTM_EVENTS.PRODUCT_SEARCH,
|
|
@@ -986,14 +959,6 @@ function trackProductSearch(input) {
|
|
|
986
959
|
)
|
|
987
960
|
});
|
|
988
961
|
}
|
|
989
|
-
function trackErrorPopup(input) {
|
|
990
|
-
pushGtmEvent({
|
|
991
|
-
event: SEARCH_GTM_EVENTS.ERROR_POPUP,
|
|
992
|
-
...baseEventPayload(input),
|
|
993
|
-
id: resolveUserId(input.userId),
|
|
994
|
-
search_type: input.searchType ?? SEARCH_GTM_SEARCH_TYPES.SEMANTIC
|
|
995
|
-
});
|
|
996
|
-
}
|
|
997
962
|
|
|
998
963
|
// src/utils/nuiSearchGate.ts
|
|
999
964
|
var NUI_SEARCH_FLAG = "enableNuiSearch";
|
|
@@ -1150,7 +1115,7 @@ function uniqueRecentSearches(queries) {
|
|
|
1150
1115
|
return true;
|
|
1151
1116
|
});
|
|
1152
1117
|
}
|
|
1153
|
-
function
|
|
1118
|
+
function CommerceSearchView({
|
|
1154
1119
|
isOpen,
|
|
1155
1120
|
onClose,
|
|
1156
1121
|
service,
|
|
@@ -1158,9 +1123,7 @@ function ProductSearch({
|
|
|
1158
1123
|
isAuthenticated,
|
|
1159
1124
|
agent,
|
|
1160
1125
|
logo,
|
|
1161
|
-
|
|
1162
|
-
fallbackImageUrl,
|
|
1163
|
-
copy,
|
|
1126
|
+
minimumSearchLength = MINIMUM_SEARCH_CHAR_LENGTH,
|
|
1164
1127
|
gtmContext
|
|
1165
1128
|
}) {
|
|
1166
1129
|
const [flag, setFlag] = react.useState(void 0);
|
|
@@ -1184,7 +1147,7 @@ function ProductSearch({
|
|
|
1184
1147
|
suggestions,
|
|
1185
1148
|
updateQuery
|
|
1186
1149
|
} = search;
|
|
1187
|
-
const enabled = isNuiSearchEnabled({ isAuthenticated, flag });
|
|
1150
|
+
const enabled = agent !== void 0 && isNuiSearchEnabled({ isAuthenticated, flag });
|
|
1188
1151
|
const items = getVisibleSuggestions({
|
|
1189
1152
|
didYouMean,
|
|
1190
1153
|
suggestions
|
|
@@ -1215,9 +1178,7 @@ function ProductSearch({
|
|
|
1215
1178
|
}, [isOpen, clearQuery]);
|
|
1216
1179
|
const navigateTo = react.useCallback(
|
|
1217
1180
|
(path) => {
|
|
1218
|
-
if (!path
|
|
1219
|
-
return;
|
|
1220
|
-
}
|
|
1181
|
+
if (!path) return;
|
|
1221
1182
|
navigate(path);
|
|
1222
1183
|
close();
|
|
1223
1184
|
},
|
|
@@ -1272,6 +1233,10 @@ function ProductSearch({
|
|
|
1272
1233
|
(value) => {
|
|
1273
1234
|
const term = value.trim();
|
|
1274
1235
|
if (!term) return;
|
|
1236
|
+
if (term.length < minimumSearchLength) {
|
|
1237
|
+
runSearch(term);
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1275
1240
|
const route = decide(term);
|
|
1276
1241
|
if (route === "wait") {
|
|
1277
1242
|
setPendingTerm(term);
|
|
@@ -1279,7 +1244,7 @@ function ProductSearch({
|
|
|
1279
1244
|
}
|
|
1280
1245
|
act(term, route);
|
|
1281
1246
|
},
|
|
1282
|
-
[act, decide]
|
|
1247
|
+
[act, decide, minimumSearchLength, runSearch]
|
|
1283
1248
|
);
|
|
1284
1249
|
const latest = react.useRef({ act, decide });
|
|
1285
1250
|
latest.current = { act, decide };
|
|
@@ -1358,9 +1323,6 @@ function ProductSearch({
|
|
|
1358
1323
|
isOpen,
|
|
1359
1324
|
onClose: close,
|
|
1360
1325
|
logo,
|
|
1361
|
-
...cancelLabel === void 0 ? {} : { cancelLabel },
|
|
1362
|
-
...fallbackImageUrl === void 0 ? {} : { fallbackImageUrl },
|
|
1363
|
-
...copy === void 0 ? {} : { copy },
|
|
1364
1326
|
input: {
|
|
1365
1327
|
value: query,
|
|
1366
1328
|
onChange: updateQuery,
|
|
@@ -1382,7 +1344,7 @@ function ProductSearch({
|
|
|
1382
1344
|
onSelect: handleRecentSelect,
|
|
1383
1345
|
onClear: handleClearRecent
|
|
1384
1346
|
},
|
|
1385
|
-
agentPanel: handoff === null ? void 0 : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1347
|
+
agentPanel: handoff === null || agent === void 0 ? void 0 : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1386
1348
|
NuiAgentPanel,
|
|
1387
1349
|
{
|
|
1388
1350
|
agent,
|
|
@@ -1399,45 +1361,69 @@ function ProductSearch({
|
|
|
1399
1361
|
}
|
|
1400
1362
|
);
|
|
1401
1363
|
}
|
|
1364
|
+
var GUEST = "guest";
|
|
1365
|
+
function CommerceSearch({
|
|
1366
|
+
isOpen,
|
|
1367
|
+
onClose,
|
|
1368
|
+
navigate,
|
|
1369
|
+
customer,
|
|
1370
|
+
country,
|
|
1371
|
+
language,
|
|
1372
|
+
logo
|
|
1373
|
+
}) {
|
|
1374
|
+
const [hasOpened, setHasOpened] = react.useState(false);
|
|
1375
|
+
react.useEffect(() => {
|
|
1376
|
+
if (isOpen) setHasOpened(true);
|
|
1377
|
+
}, [isOpen]);
|
|
1378
|
+
const { minimumSearchLength, agent } = useCommerceSearchConfig({
|
|
1379
|
+
country,
|
|
1380
|
+
language,
|
|
1381
|
+
enabled: hasOpened
|
|
1382
|
+
});
|
|
1383
|
+
const customerTypeRef = react.useRef(GUEST);
|
|
1384
|
+
customerTypeRef.current = customer.isAuthenticated ? customer.accountType ?? GUEST : GUEST;
|
|
1385
|
+
const service = react.useMemo(
|
|
1386
|
+
() => createSearchService({
|
|
1387
|
+
country,
|
|
1388
|
+
language,
|
|
1389
|
+
locale: `${country.toUpperCase()}-${language.toLowerCase()}`,
|
|
1390
|
+
getMarketConfig: fetchMarketConfig,
|
|
1391
|
+
minimumSearchLength,
|
|
1392
|
+
getCustomerType: () => customerTypeRef.current
|
|
1393
|
+
}),
|
|
1394
|
+
[country, language, minimumSearchLength]
|
|
1395
|
+
);
|
|
1396
|
+
const navigateToPath = react.useCallback(
|
|
1397
|
+
(path) => navigate(toNavigationTarget(path)),
|
|
1398
|
+
[navigate]
|
|
1399
|
+
);
|
|
1400
|
+
const { isAuthenticated, accountType, userId } = customer;
|
|
1401
|
+
const gtmContext = react.useMemo(
|
|
1402
|
+
() => ({
|
|
1403
|
+
countryCode: country,
|
|
1404
|
+
language,
|
|
1405
|
+
userStatus: isAuthenticated ? SEARCH_GTM_USER_STATUS.LOGGED_IN : SEARCH_GTM_USER_STATUS.GUEST,
|
|
1406
|
+
...isAuthenticated && accountType ? { accountType } : {},
|
|
1407
|
+
...isAuthenticated && userId ? { userId } : {}
|
|
1408
|
+
}),
|
|
1409
|
+
[country, language, isAuthenticated, accountType, userId]
|
|
1410
|
+
);
|
|
1411
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1412
|
+
CommerceSearchView,
|
|
1413
|
+
{
|
|
1414
|
+
isOpen,
|
|
1415
|
+
onClose,
|
|
1416
|
+
service,
|
|
1417
|
+
navigate: navigateToPath,
|
|
1418
|
+
isAuthenticated,
|
|
1419
|
+
...agent ? { agent } : {},
|
|
1420
|
+
logo,
|
|
1421
|
+
minimumSearchLength,
|
|
1422
|
+
gtmContext
|
|
1423
|
+
}
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1402
1426
|
|
|
1403
|
-
exports.
|
|
1404
|
-
exports.DEBOUNCE_MS = DEBOUNCE_MS;
|
|
1405
|
-
exports.DEFAULT_SEARCH_PATH = DEFAULT_SEARCH_PATH;
|
|
1406
|
-
exports.DEFAULT_SUGGESTION_PAGE = DEFAULT_SUGGESTION_PAGE;
|
|
1407
|
-
exports.DEFAULT_SUGGESTION_SIZE = DEFAULT_SUGGESTION_SIZE;
|
|
1408
|
-
exports.MAX_VISIBLE_SUGGESTIONS = MAX_VISIBLE_SUGGESTIONS;
|
|
1409
|
-
exports.NUI_SEARCH_FLAG = NUI_SEARCH_FLAG;
|
|
1410
|
-
exports.ProductSearch = ProductSearch;
|
|
1411
|
-
exports.RECENT_SEARCHES_DEFAULT_LIMIT = RECENT_SEARCHES_DEFAULT_LIMIT;
|
|
1412
|
-
exports.RECENT_SEARCHES_PREFIX = RECENT_SEARCHES_PREFIX;
|
|
1413
|
-
exports.SEARCH_GTM_EVENTS = SEARCH_GTM_EVENTS;
|
|
1414
|
-
exports.SEARCH_GTM_SEARCH_TYPES = SEARCH_GTM_SEARCH_TYPES;
|
|
1415
|
-
exports.SEARCH_GTM_USER_STATUS = SEARCH_GTM_USER_STATUS;
|
|
1416
|
-
exports.SEARCH_PLACEHOLDER = SEARCH_PLACEHOLDER;
|
|
1417
|
-
exports.STOREFRONT_SHOPPING_CONTEXT = STOREFRONT_SHOPPING_CONTEXT;
|
|
1418
|
-
exports.SUBMIT_WAIT_TIMEOUT_MS = SUBMIT_WAIT_TIMEOUT_MS;
|
|
1419
|
-
exports.TRIGGER_PLACEHOLDER = TRIGGER_PLACEHOLDER;
|
|
1420
|
-
exports.createSearchService = createSearchService;
|
|
1421
|
-
exports.decideSearchRoute = decideSearchRoute;
|
|
1422
|
-
exports.getImageFromProperty = getImageFromProperty;
|
|
1423
|
-
exports.getIngredientTerms = getIngredientTerms;
|
|
1424
|
-
exports.getLocaleFromUrl = getLocaleFromUrl;
|
|
1425
|
-
exports.getSeeMoreResultsPayload = getSeeMoreResultsPayload;
|
|
1426
|
-
exports.getVisibleSuggestions = getVisibleSuggestions;
|
|
1427
|
-
exports.isCartActionDisabled = isCartActionDisabled;
|
|
1428
|
-
exports.isNuiSearchEnabled = isNuiSearchEnabled;
|
|
1429
|
-
exports.isSellableProductStatus = isSellableProductStatus;
|
|
1430
|
-
exports.isSuggestionDisabled = isSuggestionDisabled;
|
|
1431
|
-
exports.mapCatalogProductToSuggestion = mapCatalogProductToSuggestion;
|
|
1432
|
-
exports.normalizeDidYouMean = normalizeDidYouMean;
|
|
1433
|
-
exports.pushGtmEvent = pushGtmEvent;
|
|
1434
|
-
exports.resolveApiGatewayPath = resolveApiGatewayPath;
|
|
1435
|
-
exports.resolveNuiSearchFlag = resolveNuiSearchFlag;
|
|
1436
|
-
exports.resolveSuggestionImageSrc = resolveSuggestionImageSrc;
|
|
1437
|
-
exports.trackChatEntryPoint = trackChatEntryPoint;
|
|
1438
|
-
exports.trackErrorPopup = trackErrorPopup;
|
|
1439
|
-
exports.trackProductSearch = trackProductSearch;
|
|
1440
|
-
exports.trackSearchType = trackSearchType;
|
|
1441
|
-
exports.useSearchSuggestions = useSearchSuggestions;
|
|
1427
|
+
exports.CommerceSearch = CommerceSearch;
|
|
1442
1428
|
//# sourceMappingURL=index.js.map
|
|
1443
1429
|
//# sourceMappingURL=index.js.map
|