@budibase/server 0.9.125-alpha.4 → 0.9.125-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/assets/{index.dc48c234.js → index.a6e64238.js} +1 -1
- package/builder/index.html +1 -1
- package/coverage/clover.xml +1659 -1493
- package/coverage/coverage-final.json +101 -87
- package/coverage/lcov-report/api/controllers/analytics.js.html +3 -3
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/application.js.html +39 -39
- package/coverage/lcov-report/api/controllers/auth.js.html +6 -6
- package/coverage/lcov-report/api/controllers/automation.js.html +151 -361
- package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +15 -15
- package/coverage/lcov-report/api/controllers/hosting.js.html +8 -8
- package/coverage/lcov-report/api/controllers/index.html +39 -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 +218 -0
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query.js.html +6 -12
- 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 +20 -20
- package/coverage/lcov-report/api/controllers/row/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/row/internal.js.html +95 -62
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +10 -10
- package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.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 +24 -24
- package/coverage/lcov-report/api/controllers/table/utils.js.html +32 -32
- package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
- 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/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +23 -23
- package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/application.js.html +8 -8
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +41 -26
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +13 -13
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +11 -11
- package/coverage/lcov-report/api/routes/hosting.js.html +8 -8
- package/coverage/lcov-report/api/routes/index.html +24 -9
- package/coverage/lcov-report/api/routes/index.js.html +36 -30
- 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 +194 -0
- package/coverage/lcov-report/api/routes/permission.js.html +12 -12
- package/coverage/lcov-report/api/routes/query.js.html +13 -13
- package/coverage/lcov-report/api/routes/role.js.html +12 -12
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/row.js.html +10 -10
- package/coverage/lcov-report/api/routes/screen.js.html +11 -11
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +13 -13
- package/coverage/lcov-report/api/routes/table.js.html +12 -12
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +9 -9
- package/coverage/lcov-report/api/routes/view.js.html +11 -11
- package/coverage/lcov-report/api/routes/webhook.js.html +11 -11
- package/coverage/lcov-report/automations/actions.js.html +38 -107
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +46 -16
- package/coverage/lcov-report/automations/index.html +67 -67
- package/coverage/lcov-report/automations/index.js.html +26 -128
- package/coverage/lcov-report/automations/steps/bash.js.html +33 -12
- package/coverage/lcov-report/automations/steps/createRow.js.html +8 -8
- package/coverage/lcov-report/automations/steps/delay.js.html +45 -6
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +8 -8
- package/coverage/lcov-report/automations/steps/discord.js.html +329 -0
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +19 -31
- package/coverage/lcov-report/automations/steps/executeScript.js.html +18 -30
- package/coverage/lcov-report/automations/steps/filter.js.html +22 -19
- package/coverage/lcov-report/automations/steps/index.html +125 -65
- package/coverage/lcov-report/automations/steps/integromat.js.html +341 -0
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +26 -32
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +9 -9
- package/coverage/lcov-report/automations/steps/serverLog.js.html +20 -8
- package/coverage/lcov-report/automations/steps/{sendgridEmail.js.html → slack.js.html} +57 -87
- package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/utils.js.html +188 -0
- package/coverage/lcov-report/automations/steps/zapier.js.html +332 -0
- package/coverage/lcov-report/automations/thread.js.html +79 -76
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +173 -0
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +173 -0
- package/coverage/lcov-report/automations/triggerInfo/index.html +201 -0
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +125 -0
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +176 -0
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +200 -0
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +200 -0
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +188 -0
- package/coverage/lcov-report/automations/triggers.js.html +54 -819
- package/coverage/lcov-report/automations/utils.js.html +557 -0
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +19 -4
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +2 -2
- package/coverage/lcov-report/db/client.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 +73 -73
- package/coverage/lcov-report/db/linkedRows/index.html +17 -17
- package/coverage/lcov-report/db/linkedRows/index.js.html +79 -115
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +31 -31
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +79 -28
- package/coverage/lcov-report/events/AutomationEmitter.js.html +7 -7
- 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 +115 -100
- 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/{automations/logic.js.html → middleware/appInfo.js.html} +35 -38
- package/coverage/lcov-report/middleware/authorized.js.html +16 -16
- package/coverage/lcov-report/middleware/builder.js.html +15 -15
- package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
- package/coverage/lcov-report/middleware/index.html +23 -8
- package/coverage/lcov-report/middleware/joi-validator.js.html +6 -6
- 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/usageQuota.js.html +8 -8
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +21 -21
- package/coverage/lcov-report/utilities/index.html +18 -18
- package/coverage/lcov-report/utilities/index.js.html +167 -14
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +12 -12
- 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 +14 -14
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +87 -51
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +8 -8
- 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/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +2641 -2357
- package/dist/api/controllers/automation.js +49 -127
- package/dist/api/controllers/deploy/index.js +17 -1
- package/dist/api/controllers/metadata.js +49 -0
- package/dist/api/controllers/query.js +0 -2
- package/dist/api/controllers/row/internal.js +33 -23
- package/dist/api/routes/automation.js +4 -5
- package/dist/api/routes/index.js +2 -0
- package/dist/api/routes/metadata.js +13 -0
- package/dist/api/routes/tests/utilities/TestFunctions.js +13 -0
- package/dist/app.js +1 -1
- package/dist/automations/actions.js +26 -46
- package/dist/automations/bullboard.js +10 -2
- package/dist/automations/index.js +11 -48
- package/dist/automations/steps/bash.js +11 -5
- package/dist/automations/steps/createRow.js +4 -4
- package/dist/automations/steps/delay.js +15 -2
- package/dist/automations/steps/deleteRow.js +4 -4
- package/dist/automations/steps/discord.js +91 -0
- package/dist/automations/steps/executeQuery.js +11 -14
- package/dist/automations/steps/executeScript.js +11 -14
- package/dist/automations/steps/filter.js +18 -17
- package/dist/automations/steps/integromat.js +94 -0
- package/dist/automations/steps/outgoingWebhook.js +12 -16
- package/dist/automations/steps/sendSmtpEmail.js +3 -3
- package/dist/automations/steps/serverLog.js +6 -2
- package/dist/automations/steps/slack.js +73 -0
- package/dist/automations/steps/updateRow.js +3 -3
- package/dist/automations/steps/utils.js +46 -0
- package/dist/automations/steps/zapier.js +91 -0
- package/dist/automations/tests/utilities/index.js +2 -12
- package/dist/automations/thread.js +23 -25
- package/dist/automations/triggerInfo/app.js +32 -0
- package/dist/automations/triggerInfo/cron.js +32 -0
- package/dist/automations/triggerInfo/index.js +15 -0
- package/dist/automations/triggerInfo/rowDeleted.js +33 -0
- package/dist/automations/triggerInfo/rowSaved.js +41 -0
- package/dist/automations/triggerInfo/rowUpdated.js +41 -0
- package/dist/automations/triggerInfo/webhook.js +37 -0
- package/dist/automations/triggers.js +27 -284
- package/dist/automations/utils.js +143 -0
- package/dist/constants/index.js +4 -0
- package/dist/db/linkedRows/index.js +14 -26
- package/dist/db/utils.js +14 -1
- package/dist/environment.js +1 -0
- package/dist/middleware/appInfo.js +17 -0
- package/dist/middleware/usageQuota.js +1 -1
- package/dist/package.json +4 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +0 -26
- package/dist/utilities/index.js +54 -0
- package/dist/utilities/redis.js +16 -1
- package/dist/utilities/rowProcessor/index.js +7 -4
- package/package.json +5 -6
- package/src/api/controllers/automation.js +75 -145
- package/src/api/controllers/deploy/index.js +23 -1
- package/src/api/controllers/metadata.js +46 -0
- package/src/api/controllers/query.js +0 -2
- package/src/api/controllers/row/internal.js +34 -23
- package/src/api/routes/automation.js +16 -11
- package/src/api/routes/index.js +2 -0
- package/src/api/routes/metadata.js +38 -0
- package/src/api/routes/tests/automation.spec.js +4 -26
- package/src/api/routes/tests/metadata.spec.js +65 -0
- package/src/api/routes/tests/utilities/TestFunctions.js +14 -0
- package/src/app.ts +1 -1
- package/src/automations/actions.js +26 -49
- package/src/automations/bullboard.js +12 -2
- package/src/automations/index.js +11 -45
- package/src/automations/steps/bash.js +12 -5
- package/src/automations/steps/createRow.js +4 -4
- package/src/automations/steps/delay.js +15 -2
- package/src/automations/steps/deleteRow.js +4 -4
- package/src/automations/steps/discord.js +83 -0
- package/src/automations/steps/executeQuery.js +11 -15
- package/src/automations/steps/executeScript.js +11 -15
- package/src/automations/steps/filter.js +18 -17
- package/src/automations/steps/integromat.js +87 -0
- package/src/automations/steps/outgoingWebhook.js +12 -14
- package/src/automations/steps/sendSmtpEmail.js +3 -3
- package/src/automations/steps/serverLog.js +6 -2
- package/src/automations/steps/slack.js +64 -0
- package/src/automations/steps/updateRow.js +3 -3
- package/src/automations/steps/utils.js +36 -0
- package/src/automations/steps/zapier.js +84 -0
- package/src/automations/tests/automation.spec.js +3 -66
- package/src/automations/tests/delay.spec.js +1 -1
- package/src/automations/tests/filter.spec.js +13 -13
- package/src/automations/tests/utilities/index.js +2 -13
- package/src/automations/thread.js +27 -26
- package/src/automations/triggerInfo/app.js +31 -0
- package/src/automations/triggerInfo/cron.js +31 -0
- package/src/automations/triggerInfo/index.js +15 -0
- package/src/automations/triggerInfo/rowDeleted.js +32 -0
- package/src/automations/triggerInfo/rowSaved.js +40 -0
- package/src/automations/triggerInfo/rowUpdated.js +40 -0
- package/src/automations/triggerInfo/webhook.js +36 -0
- package/src/automations/triggers.js +33 -288
- package/src/automations/utils.js +159 -0
- package/src/constants/index.js +5 -0
- package/src/db/linkedRows/index.js +15 -27
- package/src/db/tests/linkTests.spec.js +0 -12
- package/src/db/utils.js +17 -0
- package/src/environment.js +1 -0
- package/src/middleware/appInfo.js +19 -0
- package/src/middleware/usageQuota.js +1 -1
- package/src/utilities/fileSystem/index.js +0 -30
- package/src/utilities/index.js +51 -0
- package/src/utilities/redis.js +18 -1
- package/src/utilities/rowProcessor/index.js +16 -4
- package/dist/automations/logic.js +0 -17
- package/dist/automations/steps/sendgridEmail.js +0 -85
- package/src/automations/logic.js +0 -20
- package/src/automations/steps/sendgridEmail.js +0 -74
- package/src/automations/tests/sendEmail.spec.js +0 -36
|
@@ -190,10 +190,11 @@ exports.inputProcessing = (user = {}, table, row) => {
|
|
|
190
190
|
* @param {object} ctx the request which is looking for enriched rows.
|
|
191
191
|
* @param {object} table the table from which these rows came from originally, this is used to determine
|
|
192
192
|
* the schema of the rows and then enrich.
|
|
193
|
-
* @param {object[]} rows the rows which are to be enriched.
|
|
194
|
-
* @
|
|
193
|
+
* @param {object[]|object} rows the rows which are to be enriched.
|
|
194
|
+
* @param {object} opts used to set some options for the output, such as disabling relationship squashing.
|
|
195
|
+
* @returns {object[]|object} the enriched rows will be returned.
|
|
195
196
|
*/
|
|
196
|
-
exports.outputProcessing = (ctx, table, rows) => __awaiter(void 0, void 0, void 0, function* () {
|
|
197
|
+
exports.outputProcessing = (ctx, table, rows, opts = { squash: true }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
197
198
|
const appId = ctx.appId;
|
|
198
199
|
let wasArray = true;
|
|
199
200
|
if (!(rows instanceof Array)) {
|
|
@@ -217,6 +218,8 @@ exports.outputProcessing = (ctx, table, rows) => __awaiter(void 0, void 0, void
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
}
|
|
220
|
-
|
|
221
|
+
if (opts.squash) {
|
|
222
|
+
enriched = yield linkRows.squashLinksToPrimaryDisplay(appId, table, enriched);
|
|
223
|
+
}
|
|
221
224
|
return wasArray ? enriched : enriched[0];
|
|
222
225
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "0.9.125-alpha.
|
|
4
|
+
"version": "0.9.125-alpha.5",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"repository": {
|
|
@@ -61,9 +61,9 @@
|
|
|
61
61
|
"author": "Budibase",
|
|
62
62
|
"license": "AGPL-3.0-or-later",
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@budibase/auth": "^0.9.125-alpha.
|
|
65
|
-
"@budibase/client": "^0.9.125-alpha.
|
|
66
|
-
"@budibase/string-templates": "^0.9.125-alpha.
|
|
64
|
+
"@budibase/auth": "^0.9.125-alpha.5",
|
|
65
|
+
"@budibase/client": "^0.9.125-alpha.5",
|
|
66
|
+
"@budibase/string-templates": "^0.9.125-alpha.5",
|
|
67
67
|
"@elastic/elasticsearch": "7.10.0",
|
|
68
68
|
"@koa/router": "8.0.0",
|
|
69
69
|
"@sendgrid/mail": "7.1.1",
|
|
@@ -109,7 +109,6 @@
|
|
|
109
109
|
"to-json-schema": "0.2.5",
|
|
110
110
|
"uuid": "3.3.2",
|
|
111
111
|
"validate.js": "0.13.1",
|
|
112
|
-
"worker-farm": "1.7.0",
|
|
113
112
|
"yargs": "13.2.4",
|
|
114
113
|
"zlib": "1.0.5"
|
|
115
114
|
},
|
|
@@ -140,5 +139,5 @@
|
|
|
140
139
|
"typescript": "^4.3.5",
|
|
141
140
|
"update-dotenv": "^1.1.1"
|
|
142
141
|
},
|
|
143
|
-
"gitHead": "
|
|
142
|
+
"gitHead": "3fe70fa7ca64245716519d586722894f20ed563c"
|
|
144
143
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
const CouchDB = require("../../db")
|
|
2
2
|
const actions = require("../../automations/actions")
|
|
3
|
-
const logic = require("../../automations/logic")
|
|
4
3
|
const triggers = require("../../automations/triggers")
|
|
5
|
-
const webhooks = require("./webhook")
|
|
6
4
|
const { getAutomationParams, generateAutomationID } = require("../../db/utils")
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const {
|
|
6
|
+
checkForWebhooks,
|
|
7
|
+
updateTestHistory,
|
|
8
|
+
} = require("../../automations/utils")
|
|
9
|
+
const { deleteEntityMetadata } = require("../../utilities")
|
|
10
|
+
const { MetadataTypes } = require("../../constants")
|
|
11
|
+
const { setTestFlag, clearTestFlag } = require("../../utilities/redis")
|
|
10
12
|
|
|
11
13
|
/*************************
|
|
12
14
|
* *
|
|
@@ -14,6 +16,19 @@ const CRON_STEP_ID = triggers.BUILTIN_DEFINITIONS.CRON.stepId
|
|
|
14
16
|
* *
|
|
15
17
|
*************************/
|
|
16
18
|
|
|
19
|
+
async function cleanupAutomationMetadata(appId, automationId) {
|
|
20
|
+
await deleteEntityMetadata(
|
|
21
|
+
appId,
|
|
22
|
+
MetadataTypes.AUTOMATION_TEST_INPUT,
|
|
23
|
+
automationId
|
|
24
|
+
)
|
|
25
|
+
await deleteEntityMetadata(
|
|
26
|
+
appId,
|
|
27
|
+
MetadataTypes.AUTOMATION_TEST_HISTORY,
|
|
28
|
+
automationId
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
function cleanAutomationInputs(automation) {
|
|
18
33
|
if (automation == null) {
|
|
19
34
|
return automation
|
|
@@ -21,6 +36,10 @@ function cleanAutomationInputs(automation) {
|
|
|
21
36
|
let steps = automation.definition.steps
|
|
22
37
|
let trigger = automation.definition.trigger
|
|
23
38
|
let allSteps = [...steps, trigger]
|
|
39
|
+
// live is not a property used anymore
|
|
40
|
+
if (automation.live != null) {
|
|
41
|
+
delete automation.live
|
|
42
|
+
}
|
|
24
43
|
for (let step of allSteps) {
|
|
25
44
|
if (step == null) {
|
|
26
45
|
continue
|
|
@@ -34,119 +53,6 @@ function cleanAutomationInputs(automation) {
|
|
|
34
53
|
return automation
|
|
35
54
|
}
|
|
36
55
|
|
|
37
|
-
/**
|
|
38
|
-
* This function handles checking of any cron jobs need to be created or deleted for automations.
|
|
39
|
-
* @param {string} appId The ID of the app in which we are checking for webhooks
|
|
40
|
-
* @param {object|undefined} oldAuto The old automation object if updating/deleting
|
|
41
|
-
* @param {object|undefined} newAuto The new automation object if creating/updating
|
|
42
|
-
*/
|
|
43
|
-
async function checkForCronTriggers({ appId, oldAuto, newAuto }) {
|
|
44
|
-
const oldTrigger = oldAuto ? oldAuto.definition.trigger : null
|
|
45
|
-
const newTrigger = newAuto ? newAuto.definition.trigger : null
|
|
46
|
-
function isCronTrigger(auto) {
|
|
47
|
-
return (
|
|
48
|
-
auto &&
|
|
49
|
-
auto.definition.trigger &&
|
|
50
|
-
auto.definition.trigger.stepId === CRON_STEP_ID
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const isLive = auto => auto && auto.live
|
|
55
|
-
|
|
56
|
-
const cronTriggerRemoved =
|
|
57
|
-
isCronTrigger(oldAuto) && !isCronTrigger(newAuto) && oldTrigger.cronJobId
|
|
58
|
-
const cronTriggerDeactivated = !isLive(newAuto) && isLive(oldAuto)
|
|
59
|
-
|
|
60
|
-
const cronTriggerActivated = isLive(newAuto) && !isLive(oldAuto)
|
|
61
|
-
|
|
62
|
-
if (cronTriggerRemoved || (cronTriggerDeactivated && oldTrigger.cronJobId)) {
|
|
63
|
-
await triggers.automationQueue.removeRepeatableByKey(oldTrigger.cronJobId)
|
|
64
|
-
}
|
|
65
|
-
// need to create cron job
|
|
66
|
-
else if (isCronTrigger(newAuto) && cronTriggerActivated) {
|
|
67
|
-
const job = await triggers.automationQueue.add(
|
|
68
|
-
{
|
|
69
|
-
automation: newAuto,
|
|
70
|
-
event: { appId, timestamp: Date.now() },
|
|
71
|
-
},
|
|
72
|
-
{ repeat: { cron: newTrigger.inputs.cron } }
|
|
73
|
-
)
|
|
74
|
-
// Assign cron job ID from bull so we can remove it later if the cron trigger is removed
|
|
75
|
-
newTrigger.cronJobId = job.id
|
|
76
|
-
}
|
|
77
|
-
return newAuto
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* This function handles checking if any webhooks need to be created or deleted for automations.
|
|
82
|
-
* @param {string} appId The ID of the app in which we are checking for webhooks
|
|
83
|
-
* @param {object|undefined} oldAuto The old automation object if updating/deleting
|
|
84
|
-
* @param {object|undefined} newAuto The new automation object if creating/updating
|
|
85
|
-
* @returns {Promise<object|undefined>} After this is complete the new automation object may have been updated and should be
|
|
86
|
-
* written to DB (this does not write to DB as it would be wasteful to repeat).
|
|
87
|
-
*/
|
|
88
|
-
async function checkForWebhooks({ appId, oldAuto, newAuto }) {
|
|
89
|
-
const oldTrigger = oldAuto ? oldAuto.definition.trigger : null
|
|
90
|
-
const newTrigger = newAuto ? newAuto.definition.trigger : null
|
|
91
|
-
const triggerChanged =
|
|
92
|
-
oldTrigger && newTrigger && oldTrigger.id !== newTrigger.id
|
|
93
|
-
function isWebhookTrigger(auto) {
|
|
94
|
-
return (
|
|
95
|
-
auto &&
|
|
96
|
-
auto.definition.trigger &&
|
|
97
|
-
auto.definition.trigger.stepId === WH_STEP_ID
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
// need to delete webhook
|
|
101
|
-
if (
|
|
102
|
-
isWebhookTrigger(oldAuto) &&
|
|
103
|
-
(!isWebhookTrigger(newAuto) || triggerChanged) &&
|
|
104
|
-
oldTrigger.webhookId
|
|
105
|
-
) {
|
|
106
|
-
try {
|
|
107
|
-
let db = new CouchDB(appId)
|
|
108
|
-
// need to get the webhook to get the rev
|
|
109
|
-
const webhook = await db.get(oldTrigger.webhookId)
|
|
110
|
-
const ctx = {
|
|
111
|
-
appId,
|
|
112
|
-
params: { id: webhook._id, rev: webhook._rev },
|
|
113
|
-
}
|
|
114
|
-
// might be updating - reset the inputs to remove the URLs
|
|
115
|
-
if (newTrigger) {
|
|
116
|
-
delete newTrigger.webhookId
|
|
117
|
-
newTrigger.inputs = {}
|
|
118
|
-
}
|
|
119
|
-
await webhooks.destroy(ctx)
|
|
120
|
-
} catch (err) {
|
|
121
|
-
// don't worry about not being able to delete, if it doesn't exist all good
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// need to create webhook
|
|
125
|
-
if (
|
|
126
|
-
(!isWebhookTrigger(oldAuto) || triggerChanged) &&
|
|
127
|
-
isWebhookTrigger(newAuto)
|
|
128
|
-
) {
|
|
129
|
-
const ctx = {
|
|
130
|
-
appId,
|
|
131
|
-
request: {
|
|
132
|
-
body: new webhooks.Webhook(
|
|
133
|
-
"Automation webhook",
|
|
134
|
-
webhooks.WebhookType.AUTOMATION,
|
|
135
|
-
newAuto._id
|
|
136
|
-
),
|
|
137
|
-
},
|
|
138
|
-
}
|
|
139
|
-
await webhooks.save(ctx)
|
|
140
|
-
const id = ctx.body.webhook._id
|
|
141
|
-
newTrigger.webhookId = id
|
|
142
|
-
newTrigger.inputs = {
|
|
143
|
-
schemaUrl: `api/webhooks/schema/${appId}/${id}`,
|
|
144
|
-
triggerUrl: `api/webhooks/trigger/${appId}/${id}`,
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return newAuto
|
|
148
|
-
}
|
|
149
|
-
|
|
150
56
|
exports.create = async function (ctx) {
|
|
151
57
|
const db = new CouchDB(ctx.appId)
|
|
152
58
|
let automation = ctx.request.body
|
|
@@ -165,10 +71,6 @@ exports.create = async function (ctx) {
|
|
|
165
71
|
appId: ctx.appId,
|
|
166
72
|
newAuto: automation,
|
|
167
73
|
})
|
|
168
|
-
automation = await checkForCronTriggers({
|
|
169
|
-
appId: ctx.appId,
|
|
170
|
-
newAuto: automation,
|
|
171
|
-
})
|
|
172
74
|
const response = await db.put(automation)
|
|
173
75
|
automation._rev = response.rev
|
|
174
76
|
|
|
@@ -193,14 +95,26 @@ exports.update = async function (ctx) {
|
|
|
193
95
|
oldAuto: oldAutomation,
|
|
194
96
|
newAuto: automation,
|
|
195
97
|
})
|
|
196
|
-
automation = await checkForCronTriggers({
|
|
197
|
-
appId: ctx.appId,
|
|
198
|
-
oldAuto: oldAutomation,
|
|
199
|
-
newAuto: automation,
|
|
200
|
-
})
|
|
201
98
|
const response = await db.put(automation)
|
|
202
99
|
automation._rev = response.rev
|
|
203
100
|
|
|
101
|
+
const oldAutoTrigger =
|
|
102
|
+
oldAutomation && oldAutomation.definition.trigger
|
|
103
|
+
? oldAutomation.definition.trigger
|
|
104
|
+
: {}
|
|
105
|
+
const newAutoTrigger =
|
|
106
|
+
automation && automation.definition.trigger
|
|
107
|
+
? automation.definition.trigger
|
|
108
|
+
: {}
|
|
109
|
+
// trigger has been updated, remove the test inputs
|
|
110
|
+
if (oldAutoTrigger.id !== newAutoTrigger.id) {
|
|
111
|
+
await deleteEntityMetadata(
|
|
112
|
+
ctx.appId,
|
|
113
|
+
MetadataTypes.AUTOMATION_TEST_INPUT,
|
|
114
|
+
automation._id
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
204
118
|
ctx.status = 200
|
|
205
119
|
ctx.body = {
|
|
206
120
|
message: `Automation ${automation._id} updated successfully.`,
|
|
@@ -229,35 +143,29 @@ exports.find = async function (ctx) {
|
|
|
229
143
|
|
|
230
144
|
exports.destroy = async function (ctx) {
|
|
231
145
|
const db = new CouchDB(ctx.appId)
|
|
232
|
-
const
|
|
146
|
+
const automationId = ctx.params.id
|
|
147
|
+
const oldAutomation = await db.get(automationId)
|
|
233
148
|
await checkForWebhooks({
|
|
234
149
|
appId: ctx.appId,
|
|
235
150
|
oldAuto: oldAutomation,
|
|
236
151
|
})
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
})
|
|
241
|
-
ctx.body = await db.remove(ctx.params.id, ctx.params.rev)
|
|
152
|
+
// delete metadata first
|
|
153
|
+
await cleanupAutomationMetadata(ctx.appId, automationId)
|
|
154
|
+
ctx.body = await db.remove(automationId, ctx.params.rev)
|
|
242
155
|
}
|
|
243
156
|
|
|
244
157
|
exports.getActionList = async function (ctx) {
|
|
245
|
-
ctx.body = actions.
|
|
158
|
+
ctx.body = actions.ACTION_DEFINITIONS
|
|
246
159
|
}
|
|
247
160
|
|
|
248
161
|
exports.getTriggerList = async function (ctx) {
|
|
249
|
-
ctx.body = triggers.
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
exports.getLogicList = async function (ctx) {
|
|
253
|
-
ctx.body = logic.BUILTIN_DEFINITIONS
|
|
162
|
+
ctx.body = triggers.TRIGGER_DEFINITIONS
|
|
254
163
|
}
|
|
255
164
|
|
|
256
165
|
module.exports.getDefinitionList = async function (ctx) {
|
|
257
166
|
ctx.body = {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
action: actions.DEFINITIONS,
|
|
167
|
+
trigger: triggers.TRIGGER_DEFINITIONS,
|
|
168
|
+
action: actions.ACTION_DEFINITIONS,
|
|
261
169
|
}
|
|
262
170
|
}
|
|
263
171
|
|
|
@@ -268,15 +176,37 @@ module.exports.getDefinitionList = async function (ctx) {
|
|
|
268
176
|
*********************/
|
|
269
177
|
|
|
270
178
|
exports.trigger = async function (ctx) {
|
|
271
|
-
const
|
|
179
|
+
const appId = ctx.appId
|
|
180
|
+
const db = new CouchDB(appId)
|
|
272
181
|
let automation = await db.get(ctx.params.id)
|
|
273
182
|
await triggers.externalTrigger(automation, {
|
|
274
183
|
...ctx.request.body,
|
|
275
|
-
appId
|
|
184
|
+
appId,
|
|
276
185
|
})
|
|
277
|
-
ctx.status = 200
|
|
278
186
|
ctx.body = {
|
|
279
187
|
message: `Automation ${automation._id} has been triggered.`,
|
|
280
188
|
automation,
|
|
281
189
|
}
|
|
282
190
|
}
|
|
191
|
+
|
|
192
|
+
exports.test = async function (ctx) {
|
|
193
|
+
const appId = ctx.appId
|
|
194
|
+
const db = new CouchDB(appId)
|
|
195
|
+
let automation = await db.get(ctx.params.id)
|
|
196
|
+
await setTestFlag(automation._id)
|
|
197
|
+
const response = await triggers.externalTrigger(
|
|
198
|
+
automation,
|
|
199
|
+
{
|
|
200
|
+
...ctx.request.body,
|
|
201
|
+
appId,
|
|
202
|
+
},
|
|
203
|
+
{ getResponses: true }
|
|
204
|
+
)
|
|
205
|
+
// save a test history run
|
|
206
|
+
await updateTestHistory(ctx.appId, automation, {
|
|
207
|
+
...ctx.request.body,
|
|
208
|
+
occurredAt: new Date().getTime(),
|
|
209
|
+
})
|
|
210
|
+
await clearTestFlag(automation._id)
|
|
211
|
+
ctx.body = response
|
|
212
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
const CouchDB = require("../../../db")
|
|
2
2
|
const Deployment = require("./Deployment")
|
|
3
3
|
const { Replication } = require("@budibase/auth/db")
|
|
4
|
-
const { DocumentTypes } = require("../../../db/utils")
|
|
4
|
+
const { DocumentTypes, getAutomationParams } = require("../../../db/utils")
|
|
5
|
+
const {
|
|
6
|
+
disableAllCrons,
|
|
7
|
+
enableCronTrigger,
|
|
8
|
+
} = require("../../../automations/utils")
|
|
5
9
|
|
|
6
10
|
// the max time we can wait for an invalidation to complete before considering it failed
|
|
7
11
|
const MAX_PENDING_TIME_MS = 30 * 60000
|
|
@@ -58,6 +62,23 @@ async function storeDeploymentHistory(deployment) {
|
|
|
58
62
|
return deployment
|
|
59
63
|
}
|
|
60
64
|
|
|
65
|
+
async function initDeployedApp(prodAppId) {
|
|
66
|
+
const db = new CouchDB(prodAppId)
|
|
67
|
+
const automations = (
|
|
68
|
+
await db.allDocs(
|
|
69
|
+
getAutomationParams(null, {
|
|
70
|
+
include_docs: true,
|
|
71
|
+
})
|
|
72
|
+
)
|
|
73
|
+
).rows.map(row => row.doc)
|
|
74
|
+
const promises = []
|
|
75
|
+
await disableAllCrons(prodAppId)
|
|
76
|
+
for (let automation of automations) {
|
|
77
|
+
promises.push(enableCronTrigger(prodAppId, automation))
|
|
78
|
+
}
|
|
79
|
+
await Promise.all(promises)
|
|
80
|
+
}
|
|
81
|
+
|
|
61
82
|
async function deployApp(deployment) {
|
|
62
83
|
try {
|
|
63
84
|
const productionAppId = deployment.appId.replace("_dev", "")
|
|
@@ -85,6 +106,7 @@ async function deployApp(deployment) {
|
|
|
85
106
|
},
|
|
86
107
|
})
|
|
87
108
|
|
|
109
|
+
await initDeployedApp(productionAppId)
|
|
88
110
|
deployment.setStatus(DeploymentStatus.SUCCESS)
|
|
89
111
|
await storeDeploymentHistory(deployment)
|
|
90
112
|
} catch (err) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { MetadataTypes } = require("../../constants")
|
|
2
|
+
const CouchDB = require("../../db")
|
|
3
|
+
const { generateMetadataID } = require("../../db/utils")
|
|
4
|
+
const { saveEntityMetadata, deleteEntityMetadata } = require("../../utilities")
|
|
5
|
+
|
|
6
|
+
exports.getTypes = async ctx => {
|
|
7
|
+
ctx.body = {
|
|
8
|
+
types: MetadataTypes,
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.saveMetadata = async ctx => {
|
|
13
|
+
const { type, entityId } = ctx.params
|
|
14
|
+
if (type === MetadataTypes.AUTOMATION_TEST_HISTORY) {
|
|
15
|
+
ctx.throw(400, "Cannot save automation history type")
|
|
16
|
+
}
|
|
17
|
+
ctx.body = await saveEntityMetadata(
|
|
18
|
+
ctx.appId,
|
|
19
|
+
type,
|
|
20
|
+
entityId,
|
|
21
|
+
ctx.request.body
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.deleteMetadata = async ctx => {
|
|
26
|
+
const { type, entityId } = ctx.params
|
|
27
|
+
await deleteEntityMetadata(ctx.appId, type, entityId)
|
|
28
|
+
ctx.body = {
|
|
29
|
+
message: "Metadata deleted successfully",
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.getMetadata = async ctx => {
|
|
34
|
+
const { type, entityId } = ctx.params
|
|
35
|
+
const db = new CouchDB(ctx.appId)
|
|
36
|
+
const id = generateMetadataID(type, entityId)
|
|
37
|
+
try {
|
|
38
|
+
ctx.body = await db.get(id)
|
|
39
|
+
} catch (err) {
|
|
40
|
+
if (err.status === 404) {
|
|
41
|
+
ctx.body = {}
|
|
42
|
+
} else {
|
|
43
|
+
ctx.throw(err.status, err)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|