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.
Files changed (222) hide show
  1. package/README.md +2 -0
  2. package/changelog.md +56 -1
  3. package/dist/admins/adminsApi.d.ts +15 -1
  4. package/dist/admins/adminsApi.js +29 -0
  5. package/dist/admins/adminsInterfaces.d.ts +37 -1
  6. package/dist/base/lazySchema.d.ts +15 -0
  7. package/dist/base/lazySchema.js +20 -0
  8. package/dist/discounts/discountsApi.d.ts +14 -1
  9. package/dist/discounts/discountsApi.js +21 -0
  10. package/dist/discounts/discountsInterfaces.d.ts +27 -1
  11. package/dist/filters/filtersInterfaces.d.ts +2 -2
  12. package/dist/filters/filtersSchemas.d.ts +1 -1
  13. package/dist/filters/filtersSchemas.js +4 -1
  14. package/dist/forms-data/formsDataApi.d.ts +14 -1
  15. package/dist/forms-data/formsDataApi.js +21 -0
  16. package/dist/forms-data/formsDataInterfaces.d.ts +74 -1
  17. package/dist/index.d.ts +4 -0
  18. package/dist/index.js +3 -0
  19. package/dist/orders/ordersApi.d.ts +15 -1
  20. package/dist/orders/ordersApi.js +22 -0
  21. package/dist/orders/ordersInterfaces.d.ts +27 -1
  22. package/dist/pages/pagesApi.d.ts +14 -1
  23. package/dist/pages/pagesApi.js +21 -0
  24. package/dist/pages/pagesInterfaces.d.ts +38 -1
  25. package/dist/payments/paymentsInterfaces.d.ts +2 -2
  26. package/dist/products/productsInterfaces.d.ts +1 -1
  27. package/dist/search/searchApi.d.ts +35 -0
  28. package/dist/search/searchApi.js +86 -0
  29. package/dist/search/searchInterfaces.d.ts +94 -0
  30. package/dist/search/searchInterfaces.js +2 -0
  31. package/dist/search/searchSchemas.d.ts +73 -0
  32. package/dist/search/searchSchemas.js +44 -0
  33. package/dist/templates-preview/templatesPreviewInterfaces.d.ts +0 -2
  34. package/dist/templates-preview/templatesPreviewSchemas.d.ts +0 -2
  35. package/dist/templates-preview/templatesPreviewSchemas.js +0 -1
  36. package/dist/types.d.ts +35 -0
  37. package/dist/types.js +2 -0
  38. package/dist/users/usersApi.d.ts +15 -1
  39. package/dist/users/usersApi.js +22 -0
  40. package/dist/users/usersInterfaces.d.ts +39 -1
  41. package/dist/web-socket/lazySocket.d.ts +18 -0
  42. package/dist/web-socket/lazySocket.js +70 -0
  43. package/esm/admins/adminsApi.d.ts +66 -0
  44. package/esm/admins/adminsApi.js +90 -0
  45. package/esm/admins/adminsInterfaces.d.ts +137 -0
  46. package/esm/admins/adminsInterfaces.js +1 -0
  47. package/esm/admins/adminsSchemas.d.ts +48 -0
  48. package/esm/admins/adminsSchemas.js +31 -0
  49. package/esm/attribute-sets/attributeSetsApi.d.ts +67 -0
  50. package/esm/attribute-sets/attributeSetsApi.js +97 -0
  51. package/esm/attribute-sets/attributeSetsInterfaces.d.ts +285 -0
  52. package/esm/attribute-sets/attributeSetsInterfaces.js +1 -0
  53. package/esm/attribute-sets/attributeSetsSchemas.d.ts +84 -0
  54. package/esm/attribute-sets/attributeSetsSchemas.js +66 -0
  55. package/esm/auth-provider/authProviderApi.d.ts +262 -0
  56. package/esm/auth-provider/authProviderApi.js +362 -0
  57. package/esm/auth-provider/authProviderSchemas.d.ts +124 -0
  58. package/esm/auth-provider/authProviderSchemas.js +92 -0
  59. package/esm/auth-provider/authProvidersInterfaces.d.ts +430 -0
  60. package/esm/auth-provider/authProvidersInterfaces.js +1 -0
  61. package/esm/base/asyncModules.d.ts +123 -0
  62. package/esm/base/asyncModules.js +382 -0
  63. package/esm/base/lazySchema.d.ts +15 -0
  64. package/esm/base/lazySchema.js +17 -0
  65. package/esm/base/stateModule.d.ts +35 -0
  66. package/esm/base/stateModule.js +51 -0
  67. package/esm/base/syncModules.d.ts +245 -0
  68. package/esm/base/syncModules.js +555 -0
  69. package/esm/base/timeIntervals.d.ts +95 -0
  70. package/esm/base/timeIntervals.js +317 -0
  71. package/esm/base/utils.d.ts +354 -0
  72. package/esm/base/utils.js +1 -0
  73. package/esm/base/validation.d.ts +98 -0
  74. package/esm/base/validation.js +118 -0
  75. package/esm/blocks/blocksApi.d.ts +252 -0
  76. package/esm/blocks/blocksApi.js +394 -0
  77. package/esm/blocks/blocksInterfaces.d.ts +361 -0
  78. package/esm/blocks/blocksInterfaces.js +1 -0
  79. package/esm/blocks/blocksSchemas.d.ts +213 -0
  80. package/esm/blocks/blocksSchemas.js +40 -0
  81. package/esm/discounts/discountsApi.d.ts +94 -0
  82. package/esm/discounts/discountsApi.js +136 -0
  83. package/esm/discounts/discountsInterfaces.d.ts +293 -0
  84. package/esm/discounts/discountsInterfaces.js +1 -0
  85. package/esm/events/eventsApi.d.ts +108 -0
  86. package/esm/events/eventsApi.js +141 -0
  87. package/esm/events/eventsInterfaces.d.ts +176 -0
  88. package/esm/events/eventsInterfaces.js +1 -0
  89. package/esm/file-uploading/fileUploadingApi.d.ts +91 -0
  90. package/esm/file-uploading/fileUploadingApi.js +127 -0
  91. package/esm/file-uploading/fileUploadingInterfaces.d.ts +116 -0
  92. package/esm/file-uploading/fileUploadingInterfaces.js +1 -0
  93. package/esm/file-uploading/fileUploadingSchemas.d.ts +24 -0
  94. package/esm/file-uploading/fileUploadingSchemas.js +19 -0
  95. package/esm/filters/filtersApi.d.ts +32 -0
  96. package/esm/filters/filtersApi.js +36 -0
  97. package/esm/filters/filtersInterfaces.d.ts +56 -0
  98. package/esm/filters/filtersInterfaces.js +1 -0
  99. package/esm/filters/filtersSchemas.d.ts +32 -0
  100. package/esm/filters/filtersSchemas.js +29 -0
  101. package/esm/forms/formsApi.d.ts +44 -0
  102. package/esm/forms/formsApi.js +54 -0
  103. package/esm/forms/formsInterfaces.d.ts +237 -0
  104. package/esm/forms/formsInterfaces.js +1 -0
  105. package/esm/forms/formsSchemas.d.ts +56 -0
  106. package/esm/forms/formsSchemas.js +32 -0
  107. package/esm/forms-data/formsDataApi.d.ts +124 -0
  108. package/esm/forms-data/formsDataApi.js +210 -0
  109. package/esm/forms-data/formsDataInterfaces.d.ts +670 -0
  110. package/esm/forms-data/formsDataInterfaces.js +1 -0
  111. package/esm/forms-data/formsDataSchemas.d.ts +107 -0
  112. package/esm/forms-data/formsDataSchemas.js +83 -0
  113. package/esm/general-types/generalTypesApi.d.ts +29 -0
  114. package/esm/general-types/generalTypesApi.js +34 -0
  115. package/esm/general-types/generalTypesInterfaces.d.ts +29 -0
  116. package/esm/general-types/generalTypesInterfaces.js +1 -0
  117. package/esm/general-types/generalTypesSchemas.d.ts +68 -0
  118. package/esm/general-types/generalTypesSchemas.js +42 -0
  119. package/esm/index.d.ts +143 -0
  120. package/esm/index.js +124 -0
  121. package/esm/integration-collections/integrationCollectionsApi.d.ts +172 -0
  122. package/esm/integration-collections/integrationCollectionsApi.js +224 -0
  123. package/esm/integration-collections/integrationCollectionsInterfaces.d.ts +317 -0
  124. package/esm/integration-collections/integrationCollectionsInterfaces.js +1 -0
  125. package/esm/integration-collections/integrationCollectionsSchemas.d.ts +84 -0
  126. package/esm/integration-collections/integrationCollectionsSchemas.js +60 -0
  127. package/esm/locales/localesApi.d.ts +28 -0
  128. package/esm/locales/localesApi.js +33 -0
  129. package/esm/locales/localesInterfaces.d.ts +40 -0
  130. package/esm/locales/localesInterfaces.js +1 -0
  131. package/esm/locales/localesSchemas.d.ts +32 -0
  132. package/esm/locales/localesSchemas.js +23 -0
  133. package/esm/menus/menusApi.d.ts +30 -0
  134. package/esm/menus/menusApi.js +35 -0
  135. package/esm/menus/menusInterfaces.d.ts +87 -0
  136. package/esm/menus/menusInterfaces.js +2 -0
  137. package/esm/menus/menusSchemas.d.ts +16 -0
  138. package/esm/menus/menusSchemas.js +25 -0
  139. package/esm/orders/ordersApi.d.ts +213 -0
  140. package/esm/orders/ordersApi.js +288 -0
  141. package/esm/orders/ordersInterfaces.d.ts +763 -0
  142. package/esm/orders/ordersInterfaces.js +1 -0
  143. package/esm/orders/ordersSchemas.d.ts +312 -0
  144. package/esm/orders/ordersSchemas.js +171 -0
  145. package/esm/package.json +4 -0
  146. package/esm/pages/pagesApi.d.ts +173 -0
  147. package/esm/pages/pagesApi.js +414 -0
  148. package/esm/pages/pagesInterfaces.d.ts +344 -0
  149. package/esm/pages/pagesInterfaces.js +1 -0
  150. package/esm/pages/pagesSchemas.d.ts +121 -0
  151. package/esm/pages/pagesSchemas.js +60 -0
  152. package/esm/payments/paymentsApi.d.ts +88 -0
  153. package/esm/payments/paymentsApi.js +122 -0
  154. package/esm/payments/paymentsInterfaces.d.ts +189 -0
  155. package/esm/payments/paymentsInterfaces.js +1 -0
  156. package/esm/payments/paymentsSchemas.d.ts +94 -0
  157. package/esm/payments/paymentsSchemas.js +53 -0
  158. package/esm/product-statuses/productStatusesApi.d.ts +50 -0
  159. package/esm/product-statuses/productStatusesApi.js +68 -0
  160. package/esm/product-statuses/productStatusesInterfaces.d.ts +62 -0
  161. package/esm/product-statuses/productStatusesInterfaces.js +1 -0
  162. package/esm/product-statuses/productStatusesSchemas.d.ts +34 -0
  163. package/esm/product-statuses/productStatusesSchemas.js +27 -0
  164. package/esm/products/productsApi.d.ts +366 -0
  165. package/esm/products/productsApi.js +468 -0
  166. package/esm/products/productsInterfaces.d.ts +723 -0
  167. package/esm/products/productsInterfaces.js +1 -0
  168. package/esm/products/productsSchemas.d.ts +234 -0
  169. package/esm/products/productsSchemas.js +121 -0
  170. package/esm/search/searchApi.d.ts +35 -0
  171. package/esm/search/searchApi.js +47 -0
  172. package/esm/search/searchInterfaces.d.ts +94 -0
  173. package/esm/search/searchInterfaces.js +1 -0
  174. package/esm/search/searchSchemas.d.ts +73 -0
  175. package/esm/search/searchSchemas.js +41 -0
  176. package/esm/sitemap/sitemapApi.d.ts +37 -0
  177. package/esm/sitemap/sitemapApi.js +41 -0
  178. package/esm/sitemap/sitemapInterfaces.d.ts +51 -0
  179. package/esm/sitemap/sitemapInterfaces.js +1 -0
  180. package/esm/subscriptions/subscriptionsApi.d.ts +74 -0
  181. package/esm/subscriptions/subscriptionsApi.js +90 -0
  182. package/esm/subscriptions/subscriptionsInterfaces.d.ts +111 -0
  183. package/esm/subscriptions/subscriptionsInterfaces.js +1 -0
  184. package/esm/subscriptions/subscriptionsSchemas.d.ts +46 -0
  185. package/esm/subscriptions/subscriptionsSchemas.js +38 -0
  186. package/esm/system/systemApi.d.ts +46 -0
  187. package/esm/system/systemApi.js +53 -0
  188. package/esm/system/systemInterfaces.d.ts +29 -0
  189. package/esm/system/systemInterfaces.js +1 -0
  190. package/esm/templates/templatesApi.d.ts +53 -0
  191. package/esm/templates/templatesApi.js +78 -0
  192. package/esm/templates/templatesInterfaces.d.ts +68 -0
  193. package/esm/templates/templatesInterfaces.js +1 -0
  194. package/esm/templates/templatesSchemas.d.ts +48 -0
  195. package/esm/templates/templatesSchemas.js +28 -0
  196. package/esm/templates-preview/templatesPreviewApi.d.ts +40 -0
  197. package/esm/templates-preview/templatesPreviewApi.js +50 -0
  198. package/esm/templates-preview/templatesPreviewInterfaces.d.ts +129 -0
  199. package/esm/templates-preview/templatesPreviewInterfaces.js +1 -0
  200. package/esm/templates-preview/templatesPreviewSchemas.d.ts +79 -0
  201. package/esm/templates-preview/templatesPreviewSchemas.js +43 -0
  202. package/esm/types.d.ts +35 -0
  203. package/esm/types.js +1 -0
  204. package/esm/user-activity/userActivityApi.d.ts +31 -0
  205. package/esm/user-activity/userActivityApi.js +37 -0
  206. package/esm/user-activity/userActivityInterfaces.d.ts +42 -0
  207. package/esm/user-activity/userActivityInterfaces.js +1 -0
  208. package/esm/users/usersApi.d.ts +249 -0
  209. package/esm/users/usersApi.js +312 -0
  210. package/esm/users/usersInterfaces.d.ts +419 -0
  211. package/esm/users/usersInterfaces.js +1 -0
  212. package/esm/users/usersSchemas.d.ts +72 -0
  213. package/esm/users/usersSchemas.js +55 -0
  214. package/esm/web-socket/lazySocket.d.ts +18 -0
  215. package/esm/web-socket/lazySocket.js +67 -0
  216. package/esm/web-socket/wsApi.d.ts +27 -0
  217. package/esm/web-socket/wsApi.js +43 -0
  218. package/esm/web-socket/wsInterfaces.d.ts +16 -0
  219. package/esm/web-socket/wsInterfaces.js +1 -0
  220. package/package.json +47 -2
  221. package/types.d.ts +1 -0
  222. package/types.js +1 -0
