@budibase/server 1.0.105-alpha.21 → 1.0.105-alpha.24
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.8d922c8c.js → index.06b1c616.js} +150 -147
- package/builder/assets/{index.b7e0672d.css → index.e3fb1cb4.css} +2 -2
- package/builder/index.html +2 -2
- package/coverage/clover.xml +517 -1564
- package/coverage/coverage-final.json +27 -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 +23 -33
- 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 +20 -15
- 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 +52 -47
- package/coverage/lcov-report/api/controllers/table/external.js.html +8 -3
- package/coverage/lcov-report/api/controllers/table/index.html +17 -42
- 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 +9 -4
- package/coverage/lcov-report/automations/automationUtils.js.html +20 -15
- package/coverage/lcov-report/automations/bullboard.js.html +8 -3
- package/coverage/lcov-report/automations/index.html +16 -26
- 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 +16 -41
- package/coverage/lcov-report/automations/steps/integromat.js.html +8 -3
- package/coverage/lcov-report/automations/steps/loop.js.html +8 -3
- 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 +8 -3
- package/coverage/lcov-report/constants/index.js.html +35 -30
- 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/client.js.html +26 -21
- 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 +10 -5
- 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 +83 -78
- 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 +122 -117
- 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 +11 -6
- package/coverage/lcov-report/middleware/index.html +16 -41
- 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 +55 -50
- package/coverage/lcov-report/threads/index.html +16 -26
- package/coverage/lcov-report/threads/query.js.html +10 -5
- package/coverage/lcov-report/threads/utils.js.html +11 -6
- 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 +46 -41
- 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 +45 -40
- 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 +759 -2599
- package/dist/api/controllers/application.js +138 -70
- package/dist/api/controllers/deploy/index.js +64 -35
- 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/table/internal.js +40 -34
- 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 +62 -26
- package/dist/app.js +11 -4
- package/dist/automations/steps/createRow.js +12 -12
- package/dist/automations/steps/deleteRow.js +13 -16
- package/dist/automations/tests/utilities/index.js +0 -2
- package/dist/automations/utils.js +187 -132
- package/dist/environment.js +0 -2
- 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/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/rest.js +1 -1
- package/dist/middleware/authorized.js +51 -51
- 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 +10 -8
- package/dist/threads/index.js +35 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +6 -1
- package/nodemon.json +1 -1
- package/package.json +11 -9
- package/scripts/dev/manage.js +2 -0
- package/src/api/controllers/{application.js → application.ts} +103 -44
- package/src/api/controllers/deploy/{index.js → index.ts} +45 -28
- 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/table/{internal.js → internal.ts} +27 -24
- 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/utilities/{TestFunctions.js → TestFunctions.ts} +42 -25
- package/src/app.ts +1 -2
- package/src/automations/steps/{createRow.js → createRow.ts} +9 -15
- package/src/automations/steps/{deleteRow.js → deleteRow.ts} +10 -16
- 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 +0 -2
- package/src/automations/{utils.js → utils.ts} +39 -27
- package/src/environment.js +0 -2
- package/src/middleware/{authorized.js → authorized.ts} +20 -14
- 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 +32 -0
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +38 -0
- package/src/migrations/index.ts +13 -1
- package/src/module.d.ts +4 -0
- package/src/threads/{index.js → index.ts} +14 -12
- package/src/utilities/queue/inMemoryQueue.js +7 -1
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +2 -2
- package/coverage/lcov-report/api/controllers/application.js.html +0 -1430
- 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 -548
- 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/api/routes/static.js.html +0 -245
- 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 -662
- 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 -278
- 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 -134
- package/src/middleware/usageQuota.js +0 -164
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
- 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
|
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,48 @@ 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.
|
|
339
|
+
exports.revertClient = revertClient;
|
|
340
|
+
const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
341
|
+
var _a;
|
|
298
342
|
const db = getAppDB();
|
|
299
343
|
const result = yield db.destroy();
|
|
344
|
+
if ((_a = ctx.query) === null || _a === void 0 ? void 0 : _a.unpublish) {
|
|
345
|
+
yield pro_1.quotas.removePublishedApp();
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
yield pro_1.quotas.removeApp();
|
|
349
|
+
}
|
|
300
350
|
/* istanbul ignore next */
|
|
301
|
-
if (!
|
|
302
|
-
yield deleteApp(ctx.params.appId);
|
|
351
|
+
if (!environment_1.default.isTest() && !ctx.query.unpublish) {
|
|
352
|
+
yield (0, fileSystem_1.deleteApp)(ctx.params.appId);
|
|
303
353
|
}
|
|
304
354
|
if (ctx.query && ctx.query.unpublish) {
|
|
305
|
-
yield cleanupAutomations(ctx.params.appId);
|
|
355
|
+
yield (0, utils_2.cleanupAutomations)(ctx.params.appId);
|
|
306
356
|
}
|
|
307
357
|
// make sure the app/role doesn't stick around after the app has been deleted
|
|
308
|
-
yield removeAppFromUserRoles(ctx, ctx.params.appId);
|
|
358
|
+
yield (0, workerRequests_1.removeAppFromUserRoles)(ctx, ctx.params.appId);
|
|
309
359
|
yield appCache.invalidateAppMetadata(ctx.params.appId);
|
|
360
|
+
return result;
|
|
361
|
+
});
|
|
362
|
+
const preDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
363
|
+
const rows = yield (0, rows_1.getUniqueRows)([ctx.params.appId]);
|
|
364
|
+
ctx.rowCount = rows.length;
|
|
365
|
+
});
|
|
366
|
+
const postDestroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
367
|
+
const rowCount = ctx.rowCount;
|
|
368
|
+
if (rowCount) {
|
|
369
|
+
yield pro_1.quotas.removeRows(rowCount);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
const destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
373
|
+
yield preDestroyApp(ctx);
|
|
374
|
+
const result = yield destroyApp(ctx);
|
|
375
|
+
yield postDestroyApp(ctx);
|
|
310
376
|
ctx.status = 200;
|
|
311
377
|
ctx.body = result;
|
|
312
378
|
});
|
|
313
|
-
exports.
|
|
379
|
+
exports.destroy = destroy;
|
|
380
|
+
const sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
314
381
|
const appId = ctx.params.appId;
|
|
315
382
|
if (!isDevAppID(appId)) {
|
|
316
383
|
ctx.throw(400, "This action cannot be performed for production apps");
|
|
@@ -340,7 +407,7 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
340
407
|
try {
|
|
341
408
|
yield replication.replicate({
|
|
342
409
|
filter: function (doc) {
|
|
343
|
-
return doc._id !== DocumentTypes.APP_METADATA;
|
|
410
|
+
return doc._id !== utils_1.DocumentTypes.APP_METADATA;
|
|
344
411
|
},
|
|
345
412
|
});
|
|
346
413
|
}
|
|
@@ -348,7 +415,7 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
348
415
|
error = err;
|
|
349
416
|
}
|
|
350
417
|
// sync the users
|
|
351
|
-
yield syncGlobalUsers();
|
|
418
|
+
yield (0, user_1.syncGlobalUsers)();
|
|
352
419
|
if (error) {
|
|
353
420
|
ctx.throw(400, error);
|
|
354
421
|
}
|
|
@@ -358,9 +425,10 @@ exports.sync = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
358
425
|
};
|
|
359
426
|
}
|
|
360
427
|
});
|
|
428
|
+
exports.sync = sync;
|
|
361
429
|
const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
362
430
|
const db = getAppDB();
|
|
363
|
-
const application = yield db.get(DocumentTypes.APP_METADATA);
|
|
431
|
+
const application = yield db.get(utils_1.DocumentTypes.APP_METADATA);
|
|
364
432
|
const newAppPackage = Object.assign(Object.assign({}, application), appPackage);
|
|
365
433
|
if (appPackage._rev !== application._rev) {
|
|
366
434
|
newAppPackage._rev = application._rev;
|
|
@@ -376,8 +444,8 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
|
|
|
376
444
|
const createEmptyAppPackage = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
|
|
377
445
|
const db = getAppDB();
|
|
378
446
|
let screensAndLayouts = [];
|
|
379
|
-
for (let layout of BASE_LAYOUTS) {
|
|
380
|
-
const cloned = cloneDeep(layout);
|
|
447
|
+
for (let layout of layouts_1.BASE_LAYOUTS) {
|
|
448
|
+
const cloned = (0, fp_1.cloneDeep)(layout);
|
|
381
449
|
screensAndLayouts.push(yield processObject(cloned, app));
|
|
382
450
|
}
|
|
383
451
|
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..");
|
|
@@ -82,22 +89,23 @@ function initDeployedApp(prodAppId) {
|
|
|
82
89
|
function deployApp(deployment) {
|
|
83
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
91
|
try {
|
|
85
|
-
const appId = getAppId();
|
|
86
|
-
const devAppId = getDevelopmentAppID(appId);
|
|
87
|
-
const productionAppId = getProdAppID(appId);
|
|
88
|
-
const
|
|
92
|
+
const appId = (0, context_1.getAppId)();
|
|
93
|
+
const devAppId = (0, db_1.getDevelopmentAppID)(appId);
|
|
94
|
+
const productionAppId = (0, db_1.getProdAppID)(appId);
|
|
95
|
+
const config = {
|
|
89
96
|
source: devAppId,
|
|
90
97
|
target: productionAppId,
|
|
91
|
-
}
|
|
98
|
+
};
|
|
99
|
+
const replication = new db_1.Replication(config);
|
|
92
100
|
console.log("Replication object created");
|
|
93
101
|
yield replication.replicate();
|
|
94
102
|
console.log("replication complete.. replacing app meta doc");
|
|
95
|
-
const db = getProdAppDB();
|
|
96
|
-
const appDoc = yield db.get(DocumentTypes.APP_METADATA);
|
|
103
|
+
const db = (0, context_1.getProdAppDB)();
|
|
104
|
+
const appDoc = yield db.get(utils_1.DocumentTypes.APP_METADATA);
|
|
97
105
|
appDoc.appId = productionAppId;
|
|
98
106
|
appDoc.instance._id = productionAppId;
|
|
99
107
|
yield db.put(appDoc);
|
|
100
|
-
yield
|
|
108
|
+
yield cache_1.app.invalidateAppMetadata(productionAppId);
|
|
101
109
|
console.log("New app doc written successfully.");
|
|
102
110
|
yield initDeployedApp(productionAppId);
|
|
103
111
|
console.log("Deployed app initialised, setting deployment to successful");
|
|
@@ -111,12 +119,12 @@ function deployApp(deployment) {
|
|
|
111
119
|
}
|
|
112
120
|
});
|
|
113
121
|
}
|
|
114
|
-
|
|
122
|
+
function fetchDeployments(ctx) {
|
|
115
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
116
124
|
try {
|
|
117
|
-
const db = getAppDB();
|
|
118
|
-
const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
|
|
119
|
-
const { updated, deployments } = yield checkAllDeployments(deploymentDoc
|
|
125
|
+
const db = (0, context_1.getAppDB)();
|
|
126
|
+
const deploymentDoc = yield db.get(utils_1.DocumentTypes.DEPLOYMENTS);
|
|
127
|
+
const { updated, deployments } = yield checkAllDeployments(deploymentDoc);
|
|
120
128
|
if (updated) {
|
|
121
129
|
yield db.put(deployments);
|
|
122
130
|
}
|
|
@@ -126,29 +134,50 @@ exports.fetchDeployments = function (ctx) {
|
|
|
126
134
|
ctx.body = [];
|
|
127
135
|
}
|
|
128
136
|
});
|
|
129
|
-
}
|
|
130
|
-
exports.
|
|
137
|
+
}
|
|
138
|
+
exports.fetchDeployments = fetchDeployments;
|
|
139
|
+
function deploymentProgress(ctx) {
|
|
131
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
141
|
try {
|
|
133
|
-
const db = getAppDB();
|
|
134
|
-
const deploymentDoc = yield db.get(DocumentTypes.DEPLOYMENTS);
|
|
142
|
+
const db = (0, context_1.getAppDB)();
|
|
143
|
+
const deploymentDoc = yield db.get(utils_1.DocumentTypes.DEPLOYMENTS);
|
|
135
144
|
ctx.body = deploymentDoc[ctx.params.deploymentId];
|
|
136
145
|
}
|
|
137
146
|
catch (err) {
|
|
138
147
|
ctx.throw(500, `Error fetching data for deployment ${ctx.params.deploymentId}`);
|
|
139
148
|
}
|
|
140
149
|
});
|
|
141
|
-
}
|
|
142
|
-
exports.
|
|
150
|
+
}
|
|
151
|
+
exports.deploymentProgress = deploymentProgress;
|
|
152
|
+
const isFirstDeploy = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
153
|
+
try {
|
|
154
|
+
const db = (0, context_1.getProdAppDB)();
|
|
155
|
+
yield db.get(utils_1.DocumentTypes.APP_METADATA);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
if (e.status === 404) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
throw e;
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
});
|
|
165
|
+
const _deployApp = function (ctx) {
|
|
143
166
|
return __awaiter(this, void 0, void 0, function* () {
|
|
144
|
-
let deployment = new
|
|
167
|
+
let deployment = new Deployment_1.default();
|
|
145
168
|
console.log("Deployment object created");
|
|
146
169
|
deployment.setStatus(DeploymentStatus.PENDING);
|
|
147
170
|
console.log("Deployment object set to pending");
|
|
148
171
|
deployment = yield storeDeploymentHistory(deployment);
|
|
149
172
|
console.log("Stored deployment history");
|
|
150
173
|
console.log("Deploying app...");
|
|
151
|
-
yield
|
|
174
|
+
if (yield isFirstDeploy()) {
|
|
175
|
+
yield pro_1.quotas.addPublishedApp(() => deployApp(deployment));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
yield deployApp(deployment);
|
|
179
|
+
}
|
|
152
180
|
ctx.body = deployment;
|
|
153
181
|
});
|
|
154
182
|
};
|
|
183
|
+
exports.deployApp = _deployApp;
|