@adaptic/lumic-utils 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +637 -0
  2. package/dist/index-CcXQeJz8.js +1477 -0
  3. package/dist/index-CcXQeJz8.js.map +1 -0
  4. package/dist/index-CcgbRft2.js +1479 -0
  5. package/dist/index-CcgbRft2.js.map +1 -0
  6. package/dist/index.cjs +11420 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.mjs +11400 -0
  9. package/dist/index.mjs.map +1 -0
  10. package/dist/test.cjs +1119 -0
  11. package/dist/test.cjs.map +1 -0
  12. package/dist/test.mjs +1117 -0
  13. package/dist/test.mjs.map +1 -0
  14. package/dist/types/aws-types.ts +64 -0
  15. package/dist/types/functions/aws-lambda.d.ts +17 -0
  16. package/dist/types/functions/aws-s3-utils.d.ts +118 -0
  17. package/dist/types/functions/get-weather.d.ts +10 -0
  18. package/dist/types/functions/google-sheets.d.ts +40 -0
  19. package/dist/types/functions/json-llm-tools.d.ts +12 -0
  20. package/dist/types/functions/json-tools.d.ts +16 -0
  21. package/dist/types/functions/llm-call.d.ts +29 -0
  22. package/dist/types/functions/llm-config.d.ts +34 -0
  23. package/dist/types/functions/llm-deepseek.d.ts +11 -0
  24. package/dist/types/functions/llm-images.d.ts +48 -0
  25. package/dist/types/functions/llm-openai.d.ts +55 -0
  26. package/dist/types/functions/llm-utils.d.ts +15 -0
  27. package/dist/types/functions/pdf-create.d.ts +2 -0
  28. package/dist/types/functions/performance.d.ts +72 -0
  29. package/dist/types/functions/perplexity-api.d.ts +1 -0
  30. package/dist/types/functions/slack-utils.d.ts +11 -0
  31. package/dist/types/functions/utils.d.ts +22 -0
  32. package/dist/types/functions/zip-utils.d.ts +38 -0
  33. package/dist/types/google-types.ts +48 -0
  34. package/dist/types/index.d.ts +72 -0
  35. package/dist/types/index.ts +57 -0
  36. package/dist/types/llm-tools.d.ts +2 -0
  37. package/dist/types/openai-types.ts +92 -0
  38. package/dist/types/test-data.d.ts +14 -0
  39. package/dist/types/test-llm-functions-archive.d.ts +1 -0
  40. package/dist/types/test.d.ts +1 -0
  41. package/dist/types/types/aws-types.d.ts +53 -0
  42. package/dist/types/types/google-types.d.ts +41 -0
  43. package/dist/types/types/index.d.ts +44 -0
  44. package/dist/types/types/openai-types.d.ts +81 -0
  45. package/dist/types/utils/aws-initialise.d.ts +21 -0
  46. package/dist/types/utils/aws-s3-utils.d.ts +32 -0
  47. package/dist/types/utils/config.d.ts +11 -0
  48. package/package.json +56 -0
@@ -0,0 +1,1477 @@
1
+ import require$$0$4 from 'net';
2
+ import require$$1$1 from 'tls';
3
+ import require$$2 from 'assert';
4
+ import require$$0 from 'ms';
5
+ import require$$0$2 from 'tty';
6
+ import require$$0$1 from 'util';
7
+ import require$$0$3 from 'http';
8
+ import require$$1 from 'https';
9
+ import require$$2$1 from 'url';
10
+
11
+ function _mergeNamespaces(n, m) {
12
+ m.forEach(function (e) {
13
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
14
+ if (k !== 'default' && !(k in n)) {
15
+ var d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: function () { return e[k]; }
19
+ });
20
+ }
21
+ });
22
+ });
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var dist$1 = {};
27
+
28
+ var src = {exports: {}};
29
+
30
+ var browser = {exports: {}};
31
+
32
+ var common;
33
+ var hasRequiredCommon;
34
+
35
+ function requireCommon () {
36
+ if (hasRequiredCommon) return common;
37
+ hasRequiredCommon = 1;
38
+ /**
39
+ * This is the common logic for both the Node.js and web browser
40
+ * implementations of `debug()`.
41
+ */
42
+
43
+ function setup(env) {
44
+ createDebug.debug = createDebug;
45
+ createDebug.default = createDebug;
46
+ createDebug.coerce = coerce;
47
+ createDebug.disable = disable;
48
+ createDebug.enable = enable;
49
+ createDebug.enabled = enabled;
50
+ createDebug.humanize = require$$0;
51
+ createDebug.destroy = destroy;
52
+
53
+ Object.keys(env).forEach(key => {
54
+ createDebug[key] = env[key];
55
+ });
56
+
57
+ /**
58
+ * The currently active debug mode names, and names to skip.
59
+ */
60
+
61
+ createDebug.names = [];
62
+ createDebug.skips = [];
63
+
64
+ /**
65
+ * Map of special "%n" handling functions, for the debug "format" argument.
66
+ *
67
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
68
+ */
69
+ createDebug.formatters = {};
70
+
71
+ /**
72
+ * Selects a color for a debug namespace
73
+ * @param {String} namespace The namespace string for the debug instance to be colored
74
+ * @return {Number|String} An ANSI color code for the given namespace
75
+ * @api private
76
+ */
77
+ function selectColor(namespace) {
78
+ let hash = 0;
79
+
80
+ for (let i = 0; i < namespace.length; i++) {
81
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
82
+ hash |= 0; // Convert to 32bit integer
83
+ }
84
+
85
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
86
+ }
87
+ createDebug.selectColor = selectColor;
88
+
89
+ /**
90
+ * Create a debugger with the given `namespace`.
91
+ *
92
+ * @param {String} namespace
93
+ * @return {Function}
94
+ * @api public
95
+ */
96
+ function createDebug(namespace) {
97
+ let prevTime;
98
+ let enableOverride = null;
99
+ let namespacesCache;
100
+ let enabledCache;
101
+
102
+ function debug(...args) {
103
+ // Disabled?
104
+ if (!debug.enabled) {
105
+ return;
106
+ }
107
+
108
+ const self = debug;
109
+
110
+ // Set `diff` timestamp
111
+ const curr = Number(new Date());
112
+ const ms = curr - (prevTime || curr);
113
+ self.diff = ms;
114
+ self.prev = prevTime;
115
+ self.curr = curr;
116
+ prevTime = curr;
117
+
118
+ args[0] = createDebug.coerce(args[0]);
119
+
120
+ if (typeof args[0] !== 'string') {
121
+ // Anything else let's inspect with %O
122
+ args.unshift('%O');
123
+ }
124
+
125
+ // Apply any `formatters` transformations
126
+ let index = 0;
127
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
128
+ // If we encounter an escaped % then don't increase the array index
129
+ if (match === '%%') {
130
+ return '%';
131
+ }
132
+ index++;
133
+ const formatter = createDebug.formatters[format];
134
+ if (typeof formatter === 'function') {
135
+ const val = args[index];
136
+ match = formatter.call(self, val);
137
+
138
+ // Now we need to remove `args[index]` since it's inlined in the `format`
139
+ args.splice(index, 1);
140
+ index--;
141
+ }
142
+ return match;
143
+ });
144
+
145
+ // Apply env-specific formatting (colors, etc.)
146
+ createDebug.formatArgs.call(self, args);
147
+
148
+ const logFn = self.log || createDebug.log;
149
+ logFn.apply(self, args);
150
+ }
151
+
152
+ debug.namespace = namespace;
153
+ debug.useColors = createDebug.useColors();
154
+ debug.color = createDebug.selectColor(namespace);
155
+ debug.extend = extend;
156
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
157
+
158
+ Object.defineProperty(debug, 'enabled', {
159
+ enumerable: true,
160
+ configurable: false,
161
+ get: () => {
162
+ if (enableOverride !== null) {
163
+ return enableOverride;
164
+ }
165
+ if (namespacesCache !== createDebug.namespaces) {
166
+ namespacesCache = createDebug.namespaces;
167
+ enabledCache = createDebug.enabled(namespace);
168
+ }
169
+
170
+ return enabledCache;
171
+ },
172
+ set: v => {
173
+ enableOverride = v;
174
+ }
175
+ });
176
+
177
+ // Env-specific initialization logic for debug instances
178
+ if (typeof createDebug.init === 'function') {
179
+ createDebug.init(debug);
180
+ }
181
+
182
+ return debug;
183
+ }
184
+
185
+ function extend(namespace, delimiter) {
186
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
187
+ newDebug.log = this.log;
188
+ return newDebug;
189
+ }
190
+
191
+ /**
192
+ * Enables a debug mode by namespaces. This can include modes
193
+ * separated by a colon and wildcards.
194
+ *
195
+ * @param {String} namespaces
196
+ * @api public
197
+ */
198
+ function enable(namespaces) {
199
+ createDebug.save(namespaces);
200
+ createDebug.namespaces = namespaces;
201
+
202
+ createDebug.names = [];
203
+ createDebug.skips = [];
204
+
205
+ const split = (typeof namespaces === 'string' ? namespaces : '')
206
+ .trim()
207
+ .replace(' ', ',')
208
+ .split(',')
209
+ .filter(Boolean);
210
+
211
+ for (const ns of split) {
212
+ if (ns[0] === '-') {
213
+ createDebug.skips.push(ns.slice(1));
214
+ } else {
215
+ createDebug.names.push(ns);
216
+ }
217
+ }
218
+ }
219
+
220
+ /**
221
+ * Checks if the given string matches a namespace template, honoring
222
+ * asterisks as wildcards.
223
+ *
224
+ * @param {String} search
225
+ * @param {String} template
226
+ * @return {Boolean}
227
+ */
228
+ function matchesTemplate(search, template) {
229
+ let searchIndex = 0;
230
+ let templateIndex = 0;
231
+ let starIndex = -1;
232
+ let matchIndex = 0;
233
+
234
+ while (searchIndex < search.length) {
235
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
236
+ // Match character or proceed with wildcard
237
+ if (template[templateIndex] === '*') {
238
+ starIndex = templateIndex;
239
+ matchIndex = searchIndex;
240
+ templateIndex++; // Skip the '*'
241
+ } else {
242
+ searchIndex++;
243
+ templateIndex++;
244
+ }
245
+ } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
246
+ // Backtrack to the last '*' and try to match more characters
247
+ templateIndex = starIndex + 1;
248
+ matchIndex++;
249
+ searchIndex = matchIndex;
250
+ } else {
251
+ return false; // No match
252
+ }
253
+ }
254
+
255
+ // Handle trailing '*' in template
256
+ while (templateIndex < template.length && template[templateIndex] === '*') {
257
+ templateIndex++;
258
+ }
259
+
260
+ return templateIndex === template.length;
261
+ }
262
+
263
+ /**
264
+ * Disable debug output.
265
+ *
266
+ * @return {String} namespaces
267
+ * @api public
268
+ */
269
+ function disable() {
270
+ const namespaces = [
271
+ ...createDebug.names,
272
+ ...createDebug.skips.map(namespace => '-' + namespace)
273
+ ].join(',');
274
+ createDebug.enable('');
275
+ return namespaces;
276
+ }
277
+
278
+ /**
279
+ * Returns true if the given mode name is enabled, false otherwise.
280
+ *
281
+ * @param {String} name
282
+ * @return {Boolean}
283
+ * @api public
284
+ */
285
+ function enabled(name) {
286
+ for (const skip of createDebug.skips) {
287
+ if (matchesTemplate(name, skip)) {
288
+ return false;
289
+ }
290
+ }
291
+
292
+ for (const ns of createDebug.names) {
293
+ if (matchesTemplate(name, ns)) {
294
+ return true;
295
+ }
296
+ }
297
+
298
+ return false;
299
+ }
300
+
301
+ /**
302
+ * Coerce `val`.
303
+ *
304
+ * @param {Mixed} val
305
+ * @return {Mixed}
306
+ * @api private
307
+ */
308
+ function coerce(val) {
309
+ if (val instanceof Error) {
310
+ return val.stack || val.message;
311
+ }
312
+ return val;
313
+ }
314
+
315
+ /**
316
+ * XXX DO NOT USE. This is a temporary stub function.
317
+ * XXX It WILL be removed in the next major release.
318
+ */
319
+ function destroy() {
320
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
321
+ }
322
+
323
+ createDebug.enable(createDebug.load());
324
+
325
+ return createDebug;
326
+ }
327
+
328
+ common = setup;
329
+ return common;
330
+ }
331
+
332
+ /* eslint-env browser */
333
+
334
+ var hasRequiredBrowser;
335
+
336
+ function requireBrowser () {
337
+ if (hasRequiredBrowser) return browser.exports;
338
+ hasRequiredBrowser = 1;
339
+ (function (module, exports) {
340
+ /**
341
+ * This is the web browser implementation of `debug()`.
342
+ */
343
+
344
+ exports.formatArgs = formatArgs;
345
+ exports.save = save;
346
+ exports.load = load;
347
+ exports.useColors = useColors;
348
+ exports.storage = localstorage();
349
+ exports.destroy = (() => {
350
+ let warned = false;
351
+
352
+ return () => {
353
+ if (!warned) {
354
+ warned = true;
355
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
356
+ }
357
+ };
358
+ })();
359
+
360
+ /**
361
+ * Colors.
362
+ */
363
+
364
+ exports.colors = [
365
+ '#0000CC',
366
+ '#0000FF',
367
+ '#0033CC',
368
+ '#0033FF',
369
+ '#0066CC',
370
+ '#0066FF',
371
+ '#0099CC',
372
+ '#0099FF',
373
+ '#00CC00',
374
+ '#00CC33',
375
+ '#00CC66',
376
+ '#00CC99',
377
+ '#00CCCC',
378
+ '#00CCFF',
379
+ '#3300CC',
380
+ '#3300FF',
381
+ '#3333CC',
382
+ '#3333FF',
383
+ '#3366CC',
384
+ '#3366FF',
385
+ '#3399CC',
386
+ '#3399FF',
387
+ '#33CC00',
388
+ '#33CC33',
389
+ '#33CC66',
390
+ '#33CC99',
391
+ '#33CCCC',
392
+ '#33CCFF',
393
+ '#6600CC',
394
+ '#6600FF',
395
+ '#6633CC',
396
+ '#6633FF',
397
+ '#66CC00',
398
+ '#66CC33',
399
+ '#9900CC',
400
+ '#9900FF',
401
+ '#9933CC',
402
+ '#9933FF',
403
+ '#99CC00',
404
+ '#99CC33',
405
+ '#CC0000',
406
+ '#CC0033',
407
+ '#CC0066',
408
+ '#CC0099',
409
+ '#CC00CC',
410
+ '#CC00FF',
411
+ '#CC3300',
412
+ '#CC3333',
413
+ '#CC3366',
414
+ '#CC3399',
415
+ '#CC33CC',
416
+ '#CC33FF',
417
+ '#CC6600',
418
+ '#CC6633',
419
+ '#CC9900',
420
+ '#CC9933',
421
+ '#CCCC00',
422
+ '#CCCC33',
423
+ '#FF0000',
424
+ '#FF0033',
425
+ '#FF0066',
426
+ '#FF0099',
427
+ '#FF00CC',
428
+ '#FF00FF',
429
+ '#FF3300',
430
+ '#FF3333',
431
+ '#FF3366',
432
+ '#FF3399',
433
+ '#FF33CC',
434
+ '#FF33FF',
435
+ '#FF6600',
436
+ '#FF6633',
437
+ '#FF9900',
438
+ '#FF9933',
439
+ '#FFCC00',
440
+ '#FFCC33'
441
+ ];
442
+
443
+ /**
444
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
445
+ * and the Firebug extension (any Firefox version) are known
446
+ * to support "%c" CSS customizations.
447
+ *
448
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
449
+ */
450
+
451
+ // eslint-disable-next-line complexity
452
+ function useColors() {
453
+ // NB: In an Electron preload script, document will be defined but not fully
454
+ // initialized. Since we know we're in Chrome, we'll just detect this case
455
+ // explicitly
456
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
457
+ return true;
458
+ }
459
+
460
+ // Internet Explorer and Edge do not support colors.
461
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
462
+ return false;
463
+ }
464
+
465
+ let m;
466
+
467
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
468
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
469
+ // eslint-disable-next-line no-return-assign
470
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
471
+ // Is firebug? http://stackoverflow.com/a/398120/376773
472
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
473
+ // Is firefox >= v31?
474
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
475
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
476
+ // Double check webkit in userAgent just in case we are in a worker
477
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
478
+ }
479
+
480
+ /**
481
+ * Colorize log arguments if enabled.
482
+ *
483
+ * @api public
484
+ */
485
+
486
+ function formatArgs(args) {
487
+ args[0] = (this.useColors ? '%c' : '') +
488
+ this.namespace +
489
+ (this.useColors ? ' %c' : ' ') +
490
+ args[0] +
491
+ (this.useColors ? '%c ' : ' ') +
492
+ '+' + module.exports.humanize(this.diff);
493
+
494
+ if (!this.useColors) {
495
+ return;
496
+ }
497
+
498
+ const c = 'color: ' + this.color;
499
+ args.splice(1, 0, c, 'color: inherit');
500
+
501
+ // The final "%c" is somewhat tricky, because there could be other
502
+ // arguments passed either before or after the %c, so we need to
503
+ // figure out the correct index to insert the CSS into
504
+ let index = 0;
505
+ let lastC = 0;
506
+ args[0].replace(/%[a-zA-Z%]/g, match => {
507
+ if (match === '%%') {
508
+ return;
509
+ }
510
+ index++;
511
+ if (match === '%c') {
512
+ // We only are interested in the *last* %c
513
+ // (the user may have provided their own)
514
+ lastC = index;
515
+ }
516
+ });
517
+
518
+ args.splice(lastC, 0, c);
519
+ }
520
+
521
+ /**
522
+ * Invokes `console.debug()` when available.
523
+ * No-op when `console.debug` is not a "function".
524
+ * If `console.debug` is not available, falls back
525
+ * to `console.log`.
526
+ *
527
+ * @api public
528
+ */
529
+ exports.log = console.debug || console.log || (() => {});
530
+
531
+ /**
532
+ * Save `namespaces`.
533
+ *
534
+ * @param {String} namespaces
535
+ * @api private
536
+ */
537
+ function save(namespaces) {
538
+ try {
539
+ if (namespaces) {
540
+ exports.storage.setItem('debug', namespaces);
541
+ } else {
542
+ exports.storage.removeItem('debug');
543
+ }
544
+ } catch (error) {
545
+ // Swallow
546
+ // XXX (@Qix-) should we be logging these?
547
+ }
548
+ }
549
+
550
+ /**
551
+ * Load `namespaces`.
552
+ *
553
+ * @return {String} returns the previously persisted debug modes
554
+ * @api private
555
+ */
556
+ function load() {
557
+ let r;
558
+ try {
559
+ r = exports.storage.getItem('debug');
560
+ } catch (error) {
561
+ // Swallow
562
+ // XXX (@Qix-) should we be logging these?
563
+ }
564
+
565
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
566
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
567
+ r = process.env.DEBUG;
568
+ }
569
+
570
+ return r;
571
+ }
572
+
573
+ /**
574
+ * Localstorage attempts to return the localstorage.
575
+ *
576
+ * This is necessary because safari throws
577
+ * when a user disables cookies/localstorage
578
+ * and you attempt to access it.
579
+ *
580
+ * @return {LocalStorage}
581
+ * @api private
582
+ */
583
+
584
+ function localstorage() {
585
+ try {
586
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
587
+ // The Browser also has localStorage in the global context.
588
+ return localStorage;
589
+ } catch (error) {
590
+ // Swallow
591
+ // XXX (@Qix-) should we be logging these?
592
+ }
593
+ }
594
+
595
+ module.exports = requireCommon()(exports);
596
+
597
+ const {formatters} = module.exports;
598
+
599
+ /**
600
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
601
+ */
602
+
603
+ formatters.j = function (v) {
604
+ try {
605
+ return JSON.stringify(v);
606
+ } catch (error) {
607
+ return '[UnexpectedJSONParseError]: ' + error.message;
608
+ }
609
+ };
610
+ } (browser, browser.exports));
611
+ return browser.exports;
612
+ }
613
+
614
+ var node = {exports: {}};
615
+
616
+ /**
617
+ * Module dependencies.
618
+ */
619
+
620
+ var hasRequiredNode;
621
+
622
+ function requireNode () {
623
+ if (hasRequiredNode) return node.exports;
624
+ hasRequiredNode = 1;
625
+ (function (module, exports) {
626
+ const tty = require$$0$2;
627
+ const util = require$$0$1;
628
+
629
+ /**
630
+ * This is the Node.js implementation of `debug()`.
631
+ */
632
+
633
+ exports.init = init;
634
+ exports.log = log;
635
+ exports.formatArgs = formatArgs;
636
+ exports.save = save;
637
+ exports.load = load;
638
+ exports.useColors = useColors;
639
+ exports.destroy = util.deprecate(
640
+ () => {},
641
+ 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
642
+ );
643
+
644
+ /**
645
+ * Colors.
646
+ */
647
+
648
+ exports.colors = [6, 2, 3, 4, 5, 1];
649
+
650
+ try {
651
+ // Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
652
+ // eslint-disable-next-line import/no-extraneous-dependencies
653
+ const supportsColor = require('supports-color');
654
+
655
+ if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
656
+ exports.colors = [
657
+ 20,
658
+ 21,
659
+ 26,
660
+ 27,
661
+ 32,
662
+ 33,
663
+ 38,
664
+ 39,
665
+ 40,
666
+ 41,
667
+ 42,
668
+ 43,
669
+ 44,
670
+ 45,
671
+ 56,
672
+ 57,
673
+ 62,
674
+ 63,
675
+ 68,
676
+ 69,
677
+ 74,
678
+ 75,
679
+ 76,
680
+ 77,
681
+ 78,
682
+ 79,
683
+ 80,
684
+ 81,
685
+ 92,
686
+ 93,
687
+ 98,
688
+ 99,
689
+ 112,
690
+ 113,
691
+ 128,
692
+ 129,
693
+ 134,
694
+ 135,
695
+ 148,
696
+ 149,
697
+ 160,
698
+ 161,
699
+ 162,
700
+ 163,
701
+ 164,
702
+ 165,
703
+ 166,
704
+ 167,
705
+ 168,
706
+ 169,
707
+ 170,
708
+ 171,
709
+ 172,
710
+ 173,
711
+ 178,
712
+ 179,
713
+ 184,
714
+ 185,
715
+ 196,
716
+ 197,
717
+ 198,
718
+ 199,
719
+ 200,
720
+ 201,
721
+ 202,
722
+ 203,
723
+ 204,
724
+ 205,
725
+ 206,
726
+ 207,
727
+ 208,
728
+ 209,
729
+ 214,
730
+ 215,
731
+ 220,
732
+ 221
733
+ ];
734
+ }
735
+ } catch (error) {
736
+ // Swallow - we only care if `supports-color` is available; it doesn't have to be.
737
+ }
738
+
739
+ /**
740
+ * Build up the default `inspectOpts` object from the environment variables.
741
+ *
742
+ * $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
743
+ */
744
+
745
+ exports.inspectOpts = Object.keys(process.env).filter(key => {
746
+ return /^debug_/i.test(key);
747
+ }).reduce((obj, key) => {
748
+ // Camel-case
749
+ const prop = key
750
+ .substring(6)
751
+ .toLowerCase()
752
+ .replace(/_([a-z])/g, (_, k) => {
753
+ return k.toUpperCase();
754
+ });
755
+
756
+ // Coerce string value into JS value
757
+ let val = process.env[key];
758
+ if (/^(yes|on|true|enabled)$/i.test(val)) {
759
+ val = true;
760
+ } else if (/^(no|off|false|disabled)$/i.test(val)) {
761
+ val = false;
762
+ } else if (val === 'null') {
763
+ val = null;
764
+ } else {
765
+ val = Number(val);
766
+ }
767
+
768
+ obj[prop] = val;
769
+ return obj;
770
+ }, {});
771
+
772
+ /**
773
+ * Is stdout a TTY? Colored output is enabled when `true`.
774
+ */
775
+
776
+ function useColors() {
777
+ return 'colors' in exports.inspectOpts ?
778
+ Boolean(exports.inspectOpts.colors) :
779
+ tty.isatty(process.stderr.fd);
780
+ }
781
+
782
+ /**
783
+ * Adds ANSI color escape codes if enabled.
784
+ *
785
+ * @api public
786
+ */
787
+
788
+ function formatArgs(args) {
789
+ const {namespace: name, useColors} = this;
790
+
791
+ if (useColors) {
792
+ const c = this.color;
793
+ const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
794
+ const prefix = ` ${colorCode};1m${name} \u001B[0m`;
795
+
796
+ args[0] = prefix + args[0].split('\n').join('\n' + prefix);
797
+ args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
798
+ } else {
799
+ args[0] = getDate() + name + ' ' + args[0];
800
+ }
801
+ }
802
+
803
+ function getDate() {
804
+ if (exports.inspectOpts.hideDate) {
805
+ return '';
806
+ }
807
+ return new Date().toISOString() + ' ';
808
+ }
809
+
810
+ /**
811
+ * Invokes `util.formatWithOptions()` with the specified arguments and writes to stderr.
812
+ */
813
+
814
+ function log(...args) {
815
+ return process.stderr.write(util.formatWithOptions(exports.inspectOpts, ...args) + '\n');
816
+ }
817
+
818
+ /**
819
+ * Save `namespaces`.
820
+ *
821
+ * @param {String} namespaces
822
+ * @api private
823
+ */
824
+ function save(namespaces) {
825
+ if (namespaces) {
826
+ process.env.DEBUG = namespaces;
827
+ } else {
828
+ // If you set a process.env field to null or undefined, it gets cast to the
829
+ // string 'null' or 'undefined'. Just delete instead.
830
+ delete process.env.DEBUG;
831
+ }
832
+ }
833
+
834
+ /**
835
+ * Load `namespaces`.
836
+ *
837
+ * @return {String} returns the previously persisted debug modes
838
+ * @api private
839
+ */
840
+
841
+ function load() {
842
+ return process.env.DEBUG;
843
+ }
844
+
845
+ /**
846
+ * Init logic for `debug` instances.
847
+ *
848
+ * Create a new `inspectOpts` object in case `useColors` is set
849
+ * differently for a particular `debug` instance.
850
+ */
851
+
852
+ function init(debug) {
853
+ debug.inspectOpts = {};
854
+
855
+ const keys = Object.keys(exports.inspectOpts);
856
+ for (let i = 0; i < keys.length; i++) {
857
+ debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
858
+ }
859
+ }
860
+
861
+ module.exports = requireCommon()(exports);
862
+
863
+ const {formatters} = module.exports;
864
+
865
+ /**
866
+ * Map %o to `util.inspect()`, all on a single line.
867
+ */
868
+
869
+ formatters.o = function (v) {
870
+ this.inspectOpts.colors = this.useColors;
871
+ return util.inspect(v, this.inspectOpts)
872
+ .split('\n')
873
+ .map(str => str.trim())
874
+ .join(' ');
875
+ };
876
+
877
+ /**
878
+ * Map %O to `util.inspect()`, allowing multiple lines if needed.
879
+ */
880
+
881
+ formatters.O = function (v) {
882
+ this.inspectOpts.colors = this.useColors;
883
+ return util.inspect(v, this.inspectOpts);
884
+ };
885
+ } (node, node.exports));
886
+ return node.exports;
887
+ }
888
+
889
+ /**
890
+ * Detect Electron renderer / nwjs process, which is node, but we should
891
+ * treat as a browser.
892
+ */
893
+
894
+ var hasRequiredSrc;
895
+
896
+ function requireSrc () {
897
+ if (hasRequiredSrc) return src.exports;
898
+ hasRequiredSrc = 1;
899
+ if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
900
+ src.exports = requireBrowser();
901
+ } else {
902
+ src.exports = requireNode();
903
+ }
904
+ return src.exports;
905
+ }
906
+
907
+ var dist = {};
908
+
909
+ var helpers = {};
910
+
911
+ var hasRequiredHelpers;
912
+
913
+ function requireHelpers () {
914
+ if (hasRequiredHelpers) return helpers;
915
+ hasRequiredHelpers = 1;
916
+ var __createBinding = (helpers && helpers.__createBinding) || (Object.create ? (function(o, m, k, k2) {
917
+ if (k2 === undefined) k2 = k;
918
+ var desc = Object.getOwnPropertyDescriptor(m, k);
919
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
920
+ desc = { enumerable: true, get: function() { return m[k]; } };
921
+ }
922
+ Object.defineProperty(o, k2, desc);
923
+ }) : (function(o, m, k, k2) {
924
+ if (k2 === undefined) k2 = k;
925
+ o[k2] = m[k];
926
+ }));
927
+ var __setModuleDefault = (helpers && helpers.__setModuleDefault) || (Object.create ? (function(o, v) {
928
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
929
+ }) : function(o, v) {
930
+ o["default"] = v;
931
+ });
932
+ var __importStar = (helpers && helpers.__importStar) || function (mod) {
933
+ if (mod && mod.__esModule) return mod;
934
+ var result = {};
935
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
936
+ __setModuleDefault(result, mod);
937
+ return result;
938
+ };
939
+ Object.defineProperty(helpers, "__esModule", { value: true });
940
+ helpers.req = helpers.json = helpers.toBuffer = void 0;
941
+ const http = __importStar(require$$0$3);
942
+ const https = __importStar(require$$1);
943
+ async function toBuffer(stream) {
944
+ let length = 0;
945
+ const chunks = [];
946
+ for await (const chunk of stream) {
947
+ length += chunk.length;
948
+ chunks.push(chunk);
949
+ }
950
+ return Buffer.concat(chunks, length);
951
+ }
952
+ helpers.toBuffer = toBuffer;
953
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
954
+ async function json(stream) {
955
+ const buf = await toBuffer(stream);
956
+ const str = buf.toString('utf8');
957
+ try {
958
+ return JSON.parse(str);
959
+ }
960
+ catch (_err) {
961
+ const err = _err;
962
+ err.message += ` (input: ${str})`;
963
+ throw err;
964
+ }
965
+ }
966
+ helpers.json = json;
967
+ function req(url, opts = {}) {
968
+ const href = typeof url === 'string' ? url : url.href;
969
+ const req = (href.startsWith('https:') ? https : http).request(url, opts);
970
+ const promise = new Promise((resolve, reject) => {
971
+ req
972
+ .once('response', resolve)
973
+ .once('error', reject)
974
+ .end();
975
+ });
976
+ req.then = promise.then.bind(promise);
977
+ return req;
978
+ }
979
+ helpers.req = req;
980
+
981
+ return helpers;
982
+ }
983
+
984
+ var hasRequiredDist$1;
985
+
986
+ function requireDist$1 () {
987
+ if (hasRequiredDist$1) return dist;
988
+ hasRequiredDist$1 = 1;
989
+ (function (exports) {
990
+ var __createBinding = (dist && dist.__createBinding) || (Object.create ? (function(o, m, k, k2) {
991
+ if (k2 === undefined) k2 = k;
992
+ var desc = Object.getOwnPropertyDescriptor(m, k);
993
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
994
+ desc = { enumerable: true, get: function() { return m[k]; } };
995
+ }
996
+ Object.defineProperty(o, k2, desc);
997
+ }) : (function(o, m, k, k2) {
998
+ if (k2 === undefined) k2 = k;
999
+ o[k2] = m[k];
1000
+ }));
1001
+ var __setModuleDefault = (dist && dist.__setModuleDefault) || (Object.create ? (function(o, v) {
1002
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1003
+ }) : function(o, v) {
1004
+ o["default"] = v;
1005
+ });
1006
+ var __importStar = (dist && dist.__importStar) || function (mod) {
1007
+ if (mod && mod.__esModule) return mod;
1008
+ var result = {};
1009
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1010
+ __setModuleDefault(result, mod);
1011
+ return result;
1012
+ };
1013
+ var __exportStar = (dist && dist.__exportStar) || function(m, exports) {
1014
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1015
+ };
1016
+ Object.defineProperty(exports, "__esModule", { value: true });
1017
+ exports.Agent = void 0;
1018
+ const net = __importStar(require$$0$4);
1019
+ const http = __importStar(require$$0$3);
1020
+ const https_1 = require$$1;
1021
+ __exportStar(requireHelpers(), exports);
1022
+ const INTERNAL = Symbol('AgentBaseInternalState');
1023
+ class Agent extends http.Agent {
1024
+ constructor(opts) {
1025
+ super(opts);
1026
+ this[INTERNAL] = {};
1027
+ }
1028
+ /**
1029
+ * Determine whether this is an `http` or `https` request.
1030
+ */
1031
+ isSecureEndpoint(options) {
1032
+ if (options) {
1033
+ // First check the `secureEndpoint` property explicitly, since this
1034
+ // means that a parent `Agent` is "passing through" to this instance.
1035
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1036
+ if (typeof options.secureEndpoint === 'boolean') {
1037
+ return options.secureEndpoint;
1038
+ }
1039
+ // If no explicit `secure` endpoint, check if `protocol` property is
1040
+ // set. This will usually be the case since using a full string URL
1041
+ // or `URL` instance should be the most common usage.
1042
+ if (typeof options.protocol === 'string') {
1043
+ return options.protocol === 'https:';
1044
+ }
1045
+ }
1046
+ // Finally, if no `protocol` property was set, then fall back to
1047
+ // checking the stack trace of the current call stack, and try to
1048
+ // detect the "https" module.
1049
+ const { stack } = new Error();
1050
+ if (typeof stack !== 'string')
1051
+ return false;
1052
+ return stack
1053
+ .split('\n')
1054
+ .some((l) => l.indexOf('(https.js:') !== -1 ||
1055
+ l.indexOf('node:https:') !== -1);
1056
+ }
1057
+ // In order to support async signatures in `connect()` and Node's native
1058
+ // connection pooling in `http.Agent`, the array of sockets for each origin
1059
+ // has to be updated synchronously. This is so the length of the array is
1060
+ // accurate when `addRequest()` is next called. We achieve this by creating a
1061
+ // fake socket and adding it to `sockets[origin]` and incrementing
1062
+ // `totalSocketCount`.
1063
+ incrementSockets(name) {
1064
+ // If `maxSockets` and `maxTotalSockets` are both Infinity then there is no
1065
+ // need to create a fake socket because Node.js native connection pooling
1066
+ // will never be invoked.
1067
+ if (this.maxSockets === Infinity && this.maxTotalSockets === Infinity) {
1068
+ return null;
1069
+ }
1070
+ // All instances of `sockets` are expected TypeScript errors. The
1071
+ // alternative is to add it as a private property of this class but that
1072
+ // will break TypeScript subclassing.
1073
+ if (!this.sockets[name]) {
1074
+ // @ts-expect-error `sockets` is readonly in `@types/node`
1075
+ this.sockets[name] = [];
1076
+ }
1077
+ const fakeSocket = new net.Socket({ writable: false });
1078
+ this.sockets[name].push(fakeSocket);
1079
+ // @ts-expect-error `totalSocketCount` isn't defined in `@types/node`
1080
+ this.totalSocketCount++;
1081
+ return fakeSocket;
1082
+ }
1083
+ decrementSockets(name, socket) {
1084
+ if (!this.sockets[name] || socket === null) {
1085
+ return;
1086
+ }
1087
+ const sockets = this.sockets[name];
1088
+ const index = sockets.indexOf(socket);
1089
+ if (index !== -1) {
1090
+ sockets.splice(index, 1);
1091
+ // @ts-expect-error `totalSocketCount` isn't defined in `@types/node`
1092
+ this.totalSocketCount--;
1093
+ if (sockets.length === 0) {
1094
+ // @ts-expect-error `sockets` is readonly in `@types/node`
1095
+ delete this.sockets[name];
1096
+ }
1097
+ }
1098
+ }
1099
+ // In order to properly update the socket pool, we need to call `getName()` on
1100
+ // the core `https.Agent` if it is a secureEndpoint.
1101
+ getName(options) {
1102
+ const secureEndpoint = typeof options.secureEndpoint === 'boolean'
1103
+ ? options.secureEndpoint
1104
+ : this.isSecureEndpoint(options);
1105
+ if (secureEndpoint) {
1106
+ // @ts-expect-error `getName()` isn't defined in `@types/node`
1107
+ return https_1.Agent.prototype.getName.call(this, options);
1108
+ }
1109
+ // @ts-expect-error `getName()` isn't defined in `@types/node`
1110
+ return super.getName(options);
1111
+ }
1112
+ createSocket(req, options, cb) {
1113
+ const connectOpts = {
1114
+ ...options,
1115
+ secureEndpoint: this.isSecureEndpoint(options),
1116
+ };
1117
+ const name = this.getName(connectOpts);
1118
+ const fakeSocket = this.incrementSockets(name);
1119
+ Promise.resolve()
1120
+ .then(() => this.connect(req, connectOpts))
1121
+ .then((socket) => {
1122
+ this.decrementSockets(name, fakeSocket);
1123
+ if (socket instanceof http.Agent) {
1124
+ try {
1125
+ // @ts-expect-error `addRequest()` isn't defined in `@types/node`
1126
+ return socket.addRequest(req, connectOpts);
1127
+ }
1128
+ catch (err) {
1129
+ return cb(err);
1130
+ }
1131
+ }
1132
+ this[INTERNAL].currentSocket = socket;
1133
+ // @ts-expect-error `createSocket()` isn't defined in `@types/node`
1134
+ super.createSocket(req, options, cb);
1135
+ }, (err) => {
1136
+ this.decrementSockets(name, fakeSocket);
1137
+ cb(err);
1138
+ });
1139
+ }
1140
+ createConnection() {
1141
+ const socket = this[INTERNAL].currentSocket;
1142
+ this[INTERNAL].currentSocket = undefined;
1143
+ if (!socket) {
1144
+ throw new Error('No socket was returned in the `connect()` function');
1145
+ }
1146
+ return socket;
1147
+ }
1148
+ get defaultPort() {
1149
+ return (this[INTERNAL].defaultPort ??
1150
+ (this.protocol === 'https:' ? 443 : 80));
1151
+ }
1152
+ set defaultPort(v) {
1153
+ if (this[INTERNAL]) {
1154
+ this[INTERNAL].defaultPort = v;
1155
+ }
1156
+ }
1157
+ get protocol() {
1158
+ return (this[INTERNAL].protocol ??
1159
+ (this.isSecureEndpoint() ? 'https:' : 'http:'));
1160
+ }
1161
+ set protocol(v) {
1162
+ if (this[INTERNAL]) {
1163
+ this[INTERNAL].protocol = v;
1164
+ }
1165
+ }
1166
+ }
1167
+ exports.Agent = Agent;
1168
+
1169
+ } (dist));
1170
+ return dist;
1171
+ }
1172
+
1173
+ var parseProxyResponse = {};
1174
+
1175
+ var hasRequiredParseProxyResponse;
1176
+
1177
+ function requireParseProxyResponse () {
1178
+ if (hasRequiredParseProxyResponse) return parseProxyResponse;
1179
+ hasRequiredParseProxyResponse = 1;
1180
+ var __importDefault = (parseProxyResponse && parseProxyResponse.__importDefault) || function (mod) {
1181
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1182
+ };
1183
+ Object.defineProperty(parseProxyResponse, "__esModule", { value: true });
1184
+ parseProxyResponse.parseProxyResponse = void 0;
1185
+ const debug_1 = __importDefault(requireSrc());
1186
+ const debug = (0, debug_1.default)('https-proxy-agent:parse-proxy-response');
1187
+ function parseProxyResponse$1(socket) {
1188
+ return new Promise((resolve, reject) => {
1189
+ // we need to buffer any HTTP traffic that happens with the proxy before we get
1190
+ // the CONNECT response, so that if the response is anything other than an "200"
1191
+ // response code, then we can re-play the "data" events on the socket once the
1192
+ // HTTP parser is hooked up...
1193
+ let buffersLength = 0;
1194
+ const buffers = [];
1195
+ function read() {
1196
+ const b = socket.read();
1197
+ if (b)
1198
+ ondata(b);
1199
+ else
1200
+ socket.once('readable', read);
1201
+ }
1202
+ function cleanup() {
1203
+ socket.removeListener('end', onend);
1204
+ socket.removeListener('error', onerror);
1205
+ socket.removeListener('readable', read);
1206
+ }
1207
+ function onend() {
1208
+ cleanup();
1209
+ debug('onend');
1210
+ reject(new Error('Proxy connection ended before receiving CONNECT response'));
1211
+ }
1212
+ function onerror(err) {
1213
+ cleanup();
1214
+ debug('onerror %o', err);
1215
+ reject(err);
1216
+ }
1217
+ function ondata(b) {
1218
+ buffers.push(b);
1219
+ buffersLength += b.length;
1220
+ const buffered = Buffer.concat(buffers, buffersLength);
1221
+ const endOfHeaders = buffered.indexOf('\r\n\r\n');
1222
+ if (endOfHeaders === -1) {
1223
+ // keep buffering
1224
+ debug('have not received end of HTTP headers yet...');
1225
+ read();
1226
+ return;
1227
+ }
1228
+ const headerParts = buffered
1229
+ .slice(0, endOfHeaders)
1230
+ .toString('ascii')
1231
+ .split('\r\n');
1232
+ const firstLine = headerParts.shift();
1233
+ if (!firstLine) {
1234
+ socket.destroy();
1235
+ return reject(new Error('No header received from proxy CONNECT response'));
1236
+ }
1237
+ const firstLineParts = firstLine.split(' ');
1238
+ const statusCode = +firstLineParts[1];
1239
+ const statusText = firstLineParts.slice(2).join(' ');
1240
+ const headers = {};
1241
+ for (const header of headerParts) {
1242
+ if (!header)
1243
+ continue;
1244
+ const firstColon = header.indexOf(':');
1245
+ if (firstColon === -1) {
1246
+ socket.destroy();
1247
+ return reject(new Error(`Invalid header from proxy CONNECT response: "${header}"`));
1248
+ }
1249
+ const key = header.slice(0, firstColon).toLowerCase();
1250
+ const value = header.slice(firstColon + 1).trimStart();
1251
+ const current = headers[key];
1252
+ if (typeof current === 'string') {
1253
+ headers[key] = [current, value];
1254
+ }
1255
+ else if (Array.isArray(current)) {
1256
+ current.push(value);
1257
+ }
1258
+ else {
1259
+ headers[key] = value;
1260
+ }
1261
+ }
1262
+ debug('got proxy server response: %o %o', firstLine, headers);
1263
+ cleanup();
1264
+ resolve({
1265
+ connect: {
1266
+ statusCode,
1267
+ statusText,
1268
+ headers,
1269
+ },
1270
+ buffered,
1271
+ });
1272
+ }
1273
+ socket.on('error', onerror);
1274
+ socket.on('end', onend);
1275
+ read();
1276
+ });
1277
+ }
1278
+ parseProxyResponse.parseProxyResponse = parseProxyResponse$1;
1279
+
1280
+ return parseProxyResponse;
1281
+ }
1282
+
1283
+ var hasRequiredDist;
1284
+
1285
+ function requireDist () {
1286
+ if (hasRequiredDist) return dist$1;
1287
+ hasRequiredDist = 1;
1288
+ var __createBinding = (dist$1 && dist$1.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1289
+ if (k2 === undefined) k2 = k;
1290
+ var desc = Object.getOwnPropertyDescriptor(m, k);
1291
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1292
+ desc = { enumerable: true, get: function() { return m[k]; } };
1293
+ }
1294
+ Object.defineProperty(o, k2, desc);
1295
+ }) : (function(o, m, k, k2) {
1296
+ if (k2 === undefined) k2 = k;
1297
+ o[k2] = m[k];
1298
+ }));
1299
+ var __setModuleDefault = (dist$1 && dist$1.__setModuleDefault) || (Object.create ? (function(o, v) {
1300
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
1301
+ }) : function(o, v) {
1302
+ o["default"] = v;
1303
+ });
1304
+ var __importStar = (dist$1 && dist$1.__importStar) || function (mod) {
1305
+ if (mod && mod.__esModule) return mod;
1306
+ var result = {};
1307
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
1308
+ __setModuleDefault(result, mod);
1309
+ return result;
1310
+ };
1311
+ var __importDefault = (dist$1 && dist$1.__importDefault) || function (mod) {
1312
+ return (mod && mod.__esModule) ? mod : { "default": mod };
1313
+ };
1314
+ Object.defineProperty(dist$1, "__esModule", { value: true });
1315
+ dist$1.HttpsProxyAgent = void 0;
1316
+ const net = __importStar(require$$0$4);
1317
+ const tls = __importStar(require$$1$1);
1318
+ const assert_1 = __importDefault(require$$2);
1319
+ const debug_1 = __importDefault(requireSrc());
1320
+ const agent_base_1 = requireDist$1();
1321
+ const url_1 = require$$2$1;
1322
+ const parse_proxy_response_1 = requireParseProxyResponse();
1323
+ const debug = (0, debug_1.default)('https-proxy-agent');
1324
+ const setServernameFromNonIpHost = (options) => {
1325
+ if (options.servername === undefined &&
1326
+ options.host &&
1327
+ !net.isIP(options.host)) {
1328
+ return {
1329
+ ...options,
1330
+ servername: options.host,
1331
+ };
1332
+ }
1333
+ return options;
1334
+ };
1335
+ /**
1336
+ * The `HttpsProxyAgent` implements an HTTP Agent subclass that connects to
1337
+ * the specified "HTTP(s) proxy server" in order to proxy HTTPS requests.
1338
+ *
1339
+ * Outgoing HTTP requests are first tunneled through the proxy server using the
1340
+ * `CONNECT` HTTP request method to establish a connection to the proxy server,
1341
+ * and then the proxy server connects to the destination target and issues the
1342
+ * HTTP request from the proxy server.
1343
+ *
1344
+ * `https:` requests have their socket connection upgraded to TLS once
1345
+ * the connection to the proxy server has been established.
1346
+ */
1347
+ class HttpsProxyAgent extends agent_base_1.Agent {
1348
+ constructor(proxy, opts) {
1349
+ super(opts);
1350
+ this.options = { path: undefined };
1351
+ this.proxy = typeof proxy === 'string' ? new url_1.URL(proxy) : proxy;
1352
+ this.proxyHeaders = opts?.headers ?? {};
1353
+ debug('Creating new HttpsProxyAgent instance: %o', this.proxy.href);
1354
+ // Trim off the brackets from IPv6 addresses
1355
+ const host = (this.proxy.hostname || this.proxy.host).replace(/^\[|\]$/g, '');
1356
+ const port = this.proxy.port
1357
+ ? parseInt(this.proxy.port, 10)
1358
+ : this.proxy.protocol === 'https:'
1359
+ ? 443
1360
+ : 80;
1361
+ this.connectOpts = {
1362
+ // Attempt to negotiate http/1.1 for proxy servers that support http/2
1363
+ ALPNProtocols: ['http/1.1'],
1364
+ ...(opts ? omit(opts, 'headers') : null),
1365
+ host,
1366
+ port,
1367
+ };
1368
+ }
1369
+ /**
1370
+ * Called when the node-core HTTP client library is creating a
1371
+ * new HTTP request.
1372
+ */
1373
+ async connect(req, opts) {
1374
+ const { proxy } = this;
1375
+ if (!opts.host) {
1376
+ throw new TypeError('No "host" provided');
1377
+ }
1378
+ // Create a socket connection to the proxy server.
1379
+ let socket;
1380
+ if (proxy.protocol === 'https:') {
1381
+ debug('Creating `tls.Socket`: %o', this.connectOpts);
1382
+ socket = tls.connect(setServernameFromNonIpHost(this.connectOpts));
1383
+ }
1384
+ else {
1385
+ debug('Creating `net.Socket`: %o', this.connectOpts);
1386
+ socket = net.connect(this.connectOpts);
1387
+ }
1388
+ const headers = typeof this.proxyHeaders === 'function'
1389
+ ? this.proxyHeaders()
1390
+ : { ...this.proxyHeaders };
1391
+ const host = net.isIPv6(opts.host) ? `[${opts.host}]` : opts.host;
1392
+ let payload = `CONNECT ${host}:${opts.port} HTTP/1.1\r\n`;
1393
+ // Inject the `Proxy-Authorization` header if necessary.
1394
+ if (proxy.username || proxy.password) {
1395
+ const auth = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`;
1396
+ headers['Proxy-Authorization'] = `Basic ${Buffer.from(auth).toString('base64')}`;
1397
+ }
1398
+ headers.Host = `${host}:${opts.port}`;
1399
+ if (!headers['Proxy-Connection']) {
1400
+ headers['Proxy-Connection'] = this.keepAlive
1401
+ ? 'Keep-Alive'
1402
+ : 'close';
1403
+ }
1404
+ for (const name of Object.keys(headers)) {
1405
+ payload += `${name}: ${headers[name]}\r\n`;
1406
+ }
1407
+ const proxyResponsePromise = (0, parse_proxy_response_1.parseProxyResponse)(socket);
1408
+ socket.write(`${payload}\r\n`);
1409
+ const { connect, buffered } = await proxyResponsePromise;
1410
+ req.emit('proxyConnect', connect);
1411
+ this.emit('proxyConnect', connect, req);
1412
+ if (connect.statusCode === 200) {
1413
+ req.once('socket', resume);
1414
+ if (opts.secureEndpoint) {
1415
+ // The proxy is connecting to a TLS server, so upgrade
1416
+ // this socket connection to a TLS connection.
1417
+ debug('Upgrading socket connection to TLS');
1418
+ return tls.connect({
1419
+ ...omit(setServernameFromNonIpHost(opts), 'host', 'path', 'port'),
1420
+ socket,
1421
+ });
1422
+ }
1423
+ return socket;
1424
+ }
1425
+ // Some other status code that's not 200... need to re-play the HTTP
1426
+ // header "data" events onto the socket once the HTTP machinery is
1427
+ // attached so that the node core `http` can parse and handle the
1428
+ // error status code.
1429
+ // Close the original socket, and a new "fake" socket is returned
1430
+ // instead, so that the proxy doesn't get the HTTP request
1431
+ // written to it (which may contain `Authorization` headers or other
1432
+ // sensitive data).
1433
+ //
1434
+ // See: https://hackerone.com/reports/541502
1435
+ socket.destroy();
1436
+ const fakeSocket = new net.Socket({ writable: false });
1437
+ fakeSocket.readable = true;
1438
+ // Need to wait for the "socket" event to re-play the "data" events.
1439
+ req.once('socket', (s) => {
1440
+ debug('Replaying proxy buffer for failed request');
1441
+ (0, assert_1.default)(s.listenerCount('data') > 0);
1442
+ // Replay the "buffered" Buffer onto the fake `socket`, since at
1443
+ // this point the HTTP module machinery has been hooked up for
1444
+ // the user.
1445
+ s.push(buffered);
1446
+ s.push(null);
1447
+ });
1448
+ return fakeSocket;
1449
+ }
1450
+ }
1451
+ HttpsProxyAgent.protocols = ['http', 'https'];
1452
+ dist$1.HttpsProxyAgent = HttpsProxyAgent;
1453
+ function resume(socket) {
1454
+ socket.resume();
1455
+ }
1456
+ function omit(obj, ...keys) {
1457
+ const ret = {};
1458
+ let key;
1459
+ for (key in obj) {
1460
+ if (!keys.includes(key)) {
1461
+ ret[key] = obj[key];
1462
+ }
1463
+ }
1464
+ return ret;
1465
+ }
1466
+
1467
+ return dist$1;
1468
+ }
1469
+
1470
+ var distExports = requireDist();
1471
+
1472
+ var index = /*#__PURE__*/_mergeNamespaces({
1473
+ __proto__: null
1474
+ }, [distExports]);
1475
+
1476
+ export { index as i };
1477
+ //# sourceMappingURL=index-CcXQeJz8.js.map