@stryke/http 0.10.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/package.json +3 -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;
|
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.10" },
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": ["dist/**/*"],
|
|
17
17
|
"homepage": "https://stormsoftware.com",
|
|
@@ -176,5 +176,5 @@
|
|
|
176
176
|
"main": "./dist/index.cjs",
|
|
177
177
|
"module": "./dist/index.mjs",
|
|
178
178
|
"types": "./dist/index.d.ts",
|
|
179
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "0a93c9e761d48145e575cc649ae518612e9defec"
|
|
180
180
|
}
|