Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@klevu/core

Package Overview
Dependencies
Maintainers
3
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@klevu/core - npm Package Compare versions

Comparing version
5.2.1
to
5.2.2
+2
-0
dist/cjs/store/lastClickedProducts.d.ts
import { KlevuRecord } from "../models/KlevuRecord.js";
export declare const LAST_CLICKED_STORAGE_KEY = "klevu-last-clicks";
export declare const LAST_CLICKED_CATEGORY_STORAGE_KEY = "klevu-last-clicks-cat";
/**

@@ -10,2 +11,3 @@ * Keeps track of last clicked products in store

private save;
private saveCat;
private restore;

@@ -12,0 +14,0 @@ constructor();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KlevuLastClickedProducts = exports.LAST_CLICKED_STORAGE_KEY = void 0;
exports.KlevuLastClickedProducts = exports.LAST_CLICKED_CATEGORY_STORAGE_KEY = exports.LAST_CLICKED_STORAGE_KEY = void 0;
const notEmpty_js_1 = require("../utils/notEmpty.js");

@@ -11,2 +11,4 @@ const isBrowser_js_1 = require("../utils/isBrowser.js");

exports.LAST_CLICKED_STORAGE_KEY = "klevu-last-clicks";
exports.LAST_CLICKED_CATEGORY_STORAGE_KEY = "klevu-last-clicks-cat";
const MAX_COUNT = 20;
/**

@@ -24,2 +26,10 @@ * Keeps track of last clicked products in store

}
saveCat() {
if (config_js_1.KlevuConfig.getDefault().disableClickTracking) {
return;
}
if ((0, isBrowser_js_1.isBrowser)() && window.sessionStorage) {
storage_js_1.KlevuStorage.setItem(exports.LAST_CLICKED_CATEGORY_STORAGE_KEY, JSON.stringify(this.categoryCache), storage_js_1.StorageType.SESSION);
}
}
restore() {

@@ -32,2 +42,8 @@ if ((0, isBrowser_js_1.isBrowser)() && window.localStorage) {

}
if ((0, isBrowser_js_1.isBrowser)() && window.sessionStorage) {
const resCat = storage_js_1.KlevuStorage.getItem(exports.LAST_CLICKED_CATEGORY_STORAGE_KEY, storage_js_1.StorageType.SESSION);
if (resCat) {
this.categoryCache = JSON.parse(resCat);
}
}
}

@@ -49,2 +65,6 @@ constructor() {

}
const lastIndex = this.clicks.findIndex((ls) => ls.id === productId);
if (lastIndex > -1) {
this.clicks.splice(lastIndex, 1);
}
this.clicks.push({

@@ -55,2 +75,5 @@ ts: new Date(),

});
if (this.clicks.length > MAX_COUNT) {
this.clicks = this.clicks.slice(MAX_COUNT * -1);
}
this.save();

@@ -129,2 +152,4 @@ if ((0, isBrowser_js_1.isBrowser)()) {

};
storage_js_1.KlevuStorage.addKey(exports.LAST_CLICKED_CATEGORY_STORAGE_KEY);
this.saveCat();
return ids;

@@ -131,0 +156,0 @@ }

import { KlevuRecord } from "../models/KlevuRecord.js";
export declare const LAST_CLICKED_STORAGE_KEY = "klevu-last-clicks";
export declare const LAST_CLICKED_CATEGORY_STORAGE_KEY = "klevu-last-clicks-cat";
/**

@@ -10,2 +11,3 @@ * Keeps track of last clicked products in store

private save;
private saveCat;
private restore;

@@ -12,0 +14,0 @@ constructor();

@@ -5,5 +5,7 @@ import { notEmpty } from "../utils/notEmpty.js";

import { KlevuConfig } from "../config.js";
import { KlevuStorage } from "../utils/storage.js";
import { KlevuStorage, StorageType } from "../utils/storage.js";
const ONE_HOUR = 36000000;
export const LAST_CLICKED_STORAGE_KEY = "klevu-last-clicks";
export const LAST_CLICKED_CATEGORY_STORAGE_KEY = "klevu-last-clicks-cat";
const MAX_COUNT = 20;
/**

@@ -21,2 +23,10 @@ * Keeps track of last clicked products in store

}
saveCat() {
if (KlevuConfig.getDefault().disableClickTracking) {
return;
}
if (isBrowser() && window.sessionStorage) {
KlevuStorage.setItem(LAST_CLICKED_CATEGORY_STORAGE_KEY, JSON.stringify(this.categoryCache), StorageType.SESSION);
}
}
restore() {

@@ -29,2 +39,8 @@ if (isBrowser() && window.localStorage) {

}
if (isBrowser() && window.sessionStorage) {
const resCat = KlevuStorage.getItem(LAST_CLICKED_CATEGORY_STORAGE_KEY, StorageType.SESSION);
if (resCat) {
this.categoryCache = JSON.parse(resCat);
}
}
}

@@ -46,2 +62,6 @@ constructor() {

}
const lastIndex = this.clicks.findIndex((ls) => ls.id === productId);
if (lastIndex > -1) {
this.clicks.splice(lastIndex, 1);
}
this.clicks.push({

@@ -52,2 +72,5 @@ ts: new Date(),

});
if (this.clicks.length > MAX_COUNT) {
this.clicks = this.clicks.slice(MAX_COUNT * -1);
}
this.save();

@@ -126,2 +149,4 @@ if (isBrowser()) {

};
KlevuStorage.addKey(LAST_CLICKED_CATEGORY_STORAGE_KEY);
this.saveCat();
return ids;

@@ -128,0 +153,0 @@ }

+1
-1
{
"name": "@klevu/core",
"sideEffects": false,
"version": "5.2.1",
"version": "5.2.2",
"description": "Typescript SDK that simplifies development on Klevu backend. Klevu provides advanced AI-powered search and discovery solutions for online retailers.",

@@ -6,0 +6,0 @@ "keywords": [

@@ -74,3 +74,3 @@ ![Klevu](../../images/klevu_header.jpg?raw=true "Klevu")

const result = await KlevuFetch(search("hoodies"))
console.log(result.getQueriesById("search")?.records)
console.log(result.queriesById("search")?.records)
```

@@ -105,3 +105,3 @@

// Prints records that are found from the search
console.log(result.getQueriesById("search")?.records)
console.log(result.queriesById("search")?.records)
```

@@ -111,5 +111,5 @@

`KlevuFetch()` result object contains raw API response and handy helpers to get results. Use `getSuggestionsById()` to fetch suggestions results and `getQueriesById()` for search results.
`KlevuFetch()` result object contains raw API response and handy helpers to get results. Use `suggestionsById()` to fetch suggestions results and `queriesById()` for search results.
`getQueriesById()` result contains metadata for query, the result records and possible event functions for providing click events to search, category merchandising and recommendations. It also includes `next()` function. It is a nice helper to fetch the next results set with the same query and modifiers. `next()` is defined only if there are more results available.
`queriesById()` result contains metadata for query, the result records and possible event functions for providing click events to search, category merchandising and recommendations. It also includes `next()` function. It is a nice helper to fetch the next results set with the same query and modifiers. `next()` is defined only if there are more results available.

@@ -116,0 +116,0 @@ Calling event functions returns a function to use to send events to Klevu. [See definition these functions from here](./src/models/KlevuResultEvent.ts)