@types/node 16.4.1 → 16.4.5

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.
node/https.d.ts CHANGED
@@ -1,40 +1,290 @@
1
+ /**
2
+ * HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a
3
+ * separate module.
4
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/https.js)
5
+ */
1
6
  declare module 'https' {
2
7
  import * as tls from 'node:tls';
3
8
  import * as http from 'node:http';
4
9
  import { URL } from 'node:url';
5
-
6
10
  type ServerOptions = tls.SecureContextOptions & tls.TlsOptions & http.ServerOptions;
7
-
8
- type RequestOptions = http.RequestOptions & tls.SecureContextOptions & {
9
- rejectUnauthorized?: boolean | undefined; // Defaults to true
10
- servername?: string | undefined; // SNI TLS Extension
11
- };
12
-
11
+ type RequestOptions = http.RequestOptions &
12
+ tls.SecureContextOptions & {
13
+ rejectUnauthorized?: boolean | undefined; // Defaults to true
14
+ servername?: string | undefined; // SNI TLS Extension
15
+ };
13
16
  interface AgentOptions extends http.AgentOptions, tls.ConnectionOptions {
14
17
  rejectUnauthorized?: boolean | undefined;
15
18
  maxCachedSessions?: number | undefined;
16
19
  }
17
-
20
+ /**
21
+ * An `Agent` object for HTTPS similar to `http.Agent`. See {@link request} for more information.
22
+ * @since v0.4.5
23
+ */
18
24
  class Agent extends http.Agent {
19
25
  constructor(options?: AgentOptions);
20
26
  options: AgentOptions;
21
27
  }
22
-
23
28
  interface Server extends http.HttpBase {}
29
+ /**
30
+ * * Extends: `<tls.Server>`
31
+ *
32
+ * See `http.Server` for more information.
33
+ * @since v0.3.4
34
+ */
24
35
  class Server extends tls.Server {
25
36
  constructor(requestListener?: http.RequestListener);
26
37
  constructor(options: ServerOptions, requestListener?: http.RequestListener);
27
38
  }
28
-
39
+ /**
40
+ * ```js
41
+ * // curl -k https://localhost:8000/
42
+ * const https = require('https');
43
+ * const fs = require('fs');
44
+ *
45
+ * const options = {
46
+ * key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
47
+ * cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
48
+ * };
49
+ *
50
+ * https.createServer(options, (req, res) => {
51
+ * res.writeHead(200);
52
+ * res.end('hello world\n');
53
+ * }).listen(8000);
54
+ * ```
55
+ *
56
+ * Or
57
+ *
58
+ * ```js
59
+ * const https = require('https');
60
+ * const fs = require('fs');
61
+ *
62
+ * const options = {
63
+ * pfx: fs.readFileSync('test/fixtures/test_cert.pfx'),
64
+ * passphrase: 'sample'
65
+ * };
66
+ *
67
+ * https.createServer(options, (req, res) => {
68
+ * res.writeHead(200);
69
+ * res.end('hello world\n');
70
+ * }).listen(8000);
71
+ * ```
72
+ * @since v0.3.4
73
+ * @param options Accepts `options` from `createServer`, `createSecureContext` and `createServer`.
74
+ * @param requestListener A listener to be added to the `'request'` event.
75
+ */
29
76
  function createServer(requestListener?: http.RequestListener): Server;
30
77
  function createServer(options: ServerOptions, requestListener?: http.RequestListener): Server;
78
+ /**
79
+ * Makes a request to a secure web server.
80
+ *
81
+ * The following additional `options` from `tls.connect()` are also accepted:`ca`, `cert`, `ciphers`, `clientCertEngine`, `crl`, `dhparam`, `ecdhCurve`,`honorCipherOrder`, `key`, `passphrase`,
82
+ * `pfx`, `rejectUnauthorized`,`secureOptions`, `secureProtocol`, `servername`, `sessionIdContext`,`highWaterMark`.
83
+ *
84
+ * `options` can be an object, a string, or a `URL` object. If `options` is a
85
+ * string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
86
+ *
87
+ * `https.request()` returns an instance of the `http.ClientRequest` class. The `ClientRequest` instance is a writable stream. If one needs to
88
+ * upload a file with a POST request, then write to the `ClientRequest` object.
89
+ *
90
+ * ```js
91
+ * const https = require('https');
92
+ *
93
+ * const options = {
94
+ * hostname: 'encrypted.google.com',
95
+ * port: 443,
96
+ * path: '/',
97
+ * method: 'GET'
98
+ * };
99
+ *
100
+ * const req = https.request(options, (res) => {
101
+ * console.log('statusCode:', res.statusCode);
102
+ * console.log('headers:', res.headers);
103
+ *
104
+ * res.on('data', (d) => {
105
+ * process.stdout.write(d);
106
+ * });
107
+ * });
108
+ *
109
+ * req.on('error', (e) => {
110
+ * console.error(e);
111
+ * });
112
+ * req.end();
113
+ * ```
114
+ *
115
+ * Example using options from `tls.connect()`:
116
+ *
117
+ * ```js
118
+ * const options = {
119
+ * hostname: 'encrypted.google.com',
120
+ * port: 443,
121
+ * path: '/',
122
+ * method: 'GET',
123
+ * key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
124
+ * cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
125
+ * };
126
+ * options.agent = new https.Agent(options);
127
+ *
128
+ * const req = https.request(options, (res) => {
129
+ * // ...
130
+ * });
131
+ * ```
132
+ *
133
+ * Alternatively, opt out of connection pooling by not using an `Agent`.
134
+ *
135
+ * ```js
136
+ * const options = {
137
+ * hostname: 'encrypted.google.com',
138
+ * port: 443,
139
+ * path: '/',
140
+ * method: 'GET',
141
+ * key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
142
+ * cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
143
+ * agent: false
144
+ * };
145
+ *
146
+ * const req = https.request(options, (res) => {
147
+ * // ...
148
+ * });
149
+ * ```
150
+ *
151
+ * Example using a `URL` as `options`:
152
+ *
153
+ * ```js
154
+ * const options = new URL('https://abc:xyz@example.com');
155
+ *
156
+ * const req = https.request(options, (res) => {
157
+ * // ...
158
+ * });
159
+ * ```
160
+ *
161
+ * Example pinning on certificate fingerprint, or the public key (similar to`pin-sha256`):
162
+ *
163
+ * ```js
164
+ * const tls = require('tls');
165
+ * const https = require('https');
166
+ * const crypto = require('crypto');
167
+ *
168
+ * function sha256(s) {
169
+ * return crypto.createHash('sha256').update(s).digest('base64');
170
+ * }
171
+ * const options = {
172
+ * hostname: 'github.com',
173
+ * port: 443,
174
+ * path: '/',
175
+ * method: 'GET',
176
+ * checkServerIdentity: function(host, cert) {
177
+ * // Make sure the certificate is issued to the host we are connected to
178
+ * const err = tls.checkServerIdentity(host, cert);
179
+ * if (err) {
180
+ * return err;
181
+ * }
182
+ *
183
+ * // Pin the public key, similar to HPKP pin-sha25 pinning
184
+ * const pubkey256 = 'pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU=';
185
+ * if (sha256(cert.pubkey) !== pubkey256) {
186
+ * const msg = 'Certificate verification error: ' +
187
+ * `The public key of '${cert.subject.CN}' ` +
188
+ * 'does not match our pinned fingerprint';
189
+ * return new Error(msg);
190
+ * }
191
+ *
192
+ * // Pin the exact certificate, rather than the pub key
193
+ * const cert256 = '25:FE:39:32:D9:63:8C:8A:FC:A1:9A:29:87:' +
194
+ * 'D8:3E:4C:1D:98:DB:71:E4:1A:48:03:98:EA:22:6A:BD:8B:93:16';
195
+ * if (cert.fingerprint256 !== cert256) {
196
+ * const msg = 'Certificate verification error: ' +
197
+ * `The certificate of '${cert.subject.CN}' ` +
198
+ * 'does not match our pinned fingerprint';
199
+ * return new Error(msg);
200
+ * }
201
+ *
202
+ * // This loop is informational only.
203
+ * // Print the certificate and public key fingerprints of all certs in the
204
+ * // chain. Its common to pin the public key of the issuer on the public
205
+ * // internet, while pinning the public key of the service in sensitive
206
+ * // environments.
207
+ * do {
208
+ * console.log('Subject Common Name:', cert.subject.CN);
209
+ * console.log(' Certificate SHA256 fingerprint:', cert.fingerprint256);
210
+ *
211
+ * hash = crypto.createHash('sha256');
212
+ * console.log(' Public key ping-sha256:', sha256(cert.pubkey));
213
+ *
214
+ * lastprint256 = cert.fingerprint256;
215
+ * cert = cert.issuerCertificate;
216
+ * } while (cert.fingerprint256 !== lastprint256);
217
+ *
218
+ * },
219
+ * };
220
+ *
221
+ * options.agent = new https.Agent(options);
222
+ * const req = https.request(options, (res) => {
223
+ * console.log('All OK. Server matched our pinned cert or public key');
224
+ * console.log('statusCode:', res.statusCode);
225
+ * // Print the HPKP values
226
+ * console.log('headers:', res.headers['public-key-pins']);
227
+ *
228
+ * res.on('data', (d) => {});
229
+ * });
230
+ *
231
+ * req.on('error', (e) => {
232
+ * console.error(e.message);
233
+ * });
234
+ * req.end();
235
+ * ```
236
+ *
237
+ * Outputs for example:
238
+ *
239
+ * ```text
240
+ * Subject Common Name: github.com
241
+ * Certificate SHA256 fingerprint: 25:FE:39:32:D9:63:8C:8A:FC:A1:9A:29:87:D8:3E:4C:1D:98:DB:71:E4:1A:48:03:98:EA:22:6A:BD:8B:93:16
242
+ * Public key ping-sha256: pL1+qb9HTMRZJmuC/bB/ZI9d302BYrrqiVuRyW+DGrU=
243
+ * Subject Common Name: DigiCert SHA2 Extended Validation Server CA
244
+ * Certificate SHA256 fingerprint: 40:3E:06:2A:26:53:05:91:13:28:5B:AF:80:A0:D4:AE:42:2C:84:8C:9F:78:FA:D0:1F:C9:4B:C5:B8:7F:EF:1A
245
+ * Public key ping-sha256: RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=
246
+ * Subject Common Name: DigiCert High Assurance EV Root CA
247
+ * Certificate SHA256 fingerprint: 74:31:E5:F4:C3:C1:CE:46:90:77:4F:0B:61:E0:54:40:88:3B:A9:A0:1E:D0:0B:A6:AB:D7:80:6E:D3:B1:18:CF
248
+ * Public key ping-sha256: WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=
249
+ * All OK. Server matched our pinned cert or public key
250
+ * statusCode: 200
251
+ * headers: max-age=0; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=";
252
+ * pin-sha256="k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws="; pin-sha256="K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q="; pin-sha256="IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4=";
253
+ * pin-sha256="iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0="; pin-sha256="LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A="; includeSubDomains
254
+ * ```
255
+ * @since v0.3.6
256
+ * @param options Accepts all `options` from `request`, with some differences in default values:
257
+ */
31
258
  function request(options: RequestOptions | string | URL, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
32
259
  function request(url: string | URL, options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
260
+ /**
261
+ * Like `http.get()` but for HTTPS.
262
+ *
263
+ * `options` can be an object, a string, or a `URL` object. If `options` is a
264
+ * string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
265
+ *
266
+ * ```js
267
+ * const https = require('https');
268
+ *
269
+ * https.get('https://encrypted.google.com/', (res) => {
270
+ * console.log('statusCode:', res.statusCode);
271
+ * console.log('headers:', res.headers);
272
+ *
273
+ * res.on('data', (d) => {
274
+ * process.stdout.write(d);
275
+ * });
276
+ *
277
+ * }).on('error', (e) => {
278
+ * console.error(e);
279
+ * });
280
+ * ```
281
+ * @since v0.3.6
282
+ * @param options Accepts the same `options` as {@link request}, with the `method` always set to `GET`.
283
+ */
33
284
  function get(options: RequestOptions | string | URL, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
34
285
  function get(url: string | URL, options: RequestOptions, callback?: (res: http.IncomingMessage) => void): http.ClientRequest;
35
286
  let globalAgent: Agent;
36
287
  }
37
-
38
288
  declare module 'node:https' {
39
289
  export * from 'https';
40
290
  }
node/index.d.ts CHANGED
@@ -41,8 +41,33 @@
41
41
  // Jason Kwok <https://github.com/JasonHK>
42
42
  // Victor Perin <https://github.com/victorperin>
43
43
  // Yongsheng Zhang <https://github.com/ZYSzys>
44
+ // NodeJS Contributors <https://github.com/NodeJS>
44
45
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
45
46
 
47
+ /**
48
+ * License for programmatically and manually incorporated
49
+ * documentation aka. `JSDoc` from https://github.com/nodejs/node/tree/master/doc
50
+ *
51
+ * Copyright Node.js contributors. All rights reserved.
52
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
53
+ * of this software and associated documentation files (the "Software"), to
54
+ * deal in the Software without restriction, including without limitation the
55
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
56
+ * sell copies of the Software, and to permit persons to whom the Software is
57
+ * furnished to do so, subject to the following conditions:
58
+ *
59
+ * The above copyright notice and this permission notice shall be included in
60
+ * all copies or substantial portions of the Software.
61
+ *
62
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
63
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
64
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
65
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
66
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
67
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
68
+ * IN THE SOFTWARE.
69
+ */
70
+
46
71
  // NOTE: These definitions support NodeJS and TypeScript 3.7.
47
72
  // Typically type modifications should be made in base.d.ts instead of here
48
73