oneentry 1.0.149 → 1.0.151

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.
Files changed (58) hide show
  1. package/README.md +8 -0
  2. package/changelog.md +453 -0
  3. package/dist/base/asyncModules.js +13 -0
  4. package/dist/base/stateModule.d.ts +1 -0
  5. package/dist/base/stateModule.js +3 -0
  6. package/dist/base/syncModules.d.ts +30 -1
  7. package/dist/base/syncModules.js +102 -30
  8. package/dist/base/utils.d.ts +4 -1
  9. package/dist/blocks/blocksApi.d.ts +124 -3
  10. package/dist/blocks/blocksApi.js +169 -4
  11. package/dist/blocks/blocksInterfaces.d.ts +177 -4
  12. package/dist/blocks/blocksSchemas.d.ts +4 -0
  13. package/dist/events/eventsApi.d.ts +42 -1
  14. package/dist/events/eventsApi.js +67 -0
  15. package/dist/events/eventsInterfaces.d.ts +79 -1
  16. package/dist/file-uploading/fileUploadingInterfaces.d.ts +2 -0
  17. package/dist/file-uploading/fileUploadingSchemas.d.ts +2 -0
  18. package/dist/file-uploading/fileUploadingSchemas.js +1 -0
  19. package/dist/filters/filtersApi.d.ts +31 -0
  20. package/dist/filters/filtersApi.js +40 -0
  21. package/dist/filters/filtersInterfaces.d.ts +56 -0
  22. package/dist/filters/filtersInterfaces.js +2 -0
  23. package/dist/filters/filtersSchemas.d.ts +32 -0
  24. package/dist/filters/filtersSchemas.js +29 -0
  25. package/dist/forms-data/formsDataInterfaces.d.ts +2 -2
  26. package/dist/forms-data/formsDataSchemas.d.ts +1 -1
  27. package/dist/forms-data/formsDataSchemas.js +1 -1
  28. package/dist/general-types/generalTypesSchemas.d.ts +16 -0
  29. package/dist/general-types/generalTypesSchemas.js +10 -1
  30. package/dist/index.d.ts +13 -0
  31. package/dist/index.js +10 -0
  32. package/dist/orders/ordersInterfaces.d.ts +51 -3
  33. package/dist/orders/ordersSchemas.d.ts +127 -31
  34. package/dist/orders/ordersSchemas.js +53 -30
  35. package/dist/pages/pagesInterfaces.d.ts +14 -8
  36. package/dist/pages/pagesSchemas.d.ts +24 -9
  37. package/dist/pages/pagesSchemas.js +4 -3
  38. package/dist/products/productsApi.d.ts +19 -1
  39. package/dist/products/productsApi.js +42 -8
  40. package/dist/products/productsInterfaces.d.ts +35 -6
  41. package/dist/products/productsSchemas.d.ts +4 -0
  42. package/dist/products/productsSchemas.js +1 -0
  43. package/dist/subscriptions/subscriptionsApi.d.ts +69 -0
  44. package/dist/subscriptions/subscriptionsApi.js +102 -0
  45. package/dist/subscriptions/subscriptionsInterfaces.d.ts +90 -0
  46. package/dist/subscriptions/subscriptionsInterfaces.js +2 -0
  47. package/dist/subscriptions/subscriptionsSchemas.d.ts +20 -0
  48. package/dist/subscriptions/subscriptionsSchemas.js +23 -0
  49. package/dist/user-activity/userActivityApi.d.ts +30 -0
  50. package/dist/user-activity/userActivityApi.js +42 -0
  51. package/dist/user-activity/userActivityInterfaces.d.ts +42 -0
  52. package/dist/user-activity/userActivityInterfaces.js +2 -0
  53. package/dist/users/usersApi.d.ts +79 -1
  54. package/dist/users/usersApi.js +110 -0
  55. package/dist/users/usersInterfaces.d.ts +155 -1
  56. package/dist/users/usersSchemas.d.ts +40 -0
  57. package/dist/users/usersSchemas.js +34 -1
  58. package/package.json +3 -2
@@ -1,52 +1,83 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Module-level device ID cache survives class re-instantiation,
4
- // but resets on page reload if localStorage is unavailable.
5
- let _persistentDeviceId = null;
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
- * Returns a stable device ID for the browser environment.
10
+ * Generates a new opaque identifier.
8
11
  *
