@getlupa/vue 0.14.0 → 0.14.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/dist/lupaSearch.js +70 -4
- package/dist/lupaSearch.mjs +70 -4
- 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) {
|
|
@@ -12840,19 +12843,20 @@ const renderHtmlTemplate = (template, document2 = {}) => {
|
|
|
12840
12843
|
return sanitizeHtml$1(rendered);
|
|
12841
12844
|
};
|
|
12842
12845
|
const getFieldValue = (doc, field = "") => {
|
|
12846
|
+
var _a;
|
|
12843
12847
|
if (typeof field === "number") {
|
|
12844
12848
|
return field;
|
|
12845
12849
|
}
|
|
12846
|
-
return field.split(".").reduce((obj, key) => obj ? obj[key] : void 0, doc);
|
|
12850
|
+
return (_a = field == null ? void 0 : field.split(".")) == null ? void 0 : _a.reduce((obj, key) => obj ? obj[key] : void 0, doc);
|
|
12847
12851
|
};
|
|
12848
12852
|
const processDisplayCondition = (displayCondition, doc = {}) => {
|
|
12849
12853
|
const { condition, fields } = displayCondition;
|
|
12850
|
-
if (fields
|
|
12854
|
+
if (!(fields == null ? void 0 : fields.length)) {
|
|
12851
12855
|
return false;
|
|
12852
12856
|
}
|
|
12853
12857
|
switch (condition) {
|
|
12854
12858
|
case "exists": {
|
|
12855
|
-
return fields.every((field) => getFieldValue(doc, field) !== void 0);
|
|
12859
|
+
return fields == null ? void 0 : fields.every((field) => getFieldValue(doc, field) !== void 0);
|
|
12856
12860
|
}
|
|
12857
12861
|
case "equals": {
|
|
12858
12862
|
if (fields.length < 2)
|
|
@@ -19724,6 +19728,62 @@ const _sfc_main$b = /* @__PURE__ */ vue.defineComponent({
|
|
|
19724
19728
|
};
|
|
19725
19729
|
}
|
|
19726
19730
|
});
|
|
19731
|
+
const extractValue = (options) => {
|
|
19732
|
+
switch (options.extractFrom) {
|
|
19733
|
+
case "url":
|
|
19734
|
+
return extractFromUrl(options);
|
|
19735
|
+
case "localStorage":
|
|
19736
|
+
case "sessionStorage":
|
|
19737
|
+
return extractFromStorage(options);
|
|
19738
|
+
case "htmlElementText":
|
|
19739
|
+
return extractFromHtmlElementText(options);
|
|
19740
|
+
default:
|
|
19741
|
+
return options.default;
|
|
19742
|
+
}
|
|
19743
|
+
};
|
|
19744
|
+
const extractFromUrl = (options) => {
|
|
19745
|
+
const regex = new RegExp(options.regex);
|
|
19746
|
+
const match = window.location.href.match(regex);
|
|
19747
|
+
return match ? match[1] : options.default;
|
|
19748
|
+
};
|
|
19749
|
+
const extractFromStorage = (options) => {
|
|
19750
|
+
const storage = options.extractFrom === "localStorage" ? localStorage : sessionStorage;
|
|
19751
|
+
let rawValue2 = "";
|
|
19752
|
+
try {
|
|
19753
|
+
rawValue2 = storage.getItem(options.key);
|
|
19754
|
+
} catch (e2) {
|
|
19755
|
+
return options.default;
|
|
19756
|
+
}
|
|
19757
|
+
if (rawValue2) {
|
|
19758
|
+
try {
|
|
19759
|
+
const parsedValue = JSON.parse(rawValue2);
|
|
19760
|
+
return options.path ? getValueFromPath(parsedValue, options.path) : parsedValue;
|
|
19761
|
+
} catch (e2) {
|
|
19762
|
+
return rawValue2;
|
|
19763
|
+
}
|
|
19764
|
+
}
|
|
19765
|
+
return options.default;
|
|
19766
|
+
};
|
|
19767
|
+
const extractFromHtmlElementText = (options) => {
|
|
19768
|
+
var _a;
|
|
19769
|
+
const element = document.querySelector(options.querySelector);
|
|
19770
|
+
return element ? ((_a = element.textContent) == null ? void 0 : _a.trim()) || options.default : options.default;
|
|
19771
|
+
};
|
|
19772
|
+
const getValueFromPath = (obj, path) => {
|
|
19773
|
+
return path.split(".").reduce((value, key) => value && value[key] || null, obj);
|
|
19774
|
+
};
|
|
19775
|
+
const processExtractionObject = (value = {}) => {
|
|
19776
|
+
var _a;
|
|
19777
|
+
const parsedObject = {};
|
|
19778
|
+
for (const key in value) {
|
|
19779
|
+
if (isObject$1(value[key]) && ((_a = value[key]) == null ? void 0 : _a.extractFrom)) {
|
|
19780
|
+
parsedObject[key] = extractValue(value[key]);
|
|
19781
|
+
} else {
|
|
19782
|
+
parsedObject[key] = value[key];
|
|
19783
|
+
}
|
|
19784
|
+
}
|
|
19785
|
+
return parsedObject;
|
|
19786
|
+
};
|
|
19727
19787
|
const _sfc_main$a = /* @__PURE__ */ vue.defineComponent({
|
|
19728
19788
|
__name: "ProductList",
|
|
19729
19789
|
props: {
|
|
@@ -19743,6 +19803,9 @@ const _sfc_main$a = /* @__PURE__ */ vue.defineComponent({
|
|
|
19743
19803
|
var _a;
|
|
19744
19804
|
(_a = searchResults.value) == null ? void 0 : _a.handleMounted();
|
|
19745
19805
|
};
|
|
19806
|
+
vue.computed(() => {
|
|
19807
|
+
return __spreadValues({}, processExtractionObject(props.options.initialFilters));
|
|
19808
|
+
});
|
|
19746
19809
|
__expose({ fetch: fetch2 });
|
|
19747
19810
|
return (_ctx, _cache) => {
|
|
19748
19811
|
return vue.openBlock(), vue.createElementBlock("div", null, [
|
|
@@ -26120,13 +26183,16 @@ const _sfc_main$8 = /* @__PURE__ */ vue.defineComponent({
|
|
|
26120
26183
|
loading.value = false;
|
|
26121
26184
|
}
|
|
26122
26185
|
});
|
|
26186
|
+
const itemId = vue.computed(() => {
|
|
26187
|
+
return typeof props.options.itemId === "string" || typeof props.options.itemId === "number" || Array.isArray(props.options.itemId) ? props.options.itemId : extractValue(props.options.itemId);
|
|
26188
|
+
});
|
|
26123
26189
|
const loadLupaRecommendations = () => __async(this, null, function* () {
|
|
26124
26190
|
recommendationsType.value = "recommendations_lupasearch";
|
|
26125
26191
|
try {
|
|
26126
26192
|
loading.value = true;
|
|
26127
26193
|
const result2 = yield LupaSearchSdk.recommend(
|
|
26128
26194
|
props.options.queryKey,
|
|
26129
|
-
|
|
26195
|
+
itemId.value,
|
|
26130
26196
|
props.options.recommendationFilters,
|
|
26131
26197
|
props.options.options
|
|
26132
26198
|
);
|
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) {
|
|
@@ -12838,19 +12841,20 @@ const renderHtmlTemplate = (template, document2 = {}) => {
|
|
|
12838
12841
|
return sanitizeHtml$1(rendered);
|
|
12839
12842
|
};
|
|
12840
12843
|
const getFieldValue = (doc, field = "") => {
|
|
12844
|
+
var _a;
|
|
12841
12845
|
if (typeof field === "number") {
|
|
12842
12846
|
return field;
|
|
12843
12847
|
}
|
|
12844
|
-
return field.split(".").reduce((obj, key) => obj ? obj[key] : void 0, doc);
|
|
12848
|
+
return (_a = field == null ? void 0 : field.split(".")) == null ? void 0 : _a.reduce((obj, key) => obj ? obj[key] : void 0, doc);
|
|
12845
12849
|
};
|
|
12846
12850
|
const processDisplayCondition = (displayCondition, doc = {}) => {
|
|
12847
12851
|
const { condition, fields } = displayCondition;
|
|
12848
|
-
if (fields
|
|
12852
|
+
if (!(fields == null ? void 0 : fields.length)) {
|
|
12849
12853
|
return false;
|
|
12850
12854
|
}
|
|
12851
12855
|
switch (condition) {
|
|
12852
12856
|
case "exists": {
|
|
12853
|
-
return fields.every((field) => getFieldValue(doc, field) !== void 0);
|
|
12857
|
+
return fields == null ? void 0 : fields.every((field) => getFieldValue(doc, field) !== void 0);
|
|
12854
12858
|
}
|
|
12855
12859
|
case "equals": {
|
|
12856
12860
|
if (fields.length < 2)
|
|
@@ -19722,6 +19726,62 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
|
|
|
19722
19726
|
};
|
|
19723
19727
|
}
|
|
19724
19728
|
});
|
|
19729
|
+
const extractValue = (options) => {
|
|
19730
|
+
switch (options.extractFrom) {
|
|
19731
|
+
case "url":
|
|
19732
|
+
return extractFromUrl(options);
|
|
19733
|
+
case "localStorage":
|
|
19734
|
+
case "sessionStorage":
|
|
19735
|
+
return extractFromStorage(options);
|
|
19736
|
+
case "htmlElementText":
|
|
19737
|
+
return extractFromHtmlElementText(options);
|
|
19738
|
+
default:
|
|
19739
|
+
return options.default;
|
|
19740
|
+
}
|
|
19741
|
+
};
|
|
19742
|
+
const extractFromUrl = (options) => {
|
|
19743
|
+
const regex = new RegExp(options.regex);
|
|
19744
|
+
const match = window.location.href.match(regex);
|
|
19745
|
+
return match ? match[1] : options.default;
|
|
19746
|
+
};
|
|
19747
|
+
const extractFromStorage = (options) => {
|
|
19748
|
+
const storage = options.extractFrom === "localStorage" ? localStorage : sessionStorage;
|
|
19749
|
+
let rawValue2 = "";
|
|
19750
|
+
try {
|
|
19751
|
+
rawValue2 = storage.getItem(options.key);
|
|
19752
|
+
} catch (e2) {
|
|
19753
|
+
return options.default;
|
|
19754
|
+
}
|
|
19755
|
+
if (rawValue2) {
|
|
19756
|
+
try {
|
|
19757
|
+
const parsedValue = JSON.parse(rawValue2);
|
|
19758
|
+
return options.path ? getValueFromPath(parsedValue, options.path) : parsedValue;
|
|
19759
|
+
} catch (e2) {
|
|
19760
|
+
return rawValue2;
|
|
19761
|
+
}
|
|
19762
|
+
}
|
|
19763
|
+
return options.default;
|
|
19764
|
+
};
|
|
19765
|
+
const extractFromHtmlElementText = (options) => {
|
|
19766
|
+
var _a;
|
|
19767
|
+
const element = document.querySelector(options.querySelector);
|
|
19768
|
+
return element ? ((_a = element.textContent) == null ? void 0 : _a.trim()) || options.default : options.default;
|
|
19769
|
+
};
|
|
19770
|
+
const getValueFromPath = (obj, path) => {
|
|
19771
|
+
return path.split(".").reduce((value, key) => value && value[key] || null, obj);
|
|
19772
|
+
};
|
|
19773
|
+
const processExtractionObject = (value = {}) => {
|
|
19774
|
+
var _a;
|
|
19775
|
+
const parsedObject = {};
|
|
19776
|
+
for (const key in value) {
|
|
19777
|
+
if (isObject$1(value[key]) && ((_a = value[key]) == null ? void 0 : _a.extractFrom)) {
|
|
19778
|
+
parsedObject[key] = extractValue(value[key]);
|
|
19779
|
+
} else {
|
|
19780
|
+
parsedObject[key] = value[key];
|
|
19781
|
+
}
|
|
19782
|
+
}
|
|
19783
|
+
return parsedObject;
|
|
19784
|
+
};
|
|
19725
19785
|
const _sfc_main$a = /* @__PURE__ */ defineComponent({
|
|
19726
19786
|
__name: "ProductList",
|
|
19727
19787
|
props: {
|
|
@@ -19741,6 +19801,9 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
|
|
|
19741
19801
|
var _a;
|
|
19742
19802
|
(_a = searchResults.value) == null ? void 0 : _a.handleMounted();
|
|
19743
19803
|
};
|
|
19804
|
+
computed(() => {
|
|
19805
|
+
return __spreadValues({}, processExtractionObject(props.options.initialFilters));
|
|
19806
|
+
});
|
|
19744
19807
|
__expose({ fetch: fetch2 });
|
|
19745
19808
|
return (_ctx, _cache) => {
|
|
19746
19809
|
return openBlock(), createElementBlock("div", null, [
|
|
@@ -26118,13 +26181,16 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
|
|
|
26118
26181
|
loading.value = false;
|
|
26119
26182
|
}
|
|
26120
26183
|
});
|
|
26184
|
+
const itemId = computed(() => {
|
|
26185
|
+
return typeof props.options.itemId === "string" || typeof props.options.itemId === "number" || Array.isArray(props.options.itemId) ? props.options.itemId : extractValue(props.options.itemId);
|
|
26186
|
+
});
|
|
26121
26187
|
const loadLupaRecommendations = () => __async(this, null, function* () {
|
|
26122
26188
|
recommendationsType.value = "recommendations_lupasearch";
|
|
26123
26189
|
try {
|
|
26124
26190
|
loading.value = true;
|
|
26125
26191
|
const result2 = yield LupaSearchSdk.recommend(
|
|
26126
26192
|
props.options.queryKey,
|
|
26127
|
-
|
|
26193
|
+
itemId.value,
|
|
26128
26194
|
props.options.recommendationFilters,
|
|
26129
26195
|
props.options.options
|
|
26130
26196
|
);
|
|
@@ -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;
|