@budibase/server 1.0.49 → 1.0.50-alpha.0
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 +4 -5
- package/__mocks__/mssql.ts +3 -3
- package/__mocks__/node-fetch.ts +2 -1
- package/__mocks__/pg.ts +3 -5
- package/builder/assets/index.c0cc369d.css +6 -0
- package/builder/assets/{index.2c37968e.js → index.ff2bad21.js} +252 -249
- package/builder/assets/{vendor.f9faf6ab.js → vendor.5ad9695a.js} +202 -106
- package/builder/index.html +3 -3
- package/coverage/clover.xml +3105 -2814
- package/coverage/coverage-final.json +106 -101
- 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 +257 -152
- package/coverage/lcov-report/api/controllers/auth.js.html +22 -13
- package/coverage/lcov-report/api/controllers/automation.js.html +39 -69
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +8 -11
- package/coverage/lcov-report/api/controllers/component.js.html +13 -16
- package/coverage/lcov-report/api/controllers/datasource.js.html +81 -51
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- package/coverage/lcov-report/api/controllers/index.html +78 -78
- 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 +6 -21
- package/coverage/lcov-report/api/controllers/migrations.js.html +119 -0
- 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 +38 -35
- 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 +7 -10
- package/coverage/lcov-report/api/controllers/row/external.js.html +48 -141
- package/coverage/lcov-report/api/controllers/row/index.html +55 -40
- package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/row/internal.js.html +118 -226
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +52 -34
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +548 -0
- package/coverage/lcov-report/api/controllers/row/utils.js.html +47 -62
- package/coverage/lcov-report/api/controllers/screen.js.html +15 -21
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +599 -0
- package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
- package/coverage/lcov-report/api/controllers/table/index.html +58 -43
- package/coverage/lcov-report/api/controllers/table/index.js.html +58 -82
- package/coverage/lcov-report/api/controllers/table/internal.js.html +81 -66
- package/coverage/lcov-report/api/controllers/table/utils.js.html +218 -110
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +79 -76
- 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 +27 -33
- package/coverage/lcov-report/api/controllers/view/utils.js.html +35 -20
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +34 -28
- 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/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/{hosting.js.html → migrations.js.html} +17 -14
- 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 +17 -2
- 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 +7 -10
- 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 +13 -22
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +11 -20
- 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 +61 -55
- package/coverage/lcov-report/automations/utils.js.html +54 -42
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +53 -26
- 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 +25 -37
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +51 -96
- 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 +135 -120
- 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 +173 -65
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +95 -83
- 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 +281 -53
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +30 -24
- 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 +39 -24
- 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 +58 -49
- package/coverage/lcov-report/utilities/index.html +37 -37
- package/coverage/lcov-report/utilities/index.js.html +43 -73
- 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 +97 -103
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
- 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 +141 -0
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +305 -0
- package/coverage/lcov-report/{api/controllers/hosting.js.html → utilities/usageQuota/usageQuoteReset.js.html} +36 -48
- package/coverage/lcov-report/utilities/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +43 -112
- package/coverage/lcov.info +5010 -4425
- package/dist/api/controllers/application.js +90 -60
- package/dist/api/controllers/auth.js +8 -5
- package/dist/api/controllers/automation.js +14 -19
- package/dist/api/controllers/cloud.js +2 -3
- package/dist/api/controllers/component.js +3 -4
- package/dist/api/controllers/datasource.js +20 -10
- package/dist/api/controllers/deploy/Deployment.js +3 -6
- package/dist/api/controllers/deploy/index.js +12 -13
- package/dist/api/controllers/dev.js +5 -5
- package/dist/api/controllers/layout.js +3 -3
- package/dist/api/controllers/metadata.js +4 -4
- package/dist/api/controllers/migrations.js +21 -0
- package/dist/api/controllers/permission.js +4 -4
- package/dist/api/controllers/query/import/index.js +4 -6
- package/dist/api/controllers/query/index.js +11 -10
- package/dist/api/controllers/role.js +5 -5
- package/dist/api/controllers/routing.js +5 -6
- package/dist/api/controllers/row/ExternalRequest.js +90 -67
- package/dist/api/controllers/row/external.js +14 -22
- package/dist/api/controllers/row/internal.js +55 -93
- package/dist/api/controllers/row/internalSearch.js +23 -17
- package/dist/api/controllers/row/staticFormula.js +147 -0
- package/dist/api/controllers/row/utils.js +13 -14
- package/dist/api/controllers/screen.js +5 -7
- package/dist/api/controllers/static/index.js +62 -16
- package/dist/api/controllers/table/bulkFormula.js +159 -0
- package/dist/api/controllers/table/external.js +7 -10
- package/dist/api/controllers/table/index.js +16 -13
- package/dist/api/controllers/table/internal.js +22 -16
- package/dist/api/controllers/table/utils.js +62 -35
- package/dist/api/controllers/user.js +43 -43
- package/dist/api/controllers/view/index.js +8 -10
- package/dist/api/controllers/view/utils.js +9 -4
- package/dist/api/controllers/webhook.js +10 -8
- package/dist/api/routes/index.js +2 -2
- package/dist/api/routes/migrations.js +9 -0
- package/dist/api/routes/static.js +2 -1
- package/dist/api/routes/tests/utilities/TestFunctions.js +37 -17
- package/dist/app.js +35 -5
- package/dist/automations/automationUtils.js +2 -3
- package/dist/automations/steps/createRow.js +3 -5
- package/dist/automations/steps/deleteRow.js +1 -4
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +27 -25
- package/dist/automations/utils.js +10 -5
- package/dist/constants/index.js +7 -0
- package/dist/db/linkedRows/LinkController.js +3 -7
- package/dist/db/linkedRows/index.js +16 -27
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +9 -10
- package/dist/definitions/datasource.js +1 -0
- package/dist/environment.js +4 -1
- package/dist/integrations/base/sql.js +62 -21
- package/dist/integrations/googlesheets.js +340 -0
- package/dist/integrations/index.js +3 -0
- package/dist/integrations/utils.js +60 -9
- package/dist/middleware/authorized.js +57 -30
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +41 -37
- package/dist/middleware/usageQuota.js +82 -15
- package/dist/migrations/functions/appUrls.js +46 -0
- package/dist/migrations/functions/quotas1.js +50 -0
- package/dist/migrations/functions/usageQuotas/index.js +20 -0
- package/dist/migrations/functions/usageQuotas/syncApps.js +29 -0
- package/dist/migrations/functions/usageQuotas/syncRows.js +33 -0
- package/dist/migrations/functions/userEmailViewCasing.js +24 -0
- package/dist/migrations/index.js +62 -0
- package/dist/package.json +8 -5
- package/dist/tests/utilities/TestConfiguration.js +80 -50
- package/dist/threads/automation.js +13 -11
- package/dist/threads/query.js +15 -11
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +4 -3
- package/dist/utilities/global.js +15 -12
- package/dist/utilities/index.js +7 -17
- package/dist/utilities/routing/index.js +5 -5
- package/dist/utilities/rowProcessor/index.js +23 -17
- package/dist/utilities/rowProcessor/utils.js +14 -4
- package/dist/utilities/{usageQuota.js → usageQuota/index.js} +45 -31
- package/dist/utilities/usageQuota/rows.js +78 -0
- package/dist/utilities/usageQuota/usageQuoteReset.js +16 -0
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +4 -24
- package/nodemon.json +1 -1
- package/package.json +9 -6
- package/scripts/integrations/mssql/data/Dockerfile +1 -1
- package/scripts/integrations/mssql/data/setup.sql +17 -4
- package/scripts/integrations/postgres/init.sql +11 -6
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/application.js +85 -50
- package/src/api/controllers/auth.js +8 -5
- package/src/api/controllers/automation.js +13 -23
- package/src/api/controllers/cloud.js +2 -3
- package/src/api/controllers/component.js +3 -4
- package/src/api/controllers/datasource.js +21 -11
- package/src/api/controllers/deploy/Deployment.js +3 -7
- package/src/api/controllers/deploy/index.js +20 -13
- package/src/api/controllers/dev.js +5 -5
- package/src/api/controllers/layout.js +3 -3
- package/src/api/controllers/metadata.js +4 -9
- package/src/api/controllers/migrations.js +13 -0
- package/src/api/controllers/permission.js +4 -4
- package/src/api/controllers/query/import/index.ts +4 -6
- package/src/api/controllers/query/import/tests/index.spec.js +2 -1
- package/src/api/controllers/query/index.js +11 -10
- package/src/api/controllers/role.js +5 -5
- package/src/api/controllers/routing.js +5 -6
- package/src/api/controllers/row/ExternalRequest.ts +67 -43
- package/src/api/controllers/row/external.js +27 -58
- package/src/api/controllers/row/internal.js +54 -90
- package/src/api/controllers/row/internalSearch.js +23 -17
- package/src/api/controllers/row/staticFormula.js +156 -0
- package/src/api/controllers/row/utils.js +13 -18
- package/src/api/controllers/screen.js +5 -7
- package/src/api/controllers/static/index.js +66 -15
- package/src/api/controllers/table/bulkFormula.js +173 -0
- package/src/api/controllers/table/external.js +7 -10
- package/src/api/controllers/table/index.js +20 -28
- package/src/api/controllers/table/internal.js +24 -19
- package/src/api/controllers/table/utils.js +78 -42
- package/src/api/controllers/user.js +46 -45
- package/src/api/controllers/view/index.js +8 -10
- package/src/api/controllers/view/utils.js +9 -4
- package/src/api/controllers/webhook.js +10 -8
- package/src/api/routes/index.js +2 -2
- package/src/api/routes/migrations.js +14 -0
- package/src/api/routes/static.js +5 -0
- package/src/api/routes/tests/application.spec.js +2 -2
- package/src/api/routes/tests/auth.spec.js +1 -2
- package/src/api/routes/tests/automation.spec.js +1 -0
- package/src/api/routes/tests/misc.spec.js +0 -1
- package/src/api/routes/tests/routing.spec.js +21 -12
- package/src/api/routes/tests/row.spec.js +7 -4
- package/src/api/routes/tests/static.spec.js +98 -0
- package/src/api/routes/tests/utilities/TestFunctions.js +39 -17
- package/src/app.ts +18 -5
- package/src/automations/automationUtils.js +2 -3
- package/src/automations/steps/createRow.js +2 -5
- package/src/automations/steps/deleteRow.js +1 -4
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +33 -31
- package/src/automations/utils.js +9 -5
- package/src/constants/index.js +9 -0
- package/src/db/linkedRows/LinkController.js +3 -7
- package/src/db/linkedRows/index.js +16 -31
- package/src/db/linkedRows/linkUtils.js +6 -6
- package/src/db/tests/linkController.spec.js +0 -1
- package/src/db/tests/linkTests.spec.js +5 -6
- package/src/db/views/staticViews.js +8 -10
- package/src/definitions/common.ts +3 -0
- package/src/definitions/datasource.ts +3 -0
- package/src/environment.js +4 -1
- package/src/integrations/base/sql.ts +75 -29
- package/src/integrations/googlesheets.ts +353 -0
- package/src/integrations/index.ts +3 -0
- package/src/integrations/tests/sql.spec.js +16 -0
- package/src/integrations/utils.ts +75 -12
- package/src/middleware/authorized.js +66 -30
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +50 -46
- package/src/middleware/tests/authorized.spec.js +13 -6
- package/src/middleware/tests/currentapp.spec.js +6 -0
- package/src/middleware/tests/usageQuota.spec.js +18 -24
- package/src/middleware/usageQuota.js +93 -17
- package/src/migrations/functions/appUrls.ts +34 -0
- package/src/migrations/functions/quotas1.ts +20 -0
- package/src/migrations/functions/tests/appUrls.spec.js +29 -0
- package/src/migrations/functions/tests/quotas1.spec.js +27 -0
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
- package/src/migrations/functions/usageQuotas/index.ts +8 -0
- package/src/migrations/functions/usageQuotas/syncApps.ts +18 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +37 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +43 -0
- package/src/migrations/functions/userEmailViewCasing.ts +13 -0
- package/src/migrations/index.ts +56 -0
- package/src/module.d.ts +3 -0
- package/src/tests/utilities/TestConfiguration.js +82 -55
- package/src/threads/automation.js +17 -15
- package/src/threads/query.js +17 -12
- package/src/utilities/fileSystem/index.js +4 -3
- package/src/utilities/global.js +15 -12
- package/src/utilities/index.js +7 -17
- package/src/utilities/routing/index.js +5 -5
- package/src/utilities/rowProcessor/index.js +25 -27
- package/src/utilities/rowProcessor/utils.js +23 -7
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
- package/src/utilities/usageQuota/index.js +93 -0
- package/src/utilities/usageQuota/rows.js +75 -0
- package/src/utilities/usageQuota/usageQuoteReset.js +18 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +4 -27
- package/tsconfig.json +2 -1
- package/builder/assets/index.39e01193.css +0 -1
- package/dist/api/controllers/hosting.js +0 -30
- package/dist/api/routes/hosting.js +0 -11
- package/src/api/controllers/hosting.js +0 -22
- package/src/api/routes/hosting.js +0 -13
- package/src/api/routes/tests/hosting.spec.js +0 -36
- package/src/utilities/usageQuota.js +0 -73
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
2
|
+
const TestConfig = require("../../../../tests/utilities/TestConfiguration")
|
|
3
|
+
const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
|
|
4
|
+
const syncRows = require("../syncRows")
|
|
5
|
+
const env = require("../../../../environment")
|
|
6
|
+
|
|
7
|
+
describe("syncRows", () => {
|
|
8
|
+
let config = new TestConfig(false)
|
|
9
|
+
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
await config.init()
|
|
12
|
+
env._set("USE_QUOTAS", 1)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterAll(config.end)
|
|
16
|
+
|
|
17
|
+
it("runs successfully", async () => {
|
|
18
|
+
// create the usage quota doc and mock usages
|
|
19
|
+
const db = getGlobalDB()
|
|
20
|
+
await getUsageQuotaDoc(db)
|
|
21
|
+
await update(Properties.ROW, 300)
|
|
22
|
+
|
|
23
|
+
let usageDoc = await getUsageQuotaDoc(db)
|
|
24
|
+
expect(usageDoc.usageQuota.rows).toEqual(300)
|
|
25
|
+
|
|
26
|
+
// app 1
|
|
27
|
+
await config.createTable()
|
|
28
|
+
await config.createRow()
|
|
29
|
+
// app 2
|
|
30
|
+
await config.createApp("second-app")
|
|
31
|
+
await config.createTable()
|
|
32
|
+
await config.createRow()
|
|
33
|
+
await config.createRow()
|
|
34
|
+
|
|
35
|
+
// migrate
|
|
36
|
+
await syncRows.run()
|
|
37
|
+
|
|
38
|
+
// assert the migration worked
|
|
39
|
+
usageDoc = await getUsageQuotaDoc(db)
|
|
40
|
+
expect(usageDoc.usageQuota.rows).toEqual(3)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { createUserEmailView } = require("@budibase/backend-core/db")
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Date:
|
|
5
|
+
* October 2021
|
|
6
|
+
*
|
|
7
|
+
* Description:
|
|
8
|
+
* Recreate the user email view to include latest changes i.e. lower casing the email address
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const run = async (db: any) => {
|
|
12
|
+
await createUserEmailView(db)
|
|
13
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import CouchDB from "../db"
|
|
2
|
+
const {
|
|
3
|
+
MIGRATION_TYPES,
|
|
4
|
+
runMigrations,
|
|
5
|
+
} = require("@budibase/backend-core/migrations")
|
|
6
|
+
|
|
7
|
+
// migration functions
|
|
8
|
+
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
|
|
9
|
+
import * as quota1 from "./functions/quotas1"
|
|
10
|
+
import * as appUrls from "./functions/appUrls"
|
|
11
|
+
|
|
12
|
+
export interface Migration {
|
|
13
|
+
type: string
|
|
14
|
+
name: string
|
|
15
|
+
opts?: object
|
|
16
|
+
fn: Function
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* e.g.
|
|
21
|
+
* {
|
|
22
|
+
* tenantIds: ['bb'],
|
|
23
|
+
* force: {
|
|
24
|
+
* global: ['quota_1']
|
|
25
|
+
* }
|
|
26
|
+
* }
|
|
27
|
+
*/
|
|
28
|
+
export interface MigrationOptions {
|
|
29
|
+
tenantIds?: string[]
|
|
30
|
+
forced?: {
|
|
31
|
+
[type: string]: string[]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const MIGRATIONS: Migration[] = [
|
|
36
|
+
{
|
|
37
|
+
type: MIGRATION_TYPES.GLOBAL,
|
|
38
|
+
name: "user_email_view_casing",
|
|
39
|
+
fn: userEmailViewCasing.run,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: MIGRATION_TYPES.GLOBAL,
|
|
43
|
+
name: "quotas_1",
|
|
44
|
+
fn: quota1.run,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
type: MIGRATION_TYPES.APP,
|
|
48
|
+
name: "app_urls",
|
|
49
|
+
opts: { all: true },
|
|
50
|
+
fn: appUrls.run,
|
|
51
|
+
},
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
export const migrate = async (options?: MigrationOptions) => {
|
|
55
|
+
await runMigrations(CouchDB, MIGRATIONS, options)
|
|
56
|
+
}
|
package/src/module.d.ts
ADDED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const core = require("@budibase/backend-core")
|
|
2
|
+
const CouchDB = require("../../db")
|
|
3
|
+
core.init(CouchDB)
|
|
1
4
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
|
|
2
5
|
const env = require("../../environment")
|
|
3
6
|
const {
|
|
@@ -17,15 +20,15 @@ const supertest = require("supertest")
|
|
|
17
20
|
const { cleanup } = require("../../utilities/fileSystem")
|
|
18
21
|
const { Cookies, Headers } = require("@budibase/backend-core/constants")
|
|
19
22
|
const { jwt } = require("@budibase/backend-core/auth")
|
|
20
|
-
const core = require("@budibase/backend-core")
|
|
21
23
|
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
22
24
|
const { createASession } = require("@budibase/backend-core/sessions")
|
|
23
25
|
const { user: userCache } = require("@budibase/backend-core/cache")
|
|
24
|
-
const
|
|
25
|
-
core
|
|
26
|
+
const newid = require("../../db/newid")
|
|
27
|
+
const context = require("@budibase/backend-core/context")
|
|
26
28
|
|
|
27
29
|
const GLOBAL_USER_ID = "us_uuid1"
|
|
28
30
|
const EMAIL = "babs@babs.com"
|
|
31
|
+
const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
|
|
29
32
|
|
|
30
33
|
class TestConfiguration {
|
|
31
34
|
constructor(openServer = true) {
|
|
@@ -48,6 +51,10 @@ class TestConfiguration {
|
|
|
48
51
|
return this.appId
|
|
49
52
|
}
|
|
50
53
|
|
|
54
|
+
getCouch() {
|
|
55
|
+
return CouchDB
|
|
56
|
+
}
|
|
57
|
+
|
|
51
58
|
async _req(config, params, controlFunc) {
|
|
52
59
|
const request = {}
|
|
53
60
|
// fake cookies, we don't need them
|
|
@@ -59,11 +66,21 @@ class TestConfiguration {
|
|
|
59
66
|
request.request = {
|
|
60
67
|
body: config,
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
async function run() {
|
|
70
|
+
if (params) {
|
|
71
|
+
request.params = params
|
|
72
|
+
}
|
|
73
|
+
await controlFunc(request)
|
|
74
|
+
return request.body
|
|
75
|
+
}
|
|
76
|
+
// check if already in a context
|
|
77
|
+
if (context.getAppId() == null) {
|
|
78
|
+
return context.doInAppContext(this.appId, async () => {
|
|
79
|
+
return run()
|
|
80
|
+
})
|
|
81
|
+
} else {
|
|
82
|
+
return run()
|
|
64
83
|
}
|
|
65
|
-
await controlFunc(request)
|
|
66
|
-
return request.body
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
async globalUser({
|
|
@@ -85,7 +102,11 @@ class TestConfiguration {
|
|
|
85
102
|
roles: roles || {},
|
|
86
103
|
tenantId: TENANT_ID,
|
|
87
104
|
}
|
|
88
|
-
await createASession(id, {
|
|
105
|
+
await createASession(id, {
|
|
106
|
+
sessionId: "sessionid",
|
|
107
|
+
tenantId: TENANT_ID,
|
|
108
|
+
csrfToken: CSRF_TOKEN,
|
|
109
|
+
})
|
|
89
110
|
if (builder) {
|
|
90
111
|
user.builder = { global: true }
|
|
91
112
|
} else {
|
|
@@ -98,7 +119,8 @@ class TestConfiguration {
|
|
|
98
119
|
}
|
|
99
120
|
}
|
|
100
121
|
|
|
101
|
-
|
|
122
|
+
// use a new id as the name to avoid name collisions
|
|
123
|
+
async init(appName = newid()) {
|
|
102
124
|
await this.globalUser()
|
|
103
125
|
return this.createApp(appName)
|
|
104
126
|
}
|
|
@@ -131,6 +153,7 @@ class TestConfiguration {
|
|
|
131
153
|
`${Cookies.Auth}=${authToken}`,
|
|
132
154
|
`${Cookies.CurrentApp}=${appToken}`,
|
|
133
155
|
],
|
|
156
|
+
[Headers.CSRF_TOKEN]: CSRF_TOKEN,
|
|
134
157
|
}
|
|
135
158
|
if (this.appId) {
|
|
136
159
|
headers[Headers.APP_ID] = this.appId
|
|
@@ -163,6 +186,7 @@ class TestConfiguration {
|
|
|
163
186
|
// create dev app
|
|
164
187
|
this.app = await this._req({ name: appName }, null, controllers.app.create)
|
|
165
188
|
this.appId = this.app.appId
|
|
189
|
+
context.updateAppId(this.appId)
|
|
166
190
|
|
|
167
191
|
// create production app
|
|
168
192
|
this.prodApp = await this.deploy()
|
|
@@ -175,14 +199,16 @@ class TestConfiguration {
|
|
|
175
199
|
}
|
|
176
200
|
|
|
177
201
|
async deploy() {
|
|
178
|
-
|
|
179
|
-
const prodAppId =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
202
|
+
await this._req(null, null, controllers.deploy.deployApp)
|
|
203
|
+
const prodAppId = this.getAppId().replace("_dev", "")
|
|
204
|
+
return context.doInAppContext(prodAppId, async () => {
|
|
205
|
+
const appPackage = await this._req(
|
|
206
|
+
null,
|
|
207
|
+
{ appId: prodAppId },
|
|
208
|
+
controllers.app.fetchAppPackage
|
|
209
|
+
)
|
|
210
|
+
return appPackage.application
|
|
211
|
+
})
|
|
186
212
|
}
|
|
187
213
|
|
|
188
214
|
async updateTable(config = null) {
|
|
@@ -411,46 +437,47 @@ class TestConfiguration {
|
|
|
411
437
|
|
|
412
438
|
async login({ roleId, userId, builder, prodApp = false } = {}) {
|
|
413
439
|
const appId = prodApp ? this.prodAppId : this.appId
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
440
|
+
return context.doInAppContext(appId, async () => {
|
|
441
|
+
userId = !userId ? `us_uuid1` : userId
|
|
442
|
+
if (!this.request) {
|
|
443
|
+
throw "Server has not been opened, cannot login."
|
|
444
|
+
}
|
|
445
|
+
// make sure the user exists in the global DB
|
|
446
|
+
if (roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
|
|
447
|
+
await this.globalUser({
|
|
448
|
+
id: userId,
|
|
449
|
+
builder,
|
|
450
|
+
roles: { [this.prodAppId]: roleId },
|
|
451
|
+
})
|
|
452
|
+
}
|
|
453
|
+
await createASession(userId, {
|
|
454
|
+
sessionId: "sessionid",
|
|
455
|
+
tenantId: TENANT_ID,
|
|
425
456
|
})
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
457
|
+
// have to fake this
|
|
458
|
+
const auth = {
|
|
459
|
+
userId,
|
|
460
|
+
sessionId: "sessionid",
|
|
461
|
+
tenantId: TENANT_ID,
|
|
462
|
+
}
|
|
463
|
+
const app = {
|
|
464
|
+
roleId: roleId,
|
|
465
|
+
appId,
|
|
466
|
+
}
|
|
467
|
+
const authToken = jwt.sign(auth, env.JWT_SECRET)
|
|
468
|
+
const appToken = jwt.sign(app, env.JWT_SECRET)
|
|
469
|
+
|
|
470
|
+
// returning necessary request headers
|
|
471
|
+
await userCache.invalidateUser(userId)
|
|
472
|
+
return {
|
|
473
|
+
Accept: "application/json",
|
|
474
|
+
Cookie: [
|
|
475
|
+
`${Cookies.Auth}=${authToken}`,
|
|
476
|
+
`${Cookies.CurrentApp}=${appToken}`,
|
|
477
|
+
],
|
|
478
|
+
[Headers.APP_ID]: appId,
|
|
479
|
+
}
|
|
430
480
|
})
|
|
431
|
-
// have to fake this
|
|
432
|
-
const auth = {
|
|
433
|
-
userId,
|
|
434
|
-
sessionId: "sessionid",
|
|
435
|
-
tenantId: TENANT_ID,
|
|
436
|
-
}
|
|
437
|
-
const app = {
|
|
438
|
-
roleId: roleId,
|
|
439
|
-
appId,
|
|
440
|
-
}
|
|
441
|
-
const authToken = jwt.sign(auth, env.JWT_SECRET)
|
|
442
|
-
const appToken = jwt.sign(app, env.JWT_SECRET)
|
|
443
|
-
|
|
444
|
-
// returning necessary request headers
|
|
445
|
-
await userCache.invalidateUser(userId)
|
|
446
|
-
return {
|
|
447
|
-
Accept: "application/json",
|
|
448
|
-
Cookie: [
|
|
449
|
-
`${Cookies.Auth}=${authToken}`,
|
|
450
|
-
`${Cookies.CurrentApp}=${appToken}`,
|
|
451
|
-
],
|
|
452
|
-
[Headers.APP_ID]: appId,
|
|
453
|
-
}
|
|
454
481
|
}
|
|
455
482
|
}
|
|
456
483
|
|
|
@@ -5,11 +5,11 @@ const automationUtils = require("../automations/automationUtils")
|
|
|
5
5
|
const AutomationEmitter = require("../events/AutomationEmitter")
|
|
6
6
|
const { processObject } = require("@budibase/string-templates")
|
|
7
7
|
const { DEFAULT_TENANT_ID } = require("@budibase/backend-core/constants")
|
|
8
|
-
const CouchDB = require("../db")
|
|
9
8
|
const { DocumentTypes, isDevAppID } = require("../db/utils")
|
|
10
9
|
const { doInTenant } = require("@budibase/backend-core/tenancy")
|
|
11
10
|
const usage = require("../utilities/usageQuota")
|
|
12
11
|
const { definitions: triggerDefs } = require("../automations/triggerInfo")
|
|
12
|
+
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
|
|
13
13
|
|
|
14
14
|
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId
|
|
15
15
|
const CRON_STEP_ID = triggerDefs.CRON.stepId
|
|
@@ -59,11 +59,10 @@ class Orchestrator {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
async getApp() {
|
|
62
|
-
const appId = this._appId
|
|
63
62
|
if (this._app) {
|
|
64
63
|
return this._app
|
|
65
64
|
}
|
|
66
|
-
const db =
|
|
65
|
+
const db = getAppDB()
|
|
67
66
|
this._app = await db.get(DocumentTypes.APP_METADATA)
|
|
68
67
|
return this._app
|
|
69
68
|
}
|
|
@@ -131,16 +130,19 @@ class Orchestrator {
|
|
|
131
130
|
}
|
|
132
131
|
|
|
133
132
|
module.exports = (input, callback) => {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
133
|
+
const appId = input.data.event.appId
|
|
134
|
+
doInAppContext(appId, () => {
|
|
135
|
+
const automationOrchestrator = new Orchestrator(
|
|
136
|
+
input.data.automation,
|
|
137
|
+
input.data.event
|
|
138
|
+
)
|
|
139
|
+
automationOrchestrator
|
|
140
|
+
.execute()
|
|
141
|
+
.then(response => {
|
|
142
|
+
callback(null, response)
|
|
143
|
+
})
|
|
144
|
+
.catch(err => {
|
|
145
|
+
callback(err)
|
|
146
|
+
})
|
|
147
|
+
})
|
|
146
148
|
}
|
package/src/threads/query.js
CHANGED
|
@@ -3,11 +3,10 @@ threadUtils.threadSetup()
|
|
|
3
3
|
const ScriptRunner = require("../utilities/scriptRunner")
|
|
4
4
|
const { integrations } = require("../integrations")
|
|
5
5
|
const { processStringSync } = require("@budibase/string-templates")
|
|
6
|
-
const
|
|
6
|
+
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
|
|
7
7
|
|
|
8
8
|
class QueryRunner {
|
|
9
9
|
constructor(input, flags = { noRecursiveQuery: false }) {
|
|
10
|
-
this.appId = input.appId
|
|
11
10
|
this.datasource = input.datasource
|
|
12
11
|
this.queryVerb = input.queryVerb
|
|
13
12
|
this.fields = input.fields
|
|
@@ -75,6 +74,11 @@ class QueryRunner {
|
|
|
75
74
|
return this.execute()
|
|
76
75
|
}
|
|
77
76
|
|
|
77
|
+
// check for undefined response
|
|
78
|
+
if (!rows) {
|
|
79
|
+
rows = []
|
|
80
|
+
}
|
|
81
|
+
|
|
78
82
|
// needs to an array for next step
|
|
79
83
|
if (!Array.isArray(rows)) {
|
|
80
84
|
rows = [rows]
|
|
@@ -96,12 +100,11 @@ class QueryRunner {
|
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
async runAnotherQuery(queryId, parameters) {
|
|
99
|
-
const db =
|
|
103
|
+
const db = getAppDB()
|
|
100
104
|
const query = await db.get(queryId)
|
|
101
105
|
const datasource = await db.get(query.datasourceId)
|
|
102
106
|
return new QueryRunner(
|
|
103
107
|
{
|
|
104
|
-
appId: this.appId,
|
|
105
108
|
datasource,
|
|
106
109
|
queryVerb: query.queryVerb,
|
|
107
110
|
fields: query.fields,
|
|
@@ -211,12 +214,14 @@ class QueryRunner {
|
|
|
211
214
|
}
|
|
212
215
|
|
|
213
216
|
module.exports = (input, callback) => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
217
|
+
doInAppContext(input.appId, () => {
|
|
218
|
+
const Runner = new QueryRunner(input)
|
|
219
|
+
Runner.execute()
|
|
220
|
+
.then(response => {
|
|
221
|
+
callback(null, response)
|
|
222
|
+
})
|
|
223
|
+
.catch(err => {
|
|
224
|
+
callback(err)
|
|
225
|
+
})
|
|
226
|
+
})
|
|
222
227
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { budibaseTempDir } = require("../budibaseDir")
|
|
2
|
-
const { isDev } = require("../index")
|
|
3
2
|
const fs = require("fs")
|
|
4
3
|
const { join } = require("path")
|
|
5
4
|
const uuid = require("uuid/v4")
|
|
@@ -20,6 +19,7 @@ const {
|
|
|
20
19
|
LINK_USER_METADATA_PREFIX,
|
|
21
20
|
} = require("../../db/utils")
|
|
22
21
|
const MemoryStream = require("memorystream")
|
|
22
|
+
const { getAppId } = require("@budibase/backend-core/context")
|
|
23
23
|
|
|
24
24
|
const TOP_LEVEL_PATH = join(__dirname, "..", "..", "..")
|
|
25
25
|
const NODE_MODULES_PATH = join(TOP_LEVEL_PATH, "node_modules")
|
|
@@ -51,7 +51,7 @@ exports.init = () => {
|
|
|
51
51
|
* everything required to function is ready.
|
|
52
52
|
*/
|
|
53
53
|
exports.checkDevelopmentEnvironment = () => {
|
|
54
|
-
if (!isDev()) {
|
|
54
|
+
if (!env.isDev() || env.isTest()) {
|
|
55
55
|
return
|
|
56
56
|
}
|
|
57
57
|
if (!fs.existsSync(budibaseTempDir())) {
|
|
@@ -251,7 +251,8 @@ exports.downloadTemplate = async (type, name) => {
|
|
|
251
251
|
/**
|
|
252
252
|
* Retrieves component libraries from object store (or tmp symlink if in local)
|
|
253
253
|
*/
|
|
254
|
-
exports.getComponentLibraryManifest = async
|
|
254
|
+
exports.getComponentLibraryManifest = async library => {
|
|
255
|
+
const appId = getAppId()
|
|
255
256
|
const filename = "manifest.json"
|
|
256
257
|
/* istanbul ignore next */
|
|
257
258
|
// when testing in cypress and so on we need to get the package
|
package/src/utilities/global.js
CHANGED
|
@@ -3,7 +3,7 @@ const {
|
|
|
3
3
|
getGlobalIDFromUserMetadataID,
|
|
4
4
|
} = require("../db/utils")
|
|
5
5
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
|
|
6
|
-
const {
|
|
6
|
+
const { getProdAppID } = require("@budibase/backend-core/db")
|
|
7
7
|
const { getGlobalUserParams } = require("@budibase/backend-core/db")
|
|
8
8
|
const { user: userCache } = require("@budibase/backend-core/cache")
|
|
9
9
|
const {
|
|
@@ -11,8 +11,10 @@ const {
|
|
|
11
11
|
isUserInAppTenant,
|
|
12
12
|
} = require("@budibase/backend-core/tenancy")
|
|
13
13
|
const env = require("../environment")
|
|
14
|
+
const { getAppId } = require("@budibase/backend-core/context")
|
|
14
15
|
|
|
15
|
-
exports.updateAppRole = (
|
|
16
|
+
exports.updateAppRole = (user, { appId } = {}) => {
|
|
17
|
+
appId = appId || getAppId()
|
|
16
18
|
if (!user || !user.roles) {
|
|
17
19
|
return user
|
|
18
20
|
}
|
|
@@ -24,7 +26,7 @@ exports.updateAppRole = (appId, user) => {
|
|
|
24
26
|
return user
|
|
25
27
|
}
|
|
26
28
|
// always use the deployed app
|
|
27
|
-
user.roleId = user.roles[
|
|
29
|
+
user.roleId = user.roles[getProdAppID(appId)]
|
|
28
30
|
// if a role wasn't found then either set as admin (builder) or public (everyone else)
|
|
29
31
|
if (!user.roleId && user.builder && user.builder.global) {
|
|
30
32
|
user.roleId = BUILTIN_ROLE_IDS.ADMIN
|
|
@@ -35,18 +37,18 @@ exports.updateAppRole = (appId, user) => {
|
|
|
35
37
|
return user
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
function processUser(
|
|
40
|
+
function processUser(user, { appId } = {}) {
|
|
39
41
|
if (user) {
|
|
40
42
|
delete user.password
|
|
41
43
|
}
|
|
42
|
-
return exports.updateAppRole(
|
|
44
|
+
return exports.updateAppRole(user, { appId })
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
exports.getCachedSelf = async (ctx, appId) => {
|
|
46
48
|
// this has to be tenant aware, can't depend on the context to find it out
|
|
47
49
|
// running some middlewares before the tenancy causes context to break
|
|
48
50
|
const user = await userCache.getUser(ctx.user._id)
|
|
49
|
-
return processUser(
|
|
51
|
+
return processUser(user, { appId })
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
exports.getRawGlobalUser = async userId => {
|
|
@@ -54,12 +56,13 @@ exports.getRawGlobalUser = async userId => {
|
|
|
54
56
|
return db.get(getGlobalIDFromUserMetadataID(userId))
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
exports.getGlobalUser = async
|
|
59
|
+
exports.getGlobalUser = async userId => {
|
|
58
60
|
let user = await exports.getRawGlobalUser(userId)
|
|
59
|
-
return processUser(
|
|
61
|
+
return processUser(user)
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
exports.getGlobalUsers = async (
|
|
64
|
+
exports.getGlobalUsers = async (users = null) => {
|
|
65
|
+
const appId = getAppId()
|
|
63
66
|
const db = getGlobalDB()
|
|
64
67
|
let globalUsers
|
|
65
68
|
if (users) {
|
|
@@ -86,11 +89,11 @@ exports.getGlobalUsers = async (appId = null, users = null) => {
|
|
|
86
89
|
if (!appId) {
|
|
87
90
|
return globalUsers
|
|
88
91
|
}
|
|
89
|
-
return globalUsers.map(user => exports.updateAppRole(
|
|
92
|
+
return globalUsers.map(user => exports.updateAppRole(user))
|
|
90
93
|
}
|
|
91
94
|
|
|
92
|
-
exports.getGlobalUsersFromMetadata = async
|
|
93
|
-
const globalUsers = await exports.getGlobalUsers(
|
|
95
|
+
exports.getGlobalUsersFromMetadata = async users => {
|
|
96
|
+
const globalUsers = await exports.getGlobalUsers(users)
|
|
94
97
|
return users.map(user => {
|
|
95
98
|
const globalUser = globalUsers.find(
|
|
96
99
|
globalUser => globalUser && user._id.includes(globalUser._id)
|
package/src/utilities/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const env = require("../environment")
|
|
2
2
|
const { OBJ_STORE_DIRECTORY } = require("../constants")
|
|
3
3
|
const { sanitizeKey } = require("@budibase/backend-core/objectStore")
|
|
4
|
-
const CouchDB = require("../db")
|
|
5
4
|
const { generateMetadataID } = require("../db/utils")
|
|
6
5
|
const Readable = require("stream").Readable
|
|
6
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
7
7
|
|
|
8
8
|
const BB_CDN = "https://cdn.budi.live"
|
|
9
9
|
|
|
@@ -73,8 +73,8 @@ exports.attachmentsRelativeURL = attachmentKey => {
|
|
|
73
73
|
)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
exports.updateEntityMetadata = async (
|
|
77
|
-
const db =
|
|
76
|
+
exports.updateEntityMetadata = async (type, entityId, updateFn) => {
|
|
77
|
+
const db = getAppDB()
|
|
78
78
|
const id = generateMetadataID(type, entityId)
|
|
79
79
|
// read it to see if it exists, we'll overwrite it no matter what
|
|
80
80
|
let rev,
|
|
@@ -99,14 +99,14 @@ exports.updateEntityMetadata = async (appId, type, entityId, updateFn) => {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
exports.saveEntityMetadata = async (
|
|
103
|
-
return exports.updateEntityMetadata(
|
|
102
|
+
exports.saveEntityMetadata = async (type, entityId, metadata) => {
|
|
103
|
+
return exports.updateEntityMetadata(type, entityId, () => {
|
|
104
104
|
return metadata
|
|
105
105
|
})
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
exports.deleteEntityMetadata = async (
|
|
109
|
-
const db =
|
|
108
|
+
exports.deleteEntityMetadata = async (type, entityId) => {
|
|
109
|
+
const db = getAppDB()
|
|
110
110
|
const id = generateMetadataID(type, entityId)
|
|
111
111
|
let rev
|
|
112
112
|
try {
|
|
@@ -141,16 +141,6 @@ exports.stringToReadStream = string => {
|
|
|
141
141
|
})
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
exports.doesDatabaseExist = async dbName => {
|
|
145
|
-
try {
|
|
146
|
-
const db = new CouchDB(dbName, { skip_setup: true })
|
|
147
|
-
const info = await db.info()
|
|
148
|
-
return info && !info.error
|
|
149
|
-
} catch (err) {
|
|
150
|
-
return false
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
144
|
exports.formatBytes = bytes => {
|
|
155
145
|
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
|
156
146
|
const byteIncrements = 1024
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const CouchDB = require("../../db")
|
|
2
1
|
const { createRoutingView } = require("../../db/views/staticViews")
|
|
3
2
|
const { ViewNames, getQueryIndex, UNICODE_MAX } = require("../../db/utils")
|
|
3
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
4
4
|
|
|
5
|
-
exports.getRoutingInfo = async
|
|
6
|
-
const db =
|
|
5
|
+
exports.getRoutingInfo = async () => {
|
|
6
|
+
const db = getAppDB()
|
|
7
7
|
try {
|
|
8
8
|
const allRouting = await db.query(getQueryIndex(ViewNames.ROUTING), {
|
|
9
9
|
startKey: "",
|
|
@@ -14,8 +14,8 @@ exports.getRoutingInfo = async appId => {
|
|
|
14
14
|
// check if the view doesn't exist, it should for all new instances
|
|
15
15
|
/* istanbul ignore next */
|
|
16
16
|
if (err != null && err.name === "not_found") {
|
|
17
|
-
await createRoutingView(
|
|
18
|
-
return exports.getRoutingInfo(
|
|
17
|
+
await createRoutingView()
|
|
18
|
+
return exports.getRoutingInfo()
|
|
19
19
|
} else {
|
|
20
20
|
throw err
|
|
21
21
|
}
|