9
- * Algorithm:
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 (key `oneentry_device_id`).
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 from timestamp + random,
14
- * persist it to localStorage and cache it in the module variable.
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 `_nodeDeviceId`.
17
- * @returns {string | null} Device ID or null if localStorage is unavailable.
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 _getBrowserDeviceId() {
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 (_persistentDeviceId)
24
- return _persistentDeviceId;
58
+ if (_persistentIds[storageKey])
59
+ return _persistentIds[storageKey];
25
60
  try {
26
- const stored = win.localStorage.getItem('oneentry_device_id');
61
+ const stored = win.localStorage.getItem(storageKey);
27
62
  if (stored) {
28
- _persistentDeviceId = stored;
29
- return _persistentDeviceId;
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
- // Generate ID: base-36 timestamp + two random segments.
37
- // base-36 is more compact than hex and contains no special characters.
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('oneentry_device_id', id);
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 _persistentDeviceId;
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
- Date.now().toString(36) +
75
- Math.random().toString(36).substring(2, 15) +
76
- Math.random().toString(36).substring(2, 15);
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: `_getBrowserDeviceId()` — read from localStorage, stable across sessions.
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 = _getBrowserDeviceId()) !== null && _a !== void 0 ? _a : this._nodeDeviceId;
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({
@@ -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
@@ -21,7 +21,7 @@ export default class BlocksApi extends AsyncModules implements IBlocks {
21
21
  /**
22
22
  * Get blocks by parameters.
23
23
  * @handleName getBlocks
24
- * @param {BlockType} type - Available values: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none". Example: 'product'.
24
+ * @param {BlockType} [type] - Optional block type to filter by. Available values: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none". When omitted, blocks of all types are returned. Example: 'product'.
25
25
  * @param {string} [langCode] - Language code. Default: "en_US".
26
26
  * @param {number} [offset] - Parameter for pagination. Default: 0.
27
27
  * @param {number} [limit] - Parameter for pagination. Default: 30.
@@ -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,124 @@ 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.
104
+ * @example
105
+ {
106
+ "productIds": [1, 2],
107
+ "langCode": "en_US"
108
+ }
109
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
110
+ * @throws {IError} When isShell=false and an error occurs during the fetch
111
+ */
112
+ getCartComplementByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsEntity[] | IError>;
113
+ /**
114
+ * Get "similar to cart" products by the cart from context (auth user or guest).
115
+ * @handleName getCartSimilar
116
+ * @param {string} marker - Block marker. Example: "cart_similar_block".
117
+ * @param {string} [langCode] - Language code. Default: "en_US".
118
+ * @param {string} [signPrice] - Sign price.
119
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
120
+ * @throws {IError} When isShell=false and an error occurs during the fetch
121
+ */
122
+ getCartSimilar(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
123
+ /**
124
+ * Get "similar to cart" products by an explicit list of productIds (POST body).
125
+ * @handleName getCartSimilarByProductIds
126
+ * @param {string} marker - Block marker. Example: "cart_similar_block".
127
+ * @param {IBlockProductsLookup} body - Lookup body.
128
+ * @example
129
+ {
130
+ "productIds": [1, 2],
131
+ "langCode": "en_US"
132
+ }
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
+ getCartSimilarByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsEntity[] | IError>;
137
+ /**
138
+ * Get personal recommendations for the user.
139
+ * @handleName getPersonalRecommendations
140
+ * @param {string} marker - Block marker. Example: "personal_recommendations_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
+ getPersonalRecommendations(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
147
+ /**
148
+ * Get recently viewed products.
149
+ * @handleName getRecentlyViewed
150
+ * @param {string} marker - Block marker. Example: "recently_viewed_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
+ getRecentlyViewed(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
157
+ /**
158
+ * Get products for repeat purchase.
159
+ * @handleName getRepeatPurchase
160
+ * @param {string} marker - Block marker. Example: "repeat_purchase_block".
161
+ * @param {string} [langCode] - Language code. Default: "en_US".
162
+ * @param {string} [signPrice] - Sign price.
163
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
164
+ * @throws {IError} When isShell=false and an error occurs during the fetch
165
+ */
166
+ getRepeatPurchase(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
167
+ /**
168
+ * Get the block's slides tree as a flat pre-order array (slider_block only).
169
+ * @handleName getSlides
170
+ * @param {string} marker - Block marker. Example: "slider_block".
171
+ * @returns {Promise<IBlockSlidesResponse | IError>} Returns the slides response.
172
+ * @throws {IError} When isShell=false and an error occurs during the fetch
173
+ */
174
+ getSlides(marker: string): Promise<IBlockSlidesResponse | IError>;
175
+ /**
176
+ * Get trending products of the block.
177
+ * @handleName getTrending
178
+ * @param {string} marker - Block marker. Example: "trending_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
+ getTrending(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
185
+ /**
186
+ * Get "similar to wishlist" products by the wishlist from context (auth user or guest).
187
+ * @handleName getWishlistSimilar
188
+ * @param {string} marker - Block marker. Example: "wishlist_similar_block".
189
+ * @param {string} [langCode] - Language code. Default: "en_US".
190
+ * @param {string} [signPrice] - Sign price.
191
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
192
+ * @throws {IError} When isShell=false and an error occurs during the fetch
193
+ */
194
+ getWishlistSimilar(marker: string, langCode?: string, signPrice?: string): Promise<IProductsEntity[] | IError>;
195
+ /**
196
+ * Get "similar to wishlist" products by an explicit list of productIds (POST body).
197
+ * @handleName getWishlistSimilarByProductIds
198
+ * @param {string} marker - Block marker. Example: "wishlist_similar_block".
199
+ * @param {IBlockProductsLookup} body - Lookup body.
200
+ * @example
201
+ {
202
+ "productIds": [1, 2],
203
+ "langCode": "en_US"
204
+ }
205
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
206
+ * @throws {IError} When isShell=false and an error occurs during the fetch
207
+ */
208
+ getWishlistSimilarByProductIds(marker: string, body: IBlockProductsLookup): Promise<IProductsEntity[] | IError>;
88
209
  }
@@ -25,15 +25,18 @@ class BlocksApi extends asyncModules_1.default {
25
25
  /**
26
26
  * Get blocks by parameters.
27
27
  * @handleName getBlocks
28
- * @param {BlockType} type - Available values: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none". Example: 'product'.
28
+ * @param {BlockType} [type] - Optional block type to filter by. Available values: "product" | "error_page" | "catalog_page" | "product_preview" | "similar_products_block" | "product_block" | "form" | "common_page" | "common_block" | "order" | "service" | "none". When omitted, blocks of all types are returned. Example: 'product'.
29
29
  * @param {string} [langCode] - Language code. Default: "en_US".
30
30
  * @param {number} [offset] - Parameter for pagination. Default: 0.
31
31
  * @param {number} [limit] - Parameter for pagination. Default: 30.
32
32
  * @returns {Promise<IBlocksResponse | IError>} Returns BlocksEntity object.
33
33
  * @throws {IError} When isShell=false and an error occurs during the fetch
34
34
  */
35
- async getBlocks(type = '', langCode = this.state.lang, offset = 0, limit = 30) {
36
- const response = await this._fetchPost(`?langCode=${langCode}&type=${type}&offset=${offset}&limit=${limit}`);
35
+ async getBlocks(type, langCode = this.state.lang, offset = 0, limit = 30) {
36
+ // type is omitted from the query when not provided — the API rejects an
37
+ // empty type value, so it must not be sent at all.
38
+ const query = this._queryParamsToString({ langCode, type, offset, limit });
39
+ const response = await this._fetchPost(`?${query}`);
37
40
  // Validate response if validation is enabled
38
41
  const validated = this._validateResponse(response, blocksSchemas_1.BlocksResponseSchema);
39
42
  if (!this.state.traficLimit) {
@@ -136,15 +139,17 @@ class BlocksApi extends asyncModules_1.default {
136
139
  * @param {number} [offset] - Parameter for pagination. Default: 0.
137
140
  * @param {number} [limit] - Parameter for pagination. Default: 30.
138
141
  * @param {string} [signPrice] - Sign price.
142
+ * @param {number} [productId] - Optional product id to find similar products for.
139
143
  * @returns {Promise<IProductsResponse | IError>} - Returns the total count and an array of product items in object by specified block marker.
140
144
  * @throws {IError} When isShell=false and an error occurs during the fetch
141
145
  */
142
- async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice) {
146
+ async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice, productId) {
143
147
  const query = {
144
148
  langCode,
145
149
  offset,
146
150
  limit,
147
151
  signPrice,
152
+ productId,
148
153
  };
149
154
  const result = await this._fetchGet(`/${marker}/similar-products?` + this._queryParamsToString(query));
150
155
  return this._normalizeData(result);
@@ -203,5 +208,165 @@ class BlocksApi extends asyncModules_1.default {
203
208
  const validated = this._validateResponse(result, blocksSchemas_1.SearchBlocksResponseSchema);
204
209
  return validated;
205
210
  }
211
+ /**
212
+ * Get "complete your cart" products by the cart from context (auth user or guest).
213
+ * @handleName getCartComplement
214
+ * @param {string} marker - Block marker. Example: "cart_complement_block".
215
+ * @param {string} [langCode] - Language code. Default: "en_US".
216
+ * @param {string} [signPrice] - Sign price.
217
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
218
+ * @throws {IError} When isShell=false and an error occurs during the fetch
219
+ */
220
+ async getCartComplement(marker, langCode = this.state.lang, signPrice) {
221
+ const query = { langCode, signPrice };
222
+ const data = await this._fetchGet(`/${marker}/cart-complement?` + this._queryParamsToString(query));
223
+ return this._normalizeData(data);
224
+ }
225
+ /**
226
+ * Get "complete your cart" products by an explicit list of productIds (POST body).
227
+ * @handleName getCartComplementByProductIds
228
+ * @param {string} marker - Block marker. Example: "cart_complement_block".
229
+ * @param {IBlockProductsLookup} body - Lookup body.
230
+ * @example
231
+ {
232
+ "productIds": [1, 2],
233
+ "langCode": "en_US"
234
+ }
235
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
236
+ * @throws {IError} When isShell=false and an error occurs during the fetch
237
+ */
238
+ async getCartComplementByProductIds(marker, body) {
239
+ const data = await this._fetchPost(`/${marker}/cart-complement`, { langCode: this.state.lang, ...body });
240
+ return this._normalizeData(data);
241
+ }
242
+ /**
243
+ * Get "similar to cart" products by the cart from context (auth user or guest).
244
+ * @handleName getCartSimilar
245
+ * @param {string} marker - Block marker. Example: "cart_similar_block".
246
+ * @param {string} [langCode] - Language code. Default: "en_US".
247
+ * @param {string} [signPrice] - Sign price.
248
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
249
+ * @throws {IError} When isShell=false and an error occurs during the fetch
250
+ */
251
+ async getCartSimilar(marker, langCode = this.state.lang, signPrice) {
252
+ const query = { langCode, signPrice };
253
+ const data = await this._fetchGet(`/${marker}/cart-similar?` + this._queryParamsToString(query));
254
+ return this._normalizeData(data);
255
+ }
256
+ /**
257
+ * Get "similar to cart" products by an explicit list of productIds (POST body).
258
+ * @handleName getCartSimilarByProductIds
259
+ * @param {string} marker - Block marker. Example: "cart_similar_block".
260
+ * @param {IBlockProductsLookup} body - Lookup body.
261
+ * @example
262
+ {
263
+ "productIds": [1, 2],
264
+ "langCode": "en_US"
265
+ }
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 getCartSimilarByProductIds(marker, body) {
270
+ const data = await this._fetchPost(`/${marker}/cart-similar`, { langCode: this.state.lang, ...body });
271
+ return this._normalizeData(data);
272
+ }
273
+ /**
274
+ * Get personal recommendations for the user.
275
+ * @handleName getPersonalRecommendations
276
+ * @param {string} marker - Block marker. Example: "personal_recommendations_block".
277
+ * @param {string} [langCode] - Language code. Default: "en_US".
278
+ * @param {string} [signPrice] - Sign price.
279
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
280
+ * @throws {IError} When isShell=false and an error occurs during the fetch
281
+ */
282
+ async getPersonalRecommendations(marker, langCode = this.state.lang, signPrice) {
283
+ const query = { langCode, signPrice };
284
+ const data = await this._fetchGet(`/${marker}/personal-recommendations?` + this._queryParamsToString(query));
285
+ return this._normalizeData(data);
286
+ }
287
+ /**
288
+ * Get recently viewed products.
289
+ * @handleName getRecentlyViewed
290
+ * @param {string} marker - Block marker. Example: "recently_viewed_block".
291
+ * @param {string} [langCode] - Language code. Default: "en_US".
292
+ * @param {string} [signPrice] - Sign price.
293
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
294
+ * @throws {IError} When isShell=false and an error occurs during the fetch
295
+ */
296
+ async getRecentlyViewed(marker, langCode = this.state.lang, signPrice) {
297
+ const query = { langCode, signPrice };
298
+ const data = await this._fetchGet(`/${marker}/recently-viewed?` + this._queryParamsToString(query));
299
+ return this._normalizeData(data);
300
+ }
301
+ /**
302
+ * Get products for repeat purchase.
303
+ * @handleName getRepeatPurchase
304
+ * @param {string} marker - Block marker. Example: "repeat_purchase_block".
305
+ * @param {string} [langCode] - Language code. Default: "en_US".
306
+ * @param {string} [signPrice] - Sign price.
307
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
308
+ * @throws {IError} When isShell=false and an error occurs during the fetch
309
+ */
310
+ async getRepeatPurchase(marker, langCode = this.state.lang, signPrice) {
311
+ const query = { langCode, signPrice };
312
+ const data = await this._fetchGet(`/${marker}/repeat-purchase?` + this._queryParamsToString(query));
313
+ return this._normalizeData(data);
314
+ }
315
+ /**
316
+ * Get the block's slides tree as a flat pre-order array (slider_block only).
317
+ * @handleName getSlides
318
+ * @param {string} marker - Block marker. Example: "slider_block".
319
+ * @returns {Promise<IBlockSlidesResponse | IError>} Returns the slides response.
320
+ * @throws {IError} When isShell=false and an error occurs during the fetch
321
+ */
322
+ async getSlides(marker) {
323
+ const data = await this._fetchGet(`/${marker}/slides`);
324
+ return this._normalizeData(data);
325
+ }
326
+ /**
327
+ * Get trending products of the block.
328
+ * @handleName getTrending
329
+ * @param {string} marker - Block marker. Example: "trending_block".
330
+ * @param {string} [langCode] - Language code. Default: "en_US".
331
+ * @param {string} [signPrice] - Sign price.
332
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
333
+ * @throws {IError} When isShell=false and an error occurs during the fetch
334
+ */
335
+ async getTrending(marker, langCode = this.state.lang, signPrice) {
336
+ const query = { langCode, signPrice };
337
+ const data = await this._fetchGet(`/${marker}/trending?` + this._queryParamsToString(query));
338
+ return this._normalizeData(data);
339
+ }
340
+ /**
341
+ * Get "similar to wishlist" products by the wishlist from context (auth user or guest).
342
+ * @handleName getWishlistSimilar
343
+ * @param {string} marker - Block marker. Example: "wishlist_similar_block".
344
+ * @param {string} [langCode] - Language code. Default: "en_US".
345
+ * @param {string} [signPrice] - Sign price.
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 getWishlistSimilar(marker, langCode = this.state.lang, signPrice) {
350
+ const query = { langCode, signPrice };
351
+ const data = await this._fetchGet(`/${marker}/wishlist-similar?` + this._queryParamsToString(query));
352
+ return this._normalizeData(data);
353
+ }
354
+ /**
355
+ * Get "similar to wishlist" products by an explicit list of productIds (POST body).
356
+ * @handleName getWishlistSimilarByProductIds
357
+ * @param {string} marker - Block marker. Example: "wishlist_similar_block".
358
+ * @param {IBlockProductsLookup} body - Lookup body.
359
+ * @example
360
+ {
361
+ "productIds": [1, 2],
362
+ "langCode": "en_US"
363
+ }
364
+ * @returns {Promise<IProductsEntity[] | IError>} Returns an array of products.
365
+ * @throws {IError} When isShell=false and an error occurs during the fetch
366
+ */
367
+ async getWishlistSimilarByProductIds(marker, body) {
368
+ const data = await this._fetchPost(`/${marker}/wishlist-similar`, { langCode: this.state.lang, ...body });
369
+ return this._normalizeData(data);
370
+ }
206
371
  }
207
372
  exports.default = BlocksApi;