oneentry 1.0.139 → 1.0.140

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 (143) hide show
  1. package/README.md +16 -1
  2. package/configure.js +40 -21
  3. package/package.json +15 -12
  4. package/dist/admins/adminsApi.d.ts +0 -50
  5. package/dist/admins/adminsApi.js +0 -65
  6. package/dist/admins/adminsInterfaces.d.ts +0 -99
  7. package/dist/admins/adminsInterfaces.js +0 -2
  8. package/dist/admins/adminsSchemas.d.ts +0 -30
  9. package/dist/admins/adminsSchemas.js +0 -27
  10. package/dist/attribute-sets/attributeSetsApi.d.ts +0 -63
  11. package/dist/attribute-sets/attributeSetsApi.js +0 -98
  12. package/dist/attribute-sets/attributeSetsInterfaces.d.ts +0 -187
  13. package/dist/attribute-sets/attributeSetsInterfaces.js +0 -2
  14. package/dist/attribute-sets/attributeSetsSchemas.d.ts +0 -90
  15. package/dist/attribute-sets/attributeSetsSchemas.js +0 -74
  16. package/dist/auth-provider/authProviderApi.d.ts +0 -249
  17. package/dist/auth-provider/authProviderApi.js +0 -351
  18. package/dist/auth-provider/authProviderSchemas.d.ts +0 -137
  19. package/dist/auth-provider/authProviderSchemas.js +0 -85
  20. package/dist/auth-provider/authProvidersInterfaces.d.ts +0 -417
  21. package/dist/auth-provider/authProvidersInterfaces.js +0 -2
  22. package/dist/base/asyncModules.d.ts +0 -80
  23. package/dist/base/asyncModules.js +0 -440
  24. package/dist/base/result.d.ts +0 -39
  25. package/dist/base/result.js +0 -154
  26. package/dist/base/stateModule.d.ts +0 -41
  27. package/dist/base/stateModule.js +0 -128
  28. package/dist/base/syncModules.d.ts +0 -149
  29. package/dist/base/syncModules.js +0 -549
  30. package/dist/base/utils.d.ts +0 -197
  31. package/dist/base/utils.js +0 -2
  32. package/dist/base/validation.d.ts +0 -118
  33. package/dist/base/validation.js +0 -132
  34. package/dist/blocks/blocksApi.d.ts +0 -74
  35. package/dist/blocks/blocksApi.js +0 -184
  36. package/dist/blocks/blocksInterfaces.d.ts +0 -173
  37. package/dist/blocks/blocksInterfaces.js +0 -2
  38. package/dist/blocks/blocksSchemas.d.ts +0 -187
  39. package/dist/blocks/blocksSchemas.js +0 -43
  40. package/dist/events/eventsApi.d.ts +0 -60
  41. package/dist/events/eventsApi.js +0 -97
  42. package/dist/events/eventsInterfaces.d.ts +0 -87
  43. package/dist/events/eventsInterfaces.js +0 -2
  44. package/dist/file-uploading/fileUploadingApi.d.ts +0 -88
  45. package/dist/file-uploading/fileUploadingApi.js +0 -132
  46. package/dist/file-uploading/fileUploadingInterfaces.d.ts +0 -117
  47. package/dist/file-uploading/fileUploadingInterfaces.js +0 -2
  48. package/dist/file-uploading/fileUploadingSchemas.d.ts +0 -22
  49. package/dist/file-uploading/fileUploadingSchemas.js +0 -21
  50. package/dist/forms/formsApi.d.ts +0 -42
  51. package/dist/forms/formsApi.js +0 -57
  52. package/dist/forms/formsInterfaces.d.ts +0 -132
  53. package/dist/forms/formsInterfaces.js +0 -2
  54. package/dist/forms/formsSchemas.d.ts +0 -65
  55. package/dist/forms/formsSchemas.js +0 -36
  56. package/dist/forms-data/formsDataApi.d.ts +0 -106
  57. package/dist/forms-data/formsDataApi.js +0 -189
  58. package/dist/forms-data/formsDataInterfaces.d.ts +0 -525
  59. package/dist/forms-data/formsDataInterfaces.js +0 -2
  60. package/dist/forms-data/formsDataSchemas.d.ts +0 -115
  61. package/dist/forms-data/formsDataSchemas.js +0 -86
  62. package/dist/general-types/generalTypesApi.d.ts +0 -28
  63. package/dist/general-types/generalTypesApi.js +0 -38
  64. package/dist/general-types/generalTypesInterfaces.d.ts +0 -30
  65. package/dist/general-types/generalTypesInterfaces.js +0 -2
  66. package/dist/general-types/generalTypesSchemas.d.ts +0 -50
  67. package/dist/general-types/generalTypesSchemas.js +0 -35
  68. package/dist/index.d.ts +0 -94
  69. package/dist/index.js +0 -97
  70. package/dist/integration-collections/integrationCollectionsApi.d.ts +0 -173
  71. package/dist/integration-collections/integrationCollectionsApi.js +0 -220
  72. package/dist/integration-collections/integrationCollectionsInterfaces.d.ts +0 -313
  73. package/dist/integration-collections/integrationCollectionsInterfaces.js +0 -2
  74. package/dist/integration-collections/integrationCollectionsSchemas.d.ts +0 -84
  75. package/dist/integration-collections/integrationCollectionsSchemas.js +0 -63
  76. package/dist/locales/localesApi.d.ts +0 -27
  77. package/dist/locales/localesApi.js +0 -37
  78. package/dist/locales/localesInterfaces.d.ts +0 -41
  79. package/dist/locales/localesInterfaces.js +0 -2
  80. package/dist/locales/localesSchemas.d.ts +0 -32
  81. package/dist/locales/localesSchemas.js +0 -26
  82. package/dist/menus/menusApi.d.ts +0 -29
  83. package/dist/menus/menusApi.js +0 -39
  84. package/dist/menus/menusInterfaces.d.ts +0 -88
  85. package/dist/menus/menusInterfaces.js +0 -4
  86. package/dist/menus/menusSchemas.d.ts +0 -16
  87. package/dist/menus/menusSchemas.js +0 -28
  88. package/dist/orders/ordersApi.d.ts +0 -126
  89. package/dist/orders/ordersApi.js +0 -169
  90. package/dist/orders/ordersInterfaces.d.ts +0 -427
  91. package/dist/orders/ordersInterfaces.js +0 -2
  92. package/dist/orders/ordersSchemas.d.ts +0 -158
  93. package/dist/orders/ordersSchemas.js +0 -120
  94. package/dist/pages/pagesApi.d.ts +0 -151
  95. package/dist/pages/pagesApi.js +0 -390
  96. package/dist/pages/pagesInterfaces.d.ts +0 -292
  97. package/dist/pages/pagesInterfaces.js +0 -2
  98. package/dist/pages/pagesSchemas.d.ts +0 -85
  99. package/dist/pages/pagesSchemas.js +0 -46
  100. package/dist/payments/paymentsApi.d.ts +0 -82
  101. package/dist/payments/paymentsApi.js +0 -121
  102. package/dist/payments/paymentsInterfaces.d.ts +0 -206
  103. package/dist/payments/paymentsInterfaces.js +0 -2
  104. package/dist/payments/paymentsSchemas.d.ts +0 -137
  105. package/dist/payments/paymentsSchemas.js +0 -78
  106. package/dist/product-statuses/productStatusesApi.d.ts +0 -47
  107. package/dist/product-statuses/productStatusesApi.js +0 -70
  108. package/dist/product-statuses/productStatusesInterfaces.d.ts +0 -66
  109. package/dist/product-statuses/productStatusesInterfaces.js +0 -2
  110. package/dist/product-statuses/productStatusesSchemas.d.ts +0 -34
  111. package/dist/product-statuses/productStatusesSchemas.js +0 -30
  112. package/dist/products/productsApi.d.ts +0 -364
  113. package/dist/products/productsApi.js +0 -455
  114. package/dist/products/productsInterfaces.d.ts +0 -583
  115. package/dist/products/productsInterfaces.js +0 -2
  116. package/dist/products/productsSchemas.d.ts +0 -212
  117. package/dist/products/productsSchemas.js +0 -85
  118. package/dist/system/systemApi.d.ts +0 -65
  119. package/dist/system/systemApi.js +0 -82
  120. package/dist/system/systemInterfaces.d.ts +0 -23
  121. package/dist/system/systemInterfaces.js +0 -2
  122. package/dist/templates/templatesApi.d.ts +0 -49
  123. package/dist/templates/templatesApi.js +0 -75
  124. package/dist/templates/templatesInterfaces.d.ts +0 -70
  125. package/dist/templates/templatesInterfaces.js +0 -2
  126. package/dist/templates/templatesSchemas.d.ts +0 -48
  127. package/dist/templates/templatesSchemas.js +0 -31
  128. package/dist/templates-preview/templatesPreviewApi.d.ts +0 -38
  129. package/dist/templates-preview/templatesPreviewApi.js +0 -53
  130. package/dist/templates-preview/templatesPreviewInterfaces.d.ts +0 -121
  131. package/dist/templates-preview/templatesPreviewInterfaces.js +0 -2
  132. package/dist/templates-preview/templatesPreviewSchemas.d.ts +0 -83
  133. package/dist/templates-preview/templatesPreviewSchemas.js +0 -48
  134. package/dist/users/usersApi.d.ts +0 -143
  135. package/dist/users/usersApi.js +0 -174
  136. package/dist/users/usersInterfaces.d.ts +0 -235
  137. package/dist/users/usersInterfaces.js +0 -2
  138. package/dist/users/usersSchemas.d.ts +0 -38
  139. package/dist/users/usersSchemas.js +0 -28
  140. package/dist/web-socket/wsApi.d.ts +0 -25
  141. package/dist/web-socket/wsApi.js +0 -45
  142. package/dist/web-socket/wsInterfaces.d.ts +0 -17
  143. package/dist/web-socket/wsInterfaces.js +0 -2
