oneentry 1.0.142 → 1.0.143
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/dist/admins/adminsApi.d.ts +50 -0
- package/dist/admins/adminsApi.js +65 -0
- package/dist/admins/adminsInterfaces.d.ts +98 -0
- package/dist/admins/adminsInterfaces.js +2 -0
- package/dist/admins/adminsSchemas.d.ts +30 -0
- package/dist/admins/adminsSchemas.js +27 -0
- package/dist/attribute-sets/attributeSetsApi.d.ts +63 -0
- package/dist/attribute-sets/attributeSetsApi.js +98 -0
- package/dist/attribute-sets/attributeSetsInterfaces.d.ts +185 -0
- package/dist/attribute-sets/attributeSetsInterfaces.js +2 -0
- package/dist/attribute-sets/attributeSetsSchemas.d.ts +90 -0
- package/dist/attribute-sets/attributeSetsSchemas.js +74 -0
- package/dist/auth-provider/authProviderApi.d.ts +249 -0
- package/dist/auth-provider/authProviderApi.js +354 -0
- package/dist/auth-provider/authProviderSchemas.d.ts +131 -0
- package/dist/auth-provider/authProviderSchemas.js +82 -0
- package/dist/auth-provider/authProvidersInterfaces.d.ts +412 -0
- package/dist/auth-provider/authProvidersInterfaces.js +2 -0
- package/dist/base/asyncModules.d.ts +80 -0
- package/dist/base/asyncModules.js +448 -0
- package/dist/base/result.d.ts +39 -0
- package/dist/base/result.js +154 -0
- package/dist/base/stateModule.d.ts +41 -0
- package/dist/base/stateModule.js +128 -0
- package/dist/base/syncModules.d.ts +286 -0
- package/dist/base/syncModules.js +716 -0
- package/dist/base/utils.d.ts +197 -0
- package/dist/base/utils.js +2 -0
- package/dist/base/validation.d.ts +118 -0
- package/dist/base/validation.js +132 -0
- package/dist/blocks/blocksApi.d.ts +76 -0
- package/dist/blocks/blocksApi.js +188 -0
- package/dist/blocks/blocksInterfaces.d.ts +168 -0
- package/dist/blocks/blocksInterfaces.js +2 -0
- package/dist/blocks/blocksSchemas.d.ts +195 -0
- package/dist/blocks/blocksSchemas.js +43 -0
- package/dist/discounts/discountsApi.d.ts +56 -0
- package/dist/discounts/discountsApi.js +82 -0
- package/dist/discounts/discountsInterfaces.d.ts +145 -0
- package/dist/discounts/discountsInterfaces.js +2 -0
- package/dist/events/eventsApi.d.ts +60 -0
- package/dist/events/eventsApi.js +97 -0
- package/dist/events/eventsInterfaces.d.ts +87 -0
- package/dist/events/eventsInterfaces.js +2 -0
- package/dist/file-uploading/fileUploadingApi.d.ts +88 -0
- package/dist/file-uploading/fileUploadingApi.js +129 -0
- package/dist/file-uploading/fileUploadingInterfaces.d.ts +114 -0
- package/dist/file-uploading/fileUploadingInterfaces.js +2 -0
- package/dist/file-uploading/fileUploadingSchemas.d.ts +22 -0
- package/dist/file-uploading/fileUploadingSchemas.js +21 -0
- package/dist/forms/formsApi.d.ts +42 -0
- package/dist/forms/formsApi.js +57 -0
- package/dist/forms/formsInterfaces.d.ts +134 -0
- package/dist/forms/formsInterfaces.js +2 -0
- package/dist/forms/formsSchemas.d.ts +50 -0
- package/dist/forms/formsSchemas.js +31 -0
- package/dist/forms-data/formsDataApi.d.ts +106 -0
- package/dist/forms-data/formsDataApi.js +189 -0
- package/dist/forms-data/formsDataInterfaces.d.ts +522 -0
- package/dist/forms-data/formsDataInterfaces.js +2 -0
- package/dist/forms-data/formsDataSchemas.d.ts +115 -0
- package/dist/forms-data/formsDataSchemas.js +86 -0
- package/dist/general-types/generalTypesApi.d.ts +28 -0
- package/dist/general-types/generalTypesApi.js +38 -0
- package/dist/general-types/generalTypesInterfaces.d.ts +29 -0
- package/dist/general-types/generalTypesInterfaces.js +2 -0
- package/dist/general-types/generalTypesSchemas.d.ts +50 -0
- package/dist/general-types/generalTypesSchemas.js +35 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +103 -0
- package/dist/integration-collections/integrationCollectionsApi.d.ts +163 -0
- package/dist/integration-collections/integrationCollectionsApi.js +220 -0
- package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +313 -0
- package/dist/integration-collections/integrationCollectionsInterfaces.js +2 -0
- package/dist/integration-collections/integrationCollectionsSchemas.d.ts +80 -0
- package/dist/integration-collections/integrationCollectionsSchemas.js +61 -0
- package/dist/locales/localesApi.d.ts +27 -0
- package/dist/locales/localesApi.js +37 -0
- package/dist/locales/localesInterfaces.d.ts +40 -0
- package/dist/locales/localesInterfaces.js +2 -0
- package/dist/locales/localesSchemas.d.ts +32 -0
- package/dist/locales/localesSchemas.js +26 -0
- package/dist/menus/menusApi.d.ts +29 -0
- package/dist/menus/menusApi.js +39 -0
- package/dist/menus/menusInterfaces.d.ts +87 -0
- package/dist/menus/menusInterfaces.js +3 -0
- package/dist/menus/menusSchemas.d.ts +16 -0
- package/dist/menus/menusSchemas.js +28 -0
- package/dist/orders/ordersApi.d.ts +149 -0
- package/dist/orders/ordersApi.js +203 -0
- package/dist/orders/ordersInterfaces.d.ts +520 -0
- package/dist/orders/ordersInterfaces.js +2 -0
- package/dist/orders/ordersSchemas.d.ts +120 -0
- package/dist/orders/ordersSchemas.js +101 -0
- package/dist/pages/pagesApi.d.ts +151 -0
- package/dist/pages/pagesApi.js +390 -0
- package/dist/pages/pagesInterfaces.d.ts +284 -0
- package/dist/pages/pagesInterfaces.js +2 -0
- package/dist/pages/pagesSchemas.d.ts +85 -0
- package/dist/pages/pagesSchemas.js +46 -0
- package/dist/payments/paymentsApi.d.ts +82 -0
- package/dist/payments/paymentsApi.js +121 -0
- package/dist/payments/paymentsInterfaces.d.ts +200 -0
- package/dist/payments/paymentsInterfaces.js +2 -0
- package/dist/payments/paymentsSchemas.d.ts +100 -0
- package/dist/payments/paymentsSchemas.js +65 -0
- package/dist/product-statuses/productStatusesApi.d.ts +47 -0
- package/dist/product-statuses/productStatusesApi.js +70 -0
- package/dist/product-statuses/productStatusesInterfaces.d.ts +62 -0
- package/dist/product-statuses/productStatusesInterfaces.js +2 -0
- package/dist/product-statuses/productStatusesSchemas.d.ts +34 -0
- package/dist/product-statuses/productStatusesSchemas.js +30 -0
- package/dist/products/productsApi.d.ts +365 -0
- package/dist/products/productsApi.js +459 -0
- package/dist/products/productsInterfaces.d.ts +577 -0
- package/dist/products/productsInterfaces.js +2 -0
- package/dist/products/productsSchemas.d.ts +200 -0
- package/dist/products/productsSchemas.js +98 -0
- package/dist/sitemap/sitemapApi.d.ts +35 -0
- package/dist/sitemap/sitemapApi.js +45 -0
- package/dist/sitemap/sitemapInterfaces.d.ts +40 -0
- package/dist/sitemap/sitemapInterfaces.js +2 -0
- package/dist/system/systemApi.d.ts +43 -0
- package/dist/system/systemApi.js +56 -0
- package/dist/system/systemInterfaces.d.ts +29 -0
- package/dist/system/systemInterfaces.js +2 -0
- package/dist/templates/templatesApi.d.ts +49 -0
- package/dist/templates/templatesApi.js +75 -0
- package/dist/templates/templatesInterfaces.d.ts +67 -0
- package/dist/templates/templatesInterfaces.js +2 -0
- package/dist/templates/templatesSchemas.d.ts +48 -0
- package/dist/templates/templatesSchemas.js +31 -0
- package/dist/templates-preview/templatesPreviewApi.d.ts +38 -0
- package/dist/templates-preview/templatesPreviewApi.js +53 -0
- package/dist/templates-preview/templatesPreviewInterfaces.d.ts +119 -0
- package/dist/templates-preview/templatesPreviewInterfaces.js +2 -0
- package/dist/templates-preview/templatesPreviewSchemas.d.ts +83 -0
- package/dist/templates-preview/templatesPreviewSchemas.js +48 -0
- package/dist/users/usersApi.d.ts +143 -0
- package/dist/users/usersApi.js +171 -0
- package/dist/users/usersInterfaces.d.ts +229 -0
- package/dist/users/usersInterfaces.js +2 -0
- package/dist/users/usersSchemas.d.ts +38 -0
- package/dist/users/usersSchemas.js +28 -0
- package/dist/web-socket/wsApi.d.ts +25 -0
- package/dist/web-socket/wsApi.js +45 -0
- package/dist/web-socket/wsInterfaces.d.ts +16 -0
- package/dist/web-socket/wsInterfaces.js +2 -0
- package/package.json +3 -81
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdateOrderResponseSchema = exports.CreateOrderResponseSchema = exports.OrdersStorageResponseSchema = exports.OrderStorageSchema = exports.OrdersResponseSchema = exports.OrderEntitySchema = exports.OrderItemSchema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Validation schemas for Orders module
|
|
6
|
+
* @description Zod schemas for validating orders-related API responses
|
|
7
|
+
*/
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
/**
|
|
10
|
+
* Order item schema
|
|
11
|
+
* @description Order item schema for validating orders-related API responses
|
|
12
|
+
*/
|
|
13
|
+
exports.OrderItemSchema = zod_1.z.object({
|
|
14
|
+
id: zod_1.z.number(),
|
|
15
|
+
productId: zod_1.z.number(),
|
|
16
|
+
quantity: zod_1.z.number(),
|
|
17
|
+
price: zod_1.z.number(),
|
|
18
|
+
total: zod_1.z.number(),
|
|
19
|
+
attributes: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Order entity schema
|
|
23
|
+
* @description Order entity schema for validating orders-related API responses
|
|
24
|
+
*/
|
|
25
|
+
exports.OrderEntitySchema = zod_1.z.object({
|
|
26
|
+
id: zod_1.z.number(),
|
|
27
|
+
storageId: zod_1.z.number().optional(),
|
|
28
|
+
createdDate: zod_1.z.string().optional(),
|
|
29
|
+
statusIdentifier: zod_1.z.string().optional(),
|
|
30
|
+
formIdentifier: zod_1.z.string().optional(),
|
|
31
|
+
formData: zod_1.z
|
|
32
|
+
.union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
|
|
33
|
+
.optional(),
|
|
34
|
+
attributeSetIdentifier: zod_1.z.string().optional().nullable(),
|
|
35
|
+
totalSum: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
|
|
36
|
+
currency: zod_1.z.string().optional(),
|
|
37
|
+
paymentAccountIdentifier: zod_1.z.string().optional().nullable(),
|
|
38
|
+
paymentAccountLocalizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
39
|
+
paymentUrl: zod_1.z.string().optional().nullable(),
|
|
40
|
+
products: zod_1.z.array(zod_1.z.any()).optional(),
|
|
41
|
+
isCompleted: zod_1.z.boolean().optional().nullable(),
|
|
42
|
+
statusLocalizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Orders list response schema
|
|
46
|
+
* @returns Orders list response schema
|
|
47
|
+
*/
|
|
48
|
+
exports.OrdersResponseSchema = zod_1.z.object({
|
|
49
|
+
items: zod_1.z.array(exports.OrderEntitySchema),
|
|
50
|
+
total: zod_1.z.number(),
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Order storage schema
|
|
54
|
+
* @returns Order storage validation schema
|
|
55
|
+
*/
|
|
56
|
+
exports.OrderStorageSchema = zod_1.z.object({
|
|
57
|
+
id: zod_1.z.number(),
|
|
58
|
+
identifier: zod_1.z.string().nullable(),
|
|
59
|
+
localizeInfos: zod_1.z.record(zod_1.z.string(), zod_1.z.any()),
|
|
60
|
+
formIdentifier: zod_1.z.string().nullable(),
|
|
61
|
+
generalTypeId: zod_1.z.number().nullable(),
|
|
62
|
+
paymentAccountIdentifiers: zod_1.z.array(zod_1.z.object({ identifier: zod_1.z.string() })),
|
|
63
|
+
position: zod_1.z.number().nullable(),
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Orders storage list response schema
|
|
67
|
+
* @returns Orders storage list response schema
|
|
68
|
+
*/
|
|
69
|
+
exports.OrdersStorageResponseSchema = zod_1.z.array(exports.OrderStorageSchema);
|
|
70
|
+
/**
|
|
71
|
+
* Create order response schema
|
|
72
|
+
* API returns a simplified order object after creation
|
|
73
|
+
* @returns Create order response schema
|
|
74
|
+
*/
|
|
75
|
+
exports.CreateOrderResponseSchema = zod_1.z.object({
|
|
76
|
+
id: zod_1.z.number(),
|
|
77
|
+
formIdentifier: zod_1.z.string().optional(),
|
|
78
|
+
paymentAccountIdentifier: zod_1.z.string().optional(),
|
|
79
|
+
formData: zod_1.z
|
|
80
|
+
.union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
|
|
81
|
+
.optional(),
|
|
82
|
+
products: zod_1.z.array(zod_1.z.any()).optional(),
|
|
83
|
+
currency: zod_1.z.string().optional(),
|
|
84
|
+
totalSum: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
|
|
85
|
+
createdDate: zod_1.z.string().optional(),
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Update order response schema
|
|
89
|
+
* API returns the full order object after update
|
|
90
|
+
*/
|
|
91
|
+
exports.UpdateOrderResponseSchema = zod_1.z.object({
|
|
92
|
+
id: zod_1.z.number(),
|
|
93
|
+
formIdentifier: zod_1.z.string().optional(),
|
|
94
|
+
paymentAccountIdentifier: zod_1.z.string().optional(),
|
|
95
|
+
formData: zod_1.z
|
|
96
|
+
.union([zod_1.z.array(zod_1.z.any()), zod_1.z.record(zod_1.z.string(), zod_1.z.any())])
|
|
97
|
+
.optional(),
|
|
98
|
+
products: zod_1.z.array(zod_1.z.any()).optional(),
|
|
99
|
+
currency: zod_1.z.string().optional(),
|
|
100
|
+
totalSum: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]).optional(),
|
|
101
|
+
});
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import AsyncModules from '../base/asyncModules';
|
|
2
|
+
import type StateModule from '../base/stateModule';
|
|
3
|
+
import type { IError } from '../base/utils';
|
|
4
|
+
import type { IPageConfig, IPagesApi, IPagesEntity, IPositionBlock } from './pagesInterfaces';
|
|
5
|
+
/**
|
|
6
|
+
* Controllers for working with page objects, including catalog pages
|
|
7
|
+
* @handle /api/content/pages
|
|
8
|
+
* @description Controllers for working with page objects, including catalog pages
|
|
9
|
+
*/
|
|
10
|
+
export default class PagesApi extends AsyncModules implements IPagesApi {
|
|
11
|
+
protected state: StateModule;
|
|
12
|
+
protected _url: string;
|
|
13
|
+
/**
|
|
14
|
+
* Constructor
|
|
15
|
+
* @param {StateModule} state - The state module.
|
|
16
|
+
* @description Constructor initializes the PageApi with a given state.
|
|
17
|
+
*/
|
|
18
|
+
constructor(state: StateModule);
|
|
19
|
+
/**
|
|
20
|
+
* Get all top-level page objects.
|
|
21
|
+
* @handleName getRootPages
|
|
22
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
23
|
+
* @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)
|
|
24
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
25
|
+
* @description Get all top-level page objects.
|
|
26
|
+
*/
|
|
27
|
+
getRootPages(langCode?: string): Promise<IPagesEntity[] | IError>;
|
|
28
|
+
/**
|
|
29
|
+
* Get all page objects with product information as an array.
|
|
30
|
+
* @handleName getPages
|
|
31
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
32
|
+
* @returns {Promise<IPagesEntity[] | IError>} Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data).
|
|
33
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
34
|
+
* @description Get all page objects with product information as an array.
|
|
35
|
+
*/
|
|
36
|
+
getPages(langCode?: string): Promise<IPagesEntity[] | IError>;
|
|
37
|
+
/**
|
|
38
|
+
* Get page object with information about forms, blocks, menus, linked to the page.
|
|
39
|
+
* @handleName getPageById
|
|
40
|
+
* @param {number} id - The unique identifier of the page to be fetched. Example: 1.
|
|
41
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
42
|
+
* @returns {Promise<IPagesEntity | IError>} Returns PageEntity object
|
|
43
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
44
|
+
* @description Get page object with information about forms, blocks, menus, linked to the page.
|
|
45
|
+
*/
|
|
46
|
+
getPageById(id: number, langCode?: string): Promise<IPagesEntity | IError>;
|
|
47
|
+
/**
|
|
48
|
+
* Get page object with information about forms, blocks, menus, linked to the page by URL.
|
|
49
|
+
* @handleName getPageByUrl
|
|
50
|
+
* @param {string} url - Page URL. Example: "about".
|
|
51
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
52
|
+
* @returns {Promise<IPagesEntity | IError>} Returns PageEntity object
|
|
53
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
54
|
+
* @description Get page object with information about forms, blocks, menus, linked to the page by URL.
|
|
55
|
+
*/
|
|
56
|
+
getPageByUrl(url: string, langCode?: string): Promise<IPagesEntity | IError>;
|
|
57
|
+
/**
|
|
58
|
+
* Get child pages object with information as an array.
|
|
59
|
+
* @handleName getChildPagesByParentUrl
|
|
60
|
+
* @param {string} url - The URL of the parent page for which child pages are to be fetched. Example: "about/our-team".
|
|
61
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
62
|
+
* @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
|
|
63
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
64
|
+
* @description Get child pages object with information as an array.
|
|
65
|
+
*/
|
|
66
|
+
getChildPagesByParentUrl(url: string, langCode?: string): Promise<IPagesEntity[] | IError>;
|
|
67
|
+
/**
|
|
68
|
+
* Get all blocks by page url.
|
|
69
|
+
* @handleName getBlocksByPageUrl
|
|
70
|
+
* @param {string} url - Page URL. Example: "about".
|
|
71
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
72
|
+
* @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
|
|
73
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
74
|
+
* @description Get all blocks by page url.
|
|
75
|
+
*/
|
|
76
|
+
getBlocksByPageUrl(url: string, langCode?: string): Promise<IPositionBlock[] | IError>;
|
|
77
|
+
/**
|
|
78
|
+
* Get settings for the page.
|
|
79
|
+
* @handleName getConfigPageByUrl
|
|
80
|
+
* @param {string} url - Page URL. Example: "about".
|
|
81
|
+
* @returns {Promise<IPageConfig | IError>} Returns a ConfigPage object with page display settings
|
|
82
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
83
|
+
* @description Get settings for the page.
|
|
84
|
+
*/
|
|
85
|
+
getConfigPageByUrl(url: string): Promise<IPageConfig | IError>;
|
|
86
|
+
/**
|
|
87
|
+
* Quick search for page objects with limited output.
|
|
88
|
+
* @handleName searchPage
|
|
89
|
+
* @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".
|
|
90
|
+
* @param {string} [url] - Page URL. Example: "catalog".
|
|
91
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
92
|
+
* @returns {Promise<IPagesEntity[] | IError>} Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
|
|
93
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
94
|
+
* @description Quick search for page objects with limited output.
|
|
95
|
+
*/
|
|
96
|
+
searchPage(name: string, url?: string, langCode?: string): Promise<IPagesEntity[] | IError>;
|
|
97
|
+
/**
|
|
98
|
+
* Add template data to pages
|
|
99
|
+
* @handleName addTemplateToPages
|
|
100
|
+
* @param {IPagesEntity[]} data - An array of page objects (IPagesEntity[]) to which template data will be added.
|
|
101
|
+
* @example
|
|
102
|
+
[
|
|
103
|
+
{
|
|
104
|
+
"id": 8,
|
|
105
|
+
"parentId": null,
|
|
106
|
+
"moduleFormConfigs": [],
|
|
107
|
+
"pageUrl": "blog",
|
|
108
|
+
"depth": 0,
|
|
109
|
+
"localizeInfos": {
|
|
110
|
+
"title": "Blog",
|
|
111
|
+
"menuTitle": "Blog",
|
|
112
|
+
"htmlContent": "",
|
|
113
|
+
"plainContent": "",
|
|
114
|
+
},
|
|
115
|
+
"isVisible": true,
|
|
116
|
+
"forms": [],
|
|
117
|
+
"blocks": [],
|
|
118
|
+
"type": "common_page",
|
|
119
|
+
"templateIdentifier": "template",
|
|
120
|
+
"attributeSetIdentifier": "page",
|
|
121
|
+
"attributeValues": {},
|
|
122
|
+
"isSync": true,
|
|
123
|
+
"template": {
|
|
124
|
+
"id": 4,
|
|
125
|
+
"attributeSetIdentifier": null,
|
|
126
|
+
"title": "Template",
|
|
127
|
+
"generalTypeId": 4,
|
|
128
|
+
"identifier": "template",
|
|
129
|
+
"version": 0,
|
|
130
|
+
"generalTypeName": "catalog_page",
|
|
131
|
+
"attributeValues": {},
|
|
132
|
+
"position": 1,
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
* @returns {Promise<any | IError>} An array of page objects with template data added
|
|
137
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
138
|
+
* @description Add template data to pages. Optimized to avoid N+1 query problem by fetching only unique templates in parallel.
|
|
139
|
+
* For example, if 100 pages use 3 different templates, this method makes 3 requests instead of 100.
|
|
140
|
+
*/
|
|
141
|
+
protected addTemplateToPages(data: IPagesEntity[]): Promise<any | IError>;
|
|
142
|
+
/**
|
|
143
|
+
* Add template data to page by page templateIdentifier
|
|
144
|
+
* @handleName addTemplateToPage
|
|
145
|
+
* @param {IPagesEntity} data - Page object (IPagesEntity) to which template data will be added.
|
|
146
|
+
* @returns {Promise<any | IError>} An array of page objects with template data added
|
|
147
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
148
|
+
* @description Add template data to page by page templateIdentifier
|
|
149
|
+
*/
|
|
150
|
+
protected addTemplateToPage(data: IPagesEntity): Promise<any | IError>;
|
|
151
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/* eslint-disable jsdoc/reject-any-type */
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
const asyncModules_1 = __importDefault(require("../base/asyncModules"));
|
|
9
|
+
const templatesApi_1 = __importDefault(require("../templates/templatesApi"));
|
|
10
|
+
const pagesSchemas_1 = require("./pagesSchemas");
|
|
11
|
+
/**
|
|
12
|
+
* Controllers for working with page objects, including catalog pages
|
|
13
|
+
* @handle /api/content/pages
|
|
14
|
+
* @description Controllers for working with page objects, including catalog pages
|
|
15
|
+
*/
|
|
16
|
+
class PagesApi extends asyncModules_1.default {
|
|
17
|
+
/**
|
|
18
|
+
* Constructor
|
|
19
|
+
* @param {StateModule} state - The state module.
|
|
20
|
+
* @description Constructor initializes the PageApi with a given state.
|
|
21
|
+
*/
|
|
22
|
+
constructor(state) {
|
|
23
|
+
super(state);
|
|
24
|
+
this._url = state.url + '/api/content/pages';
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get all top-level page objects.
|
|
28
|
+
* @handleName getRootPages
|
|
29
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
30
|
+
* @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)
|
|
31
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
32
|
+
* @description Get all top-level page objects.
|
|
33
|
+
*/
|
|
34
|
+
async getRootPages(langCode = this.state.lang) {
|
|
35
|
+
// Fetch data from the server using a GET request to retrieve root pages for the specified language code
|
|
36
|
+
const data = await this._fetchGet(`/root?langCode=${langCode}`);
|
|
37
|
+
// Validate response if validation is enabled
|
|
38
|
+
const validated = this._validateResponse(data, pagesSchemas_1.PagesResponseSchema);
|
|
39
|
+
// Add template information to each page in the fetched root pages data
|
|
40
|
+
const withTemplate = await this.addTemplateToPages(validated);
|
|
41
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
42
|
+
return this._normalizeData(withTemplate, langCode);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get all page objects with product information as an array.
|
|
46
|
+
* @handleName getPages
|
|
47
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
48
|
+
* @returns {Promise<IPagesEntity[] | IError>} Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data).
|
|
49
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
50
|
+
* @description Get all page objects with product information as an array.
|
|
51
|
+
*/
|
|
52
|
+
async getPages(langCode = this.state.lang) {
|
|
53
|
+
// Fetch data from the server using a GET request to retrieve all pages for the specified language code
|
|
54
|
+
const data = await this._fetchGet(`?langCode=${langCode}`);
|
|
55
|
+
// Validate response if validation is enabled
|
|
56
|
+
const validated = this._validateResponse(data, pagesSchemas_1.PagesResponseSchema);
|
|
57
|
+
// Add template information to each page in the fetched data
|
|
58
|
+
const withTemplate = await this.addTemplateToPages(validated);
|
|
59
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
60
|
+
return this._normalizeData(withTemplate, langCode);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get page object with information about forms, blocks, menus, linked to the page.
|
|
64
|
+
* @handleName getPageById
|
|
65
|
+
* @param {number} id - The unique identifier of the page to be fetched. Example: 1.
|
|
66
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
67
|
+
* @returns {Promise<IPagesEntity | IError>} Returns PageEntity object
|
|
68
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
69
|
+
* @description Get page object with information about forms, blocks, menus, linked to the page.
|
|
70
|
+
*/
|
|
71
|
+
async getPageById(id, langCode = this.state.lang) {
|
|
72
|
+
// Fetch data from the server using a GET request to retrieve page details by ID and language code
|
|
73
|
+
const data = await this._fetchGet(`/${id}?langCode=${langCode}`);
|
|
74
|
+
// Validate response if validation is enabled
|
|
75
|
+
const validated = this._validateResponse(data, pagesSchemas_1.PageEntitySchema);
|
|
76
|
+
// Add template information to the fetched page data
|
|
77
|
+
const withTemplate = await this.addTemplateToPage(validated);
|
|
78
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
79
|
+
return this._normalizeData(withTemplate, langCode);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get page object with information about forms, blocks, menus, linked to the page by URL.
|
|
83
|
+
* @handleName getPageByUrl
|
|
84
|
+
* @param {string} url - Page URL. Example: "about".
|
|
85
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
86
|
+
* @returns {Promise<IPagesEntity | IError>} Returns PageEntity object
|
|
87
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
88
|
+
* @description Get page object with information about forms, blocks, menus, linked to the page by URL.
|
|
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 = this._validateResponse(data, pagesSchemas_1.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
|
+
*/
|
|
109
|
+
async getChildPagesByParentUrl(url, langCode = this.state.lang) {
|
|
110
|
+
// Fetch data from the server using a GET request to retrieve child pages for the specified parent URL and language code
|
|
111
|
+
const data = await this._fetchGet(`/${url}/children?langCode=${langCode}`);
|
|
112
|
+
// Validate response if validation is enabled
|
|
113
|
+
const validated = this._validateResponse(data, pagesSchemas_1.PagesResponseSchema);
|
|
114
|
+
// Add template information to each of the fetched child pages
|
|
115
|
+
const withTemplate = await this.addTemplateToPages(validated);
|
|
116
|
+
// Normalize the result data and return it; ensures consistent structure or handles errors
|
|
117
|
+
return this._normalizeData(withTemplate, langCode);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get all blocks by page url.
|
|
121
|
+
* @handleName getBlocksByPageUrl
|
|
122
|
+
* @param {string} url - Page URL. Example: "about".
|
|
123
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
124
|
+
* @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
|
|
125
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
126
|
+
* @description Get all blocks by page url.
|
|
127
|
+
*/
|
|
128
|
+
async getBlocksByPageUrl(url, langCode = this.state.lang) {
|
|
129
|
+
const response = await this._fetchGet(`/${url}/blocks?langCode=${langCode}`);
|
|
130
|
+
// Normalize the fetched response data
|
|
131
|
+
const normalizeResponse = this._normalizeData(response);
|
|
132
|
+
// Iterate over each item in the normalized response
|
|
133
|
+
normalizeResponse.map((item) => {
|
|
134
|
+
const customSettings = item.customSettings;
|
|
135
|
+
// Check if customSettings contains 'productConfig' property
|
|
136
|
+
if (customSettings &&
|
|
137
|
+
Object.prototype.hasOwnProperty.call(customSettings, 'productConfig')) {
|
|
138
|
+
// If 'countElementsPerRow' exists, set it on the item
|
|
139
|
+
if (customSettings.productConfig.countElementsPerRow)
|
|
140
|
+
item.countElementsPerRow =
|
|
141
|
+
+customSettings.productConfig.countElementsPerRow;
|
|
142
|
+
// If 'quantity' exists, set it on the item
|
|
143
|
+
if (customSettings.productConfig.quantity)
|
|
144
|
+
item.quantity = +customSettings.productConfig.quantity;
|
|
145
|
+
}
|
|
146
|
+
// Remove unnecessary properties from the item
|
|
147
|
+
delete item.customSettings;
|
|
148
|
+
delete item.attributesSetIdentifier;
|
|
149
|
+
// Return the modified item
|
|
150
|
+
return item;
|
|
151
|
+
});
|
|
152
|
+
// Check if traffic limit is not set
|
|
153
|
+
if (!this.state.traficLimit) {
|
|
154
|
+
// Create an instance of 'StaffModule' with the current state
|
|
155
|
+
const staffModule = new StaffModule(this.state);
|
|
156
|
+
// If the block type is 'similar_products_block', fetch similar products
|
|
157
|
+
if (normalizeResponse.type === 'similar_products_block') {
|
|
158
|
+
try {
|
|
159
|
+
await staffModule
|
|
160
|
+
.getSimilarProducts(normalizeResponse.identifier, langCode)
|
|
161
|
+
.then((result) => {
|
|
162
|
+
normalizeResponse.similarProducts = this._normalizeData(result);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Handle errors by setting an empty array
|
|
167
|
+
normalizeResponse.similarProducts = [];
|
|
168
|
+
}
|
|
169
|
+
// If the block type is 'product_block', fetch products
|
|
170
|
+
}
|
|
171
|
+
else if (normalizeResponse.type === 'product_block') {
|
|
172
|
+
try {
|
|
173
|
+
await staffModule
|
|
174
|
+
.getProductsByBlockMarker(normalizeResponse.identifier, langCode)
|
|
175
|
+
.then((result) => {
|
|
176
|
+
normalizeResponse.products = this._normalizeData(result);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Handle errors by setting an empty array
|
|
181
|
+
normalizeResponse.products = [];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Return the final normalized response
|
|
186
|
+
return this._normalizeData(normalizeResponse);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get settings for the page.
|
|
190
|
+
* @handleName getConfigPageByUrl
|
|
191
|
+
* @param {string} url - Page URL. Example: "about".
|
|
192
|
+
* @returns {Promise<IPageConfig | IError>} Returns a ConfigPage object with page display settings
|
|
193
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
194
|
+
* @description Get settings for the page.
|
|
195
|
+
*/
|
|
196
|
+
async getConfigPageByUrl(url) {
|
|
197
|
+
// Fetch data from the server using a GET request to retrieve forms for the specified page URL and language code
|
|
198
|
+
const result = await this._fetchGet(`/${url}/config`);
|
|
199
|
+
// Validate response if validation is enabled
|
|
200
|
+
const validated = this._validateResponse(result, pagesSchemas_1.PageConfigSchema);
|
|
201
|
+
// return fetched data
|
|
202
|
+
return validated;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Quick search for page objects with limited output.
|
|
206
|
+
* @handleName searchPage
|
|
207
|
+
* @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".
|
|
208
|
+
* @param {string} [url] - Page URL. Example: "catalog".
|
|
209
|
+
* @param {string} [langCode] - Language code. Default: "en_US".
|
|
210
|
+
* @returns {Promise<IPagesEntity[] | IError>} Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
|
|
211
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
212
|
+
* @description Quick search for page objects with limited output.
|
|
213
|
+
*/
|
|
214
|
+
async searchPage(name, url, langCode = this.state.lang) {
|
|
215
|
+
// Fetch data from the server using a GET request to perform a quick search by page name and language code
|
|
216
|
+
const data = await this._fetchGet(`/quick/search?${url && 'url=' + url}&lang=${langCode}&name=${name}`);
|
|
217
|
+
// /quick/search?url=catalog&langCode=en_US&name=cat
|
|
218
|
+
// Check if there is no traffic limit set in the state
|
|
219
|
+
if (!this.state.traficLimit) {
|
|
220
|
+
// Initialize an empty array to store detailed page information
|
|
221
|
+
const pageList = [];
|
|
222
|
+
// Use Promise.all to fetch detailed information for each page concurrently
|
|
223
|
+
await Promise.all(data.map(async (page) => {
|
|
224
|
+
// Fetch detailed page information by page ID and push it to pageList
|
|
225
|
+
await this.getPageById(page.id, langCode).then((result) => {
|
|
226
|
+
pageList.push(result);
|
|
227
|
+
});
|
|
228
|
+
}));
|
|
229
|
+
// Add templates to the fetched pages
|
|
230
|
+
const withTemplate = await this.addTemplateToPages(pageList);
|
|
231
|
+
// Post-process the data and return it; ensures consistent structure or handles errors
|
|
232
|
+
return this._dataPostProcess(withTemplate, langCode);
|
|
233
|
+
}
|
|
234
|
+
// If there is a traffic limit, add templates to the initially fetched data without fetching detailed information
|
|
235
|
+
const withTemplate = await this.addTemplateToPages(data);
|
|
236
|
+
// Normalize the data and return it; ensures consistent structure or handles errors
|
|
237
|
+
return this._normalizeData(withTemplate, langCode);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Add template data to pages
|
|
241
|
+
* @handleName addTemplateToPages
|
|
242
|
+
* @param {IPagesEntity[]} data - An array of page objects (IPagesEntity[]) to which template data will be added.
|
|
243
|
+
* @example
|
|
244
|
+
[
|
|
245
|
+
{
|
|
246
|
+
"id": 8,
|
|
247
|
+
"parentId": null,
|
|
248
|
+
"moduleFormConfigs": [],
|
|
249
|
+
"pageUrl": "blog",
|
|
250
|
+
"depth": 0,
|
|
251
|
+
"localizeInfos": {
|
|
252
|
+
"title": "Blog",
|
|
253
|
+
"menuTitle": "Blog",
|
|
254
|
+
"htmlContent": "",
|
|
255
|
+
"plainContent": "",
|
|
256
|
+
},
|
|
257
|
+
"isVisible": true,
|
|
258
|
+
"forms": [],
|
|
259
|
+
"blocks": [],
|
|
260
|
+
"type": "common_page",
|
|
261
|
+
"templateIdentifier": "template",
|
|
262
|
+
"attributeSetIdentifier": "page",
|
|
263
|
+
"attributeValues": {},
|
|
264
|
+
"isSync": true,
|
|
265
|
+
"template": {
|
|
266
|
+
"id": 4,
|
|
267
|
+
"attributeSetIdentifier": null,
|
|
268
|
+
"title": "Template",
|
|
269
|
+
"generalTypeId": 4,
|
|
270
|
+
"identifier": "template",
|
|
271
|
+
"version": 0,
|
|
272
|
+
"generalTypeName": "catalog_page",
|
|
273
|
+
"attributeValues": {},
|
|
274
|
+
"position": 1,
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
]
|
|
278
|
+
* @returns {Promise<any | IError>} An array of page objects with template data added
|
|
279
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
280
|
+
* @description Add template data to pages. Optimized to avoid N+1 query problem by fetching only unique templates in parallel.
|
|
281
|
+
* For example, if 100 pages use 3 different templates, this method makes 3 requests instead of 100.
|
|
282
|
+
*/
|
|
283
|
+
async addTemplateToPages(data) {
|
|
284
|
+
// Step 1: Collect unique templateIdentifiers from all pages
|
|
285
|
+
const uniqueIdentifiers = [
|
|
286
|
+
...new Set(data
|
|
287
|
+
.filter((page) => 'templateIdentifier' in page &&
|
|
288
|
+
page.templateIdentifier !== null &&
|
|
289
|
+
page.templateIdentifier !== '')
|
|
290
|
+
.map((page) => page.templateIdentifier)),
|
|
291
|
+
];
|
|
292
|
+
// Step 2: If no templates needed, return pages as-is
|
|
293
|
+
if (uniqueIdentifiers.length === 0) {
|
|
294
|
+
return data;
|
|
295
|
+
}
|
|
296
|
+
// Step 3: Fetch unique templates in parallel (not N queries, but unique count queries)
|
|
297
|
+
const Templates = new templatesApi_1.default(this.state);
|
|
298
|
+
const templatePromises = uniqueIdentifiers.map((identifier) => Templates.getTemplateByMarker(identifier).catch((error) => {
|
|
299
|
+
// eslint-disable-next-line no-undef, no-console
|
|
300
|
+
console.error(`Template fetch error for ${identifier}: `, error);
|
|
301
|
+
return null; // Return null for failed templates
|
|
302
|
+
}));
|
|
303
|
+
const templates = await Promise.all(templatePromises);
|
|
304
|
+
// Step 4: Create a Map for O(1) template lookup
|
|
305
|
+
const templateMap = new Map();
|
|
306
|
+
templates.forEach((template, index) => {
|
|
307
|
+
if (template !== null) {
|
|
308
|
+
templateMap.set(uniqueIdentifiers[index], template);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
// Step 5: Apply templates to pages (no additional API calls)
|
|
312
|
+
return data.map((page) => {
|
|
313
|
+
if ('templateIdentifier' in page &&
|
|
314
|
+
page.templateIdentifier !== null &&
|
|
315
|
+
page.templateIdentifier !== '') {
|
|
316
|
+
const template = templateMap.get(page.templateIdentifier);
|
|
317
|
+
if (template) {
|
|
318
|
+
return {
|
|
319
|
+
...page,
|
|
320
|
+
template,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// Return page without template if identifier is missing or template not found
|
|
325
|
+
return page;
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Add template data to page by page templateIdentifier
|
|
330
|
+
* @handleName addTemplateToPage
|
|
331
|
+
* @param {IPagesEntity} data - Page object (IPagesEntity) to which template data will be added.
|
|
332
|
+
* @returns {Promise<any | IError>} An array of page objects with template data added
|
|
333
|
+
* @throws {IError} When isShell=false and an error occurs during the fetch
|
|
334
|
+
* @description Add template data to page by page templateIdentifier
|
|
335
|
+
*/
|
|
336
|
+
async addTemplateToPage(data) {
|
|
337
|
+
// Check if 'templateIdentifier' exists in 'data' and is not null or an empty string
|
|
338
|
+
if ('templateIdentifier' in data &&
|
|
339
|
+
data.templateIdentifier !== null &&
|
|
340
|
+
data.templateIdentifier !== '') {
|
|
341
|
+
// Destructure 'templateIdentifier' from 'data'
|
|
342
|
+
const { templateIdentifier } = data;
|
|
343
|
+
try {
|
|
344
|
+
// Create a new instance of templatesApi with the current state
|
|
345
|
+
const Templates = new templatesApi_1.default(this.state);
|
|
346
|
+
// Fetch the template using the 'templateIdentifier'
|
|
347
|
+
const result = await Templates.getTemplateByMarker(templateIdentifier);
|
|
348
|
+
// Return the original data object with the fetched template added
|
|
349
|
+
return {
|
|
350
|
+
...data,
|
|
351
|
+
template: result,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
// Log any errors that occur during the template fetching process
|
|
356
|
+
// eslint-disable-next-line no-undef, no-console
|
|
357
|
+
console.error('Template fetch error: ', error);
|
|
358
|
+
// Return the original data object unchanged if an error occurs
|
|
359
|
+
return data;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
// If 'templateIdentifier' doesn't exist or is invalid, return the original data
|
|
364
|
+
return data;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
exports.default = PagesApi;
|
|
369
|
+
/**
|
|
370
|
+
* Helper module for working with blocks, similar products and product blocks
|
|
371
|
+
* @description Internal module for fetching products and similar products for blocks
|
|
372
|
+
*/
|
|
373
|
+
class StaffModule extends asyncModules_1.default {
|
|
374
|
+
constructor(state) {
|
|
375
|
+
super(state); // Call parent constructor
|
|
376
|
+
this._url = state.url + '/api/content/blocks'; // Set URL for content blocks
|
|
377
|
+
}
|
|
378
|
+
// Method to fetch similar products by marker
|
|
379
|
+
async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
380
|
+
// Fetch similar products from the server
|
|
381
|
+
const result = await this._fetchGet(`/${marker}/similar-products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
|
|
382
|
+
return this._normalizeData(result.items);
|
|
383
|
+
}
|
|
384
|
+
// Method to fetch products by block marker
|
|
385
|
+
async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
|
|
386
|
+
// Fetch products from the server
|
|
387
|
+
const result = await this._fetchGet(`/${marker}/products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
|
|
388
|
+
return this._normalizeData(result.items);
|
|
389
|
+
}
|
|
390
|
+
}
|