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