@stryke/http 0.11.10 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +2 -2
- package/dist/fetch.cjs +41 -17
- package/dist/fetch.d.ts +30 -1
- package/dist/fetch.mjs +1 -1
- package/dist/get-free-port.cjs +9 -8
- package/dist/get-free-port.d.ts +1 -1
- package/dist/get-free-port.mjs +1 -1
- package/dist/http-proxy.d.ts +1 -2
- package/dist/https-proxy.d.ts +1 -2
- package/dist/parse-response.d.ts +6 -0
- package/dist/proxy-agent.d.ts +2 -0
- package/package.json +9 -3
package/dist/agent.d.ts
CHANGED
|
@@ -12,9 +12,9 @@ interface HttpsConnectOpts extends tls.ConnectionOptions {
|
|
|
12
12
|
port: number;
|
|
13
13
|
}
|
|
14
14
|
export type AgentConnectOpts = HttpConnectOpts | HttpsConnectOpts;
|
|
15
|
-
declare const
|
|
15
|
+
declare const SYMBOL_INTERNAL: unique symbol;
|
|
16
16
|
export declare abstract class Agent extends http.Agent {
|
|
17
|
-
private [
|
|
17
|
+
private [SYMBOL_INTERNAL];
|
|
18
18
|
options: Partial<net.TcpNetConnectOpts & tls.ConnectionOptions>;
|
|
19
19
|
keepAlive: boolean;
|
|
20
20
|
constructor(opts?: http.AgentOptions);
|
package/dist/fetch.cjs
CHANGED
|
@@ -4,36 +4,60 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.fetch = void 0;
|
|
7
|
+
exports.fetchJSON = fetchJSON;
|
|
7
8
|
exports.fetchRequest = fetchRequest;
|
|
8
|
-
|
|
9
|
+
exports.fetchString = fetchString;
|
|
10
|
+
var _bufferToString = require("@stryke/convert/buffer-to-string");
|
|
11
|
+
var _stormJson = require("@stryke/json/storm-json");
|
|
12
|
+
var _isSetString = require("@stryke/type-checks/is-set-string");
|
|
13
|
+
var _isUrl = require("@stryke/type-checks/is-url");
|
|
14
|
+
var _helpers = require("@stryke/url/helpers");
|
|
9
15
|
var _defu = require("defu");
|
|
10
16
|
var _nodeBuffer = require("node:buffer");
|
|
11
17
|
var _nodeHttp = _interopRequireDefault(require("node:http"));
|
|
12
18
|
var _nodeHttps = _interopRequireDefault(require("node:https"));
|
|
13
19
|
var _proxyAgent = require("./proxy-agent.cjs");
|
|
14
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
async function fetchRequest(
|
|
16
|
-
return new Promise((
|
|
17
|
-
let
|
|
18
|
-
(0,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
async function fetchRequest(t, r = {}) {
|
|
22
|
+
return new Promise((i, s) => {
|
|
23
|
+
let p = "http:";
|
|
24
|
+
if ((0, _isSetString.isSetString)(t)) {
|
|
25
|
+
if (!(0, _helpers.isValidURL)(t)) {
|
|
26
|
+
s(new Error(`Invalid URL format provided: ${t}`));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
p = new URL(t).protocol;
|
|
30
|
+
} else if ((0, _isUrl.isURL)(t)) p = t.protocol;else {
|
|
31
|
+
s(new Error("Invalid URL provided to fetch"));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const m = p === "https:" ? _nodeHttps.default : _nodeHttp.default,
|
|
35
|
+
c = r.timeout ?? 3e3,
|
|
36
|
+
n = m.request(t, (0, _defu.defu)(r, {
|
|
22
37
|
agent: (0, _proxyAgent.getProxyAgent)(),
|
|
23
38
|
headers: {
|
|
24
39
|
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
|
|
25
40
|
}
|
|
26
|
-
}),
|
|
27
|
-
if (
|
|
28
|
-
|
|
41
|
+
}), e => {
|
|
42
|
+
if (e.statusCode !== 200) {
|
|
43
|
+
s(new Error(`Request failed: ${t.toString()} (status: ${e.statusCode})`));
|
|
29
44
|
return;
|
|
30
45
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
46
|
+
const f = [];
|
|
47
|
+
e.on("data", o => f.push(_nodeBuffer.Buffer.from(o))), e.on("end", () => {
|
|
48
|
+
const o = _nodeBuffer.Buffer.concat(f);
|
|
49
|
+
o.text = () => (0, _bufferToString.bufferToString)(o), o.json = () => _stormJson.StormJSON.parse(o.text()), i(o);
|
|
50
|
+
});
|
|
33
51
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}),
|
|
52
|
+
c && n.setTimeout(c, () => {
|
|
53
|
+
n.destroy(new Error(`Request timed out after ${c}ms`));
|
|
54
|
+
}), n.on("error", e => s(e)), n.end();
|
|
37
55
|
});
|
|
38
56
|
}
|
|
39
|
-
const fetch = exports.fetch = fetchRequest;
|
|
57
|
+
const fetch = exports.fetch = fetchRequest;
|
|
58
|
+
async function fetchString(t, r = {}) {
|
|
59
|
+
return (await fetchRequest(t, r)).text();
|
|
60
|
+
}
|
|
61
|
+
async function fetchJSON(t, r = {}) {
|
|
62
|
+
return (await fetchRequest(t, r)).json();
|
|
63
|
+
}
|
package/dist/fetch.d.ts
CHANGED
|
@@ -8,6 +8,21 @@ export interface FetchRequestOptions extends RequestOptions {
|
|
|
8
8
|
*/
|
|
9
9
|
timeout?: number;
|
|
10
10
|
}
|
|
11
|
+
export interface FetchResponse extends Buffer {
|
|
12
|
+
/**
|
|
13
|
+
* Parses the response body as JSON.
|
|
14
|
+
*
|
|
15
|
+
* @typeParam T - The type to parse the JSON as.
|
|
16
|
+
* @returns The parsed JSON object.
|
|
17
|
+
*/
|
|
18
|
+
json: <T extends object = Record<string, any>>() => T;
|
|
19
|
+
/**
|
|
20
|
+
* Converts the response body to a string.
|
|
21
|
+
*
|
|
22
|
+
* @returns The response body as a string.
|
|
23
|
+
*/
|
|
24
|
+
text: () => string;
|
|
25
|
+
}
|
|
11
26
|
/**
|
|
12
27
|
* Fetches a resource from a URL.
|
|
13
28
|
*
|
|
@@ -17,5 +32,19 @@ export interface FetchRequestOptions extends RequestOptions {
|
|
|
17
32
|
* @param url - The URL to fetch.
|
|
18
33
|
* @returns A promise that resolves to the response body as a Buffer.
|
|
19
34
|
*/
|
|
20
|
-
export declare function fetchRequest(url: string | URL, options?: FetchRequestOptions): Promise<
|
|
35
|
+
export declare function fetchRequest(url: string | URL, options?: FetchRequestOptions): Promise<FetchResponse>;
|
|
21
36
|
export declare const fetch: typeof fetchRequest;
|
|
37
|
+
/**
|
|
38
|
+
* Fetches a string resource from a URL.
|
|
39
|
+
*
|
|
40
|
+
* @param url - The URL to fetch.
|
|
41
|
+
* @returns A promise that resolves to the response body as a Buffer.
|
|
42
|
+
*/
|
|
43
|
+
export declare function fetchString(url: string | URL, options?: FetchRequestOptions): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Fetches a JSON resource from a URL.
|
|
46
|
+
*
|
|
47
|
+
* @param url - The URL to fetch.
|
|
48
|
+
* @returns A promise that resolves to the response body as a Buffer.
|
|
49
|
+
*/
|
|
50
|
+
export declare function fetchJSON<T extends object = Record<string, any>>(url: string | URL, options?: FetchRequestOptions): Promise<T>;
|
package/dist/fetch.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{bufferToString as d}from"@stryke/convert/buffer-to-string";import{StormJSON as u}from"@stryke/json/storm-json";import{isSetString as R}from"@stryke/type-checks/is-set-string";import{isURL as h}from"@stryke/type-checks/is-url";import{isValidURL as g}from"@stryke/url/helpers";import{defu as x}from"defu";import{Buffer as a}from"node:buffer";import l from"node:http";import q from"node:https";import{getProxyAgent as y}from"./proxy-agent";export async function fetchRequest(t,r={}){return new Promise((i,s)=>{let p="http:";if(R(t)){if(!g(t)){s(new Error(`Invalid URL format provided: ${t}`));return}p=new URL(t).protocol}else if(h(t))p=t.protocol;else{s(new Error("Invalid URL provided to fetch"));return}const m=p==="https:"?q:l,c=r.timeout??3e3,n=m.request(t,x(r,{agent:y(),headers:{"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}}),e=>{if(e.statusCode!==200){s(new Error(`Request failed: ${t.toString()} (status: ${e.statusCode})`));return}const f=[];e.on("data",o=>f.push(a.from(o))),e.on("end",()=>{const o=a.concat(f);o.text=()=>d(o),o.json=()=>u.parse(o.text()),i(o)})});c&&n.setTimeout(c,()=>{n.destroy(new Error(`Request timed out after ${c}ms`))}),n.on("error",e=>s(e)),n.end()})}export const fetch=fetchRequest;export async function fetchString(t,r={}){return(await fetchRequest(t,r)).text()}export async function fetchJSON(t,r={}){return(await fetchRequest(t,r)).json()}
|
package/dist/get-free-port.cjs
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getFreePort =
|
|
6
|
+
exports.getFreePort = getFreePort;
|
|
7
7
|
var _nodeHttp = require("node:http");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
async function getFreePort() {
|
|
9
|
+
return new Promise((o, s) => {
|
|
10
|
+
const r = (0, _nodeHttp.createServer)(() => {});
|
|
11
|
+
r.listen(0, () => {
|
|
12
|
+
const e = r.address();
|
|
13
|
+
r.close(), e && typeof e == "object" ? o(e.port) : s(new Error(`invalid address from server: ${e?.toString()}`));
|
|
14
|
+
});
|
|
13
15
|
});
|
|
14
|
-
}
|
|
15
|
-
exports.getFreePort = getFreePort;
|
|
16
|
+
}
|
package/dist/get-free-port.d.ts
CHANGED
package/dist/get-free-port.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createServer as t}from"node:http";export
|
|
1
|
+
import{createServer as t}from"node:http";export async function getFreePort(){return new Promise((o,s)=>{const r=t(()=>{});r.listen(0,()=>{const e=r.address();r.close(),e&&typeof e=="object"?o(e.port):s(new Error(`invalid address from server: ${e?.toString()}`))})})}
|
package/dist/http-proxy.d.ts
CHANGED
|
@@ -23,8 +23,7 @@ interface HttpProxyAgentClientRequest extends ClientRequest {
|
|
|
23
23
|
_implicitHeader: () => void;
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects
|
|
27
|
-
* to the specified "HTTP proxy server" in order to proxy HTTP requests.
|
|
26
|
+
* The `HttpProxyAgent` implements an HTTP Agent subclass that connects to the specified "HTTP proxy server" in order to proxy HTTP requests.
|
|
28
27
|
*/
|
|
29
28
|
export declare class HttpProxyAgent<Uri extends string> extends Agent {
|
|
30
29
|
static protocols: readonly ["http", "https"];
|
package/dist/https-proxy.d.ts
CHANGED
|
@@ -35,8 +35,7 @@ export declare class HttpsProxyAgent<Uri extends string> extends Agent {
|
|
|
35
35
|
connectOpts: net.TcpNetConnectOpts & tls.ConnectionOptions;
|
|
36
36
|
constructor(proxy: Uri | URL, opts?: HttpsProxyAgentOptions<Uri>);
|
|
37
37
|
/**
|
|
38
|
-
* Called when the node-core HTTP client library is creating a
|
|
39
|
-
* new HTTP request.
|
|
38
|
+
* Called when the node-core HTTP client library is creating a new HTTP request.
|
|
40
39
|
*/
|
|
41
40
|
connect(req: http.ClientRequest, opts: AgentConnectOpts): Promise<net.Socket>;
|
|
42
41
|
}
|
package/dist/parse-response.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ export interface ConnectResponse {
|
|
|
6
6
|
statusText: string;
|
|
7
7
|
headers: IncomingHttpHeaders;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Parses the proxy CONNECT response from the given socket.
|
|
11
|
+
*
|
|
12
|
+
* @param socket - The socket to read the response from.
|
|
13
|
+
* @returns A promise that resolves to the CONNECT response and any buffered data.
|
|
14
|
+
*/
|
|
9
15
|
export declare function parseProxyResponse(socket: Readable): Promise<{
|
|
10
16
|
connect: ConnectResponse;
|
|
11
17
|
buffered: Buffer;
|
package/dist/proxy-agent.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing HTTP communication utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
"directory": "packages/http"
|
|
10
10
|
},
|
|
11
11
|
"private": false,
|
|
12
|
-
"dependencies": {
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@stryke/convert": "^0.6.10",
|
|
14
|
+
"@stryke/type-checks": "^0.4.1",
|
|
15
|
+
"@stryke/url": "^0.3.1",
|
|
16
|
+
"defu": "^6.1.4",
|
|
17
|
+
"@stryke/json": "^0.9.13"
|
|
18
|
+
},
|
|
13
19
|
"devDependencies": { "@types/node": "^24.10.1" },
|
|
14
20
|
"publishConfig": { "access": "public" },
|
|
15
21
|
"sideEffects": false,
|
|
@@ -176,5 +182,5 @@
|
|
|
176
182
|
"main": "./dist/index.cjs",
|
|
177
183
|
"module": "./dist/index.mjs",
|
|
178
184
|
"types": "./dist/index.d.ts",
|
|
179
|
-
"gitHead": "
|
|
185
|
+
"gitHead": "bd066535c2758c8e05be32ad1e292cab7dcdf2d3"
|
|
180
186
|
}
|