@budibase/server 1.0.49-alpha.1 → 1.0.49-alpha.13
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.ba78c49d.css → index.83c0944f.css} +1 -1
- package/builder/assets/{index.ed1cf508.js → index.f686d3cd.js} +184 -184
- package/builder/index.html +2 -2
- package/coverage/clover.xml +2656 -2712
- package/coverage/coverage-final.json +104 -105
- 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 +157 -136
- package/coverage/lcov-report/api/controllers/auth.js.html +11 -14
- 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 +10 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +31 -37
- package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
- package/coverage/lcov-report/api/controllers/index.html +69 -54
- 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/{migrations/usageQuotas/syncApps.js.html → api/controllers/migrations.js.html} +30 -45
- 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 +28 -28
- package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
- package/coverage/lcov-report/api/controllers/row/internal.js.html +60 -105
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +25 -31
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +21 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +27 -24
- 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 +27 -57
- package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
- package/coverage/lcov-report/api/controllers/table/index.html +37 -37
- package/coverage/lcov-report/api/controllers/table/index.js.html +20 -20
- package/coverage/lcov-report/api/controllers/table/internal.js.html +45 -54
- package/coverage/lcov-report/api/controllers/table/utils.js.html +67 -103
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +43 -52
- 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 +3 -3
- 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 +22 -7
- package/coverage/lcov-report/api/routes/index.js.html +10 -4
- 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/{migrations/usageQuotas/index.js.html → api/routes/migrations.js.html} +25 -55
- 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 +1 -1
- 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 +7 -10
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +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 +1 -1
- package/coverage/lcov-report/constants/index.js.html +26 -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 +1 -1
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +15 -27
- package/coverage/lcov-report/db/linkedRows/index.html +27 -27
- package/coverage/lcov-report/db/linkedRows/index.js.html +40 -82
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +40 -40
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +74 -74
- 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 +97 -112
- 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 +21 -15
- package/coverage/lcov-report/middleware/builder.js.html +3 -3
- package/coverage/lcov-report/middleware/currentapp.js.html +72 -60
- package/coverage/lcov-report/middleware/index.html +28 -28
- 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 +29 -35
- 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 +25 -25
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +26 -47
- 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 +57 -48
- package/coverage/lcov-report/utilities/index.html +27 -27
- package/coverage/lcov-report/utilities/index.js.html +42 -72
- 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 +11 -11
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +32 -74
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +13 -10
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +5 -2
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +9 -9
- package/coverage/lcov-report/utilities/workerRequests.js.html +16 -16
- package/coverage/lcov.info +4018 -4092
- package/dist/api/controllers/application.js +49 -48
- package/dist/api/controllers/auth.js +4 -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 +9 -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 +29 -44
- package/dist/api/controllers/row/internalSearch.js +11 -13
- package/dist/api/controllers/row/staticFormula.js +11 -11
- package/dist/api/controllers/row/utils.js +7 -6
- package/dist/api/controllers/screen.js +5 -7
- package/dist/api/controllers/static/index.js +4 -4
- package/dist/api/controllers/table/bulkFormula.js +14 -15
- package/dist/api/controllers/table/external.js +7 -10
- package/dist/api/controllers/table/index.js +5 -5
- package/dist/api/controllers/table/internal.js +16 -19
- package/dist/api/controllers/table/utils.js +29 -31
- package/dist/api/controllers/user.js +16 -20
- 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 -0
- package/dist/api/routes/migrations.js +9 -0
- 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 +1 -1
- package/dist/automations/steps/updateRow.js +1 -1
- package/dist/automations/triggers.js +27 -25
- package/dist/automations/utils.js +10 -5
- package/dist/db/linkedRows/LinkController.js +3 -7
- package/dist/db/linkedRows/index.js +16 -26
- package/dist/db/linkedRows/linkUtils.js +6 -6
- package/dist/db/views/staticViews.js +9 -10
- package/dist/environment.js +3 -1
- package/dist/integrations/base/sql.js +49 -15
- package/dist/integrations/utils.js +3 -0
- package/dist/middleware/authorized.js +5 -3
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +41 -37
- package/dist/middleware/usageQuota.js +2 -4
- package/dist/migrations/functions/appUrls.js +46 -0
- package/dist/migrations/functions/quotas1.js +50 -0
- package/dist/migrations/{usageQuotas → functions/usageQuotas}/index.js +6 -10
- package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncApps.js +12 -9
- package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncRows.js +16 -12
- package/dist/migrations/functions/userEmailViewCasing.js +24 -0
- package/dist/migrations/index.js +62 -0
- package/dist/package.json +4 -4
- package/dist/tests/utilities/TestConfiguration.js +70 -44
- package/dist/threads/automation.js +13 -11
- package/dist/threads/query.js +13 -19
- 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 +9 -10
- package/dist/utilities/usageQuota/index.js +1 -0
- package/dist/utilities/usageQuota/rows.js +1 -0
- package/dist/utilities/users.js +3 -3
- package/dist/utilities/workerRequests.js +4 -4
- package/package.json +5 -5
- 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 +38 -31
- package/src/api/controllers/auth.js +4 -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 +9 -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 +29 -44
- package/src/api/controllers/row/internalSearch.js +11 -13
- package/src/api/controllers/row/staticFormula.js +10 -11
- package/src/api/controllers/row/utils.js +7 -6
- package/src/api/controllers/screen.js +5 -7
- package/src/api/controllers/static/index.js +4 -4
- package/src/api/controllers/table/bulkFormula.js +13 -23
- package/src/api/controllers/table/external.js +7 -10
- package/src/api/controllers/table/index.js +5 -5
- package/src/api/controllers/table/internal.js +18 -21
- package/src/api/controllers/table/utils.js +29 -41
- package/src/api/controllers/user.js +17 -20
- 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 -0
- package/src/api/routes/migrations.js +14 -0
- 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/utilities/TestFunctions.js +39 -17
- package/src/app.ts +18 -5
- package/src/automations/automationUtils.js +2 -3
- package/src/automations/steps/createRow.js +0 -1
- package/src/automations/steps/updateRow.js +1 -1
- package/src/automations/triggers.js +33 -31
- package/src/automations/utils.js +9 -5
- package/src/db/linkedRows/LinkController.js +3 -7
- package/src/db/linkedRows/index.js +16 -30
- 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/environment.js +3 -1
- package/src/integrations/base/sql.ts +61 -22
- package/src/integrations/utils.ts +4 -1
- package/src/middleware/authorized.js +5 -3
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +50 -46
- package/src/middleware/tests/authorized.spec.js +7 -2
- package/src/middleware/tests/currentapp.spec.js +6 -0
- package/src/middleware/usageQuota.js +2 -4
- 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/{tests/usageQuotas/index.spec.js → functions/tests/quotas1.spec.js} +5 -5
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
- package/src/migrations/functions/usageQuotas/index.ts +8 -0
- package/src/migrations/{usageQuotas/syncApps.js → functions/usageQuotas/syncApps.ts} +6 -6
- package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
- package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncApps.spec.js +4 -4
- package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncRows.spec.js +4 -4
- 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 +73 -50
- package/src/threads/automation.js +17 -15
- package/src/threads/query.js +14 -21
- 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 +9 -23
- package/src/utilities/usageQuota/index.js +1 -0
- package/src/utilities/usageQuota/rows.js +1 -0
- package/src/utilities/users.js +3 -3
- package/src/utilities/workerRequests.js +4 -4
- package/tsconfig.json +2 -1
- package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
- package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +0 -143
- package/src/migrations/usageQuotas/index.js +0 -24
- package/src/migrations/usageQuotas/syncRows.js +0 -21
|
@@ -8,7 +8,6 @@ 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 env = require("../../environment");
|
|
13
12
|
const packageJson = require("../../../package.json");
|
|
14
13
|
const { createLinkView, createRoutingView, createAllSearchIndex, } = require("../../db/views/staticViews");
|
|
@@ -18,7 +17,7 @@ const { BUILTIN_ROLE_IDS, AccessController, } = require("@budibase/backend-core/
|
|
|
18
17
|
const { BASE_LAYOUTS } = require("../../constants/layouts");
|
|
19
18
|
const { cloneDeep } = require("lodash/fp");
|
|
20
19
|
const { processObject } = require("@budibase/string-templates");
|
|
21
|
-
const { getAllApps, isDevAppID,
|
|
20
|
+
const { getAllApps, isDevAppID, getProdAppID, Replication, } = require("@budibase/backend-core/db");
|
|
22
21
|
const { USERS_TABLE_SCHEMA } = require("../../constants");
|
|
23
22
|
const { removeAppFromUserRoles } = require("../../utilities/workerRequests");
|
|
24
23
|
const { clientLibraryPath, stringToReadStream } = require("../../utilities");
|
|
@@ -28,17 +27,20 @@ const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
|
|
|
28
27
|
const { syncGlobalUsers } = require("./user");
|
|
29
28
|
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
30
29
|
const { cleanupAutomations } = require("../../automations/utils");
|
|
30
|
+
const { getAppDB, getProdAppDB, updateAppId, } = require("@budibase/backend-core/context");
|
|
31
31
|
const URL_REGEX_SLASH = /\/|\\/g;
|
|
32
32
|
// utility function, need to do away with this
|
|
33
|
-
function getLayouts(
|
|
33
|
+
function getLayouts() {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const db = getAppDB();
|
|
35
36
|
return (yield db.allDocs(getLayoutParams(null, {
|
|
36
37
|
include_docs: true,
|
|
37
38
|
}))).rows.map(row => row.doc);
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
|
-
function getScreens(
|
|
41
|
+
function getScreens() {
|
|
41
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const db = getAppDB();
|
|
42
44
|
return (yield db.allDocs(getScreenParams(null, {
|
|
43
45
|
include_docs: true,
|
|
44
46
|
}))).rows.map(row => row.doc);
|
|
@@ -49,24 +51,22 @@ function getUserRoleId(ctx) {
|
|
|
49
51
|
? BUILTIN_ROLE_IDS.PUBLIC
|
|
50
52
|
: ctx.user.role._id;
|
|
51
53
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
});
|
|
69
|
-
}
|
|
54
|
+
exports.getAppUrl = ctx => {
|
|
55
|
+
// construct the url
|
|
56
|
+
let url;
|
|
57
|
+
if (ctx.request.body.url) {
|
|
58
|
+
// if the url is provided, use that
|
|
59
|
+
url = encodeURI(ctx.request.body.url);
|
|
60
|
+
}
|
|
61
|
+
else if (ctx.request.body.name) {
|
|
62
|
+
// otherwise use the name
|
|
63
|
+
url = encodeURI(`${ctx.request.body.name}`);
|
|
64
|
+
}
|
|
65
|
+
if (url) {
|
|
66
|
+
url = `/${url.replace(URL_REGEX_SLASH, "")}`.toLowerCase();
|
|
67
|
+
}
|
|
68
|
+
return url;
|
|
69
|
+
};
|
|
70
70
|
const checkAppUrl = (ctx, apps, url, currentAppId) => {
|
|
71
71
|
if (currentAppId) {
|
|
72
72
|
apps = apps.filter(app => app.appId !== currentAppId);
|
|
@@ -92,7 +92,8 @@ function createInstance(template) {
|
|
|
92
92
|
const tenantId = isMultiTenant() ? getTenantId() : null;
|
|
93
93
|
const baseAppId = generateAppID(tenantId);
|
|
94
94
|
const appId = generateDevAppID(baseAppId);
|
|
95
|
-
|
|
95
|
+
updateAppId(appId);
|
|
96
|
+
const db = getAppDB();
|
|
96
97
|
yield db.put({
|
|
97
98
|
_id: "_design/database",
|
|
98
99
|
// view collation information, read before writing any complex views:
|
|
@@ -101,9 +102,9 @@ function createInstance(template) {
|
|
|
101
102
|
});
|
|
102
103
|
// NOTE: indexes need to be created before any tables/templates
|
|
103
104
|
// add view for linked rows
|
|
104
|
-
yield createLinkView(
|
|
105
|
-
yield createRoutingView(
|
|
106
|
-
yield createAllSearchIndex(
|
|
105
|
+
yield createLinkView();
|
|
106
|
+
yield createRoutingView();
|
|
107
|
+
yield createAllSearchIndex();
|
|
107
108
|
// replicate the template data to the instance DB
|
|
108
109
|
// this is currently very hard to test, downloading and importing template files
|
|
109
110
|
if (template && template.templateString) {
|
|
@@ -129,7 +130,7 @@ function createInstance(template) {
|
|
|
129
130
|
exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
131
|
const dev = ctx.query && ctx.query.status === AppStatus.DEV;
|
|
131
132
|
const all = ctx.query && ctx.query.status === AppStatus.ALL;
|
|
132
|
-
const apps = yield getAllApps(
|
|
133
|
+
const apps = yield getAllApps({ dev, all });
|
|
133
134
|
// get the locks for all the dev apps
|
|
134
135
|
if (dev || all) {
|
|
135
136
|
const locks = yield getAllLocks();
|
|
@@ -150,11 +151,10 @@ exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
150
151
|
ctx.body = apps;
|
|
151
152
|
});
|
|
152
153
|
exports.fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
-
const
|
|
154
|
-
const layouts = yield getLayouts(db);
|
|
154
|
+
const layouts = yield getLayouts();
|
|
155
155
|
const userRoleId = getUserRoleId(ctx);
|
|
156
|
-
const accessController = new AccessController(
|
|
157
|
-
const screens = yield accessController.checkScreensAccess(yield getScreens(
|
|
156
|
+
const accessController = new AccessController();
|
|
157
|
+
const screens = yield accessController.checkScreensAccess(yield getScreens(), userRoleId);
|
|
158
158
|
ctx.body = {
|
|
159
159
|
layouts,
|
|
160
160
|
screens,
|
|
@@ -162,14 +162,14 @@ exports.fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function
|
|
|
162
162
|
};
|
|
163
163
|
});
|
|
164
164
|
exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
165
|
-
const db =
|
|
165
|
+
const db = getAppDB();
|
|
166
166
|
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
167
|
-
const layouts = yield getLayouts(
|
|
168
|
-
let screens = yield getScreens(
|
|
167
|
+
const layouts = yield getLayouts();
|
|
168
|
+
let screens = yield getScreens();
|
|
169
169
|
// Only filter screens if the user is not a builder
|
|
170
170
|
if (!(ctx.user.builder && ctx.user.builder.global)) {
|
|
171
171
|
const userRoleId = getUserRoleId(ctx);
|
|
172
|
-
const accessController = new AccessController(
|
|
172
|
+
const accessController = new AccessController();
|
|
173
173
|
screens = yield accessController.checkScreensAccess(screens, userRoleId);
|
|
174
174
|
}
|
|
175
175
|
ctx.body = {
|
|
@@ -180,10 +180,10 @@ exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* (
|
|
|
180
180
|
};
|
|
181
181
|
});
|
|
182
182
|
exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
-
const apps = yield getAllApps(
|
|
183
|
+
const apps = yield getAllApps({ dev: true });
|
|
184
184
|
const name = ctx.request.body.name;
|
|
185
185
|
checkAppName(ctx, apps, name);
|
|
186
|
-
const url =
|
|
186
|
+
const url = exports.getAppUrl(ctx);
|
|
187
187
|
checkAppUrl(ctx, apps, url);
|
|
188
188
|
const { useTemplate, templateKey, templateString } = ctx.request.body;
|
|
189
189
|
const instanceConfig = {
|
|
@@ -196,7 +196,7 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
196
196
|
}
|
|
197
197
|
const instance = yield createInstance(instanceConfig);
|
|
198
198
|
const appId = instance._id;
|
|
199
|
-
const db =
|
|
199
|
+
const db = getAppDB();
|
|
200
200
|
let _rev;
|
|
201
201
|
try {
|
|
202
202
|
// if template there will be an existing doc
|
|
@@ -239,13 +239,13 @@ exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
239
239
|
// This endpoint currently operates as a PATCH rather than a PUT
|
|
240
240
|
// Thus name and url fields are handled only if present
|
|
241
241
|
exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
242
|
-
const apps = yield getAllApps(
|
|
242
|
+
const apps = yield getAllApps({ dev: true });
|
|
243
243
|
// validation
|
|
244
244
|
const name = ctx.request.body.name;
|
|
245
245
|
if (name) {
|
|
246
246
|
checkAppName(ctx, apps, name, ctx.params.appId);
|
|
247
247
|
}
|
|
248
|
-
const url = yield getAppUrl(ctx);
|
|
248
|
+
const url = yield exports.getAppUrl(ctx);
|
|
249
249
|
if (url) {
|
|
250
250
|
checkAppUrl(ctx, apps, url, ctx.params.appId);
|
|
251
251
|
ctx.request.body.url = url;
|
|
@@ -256,7 +256,7 @@ exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
256
256
|
});
|
|
257
257
|
exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
258
|
// Get current app version
|
|
259
|
-
const db =
|
|
259
|
+
const db = getAppDB();
|
|
260
260
|
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
261
261
|
const currentVersion = application.version;
|
|
262
262
|
// Update client library and manifest
|
|
@@ -275,7 +275,7 @@ exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
275
275
|
});
|
|
276
276
|
exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
277
|
// Check app can be reverted
|
|
278
|
-
const db =
|
|
278
|
+
const db = getAppDB();
|
|
279
279
|
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
280
280
|
if (!application.revertableVersion) {
|
|
281
281
|
ctx.throw(400, "There is no version to revert to");
|
|
@@ -294,7 +294,7 @@ exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
294
294
|
ctx.body = data;
|
|
295
295
|
});
|
|
296
296
|
exports.delete = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
297
|
-
const db =
|
|
297
|
+
const db = getAppDB();
|
|
298
298
|
const result = yield db.destroy();
|
|
299
299
|
/* istanbul ignore next */
|
|
300
300
|
if (!env.isTest() && !ctx.query.unpublish) {
|
|
@@ -315,9 +315,10 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
315
315
|
ctx.throw(400, "This action cannot be performed for production apps");
|
|
316
316
|
}
|
|
317
317
|
// replicate prod to dev
|
|
318
|
-
const prodAppId =
|
|
318
|
+
const prodAppId = getProdAppID(appId);
|
|
319
319
|
try {
|
|
320
|
-
|
|
320
|
+
// specific case, want to make sure setup is skipped
|
|
321
|
+
const prodDb = getProdAppDB({ skip_setup: true });
|
|
321
322
|
const info = yield prodDb.info();
|
|
322
323
|
if (info.error)
|
|
323
324
|
throw info.error;
|
|
@@ -346,7 +347,7 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
346
347
|
error = err;
|
|
347
348
|
}
|
|
348
349
|
// sync the users
|
|
349
|
-
yield syncGlobalUsers(
|
|
350
|
+
yield syncGlobalUsers();
|
|
350
351
|
if (error) {
|
|
351
352
|
ctx.throw(400, error);
|
|
352
353
|
}
|
|
@@ -357,7 +358,7 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
357
358
|
}
|
|
358
359
|
});
|
|
359
360
|
const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
360
|
-
const db =
|
|
361
|
+
const db = getAppDB();
|
|
361
362
|
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
362
363
|
const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
|
|
363
364
|
if (appPackage._rev !== application._rev) {
|
|
@@ -372,7 +373,7 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
|
|
|
372
373
|
return response;
|
|
373
374
|
});
|
|
374
375
|
const createEmptyAppPackage = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
|
|
375
|
-
const db =
|
|
376
|
+
const db = getAppDB();
|
|
376
377
|
let screensAndLayouts = [];
|
|
377
378
|
for (let layout of BASE_LAYOUTS) {
|
|
378
379
|
const cloned = cloneDeep(layout);
|
|
@@ -8,13 +8,12 @@ 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 { outputProcessing } = require("../../utilities/rowProcessor");
|
|
13
12
|
const { InternalTables } = require("../../db/utils");
|
|
14
13
|
const { getFullUser } = require("../../utilities/users");
|
|
15
14
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
15
|
+
const { getAppDB, getAppId } = require("@budibase/backend-core/context");
|
|
16
16
|
exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const appId = ctx.appId;
|
|
18
17
|
let userId = ctx.user.userId || ctx.user._id;
|
|
19
18
|
/* istanbul ignore next */
|
|
20
19
|
if (!userId) {
|
|
@@ -26,8 +25,8 @@ exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
26
25
|
delete user.roles;
|
|
27
26
|
// forward the csrf token from the session
|
|
28
27
|
user.csrfToken = ctx.user.csrfToken;
|
|
29
|
-
if (
|
|
30
|
-
const db =
|
|
28
|
+
if (getAppId()) {
|
|
29
|
+
const db = getAppDB();
|
|
31
30
|
// remove the full roles structure
|
|
32
31
|
delete user.roles;
|
|
33
32
|
try {
|
|
@@ -36,7 +35,7 @@ exports.fetchSelf = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
36
35
|
// make sure there is never a stale csrf token
|
|
37
36
|
delete metadata.csrfToken;
|
|
38
37
|
// specifically needs to make sure is enriched
|
|
39
|
-
ctx.body = yield outputProcessing(
|
|
38
|
+
ctx.body = yield outputProcessing(userTable, Object.assign(Object.assign({}, user), metadata));
|
|
40
39
|
}
|
|
41
40
|
catch (err) {
|
|
42
41
|
let response;
|
|
@@ -8,7 +8,6 @@ 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 actions = require("../../automations/actions");
|
|
13
12
|
const triggers = require("../../automations/triggers");
|
|
14
13
|
const { getAutomationParams, generateAutomationID } = require("../../db/utils");
|
|
@@ -16,6 +15,7 @@ const { checkForWebhooks, updateTestHistory, removeDeprecated, } = require("../.
|
|
|
16
15
|
const { deleteEntityMetadata } = require("../../utilities");
|
|
17
16
|
const { MetadataTypes } = require("../../constants");
|
|
18
17
|
const { setTestFlag, clearTestFlag } = require("../../utilities/redis");
|
|
18
|
+
const { getAppDB } = require("@budibase/backend-core/context");
|
|
19
19
|
const ACTION_DEFS = removeDeprecated(actions.ACTION_DEFINITIONS);
|
|
20
20
|
const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS);
|
|
21
21
|
/*************************
|
|
@@ -23,10 +23,10 @@ const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS);
|
|
|
23
23
|
* BUILDER FUNCTIONS *
|
|
24
24
|
* *
|
|
25
25
|
*************************/
|
|
26
|
-
function cleanupAutomationMetadata(
|
|
26
|
+
function cleanupAutomationMetadata(automationId) {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
yield deleteEntityMetadata(
|
|
29
|
-
yield deleteEntityMetadata(
|
|
28
|
+
yield deleteEntityMetadata(MetadataTypes.AUTOMATION_TEST_INPUT, automationId);
|
|
29
|
+
yield deleteEntityMetadata(MetadataTypes.AUTOMATION_TEST_HISTORY, automationId);
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
function cleanAutomationInputs(automation) {
|
|
@@ -54,7 +54,7 @@ function cleanAutomationInputs(automation) {
|
|
|
54
54
|
}
|
|
55
55
|
exports.create = function (ctx) {
|
|
56
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
const db =
|
|
57
|
+
const db = getAppDB();
|
|
58
58
|
let automation = ctx.request.body;
|
|
59
59
|
automation.appId = ctx.appId;
|
|
60
60
|
// call through to update if already exists
|
|
@@ -65,7 +65,6 @@ exports.create = function (ctx) {
|
|
|
65
65
|
automation.type = "automation";
|
|
66
66
|
automation = cleanAutomationInputs(automation);
|
|
67
67
|
automation = yield checkForWebhooks({
|
|
68
|
-
appId: ctx.appId,
|
|
69
68
|
newAuto: automation,
|
|
70
69
|
});
|
|
71
70
|
const response = yield db.put(automation);
|
|
@@ -79,13 +78,12 @@ exports.create = function (ctx) {
|
|
|
79
78
|
};
|
|
80
79
|
exports.update = function (ctx) {
|
|
81
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
const db =
|
|
81
|
+
const db = getAppDB();
|
|
83
82
|
let automation = ctx.request.body;
|
|
84
83
|
automation.appId = ctx.appId;
|
|
85
84
|
const oldAutomation = yield db.get(automation._id);
|
|
86
85
|
automation = cleanAutomationInputs(automation);
|
|
87
86
|
automation = yield checkForWebhooks({
|
|
88
|
-
appId: ctx.appId,
|
|
89
87
|
oldAuto: oldAutomation,
|
|
90
88
|
newAuto: automation,
|
|
91
89
|
});
|
|
@@ -110,7 +108,7 @@ exports.update = function (ctx) {
|
|
|
110
108
|
};
|
|
111
109
|
exports.fetch = function (ctx) {
|
|
112
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const db =
|
|
111
|
+
const db = getAppDB();
|
|
114
112
|
const response = yield db.allDocs(getAutomationParams(null, {
|
|
115
113
|
include_docs: true,
|
|
116
114
|
}));
|
|
@@ -119,21 +117,20 @@ exports.fetch = function (ctx) {
|
|
|
119
117
|
};
|
|
120
118
|
exports.find = function (ctx) {
|
|
121
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
-
const db =
|
|
120
|
+
const db = getAppDB();
|
|
123
121
|
ctx.body = yield db.get(ctx.params.id);
|
|
124
122
|
});
|
|
125
123
|
};
|
|
126
124
|
exports.destroy = function (ctx) {
|
|
127
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
const db =
|
|
126
|
+
const db = getAppDB();
|
|
129
127
|
const automationId = ctx.params.id;
|
|
130
128
|
const oldAutomation = yield db.get(automationId);
|
|
131
129
|
yield checkForWebhooks({
|
|
132
|
-
appId: ctx.appId,
|
|
133
130
|
oldAuto: oldAutomation,
|
|
134
131
|
});
|
|
135
132
|
// delete metadata first
|
|
136
|
-
yield cleanupAutomationMetadata(
|
|
133
|
+
yield cleanupAutomationMetadata(automationId);
|
|
137
134
|
ctx.body = yield db.remove(automationId, ctx.params.rev);
|
|
138
135
|
});
|
|
139
136
|
};
|
|
@@ -162,10 +159,9 @@ module.exports.getDefinitionList = function (ctx) {
|
|
|
162
159
|
*********************/
|
|
163
160
|
exports.trigger = function (ctx) {
|
|
164
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
-
const
|
|
166
|
-
const db = new CouchDB(appId);
|
|
162
|
+
const db = getAppDB();
|
|
167
163
|
let automation = yield db.get(ctx.params.id);
|
|
168
|
-
yield triggers.externalTrigger(automation, Object.assign(Object.assign({}, ctx.request.body), { appId }));
|
|
164
|
+
yield triggers.externalTrigger(automation, Object.assign(Object.assign({}, ctx.request.body), { appId: ctx.appId }));
|
|
169
165
|
ctx.body = {
|
|
170
166
|
message: `Automation ${automation._id} has been triggered.`,
|
|
171
167
|
automation,
|
|
@@ -184,12 +180,11 @@ function prepareTestInput(input) {
|
|
|
184
180
|
}
|
|
185
181
|
exports.test = function (ctx) {
|
|
186
182
|
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
-
const
|
|
188
|
-
const db = new CouchDB(appId);
|
|
183
|
+
const db = getAppDB();
|
|
189
184
|
let automation = yield db.get(ctx.params.id);
|
|
190
185
|
yield setTestFlag(automation._id);
|
|
191
186
|
const testInput = prepareTestInput(ctx.request.body);
|
|
192
|
-
const response = yield triggers.externalTrigger(automation, Object.assign(Object.assign({}, testInput), { appId }), { getResponses: true });
|
|
187
|
+
const response = yield triggers.externalTrigger(automation, Object.assign(Object.assign({}, testInput), { appId: ctx.appId }), { getResponses: true });
|
|
193
188
|
// save a test history run
|
|
194
189
|
yield updateTestHistory(ctx.appId, automation, Object.assign(Object.assign({}, ctx.request.body), { occurredAt: new Date().getTime() }));
|
|
195
190
|
yield clearTestFlag(automation._id);
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
const env = require("../../environment");
|
|
12
12
|
const { getAllApps } = require("@budibase/backend-core/db");
|
|
13
|
-
const CouchDB = require("../../db");
|
|
14
13
|
const { exportDB, sendTempFile, readFileSync, } = require("../../utilities/fileSystem");
|
|
15
14
|
const { stringToReadStream } = require("../../utilities");
|
|
16
15
|
const { getGlobalDBName, getGlobalDB, } = require("@budibase/backend-core/tenancy");
|
|
@@ -33,7 +32,7 @@ exports.exportApps = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
33
32
|
if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
|
|
34
33
|
ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.");
|
|
35
34
|
}
|
|
36
|
-
const apps = yield getAllApps(
|
|
35
|
+
const apps = yield getAllApps({ all: true });
|
|
37
36
|
const globalDBString = yield exportDB(getGlobalDBName(), {
|
|
38
37
|
filter: doc => !doc._id.startsWith(DocumentTypes.USER),
|
|
39
38
|
});
|
|
@@ -65,7 +64,7 @@ function hasBeenImported() {
|
|
|
65
64
|
if (!env.SELF_HOSTED || env.MULTI_TENANCY) {
|
|
66
65
|
return true;
|
|
67
66
|
}
|
|
68
|
-
const apps = yield getAllApps(
|
|
67
|
+
const apps = yield getAllApps({ all: true });
|
|
69
68
|
return apps.length !== 0;
|
|
70
69
|
});
|
|
71
70
|
}
|
|
@@ -8,16 +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 { DocumentTypes } = require("../../db/utils");
|
|
13
12
|
const { getComponentLibraryManifest } = require("../../utilities/fileSystem");
|
|
13
|
+
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
14
|
exports.fetchAppComponentDefinitions = function (ctx) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const
|
|
17
|
-
const db = new CouchDB(appId);
|
|
16
|
+
const db = getAppDB();
|
|
18
17
|
const app = yield db.get(DocumentTypes.APP_METADATA);
|
|
19
18
|
let componentManifests = yield Promise.all(app.componentLibraries.map((library) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
-
let manifest = yield getComponentLibraryManifest(
|
|
19
|
+
let manifest = yield getComponentLibraryManifest(library);
|
|
21
20
|
return {
|
|
22
21
|
manifest,
|
|
23
22
|
library,
|
|
@@ -8,24 +8,23 @@ 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 { generateDatasourceID, getDatasourceParams, getQueryParams, DocumentTypes, BudibaseInternalDB, getTableParams, } = require("../../db/utils");
|
|
13
12
|
const { BuildSchemaErrors, InvalidColumns } = require("../../constants");
|
|
14
13
|
const { integrations } = require("../../integrations");
|
|
15
14
|
const { getDatasourceAndQuery } = require("./row/utils");
|
|
16
15
|
const { invalidateDynamicVariables } = require("../../threads/utils");
|
|
16
|
+
const { getAppDB } = require("@budibase/backend-core/context");
|
|
17
17
|
exports.fetch = function (ctx) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const database = new CouchDB(ctx.appId);
|
|
20
19
|
// Get internal tables
|
|
21
|
-
const db =
|
|
20
|
+
const db = getAppDB();
|
|
22
21
|
const internalTables = yield db.allDocs(getTableParams(null, {
|
|
23
22
|
include_docs: true,
|
|
24
23
|
}));
|
|
25
24
|
const internal = internalTables.rows.map(row => row.doc);
|
|
26
25
|
const bbInternalDb = Object.assign(Object.assign({}, BudibaseInternalDB), { entities: internal });
|
|
27
26
|
// Get external datasources
|
|
28
|
-
const datasources = (yield
|
|
27
|
+
const datasources = (yield db.allDocs(getDatasourceParams(null, {
|
|
29
28
|
include_docs: true,
|
|
30
29
|
}))).rows.map(row => row.doc);
|
|
31
30
|
for (let datasource of datasources) {
|
|
@@ -39,7 +38,7 @@ exports.fetch = function (ctx) {
|
|
|
39
38
|
};
|
|
40
39
|
exports.buildSchemaFromDb = function (ctx) {
|
|
41
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const db =
|
|
41
|
+
const db = getAppDB();
|
|
43
42
|
const datasource = yield db.get(ctx.params.datasourceId);
|
|
44
43
|
const { tables, error } = yield buildSchemaHelper(datasource);
|
|
45
44
|
datasource.entities = tables;
|
|
@@ -81,7 +80,7 @@ const invalidateVariables = (existingDatasource, updatedDatasource) => __awaiter
|
|
|
81
80
|
});
|
|
82
81
|
exports.update = function (ctx) {
|
|
83
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
const db =
|
|
83
|
+
const db = getAppDB();
|
|
85
84
|
const datasourceId = ctx.params.datasourceId;
|
|
86
85
|
let datasource = yield db.get(datasourceId);
|
|
87
86
|
const auth = datasource.config.auth;
|
|
@@ -107,7 +106,7 @@ exports.update = function (ctx) {
|
|
|
107
106
|
};
|
|
108
107
|
exports.save = function (ctx) {
|
|
109
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
const db =
|
|
109
|
+
const db = getAppDB();
|
|
111
110
|
const plus = ctx.request.body.datasource.plus;
|
|
112
111
|
const fetchSchema = ctx.request.body.fetchSchema;
|
|
113
112
|
const datasource = Object.assign({ _id: generateDatasourceID({ plus }), type: plus ? DocumentTypes.DATASOURCE_PLUS : DocumentTypes.DATASOURCE }, ctx.request.body.datasource);
|
|
@@ -135,7 +134,7 @@ exports.save = function (ctx) {
|
|
|
135
134
|
};
|
|
136
135
|
exports.destroy = function (ctx) {
|
|
137
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
const db =
|
|
137
|
+
const db = getAppDB();
|
|
139
138
|
// Delete all queries for the datasource
|
|
140
139
|
const queries = yield db.allDocs(getQueryParams(ctx.params.datasourceId, null));
|
|
141
140
|
yield db.bulkDocs(queries.rows.map(row => ({
|
|
@@ -151,7 +150,7 @@ exports.destroy = function (ctx) {
|
|
|
151
150
|
};
|
|
152
151
|
exports.find = function (ctx) {
|
|
153
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
const database =
|
|
153
|
+
const database = getAppDB();
|
|
155
154
|
ctx.body = yield database.get(ctx.params.datasourceId);
|
|
156
155
|
});
|
|
157
156
|
};
|
|
@@ -160,7 +159,7 @@ exports.query = function (ctx) {
|
|
|
160
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
160
|
const queryJson = ctx.request.body;
|
|
162
161
|
try {
|
|
163
|
-
ctx.body = yield getDatasourceAndQuery(
|
|
162
|
+
ctx.body = yield getDatasourceAndQuery(queryJson);
|
|
164
163
|
}
|
|
165
164
|
catch (err) {
|
|
166
165
|
ctx.throw(400, err);
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const newid = require("../../../db/newid");
|
|
3
|
+
const { getAppId } = require("@budibase/backend-core/context");
|
|
3
4
|
/**
|
|
4
5
|
* This is used to pass around information about the deployment that is occurring
|
|
5
6
|
*/
|
|
6
7
|
class Deployment {
|
|
7
|
-
constructor(
|
|
8
|
-
this.appId = appId;
|
|
8
|
+
constructor(id = null) {
|
|
9
9
|
this._id = id || newid();
|
|
10
10
|
}
|
|
11
|
-
getAppId() {
|
|
12
|
-
return this.appId;
|
|
13
|
-
}
|
|
14
11
|
setVerification(verification) {
|
|
15
12
|
if (!verification) {
|
|
16
13
|
return;
|
|
@@ -37,7 +34,7 @@ class Deployment {
|
|
|
37
34
|
getJSON() {
|
|
38
35
|
const obj = {
|
|
39
36
|
_id: this._id,
|
|
40
|
-
appId:
|
|
37
|
+
appId: getAppId(),
|
|
41
38
|
status: this.status,
|
|
42
39
|
};
|
|
43
40
|
if (this.err) {
|
|
@@ -8,12 +8,12 @@ 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 Deployment = require("./Deployment");
|
|
13
|
-
const { Replication,
|
|
12
|
+
const { Replication, getProdAppID, getDevelopmentAppID, } = require("@budibase/backend-core/db");
|
|
14
13
|
const { DocumentTypes, getAutomationParams } = require("../../../db/utils");
|
|
15
14
|
const { disableAllCrons, enableCronTrigger, } = require("../../../automations/utils");
|
|
16
15
|
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
16
|
+
const { getAppId, getAppDB, getProdAppDB, } = require("@budibase/backend-core/context");
|
|
17
17
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
18
18
|
const MAX_PENDING_TIME_MS = 30 * 60000;
|
|
19
19
|
const DeploymentStatus = {
|
|
@@ -39,9 +39,8 @@ function checkAllDeployments(deployments) {
|
|
|
39
39
|
}
|
|
40
40
|
function storeDeploymentHistory(deployment) {
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const appId = deployment.getAppId();
|
|
43
42
|
const deploymentJSON = deployment.getJSON();
|
|
44
|
-
const db =
|
|
43
|
+
const db = getAppDB();
|
|
45
44
|
let deploymentDoc;
|
|
46
45
|
try {
|
|
47
46
|
// theres only one deployment doc per app database
|
|
@@ -62,7 +61,7 @@ function storeDeploymentHistory(deployment) {
|
|
|
62
61
|
}
|
|
63
62
|
function initDeployedApp(prodAppId) {
|
|
64
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const db =
|
|
64
|
+
const db = getProdAppDB();
|
|
66
65
|
console.log("Reading automation docs");
|
|
67
66
|
const automations = (yield db.allDocs(getAutomationParams(null, {
|
|
68
67
|
include_docs: true,
|
|
@@ -83,15 +82,17 @@ function initDeployedApp(prodAppId) {
|
|
|
83
82
|
function deployApp(deployment) {
|
|
84
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
85
84
|
try {
|
|
86
|
-
const
|
|
85
|
+
const appId = getAppId();
|
|
86
|
+
const devAppId = getDevelopmentAppID(appId);
|
|
87
|
+
const productionAppId = getProdAppID(appId);
|
|
87
88
|
const replication = new Replication({
|
|
88
|
-
source:
|
|
89
|
+
source: devAppId,
|
|
89
90
|
target: productionAppId,
|
|
90
91
|
});
|
|
91
92
|
console.log("Replication object created");
|
|
92
93
|
yield replication.replicate();
|
|
93
94
|
console.log("replication complete.. replacing app meta doc");
|
|
94
|
-
const db =
|
|
95
|
+
const db = getProdAppDB();
|
|
95
96
|
const appDoc = yield db.get(DocumentTypes.APP_METADATA);
|
|
96
97
|
appDoc.appId = productionAppId;
|
|
97
98
|
appDoc.instance._id = productionAppId;
|
|
@@ -113,8 +114,7 @@ function deployApp(deployment) {
|
|
|
113
114
|
exports.fetchDeployments = function (ctx) {
|
|
114
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
116
|
try {
|
|
116
|
-
const
|
|
117
|
-
const db = new CouchDB(appId);
|
|
117
|
+
const db = getAppDB();
|
|
118
118
|
const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
|
|
119
119
|
const { updated, deployments } = yield checkAllDeployments(deploymentDoc, ctx.user);
|
|
120
120
|
if (updated) {
|
|
@@ -130,8 +130,7 @@ exports.fetchDeployments = function (ctx) {
|
|
|
130
130
|
exports.deploymentProgress = function (ctx) {
|
|
131
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
132
|
try {
|
|
133
|
-
const
|
|
134
|
-
const db = new CouchDB(appId);
|
|
133
|
+
const db = getAppDB();
|
|
135
134
|
const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
|
|
136
135
|
ctx.body = deploymentDoc[ctx.params.deploymentId];
|
|
137
136
|
}
|
|
@@ -142,7 +141,7 @@ exports.deploymentProgress = function (ctx) {
|
|
|
142
141
|
};
|
|
143
142
|
exports.deployApp = function (ctx) {
|
|
144
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
let deployment = new Deployment(
|
|
144
|
+
let deployment = new Deployment();
|
|
146
145
|
console.log("Deployment object created");
|
|
147
146
|
deployment.setStatus(DeploymentStatus.PENDING);
|
|
148
147
|
console.log("Deployment object set to pending");
|