text: // Copyright (c) Microsoft Corporation. All rights reserved.
  // Licensed under the MIT License.
  import { __assign } from "tslib";
  import { BaseRequestPolicy, deserializationPolicy, disableResponseDecompressionPolicy, HttpHeaders, RequestPolicyOptions, WebResource, proxyPolicy, isNode, isTokenCredential, bearerTokenAuthenticationPolicy, tracingPolicy, logPolicy, keepAlivePolicy, generateClientRequestIdPolicy } from "@azure/core-http";
  import { logger } from "./log";
  import { StorageBrowserPolicyFactory } from "./StorageBrowserPolicyFactory";
  import { StorageRetryPolicyFactory } from "./StorageRetryPolicyFactory";
  import { StorageOAuthScopes, StorageBlobLoggingAllowedHeaderNames, StorageBlobLoggingAllowedQueryParameters } from "./utils/constants";
  import { TelemetryPolicyFactory } from "./TelemetryPolicyFactory";
  import { getCachedDefaultHttpClient } from "./utils/cache";
  // Export following interfaces and types for customers who want to implement their
  // own RequestPolicy or HTTPClient
  export { BaseRequestPolicy, StorageOAuthScopes, deserializationPolicy, HttpHeaders, WebResource, RequestPolicyOptions };
  /**
   * A Pipeline class containing HTTP request policies.
   * You can create a default Pipeline by calling {@link newPipeline}.
   * Or you can create a Pipeline with your own policies by the constructor of Pipeline.
   *
   * Refer to {@link newPipeline} and provided policies before implementing your
   * customized Pipeline.
   *
   * @export
   * @class Pipeline
   */
  var Pipeline = /** @class */ (function () {
      /**
       * Creates an instance of Pipeline. Customize HTTPClient by implementing IHttpClient interface.
       *
       * @param {RequestPolicyFactory[]} factories
       * @param {PipelineOptions} [options={}]
       * @memberof Pipeline
       */
      function Pipeline(factories, options) {
          if (options === void 0) { options = {}; }
          this.factories = factories;
          // when options.httpClient is not specified, passing in a DefaultHttpClient instance to
          // avoid each client creating its own http client.
          this.options = __assign(__assign({}, options), { httpClient: options.httpClient || getCachedDefaultHttpClient() });
      }
      /**
       * Transfer Pipeline object to ServiceClientOptions object which is required by
       * ServiceClient constructor.
       *
       * @returns {ServiceClientOptions} The ServiceClientOptions object from this Pipeline.
       * @memberof Pipeline
       */
      Pipeline.prototype.toServiceClientOptions = function () {
          return {
              httpClient: this.options.httpClient,
              requestPolicyFactories: this.factories
          };
      };
      return Pipeline;
  }());
  export { Pipeline };
  /**
   * Creates a new Pipeline object with Credential provided.
   *
   * @export
   * @param {StorageSharedKeyCredential | AnonymousCredential | TokenCredential} credential  Such as AnonymousCredential, StorageSharedKeyCredential or any credential from the @azure/identity package to authenticate requests to the service. You can also provide an object that implements the TokenCredential interface. If not specified, AnonymousCredential is used.
   * @param {StoragePipelineOptions} [pipelineOptions] Optional. Options.
   * @returns {Pipeline} A new Pipeline object.
   */
  export function newPipeline(credential, pipelineOptions) {
      // Order is important. Closer to the API at the top & closer to the network at the bottom.
      // The credential's policy factory must appear close to the wire so it can sign any
      // changes made by other factories (like UniqueRequestIDPolicyFactory)
      if (pipelineOptions === void 0) { pipelineOptions = {}; }
      var telemetryPolicy = new TelemetryPolicyFactory(pipelineOptions.userAgentOptions);
      var factories = [
          tracingPolicy({ userAgent: telemetryPolicy.telemetryString }),
          keepAlivePolicy(pipelineOptions.keepAliveOptions),
          telemetryPolicy,
          generateClientRequestIdPolicy(),
          new StorageBrowserPolicyFactory(),
          deserializationPolicy(),
          new StorageRetryPolicyFactory(pipelineOptions.retryOptions),
          logPolicy({
              logger: logger.info,
              allowedHeaderNames: StorageBlobLoggingAllowedHeaderNames,
              allowedQueryParameters: StorageBlobLoggingAllowedQueryParameters
          })
      ];
      if (isNode) {
          // policies only avaiable in Node.js runtime, not in browsers
          factories.push(proxyPolicy(pipelineOptions.proxyOptions));
          factories.push(disableResponseDecompressionPolicy());
      }
      factories.push(isTokenCredential(credential)
          ? bearerTokenAuthenticationPolicy(credential, StorageOAuthScopes)
          : credential);
      return new Pipeline(factories, pipelineOptions);
  }
  //# sourceMappingURL=Pipeline.js.map