Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@superset-ui/connection

Package Overview
Dependencies
Maintainers
6
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@superset-ui/connection - npm Package Compare versions

Comparing version 0.7.2 to 0.8.0

esm/SupersetClientClass.js

7

esm/callApi/callApi.js

@@ -1,5 +0,4 @@

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
import"whatwg-fetch";// This function fetches an API response and returns the corresponding json
export default function callApi(a){var b=a.body,c=a.cache,d=void 0===c?"default":c,e=a.credentials,f=void 0===e?"same-origin":e,g=a.headers,h=a.method,i=void 0===h?"GET":h,j=a.mode,k=void 0===j?"same-origin":j,l=a.postPayload,m=a.redirect,n=void 0===m?"follow":m,o=a.signal,p=a.stringify,q=a.url,r={body:b,cache:d,credentials:f,headers:g,method:i,mode:k,redirect:n,signal:o};if("POST"===i&&"object"==typeof l){// using FormData has the effect that Content-Type header is set to `multipart/form-data`,
var s=new FormData;Object.keys(l).forEach(function(a){var b=l[a];"undefined"!=typeof b&&s.append(a,!(void 0!==p)||p?JSON.stringify(b):b)}),r.body=s}return fetch(q,r);// eslint-disable-line compat/compat
}

@@ -1,1 +0,1 @@

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)}
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,2 @@

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)}
import JSONbig from"json-bigint";function rejectIfNotOkay(a){return a.ok?Promise.resolve(a):Promise.reject(a)}function parseJson(a){try{return JSONbig.parse(a)}catch(a){// if JSONbig.parse fails, it throws an object (not a proper Error), so let's re-wrap the message.
throw new Error(a.message)}}export default function parseResponse(a,b){void 0===b&&(b="json");var c=a.then(rejectIfNotOkay);if(null===b)return a.then(rejectIfNotOkay);if("text"===b)return c.then(function(a){return a.text().then(function(b){return{response:a,text:b}})});if("json"===b)return c.then(function(a){return a.text().then(function(b){return{json:parseJson(b),response:a}})});throw new Error("Expected parseResponse=null|json|text, got '"+b+"'.")}

@@ -1,2 +0,2 @@

import"core-js/modules/es6.promise";// returns a Promise that rejects after the specified timeout
// 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*from"./types";
export{default as callApi}from"./callApi";export{default as SupersetClient,SupersetClientInterface}from"./SupersetClient";export{SupersetClientClass}from"./SupersetClientClass";export*from"./types";

@@ -1,3 +0,1 @@

import"core-js/modules/es6.promise";import"core-js/modules/es6.object.assign";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=Object.assign({},g,{"X-CSRFToken":m}),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;
import{SupersetClientClass}from"./SupersetClientClass";var singletonClient;function getInstance(a){if(!a)throw new Error("You must call SupersetClient.configure(...) before calling other methods");return a}var SupersetClient={configure:function b(a){return singletonClient=new SupersetClientClass(a),singletonClient},get:function b(a){return getInstance(singletonClient).get(a)},getInstance:getInstance,init:function b(a){return getInstance(singletonClient).init(a)},isAuthenticated:function a(){return getInstance(singletonClient).isAuthenticated()},post:function b(a){return getInstance(singletonClient).post(a)},reAuthenticate:function a(){return getInstance(singletonClient).init(/* force = */!0)},reset:function a(){singletonClient=void 0}};export default SupersetClient;

@@ -1,30 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("whatwg-fetch");
// This function fetches an API response and returns the corresponding json
function callApi({ body, cache = 'default', credentials = 'same-origin', headers, method = 'GET', mode = 'same-origin', postPayload, redirect = 'follow', signal, stringify = true, url, }) {
const request = {
body,
cache,
credentials,
headers,
method,
mode,
redirect,
signal,
};
if (method === 'POST' && typeof postPayload === 'object') {
// using FormData has the effect that Content-Type header is set to `multipart/form-data`,
// not e.g., 'application/x-www-form-urlencoded'
const formData = new FormData();
Object.keys(postPayload).forEach(key => {
const value = postPayload[key];
if (typeof value !== 'undefined') {
formData.append(key, stringify ? JSON.stringify(value) : value);
}
});
request.body = formData;
}
return fetch(url, request); // eslint-disable-line compat/compat
}
exports.default = callApi;
"use strict";exports.__esModule=/* force = */!0,exports.default=callApi,require("whatwg-fetch");// This function fetches an API response and returns the corresponding json
function callApi(a){var b=a.body,c=a.cache,d=void 0===c?"default":c,e=a.credentials,f=void 0===e?"same-origin":e,g=a.headers,h=a.method,i=void 0===h?"GET":h,j=a.mode,k=void 0===j?"same-origin":j,l=a.postPayload,m=a.redirect,n=void 0===m?"follow":m,o=a.signal,p=a.stringify,q=a.url,r={body:b,cache:d,credentials:f,headers:g,method:i,mode:k,redirect:n,signal:o};if("POST"===i&&"object"==typeof l){// using FormData has the effect that Content-Type header is set to `multipart/form-data`,
var s=new FormData;Object.keys(l).forEach(function(a){var b=l[a];"undefined"!=typeof b&&s.append(a,!(void 0!==p)||p?JSON.stringify(b):b)}),r.body=s}return fetch(q,r);// eslint-disable-line compat/compat
}

@@ -1,16 +0,1 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const callApi_1 = __importDefault(require("./callApi"));
const rejectAfterTimeout_1 = __importDefault(require("./rejectAfterTimeout"));
const parseResponse_1 = __importDefault(require("./parseResponse"));
function callApiAndParseWithTimeout({ timeout, parseMethod, ...rest }) {
const apiPromise = callApi_1.default(rest);
const racedPromise = typeof timeout === 'number' && timeout > 0
? Promise.race([rejectAfterTimeout_1.default(timeout), apiPromise])
: apiPromise;
return parseResponse_1.default(racedPromise, parseMethod);
}
exports.default = callApiAndParseWithTimeout;
"use strict";exports.__esModule=/* force = */!0,exports.default=callApiAndParseWithTimeout;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,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var callApiAndParseWithTimeout_1 = require("./callApiAndParseWithTimeout");
exports.default = callApiAndParseWithTimeout_1.default;
"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,21 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function rejectIfNotOkay(response) {
if (!response.ok)
return Promise.reject(response);
return Promise.resolve(response);
}
function parseResponse(apiPromise, parseMethod = 'json') {
const checkedPromise = apiPromise.then(rejectIfNotOkay);
if (parseMethod === null) {
return checkedPromise;
}
else if (parseMethod === 'text') {
return checkedPromise.then(response => response.text().then(text => ({ response, text })));
}
else if (parseMethod === 'json') {
return checkedPromise.then(response => response.json().then(json => ({ json, response })));
}
throw new Error(`Expected parseResponse=null|json|text, got '${parseMethod}'.`);
}
exports.default = parseResponse;
"use strict";var _jsonBigint=_interopRequireDefault(require("json-bigint"));exports.__esModule=/* force = */!0,exports.default=parseResponse;function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function rejectIfNotOkay(a){return a.ok?Promise.resolve(a):Promise.reject(a)}function parseJson(a){try{return _jsonBigint.default.parse(a)}catch(a){// if JSONbig.parse fails, it throws an object (not a proper Error), so let's re-wrap the message.
throw new Error(a.message)}}function parseResponse(a,b){void 0===b&&(b="json");var c=a.then(rejectIfNotOkay);if(null===b)return a.then(rejectIfNotOkay);if("text"===b)return c.then(function(a){return a.text().then(function(b){return{response:a,text:b}})});if("json"===b)return c.then(function(a){return a.text().then(function(b){return{json:parseJson(b),response:a}})});throw new Error("Expected parseResponse=null|json|text, got '"+b+"'.")}

