oneentry 1.0.121 → 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.
@@ -12,10 +12,10 @@ interface IAttributesSets {
12
12
  /**
13
13
  * Represents an interface object of IListTitle.
14
14
  *
15
- * @property {string} title
16
- * @property {number | string} value
17
- * @property {string | number | null} position
18
- * @property {object} extended
15
+ * @property {string} title - The title or name associated with the list item.
16
+ * @property {number | string} value - The value of the list item, which can be either a number or a string depending on the context.
17
+ * @property {string | number | null} position - The position of the list item, which can be represented as a string, number, or null if not applicable.
18
+ * @property {object} extended - An object containing additional properties or metadata related to the list item. This could include any extra details that extend the basic information.
19
19
  */
20
20
  interface IListTitle {
21
21
  title: string;
@@ -53,15 +53,15 @@ interface IAttributesSetsEntity {
53
53
  /**
54
54
  * Represents an interface object of IAttributeSetsEntity.
55
55
  *
56
- * @property {number} id -
57
- * @property {string} identifier -
58
- * @property {boolean} isVisible -
59
- * @property {any} schema -
60
- * @property {string} title -
61
- * @property {any} type -
62
- * @property {number} typeId -
63
- * @property {string} updatedDate -
64
- * @property {number} version -
56
+ * @property {number} id - The unique identifier of the attribute set entity.
57
+ * @property {string} identifier - A string that uniquely identifies the attribute set.
58
+ * @property {boolean} isVisible - Indicates whether the attribute set is visible or not.
59
+ * @property {any} schema - The schema definition associated with the attribute set. This could represent the structure or rules for the data.
60
+ * @property {string} title - The title or name of the attribute set.
61
+ * @property {any} type - The type of the attribute set, which could be a specific classification or category.
62
+ * @property {number} typeId - The numerical identifier representing the type of the attribute set.
63
+ * @property {string} updatedDate - The date when the attribute set was last updated, represented as a string. Consider using Date for better date handling.
64
+ * @property {number} version - The version number of the attribute set, used for tracking changes or updates.
65
65
  */
66
66
  interface IAttributeSetsEntity {
67
67
  id: number;
@@ -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 {
@@ -4,7 +4,7 @@ export default class StateModule {
4
4
  lang: string | undefined;
5
5
  token: string | undefined;
6
6
  accessToken: string | undefined;
7
- multipleResponse: boolean;
7
+ traficLimit: boolean;
8
8
  refreshToken: string | undefined;
9
9
  customAuth: boolean;
10
10
  _NO_FETCH: boolean;
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class StateModule {
4
4
  constructor(url, config) {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
6
6
  this.url = url;
7
7
  this.lang = (_a = config.langCode) !== null && _a !== void 0 ? _a : 'en_US';
8
8
  this.token = config.token;
9
- this.multipleResponse = !!((_b = config.traficLimit) !== null && _b !== void 0 ? _b : true);
10
- this.refreshToken = (_d = (_c = config.auth) === null || _c === void 0 ? void 0 : _c.refreshToken) !== null && _d !== void 0 ? _d : undefined;
11
- this.customAuth = (_f = (_e = config.auth) === null || _e === void 0 ? void 0 : _e.customAuth) !== null && _f !== void 0 ? _f : false;
9
+ this.traficLimit = config.traficLimit || false;
10
+ this.refreshToken = (_c = (_b = config.auth) === null || _b === void 0 ? void 0 : _b.refreshToken) !== null && _c !== void 0 ? _c : undefined;
11
+ this.customAuth = (_e = (_d = config.auth) === null || _d === void 0 ? void 0 : _d.customAuth) !== null && _e !== void 0 ? _e : false;
12
12
  this.errorsFunctions = {
13
13
  '400': undefined,
14
14
  '401': undefined,
@@ -16,20 +16,20 @@ class StateModule {
16
16
  '404': undefined,
17
17
  '500': undefined,
18
18
  };
19
- this.saveFunction = (_h = (_g = config.auth) === null || _g === void 0 ? void 0 : _g.saveFunction) !== null && _h !== void 0 ? _h : null;
19
+ this.saveFunction = (_g = (_f = config.auth) === null || _f === void 0 ? void 0 : _f.saveFunction) !== null && _g !== void 0 ? _g : null;
20
20
  if (config.errors) {
21
- this.isShell = (_j = config.errors.isShell) !== null && _j !== void 0 ? _j : true;
21
+ this.isShell = (_h = config.errors.isShell) !== null && _h !== void 0 ? _h : true;
22
22
  if (config.errors.customErrors) {
23
23
  this.errorsFunctions['400'] =
24
- (_k = config.errors.customErrors['400']) !== null && _k !== void 0 ? _k : undefined;
24
+ (_j = config.errors.customErrors['400']) !== null && _j !== void 0 ? _j : undefined;
25
25
  this.errorsFunctions['401'] =
26
- (_l = config.errors.customErrors['401']) !== null && _l !== void 0 ? _l : undefined;
26
+ (_k = config.errors.customErrors['401']) !== null && _k !== void 0 ? _k : undefined;
27
27
  this.errorsFunctions['403'] =
28
- (_m = config.errors.customErrors['403']) !== null && _m !== void 0 ? _m : undefined;
28
+ (_l = config.errors.customErrors['403']) !== null && _l !== void 0 ? _l : undefined;
29
29
  this.errorsFunctions['404'] =
30
- (_o = config.errors.customErrors['404']) !== null && _o !== void 0 ? _o : undefined;
30
+ (_m = config.errors.customErrors['404']) !== null && _m !== void 0 ? _m : undefined;
31
31
  this.errorsFunctions['500'] =
32
- (_p = config.errors.customErrors['400']) !== null && _p !== void 0 ? _p : undefined;
32
+ (_o = config.errors.customErrors['400']) !== null && _o !== void 0 ? _o : undefined;
33
33
  }
34
34
  }
35
35
  else {
@@ -249,138 +249,6 @@ class SyncModules {
249
249
  });
250
250
  return schedules;
251
251
  }
252
- // /**
253
- // * Function to generate intervals for a specific date
254
- // *
255
- // * @param date
256
- // * @param schedule
257
- // * @param utcIntervals
258
- // */
259
- // protected _generateFormIntervalsForDate(
260
- // date: Date,
261
- // schedule: { inEveryWeek: boolean; intervals: any[]; inEveryMonth: boolean },
262
- // utcIntervals: Set<Array<string>>,
263
- // ) {
264
- // // inEveryWeek
265
- // if (schedule.inEveryWeek && !schedule.inEveryMonth) {
266
- // let currentDate = new Date(date);
267
- // // Вычисляем последний день текущего месяца
268
- // const endOfMonth = new Date(
269
- // currentDate.getFullYear(),
270
- // currentDate.getMonth() + 1,
271
- // 0,
272
- // );
273
- // while (currentDate <= endOfMonth) {
274
- // schedule.intervals?.forEach((timeRange: [any, any]) => {
275
- // const [startTime, endTime] = timeRange;
276
- // const intervalStart = new Date(currentDate);
277
- // intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
278
- // const intervalEnd = new Date(currentDate);
279
- // intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
280
- // // Добавляем строку JSON в Set для уникальности
281
- // utcIntervals.add([
282
- // intervalStart.toISOString(),
283
- // intervalEnd.toISOString(),
284
- // ]);
285
- // });
286
- // currentDate = this._addDays(currentDate, 7); // Переходим к следующей неделе
287
- // }
288
- // }
289
- // // inEveryMonth
290
- // if (schedule.inEveryMonth && !schedule.inEveryWeek) {
291
- // const startDate = new Date(date); // Начальная дата
292
- // const targetDayOfMonth = startDate.getUTCDate(); // Определяем день месяца начальной даты
293
- // const numberOfMonths = 12; // Количество месяцев, на которые нужно повторить
294
- // for (let i = 0; i < numberOfMonths; i++) {
295
- // const currentDate = new Date(startDate);
296
- // currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
297
- // // Попробуем установить текущую дату на целевой день месяца
298
- // currentDate.setUTCDate(targetDayOfMonth);
299
- // // Проверяем, не вышли ли мы за пределы месяца
300
- // if (currentDate.getUTCMonth() !== (startDate.getUTCMonth() + i) % 12) {
301
- // continue; // Если вышли, пропускаем этот месяц
302
- // }
303
- // schedule.intervals?.forEach((timeRange: [any, any]) => {
304
- // const [startTime, endTime] = timeRange;
305
- // const intervalStart = new Date(currentDate);
306
- // intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
307
- // const intervalEnd = new Date(currentDate);
308
- // intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
309
- // utcIntervals.add([
310
- // intervalStart.toISOString(),
311
- // intervalEnd.toISOString(),
312
- // ]);
313
- // });
314
- // }
315
- // }
316
- // // inEveryMonth && inEveryWeek
317
- // if (schedule.inEveryMonth && schedule.inEveryWeek) {
318
- // const startDate = new Date(date); // Начальная дата
319
- // const targetDayOfWeek = startDate.getUTCDay(); // Определяем день недели начальной даты
320
- // const numberOfMonths = 12; // Количество месяцев, на которые нужно повторить
321
- // console.log(startDate);
322
- // for (let i = 0; i < numberOfMonths; i++) {
323
- // const currentDate = new Date(startDate);
324
- // currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
325
- // currentDate.setUTCDate(1); // Устанавливаем на первый день месяца
326
- // // Находим первый целевой день недели в текущем месяце
327
- // const daysUntilTargetDay =
328
- // (targetDayOfWeek - currentDate.getUTCDay() + 7) % 7;
329
- // currentDate.setUTCDate(currentDate.getUTCDate() + daysUntilTargetDay);
330
- // // Проходим по всем целевым дням недели в текущем месяце
331
- // while (
332
- // currentDate.getUTCMonth() ===
333
- // (startDate.getUTCMonth() + i) % 12
334
- // ) {
335
- // schedule.intervals.forEach((timeRange: [any, any]) => {
336
- // const [startTime, endTime] = timeRange;
337
- // const intervalStart = new Date(currentDate);
338
- // intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
339
- // const intervalEnd = new Date(currentDate);
340
- // intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
341
- // utcIntervals.add([
342
- // intervalStart.toISOString(),
343
- // intervalEnd.toISOString(),
344
- // ]);
345
- // });
346
- // // Переходим к следующей неделе (следующему такому же дню недели)
347
- // currentDate.setUTCDate(currentDate.getUTCDate() + 7);
348
- // }
349
- // }
350
- // }
351
- // }
352
- // /**
353
- // * Add TimeIntervals to schedules Form
354
- // *
355
- // * @param schedules
356
- // * @returns schedules with timeIntervals
357
- // */
358
- // _addTimeIntervalsToSchedulesForm(schedules: any[]) {
359
- // schedules?.forEach((schedule: any) => {
360
- // const utcIntervals: Set<Array<string>> = new Set();
361
- // const startDate = new Date(schedule.range[0]);
362
- // const endDate = new Date(schedule.range[1]);
363
- // const isSameDay = startDate.toISOString() === endDate.toISOString();
364
- // // console.log(JSON.stringify(schedule));
365
- // if (isSameDay) {
366
- // this._generateFormIntervalsForDate(startDate, schedule, utcIntervals);
367
- // } else {
368
- // for (
369
- // let currentDate = new Date(startDate);
370
- // currentDate <= endDate;
371
- // currentDate = this._addDays(currentDate, 1)
372
- // ) {
373
- // this._generateFormIntervalsForDate(
374
- // currentDate,
375
- // schedule,
376
- // utcIntervals,
377
- // );
378
- // }
379
- // }
380
- // // schedule.timeIntervals = Array.from(utcIntervals).sort();
381
- // });
382
- // return schedules;
383
- // }
384
252
  /**
385
253
  * normalizeAttr
386
254
  *
@@ -25,7 +25,7 @@ class BlocksApi extends asyncModules_1.default {
25
25
  */
26
26
  async getBlocks(type, langCode = this.state.lang, offset = 0, limit = 30) {
27
27
  const response = await this._fetchGet(`?langCode=${langCode}&type=${type}&offset=${offset}&limit=${limit}`);
28
- if (this.state.multipleResponse) {
28
+ if (!this.state.traficLimit) {
29
29
  const normalizeResponse = this._normalizeData(response);
30
30
  await Promise.all(
31
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -93,7 +93,7 @@ class BlocksApi extends asyncModules_1.default {
93
93
  delete normalizeResponse.customSettings;
94
94
  delete normalizeResponse.attributesSetIdentifier;
95
95
  delete normalizeResponse.productPageUrls;
96
- if (this.state.multipleResponse) {
96
+ if (!this.state.traficLimit) {
97
97
  if (normalizeResponse.type === 'similar_products_block') {
98
98
  try {
99
99
  await this.getSimilarProducts(normalizeResponse.identifier, langCode, offset, limit).then((result) => {
@@ -79,7 +79,9 @@ class FormsDataApi extends asyncModules_1.default {
79
79
  type: 'page',
80
80
  entity: 'editor',
81
81
  // Generate a random 4-digit ID
82
- id: Number(Math.floor(Math.random() * 10000).toString().padStart(4, '0')),
82
+ id: Number(Math.floor(Math.random() * 10000)
83
+ .toString()
84
+ .padStart(4, '0')),
83
85
  };
84
86
  fd.fileQuery = fileQuery;
85
87
  }
@@ -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,9 +83,21 @@ 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
+ /**
92
+ * Add template data to pages
93
+ * @param data
94
+ * @returns
95
+ */
96
+ protected addTemplateToPages(data: IPagesEntity[]): Promise<IPagesEntity[]>;
97
+ /**
98
+ * Add template data to page by page templateIdentifier
99
+ * @param data - page object
100
+ * @returns
101
+ */
102
+ protected addTemplateToPage(data: IPagesEntity): Promise<IPagesEntity>;
91
103
  }
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable @typescript-eslint/no-explicit-any */
7
7
  const asyncModules_1 = __importDefault(require("../base/asyncModules"));
8
+ const templatesApi_1 = __importDefault(require("../templates/templatesApi"));
8
9
  /**
9
10
  * Controllers for working with page objects, including catalog pages
10
11
  * @handle /api/content/pages
@@ -17,36 +18,48 @@ class PageApi extends asyncModules_1.default {
17
18
  /**
18
19
  * Get all top-level page objects.
19
20
  *
20
- * @param {string} [langCode] - lang code
21
+ * @param {string} [langCode] - Default language code, using the current state if not provided
21
22
  *
22
23
  * @returns Returns all created pages without parents as an array of PageEntity objects or an empty array [] (if there is no data)
23
24
  */
24
25
  async getRootPages(langCode = this.state.lang) {
25
- const result = await this._fetchGet(`/root?langCode=${langCode}`);
26
- return this._normalizeData(result, langCode);
26
+ // Fetch data from the server using a GET request to retrieve root pages for the specified language code
27
+ const data = await this._fetchGet(`/root?langCode=${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);
27
32
  }
28
33
  /**
29
34
  * Get all page objects with product information as an array.
30
35
  *
31
- * @param {string} [langCode] - lang code
36
+ * @param {string} [langCode] - Default language code, using the current state if not provided
32
37
  *
33
38
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
34
39
  */
35
40
  async getPages(langCode = this.state.lang) {
36
- const result = await this._fetchGet(`?langCode=${langCode}`);
37
- return this._normalizeData(result, langCode);
41
+ // Fetch data from the server using a GET request to retrieve all pages for the specified language code
42
+ const data = await this._fetchGet(`?langCode=${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);
38
47
  }
39
48
  /**
40
49
  * Get page object with information about forms, blocks, menus, linked to the page.
41
50
  *
42
- * @param {number} [id] - Page object identifier
43
- * @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
44
53
  *
45
54
  * @returns Returns PageEntity object
46
55
  */
47
56
  async getPageById(id, langCode = this.state.lang) {
48
- const result = await this._fetchGet(`/${id}?langCode=${langCode}`);
49
- return this._normalizeData(result, langCode);
57
+ // Fetch data from the server using a GET request to retrieve page details by ID and language code
58
+ const data = await this._fetchGet(`/${id}?langCode=${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);
50
63
  }
51
64
  /**
52
65
  * Get page object with information about forms, blocks, menus, linked to the page by URL.
@@ -57,20 +70,28 @@ class PageApi extends asyncModules_1.default {
57
70
  * @returns Returns PageEntity object
58
71
  */
59
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
60
74
  const data = await this._fetchGet(`/url/${url}?langCode=${langCode}`);
61
- return this._normalizeData(data, 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);
62
79
  }
63
80
  /**
64
81
  * Get child pages object with information as an array.
65
82
  *
66
- * @param {string} [url] - Parent page URL
67
- * @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
68
85
  *
69
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
70
87
  */
71
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
72
90
  const data = await this._fetchGet(`/${url}/children?langCode=${langCode}`);
73
- return this._normalizeData(data, 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);
74
95
  }
75
96
  /**
76
97
  * Get all blocks by page url.
@@ -82,37 +103,52 @@ class PageApi extends asyncModules_1.default {
82
103
  */
83
104
  async getBlocksByPageUrl(url, langCode = this.state.lang) {
84
105
  const response = await this._fetchGet(`/${url}/blocks?langCode=${langCode}`);
106
+ // Normalize the fetched response data
85
107
  const normalizeResponse = this._normalizeData(response);
108
+ // Iterate over each item in the normalized response
86
109
  normalizeResponse.map((item) => {
87
110
  const customSettings = item.customSettings;
111
+ // Check if customSettings contains 'productConfig' property
88
112
  // eslint-disable-next-line no-prototype-builtins
89
113
  if (customSettings && customSettings.hasOwnProperty('productConfig')) {
114
+ // If 'countElementsPerRow' exists, set it on the item
90
115
  if (customSettings.productConfig.countElementsPerRow)
91
116
  item.countElementsPerRow =
92
117
  +customSettings.productConfig.countElementsPerRow;
118
+ // If 'quantity' exists, set it on the item
93
119
  if (customSettings.productConfig.quantity)
94
120
  item.quantity = +customSettings.productConfig.quantity;
95
121
  }
122
+ // Remove unnecessary properties from the item
96
123
  delete item.customSettings;
97
124
  delete item.attributesSetIdentifier;
125
+ // Return the modified item
98
126
  return item;
99
127
  });
100
- if (this.state.multipleResponse) {
128
+ // Check if traffic limit is not set
129
+ if (!this.state.traficLimit) {
130
+ // Define a class 'StaffModule' extending 'AsyncModules'
101
131
  class StaffModule extends asyncModules_1.default {
102
132
  constructor(state) {
103
- super(state);
104
- 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
105
135
  }
136
+ // Method to fetch similar products by marker
106
137
  async getSimilarProducts(marker, langCode = this.state.lang, offset = 0, limit = 30) {
138
+ // Fetch similar products from the server
107
139
  const result = await this._fetchGet(`/${marker}/similar-products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
108
140
  return this._normalizeData(result.items);
109
141
  }
142
+ // Method to fetch products by block marker
110
143
  async getProductsByBlockMarker(marker, langCode = this.state.lang, offset = 0, limit = 30) {
144
+ // Fetch products from the server
111
145
  const result = await this._fetchGet(`/${marker}/products?langCode=${langCode}&offset=${offset}&limit=${limit}`);
112
146
  return this._normalizeData(result.items);
113
147
  }
114
148
  }
149
+ // Create an instance of 'StaffModule' with the current state
115
150
  const staffModule = new StaffModule(this.state);
151
+ // If the block type is 'similar_products_block', fetch similar products
116
152
  if (normalizeResponse.type === 'similar_products_block') {
117
153
  try {
118
154
  await staffModule
@@ -122,8 +158,10 @@ class PageApi extends asyncModules_1.default {
122
158
  });
123
159
  }
124
160
  catch {
161
+ // Handle errors by setting an empty array
125
162
  normalizeResponse.similarProducts = [];
126
163
  }
164
+ // If the block type is 'product_block', fetch products
127
165
  }
128
166
  else if (normalizeResponse.type === 'product_block') {
129
167
  try {
@@ -134,23 +172,27 @@ class PageApi extends asyncModules_1.default {
134
172
  });
135
173
  }
136
174
  catch {
175
+ // Handle errors by setting an empty array
137
176
  normalizeResponse.products = [];
138
177
  }
139
178
  }
140
179
  }
180
+ // Return the final normalized response
141
181
  return this._normalizeData(normalizeResponse);
142
182
  }
143
183
  /**
144
184
  * Get all forms by page url.
145
185
  *
146
- * @param {string} [url] - Page URL
147
- * @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
148
188
  *
149
189
  * @returns Returns all forms as an array of PositionForm objects or an empty array [] (if there is no data) for the selected parent
150
190
  */
151
191
  async getFormsByPageUrl(url, langCode = this.state.lang) {
152
- const result = await this._fetchGet(`/${url}/forms?langCode=${langCode}`);
153
- 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);
154
196
  }
155
197
  /**
156
198
  * Get settings for the page.
@@ -160,29 +202,91 @@ class PageApi extends asyncModules_1.default {
160
202
  * @returns Returns a ConfigPage object with page display settings
161
203
  */
162
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
163
206
  const result = await this._fetchGet(`/${url}/config`);
207
+ // return fetched data
164
208
  return result;
165
209
  }
166
210
  /**
167
211
  * Quick search for page objects with limited output.
168
212
  *
169
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)
170
- * @param {string} [langCode] - lang code
214
+ * @param {string} [langCode] - Default language code, using the current state if not provided
171
215
  *
172
216
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
173
217
  */
174
218
  async searchPage(name, langCode = this.state.lang) {
175
- const searchPages = await this._fetchGet(`/quick/search?lang=${langCode}&name=${name}`);
176
- if (this.state.multipleResponse) {
219
+ // Fetch data from the server using a GET request to perform a quick search by page name and language code
220
+ const data = await this._fetchGet(`/quick/search?lang=${langCode}&name=${name}`);
221
+ // Check if there is no traffic limit set in the state
222
+ if (!this.state.traficLimit) {
223
+ // Initialize an empty array to store detailed page information
177
224
  const pageList = [];
178
- await Promise.all(searchPages.map(async (page) => {
225
+ // Use Promise.all to fetch detailed information for each page concurrently
226
+ await Promise.all(data.map(async (page) => {
227
+ // Fetch detailed page information by page ID and push it to pageList
179
228
  await this.getPageById(page.id, langCode).then((result) => {
180
229
  pageList.push(result);
181
230
  });
182
231
  }));
183
- return this._dataPostProcess(pageList, 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);
236
+ }
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);
241
+ }
242
+ /**
243
+ * Add template data to pages
244
+ * @param data
245
+ * @returns
246
+ */
247
+ async addTemplateToPages(data) {
248
+ // Use Promise.all to handle an array of promises returned by mapping over 'data'
249
+ return Promise.all(data.map(async (d) => {
250
+ // For each element 'd' in the 'data' array, call 'addTemplateToPage'
251
+ const result = await this.addTemplateToPage(d);
252
+ // Return the result of 'addTemplateToPage' for the current element
253
+ return result;
254
+ }));
255
+ }
256
+ /**
257
+ * Add template data to page by page templateIdentifier
258
+ * @param data - page object
259
+ * @returns
260
+ */
261
+ async addTemplateToPage(data) {
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
+ }
285
+ }
286
+ else {
287
+ // If 'templateIdentifier' doesn't exist or is invalid, return the original data
288
+ return data;
184
289
  }
185
- return this._normalizeData(searchPages, langCode);
186
290
  }
187
291
  }
188
292
  exports.default = PageApi;
@@ -127,5 +127,6 @@ interface IPagesEntity {
127
127
  products?: number;
128
128
  templateIdentifier: string | null;
129
129
  type: Types;
130
+ template?: any;
130
131
  }
131
132
  export type { IPageApi, IPageConfig, IPagesEntity, IPositionBlock, IPositionForm, };
@@ -295,7 +295,7 @@ class ProductApi extends asyncModules_1.default {
295
295
  */
296
296
  async searchProduct(name, langCode = this.state.lang) {
297
297
  const searchProducts = await this._fetchGet(`/quick/search?langCode=${langCode}&name=${name}`);
298
- if (this.state.multipleResponse) {
298
+ if (!this.state.traficLimit) {
299
299
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
300
300
  const productsList = [];
301
301
  await Promise.all(searchProducts.map(async (product) => {
@@ -63,7 +63,7 @@ class TemplatesPreviewApi extends asyncModules_1.default {
63
63
  * @returns Returns a TemplateEntity object
64
64
  */
65
65
  async getTemplateByMarker(marker, langCode = this.state.lang) {
66
- const result = await this._fetchGet(`/${marker}?langCode=${langCode}`);
66
+ const result = await this._fetchGet(`/marker/${marker}?langCode=${langCode}`);
67
67
  return this._normalizeData(result);
68
68
  }
69
69
  }
@@ -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.121",
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
  }