@budibase/server 0.9.125-alpha.4 → 0.9.125-alpha.8

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 (270) hide show
  1. package/builder/assets/{index.dc48c234.js → index.cf133375.js} +2 -2
  2. package/builder/assets/{vendor.4af73c18.js → vendor.d8e1ee7b.js} +1 -1
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +1659 -1493
  5. package/coverage/coverage-final.json +101 -87
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +3 -3
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  8. package/coverage/lcov-report/api/controllers/application.js.html +39 -39
  9. package/coverage/lcov-report/api/controllers/auth.js.html +6 -6
  10. package/coverage/lcov-report/api/controllers/automation.js.html +151 -361
  11. package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
  12. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/dev.js.html +15 -15
  15. package/coverage/lcov-report/api/controllers/hosting.js.html +8 -8
  16. package/coverage/lcov-report/api/controllers/index.html +39 -24
  17. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  18. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/metadata.js.html +218 -0
  20. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query.js.html +6 -12
  22. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/index.html +20 -20
  26. package/coverage/lcov-report/api/controllers/row/index.js.html +14 -14
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +95 -62
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +10 -10
  30. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/index.js.html +24 -24
  34. package/coverage/lcov-report/api/controllers/table/utils.js.html +32 -32
  35. package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
  36. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  42. package/coverage/lcov-report/api/index.html +1 -1
  43. package/coverage/lcov-report/api/index.js.html +23 -23
  44. package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
  45. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  46. package/coverage/lcov-report/api/routes/application.js.html +8 -8
  47. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  48. package/coverage/lcov-report/api/routes/automation.js.html +41 -26
  49. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  50. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/datasource.js.html +13 -13
  52. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  53. package/coverage/lcov-report/api/routes/dev.js.html +11 -11
  54. package/coverage/lcov-report/api/routes/hosting.js.html +8 -8
  55. package/coverage/lcov-report/api/routes/index.html +24 -9
  56. package/coverage/lcov-report/api/routes/index.js.html +36 -30
  57. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  58. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/metadata.js.html +194 -0
  60. package/coverage/lcov-report/api/routes/permission.js.html +12 -12
  61. package/coverage/lcov-report/api/routes/query.js.html +13 -13
  62. package/coverage/lcov-report/api/routes/role.js.html +12 -12
  63. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  64. package/coverage/lcov-report/api/routes/row.js.html +10 -10
  65. package/coverage/lcov-report/api/routes/screen.js.html +11 -11
  66. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/static.js.html +13 -13
  68. package/coverage/lcov-report/api/routes/table.js.html +12 -12
  69. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  70. package/coverage/lcov-report/api/routes/user.js.html +9 -9
  71. package/coverage/lcov-report/api/routes/view.js.html +11 -11
  72. package/coverage/lcov-report/api/routes/webhook.js.html +11 -11
  73. package/coverage/lcov-report/automations/actions.js.html +38 -107
  74. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  75. package/coverage/lcov-report/automations/bullboard.js.html +46 -16
  76. package/coverage/lcov-report/automations/index.html +67 -67
  77. package/coverage/lcov-report/automations/index.js.html +26 -128
  78. package/coverage/lcov-report/automations/steps/bash.js.html +33 -12
  79. package/coverage/lcov-report/automations/steps/createRow.js.html +8 -8
  80. package/coverage/lcov-report/automations/steps/delay.js.html +45 -6
  81. package/coverage/lcov-report/automations/steps/deleteRow.js.html +8 -8
  82. package/coverage/lcov-report/automations/steps/discord.js.html +329 -0
  83. package/coverage/lcov-report/automations/steps/executeQuery.js.html +19 -31
  84. package/coverage/lcov-report/automations/steps/executeScript.js.html +18 -30
  85. package/coverage/lcov-report/automations/steps/filter.js.html +22 -19
  86. package/coverage/lcov-report/automations/steps/index.html +125 -65
  87. package/coverage/lcov-report/automations/steps/integromat.js.html +341 -0
  88. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +26 -32
  89. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +9 -9
  90. package/coverage/lcov-report/automations/steps/serverLog.js.html +20 -8
  91. package/coverage/lcov-report/automations/steps/{sendgridEmail.js.html → slack.js.html} +57 -87
  92. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  93. package/coverage/lcov-report/automations/steps/utils.js.html +188 -0
  94. package/coverage/lcov-report/automations/steps/zapier.js.html +332 -0
  95. package/coverage/lcov-report/automations/thread.js.html +79 -76
  96. package/coverage/lcov-report/automations/triggerInfo/app.js.html +173 -0
  97. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +173 -0
  98. package/coverage/lcov-report/automations/triggerInfo/index.html +201 -0
  99. package/coverage/lcov-report/automations/triggerInfo/index.js.html +125 -0
  100. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +176 -0
  101. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +200 -0
  102. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +200 -0
  103. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +188 -0
  104. package/coverage/lcov-report/automations/triggers.js.html +54 -819
  105. package/coverage/lcov-report/automations/utils.js.html +557 -0
  106. package/coverage/lcov-report/constants/index.html +5 -5
  107. package/coverage/lcov-report/constants/index.js.html +19 -4
  108. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  109. package/coverage/lcov-report/constants/screens.js.html +2 -2
  110. package/coverage/lcov-report/db/client.js.html +1 -1
  111. package/coverage/lcov-report/db/index.html +19 -19
  112. package/coverage/lcov-report/db/index.js.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +73 -73
  114. package/coverage/lcov-report/db/linkedRows/index.html +17 -17
  115. package/coverage/lcov-report/db/linkedRows/index.js.html +79 -115
  116. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +31 -31
  117. package/coverage/lcov-report/db/newid.js.html +2 -2
  118. package/coverage/lcov-report/db/utils.js.html +79 -28
  119. package/coverage/lcov-report/events/AutomationEmitter.js.html +7 -7
  120. package/coverage/lcov-report/events/index.html +1 -1
  121. package/coverage/lcov-report/events/index.js.html +2 -2
  122. package/coverage/lcov-report/events/utils.js.html +1 -1
  123. package/coverage/lcov-report/index.html +115 -100
  124. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  125. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  126. package/coverage/lcov-report/{automations/logic.js.html → middleware/appInfo.js.html} +35 -38
  127. package/coverage/lcov-report/middleware/authorized.js.html +16 -16
  128. package/coverage/lcov-report/middleware/builder.js.html +15 -15
  129. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  130. package/coverage/lcov-report/middleware/index.html +23 -8
  131. package/coverage/lcov-report/middleware/joi-validator.js.html +6 -6
  132. package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
  133. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  134. package/coverage/lcov-report/middleware/usageQuota.js.html +8 -8
  135. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  136. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  137. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  138. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  139. package/coverage/lcov-report/utilities/global.js.html +21 -21
  140. package/coverage/lcov-report/utilities/index.html +18 -18
  141. package/coverage/lcov-report/utilities/index.js.html +167 -14
  142. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +12 -12
  143. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  144. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  145. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  146. package/coverage/lcov-report/utilities/rowProcessor/index.html +14 -14
  147. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +87 -51
  148. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +8 -8
  149. package/coverage/lcov-report/utilities/security.js.html +2 -2
  150. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  151. package/coverage/lcov-report/utilities/users.js.html +1 -1
  152. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  153. package/coverage/lcov.info +2641 -2357
  154. package/dist/api/controllers/automation.js +49 -127
  155. package/dist/api/controllers/deploy/index.js +17 -1
  156. package/dist/api/controllers/metadata.js +49 -0
  157. package/dist/api/controllers/query.js +0 -2
  158. package/dist/api/controllers/row/internal.js +33 -23
  159. package/dist/api/routes/automation.js +4 -5
  160. package/dist/api/routes/index.js +2 -0
  161. package/dist/api/routes/metadata.js +13 -0
  162. package/dist/api/routes/tests/utilities/TestFunctions.js +13 -0
  163. package/dist/app.js +1 -1
  164. package/dist/automations/actions.js +26 -46
  165. package/dist/automations/bullboard.js +10 -2
  166. package/dist/automations/index.js +11 -48
  167. package/dist/automations/steps/bash.js +11 -5
  168. package/dist/automations/steps/createRow.js +4 -4
  169. package/dist/automations/steps/delay.js +15 -2
  170. package/dist/automations/steps/deleteRow.js +4 -4
  171. package/dist/automations/steps/discord.js +91 -0
  172. package/dist/automations/steps/executeQuery.js +11 -14
  173. package/dist/automations/steps/executeScript.js +11 -14
  174. package/dist/automations/steps/filter.js +18 -17
  175. package/dist/automations/steps/integromat.js +94 -0
  176. package/dist/automations/steps/outgoingWebhook.js +12 -16
  177. package/dist/automations/steps/sendSmtpEmail.js +3 -3
  178. package/dist/automations/steps/serverLog.js +6 -2
  179. package/dist/automations/steps/slack.js +73 -0
  180. package/dist/automations/steps/updateRow.js +3 -3
  181. package/dist/automations/steps/utils.js +46 -0
  182. package/dist/automations/steps/zapier.js +91 -0
  183. package/dist/automations/tests/utilities/index.js +2 -12
  184. package/dist/automations/thread.js +23 -25
  185. package/dist/automations/triggerInfo/app.js +32 -0
  186. package/dist/automations/triggerInfo/cron.js +32 -0
  187. package/dist/automations/triggerInfo/index.js +15 -0
  188. package/dist/automations/triggerInfo/rowDeleted.js +33 -0
  189. package/dist/automations/triggerInfo/rowSaved.js +41 -0
  190. package/dist/automations/triggerInfo/rowUpdated.js +41 -0
  191. package/dist/automations/triggerInfo/webhook.js +37 -0
  192. package/dist/automations/triggers.js +27 -284
  193. package/dist/automations/utils.js +143 -0
  194. package/dist/constants/index.js +4 -0
  195. package/dist/db/linkedRows/index.js +14 -26
  196. package/dist/db/utils.js +14 -1
  197. package/dist/environment.js +1 -0
  198. package/dist/integrations/mysql.js +1 -1
  199. package/dist/middleware/appInfo.js +17 -0
  200. package/dist/middleware/usageQuota.js +1 -1
  201. package/dist/package.json +7 -6
  202. package/dist/tsconfig.tsbuildinfo +1 -1
  203. package/dist/utilities/fileSystem/index.js +0 -26
  204. package/dist/utilities/index.js +54 -0
  205. package/dist/utilities/redis.js +16 -1
  206. package/dist/utilities/rowProcessor/index.js +7 -4
  207. package/package.json +8 -7
  208. package/scripts/selfhost.js +8 -0
  209. package/src/api/controllers/automation.js +75 -145
  210. package/src/api/controllers/deploy/index.js +23 -1
  211. package/src/api/controllers/metadata.js +46 -0
  212. package/src/api/controllers/query.js +0 -2
  213. package/src/api/controllers/row/internal.js +34 -23
  214. package/src/api/routes/automation.js +16 -11
  215. package/src/api/routes/index.js +2 -0
  216. package/src/api/routes/metadata.js +38 -0
  217. package/src/api/routes/tests/automation.spec.js +4 -26
  218. package/src/api/routes/tests/metadata.spec.js +65 -0
  219. package/src/api/routes/tests/utilities/TestFunctions.js +14 -0
  220. package/src/app.ts +1 -1
  221. package/src/automations/actions.js +26 -49
  222. package/src/automations/bullboard.js +12 -2
  223. package/src/automations/index.js +11 -45
  224. package/src/automations/steps/bash.js +12 -5
  225. package/src/automations/steps/createRow.js +4 -4
  226. package/src/automations/steps/delay.js +15 -2
  227. package/src/automations/steps/deleteRow.js +4 -4
  228. package/src/automations/steps/discord.js +83 -0
  229. package/src/automations/steps/executeQuery.js +11 -15
  230. package/src/automations/steps/executeScript.js +11 -15
  231. package/src/automations/steps/filter.js +18 -17
  232. package/src/automations/steps/integromat.js +87 -0
  233. package/src/automations/steps/outgoingWebhook.js +12 -14
  234. package/src/automations/steps/sendSmtpEmail.js +3 -3
  235. package/src/automations/steps/serverLog.js +6 -2
  236. package/src/automations/steps/slack.js +64 -0
  237. package/src/automations/steps/updateRow.js +3 -3
  238. package/src/automations/steps/utils.js +36 -0
  239. package/src/automations/steps/zapier.js +84 -0
  240. package/src/automations/tests/automation.spec.js +3 -66
  241. package/src/automations/tests/delay.spec.js +1 -1
  242. package/src/automations/tests/filter.spec.js +13 -13
  243. package/src/automations/tests/utilities/index.js +2 -13
  244. package/src/automations/thread.js +27 -26
  245. package/src/automations/triggerInfo/app.js +31 -0
  246. package/src/automations/triggerInfo/cron.js +31 -0
  247. package/src/automations/triggerInfo/index.js +15 -0
  248. package/src/automations/triggerInfo/rowDeleted.js +32 -0
  249. package/src/automations/triggerInfo/rowSaved.js +40 -0
  250. package/src/automations/triggerInfo/rowUpdated.js +40 -0
  251. package/src/automations/triggerInfo/webhook.js +36 -0
  252. package/src/automations/triggers.js +33 -288
  253. package/src/automations/utils.js +159 -0
  254. package/src/constants/index.js +5 -0
  255. package/src/db/linkedRows/index.js +15 -27
  256. package/src/db/tests/linkTests.spec.js +0 -12
  257. package/src/db/utils.js +17 -0
  258. package/src/environment.js +1 -0
  259. package/src/integrations/mysql.ts +1 -1
  260. package/src/middleware/appInfo.js +19 -0
  261. package/src/middleware/usageQuota.js +1 -1
  262. package/src/utilities/fileSystem/index.js +0 -30
  263. package/src/utilities/index.js +51 -0
  264. package/src/utilities/redis.js +18 -1
  265. package/src/utilities/rowProcessor/index.js +16 -4
  266. package/dist/automations/logic.js +0 -17
  267. package/dist/automations/steps/sendgridEmail.js +0 -85
  268. package/src/automations/logic.js +0 -20
  269. package/src/automations/steps/sendgridEmail.js +0 -74
  270. package/src/automations/tests/sendEmail.spec.js +0 -36
