2022-09-27 04:54:14 +13:00
|
|
|
import {
|
|
|
|
Application,
|
|
|
|
} from "@budibase/server/api/controllers/public/mapping/types"
|
2022-10-01 03:03:38 +13:00
|
|
|
import { App } from "@budibase/types"
|
2022-09-27 04:54:14 +13:00
|
|
|
import { Response } from "node-fetch"
|
|
|
|
import InternalAPIClient from "./InternalAPIClient"
|
|
|
|
|
|
|
|
export default class AppApi {
|
|
|
|
api: InternalAPIClient
|
|
|
|
|
|
|
|
constructor(apiClient: InternalAPIClient) {
|
|
|
|
this.api = apiClient
|
|
|
|
}
|
|
|
|
|
2022-09-29 06:21:05 +13:00
|
|
|
async fetch(): Promise<[Response, Application[]]> {
|
|
|
|
const response = await this.api.get(`/applications?status=all`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
2022-10-01 03:03:38 +13:00
|
|
|
async canRender(appId: string): Promise<[Response, string]> {
|
|
|
|
const response = await this.api.get(`/${appId}`, {})
|
|
|
|
const html = await response.text()
|
|
|
|
return [response, html]
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAppPackage(appId: string): Promise<[Response, any]> {
|
|
|
|
const response = await this.api.get(`/applications/${appId}/appPackage`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: 500 Error: Missing/invalid DB name when called
|
|
|
|
async publish(): Promise<[Response, string]> {
|
|
|
|
const response = await this.api.post("/deploy")
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
2022-09-27 04:54:14 +13:00
|
|
|
async create(
|
|
|
|
body: any
|
2022-10-01 03:03:38 +13:00
|
|
|
): Promise<[Response, Partial<App>]> {
|
2022-09-27 04:54:14 +13:00
|
|
|
const response = await this.api.post(`/applications`, { body })
|
|
|
|
const json = await response.json()
|
2022-09-29 06:21:05 +13:00
|
|
|
return [response, json]
|
2022-09-27 04:54:14 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
async read(id: string): Promise<[Response, Application]> {
|
|
|
|
const response = await this.api.get(`/applications/${id}`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json.data]
|
|
|
|
}
|
|
|
|
}
|