szdl-utils-kit 0.3.15 → 0.3.17
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.
- package/dist/index.js +1457 -1359
- package/dist/index.umd.cjs +2 -2
- package/dist/types/bx-boot.d.ts +10 -2
- package/dist/types/bx-logger.d.ts +5 -0
- package/package.json +45 -44
package/dist/index.js
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
if (!
|
|
1
|
+
var ge = Object.defineProperty;
|
|
2
|
+
var pe = (y, t, e) => t in y ? ge(y, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : y[t] = e;
|
|
3
|
+
var B = (y, t, e) => (pe(y, typeof t != "symbol" ? t + "" : t, e), e), Wt = (y, t, e) => {
|
|
4
|
+
if (!t.has(y))
|
|
5
5
|
throw TypeError("Cannot " + e);
|
|
6
6
|
};
|
|
7
|
-
var
|
|
8
|
-
if (
|
|
7
|
+
var E = (y, t, e) => (Wt(y, t, "read from private field"), e ? e.call(y) : t.get(y)), S = (y, t, e) => {
|
|
8
|
+
if (t.has(y))
|
|
9
9
|
throw TypeError("Cannot add the same private member more than once");
|
|
10
|
-
|
|
11
|
-
},
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
function
|
|
15
|
-
return
|
|
10
|
+
t instanceof WeakSet ? t.add(y) : t.set(y, e);
|
|
11
|
+
}, F = (y, t, e, r) => (Wt(y, t, "write to private field"), r ? r.call(y, e) : t.set(y, e), e);
|
|
12
|
+
var _ = (y, t, e) => (Wt(y, t, "access private method"), e);
|
|
13
|
+
var ye = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
14
|
+
function Ne(y) {
|
|
15
|
+
return y && y.__esModule && Object.prototype.hasOwnProperty.call(y, "default") ? y.default : y;
|
|
16
16
|
}
|
|
17
|
-
var
|
|
18
|
-
(function(
|
|
17
|
+
var Xt = { exports: {} };
|
|
18
|
+
(function(y, t) {
|
|
19
19
|
(function(e) {
|
|
20
|
-
Array.prototype.indexOf || (Array.prototype.indexOf = function(
|
|
21
|
-
var
|
|
22
|
-
for (
|
|
23
|
-
if (this[
|
|
24
|
-
return
|
|
20
|
+
Array.prototype.indexOf || (Array.prototype.indexOf = function(s, o) {
|
|
21
|
+
var m, g;
|
|
22
|
+
for (m = o || 0, g = this.length; m < g; m += 1)
|
|
23
|
+
if (this[m] === s)
|
|
24
|
+
return m;
|
|
25
25
|
return -1;
|
|
26
26
|
});
|
|
27
|
-
var
|
|
28
|
-
for (var
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
},
|
|
32
|
-
return
|
|
33
|
-
},
|
|
34
|
-
var
|
|
35
|
-
return
|
|
36
|
-
},
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
return !isNaN(Number(g[0])) && !isNaN(Number(g[2])) && !isNaN(Number(g[4])) ? (g[1] === "." && g[3] === "." ?
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
], !isNaN(Number(
|
|
51
|
-
},
|
|
27
|
+
var r = this, i = function(s, o) {
|
|
28
|
+
for (var m = s.toString(); m.length < o; )
|
|
29
|
+
m = "0" + m;
|
|
30
|
+
return m;
|
|
31
|
+
}, a = function(s, o) {
|
|
32
|
+
return o !== e ? (s.year(o.year() || o.year), s.month(o.month() || o.month), s.day(o.day() || o.day), s.hours(o.hours() || o.hours), s.minutes(o.minutes() || o.minutes), s.seconds(o.seconds() || o.seconds), s.milliseconds(o.milliseconds() || o.milliseconds), s) : e;
|
|
33
|
+
}, A = function(s, o) {
|
|
34
|
+
var m, g = "";
|
|
35
|
+
return m = s.slice(o, o + 1), m !== "" && !isNaN(Number(m)) && (g += "%H"), m = s.charAt(o + 2), m !== "" && m === ":" && (g += m), m = s.slice(o + 3, o + 4), m !== "" && !isNaN(Number(m)) && (g += "%M"), m = s.charAt(o + 5), m !== "" && m === ":" && (g += m), m = s.slice(o + 6, o + 7), m !== "" && !isNaN(Number(m)) && (g += "%S"), g;
|
|
36
|
+
}, h = function(s, o) {
|
|
37
|
+
var m, g = [
|
|
38
|
+
s.slice(o, o + 1),
|
|
39
|
+
s.charAt(o + 2),
|
|
40
|
+
s.slice(o + 3, o + 4),
|
|
41
|
+
s.charAt(o + 5),
|
|
42
|
+
s.slice(o + 6, o + 9)
|
|
43
|
+
], w;
|
|
44
|
+
return !isNaN(Number(g[0])) && !isNaN(Number(g[2])) && !isNaN(Number(g[4])) ? (g[1] === "." && g[3] === "." ? m = "%d.%m.%Y" : g[1] === "-" && g[3] === "-" ? m = "%m-%d-%Y" : g[1] === "/" && g[3] === "/" && (m = "%m/%d/%Y"), m) : (w = [
|
|
45
|
+
s.slice(o, o + 3),
|
|
46
|
+
s.charAt(o + 4),
|
|
47
|
+
s.slice(o + 5, o + 6),
|
|
48
|
+
s.charAt(o + 7),
|
|
49
|
+
s.slice(o + 8, o + 9)
|
|
50
|
+
], !isNaN(Number(w[0])) && !isNaN(Number(w[2])) && !isNaN(Number(w[4])) ? (w[1] === "-" && w[3] === "-" && (m = "%Y-%m-%d"), m) : "");
|
|
51
|
+
}, u = r.tempus, n, f, d = r.navigator || {}, c = "en", l = {
|
|
52
52
|
en: {
|
|
53
53
|
JANUARY_SHORT: "Jan",
|
|
54
54
|
FEBRUARY_SHORT: "Feb",
|
|
@@ -211,100 +211,100 @@ var Ct = { exports: {} };
|
|
|
211
211
|
}
|
|
212
212
|
}, O = function() {
|
|
213
213
|
return [
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
214
|
+
l[c].JANUARY_LONG,
|
|
215
|
+
l[c].FEBRUARY_LONG,
|
|
216
|
+
l[c].MARCH_LONG,
|
|
217
|
+
l[c].APRIL_LONG,
|
|
218
|
+
l[c].MAY_LONG,
|
|
219
|
+
l[c].JUNE_LONG,
|
|
220
|
+
l[c].JULY_LONG,
|
|
221
|
+
l[c].AUGUST_LONG,
|
|
222
|
+
l[c].SEPTEMBER_LONG,
|
|
223
|
+
l[c].OCTOBER_LONG,
|
|
224
|
+
l[c].NOVEMBER_LONG,
|
|
225
|
+
l[c].DECEMBER_LONG
|
|
226
226
|
];
|
|
227
|
-
},
|
|
227
|
+
}, T = function() {
|
|
228
228
|
return [
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
229
|
+
l[c].JANUARY_SHORT,
|
|
230
|
+
l[c].FEBRUARY_SHORT,
|
|
231
|
+
l[c].MARCH_SHORT,
|
|
232
|
+
l[c].APRIL_SHORT,
|
|
233
|
+
l[c].MAY_SHORT,
|
|
234
|
+
l[c].JUNE_SHORT,
|
|
235
|
+
l[c].JULY_SHORT,
|
|
236
|
+
l[c].AUGUST_SHORT,
|
|
237
|
+
l[c].SEPTEMBER_SHORT,
|
|
238
|
+
l[c].OCTOBER_SHORT,
|
|
239
|
+
l[c].NOVEMBER_SHORT,
|
|
240
|
+
l[c].DECEMBER_SHORT
|
|
241
241
|
];
|
|
242
|
-
},
|
|
242
|
+
}, b = function() {
|
|
243
243
|
return [
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
244
|
+
l[c].SUNDAY_LONG,
|
|
245
|
+
l[c].MONDAY_LONG,
|
|
246
|
+
l[c].TUESDAY_LONG,
|
|
247
|
+
l[c].WEDNESDAY_LONG,
|
|
248
|
+
l[c].THURSDAY_LONG,
|
|
249
|
+
l[c].FRIDAY_LONG,
|
|
250
|
+
l[c].SATURDAY_LONG
|
|
251
251
|
];
|
|
252
|
-
},
|
|
252
|
+
}, I = function() {
|
|
253
253
|
return [
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
254
|
+
l[c].SUNDAY_SHORT,
|
|
255
|
+
l[c].MONDAY_SHORT,
|
|
256
|
+
l[c].TUESDAY_SHORT,
|
|
257
|
+
l[c].WEDNESDAY_SHORT,
|
|
258
|
+
l[c].THURSDAY_SHORT,
|
|
259
|
+
l[c].FRIDAY_SHORT,
|
|
260
|
+
l[c].SATURDAY_SHORT
|
|
261
261
|
];
|
|
262
|
-
},
|
|
262
|
+
}, N, p, R, M, H = function(s, o, m) {
|
|
263
263
|
var g;
|
|
264
|
-
|
|
265
|
-
g.readyState === 4 && (g.status === 200 ?
|
|
266
|
-
https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) :
|
|
267
|
-
}, g.open("GET",
|
|
268
|
-
},
|
|
264
|
+
r.XMLHttpRequest ? g = new XMLHttpRequest() : g = new ActiveXObject("Microsoft.XMLHTTP"), g.onreadystatechange = function() {
|
|
265
|
+
g.readyState === 4 && (g.status === 200 ? o && (r.JSON === e ? alert(`Please, include json2 into your project if you want use old browsers!
|
|
266
|
+
https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : o(JSON.parse(g.responseText))) : m && m(g));
|
|
267
|
+
}, g.open("GET", s, !1), g.send();
|
|
268
|
+
}, k = {
|
|
269
269
|
"%d": {
|
|
270
|
-
format: function(
|
|
271
|
-
return
|
|
270
|
+
format: function(s) {
|
|
271
|
+
return i(s.day() || n.MIN_DAY, 2);
|
|
272
272
|
},
|
|
273
|
-
parse: function(
|
|
274
|
-
var
|
|
275
|
-
return { day: isNaN(
|
|
273
|
+
parse: function(s) {
|
|
274
|
+
var o = Number(s);
|
|
275
|
+
return { day: isNaN(o) ? e : o };
|
|
276
276
|
},
|
|
277
277
|
minLength: 2,
|
|
278
278
|
maxLength: 2,
|
|
279
279
|
type: "number"
|
|
280
280
|
},
|
|
281
281
|
"%m": {
|
|
282
|
-
format: function(
|
|
283
|
-
return
|
|
282
|
+
format: function(s) {
|
|
283
|
+
return i(s.month() || n.MIN_MONTH, 2);
|
|
284
284
|
},
|
|
285
|
-
parse: function(
|
|
286
|
-
var
|
|
287
|
-
return { month: isNaN(
|
|
285
|
+
parse: function(s) {
|
|
286
|
+
var o = Number(s);
|
|
287
|
+
return { month: isNaN(o) ? e : o };
|
|
288
288
|
},
|
|
289
289
|
minLength: 2,
|
|
290
290
|
maxLength: 2,
|
|
291
291
|
type: "number"
|
|
292
292
|
},
|
|
293
293
|
"%Y": {
|
|
294
|
-
format: function(
|
|
295
|
-
return
|
|
294
|
+
format: function(s) {
|
|
295
|
+
return i(s.year() || n.MIN_YEAR, 4);
|
|
296
296
|
},
|
|
297
|
-
parse: function(
|
|
298
|
-
var
|
|
299
|
-
return { year: isNaN(
|
|
297
|
+
parse: function(s) {
|
|
298
|
+
var o = Number(s);
|
|
299
|
+
return { year: isNaN(o) ? e : o };
|
|
300
300
|
},
|
|
301
301
|
minLength: 4,
|
|
302
302
|
maxLength: 4,
|
|
303
303
|
type: "number"
|
|
304
304
|
},
|
|
305
305
|
"%w": {
|
|
306
|
-
format: function(
|
|
307
|
-
return
|
|
306
|
+
format: function(s) {
|
|
307
|
+
return s.dayOfWeek() || n.MIN_DAY_OF_WEEK;
|
|
308
308
|
},
|
|
309
309
|
parse: function() {
|
|
310
310
|
return {};
|
|
@@ -314,9 +314,9 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
314
314
|
type: "number"
|
|
315
315
|
},
|
|
316
316
|
"%a": {
|
|
317
|
-
format: function(
|
|
318
|
-
var
|
|
319
|
-
return
|
|
317
|
+
format: function(s) {
|
|
318
|
+
var o = s.dayOfWeek();
|
|
319
|
+
return M[o !== e ? o : n.MIN_DAY_OF_WEEK];
|
|
320
320
|
},
|
|
321
321
|
parse: function() {
|
|
322
322
|
return {};
|
|
@@ -326,9 +326,9 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
326
326
|
type: "word"
|
|
327
327
|
},
|
|
328
328
|
"%A": {
|
|
329
|
-
format: function(
|
|
330
|
-
var
|
|
331
|
-
return
|
|
329
|
+
format: function(s) {
|
|
330
|
+
var o = s.dayOfWeek();
|
|
331
|
+
return R[o !== e ? o : n.MIN_DAY_OF_WEEK];
|
|
332
332
|
},
|
|
333
333
|
parse: function() {
|
|
334
334
|
return {};
|
|
@@ -338,87 +338,87 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
338
338
|
type: "word"
|
|
339
339
|
},
|
|
340
340
|
"%b": {
|
|
341
|
-
format: function(
|
|
342
|
-
var
|
|
343
|
-
return
|
|
341
|
+
format: function(s) {
|
|
342
|
+
var o = n.options("monthFromZero") ? s.month() : s.month() - 1;
|
|
343
|
+
return p[o !== e ? o : n.MIN_MONTH];
|
|
344
344
|
},
|
|
345
|
-
parse: function(
|
|
346
|
-
var
|
|
347
|
-
return { month:
|
|
345
|
+
parse: function(s) {
|
|
346
|
+
var o = n.monthNames().indexOf(s) + (n.options("monthFromZero") ? 0 : 1);
|
|
347
|
+
return { month: o !== -1 ? o : e };
|
|
348
348
|
},
|
|
349
349
|
minLength: 1,
|
|
350
350
|
maxLength: 999,
|
|
351
351
|
type: "word"
|
|
352
352
|
},
|
|
353
353
|
"%B": {
|
|
354
|
-
format: function(
|
|
355
|
-
var
|
|
356
|
-
return
|
|
354
|
+
format: function(s) {
|
|
355
|
+
var o = n.options("monthFromZero") ? s.month() : s.month() - 1;
|
|
356
|
+
return N[o !== e ? o : n.MIN_MONTH];
|
|
357
357
|
},
|
|
358
|
-
parse: function(
|
|
359
|
-
var
|
|
360
|
-
return { month:
|
|
358
|
+
parse: function(s) {
|
|
359
|
+
var o = n.monthNames(!0).indexOf(s) + (n.options("monthFromZero") ? 0 : 1);
|
|
360
|
+
return { month: o !== -1 ? o : e };
|
|
361
361
|
},
|
|
362
362
|
minLength: 1,
|
|
363
363
|
maxLength: 999,
|
|
364
364
|
type: "word"
|
|
365
365
|
},
|
|
366
366
|
"%H": {
|
|
367
|
-
format: function(
|
|
368
|
-
return
|
|
367
|
+
format: function(s) {
|
|
368
|
+
return i(s.hours() || n.MIN_HOURS, 2);
|
|
369
369
|
},
|
|
370
|
-
parse: function(
|
|
371
|
-
var
|
|
372
|
-
return { hours: isNaN(
|
|
370
|
+
parse: function(s) {
|
|
371
|
+
var o = Number(s);
|
|
372
|
+
return { hours: isNaN(o) ? e : o };
|
|
373
373
|
},
|
|
374
374
|
minLength: 2,
|
|
375
375
|
maxLength: 2,
|
|
376
376
|
type: "number"
|
|
377
377
|
},
|
|
378
378
|
"%M": {
|
|
379
|
-
format: function(
|
|
380
|
-
return
|
|
379
|
+
format: function(s) {
|
|
380
|
+
return i(s.minutes() || n.MIN_MINUTES, 2);
|
|
381
381
|
},
|
|
382
|
-
parse: function(
|
|
383
|
-
var
|
|
384
|
-
return { minutes: isNaN(
|
|
382
|
+
parse: function(s) {
|
|
383
|
+
var o = Number(s);
|
|
384
|
+
return { minutes: isNaN(o) ? e : o };
|
|
385
385
|
},
|
|
386
386
|
minLength: 2,
|
|
387
387
|
maxLength: 2,
|
|
388
388
|
type: "number"
|
|
389
389
|
},
|
|
390
390
|
"%S": {
|
|
391
|
-
format: function(
|
|
392
|
-
return
|
|
391
|
+
format: function(s) {
|
|
392
|
+
return i(s.seconds() || n.MIN_SECONDS, 2);
|
|
393
393
|
},
|
|
394
|
-
parse: function(
|
|
395
|
-
var
|
|
396
|
-
return { seconds: isNaN(
|
|
394
|
+
parse: function(s) {
|
|
395
|
+
var o = Number(s);
|
|
396
|
+
return { seconds: isNaN(o) ? e : o };
|
|
397
397
|
},
|
|
398
398
|
minLength: 2,
|
|
399
399
|
maxLength: 2,
|
|
400
400
|
type: "number"
|
|
401
401
|
},
|
|
402
402
|
"%s": {
|
|
403
|
-
format: function(
|
|
404
|
-
return
|
|
403
|
+
format: function(s) {
|
|
404
|
+
return s.timestamp();
|
|
405
405
|
},
|
|
406
|
-
parse: function(
|
|
407
|
-
return isNaN(Number(
|
|
406
|
+
parse: function(s) {
|
|
407
|
+
return isNaN(Number(s)) ? {} : n(Number(s)).get();
|
|
408
408
|
},
|
|
409
409
|
minLength: 1,
|
|
410
410
|
maxLength: 20,
|
|
411
411
|
type: "number"
|
|
412
412
|
},
|
|
413
413
|
"%F": {
|
|
414
|
-
format: function(
|
|
415
|
-
return
|
|
414
|
+
format: function(s) {
|
|
415
|
+
return i(s.year() || n.MIN_YEAR, 4) + "-" + i(s.month() || n.MIN_MONTH, 2) + "-" + i(s.day() || n.MIN_DAY, 2);
|
|
416
416
|
},
|
|
417
|
-
parse: function(
|
|
418
|
-
var
|
|
417
|
+
parse: function(s) {
|
|
418
|
+
var o = Number(s.slice(0, 4)), m = Number(s.slice(5, 7)), g = Number(s.slice(8, 10));
|
|
419
419
|
return {
|
|
420
|
-
year:
|
|
421
|
-
month:
|
|
420
|
+
year: o,
|
|
421
|
+
month: m,
|
|
422
422
|
day: g
|
|
423
423
|
};
|
|
424
424
|
},
|
|
@@ -427,26 +427,26 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
427
427
|
type: "string"
|
|
428
428
|
},
|
|
429
429
|
"%D": {
|
|
430
|
-
format: function(
|
|
431
|
-
return
|
|
430
|
+
format: function(s) {
|
|
431
|
+
return i(s.month() || n.MIN_MONTH, 2) + "/" + i(s.day() || n.MIN_DAY, 2) + "/" + i(s.year() || n.MIN_YEAR, 4);
|
|
432
432
|
},
|
|
433
|
-
parse: function(
|
|
434
|
-
var
|
|
433
|
+
parse: function(s) {
|
|
434
|
+
var o = Number(s.slice(0, 2)), m = Number(s.slice(3, 5)), g = Number(s.slice(6, 10));
|
|
435
435
|
return {
|
|
436
436
|
year: g,
|
|
437
|
-
month:
|
|
438
|
-
day:
|
|
437
|
+
month: o,
|
|
438
|
+
day: m
|
|
439
439
|
};
|
|
440
440
|
},
|
|
441
441
|
minLength: 10,
|
|
442
442
|
maxLength: 10,
|
|
443
443
|
type: "string"
|
|
444
444
|
}
|
|
445
|
-
},
|
|
445
|
+
}, U = {
|
|
446
446
|
useMilliseconds: !1,
|
|
447
447
|
monthFromZero: !1
|
|
448
|
-
},
|
|
449
|
-
|
|
448
|
+
}, D;
|
|
449
|
+
D = function(s, o, m) {
|
|
450
450
|
return this._d = /* @__PURE__ */ new Date(), this._i = {
|
|
451
451
|
year: !1,
|
|
452
452
|
month: !1,
|
|
@@ -455,56 +455,56 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
455
455
|
minutes: !1,
|
|
456
456
|
seconds: !1,
|
|
457
457
|
milliseconds: !1
|
|
458
|
-
},
|
|
459
|
-
},
|
|
460
|
-
var
|
|
461
|
-
return this.leapYear() &&
|
|
462
|
-
},
|
|
458
|
+
}, s !== e && this.set(s, o, m), this;
|
|
459
|
+
}, D.fn = D.prototype, D.fn.dayCount = function() {
|
|
460
|
+
var s = this.month(), o = n.MAX_DAY_IN_MONTHS[s - (n.options("monthFromZero") ? 0 : 1)];
|
|
461
|
+
return this.leapYear() && s === (n.options("monthFromZero") ? 1 : 2) && (o += 1), o;
|
|
462
|
+
}, D.fn.year = function(s) {
|
|
463
463
|
if (arguments.length !== 0)
|
|
464
|
-
(typeof
|
|
464
|
+
(typeof s == "number" || typeof s == "string") && !isNaN(Number(s)) ? Number(s) >= n.MIN_YEAR && Number(s) <= n.MAX_YEAR ? (this._d.setFullYear(Number(s)), this._i.year = !1) : this._i.year = Number(s) : (this._d.setFullYear(n.MIN_YEAR), this._i.year = !1);
|
|
465
465
|
else
|
|
466
466
|
return this._i.year === !1 ? this._d.getFullYear() : this._i.year;
|
|
467
467
|
return this;
|
|
468
|
-
},
|
|
468
|
+
}, D.fn.month = function(s) {
|
|
469
469
|
if (arguments.length !== 0)
|
|
470
|
-
(typeof
|
|
470
|
+
(typeof s == "number" || typeof s == "string") && !isNaN(Number(s)) ? Number(s) >= n.MIN_MONTH && Number(s) <= n.MAX_MONTH ? (this._d.setMonth(n.options("monthFromZero") ? Number(s) : Number(s) - 1), this._i.month = !1) : this._i.month = Number(s) : (this._d.setMonth(n.options("monthFromZero") ? n.MIN_MONTH : n.MIN_MONTH - 1), this._i.month = !1);
|
|
471
471
|
else
|
|
472
|
-
return this._i.month === !1 ?
|
|
472
|
+
return this._i.month === !1 ? n.options("monthFromZero") ? this._d.getMonth() : this._d.getMonth() + 1 : this._i.month;
|
|
473
473
|
return this;
|
|
474
|
-
},
|
|
474
|
+
}, D.fn.day = function(s) {
|
|
475
475
|
if (arguments.length !== 0)
|
|
476
|
-
(typeof
|
|
476
|
+
(typeof s == "number" || typeof s == "string") && !isNaN(Number(s)) ? Number(s) >= n.MIN_DAY && Number(s) <= this.dayCount() ? (this._d.setDate(Number(s)), this._i.day = !1) : this._i.day = Number(s) : (this._d.setDate(n.MIN_DAY), this._i.day = !1);
|
|
477
477
|
else
|
|
478
478
|
return this._i.day === !1 ? this._d.getDate() : this._i.day;
|
|
479
479
|
return this;
|
|
480
|
-
},
|
|
480
|
+
}, D.fn.hours = function(s) {
|
|
481
481
|
if (arguments.length !== 0)
|
|
482
|
-
(typeof
|
|
482
|
+
(typeof s == "number" || typeof s == "string") && !isNaN(Number(s)) ? Number(s) >= n.MIN_HOURS && Number(s) <= n.MAX_HOURS ? (this._d.setHours(Number(s)), this._i.hours = !1) : this._i.hours = Number(s) : (this._d.setHours(n.MIN_HOURS), this._i.hours = !1);
|
|
483
483
|
else
|
|
484
484
|
return this._i.hours === !1 ? this._d.getHours() : this._i.hours;
|
|
485
485
|
return this;
|
|
486
|
-
},
|
|
486
|
+
}, D.fn.minutes = function(s) {
|
|
487
487
|
if (arguments.length !== 0)
|
|
488
|
-
(typeof
|
|
488
|
+
(typeof s == "number" || typeof s == "string") && !isNaN(Number(s)) ? Number(s) >= n.MIN_MINUTES && Number(s) <= n.MAX_MINUTES ? (this._d.setMinutes(Number(s)), this._i.minutes = !1) : this._i.minutes = Number(s) : (this._d.setMinutes(n.MIN_MINUTES), this._i.minutes = !1);
|
|
489
489
|
else
|
|
490
490
|
return this._i.minutes === !1 ? this._d.getMinutes() : this._i.minutes;
|
|
491
491
|
return this;
|
|
492
|
-
},
|
|
492
|
+
}, D.fn.seconds = function(s) {
|
|
493
493
|
if (arguments.length !== 0)
|
|
494
|
-
(typeof
|
|
494
|
+
(typeof s == "number" || typeof s == "string") && !isNaN(Number(s)) ? Number(s) >= n.MIN_SECONDS && Number(s) <= n.MAX_SECONDS ? (this._d.setSeconds(Number(s)), this._i.seconds = !1) : this._i.seconds = Number(s) : (this._d.setSeconds(n.MIN_SECONDS), this._i.seconds = !1);
|
|
495
495
|
else
|
|
496
496
|
return this._i.seconds === !1 ? this._d.getSeconds() : this._i.seconds;
|
|
497
497
|
return this;
|
|
498
|
-
},
|
|
498
|
+
}, D.fn.milliseconds = function(s) {
|
|
499
499
|
if (arguments.length !== 0)
|
|
500
|
-
(typeof
|
|
500
|
+
(typeof s == "number" || typeof s == "string") && !isNaN(Number(s)) ? Number(s) >= n.MIN_MILLISECONDS && Number(s) <= n.MAX_MILLISECONDS ? (this._d.setMilliseconds(Number(s)), this._i.milliseconds = !1) : this._i.milliseconds = Number(s) : (this._d.setMilliseconds(n.MIN_MILLISECONDS), this._i.milliseconds = !1);
|
|
501
501
|
else
|
|
502
502
|
return this._i.milliseconds === !1 ? this._d.getMilliseconds() : this._i.milliseconds;
|
|
503
503
|
return this;
|
|
504
|
-
},
|
|
505
|
-
var
|
|
506
|
-
return Math.ceil(((
|
|
507
|
-
},
|
|
504
|
+
}, D.fn.week = function() {
|
|
505
|
+
var s = new Date(this.year(), 0, 1), o = n(this.utc()).hours(0).minutes(0).seconds(0).milliseconds(0).utc() * 1e3;
|
|
506
|
+
return Math.ceil(((o - s.getTime()) / 864e5 + s.getDay() + 1) / 7);
|
|
507
|
+
}, D.fn.set = function(s, o, m) {
|
|
508
508
|
if (this._i = {
|
|
509
509
|
year: !1,
|
|
510
510
|
month: !1,
|
|
@@ -513,16 +513,16 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
513
513
|
minutes: !1,
|
|
514
514
|
seconds: !1,
|
|
515
515
|
milliseconds: !1
|
|
516
|
-
},
|
|
516
|
+
}, s === e)
|
|
517
517
|
return this._d = /* @__PURE__ */ new Date(), this;
|
|
518
|
-
if (
|
|
519
|
-
return this._d =
|
|
520
|
-
if (typeof
|
|
521
|
-
return this._d = new Date(
|
|
522
|
-
if (typeof
|
|
523
|
-
var g,
|
|
524
|
-
if (
|
|
525
|
-
return L =
|
|
518
|
+
if (s instanceof Date)
|
|
519
|
+
return this._d = s, this;
|
|
520
|
+
if (typeof s == "number")
|
|
521
|
+
return this._d = new Date(s * (n.options("useMilliseconds") ? 1 : 1e3)), this;
|
|
522
|
+
if (typeof s == "object" && (s instanceof Array ? (this.day(n.MIN_DAY), this.year(s[0]), this.month(s[1]), this.day(s[2]), this.hours(s[3]), this.minutes(s[4]), this.seconds(s[5]), this.milliseconds(s[6])) : (this.day(n.MIN_DAY), this.year(s.year), this.month(s.month), this.day(s.day), this.hours(s.hours), this.minutes(s.minutes), this.seconds(s.seconds), this.milliseconds(s.milliseconds))), typeof s == "string") {
|
|
523
|
+
var g, w = [], L, C, z = [], W = 0, x = 0, P, j, G = {}, Y;
|
|
524
|
+
if (s === e)
|
|
525
|
+
return L = a(this, m), L === e && (this._i = {
|
|
526
526
|
year: -1,
|
|
527
527
|
month: -1,
|
|
528
528
|
day: -1,
|
|
@@ -531,25 +531,25 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
531
531
|
seconds: -1,
|
|
532
532
|
milliseconds: -1
|
|
533
533
|
}), L;
|
|
534
|
-
for (
|
|
535
|
-
if (
|
|
536
|
-
if (
|
|
537
|
-
switch (P = 0,
|
|
534
|
+
for (o === e && (o = n.detectFormat(s)); W < o.length; ) {
|
|
535
|
+
if (o.charAt(W) === "%") {
|
|
536
|
+
if (C = o.charAt(W) + o.charAt(W + 1), k[C] !== e) {
|
|
537
|
+
switch (P = 0, j = "", k[C].type) {
|
|
538
538
|
case "number":
|
|
539
|
-
for (; P <
|
|
540
|
-
|
|
539
|
+
for (; P < k[C].maxLength && x + P < s.length && !isNaN(Number(s.charAt(x + P))); )
|
|
540
|
+
j += s.charAt(x + P), P += 1;
|
|
541
541
|
break;
|
|
542
542
|
case "word":
|
|
543
|
-
for (; P <
|
|
544
|
-
|
|
543
|
+
for (; P < k[C].maxLength && x + P < s.length && /^[\u00BF-\u1FFF\u2C00-\uD7FF\w]+$/.test(s.charAt(x + P)); )
|
|
544
|
+
j += s.charAt(x + P), P += 1;
|
|
545
545
|
break;
|
|
546
546
|
case "string":
|
|
547
|
-
for (; P <
|
|
548
|
-
|
|
547
|
+
for (; P < k[C].maxLength && x + P < s.length; )
|
|
548
|
+
j += s.charAt(x + P), P += 1;
|
|
549
549
|
break;
|
|
550
550
|
}
|
|
551
|
-
if (P <
|
|
552
|
-
return L =
|
|
551
|
+
if (P < k[C].minLength)
|
|
552
|
+
return L = a(this, m), L === e && (this._i = {
|
|
553
553
|
year: -1,
|
|
554
554
|
month: -1,
|
|
555
555
|
day: -1,
|
|
@@ -558,10 +558,10 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
558
558
|
seconds: -1,
|
|
559
559
|
milliseconds: -1
|
|
560
560
|
}), L;
|
|
561
|
-
|
|
561
|
+
w.push(C), z.push(j), P -= 1, x += P, W += 1;
|
|
562
562
|
}
|
|
563
|
-
} else if (
|
|
564
|
-
return L =
|
|
563
|
+
} else if (s.charAt(x) !== o.charAt(W))
|
|
564
|
+
return L = a(this, m), L === e && (this._i = {
|
|
565
565
|
year: -1,
|
|
566
566
|
month: -1,
|
|
567
567
|
day: -1,
|
|
@@ -572,48 +572,48 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
572
572
|
}), L;
|
|
573
573
|
W += 1, x += 1;
|
|
574
574
|
}
|
|
575
|
-
for (g in
|
|
576
|
-
|
|
577
|
-
year:
|
|
578
|
-
month:
|
|
579
|
-
day:
|
|
580
|
-
hours:
|
|
581
|
-
minutes:
|
|
582
|
-
seconds:
|
|
575
|
+
for (g in w)
|
|
576
|
+
w.hasOwnProperty(g) && k.hasOwnProperty(w[g]) && (Y = k[w[g]].parse(z[g]), G = {
|
|
577
|
+
year: Y.year !== e ? Y.year : G.year,
|
|
578
|
+
month: Y.month !== e ? Y.month : G.month,
|
|
579
|
+
day: Y.day !== e ? Y.day : G.day,
|
|
580
|
+
hours: Y.hours !== e ? Y.hours : G.hours,
|
|
581
|
+
minutes: Y.minutes !== e ? Y.minutes : G.minutes,
|
|
582
|
+
seconds: Y.seconds !== e ? Y.seconds : G.seconds
|
|
583
583
|
});
|
|
584
|
-
this.day(
|
|
584
|
+
this.day(n.MIN_DAY), this.year(G.year), this.month(G.month), this.day(G.day), this.hours(G.hours), this.minutes(G.minutes), this.seconds(G.seconds), this.milliseconds(G.milliseconds);
|
|
585
585
|
}
|
|
586
586
|
return this;
|
|
587
|
-
},
|
|
588
|
-
var
|
|
589
|
-
return
|
|
590
|
-
},
|
|
591
|
-
return arguments.length !== 0 ? (this._d = new Date(Number(
|
|
592
|
-
},
|
|
593
|
-
return arguments.length !== 0 ? (this._d = new Date(Number(
|
|
594
|
-
},
|
|
595
|
-
if (
|
|
596
|
-
return
|
|
597
|
-
if (
|
|
598
|
-
return
|
|
599
|
-
if (
|
|
587
|
+
}, D.fn.leapYear = function() {
|
|
588
|
+
var s = this.year();
|
|
589
|
+
return s % 4 === 0 ? s % 100 === 0 ? s % 400 === 0 : !0 : !1;
|
|
590
|
+
}, D.fn.timestamp = function(s) {
|
|
591
|
+
return arguments.length !== 0 ? (this._d = new Date(Number(s) * (n.options("useMilliseconds") ? 1 : 1e3) + this._d.getTimezoneOffset() * 6e4), this) : n.options("useMilliseconds") ? this._d.getTime() - this._d.getTimezoneOffset() * 6e4 : Math.floor(this._d.getTime() / 1e3) - this._d.getTimezoneOffset() * 60;
|
|
592
|
+
}, D.fn.utc = function(s) {
|
|
593
|
+
return arguments.length !== 0 ? (this._d = new Date(Number(s) * (n.options("useMilliseconds") ? 1 : 1e3)), this) : n.options("useMilliseconds") ? this._d.getTime() : Math.floor(this._d.getTime() / 1e3);
|
|
594
|
+
}, D.fn.dayOfWeek = function(s) {
|
|
595
|
+
if (s === "long")
|
|
596
|
+
return R[this._d.getDay()];
|
|
597
|
+
if (s === "short")
|
|
598
|
+
return M[this._d.getDay()];
|
|
599
|
+
if (s === e)
|
|
600
600
|
return this._d.getDay();
|
|
601
|
-
if (
|
|
601
|
+
if (s === 0 || s === "Sunday")
|
|
602
602
|
return this.calc({ day: -this.dayOfWeek() });
|
|
603
|
-
if (
|
|
603
|
+
if (s === 1 || s === "Monday")
|
|
604
604
|
return this.calc({ day: (this.dayOfWeek() === 0 ? -6 : 1) - this.dayOfWeek() });
|
|
605
|
-
if (
|
|
605
|
+
if (s === 2 || s === "Tuesday")
|
|
606
606
|
return this.calc({ day: (this.dayOfWeek() === 0 ? -5 : 2) - this.dayOfWeek() });
|
|
607
|
-
if (
|
|
607
|
+
if (s === 3 || s === "Wednesday")
|
|
608
608
|
return this.calc({ day: (this.dayOfWeek() === 0 ? -4 : 3) - this.dayOfWeek() });
|
|
609
|
-
if (
|
|
609
|
+
if (s === 4 || s === "Thursday")
|
|
610
610
|
return this.calc({ day: (this.dayOfWeek() === 0 ? -3 : 4) - this.dayOfWeek() });
|
|
611
|
-
if (
|
|
611
|
+
if (s === 5 || s === "Friday")
|
|
612
612
|
return this.calc({ day: (this.dayOfWeek() === 0 ? -2 : 5) - this.dayOfWeek() });
|
|
613
|
-
if (
|
|
613
|
+
if (s === 6 || s === "Saturday")
|
|
614
614
|
return this.calc({ day: (this.dayOfWeek() === 0 ? -1 : 6) - this.dayOfWeek() });
|
|
615
|
-
},
|
|
616
|
-
switch (
|
|
615
|
+
}, D.fn.timezone = function(s) {
|
|
616
|
+
switch (s) {
|
|
617
617
|
case "hours":
|
|
618
618
|
return Math.floor(this._d.getTimezoneOffset() / 60);
|
|
619
619
|
case "minutes":
|
|
@@ -621,12 +621,12 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
621
621
|
default:
|
|
622
622
|
return this._d.getTimezoneOffset() * 60;
|
|
623
623
|
}
|
|
624
|
-
},
|
|
625
|
-
switch (
|
|
624
|
+
}, D.fn.get = function(s) {
|
|
625
|
+
switch (s) {
|
|
626
626
|
case "Date":
|
|
627
627
|
return new Date(
|
|
628
628
|
this.year(),
|
|
629
|
-
this.month() - (
|
|
629
|
+
this.month() - (n.options("monthFromZero") ? 0 : 1),
|
|
630
630
|
this.day(),
|
|
631
631
|
this.hours(),
|
|
632
632
|
this.minutes(),
|
|
@@ -636,7 +636,7 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
636
636
|
case "DateUTC":
|
|
637
637
|
return new Date(Date.UTC(
|
|
638
638
|
this.year(),
|
|
639
|
-
this.month() - (
|
|
639
|
+
this.month() - (n.options("monthFromZero") ? 0 : 1),
|
|
640
640
|
this.day(),
|
|
641
641
|
this.hours(),
|
|
642
642
|
this.minutes(),
|
|
@@ -670,73 +670,73 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
670
670
|
timestamp: this.timestamp()
|
|
671
671
|
};
|
|
672
672
|
}
|
|
673
|
-
},
|
|
674
|
-
for (var
|
|
675
|
-
|
|
676
|
-
return
|
|
677
|
-
},
|
|
673
|
+
}, D.fn.format = function(s) {
|
|
674
|
+
for (var o = 0, m = "", g; o < s.length; )
|
|
675
|
+
s.charAt(o) === "%" ? (g = s.charAt(o) + s.charAt(o + 1), k[g] !== e ? (m += k[g].format(this), o += 1) : m += "%") : m += s.charAt(o), o += 1;
|
|
676
|
+
return m;
|
|
677
|
+
}, D.fn.valid = function() {
|
|
678
678
|
return this._i.year === !1 && this._i.month === !1 && this._i.day === !1 && this._i.hours === !1 && this._i.minutes === !1 && this._i.seconds === !1 && this._i.milliseconds === !1;
|
|
679
|
-
},
|
|
679
|
+
}, D.fn.errors = function() {
|
|
680
680
|
return this._i;
|
|
681
|
-
},
|
|
682
|
-
var
|
|
683
|
-
switch (
|
|
681
|
+
}, D.fn.between = function(s, o) {
|
|
682
|
+
var m = this.timestamp(), g = s.timestamp();
|
|
683
|
+
switch (o) {
|
|
684
684
|
case "year":
|
|
685
|
-
return Math.floor((g -
|
|
685
|
+
return Math.floor((g - m) / 31556952);
|
|
686
686
|
case "month":
|
|
687
|
-
return Math.floor((g -
|
|
687
|
+
return Math.floor((g - m) / 2629746);
|
|
688
688
|
case "day":
|
|
689
|
-
return Math.floor((g -
|
|
689
|
+
return Math.floor((g - m) / 86400);
|
|
690
690
|
case "hours":
|
|
691
|
-
return Math.floor((g -
|
|
691
|
+
return Math.floor((g - m) / 3600);
|
|
692
692
|
case "minutes":
|
|
693
|
-
return Math.floor((g -
|
|
693
|
+
return Math.floor((g - m) / 60);
|
|
694
694
|
case "seconds":
|
|
695
|
-
return g -
|
|
695
|
+
return g - m;
|
|
696
696
|
default:
|
|
697
697
|
return e;
|
|
698
698
|
}
|
|
699
|
-
},
|
|
700
|
-
return
|
|
701
|
-
},
|
|
702
|
-
return new
|
|
703
|
-
},
|
|
704
|
-
if (
|
|
705
|
-
return
|
|
706
|
-
if (
|
|
707
|
-
if (
|
|
708
|
-
return
|
|
709
|
-
|
|
699
|
+
}, D.fn.calc = function(s) {
|
|
700
|
+
return s.year !== e && this._d.setFullYear(this._d.getFullYear() + s.year), s.month !== e && this._d.setMonth(this._d.getMonth() + s.month), s.day !== e && this._d.setDate(this._d.getDate() + s.day), s.hours !== e && this._d.setHours(this._d.getHours() + s.hours), s.minutes !== e && this._d.setMinutes(this._d.getMinutes() + s.minutes), s.seconds !== e && this._d.setSeconds(this._d.getSeconds() + s.seconds), s.milliseconds !== e && this._d.setMilliseconds(this._d.getMilliseconds() + s.milliseconds), this;
|
|
701
|
+
}, n = function(s, o, m) {
|
|
702
|
+
return new D(s, o, m);
|
|
703
|
+
}, n.MIN_YEAR = 1e3, n.MAX_YEAR = 3e3, n.MIN_MONTH = 1, n.MAX_MONTH = 12, n.MIN_DAY = 1, n.MAX_DAY_IN_MONTHS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], n.MIN_DAY_OF_WEEK = 0, n.MAX_DAY_OF_WEEK = 6, n.MIN_HOURS = 0, n.MAX_HOURS = 23, n.MIN_MINUTES = 0, n.MAX_MINUTES = 59, n.MIN_SECONDS = 0, n.MAX_SECONDS = 59, n.MIN_MILLISECONDS = 0, n.MAX_MILLISECONDS = 999, n.VERSION = "0.2.18", n.options = function(s, o) {
|
|
704
|
+
if (s === e)
|
|
705
|
+
return U;
|
|
706
|
+
if (U.hasOwnProperty(s)) {
|
|
707
|
+
if (o === e)
|
|
708
|
+
return U[s];
|
|
709
|
+
U[s] = o, s === "monthFromZero" && (n.MIN_MONTH = o ? 0 : 1, n.MAX_MONTH = o ? 11 : 12);
|
|
710
710
|
}
|
|
711
711
|
return e;
|
|
712
|
-
},
|
|
713
|
-
return
|
|
714
|
-
},
|
|
715
|
-
var
|
|
716
|
-
if (typeof
|
|
712
|
+
}, n.noConflict = function() {
|
|
713
|
+
return r.tempus = u, n;
|
|
714
|
+
}, n.generate = function(s) {
|
|
715
|
+
var o, m, g, w, L, C, z, W;
|
|
716
|
+
if (typeof s.dateFrom != "number" && (s.dateFrom instanceof D ? o = s.dateFrom.utc() : o = n(s.dateFrom, s.formatFrom).utc()), typeof s.dateTo != "number" && (s.dateTo instanceof D ? m = s.dateTo.utc() : m = n(s.dateTo, s.formatTo !== e ? s.formatTo : s.formatFrom).utc()), typeof s.period == "number" ? L = {
|
|
717
717
|
year: 0,
|
|
718
718
|
month: 0,
|
|
719
719
|
day: 0,
|
|
720
720
|
hours: 0,
|
|
721
721
|
minutes: 0,
|
|
722
|
-
seconds:
|
|
723
|
-
} : typeof
|
|
724
|
-
year:
|
|
725
|
-
month:
|
|
726
|
-
day:
|
|
727
|
-
hours:
|
|
728
|
-
minutes:
|
|
729
|
-
seconds:
|
|
730
|
-
} : typeof
|
|
731
|
-
year:
|
|
732
|
-
month:
|
|
733
|
-
day:
|
|
734
|
-
hours:
|
|
735
|
-
minutes:
|
|
736
|
-
seconds:
|
|
737
|
-
}),
|
|
738
|
-
return
|
|
739
|
-
},
|
|
722
|
+
seconds: s.period
|
|
723
|
+
} : typeof s.period == "string" ? L = {
|
|
724
|
+
year: s.period === "year" ? 1 : 0,
|
|
725
|
+
month: s.period === "month" ? 1 : 0,
|
|
726
|
+
day: s.period === "day" ? 1 : 0,
|
|
727
|
+
hours: s.period === "hours" ? 1 : 0,
|
|
728
|
+
minutes: s.period === "minutes" ? 1 : 0,
|
|
729
|
+
seconds: s.period === "seconds" ? 1 : 0
|
|
730
|
+
} : typeof s.period == "object" && (L = {
|
|
731
|
+
year: s.period.year !== e ? s.period.year : 0,
|
|
732
|
+
month: s.period.month !== e ? s.period.month : 0,
|
|
733
|
+
day: s.period.day !== e ? s.period.day : 0,
|
|
734
|
+
hours: s.period.hours !== e ? s.period.hours : 0,
|
|
735
|
+
minutes: s.period.minutes !== e ? s.period.minutes : 0,
|
|
736
|
+
seconds: s.period.seconds !== e ? s.period.seconds : 0
|
|
737
|
+
}), s.groupBy === e ? C = s.asObject === !0 ? {} : [] : (C = [], C.push([]), z = n(o).get()[s.groupBy]), W = function(j, G, Y) {
|
|
738
|
+
return s.asObject === !0 ? s.format !== e ? j[n(G).format(s.format)] = {} : j[n(G).format("%F %H:%M:%S")] = {} : s.format !== e ? j.push(Y ? null : n(G).format(s.format)) : j.push(Y ? null : n(G)), j;
|
|
739
|
+
}, s.groupBy !== e && s.fillNulls) {
|
|
740
740
|
var x = {
|
|
741
741
|
year: L.year ? -L.year : e,
|
|
742
742
|
month: L.month ? -L.month : e,
|
|
@@ -746,99 +746,99 @@ https://github.com/douglascrockford/JSON-js/blob/master/json2.js`) : a(JSON.pars
|
|
|
746
746
|
seconds: L.seconds ? -L.seconds : e,
|
|
747
747
|
milliseconds: L.milliseconds ? -L.milliseconds : e
|
|
748
748
|
};
|
|
749
|
-
for (g =
|
|
750
|
-
W(
|
|
751
|
-
if (
|
|
752
|
-
var P =
|
|
753
|
-
for (g =
|
|
754
|
-
W(
|
|
749
|
+
for (g = n(o).calc(x).utc(); n(g).get()[s.groupBy] === z; )
|
|
750
|
+
W(C[C.length - 1], g, !0), g = n(g).calc(x).utc();
|
|
751
|
+
if (s.groupBy === "week") {
|
|
752
|
+
var P = n(o).dayOfWeek();
|
|
753
|
+
for (g = n(o).dayOfWeek(0).utc(); C[0].length < P && g < o; )
|
|
754
|
+
W(C[C.length - 1], g, !0), g = n(g).calc(L).utc();
|
|
755
755
|
}
|
|
756
756
|
}
|
|
757
|
-
for (;
|
|
758
|
-
|
|
759
|
-
if (
|
|
760
|
-
for (
|
|
761
|
-
W(
|
|
762
|
-
return
|
|
763
|
-
},
|
|
764
|
-
switch (
|
|
757
|
+
for (; o <= m; )
|
|
758
|
+
s.groupBy === e ? W(C, o) : n(o).get()[s.groupBy] === z ? W(C[C.length - 1], o) : (C.push([]), W(C[C.length - 1], o), z = n(o).get()[s.groupBy]), o = n(o).calc(L).utc();
|
|
759
|
+
if (s.groupBy !== e && s.fillNulls)
|
|
760
|
+
for (w = n(m).calc(L).utc(); n(w).get()[s.groupBy] === z; )
|
|
761
|
+
W(C[C.length - 1], w, !0), w = n(w).calc(L).utc();
|
|
762
|
+
return C;
|
|
763
|
+
}, n.monthNames = function(s) {
|
|
764
|
+
switch (s) {
|
|
765
765
|
case "long":
|
|
766
|
-
return
|
|
766
|
+
return N;
|
|
767
767
|
default:
|
|
768
|
-
return
|
|
768
|
+
return p;
|
|
769
769
|
}
|
|
770
|
-
},
|
|
771
|
-
switch (
|
|
770
|
+
}, n.dayNames = function(s) {
|
|
771
|
+
switch (s) {
|
|
772
772
|
case "long":
|
|
773
|
-
return
|
|
773
|
+
return R;
|
|
774
774
|
default:
|
|
775
|
-
return
|
|
775
|
+
return M;
|
|
776
776
|
}
|
|
777
|
-
},
|
|
778
|
-
if (
|
|
779
|
-
c =
|
|
777
|
+
}, n.lang = function(s) {
|
|
778
|
+
if (s !== e)
|
|
779
|
+
c = s, l[c] === e && (c = "en"), N = O(), p = T(), R = b(), M = I();
|
|
780
780
|
else
|
|
781
781
|
return c;
|
|
782
782
|
return e;
|
|
783
|
-
},
|
|
784
|
-
return Object.keys(
|
|
785
|
-
},
|
|
786
|
-
|
|
787
|
-
format:
|
|
788
|
-
parse:
|
|
783
|
+
}, n.availableLangs = function() {
|
|
784
|
+
return Object.keys(l);
|
|
785
|
+
}, n.registerFormat = function(s, o, m, g, w, L) {
|
|
786
|
+
k[s] = {
|
|
787
|
+
format: o,
|
|
788
|
+
parse: m,
|
|
789
789
|
minLength: g,
|
|
790
|
-
maxLength:
|
|
790
|
+
maxLength: w,
|
|
791
791
|
type: L
|
|
792
792
|
};
|
|
793
|
-
},
|
|
794
|
-
delete
|
|
795
|
-
},
|
|
796
|
-
var
|
|
797
|
-
return
|
|
798
|
-
},
|
|
799
|
-
TempusDate:
|
|
800
|
-
},
|
|
801
|
-
if (
|
|
802
|
-
return
|
|
803
|
-
|
|
804
|
-
},
|
|
805
|
-
typeof
|
|
806
|
-
|
|
807
|
-
}, function(
|
|
793
|
+
}, n.unregisterFormat = function(s) {
|
|
794
|
+
delete k[s];
|
|
795
|
+
}, n.detectFormat = function(s) {
|
|
796
|
+
var o, m, g;
|
|
797
|
+
return o = h(s, 0), o !== "" && (g = 10), m = s.charAt(g), (m === "T" || m === " ") && (o += m, g += 1), o += A(s, g), o;
|
|
798
|
+
}, f = {
|
|
799
|
+
TempusDate: D
|
|
800
|
+
}, n.classes = function(s, o) {
|
|
801
|
+
if (o === e)
|
|
802
|
+
return f[s];
|
|
803
|
+
f[s] = o;
|
|
804
|
+
}, n.loadTranslations = function(s) {
|
|
805
|
+
typeof s == "object" ? l = s : typeof s == "string" && H(s, function(o) {
|
|
806
|
+
l = o;
|
|
807
|
+
}, function(o) {
|
|
808
808
|
});
|
|
809
|
-
}, c = (
|
|
810
|
-
}).call(
|
|
811
|
-
})(
|
|
812
|
-
var
|
|
813
|
-
const
|
|
814
|
-
var
|
|
815
|
-
const
|
|
816
|
-
constructor(
|
|
809
|
+
}, c = (d.language || d.systemLanguage || d.userLanguage || "en").substr(0, 2).toLowerCase(), l[c] === e && (c = "en"), N = O(), p = T(), R = b(), M = I(), y.exports && (t = y.exports = n), t.tempus = n;
|
|
810
|
+
}).call(ye);
|
|
811
|
+
})(Xt, Xt.exports);
|
|
812
|
+
var Oe = Xt.exports;
|
|
813
|
+
const yt = /* @__PURE__ */ Ne(Oe);
|
|
814
|
+
var _t, Vt, Tt, Et, bt, It, ot, Nt, St, $t, Rt, te, Q, nt, $, ht, tt, lt, Lt, ee, ut, jt;
|
|
815
|
+
const J = class J {
|
|
816
|
+
constructor(t) {
|
|
817
817
|
/**
|
|
818
818
|
* Режим «прогресс по доле завершённых подкоманд» — только когда пачка похожа на
|
|
819
819
|
* много параллельных list (crm.deal.list × N и т.п.). Иначе сохраняется старая
|
|
820
820
|
* формула sum(count)/sum(total)×chunkRate (один длинный list, batchTotalCount, смешанные batch).
|
|
821
821
|
* @returns {boolean}
|
|
822
822
|
*/
|
|
823
|
-
|
|
823
|
+
S(this, _t);
|
|
824
824
|
/**
|
|
825
825
|
* Одно обновление колбэка прогресса, если снимок изменился.
|
|
826
826
|
* @returns {void}
|
|
827
827
|
*/
|
|
828
|
-
|
|
828
|
+
S(this, ot);
|
|
829
829
|
/**
|
|
830
830
|
* Проверяет, изменились ли метрики прогресса относительно предыдущей отправки.
|
|
831
831
|
*
|
|
832
832
|
* @param {{percent: number, allCount: number, allTotal: number}} snapshot - Текущий снимок прогресса.
|
|
833
833
|
* @returns {boolean} `true`, если нужно отправить callback прогресса.
|
|
834
834
|
*/
|
|
835
|
-
|
|
835
|
+
S(this, St);
|
|
836
836
|
/**
|
|
837
837
|
* Уведомляет подписчиков о текущем состоянии лимита.
|
|
838
838
|
*
|
|
839
839
|
* @returns {void}
|
|
840
840
|
*/
|
|
841
|
-
|
|
841
|
+
S(this, Rt);
|
|
842
842
|
/**
|
|
843
843
|
* Включает состояние лимита, выдерживает паузу и затем выключает лимит.
|
|
844
844
|
* Используется как единый "cooldown" перед повторной отправкой chunk.
|
|
@@ -846,7 +846,7 @@ const j = class j {
|
|
|
846
846
|
* @param {number} [pauseMs=this.defaultPauseMs] - Длительность паузы; для batch по умолчанию 120 с, для `call()` — `callLimitPauseMs` (30 с).
|
|
847
847
|
* @returns {Promise<void>}
|
|
848
848
|
*/
|
|
849
|
-
|
|
849
|
+
S(this, Q);
|
|
850
850
|
/**
|
|
851
851
|
* Проверяет operating-time в результате batch и ставит паузу,
|
|
852
852
|
* если сервер приблизился к лимиту выполнения.
|
|
@@ -854,7 +854,7 @@ const j = class j {
|
|
|
854
854
|
* @param {Object} result - Результат текущего batch-запроса.
|
|
855
855
|
* @returns {Promise<number>} Максимальный operating-time среди команд.
|
|
856
856
|
*/
|
|
857
|
-
|
|
857
|
+
S(this, $);
|
|
858
858
|
/**
|
|
859
859
|
* Выполняет один chunk с автоматическим повтором после лимит-паузы.
|
|
860
860
|
* Повтор запускается при ошибках QUERY_LIMIT_EXCEEDED, OPERATION_TIME_LIMIT или TIMEOUT.
|
|
@@ -863,7 +863,7 @@ const j = class j {
|
|
|
863
863
|
* @param {(result: Object) => Promise<void>} processResult - Обработчик успешного результата chunk.
|
|
864
864
|
* @returns {Promise<void>}
|
|
865
865
|
*/
|
|
866
|
-
|
|
866
|
+
S(this, tt);
|
|
867
867
|
/**
|
|
868
868
|
* Выполняет BX24.callMethod с таймаутом ожидания ответа.
|
|
869
869
|
*
|
|
@@ -871,14 +871,14 @@ const j = class j {
|
|
|
871
871
|
* @param {Object} params - Параметры REST-метода.
|
|
872
872
|
* @returns {Promise<Object|null>} Raw-result BX24 или null при таймауте/ошибке вызова.
|
|
873
873
|
*/
|
|
874
|
-
|
|
874
|
+
S(this, Lt);
|
|
875
875
|
/**
|
|
876
876
|
* Resets mutable runtime state before each public batch run.
|
|
877
877
|
* @param {Function} progressCall - Progress callback for current run.
|
|
878
878
|
* @returns {void}
|
|
879
879
|
*/
|
|
880
|
-
|
|
881
|
-
typeof
|
|
880
|
+
S(this, ut);
|
|
881
|
+
typeof t == "function" ? (this.callBatch = t, this.callMethod = null) : (this.callBatch = (t == null ? void 0 : t.callBatch) || null, this.callMethod = (t == null ? void 0 : t.callMethod) || null), this.result = {}, this.errors = {}, this.timeLimit = {
|
|
882
882
|
limit: !1,
|
|
883
883
|
date: void 0,
|
|
884
884
|
pauseMs: void 0
|
|
@@ -891,31 +891,31 @@ const j = class j {
|
|
|
891
891
|
get progressPercent() {
|
|
892
892
|
if (!this.progressData)
|
|
893
893
|
return { percent: 0, allCount: 0, allTotal: 0 };
|
|
894
|
-
const
|
|
895
|
-
if (
|
|
896
|
-
let
|
|
894
|
+
const t = this.totalBatchCommands || 0;
|
|
895
|
+
if (t > 0 && Array.isArray(this.batchCommandKeyOrder) && this.batchCommandKeyOrder.length && _(this, _t, Vt).call(this)) {
|
|
896
|
+
let h = 0;
|
|
897
897
|
for (const c of this.batchCommandKeyOrder) {
|
|
898
|
-
const
|
|
899
|
-
if (!
|
|
898
|
+
const l = this.progressData[c];
|
|
899
|
+
if (!l)
|
|
900
900
|
continue;
|
|
901
|
-
const O = Number(
|
|
902
|
-
O === 0 &&
|
|
901
|
+
const O = Number(l.total) || 0, T = Number(l.count) || 0;
|
|
902
|
+
O === 0 && T === 0 ? h += 1 : O > 0 && (h += Math.min(1, T / O));
|
|
903
903
|
}
|
|
904
|
-
const
|
|
905
|
-
let
|
|
906
|
-
const
|
|
907
|
-
return { percent:
|
|
904
|
+
const u = h / t * 100;
|
|
905
|
+
let n = Math.max(0, Math.min(100, Math.floor(u)));
|
|
906
|
+
const f = t, d = Math.min(t, Math.floor(h));
|
|
907
|
+
return { percent: n, allCount: d, allTotal: f };
|
|
908
908
|
}
|
|
909
|
-
let e = 0,
|
|
910
|
-
for (const
|
|
911
|
-
const { total:
|
|
912
|
-
e +=
|
|
909
|
+
let e = 0, r = 0;
|
|
910
|
+
for (const h of Object.values(this.progressData)) {
|
|
911
|
+
const { total: u, count: n } = h;
|
|
912
|
+
e += u ?? 0, r += n ?? 0;
|
|
913
913
|
}
|
|
914
|
-
const
|
|
915
|
-
let
|
|
916
|
-
e ?
|
|
917
|
-
let
|
|
918
|
-
return e > 0 &&
|
|
914
|
+
const i = Number(this.chunkRate) || 0;
|
|
915
|
+
let a = 0;
|
|
916
|
+
e ? a = r / e * 100 * i + this.totalProgress : r === 0 && e === 0 ? a = 100 * i + this.totalProgress : a = 100, a = Math.max(0, Math.min(a, 100));
|
|
917
|
+
let A = Math.floor(a);
|
|
918
|
+
return e > 0 && r >= e && (A = 100), { percent: A, allCount: r, allTotal: e };
|
|
919
919
|
}
|
|
920
920
|
/**
|
|
921
921
|
* Обновление данных прогресса выполнения
|
|
@@ -924,38 +924,38 @@ const j = class j {
|
|
|
924
924
|
* @param {Object} params.value - Значение ответа от API
|
|
925
925
|
* @param {string} params.type - Тип обработки ('count' или undefined)
|
|
926
926
|
*/
|
|
927
|
-
setProgressData({ key:
|
|
928
|
-
var
|
|
927
|
+
setProgressData({ key: t, value: e, type: r }) {
|
|
928
|
+
var l, O;
|
|
929
929
|
if (!this.progressCall)
|
|
930
930
|
return;
|
|
931
|
-
const
|
|
932
|
-
let
|
|
931
|
+
const i = this.getData(e.data()), a = Array.isArray(i) ? i.length : 0;
|
|
932
|
+
let A = a;
|
|
933
933
|
if (typeof e.total == "function") {
|
|
934
|
-
const
|
|
935
|
-
if (
|
|
936
|
-
const
|
|
937
|
-
Number.isFinite(
|
|
934
|
+
const T = e.total();
|
|
935
|
+
if (T != null && T !== "") {
|
|
936
|
+
const b = Number(T);
|
|
937
|
+
Number.isFinite(b) && (A = b);
|
|
938
938
|
}
|
|
939
939
|
}
|
|
940
|
-
|
|
941
|
-
let
|
|
942
|
-
|
|
943
|
-
const
|
|
944
|
-
if (this.progressData[
|
|
945
|
-
total:
|
|
946
|
-
count: Math.min(
|
|
940
|
+
r === "count" && (A = a);
|
|
941
|
+
let h = 1;
|
|
942
|
+
i && (h = a), this.progressData || (this.progressData = {});
|
|
943
|
+
const u = ((l = this.progressData[t]) == null ? void 0 : l.total) ?? 0, n = ((O = this.progressData[t]) == null ? void 0 : O.count) ?? 0, f = h + n, d = Math.max(u, A ?? 0, f);
|
|
944
|
+
if (this.progressData[t] = {
|
|
945
|
+
total: d,
|
|
946
|
+
count: Math.min(f, d)
|
|
947
947
|
}, typeof document < "u" && (document == null ? void 0 : document.hidden) === !0) {
|
|
948
|
-
|
|
948
|
+
_(this, ot, Nt).call(this);
|
|
949
949
|
return;
|
|
950
950
|
}
|
|
951
|
-
|
|
951
|
+
_(this, ot, Nt).call(this), this.progressTimer || (this.progressTimer = setInterval(() => {
|
|
952
952
|
if (!this.progressCall) {
|
|
953
953
|
this.clearProgressData();
|
|
954
954
|
return;
|
|
955
955
|
}
|
|
956
|
-
|
|
957
|
-
const { percent:
|
|
958
|
-
|
|
956
|
+
_(this, ot, Nt).call(this);
|
|
957
|
+
const { percent: T } = this.progressPercent;
|
|
958
|
+
T >= 100 && (clearInterval(this.progressTimer), this.progressTimer = "");
|
|
959
959
|
}, this.progressDelay));
|
|
960
960
|
}
|
|
961
961
|
/**
|
|
@@ -963,10 +963,10 @@ const j = class j {
|
|
|
963
963
|
* @param {Object} data - Ответ от API
|
|
964
964
|
* @returns {any} Данные из ответа
|
|
965
965
|
*/
|
|
966
|
-
getData(
|
|
967
|
-
if (
|
|
968
|
-
return
|
|
969
|
-
let e = (
|
|
966
|
+
getData(t) {
|
|
967
|
+
if (t == null)
|
|
968
|
+
return t;
|
|
969
|
+
let e = (t == null ? void 0 : t.items) ?? (t == null ? void 0 : t.tasks) ?? (t == null ? void 0 : t.types) ?? (t == null ? void 0 : t.type) ?? (t == null ? void 0 : t.fields) ?? (t == null ? void 0 : t.workgroups) ?? t;
|
|
970
970
|
return e && typeof e == "object" && !Array.isArray(e) && Array.isArray(e.result) && (e = e.result), e;
|
|
971
971
|
}
|
|
972
972
|
/**
|
|
@@ -977,8 +977,8 @@ const j = class j {
|
|
|
977
977
|
* @param {number|undefined} pauseMs - Длительность текущей лимит-паузы (мс); при снятии лимита не передаётся.
|
|
978
978
|
* @returns {void}
|
|
979
979
|
*/
|
|
980
|
-
setTimeLimitState(
|
|
981
|
-
this.timeLimit.limit = !!
|
|
980
|
+
setTimeLimitState(t, e, r) {
|
|
981
|
+
this.timeLimit.limit = !!t, this.timeLimit.date = t ? e : void 0, t && typeof r == "number" && r > 0 ? this.timeLimit.pauseMs = r : this.timeLimit.pauseMs = void 0, _(this, Rt, te).call(this);
|
|
982
982
|
}
|
|
983
983
|
/**
|
|
984
984
|
* Подписывает внешний код на изменения состояния лимита.
|
|
@@ -987,14 +987,14 @@ const j = class j {
|
|
|
987
987
|
* @param {(state: {limit: boolean, date?: string, pauseMs?: number}) => void} callback - Обработчик состояния лимита.
|
|
988
988
|
* @returns {() => void} Функция отписки.
|
|
989
989
|
*/
|
|
990
|
-
subscribeTimeLimit(
|
|
991
|
-
return typeof
|
|
992
|
-
} : (this.timeLimitListeners.add(
|
|
990
|
+
subscribeTimeLimit(t) {
|
|
991
|
+
return typeof t != "function" ? () => {
|
|
992
|
+
} : (this.timeLimitListeners.add(t), t({
|
|
993
993
|
limit: this.timeLimit.limit,
|
|
994
994
|
date: this.timeLimit.date,
|
|
995
995
|
pauseMs: this.timeLimit.pauseMs
|
|
996
996
|
}), () => {
|
|
997
|
-
this.timeLimitListeners.delete(
|
|
997
|
+
this.timeLimitListeners.delete(t);
|
|
998
998
|
});
|
|
999
999
|
}
|
|
1000
1000
|
/**
|
|
@@ -1004,29 +1004,29 @@ const j = class j {
|
|
|
1004
1004
|
* @param {Object} request - Объект запроса {method, params}
|
|
1005
1005
|
* @returns {Array} Массив запросов (может быть один или несколько)
|
|
1006
1006
|
*/
|
|
1007
|
-
splitLargeFilters(
|
|
1008
|
-
const { method:
|
|
1009
|
-
if (!
|
|
1010
|
-
return [{ key:
|
|
1011
|
-
const
|
|
1012
|
-
if (!
|
|
1013
|
-
return [{ key:
|
|
1014
|
-
for (const [
|
|
1015
|
-
if (!String(
|
|
1016
|
-
const
|
|
1017
|
-
for (let
|
|
1018
|
-
const
|
|
1019
|
-
|
|
1020
|
-
key:
|
|
1021
|
-
request: { method:
|
|
1022
|
-
originalKey:
|
|
1023
|
-
filterKey:
|
|
1024
|
-
chunkIndex: Math.floor(
|
|
1007
|
+
splitLargeFilters(t, e) {
|
|
1008
|
+
const { method: r, params: i } = e;
|
|
1009
|
+
if (!i)
|
|
1010
|
+
return [{ key: t, request: e }];
|
|
1011
|
+
const a = i.filter || i.FILTER;
|
|
1012
|
+
if (!a || typeof a != "object" || Array.isArray(a))
|
|
1013
|
+
return [{ key: t, request: e }];
|
|
1014
|
+
for (const [A, h] of Object.entries(a))
|
|
1015
|
+
if (!String(A).trim().startsWith("!") && Array.isArray(h) && h.length > this.filterChunkSize) {
|
|
1016
|
+
const u = [];
|
|
1017
|
+
for (let n = 0; n < h.length; n += this.filterChunkSize) {
|
|
1018
|
+
const f = h.slice(n, n + this.filterChunkSize), d = n === 0 ? t : `${t}__chunk_${Math.floor(n / this.filterChunkSize)}`, c = { ...i };
|
|
1019
|
+
i.filter ? (c.filter = { ...a }, c.filter[A] = f) : i.FILTER && (c.FILTER = { ...a }, c.FILTER[A] = f), u.push({
|
|
1020
|
+
key: d,
|
|
1021
|
+
request: { method: r, params: c },
|
|
1022
|
+
originalKey: t,
|
|
1023
|
+
filterKey: A,
|
|
1024
|
+
chunkIndex: Math.floor(n / this.filterChunkSize)
|
|
1025
1025
|
});
|
|
1026
1026
|
}
|
|
1027
|
-
return
|
|
1027
|
+
return u;
|
|
1028
1028
|
}
|
|
1029
|
-
return [{ key:
|
|
1029
|
+
return [{ key: t, request: e }];
|
|
1030
1030
|
}
|
|
1031
1031
|
/**
|
|
1032
1032
|
* Объединяет результаты разбитых запросов обратно в один результат
|
|
@@ -1034,16 +1034,16 @@ const j = class j {
|
|
|
1034
1034
|
* @param {string} originalKey - Оригинальный ключ запроса
|
|
1035
1035
|
* @returns {Array} Объединенный массив результатов
|
|
1036
1036
|
*/
|
|
1037
|
-
mergeSplitResults(
|
|
1038
|
-
const
|
|
1039
|
-
const
|
|
1040
|
-
return
|
|
1037
|
+
mergeSplitResults(t, e) {
|
|
1038
|
+
const r = [], i = String(e).replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = new RegExp(`^${i}(?:__chunk_\\d+)?$`), A = Object.keys(t).filter((h) => a.test(h)).sort((h, u) => {
|
|
1039
|
+
const n = h.match(/__chunk_(\d+)$/), f = u.match(/__chunk_(\d+)$/);
|
|
1040
|
+
return n ? f ? parseInt(n[1]) - parseInt(f[1]) : 1 : -1;
|
|
1041
1041
|
});
|
|
1042
|
-
for (const
|
|
1043
|
-
const
|
|
1044
|
-
Array.isArray(
|
|
1042
|
+
for (const h of A) {
|
|
1043
|
+
const u = t[h];
|
|
1044
|
+
Array.isArray(u) ? r.push(...u) : u && r.push(u);
|
|
1045
1045
|
}
|
|
1046
|
-
return
|
|
1046
|
+
return r;
|
|
1047
1047
|
}
|
|
1048
1048
|
/**
|
|
1049
1049
|
* Задержка между запросами
|
|
@@ -1060,26 +1060,26 @@ const j = class j {
|
|
|
1060
1060
|
* @param {Function} callback - Callback функция для обработки результата
|
|
1061
1061
|
* @returns {Promise<void>}
|
|
1062
1062
|
*/
|
|
1063
|
-
callBatchWithTimeout(
|
|
1064
|
-
return new Promise((
|
|
1065
|
-
let
|
|
1066
|
-
const
|
|
1067
|
-
if (!
|
|
1068
|
-
|
|
1063
|
+
callBatchWithTimeout(t, e) {
|
|
1064
|
+
return new Promise((r, i) => {
|
|
1065
|
+
let a = !1, A = null;
|
|
1066
|
+
const h = async (n) => {
|
|
1067
|
+
if (!a) {
|
|
1068
|
+
a = !0, A && clearTimeout(A);
|
|
1069
1069
|
try {
|
|
1070
|
-
await Promise.resolve(e(
|
|
1071
|
-
} catch (
|
|
1072
|
-
console.error("Error in callBatch callback:",
|
|
1070
|
+
await Promise.resolve(e(n)), r();
|
|
1071
|
+
} catch (f) {
|
|
1072
|
+
console.error("Error in callBatch callback:", f), i(f);
|
|
1073
1073
|
}
|
|
1074
1074
|
}
|
|
1075
|
-
},
|
|
1076
|
-
if (!
|
|
1077
|
-
|
|
1075
|
+
}, u = async () => {
|
|
1076
|
+
if (!a) {
|
|
1077
|
+
a = !0, A && clearTimeout(A), console.warn(
|
|
1078
1078
|
`Batch request timeout after ${this.requestTimeoutMs}ms. This may indicate a CORS or network error.`
|
|
1079
1079
|
);
|
|
1080
|
-
const
|
|
1081
|
-
Object.keys(
|
|
1082
|
-
|
|
1080
|
+
const n = {};
|
|
1081
|
+
Object.keys(t).forEach((f) => {
|
|
1082
|
+
n[f] = {
|
|
1083
1083
|
error: () => ({
|
|
1084
1084
|
ex: {
|
|
1085
1085
|
error: "TIMEOUT",
|
|
@@ -1091,23 +1091,23 @@ const j = class j {
|
|
|
1091
1091
|
};
|
|
1092
1092
|
});
|
|
1093
1093
|
try {
|
|
1094
|
-
await Promise.resolve(e(
|
|
1095
|
-
} catch (
|
|
1096
|
-
console.error("Error in timeout callback:",
|
|
1094
|
+
await Promise.resolve(e(n)), r();
|
|
1095
|
+
} catch (f) {
|
|
1096
|
+
console.error("Error in timeout callback:", f), r();
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
1099
|
};
|
|
1100
1100
|
try {
|
|
1101
|
-
this.callBatch(
|
|
1102
|
-
await
|
|
1101
|
+
this.callBatch(t, async (n) => {
|
|
1102
|
+
await h(n);
|
|
1103
1103
|
});
|
|
1104
|
-
} catch (
|
|
1105
|
-
|
|
1104
|
+
} catch (n) {
|
|
1105
|
+
a || console.error("Error calling callBatch:", n);
|
|
1106
1106
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1107
|
+
A = setTimeout(async () => {
|
|
1108
|
+
a || (console.warn(
|
|
1109
1109
|
`Batch request attempt timeout after ${this.requestTimeoutMs}ms. Switching to timeout fallback result.`
|
|
1110
|
-
), await
|
|
1110
|
+
), await u());
|
|
1111
1111
|
}, this.requestTimeoutMs);
|
|
1112
1112
|
});
|
|
1113
1113
|
}
|
|
@@ -1129,59 +1129,59 @@ const j = class j {
|
|
|
1129
1129
|
* @param {{oneBatch?: boolean}} [options] - Опции выполнения.
|
|
1130
1130
|
* @returns {Promise<Object>}
|
|
1131
1131
|
*/
|
|
1132
|
-
async batch(
|
|
1133
|
-
|
|
1134
|
-
const
|
|
1135
|
-
for (const [
|
|
1136
|
-
const c = this.arrayChunk(
|
|
1132
|
+
async batch(t, e, r = {}) {
|
|
1133
|
+
_(this, ut, jt).call(this, e);
|
|
1134
|
+
const i = {}, a = {}, A = {};
|
|
1135
|
+
for (const [f, d] of Object.entries(t)) {
|
|
1136
|
+
const c = this.arrayChunk(d);
|
|
1137
1137
|
if (!c)
|
|
1138
1138
|
continue;
|
|
1139
|
-
const
|
|
1140
|
-
if (
|
|
1141
|
-
|
|
1139
|
+
const l = this.splitLargeFilters(f, c);
|
|
1140
|
+
if (l.length === 1)
|
|
1141
|
+
a[f] = c;
|
|
1142
1142
|
else {
|
|
1143
|
-
|
|
1144
|
-
for (const O of
|
|
1145
|
-
|
|
1143
|
+
A[f] = [];
|
|
1144
|
+
for (const O of l)
|
|
1145
|
+
a[O.key] = O.request, A[f].push(O.key);
|
|
1146
1146
|
}
|
|
1147
1147
|
}
|
|
1148
|
-
this.batchCommandKeyOrder = Object.keys(
|
|
1149
|
-
(
|
|
1150
|
-
var
|
|
1151
|
-
return String(((
|
|
1148
|
+
this.batchCommandKeyOrder = Object.keys(a), this.totalBatchCommands = this.batchCommandKeyOrder.length, this.batchCommandMethods = this.batchCommandKeyOrder.map(
|
|
1149
|
+
(f) => {
|
|
1150
|
+
var d;
|
|
1151
|
+
return String(((d = a[f]) == null ? void 0 : d.method) || "");
|
|
1152
1152
|
}
|
|
1153
|
-
), this.chunkRate = (1 / Math.ceil(Object.keys(
|
|
1154
|
-
let
|
|
1155
|
-
const
|
|
1156
|
-
for (const [
|
|
1153
|
+
), this.chunkRate = (1 / Math.ceil(Object.keys(a).length / this.limit)).toFixed(5);
|
|
1154
|
+
let h = {}, u = 0;
|
|
1155
|
+
const n = Object.keys(a).length;
|
|
1156
|
+
for (const [f, d] of Object.entries(a)) {
|
|
1157
1157
|
if (!this.canContinue)
|
|
1158
1158
|
break;
|
|
1159
|
-
if (
|
|
1160
|
-
const c =
|
|
1159
|
+
if (h[f] = d, Object.keys(h).length >= this.limit || u + 1 === n) {
|
|
1160
|
+
const c = u + 1 === n;
|
|
1161
1161
|
await this.batchChunk(
|
|
1162
|
-
|
|
1162
|
+
h,
|
|
1163
1163
|
void 0,
|
|
1164
1164
|
!c,
|
|
1165
1165
|
{
|
|
1166
1166
|
disablePagination: !1,
|
|
1167
|
-
oneBatch: !!(
|
|
1167
|
+
oneBatch: !!(r != null && r.oneBatch)
|
|
1168
1168
|
}
|
|
1169
|
-
), Object.entries(this.result).forEach(([
|
|
1170
|
-
|
|
1169
|
+
), Object.entries(this.result).forEach(([l, O]) => {
|
|
1170
|
+
i[l] = O;
|
|
1171
1171
|
}), this.totalProgress = Math.round(
|
|
1172
|
-
|
|
1173
|
-
),
|
|
1172
|
+
u / n * 100
|
|
1173
|
+
), h = {};
|
|
1174
1174
|
}
|
|
1175
|
-
|
|
1175
|
+
u++;
|
|
1176
1176
|
}
|
|
1177
|
-
for (const [
|
|
1178
|
-
if (
|
|
1179
|
-
const c = this.mergeSplitResults(
|
|
1180
|
-
for (const
|
|
1181
|
-
delete
|
|
1182
|
-
|
|
1177
|
+
for (const [f, d] of Object.entries(A))
|
|
1178
|
+
if (d && d.length > 0) {
|
|
1179
|
+
const c = this.mergeSplitResults(i, f);
|
|
1180
|
+
for (const l of d)
|
|
1181
|
+
delete i[l];
|
|
1182
|
+
i[f] = c;
|
|
1183
1183
|
}
|
|
1184
|
-
return Object.entries(this.errors).length && (
|
|
1184
|
+
return Object.entries(this.errors).length && (i.errorsList = this.errors), e && e({ percent: 100 }), Promise.resolve(i);
|
|
1185
1185
|
}
|
|
1186
1186
|
/**
|
|
1187
1187
|
* Выполняет батч-запрос и возвращает только количество элементов для каждой команды.
|
|
@@ -1192,62 +1192,62 @@ const j = class j {
|
|
|
1192
1192
|
* @param {Function} progressCall - Callback для отслеживания прогресса
|
|
1193
1193
|
* @returns {Promise<Object>} Объект с количеством элементов для каждого ключа
|
|
1194
1194
|
*/
|
|
1195
|
-
async batchTotalCount(
|
|
1196
|
-
|
|
1197
|
-
const
|
|
1198
|
-
for (const [
|
|
1199
|
-
const
|
|
1200
|
-
if (!
|
|
1195
|
+
async batchTotalCount(t, e) {
|
|
1196
|
+
_(this, ut, jt).call(this, e);
|
|
1197
|
+
const r = {}, i = {}, a = {};
|
|
1198
|
+
for (const [u, n] of Object.entries(t)) {
|
|
1199
|
+
const f = this.arrayChunk(n);
|
|
1200
|
+
if (!f)
|
|
1201
1201
|
continue;
|
|
1202
|
-
const
|
|
1203
|
-
if (
|
|
1204
|
-
|
|
1202
|
+
const d = this.splitLargeFilters(u, f);
|
|
1203
|
+
if (d.length === 1)
|
|
1204
|
+
i[u] = f;
|
|
1205
1205
|
else {
|
|
1206
|
-
|
|
1207
|
-
for (const c of
|
|
1208
|
-
|
|
1206
|
+
a[u] = [];
|
|
1207
|
+
for (const c of d)
|
|
1208
|
+
i[c.key] = c.request, a[u].push(c.key);
|
|
1209
1209
|
}
|
|
1210
1210
|
}
|
|
1211
|
-
const
|
|
1212
|
-
for (let
|
|
1213
|
-
const
|
|
1214
|
-
for (const [
|
|
1211
|
+
const A = [], h = Object.entries(i);
|
|
1212
|
+
for (let u = 0; u < h.length; u += this.limit) {
|
|
1213
|
+
const n = h.slice(u, u + this.limit), f = {};
|
|
1214
|
+
for (const [d, c] of n) {
|
|
1215
1215
|
if (!this.canContinue)
|
|
1216
1216
|
break;
|
|
1217
|
-
|
|
1217
|
+
f[d] = c;
|
|
1218
1218
|
}
|
|
1219
|
-
Object.keys(
|
|
1219
|
+
Object.keys(f).length > 0 && A.push(f);
|
|
1220
1220
|
}
|
|
1221
|
-
this.chunkRate = (1 /
|
|
1222
|
-
for (const [
|
|
1221
|
+
this.chunkRate = (1 / A.length).toFixed(5);
|
|
1222
|
+
for (const [u, n] of Object.entries(A)) {
|
|
1223
1223
|
if (!this.canContinue)
|
|
1224
1224
|
break;
|
|
1225
|
-
this.totalProgress = Math.round(Number(
|
|
1226
|
-
const
|
|
1227
|
-
await
|
|
1228
|
-
var c,
|
|
1229
|
-
for (const [
|
|
1225
|
+
this.totalProgress = Math.round(Number(u) / A.length * 100);
|
|
1226
|
+
const f = Number(u) === A.length - 1;
|
|
1227
|
+
await _(this, tt, lt).call(this, n, async (d) => {
|
|
1228
|
+
var c, l, O, T, b;
|
|
1229
|
+
for (const [I, N] of Object.entries(d)) {
|
|
1230
1230
|
if (!this.canContinue)
|
|
1231
1231
|
return;
|
|
1232
|
-
if (
|
|
1233
|
-
const
|
|
1234
|
-
this.errors[
|
|
1232
|
+
if (N.error()) {
|
|
1233
|
+
const k = (l = (c = N.error()) == null ? void 0 : c.ex) == null ? void 0 : l.error, U = (T = (O = N.error()) == null ? void 0 : O.ex) == null ? void 0 : T.error_description;
|
|
1234
|
+
this.errors[I] = k && k.trim() || U && U.trim() || ((b = N.error()) == null ? void 0 : b.toString()) || "Неизвестная ошибка", r[I] = 0;
|
|
1235
1235
|
continue;
|
|
1236
1236
|
}
|
|
1237
|
-
const
|
|
1238
|
-
|
|
1237
|
+
const p = this.getData(N.data()), R = Array.isArray(p) ? p.length : 0, H = typeof N.total == "function" && N.total() !== void 0 ? N.total() : R;
|
|
1238
|
+
r[I] = H, this.setProgressData({ key: I, value: N, type: "count" });
|
|
1239
1239
|
}
|
|
1240
|
-
await
|
|
1240
|
+
await _(this, $, ht).call(this, d, !f);
|
|
1241
1241
|
});
|
|
1242
1242
|
}
|
|
1243
|
-
for (const [
|
|
1244
|
-
if (
|
|
1245
|
-
let
|
|
1246
|
-
for (const
|
|
1247
|
-
|
|
1248
|
-
|
|
1243
|
+
for (const [u, n] of Object.entries(a))
|
|
1244
|
+
if (n && n.length > 0) {
|
|
1245
|
+
let f = 0;
|
|
1246
|
+
for (const d of n)
|
|
1247
|
+
r[d] !== void 0 && (f += r[d] || 0), delete r[d];
|
|
1248
|
+
r[u] = f;
|
|
1249
1249
|
}
|
|
1250
|
-
return Object.entries(this.errors).length && (
|
|
1250
|
+
return Object.entries(this.errors).length && (r.errorsList = this.errors, this.errorLogger()), e && e({ percent: 100 }), Promise.resolve(r);
|
|
1251
1251
|
}
|
|
1252
1252
|
/**
|
|
1253
1253
|
* Выполняет одиночный REST-вызов с таймаутом и авто-повтором после лимит-паузы.
|
|
@@ -1256,37 +1256,37 @@ const j = class j {
|
|
|
1256
1256
|
* @param {{method: string, params?: Object}} request - Описание REST-вызова.
|
|
1257
1257
|
* @returns {Promise<{success: boolean, data: any, answer: Object, error: string|null}>}
|
|
1258
1258
|
*/
|
|
1259
|
-
async call({ method:
|
|
1260
|
-
var
|
|
1259
|
+
async call({ method: t, params: e = {} }) {
|
|
1260
|
+
var r, i, a, A, h, u, n;
|
|
1261
1261
|
for (; ; ) {
|
|
1262
|
-
const
|
|
1263
|
-
if (!
|
|
1264
|
-
await
|
|
1262
|
+
const f = await _(this, Lt, ee).call(this, t, e);
|
|
1263
|
+
if (!f) {
|
|
1264
|
+
await _(this, Q, nt).call(this, this.callLimitPauseMs);
|
|
1265
1265
|
continue;
|
|
1266
1266
|
}
|
|
1267
|
-
const
|
|
1268
|
-
if (
|
|
1269
|
-
for (const [
|
|
1270
|
-
|
|
1271
|
-
if (
|
|
1272
|
-
const
|
|
1273
|
-
if (["QUERY_LIMIT_EXCEEDED", "OPERATION_TIME_LIMIT", "TIMEOUT"].includes(
|
|
1274
|
-
await
|
|
1267
|
+
const d = {};
|
|
1268
|
+
if (f != null && f.answer)
|
|
1269
|
+
for (const [l, O] of Object.entries(f.answer))
|
|
1270
|
+
l !== "result" && O && (d[l] = O);
|
|
1271
|
+
if (f.error()) {
|
|
1272
|
+
const l = ((i = (r = f.error()) == null ? void 0 : r.ex) == null ? void 0 : i.error) ?? "";
|
|
1273
|
+
if (["QUERY_LIMIT_EXCEEDED", "OPERATION_TIME_LIMIT", "TIMEOUT"].includes(l)) {
|
|
1274
|
+
await _(this, Q, nt).call(this, this.callLimitPauseMs);
|
|
1275
1275
|
continue;
|
|
1276
1276
|
}
|
|
1277
|
-
const O = ((
|
|
1277
|
+
const O = ((a = f.error()) == null ? void 0 : a.toString()) || ((h = (A = f.error()) == null ? void 0 : A.ex) == null ? void 0 : h.error_description) || ((n = (u = f.error()) == null ? void 0 : u.ex) == null ? void 0 : n.error) || "Неизвестная ошибка";
|
|
1278
1278
|
return {
|
|
1279
1279
|
success: !1,
|
|
1280
1280
|
data: !1,
|
|
1281
|
-
answer:
|
|
1281
|
+
answer: d,
|
|
1282
1282
|
error: O
|
|
1283
1283
|
};
|
|
1284
1284
|
}
|
|
1285
|
-
let c =
|
|
1285
|
+
let c = f.data();
|
|
1286
1286
|
return c != null && c.items && (c = c.items), {
|
|
1287
1287
|
success: !0,
|
|
1288
1288
|
data: c,
|
|
1289
|
-
answer:
|
|
1289
|
+
answer: d,
|
|
1290
1290
|
error: null
|
|
1291
1291
|
};
|
|
1292
1292
|
}
|
|
@@ -1296,31 +1296,31 @@ const j = class j {
|
|
|
1296
1296
|
* Так же переделываем некоторые запросы в нужный вид (Для task-методов)
|
|
1297
1297
|
* @param {Array/Object} request - Массив/объект методов
|
|
1298
1298
|
*/
|
|
1299
|
-
arrayChunk(
|
|
1300
|
-
let e = "",
|
|
1301
|
-
if (Array.isArray(
|
|
1302
|
-
if (!
|
|
1303
|
-
|
|
1299
|
+
arrayChunk(t) {
|
|
1300
|
+
let e = "", r = {};
|
|
1301
|
+
if (Array.isArray(t) ? [e] = t : (e = t.method, r = t.params), (e.includes("list") || e === "user.get" || e === "entity.item.get") && e !== "task.item.list") {
|
|
1302
|
+
if (!r)
|
|
1303
|
+
r = e === "entity.item.get" ? { SORT: { ID: "ASC" } } : {
|
|
1304
1304
|
order: { ID: "ASC", id: "ASC" }
|
|
1305
1305
|
};
|
|
1306
1306
|
else {
|
|
1307
|
-
e === "entity.item.get" ? (
|
|
1308
|
-
const
|
|
1309
|
-
typeof
|
|
1310
|
-
(
|
|
1307
|
+
e === "entity.item.get" ? (r.SORT || (r.SORT = { ID: "ASC" }), Array.isArray(r.select) ? r.select.includes("ID") || r.select.push("ID") : r.select = ["ID"]) : e === "tasks.task.list" ? (r.order || (r.order = {}), r.order.ID = "asc") : e === "user.get" ? (r.sort || (r.sort = "ID"), r.order || (r.order = "ASC")) : r.order = { ID: "ASC", id: "ASC" }, Array.isArray(r.select) && !r.select.includes("ID") && r.select.push("ID");
|
|
1308
|
+
const i = e === "user.get" || e === "entity.item.get" ? r.FILTER : r.filter;
|
|
1309
|
+
typeof i == "object" && i !== null && !Array.isArray(i) && Object.entries(i).forEach(([a, A]) => {
|
|
1310
|
+
(r.start === void 0 || r.start !== -1) && ["id", "ID"].includes(a) && (typeof A == "string" || Array.isArray(A) && A.length <= 50) && (r.start = -1);
|
|
1311
1311
|
});
|
|
1312
1312
|
}
|
|
1313
|
-
e === "crm.type.list" &&
|
|
1313
|
+
e === "crm.type.list" && r.order && delete r.order.ID;
|
|
1314
1314
|
}
|
|
1315
1315
|
if (e === "task.item.list")
|
|
1316
|
-
if (!
|
|
1317
|
-
|
|
1316
|
+
if (!r)
|
|
1317
|
+
r = [{ ID: "ASC" }, [""], [""], ["ID"]];
|
|
1318
1318
|
else {
|
|
1319
|
-
Array.isArray(
|
|
1320
|
-
const [
|
|
1321
|
-
|
|
1319
|
+
Array.isArray(r[0]) && (r[0] = {});
|
|
1320
|
+
const [i, a, A, h] = r;
|
|
1321
|
+
i.ID = "ASC", h[0] !== "" && h.includes("ID") || h.push("ID");
|
|
1322
1322
|
}
|
|
1323
|
-
return { method: e, params:
|
|
1323
|
+
return { method: e, params: r };
|
|
1324
1324
|
}
|
|
1325
1325
|
/** Выполняет первичный запрос с массивом методов
|
|
1326
1326
|
* При наличии более 50 элементов в нем, подготоваливаем данные и передаем в this.batchPayload
|
|
@@ -1328,46 +1328,46 @@ const j = class j {
|
|
|
1328
1328
|
* @param {Array} query - Тот же массив с методами
|
|
1329
1329
|
* @returns {Object} Объект с результатами запросов
|
|
1330
1330
|
*/
|
|
1331
|
-
async batchChunk(
|
|
1332
|
-
return new Promise((
|
|
1333
|
-
const
|
|
1334
|
-
let
|
|
1335
|
-
const
|
|
1331
|
+
async batchChunk(t, e, r = !0, i = {}) {
|
|
1332
|
+
return new Promise((a) => {
|
|
1333
|
+
const A = [];
|
|
1334
|
+
let h;
|
|
1335
|
+
const u = !!(i != null && i.disablePagination);
|
|
1336
1336
|
(async () => {
|
|
1337
|
-
await
|
|
1338
|
-
var c,
|
|
1339
|
-
for (const [
|
|
1337
|
+
await _(this, tt, lt).call(this, t, async (f) => {
|
|
1338
|
+
var c, l, O, T, b;
|
|
1339
|
+
for (const [I, N] of Object.entries(f)) {
|
|
1340
1340
|
if (!this.canContinue)
|
|
1341
1341
|
return;
|
|
1342
|
-
if (
|
|
1343
|
-
const g = (
|
|
1344
|
-
this.errors[
|
|
1342
|
+
if (N.error()) {
|
|
1343
|
+
const g = (l = (c = N.error()) == null ? void 0 : c.ex) == null ? void 0 : l.error, w = (T = (O = N.error()) == null ? void 0 : O.ex) == null ? void 0 : T.error_description;
|
|
1344
|
+
this.errors[I] = g && g.trim() || w && w.trim() || ((b = N.error()) == null ? void 0 : b.toString()) || "Неизвестная ошибка", h = !0;
|
|
1345
1345
|
}
|
|
1346
|
-
const
|
|
1347
|
-
e === "count" ? this.result[
|
|
1348
|
-
const
|
|
1349
|
-
if (!
|
|
1350
|
-
let g =
|
|
1346
|
+
const p = this.getData(N.data()), R = Array.isArray(p) ? p.length : 0, M = typeof N.total == "function" && N.total() !== void 0, H = M ? N.total() : R;
|
|
1347
|
+
e === "count" ? this.result[I] ? this.result[I] += R : this.result[I] = H : this.result[I] = p, this.setProgressData({ key: I, value: N, type: e });
|
|
1348
|
+
const k = t[I], U = Array.isArray(k) ? k[0] : k == null ? void 0 : k.method, D = typeof U == "string" && (U.includes(".list") || U === "user.get" || U === "entity.item.get"), s = e === "count" ? !M && R === this.limit : D ? R === this.limit : H > this.limit && H > R, o = e !== "count" && U === "entity.item.get" && R === this.limit && !s, m = s || o;
|
|
1349
|
+
if (!u && (!this.canContinue || m)) {
|
|
1350
|
+
let g = t[I];
|
|
1351
1351
|
if (Array.isArray(g)) {
|
|
1352
|
-
const [
|
|
1353
|
-
g = [
|
|
1352
|
+
const [w, L = {}] = g;
|
|
1353
|
+
g = [w, L];
|
|
1354
1354
|
} else {
|
|
1355
|
-
const { method:
|
|
1356
|
-
g = [
|
|
1355
|
+
const { method: w, params: L = {} } = g;
|
|
1356
|
+
g = [w, L];
|
|
1357
1357
|
}
|
|
1358
|
-
|
|
1359
|
-
|
|
1358
|
+
A.push([
|
|
1359
|
+
I,
|
|
1360
1360
|
g,
|
|
1361
|
-
|
|
1362
|
-
{ entityItemGetScan:
|
|
1361
|
+
H,
|
|
1362
|
+
{ entityItemGetScan: o }
|
|
1363
1363
|
]);
|
|
1364
1364
|
}
|
|
1365
1365
|
}
|
|
1366
|
-
|
|
1367
|
-
const
|
|
1368
|
-
await
|
|
1369
|
-
() =>
|
|
1370
|
-
) :
|
|
1366
|
+
h > 0 && this.errorLogger();
|
|
1367
|
+
const d = A.length > 0 || r;
|
|
1368
|
+
await _(this, $, ht).call(this, f, d), A.length ? await this.batchPayload(A, e, i).then(
|
|
1369
|
+
() => a(this.result)
|
|
1370
|
+
) : a(this.result);
|
|
1371
1371
|
});
|
|
1372
1372
|
})();
|
|
1373
1373
|
});
|
|
@@ -1377,226 +1377,226 @@ const j = class j {
|
|
|
1377
1377
|
* @param {String} type - Тип обработки результатов ('count' или undefined)
|
|
1378
1378
|
* @param {{oneBatch?: boolean}} [options] - Опции выполнения payload.
|
|
1379
1379
|
*/
|
|
1380
|
-
async batchPayload(
|
|
1381
|
-
const
|
|
1382
|
-
let
|
|
1383
|
-
this.result[O][this.result[O].length - 1].ID || (
|
|
1384
|
-
let
|
|
1385
|
-
if (JSON.stringify(
|
|
1380
|
+
async batchPayload(t, e, r = {}) {
|
|
1381
|
+
const i = !!(r != null && r.oneBatch), a = (O, T, b, I) => {
|
|
1382
|
+
let N = "ID";
|
|
1383
|
+
this.result[O][this.result[O].length - 1].ID || (N = "id");
|
|
1384
|
+
let p = `${N}`;
|
|
1385
|
+
if (JSON.stringify(I[1]).toLocaleLowerCase().includes('"id":"desc"') ? p = "<" + p : p = ">" + p, T === 1 || b.length === 0)
|
|
1386
1386
|
return {
|
|
1387
|
-
field:
|
|
1388
|
-
id: this.result[O][this.result[O].length - 1][
|
|
1387
|
+
field: p,
|
|
1388
|
+
id: this.result[O][this.result[O].length - 1][N]
|
|
1389
1389
|
};
|
|
1390
|
-
let
|
|
1391
|
-
const [
|
|
1392
|
-
return (
|
|
1393
|
-
field:
|
|
1394
|
-
id: `$result[${[O,
|
|
1390
|
+
let M = "";
|
|
1391
|
+
const [H, k] = I;
|
|
1392
|
+
return (H === "tasks.task.list" || H === "task.item.list") && (M = "[tasks]"), ["crm.item.list", "crm.stagehistory.list"].includes(H) && (M = "[items]"), H === "crm.type.list" && (M = "[types]"), H === "socialnetwork.api.workgroup.list" && (M = "[workgroups]"), {
|
|
1393
|
+
field: p,
|
|
1394
|
+
id: `$result[${[O, T - 1].join("__")}]${M}[49][${N}]`
|
|
1395
1395
|
};
|
|
1396
|
-
},
|
|
1397
|
-
const [
|
|
1398
|
-
let
|
|
1399
|
-
if (
|
|
1400
|
-
|
|
1401
|
-
const [
|
|
1402
|
-
return
|
|
1396
|
+
}, A = (O, T) => {
|
|
1397
|
+
const [b, I] = O;
|
|
1398
|
+
let N = JSON.parse(JSON.stringify(I)), p;
|
|
1399
|
+
if (b === "task.item.list") {
|
|
1400
|
+
N = [...N];
|
|
1401
|
+
const [R, M, H, k] = N;
|
|
1402
|
+
return M[T.field] = T.id, [b, N];
|
|
1403
1403
|
}
|
|
1404
|
-
return ["user.get"].includes(
|
|
1404
|
+
return ["user.get"].includes(b) || N.FILTER ? (N.FILTER || (N.FILTER = {}), p = N.FILTER) : (N.filter || (N.filter = {}), p = N.filter), [
|
|
1405
1405
|
"socialnetwork.api.workgroup.list",
|
|
1406
1406
|
"tasks.task.list"
|
|
1407
|
-
].includes(
|
|
1408
|
-
},
|
|
1409
|
-
Object.entries(O).forEach(([
|
|
1410
|
-
var
|
|
1411
|
-
const [
|
|
1412
|
-
if (Array.isArray(
|
|
1413
|
-
const
|
|
1414
|
-
this.errors[
|
|
1407
|
+
].includes(b) ? p[">ID"] = T.id : p[T.field] = T.id, [b, { ...N, start: -1 }];
|
|
1408
|
+
}, h = (O) => {
|
|
1409
|
+
Object.entries(O).forEach(([T, b]) => {
|
|
1410
|
+
var p, R, M, H, k;
|
|
1411
|
+
const [I] = T.split("__"), N = this.getData(b.data());
|
|
1412
|
+
if (Array.isArray(N) && (e === "count" ? this.result[I] += N.length : this.result[I].push(...N)), b.error()) {
|
|
1413
|
+
const U = (R = (p = b.error()) == null ? void 0 : p.ex) == null ? void 0 : R.error, D = (H = (M = b.error()) == null ? void 0 : M.ex) == null ? void 0 : H.error_description;
|
|
1414
|
+
this.errors[I] = U && U.trim() || D && D.trim() || ((k = b.error()) == null ? void 0 : k.toString()) || "Неизвестная ошибка";
|
|
1415
1415
|
}
|
|
1416
|
-
this.setProgressData({ key:
|
|
1416
|
+
this.setProgressData({ key: I, value: b, type: e });
|
|
1417
1417
|
});
|
|
1418
|
-
},
|
|
1418
|
+
}, u = (O, T) => {
|
|
1419
1419
|
if (!Array.isArray(O) || O.length === 0)
|
|
1420
1420
|
return null;
|
|
1421
|
-
const
|
|
1422
|
-
let
|
|
1423
|
-
|
|
1424
|
-
let
|
|
1425
|
-
return JSON.stringify(
|
|
1426
|
-
},
|
|
1427
|
-
var
|
|
1428
|
-
let
|
|
1429
|
-
for (let
|
|
1430
|
-
const
|
|
1431
|
-
if (!
|
|
1421
|
+
const b = O[O.length - 1];
|
|
1422
|
+
let I = "ID";
|
|
1423
|
+
b.ID || (I = "id");
|
|
1424
|
+
let N = I;
|
|
1425
|
+
return JSON.stringify(T[1]).toLocaleLowerCase().includes('"id":"desc"') ? N = "<" + N : N = ">" + N, { field: N, id: b[I] };
|
|
1426
|
+
}, n = 1e4, f = async (O, T) => {
|
|
1427
|
+
var I, N;
|
|
1428
|
+
let b = this.limit;
|
|
1429
|
+
for (let p = 1; this.canContinue && b === this.limit && p <= n; p++) {
|
|
1430
|
+
const R = this.result[O], M = u(R, T);
|
|
1431
|
+
if (!M)
|
|
1432
1432
|
break;
|
|
1433
|
-
const
|
|
1434
|
-
let
|
|
1435
|
-
await
|
|
1436
|
-
|
|
1433
|
+
const H = `${O}__eiscan_${p}`, k = A(T, M);
|
|
1434
|
+
let U = null;
|
|
1435
|
+
await _(this, tt, lt).call(this, { [H]: k }, async (m) => {
|
|
1436
|
+
U = m, h(m);
|
|
1437
1437
|
});
|
|
1438
|
-
const
|
|
1439
|
-
await
|
|
1440
|
-
const
|
|
1441
|
-
if ((
|
|
1442
|
-
|
|
1438
|
+
const D = p < n;
|
|
1439
|
+
await _(this, $, ht).call(this, U, D), await this.delay();
|
|
1440
|
+
const s = U == null ? void 0 : U[H];
|
|
1441
|
+
if ((I = s == null ? void 0 : s.error) != null && I.call(s)) {
|
|
1442
|
+
b = 0;
|
|
1443
1443
|
break;
|
|
1444
1444
|
}
|
|
1445
|
-
const
|
|
1446
|
-
|
|
1445
|
+
const o = this.getData((N = s == null ? void 0 : s.data) == null ? void 0 : N.call(s));
|
|
1446
|
+
b = Array.isArray(o) ? o.length : 0;
|
|
1447
1447
|
}
|
|
1448
1448
|
};
|
|
1449
|
-
let
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1452
|
-
}), c++,
|
|
1453
|
-
for await (const O of
|
|
1449
|
+
let d = [], c = 0;
|
|
1450
|
+
const l = async (O = !0) => d.length ? (await _(this, tt, lt).call(this, Object.fromEntries(d), async (T) => {
|
|
1451
|
+
h(T), await _(this, $, ht).call(this, T, O);
|
|
1452
|
+
}), c++, d = [], i && c >= 1 ? !0 : (await this.delay(), !1)) : !1;
|
|
1453
|
+
for await (const O of t) {
|
|
1454
1454
|
if (!this.canContinue)
|
|
1455
1455
|
return;
|
|
1456
|
-
const [
|
|
1457
|
-
if (
|
|
1458
|
-
if (await
|
|
1456
|
+
const [T, b, I, N = {}] = O;
|
|
1457
|
+
if (N.entityItemGetScan) {
|
|
1458
|
+
if (await l(!0))
|
|
1459
1459
|
return;
|
|
1460
|
-
if (
|
|
1460
|
+
if (i)
|
|
1461
1461
|
continue;
|
|
1462
|
-
await
|
|
1462
|
+
await f(T, b);
|
|
1463
1463
|
continue;
|
|
1464
1464
|
}
|
|
1465
|
-
let
|
|
1466
|
-
for (;
|
|
1467
|
-
const
|
|
1468
|
-
if (
|
|
1465
|
+
let p = 1;
|
|
1466
|
+
for (; I > p * this.limit; ) {
|
|
1467
|
+
const R = [T, p].join("__"), M = a(T, p, d, b);
|
|
1468
|
+
if (d.push([R, A(b, M)]), i && d.length === 49 && await l(!0) || d.length % 50 === 0 && await l(!0))
|
|
1469
1469
|
return;
|
|
1470
|
-
|
|
1470
|
+
p++;
|
|
1471
1471
|
}
|
|
1472
1472
|
}
|
|
1473
|
-
await
|
|
1473
|
+
await l(!1);
|
|
1474
1474
|
}
|
|
1475
1475
|
/**
|
|
1476
1476
|
* Вывод ошибок в консоль в группированном виде
|
|
1477
1477
|
*/
|
|
1478
1478
|
errorLogger() {
|
|
1479
|
-
console.group(`${this.constructor.name}: Ошибки в методах!`), Object.entries(this.errors).forEach(([
|
|
1480
|
-
e && console.log(`[${
|
|
1479
|
+
console.group(`${this.constructor.name}: Ошибки в методах!`), Object.entries(this.errors).forEach(([t, e]) => {
|
|
1480
|
+
e && console.log(`[${t}]`, e.toString());
|
|
1481
1481
|
}), console.groupEnd();
|
|
1482
1482
|
}
|
|
1483
1483
|
};
|
|
1484
|
-
|
|
1485
|
-
const
|
|
1486
|
-
if (
|
|
1484
|
+
_t = new WeakSet(), Vt = function() {
|
|
1485
|
+
const t = this.totalBatchCommands || 0, e = this.batchCommandMethods;
|
|
1486
|
+
if (t < E(J, Tt) || !Array.isArray(e) || e.length !== t)
|
|
1487
1487
|
return !1;
|
|
1488
|
-
if (e.filter((
|
|
1488
|
+
if (e.filter((a) => a === "crm.deal.list").length >= E(J, Et))
|
|
1489
1489
|
return !0;
|
|
1490
|
-
const
|
|
1491
|
-
(
|
|
1490
|
+
const i = e.filter(
|
|
1491
|
+
(a) => typeof a == "string" && a.includes(".list")
|
|
1492
1492
|
).length;
|
|
1493
|
-
return
|
|
1494
|
-
},
|
|
1493
|
+
return i >= E(J, bt) && i / t >= E(J, It);
|
|
1494
|
+
}, Tt = new WeakMap(), Et = new WeakMap(), bt = new WeakMap(), It = new WeakMap(), ot = new WeakSet(), Nt = function() {
|
|
1495
1495
|
if (!this.progressCall || !this.progressData)
|
|
1496
1496
|
return;
|
|
1497
|
-
const { percent:
|
|
1498
|
-
|
|
1497
|
+
const { percent: t, allCount: e, allTotal: r } = this.progressPercent, i = { percent: t, allCount: e, allTotal: r };
|
|
1498
|
+
_(this, St, $t).call(this, i) && (this.progressCall({
|
|
1499
1499
|
data: this.progressData,
|
|
1500
|
-
percent:
|
|
1500
|
+
percent: t,
|
|
1501
1501
|
allCount: e,
|
|
1502
|
-
allTotal:
|
|
1503
|
-
}), this.lastProgressSnapshot =
|
|
1504
|
-
},
|
|
1505
|
-
return this.lastProgressSnapshot ? this.lastProgressSnapshot.percent !==
|
|
1506
|
-
},
|
|
1507
|
-
const
|
|
1502
|
+
allTotal: r
|
|
1503
|
+
}), this.lastProgressSnapshot = i);
|
|
1504
|
+
}, St = new WeakSet(), $t = function(t) {
|
|
1505
|
+
return this.lastProgressSnapshot ? this.lastProgressSnapshot.percent !== t.percent || this.lastProgressSnapshot.allCount !== t.allCount || this.lastProgressSnapshot.allTotal !== t.allTotal : !0;
|
|
1506
|
+
}, Rt = new WeakSet(), te = function() {
|
|
1507
|
+
const t = {
|
|
1508
1508
|
limit: this.timeLimit.limit,
|
|
1509
1509
|
date: this.timeLimit.date,
|
|
1510
1510
|
pauseMs: this.timeLimit.pauseMs
|
|
1511
1511
|
};
|
|
1512
1512
|
for (const e of this.timeLimitListeners)
|
|
1513
1513
|
try {
|
|
1514
|
-
e(
|
|
1515
|
-
} catch (
|
|
1516
|
-
console.warn("Batch timeLimit listener error:",
|
|
1514
|
+
e(t);
|
|
1515
|
+
} catch (r) {
|
|
1516
|
+
console.warn("Batch timeLimit listener error:", r);
|
|
1517
1517
|
}
|
|
1518
|
-
},
|
|
1519
|
-
this.setTimeLimitState(!0, (/* @__PURE__ */ new Date()).toISOString(),
|
|
1520
|
-
},
|
|
1518
|
+
}, Q = new WeakSet(), nt = async function(t = this.defaultPauseMs) {
|
|
1519
|
+
this.setTimeLimitState(!0, (/* @__PURE__ */ new Date()).toISOString(), t), await new Promise((e) => setTimeout(e, t)), this.setTimeLimitState(!1, void 0);
|
|
1520
|
+
}, $ = new WeakSet(), ht = async function(t, e = !0) {
|
|
1521
1521
|
if (!e)
|
|
1522
1522
|
return 0;
|
|
1523
|
-
let
|
|
1524
|
-
if (!
|
|
1523
|
+
let r = 0;
|
|
1524
|
+
if (!t || typeof t != "object")
|
|
1525
1525
|
return 0;
|
|
1526
|
-
for (const
|
|
1527
|
-
if (!(!
|
|
1526
|
+
for (const i of Object.values(t))
|
|
1527
|
+
if (!(!i || typeof i != "object"))
|
|
1528
1528
|
try {
|
|
1529
|
-
if (typeof
|
|
1530
|
-
const
|
|
1531
|
-
|
|
1529
|
+
if (typeof i.time == "function") {
|
|
1530
|
+
const a = i.time();
|
|
1531
|
+
a && typeof a.operating == "number" && (r = Math.max(r, a.operating));
|
|
1532
1532
|
}
|
|
1533
1533
|
} catch {
|
|
1534
1534
|
}
|
|
1535
|
-
|
|
1536
|
-
},
|
|
1537
|
-
let
|
|
1535
|
+
r >= this.operatingThreshold && await _(this, Q, nt).call(this);
|
|
1536
|
+
}, tt = new WeakSet(), lt = async function(t, e) {
|
|
1537
|
+
let r = !1, i = t;
|
|
1538
1538
|
do
|
|
1539
|
-
|
|
1540
|
-
var
|
|
1541
|
-
let
|
|
1542
|
-
const
|
|
1543
|
-
for (const [
|
|
1544
|
-
if (!(
|
|
1539
|
+
r = !1, await this.callBatchWithTimeout(i, async (a) => {
|
|
1540
|
+
var u, n;
|
|
1541
|
+
let A = !1;
|
|
1542
|
+
const h = /* @__PURE__ */ new Set();
|
|
1543
|
+
for (const [f, d] of Object.entries(a || {})) {
|
|
1544
|
+
if (!(d != null && d.error) || !d.error())
|
|
1545
1545
|
continue;
|
|
1546
|
-
const c = ((
|
|
1546
|
+
const c = ((n = (u = d.error()) == null ? void 0 : u.ex) == null ? void 0 : n.error) ?? "";
|
|
1547
1547
|
if (c === "TIMEOUT") {
|
|
1548
|
-
|
|
1548
|
+
A = !0;
|
|
1549
1549
|
break;
|
|
1550
1550
|
}
|
|
1551
|
-
["QUERY_LIMIT_EXCEEDED", "OPERATION_TIME_LIMIT"].includes(c) &&
|
|
1551
|
+
["QUERY_LIMIT_EXCEEDED", "OPERATION_TIME_LIMIT"].includes(c) && h.add(f);
|
|
1552
1552
|
}
|
|
1553
|
-
if (
|
|
1554
|
-
|
|
1553
|
+
if (A) {
|
|
1554
|
+
r = !0, await _(this, Q, nt).call(this);
|
|
1555
1555
|
return;
|
|
1556
1556
|
}
|
|
1557
|
-
if (
|
|
1558
|
-
const
|
|
1559
|
-
for (const [c,
|
|
1560
|
-
|
|
1561
|
-
Object.keys(
|
|
1562
|
-
const
|
|
1563
|
-
for (const c of
|
|
1564
|
-
|
|
1565
|
-
|
|
1557
|
+
if (h.size > 0) {
|
|
1558
|
+
const f = {};
|
|
1559
|
+
for (const [c, l] of Object.entries(a || {}))
|
|
1560
|
+
h.has(c) || (f[c] = l);
|
|
1561
|
+
Object.keys(f).length && await e(f);
|
|
1562
|
+
const d = {};
|
|
1563
|
+
for (const c of h)
|
|
1564
|
+
i[c] && (d[c] = i[c]);
|
|
1565
|
+
i = d, Object.keys(i).length && (r = !0, await _(this, Q, nt).call(this));
|
|
1566
1566
|
return;
|
|
1567
1567
|
}
|
|
1568
|
-
await e(
|
|
1568
|
+
await e(a);
|
|
1569
1569
|
});
|
|
1570
|
-
while (
|
|
1571
|
-
},
|
|
1572
|
-
return new Promise((
|
|
1570
|
+
while (r);
|
|
1571
|
+
}, Lt = new WeakSet(), ee = function(t, e) {
|
|
1572
|
+
return new Promise((r) => {
|
|
1573
1573
|
if (typeof this.callMethod != "function") {
|
|
1574
|
-
|
|
1574
|
+
r(null);
|
|
1575
1575
|
return;
|
|
1576
1576
|
}
|
|
1577
|
-
let
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1577
|
+
let i = !1;
|
|
1578
|
+
const a = setTimeout(() => {
|
|
1579
|
+
i || (i = !0, r(null));
|
|
1580
1580
|
}, this.requestTimeoutMs);
|
|
1581
1581
|
try {
|
|
1582
|
-
this.callMethod(
|
|
1583
|
-
|
|
1582
|
+
this.callMethod(t, e, (A) => {
|
|
1583
|
+
i || (i = !0, clearTimeout(a), r(A));
|
|
1584
1584
|
});
|
|
1585
1585
|
} catch {
|
|
1586
|
-
|
|
1586
|
+
i || (i = !0, clearTimeout(a), r(null));
|
|
1587
1587
|
}
|
|
1588
1588
|
});
|
|
1589
|
-
},
|
|
1590
|
-
this.clearProgressData(), this.progressCall = typeof
|
|
1589
|
+
}, ut = new WeakSet(), jt = function(t) {
|
|
1590
|
+
this.clearProgressData(), this.progressCall = typeof t == "function" ? t : "", this.canContinue = !0, this.result = {}, this.errors = {}, this.chunkRate = 1, this.totalProgress = 0, this.batchCommandKeyOrder = [], this.totalBatchCommands = 0, this.batchCommandMethods = [], this.setTimeLimitState(!1, void 0);
|
|
1591
1591
|
}, /** Не включать вес по командам для совсем маленьких batch. */
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
let v =
|
|
1596
|
-
var
|
|
1597
|
-
class
|
|
1592
|
+
S(J, Tt, 5), /** Явный сигнал: много отдельных выборок сделок по фильтрам. */
|
|
1593
|
+
S(J, Et, 5), /** Достаточно «list»-методов в пачке и доля list от всех команд. */
|
|
1594
|
+
S(J, bt, 8), S(J, It, 0.65);
|
|
1595
|
+
let v = J;
|
|
1596
|
+
var et;
|
|
1597
|
+
class se {
|
|
1598
1598
|
constructor() {
|
|
1599
|
-
|
|
1599
|
+
S(this, et, {});
|
|
1600
1600
|
}
|
|
1601
1601
|
/**
|
|
1602
1602
|
* Получить случайный хеш-код длиной 8 символов
|
|
@@ -1610,12 +1610,12 @@ class Ft {
|
|
|
1610
1610
|
* @param {number} length - Длина генерируемого хеша
|
|
1611
1611
|
* @returns {string}
|
|
1612
1612
|
*/
|
|
1613
|
-
createHash(
|
|
1614
|
-
let e = "abcdefghijklmnopqrstuvwxyz0123456789",
|
|
1615
|
-
|
|
1616
|
-
for (let
|
|
1617
|
-
|
|
1618
|
-
return
|
|
1613
|
+
createHash(t) {
|
|
1614
|
+
let e = "abcdefghijklmnopqrstuvwxyz0123456789", r = "";
|
|
1615
|
+
t = t || 6;
|
|
1616
|
+
for (let i = 0; i < t; i++)
|
|
1617
|
+
r += e.charAt(Math.floor(Math.random() * e.length));
|
|
1618
|
+
return r;
|
|
1619
1619
|
}
|
|
1620
1620
|
/**
|
|
1621
1621
|
* Фильтр часто запускаемых действий (debounce)
|
|
@@ -1624,9 +1624,9 @@ class Ft {
|
|
|
1624
1624
|
* @param {number} params.duration - Задержка в миллисекундах (по умолчанию 10)
|
|
1625
1625
|
* @param {Function} params.action - Функция для выполнения
|
|
1626
1626
|
*/
|
|
1627
|
-
actionFilter({ keyTimer:
|
|
1628
|
-
|
|
1629
|
-
|
|
1627
|
+
actionFilter({ keyTimer: t, duration: e = 10, action: r }) {
|
|
1628
|
+
E(this, et)[t] && (clearTimeout(E(this, et)[t]), E(this, et)[t] = null), r && (E(this, et)[t] = setTimeout(() => {
|
|
1629
|
+
r();
|
|
1630
1630
|
}, e));
|
|
1631
1631
|
}
|
|
1632
1632
|
/**
|
|
@@ -1634,88 +1634,88 @@ class Ft {
|
|
|
1634
1634
|
* Создает невидимое видео, которое циклически воспроизводится
|
|
1635
1635
|
*/
|
|
1636
1636
|
async noSleep() {
|
|
1637
|
-
let
|
|
1638
|
-
|
|
1639
|
-
|
|
1637
|
+
let t = document.createElement("video");
|
|
1638
|
+
t.classList.add("no-sleep"), t.muted = !0, t.autoplay = !0, t.setAttribute("playsinline", ""), t.addEventListener("loadeddata", () => {
|
|
1639
|
+
t.style.position = "fixed", t.style.left = "-9999px", document.querySelector("body").append(t), t.play().catch((e) => {
|
|
1640
1640
|
console.warn("noSleep: autoplay prevented", e);
|
|
1641
1641
|
});
|
|
1642
|
-
}),
|
|
1642
|
+
}), t.addEventListener("ended", () => {
|
|
1643
1643
|
this.actionFilter({
|
|
1644
1644
|
keyTimer: "no-sleep",
|
|
1645
1645
|
duration: 5e3,
|
|
1646
1646
|
action: () => {
|
|
1647
|
-
|
|
1647
|
+
t.play().catch((e) => {
|
|
1648
1648
|
console.warn("noSleep: replay prevented", e);
|
|
1649
1649
|
});
|
|
1650
1650
|
}
|
|
1651
1651
|
});
|
|
1652
|
-
}),
|
|
1652
|
+
}), t.src = "data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAGlzb21pc28yYXZjMW1wNDEAAAAIZnJlZQAAAP5tZGF0AAAAAQYAAADlZYiEE28FmH9jNWDBjI+Z/1tIBZsjfhbmcNNUpBFej0U3p+zhaJ3eemJRL2LUMa5tkidy6bp+eatLE3jBIY864TvaAmqEFCgLMTCwVbem1n3myAw9yDXQdR5HfU/8iYf+eneVnRf7Qx9M70XDUuPx1MJX671XJwAE0VAMpnhbcUDx0pTldvUX9KQPhkZNH3eyZHmObkAeyEJ2tl+BEBJIGc90BiqKL60+5EA6fXB6iG5UU/M5KsW8BNAAUw5CbRJIqohNk10fwKbUXwya03rqGkE8+wuYGtEbrVYXb+iOl1mHHVPLYQbIAAcGyAAHAAAFNG1vb3YAAABsbXZoZAAAAAAAAAAAAAAAAAAAA+gAAAAvAAEAAAEAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAIldHJhawAAAFx0a2hkAAAAAwAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAFAAAAA8AAAAAAAJGVkdHMAAAAcZWxzdAAAAAAAAAABAAAAAAAAAAAAAQAAAAABnW1kaWEAAAAgbWRoZAAAAAAAAAAAAAAAAAAAQAAAAAAAVcQAAAAAAC1oZGxyAAAAAAAAAAB2aWRlAAAAAAAAAAAAAAAAVmlkZW9IYW5kbGVyAAAAAUhtaW5mAAAAFHZtaGQAAAABAAAAAAAAAAAAAAAkZGluZgAAABxkcmVmAAAAAAAAAAEAAAAMdXJsIAAAAAEAAAEIc3RibAAAAKRzdHNkAAAAAAAAAAEAAACUYXZjMQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAFAAPAASAAAAEgAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABj//wAAAC5hdmNDAU1AC//hABZnTUAL2wUH7ARAAAADAEAAAAQDxQq4AQAFaOrAZXIAAAAQcGFzcAAAAAEAAAABAAAAGHN0dHMAAAAAAAAAAQAAAAEAAAAAAAAAHHN0c2MAAAAAAAAAAQAAAAEAAAABAAAAAQAAABRzdHN6AAAAAAAAAO4AAAABAAAAFHN0Y28AAAAAAAAAAQAAADAAAAIadHJhawAAAFx0a2hkAAAAAwAAAAAAAAAAAAAAAgAAAAAAAAAvAAAAAAAAAAAAAAABAQAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAJGVkdHMAAAAcZWxzdAAAAAAAAAABAAAALwAAAAAAAQAAAAABkm1kaWEAAAAgbWRoZAAAAAAAAAAAAAAAAAAArEQAAAgAVcQAAAAAAC1oZGxyAAAAAAAAAABzb3VuAAAAAAAAAAAAAAAAU291bmRIYW5kbGVyAAAAAT1taW5mAAAAEHNtaGQAAAAAAAAAAAAAACRkaW5mAAAAHGRyZWYAAAAAAAAAAQAAAAx1cmwgAAAAAQAAAQFzdGJsAAAAZ3N0c2QAAAAAAAAAAQAAAFdtcDRhAAAAAAAAAAEAAAAAAAAAAAACABAAAAAArEQAAAAAADNlc2RzAAAAAAOAgIAiAAIABICAgBRAFQAAAAAC7gAAAAViBYCAgAISCAaAgIABAgAAABhzdHRzAAAAAAAAAAEAAAACAAAEAAAAABxzdHNjAAAAAAAAAAEAAAABAAAAAgAAAAEAAAAUc3RzegAAAAAAAAAEAAAAAgAAABRzdGNvAAAAAAAAAAEAAAEeAAAAGnNncGQBAAAAcm9sbAAAAAIAAAAB//8AAAAcc2JncAAAAAByb2xsAAAAAQAAAAIAAAABAAAAgXVkdGEAAAB5bWV0YQAAAAAAAAAhaGRscgAAAAAAAAAAbWR0YQAAAAAAAAAAAAAAAAAAAAAfa2V5cwAAAAAAAAABAAAAD21kdGFlbmNvZGVyAAAALWlsc3QAAAAlAAAAAQAAAB1kYXRhAAAAAQAAAABMYXZmNTguMTIuMTAw";
|
|
1653
1653
|
}
|
|
1654
1654
|
/**
|
|
1655
1655
|
* Скачать данные в JSON-файл
|
|
1656
1656
|
* @param {any} data - Данные для сохранения
|
|
1657
1657
|
* @param {string} filename - Имя файла без расширения
|
|
1658
1658
|
*/
|
|
1659
|
-
downloadFileJson(
|
|
1660
|
-
let
|
|
1661
|
-
|
|
1662
|
-
document.body.removeChild(
|
|
1659
|
+
downloadFileJson(t, e) {
|
|
1660
|
+
let r = new Blob([JSON.stringify(t)], { type: "application/json" }), i = URL.createObjectURL(r), a = document.createElement("a");
|
|
1661
|
+
a.style.display = "none", a.href = i, a.download = `${e}.json`, document.body.appendChild(a), a.click(), setTimeout(() => {
|
|
1662
|
+
document.body.removeChild(a), URL.revokeObjectURL(i);
|
|
1663
1663
|
}, 200);
|
|
1664
1664
|
}
|
|
1665
1665
|
}
|
|
1666
|
-
|
|
1667
|
-
const
|
|
1668
|
-
var K,
|
|
1669
|
-
class
|
|
1666
|
+
et = new WeakMap();
|
|
1667
|
+
const xt = new se();
|
|
1668
|
+
var K, q, st, At, ft, Z, X, rt, it, Mt, re, dt, Jt, Dt, ie, kt, ne, wt, ae;
|
|
1669
|
+
class _e {
|
|
1670
1670
|
constructor() {
|
|
1671
|
-
|
|
1671
|
+
/** user.current — только при первом реальном использовании (сохранение лога, выгрузка). */
|
|
1672
|
+
S(this, Mt);
|
|
1672
1673
|
/** Вывод ошибок логера
|
|
1673
1674
|
* @param {'entity'} type - тип ошибки
|
|
1674
1675
|
*/
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1676
|
+
S(this, dt);
|
|
1677
|
+
S(this, Dt);
|
|
1678
|
+
S(this, kt);
|
|
1679
|
+
S(this, wt);
|
|
1680
|
+
S(this, K, "logger");
|
|
1681
|
+
S(this, q, !1);
|
|
1682
|
+
S(this, st, /* @__PURE__ */ new Map());
|
|
1683
|
+
S(this, At, {});
|
|
1684
|
+
S(this, ft, !1);
|
|
1685
|
+
S(this, Z, null);
|
|
1686
|
+
S(this, X, null);
|
|
1687
|
+
S(this, rt, !1);
|
|
1688
|
+
S(this, it, !1);
|
|
1686
1689
|
/** Очистка хранилища элементов старше 'N' месяцев */
|
|
1687
|
-
|
|
1688
|
-
E(this, Lt, Xt).call(this);
|
|
1690
|
+
B(this, "periodClear", 3);
|
|
1689
1691
|
}
|
|
1690
1692
|
/** Инициализация логера */
|
|
1691
1693
|
async init() {
|
|
1692
1694
|
try {
|
|
1693
|
-
let
|
|
1695
|
+
let t = new v(BX24.callBatch), { entityList: e } = await t.batch({
|
|
1694
1696
|
entityList: { method: "entity.get" }
|
|
1695
1697
|
});
|
|
1696
1698
|
if (e && Array.isArray(e))
|
|
1697
1699
|
if (e.find(
|
|
1698
|
-
(
|
|
1700
|
+
(i) => i.ENTITY == E(this, K)
|
|
1699
1701
|
))
|
|
1700
|
-
|
|
1702
|
+
F(this, q, !0);
|
|
1701
1703
|
else {
|
|
1702
|
-
let { entityAdd:
|
|
1704
|
+
let { entityAdd: i } = await t.batch({
|
|
1703
1705
|
entityAdd: {
|
|
1704
1706
|
method: "entity.add",
|
|
1705
1707
|
params: {
|
|
1706
|
-
ENTITY:
|
|
1707
|
-
NAME:
|
|
1708
|
+
ENTITY: E(this, K),
|
|
1709
|
+
NAME: E(this, K),
|
|
1708
1710
|
ACCESS: { AU: "X" }
|
|
1709
1711
|
}
|
|
1710
1712
|
}
|
|
1711
1713
|
});
|
|
1712
|
-
|
|
1714
|
+
i && F(this, q, !0);
|
|
1713
1715
|
}
|
|
1714
|
-
return E(this,
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
} catch (r) {
|
|
1718
|
-
return console.error("Ошибка при инициализации логера:", r), !1;
|
|
1716
|
+
return E(this, q);
|
|
1717
|
+
} catch (t) {
|
|
1718
|
+
return console.error("Ошибка при инициализации логера:", t), !1;
|
|
1719
1719
|
}
|
|
1720
1720
|
}
|
|
1721
1721
|
/**
|
|
@@ -1727,21 +1727,22 @@ class ee {
|
|
|
1727
1727
|
* }; }}
|
|
1728
1728
|
* @returns {string|null}
|
|
1729
1729
|
*/
|
|
1730
|
-
start({ type:
|
|
1731
|
-
if (
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1730
|
+
start({ type: t, data: e }) {
|
|
1731
|
+
if (fetch("http://127.0.0.1:7903/ingest/d13e6df1-e437-464b-831d-29219bd3ff29", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "e57011" }, body: JSON.stringify({ sessionId: "e57011", runId: "pre-fix", hypothesisId: "H4", location: "src/utils-kit/bx-logger.js:start", message: "logger start called", data: { isInitEntity: E(this, q), type: t, hasData: !!e }, timestamp: Date.now() }) }).catch(() => {
|
|
1732
|
+
}), !E(this, q))
|
|
1733
|
+
return _(this, dt, Jt).call(this, "entity"), null;
|
|
1734
|
+
if (!t || !e)
|
|
1735
|
+
return console.error("Невалидные данные для логирования:", { type: t, data: e }), null;
|
|
1736
|
+
const r = xt.hash, i = {
|
|
1737
|
+
type: t,
|
|
1737
1738
|
data: e,
|
|
1738
|
-
userInfo:
|
|
1739
|
+
userInfo: null,
|
|
1739
1740
|
errorList: {},
|
|
1740
1741
|
status: "",
|
|
1741
1742
|
answer: null,
|
|
1742
1743
|
date: (/* @__PURE__ */ new Date()).getTime()
|
|
1743
1744
|
};
|
|
1744
|
-
return
|
|
1745
|
+
return E(this, st).set(r, i), F(this, it, !0), r;
|
|
1745
1746
|
}
|
|
1746
1747
|
/**
|
|
1747
1748
|
* @param {{
|
|
@@ -1750,189 +1751,243 @@ class ee {
|
|
|
1750
1751
|
* status: 'success'|'fail'|'fail-runtime',
|
|
1751
1752
|
* answer: { [key]: unknown } }}
|
|
1752
1753
|
*/
|
|
1753
|
-
async stop({ key:
|
|
1754
|
-
var
|
|
1755
|
-
if (
|
|
1754
|
+
async stop({ key: t, errorList: e, status: r, answer: i }) {
|
|
1755
|
+
var A;
|
|
1756
|
+
if (fetch("http://127.0.0.1:7903/ingest/d13e6df1-e437-464b-831d-29219bd3ff29", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "e57011" }, body: JSON.stringify({ sessionId: "e57011", runId: "pre-fix", hypothesisId: "H5", location: "src/utils-kit/bx-logger.js:stop", message: "logger stop called", data: { keyPresent: !!t, status: r, loggerStarted: E(this, it) }, timestamp: Date.now() }) }).catch(() => {
|
|
1757
|
+
}), !E(this, it))
|
|
1756
1758
|
return;
|
|
1757
|
-
if (!
|
|
1758
|
-
|
|
1759
|
+
if (!E(this, q)) {
|
|
1760
|
+
_(this, dt, Jt).call(this, "entity");
|
|
1759
1761
|
return;
|
|
1760
1762
|
}
|
|
1761
|
-
let
|
|
1762
|
-
if (!
|
|
1763
|
-
console.error(`Не найдены данные логирования для ключа: ${
|
|
1763
|
+
let a = E(this, st).get(t);
|
|
1764
|
+
if (!a) {
|
|
1765
|
+
console.error(`Не найдены данные логирования для ключа: ${t}`);
|
|
1764
1766
|
return;
|
|
1765
1767
|
}
|
|
1766
|
-
e && (
|
|
1768
|
+
e && (a.errorList = e), r && (a.status = r), i && (a.answer = i), await _(this, Mt, re).call(this), a.userInfo = E(this, At), await _(this, Dt, ie).call(this), (A = a == null ? void 0 : a.data) != null && A.updateList && F(this, rt, !0), F(this, it, !1);
|
|
1767
1769
|
}
|
|
1768
1770
|
/**
|
|
1769
1771
|
* @param { ({percent}:{percent:number})=>{} } progressCall - коллбэк
|
|
1770
1772
|
*/
|
|
1771
|
-
async getEntityList(
|
|
1773
|
+
async getEntityList(t) {
|
|
1772
1774
|
var e;
|
|
1773
1775
|
try {
|
|
1774
|
-
if ((e =
|
|
1775
|
-
return
|
|
1776
|
-
let
|
|
1776
|
+
if ((e = E(this, X)) != null && e.length && !E(this, rt))
|
|
1777
|
+
return E(this, X);
|
|
1778
|
+
let r = new v(BX24.callBatch), { entityList: i } = await r.batch(
|
|
1777
1779
|
{
|
|
1778
1780
|
entityList: {
|
|
1779
1781
|
method: "entity.item.get",
|
|
1780
1782
|
params: {
|
|
1781
|
-
ENTITY:
|
|
1783
|
+
ENTITY: E(this, K),
|
|
1782
1784
|
SORT: { ID: "DESC" }
|
|
1783
1785
|
}
|
|
1784
1786
|
}
|
|
1785
1787
|
},
|
|
1786
|
-
|
|
1788
|
+
t
|
|
1787
1789
|
);
|
|
1788
|
-
return !
|
|
1790
|
+
return !i || !Array.isArray(i) ? (console.warn("Получен невалидный список записей"), []) : (i = i.map((a) => {
|
|
1789
1791
|
try {
|
|
1790
|
-
const { ID:
|
|
1792
|
+
const { ID: A, DATE_CREATE: h, DETAIL_TEXT: u } = a;
|
|
1791
1793
|
return {
|
|
1792
|
-
...JSON.parse(
|
|
1793
|
-
id:
|
|
1794
|
-
dateCreate:
|
|
1794
|
+
...JSON.parse(u),
|
|
1795
|
+
id: A,
|
|
1796
|
+
dateCreate: h
|
|
1795
1797
|
};
|
|
1796
|
-
} catch (
|
|
1798
|
+
} catch (A) {
|
|
1797
1799
|
return console.error(
|
|
1798
|
-
`Ошибка парсинга записи ${
|
|
1799
|
-
|
|
1800
|
+
`Ошибка парсинга записи ${a.ID}:`,
|
|
1801
|
+
A
|
|
1800
1802
|
), null;
|
|
1801
1803
|
}
|
|
1802
|
-
}).filter((
|
|
1803
|
-
} catch (
|
|
1804
|
-
return console.error("Ошибка при получении списка записей:",
|
|
1804
|
+
}).filter((a) => a !== null), F(this, rt, !1), F(this, X, i), i);
|
|
1805
|
+
} catch (r) {
|
|
1806
|
+
return console.error("Ошибка при получении списка записей:", r), [];
|
|
1805
1807
|
}
|
|
1806
1808
|
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Проверка возраста записей и очистка старых. Дёргает `entity.item.get` (как и выгрузка).
|
|
1811
|
+
* Не вызывается из `init` — вызывайте явно (например, из настроек или планировщика).
|
|
1812
|
+
*/
|
|
1813
|
+
runStorageMaintenance() {
|
|
1814
|
+
return _(this, kt, ne).call(this);
|
|
1815
|
+
}
|
|
1807
1816
|
/** Выгрузка всех данных из хранилища в JSON-файл */
|
|
1808
1817
|
async downAllEntityJson() {
|
|
1809
1818
|
try {
|
|
1810
|
-
if (
|
|
1819
|
+
if (E(this, X) || await this.getEntityList(), !E(this, X) || E(this, X).length === 0)
|
|
1811
1820
|
return console.warn("Нет данных для выгрузки"), !1;
|
|
1812
|
-
let
|
|
1813
|
-
return
|
|
1814
|
-
|
|
1815
|
-
`sdklogger-entity-data__${
|
|
1821
|
+
let t = yt().format("%Y-%m-%d");
|
|
1822
|
+
return xt.downloadFileJson(
|
|
1823
|
+
E(this, X),
|
|
1824
|
+
`sdklogger-entity-data__${t}`
|
|
1816
1825
|
), !0;
|
|
1817
|
-
} catch (
|
|
1818
|
-
return console.error("Ошибка при выгрузке данных в JSON:",
|
|
1826
|
+
} catch (t) {
|
|
1827
|
+
return console.error("Ошибка при выгрузке данных в JSON:", t), !1;
|
|
1819
1828
|
}
|
|
1820
1829
|
}
|
|
1821
1830
|
}
|
|
1822
|
-
K = new WeakMap(),
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1831
|
+
K = new WeakMap(), q = new WeakMap(), st = new WeakMap(), At = new WeakMap(), ft = new WeakMap(), Z = new WeakMap(), X = new WeakMap(), rt = new WeakMap(), it = new WeakMap(), Mt = new WeakSet(), re = async function() {
|
|
1832
|
+
if (!E(this, ft))
|
|
1833
|
+
return E(this, Z) ? E(this, Z) : (F(this, Z, (async () => {
|
|
1834
|
+
try {
|
|
1835
|
+
const t = new v(BX24.callBatch), e = BX24.isAdmin(), { curUser: r } = await t.batch({
|
|
1836
|
+
curUser: { method: "user.current" }
|
|
1837
|
+
});
|
|
1838
|
+
F(this, At, { isAdmin: e, curUser: r });
|
|
1839
|
+
} catch (t) {
|
|
1840
|
+
console.error(
|
|
1841
|
+
"Ошибка при получении информации о пользователе:",
|
|
1842
|
+
t
|
|
1843
|
+
), F(this, At, { isAdmin: !1, curUser: null });
|
|
1844
|
+
} finally {
|
|
1845
|
+
F(this, ft, !0), F(this, Z, null);
|
|
1846
|
+
}
|
|
1847
|
+
})()), E(this, Z));
|
|
1848
|
+
}, dt = new WeakSet(), Jt = function(t) {
|
|
1849
|
+
t == "entity" && xt.actionFilter({
|
|
1836
1850
|
keyTimer: "error.logger.entity",
|
|
1837
1851
|
duration: 500,
|
|
1838
1852
|
action: () => {
|
|
1839
1853
|
console.error("Хранилище для логгера не инициализировано");
|
|
1840
1854
|
}
|
|
1841
1855
|
});
|
|
1842
|
-
},
|
|
1856
|
+
}, Dt = new WeakSet(), ie = async function() {
|
|
1843
1857
|
try {
|
|
1844
|
-
let
|
|
1845
|
-
for (let [
|
|
1846
|
-
if (
|
|
1847
|
-
const
|
|
1848
|
-
r
|
|
1858
|
+
let t = {}, e = new v(BX24.callBatch);
|
|
1859
|
+
for (let [r, i] of E(this, st).entries())
|
|
1860
|
+
if (i.status) {
|
|
1861
|
+
const a = JSON.stringify(i);
|
|
1862
|
+
t[r] = {
|
|
1849
1863
|
method: "entity.item.add",
|
|
1850
1864
|
params: {
|
|
1851
|
-
ENTITY:
|
|
1852
|
-
NAME:
|
|
1853
|
-
DETAIL_TEXT:
|
|
1865
|
+
ENTITY: E(this, K),
|
|
1866
|
+
NAME: E(this, K),
|
|
1867
|
+
DETAIL_TEXT: a
|
|
1854
1868
|
}
|
|
1855
1869
|
};
|
|
1856
1870
|
}
|
|
1857
|
-
if (Object.keys(
|
|
1858
|
-
let
|
|
1859
|
-
for (let [
|
|
1860
|
-
|
|
1871
|
+
if (Object.keys(t).length) {
|
|
1872
|
+
let r = await e.batch(t), { errors: i } = e;
|
|
1873
|
+
for (let [a, A] of Object.entries({ ...r, ...i }))
|
|
1874
|
+
E(this, st).delete(a);
|
|
1861
1875
|
return !0;
|
|
1862
1876
|
}
|
|
1863
1877
|
return !1;
|
|
1864
|
-
} catch (
|
|
1865
|
-
return console.error("Ошибка при добавлении записей в хранилище:",
|
|
1878
|
+
} catch (t) {
|
|
1879
|
+
return console.error("Ошибка при добавлении записей в хранилище:", t), !1;
|
|
1866
1880
|
}
|
|
1867
|
-
},
|
|
1881
|
+
}, kt = new WeakSet(), ne = async function() {
|
|
1868
1882
|
try {
|
|
1869
|
-
let
|
|
1883
|
+
let t = new v(BX24.callBatch), { serverTime: e } = await t.batch({
|
|
1870
1884
|
serverTime: { method: "server.time" }
|
|
1871
1885
|
});
|
|
1872
1886
|
if (!e) {
|
|
1873
1887
|
console.error("Не удалось получить время сервера");
|
|
1874
1888
|
return;
|
|
1875
1889
|
}
|
|
1876
|
-
if (
|
|
1890
|
+
if (E(this, X) || await this.getEntityList(), !E(this, X) || E(this, X).length === 0)
|
|
1877
1891
|
return;
|
|
1878
|
-
let
|
|
1892
|
+
let r = E(this, X).filter((i) => {
|
|
1879
1893
|
try {
|
|
1880
|
-
let { dateCreate:
|
|
1881
|
-
return
|
|
1882
|
-
|
|
1894
|
+
let { dateCreate: a } = i;
|
|
1895
|
+
return a ? yt(new Date(a)).between(
|
|
1896
|
+
yt(new Date(e)),
|
|
1883
1897
|
"month"
|
|
1884
1898
|
) >= this.periodClear : !1;
|
|
1885
|
-
} catch (
|
|
1886
|
-
return console.error("Ошибка при проверке даты записи:",
|
|
1899
|
+
} catch (a) {
|
|
1900
|
+
return console.error("Ошибка при проверке даты записи:", a), !1;
|
|
1887
1901
|
}
|
|
1888
1902
|
});
|
|
1889
|
-
|
|
1890
|
-
`Найдено ${
|
|
1891
|
-
), await
|
|
1892
|
-
} catch (
|
|
1893
|
-
console.error("Ошибка при проверке периода очистки:",
|
|
1903
|
+
r.length > 0 && (console.log(
|
|
1904
|
+
`Найдено ${r.length} записей для очистки (старше ${this.periodClear} месяцев)`
|
|
1905
|
+
), await _(this, wt, ae).call(this, r));
|
|
1906
|
+
} catch (t) {
|
|
1907
|
+
console.error("Ошибка при проверке периода очистки:", t);
|
|
1894
1908
|
}
|
|
1895
|
-
},
|
|
1909
|
+
}, wt = new WeakSet(), ae = async function(t) {
|
|
1896
1910
|
try {
|
|
1897
|
-
if (!
|
|
1911
|
+
if (!t || t.length === 0)
|
|
1898
1912
|
return !1;
|
|
1899
|
-
let e = new v(BX24.callBatch),
|
|
1900
|
-
let { id:
|
|
1913
|
+
let e = new v(BX24.callBatch), r = t.filter((a) => a && a.id).map((a) => {
|
|
1914
|
+
let { id: A } = a;
|
|
1901
1915
|
return {
|
|
1902
1916
|
method: "entity.item.delete",
|
|
1903
1917
|
params: {
|
|
1904
|
-
ENTITY:
|
|
1905
|
-
ID:
|
|
1918
|
+
ENTITY: E(this, K),
|
|
1919
|
+
ID: A
|
|
1906
1920
|
}
|
|
1907
1921
|
};
|
|
1908
1922
|
});
|
|
1909
|
-
if (
|
|
1923
|
+
if (r.length === 0)
|
|
1910
1924
|
return !1;
|
|
1911
|
-
const
|
|
1912
|
-
return console.log(`Успешно удалено ${
|
|
1925
|
+
const i = await e.batch(r);
|
|
1926
|
+
return console.log(`Успешно удалено ${r.length} записей`), F(this, rt, !0), i;
|
|
1913
1927
|
} catch (e) {
|
|
1914
1928
|
return console.error("Ошибка при очистке устаревших записей:", e), !1;
|
|
1915
1929
|
}
|
|
1916
1930
|
};
|
|
1917
|
-
|
|
1918
|
-
|
|
1931
|
+
function Qt(y) {
|
|
1932
|
+
if (!y || typeof y != "string")
|
|
1933
|
+
return "";
|
|
1934
|
+
try {
|
|
1935
|
+
const t = new URL(y);
|
|
1936
|
+
t.search = "", t.hash = "";
|
|
1937
|
+
let e = t.toString();
|
|
1938
|
+
return e.endsWith("/") && t.pathname !== "/" && (e = e.slice(0, -1)), e;
|
|
1939
|
+
} catch {
|
|
1940
|
+
return y.split("?")[0].split("#")[0].replace(/\/$/, "");
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
function oe(y) {
|
|
1944
|
+
return !y || typeof y != "string" ? !1 : y.toLowerCase().includes("/marketplace/app");
|
|
1945
|
+
}
|
|
1946
|
+
function Te() {
|
|
1947
|
+
var t;
|
|
1948
|
+
if (typeof window > "u" || !((t = window.location) != null && t.href))
|
|
1949
|
+
return "";
|
|
1950
|
+
const y = Qt(window.location.href);
|
|
1951
|
+
return oe(y) ? "" : y;
|
|
1952
|
+
}
|
|
1953
|
+
function Kt(y) {
|
|
1954
|
+
if (!(y != null && y.appConst) || typeof y.appConst != "object")
|
|
1955
|
+
return "";
|
|
1956
|
+
const t = Te();
|
|
1957
|
+
return t ? (y.appConst.pathApp = t, t) : Qt(y.appConst.pathApp ?? "");
|
|
1958
|
+
}
|
|
1959
|
+
var ct, Ot, Ct, Ae, Bt, ce, Ht, he, Ut, le, Pt, ue, V, at, mt, vt, Gt, fe, gt, qt, Yt, de;
|
|
1960
|
+
class Le {
|
|
1919
1961
|
/**
|
|
1920
1962
|
* @param {Object} appConst - Константы приложения
|
|
1921
1963
|
* @param {string} appConst.appName - Название приложения
|
|
1922
1964
|
* @param {string} appConst.pathApp - Путь к приложению
|
|
1923
1965
|
*/
|
|
1924
|
-
constructor(
|
|
1966
|
+
constructor(t) {
|
|
1925
1967
|
/**
|
|
1926
1968
|
* Returns shared Batch instance for all batch operations.
|
|
1927
1969
|
* Keeps a single stateful Batch (including timeLimit) within current BxBoot lifecycle.
|
|
1928
1970
|
*
|
|
1929
1971
|
* @returns {Batch} Shared Batch instance.
|
|
1930
1972
|
*/
|
|
1931
|
-
|
|
1973
|
+
S(this, ct);
|
|
1974
|
+
S(this, Ct);
|
|
1975
|
+
/**
|
|
1976
|
+
* `this.logger === true` → `BxLogger` + лёгкий `init` (сущность хранилища, без полной выгрузки);
|
|
1977
|
+
* иначе — заглушка.
|
|
1978
|
+
* @param {boolean} runLoggerMaintenance
|
|
1979
|
+
*/
|
|
1980
|
+
S(this, Bt);
|
|
1981
|
+
/**
|
|
1982
|
+
* @returns {boolean}
|
|
1983
|
+
*/
|
|
1984
|
+
S(this, Ht);
|
|
1932
1985
|
/** Запрос данных о приложении */
|
|
1933
|
-
|
|
1986
|
+
S(this, Ut);
|
|
1934
1987
|
/** Запрос данных о текущем пользователе */
|
|
1935
|
-
|
|
1988
|
+
S(this, Pt);
|
|
1989
|
+
S(this, V);
|
|
1990
|
+
S(this, mt);
|
|
1936
1991
|
/**
|
|
1937
1992
|
* Расширяет errorList для случаев TIMEOUT и LIMIT
|
|
1938
1993
|
* Если есть ошибки TIMEOUT или LIMIT, добавляет все необработанные сущности из commandList
|
|
@@ -1942,32 +1997,32 @@ class se {
|
|
|
1942
1997
|
* @param {Array} updateList - Список обновлений для логирования (опционально)
|
|
1943
1998
|
* @returns {Object} Расширенный список ошибок
|
|
1944
1999
|
*/
|
|
1945
|
-
|
|
2000
|
+
S(this, Gt);
|
|
1946
2001
|
/**
|
|
1947
2002
|
* Нормализует входные данные в массив объектов {placement, handler?}
|
|
1948
2003
|
* @private
|
|
1949
2004
|
*/
|
|
1950
|
-
|
|
2005
|
+
S(this, gt);
|
|
1951
2006
|
/**
|
|
1952
2007
|
* Находит встройки с устаревшим handler (не содержащим текущий pathApp)
|
|
1953
2008
|
* @private
|
|
1954
2009
|
*/
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
2010
|
+
S(this, Yt);
|
|
2011
|
+
B(this, "domain", "");
|
|
2012
|
+
B(this, "isAdmin", !1);
|
|
2013
|
+
B(this, "appInfo", null);
|
|
2014
|
+
B(this, "appConst", null);
|
|
2015
|
+
B(this, "userInfo", null);
|
|
2016
|
+
B(this, "placeData", null);
|
|
2017
|
+
B(this, "placeInfo", null);
|
|
2018
|
+
B(this, "logger", !1);
|
|
2019
|
+
B(this, "timeLimit", {
|
|
1965
2020
|
limit: !1,
|
|
1966
2021
|
date: void 0,
|
|
1967
2022
|
pauseMs: void 0
|
|
1968
2023
|
});
|
|
1969
|
-
|
|
1970
|
-
this.appConst =
|
|
2024
|
+
B(this, "batchClient", null);
|
|
2025
|
+
this.appConst = t;
|
|
1971
2026
|
}
|
|
1972
2027
|
/**
|
|
1973
2028
|
* Подписывает внешний код на изменения состояния timeLimit в Batch.
|
|
@@ -1975,50 +2030,53 @@ class se {
|
|
|
1975
2030
|
* @param {(state: {limit: boolean, date?: string, pauseMs?: number}) => void} callback - Обработчик состояния лимита.
|
|
1976
2031
|
* @returns {() => void} Функция отписки.
|
|
1977
2032
|
*/
|
|
1978
|
-
subscribeTimeLimit(
|
|
1979
|
-
return
|
|
2033
|
+
subscribeTimeLimit(t) {
|
|
2034
|
+
return _(this, ct, Ot).call(this).subscribeTimeLimit(t);
|
|
1980
2035
|
}
|
|
1981
2036
|
/**
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
2037
|
+
* Единая инициализация: внутри автоматически выбирается ветка обычного приложения или
|
|
2038
|
+
* `PAGE_BACKGROUND_WORKER`. Всегда заполняет `app.info` и `user.current`, а также
|
|
2039
|
+
* возвращает флаг контекста запуска `{ isBackworker }`.
|
|
2040
|
+
* @param {{ runLoggerMaintenance?: boolean }} [options] — опциональная фоновая
|
|
2041
|
+
* очистка старых записей логгера (раньше запускалась вместе с `logger.init`, теперь явно).
|
|
2042
|
+
* `noSleep` запускается только вне `PAGE_BACKGROUND_WORKER`.
|
|
2043
|
+
* @returns {Promise<{ isBackworker: boolean }>}
|
|
1984
2044
|
* @throws {Error} Если BX24 не загружен в течение 30 секунд
|
|
1985
2045
|
*/
|
|
1986
2046
|
init() {
|
|
1987
|
-
return
|
|
1988
|
-
|
|
2047
|
+
return fetch("http://127.0.0.1:7903/ingest/d13e6df1-e437-464b-831d-29219bd3ff29", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "e57011" }, body: JSON.stringify({ sessionId: "e57011", runId: "pre-fix", hypothesisId: "H1", location: "src/utils-kit/bx-boot.js:init", message: "init invoked", data: { loggerFlag: this.logger }, timestamp: Date.now() }) }).catch(() => {
|
|
2048
|
+
}), new Promise((t, e) => {
|
|
2049
|
+
const i = setTimeout(() => {
|
|
2050
|
+
clearInterval(a);
|
|
2051
|
+
const A = new Error(
|
|
2052
|
+
"BX24 initialization timeout: BX24 object not found within 30 seconds"
|
|
2053
|
+
);
|
|
2054
|
+
console.error(A), e(A);
|
|
2055
|
+
}, 3e4);
|
|
2056
|
+
let a = setInterval(() => {
|
|
1989
2057
|
window.BX24 && BX24.init(async () => {
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
2058
|
+
var h, u, n;
|
|
2059
|
+
clearInterval(a), clearTimeout(i), this.domain = BX24.getDomain(), this.isAdmin = BX24.isAdmin(), this.placeInfo = BX24.placement.info();
|
|
2060
|
+
const A = _(this, Ht, he).call(this);
|
|
2061
|
+
if (fetch("http://127.0.0.1:7903/ingest/d13e6df1-e437-464b-831d-29219bd3ff29", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "e57011" }, body: JSON.stringify({ sessionId: "e57011", runId: "pre-fix", hypothesisId: "H1", location: "src/utils-kit/bx-boot.js:init:after-placement", message: "placement detected", data: { placement: (h = this.placeInfo) == null ? void 0 : h.placement, placementId: (n = (u = this.placeInfo) == null ? void 0 : u.options) == null ? void 0 : n.ID, isBackworker: A }, timestamp: Date.now() }) }).catch(() => {
|
|
2062
|
+
}), console.info(
|
|
2063
|
+
A ? "init BX24 (background worker)" : "init BX24"
|
|
2064
|
+
), this.appInfo = await _(this, Ut, le).call(this), this.userInfo = await _(this, Pt, ue).call(this), Kt(this), !A) {
|
|
2065
|
+
await _(this, Bt, ce).call(this, !0);
|
|
2066
|
+
const f = new se();
|
|
2067
|
+
try {
|
|
2068
|
+
f.noSleep();
|
|
2069
|
+
} catch (d) {
|
|
2070
|
+
console.warn(
|
|
2071
|
+
"Failed to initialize noSleep:",
|
|
2072
|
+
d
|
|
2073
|
+
);
|
|
1996
2074
|
}
|
|
1997
|
-
};
|
|
1998
|
-
const [h, A] = await Promise.all([
|
|
1999
|
-
E(this, It, vt).call(this),
|
|
2000
|
-
E(this, Mt, Qt).call(this)
|
|
2001
|
-
]);
|
|
2002
|
-
this.appInfo = h, this.userInfo = A;
|
|
2003
|
-
let l = new Ft();
|
|
2004
|
-
try {
|
|
2005
|
-
l.noSleep();
|
|
2006
|
-
} catch (i) {
|
|
2007
|
-
console.warn(
|
|
2008
|
-
"Failed to initialize noSleep:",
|
|
2009
|
-
i
|
|
2010
|
-
);
|
|
2011
2075
|
}
|
|
2012
|
-
|
|
2076
|
+
fetch("http://127.0.0.1:7903/ingest/d13e6df1-e437-464b-831d-29219bd3ff29", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "e57011" }, body: JSON.stringify({ sessionId: "e57011", runId: "pre-fix", hypothesisId: "H3", location: "src/utils-kit/bx-boot.js:init:resolve", message: "init resolved", data: { isBackworker: A, hasAppInfo: !!this.appInfo, hasUserInfo: !!this.userInfo, loggerType: typeof this.logger }, timestamp: Date.now() }) }).catch(() => {
|
|
2077
|
+
}), t({ isBackworker: A });
|
|
2013
2078
|
});
|
|
2014
2079
|
}, 100);
|
|
2015
|
-
const o = setTimeout(() => {
|
|
2016
|
-
clearInterval(n);
|
|
2017
|
-
const h = new Error(
|
|
2018
|
-
"BX24 initialization timeout: BX24 object not found within 30 seconds"
|
|
2019
|
-
);
|
|
2020
|
-
console.error(h), e(h);
|
|
2021
|
-
}, 3e4);
|
|
2022
2080
|
});
|
|
2023
2081
|
}
|
|
2024
2082
|
/**
|
|
@@ -2027,23 +2085,23 @@ class se {
|
|
|
2027
2085
|
* @param {any} value - Значение для установки (если не указано, метод вернет текущее значение)
|
|
2028
2086
|
* @returns {any}
|
|
2029
2087
|
*/
|
|
2030
|
-
userOption(
|
|
2088
|
+
userOption(t, e) {
|
|
2031
2089
|
if (typeof BX24 > "u" || !BX24.userOption) {
|
|
2032
2090
|
console.warn(
|
|
2033
2091
|
"BX24.userOption is not available. Make sure BX24 is initialized."
|
|
2034
2092
|
);
|
|
2035
2093
|
return;
|
|
2036
2094
|
}
|
|
2037
|
-
return e !== void 0 ? BX24.userOption.set(
|
|
2095
|
+
return e !== void 0 ? BX24.userOption.set(t, e) : BX24.userOption.get(t);
|
|
2038
2096
|
}
|
|
2039
|
-
appOption(
|
|
2097
|
+
appOption(t, e) {
|
|
2040
2098
|
if (typeof BX24 > "u" || !BX24.appOption) {
|
|
2041
2099
|
console.warn(
|
|
2042
2100
|
"BX24.appOption is not available. Make sure BX24 is initialized."
|
|
2043
2101
|
);
|
|
2044
2102
|
return;
|
|
2045
2103
|
}
|
|
2046
|
-
return e !== void 0 ? BX24.appOption.set(
|
|
2104
|
+
return e !== void 0 ? BX24.appOption.set(t, e) : BX24.appOption.get(t);
|
|
2047
2105
|
}
|
|
2048
2106
|
/**
|
|
2049
2107
|
* @param {{
|
|
@@ -2063,41 +2121,25 @@ class se {
|
|
|
2063
2121
|
* }[]
|
|
2064
2122
|
* }[]
|
|
2065
2123
|
*/
|
|
2066
|
-
async call({ method:
|
|
2067
|
-
let
|
|
2068
|
-
if (
|
|
2124
|
+
async call({ method: t, params: e, updateList: r }) {
|
|
2125
|
+
let i;
|
|
2126
|
+
if (r && (i = this.logger.start({
|
|
2069
2127
|
type: "call",
|
|
2070
|
-
data: { method:
|
|
2128
|
+
data: { method: t, params: e, updateList: r }
|
|
2071
2129
|
})), e || (e = {}), typeof BX24 > "u" || !BX24.callMethod) {
|
|
2072
|
-
const
|
|
2073
|
-
throw console.error(
|
|
2074
|
-
}
|
|
2075
|
-
const h = await E(this, rt, ct).call(this).call({ method: r, params: e });
|
|
2076
|
-
if (!h.success) {
|
|
2077
|
-
if (console.error(h.error), n)
|
|
2078
|
-
try {
|
|
2079
|
-
await this.logger.stop({
|
|
2080
|
-
answer: h.answer,
|
|
2081
|
-
key: n,
|
|
2082
|
-
status: "fail",
|
|
2083
|
-
errorList: { 0: h.error || "Unknown call error" }
|
|
2084
|
-
});
|
|
2085
|
-
} catch (A) {
|
|
2086
|
-
console.error("Logger error:", A);
|
|
2087
|
-
}
|
|
2088
|
-
return !1;
|
|
2130
|
+
const h = new Error("BX24 is not initialized");
|
|
2131
|
+
throw console.error(h), h;
|
|
2089
2132
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
return h.data;
|
|
2133
|
+
const A = await _(this, ct, Ot).call(this).call({ method: t, params: e });
|
|
2134
|
+
return A.success ? (await _(this, V, at).call(this, i, {
|
|
2135
|
+
answer: A.answer,
|
|
2136
|
+
status: "success"
|
|
2137
|
+
}), A.data) : (fetch("http://127.0.0.1:7903/ingest/d13e6df1-e437-464b-831d-29219bd3ff29", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "e57011" }, body: JSON.stringify({ sessionId: "e57011", runId: "pre-fix", hypothesisId: "H4", location: "src/utils-kit/bx-boot.js:call", message: "call failed", data: { method: t, error: A.error, hasUpdateList: !!r, loggerType: typeof this.logger }, timestamp: Date.now() }) }).catch(() => {
|
|
2138
|
+
}), console.error(A.error), await _(this, V, at).call(this, i, {
|
|
2139
|
+
answer: A.answer,
|
|
2140
|
+
status: "fail",
|
|
2141
|
+
errorList: { 0: A.error || "Unknown call error" }
|
|
2142
|
+
}), !1);
|
|
2101
2143
|
}
|
|
2102
2144
|
/**
|
|
2103
2145
|
* @param commandList - объект/массив команд
|
|
@@ -2118,58 +2160,19 @@ class se {
|
|
|
2118
2160
|
* }[]
|
|
2119
2161
|
* }}
|
|
2120
2162
|
*/
|
|
2121
|
-
async batch(
|
|
2163
|
+
async batch(t, e, { errorCall: r, updateList: i, batchOptions: a } = {}) {
|
|
2122
2164
|
if (typeof BX24 > "u" || !BX24.callBatch) {
|
|
2123
|
-
const
|
|
2124
|
-
return console.error(
|
|
2125
|
-
}
|
|
2126
|
-
const h = E(this, rt, ct).call(this);
|
|
2127
|
-
let A;
|
|
2128
|
-
n && (A = this.logger.start({
|
|
2129
|
-
type: "batch",
|
|
2130
|
-
data: { commandList: r, updateList: n }
|
|
2131
|
-
}));
|
|
2132
|
-
try {
|
|
2133
|
-
let l = await h.batch(
|
|
2134
|
-
r,
|
|
2135
|
-
e,
|
|
2136
|
-
o
|
|
2137
|
-
);
|
|
2138
|
-
const i = E(this, ut, Ut).call(this, h, l, r, n);
|
|
2139
|
-
if (Object.keys(i).length) {
|
|
2140
|
-
if (s && s(i), A)
|
|
2141
|
-
try {
|
|
2142
|
-
await this.logger.stop({
|
|
2143
|
-
key: A,
|
|
2144
|
-
status: "fail",
|
|
2145
|
-
errorList: i
|
|
2146
|
-
});
|
|
2147
|
-
} catch (u) {
|
|
2148
|
-
console.error("Logger error:", u);
|
|
2149
|
-
}
|
|
2150
|
-
} else if (A)
|
|
2151
|
-
try {
|
|
2152
|
-
await this.logger.stop({
|
|
2153
|
-
key: A,
|
|
2154
|
-
status: "success"
|
|
2155
|
-
});
|
|
2156
|
-
} catch (u) {
|
|
2157
|
-
console.error("Logger error:", u);
|
|
2158
|
-
}
|
|
2159
|
-
return l;
|
|
2160
|
-
} catch (l) {
|
|
2161
|
-
if (A)
|
|
2162
|
-
try {
|
|
2163
|
-
await this.logger.stop({
|
|
2164
|
-
key: A,
|
|
2165
|
-
status: "fail-runtime",
|
|
2166
|
-
errorList: { 0: l == null ? void 0 : l.toString() }
|
|
2167
|
-
});
|
|
2168
|
-
} catch (i) {
|
|
2169
|
-
console.error("Logger error:", i);
|
|
2170
|
-
}
|
|
2171
|
-
return console.error(l), !1;
|
|
2165
|
+
const A = new Error("BX24 is not initialized");
|
|
2166
|
+
return console.error(A), !1;
|
|
2172
2167
|
}
|
|
2168
|
+
return _(this, mt, vt).call(this, {
|
|
2169
|
+
mode: "batch",
|
|
2170
|
+
commandList: t,
|
|
2171
|
+
progressCall: e,
|
|
2172
|
+
errorCall: r,
|
|
2173
|
+
updateList: i,
|
|
2174
|
+
batchOptions: a
|
|
2175
|
+
});
|
|
2173
2176
|
}
|
|
2174
2177
|
/**
|
|
2175
2178
|
* Получить количество элементов для списочных методов
|
|
@@ -2193,163 +2196,124 @@ class se {
|
|
|
2193
2196
|
* }}
|
|
2194
2197
|
* @returns {Promise<Object|false>}
|
|
2195
2198
|
*/
|
|
2196
|
-
async batchTotalCount(
|
|
2199
|
+
async batchTotalCount(t, e, { errorCall: r, updateList: i } = {}) {
|
|
2197
2200
|
if (typeof BX24 > "u" || !BX24.callBatch) {
|
|
2198
|
-
const
|
|
2199
|
-
return console.error(
|
|
2200
|
-
}
|
|
2201
|
-
const o = E(this, rt, ct).call(this);
|
|
2202
|
-
let h;
|
|
2203
|
-
n && (h = this.logger.start({
|
|
2204
|
-
type: "batch-total-count",
|
|
2205
|
-
data: { commandList: r }
|
|
2206
|
-
}));
|
|
2207
|
-
try {
|
|
2208
|
-
let A = await o.batchTotalCount(
|
|
2209
|
-
r,
|
|
2210
|
-
e
|
|
2211
|
-
);
|
|
2212
|
-
const l = E(this, ut, Ut).call(this, o, A, r, n);
|
|
2213
|
-
if (Object.keys(l).length) {
|
|
2214
|
-
if (s && s(l), h)
|
|
2215
|
-
try {
|
|
2216
|
-
await this.logger.stop({
|
|
2217
|
-
key: h,
|
|
2218
|
-
status: "fail",
|
|
2219
|
-
errorList: l
|
|
2220
|
-
});
|
|
2221
|
-
} catch (i) {
|
|
2222
|
-
console.error("Logger error:", i);
|
|
2223
|
-
}
|
|
2224
|
-
} else if (h)
|
|
2225
|
-
try {
|
|
2226
|
-
await this.logger.stop({
|
|
2227
|
-
key: h,
|
|
2228
|
-
status: "success"
|
|
2229
|
-
});
|
|
2230
|
-
} catch (i) {
|
|
2231
|
-
console.error("Logger error:", i);
|
|
2232
|
-
}
|
|
2233
|
-
return A;
|
|
2234
|
-
} catch (A) {
|
|
2235
|
-
if (h)
|
|
2236
|
-
try {
|
|
2237
|
-
await this.logger.stop({
|
|
2238
|
-
key: h,
|
|
2239
|
-
status: "fail-runtime",
|
|
2240
|
-
errorList: { 0: A == null ? void 0 : A.toString() }
|
|
2241
|
-
});
|
|
2242
|
-
} catch (l) {
|
|
2243
|
-
console.error("Logger error:", l);
|
|
2244
|
-
}
|
|
2245
|
-
return console.error(A), !1;
|
|
2201
|
+
const a = new Error("BX24 is not initialized");
|
|
2202
|
+
return console.error(a), !1;
|
|
2246
2203
|
}
|
|
2204
|
+
return _(this, mt, vt).call(this, {
|
|
2205
|
+
mode: "batch-total-count",
|
|
2206
|
+
commandList: t,
|
|
2207
|
+
progressCall: e,
|
|
2208
|
+
errorCall: r,
|
|
2209
|
+
updateList: i
|
|
2210
|
+
});
|
|
2247
2211
|
}
|
|
2248
2212
|
/** Запрос данных о местах встройки приложения */
|
|
2249
2213
|
async getPlacement() {
|
|
2250
|
-
|
|
2214
|
+
const t = await this.call({ method: "placement.get" });
|
|
2215
|
+
return this.placeData || (this.placeData = t), t;
|
|
2251
2216
|
}
|
|
2252
2217
|
/**
|
|
2253
2218
|
* Встройка приложения в указанные места
|
|
2254
2219
|
* @param {string|string[]|Object|Object[]} place - Место или массив мест для встройки
|
|
2255
2220
|
*/
|
|
2256
|
-
async placementBind(
|
|
2257
|
-
var
|
|
2221
|
+
async placementBind(t) {
|
|
2222
|
+
var c;
|
|
2258
2223
|
if (!this.isAdmin || (this.placeData = await this.getPlacement(), !this.placeData))
|
|
2259
2224
|
return;
|
|
2260
|
-
const { appName: e, pathApp:
|
|
2261
|
-
let
|
|
2262
|
-
|
|
2263
|
-
(
|
|
2225
|
+
const { appName: e, pathApp: r } = this.appConst;
|
|
2226
|
+
let i = _(this, gt, qt).call(this, t);
|
|
2227
|
+
i = i.filter(
|
|
2228
|
+
(l) => l.placement !== "PAGE_BACKGROUND_WORKER" && l.placement !== "PAGE_BACKGROUND_WORKER_ALL"
|
|
2264
2229
|
);
|
|
2265
|
-
const
|
|
2266
|
-
for (const
|
|
2267
|
-
|
|
2268
|
-
if (
|
|
2230
|
+
const a = _(this, Yt, de).call(this, r), A = new Set(i.map((l) => l.placement));
|
|
2231
|
+
for (const l of a)
|
|
2232
|
+
A.has(l.placement) || i.push({ placement: l.placement });
|
|
2233
|
+
if (i.length === 0)
|
|
2269
2234
|
return;
|
|
2270
|
-
let
|
|
2271
|
-
this.domain === "szdl.bitrix24.ru" && ((
|
|
2272
|
-
const
|
|
2273
|
-
for (
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2235
|
+
let h = e;
|
|
2236
|
+
this.domain === "szdl.bitrix24.ru" && ((c = this.appInfo) != null && c.ID) && (h = `${e}: #${this.appInfo.ID}`);
|
|
2237
|
+
const u = h.replace(" CRM", ""), n = {}, f = [], d = /* @__PURE__ */ new Map();
|
|
2238
|
+
for (const l of this.placeData)
|
|
2239
|
+
d.has(l.placement) || d.set(l.placement, []), d.get(l.placement).push(l);
|
|
2240
|
+
for (let l = 0; l < i.length; l++) {
|
|
2241
|
+
const O = i[l].placement, T = d.get(O) || [];
|
|
2242
|
+
if (T.some(
|
|
2243
|
+
(N) => N.handler === r
|
|
2277
2244
|
))
|
|
2278
2245
|
continue;
|
|
2279
|
-
const
|
|
2280
|
-
(
|
|
2246
|
+
const I = T.filter(
|
|
2247
|
+
(N) => N.handler !== r
|
|
2281
2248
|
);
|
|
2282
|
-
for (const
|
|
2283
|
-
|
|
2284
|
-
placement:
|
|
2285
|
-
handler:
|
|
2249
|
+
for (const N of I)
|
|
2250
|
+
f.push({
|
|
2251
|
+
placement: O,
|
|
2252
|
+
handler: N.handler
|
|
2286
2253
|
});
|
|
2287
|
-
|
|
2254
|
+
n[`bind_${l}`] = {
|
|
2288
2255
|
method: "placement.bind",
|
|
2289
2256
|
params: {
|
|
2290
|
-
PLACEMENT:
|
|
2291
|
-
HANDLER:
|
|
2257
|
+
PLACEMENT: O,
|
|
2258
|
+
HANDLER: r,
|
|
2292
2259
|
LANG_ALL: {
|
|
2293
2260
|
ru: {
|
|
2294
|
-
TITLE:
|
|
2261
|
+
TITLE: O === "USER_PROFILE_TOOLBAR" ? u : h
|
|
2295
2262
|
}
|
|
2296
2263
|
},
|
|
2297
2264
|
OPTIONS: {
|
|
2298
|
-
errorHandlerUrl:
|
|
2265
|
+
errorHandlerUrl: r
|
|
2299
2266
|
}
|
|
2300
2267
|
}
|
|
2301
2268
|
};
|
|
2302
2269
|
}
|
|
2303
|
-
|
|
2304
|
-
console.log("Приложение успешно встроено в",
|
|
2270
|
+
f.length > 0 && await this.placementUnBind(f), Object.keys(n).length > 0 && (await this.batch(n), this.placeData = await this.getPlacement(), Object.values(n).forEach((l) => {
|
|
2271
|
+
console.log("Приложение успешно встроено в", l.params.PLACEMENT);
|
|
2305
2272
|
}));
|
|
2306
2273
|
}
|
|
2307
2274
|
/**
|
|
2308
2275
|
* Отвязка встройки из указанных мест
|
|
2309
2276
|
* @param {string|string[]|Object|Object[]} place - Место или массив мест для отвязки
|
|
2310
2277
|
*/
|
|
2311
|
-
async placementUnBind(
|
|
2312
|
-
let e =
|
|
2278
|
+
async placementUnBind(t) {
|
|
2279
|
+
let e = _(this, gt, qt).call(this, t);
|
|
2313
2280
|
if (e = e.filter(
|
|
2314
|
-
(
|
|
2281
|
+
(i) => i.placement !== "PAGE_BACKGROUND_WORKER" && i.placement !== "PAGE_BACKGROUND_WORKER_ALL"
|
|
2315
2282
|
), e.length === 0)
|
|
2316
2283
|
return;
|
|
2317
|
-
const
|
|
2318
|
-
for (let
|
|
2319
|
-
const
|
|
2320
|
-
PLACEMENT: e[
|
|
2284
|
+
const r = {};
|
|
2285
|
+
for (let i = 0; i < e.length; i++) {
|
|
2286
|
+
const a = {
|
|
2287
|
+
PLACEMENT: e[i].placement
|
|
2321
2288
|
};
|
|
2322
|
-
e[
|
|
2289
|
+
e[i].handler && (a.HANDLER = e[i].handler), r[`unbind_${i}`] = {
|
|
2323
2290
|
method: "placement.unbind",
|
|
2324
|
-
params:
|
|
2291
|
+
params: a
|
|
2325
2292
|
};
|
|
2326
2293
|
}
|
|
2327
|
-
await this.batch(
|
|
2328
|
-
console.log("Встройка отвязана",
|
|
2294
|
+
await this.batch(r), e.forEach((i) => {
|
|
2295
|
+
console.log("Встройка отвязана", i.placement);
|
|
2329
2296
|
});
|
|
2330
2297
|
}
|
|
2331
2298
|
/** Чат-бот */
|
|
2332
2299
|
/* получение списка ботов */
|
|
2333
|
-
getBotList() {
|
|
2334
|
-
|
|
2300
|
+
async getBotList() {
|
|
2301
|
+
const t = await this.call({
|
|
2335
2302
|
method: "imbot.bot.list",
|
|
2336
2303
|
params: {}
|
|
2337
|
-
}).
|
|
2338
|
-
|
|
2339
|
-
return console.log("chat-bot list:", e), e;
|
|
2340
|
-
});
|
|
2304
|
+
}), e = Object.values(t);
|
|
2305
|
+
return console.log("chat-bot list:", e), e;
|
|
2341
2306
|
}
|
|
2342
2307
|
/* регистрация бота */
|
|
2343
|
-
regBot({ code:
|
|
2344
|
-
const { appName:
|
|
2345
|
-
return this.call({
|
|
2308
|
+
async regBot({ code: t, type: e, name: r }) {
|
|
2309
|
+
const { appName: i, pathApp: a, chatBotLogo: A } = this.appConst, h = this.appInfo.ID, u = await this.call({
|
|
2346
2310
|
method: "imbot.register",
|
|
2347
2311
|
params: {
|
|
2348
|
-
CODE:
|
|
2312
|
+
CODE: t ?? this.appInfo.CODE,
|
|
2349
2313
|
// Строковой идентификатор бота, уникальный в рамках вашего приложения (обяз.)
|
|
2350
2314
|
TYPE: e ?? "O",
|
|
2351
2315
|
// Тип бота, B - чат-бот, ответы поступают сразу, H - человек, ответы поступают с задержкой от 2-х до 10 секунд, O - чат-бот для Открытых линий, S - чат-бот с повышенными привилегиями (supervisor)
|
|
2352
|
-
EVENT_HANDLER:
|
|
2316
|
+
EVENT_HANDLER: a,
|
|
2353
2317
|
// Ссылка на обработчик событий, поступивших от сервера - см. Обработчики событий ниже (обяз).
|
|
2354
2318
|
OPENLINE: "Y",
|
|
2355
2319
|
// Включение режима поддержки Открытых линий, можно не указывать, если TYPE = 'O'
|
|
@@ -2357,7 +2321,7 @@ class se {
|
|
|
2357
2321
|
// строковый идентификатор чат-бота, используется только в режиме Вебхуков
|
|
2358
2322
|
PROPERTIES: {
|
|
2359
2323
|
// Личные данные чат-бота (обяз.)
|
|
2360
|
-
NAME: `${
|
|
2324
|
+
NAME: `${r ?? i} - бот #${h}`,
|
|
2361
2325
|
// Имя чат-бота (обязательное одно из полей NAME или LAST_NAME)
|
|
2362
2326
|
LAST_NAME: "",
|
|
2363
2327
|
// Фамилия чат-бота (обязательное одно из полей NAME или LAST_NAME)
|
|
@@ -2365,7 +2329,7 @@ class se {
|
|
|
2365
2329
|
// Цвет чат-бота для мобильного приложения RED, GREEN, MINT, LIGHT_BLUE, DARK_BLUE, PURPLE, AQUA, PINK, LIME, BROWN, AZURE, KHAKI, SAND, MARENGO, GRAY, GRAPHITE
|
|
2366
2330
|
EMAIL: "",
|
|
2367
2331
|
// E-mail для связи. НЕЛЬЗЯ использовать e-mail, дублирующий e-mail реальных пользователей
|
|
2368
|
-
PERSONAL_BIRTHDAY:
|
|
2332
|
+
PERSONAL_BIRTHDAY: yt().format("%Y-%m-%d"),
|
|
2369
2333
|
// День рождения в формате YYYY-mm-dd
|
|
2370
2334
|
WORK_POSITION: "Почтальон",
|
|
2371
2335
|
// Занимаемая должность, используется как описание чат-бота
|
|
@@ -2373,100 +2337,206 @@ class se {
|
|
|
2373
2337
|
// Ссылка на сайт
|
|
2374
2338
|
PERSONAL_GENDER: "M",
|
|
2375
2339
|
// Пол чат-бота, допустимые значения M - мужской, F - женский, пусто, если не требуется указывать
|
|
2376
|
-
PERSONAL_PHOTO:
|
|
2340
|
+
PERSONAL_PHOTO: A ?? ""
|
|
2377
2341
|
// Аватар чат-бота - base64
|
|
2378
2342
|
}
|
|
2379
2343
|
}
|
|
2380
|
-
})
|
|
2344
|
+
});
|
|
2345
|
+
return console.log("Чат-бот добавлен", u), u;
|
|
2381
2346
|
}
|
|
2382
2347
|
/* Убрать регистрацию бота */
|
|
2383
|
-
unRegBot(
|
|
2384
|
-
|
|
2348
|
+
async unRegBot(t) {
|
|
2349
|
+
const e = await this.call({
|
|
2385
2350
|
method: "imbot.unregister",
|
|
2386
2351
|
params: {
|
|
2387
|
-
BOT_ID:
|
|
2352
|
+
BOT_ID: t
|
|
2388
2353
|
}
|
|
2389
|
-
})
|
|
2354
|
+
});
|
|
2355
|
+
return console.log("чат-бот удален", e), e;
|
|
2390
2356
|
}
|
|
2391
2357
|
/* Получение данных логера */
|
|
2392
|
-
getLoggerList(
|
|
2393
|
-
return this.logger.getEntityList(
|
|
2358
|
+
getLoggerList(t) {
|
|
2359
|
+
return this.logger.getEntityList(t);
|
|
2394
2360
|
}
|
|
2395
2361
|
}
|
|
2396
|
-
|
|
2362
|
+
ct = new WeakSet(), Ot = function() {
|
|
2397
2363
|
return this.batchClient || (this.batchClient = new v({
|
|
2398
2364
|
callBatch: BX24.callBatch,
|
|
2399
2365
|
callMethod: BX24.callMethod
|
|
2400
2366
|
}), this.timeLimit = this.batchClient.timeLimit), this.batchClient;
|
|
2401
|
-
},
|
|
2367
|
+
}, Ct = new WeakSet(), Ae = function() {
|
|
2368
|
+
return {
|
|
2369
|
+
start: () => {
|
|
2370
|
+
},
|
|
2371
|
+
stop: () => {
|
|
2372
|
+
},
|
|
2373
|
+
getEntityList: () => {
|
|
2374
|
+
}
|
|
2375
|
+
};
|
|
2376
|
+
}, Bt = new WeakSet(), ce = async function(t) {
|
|
2377
|
+
fetch("http://127.0.0.1:7903/ingest/d13e6df1-e437-464b-831d-29219bd3ff29", { method: "POST", headers: { "Content-Type": "application/json", "X-Debug-Session-Id": "e57011" }, body: JSON.stringify({ sessionId: "e57011", runId: "pre-fix", hypothesisId: "H2", location: "src/utils-kit/bx-boot.js:#initLoggerOrStub", message: "logger init branch selected", data: { loggerFlag: this.logger, runLoggerMaintenance: t }, timestamp: Date.now() }) }).catch(() => {
|
|
2378
|
+
}), this.logger ? (this.logger = new _e(), await this.logger.init(), t && typeof this.logger.runStorageMaintenance == "function" && this.logger.runStorageMaintenance()) : this.logger = _(this, Ct, Ae).call(this);
|
|
2379
|
+
}, Ht = new WeakSet(), he = function() {
|
|
2380
|
+
var r, i, a;
|
|
2381
|
+
const t = (r = this.placeInfo) == null ? void 0 : r.placement, e = (a = (i = this.placeInfo) == null ? void 0 : i.options) == null ? void 0 : a.ID;
|
|
2382
|
+
return t === "PAGE_BACKGROUND_WORKER" || e === "PAGE_BACKGROUND_WORKER";
|
|
2383
|
+
}, Ut = new WeakSet(), le = function() {
|
|
2402
2384
|
return this.call({ method: "app.info" });
|
|
2403
|
-
},
|
|
2385
|
+
}, Pt = new WeakSet(), ue = function() {
|
|
2404
2386
|
return this.call({ method: "user.current" });
|
|
2405
|
-
},
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2387
|
+
}, V = new WeakSet(), at = async function(t, e) {
|
|
2388
|
+
if (t)
|
|
2389
|
+
try {
|
|
2390
|
+
await this.logger.stop({
|
|
2391
|
+
key: t,
|
|
2392
|
+
...e
|
|
2393
|
+
});
|
|
2394
|
+
} catch (r) {
|
|
2395
|
+
console.error("Logger error:", r);
|
|
2396
|
+
}
|
|
2397
|
+
}, mt = new WeakSet(), vt = async function({
|
|
2398
|
+
mode: t,
|
|
2399
|
+
commandList: e,
|
|
2400
|
+
progressCall: r,
|
|
2401
|
+
errorCall: i,
|
|
2402
|
+
updateList: a,
|
|
2403
|
+
batchOptions: A
|
|
2404
|
+
}) {
|
|
2405
|
+
const h = _(this, ct, Ot).call(this), u = a ? this.logger.start({
|
|
2406
|
+
type: t,
|
|
2407
|
+
data: t === "batch" ? { commandList: e, updateList: a } : { commandList: e }
|
|
2408
|
+
}) : void 0;
|
|
2409
|
+
try {
|
|
2410
|
+
const n = t === "batch" ? await h.batch(e, r, A) : await h.batchTotalCount(e, r), f = _(this, Gt, fe).call(this, h, n, e, a);
|
|
2411
|
+
return Object.keys(f).length ? (i && i(f), await _(this, V, at).call(this, u, {
|
|
2412
|
+
status: "fail",
|
|
2413
|
+
errorList: f
|
|
2414
|
+
})) : await _(this, V, at).call(this, u, { status: "success" }), n;
|
|
2415
|
+
} catch (n) {
|
|
2416
|
+
return await _(this, V, at).call(this, u, {
|
|
2417
|
+
status: "fail-runtime",
|
|
2418
|
+
errorList: { 0: n == null ? void 0 : n.toString() }
|
|
2419
|
+
}), console.error(n), !1;
|
|
2420
|
+
}
|
|
2421
|
+
}, Gt = new WeakSet(), fe = function(t, e, r, i) {
|
|
2422
|
+
let a = { ...t.errors };
|
|
2423
|
+
if (Object.values(t.errors).some(
|
|
2424
|
+
(h) => {
|
|
2425
|
+
if (typeof h != "string")
|
|
2410
2426
|
return !1;
|
|
2411
|
-
const
|
|
2412
|
-
return
|
|
2427
|
+
const u = h.toUpperCase();
|
|
2428
|
+
return u === "TIMEOUT" || u === "OPERATION_TIME_LIMIT" || u.includes("TIMEOUT") || u.includes("OPERATION_TIME_LIMIT");
|
|
2413
2429
|
}
|
|
2414
|
-
) &&
|
|
2415
|
-
const
|
|
2430
|
+
) && i) {
|
|
2431
|
+
const h = e ? Object.keys(e).filter((d) => d !== "errorsList") : [], u = new Set(Object.keys(t.errors || {})), n = /* @__PURE__ */ new Set();
|
|
2416
2432
|
if (e) {
|
|
2417
|
-
for (const
|
|
2418
|
-
if (!
|
|
2419
|
-
const c = e[
|
|
2420
|
-
c != null &&
|
|
2433
|
+
for (const d of h)
|
|
2434
|
+
if (!u.has(d)) {
|
|
2435
|
+
const c = e[d];
|
|
2436
|
+
c != null && n.add(d);
|
|
2421
2437
|
}
|
|
2422
2438
|
}
|
|
2423
|
-
const
|
|
2424
|
-
(
|
|
2425
|
-
if (typeof
|
|
2439
|
+
const f = Object.values(t.errors).find(
|
|
2440
|
+
(d) => {
|
|
2441
|
+
if (typeof d != "string")
|
|
2426
2442
|
return !1;
|
|
2427
|
-
const c =
|
|
2443
|
+
const c = d.toUpperCase();
|
|
2428
2444
|
return c === "TIMEOUT" || c === "OPERATION_TIME_LIMIT" || c.includes("TIMEOUT") || c.includes("OPERATION_TIME_LIMIT");
|
|
2429
2445
|
}
|
|
2430
2446
|
);
|
|
2431
|
-
for (const
|
|
2432
|
-
!
|
|
2447
|
+
for (const d of Object.keys(r))
|
|
2448
|
+
!n.has(d) && !t.errors[d] && (a[d] = f || "TIMEOUT или OPERATION_TIME_LIMIT: запрос не был обработан");
|
|
2433
2449
|
}
|
|
2434
|
-
return
|
|
2435
|
-
},
|
|
2436
|
-
if (!
|
|
2450
|
+
return a;
|
|
2451
|
+
}, gt = new WeakSet(), qt = function(t) {
|
|
2452
|
+
if (!t)
|
|
2437
2453
|
return [];
|
|
2438
2454
|
let e = [];
|
|
2439
|
-
return Array.isArray(
|
|
2440
|
-
(
|
|
2441
|
-
) : typeof
|
|
2442
|
-
},
|
|
2443
|
-
return this.placeData ? this.placeData.filter((e) => !(e.placement === "PAGE_BACKGROUND_WORKER" || !e.handler || e.handler.includes(
|
|
2455
|
+
return Array.isArray(t) ? e = t.map(
|
|
2456
|
+
(r) => typeof r == "string" ? { placement: r } : r
|
|
2457
|
+
) : typeof t == "string" ? e = [{ placement: t }] : e = [t], e;
|
|
2458
|
+
}, Yt = new WeakSet(), de = function(t) {
|
|
2459
|
+
return this.placeData ? this.placeData.filter((e) => !(e.placement === "PAGE_BACKGROUND_WORKER" || !e.handler || e.handler.includes(t))) : [];
|
|
2444
2460
|
};
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2461
|
+
const me = "szdl-utils-kit|";
|
|
2462
|
+
function Ee() {
|
|
2463
|
+
if (typeof sessionStorage > "u")
|
|
2464
|
+
return `ephemeral-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
2465
|
+
let y = sessionStorage.getItem("szdl-cross-tab-instance-id");
|
|
2466
|
+
return y || (y = `${Date.now()}-${Math.random().toString(16).slice(2)}`, sessionStorage.setItem("szdl-cross-tab-instance-id", y)), y;
|
|
2467
|
+
}
|
|
2468
|
+
function be() {
|
|
2469
|
+
return typeof navigator < "u" && typeof navigator.locks < "u" && typeof navigator.locks.request == "function";
|
|
2470
|
+
}
|
|
2471
|
+
const Ft = /* @__PURE__ */ new Map();
|
|
2472
|
+
function Ie(y = "default") {
|
|
2473
|
+
if (typeof BroadcastChannel > "u")
|
|
2474
|
+
return null;
|
|
2475
|
+
const t = `${me}bc:${y}`;
|
|
2476
|
+
return Ft.has(t) || Ft.set(t, new BroadcastChannel(t)), Ft.get(t);
|
|
2477
|
+
}
|
|
2478
|
+
function Zt(y, t) {
|
|
2479
|
+
const e = Ie(y);
|
|
2480
|
+
if (e)
|
|
2481
|
+
try {
|
|
2482
|
+
const r = t && typeof t == "object" && !Array.isArray(t) ? t : { data: t };
|
|
2483
|
+
e.postMessage({
|
|
2484
|
+
...r,
|
|
2485
|
+
tabId: Ee(),
|
|
2486
|
+
ts: Date.now()
|
|
2487
|
+
});
|
|
2488
|
+
} catch {
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
async function Se(y, t, e = {}) {
|
|
2492
|
+
const { ifAvailable: r = !1 } = e, i = typeof y == "string" && y.length > 0 ? y : "default", a = `${me}${i}`;
|
|
2493
|
+
return be() ? navigator.locks.request(
|
|
2494
|
+
a,
|
|
2495
|
+
{ mode: "exclusive", ifAvailable: !!r },
|
|
2496
|
+
async (A) => {
|
|
2497
|
+
if (r && A == null)
|
|
2498
|
+
return { skipped: !0, coordination: "locks" };
|
|
2499
|
+
Zt(i, { type: "lock-acquired", resource: i });
|
|
2500
|
+
try {
|
|
2501
|
+
return { skipped: !1, result: await t(), coordination: "locks" };
|
|
2502
|
+
} finally {
|
|
2503
|
+
Zt(i, { type: "lock-released", resource: i });
|
|
2504
|
+
}
|
|
2505
|
+
}
|
|
2506
|
+
) : { skipped: !1, result: await t(), coordination: "none" };
|
|
2507
|
+
}
|
|
2508
|
+
var pt, zt;
|
|
2509
|
+
class Me {
|
|
2510
|
+
constructor(t) {
|
|
2511
|
+
/**
|
|
2512
|
+
* Канонический base URL для placement (без завершающего `/`).
|
|
2513
|
+
* Пустая строка — не биндить (некорректный или marketplace URL).
|
|
2514
|
+
*/
|
|
2515
|
+
S(this, pt);
|
|
2516
|
+
B(this, "entityName", "tabs");
|
|
2517
|
+
B(this, "maxTabs", 20);
|
|
2518
|
+
B(this, "tabList", []);
|
|
2519
|
+
B(this, "id", 0);
|
|
2520
|
+
B(this, "hasStarted", !1);
|
|
2521
|
+
B(this, "heartbeat");
|
|
2522
|
+
B(this, "runHeartbeat");
|
|
2523
|
+
/** Вкладка считается «мёртвой», если нет обновления lastActive дольше этого (см. refreshTabs). */
|
|
2524
|
+
B(this, "activeMaxPause", 10 * 1e3);
|
|
2525
|
+
B(this, "quickCleanupThreshold", 2 * 60 * 1e3);
|
|
2457
2526
|
// агрессивная очистка при переполнении
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2527
|
+
/** Должен быть заметно меньше activeMaxPause: иначе «живые» вкладки успеют удалиться до следующего тика. */
|
|
2528
|
+
B(this, "pollInterval", 6 * 1e3 + Math.floor(Math.random() * 2e3));
|
|
2529
|
+
// ~6–8 с + размазать одновременные запросы
|
|
2530
|
+
B(this, "sessionId", `${Date.now()}-${Math.random().toString(16).slice(2)}`);
|
|
2531
|
+
B(this, "continueCondition");
|
|
2532
|
+
B(this, "defaultContinueBackground", () => !0);
|
|
2533
|
+
var A, h, u;
|
|
2534
|
+
if (!t) {
|
|
2465
2535
|
console.error("BackgroundWorker: Нет опций конструктора");
|
|
2466
2536
|
return;
|
|
2467
2537
|
}
|
|
2468
|
-
const { appFunc: e, bx:
|
|
2469
|
-
this.bx =
|
|
2538
|
+
const { appFunc: e, bx: r, users: i, continueBackground: a } = t;
|
|
2539
|
+
this.bx = r, this.appInit = e, this.users = i, Kt(r), this.appPath = _(this, pt, zt).call(this, ((A = r == null ? void 0 : r.appConst) == null ? void 0 : A.pathApp) ?? ""), this.appName = ((h = r == null ? void 0 : r.appConst) == null ? void 0 : h.appName) ?? "", this.appCodeName = ((u = r == null ? void 0 : r.appConst) == null ? void 0 : u.appCodeName) ?? "", this.start = /* @__PURE__ */ new Date(), this.continueCondition = typeof a == "function" ? a : this.defaultContinueBackground;
|
|
2470
2540
|
}
|
|
2471
2541
|
async init() {
|
|
2472
2542
|
if (!this.appInit) {
|
|
@@ -2497,31 +2567,31 @@ class ie {
|
|
|
2497
2567
|
return;
|
|
2498
2568
|
}
|
|
2499
2569
|
await this.refreshTabs(!0), await this.ensureTabRegistered();
|
|
2500
|
-
const e = this.selectLeaderId(),
|
|
2501
|
-
await this.updateTabState(
|
|
2570
|
+
const e = this.selectLeaderId(), r = e && +this.id == +e;
|
|
2571
|
+
await this.updateTabState(r), r && !this.hasStarted && await this.runAsLeader();
|
|
2502
2572
|
}
|
|
2503
2573
|
stopTimers() {
|
|
2504
2574
|
this.heartbeat && (clearInterval(this.heartbeat), this.heartbeat = void 0), this.runHeartbeat && (clearInterval(this.runHeartbeat), this.runHeartbeat = void 0);
|
|
2505
2575
|
}
|
|
2506
2576
|
isAppPage() {
|
|
2507
|
-
var
|
|
2508
|
-
if (typeof BX24 > "u" || !((
|
|
2577
|
+
var t;
|
|
2578
|
+
if (typeof BX24 > "u" || !((t = BX24.placement) != null && t.info))
|
|
2509
2579
|
return !1;
|
|
2510
2580
|
try {
|
|
2511
|
-
const e = BX24.placement.info(),
|
|
2512
|
-
return !
|
|
2581
|
+
const e = BX24.placement.info(), r = e == null ? void 0 : e.placement, i = (e == null ? void 0 : e.options) || {}, a = (i == null ? void 0 : i.URI) || "", A = r === "PAGE_BACKGROUND_WORKER" || (i == null ? void 0 : i.ID) === "PAGE_BACKGROUND_WORKER", h = typeof a == "string" && (a.includes("marketplace/app") || a.includes("marketplace/apps") || a.includes("placement") || a.includes("sozdavatel" + this.appCodeName));
|
|
2582
|
+
return !A || h;
|
|
2513
2583
|
} catch {
|
|
2514
2584
|
return !1;
|
|
2515
2585
|
}
|
|
2516
2586
|
}
|
|
2517
2587
|
async checkEntity() {
|
|
2518
|
-
var
|
|
2519
|
-
const
|
|
2588
|
+
var r;
|
|
2589
|
+
const t = await this.safeCall(
|
|
2520
2590
|
() => this.bx.call({ method: "entity.get" })
|
|
2521
2591
|
);
|
|
2522
|
-
((
|
|
2523
|
-
|
|
2524
|
-
(
|
|
2592
|
+
((r = t == null ? void 0 : t.find) == null ? void 0 : r.call(
|
|
2593
|
+
t,
|
|
2594
|
+
(i) => i.ENTITY === this.entityName
|
|
2525
2595
|
)) || await this.safeCall(
|
|
2526
2596
|
() => this.bx.call({
|
|
2527
2597
|
method: "entity.add",
|
|
@@ -2534,7 +2604,7 @@ class ie {
|
|
|
2534
2604
|
);
|
|
2535
2605
|
}
|
|
2536
2606
|
async getTabs() {
|
|
2537
|
-
const
|
|
2607
|
+
const t = await this.safeCall(
|
|
2538
2608
|
() => {
|
|
2539
2609
|
var e;
|
|
2540
2610
|
return this.bx.call({
|
|
@@ -2547,14 +2617,14 @@ class ie {
|
|
|
2547
2617
|
});
|
|
2548
2618
|
}
|
|
2549
2619
|
);
|
|
2550
|
-
return !Array.isArray(
|
|
2620
|
+
return !Array.isArray(t) || !t.length ? [] : t.map((e) => {
|
|
2551
2621
|
if (!e)
|
|
2552
2622
|
return { id: void 0, data: void 0 };
|
|
2553
2623
|
try {
|
|
2554
|
-
const
|
|
2555
|
-
return { id: +e.ID || 0, data:
|
|
2556
|
-
} catch (
|
|
2557
|
-
return console.log("BackgroundWorker: parse tab error",
|
|
2624
|
+
const r = JSON.parse(e.DETAIL_TEXT);
|
|
2625
|
+
return { id: +e.ID || 0, data: r };
|
|
2626
|
+
} catch (r) {
|
|
2627
|
+
return console.log("BackgroundWorker: parse tab error", r), { id: +e.ID || 0, data: void 0 };
|
|
2558
2628
|
}
|
|
2559
2629
|
});
|
|
2560
2630
|
}
|
|
@@ -2565,109 +2635,107 @@ class ie {
|
|
|
2565
2635
|
return console.log(
|
|
2566
2636
|
"BackgroundWorker: Достигнут лимит вкладок даже после быстрой очистки, не регистрируемся"
|
|
2567
2637
|
), 0;
|
|
2568
|
-
const
|
|
2638
|
+
const t = {
|
|
2569
2639
|
lastActive: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2570
2640
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2571
2641
|
start: !1,
|
|
2572
2642
|
sessionId: this.sessionId
|
|
2573
2643
|
}, e = await this.safeCall(
|
|
2574
2644
|
() => {
|
|
2575
|
-
var
|
|
2645
|
+
var r;
|
|
2576
2646
|
return this.bx.call({
|
|
2577
2647
|
method: "entity.item.add",
|
|
2578
2648
|
params: {
|
|
2579
2649
|
ENTITY: this.entityName,
|
|
2580
|
-
NAME: (
|
|
2581
|
-
DETAIL_TEXT: JSON.stringify(
|
|
2650
|
+
NAME: (r = this.bx.userInfo) == null ? void 0 : r.ID,
|
|
2651
|
+
DETAIL_TEXT: JSON.stringify(t)
|
|
2582
2652
|
}
|
|
2583
2653
|
});
|
|
2584
2654
|
}
|
|
2585
2655
|
) || 0;
|
|
2586
2656
|
return this.id = +e || 0, this.id;
|
|
2587
2657
|
}
|
|
2588
|
-
async updateTabState(
|
|
2658
|
+
async updateTabState(t) {
|
|
2589
2659
|
if (!this.id)
|
|
2590
2660
|
return;
|
|
2591
2661
|
const e = {
|
|
2592
2662
|
lastActive: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2593
2663
|
createdAt: this.start.toISOString(),
|
|
2594
|
-
start:
|
|
2664
|
+
start: t,
|
|
2595
2665
|
sessionId: this.sessionId
|
|
2596
2666
|
};
|
|
2597
2667
|
await this.safeCall(
|
|
2598
2668
|
() => {
|
|
2599
|
-
var
|
|
2669
|
+
var r;
|
|
2600
2670
|
return this.bx.call({
|
|
2601
2671
|
method: "entity.item.update",
|
|
2602
2672
|
params: {
|
|
2603
2673
|
ENTITY: this.entityName,
|
|
2604
2674
|
ID: this.id,
|
|
2605
|
-
NAME: (
|
|
2675
|
+
NAME: (r = this.bx.userInfo) == null ? void 0 : r.ID,
|
|
2606
2676
|
DETAIL_TEXT: JSON.stringify(e)
|
|
2607
2677
|
}
|
|
2608
2678
|
});
|
|
2609
2679
|
}
|
|
2610
2680
|
);
|
|
2611
2681
|
}
|
|
2612
|
-
async deleteTabs(
|
|
2613
|
-
if (!
|
|
2682
|
+
async deleteTabs(t = []) {
|
|
2683
|
+
if (!t.length)
|
|
2614
2684
|
return;
|
|
2615
|
-
const e =
|
|
2685
|
+
const e = t.map((r) => ({
|
|
2616
2686
|
method: "entity.item.delete",
|
|
2617
|
-
params: { ENTITY: this.entityName, ID:
|
|
2687
|
+
params: { ENTITY: this.entityName, ID: r.id }
|
|
2618
2688
|
}));
|
|
2619
2689
|
await this.safeCall(() => this.bx.batch(e));
|
|
2620
2690
|
}
|
|
2621
|
-
getRandomNum() {
|
|
2622
|
-
const r = Math.round(Number(Math.random().toFixed(2)) * 30);
|
|
2623
|
-
return Math.round(Math.random()) ? r : -r;
|
|
2624
|
-
}
|
|
2625
2691
|
async checkPlacementType() {
|
|
2626
|
-
var
|
|
2692
|
+
var t, e;
|
|
2627
2693
|
try {
|
|
2628
|
-
|
|
2694
|
+
if (!((t = this.bx) != null && t.isAdmin))
|
|
2695
|
+
return !0;
|
|
2696
|
+
const r = await this.safeCall(
|
|
2629
2697
|
() => this.bx.getPlacement()
|
|
2630
2698
|
);
|
|
2631
|
-
if (!
|
|
2699
|
+
if (!r || !Array.isArray(r))
|
|
2632
2700
|
return console.log(
|
|
2633
2701
|
"BackgroundWorker: Не получили список размещений, продолжаем"
|
|
2634
2702
|
), !0;
|
|
2635
|
-
const
|
|
2703
|
+
const i = +(((e = this.bx.userInfo) == null ? void 0 : e.ID) ?? 0), a = this.isIndividualPlacement(
|
|
2636
2704
|
typeof window < "u" ? window.location.href : ""
|
|
2637
|
-
),
|
|
2638
|
-
if (!
|
|
2705
|
+
), A = !a;
|
|
2706
|
+
if (!i)
|
|
2639
2707
|
return !0;
|
|
2640
2708
|
let h = !1;
|
|
2641
|
-
for (const
|
|
2642
|
-
if (
|
|
2709
|
+
for (const u of r) {
|
|
2710
|
+
if (u.placement !== "PAGE_BACKGROUND_WORKER" || !(u.userId || u.handler && u.handler.includes("USER_ID=")))
|
|
2643
2711
|
continue;
|
|
2644
|
-
const
|
|
2645
|
-
if (
|
|
2712
|
+
const f = u.userId || (u.handler ? this.extractUserIdFromHandler(u.handler) : null);
|
|
2713
|
+
if (f && +f === i) {
|
|
2646
2714
|
h = !0;
|
|
2647
2715
|
break;
|
|
2648
2716
|
}
|
|
2649
2717
|
}
|
|
2650
|
-
return
|
|
2718
|
+
return a ? (console.log(
|
|
2651
2719
|
"BackgroundWorker: Индивидуальная встройка - разрешено"
|
|
2652
|
-
), !0) :
|
|
2720
|
+
), !0) : A && h ? (console.log(
|
|
2653
2721
|
"BackgroundWorker: Есть личная встройка, общую не запускаем"
|
|
2654
2722
|
), !1) : (console.log(
|
|
2655
2723
|
"BackgroundWorker: Проверка типа встройки пройдена, продолжаем"
|
|
2656
2724
|
), !0);
|
|
2657
|
-
} catch (
|
|
2725
|
+
} catch (r) {
|
|
2658
2726
|
return console.error(
|
|
2659
2727
|
"BackgroundWorker: Ошибка при проверке типа встройки",
|
|
2660
|
-
|
|
2728
|
+
r
|
|
2661
2729
|
), !0;
|
|
2662
2730
|
}
|
|
2663
2731
|
}
|
|
2664
|
-
isIndividualPlacement(
|
|
2665
|
-
return !
|
|
2732
|
+
isIndividualPlacement(t) {
|
|
2733
|
+
return !t || typeof t != "string" ? !1 : t.includes("USER_ID=");
|
|
2666
2734
|
}
|
|
2667
|
-
extractUserIdFromHandler(
|
|
2668
|
-
if (!
|
|
2735
|
+
extractUserIdFromHandler(t) {
|
|
2736
|
+
if (!t || typeof t != "string")
|
|
2669
2737
|
return null;
|
|
2670
|
-
const e =
|
|
2738
|
+
const e = t.match(/USER_ID=(\d+)/);
|
|
2671
2739
|
return e ? +e[1] : null;
|
|
2672
2740
|
}
|
|
2673
2741
|
async continueBackground() {
|
|
@@ -2676,209 +2744,231 @@ class ie {
|
|
|
2676
2744
|
this.continueCondition(this)
|
|
2677
2745
|
);
|
|
2678
2746
|
return console.log(e ? "BackgroundWorker: Условие продолжения выполнено" : "BackgroundWorker: continueBackground вернул false"), e;
|
|
2679
|
-
} catch (
|
|
2747
|
+
} catch (t) {
|
|
2680
2748
|
return console.error(
|
|
2681
2749
|
"BackgroundWorker: Ошибка в continueCondition",
|
|
2682
|
-
|
|
2750
|
+
t
|
|
2683
2751
|
), !1;
|
|
2684
2752
|
}
|
|
2685
2753
|
}
|
|
2686
|
-
async refreshTabs(
|
|
2687
|
-
const
|
|
2688
|
-
for (const
|
|
2689
|
-
if (!(
|
|
2690
|
-
|
|
2754
|
+
async refreshTabs(t = !1, e = this.activeMaxPause) {
|
|
2755
|
+
const r = [], i = [], a = Date.now(), A = await this.getTabs();
|
|
2756
|
+
for (const h of A) {
|
|
2757
|
+
if (!(h != null && h.data)) {
|
|
2758
|
+
r.push(h);
|
|
2691
2759
|
continue;
|
|
2692
2760
|
}
|
|
2693
|
-
if (
|
|
2694
|
-
|
|
2761
|
+
if (a - new Date(h.data.lastActive || 0).getTime() > e) {
|
|
2762
|
+
r.push(h);
|
|
2695
2763
|
continue;
|
|
2696
2764
|
}
|
|
2697
|
-
|
|
2765
|
+
i.push(h);
|
|
2698
2766
|
}
|
|
2699
|
-
return
|
|
2767
|
+
return t && r.length && await this.deleteTabs(r), this.tabList = i, i;
|
|
2700
2768
|
}
|
|
2701
2769
|
selectLeaderId() {
|
|
2702
2770
|
var e;
|
|
2703
|
-
return this.tabList.length && +((e = [...this.tabList].sort((
|
|
2704
|
-
var
|
|
2705
|
-
const
|
|
2706
|
-
((
|
|
2707
|
-
).getTime(),
|
|
2708
|
-
((
|
|
2771
|
+
return this.tabList.length && +((e = [...this.tabList].sort((r, i) => {
|
|
2772
|
+
var h, u, n, f;
|
|
2773
|
+
const a = new Date(
|
|
2774
|
+
((h = r.data) == null ? void 0 : h.createdAt) || ((u = r.data) == null ? void 0 : u.lastActive) || 0
|
|
2775
|
+
).getTime(), A = new Date(
|
|
2776
|
+
((n = i.data) == null ? void 0 : n.createdAt) || ((f = i.data) == null ? void 0 : f.lastActive) || 0
|
|
2709
2777
|
).getTime();
|
|
2710
|
-
return
|
|
2778
|
+
return a === A ? (+r.id || 0) - (+i.id || 0) : a - A;
|
|
2711
2779
|
})[0]) == null ? void 0 : e.id) || 0;
|
|
2712
2780
|
}
|
|
2713
2781
|
async runAsLeader() {
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2782
|
+
var i, a;
|
|
2783
|
+
const t = String(((a = (i = this.bx) == null ? void 0 : i.userInfo) == null ? void 0 : a.ID) ?? "0"), e = `background-worker:${this.entityName}:${t}`;
|
|
2784
|
+
(await Se(
|
|
2785
|
+
e,
|
|
2786
|
+
async () => {
|
|
2787
|
+
this.hasStarted = !0;
|
|
2788
|
+
const A = Math.min(
|
|
2789
|
+
this.activeMaxPause - 1500,
|
|
2790
|
+
Math.max(2500, Math.floor(this.pollInterval / 2))
|
|
2791
|
+
);
|
|
2792
|
+
this.runHeartbeat = setInterval(
|
|
2793
|
+
() => {
|
|
2794
|
+
this.updateTabState(!0).catch(
|
|
2795
|
+
(h) => console.error(
|
|
2796
|
+
"BackgroundWorker: heartbeat update failed",
|
|
2797
|
+
h
|
|
2798
|
+
)
|
|
2799
|
+
);
|
|
2800
|
+
},
|
|
2801
|
+
A
|
|
2721
2802
|
);
|
|
2803
|
+
try {
|
|
2804
|
+
await this.appInit();
|
|
2805
|
+
} catch (h) {
|
|
2806
|
+
console.error("BackgroundWorker: appInit failed", h);
|
|
2807
|
+
}
|
|
2808
|
+
this.stopTimers(), this.id && (await this.deleteTabs([{ id: this.id }]), this.id = 0);
|
|
2722
2809
|
},
|
|
2723
|
-
|
|
2810
|
+
{ ifAvailable: !0 }
|
|
2811
|
+
)).skipped && console.log(
|
|
2812
|
+
"BackgroundWorker: runAsLeader пропущен — Web Lock у другой вкладки (тот же фоновый воркер)"
|
|
2724
2813
|
);
|
|
2725
|
-
try {
|
|
2726
|
-
await this.appInit();
|
|
2727
|
-
} catch (r) {
|
|
2728
|
-
console.error("BackgroundWorker: appInit failed", r);
|
|
2729
|
-
}
|
|
2730
|
-
this.stopTimers(), this.id && (await this.deleteTabs([{ id: this.id }]), this.id = 0);
|
|
2731
2814
|
}
|
|
2732
2815
|
async setBackgroundWorkerAll() {
|
|
2733
|
-
var
|
|
2734
|
-
if (!((
|
|
2816
|
+
var T, b, I, N;
|
|
2817
|
+
if (!((T = this.bx) != null && T.isAdmin)) {
|
|
2735
2818
|
console.log(
|
|
2736
2819
|
"BackgroundWorker: setBackgroundWorkerAll доступен только админам"
|
|
2737
2820
|
);
|
|
2738
2821
|
return;
|
|
2739
2822
|
}
|
|
2740
|
-
(
|
|
2741
|
-
const
|
|
2823
|
+
(b = this.users) != null && b.length || await this.getEntityData(), Kt(this.bx);
|
|
2824
|
+
const t = _(this, pt, zt).call(this, ((N = (I = this.bx) == null ? void 0 : I.appConst) == null ? void 0 : N.pathApp) ?? "");
|
|
2825
|
+
if (!t) {
|
|
2826
|
+
console.error(
|
|
2827
|
+
"BackgroundWorker: setBackgroundWorkerAll — нет валидного pathApp, привязка PAGE_BACKGROUND_WORKER пропущена"
|
|
2828
|
+
);
|
|
2829
|
+
return;
|
|
2830
|
+
}
|
|
2831
|
+
const e = await this.safeCall(
|
|
2742
2832
|
() => this.bx.getPlacement()
|
|
2743
|
-
),
|
|
2744
|
-
let
|
|
2745
|
-
(
|
|
2746
|
-
if (
|
|
2833
|
+
), r = /* @__PURE__ */ new Map();
|
|
2834
|
+
let i = null;
|
|
2835
|
+
(e || []).forEach((p) => {
|
|
2836
|
+
if (p.placement !== "PAGE_BACKGROUND_WORKER")
|
|
2747
2837
|
return;
|
|
2748
|
-
if (
|
|
2749
|
-
const
|
|
2750
|
-
|
|
2838
|
+
if (p.userId || p.handler && p.handler.includes("USER_ID=")) {
|
|
2839
|
+
const M = p.userId || (p.handler ? this.extractUserIdFromHandler(p.handler) : null);
|
|
2840
|
+
M && r.set(+M, p);
|
|
2751
2841
|
} else
|
|
2752
|
-
|
|
2842
|
+
i = p;
|
|
2753
2843
|
});
|
|
2754
|
-
const
|
|
2755
|
-
|
|
2756
|
-
const
|
|
2757
|
-
return (
|
|
2844
|
+
const a = await this.resolveAdmins(), A = await this.getEligibleUsersForBackgroundWorker(a);
|
|
2845
|
+
A.sort((p, R) => {
|
|
2846
|
+
const M = p.LAST_LOGIN ? new Date(p.LAST_LOGIN) : /* @__PURE__ */ new Date(0);
|
|
2847
|
+
return (R.LAST_LOGIN ? new Date(R.LAST_LOGIN) : /* @__PURE__ */ new Date(0)) - M;
|
|
2758
2848
|
});
|
|
2759
|
-
const h = 10,
|
|
2760
|
-
const
|
|
2761
|
-
if (!
|
|
2849
|
+
const h = 10, u = A.slice(0, h), n = u.filter((p) => {
|
|
2850
|
+
const R = r.get(+p.ID);
|
|
2851
|
+
if (!R)
|
|
2762
2852
|
return !0;
|
|
2763
|
-
const
|
|
2764
|
-
return
|
|
2765
|
-
}),
|
|
2766
|
-
for (const [
|
|
2767
|
-
const
|
|
2768
|
-
|
|
2853
|
+
const M = `${t}?USER_ID=${p.ID}/`;
|
|
2854
|
+
return R.handler !== M;
|
|
2855
|
+
}), f = [];
|
|
2856
|
+
for (const [p] of r) {
|
|
2857
|
+
const R = +p || 0;
|
|
2858
|
+
A.find((H) => +H.ID === R) || f.push(R);
|
|
2769
2859
|
}
|
|
2770
|
-
for (const
|
|
2771
|
-
const
|
|
2772
|
-
if (!
|
|
2860
|
+
for (const p of u) {
|
|
2861
|
+
const R = r.get(+p.ID);
|
|
2862
|
+
if (!R)
|
|
2773
2863
|
continue;
|
|
2774
|
-
const
|
|
2775
|
-
|
|
2864
|
+
const M = `${t}?USER_ID=${p.ID}/`;
|
|
2865
|
+
R.handler !== M && f.push(+p.ID);
|
|
2776
2866
|
}
|
|
2777
|
-
const
|
|
2778
|
-
for (const
|
|
2779
|
-
|
|
2867
|
+
const d = [];
|
|
2868
|
+
for (const p of f)
|
|
2869
|
+
d.push({
|
|
2780
2870
|
method: "placement.unbind",
|
|
2781
2871
|
params: {
|
|
2782
2872
|
PLACEMENT: "PAGE_BACKGROUND_WORKER",
|
|
2783
|
-
HANDLER: `${
|
|
2873
|
+
HANDLER: `${t}?USER_ID=${p}/`
|
|
2784
2874
|
}
|
|
2785
2875
|
});
|
|
2786
|
-
const
|
|
2787
|
-
|
|
2876
|
+
const c = i && (n.length > 0 || i.handler !== `${t}`);
|
|
2877
|
+
c && d.push({
|
|
2788
2878
|
method: "placement.unbind",
|
|
2789
2879
|
params: {
|
|
2790
2880
|
PLACEMENT: "PAGE_BACKGROUND_WORKER",
|
|
2791
|
-
HANDLER:
|
|
2881
|
+
HANDLER: i.handler || `${t}`
|
|
2792
2882
|
}
|
|
2793
2883
|
});
|
|
2794
|
-
for (const
|
|
2795
|
-
|
|
2884
|
+
for (const p of n)
|
|
2885
|
+
d.push({
|
|
2796
2886
|
method: "placement.bind",
|
|
2797
2887
|
params: {
|
|
2798
2888
|
PLACEMENT: "PAGE_BACKGROUND_WORKER",
|
|
2799
|
-
HANDLER: `${
|
|
2889
|
+
HANDLER: `${t}?USER_ID=${p.ID}/`,
|
|
2800
2890
|
LANG_ALL: { ru: { TITLE: this.appName } },
|
|
2801
2891
|
OPTIONS: {
|
|
2802
|
-
errorHandlerUrl: `${
|
|
2892
|
+
errorHandlerUrl: `${t}?USER_ID=${p.ID}/`
|
|
2803
2893
|
},
|
|
2804
|
-
USER_ID:
|
|
2894
|
+
USER_ID: p.ID
|
|
2805
2895
|
}
|
|
2806
2896
|
});
|
|
2807
|
-
(!
|
|
2897
|
+
(!i || c) && d.push({
|
|
2808
2898
|
method: "placement.bind",
|
|
2809
2899
|
params: {
|
|
2810
2900
|
PLACEMENT: "PAGE_BACKGROUND_WORKER",
|
|
2811
|
-
HANDLER: `${
|
|
2901
|
+
HANDLER: `${t}`,
|
|
2812
2902
|
LANG_ALL: { ru: { TITLE: this.appName } },
|
|
2813
|
-
OPTIONS: { errorHandlerUrl: `${
|
|
2903
|
+
OPTIONS: { errorHandlerUrl: `${t}` }
|
|
2814
2904
|
}
|
|
2815
2905
|
});
|
|
2816
|
-
const
|
|
2817
|
-
(
|
|
2818
|
-
),
|
|
2819
|
-
(
|
|
2906
|
+
const l = d.filter(
|
|
2907
|
+
(p) => p.method === "placement.unbind"
|
|
2908
|
+
), O = d.filter(
|
|
2909
|
+
(p) => p.method === "placement.bind"
|
|
2820
2910
|
);
|
|
2821
|
-
|
|
2911
|
+
l.length && await this.safeCall(
|
|
2822
2912
|
() => this.bx.batch(
|
|
2823
2913
|
Object.fromEntries(
|
|
2824
|
-
|
|
2914
|
+
l.map((p, R) => [`unbind_${R}`, p])
|
|
2825
2915
|
)
|
|
2826
2916
|
)
|
|
2827
|
-
),
|
|
2917
|
+
), O.length && await this.safeCall(
|
|
2828
2918
|
() => this.bx.batch(
|
|
2829
2919
|
Object.fromEntries(
|
|
2830
|
-
|
|
2920
|
+
O.map((p, R) => [`bind_${R}`, p])
|
|
2831
2921
|
)
|
|
2832
2922
|
)
|
|
2833
|
-
),
|
|
2923
|
+
), d.length || console.log("setBackgroundWorkerAll: Нет операций");
|
|
2834
2924
|
}
|
|
2835
2925
|
async resolveAdmins() {
|
|
2836
|
-
var
|
|
2926
|
+
var t, e;
|
|
2837
2927
|
try {
|
|
2838
|
-
const
|
|
2839
|
-
if (!
|
|
2840
|
-
if (
|
|
2841
|
-
const
|
|
2842
|
-
(
|
|
2928
|
+
const r = +(((t = this.bx.userInfo) == null ? void 0 : t.ID) ?? 0), i = !!((e = this.bx) != null && e.isAdmin), a = await this.getAdminsList() || [];
|
|
2929
|
+
if (!i) {
|
|
2930
|
+
if (r && a.includes(+r)) {
|
|
2931
|
+
const u = a.filter(
|
|
2932
|
+
(n) => +n != +r
|
|
2843
2933
|
);
|
|
2844
|
-
return await this.saveAdminsList(
|
|
2934
|
+
return await this.saveAdminsList(u), u;
|
|
2845
2935
|
}
|
|
2846
|
-
return
|
|
2936
|
+
return a;
|
|
2847
2937
|
}
|
|
2848
|
-
const
|
|
2849
|
-
|
|
2850
|
-
const
|
|
2851
|
-
return await this.saveAdminsList(
|
|
2852
|
-
} catch (
|
|
2853
|
-
return console.error("BackgroundWorker: resolveAdmins error",
|
|
2938
|
+
const A = /* @__PURE__ */ new Set([...a || []]);
|
|
2939
|
+
r && A.add(+r);
|
|
2940
|
+
const h = [...A].filter(Boolean);
|
|
2941
|
+
return await this.saveAdminsList(h), h;
|
|
2942
|
+
} catch (r) {
|
|
2943
|
+
return console.error("BackgroundWorker: resolveAdmins error", r), [];
|
|
2854
2944
|
}
|
|
2855
2945
|
}
|
|
2856
|
-
async getEligibleUsersForBackgroundWorker(
|
|
2946
|
+
async getEligibleUsersForBackgroundWorker(t = []) {
|
|
2857
2947
|
const e = (this.users ?? []).filter(
|
|
2858
|
-
(
|
|
2859
|
-
),
|
|
2860
|
-
return e.filter((
|
|
2948
|
+
(i) => i.ACTIVE === "Y" || i.ACTIVE === !0
|
|
2949
|
+
), r = t.map((i) => +i || 0).filter(Boolean);
|
|
2950
|
+
return e.filter((i) => r.includes(+i.ID || 0));
|
|
2861
2951
|
}
|
|
2862
|
-
async saveAdminsList(
|
|
2952
|
+
async saveAdminsList(t = []) {
|
|
2863
2953
|
try {
|
|
2864
|
-
BX24.appOption.set("adminsList", JSON.stringify(
|
|
2954
|
+
BX24.appOption.set("adminsList", JSON.stringify(t));
|
|
2865
2955
|
} catch (e) {
|
|
2866
2956
|
console.error("BackgroundWorker: saveAdminsList error", e);
|
|
2867
2957
|
}
|
|
2868
2958
|
}
|
|
2869
2959
|
async getAdminsList() {
|
|
2870
2960
|
try {
|
|
2871
|
-
const
|
|
2872
|
-
return Array.isArray(e) ? e.map((
|
|
2873
|
-
} catch (
|
|
2874
|
-
return console.error("BackgroundWorker: getAdminsList error",
|
|
2961
|
+
const t = BX24.appOption.get("adminsList"), e = t ? JSON.parse(t) : [];
|
|
2962
|
+
return Array.isArray(e) ? e.map((r) => +r || 0).filter(Boolean) : [];
|
|
2963
|
+
} catch (t) {
|
|
2964
|
+
return console.error("BackgroundWorker: getAdminsList error", t), [];
|
|
2875
2965
|
}
|
|
2876
2966
|
}
|
|
2877
2967
|
async getEntityData() {
|
|
2878
|
-
const
|
|
2968
|
+
const t = {
|
|
2879
2969
|
users: { method: "user.get", params: { filter: { ACTIVE: "Y" } } }
|
|
2880
2970
|
}, { users: e } = await this.safeCall(
|
|
2881
|
-
() => this.bx.batch(
|
|
2971
|
+
() => this.bx.batch(t).then((r) => r ? (Array.isArray(r.users) || (r.users = []), r) : { users: [] })
|
|
2882
2972
|
);
|
|
2883
2973
|
this.users = e;
|
|
2884
2974
|
}
|
|
@@ -2887,30 +2977,38 @@ class ie {
|
|
|
2887
2977
|
* (общая и индивидуальные) и что список пользователей подгружен.
|
|
2888
2978
|
*/
|
|
2889
2979
|
async ensureAdminPlacements() {
|
|
2890
|
-
var
|
|
2891
|
-
(
|
|
2980
|
+
var t, e;
|
|
2981
|
+
(t = this.bx) != null && t.isAdmin && ((e = this.users) != null && e.length || await this.getEntityData(), await this.setBackgroundWorkerAll());
|
|
2892
2982
|
}
|
|
2893
|
-
pause(
|
|
2894
|
-
return new Promise((
|
|
2983
|
+
pause(t = 500, e) {
|
|
2984
|
+
return new Promise((r) => {
|
|
2895
2985
|
setTimeout(() => {
|
|
2896
|
-
e && e(),
|
|
2897
|
-
},
|
|
2986
|
+
e && e(), r(!0);
|
|
2987
|
+
}, t);
|
|
2898
2988
|
});
|
|
2899
2989
|
}
|
|
2900
|
-
async safeCall(
|
|
2990
|
+
async safeCall(t) {
|
|
2901
2991
|
try {
|
|
2902
|
-
return await
|
|
2992
|
+
return await t();
|
|
2903
2993
|
} catch (e) {
|
|
2904
2994
|
console.error("BackgroundWorker: safeCall error", e);
|
|
2905
2995
|
return;
|
|
2906
2996
|
}
|
|
2907
2997
|
}
|
|
2908
2998
|
}
|
|
2999
|
+
pt = new WeakSet(), zt = function(t) {
|
|
3000
|
+
if (!t || typeof t != "string")
|
|
3001
|
+
return "";
|
|
3002
|
+
const e = Qt(t).replace(/\/+$/, "");
|
|
3003
|
+
return e ? oe(e) ? (console.error(
|
|
3004
|
+
"BackgroundWorker: pathApp не должен указывать на /marketplace/app/… Откройте приложение во встроенном iframe (entry CDN), не в оболочке маркетплейса."
|
|
3005
|
+
), "") : e : "";
|
|
3006
|
+
};
|
|
2909
3007
|
export {
|
|
2910
|
-
|
|
3008
|
+
Me as BackgroundWorker,
|
|
2911
3009
|
v as Batch,
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
3010
|
+
Le as BxBoot,
|
|
3011
|
+
se as BxHelper,
|
|
3012
|
+
_e as BxLogger,
|
|
3013
|
+
yt as tempus
|
|
2916
3014
|
};
|