@superset-ui/core
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -1,1 +0,5 @@ | ||
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';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)} | ||
import"core-js/modules/es6.array.iterator";import"core-js/modules/es6.object.keys";import"core-js/modules/web.dom.iterable";import"core-js/modules/es6.object.assign";import"whatwg-fetch";var DEFAULT_HEADERS=null;// This function fetches an API response and returns the corresponding json | ||
export default function callApi(a){var b=a.url,c=a.method,d=void 0===c?"GET":c,e=a.mode,f=void 0===e?"same-origin":e,g=a.cache,h=void 0===g?"default":g,i=a.credentials,j=void 0===i?"same-origin":i,k=a.headers,l=a.body,m=a.postPayload,n=a.stringify,o=a.redirect,p=void 0===o?"follow":o,q=a.signal,r={body:l,cache:h,credentials:j,headers:Object.assign({},DEFAULT_HEADERS,k),method:d,mode:f,redirect:p,signal:q};if("POST"===d&&"object"==typeof m){// using FormData has the effect that Content-Type header is set to `multipart/form-data`, | ||
// not e.g., 'application/x-www-form-urlencoded' | ||
var s=new FormData;Object.keys(m).forEach(function(a){var b=m[a];"undefined"!=typeof b&&s.append(a,!(void 0!==n)||n?JSON.stringify(m[a]):m[a])}),r=Object.assign({},r,{body:s})}return fetch(b,r);// eslint-disable-line compat/compat | ||
} |
@@ -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=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)} | ||
import"core-js/modules/es6.object.keys";import"core-js/modules/es6.promise";import"core-js/modules/web.dom.iterable";import"core-js/modules/es6.array.iterator";import"core-js/modules/es6.string.iterator";function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}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=_objectWithoutPropertiesLoose(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 @@ | ||
export{default}from'./callApiAndParseWithTimeout'; | ||
export{default}from"./callApiAndParseWithTimeout"; |
@@ -1,1 +0,1 @@ | ||
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(a)}).then(c)} | ||
import"core-js/modules/es6.promise";var PARSERS={json:function b(a){return a.json().then(function(b){return{json:b,response:a}})},text:function b(a){return a.text().then(function(b){return{response:a,text:b}})}};export default function parseResponse(a,b){if(void 0===b&&(b="json"),null===b)return a;var c=PARSERS[b]||PARSERS.json;return a.then(function(a){return a.ok?a:Promise.reject(a)}).then(c)} |
@@ -1,1 +0,2 @@ | ||
import _Promise from'babel-runtime/core-js/promise';export default function rejectAfterTimeout(a){return new _Promise(function(b,c){setTimeout(function(){return c({error:'Request timed out',statusText:'timeout'})},a)})} | ||
import"core-js/modules/es6.promise";// returns a Promise that rejects after the specified timeout | ||
export default function rejectAfterTimeout(a){return new Promise(function(b,c){setTimeout(function(){return c({error:"Request timed out",statusText:"timeout"})},a)})} |
@@ -1,1 +0,1 @@ | ||
export{default as callApi}from'./callApi';export{default as SupersetClient}from'./SupersetClient'; | ||
export{default as callApi}from"./callApi";export{default as SupersetClient}from"./SupersetClient"; |
@@ -1,1 +0,3 @@ | ||
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?'localhost':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+(':'===d.slice(-1)?'':':'),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.csrfToken=null,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=null!==a.csrfToken&&void 0!==a.csrfPromise),a.didAuthSuccessfully?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; | ||
import"core-js/modules/es6.object.assign";import"core-js/modules/es6.promise";import callApi from"./callApi";var singletonClient,SupersetClient=/*#__PURE__*/function(){function a(a){var b=a.protocol,c=void 0===b?"http:":b,d=a.host,e=void 0===d?"localhost":d,f=a.headers,g=void 0===f?{}:f,h=a.mode,i=void 0===h?"same-origin":h,j=a.timeout,k=a.credentials,l=a.csrfToken,m=void 0===l?null:l;this.headers=g,this.host=e,this.mode=i,this.timeout=j,this.protocol=""+c+(":"===c.slice(-1)?"":":"),this.credentials=k,this.csrfToken=m,this.csrfPromise=this.isAuthenticated()?Promise.resolve(this.csrfToken):null}var b=a.prototype;return b.isAuthenticated=function a(){// if CSRF protection is disabled in the Superset app, the token may be an empty string | ||
return null!==this.csrfToken&&void 0!==this.csrfToken},b.init=function b(a){return void 0===a&&(a=!1),this.isAuthenticated()&&!a?this.csrfPromise:this.getCSRFToken()},b.getCSRFToken=function b(){var a=this;return this.csrfToken=null,this.csrfPromise=callApi({credentials:this.credentials,headers:Object.assign({},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=Object.assign({},a.headers,{"X-CSRFToken":a.csrfToken})),a.isAuthenticated()?a.csrfToken:Promise.reject({error:"Failed to fetch CSRF token"})}),this.csrfPromise},b.getUrl=function g(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;// no backslash | ||
return this.protocol+"//"+f+"/"+("/"===e[0]?e.slice(1):e)},b.ensureAuth=function a(){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")})},b.get=function m(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:Object.assign({},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})})})},b.post=function n(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:Object.assign({},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}();function hasInstance(){if(!singletonClient)throw new Error("You must call SupersetClient.configure(...) before calling other methods");return(/* force = */!0)}var PublicAPI={configure:function b(a){return singletonClient=new SupersetClient(a||{}),singletonClient},get:function b(){var a;return hasInstance()&&(a=singletonClient).get.apply(a,arguments)},init:function b(a){return hasInstance()&&singletonClient.init(a)},isAuthenticated:function a(){return hasInstance()&&singletonClient.isAuthenticated()},post:function b(){var a;return hasInstance()&&(a=singletonClient).post.apply(a,arguments)},reAuthenticate:function a(){return hasInstance()&&singletonClient.init(!0)},reset:function a(){singletonClient=null}};export{SupersetClient};export default PublicAPI; |
@@ -1,1 +0,5 @@ | ||
'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');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)} | ||
"use strict";exports.__esModule=/* force = */!0,exports.default=callApi,require("core-js/modules/es6.array.iterator"),require("core-js/modules/es6.object.keys"),require("core-js/modules/web.dom.iterable"),require("core-js/modules/es6.object.assign"),require("whatwg-fetch");var DEFAULT_HEADERS=null;// This function fetches an API response and returns the corresponding json | ||
function callApi(a){var b=a.url,c=a.method,d=void 0===c?"GET":c,e=a.mode,f=void 0===e?"same-origin":e,g=a.cache,h=void 0===g?"default":g,i=a.credentials,j=void 0===i?"same-origin":i,k=a.headers,l=a.body,m=a.postPayload,n=a.stringify,o=a.redirect,p=void 0===o?"follow":o,q=a.signal,r={body:l,cache:h,credentials:j,headers:Object.assign({},DEFAULT_HEADERS,k),method:d,mode:f,redirect:p,signal:q};if("POST"===d&&"object"==typeof m){// using FormData has the effect that Content-Type header is set to `multipart/form-data`, | ||
// not e.g., 'application/x-www-form-urlencoded' | ||
var s=new FormData;Object.keys(m).forEach(function(a){var b=m[a];"undefined"!=typeof b&&s.append(a,!(void 0!==n)||n?JSON.stringify(m[a]):m[a])}),r=Object.assign({},r,{body:s})}return fetch(b,r);// eslint-disable-line compat/compat | ||
} |
@@ -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=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)} | ||
"use strict";exports.__esModule=/* force = */!0,exports.default=callApiAndParseWithTimeout,require("core-js/modules/es6.object.keys"),require("core-js/modules/es6.promise"),require("core-js/modules/web.dom.iterable"),require("core-js/modules/es6.array.iterator"),require("core-js/modules/es6.string.iterator");var _callApi=_interopRequireDefault(require("./callApi")),_rejectAfterTimeout=_interopRequireDefault(require("./rejectAfterTimeout")),_parseResponse=_interopRequireDefault(require("./parseResponse"));function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function callApiAndParseWithTimeout(a){var b=a.timeout,c=a.parseMethod,d=_objectWithoutPropertiesLoose(a,["timeout","parseMethod"]),e=(0,_callApi.default)(d),f="number"==typeof b&&0<b?Promise.race([(0,_rejectAfterTimeout.default)(b),e]):e;return(0,_parseResponse.default)(f,c)} |
@@ -1,1 +0,1 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var _callApiAndParseWithTimeout=require('./callApiAndParseWithTimeout');Object.defineProperty(exports,'default',{enumerable:!0,get:function get(){return _interopRequireDefault(_callApiAndParseWithTimeout).default}});function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}} | ||
"use strict";var _callApiAndParseWithTimeout=_interopRequireDefault(require("./callApiAndParseWithTimeout"));exports.__esModule=/* force = */!0,exports.default=void 0;exports.default=_callApiAndParseWithTimeout.default;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}} |
@@ -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}}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(a)}).then(c)} | ||
"use strict";exports.__esModule=/* force = */!0,exports.default=parseResponse,require("core-js/modules/es6.promise");var PARSERS={json:function b(a){return a.json().then(function(b){return{json:b,response:a}})},text:function b(a){return a.text().then(function(b){return{response:a,text:b}})}};function parseResponse(a,b){if(void 0===b&&(b="json"),null===b)return a;var c=PARSERS[b]||PARSERS.json;return a.then(function(a){return a.ok?a:Promise.reject(a)}).then(c)} |
@@ -1,1 +0,2 @@ | ||
'use strict';var _promise=require('babel-runtime/core-js/promise'),_promise2=_interopRequireDefault(_promise);Object.defineProperty(exports,'__esModule',{value:!0});exports.default=rejectAfterTimeout;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function rejectAfterTimeout(a){return new _promise2.default(function(b,c){setTimeout(function(){return c({error:'Request timed out',statusText:'timeout'})},a)})} | ||
"use strict";exports.__esModule=/* force = */!0,exports.default=rejectAfterTimeout,require("core-js/modules/es6.promise");// returns a Promise that rejects after the specified timeout | ||
function rejectAfterTimeout(a){return new Promise(function(b,c){setTimeout(function(){return c({error:"Request timed out",statusText:"timeout"})},a)})} |
@@ -1,1 +0,1 @@ | ||
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var _callApi=require('./callApi');Object.defineProperty(exports,'callApi',{enumerable:!0,get:function get(){return _interopRequireDefault(_callApi).default}});var _SupersetClient=require('./SupersetClient');Object.defineProperty(exports,'SupersetClient',{enumerable:!0,get:function get(){return _interopRequireDefault(_SupersetClient).default}});function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}} | ||
"use strict";var _callApi=_interopRequireDefault(require("./callApi"));var _SupersetClient=_interopRequireDefault(require("./SupersetClient"));exports.__esModule=/* force = */!0,exports.SupersetClient=exports.callApi=void 0;exports.callApi=_callApi.default;exports.SupersetClient=_SupersetClient.default;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}} |
@@ -1,1 +0,3 @@ | ||
'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?'localhost':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+(':'===d.slice(-1)?'':':'),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.csrfToken=null,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=null!==a.csrfToken&&void 0!==a.csrfPromise),a.didAuthSuccessfully?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; | ||
"use strict";var _callApi=_interopRequireDefault(require("./callApi"));exports.__esModule=/* force = */!0,exports.default=exports.SupersetClient=void 0,require("core-js/modules/es6.object.assign"),require("core-js/modules/es6.promise");function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}var SupersetClient=/*#__PURE__*/function(){function a(a){var b=a.protocol,c=void 0===b?"http:":b,d=a.host,e=void 0===d?"localhost":d,f=a.headers,g=void 0===f?{}:f,h=a.mode,i=void 0===h?"same-origin":h,j=a.timeout,k=a.credentials,l=a.csrfToken,m=void 0===l?null:l;this.headers=g,this.host=e,this.mode=i,this.timeout=j,this.protocol=""+c+(":"===c.slice(-1)?"":":"),this.credentials=k,this.csrfToken=m,this.csrfPromise=this.isAuthenticated()?Promise.resolve(this.csrfToken):null}var b=a.prototype;return b.isAuthenticated=function a(){// if CSRF protection is disabled in the Superset app, the token may be an empty string | ||
return null!==this.csrfToken&&void 0!==this.csrfToken},b.init=function b(a){return void 0===a&&(a=!1),this.isAuthenticated()&&!a?this.csrfPromise:this.getCSRFToken()},b.getCSRFToken=function b(){var a=this;return this.csrfToken=null,this.csrfPromise=(0,_callApi.default)({credentials:this.credentials,headers:Object.assign({},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=Object.assign({},a.headers,{"X-CSRFToken":a.csrfToken})),a.isAuthenticated()?a.csrfToken:Promise.reject({error:"Failed to fetch CSRF token"})}),this.csrfPromise},b.getUrl=function g(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;// no backslash | ||
return this.protocol+"//"+f+"/"+("/"===e[0]?e.slice(1):e)},b.ensureAuth=function a(){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")})},b.get=function m(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,_callApi.default)({body:c,credentials:d||b.credentials,headers:Object.assign({},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})})})},b.post=function n(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,_callApi.default)({credentials:c||b.credentials,headers:Object.assign({},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}();exports.SupersetClient=SupersetClient;var singletonClient;function hasInstance(){if(!singletonClient)throw new Error("You must call SupersetClient.configure(...) before calling other methods");return!0}var PublicAPI={configure:function b(a){return singletonClient=new SupersetClient(a||{}),singletonClient},get:function b(){var a;return hasInstance()&&(a=singletonClient).get.apply(a,arguments)},init:function b(a){return hasInstance()&&singletonClient.init(a)},isAuthenticated:function a(){return hasInstance()&&singletonClient.isAuthenticated()},post:function b(){var a;return hasInstance()&&(a=singletonClient).post.apply(a,arguments)},reAuthenticate:function a(){return hasInstance()&&singletonClient.init(!0)},reset:function a(){singletonClient=null}},_default=PublicAPI;exports.default=_default; |
{ | ||
"name": "@superset-ui/core", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Superset UI core 🤖", | ||
@@ -23,3 +23,2 @@ "sideEffects": false, | ||
"prettier": "beemo prettier \"./{src,test}/**/*.{js,jsx,json,md}\"", | ||
"sync:gitignore": "beemo sync-dotfiles --filter=gitignore", | ||
"prepublish": "yarn run build" | ||
@@ -44,3 +43,3 @@ }, | ||
"devDependencies": { | ||
"@data-ui/build-config": "^0.0.14", | ||
"@data-ui/build-config": "^0.0.23", | ||
"fetch-mock": "^6.5.2", | ||
@@ -50,3 +49,3 @@ "node-fetch": "^2.2.0" | ||
"dependencies": { | ||
"babel-runtime": "^6.26.0", | ||
"@babel/runtime": "^7.1.2", | ||
"whatwg-fetch": "^2.0.4" | ||
@@ -71,6 +70,5 @@ }, | ||
} | ||
}, | ||
"jest": {} | ||
} | ||
}, | ||
"gitHead": "227109c4511d65dc8001d9b8ac6c0af54dabd986" | ||
"gitHead": "005723f9d496e341ac025e179bf226d514a9912c" | ||
} |
@@ -17,5 +17,7 @@ ## `@superset-ui/core` | ||
- `CSRF` token authentication | ||
- queues requests in the case that another request is made before the token is received | ||
- it checks for a token before every request, an external app that uses this can detect this by | ||
catching errors, or explicitly checking `SupersetClient.isAuthorized()` | ||
- a token may be passed at configuration time, else the client will handle fetching and passing | ||
the token in all subsequent requests. | ||
- queues requests in the case that another request is made before the token is received. | ||
- it checks for a token before every request, and will fail if no token was received or if it has | ||
expired. In either case the user should be directed to re-authenticate. | ||
- supports `GET` and `POST` requests (no `PUT` or `DELETE`) | ||
@@ -50,3 +52,3 @@ - timeouts | ||
- `protocol = 'http'` | ||
- `protocol = 'http:'` | ||
- `host` | ||
@@ -57,2 +59,4 @@ - `headers` | ||
- `timeout` | ||
- `csrfToken` you can configure the client with a CSRF token at configuration time, else the client | ||
will attempt to fetch this before any other requests are issued | ||
@@ -59,0 +63,0 @@ ##### Per-request Configuration |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances 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
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances in 1 package
29
7
95
2
18401
+ Added@babel/runtime@^7.1.2
+ Added@babel/runtime@7.26.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)
- Removedbabel-runtime@^6.26.0
- Removedbabel-runtime@6.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedregenerator-runtime@0.11.1(transitive)