@budibase/server 1.0.49-alpha.6 → 1.0.49
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__/arangojs.ts +1 -1
- package/__mocks__/aws-sdk.ts +4 -4
- package/__mocks__/mongodb.ts +5 -4
- package/__mocks__/mssql.ts +3 -3
- package/__mocks__/node-fetch.ts +1 -2
- package/__mocks__/pg.ts +5 -3
- package/builder/assets/{index.1b905242.js → index.2c37968e.js} +231 -234
- package/builder/assets/index.39e01193.css +1 -0
- package/builder/assets/{vendor.d526bfe8.js → vendor.f9faf6ab.js} +12 -12
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2816 -3119
- package/coverage/coverage-final.json +101 -106
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +152 -257
- package/coverage/lcov-report/api/controllers/auth.js.html +13 -22
- package/coverage/lcov-report/api/controllers/automation.js.html +69 -39
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -8
- package/coverage/lcov-report/api/controllers/component.js.html +16 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +51 -81
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- package/coverage/lcov-report/{utilities/usageQuota/usageQuoteReset.js.html → api/controllers/hosting.js.html} +48 -36
- package/coverage/lcov-report/api/controllers/index.html +76 -76
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
- package/coverage/lcov-report/api/controllers/metadata.js.html +21 -6
- package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
- package/coverage/lcov-report/api/controllers/query/index.html +10 -10
- package/coverage/lcov-report/api/controllers/query/index.js.html +35 -38
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
- package/coverage/lcov-report/api/controllers/role.js.html +16 -16
- package/coverage/lcov-report/api/controllers/routing.js.html +10 -7
- package/coverage/lcov-report/api/controllers/row/external.js.html +27 -21
- package/coverage/lcov-report/api/controllers/row/index.html +34 -49
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +226 -118
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +34 -52
- package/coverage/lcov-report/api/controllers/row/utils.js.html +62 -47
- package/coverage/lcov-report/api/controllers/screen.js.html +21 -15
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/external.js.html +34 -25
- package/coverage/lcov-report/api/controllers/table/index.html +43 -58
- package/coverage/lcov-report/api/controllers/table/index.js.html +82 -58
- package/coverage/lcov-report/api/controllers/table/internal.js.html +66 -81
- package/coverage/lcov-report/api/controllers/table/utils.js.html +110 -218
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +50 -47
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +16 -16
- package/coverage/lcov-report/api/controllers/view/index.js.html +33 -27
- package/coverage/lcov-report/api/controllers/view/utils.js.html +20 -35
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +28 -34
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +8 -8
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/{migrations.js.html → hosting.js.html} +14 -17
- package/coverage/lcov-report/api/routes/index.html +18 -18
- package/coverage/lcov-report/api/routes/index.js.html +3 -3
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +2 -17
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +10 -7
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +22 -13
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
- 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 +7 -7
- package/coverage/lcov-report/automations/steps/index.html +13 -13
- 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 +10 -10
- 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 +7 -7
- 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 +55 -61
- package/coverage/lcov-report/automations/utils.js.html +42 -54
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +26 -53
- 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 +37 -25
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +96 -51
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +87 -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 +5 -5
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +120 -135
- 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 +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +65 -173
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +83 -95
- package/coverage/lcov-report/middleware/index.html +38 -38
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +53 -281
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +24 -30
- package/coverage/lcov-report/threads/index.html +26 -26
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +26 -62
- 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 +49 -58
- package/coverage/lcov-report/utilities/index.html +37 -37
- package/coverage/lcov-report/utilities/index.js.html +73 -43
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
- 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 +7 -7
- package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +103 -97
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +27 -75
- 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/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +112 -43
- package/coverage/lcov.info +4423 -5022
- package/dist/api/controllers/application.js +60 -90
- package/dist/api/controllers/auth.js +5 -8
- package/dist/api/controllers/automation.js +19 -14
- package/dist/api/controllers/cloud.js +3 -2
- package/dist/api/controllers/component.js +4 -3
- package/dist/api/controllers/datasource.js +10 -20
- package/dist/api/controllers/deploy/Deployment.js +6 -3
- package/dist/api/controllers/deploy/index.js +13 -12
- package/dist/api/controllers/dev.js +5 -5
- package/dist/api/controllers/hosting.js +30 -0
- package/dist/api/controllers/layout.js +3 -3
- package/dist/api/controllers/metadata.js +4 -4
- package/dist/api/controllers/permission.js +4 -4
- package/dist/api/controllers/query/import/index.js +6 -4
- package/dist/api/controllers/query/index.js +10 -11
- package/dist/api/controllers/role.js +5 -5
- package/dist/api/controllers/routing.js +6 -5
- package/dist/api/controllers/row/ExternalRequest.js +63 -76
- package/dist/api/controllers/row/external.js +4 -4
- package/dist/api/controllers/row/internal.js +93 -55
- package/dist/api/controllers/row/internalSearch.js +17 -23
- package/dist/api/controllers/row/utils.js +14 -13
- package/dist/api/controllers/screen.js +7 -5
- package/dist/api/controllers/static/index.js +12 -61
- package/dist/api/controllers/table/external.js +10 -7
- package/dist/api/controllers/table/index.js +13 -16
- package/dist/api/controllers/table/internal.js +16 -22
- package/dist/api/controllers/table/utils.js +35 -62
- package/dist/api/controllers/user.js +20 -18
- package/dist/api/controllers/view/index.js +10 -8
- package/dist/api/controllers/view/utils.js +4 -9
- package/dist/api/controllers/webhook.js +8 -10
- package/dist/api/routes/hosting.js +11 -0
- package/dist/api/routes/index.js +2 -2
- package/dist/api/routes/static.js +1 -2
- package/dist/api/routes/tests/utilities/TestFunctions.js +17 -37
- package/dist/app.js +5 -35
- package/dist/automations/automationUtils.js +3 -2
- package/dist/automations/steps/createRow.js +5 -3
- package/dist/automations/steps/deleteRow.js +4 -1
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +25 -27
- package/dist/automations/utils.js +5 -10
- package/dist/constants/index.js +0 -7
- package/dist/db/linkedRows/LinkController.js +7 -3
- package/dist/db/linkedRows/index.js +27 -16
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +10 -9
- package/dist/definitions/datasource.js +0 -1
- package/dist/environment.js +1 -4
- package/dist/integrations/base/sql.js +6 -13
- package/dist/integrations/index.js +0 -3
- package/dist/integrations/utils.js +9 -60
- package/dist/middleware/authorized.js +30 -57
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +37 -41
- package/dist/middleware/usageQuota.js +15 -82
- package/dist/package.json +5 -8
- package/dist/tests/utilities/TestConfiguration.js +50 -80
- package/dist/threads/automation.js +11 -13
- package/dist/threads/query.js +13 -23
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +3 -4
- package/dist/utilities/global.js +12 -15
- package/dist/utilities/index.js +17 -7
- package/dist/utilities/routing/index.js +5 -5
- package/dist/utilities/rowProcessor/index.js +17 -23
- package/dist/utilities/rowProcessor/utils.js +4 -14
- package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -45
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +24 -4
- package/nodemon.json +1 -1
- package/package.json +6 -9
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/application.js +50 -85
- package/src/api/controllers/auth.js +5 -8
- package/src/api/controllers/automation.js +23 -13
- package/src/api/controllers/cloud.js +3 -2
- package/src/api/controllers/component.js +4 -3
- package/src/api/controllers/datasource.js +11 -21
- package/src/api/controllers/deploy/Deployment.js +7 -3
- package/src/api/controllers/deploy/index.js +13 -20
- package/src/api/controllers/dev.js +5 -5
- package/src/api/controllers/hosting.js +22 -0
- package/src/api/controllers/layout.js +3 -3
- package/src/api/controllers/metadata.js +9 -4
- package/src/api/controllers/permission.js +4 -4
- package/src/api/controllers/query/import/index.ts +6 -4
- package/src/api/controllers/query/import/tests/index.spec.js +1 -2
- package/src/api/controllers/query/index.js +10 -11
- package/src/api/controllers/role.js +5 -5
- package/src/api/controllers/routing.js +6 -5
- package/src/api/controllers/row/ExternalRequest.ts +42 -53
- package/src/api/controllers/row/external.js +6 -4
- package/src/api/controllers/row/internal.js +90 -54
- package/src/api/controllers/row/internalSearch.js +17 -23
- package/src/api/controllers/row/utils.js +18 -13
- package/src/api/controllers/screen.js +7 -5
- package/src/api/controllers/static/index.js +12 -65
- package/src/api/controllers/table/external.js +10 -7
- package/src/api/controllers/table/index.js +28 -20
- package/src/api/controllers/table/internal.js +19 -24
- package/src/api/controllers/table/utils.js +42 -78
- package/src/api/controllers/user.js +20 -19
- package/src/api/controllers/view/index.js +10 -8
- package/src/api/controllers/view/utils.js +4 -9
- package/src/api/controllers/webhook.js +8 -10
- package/src/api/routes/hosting.js +13 -0
- package/src/api/routes/index.js +2 -2
- package/src/api/routes/static.js +0 -5
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +2 -1
- package/src/api/routes/tests/automation.spec.js +0 -1
- package/src/api/routes/tests/hosting.spec.js +36 -0
- package/src/api/routes/tests/misc.spec.js +1 -0
- package/src/api/routes/tests/routing.spec.js +12 -21
- package/src/api/routes/tests/row.spec.js +4 -7
- package/src/api/routes/tests/utilities/TestFunctions.js +17 -39
- package/src/app.ts +5 -18
- package/src/automations/automationUtils.js +3 -2
- package/src/automations/steps/createRow.js +5 -2
- package/src/automations/steps/deleteRow.js +4 -1
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +31 -33
- package/src/automations/utils.js +5 -9
- package/src/constants/index.js +0 -9
- package/src/db/linkedRows/LinkController.js +7 -3
- package/src/db/linkedRows/index.js +31 -16
- package/src/db/linkedRows/linkUtils.js +6 -6
- package/src/db/tests/linkController.spec.js +1 -0
- package/src/db/tests/linkTests.spec.js +6 -5
- package/src/db/views/staticViews.js +10 -8
- package/src/definitions/common.ts +0 -3
- package/src/definitions/datasource.ts +0 -3
- package/src/environment.js +1 -4
- package/src/integrations/base/sql.ts +7 -14
- package/src/integrations/index.ts +0 -3
- package/src/integrations/tests/sql.spec.js +0 -16
- package/src/integrations/utils.ts +12 -75
- package/src/middleware/authorized.js +30 -66
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +46 -50
- package/src/middleware/tests/authorized.spec.js +6 -13
- package/src/middleware/tests/currentapp.spec.js +0 -6
- package/src/middleware/tests/usageQuota.spec.js +24 -18
- package/src/middleware/usageQuota.js +17 -93
- package/src/tests/utilities/TestConfiguration.js +55 -82
- package/src/threads/automation.js +15 -17
- package/src/threads/query.js +14 -26
- package/src/utilities/fileSystem/index.js +3 -4
- package/src/utilities/global.js +12 -15
- package/src/utilities/index.js +17 -7
- package/src/utilities/routing/index.js +5 -5
- package/src/utilities/rowProcessor/index.js +27 -25
- package/src/utilities/rowProcessor/utils.js +7 -23
- package/src/utilities/usageQuota.js +73 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +27 -4
- package/builder/assets/index.83c0944f.css +0 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +0 -119
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +0 -548
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +0 -599
- package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -305
- package/dist/api/controllers/migrations.js +0 -21
- package/dist/api/controllers/row/staticFormula.js +0 -147
- package/dist/api/controllers/table/bulkFormula.js +0 -159
- package/dist/api/routes/migrations.js +0 -9
- package/dist/integrations/googlesheets.js +0 -340
- package/dist/migrations/functions/appUrls.js +0 -46
- package/dist/migrations/functions/quotas1.js +0 -50
- package/dist/migrations/functions/usageQuotas/index.js +0 -20
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -30
- package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
- package/dist/migrations/functions/userEmailViewCasing.js +0 -24
- package/dist/migrations/index.js +0 -62
- package/dist/utilities/usageQuota/rows.js +0 -78
- package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
- package/src/api/controllers/migrations.js +0 -13
- package/src/api/controllers/row/staticFormula.js +0 -156
- package/src/api/controllers/table/bulkFormula.js +0 -173
- package/src/api/routes/migrations.js +0 -14
- package/src/api/routes/tests/static.spec.js +0 -98
- package/src/integrations/googlesheets.ts +0 -353
- package/src/migrations/functions/appUrls.ts +0 -34
- package/src/migrations/functions/quotas1.ts +0 -20
- package/src/migrations/functions/tests/appUrls.spec.js +0 -29
- package/src/migrations/functions/tests/quotas1.spec.js +0 -27
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +0 -25
- package/src/migrations/functions/usageQuotas/index.ts +0 -8
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -19
- package/src/migrations/functions/usageQuotas/syncRows.ts +0 -22
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
- package/src/migrations/functions/userEmailViewCasing.ts +0 -13
- package/src/migrations/index.ts +0 -56
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
- package/src/utilities/usageQuota/index.js +0 -93
- package/src/utilities/usageQuota/rows.js +0 -75
- package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
|
@@ -11,12 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const LinkController = require("./LinkController");
|
|
12
12
|
const { IncludeDocs, getLinkDocuments, createLinkView, getUniqueByProp, getRelatedTableForField, getLinkedTableIDs, getLinkedTable, } = require("./linkUtils");
|
|
13
13
|
const { flatten } = require("lodash");
|
|
14
|
+
const CouchDB = require("../../db");
|
|
14
15
|
const { FieldTypes } = require("../../constants");
|
|
15
16
|
const { getMultiIDParams, USER_METDATA_PREFIX } = require("../../db/utils");
|
|
16
17
|
const { partition } = require("lodash");
|
|
17
18
|
const { getGlobalUsersFromMetadata } = require("../../utilities/global");
|
|
18
19
|
const { processFormulas } = require("../../utilities/rowProcessor/utils");
|
|
19
|
-
const { getAppDB } = require("@budibase/backend-core/context");
|
|
20
20
|
/**
|
|
21
21
|
* This functionality makes sure that when rows with links are created, updated or deleted they are processed
|
|
22
22
|
* correctly - making sure that no stale links are left around and that all links have been made successfully.
|
|
@@ -45,11 +45,12 @@ function clearRelationshipFields(table, rows) {
|
|
|
45
45
|
}
|
|
46
46
|
return rows;
|
|
47
47
|
}
|
|
48
|
-
function getLinksForRows(rows) {
|
|
48
|
+
function getLinksForRows(appId, rows) {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
50
|
const tableIds = [...new Set(rows.map(el => el.tableId))];
|
|
51
51
|
// start by getting all the link values for performance reasons
|
|
52
52
|
const responses = flatten(yield Promise.all(tableIds.map(tableId => getLinkDocuments({
|
|
53
|
+
appId,
|
|
53
54
|
tableId: tableId,
|
|
54
55
|
includeDocs: IncludeDocs.EXCLUDE,
|
|
55
56
|
}))));
|
|
@@ -60,10 +61,10 @@ function getLinksForRows(rows) {
|
|
|
60
61
|
.map(el => (Object.assign(Object.assign({}, el), { unique: el.id + el.thisId + el.fieldName }))), "unique");
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
|
-
function getFullLinkedDocs(links) {
|
|
64
|
+
function getFullLinkedDocs(ctx, appId, links) {
|
|
64
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
66
|
// create DBs
|
|
66
|
-
const db =
|
|
67
|
+
const db = new CouchDB(appId);
|
|
67
68
|
const linkedRowIds = links.map(link => link.id);
|
|
68
69
|
const uniqueRowIds = [...new Set(linkedRowIds)];
|
|
69
70
|
let dbRows = (yield db.allDocs(getMultiIDParams(uniqueRowIds))).rows.map(row => row.doc);
|
|
@@ -73,7 +74,7 @@ function getFullLinkedDocs(links) {
|
|
|
73
74
|
.filter(row => row != null);
|
|
74
75
|
// need to handle users as specific cases
|
|
75
76
|
let [users, other] = partition(linked, linkRow => linkRow._id.startsWith(USER_METDATA_PREFIX));
|
|
76
|
-
users = yield getGlobalUsersFromMetadata(users);
|
|
77
|
+
users = yield getGlobalUsersFromMetadata(appId, users);
|
|
77
78
|
return [...other, ...users];
|
|
78
79
|
});
|
|
79
80
|
}
|
|
@@ -81,17 +82,21 @@ function getFullLinkedDocs(links) {
|
|
|
81
82
|
* Update link documents for a row or table - this is to be called by the API controller when a change is occurring.
|
|
82
83
|
* @param {string} args.eventType states what type of change which is occurring, means this can be expanded upon in the
|
|
83
84
|
* future quite easily (all updates go through one function).
|
|
85
|
+
* @param {string} args.appId The ID of the instance in which the change is occurring.
|
|
84
86
|
* @param {string} args.tableId The ID of the of the table which is being changed.
|
|
85
|
-
* @param {object|
|
|
86
|
-
* @param {object|
|
|
87
|
-
* @param {object|
|
|
87
|
+
* @param {object|null} args.row The row which is changing, e.g. created, updated or deleted.
|
|
88
|
+
* @param {object|null} args.table If the table has already been retrieved this can be used to reduce database gets.
|
|
89
|
+
* @param {object|null} args.oldTable If the table is being updated then the old table can be provided for differencing.
|
|
88
90
|
* @returns {Promise<object>} When the update is complete this will respond successfully. Returns the row for
|
|
89
91
|
* row operations and the table for table operations.
|
|
90
92
|
*/
|
|
91
93
|
exports.updateLinks = function (args) {
|
|
92
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const { eventType, row, tableId, table, oldTable } = args;
|
|
95
|
+
const { eventType, appId, row, tableId, table, oldTable } = args;
|
|
94
96
|
const baseReturnObj = row == null ? table : row;
|
|
97
|
+
if (appId == null) {
|
|
98
|
+
throw "Cannot operate without an instance ID.";
|
|
99
|
+
}
|
|
95
100
|
// make sure table ID is set
|
|
96
101
|
if (tableId == null && table != null) {
|
|
97
102
|
args.tableId = table._id;
|
|
@@ -127,21 +132,25 @@ exports.updateLinks = function (args) {
|
|
|
127
132
|
/**
|
|
128
133
|
* Given a table and a list of rows this will retrieve all of the attached docs and enrich them into the row.
|
|
129
134
|
* This is required for formula fields, this may only be utilised internally (for now).
|
|
135
|
+
* @param {object} ctx The request which is looking for rows.
|
|
130
136
|
* @param {object} table The table from which the rows originated.
|
|
131
137
|
* @param {array<object>} rows The rows which are to be enriched.
|
|
132
138
|
* @return {Promise<*>} returns the rows with all of the enriched relationships on it.
|
|
133
139
|
*/
|
|
134
|
-
exports.attachFullLinkedDocs = (table, rows) => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
exports.attachFullLinkedDocs = (ctx, table, rows) => __awaiter(void 0, void 0, void 0, function* () {
|
|
141
|
+
const appId = ctx.appId;
|
|
135
142
|
const linkedTableIds = getLinkedTableIDs(table);
|
|
136
143
|
if (linkedTableIds.length === 0) {
|
|
137
144
|
return rows;
|
|
138
145
|
}
|
|
146
|
+
// create DBs
|
|
147
|
+
const db = new CouchDB(appId);
|
|
139
148
|
// get all the links
|
|
140
|
-
const links = (yield getLinksForRows(rows)).filter(link => rows.some(row => row._id === link.thisId));
|
|
149
|
+
const links = (yield getLinksForRows(appId, rows)).filter(link => rows.some(row => row._id === link.thisId));
|
|
141
150
|
// clear any existing links that could be dupe'd
|
|
142
151
|
rows = clearRelationshipFields(table, rows);
|
|
143
152
|
// now get the docs and combine into the rows
|
|
144
|
-
let linked = yield getFullLinkedDocs(links);
|
|
153
|
+
let linked = yield getFullLinkedDocs(ctx, appId, links);
|
|
145
154
|
const linkedTables = [];
|
|
146
155
|
for (let row of rows) {
|
|
147
156
|
for (let link of links.filter(link => link.thisId === row._id)) {
|
|
@@ -151,7 +160,7 @@ exports.attachFullLinkedDocs = (table, rows) => __awaiter(void 0, void 0, void 0
|
|
|
151
160
|
const linkedRow = linked.find(row => row._id === link.id);
|
|
152
161
|
if (linkedRow) {
|
|
153
162
|
const linkedTableId = linkedRow.tableId || getRelatedTableForField(table, link.fieldName);
|
|
154
|
-
const linkedTable = yield getLinkedTable(linkedTableId, linkedTables);
|
|
163
|
+
const linkedTable = yield getLinkedTable(db, linkedTableId, linkedTables);
|
|
155
164
|
if (linkedTable) {
|
|
156
165
|
row[link.fieldName].push(processFormulas(linkedTable, linkedRow));
|
|
157
166
|
}
|
|
@@ -162,16 +171,18 @@ exports.attachFullLinkedDocs = (table, rows) => __awaiter(void 0, void 0, void 0
|
|
|
162
171
|
});
|
|
163
172
|
/**
|
|
164
173
|
* This function will take the given enriched rows and squash the links to only contain the primary display field.
|
|
174
|
+
* @param {string} appId The app in which the tables/rows/links exist.
|
|
165
175
|
* @param {object} table The table from which the rows originated.
|
|
166
176
|
* @param {array<object>} enriched The pre-enriched rows (full docs) which are to be squashed.
|
|
167
177
|
* @returns {Promise<Array>} The rows after having their links squashed to only contain the ID and primary display.
|
|
168
178
|
*/
|
|
169
|
-
exports.squashLinksToPrimaryDisplay = (table, enriched) => __awaiter(void 0, void 0, void 0, function* () {
|
|
179
|
+
exports.squashLinksToPrimaryDisplay = (appId, table, enriched) => __awaiter(void 0, void 0, void 0, function* () {
|
|
180
|
+
const db = new CouchDB(appId);
|
|
170
181
|
// will populate this as we find them
|
|
171
182
|
const linkedTables = [table];
|
|
172
183
|
for (let row of enriched) {
|
|
173
184
|
// this only fetches the table if its not already in array
|
|
174
|
-
const rowTable = yield getLinkedTable(row.tableId, linkedTables);
|
|
185
|
+
const rowTable = yield getLinkedTable(db, row.tableId, linkedTables);
|
|
175
186
|
for (let [column, schema] of Object.entries(rowTable.schema)) {
|
|
176
187
|
if (schema.type !== FieldTypes.LINK || !Array.isArray(row[column])) {
|
|
177
188
|
continue;
|
|
@@ -179,7 +190,7 @@ exports.squashLinksToPrimaryDisplay = (table, enriched) => __awaiter(void 0, voi
|
|
|
179
190
|
const newLinks = [];
|
|
180
191
|
for (let link of row[column]) {
|
|
181
192
|
const linkTblId = link.tableId || getRelatedTableForField(table, column);
|
|
182
|
-
const linkedTable = yield getLinkedTable(linkTblId, linkedTables);
|
|
193
|
+
const linkedTable = yield getLinkedTable(db, linkTblId, linkedTables);
|
|
183
194
|
const obj = { _id: link._id };
|
|
184
195
|
if (link[linkedTable.primaryDisplay]) {
|
|
185
196
|
obj.primaryDisplay = link[linkedTable.primaryDisplay];
|
|
@@ -8,11 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
const CouchDB = require("../index");
|
|
11
12
|
const Sentry = require("@sentry/node");
|
|
12
13
|
const { ViewNames, getQueryIndex } = require("../utils");
|
|
13
14
|
const { FieldTypes } = require("../../constants");
|
|
14
15
|
const { createLinkView } = require("../views/staticViews");
|
|
15
|
-
const { getAppDB } = require("@budibase/backend-core/context");
|
|
16
16
|
/**
|
|
17
17
|
* Only needed so that boolean parameters are being used for includeDocs
|
|
18
18
|
* @type {{EXCLUDE: boolean, INCLUDE: boolean}}
|
|
@@ -24,6 +24,7 @@ exports.IncludeDocs = {
|
|
|
24
24
|
exports.createLinkView = createLinkView;
|
|
25
25
|
/**
|
|
26
26
|
* Gets the linking documents, not the linked documents themselves.
|
|
27
|
+
* @param {string} args.appId The instance in which we are searching for linked rows.
|
|
27
28
|
* @param {string} args.tableId The table which we are searching for linked rows against.
|
|
28
29
|
* @param {string|null} args.fieldName The name of column/field which is being altered, only looking for
|
|
29
30
|
* linking documents that are related to it. If this is not specified then the table level will be assumed.
|
|
@@ -37,8 +38,8 @@ exports.createLinkView = createLinkView;
|
|
|
37
38
|
*/
|
|
38
39
|
exports.getLinkDocuments = function (args) {
|
|
39
40
|
return __awaiter(this, arguments, void 0, function* () {
|
|
40
|
-
const { tableId, rowId, includeDocs } = args;
|
|
41
|
-
const db =
|
|
41
|
+
const { appId, tableId, rowId, includeDocs } = args;
|
|
42
|
+
const db = new CouchDB(appId);
|
|
42
43
|
let params;
|
|
43
44
|
if (rowId != null) {
|
|
44
45
|
params = { key: [tableId, rowId] };
|
|
@@ -74,7 +75,7 @@ exports.getLinkDocuments = function (args) {
|
|
|
74
75
|
catch (err) {
|
|
75
76
|
// check if the view doesn't exist, it should for all new instances
|
|
76
77
|
if (err != null && err.name === "not_found") {
|
|
77
|
-
yield exports.createLinkView();
|
|
78
|
+
yield exports.createLinkView(appId);
|
|
78
79
|
return exports.getLinkDocuments(arguments[0]);
|
|
79
80
|
}
|
|
80
81
|
else {
|
|
@@ -94,8 +95,7 @@ exports.getLinkedTableIDs = table => {
|
|
|
94
95
|
.filter(column => column.type === FieldTypes.LINK)
|
|
95
96
|
.map(column => column.tableId);
|
|
96
97
|
};
|
|
97
|
-
exports.getLinkedTable = (id, tables) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
-
const db = getAppDB();
|
|
98
|
+
exports.getLinkedTable = (db, id, tables) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
99
|
let linkedTable = tables.find(table => table._id === id);
|
|
100
100
|
if (linkedTable) {
|
|
101
101
|
return linkedTable;
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const
|
|
11
|
+
const CouchDB = require("../index");
|
|
12
12
|
const { DocumentTypes, SEPARATOR, ViewNames, SearchIndexes, } = require("../utils");
|
|
13
13
|
const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR;
|
|
14
14
|
/**************************************************
|
|
@@ -24,11 +24,12 @@ const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR;
|
|
|
24
24
|
/**
|
|
25
25
|
* Creates the link view for the instance, this will overwrite the existing one, but this should only
|
|
26
26
|
* be called if it is found that the view does not exist.
|
|
27
|
+
* @param {string} appId The instance to which the view should be added.
|
|
27
28
|
* @returns {Promise<void>} The view now exists, please note that the next view of this query will actually build it,
|
|
28
29
|
* so it may be slow.
|
|
29
30
|
*/
|
|
30
|
-
exports.createLinkView = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
-
const db =
|
|
31
|
+
exports.createLinkView = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const db = new CouchDB(appId);
|
|
32
33
|
const designDoc = yield db.get("_design/database");
|
|
33
34
|
const view = {
|
|
34
35
|
map: function (doc) {
|
|
@@ -55,8 +56,8 @@ exports.createLinkView = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
55
56
|
designDoc.views = Object.assign(Object.assign({}, designDoc.views), { [ViewNames.LINK]: view });
|
|
56
57
|
yield db.put(designDoc);
|
|
57
58
|
});
|
|
58
|
-
exports.createRoutingView = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
-
const db =
|
|
59
|
+
exports.createRoutingView = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const db = new CouchDB(appId);
|
|
60
61
|
const designDoc = yield db.get("_design/database");
|
|
61
62
|
const view = {
|
|
62
63
|
// if using variables in a map function need to inject them before use
|
|
@@ -72,9 +73,9 @@ exports.createRoutingView = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
72
73
|
designDoc.views = Object.assign(Object.assign({}, designDoc.views), { [ViewNames.ROUTING]: view });
|
|
73
74
|
yield db.put(designDoc);
|
|
74
75
|
});
|
|
75
|
-
function searchIndex(indexName, fnString) {
|
|
76
|
+
function searchIndex(appId, indexName, fnString) {
|
|
76
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const db =
|
|
78
|
+
const db = new CouchDB(appId);
|
|
78
79
|
const designDoc = yield db.get("_design/database");
|
|
79
80
|
designDoc.indexes = {
|
|
80
81
|
[indexName]: {
|
|
@@ -85,8 +86,8 @@ function searchIndex(indexName, fnString) {
|
|
|
85
86
|
yield db.put(designDoc);
|
|
86
87
|
});
|
|
87
88
|
}
|
|
88
|
-
exports.createAllSearchIndex = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
-
yield searchIndex(SearchIndexes.ROWS, function (doc) {
|
|
89
|
+
exports.createAllSearchIndex = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
|
+
yield searchIndex(appId, SearchIndexes.ROWS, function (doc) {
|
|
90
91
|
function idx(input, prev) {
|
|
91
92
|
for (let key of Object.keys(input)) {
|
|
92
93
|
let idxKey = prev != null ? `${prev}.${key}` : key;
|
|
@@ -49,7 +49,6 @@ var SourceNames;
|
|
|
49
49
|
SourceNames["ARANGODB"] = "ARANGODB";
|
|
50
50
|
SourceNames["REST"] = "REST";
|
|
51
51
|
SourceNames["ORACLE"] = "ORACLE";
|
|
52
|
-
SourceNames["GOOGLE_SHEETS"] = "GOOGLE_SHEETS";
|
|
53
52
|
})(SourceNames = exports.SourceNames || (exports.SourceNames = {}));
|
|
54
53
|
var IncludeRelationships;
|
|
55
54
|
(function (IncludeRelationships) {
|
package/dist/environment.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
function isTest() {
|
|
3
3
|
return (process.env.NODE_ENV === "jest" ||
|
|
4
4
|
process.env.NODE_ENV === "cypress" ||
|
|
5
|
-
|
|
6
|
-
process.env.JEST_WORKER_ID !== "null"));
|
|
5
|
+
process.env.JEST_WORKER_ID != null);
|
|
7
6
|
}
|
|
8
7
|
function isDev() {
|
|
9
8
|
return (process.env.NODE_ENV !== "production" &&
|
|
@@ -31,12 +30,10 @@ module.exports = {
|
|
|
31
30
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
32
31
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
|
33
32
|
USE_QUOTAS: process.env.USE_QUOTAS,
|
|
34
|
-
EXCLUDE_QUOTAS_TENANTS: process.env.EXCLUDE_QUOTAS_TENANTS,
|
|
35
33
|
REDIS_URL: process.env.REDIS_URL,
|
|
36
34
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
|
37
35
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
|
38
36
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
|
39
|
-
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
|
|
40
37
|
// environment
|
|
41
38
|
NODE_ENV: process.env.NODE_ENV,
|
|
42
39
|
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
|
@@ -69,16 +69,10 @@ class InternalBuilder {
|
|
|
69
69
|
this.client = client;
|
|
70
70
|
}
|
|
71
71
|
// right now we only do filters on the specific table being queried
|
|
72
|
-
addFilters(query, filters
|
|
72
|
+
addFilters(tableName, query, filters) {
|
|
73
73
|
function iterate(structure, fn) {
|
|
74
74
|
for (let [key, value] of Object.entries(structure)) {
|
|
75
|
-
|
|
76
|
-
if (!opts.relationship && !isRelationshipField) {
|
|
77
|
-
fn(`${opts.tableName}.${key}`, value);
|
|
78
|
-
}
|
|
79
|
-
if (opts.relationship && isRelationshipField) {
|
|
80
|
-
fn(key, value);
|
|
81
|
-
}
|
|
75
|
+
fn(`${tableName}.${key}`, value);
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
if (!filters) {
|
|
@@ -254,7 +248,7 @@ class InternalBuilder {
|
|
|
254
248
|
if (foundOffset) {
|
|
255
249
|
query = query.offset(foundOffset);
|
|
256
250
|
}
|
|
257
|
-
query = this.addFilters(query, filters
|
|
251
|
+
query = this.addFilters(tableName, query, filters);
|
|
258
252
|
// add sorting to pre-query
|
|
259
253
|
query = this.addSorting(query, json);
|
|
260
254
|
// @ts-ignore
|
|
@@ -267,14 +261,13 @@ class InternalBuilder {
|
|
|
267
261
|
preQuery = this.addSorting(preQuery, json);
|
|
268
262
|
}
|
|
269
263
|
// handle joins
|
|
270
|
-
|
|
271
|
-
return this.addFilters(query, filters, { relationship: true });
|
|
264
|
+
return this.addRelationships(knex, preQuery, selectStatement, tableName, relationships);
|
|
272
265
|
}
|
|
273
266
|
update(knex, json, opts) {
|
|
274
267
|
const { endpoint, body, filters } = json;
|
|
275
268
|
let query = knex(endpoint.entityId);
|
|
276
269
|
const parsedBody = parseBody(body);
|
|
277
|
-
query = this.addFilters(query, filters
|
|
270
|
+
query = this.addFilters(endpoint.entityId, query, filters);
|
|
278
271
|
// mysql can't use returning
|
|
279
272
|
if (opts.disableReturning) {
|
|
280
273
|
return query.update(parsedBody);
|
|
@@ -286,7 +279,7 @@ class InternalBuilder {
|
|
|
286
279
|
delete(knex, json, opts) {
|
|
287
280
|
const { endpoint, filters } = json;
|
|
288
281
|
let query = knex(endpoint.entityId);
|
|
289
|
-
query = this.addFilters(query, filters
|
|
282
|
+
query = this.addFilters(endpoint.entityId, query, filters);
|
|
290
283
|
// mysql can't use returning
|
|
291
284
|
if (opts.disableReturning) {
|
|
292
285
|
return query.delete();
|
|
@@ -10,7 +10,6 @@ const airtable = require("./airtable");
|
|
|
10
10
|
const mysql = require("./mysql");
|
|
11
11
|
const arangodb = require("./arangodb");
|
|
12
12
|
const rest = require("./rest");
|
|
13
|
-
const googlesheets = require("./googlesheets");
|
|
14
13
|
const { SourceNames } = require("../definitions/datasource");
|
|
15
14
|
const DEFINITIONS = {
|
|
16
15
|
[SourceNames.POSTGRES]: postgres.schema,
|
|
@@ -24,7 +23,6 @@ const DEFINITIONS = {
|
|
|
24
23
|
[SourceNames.MYSQL]: mysql.schema,
|
|
25
24
|
[SourceNames.ARANGODB]: arangodb.schema,
|
|
26
25
|
[SourceNames.REST]: rest.schema,
|
|
27
|
-
[SourceNames.GOOGLE_SHEETS]: googlesheets.schema,
|
|
28
26
|
};
|
|
29
27
|
const INTEGRATIONS = {
|
|
30
28
|
[SourceNames.POSTGRES]: postgres.integration,
|
|
@@ -38,7 +36,6 @@ const INTEGRATIONS = {
|
|
|
38
36
|
[SourceNames.MYSQL]: mysql.integration,
|
|
39
37
|
[SourceNames.ARANGODB]: arangodb.integration,
|
|
40
38
|
[SourceNames.REST]: rest.integration,
|
|
41
|
-
[SourceNames.GOOGLE_SHEETS]: googlesheets.integration,
|
|
42
39
|
};
|
|
43
40
|
// optionally add oracle integration if the oracle binary can be installed
|
|
44
41
|
if (!(process.arch === "arm64" && process.platform === "darwin")) {
|
|
@@ -52,9 +52,6 @@ function buildExternalTableId(datasourceId, tableName) {
|
|
|
52
52
|
}
|
|
53
53
|
exports.buildExternalTableId = buildExternalTableId;
|
|
54
54
|
function breakExternalTableId(tableId) {
|
|
55
|
-
if (!tableId) {
|
|
56
|
-
return {};
|
|
57
|
-
}
|
|
58
55
|
const parts = tableId.split(DOUBLE_SEPARATOR);
|
|
59
56
|
let tableName = parts.pop();
|
|
60
57
|
// if they need joined
|
|
@@ -128,12 +125,7 @@ function isSQL(datasource) {
|
|
|
128
125
|
if (!datasource || !datasource.source) {
|
|
129
126
|
return false;
|
|
130
127
|
}
|
|
131
|
-
const SQL = [
|
|
132
|
-
datasource_1.SourceNames.POSTGRES,
|
|
133
|
-
datasource_1.SourceNames.SQL_SERVER,
|
|
134
|
-
datasource_1.SourceNames.MYSQL,
|
|
135
|
-
datasource_1.SourceNames.ORACLE,
|
|
136
|
-
];
|
|
128
|
+
const SQL = [datasource_1.SourceNames.POSTGRES, datasource_1.SourceNames.SQL_SERVER, datasource_1.SourceNames.MYSQL];
|
|
137
129
|
return SQL.indexOf(datasource.source) !== -1;
|
|
138
130
|
}
|
|
139
131
|
exports.isSQL = isSQL;
|
|
@@ -145,44 +137,8 @@ function isIsoDateString(str) {
|
|
|
145
137
|
return d.toISOString() === str;
|
|
146
138
|
}
|
|
147
139
|
exports.isIsoDateString = isIsoDateString;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
* is currently valid. The reason for the validity check is that tables can be deleted
|
|
151
|
-
* outside of Budibase control and if this is the case it will break Budibase relationships.
|
|
152
|
-
* The tableIds is a list passed down from the main finalise tables function, which is
|
|
153
|
-
* based on the tables that have just been fetched. This will only really be used on subsequent
|
|
154
|
-
* fetches to the first one - if the user is periodically refreshing Budibase knowledge of tables.
|
|
155
|
-
* @param column The column to check, to see if it is a valid relationship.
|
|
156
|
-
* @param tableIds The IDs of the tables which currently exist.
|
|
157
|
-
*/
|
|
158
|
-
function shouldCopyRelationship(column, tableIds) {
|
|
159
|
-
return (column.type === constants_1.FieldTypes.LINK &&
|
|
160
|
-
column.tableId &&
|
|
161
|
-
tableIds.includes(column.tableId));
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Similar function to the shouldCopyRelationship function, but instead this looks for options and boolean
|
|
165
|
-
* types. It is possible to switch a string -> options and a number -> boolean (and vice versus) need to make
|
|
166
|
-
* sure that these get copied over when tables are fetched. Also checks whether they are still valid, if a
|
|
167
|
-
* column has changed type in the external database then copying it over may not be possible.
|
|
168
|
-
* @param column The column to check for options or boolean type.
|
|
169
|
-
* @param fetchedColumn The fetched column to check for the type in the external database.
|
|
170
|
-
*/
|
|
171
|
-
function shouldCopySpecialColumn(column, fetchedColumn) {
|
|
172
|
-
return (column.type === constants_1.FieldTypes.OPTIONS ||
|
|
173
|
-
column.type === constants_1.FieldTypes.ARRAY ||
|
|
174
|
-
((!fetchedColumn || fetchedColumn.type === constants_1.FieldTypes.NUMBER) &&
|
|
175
|
-
column.type === constants_1.FieldTypes.BOOLEAN));
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Looks for columns which need to be copied over into the new table definitions, like relationships
|
|
179
|
-
* and options types.
|
|
180
|
-
* @param tableName The name of the table which is being checked.
|
|
181
|
-
* @param table The specific table which is being checked.
|
|
182
|
-
* @param entities All the tables that existed before - the old table definitions.
|
|
183
|
-
* @param tableIds The IDs of the tables which exist now, to check if anything has been removed.
|
|
184
|
-
*/
|
|
185
|
-
function copyExistingPropsOver(tableName, table, entities, tableIds) {
|
|
140
|
+
// add the existing relationships from the entities if they exist, to prevent them from being overridden
|
|
141
|
+
function copyExistingPropsOver(tableName, table, entities) {
|
|
186
142
|
if (entities && entities[tableName]) {
|
|
187
143
|
if (entities[tableName].primaryDisplay) {
|
|
188
144
|
table.primaryDisplay = entities[tableName].primaryDisplay;
|
|
@@ -192,28 +148,21 @@ function copyExistingPropsOver(tableName, table, entities, tableIds) {
|
|
|
192
148
|
if (!existingTableSchema.hasOwnProperty(key)) {
|
|
193
149
|
continue;
|
|
194
150
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
151
|
+
if (existingTableSchema[key].type === constants_1.FieldTypes.LINK ||
|
|
152
|
+
existingTableSchema[key].type === constants_1.FieldTypes.OPTIONS ||
|
|
153
|
+
existingTableSchema[key].type === constants_1.FieldTypes.ARRAY ||
|
|
154
|
+
((!table.schema[key] || table.schema[key].type === constants_1.FieldTypes.NUMBER) &&
|
|
155
|
+
existingTableSchema[key].type === constants_1.FieldTypes.BOOLEAN)) {
|
|
198
156
|
table.schema[key] = existingTableSchema[key];
|
|
199
157
|
}
|
|
200
158
|
}
|
|
201
159
|
}
|
|
202
160
|
return table;
|
|
203
161
|
}
|
|
204
|
-
/**
|
|
205
|
-
* Look through the final table definitions to see if anything needs to be
|
|
206
|
-
* copied over from the old and if any errors have occurred mark them so
|
|
207
|
-
* that the user can be made aware.
|
|
208
|
-
* @param tables The list of tables that have been retrieved from the external database.
|
|
209
|
-
* @param entities The old list of tables, if there was any to look for definitions in.
|
|
210
|
-
*/
|
|
211
162
|
function finaliseExternalTables(tables, entities) {
|
|
212
163
|
const invalidColumns = Object.values(constants_1.InvalidColumns);
|
|
213
164
|
let finalTables = {};
|
|
214
165
|
const errors = {};
|
|
215
|
-
// @ts-ignore
|
|
216
|
-
const tableIds = Object.values(tables).map(table => table._id);
|
|
217
166
|
for (let [name, table] of Object.entries(tables)) {
|
|
218
167
|
const schemaFields = Object.keys(table.schema);
|
|
219
168
|
// make sure every table has a key
|
|
@@ -226,7 +175,7 @@ function finaliseExternalTables(tables, entities) {
|
|
|
226
175
|
continue;
|
|
227
176
|
}
|
|
228
177
|
// make sure all previous props have been added back
|
|
229
|
-
finalTables[name] = copyExistingPropsOver(name, table, entities
|
|
178
|
+
finalTables[name] = copyExistingPropsOver(name, table, entities);
|
|
230
179
|
}
|
|
231
180
|
// sort the tables by name
|
|
232
181
|
finalTables = Object.entries(finalTables)
|
|
@@ -12,50 +12,9 @@ const { getUserRoleHierarchy, getRequiredResourceRole, BUILTIN_ROLE_IDS, } = req
|
|
|
12
12
|
const { PermissionTypes, doesHaveBasePermission, } = require("@budibase/backend-core/permissions");
|
|
13
13
|
const builderMiddleware = require("./builder");
|
|
14
14
|
const { isWebhookEndpoint } = require("./utils");
|
|
15
|
-
const { buildCsrfMiddleware } = require("@budibase/backend-core/auth");
|
|
16
|
-
const { getAppId } = require("@budibase/backend-core/context");
|
|
17
15
|
function hasResource(ctx) {
|
|
18
16
|
return ctx.resourceId != null;
|
|
19
17
|
}
|
|
20
|
-
const csrf = buildCsrfMiddleware();
|
|
21
|
-
/**
|
|
22
|
-
* Apply authorization to the requested resource:
|
|
23
|
-
* - If this is a builder resource the user must be a builder.
|
|
24
|
-
* - Builders can access all resources.
|
|
25
|
-
* - Otherwise the user must have the required role.
|
|
26
|
-
*/
|
|
27
|
-
const checkAuthorized = (ctx, resourceRoles, permType, permLevel) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
-
// check if this is a builder api and the user is not a builder
|
|
29
|
-
const isBuilder = ctx.user && ctx.user.builder && ctx.user.builder.global;
|
|
30
|
-
const isBuilderApi = permType === PermissionTypes.BUILDER;
|
|
31
|
-
if (isBuilderApi && !isBuilder) {
|
|
32
|
-
return ctx.throw(403, "Not Authorized");
|
|
33
|
-
}
|
|
34
|
-
// check for resource authorization
|
|
35
|
-
if (!isBuilder) {
|
|
36
|
-
yield checkAuthorizedResource(ctx, resourceRoles, permType, permLevel);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
const checkAuthorizedResource = (ctx, resourceRoles, permType, permLevel) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
// get the user's roles
|
|
41
|
-
const roleId = ctx.roleId || BUILTIN_ROLE_IDS.PUBLIC;
|
|
42
|
-
const userRoles = yield getUserRoleHierarchy(roleId, {
|
|
43
|
-
idOnly: false,
|
|
44
|
-
});
|
|
45
|
-
const permError = "User does not have permission";
|
|
46
|
-
// check if the user has the required role
|
|
47
|
-
if (resourceRoles.length > 0) {
|
|
48
|
-
// deny access if the user doesn't have the required resource role
|
|
49
|
-
const found = userRoles.find(role => resourceRoles.indexOf(role._id) !== -1);
|
|
50
|
-
if (!found) {
|
|
51
|
-
ctx.throw(403, permError);
|
|
52
|
-
}
|
|
53
|
-
// fallback to the base permissions when no resource roles are found
|
|
54
|
-
}
|
|
55
|
-
else if (!doesHaveBasePermission(permType, permLevel, userRoles)) {
|
|
56
|
-
ctx.throw(403, permError);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
18
|
module.exports =
|
|
60
19
|
(permType, permLevel = null) => (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
20
|
// webhooks don't need authentication, each webhook unique
|
|
@@ -69,23 +28,37 @@ module.exports =
|
|
|
69
28
|
// check general builder stuff, this middleware is a good way
|
|
70
29
|
// to find API endpoints which are builder focused
|
|
71
30
|
yield builderMiddleware(ctx, permType);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
// if the resource is public, proceed
|
|
79
|
-
const isPublicResource = resourceRoles.includes(BUILTIN_ROLE_IDS.PUBLIC);
|
|
80
|
-
if (isPublicResource) {
|
|
31
|
+
const isAuthed = ctx.isAuthenticated;
|
|
32
|
+
// builders for now have permission to do anything
|
|
33
|
+
let isBuilder = ctx.user && ctx.user.builder && ctx.user.builder.global;
|
|
34
|
+
const isBuilderApi = permType === PermissionTypes.BUILDER;
|
|
35
|
+
if (isBuilder) {
|
|
81
36
|
return next();
|
|
82
37
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
38
|
+
else if (isBuilderApi && !isBuilder) {
|
|
39
|
+
return ctx.throw(403, "Not Authorized");
|
|
40
|
+
}
|
|
41
|
+
// need to check this first, in-case public access, don't check authed until last
|
|
42
|
+
const roleId = ctx.roleId || BUILTIN_ROLE_IDS.PUBLIC;
|
|
43
|
+
const hierarchy = yield getUserRoleHierarchy(ctx.appId, roleId, {
|
|
44
|
+
idOnly: false,
|
|
45
|
+
});
|
|
46
|
+
const permError = "User does not have permission";
|
|
47
|
+
let possibleRoleIds = [];
|
|
48
|
+
if (hasResource(ctx)) {
|
|
49
|
+
possibleRoleIds = yield getRequiredResourceRole(ctx.appId, permLevel, ctx);
|
|
50
|
+
}
|
|
51
|
+
// check if we found a role, if not fallback to base permissions
|
|
52
|
+
if (possibleRoleIds.length > 0) {
|
|
53
|
+
const found = hierarchy.find(role => possibleRoleIds.indexOf(role._id) !== -1);
|
|
54
|
+
return found ? next() : ctx.throw(403, permError);
|
|
55
|
+
}
|
|
56
|
+
else if (!doesHaveBasePermission(permType, permLevel, hierarchy)) {
|
|
57
|
+
ctx.throw(403, permError);
|
|
58
|
+
}
|
|
59
|
+
// if they are not authed, then anything using the authorized middleware will fail
|
|
60
|
+
if (!isAuthed) {
|
|
61
|
+
ctx.throw(403, "Session not authenticated");
|
|
86
62
|
}
|
|
87
|
-
|
|
88
|
-
yield checkAuthorized(ctx, resourceRoles, permType, permLevel);
|
|
89
|
-
// csrf protection
|
|
90
|
-
return csrf(ctx, next);
|
|
63
|
+
return next();
|
|
91
64
|
});
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const { APP_DEV_PREFIX } = require("../db/utils");
|
|
12
12
|
const { doesUserHaveLock, updateLock, checkDebounce, setDebounce, } = require("../utilities/redis");
|
|
13
|
-
const
|
|
13
|
+
const CouchDB = require("../db");
|
|
14
14
|
const { DocumentTypes } = require("../db/utils");
|
|
15
15
|
const { PermissionTypes } = require("@budibase/backend-core/permissions");
|
|
16
16
|
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
@@ -49,7 +49,7 @@ function updateAppUpdatedAt(ctx) {
|
|
|
49
49
|
if (ctx.method === "GET" || (yield checkDebounce(appId))) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
|
-
const db =
|
|
52
|
+
const db = new CouchDB(appId);
|
|
53
53
|
const metadata = yield db.get(DocumentTypes.APP_METADATA);
|
|
54
54
|
metadata.updatedAt = new Date().toISOString();
|
|
55
55
|
const response = yield db.put(metadata);
|