@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.
Files changed (266) hide show
  1. package/builder/assets/{index.dc48c234.js → index.a6e64238.js} +1 -1
  2. package/builder/index.html +1 -1
  3. package/coverage/clover.xml +1659 -1493
  4. package/coverage/coverage-final.json +101 -87
  5. package/coverage/lcov-report/api/controllers/analytics.js.html +3 -3
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  7. package/coverage/lcov-report/api/controllers/application.js.html +39 -39
  8. package/coverage/lcov-report/api/controllers/auth.js.html +6 -6
  9. package/coverage/lcov-report/api/controllers/automation.js.html +151 -361
  10. package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
  11. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/dev.js.html +15 -15
  14. package/coverage/lcov-report/api/controllers/hosting.js.html +8 -8
  15. package/coverage/lcov-report/api/controllers/index.html +39 -24
  16. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  17. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +218 -0
  19. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query.js.html +6 -12
  21. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  23. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/index.html +20 -20
  25. package/coverage/lcov-report/api/controllers/row/index.js.html +14 -14
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +95 -62
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/utils.js.html +10 -10
  29. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/index.js.html +24 -24
  33. package/coverage/lcov-report/api/controllers/table/utils.js.html +32 -32
  34. package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
  35. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  41. package/coverage/lcov-report/api/index.html +1 -1
  42. package/coverage/lcov-report/api/index.js.html +23 -23
  43. package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
  44. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  45. package/coverage/lcov-report/api/routes/application.js.html +8 -8
  46. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  47. package/coverage/lcov-report/api/routes/automation.js.html +41 -26
  48. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  49. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  50. package/coverage/lcov-report/api/routes/datasource.js.html +13 -13
  51. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/dev.js.html +11 -11
  53. package/coverage/lcov-report/api/routes/hosting.js.html +8 -8
  54. package/coverage/lcov-report/api/routes/index.html +24 -9
  55. package/coverage/lcov-report/api/routes/index.js.html +36 -30
  56. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  57. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  58. package/coverage/lcov-report/api/routes/metadata.js.html +194 -0
  59. package/coverage/lcov-report/api/routes/permission.js.html +12 -12
  60. package/coverage/lcov-report/api/routes/query.js.html +13 -13
  61. package/coverage/lcov-report/api/routes/role.js.html +12 -12
  62. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  63. package/coverage/lcov-report/api/routes/row.js.html +10 -10
  64. package/coverage/lcov-report/api/routes/screen.js.html +11 -11
  65. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/static.js.html +13 -13
  67. package/coverage/lcov-report/api/routes/table.js.html +12 -12
  68. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  69. package/coverage/lcov-report/api/routes/user.js.html +9 -9
  70. package/coverage/lcov-report/api/routes/view.js.html +11 -11
  71. package/coverage/lcov-report/api/routes/webhook.js.html +11 -11
  72. package/coverage/lcov-report/automations/actions.js.html +38 -107
  73. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  74. package/coverage/lcov-report/automations/bullboard.js.html +46 -16
  75. package/coverage/lcov-report/automations/index.html +67 -67
  76. package/coverage/lcov-report/automations/index.js.html +26 -128
  77. package/coverage/lcov-report/automations/steps/bash.js.html +33 -12
  78. package/coverage/lcov-report/automations/steps/createRow.js.html +8 -8
  79. package/coverage/lcov-report/automations/steps/delay.js.html +45 -6
  80. package/coverage/lcov-report/automations/steps/deleteRow.js.html +8 -8
  81. package/coverage/lcov-report/automations/steps/discord.js.html +329 -0
  82. package/coverage/lcov-report/automations/steps/executeQuery.js.html +19 -31
  83. package/coverage/lcov-report/automations/steps/executeScript.js.html +18 -30
  84. package/coverage/lcov-report/automations/steps/filter.js.html +22 -19
  85. package/coverage/lcov-report/automations/steps/index.html +125 -65
  86. package/coverage/lcov-report/automations/steps/integromat.js.html +341 -0
  87. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +26 -32
  88. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +9 -9
  89. package/coverage/lcov-report/automations/steps/serverLog.js.html +20 -8
  90. package/coverage/lcov-report/automations/steps/{sendgridEmail.js.html → slack.js.html} +57 -87
  91. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  92. package/coverage/lcov-report/automations/steps/utils.js.html +188 -0
  93. package/coverage/lcov-report/automations/steps/zapier.js.html +332 -0
  94. package/coverage/lcov-report/automations/thread.js.html +79 -76
  95. package/coverage/lcov-report/automations/triggerInfo/app.js.html +173 -0
  96. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +173 -0
  97. package/coverage/lcov-report/automations/triggerInfo/index.html +201 -0
  98. package/coverage/lcov-report/automations/triggerInfo/index.js.html +125 -0
  99. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +176 -0
  100. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +200 -0
  101. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +200 -0
  102. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +188 -0
  103. package/coverage/lcov-report/automations/triggers.js.html +54 -819
  104. package/coverage/lcov-report/automations/utils.js.html +557 -0
  105. package/coverage/lcov-report/constants/index.html +5 -5
  106. package/coverage/lcov-report/constants/index.js.html +19 -4
  107. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  108. package/coverage/lcov-report/constants/screens.js.html +2 -2
  109. package/coverage/lcov-report/db/client.js.html +1 -1
  110. package/coverage/lcov-report/db/index.html +19 -19
  111. package/coverage/lcov-report/db/index.js.html +1 -1
  112. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +73 -73
  113. package/coverage/lcov-report/db/linkedRows/index.html +17 -17
  114. package/coverage/lcov-report/db/linkedRows/index.js.html +79 -115
  115. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +31 -31
  116. package/coverage/lcov-report/db/newid.js.html +2 -2
  117. package/coverage/lcov-report/db/utils.js.html +79 -28
  118. package/coverage/lcov-report/events/AutomationEmitter.js.html +7 -7
  119. package/coverage/lcov-report/events/index.html +1 -1
  120. package/coverage/lcov-report/events/index.js.html +2 -2
  121. package/coverage/lcov-report/events/utils.js.html +1 -1
  122. package/coverage/lcov-report/index.html +115 -100
  123. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  124. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  125. package/coverage/lcov-report/{automations/logic.js.html → middleware/appInfo.js.html} +35 -38
  126. package/coverage/lcov-report/middleware/authorized.js.html +16 -16
  127. package/coverage/lcov-report/middleware/builder.js.html +15 -15
  128. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  129. package/coverage/lcov-report/middleware/index.html +23 -8
  130. package/coverage/lcov-report/middleware/joi-validator.js.html +6 -6
  131. package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
  132. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  133. package/coverage/lcov-report/middleware/usageQuota.js.html +8 -8
  134. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  135. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  136. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  137. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  138. package/coverage/lcov-report/utilities/global.js.html +21 -21
  139. package/coverage/lcov-report/utilities/index.html +18 -18
  140. package/coverage/lcov-report/utilities/index.js.html +167 -14
  141. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +12 -12
  142. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  143. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  144. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  145. package/coverage/lcov-report/utilities/rowProcessor/index.html +14 -14
  146. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +87 -51
  147. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +8 -8
  148. package/coverage/lcov-report/utilities/security.js.html +2 -2
  149. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  150. package/coverage/lcov-report/utilities/users.js.html +1 -1
  151. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  152. package/coverage/lcov.info +2641 -2357
  153. package/dist/api/controllers/automation.js +49 -127
  154. package/dist/api/controllers/deploy/index.js +17 -1
  155. package/dist/api/controllers/metadata.js +49 -0
  156. package/dist/api/controllers/query.js +0 -2
  157. package/dist/api/controllers/row/internal.js +33 -23
  158. package/dist/api/routes/automation.js +4 -5
  159. package/dist/api/routes/index.js +2 -0
  160. package/dist/api/routes/metadata.js +13 -0
  161. package/dist/api/routes/tests/utilities/TestFunctions.js +13 -0
  162. package/dist/app.js +1 -1
  163. package/dist/automations/actions.js +26 -46
  164. package/dist/automations/bullboard.js +10 -2
  165. package/dist/automations/index.js +11 -48
  166. package/dist/automations/steps/bash.js +11 -5
  167. package/dist/automations/steps/createRow.js +4 -4
  168. package/dist/automations/steps/delay.js +15 -2
  169. package/dist/automations/steps/deleteRow.js +4 -4
  170. package/dist/automations/steps/discord.js +91 -0
  171. package/dist/automations/steps/executeQuery.js +11 -14
  172. package/dist/automations/steps/executeScript.js +11 -14
  173. package/dist/automations/steps/filter.js +18 -17
  174. package/dist/automations/steps/integromat.js +94 -0
  175. package/dist/automations/steps/outgoingWebhook.js +12 -16
  176. package/dist/automations/steps/sendSmtpEmail.js +3 -3
  177. package/dist/automations/steps/serverLog.js +6 -2
  178. package/dist/automations/steps/slack.js +73 -0
  179. package/dist/automations/steps/updateRow.js +3 -3
  180. package/dist/automations/steps/utils.js +46 -0
  181. package/dist/automations/steps/zapier.js +91 -0
  182. package/dist/automations/tests/utilities/index.js +2 -12
  183. package/dist/automations/thread.js +23 -25
  184. package/dist/automations/triggerInfo/app.js +32 -0
  185. package/dist/automations/triggerInfo/cron.js +32 -0
  186. package/dist/automations/triggerInfo/index.js +15 -0
  187. package/dist/automations/triggerInfo/rowDeleted.js +33 -0
  188. package/dist/automations/triggerInfo/rowSaved.js +41 -0
  189. package/dist/automations/triggerInfo/rowUpdated.js +41 -0
  190. package/dist/automations/triggerInfo/webhook.js +37 -0
  191. package/dist/automations/triggers.js +27 -284
  192. package/dist/automations/utils.js +143 -0
  193. package/dist/constants/index.js +4 -0
  194. package/dist/db/linkedRows/index.js +14 -26
  195. package/dist/db/utils.js +14 -1
  196. package/dist/environment.js +1 -0
  197. package/dist/middleware/appInfo.js +17 -0
  198. package/dist/middleware/usageQuota.js +1 -1
  199. package/dist/package.json +4 -5
  200. package/dist/tsconfig.tsbuildinfo +1 -1
  201. package/dist/utilities/fileSystem/index.js +0 -26
  202. package/dist/utilities/index.js +54 -0
  203. package/dist/utilities/redis.js +16 -1
  204. package/dist/utilities/rowProcessor/index.js +7 -4
  205. package/package.json +5 -6
  206. package/src/api/controllers/automation.js +75 -145
  207. package/src/api/controllers/deploy/index.js +23 -1
  208. package/src/api/controllers/metadata.js +46 -0
  209. package/src/api/controllers/query.js +0 -2
  210. package/src/api/controllers/row/internal.js +34 -23
  211. package/src/api/routes/automation.js +16 -11
  212. package/src/api/routes/index.js +2 -0
  213. package/src/api/routes/metadata.js +38 -0
  214. package/src/api/routes/tests/automation.spec.js +4 -26
  215. package/src/api/routes/tests/metadata.spec.js +65 -0
  216. package/src/api/routes/tests/utilities/TestFunctions.js +14 -0
  217. package/src/app.ts +1 -1
  218. package/src/automations/actions.js +26 -49
  219. package/src/automations/bullboard.js +12 -2
  220. package/src/automations/index.js +11 -45
  221. package/src/automations/steps/bash.js +12 -5
  222. package/src/automations/steps/createRow.js +4 -4
  223. package/src/automations/steps/delay.js +15 -2
  224. package/src/automations/steps/deleteRow.js +4 -4
  225. package/src/automations/steps/discord.js +83 -0
  226. package/src/automations/steps/executeQuery.js +11 -15
  227. package/src/automations/steps/executeScript.js +11 -15
  228. package/src/automations/steps/filter.js +18 -17
  229. package/src/automations/steps/integromat.js +87 -0
  230. package/src/automations/steps/outgoingWebhook.js +12 -14
  231. package/src/automations/steps/sendSmtpEmail.js +3 -3
  232. package/src/automations/steps/serverLog.js +6 -2
  233. package/src/automations/steps/slack.js +64 -0
  234. package/src/automations/steps/updateRow.js +3 -3
  235. package/src/automations/steps/utils.js +36 -0
  236. package/src/automations/steps/zapier.js +84 -0
  237. package/src/automations/tests/automation.spec.js +3 -66
  238. package/src/automations/tests/delay.spec.js +1 -1
  239. package/src/automations/tests/filter.spec.js +13 -13
  240. package/src/automations/tests/utilities/index.js +2 -13
  241. package/src/automations/thread.js +27 -26
  242. package/src/automations/triggerInfo/app.js +31 -0
  243. package/src/automations/triggerInfo/cron.js +31 -0
  244. package/src/automations/triggerInfo/index.js +15 -0
  245. package/src/automations/triggerInfo/rowDeleted.js +32 -0
  246. package/src/automations/triggerInfo/rowSaved.js +40 -0
  247. package/src/automations/triggerInfo/rowUpdated.js +40 -0
  248. package/src/automations/triggerInfo/webhook.js +36 -0
  249. package/src/automations/triggers.js +33 -288
  250. package/src/automations/utils.js +159 -0
  251. package/src/constants/index.js +5 -0
  252. package/src/db/linkedRows/index.js +15 -27
  253. package/src/db/tests/linkTests.spec.js +0 -12
  254. package/src/db/utils.js +17 -0
  255. package/src/environment.js +1 -0
  256. package/src/middleware/appInfo.js +19 -0
  257. package/src/middleware/usageQuota.js +1 -1
  258. package/src/utilities/fileSystem/index.js +0 -30
  259. package/src/utilities/index.js +51 -0
  260. package/src/utilities/redis.js +18 -1
  261. package/src/utilities/rowProcessor/index.js +16 -4
  262. package/dist/automations/logic.js +0 -17
  263. package/dist/automations/steps/sendgridEmail.js +0 -85
  264. package/src/automations/logic.js +0 -20
  265. package/src/automations/steps/sendgridEmail.js +0 -74
  266. package/src/automations/tests/sendEmail.spec.js +0 -36
