oneentry 1.0.122 → 1.0.123

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.
@@ -11,7 +11,7 @@ const asyncModules_1 = __importDefault(require("../base/asyncModules"));
11
11
  class AdminsApi extends asyncModules_1.default {
12
12
  constructor(state) {
13
13
  super(state);
14
- this._url = state.url + '/api/content/admins';
14
+ this._url = state.url + '/api/content/admins/all';
15
15
  }
16
16
  /**
17
17
  * Get all user objects - admins.
@@ -208,10 +208,9 @@ class AsyncModules extends syncModules_1.default {
208
208
  if (response.ok) {
209
209
  try {
210
210
  return await response.json();
211
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
212
211
  }
213
212
  catch (e) {
214
- return;
213
+ return e;
215
214
  }
216
215
  }
217
216
  else {
@@ -13,7 +13,7 @@ export default class PageApi extends AsyncModules implements IPageApi {
13
13
  /**
14
14
  * Get all top-level page objects.
15
15
  *
16
- * @param {string} [langCode] - lang code
16
+ * @param {string} [langCode] - Default language code, using the current state if not provided
17
17
  *
18
18
  * @returns Returns all created pages without parents as an array of PageEntity objects or an empty array [] (if there is no data)
19
19
  */
@@ -21,7 +21,7 @@ export default class PageApi extends AsyncModules implements IPageApi {
21
21
  /**
22
22
  * Get all page objects with product information as an array.
23
23
  *
24
- * @param {string} [langCode] - lang code
24
+ * @param {string} [langCode] - Default language code, using the current state if not provided
25
25
  *
26
26
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
27
27
  */
@@ -29,8 +29,8 @@ export default class PageApi extends AsyncModules implements IPageApi {
29
29
  /**
30
30
  * Get page object with information about forms, blocks, menus, linked to the page.
31
31
  *
32
- * @param {number} [id] - Page object identifier
33
- * @param {string} [langCode] - lang code
32
+ * @param {number} [id] - The unique identifier of the page to be fetched
33
+ * @param {string} [langCode] - Default language code, using the current state if not provided
34
34
  *
35
35
  * @returns Returns PageEntity object
36
36
  */
@@ -47,8 +47,8 @@ export default class PageApi extends AsyncModules implements IPageApi {
47
47
  /**
48
48
  * Get child pages object with information as an array.
49
49
  *
50
- * @param {string} [url] - Parent page URL
51
- * @param {string} [langCode] - Required parameter lang code
50
+ * @param {string} [url] - The URL of the parent page for which child pages are to be fetched
51
+ * @param {string} [langCode] - Required parameter langCode. Default language code, using the current state if not provided
52
52
  *
53
53
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data) for the selected parent
54
54
  */
@@ -65,8 +65,8 @@ export default class PageApi extends AsyncModules implements IPageApi {
65
65
  /**
66
66
  * Get all forms by page url.
67
67
  *
68
- * @param {string} [url] - Page URL
69
- * @param {string} [langCode] - lang code
68
+ * @param {string} [url] - The URL of the page for which forms are to be fetched
69
+ * @param {string} [langCode] - Default language code, using the current state if not provided
70
70
  *
71
71
  * @returns Returns all forms as an array of PositionForm objects or an empty array [] (if there is no data) for the selected parent
72
72
  */
@@ -83,19 +83,19 @@ export default class PageApi extends AsyncModules implements IPageApi {
83
83
  * Quick search for page objects with limited output.
84
84
  *
85
85
  * @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)
86
- * @param {string} [langCode] - lang code
86
+ * @param {string} [langCode] - Default language code, using the current state if not provided
87
87
  *
88
88
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
89
89
  */
90
90
  searchPage(name: string, langCode?: string): Promise<Array<IPagesEntity> | IError>;
91
91
  /**
92
- * addTemplateToPages
92
+ * Add template data to pages
93
93
  * @param data
94
94
  * @returns
95
95
  */
96
96
  protected addTemplateToPages(data: IPagesEntity[]): Promise<IPagesEntity[]>;
97
97
  /**
98
- * addTemplateToPage by page templateIdentifier
98
+ * Add template data to page by page templateIdentifier
99
99
  * @param data - page object
100
100
  * @returns
101
101
  */
@@ -18,39 +18,48 @@ class PageApi extends asyncModules_1.default {
18
18
  /**
19
19
  * Get all top-level page objects.
20
20
  *
21
- * @param {string} [langCode] - lang code
21
+ * @param {string} [langCode] - Default language code, using the current state if not provided
22
22
  *
23
23
  * @returns Returns all created pages without parents as an array of PageEntity objects or an empty array [] (if there is no data)
24
24
  */
25
25
  async getRootPages(langCode = this.state.lang) {
26
+ // Fetch data from the server using a GET request to retrieve root pages for the specified language code
26
27
  const data = await this._fetchGet(`/root?langCode=${langCode}`);
27
- const result = await this.addTemplateToPages(data);
28
- return this._normalizeData(result, langCode);
28
+ // Add template information to each page in the fetched root pages data
29
+ const withTemplate = await this.addTemplateToPages(data);
30
+ // Normalize the data and return it; ensures consistent structure or handles errors
31
+ return this._normalizeData(withTemplate, langCode);
29
32
  }
30
33
  /**
31
34
  * Get all page objects with product information as an array.
32
35
  *
33
- * @param {string} [langCode] - lang code
36
+ * @param {string} [langCode] - Default language code, using the current state if not provided
34
37
  *
35
38
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
36
39
  */
37
40
  async getPages(langCode = this.state.lang) {
41
+ // Fetch data from the server using a GET request to retrieve all pages for the specified language code
38
42
  const data = await this._fetchGet(`?langCode=${langCode}`);
39
- const result = await this.addTemplateToPages(data);
40
- return this._normalizeData(result, langCode);
43
+ // Add template information to each page in the fetched data
44
+ const withTemplate = await this.addTemplateToPages(data);
45
+ // Normalize the data and return it; ensures consistent structure or handles errors
46
+ return this._normalizeData(withTemplate, langCode);
41
47
  }
42
48
  /**
43
49
  * Get page object with information about forms, blocks, menus, linked to the page.
44
50
  *
45
- * @param {number} [id] - Page object identifier
46
- * @param {string} [langCode] - lang code
51
+ * @param {number} [id] - The unique identifier of the page to be fetched
52
+ * @param {string} [langCode] - Default language code, using the current state if not provided
47
53
  *
48
54
  * @returns Returns PageEntity object
49
55
  */
50
56
  async getPageById(id, langCode = this.state.lang) {
57
+ // Fetch data from the server using a GET request to retrieve page details by ID and language code
51
58
  const data = await this._fetchGet(`/${id}?langCode=${langCode}`);
52
- const result = await this.addTemplateToPage(data);
53
- return this._normalizeData(result, langCode);
59
+ // Add template information to the fetched page data
60
+ const withTemplate = await this.addTemplateToPage(data);
61
+ // Normalize the data and return it; ensures consistent structure or handles errors
62
+ return this._normalizeData(withTemplate, langCode);
54
63
  }
55
64
  /**
56
65
  * Get page object with information about forms, blocks, menus, linked to the page by URL.
@@ -61,22 +70,28 @@ class PageApi extends asyncModules_1.default {
61
70
  * @returns Returns PageEntity object
62
71
  */
63
72
  async getPageByUrl(url, langCode = this.state.lang) {
73
+ // Fetch data from the server using a GET request with the specified URL and language code
64
74
  const data = await this._fetchGet(`/url/${url}?langCode=${langCode}`);
65
- const result = await this.addTemplateToPage(data);
66
- return this._normalizeData(result, langCode);
75
+ // Add template information to the fetched page data
76
+ const withTemplate = await this.addTemplateToPage(data);
77
+ // Normalize the result data and return it; ensures consistent structure or handles errors
78
+ return this._normalizeData(withTemplate, langCode);
67
79
  }
68
80
  /**
69
81
  * Get child pages object with information as an array.
70
82
  *
71
- * @param {string} [url] - Parent page URL
72
- * @param {string} [langCode] - Required parameter lang code
83
+ * @param {string} [url] - The URL of the parent page for which child pages are to be fetched
84
+ * @param {string} [langCode] - Required parameter langCode. Default language code, using the current state if not provided
73
85
  *
74
86
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data) for the selected parent
75
87
  */
76
88
  async getChildPagesByParentUrl(url, langCode = this.state.lang) {
89
+ // Fetch data from the server using a GET request to retrieve child pages for the specified parent URL and language code
77
90
  const data = await this._fetchGet(`/${url}/children?langCode=${langCode}`);
78
- const result = await this.addTemplateToPages(data);
79
- return this._normalizeData(result, langCode);
91
+ // Add template information to each of the fetched child pages
92
+ const withTemplate = await this.addTemplateToPages(data);
93
+ // Normalize the result data and return it; ensures consistent structure or handles errors
94
+ return this._normalizeData(withTemplate, langCode);
80
95
  }
81
96
  /**
82
97
  * Get all blocks by page url.
@@ -88,37 +103,52 @@ class PageApi extends asyncModules_1.default {
88
103
  */
89
104
  async getBlocksByPageUrl(url, langCode = this.state.lang) {
90
105
  const response = await this._fetchGet(`/${url}/blocks?langCode=${langCode}`);
106
+ // Normalize the fetched response data
91
107
  const normalizeResponse = this._normalizeData(response);
108
+ // Iterate over each item in the normalized response
92
109
  normalizeResponse.map((item) => {
93
110
  const customSettings = item.customSettings;
111
+ // Check if customSettings contains 'productConfig' property
94
112
  // eslint-disable-next-line no-prototype-builtins
95
113
  if (customSettings && customSettings.hasOwnProperty('productConfig')) {
114
+ // If 'countElementsPerRow' exists, set it on the item
96
115
  if (customSettings.productConfig.countElementsPerRow)
97
116
  item.countElementsPerRow =
98
117
  +customSettings.productConfig.countElementsPerRow;
118
+ // If 'quantity' exists, set it on the item
99
119
  if (customSettings.productConfig.quantity)
100
120
  item.quantity = +customSettings.productConfig.quantity;
101
121
  }
122
+ // Remove unnecessary properties from the item
102
123
  delete item.customSettings;
103
124
  delete item.attributesSetIdentifier;
125
+ // Return the modified item
104
126
  return item;
105
127
  });
128
+ // Check if traffic limit is not set
106
129
  if (!this.state.traficLimit) {
130
+ // Define a class 'StaffModule' extending 'AsyncModules'
107
131
  class StaffModule extends asyncModules_1.default {
108
132
  constructor(state) {
109
- super(state);
110
- this._url = state.url + '/api/content/blocks';
133
+ super(state); // Call parent constructor
134
+ this._url = state.url + '/api/content/blocks'; // Set URL for content blocks
111
135
  }
136
+ // Method to fetch similar products by marker
112
137
  async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
138
+ // Fetch similar products from the server
113
139
  const result = await this._fetchGet(`/${marker}/similar-products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
114
140
  return this._normalizeData(result.items);
115
141
  }
142
+ // Method to fetch products by block marker
116
143
  async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
144
+ // Fetch products from the server
117
145
  const result = await this._fetchGet(`/${marker}/products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
118
146
  return this._normalizeData(result.items);
119
147
  }
120
148
  }
149
+ // Create an instance of 'StaffModule' with the current state
121
150
  const staffModule = new StaffModule(this.state);
151
+ // If the block type is 'similar_products_block', fetch similar products
122
152
  if (normalizeResponse.type === 'similar_products_block') {
123
153
  try {
124
154
  await staffModule
@@ -128,8 +158,10 @@ class PageApi extends asyncModules_1.default {
128
158
  });
129
159
  }
130
160
  catch {
161
+ // Handle errors by setting an empty array
131
162
  normalizeResponse.similarProducts = [];
132
163
  }
164
+ // If the block type is 'product_block', fetch products
133
165
  }
134
166
  else if (normalizeResponse.type === 'product_block') {
135
167
  try {
@@ -140,23 +172,27 @@ class PageApi extends asyncModules_1.default {
140
172
  });
141
173
  }
142
174
  catch {
175
+ // Handle errors by setting an empty array
143
176
  normalizeResponse.products = [];
144
177
  }
145
178
  }
146
179
  }
180
+ // Return the final normalized response
147
181
  return this._normalizeData(normalizeResponse);
148
182
  }
149
183
  /**
150
184
  * Get all forms by page url.
151
185
  *
152
- * @param {string} [url] - Page URL
153
- * @param {string} [langCode] - lang code
186
+ * @param {string} [url] - The URL of the page for which forms are to be fetched
187
+ * @param {string} [langCode] - Default language code, using the current state if not provided
154
188
  *
155
189
  * @returns Returns all forms as an array of PositionForm objects or an empty array [] (if there is no data) for the selected parent
156
190
  */
157
191
  async getFormsByPageUrl(url, langCode = this.state.lang) {
158
- const result = await this._fetchGet(`/${url}/forms?langCode=${langCode}`);
159
- return this._normalizeData(result, langCode);
192
+ // Fetch data from the server using a GET request to retrieve forms for the specified page URL and language code
193
+ const withTemplate = await this._fetchGet(`/${url}/forms?langCode=${langCode}`);
194
+ // Normalize the fetched result data and return it; ensures consistent structure or handles errors
195
+ return this._normalizeData(withTemplate, langCode);
160
196
  }
161
197
  /**
162
198
  * Get settings for the page.
@@ -166,60 +202,89 @@ class PageApi extends asyncModules_1.default {
166
202
  * @returns Returns a ConfigPage object with page display settings
167
203
  */
168
204
  async getConfigPageByUrl(url) {
205
+ // Fetch data from the server using a GET request to retrieve forms for the specified page URL and language code
169
206
  const result = await this._fetchGet(`/${url}/config`);
207
+ // return fetched data
170
208
  return result;
171
209
  }
172
210
  /**
173
211
  * Quick search for page objects with limited output.
174
212
  *
175
213
  * @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)
176
- * @param {string} [langCode] - lang code
214
+ * @param {string} [langCode] - Default language code, using the current state if not provided
177
215
  *
178
216
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
179
217
  */
180
218
  async searchPage(name, langCode = this.state.lang) {
219
+ // Fetch data from the server using a GET request to perform a quick search by page name and language code
181
220
  const data = await this._fetchGet(`/quick/search?lang=${langCode}&name=${name}`);
221
+ // Check if there is no traffic limit set in the state
182
222
  if (!this.state.traficLimit) {
223
+ // Initialize an empty array to store detailed page information
183
224
  const pageList = [];
225
+ // Use Promise.all to fetch detailed information for each page concurrently
184
226
  await Promise.all(data.map(async (page) => {
227
+ // Fetch detailed page information by page ID and push it to pageList
185
228
  await this.getPageById(page.id, langCode).then((result) => {
186
229
  pageList.push(result);
187
230
  });
188
231
  }));
189
- const result = await this.addTemplateToPages(pageList);
190
- return this._dataPostProcess(result, langCode);
232
+ // Add templates to the fetched pages
233
+ const withTemplate = await this.addTemplateToPages(pageList);
234
+ // Post-process the data and return it; ensures consistent structure or handles errors
235
+ return this._dataPostProcess(withTemplate, langCode);
191
236
  }
192
- const result = await this.addTemplateToPages(data);
193
- return this._normalizeData(result, langCode);
237
+ // If there is a traffic limit, add templates to the initially fetched data without fetching detailed information
238
+ const withTemplate = await this.addTemplateToPages(data);
239
+ // Normalize the data and return it; ensures consistent structure or handles errors
240
+ return this._normalizeData(withTemplate, langCode);
194
241
  }
195
242
  /**
196
- * addTemplateToPages
243
+ * Add template data to pages
197
244
  * @param data
198
245
  * @returns
199
246
  */
200
247
  async addTemplateToPages(data) {
248
+ // Use Promise.all to handle an array of promises returned by mapping over 'data'
201
249
  return Promise.all(data.map(async (d) => {
250
+ // For each element 'd' in the 'data' array, call 'addTemplateToPage'
202
251
  const result = await this.addTemplateToPage(d);
252
+ // Return the result of 'addTemplateToPage' for the current element
203
253
  return result;
204
254
  }));
205
255
  }
206
256
  /**
207
- * addTemplateToPage by page templateIdentifier
257
+ * Add template data to page by page templateIdentifier
208
258
  * @param data - page object
209
259
  * @returns
210
260
  */
211
261
  async addTemplateToPage(data) {
212
- if ('templateIdentifier' in data && data.templateIdentifier) {
213
- // Create an instance of templatesApi with the current state
214
- const Templates = new templatesApi_1.default(this.state);
215
- // get template by marker
216
- const result = await Templates.getTemplateByMarker('template');
217
- return {
218
- ...data,
219
- template: result,
220
- };
262
+ // Check if 'templateIdentifier' exists in 'data' and is not null or an empty string
263
+ if ('templateIdentifier' in data &&
264
+ data.templateIdentifier !== null &&
265
+ data.templateIdentifier !== '') {
266
+ // Destructure 'templateIdentifier' from 'data'
267
+ const { templateIdentifier } = data;
268
+ try {
269
+ // Create a new instance of templatesApi with the current state
270
+ const Templates = new templatesApi_1.default(this.state);
271
+ // Fetch the template using the 'templateIdentifier'
272
+ const result = await Templates.getTemplateByMarker(templateIdentifier);
273
+ // Return the original data object with the fetched template added
274
+ return {
275
+ ...data,
276
+ template: result,
277
+ };
278
+ }
279
+ catch (error) {
280
+ // Log any errors that occur during the template fetching process
281
+ console.error('Template fetch error: ', error);
282
+ // Return the original data object unchanged if an error occurs
283
+ return data;
284
+ }
221
285
  }
222
286
  else {
287
+ // If 'templateIdentifier' doesn't exist or is invalid, return the original data
223
288
  return data;
224
289
  }
225
290
  }
@@ -30,7 +30,7 @@ interface ITemplatesPreviewEntity {
30
30
  identifier: string;
31
31
  attributeValues: AttributeType;
32
32
  attributeSetIdentifier?: string | null;
33
- proportion: {
33
+ proportions: {
34
34
  horizontal: IProportion | null;
35
35
  vertical: IProportion | null;
36
36
  square: ISquare;
@@ -47,8 +47,8 @@ interface ITemplatesPreviewEntity {
47
47
  * @property {string} alignmentType -
48
48
  */
49
49
  interface IProportion {
50
- width: string | number | null;
51
- height: string | number | null;
50
+ width: number | null;
51
+ height: number | null;
52
52
  marker: string;
53
53
  alignmentType: string;
54
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.122",
3
+ "version": "1.0.123",
4
4
  "description": "OneEntry NPM package",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -45,19 +45,19 @@
45
45
  "@jest/globals": "^29.7.0",
46
46
  "@types/eslint-config-prettier": "^6.11.3",
47
47
  "@types/jest": "^29.5.14",
48
- "@types/node": "^22.15.17",
49
- "@typescript-eslint/eslint-plugin": "^8.32.1",
50
- "@typescript-eslint/parser": "^8.32.1",
48
+ "@types/node": "^22.15.29",
49
+ "@typescript-eslint/eslint-plugin": "^8.33.1",
50
+ "@typescript-eslint/parser": "^8.33.1",
51
51
  "eslint": "^8.57.1",
52
52
  "eslint-config-prettier": "^10.1.5",
53
53
  "eslint-plugin-import": "^2.31.0",
54
- "eslint-plugin-jest": "^28.11.0",
55
- "eslint-plugin-prettier": "^5.4.0",
54
+ "eslint-plugin-jest": "^28.12.0",
55
+ "eslint-plugin-prettier": "^5.4.1",
56
56
  "eslint-plugin-simple-import-sort": "^12.1.1",
57
57
  "jest": "^29.7.0",
58
58
  "npm-run-all": "^4.1.5",
59
59
  "prettier": "^3.5.3",
60
- "ts-jest": "^29.3.2",
60
+ "ts-jest": "^29.3.4",
61
61
  "typescript": "^5.8.3"
62
62
  }
63
63
  }