@budibase/server 1.0.123-alpha.0 → 1.0.123
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/builder/assets/index.68a7f4e3.css +6 -0
- package/builder/assets/index.8d4a5b33.js +1291 -0
- package/builder/assets/{vendor.5240f480.js → vendor.8e34a169.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1763 -758
- package/coverage/coverage-final.json +43 -28
- package/coverage/lcov-report/api/controllers/analytics.js.html +3 -8
- package/coverage/lcov-report/api/controllers/apikeys.js.html +4 -9
- package/coverage/lcov-report/api/controllers/application.js.html +1436 -0
- package/coverage/lcov-report/api/controllers/auth.js.html +3 -8
- package/coverage/lcov-report/api/controllers/automation.js.html +3 -8
- package/coverage/lcov-report/api/controllers/backup.js.html +3 -8
- package/coverage/lcov-report/api/controllers/cloud.js.html +3 -8
- package/coverage/lcov-report/api/controllers/component.js.html +3 -8
- package/coverage/lcov-report/api/controllers/datasource.js.html +6 -11
- package/coverage/lcov-report/api/controllers/dev.js.html +3 -8
- package/coverage/lcov-report/api/controllers/index.html +26 -16
- package/coverage/lcov-report/api/controllers/integration.js.html +3 -8
- package/coverage/lcov-report/api/controllers/layout.js.html +3 -8
- package/coverage/lcov-report/api/controllers/metadata.js.html +3 -8
- package/coverage/lcov-report/api/controllers/migrations.js.html +3 -8
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -8
- package/coverage/lcov-report/api/controllers/query/index.html +26 -16
- package/coverage/lcov-report/api/controllers/query/index.js.html +713 -0
- package/coverage/lcov-report/api/controllers/query/validation.js.html +3 -8
- package/coverage/lcov-report/api/controllers/role.js.html +5 -10
- package/coverage/lcov-report/api/controllers/routing.js.html +4 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +3 -8
- package/coverage/lcov-report/api/controllers/row/index.html +35 -25
- package/coverage/lcov-report/api/controllers/row/index.js.html +524 -0
- package/coverage/lcov-report/api/controllers/row/internal.js.html +24 -32
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +16 -21
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +19 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +19 -33
- package/coverage/lcov-report/api/controllers/screen.js.html +4 -9
- package/coverage/lcov-report/api/controllers/script.js.html +3 -8
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +50 -55
- package/coverage/lcov-report/api/controllers/table/external.js.html +3 -8
- package/coverage/lcov-report/api/controllers/table/index.html +44 -19
- package/coverage/lcov-report/api/controllers/table/index.js.html +15 -20
- package/coverage/lcov-report/api/controllers/table/internal.js.html +620 -0
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1331 -0
- package/coverage/lcov-report/api/controllers/templates.js.html +3 -8
- package/coverage/lcov-report/api/controllers/user.js.html +3 -8
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +3 -8
- package/coverage/lcov-report/api/controllers/view/index.html +3 -8
- package/coverage/lcov-report/api/controllers/view/index.js.html +5 -10
- package/coverage/lcov-report/api/controllers/view/utils.js.html +3 -8
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -8
- package/coverage/lcov-report/api/controllers/webhook.js.html +5 -10
- package/coverage/lcov-report/api/index.html +13 -18
- package/coverage/lcov-report/api/index.js.html +8 -28
- package/coverage/lcov-report/api/routes/analytics.js.html +3 -8
- package/coverage/lcov-report/api/routes/apikeys.js.html +3 -8
- package/coverage/lcov-report/api/routes/application.js.html +179 -0
- package/coverage/lcov-report/api/routes/auth.js.html +3 -8
- package/coverage/lcov-report/api/routes/automation.js.html +3 -8
- package/coverage/lcov-report/api/routes/backup.js.html +3 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +3 -8
- package/coverage/lcov-report/api/routes/component.js.html +3 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +3 -8
- package/coverage/lcov-report/api/routes/deploy.js.html +3 -8
- package/coverage/lcov-report/api/routes/dev.js.html +4 -9
- package/coverage/lcov-report/api/routes/index.html +68 -13
- package/coverage/lcov-report/api/routes/index.js.html +266 -0
- package/coverage/lcov-report/api/routes/integration.js.html +3 -8
- package/coverage/lcov-report/api/routes/layout.js.html +3 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +3 -8
- package/coverage/lcov-report/api/routes/migrations.js.html +3 -8
- package/coverage/lcov-report/api/routes/permission.js.html +3 -8
- package/coverage/lcov-report/api/routes/query.js.html +3 -8
- package/coverage/lcov-report/api/routes/role.js.html +3 -8
- package/coverage/lcov-report/api/routes/routing.js.html +3 -8
- package/coverage/lcov-report/api/routes/row.js.html +908 -0
- package/coverage/lcov-report/api/routes/screen.js.html +3 -8
- package/coverage/lcov-report/api/routes/script.js.html +3 -8
- package/coverage/lcov-report/{automations/steps/loop.js.html → api/routes/static.js.html} +80 -70
- package/coverage/lcov-report/api/routes/table.js.html +3 -8
- package/coverage/lcov-report/api/routes/templates.js.html +3 -8
- package/coverage/lcov-report/api/routes/user.js.html +3 -8
- package/coverage/lcov-report/api/routes/utils/index.html +3 -8
- package/coverage/lcov-report/api/routes/utils/validators.js.html +3 -8
- package/coverage/lcov-report/api/routes/view.js.html +3 -8
- package/coverage/lcov-report/api/routes/webhook.js.html +3 -8
- package/coverage/lcov-report/automations/actions.js.html +7 -21
- package/coverage/lcov-report/automations/automationUtils.js.html +23 -64
- package/coverage/lcov-report/automations/bullboard.js.html +3 -8
- package/coverage/lcov-report/automations/index.html +37 -27
- package/coverage/lcov-report/automations/index.js.html +3 -8
- package/coverage/lcov-report/automations/steps/bash.js.html +3 -8
- package/coverage/lcov-report/automations/steps/createRow.js.html +380 -0
- package/coverage/lcov-report/automations/steps/delay.js.html +3 -8
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +347 -0
- package/coverage/lcov-report/automations/steps/discord.js.html +3 -8
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +3 -8
- package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -8
- package/coverage/lcov-report/automations/steps/filter.js.html +3 -8
- package/coverage/lcov-report/automations/steps/index.html +41 -31
- package/coverage/lcov-report/automations/steps/integromat.js.html +3 -8
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +4 -9
- package/coverage/lcov-report/automations/steps/queryRows.js.html +4 -9
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +3 -8
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -8
- package/coverage/lcov-report/automations/steps/slack.js.html +3 -8
- package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -8
- package/coverage/lcov-report/automations/steps/utils.js.html +9 -14
- package/coverage/lcov-report/automations/steps/zapier.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/index.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +3 -8
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +3 -8
- package/coverage/lcov-report/automations/triggers.js.html +11 -16
- package/coverage/lcov-report/automations/utils.js.html +665 -0
- package/coverage/lcov-report/block-navigation.js +0 -8
- package/coverage/lcov-report/constants/index.html +3 -8
- package/coverage/lcov-report/constants/index.js.html +42 -41
- package/coverage/lcov-report/constants/layouts.js.html +3 -8
- package/coverage/lcov-report/constants/screens.js.html +3 -8
- package/coverage/lcov-report/db/inMemoryView.js.html +3 -8
- package/coverage/lcov-report/db/index.html +3 -8
- package/coverage/lcov-report/db/index.js.html +4 -9
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +23 -25
- package/coverage/lcov-report/db/linkedRows/index.html +12 -17
- package/coverage/lcov-report/db/linkedRows/index.js.html +17 -22
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +7 -12
- package/coverage/lcov-report/db/newid.js.html +6 -11
- package/coverage/lcov-report/db/utils.js.html +79 -84
- package/coverage/lcov-report/events/AutomationEmitter.js.html +9 -14
- package/coverage/lcov-report/events/index.html +3 -8
- package/coverage/lcov-report/events/index.js.html +4 -9
- package/coverage/lcov-report/events/utils.js.html +13 -18
- package/coverage/lcov-report/index.html +132 -137
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +3 -8
- package/coverage/lcov-report/integrations/tests/index.html +3 -8
- package/coverage/lcov-report/middleware/appInfo.js.html +3 -8
- package/coverage/lcov-report/middleware/authorized.js.html +458 -0
- package/coverage/lcov-report/middleware/builder.js.html +3 -8
- package/coverage/lcov-report/middleware/currentapp.js.html +15 -65
- package/coverage/lcov-report/middleware/index.html +50 -25
- package/coverage/lcov-report/middleware/joi-validator.js.html +4 -9
- package/coverage/lcov-report/middleware/publicApi.js.html +3 -8
- package/coverage/lcov-report/middleware/resourceId.js.html +3 -8
- package/coverage/lcov-report/middleware/selfhost.js.html +4 -9
- package/coverage/lcov-report/middleware/usageQuota.js.html +572 -0
- package/coverage/lcov-report/middleware/utils.js.html +3 -8
- package/coverage/lcov-report/sorter.js +0 -26
- package/coverage/lcov-report/threads/automation.js.html +90 -581
- package/coverage/lcov-report/threads/index.html +40 -30
- package/coverage/lcov-report/threads/index.js.html +296 -0
- package/coverage/lcov-report/threads/query.js.html +4 -9
- package/coverage/lcov-report/threads/utils.js.html +9 -17
- package/coverage/lcov-report/utilities/bcrypt.js.html +3 -8
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -8
- package/coverage/lcov-report/utilities/centralPath.js.html +3 -8
- package/coverage/lcov-report/utilities/csvParser.js.html +5 -10
- package/coverage/lcov-report/utilities/global.js.html +4 -9
- package/coverage/lcov-report/utilities/index.html +3 -8
- package/coverage/lcov-report/utilities/index.js.html +6 -11
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -32
- package/coverage/lcov-report/utilities/queue/index.html +7 -12
- package/coverage/lcov-report/utilities/routing/index.html +3 -8
- package/coverage/lcov-report/utilities/routing/index.js.html +3 -8
- package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -32
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +71 -67
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +106 -27
- package/coverage/lcov-report/utilities/scriptRunner.js.html +3 -8
- package/coverage/lcov-report/utilities/security.js.html +4 -9
- package/coverage/lcov-report/utilities/statusCodes.js.html +3 -8
- package/coverage/lcov-report/utilities/usageQuota/index.html +34 -24
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +39 -44
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +3 -8
- package/coverage/lcov-report/utilities/users.js.html +3 -8
- package/coverage/lcov-report/utilities/workerRequests.js.html +4 -9
- package/coverage/lcov.info +3061 -1290
- package/dist/api/controllers/application.js +73 -145
- package/dist/api/controllers/deploy/index.js +36 -68
- package/dist/api/controllers/public/applications.js +9 -29
- package/dist/api/controllers/public/queries.js +7 -27
- package/dist/api/controllers/public/rows.js +12 -32
- package/dist/api/controllers/public/tables.js +2 -2
- package/dist/api/controllers/public/users.js +8 -8
- package/dist/api/controllers/public/utils.js +1 -1
- package/dist/api/controllers/query/import/index.js +3 -3
- package/dist/api/controllers/query/index.js +44 -57
- package/dist/api/controllers/row/ExternalRequest.js +27 -27
- package/dist/api/controllers/row/index.js +60 -83
- package/dist/api/controllers/row/internal.js +1 -2
- package/dist/api/controllers/row/utils.js +1 -2
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -3
- package/dist/api/controllers/table/bulkFormula.js +1 -2
- package/dist/api/controllers/table/internal.js +55 -40
- package/dist/api/controllers/table/utils.js +229 -271
- package/dist/api/index.js +0 -5
- package/dist/api/routes/application.js +13 -39
- package/dist/api/routes/index.js +56 -61
- package/dist/api/routes/public/index.js +9 -6
- package/dist/api/routes/public/queries.js +1 -1
- package/dist/api/routes/public/rows.js +1 -1
- package/dist/api/routes/public/tables.js +3 -3
- package/dist/api/routes/public/users.js +1 -1
- package/dist/api/routes/row.js +17 -43
- package/dist/api/routes/static.js +13 -40
- package/dist/api/routes/tests/utilities/TestFunctions.js +33 -75
- package/dist/app.js +4 -8
- package/dist/automations/actions.js +0 -3
- package/dist/automations/automationUtils.js +0 -10
- package/dist/automations/steps/createRow.js +12 -12
- package/dist/automations/steps/deleteRow.js +16 -13
- package/dist/automations/tests/utilities/index.js +11 -13
- package/dist/automations/utils.js +133 -187
- package/dist/constants/index.js +7 -5
- package/dist/db/linkedRows/LinkController.js +1 -0
- package/dist/definitions/datasource.js +0 -1
- package/dist/environment.js +3 -2
- package/dist/index.js +0 -4
- package/dist/integrations/base/sql.js +2 -2
- package/dist/integrations/base/sqlTable.js +2 -2
- package/dist/integrations/googlesheets.js +1 -1
- package/dist/integrations/index.js +0 -4
- package/dist/integrations/microsoftSqlServer.js +8 -8
- package/dist/integrations/mysql.js +9 -9
- package/dist/integrations/oracle.js +7 -7
- package/dist/integrations/postgres.js +7 -7
- package/dist/integrations/queries/sql.js +2 -2
- package/dist/integrations/rest.js +1 -1
- package/dist/middleware/authorized.js +51 -51
- package/dist/middleware/currentapp.js +1 -15
- package/dist/middleware/usageQuota.js +154 -0
- package/dist/migrations/functions/appUrls.js +1 -1
- package/dist/migrations/functions/quotas1.js +2 -6
- package/dist/migrations/functions/usageQuotas/index.js +4 -0
- package/dist/migrations/functions/usageQuotas/syncApps.js +7 -4
- package/dist/migrations/functions/usageQuotas/syncRows.js +8 -5
- package/dist/migrations/index.js +1 -17
- package/dist/package.json +4 -10
- package/dist/threads/automation.js +27 -149
- package/dist/threads/index.js +10 -36
- package/dist/threads/utils.js +0 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +1 -6
- package/dist/utilities/rowProcessor/index.js +11 -6
- package/dist/utilities/rowProcessor/utils.js +27 -1
- package/dist/utilities/usageQuota/index.js +86 -0
- package/nodemon.json +1 -1
- package/package.json +9 -15
- package/scripts/dev/manage.js +0 -2
- package/src/api/controllers/{application.ts → application.js} +51 -118
- package/src/api/controllers/deploy/{index.ts → index.js} +29 -53
- package/src/api/controllers/public/applications.ts +2 -2
- package/src/api/controllers/public/queries.ts +1 -1
- package/src/api/controllers/public/rows.ts +1 -1
- package/src/api/controllers/query/{index.ts → index.js} +48 -51
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/{index.ts → index.js} +17 -24
- package/src/api/controllers/row/internal.js +1 -2
- package/src/api/controllers/row/utils.js +1 -4
- package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -3
- package/src/api/controllers/table/bulkFormula.js +1 -1
- package/src/api/controllers/table/{internal.ts → internal.js} +48 -27
- package/src/api/controllers/table/{utils.ts → utils.js} +69 -86
- package/src/api/index.js +0 -5
- package/src/api/routes/{application.ts → application.js} +14 -8
- package/src/api/routes/index.js +62 -0
- package/src/api/routes/public/index.ts +4 -1
- package/src/api/routes/{row.ts → row.js} +15 -7
- package/src/api/routes/{static.ts → static.js} +11 -11
- package/src/api/routes/tests/misc.spec.js +37 -39
- package/src/api/routes/tests/routing.spec.js +0 -1
- package/src/api/routes/tests/utilities/{TestFunctions.ts → TestFunctions.js} +33 -57
- package/src/app.ts +2 -1
- package/src/automations/actions.js +0 -3
- package/src/automations/automationUtils.js +0 -12
- package/src/automations/steps/{createRow.ts → createRow.js} +15 -9
- package/src/automations/steps/{deleteRow.ts → deleteRow.js} +16 -10
- package/src/automations/tests/automation.spec.js +1 -0
- package/src/automations/tests/{createRow.spec.ts → createRow.spec.js} +15 -4
- package/src/automations/tests/{deleteRow.spec.ts → deleteRow.spec.js} +5 -3
- package/src/automations/tests/utilities/index.js +10 -12
- package/src/automations/{utils.ts → utils.js} +28 -39
- package/src/constants/index.js +8 -6
- package/src/db/linkedRows/LinkController.js +1 -0
- package/src/definitions/datasource.ts +0 -1
- package/src/environment.js +3 -2
- package/src/index.ts +0 -3
- package/src/integrations/index.ts +0 -4
- package/src/middleware/{authorized.ts → authorized.js} +14 -20
- package/src/middleware/currentapp.js +1 -16
- package/src/middleware/tests/usageQuota.spec.js +120 -0
- package/src/middleware/usageQuota.js +164 -0
- package/src/migrations/functions/tests/quotas1.spec.js +2 -0
- package/src/migrations/functions/usageQuotas/index.ts +5 -0
- package/src/migrations/functions/usageQuotas/syncApps.ts +6 -3
- package/src/migrations/functions/usageQuotas/syncRows.ts +6 -3
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +41 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +45 -0
- package/src/migrations/index.ts +1 -13
- package/src/threads/automation.js +34 -196
- package/src/threads/{index.ts → index.js} +14 -18
- package/src/threads/utils.js +0 -1
- package/src/utilities/queue/inMemoryQueue.js +1 -7
- package/src/utilities/rowProcessor/index.js +12 -9
- package/src/utilities/rowProcessor/utils.js +29 -1
- package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
- package/src/utilities/usageQuota/index.js +93 -0
- package/tsconfig.json +2 -2
- package/builder/assets/index.89795487.css +0 -6
- package/builder/assets/index.be9a1b80.js +0 -1299
- package/dist/automations/steps/loop.js +0 -51
- package/dist/integrations/redis.js +0 -158
- package/dist/migrations/functions/developerQuota.js +0 -49
- package/dist/migrations/functions/publishedAppsQuota.js +0 -47
- package/dist/migrations/functions/usageQuotas/syncDevelopers.js +0 -24
- package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +0 -26
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/src/api/routes/index.ts +0 -60
- package/src/automations/steps/loop.js +0 -50
- package/src/integrations/redis.ts +0 -152
- package/src/integrations/tests/redis.spec.js +0 -60
- package/src/migrations/functions/developerQuota.ts +0 -15
- package/src/migrations/functions/publishedAppsQuota.ts +0 -13
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +0 -34
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +0 -40
- package/tsconfig.build.json +0 -10
|
@@ -8,50 +8,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const environment_1 = __importDefault(require("../../environment"));
|
|
17
|
-
const package_json_1 = __importDefault(require("../../../package.json"));
|
|
18
|
-
const staticViews_1 = require("../../db/views/staticViews");
|
|
19
|
-
const fileSystem_1 = require("../../utilities/fileSystem");
|
|
20
|
-
const utils_1 = require("../../db/utils");
|
|
11
|
+
const env = require("../../environment");
|
|
12
|
+
const packageJson = require("../../../package.json");
|
|
13
|
+
const { createLinkView, createRoutingView, createAllSearchIndex, } = require("../../db/views/staticViews");
|
|
14
|
+
const { getTemplateStream, createApp, deleteApp, } = require("../../utilities/fileSystem");
|
|
15
|
+
const { generateAppID, getLayoutParams, getScreenParams, generateDevAppID, DocumentTypes, AppStatus, } = require("../../db/utils");
|
|
21
16
|
const { BUILTIN_ROLE_IDS, AccessController, } = require("@budibase/backend-core/roles");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
17
|
+
const { BASE_LAYOUTS } = require("../../constants/layouts");
|
|
18
|
+
const { cloneDeep } = require("lodash/fp");
|
|
24
19
|
const { processObject } = require("@budibase/string-templates");
|
|
25
20
|
const { getAllApps, isDevAppID, getProdAppID, Replication, } = require("@budibase/backend-core/db");
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const
|
|
21
|
+
const { USERS_TABLE_SCHEMA } = require("../../constants");
|
|
22
|
+
const { removeAppFromUserRoles } = require("../../utilities/workerRequests");
|
|
23
|
+
const { clientLibraryPath, stringToReadStream } = require("../../utilities");
|
|
24
|
+
const { getAllLocks } = require("../../utilities/redis");
|
|
25
|
+
const { updateClientLibrary, backupClientLibrary, revertClientLibrary, } = require("../../utilities/fileSystem/clientLibrary");
|
|
31
26
|
const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy");
|
|
32
|
-
const
|
|
27
|
+
const { syncGlobalUsers } = require("./user");
|
|
33
28
|
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
34
|
-
const
|
|
29
|
+
const { cleanupAutomations } = require("../../automations/utils");
|
|
35
30
|
const { getAppDB, getProdAppDB, updateAppId, } = require("@budibase/backend-core/context");
|
|
36
|
-
const rows_1 = require("../../utilities/usageQuota/rows");
|
|
37
|
-
const pro_1 = require("@budibase/pro");
|
|
38
|
-
const backend_core_1 = require("@budibase/backend-core");
|
|
39
31
|
const URL_REGEX_SLASH = /\/|\\/g;
|
|
40
32
|
// utility function, need to do away with this
|
|
41
33
|
function getLayouts() {
|
|
42
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
35
|
const db = getAppDB();
|
|
44
|
-
return (yield db.allDocs(
|
|
36
|
+
return (yield db.allDocs(getLayoutParams(null, {
|
|
45
37
|
include_docs: true,
|
|
46
|
-
}))).rows.map(
|
|
38
|
+
}))).rows.map(row => row.doc);
|
|
47
39
|
});
|
|
48
40
|
}
|
|
49
41
|
function getScreens() {
|
|
50
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
43
|
const db = getAppDB();
|
|
52
|
-
return (yield db.allDocs(
|
|
44
|
+
return (yield db.allDocs(getScreenParams(null, {
|
|
53
45
|
include_docs: true,
|
|
54
|
-
}))).rows.map(
|
|
46
|
+
}))).rows.map(row => row.doc);
|
|
55
47
|
});
|
|
56
48
|
}
|
|
57
49
|
function getUserRoleId(ctx) {
|
|
@@ -59,7 +51,7 @@ function getUserRoleId(ctx) {
|
|
|
59
51
|
? BUILTIN_ROLE_IDS.PUBLIC
|
|
60
52
|
: ctx.user.role._id;
|
|
61
53
|
}
|
|
62
|
-
|
|
54
|
+
exports.getAppUrl = ctx => {
|
|
63
55
|
// construct the url
|
|
64
56
|
let url;
|
|
65
57
|
if (ctx.request.body.url) {
|
|
@@ -75,12 +67,11 @@ const getAppUrl = (ctx) => {
|
|
|
75
67
|
}
|
|
76
68
|
return url;
|
|
77
69
|
};
|
|
78
|
-
exports.getAppUrl = getAppUrl;
|
|
79
70
|
const checkAppUrl = (ctx, apps, url, currentAppId) => {
|
|
80
71
|
if (currentAppId) {
|
|
81
|
-
apps = apps.filter(
|
|
72
|
+
apps = apps.filter(app => app.appId !== currentAppId);
|
|
82
73
|
}
|
|
83
|
-
if (apps.some(
|
|
74
|
+
if (apps.some(app => app.url === url)) {
|
|
84
75
|
ctx.throw(400, "App URL is already in use.");
|
|
85
76
|
}
|
|
86
77
|
};
|
|
@@ -90,17 +81,17 @@ const checkAppName = (ctx, apps, name, currentAppId) => {
|
|
|
90
81
|
ctx.throw(400, "Name is required");
|
|
91
82
|
}
|
|
92
83
|
if (currentAppId) {
|
|
93
|
-
apps = apps.filter(
|
|
84
|
+
apps = apps.filter(app => app.appId !== currentAppId);
|
|
94
85
|
}
|
|
95
|
-
if (apps.some(
|
|
86
|
+
if (apps.some(app => app.name === name)) {
|
|
96
87
|
ctx.throw(400, "App name is already in use.");
|
|
97
88
|
}
|
|
98
89
|
};
|
|
99
90
|
function createInstance(template) {
|
|
100
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
92
|
const tenantId = isMultiTenant() ? getTenantId() : null;
|
|
102
|
-
const baseAppId =
|
|
103
|
-
const appId =
|
|
93
|
+
const baseAppId = generateAppID(tenantId);
|
|
94
|
+
const appId = generateDevAppID(baseAppId);
|
|
104
95
|
yield updateAppId(appId);
|
|
105
96
|
const db = getAppDB();
|
|
106
97
|
yield db.put({
|
|
@@ -111,43 +102,43 @@ function createInstance(template) {
|
|
|
111
102
|
});
|
|
112
103
|
// NOTE: indexes need to be created before any tables/templates
|
|
113
104
|
// add view for linked rows
|
|
114
|
-
yield
|
|
115
|
-
yield
|
|
116
|
-
yield
|
|
105
|
+
yield createLinkView();
|
|
106
|
+
yield createRoutingView();
|
|
107
|
+
yield createAllSearchIndex();
|
|
117
108
|
// replicate the template data to the instance DB
|
|
118
109
|
// this is currently very hard to test, downloading and importing template files
|
|
119
110
|
if (template && template.templateString) {
|
|
120
|
-
const { ok } = yield db.load(
|
|
111
|
+
const { ok } = yield db.load(stringToReadStream(template.templateString));
|
|
121
112
|
if (!ok) {
|
|
122
113
|
throw "Error loading database dump from memory.";
|
|
123
114
|
}
|
|
124
115
|
}
|
|
125
116
|
else if (template && template.useTemplate === "true") {
|
|
126
117
|
/* istanbul ignore next */
|
|
127
|
-
const { ok } = yield db.load(yield
|
|
118
|
+
const { ok } = yield db.load(yield getTemplateStream(template));
|
|
128
119
|
if (!ok) {
|
|
129
120
|
throw "Error loading database dump from template.";
|
|
130
121
|
}
|
|
131
122
|
}
|
|
132
123
|
else {
|
|
133
124
|
// create the users table
|
|
134
|
-
yield db.put(
|
|
125
|
+
yield db.put(USERS_TABLE_SCHEMA);
|
|
135
126
|
}
|
|
136
127
|
return { _id: appId };
|
|
137
128
|
});
|
|
138
129
|
}
|
|
139
|
-
|
|
140
|
-
const dev = ctx.query && ctx.query.status ===
|
|
141
|
-
const all = ctx.query && ctx.query.status ===
|
|
130
|
+
exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
+
const dev = ctx.query && ctx.query.status === AppStatus.DEV;
|
|
132
|
+
const all = ctx.query && ctx.query.status === AppStatus.ALL;
|
|
142
133
|
const apps = yield getAllApps({ dev, all });
|
|
143
134
|
// get the locks for all the dev apps
|
|
144
135
|
if (dev || all) {
|
|
145
|
-
const locks = yield
|
|
136
|
+
const locks = yield getAllLocks();
|
|
146
137
|
for (let app of apps) {
|
|
147
138
|
if (app.status !== "development") {
|
|
148
139
|
continue;
|
|
149
140
|
}
|
|
150
|
-
const lock = locks.find(
|
|
141
|
+
const lock = locks.find(lock => lock.appId === app.appId);
|
|
151
142
|
if (lock) {
|
|
152
143
|
app.lockedBy = lock.user;
|
|
153
144
|
}
|
|
@@ -159,8 +150,7 @@ const fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
159
150
|
}
|
|
160
151
|
ctx.body = apps;
|
|
161
152
|
});
|
|
162
|
-
exports.
|
|
163
|
-
const fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
+
exports.fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
154
|
const layouts = yield getLayouts();
|
|
165
155
|
const userRoleId = getUserRoleId(ctx);
|
|
166
156
|
const accessController = new AccessController();
|
|
@@ -171,10 +161,9 @@ const fetchAppDefinition = (ctx) => __awaiter(void 0, void 0, void 0, function*
|
|
|
171
161
|
libraries: ["@budibase/standard-components"],
|
|
172
162
|
};
|
|
173
163
|
});
|
|
174
|
-
exports.
|
|
175
|
-
const fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
exports.fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
176
165
|
const db = getAppDB();
|
|
177
|
-
const application = yield db.get(
|
|
166
|
+
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
178
167
|
const layouts = yield getLayouts();
|
|
179
168
|
let screens = yield getScreens();
|
|
180
169
|
// Only filter screens if the user is not a builder
|
|
@@ -187,11 +176,10 @@ const fetchAppPackage = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
187
176
|
application,
|
|
188
177
|
screens,
|
|
189
178
|
layouts,
|
|
190
|
-
clientLibPath:
|
|
179
|
+
clientLibPath: clientLibraryPath(ctx.params.appId, application.version),
|
|
191
180
|
};
|
|
192
181
|
});
|
|
193
|
-
exports.
|
|
194
|
-
const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
|
+
exports.create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
195
183
|
const apps = yield getAllApps({ dev: true });
|
|
196
184
|
const name = ctx.request.body.name;
|
|
197
185
|
checkAppName(ctx, apps, name);
|
|
@@ -212,18 +200,18 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
212
200
|
let _rev;
|
|
213
201
|
try {
|
|
214
202
|
// if template there will be an existing doc
|
|
215
|
-
const existing = yield db.get(
|
|
203
|
+
const existing = yield db.get(DocumentTypes.APP_METADATA);
|
|
216
204
|
_rev = existing._rev;
|
|
217
205
|
}
|
|
218
206
|
catch (err) {
|
|
219
207
|
// nothing to do
|
|
220
208
|
}
|
|
221
209
|
const newApplication = {
|
|
222
|
-
_id:
|
|
210
|
+
_id: DocumentTypes.APP_METADATA,
|
|
223
211
|
_rev,
|
|
224
212
|
appId: instance._id,
|
|
225
213
|
type: "app",
|
|
226
|
-
version:
|
|
214
|
+
version: packageJson.version,
|
|
227
215
|
componentLibraries: ["@budibase/standard-components"],
|
|
228
216
|
name: name,
|
|
229
217
|
url: url,
|
|
@@ -232,7 +220,7 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
232
220
|
tenantId: getTenantId(),
|
|
233
221
|
updatedAt: new Date().toISOString(),
|
|
234
222
|
createdAt: new Date().toISOString(),
|
|
235
|
-
status:
|
|
223
|
+
status: AppStatus.DEV,
|
|
236
224
|
};
|
|
237
225
|
const response = yield db.put(newApplication, { force: true });
|
|
238
226
|
newApplication._rev = response.rev;
|
|
@@ -242,44 +230,16 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
242
230
|
yield createEmptyAppPackage(ctx, newApplication);
|
|
243
231
|
}
|
|
244
232
|
/* istanbul ignore next */
|
|
245
|
-
if (!
|
|
246
|
-
yield
|
|
233
|
+
if (!env.isTest()) {
|
|
234
|
+
yield createApp(appId);
|
|
247
235
|
}
|
|
248
236
|
yield appCache.invalidateAppMetadata(appId, newApplication);
|
|
249
|
-
return newApplication;
|
|
250
|
-
});
|
|
251
|
-
const appPostCreate = (ctx, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
252
|
-
// app import & template creation
|
|
253
|
-
if (ctx.request.body.useTemplate === "true") {
|
|
254
|
-
const rows = yield (0, rows_1.getUniqueRows)([appId]);
|
|
255
|
-
const rowCount = rows ? rows.length : 0;
|
|
256
|
-
if (rowCount) {
|
|
257
|
-
try {
|
|
258
|
-
yield pro_1.quotas.addRows(rowCount);
|
|
259
|
-
}
|
|
260
|
-
catch (err) {
|
|
261
|
-
if (err.code && err.code === backend_core_1.errors.codes.USAGE_LIMIT_EXCEEDED) {
|
|
262
|
-
// this import resulted in row usage exceeding the quota
|
|
263
|
-
// delete the app
|
|
264
|
-
// skip pre and post steps as no rows have been added to quotas yet
|
|
265
|
-
ctx.params.appId = appId;
|
|
266
|
-
yield destroyApp(ctx);
|
|
267
|
-
}
|
|
268
|
-
throw err;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
const create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
274
|
-
const newApplication = yield pro_1.quotas.addApp(() => performAppCreate(ctx));
|
|
275
|
-
yield appPostCreate(ctx, newApplication.appId);
|
|
276
|
-
ctx.body = newApplication;
|
|
277
237
|
ctx.status = 200;
|
|
238
|
+
ctx.body = newApplication;
|
|
278
239
|
});
|
|
279
|
-
exports.create = create;
|
|
280
240
|
// This endpoint currently operates as a PATCH rather than a PUT
|
|
281
241
|
// Thus name and url fields are handled only if present
|
|
282
|
-
|
|
242
|
+
exports.update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
283
243
|
const apps = yield getAllApps({ dev: true });
|
|
284
244
|
// validation
|
|
285
245
|
const name = ctx.request.body.name;
|
|
@@ -295,37 +255,35 @@ const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
295
255
|
ctx.status = 200;
|
|
296
256
|
ctx.body = data;
|
|
297
257
|
});
|
|
298
|
-
exports.
|
|
299
|
-
const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
258
|
+
exports.updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
300
259
|
// Get current app version
|
|
301
260
|
const db = getAppDB();
|
|
302
|
-
const application = yield db.get(
|
|
261
|
+
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
303
262
|
const currentVersion = application.version;
|
|
304
263
|
// Update client library and manifest
|
|
305
|
-
if (!
|
|
306
|
-
yield
|
|
307
|
-
yield
|
|
264
|
+
if (!env.isTest()) {
|
|
265
|
+
yield backupClientLibrary(ctx.params.appId);
|
|
266
|
+
yield updateClientLibrary(ctx.params.appId);
|
|
308
267
|
}
|
|
309
268
|
// Update versions in app package
|
|
310
269
|
const appPackageUpdates = {
|
|
311
|
-
version:
|
|
270
|
+
version: packageJson.version,
|
|
312
271
|
revertableVersion: currentVersion,
|
|
313
272
|
};
|
|
314
273
|
const data = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
315
274
|
ctx.status = 200;
|
|
316
275
|
ctx.body = data;
|
|
317
276
|
});
|
|
318
|
-
exports.
|
|
319
|
-
const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
|
+
exports.revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
320
278
|
// Check app can be reverted
|
|
321
279
|
const db = getAppDB();
|
|
322
|
-
const application = yield db.get(
|
|
280
|
+
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
323
281
|
if (!application.revertableVersion) {
|
|
324
282
|
ctx.throw(400, "There is no version to revert to");
|
|
325
283
|
}
|
|
326
284
|
// Update client library and manifest
|
|
327
|
-
if (!
|
|
328
|
-
yield
|
|
285
|
+
if (!env.isTest()) {
|
|
286
|
+
yield revertClientLibrary(ctx.params.appId);
|
|
329
287
|
}
|
|
330
288
|
// Update versions in app package
|
|
331
289
|
const appPackageUpdates = {
|
|
@@ -336,52 +294,23 @@ const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
336
294
|
ctx.status = 200;
|
|
337
295
|
ctx.body = data;
|
|
338
296
|
});
|
|
339
|
-
exports.
|
|
340
|
-
const
|
|
341
|
-
let appId = ctx.params.appId;
|
|
342
|
-
let isUnpublish = ctx.query && ctx.query.unpublish;
|
|
343
|
-
if (isUnpublish) {
|
|
344
|
-
appId = getProdAppID(appId);
|
|
345
|
-
}
|
|
346
|
-
const db = isUnpublish ? getProdAppDB() : getAppDB();
|
|
297
|
+
exports.delete = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
298
|
+
const db = getAppDB();
|
|
347
299
|
const result = yield db.destroy();
|
|
348
|
-
if (isUnpublish) {
|
|
349
|
-
yield pro_1.quotas.removePublishedApp();
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
yield pro_1.quotas.removeApp();
|
|
353
|
-
}
|
|
354
300
|
/* istanbul ignore next */
|
|
355
|
-
if (!
|
|
356
|
-
yield (
|
|
301
|
+
if (!env.isTest() && !ctx.query.unpublish) {
|
|
302
|
+
yield deleteApp(ctx.params.appId);
|
|
357
303
|
}
|
|
358
|
-
if (
|
|
359
|
-
yield (
|
|
304
|
+
if (ctx.query && ctx.query.unpublish) {
|
|
305
|
+
yield cleanupAutomations(ctx.params.appId);
|
|
360
306
|
}
|
|
361
307
|
// make sure the app/role doesn't stick around after the app has been deleted
|
|
362
|
-
yield
|
|
363
|
-
yield appCache.invalidateAppMetadata(appId);
|
|
364
|
-
return result;
|
|
365
|
-
});
|
|
366
|
-
const preDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
367
|
-
const rows = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
|
|
368
|
-
ctx.rowCount = rows.length;
|
|
369
|
-
});
|
|
370
|
-
const postDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
371
|
-
const rowCount = ctx.rowCount;
|
|
372
|
-
if (rowCount) {
|
|
373
|
-
yield pro_1.quotas.removeRows(rowCount);
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
const destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
377
|
-
yield preDestroyApp(ctx);
|
|
378
|
-
const result = yield destroyApp(ctx);
|
|
379
|
-
yield postDestroyApp(ctx);
|
|
308
|
+
yield removeAppFromUserRoles(ctx, ctx.params.appId);
|
|
309
|
+
yield appCache.invalidateAppMetadata(ctx.params.appId);
|
|
380
310
|
ctx.status = 200;
|
|
381
311
|
ctx.body = result;
|
|
382
312
|
});
|
|
383
|
-
exports.
|
|
384
|
-
const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
313
|
+
exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
385
314
|
const appId = ctx.params.appId;
|
|
386
315
|
if (!isDevAppID(appId)) {
|
|
387
316
|
ctx.throw(400, "This action cannot be performed for production apps");
|
|
@@ -411,7 +340,7 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
411
340
|
try {
|
|
412
341
|
yield replication.replicate({
|
|
413
342
|
filter: function (doc) {
|
|
414
|
-
return doc._id !==
|
|
343
|
+
return doc._id !== DocumentTypes.APP_METADATA;
|
|
415
344
|
},
|
|
416
345
|
});
|
|
417
346
|
}
|
|
@@ -422,7 +351,7 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
422
351
|
yield replication.close();
|
|
423
352
|
}
|
|
424
353
|
// sync the users
|
|
425
|
-
yield
|
|
354
|
+
yield syncGlobalUsers();
|
|
426
355
|
if (error) {
|
|
427
356
|
ctx.throw(400, error);
|
|
428
357
|
}
|
|
@@ -432,10 +361,9 @@ const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
432
361
|
};
|
|
433
362
|
}
|
|
434
363
|
});
|
|
435
|
-
exports.sync = sync;
|
|
436
364
|
const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
437
365
|
const db = getAppDB();
|
|
438
|
-
const application = yield db.get(
|
|
366
|
+
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
439
367
|
const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
|
|
440
368
|
if (appPackage._rev !== application._rev) {
|
|
441
369
|
newAppPackage._rev = application._rev;
|
|
@@ -451,8 +379,8 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
|
|
|
451
379
|
const createEmptyAppPackage = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
|
|
452
380
|
const db = getAppDB();
|
|
453
381
|
let screensAndLayouts = [];
|
|
454
|
-
for (let layout of
|
|
455
|
-
const cloned =
|
|
382
|
+
for (let layout of BASE_LAYOUTS) {
|
|
383
|
+
const cloned = cloneDeep(layout);
|
|
456
384
|
screensAndLayouts.push(yield processObject(cloned, app));
|
|
457
385
|
}
|
|
458
386
|
yield db.bulkDocs(screensAndLayouts);
|
|
@@ -8,18 +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
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const db_1 = require("@budibase/backend-core/db");
|
|
18
|
-
const utils_1 = require("../../../db/utils");
|
|
19
|
-
const utils_2 = require("../../../automations/utils");
|
|
20
|
-
const cache_1 = require("@budibase/backend-core/cache");
|
|
21
|
-
const context_1 = require("@budibase/backend-core/context");
|
|
22
|
-
const pro_1 = require("@budibase/pro");
|
|
11
|
+
const Deployment = require("./Deployment");
|
|
12
|
+
const { Replication, getProdAppID, getDevelopmentAppID, } = require("@budibase/backend-core/db");
|
|
13
|
+
const { DocumentTypes, getAutomationParams } = require("../../../db/utils");
|
|
14
|
+
const { disableAllCrons, enableCronTrigger, } = require("../../../automations/utils");
|
|
15
|
+
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
16
|
+
const { getAppId, getAppDB, getProdAppDB, } = require("@budibase/backend-core/context");
|
|
23
17
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
24
18
|
const MAX_PENDING_TIME_MS = 30 * 60000;
|
|
25
19
|
const DeploymentStatus = {
|
|
@@ -31,8 +25,7 @@ const DeploymentStatus = {
|
|
|
31
25
|
function checkAllDeployments(deployments) {
|
|
32
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
27
|
let updated = false;
|
|
34
|
-
let deployment
|
|
35
|
-
for (deployment of Object.values(deployments.history)) {
|
|
28
|
+
for (let deployment of Object.values(deployments.history)) {
|
|
36
29
|
// check that no deployments have crashed etc and are now stuck
|
|
37
30
|
if (deployment.status === DeploymentStatus.PENDING &&
|
|
38
31
|
Date.now() - deployment.updatedAt > MAX_PENDING_TIME_MS) {
|
|
@@ -47,14 +40,14 @@ function checkAllDeployments(deployments) {
|
|
|
47
40
|
function storeDeploymentHistory(deployment) {
|
|
48
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
42
|
const deploymentJSON = deployment.getJSON();
|
|
50
|
-
const db =
|
|
43
|
+
const db = getAppDB();
|
|
51
44
|
let deploymentDoc;
|
|
52
45
|
try {
|
|
53
46
|
// theres only one deployment doc per app database
|
|
54
|
-
deploymentDoc = yield db.get(
|
|
47
|
+
deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
|
|
55
48
|
}
|
|
56
49
|
catch (err) {
|
|
57
|
-
deploymentDoc = { _id:
|
|
50
|
+
deploymentDoc = { _id: DocumentTypes.DEPLOYMENTS, history: {} };
|
|
58
51
|
}
|
|
59
52
|
const deploymentId = deploymentJSON._id;
|
|
60
53
|
// first time deployment
|
|
@@ -68,19 +61,19 @@ function storeDeploymentHistory(deployment) {
|
|
|
68
61
|
}
|
|
69
62
|
function initDeployedApp(prodAppId) {
|
|
70
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const db =
|
|
64
|
+
const db = getProdAppDB();
|
|
72
65
|
console.log("Reading automation docs");
|
|
73
|
-
const automations = (yield db.allDocs(
|
|
66
|
+
const automations = (yield db.allDocs(getAutomationParams(null, {
|
|
74
67
|
include_docs: true,
|
|
75
|
-
}))).rows.map(
|
|
68
|
+
}))).rows.map(row => row.doc);
|
|
76
69
|
console.log("You have " + automations.length + " automations");
|
|
77
70
|
const promises = [];
|
|
78
71
|
console.log("Disabling prod crons..");
|
|
79
|
-
yield
|
|
72
|
+
yield disableAllCrons(prodAppId);
|
|
80
73
|
console.log("Prod Cron triggers disabled..");
|
|
81
74
|
console.log("Enabling cron triggers for deployed app..");
|
|
82
75
|
for (let automation of automations) {
|
|
83
|
-
promises.push(
|
|
76
|
+
promises.push(enableCronTrigger(prodAppId, automation));
|
|
84
77
|
}
|
|
85
78
|
yield Promise.all(promises);
|
|
86
79
|
console.log("Enabled cron triggers for deployed app..");
|
|
@@ -90,24 +83,22 @@ function deployApp(deployment) {
|
|
|
90
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
84
|
let replication;
|
|
92
85
|
try {
|
|
93
|
-
const appId =
|
|
94
|
-
const devAppId =
|
|
95
|
-
const productionAppId =
|
|
96
|
-
|
|
86
|
+
const appId = getAppId();
|
|
87
|
+
const devAppId = getDevelopmentAppID(appId);
|
|
88
|
+
const productionAppId = getProdAppID(appId);
|
|
89
|
+
replication = new Replication({
|
|
97
90
|
source: devAppId,
|
|
98
91
|
target: productionAppId,
|
|
99
|
-
};
|
|
100
|
-
replication = new db_1.Replication(config);
|
|
92
|
+
});
|
|
101
93
|
console.log("Replication object created");
|
|
102
94
|
yield replication.replicate();
|
|
103
95
|
console.log("replication complete.. replacing app meta doc");
|
|
104
|
-
const db =
|
|
105
|
-
const appDoc = yield db.get(
|
|
106
|
-
deployment.appUrl = appDoc.url;
|
|
96
|
+
const db = getProdAppDB();
|
|
97
|
+
const appDoc = yield db.get(DocumentTypes.APP_METADATA);
|
|
107
98
|
appDoc.appId = productionAppId;
|
|
108
99
|
appDoc.instance._id = productionAppId;
|
|
109
100
|
yield db.put(appDoc);
|
|
110
|
-
yield
|
|
101
|
+
yield appCache.invalidateAppMetadata(productionAppId);
|
|
111
102
|
console.log("New app doc written successfully.");
|
|
112
103
|
yield initDeployedApp(productionAppId);
|
|
113
104
|
console.log("Deployed app initialised, setting deployment to successful");
|
|
@@ -120,18 +111,16 @@ function deployApp(deployment) {
|
|
|
120
111
|
throw Object.assign(Object.assign({}, err), { message: `Deployment Failed: ${err.message}` });
|
|
121
112
|
}
|
|
122
113
|
finally {
|
|
123
|
-
|
|
124
|
-
yield replication.close();
|
|
125
|
-
}
|
|
114
|
+
yield replication.close();
|
|
126
115
|
}
|
|
127
116
|
});
|
|
128
117
|
}
|
|
129
|
-
function
|
|
118
|
+
exports.fetchDeployments = function (ctx) {
|
|
130
119
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
120
|
try {
|
|
132
|
-
const db =
|
|
133
|
-
const deploymentDoc = yield db.get(
|
|
134
|
-
const { updated, deployments } = yield checkAllDeployments(deploymentDoc);
|
|
121
|
+
const db = getAppDB();
|
|
122
|
+
const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
|
|
123
|
+
const { updated, deployments } = yield checkAllDeployments(deploymentDoc, ctx.user);
|
|
135
124
|
if (updated) {
|
|
136
125
|
yield db.put(deployments);
|
|
137
126
|
}
|
|
@@ -141,50 +130,29 @@ function fetchDeployments(ctx) {
|
|
|
141
130
|
ctx.body = [];
|
|
142
131
|
}
|
|
143
132
|
});
|
|
144
|
-
}
|
|
145
|
-
exports.
|
|
146
|
-
function deploymentProgress(ctx) {
|
|
133
|
+
};
|
|
134
|
+
exports.deploymentProgress = function (ctx) {
|
|
147
135
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
136
|
try {
|
|
149
|
-
const db =
|
|
150
|
-
const deploymentDoc = yield db.get(
|
|
137
|
+
const db = getAppDB();
|
|
138
|
+
const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
|
|
151
139
|
ctx.body = deploymentDoc[ctx.params.deploymentId];
|
|
152
140
|
}
|
|
153
141
|
catch (err) {
|
|
154
142
|
ctx.throw(500, `Error fetching data for deployment ${ctx.params.deploymentId}`);
|
|
155
143
|
}
|
|
156
144
|
});
|
|
157
|
-
}
|
|
158
|
-
exports.
|
|
159
|
-
const isFirstDeploy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
-
try {
|
|
161
|
-
const db = (0, context_1.getProdAppDB)();
|
|
162
|
-
yield db.get(utils_1.DocumentTypes.APP_METADATA);
|
|
163
|
-
}
|
|
164
|
-
catch (e) {
|
|
165
|
-
if (e.status === 404) {
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
throw e;
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
171
|
-
});
|
|
172
|
-
const _deployApp = function (ctx) {
|
|
145
|
+
};
|
|
146
|
+
exports.deployApp = function (ctx) {
|
|
173
147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
174
|
-
let deployment = new
|
|
148
|
+
let deployment = new Deployment();
|
|
175
149
|
console.log("Deployment object created");
|
|
176
150
|
deployment.setStatus(DeploymentStatus.PENDING);
|
|
177
151
|
console.log("Deployment object set to pending");
|
|
178
152
|
deployment = yield storeDeploymentHistory(deployment);
|
|
179
153
|
console.log("Stored deployment history");
|
|
180
154
|
console.log("Deploying app...");
|
|
181
|
-
|
|
182
|
-
yield pro_1.quotas.addPublishedApp(() => deployApp(deployment));
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
yield deployApp(deployment);
|
|
186
|
-
}
|
|
155
|
+
yield deployApp(deployment);
|
|
187
156
|
ctx.body = deployment;
|
|
188
157
|
});
|
|
189
158
|
};
|
|
190
|
-
exports.deployApp = _deployApp;
|