import { checkSdk } from '../utils/schema-validators';
import {
  getAuthorizeUrl as _getAuthorizeUrl,
  exchangeCredentials as _exchangeCredentials,
} from '../open-id-connect';
import { parseQuery } from '../ports/querystring';
import User from './user';
import * as models from './index';
import * as constants from '../constants';
import { setFluxUrl } from '../utils/request';

function FluxSdk(clientId, sdkOptions = {}) {
  const {
    fluxUrl,
    redirectUri,
    implicit,
    clientSecret,
  } = sdkOptions;
  checkSdk({ clientId, ...sdkOptions });

  setFluxUrl(fluxUrl);

  function getAuthorizeUrl(state, nonce, options = {}) {
    return _getAuthorizeUrl(state, nonce, clientId, options.redirectUri || redirectUri, {
      fluxUrl: options.fluxUrl || fluxUrl || '',
      implicit: !!implicit,
    });
  }

  function exchangeCredentials(state, nonce, responseQuery = {}, options = {}) {
    const query = implicit ? parseQuery(window.location.hash.slice(1)) : responseQuery;
    const redirect = options.redirectUri || redirectUri;

    return _exchangeCredentials(state, nonce, clientId, redirect, query, {
      fluxUrl,
      clientSecret,
      implicit: !!implicit,
    });
  }

  function getUser(credentials) {
    return new User(credentials);
  }

  this.getAuthorizeUrl = getAuthorizeUrl;
  this.exchangeCredentials = exchangeCredentials;
  this.getUser = getUser;
}

Object.keys(models).forEach(key => { FluxSdk.prototype[key] = models[key]; });
FluxSdk.prototype.constants = constants;

export default FluxSdk;

@@ -376,16 +376,54 @@
 uest';%0A%0A
+import %7B VERSION %7D from '../config';%0A%0A
 function
@@ -1546,16 +1546,72 @@
 tants;%0A%0A
+FluxSdk.prototype.version = FluxSdk.version = VERSION;%0A%0A
 export d

Make the current version easily accessible