Comparing version 8.2.0 to 8.3.0
@@ -120,2 +120,13 @@ import { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-11b3788b.js'; | ||
} | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value | ||
}) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
var __accessCheck = (obj, member, msg) => { | ||
@@ -141,6 +152,18 @@ if (!member.has(obj)) throw TypeError("Cannot " + msg); | ||
/** | ||
* Public interface, interop with real XMLHttpRequest | ||
*/ | ||
__publicField(this, "onabort"); | ||
__publicField(this, "onerror"); | ||
__publicField(this, "onreadystatechange"); | ||
__publicField(this, "ontimeout"); | ||
/** | ||
* https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState | ||
*/ | ||
this.readyState = 0; | ||
this.responseType = ""; | ||
__publicField(this, "readyState", 0); | ||
__publicField(this, "response"); | ||
__publicField(this, "responseText"); | ||
__publicField(this, "responseType", ""); | ||
__publicField(this, "status"); | ||
__publicField(this, "statusText"); | ||
__publicField(this, "withCredentials"); | ||
/** | ||
@@ -147,0 +170,0 @@ * Private implementation details |
import debugIt from 'debug'; | ||
export { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-11b3788b.js'; | ||
import { isPlainObject } from 'is-plain-object'; | ||
function agent(opts) { | ||
return {}; | ||
} | ||
const leadingSlash = /^\//; | ||
@@ -105,5 +108,18 @@ const trailingSlash = /\/$/; | ||
} | ||
var __defProp$1 = Object.defineProperty; | ||
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value | ||
}) : obj[key] = value; | ||
var __publicField$1 = (obj, key, value) => { | ||
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
class HttpError extends Error { | ||
constructor(res, ctx) { | ||
super(); | ||
__publicField$1(this, "response"); | ||
__publicField$1(this, "request"); | ||
const truncatedUrl = res.url.length > 400 ? "".concat(res.url.slice(0, 399), "\u2026") : res.url; | ||
@@ -203,3 +219,2 @@ let msg = "".concat(res.method, "-request to ").concat(truncatedUrl, " resulted in "); | ||
} | ||
function keepAlive() {} | ||
function isBrowserOptions(options) { | ||
@@ -298,2 +313,13 @@ return typeof options === "object" && options !== null && !("protocol" in options); | ||
} | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value | ||
}) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
const promise = function () { | ||
@@ -330,3 +356,4 @@ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
constructor(message) { | ||
this.__CANCEL__ = true; | ||
__publicField(this, "__CANCEL__", true); | ||
__publicField(this, "message"); | ||
this.message = message; | ||
@@ -338,4 +365,6 @@ } | ||
} | ||
const _CancelToken = class { | ||
const _CancelToken = class _CancelToken { | ||
constructor(executor) { | ||
__publicField(this, "promise"); | ||
__publicField(this, "reason"); | ||
if (typeof executor !== "function") { | ||
@@ -357,4 +386,3 @@ throw new TypeError("executor must be a function."); | ||
}; | ||
let CancelToken = _CancelToken; | ||
CancelToken.source = () => { | ||
__publicField(_CancelToken, "source", () => { | ||
let cancel; | ||
@@ -369,3 +397,4 @@ const token = new _CancelToken(can => { | ||
}; | ||
}; | ||
}); | ||
let CancelToken = _CancelToken; | ||
const isCancel = value => !!(value && (value == null ? void 0 : value.__CANCEL__)); | ||
@@ -477,3 +506,17 @@ promise.Cancel = Cancel; | ||
} | ||
export { Cancel, CancelToken, base, debug, headers, httpErrors, injectResponse, jsonRequest, jsonResponse, keepAlive, mtls, observable, progress, promise, proxy, retry, urlEncoded }; | ||
function buildKeepAlive(agent) { | ||
return function keepAlive() { | ||
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const ms = config.ms || 1e3; | ||
const maxFree = config.maxFree || 256; | ||
const agentOptions = { | ||
keepAlive: true, | ||
keepAliveMsecs: ms, | ||
maxFreeSockets: maxFree | ||
}; | ||
return agent(agentOptions); | ||
}; | ||
} | ||
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 |
@@ -7,2 +7,3 @@ import cjs from './middleware.cjs'; | ||
export const CancelToken = cjs.CancelToken; | ||
export const agent = cjs.agent; | ||
export const base = cjs.base; | ||
@@ -9,0 +10,0 @@ export const debug = cjs.debug; |
/// <reference types="node" /> | ||
import {AgentOptions} from 'node:http' | ||
import type {IncomingHttpHeaders} from 'node:http' | ||
@@ -11,2 +12,9 @@ import {IncomingHttpHeaders as IncomingHttpHeaders_2} from 'http' | ||
/** | ||
* Constructs a http.Agent and uses it for all requests. | ||
* This can be used to override settings such as `maxSockets`, `maxTotalSockets` (to limit concurrency) or change the `timeout`. | ||
* @public | ||
*/ | ||
export declare function agent(opts?: AgentOptions): any | ||
/** @public */ | ||
@@ -164,7 +172,3 @@ export declare type ApplyMiddleware = <T extends keyof MiddlewareHooks>( | ||
/** @public */ | ||
export declare function keepAlive(config?: any): { | ||
finalizeOptions: ( | ||
options: RequestOptions | FinalizeNodeOptionsPayload | ||
) => RequestOptions | FinalizeNodeOptionsPayload | ||
} | ||
export declare const keepAlive: (config?: any) => any | ||
@@ -171,0 +175,0 @@ /** @public */ |
@@ -0,8 +1,35 @@ | ||
import { Agent } from 'node:http'; | ||
import { Agent as Agent$1 } from 'node:https'; | ||
import debugIt from 'debug'; | ||
export { processOptions, validateOptions } from './_chunks/defaultOptionsValidator-11b3788b.js'; | ||
import { isPlainObject } from 'is-plain-object'; | ||
import http from 'http'; | ||
import https from 'https'; | ||
import progressStream from 'progress-stream'; | ||
import allowed from 'is-retry-allowed'; | ||
const isHttpsProto = /^https:/i; | ||
function agent(opts) { | ||
const httpAgent = new Agent(opts); | ||
const httpsAgent = new Agent$1(opts); | ||
const agents = { | ||
http: httpAgent, | ||
https: httpsAgent | ||
}; | ||
return { | ||
finalizeOptions: options => { | ||
if (options.agent) { | ||
return options; | ||
} | ||
if (options.maxRedirects > 0) { | ||
return { | ||
...options, | ||
agents | ||
}; | ||
} | ||
const isHttps = isHttpsProto.test(options.href || options.protocol); | ||
return { | ||
...options, | ||
agent: isHttps ? httpsAgent : httpAgent | ||
}; | ||
} | ||
}; | ||
} | ||
const leadingSlash = /^\//; | ||
@@ -109,5 +136,18 @@ const trailingSlash = /\/$/; | ||
} | ||
var __defProp$1 = Object.defineProperty; | ||
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value | ||
}) : obj[key] = value; | ||
var __publicField$1 = (obj, key, value) => { | ||
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
class HttpError extends Error { | ||
constructor(res, ctx) { | ||
super(); | ||
__publicField$1(this, "response"); | ||
__publicField$1(this, "request"); | ||
const truncatedUrl = res.url.length > 400 ? "".concat(res.url.slice(0, 399), "\u2026") : res.url; | ||
@@ -210,36 +250,2 @@ let msg = "".concat(res.method, "-request to ").concat(truncatedUrl, " resulted in "); | ||
} | ||
const isHttpsProto = /^https:/i; | ||
function keepAlive() { | ||
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const ms = config.ms || 1e3; | ||
const maxFree = config.maxFree || 256; | ||
const agentOptions = { | ||
keepAlive: true, | ||
keepAliveMsecs: ms, | ||
maxFreeSockets: maxFree | ||
}; | ||
const httpAgent = new http.Agent(agentOptions); | ||
const httpsAgent = new https.Agent(agentOptions); | ||
const agents = { | ||
http: httpAgent, | ||
https: httpsAgent | ||
}; | ||
return { | ||
finalizeOptions: options => { | ||
if (isBrowserOptions(options)) { | ||
return options; | ||
} | ||
if (options.agent) { | ||
return options; | ||
} | ||
const isHttps = isHttpsProto.test(options.href || options.protocol); | ||
const keepOpts = options.maxRedirects === 0 ? { | ||
agent: isHttps ? httpsAgent : httpAgent | ||
} : { | ||
agents | ||
}; | ||
return Object.assign({}, options, keepOpts); | ||
} | ||
}; | ||
} | ||
function mtls() { | ||
@@ -339,2 +345,13 @@ let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
} | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value | ||
}) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
const promise = function () { | ||
@@ -371,3 +388,4 @@ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
constructor(message) { | ||
this.__CANCEL__ = true; | ||
__publicField(this, "__CANCEL__", true); | ||
__publicField(this, "message"); | ||
this.message = message; | ||
@@ -379,4 +397,6 @@ } | ||
} | ||
const _CancelToken = class { | ||
const _CancelToken = class _CancelToken { | ||
constructor(executor) { | ||
__publicField(this, "promise"); | ||
__publicField(this, "reason"); | ||
if (typeof executor !== "function") { | ||
@@ -398,4 +418,3 @@ throw new TypeError("executor must be a function."); | ||
}; | ||
let CancelToken = _CancelToken; | ||
CancelToken.source = () => { | ||
__publicField(_CancelToken, "source", () => { | ||
let cancel; | ||
@@ -410,3 +429,4 @@ const token = new _CancelToken(can => { | ||
}; | ||
}; | ||
}); | ||
let CancelToken = _CancelToken; | ||
const isCancel = value => !!(value && (value == null ? void 0 : value.__CANCEL__)); | ||
@@ -521,3 +541,17 @@ promise.Cancel = Cancel; | ||
} | ||
export { Cancel, CancelToken, base, debug, headers, httpErrors, injectResponse, jsonRequest, jsonResponse, keepAlive, mtls, observable, progress, promise, proxy, retry, urlEncoded }; | ||
function buildKeepAlive(agent) { | ||
return function keepAlive() { | ||
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
const ms = config.ms || 1e3; | ||
const maxFree = config.maxFree || 256; | ||
const agentOptions = { | ||
keepAlive: true, | ||
keepAliveMsecs: ms, | ||
maxFreeSockets: maxFree | ||
}; | ||
return agent(agentOptions); | ||
}; | ||
} | ||
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.2.0", | ||
"version": "8.3.0", | ||
"description": "Generic HTTP request library for node, browsers and workers", | ||
@@ -127,3 +127,3 @@ "keywords": [ | ||
"@typescript-eslint/parser": "^5.60.1", | ||
"@vitest/coverage-v8": "^0.32.0", | ||
"@vitest/coverage-v8": "^0.33.0", | ||
"eslint": "^8.36.0", | ||
@@ -142,4 +142,4 @@ "eslint-config-prettier": "^8.7.0", | ||
"typescript": "^5.1.3", | ||
"vite": "^4.2.1", | ||
"vitest": "^0.32.0", | ||
"vite": "4.3.9", | ||
"vitest": "^0.33.0", | ||
"vitest-github-actions-reporter": "^0.10.0", | ||
@@ -146,0 +146,0 @@ "zen-observable": "^0.10.0" |
@@ -0,1 +1,2 @@ | ||
export * from './middleware/agent/browser-agent' | ||
export * from './middleware/base' | ||
@@ -10,3 +11,2 @@ export * from './middleware/debug' | ||
export * from './middleware/jsonResponse' | ||
export * from './middleware/keepAlive/browser-keepAlive' | ||
export * from './middleware/mtls' | ||
@@ -20,1 +20,6 @@ export * from './middleware/observable' | ||
export type * from './types' | ||
import {agent} from './middleware/agent/browser-agent' | ||
import {buildKeepAlive} from './middleware/keepAlive' | ||
/** @public */ | ||
export const keepAlive = buildKeepAlive(agent) |
@@ -0,1 +1,2 @@ | ||
export * from './middleware/agent/node-agent' | ||
export * from './middleware/base' | ||
@@ -10,3 +11,2 @@ export * from './middleware/debug' | ||
export * from './middleware/jsonResponse' | ||
export * from './middleware/keepAlive/node-keepAlive' | ||
export * from './middleware/mtls' | ||
@@ -20,1 +20,6 @@ export * from './middleware/observable' | ||
export type * from './types' | ||
import {agent} from './middleware/agent/node-agent' | ||
import {buildKeepAlive} from './middleware/keepAlive' | ||
/** @public */ | ||
export const keepAlive = buildKeepAlive(agent) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
570932
71
6814
6