serviceClient.d.ts 6.2 KB

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