@nuskin/react-search-sdk 1.0.0-trying-again.1 → 1.0.0-trying-again.3
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 +206 -213
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +203 -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);
|
|
@@ -278,20 +354,21 @@ function createSearchService(options = {}) {
|
|
|
278
354
|
locationLike,
|
|
279
355
|
country: localeParts.country,
|
|
280
356
|
getMarketConfig
|
|
357
|
+
}).catch((error) => {
|
|
358
|
+
catalogRequestConfigPromise = null;
|
|
359
|
+
console.warn(
|
|
360
|
+
"[search] Could not load the market configuration for the suggestions:",
|
|
361
|
+
error
|
|
362
|
+
);
|
|
363
|
+
throw error;
|
|
281
364
|
});
|
|
282
365
|
}
|
|
283
366
|
return catalogRequestConfigPromise;
|
|
284
367
|
}
|
|
285
368
|
const service = {
|
|
286
|
-
async getSearchChromeCopy() {
|
|
287
|
-
return {
|
|
288
|
-
placeholder: searchPlaceholder || DEFAULT_SEARCH_PLACEHOLDER,
|
|
289
|
-
inputAriaLabel: inputAriaLabel || DEFAULT_INPUT_ARIA_LABEL
|
|
290
|
-
};
|
|
291
|
-
},
|
|
292
369
|
async fetchSuggestions(searchTerm) {
|
|
293
370
|
const trimmedSearchTerm = String(searchTerm ?? "").trim();
|
|
294
|
-
if (!trimmedSearchTerm || !fetchImpl) {
|
|
371
|
+
if (!trimmedSearchTerm || trimmedSearchTerm.length < minimumSearchLength || !fetchImpl) {
|
|
295
372
|
return {
|
|
296
373
|
suggestions: [],
|
|
297
374
|
didYouMean: [],
|
|
@@ -316,7 +393,8 @@ function createSearchService(options = {}) {
|
|
|
316
393
|
const requestUrls = [`${suggestionsUrl}?${queryParams.toString()}`];
|
|
317
394
|
const responsePayload = await fetchJsonFromCandidates(
|
|
318
395
|
fetchImpl,
|
|
319
|
-
requestUrls
|
|
396
|
+
requestUrls,
|
|
397
|
+
resolveCustomerTypeHeaders(getCustomerType)
|
|
320
398
|
);
|
|
321
399
|
const suggestionsField = Array.isArray(responsePayload?.suggestions) ? responsePayload?.suggestions : [];
|
|
322
400
|
const productField = Array.isArray(responsePayload?.product) ? responsePayload?.product : null;
|
|
@@ -348,33 +426,6 @@ function createSearchService(options = {}) {
|
|
|
348
426
|
return stripLocalePrefix(targetPath, localeParts);
|
|
349
427
|
},
|
|
350
428
|
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
429
|
const optionHref = resolveOptionHref(option, localeParts);
|
|
379
430
|
if (optionHref) {
|
|
380
431
|
return stripLocalePrefix(optionHref, localeParts);
|
|
@@ -401,6 +452,35 @@ function createSearchService(options = {}) {
|
|
|
401
452
|
return service;
|
|
402
453
|
}
|
|
403
454
|
|
|
455
|
+
// src/services/marketConfig.ts
|
|
456
|
+
var fetchMarketConfig = async ({ country }) => {
|
|
457
|
+
const countryCode = String(country ?? "").trim().toUpperCase() || "US";
|
|
458
|
+
const configuration = await getConfiguration([EQUINOX_MARKETS_MAP], {
|
|
459
|
+
country: countryCode,
|
|
460
|
+
...getEnvironmentCode() ? { environment: getEnvironmentCode() } : {},
|
|
461
|
+
clientId: DEFAULT_EQUINOX_CLIENT_ID,
|
|
462
|
+
shoppingContext: STOREFRONT_SHOPPING_CONTEXT
|
|
463
|
+
});
|
|
464
|
+
return configuration?.[EQUINOX_MARKETS_MAP] ?? null;
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// src/utils/gtmConstants.ts
|
|
468
|
+
var SEARCH_GTM_EVENTS = {
|
|
469
|
+
CHAT_ENTRY_POINT: "Begin_chat",
|
|
470
|
+
PRODUCT_SEARCH: "ProductSearch"};
|
|
471
|
+
var SEARCH_GTM_SEARCH_TYPES = {
|
|
472
|
+
SEMANTIC: "semantic search"};
|
|
473
|
+
var SEARCH_GTM_USER_STATUS = {
|
|
474
|
+
GUEST: "guest",
|
|
475
|
+
LOGGED_IN: "logged_in"
|
|
476
|
+
};
|
|
477
|
+
var GTM_FALLBACK_NA = "NA";
|
|
478
|
+
|
|
479
|
+
// src/utils/navigationTarget.ts
|
|
480
|
+
function toNavigationTarget(path) {
|
|
481
|
+
return /^https?:\/\//i.test(path) ? { type: "external", url: path } : { type: "internal", path };
|
|
482
|
+
}
|
|
483
|
+
|
|
404
484
|
// src/utils/catalogHelpers.ts
|
|
405
485
|
var CART_DISABLED_PRODUCT_STATUSES = /* @__PURE__ */ new Set([
|
|
406
486
|
"discontinued",
|
|
@@ -416,9 +496,6 @@ var CART_DISABLED_PRODUCT_STATUSES = /* @__PURE__ */ new Set([
|
|
|
416
496
|
function normalizeProductStatusValue(value) {
|
|
417
497
|
return String(value ?? "").trim().toLowerCase().replace(/\s+/g, "");
|
|
418
498
|
}
|
|
419
|
-
function isSellableProductStatus(productStatus) {
|
|
420
|
-
return normalizeProductStatusValue(productStatus) === "sellable";
|
|
421
|
-
}
|
|
422
499
|
function resolveSkuStatusValues(suggestionOption) {
|
|
423
500
|
return [
|
|
424
501
|
suggestionOption["productStatus"],
|
|
@@ -663,14 +740,6 @@ function getVisibleSuggestions(opts) {
|
|
|
663
740
|
}
|
|
664
741
|
return opts.suggestions;
|
|
665
742
|
}
|
|
666
|
-
function getSeeMoreResultsPayload(query, totalResultsCount, suggestions) {
|
|
667
|
-
return {
|
|
668
|
-
query,
|
|
669
|
-
source: "autocomplete-footer",
|
|
670
|
-
totalResultsCount,
|
|
671
|
-
visibleResultsCount: suggestions.length
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
743
|
|
|
675
744
|
// src/hooks/useSearchSuggestions.ts
|
|
676
745
|
function normalizeSuggestionsResponse(response) {
|
|
@@ -828,26 +897,6 @@ function useSearchSuggestions({
|
|
|
828
897
|
};
|
|
829
898
|
}
|
|
830
899
|
|
|
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
900
|
// src/utils/commonUtils.ts
|
|
852
901
|
var IS_BROWSER = typeof window !== "undefined";
|
|
853
902
|
function toEventString(value, fallback = " ") {
|
|
@@ -855,84 +904,24 @@ function toEventString(value, fallback = " ") {
|
|
|
855
904
|
const str = String(value).trim();
|
|
856
905
|
return str.length > 0 ? str : fallback;
|
|
857
906
|
}
|
|
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
907
|
|
|
886
908
|
// 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
909
|
function resolveUserId(explicit) {
|
|
909
|
-
return toEventString(explicit
|
|
910
|
+
return toEventString(explicit, GTM_FALLBACK_NA);
|
|
910
911
|
}
|
|
911
912
|
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
913
|
return {
|
|
918
914
|
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
|
-
),
|
|
915
|
+
// TODO: COMX-3277 puts `page_type` in every event but defines no values. Send `NA` until
|
|
916
|
+
// the data team says what it should hold (perhaps the page path).
|
|
917
|
+
page_type: GTM_FALLBACK_NA,
|
|
918
|
+
country_code: toEventString(ctx.countryCode, GTM_FALLBACK_NA),
|
|
919
|
+
language: toEventString(ctx.language, GTM_FALLBACK_NA),
|
|
931
920
|
user_status: toEventString(
|
|
932
|
-
|
|
921
|
+
ctx.userStatus ?? SEARCH_GTM_USER_STATUS.GUEST,
|
|
933
922
|
SEARCH_GTM_USER_STATUS.GUEST
|
|
934
923
|
),
|
|
935
|
-
account_type: toEventString(accountType, GTM_FALLBACK_NA)
|
|
924
|
+
account_type: toEventString(ctx.accountType, GTM_FALLBACK_NA)
|
|
936
925
|
};
|
|
937
926
|
}
|
|
938
927
|
function serializeProductResults(productResultsData, productResults) {
|
|
@@ -965,15 +954,6 @@ function trackChatEntryPoint(ctx) {
|
|
|
965
954
|
...baseEventPayload(ctx)
|
|
966
955
|
});
|
|
967
956
|
}
|
|
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
957
|
function trackProductSearch(input) {
|
|
978
958
|
pushGtmEvent({
|
|
979
959
|
event: SEARCH_GTM_EVENTS.PRODUCT_SEARCH,
|
|
@@ -986,14 +966,6 @@ function trackProductSearch(input) {
|
|
|
986
966
|
)
|
|
987
967
|
});
|
|
988
968
|
}
|
|
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
969
|
|
|
998
970
|
// src/utils/nuiSearchGate.ts
|
|
999
971
|
var NUI_SEARCH_FLAG = "enableNuiSearch";
|
|
@@ -1150,7 +1122,7 @@ function uniqueRecentSearches(queries) {
|
|
|
1150
1122
|
return true;
|
|
1151
1123
|
});
|
|
1152
1124
|
}
|
|
1153
|
-
function
|
|
1125
|
+
function CommerceSearchView({
|
|
1154
1126
|
isOpen,
|
|
1155
1127
|
onClose,
|
|
1156
1128
|
service,
|
|
@@ -1158,9 +1130,7 @@ function ProductSearch({
|
|
|
1158
1130
|
isAuthenticated,
|
|
1159
1131
|
agent,
|
|
1160
1132
|
logo,
|
|
1161
|
-
|
|
1162
|
-
fallbackImageUrl,
|
|
1163
|
-
copy,
|
|
1133
|
+
minimumSearchLength = MINIMUM_SEARCH_CHAR_LENGTH,
|
|
1164
1134
|
gtmContext
|
|
1165
1135
|
}) {
|
|
1166
1136
|
const [flag, setFlag] = react.useState(void 0);
|
|
@@ -1184,7 +1154,7 @@ function ProductSearch({
|
|
|
1184
1154
|
suggestions,
|
|
1185
1155
|
updateQuery
|
|
1186
1156
|
} = search;
|
|
1187
|
-
const enabled = isNuiSearchEnabled({ isAuthenticated, flag });
|
|
1157
|
+
const enabled = agent !== void 0 && isNuiSearchEnabled({ isAuthenticated, flag });
|
|
1188
1158
|
const items = getVisibleSuggestions({
|
|
1189
1159
|
didYouMean,
|
|
1190
1160
|
suggestions
|
|
@@ -1215,9 +1185,7 @@ function ProductSearch({
|
|
|
1215
1185
|
}, [isOpen, clearQuery]);
|
|
1216
1186
|
const navigateTo = react.useCallback(
|
|
1217
1187
|
(path) => {
|
|
1218
|
-
if (!path
|
|
1219
|
-
return;
|
|
1220
|
-
}
|
|
1188
|
+
if (!path) return;
|
|
1221
1189
|
navigate(path);
|
|
1222
1190
|
close();
|
|
1223
1191
|
},
|
|
@@ -1272,6 +1240,10 @@ function ProductSearch({
|
|
|
1272
1240
|
(value) => {
|
|
1273
1241
|
const term = value.trim();
|
|
1274
1242
|
if (!term) return;
|
|
1243
|
+
if (term.length < minimumSearchLength) {
|
|
1244
|
+
runSearch(term);
|
|
1245
|
+
return;
|
|
1246
|
+
}
|
|
1275
1247
|
const route = decide(term);
|
|
1276
1248
|
if (route === "wait") {
|
|
1277
1249
|
setPendingTerm(term);
|
|
@@ -1279,7 +1251,7 @@ function ProductSearch({
|
|
|
1279
1251
|
}
|
|
1280
1252
|
act(term, route);
|
|
1281
1253
|
},
|
|
1282
|
-
[act, decide]
|
|
1254
|
+
[act, decide, minimumSearchLength, runSearch]
|
|
1283
1255
|
);
|
|
1284
1256
|
const latest = react.useRef({ act, decide });
|
|
1285
1257
|
latest.current = { act, decide };
|
|
@@ -1358,9 +1330,6 @@ function ProductSearch({
|
|
|
1358
1330
|
isOpen,
|
|
1359
1331
|
onClose: close,
|
|
1360
1332
|
logo,
|
|
1361
|
-
...cancelLabel === void 0 ? {} : { cancelLabel },
|
|
1362
|
-
...fallbackImageUrl === void 0 ? {} : { fallbackImageUrl },
|
|
1363
|
-
...copy === void 0 ? {} : { copy },
|
|
1364
1333
|
input: {
|
|
1365
1334
|
value: query,
|
|
1366
1335
|
onChange: updateQuery,
|
|
@@ -1382,7 +1351,7 @@ function ProductSearch({
|
|
|
1382
1351
|
onSelect: handleRecentSelect,
|
|
1383
1352
|
onClear: handleClearRecent
|
|
1384
1353
|
},
|
|
1385
|
-
agentPanel: handoff === null ? void 0 : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1354
|
+
agentPanel: handoff === null || agent === void 0 ? void 0 : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1386
1355
|
NuiAgentPanel,
|
|
1387
1356
|
{
|
|
1388
1357
|
agent,
|
|
@@ -1399,45 +1368,69 @@ function ProductSearch({
|
|
|
1399
1368
|
}
|
|
1400
1369
|
);
|
|
1401
1370
|
}
|
|
1371
|
+
var GUEST = "guest";
|
|
1372
|
+
function CommerceSearch({
|
|
1373
|
+
isOpen,
|
|
1374
|
+
onClose,
|
|
1375
|
+
navigate,
|
|
1376
|
+
customer,
|
|
1377
|
+
country,
|
|
1378
|
+
language,
|
|
1379
|
+
logo
|
|
1380
|
+
}) {
|
|
1381
|
+
const [hasOpened, setHasOpened] = react.useState(false);
|
|
1382
|
+
react.useEffect(() => {
|
|
1383
|
+
if (isOpen) setHasOpened(true);
|
|
1384
|
+
}, [isOpen]);
|
|
1385
|
+
const { minimumSearchLength, agent } = useCommerceSearchConfig({
|
|
1386
|
+
country,
|
|
1387
|
+
language,
|
|
1388
|
+
enabled: hasOpened
|
|
1389
|
+
});
|
|
1390
|
+
const customerTypeRef = react.useRef(GUEST);
|
|
1391
|
+
customerTypeRef.current = customer.isAuthenticated ? customer.accountType ?? GUEST : GUEST;
|
|
1392
|
+
const service = react.useMemo(
|
|
1393
|
+
() => createSearchService({
|
|
1394
|
+
country,
|
|
1395
|
+
language,
|
|
1396
|
+
locale: `${country.toUpperCase()}-${language.toLowerCase()}`,
|
|
1397
|
+
getMarketConfig: fetchMarketConfig,
|
|
1398
|
+
minimumSearchLength,
|
|
1399
|
+
getCustomerType: () => customerTypeRef.current
|
|
1400
|
+
}),
|
|
1401
|
+
[country, language, minimumSearchLength]
|
|
1402
|
+
);
|
|
1403
|
+
const navigateToPath = react.useCallback(
|
|
1404
|
+
(path) => navigate(toNavigationTarget(path)),
|
|
1405
|
+
[navigate]
|
|
1406
|
+
);
|
|
1407
|
+
const { isAuthenticated, accountType, userId } = customer;
|
|
1408
|
+
const gtmContext = react.useMemo(
|
|
1409
|
+
() => ({
|
|
1410
|
+
countryCode: country,
|
|
1411
|
+
language,
|
|
1412
|
+
userStatus: isAuthenticated ? SEARCH_GTM_USER_STATUS.LOGGED_IN : SEARCH_GTM_USER_STATUS.GUEST,
|
|
1413
|
+
...isAuthenticated && accountType ? { accountType } : {},
|
|
1414
|
+
...isAuthenticated && userId ? { userId } : {}
|
|
1415
|
+
}),
|
|
1416
|
+
[country, language, isAuthenticated, accountType, userId]
|
|
1417
|
+
);
|
|
1418
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
1419
|
+
CommerceSearchView,
|
|
1420
|
+
{
|
|
1421
|
+
isOpen,
|
|
1422
|
+
onClose,
|
|
1423
|
+
service,
|
|
1424
|
+
navigate: navigateToPath,
|
|
1425
|
+
isAuthenticated,
|
|
1426
|
+
...agent ? { agent } : {},
|
|
1427
|
+
logo,
|
|
1428
|
+
minimumSearchLength,
|
|
1429
|
+
gtmContext
|
|
1430
|
+
}
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1402
1433
|
|
|
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;
|
|
1434
|
+
exports.CommerceSearch = CommerceSearch;
|
|
1442
1435
|
//# sourceMappingURL=index.js.map
|
|
1443
1436
|
//# sourceMappingURL=index.js.map
|