text: "use strict";
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
      if (k2 === undefined) k2 = k;
      Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
  }) : (function(o, m, k, k2) {
      if (k2 === undefined) k2 = k;
      o[k2] = m[k];
  }));
  var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
      Object.defineProperty(o, "default", { enumerable: true, value: v });
  }) : function(o, v) {
      o["default"] = v;
  });
  var __importStar = (this && this.__importStar) || function (mod) {
      if (mod && mod.__esModule) return mod;
      var result = {};
      if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
      __setModuleDefault(result, mod);
      return result;
  };
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  exports.Api = void 0;
  const axios_1 = __importDefault(require("axios"));
  const proxy_agent_1 = __importDefault(require("proxy-agent"));
  const errors = __importStar(require("../errors"));
  const account_1 = require("../account");
  const log_1 = require("../log");
  const configuration_1 = require("./generated/core/configuration");
  class Api {
      constructor(ApiConstructor, account, log) {
          this.log = log;
          this.axios = axios_1.default.create({
              headers: {
                  Authorization: `Bearer ${account.apiKey}`,
              },
              // ProxyAgent sets up proxying by itself
              proxy: false,
              httpAgent: new proxy_agent_1.default(),
              httpsAgent: new proxy_agent_1.default(),
          });
          this.axios.interceptors.response.use(undefined, (error) => {
              if (axios_1.default.isAxiosError(error)) {
                  // handle some common error reasons
                  if (error.request === undefined) {
                      // could not make a request
                      return Promise.reject(log_1.logAndReturn(this.log, new errors.ConnectionError(error.message, error)));
                  }
                  if (error.response === undefined) {
                      // did not receive a response
                      return Promise.reject(log_1.logAndReturn(this.log, new errors.ConnectionError(error.message, error)));
                  }
                  if (error.response.status === 401 || error.response.status === 403) {
                      // 401 Unauthorized || 403 Forbidden
                      return Promise.reject(log_1.logAndReturn(this.log, new errors.AuthenticationError()));
                  }
                  if (error.response.status === 400) {
                      return Promise.reject(log_1.logAndReturn(this.log, new errors.ArgumentError(JSON.stringify(error.response.data))));
                  }
              }
              return Promise.reject(log_1.logAndReturn(this.log, new errors.InternalError(error.message, error)));
          });
          const config = new configuration_1.Configuration({
              basePath: account_1.getBaseHttpUrl(account),
          });
          this.api = new ApiConstructor(config, undefined, this.axios);
      }
  }
  exports.Api = Api;
  //# sourceMappingURL=base.js.map