@budibase/server 1.0.79 → 1.0.80-alpha.2
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 +1 -0
- package/builder/assets/{index.c8d1e8f0.css → index.c57242d4.css} +2 -2
- package/builder/assets/index.f3e82852.js +1288 -0
- package/builder/assets/{vendor.20f80cec.js → vendor.a7c6ad0a.js} +190 -216
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2399 -2336
- package/coverage/coverage-final.json +138 -137
- 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 +152 -149
- 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 +94 -82
- 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 +47 -44
- 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 +18 -27
- package/coverage/lcov-report/api/index.html +10 -10
- package/coverage/lcov-report/api/index.js.html +37 -28
- 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 +19 -109
- 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 +18 -156
- 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 +38 -32
- 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 +16 -58
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +15 -78
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/row.js.html +17 -14
- package/coverage/lcov-report/api/routes/screen.js.html +14 -95
- 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 +17 -62
- 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/utils/index.html +111 -0
- package/coverage/lcov-report/api/routes/utils/validators.js.html +737 -0
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/api/routes/webhook.js.html +14 -62
- 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 +12 -9
- 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 +40 -28
- 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 +123 -87
- 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 +89 -74
- 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 +123 -39
- 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 +200 -53
- package/coverage/lcov.info +3323 -3224
- package/dist/api/controllers/application.js +1 -0
- package/dist/api/controllers/public/applications.js +94 -0
- package/dist/api/controllers/public/mapping/applications.js +29 -0
- package/dist/api/controllers/public/mapping/index.js +11 -0
- package/dist/api/controllers/public/mapping/queries.js +36 -0
- package/dist/api/controllers/public/mapping/rows.js +24 -0
- package/dist/api/controllers/public/mapping/tables.js +23 -0
- package/dist/api/controllers/public/mapping/types.js +2 -0
- package/dist/api/controllers/public/mapping/users.js +29 -0
- package/dist/api/controllers/public/queries.js +38 -0
- package/dist/api/controllers/public/rows.js +97 -0
- package/dist/api/controllers/public/tables.js +75 -0
- package/dist/api/controllers/public/users.js +95 -0
- package/dist/api/controllers/public/utils.js +49 -0
- package/dist/api/controllers/row/internal.js +4 -1
- package/dist/api/controllers/table/index.js +2 -1
- package/dist/api/controllers/webhook.js +3 -5
- package/dist/api/index.js +3 -1
- package/dist/api/routes/automation.js +3 -31
- package/dist/api/routes/datasource.js +3 -50
- package/dist/api/routes/index.js +2 -0
- package/dist/api/routes/permission.js +4 -14
- package/dist/api/routes/public/applications.js +141 -0
- package/dist/api/routes/public/index.js +101 -0
- package/dist/api/routes/public/middleware/mapper.js +94 -0
- package/dist/api/routes/public/queries.js +77 -0
- package/dist/api/routes/public/rows.js +229 -0
- package/dist/api/routes/public/tables.js +154 -0
- package/dist/api/routes/public/users.js +137 -0
- package/dist/api/routes/public/utils/Endpoint.js +36 -0
- package/dist/api/routes/role.js +3 -19
- package/dist/api/routes/row.js +3 -4
- package/dist/api/routes/screen.js +2 -23
- package/dist/api/routes/table.js +3 -17
- package/dist/api/routes/tests/utilities/index.js +23 -0
- package/dist/api/routes/utils/validators.js +200 -0
- package/dist/api/routes/webhook.js +2 -17
- 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 +3 -0
- package/dist/db/utils.js +11 -0
- package/dist/definitions/openapi.js +6 -0
- package/dist/environment.js +1 -0
- package/dist/integrations/base/sql.js +16 -1
- package/dist/integrations/base/sqlTable.js +8 -4
- package/dist/integrations/googlesheets.js +3 -0
- package/dist/integrations/microsoftSqlServer.js +60 -43
- package/dist/integrations/mysql.js +3 -0
- package/dist/integrations/oracle.js +14 -19
- package/dist/integrations/postgres.js +34 -28
- package/dist/integrations/utils.js +32 -15
- package/dist/package.json +11 -7
- package/dist/tests/utilities/TestConfiguration.js +25 -8
- package/dist/threads/query.js +33 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/workerRequests.js +50 -15
- package/package.json +12 -8
- package/scripts/integrations/mssql/data/setup.sql +18 -1
- package/scripts/integrations/oracle/oracle.md +2 -2
- package/scripts/integrations/postgres/init.sql +11 -3
- package/scripts/likeCypress.ts +9 -6
- package/specs/generate.js +83 -0
- package/specs/openapi.json +2222 -0
- package/specs/openapi.yaml +1530 -0
- package/specs/parameters.js +59 -0
- package/specs/resources/application.js +101 -0
- package/specs/resources/index.js +24 -0
- package/specs/resources/misc.js +12 -0
- package/specs/resources/query.js +189 -0
- package/specs/resources/row.js +125 -0
- package/specs/resources/table.js +191 -0
- package/specs/resources/user.js +126 -0
- package/specs/resources/utils/Resource.js +26 -0
- package/specs/resources/utils/index.js +11 -0
- package/specs/security.js +7 -0
- package/src/api/controllers/application.js +1 -0
- package/src/api/controllers/public/applications.ts +74 -0
- package/src/api/controllers/public/mapping/applications.ts +32 -0
- package/src/api/controllers/public/mapping/index.ts +13 -0
- package/src/api/controllers/public/mapping/queries.ts +39 -0
- package/src/api/controllers/public/mapping/rows.ts +31 -0
- package/src/api/controllers/public/mapping/tables.ts +26 -0
- package/src/api/controllers/public/mapping/types.ts +13 -0
- package/src/api/controllers/public/mapping/users.ts +32 -0
- package/src/api/controllers/public/queries.ts +20 -0
- package/src/api/controllers/public/rows.ts +77 -0
- package/src/api/controllers/public/tables.ts +56 -0
- package/src/api/controllers/public/users.ts +82 -0
- package/src/api/controllers/public/utils.ts +38 -0
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/internal.js +4 -0
- package/src/api/controllers/table/index.js +2 -1
- package/src/api/controllers/webhook.js +3 -6
- package/src/api/index.js +4 -1
- package/src/api/routes/automation.js +3 -33
- package/src/api/routes/datasource.js +6 -52
- package/src/api/routes/index.js +2 -0
- package/src/api/routes/permission.js +4 -18
- package/src/api/routes/public/applications.ts +156 -0
- package/src/api/routes/public/index.ts +118 -0
- package/src/api/routes/public/middleware/mapper.ts +81 -0
- package/src/api/routes/public/queries.ts +81 -0
- package/src/api/routes/public/rows.ts +242 -0
- package/src/api/routes/public/tables.ts +169 -0
- package/src/api/routes/public/tests/compare.spec.js +184 -0
- package/src/api/routes/public/users.ts +144 -0
- package/src/api/routes/public/utils/Endpoint.ts +51 -0
- package/src/api/routes/role.js +3 -24
- package/src/api/routes/row.js +3 -2
- package/src/api/routes/screen.js +2 -29
- package/src/api/routes/table.js +4 -19
- package/src/api/routes/tests/utilities/index.js +24 -0
- package/src/api/routes/utils/validators.js +219 -0
- package/src/api/routes/webhook.js +2 -18
- package/src/automations/steps/filter.js +3 -2
- package/src/automations/steps/queryRows.js +1 -1
- package/src/automations/utils.js +2 -2
- package/src/constants/index.js +4 -0
- package/src/db/utils.js +12 -0
- package/src/definitions/common.ts +4 -0
- package/src/definitions/datasource.ts +1 -0
- package/src/definitions/openapi.ts +943 -0
- package/src/environment.js +1 -0
- package/src/integrations/base/datasourcePlus.ts +3 -0
- package/src/integrations/base/sql.ts +16 -1
- package/src/integrations/base/sqlTable.ts +11 -7
- package/src/integrations/googlesheets.ts +5 -2
- package/src/integrations/microsoftSqlServer.ts +86 -61
- package/src/integrations/mysql.ts +4 -0
- package/src/integrations/oracle.ts +27 -35
- package/src/integrations/postgres.ts +33 -26
- package/src/integrations/utils.ts +43 -15
- package/src/tests/utilities/TestConfiguration.js +23 -2
- package/src/threads/query.js +37 -9
- package/src/utilities/workerRequests.js +65 -16
- package/builder/assets/index.f28c5d54.js +0 -1352
- package/scripts/proxy/generateProxyConfig.js +0 -70
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
}
|
|
@@ -58,7 +58,7 @@ module External {
|
|
|
58
58
|
) {
|
|
59
59
|
const primary = table.primary
|
|
60
60
|
// if passed in array need to copy for shifting etc
|
|
61
|
-
let idCopy = cloneDeep(id)
|
|
61
|
+
let idCopy: undefined | string | any[] = cloneDeep(id)
|
|
62
62
|
if (filters) {
|
|
63
63
|
// need to map over the filters and make sure the _id field isn't present
|
|
64
64
|
for (let filter of Object.values(filters)) {
|
|
@@ -2,6 +2,7 @@ const linkRows = require("../../../db/linkedRows")
|
|
|
2
2
|
const {
|
|
3
3
|
generateRowID,
|
|
4
4
|
getRowParams,
|
|
5
|
+
getTableIDFromRowID,
|
|
5
6
|
DocumentTypes,
|
|
6
7
|
InternalTables,
|
|
7
8
|
} = require("../../../db/utils")
|
|
@@ -386,6 +387,9 @@ exports.fetchEnrichedRow = async ctx => {
|
|
|
386
387
|
let groups = {},
|
|
387
388
|
tables = {}
|
|
388
389
|
for (let row of response) {
|
|
390
|
+
if (!row.tableId) {
|
|
391
|
+
row.tableId = getTableIDFromRowID(row._id)
|
|
392
|
+
}
|
|
389
393
|
const linkedTableId = row.tableId
|
|
390
394
|
if (groups[linkedTableId] == null) {
|
|
391
395
|
groups[linkedTableId] = [row]
|
|
@@ -48,7 +48,7 @@ exports.fetch = async function (ctx) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
exports.find = async function (ctx) {
|
|
51
|
-
const tableId = ctx.params.
|
|
51
|
+
const tableId = ctx.params.tableId
|
|
52
52
|
ctx.body = await getTable(tableId)
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -70,6 +70,7 @@ exports.destroy = async function (ctx) {
|
|
|
70
70
|
ctx.eventEmitter &&
|
|
71
71
|
ctx.eventEmitter.emitTable(`table:delete`, appId, deletedTable)
|
|
72
72
|
ctx.status = 200
|
|
73
|
+
ctx.table = deletedTable
|
|
73
74
|
ctx.body = { message: `Table ${tableId} deleted.` }
|
|
74
75
|
}
|
|
75
76
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const { generateWebhookID, getWebhookParams } = require("../../db/utils")
|
|
2
2
|
const toJsonSchema = require("to-json-schema")
|
|
3
3
|
const validate = require("jsonschema").validate
|
|
4
|
+
const { WebhookType } = require("../../constants")
|
|
4
5
|
const triggers = require("../../automations/triggers")
|
|
5
6
|
const { getProdAppID } = require("@budibase/backend-core/db")
|
|
6
7
|
const { getAppDB, updateAppId } = require("@budibase/backend-core/context")
|
|
@@ -18,10 +19,6 @@ function Webhook(name, type, target) {
|
|
|
18
19
|
|
|
19
20
|
exports.Webhook = Webhook
|
|
20
21
|
|
|
21
|
-
exports.WebhookType = {
|
|
22
|
-
AUTOMATION: "automation",
|
|
23
|
-
}
|
|
24
|
-
|
|
25
22
|
exports.fetch = async ctx => {
|
|
26
23
|
const db = getAppDB()
|
|
27
24
|
const response = await db.allDocs(
|
|
@@ -62,7 +59,7 @@ exports.buildSchema = async ctx => {
|
|
|
62
59
|
const webhook = await db.get(ctx.params.id)
|
|
63
60
|
webhook.bodySchema = toJsonSchema(ctx.request.body)
|
|
64
61
|
// update the automation outputs
|
|
65
|
-
if (webhook.action.type ===
|
|
62
|
+
if (webhook.action.type === WebhookType.AUTOMATION) {
|
|
66
63
|
let automation = await db.get(webhook.action.target)
|
|
67
64
|
const autoOutputs = automation.definition.trigger.schema.outputs
|
|
68
65
|
let properties = webhook.bodySchema.properties
|
|
@@ -92,7 +89,7 @@ exports.trigger = async ctx => {
|
|
|
92
89
|
validate(ctx.request.body, webhook.bodySchema)
|
|
93
90
|
}
|
|
94
91
|
const target = await db.get(webhook.action.target)
|
|
95
|
-
if (webhook.action.type ===
|
|
92
|
+
if (webhook.action.type === WebhookType.AUTOMATION) {
|
|
96
93
|
// trigger with both the pure request and then expand it
|
|
97
94
|
// incase the user has produced a schema to bind to
|
|
98
95
|
await triggers.externalTrigger(target, {
|
package/src/api/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const {
|
|
|
8
8
|
const currentApp = require("../middleware/currentapp")
|
|
9
9
|
const compress = require("koa-compress")
|
|
10
10
|
const zlib = require("zlib")
|
|
11
|
-
const { mainRoutes, staticRoutes } = require("./routes")
|
|
11
|
+
const { mainRoutes, staticRoutes, publicRoutes } = require("./routes")
|
|
12
12
|
const pkg = require("../../package.json")
|
|
13
13
|
const env = require("../environment")
|
|
14
14
|
|
|
@@ -82,6 +82,9 @@ for (let route of mainRoutes) {
|
|
|
82
82
|
router.use(route.allowedMethods())
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
router.use(publicRoutes.routes())
|
|
86
|
+
router.use(publicRoutes.allowedMethods())
|
|
87
|
+
|
|
85
88
|
// WARNING - static routes will catch everything else after them this must be last
|
|
86
89
|
router.use(staticRoutes.routes())
|
|
87
90
|
router.use(staticRoutes.allowedMethods())
|
|
@@ -1,50 +1,20 @@
|
|
|
1
1
|
const Router = require("@koa/router")
|
|
2
2
|
const controller = require("../controllers/automation")
|
|
3
3
|
const authorized = require("../../middleware/authorized")
|
|
4
|
-
const joiValidator = require("../../middleware/joi-validator")
|
|
5
4
|
const {
|
|
6
5
|
BUILDER,
|
|
7
6
|
PermissionLevels,
|
|
8
7
|
PermissionTypes,
|
|
9
8
|
} = require("@budibase/backend-core/permissions")
|
|
10
|
-
const Joi = require("joi")
|
|
11
9
|
const { bodyResource, paramResource } = require("../../middleware/resourceId")
|
|
12
10
|
const {
|
|
13
11
|
middleware: appInfoMiddleware,
|
|
14
12
|
AppType,
|
|
15
13
|
} = require("../../middleware/appInfo")
|
|
14
|
+
const { automationValidator } = require("./utils/validators")
|
|
16
15
|
|
|
17
16
|
const router = Router()
|
|
18
17
|
|
|
19
|
-
// prettier-ignore
|
|
20
|
-
function generateStepSchema(allowStepTypes) {
|
|
21
|
-
return Joi.object({
|
|
22
|
-
stepId: Joi.string().required(),
|
|
23
|
-
id: Joi.string().required(),
|
|
24
|
-
description: Joi.string().required(),
|
|
25
|
-
name: Joi.string().required(),
|
|
26
|
-
tagline: Joi.string().required(),
|
|
27
|
-
icon: Joi.string().required(),
|
|
28
|
-
params: Joi.object(),
|
|
29
|
-
args: Joi.object(),
|
|
30
|
-
type: Joi.string().required().valid(...allowStepTypes),
|
|
31
|
-
}).unknown(true)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function generateValidator(existing = false) {
|
|
35
|
-
// prettier-ignore
|
|
36
|
-
return joiValidator.body(Joi.object({
|
|
37
|
-
_id: existing ? Joi.string().required() : Joi.string(),
|
|
38
|
-
_rev: existing ? Joi.string().required() : Joi.string(),
|
|
39
|
-
name: Joi.string().required(),
|
|
40
|
-
type: Joi.string().valid("automation").required(),
|
|
41
|
-
definition: Joi.object({
|
|
42
|
-
steps: Joi.array().required().items(generateStepSchema(["ACTION", "LOGIC"])),
|
|
43
|
-
trigger: generateStepSchema(["TRIGGER"]).allow(null),
|
|
44
|
-
}).required().unknown(true),
|
|
45
|
-
}).unknown(true))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
18
|
router
|
|
49
19
|
.get(
|
|
50
20
|
"/api/automations/trigger/list",
|
|
@@ -72,13 +42,13 @@ router
|
|
|
72
42
|
"/api/automations",
|
|
73
43
|
bodyResource("_id"),
|
|
74
44
|
authorized(BUILDER),
|
|
75
|
-
|
|
45
|
+
automationValidator(true),
|
|
76
46
|
controller.update
|
|
77
47
|
)
|
|
78
48
|
.post(
|
|
79
49
|
"/api/automations",
|
|
80
50
|
authorized(BUILDER),
|
|
81
|
-
|
|
51
|
+
automationValidator(false),
|
|
82
52
|
controller.create
|
|
83
53
|
)
|
|
84
54
|
.delete(
|
|
@@ -1,64 +1,18 @@
|
|
|
1
1
|
const Router = require("@koa/router")
|
|
2
2
|
const datasourceController = require("../controllers/datasource")
|
|
3
3
|
const authorized = require("../../middleware/authorized")
|
|
4
|
-
const joiValidator = require("../../middleware/joi-validator")
|
|
5
4
|
const {
|
|
6
5
|
BUILDER,
|
|
7
6
|
PermissionLevels,
|
|
8
7
|
PermissionTypes,
|
|
9
8
|
} = require("@budibase/backend-core/permissions")
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
const {
|
|
10
|
+
datasourceValidator,
|
|
11
|
+
datasourceQueryValidator,
|
|
12
|
+
} = require("./utils/validators")
|
|
12
13
|
|
|
13
14
|
const router = Router()
|
|
14
15
|
|
|
15
|
-
function generateDatasourceSchema() {
|
|
16
|
-
// prettier-ignore
|
|
17
|
-
return joiValidator.body(Joi.object({
|
|
18
|
-
_id: Joi.string(),
|
|
19
|
-
_rev: Joi.string(),
|
|
20
|
-
// source: Joi.string().valid("POSTGRES_PLUS"),
|
|
21
|
-
type: Joi.string().allow("datasource_plus"),
|
|
22
|
-
relationships: Joi.array().items(Joi.object({
|
|
23
|
-
from: Joi.string().required(),
|
|
24
|
-
to: Joi.string().required(),
|
|
25
|
-
cardinality: Joi.valid("1:N", "1:1", "N:N").required()
|
|
26
|
-
})),
|
|
27
|
-
// entities: Joi.array().items(Joi.object({
|
|
28
|
-
// type: Joi.string().valid(...Object.values(FieldTypes)).required(),
|
|
29
|
-
// name: Joi.string().required(),
|
|
30
|
-
// })),
|
|
31
|
-
}).unknown(true))
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function generateQueryDatasourceSchema() {
|
|
35
|
-
// prettier-ignore
|
|
36
|
-
return joiValidator.body(Joi.object({
|
|
37
|
-
endpoint: Joi.object({
|
|
38
|
-
datasourceId: Joi.string().required(),
|
|
39
|
-
operation: Joi.string().required().valid(...Object.values(DataSourceOperation)),
|
|
40
|
-
entityId: Joi.string().required(),
|
|
41
|
-
}).required(),
|
|
42
|
-
resource: Joi.object({
|
|
43
|
-
fields: Joi.array().items(Joi.string()).optional(),
|
|
44
|
-
}).optional(),
|
|
45
|
-
body: Joi.object().optional(),
|
|
46
|
-
sort: Joi.object().optional(),
|
|
47
|
-
filters: Joi.object({
|
|
48
|
-
string: Joi.object().optional(),
|
|
49
|
-
range: Joi.object().optional(),
|
|
50
|
-
equal: Joi.object().optional(),
|
|
51
|
-
notEqual: Joi.object().optional(),
|
|
52
|
-
empty: Joi.object().optional(),
|
|
53
|
-
notEmpty: Joi.object().optional(),
|
|
54
|
-
}).optional(),
|
|
55
|
-
paginate: Joi.object({
|
|
56
|
-
page: Joi.string().alphanum().optional(),
|
|
57
|
-
limit: Joi.number().optional(),
|
|
58
|
-
}).optional(),
|
|
59
|
-
}))
|
|
60
|
-
}
|
|
61
|
-
|
|
62
16
|
router
|
|
63
17
|
.get("/api/datasources", authorized(BUILDER), datasourceController.fetch)
|
|
64
18
|
.get(
|
|
@@ -74,7 +28,7 @@ router
|
|
|
74
28
|
.post(
|
|
75
29
|
"/api/datasources/query",
|
|
76
30
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
|
77
|
-
|
|
31
|
+
datasourceQueryValidator(),
|
|
78
32
|
datasourceController.query
|
|
79
33
|
)
|
|
80
34
|
.post(
|
|
@@ -85,7 +39,7 @@ router
|
|
|
85
39
|
.post(
|
|
86
40
|
"/api/datasources",
|
|
87
41
|
authorized(BUILDER),
|
|
88
|
-
|
|
42
|
+
datasourceValidator(),
|
|
89
43
|
datasourceController.save
|
|
90
44
|
)
|
|
91
45
|
.delete(
|
package/src/api/routes/index.js
CHANGED
|
@@ -25,6 +25,7 @@ const metadataRoutes = require("./metadata")
|
|
|
25
25
|
const devRoutes = require("./dev")
|
|
26
26
|
const cloudRoutes = require("./cloud")
|
|
27
27
|
const migrationRoutes = require("./migrations")
|
|
28
|
+
const publicRoutes = require("./public")
|
|
28
29
|
|
|
29
30
|
exports.mainRoutes = [
|
|
30
31
|
authRoutes,
|
|
@@ -57,4 +58,5 @@ exports.mainRoutes = [
|
|
|
57
58
|
migrationRoutes,
|
|
58
59
|
]
|
|
59
60
|
|
|
61
|
+
exports.publicRoutes = publicRoutes
|
|
60
62
|
exports.staticRoutes = staticRoutes
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
const Router = require("@koa/router")
|
|
2
2
|
const controller = require("../controllers/permission")
|
|
3
3
|
const authorized = require("../../middleware/authorized")
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
PermissionLevels,
|
|
7
|
-
} = require("@budibase/backend-core/permissions")
|
|
8
|
-
const Joi = require("joi")
|
|
9
|
-
const joiValidator = require("../../middleware/joi-validator")
|
|
4
|
+
const { BUILDER } = require("@budibase/backend-core/permissions")
|
|
5
|
+
const { permissionValidator } = require("./utils/validators")
|
|
10
6
|
|
|
11
7
|
const router = Router()
|
|
12
8
|
|
|
13
|
-
function generateValidator() {
|
|
14
|
-
const permLevelArray = Object.values(PermissionLevels)
|
|
15
|
-
// prettier-ignore
|
|
16
|
-
return joiValidator.params(Joi.object({
|
|
17
|
-
level: Joi.string().valid(...permLevelArray).required(),
|
|
18
|
-
resourceId: Joi.string(),
|
|
19
|
-
roleId: Joi.string(),
|
|
20
|
-
}).unknown(true))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
9
|
router
|
|
24
10
|
.get("/api/permission/builtin", authorized(BUILDER), controller.fetchBuiltin)
|
|
25
11
|
.get("/api/permission/levels", authorized(BUILDER), controller.fetchLevels)
|
|
@@ -33,14 +19,14 @@ router
|
|
|
33
19
|
.post(
|
|
34
20
|
"/api/permission/:roleId/:resourceId/:level",
|
|
35
21
|
authorized(BUILDER),
|
|
36
|
-
|
|
22
|
+
permissionValidator(),
|
|
37
23
|
controller.addPermission
|
|
38
24
|
)
|
|
39
25
|
// deleting the level defaults it back the underlying access control for the resource
|
|
40
26
|
.delete(
|
|
41
27
|
"/api/permission/:roleId/:resourceId/:level",
|
|
42
28
|
authorized(BUILDER),
|
|
43
|
-
|
|
29
|
+
permissionValidator(),
|
|
44
30
|
controller.removePermission
|
|
45
31
|
)
|
|
46
32
|
|
|
@@ -0,0 +1,156 @@
|
|
|
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 }
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|