oneentry 1.0.149 → 1.0.150
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/README.md +8 -0
- package/changelog.md +431 -0
- package/dist/base/asyncModules.js +13 -0
- package/dist/base/stateModule.d.ts +1 -0
- package/dist/base/stateModule.js +3 -0
- package/dist/base/syncModules.d.ts +30 -1
- package/dist/base/syncModules.js +102 -30
- package/dist/base/utils.d.ts +4 -1
- package/dist/blocks/blocksApi.d.ts +108 -2
- package/dist/blocks/blocksApi.js +148 -1
- package/dist/blocks/blocksInterfaces.d.ts +160 -2
- package/dist/blocks/blocksSchemas.d.ts +4 -0
- package/dist/events/eventsApi.d.ts +42 -1
- package/dist/events/eventsApi.js +67 -0
- package/dist/events/eventsInterfaces.d.ts +79 -1
- package/dist/filters/filtersApi.d.ts +31 -0
- package/dist/filters/filtersApi.js +40 -0
- package/dist/filters/filtersInterfaces.d.ts +56 -0
- package/dist/filters/filtersInterfaces.js +2 -0
- package/dist/filters/filtersSchemas.d.ts +32 -0
- package/dist/filters/filtersSchemas.js +29 -0
- package/dist/general-types/generalTypesSchemas.d.ts +16 -0
- package/dist/general-types/generalTypesSchemas.js +10 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.js +10 -0
- package/dist/pages/pagesInterfaces.d.ts +2 -2
- package/dist/pages/pagesSchemas.d.ts +3 -3
- package/dist/pages/pagesSchemas.js +1 -1
- package/dist/products/productsApi.d.ts +19 -1
- package/dist/products/productsApi.js +29 -7
- package/dist/products/productsInterfaces.d.ts +30 -1
- package/dist/products/productsSchemas.d.ts +4 -0
- package/dist/products/productsSchemas.js +1 -0
- package/dist/subscriptions/subscriptionsApi.d.ts +69 -0
- package/dist/subscriptions/subscriptionsApi.js +102 -0
- package/dist/subscriptions/subscriptionsInterfaces.d.ts +90 -0
- package/dist/subscriptions/subscriptionsInterfaces.js +2 -0
- package/dist/subscriptions/subscriptionsSchemas.d.ts +20 -0
- package/dist/subscriptions/subscriptionsSchemas.js +23 -0
- package/dist/user-activity/userActivityApi.d.ts +30 -0
- package/dist/user-activity/userActivityApi.js +42 -0
- package/dist/user-activity/userActivityInterfaces.d.ts +42 -0
- package/dist/user-activity/userActivityInterfaces.js +2 -0
- package/dist/users/usersApi.d.ts +79 -1
- package/dist/users/usersApi.js +110 -0
- package/dist/users/usersInterfaces.d.ts +155 -1
- package/dist/users/usersSchemas.d.ts +40 -0
- package/dist/users/usersSchemas.js +34 -1
- package/package.json +3 -2
package/dist/base/syncModules.js
CHANGED
|
@@ -1,52 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
// localStorage keys for the persistent browser-side identifiers.
|
|
4
|
+
const _DEVICE_ID_STORAGE_KEY = 'oneentry_device_id';
|
|
5
|
+
const _GUEST_ID_STORAGE_KEY = 'oneentry_guest_id';
|
|
6
|
+
// Module-level cache of persistent IDs keyed by storage key — survives class
|
|
7
|
+
// re-instantiation, but resets on page reload if localStorage is unavailable.
|
|
8
|
+
const _persistentIds = {};
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
10
|
+
* Generates a new opaque identifier.
|
|
8
11
|
*
|
|
9
|
-
*
|
|
12
|
+
* Prefers a cryptographically secure source (Web Crypto, exposed as
|
|
13
|
+
* `globalThis.crypto` in browsers and Node.js >= 18): `randomUUID()` when
|
|
14
|
+
* available, otherwise random bytes rendered as a base-36 string. Falls back to
|
|
15
|
+
* a timestamp + `Math.random()` only when no CSPRNG exists (e.g. very old Node).
|
|
16
|
+
*
|
|
17
|
+
* The result contains no special characters, so it is safe to use both in
|
|
18
|
+
* localStorage and in HTTP headers.
|
|
19
|
+
* @returns {string} A freshly generated identifier.
|
|
20
|
+
*/
|
|
21
|
+
function _generateId() {
|
|
22
|
+
const cryptoObj = typeof globalThis !== 'undefined' ? globalThis.crypto : undefined;
|
|
23
|
+
if (cryptoObj === null || cryptoObj === void 0 ? void 0 : cryptoObj.randomUUID) {
|
|
24
|
+
return cryptoObj.randomUUID();
|
|
25
|
+
}
|
|
26
|
+
if (cryptoObj === null || cryptoObj === void 0 ? void 0 : cryptoObj.getRandomValues) {
|
|
27
|
+
const bytes = cryptoObj.getRandomValues(new Uint8Array(18));
|
|
28
|
+
let result = '';
|
|
29
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
30
|
+
result += bytes[i].toString(36).padStart(2, '0');
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
// Last-resort fallback for environments without Web Crypto.
|
|
35
|
+
// Non-cryptographic, but adequate when nothing better is available.
|
|
36
|
+
return (Date.now().toString(36) +
|
|
37
|
+
Math.random().toString(36).substring(2, 15) +
|
|
38
|
+
Math.random().toString(36).substring(2, 15));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns a stable identifier for the browser environment, persisted in localStorage.
|
|
42
|
+
*
|
|
43
|
+
* Algorithm (per `storageKey`):
|
|
10
44
|
* 1. If the module-level cache is already populated — return it (fastest path).
|
|
11
|
-
* 2. Otherwise try reading the ID from localStorage
|
|
45
|
+
* 2. Otherwise try reading the ID from localStorage under `storageKey`.
|
|
12
46
|
* This ensures the same browser gets the same ID across sessions and tabs.
|
|
13
|
-
* 3. If localStorage has nothing — generate a new ID
|
|
14
|
-
*
|
|
47
|
+
* 3. If localStorage has nothing — generate a new ID, persist it to localStorage
|
|
48
|
+
* and cache it in the module variable.
|
|
15
49
|
* 4. If localStorage is unavailable (SSR, private mode, iframe sandbox) —
|
|
16
|
-
* return null; the caller falls back to
|
|
17
|
-
* @
|
|
50
|
+
* return null; the caller falls back to a per-instance Node id.
|
|
51
|
+
* @param {string} storageKey - localStorage key under which the ID is stored.
|
|
52
|
+
* @returns {string | null} The identifier or null if localStorage is unavailable.
|
|
18
53
|
*/
|
|
19
|
-
function
|
|
54
|
+
function _getPersistentBrowserId(storageKey) {
|
|
20
55
|
const win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
|
|
21
56
|
if (!(win === null || win === void 0 ? void 0 : win.localStorage))
|
|
22
57
|
return null;
|
|
23
|
-
if (
|
|
24
|
-
return
|
|
58
|
+
if (_persistentIds[storageKey])
|
|
59
|
+
return _persistentIds[storageKey];
|
|
25
60
|
try {
|
|
26
|
-
const stored = win.localStorage.getItem(
|
|
61
|
+
const stored = win.localStorage.getItem(storageKey);
|
|
27
62
|
if (stored) {
|
|
28
|
-
|
|
29
|
-
return
|
|
63
|
+
_persistentIds[storageKey] = stored;
|
|
64
|
+
return _persistentIds[storageKey];
|
|
30
65
|
}
|
|
31
66
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32
67
|
}
|
|
33
68
|
catch (_e) {
|
|
34
69
|
// ignore
|
|
35
70
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const id = Date.now().toString(36) +
|
|
39
|
-
Math.random().toString(36).substring(2, 15) +
|
|
40
|
-
Math.random().toString(36).substring(2, 15);
|
|
41
|
-
_persistentDeviceId = id;
|
|
71
|
+
const id = _generateId();
|
|
72
|
+
_persistentIds[storageKey] = id;
|
|
42
73
|
try {
|
|
43
|
-
win.localStorage.setItem(
|
|
74
|
+
win.localStorage.setItem(storageKey, id);
|
|
44
75
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
76
|
}
|
|
46
77
|
catch (_e) {
|
|
47
78
|
// ignore
|
|
48
79
|
}
|
|
49
|
-
return
|
|
80
|
+
return _persistentIds[storageKey];
|
|
50
81
|
}
|
|
51
82
|
/**
|
|
52
83
|
* Abstract class representing synchronization modules.
|
|
@@ -70,10 +101,37 @@ class SyncModules {
|
|
|
70
101
|
this._sortAttributes = (data) => Object.fromEntries(Object.entries(data).sort(([, a], [, b]) => a.position - b.position));
|
|
71
102
|
this.state = state;
|
|
72
103
|
this._url = state.url;
|
|
73
|
-
this._nodeDeviceId =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
104
|
+
this._nodeDeviceId = _generateId();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Resolves the guest identifier for the current request, or `undefined`.
|
|
108
|
+
*
|
|
109
|
+
* Resolution order:
|
|
110
|
+
* 1. An explicitly configured `state.guestId` (from config or `setGuestId`) — wins.
|
|
111
|
+
* 2. A persistent browser ID stored in localStorage (key `oneentry_guest_id`),
|
|
112
|
+
* stable across sessions and tabs — mirrors the device-metadata strategy.
|
|
113
|
+
* Once resolved it is cached into `state.guestId` (safe: one browser = one user).
|
|
114
|
+
* 3. Otherwise `undefined` — the `x-guest-id` header is simply omitted.
|
|
115
|
+
*
|
|
116
|
+
* IMPORTANT (server-side): the SDK never invents a guest id on the server.
|
|
117
|
+
* `defineOneEntry` is typically created once and shared across many visitors,
|
|
118
|
+
* so a silently-generated server id would be cached into the shared state and
|
|
119
|
+
* leak one guest cart/wishlist across all anonymous visitors. On the server
|
|
120
|
+
* you must pass a per-visitor `guestId` (config or `setGuestId`) yourself.
|
|
121
|
+
* @returns {string | undefined} The guest identifier, or undefined when none is available.
|
|
122
|
+
*/
|
|
123
|
+
_getGuestId() {
|
|
124
|
+
if (this.state.guestId)
|
|
125
|
+
return this.state.guestId;
|
|
126
|
+
// Browser only: a localStorage-backed id is safe to cache into shared state,
|
|
127
|
+
// because a single browser maps to a single guest.
|
|
128
|
+
const browserId = _getPersistentBrowserId(_GUEST_ID_STORAGE_KEY);
|
|
129
|
+
if (browserId) {
|
|
130
|
+
this.state.guestId = browserId;
|
|
131
|
+
return browserId;
|
|
132
|
+
}
|
|
133
|
+
// No localStorage and no explicit id (e.g. Node/SSR) — do not invent one.
|
|
134
|
+
return undefined;
|
|
77
135
|
}
|
|
78
136
|
/**
|
|
79
137
|
* Constructs the full URL path by appending the given path to the base URL.
|
|
@@ -622,6 +680,20 @@ class SyncModules {
|
|
|
622
680
|
this.state.refreshToken = refreshToken;
|
|
623
681
|
return this;
|
|
624
682
|
}
|
|
683
|
+
/**
|
|
684
|
+
* Sets the guest identifier in the state.
|
|
685
|
+
*
|
|
686
|
+
* Once set, it is sent as the `x-guest-id` header on unauthenticated requests,
|
|
687
|
+
* enabling guest cart/wishlist/activity flows. Pass an empty string to clear it
|
|
688
|
+
* (the SDK then falls back to the localStorage-backed id in the browser, or to
|
|
689
|
+
* no guest id at all on the server).
|
|
690
|
+
* @param {string} guestId - The guest identifier to set (empty string clears it).
|
|
691
|
+
* @returns {any} The instance of SyncModules for chaining.
|
|
692
|
+
*/
|
|
693
|
+
setGuestId(guestId) {
|
|
694
|
+
this.state.guestId = guestId || undefined;
|
|
695
|
+
return this;
|
|
696
|
+
}
|
|
625
697
|
/**
|
|
626
698
|
* Get deviceMetadata
|
|
627
699
|
*
|
|
@@ -643,7 +715,7 @@ class SyncModules {
|
|
|
643
715
|
* 3. Concatenates the hash and the first 12 characters of instanceId.
|
|
644
716
|
*
|
|
645
717
|
* **instanceId strategy:**
|
|
646
|
-
* - Browser: `
|
|
718
|
+
* - Browser: `_getPersistentBrowserId('oneentry_device_id')` — read from localStorage, stable across sessions.
|
|
647
719
|
* - Node.js / no localStorage: `_nodeDeviceId` — generated at instance creation,
|
|
648
720
|
* lives until the process restarts.
|
|
649
721
|
*
|
|
@@ -658,7 +730,7 @@ class SyncModules {
|
|
|
658
730
|
}
|
|
659
731
|
// Access navigator through globalThis.window object to avoid direct reference
|
|
660
732
|
const win = globalThis.window;
|
|
661
|
-
const instanceId = (_a =
|
|
733
|
+
const instanceId = (_a = _getPersistentBrowserId(_DEVICE_ID_STORAGE_KEY)) !== null && _a !== void 0 ? _a : this._nodeDeviceId;
|
|
662
734
|
// Node.js environment
|
|
663
735
|
if (!win) {
|
|
664
736
|
return JSON.stringify({
|
package/dist/base/utils.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @interface IConfig
|
|
3
3
|
* @property {string} [token] - If your project is protected by a token, specify this token in this parameter.
|
|
4
|
+
* @property {string} [guestId] - Guest identifier sent as the `x-guest-id` header on unauthenticated requests. Lets cart/wishlist/activity endpoints work for a guest. In the browser a stable id is auto-generated (localStorage) when omitted; on the server pass a per-visitor id. Can also be set later via `setGuestId`.
|
|
4
5
|
* @property {string} [langCode] - specify the default language to avoid specifying it in every request.
|
|
5
6
|
* @property {boolean} [traficLimit] - Some methods use multiple queries to make it easier to work with the API. Set this parameter to "false" to save traffic and decide for yourself what data you need.
|
|
6
7
|
* @property {boolean} [rawData] - Set to true to receive raw API responses without any transformation.
|
|
@@ -42,6 +43,7 @@
|
|
|
42
43
|
*/
|
|
43
44
|
interface IConfig {
|
|
44
45
|
token?: string;
|
|
46
|
+
guestId?: string;
|
|
45
47
|
langCode?: string;
|
|
46
48
|
traficLimit?: boolean;
|
|
47
49
|
rawData?: boolean;
|
|
@@ -255,12 +257,13 @@ interface IError {
|
|
|
255
257
|
/**
|
|
256
258
|
* @interface IHttpHeaders
|
|
257
259
|
* @property {string} [Authorization] - Authorization header.
|
|
258
|
-
* @description Interface for HTTP headers. Supports the standard `Content-Type`, `Authorization`, and OneEntry-specific `x-app-token` / `x-device-metadata` headers, plus arbitrary string entries via the index signature.
|
|
260
|
+
* @description Interface for HTTP headers. Supports the standard `Content-Type`, `Authorization`, and OneEntry-specific `x-app-token` / `x-device-metadata` / `x-guest-id` (guest cart/wishlist/activity) headers, plus arbitrary string entries via the index signature.
|
|
259
261
|
*/
|
|
260
262
|
interface IHttpHeaders {
|
|
261
263
|
'Content-Type'?: string;
|
|
262
264
|
'x-app-token'?: string;
|
|
263
265
|
'x-device-metadata'?: string;
|
|
266
|
+
'x-guest-id'?: string;
|
|
264
267
|
Authorization?: string;
|
|
265
268
|
[key: string]: string | undefined;
|
|
266
269
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import AsyncModules from '../base/asyncModules';
|
|
2
2
|
import type StateModule from '../base/stateModule';
|
|
3
3
|
import type { IError } from '../base/utils';
|
|
4
|
-
import type { IProductsResponse } from '../products/productsInterfaces';
|
|
5
|
-
import type { BlockType, IBlockEntity, IBlocks, IBlocksResponse, ISearchBlock } from './blocksInterfaces';
|
|
4
|
+
import type { IProductsEntity, IProductsResponse } from '../products/productsInterfaces';
|
|
5
|
+
import type { BlockType, IBlockEntity, IBlockProductsLookup, IBlocks, IBlockSlidesResponse, IBlocksResponse, ISearchBlock } from './blocksInterfaces';
|
|
6
6
|
/**
|
|
7
7
|
* Controllers for working with blocks.
|
|
8
8
|
* @handle /api/content/blocks
|
|
@@ -49,6 +49,7 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
49
49
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
50
50
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
51
51
|
* @param {string} [signPrice] - Sign price.
|
|
52
|
+
* @param {number} [productId] - Optional product id to find similar products for.
|
|
52
53
|
* @returns {Promise<IProductsResponse | IError>} - Returns the total count and an array of product items in object by specified block marker.
|
|
53
54
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
54
55
|
*/
|
|
@@ -85,4 +86,109 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
|
|
|
85
86
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
86
87
|
*/
|
|
87
88
|
searchBlock(name: string, langCode?: string): Promise<ISearchBlock[] | IError>;
|
|
89
|
+
/**
|
|
90
|
+
* Get "complete your cart" products by the cart from context (auth user or guest).
|
|
91
|
+
* @handleName getCartComplement
|
|
92
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
93
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
94
|
+
* @param {string} [signPrice] - Sign price.
|
|
95
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
96
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
97
|
+
*/
|
|
98
|
+
getCartComplement(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
|
|
99
|
+
/**
|
|
100
|
+
* Get "complete your cart" products by an explicit list of productIds (POST body).
|
|
101
|
+
* @handleName getCartComplementByProductIds
|
|
102
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
103
|
+
* @param {IBlockProductsLookup} body - Lookup body. Example: `{ productIds: [1, 2], langCode: "en_US" }`.
|
|
104
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
105
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
106
|
+
*/
|
|
107
|
+
getCartComplementByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsEntity[] | IError>;
|
|
108
|
+
/**
|
|
109
|
+
* Get "similar to cart" products by the cart from context (auth user or guest).
|
|
110
|
+
* @handleName getCartSimilar
|
|
111
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
112
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
113
|
+
* @param {string} [signPrice] - Sign price.
|
|
114
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
115
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
116
|
+
*/
|
|
117
|
+
getCartSimilar(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
|
|
118
|
+
/**
|
|
119
|
+
* Get "similar to cart" products by an explicit list of productIds (POST body).
|
|
120
|
+
* @handleName getCartSimilarByProductIds
|
|
121
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
122
|
+
* @param {IBlockProductsLookup} body - Lookup body. Example: `{ productIds: [1, 2], langCode: "en_US" }`.
|
|
123
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
124
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
125
|
+
*/
|
|
126
|
+
getCartSimilarByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsEntity[] | IError>;
|
|
127
|
+
/**
|
|
128
|
+
* Get personal recommendations for the user.
|
|
129
|
+
* @handleName getPersonalRecommendations
|
|
130
|
+
* @param {string} marker - Block marker. Example: "personal_recommendations_block".
|
|
131
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
132
|
+
* @param {string} [signPrice] - Sign price.
|
|
133
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
134
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
135
|
+
*/
|
|
136
|
+
getPersonalRecommendations(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
|
|
137
|
+
/**
|
|
138
|
+
* Get recently viewed products.
|
|
139
|
+
* @handleName getRecentlyViewed
|
|
140
|
+
* @param {string} marker - Block marker. Example: "recently_viewed_block".
|
|
141
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
142
|
+
* @param {string} [signPrice] - Sign price.
|
|
143
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
144
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
145
|
+
*/
|
|
146
|
+
getRecentlyViewed(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
|
|
147
|
+
/**
|
|
148
|
+
* Get products for repeat purchase.
|
|
149
|
+
* @handleName getRepeatPurchase
|
|
150
|
+
* @param {string} marker - Block marker. Example: "repeat_purchase_block".
|
|
151
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
152
|
+
* @param {string} [signPrice] - Sign price.
|
|
153
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
154
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
155
|
+
*/
|
|
156
|
+
getRepeatPurchase(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
|
|
157
|
+
/**
|
|
158
|
+
* Get the block's slides tree as a flat pre-order array (slider_block only).
|
|
159
|
+
* @handleName getSlides
|
|
160
|
+
* @param {string} marker - Block marker. Example: "slider_block".
|
|
161
|
+
* @returns {Promise<IBlockSlidesResponse | IError>} Returns the slides response.
|
|
162
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
163
|
+
*/
|
|
164
|
+
getSlides(marker: string): Promise<IBlockSlidesResponse | IError>;
|
|
165
|
+
/**
|
|
166
|
+
* Get trending products of the block.
|
|
167
|
+
* @handleName getTrending
|
|
168
|
+
* @param {string} marker - Block marker. Example: "trending_block".
|
|
169
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
170
|
+
* @param {string} [signPrice] - Sign price.
|
|
171
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
172
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
173
|
+
*/
|
|
174
|
+
getTrending(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
|
|
175
|
+
/**
|
|
176
|
+
* Get "similar to wishlist" products by the wishlist from context (auth user or guest).
|
|
177
|
+
* @handleName getWishlistSimilar
|
|
178
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
179
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
180
|
+
* @param {string} [signPrice] - Sign price.
|
|
181
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
182
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
183
|
+
*/
|
|
184
|
+
getWishlistSimilar(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
|
|
185
|
+
/**
|
|
186
|
+
* Get "similar to wishlist" products by an explicit list of productIds (POST body).
|
|
187
|
+
* @handleName getWishlistSimilarByProductIds
|
|
188
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
189
|
+
* @param {IBlockProductsLookup} body - Lookup body. Example: `{ productIds: [1, 2], langCode: "en_US" }`.
|
|
190
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
191
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
192
|
+
*/
|
|
193
|
+
getWishlistSimilarByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsEntity[] | IError>;
|
|
88
194
|
}
|
package/dist/blocks/blocksApi.js
CHANGED
|
@@ -136,15 +136,17 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
136
136
|
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
137
137
|
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
138
138
|
* @param {string} [signPrice] - Sign price.
|
|
139
|
+
* @param {number} [productId] - Optional product id to find similar products for.
|
|
139
140
|
* @returns {Promise<IProductsResponse | IError>} - Returns the total count and an array of product items in object by specified block marker.
|
|
140
141
|
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
141
142
|
*/
|
|
142
|
-
async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice) {
|
|
143
|
+
async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice, productId) {
|
|
143
144
|
const query = {
|
|
144
145
|
langCode,
|
|
145
146
|
offset,
|
|
146
147
|
limit,
|
|
147
148
|
signPrice,
|
|
149
|
+
productId,
|
|
148
150
|
};
|
|
149
151
|
const result = await this._fetchGet(`/${marker}/similar-products?` + this._queryParamsToString(query));
|
|
150
152
|
return this._normalizeData(result);
|
|
@@ -203,5 +205,150 @@ class BlocksApi extends asyncModules_1.default {
|
|
|
203
205
|
const validated = this._validateResponse(result, blocksSchemas_1.SearchBlocksResponseSchema);
|
|
204
206
|
return validated;
|
|
205
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Get "complete your cart" products by the cart from context (auth user or guest).
|
|
210
|
+
* @handleName getCartComplement
|
|
211
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
212
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
213
|
+
* @param {string} [signPrice] - Sign price.
|
|
214
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
215
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
216
|
+
*/
|
|
217
|
+
async getCartComplement(marker, langCode = this.state.lang, signPrice) {
|
|
218
|
+
const query = { langCode, signPrice };
|
|
219
|
+
const data = await this._fetchGet(`/${marker}/cart-complement?` + this._queryParamsToString(query));
|
|
220
|
+
return this._normalizeData(data);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Get "complete your cart" products by an explicit list of productIds (POST body).
|
|
224
|
+
* @handleName getCartComplementByProductIds
|
|
225
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
226
|
+
* @param {IBlockProductsLookup} body - Lookup body. Example: `{ productIds: [1, 2], langCode: "en_US" }`.
|
|
227
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
228
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
229
|
+
*/
|
|
230
|
+
async getCartComplementByProductIds(marker, body) {
|
|
231
|
+
const data = await this._fetchPost(`/${marker}/cart-complement`, { langCode: this.state.lang, ...body });
|
|
232
|
+
return this._normalizeData(data);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Get "similar to cart" products by the cart from context (auth user or guest).
|
|
236
|
+
* @handleName getCartSimilar
|
|
237
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
238
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
239
|
+
* @param {string} [signPrice] - Sign price.
|
|
240
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
241
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
242
|
+
*/
|
|
243
|
+
async getCartSimilar(marker, langCode = this.state.lang, signPrice) {
|
|
244
|
+
const query = { langCode, signPrice };
|
|
245
|
+
const data = await this._fetchGet(`/${marker}/cart-similar?` + this._queryParamsToString(query));
|
|
246
|
+
return this._normalizeData(data);
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get "similar to cart" products by an explicit list of productIds (POST body).
|
|
250
|
+
* @handleName getCartSimilarByProductIds
|
|
251
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
252
|
+
* @param {IBlockProductsLookup} body - Lookup body. Example: `{ productIds: [1, 2], langCode: "en_US" }`.
|
|
253
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
254
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
255
|
+
*/
|
|
256
|
+
async getCartSimilarByProductIds(marker, body) {
|
|
257
|
+
const data = await this._fetchPost(`/${marker}/cart-similar`, { langCode: this.state.lang, ...body });
|
|
258
|
+
return this._normalizeData(data);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Get personal recommendations for the user.
|
|
262
|
+
* @handleName getPersonalRecommendations
|
|
263
|
+
* @param {string} marker - Block marker. Example: "personal_recommendations_block".
|
|
264
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
265
|
+
* @param {string} [signPrice] - Sign price.
|
|
266
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
267
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
268
|
+
*/
|
|
269
|
+
async getPersonalRecommendations(marker, langCode = this.state.lang, signPrice) {
|
|
270
|
+
const query = { langCode, signPrice };
|
|
271
|
+
const data = await this._fetchGet(`/${marker}/personal-recommendations?` + this._queryParamsToString(query));
|
|
272
|
+
return this._normalizeData(data);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Get recently viewed products.
|
|
276
|
+
* @handleName getRecentlyViewed
|
|
277
|
+
* @param {string} marker - Block marker. Example: "recently_viewed_block".
|
|
278
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
279
|
+
* @param {string} [signPrice] - Sign price.
|
|
280
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
281
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
282
|
+
*/
|
|
283
|
+
async getRecentlyViewed(marker, langCode = this.state.lang, signPrice) {
|
|
284
|
+
const query = { langCode, signPrice };
|
|
285
|
+
const data = await this._fetchGet(`/${marker}/recently-viewed?` + this._queryParamsToString(query));
|
|
286
|
+
return this._normalizeData(data);
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Get products for repeat purchase.
|
|
290
|
+
* @handleName getRepeatPurchase
|
|
291
|
+
* @param {string} marker - Block marker. Example: "repeat_purchase_block".
|
|
292
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
293
|
+
* @param {string} [signPrice] - Sign price.
|
|
294
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
295
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
296
|
+
*/
|
|
297
|
+
async getRepeatPurchase(marker, langCode = this.state.lang, signPrice) {
|
|
298
|
+
const query = { langCode, signPrice };
|
|
299
|
+
const data = await this._fetchGet(`/${marker}/repeat-purchase?` + this._queryParamsToString(query));
|
|
300
|
+
return this._normalizeData(data);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Get the block's slides tree as a flat pre-order array (slider_block only).
|
|
304
|
+
* @handleName getSlides
|
|
305
|
+
* @param {string} marker - Block marker. Example: "slider_block".
|
|
306
|
+
* @returns {Promise<IBlockSlidesResponse | IError>} Returns the slides response.
|
|
307
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
308
|
+
*/
|
|
309
|
+
async getSlides(marker) {
|
|
310
|
+
const data = await this._fetchGet(`/${marker}/slides`);
|
|
311
|
+
return this._normalizeData(data);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get trending products of the block.
|
|
315
|
+
* @handleName getTrending
|
|
316
|
+
* @param {string} marker - Block marker. Example: "trending_block".
|
|
317
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
318
|
+
* @param {string} [signPrice] - Sign price.
|
|
319
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
320
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
321
|
+
*/
|
|
322
|
+
async getTrending(marker, langCode = this.state.lang, signPrice) {
|
|
323
|
+
const query = { langCode, signPrice };
|
|
324
|
+
const data = await this._fetchGet(`/${marker}/trending?` + this._queryParamsToString(query));
|
|
325
|
+
return this._normalizeData(data);
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get "similar to wishlist" products by the wishlist from context (auth user or guest).
|
|
329
|
+
* @handleName getWishlistSimilar
|
|
330
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
331
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
332
|
+
* @param {string} [signPrice] - Sign price.
|
|
333
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
334
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
335
|
+
*/
|
|
336
|
+
async getWishlistSimilar(marker, langCode = this.state.lang, signPrice) {
|
|
337
|
+
const query = { langCode, signPrice };
|
|
338
|
+
const data = await this._fetchGet(`/${marker}/wishlist-similar?` + this._queryParamsToString(query));
|
|
339
|
+
return this._normalizeData(data);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Get "similar to wishlist" products by an explicit list of productIds (POST body).
|
|
343
|
+
* @handleName getWishlistSimilarByProductIds
|
|
344
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
345
|
+
* @param {IBlockProductsLookup} body - Lookup body. Example: `{ productIds: [1, 2], langCode: "en_US" }`.
|
|
346
|
+
* @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
|
|
347
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
348
|
+
*/
|
|
349
|
+
async getWishlistSimilarByProductIds(marker, body) {
|
|
350
|
+
const data = await this._fetchPost(`/${marker}/wishlist-similar`, { langCode: this.state.lang, ...body });
|
|
351
|
+
return this._normalizeData(data);
|
|
352
|
+
}
|
|
206
353
|
}
|
|
207
354
|
exports.default = BlocksApi;
|