@@ -1,12 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// returns a Promise that rejects after the specified timeout
function rejectAfterTimeout(timeout) {
return new Promise((resolve, reject) => {
setTimeout(() => reject({
error: 'Request timed out',
statusText: 'timeout',
}), timeout);
});
}
exports.default = rejectAfterTimeout;
"use strict";exports.__esModule=/* force = */!0,exports.default=rejectAfterTimeout;// 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";var _exportNames={callApi:!0,SupersetClient:!0};var _callApi=_interopRequireDefault(require("./callApi"));var _SupersetClient=_interopRequireDefault(require("./SupersetClient"));var _types=require("./types");require("core-js/modules/es6.array.iterator"),require("core-js/modules/es6.object.keys"),require("core-js/modules/web.dom.iterable"),exports.__esModule=!0;exports.SupersetClient=exports.callApi=void 0;exports.callApi=_callApi.default;exports.SupersetClient=_SupersetClient.default;Object.keys(_types).forEach(function(a){"default"===a||"__esModule"===a||Object.prototype.hasOwnProperty.call(_exportNames,a)||(exports[a]=_types[a])});function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}
"use strict";var _exportNames={callApi:/* force = */!0,SupersetClient:!0,SupersetClientInterface:!0,SupersetClientClass:!0};var _callApi=_interopRequireDefault(require("./callApi"));var _SupersetClient=_interopRequireWildcard(require("./SupersetClient"));var _SupersetClientClass=require("./SupersetClientClass");var _types=require("./types");exports.__esModule=!0;exports.SupersetClientClass=exports.SupersetClientInterface=exports.SupersetClient=exports.callApi=void 0;exports.callApi=_callApi.default;exports.SupersetClient=_SupersetClient.default,exports.SupersetClientInterface=_SupersetClient.SupersetClientInterface;exports.SupersetClientClass=_SupersetClientClass.SupersetClientClass;Object.keys(_types).forEach(function(a){"default"===a||"__esModule"===a||Object.prototype.hasOwnProperty.call(_exportNames,a)||(exports[a]=_types[a])});function _interopRequireWildcard(a){if(a&&a.__esModule)return a;var b={};if(null!=a)for(var c in a)if(Object.prototype.hasOwnProperty.call(a,c)){var d=Object.defineProperty&&Object.getOwnPropertyDescriptor?Object.getOwnPropertyDescriptor(a,c):{};d.get||d.set?Object.defineProperty(b,c,d):b[c]=a[c]}return b.default=a,b}function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}

@@ -1,46 +0,14 @@