@@ -1,549 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- // Browser: module-level persistent device ID (localStorage-backed)
4
- let _persistentDeviceId = null;
5
- function _getBrowserDeviceId() {
6
- const win = typeof globalThis !== 'undefined' ? globalThis.window : undefined;
7
- if (!(win === null || win === void 0 ? void 0 : win.localStorage))
8
- return null;
9
- if (_persistentDeviceId)
10
- return _persistentDeviceId;
11
- try {
12
- const stored = win.localStorage.getItem('oneentry_device_id');
13
- if (stored) {
14
- _persistentDeviceId = stored;
15
- return _persistentDeviceId;
16
- }
17
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
- }
19
- catch (_e) {
20
- // ignore
21
- }
22
- const id = Date.now().toString(36) +
23
- Math.random().toString(36).substring(2, 15) +
24
- Math.random().toString(36).substring(2, 15);
25
- _persistentDeviceId = id;
26
- try {
27
- win.localStorage.setItem('oneentry_device_id', id);
28
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- }
30
- catch (_e) {
31
- // ignore
32
- }
33
- return _persistentDeviceId;
34
- }
35
- /**
36
- * Abstract class representing synchronization modules.
37
- */
38
- class SyncModules {
39
- /**
40
- * Constructor to initialize state and URL.
41
- * @param {StateModule} state - StateModule instance.
42
- */
43
- constructor(state) {
44
- /**
45
- * Sorts attributes by their positions.
46
- * @param {any} data - The data containing attributes.
47
- * @returns {any} Sorted attributes.
48
- */
49
- this._sortAttributes = (data) => Object.fromEntries(Object.entries(data).sort(([, a], [, b]) => a.position - b.position));
50
- this.state = state;
51
- this._url = state.url;
52
- this._nodeDeviceId =
53
- Date.now().toString(36) +
54
- Math.random().toString(36).substring(2, 15) +
55
- Math.random().toString(36).substring(2, 15);
56
- }
57
- /**
58
- * Constructs the full URL path by appending the given path to the base URL.
59
- * @param {string} path - The path to append to the base URL.
60
- * @returns {string} The full URL as a string.
61
- */
62
- _getFullPath(path) {
63
- return this._url + path;
64
- }
65
- /**
66
- * Converts query parameters into a query string.
67
- * @param {IProductsQuery | IUploadingQuery | any} query - The query object containing key-value pairs.
68
- * @returns {string} A string representation of the query parameters.
69
- */
70
- _queryParamsToString(query) {
71
- let result = '';
72
- for (const key in query) {
73
- if (query[key] !== null) {
74
- result += `${key}=${query[key]}&`;
75
- }
76
- }
77
- return result.slice(0, result.length - 1);
78
- }
79
- /**
80
- * Normalizes data based on language code.
81
- * @param {any} data - The data to normalize.
82
- * @param {string} langCode - The language code for normalization.
83
- * @returns {any} Normalized data.
84
- */
85
- _normalizeData(data, langCode = this.state.lang) {
86
- if (Array.isArray(data)) {
87
- return this._normalizeAttr(data.map((item) => this._normalizeData(item, langCode)));
88
- }
89
- else if (typeof data === 'object' && data) {
90
- const normalizeData = {};
91
- for (const key in data) {
92
- if (Array.isArray(data[key])) {
93
- normalizeData[key] = this._normalizeData(data[key], langCode);
94
- }
95
- else if (!data[key] || typeof data[key] !== 'object') {
96
- normalizeData[key] = data[key];
97
- }
98
- else if (langCode in data[key]) {
99
- normalizeData[key] = data[key][langCode];
100
- }
101
- else {
102
- normalizeData[key] = this._normalizeData(data[key], langCode);
103
- }
104
- }
105
- return this._normalizeAttr(normalizeData);
106
- }
107
- else {
108
- return data;
109
- }
110
- }
111
- /**
112
- * Normalizes the body of a POST request.
113
- * @param {any} body - The body to normalize.
114
- * @param {string} [langCode] - The language code for normalization.
115
- * @returns {any} Normalized body.
116
- */
117
- _normalizePostBody(body, langCode = this.state.lang) {
118
- const formData = {};
119
- formData[langCode] = Array.isArray(body.formData)
120
- ? body.formData
121
- : [body.formData];
122
- body.formData = formData;
123
- return body;
124
- }
125
- /**
126
- * Clears arrays within the data structure.
127
- * @param {Record<string, any>} data - The data to clear.
128
- * @returns {any} Cleared data.
129
- */
130
- _clearArray(data) {
131
- if (Array.isArray(data)) {
132
- return data.map((item) => this._clearArray(item));
133
- }
134
- else if (typeof data === 'object' && data) {
135
- const normalizeData = {};
136
- for (const key in data) {
137
- if (Array.isArray(data[key])) {
138
- normalizeData[key] = this._clearArray(data[key]);
139
- }
140
- else if (!data[key] || typeof data[key] !== 'object') {
141
- normalizeData[key] = data[key];
142
- }
143
- else if (key === 'attributeValues') {
144
- const attrs = data[key];
145
- for (const attr in attrs) {
146
- if (attrs[attr].type === 'image' &&
147
- attrs[attr].value.length === 1) {
148
- attrs[attr].value = attrs[attr].value[0];
149
- }
150
- }
151
- normalizeData[key] = data[key];
152
- }
153
- else {
154
- normalizeData[key] = this._clearArray(data[key]);
155
- }
156
- }
157
- return normalizeData;
158
- }
159
- else {
160
- return data;
161
- }
162
- }
163
- /**
164
- * Adds a specified number of days to a date.
165
- * @param {Date} date - The initial date.
166
- * @param {number} days - The number of days to add.
167
- * @returns {any} The new date with added days.
168
- */
169
- _addDays(date, days) {
170
- const result = new Date(date);
171
- result.setUTCDate(result.getUTCDate() + days);
172
- return result;
173
- }
174
- /**
175
- * Common logic for processing schedule dates (weekly, monthly, or both).
176
- * @param {Date} date - The date for which to process intervals.
177
- * @param {object} config - Configuration for schedule repetition.
178
- * @param {boolean} config.inEveryWeek - Whether to repeat weekly.
179
- * @param {boolean} config.inEveryMonth - Whether to repeat monthly.
180
- * @param {Function} processDate - Callback function to process each date.
181
- */
182
- _processScheduleDates(date, config, processDate) {
183
- // Handle weekly schedules
184
- if (config.inEveryWeek && !config.inEveryMonth) {
185
- let currentDate = new Date(date);
186
- // Calculate the last day of the current month
187
- const endOfMonth = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0);
188
- while (currentDate <= endOfMonth) {
189
- processDate(currentDate);
190
- // Move to the next week
191
- currentDate = this._addDays(currentDate, 7);
192
- }
193
- }
194
- // Handle monthly schedules
195
- if (config.inEveryMonth && !config.inEveryWeek) {
196
- const startDate = new Date(date);
197
- const targetDayOfMonth = startDate.getUTCDate();
198
- const numberOfMonths = 12;
199
- for (let i = 0; i < numberOfMonths; i++) {
200
- const currentDate = new Date(startDate);
201
- currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
202
- // Try setting the current date to the target day of the month
203
- currentDate.setUTCDate(targetDayOfMonth);
204
- // Check if we have exceeded the month
205
- if (currentDate.getUTCMonth() !== (startDate.getUTCMonth() + i) % 12) {
206
- continue; // Skip this month if exceeded
207
- }
208
- processDate(currentDate);
209
- }
210
- }
211
- // Handle both weekly and monthly schedules
212
- if (config.inEveryMonth && config.inEveryWeek) {
213
- const startDate = new Date(date);
214
- const targetDayOfWeek = startDate.getUTCDay();
215
- const numberOfMonths = 12;
216
- for (let i = 0; i < numberOfMonths; i++) {
217
- const currentDate = new Date(startDate);
218
- currentDate.setUTCMonth(currentDate.getUTCMonth() + i);
219
- // Set to the first day of the month
220
- currentDate.setUTCDate(1);
221
- // Find the first target day of the week in the current month
222
- const daysUntilTargetDay = (targetDayOfWeek - currentDate.getUTCDay() + 7) % 7;
223
- currentDate.setUTCDate(currentDate.getUTCDate() + daysUntilTargetDay);
224
- // Iterate over all target days of the week in the current month
225
- while (currentDate.getUTCMonth() ===
226
- (startDate.getUTCMonth() + i) % 12) {
227
- processDate(currentDate);
228
- // Move to the next week (same day of the week)
229
- currentDate.setUTCDate(currentDate.getUTCDate() + 7);
230
- }
231
- }
232
- }
233
- }
234
- /**
235
- * Generates intervals for a specific date based on a schedule.
236
- * @param {Date} date - The date for which to generate intervals.
237
- * @param {object} schedule - The schedule defining the intervals.
238
- * @param {boolean} schedule.inEveryWeek - The number of weeks between intervals.
239
- * @param {any[]} schedule.times - The times for each interval.
240
- * @param {boolean} schedule.inEveryMonth - The month intervals for each interval.
241
- * @param {Set<Array<string>>} utcIntervals - A set to store unique intervals.
242
- */
243
- _generateIntervalsForDate(date, schedule, utcIntervals) {
244
- this._processScheduleDates(date, schedule, (currentDate) => {
245
- schedule.times.forEach((timeRange) => {
246
- const [startTime, endTime] = timeRange;
247
- const intervalStart = new Date(currentDate);
248
- intervalStart.setUTCHours(startTime.hours, startTime.minutes, 0, 0);
249
- const intervalEnd = new Date(currentDate);
250
- intervalEnd.setUTCHours(endTime.hours, endTime.minutes, 0, 0);
251
- utcIntervals.add([
252
- intervalStart.toISOString(),
253
- intervalEnd.toISOString(),
254
- ]);
255
- });
256
- });
257
- }
258
- /**
259
- * Adds time intervals to schedules.
260
- * @param {any[]} schedules - The schedules to process.
261
- * @returns {any} Schedules with added time intervals.
262
- */
263
- _addTimeIntervalsToSchedules(schedules) {
264
- schedules === null || schedules === void 0 ? void 0 : schedules.forEach((scheduleGroup) => {
265
- // Skip if scheduleGroup.values is not an array
266
- if (!scheduleGroup ||
267
- !scheduleGroup.values ||
268
- !Array.isArray(scheduleGroup.values)) {
269
- return;
270
- }
271
- scheduleGroup.values.forEach((schedule) => {
272
- const utcIntervals = new Set();
273
- const startDate = new Date(schedule.dates[0]);
274
- const endDate = new Date(schedule.dates[1]);
275
- const isSameDay = startDate.toISOString() === endDate.toISOString();
276
- if (isSameDay) {
277
- this._generateIntervalsForDate(startDate, schedule, utcIntervals);
278
- }
279
- else {
280
- for (let currentDate = new Date(startDate); currentDate <= endDate; currentDate = this._addDays(currentDate, 1)) {
281
- this._generateIntervalsForDate(currentDate, schedule, utcIntervals);
282
- }
283
- }
284
- schedule.timeIntervals = Array.from(utcIntervals).sort();
285
- });
286
- });
287
- return schedules;
288
- }
289
- /**
290
- * Generates intervals for a specific date for form schedules.
291
- * @param {Date} date - The date for which to generate intervals.
292
- * @param {object} interval - The interval configuration.
293
- * @param {boolean} interval.inEveryWeek - Indicates whether the schedule is weekly.
294
- * @param {boolean} interval.inEveryMonth - Indicates whether the schedule is monthly.
295
- * @param {any[]} timeIntervals - The time intervals to process.
296
- * @param {Set<Array<string>>} utcIntervals - A set to store unique intervals.
297
- */
298
- _generateIntervalsForFormDate(date, interval, timeIntervals, utcIntervals) {
299
- const generateTimeSlotsForDate = (currentDate) => {
300
- timeIntervals.forEach((timeInterval) => {
301
- let currentStart = timeInterval.start;
302
- const endTime = timeInterval.end;
303
- while (currentStart.hours < endTime.hours ||
304
- (currentStart.hours === endTime.hours &&
305
- currentStart.minutes < endTime.minutes)) {
306
- const intervalStart = new Date(currentDate);
307
- intervalStart.setUTCHours(currentStart.hours, currentStart.minutes, 0, 0);
308
- const nextMinutes = currentStart.minutes + timeInterval.period;
309
- const nextHours = currentStart.hours + Math.floor(nextMinutes / 60);
310
- const minutes = nextMinutes % 60;
311
- if (nextHours > endTime.hours ||
312
- (nextHours === endTime.hours && minutes > endTime.minutes)) {
313
- break;
314
- }
315
- const intervalEnd = new Date(currentDate);
316
- intervalEnd.setUTCHours(nextHours, minutes, 0, 0);
317
- utcIntervals.add([
318
- intervalStart.toISOString(),
319
- intervalEnd.toISOString(),
320
- ]);
321
- currentStart = { hours: nextHours, minutes };
322
- }
323
- });
324
- };
325
- this._processScheduleDates(date, interval, generateTimeSlotsForDate);
326
- }
327
- /**
328
- * Adds time intervals to form schedules (different structure).
329
- * @param {any[]} intervals - The intervals to process.
330
- * @returns {any} Intervals with added time intervals.
331
- */
332
- _addTimeIntervalsToFormSchedules(intervals) {
333
- intervals.forEach((interval) => {
334
- var _a, _b;
335
- if (!interval.intervals || !Array.isArray(interval.intervals)) {
336
- return;
337
- }
338
- const utcIntervals = new Set();
339
- const startDate = new Date(interval.range[0]);
340
- const endDate = new Date(interval.range[1]);
341
- const isSameDay = startDate.toISOString() === endDate.toISOString();
342
- const intervalConfig = {
343
- inEveryWeek: (_a = interval.inEveryWeek) !== null && _a !== void 0 ? _a : false,
344
- inEveryMonth: (_b = interval.inEveryMonth) !== null && _b !== void 0 ? _b : false,
345
- };
346
- if (isSameDay) {
347
- this._generateIntervalsForFormDate(startDate, intervalConfig, interval.intervals, utcIntervals);
348
- }
349
- else {
350
- for (let currentDate = new Date(startDate); currentDate <= endDate; currentDate = this._addDays(currentDate, 1)) {
351
- this._generateIntervalsForFormDate(currentDate, intervalConfig, interval.intervals, utcIntervals);
352
- }
353
- }
354
- interval.timeIntervals = Array.from(utcIntervals).sort();
355
- });
356
- return intervals;
357
- }
358
- /**
359
- * Transforms additionalFields from array to object keyed by marker.
360
- * Skipped when rawData is enabled in config.
361
- * @param {any} attr - The attribute object that may contain additionalFields.
362
- */
363
- _normalizeAdditionalFields(attr) {
364
- if (!this.state.rawData && Array.isArray(attr.additionalFields)) {
365
- attr.additionalFields = Object.fromEntries(attr.additionalFields.map((field) => [field.marker, field]));
366
- }
367
- }
368
- /**
369
- * Normalizes attributes within the data.
370
- * @param {any} data - The data to normalize.
371
- * @returns {any} Normalized attributes.
372
- */
373
- _normalizeAttr(data) {
374
- var _a;
375
- // For regular attributes collections - pages, products, etc.
376
- if ('attributeValues' in data) {
377
- for (const attr in data.attributeValues) {
378
- const d = data.attributeValues[attr];
379
- this._normalizeAdditionalFields(d);
380
- // normalize numbers
381
- if (d.type === 'integer' || d.type === 'float') {
382
- const numValue = Number(d.value);
383
- d.value = isNaN(numValue) ? null : numValue;
384
- }
385
- // add timeIntervals
386
- if (data.attributeValues[attr].type === 'timeInterval') {
387
- const schedules = data.attributeValues[attr].value;
388
- // console.log('Schedules: ', JSON.stringify(schedules));
389
- if (Array.isArray(schedules) && schedules.length > 0) {
390
- const result = this._addTimeIntervalsToSchedules(schedules);
391
- data.attributeValues[attr].value = result;
392
- }
393
- }
394
- }
395
- return {
396
- ...data,
397
- attributeValues: this._sortAttributes(data.attributeValues),
398
- };
399
- }
400
- // for forms attributes - forms attributes collections
401
- if ('attributes' in data) {
402
- const d = data.attributes;
403
- for (const attr in d) {
404
- this._normalizeAdditionalFields(d[attr]);
405
- // Normalize numbers
406
- // if (d[attr].type === 'integer' || d[attr].type === 'float') {
407
- // const numValue = Number(d[attr].value);
408
- // d[attr].value = isNaN(numValue) ? null : numValue;
409
- // }
410
- // Add time intervals
411
- if (d[attr].type === 'timeInterval') {
412
- const intervals = (_a = d[attr].localizeInfos) === null || _a === void 0 ? void 0 : _a.intervals;
413
- // console.log('Schedules:: ', JSON.stringify(intervals));
414
- if (intervals && Array.isArray(intervals) && intervals.length > 0) {
415
- const result = this._addTimeIntervalsToFormSchedules(intervals);
416
- d[attr].localizeInfos.intervals = result;
417
- }
418
- }
419
- }
420
- return data;
421
- }
422
- // For single attribute - for attribute sets
423
- if ('type' in data) {
424
- this._normalizeAdditionalFields(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
- }
438
- }
439
- return data;
440
- }
441
- /**
442
- * Processes data after fetching or receiving it.
443
- * @param {any} data - The data to process.
444
- * @param {any} [langCode] - The language code for processing.
445
- * @returns {any} Processed data.
446
- */
447
- _dataPostProcess(data, langCode = this.state.lang) {
448
- const normalize = this._normalizeData(data, langCode);
449
- const result = this._clearArray(normalize);
450
- return result;
451
- }
452
- /**
453
- * Sets the access token in the state.
454
- * @param {string} accessToken - The access token to set.
455
- * @returns {any} The instance of SyncModules for chaining.
456
- */
457
- setAccessToken(accessToken) {
458
- this.state.accessToken = accessToken;
459
- return this;
460
- }
461
- /**
462
- * Sets the refresh token in the state.
463
- * @param {string} refreshToken - The refresh token to set.
464
- * @returns {any} The instance of SyncModules for chaining.
465
- */
466
- setRefreshToken(refreshToken) {
467
- this.state.refreshToken = refreshToken;
468
- return this;
469
- }
470
- /**
471
- * Get deviceMetadata
472
- * @returns {string} - Returns an object containing device metadata.
473
- */
474
- _getDeviceMetadata() {
475
- var _a;
476
- // Check if we're in a browser environment
477
- if (typeof globalThis === 'undefined') {
478
- return '';
479
- }
480
- // Access navigator through globalThis.window object to avoid direct reference
481
- const win = globalThis.window;
482
- const instanceId = (_a = _getBrowserDeviceId()) !== null && _a !== void 0 ? _a : this._nodeDeviceId;
483
- // Node.js environment
484
- if (!win) {
485
- return JSON.stringify({
486
- fingerprint: `UQ_${instanceId}`,
487
- deviceInfo: {
488
- os: 'Node.js',
489
- browser: `Node.js/${instanceId.substring(0, 10)}`,
490
- location: 'en-US',
491
- },
492
- });
493
- }
494
- const nav = win.navigator || {};
495
- const platform = nav.platform || 'Win32';
496
- const userAgent = nav.userAgent || 'Node.js/22';
497
- const language = nav.language || 'en-US';
498
- // Get screen information if available
499
- const screen = win.screen || {};
500
- const screenWidth = screen.width || 0;
501
- const screenHeight = screen.height || 0;
502
- const colorDepth = screen.colorDepth || 0;
503
- // Get timezone
504
- let timezone = 'UTC';
505
- try {
506
- timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
507
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
508
- }
509
- catch (e) {
510
- // Ignore error, fallback to UTC
511
- }
512
- // Detect private browsing mode
513
- let isPrivateBrowsing = false;
514
- try {
515
- // Simple localStorage test to detect private browsing
516
- if (win.localStorage) {
517
- const testKey = 'test_private_browsing';
518
- win.localStorage.setItem(testKey, '1');
519
- win.localStorage.removeItem(testKey);
520
- }
521
- else {
522
- isPrivateBrowsing = true; // If localStorage is not available, likely private browsing
523
- }
524
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
525
- }
526
- catch (e) {
527
- isPrivateBrowsing = true; // Error during localStorage access indicates private browsing
528
- }
529
- // Create a stable fingerprint string using stable device/browser characteristics
530
- const fingerprintString = `${platform}|${userAgent}|${language}|${screenWidth}|${screenHeight}|${colorDepth}|${timezone}|${isPrivateBrowsing ? 'private' : 'normal'}|${instanceId}`;
531
- // Simple but stable hash function
532
- let hash = 0;
533
- for (let i = 0; i < fingerprintString.length; i++) {
534
- const char = fingerprintString.charCodeAt(i);
535
- hash = (hash << 5) - hash + char;
536
- hash = hash & hash; // Convert to 32-bit integer
537
- }
538
- const deviceMetadata = {
539
- fingerprint: `UQ_${Math.abs(hash).toString(36)}_${instanceId.substring(0, 12)}`,
540
- deviceInfo: {
541
- os: platform.replace(/ /g, '_'),
542
- browser: userAgent.replace(/ /g, '_'),
543
- location: language,
544
- },
545
- };
546
- return JSON.stringify(deviceMetadata);
547
- }
548
- }
549
- exports.default = SyncModules;