oneentry 1.0.160 → 1.0.162
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 +61 -0
- package/dist/admins/adminsApi.d.ts +15 -1
- package/dist/admins/adminsApi.js +29 -0
- package/dist/admins/adminsInterfaces.d.ts +39 -1
- package/dist/admins/adminsSchemas.d.ts +2 -0
- package/dist/admins/adminsSchemas.js +1 -0
- package/dist/attribute-sets/attributeSetsInterfaces.d.ts +2 -0
- package/dist/auth-provider/authProviderSchemas.d.ts +1 -0
- package/dist/base/lazySchema.d.ts +15 -0
- package/dist/base/lazySchema.js +20 -0
- package/dist/base/validation.d.ts +1 -0
- package/dist/base/validation.js +1 -0
- package/dist/blocks/blocksApi.d.ts +16 -8
- package/dist/blocks/blocksApi.js +24 -15
- package/dist/blocks/blocksInterfaces.d.ts +16 -8
- package/dist/discounts/discountsApi.d.ts +14 -1
- package/dist/discounts/discountsApi.js +21 -0
- package/dist/discounts/discountsInterfaces.d.ts +29 -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 +78 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/menus/menusInterfaces.d.ts +4 -0
- package/dist/menus/menusSchemas.js +2 -0
- package/dist/orders/ordersApi.d.ts +15 -1
- package/dist/orders/ordersApi.js +22 -0
- package/dist/orders/ordersInterfaces.d.ts +29 -1
- package/dist/orders/ordersSchemas.d.ts +2 -0
- package/dist/orders/ordersSchemas.js +1 -0
- package/dist/pages/pagesApi.d.ts +14 -11
- package/dist/pages/pagesApi.js +21 -17
- package/dist/pages/pagesInterfaces.d.ts +37 -17
- package/dist/pages/pagesSchemas.d.ts +3 -7
- package/dist/pages/pagesSchemas.js +2 -8
- 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 +41 -1
- package/dist/users/usersSchemas.d.ts +1 -0
- 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 +139 -0
- package/esm/admins/adminsInterfaces.js +1 -0
- package/esm/admins/adminsSchemas.d.ts +50 -0
- package/esm/admins/adminsSchemas.js +32 -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 +287 -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 +125 -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 +99 -0
- package/esm/base/validation.js +119 -0
- package/esm/blocks/blocksApi.d.ts +260 -0
- package/esm/blocks/blocksApi.js +403 -0
- package/esm/blocks/blocksInterfaces.d.ts +369 -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 +295 -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 +674 -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 +91 -0
- package/esm/menus/menusInterfaces.js +2 -0
- package/esm/menus/menusSchemas.d.ts +16 -0
- package/esm/menus/menusSchemas.js +27 -0
- package/esm/orders/ordersApi.d.ts +213 -0
- package/esm/orders/ordersApi.js +288 -0
- package/esm/orders/ordersInterfaces.d.ts +765 -0
- package/esm/orders/ordersInterfaces.js +1 -0
- package/esm/orders/ordersSchemas.d.ts +314 -0
- package/esm/orders/ordersSchemas.js +172 -0
- package/esm/package.json +4 -0
- package/esm/pages/pagesApi.d.ts +163 -0
- package/esm/pages/pagesApi.js +397 -0
- package/esm/pages/pagesInterfaces.d.ts +327 -0
- package/esm/pages/pagesInterfaces.js +1 -0
- package/esm/pages/pagesSchemas.d.ts +117 -0
- package/esm/pages/pagesSchemas.js +54 -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 +421 -0
- package/esm/users/usersInterfaces.js +1 -0
- package/esm/users/usersSchemas.d.ts +73 -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 +5 -1
- package/types.d.ts +1 -0
- package/types.js +1 -0
|
@@ -0,0 +1,397 @@
|
|
|
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
|
+
import templatesApi from '../templates/templatesApi.js';
|
|
6
|
+
const schema = createSchemaLoader(() => import('./pagesSchemas.js'));
|
|
7
|
+
/**
|
|
8
|
+
* Controllers for working with page objects, including catalog pages
|
|
9
|
+
* @handle /api/content/pages
|
|
10
|
+
* @description Controllers for working with page objects, including catalog pages
|
|
11
|
+
*/
|
|
12
|
+
export default class PagesApi extends AsyncModules {
|
|
13
|
+
/**
|
|
14
|
+
* Constructor
|
|
15
|
+
* @param {StateModule} state - The state module.
|
|
16
|
+
* @description Constructor initializes the PageApi with a given state.
|
|
17
|
+
*/
|
|
18
|
+
constructor(state) {
|
|
19
|
+
super(state);
|
|
20
|
+
this._url = state.url + '/api/content/pages';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get all top-level page objects.
|
|
24
|
+
* @handleName getRootPages
|
|
25
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
26
|
+
* @returns {Promise<IPagesEntity[] | IError>} Returns all created pages without parents as an array of PageEntity objects or an empty array [] (if there is no data)
|
|
27
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
28
|
+
* @description Get all top-level page objects.
|
|
29
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/getRootPages getRootPages} documentation.
|
|
30
|
+
*/
|
|
31
|
+
async getRootPages(langCode = this.state.lang) {
|
|
32
|
+
// Fetch data from the server using a GET request to retrieve root pages for the specified language code
|
|
33
|
+
const data = await this._fetchGet(`/root?langCode=${langCode}`);
|
|
34
|
+
// Validate response if validation is enabled
|
|
35
|
+
const validated = await this._validateResponse(data, schema('PagesResponseSchema'));
|
|
36
|
+
// Add template information to each page in the fetched root pages data
|
|
37
|
+
const withTemplate = await this.addTemplateToPages(validated);
|
|
38
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
39
|
+
return this._normalizeData(withTemplate, langCode);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get all page objects with product information as an array.
|
|
43
|
+
* @handleName getPages
|
|
44
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
45
|
+
* @returns {Promise<IPagesEntity[] | IError>} Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data).
|
|
46
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
47
|
+
* @description Get all page objects with product information as an array.
|
|
48
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/getPages getPages} documentation.
|
|
49
|
+
*/
|
|
50
|
+
async getPages(langCode = this.state.lang) {
|
|
51
|
+
// Fetch data from the server using a GET request to retrieve all pages for the specified language code
|
|
52
|
+
const data = await this._fetchGet(`?langCode=${langCode}`);
|
|
53
|
+
// Validate response if validation is enabled
|
|
54
|
+
const validated = await this._validateResponse(data, schema('PagesResponseSchema'));
|
|
55
|
+
// Add template information to each page in the fetched data
|
|
56
|
+
const withTemplate = await this.addTemplateToPages(validated);
|
|
57
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
58
|
+
return this._normalizeData(withTemplate, langCode);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get page object with information about forms, blocks, menus, linked to the page.
|
|
62
|
+
* @handleName getPageById
|
|
63
|
+
* @param {number} id - The unique identifier of the page to be fetched. Example: 1.
|
|
64
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
65
|
+
* @returns {Promise<IPagesEntity | IError>} Returns PageEntity object
|
|
66
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
67
|
+
* @description Get page object with information about forms, blocks, menus, linked to the page.
|
|
68
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/getPageById getPageById} documentation.
|
|
69
|
+
*/
|
|
70
|
+
async getPageById(id, langCode = this.state.lang) {
|
|
71
|
+
// Fetch data from the server using a GET request to retrieve page details by ID and language code
|
|
72
|
+
const data = await this._fetchGet(`/${id}?langCode=${langCode}`);
|
|
73
|
+
// Validate response if validation is enabled
|
|
74
|
+
const validated = await this._validateResponse(data, schema('PageEntitySchema'));
|
|
75
|
+
// Add template information to the fetched page data
|
|
76
|
+
const withTemplate = await this.addTemplateToPage(validated);
|
|
77
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
78
|
+
return this._normalizeData(withTemplate, langCode);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get page object with information about forms, blocks, menus, linked to the page by URL.
|
|
82
|
+
* @handleName getPageByUrl
|
|
83
|
+
* @param {string} url - Page URL. Example: "about".
|
|
84
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
85
|
+
* @returns {Promise<IPagesEntity | IError>} Returns PageEntity object
|
|
86
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
87
|
+
* @description Get page object with information about forms, blocks, menus, linked to the page by URL.
|
|
88
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/getPageByUrl getPageByUrl} documentation.
|
|
89
|
+
*/
|
|
90
|
+
async getPageByUrl(url, langCode = this.state.lang) {
|
|
91
|
+
// Fetch data from the server using a GET request with the specified URL and language code
|
|
92
|
+
const data = await this._fetchGet(`/url/${url}?langCode=${langCode}`);
|
|
93
|
+
// Validate response if validation is enabled
|
|
94
|
+
const validated = await this._validateResponse(data, schema('PageEntitySchema'));
|
|
95
|
+
// Add template information to the fetched page data
|
|
96
|
+
const withTemplate = await this.addTemplateToPage(validated);
|
|
97
|
+
// Normalize the result data and return it; ensures consistent structure or handles errors
|
|
98
|
+
return this._normalizeData(withTemplate, langCode);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get child pages object with information as an array.
|
|
102
|
+
* @handleName getChildPagesByParentUrl
|
|
103
|
+
* @param {string} url - The URL of the parent page for which child pages are to be fetched. Example: "about/our-team".
|
|
104
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
105
|
+
* @returns {Promise<IPagesEntity | IError>} Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data) for the selected parent
|
|
106
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
107
|
+
* @description Get child pages object with information as an array.
|
|
108
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/getChildPagesByParentUrl getChildPagesByParentUrl} documentation.
|
|
109
|
+
*/
|
|
110
|
+
async getChildPagesByParentUrl(url, langCode = this.state.lang) {
|
|
111
|
+
// Fetch data from the server using a GET request to retrieve child pages for the specified parent URL and language code
|
|
112
|
+
const data = await this._fetchGet(`/${url}/children?langCode=${langCode}`);
|
|
113
|
+
// Validate response if validation is enabled
|
|
114
|
+
const validated = await this._validateResponse(data, schema('PagesResponseSchema'));
|
|
115
|
+
// Add template information to each of the fetched child pages
|
|
116
|
+
const withTemplate = await this.addTemplateToPages(validated);
|
|
117
|
+
// Normalize the result data and return it; ensures consistent structure or handles errors
|
|
118
|
+
return this._normalizeData(withTemplate, langCode);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Get all blocks by page url.
|
|
122
|
+
* @handleName getBlocksByPageUrl
|
|
123
|
+
* @param {string} url - Page URL. Example: "about".
|
|
124
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
125
|
+
* @returns {Promise<IPositionBlock[] | IError>} Returns all blocks as an array of PositionBlock objects or an empty array [] (if there is no data) for the selected parent
|
|
126
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
127
|
+
* @description Get all blocks by page url.
|
|
128
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/getBlocksByPageUrl getBlocksByPageUrl} documentation.
|
|
129
|
+
*/
|
|
130
|
+
async getBlocksByPageUrl(url, langCode = this.state.lang) {
|
|
131
|
+
const response = await this._fetchGet(`/${url}/blocks?langCode=${langCode}`);
|
|
132
|
+
// Normalize the fetched response data
|
|
133
|
+
const normalizeResponse = this._normalizeData(response);
|
|
134
|
+
if (!Array.isArray(normalizeResponse)) {
|
|
135
|
+
return normalizeResponse;
|
|
136
|
+
}
|
|
137
|
+
// Helper module wrapping the block product endpoints (similar / products).
|
|
138
|
+
const staffModule = new StaffModule(this.state);
|
|
139
|
+
// Enrich every block in parallel: product / similar blocks
|
|
140
|
+
await Promise.all(normalizeResponse.map(async (item) => {
|
|
141
|
+
const customSettings = item.customSettings;
|
|
142
|
+
// Lift product display settings (stored as strings) to numeric top-level fields.
|
|
143
|
+
if (customSettings &&
|
|
144
|
+
Object.prototype.hasOwnProperty.call(customSettings, 'productConfig')) {
|
|
145
|
+
if (customSettings.productConfig.countElementsPerRow)
|
|
146
|
+
item.countElementsPerRow =
|
|
147
|
+
+customSettings.productConfig.countElementsPerRow;
|
|
148
|
+
if (customSettings.productConfig.quantity)
|
|
149
|
+
item.quantity = +customSettings.productConfig.quantity;
|
|
150
|
+
}
|
|
151
|
+
// Remove internal-only properties from the result.
|
|
152
|
+
delete item.customSettings;
|
|
153
|
+
delete item.attributesSetIdentifier;
|
|
154
|
+
// In traffic-saving mode skip the extra product requests.
|
|
155
|
+
if (this.state.traficLimit)
|
|
156
|
+
return;
|
|
157
|
+
// Attach related products by block type. StaffModule already normalizes its results.
|
|
158
|
+
if (item.type === 'similar_products_block') {
|
|
159
|
+
try {
|
|
160
|
+
item.similarProducts = await staffModule.getSimilarProducts(item.identifier, langCode);
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
item.similarProducts = [];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (item.type === 'product_block') {
|
|
167
|
+
try {
|
|
168
|
+
item.products = await staffModule.getProductsByBlockMarker(item.identifier, langCode);
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
item.products = [];
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}));
|
|
175
|
+
return normalizeResponse;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Quick search for page objects with limited output.
|
|
179
|
+
* @handleName searchPage
|
|
180
|
+
* @param {string} name - Text for searching page objects (search is performed on the title field of the localizeInfos object with the language taken into account). Example: "About Us".
|
|
181
|
+
* @param {string} [url] - Page URL. Example: "catalog".
|
|
182
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
183
|
+
* @returns {Promise<IPagesEntity[] | IPageSearchResult[] | IError>} Returns found pages as an array of PageEntity objects, an array of short PageSearchResult cards when the traficLimit config option is enabled, or an empty array [] (if there is no data)
|
|
184
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
185
|
+
* @description Quick search for page objects with limited output. The quick search endpoint returns short cards ({ id, title }); with traficLimit enabled they are returned as is, otherwise full page entities are fetched for the found ids.
|
|
186
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/searchPage searchPage} documentation.
|
|
187
|
+
*/
|
|
188
|
+
async searchPage(name, url, langCode = this.state.lang) {
|
|
189
|
+
// Fetch data from the server using a GET request to perform a quick search by page name and language code
|
|
190
|
+
const urlPart = url ? `url=${encodeURIComponent(url)}&` : '';
|
|
191
|
+
const searchPages = await this._fetchGet(`/quick/search?${urlPart}lang=${encodeURIComponent(langCode)}&name=${encodeURIComponent(name)}`);
|
|
192
|
+
// /quick/search?url=catalog&langCode=en_US&name=cat
|
|
193
|
+
// Validate response if validation is enabled
|
|
194
|
+
const data = (await this._validateResponse(searchPages, schema('PageSearchResponseSchema')));
|
|
195
|
+
// Check if there is no traffic limit set in the state
|
|
196
|
+
if (!this.state.traficLimit && Array.isArray(data)) {
|
|
197
|
+
// Initialize an empty array to store detailed page information
|
|
198
|
+
const pageList = [];
|
|
199
|
+
// Use Promise.all to fetch detailed information for each page concurrently
|
|
200
|
+
await Promise.all(data.map(async (page) => {
|
|
201
|
+
// Fetch detailed page information by page ID and push it to pageList
|
|
202
|
+
await this.getPageById(page.id, langCode).then((result) => {
|
|
203
|
+
pageList.push(result);
|
|
204
|
+
});
|
|
205
|
+
}));
|
|
206
|
+
// Add templates to the fetched pages
|
|
207
|
+
const withTemplate = await this.addTemplateToPages(pageList);
|
|
208
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
209
|
+
return this._normalizeData(withTemplate, langCode);
|
|
210
|
+
}
|
|
211
|
+
// With a traffic limit (or on an API error) return the quick search response as is:
|
|
212
|
+
// short cards carry no templateIdentifier, so there is nothing to attach a template to
|
|
213
|
+
return this._normalizeData(data, langCode);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Semantic (vector) search for pages.
|
|
217
|
+
* @handleName getPagesByVectorSearch
|
|
218
|
+
* @param {IPagesVectorSearch} body - Vector search body. Example: `{ queryText: "winter sale" }`.
|
|
219
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
220
|
+
* @param {number} [offset] - Parameter for pagination. Default: 0.
|
|
221
|
+
* @param {number} [limit] - Parameter for pagination. Default: 30.
|
|
222
|
+
* @returns {Promise<IPagesResponse | IError>} Returns an object with an array of found pages and total count.
|
|
223
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
224
|
+
* @description This method performs a semantic (vector) search for pages.
|
|
225
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/getPagesByVectorSearch getPagesByVectorSearch} documentation.
|
|
226
|
+
*/
|
|
227
|
+
async getPagesByVectorSearch(body, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
228
|
+
const query = {
|
|
229
|
+
langCode,
|
|
230
|
+
offset,
|
|
231
|
+
limit,
|
|
232
|
+
};
|
|
233
|
+
const result = await this._fetchPost(`/vector/search?` + this._queryParamsToString(query), body);
|
|
234
|
+
return this._normalizeData(result, langCode);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Add template data to pages
|
|
238
|
+
* @handleName addTemplateToPages
|
|
239
|
+
* @param {IPagesEntity[]} data - An array of page objects (IPagesEntity[]) to which template data will be added.
|
|
240
|
+
* @example
|
|
241
|
+
[
|
|
242
|
+
{
|
|
243
|
+
"id": 8,
|
|
244
|
+
"parentId": null,
|
|
245
|
+
"moduleFormConfigs": [],
|
|
246
|
+
"pageUrl": "blog",
|
|
247
|
+
"depth": 0,
|
|
248
|
+
"localizeInfos": {
|
|
249
|
+
"title": "Blog",
|
|
250
|
+
"menuTitle": "Blog",
|
|
251
|
+
"htmlContent": "",
|
|
252
|
+
"plainContent": "",
|
|
253
|
+
},
|
|
254
|
+
"isVisible": true,
|
|
255
|
+
"forms": [],
|
|
256
|
+
"blocks": [],
|
|
257
|
+
"type": "common_page",
|
|
258
|
+
"templateIdentifier": "template",
|
|
259
|
+
"attributeSetIdentifier": "page",
|
|
260
|
+
"attributeValues": {},
|
|
261
|
+
"isSync": true,
|
|
262
|
+
"template": {
|
|
263
|
+
"id": 4,
|
|
264
|
+
"attributeSetIdentifier": null,
|
|
265
|
+
"title": "Template",
|
|
266
|
+
"generalTypeId": 4,
|
|
267
|
+
"identifier": "template",
|
|
268
|
+
"version": 0,
|
|
269
|
+
"generalTypeName": "catalog_page",
|
|
270
|
+
"attributeValues": {},
|
|
271
|
+
"position": 1,
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
* @returns {Promise<any | IError>} An array of page objects with template data added
|
|
276
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
277
|
+
* @description Add template data to pages. Optimized to avoid N+1 query problem by fetching only unique templates in parallel.
|
|
278
|
+
* For example, if 100 pages use 3 different templates, this method makes 3 requests instead of 100.
|
|
279
|
+
*/
|
|
280
|
+
async addTemplateToPages(data) {
|
|
281
|
+
// On API error responses (e.g. 403 without list permission, 422) the value
|
|
282
|
+
// is an IError, not an array — return it as-is instead of calling array
|
|
283
|
+
// methods (.filter/.map) on it and throwing a TypeError.
|
|
284
|
+
if (!Array.isArray(data)) {
|
|
285
|
+
return data;
|
|
286
|
+
}
|
|
287
|
+
// Step 1: Collect unique templateIdentifiers from all pages
|
|
288
|
+
const uniqueIdentifiers = [
|
|
289
|
+
...new Set(data
|
|
290
|
+
.filter((page) => 'templateIdentifier' in page &&
|
|
291
|
+
page.templateIdentifier !== null &&
|
|
292
|
+
page.templateIdentifier !== '')
|
|
293
|
+
.map((page) => page.templateIdentifier)),
|
|
294
|
+
];
|
|
295
|
+
// Step 2: If no templates needed, return pages as-is
|
|
296
|
+
if (uniqueIdentifiers.length === 0) {
|
|
297
|
+
return data;
|
|
298
|
+
}
|
|
299
|
+
// Step 3: Fetch unique templates in parallel (not N queries, but unique count queries)
|
|
300
|
+
const Templates = new templatesApi(this.state);
|
|
301
|
+
const templatePromises = uniqueIdentifiers.map((identifier) => Templates.getTemplateByMarker(identifier).catch((error) => {
|
|
302
|
+
// eslint-disable-next-line no-undef, no-console
|
|
303
|
+
console.error(`Template fetch error for ${identifier}: `, error);
|
|
304
|
+
return null; // Return null for failed templates
|
|
305
|
+
}));
|
|
306
|
+
const templates = await Promise.all(templatePromises);
|
|
307
|
+
// Step 4: Create a Map for O(1) template lookup
|
|
308
|
+
const templateMap = new Map();
|
|
309
|
+
templates.forEach((template, index) => {
|
|
310
|
+
if (template !== null) {
|
|
311
|
+
templateMap.set(uniqueIdentifiers[index], template);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
// Step 5: Apply templates to pages (no additional API calls)
|
|
315
|
+
return data.map((page) => {
|
|
316
|
+
if ('templateIdentifier' in page &&
|
|
317
|
+
page.templateIdentifier !== null &&
|
|
318
|
+
page.templateIdentifier !== '') {
|
|
319
|
+
const template = templateMap.get(page.templateIdentifier);
|
|
320
|
+
if (template) {
|
|
321
|
+
return {
|
|
322
|
+
...page,
|
|
323
|
+
template,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
// Return page without template if identifier is missing or template not found
|
|
328
|
+
return page;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Add template data to page by page templateIdentifier
|
|
333
|
+
* @handleName addTemplateToPage
|
|
334
|
+
* @param {IPagesEntity} data - Page object (IPagesEntity) to which template data will be added.
|
|
335
|
+
* @returns {Promise<any | IError>} An array of page objects with template data added
|
|
336
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
337
|
+
* @description Add template data to page by page templateIdentifier
|
|
338
|
+
* @see {@link https://js-sdk.oneentry.cloud/docs/pages/addTemplateToPage addTemplateToPage} documentation.
|
|
339
|
+
*/
|
|
340
|
+
async addTemplateToPage(data) {
|
|
341
|
+
// Check if 'templateIdentifier' exists in 'data' and is not null or an empty string
|
|
342
|
+
if ('templateIdentifier' in data &&
|
|
343
|
+
data.templateIdentifier !== null &&
|
|
344
|
+
data.templateIdentifier !== '') {
|
|
345
|
+
// Destructure 'templateIdentifier' from 'data'
|
|
346
|
+
const { templateIdentifier } = data;
|
|
347
|
+
try {
|
|
348
|
+
// Create a new instance of templatesApi with the current state
|
|
349
|
+
const Templates = new templatesApi(this.state);
|
|
350
|
+
// Fetch the template using the 'templateIdentifier'
|
|
351
|
+
const result = await Templates.getTemplateByMarker(templateIdentifier);
|
|
352
|
+
// Return the original data object with the fetched template added
|
|
353
|
+
return {
|
|
354
|
+
...data,
|
|
355
|
+
template: result,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
// eslint-disable-next-line no-undef, no-console
|
|
360
|
+
console.error('Template fetch error: ', error);
|
|
361
|
+
return data;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
// If 'templateIdentifier' doesn't exist or is invalid, return the original data
|
|
366
|
+
return data;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Helper module for working with blocks, similar products and product blocks
|
|
372
|
+
* @description Internal module for fetching products and similar products for blocks
|
|
373
|
+
*/
|
|
374
|
+
class StaffModule extends AsyncModules {
|
|
375
|
+
constructor(state) {
|
|
376
|
+
super(state); // Call parent constructor
|
|
377
|
+
this._url = state.url + '/api/content/blocks'; // Set URL for content blocks
|
|
378
|
+
}
|
|
379
|
+
// Method to fetch similar products by marker. Returns the full response
|
|
380
|
+
// ({ total, items }) to match BlocksApi's similarProducts contract.
|
|
381
|
+
async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
382
|
+
// Fetch similar products from the server
|
|
383
|
+
const result = await this._fetchGet(`/${marker}/similar-products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
|
|
384
|
+
return this._normalizeData(result);
|
|
385
|
+
}
|
|
386
|
+
// Method to fetch products by block marker
|
|
387
|
+
async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
388
|
+
// Fetch products from the server
|
|
389
|
+
const result = await this._fetchGet(`/${marker}/products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
|
|
390
|
+
// On API error responses there is no `items` array — return the (normalized)
|
|
391
|
+
// error as-is instead of producing `undefined` from `result.items`.
|
|
392
|
+
if (!Array.isArray(result === null || result === void 0 ? void 0 : result.items)) {
|
|
393
|
+
return this._normalizeData(result);
|
|
394
|
+
}
|
|
395
|
+
return this._normalizeData(result.items);
|
|
396
|
+
}
|
|
397
|
+
}
|