import { ClientTimeout, Credentials, Headers, Host, Mode, SupersetClientResponse, RequestConfig } from './types';
declare type CsrfToken = string;
declare type CsrfPromise = Promise<string | undefined>;
declare type Protocol = 'http:' | 'https:';
export interface ClientConfig {
credentials?: Credentials;
csrfToken?: CsrfToken;
headers?: Headers;
host?: Host;
protocol?: Protocol;
mode?: Mode;
timeout?: ClientTimeout;
}
declare class SupersetClient {
credentials: Credentials;
csrfToken: CsrfToken | undefined;
csrfPromise: CsrfPromise;
protocol: Protocol;
host: Host;
headers: Headers;
mode: Mode;
timeout: ClientTimeout;
constructor({ protocol, host, headers, mode, timeout, credentials, csrfToken, }?: ClientConfig);
init(force?: boolean): Promise<string | undefined>;
isAuthenticated(): boolean;
get({ body, credentials, headers, host, endpoint, mode, parseMethod, signal, timeout, url, }: RequestConfig): Promise<SupersetClientResponse>;
post({ credentials, endpoint, headers, host, mode, parseMethod, postPayload, signal, stringify, timeout, url, }: RequestConfig): Promise<SupersetClientResponse>;
ensureAuth(): Promise<string | undefined>;
getCSRFToken(): Promise<string | undefined>;
getUrl({ host: inputHost, endpoint, url, }?: {
endpoint?: string;
host?: Host;
url?: string;
}): string;
}
declare const PublicAPI: {
configure: (config?: ClientConfig) => SupersetClient;
get: (request: RequestConfig) => false | Promise<SupersetClientResponse>;
init: (force?: boolean | undefined) => false | Promise<string | undefined>;
import { ClientConfig, SupersetClientClass } from './SupersetClientClass';
import { RequestConfig, SupersetClientResponse } from './types';
export interface SupersetClientInterface {
configure: (config?: ClientConfig) => SupersetClientClass;
get: (request: RequestConfig) => Promise<SupersetClientResponse>;
getInstance: (maybeClient?: SupersetClientClass) => SupersetClientClass;
init: (force?: boolean) => Promise<string | undefined>;
isAuthenticated: () => boolean;
post: (request: RequestConfig) => false | Promise<SupersetClientResponse>;
reAuthenticate: () => false | Promise<string | undefined>;
post: (request: RequestConfig) => Promise<SupersetClientResponse>;
reAuthenticate: () => Promise<string | undefined>;
reset: () => void;
};
export { SupersetClient };
export default PublicAPI;
}
declare const SupersetClient: SupersetClientInterface;
export default SupersetClient;

