-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
interfaces.ts
515 lines (463 loc) · 14.8 KB
/
interfaces.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import type { AbortSignalLike } from "@azure/abort-controller";
import type { OperationTracingOptions } from "@azure/core-tracing";
/**
* A HttpHeaders collection represented as a simple JSON object.
*/
export type RawHttpHeaders = { [headerName: string]: string };
/**
* A HttpHeaders collection for input, represented as a simple JSON object.
*/
export type RawHttpHeadersInput = Record<string, string | number | boolean>;
/**
* Represents a set of HTTP headers on a request/response.
* Header names are treated as case insensitive.
*/
export interface HttpHeaders extends Iterable<[string, string]> {
/**
* Returns the value of a specific header or undefined if not set.
* @param name - The name of the header to retrieve.
*/
get(name: string): string | undefined;
/**
* Returns true if the specified header exists.
* @param name - The name of the header to check.
*/
has(name: string): boolean;
/**
* Sets a specific header with a given value.
* @param name - The name of the header to set.
* @param value - The value to use for the header.
*/
set(name: string, value: string | number | boolean): void;
/**
* Removes a specific header from the collection.
* @param name - The name of the header to delete.
*/
delete(name: string): void;
/**
* Accesses a raw JS object that acts as a simple map
* of header names to values.
*/
toJSON(options?: { preserveCase?: boolean }): RawHttpHeaders;
}
/**
* A part of the request body in a multipart request.
*/
export interface BodyPart {
/**
* The headers for this part of the multipart request.
*/
headers: HttpHeaders;
/**
* The body of this part of the multipart request.
*/
body:
| ((() => ReadableStream<Uint8Array>) | (() => NodeJS.ReadableStream))
| ReadableStream<Uint8Array>
| NodeJS.ReadableStream
| Uint8Array
| Blob;
}
/**
* A request body consisting of multiple parts.
*/
export interface MultipartRequestBody {
/**
* The parts of the request body.
*/
parts: BodyPart[];
/**
* The boundary separating each part of the request body.
* If not specified, a random boundary will be generated.
*
* When specified, '--' will be prepended to the boundary in the request to ensure the boundary follows the specification.
*/
boundary?: string;
}
/**
* Types of bodies supported on the request.
* NodeJS.ReadableStream and () =\> NodeJS.ReadableStream is Node only.
* Blob, ReadableStream<Uint8Array>, and () =\> ReadableStream<Uint8Array> are browser only.
*/
export type RequestBodyType =
| NodeJS.ReadableStream
| (() => NodeJS.ReadableStream)
| ReadableStream<Uint8Array>
| (() => ReadableStream<Uint8Array>)
| Blob
| ArrayBuffer
| ArrayBufferView
| FormData
| string
| null;
/**
* An interface compatible with NodeJS's `http.Agent`.
* We want to avoid publicly re-exporting the actual interface,
* since it might vary across runtime versions.
*/
export interface Agent {
/**
* Destroy any sockets that are currently in use by the agent.
*/
destroy(): void;
/**
* For agents with keepAlive enabled, this sets the maximum number of sockets that will be left open in the free state.
*/
maxFreeSockets: number;
/**
* Determines how many concurrent sockets the agent can have open per origin.
*/
maxSockets: number;
/**
* An object which contains queues of requests that have not yet been assigned to sockets.
*/
requests: unknown;
/**
* An object which contains arrays of sockets currently in use by the agent.
*/
sockets: unknown;
}
/**
* Metadata about a request being made by the pipeline.
*/
export interface PipelineRequest {
/**
* The URL to make the request to.
*/
url: string;
/**
* The HTTP method to use when making the request.
*/
method: HttpMethods;
/**
* The HTTP headers to use when making the request.
*/
headers: HttpHeaders;
/**
* The number of milliseconds a request can take before automatically being terminated.
* If the request is terminated, an `AbortError` is thrown.
* Defaults to 0, which disables the timeout.
*/
timeout: number;
/**
* Indicates whether the user agent should send cookies from the other domain in the case of cross-origin requests.
* Defaults to false.
*/
withCredentials: boolean;
/**
* A unique identifier for the request. Used for logging and tracing.
*/
requestId: string;
/**
* The HTTP body content (if any)
*/
body?: RequestBodyType;
/**
* Body for a multipart request.
*/
multipartBody?: MultipartRequestBody;
/**
* To simulate a browser form post
*/
formData?: FormDataMap;
/**
* A list of response status codes whose corresponding PipelineResponse body should be treated as a stream.
* When streamResponseStatusCodes contains the value Number.POSITIVE_INFINITY any status would be treated as a stream.
*/
streamResponseStatusCodes?: Set<number>;
/**
* Proxy configuration.
*/
proxySettings?: ProxySettings;
/**
* If the connection should not be reused.
*/
disableKeepAlive?: boolean;
/**
* Used to abort the request later.
*/
abortSignal?: AbortSignalLike;
/**
* Tracing options to use for any created Spans.
*/
tracingOptions?: OperationTracingOptions;
/**
* Callback which fires upon upload progress.
*/
onUploadProgress?: (progress: TransferProgressEvent) => void;
/** Callback which fires upon download progress. */
onDownloadProgress?: (progress: TransferProgressEvent) => void;
/** Set to true if the request is sent over HTTP instead of HTTPS */
allowInsecureConnection?: boolean;
/**
* NODEJS ONLY
*
* A Node-only option to provide a custom `http.Agent`/`https.Agent`.
* Does nothing when running in the browser.
*/
agent?: Agent;
/**
* BROWSER ONLY
*
* A browser only option to enable browser Streams. If this option is set and a response is a stream
* the response will have a property `browserStream` instead of `blobBody` which will be undefined.
*
* Default value is false
*/
enableBrowserStreams?: boolean;
/** Settings for configuring TLS authentication */
tlsSettings?: TlsSettings;
}
/**
* Metadata about a response received by the pipeline.
*/
export interface PipelineResponse {
/**
* The request that generated this response.
*/
request: PipelineRequest;
/**
* The HTTP status code of the response.
*/
status: number;
/**
* The HTTP response headers.
*/
headers: HttpHeaders;
/**
* The response body as text (string format)
*/
bodyAsText?: string | null;
/**
* BROWSER ONLY
*
* The response body as a browser Blob.
* Always undefined in node.js.
*/
blobBody?: Promise<Blob>;
/**
* BROWSER ONLY
*
* The response body as a browser ReadableStream.
* Always undefined in node.js.
*/
browserStreamBody?: ReadableStream<Uint8Array>;
/**
* NODEJS ONLY
*
* The response body as a node.js Readable stream.
* Always undefined in the browser.
*/
readableStreamBody?: NodeJS.ReadableStream;
}
/**
* A simple interface for making a pipeline request and receiving a response.
*/
export type SendRequest = (request: PipelineRequest) => Promise<PipelineResponse>;
/**
* The required interface for a client that makes HTTP requests
* on behalf of a pipeline.
*/
export interface HttpClient {
/**
* The method that makes the request and returns a response.
*/
sendRequest: SendRequest;
}
/**
* Fired in response to upload or download progress.
*/
export type TransferProgressEvent = {
/**
* The number of bytes loaded so far.
*/
loadedBytes: number;
};
/**
* Supported HTTP methods to use when making requests.
*/
export type HttpMethods =
| "GET"
| "PUT"
| "POST"
| "DELETE"
| "PATCH"
| "HEAD"
| "OPTIONS"
| "TRACE";
/**
* Options to configure a proxy for outgoing requests (Node.js only).
*/
export interface ProxySettings {
/**
* The proxy's host address.
*/
host: string;
/**
* The proxy host's port.
*/
port: number;
/**
* The user name to authenticate with the proxy, if required.
*/
username?: string;
/**
* The password to authenticate with the proxy, if required.
*/
password?: string;
}
/**
* Each form data entry can be a string, Blob, or a File. If you wish to pass a file with a name but do not have
* access to the File class, you can use the createFile helper to create one.
*/
export type FormDataValue = string | Blob | File;
/**
* A simple object that provides form data, as if from a browser form.
*/
export type FormDataMap = { [key: string]: FormDataValue | FormDataValue[] };
/**
* Options that control how to retry failed requests.
*/
export interface PipelineRetryOptions {
/**
* The maximum number of retry attempts. Defaults to 3.
*/
maxRetries?: number;
/**
* The amount of delay in milliseconds between retry attempts. Defaults to 1000
* (1 second). The delay increases exponentially with each retry up to a maximum
* specified by maxRetryDelayInMs.
*/
retryDelayInMs?: number;
/**
* The maximum delay in milliseconds allowed before retrying an operation. Defaults
* to 64000 (64 seconds).
*/
maxRetryDelayInMs?: number;
}
/**
* Represents a certificate credential for authentication.
*/
export interface CertificateCredential {
/**
* Optionally override the trusted CA certificates. Default is to trust
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
* replaced when CAs are explicitly specified using this option.
*/
ca?: string | Buffer | Array<string | Buffer> | undefined;
/**
* Cert chains in PEM format. One cert chain should be provided per
* private key. Each cert chain should consist of the PEM formatted
* certificate for a provided private key, followed by the PEM
* formatted intermediate certificates (if any), in order, and not
* including the root CA (the root CA must be pre-known to the peer,
* see ca). When providing multiple cert chains, they do not have to
* be in the same order as their private keys in key. If the
* intermediate certificates are not provided, the peer will not be
* able to validate the certificate, and the handshake will fail.
*/
cert?: string | Buffer | Array<string | Buffer> | undefined;
/**
* Private keys in PEM format. PEM allows the option of private keys
* being encrypted. Encrypted keys will be decrypted with
* options.passphrase. Multiple keys using different algorithms can be
* provided either as an array of unencrypted key strings or buffers,
* or an array of objects in the form `{pem: <string|buffer>[,passphrase: <string>]}`.
* The object form can only occur in an array.object.passphrase is optional.
* Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
*/
key?: string | Buffer | Array<Buffer | KeyObject> | undefined;
/**
* Shared passphrase used for a single private key and/or a PFX.
*/
passphrase?: string | undefined;
/**
* PFX or PKCS12 encoded private key and certificate chain. pfx is an
* alternative to providing key and cert individually. PFX is usually
* encrypted, if it is, passphrase will be used to decrypt it. Multiple
* PFX can be provided either as an array of unencrypted PFX buffers,
* or an array of objects in the form `{buf: <string|buffer>[,passphrase: <string>]}`.
* The object form can only occur in an array.object.passphrase is optional.
* Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
*/
pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;
}
/**
* Represents a certificate for TLS authentication.
*/
export interface TlsSettings {
/**
* Optionally override the trusted CA certificates. Default is to trust
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
* replaced when CAs are explicitly specified using this option.
*/
ca?: string | Buffer | Array<string | Buffer> | undefined;
/**
* Cert chains in PEM format. One cert chain should be provided per
* private key. Each cert chain should consist of the PEM formatted
* certificate for a provided private key, followed by the PEM
* formatted intermediate certificates (if any), in order, and not
* including the root CA (the root CA must be pre-known to the peer,
* see ca). When providing multiple cert chains, they do not have to
* be in the same order as their private keys in key. If the
* intermediate certificates are not provided, the peer will not be
* able to validate the certificate, and the handshake will fail.
*/
cert?: string | Buffer | Array<string | Buffer> | undefined;
/**
* Private keys in PEM format. PEM allows the option of private keys
* being encrypted. Encrypted keys will be decrypted with
* options.passphrase. Multiple keys using different algorithms can be
* provided either as an array of unencrypted key strings or buffers,
* or an array of objects in the form `{pem: <string|buffer>[,passphrase: <string>]}`.
* The object form can only occur in an array.object.passphrase is optional.
* Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
*/
key?: string | Buffer | Array<Buffer | KeyObject> | undefined;
/**
* Shared passphrase used for a single private key and/or a PFX.
*/
passphrase?: string | undefined;
/**
* PFX or PKCS12 encoded private key and certificate chain. pfx is an
* alternative to providing key and cert individually. PFX is usually
* encrypted, if it is, passphrase will be used to decrypt it. Multiple
* PFX can be provided either as an array of unencrypted PFX buffers,
* or an array of objects in the form `{buf: <string|buffer>[,passphrase: <string>]}`.
* The object form can only occur in an array.object.passphrase is optional.
* Encrypted PFX will be decrypted with object.passphrase if provided, or options.passphrase if it is not.
*/
pfx?: string | Buffer | Array<string | Buffer | PxfObject> | undefined;
}
/**
* An interface compatible with NodeJS's `tls.KeyObject`.
* We want to avoid publicly re-exporting the actual interface,
* since it might vary across runtime versions.
*/
export interface KeyObject {
/**
* Private keys in PEM format.
*/
pem: string | Buffer;
/**
* Optional passphrase.
*/
passphrase?: string | undefined;
}
/**
* An interface compatible with NodeJS's `tls.PxfObject`.
* We want to avoid publicly re-exporting the actual interface,
* since it might vary across runtime versions.
*/
export interface PxfObject {
/**
* PFX or PKCS12 encoded private key and certificate chain.
*/
buf: string | Buffer;
/**
* Optional passphrase.
*/
passphrase?: string | undefined;
}