fast-simon-sdk 1.6.80 → 1.6.81
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/lib/config.d.ts
CHANGED
|
@@ -25,4 +25,4 @@ export declare const PROMOTED_PRODUCTS_BY_PERSONALIZATION = "isp-promoted-produc
|
|
|
25
25
|
export declare const INITIALIZATION_ERROR_MSG = "\u274C IS+ SDK Error | SDK Not Initialized Yet";
|
|
26
26
|
export declare const ISP_LOCAL_STORAGE_LOAD_ERROR_MSG = "\u274C IS+ SDK Error | Error parsing data from localStorage";
|
|
27
27
|
export declare const RECENT_PRODUCTS_EXPIRY_DAYS = 5;
|
|
28
|
-
export declare const RECENT_PRODUCTS_LENGTH_LIMIT =
|
|
28
|
+
export declare const RECENT_PRODUCTS_LENGTH_LIMIT = 20;
|
package/lib/config.js
CHANGED
|
@@ -30,5 +30,5 @@ exports.PROMOTED_PRODUCTS_BY_PERSONALIZATION = "isp-promoted-products-by-persona
|
|
|
30
30
|
exports.INITIALIZATION_ERROR_MSG = "\u274C IS+ SDK Error | SDK Not Initialized Yet";
|
|
31
31
|
exports.ISP_LOCAL_STORAGE_LOAD_ERROR_MSG = "\u274C IS+ SDK Error | Error parsing data from localStorage";
|
|
32
32
|
exports.RECENT_PRODUCTS_EXPIRY_DAYS = 5;
|
|
33
|
-
exports.RECENT_PRODUCTS_LENGTH_LIMIT =
|
|
33
|
+
exports.RECENT_PRODUCTS_LENGTH_LIMIT = 20;
|
|
34
34
|
//# sourceMappingURL=config.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export default function updateRecentSearches(params: object): void;
|
|
2
2
|
/**
|
|
3
|
-
* Fetches recent product as list of product id.
|
|
3
|
+
* Fetches recent product as list of product id (stripped of variant suffix).
|
|
4
4
|
* @returns {string[]} A list of product IDs.
|
|
5
5
|
*/
|
|
6
6
|
export declare function getRecentProducts(): string[];
|
|
7
7
|
/**
|
|
8
|
-
* Fetches recent product as a record of id and timestamp.
|
|
8
|
+
* Fetches recent product as a record of id and timestamp (keys stripped of variant suffix).
|
|
9
9
|
* @returns {Record<string, number>} A map of product IDs to their timestamps.
|
|
10
10
|
*/
|
|
11
11
|
export declare function getRecentProductsTimestamps(): Record<string, number>;
|
|
@@ -6,29 +6,32 @@ exports.getRecentProductsTimestamps = getRecentProductsTimestamps;
|
|
|
6
6
|
var config_1 = require("../config");
|
|
7
7
|
var RELATED_KEY = "ISP_PRODUCTS_VIEWED_SESSION_2";
|
|
8
8
|
function updateRecentSearches(params) {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
10
10
|
var anyParams = params;
|
|
11
|
-
var id = (_c = (_b = (_a = anyParams.id) !== null && _a !== void 0 ? _a : anyParams.product_id) !== null && _b !== void 0 ? _b : anyParams.pid) !== null && _c !== void 0 ? _c : null;
|
|
12
|
-
var
|
|
11
|
+
var id = (_d = (_c = (_b = (_a = anyParams.id) !== null && _a !== void 0 ? _a : anyParams.product_id) !== null && _b !== void 0 ? _b : anyParams.pid) !== null && _c !== void 0 ? _c : anyParams.cart_product) !== null && _d !== void 0 ? _d : null;
|
|
12
|
+
var variantId = (_e = anyParams.variant_id) !== null && _e !== void 0 ? _e : null;
|
|
13
|
+
var query = (_h = (_g = (_f = anyParams.original_search_query) !== null && _f !== void 0 ? _f : anyParams.serp) !== null && _g !== void 0 ? _g : anyParams.original_smart_navigation) !== null && _h !== void 0 ? _h : null;
|
|
13
14
|
if (!id) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
17
|
+
var compositeKey = variantId ? "".concat(id, "::").concat(variantId) : String(id);
|
|
16
18
|
var now = parseInt(String(Date.now() / 1000), 10); // sec since 1970...
|
|
17
|
-
var products = JSON.parse((
|
|
19
|
+
var products = JSON.parse((_j = localStorage.getItem(RELATED_KEY)) !== null && _j !== void 0 ? _j : '[]');
|
|
18
20
|
var newProducts = [];
|
|
19
|
-
var
|
|
20
|
-
newProducts.push([
|
|
21
|
-
|
|
21
|
+
var keys = new Set();
|
|
22
|
+
newProducts.push([compositeKey, now, query]);
|
|
23
|
+
keys.add(compositeKey);
|
|
22
24
|
for (var i = 0; i < products.length && newProducts.length < config_1.RECENT_PRODUCTS_LENGTH_LIMIT; i++) {
|
|
23
|
-
|
|
25
|
+
var existingKey = String(products[i][0]);
|
|
26
|
+
if (!keys.has(existingKey) && (now - products[i][1]) <= config_1.RECENT_PRODUCTS_EXPIRY_DAYS * 24 * 60 * 60) {
|
|
24
27
|
newProducts.push(products[i]);
|
|
25
|
-
|
|
28
|
+
keys.add(existingKey);
|
|
26
29
|
}
|
|
27
30
|
}
|
|
28
31
|
localStorage.setItem(RELATED_KEY, JSON.stringify(newProducts));
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
|
-
* Parses the stored
|
|
34
|
+
* Parses the stored "recent products" array from localStorage,
|
|
32
35
|
* filters out items older than RECENT_PRODUCTS_EXPIRY_DAYS days,
|
|
33
36
|
* sorts by timestamp (oldest → newest), and returns up to the
|
|
34
37
|
* last RECENT_PRODUCTS_LENGTH_LIMIT entries.
|
|
@@ -56,25 +59,30 @@ function parseRecentProducts() {
|
|
|
56
59
|
return [];
|
|
57
60
|
}
|
|
58
61
|
}
|
|
62
|
+
function extractProductId(key) {
|
|
63
|
+
var str = String(key);
|
|
64
|
+
var idx = str.indexOf('::');
|
|
65
|
+
return idx !== -1 ? str.substring(0, idx) : str;
|
|
66
|
+
}
|
|
59
67
|
/**
|
|
60
|
-
* Fetches recent product as list of product id.
|
|
68
|
+
* Fetches recent product as list of product id (stripped of variant suffix).
|
|
61
69
|
* @returns {string[]} A list of product IDs.
|
|
62
70
|
*/
|
|
63
71
|
function getRecentProducts() {
|
|
64
72
|
var recentProducts = parseRecentProducts().map(function (_a) {
|
|
65
73
|
var id = _a[0];
|
|
66
|
-
return id;
|
|
74
|
+
return extractProductId(id);
|
|
67
75
|
});
|
|
68
76
|
return Array.from(new Set(recentProducts));
|
|
69
77
|
}
|
|
70
78
|
/**
|
|
71
|
-
* Fetches recent product as a record of id and timestamp.
|
|
79
|
+
* Fetches recent product as a record of id and timestamp (keys stripped of variant suffix).
|
|
72
80
|
* @returns {Record<string, number>} A map of product IDs to their timestamps.
|
|
73
81
|
*/
|
|
74
82
|
function getRecentProductsTimestamps() {
|
|
75
83
|
return parseRecentProducts().reduce(function (acc, _a) {
|
|
76
84
|
var id = _a[0], timestamp = _a[1];
|
|
77
|
-
acc[id] = timestamp;
|
|
85
|
+
acc[extractProductId(id)] = timestamp;
|
|
78
86
|
return acc;
|
|
79
87
|
}, {});
|
|
80
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateRecentSearches.js","sourceRoot":"","sources":["../../src/utils/updateRecentSearches.ts"],"names":[],"mappings":";;AAMA,
|
|
1
|
+
{"version":3,"file":"updateRecentSearches.js","sourceRoot":"","sources":["../../src/utils/updateRecentSearches.ts"],"names":[],"mappings":";;AAMA,uCA2BC;AAuCD,8CAGC;AAMD,kEAKC;AAtFD,oCAA2G;AAE3G,IAAM,WAAW,GAAG,+BAA+B,CAAC;AAIpD,SAAwB,oBAAoB,CAAC,MAAc;;IACvD,IAAM,SAAS,GAAI,MAAc,CAAC;IAElC,IAAM,EAAE,GAAG,MAAA,MAAA,MAAA,MAAA,SAAS,CAAC,EAAE,mCAAI,SAAS,CAAC,UAAU,mCAAI,SAAS,CAAC,GAAG,mCAAI,SAAS,CAAC,YAAY,mCAAI,IAAI,CAAC;IACnG,IAAM,SAAS,GAAG,MAAA,SAAS,CAAC,UAAU,mCAAI,IAAI,CAAC;IAC/C,IAAM,KAAK,GAAG,MAAA,MAAA,MAAA,SAAS,CAAC,qBAAqB,mCAAI,SAAS,CAAC,IAAI,mCAAI,SAAS,CAAC,yBAAyB,mCAAI,IAAI,CAAC;IAE/G,IAAI,CAAC,EAAE,EAAE,CAAC;QACN,OAAO;IACX,CAAC;IAED,IAAM,YAAY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