1 | /// <reference types="node" />
|
2 | import { HttpHeadersLike } from "./httpHeaders";
|
3 | import { OperationSpec } from "./operationSpec";
|
4 | import { Mapper } from "./serializer";
|
5 | import { HttpOperationResponse } from "./httpOperationResponse";
|
6 | import { OperationResponse } from "./operationResponse";
|
7 | import { AgentSettings, ProxySettings } from "./serviceClient";
|
8 | export declare type HttpMethods = "GET" | "PUT" | "POST" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE";
|
9 | export declare type HttpRequestBody = Blob | string | ArrayBuffer | ArrayBufferView | (() => NodeJS.ReadableStream);
|
10 | /**
|
11 | * Fired in response to upload or download progress.
|
12 | */
|
13 | export declare type TransferProgressEvent = {
|
14 | /**
|
15 | * The number of bytes loaded so far.
|
16 | */
|
17 | loadedBytes: number;
|
18 | };
|
19 | /**
|
20 | * Allows the request to be aborted upon firing of the "abort" event.
|
21 | * Compatible with the browser built-in AbortSignal and common polyfills.
|
22 | */
|
23 | export interface AbortSignalLike {
|
24 | readonly aborted: boolean;
|
25 | dispatchEvent: (event: Event) => boolean;
|
26 | onabort: ((this: AbortSignalLike, ev: Event) => any) | null;
|
27 | addEventListener: (type: "abort", listener: (this: AbortSignalLike, ev: Event) => any, options?: any) => void;
|
28 | removeEventListener: (type: "abort", listener: (this: AbortSignalLike, ev: Event) => any, options?: any) => void;
|
29 | }
|
30 | /**
|
31 | * An abstraction over a REST call.
|
32 | */
|
33 | export interface WebResourceLike {
|
34 | /**
|
35 | * The URL being accessed by the request.
|
36 | */
|
37 | url: string;
|
38 | /**
|
39 | * The HTTP method to use when making the request.
|
40 | */
|
41 | method: HttpMethods;
|
42 | /**
|
43 | * The HTTP body contents of the request.
|
44 | */
|
45 | body?: any;
|
46 | /**
|
47 | * The HTTP headers to use when making the request.
|
48 | */
|
49 | headers: HttpHeadersLike;
|
50 | /**
|
51 | * Whether or not the body of the HttpOperationResponse should be treated as a stream.
|
52 | */
|
53 | streamResponseBody?: boolean;
|
54 | /**
|
55 | * Whether or not the HttpOperationResponse should be deserialized. If this is undefined, then the
|
56 | * HttpOperationResponse should be deserialized.
|
57 | */
|
58 | shouldDeserialize?: boolean | ((response: HttpOperationResponse) => boolean);
|
59 | /**
|
60 | * A function that returns the proper OperationResponse for the given OperationSpec and
|
61 | * HttpOperationResponse combination. If this is undefined, then a simple status code lookup will
|
62 | * be used.
|
63 | */
|
64 | operationResponseGetter?: (operationSpec: OperationSpec, response: HttpOperationResponse) => undefined | OperationResponse;
|
65 | formData?: any;
|
66 | /**
|
67 | * A query string represented as an object.
|
68 | */
|
69 | query?: {
|
70 | [key: string]: any;
|
71 | };
|
72 | /**
|
73 | * Used to parse the response.
|
74 | */
|
75 | operationSpec?: OperationSpec;
|
76 | /**
|
77 | * If credentials (cookies) should be sent along during an XHR.
|
78 | */
|
79 | withCredentials: boolean;
|
80 | /**
|
81 | * The number of milliseconds a request can take before automatically being terminated.
|
82 | * If the request is terminated, an `AbortError` is thrown.
|
83 | */
|
84 | timeout: number;
|
85 | /**
|
86 | * Proxy configuration.
|
87 | */
|
88 | proxySettings?: ProxySettings;
|
89 | /**
|
90 | * HTTP(S) agent configuration.
|
91 | */
|
92 | agentSettings?: AgentSettings;
|
93 | /**
|
94 | * If the connection should be reused.
|
95 | */
|
96 | keepAlive?: boolean;
|
97 | /**
|
98 | * Limit the number of redirects followed for this request. If set to 0, redirects will not be followed.
|
99 | * If left undefined the default redirect behaviour of the underlying node_fetch will apply.
|
100 | */
|
101 | redirectLimit?: number;
|
102 | /**
|
103 | * Used to abort the request later.
|
104 | */
|
105 | abortSignal?: AbortSignalLike;
|
106 | /**
|
107 | * Callback which fires upon upload progress.
|
108 | */
|
109 | onUploadProgress?: (progress: TransferProgressEvent) => void;
|
110 | /** Callback which fires upon download progress. */
|
111 | onDownloadProgress?: (progress: TransferProgressEvent) => void;
|
112 | /**
|
113 | * Validates that the required properties such as method, url, headers["Content-Type"],
|
114 | * headers["accept-language"] are defined. It will throw an error if one of the above
|
115 | * mentioned properties are not defined.
|
116 | */
|
117 | validateRequestProperties(): void;
|
118 | /**
|
119 | * Sets options on the request.
|
120 | */
|
121 | prepare(options: RequestPrepareOptions): WebResourceLike;
|
122 | /**
|
123 | * Clone this request object.
|
124 | */
|
125 | clone(): WebResourceLike;
|
126 | }
|
127 | export declare function isWebResourceLike(object: any): object is WebResourceLike;
|
128 | /**
|
129 | * Creates a new WebResource object.
|
130 | *
|
131 | * This class provides an abstraction over a REST call by being library / implementation agnostic and wrapping the necessary
|
132 | * properties to initiate a request.
|
133 | *
|
134 | * @constructor
|
135 | */
|
136 | export declare class WebResource {
|
137 | url: string;
|
138 | method: HttpMethods;
|
139 | body?: any;
|
140 | headers: HttpHeadersLike;
|
141 | /**
|
142 | * Whether or not the body of the HttpOperationResponse should be treated as a stream.
|
143 | */
|
144 | streamResponseBody?: boolean;
|
145 | /**
|
146 | * Whether or not the HttpOperationResponse should be deserialized. If this is undefined, then the
|
147 | * HttpOperationResponse should be deserialized.
|
148 | */
|
149 | shouldDeserialize?: boolean | ((response: HttpOperationResponse) => boolean);
|
150 | /**
|
151 | * A function that returns the proper OperationResponse for the given OperationSpec and
|
152 | * HttpOperationResponse combination. If this is undefined, then a simple status code lookup will
|
153 | * be used.
|
154 | */
|
155 | operationResponseGetter?: (operationSpec: OperationSpec, response: HttpOperationResponse) => undefined | OperationResponse;
|
156 | formData?: any;
|
157 | query?: {
|
158 | [key: string]: any;
|
159 | };
|
160 | operationSpec?: OperationSpec;
|
161 | withCredentials: boolean;
|
162 | timeout: number;
|
163 | proxySettings?: ProxySettings;
|
164 | keepAlive?: boolean;
|
165 | agentSettings?: AgentSettings;
|
166 | redirectLimit?: number;
|
167 | abortSignal?: AbortSignalLike;
|
168 | /** Callback which fires upon upload progress. */
|
169 | onUploadProgress?: (progress: TransferProgressEvent) => void;
|
170 | /** Callback which fires upon download progress. */
|
171 | onDownloadProgress?: (progress: TransferProgressEvent) => void;
|
172 | constructor(url?: string, method?: HttpMethods, body?: any, query?: {
|
173 | [key: string]: any;
|
174 | }, headers?: {
|
175 | [key: string]: any;
|
176 | } | HttpHeadersLike, streamResponseBody?: boolean, withCredentials?: boolean, abortSignal?: AbortSignalLike, timeout?: number, onUploadProgress?: (progress: TransferProgressEvent) => void, onDownloadProgress?: (progress: TransferProgressEvent) => void, proxySettings?: ProxySettings, keepAlive?: boolean, agentSettings?: AgentSettings, redirectLimit?: number);
|
177 | /**
|
178 | * Validates that the required properties such as method, url, headers["Content-Type"],
|
179 | * headers["accept-language"] are defined. It will throw an error if one of the above
|
180 | * mentioned properties are not defined.
|
181 | */
|
182 | validateRequestProperties(): void;
|
183 | /**
|
184 | * Prepares the request.
|
185 | * @param {RequestPrepareOptions} options Options to provide for preparing the request.
|
186 | * {WebResource} Returns the prepared WebResource (HTTP Request) object that needs to be given to the request pipeline.
|
187 | */
|
188 | prepare(options: RequestPrepareOptions): WebResource;
|
189 | /**
|
190 | * Clone this WebResource HTTP request object.
|
191 | * @returns {WebResource} The clone of this WebResource HTTP request object.
|
192 | */
|
193 | clone(): WebResource;
|
194 | }
|
195 | export interface RequestPrepareOptions {
|
196 | /**
|
197 | * The HTTP request method. Valid values are "GET", "PUT", "HEAD", "DELETE", "OPTIONS", "POST",
|
198 | * or "PATCH".
|
199 | */
|
200 | method: HttpMethods;
|
201 | /**
|
202 | * The request url. It may or may not have query parameters in it. Either provide the "url" or
|
203 | * provide the "pathTemplate" in the options object. Both the options are mutually exclusive.
|
204 | */
|
205 | url?: string;
|
206 | /**
|
207 | * A dictionary of query parameters to be appended to the url, where
|
208 | * the "key" is the "query-parameter-name" and the "value" is the "query-parameter-value".
|
209 | * The "query-parameter-value" can be of type "string" or it can be of type "object".
|
210 | * The "object" format should be used when you want to skip url encoding. While using the object format,
|
211 | * the object must have a property named value which provides the "query-parameter-value".
|
212 | * Example:
|
213 | * - query-parameter-value in "object" format: { "query-parameter-name": { value: "query-parameter-value", skipUrlEncoding: true } }
|
214 | * - query-parameter-value in "string" format: { "query-parameter-name": "query-parameter-value"}.
|
215 | * Note: "If options.url already has some query parameters, then the value provided in options.queryParameters will be appended to the url.
|
216 | */
|
217 | queryParameters?: {
|
218 | [key: string]: any | ParameterValue;
|
219 | };
|
220 | /**
|
221 | * The path template of the request url. Either provide the "url" or provide the "pathTemplate" in
|
222 | * the options object. Both the options are mutually exclusive.
|
223 | * Example: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}"
|
224 | */
|
225 | pathTemplate?: string;
|
226 | /**
|
227 | * The base url of the request. Default value is: "https://management.azure.com". This is
|
228 | * applicable only with pathTemplate. If you are providing options.url then it is expected that
|
229 | * you provide the complete url.
|
230 | */
|
231 | baseUrl?: string;
|
232 | /**
|
233 | * A dictionary of path parameters that need to be replaced with actual values in the pathTemplate.
|
234 | * Here the key is the "path-parameter-name" and the value is the "path-parameter-value".
|
235 | * The "path-parameter-value" can be of type "string" or it can be of type "object".
|
236 | * The "object" format should be used when you want to skip url encoding. While using the object format,
|
237 | * the object must have a property named value which provides the "path-parameter-value".
|
238 | * Example:
|
239 | * - path-parameter-value in "object" format: { "path-parameter-name": { value: "path-parameter-value", skipUrlEncoding: true } }
|
240 | * - path-parameter-value in "string" format: { "path-parameter-name": "path-parameter-value" }.
|
241 | */
|
242 | pathParameters?: {
|
243 | [key: string]: any | ParameterValue;
|
244 | };
|
245 | formData?: {
|
246 | [key: string]: any;
|
247 | };
|
248 | /**
|
249 | * A dictionary of request headers that need to be applied to the request.
|
250 | * Here the key is the "header-name" and the value is the "header-value". The header-value MUST be of type string.
|
251 | * - ContentType must be provided with the key name as "Content-Type". Default value "application/json; charset=utf-8".
|
252 | * - "Transfer-Encoding" is set to "chunked" by default if "options.bodyIsStream" is set to true.
|
253 | * - "Content-Type" is set to "application/octet-stream" by default if "options.bodyIsStream" is set to true.
|
254 | * - "accept-language" by default is set to "en-US"
|
255 | * - "x-ms-client-request-id" by default is set to a new Guid. To not generate a guid for the request, please set options.disableClientRequestId to true
|
256 | */
|
257 | headers?: {
|
258 | [key: string]: any;
|
259 | };
|
260 | /**
|
261 | * When set to true, instructs the client to not set "x-ms-client-request-id" header to a new Guid().
|
262 | */
|
263 | disableClientRequestId?: boolean;
|
264 | /**
|
265 | * The request body. It can be of any type. This value will be serialized if it is not a stream.
|
266 | */
|
267 | body?: any;
|
268 | /**
|
269 | * Provides information on how to serialize the request body.
|
270 | */
|
271 | serializationMapper?: Mapper;
|
272 | /**
|
273 | * A dictionary of mappers that may be used while [de]serialization.
|
274 | */
|
275 | mappers?: {
|
276 | [x: string]: any;
|
277 | };
|
278 | /**
|
279 | * Provides information on how to deserialize the response body.
|
280 | */
|
281 | deserializationMapper?: object;
|
282 | /**
|
283 | * Indicates whether this method should JSON.stringify() the request body. Default value: false.
|
284 | */
|
285 | disableJsonStringifyOnBody?: boolean;
|
286 | /**
|
287 | * Indicates whether the request body is a stream (useful for file upload scenarios).
|
288 | */
|
289 | bodyIsStream?: boolean;
|
290 | abortSignal?: AbortSignalLike;
|
291 | /**
|
292 | * Limit the number of redirects followed for this request. If set to 0, redirects will not be followed.
|
293 | * If left undefined the default redirect behaviour of the underlying node_fetch will apply.
|
294 | */
|
295 | redirectLimit?: number;
|
296 | onUploadProgress?: (progress: TransferProgressEvent) => void;
|
297 | onDownloadProgress?: (progress: TransferProgressEvent) => void;
|
298 | streamResponseBody?: boolean;
|
299 | }
|
300 | /**
|
301 | * The Parameter value provided for path or query parameters in RequestPrepareOptions
|
302 | */
|
303 | export interface ParameterValue {
|
304 | value: any;
|
305 | skipUrlEncoding: boolean;
|
306 | [key: string]: any;
|
307 | }
|
308 | /**
|
309 | * Describes the base structure of the options object that will be used in every operation.
|
310 | */
|
311 | export interface RequestOptionsBase {
|
312 | /**
|
313 | * @property {object} [customHeaders] User defined custom request headers that
|
314 | * will be applied before the request is sent.
|
315 | */
|
316 | customHeaders?: {
|
317 | [key: string]: string;
|
318 | };
|
319 | /**
|
320 | * The signal which can be used to abort requests.
|
321 | */
|
322 | abortSignal?: AbortSignalLike;
|
323 | /**
|
324 | * The number of milliseconds a request can take before automatically being terminated.
|
325 | */
|
326 | timeout?: number;
|
327 | /**
|
328 | * Callback which fires upon upload progress.
|
329 | */
|
330 | onUploadProgress?: (progress: TransferProgressEvent) => void;
|
331 | /**
|
332 | * Callback which fires upon download progress.
|
333 | */
|
334 | onDownloadProgress?: (progress: TransferProgressEvent) => void;
|
335 | [key: string]: any;
|
336 | }
|
337 | //# sourceMappingURL=webResource.d.ts.map |
\ | No newline at end of file |