@coze-arch/cli 0.0.7 → 0.0.8

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.
@@ -0,0 +1,1358 @@
1
+ var DEFAULT_SIZE = 10;
2
+ var DEFAULT_WAIT = 1000;
3
+ var stringifyBatch = function (list) {
4
+ return JSON.stringify({
5
+ ev_type: 'batch',
6
+ list: list,
7
+ });
8
+ };
9
+ function createBatchSender(config) {
10
+ var transport = config.transport;
11
+ var endpoint = config.endpoint, _a = config.size, size = _a === void 0 ? DEFAULT_SIZE : _a, _b = config.wait, wait = _b === void 0 ? DEFAULT_WAIT : _b;
12
+ var batch = [];
13
+ var tid = 0;
14
+ var fail;
15
+ var success;
16
+ var sender = {
17
+ getSize: function () {
18
+ return size;
19
+ },
20
+ getWait: function () {
21
+ return wait;
22
+ },
23
+ setSize: function (v) {
24
+ size = v;
25
+ },
26
+ setWait: function (v) {
27
+ wait = v;
28
+ },
29
+ getEndpoint: function () {
30
+ return endpoint;
31
+ },
32
+ setEndpoint: function (v) {
33
+ endpoint = v;
34
+ },
35
+ send: function (e) {
36
+ batch.push(e);
37
+ if (batch.length >= size) {
38
+ sendBatch.call(this);
39
+ }
40
+ clearTimeout(tid);
41
+ tid = setTimeout(sendBatch.bind(this), wait);
42
+ },
43
+ flush: function () {
44
+ clearTimeout(tid);
45
+ sendBatch.call(this);
46
+ },
47
+ getBatchData: function () {
48
+ return batch.length ? stringifyBatch(batch) : '';
49
+ },
50
+ clear: function () {
51
+ clearTimeout(tid);
52
+ batch = [];
53
+ },
54
+ fail: function (cb) {
55
+ fail = cb;
56
+ },
57
+ success: function (cb) {
58
+ success = cb;
59
+ },
60
+ };
61
+ function sendBatch() {
62
+ if (!batch.length) {
63
+ return;
64
+ }
65
+ var data = this.getBatchData();
66
+ transport.post({
67
+ url: endpoint,
68
+ data: data,
69
+ fail: function (err) {
70
+ fail && fail(err, data);
71
+ },
72
+ success: function () {
73
+ success && success(data);
74
+ },
75
+ });
76
+ batch = [];
77
+ }
78
+ return sender;
79
+ }
80
+
81
+ /*! *****************************************************************************
82
+ Copyright (c) Microsoft Corporation.
83
+
84
+ Permission to use, copy, modify, and/or distribute this software for any
85
+ purpose with or without fee is hereby granted.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
88
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
89
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
90
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
91
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
92
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
93
+ PERFORMANCE OF THIS SOFTWARE.
94
+ ***************************************************************************** */
95
+
96
+ var __assign = function() {
97
+ __assign = Object.assign || function __assign(t) {
98
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
99
+ s = arguments[i];
100
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
101
+ }
102
+ return t;
103
+ };
104
+ return __assign.apply(this, arguments);
105
+ };
106
+
107
+ function __values(o) {
108
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
109
+ if (m) return m.call(o);
110
+ if (o && typeof o.length === "number") return {
111
+ next: function () {
112
+ if (o && i >= o.length) o = void 0;
113
+ return { value: o && o[i++], done: !o };
114
+ }
115
+ };
116
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
117
+ }
118
+
119
+ function __read(o, n) {
120
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
121
+ if (!m) return o;
122
+ var i = m.call(o), r, ar = [], e;
123
+ try {
124
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
125
+ }
126
+ catch (error) { e = { error: error }; }
127
+ finally {
128
+ try {
129
+ if (r && !r.done && (m = i["return"])) m.call(i);
130
+ }
131
+ finally { if (e) throw e.error; }
132
+ }
133
+ return ar;
134
+ }
135
+
136
+ function __spreadArray(to, from, pack) {
137
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
138
+ if (ar || !(i in from)) {
139
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
140
+ ar[i] = from[i];
141
+ }
142
+ }
143
+ return to.concat(ar || Array.prototype.slice.call(from));
144
+ }
145
+
146
+ var noop = function () { return ({}); };
147
+ function id(v) {
148
+ return v;
149
+ }
150
+
151
+ // eslint-disable-next-line @typescript-eslint/ban-types
152
+ function isObject(o) {
153
+ return typeof o === 'object' && o !== null;
154
+ }
155
+ var objProto = Object.prototype;
156
+ function isArray(o) {
157
+ return objProto.toString.call(o) === '[object Array]';
158
+ }
159
+ function isBoolean(o) {
160
+ return typeof o === 'boolean';
161
+ }
162
+ function isNumber(o) {
163
+ return typeof o === 'number';
164
+ }
165
+ function isString(o) {
166
+ return typeof o === 'string';
167
+ }
168
+
169
+ // 检查数组中是否有元素
170
+ function arrayIncludes(array, value) {
171
+ if (!isArray(array)) {
172
+ return false;
173
+ }
174
+ if (array.length === 0) {
175
+ return false;
176
+ }
177
+ var k = 0;
178
+ while (k < array.length) {
179
+ if (array[k] === value) {
180
+ return true;
181
+ }
182
+ k++;
183
+ }
184
+ return false;
185
+ }
186
+ var arrayRemove = function (arr, e) {
187
+ if (!isArray(arr)) {
188
+ return arr;
189
+ }
190
+ var i = arr.indexOf(e);
191
+ if (i >= 0) {
192
+ var arr_ = arr.slice();
193
+ arr_.splice(i, 1);
194
+ return arr_;
195
+ }
196
+ return arr;
197
+ };
198
+ /**
199
+ * 按路径访问对象属性
200
+ * @param target 待访问对象
201
+ * @param property 访问属性路径
202
+ * @param { (target: any, property: string): any } visitor 访问器
203
+ */
204
+ var safeVisit = function (target, path, visitor) {
205
+ var _a, _b;
206
+ var paths = path.split('.');
207
+ var _c = __read(paths), method = _c[0], rest = _c.slice(1);
208
+ while (target && rest.length > 0) {
209
+ target = target[method];
210
+ _a = rest, _b = __read(_a), method = _b[0], rest = _b.slice(1);
211
+ }
212
+ if (!target) {
213
+ return undefined;
214
+ }
215
+ return visitor(target, method);
216
+ };
217
+
218
+ function safeStringify(a) {
219
+ try {
220
+ return isString(a) ? a : JSON.stringify(a);
221
+ }
222
+ catch (err) {
223
+ return '[FAILED_TO_STRINGIFY]:' + String(err);
224
+ }
225
+ }
226
+
227
+ function createContextAgent() {
228
+ var context = {};
229
+ var stringified = {};
230
+ var contextAgent = {
231
+ set: function (k, v) {
232
+ context[k] = v;
233
+ stringified[k] = safeStringify(v);
234
+ return contextAgent;
235
+ },
236
+ merge: function (ctx) {
237
+ context = __assign(__assign({}, context), ctx);
238
+ Object.keys(ctx).forEach(function (key) {
239
+ stringified[key] = safeStringify(ctx[key]);
240
+ });
241
+ return contextAgent;
242
+ },
243
+ delete: function (k) {
244
+ delete context[k];
245
+ delete stringified[k];
246
+ return contextAgent;
247
+ },
248
+ clear: function () {
249
+ context = {};
250
+ stringified = {};
251
+ return contextAgent;
252
+ },
253
+ get: function (k) {
254
+ return stringified[k];
255
+ },
256
+ toString: function () {
257
+ return __assign({}, stringified);
258
+ },
259
+ };
260
+ return contextAgent;
261
+ }
262
+
263
+ var getPrintString = function () {
264
+ // @ts-expect-error
265
+ if (''.padStart) {
266
+ return function (str, prefixLength) {
267
+ if (prefixLength === void 0) { prefixLength = 8; }
268
+ return str.padStart(prefixLength, ' ');
269
+ };
270
+ }
271
+ return function (str) { return str; };
272
+ };
273
+ var printString = getPrintString();
274
+ var errCount = 0;
275
+ var error = function () {
276
+ var args = [];
277
+ for (var _i = 0; _i < arguments.length; _i++) {
278
+ args[_i] = arguments[_i];
279
+ }
280
+ // eslint-disable-next-line no-console
281
+ console.error.apply(console, __spreadArray(['[SDK]', Date.now(), printString("" + errCount++)], __read(args), false));
282
+ };
283
+ var warnCount = 0;
284
+ var warn = function () {
285
+ var args = [];
286
+ for (var _i = 0; _i < arguments.length; _i++) {
287
+ args[_i] = arguments[_i];
288
+ }
289
+ // eslint-disable-next-line no-console
290
+ console.warn.apply(console, __spreadArray(['[SDK]', Date.now(), printString("" + warnCount++)], __read(args), false));
291
+ };
292
+
293
+ var isHitBySampleRate = function (sampleRate) {
294
+ if (Math.random() < Number(sampleRate)) {
295
+ return true;
296
+ }
297
+ return false;
298
+ };
299
+ var isHitByRandom = function (random, sampleRate) {
300
+ if (random < Number(sampleRate)) {
301
+ return true;
302
+ }
303
+ return false;
304
+ };
305
+
306
+ var runProcessors = function (fns) {
307
+ return function (e) {
308
+ var r = e;
309
+ for (var i = 0; i < fns.length; i++) {
310
+ if (r) {
311
+ try {
312
+ r = fns[i](r);
313
+ }
314
+ catch (err) {
315
+ error(err);
316
+ }
317
+ }
318
+ else {
319
+ break;
320
+ }
321
+ }
322
+ return r;
323
+ };
324
+ };
325
+
326
+ /**
327
+ * 生成uuid
328
+ * stolen from https://github.com/kelektiv/node-uuid#readme uuid/v4
329
+ *
330
+ * @returns
331
+ */
332
+ function mathRNG() {
333
+ var rnds = new Array(16);
334
+ var r = 0;
335
+ for (var i = 0; i < 16; i++) {
336
+ if ((i & 0x03) === 0) {
337
+ r = Math.random() * 0x100000000;
338
+ }
339
+ rnds[i] = (r >>> ((i & 0x03) << 3)) & 0xff;
340
+ }
341
+ return rnds;
342
+ }
343
+ function bytesToUuid(buf) {
344
+ var byteToHex = [];
345
+ for (var index = 0; index < 256; ++index) {
346
+ byteToHex[index] = (index + 0x100).toString(16).substr(1);
347
+ }
348
+ var i = 0;
349
+ var bth = byteToHex;
350
+ // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
351
+ return [
352
+ bth[buf[i++]],
353
+ bth[buf[i++]],
354
+ bth[buf[i++]],
355
+ bth[buf[i++]],
356
+ '-',
357
+ bth[buf[i++]],
358
+ bth[buf[i++]],
359
+ '-',
360
+ bth[buf[i++]],
361
+ bth[buf[i++]],
362
+ '-',
363
+ bth[buf[i++]],
364
+ bth[buf[i++]],
365
+ '-',
366
+ bth[buf[i++]],
367
+ bth[buf[i++]],
368
+ bth[buf[i++]],
369
+ bth[buf[i++]],
370
+ bth[buf[i++]],
371
+ bth[buf[i++]],
372
+ ].join('');
373
+ }
374
+ function uuid() {
375
+ var rnds = mathRNG();
376
+ // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
377
+ rnds[6] = (rnds[6] & 0x0f) | 0x40;
378
+ rnds[8] = (rnds[8] & 0x3f) | 0x80;
379
+ return bytesToUuid(rnds);
380
+ }
381
+
382
+ function createDestroyAgent() {
383
+ var destroyed = false;
384
+ var data = {};
385
+ var removeTearDownGroup = function (tearDownGroup) {
386
+ tearDownGroup.length &&
387
+ tearDownGroup.forEach(function (v) {
388
+ try {
389
+ v();
390
+ // eslint-disable-next-line no-empty
391
+ }
392
+ catch (_a) { }
393
+ });
394
+ tearDownGroup.length = 0;
395
+ };
396
+ var removeByPluginName = function (pluginName) {
397
+ data[pluginName] &&
398
+ data[pluginName].forEach(function (e) {
399
+ removeTearDownGroup(e[1]);
400
+ });
401
+ data[pluginName] = undefined;
402
+ };
403
+ var removeByEvType = function (evType) {
404
+ Object.keys(data).forEach(function (k) {
405
+ data[k] &&
406
+ data[k].forEach(function (e) {
407
+ if (e[0] === evType) {
408
+ removeTearDownGroup(e[1]);
409
+ }
410
+ });
411
+ });
412
+ };
413
+ return {
414
+ /**
415
+ * register tearDownGroup for a single plugin.
416
+ */
417
+ set: function (pluginName, evType, tearDownGroup) {
418
+ if (data[pluginName])
419
+ data[pluginName].push([evType, tearDownGroup]);
420
+ else
421
+ data[pluginName] = [[evType, tearDownGroup]];
422
+ // auto remove tearDownGroup if destroyed
423
+ destroyed && removeTearDownGroup(tearDownGroup);
424
+ },
425
+ has: function (pluginName) {
426
+ return !!data[pluginName];
427
+ },
428
+ /**
429
+ * remove tearDownGroup for a single plugin.
430
+ */
431
+ remove: removeByPluginName,
432
+ /**
433
+ * remove tearDownGroup by event type
434
+ */
435
+ removeByEvType: removeByEvType,
436
+ /**
437
+ * clear all tearDownGroup
438
+ */
439
+ clear: function () {
440
+ destroyed = true;
441
+ Object.keys(data).forEach(function (k) {
442
+ removeByPluginName(k);
443
+ });
444
+ },
445
+ };
446
+ }
447
+
448
+ // max size of preStartQueue
449
+ var PRESTART_QUEUE_MAX_SIZE = 500;
450
+ // slice size to operate preStartQueue
451
+ var PRESTART_QUEUE_OP_SLICE_SIZE = 50;
452
+ function cachePreStartData(client, preStartQueue, processed) {
453
+ preStartQueue.push(processed);
454
+ if (preStartQueue.length < PRESTART_QUEUE_MAX_SIZE) {
455
+ return;
456
+ }
457
+ // delete some data to prevent OOM
458
+ var deleteData = preStartQueue.splice(0, PRESTART_QUEUE_OP_SLICE_SIZE);
459
+ if (client.savePreStartDataToDb) {
460
+ void client.savePreStartDataToDb(deleteData);
461
+ }
462
+ }
463
+ function consumePreStartData(client) {
464
+ var preStartQueue = client.getPreStartQueue();
465
+ preStartQueue.forEach(function (e) { return client.build(e); });
466
+ preStartQueue.length = 0;
467
+ }
468
+
469
+ var EVENTS = [
470
+ 'init',
471
+ 'start',
472
+ 'config',
473
+ 'beforeDestroy',
474
+ 'provide',
475
+ 'beforeReport',
476
+ 'report',
477
+ 'beforeBuild',
478
+ 'build',
479
+ 'beforeSend',
480
+ 'send',
481
+ 'beforeConfig',
482
+ ];
483
+
484
+ function createClient(creationConfig) {
485
+ var builder = creationConfig.builder, createSender = creationConfig.createSender, createDefaultConfig = creationConfig.createDefaultConfig, createConfigManager = creationConfig.createConfigManager, userConfigNormalizer = creationConfig.userConfigNormalizer, initConfigNormalizer = creationConfig.initConfigNormalizer, validateInitConfig = creationConfig.validateInitConfig;
486
+ var sender;
487
+ var configManager;
488
+ var handlers = {};
489
+ EVENTS.forEach(function (e) { return (handlers[e] = []); });
490
+ var inited = false;
491
+ var started = false;
492
+ var destroyed = false;
493
+ // 缓存 start 之前 build 的事件
494
+ var preStartQueue = [];
495
+ // 禁止通过 provide 挂载的字段名
496
+ var reservedNames = [];
497
+ var destroyAgent = createDestroyAgent();
498
+ var client = {
499
+ getBuilder: function () { return builder; },
500
+ getSender: function () { return sender; },
501
+ getPreStartQueue: function () { return preStartQueue; },
502
+ init: function (c) {
503
+ if (inited) {
504
+ warn('already inited');
505
+ return;
506
+ }
507
+ if (c && isObject(c) && validateInitConfig(c)) {
508
+ var defaultConfig = createDefaultConfig(c);
509
+ if (!defaultConfig) {
510
+ throw new Error('defaultConfig missing');
511
+ }
512
+ var initConfig = initConfigNormalizer(c);
513
+ configManager = createConfigManager(defaultConfig);
514
+ configManager.setConfig(initConfig);
515
+ configManager.onChange(function () {
516
+ handle('config');
517
+ });
518
+ sender = createSender(configManager.getConfig());
519
+ if (!sender) {
520
+ throw new Error('sender missing');
521
+ }
522
+ inited = true;
523
+ handle('init', true);
524
+ }
525
+ else {
526
+ throw new Error('invalid InitConfig, init failed');
527
+ }
528
+ },
529
+ set: function (c) {
530
+ if (!inited) {
531
+ return;
532
+ }
533
+ if (c && isObject(c)) {
534
+ handle('beforeConfig', false, c);
535
+ configManager === null || configManager === void 0 ? void 0 : configManager.setConfig(c);
536
+ }
537
+ },
538
+ config: function (c) {
539
+ if (!inited) {
540
+ return;
541
+ }
542
+ if (c && isObject(c)) {
543
+ handle('beforeConfig', false, c);
544
+ configManager === null || configManager === void 0 ? void 0 : configManager.setConfig(userConfigNormalizer(c));
545
+ }
546
+ return configManager === null || configManager === void 0 ? void 0 : configManager.getConfig();
547
+ },
548
+ provide: function (name, value) {
549
+ if (arrayIncludes(reservedNames, name)) {
550
+ warn("cannot provide " + name + ", reserved");
551
+ return;
552
+ }
553
+ client[name] = value;
554
+ handle('provide', false, name);
555
+ },
556
+ start: function () {
557
+ if (!inited) {
558
+ return;
559
+ }
560
+ if (started) {
561
+ return;
562
+ }
563
+ configManager === null || configManager === void 0 ? void 0 : configManager.onReady(function () {
564
+ started = true;
565
+ handle('start', true);
566
+ consumePreStartData(client);
567
+ });
568
+ },
569
+ report: function (data) {
570
+ if (!data) {
571
+ return;
572
+ }
573
+ var preReport = runProcessors(handlers['beforeReport'])(data);
574
+ if (!preReport) {
575
+ return;
576
+ }
577
+ var processed = runProcessors(handlers['report'])(preReport);
578
+ if (!processed) {
579
+ return;
580
+ }
581
+ if (started) {
582
+ this.build(processed);
583
+ }
584
+ else {
585
+ cachePreStartData(client, preStartQueue, processed);
586
+ }
587
+ },
588
+ build: function (data) {
589
+ if (!started) {
590
+ return;
591
+ }
592
+ var preBuild = runProcessors(handlers['beforeBuild'])(data);
593
+ if (!preBuild) {
594
+ return;
595
+ }
596
+ var built = builder.build(preBuild);
597
+ if (!built) {
598
+ return;
599
+ }
600
+ var processed = runProcessors(handlers['build'])(built);
601
+ if (!processed) {
602
+ return;
603
+ }
604
+ this.send(processed);
605
+ },
606
+ send: function (data) {
607
+ if (!started) {
608
+ return;
609
+ }
610
+ var processed = runProcessors(handlers['beforeSend'])(data);
611
+ if (processed) {
612
+ sender.send(processed);
613
+ handle('send', false, processed);
614
+ }
615
+ },
616
+ destroy: function () {
617
+ destroyAgent.clear();
618
+ destroyed = true;
619
+ preStartQueue.length = 0;
620
+ handle('beforeDestroy', true);
621
+ },
622
+ on: function (ev, handler) {
623
+ if ((ev === 'init' && inited) || (ev === 'start' && started) || (ev === 'beforeDestroy' && destroyed)) {
624
+ try {
625
+ ;
626
+ handler();
627
+ }
628
+ catch (_err) {
629
+ // ignore
630
+ }
631
+ }
632
+ else if (handlers[ev]) {
633
+ handlers[ev].push(handler);
634
+ }
635
+ },
636
+ off: function (ev, handler) {
637
+ if (handlers[ev])
638
+ handlers[ev] = arrayRemove(handlers[ev], handler);
639
+ },
640
+ destroyAgent: destroyAgent,
641
+ };
642
+ reservedNames = Object.keys(client);
643
+ return client;
644
+ function handle(ev, once) {
645
+ if (once === void 0) { once = false; }
646
+ var args = [];
647
+ for (var _i = 2; _i < arguments.length; _i++) {
648
+ args[_i - 2] = arguments[_i];
649
+ }
650
+ handlers[ev].forEach(function (f) {
651
+ try {
652
+ f.apply(void 0, __spreadArray([], __read(args), false));
653
+ }
654
+ catch (_err) {
655
+ // ignore
656
+ }
657
+ });
658
+ if (once) {
659
+ handlers[ev].length = 0;
660
+ }
661
+ }
662
+ }
663
+
664
+ var ContextPlugin = function (client) {
665
+ var contextAgent = createContextAgent();
666
+ client.provide('context', contextAgent);
667
+ client.on('report', function (ev) {
668
+ if (!ev.extra) {
669
+ ev.extra = {};
670
+ }
671
+ ev.extra.context = contextAgent.toString();
672
+ return ev;
673
+ });
674
+ };
675
+
676
+ function IntegrationPlugin(client, runAfterSetup) {
677
+ client.on('init', function () {
678
+ var nameList = [];
679
+ var applyIntegrations = function (integrations) {
680
+ integrations.forEach(function (integration) {
681
+ var integrationName = integration.name;
682
+ if (!arrayIncludes(nameList, integrationName)) {
683
+ nameList.push(integrationName);
684
+ integration.setup(client);
685
+ runAfterSetup && runAfterSetup(integrationName, integration.setup);
686
+ client.destroyAgent.set(integrationName, integrationName, [
687
+ function () {
688
+ nameList = arrayRemove(nameList, integrationName);
689
+ integration.tearDown && integration.tearDown();
690
+ },
691
+ ]);
692
+ }
693
+ });
694
+ };
695
+ client.provide('applyIntegrations', applyIntegrations);
696
+ var config = client.config();
697
+ if (config && config.integrations) {
698
+ applyIntegrations(config.integrations);
699
+ }
700
+ });
701
+ }
702
+
703
+ var DevtoolsPlugin = function (client) {
704
+ try {
705
+ if (typeof window === 'object' && isObject(window) && window.__SLARDAR_DEVTOOLS_GLOBAL_HOOK__) {
706
+ window.__SLARDAR_DEVTOOLS_GLOBAL_HOOK__.push(client);
707
+ }
708
+ }
709
+ catch (e) {
710
+ // ignore
711
+ }
712
+ };
713
+
714
+ var now = function () { return Date.now(); };
715
+
716
+ function getDefaultBrowser() {
717
+ if (typeof window === 'object' && isObject(window))
718
+ return window;
719
+ }
720
+
721
+ // 获取全局注册表
722
+ var getGlobalRegistry = function (global) {
723
+ if (!global)
724
+ return;
725
+ if (!global.__SLARDAR_REGISTRY__) {
726
+ global.__SLARDAR_REGISTRY__ = {
727
+ Slardar: {
728
+ plugins: [],
729
+ errors: [],
730
+ subject: {},
731
+ },
732
+ };
733
+ }
734
+ return global.__SLARDAR_REGISTRY__.Slardar;
735
+ };
736
+ var reportSelfError = function () {
737
+ var errorInfo = [];
738
+ for (var _i = 0; _i < arguments.length; _i++) {
739
+ errorInfo[_i] = arguments[_i];
740
+ }
741
+ var registry = getGlobalRegistry(getDefaultBrowser());
742
+ if (!registry)
743
+ return;
744
+ if (!registry.errors) {
745
+ registry.errors = [];
746
+ }
747
+ registry.errors.push(errorInfo);
748
+ };
749
+
750
+ /**
751
+ * Special support in Perfsee for analyzing call stacks of custom events and custom metrics.
752
+ */
753
+ // eslint-disable-next-line
754
+ var getStacksOnPerfsee = function (constructor) {
755
+ var _a;
756
+ // @ts-expect-error
757
+ if (typeof window !== 'object' || !window.__perfsee__) {
758
+ return;
759
+ }
760
+ var obj = {};
761
+ (_a = Error.captureStackTrace) === null || _a === void 0 ? void 0 : _a.call(Error, obj, constructor);
762
+ return obj.stack;
763
+ };
764
+
765
+ var CUSTOM_EV_TYPE = 'custom';
766
+
767
+ var CUSTOM_EVENT_TYPE = 'event';
768
+ var CUSTOM_LOG_TYPE = 'log';
769
+ var normalizeCustomEventData = function (raw) {
770
+ if (!raw || !isObject(raw)) {
771
+ return;
772
+ }
773
+ // name is required
774
+ if (!raw['name'] || !isString(raw['name'])) {
775
+ return;
776
+ }
777
+ var res = {
778
+ name: raw['name'],
779
+ type: CUSTOM_EVENT_TYPE,
780
+ };
781
+ if ('metrics' in raw && isObject(raw['metrics'])) {
782
+ var rMetrics = raw['metrics'];
783
+ var metrics = {};
784
+ for (var k in rMetrics) {
785
+ if (isNumber(rMetrics[k])) {
786
+ metrics[k] = rMetrics[k];
787
+ }
788
+ }
789
+ res.metrics = metrics;
790
+ }
791
+ if ('categories' in raw && isObject(raw['categories'])) {
792
+ var rCategories = raw['categories'];
793
+ var categories = {};
794
+ for (var k in rCategories) {
795
+ categories[k] = safeStringify(rCategories[k]);
796
+ }
797
+ res.categories = categories;
798
+ }
799
+ if ('attached_log' in raw && isString(raw['attached_log'])) {
800
+ res.attached_log = raw['attached_log'];
801
+ }
802
+ return res;
803
+ };
804
+ var normalizeCustomLogData = function (raw) {
805
+ if (!raw || !isObject(raw)) {
806
+ return;
807
+ }
808
+ // content is required
809
+ if (!raw['content'] || !isString(raw['content'])) {
810
+ return;
811
+ }
812
+ var rContent = raw['content'];
813
+ var res = {
814
+ content: safeStringify(rContent),
815
+ type: CUSTOM_LOG_TYPE,
816
+ level: 'info',
817
+ };
818
+ if ('level' in raw) {
819
+ res.level = raw['level'];
820
+ }
821
+ if ('extra' in raw && isObject(raw['extra'])) {
822
+ var rExtra = raw['extra'];
823
+ var metrics = {};
824
+ var categories = {};
825
+ for (var k in rExtra) {
826
+ if (isNumber(rExtra[k])) {
827
+ metrics[k] = rExtra[k];
828
+ }
829
+ else {
830
+ categories[k] = safeStringify(rExtra[k]);
831
+ }
832
+ }
833
+ res.metrics = metrics;
834
+ res.categories = categories;
835
+ }
836
+ if ('attached_log' in raw && isString(raw['attached_log'])) {
837
+ res.attached_log = raw['attached_log'];
838
+ }
839
+ return res;
840
+ };
841
+ var CustomPlugin = function (client) {
842
+ var sendEvent = function (data) {
843
+ var normalized = normalizeCustomEventData(data);
844
+ if (normalized) {
845
+ var stacks = getStacksOnPerfsee(sendEvent);
846
+ if (stacks) {
847
+ // @ts-expect-error
848
+ normalized.stacks = stacks;
849
+ }
850
+ client.report({
851
+ ev_type: CUSTOM_EV_TYPE,
852
+ payload: normalized,
853
+ extra: {
854
+ timestamp: now(),
855
+ },
856
+ });
857
+ }
858
+ };
859
+ var sendLog = function (data) {
860
+ var normalized = normalizeCustomLogData(data);
861
+ if (normalized) {
862
+ client.report({
863
+ ev_type: CUSTOM_EV_TYPE,
864
+ payload: normalized,
865
+ extra: {
866
+ timestamp: now(),
867
+ },
868
+ });
869
+ }
870
+ };
871
+ client.provide('sendEvent', sendEvent);
872
+ client.provide('sendLog', sendLog);
873
+ };
874
+
875
+ /* eslint-disable @typescript-eslint/prefer-for-of */
876
+ var withSampleRate = function (ev, sampleRate) {
877
+ var common = ev.common || {};
878
+ common.sample_rate = sampleRate;
879
+ ev.common = common;
880
+ return ev;
881
+ };
882
+ var hitFnWithRandom = function (preCalc, sampleRate, isHitBySampleRate, random, isHitByRandom) {
883
+ return preCalc
884
+ ? (function (h) { return function () {
885
+ return h;
886
+ }; })(isHitByRandom(random, sampleRate))
887
+ : function () { return isHitBySampleRate(sampleRate); };
888
+ };
889
+ var parseValues = function (values, type) {
890
+ return values.map(function (v) {
891
+ switch (type) {
892
+ case 'number':
893
+ return Number(v);
894
+ case 'boolean':
895
+ return v === '1';
896
+ case 'string': // default to string
897
+ default:
898
+ return String(v);
899
+ }
900
+ });
901
+ };
902
+ var checkVal = function (val, values, op) {
903
+ switch (op) {
904
+ case 'eq':
905
+ return arrayIncludes(values, val);
906
+ case 'neq':
907
+ return !arrayIncludes(values, val);
908
+ case 'gt':
909
+ return val > values[0];
910
+ case 'gte':
911
+ return val >= values[0];
912
+ case 'lt':
913
+ return val < values[0];
914
+ case 'lte':
915
+ return val <= values[0];
916
+ case 'regex':
917
+ return Boolean(val.match(new RegExp(values.join('|'))));
918
+ case 'not_regex':
919
+ return !val.match(new RegExp(values.join('|')));
920
+ default: {
921
+ // unknown op
922
+ return false;
923
+ }
924
+ }
925
+ };
926
+ var checkFilter = function (ev, field, op, values) {
927
+ var val = safeVisit(ev, field, function (t, p) {
928
+ return t[p];
929
+ });
930
+ if (val === undefined) {
931
+ return false;
932
+ }
933
+ var field_type = isBoolean(val) ? 'bool' : isNumber(val) ? 'number' : 'string';
934
+ return checkVal(val, parseValues(values, field_type), op);
935
+ };
936
+ var matchFilter = function (ev, filter) {
937
+ try {
938
+ return filter.type === 'rule'
939
+ ? checkFilter(ev, filter.field, filter.op, filter.values)
940
+ : filter.type === 'and'
941
+ ? filter.children.every(function (f) { return matchFilter(ev, f); })
942
+ : filter.children.some(function (f) { return matchFilter(ev, f); });
943
+ }
944
+ catch (e) {
945
+ reportSelfError(e);
946
+ return false;
947
+ }
948
+ };
949
+ var getHitMap = function (rules, preCalcHit, baseRate, isHitBySampleRate, random, isHitByRandom) {
950
+ var hitMap = {};
951
+ Object.keys(rules).forEach(function (name) {
952
+ var _a = rules[name], enable = _a.enable, sample_rate = _a.sample_rate, conditional_sample_rules = _a.conditional_sample_rules;
953
+ if (enable) {
954
+ hitMap[name] = {
955
+ enable: enable,
956
+ sample_rate: sample_rate,
957
+ effectiveSampleRate: sample_rate * baseRate,
958
+ hit: hitFnWithRandom(preCalcHit, sample_rate, isHitBySampleRate, random, isHitByRandom),
959
+ };
960
+ if (conditional_sample_rules) {
961
+ hitMap[name].conditional_hit_rules = conditional_sample_rules.map(function (_a) {
962
+ var s = _a.sample_rate, filter = _a.filter;
963
+ return ({
964
+ sample_rate: s,
965
+ hit: hitFnWithRandom(preCalcHit, s, isHitBySampleRate, random, isHitByRandom),
966
+ effectiveSampleRate: s * baseRate,
967
+ filter: filter,
968
+ });
969
+ });
970
+ }
971
+ }
972
+ else {
973
+ hitMap[name] = {
974
+ enable: enable,
975
+ hit: function () {
976
+ /* istanbul ignore next */
977
+ return false;
978
+ },
979
+ sample_rate: 0,
980
+ effectiveSampleRate: 0,
981
+ };
982
+ }
983
+ });
984
+ return hitMap;
985
+ };
986
+ var getSampler = function (userId, config, isHitBySampleRate, isHitByRandom, destroyFns) {
987
+ if (!config)
988
+ return id;
989
+ // r的设计是为了允许外部传入随机数,用于彻底实现按用户采样
990
+ var baseRate = config.sample_rate, include_users = config.include_users, sample_granularity = config.sample_granularity, rules = config.rules, _a = config.r, random = _a === void 0 ? Math.random() : _a;
991
+ // 用户名单采样
992
+ var userHit = arrayIncludes(include_users, userId);
993
+ if (userHit) {
994
+ return function (ev) { return withSampleRate(ev, 1); };
995
+ }
996
+ // should pre calculate hit
997
+ var preCalcHit = sample_granularity === 'session';
998
+ var baseHit = hitFnWithRandom(preCalcHit, baseRate, isHitBySampleRate, random, isHitByRandom);
999
+ var hitMap = getHitMap(rules, preCalcHit, baseRate, isHitBySampleRate, random, isHitByRandom);
1000
+ return function (ev) {
1001
+ var _a;
1002
+ // 总采样必须命中才有后续
1003
+ if (!baseHit()) {
1004
+ preCalcHit && destroyFns[0]();
1005
+ return false;
1006
+ }
1007
+ // 未配置的事件类型
1008
+ if (!(ev.ev_type in hitMap)) {
1009
+ return withSampleRate(ev, baseRate);
1010
+ }
1011
+ // 忽略未开启的事件类型
1012
+ if (!hitMap[ev.ev_type].enable) {
1013
+ preCalcHit && destroyFns[1](ev.ev_type);
1014
+ return false;
1015
+ }
1016
+ // 跳过采样配置
1017
+ if ((_a = ev.common) === null || _a === void 0 ? void 0 : _a.sample_rate) {
1018
+ return ev;
1019
+ }
1020
+ var hitConfig = hitMap[ev.ev_type];
1021
+ var conditions = hitConfig.conditional_hit_rules;
1022
+ if (conditions) {
1023
+ // 先判断条件采样
1024
+ for (var i = 0; i < conditions.length; i++) {
1025
+ if (matchFilter(ev, conditions[i].filter)) {
1026
+ if (conditions[i].hit()) {
1027
+ return withSampleRate(ev, conditions[i].effectiveSampleRate);
1028
+ }
1029
+ // 条件匹配后不再搜索
1030
+ return false;
1031
+ }
1032
+ }
1033
+ }
1034
+ // 事件类型采样
1035
+ if (!hitConfig.hit()) {
1036
+ // not hit ev_type and no condition, destroy side effect
1037
+ !(conditions && conditions.length) && preCalcHit && destroyFns[1](ev.ev_type);
1038
+ return false;
1039
+ }
1040
+ // 事件类型默认采样已经命中
1041
+ return withSampleRate(ev, hitConfig.effectiveSampleRate);
1042
+ };
1043
+ };
1044
+ var SamplePlugin = function (client) {
1045
+ client.on('start', function () {
1046
+ var _a = client.config(), userId = _a.userId, sample = _a.sample;
1047
+ var destroyFns = [
1048
+ function () {
1049
+ client.destroy();
1050
+ },
1051
+ function (ev_type) {
1052
+ client.destroyAgent.removeByEvType(ev_type);
1053
+ },
1054
+ ];
1055
+ var sampler = getSampler(userId, sample, isHitBySampleRate, isHitByRandom, destroyFns);
1056
+ client.on('build', sampler);
1057
+ });
1058
+ };
1059
+
1060
+ var builder = {
1061
+ build: function (e) {
1062
+ return {
1063
+ ev_type: e.ev_type,
1064
+ payload: e.payload,
1065
+ common: __assign(__assign({}, (e.extra || {})), (e.overrides || {})),
1066
+ };
1067
+ },
1068
+ };
1069
+
1070
+ var REPORT_DOMAIN = "mon.zijieapi.com";
1071
+ var SETTINGS_DOMAIN = REPORT_DOMAIN;
1072
+ var SDK_VERSION = "2.1.8" ;
1073
+ var SDK_NAME = 'SDK_BASE';
1074
+ var SETTINGS_PATH = '/monitor_web/settings/browser-settings';
1075
+ var BATCH_REPORT_PATH = "/monitor_browser/collect/batch/";
1076
+ var DEFAULT_SAMPLE_CONFIG = {
1077
+ sample_rate: 1,
1078
+ include_users: [],
1079
+ sample_granularity: 'session',
1080
+ rules: {},
1081
+ };
1082
+ var DEFAULT_SENDER_SIZE = 20;
1083
+ var DEFAULT_SAMPLE_GRANULARITY = 'session';
1084
+
1085
+ function normalizeStrictFields(config) {
1086
+ var e_1, _a;
1087
+ var strictFields = ['userId', 'deviceId', 'sessionId', 'env'];
1088
+ try {
1089
+ for (var strictFields_1 = __values(strictFields), strictFields_1_1 = strictFields_1.next(); !strictFields_1_1.done; strictFields_1_1 = strictFields_1.next()) {
1090
+ var k = strictFields_1_1.value;
1091
+ if (!config[k]) {
1092
+ delete config[k];
1093
+ }
1094
+ }
1095
+ }
1096
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1097
+ finally {
1098
+ try {
1099
+ if (strictFields_1_1 && !strictFields_1_1.done && (_a = strictFields_1.return)) _a.call(strictFields_1);
1100
+ }
1101
+ finally { if (e_1) throw e_1.error; }
1102
+ }
1103
+ return config;
1104
+ }
1105
+ function normalizeInitConfig(config) {
1106
+ return normalizeStrictFields(__assign({}, config));
1107
+ }
1108
+ function validateInitConfig(config) {
1109
+ return isObject(config) && 'bid' in config && 'transport' in config;
1110
+ }
1111
+ function normalizeUserConfig(config) {
1112
+ return normalizeStrictFields(__assign({}, config));
1113
+ }
1114
+ function parseServerConfig(serverConfig) {
1115
+ if (!serverConfig) {
1116
+ return {};
1117
+ }
1118
+ var sample = serverConfig.sample, timestamp = serverConfig.timestamp, _a = serverConfig.quota_rate, quota_rate = _a === void 0 ? 1 : _a;
1119
+ if (!sample) {
1120
+ return {};
1121
+ }
1122
+ var sample_rate = sample.sample_rate, _b = sample.sample_granularity, sample_granularity = _b === void 0 ? DEFAULT_SAMPLE_GRANULARITY : _b, include_users = sample.include_users, _c = sample.rules, rules = _c === void 0 ? [] : _c;
1123
+ return {
1124
+ sample: {
1125
+ include_users: include_users,
1126
+ sample_rate: sample_rate * quota_rate,
1127
+ sample_granularity: sample_granularity,
1128
+ rules: rules.reduce(function (prev, cur) {
1129
+ var name = cur.name, enable = cur.enable, sample_rate = cur.sample_rate, conditional_sample_rules = cur.conditional_sample_rules;
1130
+ prev[name] = {
1131
+ enable: enable,
1132
+ sample_rate: sample_rate,
1133
+ conditional_sample_rules: conditional_sample_rules,
1134
+ };
1135
+ return prev;
1136
+ }, {}),
1137
+ },
1138
+ serverTimestamp: timestamp,
1139
+ };
1140
+ }
1141
+
1142
+ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
1143
+ var getReportUrl = function (domain, path) {
1144
+ if (path === void 0) { path = BATCH_REPORT_PATH; }
1145
+ return "" + (domain && domain.indexOf('//') >= 0 ? '' : 'https://') + domain + path;
1146
+ };
1147
+ var getSettingsUrl = function (domain, path) {
1148
+ if (path === void 0) { path = SETTINGS_PATH; }
1149
+ return "" + (domain && domain.indexOf('//') >= 0 ? '' : 'https://') + domain + path;
1150
+ };
1151
+ var getDefaultUserId = function () {
1152
+ return uuid();
1153
+ };
1154
+ var getDefaultDeviceId = function () {
1155
+ return uuid();
1156
+ };
1157
+ var getViewId = function (pid) { return pid + "_" + Date.now(); };
1158
+ var getDefaultSessionId = function () {
1159
+ return uuid();
1160
+ };
1161
+
1162
+ var createConfigManager = function (defaultConfig) {
1163
+ // the merged config
1164
+ var config = defaultConfig;
1165
+ // save it so we know when initConfig is set
1166
+ var initConfig;
1167
+ // save UserConfig so we can merge with priority
1168
+ var userConfig = {};
1169
+ // save the original server config, from get_setting response
1170
+ var serverConfig;
1171
+ // cache the parsed ServerConfig, used in merge
1172
+ var parsedServerConfig;
1173
+ var onReady = noop;
1174
+ // call when config changed
1175
+ var onChange = noop;
1176
+ return {
1177
+ getConfig: function () {
1178
+ return config;
1179
+ },
1180
+ setConfig: function (c) {
1181
+ userConfig = __assign(__assign({}, userConfig), (c || {}));
1182
+ updateConfig();
1183
+ if (!initConfig) {
1184
+ // handle init
1185
+ initConfig = c;
1186
+ if (config.useLocalConfig || !config.bid) {
1187
+ parsedServerConfig = {};
1188
+ onReady();
1189
+ }
1190
+ else {
1191
+ getServerConfig(config.transport, config.domain, config.bid, function (res) {
1192
+ serverConfig = res;
1193
+ handleServerConfig();
1194
+ });
1195
+ }
1196
+ }
1197
+ return config;
1198
+ },
1199
+ onChange: function (fn) {
1200
+ onChange = fn;
1201
+ },
1202
+ onReady: function (fn) {
1203
+ onReady = fn;
1204
+ if (parsedServerConfig) {
1205
+ onReady();
1206
+ }
1207
+ },
1208
+ };
1209
+ function updateConfig() {
1210
+ var newConfig = __assign(__assign(__assign({}, defaultConfig), (parsedServerConfig || {})), userConfig);
1211
+ newConfig.sample = mergeSampleConfig(mergeSampleConfig(defaultConfig.sample, parsedServerConfig === null || parsedServerConfig === void 0 ? void 0 : parsedServerConfig.sample), userConfig.sample);
1212
+ config = newConfig;
1213
+ onChange();
1214
+ }
1215
+ function handleServerConfig() {
1216
+ parsedServerConfig = parseServerConfig(serverConfig);
1217
+ updateConfig();
1218
+ onReady();
1219
+ }
1220
+ };
1221
+ function getServerConfig(transport, domain, bid, cb) {
1222
+ if (!transport.get) {
1223
+ return cb({});
1224
+ }
1225
+ transport.get({
1226
+ withCredentials: true,
1227
+ url: getSettingsUrl(domain) + "?bid=" + bid + "&store=1",
1228
+ success: function (res) {
1229
+ cb(res.data || {});
1230
+ },
1231
+ fail: function () {
1232
+ cb({ sample: { sample_rate: 0.001 } });
1233
+ },
1234
+ });
1235
+ }
1236
+ function mergeSampleConfig(a, b) {
1237
+ if (!a || !b)
1238
+ return a || b;
1239
+ var res = __assign(__assign({}, a), b);
1240
+ res.include_users = __spreadArray(__spreadArray([], __read((a.include_users || [])), false), __read((b.include_users || [])), false);
1241
+ res.rules = __spreadArray(__spreadArray([], __read(Object.keys(a.rules || {})), false), __read(Object.keys(b.rules || {})), false).reduce(function (obj, key) {
1242
+ var _a, _b;
1243
+ if (!(key in obj)) {
1244
+ if (key in (a.rules || {}) && key in (b.rules || {})) {
1245
+ obj[key] = __assign(__assign({}, a.rules[key]), b.rules[key]);
1246
+ obj[key].conditional_sample_rules = __spreadArray(__spreadArray([], __read((a.rules[key].conditional_sample_rules || [])), false), __read((b.rules[key].conditional_sample_rules || [])), false);
1247
+ }
1248
+ else {
1249
+ obj[key] = ((_a = a.rules) === null || _a === void 0 ? void 0 : _a[key]) || ((_b = b.rules) === null || _b === void 0 ? void 0 : _b[key]);
1250
+ }
1251
+ }
1252
+ return obj;
1253
+ }, {});
1254
+ return res;
1255
+ }
1256
+
1257
+ var addEnvToSendEvent = function (ev, config) {
1258
+ var _a = config || {}, version = _a.version, name = _a.name;
1259
+ var extra = {
1260
+ url: '',
1261
+ protocol: '',
1262
+ domain: '',
1263
+ path: '',
1264
+ query: '',
1265
+ timestamp: Date.now(),
1266
+ sdk_version: version || SDK_VERSION,
1267
+ sdk_name: name || SDK_NAME,
1268
+ };
1269
+ return __assign(__assign({}, ev), { extra: __assign(__assign({}, extra), (ev.extra || {})) });
1270
+ };
1271
+ var InjectEnvPlugin = function (client) {
1272
+ client.on('report', function (ev) {
1273
+ return addEnvToSendEvent(ev, client.config());
1274
+ });
1275
+ };
1276
+
1277
+ var addConfigToReportEvent = function (ev, config) {
1278
+ var extra = {};
1279
+ extra.bid = config.bid;
1280
+ extra.pid = config.pid;
1281
+ extra.view_id = config.viewId;
1282
+ extra.user_id = config.userId;
1283
+ extra.device_id = config.deviceId;
1284
+ extra.session_id = config.sessionId;
1285
+ extra.release = config.release;
1286
+ extra.env = config.env;
1287
+ return __assign(__assign({}, ev), { extra: __assign(__assign({}, extra), (ev.extra || {})) });
1288
+ };
1289
+ var InjectConfigPlugin = function (client) {
1290
+ client.on('beforeBuild', function (ev) {
1291
+ return addConfigToReportEvent(ev, client.config());
1292
+ });
1293
+ };
1294
+
1295
+ // createSender has side effects(register onClose behaviour)
1296
+ // so it must be create lazily
1297
+ function createSender(config) {
1298
+ return createBatchSender(config);
1299
+ }
1300
+
1301
+ /* eslint-disable @typescript-eslint/prefer-nullish-coalescing */
1302
+ var getDefaultConfig = function (_c) { return ({
1303
+ bid: '',
1304
+ pid: '',
1305
+ viewId: getViewId('_'),
1306
+ userId: getDefaultUserId(),
1307
+ deviceId: getDefaultDeviceId(),
1308
+ sessionId: getDefaultSessionId(),
1309
+ domain: REPORT_DOMAIN,
1310
+ release: '',
1311
+ env: 'production',
1312
+ sample: DEFAULT_SAMPLE_CONFIG,
1313
+ plugins: {},
1314
+ transport: {
1315
+ get: noop,
1316
+ post: noop,
1317
+ },
1318
+ useLocalConfig: false,
1319
+ }); };
1320
+ var createMinimalClient = function (_a) {
1321
+ var _b = _a === void 0 ? {} : _a, _d = _b.createSender, createSender$1 = _d === void 0 ? function (config) {
1322
+ return createSender({
1323
+ size: DEFAULT_SENDER_SIZE,
1324
+ endpoint: getReportUrl(config.domain),
1325
+ transport: config.transport,
1326
+ });
1327
+ } : _d, _e = _b.builder, builder$1 = _e === void 0 ? builder : _e, _f = _b.createDefaultConfig, createDefaultConfig = _f === void 0 ? getDefaultConfig : _f;
1328
+ var client = createClient({
1329
+ validateInitConfig: validateInitConfig,
1330
+ initConfigNormalizer: normalizeInitConfig,
1331
+ userConfigNormalizer: normalizeUserConfig,
1332
+ createSender: createSender$1,
1333
+ builder: builder$1,
1334
+ createDefaultConfig: createDefaultConfig,
1335
+ createConfigManager: createConfigManager,
1336
+ });
1337
+ ContextPlugin(client);
1338
+ InjectConfigPlugin(client);
1339
+ InjectEnvPlugin(client);
1340
+ IntegrationPlugin(client);
1341
+ DevtoolsPlugin(client);
1342
+ return client;
1343
+ };
1344
+ var createBaseClient = function (config) {
1345
+ if (config === void 0) { config = {}; }
1346
+ var client = createMinimalClient(config);
1347
+ SamplePlugin(client);
1348
+ CustomPlugin(client);
1349
+ return client;
1350
+ };
1351
+
1352
+ var browserClient = createBaseClient();
1353
+
1354
+ /**
1355
+ * compat module entry
1356
+ */
1357
+
1358
+ export { BATCH_REPORT_PATH, CustomPlugin, DEFAULT_SAMPLE_CONFIG, DEFAULT_SAMPLE_GRANULARITY, DEFAULT_SENDER_SIZE, InjectConfigPlugin, InjectEnvPlugin, REPORT_DOMAIN, SDK_NAME, SDK_VERSION, SETTINGS_DOMAIN, SETTINGS_PATH, addConfigToReportEvent, addEnvToSendEvent, builder, createBaseClient, createConfigManager, createMinimalClient, browserClient as default, getDefaultConfig, getDefaultDeviceId, getDefaultSessionId, getDefaultUserId, getReportUrl, getServerConfig, getSettingsUrl, getViewId, mergeSampleConfig, normalizeInitConfig, normalizeStrictFields, normalizeUserConfig, parseServerConfig, validateInitConfig };