Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

get-it

Package Overview
Dependencies
Maintainers
45
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-it - npm Package Compare versions

Comparing version 8.4.5 to 8.4.6

dist/_chunks/createRequester-46TmGIk5.js

134

dist/index.browser.js

@@ -1,9 +0,7 @@

import { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-dittwL7d.js';
import { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-N21NGwyb.js';
import parseHeaders from 'parse-headers';
const middlewareReducer = middleware => function applyMiddleware(hook, defaultValue) {
const middlewareReducer = (middleware) => function applyMiddleware(hook, defaultValue, ...args) {
const bailEarly = hook === "onError";
let value = defaultValue;
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
for (let i = 0; i < middleware[hook].length; i++) {

@@ -18,4 +16,5 @@ const handler = middleware[hook][i];

};
function createPubSub() {
const subscribers = /* @__PURE__ */Object.create(null);
const subscribers = /* @__PURE__ */ Object.create(null);
let nextId = 0;

@@ -39,13 +38,33 @@ function subscribe(subscriber) {

}
const channelNames = ["request", "response", "progress", "error", "abort"];
const middlehooks = ["processOptions", "validateOptions", "interceptRequest", "finalizeOptions", "onRequest", "onResponse", "onError", "onReturn", "onHeaders"];
const channelNames = [
"request",
"response",
"progress",
"error",
"abort"
];
const middlehooks = [
"processOptions",
"validateOptions",
"interceptRequest",
"finalizeOptions",
"onRequest",
"onResponse",
"onError",
"onReturn",
"onHeaders"
];
function createRequester(initMiddleware, httpRequest) {
const loadedMiddleware = [];
const middleware = middlehooks.reduce((ware, name) => {
ware[name] = ware[name] || [];
return ware;
}, {
processOptions: [processOptions],
validateOptions: [validateOptions]
});
const middleware = middlehooks.reduce(
(ware, name) => {
ware[name] = ware[name] || [];
return ware;
},
{
processOptions: [processOptions],
validateOptions: [validateOptions]
}
);
function request(opts) {

@@ -77,9 +96,5 @@ const onResponse = (reqErr, res, ctx) => {

applyMiddleware("validateOptions", options);
const context = {
options,
channels,
applyMiddleware
};
const context = { options, channels, applyMiddleware };
let ongoingRequest;
const unsubscribe = channels.request.subscribe(ctx => {
const unsubscribe = channels.request.subscribe((ctx) => {
ongoingRequest = httpRequest(ctx, (err, res) => onResponse(err, res, ctx));

@@ -104,8 +119,12 @@ });

if (typeof newMiddleware === "function") {
throw new Error("Tried to add middleware that was a function. It probably expects you to pass options to it.");
throw new Error(
"Tried to add middleware that was a function. It probably expects you to pass options to it."
);
}
if (newMiddleware.onReturn && middleware.onReturn.length > 0) {
throw new Error("Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event");
throw new Error(
"Tried to add new middleware with `onReturn` handler, but another handler has already been registered for this event"
);
}
middlehooks.forEach(key => {
middlehooks.forEach((key) => {
if (newMiddleware[key]) {

@@ -122,4 +141,6 @@ middleware[key].push(newMiddleware[key]);

}
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj)) throw TypeError("Cannot " + msg);
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};

@@ -131,3 +152,4 @@ var __privateGet = (obj, member, getter) => {

var __privateAdd = (obj, member, value) => {
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);

@@ -180,4 +202,3 @@ };

// Allow setting extra fetch init options, needed for runtimes such as Vercel Edge to set `cache` and other options in React Server Components
setInit(init) {
let useAbortSignal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
setInit(init, useAbortSignal = true) {
__privateSet(this, _init, init);

@@ -203,3 +224,3 @@ __privateSet(this, _useAbortSignal, useAbortSignal);

}
fetch(__privateGet(this, _url), options).then(res => {
fetch(__privateGet(this, _url), options).then((res) => {
res.headers.forEach((value, key) => {

@@ -212,3 +233,3 @@ __privateSet(this, _resHeaders, __privateGet(this, _resHeaders) + "".concat(key, ": ").concat(value, "\r\n"));

return textBody ? res.text() : res.arrayBuffer();
}).then(resBody => {
}).then((resBody) => {
if (typeof resBody === "string") {

@@ -221,3 +242,3 @@ this.responseText = resBody;

this.onreadystatechange();
}).catch(err => {
}).catch((err) => {
var _a;

@@ -239,2 +260,3 @@ if (err.name === "AbortError") {

_useAbortSignal = new WeakMap();
const adapter = typeof XMLHttpRequest === "function" ? "xhr" : "fetch";

@@ -254,5 +276,3 @@ const XmlHttpRequest = adapter === "xhr" ? XMLHttpRequest : FetchXhr;

const cancel = () => clearTimeout(cbTimer);
return {
abort: cancel
};
return { abort: cancel };
}

@@ -268,7 +288,15 @@ let xhr = new XmlHttpRequest();

let timedOut = false;
xhr.onerror = event => {
onError(new Error("Request error while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")));
xhr.onerror = (event) => {
onError(
new Error(
"Request error while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")
)
);
};
xhr.ontimeout = event => {
onError(new Error("Request timeout while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")));
xhr.ontimeout = (event) => {
onError(
new Error(
"Request timeout while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")
)
);
};

@@ -289,4 +317,7 @@ xhr.onabort = () => {

};
xhr.open(options.method, options.url, true
// Always async
xhr.open(
options.method,
options.url,
true
// Always async
);

@@ -304,8 +335,3 @@ xhr.withCredentials = !!options.withCredentials;

}
context.applyMiddleware("onRequest", {
options,
adapter,
request: xhr,
context
});
context.applyMiddleware("onRequest", { options, adapter, request: xhr, context });
xhr.send(options.body || null);

@@ -315,5 +341,3 @@ if (delays) {

}
return {
abort
};
return { abort };
function abort() {

@@ -328,3 +352,5 @@ aborted = true;

xhr.abort();
const error = new Error(code === "ESOCKETTIMEDOUT" ? "Socket timed out on request to ".concat(options.url) : "Connection timed out on request to ".concat(options.url));
const error = new Error(
code === "ESOCKETTIMEDOUT" ? "Socket timed out on request to ".concat(options.url) : "Connection timed out on request to ".concat(options.url)
);
error.code = code;

@@ -383,9 +409,7 @@ context.channels.error.publish(error);

};
const getIt = function () {
let initMiddleware = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
let httpRequest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : httpRequester;
return createRequester(initMiddleware, httpRequest);
};
const getIt = (initMiddleware = [], httpRequest = httpRequester) => createRequester(initMiddleware, httpRequest);
const environment = "browser";
export { adapter, environment, getIt };
//# sourceMappingURL=index.browser.js.map

@@ -1,2 +0,2 @@

import { createRequester } from './_chunks/createRequester-ryeXkh0z.js';
import { createRequester } from './_chunks/createRequester-46TmGIk5.js';
import decompressResponse from 'decompress-response';

@@ -12,2 +12,3 @@ import follow from 'follow-redirects';

import * as tunnel from 'tunnel-agent';
function lowerCaseHeaders(headers) {

@@ -19,2 +20,3 @@ return Object.keys(headers || {}).reduce((acc, header) => {

}
function formatHostname(hostname) {

@@ -29,7 +31,3 @@ return hostname.replace(/^\.*/, ".").toLowerCase();

const hasPort = zone.indexOf(":") > -1;
return {
hostname: zoneHost,
port: zonePort,
hasPort
};
return { hostname: zoneHost, port: zonePort, hasPort };
}

@@ -40,3 +38,3 @@ function uriInNoProxy(uri, noProxy) {

const noProxyList = noProxy.split(",");
return noProxyList.map(parseNoProxyZone).some(noProxyZone => {
return noProxyList.map(parseNoProxyZone).some((noProxyZone) => {
const isMatchedAt = hostname.indexOf(noProxyZone.hostname);

@@ -81,5 +79,3 @@ const hostnameMatched = isMatchedAt > -1 && isMatchedAt === hostname.length - noProxyZone.hostname.length;

const headers = reqOpts.headers || {};
const options = Object.assign({}, reqOpts, {
headers
});
const options = Object.assign({}, reqOpts, { headers });
headers.host = headers.host || getHostHeaderWithPort(uri);

@@ -108,14 +104,17 @@ options.protocol = proxy.protocol || options.protocol;

const chunks = [];
stream.on("data", function (chunk) {
stream.on("data", function(chunk) {
chunks.push(chunk);
});
stream.once("end", function () {
if (cb) cb(null, Buffer.concat(chunks));
stream.once("end", function() {
if (cb)
cb(null, Buffer.concat(chunks));
cb = null;
});
stream.once("error", function (err) {
if (cb) cb(err);
stream.once("error", function(err) {
if (cb)
cb(err);
cb = null;
});
}
function timedOut(req, time) {

@@ -125,6 +124,3 @@ if (req.timeoutTimer) {

}
const delays = isNaN(time) ? time : {
socket: time,
connect: time
};
const delays = isNaN(time) ? time : { socket: time, connect: time };
const hostHeader = req.getHeader("host");

@@ -166,4 +162,40 @@ const host = hostHeader ? " to " + hostHeader : "";

}
const uriParts = ["protocol", "slashes", "auth", "host", "port", "hostname", "hash", "search", "query", "pathname", "path", "href"];
const defaultProxyHeaderWhiteList = ["accept", "accept-charset", "accept-encoding", "accept-language", "accept-ranges", "cache-control", "content-encoding", "content-language", "content-location", "content-md5", "content-range", "content-type", "connection", "date", "expect", "max-forwards", "pragma", "referer", "te", "user-agent", "via"];
const uriParts = [
"protocol",
"slashes",
"auth",
"host",
"port",
"hostname",
"hash",
"search",
"query",
"pathname",
"path",
"href"
];
const defaultProxyHeaderWhiteList = [
"accept",
"accept-charset",
"accept-encoding",
"accept-language",
"accept-ranges",
"cache-control",
"content-encoding",
"content-language",
"content-location",
"content-md5",
"content-range",
"content-type",
"connection",
"date",
"expect",
"max-forwards",
"pragma",
"referer",
"te",
"user-agent",
"via"
];
const defaultProxyHeaderExclusiveList = ["proxy-authorization"];

@@ -180,8 +212,6 @@ function shouldEnable(options) {

}
function applyAgent() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
let proxy = arguments.length > 1 ? arguments[1] : undefined;
function applyAgent(opts = {}, proxy) {
const options = Object.assign({}, opts);
const proxyHeaderWhiteList = defaultProxyHeaderWhiteList.concat(options.proxyHeaderWhiteList || []).map(header => header.toLowerCase());
const proxyHeaderExclusiveList = defaultProxyHeaderExclusiveList.concat(options.proxyHeaderExclusiveList || []).map(header => header.toLowerCase());
const proxyHeaderWhiteList = defaultProxyHeaderWhiteList.concat(options.proxyHeaderWhiteList || []).map((header) => header.toLowerCase());
const proxyHeaderExclusiveList = defaultProxyHeaderExclusiveList.concat(options.proxyHeaderExclusiveList || []).map((header) => header.toLowerCase());
const proxyHeaders = getAllowedProxyHeaders(options.headers, proxyHeaderWhiteList);

@@ -231,3 +261,3 @@ proxyHeaders.host = constructProxyHost(options);

function getAllowedProxyHeaders(headers, whiteList) {
return Object.keys(headers).filter(header => whiteList.indexOf(header.toLowerCase()) !== -1).reduce((set, header) => {
return Object.keys(headers).filter((header) => whiteList.indexOf(header.toLowerCase()) !== -1).reduce((set, header) => {
set[header] = headers[header];

@@ -257,2 +287,3 @@ return set;

}
const adapter = "node";

@@ -268,5 +299,3 @@ const reduceResponse = (res, reqUrl, method, body) => ({

const httpRequester = (context, cb) => {
const {
options
} = context;
const { options } = context;
const uri = Object.assign({}, url.parse(options.url));

@@ -279,3 +308,3 @@ if (typeof fetch === "function" && options.fetch) {

headers: {
...(typeof options.fetch === "object" && options.fetch.headers ? lowerCaseHeaders(options.fetch.headers) : {}),
...typeof options.fetch === "object" && options.fetch.headers ? lowerCaseHeaders(options.fetch.headers) : {},
...lowerCaseHeaders(options.headers)

@@ -287,3 +316,3 @@ },

credentials: options.withCredentials ? "include" : "omit",
...(typeof options.fetch === "object" ? options.fetch : {}),
...typeof options.fetch === "object" ? options.fetch : {},
method: reqOpts2.method,

@@ -301,14 +330,7 @@ headers: reqOpts2.headers,

const cancel = () => clearTimeout(cbTimer);
return {
abort: cancel
};
return { abort: cancel };
}
const request2 = fetch(options.url, fetchOpts);
context.applyMiddleware("onRequest", {
options,
adapter,
request: request2,
context
});
request2.then(async res => {
context.applyMiddleware("onRequest", { options, adapter, request: request2, context });
request2.then(async (res) => {
const body = options.rawBody ? res.body : await res.text();

@@ -327,9 +349,8 @@ const headers = {};

});
}).catch(err => {
if (err.name == "AbortError") return;
}).catch((err) => {
if (err.name == "AbortError")
return;
cb(err);
});
return {
abort: () => controller.abort()
};
return { abort: () => controller.abort() };
}

@@ -365,5 +386,3 @@ const bodyType = isStream(options.body) ? "stream" : typeof options.body;

const abort = () => clearImmediate(cbTimer);
return {
abort
};
return { abort };
}

@@ -379,3 +398,3 @@ if (options.maxRedirects !== 0) {

if (!tunnel && proxy && proxy.auth && !reqOpts.headers["proxy-authorization"]) {
const [username, password] = proxy.auth.username ? [proxy.auth.username, proxy.auth.password] : proxy.auth.split(":").map(item => qs.unescape(item));
const [username, password] = proxy.auth.username ? [proxy.auth.username, proxy.auth.password] : proxy.auth.split(":").map((item) => qs.unescape(item));
const auth = Buffer.from("".concat(username, ":").concat(password), "utf8");

@@ -387,3 +406,6 @@ const authBase64 = auth.toString("base64");

if (typeof options.debug === "function" && proxy) {
options.debug("Proxying using %s", reqOpts.agent ? "tunnel agent" : "".concat(reqOpts.host, ":").concat(reqOpts.port));
options.debug(
"Proxying using %s",
reqOpts.agent ? "tunnel agent" : "".concat(reqOpts.host, ":").concat(reqOpts.port)
);
}

@@ -394,4 +416,7 @@ const tryCompressed = reqOpts.method !== "HEAD";

}
const finalOptions = context.applyMiddleware("finalizeOptions", reqOpts);
const request = transport.request(finalOptions, response => {
const finalOptions = context.applyMiddleware(
"finalizeOptions",
reqOpts
);
const request = transport.request(finalOptions, (response) => {
const res = tryCompressed ? decompressResponse(response) : response;

@@ -421,13 +446,4 @@ const resStream = context.applyMiddleware("onHeaders", res, {

request.once("error", callback);
const {
bodyStream,
progress
} = getProgressStream(options);
context.applyMiddleware("onRequest", {
options,
adapter,
request,
context,
progress
});
const { bodyStream, progress } = getProgressStream(options);
context.applyMiddleware("onRequest", { options, adapter, request, context, progress });
if (bodyStream) {

@@ -438,5 +454,3 @@ bodyStream.pipe(request);

}
return {
abort: () => request.abort()
};
return { abort: () => request.abort() };
};

@@ -450,25 +464,11 @@ function getProgressStream(options) {

if (!length) {
return bodyIsStream ? {
bodyStream: options.body
} : {};
return bodyIsStream ? { bodyStream: options.body } : {};
}
const progress = progressStream({
time: 16,
length
});
const progress = progressStream({ time: 16, length });
const bodyStream = bodyIsStream ? options.body : toStream(options.body);
return {
bodyStream: bodyStream.pipe(progress),
progress
};
return { bodyStream: bodyStream.pipe(progress), progress };
}
function getRequestTransport(reqOpts, proxy, tunnel) {
const isHttpsRequest = reqOpts.protocol === "https:";
const transports = reqOpts.maxRedirects === 0 ? {
http,
https
} : {
http: follow.http,
https: follow.https
};
const transports = reqOpts.maxRedirects === 0 ? { http, https } : { http: follow.http, https: follow.https };
if (!proxy || tunnel) {

@@ -483,9 +483,7 @@ return isHttpsRequest ? transports.https : transports.http;

}
const getIt = function () {
let initMiddleware = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
let httpRequest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : httpRequester;
return createRequester(initMiddleware, httpRequest);
};
const getIt = (initMiddleware = [], httpRequest = httpRequester) => createRequester(initMiddleware, httpRequest);
const environment = "node";
export { adapter, environment, getIt };
//# sourceMappingURL=index.js.map

@@ -1,5 +0,7 @@

import { createRequester } from './_chunks/createRequester-ryeXkh0z.js';
import { createRequester } from './_chunks/createRequester-46TmGIk5.js';
import parseHeaders from 'parse-headers';
var __accessCheck = (obj, member, msg) => {
if (!member.has(obj)) throw TypeError("Cannot " + msg);
if (!member.has(obj))
throw TypeError("Cannot " + msg);
};

@@ -11,3 +13,4 @@ var __privateGet = (obj, member, getter) => {

var __privateAdd = (obj, member, value) => {
if (member.has(obj)) throw TypeError("Cannot add the same private member more than once");
if (member.has(obj))
throw TypeError("Cannot add the same private member more than once");
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);

@@ -60,4 +63,3 @@ };

// Allow setting extra fetch init options, needed for runtimes such as Vercel Edge to set `cache` and other options in React Server Components
setInit(init) {
let useAbortSignal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
setInit(init, useAbortSignal = true) {
__privateSet(this, _init, init);

@@ -83,3 +85,3 @@ __privateSet(this, _useAbortSignal, useAbortSignal);

}
fetch(__privateGet(this, _url), options).then(res => {
fetch(__privateGet(this, _url), options).then((res) => {
res.headers.forEach((value, key) => {

@@ -92,3 +94,3 @@ __privateSet(this, _resHeaders, __privateGet(this, _resHeaders) + "".concat(key, ": ").concat(value, "\r\n"));

return textBody ? res.text() : res.arrayBuffer();
}).then(resBody => {
}).then((resBody) => {
if (typeof resBody === "string") {

@@ -101,3 +103,3 @@ this.responseText = resBody;

this.onreadystatechange();
}).catch(err => {
}).catch((err) => {
var _a;

@@ -119,2 +121,3 @@ if (err.name === "AbortError") {

_useAbortSignal = new WeakMap();
const adapter = typeof XMLHttpRequest === "function" ? "xhr" : "fetch";

@@ -134,5 +137,3 @@ const XmlHttpRequest = adapter === "xhr" ? XMLHttpRequest : FetchXhr;

const cancel = () => clearTimeout(cbTimer);
return {
abort: cancel
};
return { abort: cancel };
}

@@ -148,7 +149,15 @@ let xhr = new XmlHttpRequest();

let timedOut = false;
xhr.onerror = event => {
onError(new Error("Request error while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")));
xhr.onerror = (event) => {
onError(
new Error(
"Request error while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")
)
);
};
xhr.ontimeout = event => {
onError(new Error("Request timeout while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")));
xhr.ontimeout = (event) => {
onError(
new Error(
"Request timeout while attempting to reach ".concat(options.url).concat(event.lengthComputable ? "(".concat(event.loaded, " of ").concat(event.total, " bytes transferred)") : "")
)
);
};

@@ -169,4 +178,7 @@ xhr.onabort = () => {

};
xhr.open(options.method, options.url, true
// Always async
xhr.open(
options.method,
options.url,
true
// Always async
);

@@ -184,8 +196,3 @@ xhr.withCredentials = !!options.withCredentials;

}
context.applyMiddleware("onRequest", {
options,
adapter,
request: xhr,
context
});
context.applyMiddleware("onRequest", { options, adapter, request: xhr, context });
xhr.send(options.body || null);

@@ -195,5 +202,3 @@ if (delays) {

}
return {
abort
};
return { abort };
function abort() {

@@ -208,3 +213,5 @@ aborted = true;

xhr.abort();
const error = new Error(code === "ESOCKETTIMEDOUT" ? "Socket timed out on request to ".concat(options.url) : "Connection timed out on request to ".concat(options.url));
const error = new Error(
code === "ESOCKETTIMEDOUT" ? "Socket timed out on request to ".concat(options.url) : "Connection timed out on request to ".concat(options.url)
);
error.code = code;

@@ -263,9 +270,8 @@ context.channels.error.publish(error);

};
const getIt = function () {
let initMiddleware = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
let httpRequest = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : httpRequester;
return createRequester(initMiddleware, httpRequest);
};
const getIt = (initMiddleware = [], httpRequest = httpRequester) => createRequester(initMiddleware, httpRequest);
const environment = "react-server";
export { adapter, environment, getIt };
//# sourceMappingURL=index.react-server.js.map
import debugIt from 'debug';
export { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-dittwL7d.js';
export { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-N21NGwyb.js';
import { isPlainObject } from 'is-plain-object';
function agent(opts) {
return {};
}
const leadingSlash = /^\//;

@@ -12,3 +14,3 @@ const trailingSlash = /\/$/;

return {
processOptions: options => {
processOptions: (options) => {
if (/^https?:\/\//i.test(options.url)) {

@@ -18,8 +20,7 @@ return options;

const url = [baseUri, options.url.replace(leadingSlash, "")].join("/");
return Object.assign({}, options, {
url
});
return Object.assign({}, options, { url });
}
};
}
const SENSITIVE_HEADERS = ["cookie", "authorization"];

@@ -36,4 +37,3 @@ const hasOwn = Object.prototype.hasOwnProperty;

};
function debug() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function debug(opts = {}) {
const verbose = opts.verbose;

@@ -46,3 +46,3 @@ const namespace = opts.namespace || "get-it";

return {
processOptions: options => {
processOptions: (options) => {
options.debug = log;

@@ -52,3 +52,3 @@ options.requestId = options.requestId || ++requestId;

},
onRequest: event => {
onRequest: (event) => {
if (shortCircuit || !event) {

@@ -103,6 +103,6 @@ return event;

}
function headers(_headers) {
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
function headers(_headers, opts = {}) {
return {
processOptions: options => {
processOptions: (options) => {
const existing = options.headers || {};

@@ -114,2 +114,3 @@ options.headers = opts.override ? Object.assign({}, existing, _headers) : Object.assign({}, _headers, existing);

}
class HttpError extends Error {

@@ -137,4 +138,4 @@ constructor(res, ctx) {

}
function injectResponse() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function injectResponse(opts = {}) {
if (typeof opts.inject !== "function") {

@@ -159,11 +160,11 @@ throw new Error("`injectResponse` middleware requires a `inject` function");

};
return {
interceptRequest: inject
};
return { interceptRequest: inject };
}
const isBuffer = typeof Buffer === "undefined" ? () => false : obj => Buffer.isBuffer(obj);
const isBuffer = typeof Buffer === "undefined" ? () => false : (obj) => Buffer.isBuffer(obj);
const serializeTypes = ["boolean", "string", "number"];
function jsonRequest() {
return {
processOptions: options => {
processOptions: (options) => {
const body = options.body;

@@ -187,5 +188,6 @@ if (!body) {

}
function jsonResponse(opts) {
return {
onResponse: response => {
onResponse: (response) => {
const contentType = response.headers["content-type"] || "";

@@ -196,10 +198,6 @@ const shouldDecode = opts && opts.force || contentType.indexOf("application/json") !== -1;

}
return Object.assign({}, response, {
body: tryParse(response.body)
});
return Object.assign({}, response, { body: tryParse(response.body) });
},
processOptions: options => Object.assign({}, options, {
headers: Object.assign({
Accept: "application/json"
}, options.headers)
processOptions: (options) => Object.assign({}, options, {
headers: Object.assign({ Accept: "application/json" }, options.headers)
})

@@ -216,7 +214,8 @@ };

}
function isBrowserOptions(options) {
return typeof options === "object" && options !== null && !("protocol" in options);
}
function mtls() {
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function mtls(config = {}) {
if (!config.ca) {

@@ -232,3 +231,3 @@ throw new Error('Required mtls option "ca" is missing');

return {
finalizeOptions: options => {
finalizeOptions: (options) => {
if (isBrowserOptions(options)) {

@@ -246,2 +245,3 @@ return options;

}
let actualGlobal = {};

@@ -258,20 +258,21 @@ if (typeof globalThis !== "undefined") {

var global$1 = actualGlobal;
function observable() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const Observable =
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- @TODO consider dropping checking for a global Observable since it's not on a standards track
opts.implementation || global$1.Observable;
function observable(opts = {}) {
const Observable = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- @TODO consider dropping checking for a global Observable since it's not on a standards track
opts.implementation || global$1.Observable
);
if (!Observable) {
throw new Error("`Observable` is not available in global scope, and no implementation was passed");
throw new Error(
"`Observable` is not available in global scope, and no implementation was passed"
);
}
return {
onReturn: (channels, context) => new Observable(observer => {
channels.error.subscribe(err => observer.error(err));
channels.progress.subscribe(event => observer.next(Object.assign({
type: "progress"
}, event)));
channels.response.subscribe(response => {
observer.next(Object.assign({
type: "response"
}, response));
onReturn: (channels, context) => new Observable((observer) => {
channels.error.subscribe((err) => observer.error(err));
channels.progress.subscribe(
(event) => observer.next(Object.assign({ type: "progress" }, event))
);
channels.response.subscribe((response) => {
observer.next(Object.assign({ type: "response" }, response));
observer.complete();

@@ -284,5 +285,6 @@ });

}
function progress() {
return {
onRequest: evt => {
onRequest: (evt) => {
if (evt.adapter !== "xhr") {

@@ -300,3 +302,3 @@ return;

function handleProgress(stage) {
return event => {
return (event) => {
const percent = event.lengthComputable ? event.loaded / event.total * 100 : -1;

@@ -315,4 +317,4 @@ context.channels.progress.publish({

}
const promise = function () {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const promise = (options = {}) => {
const PromiseImplementation = options.implementation || Promise;

@@ -326,3 +328,3 @@ if (!PromiseImplementation) {

if (cancel) {
cancel.promise.then(reason => {
cancel.promise.then((reason) => {
channels.abort.publish(reason);

@@ -333,3 +335,3 @@ reject(reason);

channels.error.subscribe(reject);
channels.response.subscribe(response => {
channels.response.subscribe((response) => {
resolve(options.onlyBody ? response.body : response);

@@ -362,6 +364,6 @@ });

let resolvePromise = null;
this.promise = new Promise(resolve => {
this.promise = new Promise((resolve) => {
resolvePromise = resolve;
});
executor(message => {
executor((message) => {
if (this.reason) {

@@ -377,3 +379,3 @@ return;

let cancel;
const token = new _CancelToken(can => {
const token = new _CancelToken((can) => {
cancel = can;

@@ -387,6 +389,7 @@ });

let CancelToken = _CancelToken;
const isCancel = value => !!(value && (value == null ? void 0 : value.__CANCEL__));
const isCancel = (value) => !!(value && (value == null ? void 0 : value.__CANCEL__));
promise.Cancel = Cancel;
promise.CancelToken = CancelToken;
promise.isCancel = isCancel;
function proxy(_proxy) {

@@ -397,7 +400,6 @@ if (_proxy !== false && (!_proxy || !_proxy.host)) {

return {
processOptions: options => Object.assign({
proxy: _proxy
}, options)
processOptions: (options) => Object.assign({ proxy: _proxy }, options)
};
}
var defaultShouldRetry = (err, attempt, options) => {

@@ -409,4 +411,5 @@ if (options.method !== "GET" && options.method !== "HEAD") {

};
const isStream = stream => stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
var sharedRetry = opts => {
const isStream = (stream) => stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
var sharedRetry = (opts) => {
const maxRetries = opts.maxRetries || 5;

@@ -428,5 +431,3 @@ const retryDelay = opts.retryDelay || getRetryDelay;

const newContext = Object.assign({}, context, {
options: Object.assign({}, options, {
attemptNumber: attemptNumber + 1
})
options: Object.assign({}, options, { attemptNumber: attemptNumber + 1 })
});

@@ -441,10 +442,6 @@ setTimeout(() => context.channels.request.publish(newContext), retryDelay(attemptNumber));

}
const retry = function () {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return sharedRetry({
shouldRetry: defaultShouldRetry,
...opts
});
};
const retry = (opts = {}) => sharedRetry({ shouldRetry: defaultShouldRetry, ...opts });
retry.shouldRetry = defaultShouldRetry;
function encode(data) {

@@ -477,3 +474,3 @@ const query = new URLSearchParams();

return {
processOptions: options => {
processOptions: (options) => {
const body = options.body;

@@ -499,5 +496,5 @@ if (!body) {

}
function buildKeepAlive(agent) {
return function keepAlive() {
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return function keepAlive(config = {}) {
const ms = config.ms || 1e3;

@@ -513,4 +510,6 @@ const maxFree = config.maxFree || 256;

}
const keepAlive = buildKeepAlive(agent);
export { Cancel, CancelToken, agent, base, debug, headers, httpErrors, injectResponse, jsonRequest, jsonResponse, keepAlive, mtls, observable, progress, promise, proxy, retry, urlEncoded };
//# sourceMappingURL=middleware.browser.js.map
import { Agent } from 'http';
import { Agent as Agent$1 } from 'https';
import debugIt from 'debug';
export { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-dittwL7d.js';
export { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-N21NGwyb.js';
import { isPlainObject } from 'is-plain-object';
import progressStream from 'progress-stream';
import allowed from 'is-retry-allowed';
const isHttpsProto = /^https:/i;

@@ -12,8 +13,5 @@ function agent(opts) {

const httpsAgent = new Agent$1(opts);
const agents = {
http: httpAgent,
https: httpsAgent
};
const agents = { http: httpAgent, https: httpsAgent };
return {
finalizeOptions: options => {
finalizeOptions: (options) => {
if (options.agent) {

@@ -23,15 +21,10 @@ return options;

if (options.maxRedirects > 0) {
return {
...options,
agents
};
return { ...options, agents };
}
const isHttps = isHttpsProto.test(options.href || options.protocol);
return {
...options,
agent: isHttps ? httpsAgent : httpAgent
};
return { ...options, agent: isHttps ? httpsAgent : httpAgent };
}
};
}
const leadingSlash = /^\//;

@@ -42,3 +35,3 @@ const trailingSlash = /\/$/;

return {
processOptions: options => {
processOptions: (options) => {
if (/^https?:\/\//i.test(options.url)) {

@@ -48,8 +41,7 @@ return options;

const url = [baseUri, options.url.replace(leadingSlash, "")].join("/");
return Object.assign({}, options, {
url
});
return Object.assign({}, options, { url });
}
};
}
const SENSITIVE_HEADERS = ["cookie", "authorization"];

@@ -66,4 +58,3 @@ const hasOwn = Object.prototype.hasOwnProperty;

};
function debug() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function debug(opts = {}) {
const verbose = opts.verbose;

@@ -76,3 +67,3 @@ const namespace = opts.namespace || "get-it";

return {
processOptions: options => {
processOptions: (options) => {
options.debug = log;

@@ -82,3 +73,3 @@ options.requestId = options.requestId || ++requestId;

},
onRequest: event => {
onRequest: (event) => {
if (shortCircuit || !event) {

@@ -133,6 +124,6 @@ return event;

}
function headers(_headers) {
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
function headers(_headers, opts = {}) {
return {
processOptions: options => {
processOptions: (options) => {
const existing = options.headers || {};

@@ -144,2 +135,3 @@ options.headers = opts.override ? Object.assign({}, existing, _headers) : Object.assign({}, _headers, existing);

}
class HttpError extends Error {

@@ -167,4 +159,4 @@ constructor(res, ctx) {

}
function injectResponse() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function injectResponse(opts = {}) {
if (typeof opts.inject !== "function") {

@@ -189,11 +181,11 @@ throw new Error("`injectResponse` middleware requires a `inject` function");

};
return {
interceptRequest: inject
};
return { interceptRequest: inject };
}
const isBuffer = typeof Buffer === "undefined" ? () => false : obj => Buffer.isBuffer(obj);
const isBuffer = typeof Buffer === "undefined" ? () => false : (obj) => Buffer.isBuffer(obj);
const serializeTypes = ["boolean", "string", "number"];
function jsonRequest() {
return {
processOptions: options => {
processOptions: (options) => {
const body = options.body;

@@ -217,5 +209,6 @@ if (!body) {

}
function jsonResponse(opts) {
return {
onResponse: response => {
onResponse: (response) => {
const contentType = response.headers["content-type"] || "";

@@ -226,10 +219,6 @@ const shouldDecode = opts && opts.force || contentType.indexOf("application/json") !== -1;

}
return Object.assign({}, response, {
body: tryParse(response.body)
});
return Object.assign({}, response, { body: tryParse(response.body) });
},
processOptions: options => Object.assign({}, options, {
headers: Object.assign({
Accept: "application/json"
}, options.headers)
processOptions: (options) => Object.assign({}, options, {
headers: Object.assign({ Accept: "application/json" }, options.headers)
})

@@ -246,7 +235,8 @@ };

}
function isBrowserOptions(options) {
return typeof options === "object" && options !== null && !("protocol" in options);
}
function mtls() {
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
function mtls(config = {}) {
if (!config.ca) {

@@ -262,3 +252,3 @@ throw new Error('Required mtls option "ca" is missing');

return {
finalizeOptions: options => {
finalizeOptions: (options) => {
if (isBrowserOptions(options)) {

@@ -276,2 +266,3 @@ return options;

}
let actualGlobal = {};

@@ -288,20 +279,21 @@ if (typeof globalThis !== "undefined") {

var global$1 = actualGlobal;
function observable() {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const Observable =
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- @TODO consider dropping checking for a global Observable since it's not on a standards track
opts.implementation || global$1.Observable;
function observable(opts = {}) {
const Observable = (
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- @TODO consider dropping checking for a global Observable since it's not on a standards track
opts.implementation || global$1.Observable
);
if (!Observable) {
throw new Error("`Observable` is not available in global scope, and no implementation was passed");
throw new Error(
"`Observable` is not available in global scope, and no implementation was passed"
);
}
return {
onReturn: (channels, context) => new Observable(observer => {
channels.error.subscribe(err => observer.error(err));
channels.progress.subscribe(event => observer.next(Object.assign({
type: "progress"
}, event)));
channels.response.subscribe(response => {
observer.next(Object.assign({
type: "response"
}, response));
onReturn: (channels, context) => new Observable((observer) => {
channels.error.subscribe((err) => observer.error(err));
channels.progress.subscribe(
(event) => observer.next(Object.assign({ type: "progress" }, event))
);
channels.response.subscribe((response) => {
observer.next(Object.assign({ type: "response" }, response));
observer.complete();

@@ -314,4 +306,5 @@ });

}
function normalizer(stage) {
return prog => ({
return (prog) => ({
stage,

@@ -327,5 +320,3 @@ percent: prog.percentage,

onHeaders: (response, evt) => {
const _progress = progressStream({
time: 16
});
const _progress = progressStream({ time: 16 });
const normalize = normalizer("download");

@@ -337,6 +328,6 @@ const contentLength = response.headers["content-length"];

}
_progress.on("progress", prog => evt.context.channels.progress.publish(normalize(prog)));
_progress.on("progress", (prog) => evt.context.channels.progress.publish(normalize(prog)));
return response.pipe(_progress);
},
onRequest: evt => {
onRequest: (evt) => {
if (!evt.progress) {

@@ -346,8 +337,11 @@ return;

const normalize = normalizer("upload");
evt.progress.on("progress", prog => evt.context.channels.progress.publish(normalize(prog)));
evt.progress.on(
"progress",
(prog) => evt.context.channels.progress.publish(normalize(prog))
);
}
};
}
const promise = function () {
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
const promise = (options = {}) => {
const PromiseImplementation = options.implementation || Promise;

@@ -361,3 +355,3 @@ if (!PromiseImplementation) {

if (cancel) {
cancel.promise.then(reason => {
cancel.promise.then((reason) => {
channels.abort.publish(reason);

@@ -368,3 +362,3 @@ reject(reason);

channels.error.subscribe(reject);
channels.response.subscribe(response => {
channels.response.subscribe((response) => {
resolve(options.onlyBody ? response.body : response);

@@ -397,6 +391,6 @@ });

let resolvePromise = null;
this.promise = new Promise(resolve => {
this.promise = new Promise((resolve) => {
resolvePromise = resolve;
});
executor(message => {
executor((message) => {
if (this.reason) {

@@ -412,3 +406,3 @@ return;

let cancel;
const token = new _CancelToken(can => {
const token = new _CancelToken((can) => {
cancel = can;

@@ -422,6 +416,7 @@ });

let CancelToken = _CancelToken;
const isCancel = value => !!(value && (value == null ? void 0 : value.__CANCEL__));
const isCancel = (value) => !!(value && (value == null ? void 0 : value.__CANCEL__));
promise.Cancel = Cancel;
promise.CancelToken = CancelToken;
promise.isCancel = isCancel;
function proxy(_proxy) {

@@ -432,7 +427,6 @@ if (_proxy !== false && (!_proxy || !_proxy.host)) {

return {
processOptions: options => Object.assign({
proxy: _proxy
}, options)
processOptions: (options) => Object.assign({ proxy: _proxy }, options)
};
}
var defaultShouldRetry = (err, num, options) => {

@@ -447,4 +441,5 @@ if (options.method !== "GET" && options.method !== "HEAD") {

};
const isStream = stream => stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
var sharedRetry = opts => {
const isStream = (stream) => stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
var sharedRetry = (opts) => {
const maxRetries = opts.maxRetries || 5;

@@ -466,5 +461,3 @@ const retryDelay = opts.retryDelay || getRetryDelay;

const newContext = Object.assign({}, context, {
options: Object.assign({}, options, {
attemptNumber: attemptNumber + 1
})
options: Object.assign({}, options, { attemptNumber: attemptNumber + 1 })
});

@@ -479,10 +472,6 @@ setTimeout(() => context.channels.request.publish(newContext), retryDelay(attemptNumber));

}
const retry = function () {
let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return sharedRetry({
shouldRetry: defaultShouldRetry,
...opts
});
};
const retry = (opts = {}) => sharedRetry({ shouldRetry: defaultShouldRetry, ...opts });
retry.shouldRetry = defaultShouldRetry;
function encode(data) {

@@ -515,3 +504,3 @@ const query = new URLSearchParams();

return {
processOptions: options => {
processOptions: (options) => {
const body = options.body;

@@ -537,5 +526,5 @@ if (!body) {

}
function buildKeepAlive(agent) {
return function keepAlive() {
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return function keepAlive(config = {}) {
const ms = config.ms || 1e3;

@@ -551,4 +540,6 @@ const maxFree = config.maxFree || 256;

}
const keepAlive = buildKeepAlive(agent);
export { Cancel, CancelToken, agent, base, debug, headers, httpErrors, injectResponse, jsonRequest, jsonResponse, keepAlive, mtls, observable, progress, promise, proxy, retry, urlEncoded };
//# sourceMappingURL=middleware.js.map
{
"name": "get-it",
"version": "8.4.5",
"version": "8.4.6",
"workspaces": [

@@ -115,4 +115,4 @@ "test-next"

"devDependencies": {
"@edge-runtime/vm": "^3.1.7",
"@sanity/pkg-utils": "^3.3.7",
"@edge-runtime/vm": "^3.1.8",
"@sanity/pkg-utils": "^4.0.0",
"@sanity/semantic-release-preset": "^4.1.6",

@@ -124,5 +124,5 @@ "@types/debug": "^4.1.10",

"@types/zen-observable": "^0.8.7",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@vitest/coverage-v8": "^1.1.3",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@vitest/coverage-v8": "^1.2.1",
"eslint": "^8.56.0",

@@ -137,8 +137,8 @@ "eslint-config-prettier": "^9.1.0",

"node-fetch": "^2.6.7",
"prettier": "^3.1.1",
"prettier": "^3.2.4",
"prettier-plugin-packagejson": "^2.4.9",
"rimraf": "^5.0.1",
"typescript": "^5.3.3",
"vite": "5.0.11",
"vitest": "^1.1.3",
"vite": "5.0.12",
"vitest": "^1.2.1",
"vitest-github-actions-reporter": "^0.11.1",

@@ -145,0 +145,0 @@ "zen-observable": "^0.10.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc