function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

import { BrowserAdaptor, getEnvAdaptor } from '@looker/extension-utils';
import { getSpecsFromVersions } from '@looker/sdk-codegen';
import { RunItConfigKey, RunItNoConfig } from '@looker/run-it';
import cloneDeep from 'lodash/cloneDeep';
import { fullify, fallbackFetch, funFetch } from './adaptorUtils';
export var getApixAdaptor = () => getEnvAdaptor();
export class ApixAdaptor extends BrowserAdaptor {
  constructor(sdk, fallbackVersionsUrl) {
    super(sdk);
    this.fallbackVersionsUrl = fallbackVersionsUrl;
  }

  fetchSpecList(versionsUrl) {
    var _this = this;

    return _asyncToGenerator(function* () {
      var data = yield _this.localStorageGetItem(RunItConfigKey);
      var config = data ? JSON.parse(data) : RunItNoConfig;
      var url;

      if (versionsUrl) {
        url = versionsUrl;
      } else {
        url = config.base_url ? "".concat(config.base_url, "/versions") : "".concat(_this.fallbackVersionsUrl, "/versions.json");
      }

      var versions = yield _this.sdk.authSession.transport.rawRequest('GET', url);
      var specs = yield getSpecsFromVersions(JSON.parse(versions.body));
      return specs;
    })();
  }

  fetchSpec(spec) {
    return _asyncToGenerator(function* () {
      var _spec = cloneDeep(spec);

      _spec.specURL = fullify(spec.specURL, origin);
      _spec.api = yield fallbackFetch(_spec, funFetch);
      return _spec;
    })();
  }

}
//# sourceMappingURL=apixAdaptor.js.map