@e-mc/request 0.10.1 → 0.10.3

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,11 @@
1
- Copyright 2024 An Pham
2
-
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
-
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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
-
1
+ Copyright 2024 An Pham
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
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
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.
package/README.md CHANGED
@@ -1,215 +1,216 @@
1
- # @e-mc/request
2
-
3
- * NodeJS 16
4
- * ES2020
5
-
6
- ## General Usage
7
-
8
- * [Read the Docs](https://e-mc.readthedocs.io)
9
-
10
- ## Interface
11
-
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.10.1/lib/index.d.ts)
13
-
14
- ```typescript
15
- import type { IModule, ModuleConstructor } from "./index";
16
- import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
17
- import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
18
- import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
19
-
20
- import type { ClientRequest, OutgoingHttpHeaders } from "http";
21
- import type { LookupFunction } from "net";
22
- import type { Writable } from "stream";
23
-
24
- interface IRequest extends IModule {
25
- module: RequestModule;
26
- startTime: number;
27
- acceptEncoding: boolean;
28
- keepAlive: boolean | null;
29
- readTimeout: number;
30
- readExpect: ReadExpectType;
31
- proxy: ProxySettings | null;
32
- init(config?: RequestInit): this;
33
- apply(options: ApplyOptions): this;
34
- addDns(hostname: string, address: string, timeout: number): void;
35
- addDns(hostname: string, address: string, family?: string, timeout?: number): void;
36
- lookupDns(hostname: string): LookupFunction;
37
- proxyOf(uri: string, localhost?: boolean): ProxySettings | undefined;
38
- statusOn(name: number | number[], callback: StatusOnCallback): void;
39
- statusOn(name: number | number[], globUrl: string, callback: StatusOnCallback): void;
40
- headersOn(name: string | string[], callback: HeadersOnCallback): void;
41
- headersOn(name: string | string[], globUrl: string, callback: HeadersOnCallback): void;
42
- headersOf(uri: string): OutgoingHttpHeaders | undefined;
43
- aria2c(uri: string | URL, pathname: string): Promise<string[]>;
44
- aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
45
- json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
46
- pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
47
- opts(url: string | URL, options?: OpenOptions): HostConfig;
48
- open(uri: string | URL, options: OpenOptions): HttpRequestClient;
49
- head(uri: string | URL, options?: OpenOptions): ClientRequest;
50
- post(uri: string | URL, data: unknown, contentType: string): Promise<Buffer | string | null>;
51
- post(uri: string | URL, parts: FormDataPart[]): Promise<Buffer | string | null>;
52
- post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
53
- post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
54
- post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
55
- get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
56
- detach(singleton?: boolean): void;
57
- reset(): void;
58
- close(): void;
59
- set agentTimeout(value);
60
- get agentTimeout(): number;
61
- set httpVersion(value);
62
- get httpVersion(): HttpProtocolVersion | null;
63
- set ipVersion(value);
64
- get ipVersion(): InternetProtocolVersion;
65
- get settings(): RequestSettings;
66
- }
67
-
68
- interface RequestConstructor extends ModuleConstructor {
69
- readCACert(value: string, cache?: boolean): string;
70
- readTLSKey(value: string, cache?: boolean): string;
71
- readTLSCert(value: string, cache?: boolean): string;
72
- isCert(value: string): boolean;
73
- fromURL(url: URL, value: string): string;
74
- fromStatusCode(value: number | string): string;
75
- defineHttpAgent(options: HttpAgentSettings): void;
76
- defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
77
- getAria2Path(): string;
78
- readonly prototype: IRequest;
79
- new(module?: RequestModule): IRequest;
80
- }
81
- ```
82
-
83
- ## Settings
84
-
85
- ```typescript
86
- import type { PermittedDirectories } from "./core";
87
- import type { SecureConfig } from "./http";
88
- import type { PurgeComponent } from "./settings";
89
-
90
- import type { LookupAddress } from "dns";
91
- import type { OutgoingHttpHeaders } from "http";
92
-
93
- interface RequestModule {
94
- handler: "@e-mc/request";
95
- timeout?: number | string;
96
- read_timeout?: number | string;
97
- agent?: {
98
- keep_alive?: boolean;
99
- timeout?: number | string;
100
- };
101
- connect?: {
102
- timeout?: number | string;
103
- retry_wait?: number | string;
104
- retry_after?: number | string;
105
- retry_limit?: number;
106
- redirect_limit?: number;
107
- };
108
- dns?: {
109
- family?: number;
110
- expires?: number | string;
111
- resolve?: Record<string, Partial<LookupAddress>>;
112
- };
113
- use?: {
114
- http_version?: 1 | 2;
115
- accept_encoding?: boolean;
116
- };
117
- proxy?: {
118
- address?: string;
119
- port?: number;
120
- origin?: string;
121
- username?: string;
122
- password?: string;
123
- include?: string[];
124
- exclude?: string[];
125
- keep_alive?: boolean;
126
- };
127
- headers: Record<string, OutgoingHttpHeaders>;
128
- certs?: Record<string, SecureConfig<string | string[]>>;
129
- localhost?: string[];
130
- protocol?: {
131
- "http/1.1"?: string[];
132
- h2c?: string[];
133
- h2?: string[];
134
- };
135
- write_stream?: Record<string, number | string>;
136
- post_limit?: number | string;
137
- settings?: {
138
- broadcast_id?: string | string[];
139
- time_format?: "readable" | "relative" | "none";
140
- purge?: PurgeComponent;
141
- }
142
- }
143
-
144
- interface DownloadModule {
145
- expires?: number | string;
146
- aria2?: {
147
- bin?: string | false;
148
- exec?: {
149
- uid?: number;
150
- gid?: number;
151
- };
152
- update_status?: number | { interval?: number; broadcast_only?: boolean };
153
- max_concurrent_downloads?: number;
154
- max_connection_per_server?: number;
155
- check_integrity?: boolean;
156
- bt_stop_timeout?: number;
157
- bt_tracker_connect_timeout?: number;
158
- bt_tracker_timeout?: number;
159
- min_split_size?: string;
160
- disk_cache?: number | string;
161
- lowest_speed_limit?: number | string;
162
- always_resume?: boolean;
163
- file_allocation?: "none" | "prealloc" | "trunc" | "falloc";
164
- conf_path?: string;
165
- };
166
- }
167
- ```
168
-
169
- ### Example usage
170
-
171
- ```javascript
172
- const Request = require("@e-mc/request");
173
-
174
- const instance = new Request({
175
- read_timeout: 30,
176
- connect: {
177
- timeout: 20, // Seconds
178
- retry_wait: 1,
179
- retry_after: 30,
180
- retry_limit: 3, // Max attempts
181
- redirect_limit: 10
182
- },
183
- use: {
184
- http_version: 2,
185
- accept_encoding: true
186
- },
187
- dns: {
188
- family: 4 // ipVersion
189
- },
190
- agent: { keep_alive: true }
191
- });
192
- request.init({ ipVersion: 6 });
193
-
194
- const options = {
195
- format: "yaml",
196
- httpVersion: 1,
197
- silent: true,
198
- headers: { "x-goog-user-project": "project-1" }
199
- };
200
- instance.get("http://hostname/path/config.yml", options).then(data => {
201
- console.log(data.property);
202
- });
203
- ```
204
-
205
- ## References
206
-
207
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/http.d.ts
208
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/request.d.ts
209
- - https://www.unpkg.com/@e-mc/types@0.10.1/lib/settings.d.ts
210
-
211
- * https://www.npmjs.com/package/@types/node
212
-
213
- ## LICENSE
214
-
1
+ # @e-mc/request
2
+
3
+ * NodeJS 16
4
+ * ES2020
5
+
6
+ ## General Usage
7
+
8
+ * [Read the Docs](https://e-mc.readthedocs.io)
9
+
10
+ ## Interface
11
+
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.10.3/lib/index.d.ts)
13
+
14
+ ```typescript
15
+ import type { IModule, ModuleConstructor } from "./index";
16
+ import type { HttpAgentSettings, HttpProtocolVersion, HttpRequestClient, InternetProtocolVersion } from "./http";
17
+ import type { ApplyOptions, Aria2Options, FormDataPart, HeadersOnCallback, HostConfig, OpenOptions, PostOptions, ProxySettings, PutOptions, ReadExpectType, RequestInit, StatusOnCallback } from "./request";
18
+ import type { DnsLookupSettings, RequestModule, RequestSettings } from "./settings";
19
+
20
+ import type { ClientRequest, OutgoingHttpHeaders } from "http";
21
+ import type { LookupFunction } from "net";
22
+ import type { Writable } from "stream";
23
+
24
+ interface IRequest extends IModule {
25
+ module: RequestModule;
26
+ startTime: number;
27
+ acceptEncoding: boolean;
28
+ keepAlive: boolean | null;
29
+ readTimeout: number;
30
+ readExpect: ReadExpectType;
31
+ proxy: ProxySettings | null;
32
+ init(config?: RequestInit): this;
33
+ apply(options: ApplyOptions): this;
34
+ addDns(hostname: string, address: string, timeout: number): void;
35
+ addDns(hostname: string, address: string, family?: string, timeout?: number): void;
36
+ lookupDns(hostname: string): LookupFunction;
37
+ proxyOf(uri: string, localhost?: boolean): ProxySettings | undefined;
38
+ statusOn(name: number | number[], callback: StatusOnCallback): void;
39
+ statusOn(name: number | number[], globUrl: string, callback: StatusOnCallback): void;
40
+ headersOn(name: string | string[], callback: HeadersOnCallback): void;
41
+ headersOn(name: string | string[], globUrl: string, callback: HeadersOnCallback): void;
42
+ headersOf(uri: string): OutgoingHttpHeaders | undefined;
43
+ aria2c(uri: string | URL, pathname: string): Promise<string[]>;
44
+ aria2c(uri: string | URL, options?: Aria2Options): Promise<string[]>;
45
+ json(uri: string | URL, options?: OpenOptions): Promise<object | null>;
46
+ pipe(uri: string | URL, to: Writable, options?: OpenOptions): Promise<null>;
47
+ opts(url: string | URL, options?: OpenOptions): HostConfig;
48
+ open(uri: string | URL, options: OpenOptions): HttpRequestClient;
49
+ head(uri: string | URL, options?: OpenOptions): ClientRequest;
50
+ put(uri: string | URL, data: unknown, options: PutOptions): Promise<Buffer | string | null>;
51
+ put(uri: string | URL, data: unknown, contentType?: string, options?: PutOptions): Promise<Buffer | string | null>;
52
+ post(uri: string | URL, parts: FormDataPart[]): Promise<Buffer | string | null>;
53
+ post(uri: string | URL, form: Record<string, unknown>, parts: FormDataPart[]): Promise<Buffer | string | null>;
54
+ post(uri: string | URL, data: unknown, options: PostOptions): Promise<Buffer | string | null>;
55
+ post(uri: string | URL, data: unknown, contentType?: string, options?: PostOptions): Promise<Buffer | string | null>;
56
+ get(uri: string | URL, options?: OpenOptions): Promise<Buffer | object | string | null>;
57
+ detach(singleton?: boolean): void;
58
+ reset(): void;
59
+ close(): void;
60
+ set agentTimeout(value);
61
+ get agentTimeout(): number;
62
+ set httpVersion(value);
63
+ get httpVersion(): HttpProtocolVersion | null;
64
+ set ipVersion(value);
65
+ get ipVersion(): InternetProtocolVersion;
66
+ get settings(): RequestSettings;
67
+ }
68
+
69
+ interface RequestConstructor extends ModuleConstructor {
70
+ readCACert(value: string, cache?: boolean): string;
71
+ readTLSKey(value: string, cache?: boolean): string;
72
+ readTLSCert(value: string, cache?: boolean): string;
73
+ isCert(value: string): boolean;
74
+ fromURL(url: URL, value: string): string;
75
+ fromStatusCode(value: number | string): string;
76
+ defineHttpAgent(options: HttpAgentSettings): void;
77
+ defineDnsLookup(options: DnsLookupSettings, clear?: boolean): void;
78
+ getAria2Path(): string;
79
+ readonly prototype: IRequest;
80
+ new(module?: RequestModule): IRequest;
81
+ }
82
+ ```
83
+
84
+ ## Settings
85
+
86
+ ```typescript
87
+ import type { PermittedDirectories } from "./core";
88
+ import type { SecureConfig } from "./http";
89
+ import type { PurgeComponent } from "./settings";
90
+
91
+ import type { LookupAddress } from "dns";
92
+ import type { OutgoingHttpHeaders } from "http";
93
+
94
+ interface RequestModule {
95
+ handler: "@e-mc/request";
96
+ timeout?: number | string;
97
+ read_timeout?: number | string;
98
+ agent?: {
99
+ keep_alive?: boolean;
100
+ timeout?: number | string;
101
+ };
102
+ connect?: {
103
+ timeout?: number | string;
104
+ retry_wait?: number | string;
105
+ retry_after?: number | string;
106
+ retry_limit?: number;
107
+ redirect_limit?: number;
108
+ };
109
+ dns?: {
110
+ family?: number;
111
+ expires?: number | string;
112
+ resolve?: Record<string, Partial<LookupAddress>>;
113
+ };
114
+ use?: {
115
+ http_version?: 1 | 2;
116
+ accept_encoding?: boolean;
117
+ };
118
+ proxy?: {
119
+ address?: string;
120
+ port?: number;
121
+ origin?: string;
122
+ username?: string;
123
+ password?: string;
124
+ include?: string[];
125
+ exclude?: string[];
126
+ keep_alive?: boolean;
127
+ };
128
+ headers: Record<string, OutgoingHttpHeaders>;
129
+ certs?: Record<string, SecureConfig<string | string[]>>;
130
+ localhost?: string[];
131
+ protocol?: {
132
+ "http/1.1"?: string[];
133
+ h2c?: string[];
134
+ h2?: string[];
135
+ };
136
+ write_stream?: Record<string, number | string>;
137
+ post_limit?: number | string;
138
+ settings?: {
139
+ broadcast_id?: string | string[];
140
+ time_format?: "readable" | "relative" | "none";
141
+ purge?: PurgeComponent;
142
+ }
143
+ }
144
+
145
+ interface DownloadModule {
146
+ expires?: number | string;
147
+ aria2?: {
148
+ bin?: string | false;
149
+ exec?: {
150
+ uid?: number;
151
+ gid?: number;
152
+ };
153
+ update_status?: number | { interval?: number; broadcast_only?: boolean };
154
+ max_concurrent_downloads?: number;
155
+ max_connection_per_server?: number;
156
+ check_integrity?: boolean;
157
+ bt_stop_timeout?: number;
158
+ bt_tracker_connect_timeout?: number;
159
+ bt_tracker_timeout?: number;
160
+ min_split_size?: string;
161
+ disk_cache?: number | string;
162
+ lowest_speed_limit?: number | string;
163
+ always_resume?: boolean;
164
+ file_allocation?: "none" | "prealloc" | "trunc" | "falloc";
165
+ conf_path?: string;
166
+ };
167
+ }
168
+ ```
169
+
170
+ ### Example usage
171
+
172
+ ```javascript
173
+ const Request = require("@e-mc/request");
174
+
175
+ const instance = new Request({
176
+ read_timeout: 30,
177
+ connect: {
178
+ timeout: 20, // Seconds
179
+ retry_wait: 1,
180
+ retry_after: 30,
181
+ retry_limit: 3, // Max attempts
182
+ redirect_limit: 10
183
+ },
184
+ use: {
185
+ http_version: 2,
186
+ accept_encoding: true
187
+ },
188
+ dns: {
189
+ family: 4 // ipVersion
190
+ },
191
+ agent: { keep_alive: true }
192
+ });
193
+ request.init({ ipVersion: 6 });
194
+
195
+ const options = {
196
+ format: "yaml",
197
+ httpVersion: 1,
198
+ silent: true,
199
+ headers: { "x-goog-user-project": "project-1" }
200
+ };
201
+ instance.get("http://hostname/path/config.yml", options).then(data => {
202
+ console.log(data.property);
203
+ });
204
+ ```
205
+
206
+ ## References
207
+
208
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/http.d.ts
209
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/request.d.ts
210
+ - https://www.unpkg.com/@e-mc/types@0.10.3/lib/settings.d.ts
211
+
212
+ * https://www.npmjs.com/package/@types/node
213
+
214
+ ## LICENSE
215
+
215
216
  BSD 3-Clause
@@ -1,5 +1,5 @@
1
- import type { HttpHostConstructor } from '../../../types/lib/request';
2
-
3
- declare const HttpHost: HttpHostConstructor;
4
-
1
+ import type { HttpHostConstructor } from '@e-mc/types/lib/request';
2
+
3
+ declare const HttpHost: HttpHostConstructor;
4
+
5
5
  export = HttpHost;
@@ -120,7 +120,7 @@ class HttpHost {
120
120
  case 1:
121
121
  return status;
122
122
  default:
123
- return this._tlsConnect || (this._tlsConnect = new Promise(resolve => {
123
+ return this._tlsConnect ||= new Promise(resolve => {
124
124
  const alpn = 'h' + version;
125
125
  const socket = tls.connect(+this.port, this.hostname, { ALPNProtocols: [alpn], requestCert: true, rejectUnauthorized: false }, () => {
126
126
  this._tlsConnect = null;
@@ -147,7 +147,7 @@ class HttpHost {
147
147
  resolve(data[3] = 0);
148
148
  })
149
149
  .end();
150
- }));
150
+ });
151
151
  }
152
152
  }
153
153
  return 1;
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { RequestConstructor } from '../types/lib';
2
-
3
- declare const Request: RequestConstructor;
4
-
1
+ import type { RequestConstructor } from '@e-mc/types/lib';
2
+
3
+ declare const Request: RequestConstructor;
4
+
5
5
  export = Request;