@budibase/server 1.0.200 → 1.0.201-alpha.2
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/Dockerfile +2 -0
- package/builder/assets/index.d7c6f2cd.js +1315 -0
- package/builder/index.html +1 -1
- package/coverage/clover.xml +2094 -2004
- package/coverage/coverage-final.json +121 -122
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
- package/coverage/lcov-report/api/controllers/automation.js.html +174 -72
- package/coverage/lcov-report/api/controllers/backup.js.html +30 -6
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +53 -41
- package/coverage/lcov-report/api/controllers/dev.js.html +94 -70
- package/coverage/lcov-report/api/controllers/index.html +57 -72
- package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
- package/coverage/lcov-report/api/controllers/layout.js.html +28 -19
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
- package/coverage/lcov-report/api/controllers/role.js.html +78 -48
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
- package/coverage/lcov-report/api/controllers/screen.js.html +56 -20
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
- package/coverage/lcov-report/api/controllers/table/external.js.html +23 -17
- package/coverage/lcov-report/api/controllers/table/index.html +26 -26
- package/coverage/lcov-report/api/controllers/table/index.js.html +85 -49
- package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
- package/coverage/lcov-report/api/controllers/user.js.html +19 -19
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/index.html +21 -21
- package/coverage/lcov-report/api/controllers/view/index.js.html +275 -65
- package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
- package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
- package/coverage/lcov-report/api/index.html +15 -15
- package/coverage/lcov-report/api/index.js.html +39 -45
- package/coverage/lcov-report/api/routes/analytics.js.html +7 -13
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +11 -11
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +9 -9
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +9 -9
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/screen.js.html +9 -9
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +10 -10
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
- package/coverage/lcov-report/automations/actions.js.html +25 -25
- package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
- package/coverage/lcov-report/automations/bullboard.js.html +35 -35
- package/coverage/lcov-report/automations/index.html +29 -29
- package/coverage/lcov-report/automations/index.js.html +29 -17
- package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +18 -18
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +30 -30
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +9 -9
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +81 -81
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +7 -7
- package/coverage/lcov-report/events/utils.js.html +10 -10
- package/coverage/lcov-report/index.html +79 -79
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
- package/coverage/lcov-report/middleware/builder.js.html +20 -20
- package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
- package/coverage/lcov-report/middleware/index.html +11 -11
- package/coverage/lcov-report/middleware/joi-validator.js.html +44 -20
- package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
- package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +1 -1
- package/coverage/lcov-report/threads/utils.js.html +13 -13
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
- package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
- package/coverage/lcov-report/utilities/global.js.html +28 -28
- package/coverage/lcov-report/utilities/index.html +25 -25
- package/coverage/lcov-report/utilities/index.js.html +41 -41
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
- package/coverage/lcov-report/utilities/queue/index.html +15 -15
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +7 -7
- package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
- package/coverage/lcov.info +2914 -2771
- package/dist/api/controllers/analytics.js +7 -30
- package/dist/api/controllers/application.js +56 -16
- package/dist/api/controllers/automation.js +31 -2
- package/dist/api/controllers/backup.js +7 -0
- package/dist/api/controllers/datasource.js +8 -2
- package/dist/api/controllers/deploy/index.js +6 -2
- package/dist/api/controllers/dev.js +9 -2
- package/dist/api/controllers/layout.js +3 -0
- package/dist/api/controllers/query/import/index.js +12 -2
- package/dist/api/controllers/query/import/sources/curl.js +3 -0
- package/dist/api/controllers/query/import/sources/openapi2.js +3 -0
- package/dist/api/controllers/query/import/sources/openapi3.js +3 -0
- package/dist/api/controllers/query/index.js +16 -2
- package/dist/api/controllers/role.js +11 -0
- package/dist/api/controllers/screen.js +10 -1
- package/dist/api/controllers/static/index.js +29 -15
- package/dist/api/controllers/table/external.js +2 -0
- package/dist/api/controllers/table/index.js +12 -0
- package/dist/api/controllers/table/utils.js +3 -3
- package/dist/api/controllers/view/index.js +62 -6
- package/dist/api/index.js +2 -4
- package/dist/api/routes/analytics.js +1 -3
- package/dist/app.js +16 -8
- package/dist/automations/index.js +4 -0
- package/dist/environment.js +4 -2
- package/dist/middleware/joi-validator.js +5 -0
- package/dist/migrations/functions/backfill/app/automations.js +31 -0
- package/dist/migrations/functions/backfill/app/datasources.js +28 -0
- package/dist/migrations/functions/backfill/app/layouts.js +33 -0
- package/dist/migrations/functions/backfill/app/queries.js +32 -0
- package/dist/migrations/functions/backfill/app/roles.js +28 -0
- package/dist/migrations/functions/backfill/app/screens.js +28 -0
- package/dist/migrations/functions/backfill/app/tables.js +40 -0
- package/dist/migrations/functions/backfill/app.js +175 -0
- package/dist/migrations/functions/backfill/global/configs.js +61 -0
- package/dist/migrations/functions/backfill/global/quotas.js +60 -0
- package/dist/migrations/functions/backfill/global/users.js +50 -0
- package/dist/migrations/functions/backfill/global.js +206 -0
- package/dist/migrations/functions/backfill/index.js +32 -0
- package/dist/migrations/functions/backfill/installation.js +80 -0
- package/dist/migrations/index.js +95 -31
- package/dist/migrations/tests/helpers.js +72 -0
- package/dist/migrations/tests/structures.js +37 -0
- package/dist/package.json +79 -69
- package/dist/tests/utilities/TestConfiguration.js +121 -93
- package/dist/tests/utilities/structures.js +45 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/nodemon.json +1 -1
- package/package.json +80 -70
- package/scripts/dev/manage.js +2 -0
- package/scripts/jestSetup.js +7 -0
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/analytics.ts +8 -0
- package/src/api/controllers/application.ts +60 -18
- package/src/api/controllers/automation.js +36 -2
- package/src/api/controllers/backup.js +8 -0
- package/src/api/controllers/datasource.js +8 -4
- package/src/api/controllers/deploy/index.ts +6 -2
- package/src/api/controllers/dev.js +10 -2
- package/src/api/controllers/layout.js +3 -0
- package/src/api/controllers/query/import/index.ts +16 -3
- package/src/api/controllers/query/import/sources/base/index.ts +2 -1
- package/src/api/controllers/query/import/sources/curl.ts +4 -0
- package/src/api/controllers/query/import/sources/openapi2.ts +4 -0
- package/src/api/controllers/query/import/sources/openapi3.ts +4 -0
- package/src/api/controllers/query/import/tests/index.spec.js +20 -7
- package/src/api/controllers/query/index.ts +16 -3
- package/src/api/controllers/role.js +10 -0
- package/src/api/controllers/screen.js +13 -1
- package/src/api/controllers/static/index.js +28 -15
- package/src/api/controllers/table/external.js +2 -0
- package/src/api/controllers/table/index.js +12 -0
- package/src/api/controllers/table/utils.ts +4 -4
- package/src/api/controllers/view/index.js +76 -6
- package/src/api/index.js +2 -4
- package/src/api/routes/analytics.js +1 -3
- package/src/api/routes/public/utils/Endpoint.ts +1 -1
- package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +5 -1
- package/src/api/routes/tests/application.spec.js +64 -4
- package/src/api/routes/tests/automation.spec.js +168 -60
- package/src/api/routes/tests/backup.spec.js +2 -0
- package/src/api/routes/tests/data/export.txt +1 -0
- package/src/api/routes/tests/datasource.spec.js +5 -0
- package/src/api/routes/tests/deployment.spec.js +25 -0
- package/src/api/routes/tests/dev.spec.js +40 -0
- package/src/api/routes/tests/layout.spec.js +4 -0
- package/src/api/routes/tests/query.spec.js +56 -13
- package/src/api/routes/tests/role.spec.js +40 -7
- package/src/api/routes/tests/row.spec.js +2 -3
- package/src/api/routes/tests/screen.spec.js +30 -4
- package/src/api/routes/tests/static.spec.js +120 -54
- package/src/api/routes/tests/table.spec.js +102 -38
- package/src/api/routes/tests/view.spec.js +222 -43
- package/src/app.ts +18 -9
- package/src/automations/index.js +4 -0
- package/src/automations/tests/delay.spec.js +4 -0
- package/src/environment.js +5 -2
- package/src/middleware/joi-validator.js +8 -0
- package/src/migrations/functions/backfill/app/automations.ts +26 -0
- package/src/migrations/functions/backfill/app/datasources.ts +22 -0
- package/src/migrations/functions/backfill/app/layouts.ts +29 -0
- package/src/migrations/functions/backfill/app/queries.ts +33 -0
- package/src/migrations/functions/backfill/app/roles.ts +22 -0
- package/src/migrations/functions/backfill/app/screens.ts +22 -0
- package/src/migrations/functions/backfill/app/tables.ts +36 -0
- package/src/migrations/functions/backfill/app.ts +148 -0
- package/src/migrations/functions/backfill/global/configs.ts +66 -0
- package/src/migrations/functions/backfill/global/quotas.ts +60 -0
- package/src/migrations/functions/backfill/global/users.ts +49 -0
- package/src/migrations/functions/backfill/global.ts +214 -0
- package/src/migrations/functions/backfill/index.ts +7 -0
- package/src/migrations/functions/backfill/installation.ts +50 -0
- package/src/migrations/index.ts +119 -51
- package/src/migrations/tests/helpers.ts +40 -0
- package/src/migrations/tests/index.spec.ts +132 -0
- package/src/migrations/tests/structures.ts +66 -0
- package/src/module.d.ts +0 -1
- package/src/tests/utilities/TestConfiguration.js +138 -90
- package/src/tests/utilities/structures.js +71 -0
- package/tsconfig.build.json +20 -5
- package/tsconfig.json +22 -17
- package/builder/assets/index.f83b3433.js +0 -1315
- package/coverage/lcov-report/api/controllers/analytics.js.html +0 -202
- package/src/api/controllers/analytics.js +0 -39
|
@@ -8,36 +8,13 @@ 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
|
-
}
|
|
17
|
-
exports.isEnabled = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isEnabled = void 0;
|
|
13
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
14
|
+
const isEnabled = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const enabled = yield backend_core_1.events.analytics.enabled();
|
|
18
16
|
ctx.body = {
|
|
19
|
-
enabled
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
exports.endUserPing = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
if (!posthogClient) {
|
|
24
|
-
ctx.body = {
|
|
25
|
-
ping: false,
|
|
26
|
-
};
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
posthogClient.identify({
|
|
30
|
-
distinctId: ctx.user && ctx.user._id,
|
|
31
|
-
properties: {},
|
|
32
|
-
});
|
|
33
|
-
posthogClient.capture({
|
|
34
|
-
event: "budibase:end_user_ping",
|
|
35
|
-
distinctId: ctx.user && ctx.user._id,
|
|
36
|
-
properties: {
|
|
37
|
-
appId: ctx.appId,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
ctx.body = {
|
|
41
|
-
ping: true,
|
|
17
|
+
enabled,
|
|
42
18
|
};
|
|
43
19
|
});
|
|
20
|
+
exports.isEnabled = isEnabled;
|
|
@@ -37,6 +37,7 @@ const { getAppDB, getProdAppDB, updateAppId, } = require("@budibase/backend-core
|
|
|
37
37
|
const rows_1 = require("../../utilities/usageQuota/rows");
|
|
38
38
|
const pro_1 = require("@budibase/pro");
|
|
39
39
|
const backend_core_1 = require("@budibase/backend-core");
|
|
40
|
+
const types_1 = require("@budibase/types");
|
|
40
41
|
const URL_REGEX_SLASH = /\/|\\/g;
|
|
41
42
|
// utility function, need to do away with this
|
|
42
43
|
function getLayouts() {
|
|
@@ -196,7 +197,7 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
196
197
|
const apps = yield getAllApps({ dev: true });
|
|
197
198
|
const name = ctx.request.body.name;
|
|
198
199
|
checkAppName(ctx, apps, name);
|
|
199
|
-
const url = exports.getAppUrl(ctx);
|
|
200
|
+
const url = (0, exports.getAppUrl)(ctx);
|
|
200
201
|
checkAppUrl(ctx, apps, url);
|
|
201
202
|
const { useTemplate, templateKey, templateString } = ctx.request.body;
|
|
202
203
|
const instanceConfig = {
|
|
@@ -249,10 +250,40 @@ const performAppCreate = (ctx) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
249
250
|
yield appCache.invalidateAppMetadata(appId, newApplication);
|
|
250
251
|
return newApplication;
|
|
251
252
|
});
|
|
252
|
-
const
|
|
253
|
+
const creationEvents = (request, app) => __awaiter(void 0, void 0, void 0, function* () {
|
|
254
|
+
var _a;
|
|
255
|
+
let creationFns = [];
|
|
256
|
+
const body = request.body;
|
|
257
|
+
if (body.useTemplate === "true") {
|
|
258
|
+
// from template
|
|
259
|
+
if (body.templateKey && body.templateKey !== "undefined") {
|
|
260
|
+
creationFns.push(a => backend_core_1.events.app.templateImported(a, body.templateKey));
|
|
261
|
+
}
|
|
262
|
+
// from file
|
|
263
|
+
else if ((_a = request.files) === null || _a === void 0 ? void 0 : _a.templateFile) {
|
|
264
|
+
creationFns.push(a => backend_core_1.events.app.fileImported(a));
|
|
265
|
+
}
|
|
266
|
+
// unknown
|
|
267
|
+
else {
|
|
268
|
+
console.error("Could not determine template creation event");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
creationFns.push(a => backend_core_1.events.app.created(a));
|
|
272
|
+
for (let fn of creationFns) {
|
|
273
|
+
yield fn(app);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
const appPostCreate = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
|
|
277
|
+
const tenantId = getTenantId();
|
|
278
|
+
yield backend_core_1.migrations.backPopulateMigrations({
|
|
279
|
+
type: types_1.MigrationType.APP,
|
|
280
|
+
tenantId,
|
|
281
|
+
appId: app.appId,
|
|
282
|
+
});
|
|
283
|
+
yield creationEvents(ctx.request, app);
|
|
253
284
|
// app import & template creation
|
|
254
285
|
if (ctx.request.body.useTemplate === "true") {
|
|
255
|
-
const rows = yield (0, rows_1.getUniqueRows)([appId]);
|
|
286
|
+
const rows = yield (0, rows_1.getUniqueRows)([app.appId]);
|
|
256
287
|
const rowCount = rows ? rows.length : 0;
|
|
257
288
|
if (rowCount) {
|
|
258
289
|
try {
|
|
@@ -263,7 +294,7 @@ const appPostCreate = (ctx, appId) => __awaiter(void 0, void 0, void 0, function
|
|
|
263
294
|
// this import resulted in row usage exceeding the quota
|
|
264
295
|
// delete the app
|
|
265
296
|
// skip pre and post steps as no rows have been added to quotas yet
|
|
266
|
-
ctx.params.appId = appId;
|
|
297
|
+
ctx.params.appId = app.appId;
|
|
267
298
|
yield destroyApp(ctx);
|
|
268
299
|
}
|
|
269
300
|
throw err;
|
|
@@ -273,7 +304,7 @@ const appPostCreate = (ctx, appId) => __awaiter(void 0, void 0, void 0, function
|
|
|
273
304
|
});
|
|
274
305
|
const create = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
275
306
|
const newApplication = yield pro_1.quotas.addApp(() => performAppCreate(ctx));
|
|
276
|
-
yield appPostCreate(ctx, newApplication
|
|
307
|
+
yield appPostCreate(ctx, newApplication);
|
|
277
308
|
yield bustCache(CacheKeys.CHECKLIST);
|
|
278
309
|
ctx.body = newApplication;
|
|
279
310
|
ctx.status = 200;
|
|
@@ -288,14 +319,15 @@ const update = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
288
319
|
if (name) {
|
|
289
320
|
checkAppName(ctx, apps, name, ctx.params.appId);
|
|
290
321
|
}
|
|
291
|
-
const url =
|
|
322
|
+
const url = (0, exports.getAppUrl)(ctx);
|
|
292
323
|
if (url) {
|
|
293
324
|
checkAppUrl(ctx, apps, url, ctx.params.appId);
|
|
294
325
|
ctx.request.body.url = url;
|
|
295
326
|
}
|
|
296
|
-
const
|
|
327
|
+
const app = yield updateAppPackage(ctx.request.body, ctx.params.appId);
|
|
328
|
+
yield backend_core_1.events.app.updated(app);
|
|
297
329
|
ctx.status = 200;
|
|
298
|
-
ctx.body =
|
|
330
|
+
ctx.body = app;
|
|
299
331
|
});
|
|
300
332
|
exports.update = update;
|
|
301
333
|
const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -309,13 +341,15 @@ const updateClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
309
341
|
yield (0, clientLibrary_1.updateClientLibrary)(ctx.params.appId);
|
|
310
342
|
}
|
|
311
343
|
// Update versions in app package
|
|
344
|
+
const updatedToVersion = package_json_1.default.version;
|
|
312
345
|
const appPackageUpdates = {
|
|
313
|
-
version:
|
|
346
|
+
version: updatedToVersion,
|
|
314
347
|
revertableVersion: currentVersion,
|
|
315
348
|
};
|
|
316
|
-
const
|
|
349
|
+
const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
350
|
+
yield backend_core_1.events.app.versionUpdated(app, currentVersion, updatedToVersion);
|
|
317
351
|
ctx.status = 200;
|
|
318
|
-
ctx.body =
|
|
352
|
+
ctx.body = app;
|
|
319
353
|
});
|
|
320
354
|
exports.updateClient = updateClient;
|
|
321
355
|
const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -330,13 +364,16 @@ const revertClient = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
330
364
|
yield (0, clientLibrary_1.revertClientLibrary)(ctx.params.appId);
|
|
331
365
|
}
|
|
332
366
|
// Update versions in app package
|
|
367
|
+
const currentVersion = application.version;
|
|
368
|
+
const revertedToVersion = application.revertableVersion;
|
|
333
369
|
const appPackageUpdates = {
|
|
334
|
-
version:
|
|
370
|
+
version: revertedToVersion,
|
|
335
371
|
revertableVersion: null,
|
|
336
372
|
};
|
|
337
|
-
const
|
|
373
|
+
const app = yield updateAppPackage(appPackageUpdates, ctx.params.appId);
|
|
374
|
+
yield backend_core_1.events.app.versionReverted(app, currentVersion, revertedToVersion);
|
|
338
375
|
ctx.status = 200;
|
|
339
|
-
ctx.body =
|
|
376
|
+
ctx.body = app;
|
|
340
377
|
});
|
|
341
378
|
exports.revertClient = revertClient;
|
|
342
379
|
const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -346,12 +383,15 @@ const destroyApp = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
346
383
|
appId = getProdAppID(appId);
|
|
347
384
|
}
|
|
348
385
|
const db = isUnpublish ? getProdAppDB() : getAppDB();
|
|
386
|
+
const app = yield db.get(utils_1.DocumentTypes.APP_METADATA);
|
|
349
387
|
const result = yield db.destroy();
|
|
350
388
|
if (isUnpublish) {
|
|
351
389
|
yield pro_1.quotas.removePublishedApp();
|
|
390
|
+
yield backend_core_1.events.app.unpublished(app);
|
|
352
391
|
}
|
|
353
392
|
else {
|
|
354
393
|
yield pro_1.quotas.removeApp();
|
|
394
|
+
yield backend_core_1.events.app.deleted(app);
|
|
355
395
|
}
|
|
356
396
|
/* istanbul ignore next */
|
|
357
397
|
if (!environment_1.default.isTest() && !isUnpublish) {
|
|
@@ -455,10 +495,10 @@ const updateAppPackage = (appPackage, appId) => __awaiter(void 0, void 0, void 0
|
|
|
455
495
|
// the locked by property is attached by server but generated from
|
|
456
496
|
// Redis, shouldn't ever store it
|
|
457
497
|
delete newAppPackage.lockedBy;
|
|
458
|
-
|
|
498
|
+
yield db.put(newAppPackage);
|
|
459
499
|
// remove any cached metadata, so that it will be updated
|
|
460
500
|
yield appCache.invalidateAppMetadata(appId);
|
|
461
|
-
return
|
|
501
|
+
return newAppPackage;
|
|
462
502
|
});
|
|
463
503
|
const createEmptyAppPackage = (ctx, app) => __awaiter(void 0, void 0, void 0, function* () {
|
|
464
504
|
const db = getAppDB();
|
|
@@ -16,6 +16,7 @@ const { deleteEntityMetadata } = require("../../utilities");
|
|
|
16
16
|
const { MetadataTypes } = require("../../constants");
|
|
17
17
|
const { setTestFlag, clearTestFlag } = require("../../utilities/redis");
|
|
18
18
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
19
|
+
const { events } = require("@budibase/backend-core");
|
|
19
20
|
const ACTION_DEFS = removeDeprecated(actions.ACTION_DEFINITIONS);
|
|
20
21
|
const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS);
|
|
21
22
|
/*************************
|
|
@@ -68,6 +69,10 @@ exports.create = function (ctx) {
|
|
|
68
69
|
newAuto: automation,
|
|
69
70
|
});
|
|
70
71
|
const response = yield db.put(automation);
|
|
72
|
+
yield events.automation.created(automation);
|
|
73
|
+
for (let step of automation.definition.steps) {
|
|
74
|
+
yield events.automation.stepCreated(automation, step);
|
|
75
|
+
}
|
|
71
76
|
automation._rev = response.rev;
|
|
72
77
|
ctx.status = 200;
|
|
73
78
|
ctx.body = {
|
|
@@ -76,6 +81,26 @@ exports.create = function (ctx) {
|
|
|
76
81
|
};
|
|
77
82
|
});
|
|
78
83
|
};
|
|
84
|
+
const getNewSteps = (oldAutomation, automation) => {
|
|
85
|
+
const oldStepIds = oldAutomation.definition.steps.map(s => s.id);
|
|
86
|
+
return automation.definition.steps.filter(s => !oldStepIds.includes(s.id));
|
|
87
|
+
};
|
|
88
|
+
const getDeletedSteps = (oldAutomation, automation) => {
|
|
89
|
+
const stepIds = automation.definition.steps.map(s => s.id);
|
|
90
|
+
return oldAutomation.definition.steps.filter(s => !stepIds.includes(s.id));
|
|
91
|
+
};
|
|
92
|
+
const handleStepEvents = (oldAutomation, automation) => __awaiter(void 0, void 0, void 0, function* () {
|
|
93
|
+
// new steps
|
|
94
|
+
const newSteps = getNewSteps(oldAutomation, automation);
|
|
95
|
+
for (let step of newSteps) {
|
|
96
|
+
yield events.automation.stepCreated(automation, step);
|
|
97
|
+
}
|
|
98
|
+
// old steps
|
|
99
|
+
const deletedSteps = getDeletedSteps(oldAutomation, automation);
|
|
100
|
+
for (let step of deletedSteps) {
|
|
101
|
+
yield events.automation.stepDeleted(automation, step);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
79
104
|
exports.update = function (ctx) {
|
|
80
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
106
|
const db = getAppDB();
|
|
@@ -91,14 +116,16 @@ exports.update = function (ctx) {
|
|
|
91
116
|
automation._rev = response.rev;
|
|
92
117
|
const oldAutoTrigger = oldAutomation && oldAutomation.definition.trigger
|
|
93
118
|
? oldAutomation.definition.trigger
|
|
94
|
-
:
|
|
119
|
+
: undefined;
|
|
95
120
|
const newAutoTrigger = automation && automation.definition.trigger
|
|
96
121
|
? automation.definition.trigger
|
|
97
122
|
: {};
|
|
98
123
|
// trigger has been updated, remove the test inputs
|
|
99
|
-
if (oldAutoTrigger.id !== newAutoTrigger.id) {
|
|
124
|
+
if (oldAutoTrigger && oldAutoTrigger.id !== newAutoTrigger.id) {
|
|
125
|
+
yield events.automation.triggerUpdated(automation);
|
|
100
126
|
yield deleteEntityMetadata(ctx.appId, MetadataTypes.AUTOMATION_TEST_INPUT, automation._id);
|
|
101
127
|
}
|
|
128
|
+
yield handleStepEvents(oldAutomation, automation);
|
|
102
129
|
ctx.status = 200;
|
|
103
130
|
ctx.body = {
|
|
104
131
|
message: `Automation ${automation._id} updated successfully.`,
|
|
@@ -132,6 +159,7 @@ exports.destroy = function (ctx) {
|
|
|
132
159
|
// delete metadata first
|
|
133
160
|
yield cleanupAutomationMetadata(automationId);
|
|
134
161
|
ctx.body = yield db.remove(automationId, ctx.params.rev);
|
|
162
|
+
yield events.automation.deleted(oldAutomation);
|
|
135
163
|
});
|
|
136
164
|
};
|
|
137
165
|
exports.getActionList = function (ctx) {
|
|
@@ -189,5 +217,6 @@ exports.test = function (ctx) {
|
|
|
189
217
|
yield updateTestHistory(ctx.appId, automation, Object.assign(Object.assign({}, ctx.request.body), { occurredAt: new Date().getTime() }));
|
|
190
218
|
yield clearTestFlag(automation._id);
|
|
191
219
|
ctx.body = response;
|
|
220
|
+
yield events.automation.tested(automation);
|
|
192
221
|
});
|
|
193
222
|
};
|
|
@@ -9,6 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { streamBackup } = require("../../utilities/fileSystem");
|
|
12
|
+
const { events, context } = require("@budibase/backend-core");
|
|
13
|
+
const { DocumentTypes } = require("../../db/utils");
|
|
12
14
|
exports.exportAppDump = function (ctx) {
|
|
13
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
16
|
const { appId } = ctx.query;
|
|
@@ -16,5 +18,10 @@ exports.exportAppDump = function (ctx) {
|
|
|
16
18
|
const backupIdentifier = `${appName}-export-${new Date().getTime()}.txt`;
|
|
17
19
|
ctx.attachment(backupIdentifier);
|
|
18
20
|
ctx.body = yield streamBackup(appId);
|
|
21
|
+
yield context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const appDb = context.getAppDB();
|
|
23
|
+
const app = yield appDb.get(DocumentTypes.APP_METADATA);
|
|
24
|
+
yield events.app.exported(app);
|
|
25
|
+
}));
|
|
19
26
|
});
|
|
20
27
|
};
|
|
@@ -14,6 +14,7 @@ const { integrations } = require("../../integrations");
|
|
|
14
14
|
const { getDatasourceAndQuery } = require("./row/utils");
|
|
15
15
|
const { invalidateDynamicVariables } = require("../../threads/utils");
|
|
16
16
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
17
|
+
const { events } = require("@budibase/backend-core");
|
|
17
18
|
exports.fetch = function (ctx) {
|
|
18
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
20
|
// Get internal tables
|
|
@@ -91,6 +92,7 @@ exports.update = function (ctx) {
|
|
|
91
92
|
datasource.config.auth = auth;
|
|
92
93
|
}
|
|
93
94
|
const response = yield db.put(datasource);
|
|
95
|
+
yield events.datasource.updated(datasource);
|
|
94
96
|
datasource._rev = response.rev;
|
|
95
97
|
// Drain connection pools when configuration is changed
|
|
96
98
|
if (datasource.source) {
|
|
@@ -117,6 +119,7 @@ exports.save = function (ctx) {
|
|
|
117
119
|
datasource.entities = tables;
|
|
118
120
|
}
|
|
119
121
|
const dbResp = yield db.put(datasource);
|
|
122
|
+
yield events.datasource.created(datasource);
|
|
120
123
|
datasource._rev = dbResp.rev;
|
|
121
124
|
// Drain connection pools when configuration is changed
|
|
122
125
|
if (datasource.source) {
|
|
@@ -135,15 +138,18 @@ exports.save = function (ctx) {
|
|
|
135
138
|
exports.destroy = function (ctx) {
|
|
136
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
140
|
const db = getAppDB();
|
|
141
|
+
const datasourceId = ctx.params.datasourceId;
|
|
142
|
+
const datasource = yield db.get(datasourceId);
|
|
138
143
|
// Delete all queries for the datasource
|
|
139
|
-
const queries = yield db.allDocs(getQueryParams(
|
|
144
|
+
const queries = yield db.allDocs(getQueryParams(datasourceId, null));
|
|
140
145
|
yield db.bulkDocs(queries.rows.map(row => ({
|
|
141
146
|
_id: row.id,
|
|
142
147
|
_rev: row.value.rev,
|
|
143
148
|
_deleted: true,
|
|
144
149
|
})));
|
|
145
150
|
// delete the datasource
|
|
146
|
-
yield db.remove(
|
|
151
|
+
yield db.remove(datasourceId, ctx.params.revId);
|
|
152
|
+
yield events.datasource.deleted(datasource);
|
|
147
153
|
ctx.message = `Datasource deleted.`;
|
|
148
154
|
ctx.status = 200;
|
|
149
155
|
});
|
|
@@ -20,6 +20,7 @@ const utils_2 = require("../../../automations/utils");
|
|
|
20
20
|
const cache_1 = require("@budibase/backend-core/cache");
|
|
21
21
|
const context_1 = require("@budibase/backend-core/context");
|
|
22
22
|
const pro_1 = require("@budibase/pro");
|
|
23
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
23
24
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
24
25
|
const MAX_PENDING_TIME_MS = 30 * 60000;
|
|
25
26
|
const DeploymentStatus = {
|
|
@@ -113,6 +114,7 @@ function deployApp(deployment) {
|
|
|
113
114
|
console.log("Deployed app initialised, setting deployment to successful");
|
|
114
115
|
deployment.setStatus(DeploymentStatus.SUCCESS);
|
|
115
116
|
yield storeDeploymentHistory(deployment);
|
|
117
|
+
return appDoc;
|
|
116
118
|
}
|
|
117
119
|
catch (err) {
|
|
118
120
|
deployment.setStatus(DeploymentStatus.FAILURE, err.message);
|
|
@@ -178,12 +180,14 @@ const _deployApp = function (ctx) {
|
|
|
178
180
|
deployment = yield storeDeploymentHistory(deployment);
|
|
179
181
|
console.log("Stored deployment history");
|
|
180
182
|
console.log("Deploying app...");
|
|
183
|
+
let app;
|
|
181
184
|
if (yield isFirstDeploy()) {
|
|
182
|
-
yield pro_1.quotas.addPublishedApp(() => deployApp(deployment));
|
|
185
|
+
app = yield pro_1.quotas.addPublishedApp(() => deployApp(deployment));
|
|
183
186
|
}
|
|
184
187
|
else {
|
|
185
|
-
yield deployApp(deployment);
|
|
188
|
+
app = yield deployApp(deployment);
|
|
186
189
|
}
|
|
190
|
+
yield backend_core_1.events.app.published(app);
|
|
187
191
|
ctx.body = deployment;
|
|
188
192
|
});
|
|
189
193
|
};
|
|
@@ -17,6 +17,7 @@ const { Replication, getProdAppID } = require("@budibase/backend-core/db");
|
|
|
17
17
|
const { DocumentTypes } = require("../../db/utils");
|
|
18
18
|
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
19
19
|
const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context");
|
|
20
|
+
const { events } = require("@budibase/backend-core");
|
|
20
21
|
function redirect(ctx, method, path = "global") {
|
|
21
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
23
|
const { devPath } = ctx.params;
|
|
@@ -98,7 +99,10 @@ exports.revert = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
98
99
|
target: appId,
|
|
99
100
|
});
|
|
100
101
|
try {
|
|
101
|
-
|
|
102
|
+
if (!env.isTest()) {
|
|
103
|
+
// in-memory db stalls on rollback
|
|
104
|
+
yield replication.rollback();
|
|
105
|
+
}
|
|
102
106
|
// update appID in reverted app to be dev version again
|
|
103
107
|
const db = getAppDB();
|
|
104
108
|
const appDoc = yield db.get(DocumentTypes.APP_METADATA);
|
|
@@ -109,6 +113,7 @@ exports.revert = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
109
113
|
ctx.body = {
|
|
110
114
|
message: "Reverted changes successfully.",
|
|
111
115
|
};
|
|
116
|
+
yield events.app.reverted(appDoc);
|
|
112
117
|
}
|
|
113
118
|
catch (err) {
|
|
114
119
|
ctx.throw(400, `Unable to revert. ${err}`);
|
|
@@ -118,7 +123,9 @@ exports.revert = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
118
123
|
}
|
|
119
124
|
});
|
|
120
125
|
exports.getBudibaseVersion = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
+
const version = require("../../../package.json").version;
|
|
121
127
|
ctx.body = {
|
|
122
|
-
version
|
|
128
|
+
version,
|
|
123
129
|
};
|
|
130
|
+
yield events.installation.versionChecked(version);
|
|
124
131
|
});
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const { EMPTY_LAYOUT, BASE_LAYOUT_PROP_IDS, } = require("../../constants/layouts");
|
|
12
12
|
const { generateLayoutID, getScreenParams } = require("../../db/utils");
|
|
13
13
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
|
+
const { events } = require("@budibase/backend-core");
|
|
14
15
|
exports.save = function (ctx) {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
17
|
const db = getAppDB();
|
|
@@ -21,6 +22,7 @@ exports.save = function (ctx) {
|
|
|
21
22
|
}
|
|
22
23
|
layout._id = layout._id || generateLayoutID();
|
|
23
24
|
const response = yield db.put(layout);
|
|
25
|
+
yield events.layout.created(layout);
|
|
24
26
|
layout._rev = response.rev;
|
|
25
27
|
ctx.body = layout;
|
|
26
28
|
ctx.status = 200;
|
|
@@ -42,6 +44,7 @@ exports.destroy = function (ctx) {
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
yield db.remove(layoutId, layoutRev);
|
|
47
|
+
yield events.layout.deleted(layoutId);
|
|
45
48
|
ctx.body = { message: "Layout deleted successfully" };
|
|
46
49
|
ctx.status = 200;
|
|
47
50
|
});
|
|
@@ -17,6 +17,7 @@ const openapi3_1 = require("./sources/openapi3");
|
|
|
17
17
|
const curl_1 = require("./sources/curl");
|
|
18
18
|
// @ts-ignore
|
|
19
19
|
const context_1 = require("@budibase/backend-core/context");
|
|
20
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
20
21
|
class RestImporter {
|
|
21
22
|
constructor(data) {
|
|
22
23
|
this.init = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -31,7 +32,7 @@ class RestImporter {
|
|
|
31
32
|
return this.source.getInfo();
|
|
32
33
|
});
|
|
33
34
|
this.importQueries = (datasourceId) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
//
|
|
35
|
+
// construct the queries
|
|
35
36
|
let queries = yield this.source.getQueries(datasourceId);
|
|
36
37
|
// validate queries
|
|
37
38
|
const errorQueries = [];
|
|
@@ -66,9 +67,18 @@ class RestImporter {
|
|
|
66
67
|
delete queryIndex[query.id];
|
|
67
68
|
}
|
|
68
69
|
});
|
|
70
|
+
const successQueries = Object.values(queryIndex);
|
|
71
|
+
// events
|
|
72
|
+
const count = successQueries.length;
|
|
73
|
+
const importSource = this.source.getImportSource();
|
|
74
|
+
const datasource = yield db.get(datasourceId);
|
|
75
|
+
yield backend_core_1.events.query.imported(datasource, importSource, count);
|
|
76
|
+
for (let query of successQueries) {
|
|
77
|
+
yield backend_core_1.events.query.created(datasource, query);
|
|
78
|
+
}
|
|
69
79
|
return {
|
|
70
80
|
errorQueries,
|
|
71
|
-
queries:
|
|
81
|
+
queries: successQueries,
|
|
72
82
|
};
|
|
73
83
|
});
|
|
74
84
|
this.data = data;
|
|
@@ -19,6 +19,7 @@ const utils_2 = require("../../../threads/utils");
|
|
|
19
19
|
const environment_1 = require("../../../environment");
|
|
20
20
|
const context_1 = require("@budibase/backend-core/context");
|
|
21
21
|
const pro_1 = require("@budibase/pro");
|
|
22
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
22
23
|
const Runner = new threads_1.Thread(threads_1.ThreadType.QUERY, {
|
|
23
24
|
timeoutMs: environment_1.QUERY_THREAD_TIMEOUT || 10000,
|
|
24
25
|
});
|
|
@@ -80,10 +81,17 @@ function save(ctx) {
|
|
|
80
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
82
|
const db = (0, context_1.getAppDB)();
|
|
82
83
|
const query = ctx.request.body;
|
|
84
|
+
const datasource = yield db.get(query.datasourceId);
|
|
85
|
+
let eventFn;
|
|
83
86
|
if (!query._id) {
|
|
84
87
|
query._id = (0, utils_1.generateQueryID)(query.datasourceId);
|
|
88
|
+
eventFn = () => backend_core_1.events.query.created(datasource, query);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
eventFn = () => backend_core_1.events.query.updated(datasource, query);
|
|
85
92
|
}
|
|
86
93
|
const response = yield db.put(query);
|
|
94
|
+
yield eventFn();
|
|
87
95
|
query._rev = response.rev;
|
|
88
96
|
ctx.body = query;
|
|
89
97
|
ctx.message = `Query ${query.name} saved successfully.`;
|
|
@@ -107,9 +115,10 @@ function preview(ctx) {
|
|
|
107
115
|
return __awaiter(this, void 0, void 0, function* () {
|
|
108
116
|
const db = (0, context_1.getAppDB)();
|
|
109
117
|
const datasource = yield db.get(ctx.request.body.datasourceId);
|
|
118
|
+
const query = ctx.request.body;
|
|
110
119
|
// preview may not have a queryId as it hasn't been saved, but if it does
|
|
111
120
|
// this stops dynamic variables from calling the same query
|
|
112
|
-
const { fields, parameters, queryVerb, transformer, queryId } =
|
|
121
|
+
const { fields, parameters, queryVerb, transformer, queryId } = query;
|
|
113
122
|
try {
|
|
114
123
|
const runFn = () => Runner.run({
|
|
115
124
|
appId: ctx.appId,
|
|
@@ -121,6 +130,7 @@ function preview(ctx) {
|
|
|
121
130
|
queryId,
|
|
122
131
|
});
|
|
123
132
|
const { rows, keys, info, extra } = yield pro_1.quotas.addQuery(runFn);
|
|
133
|
+
yield backend_core_1.events.query.previewed(datasource, query);
|
|
124
134
|
ctx.body = {
|
|
125
135
|
rows,
|
|
126
136
|
schemaFields: [...new Set(keys)],
|
|
@@ -202,10 +212,14 @@ const removeDynamicVariables = (queryId) => __awaiter(void 0, void 0, void 0, fu
|
|
|
202
212
|
function destroy(ctx) {
|
|
203
213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
204
214
|
const db = (0, context_1.getAppDB)();
|
|
205
|
-
|
|
215
|
+
const queryId = ctx.params.queryId;
|
|
216
|
+
yield removeDynamicVariables(queryId);
|
|
217
|
+
const query = yield db.get(queryId);
|
|
218
|
+
const datasource = yield db.get(query.datasourceId);
|
|
206
219
|
yield db.remove(ctx.params.queryId, ctx.params.revId);
|
|
207
220
|
ctx.message = `Query deleted.`;
|
|
208
221
|
ctx.status = 200;
|
|
222
|
+
yield backend_core_1.events.query.deleted(datasource, query);
|
|
209
223
|
});
|
|
210
224
|
}
|
|
211
225
|
exports.destroy = destroy;
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const { Role, getRole, isBuiltin, getAllRoles, } = require("@budibase/backend-core/roles");
|
|
12
12
|
const { generateRoleID, getUserMetadataParams, InternalTables, } = require("../../db/utils");
|
|
13
13
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
|
+
const { events } = require("@budibase/backend-core");
|
|
14
15
|
const UpdateRolesOptions = {
|
|
15
16
|
CREATED: "created",
|
|
16
17
|
REMOVED: "removed",
|
|
@@ -54,8 +55,10 @@ exports.save = function (ctx) {
|
|
|
54
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
56
|
const db = getAppDB();
|
|
56
57
|
let { _id, name, inherits, permissionId } = ctx.request.body;
|
|
58
|
+
let isCreate = false;
|
|
57
59
|
if (!_id) {
|
|
58
60
|
_id = generateRoleID();
|
|
61
|
+
isCreate = true;
|
|
59
62
|
}
|
|
60
63
|
else if (isBuiltin(_id)) {
|
|
61
64
|
ctx.throw(400, "Cannot update builtin roles.");
|
|
@@ -67,6 +70,12 @@ exports.save = function (ctx) {
|
|
|
67
70
|
role._rev = ctx.request.body._rev;
|
|
68
71
|
}
|
|
69
72
|
const result = yield db.put(role);
|
|
73
|
+
if (isCreate) {
|
|
74
|
+
yield events.role.created(role);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
yield events.role.updated(role);
|
|
78
|
+
}
|
|
70
79
|
yield updateRolesOnUserTable(db, _id, UpdateRolesOptions.CREATED);
|
|
71
80
|
role._rev = result.rev;
|
|
72
81
|
ctx.body = role;
|
|
@@ -77,6 +86,7 @@ exports.destroy = function (ctx) {
|
|
|
77
86
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
87
|
const db = getAppDB();
|
|
79
88
|
const roleId = ctx.params.roleId;
|
|
89
|
+
const role = yield db.get(roleId);
|
|
80
90
|
if (isBuiltin(roleId)) {
|
|
81
91
|
ctx.throw(400, "Cannot delete builtin role.");
|
|
82
92
|
}
|
|
@@ -89,6 +99,7 @@ exports.destroy = function (ctx) {
|
|
|
89
99
|
ctx.throw(400, "Cannot delete role when it is in use.");
|
|
90
100
|
}
|
|
91
101
|
yield db.remove(roleId, ctx.params.rev);
|
|
102
|
+
yield events.role.deleted(role);
|
|
92
103
|
yield updateRolesOnUserTable(db, ctx.params.roleId, UpdateRolesOptions.REMOVED);
|
|
93
104
|
ctx.message = `Role ${ctx.params.roleId} deleted successfully`;
|
|
94
105
|
ctx.status = 200;
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const { getScreenParams, generateScreenID } = require("../../db/utils");
|
|
12
12
|
const { AccessController } = require("@budibase/backend-core/roles");
|
|
13
13
|
const { getAppDB } = require("@budibase/backend-core/context");
|
|
14
|
+
const { events } = require("@budibase/backend-core");
|
|
14
15
|
exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
16
|
const db = getAppDB();
|
|
16
17
|
const screens = (yield db.allDocs(getScreenParams(null, {
|
|
@@ -21,16 +22,24 @@ exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
21
22
|
exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
23
|
const db = getAppDB();
|
|
23
24
|
let screen = ctx.request.body;
|
|
25
|
+
let eventFn;
|
|
24
26
|
if (!screen._id) {
|
|
25
27
|
screen._id = generateScreenID();
|
|
28
|
+
eventFn = events.screen.created;
|
|
26
29
|
}
|
|
27
30
|
const response = yield db.put(screen);
|
|
31
|
+
if (eventFn) {
|
|
32
|
+
yield eventFn(screen);
|
|
33
|
+
}
|
|
28
34
|
ctx.message = `Screen ${screen.name} saved.`;
|
|
29
35
|
ctx.body = Object.assign(Object.assign({}, screen), { _id: response.id, _rev: response.rev });
|
|
30
36
|
});
|
|
31
37
|
exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
38
|
const db = getAppDB();
|
|
33
|
-
|
|
39
|
+
const id = ctx.params.screenId;
|
|
40
|
+
const screen = yield db.get(id);
|
|
41
|
+
yield db.remove(id, ctx.params.screenRev);
|
|
42
|
+
yield events.screen.deleted(screen);
|
|
34
43
|
ctx.body = {
|
|
35
44
|
message: "Screen deleted successfully",
|
|
36
45
|
};
|