@budibase/frontend-core 3.2.29 → 3.2.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/package.json +9 -3
  2. package/src/api/ai.ts +17 -0
  3. package/src/api/analytics.ts +39 -0
  4. package/src/api/{app.js → app.ts} +84 -5
  5. package/src/api/attachments.ts +121 -0
  6. package/src/api/auditLogs.ts +35 -0
  7. package/src/api/{auth.js → auth.ts} +44 -7
  8. package/src/api/automations.ts +158 -0
  9. package/src/api/backups.ts +50 -0
  10. package/src/api/{configs.js → configs.ts} +31 -3
  11. package/src/api/datasources.ts +132 -0
  12. package/src/api/environmentVariables.ts +58 -0
  13. package/src/api/events.ts +21 -0
  14. package/src/api/flags.ts +48 -0
  15. package/src/api/{groups.js → groups.ts} +73 -17
  16. package/src/api/{index.js → index.ts} +89 -102
  17. package/src/api/layouts.ts +35 -0
  18. package/src/api/licensing.ts +107 -0
  19. package/src/api/{logs.js → logs.ts} +7 -1
  20. package/src/api/migrations.ts +19 -0
  21. package/src/api/{other.js → other.ts} +19 -12
  22. package/src/api/{permissions.js → permissions.ts} +31 -5
  23. package/src/api/{plugins.js → plugins.ts} +18 -1
  24. package/src/api/{queries.js → queries.ts} +39 -14
  25. package/src/api/relationships.ts +31 -0
  26. package/src/api/{roles.js → roles.ts} +22 -5
  27. package/src/api/routes.ts +30 -0
  28. package/src/api/{rowActions.js → rowActions.ts} +45 -27
  29. package/src/api/rows.ts +120 -0
  30. package/src/api/screens.ts +35 -0
  31. package/src/api/{self.js → self.ts} +20 -4
  32. package/src/api/tables.ts +192 -0
  33. package/src/api/templates.ts +57 -0
  34. package/src/api/types.ts +136 -0
  35. package/src/api/{user.js → user.ts} +111 -119
  36. package/src/api/{views.js → views.ts} +18 -7
  37. package/src/api/{viewsV2.js → viewsV2.ts} +30 -27
  38. package/src/components/grid/cells/AICell.svelte +1 -0
  39. package/src/components/grid/cells/LongFormCell.svelte +1 -0
  40. package/src/components/grid/cells/RelationshipCell.svelte +1 -2
  41. package/src/components/grid/cells/TextCell.svelte +3 -0
  42. package/src/components/grid/controls/MigrationModal.svelte +5 -5
  43. package/src/components/grid/layout/Grid.svelte +5 -8
  44. package/src/components/grid/lib/constants.js +1 -1
  45. package/src/components/grid/lib/{events.js → events.ts} +3 -3
  46. package/src/components/grid/lib/utils.js +2 -0
  47. package/src/components/grid/lib/utils.ts +32 -0
  48. package/src/components/grid/stores/bounds.ts +29 -0
  49. package/src/components/grid/stores/{cache.js → cache.ts} +21 -6
  50. package/src/components/grid/stores/{clipboard.js → clipboard.ts} +55 -19
  51. package/src/components/grid/stores/{columns.js → columns.ts} +47 -19
  52. package/src/components/grid/stores/{conditions.js → conditions.ts} +32 -12
  53. package/src/components/grid/stores/{config.js → config.ts} +16 -6
  54. package/src/components/grid/stores/{datasource.js → datasource.ts} +86 -36
  55. package/src/components/grid/stores/datasources/index.ts +31 -0
  56. package/src/components/grid/stores/datasources/{nonPlus.js → nonPlus.ts} +21 -11
  57. package/src/components/grid/stores/datasources/{table.js → table.ts} +39 -21
  58. package/src/components/grid/stores/datasources/{viewV2.js → viewV2.ts} +74 -28
  59. package/src/components/grid/stores/{filter.js → filter.ts} +39 -16
  60. package/src/components/grid/stores/index.ts +143 -0
  61. package/src/components/grid/stores/{menu.js → menu.ts} +31 -6
  62. package/src/components/grid/stores/{notifications.js → notifications.ts} +12 -2
  63. package/src/components/grid/stores/{pagination.js → pagination.ts} +2 -1
  64. package/src/components/grid/stores/{reorder.js → reorder.ts} +47 -15
  65. package/src/components/grid/stores/{resize.js → resize.ts} +28 -10
  66. package/src/components/grid/stores/{rows.js → rows.ts} +167 -53
  67. package/src/components/grid/stores/{scroll.js → scroll.ts} +28 -5
  68. package/src/components/grid/stores/{sort.js → sort.ts} +13 -3
  69. package/src/components/grid/stores/{ui.js → ui.ts} +77 -20
  70. package/src/components/grid/stores/{users.js → users.ts} +36 -9
  71. package/src/components/grid/stores/{validation.js → validation.ts} +35 -12
  72. package/src/components/grid/stores/{viewport.js → viewport.ts} +14 -3
  73. package/src/{constants.js → constants.ts} +2 -2
  74. package/src/fetch/QueryFetch.js +2 -2
  75. package/src/fetch/RelationshipFetch.js +9 -6
  76. package/src/fetch/TableFetch.js +1 -2
  77. package/src/fetch/ViewFetch.js +1 -1
  78. package/src/fetch/ViewV2Fetch.js +1 -2
  79. package/src/utils/memo.d.ts +10 -0
  80. package/src/utils/relatedColumns.ts +126 -0
  81. package/tsconfig.json +14 -0
  82. package/src/api/ai.js +0 -11
  83. package/src/api/analytics.js +0 -17
  84. package/src/api/attachments.js +0 -78
  85. package/src/api/auditLogs.js +0 -63
  86. package/src/api/automations.js +0 -111
  87. package/src/api/backups.js +0 -46
  88. package/src/api/datasources.js +0 -92
  89. package/src/api/environmentVariables.js +0 -36
  90. package/src/api/events.js +0 -13
  91. package/src/api/flags.js +0 -34
  92. package/src/api/hosting.js +0 -19
  93. package/src/api/layouts.js +0 -23
  94. package/src/api/licensing.js +0 -75
  95. package/src/api/migrations.js +0 -10
  96. package/src/api/relationships.js +0 -21
  97. package/src/api/routes.js +0 -19
  98. package/src/api/rows.js +0 -117
  99. package/src/api/screens.js +0 -23
  100. package/src/api/tables.js +0 -152
  101. package/src/api/templates.js +0 -35
  102. package/src/components/grid/stores/bounds.js +0 -16
  103. package/src/components/grid/stores/index.js +0 -73
  104. package/src/utils/relatedColumns.js +0 -103
  105. /package/src/{index.js → index.ts} +0 -0
  106. /package/src/utils/{index.js → index.ts} +0 -0
