@e-mc/request 0.13.7 → 0.13.8
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/README.md +8 -8
- package/index.js +60 -50
- package/package.json +3 -3
- package/util.d.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @e-mc/request
|
|
2
2
|
|
|
3
|
-
* NodeJS 18.20
|
|
3
|
+
* NodeJS 18.20 LTS
|
|
4
4
|
* ES2022
|
|
5
5
|
|
|
6
6
|
## General Usage
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.13.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.13.8/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { IModule, ModuleConstructor } from "./index";
|
|
16
16
|
import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
|
|
17
|
-
import type { ApplyOptions, Aria2Options,
|
|
17
|
+
import type { ApplyOptions, Aria2Options, HeadersOnCallback, HostConfig, IHttpAdapter, OpenOptions, PostFileParts, PostOptions, ProxySettings, PutOptions, RcloneOptions, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
|
|
18
18
|
import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
|
|
19
19
|
|
|
20
20
|
import type { ClientRequest, OutgoingHttpHeaders } from "node:http";
|
|
@@ -51,8 +51,8 @@ interface IRequest extends IModule {
|
|
|
51
51
|
head(uri: string | URL, options?: OpenOptions): ClientRequest;
|
|
52
52
|
put(uri: string | URL, data: unknown, options: PutOptions): Promise<Buffer | string | null>;
|
|
53
53
|
put(uri: string | URL, data: unknown, contentType?: string, options?: PutOptions): Promise<Buffer | string | null>;
|
|
54
|
-
post(uri: string | URL, parts:
|
|
55
|
-
post(uri: string | URL, form: Record<string, unknown>, parts:
|
|
54
|
+
post(uri: string | URL, parts: PostFileParts): Promise<Buffer | string | null>;
|
|
55
|
+
post(uri: string | URL, form: Record<string, unknown>, parts: PostFileParts): Promise<Buffer | string | null>;
|
|
56
56
|
post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
|
|
57
57
|
post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
|
|
58
58
|
get(uri: string | URL, format: "json" | "yaml" | "json5" | "xml" | "toml"): Promise<object | null>;
|
|
@@ -252,9 +252,9 @@ instance.get("http://hostname/path/config.yml", options).then(data => {
|
|
|
252
252
|
|
|
253
253
|
## References
|
|
254
254
|
|
|
255
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
256
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
257
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
255
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/http.d.ts
|
|
256
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/request.d.ts
|
|
257
|
+
- https://www.unpkg.com/@e-mc/types@0.13.8/lib/settings.d.ts
|
|
258
258
|
|
|
259
259
|
* https://www.npmjs.com/package/@types/node
|
|
260
260
|
|
package/index.js
CHANGED
|
@@ -414,8 +414,7 @@ function createAgentOptions(options) {
|
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
416
|
const hasResponse = (value) => value >= 200 && (value < 300 || value === 304);
|
|
417
|
-
const isDirEnd = (value) => value.
|
|
418
|
-
const trimCharEnd = (value) => value.substring(0, value.length - 1);
|
|
417
|
+
const isDirEnd = (value) => (value = value.at(-1), value === '/' || value === path.sep);
|
|
419
418
|
const configureDns = (family, options) => family === 0 ? options : { family, hints: family === 6 ? dns.V4MAPPED : 0 };
|
|
420
419
|
const ignoreOpt = (opts, ...values) => !opts?.some(opt => values.some(value => opt === value || opt.startsWith(value + '=')));
|
|
421
420
|
const escapeQuote = (value) => value.replace(/[\\"]/g, capture => '\\' + capture);
|
|
@@ -488,7 +487,7 @@ class Request extends module_1 {
|
|
|
488
487
|
try {
|
|
489
488
|
for (const uri in proxy) {
|
|
490
489
|
const host = new URL(uri);
|
|
491
|
-
ARIA2.PROXY[
|
|
490
|
+
ARIA2.PROXY[host.protocol.slice(0, -1)] = { host };
|
|
492
491
|
}
|
|
493
492
|
}
|
|
494
493
|
catch {
|
|
@@ -591,7 +590,7 @@ class Request extends module_1 {
|
|
|
591
590
|
if ((read_timeout = (0, util_1.fromSeconds)(read_timeout)) >= 0) {
|
|
592
591
|
READ_TIMEOUT = read_timeout;
|
|
593
592
|
}
|
|
594
|
-
if (
|
|
593
|
+
if (agent) {
|
|
595
594
|
let { keep_alive, timeout, proxy_env } = agent;
|
|
596
595
|
if ((agent_timeout = (0, util_1.fromSeconds)(timeout)) > 0) {
|
|
597
596
|
AGENT_TIMEOUT = agent_timeout;
|
|
@@ -620,8 +619,8 @@ class Request extends module_1 {
|
|
|
620
619
|
break;
|
|
621
620
|
}
|
|
622
621
|
}
|
|
623
|
-
|
|
624
|
-
|
|
622
|
+
for (const href in headers) {
|
|
623
|
+
if ((0, types_1.isObject)(headers[href])) {
|
|
625
624
|
HTTP.HEADERS[href] = (0, util_1.normalizeHeaders)(headers[href]);
|
|
626
625
|
}
|
|
627
626
|
}
|
|
@@ -1121,15 +1120,10 @@ class Request extends module_1 {
|
|
|
1121
1120
|
({ signal, silent } = options);
|
|
1122
1121
|
({ pathname, headers, binOpts } = this.parseBinOpts(options, ['--daemon'], ['--input-file']));
|
|
1123
1122
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
uri = new URL(uri);
|
|
1127
|
-
}
|
|
1128
|
-
pathname = checkBinTarget(this, "aria2", uri, pathname, 'aria2', binOpts);
|
|
1129
|
-
}
|
|
1130
|
-
catch (err) {
|
|
1131
|
-
return Promise.reject(err);
|
|
1123
|
+
if ((0, types_1.isString)(uri) && module_1.isURL(uri)) {
|
|
1124
|
+
uri = new URL(uri);
|
|
1132
1125
|
}
|
|
1126
|
+
pathname = checkBinTarget(this, "aria2", uri, pathname, 'aria2', binOpts);
|
|
1133
1127
|
silent ??= this.#singleton;
|
|
1134
1128
|
return new Promise((resolve, reject) => {
|
|
1135
1129
|
let protocol, origin, username, password;
|
|
@@ -1224,7 +1218,7 @@ class Request extends module_1 {
|
|
|
1224
1218
|
}
|
|
1225
1219
|
}
|
|
1226
1220
|
}
|
|
1227
|
-
switch (protocol =
|
|
1221
|
+
switch (protocol = protocol.slice(0, -1)) {
|
|
1228
1222
|
case 'http':
|
|
1229
1223
|
case 'https':
|
|
1230
1224
|
if (ignoreOpt(binOpts, '--http-no-cache')) {
|
|
@@ -1394,12 +1388,7 @@ class Request extends module_1 {
|
|
|
1394
1388
|
default:
|
|
1395
1389
|
return Promise.reject((0, types_1.errorMessage)("rclone", "Invalid command", command || uri));
|
|
1396
1390
|
}
|
|
1397
|
-
|
|
1398
|
-
pathname = checkBinTarget(this, "rclone", uri, pathname, command, binOpts);
|
|
1399
|
-
}
|
|
1400
|
-
catch (err) {
|
|
1401
|
-
return Promise.reject(err);
|
|
1402
|
-
}
|
|
1391
|
+
pathname = checkBinTarget(this, "rclone", uri, pathname, command, binOpts);
|
|
1403
1392
|
silent ??= this.#singleton;
|
|
1404
1393
|
return new Promise((resolve, reject) => {
|
|
1405
1394
|
const init = [
|
|
@@ -1770,13 +1759,18 @@ class Request extends module_1 {
|
|
|
1770
1759
|
if (this.matchStatus(statusCode, url, response, request, options) && hasResponse(statusCode)) {
|
|
1771
1760
|
const contentEncoding = response['content-encoding'];
|
|
1772
1761
|
if (checkEncoding(request, statusCode, contentEncoding) && (emitter = this.pipeline(request, contentEncoding, outStream))) {
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1762
|
+
if (typeof emitter === 'number') {
|
|
1763
|
+
this.abortHeaders(request, options, { href: url.href, statusCode: emitter, message: (0, util_1.fromStatusCode)(emitter) });
|
|
1764
|
+
}
|
|
1765
|
+
else {
|
|
1766
|
+
for (const event in listenerMap) {
|
|
1767
|
+
const [name, type] = event.split('-');
|
|
1768
|
+
for (const listener of listenerMap[event]) {
|
|
1769
|
+
if (name !== 'error') {
|
|
1770
|
+
request.removeListener(name, listener);
|
|
1771
|
+
}
|
|
1772
|
+
emitter[type](name === 'end' ? 'finish' : name, listener);
|
|
1778
1773
|
}
|
|
1779
|
-
emitter[type](name === 'end' ? 'finish' : name, listener);
|
|
1780
1774
|
}
|
|
1781
1775
|
}
|
|
1782
1776
|
}
|
|
@@ -1899,9 +1893,14 @@ class Request extends module_1 {
|
|
|
1899
1893
|
const contentEncoding = incoming['content-encoding'];
|
|
1900
1894
|
let source;
|
|
1901
1895
|
if (checkEncoding(request, statusCode, contentEncoding) && (source = this.pipeline(response, contentEncoding, outStream))) {
|
|
1902
|
-
source
|
|
1903
|
-
request.
|
|
1904
|
-
}
|
|
1896
|
+
if (typeof source === 'number') {
|
|
1897
|
+
this.abortHeaders(request, options, { href: url.href, statusCode: source, message: (0, util_1.fromStatusCode)(source) });
|
|
1898
|
+
}
|
|
1899
|
+
else {
|
|
1900
|
+
source.once('finish', () => {
|
|
1901
|
+
request.emit('end');
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1905
1904
|
}
|
|
1906
1905
|
else {
|
|
1907
1906
|
if (encoding) {
|
|
@@ -2093,9 +2092,18 @@ class Request extends module_1 {
|
|
|
2093
2092
|
addValue(name, data[name]);
|
|
2094
2093
|
}
|
|
2095
2094
|
}
|
|
2096
|
-
for (
|
|
2097
|
-
|
|
2098
|
-
|
|
2095
|
+
for (const part of parts) {
|
|
2096
|
+
let name, target, value, type, filename;
|
|
2097
|
+
if ((0, types_1.isPlainObject)(part)) {
|
|
2098
|
+
({ name, data: target, value, contentType: type, filename } = part);
|
|
2099
|
+
}
|
|
2100
|
+
else if ((0, types_1.supported)(18, 13) && part instanceof File) {
|
|
2101
|
+
name = part.name;
|
|
2102
|
+
type = part.type;
|
|
2103
|
+
target = Buffer.from(await part.arrayBuffer());
|
|
2104
|
+
}
|
|
2105
|
+
if (!(0, types_1.isString)(name)) {
|
|
2106
|
+
throw (0, types_1.errorValue)('Name of file part was invalid', uri.toString());
|
|
2099
2107
|
}
|
|
2100
2108
|
if (target) {
|
|
2101
2109
|
if (typeof target === 'string') {
|
|
@@ -2226,28 +2234,30 @@ class Request extends module_1 {
|
|
|
2226
2234
|
for (const value of encoding.split(/\s*,\s*/).reverse()) {
|
|
2227
2235
|
const next = this.fromEncoding(value, { chunkSize });
|
|
2228
2236
|
if (!next) {
|
|
2229
|
-
|
|
2237
|
+
pipeTo = undefined;
|
|
2238
|
+
break;
|
|
2230
2239
|
}
|
|
2231
2240
|
pipeTo = pipeTo ? pipeTo.pipe(next) : next;
|
|
2232
2241
|
}
|
|
2233
2242
|
}
|
|
2234
|
-
if (pipeTo) {
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2243
|
+
if (!pipeTo) {
|
|
2244
|
+
return 415;
|
|
2245
|
+
}
|
|
2246
|
+
if (outStream) {
|
|
2247
|
+
stream.pipeline(response, pipeTo, outStream, err => {
|
|
2248
|
+
if (err) {
|
|
2249
|
+
response.emit('error', err);
|
|
2250
|
+
}
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
else {
|
|
2254
|
+
stream.pipeline(response, pipeTo, err => {
|
|
2255
|
+
if (err) {
|
|
2256
|
+
response.emit('error', err);
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2250
2259
|
}
|
|
2260
|
+
return pipeTo;
|
|
2251
2261
|
}
|
|
2252
2262
|
fromEncoding(value, options) {
|
|
2253
2263
|
switch (value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/request",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.8",
|
|
4
4
|
"description": "Request constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"license": "BSD-3-Clause",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/module": "0.13.
|
|
23
|
-
"@e-mc/types": "0.13.
|
|
22
|
+
"@e-mc/module": "0.13.8",
|
|
23
|
+
"@e-mc/types": "0.13.8",
|
|
24
24
|
"combined-stream": "^1.0.8",
|
|
25
25
|
"js-yaml": "^4.1.1",
|
|
26
26
|
"picomatch": "^4.0.3",
|
package/util.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ declare namespace util {
|
|
|
13
13
|
function hasBasicAuth(value: string): boolean;
|
|
14
14
|
function checkRetryable(err: unknown): boolean;
|
|
15
15
|
function isRetryable(value: number, timeout?: boolean): boolean;
|
|
16
|
-
function parseHttpProxy(value?: string): HttpProxySettings | undefined;
|
|
16
|
+
function parseHttpProxy(value?: string, ignoreEnv?: boolean): HttpProxySettings | undefined;
|
|
17
17
|
function trimPath(value: string, char?: string): string;
|
|
18
18
|
function asInt(value: unknown): number;
|
|
19
19
|
function asFloat(value: unknown): number;
|