@budibase/server 1.0.80-alpha.3 → 1.0.80
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.
- package/__mocks__/node-fetch.ts +0 -1
- package/builder/assets/index.22a39cc9.js +1352 -0
- package/builder/assets/{index.c57242d4.css → index.c8d1e8f0.css} +2 -2
- package/builder/assets/{vendor.a7c6ad0a.js → vendor.20f80cec.js} +216 -190
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2327 -2390
- package/coverage/coverage-final.json +137 -138
- package/coverage/lcov-report/api/controllers/analytics.js.html +6 -6
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/application.js.html +149 -152
- package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
- package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
- package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
- package/coverage/lcov-report/api/controllers/dev.js.html +19 -19
- package/coverage/lcov-report/api/controllers/index.html +16 -16
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
- package/coverage/lcov-report/api/controllers/row/index.html +27 -27
- package/coverage/lcov-report/api/controllers/row/index.js.html +46 -46
- package/coverage/lcov-report/api/controllers/row/internal.js.html +82 -94
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +204 -204
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -29
- package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
- package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
- package/coverage/lcov-report/api/controllers/table/index.html +11 -11
- package/coverage/lcov-report/api/controllers/table/index.js.html +44 -47
- package/coverage/lcov-report/api/controllers/table/internal.js.html +50 -50
- package/coverage/lcov-report/api/controllers/table/utils.js.html +80 -80
- package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
- package/coverage/lcov-report/api/controllers/user.js.html +19 -19
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/view/utils.js.html +12 -12
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +27 -18
- package/coverage/lcov-report/api/index.html +10 -10
- package/coverage/lcov-report/api/index.js.html +28 -37
- package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/application.js.html +9 -9
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +109 -19
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +156 -18
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +35 -35
- package/coverage/lcov-report/api/routes/index.js.html +32 -38
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +58 -16
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +78 -15
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/row.js.html +14 -17
- package/coverage/lcov-report/api/routes/screen.js.html +95 -14
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +13 -13
- package/coverage/lcov-report/api/routes/table.js.html +62 -17
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/api/routes/webhook.js.html +62 -14
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +7 -7
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +9 -12
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +11 -11
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +26 -26
- package/coverage/lcov-report/automations/utils.js.html +35 -35
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +28 -40
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +21 -21
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +30 -30
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +87 -123
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +8 -8
- package/coverage/lcov-report/events/utils.js.html +18 -18
- package/coverage/lcov-report/index.html +74 -89
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
- package/coverage/lcov-report/middleware/authorized.js.html +29 -29
- package/coverage/lcov-report/middleware/builder.js.html +16 -16
- package/coverage/lcov-report/middleware/currentapp.js.html +44 -44
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
- package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +17 -17
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +19 -19
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +39 -123
- package/coverage/lcov-report/threads/utils.js.html +14 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +28 -28
- package/coverage/lcov-report/utilities/index.html +18 -18
- package/coverage/lcov-report/utilities/index.js.html +24 -24
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -9
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +60 -60
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +13 -13
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +12 -12
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +8 -8
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +5 -5
- package/coverage/lcov-report/utilities/workerRequests.js.html +53 -200
- package/coverage/lcov.info +3233 -3332
- package/dist/api/controllers/application.js +0 -1
- package/dist/api/controllers/row/internal.js +1 -4
- package/dist/api/controllers/table/index.js +1 -2
- package/dist/api/controllers/webhook.js +5 -3
- package/dist/api/index.js +1 -3
- package/dist/api/routes/automation.js +31 -3
- package/dist/api/routes/datasource.js +50 -3
- package/dist/api/routes/index.js +0 -2
- package/dist/api/routes/permission.js +14 -4
- package/dist/api/routes/role.js +19 -3
- package/dist/api/routes/row.js +4 -3
- package/dist/api/routes/screen.js +23 -2
- package/dist/api/routes/table.js +17 -3
- package/dist/api/routes/tests/utilities/index.js +0 -23
- package/dist/api/routes/webhook.js +17 -2
- package/dist/automations/steps/filter.js +2 -2
- package/dist/automations/steps/queryRows.js +1 -1
- package/dist/automations/utils.js +2 -2
- package/dist/constants/index.js +0 -3
- package/dist/db/utils.js +0 -11
- package/dist/environment.js +0 -1
- package/dist/integrations/base/sql.js +1 -16
- package/dist/integrations/base/sqlTable.js +4 -8
- package/dist/integrations/googlesheets.js +0 -3
- package/dist/integrations/microsoftSqlServer.js +43 -60
- package/dist/integrations/mysql.js +0 -3
- package/dist/integrations/oracle.js +19 -14
- package/dist/integrations/postgres.js +28 -34
- package/dist/integrations/utils.js +15 -32
- package/dist/package.json +7 -11
- package/dist/tests/utilities/TestConfiguration.js +8 -25
- package/dist/threads/query.js +8 -33
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/workerRequests.js +15 -50
- package/package.json +8 -12
- package/scripts/integrations/mssql/data/setup.sql +1 -18
- package/scripts/integrations/oracle/oracle.md +2 -2
- package/scripts/integrations/postgres/init.sql +3 -11
- package/scripts/likeCypress.ts +6 -9
- package/scripts/proxy/generateProxyConfig.js +70 -0
- package/src/api/controllers/application.js +0 -1
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/internal.js +0 -4
- package/src/api/controllers/table/index.js +1 -2
- package/src/api/controllers/webhook.js +6 -3
- package/src/api/index.js +1 -4
- package/src/api/routes/automation.js +33 -3
- package/src/api/routes/datasource.js +52 -6
- package/src/api/routes/index.js +0 -2
- package/src/api/routes/permission.js +18 -4
- package/src/api/routes/role.js +24 -3
- package/src/api/routes/row.js +2 -3
- package/src/api/routes/screen.js +29 -2
- package/src/api/routes/table.js +19 -4
- package/src/api/routes/tests/utilities/index.js +0 -24
- package/src/api/routes/webhook.js +18 -2
- package/src/automations/steps/filter.js +2 -3
- package/src/automations/steps/queryRows.js +1 -1
- package/src/automations/utils.js +2 -2
- package/src/constants/index.js +0 -4
- package/src/db/utils.js +0 -12
- package/src/definitions/common.ts +0 -4
- package/src/definitions/datasource.ts +0 -1
- package/src/environment.js +0 -1
- package/src/integrations/base/datasourcePlus.ts +0 -3
- package/src/integrations/base/sql.ts +1 -16
- package/src/integrations/base/sqlTable.ts +7 -11
- package/src/integrations/googlesheets.ts +2 -5
- package/src/integrations/microsoftSqlServer.ts +61 -86
- package/src/integrations/mysql.ts +0 -4
- package/src/integrations/oracle.ts +35 -27
- package/src/integrations/postgres.ts +26 -33
- package/src/integrations/utils.ts +15 -43
- package/src/tests/utilities/TestConfiguration.js +2 -23
- package/src/threads/query.js +9 -37
- package/src/utilities/workerRequests.js +16 -65
- package/builder/assets/index.f8c92447.js +0 -1288
- package/coverage/lcov-report/api/routes/utils/index.html +0 -111
- package/coverage/lcov-report/api/routes/utils/validators.js.html +0 -737
- package/dist/api/controllers/public/applications.js +0 -94
- package/dist/api/controllers/public/mapping/applications.js +0 -29
- package/dist/api/controllers/public/mapping/index.js +0 -11
- package/dist/api/controllers/public/mapping/queries.js +0 -36
- package/dist/api/controllers/public/mapping/rows.js +0 -24
- package/dist/api/controllers/public/mapping/tables.js +0 -23
- package/dist/api/controllers/public/mapping/types.js +0 -2
- package/dist/api/controllers/public/mapping/users.js +0 -29
- package/dist/api/controllers/public/queries.js +0 -38
- package/dist/api/controllers/public/rows.js +0 -97
- package/dist/api/controllers/public/tables.js +0 -75
- package/dist/api/controllers/public/users.js +0 -95
- package/dist/api/controllers/public/utils.js +0 -49
- package/dist/api/routes/public/applications.js +0 -141
- package/dist/api/routes/public/index.js +0 -101
- package/dist/api/routes/public/middleware/mapper.js +0 -94
- package/dist/api/routes/public/queries.js +0 -77
- package/dist/api/routes/public/rows.js +0 -229
- package/dist/api/routes/public/tables.js +0 -154
- package/dist/api/routes/public/users.js +0 -137
- package/dist/api/routes/public/utils/Endpoint.js +0 -36
- package/dist/api/routes/utils/validators.js +0 -200
- package/dist/definitions/openapi.js +0 -6
- package/specs/generate.js +0 -94
- package/specs/openapi.json +0 -2232
- package/specs/openapi.yaml +0 -1538
- package/specs/parameters.js +0 -59
- package/specs/resources/application.js +0 -101
- package/specs/resources/index.js +0 -24
- package/specs/resources/misc.js +0 -12
- package/specs/resources/query.js +0 -189
- package/specs/resources/row.js +0 -125
- package/specs/resources/table.js +0 -191
- package/specs/resources/user.js +0 -126
- package/specs/resources/utils/Resource.js +0 -26
- package/specs/resources/utils/index.js +0 -11
- package/specs/security.js +0 -7
- package/src/api/controllers/public/applications.ts +0 -74
- package/src/api/controllers/public/mapping/applications.ts +0 -32
- package/src/api/controllers/public/mapping/index.ts +0 -13
- package/src/api/controllers/public/mapping/queries.ts +0 -39
- package/src/api/controllers/public/mapping/rows.ts +0 -31
- package/src/api/controllers/public/mapping/tables.ts +0 -26
- package/src/api/controllers/public/mapping/types.ts +0 -13
- package/src/api/controllers/public/mapping/users.ts +0 -32
- package/src/api/controllers/public/queries.ts +0 -20
- package/src/api/controllers/public/rows.ts +0 -77
- package/src/api/controllers/public/tables.ts +0 -56
- package/src/api/controllers/public/users.ts +0 -82
- package/src/api/controllers/public/utils.ts +0 -38
- package/src/api/routes/public/applications.ts +0 -156
- package/src/api/routes/public/index.ts +0 -118
- package/src/api/routes/public/middleware/mapper.ts +0 -81
- package/src/api/routes/public/queries.ts +0 -81
- package/src/api/routes/public/rows.ts +0 -242
- package/src/api/routes/public/tables.ts +0 -169
- package/src/api/routes/public/tests/compare.spec.js +0 -184
- package/src/api/routes/public/users.ts +0 -144
- package/src/api/routes/public/utils/Endpoint.ts +0 -51
- package/src/api/routes/utils/validators.js +0 -219
- package/src/definitions/openapi.ts +0 -943
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
const { getAppDB } = require("@budibase/backend-core/context")
|
|
2
|
-
import { isExternalTable } from "../../../integrations/utils"
|
|
3
|
-
|
|
4
|
-
export async function addRev(
|
|
5
|
-
body: { _id?: string; _rev?: string },
|
|
6
|
-
tableId?: string
|
|
7
|
-
) {
|
|
8
|
-
if (!body._id || (tableId && isExternalTable(tableId))) {
|
|
9
|
-
return body
|
|
10
|
-
}
|
|
11
|
-
const db = getAppDB()
|
|
12
|
-
const dbDoc = await db.get(body._id)
|
|
13
|
-
body._rev = dbDoc._rev
|
|
14
|
-
return body
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Performs a case insensitive search on the provided documents, using the
|
|
19
|
-
* provided key and value. This will be a string based search, using the
|
|
20
|
-
* startsWith function.
|
|
21
|
-
*/
|
|
22
|
-
export function search(docs: any[], value: any, key = "name") {
|
|
23
|
-
if (!value || typeof value !== "string") {
|
|
24
|
-
return docs
|
|
25
|
-
}
|
|
26
|
-
value = value.toLowerCase()
|
|
27
|
-
const filtered = []
|
|
28
|
-
for (let doc of docs) {
|
|
29
|
-
if (typeof doc[key] !== "string") {
|
|
30
|
-
continue
|
|
31
|
-
}
|
|
32
|
-
const toTest = doc[key].toLowerCase()
|
|
33
|
-
if (toTest.startsWith(value)) {
|
|
34
|
-
filtered.push(doc)
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return filtered
|
|
38
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import controller from "../../controllers/public/applications"
|
|
2
|
-
import Endpoint from "./utils/Endpoint"
|
|
3
|
-
const { nameValidator, applicationValidator } = require("../utils/validators")
|
|
4
|
-
|
|
5
|
-
const read = [],
|
|
6
|
-
write = []
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @openapi
|
|
10
|
-
* /applications:
|
|
11
|
-
* post:
|
|
12
|
-
* summary: Create an application
|
|
13
|
-
* tags:
|
|
14
|
-
* - applications
|
|
15
|
-
* parameters:
|
|
16
|
-
* - $ref: '#/components/parameters/appId'
|
|
17
|
-
* requestBody:
|
|
18
|
-
* required: true
|
|
19
|
-
* content:
|
|
20
|
-
* application/json:
|
|
21
|
-
* schema:
|
|
22
|
-
* $ref: '#/components/schemas/application'
|
|
23
|
-
* responses:
|
|
24
|
-
* 200:
|
|
25
|
-
* description: Returns the created application.
|
|
26
|
-
* content:
|
|
27
|
-
* application/json:
|
|
28
|
-
* schema:
|
|
29
|
-
* $ref: '#/components/schemas/applicationOutput'
|
|
30
|
-
* examples:
|
|
31
|
-
* application:
|
|
32
|
-
* $ref: '#/components/examples/application'
|
|
33
|
-
*/
|
|
34
|
-
write.push(
|
|
35
|
-
new Endpoint("post", "/applications", controller.create).addMiddleware(
|
|
36
|
-
applicationValidator()
|
|
37
|
-
)
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @openapi
|
|
42
|
-
* /applications/{appId}:
|
|
43
|
-
* put:
|
|
44
|
-
* summary: Update an application
|
|
45
|
-
* tags:
|
|
46
|
-
* - applications
|
|
47
|
-
* parameters:
|
|
48
|
-
* - $ref: '#/components/parameters/appIdUrl'
|
|
49
|
-
* requestBody:
|
|
50
|
-
* required: true
|
|
51
|
-
* content:
|
|
52
|
-
* application/json:
|
|
53
|
-
* schema:
|
|
54
|
-
* $ref: '#/components/schemas/application'
|
|
55
|
-
* responses:
|
|
56
|
-
* 200:
|
|
57
|
-
* description: Returns the updated application.
|
|
58
|
-
* content:
|
|
59
|
-
* application/json:
|
|
60
|
-
* schema:
|
|
61
|
-
* $ref: '#/components/schemas/applicationOutput'
|
|
62
|
-
* examples:
|
|
63
|
-
* application:
|
|
64
|
-
* $ref: '#/components/examples/application'
|
|
65
|
-
*/
|
|
66
|
-
write.push(
|
|
67
|
-
new Endpoint("put", "/applications/:appId", controller.update).addMiddleware(
|
|
68
|
-
applicationValidator()
|
|
69
|
-
)
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @openapi
|
|
74
|
-
* /applications/{appId}:
|
|
75
|
-
* delete:
|
|
76
|
-
* summary: Delete an application
|
|
77
|
-
* tags:
|
|
78
|
-
* - applications
|
|
79
|
-
* parameters:
|
|
80
|
-
* - $ref: '#/components/parameters/appIdUrl'
|
|
81
|
-
* responses:
|
|
82
|
-
* 200:
|
|
83
|
-
* description: Returns the deleted application.
|
|
84
|
-
* content:
|
|
85
|
-
* application/json:
|
|
86
|
-
* schema:
|
|
87
|
-
* $ref: '#/components/schemas/applicationOutput'
|
|
88
|
-
* examples:
|
|
89
|
-
* application:
|
|
90
|
-
* $ref: '#/components/examples/application'
|
|
91
|
-
*/
|
|
92
|
-
write.push(new Endpoint("delete", "/applications/:appId", controller.destroy))
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @openapi
|
|
96
|
-
* /applications/{appId}:
|
|
97
|
-
* get:
|
|
98
|
-
* summary: Retrieve an application
|
|
99
|
-
* tags:
|
|
100
|
-
* - applications
|
|
101
|
-
* parameters:
|
|
102
|
-
* - $ref: '#/components/parameters/appIdUrl'
|
|
103
|
-
* responses:
|
|
104
|
-
* 200:
|
|
105
|
-
* description: Returns the retrieved application.
|
|
106
|
-
* content:
|
|
107
|
-
* application/json:
|
|
108
|
-
* schema:
|
|
109
|
-
* $ref: '#/components/schemas/applicationOutput'
|
|
110
|
-
* examples:
|
|
111
|
-
* application:
|
|
112
|
-
* $ref: '#/components/examples/application'
|
|
113
|
-
*/
|
|
114
|
-
read.push(new Endpoint("get", "/applications/:appId", controller.read))
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @openapi
|
|
118
|
-
* /applications/search:
|
|
119
|
-
* post:
|
|
120
|
-
* summary: Search for applications
|
|
121
|
-
* description: Based on application properties (currently only name) search for applications.
|
|
122
|
-
* tags:
|
|
123
|
-
* - applications
|
|
124
|
-
* parameters:
|
|
125
|
-
* - $ref: '#/components/parameters/appId'
|
|
126
|
-
* requestBody:
|
|
127
|
-
* required: true
|
|
128
|
-
* content:
|
|
129
|
-
* application/json:
|
|
130
|
-
* schema:
|
|
131
|
-
* $ref: '#/components/schemas/nameSearch'
|
|
132
|
-
* responses:
|
|
133
|
-
* 200:
|
|
134
|
-
* description: Returns the applications that were found based on the search parameters.
|
|
135
|
-
* content:
|
|
136
|
-
* application/json:
|
|
137
|
-
* schema:
|
|
138
|
-
* type: object
|
|
139
|
-
* required:
|
|
140
|
-
* - data
|
|
141
|
-
* properties:
|
|
142
|
-
* data:
|
|
143
|
-
* type: array
|
|
144
|
-
* items:
|
|
145
|
-
* $ref: '#/components/schemas/application'
|
|
146
|
-
* examples:
|
|
147
|
-
* applications:
|
|
148
|
-
* $ref: '#/components/examples/applications'
|
|
149
|
-
*/
|
|
150
|
-
read.push(
|
|
151
|
-
new Endpoint("post", "/applications/search", controller.search).addMiddleware(
|
|
152
|
-
nameValidator()
|
|
153
|
-
)
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
export default { read, write }
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import appEndpoints from "./applications"
|
|
2
|
-
import queryEndpoints from "./queries"
|
|
3
|
-
import tableEndpoints from "./tables"
|
|
4
|
-
import rowEndpoints from "./rows"
|
|
5
|
-
import userEndpoints from "./users"
|
|
6
|
-
import usage from "../../../middleware/usageQuota"
|
|
7
|
-
import authorized from "../../../middleware/authorized"
|
|
8
|
-
import { paramResource, paramSubResource } from "../../../middleware/resourceId"
|
|
9
|
-
import { CtxFn } from "./utils/Endpoint"
|
|
10
|
-
import mapperMiddleware from "./middleware/mapper"
|
|
11
|
-
import env from "../../../environment"
|
|
12
|
-
// below imports don't have declaration files
|
|
13
|
-
const Router = require("@koa/router")
|
|
14
|
-
const { RateLimit, Stores } = require("koa2-ratelimit")
|
|
15
|
-
const {
|
|
16
|
-
PermissionLevels,
|
|
17
|
-
PermissionTypes,
|
|
18
|
-
} = require("@budibase/backend-core/permissions")
|
|
19
|
-
const { getRedisOptions } = require("@budibase/backend-core/redis").utils
|
|
20
|
-
|
|
21
|
-
const PREFIX = "/api/public/v1"
|
|
22
|
-
// allow a lot more requests when in test
|
|
23
|
-
const DEFAULT_API_REQ_LIMIT_PER_SEC = env.isTest() ? 100 : 10
|
|
24
|
-
|
|
25
|
-
function getApiLimitPerSecond(): number {
|
|
26
|
-
if (!env.API_REQ_LIMIT_PER_SEC) {
|
|
27
|
-
return DEFAULT_API_REQ_LIMIT_PER_SEC
|
|
28
|
-
}
|
|
29
|
-
return parseInt(env.API_REQ_LIMIT_PER_SEC)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (!env.isTest()) {
|
|
33
|
-
const REDIS_OPTS = getRedisOptions()
|
|
34
|
-
RateLimit.defaultOptions({
|
|
35
|
-
store: new Stores.Redis({
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
socket: {
|
|
38
|
-
host: REDIS_OPTS.host,
|
|
39
|
-
port: REDIS_OPTS.port,
|
|
40
|
-
},
|
|
41
|
-
password: REDIS_OPTS.opts.password,
|
|
42
|
-
database: 1,
|
|
43
|
-
}),
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
// rate limiting, allows for 2 requests per second
|
|
47
|
-
const limiter = RateLimit.middleware({
|
|
48
|
-
interval: { sec: 1 },
|
|
49
|
-
// per ip, per interval
|
|
50
|
-
max: getApiLimitPerSecond(),
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
const publicRouter = new Router({
|
|
54
|
-
prefix: PREFIX,
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
publicRouter.use(limiter)
|
|
58
|
-
|
|
59
|
-
function addMiddleware(
|
|
60
|
-
endpoints: any,
|
|
61
|
-
middleware: CtxFn,
|
|
62
|
-
opts: { output: boolean } = { output: false }
|
|
63
|
-
) {
|
|
64
|
-
if (!endpoints) {
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
if (!Array.isArray(endpoints)) {
|
|
68
|
-
endpoints = [endpoints]
|
|
69
|
-
}
|
|
70
|
-
for (let endpoint of endpoints) {
|
|
71
|
-
if (opts?.output) {
|
|
72
|
-
endpoint.addOutputMiddleware(middleware)
|
|
73
|
-
} else {
|
|
74
|
-
endpoint.addMiddleware(middleware)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function addToRouter(endpoints: any) {
|
|
80
|
-
if (endpoints) {
|
|
81
|
-
for (let endpoint of endpoints) {
|
|
82
|
-
endpoint.apply(publicRouter)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function applyRoutes(
|
|
88
|
-
endpoints: any,
|
|
89
|
-
permType: string,
|
|
90
|
-
resource: string,
|
|
91
|
-
subResource?: string
|
|
92
|
-
) {
|
|
93
|
-
const paramMiddleware = subResource
|
|
94
|
-
? paramSubResource(resource, subResource)
|
|
95
|
-
: paramResource(resource)
|
|
96
|
-
// add the parameter capture middleware
|
|
97
|
-
addMiddleware(endpoints.read, paramMiddleware)
|
|
98
|
-
addMiddleware(endpoints.write, paramMiddleware)
|
|
99
|
-
// add the authorization middleware, using the correct perm type
|
|
100
|
-
addMiddleware(endpoints.read, authorized(permType, PermissionLevels.READ))
|
|
101
|
-
addMiddleware(endpoints.write, authorized(permType, PermissionLevels.WRITE))
|
|
102
|
-
// add the usage quota middleware
|
|
103
|
-
addMiddleware(endpoints.write, usage)
|
|
104
|
-
// add the output mapper middleware
|
|
105
|
-
addMiddleware(endpoints.read, mapperMiddleware, { output: true })
|
|
106
|
-
addMiddleware(endpoints.write, mapperMiddleware, { output: true })
|
|
107
|
-
addToRouter(endpoints.read)
|
|
108
|
-
addToRouter(endpoints.write)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
applyRoutes(appEndpoints, PermissionTypes.APP, "appId")
|
|
112
|
-
applyRoutes(tableEndpoints, PermissionTypes.TABLE, "tableId")
|
|
113
|
-
applyRoutes(userEndpoints, PermissionTypes.USER, "userId")
|
|
114
|
-
applyRoutes(queryEndpoints, PermissionTypes.QUERY, "queryId")
|
|
115
|
-
// needs to be applied last for routing purposes, don't override other endpoints
|
|
116
|
-
applyRoutes(rowEndpoints, PermissionTypes.TABLE, "tableId", "rowId")
|
|
117
|
-
|
|
118
|
-
module.exports = publicRouter
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import mapping from "../../../controllers/public/mapping"
|
|
2
|
-
|
|
3
|
-
enum Resources {
|
|
4
|
-
APPLICATION = "applications",
|
|
5
|
-
TABLES = "tables",
|
|
6
|
-
ROWS = "rows",
|
|
7
|
-
USERS = "users",
|
|
8
|
-
QUERIES = "queries",
|
|
9
|
-
SEARCH = "search",
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function isArrayResponse(ctx: any) {
|
|
13
|
-
return ctx.url.endsWith(Resources.SEARCH) || Array.isArray(ctx.body)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function processApplications(ctx: any) {
|
|
17
|
-
if (isArrayResponse(ctx)) {
|
|
18
|
-
return mapping.mapApplications(ctx)
|
|
19
|
-
} else {
|
|
20
|
-
return mapping.mapApplication(ctx)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function processTables(ctx: any) {
|
|
25
|
-
if (isArrayResponse(ctx)) {
|
|
26
|
-
return mapping.mapTables(ctx)
|
|
27
|
-
} else {
|
|
28
|
-
return mapping.mapTable(ctx)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function processRows(ctx: any) {
|
|
33
|
-
if (isArrayResponse(ctx)) {
|
|
34
|
-
return mapping.mapRowSearch(ctx)
|
|
35
|
-
} else {
|
|
36
|
-
return mapping.mapRow(ctx)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function processUsers(ctx: any) {
|
|
41
|
-
if (isArrayResponse(ctx)) {
|
|
42
|
-
return mapping.mapUsers(ctx)
|
|
43
|
-
} else {
|
|
44
|
-
return mapping.mapUser(ctx)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function processQueries(ctx: any) {
|
|
49
|
-
if (isArrayResponse(ctx)) {
|
|
50
|
-
return mapping.mapQueries(ctx)
|
|
51
|
-
} else {
|
|
52
|
-
return mapping.mapQueryExecution(ctx)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default async (ctx: any, next: any) => {
|
|
57
|
-
let urlParts = ctx.url.split("/")
|
|
58
|
-
urlParts = urlParts.slice(4, urlParts.length)
|
|
59
|
-
let body = {}
|
|
60
|
-
switch (urlParts[0]) {
|
|
61
|
-
case Resources.APPLICATION:
|
|
62
|
-
body = processApplications(ctx)
|
|
63
|
-
break
|
|
64
|
-
case Resources.TABLES:
|
|
65
|
-
if (urlParts[2] === Resources.ROWS) {
|
|
66
|
-
body = processRows(ctx)
|
|
67
|
-
} else {
|
|
68
|
-
body = processTables(ctx)
|
|
69
|
-
}
|
|
70
|
-
break
|
|
71
|
-
case Resources.USERS:
|
|
72
|
-
body = processUsers(ctx)
|
|
73
|
-
break
|
|
74
|
-
case Resources.QUERIES:
|
|
75
|
-
body = processQueries(ctx)
|
|
76
|
-
break
|
|
77
|
-
}
|
|
78
|
-
// update the body based on what has occurred in the mapper
|
|
79
|
-
ctx.body = body
|
|
80
|
-
await next()
|
|
81
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import controller from "../../controllers/public/queries"
|
|
2
|
-
import Endpoint from "./utils/Endpoint"
|
|
3
|
-
import { nameValidator } from "../utils/validators"
|
|
4
|
-
|
|
5
|
-
const read = [],
|
|
6
|
-
write = []
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @openapi
|
|
10
|
-
* /queries/{queryId}:
|
|
11
|
-
* post:
|
|
12
|
-
* summary: Execute a query
|
|
13
|
-
* description: Queries which have been created within a Budibase app can be executed using this,
|
|
14
|
-
* tags:
|
|
15
|
-
* - queries
|
|
16
|
-
* parameters:
|
|
17
|
-
* - $ref: '#/components/parameters/queryId'
|
|
18
|
-
* - $ref: '#/components/parameters/appId'
|
|
19
|
-
* requestBody:
|
|
20
|
-
* required: true
|
|
21
|
-
* content:
|
|
22
|
-
* application/json:
|
|
23
|
-
* schema:
|
|
24
|
-
* $ref: '#/components/schemas/executeQuery'
|
|
25
|
-
* responses:
|
|
26
|
-
* 200:
|
|
27
|
-
* description: Returns the result of the query execution.
|
|
28
|
-
* content:
|
|
29
|
-
* application/json:
|
|
30
|
-
* schema:
|
|
31
|
-
* $ref: '#/components/schemas/executeQueryOutput'
|
|
32
|
-
* examples:
|
|
33
|
-
* REST:
|
|
34
|
-
* $ref: '#/components/examples/restResponse'
|
|
35
|
-
* SQL:
|
|
36
|
-
* $ref: '#/components/examples/sqlResponse'
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
write.push(new Endpoint("post", "/queries/:queryId", controller.execute))
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @openapi
|
|
43
|
-
* /queries/search:
|
|
44
|
-
* post:
|
|
45
|
-
* summary: Search for queries
|
|
46
|
-
* description: Based on query properties (currently only name) search for queries.
|
|
47
|
-
* tags:
|
|
48
|
-
* - queries
|
|
49
|
-
* parameters:
|
|
50
|
-
* - $ref: '#/components/parameters/appId'
|
|
51
|
-
* requestBody:
|
|
52
|
-
* required: true
|
|
53
|
-
* content:
|
|
54
|
-
* application/json:
|
|
55
|
-
* schema:
|
|
56
|
-
* $ref: '#/components/schemas/nameSearch'
|
|
57
|
-
* responses:
|
|
58
|
-
* 200:
|
|
59
|
-
* description: Returns the queries found based on the search parameters.
|
|
60
|
-
* content:
|
|
61
|
-
* application/json:
|
|
62
|
-
* schema:
|
|
63
|
-
* type: object
|
|
64
|
-
* required:
|
|
65
|
-
* - data
|
|
66
|
-
* properties:
|
|
67
|
-
* data:
|
|
68
|
-
* type: array
|
|
69
|
-
* items:
|
|
70
|
-
* $ref: '#/components/schemas/query'
|
|
71
|
-
* examples:
|
|
72
|
-
* queries:
|
|
73
|
-
* $ref: '#/components/examples/queries'
|
|
74
|
-
*/
|
|
75
|
-
read.push(
|
|
76
|
-
new Endpoint("post", "/queries/search", controller.search).addMiddleware(
|
|
77
|
-
nameValidator()
|
|
78
|
-
)
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
export default { read, write }
|