oneentry 1.0.121 → 1.0.122

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.
@@ -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;
@@ -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
  }
@@ -88,4 +88,16 @@ export default class PageApi extends AsyncModules implements IPageApi {
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
+ * addTemplateToPages
93
+ * @param data
94
+ * @returns
95
+ */
96
+ protected addTemplateToPages(data: IPagesEntity[]): Promise<IPagesEntity[]>;
97
+ /**
98
+ * addTemplateToPage 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
@@ -22,7 +23,8 @@ class PageApi extends asyncModules_1.default {
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
+ const data = await this._fetchGet(`/root?langCode=${langCode}`);
27
+ const result = await this.addTemplateToPages(data);
26
28
  return this._normalizeData(result, langCode);
27
29
  }
28
30
  /**
@@ -33,7 +35,8 @@ class PageApi extends asyncModules_1.default {
33
35
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
34
36
  */
35
37
  async getPages(langCode = this.state.lang) {
36
- const result = await this._fetchGet(`?langCode=${langCode}`);
38
+ const data = await this._fetchGet(`?langCode=${langCode}`);
39
+ const result = await this.addTemplateToPages(data);
37
40
  return this._normalizeData(result, langCode);
38
41
  }
39
42
  /**
@@ -45,7 +48,8 @@ class PageApi extends asyncModules_1.default {
45
48
  * @returns Returns PageEntity object
46
49
  */
47
50
  async getPageById(id, langCode = this.state.lang) {
48
- const result = await this._fetchGet(`/${id}?langCode=${langCode}`);
51
+ const data = await this._fetchGet(`/${id}?langCode=${langCode}`);
52
+ const result = await this.addTemplateToPage(data);
49
53
  return this._normalizeData(result, langCode);
50
54
  }
51
55
  /**
@@ -58,7 +62,8 @@ class PageApi extends asyncModules_1.default {
58
62
  */
59
63
  async getPageByUrl(url, langCode = this.state.lang) {
60
64
  const data = await this._fetchGet(`/url/${url}?langCode=${langCode}`);
61
- return this._normalizeData(data, langCode);
65
+ const result = await this.addTemplateToPage(data);
66
+ return this._normalizeData(result, langCode);
62
67
  }
63
68
  /**
64
69
  * Get child pages object with information as an array.
@@ -70,7 +75,8 @@ class PageApi extends asyncModules_1.default {
70
75
  */
71
76
  async getChildPagesByParentUrl(url, langCode = this.state.lang) {
72
77
  const data = await this._fetchGet(`/${url}/children?langCode=${langCode}`);
73
- return this._normalizeData(data, langCode);
78
+ const result = await this.addTemplateToPages(data);
79
+ return this._normalizeData(result, langCode);
74
80
  }
75
81
  /**
76
82
  * Get all blocks by page url.
@@ -97,7 +103,7 @@ class PageApi extends asyncModules_1.default {
97
103
  delete item.attributesSetIdentifier;
98
104
  return item;
99
105
  });
100
- if (this.state.multipleResponse) {
106
+ if (!this.state.traficLimit) {
101
107
  class StaffModule extends asyncModules_1.default {
102
108
  constructor(state) {
103
109
  super(state);
@@ -172,17 +178,50 @@ class PageApi extends asyncModules_1.default {
172
178
  * @returns Returns all created pages as an array of PageEntity objects or an empty array [] (if there is no data)
173
179
  */
174
180
  async searchPage(name, langCode = this.state.lang) {
175
- const searchPages = await this._fetchGet(`/quick/search?lang=${langCode}&name=${name}`);
176
- if (this.state.multipleResponse) {
181
+ const data = await this._fetchGet(`/quick/search?lang=${langCode}&name=${name}`);
182
+ if (!this.state.traficLimit) {
177
183
  const pageList = [];
178
- await Promise.all(searchPages.map(async (page) => {
184
+ await Promise.all(data.map(async (page) => {
179
185
  await this.getPageById(page.id, langCode).then((result) => {
180
186
  pageList.push(result);
181
187
  });
182
188
  }));
183
- return this._dataPostProcess(pageList, langCode);
189
+ const result = await this.addTemplateToPages(pageList);
190
+ return this._dataPostProcess(result, langCode);
191
+ }
192
+ const result = await this.addTemplateToPages(data);
193
+ return this._normalizeData(result, langCode);
194
+ }
195
+ /**
196
+ * addTemplateToPages
197
+ * @param data
198
+ * @returns
199
+ */
200
+ async addTemplateToPages(data) {
201
+ return Promise.all(data.map(async (d) => {
202
+ const result = await this.addTemplateToPage(d);
203
+ return result;
204
+ }));
205
+ }
206
+ /**
207
+ * addTemplateToPage by page templateIdentifier
208
+ * @param data - page object
209
+ * @returns
210
+ */
211
+ 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
+ };
221
+ }
222
+ else {
223
+ return data;
184
224
  }
185
- return this._normalizeData(searchPages, langCode);
186
225
  }
187
226
  }
188
227
  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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.121",
3
+ "version": "1.0.122",
4
4
  "description": "OneEntry NPM package",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",