@budibase/server 2.0.39 → 2.0.40
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/__mocks__/mongodb.ts +1 -1
- package/__mocks__/node-fetch.ts +12 -2
- package/builder/assets/backups-default.8c011f1b.png +0 -0
- package/builder/assets/{index.e0ddd30b.css → index.442de33f.css} +2 -2
- package/builder/assets/{index.b20dee52.js → index.72aa3989.js} +340 -332
- package/builder/index.html +2 -2
- package/coverage/clover.xml +1125 -1250
- package/coverage/coverage-final.json +73 -77
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +79 -67
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +21 -21
- package/coverage/lcov-report/api/controllers/index.html +17 -47
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +13 -13
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/index.html +16 -16
- package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
- package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +3 -3
- package/coverage/lcov-report/api/controllers/view/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -8
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +30 -30
- package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/automation.js.html +11 -11
- 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 +5 -35
- 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 +45 -45
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
- package/coverage/lcov-report/automations/bullboard.js.html +24 -84
- package/coverage/lcov-report/automations/index.html +21 -21
- package/coverage/lcov-report/automations/index.js.html +9 -9
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +15 -15
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
- package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +49 -49
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +10 -28
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +19 -19
- package/coverage/lcov-report/db/index.js.html +1 -1
- 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 +28 -28
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +37 -316
- 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 +3 -3
- package/coverage/lcov-report/events/utils.js.html +9 -9
- package/coverage/lcov-report/index.html +88 -88
- 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 +19 -19
- 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 +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
- package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +15 -12
- package/coverage/lcov-report/utilities/global.js.html +31 -31
- package/coverage/lcov-report/utilities/index.html +28 -28
- package/coverage/lcov-report/utilities/index.js.html +8 -8
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
- package/coverage/lcov-report/utilities/queue/index.html +21 -21
- 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 +72 -57
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
- package/coverage/lcov.info +1691 -1899
- package/dist/api/controllers/application.js +4 -7
- package/dist/api/controllers/backup.js +19 -13
- package/dist/api/controllers/cloud.js +38 -35
- package/dist/api/controllers/deploy/index.js +11 -2
- package/dist/api/controllers/dev.js +1 -1
- package/dist/api/controllers/query/index.js +7 -2
- package/dist/api/controllers/row/index.js +40 -66
- package/dist/api/controllers/row/internal.js +1 -1
- package/dist/api/controllers/static/index.js +3 -2
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/dist/api/controllers/static/templates/preview.hbs +10 -0
- package/dist/api/controllers/table/bulkFormula.js +4 -3
- package/dist/api/controllers/table/external.js +5 -4
- package/dist/api/controllers/table/index.js +4 -4
- package/dist/api/controllers/table/internal.js +10 -3
- package/dist/api/controllers/table/utils.js +7 -49
- package/dist/api/controllers/view/index.js +2 -2
- package/dist/api/controllers/webhook.js +88 -89
- package/dist/api/routes/backup.js +34 -7
- package/dist/api/routes/index.js +9 -4
- package/dist/api/routes/utils/validators.js +2 -2
- package/dist/api/routes/webhook.js +39 -11
- package/dist/app.js +2 -68
- package/dist/automations/automationUtils.js +2 -2
- package/dist/automations/bullboard.js +12 -35
- package/dist/automations/index.js +4 -4
- package/dist/automations/steps/updateRow.js +2 -2
- package/dist/automations/triggers.js +6 -6
- package/dist/automations/utils.js +23 -49
- package/dist/constants/index.js +4 -8
- package/dist/db/utils.js +10 -75
- package/dist/index.js +1 -0
- package/dist/integrations/arangodb.js +2 -0
- package/dist/integrations/base/sqlTable.js +1 -0
- package/dist/integrations/mongodb.js +300 -11
- package/dist/integrations/rest.js +38 -5
- package/dist/migrations/functions/backfill/app/tables.js +5 -8
- package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
- package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
- package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
- package/dist/migrations/index.js +10 -38
- package/dist/package.json +14 -14
- package/dist/sdk/app/automations/index.js +29 -0
- package/dist/sdk/app/automations/webhook.js +54 -0
- package/dist/sdk/app/backups/constants.js +5 -0
- package/dist/sdk/app/backups/exports.js +172 -0
- package/dist/sdk/app/backups/imports.js +190 -0
- package/dist/sdk/app/backups/index.js +29 -0
- package/dist/sdk/app/backups/statistics.js +73 -0
- package/dist/sdk/app/tables/index.js +61 -0
- package/dist/sdk/index.js +17 -0
- package/dist/startup.js +152 -0
- package/dist/tests/utilities/TestConfiguration.js +12 -2
- package/dist/threads/automation.js +12 -17
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +1 -0
- package/dist/utilities/fileSystem/index.js +3 -95
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/rowProcessor/index.js +5 -0
- package/dist/utilities/usageQuota/rows.js +6 -4
- package/package.json +15 -15
- package/specs/openapi.json +3 -0
- package/specs/openapi.yaml +3 -0
- package/src/api/controllers/application.ts +5 -12
- package/src/api/controllers/{backup.js → backup.ts} +7 -7
- package/src/api/controllers/cloud.js +44 -40
- package/src/api/controllers/deploy/index.ts +20 -8
- package/src/api/controllers/dev.js +1 -1
- package/src/api/controllers/query/index.ts +8 -2
- package/src/api/controllers/row/index.ts +50 -65
- package/src/api/controllers/row/internal.js +1 -1
- package/src/api/controllers/static/index.ts +4 -2
- package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/src/api/controllers/static/templates/preview.hbs +10 -0
- package/src/api/controllers/table/bulkFormula.js +4 -3
- package/src/api/controllers/table/external.js +4 -4
- package/src/api/controllers/table/index.js +4 -4
- package/src/api/controllers/table/internal.ts +8 -9
- package/src/api/controllers/table/utils.ts +4 -53
- package/src/api/controllers/view/index.js +2 -2
- package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
- package/src/api/routes/backup.ts +10 -0
- package/src/api/routes/index.ts +11 -5
- package/src/api/routes/tests/backup.spec.js +1 -1
- package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
- package/src/api/routes/tests/row.spec.js +22 -27
- package/src/api/routes/utils/validators.js +2 -2
- package/src/api/routes/{webhook.js → webhook.ts} +7 -6
- package/src/app.ts +3 -91
- package/src/automations/automationUtils.js +2 -2
- package/src/automations/bullboard.js +14 -34
- package/src/automations/index.js +4 -4
- package/src/automations/steps/updateRow.js +2 -2
- package/src/automations/tests/automation.spec.js +1 -6
- package/src/automations/triggers.js +6 -6
- package/src/automations/utils.ts +30 -32
- package/src/constants/index.js +4 -10
- package/src/db/utils.js +17 -110
- package/src/definitions/automations.ts +1 -18
- package/src/definitions/datasource.ts +1 -0
- package/src/index.ts +1 -0
- package/src/integrations/arangodb.ts +2 -0
- package/src/integrations/base/sqlTable.ts +1 -0
- package/src/integrations/mongodb.ts +290 -27
- package/src/integrations/rest.ts +17 -5
- package/src/integrations/tests/mongo.spec.ts +19 -19
- package/src/integrations/tests/rest.spec.ts +38 -22
- package/src/migrations/functions/backfill/app/tables.ts +7 -13
- package/src/migrations/functions/backfill/global.ts +1 -1
- package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
- package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +6 -5
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
- package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
- package/src/migrations/index.ts +21 -45
- package/src/migrations/tests/index.spec.ts +0 -1
- package/src/sdk/app/automations/index.ts +5 -0
- package/src/sdk/app/automations/webhook.ts +43 -0
- package/src/sdk/app/backups/constants.ts +2 -0
- package/src/sdk/app/backups/exports.ts +171 -0
- package/src/sdk/app/backups/imports.ts +206 -0
- package/src/sdk/app/backups/index.ts +9 -0
- package/src/sdk/app/backups/statistics.ts +78 -0
- package/src/sdk/app/tables/index.ts +61 -0
- package/src/sdk/index.ts +15 -0
- package/src/startup.ts +138 -0
- package/src/tests/utilities/TestConfiguration.js +12 -2
- package/src/threads/automation.ts +20 -27
- package/src/utilities/csvParser.js +1 -0
- package/src/utilities/fileSystem/index.js +2 -119
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/src/utilities/rowProcessor/index.js +5 -0
- package/src/utilities/usageQuota/rows.js +7 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
- package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
- package/coverage/lcov-report/api/routes/backup.js.html +0 -115
- package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
- package/dist/automations/listeners.js +0 -102
- package/src/api/routes/backup.js +0 -10
- package/src/automations/listeners.ts +0 -78
- package/src/migrations/functions/pluginCount.ts +0 -12
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const context_1 = require("@budibase/backend-core/context");
|
|
13
|
+
const utils_1 = require("../../../db/utils");
|
|
14
|
+
const utils_2 = require("../../../integrations/utils");
|
|
15
|
+
function getAllInternalTables(db) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (!db) {
|
|
18
|
+
db = (0, context_1.getAppDB)();
|
|
19
|
+
}
|
|
20
|
+
const internalTables = yield db.allDocs((0, utils_1.getTableParams)(null, {
|
|
21
|
+
include_docs: true,
|
|
22
|
+
}));
|
|
23
|
+
return internalTables.rows.map((tableDoc) => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: utils_1.BudibaseInternalDB._id })));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function getAllExternalTables(datasourceId) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const db = (0, context_1.getAppDB)();
|
|
29
|
+
const datasource = yield db.get(datasourceId);
|
|
30
|
+
if (!datasource || !datasource.entities) {
|
|
31
|
+
throw "Datasource is not configured fully.";
|
|
32
|
+
}
|
|
33
|
+
return datasource.entities;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function getExternalTable(datasourceId, tableName) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const entities = yield getAllExternalTables(datasourceId);
|
|
39
|
+
return entities[tableName];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function getTable(tableId) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const db = (0, context_1.getAppDB)();
|
|
45
|
+
if ((0, utils_2.isExternalTable)(tableId)) {
|
|
46
|
+
let { datasourceId, tableName } = (0, utils_2.breakExternalTableId)(tableId);
|
|
47
|
+
const datasource = yield db.get(datasourceId);
|
|
48
|
+
const table = yield getExternalTable(datasourceId, tableName);
|
|
49
|
+
return Object.assign(Object.assign({}, table), { sql: (0, utils_2.isSQL)(datasource) });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return db.get(tableId);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.default = {
|
|
57
|
+
getAllInternalTables,
|
|
58
|
+
getAllExternalTables,
|
|
59
|
+
getExternalTable,
|
|
60
|
+
getTable,
|
|
61
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const backups_1 = __importDefault(require("./app/backups"));
|
|
7
|
+
const tables_1 = __importDefault(require("./app/tables"));
|
|
8
|
+
const automations_1 = __importDefault(require("./app/automations"));
|
|
9
|
+
const sdk = {
|
|
10
|
+
backups: backups_1.default,
|
|
11
|
+
tables: tables_1.default,
|
|
12
|
+
automations: automations_1.default,
|
|
13
|
+
};
|
|
14
|
+
// default export for TS
|
|
15
|
+
exports.default = sdk;
|
|
16
|
+
// default export for JS
|
|
17
|
+
module.exports = sdk;
|
package/dist/startup.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.startup = void 0;
|
|
39
|
+
const env = __importStar(require("./environment"));
|
|
40
|
+
const redis_1 = __importDefault(require("./utilities/redis"));
|
|
41
|
+
const workerRequests_1 = require("./utilities/workerRequests");
|
|
42
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
43
|
+
const fs_1 = __importDefault(require("fs"));
|
|
44
|
+
const watch_1 = require("./watch");
|
|
45
|
+
const automations_1 = __importDefault(require("./automations"));
|
|
46
|
+
const fileSystem_1 = __importDefault(require("./utilities/fileSystem"));
|
|
47
|
+
const events_1 = __importDefault(require("./events"));
|
|
48
|
+
const migrations = __importStar(require("./migrations"));
|
|
49
|
+
const bullboard_1 = __importDefault(require("./automations/bullboard"));
|
|
50
|
+
const pro = __importStar(require("@budibase/pro"));
|
|
51
|
+
const api_1 = __importDefault(require("./api"));
|
|
52
|
+
const sdk_1 = __importDefault(require("./sdk"));
|
|
53
|
+
const pino = require("koa-pino-logger");
|
|
54
|
+
let STARTUP_RAN = false;
|
|
55
|
+
function initRoutes(app) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
app.use(pino((0, backend_core_1.pinoSettings)()));
|
|
58
|
+
if (!env.isTest()) {
|
|
59
|
+
const plugin = yield bullboard_1.default.init();
|
|
60
|
+
app.use(plugin);
|
|
61
|
+
}
|
|
62
|
+
app.context.eventEmitter = events_1.default;
|
|
63
|
+
app.context.auth = {};
|
|
64
|
+
// api routes
|
|
65
|
+
app.use(api_1.default.router.routes());
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function initPro() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
yield pro.init({
|
|
71
|
+
backups: {
|
|
72
|
+
processing: {
|
|
73
|
+
exportAppFn: sdk_1.default.backups.exportApp,
|
|
74
|
+
importAppFn: sdk_1.default.backups.importApp,
|
|
75
|
+
statsFn: sdk_1.default.backups.calculateBackupStats,
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function shutdown(server) {
|
|
82
|
+
server.close();
|
|
83
|
+
server.destroy();
|
|
84
|
+
}
|
|
85
|
+
function startup(app, server) {
|
|
86
|
+
var _a;
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
if (STARTUP_RAN) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
STARTUP_RAN = true;
|
|
92
|
+
if (server) {
|
|
93
|
+
console.log(`Budibase running on ${JSON.stringify(server.address())}`);
|
|
94
|
+
env._set("PORT", server.address().port);
|
|
95
|
+
}
|
|
96
|
+
events_1.default.emitPort(env.PORT);
|
|
97
|
+
fileSystem_1.default.init();
|
|
98
|
+
yield redis_1.default.init();
|
|
99
|
+
// run migrations on startup if not done via http
|
|
100
|
+
// not recommended in a clustered environment
|
|
101
|
+
if (!env.HTTP_MIGRATIONS && !env.isTest()) {
|
|
102
|
+
try {
|
|
103
|
+
yield migrations.migrate();
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
backend_core_1.logging.logAlert("Error performing migrations. Exiting.", e);
|
|
107
|
+
shutdown();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// check and create admin user if required
|
|
111
|
+
if (env.SELF_HOSTED &&
|
|
112
|
+
!env.MULTI_TENANCY &&
|
|
113
|
+
env.BB_ADMIN_USER_EMAIL &&
|
|
114
|
+
env.BB_ADMIN_USER_PASSWORD) {
|
|
115
|
+
const checklist = yield (0, workerRequests_1.getChecklist)();
|
|
116
|
+
if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
|
|
117
|
+
try {
|
|
118
|
+
const tenantId = backend_core_1.tenancy.getTenantId();
|
|
119
|
+
const user = yield (0, workerRequests_1.createAdminUser)(env.BB_ADMIN_USER_EMAIL, env.BB_ADMIN_USER_PASSWORD, tenantId);
|
|
120
|
+
// Need to set up an API key for automated integration tests
|
|
121
|
+
if (env.isTest()) {
|
|
122
|
+
yield (0, workerRequests_1.generateApiKey)(user._id);
|
|
123
|
+
}
|
|
124
|
+
console.log("Admin account automatically created for", env.BB_ADMIN_USER_EMAIL);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
backend_core_1.logging.logAlert("Error creating initial admin user. Exiting.", e);
|
|
128
|
+
shutdown();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// monitor plugin directory if required
|
|
133
|
+
if (env.SELF_HOSTED &&
|
|
134
|
+
!env.MULTI_TENANCY &&
|
|
135
|
+
env.PLUGINS_DIR &&
|
|
136
|
+
fs_1.default.existsSync(env.PLUGINS_DIR)) {
|
|
137
|
+
(0, watch_1.watch)();
|
|
138
|
+
}
|
|
139
|
+
// check for version updates
|
|
140
|
+
yield backend_core_1.installation.checkInstallVersion();
|
|
141
|
+
// get the references to the queue promises, don't await as
|
|
142
|
+
// they will never end, unless the processing stops
|
|
143
|
+
let queuePromises = [];
|
|
144
|
+
queuePromises.push(automations_1.default.init());
|
|
145
|
+
queuePromises.push(initPro());
|
|
146
|
+
if (app) {
|
|
147
|
+
// bring routes online as final step once everything ready
|
|
148
|
+
yield initRoutes(app);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
exports.startup = startup;
|
|
@@ -24,7 +24,8 @@ const newid = require("../../db/newid");
|
|
|
24
24
|
const context = require("@budibase/backend-core/context");
|
|
25
25
|
const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db");
|
|
26
26
|
const { encrypt } = require("@budibase/backend-core/encryption");
|
|
27
|
-
const { DocumentType } = require("../../db/utils");
|
|
27
|
+
const { DocumentType, generateUserMetadataID } = require("../../db/utils");
|
|
28
|
+
const { startup } = require("../../startup");
|
|
28
29
|
const GLOBAL_USER_ID = "us_uuid1";
|
|
29
30
|
const EMAIL = "babs@babs.com";
|
|
30
31
|
const FIRSTNAME = "Barbara";
|
|
@@ -38,6 +39,10 @@ class TestConfiguration {
|
|
|
38
39
|
this.server = require("../../app");
|
|
39
40
|
// we need the request for logging in, involves cookies, hard to fake
|
|
40
41
|
this.request = supertest(this.server);
|
|
42
|
+
this.started = true;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.started = false;
|
|
41
46
|
}
|
|
42
47
|
this.appId = null;
|
|
43
48
|
this.allApps = [];
|
|
@@ -87,7 +92,12 @@ class TestConfiguration {
|
|
|
87
92
|
// use a new id as the name to avoid name collisions
|
|
88
93
|
init(appName = newid()) {
|
|
89
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
95
|
+
if (!this.started) {
|
|
96
|
+
yield startup();
|
|
97
|
+
}
|
|
98
|
+
this.user = yield this.globalUser();
|
|
99
|
+
this.globalUserId = this.user._id;
|
|
100
|
+
this.userMetadataId = generateUserMetadataID(this.globalUserId);
|
|
91
101
|
return this.createApp(appName);
|
|
92
102
|
});
|
|
93
103
|
}
|
|
@@ -72,16 +72,12 @@ function getLoopIterations(loopStep, input) {
|
|
|
72
72
|
* inputs and handles any outputs.
|
|
73
73
|
*/
|
|
74
74
|
class Orchestrator {
|
|
75
|
-
constructor(
|
|
75
|
+
constructor(job) {
|
|
76
|
+
let automation = job.data.automation, triggerOutput = job.data.event;
|
|
76
77
|
const metadata = triggerOutput.metadata;
|
|
77
78
|
this._chainCount = metadata ? metadata.automationChainCount : 0;
|
|
78
79
|
this._appId = triggerOutput.appId;
|
|
79
|
-
|
|
80
|
-
this._repeat = {
|
|
81
|
-
jobId: opts.repeat.jobId,
|
|
82
|
-
jobKey: opts.repeat.key,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
80
|
+
this._job = job;
|
|
85
81
|
const triggerStepId = automation.definition.trigger.stepId;
|
|
86
82
|
triggerOutput = this.cleanupTriggerOutputs(triggerStepId, triggerOutput);
|
|
87
83
|
// remove from context
|
|
@@ -131,15 +127,14 @@ class Orchestrator {
|
|
|
131
127
|
});
|
|
132
128
|
}
|
|
133
129
|
stopCron(reason) {
|
|
134
|
-
var _a, _b;
|
|
135
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
if (!this.
|
|
131
|
+
if (!this._job.opts.repeat) {
|
|
137
132
|
return;
|
|
138
133
|
}
|
|
139
134
|
logWarn(`CRON disabled reason=${reason} - ${this._appId}/${this._automation._id}`);
|
|
140
135
|
const automation = this._automation;
|
|
141
136
|
const trigger = automation.definition.trigger;
|
|
142
|
-
yield (0, utils_2.
|
|
137
|
+
yield (0, utils_2.disableCronById)(this._job.id);
|
|
143
138
|
this.updateExecutionOutput(trigger.id, trigger.stepId, {}, {
|
|
144
139
|
status: types_1.AutomationStatus.STOPPED_ERROR,
|
|
145
140
|
success: false,
|
|
@@ -149,7 +144,7 @@ class Orchestrator {
|
|
|
149
144
|
}
|
|
150
145
|
checkIfShouldStop(metadata) {
|
|
151
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
if (!metadata.errorCount || !this.
|
|
147
|
+
if (!metadata.errorCount || !this._job.opts.repeat) {
|
|
153
148
|
return false;
|
|
154
149
|
}
|
|
155
150
|
if (metadata.errorCount >= constants_1.MAX_AUTOMATION_RECURRING_ERRORS) {
|
|
@@ -404,13 +399,13 @@ class Orchestrator {
|
|
|
404
399
|
});
|
|
405
400
|
}
|
|
406
401
|
}
|
|
407
|
-
function execute(
|
|
408
|
-
const appId =
|
|
402
|
+
function execute(job, callback) {
|
|
403
|
+
const appId = job.data.event.appId;
|
|
409
404
|
if (!appId) {
|
|
410
405
|
throw new Error("Unable to execute, event doesn't contain app ID.");
|
|
411
406
|
}
|
|
412
407
|
doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
413
|
-
const automationOrchestrator = new Orchestrator(
|
|
408
|
+
const automationOrchestrator = new Orchestrator(job);
|
|
414
409
|
try {
|
|
415
410
|
const response = yield automationOrchestrator.execute();
|
|
416
411
|
callback(null, response);
|
|
@@ -421,13 +416,13 @@ function execute(input, callback) {
|
|
|
421
416
|
}));
|
|
422
417
|
}
|
|
423
418
|
exports.execute = execute;
|
|
424
|
-
const removeStalled = (
|
|
425
|
-
const appId =
|
|
419
|
+
const removeStalled = (job) => __awaiter(void 0, void 0, void 0, function* () {
|
|
420
|
+
const appId = job.data.event.appId;
|
|
426
421
|
if (!appId) {
|
|
427
422
|
throw new Error("Unable to execute, event doesn't contain app ID.");
|
|
428
423
|
}
|
|
429
424
|
yield doInAppContext(appId, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
430
|
-
const automationOrchestrator = new Orchestrator(
|
|
425
|
+
const automationOrchestrator = new Orchestrator(job);
|
|
431
426
|
yield automationOrchestrator.stopCron("stalled");
|
|
432
427
|
}));
|
|
433
428
|
});
|