@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
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
exports.definition = {
|
|
2
|
+
name: "Row Updated",
|
|
3
|
+
event: "row:update",
|
|
4
|
+
icon: "ri-refresh-line",
|
|
5
|
+
tagline: "Row is updated in {{inputs.enriched.table.name}}",
|
|
6
|
+
description: "Fired when a row is updated in your database",
|
|
7
|
+
stepId: "ROW_UPDATED",
|
|
8
|
+
inputs: {},
|
|
9
|
+
schema: {
|
|
10
|
+
inputs: {
|
|
11
|
+
properties: {
|
|
12
|
+
tableId: {
|
|
13
|
+
type: "string",
|
|
14
|
+
customType: "table",
|
|
15
|
+
title: "Table",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
required: ["tableId"],
|
|
19
|
+
},
|
|
20
|
+
outputs: {
|
|
21
|
+
properties: {
|
|
22
|
+
row: {
|
|
23
|
+
type: "object",
|
|
24
|
+
customType: "row",
|
|
25
|
+
description: "The row that was updated",
|
|
26
|
+
},
|
|
27
|
+
id: {
|
|
28
|
+
type: "string",
|
|
29
|
+
description: "Row ID - can be used for updating",
|
|
30
|
+
},
|
|
31
|
+
revision: {
|
|
32
|
+
type: "string",
|
|
33
|
+
description: "Revision of row",
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
required: ["row", "id"],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
type: "TRIGGER",
|
|
40
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
exports.definition = {
|
|
2
|
+
name: "Webhook",
|
|
3
|
+
event: "web:trigger",
|
|
4
|
+
icon: "ri-global-line",
|
|
5
|
+
tagline: "Webhook endpoint is hit",
|
|
6
|
+
description: "Trigger an automation when a HTTP POST webhook is hit",
|
|
7
|
+
stepId: "WEBHOOK",
|
|
8
|
+
inputs: {},
|
|
9
|
+
schema: {
|
|
10
|
+
inputs: {
|
|
11
|
+
properties: {
|
|
12
|
+
schemaUrl: {
|
|
13
|
+
type: "string",
|
|
14
|
+
customType: "webhookUrl",
|
|
15
|
+
title: "Schema URL",
|
|
16
|
+
},
|
|
17
|
+
triggerUrl: {
|
|
18
|
+
type: "string",
|
|
19
|
+
customType: "webhookUrl",
|
|
20
|
+
title: "Trigger URL",
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
required: ["schemaUrl", "triggerUrl"],
|
|
24
|
+
},
|
|
25
|
+
outputs: {
|
|
26
|
+
properties: {
|
|
27
|
+
body: {
|
|
28
|
+
type: "object",
|
|
29
|
+
description: "Body of the request which hit the webhook",
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
required: ["body"],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
type: "TRIGGER",
|
|
36
|
+
}
|
|
@@ -1,244 +1,22 @@
|
|
|
1
1
|
const CouchDB = require("../db")
|
|
2
2
|
const emitter = require("../events/index")
|
|
3
|
-
const env = require("../environment")
|
|
4
|
-
const Queue = env.isTest()
|
|
5
|
-
? require("../utilities/queue/inMemoryQueue")
|
|
6
|
-
: require("bull")
|
|
7
3
|
const { getAutomationParams } = require("../db/utils")
|
|
8
4
|
const { coerce } = require("../utilities/rowProcessor")
|
|
9
|
-
const {
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const { opts } = utils.getRedisOptions()
|
|
18
|
-
let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts })
|
|
19
|
-
|
|
20
|
-
const FAKE_STRING = "TEST"
|
|
21
|
-
const FAKE_BOOL = false
|
|
22
|
-
const FAKE_NUMBER = 1
|
|
23
|
-
const FAKE_DATETIME = "1970-01-01T00:00:00.000Z"
|
|
5
|
+
const { definitions } = require("./triggerInfo")
|
|
6
|
+
const { isDevAppID } = require("../db/utils")
|
|
7
|
+
// need this to call directly, so we can get a response
|
|
8
|
+
const { queue } = require("./bullboard")
|
|
9
|
+
const { checkTestFlag } = require("../utilities/redis")
|
|
10
|
+
const utils = require("./utils")
|
|
11
|
+
const env = require("../environment")
|
|
24
12
|
|
|
25
|
-
const
|
|
26
|
-
ROW_SAVED: {
|
|
27
|
-
name: "Row Created",
|
|
28
|
-
event: "row:save",
|
|
29
|
-
icon: "ri-save-line",
|
|
30
|
-
tagline: "Row is added to {{inputs.enriched.table.name}}",
|
|
31
|
-
description: "Fired when a row is added to your database",
|
|
32
|
-
stepId: "ROW_SAVED",
|
|
33
|
-
inputs: {},
|
|
34
|
-
schema: {
|
|
35
|
-
inputs: {
|
|
36
|
-
properties: {
|
|
37
|
-
tableId: {
|
|
38
|
-
type: "string",
|
|
39
|
-
customType: "table",
|
|
40
|
-
title: "Table",
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
required: ["tableId"],
|
|
44
|
-
},
|
|
45
|
-
outputs: {
|
|
46
|
-
properties: {
|
|
47
|
-
row: {
|
|
48
|
-
type: "object",
|
|
49
|
-
customType: "row",
|
|
50
|
-
description: "The new row that was created",
|
|
51
|
-
},
|
|
52
|
-
id: {
|
|
53
|
-
type: "string",
|
|
54
|
-
description: "Row ID - can be used for updating",
|
|
55
|
-
},
|
|
56
|
-
revision: {
|
|
57
|
-
type: "string",
|
|
58
|
-
description: "Revision of row",
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
required: ["row", "id"],
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
type: "TRIGGER",
|
|
65
|
-
},
|
|
66
|
-
ROW_UPDATED: {
|
|
67
|
-
name: "Row Updated",
|
|
68
|
-
event: "row:update",
|
|
69
|
-
icon: "ri-refresh-line",
|
|
70
|
-
tagline: "Row is updated in {{inputs.enriched.table.name}}",
|
|
71
|
-
description: "Fired when a row is updated in your database",
|
|
72
|
-
stepId: "ROW_UPDATED",
|
|
73
|
-
inputs: {},
|
|
74
|
-
schema: {
|
|
75
|
-
inputs: {
|
|
76
|
-
properties: {
|
|
77
|
-
tableId: {
|
|
78
|
-
type: "string",
|
|
79
|
-
customType: "table",
|
|
80
|
-
title: "Table",
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
required: ["tableId"],
|
|
84
|
-
},
|
|
85
|
-
outputs: {
|
|
86
|
-
properties: {
|
|
87
|
-
row: {
|
|
88
|
-
type: "object",
|
|
89
|
-
customType: "row",
|
|
90
|
-
description: "The row that was updated",
|
|
91
|
-
},
|
|
92
|
-
id: {
|
|
93
|
-
type: "string",
|
|
94
|
-
description: "Row ID - can be used for updating",
|
|
95
|
-
},
|
|
96
|
-
revision: {
|
|
97
|
-
type: "string",
|
|
98
|
-
description: "Revision of row",
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
required: ["row", "id"],
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
type: "TRIGGER",
|
|
105
|
-
},
|
|
106
|
-
ROW_DELETED: {
|
|
107
|
-
name: "Row Deleted",
|
|
108
|
-
event: "row:delete",
|
|
109
|
-
icon: "ri-delete-bin-line",
|
|
110
|
-
tagline: "Row is deleted from {{inputs.enriched.table.name}}",
|
|
111
|
-
description: "Fired when a row is deleted from your database",
|
|
112
|
-
stepId: "ROW_DELETED",
|
|
113
|
-
inputs: {},
|
|
114
|
-
schema: {
|
|
115
|
-
inputs: {
|
|
116
|
-
properties: {
|
|
117
|
-
tableId: {
|
|
118
|
-
type: "string",
|
|
119
|
-
customType: "table",
|
|
120
|
-
title: "Table",
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
required: ["tableId"],
|
|
124
|
-
},
|
|
125
|
-
outputs: {
|
|
126
|
-
properties: {
|
|
127
|
-
row: {
|
|
128
|
-
type: "object",
|
|
129
|
-
customType: "row",
|
|
130
|
-
description: "The row that was deleted",
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
required: ["row"],
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
type: "TRIGGER",
|
|
137
|
-
},
|
|
138
|
-
WEBHOOK: {
|
|
139
|
-
name: "Webhook",
|
|
140
|
-
event: "web:trigger",
|
|
141
|
-
icon: "ri-global-line",
|
|
142
|
-
tagline: "Webhook endpoint is hit",
|
|
143
|
-
description: "Trigger an automation when a HTTP POST webhook is hit",
|
|
144
|
-
stepId: "WEBHOOK",
|
|
145
|
-
inputs: {},
|
|
146
|
-
schema: {
|
|
147
|
-
inputs: {
|
|
148
|
-
properties: {
|
|
149
|
-
schemaUrl: {
|
|
150
|
-
type: "string",
|
|
151
|
-
customType: "webhookUrl",
|
|
152
|
-
title: "Schema URL",
|
|
153
|
-
},
|
|
154
|
-
triggerUrl: {
|
|
155
|
-
type: "string",
|
|
156
|
-
customType: "webhookUrl",
|
|
157
|
-
title: "Trigger URL",
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
required: ["schemaUrl", "triggerUrl"],
|
|
161
|
-
},
|
|
162
|
-
outputs: {
|
|
163
|
-
properties: {
|
|
164
|
-
body: {
|
|
165
|
-
type: "object",
|
|
166
|
-
description: "Body of the request which hit the webhook",
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
required: ["body"],
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
type: "TRIGGER",
|
|
173
|
-
},
|
|
174
|
-
APP: {
|
|
175
|
-
name: "App Action",
|
|
176
|
-
event: "app:trigger",
|
|
177
|
-
icon: "ri-window-fill",
|
|
178
|
-
tagline: "Automation fired from the frontend",
|
|
179
|
-
description: "Trigger an automation from an action inside your app",
|
|
180
|
-
stepId: "APP",
|
|
181
|
-
inputs: {},
|
|
182
|
-
schema: {
|
|
183
|
-
inputs: {
|
|
184
|
-
properties: {
|
|
185
|
-
fields: {
|
|
186
|
-
type: "object",
|
|
187
|
-
customType: "triggerSchema",
|
|
188
|
-
title: "Fields",
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
required: [],
|
|
192
|
-
},
|
|
193
|
-
outputs: {
|
|
194
|
-
properties: {
|
|
195
|
-
fields: {
|
|
196
|
-
type: "object",
|
|
197
|
-
description: "Fields submitted from the app frontend",
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
required: ["fields"],
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
type: "TRIGGER",
|
|
204
|
-
},
|
|
205
|
-
CRON: {
|
|
206
|
-
name: "Cron Trigger",
|
|
207
|
-
event: "cron:trigger",
|
|
208
|
-
icon: "ri-timer-line",
|
|
209
|
-
tagline: "Cron Trigger (<b>{{inputs.cron}}</b>)",
|
|
210
|
-
description: "Triggers automation on a cron schedule.",
|
|
211
|
-
stepId: "CRON",
|
|
212
|
-
inputs: {},
|
|
213
|
-
schema: {
|
|
214
|
-
inputs: {
|
|
215
|
-
properties: {
|
|
216
|
-
cron: {
|
|
217
|
-
type: "string",
|
|
218
|
-
customType: "cron",
|
|
219
|
-
title: "Expression",
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
required: ["cron"],
|
|
223
|
-
},
|
|
224
|
-
outputs: {
|
|
225
|
-
properties: {
|
|
226
|
-
timestamp: {
|
|
227
|
-
type: "number",
|
|
228
|
-
description: "Timestamp the cron was executed",
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
required: ["timestamp"],
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
type: "TRIGGER",
|
|
235
|
-
},
|
|
236
|
-
}
|
|
13
|
+
const TRIGGER_DEFINITIONS = definitions
|
|
237
14
|
|
|
238
15
|
async function queueRelevantRowAutomations(event, eventType) {
|
|
239
16
|
if (event.appId == null) {
|
|
240
17
|
throw `No appId specified for ${eventType} - check event emitters.`
|
|
241
18
|
}
|
|
19
|
+
|
|
242
20
|
const db = new CouchDB(event.appId)
|
|
243
21
|
let automations = await db.allDocs(
|
|
244
22
|
getAutomationParams(null, { include_docs: true })
|
|
@@ -255,14 +33,22 @@ async function queueRelevantRowAutomations(event, eventType) {
|
|
|
255
33
|
for (let automation of automations) {
|
|
256
34
|
let automationDef = automation.definition
|
|
257
35
|
let automationTrigger = automationDef ? automationDef.trigger : {}
|
|
36
|
+
// don't queue events which are for dev apps, only way to test automations is
|
|
37
|
+
// running tests on them, in production the test flag will never
|
|
38
|
+
// be checked due to lazy evaluation (first always false)
|
|
258
39
|
if (
|
|
259
|
-
!
|
|
260
|
-
|
|
261
|
-
|
|
40
|
+
!env.ALLOW_DEV_AUTOMATIONS &&
|
|
41
|
+
isDevAppID(event.appId) &&
|
|
42
|
+
!(await checkTestFlag(automation._id))
|
|
262
43
|
) {
|
|
263
44
|
continue
|
|
264
45
|
}
|
|
265
|
-
|
|
46
|
+
if (
|
|
47
|
+
automationTrigger.inputs &&
|
|
48
|
+
automationTrigger.inputs.tableId === event.row.tableId
|
|
49
|
+
) {
|
|
50
|
+
await queue.add({ automation, event })
|
|
51
|
+
}
|
|
266
52
|
}
|
|
267
53
|
}
|
|
268
54
|
|
|
@@ -290,51 +76,12 @@ emitter.on("row:delete", async function (event) {
|
|
|
290
76
|
await queueRelevantRowAutomations(event, "row:delete")
|
|
291
77
|
})
|
|
292
78
|
|
|
293
|
-
async function
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
if (!isExternalTable(tableId)) {
|
|
299
|
-
const db = new CouchDB(params.appId)
|
|
300
|
-
table = await db.get(tableId)
|
|
301
|
-
} else {
|
|
302
|
-
const { datasourceId, tableName } = breakExternalTableId(tableId)
|
|
303
|
-
table = await getExternalTable(params.appId, datasourceId, tableName)
|
|
304
|
-
}
|
|
305
|
-
let row = {}
|
|
306
|
-
for (let schemaKey of Object.keys(table.schema)) {
|
|
307
|
-
const paramValue = params[schemaKey]
|
|
308
|
-
let propSchema = table.schema[schemaKey]
|
|
309
|
-
switch (propSchema.constraints.type) {
|
|
310
|
-
case "string":
|
|
311
|
-
row[schemaKey] = paramValue || FAKE_STRING
|
|
312
|
-
break
|
|
313
|
-
case "boolean":
|
|
314
|
-
row[schemaKey] = paramValue || FAKE_BOOL
|
|
315
|
-
break
|
|
316
|
-
case "number":
|
|
317
|
-
row[schemaKey] = paramValue || FAKE_NUMBER
|
|
318
|
-
break
|
|
319
|
-
case "datetime":
|
|
320
|
-
row[schemaKey] = paramValue || FAKE_DATETIME
|
|
321
|
-
break
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
params.row = row
|
|
325
|
-
} catch (err) {
|
|
326
|
-
/* istanbul ignore next */
|
|
327
|
-
throw "Failed to find table for trigger"
|
|
328
|
-
}
|
|
329
|
-
return params
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
module.exports.externalTrigger = async function (automation, params) {
|
|
333
|
-
// TODO: replace this with allowing user in builder to input values in future
|
|
79
|
+
exports.externalTrigger = async function (
|
|
80
|
+
automation,
|
|
81
|
+
params,
|
|
82
|
+
{ getResponses } = {}
|
|
83
|
+
) {
|
|
334
84
|
if (automation.definition != null && automation.definition.trigger != null) {
|
|
335
|
-
if (automation.definition.trigger.inputs.tableId != null) {
|
|
336
|
-
params = await fillRowOutput(automation, params)
|
|
337
|
-
}
|
|
338
85
|
if (automation.definition.trigger.stepId === "APP") {
|
|
339
86
|
// values are likely to be submitted as strings, so we shall convert to correct type
|
|
340
87
|
const coercedFields = {}
|
|
@@ -345,14 +92,12 @@ module.exports.externalTrigger = async function (automation, params) {
|
|
|
345
92
|
params.fields = coercedFields
|
|
346
93
|
}
|
|
347
94
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
95
|
+
const data = { automation, event: params }
|
|
96
|
+
if (getResponses) {
|
|
97
|
+
return utils.processEvent({ data })
|
|
98
|
+
} else {
|
|
99
|
+
return queue.add(data)
|
|
100
|
+
}
|
|
354
101
|
}
|
|
355
|
-
module.exports.fillRowOutput = fillRowOutput
|
|
356
|
-
module.exports.automationQueue = automationQueue
|
|
357
102
|
|
|
358
|
-
|
|
103
|
+
exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const runner = require("./thread")
|
|
2
|
+
const { definitions } = require("./triggerInfo")
|
|
3
|
+
const webhooks = require("../api/controllers/webhook")
|
|
4
|
+
const CouchDB = require("../db")
|
|
5
|
+
const { queue } = require("./bullboard")
|
|
6
|
+
const newid = require("../db/newid")
|
|
7
|
+
const { updateEntityMetadata } = require("../utilities")
|
|
8
|
+
const { MetadataTypes } = require("../constants")
|
|
9
|
+
|
|
10
|
+
const WH_STEP_ID = definitions.WEBHOOK.stepId
|
|
11
|
+
const CRON_STEP_ID = definitions.CRON.stepId
|
|
12
|
+
|
|
13
|
+
exports.processEvent = async job => {
|
|
14
|
+
try {
|
|
15
|
+
// need to actually await these so that an error can be captured properly
|
|
16
|
+
return await runner(job)
|
|
17
|
+
} catch (err) {
|
|
18
|
+
console.error(
|
|
19
|
+
`${job.data.automation.appId} automation ${job.data.automation._id} was unable to run - ${err}`
|
|
20
|
+
)
|
|
21
|
+
return { err }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.updateTestHistory = async (appId, automation, history) => {
|
|
26
|
+
return updateEntityMetadata(
|
|
27
|
+
appId,
|
|
28
|
+
MetadataTypes.AUTOMATION_TEST_HISTORY,
|
|
29
|
+
automation._id,
|
|
30
|
+
metadata => {
|
|
31
|
+
if (metadata && Array.isArray(metadata.history)) {
|
|
32
|
+
metadata.history.push(history)
|
|
33
|
+
} else {
|
|
34
|
+
metadata = {
|
|
35
|
+
history: [history],
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return metadata
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// end the repetition and the job itself
|
|
44
|
+
exports.disableAllCrons = async appId => {
|
|
45
|
+
const promises = []
|
|
46
|
+
const jobs = await queue.getRepeatableJobs()
|
|
47
|
+
for (let job of jobs) {
|
|
48
|
+
if (job.key.includes(`${appId}_cron`)) {
|
|
49
|
+
promises.push(queue.removeRepeatableByKey(job.key))
|
|
50
|
+
promises.push(queue.removeJobs(job.id))
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return Promise.all(promises)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This function handles checking of any cron jobs that need to be enabled/updated.
|
|
58
|
+
* @param {string} appId The ID of the app in which we are checking for webhooks
|
|
59
|
+
* @param {object|undefined} automation The automation object to be updated.
|
|
60
|
+
*/
|
|
61
|
+
exports.enableCronTrigger = async (appId, automation) => {
|
|
62
|
+
const trigger = automation ? automation.definition.trigger : null
|
|
63
|
+
function isCronTrigger(auto) {
|
|
64
|
+
return (
|
|
65
|
+
auto &&
|
|
66
|
+
auto.definition.trigger &&
|
|
67
|
+
auto.definition.trigger.stepId === CRON_STEP_ID
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
// need to create cron job
|
|
71
|
+
if (isCronTrigger(automation)) {
|
|
72
|
+
// make a job id rather than letting Bull decide, makes it easier to handle on way out
|
|
73
|
+
const jobId = `${appId}_cron_${newid()}`
|
|
74
|
+
const job = await queue.add(
|
|
75
|
+
{
|
|
76
|
+
automation,
|
|
77
|
+
event: { appId, timestamp: Date.now() },
|
|
78
|
+
},
|
|
79
|
+
{ repeat: { cron: trigger.inputs.cron }, jobId }
|
|
80
|
+
)
|
|
81
|
+
// Assign cron job ID from bull so we can remove it later if the cron trigger is removed
|
|
82
|
+
trigger.cronJobId = job.id
|
|
83
|
+
const db = new CouchDB(appId)
|
|
84
|
+
const response = await db.put(automation)
|
|
85
|
+
automation._id = response.id
|
|
86
|
+
automation._rev = response.rev
|
|
87
|
+
}
|
|
88
|
+
return automation
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* This function handles checking if any webhooks need to be created or deleted for automations.
|
|
93
|
+
* @param {string} appId The ID of the app in which we are checking for webhooks
|
|
94
|
+
* @param {object|undefined} oldAuto The old automation object if updating/deleting
|
|
95
|
+
* @param {object|undefined} newAuto The new automation object if creating/updating
|
|
96
|
+
* @returns {Promise<object|undefined>} After this is complete the new automation object may have been updated and should be
|
|
97
|
+
* written to DB (this does not write to DB as it would be wasteful to repeat).
|
|
98
|
+
*/
|
|
99
|
+
exports.checkForWebhooks = async ({ appId, oldAuto, newAuto }) => {
|
|
100
|
+
const oldTrigger = oldAuto ? oldAuto.definition.trigger : null
|
|
101
|
+
const newTrigger = newAuto ? newAuto.definition.trigger : null
|
|
102
|
+
const triggerChanged =
|
|
103
|
+
oldTrigger && newTrigger && oldTrigger.id !== newTrigger.id
|
|
104
|
+
function isWebhookTrigger(auto) {
|
|
105
|
+
return (
|
|
106
|
+
auto &&
|
|
107
|
+
auto.definition.trigger &&
|
|
108
|
+
auto.definition.trigger.stepId === WH_STEP_ID
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
// need to delete webhook
|
|
112
|
+
if (
|
|
113
|
+
isWebhookTrigger(oldAuto) &&
|
|
114
|
+
(!isWebhookTrigger(newAuto) || triggerChanged) &&
|
|
115
|
+
oldTrigger.webhookId
|
|
116
|
+
) {
|
|
117
|
+
try {
|
|
118
|
+
let db = new CouchDB(appId)
|
|
119
|
+
// need to get the webhook to get the rev
|
|
120
|
+
const webhook = await db.get(oldTrigger.webhookId)
|
|
121
|
+
const ctx = {
|
|
122
|
+
appId,
|
|
123
|
+
params: { id: webhook._id, rev: webhook._rev },
|
|
124
|
+
}
|
|
125
|
+
// might be updating - reset the inputs to remove the URLs
|
|
126
|
+
if (newTrigger) {
|
|
127
|
+
delete newTrigger.webhookId
|
|
128
|
+
newTrigger.inputs = {}
|
|
129
|
+
}
|
|
130
|
+
await webhooks.destroy(ctx)
|
|
131
|
+
} catch (err) {
|
|
132
|
+
// don't worry about not being able to delete, if it doesn't exist all good
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
// need to create webhook
|
|
136
|
+
if (
|
|
137
|
+
(!isWebhookTrigger(oldAuto) || triggerChanged) &&
|
|
138
|
+
isWebhookTrigger(newAuto)
|
|
139
|
+
) {
|
|
140
|
+
const ctx = {
|
|
141
|
+
appId,
|
|
142
|
+
request: {
|
|
143
|
+
body: new webhooks.Webhook(
|
|
144
|
+
"Automation webhook",
|
|
145
|
+
webhooks.WebhookType.AUTOMATION,
|
|
146
|
+
newAuto._id
|
|
147
|
+
),
|
|
148
|
+
},
|
|
149
|
+
}
|
|
150
|
+
await webhooks.save(ctx)
|
|
151
|
+
const id = ctx.body.webhook._id
|
|
152
|
+
newTrigger.webhookId = id
|
|
153
|
+
newTrigger.inputs = {
|
|
154
|
+
schemaUrl: `api/webhooks/schema/${appId}/${id}`,
|
|
155
|
+
triggerUrl: `api/webhooks/trigger/${appId}/${id}`,
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return newAuto
|
|
159
|
+
}
|