@getlupa/vue 0.14.0 → 0.14.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.js +66 -1
- package/dist/lupaSearch.mjs +66 -1
- package/dist/src/types/DataExtraction.d.ts +19 -0
- package/dist/src/types/product-list/ProductListOptions.d.ts +2 -1
- package/dist/src/types/recommendations/RecommendationsOptions.d.ts +2 -1
- package/dist/src/utils/extraction.utils.d.ts +3 -0
- package/dist/src/utils/picker.utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/lupaSearch.js
CHANGED
|
@@ -2589,6 +2589,9 @@ const reverseKeyValue = (obj) => {
|
|
|
2589
2589
|
const getPageCount = (total, limit) => {
|
|
2590
2590
|
return Math.ceil(total / limit) || 0;
|
|
2591
2591
|
};
|
|
2592
|
+
const isObject$1 = (value) => {
|
|
2593
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2594
|
+
};
|
|
2592
2595
|
const parseParam = (key, params) => {
|
|
2593
2596
|
const value = params.get(key);
|
|
2594
2597
|
if (!value) {
|
|
@@ -19724,6 +19727,62 @@ const _sfc_main$b = /* @__PURE__ */ vue.defineComponent({
|
|
|
19724
19727
|
};
|
|
19725
19728
|
}
|
|
19726
19729
|
});
|
|
19730
|
+
const extractValue = (options) => {
|
|
19731
|
+
switch (options.extractFrom) {
|
|
19732
|
+
case "url":
|
|
19733
|
+
return extractFromUrl(options);
|
|
19734
|
+
case "localStorage":
|
|
19735
|
+
case "sessionStorage":
|
|
19736
|
+
return extractFromStorage(options);
|
|
19737
|
+
case "htmlElementText":
|
|
19738
|
+
return extractFromHtmlElementText(options);
|
|
19739
|
+
default:
|
|
19740
|
+
return options.default;
|
|
19741
|
+
}
|
|
19742
|
+
};
|
|
19743
|
+
const extractFromUrl = (options) => {
|
|
19744
|
+
const regex = new RegExp(options.regex);
|
|
19745
|
+
const match = window.location.href.match(regex);
|
|
19746
|
+
return match ? match[1] : options.default;
|
|
19747
|
+
};
|
|
19748
|
+
const extractFromStorage = (options) => {
|
|
19749
|
+
const storage = options.extractFrom === "localStorage" ? localStorage : sessionStorage;
|
|
19750
|
+
let rawValue2 = "";
|
|
19751
|
+
try {
|
|
19752
|
+
rawValue2 = storage.getItem(options.key);
|
|
19753
|
+
} catch (e2) {
|
|
19754
|
+
return options.default;
|
|
19755
|
+
}
|
|
19756
|
+
if (rawValue2) {
|
|
19757
|
+
try {
|
|
19758
|
+
const parsedValue = JSON.parse(rawValue2);
|
|
19759
|
+
return options.path ? getValueFromPath(parsedValue, options.path) : parsedValue;
|
|
19760
|
+
} catch (e2) {
|
|
19761
|
+
return rawValue2;
|
|
19762
|
+
}
|
|
19763
|
+
}
|
|
19764
|
+
return options.default;
|
|
19765
|
+
};
|
|
19766
|
+
const extractFromHtmlElementText = (options) => {
|
|
19767
|
+
var _a;
|
|
19768
|
+
const element = document.querySelector(options.querySelector);
|
|
19769
|
+
return element ? ((_a = element.textContent) == null ? void 0 : _a.trim()) || options.default : options.default;
|
|
19770
|
+
};
|
|
19771
|
+
const getValueFromPath = (obj, path) => {
|
|
19772
|
+
return path.split(".").reduce((value, key) => value && value[key] || null, obj);
|
|
19773
|
+
};
|
|
19774
|
+
const processExtractionObject = (value = {}) => {
|
|
19775
|
+
var _a;
|
|
19776
|
+
const parsedObject = {};
|
|
19777
|
+
for (const key in value) {
|
|
19778
|
+
if (isObject$1(value[key]) && ((_a = value[key]) == null ? void 0 : _a.extractFrom)) {
|
|
19779
|
+
parsedObject[key] = extractValue(value[key]);
|
|
19780
|
+
} else {
|
|
19781
|
+
parsedObject[key] = value[key];
|
|
19782
|
+
}
|
|
19783
|
+
}
|
|
19784
|
+
return parsedObject;
|
|
19785
|
+
};
|
|
19727
19786
|
const _sfc_main$a = /* @__PURE__ */ vue.defineComponent({
|
|
19728
19787
|
__name: "ProductList",
|
|
19729
19788
|
props: {
|
|
@@ -19743,6 +19802,9 @@ const _sfc_main$a = /* @__PURE__ */ vue.defineComponent({
|
|
|
19743
19802
|
var _a;
|
|
19744
19803
|
(_a = searchResults.value) == null ? void 0 : _a.handleMounted();
|
|
19745
19804
|
};
|
|
19805
|
+
vue.computed(() => {
|
|
19806
|
+
return __spreadValues({}, processExtractionObject(props.options.initialFilters));
|
|
19807
|
+
});
|
|
19746
19808
|
__expose({ fetch: fetch2 });
|
|
19747
19809
|
return (_ctx, _cache) => {
|
|
19748
19810
|
return vue.openBlock(), vue.createElementBlock("div", null, [
|
|
@@ -26120,13 +26182,16 @@ const _sfc_main$8 = /* @__PURE__ */ vue.defineComponent({
|
|
|
26120
26182
|
loading.value = false;
|
|
26121
26183
|
}
|
|
26122
26184
|
});
|
|
26185
|
+
const itemId = vue.computed(() => {
|
|
26186
|
+
return typeof props.options.itemId === "string" || Array.isArray(props.options.itemId) ? props.options.itemId : extractValue(props.options.itemId);
|
|
26187
|
+
});
|
|
26123
26188
|
const loadLupaRecommendations = () => __async(this, null, function* () {
|
|
26124
26189
|
recommendationsType.value = "recommendations_lupasearch";
|
|
26125
26190
|
try {
|
|
26126
26191
|
loading.value = true;
|
|
26127
26192
|
const result2 = yield LupaSearchSdk.recommend(
|
|
26128
26193
|
props.options.queryKey,
|
|
26129
|
-
|
|
26194
|
+
itemId.value,
|
|
26130
26195
|
props.options.recommendationFilters,
|
|
26131
26196
|
props.options.options
|
|
26132
26197
|
);
|
package/dist/lupaSearch.mjs
CHANGED
|
@@ -2587,6 +2587,9 @@ const reverseKeyValue = (obj) => {
|
|
|
2587
2587
|
const getPageCount = (total, limit) => {
|
|
2588
2588
|
return Math.ceil(total / limit) || 0;
|
|
2589
2589
|
};
|
|
2590
|
+
const isObject$1 = (value) => {
|
|
2591
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
2592
|
+
};
|
|
2590
2593
|
const parseParam = (key, params) => {
|
|
2591
2594
|
const value = params.get(key);
|
|
2592
2595
|
if (!value) {
|
|
@@ -19722,6 +19725,62 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
|
|
|
19722
19725
|
};
|
|
19723
19726
|
}
|
|
19724
19727
|
});
|
|
19728
|
+
const extractValue = (options) => {
|
|
19729
|
+
switch (options.extractFrom) {
|
|
19730
|
+
case "url":
|
|
19731
|
+
return extractFromUrl(options);
|
|
19732
|
+
case "localStorage":
|
|
19733
|
+
case "sessionStorage":
|
|
19734
|
+
return extractFromStorage(options);
|
|
19735
|
+
case "htmlElementText":
|
|
19736
|
+
return extractFromHtmlElementText(options);
|
|
19737
|
+
default:
|
|
19738
|
+
return options.default;
|
|
19739
|
+
}
|
|
19740
|
+
};
|
|
19741
|
+
const extractFromUrl = (options) => {
|
|
19742
|
+
const regex = new RegExp(options.regex);
|
|
19743
|
+
const match = window.location.href.match(regex);
|
|
19744
|
+
return match ? match[1] : options.default;
|
|
19745
|
+
};
|
|
19746
|
+
const extractFromStorage = (options) => {
|
|
19747
|
+
const storage = options.extractFrom === "localStorage" ? localStorage : sessionStorage;
|
|
19748
|
+
let rawValue2 = "";
|
|
19749
|
+
try {
|
|
19750
|
+
rawValue2 = storage.getItem(options.key);
|
|
19751
|
+
} catch (e2) {
|
|
19752
|
+
return options.default;
|
|
19753
|
+
}
|
|
19754
|
+
if (rawValue2) {
|
|
19755
|
+
try {
|
|
19756
|
+
const parsedValue = JSON.parse(rawValue2);
|
|
19757
|
+
return options.path ? getValueFromPath(parsedValue, options.path) : parsedValue;
|
|
19758
|
+
} catch (e2) {
|
|
19759
|
+
return rawValue2;
|
|
19760
|
+
}
|
|
19761
|
+
}
|
|
19762
|
+
return options.default;
|
|
19763
|
+
};
|
|
19764
|
+
const extractFromHtmlElementText = (options) => {
|
|
19765
|
+
var _a;
|
|
19766
|
+
const element = document.querySelector(options.querySelector);
|
|
19767
|
+
return element ? ((_a = element.textContent) == null ? void 0 : _a.trim()) || options.default : options.default;
|
|
19768
|
+
};
|
|
19769
|
+
const getValueFromPath = (obj, path) => {
|
|
19770
|
+
return path.split(".").reduce((value, key) => value && value[key] || null, obj);
|
|
19771
|
+
};
|
|
19772
|
+
const processExtractionObject = (value = {}) => {
|
|
19773
|
+
var _a;
|
|
19774
|
+
const parsedObject = {};
|
|
19775
|
+
for (const key in value) {
|
|
19776
|
+
if (isObject$1(value[key]) && ((_a = value[key]) == null ? void 0 : _a.extractFrom)) {
|
|
19777
|
+
parsedObject[key] = extractValue(value[key]);
|
|
19778
|
+
} else {
|
|
19779
|
+
parsedObject[key] = value[key];
|
|
19780
|
+
}
|
|
19781
|
+
}
|
|
19782
|
+
return parsedObject;
|
|
19783
|
+
};
|
|
19725
19784
|
const _sfc_main$a = /* @__PURE__ */ defineComponent({
|
|
19726
19785
|
__name: "ProductList",
|
|
19727
19786
|
props: {
|
|
@@ -19741,6 +19800,9 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
|
|
|
19741
19800
|
var _a;
|
|
19742
19801
|
(_a = searchResults.value) == null ? void 0 : _a.handleMounted();
|
|
19743
19802
|
};
|
|
19803
|
+
computed(() => {
|
|
19804
|
+
return __spreadValues({}, processExtractionObject(props.options.initialFilters));
|
|
19805
|
+
});
|
|
19744
19806
|
__expose({ fetch: fetch2 });
|
|
19745
19807
|
return (_ctx, _cache) => {
|
|
19746
19808
|
return openBlock(), createElementBlock("div", null, [
|
|
@@ -26118,13 +26180,16 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
|
|
|
26118
26180
|
loading.value = false;
|
|
26119
26181
|
}
|
|
26120
26182
|
});
|
|
26183
|
+
const itemId = computed(() => {
|
|
26184
|
+
return typeof props.options.itemId === "string" || Array.isArray(props.options.itemId) ? props.options.itemId : extractValue(props.options.itemId);
|
|
26185
|
+
});
|
|
26121
26186
|
const loadLupaRecommendations = () => __async(this, null, function* () {
|
|
26122
26187
|
recommendationsType.value = "recommendations_lupasearch";
|
|
26123
26188
|
try {
|
|
26124
26189
|
loading.value = true;
|
|
26125
26190
|
const result2 = yield LupaSearchSdk.recommend(
|
|
26126
26191
|
props.options.queryKey,
|
|
26127
|
-
|
|
26192
|
+
itemId.value,
|
|
26128
26193
|
props.options.recommendationFilters,
|
|
26129
26194
|
props.options.options
|
|
26130
26195
|
);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type ExtractFrom = 'url' | 'localStorage' | 'sessionStorage' | 'htmlElementText';
|
|
2
|
+
export type BaseExtractFrom = {
|
|
3
|
+
extractFrom: ExtractFrom;
|
|
4
|
+
default: string | number | Record<string, unknown>;
|
|
5
|
+
};
|
|
6
|
+
export type ExtractFromUrl = BaseExtractFrom & {
|
|
7
|
+
extractFrom: 'url';
|
|
8
|
+
regex: string;
|
|
9
|
+
};
|
|
10
|
+
export type ExtractFromStorage = BaseExtractFrom & {
|
|
11
|
+
extractFrom: 'localStorage' | 'sessionStorage';
|
|
12
|
+
key: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
};
|
|
15
|
+
export type ExtractFromHtmlElementText = BaseExtractFrom & {
|
|
16
|
+
extractFrom: 'htmlElementText';
|
|
17
|
+
querySelector: string;
|
|
18
|
+
};
|
|
19
|
+
export type DataExtraction = ExtractFromUrl | ExtractFromStorage | ExtractFromHtmlElementText;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { FilterGroup } from '@getlupa/client-sdk/Types';
|
|
2
2
|
import type { RoutingBehavior } from '../search-results/RoutingBehavior';
|
|
3
3
|
import type { SearchResultsOptions } from '../search-results/SearchResultsOptions';
|
|
4
|
+
import { DataExtraction } from '../DataExtraction';
|
|
4
5
|
export type CategoryFilterOptions = {
|
|
5
6
|
queryKey?: string;
|
|
6
7
|
routingBehavior?: RoutingBehavior;
|
|
@@ -24,6 +25,6 @@ export type CategoryFilterOptions = {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
export type ProductListOptions = SearchResultsOptions & {
|
|
27
|
-
initialFilters?: FilterGroup
|
|
28
|
+
initialFilters?: FilterGroup | Record<string, DataExtraction>;
|
|
28
29
|
categories?: CategoryFilterOptions;
|
|
29
30
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FilterGroup } from '@getlupa/client-sdk/Types';
|
|
2
2
|
import type { SdkOptions } from '../General';
|
|
3
3
|
import { SearchResultsProductOptions } from '../search-results/SearchResultsOptions';
|
|
4
|
+
import { DataExtraction } from '../DataExtraction';
|
|
4
5
|
export type RecommenderCarouselOptions = {
|
|
5
6
|
itemsToShow?: number;
|
|
6
7
|
snapAlign?: string;
|
|
@@ -12,7 +13,7 @@ export type ProductRecommendationOptions = SearchResultsProductOptions & {
|
|
|
12
13
|
} & {
|
|
13
14
|
containerSelector: string;
|
|
14
15
|
queryKey: string;
|
|
15
|
-
itemId: string[] | string;
|
|
16
|
+
itemId: DataExtraction | (string[] | string);
|
|
16
17
|
abTesting?: RecommendationABTestingOptions;
|
|
17
18
|
carousel?: RecommenderCarouselOptions;
|
|
18
19
|
recommendationFilters?: FilterGroup;
|
|
@@ -3,3 +3,4 @@ export declare const getHint: (suggestion: string, inputValue: string) => string
|
|
|
3
3
|
export declare const reverseKeyValue: (obj: Record<string, string>) => Record<string, string>;
|
|
4
4
|
export declare const pickClosestNumber: (numbers: number[], closestTo: number) => number;
|
|
5
5
|
export declare const getPageCount: (total: number, limit: number) => number;
|
|
6
|
+
export declare const isObject: (value: unknown) => boolean;
|