@@ -1,14 +1,22 @@
1
1
  const { createBullBoard } = require("bull-board")
2
2
  const { BullAdapter } = require("bull-board/bullAdapter")
3
- const { getQueues } = require("./triggers")
4
3
  const express = require("express")
4
+ const env = require("../environment")
5
+ const Queue = env.isTest()
6
+ ? require("../utilities/queue/inMemoryQueue")
7
+ : require("bull")
8
+ const { JobQueues } = require("../constants")
9
+ const { utils } = require("@budibase/auth/redis")
10
+ const { opts } = utils.getRedisOptions()
11
+
12
+ let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts })
5
13
 
6
14
  exports.pathPrefix = "/bulladmin"
7
15
 
8
16
  exports.init = () => {
9
17
  const expressApp = express()
10
18
  // Set up queues for bull board admin
11
- const queues = getQueues()
19
+ const queues = [automationQueue]
12
20
  const adapters = []
13
21
  for (let queue of queues) {
14
22
  adapters.push(new BullAdapter(queue))
@@ -18,3 +26,5 @@ exports.init = () => {
18
26
  expressApp.use(exports.pathPrefix, router)
19
27
  return expressApp
20
28
  }
29
+
30
+ exports.queue = automationQueue
@@ -1,51 +1,17 @@
1
- const triggers = require("./triggers")
2
- const actions = require("./actions")
3
- const env = require("../environment")
4
- const workerFarm = require("worker-farm")
5
- const singleThread = require("./thread")
6
- const { getAPIKey, update, Properties } = require("../utilities/usageQuota")
7
-
8
- let workers = workerFarm(require.resolve("./thread"))
9
-
10
- function runWorker(job) {
11
- return new Promise((resolve, reject) => {
12
- workers(job, err => {
13
- if (err) {
14
- reject(err)
15
- } else {
16
- resolve()
17
- }
18
- })
19
- })
20
- }
21
-
22
- async function updateQuota(automation) {
23
- const appId = automation.appId
24
- const apiObj = await getAPIKey(appId)
25
- // this will fail, causing automation to escape if limits reached
26
- await update(apiObj.apiKey, Properties.AUTOMATION, 1)
27
- return apiObj.apiKey
28
- }
1
+ const { processEvent } = require("./utils")
2
+ const { queue } = require("./bullboard")
29
3
 
30
4
  /**
31
5
  * This module is built purely to kick off the worker farm and manage the inputs/outputs
32
6
  */
33
- module.exports.init = async function () {
34
- await actions.init()
35
- triggers.automationQueue.process(async job => {
36
- try {
37
- if (env.USE_QUOTAS) {
38
- job.data.automation.apiKey = await updateQuota(job.data.automation)
39
- }
40
- if (env.isProd()) {
41
- await runWorker(job)
42
- } else {
43
- await singleThread(job)
44
- }
45
- } catch (err) {
46
- console.error(
47
- `${job.data.automation.appId} automation ${job.data.automation._id} was unable to run - ${err}`
48
- )
49
- }
7
+ exports.init = function () {
8
+ // this promise will not complete
9
+ return queue.process(async job => {
10
+ await processEvent(job)
50
11
  })
51
12
  }
13
+
14
+ exports.getQueues = () => {
15
+ return [queue]
16
+ }
17
+ exports.queue = queue
@@ -1,12 +1,13 @@
1
1
  const { execSync } = require("child_process")
2
2
  const { processStringSync } = require("@budibase/string-templates")
3
3
 
4
- module.exports.definition = {
4
+ exports.definition = {
5
5
  name: "Bash Scripting",
6
6
  tagline: "Execute a bash command",
7
7
  icon: "ri-terminal-box-line",
8
8
  description: "Run a bash script",
9
9
  type: "ACTION",
10
+ internal: true,
10
11
  stepId: "EXECUTE_BASH",
11
12
  inputs: {},
12
13
  schema: {
@@ -24,7 +25,11 @@ module.exports.definition = {
24
25
  properties: {
25
26
  stdout: {
26
27
  type: "string",
27
- description: "Standard output of your bash command or script.",
28
+ description: "Standard output of your bash command or script",
29
+ },
30
+ success: {
31
+ type: "boolean",
32
+ description: "Whether the command was successful",
28
33
  },
29
34
  },
30
35
  },
@@ -32,7 +37,7 @@ module.exports.definition = {
32
37
  },
33
38
  }
34
39
 
35
- module.exports.run = async function ({ inputs, context }) {
40
+ exports.run = async function ({ inputs, context }) {
36
41
  if (inputs.code == null) {
37
42
  return {
38
43
  stdout: "Budibase bash automation failed: Invalid inputs",
@@ -42,18 +47,20 @@ module.exports.run = async function ({ inputs, context }) {
42
47
  try {
43
48
  const command = processStringSync(inputs.code, context)
44
49
 
45
- let stdout
50
+ let stdout,
51
+ success = true
46
52
  try {
47
53
  stdout = execSync(command, { timeout: 500 })
48
54
  } catch (err) {
49
55
  stdout = err.message
56
+ success = false
50
57
  }
51
58
 
52
59
  return {
53
60
  stdout,
61
+ success,
54
62
  }
55
63
  } catch (err) {
56
- console.error(err)
57
64
  return {
58
65
  success: false,
59
66
  response: err,
@@ -3,12 +3,13 @@ const automationUtils = require("../automationUtils")
3
3
  const env = require("../../environment")
4
4
  const usage = require("../../utilities/usageQuota")
5
5
 
6
- module.exports.definition = {
6
+ exports.definition = {
7
7
  name: "Create Row",
8
8
  tagline: "Create a {{inputs.enriched.table.name}} row",
9
9
  icon: "ri-save-3-line",
10
10
  description: "Add a row to your database",
11
11
  type: "ACTION",
12
+ internal: true,
12
13
  stepId: "CREATE_ROW",
13
14
  inputs: {},
14
15
  schema: {
@@ -42,7 +43,7 @@ module.exports.definition = {
42
43
  },
43
44
  success: {
44
45
  type: "boolean",
45
- description: "Whether the action was successful",
46
+ description: "Whether the row creation was successful",
46
47
  },
47
48
  id: {
48
49
  type: "string",
@@ -58,7 +59,7 @@ module.exports.definition = {
58
59
  },
59
60
  }
60
61
 
61
- module.exports.run = async function ({ inputs, appId, apiKey, emitter }) {
62
+ exports.run = async function ({ inputs, appId, apiKey, emitter }) {
62
63
  if (inputs.row == null || inputs.row.tableId == null) {
63
64
  return {
64
65
  success: false,
@@ -97,7 +98,6 @@ module.exports.run = async function ({ inputs, appId, apiKey, emitter }) {
97
98
  success: ctx.status === 200,
98
99
  }
99
100
  } catch (err) {
100
- console.error(err)
101
101
  return {
102
102
  success: false,
103
103
  response: err,
@@ -1,11 +1,12 @@
1
1
  let { wait } = require("../../utilities")
2
2
 
3
- module.exports.definition = {
3
+ exports.definition = {
4
4
  name: "Delay",
5
5
  icon: "ri-time-line",
6
6
  tagline: "Delay for {{inputs.time}} milliseconds",
7
7
  description: "Delay the automation until an amount of time has passed",
8
8
  stepId: "DELAY",
9
+ internal: true,
9
10
  inputs: {},
10
11
  schema: {
11
12
  inputs: {
@@ -17,10 +18,22 @@ module.exports.definition = {
17
18
  },
18
19
  required: ["time"],
19
20
  },
21
+ outputs: {
22
+ properties: {
23
+ success: {
24
+ type: "boolean",
25
+ description: "Whether the delay was successful",
26
+ },
27
+ },
28
+ required: ["success"],
29
+ },
20
30
  },
21
31
  type: "LOGIC",
22
32
  }
23
33
 
24
- module.exports.run = async function delay({ inputs }) {
34
+ exports.run = async function delay({ inputs }) {
25
35
  await wait(inputs.time)
36
+ return {
37
+ success: true,
38
+ }
26
39
  }
@@ -2,13 +2,14 @@ const rowController = require("../../api/controllers/row")
2
2
  const env = require("../../environment")
3
3
  const usage = require("../../utilities/usageQuota")
4
4
 
5
- module.exports.definition = {
5
+ exports.definition = {
6
6
  description: "Delete a row from your database",
7
7
  icon: "ri-delete-bin-line",
8
8
  name: "Delete Row",
9
9
  tagline: "Delete a {{inputs.enriched.table.name}} row",
10
10
  type: "ACTION",
11
11
  stepId: "DELETE_ROW",
12
+ internal: true,
12
13
  inputs: {},
13
14
  schema: {
14
15
  inputs: {
@@ -42,7 +43,7 @@ module.exports.definition = {
42
43
  },
43
44
  success: {
44
45
  type: "boolean",
45
- description: "Whether the action was successful",
46
+ description: "Whether the deletion was successful",
46
47
  },
47
48
  },
48
49
  required: ["row", "success"],
@@ -50,7 +51,7 @@ module.exports.definition = {
50
51
  },
51
52
  }
52
53
 
53
- module.exports.run = async function ({ inputs, appId, apiKey, emitter }) {
54
+ exports.run = async function ({ inputs, appId, apiKey, emitter }) {
54
55
  if (inputs.id == null || inputs.revision == null) {
55
56
  return {
56
57
  success: false,
@@ -84,7 +85,6 @@ module.exports.run = async function ({ inputs, appId, apiKey, emitter }) {
84
85
  success: ctx.status === 200,
85
86
  }
86
87
  } catch (err) {
87
- console.error(err)
88
88
  return {
89
89
  success: false,
90
90
  response: err,
@@ -0,0 +1,83 @@
1
+ const fetch = require("node-fetch")
2
+ const { getFetchResponse } = require("./utils")
3
+
4
+ const DEFAULT_USERNAME = "Budibase Automate"
5
+ const DEFAULT_AVATAR_URL = "https://i.imgur.com/a1cmTKM.png"
6
+
7
+ exports.definition = {
8
+ name: "Discord Message",
9
+ tagline: "Send a message to a Discord server",
10
+ description: "Send a message to a Discord server",
11
+ icon: "ri-discord-line",
12
+ stepId: "discord",
13
+ type: "ACTION",
14
+ internal: false,
15
+ inputs: {},
16
+ schema: {
17
+ inputs: {
18
+ properties: {
19
+ url: {
20
+ type: "string",
21
+ title: "Discord Webhook URL",
22
+ },
23
+ username: {
24
+ type: "string",
25
+ title: "Bot Name",
26
+ },
27
+ avatar_url: {
28
+ type: "string",
29
+ title: "Bot Avatar URL",
30
+ },
31
+ content: {
32
+ type: "string",
33
+ title: "Message",
34
+ },
35
+ },
36
+ required: ["url", "content"],
37
+ },
38
+ outputs: {
39
+ properties: {
40
+ httpStatus: {
41
+ type: "number",
42
+ description: "The HTTP status code of the request",
43
+ },
44
+ response: {
45
+ type: "string",
46
+ description: "The response from the Discord Webhook",
47
+ },
48
+ success: {
49
+ type: "boolean",
50
+ description: "Whether the message sent successfully",
51
+ },
52
+ },
53
+ },
54
+ },
55
+ }
56
+
57
+ exports.run = async function ({ inputs }) {
58
+ let { url, username, avatar_url, content } = inputs
59
+ if (!username) {
60
+ username = DEFAULT_USERNAME
61
+ }
62
+ if (!avatar_url) {
63
+ avatar_url = DEFAULT_AVATAR_URL
64
+ }
65
+ const response = await fetch(url, {
66
+ method: "post",
67
+ body: JSON.stringify({
68
+ username,
69
+ avatar_url,
70
+ content,
71
+ }),
72
+ headers: {
73
+ "Content-Type": "application/json",
74
+ },
75
+ })
76
+
77
+ const { status, message } = await getFetchResponse(response)
78
+ return {
79
+ httpStatus: status,
80
+ success: status === 200,
81
+ response: message,
82
+ }
83
+ }
@@ -1,12 +1,14 @@
1
1
  const queryController = require("../../api/controllers/query")
2
+ const { buildCtx } = require("./utils")
2
3
 
3
- module.exports.definition = {
4
+ exports.definition = {
4
5
  name: "External Data Connector",
5
6
  tagline: "Execute Data Connector",
6
7
  icon: "ri-database-2-line",
7
8
  description: "Execute a query in an external data connector",
8
9
  type: "ACTION",
9
10
  stepId: "EXECUTE_QUERY",
11
+ internal: true,
10
12
  inputs: {},
11
13
  schema: {
12
14
  inputs: {
@@ -42,7 +44,7 @@ module.exports.definition = {
42
44
  },
43
45
  }
44
46
 
45
- module.exports.run = async function ({ inputs, appId, emitter }) {
47
+ exports.run = async function ({ inputs, appId, emitter }) {
46
48
  if (inputs.query == null) {
47
49
  return {
48
50
  success: false,
@@ -54,28 +56,22 @@ module.exports.run = async function ({ inputs, appId, emitter }) {
54
56
 
55
57
  const { queryId, ...rest } = inputs.query
56
58
 
57
- const ctx = {
59
+ const ctx = buildCtx(appId, emitter, {
60
+ body: {
61
+ parameters: rest,
62
+ },
58
63
  params: {
59
64
  queryId,
60
65
  },
61
- request: {
62
- body: {
63
- parameters: rest,
64
- },
65
- },
66
- appId,
67
- eventEmitter: emitter,
68
- }
69
-
70
- await queryController.execute(ctx)
66
+ })
71
67
 
72
68
  try {
69
+ await queryController.execute(ctx)
73
70
  return {
74
71
  response: ctx.body,
75
- success: ctx.status === 200,
72
+ success: true,
76
73
  }
77
74
  } catch (err) {
78
- console.error(err)
79
75
  return {
80
76
  success: false,
81
77
  response: err,
@@ -1,11 +1,13 @@
1
1
  const scriptController = require("../../api/controllers/script")
2
+ const { buildCtx } = require("./utils")
2
3
 
3
- module.exports.definition = {
4
+ exports.definition = {
4
5
  name: "JS Scripting",
5
6
  tagline: "Execute JavaScript Code",
6
7
  icon: "ri-terminal-box-line",
7
8
  description: "Run a piece of JavaScript code in your automation",
8
9
  type: "ACTION",
10
+ internal: true,
9
11
  stepId: "EXECUTE_SCRIPT",
10
12
  inputs: {},
11
13
  schema: {
@@ -23,8 +25,7 @@ module.exports.definition = {
23
25
  properties: {
24
26
  value: {
25
27
  type: "string",
26
- description:
27
- "The result of the last statement of the executed script.",
28
+ description: "The result of the return statement",
28
29
  },
29
30
  success: {
30
31
  type: "boolean",
@@ -36,7 +37,7 @@ module.exports.definition = {
36
37
  },
37
38
  }
38
39
 
39
- module.exports.run = async function ({ inputs, appId, context, emitter }) {
40
+ exports.run = async function ({ inputs, appId, context, emitter }) {
40
41
  if (inputs.code == null) {
41
42
  return {
42
43
  success: false,
@@ -46,25 +47,20 @@ module.exports.run = async function ({ inputs, appId, context, emitter }) {
46
47
  }
47
48
  }
48
49
 
49
- const ctx = {
50
- request: {
51
- body: {
52
- script: inputs.code,
53
- context,
54
- },
50
+ const ctx = buildCtx(appId, emitter, {
51
+ body: {
52
+ script: inputs.code,
53
+ context,
55
54
  },
56
- user: { appId },
57
- eventEmitter: emitter,
58
- }
55
+ })
59
56
 
60
57
  try {
61
58
  await scriptController.execute(ctx)
62
59
  return {
63
- success: ctx.status === 200,
60
+ success: true,
64
61
  value: ctx.body,
65
62
  }
66
63
  } catch (err) {
67
- console.error(err)
68
64
  return {
69
65
  success: false,
70
66
  response: err,