@@ -1,124 +0,1 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const callApi_1 = __importDefault(require("./callApi"));
class SupersetClient {
constructor({ protocol = 'http:', host = 'localhost', headers = {}, mode = 'same-origin', timeout, credentials = undefined, csrfToken = undefined, } = {}) {
this.headers = { ...headers };
this.host = host;
this.mode = mode;
this.timeout = timeout;
this.protocol = protocol;
this.credentials = credentials;
this.csrfToken = csrfToken;
this.csrfPromise = Promise.reject({
error: `SupersetClient has no CSRF token, ensure it is initialized or
try logging into the Superset instance at ${this.getUrl({
endpoint: '/login',
})}`,
});
if (typeof this.csrfToken === 'string') {
this.headers = { ...this.headers, 'X-CSRFToken': this.csrfToken };
this.csrfPromise = Promise.resolve(this.csrfToken);
}
}
init(force = false) {
if (this.isAuthenticated() && !force) {
return this.csrfPromise;
}
return this.getCSRFToken();
}
isAuthenticated() {
// if CSRF protection is disabled in the Superset app, the token may be an empty string
return this.csrfToken !== null && this.csrfToken !== undefined;
}
async get({ body, credentials, headers, host, endpoint, mode, parseMethod, signal, timeout, url, }) {
return this.ensureAuth().then(() => callApi_1.default({
body,
credentials: credentials || this.credentials,
headers: { ...this.headers, ...headers },
method: 'GET',
mode: mode || this.mode,
parseMethod,
signal,
timeout: timeout || this.timeout,
url: this.getUrl({ endpoint, host, url }),
}));
}
async post({ credentials, endpoint, headers, host, mode, parseMethod, postPayload, signal, stringify, timeout, url, }) {
return this.ensureAuth().then(() => callApi_1.default({
credentials: credentials || this.credentials,
headers: { ...this.headers, ...headers },
method: 'POST',
mode: mode || this.mode,
parseMethod,
postPayload,
signal,
stringify,
timeout: timeout || this.timeout,
url: this.getUrl({ endpoint, host, url }),
}));
}
ensureAuth() {
return this.csrfPromise;
}
async getCSRFToken() {
this.csrfToken = undefined;
// If we can request this resource successfully, it means that the user has
// authenticated. If not we throw an error prompting to authenticate.
this.csrfPromise = callApi_1.default({
credentials: this.credentials,
headers: {
...this.headers,
},
method: 'GET',
mode: this.mode,
timeout: this.timeout,
url: this.getUrl({ endpoint: 'superset/csrf_token/' }),
}).then(response => {
if (typeof response.json === 'object') {
this.csrfToken = response.json.csrf_token;
if (typeof this.csrfToken === 'string') {
this.headers = { ...this.headers, 'X-CSRFToken': this.csrfToken };
}
}
if (!this.isAuthenticated()) {
return Promise.reject({ error: 'Failed to fetch CSRF token' });
}
return Promise.resolve(this.csrfToken);
});
return this.csrfPromise;
}
getUrl({ host: inputHost, endpoint = '', url, } = {}) {
if (typeof url === 'string')
return url;
const host = inputHost || this.host;
const cleanHost = host.slice(-1) === '/' ? host.slice(0, -1) : host; // no backslash
return `${this.protocol}//${cleanHost}/${endpoint[0] === '/' ? endpoint.slice(1) : endpoint}`;
}
}
exports.SupersetClient = SupersetClient;
let singletonClient;
function hasInstance(maybeClient) {
if (!maybeClient) {
throw new Error('You must call SupersetClient.configure(...) before calling other methods');
}
return true;
}
const PublicAPI = {
configure: (config = {}) => {
singletonClient = new SupersetClient(config);
return singletonClient;
},
get: (request) => hasInstance(singletonClient) && singletonClient.get(request),
init: (force) => hasInstance(singletonClient) && singletonClient.init(force),
isAuthenticated: () => hasInstance(singletonClient) && singletonClient.isAuthenticated(),
post: (request) => hasInstance(singletonClient) && singletonClient.post(request),
reAuthenticate: () => hasInstance(singletonClient) && singletonClient.init(/* force = */ true),
reset: () => {
singletonClient = undefined;
},
};
exports.default = PublicAPI;
"use strict";exports.__esModule=/* force = */!0,exports.default=void 0;var singletonClient,_SupersetClientClass=require("./SupersetClientClass");function getInstance(a){if(!a)throw new Error("You must call SupersetClient.configure(...) before calling other methods");return a}var SupersetClient={configure:function b(a){return singletonClient=new _SupersetClientClass.SupersetClientClass(a),singletonClient},get:function b(a){return getInstance(singletonClient).get(a)},getInstance:getInstance,init:function b(a){return getInstance(singletonClient).init(a)},isAuthenticated:function a(){return getInstance(singletonClient).isAuthenticated()},post:function b(a){return getInstance(singletonClient).post(a)},reAuthenticate:function a(){return getInstance(singletonClient).init(!0)},reset:function a(){singletonClient=void 0}},_default=SupersetClient;exports.default=_default;

@@ -19,3 +19,3 @@ export declare type Body = RequestInit['body'];

export declare type ClientTimeout = number | undefined;
export declare type ParseMethod = 'json' | 'text';
export declare type ParseMethod = 'json' | 'text' | null;
export declare type Signal = RequestInit['signal'];

@@ -22,0 +22,0 @@ export declare type Stringify = boolean;

@@ -1,2 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
"use strict";
{
"name": "@superset-ui/connection",
"version": "0.7.2",
"version": "0.8.0",
"description": "Superset UI connection",

@@ -29,2 +29,3 @@ "sideEffects": false,

"devDependencies": {
"@types/fetch-mock": "^6.0.0",
"fetch-mock": "^6.5.2",

@@ -35,2 +36,3 @@ "node-fetch": "^2.2.0"

"@babel/runtime": "^7.1.2",
"json-bigint": "^0.3.0",
"whatwg-fetch": "^2.0.4"

@@ -41,3 +43,3 @@ },

},
"gitHead": "c7dd6305013a152ba59418c0af9c334126a2689f"
"gitHead": "48b5ede60e10999881b18dcaa1378640791bcdc8"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc