@arsatir/superset-utils
v0.1.3
Published
Superset helper utilities for access token and guest token requests
Downloads
474
Readme
@arsatir/superset-utils
Small helper library for working with Apache Superset authentication flows, wrapped in a configurable SupersetClient class.
Installation
npm install @arsatir/superset-utilsSupersetClient
The main export is the SupersetClient class.
import { SupersetClient } from '@arsatir/superset-utils'
const client = new SupersetClient({
accessTokenUrl: 'https://superset.example.com/api/v1/security/login',
guestTokenUrl: 'https://superset.example.com/api/v1/security/guest_token',
defaultUsername: 'admin',
defaultPassword: 'admin',
defaultDashboardId: '12',
accessToken: 'ACCESS_TOKEN_IF_YOU_ALREADY_HAVE_ONE',
})Configuration
SupersetClient accepts the following configuration object:
export type SupersetClientConfig = {
accessToken?: string
defaultUsername?: string
defaultPassword?: string
defaultDashboardId?: string
accessTokenUrl?: string
guestTokenUrl?: string
}You can update the configuration at any time:
client.setConfig({ accessToken: 'NEW_ACCESS_TOKEN' })Methods
getValidAccessToken
Calls the Superset login endpoint using the configured or provided credentials.
const response = await client.getValidAccessToken()
// Override username / password / URL when needed
const response2 = await client.getValidAccessToken(
'other_user',
'other_password',
'https://custom-superset/api/v1/security/login',
)
if (!response.ok) {
throw new Error('Failed to get valid access token')
}
const data = await response.json()getValidGuestToken
Calls the Superset guest token endpoint to generate a guest token for a dashboard.
const response = await client.getValidGuestToken()
// Override dashboardId / accessToken / URL when needed
const response2 = await client.getValidGuestToken(
'34',
'OTHER_ACCESS_TOKEN',
'https://custom-superset/api/v1/security/guest_token',
)
if (!response.ok) {
throw new Error('Failed to get valid guest token')
}
const data = await response.json()Notes
- This package does not manage token storage or refresh; it only builds and executes the HTTP requests.
- You are expected to handle responses (
response.ok,response.json(), error handling, etc.) in your own code.
