@stryke/http 0.9.0 → 0.11.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/fetch.cjs +18 -17
- package/dist/fetch.d.ts +11 -9
- package/dist/fetch.mjs +1 -1
- package/dist/format-data-uri.d.ts +1 -3
- package/dist/get-free-port.cjs +15 -0
- package/dist/get-free-port.d.ts +6 -0
- package/dist/get-free-port.mjs +1 -0
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/package.json +17 -3
package/dist/fetch.cjs
CHANGED
|
@@ -3,36 +3,37 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.$fetch = $fetch;
|
|
7
6
|
exports.fetch = void 0;
|
|
7
|
+
exports.fetchRequest = fetchRequest;
|
|
8
|
+
var _typeChecks = require("@stryke/type-checks");
|
|
9
|
+
var _defu = require("defu");
|
|
8
10
|
var _nodeBuffer = require("node:buffer");
|
|
9
11
|
var _nodeHttp = _interopRequireDefault(require("node:http"));
|
|
10
12
|
var _nodeHttps = _interopRequireDefault(require("node:https"));
|
|
11
13
|
var _proxyAgent = require("./proxy-agent.cjs");
|
|
12
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
async function
|
|
14
|
-
return new Promise((
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
e = u.request(o, {
|
|
15
|
+
async function fetchRequest(e, n = {}) {
|
|
16
|
+
return new Promise((m, i) => {
|
|
17
|
+
let r = "http:";
|
|
18
|
+
(0, _typeChecks.isString)(e) ? r = new URL(e).protocol : r = e.protocol;
|
|
19
|
+
const c = r === "https:" ? _nodeHttps.default : _nodeHttp.default,
|
|
20
|
+
s = n.timeout ?? 3e3,
|
|
21
|
+
o = c.request(e, (0, _defu.defu)(n, {
|
|
21
22
|
agent: (0, _proxyAgent.getProxyAgent)(),
|
|
22
23
|
headers: {
|
|
23
24
|
"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"
|
|
24
25
|
}
|
|
25
|
-
}, t => {
|
|
26
|
+
}), t => {
|
|
26
27
|
if (t.statusCode !== 200) {
|
|
27
|
-
|
|
28
|
+
i(new Error(`Request failed: ${e.toString()} (status: ${t.statusCode})`));
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
30
|
-
const
|
|
31
|
-
t.on("data",
|
|
31
|
+
const p = [];
|
|
32
|
+
t.on("data", u => p.push(_nodeBuffer.Buffer.from(u))), t.on("end", () => m(_nodeBuffer.Buffer.concat(p)));
|
|
32
33
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}),
|
|
34
|
+
s && o.setTimeout(s, () => {
|
|
35
|
+
o.destroy(new Error(`Request timed out after ${s}ms`));
|
|
36
|
+
}), o.on("error", t => i(t)), o.end();
|
|
36
37
|
});
|
|
37
38
|
}
|
|
38
|
-
const fetch = exports.fetch =
|
|
39
|
+
const fetch = exports.fetch = fetchRequest;
|
package/dist/fetch.d.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { Buffer } from "node:buffer";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import type { RequestOptions } from "node:https";
|
|
3
|
+
export interface FetchRequestOptions extends RequestOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Timeout in milliseconds
|
|
6
|
+
*
|
|
7
|
+
* @defaultValue 3000
|
|
8
|
+
*/
|
|
9
|
+
timeout?: number;
|
|
4
10
|
}
|
|
5
11
|
/**
|
|
6
12
|
* Fetches a resource from a URL.
|
|
7
13
|
*
|
|
8
14
|
* @remarks
|
|
9
|
-
* Makes a simple GET request and returns the entire response as a Buffer.
|
|
10
|
-
*
|
|
11
|
-
* Features:
|
|
12
|
-
* - Throws if the response status is not 200.
|
|
13
|
-
* - Applies a 3000 ms timeout when `isDev` is `true`.
|
|
15
|
+
* Makes a simple GET request and returns the entire response as a Buffer. Throws if the response status is not 200.
|
|
14
16
|
*
|
|
15
17
|
* @param url - The URL to fetch.
|
|
16
18
|
* @returns A promise that resolves to the response body as a Buffer.
|
|
17
19
|
*/
|
|
18
|
-
export declare function
|
|
19
|
-
export declare const fetch: typeof
|
|
20
|
+
export declare function fetchRequest(url: string | URL, options?: FetchRequestOptions): Promise<Buffer>;
|
|
21
|
+
export declare const fetch: typeof fetchRequest;
|
package/dist/fetch.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Buffer as
|
|
1
|
+
import{isString as a}from"@stryke/type-checks";import{defu as d}from"defu";import{Buffer as f}from"node:buffer";import h from"node:http";import l from"node:https";import{getProxyAgent as q}from"./proxy-agent";export async function fetchRequest(e,n={}){return new Promise((m,i)=>{let r="http:";a(e)?r=new URL(e).protocol:r=e.protocol;const c=r==="https:"?l:h,s=n.timeout??3e3,o=c.request(e,d(n,{agent:q(),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"}}),t=>{if(t.statusCode!==200){i(new Error(`Request failed: ${e.toString()} (status: ${t.statusCode})`));return}const p=[];t.on("data",u=>p.push(f.from(u))),t.on("end",()=>m(f.concat(p)))});s&&o.setTimeout(s,()=>{o.destroy(new Error(`Request timed out after ${s}ms`))}),o.on("error",t=>i(t)),o.end()})}export const fetch=fetchRequest;
|
|
@@ -40,9 +40,7 @@ export interface BufferConversionsInterface {
|
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* @param convert - Conversion functions
|
|
43
|
-
* @
|
|
43
|
+
* @returns An object containing the parsed data URI properties and the decoded data as a Buffer instance.
|
|
44
44
|
* @throws `TypeError` if `uri` is not a valid Data URI
|
|
45
|
-
* @returns An object containing the parsed data URI properties
|
|
46
|
-
* and the decoded data as a Buffer instance.
|
|
47
45
|
*/
|
|
48
46
|
export declare const makeDataUriToBuffer: (convert: BufferConversionsInterface) => (uri: string | URL) => ParsedDataURI;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFreePort = void 0;
|
|
7
|
+
var _nodeHttp = require("node:http");
|
|
8
|
+
const getFreePort = async () => new Promise((s, o) => {
|
|
9
|
+
const r = (0, _nodeHttp.createServer)(() => {});
|
|
10
|
+
r.listen(0, () => {
|
|
11
|
+
const e = r.address();
|
|
12
|
+
r.close(), e && typeof e == "object" ? s(e.port) : o(new Error(`invalid address from server: ${e?.toString()}`));
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
exports.getFreePort = getFreePort;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds and returns a free port on the local machine by creating a temporary server that listens on port 0. The operating system assigns an available port, which is then retrieved and returned.
|
|
3
|
+
*
|
|
4
|
+
* @returns A promise that resolves to a free port number.
|
|
5
|
+
*/
|
|
6
|
+
export declare const getFreePort: () => Promise<number>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createServer as t}from"node:http";export const getFreePort=async()=>new Promise((s,o)=>{const r=t(()=>{});r.listen(0,()=>{const e=r.address();r.close(),e&&typeof e=="object"?s(e.port):o(new Error(`invalid address from server: ${e?.toString()}`))})});
|
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,17 @@ Object.keys(_formatDataUri).forEach(function (key) {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
+
var _getFreePort = require("./get-free-port.cjs");
|
|
40
|
+
Object.keys(_getFreePort).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _getFreePort[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _getFreePort[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
39
50
|
var _httpProxy = require("./http-proxy.cjs");
|
|
40
51
|
Object.keys(_httpProxy).forEach(function (key) {
|
|
41
52
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./agent";export*from"./fetch";export*from"./format-data-uri";export*from"./http-proxy";export*from"./https-proxy";export*from"./parse-response";export*from"./proxy-agent";
|
|
1
|
+
export*from"./agent";export*from"./fetch";export*from"./format-data-uri";export*from"./get-free-port";export*from"./http-proxy";export*from"./https-proxy";export*from"./parse-response";export*from"./proxy-agent";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/http",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing HTTP communication utilities used by Storm Software.",
|
|
6
6
|
"repository": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"directory": "packages/http"
|
|
10
10
|
},
|
|
11
11
|
"private": false,
|
|
12
|
+
"dependencies": { "defu": "^6.1.4", "@stryke/type-checks": "^0.3.10" },
|
|
12
13
|
"devDependencies": { "@types/node": "^22.14.0" },
|
|
13
14
|
"publishConfig": { "access": "public" },
|
|
14
|
-
"dependencies": { "@stryke/type-checks": "^0.3.9" },
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": ["dist/**/*"],
|
|
17
17
|
"homepage": "https://stormsoftware.com",
|
|
@@ -119,6 +119,20 @@
|
|
|
119
119
|
"default": "./dist/http-proxy.mjs"
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
|
+
"./get-free-port": {
|
|
123
|
+
"import": {
|
|
124
|
+
"types": "./dist/get-free-port.d.ts",
|
|
125
|
+
"default": "./dist/get-free-port.mjs"
|
|
126
|
+
},
|
|
127
|
+
"require": {
|
|
128
|
+
"types": "./dist/get-free-port.d.ts",
|
|
129
|
+
"default": "./dist/get-free-port.cjs"
|
|
130
|
+
},
|
|
131
|
+
"default": {
|
|
132
|
+
"types": "./dist/get-free-port.d.ts",
|
|
133
|
+
"default": "./dist/get-free-port.mjs"
|
|
134
|
+
}
|
|
135
|
+
},
|
|
122
136
|
"./format-data-uri": {
|
|
123
137
|
"import": {
|
|
124
138
|
"types": "./dist/format-data-uri.d.ts",
|
|
@@ -162,5 +176,5 @@
|
|
|
162
176
|
"main": "./dist/index.cjs",
|
|
163
177
|
"module": "./dist/index.mjs",
|
|
164
178
|
"types": "./dist/index.d.ts",
|
|
165
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "0a93c9e761d48145e575cc649ae518612e9defec"
|
|
166
180
|
}
|