@budibase/server 2.0.34-alpha.0 → 2.0.34-alpha.10
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__/node-fetch.ts +12 -2
- package/builder/assets/{index.d09d1931.js → index.02132811.js} +113 -113
- package/builder/index.html +1 -1
- package/coverage/clover.xml +430 -500
- package/coverage/coverage-final.json +49 -51
- 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 +13 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +20 -20
- package/coverage/lcov-report/api/controllers/index.html +9 -24
- 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 +2 -2
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +26 -26
- 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 -20
- 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 +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +25 -10
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +4 -4
- 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 +1 -1
- 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 +27 -27
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +4 -16
- 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 +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +1 -1
- package/coverage/lcov-report/db/utils.js.html +2 -2
- 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 +2 -2
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +52 -52
- 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 +9 -9
- package/coverage/lcov-report/middleware/currentapp.js.html +14 -14
- 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 +22 -22
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +3 -3
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +20 -20
- package/coverage/lcov-report/utilities/index.js.html +2 -2
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- 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 +1 -1
- 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 +498 -601
- package/dist/api/controllers/row/index.js +34 -80
- package/dist/api/controllers/row/internal.js +1 -1
- package/dist/api/controllers/static/index.js +1 -0
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/dist/api/controllers/webhook.js +88 -89
- package/dist/api/routes/utils/validators.js +2 -2
- package/dist/api/routes/webhook.js +39 -11
- package/dist/app.js +2 -82
- package/dist/automations/bullboard.js +7 -2
- package/dist/automations/triggers.js +2 -2
- package/dist/automations/utils.js +5 -37
- package/dist/constants/index.js +0 -3
- package/dist/migrations/index.js +2 -1
- package/dist/package.json +6 -6
- package/dist/sdk/app/automations/index.js +29 -0
- package/dist/sdk/app/automations/webhook.js +54 -0
- package/dist/sdk/app/backups/imports.js +29 -1
- package/dist/sdk/index.js +2 -0
- package/dist/startup.js +152 -0
- package/dist/tests/utilities/TestConfiguration.js +8 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/api/controllers/row/index.ts +42 -80
- package/src/api/controllers/row/internal.js +1 -1
- package/src/api/controllers/static/index.ts +2 -0
- package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
- package/src/api/routes/utils/validators.js +2 -2
- package/src/api/routes/{webhook.js → webhook.ts} +7 -6
- package/src/app.ts +3 -106
- package/src/automations/bullboard.js +6 -1
- package/src/automations/triggers.js +2 -2
- package/src/automations/utils.ts +12 -20
- package/src/constants/index.js +0 -4
- package/src/definitions/automations.ts +1 -6
- package/src/migrations/functions/tests/syncQuotas.spec.js +1 -3
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
- package/src/migrations/index.ts +1 -0
- package/src/sdk/app/automations/index.ts +5 -0
- package/src/sdk/app/automations/webhook.ts +43 -0
- package/src/sdk/app/backups/imports.ts +43 -6
- package/src/sdk/index.ts +2 -0
- package/src/startup.ts +138 -0
- package/src/tests/utilities/TestConfiguration.js +7 -0
- package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
- package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
|
@@ -1,27 +1,4 @@
|
|
|
1
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
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -38,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
38
15
|
exports.isErrorInOutput = exports.isRecurring = exports.cleanupAutomations = exports.checkForWebhooks = exports.enableCronTrigger = exports.isRebootTrigger = exports.isCronTrigger = exports.clearMetadata = exports.disableCronById = exports.disableAllCrons = exports.removeDeprecated = exports.updateTestHistory = exports.processEvent = void 0;
|
|
39
16
|
const threads_1 = require("../threads");
|
|
40
17
|
const triggerInfo_1 = require("./triggerInfo");
|
|
41
|
-
const webhooks = __importStar(require("../api/controllers/webhook"));
|
|
42
18
|
const bullboard_1 = require("./bullboard");
|
|
43
19
|
const newid_1 = __importDefault(require("../db/newid"));
|
|
44
20
|
const utilities_1 = require("../utilities");
|
|
@@ -49,6 +25,8 @@ const fp_1 = require("lodash/fp");
|
|
|
49
25
|
const context_1 = require("@budibase/backend-core/context");
|
|
50
26
|
const backend_core_1 = require("@budibase/backend-core");
|
|
51
27
|
const pro_1 = require("@budibase/pro");
|
|
28
|
+
const types_1 = require("@budibase/types");
|
|
29
|
+
const sdk_1 = __importDefault(require("../sdk"));
|
|
52
30
|
const REBOOT_CRON = "@reboot";
|
|
53
31
|
const WH_STEP_ID = triggerInfo_1.definitions.WEBHOOK.stepId;
|
|
54
32
|
const CRON_STEP_ID = triggerInfo_1.definitions.CRON.stepId;
|
|
@@ -217,16 +195,12 @@ function checkForWebhooks({ oldAuto, newAuto }) {
|
|
|
217
195
|
let db = (0, context_1.getAppDB)();
|
|
218
196
|
// need to get the webhook to get the rev
|
|
219
197
|
const webhook = yield db.get(oldTrigger.webhookId);
|
|
220
|
-
const ctx = {
|
|
221
|
-
appId,
|
|
222
|
-
params: { id: webhook._id, rev: webhook._rev },
|
|
223
|
-
};
|
|
224
198
|
// might be updating - reset the inputs to remove the URLs
|
|
225
199
|
if (newTrigger) {
|
|
226
200
|
delete newTrigger.webhookId;
|
|
227
201
|
newTrigger.inputs = {};
|
|
228
202
|
}
|
|
229
|
-
yield
|
|
203
|
+
yield sdk_1.default.automations.webhook.destroy(webhook._id, webhook._rev);
|
|
230
204
|
}
|
|
231
205
|
catch (err) {
|
|
232
206
|
// don't worry about not being able to delete, if it doesn't exist all good
|
|
@@ -235,14 +209,8 @@ function checkForWebhooks({ oldAuto, newAuto }) {
|
|
|
235
209
|
// need to create webhook
|
|
236
210
|
if ((!isWebhookTrigger(oldAuto) || triggerChanged) &&
|
|
237
211
|
isWebhookTrigger(newAuto)) {
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
request: {
|
|
241
|
-
body: new webhooks.Webhook("Automation webhook", constants_1.WebhookType.AUTOMATION, newAuto._id),
|
|
242
|
-
},
|
|
243
|
-
};
|
|
244
|
-
yield webhooks.save(ctx);
|
|
245
|
-
const id = ctx.body.webhook._id;
|
|
212
|
+
const webhook = yield sdk_1.default.automations.webhook.save(sdk_1.default.automations.webhook.newDoc("Automation webhook", types_1.WebhookActionType.AUTOMATION, newAuto._id));
|
|
213
|
+
const id = webhook._id;
|
|
246
214
|
newTrigger.webhookId = id;
|
|
247
215
|
// the app ID has to be development for this endpoint
|
|
248
216
|
// it can only be used when building the app
|
package/dist/constants/index.js
CHANGED
|
@@ -176,9 +176,6 @@ exports.BuildSchemaErrors = {
|
|
|
176
176
|
NO_KEY: "no_key",
|
|
177
177
|
INVALID_COLUMN: "invalid_column",
|
|
178
178
|
};
|
|
179
|
-
exports.WebhookType = {
|
|
180
|
-
AUTOMATION: "automation",
|
|
181
|
-
};
|
|
182
179
|
exports.AutomationErrors = {
|
|
183
180
|
INCORRECT_TYPE: "INCORRECT_TYPE",
|
|
184
181
|
MAX_ITERATIONS: "MAX_ITERATIONS_REACHED",
|
package/dist/migrations/index.js
CHANGED
|
@@ -98,7 +98,8 @@ const migrateWithLock = (options) => __awaiter(void 0, void 0, void 0, function*
|
|
|
98
98
|
yield backend_core_1.locks.doWithLock({
|
|
99
99
|
type: types_1.LockType.TRY_ONCE,
|
|
100
100
|
name: types_1.LockName.MIGRATIONS,
|
|
101
|
-
ttl: 1000 * 60 * 15,
|
|
101
|
+
ttl: 1000 * 60 * 15,
|
|
102
|
+
systemLock: true,
|
|
102
103
|
}, () => __awaiter(void 0, void 0, void 0, function* () {
|
|
103
104
|
yield backend_core_1.migrations.runMigrations(exports.MIGRATIONS, options);
|
|
104
105
|
}));
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.34-alpha.9",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -77,11 +77,11 @@
|
|
|
77
77
|
"license": "GPL-3.0",
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
80
|
-
"@budibase/backend-core": "
|
|
81
|
-
"@budibase/client": "
|
|
82
|
-
"@budibase/pro": "2.0.
|
|
83
|
-
"@budibase/string-templates": "
|
|
84
|
-
"@budibase/types": "
|
|
80
|
+
"@budibase/backend-core": "2.0.34-alpha.9",
|
|
81
|
+
"@budibase/client": "2.0.34-alpha.9",
|
|
82
|
+
"@budibase/pro": "2.0.34-alpha.9",
|
|
83
|
+
"@budibase/string-templates": "2.0.34-alpha.9",
|
|
84
|
+
"@budibase/types": "2.0.34-alpha.9",
|
|
85
85
|
"@bull-board/api": "3.7.0",
|
|
86
86
|
"@bull-board/koa": "3.9.4",
|
|
87
87
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const webhook = __importStar(require("./webhook"));
|
|
27
|
+
exports.default = {
|
|
28
|
+
webhook,
|
|
29
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
exports.destroy = exports.save = exports.newDoc = void 0;
|
|
13
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
14
|
+
const utils_1 = require("../../../db/utils");
|
|
15
|
+
function isWebhookID(id) {
|
|
16
|
+
return id.startsWith(backend_core_1.db.DocumentType.WEBHOOK);
|
|
17
|
+
}
|
|
18
|
+
function newDoc(name, type, target) {
|
|
19
|
+
return {
|
|
20
|
+
live: true,
|
|
21
|
+
name,
|
|
22
|
+
action: {
|
|
23
|
+
type,
|
|
24
|
+
target,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
exports.newDoc = newDoc;
|
|
29
|
+
function save(webhook) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const db = backend_core_1.context.getAppDB();
|
|
32
|
+
// check that the webhook exists
|
|
33
|
+
if (webhook._id && isWebhookID(webhook._id)) {
|
|
34
|
+
yield db.get(webhook._id);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
webhook._id = (0, utils_1.generateWebhookID)();
|
|
38
|
+
}
|
|
39
|
+
const response = yield db.put(webhook);
|
|
40
|
+
webhook._rev = response.rev;
|
|
41
|
+
return webhook;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.save = save;
|
|
45
|
+
function destroy(id, rev) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const db = backend_core_1.context.getAppDB();
|
|
48
|
+
if (!id || !isWebhookID(id)) {
|
|
49
|
+
throw new Error("Provided webhook ID is not valid.");
|
|
50
|
+
}
|
|
51
|
+
return yield db.remove(id, rev);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.destroy = destroy;
|
|
@@ -23,6 +23,7 @@ const constants_2 = require("../../../constants");
|
|
|
23
23
|
const path_1 = require("path");
|
|
24
24
|
const fs_1 = __importDefault(require("fs"));
|
|
25
25
|
const __1 = __importDefault(require("../../"));
|
|
26
|
+
const types_1 = require("@budibase/types");
|
|
26
27
|
const uuid = require("uuid/v4");
|
|
27
28
|
const tar = require("tar");
|
|
28
29
|
function updateAttachmentColumns(prodAppId, db) {
|
|
@@ -76,6 +77,28 @@ function updateAttachmentColumns(prodAppId, db) {
|
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
79
|
}
|
|
80
|
+
function updateAutomations(prodAppId, db) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const automations = (yield db.allDocs((0, utils_1.getAutomationParams)(null, {
|
|
83
|
+
include_docs: true,
|
|
84
|
+
}))).rows.map(row => row.doc);
|
|
85
|
+
const devAppId = backend_core_1.db.getDevAppID(prodAppId);
|
|
86
|
+
let toSave = [];
|
|
87
|
+
for (let automation of automations) {
|
|
88
|
+
const oldDevAppId = automation.appId, oldProdAppId = backend_core_1.db.getProdAppID(automation.appId);
|
|
89
|
+
if (automation.definition.trigger.stepId === types_1.AutomationTriggerStepId.WEBHOOK) {
|
|
90
|
+
const old = automation.definition.trigger.inputs;
|
|
91
|
+
automation.definition.trigger.inputs = {
|
|
92
|
+
schemaUrl: old.schemaUrl.replace(oldDevAppId, devAppId),
|
|
93
|
+
triggerUrl: old.triggerUrl.replace(oldProdAppId, prodAppId),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
automation.appId = devAppId;
|
|
97
|
+
toSave.push(automation);
|
|
98
|
+
}
|
|
99
|
+
yield db.bulkDocs(toSave);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
79
102
|
/**
|
|
80
103
|
* This function manages temporary template files which are stored by Koa.
|
|
81
104
|
* @param {Object} template The template object retrieved from the Koa context object.
|
|
@@ -83,6 +106,9 @@ function updateAttachmentColumns(prodAppId, db) {
|
|
|
83
106
|
*/
|
|
84
107
|
function getTemplateStream(template) {
|
|
85
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
if (template.file && template.file.type !== "text/plain") {
|
|
110
|
+
throw new Error("Cannot import a non-text based file.");
|
|
111
|
+
}
|
|
86
112
|
if (template.file) {
|
|
87
113
|
return fs_1.default.createReadStream(template.file.path);
|
|
88
114
|
}
|
|
@@ -114,10 +140,11 @@ function getListOfAppsInMulti(tmpPath) {
|
|
|
114
140
|
}
|
|
115
141
|
exports.getListOfAppsInMulti = getListOfAppsInMulti;
|
|
116
142
|
function importApp(appId, db, template) {
|
|
143
|
+
var _a, _b;
|
|
117
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
145
|
let prodAppId = backend_core_1.db.getProdAppID(appId);
|
|
119
146
|
let dbStream;
|
|
120
|
-
const isTar = template.file && template.file.type === "
|
|
147
|
+
const isTar = template.file && ((_b = (_a = template === null || template === void 0 ? void 0 : template.file) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.endsWith("gzip"));
|
|
121
148
|
const isDirectory = template.file && fs_1.default.lstatSync(template.file.path).isDirectory();
|
|
122
149
|
if (template.file && (isTar || isDirectory)) {
|
|
123
150
|
const tmpPath = isTar ? untarFile(template.file) : template.file.path;
|
|
@@ -156,6 +183,7 @@ function importApp(appId, db, template) {
|
|
|
156
183
|
throw "Error loading database dump from template.";
|
|
157
184
|
}
|
|
158
185
|
yield updateAttachmentColumns(prodAppId, db);
|
|
186
|
+
yield updateAutomations(prodAppId, db);
|
|
159
187
|
return ok;
|
|
160
188
|
});
|
|
161
189
|
}
|
package/dist/sdk/index.js
CHANGED
|
@@ -5,9 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const backups_1 = __importDefault(require("./app/backups"));
|
|
7
7
|
const tables_1 = __importDefault(require("./app/tables"));
|
|
8
|
+
const automations_1 = __importDefault(require("./app/automations"));
|
|
8
9
|
const sdk = {
|
|
9
10
|
backups: backups_1.default,
|
|
10
11
|
tables: tables_1.default,
|
|
12
|
+
automations: automations_1.default,
|
|
11
13
|
};
|
|
12
14
|
// default export for TS
|
|
13
15
|
exports.default = 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;
|
|
@@ -25,6 +25,7 @@ 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
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,6 +92,9 @@ 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* () {
|
|
95
|
+
if (!this.started) {
|
|
96
|
+
yield startup();
|
|
97
|
+
}
|
|
90
98
|
this.user = yield this.globalUser();
|
|
91
99
|
this.globalUserId = this.user._id;
|
|
92
100
|
this.userMetadataId = generateUserMetadataID(this.globalUserId);
|