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