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