@@ -1,12 +1,42 @@
1
- export const buildQueryEndpoints = API => ({
1
+ import {
2
+ DeleteQueryResponse,
3
+ ExecuteQueryRequest,
4
+ ExecuteV2QueryResponse,
5
+ FetchQueriesResponse,
6
+ FindQueryResponse,
7
+ ImportRestQueryRequest,
8
+ ImportRestQueryResponse,
9
+ PreviewQueryRequest,
10
+ PreviewQueryResponse,
11
+ SaveQueryRequest,
12
+ SaveQueryResponse,
13
+ } from "@budibase/types"
14
+ import { BaseAPIClient } from "./types"
15
+
16
+ export interface QueryEndpoints {
17
+ executeQuery: (
18
+ queryId: string,
19
+ opts?: ExecuteQueryRequest
20
+ ) => Promise<ExecuteV2QueryResponse>
21
+ fetchQueryDefinition: (queryId: string) => Promise<FindQueryResponse>
22
+ getQueries: () => Promise<FetchQueriesResponse>
23
+ saveQuery: (query: SaveQueryRequest) => Promise<SaveQueryResponse>
24
+ deleteQuery: (id: string, rev: string) => Promise<DeleteQueryResponse>
25
+ previewQuery: (query: PreviewQueryRequest) => Promise<PreviewQueryResponse>
26
+ importQueries: (
27
+ data: ImportRestQueryRequest
28
+ ) => Promise<ImportRestQueryResponse>
29
+ }
30
+
31
+ export const buildQueryEndpoints = (API: BaseAPIClient): QueryEndpoints => ({
2
32
  /**
3
33
  * Executes a query against an external data connector.
4
34
  * @param queryId the ID of the query to execute
5
35
  * @param pagination pagination info for the query
6
36
  * @param parameters parameters for the query
7
37
  */
8
- executeQuery: async ({ queryId, pagination, parameters }) => {
9
- return await API.post({
38
+ executeQuery: async (queryId, { pagination, parameters } = {}) => {
39
+ return await API.post<ExecuteQueryRequest, ExecuteV2QueryResponse>({
10
40
  url: `/api/v2/queries/${queryId}`,
11
41
  body: {
12
42
  parameters,
@@ -48,27 +78,22 @@ export const buildQueryEndpoints = API => ({
48
78
 
49
79
  /**
50
80
  * Deletes a query
51
- * @param queryId the ID of the query to delete
52
- * @param queryRev the rev of the query to delete
81
+ * @param id the ID of the query to delete
82
+ * @param rev the rev of the query to delete
53
83
  */
54
- deleteQuery: async ({ queryId, queryRev }) => {
84
+ deleteQuery: async (id, rev) => {
55
85
  return await API.delete({
56
- url: `/api/queries/${queryId}/${queryRev}`,
86
+ url: `/api/queries/${id}/${rev}`,
57
87
  })
58
88
  },
59
89
 
60
90
  /**
61
91
  * Imports a set of queries into a certain datasource
62
- * @param datasourceId the datasource ID to import queries into
63
- * @param data the data string of the content to import
64
92
  */
65
- importQueries: async ({ datasourceId, data }) => {
93
+ importQueries: async data => {
66
94
  return await API.post({
67
95
  url: "/api/queries/import",
68
- body: {
69
- datasourceId,
70
- data,
71
- },
96
+ body: data,
72
97
  })
73
98
  },
74
99
 
@@ -0,0 +1,31 @@
1
+ import { FetchEnrichedRowResponse, Row } from "@budibase/types"
2
+ import { BaseAPIClient } from "./types"
3
+
4
+ export interface RelationshipEndpoints {
5
+ fetchRelationshipData: (
6
+ sourceId: string,
7
+ rowId: string,
8
+ fieldName?: string
9
+ ) => Promise<Row[]>
10
+ }
11
+
12
+ export const buildRelationshipEndpoints = (
13
+ API: BaseAPIClient
14
+ ): RelationshipEndpoints => ({
15
+ /**
16
+ * Fetches related rows for a certain field of a certain row.
17
+ * @param sourceId the ID of the table to fetch from
18
+ * @param rowId the ID of the row to fetch related rows for
19
+ * @param fieldName the name of the relationship field
20
+ */
21
+ fetchRelationshipData: async (sourceId, rowId, fieldName) => {
22
+ const response = await API.get<FetchEnrichedRowResponse>({
23
+ url: `/api/${sourceId}/${rowId}/enrich?field=${fieldName}`,
24
+ })
25
+ if (!fieldName) {
26
+ return [response]
27
+ } else {
28
+ return response[fieldName] || []
29
+ }
30
+ },
31
+ })
@@ -1,12 +1,29 @@
1
- export const buildRoleEndpoints = API => ({
1
+ import {
2
+ AccessibleRolesResponse,
3
+ DeleteRoleResponse,
4
+ FetchRolesResponse,
5
+ SaveRoleRequest,
6
+ SaveRoleResponse,
7
+ } from "@budibase/types"
8
+ import { BaseAPIClient } from "./types"
9
+
10
+ export interface RoleEndpoints {
11
+ deleteRole: (id: string, rev: string) => Promise<DeleteRoleResponse>
12
+ saveRole: (role: SaveRoleRequest) => Promise<SaveRoleResponse>
13
+ getRoles: () => Promise<FetchRolesResponse>
14
+ getRolesForApp: (appId: string) => Promise<any>
15
+ getAccessibleRoles: () => Promise<AccessibleRolesResponse>
16
+ }
17
+
18
+ export const buildRoleEndpoints = (API: BaseAPIClient): RoleEndpoints => ({
2
19
  /**
3
20
  * Deletes a role.
4
- * @param roleId the ID of the role to delete
5
- * @param roleRev the rev of the role to delete
21
+ * @param id the ID of the role to delete
22
+ * @param rev the rev of the role to delete
6
23
  */
7
- deleteRole: async ({ roleId, roleRev }) => {
24
+ deleteRole: async (id, rev) => {
8
25
  return await API.delete({
9
- url: `/api/roles/${roleId}/${roleRev}`,
26
+ url: `/api/roles/${id}/${rev}`,
10
27
  })
11
28
  },
12
29
 
@@ -0,0 +1,30 @@
1
+ import {
2
+ FetchClientScreenRoutingResponse,
3
+ FetchScreenRoutingResponse,
4
+ } from "@budibase/types"
5
+ import { BaseAPIClient } from "./types"
6
+
7
+ export interface RouteEndpoints {
8
+ fetchClientAppRoutes: () => Promise<FetchClientScreenRoutingResponse>
9
+ fetchAppRoutes: () => Promise<FetchScreenRoutingResponse>
10
+ }
11
+
12
+ export const buildRouteEndpoints = (API: BaseAPIClient): RouteEndpoints => ({
13
+ /**
14
+ * Fetches available routes for the client app.
15
+ */
16
+ fetchClientAppRoutes: async () => {
17
+ return await API.get({
18
+ url: `/api/routing/client`,
19
+ })
20
+ },
21
+
22
+ /**
23
+ * Fetches all routes for the current app.
24
+ */
25
+ fetchAppRoutes: async () => {
26
+ return await API.get({
27
+ url: "/api/routing",
28
+ })
29
+ },
30
+ })
@@ -1,13 +1,46 @@
1
- export const buildRowActionEndpoints = API => ({
1
+ import {
2
+ RowActionsResponse,
3
+ RowActionResponse,
4
+ CreateRowActionRequest,
5
+ RowActionPermissionsResponse,
6
+ RowActionTriggerRequest,
7
+ } from "@budibase/types"
8
+ import { BaseAPIClient } from "./types"
9
+
10
+ export interface RowActionEndpoints {
11
+ fetch: (tableId: string) => Promise<Record<string, RowActionResponse>>
12
+ create: (tableId: string, name: string) => Promise<RowActionResponse>
13
+ delete: (tableId: string, rowActionId: string) => Promise<void>
14
+ enableView: (
15
+ tableId: string,
16
+ rowActionId: string,
17
+ viewId: string
18
+ ) => Promise<RowActionPermissionsResponse>
19
+ disableView: (
20
+ tableId: string,
21
+ rowActionId: string,
22
+ viewId: string
23
+ ) => Promise<RowActionPermissionsResponse>
24
+ trigger: (
25
+ sourceId: string,
26
+ rowActionId: string,
27
+ rowId: string
28
+ ) => Promise<void>
29
+ }
30
+
31
+ export const buildRowActionEndpoints = (
32
+ API: BaseAPIClient
33
+ ): RowActionEndpoints => ({
2
34
  /**
3
35
  * Gets the available row actions for a table.
4
36
  * @param tableId the ID of the table
5
37
  */
6
38
  fetch: async tableId => {
7
- const res = await API.get({
8
- url: `/api/tables/${tableId}/actions`,
9
- })
10
- return res?.actions || {}
39
+ return (
40
+ await API.get<RowActionsResponse>({
41
+ url: `/api/tables/${tableId}/actions`,
42
+ })
43
+ ).actions
11
44
  },
12
45
 
13
46
  /**
@@ -15,8 +48,8 @@ export const buildRowActionEndpoints = API => ({
15
48
  * @param name the name of the row action
16
49
  * @param tableId the ID of the table
17
50
  */
18
- create: async ({ name, tableId }) => {
19
- return await API.post({
51
+ create: async (tableId, name) => {
52
+ return await API.post<CreateRowActionRequest, RowActionResponse>({
20
53
  url: `/api/tables/${tableId}/actions`,
21
54
  body: {
22
55
  name,
@@ -24,27 +57,12 @@ export const buildRowActionEndpoints = API => ({
24
57
  })
25
58
  },
26
59
 
27
- /**
28
- * Updates a row action.
29
- * @param name the new name of the row action
30
- * @param tableId the ID of the table
31
- * @param rowActionId the ID of the row action to update
32
- */
33
- update: async ({ tableId, rowActionId, name }) => {
34
- return await API.put({
35
- url: `/api/tables/${tableId}/actions/${rowActionId}`,
36
- body: {
37
- name,
38
- },
39
- })
40
- },
41
-
42
60
  /**
43
61
  * Deletes a row action.
44
62
  * @param tableId the ID of the table
45
63
  * @param rowActionId the ID of the row action to delete
46
64
  */
47
- delete: async ({ tableId, rowActionId }) => {
65
+ delete: async (tableId, rowActionId) => {
48
66
  return await API.delete({
49
67
  url: `/api/tables/${tableId}/actions/${rowActionId}`,
50
68
  })
@@ -56,7 +74,7 @@ export const buildRowActionEndpoints = API => ({
56
74
  * @param rowActionId the ID of the row action
57
75
  * @param viewId the ID of the view
58
76
  */
59
- enableView: async ({ tableId, rowActionId, viewId }) => {
77
+ enableView: async (tableId, rowActionId, viewId) => {
60
78
  return await API.post({
61
79
  url: `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
62
80
  })
@@ -68,7 +86,7 @@ export const buildRowActionEndpoints = API => ({
68
86
  * @param rowActionId the ID of the row action
69
87
  * @param viewId the ID of the view
70
88
  */
71
- disableView: async ({ tableId, rowActionId, viewId }) => {
89
+ disableView: async (tableId, rowActionId, viewId) => {
72
90
  return await API.delete({
73
91
  url: `/api/tables/${tableId}/actions/${rowActionId}/permissions/${viewId}`,
74
92
  })
@@ -79,8 +97,8 @@ export const buildRowActionEndpoints = API => ({
79
97
  * @param tableId the ID of the table
80
98
  * @param rowActionId the ID of the row action to trigger
81
99
  */
82
- trigger: async ({ sourceId, rowActionId, rowId }) => {
83
- return await API.post({
100
+ trigger: async (sourceId, rowActionId, rowId) => {
101
+ return await API.post<RowActionTriggerRequest>({
84
102
  url: `/api/tables/${sourceId}/actions/${rowActionId}/trigger`,
85
103
  body: {
86
104
  rowId,
@@ -0,0 +1,120 @@
1
+ import {
2
+ DeleteRowRequest,
3
+ ExportRowsRequest,
4
+ FindRowResponse,
5
+ PatchRowRequest,
6
+ PatchRowResponse,
7
+ Row,
8
+ SaveRowRequest,
9
+ SaveRowResponse,
10
+ } from "@budibase/types"
11
+ import { BaseAPIClient } from "./types"
12
+
13
+ export interface RowEndpoints {
14
+ fetchRow: (tableId: string, rowId: string) => Promise<FindRowResponse>
15
+ saveRow: (
16
+ row: SaveRowRequest,
17
+ suppressErrors?: boolean
18
+ ) => Promise<SaveRowResponse>
19
+ patchRow: (
20
+ row: PatchRowRequest,
21
+ suppressErrors?: boolean
22
+ ) => Promise<PatchRowResponse>
23
+ deleteRow: (sourceId: string, id: string) => Promise<void>
24
+ deleteRows: (sourceId: string, rows: (Row | string)[]) => Promise<void>
25
+ exportRows: (
26
+ tableId: string,
27
+ format: string,
28
+ data: ExportRowsRequest
29
+ ) => Promise<string>
30
+ }
31
+
32
+ export const buildRowEndpoints = (API: BaseAPIClient): RowEndpoints => ({
33
+ /**
34
+ * Fetches data about a certain row in a data source.
35
+ * @param sourceId the ID of the table or view to fetch from
36
+ * @param rowId the ID of the row to fetch
37
+ */
38
+ fetchRow: async (sourceId, rowId) => {
39
+ return await API.get({
40
+ url: `/api/${sourceId}/rows/${rowId}`,
41
+ })
42
+ },
43
+
44
+ /**
45
+ * Creates or updates a row in a table.
46
+ * @param row the row to save
47
+ * @param suppressErrors whether or not to suppress error notifications
48
+ */
49
+ saveRow: async (row, suppressErrors = false) => {
50
+ const sourceId = row._viewId || row.tableId
51
+ return await API.post({
52
+ url: `/api/${sourceId}/rows`,
53
+ body: row,
54
+ suppressErrors,
55
+ })
56
+ },
57
+
58
+ /**
59
+ * Patches a row in a table.
60
+ * @param row the row to patch
61
+ * @param suppressErrors whether or not to suppress error notifications
62
+ */
63
+ patchRow: async (row, suppressErrors = false) => {
64
+ const sourceId = row._viewId || row.tableId
65
+ return await API.patch({
66
+ url: `/api/${sourceId}/rows`,
67
+ body: row,
68
+ suppressErrors,
69
+ })
70
+ },
71
+
72
+ /**
73
+ * Deletes a row from a table.
74
+ * @param sourceId the ID of the table or view to delete from
75
+ * @param rowId the ID of the row to delete
76
+ */
77
+ deleteRow: async (sourceId, rowId) => {
78
+ return await API.delete<DeleteRowRequest>({
79
+ url: `/api/${sourceId}/rows`,
80
+ body: {
81
+ _id: rowId,
82
+ },
83
+ })
84
+ },
85
+
86
+ /**
87
+ * Deletes multiple rows from a table.
88
+ * @param sourceId the table or view ID to delete the rows from
89
+ * @param rows the array of rows to delete
90
+ */
91
+ deleteRows: async (sourceId, rows) => {
92
+ rows.forEach(row => {
93
+ if (typeof row === "object") {
94
+ delete row?._viewId
95
+ }
96
+ })
97
+ return await API.delete<DeleteRowRequest>({
98
+ url: `/api/${sourceId}/rows`,
99
+ body: {
100
+ rows,
101
+ },
102
+ })
103
+ },
104
+
105
+ /**
106
+ * Exports rows.
107
+ * @param tableId the table ID to export the rows from
108
+ * @param format the format to export (csv or json)
109
+ * @param data the export options
110
+ */
111
+ exportRows: async (tableId, format, data) => {
112
+ return await API.post({
113
+ url: `/api/${tableId}/rows/exportRows?format=${format}`,
114
+ body: data,
115
+ parseResponse: async response => {
116
+ return await response.text()
117
+ },
118
+ })
119
+ },
120
+ })
@@ -0,0 +1,35 @@
1
+ import {
2
+ DeleteScreenResponse,
3
+ SaveScreenRequest,
4
+ SaveScreenResponse,
5
+ } from "@budibase/types"
6
+ import { BaseAPIClient } from "./types"
7
+
8
+ export interface ScreenEndpoints {
9
+ saveScreen: (screen: SaveScreenRequest) => Promise<SaveScreenResponse>
10
+ deleteScreen: (id: string, rev: string) => Promise<DeleteScreenResponse>
11
+ }
12
+
13
+ export const buildScreenEndpoints = (API: BaseAPIClient): ScreenEndpoints => ({
14
+ /**
15
+ * Saves a screen definition
16
+ * @param screen the screen to save
17
+ */
18
+ saveScreen: async screen => {
19
+ return await API.post({
20
+ url: "/api/screens",
21
+ body: screen,
22
+ })
23
+ },
24
+
25
+ /**
26
+ * Deletes a screen.
27
+ * @param id the ID of the screen to delete
28
+ * @param rev the rev of the screen to delete
29
+ */
30
+ deleteScreen: async (id, rev) => {
31
+ return await API.delete({
32
+ url: `/api/screens/${id}/${rev}`,
33
+ })
34
+ },
35
+ })
@@ -1,11 +1,28 @@
1
- export const buildSelfEndpoints = API => ({
1
+ import {
2
+ AppSelfResponse,
3
+ FetchAPIKeyResponse,
4
+ GenerateAPIKeyResponse,
5
+ GetGlobalSelfResponse,
6
+ UpdateSelfRequest,
7
+ UpdateSelfResponse,
8
+ } from "@budibase/types"
9
+ import { BaseAPIClient } from "./types"
10
+
11
+ export interface SelfEndpoints {
12
+ updateSelf: (user: UpdateSelfRequest) => Promise<UpdateSelfResponse>
13
+ generateAPIKey: () => Promise<string | undefined>
14
+ fetchDeveloperInfo: () => Promise<FetchAPIKeyResponse>
15
+ fetchBuilderSelf: () => Promise<GetGlobalSelfResponse>
16
+ fetchSelf: () => Promise<AppSelfResponse>
17
+ }
18
+
19
+ export const buildSelfEndpoints = (API: BaseAPIClient): SelfEndpoints => ({
2
20
  /**
3
21
  * Using the logged in user, this will generate a new API key,
4
22
  * assuming the user is a builder.
5
- * @return {Promise<object>} returns the API response, including an API key.
6
23
  */
7
24
  generateAPIKey: async () => {
8
- const response = await API.post({
25
+ const response = await API.post<null, GenerateAPIKeyResponse>({
9
26
  url: "/api/global/self/api_key",
10
27
  })
11
28
  return response?.apiKey
@@ -13,7 +30,6 @@ export const buildSelfEndpoints = API => ({
13
30
 
14
31
  /**
15
32
  * retrieves the API key for the logged in user.
16
- * @return {Promise<object>} An object containing the user developer information.
17
33
  */
18
34
  fetchDeveloperInfo: async () => {
19
35
  return API.get({
@@ -0,0 +1,192 @@
1
+ import {
2
+ BulkImportRequest,
3
+ BulkImportResponse,
4
+ CsvToJsonRequest,
5
+ CsvToJsonResponse,
6
+ FetchTablesResponse,
7
+ Row,
8
+ SaveTableRequest,
9
+ SaveTableResponse,
10
+ SearchRowRequest,
11
+ PaginatedSearchRowResponse,
12
+ TableSchema,
13
+ ValidateNewTableImportRequest,
14
+ ValidateTableImportRequest,
15
+ ValidateTableImportResponse,
16
+ FindTableResponse,
17
+ FetchRowsResponse,
18
+ MigrateTableResponse,
19
+ MigrateTableRequest,
20
+ DeleteTableResponse,
21
+ } from "@budibase/types"
22
+ import { BaseAPIClient } from "./types"
23
+
24
+ export interface TableEndpoints {
25
+ fetchTableDefinition: (tableId: string) => Promise<FindTableResponse>
26
+ fetchTableData: (tableId: string) => Promise<FetchRowsResponse>
27
+ searchTable: (
28
+ sourceId: string,
29
+ opts: SearchRowRequest
30
+ ) => Promise<PaginatedSearchRowResponse>
31
+ importTableData: (
32
+ tableId: string,
33
+ rows: Row[],
34
+ identifierFields?: string[]
35
+ ) => Promise<BulkImportResponse>
36
+ csvToJson: (csvString: string) => Promise<CsvToJsonResponse>
37
+ getTables: () => Promise<FetchTablesResponse>
38
+ getTable: (tableId: string) => Promise<FindTableResponse>
39
+ saveTable: (table: SaveTableRequest) => Promise<SaveTableResponse>
40
+ deleteTable: (id: string, rev: string) => Promise<DeleteTableResponse>
41
+ validateNewTableImport: (
42
+ rows: Row[],
43
+ schema: TableSchema
44
+ ) => Promise<ValidateTableImportResponse>
45
+ validateExistingTableImport: (
46
+ rows: Row[],
47
+ tableId?: string
48
+ ) => Promise<ValidateTableImportResponse>
49
+ migrateColumn: (
50
+ tableId: string,
51
+ oldColumn: string,
52
+ newColumn: string
53
+ ) => Promise<MigrateTableResponse>
54
+ }
55
+
56
+ export const buildTableEndpoints = (API: BaseAPIClient): TableEndpoints => ({
57
+ /**
58
+ * Fetches a table definition.
59
+ * Since definitions cannot change at runtime, the result is cached.
60
+ * @param tableId the ID of the table to fetch
61
+ */
62
+ fetchTableDefinition: async tableId => {
63
+ return await API.get({
64
+ url: `/api/tables/${tableId}`,
65
+ cache: true,
66
+ })
67
+ },
68
+
69
+ /**
70
+ * Fetches all rows from a table.
71
+ * @param sourceId the ID of the table to fetch
72
+ */
73
+ fetchTableData: async sourceId => {
74
+ return await API.get({ url: `/api/${sourceId}/rows` })
75
+ },
76
+
77
+ /**
78
+ * Searches a table using Lucene.
79
+ * @param sourceId the ID of the table to search
80
+ * @param opts the search opts
81
+ */
82
+ searchTable: async (sourceId, opts) => {
83
+ return await API.post({
84
+ url: `/api/${sourceId}/search`,
85
+ body: opts,
86
+ })
87
+ },
88
+
89
+ /**
90
+ * Imports data into an existing table
91
+ * @param tableId the table ID to import to
92
+ * @param rows the data import object
93
+ * @param identifierFields column names to be used as keys for overwriting existing rows
94
+ */
95
+ importTableData: async (tableId, rows, identifierFields) => {
96
+ return await API.post<BulkImportRequest, BulkImportResponse>({
97
+ url: `/api/tables/${tableId}/import`,
98
+ body: {
99
+ rows,
100
+ identifierFields,
101
+ },
102
+ })
103
+ },
104
+
105
+ /**
106
+ * Converts a CSV string to JSON
107
+ * @param csvString the CSV string
108
+ */
109
+ csvToJson: async csvString => {
110
+ return await API.post<CsvToJsonRequest, CsvToJsonResponse>({
111
+ url: "/api/convert/csvToJson",
112
+ body: {
113
+ csvString,
114
+ },
115
+ })
116
+ },
117
+
118
+ /**
119
+ * Gets a list of tables.
120
+ */
121
+ getTables: async () => {
122
+ return await API.get({
123
+ url: "/api/tables",
124
+ })
125
+ },
126
+
127
+ /**
128
+ * Get a single table based on table ID.
129
+ * Dupe of fetchTableDefinition but not cached?
130
+ */
131
+ getTable: async tableId => {
132
+ return await API.get({
133
+ url: `/api/tables/${tableId}`,
134
+ })
135
+ },
136
+
137
+ /**
138
+ * Saves a table.
139
+ * @param table the table to save
140
+ */
141
+ saveTable: async table => {
142
+ return await API.post({
143
+ url: "/api/tables",
144
+ body: table,
145
+ })
146
+ },
147
+
148
+ /**
149
+ * Deletes a table.
150
+ * @param id the ID of the table to delete
151
+ * @param rev the rev of the table to delete
152
+ */
153
+ deleteTable: async (id, rev) => {
154
+ return await API.delete({
155
+ url: `/api/tables/${id}/${rev}`,
156
+ })
157
+ },
158
+
159
+ validateNewTableImport: async (rows, schema) => {
160
+ return await API.post<
161
+ ValidateNewTableImportRequest,
162
+ ValidateTableImportResponse
163
+ >({
164
+ url: "/api/tables/validateNewTableImport",
165
+ body: {
166
+ rows,
167
+ schema,
168
+ },
169
+ })
170
+ },
171
+ validateExistingTableImport: async (rows, tableId) => {
172
+ return await API.post<
173
+ ValidateTableImportRequest,
174
+ ValidateTableImportResponse
175
+ >({
176
+ url: "/api/tables/validateExistingTableImport",
177
+ body: {
178
+ rows,
179
+ tableId,
180
+ },
181
+ })
182
+ },
183
+ migrateColumn: async (tableId, oldColumn, newColumn) => {
184
+ return await API.post<MigrateTableRequest, MigrateTableResponse>({
185
+ url: `/api/tables/${tableId}/migrate`,
186
+ body: {
187
+ oldColumn,
188
+ newColumn,
189
+ },
190
+ })
191
+ },
192
+ })