Export SDK as a class to allow multiple instances

This commit is contained in:
Andrew Kingston 2022-09-21 19:12:25 +01:00
parent 3b4ca9e5b3
commit 1ec90ae770
1 changed files with 18 additions and 17 deletions

View File

@ -1,22 +1,23 @@
import * as BudibaseApi from "../sdk"
let ApiClient = new BudibaseApi.ApiClient()
export default class SDK {
applications = new BudibaseApi.ApplicationsApi()
queries = new BudibaseApi.QueriesApi()
rows = new BudibaseApi.RowsApi()
tables = new BudibaseApi.TablesApi()
users = new BudibaseApi.UsersApi()
// Default to current host
ApiClient.basePath = "/api/public/v1"
constructor({ apiKey, host }) {
let ApiClient = new BudibaseApi.ApiClient()
/**
* Configures the Budibase Public API SDK
* @param apiKey the user's API key
* @param host the Budibase server host
*/
export const configure = ({ apiKey, host }) => {
ApiClient.authentications["ApiKeyAuth"].apiKey = apiKey
ApiClient.basePath = `${host || ""}/api/public/v1`
// Default to current host
ApiClient.basePath = `${host || ""}/api/public/v1`
ApiClient.authentications["ApiKeyAuth"].apiKey = apiKey
this.applications = new BudibaseApi.ApplicationsApi(ApiClient)
this.queries = new BudibaseApi.QueriesApi(ApiClient)
this.rows = new BudibaseApi.RowsApi(ApiClient)
this.tables = new BudibaseApi.TablesApi(ApiClient)
this.users = new BudibaseApi.UsersApi(ApiClient)
}
}
export const ApplicationsApi = new BudibaseApi.ApplicationsApi(ApiClient)
export const QueriesApi = new BudibaseApi.QueriesApi(ApiClient)
export const RowsApi = new BudibaseApi.RowsApi(ApiClient)
export const TablesApi = new BudibaseApi.TablesApi(ApiClient)
export const UsersApi = new BudibaseApi.UsersApi(ApiClient)