package/src/app.ts CHANGED
@@ -88,8 +88,8 @@ module.exports = server.listen(env.PORT || 0, async () => {
88
88
  env._set("PORT", server.address().port)
89
89
  eventEmitter.emitPort(env.PORT)
90
90
  fileSystem.init()
91
- await automations.init()
92
91
  await redis.init()
92
+ await automations.init()
93
93
  })
94
94
 
95
95
  process.on("uncaughtException", err => {
@@ -1,4 +1,3 @@
1
- const sendgridEmail = require("./steps/sendgridEmail")
2
1
  const sendSmtpEmail = require("./steps/sendSmtpEmail")
3
2
  const createRow = require("./steps/createRow")
4
3
  const updateRow = require("./steps/updateRow")
@@ -8,15 +7,14 @@ const bash = require("./steps/bash")
8
7
  const executeQuery = require("./steps/executeQuery")
9
8
  const outgoingWebhook = require("./steps/outgoingWebhook")
10
9
  const serverLog = require("./steps/serverLog")
11
- const env = require("../environment")
12
- const Sentry = require("@sentry/node")
13
- const {
14
- automationInit,
15
- getExternalAutomationStep,
16
- } = require("../utilities/fileSystem")
10
+ const discord = require("./steps/discord")
11
+ const slack = require("./steps/slack")
12
+ const zapier = require("./steps/zapier")
13
+ const integromat = require("./steps/integromat")
14
+ let filter = require("./steps/filter")
15
+ let delay = require("./steps/delay")
17
16
 
18
- const BUILTIN_ACTIONS = {
19
- SEND_EMAIL: sendgridEmail.run,
17
+ const ACTION_IMPLS = {
20
18
  SEND_EMAIL_SMTP: sendSmtpEmail.run,
21
19
  CREATE_ROW: createRow.run,
22
20
  UPDATE_ROW: updateRow.run,
@@ -26,9 +24,15 @@ const BUILTIN_ACTIONS = {
26
24
  EXECUTE_BASH: bash.run,
27
25
  EXECUTE_QUERY: executeQuery.run,
28
26
  SERVER_LOG: serverLog.run,
27
+ DELAY: delay.run,
28
+ FILTER: filter.run,
29
+ // these used to be lowercase step IDs, maintain for backwards compat
30
+ discord: discord.run,
31
+ slack: slack.run,
32
+ zapier: zapier.run,
33
+ integromat: integromat.run,
29
34
  }
30
- const BUILTIN_DEFINITIONS = {
31
- SEND_EMAIL: sendgridEmail.definition,
35
+ const ACTION_DEFINITIONS = {
32
36
  SEND_EMAIL_SMTP: sendSmtpEmail.definition,
33
37
  CREATE_ROW: createRow.definition,
34
38
  UPDATE_ROW: updateRow.definition,
@@ -38,47 +42,20 @@ const BUILTIN_DEFINITIONS = {
38
42
  EXECUTE_QUERY: executeQuery.definition,
39
43
  EXECUTE_BASH: bash.definition,
40
44
  SERVER_LOG: serverLog.definition,
45
+ DELAY: delay.definition,
46
+ FILTER: filter.definition,
47
+ // these used to be lowercase step IDs, maintain for backwards compat
48
+ discord: discord.definition,
49
+ slack: slack.definition,
50
+ zapier: zapier.definition,
51
+ integromat: integromat.definition,
41
52
  }
42
53
 
43
- let MANIFEST = null
44
-
45
54
  /* istanbul ignore next */
46
- function buildBundleName(pkgName, version) {
47
- return `${pkgName}@${version}.min.js`
48
- }
49
-
50
- /* istanbul ignore next */
51
- module.exports.getAction = async function (actionName) {
52
- if (BUILTIN_ACTIONS[actionName] != null) {
53
- return BUILTIN_ACTIONS[actionName]
54
- }
55
- // worker pools means that a worker may not have manifest
56
- if (env.isProd() && MANIFEST == null) {
57
- MANIFEST = await module.exports.init()
58
- }
59
- // env setup to get async packages
60
- if (!MANIFEST || !MANIFEST.packages || !MANIFEST.packages[actionName]) {
61
- return null
62
- }
63
- const pkg = MANIFEST.packages[actionName]
64
- const bundleName = buildBundleName(pkg.stepId, pkg.version)
65
- return getExternalAutomationStep(pkg.stepId, pkg.version, bundleName)
66
- }
67
-
68
- module.exports.init = async function () {
69
- try {
70
- MANIFEST = await automationInit()
71
- module.exports.DEFINITIONS =
72
- MANIFEST && MANIFEST.packages
73
- ? Object.assign(MANIFEST.packages, BUILTIN_DEFINITIONS)
74
- : BUILTIN_DEFINITIONS
75
- } catch (err) {
76
- console.error(err)
77
- Sentry.captureException(err)
55
+ exports.getAction = async function (actionName) {
56
+ if (ACTION_IMPLS[actionName] != null) {
57
+ return ACTION_IMPLS[actionName]
78
58
  }
79
- return MANIFEST
80
59
  }
81
60
 
82
- // definitions will have downloaded ones added to it, while builtin won't
83
- module.exports.DEFINITIONS = BUILTIN_DEFINITIONS
84
- module.exports.BUILTIN_DEFINITIONS = BUILTIN_DEFINITIONS
61
+ exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS
@@ -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
+ }