@superset-ui/core
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,1 +0,1 @@ | ||
import _JSON$stringify from'babel-runtime/core-js/json/stringify';import _Object$keys from'babel-runtime/core-js/object/keys';import _typeof from'babel-runtime/helpers/typeof';import _extends from'babel-runtime/helpers/extends';import'whatwg-fetch';import'url-search-params-polyfill';var DEFAULT_HEADERS=null;export default function callApi(a){var b=a.url,c=a.method,d=c===void 0?'GET':c,e=a.mode,f=e===void 0?'same-origin':e,g=a.cache,h=g===void 0?'default':g,i=a.credentials,j=i===void 0?'same-origin':i,k=a.headers,l=a.body,m=a.postPayload,n=a.stringify,o=a.redirect,p=o===void 0?'follow':o,q=a.timeoutId,r=a.signal,s={body:l,cache:h,credentials:j,headers:_extends({},DEFAULT_HEADERS,k),method:d,mode:f,redirect:p,signal:r};if('POST'===d&&'object'===('undefined'==typeof m?'undefined':_typeof(m))){var t=new FormData;_Object$keys(m).forEach(function(a){var b=m[a];'undefined'!=typeof b&&t.append(a,!(n!==void 0)||n?_JSON$stringify(m[a]):m[a])}),s=_extends({},s,{body:t})}return fetch(b,s)} | ||
import _JSON$stringify from'babel-runtime/core-js/json/stringify';import _Object$keys from'babel-runtime/core-js/object/keys';import _typeof from'babel-runtime/helpers/typeof';import _extends from'babel-runtime/helpers/extends';import'whatwg-fetch';import'url-search-params-polyfill';var DEFAULT_HEADERS=null;export default function callApi(a){var b=a.url,c=a.method,d=c===void 0?'GET':c,e=a.mode,f=e===void 0?'same-origin':e,g=a.cache,h=g===void 0?'default':g,i=a.credentials,j=i===void 0?'same-origin':i,k=a.headers,l=a.body,m=a.postPayload,n=a.stringify,o=a.redirect,p=o===void 0?'follow':o,q=a.signal,r={body:l,cache:h,credentials:j,headers:_extends({},DEFAULT_HEADERS,k),method:d,mode:f,redirect:p,signal:q};if('POST'===d&&'object'===('undefined'==typeof m?'undefined':_typeof(m))){var s=new FormData;_Object$keys(m).forEach(function(a){var b=m[a];'undefined'!=typeof b&&s.append(a,!(n!==void 0)||n?_JSON$stringify(m[a]):m[a])}),r=_extends({},r,{body:s})}return fetch(b,r)} |
@@ -1,1 +0,1 @@ | ||
import _Promise from'babel-runtime/core-js/promise';import _objectWithoutProperties from'babel-runtime/helpers/objectWithoutProperties';import callApi from'./callApi';import rejectAfterTimeout from'./rejectAfterTimeout';import parseResponse from'./parseResponse';export default function callApiAndParseWithTimeout(a){var b=a.timeout,c=_objectWithoutProperties(a,['timeout']),d=callApi(c),e='number'==typeof b&&0<b?_Promise.race([rejectAfterTimeout(b),d]):d;return parseResponse(e)} | ||
import _Promise from'babel-runtime/core-js/promise';import _objectWithoutProperties from'babel-runtime/helpers/objectWithoutProperties';import callApi from'./callApi';import rejectAfterTimeout from'./rejectAfterTimeout';import parseResponse from'./parseResponse';export default function callApiAndParseWithTimeout(a){var b=a.timeout,c=a.parseMethod,d=_objectWithoutProperties(a,['timeout','parseMethod']),e=callApi(d),f='number'==typeof b&&0<b?_Promise.race([rejectAfterTimeout(b),e]):e;return parseResponse(f,c)} |
@@ -1,1 +0,1 @@ | ||
import _Promise from'babel-runtime/core-js/promise';export default function parseResponse(a){return a.then(function(a){return a.clone().json().catch(function(){return a.text().then(function(a){return{textPayload:a}})}).then(function(b){return{json:b.textPayload?void 0:b,response:a,text:b.textPayload}}).then(function(a){var b=a.response,c=a.json,d=a.text;return b.ok?'undefined'==typeof d?{json:c,response:b}:{response:b,text:d}:_Promise.reject({error:b.error||c&&c.error||d||'An error occurred',status:b.status,statusText:b.statusText})})})} | ||
import _Promise from'babel-runtime/core-js/promise';var PARSERS={json:function json(a){return a.json().then(function(b){return{json:b,response:a}})},text:function text(a){return a.text().then(function(b){return{response:a,text:b}})}};export default function parseResponse(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:'json';if(null===b)return a;var c=PARSERS[b]||PARSERS.json;return a.then(function(a){return a.ok?a:_Promise.reject({error:a.error||'An error occurred',response:a,status:a.status,statusText:a.statusText})}).then(c)} |
@@ -1,1 +0,1 @@ | ||
import _Promise from'babel-runtime/core-js/promise';import _extends from'babel-runtime/helpers/extends';import _classCallCheck from'babel-runtime/helpers/classCallCheck';import _createClass from'babel-runtime/helpers/createClass';import callApi from'./callApi';var SupersetClient=function(){function a(b){_classCallCheck(this,a);var c=b.protocol,d=void 0===c?'http':c,e=b.host,f=void 0===e?'':e,g=b.headers,h=void 0===g?{}:g,i=b.mode,j=void 0===i?'same-origin':i,k=b.timeout,l=b.credentials;this.headers=h,this.host=f,this.mode=j,this.timeout=k,this.protocol=d,this.credentials=l,this.csrfToken=null,this.didAuthSuccessfully=!1,this.csrfPromise=null}return _createClass(a,[{key:'isAuthenticated',value:function isAuthenticated(){return this.didAuthSuccessfully}},{key:'init',value:function init(){return this.getCSRFToken()}},{key:'getCSRFToken',value:function getCSRFToken(){var a=this;return this.csrfPromise=callApi({credentials:this.credentials,headers:_extends({},this.headers),method:'GET',mode:this.mode,timeout:this.timeout,url:this.getUrl({endpoint:'superset/csrf_token/',host:this.host})}).then(function(b){return b.json&&(a.csrfToken=b.json.csrf_token,a.headers=_extends({},a.headers,{"X-CSRFToken":a.csrfToken}),a.didAuthSuccessfully=!!a.csrfToken),a.csrfToken?b:_Promise.reject({error:'Failed to fetch CSRF token'})}),this.csrfPromise}},{key:'getUrl',value:function getUrl(a){var b=a.host,c=void 0===b?'':b,d=a.endpoint,e=void 0===d?'':d,f='/'===c.slice(-1)?c.slice(0,-1):c;return this.protocol+'://'+f+'/'+('/'===e[0]?e.slice(1):e)}},{key:'ensureAuth',value:function ensureAuth(){return this.csrfPromise||_Promise.reject({error:'SupersetClient has no CSRF token, ensure it is initialized or\n try logging into the Superset instance at '+this.getUrl('/login')})}},{key:'get',value:function get(a){var b=this,c=a.host,d=a.url,e=a.endpoint,f=a.mode,g=a.credentials,h=a.headers,i=a.body,j=a.timeout,k=a.signal;return this.ensureAuth().then(function(){return callApi({body:i,credentials:g||b.credentials,headers:_extends({},b.headers,h),method:'GET',mode:f||b.mode,signal:k,timeout:j||b.timeout,url:d||b.getUrl({endpoint:e,host:c||b.host})})})}},{key:'post',value:function post(a){var b=this,c=a.host,d=a.endpoint,e=a.url,f=a.mode,g=a.credentials,h=a.headers,i=a.postPayload,j=a.timeout,k=a.signal,l=a.stringify;return this.ensureAuth().then(function(){return callApi({credentials:g||b.credentials,headers:_extends({},b.headers,h),method:'POST',mode:f||b.mode,postPayload:i,signal:k,stringify:l,timeout:j||b.timeout,url:e||b.getUrl({endpoint:d,host:c||b.host})})})}}]),a}(),singletonClient=void 0;function hasInstance(){if(!singletonClient)throw new Error('You must call SupersetClient.configure(...) before calling other methods');return!0}var PublicAPI={configure:function configure(a){return singletonClient=new SupersetClient(a||{}),singletonClient},get:function get(){var a;return hasInstance()&&(a=singletonClient).get.apply(a,arguments)},init:function init(){return hasInstance()&&singletonClient.init()},isAuthenticated:function isAuthenticated(){return hasInstance()&&singletonClient.isAuthenticated()},post:function post(){var a;return hasInstance()&&(a=singletonClient).post.apply(a,arguments)},reAuthenticate:function reAuthenticate(){return hasInstance()&&singletonClient.getCSRFToken()},reset:function reset(){singletonClient=null}};export{SupersetClient};export default PublicAPI; | ||
import _Promise from'babel-runtime/core-js/promise';import _extends from'babel-runtime/helpers/extends';import _classCallCheck from'babel-runtime/helpers/classCallCheck';import _createClass from'babel-runtime/helpers/createClass';import callApi from'./callApi';var SupersetClient=function(){function a(b){_classCallCheck(this,a);var c=b.protocol,d=void 0===c?'http':c,e=b.host,f=void 0===e?'':e,g=b.headers,h=void 0===g?{}:g,i=b.mode,j=void 0===i?'same-origin':i,k=b.timeout,l=b.credentials;this.headers=h,this.host=f,this.mode=j,this.timeout=k,this.protocol=d,this.credentials=l,this.csrfToken=null,this.didAuthSuccessfully=!1,this.csrfPromise=null}return _createClass(a,[{key:'isAuthenticated',value:function isAuthenticated(){return this.didAuthSuccessfully}},{key:'init',value:function init(){return this.getCSRFToken()}},{key:'getCSRFToken',value:function getCSRFToken(){var a=this;return this.csrfPromise=callApi({credentials:this.credentials,headers:_extends({},this.headers),method:'GET',mode:this.mode,timeout:this.timeout,url:this.getUrl({endpoint:'superset/csrf_token/',host:this.host})}).then(function(b){return b.json&&(a.csrfToken=b.json.csrf_token,a.headers=_extends({},a.headers,{"X-CSRFToken":a.csrfToken}),a.didAuthSuccessfully=!!a.csrfToken),a.csrfToken?b:_Promise.reject({error:'Failed to fetch CSRF token'})}),this.csrfPromise}},{key:'getUrl',value:function getUrl(a){var b=a.host,c=void 0===b?'':b,d=a.endpoint,e=void 0===d?'':d,f='/'===c.slice(-1)?c.slice(0,-1):c;return this.protocol+'://'+f+'/'+('/'===e[0]?e.slice(1):e)}},{key:'ensureAuth',value:function ensureAuth(){return this.csrfPromise||_Promise.reject({error:'SupersetClient has no CSRF token, ensure it is initialized or\n try logging into the Superset instance at '+this.getUrl('/login')})}},{key:'get',value:function get(a){var b=this,c=a.body,d=a.credentials,e=a.headers,f=a.host,g=a.endpoint,h=a.mode,i=a.parseMethod,j=a.signal,k=a.timeout,l=a.url;return this.ensureAuth().then(function(){return callApi({body:c,credentials:d||b.credentials,headers:_extends({},b.headers,e),method:'GET',mode:h||b.mode,parseMethod:i,signal:j,timeout:k||b.timeout,url:l||b.getUrl({endpoint:g,host:f||b.host})})})}},{key:'post',value:function post(a){var b=this,c=a.credentials,d=a.headers,e=a.host,f=a.endpoint,g=a.mode,h=a.parseMethod,i=a.postPayload,j=a.signal,k=a.stringify,l=a.timeout,m=a.url;return this.ensureAuth().then(function(){return callApi({credentials:c||b.credentials,headers:_extends({},b.headers,d),method:'POST',mode:g||b.mode,parseMethod:h,postPayload:i,signal:j,stringify:k,timeout:l||b.timeout,url:m||b.getUrl({endpoint:f,host:e||b.host})})})}}]),a}(),singletonClient=void 0;function hasInstance(){if(!singletonClient)throw new Error('You must call SupersetClient.configure(...) before calling other methods');return!0}var PublicAPI={configure:function configure(a){return singletonClient=new SupersetClient(a||{}),singletonClient},get:function get(){var a;return hasInstance()&&(a=singletonClient).get.apply(a,arguments)},init:function init(){return hasInstance()&&singletonClient.init()},isAuthenticated:function isAuthenticated(){return hasInstance()&&singletonClient.isAuthenticated()},post:function post(){var a;return hasInstance()&&(a=singletonClient).post.apply(a,arguments)},reAuthenticate:function reAuthenticate(){return hasInstance()&&singletonClient.getCSRFToken()},reset:function reset(){singletonClient=null}};export{SupersetClient};export default PublicAPI; |
@@ -1,1 +0,1 @@ | ||
'use strict';var _stringify=require('babel-runtime/core-js/json/stringify'),_stringify2=_interopRequireDefault(_stringify),_keys=require('babel-runtime/core-js/object/keys'),_keys2=_interopRequireDefault(_keys),_typeof2=require('babel-runtime/helpers/typeof'),_typeof3=_interopRequireDefault(_typeof2),_extends2=require('babel-runtime/helpers/extends'),_extends3=_interopRequireDefault(_extends2);Object.defineProperty(exports,'__esModule',{value:!0});exports.default=callApi,require('whatwg-fetch'),require('url-search-params-polyfill');function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var DEFAULT_HEADERS=null;function callApi(a){var b=a.url,c=a.method,d=c===void 0?'GET':c,e=a.mode,f=e===void 0?'same-origin':e,g=a.cache,h=g===void 0?'default':g,i=a.credentials,j=i===void 0?'same-origin':i,k=a.headers,l=a.body,m=a.postPayload,n=a.stringify,o=a.redirect,p=o===void 0?'follow':o,q=a.timeoutId,r=a.signal,s={body:l,cache:h,credentials:j,headers:(0,_extends3.default)({},DEFAULT_HEADERS,k),method:d,mode:f,redirect:p,signal:r};if('POST'===d&&'object'===('undefined'==typeof m?'undefined':(0,_typeof3.default)(m))){var t=new FormData;(0,_keys2.default)(m).forEach(function(a){var b=m[a];'undefined'!=typeof b&&t.append(a,!(n!==void 0)||n?(0,_stringify2.default)(m[a]):m[a])}),s=(0,_extends3.default)({},s,{body:t})}return fetch(b,s)} | ||
'use strict';var _stringify=require('babel-runtime/core-js/json/stringify'),_stringify2=_interopRequireDefault(_stringify),_keys=require('babel-runtime/core-js/object/keys'),_keys2=_interopRequireDefault(_keys),_typeof2=require('babel-runtime/helpers/typeof'),_typeof3=_interopRequireDefault(_typeof2),_extends2=require('babel-runtime/helpers/extends'),_extends3=_interopRequireDefault(_extends2);Object.defineProperty(exports,'__esModule',{value:!0});exports.default=callApi,require('whatwg-fetch'),require('url-search-params-polyfill');function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var DEFAULT_HEADERS=null;function callApi(a){var b=a.url,c=a.method,d=c===void 0?'GET':c,e=a.mode,f=e===void 0?'same-origin':e,g=a.cache,h=g===void 0?'default':g,i=a.credentials,j=i===void 0?'same-origin':i,k=a.headers,l=a.body,m=a.postPayload,n=a.stringify,o=a.redirect,p=o===void 0?'follow':o,q=a.signal,r={body:l,cache:h,credentials:j,headers:(0,_extends3.default)({},DEFAULT_HEADERS,k),method:d,mode:f,redirect:p,signal:q};if('POST'===d&&'object'===('undefined'==typeof m?'undefined':(0,_typeof3.default)(m))){var s=new FormData;(0,_keys2.default)(m).forEach(function(a){var b=m[a];'undefined'!=typeof b&&s.append(a,!(n!==void 0)||n?(0,_stringify2.default)(m[a]):m[a])}),r=(0,_extends3.default)({},r,{body:s})}return fetch(b,r)} |
@@ -1,1 +0,1 @@ | ||
'use strict';var _promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise),_objectWithoutProperties2=require('babel-runtime/helpers/objectWithoutProperties'),_objectWithoutProperties3=_interopRequireDefault(_objectWithoutProperties2);Object.defineProperty(exports,'__esModule',{value:!0});exports.default=callApiAndParseWithTimeout;var _callApi=require('./callApi'),_callApi2=_interopRequireDefault(_callApi),_rejectAfterTimeout=require('./rejectAfterTimeout'),_rejectAfterTimeout2=_interopRequireDefault(_rejectAfterTimeout),_parseResponse=require('./parseResponse'),_parseResponse2=_interopRequireDefault(_parseResponse);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function callApiAndParseWithTimeout(a){var b=a.timeout,c=(0,_objectWithoutProperties3.default)(a,['timeout']),d=(0,_callApi2.default)(c),e='number'==typeof b&&0<b?_promise2.default.race([(0,_rejectAfterTimeout2.default)(b),d]):d;return(0,_parseResponse2.default)(e)} | ||
'use strict';var _promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise),_objectWithoutProperties2=require('babel-runtime/helpers/objectWithoutProperties'),_objectWithoutProperties3=_interopRequireDefault(_objectWithoutProperties2);Object.defineProperty(exports,'__esModule',{value:!0});exports.default=callApiAndParseWithTimeout;var _callApi=require('./callApi'),_callApi2=_interopRequireDefault(_callApi),_rejectAfterTimeout=require('./rejectAfterTimeout'),_rejectAfterTimeout2=_interopRequireDefault(_rejectAfterTimeout),_parseResponse=require('./parseResponse'),_parseResponse2=_interopRequireDefault(_parseResponse);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function callApiAndParseWithTimeout(a){var b=a.timeout,c=a.parseMethod,d=(0,_objectWithoutProperties3.default)(a,['timeout','parseMethod']),e=(0,_callApi2.default)(d),f='number'==typeof b&&0<b?_promise2.default.race([(0,_rejectAfterTimeout2.default)(b),e]):e;return(0,_parseResponse2.default)(f,c)} |
@@ -1,1 +0,1 @@ | ||
'use strict';var _promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise);Object.defineProperty(exports,'__esModule',{value:!0});exports.default=parseResponse;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function parseResponse(a){return a.then(function(a){return a.clone().json().catch(function(){return a.text().then(function(a){return{textPayload:a}})}).then(function(b){return{json:b.textPayload?void 0:b,response:a,text:b.textPayload}}).then(function(a){var b=a.response,c=a.json,d=a.text;return b.ok?'undefined'==typeof d?{json:c,response:b}:{response:b,text:d}:_promise2.default.reject({error:b.error||c&&c.error||d||'An error occurred',status:b.status,statusText:b.statusText})})})} | ||
'use strict';var _promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise);Object.defineProperty(exports,'__esModule',{value:!0});exports.default=parseResponse;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var PARSERS={json:function json(a){return a.json().then(function(b){return{json:b,response:a}})},text:function text(a){return a.text().then(function(b){return{response:a,text:b}})}};function parseResponse(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:'json';if(null===b)return a;var c=PARSERS[b]||PARSERS.json;return a.then(function(a){return a.ok?a:_promise2.default.reject({error:a.error||'An error occurred',response:a,status:a.status,statusText:a.statusText})}).then(c)} |
@@ -1,1 +0,1 @@ | ||
'use strict';var _promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise),_extends2=require('babel-runtime/helpers/extends'),_extends3=_interopRequireDefault(_extends2),_classCallCheck2=require('babel-runtime/helpers/classCallCheck'),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require('babel-runtime/helpers/createClass'),_createClass3=_interopRequireDefault(_createClass2),_callApi=require('./callApi'),_callApi2=_interopRequireDefault(_callApi);Object.defineProperty(exports,'__esModule',{value:!0}),exports.SupersetClient=void 0;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var SupersetClient=function(){function a(b){(0,_classCallCheck3.default)(this,a);var c=b.protocol,d=void 0===c?'http':c,e=b.host,f=void 0===e?'':e,g=b.headers,h=void 0===g?{}:g,i=b.mode,j=void 0===i?'same-origin':i,k=b.timeout,l=b.credentials;this.headers=h,this.host=f,this.mode=j,this.timeout=k,this.protocol=d,this.credentials=l,this.csrfToken=null,this.didAuthSuccessfully=!1,this.csrfPromise=null}return(0,_createClass3.default)(a,[{key:'isAuthenticated',value:function isAuthenticated(){return this.didAuthSuccessfully}},{key:'init',value:function init(){return this.getCSRFToken()}},{key:'getCSRFToken',value:function getCSRFToken(){var a=this;return this.csrfPromise=(0,_callApi2.default)({credentials:this.credentials,headers:(0,_extends3.default)({},this.headers),method:'GET',mode:this.mode,timeout:this.timeout,url:this.getUrl({endpoint:'superset/csrf_token/',host:this.host})}).then(function(b){return b.json&&(a.csrfToken=b.json.csrf_token,a.headers=(0,_extends3.default)({},a.headers,{"X-CSRFToken":a.csrfToken}),a.didAuthSuccessfully=!!a.csrfToken),a.csrfToken?b:_promise2.default.reject({error:'Failed to fetch CSRF token'})}),this.csrfPromise}},{key:'getUrl',value:function getUrl(a){var b=a.host,c=void 0===b?'':b,d=a.endpoint,e=void 0===d?'':d,f='/'===c.slice(-1)?c.slice(0,-1):c;return this.protocol+'://'+f+'/'+('/'===e[0]?e.slice(1):e)}},{key:'ensureAuth',value:function ensureAuth(){return this.csrfPromise||_promise2.default.reject({error:'SupersetClient has no CSRF token, ensure it is initialized or\n try logging into the Superset instance at '+this.getUrl('/login')})}},{key:'get',value:function get(a){var b=this,c=a.host,d=a.url,e=a.endpoint,f=a.mode,g=a.credentials,h=a.headers,i=a.body,j=a.timeout,k=a.signal;return this.ensureAuth().then(function(){return(0,_callApi2.default)({body:i,credentials:g||b.credentials,headers:(0,_extends3.default)({},b.headers,h),method:'GET',mode:f||b.mode,signal:k,timeout:j||b.timeout,url:d||b.getUrl({endpoint:e,host:c||b.host})})})}},{key:'post',value:function post(a){var b=this,c=a.host,d=a.endpoint,e=a.url,f=a.mode,g=a.credentials,h=a.headers,i=a.postPayload,j=a.timeout,k=a.signal,l=a.stringify;return this.ensureAuth().then(function(){return(0,_callApi2.default)({credentials:g||b.credentials,headers:(0,_extends3.default)({},b.headers,h),method:'POST',mode:f||b.mode,postPayload:i,signal:k,stringify:l,timeout:j||b.timeout,url:e||b.getUrl({endpoint:d,host:c||b.host})})})}}]),a}(),singletonClient=void 0;function hasInstance(){if(!singletonClient)throw new Error('You must call SupersetClient.configure(...) before calling other methods');return!0}var PublicAPI={configure:function configure(a){return singletonClient=new SupersetClient(a||{}),singletonClient},get:function get(){var a;return hasInstance()&&(a=singletonClient).get.apply(a,arguments)},init:function init(){return hasInstance()&&singletonClient.init()},isAuthenticated:function isAuthenticated(){return hasInstance()&&singletonClient.isAuthenticated()},post:function post(){var a;return hasInstance()&&(a=singletonClient).post.apply(a,arguments)},reAuthenticate:function reAuthenticate(){return hasInstance()&&singletonClient.getCSRFToken()},reset:function reset(){singletonClient=null}};exports.SupersetClient=SupersetClient,exports.default=PublicAPI; | ||
'use strict';var _promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise),_extends2=require('babel-runtime/helpers/extends'),_extends3=_interopRequireDefault(_extends2),_classCallCheck2=require('babel-runtime/helpers/classCallCheck'),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require('babel-runtime/helpers/createClass'),_createClass3=_interopRequireDefault(_createClass2),_callApi=require('./callApi'),_callApi2=_interopRequireDefault(_callApi);Object.defineProperty(exports,'__esModule',{value:!0}),exports.SupersetClient=void 0;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var SupersetClient=function(){function a(b){(0,_classCallCheck3.default)(this,a);var c=b.protocol,d=void 0===c?'http':c,e=b.host,f=void 0===e?'':e,g=b.headers,h=void 0===g?{}:g,i=b.mode,j=void 0===i?'same-origin':i,k=b.timeout,l=b.credentials;this.headers=h,this.host=f,this.mode=j,this.timeout=k,this.protocol=d,this.credentials=l,this.csrfToken=null,this.didAuthSuccessfully=!1,this.csrfPromise=null}return(0,_createClass3.default)(a,[{key:'isAuthenticated',value:function isAuthenticated(){return this.didAuthSuccessfully}},{key:'init',value:function init(){return this.getCSRFToken()}},{key:'getCSRFToken',value:function getCSRFToken(){var a=this;return this.csrfPromise=(0,_callApi2.default)({credentials:this.credentials,headers:(0,_extends3.default)({},this.headers),method:'GET',mode:this.mode,timeout:this.timeout,url:this.getUrl({endpoint:'superset/csrf_token/',host:this.host})}).then(function(b){return b.json&&(a.csrfToken=b.json.csrf_token,a.headers=(0,_extends3.default)({},a.headers,{"X-CSRFToken":a.csrfToken}),a.didAuthSuccessfully=!!a.csrfToken),a.csrfToken?b:_promise2.default.reject({error:'Failed to fetch CSRF token'})}),this.csrfPromise}},{key:'getUrl',value:function getUrl(a){var b=a.host,c=void 0===b?'':b,d=a.endpoint,e=void 0===d?'':d,f='/'===c.slice(-1)?c.slice(0,-1):c;return this.protocol+'://'+f+'/'+('/'===e[0]?e.slice(1):e)}},{key:'ensureAuth',value:function ensureAuth(){return this.csrfPromise||_promise2.default.reject({error:'SupersetClient has no CSRF token, ensure it is initialized or\n try logging into the Superset instance at '+this.getUrl('/login')})}},{key:'get',value:function get(a){var b=this,c=a.body,d=a.credentials,e=a.headers,f=a.host,g=a.endpoint,h=a.mode,i=a.parseMethod,j=a.signal,k=a.timeout,l=a.url;return this.ensureAuth().then(function(){return(0,_callApi2.default)({body:c,credentials:d||b.credentials,headers:(0,_extends3.default)({},b.headers,e),method:'GET',mode:h||b.mode,parseMethod:i,signal:j,timeout:k||b.timeout,url:l||b.getUrl({endpoint:g,host:f||b.host})})})}},{key:'post',value:function post(a){var b=this,c=a.credentials,d=a.headers,e=a.host,f=a.endpoint,g=a.mode,h=a.parseMethod,i=a.postPayload,j=a.signal,k=a.stringify,l=a.timeout,m=a.url;return this.ensureAuth().then(function(){return(0,_callApi2.default)({credentials:c||b.credentials,headers:(0,_extends3.default)({},b.headers,d),method:'POST',mode:g||b.mode,parseMethod:h,postPayload:i,signal:j,stringify:k,timeout:l||b.timeout,url:m||b.getUrl({endpoint:f,host:e||b.host})})})}}]),a}(),singletonClient=void 0;function hasInstance(){if(!singletonClient)throw new Error('You must call SupersetClient.configure(...) before calling other methods');return!0}var PublicAPI={configure:function configure(a){return singletonClient=new SupersetClient(a||{}),singletonClient},get:function get(){var a;return hasInstance()&&(a=singletonClient).get.apply(a,arguments)},init:function init(){return hasInstance()&&singletonClient.init()},isAuthenticated:function isAuthenticated(){return hasInstance()&&singletonClient.isAuthenticated()},post:function post(){var a;return hasInstance()&&(a=singletonClient).post.apply(a,arguments)},reAuthenticate:function reAuthenticate(){return hasInstance()&&singletonClient.getCSRFToken()},reset:function reset(){singletonClient=null}};exports.SupersetClient=SupersetClient,exports.default=PublicAPI; |
{ | ||
"name": "@superset-ui/core", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Superset UI core 🤖", | ||
@@ -43,3 +43,3 @@ "sideEffects": false, | ||
"devDependencies": { | ||
"@data-ui/build-config": "^0.0.12", | ||
"@data-ui/build-config": "^0.0.14", | ||
"fetch-mock": "^6.5.2", | ||
@@ -46,0 +46,0 @@ "node-fetch": "^2.2.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19006