@getlupa/client 1.5.2 → 1.6.1
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/lupaSearch.iife.js +115 -2
- package/dist/lupaSearch.js +115 -2
- package/dist/lupaSearch.mjs +115 -2
- package/dist/lupaSearch.umd.js +115 -2
- package/dist/src/index.d.ts +2 -2
- package/package.json +2 -2
package/dist/lupaSearch.iife.js
CHANGED
|
@@ -6279,6 +6279,14 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6279
6279
|
}
|
|
6280
6280
|
return res.json();
|
|
6281
6281
|
});
|
|
6282
|
+
const loadRedirectionRules = (queryKey, environment, customBaseUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6283
|
+
const res = yield fetch(`${getApiUrl$1(environment, customBaseUrl)}redirections/${queryKey}`, Object.assign(Object.assign({}, defaultConfig$1), { method: "GET" }));
|
|
6284
|
+
if (res.status < 400) {
|
|
6285
|
+
return res.json();
|
|
6286
|
+
}
|
|
6287
|
+
const errors = yield res.json();
|
|
6288
|
+
return { success: false, errors };
|
|
6289
|
+
});
|
|
6282
6290
|
const LupaSearchSdk = {
|
|
6283
6291
|
query: (queryKey, publicQuery, options = null) => {
|
|
6284
6292
|
if (options === null || options === void 0 ? void 0 : options.customUrl) {
|
|
@@ -6300,6 +6308,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6300
6308
|
},
|
|
6301
6309
|
queryByIds: (queryKey, ids, options = null) => {
|
|
6302
6310
|
return queryByIds(queryKey, ids, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6311
|
+
},
|
|
6312
|
+
loadRedirectionRules: (queryKey, options = null) => {
|
|
6313
|
+
return loadRedirectionRules(queryKey, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6303
6314
|
}
|
|
6304
6315
|
};
|
|
6305
6316
|
const getNormalizedString = (str) => {
|
|
@@ -6378,6 +6389,13 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6378
6389
|
});
|
|
6379
6390
|
return output;
|
|
6380
6391
|
};
|
|
6392
|
+
const inputMatches = (input, possibleValues) => {
|
|
6393
|
+
if (!input) {
|
|
6394
|
+
return false;
|
|
6395
|
+
}
|
|
6396
|
+
const normalizedInput = getNormalizedString(input);
|
|
6397
|
+
return possibleValues.some((v) => getNormalizedString(v).startsWith(normalizedInput));
|
|
6398
|
+
};
|
|
6381
6399
|
const initAnalyticsTracking = (analyticsOptions) => {
|
|
6382
6400
|
try {
|
|
6383
6401
|
if (analyticsOptions == null ? void 0 : analyticsOptions.enabled) {
|
|
@@ -7328,12 +7346,89 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
7328
7346
|
}
|
|
7329
7347
|
return getMostSpecificHierarchyTerms([param, ...params]);
|
|
7330
7348
|
};
|
|
7349
|
+
const CACHE_KEY = "lupasearch-client-redirections";
|
|
7350
|
+
const useRedirectionStore = defineStore("redirections", () => {
|
|
7351
|
+
const redirections = ref({ rules: [] });
|
|
7352
|
+
const redirectionOptions = ref({ enabled: false, queryKey: "" });
|
|
7353
|
+
const saveToLocalStorage = () => {
|
|
7354
|
+
try {
|
|
7355
|
+
localStorage.setItem(
|
|
7356
|
+
CACHE_KEY,
|
|
7357
|
+
JSON.stringify({ redirections: redirections.value, savedAt: Date.now() })
|
|
7358
|
+
);
|
|
7359
|
+
} catch (e) {
|
|
7360
|
+
}
|
|
7361
|
+
};
|
|
7362
|
+
const tryLoadFromLocalStorage = (config) => {
|
|
7363
|
+
var _a;
|
|
7364
|
+
if (!config.cacheSeconds)
|
|
7365
|
+
return false;
|
|
7366
|
+
try {
|
|
7367
|
+
const data = JSON.parse((_a = localStorage.getItem(CACHE_KEY)) != null ? _a : "");
|
|
7368
|
+
if ((data == null ? void 0 : data.redirections) && Date.now() - data.savedAt < 1e3 * config.cacheSeconds) {
|
|
7369
|
+
redirections.value = data.redirections;
|
|
7370
|
+
return true;
|
|
7371
|
+
}
|
|
7372
|
+
} catch (e) {
|
|
7373
|
+
}
|
|
7374
|
+
return false;
|
|
7375
|
+
};
|
|
7376
|
+
const initiate = (config, options) => __async(void 0, null, function* () {
|
|
7377
|
+
var _a, _b, _c, _d;
|
|
7378
|
+
if ((_a = redirectionOptions.value) == null ? void 0 : _a.enabled) {
|
|
7379
|
+
return;
|
|
7380
|
+
}
|
|
7381
|
+
redirectionOptions.value = config;
|
|
7382
|
+
if (!(config == null ? void 0 : config.enabled)) {
|
|
7383
|
+
return;
|
|
7384
|
+
}
|
|
7385
|
+
const loaded = tryLoadFromLocalStorage(config);
|
|
7386
|
+
if (loaded || ((_c = (_b = redirections.value) == null ? void 0 : _b.rules) == null ? void 0 : _c.length) > 0) {
|
|
7387
|
+
return;
|
|
7388
|
+
}
|
|
7389
|
+
try {
|
|
7390
|
+
const result = yield LupaSearchSdk.loadRedirectionRules(config.queryKey, options);
|
|
7391
|
+
if (!((_d = result == null ? void 0 : result.rules) == null ? void 0 : _d.length)) {
|
|
7392
|
+
return;
|
|
7393
|
+
}
|
|
7394
|
+
redirections.value = result;
|
|
7395
|
+
saveToLocalStorage();
|
|
7396
|
+
} catch (e) {
|
|
7397
|
+
}
|
|
7398
|
+
});
|
|
7399
|
+
const redirectOnKeywordIfConfigured = (input, routingBehavior = "direct-link") => {
|
|
7400
|
+
var _a, _b, _c, _d;
|
|
7401
|
+
if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
|
|
7402
|
+
return false;
|
|
7403
|
+
}
|
|
7404
|
+
const redirectTo = redirections.value.rules.find((r) => inputMatches(input, r.sources));
|
|
7405
|
+
if (!redirectTo) {
|
|
7406
|
+
return false;
|
|
7407
|
+
}
|
|
7408
|
+
const url = ((_c = redirectionOptions.value) == null ? void 0 : _c.urlTransformer) ? (_d = redirectionOptions.value) == null ? void 0 : _d.urlTransformer(redirectTo == null ? void 0 : redirectTo.target) : redirectTo == null ? void 0 : redirectTo.target;
|
|
7409
|
+
if (url === void 0 || url === null || url === "") {
|
|
7410
|
+
return false;
|
|
7411
|
+
}
|
|
7412
|
+
if (routingBehavior === "event") {
|
|
7413
|
+
emitRoutingEvent(url);
|
|
7414
|
+
} else {
|
|
7415
|
+
window.location.assign(url);
|
|
7416
|
+
}
|
|
7417
|
+
return true;
|
|
7418
|
+
};
|
|
7419
|
+
return {
|
|
7420
|
+
redirections,
|
|
7421
|
+
redirectOnKeywordIfConfigured,
|
|
7422
|
+
initiate
|
|
7423
|
+
};
|
|
7424
|
+
});
|
|
7331
7425
|
const useParamsStore = defineStore("params", () => {
|
|
7332
7426
|
const params = ref({});
|
|
7333
7427
|
const defaultLimit = ref(DEFAULT_PAGE_SIZE);
|
|
7334
7428
|
const searchResultsLink = ref("");
|
|
7335
7429
|
const searchString = ref("");
|
|
7336
7430
|
const optionsStore = useOptionsStore();
|
|
7431
|
+
const redirectionStore = useRedirectionStore();
|
|
7337
7432
|
const query = computed(() => params.value[QUERY_PARAMS_PARSED.QUERY]);
|
|
7338
7433
|
const page = computed(() => {
|
|
7339
7434
|
const page2 = Number(params.value[QUERY_PARAMS_PARSED.PAGE]) || 1;
|
|
@@ -7411,6 +7506,13 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
7411
7506
|
facet
|
|
7412
7507
|
}) => {
|
|
7413
7508
|
var _a;
|
|
7509
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
7510
|
+
searchText,
|
|
7511
|
+
optionsStore.boxRoutingBehavior
|
|
7512
|
+
);
|
|
7513
|
+
if (redirectionApplied) {
|
|
7514
|
+
return;
|
|
7515
|
+
}
|
|
7414
7516
|
if (!searchResultsLink.value || linksMatch(searchResultsLink.value, window.location.pathname)) {
|
|
7415
7517
|
const singleFacetParam = facet ? getFacetParam(facet.key, [facet.title]) : void 0;
|
|
7416
7518
|
const facetParam = singleFacetParam ? [
|
|
@@ -9326,6 +9428,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
9326
9428
|
const searchBoxStore = useSearchBoxStore();
|
|
9327
9429
|
const optionsStore = useOptionsStore();
|
|
9328
9430
|
const trackingStore = useTrackingStore();
|
|
9431
|
+
const redirectionStore = useRedirectionStore();
|
|
9329
9432
|
const inputValue = ref("");
|
|
9330
9433
|
const suggestedValue = ref(defaultSuggestedValue);
|
|
9331
9434
|
const opened = ref(props.isSearchContainer);
|
|
@@ -9364,6 +9467,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
9364
9467
|
paramsStore.setSearchResultsLink(props.options.links.searchResults);
|
|
9365
9468
|
searchBoxStore.saveOptions({ newOptions: props.options });
|
|
9366
9469
|
optionsStore.setSearchBoxOptions({ options: props.options });
|
|
9470
|
+
redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
9367
9471
|
bindSearchTriggers(searchTriggers.value, handleCurrentValueSearch);
|
|
9368
9472
|
if (props.isSearchContainer && searchBoxInput.value) {
|
|
9369
9473
|
(_a2 = searchBoxInput.value) == null ? void 0 : _a2.focus();
|
|
@@ -14054,6 +14158,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
14054
14158
|
const trackingStore = useTrackingStore();
|
|
14055
14159
|
const dynamicDataStore = useDynamicDataStore();
|
|
14056
14160
|
const screenStore = useScreenStore();
|
|
14161
|
+
const redirectionStore = useRedirectionStore();
|
|
14057
14162
|
const initialFilters = computed(() => {
|
|
14058
14163
|
var _a;
|
|
14059
14164
|
return (_a = props.initialFilters) != null ? _a : {};
|
|
@@ -14079,17 +14184,18 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
14079
14184
|
const searchParams = getSearchParams((_a = props.options.ssr) == null ? void 0 : _a.url);
|
|
14080
14185
|
paramStore.add(parseParams(searchParams));
|
|
14081
14186
|
};
|
|
14082
|
-
onMounted(() => {
|
|
14187
|
+
onMounted(() => __async(this, null, function* () {
|
|
14083
14188
|
var _a, _b;
|
|
14084
14189
|
window.addEventListener("popstate", handlePopState);
|
|
14085
14190
|
window.addEventListener("resize", handleResize);
|
|
14191
|
+
yield redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
14086
14192
|
if (props.initialData) {
|
|
14087
14193
|
searchResultStore.add(__spreadValues2({}, props.initialData));
|
|
14088
14194
|
}
|
|
14089
14195
|
handleMounted();
|
|
14090
14196
|
(_b = (_a = props.options.callbacks) == null ? void 0 : _a.onMounted) == null ? void 0 : _b.call(_a);
|
|
14091
14197
|
mounted.value = true;
|
|
14092
|
-
});
|
|
14198
|
+
}));
|
|
14093
14199
|
onBeforeUnmount(() => {
|
|
14094
14200
|
window.removeEventListener("resize", handleResize);
|
|
14095
14201
|
window.removeEventListener("popstate", handlePopState);
|
|
@@ -14133,6 +14239,13 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
14133
14239
|
const context = getLupaTrackingContext();
|
|
14134
14240
|
const limit = publicQuery.limit || defaultSearchResultPageSize.value;
|
|
14135
14241
|
const query2 = __spreadProps2(__spreadValues2(__spreadValues2({}, publicQuery), context), { limit });
|
|
14242
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
14243
|
+
publicQuery.searchText,
|
|
14244
|
+
optionStore.searchResultsRoutingBehavior
|
|
14245
|
+
);
|
|
14246
|
+
if (redirectionApplied) {
|
|
14247
|
+
return;
|
|
14248
|
+
}
|
|
14136
14249
|
if (!query2.searchText && props.options.disallowEmptyQuery) {
|
|
14137
14250
|
return;
|
|
14138
14251
|
}
|
package/dist/lupaSearch.js
CHANGED
|
@@ -6279,6 +6279,14 @@ const track$1 = (queryKey, event, environment, customBaseUrl) => __awaiter(void
|
|
|
6279
6279
|
}
|
|
6280
6280
|
return res.json();
|
|
6281
6281
|
});
|
|
6282
|
+
const loadRedirectionRules = (queryKey, environment, customBaseUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6283
|
+
const res = yield fetch(`${getApiUrl$1(environment, customBaseUrl)}redirections/${queryKey}`, Object.assign(Object.assign({}, defaultConfig$1), { method: "GET" }));
|
|
6284
|
+
if (res.status < 400) {
|
|
6285
|
+
return res.json();
|
|
6286
|
+
}
|
|
6287
|
+
const errors = yield res.json();
|
|
6288
|
+
return { success: false, errors };
|
|
6289
|
+
});
|
|
6282
6290
|
const LupaSearchSdk = {
|
|
6283
6291
|
query: (queryKey, publicQuery, options = null) => {
|
|
6284
6292
|
if (options === null || options === void 0 ? void 0 : options.customUrl) {
|
|
@@ -6300,6 +6308,9 @@ const LupaSearchSdk = {
|
|
|
6300
6308
|
},
|
|
6301
6309
|
queryByIds: (queryKey, ids, options = null) => {
|
|
6302
6310
|
return queryByIds(queryKey, ids, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6311
|
+
},
|
|
6312
|
+
loadRedirectionRules: (queryKey, options = null) => {
|
|
6313
|
+
return loadRedirectionRules(queryKey, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6303
6314
|
}
|
|
6304
6315
|
};
|
|
6305
6316
|
const getNormalizedString = (str) => {
|
|
@@ -6378,6 +6389,13 @@ const escapeHtml = (value) => {
|
|
|
6378
6389
|
});
|
|
6379
6390
|
return output;
|
|
6380
6391
|
};
|
|
6392
|
+
const inputMatches = (input, possibleValues) => {
|
|
6393
|
+
if (!input) {
|
|
6394
|
+
return false;
|
|
6395
|
+
}
|
|
6396
|
+
const normalizedInput = getNormalizedString(input);
|
|
6397
|
+
return possibleValues.some((v) => getNormalizedString(v).startsWith(normalizedInput));
|
|
6398
|
+
};
|
|
6381
6399
|
const initAnalyticsTracking = (analyticsOptions) => {
|
|
6382
6400
|
try {
|
|
6383
6401
|
if (analyticsOptions == null ? void 0 : analyticsOptions.enabled) {
|
|
@@ -7328,12 +7346,89 @@ const toggleHierarchyParam = (params = [], param = "", removeAllLevels = false)
|
|
|
7328
7346
|
}
|
|
7329
7347
|
return getMostSpecificHierarchyTerms([param, ...params]);
|
|
7330
7348
|
};
|
|
7349
|
+
const CACHE_KEY = "lupasearch-client-redirections";
|
|
7350
|
+
const useRedirectionStore = defineStore("redirections", () => {
|
|
7351
|
+
const redirections = ref({ rules: [] });
|
|
7352
|
+
const redirectionOptions = ref({ enabled: false, queryKey: "" });
|
|
7353
|
+
const saveToLocalStorage = () => {
|
|
7354
|
+
try {
|
|
7355
|
+
localStorage.setItem(
|
|
7356
|
+
CACHE_KEY,
|
|
7357
|
+
JSON.stringify({ redirections: redirections.value, savedAt: Date.now() })
|
|
7358
|
+
);
|
|
7359
|
+
} catch (e) {
|
|
7360
|
+
}
|
|
7361
|
+
};
|
|
7362
|
+
const tryLoadFromLocalStorage = (config) => {
|
|
7363
|
+
var _a;
|
|
7364
|
+
if (!config.cacheSeconds)
|
|
7365
|
+
return false;
|
|
7366
|
+
try {
|
|
7367
|
+
const data = JSON.parse((_a = localStorage.getItem(CACHE_KEY)) != null ? _a : "");
|
|
7368
|
+
if ((data == null ? void 0 : data.redirections) && Date.now() - data.savedAt < 1e3 * config.cacheSeconds) {
|
|
7369
|
+
redirections.value = data.redirections;
|
|
7370
|
+
return true;
|
|
7371
|
+
}
|
|
7372
|
+
} catch (e) {
|
|
7373
|
+
}
|
|
7374
|
+
return false;
|
|
7375
|
+
};
|
|
7376
|
+
const initiate = (config, options) => __async(void 0, null, function* () {
|
|
7377
|
+
var _a, _b, _c, _d;
|
|
7378
|
+
if ((_a = redirectionOptions.value) == null ? void 0 : _a.enabled) {
|
|
7379
|
+
return;
|
|
7380
|
+
}
|
|
7381
|
+
redirectionOptions.value = config;
|
|
7382
|
+
if (!(config == null ? void 0 : config.enabled)) {
|
|
7383
|
+
return;
|
|
7384
|
+
}
|
|
7385
|
+
const loaded = tryLoadFromLocalStorage(config);
|
|
7386
|
+
if (loaded || ((_c = (_b = redirections.value) == null ? void 0 : _b.rules) == null ? void 0 : _c.length) > 0) {
|
|
7387
|
+
return;
|
|
7388
|
+
}
|
|
7389
|
+
try {
|
|
7390
|
+
const result = yield LupaSearchSdk.loadRedirectionRules(config.queryKey, options);
|
|
7391
|
+
if (!((_d = result == null ? void 0 : result.rules) == null ? void 0 : _d.length)) {
|
|
7392
|
+
return;
|
|
7393
|
+
}
|
|
7394
|
+
redirections.value = result;
|
|
7395
|
+
saveToLocalStorage();
|
|
7396
|
+
} catch (e) {
|
|
7397
|
+
}
|
|
7398
|
+
});
|
|
7399
|
+
const redirectOnKeywordIfConfigured = (input, routingBehavior = "direct-link") => {
|
|
7400
|
+
var _a, _b, _c, _d;
|
|
7401
|
+
if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
|
|
7402
|
+
return false;
|
|
7403
|
+
}
|
|
7404
|
+
const redirectTo = redirections.value.rules.find((r) => inputMatches(input, r.sources));
|
|
7405
|
+
if (!redirectTo) {
|
|
7406
|
+
return false;
|
|
7407
|
+
}
|
|
7408
|
+
const url = ((_c = redirectionOptions.value) == null ? void 0 : _c.urlTransformer) ? (_d = redirectionOptions.value) == null ? void 0 : _d.urlTransformer(redirectTo == null ? void 0 : redirectTo.target) : redirectTo == null ? void 0 : redirectTo.target;
|
|
7409
|
+
if (url === void 0 || url === null || url === "") {
|
|
7410
|
+
return false;
|
|
7411
|
+
}
|
|
7412
|
+
if (routingBehavior === "event") {
|
|
7413
|
+
emitRoutingEvent(url);
|
|
7414
|
+
} else {
|
|
7415
|
+
window.location.assign(url);
|
|
7416
|
+
}
|
|
7417
|
+
return true;
|
|
7418
|
+
};
|
|
7419
|
+
return {
|
|
7420
|
+
redirections,
|
|
7421
|
+
redirectOnKeywordIfConfigured,
|
|
7422
|
+
initiate
|
|
7423
|
+
};
|
|
7424
|
+
});
|
|
7331
7425
|
const useParamsStore = defineStore("params", () => {
|
|
7332
7426
|
const params = ref({});
|
|
7333
7427
|
const defaultLimit = ref(DEFAULT_PAGE_SIZE);
|
|
7334
7428
|
const searchResultsLink = ref("");
|
|
7335
7429
|
const searchString = ref("");
|
|
7336
7430
|
const optionsStore = useOptionsStore();
|
|
7431
|
+
const redirectionStore = useRedirectionStore();
|
|
7337
7432
|
const query = computed(() => params.value[QUERY_PARAMS_PARSED.QUERY]);
|
|
7338
7433
|
const page = computed(() => {
|
|
7339
7434
|
const page2 = Number(params.value[QUERY_PARAMS_PARSED.PAGE]) || 1;
|
|
@@ -7411,6 +7506,13 @@ const useParamsStore = defineStore("params", () => {
|
|
|
7411
7506
|
facet
|
|
7412
7507
|
}) => {
|
|
7413
7508
|
var _a;
|
|
7509
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
7510
|
+
searchText,
|
|
7511
|
+
optionsStore.boxRoutingBehavior
|
|
7512
|
+
);
|
|
7513
|
+
if (redirectionApplied) {
|
|
7514
|
+
return;
|
|
7515
|
+
}
|
|
7414
7516
|
if (!searchResultsLink.value || linksMatch(searchResultsLink.value, window.location.pathname)) {
|
|
7415
7517
|
const singleFacetParam = facet ? getFacetParam(facet.key, [facet.title]) : void 0;
|
|
7416
7518
|
const facetParam = singleFacetParam ? [
|
|
@@ -9326,6 +9428,7 @@ const _sfc_main$_ = /* @__PURE__ */ defineComponent({
|
|
|
9326
9428
|
const searchBoxStore = useSearchBoxStore();
|
|
9327
9429
|
const optionsStore = useOptionsStore();
|
|
9328
9430
|
const trackingStore = useTrackingStore();
|
|
9431
|
+
const redirectionStore = useRedirectionStore();
|
|
9329
9432
|
const inputValue = ref("");
|
|
9330
9433
|
const suggestedValue = ref(defaultSuggestedValue);
|
|
9331
9434
|
const opened = ref(props.isSearchContainer);
|
|
@@ -9364,6 +9467,7 @@ const _sfc_main$_ = /* @__PURE__ */ defineComponent({
|
|
|
9364
9467
|
paramsStore.setSearchResultsLink(props.options.links.searchResults);
|
|
9365
9468
|
searchBoxStore.saveOptions({ newOptions: props.options });
|
|
9366
9469
|
optionsStore.setSearchBoxOptions({ options: props.options });
|
|
9470
|
+
redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
9367
9471
|
bindSearchTriggers(searchTriggers.value, handleCurrentValueSearch);
|
|
9368
9472
|
if (props.isSearchContainer && searchBoxInput.value) {
|
|
9369
9473
|
(_a2 = searchBoxInput.value) == null ? void 0 : _a2.focus();
|
|
@@ -14054,6 +14158,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
|
|
|
14054
14158
|
const trackingStore = useTrackingStore();
|
|
14055
14159
|
const dynamicDataStore = useDynamicDataStore();
|
|
14056
14160
|
const screenStore = useScreenStore();
|
|
14161
|
+
const redirectionStore = useRedirectionStore();
|
|
14057
14162
|
const initialFilters = computed(() => {
|
|
14058
14163
|
var _a;
|
|
14059
14164
|
return (_a = props.initialFilters) != null ? _a : {};
|
|
@@ -14079,17 +14184,18 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
|
|
|
14079
14184
|
const searchParams = getSearchParams((_a = props.options.ssr) == null ? void 0 : _a.url);
|
|
14080
14185
|
paramStore.add(parseParams(searchParams));
|
|
14081
14186
|
};
|
|
14082
|
-
onMounted(() => {
|
|
14187
|
+
onMounted(() => __async(this, null, function* () {
|
|
14083
14188
|
var _a, _b;
|
|
14084
14189
|
window.addEventListener("popstate", handlePopState);
|
|
14085
14190
|
window.addEventListener("resize", handleResize);
|
|
14191
|
+
yield redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
14086
14192
|
if (props.initialData) {
|
|
14087
14193
|
searchResultStore.add(__spreadValues2({}, props.initialData));
|
|
14088
14194
|
}
|
|
14089
14195
|
handleMounted();
|
|
14090
14196
|
(_b = (_a = props.options.callbacks) == null ? void 0 : _a.onMounted) == null ? void 0 : _b.call(_a);
|
|
14091
14197
|
mounted.value = true;
|
|
14092
|
-
});
|
|
14198
|
+
}));
|
|
14093
14199
|
onBeforeUnmount(() => {
|
|
14094
14200
|
window.removeEventListener("resize", handleResize);
|
|
14095
14201
|
window.removeEventListener("popstate", handlePopState);
|
|
@@ -14133,6 +14239,13 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
|
|
|
14133
14239
|
const context = getLupaTrackingContext();
|
|
14134
14240
|
const limit = publicQuery.limit || defaultSearchResultPageSize.value;
|
|
14135
14241
|
const query2 = __spreadProps2(__spreadValues2(__spreadValues2({}, publicQuery), context), { limit });
|
|
14242
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
14243
|
+
publicQuery.searchText,
|
|
14244
|
+
optionStore.searchResultsRoutingBehavior
|
|
14245
|
+
);
|
|
14246
|
+
if (redirectionApplied) {
|
|
14247
|
+
return;
|
|
14248
|
+
}
|
|
14136
14249
|
if (!query2.searchText && props.options.disallowEmptyQuery) {
|
|
14137
14250
|
return;
|
|
14138
14251
|
}
|
package/dist/lupaSearch.mjs
CHANGED
|
@@ -6277,6 +6277,14 @@ const track$1 = (queryKey, event, environment, customBaseUrl) => __awaiter(void
|
|
|
6277
6277
|
}
|
|
6278
6278
|
return res.json();
|
|
6279
6279
|
});
|
|
6280
|
+
const loadRedirectionRules = (queryKey, environment, customBaseUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6281
|
+
const res = yield fetch(`${getApiUrl$1(environment, customBaseUrl)}redirections/${queryKey}`, Object.assign(Object.assign({}, defaultConfig$1), { method: "GET" }));
|
|
6282
|
+
if (res.status < 400) {
|
|
6283
|
+
return res.json();
|
|
6284
|
+
}
|
|
6285
|
+
const errors = yield res.json();
|
|
6286
|
+
return { success: false, errors };
|
|
6287
|
+
});
|
|
6280
6288
|
const LupaSearchSdk = {
|
|
6281
6289
|
query: (queryKey, publicQuery, options = null) => {
|
|
6282
6290
|
if (options === null || options === void 0 ? void 0 : options.customUrl) {
|
|
@@ -6298,6 +6306,9 @@ const LupaSearchSdk = {
|
|
|
6298
6306
|
},
|
|
6299
6307
|
queryByIds: (queryKey, ids, options = null) => {
|
|
6300
6308
|
return queryByIds(queryKey, ids, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6309
|
+
},
|
|
6310
|
+
loadRedirectionRules: (queryKey, options = null) => {
|
|
6311
|
+
return loadRedirectionRules(queryKey, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6301
6312
|
}
|
|
6302
6313
|
};
|
|
6303
6314
|
const getNormalizedString = (str) => {
|
|
@@ -6376,6 +6387,13 @@ const escapeHtml = (value) => {
|
|
|
6376
6387
|
});
|
|
6377
6388
|
return output;
|
|
6378
6389
|
};
|
|
6390
|
+
const inputMatches = (input, possibleValues) => {
|
|
6391
|
+
if (!input) {
|
|
6392
|
+
return false;
|
|
6393
|
+
}
|
|
6394
|
+
const normalizedInput = getNormalizedString(input);
|
|
6395
|
+
return possibleValues.some((v) => getNormalizedString(v).startsWith(normalizedInput));
|
|
6396
|
+
};
|
|
6379
6397
|
const initAnalyticsTracking = (analyticsOptions) => {
|
|
6380
6398
|
try {
|
|
6381
6399
|
if (analyticsOptions == null ? void 0 : analyticsOptions.enabled) {
|
|
@@ -7326,12 +7344,89 @@ const toggleHierarchyParam = (params = [], param = "", removeAllLevels = false)
|
|
|
7326
7344
|
}
|
|
7327
7345
|
return getMostSpecificHierarchyTerms([param, ...params]);
|
|
7328
7346
|
};
|
|
7347
|
+
const CACHE_KEY = "lupasearch-client-redirections";
|
|
7348
|
+
const useRedirectionStore = defineStore("redirections", () => {
|
|
7349
|
+
const redirections = ref({ rules: [] });
|
|
7350
|
+
const redirectionOptions = ref({ enabled: false, queryKey: "" });
|
|
7351
|
+
const saveToLocalStorage = () => {
|
|
7352
|
+
try {
|
|
7353
|
+
localStorage.setItem(
|
|
7354
|
+
CACHE_KEY,
|
|
7355
|
+
JSON.stringify({ redirections: redirections.value, savedAt: Date.now() })
|
|
7356
|
+
);
|
|
7357
|
+
} catch (e) {
|
|
7358
|
+
}
|
|
7359
|
+
};
|
|
7360
|
+
const tryLoadFromLocalStorage = (config) => {
|
|
7361
|
+
var _a;
|
|
7362
|
+
if (!config.cacheSeconds)
|
|
7363
|
+
return false;
|
|
7364
|
+
try {
|
|
7365
|
+
const data = JSON.parse((_a = localStorage.getItem(CACHE_KEY)) != null ? _a : "");
|
|
7366
|
+
if ((data == null ? void 0 : data.redirections) && Date.now() - data.savedAt < 1e3 * config.cacheSeconds) {
|
|
7367
|
+
redirections.value = data.redirections;
|
|
7368
|
+
return true;
|
|
7369
|
+
}
|
|
7370
|
+
} catch (e) {
|
|
7371
|
+
}
|
|
7372
|
+
return false;
|
|
7373
|
+
};
|
|
7374
|
+
const initiate = (config, options) => __async(void 0, null, function* () {
|
|
7375
|
+
var _a, _b, _c, _d;
|
|
7376
|
+
if ((_a = redirectionOptions.value) == null ? void 0 : _a.enabled) {
|
|
7377
|
+
return;
|
|
7378
|
+
}
|
|
7379
|
+
redirectionOptions.value = config;
|
|
7380
|
+
if (!(config == null ? void 0 : config.enabled)) {
|
|
7381
|
+
return;
|
|
7382
|
+
}
|
|
7383
|
+
const loaded = tryLoadFromLocalStorage(config);
|
|
7384
|
+
if (loaded || ((_c = (_b = redirections.value) == null ? void 0 : _b.rules) == null ? void 0 : _c.length) > 0) {
|
|
7385
|
+
return;
|
|
7386
|
+
}
|
|
7387
|
+
try {
|
|
7388
|
+
const result = yield LupaSearchSdk.loadRedirectionRules(config.queryKey, options);
|
|
7389
|
+
if (!((_d = result == null ? void 0 : result.rules) == null ? void 0 : _d.length)) {
|
|
7390
|
+
return;
|
|
7391
|
+
}
|
|
7392
|
+
redirections.value = result;
|
|
7393
|
+
saveToLocalStorage();
|
|
7394
|
+
} catch (e) {
|
|
7395
|
+
}
|
|
7396
|
+
});
|
|
7397
|
+
const redirectOnKeywordIfConfigured = (input, routingBehavior = "direct-link") => {
|
|
7398
|
+
var _a, _b, _c, _d;
|
|
7399
|
+
if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
|
|
7400
|
+
return false;
|
|
7401
|
+
}
|
|
7402
|
+
const redirectTo = redirections.value.rules.find((r) => inputMatches(input, r.sources));
|
|
7403
|
+
if (!redirectTo) {
|
|
7404
|
+
return false;
|
|
7405
|
+
}
|
|
7406
|
+
const url = ((_c = redirectionOptions.value) == null ? void 0 : _c.urlTransformer) ? (_d = redirectionOptions.value) == null ? void 0 : _d.urlTransformer(redirectTo == null ? void 0 : redirectTo.target) : redirectTo == null ? void 0 : redirectTo.target;
|
|
7407
|
+
if (url === void 0 || url === null || url === "") {
|
|
7408
|
+
return false;
|
|
7409
|
+
}
|
|
7410
|
+
if (routingBehavior === "event") {
|
|
7411
|
+
emitRoutingEvent(url);
|
|
7412
|
+
} else {
|
|
7413
|
+
window.location.assign(url);
|
|
7414
|
+
}
|
|
7415
|
+
return true;
|
|
7416
|
+
};
|
|
7417
|
+
return {
|
|
7418
|
+
redirections,
|
|
7419
|
+
redirectOnKeywordIfConfigured,
|
|
7420
|
+
initiate
|
|
7421
|
+
};
|
|
7422
|
+
});
|
|
7329
7423
|
const useParamsStore = defineStore("params", () => {
|
|
7330
7424
|
const params = ref({});
|
|
7331
7425
|
const defaultLimit = ref(DEFAULT_PAGE_SIZE);
|
|
7332
7426
|
const searchResultsLink = ref("");
|
|
7333
7427
|
const searchString = ref("");
|
|
7334
7428
|
const optionsStore = useOptionsStore();
|
|
7429
|
+
const redirectionStore = useRedirectionStore();
|
|
7335
7430
|
const query = computed(() => params.value[QUERY_PARAMS_PARSED.QUERY]);
|
|
7336
7431
|
const page = computed(() => {
|
|
7337
7432
|
const page2 = Number(params.value[QUERY_PARAMS_PARSED.PAGE]) || 1;
|
|
@@ -7409,6 +7504,13 @@ const useParamsStore = defineStore("params", () => {
|
|
|
7409
7504
|
facet
|
|
7410
7505
|
}) => {
|
|
7411
7506
|
var _a;
|
|
7507
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
7508
|
+
searchText,
|
|
7509
|
+
optionsStore.boxRoutingBehavior
|
|
7510
|
+
);
|
|
7511
|
+
if (redirectionApplied) {
|
|
7512
|
+
return;
|
|
7513
|
+
}
|
|
7412
7514
|
if (!searchResultsLink.value || linksMatch(searchResultsLink.value, window.location.pathname)) {
|
|
7413
7515
|
const singleFacetParam = facet ? getFacetParam(facet.key, [facet.title]) : void 0;
|
|
7414
7516
|
const facetParam = singleFacetParam ? [
|
|
@@ -9324,6 +9426,7 @@ const _sfc_main$_ = /* @__PURE__ */ defineComponent({
|
|
|
9324
9426
|
const searchBoxStore = useSearchBoxStore();
|
|
9325
9427
|
const optionsStore = useOptionsStore();
|
|
9326
9428
|
const trackingStore = useTrackingStore();
|
|
9429
|
+
const redirectionStore = useRedirectionStore();
|
|
9327
9430
|
const inputValue = ref("");
|
|
9328
9431
|
const suggestedValue = ref(defaultSuggestedValue);
|
|
9329
9432
|
const opened = ref(props.isSearchContainer);
|
|
@@ -9362,6 +9465,7 @@ const _sfc_main$_ = /* @__PURE__ */ defineComponent({
|
|
|
9362
9465
|
paramsStore.setSearchResultsLink(props.options.links.searchResults);
|
|
9363
9466
|
searchBoxStore.saveOptions({ newOptions: props.options });
|
|
9364
9467
|
optionsStore.setSearchBoxOptions({ options: props.options });
|
|
9468
|
+
redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
9365
9469
|
bindSearchTriggers(searchTriggers.value, handleCurrentValueSearch);
|
|
9366
9470
|
if (props.isSearchContainer && searchBoxInput.value) {
|
|
9367
9471
|
(_a2 = searchBoxInput.value) == null ? void 0 : _a2.focus();
|
|
@@ -14052,6 +14156,7 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
|
|
|
14052
14156
|
const trackingStore = useTrackingStore();
|
|
14053
14157
|
const dynamicDataStore = useDynamicDataStore();
|
|
14054
14158
|
const screenStore = useScreenStore();
|
|
14159
|
+
const redirectionStore = useRedirectionStore();
|
|
14055
14160
|
const initialFilters = computed(() => {
|
|
14056
14161
|
var _a;
|
|
14057
14162
|
return (_a = props.initialFilters) != null ? _a : {};
|
|
@@ -14077,17 +14182,18 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
|
|
|
14077
14182
|
const searchParams = getSearchParams((_a = props.options.ssr) == null ? void 0 : _a.url);
|
|
14078
14183
|
paramStore.add(parseParams(searchParams));
|
|
14079
14184
|
};
|
|
14080
|
-
onMounted(() => {
|
|
14185
|
+
onMounted(() => __async(this, null, function* () {
|
|
14081
14186
|
var _a, _b;
|
|
14082
14187
|
window.addEventListener("popstate", handlePopState);
|
|
14083
14188
|
window.addEventListener("resize", handleResize);
|
|
14189
|
+
yield redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
14084
14190
|
if (props.initialData) {
|
|
14085
14191
|
searchResultStore.add(__spreadValues2({}, props.initialData));
|
|
14086
14192
|
}
|
|
14087
14193
|
handleMounted();
|
|
14088
14194
|
(_b = (_a = props.options.callbacks) == null ? void 0 : _a.onMounted) == null ? void 0 : _b.call(_a);
|
|
14089
14195
|
mounted.value = true;
|
|
14090
|
-
});
|
|
14196
|
+
}));
|
|
14091
14197
|
onBeforeUnmount(() => {
|
|
14092
14198
|
window.removeEventListener("resize", handleResize);
|
|
14093
14199
|
window.removeEventListener("popstate", handlePopState);
|
|
@@ -14131,6 +14237,13 @@ const _sfc_main$c = /* @__PURE__ */ defineComponent({
|
|
|
14131
14237
|
const context = getLupaTrackingContext();
|
|
14132
14238
|
const limit = publicQuery.limit || defaultSearchResultPageSize.value;
|
|
14133
14239
|
const query2 = __spreadProps2(__spreadValues2(__spreadValues2({}, publicQuery), context), { limit });
|
|
14240
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
14241
|
+
publicQuery.searchText,
|
|
14242
|
+
optionStore.searchResultsRoutingBehavior
|
|
14243
|
+
);
|
|
14244
|
+
if (redirectionApplied) {
|
|
14245
|
+
return;
|
|
14246
|
+
}
|
|
14134
14247
|
if (!query2.searchText && props.options.disallowEmptyQuery) {
|
|
14135
14248
|
return;
|
|
14136
14249
|
}
|
package/dist/lupaSearch.umd.js
CHANGED
|
@@ -6281,6 +6281,14 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6281
6281
|
}
|
|
6282
6282
|
return res.json();
|
|
6283
6283
|
});
|
|
6284
|
+
const loadRedirectionRules = (queryKey, environment, customBaseUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6285
|
+
const res = yield fetch(`${getApiUrl$1(environment, customBaseUrl)}redirections/${queryKey}`, Object.assign(Object.assign({}, defaultConfig$1), { method: "GET" }));
|
|
6286
|
+
if (res.status < 400) {
|
|
6287
|
+
return res.json();
|
|
6288
|
+
}
|
|
6289
|
+
const errors = yield res.json();
|
|
6290
|
+
return { success: false, errors };
|
|
6291
|
+
});
|
|
6284
6292
|
const LupaSearchSdk = {
|
|
6285
6293
|
query: (queryKey, publicQuery, options = null) => {
|
|
6286
6294
|
if (options === null || options === void 0 ? void 0 : options.customUrl) {
|
|
@@ -6302,6 +6310,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6302
6310
|
},
|
|
6303
6311
|
queryByIds: (queryKey, ids, options = null) => {
|
|
6304
6312
|
return queryByIds(queryKey, ids, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6313
|
+
},
|
|
6314
|
+
loadRedirectionRules: (queryKey, options = null) => {
|
|
6315
|
+
return loadRedirectionRules(queryKey, (options === null || options === void 0 ? void 0 : options.environment) || "production", options === null || options === void 0 ? void 0 : options.customBaseUrl);
|
|
6305
6316
|
}
|
|
6306
6317
|
};
|
|
6307
6318
|
const getNormalizedString = (str) => {
|
|
@@ -6380,6 +6391,13 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
6380
6391
|
});
|
|
6381
6392
|
return output;
|
|
6382
6393
|
};
|
|
6394
|
+
const inputMatches = (input, possibleValues) => {
|
|
6395
|
+
if (!input) {
|
|
6396
|
+
return false;
|
|
6397
|
+
}
|
|
6398
|
+
const normalizedInput = getNormalizedString(input);
|
|
6399
|
+
return possibleValues.some((v) => getNormalizedString(v).startsWith(normalizedInput));
|
|
6400
|
+
};
|
|
6383
6401
|
const initAnalyticsTracking = (analyticsOptions) => {
|
|
6384
6402
|
try {
|
|
6385
6403
|
if (analyticsOptions == null ? void 0 : analyticsOptions.enabled) {
|
|
@@ -7330,12 +7348,89 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
7330
7348
|
}
|
|
7331
7349
|
return getMostSpecificHierarchyTerms([param, ...params]);
|
|
7332
7350
|
};
|
|
7351
|
+
const CACHE_KEY = "lupasearch-client-redirections";
|
|
7352
|
+
const useRedirectionStore = defineStore("redirections", () => {
|
|
7353
|
+
const redirections = ref({ rules: [] });
|
|
7354
|
+
const redirectionOptions = ref({ enabled: false, queryKey: "" });
|
|
7355
|
+
const saveToLocalStorage = () => {
|
|
7356
|
+
try {
|
|
7357
|
+
localStorage.setItem(
|
|
7358
|
+
CACHE_KEY,
|
|
7359
|
+
JSON.stringify({ redirections: redirections.value, savedAt: Date.now() })
|
|
7360
|
+
);
|
|
7361
|
+
} catch (e) {
|
|
7362
|
+
}
|
|
7363
|
+
};
|
|
7364
|
+
const tryLoadFromLocalStorage = (config) => {
|
|
7365
|
+
var _a;
|
|
7366
|
+
if (!config.cacheSeconds)
|
|
7367
|
+
return false;
|
|
7368
|
+
try {
|
|
7369
|
+
const data = JSON.parse((_a = localStorage.getItem(CACHE_KEY)) != null ? _a : "");
|
|
7370
|
+
if ((data == null ? void 0 : data.redirections) && Date.now() - data.savedAt < 1e3 * config.cacheSeconds) {
|
|
7371
|
+
redirections.value = data.redirections;
|
|
7372
|
+
return true;
|
|
7373
|
+
}
|
|
7374
|
+
} catch (e) {
|
|
7375
|
+
}
|
|
7376
|
+
return false;
|
|
7377
|
+
};
|
|
7378
|
+
const initiate = (config, options) => __async(void 0, null, function* () {
|
|
7379
|
+
var _a, _b, _c, _d;
|
|
7380
|
+
if ((_a = redirectionOptions.value) == null ? void 0 : _a.enabled) {
|
|
7381
|
+
return;
|
|
7382
|
+
}
|
|
7383
|
+
redirectionOptions.value = config;
|
|
7384
|
+
if (!(config == null ? void 0 : config.enabled)) {
|
|
7385
|
+
return;
|
|
7386
|
+
}
|
|
7387
|
+
const loaded = tryLoadFromLocalStorage(config);
|
|
7388
|
+
if (loaded || ((_c = (_b = redirections.value) == null ? void 0 : _b.rules) == null ? void 0 : _c.length) > 0) {
|
|
7389
|
+
return;
|
|
7390
|
+
}
|
|
7391
|
+
try {
|
|
7392
|
+
const result = yield LupaSearchSdk.loadRedirectionRules(config.queryKey, options);
|
|
7393
|
+
if (!((_d = result == null ? void 0 : result.rules) == null ? void 0 : _d.length)) {
|
|
7394
|
+
return;
|
|
7395
|
+
}
|
|
7396
|
+
redirections.value = result;
|
|
7397
|
+
saveToLocalStorage();
|
|
7398
|
+
} catch (e) {
|
|
7399
|
+
}
|
|
7400
|
+
});
|
|
7401
|
+
const redirectOnKeywordIfConfigured = (input, routingBehavior = "direct-link") => {
|
|
7402
|
+
var _a, _b, _c, _d;
|
|
7403
|
+
if (!((_b = (_a = redirections.value) == null ? void 0 : _a.rules) == null ? void 0 : _b.length)) {
|
|
7404
|
+
return false;
|
|
7405
|
+
}
|
|
7406
|
+
const redirectTo = redirections.value.rules.find((r) => inputMatches(input, r.sources));
|
|
7407
|
+
if (!redirectTo) {
|
|
7408
|
+
return false;
|
|
7409
|
+
}
|
|
7410
|
+
const url = ((_c = redirectionOptions.value) == null ? void 0 : _c.urlTransformer) ? (_d = redirectionOptions.value) == null ? void 0 : _d.urlTransformer(redirectTo == null ? void 0 : redirectTo.target) : redirectTo == null ? void 0 : redirectTo.target;
|
|
7411
|
+
if (url === void 0 || url === null || url === "") {
|
|
7412
|
+
return false;
|
|
7413
|
+
}
|
|
7414
|
+
if (routingBehavior === "event") {
|
|
7415
|
+
emitRoutingEvent(url);
|
|
7416
|
+
} else {
|
|
7417
|
+
window.location.assign(url);
|
|
7418
|
+
}
|
|
7419
|
+
return true;
|
|
7420
|
+
};
|
|
7421
|
+
return {
|
|
7422
|
+
redirections,
|
|
7423
|
+
redirectOnKeywordIfConfigured,
|
|
7424
|
+
initiate
|
|
7425
|
+
};
|
|
7426
|
+
});
|
|
7333
7427
|
const useParamsStore = defineStore("params", () => {
|
|
7334
7428
|
const params = ref({});
|
|
7335
7429
|
const defaultLimit = ref(DEFAULT_PAGE_SIZE);
|
|
7336
7430
|
const searchResultsLink = ref("");
|
|
7337
7431
|
const searchString = ref("");
|
|
7338
7432
|
const optionsStore = useOptionsStore();
|
|
7433
|
+
const redirectionStore = useRedirectionStore();
|
|
7339
7434
|
const query = computed(() => params.value[QUERY_PARAMS_PARSED.QUERY]);
|
|
7340
7435
|
const page = computed(() => {
|
|
7341
7436
|
const page2 = Number(params.value[QUERY_PARAMS_PARSED.PAGE]) || 1;
|
|
@@ -7413,6 +7508,13 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
7413
7508
|
facet
|
|
7414
7509
|
}) => {
|
|
7415
7510
|
var _a;
|
|
7511
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
7512
|
+
searchText,
|
|
7513
|
+
optionsStore.boxRoutingBehavior
|
|
7514
|
+
);
|
|
7515
|
+
if (redirectionApplied) {
|
|
7516
|
+
return;
|
|
7517
|
+
}
|
|
7416
7518
|
if (!searchResultsLink.value || linksMatch(searchResultsLink.value, window.location.pathname)) {
|
|
7417
7519
|
const singleFacetParam = facet ? getFacetParam(facet.key, [facet.title]) : void 0;
|
|
7418
7520
|
const facetParam = singleFacetParam ? [
|
|
@@ -9328,6 +9430,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
9328
9430
|
const searchBoxStore = useSearchBoxStore();
|
|
9329
9431
|
const optionsStore = useOptionsStore();
|
|
9330
9432
|
const trackingStore = useTrackingStore();
|
|
9433
|
+
const redirectionStore = useRedirectionStore();
|
|
9331
9434
|
const inputValue = ref("");
|
|
9332
9435
|
const suggestedValue = ref(defaultSuggestedValue);
|
|
9333
9436
|
const opened = ref(props.isSearchContainer);
|
|
@@ -9366,6 +9469,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
9366
9469
|
paramsStore.setSearchResultsLink(props.options.links.searchResults);
|
|
9367
9470
|
searchBoxStore.saveOptions({ newOptions: props.options });
|
|
9368
9471
|
optionsStore.setSearchBoxOptions({ options: props.options });
|
|
9472
|
+
redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
9369
9473
|
bindSearchTriggers(searchTriggers.value, handleCurrentValueSearch);
|
|
9370
9474
|
if (props.isSearchContainer && searchBoxInput.value) {
|
|
9371
9475
|
(_a2 = searchBoxInput.value) == null ? void 0 : _a2.focus();
|
|
@@ -14056,6 +14160,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
14056
14160
|
const trackingStore = useTrackingStore();
|
|
14057
14161
|
const dynamicDataStore = useDynamicDataStore();
|
|
14058
14162
|
const screenStore = useScreenStore();
|
|
14163
|
+
const redirectionStore = useRedirectionStore();
|
|
14059
14164
|
const initialFilters = computed(() => {
|
|
14060
14165
|
var _a;
|
|
14061
14166
|
return (_a = props.initialFilters) != null ? _a : {};
|
|
@@ -14081,17 +14186,18 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
14081
14186
|
const searchParams = getSearchParams((_a = props.options.ssr) == null ? void 0 : _a.url);
|
|
14082
14187
|
paramStore.add(parseParams(searchParams));
|
|
14083
14188
|
};
|
|
14084
|
-
onMounted(() => {
|
|
14189
|
+
onMounted(() => __async(this, null, function* () {
|
|
14085
14190
|
var _a, _b;
|
|
14086
14191
|
window.addEventListener("popstate", handlePopState);
|
|
14087
14192
|
window.addEventListener("resize", handleResize);
|
|
14193
|
+
yield redirectionStore.initiate(props.options.redirections, props.options.options);
|
|
14088
14194
|
if (props.initialData) {
|
|
14089
14195
|
searchResultStore.add(__spreadValues2({}, props.initialData));
|
|
14090
14196
|
}
|
|
14091
14197
|
handleMounted();
|
|
14092
14198
|
(_b = (_a = props.options.callbacks) == null ? void 0 : _a.onMounted) == null ? void 0 : _b.call(_a);
|
|
14093
14199
|
mounted.value = true;
|
|
14094
|
-
});
|
|
14200
|
+
}));
|
|
14095
14201
|
onBeforeUnmount(() => {
|
|
14096
14202
|
window.removeEventListener("resize", handleResize);
|
|
14097
14203
|
window.removeEventListener("popstate", handlePopState);
|
|
@@ -14135,6 +14241,13 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
14135
14241
|
const context = getLupaTrackingContext();
|
|
14136
14242
|
const limit = publicQuery.limit || defaultSearchResultPageSize.value;
|
|
14137
14243
|
const query2 = __spreadProps2(__spreadValues2(__spreadValues2({}, publicQuery), context), { limit });
|
|
14244
|
+
const redirectionApplied = redirectionStore.redirectOnKeywordIfConfigured(
|
|
14245
|
+
publicQuery.searchText,
|
|
14246
|
+
optionStore.searchResultsRoutingBehavior
|
|
14247
|
+
);
|
|
14248
|
+
if (redirectionApplied) {
|
|
14249
|
+
return;
|
|
14250
|
+
}
|
|
14138
14251
|
if (!query2.searchText && props.options.disallowEmptyQuery) {
|
|
14139
14252
|
return;
|
|
14140
14253
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Environment, SdkOptions, SortDirection, TrackingOptions, DocumentElement, ImageDocumentElement, TitleDocumentElement, DescriptionDocumentElement, CustomDocumentElement, PriceElement, RegularPriceDocumentElement, RatingElement, AddToCartElement, CustomHtmlElement, SingleStarRatingElement, ProductListOptions, CategoryFilterOptions, ProductRecommendationOptions, RecommendationABTestingOptions, SearchBoxOptions, SearchContainerOptions, SearchContainerConfigOptions, SearchResultBadgeElement, BadgeGenerateSeed, BadgeGenerateOptions, BadgeOptions, RoutingBehavior, SearchResultsOptions, FacetStyle, SearchResultEventCallbacks, CallbackContext, SortCallbackContext, FacetFilterQuery, SearchResultsFilterOptions, ResultFacetOptions, DynamicData, AnchorPosition, SortOptions, SearchResultsSortOptions, ChatOptions } from '@getlupa/vue';
|
|
1
|
+
import type { Environment, SdkOptions, SortDirection, TrackingOptions, DocumentElement, ImageDocumentElement, TitleDocumentElement, DescriptionDocumentElement, CustomDocumentElement, PriceElement, RegularPriceDocumentElement, RatingElement, AddToCartElement, CustomHtmlElement, SingleStarRatingElement, ProductListOptions, CategoryFilterOptions, ProductRecommendationOptions, RecommendationABTestingOptions, SearchBoxOptions, SearchContainerOptions, SearchContainerConfigOptions, SearchResultBadgeElement, BadgeGenerateSeed, BadgeGenerateOptions, BadgeOptions, RoutingBehavior, SearchResultsOptions, FacetStyle, SearchResultEventCallbacks, CallbackContext, SortCallbackContext, FacetFilterQuery, SearchResultsFilterOptions, ResultFacetOptions, DynamicData, AnchorPosition, SortOptions, SearchResultsSortOptions, ChatOptions, RedirectionOptions } from '@getlupa/vue';
|
|
2
2
|
import { DocumentElementType, SearchBoxPanelType, BadgeType, SearchResultBadgeType } from '@getlupa/vue';
|
|
3
3
|
type MountOptions = {
|
|
4
4
|
fetch: boolean;
|
|
@@ -19,7 +19,7 @@ declare const lupaSearch: {
|
|
|
19
19
|
clearChat: (selector?: string) => void;
|
|
20
20
|
};
|
|
21
21
|
export { DocumentElementType, SearchBoxPanelType, BadgeType };
|
|
22
|
-
export type { TrackingOptions, SearchBoxOptions, SearchResultsOptions, ProductListOptions, SdkOptions, FacetStyle, Environment, RoutingBehavior, AnchorPosition, SortDirection, DocumentElement, ImageDocumentElement, TitleDocumentElement, DescriptionDocumentElement, CustomDocumentElement, PriceElement, RegularPriceDocumentElement, RatingElement, AddToCartElement, CustomHtmlElement, SortOptions, SearchResultsSortOptions, SearchResultEventCallbacks, CallbackContext, SortCallbackContext, FacetFilterQuery, CategoryFilterOptions, SearchResultsFilterOptions, SearchResultBadgeType, SearchResultBadgeElement, ResultFacetOptions, BadgeGenerateSeed, BadgeGenerateOptions, BadgeOptions, MountOptions, SearchContainerOptions, SearchContainerConfigOptions, SingleStarRatingElement, DynamicData, ProductRecommendationOptions, RecommendationABTestingOptions, ChatOptions };
|
|
22
|
+
export type { TrackingOptions, SearchBoxOptions, SearchResultsOptions, ProductListOptions, SdkOptions, FacetStyle, Environment, RoutingBehavior, AnchorPosition, SortDirection, DocumentElement, ImageDocumentElement, TitleDocumentElement, DescriptionDocumentElement, CustomDocumentElement, PriceElement, RegularPriceDocumentElement, RatingElement, AddToCartElement, CustomHtmlElement, SortOptions, SearchResultsSortOptions, SearchResultEventCallbacks, CallbackContext, SortCallbackContext, FacetFilterQuery, CategoryFilterOptions, SearchResultsFilterOptions, SearchResultBadgeType, SearchResultBadgeElement, ResultFacetOptions, BadgeGenerateSeed, BadgeGenerateOptions, BadgeOptions, MountOptions, SearchContainerOptions, SearchContainerConfigOptions, SingleStarRatingElement, DynamicData, ProductRecommendationOptions, RecommendationABTestingOptions, ChatOptions, RedirectionOptions };
|
|
23
23
|
declare global {
|
|
24
24
|
interface Window {
|
|
25
25
|
getLupa: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getlupa/client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"main": "dist/lupaSearch.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@getlupa/client-sdk": "^1.3.4",
|
|
23
|
-
"@getlupa/vue": "0.
|
|
23
|
+
"@getlupa/vue": "0.7.1",
|
|
24
24
|
"@rushstack/eslint-patch": "^1.3.2",
|
|
25
25
|
"@tsconfig/node18": "^2.0.1",
|
|
26
26
|
"@types/jsdom": "^21.1.1",
|