@@ -0,0 +1,414 @@
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
+ * Get settings for the page.
179
+ * @handleName getConfigPageByUrl
180
+ * @param {string} url - Page URL. Example: "about".
181
+ * @returns {Promise<IPageConfig | IError>} Returns a ConfigPage object with page display settings
182
+ * @throws {IError} When isShell=false and an error occurs during the fetch
183
+ * @description Get settings for the page.
184
+ * @see {@link https://js-sdk.oneentry.cloud/docs/pages/getConfigPageByUrl getConfigPageByUrl} documentation.
185
+ */
186
+ async getConfigPageByUrl(url) {
187
+ // Fetch data from the server using a GET request to retrieve forms for the specified page URL and language code
188
+ const result = await this._fetchGet(`/${url}/config`);
189
+ // Validate response if validation is enabled
190
+ const validated = await this._validateResponse(result, schema('PageConfigSchema'));
191
+ // return fetched data
192
+ return validated;
193
+ }
194
+ /**
195
+ * Quick search for page objects with limited output.
196
+ * @handleName searchPage
197
+ * @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".
198
+ * @param {string} [url] - Page URL. Example: "catalog".
199
+ * @param {string} [langCode] - Language code. Default: "en_US".
200
+ * @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)
201
+ * @throws {IError} When isShell=false and an error occurs during the fetch
202
+ * @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.
203
+ * @see {@link https://js-sdk.oneentry.cloud/docs/pages/searchPage searchPage} documentation.
204
+ */
205
+ async searchPage(name, url, langCode = this.state.lang) {
206
+ // Fetch data from the server using a GET request to perform a quick search by page name and language code
207
+ const urlPart = url ? `url=${encodeURIComponent(url)}&` : '';
208
+ const searchPages = await this._fetchGet(`/quick/search?${urlPart}lang=${encodeURIComponent(langCode)}&name=${encodeURIComponent(name)}`);
209
+ // /quick/search?url=catalog&langCode=en_US&name=cat
210
+ // Validate response if validation is enabled
211
+ const data = (await this._validateResponse(searchPages, schema('PageSearchResponseSchema')));
212
+ // Check if there is no traffic limit set in the state
213
+ if (!this.state.traficLimit && Array.isArray(data)) {
214
+ // Initialize an empty array to store detailed page information
215
+ const pageList = [];
216
+ // Use Promise.all to fetch detailed information for each page concurrently
217
+ await Promise.all(data.map(async (page) => {
218
+ // Fetch detailed page information by page ID and push it to pageList
219
+ await this.getPageById(page.id, langCode).then((result) => {
220
+ pageList.push(result);
221
+ });
222
+ }));
223
+ // Add templates to the fetched pages
224
+ const withTemplate = await this.addTemplateToPages(pageList);
225
+ // Normalize the data and return it; ensures consistent structure or handles errors
226
+ return this._normalizeData(withTemplate, langCode);
227
+ }
228
+ // With a traffic limit (or on an API error) return the quick search response as is:
229
+ // short cards carry no templateIdentifier, so there is nothing to attach a template to
230
+ return this._normalizeData(data, langCode);
231
+ }
232
+ /**
233
+ * Semantic (vector) search for pages.
234
+ * @handleName getPagesByVectorSearch
235
+ * @param {IPagesVectorSearch} body - Vector search body. Example: `{ queryText: "winter sale" }`.
236
+ * @param {string} [langCode] - Language code. Default: "en_US".
237
+ * @param {number} [offset] - Parameter for pagination. Default: 0.
238
+ * @param {number} [limit] - Parameter for pagination. Default: 30.
239
+ * @returns {Promise<IPagesResponse | IError>} Returns an object with an array of found pages and total count.
240
+ * @throws {IError} When isShell=false and an error occurs during the fetch
241
+ * @description This method performs a semantic (vector) search for pages.
242
+ * @see {@link https://js-sdk.oneentry.cloud/docs/pages/getPagesByVectorSearch getPagesByVectorSearch} documentation.
243
+ */
244
+ async getPagesByVectorSearch(body, langCode = this.state.lang, offset = 0, limit = 30) {
245
+ const query = {
246
+ langCode,
247
+ offset,
248
+ limit,
249
+ };
250
+ const result = await this._fetchPost(`/vector/search?` + this._queryParamsToString(query), body);
251
+ return this._normalizeData(result, langCode);
252
+ }
253
+ /**
254
+ * Add template data to pages
255
+ * @handleName addTemplateToPages
256
+ * @param {IPagesEntity[]} data - An array of page objects (IPagesEntity[]) to which template data will be added.
257
+ * @example
258
+ [
259
+ {
260
+ "id": 8,
261
+ "parentId": null,
262
+ "moduleFormConfigs": [],
263
+ "pageUrl": "blog",
264
+ "depth": 0,
265
+ "localizeInfos": {
266
+ "title": "Blog",
267
+ "menuTitle": "Blog",
268
+ "htmlContent": "",
269
+ "plainContent": "",
270
+ },
271
+ "isVisible": true,
272
+ "forms": [],
273
+ "blocks": [],
274
+ "type": "common_page",
275
+ "templateIdentifier": "template",
276
+ "attributeSetIdentifier": "page",
277
+ "attributeValues": {},
278
+ "isSync": true,
279
+ "template": {
280
+ "id": 4,
281
+ "attributeSetIdentifier": null,
282
+ "title": "Template",
283
+ "generalTypeId": 4,
284
+ "identifier": "template",
285
+ "version": 0,
286
+ "generalTypeName": "catalog_page",
287
+ "attributeValues": {},
288
+ "position": 1,
289
+ }
290
+ }
291
+ ]
292
+ * @returns {Promise<any | IError>} An array of page objects with template data added
293
+ * @throws {IError} When isShell=false and an error occurs during the fetch
294
+ * @description Add template data to pages. Optimized to avoid N+1 query problem by fetching only unique templates in parallel.
295
+ * For example, if 100 pages use 3 different templates, this method makes 3 requests instead of 100.
296
+ */
297
+ async addTemplateToPages(data) {
298
+ // On API error responses (e.g. 403 without list permission, 422) the value
299
+ // is an IError, not an array — return it as-is instead of calling array
300
+ // methods (.filter/.map) on it and throwing a TypeError.
301
+ if (!Array.isArray(data)) {
302
+ return data;
303
+ }
304
+ // Step 1: Collect unique templateIdentifiers from all pages
305
+ const uniqueIdentifiers = [
306
+ ...new Set(data
307
+ .filter((page) => 'templateIdentifier' in page &&
308
+ page.templateIdentifier !== null &&
309
+ page.templateIdentifier !== '')
310
+ .map((page) => page.templateIdentifier)),
311
+ ];
312
+ // Step 2: If no templates needed, return pages as-is
313
+ if (uniqueIdentifiers.length === 0) {
314
+ return data;
315
+ }
316
+ // Step 3: Fetch unique templates in parallel (not N queries, but unique count queries)
317
+ const Templates = new templatesApi(this.state);
318
+ const templatePromises = uniqueIdentifiers.map((identifier) => Templates.getTemplateByMarker(identifier).catch((error) => {
319
+ // eslint-disable-next-line no-undef, no-console
320
+ console.error(`Template fetch error for ${identifier}: `, error);
321
+ return null; // Return null for failed templates
322
+ }));
323
+ const templates = await Promise.all(templatePromises);
324
+ // Step 4: Create a Map for O(1) template lookup
325
+ const templateMap = new Map();
326
+ templates.forEach((template, index) => {
327
+ if (template !== null) {
328
+ templateMap.set(uniqueIdentifiers[index], template);
329
+ }
330
+ });
331
+ // Step 5: Apply templates to pages (no additional API calls)
332
+ return data.map((page) => {
333
+ if ('templateIdentifier' in page &&
334
+ page.templateIdentifier !== null &&
335
+ page.templateIdentifier !== '') {
336
+ const template = templateMap.get(page.templateIdentifier);
337
+ if (template) {
338
+ return {
339
+ ...page,
340
+ template,
341
+ };
342
+ }
343
+ }
344
+ // Return page without template if identifier is missing or template not found
345
+ return page;
346
+ });
347
+ }
348
+ /**
349
+ * Add template data to page by page templateIdentifier
350
+ * @handleName addTemplateToPage
351
+ * @param {IPagesEntity} data - Page object (IPagesEntity) to which template data will be added.
352
+ * @returns {Promise<any | IError>} An array of page objects with template data added
353
+ * @throws {IError} When isShell=false and an error occurs during the fetch
354
+ * @description Add template data to page by page templateIdentifier
355
+ * @see {@link https://js-sdk.oneentry.cloud/docs/pages/addTemplateToPage addTemplateToPage} documentation.
356
+ */
357
+ async addTemplateToPage(data) {
358
+ // Check if 'templateIdentifier' exists in 'data' and is not null or an empty string
359
+ if ('templateIdentifier' in data &&
360
+ data.templateIdentifier !== null &&
361
+ data.templateIdentifier !== '') {
362
+ // Destructure 'templateIdentifier' from 'data'
363
+ const { templateIdentifier } = data;
364
+ try {
365
+ // Create a new instance of templatesApi with the current state
366
+ const Templates = new templatesApi(this.state);
367
+ // Fetch the template using the 'templateIdentifier'
368
+ const result = await Templates.getTemplateByMarker(templateIdentifier);
369
+ // Return the original data object with the fetched template added
370
+ return {
371
+ ...data,
372
+ template: result,
373
+ };
374
+ }
375
+ catch (error) {
376
+ // eslint-disable-next-line no-undef, no-console
377
+ console.error('Template fetch error: ', error);
378
+ return data;
379
+ }
380
+ }
381
+ else {
382
+ // If 'templateIdentifier' doesn't exist or is invalid, return the original data
383
+ return data;
384
+ }
385
+ }
386
+ }
387
+ /**
388
+ * Helper module for working with blocks, similar products and product blocks
389
+ * @description Internal module for fetching products and similar products for blocks
390
+ */
391
+ class StaffModule extends AsyncModules {
392
+ constructor(state) {
393
+ super(state); // Call parent constructor
394
+ this._url = state.url + '/api/content/blocks'; // Set URL for content blocks
395
+ }
396
+ // Method to fetch similar products by marker. Returns the full response
397
+ // ({ total, items }) to match BlocksApi's similarProducts contract.
398
+ async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
399
+ // Fetch similar products from the server
400
+ const result = await this._fetchGet(`/${marker}/similar-products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
401
+ return this._normalizeData(result);
402
+ }
403
+ // Method to fetch products by block marker
404
+ async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
405
+ // Fetch products from the server
406
+ const result = await this._fetchGet(`/${marker}/products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
407
+ // On API error responses there is no `items` array — return the (normalized)
408
+ // error as-is instead of producing `undefined` from `result.items`.
409
+ if (!Array.isArray(result === null || result === void 0 ? void 0 : result.items)) {
410
+ return this._normalizeData(result);
411
+ }
412
+ return this._normalizeData(result.items);
413
+ }
414
+ }