@budibase/server 1.0.49 → 1.0.50-alpha.3
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.2c37968e.js → index.9fe798bd.js} +252 -249
- package/builder/assets/index.c0cc369d.css +6 -0
- 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 +4 -2
- 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
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { budibaseTempDir } = require("../budibaseDir");
|
|
12
|
-
const { isDev } = require("../index");
|
|
13
12
|
const fs = require("fs");
|
|
14
13
|
const { join } = require("path");
|
|
15
14
|
const uuid = require("uuid/v4");
|
|
@@ -20,6 +19,7 @@ const { updateClientLibrary } = require("./clientLibrary");
|
|
|
20
19
|
const env = require("../../environment");
|
|
21
20
|
const { USER_METDATA_PREFIX, LINK_USER_METADATA_PREFIX, } = require("../../db/utils");
|
|
22
21
|
const MemoryStream = require("memorystream");
|
|
22
|
+
const { getAppId } = require("@budibase/backend-core/context");
|
|
23
23
|
const TOP_LEVEL_PATH = join(__dirname, "..", "..", "..");
|
|
24
24
|
const NODE_MODULES_PATH = join(TOP_LEVEL_PATH, "node_modules");
|
|
25
25
|
/**
|
|
@@ -47,7 +47,7 @@ exports.init = () => {
|
|
|
47
47
|
* everything required to function is ready.
|
|
48
48
|
*/
|
|
49
49
|
exports.checkDevelopmentEnvironment = () => {
|
|
50
|
-
if (!isDev()) {
|
|
50
|
+
if (!env.isDev() || env.isTest()) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
if (!fs.existsSync(budibaseTempDir())) {
|
|
@@ -218,7 +218,8 @@ exports.downloadTemplate = (type, name) => __awaiter(void 0, void 0, void 0, fun
|
|
|
218
218
|
/**
|
|
219
219
|
* Retrieves component libraries from object store (or tmp symlink if in local)
|
|
220
220
|
*/
|
|
221
|
-
exports.getComponentLibraryManifest = (
|
|
221
|
+
exports.getComponentLibraryManifest = (library) => __awaiter(void 0, void 0, void 0, function* () {
|
|
222
|
+
const appId = getAppId();
|
|
222
223
|
const filename = "manifest.json";
|
|
223
224
|
/* istanbul ignore next */
|
|
224
225
|
// when testing in cypress and so on we need to get the package
|
package/dist/utilities/global.js
CHANGED
|
@@ -10,12 +10,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const { getMultiIDParams, getGlobalIDFromUserMetadataID, } = require("../db/utils");
|
|
12
12
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
13
|
-
const {
|
|
13
|
+
const { getProdAppID } = require("@budibase/backend-core/db");
|
|
14
14
|
const { getGlobalUserParams } = require("@budibase/backend-core/db");
|
|
15
15
|
const { user: userCache } = require("@budibase/backend-core/cache");
|
|
16
16
|
const { getGlobalDB, isUserInAppTenant, } = require("@budibase/backend-core/tenancy");
|
|
17
17
|
const env = require("../environment");
|
|
18
|
-
|
|
18
|
+
const { getAppId } = require("@budibase/backend-core/context");
|
|
19
|
+
exports.updateAppRole = (user, { appId } = {}) => {
|
|
20
|
+
appId = appId || getAppId();
|
|
19
21
|
if (!user || !user.roles) {
|
|
20
22
|
return user;
|
|
21
23
|
}
|
|
@@ -27,7 +29,7 @@ exports.updateAppRole = (appId, user) => {
|
|
|
27
29
|
return user;
|
|
28
30
|
}
|
|
29
31
|
// always use the deployed app
|
|
30
|
-
user.roleId = user.roles[
|
|
32
|
+
user.roleId = user.roles[getProdAppID(appId)];
|
|
31
33
|
// if a role wasn't found then either set as admin (builder) or public (everyone else)
|
|
32
34
|
if (!user.roleId && user.builder && user.builder.global) {
|
|
33
35
|
user.roleId = BUILTIN_ROLE_IDS.ADMIN;
|
|
@@ -38,27 +40,28 @@ exports.updateAppRole = (appId, user) => {
|
|
|
38
40
|
delete user.roles;
|
|
39
41
|
return user;
|
|
40
42
|
};
|
|
41
|
-
function processUser(
|
|
43
|
+
function processUser(user, { appId } = {}) {
|
|
42
44
|
if (user) {
|
|
43
45
|
delete user.password;
|
|
44
46
|
}
|
|
45
|
-
return exports.updateAppRole(
|
|
47
|
+
return exports.updateAppRole(user, { appId });
|
|
46
48
|
}
|
|
47
49
|
exports.getCachedSelf = (ctx, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
50
|
// this has to be tenant aware, can't depend on the context to find it out
|
|
49
51
|
// running some middlewares before the tenancy causes context to break
|
|
50
52
|
const user = yield userCache.getUser(ctx.user._id);
|
|
51
|
-
return processUser(
|
|
53
|
+
return processUser(user, { appId });
|
|
52
54
|
});
|
|
53
55
|
exports.getRawGlobalUser = (userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
56
|
const db = getGlobalDB();
|
|
55
57
|
return db.get(getGlobalIDFromUserMetadataID(userId));
|
|
56
58
|
});
|
|
57
|
-
exports.getGlobalUser = (
|
|
59
|
+
exports.getGlobalUser = (userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
60
|
let user = yield exports.getRawGlobalUser(userId);
|
|
59
|
-
return processUser(
|
|
61
|
+
return processUser(user);
|
|
60
62
|
});
|
|
61
|
-
exports.getGlobalUsers = (
|
|
63
|
+
exports.getGlobalUsers = (users = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
const appId = getAppId();
|
|
62
65
|
const db = getGlobalDB();
|
|
63
66
|
let globalUsers;
|
|
64
67
|
if (users) {
|
|
@@ -80,10 +83,10 @@ exports.getGlobalUsers = (appId = null, users = null) => __awaiter(void 0, void
|
|
|
80
83
|
if (!appId) {
|
|
81
84
|
return globalUsers;
|
|
82
85
|
}
|
|
83
|
-
return globalUsers.map(user => exports.updateAppRole(
|
|
86
|
+
return globalUsers.map(user => exports.updateAppRole(user));
|
|
84
87
|
});
|
|
85
|
-
exports.getGlobalUsersFromMetadata = (
|
|
86
|
-
const globalUsers = yield exports.getGlobalUsers(
|
|
88
|
+
exports.getGlobalUsersFromMetadata = (users) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const globalUsers = yield exports.getGlobalUsers(users);
|
|
87
90
|
return users.map(user => {
|
|
88
91
|
const globalUser = globalUsers.find(globalUser => globalUser && user._id.includes(globalUser._id));
|
|
89
92
|
return Object.assign(Object.assign({}, globalUser), user);
|
package/dist/utilities/index.js
CHANGED
|
@@ -11,9 +11,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const env = require("../environment");
|
|
12
12
|
const { OBJ_STORE_DIRECTORY } = require("../constants");
|
|
13
13
|
const { sanitizeKey } = require("@budibase/backend-core/objectStore");
|
|
14
|
-
const CouchDB = require("../db");
|
|
15
14
|
const { generateMetadataID } = require("../db/utils");
|
|
16
15
|
const Readable = require("stream").Readable;
|
|
16
|
+
const { getAppDB } = require("@budibase/backend-core/context");
|
|
17
17
|
const BB_CDN = "https://cdn.budi.live";
|
|
18
18
|
exports.wait = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
19
19
|
exports.isDev = env.isDev;
|
|
@@ -72,8 +72,8 @@ exports.clientLibraryPath = (appId, version) => {
|
|
|
72
72
|
exports.attachmentsRelativeURL = attachmentKey => {
|
|
73
73
|
return exports.checkSlashesInUrl(`${exports.objectStoreUrl()}/${attachmentKey}`);
|
|
74
74
|
};
|
|
75
|
-
exports.updateEntityMetadata = (
|
|
76
|
-
const db =
|
|
75
|
+
exports.updateEntityMetadata = (type, entityId, updateFn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const db = getAppDB();
|
|
77
77
|
const id = generateMetadataID(type, entityId);
|
|
78
78
|
// read it to see if it exists, we'll overwrite it no matter what
|
|
79
79
|
let rev, metadata = {};
|
|
@@ -93,13 +93,13 @@ exports.updateEntityMetadata = (appId, type, entityId, updateFn) => __awaiter(vo
|
|
|
93
93
|
const response = yield db.put(metadata);
|
|
94
94
|
return Object.assign(Object.assign({}, metadata), { _id: id, _rev: response.rev });
|
|
95
95
|
});
|
|
96
|
-
exports.saveEntityMetadata = (
|
|
97
|
-
return exports.updateEntityMetadata(
|
|
96
|
+
exports.saveEntityMetadata = (type, entityId, metadata) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
return exports.updateEntityMetadata(type, entityId, () => {
|
|
98
98
|
return metadata;
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
|
-
exports.deleteEntityMetadata = (
|
|
102
|
-
const db =
|
|
101
|
+
exports.deleteEntityMetadata = (type, entityId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
const db = getAppDB();
|
|
103
103
|
const id = generateMetadataID(type, entityId);
|
|
104
104
|
let rev;
|
|
105
105
|
try {
|
|
@@ -132,16 +132,6 @@ exports.stringToReadStream = string => {
|
|
|
132
132
|
},
|
|
133
133
|
});
|
|
134
134
|
};
|
|
135
|
-
exports.doesDatabaseExist = (dbName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
136
|
-
try {
|
|
137
|
-
const db = new CouchDB(dbName, { skip_setup: true });
|
|
138
|
-
const info = yield db.info();
|
|
139
|
-
return info && !info.error;
|
|
140
|
-
}
|
|
141
|
-
catch (err) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
135
|
exports.formatBytes = bytes => {
|
|
146
136
|
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
147
137
|
const byteIncrements = 1024;
|
|
@@ -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("../../db");
|
|
12
11
|
const { createRoutingView } = require("../../db/views/staticViews");
|
|
13
12
|
const { ViewNames, getQueryIndex, UNICODE_MAX } = require("../../db/utils");
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
|
+
exports.getRoutingInfo = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const db = getAppDB();
|
|
16
16
|
try {
|
|
17
17
|
const allRouting = yield db.query(getQueryIndex(ViewNames.ROUTING), {
|
|
18
18
|
startKey: "",
|
|
@@ -24,8 +24,8 @@ exports.getRoutingInfo = (appId) => __awaiter(void 0, void 0, void 0, function*
|
|
|
24
24
|
// check if the view doesn't exist, it should for all new instances
|
|
25
25
|
/* istanbul ignore next */
|
|
26
26
|
if (err != null && err.name === "not_found") {
|
|
27
|
-
yield createRoutingView(
|
|
28
|
-
return exports.getRoutingInfo(
|
|
27
|
+
yield createRoutingView();
|
|
28
|
+
return exports.getRoutingInfo();
|
|
29
29
|
}
|
|
30
30
|
else {
|
|
31
31
|
throw err;
|
|
@@ -15,8 +15,8 @@ const { attachmentsRelativeURL } = require("../index");
|
|
|
15
15
|
const { processFormulas } = require("./utils");
|
|
16
16
|
const { deleteFiles } = require("../../utilities/fileSystem/utilities");
|
|
17
17
|
const { ObjectStoreBuckets } = require("../../constants");
|
|
18
|
-
const { isProdAppID,
|
|
19
|
-
const
|
|
18
|
+
const { isProdAppID, getProdAppID, dbExists, } = require("@budibase/backend-core/db");
|
|
19
|
+
const { getAppId } = require("@budibase/backend-core/context");
|
|
20
20
|
const BASE_AUTO_ID = 1;
|
|
21
21
|
/**
|
|
22
22
|
* A map of how we convert various properties in rows to each other based on the row type.
|
|
@@ -175,6 +175,7 @@ function processAutoColumn(user, table, row, opts = { reprocessing: false, noAut
|
|
|
175
175
|
return { table, row };
|
|
176
176
|
}
|
|
177
177
|
exports.processAutoColumn = processAutoColumn;
|
|
178
|
+
exports.processFormulas = processFormulas;
|
|
178
179
|
/**
|
|
179
180
|
* This will coerce a value to the correct types based on the type transform map
|
|
180
181
|
* @param {object} row The value to coerce
|
|
@@ -218,11 +219,11 @@ exports.inputProcessing = (user = {}, table, row, opts = { noAutoRelationships:
|
|
|
218
219
|
}
|
|
219
220
|
continue;
|
|
220
221
|
}
|
|
221
|
-
//
|
|
222
|
-
// type coercion cannot completely remove the field, so have to do it here
|
|
222
|
+
// remove any formula values, they are to be generated
|
|
223
223
|
if (field.type === FieldTypes.FORMULA) {
|
|
224
224
|
delete clonedRow[key];
|
|
225
225
|
}
|
|
226
|
+
// otherwise coerce what is there to correct types
|
|
226
227
|
else {
|
|
227
228
|
clonedRow[key] = exports.coerce(value, field.type);
|
|
228
229
|
}
|
|
@@ -237,24 +238,22 @@ exports.inputProcessing = (user = {}, table, row, opts = { noAutoRelationships:
|
|
|
237
238
|
/**
|
|
238
239
|
* This function enriches the input rows with anything they are supposed to contain, for example
|
|
239
240
|
* link records or attachment links.
|
|
240
|
-
* @param {object} ctx the request which is looking for enriched rows.
|
|
241
241
|
* @param {object} table the table from which these rows came from originally, this is used to determine
|
|
242
242
|
* the schema of the rows and then enrich.
|
|
243
243
|
* @param {object[]|object} rows the rows which are to be enriched.
|
|
244
244
|
* @param {object} opts used to set some options for the output, such as disabling relationship squashing.
|
|
245
245
|
* @returns {object[]|object} the enriched rows will be returned.
|
|
246
246
|
*/
|
|
247
|
-
exports.outputProcessing = (
|
|
248
|
-
const appId = ctx.appId;
|
|
247
|
+
exports.outputProcessing = (table, rows, opts = { squash: true }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
249
248
|
let wasArray = true;
|
|
250
249
|
if (!(rows instanceof Array)) {
|
|
251
250
|
rows = [rows];
|
|
252
251
|
wasArray = false;
|
|
253
252
|
}
|
|
254
253
|
// attach any linked row information
|
|
255
|
-
let enriched = yield linkRows.attachFullLinkedDocs(
|
|
254
|
+
let enriched = yield linkRows.attachFullLinkedDocs(table, rows);
|
|
256
255
|
// process formulas
|
|
257
|
-
enriched = processFormulas(table, enriched);
|
|
256
|
+
enriched = processFormulas(table, enriched, { dynamic: true });
|
|
258
257
|
// update the attachments URL depending on hosting
|
|
259
258
|
for (let [property, column] of Object.entries(table.schema)) {
|
|
260
259
|
if (column.type === FieldTypes.ATTACHMENT) {
|
|
@@ -269,24 +268,26 @@ exports.outputProcessing = (ctx, table, rows, opts = { squash: true }) => __awai
|
|
|
269
268
|
}
|
|
270
269
|
}
|
|
271
270
|
if (opts.squash) {
|
|
272
|
-
enriched = yield linkRows.squashLinksToPrimaryDisplay(
|
|
271
|
+
enriched = yield linkRows.squashLinksToPrimaryDisplay(table, enriched);
|
|
273
272
|
}
|
|
274
273
|
return wasArray ? enriched : enriched[0];
|
|
275
274
|
});
|
|
276
275
|
/**
|
|
277
276
|
* Clean up any attachments that were attached to a row.
|
|
278
|
-
* @param {string} appId The ID of the app from which a row is being deleted.
|
|
279
277
|
* @param {object} table The table from which a row is being removed.
|
|
280
278
|
* @param {any} row optional - the row being removed.
|
|
281
279
|
* @param {any} rows optional - if multiple rows being deleted can do this in bulk.
|
|
282
280
|
* @param {any} oldRow optional - if updating a row this will determine the difference.
|
|
281
|
+
* @param {any} oldTable optional - if updating a table, can supply the old table to look for
|
|
282
|
+
* deleted attachment columns.
|
|
283
283
|
* @return {Promise<void>} When all attachments have been removed this will return.
|
|
284
284
|
*/
|
|
285
|
-
exports.cleanupAttachments = (
|
|
285
|
+
exports.cleanupAttachments = (table, { row, rows, oldRow, oldTable }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
286
|
+
const appId = getAppId();
|
|
286
287
|
if (!isProdAppID(appId)) {
|
|
287
|
-
const prodAppId =
|
|
288
|
+
const prodAppId = getProdAppID(appId);
|
|
288
289
|
// if prod exists, then don't allow deleting
|
|
289
|
-
const exists = yield dbExists(
|
|
290
|
+
const exists = yield dbExists(prodAppId);
|
|
290
291
|
if (exists) {
|
|
291
292
|
return;
|
|
292
293
|
}
|
|
@@ -297,12 +298,17 @@ exports.cleanupAttachments = (appId, table, { row, rows, oldRow }) => __awaiter(
|
|
|
297
298
|
files = files.concat(row[key].map(attachment => attachment.key));
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
|
-
|
|
301
|
+
const schemaToUse = oldTable ? oldTable.schema : table.schema;
|
|
302
|
+
for (let [key, schema] of Object.entries(schemaToUse)) {
|
|
301
303
|
if (schema.type !== FieldTypes.ATTACHMENT) {
|
|
302
304
|
continue;
|
|
303
305
|
}
|
|
304
|
-
//
|
|
305
|
-
if (
|
|
306
|
+
// old table had this column, new table doesn't - delete it
|
|
307
|
+
if (oldTable && !table.schema[key]) {
|
|
308
|
+
rows.forEach(row => addFiles(row, key));
|
|
309
|
+
}
|
|
310
|
+
else if (oldRow && row) {
|
|
311
|
+
// if updating, need to manage the differences
|
|
306
312
|
files = files.concat(getRemovedAttachmentKeys(oldRow, row, key));
|
|
307
313
|
}
|
|
308
314
|
else if (row) {
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const { FieldTypes } = require("../../constants");
|
|
2
|
+
const { FieldTypes, FormulaTypes } = require("../../constants");
|
|
3
3
|
const { processStringSync } = require("@budibase/string-templates");
|
|
4
4
|
/**
|
|
5
5
|
* Looks through the rows provided and finds formulas - which it then processes.
|
|
6
6
|
*/
|
|
7
|
-
exports.processFormulas = (table, rows) => {
|
|
7
|
+
exports.processFormulas = (table, rows, { dynamic, contextRows } = { dynamic: true }) => {
|
|
8
8
|
const single = !Array.isArray(rows);
|
|
9
9
|
if (single) {
|
|
10
10
|
rows = [rows];
|
|
11
|
+
contextRows = contextRows ? [contextRows] : contextRows;
|
|
11
12
|
}
|
|
12
13
|
for (let [column, schema] of Object.entries(table.schema)) {
|
|
13
|
-
|
|
14
|
+
const isStatic = schema.formulaType === FormulaTypes.STATIC;
|
|
15
|
+
if (schema.type !== FieldTypes.FORMULA ||
|
|
16
|
+
(dynamic && isStatic) ||
|
|
17
|
+
(!dynamic && !isStatic)) {
|
|
14
18
|
continue;
|
|
15
19
|
}
|
|
16
20
|
// iterate through rows and process formula
|
|
17
|
-
|
|
21
|
+
for (let i = 0; i < rows.length; i++) {
|
|
22
|
+
if (schema.formula) {
|
|
23
|
+
let row = rows[i];
|
|
24
|
+
let context = contextRows ? contextRows[i] : row;
|
|
25
|
+
rows[i] = Object.assign(Object.assign({}, row), { [column]: processStringSync(schema.formula, context) });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
18
28
|
}
|
|
19
29
|
return single ? rows[0] : rows;
|
|
20
30
|
};
|
|
@@ -8,12 +8,24 @@ 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 env = require("
|
|
12
|
-
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
11
|
+
const env = require("../../environment");
|
|
12
|
+
const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy");
|
|
13
13
|
const { StaticDatabases, generateNewUsageQuotaDoc, } = require("@budibase/backend-core/db");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
exports.useQuotas = () => {
|
|
15
|
+
// check if quotas are enabled
|
|
16
|
+
if (env.USE_QUOTAS) {
|
|
17
|
+
// check if there are any tenants without limits
|
|
18
|
+
if (env.EXCLUDE_QUOTAS_TENANTS) {
|
|
19
|
+
const excludedTenants = env.EXCLUDE_QUOTAS_TENANTS.replace(/\s/g, "").split(",");
|
|
20
|
+
const tenantId = getTenantId();
|
|
21
|
+
if (excludedTenants.includes(tenantId)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
};
|
|
17
29
|
exports.Properties = {
|
|
18
30
|
ROW: "rows",
|
|
19
31
|
UPLOAD: "storage",
|
|
@@ -21,49 +33,51 @@ exports.Properties = {
|
|
|
21
33
|
USER: "users",
|
|
22
34
|
AUTOMATION: "automationRuns",
|
|
23
35
|
APPS: "apps",
|
|
24
|
-
EMAILS: "emails",
|
|
36
|
+
EMAILS: "emails", // doesn't work yet
|
|
25
37
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
38
|
+
exports.getUsageQuotaDoc = (db) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
let quota;
|
|
40
|
+
try {
|
|
41
|
+
quota = yield db.get(StaticDatabases.GLOBAL.docs.usageQuota);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
// doc doesn't exist. Create it
|
|
45
|
+
quota = generateNewUsageQuotaDoc();
|
|
46
|
+
const response = yield db.put(quota);
|
|
47
|
+
quota._rev = response.rev;
|
|
48
|
+
}
|
|
49
|
+
return quota;
|
|
50
|
+
});
|
|
39
51
|
/**
|
|
40
52
|
* Given a specified tenantId this will add to the usage object for the specified property.
|
|
41
53
|
* @param {string} property The property which is to be added to (within the nested usageQuota object).
|
|
42
54
|
* @param {number} usage The amount (this can be negative) to adjust the number by.
|
|
55
|
+
* @param {object} opts optional - options such as dryRun, to check what update will do.
|
|
43
56
|
* @returns {Promise<void>} When this completes the API key will now be up to date - the quota period may have
|
|
44
57
|
* also been reset after this call.
|
|
45
58
|
*/
|
|
46
|
-
exports.update = (property, usage) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
if (!
|
|
59
|
+
exports.update = (property, usage, opts = { dryRun: false }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
if (!exports.useQuotas()) {
|
|
48
61
|
return;
|
|
49
62
|
}
|
|
50
63
|
try {
|
|
51
64
|
const db = getGlobalDB();
|
|
52
|
-
const quota = yield getUsageQuotaDoc(db);
|
|
53
|
-
// Check if the quota needs reset
|
|
54
|
-
if (Date.now() >= quota.quotaReset) {
|
|
55
|
-
quota.quotaReset = getNewQuotaReset();
|
|
56
|
-
for (let prop of Object.keys(quota.usageQuota)) {
|
|
57
|
-
quota.usageQuota[prop] = 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
65
|
+
const quota = yield exports.getUsageQuotaDoc(db);
|
|
60
66
|
// increment the quota
|
|
61
67
|
quota.usageQuota[property] += usage;
|
|
62
|
-
if (quota.usageQuota[property] > quota.usageLimits[property]
|
|
68
|
+
if (quota.usageQuota[property] > quota.usageLimits[property] &&
|
|
69
|
+
usage > 0 // allow for decrementing usage when the quota is already exceeded
|
|
70
|
+
) {
|
|
63
71
|
throw new Error(`You have exceeded your usage quota of ${quota.usageLimits[property]} ${property}.`);
|
|
64
72
|
}
|
|
73
|
+
if (quota.usageQuota[property] < 0) {
|
|
74
|
+
// never go negative if the quota has previously been exceeded
|
|
75
|
+
quota.usageQuota[property] = 0;
|
|
76
|
+
}
|
|
65
77
|
// update the usage quotas
|
|
66
|
-
|
|
78
|
+
if (!opts.dryRun) {
|
|
79
|
+
yield db.put(quota);
|
|
80
|
+
}
|
|
67
81
|
}
|
|
68
82
|
catch (err) {
|
|
69
83
|
console.error(`Error updating usage quotas for ${property}`, err);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
const { getRowParams, USER_METDATA_PREFIX } = require("../../db/utils");
|
|
12
|
+
const CouchDB = require("../../db");
|
|
13
|
+
const { isDevAppID, getDevelopmentAppID } = require("@budibase/backend-core/db");
|
|
14
|
+
const ROW_EXCLUSIONS = [USER_METDATA_PREFIX];
|
|
15
|
+
const getAppPairs = appIds => {
|
|
16
|
+
// collect the app ids into dev / prod pairs
|
|
17
|
+
// keyed by the dev app id
|
|
18
|
+
const pairs = {};
|
|
19
|
+
for (let appId of appIds) {
|
|
20
|
+
const devId = getDevelopmentAppID(appId);
|
|
21
|
+
if (!pairs[devId]) {
|
|
22
|
+
pairs[devId] = {};
|
|
23
|
+
}
|
|
24
|
+
if (isDevAppID(appId)) {
|
|
25
|
+
pairs[devId].devId = appId;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
pairs[devId].prodId = appId;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return pairs;
|
|
32
|
+
};
|
|
33
|
+
const getAppRows = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
// need to specify the app ID, as this is used for different apps in one call
|
|
35
|
+
const appDb = new CouchDB(appId);
|
|
36
|
+
const response = yield appDb.allDocs(getRowParams(null, null, {
|
|
37
|
+
include_docs: false,
|
|
38
|
+
}));
|
|
39
|
+
return response.rows
|
|
40
|
+
.map(r => r.id)
|
|
41
|
+
.filter(id => {
|
|
42
|
+
for (let exclusion of ROW_EXCLUSIONS) {
|
|
43
|
+
if (id.startsWith(exclusion)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Return a set of all rows in the given app ids.
|
|
52
|
+
* The returned rows will be unique on a per dev/prod app basis.
|
|
53
|
+
* Rows duplicates may exist across apps due to data import so they are not filtered out.
|
|
54
|
+
*/
|
|
55
|
+
exports.getUniqueRows = (appIds) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
let uniqueRows = [];
|
|
57
|
+
const pairs = getAppPairs(appIds);
|
|
58
|
+
for (let pair of Object.values(pairs)) {
|
|
59
|
+
let appRows = [];
|
|
60
|
+
for (let appId of [pair.devId, pair.prodId]) {
|
|
61
|
+
if (!appId) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
appRows.push(yield getAppRows(appId));
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
console.error(e);
|
|
69
|
+
// don't error out if we can't count the app rows, just continue
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// ensure uniqueness on a per app pair basis
|
|
73
|
+
// this can't be done on all rows because app import results in
|
|
74
|
+
// duplicate row ids across apps
|
|
75
|
+
uniqueRows = uniqueRows.concat(...new Set(appRows));
|
|
76
|
+
}
|
|
77
|
+
return uniqueRows;
|
|
78
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// UNUSED CODE
|
|
3
|
+
// Preserved for future use
|
|
4
|
+
/* eslint-disable no-unused-vars */
|
|
5
|
+
function getNewQuotaReset() {
|
|
6
|
+
return Date.now() + 2592000000;
|
|
7
|
+
}
|
|
8
|
+
function resetQuotasIfRequired(quota) {
|
|
9
|
+
// Check if the quota needs reset
|
|
10
|
+
if (Date.now() >= quota.quotaReset) {
|
|
11
|
+
quota.quotaReset = getNewQuotaReset();
|
|
12
|
+
for (let prop of Object.keys(quota.usageQuota)) {
|
|
13
|
+
quota.usageQuota[prop] = 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/utilities/users.js
CHANGED
|
@@ -8,15 +8,15 @@ 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("../db");
|
|
12
11
|
const { InternalTables } = require("../db/utils");
|
|
13
12
|
const { getGlobalUser } = require("../utilities/global");
|
|
13
|
+
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
14
|
exports.getFullUser = (ctx, userId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
-
const global = yield getGlobalUser(
|
|
15
|
+
const global = yield getGlobalUser(userId);
|
|
16
16
|
let metadata;
|
|
17
17
|
try {
|
|
18
18
|
// this will throw an error if the db doesn't exist, or there is no appId
|
|
19
|
-
const db =
|
|
19
|
+
const db = getAppDB();
|
|
20
20
|
metadata = yield db.get(userId);
|
|
21
21
|
}
|
|
22
22
|
catch (err) {
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const fetch = require("node-fetch");
|
|
12
12
|
const env = require("../environment");
|
|
13
13
|
const { checkSlashesInUrl } = require("./index");
|
|
14
|
-
const {
|
|
14
|
+
const { getProdAppID } = require("@budibase/backend-core/db");
|
|
15
15
|
const { updateAppRole } = require("./global");
|
|
16
16
|
const { Headers } = require("@budibase/backend-core/constants");
|
|
17
17
|
const { getTenantId, isTenantIdSet } = require("@budibase/backend-core/tenancy");
|
|
@@ -61,26 +61,6 @@ exports.sendSmtpEmail = (to, from, subject, contents, automation) => __awaiter(v
|
|
|
61
61
|
}
|
|
62
62
|
return response.json();
|
|
63
63
|
});
|
|
64
|
-
exports.getDeployedApps = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
|
-
try {
|
|
66
|
-
const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + `/api/apps`), request(null, {
|
|
67
|
-
method: "GET",
|
|
68
|
-
}));
|
|
69
|
-
const json = yield response.json();
|
|
70
|
-
const apps = {};
|
|
71
|
-
for (let [key, value] of Object.entries(json)) {
|
|
72
|
-
if (value.url) {
|
|
73
|
-
value.url = value.url.toLowerCase();
|
|
74
|
-
apps[key.toLowerCase()] = value;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return apps;
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
// error, cannot determine deployed apps, don't stop app creation - sort this later
|
|
81
|
-
return {};
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
64
|
exports.getGlobalSelf = (ctx, appId = null) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
65
|
const endpoint = `/api/global/users/self`;
|
|
86
66
|
const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + endpoint),
|
|
@@ -91,13 +71,13 @@ exports.getGlobalSelf = (ctx, appId = null) => __awaiter(void 0, void 0, void 0,
|
|
|
91
71
|
}
|
|
92
72
|
let json = yield response.json();
|
|
93
73
|
if (appId) {
|
|
94
|
-
json = updateAppRole(
|
|
74
|
+
json = updateAppRole(json);
|
|
95
75
|
}
|
|
96
76
|
return json;
|
|
97
77
|
});
|
|
98
78
|
exports.removeAppFromUserRoles = (ctx, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
-
const
|
|
100
|
-
const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${
|
|
79
|
+
const prodAppId = getProdAppID(appId);
|
|
80
|
+
const response = yield fetch(checkSlashesInUrl(env.WORKER_URL + `/api/global/roles/${prodAppId}`), request(ctx, {
|
|
101
81
|
method: "DELETE",
|
|
102
82
|
}));
|
|
103
83
|
if (response.status !== 200) {
|
package/nodemon.json
CHANGED