oneentry 1.0.159 → 1.0.161
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 +2 -0
- package/changelog.md +56 -1
- package/dist/admins/adminsApi.d.ts +15 -1
- package/dist/admins/adminsApi.js +29 -0
- package/dist/admins/adminsInterfaces.d.ts +37 -1
- package/dist/base/lazySchema.d.ts +15 -0
- package/dist/base/lazySchema.js +20 -0
- package/dist/discounts/discountsApi.d.ts +14 -1
- package/dist/discounts/discountsApi.js +21 -0
- package/dist/discounts/discountsInterfaces.d.ts +27 -1
- package/dist/filters/filtersInterfaces.d.ts +2 -2
- package/dist/filters/filtersSchemas.d.ts +1 -1
- package/dist/filters/filtersSchemas.js +4 -1
- package/dist/forms-data/formsDataApi.d.ts +14 -1
- package/dist/forms-data/formsDataApi.js +21 -0
- package/dist/forms-data/formsDataInterfaces.d.ts +74 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/orders/ordersApi.d.ts +15 -1
- package/dist/orders/ordersApi.js +22 -0
- package/dist/orders/ordersInterfaces.d.ts +27 -1
- package/dist/pages/pagesApi.d.ts +14 -1
- package/dist/pages/pagesApi.js +21 -0
- package/dist/pages/pagesInterfaces.d.ts +38 -1
- package/dist/payments/paymentsInterfaces.d.ts +2 -2
- package/dist/products/productsInterfaces.d.ts +1 -1
- package/dist/search/searchApi.d.ts +35 -0
- package/dist/search/searchApi.js +86 -0
- package/dist/search/searchInterfaces.d.ts +94 -0
- package/dist/search/searchInterfaces.js +2 -0
- package/dist/search/searchSchemas.d.ts +73 -0
- package/dist/search/searchSchemas.js +44 -0
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +0 -2
- package/dist/templates-preview/templatesPreviewSchemas.d.ts +0 -2
- package/dist/templates-preview/templatesPreviewSchemas.js +0 -1
- package/dist/types.d.ts +35 -0
- package/dist/types.js +2 -0
- package/dist/users/usersApi.d.ts +15 -1
- package/dist/users/usersApi.js +22 -0
- package/dist/users/usersInterfaces.d.ts +39 -1
- package/dist/web-socket/lazySocket.d.ts +18 -0
- package/dist/web-socket/lazySocket.js +70 -0
- package/esm/admins/adminsApi.d.ts +66 -0
- package/esm/admins/adminsApi.js +90 -0
- package/esm/admins/adminsInterfaces.d.ts +137 -0
- package/esm/admins/adminsInterfaces.js +1 -0
- package/esm/admins/adminsSchemas.d.ts +48 -0
- package/esm/admins/adminsSchemas.js +31 -0
- package/esm/attribute-sets/attributeSetsApi.d.ts +67 -0
- package/esm/attribute-sets/attributeSetsApi.js +97 -0
- package/esm/attribute-sets/attributeSetsInterfaces.d.ts +285 -0
- package/esm/attribute-sets/attributeSetsInterfaces.js +1 -0
- package/esm/attribute-sets/attributeSetsSchemas.d.ts +84 -0
- package/esm/attribute-sets/attributeSetsSchemas.js +66 -0
- package/esm/auth-provider/authProviderApi.d.ts +262 -0
- package/esm/auth-provider/authProviderApi.js +362 -0
- package/esm/auth-provider/authProviderSchemas.d.ts +124 -0
- package/esm/auth-provider/authProviderSchemas.js +92 -0
- package/esm/auth-provider/authProvidersInterfaces.d.ts +430 -0
- package/esm/auth-provider/authProvidersInterfaces.js +1 -0
- package/esm/base/asyncModules.d.ts +123 -0
- package/esm/base/asyncModules.js +382 -0
- package/esm/base/lazySchema.d.ts +15 -0
- package/esm/base/lazySchema.js +17 -0
- package/esm/base/stateModule.d.ts +35 -0
- package/esm/base/stateModule.js +51 -0
- package/esm/base/syncModules.d.ts +245 -0
- package/esm/base/syncModules.js +555 -0
- package/esm/base/timeIntervals.d.ts +95 -0
- package/esm/base/timeIntervals.js +317 -0
- package/esm/base/utils.d.ts +354 -0
- package/esm/base/utils.js +1 -0
- package/esm/base/validation.d.ts +98 -0
- package/esm/base/validation.js +118 -0
- package/esm/blocks/blocksApi.d.ts +252 -0
- package/esm/blocks/blocksApi.js +394 -0
- package/esm/blocks/blocksInterfaces.d.ts +361 -0
- package/esm/blocks/blocksInterfaces.js +1 -0
- package/esm/blocks/blocksSchemas.d.ts +213 -0
- package/esm/blocks/blocksSchemas.js +40 -0
- package/esm/discounts/discountsApi.d.ts +94 -0
- package/esm/discounts/discountsApi.js +136 -0
- package/esm/discounts/discountsInterfaces.d.ts +293 -0
- package/esm/discounts/discountsInterfaces.js +1 -0
- package/esm/events/eventsApi.d.ts +108 -0
- package/esm/events/eventsApi.js +141 -0
- package/esm/events/eventsInterfaces.d.ts +176 -0
- package/esm/events/eventsInterfaces.js +1 -0
- package/esm/file-uploading/fileUploadingApi.d.ts +91 -0
- package/esm/file-uploading/fileUploadingApi.js +127 -0
- package/esm/file-uploading/fileUploadingInterfaces.d.ts +116 -0
- package/esm/file-uploading/fileUploadingInterfaces.js +1 -0
- package/esm/file-uploading/fileUploadingSchemas.d.ts +24 -0
- package/esm/file-uploading/fileUploadingSchemas.js +19 -0
- package/esm/filters/filtersApi.d.ts +32 -0
- package/esm/filters/filtersApi.js +36 -0
- package/esm/filters/filtersInterfaces.d.ts +56 -0
- package/esm/filters/filtersInterfaces.js +1 -0
- package/esm/filters/filtersSchemas.d.ts +32 -0
- package/esm/filters/filtersSchemas.js +29 -0
- package/esm/forms/formsApi.d.ts +44 -0
- package/esm/forms/formsApi.js +54 -0
- package/esm/forms/formsInterfaces.d.ts +237 -0
- package/esm/forms/formsInterfaces.js +1 -0
- package/esm/forms/formsSchemas.d.ts +56 -0
- package/esm/forms/formsSchemas.js +32 -0
- package/esm/forms-data/formsDataApi.d.ts +124 -0
- package/esm/forms-data/formsDataApi.js +210 -0
- package/esm/forms-data/formsDataInterfaces.d.ts +670 -0
- package/esm/forms-data/formsDataInterfaces.js +1 -0
- package/esm/forms-data/formsDataSchemas.d.ts +107 -0
- package/esm/forms-data/formsDataSchemas.js +83 -0
- package/esm/general-types/generalTypesApi.d.ts +29 -0
- package/esm/general-types/generalTypesApi.js +34 -0
- package/esm/general-types/generalTypesInterfaces.d.ts +29 -0
- package/esm/general-types/generalTypesInterfaces.js +1 -0
- package/esm/general-types/generalTypesSchemas.d.ts +68 -0
- package/esm/general-types/generalTypesSchemas.js +42 -0
- package/esm/index.d.ts +143 -0
- package/esm/index.js +124 -0
- package/esm/integration-collections/integrationCollectionsApi.d.ts +172 -0
- package/esm/integration-collections/integrationCollectionsApi.js +224 -0
- package/esm/integration-collections/integrationCollectionsInterfaces.d.ts +317 -0
- package/esm/integration-collections/integrationCollectionsInterfaces.js +1 -0
- package/esm/integration-collections/integrationCollectionsSchemas.d.ts +84 -0
- package/esm/integration-collections/integrationCollectionsSchemas.js +60 -0
- package/esm/locales/localesApi.d.ts +28 -0
- package/esm/locales/localesApi.js +33 -0
- package/esm/locales/localesInterfaces.d.ts +40 -0
- package/esm/locales/localesInterfaces.js +1 -0
- package/esm/locales/localesSchemas.d.ts +32 -0
- package/esm/locales/localesSchemas.js +23 -0
- package/esm/menus/menusApi.d.ts +30 -0
- package/esm/menus/menusApi.js +35 -0
- package/esm/menus/menusInterfaces.d.ts +87 -0
- package/esm/menus/menusInterfaces.js +2 -0
- package/esm/menus/menusSchemas.d.ts +16 -0
- package/esm/menus/menusSchemas.js +25 -0
- package/esm/orders/ordersApi.d.ts +213 -0
- package/esm/orders/ordersApi.js +288 -0
- package/esm/orders/ordersInterfaces.d.ts +763 -0
- package/esm/orders/ordersInterfaces.js +1 -0
- package/esm/orders/ordersSchemas.d.ts +312 -0
- package/esm/orders/ordersSchemas.js +171 -0
- package/esm/package.json +4 -0
- package/esm/pages/pagesApi.d.ts +173 -0
- package/esm/pages/pagesApi.js +414 -0
- package/esm/pages/pagesInterfaces.d.ts +344 -0
- package/esm/pages/pagesInterfaces.js +1 -0
- package/esm/pages/pagesSchemas.d.ts +121 -0
- package/esm/pages/pagesSchemas.js +60 -0
- package/esm/payments/paymentsApi.d.ts +88 -0
- package/esm/payments/paymentsApi.js +122 -0
- package/esm/payments/paymentsInterfaces.d.ts +189 -0
- package/esm/payments/paymentsInterfaces.js +1 -0
- package/esm/payments/paymentsSchemas.d.ts +94 -0
- package/esm/payments/paymentsSchemas.js +53 -0
- package/esm/product-statuses/productStatusesApi.d.ts +50 -0
- package/esm/product-statuses/productStatusesApi.js +68 -0
- package/esm/product-statuses/productStatusesInterfaces.d.ts +62 -0
- package/esm/product-statuses/productStatusesInterfaces.js +1 -0
- package/esm/product-statuses/productStatusesSchemas.d.ts +34 -0
- package/esm/product-statuses/productStatusesSchemas.js +27 -0
- package/esm/products/productsApi.d.ts +366 -0
- package/esm/products/productsApi.js +468 -0
- package/esm/products/productsInterfaces.d.ts +723 -0
- package/esm/products/productsInterfaces.js +1 -0
- package/esm/products/productsSchemas.d.ts +234 -0
- package/esm/products/productsSchemas.js +121 -0
- package/esm/search/searchApi.d.ts +35 -0
- package/esm/search/searchApi.js +47 -0
- package/esm/search/searchInterfaces.d.ts +94 -0
- package/esm/search/searchInterfaces.js +1 -0
- package/esm/search/searchSchemas.d.ts +73 -0
- package/esm/search/searchSchemas.js +41 -0
- package/esm/sitemap/sitemapApi.d.ts +37 -0
- package/esm/sitemap/sitemapApi.js +41 -0
- package/esm/sitemap/sitemapInterfaces.d.ts +51 -0
- package/esm/sitemap/sitemapInterfaces.js +1 -0
- package/esm/subscriptions/subscriptionsApi.d.ts +74 -0
- package/esm/subscriptions/subscriptionsApi.js +90 -0
- package/esm/subscriptions/subscriptionsInterfaces.d.ts +111 -0
- package/esm/subscriptions/subscriptionsInterfaces.js +1 -0
- package/esm/subscriptions/subscriptionsSchemas.d.ts +46 -0
- package/esm/subscriptions/subscriptionsSchemas.js +38 -0
- package/esm/system/systemApi.d.ts +46 -0
- package/esm/system/systemApi.js +53 -0
- package/esm/system/systemInterfaces.d.ts +29 -0
- package/esm/system/systemInterfaces.js +1 -0
- package/esm/templates/templatesApi.d.ts +53 -0
- package/esm/templates/templatesApi.js +78 -0
- package/esm/templates/templatesInterfaces.d.ts +68 -0
- package/esm/templates/templatesInterfaces.js +1 -0
- package/esm/templates/templatesSchemas.d.ts +48 -0
- package/esm/templates/templatesSchemas.js +28 -0
- package/esm/templates-preview/templatesPreviewApi.d.ts +40 -0
- package/esm/templates-preview/templatesPreviewApi.js +50 -0
- package/esm/templates-preview/templatesPreviewInterfaces.d.ts +129 -0
- package/esm/templates-preview/templatesPreviewInterfaces.js +1 -0
- package/esm/templates-preview/templatesPreviewSchemas.d.ts +79 -0
- package/esm/templates-preview/templatesPreviewSchemas.js +43 -0
- package/esm/types.d.ts +35 -0
- package/esm/types.js +1 -0
- package/esm/user-activity/userActivityApi.d.ts +31 -0
- package/esm/user-activity/userActivityApi.js +37 -0
- package/esm/user-activity/userActivityInterfaces.d.ts +42 -0
- package/esm/user-activity/userActivityInterfaces.js +1 -0
- package/esm/users/usersApi.d.ts +249 -0
- package/esm/users/usersApi.js +312 -0
- package/esm/users/usersInterfaces.d.ts +419 -0
- package/esm/users/usersInterfaces.js +1 -0
- package/esm/users/usersSchemas.d.ts +72 -0
- package/esm/users/usersSchemas.js +55 -0
- package/esm/web-socket/lazySocket.d.ts +18 -0
- package/esm/web-socket/lazySocket.js +67 -0
- package/esm/web-socket/wsApi.d.ts +27 -0
- package/esm/web-socket/wsApi.js +43 -0
- package/esm/web-socket/wsInterfaces.d.ts +16 -0
- package/esm/web-socket/wsInterfaces.js +1 -0
- package/package.json +47 -2
- package/types.d.ts +1 -0
- package/types.js +1 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
import AsyncModules from '../base/asyncModules.js';
|
|
4
|
+
import createSchemaLoader from '../base/lazySchema.js';
|
|
5
|
+
const schema = createSchemaLoader(() => import('./blocksSchemas.js'));
|
|
6
|
+
/**
|
|
7
|
+
* Controllers for working with blocks.
|
|
8
|
+
* @handle /api/content/blocks
|
|
9
|
+
* @class BlocksApi
|
|
10
|
+
* @augments AsyncModules
|
|
11
|
+
* @implements {IBlocks}
|
|
12
|
+
* @description This class provides methods to interact with blocks.
|
|
13
|
+
*/
|
|
14
|
+
export default class BlocksApi extends AsyncModules {
|
|
15
|
+
/**
|
|
16
|
+
* Constructor for BlocksApi class.
|
|
17
|
+
*/
|
|
18
|
+
constructor(state) {
|
|
19
|
+
super(state);
|
|
20
|
+
this._url = state.url + '/api/content/blocks';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get blocks by parameters.
|
|
24
|
+
* @handleName getBlocks
|
|
25
|
+
* @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'.
|
|
26
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
27
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
28
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
29
|
+
* @returns {Promise<IBlocksResponse | IError>} Returns BlocksEntity object.
|
|
30
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
31
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getBlocks getBlocks} documentation.
|
|
32
|
+
*/
|
|
33
|
+
async getBlocks(type, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
34
|
+
// type is omitted from the query when not provided — the API rejects an
|
|
35
|
+
// empty type value, so it must not be sent at all.
|
|
36
|
+
const query = this._queryParamsToString({ langCode, type, offset, limit });
|
|
37
|
+
const response = await this._fetchPost(`?${query}`);
|
|
38
|
+
// Validate response if validation is enabled
|
|
39
|
+
const validated = await this._validateResponse(response, schema('BlocksResponseSchema'));
|
|
40
|
+
if (!this.state.traficLimit) {
|
|
41
|
+
const normalizeResponse = this._normalizeData(validated);
|
|
42
|
+
// On API error responses (e.g. 403 without list permission, 422) the
|
|
43
|
+
// normalized value is an IError without `items` — skip enrichment and
|
|
44
|
+
// return it as-is
|
|
45
|
+
if (Array.isArray(normalizeResponse.items)) {
|
|
46
|
+
await Promise.all(normalizeResponse.items.map((block) => this._enrichBlock(block, langCode, offset, limit, true)));
|
|
47
|
+
}
|
|
48
|
+
return normalizeResponse;
|
|
49
|
+
}
|
|
50
|
+
return this._normalizeData(validated);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get block by marker.
|
|
54
|
+
* @handleName getBlockByMarker
|
|
55
|
+
* @param {string} marker - Marker of Block. Example: "product_block".
|
|
56
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
57
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
58
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
59
|
+
* @returns {Promise<IBlockEntity | IError>} - Returns a BlockEntity object.
|
|
60
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
61
|
+
* @description This method retrieves a block by its marker and includes additional information such as similar products or products associated with the block.
|
|
62
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getBlockByMarker getBlockByMarker} documentation.
|
|
63
|
+
*/
|
|
64
|
+
async getBlockByMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
65
|
+
const response = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
|
|
66
|
+
// Validate response if validation is enabled
|
|
67
|
+
const validated = await this._validateResponse(response, schema('BlockEntitySchema'));
|
|
68
|
+
const normalizeResponse = this._normalizeData(validated);
|
|
69
|
+
await this._enrichBlock(normalizeResponse, langCode, offset, limit, !this.state.traficLimit);
|
|
70
|
+
return normalizeResponse;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Enrich a single block in place.
|
|
74
|
+
*
|
|
75
|
+
* Lifts product display settings from `customSettings.productConfig` to
|
|
76
|
+
* numeric top-level fields, strips internal-only fields, and — when
|
|
77
|
+
* `loadProducts` is true — fetches the related products for
|
|
78
|
+
* `similar_products_block` / `product_block` blocks. Shared by `getBlocks`
|
|
79
|
+
* (array) and `getBlockByMarker` (single block). Mutates `block` in place.
|
|
80
|
+
* @param {any} block - Normalized block to enrich (mutated in place).
|
|
81
|
+
* @param {string} langCode - Language code passed to product sub-requests.
|
|
82
|
+
* @param {number} offset - Pagination offset for product sub-requests.
|
|
83
|
+
* @param {number} limit - Pagination limit for product sub-requests.
|
|
84
|
+
* @param {boolean} loadProducts - Whether to fetch related products.
|
|
85
|
+
* @returns {Promise<void>} Resolves when enrichment (incl. sub-requests) is done.
|
|
86
|
+
*/
|
|
87
|
+
async _enrichBlock(block, langCode, offset, limit, loadProducts) {
|
|
88
|
+
const customSettings = block.customSettings;
|
|
89
|
+
// Если у блока есть настройки отображения товаров (productConfig) —
|
|
90
|
+
// переносим их на верхний уровень блока в числовом формате (в API значения
|
|
91
|
+
// хранятся строками, поэтому приводим через «+»).
|
|
92
|
+
if (customSettings &&
|
|
93
|
+
Object.prototype.hasOwnProperty.call(customSettings, 'productConfig')) {
|
|
94
|
+
if (customSettings.productConfig.countElementsPerRow)
|
|
95
|
+
block.countElementsPerRow =
|
|
96
|
+
+customSettings.productConfig.countElementsPerRow;
|
|
97
|
+
if (customSettings.productConfig.quantity)
|
|
98
|
+
block.quantity = +customSettings.productConfig.quantity;
|
|
99
|
+
}
|
|
100
|
+
// Убираем служебные/внутренние поля из итогового объекта блока.
|
|
101
|
+
delete block.customSettings;
|
|
102
|
+
delete block.attributesSetIdentifier;
|
|
103
|
+
delete block.productPageUrls;
|
|
104
|
+
// В режиме экономии трафика товары не подгружаем.
|
|
105
|
+
if (!loadProducts)
|
|
106
|
+
return;
|
|
107
|
+
// Подгружаем связанные товары по идентификатору блока. При ошибке запроса
|
|
108
|
+
// подставляем пустой массив, чтобы один упавший подзапрос не ронял весь
|
|
109
|
+
// ответ (в getBlocks — не ломал обработку остальных блоков).
|
|
110
|
+
if (block.type === 'similar_products_block') {
|
|
111
|
+
try {
|
|
112
|
+
block.similarProducts = await this.getSimilarProducts(block.identifier, langCode, offset, limit);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
block.similarProducts = [];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else if (block.type === 'product_block') {
|
|
119
|
+
try {
|
|
120
|
+
block.products = await this.getProductsByBlockMarker(block.identifier, langCode, offset, limit);
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
block.products = [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get similar products by block marker.
|
|
129
|
+
* @handleName getSimilarProducts
|
|
130
|
+
* @param {string} marker - Block identifier. Example: "similar_products_block".
|
|
131
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
132
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
133
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
134
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
135
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
136
|
+
* @param {number} [productId] - Optional product id to find similar products for.
|
|
137
|
+
* @returns {Promise<IProductsResponse | IError>} Returns the total count and an array of product items in object by specified block marker.
|
|
138
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
139
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getSimilarProducts getSimilarProducts} documentation.
|
|
140
|
+
*/
|
|
141
|
+
async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice, productId) {
|
|
142
|
+
const query = {
|
|
143
|
+
langCode,
|
|
144
|
+
offset,
|
|
145
|
+
limit,
|
|
146
|
+
signPrice,
|
|
147
|
+
productId,
|
|
148
|
+
};
|
|
149
|
+
const result = await this._fetchGet(`/${marker}/similar-products?` + this._queryParamsToString(query));
|
|
150
|
+
return this._normalizeData(result);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get products by block marker.
|
|
154
|
+
* @handleName getProductsByBlockMarker
|
|
155
|
+
* @param {string} marker - Block identifier. Example: "product_block".
|
|
156
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
157
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
158
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
159
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
160
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
161
|
+
* @returns {Promise<IProductsEntity[] | IError>} Return array of BlocksEntity object.
|
|
162
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
163
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getProductsByBlockMarker getProductsByBlockMarker} documentation.
|
|
164
|
+
*/
|
|
165
|
+
async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30, signPrice) {
|
|
166
|
+
const query = {
|
|
167
|
+
langCode,
|
|
168
|
+
offset,
|
|
169
|
+
limit,
|
|
170
|
+
signPrice,
|
|
171
|
+
};
|
|
172
|
+
const result = await this._fetchGet(`/${marker}/products?` + this._queryParamsToString(query));
|
|
173
|
+
// On API error responses there is no `items` array — return the (normalized)
|
|
174
|
+
// error as-is instead of producing `undefined` from `result.items`.
|
|
175
|
+
if (!Array.isArray(result === null || result === void 0 ? void 0 : result.items)) {
|
|
176
|
+
return this._normalizeData(result);
|
|
177
|
+
}
|
|
178
|
+
return this._normalizeData(result.items);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Get frequently ordered products by block marker and product id.
|
|
182
|
+
* @handleName getFrequentlyOrderedProducts
|
|
183
|
+
* @param {number} productId - Product id. Example: 1.
|
|
184
|
+
* @param {string} marker - Block marker. Example: "frequently_ordered_block".
|
|
185
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
186
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
187
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
188
|
+
* @returns {Promise<IProductsResponse | IError>} Returns a products response with items and total.
|
|
189
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
190
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getFrequentlyOrderedProducts getFrequentlyOrderedProducts} documentation.
|
|
191
|
+
*/
|
|
192
|
+
async getFrequentlyOrderedProducts(productId, marker, langCode = this.state.lang, signPrice) {
|
|
193
|
+
const query = {
|
|
194
|
+
langCode,
|
|
195
|
+
signPrice,
|
|
196
|
+
};
|
|
197
|
+
const data = await this._fetchGet(`/${marker}/products/${productId}/frequently-ordered?` +
|
|
198
|
+
this._queryParamsToString(query));
|
|
199
|
+
return this._normalizeData(data);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Quick search for block objects with limited output.
|
|
203
|
+
* @handleName searchBlock
|
|
204
|
+
* @param {string} name - Search string. Example: "product_block".
|
|
205
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
206
|
+
* @returns {Promise<ISearchBlock[] | IError>} Returns an array of ISearchBlock objects.
|
|
207
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
208
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/searchBlock searchBlock} documentation.
|
|
209
|
+
*/
|
|
210
|
+
async searchBlock(name, langCode = this.state.lang) {
|
|
211
|
+
const result = await this._fetchGet(`/quick/search?langCode=${encodeURIComponent(langCode)}&name=${encodeURIComponent(name)}`);
|
|
212
|
+
// Validate response if validation is enabled
|
|
213
|
+
const validated = await this._validateResponse(result, schema('SearchBlocksResponseSchema'));
|
|
214
|
+
return validated;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get "complete your cart" products by the cart from context (auth user or guest).
|
|
218
|
+
* @handleName getCartComplement
|
|
219
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
220
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
221
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
222
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
223
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
224
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
225
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartComplement getCartComplement} documentation.
|
|
226
|
+
*/
|
|
227
|
+
async getCartComplement(marker, langCode = this.state.lang, signPrice) {
|
|
228
|
+
const query = { langCode, signPrice };
|
|
229
|
+
const data = await this._fetchGet(`/${marker}/cart-complement?` + this._queryParamsToString(query));
|
|
230
|
+
return this._normalizeData(data);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get "complete your cart" products by an explicit list of productIds (POST body).
|
|
234
|
+
* @handleName getCartComplementByProductIds
|
|
235
|
+
* @param {string} marker - Block marker. Example: "cart_complement_block".
|
|
236
|
+
* @param {IBlockProductsLookup} body - Lookup body.
|
|
237
|
+
* @example
|
|
238
|
+
{
|
|
239
|
+
"productIds": [1, 2],
|
|
240
|
+
"langCode": "en_US"
|
|
241
|
+
}
|
|
242
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
243
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
244
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartComplementByProductIds getCartComplementByProductIds} documentation.
|
|
245
|
+
*/
|
|
246
|
+
async getCartComplementByProductIds(marker, body) {
|
|
247
|
+
const data = await this._fetchPost(`/${marker}/cart-complement`, { langCode: this.state.lang, ...body });
|
|
248
|
+
return this._normalizeData(data);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get "similar to cart" products by the cart from context (auth user or guest).
|
|
252
|
+
* @handleName getCartSimilar
|
|
253
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
254
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
255
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
256
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
257
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
258
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
259
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartSimilar getCartSimilar} documentation.
|
|
260
|
+
*/
|
|
261
|
+
async getCartSimilar(marker, langCode = this.state.lang, signPrice) {
|
|
262
|
+
const query = { langCode, signPrice };
|
|
263
|
+
const data = await this._fetchGet(`/${marker}/cart-similar?` + this._queryParamsToString(query));
|
|
264
|
+
return this._normalizeData(data);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get "similar to cart" products by an explicit list of productIds (POST body).
|
|
268
|
+
* @handleName getCartSimilarByProductIds
|
|
269
|
+
* @param {string} marker - Block marker. Example: "cart_similar_block".
|
|
270
|
+
* @param {IBlockProductsLookup} body - Lookup body.
|
|
271
|
+
* @example
|
|
272
|
+
{
|
|
273
|
+
"productIds": [1, 2],
|
|
274
|
+
"langCode": "en_US"
|
|
275
|
+
}
|
|
276
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
277
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
278
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getCartSimilarByProductIds getCartSimilarByProductIds} documentation.
|
|
279
|
+
*/
|
|
280
|
+
async getCartSimilarByProductIds(marker, body) {
|
|
281
|
+
const data = await this._fetchPost(`/${marker}/cart-similar`, { langCode: this.state.lang, ...body });
|
|
282
|
+
return this._normalizeData(data);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Get personal recommendations for the user.
|
|
286
|
+
* @handleName getPersonalRecommendations
|
|
287
|
+
* @param {string} marker - Block marker. Example: "personal_recommendations_block".
|
|
288
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
289
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
290
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
291
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
292
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
293
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getPersonalRecommendations getPersonalRecommendations} documentation.
|
|
294
|
+
*/
|
|
295
|
+
async getPersonalRecommendations(marker, langCode = this.state.lang, signPrice) {
|
|
296
|
+
const query = { langCode, signPrice };
|
|
297
|
+
const data = await this._fetchGet(`/${marker}/personal-recommendations?` + this._queryParamsToString(query));
|
|
298
|
+
return this._normalizeData(data);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Get recently viewed products.
|
|
302
|
+
* @handleName getRecentlyViewed
|
|
303
|
+
* @param {string} marker - Block marker. Example: "recently_viewed_block".
|
|
304
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
305
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
306
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
307
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
308
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
309
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getRecentlyViewed getRecentlyViewed} documentation.
|
|
310
|
+
*/
|
|
311
|
+
async getRecentlyViewed(marker, langCode = this.state.lang, signPrice) {
|
|
312
|
+
const query = { langCode, signPrice };
|
|
313
|
+
const data = await this._fetchGet(`/${marker}/recently-viewed?` + this._queryParamsToString(query));
|
|
314
|
+
return this._normalizeData(data);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get products for repeat purchase.
|
|
318
|
+
* @handleName getRepeatPurchase
|
|
319
|
+
* @param {string} marker - Block marker. Example: "repeat_purchase_block".
|
|
320
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
321
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
322
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
323
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
324
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
325
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getRepeatPurchase getRepeatPurchase} documentation.
|
|
326
|
+
*/
|
|
327
|
+
async getRepeatPurchase(marker, langCode = this.state.lang, signPrice) {
|
|
328
|
+
const query = { langCode, signPrice };
|
|
329
|
+
const data = await this._fetchGet(`/${marker}/repeat-purchase?` + this._queryParamsToString(query));
|
|
330
|
+
return this._normalizeData(data);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get the block's slides tree as a flat pre-order array (slider_block only).
|
|
334
|
+
* @handleName getSlides
|
|
335
|
+
* @param {string} marker - Block marker. Example: "slider_block".
|
|
336
|
+
* @returns {Promise<IBlockSlidesResponse | IError>} Returns the slides response.
|
|
337
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
338
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getSlides getSlides} documentation.
|
|
339
|
+
*/
|
|
340
|
+
async getSlides(marker) {
|
|
341
|
+
const data = await this._fetchGet(`/${marker}/slides`);
|
|
342
|
+
return this._normalizeData(data);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Get trending products of the block.
|
|
346
|
+
* @handleName getTrending
|
|
347
|
+
* @param {string} marker - Block marker. Example: "trending_block".
|
|
348
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
349
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
350
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
351
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
352
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
353
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getTrending getTrending} documentation.
|
|
354
|
+
*/
|
|
355
|
+
async getTrending(marker, langCode = this.state.lang, signPrice) {
|
|
356
|
+
const query = { langCode, signPrice };
|
|
357
|
+
const data = await this._fetchGet(`/${marker}/trending?` + this._queryParamsToString(query));
|
|
358
|
+
return this._normalizeData(data);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Get "similar to wishlist" products by the wishlist from context (auth user or guest).
|
|
362
|
+
* @handleName getWishlistSimilar
|
|
363
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
364
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
365
|
+
* @param {string} [signPrice] - Order storage marker for price fixing. If the parameter is set, the price is fixed for a certain time.
|
|
366
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/#Fixing-the-price-signPrice Fixing the price} documentation.
|
|
367
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
368
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
369
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getWishlistSimilar getWishlistSimilar} documentation.
|
|
370
|
+
*/
|
|
371
|
+
async getWishlistSimilar(marker, langCode = this.state.lang, signPrice) {
|
|
372
|
+
const query = { langCode, signPrice };
|
|
373
|
+
const data = await this._fetchGet(`/${marker}/wishlist-similar?` + this._queryParamsToString(query));
|
|
374
|
+
return this._normalizeData(data);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get "similar to wishlist" products by an explicit list of productIds (POST body).
|
|
378
|
+
* @handleName getWishlistSimilarByProductIds
|
|
379
|
+
* @param {string} marker - Block marker. Example: "wishlist_similar_block".
|
|
380
|
+
* @param {IBlockProductsLookup} body - Lookup body.
|
|
381
|
+
* @example
|
|
382
|
+
{
|
|
383
|
+
"productIds": [1, 2],
|
|
384
|
+
"langCode": "en_US"
|
|
385
|
+
}
|
|
386
|
+
* @returns {Promise<IProductsResponse | IError>} Returns an object with an array of products, total count and totalFound.
|
|
387
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
388
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/blocks/getWishlistSimilarByProductIds getWishlistSimilarByProductIds} documentation.
|
|
389
|
+
*/
|
|
390
|
+
async getWishlistSimilarByProductIds(marker, body) {
|
|
391
|
+
const data = await this._fetchPost(`/${marker}/wishlist-similar`, { langCode: this.state.lang, ...body });
|
|
392
|
+
return this._normalizeData(data);
|
|
393
|
+
}
|
|
394
|
+
}
|