@mcp-z/client 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/dist/cjs/auth/capability-discovery.js +16 -6
- package/dist/cjs/auth/capability-discovery.js.map +1 -1
- package/dist/cjs/auth/discovery-fetch.d.cts +22 -2
- package/dist/cjs/auth/discovery-fetch.d.ts +22 -2
- package/dist/cjs/auth/discovery-fetch.js +440 -124
- package/dist/cjs/auth/discovery-fetch.js.map +1 -1
- package/dist/cjs/auth/interactive-oauth-flow.d.cts +9 -2
- package/dist/cjs/auth/interactive-oauth-flow.d.ts +9 -2
- package/dist/cjs/auth/interactive-oauth-flow.js +29 -11
- package/dist/cjs/auth/interactive-oauth-flow.js.map +1 -1
- package/dist/cjs/auth/oauth-callback-listener.js +4 -0
- package/dist/cjs/auth/oauth-callback-listener.js.map +1 -1
- package/dist/cjs/auth/types.d.cts +29 -4
- package/dist/cjs/auth/types.d.ts +29 -4
- package/dist/cjs/auth/types.js.map +1 -1
- package/dist/cjs/client-helpers.d.cts +5 -6
- package/dist/cjs/client-helpers.d.ts +5 -6
- package/dist/cjs/client-helpers.js +8 -8
- package/dist/cjs/client-helpers.js.map +1 -1
- package/dist/cjs/connection/connect-client.d.cts +12 -11
- package/dist/cjs/connection/connect-client.d.ts +12 -11
- package/dist/cjs/connection/connect-client.js +31 -47
- package/dist/cjs/connection/connect-client.js.map +1 -1
- package/dist/cjs/connection/existing-process-transport.d.cts +1 -2
- package/dist/cjs/connection/existing-process-transport.d.ts +1 -2
- package/dist/cjs/connection/existing-process-transport.js +3 -3
- package/dist/cjs/connection/existing-process-transport.js.map +1 -1
- package/dist/cjs/dcr/dcr-authenticator.d.cts +36 -5
- package/dist/cjs/dcr/dcr-authenticator.d.ts +36 -5
- package/dist/cjs/dcr/dcr-authenticator.js +473 -57
- package/dist/cjs/dcr/dcr-authenticator.js.map +1 -1
- package/dist/cjs/dcr/dynamic-client-registrar.d.cts +2 -2
- package/dist/cjs/dcr/dynamic-client-registrar.d.ts +2 -2
- package/dist/cjs/dcr/dynamic-client-registrar.js +10 -11
- package/dist/cjs/dcr/dynamic-client-registrar.js.map +1 -1
- package/dist/cjs/index.d.cts +2 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +8 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/url-utils.d.cts +17 -0
- package/dist/cjs/lib/url-utils.d.ts +17 -0
- package/dist/cjs/lib/url-utils.js +22 -2
- package/dist/cjs/lib/url-utils.js.map +1 -1
- package/dist/cjs/response-wrappers.d.cts +1 -1
- package/dist/cjs/response-wrappers.d.ts +1 -1
- package/dist/cjs/response-wrappers.js.map +1 -1
- package/dist/cjs/search/search.d.cts +1 -1
- package/dist/cjs/search/search.d.ts +1 -1
- package/dist/cjs/search/search.js.map +1 -1
- package/dist/esm/auth/capability-discovery.js +16 -6
- package/dist/esm/auth/capability-discovery.js.map +1 -1
- package/dist/esm/auth/discovery-fetch.d.ts +22 -2
- package/dist/esm/auth/discovery-fetch.js +234 -54
- package/dist/esm/auth/discovery-fetch.js.map +1 -1
- package/dist/esm/auth/interactive-oauth-flow.d.ts +9 -2
- package/dist/esm/auth/interactive-oauth-flow.js +28 -10
- package/dist/esm/auth/interactive-oauth-flow.js.map +1 -1
- package/dist/esm/auth/oauth-callback-listener.js +4 -0
- package/dist/esm/auth/oauth-callback-listener.js.map +1 -1
- package/dist/esm/auth/types.d.ts +29 -4
- package/dist/esm/auth/types.js.map +1 -1
- package/dist/esm/client-helpers.d.ts +5 -6
- package/dist/esm/client-helpers.js +8 -8
- package/dist/esm/client-helpers.js.map +1 -1
- package/dist/esm/connection/connect-client.d.ts +12 -11
- package/dist/esm/connection/connect-client.js +32 -38
- package/dist/esm/connection/connect-client.js.map +1 -1
- package/dist/esm/connection/existing-process-transport.d.ts +1 -2
- package/dist/esm/connection/existing-process-transport.js +1 -1
- package/dist/esm/connection/existing-process-transport.js.map +1 -1
- package/dist/esm/dcr/dcr-authenticator.d.ts +36 -5
- package/dist/esm/dcr/dcr-authenticator.js +129 -52
- package/dist/esm/dcr/dcr-authenticator.js.map +1 -1
- package/dist/esm/dcr/dynamic-client-registrar.d.ts +2 -2
- package/dist/esm/dcr/dynamic-client-registrar.js +7 -6
- package/dist/esm/dcr/dynamic-client-registrar.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +4 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/url-utils.d.ts +17 -0
- package/dist/esm/lib/url-utils.js +34 -2
- package/dist/esm/lib/url-utils.js.map +1 -1
- package/dist/esm/response-wrappers.d.ts +1 -1
- package/dist/esm/response-wrappers.js.map +1 -1
- package/dist/esm/search/search.d.ts +1 -1
- package/dist/esm/search/search.js.map +1 -1
- package/package.json +4 -4
- package/dist/cjs/monkey-patches.d.cts +0 -6
- package/dist/cjs/monkey-patches.d.ts +0 -6
- package/dist/cjs/monkey-patches.js +0 -233
- package/dist/cjs/monkey-patches.js.map +0 -1
- package/dist/esm/monkey-patches.d.ts +0 -6
- package/dist/esm/monkey-patches.js +0 -32
- package/dist/esm/monkey-patches.js.map +0 -1
|
@@ -25,9 +25,19 @@ _export(exports, {
|
|
|
25
25
|
return readDiscoveryJson;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
var
|
|
28
|
+
var _nodedns = /*#__PURE__*/ _interop_require_default(require("node:dns"));
|
|
29
|
+
var _nodehttp = /*#__PURE__*/ _interop_require_default(require("node:http"));
|
|
30
|
+
var _nodehttps = /*#__PURE__*/ _interop_require_default(require("node:https"));
|
|
29
31
|
var _nodenet = require("node:net");
|
|
30
32
|
var _ipaddr = /*#__PURE__*/ _interop_require_default(require("ipaddr.js"));
|
|
33
|
+
function _array_like_to_array(arr, len) {
|
|
34
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
35
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
36
|
+
return arr2;
|
|
37
|
+
}
|
|
38
|
+
function _array_with_holes(arr) {
|
|
39
|
+
if (Array.isArray(arr)) return arr;
|
|
40
|
+
}
|
|
31
41
|
function _assert_this_initialized(self) {
|
|
32
42
|
if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
33
43
|
return self;
|
|
@@ -81,17 +91,6 @@ function _construct(Parent, args, Class) {
|
|
|
81
91
|
}
|
|
82
92
|
return _construct.apply(null, arguments);
|
|
83
93
|
}
|
|
84
|
-
function _define_property(obj, key, value) {
|
|
85
|
-
if (key in obj) {
|
|
86
|
-
Object.defineProperty(obj, key, {
|
|
87
|
-
value: value,
|
|
88
|
-
enumerable: true,
|
|
89
|
-
configurable: true,
|
|
90
|
-
writable: true
|
|
91
|
-
});
|
|
92
|
-
} else obj[key] = value;
|
|
93
|
-
return obj;
|
|
94
|
-
}
|
|
95
94
|
function _get_prototype_of(o) {
|
|
96
95
|
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
|
97
96
|
return o.__proto__ || Object.getPrototypeOf(o);
|
|
@@ -111,6 +110,12 @@ function _inherits(subClass, superClass) {
|
|
|
111
110
|
});
|
|
112
111
|
if (superClass) _set_prototype_of(subClass, superClass);
|
|
113
112
|
}
|
|
113
|
+
function _instanceof(left, right) {
|
|
114
|
+
"@swc/helpers - instanceof";
|
|
115
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
116
|
+
return !!right[Symbol.hasInstance](left);
|
|
117
|
+
} else return left instanceof right;
|
|
118
|
+
}
|
|
114
119
|
function _interop_require_default(obj) {
|
|
115
120
|
return obj && obj.__esModule ? obj : {
|
|
116
121
|
default: obj
|
|
@@ -127,43 +132,32 @@ function _is_native_reflect_construct() {
|
|
|
127
132
|
return !!result;
|
|
128
133
|
})();
|
|
129
134
|
}
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
function _iterable_to_array_limit(arr, i) {
|
|
136
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
137
|
+
if (_i == null) return;
|
|
138
|
+
var _arr = [];
|
|
139
|
+
var _n = true;
|
|
140
|
+
var _d = false;
|
|
141
|
+
var _s, _e;
|
|
142
|
+
try {
|
|
143
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
144
|
+
_arr.push(_s.value);
|
|
145
|
+
if (i && _arr.length === i) break;
|
|
138
146
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (Object.getOwnPropertySymbols) {
|
|
148
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
149
|
-
if (enumerableOnly) {
|
|
150
|
-
symbols = symbols.filter(function(sym) {
|
|
151
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
152
|
-
});
|
|
147
|
+
} catch (err) {
|
|
148
|
+
_d = true;
|
|
149
|
+
_e = err;
|
|
150
|
+
} finally{
|
|
151
|
+
try {
|
|
152
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
153
|
+
} finally{
|
|
154
|
+
if (_d) throw _e;
|
|
153
155
|
}
|
|
154
|
-
keys.push.apply(keys, symbols);
|
|
155
156
|
}
|
|
156
|
-
return
|
|
157
|
+
return _arr;
|
|
157
158
|
}
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
161
|
-
else {
|
|
162
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
163
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return target;
|
|
159
|
+
function _non_iterable_rest() {
|
|
160
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
167
161
|
}
|
|
168
162
|
function _possible_constructor_return(self, call) {
|
|
169
163
|
if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
|
|
@@ -176,6 +170,9 @@ function _set_prototype_of(o, p) {
|
|
|
176
170
|
};
|
|
177
171
|
return _set_prototype_of(o, p);
|
|
178
172
|
}
|
|
173
|
+
function _sliced_to_array(arr, i) {
|
|
174
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
175
|
+
}
|
|
179
176
|
function _ts_generator(thisArg, body) {
|
|
180
177
|
var f, y, t, _ = {
|
|
181
178
|
label: 0,
|
|
@@ -279,6 +276,14 @@ function _type_of(obj) {
|
|
|
279
276
|
"@swc/helpers - typeof";
|
|
280
277
|
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
281
278
|
}
|
|
279
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
280
|
+
if (!o) return;
|
|
281
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
282
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
283
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
284
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
285
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
286
|
+
}
|
|
282
287
|
function _wrap_native_super(Class) {
|
|
283
288
|
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
284
289
|
_wrap_native_super = function(Class) {
|
|
@@ -350,6 +355,13 @@ function isLoopbackUrl(rawUrl) {
|
|
|
350
355
|
return true; // unparseable - fail closed
|
|
351
356
|
}
|
|
352
357
|
}
|
|
358
|
+
function isLoopbackAddress(address) {
|
|
359
|
+
try {
|
|
360
|
+
return _ipaddr.default.process(address).range() === 'loopback';
|
|
361
|
+
} catch (unused) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
353
365
|
/**
|
|
354
366
|
* Validates scheme and, for literal-IP hosts, address range. `allowLoopback`
|
|
355
367
|
* reflects trust in the calling server, never in `rawUrl` itself.
|
|
@@ -374,22 +386,61 @@ function isLoopbackUrl(rawUrl) {
|
|
|
374
386
|
}
|
|
375
387
|
return url;
|
|
376
388
|
}
|
|
389
|
+
function lookupAll(hostname, lookup, timeoutMs) {
|
|
390
|
+
return new Promise(function(resolve, reject) {
|
|
391
|
+
var settled = false;
|
|
392
|
+
var deadline = setTimeout(function() {
|
|
393
|
+
if (!settled) {
|
|
394
|
+
settled = true;
|
|
395
|
+
reject(new Error('DNS resolution timed out'));
|
|
396
|
+
}
|
|
397
|
+
}, timeoutMs);
|
|
398
|
+
try {
|
|
399
|
+
lookup(hostname, {
|
|
400
|
+
all: true,
|
|
401
|
+
verbatim: true
|
|
402
|
+
}, function(error, addresses) {
|
|
403
|
+
if (settled) return;
|
|
404
|
+
settled = true;
|
|
405
|
+
clearTimeout(deadline);
|
|
406
|
+
if (error || addresses.length === 0) reject(new Error('DNS resolution failed'));
|
|
407
|
+
else resolve(addresses);
|
|
408
|
+
});
|
|
409
|
+
} catch (unused) {
|
|
410
|
+
if (!settled) {
|
|
411
|
+
settled = true;
|
|
412
|
+
clearTimeout(deadline);
|
|
413
|
+
reject(new Error('DNS resolution failed'));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
377
418
|
/**
|
|
378
|
-
* Resolves the hostname
|
|
379
|
-
*
|
|
380
|
-
|
|
419
|
+
* Resolves the hostname once, rejects it unless every returned address is
|
|
420
|
+
* acceptable, and returns the validated set. The set is pinned into the
|
|
421
|
+
* request itself (see `requestOnce`), which is what closes the DNS-rebinding
|
|
422
|
+
* TOCTOU: the transport can only dial addresses that were already validated,
|
|
423
|
+
* and it never resolves the hostname a second time.
|
|
424
|
+
*/ function resolveSafeAddresses(url, context, allowLoopback, lookup, timeoutMs) {
|
|
381
425
|
return _async_to_generator(function() {
|
|
382
|
-
var host,
|
|
426
|
+
var host, loopbackGrant, addresses, unused;
|
|
383
427
|
return _ts_generator(this, function(_state) {
|
|
384
428
|
switch(_state.label){
|
|
385
429
|
case 0:
|
|
386
430
|
host = stripBrackets(url.hostname);
|
|
387
431
|
if ((0, _nodenet.isIP)(host)) return [
|
|
388
|
-
2
|
|
432
|
+
2,
|
|
433
|
+
[
|
|
434
|
+
{
|
|
435
|
+
address: host,
|
|
436
|
+
family: host.includes(':') ? 6 : 4
|
|
437
|
+
}
|
|
438
|
+
]
|
|
389
439
|
]; // literal IP already fully checked in assertSafeUrl
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
440
|
+
// Literal `localhost` under a trusted-loopback grant: still resolved, and the
|
|
441
|
+
// answers must be loopback - the grant covers loopback, not "wherever
|
|
442
|
+
// localhost happens to point".
|
|
443
|
+
loopbackGrant = allowLoopback && isLoopbackHost(host);
|
|
393
444
|
_state.label = 1;
|
|
394
445
|
case 1:
|
|
395
446
|
_state.trys.push([
|
|
@@ -400,16 +451,10 @@ function isLoopbackUrl(rawUrl) {
|
|
|
400
451
|
]);
|
|
401
452
|
return [
|
|
402
453
|
4,
|
|
403
|
-
|
|
404
|
-
all: true,
|
|
405
|
-
verbatim: true
|
|
406
|
-
})
|
|
454
|
+
lookupAll(host, lookup, timeoutMs)
|
|
407
455
|
];
|
|
408
456
|
case 2:
|
|
409
|
-
|
|
410
|
-
addresses = records.map(function(record) {
|
|
411
|
-
return record.address;
|
|
412
|
-
});
|
|
457
|
+
addresses = _state.sent();
|
|
413
458
|
return [
|
|
414
459
|
3,
|
|
415
460
|
4
|
|
@@ -418,49 +463,120 @@ function isLoopbackUrl(rawUrl) {
|
|
|
418
463
|
unused = _state.sent();
|
|
419
464
|
throw new DiscoveryFetchError("Refusing to fetch ".concat(context, ": host could not be resolved"));
|
|
420
465
|
case 4:
|
|
421
|
-
if (
|
|
422
|
-
|
|
466
|
+
if (loopbackGrant) {
|
|
467
|
+
if (!addresses.every(function(record) {
|
|
468
|
+
return isLoopbackAddress(record.address);
|
|
469
|
+
})) {
|
|
470
|
+
throw new DiscoveryFetchError("Refusing to fetch ".concat(context, ": host does not resolve to a loopback address"));
|
|
471
|
+
}
|
|
472
|
+
} else if (addresses.some(function(record) {
|
|
473
|
+
return isBlockedAddress(record.address);
|
|
423
474
|
})) {
|
|
424
475
|
throw new DiscoveryFetchError("Refusing to fetch ".concat(context, ": host resolves to an address that is not publicly routable"));
|
|
425
476
|
}
|
|
426
477
|
return [
|
|
427
|
-
2
|
|
478
|
+
2,
|
|
479
|
+
addresses
|
|
428
480
|
];
|
|
429
481
|
}
|
|
430
482
|
});
|
|
431
483
|
})();
|
|
432
484
|
}
|
|
433
|
-
|
|
485
|
+
/**
|
|
486
|
+
* A `net` lookup that can only ever answer with `addresses` - the set already
|
|
487
|
+
* validated for this URL. The request is built against the original URL (so
|
|
488
|
+
* SNI and certificate verification still see the hostname), but the
|
|
489
|
+
* connection can only land on a validated address.
|
|
490
|
+
*/ function pinnedLookup(addresses) {
|
|
491
|
+
return function(_hostname, options, callback) {
|
|
492
|
+
if ((typeof options === "undefined" ? "undefined" : _type_of(options)) === 'object' && options.all === true) {
|
|
493
|
+
callback(null, addresses);
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
var first = addresses[0];
|
|
497
|
+
if (!first) {
|
|
498
|
+
callback(Object.assign(new Error('no validated address'), {
|
|
499
|
+
code: 'ENOTFOUND'
|
|
500
|
+
}), '', 0);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
callback(null, first.address, first.family);
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function toRequestHeaders(init) {
|
|
507
|
+
var headers = new Headers(init.headers);
|
|
508
|
+
var out = {};
|
|
509
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
510
|
+
try {
|
|
511
|
+
for(var _iterator = headers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
512
|
+
var _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], value = _step_value[1];
|
|
513
|
+
out[name] = value;
|
|
514
|
+
}
|
|
515
|
+
} catch (err) {
|
|
516
|
+
_didIteratorError = true;
|
|
517
|
+
_iteratorError = err;
|
|
518
|
+
} finally{
|
|
519
|
+
try {
|
|
520
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
521
|
+
_iterator.return();
|
|
522
|
+
}
|
|
523
|
+
} finally{
|
|
524
|
+
if (_didIteratorError) {
|
|
525
|
+
throw _iteratorError;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return out;
|
|
530
|
+
}
|
|
531
|
+
function toRequestBody(body) {
|
|
434
532
|
return _async_to_generator(function() {
|
|
435
|
-
var
|
|
533
|
+
var _, reader, chunks, _ref, done, value;
|
|
436
534
|
return _ts_generator(this, function(_state) {
|
|
437
535
|
switch(_state.label){
|
|
438
536
|
case 0:
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
537
|
+
if (body === undefined || body === null) return [
|
|
538
|
+
2,
|
|
539
|
+
undefined
|
|
540
|
+
];
|
|
541
|
+
if (typeof body === 'string') return [
|
|
542
|
+
2,
|
|
543
|
+
Buffer.from(body)
|
|
544
|
+
];
|
|
545
|
+
if (_instanceof(body, URLSearchParams)) return [
|
|
546
|
+
2,
|
|
547
|
+
Buffer.from(body.toString())
|
|
548
|
+
];
|
|
549
|
+
if (!_instanceof(body, Blob)) return [
|
|
445
550
|
3,
|
|
446
551
|
2
|
|
447
552
|
];
|
|
553
|
+
_ = Buffer.from;
|
|
448
554
|
return [
|
|
449
555
|
4,
|
|
450
|
-
|
|
556
|
+
body.arrayBuffer()
|
|
451
557
|
];
|
|
452
558
|
case 1:
|
|
453
|
-
text = _state.sent();
|
|
454
|
-
if (Buffer.byteLength(text, 'utf8') > maxBytes) {
|
|
455
|
-
throw new DiscoveryFetchError("Refusing to read ".concat(context, ": response too large"));
|
|
456
|
-
}
|
|
457
559
|
return [
|
|
458
560
|
2,
|
|
459
|
-
|
|
561
|
+
_.apply(Buffer, [
|
|
562
|
+
_state.sent()
|
|
563
|
+
])
|
|
460
564
|
];
|
|
461
565
|
case 2:
|
|
566
|
+
if (_instanceof(body, ArrayBuffer)) return [
|
|
567
|
+
2,
|
|
568
|
+
Buffer.from(body)
|
|
569
|
+
];
|
|
570
|
+
if (ArrayBuffer.isView(body)) return [
|
|
571
|
+
2,
|
|
572
|
+
Buffer.from(body.buffer, body.byteOffset, body.byteLength)
|
|
573
|
+
];
|
|
574
|
+
if (!(typeof ReadableStream !== 'undefined' && _instanceof(body, ReadableStream))) return [
|
|
575
|
+
3,
|
|
576
|
+
10
|
|
577
|
+
];
|
|
578
|
+
reader = body.getReader();
|
|
462
579
|
chunks = [];
|
|
463
|
-
total = 0;
|
|
464
580
|
_state.label = 3;
|
|
465
581
|
case 3:
|
|
466
582
|
_state.trys.push([
|
|
@@ -481,15 +597,7 @@ function readLimited(response, context, maxBytes) {
|
|
|
481
597
|
3,
|
|
482
598
|
7
|
|
483
599
|
];
|
|
484
|
-
if (
|
|
485
|
-
3,
|
|
486
|
-
6
|
|
487
|
-
];
|
|
488
|
-
total += value.byteLength;
|
|
489
|
-
if (total > maxBytes) {
|
|
490
|
-
throw new DiscoveryFetchError("Refusing to read ".concat(context, ": response too large"));
|
|
491
|
-
}
|
|
492
|
-
chunks.push(value);
|
|
600
|
+
if (value) chunks.push(value);
|
|
493
601
|
_state.label = 6;
|
|
494
602
|
case 6:
|
|
495
603
|
return [
|
|
@@ -511,60 +619,181 @@ function readLimited(response, context, maxBytes) {
|
|
|
511
619
|
2,
|
|
512
620
|
Buffer.concat(chunks.map(function(chunk) {
|
|
513
621
|
return Buffer.from(chunk);
|
|
514
|
-
}))
|
|
622
|
+
}))
|
|
515
623
|
];
|
|
624
|
+
case 10:
|
|
625
|
+
throw new Error('unsupported request body');
|
|
516
626
|
}
|
|
517
627
|
});
|
|
518
628
|
})();
|
|
519
629
|
}
|
|
520
|
-
function
|
|
630
|
+
function toResponse(status, statusText, headers, body) {
|
|
631
|
+
var responseHeaders = new Headers();
|
|
632
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
633
|
+
try {
|
|
634
|
+
for(var _iterator = Object.entries(headers)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
635
|
+
var _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], value = _step_value[1];
|
|
636
|
+
if (value === undefined) continue;
|
|
637
|
+
if (Array.isArray(value)) {
|
|
638
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
639
|
+
try {
|
|
640
|
+
for(var _iterator1 = value[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
641
|
+
var entry = _step1.value;
|
|
642
|
+
responseHeaders.append(name, entry);
|
|
643
|
+
}
|
|
644
|
+
} catch (err) {
|
|
645
|
+
_didIteratorError1 = true;
|
|
646
|
+
_iteratorError1 = err;
|
|
647
|
+
} finally{
|
|
648
|
+
try {
|
|
649
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
650
|
+
_iterator1.return();
|
|
651
|
+
}
|
|
652
|
+
} finally{
|
|
653
|
+
if (_didIteratorError1) {
|
|
654
|
+
throw _iteratorError1;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
} else {
|
|
659
|
+
responseHeaders.append(name, value);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
} catch (err) {
|
|
663
|
+
_didIteratorError = true;
|
|
664
|
+
_iteratorError = err;
|
|
665
|
+
} finally{
|
|
666
|
+
try {
|
|
667
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
668
|
+
_iterator.return();
|
|
669
|
+
}
|
|
670
|
+
} finally{
|
|
671
|
+
if (_didIteratorError) {
|
|
672
|
+
throw _iteratorError;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
// The fetch spec gives these statuses a null body, and the Response
|
|
677
|
+
// constructor rejects a body for them.
|
|
678
|
+
var nullBody = status === 204 || status === 205 || status === 304;
|
|
679
|
+
return new Response(nullBody ? null : body, {
|
|
680
|
+
status: status,
|
|
681
|
+
statusText: statusText,
|
|
682
|
+
headers: responseHeaders
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
function requestOnce(url, init, context, addresses, timeoutMs) {
|
|
521
686
|
return _async_to_generator(function() {
|
|
522
|
-
var
|
|
687
|
+
var _init_method, body, unused, transport, options;
|
|
523
688
|
return _ts_generator(this, function(_state) {
|
|
524
689
|
switch(_state.label){
|
|
525
690
|
case 0:
|
|
526
|
-
return [
|
|
527
|
-
4,
|
|
528
|
-
assertResolvesToSafeAddress(url, context, allowLoopback)
|
|
529
|
-
];
|
|
530
|
-
case 1:
|
|
531
|
-
_state.sent();
|
|
532
|
-
controller = new AbortController();
|
|
533
|
-
timeout = setTimeout(function() {
|
|
534
|
-
return controller.abort();
|
|
535
|
-
}, timeoutMs);
|
|
536
|
-
_state.label = 2;
|
|
537
|
-
case 2:
|
|
538
691
|
_state.trys.push([
|
|
692
|
+
0,
|
|
539
693
|
2,
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
6
|
|
694
|
+
,
|
|
695
|
+
3
|
|
543
696
|
]);
|
|
544
697
|
return [
|
|
545
698
|
4,
|
|
546
|
-
|
|
547
|
-
redirect: 'manual',
|
|
548
|
-
signal: controller.signal
|
|
549
|
-
}))
|
|
699
|
+
toRequestBody(init.body)
|
|
550
700
|
];
|
|
551
|
-
case
|
|
701
|
+
case 1:
|
|
702
|
+
body = _state.sent();
|
|
552
703
|
return [
|
|
553
|
-
|
|
554
|
-
|
|
704
|
+
3,
|
|
705
|
+
3
|
|
555
706
|
];
|
|
556
|
-
case
|
|
707
|
+
case 2:
|
|
557
708
|
unused = _state.sent();
|
|
558
|
-
// Never surface the underlying error (ECONNREFUSED host/port, DNS detail, etc.)
|
|
559
709
|
throw new DiscoveryFetchError("Failed to fetch ".concat(context));
|
|
560
|
-
case
|
|
561
|
-
|
|
710
|
+
case 3:
|
|
711
|
+
transport = url.protocol === 'https:' ? _nodehttps.default : _nodehttp.default;
|
|
712
|
+
options = {
|
|
713
|
+
method: ((_init_method = init.method) !== null && _init_method !== void 0 ? _init_method : 'GET').toUpperCase(),
|
|
714
|
+
headers: toRequestHeaders(init),
|
|
715
|
+
agent: false,
|
|
716
|
+
lookup: pinnedLookup(addresses)
|
|
717
|
+
};
|
|
562
718
|
return [
|
|
563
|
-
|
|
719
|
+
2,
|
|
720
|
+
new Promise(function(resolve, reject) {
|
|
721
|
+
var settled = false;
|
|
722
|
+
var req;
|
|
723
|
+
var res;
|
|
724
|
+
var fail = function fail(message) {
|
|
725
|
+
if (!settled) {
|
|
726
|
+
settled = true;
|
|
727
|
+
clearTimeout(deadline);
|
|
728
|
+
reject(new DiscoveryFetchError(message));
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
var deadline = setTimeout(function() {
|
|
732
|
+
res === null || res === void 0 ? void 0 : res.destroy();
|
|
733
|
+
req === null || req === void 0 ? void 0 : req.destroy();
|
|
734
|
+
fail("Failed to fetch ".concat(context));
|
|
735
|
+
}, timeoutMs);
|
|
736
|
+
try {
|
|
737
|
+
req = transport.request(url, options, function(response) {
|
|
738
|
+
var _response_statusMessage;
|
|
739
|
+
res = response;
|
|
740
|
+
var status = response.statusCode;
|
|
741
|
+
var statusText = (_response_statusMessage = response.statusMessage) !== null && _response_statusMessage !== void 0 ? _response_statusMessage : '';
|
|
742
|
+
if (status === undefined || status < 200 || status > 599) {
|
|
743
|
+
response.destroy();
|
|
744
|
+
fail("Failed to fetch ".concat(context));
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
var chunks = [];
|
|
748
|
+
var total = 0;
|
|
749
|
+
response.on('data', function(chunk) {
|
|
750
|
+
total += chunk.length;
|
|
751
|
+
if (total > MAX_BODY_BYTES) {
|
|
752
|
+
response.destroy();
|
|
753
|
+
fail("Refusing to read ".concat(context, ": response too large"));
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
chunks.push(chunk);
|
|
757
|
+
});
|
|
758
|
+
response.once('error', function() {
|
|
759
|
+
return fail("Failed to fetch ".concat(context));
|
|
760
|
+
});
|
|
761
|
+
response.once('end', function() {
|
|
762
|
+
if (settled) return;
|
|
763
|
+
settled = true;
|
|
764
|
+
clearTimeout(deadline);
|
|
765
|
+
resolve(toResponse(status, statusText, response.headers, Buffer.concat(chunks)));
|
|
766
|
+
});
|
|
767
|
+
});
|
|
768
|
+
} catch (unused) {
|
|
769
|
+
fail("Failed to fetch ".concat(context));
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
req.once('error', function() {
|
|
773
|
+
return fail("Failed to fetch ".concat(context));
|
|
774
|
+
});
|
|
775
|
+
req.end(body);
|
|
776
|
+
})
|
|
564
777
|
];
|
|
565
|
-
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
})();
|
|
781
|
+
}
|
|
782
|
+
function fetchOnce(url, init, context, allowLoopback, timeoutMs, lookup) {
|
|
783
|
+
return _async_to_generator(function() {
|
|
784
|
+
var addresses;
|
|
785
|
+
return _ts_generator(this, function(_state) {
|
|
786
|
+
switch(_state.label){
|
|
787
|
+
case 0:
|
|
566
788
|
return [
|
|
567
|
-
|
|
789
|
+
4,
|
|
790
|
+
resolveSafeAddresses(url, context, allowLoopback, lookup, timeoutMs)
|
|
791
|
+
];
|
|
792
|
+
case 1:
|
|
793
|
+
addresses = _state.sent();
|
|
794
|
+
return [
|
|
795
|
+
2,
|
|
796
|
+
requestOnce(url, init, context, addresses, timeoutMs)
|
|
568
797
|
];
|
|
569
798
|
}
|
|
570
799
|
});
|
|
@@ -572,17 +801,17 @@ function fetchOnce(url, init, context, allowLoopback, timeoutMs) {
|
|
|
572
801
|
}
|
|
573
802
|
function discoveryFetch(_0) {
|
|
574
803
|
return _async_to_generator(function(rawUrl) {
|
|
575
|
-
var init, context, options, _options_allowLoopback, allowLoopback, _options_timeoutMs, timeoutMs, url, response, redirectsLeft, location, nextUrl;
|
|
804
|
+
var init, context, options, _options_allowLoopback, allowLoopback, _options_timeoutMs, timeoutMs, _options_lookup, lookup, url, response, redirectsLeft, location, nextUrl;
|
|
576
805
|
var _arguments = arguments;
|
|
577
806
|
return _ts_generator(this, function(_state) {
|
|
578
807
|
switch(_state.label){
|
|
579
808
|
case 0:
|
|
580
809
|
init = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {}, context = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : 'discovery URL', options = _arguments.length > 3 && _arguments[3] !== void 0 ? _arguments[3] : {};
|
|
581
|
-
_options_allowLoopback = options.allowLoopback, allowLoopback = _options_allowLoopback === void 0 ? false : _options_allowLoopback, _options_timeoutMs = options.timeoutMs, timeoutMs = _options_timeoutMs === void 0 ? DEFAULT_TIMEOUT_MS : _options_timeoutMs;
|
|
810
|
+
_options_allowLoopback = options.allowLoopback, allowLoopback = _options_allowLoopback === void 0 ? false : _options_allowLoopback, _options_timeoutMs = options.timeoutMs, timeoutMs = _options_timeoutMs === void 0 ? DEFAULT_TIMEOUT_MS : _options_timeoutMs, _options_lookup = options.lookup, lookup = _options_lookup === void 0 ? _nodedns.default.lookup : _options_lookup;
|
|
582
811
|
url = assertSafeUrl(rawUrl, context, allowLoopback);
|
|
583
812
|
return [
|
|
584
813
|
4,
|
|
585
|
-
fetchOnce(url, init, context, allowLoopback, timeoutMs)
|
|
814
|
+
fetchOnce(url, init, context, allowLoopback, timeoutMs, lookup)
|
|
586
815
|
];
|
|
587
816
|
case 1:
|
|
588
817
|
response = _state.sent();
|
|
@@ -611,7 +840,7 @@ function discoveryFetch(_0) {
|
|
|
611
840
|
url = assertSafeUrl(nextUrl.toString(), context, allowLoopback);
|
|
612
841
|
return [
|
|
613
842
|
4,
|
|
614
|
-
fetchOnce(url, init, context, allowLoopback, timeoutMs)
|
|
843
|
+
fetchOnce(url, init, context, allowLoopback, timeoutMs, lookup)
|
|
615
844
|
];
|
|
616
845
|
case 3:
|
|
617
846
|
response = _state.sent();
|
|
@@ -655,4 +884,91 @@ function readDiscoveryJson(response, context) {
|
|
|
655
884
|
});
|
|
656
885
|
})();
|
|
657
886
|
}
|
|
887
|
+
function readLimited(response, context, maxBytes) {
|
|
888
|
+
return _async_to_generator(function() {
|
|
889
|
+
var _response_body, contentLength, reader, text, chunks, total, _ref, done, value;
|
|
890
|
+
return _ts_generator(this, function(_state) {
|
|
891
|
+
switch(_state.label){
|
|
892
|
+
case 0:
|
|
893
|
+
contentLength = response.headers.get('content-length');
|
|
894
|
+
if (contentLength && Number(contentLength) > maxBytes) {
|
|
895
|
+
throw new DiscoveryFetchError("Refusing to read ".concat(context, ": response too large"));
|
|
896
|
+
}
|
|
897
|
+
reader = (_response_body = response.body) === null || _response_body === void 0 ? void 0 : _response_body.getReader();
|
|
898
|
+
if (!!reader) return [
|
|
899
|
+
3,
|
|
900
|
+
2
|
|
901
|
+
];
|
|
902
|
+
return [
|
|
903
|
+
4,
|
|
904
|
+
response.text()
|
|
905
|
+
];
|
|
906
|
+
case 1:
|
|
907
|
+
text = _state.sent();
|
|
908
|
+
if (Buffer.byteLength(text, 'utf8') > maxBytes) {
|
|
909
|
+
throw new DiscoveryFetchError("Refusing to read ".concat(context, ": response too large"));
|
|
910
|
+
}
|
|
911
|
+
return [
|
|
912
|
+
2,
|
|
913
|
+
text
|
|
914
|
+
];
|
|
915
|
+
case 2:
|
|
916
|
+
chunks = [];
|
|
917
|
+
total = 0;
|
|
918
|
+
_state.label = 3;
|
|
919
|
+
case 3:
|
|
920
|
+
_state.trys.push([
|
|
921
|
+
3,
|
|
922
|
+
,
|
|
923
|
+
8,
|
|
924
|
+
9
|
|
925
|
+
]);
|
|
926
|
+
_state.label = 4;
|
|
927
|
+
case 4:
|
|
928
|
+
return [
|
|
929
|
+
4,
|
|
930
|
+
reader.read()
|
|
931
|
+
];
|
|
932
|
+
case 5:
|
|
933
|
+
_ref = _state.sent(), done = _ref.done, value = _ref.value;
|
|
934
|
+
if (done) return [
|
|
935
|
+
3,
|
|
936
|
+
7
|
|
937
|
+
];
|
|
938
|
+
if (!value) return [
|
|
939
|
+
3,
|
|
940
|
+
6
|
|
941
|
+
];
|
|
942
|
+
total += value.byteLength;
|
|
943
|
+
if (total > maxBytes) {
|
|
944
|
+
throw new DiscoveryFetchError("Refusing to read ".concat(context, ": response too large"));
|
|
945
|
+
}
|
|
946
|
+
chunks.push(value);
|
|
947
|
+
_state.label = 6;
|
|
948
|
+
case 6:
|
|
949
|
+
return [
|
|
950
|
+
3,
|
|
951
|
+
4
|
|
952
|
+
];
|
|
953
|
+
case 7:
|
|
954
|
+
return [
|
|
955
|
+
3,
|
|
956
|
+
9
|
|
957
|
+
];
|
|
958
|
+
case 8:
|
|
959
|
+
reader.releaseLock();
|
|
960
|
+
return [
|
|
961
|
+
7
|
|
962
|
+
];
|
|
963
|
+
case 9:
|
|
964
|
+
return [
|
|
965
|
+
2,
|
|
966
|
+
Buffer.concat(chunks.map(function(chunk) {
|
|
967
|
+
return Buffer.from(chunk);
|
|
968
|
+
})).toString('utf8')
|
|
969
|
+
];
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
})();
|
|
973
|
+
}
|
|
658
974
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|