2024-12-03 10:46:34 +01:00
|
|
|
import {
|
|
|
|
CreatePluginRequest,
|
|
|
|
CreatePluginResponse,
|
2024-12-05 16:40:33 +01:00
|
|
|
DeletePluginResponse,
|
|
|
|
FetchPluginResponse,
|
|
|
|
UploadPluginRequest,
|
|
|
|
UploadPluginResponse,
|
2024-12-03 10:46:34 +01:00
|
|
|
} from "@budibase/types"
|
|
|
|
import { BaseAPIClient } from "./types"
|
|
|
|
|
|
|
|
export interface PluginEndpoins {
|
2024-12-05 16:40:33 +01:00
|
|
|
uploadPlugin: (data: UploadPluginRequest) => Promise<UploadPluginResponse>
|
2024-12-03 10:46:34 +01:00
|
|
|
createPlugin: (data: CreatePluginRequest) => Promise<CreatePluginResponse>
|
2024-12-05 16:40:33 +01:00
|
|
|
getPlugins: () => Promise<FetchPluginResponse>
|
|
|
|
deletePlugin: (pluginId: string) => Promise<DeletePluginResponse>
|
2024-12-03 10:46:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const buildPluginEndpoints = (API: BaseAPIClient): PluginEndpoins => ({
|
2022-08-11 11:37:57 +02:00
|
|
|
/**
|
|
|
|
* Uploads a plugin tarball bundle
|
|
|
|
* @param data the plugin tarball bundle to upload
|
|
|
|
*/
|
2022-09-06 11:37:49 +02:00
|
|
|
uploadPlugin: async data => {
|
2022-08-11 11:37:57 +02:00
|
|
|
return await API.post({
|
2022-09-06 11:37:49 +02:00
|
|
|
url: `/api/plugin/upload`,
|
2022-08-11 11:37:57 +02:00
|
|
|
body: data,
|
|
|
|
json: false,
|
|
|
|
})
|
|
|
|
},
|
2022-08-11 16:28:19 +02:00
|
|
|
|
2022-08-30 22:37:08 +02:00
|
|
|
/**
|
|
|
|
* Creates a plugin from URL, Github or NPM
|
|
|
|
*/
|
|
|
|
createPlugin: async data => {
|
|
|
|
return await API.post({
|
|
|
|
url: `/api/plugin`,
|
|
|
|
body: data,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2022-08-11 16:28:19 +02:00
|
|
|
/**
|
|
|
|
* Gets a list of all plugins
|
|
|
|
*/
|
|
|
|
getPlugins: async () => {
|
|
|
|
return await API.get({
|
|
|
|
url: "/api/plugin",
|
|
|
|
})
|
|
|
|
},
|
2022-08-30 11:49:19 +02:00
|
|
|
|
|
|
|
/**
|
2022-08-30 11:50:25 +02:00
|
|
|
* Deletes a plugin.
|
|
|
|
* @param pluginId the ID of the plugin to delete
|
|
|
|
*
|
|
|
|
* * @param pluginId the revision of the plugin to delete
|
|
|
|
*/
|
2022-09-12 18:43:13 +02:00
|
|
|
deletePlugin: async pluginId => {
|
2022-08-30 11:49:19 +02:00
|
|
|
return await API.delete({
|
2022-09-12 18:43:13 +02:00
|
|
|
url: `/api/plugin/${pluginId}`,
|
2022-08-30 11:49:19 +02:00
|
|
|
})
|
|
|
|
},
|
2022-08-11 11:37:57 +02:00
|
|
|
})
|