Add missing API client documentation and fix S3 upload endpoints to make them consistent

This commit is contained in:
Andrew Kingston 2022-01-25 16:54:55 +00:00
parent 48c3c7852a
commit cfa02f88f6
8 changed files with 44 additions and 7 deletions

View File

@ -71,7 +71,12 @@
const upload = async () => { const upload = async () => {
loading = true loading = true
try { try {
const res = await API.externalUpload(datasourceId, bucket, key, data) const res = await API.externalUpload({
datasourceId,
bucket,
key,
data,
})
notificationStore.actions.success("File uploaded successfully") notificationStore.actions.success("File uploaded successfully")
loading = false loading = false
return res return res

View File

@ -1,6 +1,7 @@
export const buildAppEndpoints = API => ({ export const buildAppEndpoints = API => ({
/** /**
* Fetches screen definition for an app. * Fetches screen definition for an app.
* @param appId the ID of the app to fetch from
*/ */
fetchAppPackage: async appId => { fetchAppPackage: async appId => {
return await API.get({ return await API.get({

View File

@ -26,8 +26,11 @@ export const buildAttachmentEndpoints = API => ({
/** /**
* Generates a signed URL to upload a file to an external datasource. * Generates a signed URL to upload a file to an external datasource.
* @param datasourceId the ID of the datasource to upload to
* @param bucket the name of the bucket to upload to
* @param key the name of the file to upload to
*/ */
getSignedDatasourceURL: async (datasourceId, bucket, key) => { getSignedDatasourceURL: async ({ datasourceId, bucket, key }) => {
return await API.post({ return await API.post({
url: `/api/attachments/${datasourceId}/url`, url: `/api/attachments/${datasourceId}/url`,
body: { bucket, key }, body: { bucket, key },
@ -36,13 +39,17 @@ export const buildAttachmentEndpoints = API => ({
/** /**
* Uploads a file to an external datasource. * Uploads a file to an external datasource.
* @param datasourceId the ID of the datasource to upload to
* @param bucket the name of the bucket to upload to
* @param key the name of the file to upload to
* @param data the file to upload
*/ */
externalUpload: async (datasourceId, bucket, key, data) => { externalUpload: async ({ datasourceId, bucket, key, data }) => {
const { signedUrl, publicUrl } = await API.getSignedDatasourceURL( const { signedUrl, publicUrl } = await API.getSignedDatasourceURL({
datasourceId, datasourceId,
bucket, bucket,
key key,
) })
await API.put({ await API.put({
url: signedUrl, url: signedUrl,
body: data, body: data,

View File

@ -1,6 +1,8 @@
export const buildAutomationEndpoints = API => ({ export const buildAutomationEndpoints = API => ({
/** /**
* Executes an automation. Must have "App Action" trigger. * Executes an automation. Must have "App Action" trigger.
* @param automationId the ID of the automation to trigger
* @param fields the fields to trigger the automation with
*/ */
triggerAutomation: async ({ automationId, fields }) => { triggerAutomation: async ({ automationId, fields }) => {
return await API.post({ return await API.post({

View File

@ -1,6 +1,9 @@
export const buildRelationshipEndpoints = API => ({ export const buildRelationshipEndpoints = API => ({
/** /**
* Fetches related rows for a certain field of a certain row. * Fetches related rows for a certain field of a certain row.
* @param tableId the ID of the table to fetch from
* @param rowId the ID of the row to fetch related rows for
* @param fieldName the name of the relationship field
*/ */
fetchRelationshipData: async ({ tableId, rowId, fieldName }) => { fetchRelationshipData: async ({ tableId, rowId, fieldName }) => {
if (!tableId || !rowId) { if (!tableId || !rowId) {

View File

@ -8,6 +8,9 @@ export const buildRouteEndpoints = API => ({
}) })
}, },
/**
* Fetches all routes for the current app.
*/
fetchAppRoutes: async () => { fetchAppRoutes: async () => {
return await API.get({ return await API.get({
url: "/api/routing", url: "/api/routing",

View File

@ -1,6 +1,8 @@
export const buildRowEndpoints = API => ({ export const buildRowEndpoints = API => ({
/** /**
* Fetches data about a certain row in a table. * Fetches data about a certain row in a table.
* @param tableId the ID of the table to fetch from
* @param rowId the ID of the row to fetch
*/ */
fetchRow: async ({ tableId, rowId }) => { fetchRow: async ({ tableId, rowId }) => {
if (!tableId || !rowId) { if (!tableId || !rowId) {
@ -13,7 +15,8 @@ export const buildRowEndpoints = API => ({
}, },
/** /**
* Creates a row in a table. * Creates or updates a row in a table.
* @param row the row to save
*/ */
saveRow: async row => { saveRow: async row => {
if (!row?.tableId) { if (!row?.tableId) {
@ -27,6 +30,9 @@ export const buildRowEndpoints = API => ({
/** /**
* Deletes a row from a table. * Deletes a row from a table.
* @param tableId the ID of the table to delete from
* @param rowId the ID of the row to delete
* @param revId the rev of the row to delete
*/ */
deleteRow: async ({ tableId, rowId, revId }) => { deleteRow: async ({ tableId, rowId, revId }) => {
if (!tableId || !rowId || !revId) { if (!tableId || !rowId || !revId) {

View File

@ -2,6 +2,7 @@ export const buildTableEndpoints = API => ({
/** /**
* Fetches a table definition. * Fetches a table definition.
* Since definitions cannot change at runtime, the result is cached. * Since definitions cannot change at runtime, the result is cached.
* @param tableId the ID of the table to fetch
*/ */
fetchTableDefinition: async tableId => { fetchTableDefinition: async tableId => {
return await API.get({ return await API.get({
@ -12,6 +13,7 @@ export const buildTableEndpoints = API => ({
/** /**
* Fetches all rows from a table. * Fetches all rows from a table.
* @param tableId the ID of the table for fetch
*/ */
fetchTableData: async tableId => { fetchTableData: async tableId => {
return await API.get({ url: `/api/${tableId}/rows` }) return await API.get({ url: `/api/${tableId}/rows` })
@ -19,6 +21,14 @@ export const buildTableEndpoints = API => ({
/** /**
* Searches a table using Lucene. * Searches a table using Lucene.
* @param tableId the ID of the table to search
* @param query the lucene search query
* @param bookmark the current pagination bookmark
* @param limit the number of rows to retrieve
* @param sort the field to sort by
* @param sortOrder the order to sort by
* @param sortType the type to sort by, either numerically or alphabetically
* @param paginate whether to paginate the data
*/ */
searchTable: async ({ searchTable: async ({
tableId, tableId,