@e-mc/request 0.8.7 → 0.8.9

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/LICENSE CHANGED
@@ -1,11 +1,7 @@
1
1
  Copyright 2024 An Pham
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
-
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
-
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/request
2
2
 
3
3
  * NodeJS 14
4
- * ES2020
4
+ * ES2019
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { IModule, ModuleConstructor } from "./index";
@@ -82,10 +82,10 @@ interface RequestConstructor extends ModuleConstructor {
82
82
 
83
83
  ## References
84
84
 
85
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/http.d.ts
86
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/request.d.ts
87
- - https://www.unpkg.com/@e-mc/types@0.8.7/lib/settings.d.ts
85
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/http.d.ts
86
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/request.d.ts
87
+ - https://www.unpkg.com/@e-mc/types@0.8.9/lib/settings.d.ts
88
88
 
89
89
  ## LICENSE
90
90
 
91
- BSD 3-Clause
91
+ MIT
@@ -154,6 +154,7 @@ class HttpHost {
154
154
  return ++data[2];
155
155
  }
156
156
  upgrade(version, altSvc) {
157
+ var _e;
157
158
  if (altSvc && this.secure) {
158
159
  if (altSvc === 'clear') {
159
160
  this.clearAltSvc();
@@ -187,7 +188,7 @@ class HttpHost {
187
188
  break;
188
189
  }
189
190
  const address = match[1] || hostname;
190
- const ma = +(/ma=(\d+)/.exec(match[3])?.[1] || 86400);
191
+ const ma = +(((_e = /ma=(\d+)/.exec(match[3])) === null || _e === void 0 ? void 0 : _e[1]) || 86400);
191
192
  if (!excluded.includes(`h${i + 1}:${address}:${port}`)) {
192
193
  addresses.push([
193
194
  address,
package/index.js CHANGED
@@ -37,7 +37,7 @@ const kStatusOn = Symbol('statusOn');
37
37
  const kHeadersOn = Symbol('headersOn');
38
38
  const PLATFORM_WIN32 = process.platform === 'win32';
39
39
  const SUPPORT_NODEJS20 = module_1.default.supported(20);
40
- const SUPPORT_ABORTSIGNAL = module_1.default.supported(15, 3) || module_1.default.supported(14, 17, 0, true);
40
+ const SUPPORT_ABORTSIGNAL = module_1.default.supported(15, 4);
41
41
  const HTTP = {
42
42
  HOST: {},
43
43
  HEADERS: {},
@@ -106,7 +106,7 @@ function getBaseHeaders(uri, headers) {
106
106
  }
107
107
  }
108
108
  function setDnsCache(hostname, value, expires) {
109
- expires ?? (expires = DNS.EXPIRES);
109
+ expires !== null && expires !== void 0 ? expires : (expires = DNS.EXPIRES);
110
110
  if (expires > 0 && !DNS.CACHE[hostname]) {
111
111
  DNS.CACHE[hostname] = value;
112
112
  if (expires !== Infinity) {
@@ -137,7 +137,7 @@ function setOutgoingHeaders(output, headers) {
137
137
  }
138
138
  function getProxySettings(request, agentTimeout) {
139
139
  const proxy = request.proxy;
140
- if (proxy?.address && proxy.port) {
140
+ if ((proxy === null || proxy === void 0 ? void 0 : proxy.address) && proxy.port) {
141
141
  const port = (0, util_1.asInt)(proxy.port);
142
142
  const address = (!module_1.default.isURL(proxy.address) ? port === 80 ? 'http://' : 'https://' : '') + proxy.address;
143
143
  try {
@@ -285,6 +285,7 @@ class Request extends module_1.default {
285
285
  return parent ? super.purgeMemory(percent, limit) : 0;
286
286
  }
287
287
  static loadSettings(settings, password) {
288
+ var _o;
288
289
  if (this.enabled("process.password") && !super.loadSettings({ process: settings.process }, password)) {
289
290
  return false;
290
291
  }
@@ -403,7 +404,7 @@ class Request extends module_1.default {
403
404
  [TLS.TEXT, TLS.FILE] = validateCerts(certs);
404
405
  }
405
406
  HTTP.PROXY = getProxySettings(request, agent_timeout);
406
- const time_format = request.settings?.time_format;
407
+ const time_format = (_o = request.settings) === null || _o === void 0 ? void 0 : _o.time_format;
407
408
  switch (time_format) {
408
409
  case 'readable':
409
410
  case 'relative':
@@ -628,6 +629,7 @@ class Request extends module_1.default {
628
629
  return ARIA2.BIN;
629
630
  }
630
631
  constructor(data) {
632
+ var _o;
631
633
  super();
632
634
  this.startTime = Date.now();
633
635
  this.readExpect = 'none';
@@ -659,13 +661,13 @@ class Request extends module_1.default {
659
661
  const timeout = (0, util_1.fromSeconds)(data.timeout);
660
662
  let value;
661
663
  this.readTimeout = (value = (0, util_1.fromSeconds)(read_timeout)) >= 0 ? value : READ_TIMEOUT;
662
- this.keepAlive = typeof (value = agent?.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
663
- this.acceptEncoding = typeof (value = use?.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
664
- if ((value = (0, util_1.asInt)(use?.http_version)) === 1 || value === 2) {
664
+ this.keepAlive = typeof (value = agent === null || agent === void 0 ? void 0 : agent.keep_alive) === 'boolean' ? value : KEEP_ALIVE;
665
+ this.acceptEncoding = typeof (value = use === null || use === void 0 ? void 0 : use.accept_encoding) === 'boolean' ? value : ACCEPT_ENCODING;
666
+ if ((value = (0, util_1.asInt)(use === null || use === void 0 ? void 0 : use.http_version)) === 1 || value === 2) {
665
667
  this[kHttpVersion] = value;
666
668
  }
667
- this[kIpVersion] = (value = (0, util_1.asInt)(data.dns?.family)) && (value === 4 || value === 6) ? value : 0;
668
- if ((value = (0, util_1.fromSeconds)(agent?.timeout)) >= 0) {
669
+ this[kIpVersion] = (value = (0, util_1.asInt)((_o = data.dns) === null || _o === void 0 ? void 0 : _o.family)) && (value === 4 || value === 6) ? value : 0;
670
+ if ((value = (0, util_1.fromSeconds)(agent === null || agent === void 0 ? void 0 : agent.timeout)) >= 0) {
669
671
  this[kAgentTimeout] = value;
670
672
  }
671
673
  else {
@@ -707,12 +709,13 @@ class Request extends module_1.default {
707
709
  this.module = data;
708
710
  }
709
711
  flushLog() {
712
+ var _o;
710
713
  const log = this._logQueued;
711
714
  if (this[kSingleton]) {
712
715
  log.length = 0;
713
716
  }
714
717
  else {
715
- if (log.length && !this.host?.aborted) {
718
+ if (log.length && !((_o = this.host) === null || _o === void 0 ? void 0 : _o.aborted)) {
716
719
  const output = [];
717
720
  let count = 0;
718
721
  this[kConnectHttp].forEach((protocol, index) => {
@@ -1071,8 +1074,9 @@ class Request extends module_1.default {
1071
1074
  if (!module_1.default.createDir(pathname)) {
1072
1075
  return Promise.reject((0, types_1.errorMessage)("aria2", "Path is not a directory", pathname));
1073
1076
  }
1074
- silent ?? (silent = this[kSingleton]);
1077
+ silent !== null && silent !== void 0 ? silent : (silent = this[kSingleton]);
1075
1078
  return new Promise((resolve, reject) => {
1079
+ var _o;
1076
1080
  let protocol, origin, username, password;
1077
1081
  if (uri instanceof URL) {
1078
1082
  ({ protocol, origin, username, password, href: uri } = uri);
@@ -1130,7 +1134,7 @@ class Request extends module_1.default {
1130
1134
  '--file-allocation=' + ARIA2.FILE_ALLOCATION,
1131
1135
  '--max-tries=' + (retryLimit + 1)
1132
1136
  ];
1133
- const ignoreOpt = (...values) => !binOpts?.some(item => values.includes(item));
1137
+ const ignoreOpt = (...values) => !(binOpts === null || binOpts === void 0 ? void 0 : binOpts.some(item => values.includes(item)));
1134
1138
  if (ARIA2.MAX_CONCURRENT_DOWNLOADS) {
1135
1139
  opts.push('--max-concurrent-downloads=' + ARIA2.MAX_CONCURRENT_DOWNLOADS);
1136
1140
  }
@@ -1179,7 +1183,7 @@ class Request extends module_1.default {
1179
1183
  }
1180
1184
  }
1181
1185
  if (origin) {
1182
- const secure = this[kCerts]?.[1][origin] || (this.host ? TLS.FILE[origin] : null);
1186
+ const secure = ((_o = this[kCerts]) === null || _o === void 0 ? void 0 : _o[1][origin]) || (this.host ? TLS.FILE[origin] : null);
1183
1187
  if (secure) {
1184
1188
  if (secure.ca && ignoreOpt('--ca-certificate')) {
1185
1189
  args.push(`--ca-certificate="${escapeQuote(secure.ca)}"`);
@@ -1329,7 +1333,7 @@ class Request extends module_1.default {
1329
1333
  }
1330
1334
  else {
1331
1335
  const current = (0, types_1.getLogCurrent)();
1332
- progressBar = current?.type === 128 && current.title === "aria2";
1336
+ progressBar = (current === null || current === void 0 ? void 0 : current.type) === 128 && current.title === "aria2";
1333
1337
  }
1334
1338
  this.formatMessage(128, "aria2", ['Downloading...', (0, types_1.formatTime)(startTime, true)], (PLATFORM_WIN32 ? 'taskkill /f /pid' : 'kill') + ` ${item[0]} -> ` + item[1], { ...module_1.default.LOG_STYLE_INFO, progressBar, broadcastId });
1335
1339
  }
@@ -1368,7 +1372,8 @@ class Request extends module_1.default {
1368
1372
  return { ...options, host, url };
1369
1373
  }
1370
1374
  open(uri, options) {
1371
- var _o, _p;
1375
+ var _o;
1376
+ var _p, _q;
1372
1377
  let { host, url, httpVersion, method = 'GET', encoding, format, headers, postData, keepAlive, agentTimeout, socketPath, timeout = this._config.connectTimeout, outStream } = options;
1373
1378
  const getting = method === 'GET';
1374
1379
  const posting = method === 'POST';
@@ -1423,7 +1428,7 @@ class Request extends module_1.default {
1423
1428
  case 204:
1424
1429
  return;
1425
1430
  }
1426
- const chunkSize = outStream?.writableHighWaterMark;
1431
+ const chunkSize = outStream === null || outStream === void 0 ? void 0 : outStream.writableHighWaterMark;
1427
1432
  let pipeTo;
1428
1433
  switch (contentEncoding.trim().toLowerCase()) {
1429
1434
  case 'gzip':
@@ -1459,17 +1464,17 @@ class Request extends module_1.default {
1459
1464
  const proxy = this.proxyOf(uri, localhost);
1460
1465
  const version = this.httpVersion;
1461
1466
  let request, ca, cert, key, minVersion, baseHeaders = this.headersOf(uri);
1462
- if (getting && this.acceptEncoding && !localhost && !baseHeaders?.['accept-encoding']) {
1463
- (_o = (headers || (headers = {})))['accept-encoding'] || (_o['accept-encoding'] = 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : ''));
1467
+ if (getting && this.acceptEncoding && !localhost && !(baseHeaders === null || baseHeaders === void 0 ? void 0 : baseHeaders['accept-encoding'])) {
1468
+ (_p = (headers || (headers = {})))['accept-encoding'] || (_p['accept-encoding'] = 'gzip, deflate, br' + (LIB_ZSTD ? ', zstd' : ''));
1464
1469
  }
1465
1470
  if (secure) {
1466
- const certs = this[kCerts]?.[0][origin] || (this.host ? TLS.TEXT[origin] : null);
1471
+ const certs = ((_o = this[kCerts]) === null || _o === void 0 ? void 0 : _o[0][origin]) || (this.host ? TLS.TEXT[origin] : null);
1467
1472
  if (certs) {
1468
1473
  ({ ca, cert, key, version: minVersion } = certs);
1469
1474
  }
1470
1475
  }
1471
1476
  if (!proxy && httpVersion !== 1 && ((httpVersion || host.version) === 2 && version !== 1 || secure && version === 2 && host.failed(2, true) === 0)) {
1472
- request = ((_p = this[kSession][0])[origin] || (_p[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { maxFrameSize: 16777215, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
1477
+ request = ((_q = this[kSession][0])[origin] || (_q[origin] = http2.connect(origin, { lookup: this.lookupDns(hostname), ca, cert, key, minVersion, settings: localhost ? { maxFrameSize: 16777215, enablePush: false } : { enablePush: false } }))).request({ ...baseHeaders, ...host_1.default.getBasicAuth(url), ...headers, ':path': pathname, ':method': method });
1473
1478
  if (getting) {
1474
1479
  const listenerMap = {};
1475
1480
  const onEvent = request.on.bind(request);
@@ -1553,8 +1558,8 @@ class Request extends module_1.default {
1553
1558
  const pkg = secure ? 'https-proxy-agent' : 'http-proxy-agent';
1554
1559
  try {
1555
1560
  const { protocol, hostname: proxyname, port, username, password, href } = proxy.host;
1556
- keepAlive ?? (keepAlive = proxy.keepAlive || false);
1557
- agentTimeout ?? (agentTimeout = proxy.agentTimeout);
1561
+ keepAlive !== null && keepAlive !== void 0 ? keepAlive : (keepAlive = proxy.keepAlive || false);
1562
+ agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = proxy.agentTimeout);
1558
1563
  agent = require(pkg)(keepAlive || agentTimeout > 0 ? { protocol, hostname: proxyname, port, username, password, keepAlive, timeout: agentTimeout } : href);
1559
1564
  const proxyHeaders = this[kHeaders] && getBaseHeaders(href, this[kHeaders]) || getBaseHeaders(href, HTTP.HEADERS);
1560
1565
  if (proxyHeaders) {
@@ -1573,7 +1578,7 @@ class Request extends module_1.default {
1573
1578
  }
1574
1579
  else if (agentTimeout !== 0) {
1575
1580
  keepAlive = this.keepAlive || false;
1576
- agentTimeout ?? (agentTimeout = this.agentTimeout);
1581
+ agentTimeout !== null && agentTimeout !== void 0 ? agentTimeout : (agentTimeout = this.agentTimeout);
1577
1582
  if (keepAlive || agentTimeout > 0) {
1578
1583
  agent = new (secure ? https.Agent : http.Agent)({ keepAlive, timeout: agentTimeout });
1579
1584
  }
@@ -1597,6 +1602,7 @@ class Request extends module_1.default {
1597
1602
  lookup: this.lookupDns(hostname),
1598
1603
  agent
1599
1604
  }, response => {
1605
+ var _o;
1600
1606
  const statusCode = response.statusCode;
1601
1607
  const incoming = response.headers;
1602
1608
  if (this.matchStatus(statusCode, url, incoming, request, options) && (getting || posting) && statusCode >= 200 && statusCode < 300) {
@@ -1632,7 +1638,7 @@ class Request extends module_1.default {
1632
1638
  source.on('error', err => request.emit('error', err));
1633
1639
  }
1634
1640
  if (!posting) {
1635
- if (version === 2 && incoming.upgrade?.includes('h2')) {
1641
+ if (version === 2 && ((_o = incoming.upgrade) === null || _o === void 0 ? void 0 : _o.includes('h2'))) {
1636
1642
  host.version = 2;
1637
1643
  }
1638
1644
  else if (!host.didAltSvc(1)) {
@@ -1906,19 +1912,21 @@ class Request extends module_1.default {
1906
1912
  downloadUri.call(this, href);
1907
1913
  };
1908
1914
  const acceptResponse = (headers) => {
1915
+ var _o;
1909
1916
  if ('outHeaders' in opts) {
1910
1917
  opts.outHeaders = headers;
1911
1918
  }
1912
1919
  if ('outFilename' in opts) {
1913
1920
  opts.outFilename = (0, util_1.parseHeader)(headers, 'content-disposition');
1914
1921
  }
1915
- const buffering = request.connected?.call(client, headers);
1922
+ const buffering = (_o = request.connected) === null || _o === void 0 ? void 0 : _o.call(client, headers);
1916
1923
  const pipeline = pipeTo ? !(0, types_1.isString)(pipeTo) : false;
1917
1924
  const enabled = buffering !== false && !pipeline;
1918
1925
  const readTimeout = this.readTimeout;
1919
1926
  let mibsTime, delayTime;
1920
1927
  if (log || readTimeout > 0) {
1921
1928
  client.once('readable', () => {
1929
+ var _o;
1922
1930
  if (readTimeout > 0) {
1923
1931
  timeout = setTimeout(() => {
1924
1932
  abortResponse();
@@ -1926,7 +1934,7 @@ class Request extends module_1.default {
1926
1934
  }, readTimeout);
1927
1935
  }
1928
1936
  if (log) {
1929
- switch (this.settings?.time_format || LOG_TIMEFORMAT) {
1937
+ switch (((_o = this.settings) === null || _o === void 0 ? void 0 : _o.time_format) || LOG_TIMEFORMAT) {
1930
1938
  case 'readable':
1931
1939
  delayTime = process.hrtime(startTime);
1932
1940
  break;
@@ -2256,7 +2264,8 @@ class Request extends module_1.default {
2256
2264
  this[kDownloading].clear();
2257
2265
  }
2258
2266
  matchStatus(code, url, headers, request, options) {
2259
- const status = this[kStatusOn]?.get(code);
2267
+ var _o;
2268
+ const status = (_o = this[kStatusOn]) === null || _o === void 0 ? void 0 : _o.get(code);
2260
2269
  if (status) {
2261
2270
  const href = url.href;
2262
2271
  const called = new Set();
@@ -2281,7 +2290,7 @@ class Request extends module_1.default {
2281
2290
  }
2282
2291
  matchHeaders(url, headers, request, options) {
2283
2292
  const on = this[kHeadersOn];
2284
- if (on?.size) {
2293
+ if (on === null || on === void 0 ? void 0 : on.size) {
2285
2294
  const href = url.href;
2286
2295
  const called = new Map();
2287
2296
  for (const [name, item] of on) {
@@ -2312,13 +2321,14 @@ class Request extends module_1.default {
2312
2321
  return true;
2313
2322
  }
2314
2323
  set agentTimeout(value) {
2324
+ var _o, _p;
2315
2325
  if (value > 0) {
2316
2326
  this[kAgentTimeout] = value;
2317
- this.keepAlive ?? (this.keepAlive = true);
2327
+ (_o = this.keepAlive) !== null && _o !== void 0 ? _o : (this.keepAlive = true);
2318
2328
  }
2319
2329
  else {
2320
2330
  this[kAgentTimeout] = 0;
2321
- this.keepAlive ?? (this.keepAlive = false);
2331
+ (_p = this.keepAlive) !== null && _p !== void 0 ? _p : (this.keepAlive = false);
2322
2332
  }
2323
2333
  }
2324
2334
  get agentTimeout() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/request",
3
- "version": "0.8.7",
3
+ "version": "0.8.9",
4
4
  "description": "Request constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,11 +17,11 @@
17
17
  "squared-functions"
18
18
  ],
19
19
  "author": "An Pham <anpham6@gmail.com>",
20
- "license": "BSD 3-Clause",
20
+ "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/module": "0.8.7",
24
- "@e-mc/types": "0.8.7",
23
+ "@e-mc/module": "0.8.9",
24
+ "@e-mc/types": "0.8.9",
25
25
  "combined-stream": "^1.0.8",
26
26
  "js-yaml": "^4.1.0",
27
27
  "picomatch": "^3.0.1",