-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy pathutility.js
More file actions
975 lines (890 loc) · 22.2 KB
/
Copy pathutility.js
File metadata and controls
975 lines (890 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
/*
* isType - Given a Javascript value and a string, returns true if the type of the value matches the
* given string.
*
* @param x - any value
* @param t - a lowercase string containing one of the following type names:
* - undefined
* - null
* - error
* - number
* - boolean
* - string
* - symbol
* - function
* - object
* - array
* @returns true if x is of type t, otherwise false
*/
function isType(x, t) {
return t === typeName(x);
}
/*
* typeName - Given a Javascript value, returns the type of the object as a string
*/
function typeName(x) {
var name = typeof x;
if (name !== 'object') {
return name;
}
if (!x) {
return 'null';
}
if (x instanceof Error) {
return 'error';
}
return {}.toString
.call(x)
.match(/\s([a-zA-Z]+)/)[1]
.toLowerCase();
}
/* isFunction - a convenience function for checking if a value is a function
*
* @param f - any value
* @returns true if f is a function, otherwise false
*/
function isFunction(f) {
return isType(f, 'function');
}
/* isNativeFunction - a convenience function for checking if a value is a native JS function
*
* @param f - any value
* @returns true if f is a native JS function, otherwise false
*/
function isNativeFunction(f) {
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
var funcMatchString = Function.prototype.toString
.call(Object.prototype.hasOwnProperty)
.replace(reRegExpChar, '\\$&')
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?');
var reIsNative = RegExp('^' + funcMatchString + '$');
return isObject(f) && reIsNative.test(f);
}
/* isObject - Checks if the argument is an object
*
* @param value - any value
* @returns true is value is an object function is an object)
*/
function isObject(value) {
return (
value != null && (typeof value == 'object' || typeof value == 'function')
);
}
/* hasOwn - safe helper around Object.hasOwnProperty */
function hasOwn(obj, prop) {
if (obj == null) {
return false;
}
if (Object.hasOwn) {
return Object.hasOwn(obj, prop);
}
return Object.prototype.hasOwnProperty.call(obj, prop);
}
/* isString - Checks if the argument is a string
*
* @param value - any value
* @returns true if value is a string
*/
function isString(value) {
return typeof value === 'string' || value instanceof String;
}
/**
* isFiniteNumber - determines whether the passed value is a finite number
*
* @param {*} n - any value
* @returns true if value is a finite number
*/
function isFiniteNumber(n) {
return Number.isFinite(n);
}
/*
* isIterable - convenience function for checking if a value can be iterated, essentially
* whether it is an object or an array.
*
* @param i - any value
* @returns true if i is an object or an array as determined by `typeName`
*/
function isIterable(i) {
var type = typeName(i);
return type === 'object' || type === 'array';
}
/*
* isError - convenience function for checking if a value is of an error type
*
* @param e - any value
* @returns true if e is an error
*/
function isError(e) {
// Detect both Error and Firefox Exception type
return isType(e, 'error') || isType(e, 'exception');
}
/* isPromise - a convenience function for checking if a value is a promise
*
* @param p - any value
* @returns true if f is a function, otherwise false
*/
function isPromise(p) {
return isObject(p) && isType(p.then, 'function');
}
/**
* isBrowser - a convenience function for checking if the code is running in a browser
*
* @returns true if the code is running in a browser environment
*/
function isBrowser() {
return typeof window !== 'undefined';
}
function isRequestObject(input) {
return typeof Request !== 'undefined' && input instanceof Request;
}
function redact() {
return '********';
}
// from http://stackoverflow.com/a/8809472/1138191
function uuid4() {
var d = now();
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
/[xy]/g,
function (c) {
var r = ((d + Math.random() * 16) % 16) | 0;
d = Math.floor(d / 16);
return (c === 'x' ? r : (r & 0x7) | 0x8).toString(16);
},
);
return uuid;
}
var LEVELS = {
debug: 0,
info: 1,
warning: 2,
error: 3,
critical: 4,
};
function sanitizeHref(url) {
try {
const urlObject = new URL(url);
if (urlObject.password) {
urlObject.password = redact();
}
if (urlObject.search) {
urlObject.search = redact();
}
return urlObject.toString();
} catch (_) {
return url; // Return original URL if parsing fails
}
}
function sanitizeUrl(url) {
var baseUrlParts = parseUri(url);
if (!baseUrlParts) {
return '(unknown)';
}
// remove a trailing # if there is no anchor
if (baseUrlParts.anchor === '') {
baseUrlParts.source = baseUrlParts.source.replace('#', '');
}
url = baseUrlParts.source.replace('?' + baseUrlParts.query, '');
return url;
}
var parseUriOptions = {
strictMode: false,
key: [
'source',
'protocol',
'authority',
'userInfo',
'user',
'password',
'host',
'port',
'relative',
'path',
'directory',
'file',
'query',
'anchor',
],
q: {
name: 'queryKey',
parser: /(?:^|&)([^&=]*)=?([^&]*)/g,
},
parser: {
strict:
/^(?:([^:/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?))?((((?:[^?#/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose:
/^(?:(?![^:@]+:[^:@/]*@)([^:/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#/]*\.[^?#/.]+(?:[?#]|$)))*\/?)?([^?#/]*))(?:\?([^#]*))?(?:#(.*))?)/,
},
};
function parseUri(str) {
if (!isType(str, 'string')) {
return undefined;
}
var o = parseUriOptions;
var m = o.parser[o.strictMode ? 'strict' : 'loose'].exec(str);
var uri = {};
for (var i = 0, l = o.key.length; i < l; ++i) {
uri[o.key[i]] = m[i] || '';
}
uri[o.q.name] = {};
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
if ($1) {
uri[o.q.name][$1] = $2;
}
});
return uri;
}
function addParamsAndAccessTokenToPath(accessToken, options, params) {
params = params || {};
params.access_token = accessToken;
var paramsArray = [];
var k;
for (k in params) {
if (Object.prototype.hasOwnProperty.call(params, k)) {
paramsArray.push([k, params[k]].join('='));
}
}
var query = '?' + paramsArray.sort().join('&');
options = options || {};
options.path = options.path || '';
var qs = options.path.indexOf('?');
var h = options.path.indexOf('#');
var p;
if (qs !== -1 && (h === -1 || h > qs)) {
p = options.path;
options.path = p.substring(0, qs) + query + '&' + p.substring(qs + 1);
} else {
if (h !== -1) {
p = options.path;
options.path = p.substring(0, h) + query + p.substring(h);
} else {
options.path = options.path + query;
}
}
}
function formatUrl(u, protocol) {
protocol = protocol || u.protocol;
if (!protocol && u.port) {
if (u.port === 80) {
protocol = 'http:';
} else if (u.port === 443) {
protocol = 'https:';
}
}
protocol = protocol || 'https:';
if (!u.hostname) {
return null;
}
var result = protocol + '//' + u.hostname;
if (u.port) {
result = result + ':' + u.port;
}
if (u.path) {
result = result + u.path;
}
return result;
}
function stringify(obj, backup) {
var value, error;
try {
value = JSON.stringify(obj);
} catch (jsonError) {
if (backup && isFunction(backup)) {
try {
value = backup(obj);
} catch (backupError) {
error = backupError;
}
} else {
error = jsonError;
}
}
return { error: error, value: value };
}
function maxByteSize(string) {
// The transport will use utf-8, so assume utf-8 encoding.
//
// This minimal implementation will accurately count bytes for all UCS-2 and
// single code point UTF-16. If presented with multi code point UTF-16,
// which should be rare, it will safely overcount, not undercount.
//
// While robust utf-8 encoders exist, this is far smaller and far more performant.
// For quickly counting payload size for truncation, smaller is better.
var count = 0;
var length = string.length;
for (var i = 0; i < length; i++) {
var code = string.charCodeAt(i);
if (code < 128) {
// up to 7 bits
count = count + 1;
} else if (code < 2048) {
// up to 11 bits
count = count + 2;
} else if (code < 65536) {
// up to 16 bits
count = count + 3;
}
}
return count;
}
function jsonParse(s) {
var value, error;
try {
value = JSON.parse(s);
} catch (e) {
error = e;
}
return { error, value };
}
function makeUnhandledStackInfo(
message,
url,
lineno,
colno,
error,
mode,
backupMessage,
errorParser,
) {
var location = {
url: url || '',
line: lineno,
column: colno,
};
location.func = errorParser.guessFunctionName(location.url, location.line);
location.context = errorParser.gatherContext(location.url, location.line);
var href =
typeof document !== 'undefined' &&
document &&
document.location &&
document.location.href;
var useragent =
typeof window !== 'undefined' &&
window &&
window.navigator &&
window.navigator.userAgent;
return {
mode: mode,
message: error ? String(error) : message || backupMessage,
url: href,
stack: [location],
useragent: useragent,
};
}
function wrapCallback(logger, f) {
return function (err, resp) {
try {
f(err, resp);
} catch (e) {
logger.error(e);
}
};
}
function nonCircularClone(obj) {
var seen = [obj];
function clone(obj, seen) {
var value,
name,
newSeen,
result = {};
try {
for (name in obj) {
value = obj[name];
if (value && (isType(value, 'object') || isType(value, 'array'))) {
if (seen.includes(value)) {
result[name] = 'Removed circular reference: ' + typeName(value);
} else {
newSeen = seen.slice();
newSeen.push(value);
result[name] = clone(value, newSeen);
}
continue;
}
result[name] = value;
}
} catch (e) {
result = 'Failed cloning custom data: ' + e.message;
}
return result;
}
return clone(obj, seen);
}
function createItem(args, logger, notifier, requestKeys, lambdaContext) {
var message, err, custom, callback, request;
var arg;
var extraArgs = [];
var diagnostic = {};
var argTypes = [];
for (var i = 0, l = args.length; i < l; ++i) {
arg = args[i];
var typ = typeName(arg);
argTypes.push(typ);
switch (typ) {
case 'undefined':
break;
case 'string':
if (message) {
extraArgs.push(arg);
} else {
message = arg;
}
break;
case 'function':
callback = wrapCallback(logger, arg);
break;
case 'date':
extraArgs.push(arg);
break;
case 'error':
case 'domexception':
case 'exception': // Firefox Exception type
if (err) {
extraArgs.push(arg);
} else {
err = arg;
}
break;
case 'object':
case 'array':
if (
arg instanceof Error ||
(typeof DOMException !== 'undefined' && arg instanceof DOMException)
) {
if (err) {
extraArgs.push(arg);
} else {
err = arg;
}
break;
}
if (requestKeys && typ === 'object' && !request) {
for (var j = 0, len = requestKeys.length; j < len; ++j) {
if (arg[requestKeys[j]] !== undefined) {
request = arg;
break;
}
}
if (request) {
break;
}
}
if (custom) {
extraArgs.push(arg);
} else {
custom = arg;
}
break;
default:
if (
arg instanceof Error ||
(typeof DOMException !== 'undefined' && arg instanceof DOMException)
) {
if (err) {
extraArgs.push(arg);
} else {
err = arg;
}
break;
}
extraArgs.push(arg);
}
}
// if custom is an array this turns it into an object with integer keys
if (custom) custom = nonCircularClone(custom);
if (extraArgs.length > 0) {
if (!custom) custom = nonCircularClone({});
custom.extraArgs = nonCircularClone(extraArgs);
}
var item = {
message: message,
err: err,
custom: custom,
timestamp: now(),
callback: callback,
notifier: notifier,
diagnostic: diagnostic,
uuid: uuid4(),
};
item.data = item.data || {};
setCustomItemKeys(item, custom);
if (requestKeys && request) {
item.request = request;
}
if (lambdaContext) {
item.lambdaContext = lambdaContext;
}
item._originalArgs = args;
item.diagnostic.original_arg_types = argTypes;
return item;
}
function setCustomItemKeys(item, custom) {
if (custom && custom.level !== undefined) {
item.level = custom.level;
delete custom.level;
}
if (custom && custom.skipFrames !== undefined) {
item.skipFrames = custom.skipFrames;
delete custom.skipFrames;
}
}
function addErrorContext(item, errors) {
var custom = item.data.custom || {};
var contextAdded = false;
try {
for (const error of errors) {
if (hasOwn(error, 'rollbarContext')) {
custom = merge(custom, nonCircularClone(error.rollbarContext));
contextAdded = true;
}
}
// Avoid adding an empty object to the data.
if (contextAdded) {
item.data.custom = custom;
}
} catch (e) {
item.diagnostic.error_context = 'Failed: ' + e.message;
}
}
var TELEMETRY_TYPES = [
'log',
'network',
'dom',
'navigation',
'error',
'manual',
];
var TELEMETRY_LEVELS = ['critical', 'error', 'warning', 'info', 'debug'];
function arrayIncludes(arr, val) {
for (const entry of arr) {
if (entry === val) {
return true;
}
}
return false;
}
function createTelemetryEvent(args) {
var type, metadata, level;
var arg;
for (var i = 0, l = args.length; i < l; ++i) {
arg = args[i];
var typ = typeName(arg);
switch (typ) {
case 'string':
if (!type && arrayIncludes(TELEMETRY_TYPES, arg)) {
type = arg;
} else if (!level && arrayIncludes(TELEMETRY_LEVELS, arg)) {
level = arg;
}
break;
case 'object':
metadata = arg;
break;
default:
break;
}
}
var event = {
type: type || 'manual',
metadata: metadata || {},
level: level,
};
return event;
}
function addItemAttributes(itemData, attributes) {
itemData.attributes = itemData.attributes || [];
for (const a of attributes) {
if (a.value === undefined) {
continue;
}
itemData.attributes.push(a);
}
}
/*
* get - given an obj/array and a keypath, return the value at that keypath or
* undefined if not possible.
*
* @param obj - an object or array
* @param path - a string of keys separated by '.' such as 'plugin.jquery.0.message'
* which would correspond to 42 in `{plugin: {jquery: [{message: 42}]}}`
*/
function get(obj, path) {
if (!obj) {
return undefined;
}
var keys = path.split('.');
var result = obj;
try {
for (var i = 0, len = keys.length; i < len; ++i) {
result = result[keys[i]];
}
} catch (_e) {
result = undefined;
}
return result;
}
function set(obj, path, value) {
if (!obj) {
return;
}
// Prevent prototype pollution by setting the prototype to null.
Object.setPrototypeOf(obj, null);
var keys = path.split('.');
var len = keys.length;
if (len < 1) {
return;
}
if (len === 1) {
obj[keys[0]] = value;
return;
}
try {
var temp = obj[keys[0]] || {};
var replacement = temp;
for (var i = 1; i < len - 1; ++i) {
temp[keys[i]] = temp[keys[i]] || {};
temp = temp[keys[i]];
}
temp[keys[len - 1]] = value;
obj[keys[0]] = replacement;
} catch (_e) {
return;
}
}
function formatArgsAsString(args) {
var i, len, arg;
var result = [];
for (i = 0, len = args.length; i < len; ++i) {
arg = args[i];
switch (typeName(arg)) {
case 'object':
arg = stringify(arg);
arg = arg.error || arg.value;
if (arg.length > 500) {
arg = arg.substr(0, 497) + '...';
}
break;
case 'null':
arg = 'null';
break;
case 'undefined':
arg = 'undefined';
break;
case 'symbol':
arg = arg.toString();
break;
}
result.push(arg);
}
return result.join(' ');
}
function now() {
if (Date.now) {
return Date.now();
}
return Number(new Date());
}
function filterIp(requestData, captureIp) {
if (!requestData || !requestData['user_ip'] || captureIp === true) {
return;
}
var newIp = requestData['user_ip'];
if (!captureIp) {
newIp = null;
} else {
try {
var parts;
if (newIp.indexOf('.') !== -1) {
parts = newIp.split('.');
parts.pop();
parts.push('0');
newIp = parts.join('.');
} else if (newIp.indexOf(':') !== -1) {
parts = newIp.split(':');
if (parts.length > 2) {
var beginning = parts.slice(0, 3);
var slashIdx = beginning[2].indexOf('/');
if (slashIdx !== -1) {
beginning[2] = beginning[2].substring(0, slashIdx);
}
var terminal = '0000:0000:0000:0000:0000';
newIp = beginning.concat(terminal).join(':');
}
} else {
newIp = null;
}
} catch (_e) {
newIp = null;
}
}
requestData['user_ip'] = newIp;
}
function handleOptions(current, input, payload, logger) {
var result = merge(current, input, payload);
result = updateDeprecatedOptions(result, logger);
if (!input || input.overwriteScrubFields) {
return result;
}
if (input.scrubFields) {
result.scrubFields = (current.scrubFields || []).concat(input.scrubFields);
}
return result;
}
function updateDeprecatedOptions(options, logger) {
if (options.hostWhiteList && !options.hostSafeList) {
options.hostSafeList = options.hostWhiteList;
options.hostWhiteList = undefined;
logger && logger.log('hostWhiteList is deprecated. Use hostSafeList.');
}
if (options.hostBlackList && !options.hostBlockList) {
options.hostBlockList = options.hostBlackList;
options.hostBlackList = undefined;
logger && logger.log('hostBlackList is deprecated. Use hostBlockList.');
}
return options;
}
function merge() {
function isPlainObject(obj) {
if (!obj || Object.prototype.toString.call(obj) !== '[object Object]') {
return false;
}
var hasOwnConstructor = hasOwn(obj, 'constructor');
var hasIsPrototypeOf =
obj.constructor &&
obj.constructor.prototype &&
hasOwn(obj.constructor.prototype, 'isPrototypeOf');
// Not own constructor property must be Object
if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
return false;
}
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
var key;
for (key in obj) {
/**/
}
return typeof key === 'undefined' || hasOwn(obj, key);
}
var i,
src,
copy,
clone,
name,
result = Object.create(null), // no prototype pollution on Object
current = null,
length = arguments.length;
for (i = 0; i < length; i++) {
current = arguments[i];
if (current === null || current === undefined) {
continue;
}
for (name in current) {
src = result[name];
copy = current[name];
if (result !== copy) {
if (copy && isPlainObject(copy)) {
clone = src && isPlainObject(src) ? src : {};
result[name] = merge(clone, copy);
} else if (typeof copy !== 'undefined') {
result[name] = copy;
}
}
}
}
return result;
}
function shouldAddBaggageHeader(options, tracing, url) {
if (!tracing?.sessionId || !url) {
return false;
}
const propagation = options?.tracing?.propagation;
const enabledHeaders = propagation?.enabledHeaders;
if (!Array.isArray(enabledHeaders) || !enabledHeaders.includes('baggage')) {
return false;
}
const enabledCorsUrls = propagation?.enabledCorsUrls;
if (!Array.isArray(enabledCorsUrls) || enabledCorsUrls.length === 0) {
return false;
}
return enabledCorsUrls.some((pattern) => {
if (isType(pattern, 'string')) {
return url === pattern;
}
if (isType(pattern, 'regexp')) {
return pattern.test(url);
}
return false;
});
}
function addHeadersToFetch(args, newHeaders) {
// Headers may be in the request object or the init object.
// If present in both places, the init object must be used.
//
let init = args[1];
const initHeaders = init?.headers;
const reqHeaders = isRequestObject(args[0]) && args[0].headers;
let headers = initHeaders || reqHeaders;
// If headers are not present in either place, they are added to the init object.
// If there is no init object, one must be created and added to args.
if (!headers) {
if (!init) {
args[1] = init = {};
}
headers = init.headers = {};
}
// `headers` may be a Headers object or a plain object.
if (headers instanceof Headers) {
for (const key of Object.keys(newHeaders)) {
headers.append(key, newHeaders[key]);
}
} else if (isObject(headers)) {
for (const key of Object.keys(newHeaders)) {
headers[key] = newHeaders[key];
}
}
}
function getSessionIdFromAsyncLocalStorage(client) {
const storage = client.asyncLocalStorage;
if (!storage || typeof storage.getStore !== 'function') {
return null;
}
const store = storage.getStore();
return store?.sessionId || null;
}
export {
addParamsAndAccessTokenToPath,
createItem,
addErrorContext,
createTelemetryEvent,
addItemAttributes,
filterIp,
formatArgsAsString,
formatUrl,
get,
handleOptions,
isError,
isFiniteNumber,
isFunction,
hasOwn,
isIterable,
isNativeFunction,
isObject,
isString,
isType,
isPromise,
isBrowser,
jsonParse,
LEVELS,
makeUnhandledStackInfo,
merge,
now,
redact,
sanitizeHref,
sanitizeUrl,
set,
stringify,
maxByteSize,
typeName,
uuid4,
shouldAddBaggageHeader,
addHeadersToFetch,
getSessionIdFromAsyncLocalStorage,
};