UNPKG

8.03 kBTypeScriptView Raw
1/// <reference types="node" />
2import { TokenCredential } from "@azure/core-auth";
3import { ServiceClientCredentials } from "./credentials/serviceClientCredentials";
4import { HttpClient } from "./httpClient";
5import { HttpOperationResponse, RestResponse } from "./httpOperationResponse";
6import { HttpPipelineLogger } from "./httpPipelineLogger";
7import { OperationArguments } from "./operationArguments";
8import { ParameterPath } from "./operationParameter";
9import { OperationSpec } from "./operationSpec";
10import { DeserializationContentTypes } from "./policies/deserializationPolicy";
11import { RedirectOptions } from "./policies/redirectPolicy";
12import { RequestPolicyFactory } from "./policies/requestPolicy";
13import { Mapper, Serializer } from "./serializer";
14import { RequestPrepareOptions, WebResourceLike } from "./webResource";
15import { OperationResponse } from "./operationResponse";
16import { ServiceCallback } from "./util/utils";
17import { Agent } from "http";
18/**
19 * HTTP proxy settings (Node.js only)
20 */
21export interface ProxySettings {
22 host: string;
23 port: number;
24 username?: string;
25 password?: string;
26}
27/**
28 * HTTP and HTTPS agents (Node.js only)
29 */
30export interface AgentSettings {
31 http: Agent;
32 https: Agent;
33}
34/**
35 * Options to be provided while creating the client.
36 */
37export interface ServiceClientOptions {
38 /**
39 * An array of factories which get called to create the RequestPolicy pipeline used to send a HTTP
40 * request on the wire, or a function that takes in the defaultRequestPolicyFactories and returns
41 * the requestPolicyFactories that will be used.
42 */
43 requestPolicyFactories?: RequestPolicyFactory[] | ((defaultRequestPolicyFactories: RequestPolicyFactory[]) => void | RequestPolicyFactory[]);
44 /**
45 * The HttpClient that will be used to send HTTP requests.
46 */
47 httpClient?: HttpClient;
48 /**
49 * The HttpPipelineLogger that can be used to debug RequestPolicies within the HTTP pipeline.
50 */
51 httpPipelineLogger?: HttpPipelineLogger;
52 /**
53 * If set to true, turn off the default retry policy.
54 */
55 noRetryPolicy?: boolean;
56 /**
57 * Gets or sets the retry timeout in seconds for AutomaticRPRegistration. Default value is 30.
58 */
59 rpRegistrationRetryTimeout?: number;
60 /**
61 * Whether or not to generate a client request ID header for each HTTP request.
62 */
63 generateClientRequestIdHeader?: boolean;
64 /**
65 * Whether to include credentials in CORS requests in the browser.
66 * See https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials for more information.
67 */
68 withCredentials?: boolean;
69 /**
70 * If specified, a GenerateRequestIdPolicy will be added to the HTTP pipeline that will add a
71 * header to all outgoing requests with this header name and a random UUID as the request ID.
72 */
73 clientRequestIdHeaderName?: string;
74 /**
75 * The content-types that will be associated with JSON or XML serialization.
76 */
77 deserializationContentTypes?: DeserializationContentTypes;
78 /**
79 * The header name to use for the telemetry header while sending the request. If this is not
80 * specified, then "User-Agent" will be used when running on Node.js and "x-ms-command-name" will
81 * be used when running in a browser.
82 */
83 userAgentHeaderName?: string | ((defaultUserAgentHeaderName: string) => string);
84 /**
85 * The string to be set to the telemetry header while sending the request, or a function that
86 * takes in the default user-agent string and returns the user-agent string that will be used.
87 */
88 userAgent?: string | ((defaultUserAgent: string) => string);
89 /**
90 * Proxy settings which will be used for every HTTP request (Node.js only).
91 */
92 proxySettings?: ProxySettings;
93 /**
94 * Options for how redirect responses are handled.
95 */
96 redirectOptions?: RedirectOptions;
97 /**
98 * HTTP and HTTPS agents which will be used for every HTTP request (Node.js only).
99 */
100 agentSettings?: AgentSettings;
101 /**
102 * If specified:
103 * - This `baseUri` becomes the base URI that requests will be made against for this ServiceClient.
104 * - If the `baseUri` matches a known resource manager endpoint and if a `TokenCredential` was passed through the constructor, this `baseUri` defines the `getToken` scope to be `${options.baseUri}/.default`. Otherwise, the scope would default to "https://management.azure.com/.default".
105 *
106 * If it is not specified:
107 * - All OperationSpecs must contain a baseUrl property.
108 * - If a `TokenCredential` was passed through the constructor, the `getToken` scope is set to be "https://management.azure.com/.default".
109 */
110 baseUri?: string;
111}
112/**
113 * @class
114 * Initializes a new instance of the ServiceClient.
115 */
116export declare class ServiceClient {
117 /**
118 * The base URI against which requests will be made when using this ServiceClient instance.
119 *
120 * This can be set either by setting the `baseUri` in the `options` parameter to the ServiceClient constructor or directly after constructing the ServiceClient.
121 * If set via the ServiceClient constructor when using the overload that takes the `TokenCredential`, and if it matches a known resource manager endpoint, this base URI sets the scope used to get the AAD token to `${baseUri}/.default` instead of the default "https://management.azure.com/.default"
122 *
123 * If it is not specified, all OperationSpecs must contain a baseUrl property.
124 */
125 protected baseUri?: string;
126 /**
127 * The default request content type for the service.
128 * Used if no requestContentType is present on an OperationSpec.
129 */
130 protected requestContentType?: string;
131 /**
132 * The HTTP client that will be used to send requests.
133 */
134 private readonly _httpClient;
135 private readonly _requestPolicyOptions;
136 private readonly _requestPolicyFactories;
137 private readonly _withCredentials;
138 /**
139 * The ServiceClient constructor
140 * @constructor
141 * @param {ServiceClientCredentials} [credentials] The credentials object used for authentication.
142 * @param {ServiceClientOptions} [options] The service client options that govern the behavior of the client.
143 */
144 constructor(credentials?: ServiceClientCredentials | TokenCredential, options?: ServiceClientOptions);
145 /**
146 * Send the provided httpRequest.
147 */
148 sendRequest(options: RequestPrepareOptions | WebResourceLike): Promise<HttpOperationResponse>;
149 /**
150 * Send an HTTP request that is populated using the provided OperationSpec.
151 * @param {OperationArguments} operationArguments The arguments that the HTTP request's templated values will be populated from.
152 * @param {OperationSpec} operationSpec The OperationSpec to use to populate the httpRequest.
153 * @param {ServiceCallback} callback The callback to call when the response is received.
154 */
155 sendOperationRequest(operationArguments: OperationArguments, operationSpec: OperationSpec, callback?: ServiceCallback<any>): Promise<RestResponse>;
156}
157export declare function serializeRequestBody(serviceClient: ServiceClient, httpRequest: WebResourceLike, operationArguments: OperationArguments, operationSpec: OperationSpec): void;
158export declare type PropertyParent = {
159 [propertyName: string]: any;
160};
161/**
162 * Get the property parent for the property at the provided path when starting with the provided
163 * parent object.
164 */
165export declare function getPropertyParent(parent: PropertyParent, propertyPath: string[]): PropertyParent;
166export declare function getOperationArgumentValueFromParameterPath(serviceClient: ServiceClient, operationArguments: OperationArguments, parameterPath: ParameterPath, parameterMapper: Mapper, serializer: Serializer): any;
167export declare function flattenResponse(_response: HttpOperationResponse, responseSpec: OperationResponse | undefined): RestResponse;
168//# sourceMappingURL=serviceClient.d.ts.map
\No newline at end of file