2022-10-04 22:59:53 +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"
|
2022-10-01 03:35:13 +13:00
|
|
|
import FormData from "form-data"
|
2022-09-27 04:54:14 +13:00
|
|
|
|
|
|
|
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:35:13 +13:00
|
|
|
async canRender(): Promise<[Response, boolean]> {
|
|
|
|
const response = await this.api.get("/routing/client")
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, Object.keys(json.routes).length > 0]
|
2022-10-01 03:03:38 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
async getAppPackage(appId: string): Promise<[Response, any]> {
|
|
|
|
const response = await this.api.get(`/applications/${appId}/appPackage`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
2022-10-08 06:05:58 +13:00
|
|
|
async publish(): Promise<[Response, any]> {
|
2022-10-01 03:03:38 +13:00
|
|
|
const response = await this.api.post("/deploy")
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
2022-10-04 22:59:53 +13:00
|
|
|
async create(body: any): Promise<[Response, Partial<App>]> {
|
2022-10-01 14:54:51 +13:00
|
|
|
const response = await this.api.post(`/applications`, { body })
|
2022-09-27 04:54:14 +13:00
|
|
|
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]
|
|
|
|
}
|
2022-10-05 04:11:19 +13:00
|
|
|
|
|
|
|
async sync(appId: string): Promise<[Response, any]> {
|
|
|
|
const response = await this.api.post(`/applications/${appId}/sync`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
2022-10-08 00:19:00 +13:00
|
|
|
async updateClient(appId: string, body: any): Promise<[Response, Application]> {
|
2022-10-05 05:12:38 +13:00
|
|
|
const response = await this.api.put(`/applications/${appId}/client/update`, { body })
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
|
|
|
async revert(appId: string): Promise<[Response, Application]> {
|
|
|
|
const response = await this.api.post(`/applications/${appId}/client/revert`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete(appId: string): Promise<[Response, any]> {
|
|
|
|
const response = await this.api.del(`/applications/${appId}`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAppDefinition(appId: string): Promise<[Response, any]> {
|
|
|
|
const response = await this.api.get(`/applications/${appId}/definition`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
2022-10-08 00:19:00 +13:00
|
|
|
async update(appId: string, body: any): Promise<[Response, Application]> {
|
|
|
|
const response = await this.api.put(`/applications/${appId}`, { body })
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
2022-10-08 06:05:58 +13:00
|
|
|
async addScreentoApp(body: any): Promise<[Response, Application]> {
|
2022-10-08 00:19:00 +13:00
|
|
|
|
2022-10-08 06:05:58 +13:00
|
|
|
const response = await this.api.post(`/screens`, { body })
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
|
|
|
|
|
|
|
async getRoutes(): Promise<[Response, any]> {
|
|
|
|
const response = await this.api.get(`/routing`)
|
|
|
|
const json = await response.json()
|
|
|
|
return [response, json]
|
|
|
|
}
|
2022-10-05 05:12:38 +13:00
|
|
|
|
2022-09-27 04:54:14 +13:00
|
|
|
}
|