diff --git a/dist/index.js b/dist/index.js
index 54c4593..5e4459a 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -1984,7 +1984,8 @@ const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
const stream = __importStar(__nccwpck_require__(2781));
const util_1 = __nccwpck_require__(3837);
-const got_1 = __importDefault(__nccwpck_require__(3061));
+// eslint-disable-next-line import/no-named-as-default
+const got_1 = __importDefault(__nccwpck_require__(2430));
const asyncStream = (0, util_1.promisify)(stream.pipeline);
function getCheckRunContext() {
if (github.context.eventName === 'workflow_run') {
@@ -8813,582 +8814,6 @@ exports.request = request;
//# sourceMappingURL=index.js.map
-/***/ }),
-
-/***/ 7678:
-/***/ ((module, exports) => {
-
-"use strict";
-
-///
-///
-///
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const typedArrayTypeNames = [
- 'Int8Array',
- 'Uint8Array',
- 'Uint8ClampedArray',
- 'Int16Array',
- 'Uint16Array',
- 'Int32Array',
- 'Uint32Array',
- 'Float32Array',
- 'Float64Array',
- 'BigInt64Array',
- 'BigUint64Array'
-];
-function isTypedArrayName(name) {
- return typedArrayTypeNames.includes(name);
-}
-const objectTypeNames = [
- 'Function',
- 'Generator',
- 'AsyncGenerator',
- 'GeneratorFunction',
- 'AsyncGeneratorFunction',
- 'AsyncFunction',
- 'Observable',
- 'Array',
- 'Buffer',
- 'Blob',
- 'Object',
- 'RegExp',
- 'Date',
- 'Error',
- 'Map',
- 'Set',
- 'WeakMap',
- 'WeakSet',
- 'ArrayBuffer',
- 'SharedArrayBuffer',
- 'DataView',
- 'Promise',
- 'URL',
- 'FormData',
- 'URLSearchParams',
- 'HTMLElement',
- ...typedArrayTypeNames
-];
-function isObjectTypeName(name) {
- return objectTypeNames.includes(name);
-}
-const primitiveTypeNames = [
- 'null',
- 'undefined',
- 'string',
- 'number',
- 'bigint',
- 'boolean',
- 'symbol'
-];
-function isPrimitiveTypeName(name) {
- return primitiveTypeNames.includes(name);
-}
-// eslint-disable-next-line @typescript-eslint/ban-types
-function isOfType(type) {
- return (value) => typeof value === type;
-}
-const { toString } = Object.prototype;
-const getObjectType = (value) => {
- const objectTypeName = toString.call(value).slice(8, -1);
- if (/HTML\w+Element/.test(objectTypeName) && is.domElement(value)) {
- return 'HTMLElement';
- }
- if (isObjectTypeName(objectTypeName)) {
- return objectTypeName;
- }
- return undefined;
-};
-const isObjectOfType = (type) => (value) => getObjectType(value) === type;
-function is(value) {
- if (value === null) {
- return 'null';
- }
- switch (typeof value) {
- case 'undefined':
- return 'undefined';
- case 'string':
- return 'string';
- case 'number':
- return 'number';
- case 'boolean':
- return 'boolean';
- case 'function':
- return 'Function';
- case 'bigint':
- return 'bigint';
- case 'symbol':
- return 'symbol';
- default:
- }
- if (is.observable(value)) {
- return 'Observable';
- }
- if (is.array(value)) {
- return 'Array';
- }
- if (is.buffer(value)) {
- return 'Buffer';
- }
- const tagType = getObjectType(value);
- if (tagType) {
- return tagType;
- }
- if (value instanceof String || value instanceof Boolean || value instanceof Number) {
- throw new TypeError('Please don\'t use object wrappers for primitive types');
- }
- return 'Object';
-}
-is.undefined = isOfType('undefined');
-is.string = isOfType('string');
-const isNumberType = isOfType('number');
-is.number = (value) => isNumberType(value) && !is.nan(value);
-is.bigint = isOfType('bigint');
-// eslint-disable-next-line @typescript-eslint/ban-types
-is.function_ = isOfType('function');
-is.null_ = (value) => value === null;
-is.class_ = (value) => is.function_(value) && value.toString().startsWith('class ');
-is.boolean = (value) => value === true || value === false;
-is.symbol = isOfType('symbol');
-is.numericString = (value) => is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
-is.array = (value, assertion) => {
- if (!Array.isArray(value)) {
- return false;
- }
- if (!is.function_(assertion)) {
- return true;
- }
- return value.every(assertion);
-};
-is.buffer = (value) => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = value) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.isBuffer) === null || _c === void 0 ? void 0 : _c.call(_b, value)) !== null && _d !== void 0 ? _d : false; };
-is.blob = (value) => isObjectOfType('Blob')(value);
-is.nullOrUndefined = (value) => is.null_(value) || is.undefined(value);
-is.object = (value) => !is.null_(value) && (typeof value === 'object' || is.function_(value));
-is.iterable = (value) => { var _a; return is.function_((_a = value) === null || _a === void 0 ? void 0 : _a[Symbol.iterator]); };
-is.asyncIterable = (value) => { var _a; return is.function_((_a = value) === null || _a === void 0 ? void 0 : _a[Symbol.asyncIterator]); };
-is.generator = (value) => { var _a, _b; return is.iterable(value) && is.function_((_a = value) === null || _a === void 0 ? void 0 : _a.next) && is.function_((_b = value) === null || _b === void 0 ? void 0 : _b.throw); };
-is.asyncGenerator = (value) => is.asyncIterable(value) && is.function_(value.next) && is.function_(value.throw);
-is.nativePromise = (value) => isObjectOfType('Promise')(value);
-const hasPromiseAPI = (value) => {
- var _a, _b;
- return is.function_((_a = value) === null || _a === void 0 ? void 0 : _a.then) &&
- is.function_((_b = value) === null || _b === void 0 ? void 0 : _b.catch);
-};
-is.promise = (value) => is.nativePromise(value) || hasPromiseAPI(value);
-is.generatorFunction = isObjectOfType('GeneratorFunction');
-is.asyncGeneratorFunction = (value) => getObjectType(value) === 'AsyncGeneratorFunction';
-is.asyncFunction = (value) => getObjectType(value) === 'AsyncFunction';
-// eslint-disable-next-line no-prototype-builtins, @typescript-eslint/ban-types
-is.boundFunction = (value) => is.function_(value) && !value.hasOwnProperty('prototype');
-is.regExp = isObjectOfType('RegExp');
-is.date = isObjectOfType('Date');
-is.error = isObjectOfType('Error');
-is.map = (value) => isObjectOfType('Map')(value);
-is.set = (value) => isObjectOfType('Set')(value);
-is.weakMap = (value) => isObjectOfType('WeakMap')(value);
-is.weakSet = (value) => isObjectOfType('WeakSet')(value);
-is.int8Array = isObjectOfType('Int8Array');
-is.uint8Array = isObjectOfType('Uint8Array');
-is.uint8ClampedArray = isObjectOfType('Uint8ClampedArray');
-is.int16Array = isObjectOfType('Int16Array');
-is.uint16Array = isObjectOfType('Uint16Array');
-is.int32Array = isObjectOfType('Int32Array');
-is.uint32Array = isObjectOfType('Uint32Array');
-is.float32Array = isObjectOfType('Float32Array');
-is.float64Array = isObjectOfType('Float64Array');
-is.bigInt64Array = isObjectOfType('BigInt64Array');
-is.bigUint64Array = isObjectOfType('BigUint64Array');
-is.arrayBuffer = isObjectOfType('ArrayBuffer');
-is.sharedArrayBuffer = isObjectOfType('SharedArrayBuffer');
-is.dataView = isObjectOfType('DataView');
-is.enumCase = (value, targetEnum) => Object.values(targetEnum).includes(value);
-is.directInstanceOf = (instance, class_) => Object.getPrototypeOf(instance) === class_.prototype;
-is.urlInstance = (value) => isObjectOfType('URL')(value);
-is.urlString = (value) => {
- if (!is.string(value)) {
- return false;
- }
- try {
- new URL(value); // eslint-disable-line no-new
- return true;
- }
- catch (_a) {
- return false;
- }
-};
-// Example: `is.truthy = (value: unknown): value is (not false | not 0 | not '' | not undefined | not null) => Boolean(value);`
-is.truthy = (value) => Boolean(value);
-// Example: `is.falsy = (value: unknown): value is (not true | 0 | '' | undefined | null) => Boolean(value);`
-is.falsy = (value) => !value;
-is.nan = (value) => Number.isNaN(value);
-is.primitive = (value) => is.null_(value) || isPrimitiveTypeName(typeof value);
-is.integer = (value) => Number.isInteger(value);
-is.safeInteger = (value) => Number.isSafeInteger(value);
-is.plainObject = (value) => {
- // From: https://github.com/sindresorhus/is-plain-obj/blob/main/index.js
- if (toString.call(value) !== '[object Object]') {
- return false;
- }
- const prototype = Object.getPrototypeOf(value);
- return prototype === null || prototype === Object.getPrototypeOf({});
-};
-is.typedArray = (value) => isTypedArrayName(getObjectType(value));
-const isValidLength = (value) => is.safeInteger(value) && value >= 0;
-is.arrayLike = (value) => !is.nullOrUndefined(value) && !is.function_(value) && isValidLength(value.length);
-is.inRange = (value, range) => {
- if (is.number(range)) {
- return value >= Math.min(0, range) && value <= Math.max(range, 0);
- }
- if (is.array(range) && range.length === 2) {
- return value >= Math.min(...range) && value <= Math.max(...range);
- }
- throw new TypeError(`Invalid range: ${JSON.stringify(range)}`);
-};
-const NODE_TYPE_ELEMENT = 1;
-const DOM_PROPERTIES_TO_CHECK = [
- 'innerHTML',
- 'ownerDocument',
- 'style',
- 'attributes',
- 'nodeValue'
-];
-is.domElement = (value) => {
- return is.object(value) &&
- value.nodeType === NODE_TYPE_ELEMENT &&
- is.string(value.nodeName) &&
- !is.plainObject(value) &&
- DOM_PROPERTIES_TO_CHECK.every(property => property in value);
-};
-is.observable = (value) => {
- var _a, _b, _c, _d;
- if (!value) {
- return false;
- }
- // eslint-disable-next-line no-use-extend-native/no-use-extend-native
- if (value === ((_b = (_a = value)[Symbol.observable]) === null || _b === void 0 ? void 0 : _b.call(_a))) {
- return true;
- }
- if (value === ((_d = (_c = value)['@@observable']) === null || _d === void 0 ? void 0 : _d.call(_c))) {
- return true;
- }
- return false;
-};
-is.nodeStream = (value) => is.object(value) && is.function_(value.pipe) && !is.observable(value);
-is.infinite = (value) => value === Infinity || value === -Infinity;
-const isAbsoluteMod2 = (remainder) => (value) => is.integer(value) && Math.abs(value % 2) === remainder;
-is.evenInteger = isAbsoluteMod2(0);
-is.oddInteger = isAbsoluteMod2(1);
-is.emptyArray = (value) => is.array(value) && value.length === 0;
-is.nonEmptyArray = (value) => is.array(value) && value.length > 0;
-is.emptyString = (value) => is.string(value) && value.length === 0;
-const isWhiteSpaceString = (value) => is.string(value) && !/\S/.test(value);
-is.emptyStringOrWhitespace = (value) => is.emptyString(value) || isWhiteSpaceString(value);
-// TODO: Use `not ''` when the `not` operator is available.
-is.nonEmptyString = (value) => is.string(value) && value.length > 0;
-// TODO: Use `not ''` when the `not` operator is available.
-is.nonEmptyStringAndNotWhitespace = (value) => is.string(value) && !is.emptyStringOrWhitespace(value);
-is.emptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length === 0;
-// TODO: Use `not` operator here to remove `Map` and `Set` from type guard:
-// - https://github.com/Microsoft/TypeScript/pull/29317
-is.nonEmptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length > 0;
-is.emptySet = (value) => is.set(value) && value.size === 0;
-is.nonEmptySet = (value) => is.set(value) && value.size > 0;
-is.emptyMap = (value) => is.map(value) && value.size === 0;
-is.nonEmptyMap = (value) => is.map(value) && value.size > 0;
-// `PropertyKey` is any value that can be used as an object key (string, number, or symbol)
-is.propertyKey = (value) => is.any([is.string, is.number, is.symbol], value);
-is.formData = (value) => isObjectOfType('FormData')(value);
-is.urlSearchParams = (value) => isObjectOfType('URLSearchParams')(value);
-const predicateOnArray = (method, predicate, values) => {
- if (!is.function_(predicate)) {
- throw new TypeError(`Invalid predicate: ${JSON.stringify(predicate)}`);
- }
- if (values.length === 0) {
- throw new TypeError('Invalid number of values');
- }
- return method.call(values, predicate);
-};
-is.any = (predicate, ...values) => {
- const predicates = is.array(predicate) ? predicate : [predicate];
- return predicates.some(singlePredicate => predicateOnArray(Array.prototype.some, singlePredicate, values));
-};
-is.all = (predicate, ...values) => predicateOnArray(Array.prototype.every, predicate, values);
-const assertType = (condition, description, value, options = {}) => {
- if (!condition) {
- const { multipleValues } = options;
- const valuesMessage = multipleValues ?
- `received values of types ${[
- ...new Set(value.map(singleValue => `\`${is(singleValue)}\``))
- ].join(', ')}` :
- `received value of type \`${is(value)}\``;
- throw new TypeError(`Expected value which is \`${description}\`, ${valuesMessage}.`);
- }
-};
-exports.assert = {
- // Unknowns.
- undefined: (value) => assertType(is.undefined(value), 'undefined', value),
- string: (value) => assertType(is.string(value), 'string', value),
- number: (value) => assertType(is.number(value), 'number', value),
- bigint: (value) => assertType(is.bigint(value), 'bigint', value),
- // eslint-disable-next-line @typescript-eslint/ban-types
- function_: (value) => assertType(is.function_(value), 'Function', value),
- null_: (value) => assertType(is.null_(value), 'null', value),
- class_: (value) => assertType(is.class_(value), "Class" /* class_ */, value),
- boolean: (value) => assertType(is.boolean(value), 'boolean', value),
- symbol: (value) => assertType(is.symbol(value), 'symbol', value),
- numericString: (value) => assertType(is.numericString(value), "string with a number" /* numericString */, value),
- array: (value, assertion) => {
- const assert = assertType;
- assert(is.array(value), 'Array', value);
- if (assertion) {
- value.forEach(assertion);
- }
- },
- buffer: (value) => assertType(is.buffer(value), 'Buffer', value),
- blob: (value) => assertType(is.blob(value), 'Blob', value),
- nullOrUndefined: (value) => assertType(is.nullOrUndefined(value), "null or undefined" /* nullOrUndefined */, value),
- object: (value) => assertType(is.object(value), 'Object', value),
- iterable: (value) => assertType(is.iterable(value), "Iterable" /* iterable */, value),
- asyncIterable: (value) => assertType(is.asyncIterable(value), "AsyncIterable" /* asyncIterable */, value),
- generator: (value) => assertType(is.generator(value), 'Generator', value),
- asyncGenerator: (value) => assertType(is.asyncGenerator(value), 'AsyncGenerator', value),
- nativePromise: (value) => assertType(is.nativePromise(value), "native Promise" /* nativePromise */, value),
- promise: (value) => assertType(is.promise(value), 'Promise', value),
- generatorFunction: (value) => assertType(is.generatorFunction(value), 'GeneratorFunction', value),
- asyncGeneratorFunction: (value) => assertType(is.asyncGeneratorFunction(value), 'AsyncGeneratorFunction', value),
- // eslint-disable-next-line @typescript-eslint/ban-types
- asyncFunction: (value) => assertType(is.asyncFunction(value), 'AsyncFunction', value),
- // eslint-disable-next-line @typescript-eslint/ban-types
- boundFunction: (value) => assertType(is.boundFunction(value), 'Function', value),
- regExp: (value) => assertType(is.regExp(value), 'RegExp', value),
- date: (value) => assertType(is.date(value), 'Date', value),
- error: (value) => assertType(is.error(value), 'Error', value),
- map: (value) => assertType(is.map(value), 'Map', value),
- set: (value) => assertType(is.set(value), 'Set', value),
- weakMap: (value) => assertType(is.weakMap(value), 'WeakMap', value),
- weakSet: (value) => assertType(is.weakSet(value), 'WeakSet', value),
- int8Array: (value) => assertType(is.int8Array(value), 'Int8Array', value),
- uint8Array: (value) => assertType(is.uint8Array(value), 'Uint8Array', value),
- uint8ClampedArray: (value) => assertType(is.uint8ClampedArray(value), 'Uint8ClampedArray', value),
- int16Array: (value) => assertType(is.int16Array(value), 'Int16Array', value),
- uint16Array: (value) => assertType(is.uint16Array(value), 'Uint16Array', value),
- int32Array: (value) => assertType(is.int32Array(value), 'Int32Array', value),
- uint32Array: (value) => assertType(is.uint32Array(value), 'Uint32Array', value),
- float32Array: (value) => assertType(is.float32Array(value), 'Float32Array', value),
- float64Array: (value) => assertType(is.float64Array(value), 'Float64Array', value),
- bigInt64Array: (value) => assertType(is.bigInt64Array(value), 'BigInt64Array', value),
- bigUint64Array: (value) => assertType(is.bigUint64Array(value), 'BigUint64Array', value),
- arrayBuffer: (value) => assertType(is.arrayBuffer(value), 'ArrayBuffer', value),
- sharedArrayBuffer: (value) => assertType(is.sharedArrayBuffer(value), 'SharedArrayBuffer', value),
- dataView: (value) => assertType(is.dataView(value), 'DataView', value),
- enumCase: (value, targetEnum) => assertType(is.enumCase(value, targetEnum), 'EnumCase', value),
- urlInstance: (value) => assertType(is.urlInstance(value), 'URL', value),
- urlString: (value) => assertType(is.urlString(value), "string with a URL" /* urlString */, value),
- truthy: (value) => assertType(is.truthy(value), "truthy" /* truthy */, value),
- falsy: (value) => assertType(is.falsy(value), "falsy" /* falsy */, value),
- nan: (value) => assertType(is.nan(value), "NaN" /* nan */, value),
- primitive: (value) => assertType(is.primitive(value), "primitive" /* primitive */, value),
- integer: (value) => assertType(is.integer(value), "integer" /* integer */, value),
- safeInteger: (value) => assertType(is.safeInteger(value), "integer" /* safeInteger */, value),
- plainObject: (value) => assertType(is.plainObject(value), "plain object" /* plainObject */, value),
- typedArray: (value) => assertType(is.typedArray(value), "TypedArray" /* typedArray */, value),
- arrayLike: (value) => assertType(is.arrayLike(value), "array-like" /* arrayLike */, value),
- domElement: (value) => assertType(is.domElement(value), "HTMLElement" /* domElement */, value),
- observable: (value) => assertType(is.observable(value), 'Observable', value),
- nodeStream: (value) => assertType(is.nodeStream(value), "Node.js Stream" /* nodeStream */, value),
- infinite: (value) => assertType(is.infinite(value), "infinite number" /* infinite */, value),
- emptyArray: (value) => assertType(is.emptyArray(value), "empty array" /* emptyArray */, value),
- nonEmptyArray: (value) => assertType(is.nonEmptyArray(value), "non-empty array" /* nonEmptyArray */, value),
- emptyString: (value) => assertType(is.emptyString(value), "empty string" /* emptyString */, value),
- emptyStringOrWhitespace: (value) => assertType(is.emptyStringOrWhitespace(value), "empty string or whitespace" /* emptyStringOrWhitespace */, value),
- nonEmptyString: (value) => assertType(is.nonEmptyString(value), "non-empty string" /* nonEmptyString */, value),
- nonEmptyStringAndNotWhitespace: (value) => assertType(is.nonEmptyStringAndNotWhitespace(value), "non-empty string and not whitespace" /* nonEmptyStringAndNotWhitespace */, value),
- emptyObject: (value) => assertType(is.emptyObject(value), "empty object" /* emptyObject */, value),
- nonEmptyObject: (value) => assertType(is.nonEmptyObject(value), "non-empty object" /* nonEmptyObject */, value),
- emptySet: (value) => assertType(is.emptySet(value), "empty set" /* emptySet */, value),
- nonEmptySet: (value) => assertType(is.nonEmptySet(value), "non-empty set" /* nonEmptySet */, value),
- emptyMap: (value) => assertType(is.emptyMap(value), "empty map" /* emptyMap */, value),
- nonEmptyMap: (value) => assertType(is.nonEmptyMap(value), "non-empty map" /* nonEmptyMap */, value),
- propertyKey: (value) => assertType(is.propertyKey(value), 'PropertyKey', value),
- formData: (value) => assertType(is.formData(value), 'FormData', value),
- urlSearchParams: (value) => assertType(is.urlSearchParams(value), 'URLSearchParams', value),
- // Numbers.
- evenInteger: (value) => assertType(is.evenInteger(value), "even integer" /* evenInteger */, value),
- oddInteger: (value) => assertType(is.oddInteger(value), "odd integer" /* oddInteger */, value),
- // Two arguments.
- directInstanceOf: (instance, class_) => assertType(is.directInstanceOf(instance, class_), "T" /* directInstanceOf */, instance),
- inRange: (value, range) => assertType(is.inRange(value, range), "in range" /* inRange */, value),
- // Variadic functions.
- any: (predicate, ...values) => {
- return assertType(is.any(predicate, ...values), "predicate returns truthy for any value" /* any */, values, { multipleValues: true });
- },
- all: (predicate, ...values) => assertType(is.all(predicate, ...values), "predicate returns truthy for all values" /* all */, values, { multipleValues: true })
-};
-// Some few keywords are reserved, but we'll populate them for Node.js users
-// See https://github.com/Microsoft/TypeScript/issues/2536
-Object.defineProperties(is, {
- class: {
- value: is.class_
- },
- function: {
- value: is.function_
- },
- null: {
- value: is.null_
- }
-});
-Object.defineProperties(exports.assert, {
- class: {
- value: exports.assert.class_
- },
- function: {
- value: exports.assert.function_
- },
- null: {
- value: exports.assert.null_
- }
-});
-exports["default"] = is;
-// For CommonJS default export support
-module.exports = is;
-module.exports["default"] = is;
-module.exports.assert = exports.assert;
-
-
-/***/ }),
-
-/***/ 8097:
-/***/ ((module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const defer_to_connect_1 = __nccwpck_require__(6214);
-const util_1 = __nccwpck_require__(3837);
-const nodejsMajorVersion = Number(process.versions.node.split('.')[0]);
-const timer = (request) => {
- if (request.timings) {
- return request.timings;
- }
- const timings = {
- start: Date.now(),
- socket: undefined,
- lookup: undefined,
- connect: undefined,
- secureConnect: undefined,
- upload: undefined,
- response: undefined,
- end: undefined,
- error: undefined,
- abort: undefined,
- phases: {
- wait: undefined,
- dns: undefined,
- tcp: undefined,
- tls: undefined,
- request: undefined,
- firstByte: undefined,
- download: undefined,
- total: undefined
- }
- };
- request.timings = timings;
- const handleError = (origin) => {
- const emit = origin.emit.bind(origin);
- origin.emit = (event, ...args) => {
- // Catches the `error` event
- if (event === 'error') {
- timings.error = Date.now();
- timings.phases.total = timings.error - timings.start;
- origin.emit = emit;
- }
- // Saves the original behavior
- return emit(event, ...args);
- };
- };
- handleError(request);
- const onAbort = () => {
- timings.abort = Date.now();
- // Let the `end` response event be responsible for setting the total phase,
- // unless the Node.js major version is >= 13.
- if (!timings.response || nodejsMajorVersion >= 13) {
- timings.phases.total = Date.now() - timings.start;
- }
- };
- request.prependOnceListener('abort', onAbort);
- const onSocket = (socket) => {
- timings.socket = Date.now();
- timings.phases.wait = timings.socket - timings.start;
- if (util_1.types.isProxy(socket)) {
- return;
- }
- const lookupListener = () => {
- timings.lookup = Date.now();
- timings.phases.dns = timings.lookup - timings.socket;
- };
- socket.prependOnceListener('lookup', lookupListener);
- defer_to_connect_1.default(socket, {
- connect: () => {
- timings.connect = Date.now();
- if (timings.lookup === undefined) {
- socket.removeListener('lookup', lookupListener);
- timings.lookup = timings.connect;
- timings.phases.dns = timings.lookup - timings.socket;
- }
- timings.phases.tcp = timings.connect - timings.lookup;
- // This callback is called before flushing any data,
- // so we don't need to set `timings.phases.request` here.
- },
- secureConnect: () => {
- timings.secureConnect = Date.now();
- timings.phases.tls = timings.secureConnect - timings.connect;
- }
- });
- };
- if (request.socket) {
- onSocket(request.socket);
- }
- else {
- request.prependOnceListener('socket', onSocket);
- }
- const onUpload = () => {
- var _a;
- timings.upload = Date.now();
- timings.phases.request = timings.upload - ((_a = timings.secureConnect) !== null && _a !== void 0 ? _a : timings.connect);
- };
- const writableFinished = () => {
- if (typeof request.writableFinished === 'boolean') {
- return request.writableFinished;
- }
- // Node.js doesn't have `request.writableFinished` property
- return request.finished && request.outputSize === 0 && (!request.socket || request.socket.writableLength === 0);
- };
- if (writableFinished()) {
- onUpload();
- }
- else {
- request.prependOnceListener('finish', onUpload);
- }
- request.prependOnceListener('response', (response) => {
- timings.response = Date.now();
- timings.phases.firstByte = timings.response - timings.upload;
- response.timings = timings;
- handleError(response);
- response.prependOnceListener('end', () => {
- timings.end = Date.now();
- timings.phases.download = timings.end - timings.response;
- timings.phases.total = timings.end - timings.start;
- });
- response.prependOnceListener('aborted', onAbort);
- });
- return timings;
-};
-exports["default"] = timer;
-// For CommonJS default export support
-module.exports = timer;
-module.exports["default"] = timer;
-
-
/***/ }),
/***/ 6761:
@@ -13332,941 +12757,6 @@ exports.flatten = (...args) => {
};
-/***/ }),
-
-/***/ 2286:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-"use strict";
-
-const {
- V4MAPPED,
- ADDRCONFIG,
- ALL,
- promises: {
- Resolver: AsyncResolver
- },
- lookup: dnsLookup
-} = __nccwpck_require__(9523);
-const {promisify} = __nccwpck_require__(3837);
-const os = __nccwpck_require__(2037);
-
-const kCacheableLookupCreateConnection = Symbol('cacheableLookupCreateConnection');
-const kCacheableLookupInstance = Symbol('cacheableLookupInstance');
-const kExpires = Symbol('expires');
-
-const supportsALL = typeof ALL === 'number';
-
-const verifyAgent = agent => {
- if (!(agent && typeof agent.createConnection === 'function')) {
- throw new Error('Expected an Agent instance as the first argument');
- }
-};
-
-const map4to6 = entries => {
- for (const entry of entries) {
- if (entry.family === 6) {
- continue;
- }
-
- entry.address = `::ffff:${entry.address}`;
- entry.family = 6;
- }
-};
-
-const getIfaceInfo = () => {
- let has4 = false;
- let has6 = false;
-
- for (const device of Object.values(os.networkInterfaces())) {
- for (const iface of device) {
- if (iface.internal) {
- continue;
- }
-
- if (iface.family === 'IPv6') {
- has6 = true;
- } else {
- has4 = true;
- }
-
- if (has4 && has6) {
- return {has4, has6};
- }
- }
- }
-
- return {has4, has6};
-};
-
-const isIterable = map => {
- return Symbol.iterator in map;
-};
-
-const ttl = {ttl: true};
-const all = {all: true};
-
-class CacheableLookup {
- constructor({
- cache = new Map(),
- maxTtl = Infinity,
- fallbackDuration = 3600,
- errorTtl = 0.15,
- resolver = new AsyncResolver(),
- lookup = dnsLookup
- } = {}) {
- this.maxTtl = maxTtl;
- this.errorTtl = errorTtl;
-
- this._cache = cache;
- this._resolver = resolver;
- this._dnsLookup = promisify(lookup);
-
- if (this._resolver instanceof AsyncResolver) {
- this._resolve4 = this._resolver.resolve4.bind(this._resolver);
- this._resolve6 = this._resolver.resolve6.bind(this._resolver);
- } else {
- this._resolve4 = promisify(this._resolver.resolve4.bind(this._resolver));
- this._resolve6 = promisify(this._resolver.resolve6.bind(this._resolver));
- }
-
- this._iface = getIfaceInfo();
-
- this._pending = {};
- this._nextRemovalTime = false;
- this._hostnamesToFallback = new Set();
-
- if (fallbackDuration < 1) {
- this._fallback = false;
- } else {
- this._fallback = true;
-
- const interval = setInterval(() => {
- this._hostnamesToFallback.clear();
- }, fallbackDuration * 1000);
-
- /* istanbul ignore next: There is no `interval.unref()` when running inside an Electron renderer */
- if (interval.unref) {
- interval.unref();
- }
- }
-
- this.lookup = this.lookup.bind(this);
- this.lookupAsync = this.lookupAsync.bind(this);
- }
-
- set servers(servers) {
- this.clear();
-
- this._resolver.setServers(servers);
- }
-
- get servers() {
- return this._resolver.getServers();
- }
-
- lookup(hostname, options, callback) {
- if (typeof options === 'function') {
- callback = options;
- options = {};
- } else if (typeof options === 'number') {
- options = {
- family: options
- };
- }
-
- if (!callback) {
- throw new Error('Callback must be a function.');
- }
-
- // eslint-disable-next-line promise/prefer-await-to-then
- this.lookupAsync(hostname, options).then(result => {
- if (options.all) {
- callback(null, result);
- } else {
- callback(null, result.address, result.family, result.expires, result.ttl);
- }
- }, callback);
- }
-
- async lookupAsync(hostname, options = {}) {
- if (typeof options === 'number') {
- options = {
- family: options
- };
- }
-
- let cached = await this.query(hostname);
-
- if (options.family === 6) {
- const filtered = cached.filter(entry => entry.family === 6);
-
- if (options.hints & V4MAPPED) {
- if ((supportsALL && options.hints & ALL) || filtered.length === 0) {
- map4to6(cached);
- } else {
- cached = filtered;
- }
- } else {
- cached = filtered;
- }
- } else if (options.family === 4) {
- cached = cached.filter(entry => entry.family === 4);
- }
-
- if (options.hints & ADDRCONFIG) {
- const {_iface} = this;
- cached = cached.filter(entry => entry.family === 6 ? _iface.has6 : _iface.has4);
- }
-
- if (cached.length === 0) {
- const error = new Error(`cacheableLookup ENOTFOUND ${hostname}`);
- error.code = 'ENOTFOUND';
- error.hostname = hostname;
-
- throw error;
- }
-
- if (options.all) {
- return cached;
- }
-
- return cached[0];
- }
-
- async query(hostname) {
- let cached = await this._cache.get(hostname);
-
- if (!cached) {
- const pending = this._pending[hostname];
-
- if (pending) {
- cached = await pending;
- } else {
- const newPromise = this.queryAndCache(hostname);
- this._pending[hostname] = newPromise;
-
- try {
- cached = await newPromise;
- } finally {
- delete this._pending[hostname];
- }
- }
- }
-
- cached = cached.map(entry => {
- return {...entry};
- });
-
- return cached;
- }
-
- async _resolve(hostname) {
- const wrap = async promise => {
- try {
- return await promise;
- } catch (error) {
- if (error.code === 'ENODATA' || error.code === 'ENOTFOUND') {
- return [];
- }
-
- throw error;
- }
- };
-
- // ANY is unsafe as it doesn't trigger new queries in the underlying server.
- const [A, AAAA] = await Promise.all([
- this._resolve4(hostname, ttl),
- this._resolve6(hostname, ttl)
- ].map(promise => wrap(promise)));
-
- let aTtl = 0;
- let aaaaTtl = 0;
- let cacheTtl = 0;
-
- const now = Date.now();
-
- for (const entry of A) {
- entry.family = 4;
- entry.expires = now + (entry.ttl * 1000);
-
- aTtl = Math.max(aTtl, entry.ttl);
- }
-
- for (const entry of AAAA) {
- entry.family = 6;
- entry.expires = now + (entry.ttl * 1000);
-
- aaaaTtl = Math.max(aaaaTtl, entry.ttl);
- }
-
- if (A.length > 0) {
- if (AAAA.length > 0) {
- cacheTtl = Math.min(aTtl, aaaaTtl);
- } else {
- cacheTtl = aTtl;
- }
- } else {
- cacheTtl = aaaaTtl;
- }
-
- return {
- entries: [
- ...A,
- ...AAAA
- ],
- cacheTtl
- };
- }
-
- async _lookup(hostname) {
- try {
- const entries = await this._dnsLookup(hostname, {
- all: true
- });
-
- return {
- entries,
- cacheTtl: 0
- };
- } catch (_) {
- return {
- entries: [],
- cacheTtl: 0
- };
- }
- }
-
- async _set(hostname, data, cacheTtl) {
- if (this.maxTtl > 0 && cacheTtl > 0) {
- cacheTtl = Math.min(cacheTtl, this.maxTtl) * 1000;
- data[kExpires] = Date.now() + cacheTtl;
-
- try {
- await this._cache.set(hostname, data, cacheTtl);
- } catch (error) {
- this.lookupAsync = async () => {
- const cacheError = new Error('Cache Error. Please recreate the CacheableLookup instance.');
- cacheError.cause = error;
-
- throw cacheError;
- };
- }
-
- if (isIterable(this._cache)) {
- this._tick(cacheTtl);
- }
- }
- }
-
- async queryAndCache(hostname) {
- if (this._hostnamesToFallback.has(hostname)) {
- return this._dnsLookup(hostname, all);
- }
-
- let query = await this._resolve(hostname);
-
- if (query.entries.length === 0 && this._fallback) {
- query = await this._lookup(hostname);
-
- if (query.entries.length !== 0) {
- // Use `dns.lookup(...)` for that particular hostname
- this._hostnamesToFallback.add(hostname);
- }
- }
-
- const cacheTtl = query.entries.length === 0 ? this.errorTtl : query.cacheTtl;
- await this._set(hostname, query.entries, cacheTtl);
-
- return query.entries;
- }
-
- _tick(ms) {
- const nextRemovalTime = this._nextRemovalTime;
-
- if (!nextRemovalTime || ms < nextRemovalTime) {
- clearTimeout(this._removalTimeout);
-
- this._nextRemovalTime = ms;
-
- this._removalTimeout = setTimeout(() => {
- this._nextRemovalTime = false;
-
- let nextExpiry = Infinity;
-
- const now = Date.now();
-
- for (const [hostname, entries] of this._cache) {
- const expires = entries[kExpires];
-
- if (now >= expires) {
- this._cache.delete(hostname);
- } else if (expires < nextExpiry) {
- nextExpiry = expires;
- }
- }
-
- if (nextExpiry !== Infinity) {
- this._tick(nextExpiry - now);
- }
- }, ms);
-
- /* istanbul ignore next: There is no `timeout.unref()` when running inside an Electron renderer */
- if (this._removalTimeout.unref) {
- this._removalTimeout.unref();
- }
- }
- }
-
- install(agent) {
- verifyAgent(agent);
-
- if (kCacheableLookupCreateConnection in agent) {
- throw new Error('CacheableLookup has been already installed');
- }
-
- agent[kCacheableLookupCreateConnection] = agent.createConnection;
- agent[kCacheableLookupInstance] = this;
-
- agent.createConnection = (options, callback) => {
- if (!('lookup' in options)) {
- options.lookup = this.lookup;
- }
-
- return agent[kCacheableLookupCreateConnection](options, callback);
- };
- }
-
- uninstall(agent) {
- verifyAgent(agent);
-
- if (agent[kCacheableLookupCreateConnection]) {
- if (agent[kCacheableLookupInstance] !== this) {
- throw new Error('The agent is not owned by this CacheableLookup instance');
- }
-
- agent.createConnection = agent[kCacheableLookupCreateConnection];
-
- delete agent[kCacheableLookupCreateConnection];
- delete agent[kCacheableLookupInstance];
- }
- }
-
- updateInterfaceInfo() {
- const {_iface} = this;
-
- this._iface = getIfaceInfo();
-
- if ((_iface.has4 && !this._iface.has4) || (_iface.has6 && !this._iface.has6)) {
- this._cache.clear();
- }
- }
-
- clear(hostname) {
- if (hostname) {
- this._cache.delete(hostname);
- return;
- }
-
- this._cache.clear();
- }
-}
-
-module.exports = CacheableLookup;
-module.exports["default"] = CacheableLookup;
-
-
-/***/ }),
-
-/***/ 4340:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-"use strict";
-
-const {PassThrough: PassThroughStream} = __nccwpck_require__(2781);
-
-module.exports = options => {
- options = {...options};
-
- const {array} = options;
- let {encoding} = options;
- const isBuffer = encoding === 'buffer';
- let objectMode = false;
-
- if (array) {
- objectMode = !(encoding || isBuffer);
- } else {
- encoding = encoding || 'utf8';
- }
-
- if (isBuffer) {
- encoding = null;
- }
-
- const stream = new PassThroughStream({objectMode});
-
- if (encoding) {
- stream.setEncoding(encoding);
- }
-
- let length = 0;
- const chunks = [];
-
- stream.on('data', chunk => {
- chunks.push(chunk);
-
- if (objectMode) {
- length = chunks.length;
- } else {
- length += chunk.length;
- }
- });
-
- stream.getBufferedValue = () => {
- if (array) {
- return chunks;
- }
-
- return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
- };
-
- stream.getBufferedLength = () => length;
-
- return stream;
-};
-
-
-/***/ }),
-
-/***/ 7040:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-"use strict";
-
-const {constants: BufferConstants} = __nccwpck_require__(4300);
-const pump = __nccwpck_require__(8341);
-const bufferStream = __nccwpck_require__(4340);
-
-class MaxBufferError extends Error {
- constructor() {
- super('maxBuffer exceeded');
- this.name = 'MaxBufferError';
- }
-}
-
-async function getStream(inputStream, options) {
- if (!inputStream) {
- return Promise.reject(new Error('Expected a stream'));
- }
-
- options = {
- maxBuffer: Infinity,
- ...options
- };
-
- const {maxBuffer} = options;
-
- let stream;
- await new Promise((resolve, reject) => {
- const rejectPromise = error => {
- // Don't retrieve an oversized buffer.
- if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
- error.bufferedData = stream.getBufferedValue();
- }
-
- reject(error);
- };
-
- stream = pump(inputStream, bufferStream(options), error => {
- if (error) {
- rejectPromise(error);
- return;
- }
-
- resolve();
- });
-
- stream.on('data', () => {
- if (stream.getBufferedLength() > maxBuffer) {
- rejectPromise(new MaxBufferError());
- }
- });
- });
-
- return stream.getBufferedValue();
-}
-
-module.exports = getStream;
-// TODO: Remove this for the next major release
-module.exports["default"] = getStream;
-module.exports.buffer = (stream, options) => getStream(stream, {...options, encoding: 'buffer'});
-module.exports.array = (stream, options) => getStream(stream, {...options, array: true});
-module.exports.MaxBufferError = MaxBufferError;
-
-
-/***/ }),
-
-/***/ 8116:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-"use strict";
-
-
-const EventEmitter = __nccwpck_require__(2361);
-const urlLib = __nccwpck_require__(7310);
-const normalizeUrl = __nccwpck_require__(7952);
-const getStream = __nccwpck_require__(7040);
-const CachePolicy = __nccwpck_require__(1002);
-const Response = __nccwpck_require__(9004);
-const lowercaseKeys = __nccwpck_require__(9662);
-const cloneResponse = __nccwpck_require__(1312);
-const Keyv = __nccwpck_require__(1531);
-
-class CacheableRequest {
- constructor(request, cacheAdapter) {
- if (typeof request !== 'function') {
- throw new TypeError('Parameter `request` must be a function');
- }
-
- this.cache = new Keyv({
- uri: typeof cacheAdapter === 'string' && cacheAdapter,
- store: typeof cacheAdapter !== 'string' && cacheAdapter,
- namespace: 'cacheable-request'
- });
-
- return this.createCacheableRequest(request);
- }
-
- createCacheableRequest(request) {
- return (opts, cb) => {
- let url;
- if (typeof opts === 'string') {
- url = normalizeUrlObject(urlLib.parse(opts));
- opts = {};
- } else if (opts instanceof urlLib.URL) {
- url = normalizeUrlObject(urlLib.parse(opts.toString()));
- opts = {};
- } else {
- const [pathname, ...searchParts] = (opts.path || '').split('?');
- const search = searchParts.length > 0 ?
- `?${searchParts.join('?')}` :
- '';
- url = normalizeUrlObject({ ...opts, pathname, search });
- }
-
- opts = {
- headers: {},
- method: 'GET',
- cache: true,
- strictTtl: false,
- automaticFailover: false,
- ...opts,
- ...urlObjectToRequestOptions(url)
- };
- opts.headers = lowercaseKeys(opts.headers);
-
- const ee = new EventEmitter();
- const normalizedUrlString = normalizeUrl(
- urlLib.format(url),
- {
- stripWWW: false,
- removeTrailingSlash: false,
- stripAuthentication: false
- }
- );
- const key = `${opts.method}:${normalizedUrlString}`;
- let revalidate = false;
- let madeRequest = false;
-
- const makeRequest = opts => {
- madeRequest = true;
- let requestErrored = false;
- let requestErrorCallback;
-
- const requestErrorPromise = new Promise(resolve => {
- requestErrorCallback = () => {
- if (!requestErrored) {
- requestErrored = true;
- resolve();
- }
- };
- });
-
- const handler = response => {
- if (revalidate && !opts.forceRefresh) {
- response.status = response.statusCode;
- const revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(opts, response);
- if (!revalidatedPolicy.modified) {
- const headers = revalidatedPolicy.policy.responseHeaders();
- response = new Response(revalidate.statusCode, headers, revalidate.body, revalidate.url);
- response.cachePolicy = revalidatedPolicy.policy;
- response.fromCache = true;
- }
- }
-
- if (!response.fromCache) {
- response.cachePolicy = new CachePolicy(opts, response, opts);
- response.fromCache = false;
- }
-
- let clonedResponse;
- if (opts.cache && response.cachePolicy.storable()) {
- clonedResponse = cloneResponse(response);
-
- (async () => {
- try {
- const bodyPromise = getStream.buffer(response);
-
- await Promise.race([
- requestErrorPromise,
- new Promise(resolve => response.once('end', resolve))
- ]);
-
- if (requestErrored) {
- return;
- }
-
- const body = await bodyPromise;
-
- const value = {
- cachePolicy: response.cachePolicy.toObject(),
- url: response.url,
- statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
- body
- };
-
- let ttl = opts.strictTtl ? response.cachePolicy.timeToLive() : undefined;
- if (opts.maxTtl) {
- ttl = ttl ? Math.min(ttl, opts.maxTtl) : opts.maxTtl;
- }
-
- await this.cache.set(key, value, ttl);
- } catch (error) {
- ee.emit('error', new CacheableRequest.CacheError(error));
- }
- })();
- } else if (opts.cache && revalidate) {
- (async () => {
- try {
- await this.cache.delete(key);
- } catch (error) {
- ee.emit('error', new CacheableRequest.CacheError(error));
- }
- })();
- }
-
- ee.emit('response', clonedResponse || response);
- if (typeof cb === 'function') {
- cb(clonedResponse || response);
- }
- };
-
- try {
- const req = request(opts, handler);
- req.once('error', requestErrorCallback);
- req.once('abort', requestErrorCallback);
- ee.emit('request', req);
- } catch (error) {
- ee.emit('error', new CacheableRequest.RequestError(error));
- }
- };
-
- (async () => {
- const get = async opts => {
- await Promise.resolve();
-
- const cacheEntry = opts.cache ? await this.cache.get(key) : undefined;
- if (typeof cacheEntry === 'undefined') {
- return makeRequest(opts);
- }
-
- const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
- if (policy.satisfiesWithoutRevalidation(opts) && !opts.forceRefresh) {
- const headers = policy.responseHeaders();
- const response = new Response(cacheEntry.statusCode, headers, cacheEntry.body, cacheEntry.url);
- response.cachePolicy = policy;
- response.fromCache = true;
-
- ee.emit('response', response);
- if (typeof cb === 'function') {
- cb(response);
- }
- } else {
- revalidate = cacheEntry;
- opts.headers = policy.revalidationHeaders(opts);
- makeRequest(opts);
- }
- };
-
- const errorHandler = error => ee.emit('error', new CacheableRequest.CacheError(error));
- this.cache.once('error', errorHandler);
- ee.on('response', () => this.cache.removeListener('error', errorHandler));
-
- try {
- await get(opts);
- } catch (error) {
- if (opts.automaticFailover && !madeRequest) {
- makeRequest(opts);
- }
-
- ee.emit('error', new CacheableRequest.CacheError(error));
- }
- })();
-
- return ee;
- };
- }
-}
-
-function urlObjectToRequestOptions(url) {
- const options = { ...url };
- options.path = `${url.pathname || '/'}${url.search || ''}`;
- delete options.pathname;
- delete options.search;
- return options;
-}
-
-function normalizeUrlObject(url) {
- // If url was parsed by url.parse or new URL:
- // - hostname will be set
- // - host will be hostname[:port]
- // - port will be set if it was explicit in the parsed string
- // Otherwise, url was from request options:
- // - hostname or host may be set
- // - host shall not have port encoded
- return {
- protocol: url.protocol,
- auth: url.auth,
- hostname: url.hostname || url.host || 'localhost',
- port: url.port,
- pathname: url.pathname,
- search: url.search
- };
-}
-
-CacheableRequest.RequestError = class extends Error {
- constructor(error) {
- super(error.message);
- this.name = 'RequestError';
- Object.assign(this, error);
- }
-};
-
-CacheableRequest.CacheError = class extends Error {
- constructor(error) {
- super(error.message);
- this.name = 'CacheError';
- Object.assign(this, error);
- }
-};
-
-module.exports = CacheableRequest;
-
-
-/***/ }),
-
-/***/ 1312:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-"use strict";
-
-
-const PassThrough = (__nccwpck_require__(2781).PassThrough);
-const mimicResponse = __nccwpck_require__(2610);
-
-const cloneResponse = response => {
- if (!(response && response.pipe)) {
- throw new TypeError('Parameter `response` must be a response stream.');
- }
-
- const clone = new PassThrough();
- mimicResponse(response, clone);
-
- return response.pipe(clone);
-};
-
-module.exports = cloneResponse;
-
-
-/***/ }),
-
-/***/ 5728:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-"use strict";
-
-
-const { promisify } = __nccwpck_require__(3837)
-const JSONB = __nccwpck_require__(2820)
-const zlib = __nccwpck_require__(9796)
-
-const mergeOptions = __nccwpck_require__(4968)
-
-const compress = promisify(zlib.brotliCompress)
-
-const decompress = promisify(zlib.brotliDecompress)
-
-const identity = val => val
-
-const createCompress = ({
- enable = true,
- serialize = JSONB.stringify,
- deserialize = JSONB.parse,
- compressOptions,
- decompressOptions
-} = {}) => {
- if (!enable) {
- return { serialize, deserialize, decompress: identity, compress: identity }
- }
-
- return {
- serialize,
- deserialize,
- compress: async (data, options = {}) => {
- if (data === undefined) return data
- const serializedData = serialize(data)
- return compress(serializedData, mergeOptions(compressOptions, options))
- },
- decompress: async (data, options = {}) => {
- if (data === undefined) return data
- return deserialize(
- await decompress(data, mergeOptions(decompressOptions, options))
- )
- }
- }
-}
-
-module.exports = createCompress
-module.exports.stringify = JSONB.stringify
-module.exports.parse = JSONB.parse
-
-
-/***/ }),
-
-/***/ 4968:
-/***/ ((module) => {
-
-"use strict";
-
-
-module.exports = (defaultOptions = {}, options = {}) => {
- const params = {
- ...(defaultOptions.params || {}),
- ...(options.params || {})
- }
-
- return {
- ...defaultOptions,
- ...options,
- ...(Object.keys(params).length
- ? {
- params
- }
- : {})
- }
-}
-
-
/***/ }),
/***/ 2391:
@@ -14501,107 +12991,6 @@ class Deprecation extends Error {
exports.Deprecation = Deprecation;
-/***/ }),
-
-/***/ 1205:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-var once = __nccwpck_require__(1223);
-
-var noop = function() {};
-
-var isRequest = function(stream) {
- return stream.setHeader && typeof stream.abort === 'function';
-};
-
-var isChildProcess = function(stream) {
- return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
-};
-
-var eos = function(stream, opts, callback) {
- if (typeof opts === 'function') return eos(stream, null, opts);
- if (!opts) opts = {};
-
- callback = once(callback || noop);
-
- var ws = stream._writableState;
- var rs = stream._readableState;
- var readable = opts.readable || (opts.readable !== false && stream.readable);
- var writable = opts.writable || (opts.writable !== false && stream.writable);
- var cancelled = false;
-
- var onlegacyfinish = function() {
- if (!stream.writable) onfinish();
- };
-
- var onfinish = function() {
- writable = false;
- if (!readable) callback.call(stream);
- };
-
- var onend = function() {
- readable = false;
- if (!writable) callback.call(stream);
- };
-
- var onexit = function(exitCode) {
- callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
- };
-
- var onerror = function(err) {
- callback.call(stream, err);
- };
-
- var onclose = function() {
- process.nextTick(onclosenexttick);
- };
-
- var onclosenexttick = function() {
- if (cancelled) return;
- if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
- if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
- };
-
- var onrequest = function() {
- stream.req.on('finish', onfinish);
- };
-
- if (isRequest(stream)) {
- stream.on('complete', onfinish);
- stream.on('abort', onclose);
- if (stream.req) onrequest();
- else stream.on('request', onrequest);
- } else if (writable && !ws) { // legacy streams
- stream.on('end', onlegacyfinish);
- stream.on('close', onlegacyfinish);
- }
-
- if (isChildProcess(stream)) stream.on('exit', onexit);
-
- stream.on('end', onend);
- stream.on('finish', onfinish);
- if (opts.error !== false) stream.on('error', onerror);
- stream.on('close', onclose);
-
- return function() {
- cancelled = true;
- stream.removeListener('complete', onfinish);
- stream.removeListener('abort', onclose);
- stream.removeListener('request', onrequest);
- if (stream.req) stream.req.removeListener('finish', onfinish);
- stream.removeListener('end', onlegacyfinish);
- stream.removeListener('close', onlegacyfinish);
- stream.removeListener('finish', onfinish);
- stream.removeListener('exit', onexit);
- stream.removeListener('end', onend);
- stream.removeListener('error', onerror);
- stream.removeListener('close', onclose);
- };
-};
-
-module.exports = eos;
-
-
/***/ }),
/***/ 4460:
@@ -16435,2812 +14824,131 @@ module.exports = fill;
/***/ }),
-/***/ 6457:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
+/***/ 1585:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
"use strict";
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const types_1 = __nccwpck_require__(4597);
-function createRejection(error, ...beforeErrorGroups) {
- const promise = (async () => {
- if (error instanceof types_1.RequestError) {
- try {
- for (const hooks of beforeErrorGroups) {
- if (hooks) {
- for (const hook of hooks) {
- // eslint-disable-next-line no-await-in-loop
- error = await hook(error);
- }
- }
- }
- }
- catch (error_) {
- error = error_;
- }
- }
- throw error;
- })();
- const returnPromise = () => promise;
- promise.json = returnPromise;
- promise.text = returnPromise;
- promise.buffer = returnPromise;
- promise.on = returnPromise;
- return promise;
+const {PassThrough: PassThroughStream} = __nccwpck_require__(2781);
+
+module.exports = options => {
+ options = {...options};
+
+ const {array} = options;
+ let {encoding} = options;
+ const isBuffer = encoding === 'buffer';
+ let objectMode = false;
+
+ if (array) {
+ objectMode = !(encoding || isBuffer);
+ } else {
+ encoding = encoding || 'utf8';
+ }
+
+ if (isBuffer) {
+ encoding = null;
+ }
+
+ const stream = new PassThroughStream({objectMode});
+
+ if (encoding) {
+ stream.setEncoding(encoding);
+ }
+
+ let length = 0;
+ const chunks = [];
+
+ stream.on('data', chunk => {
+ chunks.push(chunk);
+
+ if (objectMode) {
+ length = chunks.length;
+ } else {
+ length += chunk.length;
+ }
+ });
+
+ stream.getBufferedValue = () => {
+ if (array) {
+ return chunks;
+ }
+
+ return isBuffer ? Buffer.concat(chunks, length) : chunks.join('');
+ };
+
+ stream.getBufferedLength = () => length;
+
+ return stream;
+};
+
+
+/***/ }),
+
+/***/ 1766:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const {constants: BufferConstants} = __nccwpck_require__(4300);
+const stream = __nccwpck_require__(2781);
+const {promisify} = __nccwpck_require__(3837);
+const bufferStream = __nccwpck_require__(1585);
+
+const streamPipelinePromisified = promisify(stream.pipeline);
+
+class MaxBufferError extends Error {
+ constructor() {
+ super('maxBuffer exceeded');
+ this.name = 'MaxBufferError';
+ }
}
-exports["default"] = createRejection;
+async function getStream(inputStream, options) {
+ if (!inputStream) {
+ throw new Error('Expected a stream');
+ }
-/***/ }),
+ options = {
+ maxBuffer: Infinity,
+ ...options
+ };
-/***/ 6056:
-/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
+ const {maxBuffer} = options;
+ const stream = bufferStream(options);
-"use strict";
+ await new Promise((resolve, reject) => {
+ const rejectPromise = error => {
+ // Don't retrieve an oversized buffer.
+ if (error && stream.getBufferedLength() <= BufferConstants.MAX_LENGTH) {
+ error.bufferedData = stream.getBufferedValue();
+ }
-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
-}) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
-}));
-var __exportStar = (this && this.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
-};
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const events_1 = __nccwpck_require__(2361);
-const is_1 = __nccwpck_require__(7678);
-const PCancelable = __nccwpck_require__(9072);
-const types_1 = __nccwpck_require__(4597);
-const parse_body_1 = __nccwpck_require__(8220);
-const core_1 = __nccwpck_require__(94);
-const proxy_events_1 = __nccwpck_require__(3021);
-const get_buffer_1 = __nccwpck_require__(4500);
-const is_response_ok_1 = __nccwpck_require__(9298);
-const proxiedRequestEvents = [
- 'request',
- 'response',
- 'redirect',
- 'uploadProgress',
- 'downloadProgress'
-];
-function asPromise(normalizedOptions) {
- let globalRequest;
- let globalResponse;
- const emitter = new events_1.EventEmitter();
- const promise = new PCancelable((resolve, reject, onCancel) => {
- const makeRequest = (retryCount) => {
- const request = new core_1.default(undefined, normalizedOptions);
- request.retryCount = retryCount;
- request._noPipe = true;
- onCancel(() => request.destroy());
- onCancel.shouldReject = false;
- onCancel(() => reject(new types_1.CancelError(request)));
- globalRequest = request;
- request.once('response', async (response) => {
- var _a;
- response.retryCount = retryCount;
- if (response.request.aborted) {
- // Canceled while downloading - will throw a `CancelError` or `TimeoutError` error
- return;
- }
- // Download body
- let rawBody;
- try {
- rawBody = await get_buffer_1.default(request);
- response.rawBody = rawBody;
- }
- catch (_b) {
- // The same error is caught below.
- // See request.once('error')
- return;
- }
- if (request._isAboutToError) {
- return;
- }
- // Parse body
- const contentEncoding = ((_a = response.headers['content-encoding']) !== null && _a !== void 0 ? _a : '').toLowerCase();
- const isCompressed = ['gzip', 'deflate', 'br'].includes(contentEncoding);
- const { options } = request;
- if (isCompressed && !options.decompress) {
- response.body = rawBody;
- }
- else {
- try {
- response.body = parse_body_1.default(response, options.responseType, options.parseJson, options.encoding);
- }
- catch (error) {
- // Fallback to `utf8`
- response.body = rawBody.toString();
- if (is_response_ok_1.isResponseOk(response)) {
- request._beforeError(error);
- return;
- }
- }
- }
- try {
- for (const [index, hook] of options.hooks.afterResponse.entries()) {
- // @ts-expect-error TS doesn't notice that CancelableRequest is a Promise
- // eslint-disable-next-line no-await-in-loop
- response = await hook(response, async (updatedOptions) => {
- const typedOptions = core_1.default.normalizeArguments(undefined, {
- ...updatedOptions,
- retry: {
- calculateDelay: () => 0
- },
- throwHttpErrors: false,
- resolveBodyOnly: false
- }, options);
- // Remove any further hooks for that request, because we'll call them anyway.
- // The loop continues. We don't want duplicates (asPromise recursion).
- typedOptions.hooks.afterResponse = typedOptions.hooks.afterResponse.slice(0, index);
- for (const hook of typedOptions.hooks.beforeRetry) {
- // eslint-disable-next-line no-await-in-loop
- await hook(typedOptions);
- }
- const promise = asPromise(typedOptions);
- onCancel(() => {
- promise.catch(() => { });
- promise.cancel();
- });
- return promise;
- });
- }
- }
- catch (error) {
- request._beforeError(new types_1.RequestError(error.message, error, request));
- return;
- }
- globalResponse = response;
- if (!is_response_ok_1.isResponseOk(response)) {
- request._beforeError(new types_1.HTTPError(response));
- return;
- }
- resolve(request.options.resolveBodyOnly ? response.body : response);
- });
- const onError = (error) => {
- if (promise.isCanceled) {
- return;
- }
- const { options } = request;
- if (error instanceof types_1.HTTPError && !options.throwHttpErrors) {
- const { response } = error;
- resolve(request.options.resolveBodyOnly ? response.body : response);
- return;
- }
- reject(error);
- };
- request.once('error', onError);
- const previousBody = request.options.body;
- request.once('retry', (newRetryCount, error) => {
- var _a, _b;
- if (previousBody === ((_a = error.request) === null || _a === void 0 ? void 0 : _a.options.body) && is_1.default.nodeStream((_b = error.request) === null || _b === void 0 ? void 0 : _b.options.body)) {
- onError(error);
- return;
- }
- makeRequest(newRetryCount);
- });
- proxy_events_1.default(request, emitter, proxiedRequestEvents);
- };
- makeRequest(0);
- });
- promise.on = (event, fn) => {
- emitter.on(event, fn);
- return promise;
- };
- const shortcut = (responseType) => {
- const newPromise = (async () => {
- // Wait until downloading has ended
- await promise;
- const { options } = globalResponse.request;
- return parse_body_1.default(globalResponse, responseType, options.parseJson, options.encoding);
- })();
- Object.defineProperties(newPromise, Object.getOwnPropertyDescriptors(promise));
- return newPromise;
- };
- promise.json = () => {
- const { headers } = globalRequest.options;
- if (!globalRequest.writableFinished && headers.accept === undefined) {
- headers.accept = 'application/json';
- }
- return shortcut('json');
- };
- promise.buffer = () => shortcut('buffer');
- promise.text = () => shortcut('text');
- return promise;
+ reject(error);
+ };
+
+ (async () => {
+ try {
+ await streamPipelinePromisified(inputStream, stream);
+ resolve();
+ } catch (error) {
+ rejectPromise(error);
+ }
+ })();
+
+ stream.on('data', () => {
+ if (stream.getBufferedLength() > maxBuffer) {
+ rejectPromise(new MaxBufferError());
+ }
+ });
+ });
+
+ return stream.getBufferedValue();
}
-exports["default"] = asPromise;
-__exportStar(__nccwpck_require__(4597), exports);
-
-/***/ }),
-
-/***/ 1048:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const is_1 = __nccwpck_require__(7678);
-const normalizeArguments = (options, defaults) => {
- if (is_1.default.null_(options.encoding)) {
- throw new TypeError('To get a Buffer, set `options.responseType` to `buffer` instead');
- }
- is_1.assert.any([is_1.default.string, is_1.default.undefined], options.encoding);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.resolveBodyOnly);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.methodRewriting);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.isStream);
- is_1.assert.any([is_1.default.string, is_1.default.undefined], options.responseType);
- // `options.responseType`
- if (options.responseType === undefined) {
- options.responseType = 'text';
- }
- // `options.retry`
- const { retry } = options;
- if (defaults) {
- options.retry = { ...defaults.retry };
- }
- else {
- options.retry = {
- calculateDelay: retryObject => retryObject.computedValue,
- limit: 0,
- methods: [],
- statusCodes: [],
- errorCodes: [],
- maxRetryAfter: undefined
- };
- }
- if (is_1.default.object(retry)) {
- options.retry = {
- ...options.retry,
- ...retry
- };
- options.retry.methods = [...new Set(options.retry.methods.map(method => method.toUpperCase()))];
- options.retry.statusCodes = [...new Set(options.retry.statusCodes)];
- options.retry.errorCodes = [...new Set(options.retry.errorCodes)];
- }
- else if (is_1.default.number(retry)) {
- options.retry.limit = retry;
- }
- if (is_1.default.undefined(options.retry.maxRetryAfter)) {
- options.retry.maxRetryAfter = Math.min(
- // TypeScript is not smart enough to handle `.filter(x => is.number(x))`.
- // eslint-disable-next-line unicorn/no-fn-reference-in-iterator
- ...[options.timeout.request, options.timeout.connect].filter(is_1.default.number));
- }
- // `options.pagination`
- if (is_1.default.object(options.pagination)) {
- if (defaults) {
- options.pagination = {
- ...defaults.pagination,
- ...options.pagination
- };
- }
- const { pagination } = options;
- if (!is_1.default.function_(pagination.transform)) {
- throw new Error('`options.pagination.transform` must be implemented');
- }
- if (!is_1.default.function_(pagination.shouldContinue)) {
- throw new Error('`options.pagination.shouldContinue` must be implemented');
- }
- if (!is_1.default.function_(pagination.filter)) {
- throw new TypeError('`options.pagination.filter` must be implemented');
- }
- if (!is_1.default.function_(pagination.paginate)) {
- throw new Error('`options.pagination.paginate` must be implemented');
- }
- }
- // JSON mode
- if (options.responseType === 'json' && options.headers.accept === undefined) {
- options.headers.accept = 'application/json';
- }
- return options;
-};
-exports["default"] = normalizeArguments;
-
-
-/***/ }),
-
-/***/ 8220:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const types_1 = __nccwpck_require__(4597);
-const parseBody = (response, responseType, parseJson, encoding) => {
- const { rawBody } = response;
- try {
- if (responseType === 'text') {
- return rawBody.toString(encoding);
- }
- if (responseType === 'json') {
- return rawBody.length === 0 ? '' : parseJson(rawBody.toString());
- }
- if (responseType === 'buffer') {
- return rawBody;
- }
- throw new types_1.ParseError({
- message: `Unknown body type '${responseType}'`,
- name: 'Error'
- }, response);
- }
- catch (error) {
- throw new types_1.ParseError(error, response);
- }
-};
-exports["default"] = parseBody;
-
-
-/***/ }),
-
-/***/ 4597:
-/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
-
-"use strict";
-
-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
-}) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
-}));
-var __exportStar = (this && this.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
-};
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.CancelError = exports.ParseError = void 0;
-const core_1 = __nccwpck_require__(94);
-/**
-An error to be thrown when server response code is 2xx, and parsing body fails.
-Includes a `response` property.
-*/
-class ParseError extends core_1.RequestError {
- constructor(error, response) {
- const { options } = response.request;
- super(`${error.message} in "${options.url.toString()}"`, error, response.request);
- this.name = 'ParseError';
- this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_BODY_PARSE_FAILURE' : this.code;
- }
-}
-exports.ParseError = ParseError;
-/**
-An error to be thrown when the request is aborted with `.cancel()`.
-*/
-class CancelError extends core_1.RequestError {
- constructor(request) {
- super('Promise was canceled', {}, request);
- this.name = 'CancelError';
- this.code = 'ERR_CANCELED';
- }
- get isCanceled() {
- return true;
- }
-}
-exports.CancelError = CancelError;
-__exportStar(__nccwpck_require__(94), exports);
-
-
-/***/ }),
-
-/***/ 3462:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.retryAfterStatusCodes = void 0;
-exports.retryAfterStatusCodes = new Set([413, 429, 503]);
-const calculateRetryDelay = ({ attemptCount, retryOptions, error, retryAfter }) => {
- if (attemptCount > retryOptions.limit) {
- return 0;
- }
- const hasMethod = retryOptions.methods.includes(error.options.method);
- const hasErrorCode = retryOptions.errorCodes.includes(error.code);
- const hasStatusCode = error.response && retryOptions.statusCodes.includes(error.response.statusCode);
- if (!hasMethod || (!hasErrorCode && !hasStatusCode)) {
- return 0;
- }
- if (error.response) {
- if (retryAfter) {
- if (retryOptions.maxRetryAfter === undefined || retryAfter > retryOptions.maxRetryAfter) {
- return 0;
- }
- return retryAfter;
- }
- if (error.response.statusCode === 413) {
- return 0;
- }
- }
- const noise = Math.random() * 100;
- return ((2 ** (attemptCount - 1)) * 1000) + noise;
-};
-exports["default"] = calculateRetryDelay;
-
-
-/***/ }),
-
-/***/ 94:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.UnsupportedProtocolError = exports.ReadError = exports.TimeoutError = exports.UploadError = exports.CacheError = exports.HTTPError = exports.MaxRedirectsError = exports.RequestError = exports.setNonEnumerableProperties = exports.knownHookEvents = exports.withoutBody = exports.kIsNormalizedAlready = void 0;
-const util_1 = __nccwpck_require__(3837);
-const stream_1 = __nccwpck_require__(2781);
-const fs_1 = __nccwpck_require__(7147);
-const url_1 = __nccwpck_require__(7310);
-const http = __nccwpck_require__(3685);
-const http_1 = __nccwpck_require__(3685);
-const https = __nccwpck_require__(5687);
-const http_timer_1 = __nccwpck_require__(8097);
-const cacheable_lookup_1 = __nccwpck_require__(2286);
-const CacheableRequest = __nccwpck_require__(8116);
-const decompressResponse = __nccwpck_require__(2391);
-// @ts-expect-error Missing types
-const http2wrapper = __nccwpck_require__(4645);
-const lowercaseKeys = __nccwpck_require__(9662);
-const is_1 = __nccwpck_require__(7678);
-const get_body_size_1 = __nccwpck_require__(4564);
-const is_form_data_1 = __nccwpck_require__(40);
-const proxy_events_1 = __nccwpck_require__(3021);
-const timed_out_1 = __nccwpck_require__(2454);
-const url_to_options_1 = __nccwpck_require__(8026);
-const options_to_url_1 = __nccwpck_require__(9219);
-const weakable_map_1 = __nccwpck_require__(7288);
-const get_buffer_1 = __nccwpck_require__(4500);
-const dns_ip_version_1 = __nccwpck_require__(4993);
-const is_response_ok_1 = __nccwpck_require__(9298);
-const deprecation_warning_1 = __nccwpck_require__(397);
-const normalize_arguments_1 = __nccwpck_require__(1048);
-const calculate_retry_delay_1 = __nccwpck_require__(3462);
-let globalDnsCache;
-const kRequest = Symbol('request');
-const kResponse = Symbol('response');
-const kResponseSize = Symbol('responseSize');
-const kDownloadedSize = Symbol('downloadedSize');
-const kBodySize = Symbol('bodySize');
-const kUploadedSize = Symbol('uploadedSize');
-const kServerResponsesPiped = Symbol('serverResponsesPiped');
-const kUnproxyEvents = Symbol('unproxyEvents');
-const kIsFromCache = Symbol('isFromCache');
-const kCancelTimeouts = Symbol('cancelTimeouts');
-const kStartedReading = Symbol('startedReading');
-const kStopReading = Symbol('stopReading');
-const kTriggerRead = Symbol('triggerRead');
-const kBody = Symbol('body');
-const kJobs = Symbol('jobs');
-const kOriginalResponse = Symbol('originalResponse');
-const kRetryTimeout = Symbol('retryTimeout');
-exports.kIsNormalizedAlready = Symbol('isNormalizedAlready');
-const supportsBrotli = is_1.default.string(process.versions.brotli);
-exports.withoutBody = new Set(['GET', 'HEAD']);
-exports.knownHookEvents = [
- 'init',
- 'beforeRequest',
- 'beforeRedirect',
- 'beforeError',
- 'beforeRetry',
- // Promise-Only
- 'afterResponse'
-];
-function validateSearchParameters(searchParameters) {
- // eslint-disable-next-line guard-for-in
- for (const key in searchParameters) {
- const value = searchParameters[key];
- if (!is_1.default.string(value) && !is_1.default.number(value) && !is_1.default.boolean(value) && !is_1.default.null_(value) && !is_1.default.undefined(value)) {
- throw new TypeError(`The \`searchParams\` value '${String(value)}' must be a string, number, boolean or null`);
- }
- }
-}
-function isClientRequest(clientRequest) {
- return is_1.default.object(clientRequest) && !('statusCode' in clientRequest);
-}
-const cacheableStore = new weakable_map_1.default();
-const waitForOpenFile = async (file) => new Promise((resolve, reject) => {
- const onError = (error) => {
- reject(error);
- };
- // Node.js 12 has incomplete types
- if (!file.pending) {
- resolve();
- }
- file.once('error', onError);
- file.once('ready', () => {
- file.off('error', onError);
- resolve();
- });
-});
-const redirectCodes = new Set([300, 301, 302, 303, 304, 307, 308]);
-const nonEnumerableProperties = [
- 'context',
- 'body',
- 'json',
- 'form'
-];
-exports.setNonEnumerableProperties = (sources, to) => {
- // Non enumerable properties shall not be merged
- const properties = {};
- for (const source of sources) {
- if (!source) {
- continue;
- }
- for (const name of nonEnumerableProperties) {
- if (!(name in source)) {
- continue;
- }
- properties[name] = {
- writable: true,
- configurable: true,
- enumerable: false,
- // @ts-expect-error TS doesn't see the check above
- value: source[name]
- };
- }
- }
- Object.defineProperties(to, properties);
-};
-/**
-An error to be thrown when a request fails.
-Contains a `code` property with error class code, like `ECONNREFUSED`.
-*/
-class RequestError extends Error {
- constructor(message, error, self) {
- var _a, _b;
- super(message);
- Error.captureStackTrace(this, this.constructor);
- this.name = 'RequestError';
- this.code = (_a = error.code) !== null && _a !== void 0 ? _a : 'ERR_GOT_REQUEST_ERROR';
- if (self instanceof Request) {
- Object.defineProperty(this, 'request', {
- enumerable: false,
- value: self
- });
- Object.defineProperty(this, 'response', {
- enumerable: false,
- value: self[kResponse]
- });
- Object.defineProperty(this, 'options', {
- // This fails because of TS 3.7.2 useDefineForClassFields
- // Ref: https://github.com/microsoft/TypeScript/issues/34972
- enumerable: false,
- value: self.options
- });
- }
- else {
- Object.defineProperty(this, 'options', {
- // This fails because of TS 3.7.2 useDefineForClassFields
- // Ref: https://github.com/microsoft/TypeScript/issues/34972
- enumerable: false,
- value: self
- });
- }
- this.timings = (_b = this.request) === null || _b === void 0 ? void 0 : _b.timings;
- // Recover the original stacktrace
- if (is_1.default.string(error.stack) && is_1.default.string(this.stack)) {
- const indexOfMessage = this.stack.indexOf(this.message) + this.message.length;
- const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').reverse();
- const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').reverse();
- // Remove duplicated traces
- while (errorStackTrace.length !== 0 && errorStackTrace[0] === thisStackTrace[0]) {
- thisStackTrace.shift();
- }
- this.stack = `${this.stack.slice(0, indexOfMessage)}${thisStackTrace.reverse().join('\n')}${errorStackTrace.reverse().join('\n')}`;
- }
- }
-}
-exports.RequestError = RequestError;
-/**
-An error to be thrown when the server redirects you more than ten times.
-Includes a `response` property.
-*/
-class MaxRedirectsError extends RequestError {
- constructor(request) {
- super(`Redirected ${request.options.maxRedirects} times. Aborting.`, {}, request);
- this.name = 'MaxRedirectsError';
- this.code = 'ERR_TOO_MANY_REDIRECTS';
- }
-}
-exports.MaxRedirectsError = MaxRedirectsError;
-/**
-An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304.
-Includes a `response` property.
-*/
-class HTTPError extends RequestError {
- constructor(response) {
- super(`Response code ${response.statusCode} (${response.statusMessage})`, {}, response.request);
- this.name = 'HTTPError';
- this.code = 'ERR_NON_2XX_3XX_RESPONSE';
- }
-}
-exports.HTTPError = HTTPError;
-/**
-An error to be thrown when a cache method fails.
-For example, if the database goes down or there's a filesystem error.
-*/
-class CacheError extends RequestError {
- constructor(error, request) {
- super(error.message, error, request);
- this.name = 'CacheError';
- this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_CACHE_ACCESS' : this.code;
- }
-}
-exports.CacheError = CacheError;
-/**
-An error to be thrown when the request body is a stream and an error occurs while reading from that stream.
-*/
-class UploadError extends RequestError {
- constructor(error, request) {
- super(error.message, error, request);
- this.name = 'UploadError';
- this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_UPLOAD' : this.code;
- }
-}
-exports.UploadError = UploadError;
-/**
-An error to be thrown when the request is aborted due to a timeout.
-Includes an `event` and `timings` property.
-*/
-class TimeoutError extends RequestError {
- constructor(error, timings, request) {
- super(error.message, error, request);
- this.name = 'TimeoutError';
- this.event = error.event;
- this.timings = timings;
- }
-}
-exports.TimeoutError = TimeoutError;
-/**
-An error to be thrown when reading from response stream fails.
-*/
-class ReadError extends RequestError {
- constructor(error, request) {
- super(error.message, error, request);
- this.name = 'ReadError';
- this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_READING_RESPONSE_STREAM' : this.code;
- }
-}
-exports.ReadError = ReadError;
-/**
-An error to be thrown when given an unsupported protocol.
-*/
-class UnsupportedProtocolError extends RequestError {
- constructor(options) {
- super(`Unsupported protocol "${options.url.protocol}"`, {}, options);
- this.name = 'UnsupportedProtocolError';
- this.code = 'ERR_UNSUPPORTED_PROTOCOL';
- }
-}
-exports.UnsupportedProtocolError = UnsupportedProtocolError;
-const proxiedRequestEvents = [
- 'socket',
- 'connect',
- 'continue',
- 'information',
- 'upgrade',
- 'timeout'
-];
-class Request extends stream_1.Duplex {
- constructor(url, options = {}, defaults) {
- super({
- // This must be false, to enable throwing after destroy
- // It is used for retry logic in Promise API
- autoDestroy: false,
- // It needs to be zero because we're just proxying the data to another stream
- highWaterMark: 0
- });
- this[kDownloadedSize] = 0;
- this[kUploadedSize] = 0;
- this.requestInitialized = false;
- this[kServerResponsesPiped] = new Set();
- this.redirects = [];
- this[kStopReading] = false;
- this[kTriggerRead] = false;
- this[kJobs] = [];
- this.retryCount = 0;
- // TODO: Remove this when targeting Node.js >= 12
- this._progressCallbacks = [];
- const unlockWrite = () => this._unlockWrite();
- const lockWrite = () => this._lockWrite();
- this.on('pipe', (source) => {
- source.prependListener('data', unlockWrite);
- source.on('data', lockWrite);
- source.prependListener('end', unlockWrite);
- source.on('end', lockWrite);
- });
- this.on('unpipe', (source) => {
- source.off('data', unlockWrite);
- source.off('data', lockWrite);
- source.off('end', unlockWrite);
- source.off('end', lockWrite);
- });
- this.on('pipe', source => {
- if (source instanceof http_1.IncomingMessage) {
- this.options.headers = {
- ...source.headers,
- ...this.options.headers
- };
- }
- });
- const { json, body, form } = options;
- if (json || body || form) {
- this._lockWrite();
- }
- if (exports.kIsNormalizedAlready in options) {
- this.options = options;
- }
- else {
- try {
- // @ts-expect-error Common TypeScript bug saying that `this.constructor` is not accessible
- this.options = this.constructor.normalizeArguments(url, options, defaults);
- }
- catch (error) {
- // TODO: Move this to `_destroy()`
- if (is_1.default.nodeStream(options.body)) {
- options.body.destroy();
- }
- this.destroy(error);
- return;
- }
- }
- (async () => {
- var _a;
- try {
- if (this.options.body instanceof fs_1.ReadStream) {
- await waitForOpenFile(this.options.body);
- }
- const { url: normalizedURL } = this.options;
- if (!normalizedURL) {
- throw new TypeError('Missing `url` property');
- }
- this.requestUrl = normalizedURL.toString();
- decodeURI(this.requestUrl);
- await this._finalizeBody();
- await this._makeRequest();
- if (this.destroyed) {
- (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroy();
- return;
- }
- // Queued writes etc.
- for (const job of this[kJobs]) {
- job();
- }
- // Prevent memory leak
- this[kJobs].length = 0;
- this.requestInitialized = true;
- }
- catch (error) {
- if (error instanceof RequestError) {
- this._beforeError(error);
- return;
- }
- // This is a workaround for https://github.com/nodejs/node/issues/33335
- if (!this.destroyed) {
- this.destroy(error);
- }
- }
- })();
- }
- static normalizeArguments(url, options, defaults) {
- var _a, _b, _c, _d, _e;
- const rawOptions = options;
- if (is_1.default.object(url) && !is_1.default.urlInstance(url)) {
- options = { ...defaults, ...url, ...options };
- }
- else {
- if (url && options && options.url !== undefined) {
- throw new TypeError('The `url` option is mutually exclusive with the `input` argument');
- }
- options = { ...defaults, ...options };
- if (url !== undefined) {
- options.url = url;
- }
- if (is_1.default.urlInstance(options.url)) {
- options.url = new url_1.URL(options.url.toString());
- }
- }
- // TODO: Deprecate URL options in Got 12.
- // Support extend-specific options
- if (options.cache === false) {
- options.cache = undefined;
- }
- if (options.dnsCache === false) {
- options.dnsCache = undefined;
- }
- // Nice type assertions
- is_1.assert.any([is_1.default.string, is_1.default.undefined], options.method);
- is_1.assert.any([is_1.default.object, is_1.default.undefined], options.headers);
- is_1.assert.any([is_1.default.string, is_1.default.urlInstance, is_1.default.undefined], options.prefixUrl);
- is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cookieJar);
- is_1.assert.any([is_1.default.object, is_1.default.string, is_1.default.undefined], options.searchParams);
- is_1.assert.any([is_1.default.object, is_1.default.string, is_1.default.undefined], options.cache);
- is_1.assert.any([is_1.default.object, is_1.default.number, is_1.default.undefined], options.timeout);
- is_1.assert.any([is_1.default.object, is_1.default.undefined], options.context);
- is_1.assert.any([is_1.default.object, is_1.default.undefined], options.hooks);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.decompress);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.ignoreInvalidCookies);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.followRedirect);
- is_1.assert.any([is_1.default.number, is_1.default.undefined], options.maxRedirects);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.throwHttpErrors);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.http2);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.allowGetBody);
- is_1.assert.any([is_1.default.string, is_1.default.undefined], options.localAddress);
- is_1.assert.any([dns_ip_version_1.isDnsLookupIpVersion, is_1.default.undefined], options.dnsLookupIpVersion);
- is_1.assert.any([is_1.default.object, is_1.default.undefined], options.https);
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.rejectUnauthorized);
- if (options.https) {
- is_1.assert.any([is_1.default.boolean, is_1.default.undefined], options.https.rejectUnauthorized);
- is_1.assert.any([is_1.default.function_, is_1.default.undefined], options.https.checkServerIdentity);
- is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificateAuthority);
- is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.key);
- is_1.assert.any([is_1.default.string, is_1.default.object, is_1.default.array, is_1.default.undefined], options.https.certificate);
- is_1.assert.any([is_1.default.string, is_1.default.undefined], options.https.passphrase);
- is_1.assert.any([is_1.default.string, is_1.default.buffer, is_1.default.array, is_1.default.undefined], options.https.pfx);
- }
- is_1.assert.any([is_1.default.object, is_1.default.undefined], options.cacheOptions);
- // `options.method`
- if (is_1.default.string(options.method)) {
- options.method = options.method.toUpperCase();
- }
- else {
- options.method = 'GET';
- }
- // `options.headers`
- if (options.headers === (defaults === null || defaults === void 0 ? void 0 : defaults.headers)) {
- options.headers = { ...options.headers };
- }
- else {
- options.headers = lowercaseKeys({ ...(defaults === null || defaults === void 0 ? void 0 : defaults.headers), ...options.headers });
- }
- // Disallow legacy `url.Url`
- if ('slashes' in options) {
- throw new TypeError('The legacy `url.Url` has been deprecated. Use `URL` instead.');
- }
- // `options.auth`
- if ('auth' in options) {
- throw new TypeError('Parameter `auth` is deprecated. Use `username` / `password` instead.');
- }
- // `options.searchParams`
- if ('searchParams' in options) {
- if (options.searchParams && options.searchParams !== (defaults === null || defaults === void 0 ? void 0 : defaults.searchParams)) {
- let searchParameters;
- if (is_1.default.string(options.searchParams) || (options.searchParams instanceof url_1.URLSearchParams)) {
- searchParameters = new url_1.URLSearchParams(options.searchParams);
- }
- else {
- validateSearchParameters(options.searchParams);
- searchParameters = new url_1.URLSearchParams();
- // eslint-disable-next-line guard-for-in
- for (const key in options.searchParams) {
- const value = options.searchParams[key];
- if (value === null) {
- searchParameters.append(key, '');
- }
- else if (value !== undefined) {
- searchParameters.append(key, value);
- }
- }
- }
- // `normalizeArguments()` is also used to merge options
- (_a = defaults === null || defaults === void 0 ? void 0 : defaults.searchParams) === null || _a === void 0 ? void 0 : _a.forEach((value, key) => {
- // Only use default if one isn't already defined
- if (!searchParameters.has(key)) {
- searchParameters.append(key, value);
- }
- });
- options.searchParams = searchParameters;
- }
- }
- // `options.username` & `options.password`
- options.username = (_b = options.username) !== null && _b !== void 0 ? _b : '';
- options.password = (_c = options.password) !== null && _c !== void 0 ? _c : '';
- // `options.prefixUrl` & `options.url`
- if (is_1.default.undefined(options.prefixUrl)) {
- options.prefixUrl = (_d = defaults === null || defaults === void 0 ? void 0 : defaults.prefixUrl) !== null && _d !== void 0 ? _d : '';
- }
- else {
- options.prefixUrl = options.prefixUrl.toString();
- if (options.prefixUrl !== '' && !options.prefixUrl.endsWith('/')) {
- options.prefixUrl += '/';
- }
- }
- if (is_1.default.string(options.url)) {
- if (options.url.startsWith('/')) {
- throw new Error('`input` must not start with a slash when using `prefixUrl`');
- }
- options.url = options_to_url_1.default(options.prefixUrl + options.url, options);
- }
- else if ((is_1.default.undefined(options.url) && options.prefixUrl !== '') || options.protocol) {
- options.url = options_to_url_1.default(options.prefixUrl, options);
- }
- if (options.url) {
- if ('port' in options) {
- delete options.port;
- }
- // Make it possible to change `options.prefixUrl`
- let { prefixUrl } = options;
- Object.defineProperty(options, 'prefixUrl', {
- set: (value) => {
- const url = options.url;
- if (!url.href.startsWith(value)) {
- throw new Error(`Cannot change \`prefixUrl\` from ${prefixUrl} to ${value}: ${url.href}`);
- }
- options.url = new url_1.URL(value + url.href.slice(prefixUrl.length));
- prefixUrl = value;
- },
- get: () => prefixUrl
- });
- // Support UNIX sockets
- let { protocol } = options.url;
- if (protocol === 'unix:') {
- protocol = 'http:';
- options.url = new url_1.URL(`http://unix${options.url.pathname}${options.url.search}`);
- }
- // Set search params
- if (options.searchParams) {
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
- options.url.search = options.searchParams.toString();
- }
- // Protocol check
- if (protocol !== 'http:' && protocol !== 'https:') {
- throw new UnsupportedProtocolError(options);
- }
- // Update `username`
- if (options.username === '') {
- options.username = options.url.username;
- }
- else {
- options.url.username = options.username;
- }
- // Update `password`
- if (options.password === '') {
- options.password = options.url.password;
- }
- else {
- options.url.password = options.password;
- }
- }
- // `options.cookieJar`
- const { cookieJar } = options;
- if (cookieJar) {
- let { setCookie, getCookieString } = cookieJar;
- is_1.assert.function_(setCookie);
- is_1.assert.function_(getCookieString);
- /* istanbul ignore next: Horrible `tough-cookie` v3 check */
- if (setCookie.length === 4 && getCookieString.length === 0) {
- setCookie = util_1.promisify(setCookie.bind(options.cookieJar));
- getCookieString = util_1.promisify(getCookieString.bind(options.cookieJar));
- options.cookieJar = {
- setCookie,
- getCookieString: getCookieString
- };
- }
- }
- // `options.cache`
- const { cache } = options;
- if (cache) {
- if (!cacheableStore.has(cache)) {
- cacheableStore.set(cache, new CacheableRequest(((requestOptions, handler) => {
- const result = requestOptions[kRequest](requestOptions, handler);
- // TODO: remove this when `cacheable-request` supports async request functions.
- if (is_1.default.promise(result)) {
- // @ts-expect-error
- // We only need to implement the error handler in order to support HTTP2 caching.
- // The result will be a promise anyway.
- result.once = (event, handler) => {
- if (event === 'error') {
- result.catch(handler);
- }
- else if (event === 'abort') {
- // The empty catch is needed here in case when
- // it rejects before it's `await`ed in `_makeRequest`.
- (async () => {
- try {
- const request = (await result);
- request.once('abort', handler);
- }
- catch (_a) { }
- })();
- }
- else {
- /* istanbul ignore next: safety check */
- throw new Error(`Unknown HTTP2 promise event: ${event}`);
- }
- return result;
- };
- }
- return result;
- }), cache));
- }
- }
- // `options.cacheOptions`
- options.cacheOptions = { ...options.cacheOptions };
- // `options.dnsCache`
- if (options.dnsCache === true) {
- if (!globalDnsCache) {
- globalDnsCache = new cacheable_lookup_1.default();
- }
- options.dnsCache = globalDnsCache;
- }
- else if (!is_1.default.undefined(options.dnsCache) && !options.dnsCache.lookup) {
- throw new TypeError(`Parameter \`dnsCache\` must be a CacheableLookup instance or a boolean, got ${is_1.default(options.dnsCache)}`);
- }
- // `options.timeout`
- if (is_1.default.number(options.timeout)) {
- options.timeout = { request: options.timeout };
- }
- else if (defaults && options.timeout !== defaults.timeout) {
- options.timeout = {
- ...defaults.timeout,
- ...options.timeout
- };
- }
- else {
- options.timeout = { ...options.timeout };
- }
- // `options.context`
- if (!options.context) {
- options.context = {};
- }
- // `options.hooks`
- const areHooksDefault = options.hooks === (defaults === null || defaults === void 0 ? void 0 : defaults.hooks);
- options.hooks = { ...options.hooks };
- for (const event of exports.knownHookEvents) {
- if (event in options.hooks) {
- if (is_1.default.array(options.hooks[event])) {
- // See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
- options.hooks[event] = [...options.hooks[event]];
- }
- else {
- throw new TypeError(`Parameter \`${event}\` must be an Array, got ${is_1.default(options.hooks[event])}`);
- }
- }
- else {
- options.hooks[event] = [];
- }
- }
- if (defaults && !areHooksDefault) {
- for (const event of exports.knownHookEvents) {
- const defaultHooks = defaults.hooks[event];
- if (defaultHooks.length > 0) {
- // See https://github.com/microsoft/TypeScript/issues/31445#issuecomment-576929044
- options.hooks[event] = [
- ...defaults.hooks[event],
- ...options.hooks[event]
- ];
- }
- }
- }
- // DNS options
- if ('family' in options) {
- deprecation_warning_1.default('"options.family" was never documented, please use "options.dnsLookupIpVersion"');
- }
- // HTTPS options
- if (defaults === null || defaults === void 0 ? void 0 : defaults.https) {
- options.https = { ...defaults.https, ...options.https };
- }
- if ('rejectUnauthorized' in options) {
- deprecation_warning_1.default('"options.rejectUnauthorized" is now deprecated, please use "options.https.rejectUnauthorized"');
- }
- if ('checkServerIdentity' in options) {
- deprecation_warning_1.default('"options.checkServerIdentity" was never documented, please use "options.https.checkServerIdentity"');
- }
- if ('ca' in options) {
- deprecation_warning_1.default('"options.ca" was never documented, please use "options.https.certificateAuthority"');
- }
- if ('key' in options) {
- deprecation_warning_1.default('"options.key" was never documented, please use "options.https.key"');
- }
- if ('cert' in options) {
- deprecation_warning_1.default('"options.cert" was never documented, please use "options.https.certificate"');
- }
- if ('passphrase' in options) {
- deprecation_warning_1.default('"options.passphrase" was never documented, please use "options.https.passphrase"');
- }
- if ('pfx' in options) {
- deprecation_warning_1.default('"options.pfx" was never documented, please use "options.https.pfx"');
- }
- // Other options
- if ('followRedirects' in options) {
- throw new TypeError('The `followRedirects` option does not exist. Use `followRedirect` instead.');
- }
- if (options.agent) {
- for (const key in options.agent) {
- if (key !== 'http' && key !== 'https' && key !== 'http2') {
- throw new TypeError(`Expected the \`options.agent\` properties to be \`http\`, \`https\` or \`http2\`, got \`${key}\``);
- }
- }
- }
- options.maxRedirects = (_e = options.maxRedirects) !== null && _e !== void 0 ? _e : 0;
- // Set non-enumerable properties
- exports.setNonEnumerableProperties([defaults, rawOptions], options);
- return normalize_arguments_1.default(options, defaults);
- }
- _lockWrite() {
- const onLockedWrite = () => {
- throw new TypeError('The payload has been already provided');
- };
- this.write = onLockedWrite;
- this.end = onLockedWrite;
- }
- _unlockWrite() {
- this.write = super.write;
- this.end = super.end;
- }
- async _finalizeBody() {
- const { options } = this;
- const { headers } = options;
- const isForm = !is_1.default.undefined(options.form);
- const isJSON = !is_1.default.undefined(options.json);
- const isBody = !is_1.default.undefined(options.body);
- const hasPayload = isForm || isJSON || isBody;
- const cannotHaveBody = exports.withoutBody.has(options.method) && !(options.method === 'GET' && options.allowGetBody);
- this._cannotHaveBody = cannotHaveBody;
- if (hasPayload) {
- if (cannotHaveBody) {
- throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
- }
- if ([isBody, isForm, isJSON].filter(isTrue => isTrue).length > 1) {
- throw new TypeError('The `body`, `json` and `form` options are mutually exclusive');
- }
- if (isBody &&
- !(options.body instanceof stream_1.Readable) &&
- !is_1.default.string(options.body) &&
- !is_1.default.buffer(options.body) &&
- !is_form_data_1.default(options.body)) {
- throw new TypeError('The `body` option must be a stream.Readable, string or Buffer');
- }
- if (isForm && !is_1.default.object(options.form)) {
- throw new TypeError('The `form` option must be an Object');
- }
- {
- // Serialize body
- const noContentType = !is_1.default.string(headers['content-type']);
- if (isBody) {
- // Special case for https://github.com/form-data/form-data
- if (is_form_data_1.default(options.body) && noContentType) {
- headers['content-type'] = `multipart/form-data; boundary=${options.body.getBoundary()}`;
- }
- this[kBody] = options.body;
- }
- else if (isForm) {
- if (noContentType) {
- headers['content-type'] = 'application/x-www-form-urlencoded';
- }
- this[kBody] = (new url_1.URLSearchParams(options.form)).toString();
- }
- else {
- if (noContentType) {
- headers['content-type'] = 'application/json';
- }
- this[kBody] = options.stringifyJson(options.json);
- }
- const uploadBodySize = await get_body_size_1.default(this[kBody], options.headers);
- // See https://tools.ietf.org/html/rfc7230#section-3.3.2
- // A user agent SHOULD send a Content-Length in a request message when
- // no Transfer-Encoding is sent and the request method defines a meaning
- // for an enclosed payload body. For example, a Content-Length header
- // field is normally sent in a POST request even when the value is 0
- // (indicating an empty payload body). A user agent SHOULD NOT send a
- // Content-Length header field when the request message does not contain
- // a payload body and the method semantics do not anticipate such a
- // body.
- if (is_1.default.undefined(headers['content-length']) && is_1.default.undefined(headers['transfer-encoding'])) {
- if (!cannotHaveBody && !is_1.default.undefined(uploadBodySize)) {
- headers['content-length'] = String(uploadBodySize);
- }
- }
- }
- }
- else if (cannotHaveBody) {
- this._lockWrite();
- }
- else {
- this._unlockWrite();
- }
- this[kBodySize] = Number(headers['content-length']) || undefined;
- }
- async _onResponseBase(response) {
- const { options } = this;
- const { url } = options;
- this[kOriginalResponse] = response;
- if (options.decompress) {
- response = decompressResponse(response);
- }
- const statusCode = response.statusCode;
- const typedResponse = response;
- typedResponse.statusMessage = typedResponse.statusMessage ? typedResponse.statusMessage : http.STATUS_CODES[statusCode];
- typedResponse.url = options.url.toString();
- typedResponse.requestUrl = this.requestUrl;
- typedResponse.redirectUrls = this.redirects;
- typedResponse.request = this;
- typedResponse.isFromCache = response.fromCache || false;
- typedResponse.ip = this.ip;
- typedResponse.retryCount = this.retryCount;
- this[kIsFromCache] = typedResponse.isFromCache;
- this[kResponseSize] = Number(response.headers['content-length']) || undefined;
- this[kResponse] = response;
- response.once('end', () => {
- this[kResponseSize] = this[kDownloadedSize];
- this.emit('downloadProgress', this.downloadProgress);
- });
- response.once('error', (error) => {
- // Force clean-up, because some packages don't do this.
- // TODO: Fix decompress-response
- response.destroy();
- this._beforeError(new ReadError(error, this));
- });
- response.once('aborted', () => {
- this._beforeError(new ReadError({
- name: 'Error',
- message: 'The server aborted pending request',
- code: 'ECONNRESET'
- }, this));
- });
- this.emit('downloadProgress', this.downloadProgress);
- const rawCookies = response.headers['set-cookie'];
- if (is_1.default.object(options.cookieJar) && rawCookies) {
- let promises = rawCookies.map(async (rawCookie) => options.cookieJar.setCookie(rawCookie, url.toString()));
- if (options.ignoreInvalidCookies) {
- promises = promises.map(async (p) => p.catch(() => { }));
- }
- try {
- await Promise.all(promises);
- }
- catch (error) {
- this._beforeError(error);
- return;
- }
- }
- if (options.followRedirect && response.headers.location && redirectCodes.has(statusCode)) {
- // We're being redirected, we don't care about the response.
- // It'd be best to abort the request, but we can't because
- // we would have to sacrifice the TCP connection. We don't want that.
- response.resume();
- if (this[kRequest]) {
- this[kCancelTimeouts]();
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
- delete this[kRequest];
- this[kUnproxyEvents]();
- }
- const shouldBeGet = statusCode === 303 && options.method !== 'GET' && options.method !== 'HEAD';
- if (shouldBeGet || !options.methodRewriting) {
- // Server responded with "see other", indicating that the resource exists at another location,
- // and the client should request it from that location via GET or HEAD.
- options.method = 'GET';
- if ('body' in options) {
- delete options.body;
- }
- if ('json' in options) {
- delete options.json;
- }
- if ('form' in options) {
- delete options.form;
- }
- this[kBody] = undefined;
- delete options.headers['content-length'];
- }
- if (this.redirects.length >= options.maxRedirects) {
- this._beforeError(new MaxRedirectsError(this));
- return;
- }
- try {
- // Do not remove. See https://github.com/sindresorhus/got/pull/214
- const redirectBuffer = Buffer.from(response.headers.location, 'binary').toString();
- // Handles invalid URLs. See https://github.com/sindresorhus/got/issues/604
- const redirectUrl = new url_1.URL(redirectBuffer, url);
- const redirectString = redirectUrl.toString();
- decodeURI(redirectString);
- // eslint-disable-next-line no-inner-declarations
- function isUnixSocketURL(url) {
- return url.protocol === 'unix:' || url.hostname === 'unix';
- }
- if (!isUnixSocketURL(url) && isUnixSocketURL(redirectUrl)) {
- this._beforeError(new RequestError('Cannot redirect to UNIX socket', {}, this));
- return;
- }
- // Redirecting to a different site, clear sensitive data.
- if (redirectUrl.hostname !== url.hostname || redirectUrl.port !== url.port) {
- if ('host' in options.headers) {
- delete options.headers.host;
- }
- if ('cookie' in options.headers) {
- delete options.headers.cookie;
- }
- if ('authorization' in options.headers) {
- delete options.headers.authorization;
- }
- if (options.username || options.password) {
- options.username = '';
- options.password = '';
- }
- }
- else {
- redirectUrl.username = options.username;
- redirectUrl.password = options.password;
- }
- this.redirects.push(redirectString);
- options.url = redirectUrl;
- for (const hook of options.hooks.beforeRedirect) {
- // eslint-disable-next-line no-await-in-loop
- await hook(options, typedResponse);
- }
- this.emit('redirect', typedResponse, options);
- await this._makeRequest();
- }
- catch (error) {
- this._beforeError(error);
- return;
- }
- return;
- }
- if (options.isStream && options.throwHttpErrors && !is_response_ok_1.isResponseOk(typedResponse)) {
- this._beforeError(new HTTPError(typedResponse));
- return;
- }
- response.on('readable', () => {
- if (this[kTriggerRead]) {
- this._read();
- }
- });
- this.on('resume', () => {
- response.resume();
- });
- this.on('pause', () => {
- response.pause();
- });
- response.once('end', () => {
- this.push(null);
- });
- this.emit('response', response);
- for (const destination of this[kServerResponsesPiped]) {
- if (destination.headersSent) {
- continue;
- }
- // eslint-disable-next-line guard-for-in
- for (const key in response.headers) {
- const isAllowed = options.decompress ? key !== 'content-encoding' : true;
- const value = response.headers[key];
- if (isAllowed) {
- destination.setHeader(key, value);
- }
- }
- destination.statusCode = statusCode;
- }
- }
- async _onResponse(response) {
- try {
- await this._onResponseBase(response);
- }
- catch (error) {
- /* istanbul ignore next: better safe than sorry */
- this._beforeError(error);
- }
- }
- _onRequest(request) {
- const { options } = this;
- const { timeout, url } = options;
- http_timer_1.default(request);
- this[kCancelTimeouts] = timed_out_1.default(request, timeout, url);
- const responseEventName = options.cache ? 'cacheableResponse' : 'response';
- request.once(responseEventName, (response) => {
- void this._onResponse(response);
- });
- request.once('error', (error) => {
- var _a;
- // Force clean-up, because some packages (e.g. nock) don't do this.
- request.destroy();
- // Node.js <= 12.18.2 mistakenly emits the response `end` first.
- (_a = request.res) === null || _a === void 0 ? void 0 : _a.removeAllListeners('end');
- error = error instanceof timed_out_1.TimeoutError ? new TimeoutError(error, this.timings, this) : new RequestError(error.message, error, this);
- this._beforeError(error);
- });
- this[kUnproxyEvents] = proxy_events_1.default(request, this, proxiedRequestEvents);
- this[kRequest] = request;
- this.emit('uploadProgress', this.uploadProgress);
- // Send body
- const body = this[kBody];
- const currentRequest = this.redirects.length === 0 ? this : request;
- if (is_1.default.nodeStream(body)) {
- body.pipe(currentRequest);
- body.once('error', (error) => {
- this._beforeError(new UploadError(error, this));
- });
- }
- else {
- this._unlockWrite();
- if (!is_1.default.undefined(body)) {
- this._writeRequest(body, undefined, () => { });
- currentRequest.end();
- this._lockWrite();
- }
- else if (this._cannotHaveBody || this._noPipe) {
- currentRequest.end();
- this._lockWrite();
- }
- }
- this.emit('request', request);
- }
- async _createCacheableRequest(url, options) {
- return new Promise((resolve, reject) => {
- // TODO: Remove `utils/url-to-options.ts` when `cacheable-request` is fixed
- Object.assign(options, url_to_options_1.default(url));
- // `http-cache-semantics` checks this
- // TODO: Fix this ignore.
- // @ts-expect-error
- delete options.url;
- let request;
- // This is ugly
- const cacheRequest = cacheableStore.get(options.cache)(options, async (response) => {
- // TODO: Fix `cacheable-response`
- response._readableState.autoDestroy = false;
- if (request) {
- (await request).emit('cacheableResponse', response);
- }
- resolve(response);
- });
- // Restore options
- options.url = url;
- cacheRequest.once('error', reject);
- cacheRequest.once('request', async (requestOrPromise) => {
- request = requestOrPromise;
- resolve(request);
- });
- });
- }
- async _makeRequest() {
- var _a, _b, _c, _d, _e;
- const { options } = this;
- const { headers } = options;
- for (const key in headers) {
- if (is_1.default.undefined(headers[key])) {
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
- delete headers[key];
- }
- else if (is_1.default.null_(headers[key])) {
- throw new TypeError(`Use \`undefined\` instead of \`null\` to delete the \`${key}\` header`);
- }
- }
- if (options.decompress && is_1.default.undefined(headers['accept-encoding'])) {
- headers['accept-encoding'] = supportsBrotli ? 'gzip, deflate, br' : 'gzip, deflate';
- }
- // Set cookies
- if (options.cookieJar) {
- const cookieString = await options.cookieJar.getCookieString(options.url.toString());
- if (is_1.default.nonEmptyString(cookieString)) {
- options.headers.cookie = cookieString;
- }
- }
- for (const hook of options.hooks.beforeRequest) {
- // eslint-disable-next-line no-await-in-loop
- const result = await hook(options);
- if (!is_1.default.undefined(result)) {
- // @ts-expect-error Skip the type mismatch to support abstract responses
- options.request = () => result;
- break;
- }
- }
- if (options.body && this[kBody] !== options.body) {
- this[kBody] = options.body;
- }
- const { agent, request, timeout, url } = options;
- if (options.dnsCache && !('lookup' in options)) {
- options.lookup = options.dnsCache.lookup;
- }
- // UNIX sockets
- if (url.hostname === 'unix') {
- const matches = /(?.+?):(?.+)/.exec(`${url.pathname}${url.search}`);
- if (matches === null || matches === void 0 ? void 0 : matches.groups) {
- const { socketPath, path } = matches.groups;
- Object.assign(options, {
- socketPath,
- path,
- host: ''
- });
- }
- }
- const isHttps = url.protocol === 'https:';
- // Fallback function
- let fallbackFn;
- if (options.http2) {
- fallbackFn = http2wrapper.auto;
- }
- else {
- fallbackFn = isHttps ? https.request : http.request;
- }
- const realFn = (_a = options.request) !== null && _a !== void 0 ? _a : fallbackFn;
- // Cache support
- const fn = options.cache ? this._createCacheableRequest : realFn;
- // Pass an agent directly when HTTP2 is disabled
- if (agent && !options.http2) {
- options.agent = agent[isHttps ? 'https' : 'http'];
- }
- // Prepare plain HTTP request options
- options[kRequest] = realFn;
- delete options.request;
- // TODO: Fix this ignore.
- // @ts-expect-error
- delete options.timeout;
- const requestOptions = options;
- requestOptions.shared = (_b = options.cacheOptions) === null || _b === void 0 ? void 0 : _b.shared;
- requestOptions.cacheHeuristic = (_c = options.cacheOptions) === null || _c === void 0 ? void 0 : _c.cacheHeuristic;
- requestOptions.immutableMinTimeToLive = (_d = options.cacheOptions) === null || _d === void 0 ? void 0 : _d.immutableMinTimeToLive;
- requestOptions.ignoreCargoCult = (_e = options.cacheOptions) === null || _e === void 0 ? void 0 : _e.ignoreCargoCult;
- // If `dnsLookupIpVersion` is not present do not override `family`
- if (options.dnsLookupIpVersion !== undefined) {
- try {
- requestOptions.family = dns_ip_version_1.dnsLookupIpVersionToFamily(options.dnsLookupIpVersion);
- }
- catch (_f) {
- throw new Error('Invalid `dnsLookupIpVersion` option value');
- }
- }
- // HTTPS options remapping
- if (options.https) {
- if ('rejectUnauthorized' in options.https) {
- requestOptions.rejectUnauthorized = options.https.rejectUnauthorized;
- }
- if (options.https.checkServerIdentity) {
- requestOptions.checkServerIdentity = options.https.checkServerIdentity;
- }
- if (options.https.certificateAuthority) {
- requestOptions.ca = options.https.certificateAuthority;
- }
- if (options.https.certificate) {
- requestOptions.cert = options.https.certificate;
- }
- if (options.https.key) {
- requestOptions.key = options.https.key;
- }
- if (options.https.passphrase) {
- requestOptions.passphrase = options.https.passphrase;
- }
- if (options.https.pfx) {
- requestOptions.pfx = options.https.pfx;
- }
- }
- try {
- let requestOrResponse = await fn(url, requestOptions);
- if (is_1.default.undefined(requestOrResponse)) {
- requestOrResponse = fallbackFn(url, requestOptions);
- }
- // Restore options
- options.request = request;
- options.timeout = timeout;
- options.agent = agent;
- // HTTPS options restore
- if (options.https) {
- if ('rejectUnauthorized' in options.https) {
- delete requestOptions.rejectUnauthorized;
- }
- if (options.https.checkServerIdentity) {
- // @ts-expect-error - This one will be removed when we remove the alias.
- delete requestOptions.checkServerIdentity;
- }
- if (options.https.certificateAuthority) {
- delete requestOptions.ca;
- }
- if (options.https.certificate) {
- delete requestOptions.cert;
- }
- if (options.https.key) {
- delete requestOptions.key;
- }
- if (options.https.passphrase) {
- delete requestOptions.passphrase;
- }
- if (options.https.pfx) {
- delete requestOptions.pfx;
- }
- }
- if (isClientRequest(requestOrResponse)) {
- this._onRequest(requestOrResponse);
- // Emit the response after the stream has been ended
- }
- else if (this.writable) {
- this.once('finish', () => {
- void this._onResponse(requestOrResponse);
- });
- this._unlockWrite();
- this.end();
- this._lockWrite();
- }
- else {
- void this._onResponse(requestOrResponse);
- }
- }
- catch (error) {
- if (error instanceof CacheableRequest.CacheError) {
- throw new CacheError(error, this);
- }
- throw new RequestError(error.message, error, this);
- }
- }
- async _error(error) {
- try {
- for (const hook of this.options.hooks.beforeError) {
- // eslint-disable-next-line no-await-in-loop
- error = await hook(error);
- }
- }
- catch (error_) {
- error = new RequestError(error_.message, error_, this);
- }
- this.destroy(error);
- }
- _beforeError(error) {
- if (this[kStopReading]) {
- return;
- }
- const { options } = this;
- const retryCount = this.retryCount + 1;
- this[kStopReading] = true;
- if (!(error instanceof RequestError)) {
- error = new RequestError(error.message, error, this);
- }
- const typedError = error;
- const { response } = typedError;
- void (async () => {
- if (response && !response.body) {
- response.setEncoding(this._readableState.encoding);
- try {
- response.rawBody = await get_buffer_1.default(response);
- response.body = response.rawBody.toString();
- }
- catch (_a) { }
- }
- if (this.listenerCount('retry') !== 0) {
- let backoff;
- try {
- let retryAfter;
- if (response && 'retry-after' in response.headers) {
- retryAfter = Number(response.headers['retry-after']);
- if (Number.isNaN(retryAfter)) {
- retryAfter = Date.parse(response.headers['retry-after']) - Date.now();
- if (retryAfter <= 0) {
- retryAfter = 1;
- }
- }
- else {
- retryAfter *= 1000;
- }
- }
- backoff = await options.retry.calculateDelay({
- attemptCount: retryCount,
- retryOptions: options.retry,
- error: typedError,
- retryAfter,
- computedValue: calculate_retry_delay_1.default({
- attemptCount: retryCount,
- retryOptions: options.retry,
- error: typedError,
- retryAfter,
- computedValue: 0
- })
- });
- }
- catch (error_) {
- void this._error(new RequestError(error_.message, error_, this));
- return;
- }
- if (backoff) {
- const retry = async () => {
- try {
- for (const hook of this.options.hooks.beforeRetry) {
- // eslint-disable-next-line no-await-in-loop
- await hook(this.options, typedError, retryCount);
- }
- }
- catch (error_) {
- void this._error(new RequestError(error_.message, error, this));
- return;
- }
- // Something forced us to abort the retry
- if (this.destroyed) {
- return;
- }
- this.destroy();
- this.emit('retry', retryCount, error);
- };
- this[kRetryTimeout] = setTimeout(retry, backoff);
- return;
- }
- }
- void this._error(typedError);
- })();
- }
- _read() {
- this[kTriggerRead] = true;
- const response = this[kResponse];
- if (response && !this[kStopReading]) {
- // We cannot put this in the `if` above
- // because `.read()` also triggers the `end` event
- if (response.readableLength) {
- this[kTriggerRead] = false;
- }
- let data;
- while ((data = response.read()) !== null) {
- this[kDownloadedSize] += data.length;
- this[kStartedReading] = true;
- const progress = this.downloadProgress;
- if (progress.percent < 1) {
- this.emit('downloadProgress', progress);
- }
- this.push(data);
- }
- }
- }
- // Node.js 12 has incorrect types, so the encoding must be a string
- _write(chunk, encoding, callback) {
- const write = () => {
- this._writeRequest(chunk, encoding, callback);
- };
- if (this.requestInitialized) {
- write();
- }
- else {
- this[kJobs].push(write);
- }
- }
- _writeRequest(chunk, encoding, callback) {
- if (this[kRequest].destroyed) {
- // Probably the `ClientRequest` instance will throw
- return;
- }
- this._progressCallbacks.push(() => {
- this[kUploadedSize] += Buffer.byteLength(chunk, encoding);
- const progress = this.uploadProgress;
- if (progress.percent < 1) {
- this.emit('uploadProgress', progress);
- }
- });
- // TODO: What happens if it's from cache? Then this[kRequest] won't be defined.
- this[kRequest].write(chunk, encoding, (error) => {
- if (!error && this._progressCallbacks.length > 0) {
- this._progressCallbacks.shift()();
- }
- callback(error);
- });
- }
- _final(callback) {
- const endRequest = () => {
- // FIX: Node.js 10 calls the write callback AFTER the end callback!
- while (this._progressCallbacks.length !== 0) {
- this._progressCallbacks.shift()();
- }
- // We need to check if `this[kRequest]` is present,
- // because it isn't when we use cache.
- if (!(kRequest in this)) {
- callback();
- return;
- }
- if (this[kRequest].destroyed) {
- callback();
- return;
- }
- this[kRequest].end((error) => {
- if (!error) {
- this[kBodySize] = this[kUploadedSize];
- this.emit('uploadProgress', this.uploadProgress);
- this[kRequest].emit('upload-complete');
- }
- callback(error);
- });
- };
- if (this.requestInitialized) {
- endRequest();
- }
- else {
- this[kJobs].push(endRequest);
- }
- }
- _destroy(error, callback) {
- var _a;
- this[kStopReading] = true;
- // Prevent further retries
- clearTimeout(this[kRetryTimeout]);
- if (kRequest in this) {
- this[kCancelTimeouts]();
- // TODO: Remove the next `if` when these get fixed:
- // - https://github.com/nodejs/node/issues/32851
- if (!((_a = this[kResponse]) === null || _a === void 0 ? void 0 : _a.complete)) {
- this[kRequest].destroy();
- }
- }
- if (error !== null && !is_1.default.undefined(error) && !(error instanceof RequestError)) {
- error = new RequestError(error.message, error, this);
- }
- callback(error);
- }
- get _isAboutToError() {
- return this[kStopReading];
- }
- /**
- The remote IP address.
- */
- get ip() {
- var _a;
- return (_a = this.socket) === null || _a === void 0 ? void 0 : _a.remoteAddress;
- }
- /**
- Indicates whether the request has been aborted or not.
- */
- get aborted() {
- var _a, _b, _c;
- return ((_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.destroyed) !== null && _b !== void 0 ? _b : this.destroyed) && !((_c = this[kOriginalResponse]) === null || _c === void 0 ? void 0 : _c.complete);
- }
- get socket() {
- var _a, _b;
- return (_b = (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.socket) !== null && _b !== void 0 ? _b : undefined;
- }
- /**
- Progress event for downloading (receiving a response).
- */
- get downloadProgress() {
- let percent;
- if (this[kResponseSize]) {
- percent = this[kDownloadedSize] / this[kResponseSize];
- }
- else if (this[kResponseSize] === this[kDownloadedSize]) {
- percent = 1;
- }
- else {
- percent = 0;
- }
- return {
- percent,
- transferred: this[kDownloadedSize],
- total: this[kResponseSize]
- };
- }
- /**
- Progress event for uploading (sending a request).
- */
- get uploadProgress() {
- let percent;
- if (this[kBodySize]) {
- percent = this[kUploadedSize] / this[kBodySize];
- }
- else if (this[kBodySize] === this[kUploadedSize]) {
- percent = 1;
- }
- else {
- percent = 0;
- }
- return {
- percent,
- transferred: this[kUploadedSize],
- total: this[kBodySize]
- };
- }
- /**
- The object contains the following properties:
-
- - `start` - Time when the request started.
- - `socket` - Time when a socket was assigned to the request.
- - `lookup` - Time when the DNS lookup finished.
- - `connect` - Time when the socket successfully connected.
- - `secureConnect` - Time when the socket securely connected.
- - `upload` - Time when the request finished uploading.
- - `response` - Time when the request fired `response` event.
- - `end` - Time when the response fired `end` event.
- - `error` - Time when the request fired `error` event.
- - `abort` - Time when the request fired `abort` event.
- - `phases`
- - `wait` - `timings.socket - timings.start`
- - `dns` - `timings.lookup - timings.socket`
- - `tcp` - `timings.connect - timings.lookup`
- - `tls` - `timings.secureConnect - timings.connect`
- - `request` - `timings.upload - (timings.secureConnect || timings.connect)`
- - `firstByte` - `timings.response - timings.upload`
- - `download` - `timings.end - timings.response`
- - `total` - `(timings.end || timings.error || timings.abort) - timings.start`
-
- If something has not been measured yet, it will be `undefined`.
-
- __Note__: The time is a `number` representing the milliseconds elapsed since the UNIX epoch.
- */
- get timings() {
- var _a;
- return (_a = this[kRequest]) === null || _a === void 0 ? void 0 : _a.timings;
- }
- /**
- Whether the response was retrieved from the cache.
- */
- get isFromCache() {
- return this[kIsFromCache];
- }
- pipe(destination, options) {
- if (this[kStartedReading]) {
- throw new Error('Failed to pipe. The response has been emitted already.');
- }
- if (destination instanceof http_1.ServerResponse) {
- this[kServerResponsesPiped].add(destination);
- }
- return super.pipe(destination, options);
- }
- unpipe(destination) {
- if (destination instanceof http_1.ServerResponse) {
- this[kServerResponsesPiped].delete(destination);
- }
- super.unpipe(destination);
- return this;
- }
-}
-exports["default"] = Request;
-
-
-/***/ }),
-
-/***/ 4993:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.dnsLookupIpVersionToFamily = exports.isDnsLookupIpVersion = void 0;
-const conversionTable = {
- auto: 0,
- ipv4: 4,
- ipv6: 6
-};
-exports.isDnsLookupIpVersion = (value) => {
- return value in conversionTable;
-};
-exports.dnsLookupIpVersionToFamily = (dnsLookupIpVersion) => {
- if (exports.isDnsLookupIpVersion(dnsLookupIpVersion)) {
- return conversionTable[dnsLookupIpVersion];
- }
- throw new Error('Invalid DNS lookup IP version');
-};
-
-
-/***/ }),
-
-/***/ 4564:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const fs_1 = __nccwpck_require__(7147);
-const util_1 = __nccwpck_require__(3837);
-const is_1 = __nccwpck_require__(7678);
-const is_form_data_1 = __nccwpck_require__(40);
-const statAsync = util_1.promisify(fs_1.stat);
-exports["default"] = async (body, headers) => {
- if (headers && 'content-length' in headers) {
- return Number(headers['content-length']);
- }
- if (!body) {
- return 0;
- }
- if (is_1.default.string(body)) {
- return Buffer.byteLength(body);
- }
- if (is_1.default.buffer(body)) {
- return body.length;
- }
- if (is_form_data_1.default(body)) {
- return util_1.promisify(body.getLength.bind(body))();
- }
- if (body instanceof fs_1.ReadStream) {
- const { size } = await statAsync(body.path);
- if (size === 0) {
- return undefined;
- }
- return size;
- }
- return undefined;
-};
-
-
-/***/ }),
-
-/***/ 4500:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-// TODO: Update https://github.com/sindresorhus/get-stream
-const getBuffer = async (stream) => {
- const chunks = [];
- let length = 0;
- for await (const chunk of stream) {
- chunks.push(chunk);
- length += Buffer.byteLength(chunk);
- }
- if (Buffer.isBuffer(chunks[0])) {
- return Buffer.concat(chunks, length);
- }
- return Buffer.from(chunks.join(''));
-};
-exports["default"] = getBuffer;
-
-
-/***/ }),
-
-/***/ 40:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const is_1 = __nccwpck_require__(7678);
-exports["default"] = (body) => is_1.default.nodeStream(body) && is_1.default.function_(body.getBoundary);
-
-
-/***/ }),
-
-/***/ 9298:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.isResponseOk = void 0;
-exports.isResponseOk = (response) => {
- const { statusCode } = response;
- const limitStatusCode = response.request.options.followRedirect ? 299 : 399;
- return (statusCode >= 200 && statusCode <= limitStatusCode) || statusCode === 304;
-};
-
-
-/***/ }),
-
-/***/ 9219:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-/* istanbul ignore file: deprecated */
-const url_1 = __nccwpck_require__(7310);
-const keys = [
- 'protocol',
- 'host',
- 'hostname',
- 'port',
- 'pathname',
- 'search'
-];
-exports["default"] = (origin, options) => {
- var _a, _b;
- if (options.path) {
- if (options.pathname) {
- throw new TypeError('Parameters `path` and `pathname` are mutually exclusive.');
- }
- if (options.search) {
- throw new TypeError('Parameters `path` and `search` are mutually exclusive.');
- }
- if (options.searchParams) {
- throw new TypeError('Parameters `path` and `searchParams` are mutually exclusive.');
- }
- }
- if (options.search && options.searchParams) {
- throw new TypeError('Parameters `search` and `searchParams` are mutually exclusive.');
- }
- if (!origin) {
- if (!options.protocol) {
- throw new TypeError('No URL protocol specified');
- }
- origin = `${options.protocol}//${(_b = (_a = options.hostname) !== null && _a !== void 0 ? _a : options.host) !== null && _b !== void 0 ? _b : ''}`;
- }
- const url = new url_1.URL(origin);
- if (options.path) {
- const searchIndex = options.path.indexOf('?');
- if (searchIndex === -1) {
- options.pathname = options.path;
- }
- else {
- options.pathname = options.path.slice(0, searchIndex);
- options.search = options.path.slice(searchIndex + 1);
- }
- delete options.path;
- }
- for (const key of keys) {
- if (options[key]) {
- url[key] = options[key].toString();
- }
- }
- return url;
-};
-
-
-/***/ }),
-
-/***/ 3021:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-function default_1(from, to, events) {
- const fns = {};
- for (const event of events) {
- fns[event] = (...args) => {
- to.emit(event, ...args);
- };
- from.on(event, fns[event]);
- }
- return () => {
- for (const event of events) {
- from.off(event, fns[event]);
- }
- };
-}
-exports["default"] = default_1;
-
-
-/***/ }),
-
-/***/ 2454:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.TimeoutError = void 0;
-const net = __nccwpck_require__(1808);
-const unhandle_1 = __nccwpck_require__(1593);
-const reentry = Symbol('reentry');
-const noop = () => { };
-class TimeoutError extends Error {
- constructor(threshold, event) {
- super(`Timeout awaiting '${event}' for ${threshold}ms`);
- this.event = event;
- this.name = 'TimeoutError';
- this.code = 'ETIMEDOUT';
- }
-}
-exports.TimeoutError = TimeoutError;
-exports["default"] = (request, delays, options) => {
- if (reentry in request) {
- return noop;
- }
- request[reentry] = true;
- const cancelers = [];
- const { once, unhandleAll } = unhandle_1.default();
- const addTimeout = (delay, callback, event) => {
- var _a;
- const timeout = setTimeout(callback, delay, delay, event);
- (_a = timeout.unref) === null || _a === void 0 ? void 0 : _a.call(timeout);
- const cancel = () => {
- clearTimeout(timeout);
- };
- cancelers.push(cancel);
- return cancel;
- };
- const { host, hostname } = options;
- const timeoutHandler = (delay, event) => {
- request.destroy(new TimeoutError(delay, event));
- };
- const cancelTimeouts = () => {
- for (const cancel of cancelers) {
- cancel();
- }
- unhandleAll();
- };
- request.once('error', error => {
- cancelTimeouts();
- // Save original behavior
- /* istanbul ignore next */
- if (request.listenerCount('error') === 0) {
- throw error;
- }
- });
- request.once('close', cancelTimeouts);
- once(request, 'response', (response) => {
- once(response, 'end', cancelTimeouts);
- });
- if (typeof delays.request !== 'undefined') {
- addTimeout(delays.request, timeoutHandler, 'request');
- }
- if (typeof delays.socket !== 'undefined') {
- const socketTimeoutHandler = () => {
- timeoutHandler(delays.socket, 'socket');
- };
- request.setTimeout(delays.socket, socketTimeoutHandler);
- // `request.setTimeout(0)` causes a memory leak.
- // We can just remove the listener and forget about the timer - it's unreffed.
- // See https://github.com/sindresorhus/got/issues/690
- cancelers.push(() => {
- request.removeListener('timeout', socketTimeoutHandler);
- });
- }
- once(request, 'socket', (socket) => {
- var _a;
- const { socketPath } = request;
- /* istanbul ignore next: hard to test */
- if (socket.connecting) {
- const hasPath = Boolean(socketPath !== null && socketPath !== void 0 ? socketPath : net.isIP((_a = hostname !== null && hostname !== void 0 ? hostname : host) !== null && _a !== void 0 ? _a : '') !== 0);
- if (typeof delays.lookup !== 'undefined' && !hasPath && typeof socket.address().address === 'undefined') {
- const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
- once(socket, 'lookup', cancelTimeout);
- }
- if (typeof delays.connect !== 'undefined') {
- const timeConnect = () => addTimeout(delays.connect, timeoutHandler, 'connect');
- if (hasPath) {
- once(socket, 'connect', timeConnect());
- }
- else {
- once(socket, 'lookup', (error) => {
- if (error === null) {
- once(socket, 'connect', timeConnect());
- }
- });
- }
- }
- if (typeof delays.secureConnect !== 'undefined' && options.protocol === 'https:') {
- once(socket, 'connect', () => {
- const cancelTimeout = addTimeout(delays.secureConnect, timeoutHandler, 'secureConnect');
- once(socket, 'secureConnect', cancelTimeout);
- });
- }
- }
- if (typeof delays.send !== 'undefined') {
- const timeRequest = () => addTimeout(delays.send, timeoutHandler, 'send');
- /* istanbul ignore next: hard to test */
- if (socket.connecting) {
- once(socket, 'connect', () => {
- once(request, 'upload-complete', timeRequest());
- });
- }
- else {
- once(request, 'upload-complete', timeRequest());
- }
- }
- });
- if (typeof delays.response !== 'undefined') {
- once(request, 'upload-complete', () => {
- const cancelTimeout = addTimeout(delays.response, timeoutHandler, 'response');
- once(request, 'response', cancelTimeout);
- });
- }
- return cancelTimeouts;
-};
-
-
-/***/ }),
-
-/***/ 1593:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-// When attaching listeners, it's very easy to forget about them.
-// Especially if you do error handling and set timeouts.
-// So instead of checking if it's proper to throw an error on every timeout ever,
-// use this simple tool which will remove all listeners you have attached.
-exports["default"] = () => {
- const handlers = [];
- return {
- once(origin, event, fn) {
- origin.once(event, fn);
- handlers.push({ origin, event, fn });
- },
- unhandleAll() {
- for (const handler of handlers) {
- const { origin, event, fn } = handler;
- origin.removeListener(event, fn);
- }
- handlers.length = 0;
- }
- };
-};
-
-
-/***/ }),
-
-/***/ 8026:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const is_1 = __nccwpck_require__(7678);
-exports["default"] = (url) => {
- // Cast to URL
- url = url;
- const options = {
- protocol: url.protocol,
- hostname: is_1.default.string(url.hostname) && url.hostname.startsWith('[') ? url.hostname.slice(1, -1) : url.hostname,
- host: url.host,
- hash: url.hash,
- search: url.search,
- pathname: url.pathname,
- href: url.href,
- path: `${url.pathname || ''}${url.search || ''}`
- };
- if (is_1.default.string(url.port) && url.port.length > 0) {
- options.port = Number(url.port);
- }
- if (url.username || url.password) {
- options.auth = `${url.username || ''}:${url.password || ''}`;
- }
- return options;
-};
-
-
-/***/ }),
-
-/***/ 7288:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-class WeakableMap {
- constructor() {
- this.weakMap = new WeakMap();
- this.map = new Map();
- }
- set(key, value) {
- if (typeof key === 'object') {
- this.weakMap.set(key, value);
- }
- else {
- this.map.set(key, value);
- }
- }
- get(key) {
- if (typeof key === 'object') {
- return this.weakMap.get(key);
- }
- return this.map.get(key);
- }
- has(key) {
- if (typeof key === 'object') {
- return this.weakMap.has(key);
- }
- return this.map.has(key);
- }
-}
-exports["default"] = WeakableMap;
-
-
-/***/ }),
-
-/***/ 4337:
-/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
-
-"use strict";
-
-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
-}) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
-}));
-var __exportStar = (this && this.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
-};
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.defaultHandler = void 0;
-const is_1 = __nccwpck_require__(7678);
-const as_promise_1 = __nccwpck_require__(6056);
-const create_rejection_1 = __nccwpck_require__(6457);
-const core_1 = __nccwpck_require__(94);
-const deep_freeze_1 = __nccwpck_require__(285);
-const errors = {
- RequestError: as_promise_1.RequestError,
- CacheError: as_promise_1.CacheError,
- ReadError: as_promise_1.ReadError,
- HTTPError: as_promise_1.HTTPError,
- MaxRedirectsError: as_promise_1.MaxRedirectsError,
- TimeoutError: as_promise_1.TimeoutError,
- ParseError: as_promise_1.ParseError,
- CancelError: as_promise_1.CancelError,
- UnsupportedProtocolError: as_promise_1.UnsupportedProtocolError,
- UploadError: as_promise_1.UploadError
-};
-// The `delay` package weighs 10KB (!)
-const delay = async (ms) => new Promise(resolve => {
- setTimeout(resolve, ms);
-});
-const { normalizeArguments } = core_1.default;
-const mergeOptions = (...sources) => {
- let mergedOptions;
- for (const source of sources) {
- mergedOptions = normalizeArguments(undefined, source, mergedOptions);
- }
- return mergedOptions;
-};
-const getPromiseOrStream = (options) => options.isStream ? new core_1.default(undefined, options) : as_promise_1.default(options);
-const isGotInstance = (value) => ('defaults' in value && 'options' in value.defaults);
-const aliases = [
- 'get',
- 'post',
- 'put',
- 'patch',
- 'head',
- 'delete'
-];
-exports.defaultHandler = (options, next) => next(options);
-const callInitHooks = (hooks, options) => {
- if (hooks) {
- for (const hook of hooks) {
- hook(options);
- }
- }
-};
-const create = (defaults) => {
- // Proxy properties from next handlers
- defaults._rawHandlers = defaults.handlers;
- defaults.handlers = defaults.handlers.map(fn => ((options, next) => {
- // This will be assigned by assigning result
- let root;
- const result = fn(options, newOptions => {
- root = next(newOptions);
- return root;
- });
- if (result !== root && !options.isStream && root) {
- const typedResult = result;
- const { then: promiseThen, catch: promiseCatch, finally: promiseFianlly } = typedResult;
- Object.setPrototypeOf(typedResult, Object.getPrototypeOf(root));
- Object.defineProperties(typedResult, Object.getOwnPropertyDescriptors(root));
- // These should point to the new promise
- // eslint-disable-next-line promise/prefer-await-to-then
- typedResult.then = promiseThen;
- typedResult.catch = promiseCatch;
- typedResult.finally = promiseFianlly;
- }
- return result;
- }));
- // Got interface
- const got = ((url, options = {}, _defaults) => {
- var _a, _b;
- let iteration = 0;
- const iterateHandlers = (newOptions) => {
- return defaults.handlers[iteration++](newOptions, iteration === defaults.handlers.length ? getPromiseOrStream : iterateHandlers);
- };
- // TODO: Remove this in Got 12.
- if (is_1.default.plainObject(url)) {
- const mergedOptions = {
- ...url,
- ...options
- };
- core_1.setNonEnumerableProperties([url, options], mergedOptions);
- options = mergedOptions;
- url = undefined;
- }
- try {
- // Call `init` hooks
- let initHookError;
- try {
- callInitHooks(defaults.options.hooks.init, options);
- callInitHooks((_a = options.hooks) === null || _a === void 0 ? void 0 : _a.init, options);
- }
- catch (error) {
- initHookError = error;
- }
- // Normalize options & call handlers
- const normalizedOptions = normalizeArguments(url, options, _defaults !== null && _defaults !== void 0 ? _defaults : defaults.options);
- normalizedOptions[core_1.kIsNormalizedAlready] = true;
- if (initHookError) {
- throw new as_promise_1.RequestError(initHookError.message, initHookError, normalizedOptions);
- }
- return iterateHandlers(normalizedOptions);
- }
- catch (error) {
- if (options.isStream) {
- throw error;
- }
- else {
- return create_rejection_1.default(error, defaults.options.hooks.beforeError, (_b = options.hooks) === null || _b === void 0 ? void 0 : _b.beforeError);
- }
- }
- });
- got.extend = (...instancesOrOptions) => {
- const optionsArray = [defaults.options];
- let handlers = [...defaults._rawHandlers];
- let isMutableDefaults;
- for (const value of instancesOrOptions) {
- if (isGotInstance(value)) {
- optionsArray.push(value.defaults.options);
- handlers.push(...value.defaults._rawHandlers);
- isMutableDefaults = value.defaults.mutableDefaults;
- }
- else {
- optionsArray.push(value);
- if ('handlers' in value) {
- handlers.push(...value.handlers);
- }
- isMutableDefaults = value.mutableDefaults;
- }
- }
- handlers = handlers.filter(handler => handler !== exports.defaultHandler);
- if (handlers.length === 0) {
- handlers.push(exports.defaultHandler);
- }
- return create({
- options: mergeOptions(...optionsArray),
- handlers,
- mutableDefaults: Boolean(isMutableDefaults)
- });
- };
- // Pagination
- const paginateEach = (async function* (url, options) {
- // TODO: Remove this `@ts-expect-error` when upgrading to TypeScript 4.
- // Error: Argument of type 'Merge> | undefined' is not assignable to parameter of type 'Options | undefined'.
- // @ts-expect-error
- let normalizedOptions = normalizeArguments(url, options, defaults.options);
- normalizedOptions.resolveBodyOnly = false;
- const pagination = normalizedOptions.pagination;
- if (!is_1.default.object(pagination)) {
- throw new TypeError('`options.pagination` must be implemented');
- }
- const all = [];
- let { countLimit } = pagination;
- let numberOfRequests = 0;
- while (numberOfRequests < pagination.requestLimit) {
- if (numberOfRequests !== 0) {
- // eslint-disable-next-line no-await-in-loop
- await delay(pagination.backoff);
- }
- // @ts-expect-error FIXME!
- // TODO: Throw when result is not an instance of Response
- // eslint-disable-next-line no-await-in-loop
- const result = (await got(undefined, undefined, normalizedOptions));
- // eslint-disable-next-line no-await-in-loop
- const parsed = await pagination.transform(result);
- const current = [];
- for (const item of parsed) {
- if (pagination.filter(item, all, current)) {
- if (!pagination.shouldContinue(item, all, current)) {
- return;
- }
- yield item;
- if (pagination.stackAllItems) {
- all.push(item);
- }
- current.push(item);
- if (--countLimit <= 0) {
- return;
- }
- }
- }
- const optionsToMerge = pagination.paginate(result, all, current);
- if (optionsToMerge === false) {
- return;
- }
- if (optionsToMerge === result.request.options) {
- normalizedOptions = result.request.options;
- }
- else if (optionsToMerge !== undefined) {
- normalizedOptions = normalizeArguments(undefined, optionsToMerge, normalizedOptions);
- }
- numberOfRequests++;
- }
- });
- got.paginate = paginateEach;
- got.paginate.all = (async (url, options) => {
- const results = [];
- for await (const item of paginateEach(url, options)) {
- results.push(item);
- }
- return results;
- });
- // For those who like very descriptive names
- got.paginate.each = paginateEach;
- // Stream API
- got.stream = ((url, options) => got(url, { ...options, isStream: true }));
- // Shortcuts
- for (const method of aliases) {
- got[method] = ((url, options) => got(url, { ...options, method }));
- got.stream[method] = ((url, options) => {
- return got(url, { ...options, method, isStream: true });
- });
- }
- Object.assign(got, errors);
- Object.defineProperty(got, 'defaults', {
- value: defaults.mutableDefaults ? defaults : deep_freeze_1.default(defaults),
- writable: defaults.mutableDefaults,
- configurable: defaults.mutableDefaults,
- enumerable: true
- });
- got.mergeOptions = mergeOptions;
- return got;
-};
-exports["default"] = create;
-__exportStar(__nccwpck_require__(2613), exports);
-
-
-/***/ }),
-
-/***/ 3061:
-/***/ (function(module, exports, __nccwpck_require__) {
-
-"use strict";
-
-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
-}) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
-}));
-var __exportStar = (this && this.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
-};
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const url_1 = __nccwpck_require__(7310);
-const create_1 = __nccwpck_require__(4337);
-const defaults = {
- options: {
- method: 'GET',
- retry: {
- limit: 2,
- methods: [
- 'GET',
- 'PUT',
- 'HEAD',
- 'DELETE',
- 'OPTIONS',
- 'TRACE'
- ],
- statusCodes: [
- 408,
- 413,
- 429,
- 500,
- 502,
- 503,
- 504,
- 521,
- 522,
- 524
- ],
- errorCodes: [
- 'ETIMEDOUT',
- 'ECONNRESET',
- 'EADDRINUSE',
- 'ECONNREFUSED',
- 'EPIPE',
- 'ENOTFOUND',
- 'ENETUNREACH',
- 'EAI_AGAIN'
- ],
- maxRetryAfter: undefined,
- calculateDelay: ({ computedValue }) => computedValue
- },
- timeout: {},
- headers: {
- 'user-agent': 'got (https://github.com/sindresorhus/got)'
- },
- hooks: {
- init: [],
- beforeRequest: [],
- beforeRedirect: [],
- beforeRetry: [],
- beforeError: [],
- afterResponse: []
- },
- cache: undefined,
- dnsCache: undefined,
- decompress: true,
- throwHttpErrors: true,
- followRedirect: true,
- isStream: false,
- responseType: 'text',
- resolveBodyOnly: false,
- maxRedirects: 10,
- prefixUrl: '',
- methodRewriting: true,
- ignoreInvalidCookies: false,
- context: {},
- // TODO: Set this to `true` when Got 12 gets released
- http2: false,
- allowGetBody: false,
- https: undefined,
- pagination: {
- transform: (response) => {
- if (response.request.options.responseType === 'json') {
- return response.body;
- }
- return JSON.parse(response.body);
- },
- paginate: response => {
- if (!Reflect.has(response.headers, 'link')) {
- return false;
- }
- const items = response.headers.link.split(',');
- let next;
- for (const item of items) {
- const parsed = item.split(';');
- if (parsed[1].includes('next')) {
- next = parsed[0].trimStart().trim();
- next = next.slice(1, -1);
- break;
- }
- }
- if (next) {
- const options = {
- url: new url_1.URL(next)
- };
- return options;
- }
- return false;
- },
- filter: () => true,
- shouldContinue: () => true,
- countLimit: Infinity,
- backoff: 0,
- requestLimit: 10000,
- stackAllItems: true
- },
- parseJson: (text) => JSON.parse(text),
- stringifyJson: (object) => JSON.stringify(object),
- cacheOptions: {}
- },
- handlers: [create_1.defaultHandler],
- mutableDefaults: false
-};
-const got = create_1.default(defaults);
-exports["default"] = got;
-// For CommonJS default export support
-module.exports = got;
-module.exports["default"] = got;
-module.exports.__esModule = true; // Workaround for TS issue: https://github.com/sindresorhus/got/pull/1267
-__exportStar(__nccwpck_require__(4337), exports);
-__exportStar(__nccwpck_require__(6056), exports);
-
-
-/***/ }),
-
-/***/ 2613:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-
-
-/***/ }),
-
-/***/ 285:
-/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const is_1 = __nccwpck_require__(7678);
-function deepFreeze(object) {
- for (const value of Object.values(object)) {
- if (is_1.default.plainObject(value) || is_1.default.array(value)) {
- deepFreeze(value);
- }
- }
- return Object.freeze(object);
-}
-exports["default"] = deepFreeze;
-
-
-/***/ }),
-
-/***/ 397:
-/***/ ((__unused_webpack_module, exports) => {
-
-"use strict";
-
-Object.defineProperty(exports, "__esModule", ({ value: true }));
-const alreadyWarned = new Set();
-exports["default"] = (message) => {
- if (alreadyWarned.has(message)) {
- return;
- }
- alreadyWarned.add(message);
- // @ts-expect-error Missing types.
- process.emitWarning(`Got: ${message}`, {
- type: 'DeprecationWarning'
- });
-};
+module.exports = getStream;
+module.exports.buffer = (stream, options) => getStream(stream, {...options, encoding: 'buffer'});
+module.exports.array = (stream, options) => getStream(stream, {...options, array: true});
+module.exports.MaxBufferError = MaxBufferError;
/***/ }),
@@ -19258,6 +14966,7 @@ const statusCodeCacheableByDefault = new Set([
206,
300,
301,
+ 308,
404,
405,
410,
@@ -19330,10 +15039,10 @@ function parseCacheControl(header) {
// TODO: When there is more than one value present for a given directive (e.g., two Expires header fields, multiple Cache-Control: max-age directives),
// the directive's value is considered invalid. Caches are encouraged to consider responses that have invalid freshness information to be stale
- const parts = header.trim().split(/\s*,\s*/); // TODO: lame parsing
+ const parts = header.trim().split(/,/);
for (const part of parts) {
- const [k, v] = part.split(/\s*=\s*/, 2);
- cc[k] = v === undefined ? true : v.replace(/^"|"$/g, ''); // TODO: lame unquoting
+ const [k, v] = part.split(/=/, 2);
+ cc[k.trim()] = v === undefined ? true : v.trim().replace(/^"|"$/g, '');
}
return cc;
@@ -19931,49 +15640,72 @@ module.exports = class CachePolicy {
"use strict";
+// See https://github.com/facebook/jest/issues/2549
+// eslint-disable-next-line node/prefer-global/url
+const {URL} = __nccwpck_require__(7310);
const EventEmitter = __nccwpck_require__(2361);
const tls = __nccwpck_require__(4404);
const http2 = __nccwpck_require__(5158);
const QuickLRU = __nccwpck_require__(9273);
+const delayAsyncDestroy = __nccwpck_require__(9237);
-const kCurrentStreamsCount = Symbol('currentStreamsCount');
+const kCurrentStreamCount = Symbol('currentStreamCount');
const kRequest = Symbol('request');
const kOriginSet = Symbol('cachedOriginSet');
const kGracefullyClosing = Symbol('gracefullyClosing');
+const kLength = Symbol('length');
const nameKeys = [
+ // Not an Agent option actually
+ 'createConnection',
+
// `http2.connect()` options
'maxDeflateDynamicTableSize',
+ 'maxSettings',
'maxSessionMemory',
'maxHeaderListPairs',
'maxOutstandingPings',
'maxReservedRemoteStreams',
'maxSendHeaderBlockLength',
'paddingStrategy',
+ 'peerMaxConcurrentStreams',
+ 'settings',
- // `tls.connect()` options
+ // `tls.connect()` source options
+ 'family',
'localAddress',
- 'path',
'rejectUnauthorized',
+
+ // `tls.connect()` secure context options
+ 'pskCallback',
'minDHSize',
+ // `tls.connect()` destination options
+ // - `servername` is automatically validated, skip it
+ // - `host` and `port` just describe the destination server,
+ 'path',
+ 'socket',
+
// `tls.createSecureContext()` options
'ca',
'cert',
- 'clientCertEngine',
+ 'sigalgs',
'ciphers',
- 'key',
- 'pfx',
- 'servername',
- 'minVersion',
- 'maxVersion',
- 'secureProtocol',
+ 'clientCertEngine',
'crl',
- 'honorCipherOrder',
- 'ecdhCurve',
'dhparam',
+ 'ecdhCurve',
+ 'honorCipherOrder',
+ 'key',
+ 'privateKeyEngine',
+ 'privateKeyIdentifier',
+ 'maxVersion',
+ 'minVersion',
+ 'pfx',
'secureOptions',
- 'sessionIdContext'
+ 'secureProtocol',
+ 'sessionIdContext',
+ 'ticketKeys'
];
const getSortedIndex = (array, value, compare) => {
@@ -19983,9 +15715,7 @@ const getSortedIndex = (array, value, compare) => {
while (low < high) {
const mid = (low + high) >>> 1;
- /* istanbul ignore next */
if (compare(array[mid], value)) {
- // This never gets called because we use descending sort. Better to have this anyway.
low = mid + 1;
} else {
high = mid;
@@ -19995,25 +15725,28 @@ const getSortedIndex = (array, value, compare) => {
return low;
};
-const compareSessions = (a, b) => {
- return a.remoteSettings.maxConcurrentStreams > b.remoteSettings.maxConcurrentStreams;
-};
+const compareSessions = (a, b) => a.remoteSettings.maxConcurrentStreams > b.remoteSettings.maxConcurrentStreams;
// See https://tools.ietf.org/html/rfc8336
const closeCoveredSessions = (where, session) => {
// Clients SHOULD NOT emit new requests on any connection whose Origin
// Set is a proper subset of another connection's Origin Set, and they
// SHOULD close it once all outstanding requests are satisfied.
- for (const coveredSession of where) {
+ for (let index = 0; index < where.length; index++) {
+ const coveredSession = where[index];
+
if (
+ // Unfortunately `.every()` returns true for an empty array
+ coveredSession[kOriginSet].length > 0
+
// The set is a proper subset when its length is less than the other set.
- coveredSession[kOriginSet].length < session[kOriginSet].length &&
+ && coveredSession[kOriginSet].length < session[kOriginSet].length
// And the other set includes all elements of the subset.
- coveredSession[kOriginSet].every(origin => session[kOriginSet].includes(origin)) &&
+ && coveredSession[kOriginSet].every(origin => session[kOriginSet].includes(origin))
// Makes sure that the session can handle all requests from the covered session.
- coveredSession[kCurrentStreamsCount] + session[kCurrentStreamsCount] <= session.remoteSettings.maxConcurrentStreams
+ && (coveredSession[kCurrentStreamCount] + session[kCurrentStreamCount]) <= session.remoteSettings.maxConcurrentStreams
) {
// This allows pending requests to finish and prevents making new requests.
gracefullyClose(coveredSession);
@@ -20023,62 +15756,45 @@ const closeCoveredSessions = (where, session) => {
// This is basically inverted `closeCoveredSessions(...)`.
const closeSessionIfCovered = (where, coveredSession) => {
- for (const session of where) {
+ for (let index = 0; index < where.length; index++) {
+ const session = where[index];
+
if (
- coveredSession[kOriginSet].length < session[kOriginSet].length &&
- coveredSession[kOriginSet].every(origin => session[kOriginSet].includes(origin)) &&
- coveredSession[kCurrentStreamsCount] + session[kCurrentStreamsCount] <= session.remoteSettings.maxConcurrentStreams
+ coveredSession[kOriginSet].length > 0
+ && coveredSession[kOriginSet].length < session[kOriginSet].length
+ && coveredSession[kOriginSet].every(origin => session[kOriginSet].includes(origin))
+ && (coveredSession[kCurrentStreamCount] + session[kCurrentStreamCount]) <= session.remoteSettings.maxConcurrentStreams
) {
gracefullyClose(coveredSession);
- }
- }
-};
-const getSessions = ({agent, isFree}) => {
- const result = {};
-
- // eslint-disable-next-line guard-for-in
- for (const normalizedOptions in agent.sessions) {
- const sessions = agent.sessions[normalizedOptions];
-
- const filtered = sessions.filter(session => {
- const result = session[Agent.kCurrentStreamsCount] < session.remoteSettings.maxConcurrentStreams;
-
- return isFree ? result : !result;
- });
-
- if (filtered.length !== 0) {
- result[normalizedOptions] = filtered;
+ return true;
}
}
- return result;
+ return false;
};
const gracefullyClose = session => {
session[kGracefullyClosing] = true;
- if (session[kCurrentStreamsCount] === 0) {
+ if (session[kCurrentStreamCount] === 0) {
session.close();
}
};
class Agent extends EventEmitter {
- constructor({timeout = 60000, maxSessions = Infinity, maxFreeSessions = 10, maxCachedTlsSessions = 100} = {}) {
+ constructor({timeout = 0, maxSessions = Number.POSITIVE_INFINITY, maxEmptySessions = 10, maxCachedTlsSessions = 100} = {}) {
super();
- // A session is considered busy when its current streams count
- // is equal to or greater than the `maxConcurrentStreams` value.
-
- // A session is considered free when its current streams count
- // is less than the `maxConcurrentStreams` value.
-
// SESSIONS[NORMALIZED_OPTIONS] = [];
this.sessions = {};
// The queue for creating new sessions. It looks like this:
// QUEUE[NORMALIZED_OPTIONS][NORMALIZED_ORIGIN] = ENTRY_FUNCTION
//
+ // It's faster when there are many origins. If there's only one, then QUEUE[`${options}:${origin}`] is faster.
+ // I guess object creation / deletion is causing the slowdown.
+ //
// The entry function has `listeners`, `completed` and `destroyed` properties.
// `listeners` is an array of objects containing `resolve` and `reject` functions.
// `completed` is a boolean. It's set to true after ENTRY_FUNCTION is executed.
@@ -20091,69 +15807,90 @@ class Agent extends EventEmitter {
// Max sessions in total
this.maxSessions = maxSessions;
- // Max free sessions in total
- // TODO: decreasing `maxFreeSessions` should close some sessions
- this.maxFreeSessions = maxFreeSessions;
+ // Max empty sessions in total
+ this.maxEmptySessions = maxEmptySessions;
- this._freeSessionsCount = 0;
- this._sessionsCount = 0;
+ this._emptySessionCount = 0;
+ this._sessionCount = 0;
// We don't support push streams by default.
this.settings = {
- enablePush: false
+ enablePush: false,
+ initialWindowSize: 1024 * 1024 * 32 // 32MB, see https://github.com/nodejs/node/issues/38426
};
// Reusing TLS sessions increases performance.
this.tlsSessionCache = new QuickLRU({maxSize: maxCachedTlsSessions});
}
- static normalizeOrigin(url, servername) {
- if (typeof url === 'string') {
- url = new URL(url);
- }
-
- if (servername && url.hostname !== servername) {
- url.hostname = servername;
- }
-
- return url.origin;
+ get protocol() {
+ return 'https:';
}
normalizeOptions(options) {
let normalized = '';
- if (options) {
- for (const key of nameKeys) {
- if (options[key]) {
- normalized += `:${options[key]}`;
- }
+ for (let index = 0; index < nameKeys.length; index++) {
+ const key = nameKeys[index];
+
+ normalized += ':';
+
+ if (options && options[key] !== undefined) {
+ normalized += options[key];
}
}
return normalized;
}
- _tryToCreateNewSession(normalizedOptions, normalizedOrigin) {
- if (!(normalizedOptions in this.queue) || !(normalizedOrigin in this.queue[normalizedOptions])) {
+ _processQueue() {
+ if (this._sessionCount >= this.maxSessions) {
+ this.closeEmptySessions(this.maxSessions - this._sessionCount + 1);
return;
}
- const item = this.queue[normalizedOptions][normalizedOrigin];
+ // eslint-disable-next-line guard-for-in
+ for (const normalizedOptions in this.queue) {
+ // eslint-disable-next-line guard-for-in
+ for (const normalizedOrigin in this.queue[normalizedOptions]) {
+ const item = this.queue[normalizedOptions][normalizedOrigin];
- // The entry function can be run only once.
- // BUG: The session may be never created when:
- // - the first condition is false AND
- // - this function is never called with the same arguments in the future.
- if (this._sessionsCount < this.maxSessions && !item.completed) {
- item.completed = true;
+ // The entry function can be run only once.
+ if (!item.completed) {
+ item.completed = true;
- item();
+ item();
+ }
+ }
+ }
+ }
+
+ _isBetterSession(thisStreamCount, thatStreamCount) {
+ return thisStreamCount > thatStreamCount;
+ }
+
+ _accept(session, listeners, normalizedOrigin, options) {
+ let index = 0;
+
+ while (index < listeners.length && session[kCurrentStreamCount] < session.remoteSettings.maxConcurrentStreams) {
+ // We assume `resolve(...)` calls `request(...)` *directly*,
+ // otherwise the session will get overloaded.
+ listeners[index].resolve(session);
+
+ index++;
+ }
+
+ listeners.splice(0, index);
+
+ if (listeners.length > 0) {
+ this.getSession(normalizedOrigin, options, listeners);
+ listeners.length = 0;
}
}
getSession(origin, options, listeners) {
return new Promise((resolve, reject) => {
- if (Array.isArray(listeners)) {
+ if (Array.isArray(listeners) && listeners.length > 0) {
listeners = [...listeners];
// Resolve the current promise ASAP, we're just moving the listeners.
@@ -20163,17 +15900,33 @@ class Agent extends EventEmitter {
listeners = [{resolve, reject}];
}
- const normalizedOptions = this.normalizeOptions(options);
- const normalizedOrigin = Agent.normalizeOrigin(origin, options && options.servername);
+ try {
+ // Parse origin
+ if (typeof origin === 'string') {
+ origin = new URL(origin);
+ } else if (!(origin instanceof URL)) {
+ throw new TypeError('The `origin` argument needs to be a string or an URL object');
+ }
- if (normalizedOrigin === undefined) {
- for (const {reject} of listeners) {
- reject(new TypeError('The `origin` argument needs to be a string or an URL object'));
+ if (options) {
+ // Validate servername
+ const {servername} = options;
+ const {hostname} = origin;
+ if (servername && hostname !== servername) {
+ throw new Error(`Origin ${hostname} differs from servername ${servername}`);
+ }
+ }
+ } catch (error) {
+ for (let index = 0; index < listeners.length; index++) {
+ listeners[index].reject(error);
}
return;
}
+ const normalizedOptions = this.normalizeOptions(options);
+ const normalizedOrigin = origin.origin;
+
if (normalizedOptions in this.sessions) {
const sessions = this.sessions[normalizedOptions];
@@ -20183,56 +15936,55 @@ class Agent extends EventEmitter {
// We could just do this.sessions[normalizedOptions].find(...) but that isn't optimal.
// Additionally, we are looking for session which has biggest current pending streams count.
- for (const session of sessions) {
+ //
+ // |------------| |------------| |------------| |------------|
+ // | Session: A | | Session: B | | Session: C | | Session: D |
+ // | Pending: 5 |-| Pending: 8 |-| Pending: 9 |-| Pending: 4 |
+ // | Max: 10 | | Max: 10 | | Max: 9 | | Max: 5 |
+ // |------------| |------------| |------------| |------------|
+ // ^
+ // |
+ // pick this one --
+ //
+ for (let index = 0; index < sessions.length; index++) {
+ const session = sessions[index];
+
const sessionMaxConcurrentStreams = session.remoteSettings.maxConcurrentStreams;
if (sessionMaxConcurrentStreams < maxConcurrentStreams) {
break;
}
- if (session[kOriginSet].includes(normalizedOrigin)) {
- const sessionCurrentStreamsCount = session[kCurrentStreamsCount];
+ if (!session[kOriginSet].includes(normalizedOrigin)) {
+ continue;
+ }
- if (
- sessionCurrentStreamsCount >= sessionMaxConcurrentStreams ||
- session[kGracefullyClosing] ||
- // Unfortunately the `close` event isn't called immediately,
- // so `session.destroyed` is `true`, but `session.closed` is `false`.
- session.destroyed
- ) {
- continue;
- }
+ const sessionCurrentStreamsCount = session[kCurrentStreamCount];
- // We only need set this once.
- if (!optimalSession) {
- maxConcurrentStreams = sessionMaxConcurrentStreams;
- }
+ if (
+ sessionCurrentStreamsCount >= sessionMaxConcurrentStreams
+ || session[kGracefullyClosing]
+ // Unfortunately the `close` event isn't called immediately,
+ // so `session.destroyed` is `true`, but `session.closed` is `false`.
+ || session.destroyed
+ ) {
+ continue;
+ }
- // We're looking for the session which has biggest current pending stream count,
- // in order to minimalize the amount of active sessions.
- if (sessionCurrentStreamsCount > currentStreamsCount) {
- optimalSession = session;
- currentStreamsCount = sessionCurrentStreamsCount;
- }
+ // We only need set this once.
+ if (!optimalSession) {
+ maxConcurrentStreams = sessionMaxConcurrentStreams;
+ }
+
+ // Either get the session which has biggest current stream count or the lowest.
+ if (this._isBetterSession(sessionCurrentStreamsCount, currentStreamsCount)) {
+ optimalSession = session;
+ currentStreamsCount = sessionCurrentStreamsCount;
}
}
if (optimalSession) {
- /* istanbul ignore next: safety check */
- if (listeners.length !== 1) {
- for (const {reject} of listeners) {
- const error = new Error(
- `Expected the length of listeners to be 1, got ${listeners.length}.\n` +
- 'Please report this to https://github.com/szmarczak/http2-wrapper/'
- );
-
- reject(error);
- }
-
- return;
- }
-
- listeners[0].resolve(optimalSession);
+ this._accept(optimalSession, listeners, normalizedOrigin, options);
return;
}
}
@@ -20241,14 +15993,12 @@ class Agent extends EventEmitter {
if (normalizedOrigin in this.queue[normalizedOptions]) {
// There's already an item in the queue, just attach ourselves to it.
this.queue[normalizedOptions][normalizedOrigin].listeners.push(...listeners);
-
- // This shouldn't be executed here.
- // See the comment inside _tryToCreateNewSession.
- this._tryToCreateNewSession(normalizedOptions, normalizedOrigin);
return;
}
} else {
- this.queue[normalizedOptions] = {};
+ this.queue[normalizedOptions] = {
+ [kLength]: 0
+ };
}
// The entry must be removed from the queue IMMEDIATELY when:
@@ -20259,29 +16009,58 @@ class Agent extends EventEmitter {
if (normalizedOptions in this.queue && this.queue[normalizedOptions][normalizedOrigin] === entry) {
delete this.queue[normalizedOptions][normalizedOrigin];
- if (Object.keys(this.queue[normalizedOptions]).length === 0) {
+ if (--this.queue[normalizedOptions][kLength] === 0) {
delete this.queue[normalizedOptions];
}
}
};
// The main logic is here
- const entry = () => {
+ const entry = async () => {
+ this._sessionCount++;
+
const name = `${normalizedOrigin}:${normalizedOptions}`;
let receivedSettings = false;
+ let socket;
try {
- const session = http2.connect(origin, {
- createConnection: this.createConnection,
- settings: this.settings,
- session: this.tlsSessionCache.get(name),
- ...options
- });
- session[kCurrentStreamsCount] = 0;
+ const computedOptions = {...options};
+
+ if (computedOptions.settings === undefined) {
+ computedOptions.settings = this.settings;
+ }
+
+ if (computedOptions.session === undefined) {
+ computedOptions.session = this.tlsSessionCache.get(name);
+ }
+
+ const createConnection = computedOptions.createConnection || this.createConnection;
+
+ // A hacky workaround to enable async `createConnection`
+ socket = await createConnection.call(this, origin, computedOptions);
+ computedOptions.createConnection = () => socket;
+
+ const session = http2.connect(origin, computedOptions);
+ session[kCurrentStreamCount] = 0;
session[kGracefullyClosing] = false;
- const isFree = () => session[kCurrentStreamsCount] < session.remoteSettings.maxConcurrentStreams;
- let wasFree = true;
+ // Node.js return https://false:443 instead of https://1.1.1.1:443
+ const getOriginSet = () => {
+ const {socket} = session;
+
+ let originSet;
+ if (socket.servername === false) {
+ socket.servername = socket.remoteAddress;
+ originSet = session.originSet;
+ socket.servername = false;
+ } else {
+ originSet = session.originSet;
+ }
+
+ return originSet;
+ };
+
+ const isFree = () => session[kCurrentStreamCount] < session.remoteSettings.maxConcurrentStreams;
session.socket.once('session', tlsSession => {
this.tlsSessionCache.set(name, tlsSession);
@@ -20289,8 +16068,8 @@ class Agent extends EventEmitter {
session.once('error', error => {
// Listeners are empty when the session successfully connected.
- for (const {reject} of listeners) {
- reject(error);
+ for (let index = 0; index < listeners.length; index++) {
+ listeners[index].reject(error);
}
// The connection got broken, purge the cache.
@@ -20299,68 +16078,73 @@ class Agent extends EventEmitter {
session.setTimeout(this.timeout, () => {
// Terminates all streams owned by this session.
- // TODO: Maybe the streams should have a "Session timed out" error?
session.destroy();
});
session.once('close', () => {
- if (receivedSettings) {
- // 1. If it wasn't free then no need to decrease because
- // it has been decreased already in session.request().
- // 2. `stream.once('close')` won't increment the count
- // because the session is already closed.
- if (wasFree) {
- this._freeSessionsCount--;
- }
+ this._sessionCount--;
- this._sessionsCount--;
+ if (receivedSettings) {
+ // Assumes session `close` is emitted after request `close`
+ this._emptySessionCount--;
// This cannot be moved to the stream logic,
// because there may be a session that hadn't made a single request.
const where = this.sessions[normalizedOptions];
- where.splice(where.indexOf(session), 1);
- if (where.length === 0) {
+ if (where.length === 1) {
delete this.sessions[normalizedOptions];
+ } else {
+ where.splice(where.indexOf(session), 1);
}
} else {
// Broken connection
+ removeFromQueue();
+
const error = new Error('Session closed without receiving a SETTINGS frame');
error.code = 'HTTP2WRAPPER_NOSETTINGS';
- for (const {reject} of listeners) {
- reject(error);
+ for (let index = 0; index < listeners.length; index++) {
+ listeners[index].reject(error);
}
-
- removeFromQueue();
}
// There may be another session awaiting.
- this._tryToCreateNewSession(normalizedOptions, normalizedOrigin);
+ this._processQueue();
});
// Iterates over the queue and processes listeners.
const processListeners = () => {
- if (!(normalizedOptions in this.queue) || !isFree()) {
+ const queue = this.queue[normalizedOptions];
+ if (!queue) {
return;
}
- for (const origin of session[kOriginSet]) {
- if (origin in this.queue[normalizedOptions]) {
- const {listeners} = this.queue[normalizedOptions][origin];
+ const originSet = session[kOriginSet];
+
+ for (let index = 0; index < originSet.length; index++) {
+ const origin = originSet[index];
+
+ if (origin in queue) {
+ const {listeners, completed} = queue[origin];
+
+ let index = 0;
// Prevents session overloading.
- while (listeners.length !== 0 && isFree()) {
+ while (index < listeners.length && isFree()) {
// We assume `resolve(...)` calls `request(...)` *directly*,
// otherwise the session will get overloaded.
- listeners.shift().resolve(session);
+ listeners[index].resolve(session);
+
+ index++;
}
- const where = this.queue[normalizedOptions];
- if (where[origin].listeners.length === 0) {
- delete where[origin];
+ queue[origin].listeners.splice(0, index);
- if (Object.keys(where).length === 0) {
+ if (queue[origin].listeners.length === 0 && !completed) {
+ delete queue[origin];
+
+ if (--queue[kLength] === 0) {
delete this.queue[normalizedOptions];
break;
}
@@ -20376,39 +16160,59 @@ class Agent extends EventEmitter {
// The Origin Set cannot shrink. No need to check if it suddenly became covered by another one.
session.on('origin', () => {
- session[kOriginSet] = session.originSet;
+ session[kOriginSet] = getOriginSet() || [];
+ session[kGracefullyClosing] = false;
+ closeSessionIfCovered(this.sessions[normalizedOptions], session);
- if (!isFree()) {
- // The session is full.
+ if (session[kGracefullyClosing] || !isFree()) {
return;
}
processListeners();
+ if (!isFree()) {
+ return;
+ }
+
// Close covered sessions (if possible).
closeCoveredSessions(this.sessions[normalizedOptions], session);
});
session.once('remoteSettings', () => {
- // Fix Node.js bug preventing the process from exiting
- session.ref();
- session.unref();
-
- this._sessionsCount++;
-
// The Agent could have been destroyed already.
if (entry.destroyed) {
const error = new Error('Agent has been destroyed');
- for (const listener of listeners) {
- listener.reject(error);
+ for (let index = 0; index < listeners.length; index++) {
+ listeners[index].reject(error);
}
session.destroy();
return;
}
- session[kOriginSet] = session.originSet;
+ // See https://github.com/nodejs/node/issues/38426
+ if (session.setLocalWindowSize) {
+ session.setLocalWindowSize(1024 * 1024 * 4); // 4 MB
+ }
+
+ session[kOriginSet] = getOriginSet() || [];
+
+ if (session.socket.encrypted) {
+ const mainOrigin = session[kOriginSet][0];
+ if (mainOrigin !== normalizedOrigin) {
+ const error = new Error(`Requested origin ${normalizedOrigin} does not match server ${mainOrigin}`);
+
+ for (let index = 0; index < listeners.length; index++) {
+ listeners[index].reject(error);
+ }
+
+ session.destroy();
+ return;
+ }
+ }
+
+ removeFromQueue();
{
const where = this.sessions;
@@ -20421,30 +16225,28 @@ class Agent extends EventEmitter {
}
}
- this._freeSessionsCount += 1;
receivedSettings = true;
+ this._emptySessionCount++;
this.emit('session', session);
+ this._accept(session, listeners, normalizedOrigin, options);
- processListeners();
- removeFromQueue();
-
- // TODO: Close last recently used (or least used?) session
- if (session[kCurrentStreamsCount] === 0 && this._freeSessionsCount > this.maxFreeSessions) {
- session.close();
- }
-
- // Check if we haven't managed to execute all listeners.
- if (listeners.length !== 0) {
- // Request for a new session with predefined listeners.
- this.getSession(normalizedOrigin, options, listeners);
- listeners.length = 0;
+ if (session[kCurrentStreamCount] === 0 && this._emptySessionCount > this.maxEmptySessions) {
+ this.closeEmptySessions(this._emptySessionCount - this.maxEmptySessions);
}
// `session.remoteSettings.maxConcurrentStreams` might get increased
session.on('remoteSettings', () => {
+ if (!isFree()) {
+ return;
+ }
+
processListeners();
+ if (!isFree()) {
+ return;
+ }
+
// In case the Origin Set changes
closeCoveredSessions(this.sessions[normalizedOptions], session);
});
@@ -20462,45 +16264,31 @@ class Agent extends EventEmitter {
// The process won't exit until the session is closed or all requests are gone.
session.ref();
- ++session[kCurrentStreamsCount];
-
- if (session[kCurrentStreamsCount] === session.remoteSettings.maxConcurrentStreams) {
- this._freeSessionsCount--;
+ if (session[kCurrentStreamCount]++ === 0) {
+ this._emptySessionCount--;
}
stream.once('close', () => {
- wasFree = isFree();
+ if (--session[kCurrentStreamCount] === 0) {
+ this._emptySessionCount++;
+ session.unref();
- --session[kCurrentStreamsCount];
+ if (this._emptySessionCount > this.maxEmptySessions || session[kGracefullyClosing]) {
+ session.close();
+ return;
+ }
+ }
- if (!session.destroyed && !session.closed) {
- closeSessionIfCovered(this.sessions[normalizedOptions], session);
+ if (session.destroyed || session.closed) {
+ return;
+ }
- if (isFree() && !session.closed) {
- if (!wasFree) {
- this._freeSessionsCount++;
+ if (isFree() && !closeSessionIfCovered(this.sessions[normalizedOptions], session)) {
+ closeCoveredSessions(this.sessions[normalizedOptions], session);
+ processListeners();
- wasFree = true;
- }
-
- const isEmpty = session[kCurrentStreamsCount] === 0;
-
- if (isEmpty) {
- session.unref();
- }
-
- if (
- isEmpty &&
- (
- this._freeSessionsCount > this.maxFreeSessions ||
- session[kGracefullyClosing]
- )
- ) {
- session.close();
- } else {
- closeCoveredSessions(this.sessions[normalizedOptions], session);
- processListeners();
- }
+ if (session[kCurrentStreamCount] === 0) {
+ this._processQueue();
}
}
});
@@ -20508,11 +16296,12 @@ class Agent extends EventEmitter {
return stream;
};
} catch (error) {
- for (const listener of listeners) {
- listener.reject(error);
- }
-
removeFromQueue();
+ this._sessionCount--;
+
+ for (let index = 0; index < listeners.length; index++) {
+ listeners[index].reject(error);
+ }
}
};
@@ -20521,7 +16310,8 @@ class Agent extends EventEmitter {
entry.destroyed = false;
this.queue[normalizedOptions][normalizedOrigin] = entry;
- this._tryToCreateNewSession(normalizedOptions, normalizedOrigin);
+ this.queue[normalizedOptions][kLength]++;
+ this._processQueue();
});
}
@@ -20531,7 +16321,12 @@ class Agent extends EventEmitter {
reject,
resolve: session => {
try {
- resolve(session.request(headers, streamOptions));
+ const stream = session.request(headers, streamOptions);
+
+ // Do not throw before `request(...)` has been awaited
+ delayAsyncDestroy(stream);
+
+ resolve(stream);
} catch (error) {
reject(error);
}
@@ -20540,7 +16335,7 @@ class Agent extends EventEmitter {
});
}
- createConnection(origin, options) {
+ async createConnection(origin, options) {
return Agent.connect(origin, options);
}
@@ -20548,52 +16343,92 @@ class Agent extends EventEmitter {
options.ALPNProtocols = ['h2'];
const port = origin.port || 443;
- const host = origin.hostname || origin.host;
+ const host = origin.hostname;
if (typeof options.servername === 'undefined') {
options.servername = host;
}
- return tls.connect(port, host, options);
+ const socket = tls.connect(port, host, options);
+
+ if (options.socket) {
+ socket._peername = {
+ family: undefined,
+ address: undefined,
+ port
+ };
+ }
+
+ return socket;
}
- closeFreeSessions() {
- for (const sessions of Object.values(this.sessions)) {
- for (const session of sessions) {
- if (session[kCurrentStreamsCount] === 0) {
+ closeEmptySessions(maxCount = Number.POSITIVE_INFINITY) {
+ let closedCount = 0;
+
+ const {sessions} = this;
+
+ // eslint-disable-next-line guard-for-in
+ for (const key in sessions) {
+ const thisSessions = sessions[key];
+
+ for (let index = 0; index < thisSessions.length; index++) {
+ const session = thisSessions[index];
+
+ if (session[kCurrentStreamCount] === 0) {
+ closedCount++;
session.close();
+
+ if (closedCount >= maxCount) {
+ return closedCount;
+ }
}
}
}
+
+ return closedCount;
}
destroy(reason) {
- for (const sessions of Object.values(this.sessions)) {
- for (const session of sessions) {
- session.destroy(reason);
+ const {sessions, queue} = this;
+
+ // eslint-disable-next-line guard-for-in
+ for (const key in sessions) {
+ const thisSessions = sessions[key];
+
+ for (let index = 0; index < thisSessions.length; index++) {
+ thisSessions[index].destroy(reason);
}
}
- for (const entriesOfAuthority of Object.values(this.queue)) {
- for (const entry of Object.values(entriesOfAuthority)) {
- entry.destroyed = true;
+ // eslint-disable-next-line guard-for-in
+ for (const normalizedOptions in queue) {
+ const entries = queue[normalizedOptions];
+
+ // eslint-disable-next-line guard-for-in
+ for (const normalizedOrigin in entries) {
+ entries[normalizedOrigin].destroyed = true;
}
}
// New requests should NOT attach to destroyed sessions
this.queue = {};
+ this.tlsSessionCache.clear();
}
- get freeSessions() {
- return getSessions({agent: this, isFree: true});
+ get emptySessionCount() {
+ return this._emptySessionCount;
}
- get busySessions() {
- return getSessions({agent: this, isFree: false});
+ get pendingSessionCount() {
+ return this._sessionCount - this._emptySessionCount;
+ }
+
+ get sessionCount() {
+ return this._sessionCount;
}
}
-Agent.kCurrentStreamsCount = kCurrentStreamsCount;
+Agent.kCurrentStreamCount = kCurrentStreamCount;
Agent.kGracefullyClosing = kGracefullyClosing;
module.exports = {
@@ -20609,13 +16444,17 @@ module.exports = {
"use strict";
+// See https://github.com/facebook/jest/issues/2549
+// eslint-disable-next-line node/prefer-global/url
+const {URL, urlToHttpOptions} = __nccwpck_require__(7310);
const http = __nccwpck_require__(3685);
const https = __nccwpck_require__(5687);
const resolveALPN = __nccwpck_require__(6624);
const QuickLRU = __nccwpck_require__(9273);
+const {Agent, globalAgent} = __nccwpck_require__(9898);
const Http2ClientRequest = __nccwpck_require__(9632);
const calculateServerName = __nccwpck_require__(1982);
-const urlToOptions = __nccwpck_require__(2686);
+const delayAsyncDestroy = __nccwpck_require__(9237);
const cache = new QuickLRU({maxSize: 100});
const queue = new Map();
@@ -20635,10 +16474,24 @@ const installSocket = (agent, socket, options) => {
socket.on('close', onClose);
+ const onTimeout = () => {
+ const {freeSockets} = agent;
+
+ for (const sockets of Object.values(freeSockets)) {
+ if (sockets.includes(socket)) {
+ socket.destroy();
+ return;
+ }
+ }
+ };
+
+ socket.on('timeout', onTimeout);
+
const onRemove = () => {
agent.removeSocket(socket, options);
socket.off('close', onClose);
socket.off('free', onFree);
+ socket.off('timeout', onTimeout);
socket.off('agentRemove', onRemove);
};
@@ -20647,76 +16500,65 @@ const installSocket = (agent, socket, options) => {
agent.emit('free', socket, options);
};
-const resolveProtocol = async options => {
- const name = `${options.host}:${options.port}:${options.ALPNProtocols.sort()}`;
+const createResolveProtocol = (cache, queue = new Map(), connect = undefined) => {
+ return async options => {
+ const name = `${options.host}:${options.port}:${options.ALPNProtocols.sort()}`;
- if (!cache.has(name)) {
- if (queue.has(name)) {
- const result = await queue.get(name);
- return result.alpnProtocol;
- }
-
- const {path, agent} = options;
- options.path = options.socketPath;
-
- const resultPromise = resolveALPN(options);
- queue.set(name, resultPromise);
-
- try {
- const {socket, alpnProtocol} = await resultPromise;
- cache.set(name, alpnProtocol);
-
- options.path = path;
-
- if (alpnProtocol === 'h2') {
- // https://github.com/nodejs/node/issues/33343
- socket.destroy();
- } else {
- const {globalAgent} = https;
- const defaultCreateConnection = https.Agent.prototype.createConnection;
-
- if (agent) {
- if (agent.createConnection === defaultCreateConnection) {
- installSocket(agent, socket, options);
- } else {
- socket.destroy();
- }
- } else if (globalAgent.createConnection === defaultCreateConnection) {
- installSocket(globalAgent, socket, options);
- } else {
- socket.destroy();
- }
+ if (!cache.has(name)) {
+ if (queue.has(name)) {
+ const result = await queue.get(name);
+ return {alpnProtocol: result.alpnProtocol};
}
- queue.delete(name);
+ const {path} = options;
+ options.path = options.socketPath;
- return alpnProtocol;
- } catch (error) {
- queue.delete(name);
+ const resultPromise = resolveALPN(options, connect);
+ queue.set(name, resultPromise);
- throw error;
+ try {
+ const result = await resultPromise;
+
+ cache.set(name, result.alpnProtocol);
+ queue.delete(name);
+
+ options.path = path;
+
+ return result;
+ } catch (error) {
+ queue.delete(name);
+
+ options.path = path;
+
+ throw error;
+ }
}
- }
- return cache.get(name);
+ return {alpnProtocol: cache.get(name)};
+ };
};
+const defaultResolveProtocol = createResolveProtocol(cache, queue);
+
module.exports = async (input, options, callback) => {
- if (typeof input === 'string' || input instanceof URL) {
- input = urlToOptions(new URL(input));
+ if (typeof input === 'string') {
+ input = urlToHttpOptions(new URL(input));
+ } else if (input instanceof URL) {
+ input = urlToHttpOptions(input);
+ } else {
+ input = {...input};
}
- if (typeof options === 'function') {
+ if (typeof options === 'function' || options === undefined) {
+ // (options, callback)
callback = options;
- options = undefined;
+ options = input;
+ } else {
+ // (input, options, callback)
+ options = Object.assign(input, options);
}
- options = {
- ALPNProtocols: ['h2', 'http/1.1'],
- ...input,
- ...options,
- resolveSocket: true
- };
+ options.ALPNProtocols = options.ALPNProtocols || ['h2', 'http/1.1'];
if (!Array.isArray(options.ALPNProtocols) || options.ALPNProtocols.length === 0) {
throw new Error('The `ALPNProtocols` option must be an Array with at least one entry');
@@ -20727,36 +16569,86 @@ module.exports = async (input, options, callback) => {
options.host = options.hostname || options.host || 'localhost';
options.session = options.tlsSession;
- options.servername = options.servername || calculateServerName(options);
+ options.servername = options.servername || calculateServerName((options.headers && options.headers.host) || options.host);
options.port = options.port || (isHttps ? 443 : 80);
options._defaultAgent = isHttps ? https.globalAgent : http.globalAgent;
- const agents = options.agent;
+ const resolveProtocol = options.resolveProtocol || defaultResolveProtocol;
- if (agents) {
- if (agents.addRequest) {
- throw new Error('The `options.agent` object can contain only `http`, `https` or `http2` properties');
- }
+ // Note: We don't support `h2session` here
- options.agent = agents[isHttps ? 'https' : 'http'];
+ let {agent} = options;
+ if (agent !== undefined && agent !== false && agent.constructor.name !== 'Object') {
+ throw new Error('The `options.agent` can be only an object `http`, `https` or `http2` properties');
}
if (isHttps) {
- const protocol = await resolveProtocol(options);
+ options.resolveSocket = true;
- if (protocol === 'h2') {
- if (agents) {
- options.agent = agents.http2;
+ let {socket, alpnProtocol, timeout} = await resolveProtocol(options);
+
+ if (timeout) {
+ if (socket) {
+ socket.destroy();
}
- return new Http2ClientRequest(options, callback);
+ const error = new Error(`Timed out resolving ALPN: ${options.timeout} ms`);
+ error.code = 'ETIMEDOUT';
+ error.ms = options.timeout;
+
+ throw error;
}
+
+ // We can't accept custom `createConnection` because the API is different for HTTP/2
+ if (socket && options.createConnection) {
+ socket.destroy();
+ socket = undefined;
+ }
+
+ delete options.resolveSocket;
+
+ const isHttp2 = alpnProtocol === 'h2';
+
+ if (agent) {
+ agent = isHttp2 ? agent.http2 : agent.https;
+ options.agent = agent;
+ }
+
+ if (agent === undefined) {
+ agent = isHttp2 ? globalAgent : https.globalAgent;
+ }
+
+ if (socket) {
+ if (agent === false) {
+ socket.destroy();
+ } else {
+ const defaultCreateConnection = (isHttp2 ? Agent : https.Agent).prototype.createConnection;
+
+ if (agent.createConnection === defaultCreateConnection) {
+ if (isHttp2) {
+ options._reuseSocket = socket;
+ } else {
+ installSocket(agent, socket, options);
+ }
+ } else {
+ socket.destroy();
+ }
+ }
+ }
+
+ if (isHttp2) {
+ return delayAsyncDestroy(new Http2ClientRequest(options, callback));
+ }
+ } else if (agent) {
+ options.agent = agent.http;
}
- return http.request(options, callback);
+ return delayAsyncDestroy(http.request(options, callback));
};
module.exports.protocolCache = cache;
+module.exports.resolveProtocol = defaultResolveProtocol;
+module.exports.createResolveProtocol = createResolveProtocol;
/***/ }),
@@ -20766,26 +16658,28 @@ module.exports.protocolCache = cache;
"use strict";
+// See https://github.com/facebook/jest/issues/2549
+// eslint-disable-next-line node/prefer-global/url
+const {URL, urlToHttpOptions} = __nccwpck_require__(7310);
const http2 = __nccwpck_require__(5158);
const {Writable} = __nccwpck_require__(2781);
const {Agent, globalAgent} = __nccwpck_require__(9898);
const IncomingMessage = __nccwpck_require__(2575);
-const urlToOptions = __nccwpck_require__(2686);
const proxyEvents = __nccwpck_require__(1818);
-const isRequestPseudoHeader = __nccwpck_require__(1199);
const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_PROTOCOL,
- ERR_HTTP_HEADERS_SENT,
- ERR_INVALID_HTTP_TOKEN,
- ERR_HTTP_INVALID_HEADER_VALUE,
- ERR_INVALID_CHAR
+ ERR_HTTP_HEADERS_SENT
} = __nccwpck_require__(7087);
+const validateHeaderName = __nccwpck_require__(4592);
+const validateHeaderValue = __nccwpck_require__(3549);
+const proxySocketHandler = __nccwpck_require__(9404);
const {
HTTP2_HEADER_STATUS,
HTTP2_HEADER_METHOD,
HTTP2_HEADER_PATH,
+ HTTP2_HEADER_AUTHORITY,
HTTP2_METHOD_CONNECT
} = http2.constants;
@@ -20795,59 +16689,66 @@ const kSession = Symbol('session');
const kOptions = Symbol('options');
const kFlushedHeaders = Symbol('flushedHeaders');
const kJobs = Symbol('jobs');
-
-const isValidHttpToken = /^[\^`\-\w!#$%&*+.|~]+$/;
-const isInvalidHeaderValue = /[^\t\u0020-\u007E\u0080-\u00FF]/;
+const kPendingAgentPromise = Symbol('pendingAgentPromise');
class ClientRequest extends Writable {
constructor(input, options, callback) {
super({
- autoDestroy: false
+ autoDestroy: false,
+ emitClose: false
});
- const hasInput = typeof input === 'string' || input instanceof URL;
- if (hasInput) {
- input = urlToOptions(input instanceof URL ? input : new URL(input));
+ if (typeof input === 'string') {
+ input = urlToHttpOptions(new URL(input));
+ } else if (input instanceof URL) {
+ input = urlToHttpOptions(input);
+ } else {
+ input = {...input};
}
if (typeof options === 'function' || options === undefined) {
// (options, callback)
callback = options;
- options = hasInput ? input : {...input};
+ options = input;
} else {
// (input, options, callback)
- options = {...input, ...options};
+ options = Object.assign(input, options);
}
if (options.h2session) {
this[kSession] = options.h2session;
- } else if (options.agent === false) {
- this.agent = new Agent({maxFreeSessions: 0});
- } else if (typeof options.agent === 'undefined' || options.agent === null) {
- if (typeof options.createConnection === 'function') {
- // This is a workaround - we don't have to create the session on our own.
- this.agent = new Agent({maxFreeSessions: 0});
- this.agent.createConnection = options.createConnection;
- } else {
- this.agent = globalAgent;
+
+ if (this[kSession].destroyed) {
+ throw new Error('The session has been closed already');
}
+
+ this.protocol = this[kSession].socket.encrypted ? 'https:' : 'http:';
+ } else if (options.agent === false) {
+ this.agent = new Agent({maxEmptySessions: 0});
+ } else if (typeof options.agent === 'undefined' || options.agent === null) {
+ this.agent = globalAgent;
} else if (typeof options.agent.request === 'function') {
this.agent = options.agent;
} else {
- throw new ERR_INVALID_ARG_TYPE('options.agent', ['Agent-like Object', 'undefined', 'false'], options.agent);
+ throw new ERR_INVALID_ARG_TYPE('options.agent', ['http2wrapper.Agent-like Object', 'undefined', 'false'], options.agent);
}
- if (options.protocol && options.protocol !== 'https:') {
- throw new ERR_INVALID_PROTOCOL(options.protocol, 'https:');
+ if (this.agent) {
+ this.protocol = this.agent.protocol;
}
- const port = options.port || options.defaultPort || (this.agent && this.agent.defaultPort) || 443;
- const host = options.hostname || options.host || 'localhost';
+ if (options.protocol && options.protocol !== this.protocol) {
+ throw new ERR_INVALID_PROTOCOL(options.protocol, this.protocol);
+ }
- // Don't enforce the origin via options. It may be changed in an Agent.
+ if (!options.port) {
+ options.port = options.defaultPort || (this.agent && this.agent.defaultPort) || 443;
+ }
+
+ options.host = options.hostname || options.host || 'localhost';
+
+ // Unused
delete options.hostname;
- delete options.host;
- delete options.port;
const {timeout} = options;
options.timeout = undefined;
@@ -20855,19 +16756,26 @@ class ClientRequest extends Writable {
this[kHeaders] = Object.create(null);
this[kJobs] = [];
+ this[kPendingAgentPromise] = undefined;
+
this.socket = null;
this.connection = null;
this.method = options.method || 'GET';
- this.path = options.path;
+
+ if (!(this.method === 'CONNECT' && (options.path === '/' || options.path === undefined))) {
+ this.path = options.path;
+ }
this.res = null;
this.aborted = false;
this.reusedSocket = false;
- if (options.headers) {
- for (const [header, value] of Object.entries(options.headers)) {
- this.setHeader(header, value);
+ const {headers} = options;
+ if (headers) {
+ // eslint-disable-next-line guard-for-in
+ for (const header in headers) {
+ this.setHeader(header, headers[header]);
}
}
@@ -20881,18 +16789,21 @@ class ClientRequest extends Writable {
this[kOptions] = options;
// Clients that generate HTTP/2 requests directly SHOULD use the :authority pseudo-header field instead of the Host header field.
- if (port === 443) {
- this[kOrigin] = `https://${host}`;
+ this[kOrigin] = new URL(`${this.protocol}//${options.servername || options.host}:${options.port}`);
- if (!(':authority' in this[kHeaders])) {
- this[kHeaders][':authority'] = host;
- }
- } else {
- this[kOrigin] = `https://${host}:${port}`;
+ // A socket is being reused
+ const reuseSocket = options._reuseSocket;
+ if (reuseSocket) {
+ options.createConnection = (...args) => {
+ if (reuseSocket.destroyed) {
+ return this.agent.createConnection(...args);
+ }
- if (!(':authority' in this[kHeaders])) {
- this[kHeaders][':authority'] = `${host}:${port}`;
- }
+ return reuseSocket;
+ };
+
+ // eslint-disable-next-line promise/prefer-await-to-then
+ this.agent.getSession(this[kOrigin], this[kOptions]).catch(() => {});
}
if (timeout) {
@@ -20917,15 +16828,27 @@ class ClientRequest extends Writable {
}
get path() {
- return this[kHeaders][HTTP2_HEADER_PATH];
+ const header = this.method === 'CONNECT' ? HTTP2_HEADER_AUTHORITY : HTTP2_HEADER_PATH;
+
+ return this[kHeaders][header];
}
set path(value) {
if (value) {
- this[kHeaders][HTTP2_HEADER_PATH] = value;
+ const header = this.method === 'CONNECT' ? HTTP2_HEADER_AUTHORITY : HTTP2_HEADER_PATH;
+
+ this[kHeaders][header] = value;
}
}
+ get host() {
+ return this[kOrigin].hostname;
+ }
+
+ set host(_value) {
+ // Do nothing as this is read only.
+ }
+
get _mustNotHaveABody() {
return this.method === 'GET' || this.method === 'HEAD' || this.method === 'DELETE';
}
@@ -20949,15 +16872,11 @@ class ClientRequest extends Writable {
}
_final(callback) {
- if (this.destroyed) {
- return;
- }
-
this.flushHeaders();
const callEnd = () => {
- // For GET, HEAD and DELETE
- if (this._mustNotHaveABody) {
+ // For GET, HEAD and DELETE and CONNECT
+ if (this._mustNotHaveABody || this.method === 'CONNECT') {
callback();
return;
}
@@ -20986,13 +16905,25 @@ class ClientRequest extends Writable {
this.destroy();
}
- _destroy(error, callback) {
+ async _destroy(error, callback) {
if (this.res) {
this.res._dump();
}
if (this._request) {
this._request.destroy();
+ } else {
+ process.nextTick(() => {
+ this.emit('close');
+ });
+ }
+
+ try {
+ await this[kPendingAgentPromise];
+ } catch (internalError) {
+ if (this.aborted) {
+ error = internalError;
+ }
}
callback(error);
@@ -21018,46 +16949,45 @@ class ClientRequest extends Writable {
// Forwards `timeout`, `continue`, `close` and `error` events to this instance.
if (!isConnectMethod) {
- proxyEvents(stream, this, ['timeout', 'continue', 'close', 'error']);
+ // TODO: Should we proxy `close` here?
+ proxyEvents(stream, this, ['timeout', 'continue']);
}
- // Wait for the `finish` event. We don't want to emit the `response` event
- // before `request.end()` is called.
- const waitForEnd = fn => {
- return (...args) => {
- if (!this.writable && !this.destroyed) {
- fn(...args);
- } else {
- this.once('finish', () => {
- fn(...args);
- });
- }
- };
- };
+ stream.once('error', error => {
+ this.destroy(error);
+ });
- // This event tells we are ready to listen for the data.
- stream.once('response', waitForEnd((headers, flags, rawHeaders) => {
+ stream.once('aborted', () => {
+ const {res} = this;
+ if (res) {
+ res.aborted = true;
+ res.emit('aborted');
+ res.destroy();
+ } else {
+ this.destroy(new Error('The server aborted the HTTP/2 stream'));
+ }
+ });
+
+ const onResponse = (headers, flags, rawHeaders) => {
// If we were to emit raw request stream, it would be as fast as the native approach.
// Note that wrapping the raw stream in a Proxy instance won't improve the performance (already tested it).
const response = new IncomingMessage(this.socket, stream.readableHighWaterMark);
this.res = response;
+ // Undocumented, but it is used by `cacheable-request`
+ response.url = `${this[kOrigin].origin}${this.path}`;
+
response.req = this;
response.statusCode = headers[HTTP2_HEADER_STATUS];
response.headers = headers;
response.rawHeaders = rawHeaders;
response.once('end', () => {
- if (this.aborted) {
- response.aborted = true;
- response.emit('aborted');
- } else {
- response.complete = true;
+ response.complete = true;
- // Has no effect, just be consistent with the Node.js behavior
- response.socket = null;
- response.connection = null;
- }
+ // Has no effect, just be consistent with the Node.js behavior
+ response.socket = null;
+ response.connection = null;
});
if (isConnectMethod) {
@@ -21080,7 +17010,9 @@ class ClientRequest extends Writable {
});
stream.once('end', () => {
- response.push(null);
+ if (!this.aborted) {
+ response.push(null);
+ }
});
if (!this.emit('response', response)) {
@@ -21088,50 +17020,123 @@ class ClientRequest extends Writable {
response._dump();
}
}
- }));
+ };
+
+ // This event tells we are ready to listen for the data.
+ stream.once('response', onResponse);
// Emits `information` event
- stream.once('headers', waitForEnd(
- headers => this.emit('information', {statusCode: headers[HTTP2_HEADER_STATUS]})
- ));
+ stream.once('headers', headers => this.emit('information', {statusCode: headers[HTTP2_HEADER_STATUS]}));
- stream.once('trailers', waitForEnd((trailers, flags, rawTrailers) => {
+ stream.once('trailers', (trailers, flags, rawTrailers) => {
const {res} = this;
+ // https://github.com/nodejs/node/issues/41251
+ if (res === null) {
+ onResponse(trailers, flags, rawTrailers);
+ return;
+ }
+
// Assigns trailers to the response object.
res.trailers = trailers;
res.rawTrailers = rawTrailers;
- }));
+ });
- const {socket} = stream.session;
- this.socket = socket;
- this.connection = socket;
+ stream.once('close', () => {
+ const {aborted, res} = this;
+ if (res) {
+ if (aborted) {
+ res.aborted = true;
+ res.emit('aborted');
+ res.destroy();
+ }
+
+ const finish = () => {
+ res.emit('close');
+
+ this.destroy();
+ this.emit('close');
+ };
+
+ if (res.readable) {
+ res.once('end', finish);
+ } else {
+ finish();
+ }
+
+ return;
+ }
+
+ if (!this.destroyed) {
+ this.destroy(new Error('The HTTP/2 stream has been early terminated'));
+ this.emit('close');
+ return;
+ }
+
+ this.destroy();
+ this.emit('close');
+ });
+
+ this.socket = new Proxy(stream, proxySocketHandler);
for (const job of this[kJobs]) {
job();
}
+ this[kJobs].length = 0;
+
this.emit('socket', this.socket);
};
+ if (!(HTTP2_HEADER_AUTHORITY in this[kHeaders]) && !isConnectMethod) {
+ this[kHeaders][HTTP2_HEADER_AUTHORITY] = this[kOrigin].host;
+ }
+
// Makes a HTTP2 request
if (this[kSession]) {
try {
onStream(this[kSession].request(this[kHeaders]));
} catch (error) {
- this.emit('error', error);
+ this.destroy(error);
}
} else {
this.reusedSocket = true;
try {
- onStream(await this.agent.request(this[kOrigin], this[kOptions], this[kHeaders]));
+ const promise = this.agent.request(this[kOrigin], this[kOptions], this[kHeaders]);
+ this[kPendingAgentPromise] = promise;
+
+ onStream(await promise);
+
+ this[kPendingAgentPromise] = false;
} catch (error) {
- this.emit('error', error);
+ this[kPendingAgentPromise] = false;
+
+ this.destroy(error);
}
}
}
+ get connection() {
+ return this.socket;
+ }
+
+ set connection(value) {
+ this.socket = value;
+ }
+
+ getHeaderNames() {
+ return Object.keys(this[kHeaders]);
+ }
+
+ hasHeader(name) {
+ if (typeof name !== 'string') {
+ throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
+ }
+
+ return Boolean(this[kHeaders][name.toLowerCase()]);
+ }
+
getHeader(name) {
if (typeof name !== 'string') {
throw new ERR_INVALID_ARG_TYPE('name', 'string', name);
@@ -21161,19 +17166,24 @@ class ClientRequest extends Writable {
throw new ERR_HTTP_HEADERS_SENT('set');
}
- if (typeof name !== 'string' || (!isValidHttpToken.test(name) && !isRequestPseudoHeader(name))) {
- throw new ERR_INVALID_HTTP_TOKEN('Header name', name);
+ validateHeaderName(name);
+ validateHeaderValue(name, value);
+
+ const lowercased = name.toLowerCase();
+
+ if (lowercased === 'connection') {
+ if (value.toLowerCase() === 'keep-alive') {
+ return;
+ }
+
+ throw new Error(`Invalid 'connection' header: ${value}`);
}
- if (typeof value === 'undefined') {
- throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
+ if (lowercased === 'host' && this.method === 'CONNECT') {
+ this[kHeaders][HTTP2_HEADER_AUTHORITY] = value;
+ } else {
+ this[kHeaders][lowercased] = value;
}
-
- if (isInvalidHeaderValue.test(value)) {
- throw new ERR_INVALID_CHAR('header content', name);
- }
-
- this[kHeaders][name.toLowerCase()] = value;
}
setNoDelay() {
@@ -21224,8 +17234,9 @@ const {Readable} = __nccwpck_require__(2781);
class IncomingMessage extends Readable {
constructor(socket, highWaterMark) {
super({
- highWaterMark,
- autoDestroy: false
+ emitClose: false,
+ autoDestroy: true,
+ highWaterMark
});
this.statusCode = null;
@@ -21245,12 +17256,26 @@ class IncomingMessage extends Readable {
this.rawTrailers = [];
this.socket = socket;
- this.connection = socket;
this._dumped = false;
}
- _destroy(error) {
+ get connection() {
+ return this.socket;
+ }
+
+ set connection(value) {
+ this.socket = value;
+ }
+
+ _destroy(error, callback) {
+ if (!this.readableEnded) {
+ this.aborted = true;
+ }
+
+ // See https://github.com/nodejs/node/issues/35303
+ callback();
+
this.req._request.destroy(error);
}
@@ -21286,14 +17311,26 @@ module.exports = IncomingMessage;
"use strict";
const http2 = __nccwpck_require__(5158);
-const agent = __nccwpck_require__(9898);
+const {
+ Agent,
+ globalAgent
+} = __nccwpck_require__(9898);
const ClientRequest = __nccwpck_require__(9632);
const IncomingMessage = __nccwpck_require__(2575);
const auto = __nccwpck_require__(7167);
+const {
+ HttpOverHttp2,
+ HttpsOverHttp2
+} = __nccwpck_require__(8795);
+const Http2OverHttp2 = __nccwpck_require__(8553);
+const {
+ Http2OverHttp,
+ Http2OverHttps
+} = __nccwpck_require__(9794);
+const validateHeaderName = __nccwpck_require__(4592);
+const validateHeaderValue = __nccwpck_require__(3549);
-const request = (url, options, callback) => {
- return new ClientRequest(url, options, callback);
-};
+const request = (url, options, callback) => new ClientRequest(url, options, callback);
const get = (url, options, callback) => {
// eslint-disable-next-line unicorn/prevent-abbreviations
@@ -21307,13 +17344,338 @@ module.exports = {
...http2,
ClientRequest,
IncomingMessage,
- ...agent,
+ Agent,
+ globalAgent,
request,
get,
- auto
+ auto,
+ proxies: {
+ HttpOverHttp2,
+ HttpsOverHttp2,
+ Http2OverHttp2,
+ Http2OverHttp,
+ Http2OverHttps
+ },
+ validateHeaderName,
+ validateHeaderValue
};
+/***/ }),
+
+/***/ 7885:
+/***/ ((module) => {
+
+"use strict";
+
+
+module.exports = self => {
+ const {username, password} = self.proxyOptions.url;
+
+ if (username || password) {
+ const data = `${username}:${password}`;
+ const authorization = `Basic ${Buffer.from(data).toString('base64')}`;
+
+ return {
+ 'proxy-authorization': authorization,
+ authorization
+ };
+ }
+
+ return {};
+};
+
+
+/***/ }),
+
+/***/ 8795:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const tls = __nccwpck_require__(4404);
+const http = __nccwpck_require__(3685);
+const https = __nccwpck_require__(5687);
+const JSStreamSocket = __nccwpck_require__(1564);
+const {globalAgent} = __nccwpck_require__(9898);
+const UnexpectedStatusCodeError = __nccwpck_require__(6203);
+const initialize = __nccwpck_require__(1089);
+const getAuthorizationHeaders = __nccwpck_require__(7885);
+
+const createConnection = (self, options, callback) => {
+ (async () => {
+ try {
+ const {proxyOptions} = self;
+ const {url, headers, raw} = proxyOptions;
+
+ const stream = await globalAgent.request(url, proxyOptions, {
+ ...getAuthorizationHeaders(self),
+ ...headers,
+ ':method': 'CONNECT',
+ ':authority': `${options.host}:${options.port}`
+ });
+
+ stream.once('error', callback);
+ stream.once('response', headers => {
+ const statusCode = headers[':status'];
+
+ if (statusCode !== 200) {
+ callback(new UnexpectedStatusCodeError(statusCode, ''));
+ return;
+ }
+
+ const encrypted = self instanceof https.Agent;
+
+ if (raw && encrypted) {
+ options.socket = stream;
+ const secureStream = tls.connect(options);
+
+ secureStream.once('close', () => {
+ stream.destroy();
+ });
+
+ callback(null, secureStream);
+ return;
+ }
+
+ const socket = new JSStreamSocket(stream);
+ socket.encrypted = false;
+ socket._handle.getpeername = out => {
+ out.family = undefined;
+ out.address = undefined;
+ out.port = undefined;
+ };
+
+ callback(null, socket);
+ });
+ } catch (error) {
+ callback(error);
+ }
+ })();
+};
+
+class HttpOverHttp2 extends http.Agent {
+ constructor(options) {
+ super(options);
+
+ initialize(this, options.proxyOptions);
+ }
+
+ createConnection(options, callback) {
+ createConnection(this, options, callback);
+ }
+}
+
+class HttpsOverHttp2 extends https.Agent {
+ constructor(options) {
+ super(options);
+
+ initialize(this, options.proxyOptions);
+ }
+
+ createConnection(options, callback) {
+ createConnection(this, options, callback);
+ }
+}
+
+module.exports = {
+ HttpOverHttp2,
+ HttpsOverHttp2
+};
+
+
+/***/ }),
+
+/***/ 9794:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const http = __nccwpck_require__(3685);
+const https = __nccwpck_require__(5687);
+const Http2OverHttpX = __nccwpck_require__(1857);
+const getAuthorizationHeaders = __nccwpck_require__(7885);
+
+const getStream = request => new Promise((resolve, reject) => {
+ const onConnect = (response, socket, head) => {
+ socket.unshift(head);
+
+ request.off('error', reject);
+ resolve([socket, response.statusCode, response.statusMessage]);
+ };
+
+ request.once('error', reject);
+ request.once('connect', onConnect);
+});
+
+class Http2OverHttp extends Http2OverHttpX {
+ async _getProxyStream(authority) {
+ const {proxyOptions} = this;
+ const {url, headers} = this.proxyOptions;
+
+ const network = url.protocol === 'https:' ? https : http;
+
+ // `new URL('https://localhost/httpbin.org:443')` results in
+ // a `/httpbin.org:443` path, which has an invalid leading slash.
+ const request = network.request({
+ ...proxyOptions,
+ hostname: url.hostname,
+ port: url.port,
+ path: authority,
+ headers: {
+ ...getAuthorizationHeaders(this),
+ ...headers,
+ host: authority
+ },
+ method: 'CONNECT'
+ }).end();
+
+ return getStream(request);
+ }
+}
+
+module.exports = {
+ Http2OverHttp,
+ Http2OverHttps: Http2OverHttp
+};
+
+
+/***/ }),
+
+/***/ 8553:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const {globalAgent} = __nccwpck_require__(9898);
+const Http2OverHttpX = __nccwpck_require__(1857);
+const getAuthorizationHeaders = __nccwpck_require__(7885);
+
+const getStatusCode = stream => new Promise((resolve, reject) => {
+ stream.once('error', reject);
+ stream.once('response', headers => {
+ stream.off('error', reject);
+ resolve(headers[':status']);
+ });
+});
+
+class Http2OverHttp2 extends Http2OverHttpX {
+ async _getProxyStream(authority) {
+ const {proxyOptions} = this;
+
+ const headers = {
+ ...getAuthorizationHeaders(this),
+ ...proxyOptions.headers,
+ ':method': 'CONNECT',
+ ':authority': authority
+ };
+
+ const stream = await globalAgent.request(proxyOptions.url, proxyOptions, headers);
+ const statusCode = await getStatusCode(stream);
+
+ return [stream, statusCode, ''];
+ }
+}
+
+module.exports = Http2OverHttp2;
+
+
+/***/ }),
+
+/***/ 1857:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const {Agent} = __nccwpck_require__(9898);
+const JSStreamSocket = __nccwpck_require__(1564);
+const UnexpectedStatusCodeError = __nccwpck_require__(6203);
+const initialize = __nccwpck_require__(1089);
+
+class Http2OverHttpX extends Agent {
+ constructor(options) {
+ super(options);
+
+ initialize(this, options.proxyOptions);
+ }
+
+ async createConnection(origin, options) {
+ const authority = `${origin.hostname}:${origin.port || 443}`;
+
+ const [stream, statusCode, statusMessage] = await this._getProxyStream(authority);
+ if (statusCode !== 200) {
+ throw new UnexpectedStatusCodeError(statusCode, statusMessage);
+ }
+
+ if (this.proxyOptions.raw) {
+ options.socket = stream;
+ } else {
+ const socket = new JSStreamSocket(stream);
+ socket.encrypted = false;
+ socket._handle.getpeername = out => {
+ out.family = undefined;
+ out.address = undefined;
+ out.port = undefined;
+ };
+
+ return socket;
+ }
+
+ return super.createConnection(origin, options);
+ }
+}
+
+module.exports = Http2OverHttpX;
+
+
+/***/ }),
+
+/***/ 1089:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+// See https://github.com/facebook/jest/issues/2549
+// eslint-disable-next-line node/prefer-global/url
+const {URL} = __nccwpck_require__(7310);
+const checkType = __nccwpck_require__(3453);
+
+module.exports = (self, proxyOptions) => {
+ checkType('proxyOptions', proxyOptions, ['object']);
+ checkType('proxyOptions.headers', proxyOptions.headers, ['object', 'undefined']);
+ checkType('proxyOptions.raw', proxyOptions.raw, ['boolean', 'undefined']);
+ checkType('proxyOptions.url', proxyOptions.url, [URL, 'string']);
+
+ const url = new URL(proxyOptions.url);
+
+ self.proxyOptions = {
+ raw: true,
+ ...proxyOptions,
+ headers: {...proxyOptions.headers},
+ url
+ };
+};
+
+
+/***/ }),
+
+/***/ 6203:
+/***/ ((module) => {
+
+"use strict";
+
+
+class UnexpectedStatusCodeError extends Error {
+ constructor(statusCode, statusMessage = '') {
+ super(`The proxy server rejected the request with status code ${statusCode} (${statusMessage || 'empty status message'})`);
+ this.statusCode = statusCode;
+ this.statusMessage = statusMessage;
+ }
+}
+
+module.exports = UnexpectedStatusCodeError;
+
+
/***/ }),
/***/ 1982:
@@ -21321,27 +17683,29 @@ module.exports = {
"use strict";
-const net = __nccwpck_require__(1808);
-/* istanbul ignore file: https://github.com/nodejs/node/blob/v13.0.1/lib/_http_agent.js */
+const {isIP} = __nccwpck_require__(1808);
+const assert = __nccwpck_require__(9491);
-module.exports = options => {
- let servername = options.host;
- const hostHeader = options.headers && options.headers.host;
+const getHost = host => {
+ if (host[0] === '[') {
+ const idx = host.indexOf(']');
- if (hostHeader) {
- if (hostHeader.startsWith('[')) {
- const index = hostHeader.indexOf(']');
- if (index === -1) {
- servername = hostHeader;
- } else {
- servername = hostHeader.slice(1, -1);
- }
- } else {
- servername = hostHeader.split(':', 1)[0];
- }
+ assert(idx !== -1);
+ return host.slice(1, idx);
}
- if (net.isIP(servername)) {
+ const idx = host.indexOf(':');
+ if (idx === -1) {
+ return host;
+ }
+
+ return host.slice(0, idx);
+};
+
+module.exports = host => {
+ const servername = getHost(host);
+
+ if (isIP(servername)) {
return '';
}
@@ -21349,6 +17713,75 @@ module.exports = options => {
};
+/***/ }),
+
+/***/ 3453:
+/***/ ((module) => {
+
+"use strict";
+
+
+const checkType = (name, value, types) => {
+ const valid = types.some(type => {
+ const typeofType = typeof type;
+ if (typeofType === 'string') {
+ return typeof value === type;
+ }
+
+ return value instanceof type;
+ });
+
+ if (!valid) {
+ const names = types.map(type => typeof type === 'string' ? type : type.name);
+
+ throw new TypeError(`Expected '${name}' to be a type of ${names.join(' or ')}, got ${typeof value}`);
+ }
+};
+
+module.exports = checkType;
+
+
+/***/ }),
+
+/***/ 9237:
+/***/ ((module) => {
+
+"use strict";
+
+
+module.exports = stream => {
+ if (stream.listenerCount('error') !== 0) {
+ return stream;
+ }
+
+ stream.__destroy = stream._destroy;
+ stream._destroy = (...args) => {
+ const callback = args.pop();
+
+ stream.__destroy(...args, async error => {
+ await Promise.resolve();
+ callback(error);
+ });
+ };
+
+ const onError = error => {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ Promise.resolve().then(() => {
+ stream.emit('error', error);
+ });
+ };
+
+ stream.once('error', onError);
+
+ // eslint-disable-next-line promise/prefer-await-to-then
+ Promise.resolve().then(() => {
+ stream.off('error', onError);
+ });
+
+ return stream;
+};
+
+
/***/ }),
/***/ 7087:
@@ -21381,25 +17814,31 @@ makeError(TypeError, 'ERR_INVALID_ARG_TYPE', args => {
return `The "${args[0]}" ${type} must be ${isManyTypes ? 'one of' : 'of'} type ${valid}. Received ${typeof args[2]}`;
});
-makeError(TypeError, 'ERR_INVALID_PROTOCOL', args => {
- return `Protocol "${args[0]}" not supported. Expected "${args[1]}"`;
-});
+makeError(TypeError, 'ERR_INVALID_PROTOCOL', args =>
+ `Protocol "${args[0]}" not supported. Expected "${args[1]}"`
+);
-makeError(Error, 'ERR_HTTP_HEADERS_SENT', args => {
- return `Cannot ${args[0]} headers after they are sent to the client`;
-});
+makeError(Error, 'ERR_HTTP_HEADERS_SENT', args =>
+ `Cannot ${args[0]} headers after they are sent to the client`
+);
-makeError(TypeError, 'ERR_INVALID_HTTP_TOKEN', args => {
- return `${args[0]} must be a valid HTTP token [${args[1]}]`;
-});
+makeError(TypeError, 'ERR_INVALID_HTTP_TOKEN', args =>
+ `${args[0]} must be a valid HTTP token [${args[1]}]`
+);
-makeError(TypeError, 'ERR_HTTP_INVALID_HEADER_VALUE', args => {
- return `Invalid value "${args[0]} for header "${args[1]}"`;
-});
+makeError(TypeError, 'ERR_HTTP_INVALID_HEADER_VALUE', args =>
+ `Invalid value "${args[0]} for header "${args[1]}"`
+);
-makeError(TypeError, 'ERR_INVALID_CHAR', args => {
- return `Invalid character in ${args[0]} [${args[1]}]`;
-});
+makeError(TypeError, 'ERR_INVALID_CHAR', args =>
+ `Invalid character in ${args[0]} [${args[1]}]`
+);
+
+makeError(
+ Error,
+ 'ERR_HTTP2_NO_SOCKET_MANIPULATION',
+ 'HTTP/2 sockets should not be directly manipulated (e.g. read and written)'
+);
/***/ }),
@@ -21423,6 +17862,22 @@ module.exports = header => {
};
+/***/ }),
+
+/***/ 1564:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const stream = __nccwpck_require__(2781);
+const tls = __nccwpck_require__(4404);
+
+// Really awesome hack.
+const JSStreamSocket = (new tls.TLSSocket(new stream.PassThrough()))._handle._parentWrap.constructor;
+
+module.exports = JSStreamSocket;
+
+
/***/ }),
/***/ 1818:
@@ -21440,34 +17895,155 @@ module.exports = (from, to, events) => {
/***/ }),
-/***/ 2686:
-/***/ ((module) => {
+/***/ 9404:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
"use strict";
-/* istanbul ignore file: https://github.com/nodejs/node/blob/a91293d4d9ab403046ab5eb022332e4e3d249bd3/lib/internal/url.js#L1257 */
+const {ERR_HTTP2_NO_SOCKET_MANIPULATION} = __nccwpck_require__(7087);
-module.exports = url => {
- const options = {
- protocol: url.protocol,
- hostname: typeof url.hostname === 'string' && url.hostname.startsWith('[') ? url.hostname.slice(1, -1) : url.hostname,
- host: url.host,
- hash: url.hash,
- search: url.search,
- pathname: url.pathname,
- href: url.href,
- path: `${url.pathname || ''}${url.search || ''}`
- };
+/* istanbul ignore file */
+/* https://github.com/nodejs/node/blob/6eec858f34a40ffa489c1ec54bb24da72a28c781/lib/internal/http2/compat.js#L195-L272 */
- if (typeof url.port === 'string' && url.port.length !== 0) {
- options.port = Number(url.port);
+const proxySocketHandler = {
+ has(stream, property) {
+ // Replaced [kSocket] with .socket
+ const reference = stream.session === undefined ? stream : stream.session.socket;
+ return (property in stream) || (property in reference);
+ },
+
+ get(stream, property) {
+ switch (property) {
+ case 'on':
+ case 'once':
+ case 'end':
+ case 'emit':
+ case 'destroy':
+ return stream[property].bind(stream);
+ case 'writable':
+ case 'destroyed':
+ return stream[property];
+ case 'readable':
+ if (stream.destroyed) {
+ return false;
+ }
+
+ return stream.readable;
+ case 'setTimeout': {
+ const {session} = stream;
+ if (session !== undefined) {
+ return session.setTimeout.bind(session);
+ }
+
+ return stream.setTimeout.bind(stream);
+ }
+
+ case 'write':
+ case 'read':
+ case 'pause':
+ case 'resume':
+ throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
+ default: {
+ // Replaced [kSocket] with .socket
+ const reference = stream.session === undefined ? stream : stream.session.socket;
+ const value = reference[property];
+
+ return typeof value === 'function' ? value.bind(reference) : value;
+ }
+ }
+ },
+
+ getPrototypeOf(stream) {
+ if (stream.session !== undefined) {
+ // Replaced [kSocket] with .socket
+ return Reflect.getPrototypeOf(stream.session.socket);
+ }
+
+ return Reflect.getPrototypeOf(stream);
+ },
+
+ set(stream, property, value) {
+ switch (property) {
+ case 'writable':
+ case 'readable':
+ case 'destroyed':
+ case 'on':
+ case 'once':
+ case 'end':
+ case 'emit':
+ case 'destroy':
+ stream[property] = value;
+ return true;
+ case 'setTimeout': {
+ const {session} = stream;
+ if (session === undefined) {
+ stream.setTimeout = value;
+ } else {
+ session.setTimeout = value;
+ }
+
+ return true;
+ }
+
+ case 'write':
+ case 'read':
+ case 'pause':
+ case 'resume':
+ throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
+ default: {
+ // Replaced [kSocket] with .socket
+ const reference = stream.session === undefined ? stream : stream.session.socket;
+ reference[property] = value;
+ return true;
+ }
+ }
+ }
+};
+
+module.exports = proxySocketHandler;
+
+
+/***/ }),
+
+/***/ 4592:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const {ERR_INVALID_HTTP_TOKEN} = __nccwpck_require__(7087);
+const isRequestPseudoHeader = __nccwpck_require__(1199);
+
+const isValidHttpToken = /^[\^`\-\w!#$%&*+.|~]+$/;
+
+module.exports = name => {
+ if (typeof name !== 'string' || (!isValidHttpToken.test(name) && !isRequestPseudoHeader(name))) {
+ throw new ERR_INVALID_HTTP_TOKEN('Header name', name);
+ }
+};
+
+
+/***/ }),
+
+/***/ 3549:
+/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
+
+"use strict";
+
+const {
+ ERR_HTTP_INVALID_HEADER_VALUE,
+ ERR_INVALID_CHAR
+} = __nccwpck_require__(7087);
+
+const isInvalidHeaderValue = /[^\t\u0020-\u007E\u0080-\u00FF]/;
+
+module.exports = (name, value) => {
+ if (typeof value === 'undefined') {
+ throw new ERR_HTTP_INVALID_HEADER_VALUE(value, name);
}
- if (url.username || url.password) {
- options.auth = `${url.username || ''}:${url.password || ''}`;
+ if (isInvalidHeaderValue.test(value)) {
+ throw new ERR_INVALID_CHAR('header content', name);
}
-
- return options;
};
@@ -21802,7 +18378,6 @@ exports.parse = function (s) {
const EventEmitter = __nccwpck_require__(2361);
const JSONB = __nccwpck_require__(2820);
-const compressBrotli = __nccwpck_require__(5728);
const loadStore = options => {
const adapters = {
@@ -21851,13 +18426,10 @@ class Keyv extends EventEmitter {
this.opts.store = loadStore(adapterOptions);
}
- if (this.opts.compress) {
- const brotli = compressBrotli(this.opts.compress.opts);
- this.opts.serialize = async ({value, expires}) => brotli.serialize({value: await brotli.compress(value), expires});
- this.opts.deserialize = async data => {
- const {value, expires} = brotli.deserialize(data);
- return {value: await brotli.decompress(value), expires};
- };
+ if (this.opts.compression) {
+ const compression = this.opts.compression;
+ this.opts.serialize = compression.serialize.bind(compression);
+ this.opts.deserialize = compression.deserialize.bind(compression);
}
if (typeof this.opts.store.on === 'function' && emitErrors) {
@@ -21870,7 +18442,7 @@ class Keyv extends EventEmitter {
for await (const [key, raw] of typeof iterator === 'function'
? iterator(this.opts.store.namespace)
: iterator) {
- const data = this.opts.deserialize(raw);
+ const data = await this.opts.deserialize(raw);
if (this.opts.store.namespace && !key.includes(this.opts.store.namespace)) {
continue;
}
@@ -21922,7 +18494,7 @@ class Keyv extends EventEmitter {
for (const key of keyPrefixed) {
promises.push(Promise.resolve()
.then(() => store.get(key))
- .then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data)
+ .then(data => (typeof data === 'string') ? this.opts.deserialize(data) : (this.opts.compression ? this.opts.deserialize(data) : data))
.then(data => {
if (data === undefined || data === null) {
return undefined;
@@ -21944,13 +18516,13 @@ class Keyv extends EventEmitter {
data.push(value.value);
}
- return data.every(x => x === undefined) ? [] : data;
+ return data;
});
}
return Promise.resolve()
.then(() => isArray ? store.getMany(keyPrefixed) : store.get(keyPrefixed))
- .then(data => (typeof data === 'string') ? this.opts.deserialize(data) : data)
+ .then(data => (typeof data === 'string') ? this.opts.deserialize(data) : (this.opts.compression ? this.opts.deserialize(data) : data))
.then(data => {
if (data === undefined || data === null) {
return undefined;
@@ -21959,10 +18531,6 @@ class Keyv extends EventEmitter {
if (isArray) {
const result = [];
- if (data.length === 0) {
- return [];
- }
-
for (let row of data) {
if ((typeof row === 'string')) {
row = this.opts.deserialize(row);
@@ -21981,7 +18549,7 @@ class Keyv extends EventEmitter {
}
}
- return result.every(x => x === undefined) ? [] : result;
+ return result;
}
if (typeof data.expires === 'number' && Date.now() > data.expires) {
@@ -22072,24 +18640,6 @@ class Keyv extends EventEmitter {
module.exports = Keyv;
-/***/ }),
-
-/***/ 9662:
-/***/ ((module) => {
-
-"use strict";
-
-module.exports = object => {
- const result = {};
-
- for (const [key, value] of Object.entries(object)) {
- result[key.toLowerCase()] = value;
- }
-
- return result;
-};
-
-
/***/ }),
/***/ 2578:
@@ -22717,46 +19267,6 @@ micromatch.braceExpand = (pattern, options) => {
module.exports = micromatch;
-/***/ }),
-
-/***/ 2610:
-/***/ ((module) => {
-
-"use strict";
-
-
-// We define these manually to ensure they're always copied
-// even if they would move up the prototype chain
-// https://nodejs.org/api/http.html#http_class_http_incomingmessage
-const knownProps = [
- 'destroy',
- 'setTimeout',
- 'socket',
- 'headers',
- 'trailers',
- 'rawHeaders',
- 'statusCode',
- 'httpVersion',
- 'httpVersionMinor',
- 'httpVersionMajor',
- 'rawTrailers',
- 'statusMessage'
-];
-
-module.exports = (fromStream, toStream) => {
- const fromProps = new Set(Object.keys(fromStream).concat(knownProps));
-
- for (const prop of fromProps) {
- // Don't overwrite existing properties
- if (prop in toStream) {
- continue;
- }
-
- toStream[prop] = typeof fromStream[prop] === 'function' ? fromStream[prop].bind(fromStream) : fromStream[prop];
- }
-};
-
-
/***/ }),
/***/ 467:
@@ -24462,230 +20972,6 @@ exports.Response = Response;
exports.FetchError = FetchError;
-/***/ }),
-
-/***/ 7952:
-/***/ ((module) => {
-
-"use strict";
-
-
-// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
-const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';
-const DATA_URL_DEFAULT_CHARSET = 'us-ascii';
-
-const testParameter = (name, filters) => {
- return filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
-};
-
-const normalizeDataURL = (urlString, {stripHash}) => {
- const match = /^data:(?[^,]*?),(?[^#]*?)(?:#(?.*))?$/.exec(urlString);
-
- if (!match) {
- throw new Error(`Invalid URL: ${urlString}`);
- }
-
- let {type, data, hash} = match.groups;
- const mediaType = type.split(';');
- hash = stripHash ? '' : hash;
-
- let isBase64 = false;
- if (mediaType[mediaType.length - 1] === 'base64') {
- mediaType.pop();
- isBase64 = true;
- }
-
- // Lowercase MIME type
- const mimeType = (mediaType.shift() || '').toLowerCase();
- const attributes = mediaType
- .map(attribute => {
- let [key, value = ''] = attribute.split('=').map(string => string.trim());
-
- // Lowercase `charset`
- if (key === 'charset') {
- value = value.toLowerCase();
-
- if (value === DATA_URL_DEFAULT_CHARSET) {
- return '';
- }
- }
-
- return `${key}${value ? `=${value}` : ''}`;
- })
- .filter(Boolean);
-
- const normalizedMediaType = [
- ...attributes
- ];
-
- if (isBase64) {
- normalizedMediaType.push('base64');
- }
-
- if (normalizedMediaType.length !== 0 || (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)) {
- normalizedMediaType.unshift(mimeType);
- }
-
- return `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ''}`;
-};
-
-const normalizeUrl = (urlString, options) => {
- options = {
- defaultProtocol: 'http:',
- normalizeProtocol: true,
- forceHttp: false,
- forceHttps: false,
- stripAuthentication: true,
- stripHash: false,
- stripTextFragment: true,
- stripWWW: true,
- removeQueryParameters: [/^utm_\w+/i],
- removeTrailingSlash: true,
- removeSingleSlash: true,
- removeDirectoryIndex: false,
- sortQueryParameters: true,
- ...options
- };
-
- urlString = urlString.trim();
-
- // Data URL
- if (/^data:/i.test(urlString)) {
- return normalizeDataURL(urlString, options);
- }
-
- if (/^view-source:/i.test(urlString)) {
- throw new Error('`view-source:` is not supported as it is a non-standard protocol');
- }
-
- const hasRelativeProtocol = urlString.startsWith('//');
- const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
-
- // Prepend protocol
- if (!isRelativeUrl) {
- urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
- }
-
- const urlObj = new URL(urlString);
-
- if (options.forceHttp && options.forceHttps) {
- throw new Error('The `forceHttp` and `forceHttps` options cannot be used together');
- }
-
- if (options.forceHttp && urlObj.protocol === 'https:') {
- urlObj.protocol = 'http:';
- }
-
- if (options.forceHttps && urlObj.protocol === 'http:') {
- urlObj.protocol = 'https:';
- }
-
- // Remove auth
- if (options.stripAuthentication) {
- urlObj.username = '';
- urlObj.password = '';
- }
-
- // Remove hash
- if (options.stripHash) {
- urlObj.hash = '';
- } else if (options.stripTextFragment) {
- urlObj.hash = urlObj.hash.replace(/#?:~:text.*?$/i, '');
- }
-
- // Remove duplicate slashes if not preceded by a protocol
- if (urlObj.pathname) {
- urlObj.pathname = urlObj.pathname.replace(/(? 0) {
- let pathComponents = urlObj.pathname.split('/');
- const lastComponent = pathComponents[pathComponents.length - 1];
-
- if (testParameter(lastComponent, options.removeDirectoryIndex)) {
- pathComponents = pathComponents.slice(0, pathComponents.length - 1);
- urlObj.pathname = pathComponents.slice(1).join('/') + '/';
- }
- }
-
- if (urlObj.hostname) {
- // Remove trailing dot
- urlObj.hostname = urlObj.hostname.replace(/\.$/, '');
-
- // Remove `www.`
- if (options.stripWWW && /^www\.(?!www\.)(?:[a-z\-\d]{1,63})\.(?:[a-z.\-\d]{2,63})$/.test(urlObj.hostname)) {
- // Each label should be max 63 at length (min: 1).
- // Source: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
- // Each TLD should be up to 63 characters long (min: 2).
- // It is technically possible to have a single character TLD, but none currently exist.
- urlObj.hostname = urlObj.hostname.replace(/^www\./, '');
- }
- }
-
- // Remove query unwanted parameters
- if (Array.isArray(options.removeQueryParameters)) {
- for (const key of [...urlObj.searchParams.keys()]) {
- if (testParameter(key, options.removeQueryParameters)) {
- urlObj.searchParams.delete(key);
- }
- }
- }
-
- if (options.removeQueryParameters === true) {
- urlObj.search = '';
- }
-
- // Sort query parameters
- if (options.sortQueryParameters) {
- urlObj.searchParams.sort();
- }
-
- if (options.removeTrailingSlash) {
- urlObj.pathname = urlObj.pathname.replace(/\/$/, '');
- }
-
- const oldUrlString = urlString;
-
- // Take advantage of many of the Node `url` normalizations
- urlString = urlObj.toString();
-
- if (!options.removeSingleSlash && urlObj.pathname === '/' && !oldUrlString.endsWith('/') && urlObj.hash === '') {
- urlString = urlString.replace(/\/$/, '');
- }
-
- // Remove ending `/` unless removeSingleSlash is false
- if ((options.removeTrailingSlash || urlObj.pathname === '/') && urlObj.hash === '' && options.removeSingleSlash) {
- urlString = urlString.replace(/\/$/, '');
- }
-
- // Restore relative protocol, if applicable
- if (hasRelativeProtocol && !options.normalizeProtocol) {
- urlString = urlString.replace(/^http:\/\//, '//');
- }
-
- // Remove http/https
- if (options.stripProtocol) {
- urlString = urlString.replace(/^(?:https?:)?\/\//, '');
- }
-
- return urlString;
-};
-
-module.exports = normalizeUrl;
-
-
/***/ }),
/***/ 1223:
@@ -24735,125 +21021,6 @@ function onceStrict (fn) {
}
-/***/ }),
-
-/***/ 9072:
-/***/ ((module) => {
-
-"use strict";
-
-
-class CancelError extends Error {
- constructor(reason) {
- super(reason || 'Promise was canceled');
- this.name = 'CancelError';
- }
-
- get isCanceled() {
- return true;
- }
-}
-
-class PCancelable {
- static fn(userFn) {
- return (...arguments_) => {
- return new PCancelable((resolve, reject, onCancel) => {
- arguments_.push(onCancel);
- // eslint-disable-next-line promise/prefer-await-to-then
- userFn(...arguments_).then(resolve, reject);
- });
- };
- }
-
- constructor(executor) {
- this._cancelHandlers = [];
- this._isPending = true;
- this._isCanceled = false;
- this._rejectOnCancel = true;
-
- this._promise = new Promise((resolve, reject) => {
- this._reject = reject;
-
- const onResolve = value => {
- if (!this._isCanceled || !onCancel.shouldReject) {
- this._isPending = false;
- resolve(value);
- }
- };
-
- const onReject = error => {
- this._isPending = false;
- reject(error);
- };
-
- const onCancel = handler => {
- if (!this._isPending) {
- throw new Error('The `onCancel` handler was attached after the promise settled.');
- }
-
- this._cancelHandlers.push(handler);
- };
-
- Object.defineProperties(onCancel, {
- shouldReject: {
- get: () => this._rejectOnCancel,
- set: boolean => {
- this._rejectOnCancel = boolean;
- }
- }
- });
-
- return executor(onResolve, onReject, onCancel);
- });
- }
-
- then(onFulfilled, onRejected) {
- // eslint-disable-next-line promise/prefer-await-to-then
- return this._promise.then(onFulfilled, onRejected);
- }
-
- catch(onRejected) {
- return this._promise.catch(onRejected);
- }
-
- finally(onFinally) {
- return this._promise.finally(onFinally);
- }
-
- cancel(reason) {
- if (!this._isPending || this._isCanceled) {
- return;
- }
-
- this._isCanceled = true;
-
- if (this._cancelHandlers.length > 0) {
- try {
- for (const handler of this._cancelHandlers) {
- handler();
- }
- } catch (error) {
- this._reject(error);
- return;
- }
- }
-
- if (this._rejectOnCancel) {
- this._reject(new CancelError(reason));
- }
- }
-
- get isCanceled() {
- return this._isCanceled;
- }
-}
-
-Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
-
-module.exports = PCancelable;
-module.exports.CancelError = CancelError;
-
-
/***/ }),
/***/ 8569:
@@ -26972,95 +23139,6 @@ exports.wrapOutput = (input, state = {}, options = {}) => {
};
-/***/ }),
-
-/***/ 8341:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-var once = __nccwpck_require__(1223)
-var eos = __nccwpck_require__(1205)
-var fs = __nccwpck_require__(7147) // we only need fs to get the ReadStream and WriteStream prototypes
-
-var noop = function () {}
-var ancient = /^v?\.0/.test(process.version)
-
-var isFn = function (fn) {
- return typeof fn === 'function'
-}
-
-var isFS = function (stream) {
- if (!ancient) return false // newer node version do not need to care about fs is a special way
- if (!fs) return false // browser
- return (stream instanceof (fs.ReadStream || noop) || stream instanceof (fs.WriteStream || noop)) && isFn(stream.close)
-}
-
-var isRequest = function (stream) {
- return stream.setHeader && isFn(stream.abort)
-}
-
-var destroyer = function (stream, reading, writing, callback) {
- callback = once(callback)
-
- var closed = false
- stream.on('close', function () {
- closed = true
- })
-
- eos(stream, {readable: reading, writable: writing}, function (err) {
- if (err) return callback(err)
- closed = true
- callback()
- })
-
- var destroyed = false
- return function (err) {
- if (closed) return
- if (destroyed) return
- destroyed = true
-
- if (isFS(stream)) return stream.close(noop) // use close for fs streams to avoid fd leaks
- if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want
-
- if (isFn(stream.destroy)) return stream.destroy()
-
- callback(err || new Error('stream was destroyed'))
- }
-}
-
-var call = function (fn) {
- fn()
-}
-
-var pipe = function (from, to) {
- return from.pipe(to)
-}
-
-var pump = function () {
- var streams = Array.prototype.slice.call(arguments)
- var callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop
-
- if (Array.isArray(streams[0])) streams = streams[0]
- if (streams.length < 2) throw new Error('pump requires two streams per minimum')
-
- var error
- var destroys = streams.map(function (stream, i) {
- var reading = i < streams.length - 1
- var writing = i > 0
- return destroyer(stream, reading, writing, function (err) {
- if (!error) error = err
- if (err) destroys.forEach(call)
- if (reading) return
- destroys.forEach(call)
- callback(error)
- })
- })
-
- return streams.reduce(pipe)
-}
-
-module.exports = pump
-
-
/***/ }),
/***/ 9795:
@@ -27259,48 +23337,6 @@ module.exports = (options = {}, connect = tls.connect) => new Promise((resolve,
});
-/***/ }),
-
-/***/ 9004:
-/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
-
-"use strict";
-
-
-const Readable = (__nccwpck_require__(2781).Readable);
-const lowercaseKeys = __nccwpck_require__(9662);
-
-class Response extends Readable {
- constructor(statusCode, headers, body, url) {
- if (typeof statusCode !== 'number') {
- throw new TypeError('Argument `statusCode` should be a number');
- }
- if (typeof headers !== 'object') {
- throw new TypeError('Argument `headers` should be an object');
- }
- if (!(body instanceof Buffer)) {
- throw new TypeError('Argument `body` should be a buffer');
- }
- if (typeof url !== 'string') {
- throw new TypeError('Argument `url` should be a string');
- }
-
- super();
- this.statusCode = statusCode;
- this.headers = lowercaseKeys(headers);
- this.body = body;
- this.url = url;
- }
-
- _read() {
- this.push(this.body);
- this.push(null);
- }
-}
-
-module.exports = Response;
-
-
/***/ }),
/***/ 2113:
@@ -32802,14 +28838,14 @@ function wrappy (fn, cb) {
this.saxParser.onopentag = (function(_this) {
return function(node) {
var key, newValue, obj, processedKey, ref;
- obj = {};
+ obj = Object.create(null);
obj[charkey] = "";
if (!_this.options.ignoreAttrs) {
ref = node.attributes;
for (key in ref) {
if (!hasProp.call(ref, key)) continue;
if (!(attrkey in obj) && !_this.options.mergeAttrs) {
- obj[attrkey] = {};
+ obj[attrkey] = Object.create(null);
}
newValue = _this.options.attrValueProcessors ? processItem(_this.options.attrValueProcessors, node.attributes[key], key) : node.attributes[key];
processedKey = _this.options.attrNameProcessors ? processItem(_this.options.attrNameProcessors, key) : key;
@@ -32859,7 +28895,11 @@ function wrappy (fn, cb) {
}
}
if (isEmpty(obj)) {
- obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr;
+ if (typeof _this.options.emptyTag === 'function') {
+ obj = _this.options.emptyTag();
+ } else {
+ obj = _this.options.emptyTag !== '' ? _this.options.emptyTag : emptyStr;
+ }
}
if (_this.options.validator != null) {
xpath = "/" + ((function() {
@@ -32883,7 +28923,7 @@ function wrappy (fn, cb) {
}
if (_this.options.explicitChildren && !_this.options.mergeAttrs && typeof obj === 'object') {
if (!_this.options.preserveChildrenOrder) {
- node = {};
+ node = Object.create(null);
if (_this.options.attrkey in obj) {
node[_this.options.attrkey] = obj[_this.options.attrkey];
delete obj[_this.options.attrkey];
@@ -32898,7 +28938,7 @@ function wrappy (fn, cb) {
obj = node;
} else if (s) {
s[_this.options.childkey] = s[_this.options.childkey] || [];
- objClone = {};
+ objClone = Object.create(null);
for (key in obj) {
if (!hasProp.call(obj, key)) continue;
objClone[key] = obj[key];
@@ -32915,7 +28955,7 @@ function wrappy (fn, cb) {
} else {
if (_this.options.explicitRoot) {
old = obj;
- obj = {};
+ obj = Object.create(null);
obj[nodeName] = old;
}
_this.resultObject = obj;
@@ -37475,14 +33515,6 @@ module.exports = require("crypto");
/***/ }),
-/***/ 9523:
-/***/ ((module) => {
-
-"use strict";
-module.exports = require("dns");
-
-/***/ }),
-
/***/ 2361:
/***/ ((module) => {
@@ -37609,6 +33641,5891 @@ module.exports = require("util");
"use strict";
module.exports = require("zlib");
+/***/ }),
+
+/***/ 2430:
+/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
+
+"use strict";
+// ESM COMPAT FLAG
+__nccwpck_require__.r(__webpack_exports__);
+
+// EXPORTS
+__nccwpck_require__.d(__webpack_exports__, {
+ "AbortError": () => (/* reexport */ AbortError),
+ "CacheError": () => (/* reexport */ CacheError),
+ "CancelError": () => (/* reexport */ types_CancelError),
+ "HTTPError": () => (/* reexport */ HTTPError),
+ "MaxRedirectsError": () => (/* reexport */ MaxRedirectsError),
+ "Options": () => (/* reexport */ Options),
+ "ParseError": () => (/* reexport */ ParseError),
+ "ReadError": () => (/* reexport */ ReadError),
+ "RequestError": () => (/* reexport */ RequestError),
+ "RetryError": () => (/* reexport */ RetryError),
+ "TimeoutError": () => (/* reexport */ TimeoutError),
+ "UploadError": () => (/* reexport */ UploadError),
+ "calculateRetryDelay": () => (/* reexport */ calculate_retry_delay),
+ "create": () => (/* reexport */ source_create),
+ "default": () => (/* binding */ got_dist_source),
+ "got": () => (/* binding */ got),
+ "isResponseOk": () => (/* reexport */ isResponseOk),
+ "parseBody": () => (/* reexport */ parseBody),
+ "parseLinkHeader": () => (/* reexport */ parseLinkHeader)
+});
+
+;// CONCATENATED MODULE: ./node_modules/@sindresorhus/is/dist/index.js
+const typedArrayTypeNames = [
+ 'Int8Array',
+ 'Uint8Array',
+ 'Uint8ClampedArray',
+ 'Int16Array',
+ 'Uint16Array',
+ 'Int32Array',
+ 'Uint32Array',
+ 'Float32Array',
+ 'Float64Array',
+ 'BigInt64Array',
+ 'BigUint64Array',
+];
+function isTypedArrayName(name) {
+ return typedArrayTypeNames.includes(name);
+}
+const objectTypeNames = [
+ 'Function',
+ 'Generator',
+ 'AsyncGenerator',
+ 'GeneratorFunction',
+ 'AsyncGeneratorFunction',
+ 'AsyncFunction',
+ 'Observable',
+ 'Array',
+ 'Buffer',
+ 'Blob',
+ 'Object',
+ 'RegExp',
+ 'Date',
+ 'Error',
+ 'Map',
+ 'Set',
+ 'WeakMap',
+ 'WeakSet',
+ 'WeakRef',
+ 'ArrayBuffer',
+ 'SharedArrayBuffer',
+ 'DataView',
+ 'Promise',
+ 'URL',
+ 'FormData',
+ 'URLSearchParams',
+ 'HTMLElement',
+ 'NaN',
+ ...typedArrayTypeNames,
+];
+function isObjectTypeName(name) {
+ return objectTypeNames.includes(name);
+}
+const primitiveTypeNames = [
+ 'null',
+ 'undefined',
+ 'string',
+ 'number',
+ 'bigint',
+ 'boolean',
+ 'symbol',
+];
+function isPrimitiveTypeName(name) {
+ return primitiveTypeNames.includes(name);
+}
+// eslint-disable-next-line @typescript-eslint/ban-types
+function isOfType(type) {
+ return (value) => typeof value === type;
+}
+const { toString: dist_toString } = Object.prototype;
+const getObjectType = (value) => {
+ const objectTypeName = dist_toString.call(value).slice(8, -1);
+ if (/HTML\w+Element/.test(objectTypeName) && is.domElement(value)) {
+ return 'HTMLElement';
+ }
+ if (isObjectTypeName(objectTypeName)) {
+ return objectTypeName;
+ }
+ return undefined;
+};
+const isObjectOfType = (type) => (value) => getObjectType(value) === type;
+function is(value) {
+ if (value === null) {
+ return 'null';
+ }
+ switch (typeof value) {
+ case 'undefined': {
+ return 'undefined';
+ }
+ case 'string': {
+ return 'string';
+ }
+ case 'number': {
+ return Number.isNaN(value) ? 'NaN' : 'number';
+ }
+ case 'boolean': {
+ return 'boolean';
+ }
+ case 'function': {
+ return 'Function';
+ }
+ case 'bigint': {
+ return 'bigint';
+ }
+ case 'symbol': {
+ return 'symbol';
+ }
+ default:
+ }
+ if (is.observable(value)) {
+ return 'Observable';
+ }
+ if (is.array(value)) {
+ return 'Array';
+ }
+ if (is.buffer(value)) {
+ return 'Buffer';
+ }
+ const tagType = getObjectType(value);
+ if (tagType) {
+ return tagType;
+ }
+ if (value instanceof String || value instanceof Boolean || value instanceof Number) {
+ throw new TypeError('Please don\'t use object wrappers for primitive types');
+ }
+ return 'Object';
+}
+is.undefined = isOfType('undefined');
+is.string = isOfType('string');
+const isNumberType = isOfType('number');
+is.number = (value) => isNumberType(value) && !is.nan(value);
+is.positiveNumber = (value) => is.number(value) && value > 0;
+is.negativeNumber = (value) => is.number(value) && value < 0;
+is.bigint = isOfType('bigint');
+// eslint-disable-next-line @typescript-eslint/ban-types
+is.function_ = isOfType('function');
+// eslint-disable-next-line @typescript-eslint/ban-types
+is.null_ = (value) => value === null;
+is.class_ = (value) => is.function_(value) && value.toString().startsWith('class ');
+is.boolean = (value) => value === true || value === false;
+is.symbol = isOfType('symbol');
+is.numericString = (value) => is.string(value) && !is.emptyStringOrWhitespace(value) && !Number.isNaN(Number(value));
+is.array = (value, assertion) => {
+ if (!Array.isArray(value)) {
+ return false;
+ }
+ if (!is.function_(assertion)) {
+ return true;
+ }
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
+ return value.every(element => assertion(element));
+};
+// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
+is.buffer = (value) => value?.constructor?.isBuffer?.(value) ?? false;
+is.blob = (value) => isObjectOfType('Blob')(value);
+is.nullOrUndefined = (value) => is.null_(value) || is.undefined(value); // eslint-disable-line @typescript-eslint/ban-types
+is.object = (value) => !is.null_(value) && (typeof value === 'object' || is.function_(value)); // eslint-disable-line @typescript-eslint/ban-types
+is.iterable = (value) => is.function_(value?.[Symbol.iterator]);
+is.asyncIterable = (value) => is.function_(value?.[Symbol.asyncIterator]);
+is.generator = (value) => is.iterable(value) && is.function_(value?.next) && is.function_(value?.throw);
+is.asyncGenerator = (value) => is.asyncIterable(value) && is.function_(value.next) && is.function_(value.throw);
+is.nativePromise = (value) => isObjectOfType('Promise')(value);
+const hasPromiseApi = (value) => is.function_(value?.then)
+ && is.function_(value?.catch);
+is.promise = (value) => is.nativePromise(value) || hasPromiseApi(value);
+is.generatorFunction = isObjectOfType('GeneratorFunction');
+is.asyncGeneratorFunction = (value) => getObjectType(value) === 'AsyncGeneratorFunction';
+is.asyncFunction = (value) => getObjectType(value) === 'AsyncFunction';
+// eslint-disable-next-line no-prototype-builtins, @typescript-eslint/ban-types
+is.boundFunction = (value) => is.function_(value) && !value.hasOwnProperty('prototype');
+is.regExp = isObjectOfType('RegExp');
+is.date = isObjectOfType('Date');
+is.error = isObjectOfType('Error');
+is.map = (value) => isObjectOfType('Map')(value);
+is.set = (value) => isObjectOfType('Set')(value);
+is.weakMap = (value) => isObjectOfType('WeakMap')(value); // eslint-disable-line @typescript-eslint/ban-types
+is.weakSet = (value) => isObjectOfType('WeakSet')(value); // eslint-disable-line @typescript-eslint/ban-types
+is.weakRef = (value) => isObjectOfType('WeakRef')(value); // eslint-disable-line @typescript-eslint/ban-types
+is.int8Array = isObjectOfType('Int8Array');
+is.uint8Array = isObjectOfType('Uint8Array');
+is.uint8ClampedArray = isObjectOfType('Uint8ClampedArray');
+is.int16Array = isObjectOfType('Int16Array');
+is.uint16Array = isObjectOfType('Uint16Array');
+is.int32Array = isObjectOfType('Int32Array');
+is.uint32Array = isObjectOfType('Uint32Array');
+is.float32Array = isObjectOfType('Float32Array');
+is.float64Array = isObjectOfType('Float64Array');
+is.bigInt64Array = isObjectOfType('BigInt64Array');
+is.bigUint64Array = isObjectOfType('BigUint64Array');
+is.arrayBuffer = isObjectOfType('ArrayBuffer');
+is.sharedArrayBuffer = isObjectOfType('SharedArrayBuffer');
+is.dataView = isObjectOfType('DataView');
+// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
+is.enumCase = (value, targetEnum) => Object.values(targetEnum).includes(value);
+is.directInstanceOf = (instance, class_) => Object.getPrototypeOf(instance) === class_.prototype;
+is.urlInstance = (value) => isObjectOfType('URL')(value);
+is.urlString = (value) => {
+ if (!is.string(value)) {
+ return false;
+ }
+ try {
+ new URL(value); // eslint-disable-line no-new
+ return true;
+ }
+ catch {
+ return false;
+ }
+};
+// Example: `is.truthy = (value: unknown): value is (not false | not 0 | not '' | not undefined | not null) => Boolean(value);`
+is.truthy = (value) => Boolean(value); // eslint-disable-line unicorn/prefer-native-coercion-functions
+// Example: `is.falsy = (value: unknown): value is (not true | 0 | '' | undefined | null) => Boolean(value);`
+is.falsy = (value) => !value;
+is.nan = (value) => Number.isNaN(value);
+is.primitive = (value) => is.null_(value) || isPrimitiveTypeName(typeof value);
+is.integer = (value) => Number.isInteger(value);
+is.safeInteger = (value) => Number.isSafeInteger(value);
+is.plainObject = (value) => {
+ // From: https://github.com/sindresorhus/is-plain-obj/blob/main/index.js
+ if (typeof value !== 'object' || value === null) {
+ return false;
+ }
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ const prototype = Object.getPrototypeOf(value);
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
+};
+is.typedArray = (value) => isTypedArrayName(getObjectType(value));
+const isValidLength = (value) => is.safeInteger(value) && value >= 0;
+is.arrayLike = (value) => !is.nullOrUndefined(value) && !is.function_(value) && isValidLength(value.length);
+is.tupleLike = (value, guards) => {
+ if (is.array(guards) && is.array(value) && guards.length === value.length) {
+ return guards.every((guard, index) => guard(value[index]));
+ }
+ return false;
+};
+is.inRange = (value, range) => {
+ if (is.number(range)) {
+ return value >= Math.min(0, range) && value <= Math.max(range, 0);
+ }
+ if (is.array(range) && range.length === 2) {
+ return value >= Math.min(...range) && value <= Math.max(...range);
+ }
+ throw new TypeError(`Invalid range: ${JSON.stringify(range)}`);
+};
+// eslint-disable-next-line @typescript-eslint/naming-convention
+const NODE_TYPE_ELEMENT = 1;
+// eslint-disable-next-line @typescript-eslint/naming-convention
+const DOM_PROPERTIES_TO_CHECK = [
+ 'innerHTML',
+ 'ownerDocument',
+ 'style',
+ 'attributes',
+ 'nodeValue',
+];
+is.domElement = (value) => is.object(value)
+ && value.nodeType === NODE_TYPE_ELEMENT
+ && is.string(value.nodeName)
+ && !is.plainObject(value)
+ && DOM_PROPERTIES_TO_CHECK.every(property => property in value);
+is.observable = (value) => {
+ if (!value) {
+ return false;
+ }
+ // eslint-disable-next-line no-use-extend-native/no-use-extend-native, @typescript-eslint/no-unsafe-call
+ if (value === value[Symbol.observable]?.()) {
+ return true;
+ }
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
+ if (value === value['@@observable']?.()) {
+ return true;
+ }
+ return false;
+};
+is.nodeStream = (value) => is.object(value) && is.function_(value.pipe) && !is.observable(value);
+is.infinite = (value) => value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY;
+const isAbsoluteMod2 = (remainder) => (value) => is.integer(value) && Math.abs(value % 2) === remainder;
+is.evenInteger = isAbsoluteMod2(0);
+is.oddInteger = isAbsoluteMod2(1);
+is.emptyArray = (value) => is.array(value) && value.length === 0;
+is.nonEmptyArray = (value) => is.array(value) && value.length > 0;
+is.emptyString = (value) => is.string(value) && value.length === 0;
+const isWhiteSpaceString = (value) => is.string(value) && !/\S/.test(value);
+is.emptyStringOrWhitespace = (value) => is.emptyString(value) || isWhiteSpaceString(value);
+// TODO: Use `not ''` when the `not` operator is available.
+is.nonEmptyString = (value) => is.string(value) && value.length > 0;
+// TODO: Use `not ''` when the `not` operator is available.
+is.nonEmptyStringAndNotWhitespace = (value) => is.string(value) && !is.emptyStringOrWhitespace(value);
+// eslint-disable-next-line unicorn/no-array-callback-reference
+is.emptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length === 0;
+// TODO: Use `not` operator here to remove `Map` and `Set` from type guard:
+// - https://github.com/Microsoft/TypeScript/pull/29317
+// eslint-disable-next-line unicorn/no-array-callback-reference
+is.nonEmptyObject = (value) => is.object(value) && !is.map(value) && !is.set(value) && Object.keys(value).length > 0;
+is.emptySet = (value) => is.set(value) && value.size === 0;
+is.nonEmptySet = (value) => is.set(value) && value.size > 0;
+// eslint-disable-next-line unicorn/no-array-callback-reference
+is.emptyMap = (value) => is.map(value) && value.size === 0;
+// eslint-disable-next-line unicorn/no-array-callback-reference
+is.nonEmptyMap = (value) => is.map(value) && value.size > 0;
+// `PropertyKey` is any value that can be used as an object key (string, number, or symbol)
+is.propertyKey = (value) => is.any([is.string, is.number, is.symbol], value);
+is.formData = (value) => isObjectOfType('FormData')(value);
+is.urlSearchParams = (value) => isObjectOfType('URLSearchParams')(value);
+const predicateOnArray = (method, predicate, values) => {
+ if (!is.function_(predicate)) {
+ throw new TypeError(`Invalid predicate: ${JSON.stringify(predicate)}`);
+ }
+ if (values.length === 0) {
+ throw new TypeError('Invalid number of values');
+ }
+ return method.call(values, predicate);
+};
+is.any = (predicate, ...values) => {
+ const predicates = is.array(predicate) ? predicate : [predicate];
+ return predicates.some(singlePredicate => predicateOnArray(Array.prototype.some, singlePredicate, values));
+};
+is.all = (predicate, ...values) => predicateOnArray(Array.prototype.every, predicate, values);
+const assertType = (condition, description, value, options = {}) => {
+ if (!condition) {
+ const { multipleValues } = options;
+ const valuesMessage = multipleValues
+ ? `received values of types ${[
+ ...new Set(value.map(singleValue => `\`${is(singleValue)}\``)),
+ ].join(', ')}`
+ : `received value of type \`${is(value)}\``;
+ throw new TypeError(`Expected value which is \`${description}\`, ${valuesMessage}.`);
+ }
+};
+/* eslint-disable @typescript-eslint/no-confusing-void-expression */
+const assert = {
+ // Unknowns.
+ undefined: (value) => assertType(is.undefined(value), 'undefined', value),
+ string: (value) => assertType(is.string(value), 'string', value),
+ number: (value) => assertType(is.number(value), 'number', value),
+ positiveNumber: (value) => assertType(is.positiveNumber(value), "positive number" /* AssertionTypeDescription.positiveNumber */, value),
+ negativeNumber: (value) => assertType(is.negativeNumber(value), "negative number" /* AssertionTypeDescription.negativeNumber */, value),
+ bigint: (value) => assertType(is.bigint(value), 'bigint', value),
+ // eslint-disable-next-line @typescript-eslint/ban-types
+ function_: (value) => assertType(is.function_(value), 'Function', value),
+ null_: (value) => assertType(is.null_(value), 'null', value),
+ class_: (value) => assertType(is.class_(value), "Class" /* AssertionTypeDescription.class_ */, value),
+ boolean: (value) => assertType(is.boolean(value), 'boolean', value),
+ symbol: (value) => assertType(is.symbol(value), 'symbol', value),
+ numericString: (value) => assertType(is.numericString(value), "string with a number" /* AssertionTypeDescription.numericString */, value),
+ array: (value, assertion) => {
+ const assert = assertType;
+ assert(is.array(value), 'Array', value);
+ if (assertion) {
+ // eslint-disable-next-line unicorn/no-array-for-each, unicorn/no-array-callback-reference
+ value.forEach(assertion);
+ }
+ },
+ buffer: (value) => assertType(is.buffer(value), 'Buffer', value),
+ blob: (value) => assertType(is.blob(value), 'Blob', value),
+ nullOrUndefined: (value) => assertType(is.nullOrUndefined(value), "null or undefined" /* AssertionTypeDescription.nullOrUndefined */, value),
+ object: (value) => assertType(is.object(value), 'Object', value),
+ iterable: (value) => assertType(is.iterable(value), "Iterable" /* AssertionTypeDescription.iterable */, value),
+ asyncIterable: (value) => assertType(is.asyncIterable(value), "AsyncIterable" /* AssertionTypeDescription.asyncIterable */, value),
+ generator: (value) => assertType(is.generator(value), 'Generator', value),
+ asyncGenerator: (value) => assertType(is.asyncGenerator(value), 'AsyncGenerator', value),
+ nativePromise: (value) => assertType(is.nativePromise(value), "native Promise" /* AssertionTypeDescription.nativePromise */, value),
+ promise: (value) => assertType(is.promise(value), 'Promise', value),
+ generatorFunction: (value) => assertType(is.generatorFunction(value), 'GeneratorFunction', value),
+ asyncGeneratorFunction: (value) => assertType(is.asyncGeneratorFunction(value), 'AsyncGeneratorFunction', value),
+ // eslint-disable-next-line @typescript-eslint/ban-types
+ asyncFunction: (value) => assertType(is.asyncFunction(value), 'AsyncFunction', value),
+ // eslint-disable-next-line @typescript-eslint/ban-types
+ boundFunction: (value) => assertType(is.boundFunction(value), 'Function', value),
+ regExp: (value) => assertType(is.regExp(value), 'RegExp', value),
+ date: (value) => assertType(is.date(value), 'Date', value),
+ error: (value) => assertType(is.error(value), 'Error', value),
+ map: (value) => assertType(is.map(value), 'Map', value),
+ set: (value) => assertType(is.set(value), 'Set', value),
+ weakMap: (value) => assertType(is.weakMap(value), 'WeakMap', value),
+ weakSet: (value) => assertType(is.weakSet(value), 'WeakSet', value),
+ weakRef: (value) => assertType(is.weakRef(value), 'WeakRef', value),
+ int8Array: (value) => assertType(is.int8Array(value), 'Int8Array', value),
+ uint8Array: (value) => assertType(is.uint8Array(value), 'Uint8Array', value),
+ uint8ClampedArray: (value) => assertType(is.uint8ClampedArray(value), 'Uint8ClampedArray', value),
+ int16Array: (value) => assertType(is.int16Array(value), 'Int16Array', value),
+ uint16Array: (value) => assertType(is.uint16Array(value), 'Uint16Array', value),
+ int32Array: (value) => assertType(is.int32Array(value), 'Int32Array', value),
+ uint32Array: (value) => assertType(is.uint32Array(value), 'Uint32Array', value),
+ float32Array: (value) => assertType(is.float32Array(value), 'Float32Array', value),
+ float64Array: (value) => assertType(is.float64Array(value), 'Float64Array', value),
+ bigInt64Array: (value) => assertType(is.bigInt64Array(value), 'BigInt64Array', value),
+ bigUint64Array: (value) => assertType(is.bigUint64Array(value), 'BigUint64Array', value),
+ arrayBuffer: (value) => assertType(is.arrayBuffer(value), 'ArrayBuffer', value),
+ sharedArrayBuffer: (value) => assertType(is.sharedArrayBuffer(value), 'SharedArrayBuffer', value),
+ dataView: (value) => assertType(is.dataView(value), 'DataView', value),
+ enumCase: (value, targetEnum) => assertType(is.enumCase(value, targetEnum), 'EnumCase', value),
+ urlInstance: (value) => assertType(is.urlInstance(value), 'URL', value),
+ urlString: (value) => assertType(is.urlString(value), "string with a URL" /* AssertionTypeDescription.urlString */, value),
+ truthy: (value) => assertType(is.truthy(value), "truthy" /* AssertionTypeDescription.truthy */, value),
+ falsy: (value) => assertType(is.falsy(value), "falsy" /* AssertionTypeDescription.falsy */, value),
+ nan: (value) => assertType(is.nan(value), "NaN" /* AssertionTypeDescription.nan */, value),
+ primitive: (value) => assertType(is.primitive(value), "primitive" /* AssertionTypeDescription.primitive */, value),
+ integer: (value) => assertType(is.integer(value), "integer" /* AssertionTypeDescription.integer */, value),
+ safeInteger: (value) => assertType(is.safeInteger(value), "integer" /* AssertionTypeDescription.safeInteger */, value),
+ plainObject: (value) => assertType(is.plainObject(value), "plain object" /* AssertionTypeDescription.plainObject */, value),
+ typedArray: (value) => assertType(is.typedArray(value), "TypedArray" /* AssertionTypeDescription.typedArray */, value),
+ arrayLike: (value) => assertType(is.arrayLike(value), "array-like" /* AssertionTypeDescription.arrayLike */, value),
+ tupleLike: (value, guards) => assertType(is.tupleLike(value, guards), "tuple-like" /* AssertionTypeDescription.tupleLike */, value),
+ domElement: (value) => assertType(is.domElement(value), "HTMLElement" /* AssertionTypeDescription.domElement */, value),
+ observable: (value) => assertType(is.observable(value), 'Observable', value),
+ nodeStream: (value) => assertType(is.nodeStream(value), "Node.js Stream" /* AssertionTypeDescription.nodeStream */, value),
+ infinite: (value) => assertType(is.infinite(value), "infinite number" /* AssertionTypeDescription.infinite */, value),
+ emptyArray: (value) => assertType(is.emptyArray(value), "empty array" /* AssertionTypeDescription.emptyArray */, value),
+ nonEmptyArray: (value) => assertType(is.nonEmptyArray(value), "non-empty array" /* AssertionTypeDescription.nonEmptyArray */, value),
+ emptyString: (value) => assertType(is.emptyString(value), "empty string" /* AssertionTypeDescription.emptyString */, value),
+ emptyStringOrWhitespace: (value) => assertType(is.emptyStringOrWhitespace(value), "empty string or whitespace" /* AssertionTypeDescription.emptyStringOrWhitespace */, value),
+ nonEmptyString: (value) => assertType(is.nonEmptyString(value), "non-empty string" /* AssertionTypeDescription.nonEmptyString */, value),
+ nonEmptyStringAndNotWhitespace: (value) => assertType(is.nonEmptyStringAndNotWhitespace(value), "non-empty string and not whitespace" /* AssertionTypeDescription.nonEmptyStringAndNotWhitespace */, value),
+ emptyObject: (value) => assertType(is.emptyObject(value), "empty object" /* AssertionTypeDescription.emptyObject */, value),
+ nonEmptyObject: (value) => assertType(is.nonEmptyObject(value), "non-empty object" /* AssertionTypeDescription.nonEmptyObject */, value),
+ emptySet: (value) => assertType(is.emptySet(value), "empty set" /* AssertionTypeDescription.emptySet */, value),
+ nonEmptySet: (value) => assertType(is.nonEmptySet(value), "non-empty set" /* AssertionTypeDescription.nonEmptySet */, value),
+ emptyMap: (value) => assertType(is.emptyMap(value), "empty map" /* AssertionTypeDescription.emptyMap */, value),
+ nonEmptyMap: (value) => assertType(is.nonEmptyMap(value), "non-empty map" /* AssertionTypeDescription.nonEmptyMap */, value),
+ propertyKey: (value) => assertType(is.propertyKey(value), 'PropertyKey', value),
+ formData: (value) => assertType(is.formData(value), 'FormData', value),
+ urlSearchParams: (value) => assertType(is.urlSearchParams(value), 'URLSearchParams', value),
+ // Numbers.
+ evenInteger: (value) => assertType(is.evenInteger(value), "even integer" /* AssertionTypeDescription.evenInteger */, value),
+ oddInteger: (value) => assertType(is.oddInteger(value), "odd integer" /* AssertionTypeDescription.oddInteger */, value),
+ // Two arguments.
+ directInstanceOf: (instance, class_) => assertType(is.directInstanceOf(instance, class_), "T" /* AssertionTypeDescription.directInstanceOf */, instance),
+ inRange: (value, range) => assertType(is.inRange(value, range), "in range" /* AssertionTypeDescription.inRange */, value),
+ // Variadic functions.
+ any: (predicate, ...values) => assertType(is.any(predicate, ...values), "predicate returns truthy for any value" /* AssertionTypeDescription.any */, values, { multipleValues: true }),
+ all: (predicate, ...values) => assertType(is.all(predicate, ...values), "predicate returns truthy for all values" /* AssertionTypeDescription.all */, values, { multipleValues: true }),
+};
+/* eslint-enable @typescript-eslint/no-confusing-void-expression */
+// Some few keywords are reserved, but we'll populate them for Node.js users
+// See https://github.com/Microsoft/TypeScript/issues/2536
+Object.defineProperties(is, {
+ class: {
+ value: is.class_,
+ },
+ function: {
+ value: is.function_,
+ },
+ null: {
+ value: is.null_,
+ },
+});
+Object.defineProperties(assert, {
+ class: {
+ value: assert.class_,
+ },
+ function: {
+ value: assert.function_,
+ },
+ null: {
+ value: assert.null_,
+ },
+});
+/* harmony default export */ const dist = (is);
+
+;// CONCATENATED MODULE: external "node:events"
+const external_node_events_namespaceObject = require("node:events");
+;// CONCATENATED MODULE: ./node_modules/p-cancelable/index.js
+class CancelError extends Error {
+ constructor(reason) {
+ super(reason || 'Promise was canceled');
+ this.name = 'CancelError';
+ }
+
+ get isCanceled() {
+ return true;
+ }
+}
+
+// TODO: Use private class fields when ESLint 8 is out.
+
+class PCancelable {
+ static fn(userFunction) {
+ return (...arguments_) => {
+ return new PCancelable((resolve, reject, onCancel) => {
+ arguments_.push(onCancel);
+ // eslint-disable-next-line promise/prefer-await-to-then
+ userFunction(...arguments_).then(resolve, reject);
+ });
+ };
+ }
+
+ constructor(executor) {
+ this._cancelHandlers = [];
+ this._isPending = true;
+ this._isCanceled = false;
+ this._rejectOnCancel = true;
+
+ this._promise = new Promise((resolve, reject) => {
+ this._reject = reject;
+
+ const onResolve = value => {
+ if (!this._isCanceled || !onCancel.shouldReject) {
+ this._isPending = false;
+ resolve(value);
+ }
+ };
+
+ const onReject = error => {
+ this._isPending = false;
+ reject(error);
+ };
+
+ const onCancel = handler => {
+ if (!this._isPending) {
+ throw new Error('The `onCancel` handler was attached after the promise settled.');
+ }
+
+ this._cancelHandlers.push(handler);
+ };
+
+ Object.defineProperties(onCancel, {
+ shouldReject: {
+ get: () => this._rejectOnCancel,
+ set: boolean => {
+ this._rejectOnCancel = boolean;
+ }
+ }
+ });
+
+ executor(onResolve, onReject, onCancel);
+ });
+ }
+
+ then(onFulfilled, onRejected) {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ return this._promise.then(onFulfilled, onRejected);
+ }
+
+ catch(onRejected) {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ return this._promise.catch(onRejected);
+ }
+
+ finally(onFinally) {
+ // eslint-disable-next-line promise/prefer-await-to-then
+ return this._promise.finally(onFinally);
+ }
+
+ cancel(reason) {
+ if (!this._isPending || this._isCanceled) {
+ return;
+ }
+
+ this._isCanceled = true;
+
+ if (this._cancelHandlers.length > 0) {
+ try {
+ for (const handler of this._cancelHandlers) {
+ handler();
+ }
+ } catch (error) {
+ this._reject(error);
+ return;
+ }
+ }
+
+ if (this._rejectOnCancel) {
+ this._reject(new CancelError(reason));
+ }
+ }
+
+ get isCanceled() {
+ return this._isCanceled;
+ }
+}
+
+Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/errors.js
+
+// A hacky check to prevent circular references.
+function isRequest(x) {
+ return dist.object(x) && '_onResponse' in x;
+}
+/**
+An error to be thrown when a request fails.
+Contains a `code` property with error class code, like `ECONNREFUSED`.
+*/
+class RequestError extends Error {
+ constructor(message, error, self) {
+ super(message);
+ Object.defineProperty(this, "input", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "code", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "stack", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "response", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "request", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "timings", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Error.captureStackTrace(this, this.constructor);
+ this.name = 'RequestError';
+ this.code = error.code ?? 'ERR_GOT_REQUEST_ERROR';
+ this.input = error.input;
+ if (isRequest(self)) {
+ Object.defineProperty(this, 'request', {
+ enumerable: false,
+ value: self,
+ });
+ Object.defineProperty(this, 'response', {
+ enumerable: false,
+ value: self.response,
+ });
+ this.options = self.options;
+ }
+ else {
+ this.options = self;
+ }
+ this.timings = this.request?.timings;
+ // Recover the original stacktrace
+ if (dist.string(error.stack) && dist.string(this.stack)) {
+ const indexOfMessage = this.stack.indexOf(this.message) + this.message.length;
+ const thisStackTrace = this.stack.slice(indexOfMessage).split('\n').reverse();
+ const errorStackTrace = error.stack.slice(error.stack.indexOf(error.message) + error.message.length).split('\n').reverse();
+ // Remove duplicated traces
+ while (errorStackTrace.length > 0 && errorStackTrace[0] === thisStackTrace[0]) {
+ thisStackTrace.shift();
+ }
+ this.stack = `${this.stack.slice(0, indexOfMessage)}${thisStackTrace.reverse().join('\n')}${errorStackTrace.reverse().join('\n')}`;
+ }
+ }
+}
+/**
+An error to be thrown when the server redirects you more than ten times.
+Includes a `response` property.
+*/
+class MaxRedirectsError extends RequestError {
+ constructor(request) {
+ super(`Redirected ${request.options.maxRedirects} times. Aborting.`, {}, request);
+ this.name = 'MaxRedirectsError';
+ this.code = 'ERR_TOO_MANY_REDIRECTS';
+ }
+}
+/**
+An error to be thrown when the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304.
+Includes a `response` property.
+*/
+// eslint-disable-next-line @typescript-eslint/naming-convention
+class HTTPError extends RequestError {
+ constructor(response) {
+ super(`Response code ${response.statusCode} (${response.statusMessage})`, {}, response.request);
+ this.name = 'HTTPError';
+ this.code = 'ERR_NON_2XX_3XX_RESPONSE';
+ }
+}
+/**
+An error to be thrown when a cache method fails.
+For example, if the database goes down or there's a filesystem error.
+*/
+class CacheError extends RequestError {
+ constructor(error, request) {
+ super(error.message, error, request);
+ this.name = 'CacheError';
+ this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_CACHE_ACCESS' : this.code;
+ }
+}
+/**
+An error to be thrown when the request body is a stream and an error occurs while reading from that stream.
+*/
+class UploadError extends RequestError {
+ constructor(error, request) {
+ super(error.message, error, request);
+ this.name = 'UploadError';
+ this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_UPLOAD' : this.code;
+ }
+}
+/**
+An error to be thrown when the request is aborted due to a timeout.
+Includes an `event` and `timings` property.
+*/
+class TimeoutError extends RequestError {
+ constructor(error, timings, request) {
+ super(error.message, error, request);
+ Object.defineProperty(this, "timings", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "event", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ this.name = 'TimeoutError';
+ this.event = error.event;
+ this.timings = timings;
+ }
+}
+/**
+An error to be thrown when reading from response stream fails.
+*/
+class ReadError extends RequestError {
+ constructor(error, request) {
+ super(error.message, error, request);
+ this.name = 'ReadError';
+ this.code = this.code === 'ERR_GOT_REQUEST_ERROR' ? 'ERR_READING_RESPONSE_STREAM' : this.code;
+ }
+}
+/**
+An error which always triggers a new retry when thrown.
+*/
+class RetryError extends RequestError {
+ constructor(request) {
+ super('Retrying', {}, request);
+ this.name = 'RetryError';
+ this.code = 'ERR_RETRYING';
+ }
+}
+/**
+An error to be thrown when the request is aborted by AbortController.
+*/
+class AbortError extends RequestError {
+ constructor(request) {
+ super('This operation was aborted.', {}, request);
+ this.code = 'ERR_ABORTED';
+ this.name = 'AbortError';
+ }
+}
+
+;// CONCATENATED MODULE: external "node:process"
+const external_node_process_namespaceObject = require("node:process");
+;// CONCATENATED MODULE: external "node:buffer"
+const external_node_buffer_namespaceObject = require("node:buffer");
+;// CONCATENATED MODULE: external "node:stream"
+const external_node_stream_namespaceObject = require("node:stream");
+;// CONCATENATED MODULE: external "node:url"
+const external_node_url_namespaceObject = require("node:url");
+;// CONCATENATED MODULE: external "node:http"
+const external_node_http_namespaceObject = require("node:http");
+// EXTERNAL MODULE: external "events"
+var external_events_ = __nccwpck_require__(2361);
+// EXTERNAL MODULE: external "util"
+var external_util_ = __nccwpck_require__(3837);
+// EXTERNAL MODULE: ./node_modules/defer-to-connect/dist/source/index.js
+var source = __nccwpck_require__(6214);
+;// CONCATENATED MODULE: ./node_modules/@szmarczak/http-timer/dist/source/index.js
+
+
+
+const timer = (request) => {
+ if (request.timings) {
+ return request.timings;
+ }
+ const timings = {
+ start: Date.now(),
+ socket: undefined,
+ lookup: undefined,
+ connect: undefined,
+ secureConnect: undefined,
+ upload: undefined,
+ response: undefined,
+ end: undefined,
+ error: undefined,
+ abort: undefined,
+ phases: {
+ wait: undefined,
+ dns: undefined,
+ tcp: undefined,
+ tls: undefined,
+ request: undefined,
+ firstByte: undefined,
+ download: undefined,
+ total: undefined,
+ },
+ };
+ request.timings = timings;
+ const handleError = (origin) => {
+ origin.once(external_events_.errorMonitor, () => {
+ timings.error = Date.now();
+ timings.phases.total = timings.error - timings.start;
+ });
+ };
+ handleError(request);
+ const onAbort = () => {
+ timings.abort = Date.now();
+ timings.phases.total = timings.abort - timings.start;
+ };
+ request.prependOnceListener('abort', onAbort);
+ const onSocket = (socket) => {
+ timings.socket = Date.now();
+ timings.phases.wait = timings.socket - timings.start;
+ if (external_util_.types.isProxy(socket)) {
+ return;
+ }
+ const lookupListener = () => {
+ timings.lookup = Date.now();
+ timings.phases.dns = timings.lookup - timings.socket;
+ };
+ socket.prependOnceListener('lookup', lookupListener);
+ source(socket, {
+ connect: () => {
+ timings.connect = Date.now();
+ if (timings.lookup === undefined) {
+ socket.removeListener('lookup', lookupListener);
+ timings.lookup = timings.connect;
+ timings.phases.dns = timings.lookup - timings.socket;
+ }
+ timings.phases.tcp = timings.connect - timings.lookup;
+ },
+ secureConnect: () => {
+ timings.secureConnect = Date.now();
+ timings.phases.tls = timings.secureConnect - timings.connect;
+ },
+ });
+ };
+ if (request.socket) {
+ onSocket(request.socket);
+ }
+ else {
+ request.prependOnceListener('socket', onSocket);
+ }
+ const onUpload = () => {
+ timings.upload = Date.now();
+ timings.phases.request = timings.upload - (timings.secureConnect ?? timings.connect);
+ };
+ if (request.writableFinished) {
+ onUpload();
+ }
+ else {
+ request.prependOnceListener('finish', onUpload);
+ }
+ request.prependOnceListener('response', (response) => {
+ timings.response = Date.now();
+ timings.phases.firstByte = timings.response - timings.upload;
+ response.timings = timings;
+ handleError(response);
+ response.prependOnceListener('end', () => {
+ request.off('abort', onAbort);
+ response.off('aborted', onAbort);
+ if (timings.phases.total) {
+ // Aborted or errored
+ return;
+ }
+ timings.end = Date.now();
+ timings.phases.download = timings.end - timings.response;
+ timings.phases.total = timings.end - timings.start;
+ });
+ response.prependOnceListener('aborted', onAbort);
+ });
+ return timings;
+};
+/* harmony default export */ const dist_source = (timer);
+
+;// CONCATENATED MODULE: external "node:crypto"
+const external_node_crypto_namespaceObject = require("node:crypto");
+;// CONCATENATED MODULE: ./node_modules/normalize-url/index.js
+// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
+const DATA_URL_DEFAULT_MIME_TYPE = 'text/plain';
+const DATA_URL_DEFAULT_CHARSET = 'us-ascii';
+
+const testParameter = (name, filters) => filters.some(filter => filter instanceof RegExp ? filter.test(name) : filter === name);
+
+const supportedProtocols = new Set([
+ 'https:',
+ 'http:',
+ 'file:',
+]);
+
+const hasCustomProtocol = urlString => {
+ try {
+ const {protocol} = new URL(urlString);
+ return protocol.endsWith(':') && !supportedProtocols.has(protocol);
+ } catch {
+ return false;
+ }
+};
+
+const normalizeDataURL = (urlString, {stripHash}) => {
+ const match = /^data:(?[^,]*?),(?[^#]*?)(?:#(?.*))?$/.exec(urlString);
+
+ if (!match) {
+ throw new Error(`Invalid URL: ${urlString}`);
+ }
+
+ let {type, data, hash} = match.groups;
+ const mediaType = type.split(';');
+ hash = stripHash ? '' : hash;
+
+ let isBase64 = false;
+ if (mediaType[mediaType.length - 1] === 'base64') {
+ mediaType.pop();
+ isBase64 = true;
+ }
+
+ // Lowercase MIME type
+ const mimeType = mediaType.shift()?.toLowerCase() ?? '';
+ const attributes = mediaType
+ .map(attribute => {
+ let [key, value = ''] = attribute.split('=').map(string => string.trim());
+
+ // Lowercase `charset`
+ if (key === 'charset') {
+ value = value.toLowerCase();
+
+ if (value === DATA_URL_DEFAULT_CHARSET) {
+ return '';
+ }
+ }
+
+ return `${key}${value ? `=${value}` : ''}`;
+ })
+ .filter(Boolean);
+
+ const normalizedMediaType = [
+ ...attributes,
+ ];
+
+ if (isBase64) {
+ normalizedMediaType.push('base64');
+ }
+
+ if (normalizedMediaType.length > 0 || (mimeType && mimeType !== DATA_URL_DEFAULT_MIME_TYPE)) {
+ normalizedMediaType.unshift(mimeType);
+ }
+
+ return `data:${normalizedMediaType.join(';')},${isBase64 ? data.trim() : data}${hash ? `#${hash}` : ''}`;
+};
+
+function normalizeUrl(urlString, options) {
+ options = {
+ defaultProtocol: 'http',
+ normalizeProtocol: true,
+ forceHttp: false,
+ forceHttps: false,
+ stripAuthentication: true,
+ stripHash: false,
+ stripTextFragment: true,
+ stripWWW: true,
+ removeQueryParameters: [/^utm_\w+/i],
+ removeTrailingSlash: true,
+ removeSingleSlash: true,
+ removeDirectoryIndex: false,
+ removeExplicitPort: false,
+ sortQueryParameters: true,
+ ...options,
+ };
+
+ // Legacy: Append `:` to the protocol if missing.
+ if (typeof options.defaultProtocol === 'string' && !options.defaultProtocol.endsWith(':')) {
+ options.defaultProtocol = `${options.defaultProtocol}:`;
+ }
+
+ urlString = urlString.trim();
+
+ // Data URL
+ if (/^data:/i.test(urlString)) {
+ return normalizeDataURL(urlString, options);
+ }
+
+ if (hasCustomProtocol(urlString)) {
+ return urlString;
+ }
+
+ const hasRelativeProtocol = urlString.startsWith('//');
+ const isRelativeUrl = !hasRelativeProtocol && /^\.*\//.test(urlString);
+
+ // Prepend protocol
+ if (!isRelativeUrl) {
+ urlString = urlString.replace(/^(?!(?:\w+:)?\/\/)|^\/\//, options.defaultProtocol);
+ }
+
+ const urlObject = new URL(urlString);
+
+ if (options.forceHttp && options.forceHttps) {
+ throw new Error('The `forceHttp` and `forceHttps` options cannot be used together');
+ }
+
+ if (options.forceHttp && urlObject.protocol === 'https:') {
+ urlObject.protocol = 'http:';
+ }
+
+ if (options.forceHttps && urlObject.protocol === 'http:') {
+ urlObject.protocol = 'https:';
+ }
+
+ // Remove auth
+ if (options.stripAuthentication) {
+ urlObject.username = '';
+ urlObject.password = '';
+ }
+
+ // Remove hash
+ if (options.stripHash) {
+ urlObject.hash = '';
+ } else if (options.stripTextFragment) {
+ urlObject.hash = urlObject.hash.replace(/#?:~:text.*?$/i, '');
+ }
+
+ // Remove duplicate slashes if not preceded by a protocol
+ // NOTE: This could be implemented using a single negative lookbehind
+ // regex, but we avoid that to maintain compatibility with older js engines
+ // which do not have support for that feature.
+ if (urlObject.pathname) {
+ // TODO: Replace everything below with `urlObject.pathname = urlObject.pathname.replace(/(? 0) {
+ let pathComponents = urlObject.pathname.split('/');
+ const lastComponent = pathComponents[pathComponents.length - 1];
+
+ if (testParameter(lastComponent, options.removeDirectoryIndex)) {
+ pathComponents = pathComponents.slice(0, -1);
+ urlObject.pathname = pathComponents.slice(1).join('/') + '/';
+ }
+ }
+
+ if (urlObject.hostname) {
+ // Remove trailing dot
+ urlObject.hostname = urlObject.hostname.replace(/\.$/, '');
+
+ // Remove `www.`
+ if (options.stripWWW && /^www\.(?!www\.)[a-z\-\d]{1,63}\.[a-z.\-\d]{2,63}$/.test(urlObject.hostname)) {
+ // Each label should be max 63 at length (min: 1).
+ // Source: https://en.wikipedia.org/wiki/Hostname#Restrictions_on_valid_host_names
+ // Each TLD should be up to 63 characters long (min: 2).
+ // It is technically possible to have a single character TLD, but none currently exist.
+ urlObject.hostname = urlObject.hostname.replace(/^www\./, '');
+ }
+ }
+
+ // Remove query unwanted parameters
+ if (Array.isArray(options.removeQueryParameters)) {
+ // eslint-disable-next-line unicorn/no-useless-spread -- We are intentionally spreading to get a copy.
+ for (const key of [...urlObject.searchParams.keys()]) {
+ if (testParameter(key, options.removeQueryParameters)) {
+ urlObject.searchParams.delete(key);
+ }
+ }
+ }
+
+ if (!Array.isArray(options.keepQueryParameters) && options.removeQueryParameters === true) {
+ urlObject.search = '';
+ }
+
+ // Keep wanted query parameters
+ if (Array.isArray(options.keepQueryParameters) && options.keepQueryParameters.length > 0) {
+ // eslint-disable-next-line unicorn/no-useless-spread -- We are intentionally spreading to get a copy.
+ for (const key of [...urlObject.searchParams.keys()]) {
+ if (!testParameter(key, options.keepQueryParameters)) {
+ urlObject.searchParams.delete(key);
+ }
+ }
+ }
+
+ // Sort query parameters
+ if (options.sortQueryParameters) {
+ urlObject.searchParams.sort();
+
+ // Calling `.sort()` encodes the search parameters, so we need to decode them again.
+ try {
+ urlObject.search = decodeURIComponent(urlObject.search);
+ } catch {}
+ }
+
+ if (options.removeTrailingSlash) {
+ urlObject.pathname = urlObject.pathname.replace(/\/$/, '');
+ }
+
+ // Remove an explicit port number, excluding a default port number, if applicable
+ if (options.removeExplicitPort && urlObject.port) {
+ urlObject.port = '';
+ }
+
+ const oldUrlString = urlString;
+
+ // Take advantage of many of the Node `url` normalizations
+ urlString = urlObject.toString();
+
+ if (!options.removeSingleSlash && urlObject.pathname === '/' && !oldUrlString.endsWith('/') && urlObject.hash === '') {
+ urlString = urlString.replace(/\/$/, '');
+ }
+
+ // Remove ending `/` unless removeSingleSlash is false
+ if ((options.removeTrailingSlash || urlObject.pathname === '/') && urlObject.hash === '' && options.removeSingleSlash) {
+ urlString = urlString.replace(/\/$/, '');
+ }
+
+ // Restore relative protocol, if applicable
+ if (hasRelativeProtocol && !options.normalizeProtocol) {
+ urlString = urlString.replace(/^http:\/\//, '//');
+ }
+
+ // Remove http/https
+ if (options.stripProtocol) {
+ urlString = urlString.replace(/^(?:https?:)?\/\//, '');
+ }
+
+ return urlString;
+}
+
+// EXTERNAL MODULE: ./node_modules/get-stream/index.js
+var get_stream = __nccwpck_require__(1766);
+// EXTERNAL MODULE: ./node_modules/http-cache-semantics/index.js
+var http_cache_semantics = __nccwpck_require__(1002);
+;// CONCATENATED MODULE: ./node_modules/lowercase-keys/index.js
+function lowercaseKeys(object) {
+ return Object.fromEntries(Object.entries(object).map(([key, value]) => [key.toLowerCase(), value]));
+}
+
+;// CONCATENATED MODULE: ./node_modules/responselike/index.js
+
+
+
+class Response extends external_node_stream_namespaceObject.Readable {
+ statusCode;
+ headers;
+ body;
+ url;
+
+ constructor({statusCode, headers, body, url}) {
+ if (typeof statusCode !== 'number') {
+ throw new TypeError('Argument `statusCode` should be a number');
+ }
+
+ if (typeof headers !== 'object') {
+ throw new TypeError('Argument `headers` should be an object');
+ }
+
+ if (!(body instanceof Uint8Array)) {
+ throw new TypeError('Argument `body` should be a buffer');
+ }
+
+ if (typeof url !== 'string') {
+ throw new TypeError('Argument `url` should be a string');
+ }
+
+ super({
+ read() {
+ this.push(body);
+ this.push(null);
+ },
+ });
+
+ this.statusCode = statusCode;
+ this.headers = lowercaseKeys(headers);
+ this.body = body;
+ this.url = url;
+ }
+}
+
+// EXTERNAL MODULE: ./node_modules/keyv/src/index.js
+var src = __nccwpck_require__(1531);
+;// CONCATENATED MODULE: ./node_modules/mimic-response/index.js
+// We define these manually to ensure they're always copied
+// even if they would move up the prototype chain
+// https://nodejs.org/api/http.html#http_class_http_incomingmessage
+const knownProperties = [
+ 'aborted',
+ 'complete',
+ 'headers',
+ 'httpVersion',
+ 'httpVersionMinor',
+ 'httpVersionMajor',
+ 'method',
+ 'rawHeaders',
+ 'rawTrailers',
+ 'setTimeout',
+ 'socket',
+ 'statusCode',
+ 'statusMessage',
+ 'trailers',
+ 'url',
+];
+
+function mimicResponse(fromStream, toStream) {
+ if (toStream._readableState.autoDestroy) {
+ throw new Error('The second stream must have the `autoDestroy` option set to `false`');
+ }
+
+ const fromProperties = new Set([...Object.keys(fromStream), ...knownProperties]);
+
+ const properties = {};
+
+ for (const property of fromProperties) {
+ // Don't overwrite existing properties.
+ if (property in toStream) {
+ continue;
+ }
+
+ properties[property] = {
+ get() {
+ const value = fromStream[property];
+ const isFunction = typeof value === 'function';
+
+ return isFunction ? value.bind(fromStream) : value;
+ },
+ set(value) {
+ fromStream[property] = value;
+ },
+ enumerable: true,
+ configurable: false,
+ };
+ }
+
+ Object.defineProperties(toStream, properties);
+
+ fromStream.once('aborted', () => {
+ toStream.destroy();
+
+ toStream.emit('aborted');
+ });
+
+ fromStream.once('close', () => {
+ if (fromStream.complete) {
+ if (toStream.readable) {
+ toStream.once('end', () => {
+ toStream.emit('close');
+ });
+ } else {
+ toStream.emit('close');
+ }
+ } else {
+ toStream.emit('close');
+ }
+ });
+
+ return toStream;
+}
+
+;// CONCATENATED MODULE: ./node_modules/cacheable-request/dist/types.js
+// Type definitions for cacheable-request 6.0
+// Project: https://github.com/lukechilds/cacheable-request#readme
+// Definitions by: BendingBender
+// Paul Melnikow
+// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
+// TypeScript Version: 2.3
+class types_RequestError extends Error {
+ constructor(error) {
+ super(error.message);
+ Object.assign(this, error);
+ }
+}
+class types_CacheError extends Error {
+ constructor(error) {
+ super(error.message);
+ Object.assign(this, error);
+ }
+}
+//# sourceMappingURL=types.js.map
+;// CONCATENATED MODULE: ./node_modules/cacheable-request/dist/index.js
+
+
+
+
+
+
+
+
+
+
+
+class CacheableRequest {
+ constructor(cacheRequest, cacheAdapter) {
+ this.hooks = new Map();
+ this.request = () => (options, cb) => {
+ let url;
+ if (typeof options === 'string') {
+ url = normalizeUrlObject(external_node_url_namespaceObject.parse(options));
+ options = {};
+ }
+ else if (options instanceof external_node_url_namespaceObject.URL) {
+ url = normalizeUrlObject(external_node_url_namespaceObject.parse(options.toString()));
+ options = {};
+ }
+ else {
+ const [pathname, ...searchParts] = (options.path ?? '').split('?');
+ const search = searchParts.length > 0
+ ? `?${searchParts.join('?')}`
+ : '';
+ url = normalizeUrlObject({ ...options, pathname, search });
+ }
+ options = {
+ headers: {},
+ method: 'GET',
+ cache: true,
+ strictTtl: false,
+ automaticFailover: false,
+ ...options,
+ ...urlObjectToRequestOptions(url),
+ };
+ options.headers = Object.fromEntries(entries(options.headers).map(([key, value]) => [key.toLowerCase(), value]));
+ const ee = new external_node_events_namespaceObject();
+ const normalizedUrlString = normalizeUrl(external_node_url_namespaceObject.format(url), {
+ stripWWW: false,
+ removeTrailingSlash: false,
+ stripAuthentication: false,
+ });
+ let key = `${options.method}:${normalizedUrlString}`;
+ // POST, PATCH, and PUT requests may be cached, depending on the response
+ // cache-control headers. As a result, the body of the request should be
+ // added to the cache key in order to avoid collisions.
+ if (options.body && options.method !== undefined && ['POST', 'PATCH', 'PUT'].includes(options.method)) {
+ if (options.body instanceof external_node_stream_namespaceObject.Readable) {
+ // Streamed bodies should completely skip the cache because they may
+ // or may not be hashable and in either case the stream would need to
+ // close before the cache key could be generated.
+ options.cache = false;
+ }
+ else {
+ key += `:${external_node_crypto_namespaceObject.createHash('md5').update(options.body).digest('hex')}`;
+ }
+ }
+ let revalidate = false;
+ let madeRequest = false;
+ const makeRequest = (options_) => {
+ madeRequest = true;
+ let requestErrored = false;
+ let requestErrorCallback = () => { };
+ const requestErrorPromise = new Promise(resolve => {
+ requestErrorCallback = () => {
+ if (!requestErrored) {
+ requestErrored = true;
+ resolve();
+ }
+ };
+ });
+ const handler = async (response) => {
+ if (revalidate) {
+ response.status = response.statusCode;
+ const revalidatedPolicy = http_cache_semantics.fromObject(revalidate.cachePolicy).revalidatedPolicy(options_, response);
+ if (!revalidatedPolicy.modified) {
+ response.resume();
+ await new Promise(resolve => {
+ // Skipping 'error' handler cause 'error' event should't be emitted for 304 response
+ response
+ .once('end', resolve);
+ });
+ const headers = convertHeaders(revalidatedPolicy.policy.responseHeaders());
+ response = new Response({ statusCode: revalidate.statusCode, headers, body: revalidate.body, url: revalidate.url });
+ response.cachePolicy = revalidatedPolicy.policy;
+ response.fromCache = true;
+ }
+ }
+ if (!response.fromCache) {
+ response.cachePolicy = new http_cache_semantics(options_, response, options_);
+ response.fromCache = false;
+ }
+ let clonedResponse;
+ if (options_.cache && response.cachePolicy.storable()) {
+ clonedResponse = cloneResponse(response);
+ (async () => {
+ try {
+ const bodyPromise = get_stream.buffer(response);
+ await Promise.race([
+ requestErrorPromise,
+ new Promise(resolve => response.once('end', resolve)),
+ new Promise(resolve => response.once('close', resolve)), // eslint-disable-line no-promise-executor-return
+ ]);
+ const body = await bodyPromise;
+ let value = {
+ url: response.url,
+ statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
+ body,
+ cachePolicy: response.cachePolicy.toObject(),
+ };
+ let ttl = options_.strictTtl ? response.cachePolicy.timeToLive() : undefined;
+ if (options_.maxTtl) {
+ ttl = ttl ? Math.min(ttl, options_.maxTtl) : options_.maxTtl;
+ }
+ if (this.hooks.size > 0) {
+ /* eslint-disable no-await-in-loop */
+ for (const key_ of this.hooks.keys()) {
+ value = await this.runHook(key_, value, response);
+ }
+ /* eslint-enable no-await-in-loop */
+ }
+ await this.cache.set(key, value, ttl);
+ }
+ catch (error) {
+ ee.emit('error', new types_CacheError(error));
+ }
+ })();
+ }
+ else if (options_.cache && revalidate) {
+ (async () => {
+ try {
+ await this.cache.delete(key);
+ }
+ catch (error) {
+ ee.emit('error', new types_CacheError(error));
+ }
+ })();
+ }
+ ee.emit('response', clonedResponse ?? response);
+ if (typeof cb === 'function') {
+ cb(clonedResponse ?? response);
+ }
+ };
+ try {
+ const request_ = this.cacheRequest(options_, handler);
+ request_.once('error', requestErrorCallback);
+ request_.once('abort', requestErrorCallback);
+ request_.once('destroy', requestErrorCallback);
+ ee.emit('request', request_);
+ }
+ catch (error) {
+ ee.emit('error', new types_RequestError(error));
+ }
+ };
+ (async () => {
+ const get = async (options_) => {
+ await Promise.resolve();
+ const cacheEntry = options_.cache ? await this.cache.get(key) : undefined;
+ if (cacheEntry === undefined && !options_.forceRefresh) {
+ makeRequest(options_);
+ return;
+ }
+ const policy = http_cache_semantics.fromObject(cacheEntry.cachePolicy);
+ if (policy.satisfiesWithoutRevalidation(options_) && !options_.forceRefresh) {
+ const headers = convertHeaders(policy.responseHeaders());
+ const response = new Response({ statusCode: cacheEntry.statusCode, headers, body: cacheEntry.body, url: cacheEntry.url });
+ response.cachePolicy = policy;
+ response.fromCache = true;
+ ee.emit('response', response);
+ if (typeof cb === 'function') {
+ cb(response);
+ }
+ }
+ else if (policy.satisfiesWithoutRevalidation(options_) && Date.now() >= policy.timeToLive() && options_.forceRefresh) {
+ await this.cache.delete(key);
+ options_.headers = policy.revalidationHeaders(options_);
+ makeRequest(options_);
+ }
+ else {
+ revalidate = cacheEntry;
+ options_.headers = policy.revalidationHeaders(options_);
+ makeRequest(options_);
+ }
+ };
+ const errorHandler = (error) => ee.emit('error', new types_CacheError(error));
+ if (this.cache instanceof src) {
+ const cachek = this.cache;
+ cachek.once('error', errorHandler);
+ ee.on('error', () => cachek.removeListener('error', errorHandler));
+ ee.on('response', () => cachek.removeListener('error', errorHandler));
+ }
+ try {
+ await get(options);
+ }
+ catch (error) {
+ if (options.automaticFailover && !madeRequest) {
+ makeRequest(options);
+ }
+ ee.emit('error', new types_CacheError(error));
+ }
+ })();
+ return ee;
+ };
+ this.addHook = (name, fn) => {
+ if (!this.hooks.has(name)) {
+ this.hooks.set(name, fn);
+ }
+ };
+ this.removeHook = (name) => this.hooks.delete(name);
+ this.getHook = (name) => this.hooks.get(name);
+ this.runHook = async (name, ...args) => this.hooks.get(name)?.(...args);
+ if (cacheAdapter instanceof src) {
+ this.cache = cacheAdapter;
+ }
+ else if (typeof cacheAdapter === 'string') {
+ this.cache = new src({
+ uri: cacheAdapter,
+ namespace: 'cacheable-request',
+ });
+ }
+ else {
+ this.cache = new src({
+ store: cacheAdapter,
+ namespace: 'cacheable-request',
+ });
+ }
+ this.request = this.request.bind(this);
+ this.cacheRequest = cacheRequest;
+ }
+}
+const entries = Object.entries;
+const cloneResponse = (response) => {
+ const clone = new external_node_stream_namespaceObject.PassThrough({ autoDestroy: false });
+ mimicResponse(response, clone);
+ return response.pipe(clone);
+};
+const urlObjectToRequestOptions = (url) => {
+ const options = { ...url };
+ options.path = `${url.pathname || '/'}${url.search || ''}`;
+ delete options.pathname;
+ delete options.search;
+ return options;
+};
+const normalizeUrlObject = (url) =>
+// If url was parsed by url.parse or new URL:
+// - hostname will be set
+// - host will be hostname[:port]
+// - port will be set if it was explicit in the parsed string
+// Otherwise, url was from request options:
+// - hostname or host may be set
+// - host shall not have port encoded
+({
+ protocol: url.protocol,
+ auth: url.auth,
+ hostname: url.hostname || url.host || 'localhost',
+ port: url.port,
+ pathname: url.pathname,
+ search: url.search,
+});
+const convertHeaders = (headers) => {
+ const result = [];
+ for (const name of Object.keys(headers)) {
+ result[name.toLowerCase()] = headers[name];
+ }
+ return result;
+};
+/* harmony default export */ const cacheable_request_dist = (CacheableRequest);
+
+const onResponse = 'onResponse';
+//# sourceMappingURL=index.js.map
+// EXTERNAL MODULE: ./node_modules/decompress-response/index.js
+var decompress_response = __nccwpck_require__(2391);
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/isFunction.js
+const isFunction = (value) => (typeof value === "function");
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/isFormData.js
+
+const isFormData = (value) => Boolean(value
+ && isFunction(value.constructor)
+ && value[Symbol.toStringTag] === "FormData"
+ && isFunction(value.append)
+ && isFunction(value.getAll)
+ && isFunction(value.entries)
+ && isFunction(value[Symbol.iterator]));
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/getStreamIterator.js
+
+const isAsyncIterable = (value) => (isFunction(value[Symbol.asyncIterator]));
+async function* readStream(readable) {
+ const reader = readable.getReader();
+ while (true) {
+ const { done, value } = await reader.read();
+ if (done) {
+ break;
+ }
+ yield value;
+ }
+}
+const getStreamIterator = (source) => {
+ if (isAsyncIterable(source)) {
+ return source;
+ }
+ if (isFunction(source.getReader)) {
+ return readStream(source);
+ }
+ throw new TypeError("Unsupported data source: Expected either ReadableStream or async iterable.");
+};
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/createBoundary.js
+const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
+function createBoundary() {
+ let size = 16;
+ let res = "";
+ while (size--) {
+ res += alphabet[(Math.random() * alphabet.length) << 0];
+ }
+ return res;
+}
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/normalizeValue.js
+const normalizeValue = (value) => String(value)
+ .replace(/\r|\n/g, (match, i, str) => {
+ if ((match === "\r" && str[i + 1] !== "\n")
+ || (match === "\n" && str[i - 1] !== "\r")) {
+ return "\r\n";
+ }
+ return match;
+});
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/isPlainObject.js
+const getType = (value) => (Object.prototype.toString.call(value).slice(8, -1).toLowerCase());
+function isPlainObject(value) {
+ if (getType(value) !== "object") {
+ return false;
+ }
+ const pp = Object.getPrototypeOf(value);
+ if (pp === null || pp === undefined) {
+ return true;
+ }
+ const Ctor = pp.constructor && pp.constructor.toString();
+ return Ctor === Object.toString();
+}
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/proxyHeaders.js
+function getProperty(target, prop) {
+ if (typeof prop === "string") {
+ for (const [name, value] of Object.entries(target)) {
+ if (prop.toLowerCase() === name.toLowerCase()) {
+ return value;
+ }
+ }
+ }
+ return undefined;
+}
+const proxyHeaders = (object) => new Proxy(object, {
+ get: (target, prop) => getProperty(target, prop),
+ has: (target, prop) => getProperty(target, prop) !== undefined
+});
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/escapeName.js
+const escapeName = (name) => String(name)
+ .replace(/\r/g, "%0D")
+ .replace(/\n/g, "%0A")
+ .replace(/"/g, "%22");
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/util/isFile.js
+
+const isFile = (value) => Boolean(value
+ && typeof value === "object"
+ && isFunction(value.constructor)
+ && value[Symbol.toStringTag] === "File"
+ && isFunction(value.stream)
+ && value.name != null);
+const isFileLike = (/* unused pure expression or super */ null && (isFile));
+
+;// CONCATENATED MODULE: ./node_modules/form-data-encoder/lib/FormDataEncoder.js
+var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
+ if (kind === "m") throw new TypeError("Private method is not writable");
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
+};
+var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
+};
+var _FormDataEncoder_instances, _FormDataEncoder_CRLF, _FormDataEncoder_CRLF_BYTES, _FormDataEncoder_CRLF_BYTES_LENGTH, _FormDataEncoder_DASHES, _FormDataEncoder_encoder, _FormDataEncoder_footer, _FormDataEncoder_form, _FormDataEncoder_options, _FormDataEncoder_getFieldHeader, _FormDataEncoder_getContentLength;
+
+
+
+
+
+
+
+
+const defaultOptions = {
+ enableAdditionalHeaders: false
+};
+const readonlyProp = { writable: false, configurable: false };
+class FormDataEncoder {
+ constructor(form, boundaryOrOptions, options) {
+ _FormDataEncoder_instances.add(this);
+ _FormDataEncoder_CRLF.set(this, "\r\n");
+ _FormDataEncoder_CRLF_BYTES.set(this, void 0);
+ _FormDataEncoder_CRLF_BYTES_LENGTH.set(this, void 0);
+ _FormDataEncoder_DASHES.set(this, "-".repeat(2));
+ _FormDataEncoder_encoder.set(this, new TextEncoder());
+ _FormDataEncoder_footer.set(this, void 0);
+ _FormDataEncoder_form.set(this, void 0);
+ _FormDataEncoder_options.set(this, void 0);
+ if (!isFormData(form)) {
+ throw new TypeError("Expected first argument to be a FormData instance.");
+ }
+ let boundary;
+ if (isPlainObject(boundaryOrOptions)) {
+ options = boundaryOrOptions;
+ }
+ else {
+ boundary = boundaryOrOptions;
+ }
+ if (!boundary) {
+ boundary = createBoundary();
+ }
+ if (typeof boundary !== "string") {
+ throw new TypeError("Expected boundary argument to be a string.");
+ }
+ if (options && !isPlainObject(options)) {
+ throw new TypeError("Expected options argument to be an object.");
+ }
+ __classPrivateFieldSet(this, _FormDataEncoder_form, Array.from(form.entries()), "f");
+ __classPrivateFieldSet(this, _FormDataEncoder_options, { ...defaultOptions, ...options }, "f");
+ __classPrivateFieldSet(this, _FormDataEncoder_CRLF_BYTES, __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")), "f");
+ __classPrivateFieldSet(this, _FormDataEncoder_CRLF_BYTES_LENGTH, __classPrivateFieldGet(this, _FormDataEncoder_CRLF_BYTES, "f").byteLength, "f");
+ this.boundary = `form-data-boundary-${boundary}`;
+ this.contentType = `multipart/form-data; boundary=${this.boundary}`;
+ __classPrivateFieldSet(this, _FormDataEncoder_footer, __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(`${__classPrivateFieldGet(this, _FormDataEncoder_DASHES, "f")}${this.boundary}${__classPrivateFieldGet(this, _FormDataEncoder_DASHES, "f")}${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f").repeat(2)}`), "f");
+ const headers = {
+ "Content-Type": this.contentType
+ };
+ const contentLength = __classPrivateFieldGet(this, _FormDataEncoder_instances, "m", _FormDataEncoder_getContentLength).call(this);
+ if (contentLength) {
+ this.contentLength = contentLength;
+ headers["Content-Length"] = contentLength;
+ }
+ this.headers = proxyHeaders(Object.freeze(headers));
+ Object.defineProperties(this, {
+ boundary: readonlyProp,
+ contentType: readonlyProp,
+ contentLength: readonlyProp,
+ headers: readonlyProp
+ });
+ }
+ getContentLength() {
+ return this.contentLength == null ? undefined : Number(this.contentLength);
+ }
+ *values() {
+ for (const [name, raw] of __classPrivateFieldGet(this, _FormDataEncoder_form, "f")) {
+ const value = isFile(raw) ? raw : __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(normalizeValue(raw));
+ yield __classPrivateFieldGet(this, _FormDataEncoder_instances, "m", _FormDataEncoder_getFieldHeader).call(this, name, value);
+ yield value;
+ yield __classPrivateFieldGet(this, _FormDataEncoder_CRLF_BYTES, "f");
+ }
+ yield __classPrivateFieldGet(this, _FormDataEncoder_footer, "f");
+ }
+ async *encode() {
+ for (const part of this.values()) {
+ if (isFile(part)) {
+ yield* getStreamIterator(part.stream());
+ }
+ else {
+ yield part;
+ }
+ }
+ }
+ [(_FormDataEncoder_CRLF = new WeakMap(), _FormDataEncoder_CRLF_BYTES = new WeakMap(), _FormDataEncoder_CRLF_BYTES_LENGTH = new WeakMap(), _FormDataEncoder_DASHES = new WeakMap(), _FormDataEncoder_encoder = new WeakMap(), _FormDataEncoder_footer = new WeakMap(), _FormDataEncoder_form = new WeakMap(), _FormDataEncoder_options = new WeakMap(), _FormDataEncoder_instances = new WeakSet(), _FormDataEncoder_getFieldHeader = function _FormDataEncoder_getFieldHeader(name, value) {
+ let header = "";
+ header += `${__classPrivateFieldGet(this, _FormDataEncoder_DASHES, "f")}${this.boundary}${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")}`;
+ header += `Content-Disposition: form-data; name="${escapeName(name)}"`;
+ if (isFile(value)) {
+ header += `; filename="${escapeName(value.name)}"${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")}`;
+ header += `Content-Type: ${value.type || "application/octet-stream"}`;
+ }
+ const size = isFile(value) ? value.size : value.byteLength;
+ if (__classPrivateFieldGet(this, _FormDataEncoder_options, "f").enableAdditionalHeaders === true
+ && size != null
+ && !isNaN(size)) {
+ header += `${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f")}Content-Length: ${isFile(value) ? value.size : value.byteLength}`;
+ }
+ return __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(`${header}${__classPrivateFieldGet(this, _FormDataEncoder_CRLF, "f").repeat(2)}`);
+ }, _FormDataEncoder_getContentLength = function _FormDataEncoder_getContentLength() {
+ let length = 0;
+ for (const [name, raw] of __classPrivateFieldGet(this, _FormDataEncoder_form, "f")) {
+ const value = isFile(raw) ? raw : __classPrivateFieldGet(this, _FormDataEncoder_encoder, "f").encode(normalizeValue(raw));
+ const size = isFile(value) ? value.size : value.byteLength;
+ if (size == null || isNaN(size)) {
+ return undefined;
+ }
+ length += __classPrivateFieldGet(this, _FormDataEncoder_instances, "m", _FormDataEncoder_getFieldHeader).call(this, name, value).byteLength;
+ length += size;
+ length += __classPrivateFieldGet(this, _FormDataEncoder_CRLF_BYTES_LENGTH, "f");
+ }
+ return String(length + __classPrivateFieldGet(this, _FormDataEncoder_footer, "f").byteLength);
+ }, Symbol.iterator)]() {
+ return this.values();
+ }
+ [Symbol.asyncIterator]() {
+ return this.encode();
+ }
+}
+
+;// CONCATENATED MODULE: external "node:util"
+const external_node_util_namespaceObject = require("node:util");
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/is-form-data.js
+
+function is_form_data_isFormData(body) {
+ return dist.nodeStream(body) && dist.function_(body.getBoundary);
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/get-body-size.js
+
+
+
+
+async function getBodySize(body, headers) {
+ if (headers && 'content-length' in headers) {
+ return Number(headers['content-length']);
+ }
+ if (!body) {
+ return 0;
+ }
+ if (dist.string(body)) {
+ return external_node_buffer_namespaceObject.Buffer.byteLength(body);
+ }
+ if (dist.buffer(body)) {
+ return body.length;
+ }
+ if (is_form_data_isFormData(body)) {
+ return (0,external_node_util_namespaceObject.promisify)(body.getLength.bind(body))();
+ }
+ return undefined;
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/proxy-events.js
+function proxyEvents(from, to, events) {
+ const eventFunctions = {};
+ for (const event of events) {
+ const eventFunction = (...args) => {
+ to.emit(event, ...args);
+ };
+ eventFunctions[event] = eventFunction;
+ from.on(event, eventFunction);
+ }
+ return () => {
+ for (const [event, eventFunction] of Object.entries(eventFunctions)) {
+ from.off(event, eventFunction);
+ }
+ };
+}
+
+;// CONCATENATED MODULE: external "node:net"
+const external_node_net_namespaceObject = require("node:net");
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/unhandle.js
+// When attaching listeners, it's very easy to forget about them.
+// Especially if you do error handling and set timeouts.
+// So instead of checking if it's proper to throw an error on every timeout ever,
+// use this simple tool which will remove all listeners you have attached.
+function unhandle() {
+ const handlers = [];
+ return {
+ once(origin, event, fn) {
+ origin.once(event, fn);
+ handlers.push({ origin, event, fn });
+ },
+ unhandleAll() {
+ for (const handler of handlers) {
+ const { origin, event, fn } = handler;
+ origin.removeListener(event, fn);
+ }
+ handlers.length = 0;
+ },
+ };
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/timed-out.js
+
+
+const reentry = Symbol('reentry');
+const noop = () => { };
+class timed_out_TimeoutError extends Error {
+ constructor(threshold, event) {
+ super(`Timeout awaiting '${event}' for ${threshold}ms`);
+ Object.defineProperty(this, "event", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: event
+ });
+ Object.defineProperty(this, "code", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ this.name = 'TimeoutError';
+ this.code = 'ETIMEDOUT';
+ }
+}
+function timedOut(request, delays, options) {
+ if (reentry in request) {
+ return noop;
+ }
+ request[reentry] = true;
+ const cancelers = [];
+ const { once, unhandleAll } = unhandle();
+ const addTimeout = (delay, callback, event) => {
+ const timeout = setTimeout(callback, delay, delay, event);
+ timeout.unref?.();
+ const cancel = () => {
+ clearTimeout(timeout);
+ };
+ cancelers.push(cancel);
+ return cancel;
+ };
+ const { host, hostname } = options;
+ const timeoutHandler = (delay, event) => {
+ request.destroy(new timed_out_TimeoutError(delay, event));
+ };
+ const cancelTimeouts = () => {
+ for (const cancel of cancelers) {
+ cancel();
+ }
+ unhandleAll();
+ };
+ request.once('error', error => {
+ cancelTimeouts();
+ // Save original behavior
+ /* istanbul ignore next */
+ if (request.listenerCount('error') === 0) {
+ throw error;
+ }
+ });
+ if (typeof delays.request !== 'undefined') {
+ const cancelTimeout = addTimeout(delays.request, timeoutHandler, 'request');
+ once(request, 'response', (response) => {
+ once(response, 'end', cancelTimeout);
+ });
+ }
+ if (typeof delays.socket !== 'undefined') {
+ const { socket } = delays;
+ const socketTimeoutHandler = () => {
+ timeoutHandler(socket, 'socket');
+ };
+ request.setTimeout(socket, socketTimeoutHandler);
+ // `request.setTimeout(0)` causes a memory leak.
+ // We can just remove the listener and forget about the timer - it's unreffed.
+ // See https://github.com/sindresorhus/got/issues/690
+ cancelers.push(() => {
+ request.removeListener('timeout', socketTimeoutHandler);
+ });
+ }
+ const hasLookup = typeof delays.lookup !== 'undefined';
+ const hasConnect = typeof delays.connect !== 'undefined';
+ const hasSecureConnect = typeof delays.secureConnect !== 'undefined';
+ const hasSend = typeof delays.send !== 'undefined';
+ if (hasLookup || hasConnect || hasSecureConnect || hasSend) {
+ once(request, 'socket', (socket) => {
+ const { socketPath } = request;
+ /* istanbul ignore next: hard to test */
+ if (socket.connecting) {
+ const hasPath = Boolean(socketPath ?? external_node_net_namespaceObject.isIP(hostname ?? host ?? '') !== 0);
+ if (hasLookup && !hasPath && typeof socket.address().address === 'undefined') {
+ const cancelTimeout = addTimeout(delays.lookup, timeoutHandler, 'lookup');
+ once(socket, 'lookup', cancelTimeout);
+ }
+ if (hasConnect) {
+ const timeConnect = () => addTimeout(delays.connect, timeoutHandler, 'connect');
+ if (hasPath) {
+ once(socket, 'connect', timeConnect());
+ }
+ else {
+ once(socket, 'lookup', (error) => {
+ if (error === null) {
+ once(socket, 'connect', timeConnect());
+ }
+ });
+ }
+ }
+ if (hasSecureConnect && options.protocol === 'https:') {
+ once(socket, 'connect', () => {
+ const cancelTimeout = addTimeout(delays.secureConnect, timeoutHandler, 'secureConnect');
+ once(socket, 'secureConnect', cancelTimeout);
+ });
+ }
+ }
+ if (hasSend) {
+ const timeRequest = () => addTimeout(delays.send, timeoutHandler, 'send');
+ /* istanbul ignore next: hard to test */
+ if (socket.connecting) {
+ once(socket, 'connect', () => {
+ once(request, 'upload-complete', timeRequest());
+ });
+ }
+ else {
+ once(request, 'upload-complete', timeRequest());
+ }
+ }
+ });
+ }
+ if (typeof delays.response !== 'undefined') {
+ once(request, 'upload-complete', () => {
+ const cancelTimeout = addTimeout(delays.response, timeoutHandler, 'response');
+ once(request, 'response', cancelTimeout);
+ });
+ }
+ if (typeof delays.read !== 'undefined') {
+ once(request, 'response', (response) => {
+ const cancelTimeout = addTimeout(delays.read, timeoutHandler, 'read');
+ once(response, 'end', cancelTimeout);
+ });
+ }
+ return cancelTimeouts;
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/url-to-options.js
+
+function urlToOptions(url) {
+ // Cast to URL
+ url = url;
+ const options = {
+ protocol: url.protocol,
+ hostname: dist.string(url.hostname) && url.hostname.startsWith('[') ? url.hostname.slice(1, -1) : url.hostname,
+ host: url.host,
+ hash: url.hash,
+ search: url.search,
+ pathname: url.pathname,
+ href: url.href,
+ path: `${url.pathname || ''}${url.search || ''}`,
+ };
+ if (dist.string(url.port) && url.port.length > 0) {
+ options.port = Number(url.port);
+ }
+ if (url.username || url.password) {
+ options.auth = `${url.username || ''}:${url.password || ''}`;
+ }
+ return options;
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/weakable-map.js
+class WeakableMap {
+ constructor() {
+ Object.defineProperty(this, "weakMap", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "map", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ this.weakMap = new WeakMap();
+ this.map = new Map();
+ }
+ set(key, value) {
+ if (typeof key === 'object') {
+ this.weakMap.set(key, value);
+ }
+ else {
+ this.map.set(key, value);
+ }
+ }
+ get(key) {
+ if (typeof key === 'object') {
+ return this.weakMap.get(key);
+ }
+ return this.map.get(key);
+ }
+ has(key) {
+ if (typeof key === 'object') {
+ return this.weakMap.has(key);
+ }
+ return this.map.has(key);
+ }
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/calculate-retry-delay.js
+const calculateRetryDelay = ({ attemptCount, retryOptions, error, retryAfter, computedValue, }) => {
+ if (error.name === 'RetryError') {
+ return 1;
+ }
+ if (attemptCount > retryOptions.limit) {
+ return 0;
+ }
+ const hasMethod = retryOptions.methods.includes(error.options.method);
+ const hasErrorCode = retryOptions.errorCodes.includes(error.code);
+ const hasStatusCode = error.response && retryOptions.statusCodes.includes(error.response.statusCode);
+ if (!hasMethod || (!hasErrorCode && !hasStatusCode)) {
+ return 0;
+ }
+ if (error.response) {
+ if (retryAfter) {
+ // In this case `computedValue` is `options.request.timeout`
+ if (retryAfter > computedValue) {
+ return 0;
+ }
+ return retryAfter;
+ }
+ if (error.response.statusCode === 413) {
+ return 0;
+ }
+ }
+ const noise = Math.random() * retryOptions.noise;
+ return Math.min(((2 ** (attemptCount - 1)) * 1000), retryOptions.backoffLimit) + noise;
+};
+/* harmony default export */ const calculate_retry_delay = (calculateRetryDelay);
+
+;// CONCATENATED MODULE: external "node:tls"
+const external_node_tls_namespaceObject = require("node:tls");
+;// CONCATENATED MODULE: external "node:https"
+const external_node_https_namespaceObject = require("node:https");
+;// CONCATENATED MODULE: external "node:dns"
+const external_node_dns_namespaceObject = require("node:dns");
+;// CONCATENATED MODULE: external "node:os"
+const external_node_os_namespaceObject = require("node:os");
+;// CONCATENATED MODULE: ./node_modules/cacheable-lookup/source/index.js
+
+
+
+
+const {Resolver: AsyncResolver} = external_node_dns_namespaceObject.promises;
+
+const kCacheableLookupCreateConnection = Symbol('cacheableLookupCreateConnection');
+const kCacheableLookupInstance = Symbol('cacheableLookupInstance');
+const kExpires = Symbol('expires');
+
+const supportsALL = typeof external_node_dns_namespaceObject.ALL === 'number';
+
+const verifyAgent = agent => {
+ if (!(agent && typeof agent.createConnection === 'function')) {
+ throw new Error('Expected an Agent instance as the first argument');
+ }
+};
+
+const map4to6 = entries => {
+ for (const entry of entries) {
+ if (entry.family === 6) {
+ continue;
+ }
+
+ entry.address = `::ffff:${entry.address}`;
+ entry.family = 6;
+ }
+};
+
+const getIfaceInfo = () => {
+ let has4 = false;
+ let has6 = false;
+
+ for (const device of Object.values(external_node_os_namespaceObject.networkInterfaces())) {
+ for (const iface of device) {
+ if (iface.internal) {
+ continue;
+ }
+
+ if (iface.family === 'IPv6') {
+ has6 = true;
+ } else {
+ has4 = true;
+ }
+
+ if (has4 && has6) {
+ return {has4, has6};
+ }
+ }
+ }
+
+ return {has4, has6};
+};
+
+const isIterable = map => {
+ return Symbol.iterator in map;
+};
+
+const ignoreNoResultErrors = dnsPromise => {
+ return dnsPromise.catch(error => {
+ if (
+ error.code === 'ENODATA' ||
+ error.code === 'ENOTFOUND' ||
+ error.code === 'ENOENT' // Windows: name exists, but not this record type
+ ) {
+ return [];
+ }
+
+ throw error;
+ });
+};
+
+const ttl = {ttl: true};
+const source_all = {all: true};
+const all4 = {all: true, family: 4};
+const all6 = {all: true, family: 6};
+
+class CacheableLookup {
+ constructor({
+ cache = new Map(),
+ maxTtl = Infinity,
+ fallbackDuration = 3600,
+ errorTtl = 0.15,
+ resolver = new AsyncResolver(),
+ lookup = external_node_dns_namespaceObject.lookup
+ } = {}) {
+ this.maxTtl = maxTtl;
+ this.errorTtl = errorTtl;
+
+ this._cache = cache;
+ this._resolver = resolver;
+ this._dnsLookup = lookup && (0,external_node_util_namespaceObject.promisify)(lookup);
+ this.stats = {
+ cache: 0,
+ query: 0
+ };
+
+ if (this._resolver instanceof AsyncResolver) {
+ this._resolve4 = this._resolver.resolve4.bind(this._resolver);
+ this._resolve6 = this._resolver.resolve6.bind(this._resolver);
+ } else {
+ this._resolve4 = (0,external_node_util_namespaceObject.promisify)(this._resolver.resolve4.bind(this._resolver));
+ this._resolve6 = (0,external_node_util_namespaceObject.promisify)(this._resolver.resolve6.bind(this._resolver));
+ }
+
+ this._iface = getIfaceInfo();
+
+ this._pending = {};
+ this._nextRemovalTime = false;
+ this._hostnamesToFallback = new Set();
+
+ this.fallbackDuration = fallbackDuration;
+
+ if (fallbackDuration > 0) {
+ const interval = setInterval(() => {
+ this._hostnamesToFallback.clear();
+ }, fallbackDuration * 1000);
+
+ /* istanbul ignore next: There is no `interval.unref()` when running inside an Electron renderer */
+ if (interval.unref) {
+ interval.unref();
+ }
+
+ this._fallbackInterval = interval;
+ }
+
+ this.lookup = this.lookup.bind(this);
+ this.lookupAsync = this.lookupAsync.bind(this);
+ }
+
+ set servers(servers) {
+ this.clear();
+
+ this._resolver.setServers(servers);
+ }
+
+ get servers() {
+ return this._resolver.getServers();
+ }
+
+ lookup(hostname, options, callback) {
+ if (typeof options === 'function') {
+ callback = options;
+ options = {};
+ } else if (typeof options === 'number') {
+ options = {
+ family: options
+ };
+ }
+
+ if (!callback) {
+ throw new Error('Callback must be a function.');
+ }
+
+ // eslint-disable-next-line promise/prefer-await-to-then
+ this.lookupAsync(hostname, options).then(result => {
+ if (options.all) {
+ callback(null, result);
+ } else {
+ callback(null, result.address, result.family, result.expires, result.ttl, result.source);
+ }
+ }, callback);
+ }
+
+ async lookupAsync(hostname, options = {}) {
+ if (typeof options === 'number') {
+ options = {
+ family: options
+ };
+ }
+
+ let cached = await this.query(hostname);
+
+ if (options.family === 6) {
+ const filtered = cached.filter(entry => entry.family === 6);
+
+ if (options.hints & external_node_dns_namespaceObject.V4MAPPED) {
+ if ((supportsALL && options.hints & external_node_dns_namespaceObject.ALL) || filtered.length === 0) {
+ map4to6(cached);
+ } else {
+ cached = filtered;
+ }
+ } else {
+ cached = filtered;
+ }
+ } else if (options.family === 4) {
+ cached = cached.filter(entry => entry.family === 4);
+ }
+
+ if (options.hints & external_node_dns_namespaceObject.ADDRCONFIG) {
+ const {_iface} = this;
+ cached = cached.filter(entry => entry.family === 6 ? _iface.has6 : _iface.has4);
+ }
+
+ if (cached.length === 0) {
+ const error = new Error(`cacheableLookup ENOTFOUND ${hostname}`);
+ error.code = 'ENOTFOUND';
+ error.hostname = hostname;
+
+ throw error;
+ }
+
+ if (options.all) {
+ return cached;
+ }
+
+ return cached[0];
+ }
+
+ async query(hostname) {
+ let source = 'cache';
+ let cached = await this._cache.get(hostname);
+
+ if (cached) {
+ this.stats.cache++;
+ }
+
+ if (!cached) {
+ const pending = this._pending[hostname];
+ if (pending) {
+ this.stats.cache++;
+ cached = await pending;
+ } else {
+ source = 'query';
+ const newPromise = this.queryAndCache(hostname);
+ this._pending[hostname] = newPromise;
+ this.stats.query++;
+ try {
+ cached = await newPromise;
+ } finally {
+ delete this._pending[hostname];
+ }
+ }
+ }
+
+ cached = cached.map(entry => {
+ return {...entry, source};
+ });
+
+ return cached;
+ }
+
+ async _resolve(hostname) {
+ // ANY is unsafe as it doesn't trigger new queries in the underlying server.
+ const [A, AAAA] = await Promise.all([
+ ignoreNoResultErrors(this._resolve4(hostname, ttl)),
+ ignoreNoResultErrors(this._resolve6(hostname, ttl))
+ ]);
+
+ let aTtl = 0;
+ let aaaaTtl = 0;
+ let cacheTtl = 0;
+
+ const now = Date.now();
+
+ for (const entry of A) {
+ entry.family = 4;
+ entry.expires = now + (entry.ttl * 1000);
+
+ aTtl = Math.max(aTtl, entry.ttl);
+ }
+
+ for (const entry of AAAA) {
+ entry.family = 6;
+ entry.expires = now + (entry.ttl * 1000);
+
+ aaaaTtl = Math.max(aaaaTtl, entry.ttl);
+ }
+
+ if (A.length > 0) {
+ if (AAAA.length > 0) {
+ cacheTtl = Math.min(aTtl, aaaaTtl);
+ } else {
+ cacheTtl = aTtl;
+ }
+ } else {
+ cacheTtl = aaaaTtl;
+ }
+
+ return {
+ entries: [
+ ...A,
+ ...AAAA
+ ],
+ cacheTtl
+ };
+ }
+
+ async _lookup(hostname) {
+ try {
+ const [A, AAAA] = await Promise.all([
+ // Passing {all: true} doesn't return all IPv4 and IPv6 entries.
+ // See https://github.com/szmarczak/cacheable-lookup/issues/42
+ ignoreNoResultErrors(this._dnsLookup(hostname, all4)),
+ ignoreNoResultErrors(this._dnsLookup(hostname, all6))
+ ]);
+
+ return {
+ entries: [
+ ...A,
+ ...AAAA
+ ],
+ cacheTtl: 0
+ };
+ } catch {
+ return {
+ entries: [],
+ cacheTtl: 0
+ };
+ }
+ }
+
+ async _set(hostname, data, cacheTtl) {
+ if (this.maxTtl > 0 && cacheTtl > 0) {
+ cacheTtl = Math.min(cacheTtl, this.maxTtl) * 1000;
+ data[kExpires] = Date.now() + cacheTtl;
+
+ try {
+ await this._cache.set(hostname, data, cacheTtl);
+ } catch (error) {
+ this.lookupAsync = async () => {
+ const cacheError = new Error('Cache Error. Please recreate the CacheableLookup instance.');
+ cacheError.cause = error;
+
+ throw cacheError;
+ };
+ }
+
+ if (isIterable(this._cache)) {
+ this._tick(cacheTtl);
+ }
+ }
+ }
+
+ async queryAndCache(hostname) {
+ if (this._hostnamesToFallback.has(hostname)) {
+ return this._dnsLookup(hostname, source_all);
+ }
+
+ let query = await this._resolve(hostname);
+
+ if (query.entries.length === 0 && this._dnsLookup) {
+ query = await this._lookup(hostname);
+
+ if (query.entries.length !== 0 && this.fallbackDuration > 0) {
+ // Use `dns.lookup(...)` for that particular hostname
+ this._hostnamesToFallback.add(hostname);
+ }
+ }
+
+ const cacheTtl = query.entries.length === 0 ? this.errorTtl : query.cacheTtl;
+ await this._set(hostname, query.entries, cacheTtl);
+
+ return query.entries;
+ }
+
+ _tick(ms) {
+ const nextRemovalTime = this._nextRemovalTime;
+
+ if (!nextRemovalTime || ms < nextRemovalTime) {
+ clearTimeout(this._removalTimeout);
+
+ this._nextRemovalTime = ms;
+
+ this._removalTimeout = setTimeout(() => {
+ this._nextRemovalTime = false;
+
+ let nextExpiry = Infinity;
+
+ const now = Date.now();
+
+ for (const [hostname, entries] of this._cache) {
+ const expires = entries[kExpires];
+
+ if (now >= expires) {
+ this._cache.delete(hostname);
+ } else if (expires < nextExpiry) {
+ nextExpiry = expires;
+ }
+ }
+
+ if (nextExpiry !== Infinity) {
+ this._tick(nextExpiry - now);
+ }
+ }, ms);
+
+ /* istanbul ignore next: There is no `timeout.unref()` when running inside an Electron renderer */
+ if (this._removalTimeout.unref) {
+ this._removalTimeout.unref();
+ }
+ }
+ }
+
+ install(agent) {
+ verifyAgent(agent);
+
+ if (kCacheableLookupCreateConnection in agent) {
+ throw new Error('CacheableLookup has been already installed');
+ }
+
+ agent[kCacheableLookupCreateConnection] = agent.createConnection;
+ agent[kCacheableLookupInstance] = this;
+
+ agent.createConnection = (options, callback) => {
+ if (!('lookup' in options)) {
+ options.lookup = this.lookup;
+ }
+
+ return agent[kCacheableLookupCreateConnection](options, callback);
+ };
+ }
+
+ uninstall(agent) {
+ verifyAgent(agent);
+
+ if (agent[kCacheableLookupCreateConnection]) {
+ if (agent[kCacheableLookupInstance] !== this) {
+ throw new Error('The agent is not owned by this CacheableLookup instance');
+ }
+
+ agent.createConnection = agent[kCacheableLookupCreateConnection];
+
+ delete agent[kCacheableLookupCreateConnection];
+ delete agent[kCacheableLookupInstance];
+ }
+ }
+
+ updateInterfaceInfo() {
+ const {_iface} = this;
+
+ this._iface = getIfaceInfo();
+
+ if ((_iface.has4 && !this._iface.has4) || (_iface.has6 && !this._iface.has6)) {
+ this._cache.clear();
+ }
+ }
+
+ clear(hostname) {
+ if (hostname) {
+ this._cache.delete(hostname);
+ return;
+ }
+
+ this._cache.clear();
+ }
+}
+
+// EXTERNAL MODULE: ./node_modules/http2-wrapper/source/index.js
+var http2_wrapper_source = __nccwpck_require__(4645);
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/parse-link-header.js
+function parseLinkHeader(link) {
+ const parsed = [];
+ const items = link.split(',');
+ for (const item of items) {
+ // https://tools.ietf.org/html/rfc5988#section-5
+ const [rawUriReference, ...rawLinkParameters] = item.split(';');
+ const trimmedUriReference = rawUriReference.trim();
+ // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
+ if (trimmedUriReference[0] !== '<' || trimmedUriReference[trimmedUriReference.length - 1] !== '>') {
+ throw new Error(`Invalid format of the Link header reference: ${trimmedUriReference}`);
+ }
+ const reference = trimmedUriReference.slice(1, -1);
+ const parameters = {};
+ if (rawLinkParameters.length === 0) {
+ throw new Error(`Unexpected end of Link header parameters: ${rawLinkParameters.join(';')}`);
+ }
+ for (const rawParameter of rawLinkParameters) {
+ const trimmedRawParameter = rawParameter.trim();
+ const center = trimmedRawParameter.indexOf('=');
+ if (center === -1) {
+ throw new Error(`Failed to parse Link header: ${link}`);
+ }
+ const name = trimmedRawParameter.slice(0, center).trim();
+ const value = trimmedRawParameter.slice(center + 1).trim();
+ parameters[name] = value;
+ }
+ parsed.push({
+ reference,
+ parameters,
+ });
+ }
+ return parsed;
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/options.js
+
+
+
+
+// DO NOT use destructuring for `https.request` and `http.request` as it's not compatible with `nock`.
+
+
+
+
+
+
+
+
+const [major, minor] = external_node_process_namespaceObject.versions.node.split('.').map(Number);
+function validateSearchParameters(searchParameters) {
+ // eslint-disable-next-line guard-for-in
+ for (const key in searchParameters) {
+ const value = searchParameters[key];
+ assert.any([dist.string, dist.number, dist.boolean, dist.null_, dist.undefined], value);
+ }
+}
+const globalCache = new Map();
+let globalDnsCache;
+const getGlobalDnsCache = () => {
+ if (globalDnsCache) {
+ return globalDnsCache;
+ }
+ globalDnsCache = new CacheableLookup();
+ return globalDnsCache;
+};
+const defaultInternals = {
+ request: undefined,
+ agent: {
+ http: undefined,
+ https: undefined,
+ http2: undefined,
+ },
+ h2session: undefined,
+ decompress: true,
+ timeout: {
+ connect: undefined,
+ lookup: undefined,
+ read: undefined,
+ request: undefined,
+ response: undefined,
+ secureConnect: undefined,
+ send: undefined,
+ socket: undefined,
+ },
+ prefixUrl: '',
+ body: undefined,
+ form: undefined,
+ json: undefined,
+ cookieJar: undefined,
+ ignoreInvalidCookies: false,
+ searchParams: undefined,
+ dnsLookup: undefined,
+ dnsCache: undefined,
+ context: {},
+ hooks: {
+ init: [],
+ beforeRequest: [],
+ beforeError: [],
+ beforeRedirect: [],
+ beforeRetry: [],
+ afterResponse: [],
+ },
+ followRedirect: true,
+ maxRedirects: 10,
+ cache: undefined,
+ throwHttpErrors: true,
+ username: '',
+ password: '',
+ http2: false,
+ allowGetBody: false,
+ headers: {
+ 'user-agent': 'got (https://github.com/sindresorhus/got)',
+ },
+ methodRewriting: false,
+ dnsLookupIpVersion: undefined,
+ parseJson: JSON.parse,
+ stringifyJson: JSON.stringify,
+ retry: {
+ limit: 2,
+ methods: [
+ 'GET',
+ 'PUT',
+ 'HEAD',
+ 'DELETE',
+ 'OPTIONS',
+ 'TRACE',
+ ],
+ statusCodes: [
+ 408,
+ 413,
+ 429,
+ 500,
+ 502,
+ 503,
+ 504,
+ 521,
+ 522,
+ 524,
+ ],
+ errorCodes: [
+ 'ETIMEDOUT',
+ 'ECONNRESET',
+ 'EADDRINUSE',
+ 'ECONNREFUSED',
+ 'EPIPE',
+ 'ENOTFOUND',
+ 'ENETUNREACH',
+ 'EAI_AGAIN',
+ ],
+ maxRetryAfter: undefined,
+ calculateDelay: ({ computedValue }) => computedValue,
+ backoffLimit: Number.POSITIVE_INFINITY,
+ noise: 100,
+ },
+ localAddress: undefined,
+ method: 'GET',
+ createConnection: undefined,
+ cacheOptions: {
+ shared: undefined,
+ cacheHeuristic: undefined,
+ immutableMinTimeToLive: undefined,
+ ignoreCargoCult: undefined,
+ },
+ https: {
+ alpnProtocols: undefined,
+ rejectUnauthorized: undefined,
+ checkServerIdentity: undefined,
+ certificateAuthority: undefined,
+ key: undefined,
+ certificate: undefined,
+ passphrase: undefined,
+ pfx: undefined,
+ ciphers: undefined,
+ honorCipherOrder: undefined,
+ minVersion: undefined,
+ maxVersion: undefined,
+ signatureAlgorithms: undefined,
+ tlsSessionLifetime: undefined,
+ dhparam: undefined,
+ ecdhCurve: undefined,
+ certificateRevocationLists: undefined,
+ },
+ encoding: undefined,
+ resolveBodyOnly: false,
+ isStream: false,
+ responseType: 'text',
+ url: undefined,
+ pagination: {
+ transform(response) {
+ if (response.request.options.responseType === 'json') {
+ return response.body;
+ }
+ return JSON.parse(response.body);
+ },
+ paginate({ response }) {
+ const rawLinkHeader = response.headers.link;
+ if (typeof rawLinkHeader !== 'string' || rawLinkHeader.trim() === '') {
+ return false;
+ }
+ const parsed = parseLinkHeader(rawLinkHeader);
+ const next = parsed.find(entry => entry.parameters.rel === 'next' || entry.parameters.rel === '"next"');
+ if (next) {
+ return {
+ url: new external_node_url_namespaceObject.URL(next.reference, response.url),
+ };
+ }
+ return false;
+ },
+ filter: () => true,
+ shouldContinue: () => true,
+ countLimit: Number.POSITIVE_INFINITY,
+ backoff: 0,
+ requestLimit: 10000,
+ stackAllItems: false,
+ },
+ setHost: true,
+ maxHeaderSize: undefined,
+ signal: undefined,
+ enableUnixSockets: true,
+};
+const cloneInternals = (internals) => {
+ const { hooks, retry } = internals;
+ const result = {
+ ...internals,
+ context: { ...internals.context },
+ cacheOptions: { ...internals.cacheOptions },
+ https: { ...internals.https },
+ agent: { ...internals.agent },
+ headers: { ...internals.headers },
+ retry: {
+ ...retry,
+ errorCodes: [...retry.errorCodes],
+ methods: [...retry.methods],
+ statusCodes: [...retry.statusCodes],
+ },
+ timeout: { ...internals.timeout },
+ hooks: {
+ init: [...hooks.init],
+ beforeRequest: [...hooks.beforeRequest],
+ beforeError: [...hooks.beforeError],
+ beforeRedirect: [...hooks.beforeRedirect],
+ beforeRetry: [...hooks.beforeRetry],
+ afterResponse: [...hooks.afterResponse],
+ },
+ searchParams: internals.searchParams ? new external_node_url_namespaceObject.URLSearchParams(internals.searchParams) : undefined,
+ pagination: { ...internals.pagination },
+ };
+ if (result.url !== undefined) {
+ result.prefixUrl = '';
+ }
+ return result;
+};
+const cloneRaw = (raw) => {
+ const { hooks, retry } = raw;
+ const result = { ...raw };
+ if (dist.object(raw.context)) {
+ result.context = { ...raw.context };
+ }
+ if (dist.object(raw.cacheOptions)) {
+ result.cacheOptions = { ...raw.cacheOptions };
+ }
+ if (dist.object(raw.https)) {
+ result.https = { ...raw.https };
+ }
+ if (dist.object(raw.cacheOptions)) {
+ result.cacheOptions = { ...result.cacheOptions };
+ }
+ if (dist.object(raw.agent)) {
+ result.agent = { ...raw.agent };
+ }
+ if (dist.object(raw.headers)) {
+ result.headers = { ...raw.headers };
+ }
+ if (dist.object(retry)) {
+ result.retry = { ...retry };
+ if (dist.array(retry.errorCodes)) {
+ result.retry.errorCodes = [...retry.errorCodes];
+ }
+ if (dist.array(retry.methods)) {
+ result.retry.methods = [...retry.methods];
+ }
+ if (dist.array(retry.statusCodes)) {
+ result.retry.statusCodes = [...retry.statusCodes];
+ }
+ }
+ if (dist.object(raw.timeout)) {
+ result.timeout = { ...raw.timeout };
+ }
+ if (dist.object(hooks)) {
+ result.hooks = {
+ ...hooks,
+ };
+ if (dist.array(hooks.init)) {
+ result.hooks.init = [...hooks.init];
+ }
+ if (dist.array(hooks.beforeRequest)) {
+ result.hooks.beforeRequest = [...hooks.beforeRequest];
+ }
+ if (dist.array(hooks.beforeError)) {
+ result.hooks.beforeError = [...hooks.beforeError];
+ }
+ if (dist.array(hooks.beforeRedirect)) {
+ result.hooks.beforeRedirect = [...hooks.beforeRedirect];
+ }
+ if (dist.array(hooks.beforeRetry)) {
+ result.hooks.beforeRetry = [...hooks.beforeRetry];
+ }
+ if (dist.array(hooks.afterResponse)) {
+ result.hooks.afterResponse = [...hooks.afterResponse];
+ }
+ }
+ // TODO: raw.searchParams
+ if (dist.object(raw.pagination)) {
+ result.pagination = { ...raw.pagination };
+ }
+ return result;
+};
+const getHttp2TimeoutOption = (internals) => {
+ const delays = [internals.timeout.socket, internals.timeout.connect, internals.timeout.lookup, internals.timeout.request, internals.timeout.secureConnect].filter(delay => typeof delay === 'number');
+ if (delays.length > 0) {
+ return Math.min(...delays);
+ }
+ return undefined;
+};
+const init = (options, withOptions, self) => {
+ const initHooks = options.hooks?.init;
+ if (initHooks) {
+ for (const hook of initHooks) {
+ hook(withOptions, self);
+ }
+ }
+};
+class Options {
+ constructor(input, options, defaults) {
+ Object.defineProperty(this, "_unixOptions", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_internals", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_merging", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_init", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ assert.any([dist.string, dist.urlInstance, dist.object, dist.undefined], input);
+ assert.any([dist.object, dist.undefined], options);
+ assert.any([dist.object, dist.undefined], defaults);
+ if (input instanceof Options || options instanceof Options) {
+ throw new TypeError('The defaults must be passed as the third argument');
+ }
+ this._internals = cloneInternals(defaults?._internals ?? defaults ?? defaultInternals);
+ this._init = [...(defaults?._init ?? [])];
+ this._merging = false;
+ this._unixOptions = undefined;
+ // This rule allows `finally` to be considered more important.
+ // Meaning no matter the error thrown in the `try` block,
+ // if `finally` throws then the `finally` error will be thrown.
+ //
+ // Yes, we want this. If we set `url` first, then the `url.searchParams`
+ // would get merged. Instead we set the `searchParams` first, then
+ // `url.searchParams` is overwritten as expected.
+ //
+ /* eslint-disable no-unsafe-finally */
+ try {
+ if (dist.plainObject(input)) {
+ try {
+ this.merge(input);
+ this.merge(options);
+ }
+ finally {
+ this.url = input.url;
+ }
+ }
+ else {
+ try {
+ this.merge(options);
+ }
+ finally {
+ if (options?.url !== undefined) {
+ if (input === undefined) {
+ this.url = options.url;
+ }
+ else {
+ throw new TypeError('The `url` option is mutually exclusive with the `input` argument');
+ }
+ }
+ else if (input !== undefined) {
+ this.url = input;
+ }
+ }
+ }
+ }
+ catch (error) {
+ error.options = this;
+ throw error;
+ }
+ /* eslint-enable no-unsafe-finally */
+ }
+ merge(options) {
+ if (!options) {
+ return;
+ }
+ if (options instanceof Options) {
+ for (const init of options._init) {
+ this.merge(init);
+ }
+ return;
+ }
+ options = cloneRaw(options);
+ init(this, options, this);
+ init(options, options, this);
+ this._merging = true;
+ // Always merge `isStream` first
+ if ('isStream' in options) {
+ this.isStream = options.isStream;
+ }
+ try {
+ let push = false;
+ for (const key in options) {
+ // `got.extend()` options
+ if (key === 'mutableDefaults' || key === 'handlers') {
+ continue;
+ }
+ // Never merge `url`
+ if (key === 'url') {
+ continue;
+ }
+ if (!(key in this)) {
+ throw new Error(`Unexpected option: ${key}`);
+ }
+ // @ts-expect-error Type 'unknown' is not assignable to type 'never'.
+ this[key] = options[key];
+ push = true;
+ }
+ if (push) {
+ this._init.push(options);
+ }
+ }
+ finally {
+ this._merging = false;
+ }
+ }
+ /**
+ Custom request function.
+ The main purpose of this is to [support HTTP2 using a wrapper](https://github.com/szmarczak/http2-wrapper).
+
+ @default http.request | https.request
+ */
+ get request() {
+ return this._internals.request;
+ }
+ set request(value) {
+ assert.any([dist.function_, dist.undefined], value);
+ this._internals.request = value;
+ }
+ /**
+ An object representing `http`, `https` and `http2` keys for [`http.Agent`](https://nodejs.org/api/http.html#http_class_http_agent), [`https.Agent`](https://nodejs.org/api/https.html#https_class_https_agent) and [`http2wrapper.Agent`](https://github.com/szmarczak/http2-wrapper#new-http2agentoptions) instance.
+ This is necessary because a request to one protocol might redirect to another.
+ In such a scenario, Got will switch over to the right protocol agent for you.
+
+ If a key is not present, it will default to a global agent.
+
+ @example
+ ```
+ import got from 'got';
+ import HttpAgent from 'agentkeepalive';
+
+ const {HttpsAgent} = HttpAgent;
+
+ await got('https://sindresorhus.com', {
+ agent: {
+ http: new HttpAgent(),
+ https: new HttpsAgent()
+ }
+ });
+ ```
+ */
+ get agent() {
+ return this._internals.agent;
+ }
+ set agent(value) {
+ assert.plainObject(value);
+ // eslint-disable-next-line guard-for-in
+ for (const key in value) {
+ if (!(key in this._internals.agent)) {
+ throw new TypeError(`Unexpected agent option: ${key}`);
+ }
+ // @ts-expect-error - No idea why `value[key]` doesn't work here.
+ assert.any([dist.object, dist.undefined], value[key]);
+ }
+ if (this._merging) {
+ Object.assign(this._internals.agent, value);
+ }
+ else {
+ this._internals.agent = { ...value };
+ }
+ }
+ get h2session() {
+ return this._internals.h2session;
+ }
+ set h2session(value) {
+ this._internals.h2session = value;
+ }
+ /**
+ Decompress the response automatically.
+
+ This will set the `accept-encoding` header to `gzip, deflate, br` unless you set it yourself.
+
+ If this is disabled, a compressed response is returned as a `Buffer`.
+ This may be useful if you want to handle decompression yourself or stream the raw compressed data.
+
+ @default true
+ */
+ get decompress() {
+ return this._internals.decompress;
+ }
+ set decompress(value) {
+ assert.boolean(value);
+ this._internals.decompress = value;
+ }
+ /**
+ Milliseconds to wait for the server to end the response before aborting the request with `got.TimeoutError` error (a.k.a. `request` property).
+ By default, there's no timeout.
+
+ This also accepts an `object` with the following fields to constrain the duration of each phase of the request lifecycle:
+
+ - `lookup` starts when a socket is assigned and ends when the hostname has been resolved.
+ Does not apply when using a Unix domain socket.
+ - `connect` starts when `lookup` completes (or when the socket is assigned if lookup does not apply to the request) and ends when the socket is connected.
+ - `secureConnect` starts when `connect` completes and ends when the handshaking process completes (HTTPS only).
+ - `socket` starts when the socket is connected. See [request.setTimeout](https://nodejs.org/api/http.html#http_request_settimeout_timeout_callback).
+ - `response` starts when the request has been written to the socket and ends when the response headers are received.
+ - `send` starts when the socket is connected and ends with the request has been written to the socket.
+ - `request` starts when the request is initiated and ends when the response's end event fires.
+ */
+ get timeout() {
+ // We always return `Delays` here.
+ // It has to be `Delays | number`, otherwise TypeScript will error because the getter and the setter have incompatible types.
+ return this._internals.timeout;
+ }
+ set timeout(value) {
+ assert.plainObject(value);
+ // eslint-disable-next-line guard-for-in
+ for (const key in value) {
+ if (!(key in this._internals.timeout)) {
+ throw new Error(`Unexpected timeout option: ${key}`);
+ }
+ // @ts-expect-error - No idea why `value[key]` doesn't work here.
+ assert.any([dist.number, dist.undefined], value[key]);
+ }
+ if (this._merging) {
+ Object.assign(this._internals.timeout, value);
+ }
+ else {
+ this._internals.timeout = { ...value };
+ }
+ }
+ /**
+ When specified, `prefixUrl` will be prepended to `url`.
+ The prefix can be any valid URL, either relative or absolute.
+ A trailing slash `/` is optional - one will be added automatically.
+
+ __Note__: `prefixUrl` will be ignored if the `url` argument is a URL instance.
+
+ __Note__: Leading slashes in `input` are disallowed when using this option to enforce consistency and avoid confusion.
+ For example, when the prefix URL is `https://example.com/foo` and the input is `/bar`, there's ambiguity whether the resulting URL would become `https://example.com/foo/bar` or `https://example.com/bar`.
+ The latter is used by browsers.
+
+ __Tip__: Useful when used with `got.extend()` to create niche-specific Got instances.
+
+ __Tip__: You can change `prefixUrl` using hooks as long as the URL still includes the `prefixUrl`.
+ If the URL doesn't include it anymore, it will throw.
+
+ @example
+ ```
+ import got from 'got';
+
+ await got('unicorn', {prefixUrl: 'https://cats.com'});
+ //=> 'https://cats.com/unicorn'
+
+ const instance = got.extend({
+ prefixUrl: 'https://google.com'
+ });
+
+ await instance('unicorn', {
+ hooks: {
+ beforeRequest: [
+ options => {
+ options.prefixUrl = 'https://cats.com';
+ }
+ ]
+ }
+ });
+ //=> 'https://cats.com/unicorn'
+ ```
+ */
+ get prefixUrl() {
+ // We always return `string` here.
+ // It has to be `string | URL`, otherwise TypeScript will error because the getter and the setter have incompatible types.
+ return this._internals.prefixUrl;
+ }
+ set prefixUrl(value) {
+ assert.any([dist.string, dist.urlInstance], value);
+ if (value === '') {
+ this._internals.prefixUrl = '';
+ return;
+ }
+ value = value.toString();
+ if (!value.endsWith('/')) {
+ value += '/';
+ }
+ if (this._internals.prefixUrl && this._internals.url) {
+ const { href } = this._internals.url;
+ this._internals.url.href = value + href.slice(this._internals.prefixUrl.length);
+ }
+ this._internals.prefixUrl = value;
+ }
+ /**
+ __Note #1__: The `body` option cannot be used with the `json` or `form` option.
+
+ __Note #2__: If you provide this option, `got.stream()` will be read-only.
+
+ __Note #3__: If you provide a payload with the `GET` or `HEAD` method, it will throw a `TypeError` unless the method is `GET` and the `allowGetBody` option is set to `true`.
+
+ __Note #4__: This option is not enumerable and will not be merged with the instance defaults.
+
+ The `content-length` header will be automatically set if `body` is a `string` / `Buffer` / [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) / [`form-data` instance](https://github.com/form-data/form-data), and `content-length` and `transfer-encoding` are not manually set in `options.headers`.
+
+ Since Got 12, the `content-length` is not automatically set when `body` is a `fs.createReadStream`.
+ */
+ get body() {
+ return this._internals.body;
+ }
+ set body(value) {
+ assert.any([dist.string, dist.buffer, dist.nodeStream, dist.generator, dist.asyncGenerator, isFormData, dist.undefined], value);
+ if (dist.nodeStream(value)) {
+ assert.truthy(value.readable);
+ }
+ if (value !== undefined) {
+ assert.undefined(this._internals.form);
+ assert.undefined(this._internals.json);
+ }
+ this._internals.body = value;
+ }
+ /**
+ The form body is converted to a query string using [`(new URLSearchParams(object)).toString()`](https://nodejs.org/api/url.html#url_constructor_new_urlsearchparams_obj).
+
+ If the `Content-Type` header is not present, it will be set to `application/x-www-form-urlencoded`.
+
+ __Note #1__: If you provide this option, `got.stream()` will be read-only.
+
+ __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
+ */
+ get form() {
+ return this._internals.form;
+ }
+ set form(value) {
+ assert.any([dist.plainObject, dist.undefined], value);
+ if (value !== undefined) {
+ assert.undefined(this._internals.body);
+ assert.undefined(this._internals.json);
+ }
+ this._internals.form = value;
+ }
+ /**
+ JSON body. If the `Content-Type` header is not set, it will be set to `application/json`.
+
+ __Note #1__: If you provide this option, `got.stream()` will be read-only.
+
+ __Note #2__: This option is not enumerable and will not be merged with the instance defaults.
+ */
+ get json() {
+ return this._internals.json;
+ }
+ set json(value) {
+ if (value !== undefined) {
+ assert.undefined(this._internals.body);
+ assert.undefined(this._internals.form);
+ }
+ this._internals.json = value;
+ }
+ /**
+ The URL to request, as a string, a [`https.request` options object](https://nodejs.org/api/https.html#https_https_request_options_callback), or a [WHATWG `URL`](https://nodejs.org/api/url.html#url_class_url).
+
+ Properties from `options` will override properties in the parsed `url`.
+
+ If no protocol is specified, it will throw a `TypeError`.
+
+ __Note__: The query string is **not** parsed as search params.
+
+ @example
+ ```
+ await got('https://example.com/?query=a b'); //=> https://example.com/?query=a%20b
+ await got('https://example.com/', {searchParams: {query: 'a b'}}); //=> https://example.com/?query=a+b
+
+ // The query string is overridden by `searchParams`
+ await got('https://example.com/?query=a b', {searchParams: {query: 'a b'}}); //=> https://example.com/?query=a+b
+ ```
+ */
+ get url() {
+ return this._internals.url;
+ }
+ set url(value) {
+ assert.any([dist.string, dist.urlInstance, dist.undefined], value);
+ if (value === undefined) {
+ this._internals.url = undefined;
+ return;
+ }
+ if (dist.string(value) && value.startsWith('/')) {
+ throw new Error('`url` must not start with a slash');
+ }
+ const urlString = `${this.prefixUrl}${value.toString()}`;
+ const url = new external_node_url_namespaceObject.URL(urlString);
+ this._internals.url = url;
+ if (url.protocol === 'unix:') {
+ url.href = `http://unix${url.pathname}${url.search}`;
+ }
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
+ const error = new Error(`Unsupported protocol: ${url.protocol}`);
+ error.code = 'ERR_UNSUPPORTED_PROTOCOL';
+ throw error;
+ }
+ if (this._internals.username) {
+ url.username = this._internals.username;
+ this._internals.username = '';
+ }
+ if (this._internals.password) {
+ url.password = this._internals.password;
+ this._internals.password = '';
+ }
+ if (this._internals.searchParams) {
+ url.search = this._internals.searchParams.toString();
+ this._internals.searchParams = undefined;
+ }
+ if (url.hostname === 'unix') {
+ if (!this._internals.enableUnixSockets) {
+ throw new Error('Using UNIX domain sockets but option `enableUnixSockets` is not enabled');
+ }
+ const matches = /(?.+?):(?.+)/.exec(`${url.pathname}${url.search}`);
+ if (matches?.groups) {
+ const { socketPath, path } = matches.groups;
+ this._unixOptions = {
+ socketPath,
+ path,
+ host: '',
+ };
+ }
+ else {
+ this._unixOptions = undefined;
+ }
+ return;
+ }
+ this._unixOptions = undefined;
+ }
+ /**
+ Cookie support. You don't have to care about parsing or how to store them.
+
+ __Note__: If you provide this option, `options.headers.cookie` will be overridden.
+ */
+ get cookieJar() {
+ return this._internals.cookieJar;
+ }
+ set cookieJar(value) {
+ assert.any([dist.object, dist.undefined], value);
+ if (value === undefined) {
+ this._internals.cookieJar = undefined;
+ return;
+ }
+ let { setCookie, getCookieString } = value;
+ assert.function_(setCookie);
+ assert.function_(getCookieString);
+ /* istanbul ignore next: Horrible `tough-cookie` v3 check */
+ if (setCookie.length === 4 && getCookieString.length === 0) {
+ setCookie = (0,external_node_util_namespaceObject.promisify)(setCookie.bind(value));
+ getCookieString = (0,external_node_util_namespaceObject.promisify)(getCookieString.bind(value));
+ this._internals.cookieJar = {
+ setCookie,
+ getCookieString: getCookieString,
+ };
+ }
+ else {
+ this._internals.cookieJar = value;
+ }
+ }
+ /**
+ You can abort the `request` using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
+
+ *Requires Node.js 16 or later.*
+
+ @example
+ ```
+ import got from 'got';
+
+ const abortController = new AbortController();
+
+ const request = got('https://httpbin.org/anything', {
+ signal: abortController.signal
+ });
+
+ setTimeout(() => {
+ abortController.abort();
+ }, 100);
+ ```
+ */
+ // TODO: Replace `any` with `AbortSignal` when targeting Node 16.
+ get signal() {
+ return this._internals.signal;
+ }
+ // TODO: Replace `any` with `AbortSignal` when targeting Node 16.
+ set signal(value) {
+ assert.object(value);
+ this._internals.signal = value;
+ }
+ /**
+ Ignore invalid cookies instead of throwing an error.
+ Only useful when the `cookieJar` option has been set. Not recommended.
+
+ @default false
+ */
+ get ignoreInvalidCookies() {
+ return this._internals.ignoreInvalidCookies;
+ }
+ set ignoreInvalidCookies(value) {
+ assert.boolean(value);
+ this._internals.ignoreInvalidCookies = value;
+ }
+ /**
+ Query string that will be added to the request URL.
+ This will override the query string in `url`.
+
+ If you need to pass in an array, you can do it using a `URLSearchParams` instance.
+
+ @example
+ ```
+ import got from 'got';
+
+ const searchParams = new URLSearchParams([['key', 'a'], ['key', 'b']]);
+
+ await got('https://example.com', {searchParams});
+
+ console.log(searchParams.toString());
+ //=> 'key=a&key=b'
+ ```
+ */
+ get searchParams() {
+ if (this._internals.url) {
+ return this._internals.url.searchParams;
+ }
+ if (this._internals.searchParams === undefined) {
+ this._internals.searchParams = new external_node_url_namespaceObject.URLSearchParams();
+ }
+ return this._internals.searchParams;
+ }
+ set searchParams(value) {
+ assert.any([dist.string, dist.object, dist.undefined], value);
+ const url = this._internals.url;
+ if (value === undefined) {
+ this._internals.searchParams = undefined;
+ if (url) {
+ url.search = '';
+ }
+ return;
+ }
+ const searchParameters = this.searchParams;
+ let updated;
+ if (dist.string(value)) {
+ updated = new external_node_url_namespaceObject.URLSearchParams(value);
+ }
+ else if (value instanceof external_node_url_namespaceObject.URLSearchParams) {
+ updated = value;
+ }
+ else {
+ validateSearchParameters(value);
+ updated = new external_node_url_namespaceObject.URLSearchParams();
+ // eslint-disable-next-line guard-for-in
+ for (const key in value) {
+ const entry = value[key];
+ if (entry === null) {
+ updated.append(key, '');
+ }
+ else if (entry === undefined) {
+ searchParameters.delete(key);
+ }
+ else {
+ updated.append(key, entry);
+ }
+ }
+ }
+ if (this._merging) {
+ // These keys will be replaced
+ for (const key of updated.keys()) {
+ searchParameters.delete(key);
+ }
+ for (const [key, value] of updated) {
+ searchParameters.append(key, value);
+ }
+ }
+ else if (url) {
+ url.search = searchParameters.toString();
+ }
+ else {
+ this._internals.searchParams = searchParameters;
+ }
+ }
+ get searchParameters() {
+ throw new Error('The `searchParameters` option does not exist. Use `searchParams` instead.');
+ }
+ set searchParameters(_value) {
+ throw new Error('The `searchParameters` option does not exist. Use `searchParams` instead.');
+ }
+ get dnsLookup() {
+ return this._internals.dnsLookup;
+ }
+ set dnsLookup(value) {
+ assert.any([dist.function_, dist.undefined], value);
+ this._internals.dnsLookup = value;
+ }
+ /**
+ An instance of [`CacheableLookup`](https://github.com/szmarczak/cacheable-lookup) used for making DNS lookups.
+ Useful when making lots of requests to different *public* hostnames.
+
+ `CacheableLookup` uses `dns.resolver4(..)` and `dns.resolver6(...)` under the hood and fall backs to `dns.lookup(...)` when the first two fail, which may lead to additional delay.
+
+ __Note__: This should stay disabled when making requests to internal hostnames such as `localhost`, `database.local` etc.
+
+ @default false
+ */
+ get dnsCache() {
+ return this._internals.dnsCache;
+ }
+ set dnsCache(value) {
+ assert.any([dist.object, dist.boolean, dist.undefined], value);
+ if (value === true) {
+ this._internals.dnsCache = getGlobalDnsCache();
+ }
+ else if (value === false) {
+ this._internals.dnsCache = undefined;
+ }
+ else {
+ this._internals.dnsCache = value;
+ }
+ }
+ /**
+ User data. `context` is shallow merged and enumerable. If it contains non-enumerable properties they will NOT be merged.
+
+ @example
+ ```
+ import got from 'got';
+
+ const instance = got.extend({
+ hooks: {
+ beforeRequest: [
+ options => {
+ if (!options.context || !options.context.token) {
+ throw new Error('Token required');
+ }
+
+ options.headers.token = options.context.token;
+ }
+ ]
+ }
+ });
+
+ const context = {
+ token: 'secret'
+ };
+
+ const response = await instance('https://httpbin.org/headers', {context});
+
+ // Let's see the headers
+ console.log(response.body);
+ ```
+ */
+ get context() {
+ return this._internals.context;
+ }
+ set context(value) {
+ assert.object(value);
+ if (this._merging) {
+ Object.assign(this._internals.context, value);
+ }
+ else {
+ this._internals.context = { ...value };
+ }
+ }
+ /**
+ Hooks allow modifications during the request lifecycle.
+ Hook functions may be async and are run serially.
+ */
+ get hooks() {
+ return this._internals.hooks;
+ }
+ set hooks(value) {
+ assert.object(value);
+ // eslint-disable-next-line guard-for-in
+ for (const knownHookEvent in value) {
+ if (!(knownHookEvent in this._internals.hooks)) {
+ throw new Error(`Unexpected hook event: ${knownHookEvent}`);
+ }
+ const typedKnownHookEvent = knownHookEvent;
+ const hooks = value[typedKnownHookEvent];
+ assert.any([dist.array, dist.undefined], hooks);
+ if (hooks) {
+ for (const hook of hooks) {
+ assert.function_(hook);
+ }
+ }
+ if (this._merging) {
+ if (hooks) {
+ // @ts-expect-error FIXME
+ this._internals.hooks[typedKnownHookEvent].push(...hooks);
+ }
+ }
+ else {
+ if (!hooks) {
+ throw new Error(`Missing hook event: ${knownHookEvent}`);
+ }
+ // @ts-expect-error FIXME
+ this._internals.hooks[knownHookEvent] = [...hooks];
+ }
+ }
+ }
+ /**
+ Defines if redirect responses should be followed automatically.
+
+ Note that if a `303` is sent by the server in response to any request type (`POST`, `DELETE`, etc.), Got will automatically request the resource pointed to in the location header via `GET`.
+ This is in accordance with [the spec](https://tools.ietf.org/html/rfc7231#section-6.4.4). You can optionally turn on this behavior also for other redirect codes - see `methodRewriting`.
+
+ @default true
+ */
+ get followRedirect() {
+ return this._internals.followRedirect;
+ }
+ set followRedirect(value) {
+ assert.boolean(value);
+ this._internals.followRedirect = value;
+ }
+ get followRedirects() {
+ throw new TypeError('The `followRedirects` option does not exist. Use `followRedirect` instead.');
+ }
+ set followRedirects(_value) {
+ throw new TypeError('The `followRedirects` option does not exist. Use `followRedirect` instead.');
+ }
+ /**
+ If exceeded, the request will be aborted and a `MaxRedirectsError` will be thrown.
+
+ @default 10
+ */
+ get maxRedirects() {
+ return this._internals.maxRedirects;
+ }
+ set maxRedirects(value) {
+ assert.number(value);
+ this._internals.maxRedirects = value;
+ }
+ /**
+ A cache adapter instance for storing cached response data.
+
+ @default false
+ */
+ get cache() {
+ return this._internals.cache;
+ }
+ set cache(value) {
+ assert.any([dist.object, dist.string, dist.boolean, dist.undefined], value);
+ if (value === true) {
+ this._internals.cache = globalCache;
+ }
+ else if (value === false) {
+ this._internals.cache = undefined;
+ }
+ else {
+ this._internals.cache = value;
+ }
+ }
+ /**
+ Determines if a `got.HTTPError` is thrown for unsuccessful responses.
+
+ If this is disabled, requests that encounter an error status code will be resolved with the `response` instead of throwing.
+ This may be useful if you are checking for resource availability and are expecting error responses.
+
+ @default true
+ */
+ get throwHttpErrors() {
+ return this._internals.throwHttpErrors;
+ }
+ set throwHttpErrors(value) {
+ assert.boolean(value);
+ this._internals.throwHttpErrors = value;
+ }
+ get username() {
+ const url = this._internals.url;
+ const value = url ? url.username : this._internals.username;
+ return decodeURIComponent(value);
+ }
+ set username(value) {
+ assert.string(value);
+ const url = this._internals.url;
+ const fixedValue = encodeURIComponent(value);
+ if (url) {
+ url.username = fixedValue;
+ }
+ else {
+ this._internals.username = fixedValue;
+ }
+ }
+ get password() {
+ const url = this._internals.url;
+ const value = url ? url.password : this._internals.password;
+ return decodeURIComponent(value);
+ }
+ set password(value) {
+ assert.string(value);
+ const url = this._internals.url;
+ const fixedValue = encodeURIComponent(value);
+ if (url) {
+ url.password = fixedValue;
+ }
+ else {
+ this._internals.password = fixedValue;
+ }
+ }
+ /**
+ If set to `true`, Got will additionally accept HTTP2 requests.
+
+ It will choose either HTTP/1.1 or HTTP/2 depending on the ALPN protocol.
+
+ __Note__: This option requires Node.js 15.10.0 or newer as HTTP/2 support on older Node.js versions is very buggy.
+
+ __Note__: Overriding `options.request` will disable HTTP2 support.
+
+ @default false
+
+ @example
+ ```
+ import got from 'got';
+
+ const {headers} = await got('https://nghttp2.org/httpbin/anything', {http2: true});
+
+ console.log(headers.via);
+ //=> '2 nghttpx'
+ ```
+ */
+ get http2() {
+ return this._internals.http2;
+ }
+ set http2(value) {
+ assert.boolean(value);
+ this._internals.http2 = value;
+ }
+ /**
+ Set this to `true` to allow sending body for the `GET` method.
+ However, the [HTTP/2 specification](https://tools.ietf.org/html/rfc7540#section-8.1.3) says that `An HTTP GET request includes request header fields and no payload body`, therefore when using the HTTP/2 protocol this option will have no effect.
+ This option is only meant to interact with non-compliant servers when you have no other choice.
+
+ __Note__: The [RFC 7231](https://tools.ietf.org/html/rfc7231#section-4.3.1) doesn't specify any particular behavior for the GET method having a payload, therefore __it's considered an [anti-pattern](https://en.wikipedia.org/wiki/Anti-pattern)__.
+
+ @default false
+ */
+ get allowGetBody() {
+ return this._internals.allowGetBody;
+ }
+ set allowGetBody(value) {
+ assert.boolean(value);
+ this._internals.allowGetBody = value;
+ }
+ /**
+ Request headers.
+
+ Existing headers will be overwritten. Headers set to `undefined` will be omitted.
+
+ @default {}
+ */
+ get headers() {
+ return this._internals.headers;
+ }
+ set headers(value) {
+ assert.plainObject(value);
+ if (this._merging) {
+ Object.assign(this._internals.headers, lowercaseKeys(value));
+ }
+ else {
+ this._internals.headers = lowercaseKeys(value);
+ }
+ }
+ /**
+ Specifies if the HTTP request method should be [rewritten as `GET`](https://tools.ietf.org/html/rfc7231#section-6.4) on redirects.
+
+ As the [specification](https://tools.ietf.org/html/rfc7231#section-6.4) prefers to rewrite the HTTP method only on `303` responses, this is Got's default behavior.
+ Setting `methodRewriting` to `true` will also rewrite `301` and `302` responses, as allowed by the spec. This is the behavior followed by `curl` and browsers.
+
+ __Note__: Got never performs method rewriting on `307` and `308` responses, as this is [explicitly prohibited by the specification](https://www.rfc-editor.org/rfc/rfc7231#section-6.4.7).
+
+ @default false
+ */
+ get methodRewriting() {
+ return this._internals.methodRewriting;
+ }
+ set methodRewriting(value) {
+ assert.boolean(value);
+ this._internals.methodRewriting = value;
+ }
+ /**
+ Indicates which DNS record family to use.
+
+ Values:
+ - `undefined`: IPv4 (if present) or IPv6
+ - `4`: Only IPv4
+ - `6`: Only IPv6
+
+ @default undefined
+ */
+ get dnsLookupIpVersion() {
+ return this._internals.dnsLookupIpVersion;
+ }
+ set dnsLookupIpVersion(value) {
+ if (value !== undefined && value !== 4 && value !== 6) {
+ throw new TypeError(`Invalid DNS lookup IP version: ${value}`);
+ }
+ this._internals.dnsLookupIpVersion = value;
+ }
+ /**
+ A function used to parse JSON responses.
+
+ @example
+ ```
+ import got from 'got';
+ import Bourne from '@hapi/bourne';
+
+ const parsed = await got('https://example.com', {
+ parseJson: text => Bourne.parse(text)
+ }).json();
+
+ console.log(parsed);
+ ```
+ */
+ get parseJson() {
+ return this._internals.parseJson;
+ }
+ set parseJson(value) {
+ assert.function_(value);
+ this._internals.parseJson = value;
+ }
+ /**
+ A function used to stringify the body of JSON requests.
+
+ @example
+ ```
+ import got from 'got';
+
+ await got.post('https://example.com', {
+ stringifyJson: object => JSON.stringify(object, (key, value) => {
+ if (key.startsWith('_')) {
+ return;
+ }
+
+ return value;
+ }),
+ json: {
+ some: 'payload',
+ _ignoreMe: 1234
+ }
+ });
+ ```
+
+ @example
+ ```
+ import got from 'got';
+
+ await got.post('https://example.com', {
+ stringifyJson: object => JSON.stringify(object, (key, value) => {
+ if (typeof value === 'number') {
+ return value.toString();
+ }
+
+ return value;
+ }),
+ json: {
+ some: 'payload',
+ number: 1
+ }
+ });
+ ```
+ */
+ get stringifyJson() {
+ return this._internals.stringifyJson;
+ }
+ set stringifyJson(value) {
+ assert.function_(value);
+ this._internals.stringifyJson = value;
+ }
+ /**
+ An object representing `limit`, `calculateDelay`, `methods`, `statusCodes`, `maxRetryAfter` and `errorCodes` fields for maximum retry count, retry handler, allowed methods, allowed status codes, maximum [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) time and allowed error codes.
+
+ Delays between retries counts with function `1000 * Math.pow(2, retry) + Math.random() * 100`, where `retry` is attempt number (starts from 1).
+
+ The `calculateDelay` property is a `function` that receives an object with `attemptCount`, `retryOptions`, `error` and `computedValue` properties for current retry count, the retry options, error and default computed value.
+ The function must return a delay in milliseconds (or a Promise resolving with it) (`0` return value cancels retry).
+
+ By default, it retries *only* on the specified methods, status codes, and on these network errors:
+
+ - `ETIMEDOUT`: One of the [timeout](#timeout) limits were reached.
+ - `ECONNRESET`: Connection was forcibly closed by a peer.
+ - `EADDRINUSE`: Could not bind to any free port.
+ - `ECONNREFUSED`: Connection was refused by the server.
+ - `EPIPE`: The remote side of the stream being written has been closed.
+ - `ENOTFOUND`: Couldn't resolve the hostname to an IP address.
+ - `ENETUNREACH`: No internet connection.
+ - `EAI_AGAIN`: DNS lookup timed out.
+
+ __Note__: If `maxRetryAfter` is set to `undefined`, it will use `options.timeout`.
+ __Note__: If [`Retry-After`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) header is greater than `maxRetryAfter`, it will cancel the request.
+ */
+ get retry() {
+ return this._internals.retry;
+ }
+ set retry(value) {
+ assert.plainObject(value);
+ assert.any([dist.function_, dist.undefined], value.calculateDelay);
+ assert.any([dist.number, dist.undefined], value.maxRetryAfter);
+ assert.any([dist.number, dist.undefined], value.limit);
+ assert.any([dist.array, dist.undefined], value.methods);
+ assert.any([dist.array, dist.undefined], value.statusCodes);
+ assert.any([dist.array, dist.undefined], value.errorCodes);
+ assert.any([dist.number, dist.undefined], value.noise);
+ if (value.noise && Math.abs(value.noise) > 100) {
+ throw new Error(`The maximum acceptable retry noise is +/- 100ms, got ${value.noise}`);
+ }
+ for (const key in value) {
+ if (!(key in this._internals.retry)) {
+ throw new Error(`Unexpected retry option: ${key}`);
+ }
+ }
+ if (this._merging) {
+ Object.assign(this._internals.retry, value);
+ }
+ else {
+ this._internals.retry = { ...value };
+ }
+ const { retry } = this._internals;
+ retry.methods = [...new Set(retry.methods.map(method => method.toUpperCase()))];
+ retry.statusCodes = [...new Set(retry.statusCodes)];
+ retry.errorCodes = [...new Set(retry.errorCodes)];
+ }
+ /**
+ From `http.RequestOptions`.
+
+ The IP address used to send the request from.
+ */
+ get localAddress() {
+ return this._internals.localAddress;
+ }
+ set localAddress(value) {
+ assert.any([dist.string, dist.undefined], value);
+ this._internals.localAddress = value;
+ }
+ /**
+ The HTTP method used to make the request.
+
+ @default 'GET'
+ */
+ get method() {
+ return this._internals.method;
+ }
+ set method(value) {
+ assert.string(value);
+ this._internals.method = value.toUpperCase();
+ }
+ get createConnection() {
+ return this._internals.createConnection;
+ }
+ set createConnection(value) {
+ assert.any([dist.function_, dist.undefined], value);
+ this._internals.createConnection = value;
+ }
+ /**
+ From `http-cache-semantics`
+
+ @default {}
+ */
+ get cacheOptions() {
+ return this._internals.cacheOptions;
+ }
+ set cacheOptions(value) {
+ assert.plainObject(value);
+ assert.any([dist.boolean, dist.undefined], value.shared);
+ assert.any([dist.number, dist.undefined], value.cacheHeuristic);
+ assert.any([dist.number, dist.undefined], value.immutableMinTimeToLive);
+ assert.any([dist.boolean, dist.undefined], value.ignoreCargoCult);
+ for (const key in value) {
+ if (!(key in this._internals.cacheOptions)) {
+ throw new Error(`Cache option \`${key}\` does not exist`);
+ }
+ }
+ if (this._merging) {
+ Object.assign(this._internals.cacheOptions, value);
+ }
+ else {
+ this._internals.cacheOptions = { ...value };
+ }
+ }
+ /**
+ Options for the advanced HTTPS API.
+ */
+ get https() {
+ return this._internals.https;
+ }
+ set https(value) {
+ assert.plainObject(value);
+ assert.any([dist.boolean, dist.undefined], value.rejectUnauthorized);
+ assert.any([dist.function_, dist.undefined], value.checkServerIdentity);
+ assert.any([dist.string, dist.object, dist.array, dist.undefined], value.certificateAuthority);
+ assert.any([dist.string, dist.object, dist.array, dist.undefined], value.key);
+ assert.any([dist.string, dist.object, dist.array, dist.undefined], value.certificate);
+ assert.any([dist.string, dist.undefined], value.passphrase);
+ assert.any([dist.string, dist.buffer, dist.array, dist.undefined], value.pfx);
+ assert.any([dist.array, dist.undefined], value.alpnProtocols);
+ assert.any([dist.string, dist.undefined], value.ciphers);
+ assert.any([dist.string, dist.buffer, dist.undefined], value.dhparam);
+ assert.any([dist.string, dist.undefined], value.signatureAlgorithms);
+ assert.any([dist.string, dist.undefined], value.minVersion);
+ assert.any([dist.string, dist.undefined], value.maxVersion);
+ assert.any([dist.boolean, dist.undefined], value.honorCipherOrder);
+ assert.any([dist.number, dist.undefined], value.tlsSessionLifetime);
+ assert.any([dist.string, dist.undefined], value.ecdhCurve);
+ assert.any([dist.string, dist.buffer, dist.array, dist.undefined], value.certificateRevocationLists);
+ for (const key in value) {
+ if (!(key in this._internals.https)) {
+ throw new Error(`HTTPS option \`${key}\` does not exist`);
+ }
+ }
+ if (this._merging) {
+ Object.assign(this._internals.https, value);
+ }
+ else {
+ this._internals.https = { ...value };
+ }
+ }
+ /**
+ [Encoding](https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings) to be used on `setEncoding` of the response data.
+
+ To get a [`Buffer`](https://nodejs.org/api/buffer.html), you need to set `responseType` to `buffer` instead.
+ Don't set this option to `null`.
+
+ __Note__: This doesn't affect streams! Instead, you need to do `got.stream(...).setEncoding(encoding)`.
+
+ @default 'utf-8'
+ */
+ get encoding() {
+ return this._internals.encoding;
+ }
+ set encoding(value) {
+ if (value === null) {
+ throw new TypeError('To get a Buffer, set `options.responseType` to `buffer` instead');
+ }
+ assert.any([dist.string, dist.undefined], value);
+ this._internals.encoding = value;
+ }
+ /**
+ When set to `true` the promise will return the Response body instead of the Response object.
+
+ @default false
+ */
+ get resolveBodyOnly() {
+ return this._internals.resolveBodyOnly;
+ }
+ set resolveBodyOnly(value) {
+ assert.boolean(value);
+ this._internals.resolveBodyOnly = value;
+ }
+ /**
+ Returns a `Stream` instead of a `Promise`.
+ This is equivalent to calling `got.stream(url, options?)`.
+
+ @default false
+ */
+ get isStream() {
+ return this._internals.isStream;
+ }
+ set isStream(value) {
+ assert.boolean(value);
+ this._internals.isStream = value;
+ }
+ /**
+ The parsing method.
+
+ The promise also has `.text()`, `.json()` and `.buffer()` methods which return another Got promise for the parsed body.
+
+ It's like setting the options to `{responseType: 'json', resolveBodyOnly: true}` but without affecting the main Got promise.
+
+ __Note__: When using streams, this option is ignored.
+
+ @example
+ ```
+ const responsePromise = got(url);
+ const bufferPromise = responsePromise.buffer();
+ const jsonPromise = responsePromise.json();
+
+ const [response, buffer, json] = Promise.all([responsePromise, bufferPromise, jsonPromise]);
+ // `response` is an instance of Got Response
+ // `buffer` is an instance of Buffer
+ // `json` is an object
+ ```
+
+ @example
+ ```
+ // This
+ const body = await got(url).json();
+
+ // is semantically the same as this
+ const body = await got(url, {responseType: 'json', resolveBodyOnly: true});
+ ```
+ */
+ get responseType() {
+ return this._internals.responseType;
+ }
+ set responseType(value) {
+ if (value === undefined) {
+ this._internals.responseType = 'text';
+ return;
+ }
+ if (value !== 'text' && value !== 'buffer' && value !== 'json') {
+ throw new Error(`Invalid \`responseType\` option: ${value}`);
+ }
+ this._internals.responseType = value;
+ }
+ get pagination() {
+ return this._internals.pagination;
+ }
+ set pagination(value) {
+ assert.object(value);
+ if (this._merging) {
+ Object.assign(this._internals.pagination, value);
+ }
+ else {
+ this._internals.pagination = value;
+ }
+ }
+ get auth() {
+ throw new Error('Parameter `auth` is deprecated. Use `username` / `password` instead.');
+ }
+ set auth(_value) {
+ throw new Error('Parameter `auth` is deprecated. Use `username` / `password` instead.');
+ }
+ get setHost() {
+ return this._internals.setHost;
+ }
+ set setHost(value) {
+ assert.boolean(value);
+ this._internals.setHost = value;
+ }
+ get maxHeaderSize() {
+ return this._internals.maxHeaderSize;
+ }
+ set maxHeaderSize(value) {
+ assert.any([dist.number, dist.undefined], value);
+ this._internals.maxHeaderSize = value;
+ }
+ get enableUnixSockets() {
+ return this._internals.enableUnixSockets;
+ }
+ set enableUnixSockets(value) {
+ assert.boolean(value);
+ this._internals.enableUnixSockets = value;
+ }
+ // eslint-disable-next-line @typescript-eslint/naming-convention
+ toJSON() {
+ return { ...this._internals };
+ }
+ [Symbol.for('nodejs.util.inspect.custom')](_depth, options) {
+ return (0,external_node_util_namespaceObject.inspect)(this._internals, options);
+ }
+ createNativeRequestOptions() {
+ const internals = this._internals;
+ const url = internals.url;
+ let agent;
+ if (url.protocol === 'https:') {
+ agent = internals.http2 ? internals.agent : internals.agent.https;
+ }
+ else {
+ agent = internals.agent.http;
+ }
+ const { https } = internals;
+ let { pfx } = https;
+ if (dist.array(pfx) && dist.plainObject(pfx[0])) {
+ pfx = pfx.map(object => ({
+ buf: object.buffer,
+ passphrase: object.passphrase,
+ }));
+ }
+ return {
+ ...internals.cacheOptions,
+ ...this._unixOptions,
+ // HTTPS options
+ // eslint-disable-next-line @typescript-eslint/naming-convention
+ ALPNProtocols: https.alpnProtocols,
+ ca: https.certificateAuthority,
+ cert: https.certificate,
+ key: https.key,
+ passphrase: https.passphrase,
+ pfx: https.pfx,
+ rejectUnauthorized: https.rejectUnauthorized,
+ checkServerIdentity: https.checkServerIdentity ?? external_node_tls_namespaceObject.checkServerIdentity,
+ ciphers: https.ciphers,
+ honorCipherOrder: https.honorCipherOrder,
+ minVersion: https.minVersion,
+ maxVersion: https.maxVersion,
+ sigalgs: https.signatureAlgorithms,
+ sessionTimeout: https.tlsSessionLifetime,
+ dhparam: https.dhparam,
+ ecdhCurve: https.ecdhCurve,
+ crl: https.certificateRevocationLists,
+ // HTTP options
+ lookup: internals.dnsLookup ?? internals.dnsCache?.lookup,
+ family: internals.dnsLookupIpVersion,
+ agent,
+ setHost: internals.setHost,
+ method: internals.method,
+ maxHeaderSize: internals.maxHeaderSize,
+ localAddress: internals.localAddress,
+ headers: internals.headers,
+ createConnection: internals.createConnection,
+ timeout: internals.http2 ? getHttp2TimeoutOption(internals) : undefined,
+ // HTTP/2 options
+ h2session: internals.h2session,
+ };
+ }
+ getRequestFunction() {
+ const url = this._internals.url;
+ const { request } = this._internals;
+ if (!request && url) {
+ return this.getFallbackRequestFunction();
+ }
+ return request;
+ }
+ getFallbackRequestFunction() {
+ const url = this._internals.url;
+ if (!url) {
+ return;
+ }
+ if (url.protocol === 'https:') {
+ if (this._internals.http2) {
+ if (major < 15 || (major === 15 && minor < 10)) {
+ const error = new Error('To use the `http2` option, install Node.js 15.10.0 or above');
+ error.code = 'EUNSUPPORTED';
+ throw error;
+ }
+ return http2_wrapper_source.auto;
+ }
+ return external_node_https_namespaceObject.request;
+ }
+ return external_node_http_namespaceObject.request;
+ }
+ freeze() {
+ const options = this._internals;
+ Object.freeze(options);
+ Object.freeze(options.hooks);
+ Object.freeze(options.hooks.afterResponse);
+ Object.freeze(options.hooks.beforeError);
+ Object.freeze(options.hooks.beforeRedirect);
+ Object.freeze(options.hooks.beforeRequest);
+ Object.freeze(options.hooks.beforeRetry);
+ Object.freeze(options.hooks.init);
+ Object.freeze(options.https);
+ Object.freeze(options.cacheOptions);
+ Object.freeze(options.agent);
+ Object.freeze(options.headers);
+ Object.freeze(options.timeout);
+ Object.freeze(options.retry);
+ Object.freeze(options.retry.errorCodes);
+ Object.freeze(options.retry.methods);
+ Object.freeze(options.retry.statusCodes);
+ }
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/response.js
+
+const isResponseOk = (response) => {
+ const { statusCode } = response;
+ const limitStatusCode = response.request.options.followRedirect ? 299 : 399;
+ return (statusCode >= 200 && statusCode <= limitStatusCode) || statusCode === 304;
+};
+/**
+An error to be thrown when server response code is 2xx, and parsing body fails.
+Includes a `response` property.
+*/
+class ParseError extends RequestError {
+ constructor(error, response) {
+ const { options } = response.request;
+ super(`${error.message} in "${options.url.toString()}"`, error, response.request);
+ this.name = 'ParseError';
+ this.code = 'ERR_BODY_PARSE_FAILURE';
+ }
+}
+const parseBody = (response, responseType, parseJson, encoding) => {
+ const { rawBody } = response;
+ try {
+ if (responseType === 'text') {
+ return rawBody.toString(encoding);
+ }
+ if (responseType === 'json') {
+ return rawBody.length === 0 ? '' : parseJson(rawBody.toString(encoding));
+ }
+ if (responseType === 'buffer') {
+ return rawBody;
+ }
+ }
+ catch (error) {
+ throw new ParseError(error, response);
+ }
+ throw new ParseError({
+ message: `Unknown body type '${responseType}'`,
+ name: 'Error',
+ }, response);
+};
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/is-client-request.js
+function isClientRequest(clientRequest) {
+ return clientRequest.writable && !clientRequest.writableEnded;
+}
+/* harmony default export */ const is_client_request = (isClientRequest);
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/utils/is-unix-socket-url.js
+// eslint-disable-next-line @typescript-eslint/naming-convention
+function isUnixSocketURL(url) {
+ return url.protocol === 'unix:' || url.hostname === 'unix';
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/core/index.js
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+const { buffer: getBuffer } = get_stream;
+const supportsBrotli = dist.string(external_node_process_namespaceObject.versions.brotli);
+const methodsWithoutBody = new Set(['GET', 'HEAD']);
+const cacheableStore = new WeakableMap();
+const redirectCodes = new Set([300, 301, 302, 303, 304, 307, 308]);
+const proxiedRequestEvents = [
+ 'socket',
+ 'connect',
+ 'continue',
+ 'information',
+ 'upgrade',
+];
+const core_noop = () => { };
+class Request extends external_node_stream_namespaceObject.Duplex {
+ constructor(url, options, defaults) {
+ super({
+ // Don't destroy immediately, as the error may be emitted on unsuccessful retry
+ autoDestroy: false,
+ // It needs to be zero because we're just proxying the data to another stream
+ highWaterMark: 0,
+ });
+ // @ts-expect-error - Ignoring for now.
+ Object.defineProperty(this, 'constructor', {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_noPipe", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ // @ts-expect-error https://github.com/microsoft/TypeScript/issues/9568
+ Object.defineProperty(this, "options", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "response", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "requestUrl", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "redirectUrls", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "retryCount", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_stopRetry", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_downloadedSize", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_uploadedSize", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_stopReading", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_pipedServerResponses", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_request", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_responseSize", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_bodySize", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_unproxyEvents", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_isFromCache", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_cannotHaveBody", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_triggerRead", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_cancelTimeouts", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_removeListeners", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_nativeResponse", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_flushed", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ Object.defineProperty(this, "_aborted", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ // We need this because `this._request` if `undefined` when using cache
+ Object.defineProperty(this, "_requestInitialized", {
+ enumerable: true,
+ configurable: true,
+ writable: true,
+ value: void 0
+ });
+ this._downloadedSize = 0;
+ this._uploadedSize = 0;
+ this._stopReading = false;
+ this._pipedServerResponses = new Set();
+ this._cannotHaveBody = false;
+ this._unproxyEvents = core_noop;
+ this._triggerRead = false;
+ this._cancelTimeouts = core_noop;
+ this._removeListeners = core_noop;
+ this._jobs = [];
+ this._flushed = false;
+ this._requestInitialized = false;
+ this._aborted = false;
+ this.redirectUrls = [];
+ this.retryCount = 0;
+ this._stopRetry = core_noop;
+ this.on('pipe', (source) => {
+ if (source?.headers) {
+ Object.assign(this.options.headers, source.headers);
+ }
+ });
+ this.on('newListener', event => {
+ if (event === 'retry' && this.listenerCount('retry') > 0) {
+ throw new Error('A retry listener has been attached already.');
+ }
+ });
+ try {
+ this.options = new Options(url, options, defaults);
+ if (!this.options.url) {
+ if (this.options.prefixUrl === '') {
+ throw new TypeError('Missing `url` property');
+ }
+ this.options.url = '';
+ }
+ this.requestUrl = this.options.url;
+ }
+ catch (error) {
+ const { options } = error;
+ if (options) {
+ this.options = options;
+ }
+ this.flush = async () => {
+ this.flush = async () => { };
+ this.destroy(error);
+ };
+ return;
+ }
+ // Important! If you replace `body` in a handler with another stream, make sure it's readable first.
+ // The below is run only once.
+ const { body } = this.options;
+ if (dist.nodeStream(body)) {
+ body.once('error', error => {
+ if (this._flushed) {
+ this._beforeError(new UploadError(error, this));
+ }
+ else {
+ this.flush = async () => {
+ this.flush = async () => { };
+ this._beforeError(new UploadError(error, this));
+ };
+ }
+ });
+ }
+ if (this.options.signal) {
+ const abort = () => {
+ this.destroy(new AbortError(this));
+ };
+ if (this.options.signal.aborted) {
+ abort();
+ }
+ else {
+ this.options.signal.addEventListener('abort', abort);
+ this._removeListeners = () => {
+ this.options.signal.removeEventListener('abort', abort);
+ };
+ }
+ }
+ }
+ async flush() {
+ if (this._flushed) {
+ return;
+ }
+ this._flushed = true;
+ try {
+ await this._finalizeBody();
+ if (this.destroyed) {
+ return;
+ }
+ await this._makeRequest();
+ if (this.destroyed) {
+ this._request?.destroy();
+ return;
+ }
+ // Queued writes etc.
+ for (const job of this._jobs) {
+ job();
+ }
+ // Prevent memory leak
+ this._jobs.length = 0;
+ this._requestInitialized = true;
+ }
+ catch (error) {
+ this._beforeError(error);
+ }
+ }
+ _beforeError(error) {
+ if (this._stopReading) {
+ return;
+ }
+ const { response, options } = this;
+ const attemptCount = this.retryCount + (error.name === 'RetryError' ? 0 : 1);
+ this._stopReading = true;
+ if (!(error instanceof RequestError)) {
+ error = new RequestError(error.message, error, this);
+ }
+ const typedError = error;
+ void (async () => {
+ // Node.js parser is really weird.
+ // It emits post-request Parse Errors on the same instance as previous request. WTF.
+ // Therefore we need to check if it has been destroyed as well.
+ //
+ // Furthermore, Node.js 16 `response.destroy()` doesn't immediately destroy the socket,
+ // but makes the response unreadable. So we additionally need to check `response.readable`.
+ if (response?.readable && !response.rawBody && !this._request?.socket?.destroyed) {
+ // @types/node has incorrect typings. `setEncoding` accepts `null` as well.
+ response.setEncoding(this.readableEncoding);
+ const success = await this._setRawBody(response);
+ if (success) {
+ response.body = response.rawBody.toString();
+ }
+ }
+ if (this.listenerCount('retry') !== 0) {
+ let backoff;
+ try {
+ let retryAfter;
+ if (response && 'retry-after' in response.headers) {
+ retryAfter = Number(response.headers['retry-after']);
+ if (Number.isNaN(retryAfter)) {
+ retryAfter = Date.parse(response.headers['retry-after']) - Date.now();
+ if (retryAfter <= 0) {
+ retryAfter = 1;
+ }
+ }
+ else {
+ retryAfter *= 1000;
+ }
+ }
+ const retryOptions = options.retry;
+ backoff = await retryOptions.calculateDelay({
+ attemptCount,
+ retryOptions,
+ error: typedError,
+ retryAfter,
+ computedValue: calculate_retry_delay({
+ attemptCount,
+ retryOptions,
+ error: typedError,
+ retryAfter,
+ computedValue: retryOptions.maxRetryAfter ?? options.timeout.request ?? Number.POSITIVE_INFINITY,
+ }),
+ });
+ }
+ catch (error_) {
+ void this._error(new RequestError(error_.message, error_, this));
+ return;
+ }
+ if (backoff) {
+ await new Promise(resolve => {
+ const timeout = setTimeout(resolve, backoff);
+ this._stopRetry = () => {
+ clearTimeout(timeout);
+ resolve();
+ };
+ });
+ // Something forced us to abort the retry
+ if (this.destroyed) {
+ return;
+ }
+ try {
+ for (const hook of this.options.hooks.beforeRetry) {
+ // eslint-disable-next-line no-await-in-loop
+ await hook(typedError, this.retryCount + 1);
+ }
+ }
+ catch (error_) {
+ void this._error(new RequestError(error_.message, error, this));
+ return;
+ }
+ // Something forced us to abort the retry
+ if (this.destroyed) {
+ return;
+ }
+ this.destroy();
+ this.emit('retry', this.retryCount + 1, error, (updatedOptions) => {
+ const request = new Request(options.url, updatedOptions, options);
+ request.retryCount = this.retryCount + 1;
+ external_node_process_namespaceObject.nextTick(() => {
+ void request.flush();
+ });
+ return request;
+ });
+ return;
+ }
+ }
+ void this._error(typedError);
+ })();
+ }
+ _read() {
+ this._triggerRead = true;
+ const { response } = this;
+ if (response && !this._stopReading) {
+ // We cannot put this in the `if` above
+ // because `.read()` also triggers the `end` event
+ if (response.readableLength) {
+ this._triggerRead = false;
+ }
+ let data;
+ while ((data = response.read()) !== null) {
+ this._downloadedSize += data.length; // eslint-disable-line @typescript-eslint/restrict-plus-operands
+ const progress = this.downloadProgress;
+ if (progress.percent < 1) {
+ this.emit('downloadProgress', progress);
+ }
+ this.push(data);
+ }
+ }
+ }
+ _write(chunk, encoding, callback) {
+ const write = () => {
+ this._writeRequest(chunk, encoding, callback);
+ };
+ if (this._requestInitialized) {
+ write();
+ }
+ else {
+ this._jobs.push(write);
+ }
+ }
+ _final(callback) {
+ const endRequest = () => {
+ // We need to check if `this._request` is present,
+ // because it isn't when we use cache.
+ if (!this._request || this._request.destroyed) {
+ callback();
+ return;
+ }
+ this._request.end((error) => {
+ // The request has been destroyed before `_final` finished.
+ // See https://github.com/nodejs/node/issues/39356
+ if (this._request._writableState?.errored) {
+ return;
+ }
+ if (!error) {
+ this._bodySize = this._uploadedSize;
+ this.emit('uploadProgress', this.uploadProgress);
+ this._request.emit('upload-complete');
+ }
+ callback(error);
+ });
+ };
+ if (this._requestInitialized) {
+ endRequest();
+ }
+ else {
+ this._jobs.push(endRequest);
+ }
+ }
+ _destroy(error, callback) {
+ this._stopReading = true;
+ this.flush = async () => { };
+ // Prevent further retries
+ this._stopRetry();
+ this._cancelTimeouts();
+ this._removeListeners();
+ if (this.options) {
+ const { body } = this.options;
+ if (dist.nodeStream(body)) {
+ body.destroy();
+ }
+ }
+ if (this._request) {
+ this._request.destroy();
+ }
+ if (error !== null && !dist.undefined(error) && !(error instanceof RequestError)) {
+ error = new RequestError(error.message, error, this);
+ }
+ callback(error);
+ }
+ pipe(destination, options) {
+ if (destination instanceof external_node_http_namespaceObject.ServerResponse) {
+ this._pipedServerResponses.add(destination);
+ }
+ return super.pipe(destination, options);
+ }
+ unpipe(destination) {
+ if (destination instanceof external_node_http_namespaceObject.ServerResponse) {
+ this._pipedServerResponses.delete(destination);
+ }
+ super.unpipe(destination);
+ return this;
+ }
+ async _finalizeBody() {
+ const { options } = this;
+ const { headers } = options;
+ const isForm = !dist.undefined(options.form);
+ // eslint-disable-next-line @typescript-eslint/naming-convention
+ const isJSON = !dist.undefined(options.json);
+ const isBody = !dist.undefined(options.body);
+ const cannotHaveBody = methodsWithoutBody.has(options.method) && !(options.method === 'GET' && options.allowGetBody);
+ this._cannotHaveBody = cannotHaveBody;
+ if (isForm || isJSON || isBody) {
+ if (cannotHaveBody) {
+ throw new TypeError(`The \`${options.method}\` method cannot be used with a body`);
+ }
+ // Serialize body
+ const noContentType = !dist.string(headers['content-type']);
+ if (isBody) {
+ // Body is spec-compliant FormData
+ if (isFormData(options.body)) {
+ const encoder = new FormDataEncoder(options.body);
+ if (noContentType) {
+ headers['content-type'] = encoder.headers['Content-Type'];
+ }
+ if ('Content-Length' in encoder.headers) {
+ headers['content-length'] = encoder.headers['Content-Length'];
+ }
+ options.body = encoder.encode();
+ }
+ // Special case for https://github.com/form-data/form-data
+ if (is_form_data_isFormData(options.body) && noContentType) {
+ headers['content-type'] = `multipart/form-data; boundary=${options.body.getBoundary()}`;
+ }
+ }
+ else if (isForm) {
+ if (noContentType) {
+ headers['content-type'] = 'application/x-www-form-urlencoded';
+ }
+ const { form } = options;
+ options.form = undefined;
+ options.body = (new external_node_url_namespaceObject.URLSearchParams(form)).toString();
+ }
+ else {
+ if (noContentType) {
+ headers['content-type'] = 'application/json';
+ }
+ const { json } = options;
+ options.json = undefined;
+ options.body = options.stringifyJson(json);
+ }
+ const uploadBodySize = await getBodySize(options.body, options.headers);
+ // See https://tools.ietf.org/html/rfc7230#section-3.3.2
+ // A user agent SHOULD send a Content-Length in a request message when
+ // no Transfer-Encoding is sent and the request method defines a meaning
+ // for an enclosed payload body. For example, a Content-Length header
+ // field is normally sent in a POST request even when the value is 0
+ // (indicating an empty payload body). A user agent SHOULD NOT send a
+ // Content-Length header field when the request message does not contain
+ // a payload body and the method semantics do not anticipate such a
+ // body.
+ if (dist.undefined(headers['content-length']) && dist.undefined(headers['transfer-encoding']) && !cannotHaveBody && !dist.undefined(uploadBodySize)) {
+ headers['content-length'] = String(uploadBodySize);
+ }
+ }
+ if (options.responseType === 'json' && !('accept' in options.headers)) {
+ options.headers.accept = 'application/json';
+ }
+ this._bodySize = Number(headers['content-length']) || undefined;
+ }
+ async _onResponseBase(response) {
+ // This will be called e.g. when using cache so we need to check if this request has been aborted.
+ if (this.isAborted) {
+ return;
+ }
+ const { options } = this;
+ const { url } = options;
+ this._nativeResponse = response;
+ if (options.decompress) {
+ response = decompress_response(response);
+ }
+ const statusCode = response.statusCode;
+ const typedResponse = response;
+ typedResponse.statusMessage = typedResponse.statusMessage ?? external_node_http_namespaceObject.STATUS_CODES[statusCode];
+ typedResponse.url = options.url.toString();
+ typedResponse.requestUrl = this.requestUrl;
+ typedResponse.redirectUrls = this.redirectUrls;
+ typedResponse.request = this;
+ typedResponse.isFromCache = this._nativeResponse.fromCache ?? false;
+ typedResponse.ip = this.ip;
+ typedResponse.retryCount = this.retryCount;
+ typedResponse.ok = isResponseOk(typedResponse);
+ this._isFromCache = typedResponse.isFromCache;
+ this._responseSize = Number(response.headers['content-length']) || undefined;
+ this.response = typedResponse;
+ response.once('end', () => {
+ this._responseSize = this._downloadedSize;
+ this.emit('downloadProgress', this.downloadProgress);
+ });
+ response.once('error', (error) => {
+ this._aborted = true;
+ // Force clean-up, because some packages don't do this.
+ // TODO: Fix decompress-response
+ response.destroy();
+ this._beforeError(new ReadError(error, this));
+ });
+ response.once('aborted', () => {
+ this._aborted = true;
+ this._beforeError(new ReadError({
+ name: 'Error',
+ message: 'The server aborted pending request',
+ code: 'ECONNRESET',
+ }, this));
+ });
+ this.emit('downloadProgress', this.downloadProgress);
+ const rawCookies = response.headers['set-cookie'];
+ if (dist.object(options.cookieJar) && rawCookies) {
+ let promises = rawCookies.map(async (rawCookie) => options.cookieJar.setCookie(rawCookie, url.toString()));
+ if (options.ignoreInvalidCookies) {
+ promises = promises.map(async (promise) => {
+ try {
+ await promise;
+ }
+ catch { }
+ });
+ }
+ try {
+ await Promise.all(promises);
+ }
+ catch (error) {
+ this._beforeError(error);
+ return;
+ }
+ }
+ // The above is running a promise, therefore we need to check if this request has been aborted yet again.
+ if (this.isAborted) {
+ return;
+ }
+ if (options.followRedirect && response.headers.location && redirectCodes.has(statusCode)) {
+ // We're being redirected, we don't care about the response.
+ // It'd be best to abort the request, but we can't because
+ // we would have to sacrifice the TCP connection. We don't want that.
+ response.resume();
+ this._cancelTimeouts();
+ this._unproxyEvents();
+ if (this.redirectUrls.length >= options.maxRedirects) {
+ this._beforeError(new MaxRedirectsError(this));
+ return;
+ }
+ this._request = undefined;
+ const updatedOptions = new Options(undefined, undefined, this.options);
+ const serverRequestedGet = statusCode === 303 && updatedOptions.method !== 'GET' && updatedOptions.method !== 'HEAD';
+ const canRewrite = statusCode !== 307 && statusCode !== 308;
+ const userRequestedGet = updatedOptions.methodRewriting && canRewrite;
+ if (serverRequestedGet || userRequestedGet) {
+ updatedOptions.method = 'GET';
+ updatedOptions.body = undefined;
+ updatedOptions.json = undefined;
+ updatedOptions.form = undefined;
+ delete updatedOptions.headers['content-length'];
+ }
+ try {
+ // We need this in order to support UTF-8
+ const redirectBuffer = external_node_buffer_namespaceObject.Buffer.from(response.headers.location, 'binary').toString();
+ const redirectUrl = new external_node_url_namespaceObject.URL(redirectBuffer, url);
+ if (!isUnixSocketURL(url) && isUnixSocketURL(redirectUrl)) {
+ this._beforeError(new RequestError('Cannot redirect to UNIX socket', {}, this));
+ return;
+ }
+ // Redirecting to a different site, clear sensitive data.
+ if (redirectUrl.hostname !== url.hostname || redirectUrl.port !== url.port) {
+ if ('host' in updatedOptions.headers) {
+ delete updatedOptions.headers.host;
+ }
+ if ('cookie' in updatedOptions.headers) {
+ delete updatedOptions.headers.cookie;
+ }
+ if ('authorization' in updatedOptions.headers) {
+ delete updatedOptions.headers.authorization;
+ }
+ if (updatedOptions.username || updatedOptions.password) {
+ updatedOptions.username = '';
+ updatedOptions.password = '';
+ }
+ }
+ else {
+ redirectUrl.username = updatedOptions.username;
+ redirectUrl.password = updatedOptions.password;
+ }
+ this.redirectUrls.push(redirectUrl);
+ updatedOptions.prefixUrl = '';
+ updatedOptions.url = redirectUrl;
+ for (const hook of updatedOptions.hooks.beforeRedirect) {
+ // eslint-disable-next-line no-await-in-loop
+ await hook(updatedOptions, typedResponse);
+ }
+ this.emit('redirect', updatedOptions, typedResponse);
+ this.options = updatedOptions;
+ await this._makeRequest();
+ }
+ catch (error) {
+ this._beforeError(error);
+ return;
+ }
+ return;
+ }
+ // `HTTPError`s always have `error.response.body` defined.
+ // Therefore we cannot retry if `options.throwHttpErrors` is false.
+ // On the last retry, if `options.throwHttpErrors` is false, we would need to return the body,
+ // but that wouldn't be possible since the body would be already read in `error.response.body`.
+ if (options.isStream && options.throwHttpErrors && !isResponseOk(typedResponse)) {
+ this._beforeError(new HTTPError(typedResponse));
+ return;
+ }
+ response.on('readable', () => {
+ if (this._triggerRead) {
+ this._read();
+ }
+ });
+ this.on('resume', () => {
+ response.resume();
+ });
+ this.on('pause', () => {
+ response.pause();
+ });
+ response.once('end', () => {
+ this.push(null);
+ });
+ if (this._noPipe) {
+ const success = await this._setRawBody();
+ if (success) {
+ this.emit('response', response);
+ }
+ return;
+ }
+ this.emit('response', response);
+ for (const destination of this._pipedServerResponses) {
+ if (destination.headersSent) {
+ continue;
+ }
+ // eslint-disable-next-line guard-for-in
+ for (const key in response.headers) {
+ const isAllowed = options.decompress ? key !== 'content-encoding' : true;
+ const value = response.headers[key];
+ if (isAllowed) {
+ destination.setHeader(key, value);
+ }
+ }
+ destination.statusCode = statusCode;
+ }
+ }
+ async _setRawBody(from = this) {
+ if (from.readableEnded) {
+ return false;
+ }
+ try {
+ // Errors are emitted via the `error` event
+ const rawBody = await getBuffer(from);
+ // On retry Request is destroyed with no error, therefore the above will successfully resolve.
+ // So in order to check if this was really successfull, we need to check if it has been properly ended.
+ if (!this.isAborted) {
+ this.response.rawBody = rawBody;
+ return true;
+ }
+ }
+ catch { }
+ return false;
+ }
+ async _onResponse(response) {
+ try {
+ await this._onResponseBase(response);
+ }
+ catch (error) {
+ /* istanbul ignore next: better safe than sorry */
+ this._beforeError(error);
+ }
+ }
+ _onRequest(request) {
+ const { options } = this;
+ const { timeout, url } = options;
+ dist_source(request);
+ if (this.options.http2) {
+ // Unset stream timeout, as the `timeout` option was used only for connection timeout.
+ request.setTimeout(0);
+ }
+ this._cancelTimeouts = timedOut(request, timeout, url);
+ const responseEventName = options.cache ? 'cacheableResponse' : 'response';
+ request.once(responseEventName, (response) => {
+ void this._onResponse(response);
+ });
+ request.once('error', (error) => {
+ this._aborted = true;
+ // Force clean-up, because some packages (e.g. nock) don't do this.
+ request.destroy();
+ error = error instanceof timed_out_TimeoutError ? new TimeoutError(error, this.timings, this) : new RequestError(error.message, error, this);
+ this._beforeError(error);
+ });
+ this._unproxyEvents = proxyEvents(request, this, proxiedRequestEvents);
+ this._request = request;
+ this.emit('uploadProgress', this.uploadProgress);
+ this._sendBody();
+ this.emit('request', request);
+ }
+ async _asyncWrite(chunk) {
+ return new Promise((resolve, reject) => {
+ super.write(chunk, error => {
+ if (error) {
+ reject(error);
+ return;
+ }
+ resolve();
+ });
+ });
+ }
+ _sendBody() {
+ // Send body
+ const { body } = this.options;
+ const currentRequest = this.redirectUrls.length === 0 ? this : this._request ?? this;
+ if (dist.nodeStream(body)) {
+ body.pipe(currentRequest);
+ }
+ else if (dist.generator(body) || dist.asyncGenerator(body)) {
+ (async () => {
+ try {
+ for await (const chunk of body) {
+ await this._asyncWrite(chunk);
+ }
+ super.end();
+ }
+ catch (error) {
+ this._beforeError(error);
+ }
+ })();
+ }
+ else if (!dist.undefined(body)) {
+ this._writeRequest(body, undefined, () => { });
+ currentRequest.end();
+ }
+ else if (this._cannotHaveBody || this._noPipe) {
+ currentRequest.end();
+ }
+ }
+ _prepareCache(cache) {
+ if (!cacheableStore.has(cache)) {
+ const cacheableRequest = new cacheable_request_dist(((requestOptions, handler) => {
+ const result = requestOptions._request(requestOptions, handler);
+ // TODO: remove this when `cacheable-request` supports async request functions.
+ if (dist.promise(result)) {
+ // We only need to implement the error handler in order to support HTTP2 caching.
+ // The result will be a promise anyway.
+ // @ts-expect-error ignore
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
+ result.once = (event, handler) => {
+ if (event === 'error') {
+ (async () => {
+ try {
+ await result;
+ }
+ catch (error) {
+ handler(error);
+ }
+ })();
+ }
+ else if (event === 'abort') {
+ // The empty catch is needed here in case when
+ // it rejects before it's `await`ed in `_makeRequest`.
+ (async () => {
+ try {
+ const request = (await result);
+ request.once('abort', handler);
+ }
+ catch { }
+ })();
+ }
+ else {
+ /* istanbul ignore next: safety check */
+ throw new Error(`Unknown HTTP2 promise event: ${event}`);
+ }
+ return result;
+ };
+ }
+ return result;
+ }), cache);
+ cacheableStore.set(cache, cacheableRequest.request());
+ }
+ }
+ async _createCacheableRequest(url, options) {
+ return new Promise((resolve, reject) => {
+ // TODO: Remove `utils/url-to-options.ts` when `cacheable-request` is fixed
+ Object.assign(options, urlToOptions(url));
+ let request;
+ // TODO: Fix `cacheable-response`. This is ugly.
+ const cacheRequest = cacheableStore.get(options.cache)(options, async (response) => {
+ response._readableState.autoDestroy = false;
+ if (request) {
+ const fix = () => {
+ if (response.req) {
+ response.complete = response.req.res.complete;
+ }
+ };
+ response.prependOnceListener('end', fix);
+ fix();
+ (await request).emit('cacheableResponse', response);
+ }
+ resolve(response);
+ });
+ cacheRequest.once('error', reject);
+ cacheRequest.once('request', async (requestOrPromise) => {
+ request = requestOrPromise;
+ resolve(request);
+ });
+ });
+ }
+ async _makeRequest() {
+ const { options } = this;
+ const { headers, username, password } = options;
+ const cookieJar = options.cookieJar;
+ for (const key in headers) {
+ if (dist.undefined(headers[key])) {
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
+ delete headers[key];
+ }
+ else if (dist.null_(headers[key])) {
+ throw new TypeError(`Use \`undefined\` instead of \`null\` to delete the \`${key}\` header`);
+ }
+ }
+ if (options.decompress && dist.undefined(headers['accept-encoding'])) {
+ headers['accept-encoding'] = supportsBrotli ? 'gzip, deflate, br' : 'gzip, deflate';
+ }
+ if (username || password) {
+ const credentials = external_node_buffer_namespaceObject.Buffer.from(`${username}:${password}`).toString('base64');
+ headers.authorization = `Basic ${credentials}`;
+ }
+ // Set cookies
+ if (cookieJar) {
+ const cookieString = await cookieJar.getCookieString(options.url.toString());
+ if (dist.nonEmptyString(cookieString)) {
+ headers.cookie = cookieString;
+ }
+ }
+ // Reset `prefixUrl`
+ options.prefixUrl = '';
+ let request;
+ for (const hook of options.hooks.beforeRequest) {
+ // eslint-disable-next-line no-await-in-loop
+ const result = await hook(options);
+ if (!dist.undefined(result)) {
+ // @ts-expect-error Skip the type mismatch to support abstract responses
+ request = () => result;
+ break;
+ }
+ }
+ if (!request) {
+ request = options.getRequestFunction();
+ }
+ const url = options.url;
+ this._requestOptions = options.createNativeRequestOptions();
+ if (options.cache) {
+ this._requestOptions._request = request;
+ this._requestOptions.cache = options.cache;
+ this._requestOptions.body = options.body;
+ this._prepareCache(options.cache);
+ }
+ // Cache support
+ const fn = options.cache ? this._createCacheableRequest : request;
+ try {
+ // We can't do `await fn(...)`,
+ // because stream `error` event can be emitted before `Promise.resolve()`.
+ let requestOrResponse = fn(url, this._requestOptions);
+ if (dist.promise(requestOrResponse)) {
+ requestOrResponse = await requestOrResponse;
+ }
+ // Fallback
+ if (dist.undefined(requestOrResponse)) {
+ requestOrResponse = options.getFallbackRequestFunction()(url, this._requestOptions);
+ if (dist.promise(requestOrResponse)) {
+ requestOrResponse = await requestOrResponse;
+ }
+ }
+ if (is_client_request(requestOrResponse)) {
+ this._onRequest(requestOrResponse);
+ }
+ else if (this.writable) {
+ this.once('finish', () => {
+ void this._onResponse(requestOrResponse);
+ });
+ this._sendBody();
+ }
+ else {
+ void this._onResponse(requestOrResponse);
+ }
+ }
+ catch (error) {
+ if (error instanceof types_CacheError) {
+ throw new CacheError(error, this);
+ }
+ throw error;
+ }
+ }
+ async _error(error) {
+ try {
+ if (error instanceof HTTPError && !this.options.throwHttpErrors) {
+ // This branch can be reached only when using the Promise API
+ // Skip calling the hooks on purpose.
+ // See https://github.com/sindresorhus/got/issues/2103
+ }
+ else {
+ for (const hook of this.options.hooks.beforeError) {
+ // eslint-disable-next-line no-await-in-loop
+ error = await hook(error);
+ }
+ }
+ }
+ catch (error_) {
+ error = new RequestError(error_.message, error_, this);
+ }
+ this.destroy(error);
+ }
+ _writeRequest(chunk, encoding, callback) {
+ if (!this._request || this._request.destroyed) {
+ // Probably the `ClientRequest` instance will throw
+ return;
+ }
+ this._request.write(chunk, encoding, (error) => {
+ // The `!destroyed` check is required to prevent `uploadProgress` being emitted after the stream was destroyed
+ if (!error && !this._request.destroyed) {
+ this._uploadedSize += external_node_buffer_namespaceObject.Buffer.byteLength(chunk, encoding);
+ const progress = this.uploadProgress;
+ if (progress.percent < 1) {
+ this.emit('uploadProgress', progress);
+ }
+ }
+ callback(error);
+ });
+ }
+ /**
+ The remote IP address.
+ */
+ get ip() {
+ return this.socket?.remoteAddress;
+ }
+ /**
+ Indicates whether the request has been aborted or not.
+ */
+ get isAborted() {
+ return this._aborted;
+ }
+ get socket() {
+ return this._request?.socket ?? undefined;
+ }
+ /**
+ Progress event for downloading (receiving a response).
+ */
+ get downloadProgress() {
+ let percent;
+ if (this._responseSize) {
+ percent = this._downloadedSize / this._responseSize;
+ }
+ else if (this._responseSize === this._downloadedSize) {
+ percent = 1;
+ }
+ else {
+ percent = 0;
+ }
+ return {
+ percent,
+ transferred: this._downloadedSize,
+ total: this._responseSize,
+ };
+ }
+ /**
+ Progress event for uploading (sending a request).
+ */
+ get uploadProgress() {
+ let percent;
+ if (this._bodySize) {
+ percent = this._uploadedSize / this._bodySize;
+ }
+ else if (this._bodySize === this._uploadedSize) {
+ percent = 1;
+ }
+ else {
+ percent = 0;
+ }
+ return {
+ percent,
+ transferred: this._uploadedSize,
+ total: this._bodySize,
+ };
+ }
+ /**
+ The object contains the following properties:
+
+ - `start` - Time when the request started.
+ - `socket` - Time when a socket was assigned to the request.
+ - `lookup` - Time when the DNS lookup finished.
+ - `connect` - Time when the socket successfully connected.
+ - `secureConnect` - Time when the socket securely connected.
+ - `upload` - Time when the request finished uploading.
+ - `response` - Time when the request fired `response` event.
+ - `end` - Time when the response fired `end` event.
+ - `error` - Time when the request fired `error` event.
+ - `abort` - Time when the request fired `abort` event.
+ - `phases`
+ - `wait` - `timings.socket - timings.start`
+ - `dns` - `timings.lookup - timings.socket`
+ - `tcp` - `timings.connect - timings.lookup`
+ - `tls` - `timings.secureConnect - timings.connect`
+ - `request` - `timings.upload - (timings.secureConnect || timings.connect)`
+ - `firstByte` - `timings.response - timings.upload`
+ - `download` - `timings.end - timings.response`
+ - `total` - `(timings.end || timings.error || timings.abort) - timings.start`
+
+ If something has not been measured yet, it will be `undefined`.
+
+ __Note__: The time is a `number` representing the milliseconds elapsed since the UNIX epoch.
+ */
+ get timings() {
+ return this._request?.timings;
+ }
+ /**
+ Whether the response was retrieved from the cache.
+ */
+ get isFromCache() {
+ return this._isFromCache;
+ }
+ get reusedSocket() {
+ return this._request?.reusedSocket;
+ }
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/as-promise/types.js
+
+/**
+An error to be thrown when the request is aborted with `.cancel()`.
+*/
+class types_CancelError extends RequestError {
+ constructor(request) {
+ super('Promise was canceled', {}, request);
+ this.name = 'CancelError';
+ this.code = 'ERR_CANCELED';
+ }
+ /**
+ Whether the promise is canceled.
+ */
+ get isCanceled() {
+ return true;
+ }
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/as-promise/index.js
+
+
+
+
+
+
+
+
+const as_promise_proxiedRequestEvents = [
+ 'request',
+ 'response',
+ 'redirect',
+ 'uploadProgress',
+ 'downloadProgress',
+];
+function asPromise(firstRequest) {
+ let globalRequest;
+ let globalResponse;
+ let normalizedOptions;
+ const emitter = new external_node_events_namespaceObject.EventEmitter();
+ const promise = new PCancelable((resolve, reject, onCancel) => {
+ onCancel(() => {
+ globalRequest.destroy();
+ });
+ onCancel.shouldReject = false;
+ onCancel(() => {
+ reject(new types_CancelError(globalRequest));
+ });
+ const makeRequest = (retryCount) => {
+ // Errors when a new request is made after the promise settles.
+ // Used to detect a race condition.
+ // See https://github.com/sindresorhus/got/issues/1489
+ onCancel(() => { });
+ const request = firstRequest ?? new Request(undefined, undefined, normalizedOptions);
+ request.retryCount = retryCount;
+ request._noPipe = true;
+ globalRequest = request;
+ request.once('response', async (response) => {
+ // Parse body
+ const contentEncoding = (response.headers['content-encoding'] ?? '').toLowerCase();
+ const isCompressed = contentEncoding === 'gzip' || contentEncoding === 'deflate' || contentEncoding === 'br';
+ const { options } = request;
+ if (isCompressed && !options.decompress) {
+ response.body = response.rawBody;
+ }
+ else {
+ try {
+ response.body = parseBody(response, options.responseType, options.parseJson, options.encoding);
+ }
+ catch (error) {
+ // Fall back to `utf8`
+ response.body = response.rawBody.toString();
+ if (isResponseOk(response)) {
+ request._beforeError(error);
+ return;
+ }
+ }
+ }
+ try {
+ const hooks = options.hooks.afterResponse;
+ for (const [index, hook] of hooks.entries()) {
+ // @ts-expect-error TS doesn't notice that CancelableRequest is a Promise
+ // eslint-disable-next-line no-await-in-loop
+ response = await hook(response, async (updatedOptions) => {
+ options.merge(updatedOptions);
+ options.prefixUrl = '';
+ if (updatedOptions.url) {
+ options.url = updatedOptions.url;
+ }
+ // Remove any further hooks for that request, because we'll call them anyway.
+ // The loop continues. We don't want duplicates (asPromise recursion).
+ options.hooks.afterResponse = options.hooks.afterResponse.slice(0, index);
+ throw new RetryError(request);
+ });
+ if (!(dist.object(response) && dist.number(response.statusCode) && !dist.nullOrUndefined(response.body))) {
+ throw new TypeError('The `afterResponse` hook returned an invalid value');
+ }
+ }
+ }
+ catch (error) {
+ request._beforeError(error);
+ return;
+ }
+ globalResponse = response;
+ if (!isResponseOk(response)) {
+ request._beforeError(new HTTPError(response));
+ return;
+ }
+ request.destroy();
+ resolve(request.options.resolveBodyOnly ? response.body : response);
+ });
+ const onError = (error) => {
+ if (promise.isCanceled) {
+ return;
+ }
+ const { options } = request;
+ if (error instanceof HTTPError && !options.throwHttpErrors) {
+ const { response } = error;
+ request.destroy();
+ resolve(request.options.resolveBodyOnly ? response.body : response);
+ return;
+ }
+ reject(error);
+ };
+ request.once('error', onError);
+ const previousBody = request.options?.body;
+ request.once('retry', (newRetryCount, error) => {
+ firstRequest = undefined;
+ const newBody = request.options.body;
+ if (previousBody === newBody && dist.nodeStream(newBody)) {
+ error.message = 'Cannot retry with consumed body stream';
+ onError(error);
+ return;
+ }
+ // This is needed! We need to reuse `request.options` because they can get modified!
+ // For example, by calling `promise.json()`.
+ normalizedOptions = request.options;
+ makeRequest(newRetryCount);
+ });
+ proxyEvents(request, emitter, as_promise_proxiedRequestEvents);
+ if (dist.undefined(firstRequest)) {
+ void request.flush();
+ }
+ };
+ makeRequest(0);
+ });
+ promise.on = (event, fn) => {
+ emitter.on(event, fn);
+ return promise;
+ };
+ promise.off = (event, fn) => {
+ emitter.off(event, fn);
+ return promise;
+ };
+ const shortcut = (responseType) => {
+ const newPromise = (async () => {
+ // Wait until downloading has ended
+ await promise;
+ const { options } = globalResponse.request;
+ return parseBody(globalResponse, responseType, options.parseJson, options.encoding);
+ })();
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
+ Object.defineProperties(newPromise, Object.getOwnPropertyDescriptors(promise));
+ return newPromise;
+ };
+ promise.json = () => {
+ if (globalRequest.options) {
+ const { headers } = globalRequest.options;
+ if (!globalRequest.writableFinished && !('accept' in headers)) {
+ headers.accept = 'application/json';
+ }
+ }
+ return shortcut('json');
+ };
+ promise.buffer = () => shortcut('buffer');
+ promise.text = () => shortcut('text');
+ return promise;
+}
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/create.js
+
+
+
+
+// The `delay` package weighs 10KB (!)
+const delay = async (ms) => new Promise(resolve => {
+ setTimeout(resolve, ms);
+});
+const isGotInstance = (value) => dist.function_(value);
+const aliases = [
+ 'get',
+ 'post',
+ 'put',
+ 'patch',
+ 'head',
+ 'delete',
+];
+const create = (defaults) => {
+ defaults = {
+ options: new Options(undefined, undefined, defaults.options),
+ handlers: [...defaults.handlers],
+ mutableDefaults: defaults.mutableDefaults,
+ };
+ Object.defineProperty(defaults, 'mutableDefaults', {
+ enumerable: true,
+ configurable: false,
+ writable: false,
+ });
+ // Got interface
+ const got = ((url, options, defaultOptions = defaults.options) => {
+ const request = new Request(url, options, defaultOptions);
+ let promise;
+ const lastHandler = (normalized) => {
+ // Note: `options` is `undefined` when `new Options(...)` fails
+ request.options = normalized;
+ request._noPipe = !normalized.isStream;
+ void request.flush();
+ if (normalized.isStream) {
+ return request;
+ }
+ if (!promise) {
+ promise = asPromise(request);
+ }
+ return promise;
+ };
+ let iteration = 0;
+ const iterateHandlers = (newOptions) => {
+ const handler = defaults.handlers[iteration++] ?? lastHandler;
+ const result = handler(newOptions, iterateHandlers);
+ if (dist.promise(result) && !request.options.isStream) {
+ if (!promise) {
+ promise = asPromise(request);
+ }
+ if (result !== promise) {
+ const descriptors = Object.getOwnPropertyDescriptors(promise);
+ for (const key in descriptors) {
+ if (key in result) {
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
+ delete descriptors[key];
+ }
+ }
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
+ Object.defineProperties(result, descriptors);
+ result.cancel = promise.cancel;
+ }
+ }
+ return result;
+ };
+ return iterateHandlers(request.options);
+ });
+ got.extend = (...instancesOrOptions) => {
+ const options = new Options(undefined, undefined, defaults.options);
+ const handlers = [...defaults.handlers];
+ let mutableDefaults;
+ for (const value of instancesOrOptions) {
+ if (isGotInstance(value)) {
+ options.merge(value.defaults.options);
+ handlers.push(...value.defaults.handlers);
+ mutableDefaults = value.defaults.mutableDefaults;
+ }
+ else {
+ options.merge(value);
+ if (value.handlers) {
+ handlers.push(...value.handlers);
+ }
+ mutableDefaults = value.mutableDefaults;
+ }
+ }
+ return create({
+ options,
+ handlers,
+ mutableDefaults: Boolean(mutableDefaults),
+ });
+ };
+ // Pagination
+ const paginateEach = (async function* (url, options) {
+ let normalizedOptions = new Options(url, options, defaults.options);
+ normalizedOptions.resolveBodyOnly = false;
+ const { pagination } = normalizedOptions;
+ assert.function_(pagination.transform);
+ assert.function_(pagination.shouldContinue);
+ assert.function_(pagination.filter);
+ assert.function_(pagination.paginate);
+ assert.number(pagination.countLimit);
+ assert.number(pagination.requestLimit);
+ assert.number(pagination.backoff);
+ const allItems = [];
+ let { countLimit } = pagination;
+ let numberOfRequests = 0;
+ while (numberOfRequests < pagination.requestLimit) {
+ if (numberOfRequests !== 0) {
+ // eslint-disable-next-line no-await-in-loop
+ await delay(pagination.backoff);
+ }
+ // eslint-disable-next-line no-await-in-loop
+ const response = (await got(undefined, undefined, normalizedOptions));
+ // eslint-disable-next-line no-await-in-loop
+ const parsed = await pagination.transform(response);
+ const currentItems = [];
+ assert.array(parsed);
+ for (const item of parsed) {
+ if (pagination.filter({ item, currentItems, allItems })) {
+ if (!pagination.shouldContinue({ item, currentItems, allItems })) {
+ return;
+ }
+ yield item;
+ if (pagination.stackAllItems) {
+ allItems.push(item);
+ }
+ currentItems.push(item);
+ if (--countLimit <= 0) {
+ return;
+ }
+ }
+ }
+ const optionsToMerge = pagination.paginate({
+ response,
+ currentItems,
+ allItems,
+ });
+ if (optionsToMerge === false) {
+ return;
+ }
+ if (optionsToMerge === response.request.options) {
+ normalizedOptions = response.request.options;
+ }
+ else {
+ normalizedOptions.merge(optionsToMerge);
+ assert.any([dist.urlInstance, dist.undefined], optionsToMerge.url);
+ if (optionsToMerge.url !== undefined) {
+ normalizedOptions.prefixUrl = '';
+ normalizedOptions.url = optionsToMerge.url;
+ }
+ }
+ numberOfRequests++;
+ }
+ });
+ got.paginate = paginateEach;
+ got.paginate.all = (async (url, options) => {
+ const results = [];
+ for await (const item of paginateEach(url, options)) {
+ results.push(item);
+ }
+ return results;
+ });
+ // For those who like very descriptive names
+ got.paginate.each = paginateEach;
+ // Stream API
+ got.stream = ((url, options) => got(url, { ...options, isStream: true }));
+ // Shortcuts
+ for (const method of aliases) {
+ got[method] = ((url, options) => got(url, { ...options, method }));
+ got.stream[method] = ((url, options) => got(url, { ...options, method, isStream: true }));
+ }
+ if (!defaults.mutableDefaults) {
+ Object.freeze(defaults.handlers);
+ defaults.options.freeze();
+ }
+ Object.defineProperty(got, 'defaults', {
+ value: defaults,
+ writable: false,
+ configurable: false,
+ enumerable: true,
+ });
+ return got;
+};
+/* harmony default export */ const source_create = (create);
+
+;// CONCATENATED MODULE: ./node_modules/got/dist/source/index.js
+
+
+const defaults = {
+ options: new Options(),
+ handlers: [],
+ mutableDefaults: false,
+};
+const got = source_create(defaults);
+/* harmony default export */ const got_dist_source = (got);
+
+
+
+
+
+
+
+
+
+
+
+
+
/***/ }),
/***/ 2020:
@@ -37652,6 +39569,34 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ }
/******/
/************************************************************************/
+/******/ /* webpack/runtime/define property getters */
+/******/ (() => {
+/******/ // define getter functions for harmony exports
+/******/ __nccwpck_require__.d = (exports, definition) => {
+/******/ for(var key in definition) {
+/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
+/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
+/******/ }
+/******/ }
+/******/ };
+/******/ })();
+/******/
+/******/ /* webpack/runtime/hasOwnProperty shorthand */
+/******/ (() => {
+/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
+/******/ })();
+/******/
+/******/ /* webpack/runtime/make namespace object */
+/******/ (() => {
+/******/ // define __esModule on exports
+/******/ __nccwpck_require__.r = (exports) => {
+/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
+/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
+/******/ }
+/******/ Object.defineProperty(exports, '__esModule', { value: true });
+/******/ };
+/******/ })();
+/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
diff --git a/dist/licenses.txt b/dist/licenses.txt
index 02c6588..1ed94e6 100644
--- a/dist/licenses.txt
+++ b/dist/licenses.txt
@@ -648,78 +648,6 @@ SOFTWARE.
cacheable-request
MIT
-MIT License
-
-Copyright (c) 2017 Luke Childs
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-
-clone-response
-MIT
-MIT License
-
-Copyright (c) 2017 Luke Childs
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-
-
-compress-brotli
-MIT
-The MIT License (MIT)
-
-Copyright © 2019 Kiko Beats (kikobeats.com)
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
decompress-response
MIT
@@ -778,30 +706,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-end-of-stream
-MIT
-The MIT License (MIT)
-
-Copyright (c) 2014 Mathias Buus
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
fast-glob
MIT
The MIT License (MIT)
@@ -869,6 +773,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+form-data-encoder
+MIT
+The MIT License (MIT)
+
+Copyright (c) 2021-present Nick K.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+
get-stream
MIT
MIT License
@@ -1085,7 +1014,7 @@ lowercase-keys
MIT
MIT License
-Copyright (c) Sindre Sorhus (sindresorhus.com)
+Copyright (c) Sindre Sorhus (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@@ -1148,7 +1077,7 @@ mimic-response
MIT
MIT License
-Copyright (c) Sindre Sorhus (sindresorhus.com)
+Copyright (c) Sindre Sorhus (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@@ -1187,7 +1116,7 @@ normalize-url
MIT
MIT License
-Copyright (c) Sindre Sorhus (sindresorhus.com)
+Copyright (c) Sindre Sorhus (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@@ -1219,7 +1148,7 @@ p-cancelable
MIT
MIT License
-Copyright (c) Sindre Sorhus (sindresorhus.com)
+Copyright (c) Sindre Sorhus (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@@ -1253,30 +1182,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-pump
-MIT
-The MIT License (MIT)
-
-Copyright (c) 2014 Mathias Buus
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
queue-microtask
MIT
The MIT License (MIT)
@@ -1342,25 +1247,16 @@ SOFTWARE.
responselike
MIT
-Copyright (c) 2017 Luke Childs
+MIT License
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Copyright (c) Sindre Sorhus (https://sindresorhus.com)
+Copyright (c) Luke Childs (https://lukechilds.co.uk)
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
reusify
diff --git a/package.json b/package.json
index 9d4af54..028d91d 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,7 @@
"@actions/github": "^5.0.3",
"adm-zip": "^0.5.3",
"fast-glob": "^3.2.5",
- "got": "^12.0.0",
+ "got": "^12.5.1",
"picomatch": "^2.2.2",
"xml2js": "^0.5.0"
},
diff --git a/tsconfig.json b/tsconfig.json
index f6e7cb5..9c4f794 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -6,7 +6,8 @@
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
- "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
+ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
+ "skipLibCheck": true /* Setting to true based on stackoverflow here; https://github.com/sindresorhus/got/issues/2051#issuecomment-1259401339 */
},
"exclude": ["node_modules", "**/*.test.ts"]
}