oneentry 1.0.135 → 1.0.136

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.
@@ -78,6 +78,25 @@ export default abstract class SyncModules {
78
78
  * @returns {any} Schedules with added time intervals.
79
79
  */
80
80
  _addTimeIntervalsToSchedules(schedules: any[]): any;
81
+ /**
82
+ * Generates intervals for a specific date for form schedules.
83
+ * @param {Date} date - The date for which to generate intervals.
84
+ * @param {object} interval - The interval configuration.
85
+ * @param {boolean} interval.inEveryWeek - Indicates whether the schedule is weekly.
86
+ * @param {boolean} interval.inEveryMonth - Indicates whether the schedule is monthly.
87
+ * @param {any[]} timeIntervals - The time intervals to process.
88
+ * @param {Set<Array<string>>} utcIntervals - A set to store unique intervals.
89
+ */
90
+ protected _generateIntervalsForFormDate(date: Date, interval: {
91
+ inEveryWeek: boolean;
92
+ inEveryMonth: boolean;
93
+ }, timeIntervals: any[], utcIntervals: Set<Array<string>>): void;
94
+ /**
95
+ * Adds time intervals to form schedules (different structure).
96
+ * @param {any[]} intervals - The intervals to process.
97
+ * @returns {any} Intervals with added time intervals.
98
+ */
99
+ _addTimeIntervalsToFormSchedules(intervals: any[]): any;
81
100
  /**
82
101
  * Normalizes attributes within the data.
83
102
  * @param {any} data - The data to normalize.
@@ -258,13 +258,124 @@ class SyncModules {
258
258
  });
259
259
  return schedules;
260
260
  }
261
+ /**
262
+ * Generates intervals for a specific date for form schedules.
263
+ * @param {Date} date - The date for which to generate intervals.
264
+ * @param {object} interval - The interval configuration.
265
+ * @param {boolean} interval.inEveryWeek - Indicates whether the schedule is weekly.
266
+ * @param {boolean} interval.inEveryMonth - Indicates whether the schedule is monthly.
267
+ * @param {any[]} timeIntervals - The time intervals to process.
268
+ * @param {Set<Array<string>>} utcIntervals - A set to store unique intervals.
269
+ */
270
+ _generateIntervalsForFormDate(date, interval, timeIntervals, utcIntervals) {
271
+ const generateTimeSlotsForDate = (currentDate) => {
272
+ timeIntervals.forEach((timeInterval) => {
273
+ let currentStart = timeInterval.start;
274
+ const endTime = timeInterval.end;
275
+ while (currentStart.hours < endTime.hours ||
276
+ (currentStart.hours === endTime.hours &&
277
+ currentStart.minutes < endTime.minutes)) {
278
+ const intervalStart = new Date(currentDate);
279
+ intervalStart.setUTCHours(currentStart.hours, currentStart.minutes, 0, 0);
280
+ const nextMinutes = currentStart.minutes + timeInterval.period;
281
+ const nextHours = currentStart.hours + Math.floor(nextMinutes / 60);
282
+ const minutes = nextMinutes % 60;
283
+ if (nextHours > endTime.hours ||
284
+ (nextHours === endTime.hours && minutes > endTime.minutes)) {
285
+ break;
286
+ }
287
+ const intervalEnd = new Date(currentDate);
288
+ intervalEnd.setUTCHours(nextHours, minutes, 0, 0);
289
+ utcIntervals.add([
290
+ intervalStart.toISOString(),
291
+ intervalEnd.toISOString(),
292
+ ]);
293
+ currentStart = { hours: nextHours, minutes };
294
+ }
295
+ });
296
+ };
297
+ // Handle weekly schedules
298
+ if (interval.inEveryWeek && !interval.inEveryMonth) {
299
+ let currentDate = new Date(date);
300
+ const endOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
301
+ while (currentDate <= endOfMonth) {
302
+ generateTimeSlotsForDate(currentDate);
303
+ currentDate = this._addDays(currentDate, 7);
304
+ }
305
+ }
306
+ // Handle monthly schedules
307
+ if (interval.inEveryMonth && !interval.inEveryWeek) {
308
+ const startDate = new Date(date);
309
+ const targetDayOfMonth = startDate.getUTCDate();
310
+ const numberOfMonths = 12;
311
+ for (let i = 0; i < numberOfMonths; i++) {
312
+ const currentDate = new Date(startDate);
313
+ currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
314
+ currentDate.setUTCDate(targetDayOfMonth);
315
+ if (currentDate.getUTCMonth() !== (startDate.getUTCMonth() + i) % 12) {
316
+ continue;
317
+ }
318
+ generateTimeSlotsForDate(currentDate);
319
+ }
320
+ }
321
+ // Handle both weekly and monthly schedules
322
+ if (interval.inEveryMonth && interval.inEveryWeek) {
323
+ const startDate = new Date(date);
324
+ const targetDayOfWeek = startDate.getUTCDay();
325
+ const numberOfMonths = 12;
326
+ for (let i = 0; i < numberOfMonths; i++) {
327
+ const currentDate = new Date(startDate);
328
+ currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
329
+ currentDate.setUTCDate(1);
330
+ const daysUntilTargetDay = (targetDayOfWeek - currentDate.getUTCDay() + 7) % 7;
331
+ currentDate.setUTCDate(currentDate.getUTCDate() + daysUntilTargetDay);
332
+ while (currentDate.getUTCMonth() ===
333
+ (startDate.getUTCMonth() + i) % 12) {
334
+ generateTimeSlotsForDate(currentDate);
335
+ currentDate.setUTCDate(currentDate.getUTCDate() + 7);
336
+ }
337
+ }
338
+ }
339
+ }
340
+ /**
341
+ * Adds time intervals to form schedules (different structure).
342
+ * @param {any[]} intervals - The intervals to process.
343
+ * @returns {any} Intervals with added time intervals.
344
+ */
345
+ _addTimeIntervalsToFormSchedules(intervals) {
346
+ intervals.forEach((interval) => {
347
+ var _a, _b;
348
+ if (!interval.intervals || !Array.isArray(interval.intervals)) {
349
+ return;
350
+ }
351
+ const utcIntervals = new Set();
352
+ const startDate = new Date(interval.range[0]);
353
+ const endDate = new Date(interval.range[1]);
354
+ const isSameDay = startDate.toISOString() === endDate.toISOString();
355
+ const intervalConfig = {
356
+ inEveryWeek: (_a = interval.inEveryWeek) !== null && _a !== void 0 ? _a : false,
357
+ inEveryMonth: (_b = interval.inEveryMonth) !== null && _b !== void 0 ? _b : false,
358
+ };
359
+ if (isSameDay) {
360
+ this._generateIntervalsForFormDate(startDate, intervalConfig, interval.intervals, utcIntervals);
361
+ }
362
+ else {
363
+ for (let currentDate = new Date(startDate); currentDate <= endDate; currentDate = this._addDays(currentDate, 1)) {
364
+ this._generateIntervalsForFormDate(currentDate, intervalConfig, interval.intervals, utcIntervals);
365
+ }
366
+ }
367
+ interval.timeIntervals = Array.from(utcIntervals).sort();
368
+ });
369
+ return intervals;
370
+ }
261
371
  /**
262
372
  * Normalizes attributes within the data.
263
373
  * @param {any} data - The data to normalize.
264
374
  * @returns {any} Normalized attributes.
265
375
  */
266
376
  _normalizeAttr(data) {
267
- // For regular attributes collections
377
+ var _a;
378
+ // For regular attributes collections - pages, products, etc.
268
379
  if ('attributeValues' in data) {
269
380
  for (const attr in data.attributeValues) {
270
381
  const d = data.attributeValues[attr];
@@ -288,33 +399,43 @@ class SyncModules {
288
399
  attributeValues: this._sortAttributes(data.attributeValues),
289
400
  };
290
401
  }
291
- // for forms attributes
402
+ // for forms attributes - forms attributes collections
292
403
  if ('attributes' in data) {
293
404
  const d = data.attributes;
294
- // console.log('Schedules:: ', JSON.stringify(d));
295
405
  for (const attr in d) {
296
406
  // Normalize numbers
297
- if (d[attr].type === 'integer' || d[attr].type === 'float') {
298
- const numValue = Number(d[attr].value);
299
- d[attr].value = isNaN(numValue) ? null : numValue;
300
- }
407
+ // if (d[attr].type === 'integer' || d[attr].type === 'float') {
408
+ // const numValue = Number(d[attr].value);
409
+ // d[attr].value = isNaN(numValue) ? null : numValue;
410
+ // }
301
411
  // Add time intervals
302
412
  if (d[attr].type === 'timeInterval') {
303
- // const schedules = d[attr].localizeInfos.intervals;
304
- // console.log('Schedules:: ', JSON.stringify(schedules));
305
- // if (Array.isArray(schedules) && schedules.length > 0) {
306
- // const result = this._addTimeIntervalsToSchedulesForm(schedules);
307
- // d[attr].localizeInfos.intervals = result;
308
- // }
413
+ const intervals = (_a = d[attr].localizeInfos) === null || _a === void 0 ? void 0 : _a.intervals;
414
+ // console.log('Schedules:: ', JSON.stringify(intervals));
415
+ if (intervals && Array.isArray(intervals) && intervals.length > 0) {
416
+ const result = this._addTimeIntervalsToFormSchedules(intervals);
417
+ d[attr].localizeInfos.intervals = result;
418
+ }
309
419
  }
310
420
  }
311
421
  return data;
312
422
  }
313
- // !!! For single attribute
314
- if ('attributes' in data) {
315
- // console.log('Schedules:: ', JSON.stringify(data));
423
+ // For single attribute - for attribute sets
424
+ if ('type' in data) {
425
+ // Normalize numbers
426
+ if (data.type === 'integer' || data.type === 'float') {
427
+ const numValue = Number(data.value);
428
+ data.value = isNaN(numValue) ? null : numValue;
429
+ }
430
+ // Add time intervals
431
+ if (data.type === 'timeInterval') {
432
+ const schedules = data.value;
433
+ if (Array.isArray(schedules) && schedules.length > 0) {
434
+ const result = this._addTimeIntervalsToSchedules(schedules);
435
+ data.value = result;
436
+ }
437
+ }
316
438
  }
317
- // console.log('Schedules:: ', JSON.stringify(data));
318
439
  return data;
319
440
  }
320
441
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneentry",
3
- "version": "1.0.135",
3
+ "version": "1.0.136",
4
4
  "description": "OneEntry NPM package",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",