@budibase/server 0.9.136 → 0.9.140-alpha.0

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 (296) hide show
  1. package/builder/assets/discord.c14881e9.svg +10 -0
  2. package/builder/assets/{index.a0ab7774.js → index.0d1fa670.js} +35 -35
  3. package/builder/assets/{index.121692c9.css → index.79907e5c.css} +5 -5
  4. package/builder/assets/integromat.42212f11.png +0 -0
  5. package/builder/assets/slack.1e1f7cfb.svg +33 -0
  6. package/builder/assets/{vendor.7177f366.js → vendor.d39b3c1e.js} +2 -2
  7. package/builder/assets/zapier.3fbd8f5c.png +0 -0
  8. package/builder/index.html +3 -3
  9. package/coverage/clover.xml +2142 -2095
  10. package/coverage/coverage-final.json +120 -106
  11. package/coverage/lcov-report/api/controllers/analytics.js.html +3 -3
  12. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  13. package/coverage/lcov-report/api/controllers/application.js.html +84 -84
  14. package/coverage/lcov-report/api/controllers/auth.js.html +6 -6
  15. package/coverage/lcov-report/api/controllers/automation.js.html +182 -356
  16. package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
  17. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  18. package/coverage/lcov-report/api/controllers/datasource.js.html +12 -12
  19. package/coverage/lcov-report/api/controllers/dev.js.html +15 -15
  20. package/coverage/lcov-report/api/controllers/hosting.js.html +8 -8
  21. package/coverage/lcov-report/api/controllers/index.html +47 -32
  22. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  23. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  24. package/coverage/lcov-report/api/controllers/metadata.js.html +218 -0
  25. package/coverage/lcov-report/api/controllers/permission.js.html +14 -14
  26. package/coverage/lcov-report/api/controllers/query.js.html +17 -23
  27. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  28. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  29. package/coverage/lcov-report/api/controllers/row/external.js.html +15 -15
  30. package/coverage/lcov-report/api/controllers/row/index.html +29 -44
  31. package/coverage/lcov-report/api/controllers/row/index.js.html +48 -45
  32. package/coverage/lcov-report/api/controllers/row/internal.js.html +159 -126
  33. package/coverage/lcov-report/api/controllers/row/utils.js.html +17 -17
  34. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  35. package/coverage/lcov-report/api/controllers/script.js.html +5 -5
  36. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.js.html +40 -40
  38. package/coverage/lcov-report/api/controllers/table/utils.js.html +48 -48
  39. package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
  40. package/coverage/lcov-report/api/controllers/user.js.html +14 -11
  41. package/coverage/lcov-report/api/controllers/view/exporters.js.html +3 -3
  42. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.js.html +9 -9
  44. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +6 -6
  45. package/coverage/lcov-report/api/controllers/webhook.js.html +14 -14
  46. package/coverage/lcov-report/api/index.html +1 -1
  47. package/coverage/lcov-report/api/index.js.html +23 -23
  48. package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
  49. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  50. package/coverage/lcov-report/api/routes/application.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  52. package/coverage/lcov-report/api/routes/automation.js.html +41 -26
  53. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  54. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  55. package/coverage/lcov-report/api/routes/datasource.js.html +13 -13
  56. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  57. package/coverage/lcov-report/api/routes/dev.js.html +11 -11
  58. package/coverage/lcov-report/api/routes/hosting.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/index.html +24 -9
  60. package/coverage/lcov-report/api/routes/index.js.html +36 -30
  61. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  62. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  63. package/coverage/lcov-report/api/routes/metadata.js.html +194 -0
  64. package/coverage/lcov-report/api/routes/permission.js.html +12 -12
  65. package/coverage/lcov-report/api/routes/query.js.html +13 -13
  66. package/coverage/lcov-report/api/routes/role.js.html +12 -12
  67. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  68. package/coverage/lcov-report/api/routes/row.js.html +10 -10
  69. package/coverage/lcov-report/api/routes/screen.js.html +11 -11
  70. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/static.js.html +13 -16
  72. package/coverage/lcov-report/api/routes/table.js.html +12 -12
  73. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  74. package/coverage/lcov-report/api/routes/user.js.html +9 -9
  75. package/coverage/lcov-report/api/routes/view.js.html +11 -11
  76. package/coverage/lcov-report/api/routes/webhook.js.html +11 -11
  77. package/coverage/lcov-report/automations/actions.js.html +57 -117
  78. package/coverage/lcov-report/automations/automationUtils.js.html +7 -7
  79. package/coverage/lcov-report/automations/bullboard.js.html +49 -16
  80. package/coverage/lcov-report/automations/index.html +67 -67
  81. package/coverage/lcov-report/automations/index.js.html +27 -129
  82. package/coverage/lcov-report/automations/steps/bash.js.html +37 -16
  83. package/coverage/lcov-report/automations/steps/createRow.js.html +15 -15
  84. package/coverage/lcov-report/automations/steps/delay.js.html +48 -9
  85. package/coverage/lcov-report/automations/steps/deleteRow.js.html +14 -14
  86. package/coverage/lcov-report/automations/steps/discord.js.html +329 -0
  87. package/coverage/lcov-report/automations/steps/executeQuery.js.html +22 -34
  88. package/coverage/lcov-report/automations/steps/executeScript.js.html +21 -33
  89. package/coverage/lcov-report/automations/steps/filter.js.html +28 -25
  90. package/coverage/lcov-report/automations/steps/index.html +140 -65
  91. package/coverage/lcov-report/automations/steps/integromat.js.html +341 -0
  92. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +44 -38
  93. package/coverage/lcov-report/automations/steps/queryRows.js.html +437 -0
  94. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +13 -13
  95. package/coverage/lcov-report/automations/steps/serverLog.js.html +23 -11
  96. package/coverage/lcov-report/automations/steps/{sendgridEmail.js.html → slack.js.html} +58 -88
  97. package/coverage/lcov-report/automations/steps/updateRow.js.html +12 -12
  98. package/coverage/lcov-report/automations/steps/utils.js.html +188 -0
  99. package/coverage/lcov-report/automations/steps/zapier.js.html +332 -0
  100. package/coverage/lcov-report/automations/thread.js.html +81 -78
  101. package/coverage/lcov-report/automations/triggerInfo/app.js.html +173 -0
  102. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +173 -0
  103. package/coverage/lcov-report/automations/triggerInfo/index.html +201 -0
  104. package/coverage/lcov-report/automations/triggerInfo/index.js.html +125 -0
  105. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +176 -0
  106. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +200 -0
  107. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +200 -0
  108. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +188 -0
  109. package/coverage/lcov-report/automations/triggers.js.html +67 -838
  110. package/coverage/lcov-report/automations/utils.js.html +557 -0
  111. package/coverage/lcov-report/constants/index.html +5 -5
  112. package/coverage/lcov-report/constants/index.js.html +32 -17
  113. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  114. package/coverage/lcov-report/constants/screens.js.html +4 -4
  115. package/coverage/lcov-report/db/client.js.html +18 -18
  116. package/coverage/lcov-report/db/index.html +19 -19
  117. package/coverage/lcov-report/db/index.js.html +3 -3
  118. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +79 -79
  119. package/coverage/lcov-report/db/linkedRows/index.html +18 -18
  120. package/coverage/lcov-report/db/linkedRows/index.js.html +107 -149
  121. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +43 -43
  122. package/coverage/lcov-report/db/newid.js.html +4 -4
  123. package/coverage/lcov-report/db/utils.js.html +127 -76
  124. package/coverage/lcov-report/events/AutomationEmitter.js.html +7 -7
  125. package/coverage/lcov-report/events/index.html +1 -1
  126. package/coverage/lcov-report/events/index.js.html +6 -6
  127. package/coverage/lcov-report/events/utils.js.html +3 -3
  128. package/coverage/lcov-report/index.html +116 -101
  129. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  130. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  131. package/coverage/lcov-report/{automations/logic.js.html → middleware/appInfo.js.html} +35 -38
  132. package/coverage/lcov-report/middleware/authorized.js.html +16 -16
  133. package/coverage/lcov-report/middleware/builder.js.html +15 -15
  134. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  135. package/coverage/lcov-report/middleware/index.html +23 -8
  136. package/coverage/lcov-report/middleware/joi-validator.js.html +6 -6
  137. package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
  138. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  139. package/coverage/lcov-report/middleware/usageQuota.js.html +8 -8
  140. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  141. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  142. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  143. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  144. package/coverage/lcov-report/utilities/global.js.html +33 -33
  145. package/coverage/lcov-report/utilities/index.html +28 -28
  146. package/coverage/lcov-report/utilities/index.js.html +178 -25
  147. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
  148. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  149. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  150. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  151. package/coverage/lcov-report/utilities/rowProcessor/index.html +14 -14
  152. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +87 -51
  153. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
  154. package/coverage/lcov-report/utilities/security.js.html +9 -9
  155. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  156. package/coverage/lcov-report/utilities/users.js.html +5 -5
  157. package/coverage/lcov-report/utilities/workerRequests.js.html +52 -52
  158. package/coverage/lcov.info +3250 -3213
  159. package/dist/api/controllers/automation.js +60 -127
  160. package/dist/api/controllers/deploy/index.js +17 -1
  161. package/dist/api/controllers/metadata.js +49 -0
  162. package/dist/api/controllers/query.js +0 -2
  163. package/dist/api/controllers/row/ExternalRequest.js +1 -1
  164. package/dist/api/controllers/row/index.js +1 -0
  165. package/dist/api/controllers/row/internal.js +33 -23
  166. package/dist/api/controllers/static/index.js +1 -28
  167. package/dist/api/controllers/static/templates/BudibaseApp.svelte +4 -1
  168. package/dist/api/controllers/user.js +1 -1
  169. package/dist/api/routes/automation.js +4 -5
  170. package/dist/api/routes/index.js +2 -0
  171. package/dist/api/routes/metadata.js +13 -0
  172. package/dist/api/routes/static.js +0 -1
  173. package/dist/api/routes/tests/utilities/TestFunctions.js +13 -0
  174. package/dist/app.js +1 -1
  175. package/dist/automations/actions.js +29 -46
  176. package/dist/automations/bullboard.js +11 -2
  177. package/dist/automations/index.js +11 -48
  178. package/dist/automations/steps/bash.js +12 -6
  179. package/dist/automations/steps/createRow.js +5 -5
  180. package/dist/automations/steps/delay.js +16 -3
  181. package/dist/automations/steps/deleteRow.js +5 -5
  182. package/dist/automations/steps/discord.js +91 -0
  183. package/dist/automations/steps/executeQuery.js +12 -15
  184. package/dist/automations/steps/executeScript.js +12 -15
  185. package/dist/automations/steps/filter.js +19 -18
  186. package/dist/automations/steps/integromat.js +94 -0
  187. package/dist/automations/steps/outgoingWebhook.js +19 -20
  188. package/dist/automations/steps/queryRows.js +129 -0
  189. package/dist/automations/steps/sendSmtpEmail.js +4 -4
  190. package/dist/automations/steps/serverLog.js +7 -3
  191. package/dist/automations/steps/slack.js +73 -0
  192. package/dist/automations/steps/updateRow.js +4 -4
  193. package/dist/automations/steps/utils.js +46 -0
  194. package/dist/automations/steps/zapier.js +91 -0
  195. package/dist/automations/tests/utilities/index.js +2 -12
  196. package/dist/automations/thread.js +23 -25
  197. package/dist/automations/triggerInfo/app.js +32 -0
  198. package/dist/automations/triggerInfo/cron.js +32 -0
  199. package/dist/automations/triggerInfo/index.js +15 -0
  200. package/dist/automations/triggerInfo/rowDeleted.js +33 -0
  201. package/dist/automations/triggerInfo/rowSaved.js +41 -0
  202. package/dist/automations/triggerInfo/rowUpdated.js +41 -0
  203. package/dist/automations/triggerInfo/webhook.js +37 -0
  204. package/dist/automations/triggers.js +27 -285
  205. package/dist/automations/utils.js +143 -0
  206. package/dist/constants/index.js +4 -0
  207. package/dist/db/linkedRows/index.js +20 -34
  208. package/dist/db/utils.js +14 -1
  209. package/dist/environment.js +2 -1
  210. package/dist/integrations/mysql.js +14 -2
  211. package/dist/middleware/appInfo.js +17 -0
  212. package/dist/middleware/usageQuota.js +1 -1
  213. package/dist/package.json +12 -11
  214. package/dist/tsconfig.tsbuildinfo +1 -1
  215. package/dist/utilities/appDirectoryTemplate/package.json +1 -1
  216. package/dist/utilities/fileSystem/clientLibrary.js +2 -2
  217. package/dist/utilities/fileSystem/index.js +2 -27
  218. package/dist/utilities/index.js +54 -0
  219. package/dist/utilities/redis.js +16 -1
  220. package/dist/utilities/rowProcessor/index.js +7 -4
  221. package/package.json +13 -12
  222. package/scripts/jestSetup.js +1 -0
  223. package/scripts/selfhost.js +8 -0
  224. package/src/api/controllers/automation.js +87 -145
  225. package/src/api/controllers/deploy/index.js +23 -1
  226. package/src/api/controllers/metadata.js +46 -0
  227. package/src/api/controllers/query.js +0 -2
  228. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  229. package/src/api/controllers/row/index.js +1 -0
  230. package/src/api/controllers/row/internal.js +34 -23
  231. package/src/api/controllers/static/index.js +1 -39
  232. package/src/api/controllers/static/templates/BudibaseApp.svelte +4 -1
  233. package/src/api/controllers/user.js +1 -0
  234. package/src/api/routes/automation.js +16 -11
  235. package/src/api/routes/index.js +2 -0
  236. package/src/api/routes/metadata.js +38 -0
  237. package/src/api/routes/static.js +0 -1
  238. package/src/api/routes/tests/automation.spec.js +4 -26
  239. package/src/api/routes/tests/metadata.spec.js +65 -0
  240. package/src/api/routes/tests/utilities/TestFunctions.js +14 -0
  241. package/src/app.ts +1 -1
  242. package/src/automations/actions.js +29 -49
  243. package/src/automations/bullboard.js +13 -2
  244. package/src/automations/index.js +11 -45
  245. package/src/automations/steps/bash.js +13 -6
  246. package/src/automations/steps/createRow.js +5 -5
  247. package/src/automations/steps/delay.js +16 -3
  248. package/src/automations/steps/deleteRow.js +5 -5
  249. package/src/automations/steps/discord.js +83 -0
  250. package/src/automations/steps/executeQuery.js +12 -16
  251. package/src/automations/steps/executeScript.js +12 -16
  252. package/src/automations/steps/filter.js +19 -18
  253. package/src/automations/steps/integromat.js +87 -0
  254. package/src/automations/steps/outgoingWebhook.js +20 -18
  255. package/src/automations/steps/queryRows.js +119 -0
  256. package/src/automations/steps/sendSmtpEmail.js +4 -4
  257. package/src/automations/steps/serverLog.js +7 -3
  258. package/src/automations/steps/slack.js +64 -0
  259. package/src/automations/steps/updateRow.js +4 -4
  260. package/src/automations/steps/utils.js +36 -0
  261. package/src/automations/steps/zapier.js +84 -0
  262. package/src/automations/tests/automation.spec.js +4 -67
  263. package/src/automations/tests/delay.spec.js +2 -2
  264. package/src/automations/tests/filter.spec.js +14 -14
  265. package/src/automations/tests/queryRows.spec.js +51 -0
  266. package/src/automations/tests/utilities/index.js +2 -13
  267. package/src/automations/thread.js +27 -26
  268. package/src/automations/triggerInfo/app.js +31 -0
  269. package/src/automations/triggerInfo/cron.js +31 -0
  270. package/src/automations/triggerInfo/index.js +15 -0
  271. package/src/automations/triggerInfo/rowDeleted.js +32 -0
  272. package/src/automations/triggerInfo/rowSaved.js +40 -0
  273. package/src/automations/triggerInfo/rowUpdated.js +40 -0
  274. package/src/automations/triggerInfo/webhook.js +36 -0
  275. package/src/automations/triggers.js +33 -290
  276. package/src/automations/utils.js +159 -0
  277. package/src/constants/index.js +5 -0
  278. package/src/db/linkedRows/index.js +21 -35
  279. package/src/db/tests/linkTests.spec.js +0 -12
  280. package/src/db/utils.js +17 -0
  281. package/src/environment.js +2 -1
  282. package/src/integrations/mysql.ts +15 -2
  283. package/src/middleware/appInfo.js +19 -0
  284. package/src/middleware/usageQuota.js +1 -1
  285. package/src/utilities/appDirectoryTemplate/package.json +1 -1
  286. package/src/utilities/fileSystem/clientLibrary.js +2 -2
  287. package/src/utilities/fileSystem/index.js +2 -36
  288. package/src/utilities/index.js +51 -0
  289. package/src/utilities/redis.js +18 -1
  290. package/src/utilities/rowProcessor/index.js +16 -4
  291. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +0 -1244
  292. package/dist/automations/logic.js +0 -17
  293. package/dist/automations/steps/sendgridEmail.js +0 -85
  294. package/src/automations/logic.js +0 -20
  295. package/src/automations/steps/sendgridEmail.js +0 -74
  296. package/src/automations/tests/sendEmail.spec.js +0 -36
@@ -97,3 +97,16 @@ exports.checkPermissionsEndpoint = ({ config, method, url, body, passRole, failR
97
97
  exports.getDB = config => {
98
98
  return new CouchDB(config.getAppId());
99
99
  };
100
+ exports.testAutomation = (config, automation) => __awaiter(void 0, void 0, void 0, function* () {
101
+ return yield config.request
102
+ .post(`/api/automations/${automation._id}/test`)
103
+ .send({
104
+ row: {
105
+ name: "Test",
106
+ description: "TEST",
107
+ },
108
+ })
109
+ .set(config.defaultHeaders())
110
+ .expect("Content-Type", /json/)
111
+ .expect(200);
112
+ });
package/dist/app.js CHANGED
@@ -82,8 +82,8 @@ module.exports = server.listen(env.PORT || 0, () => __awaiter(void 0, void 0, vo
82
82
  env._set("PORT", server.address().port);
83
83
  eventEmitter.emitPort(env.PORT);
84
84
  fileSystem.init();
85
- yield automations.init();
86
85
  yield redis.init();
86
+ yield automations.init();
87
87
  }));
88
88
  process.on("uncaughtException", err => {
89
89
  console.error(err);
@@ -8,7 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const sendgridEmail = require("./steps/sendgridEmail");
12
11
  const sendSmtpEmail = require("./steps/sendSmtpEmail");
13
12
  const createRow = require("./steps/createRow");
14
13
  const updateRow = require("./steps/updateRow");
@@ -18,11 +17,14 @@ const bash = require("./steps/bash");
18
17
  const executeQuery = require("./steps/executeQuery");
19
18
  const outgoingWebhook = require("./steps/outgoingWebhook");
20
19
  const serverLog = require("./steps/serverLog");
21
- const env = require("../environment");
22
- const Sentry = require("@sentry/node");
23
- const { automationInit, getExternalAutomationStep, } = require("../utilities/fileSystem");
24
- const BUILTIN_ACTIONS = {
25
- SEND_EMAIL: sendgridEmail.run,
20
+ const discord = require("./steps/discord");
21
+ const slack = require("./steps/slack");
22
+ const zapier = require("./steps/zapier");
23
+ const integromat = require("./steps/integromat");
24
+ let filter = require("./steps/filter");
25
+ let delay = require("./steps/delay");
26
+ let queryRow = require("./steps/queryRows");
27
+ const ACTION_IMPLS = {
26
28
  SEND_EMAIL_SMTP: sendSmtpEmail.run,
27
29
  CREATE_ROW: createRow.run,
28
30
  UPDATE_ROW: updateRow.run,
@@ -32,9 +34,16 @@ const BUILTIN_ACTIONS = {
32
34
  EXECUTE_BASH: bash.run,
33
35
  EXECUTE_QUERY: executeQuery.run,
34
36
  SERVER_LOG: serverLog.run,
37
+ DELAY: delay.run,
38
+ FILTER: filter.run,
39
+ QUERY_ROWS: queryRow.run,
40
+ // these used to be lowercase step IDs, maintain for backwards compat
41
+ discord: discord.run,
42
+ slack: slack.run,
43
+ zapier: zapier.run,
44
+ integromat: integromat.run,
35
45
  };
36
- const BUILTIN_DEFINITIONS = {
37
- SEND_EMAIL: sendgridEmail.definition,
46
+ const ACTION_DEFINITIONS = {
38
47
  SEND_EMAIL_SMTP: sendSmtpEmail.definition,
39
48
  CREATE_ROW: createRow.definition,
40
49
  UPDATE_ROW: updateRow.definition,
@@ -44,47 +53,21 @@ const BUILTIN_DEFINITIONS = {
44
53
  EXECUTE_QUERY: executeQuery.definition,
45
54
  EXECUTE_BASH: bash.definition,
46
55
  SERVER_LOG: serverLog.definition,
56
+ DELAY: delay.definition,
57
+ FILTER: filter.definition,
58
+ QUERY_ROWS: queryRow.definition,
59
+ // these used to be lowercase step IDs, maintain for backwards compat
60
+ discord: discord.definition,
61
+ slack: slack.definition,
62
+ zapier: zapier.definition,
63
+ integromat: integromat.definition,
47
64
  };
48
- let MANIFEST = null;
49
65
  /* istanbul ignore next */
50
- function buildBundleName(pkgName, version) {
51
- return `${pkgName}@${version}.min.js`;
52
- }
53
- /* istanbul ignore next */
54
- module.exports.getAction = function (actionName) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- if (BUILTIN_ACTIONS[actionName] != null) {
57
- return BUILTIN_ACTIONS[actionName];
58
- }
59
- // worker pools means that a worker may not have manifest
60
- if (env.isProd() && MANIFEST == null) {
61
- MANIFEST = yield module.exports.init();
62
- }
63
- // env setup to get async packages
64
- if (!MANIFEST || !MANIFEST.packages || !MANIFEST.packages[actionName]) {
65
- return null;
66
- }
67
- const pkg = MANIFEST.packages[actionName];
68
- const bundleName = buildBundleName(pkg.stepId, pkg.version);
69
- return getExternalAutomationStep(pkg.stepId, pkg.version, bundleName);
70
- });
71
- };
72
- module.exports.init = function () {
66
+ exports.getAction = function (actionName) {
73
67
  return __awaiter(this, void 0, void 0, function* () {
74
- try {
75
- MANIFEST = yield automationInit();
76
- module.exports.DEFINITIONS =
77
- MANIFEST && MANIFEST.packages
78
- ? Object.assign(MANIFEST.packages, BUILTIN_DEFINITIONS)
79
- : BUILTIN_DEFINITIONS;
80
- }
81
- catch (err) {
82
- console.error(err);
83
- Sentry.captureException(err);
68
+ if (ACTION_IMPLS[actionName] != null) {
69
+ return ACTION_IMPLS[actionName];
84
70
  }
85
- return MANIFEST;
86
71
  });
87
72
  };
88
- // definitions will have downloaded ones added to it, while builtin won't
89
- module.exports.DEFINITIONS = BUILTIN_DEFINITIONS;
90
- module.exports.BUILTIN_DEFINITIONS = BUILTIN_DEFINITIONS;
73
+ exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS;
@@ -1,13 +1,21 @@
1
1
  "use strict";
2
2
  const { createBullBoard } = require("bull-board");
3
3
  const { BullAdapter } = require("bull-board/bullAdapter");
4
- const { getQueues } = require("./triggers");
5
4
  const express = require("express");
5
+ const env = require("../environment");
6
+ const Queue = env.isTest()
7
+ ? require("../utilities/queue/inMemoryQueue")
8
+ : require("bull");
9
+ const { JobQueues } = require("../constants");
10
+ const { utils } = require("@budibase/auth/redis");
11
+ const { opts, redisProtocolUrl } = utils.getRedisOptions();
12
+ const redisConfig = redisProtocolUrl || { redis: opts };
13
+ let automationQueue = new Queue(JobQueues.AUTOMATIONS, redisConfig);
6
14
  exports.pathPrefix = "/bulladmin";
7
15
  exports.init = () => {
8
16
  const expressApp = express();
9
17
  // Set up queues for bull board admin
10
- const queues = getQueues();
18
+ const queues = [automationQueue];
11
19
  const adapters = [];
12
20
  for (let queue of queues) {
13
21
  adapters.push(new BullAdapter(queue));
@@ -16,3 +24,4 @@ exports.init = () => {
16
24
  expressApp.use(exports.pathPrefix, router);
17
25
  return expressApp;
18
26
  };
27
+ exports.queue = automationQueue;
@@ -8,55 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const triggers = require("./triggers");
12
- const actions = require("./actions");
13
- const env = require("../environment");
14
- const workerFarm = require("worker-farm");
15
- const singleThread = require("./thread");
16
- const { getAPIKey, update, Properties } = require("../utilities/usageQuota");
17
- let workers = workerFarm(require.resolve("./thread"));
18
- function runWorker(job) {
19
- return new Promise((resolve, reject) => {
20
- workers(job, err => {
21
- if (err) {
22
- reject(err);
23
- }
24
- else {
25
- resolve();
26
- }
27
- });
28
- });
29
- }
30
- function updateQuota(automation) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const appId = automation.appId;
33
- const apiObj = yield getAPIKey(appId);
34
- // this will fail, causing automation to escape if limits reached
35
- yield update(apiObj.apiKey, Properties.AUTOMATION, 1);
36
- return apiObj.apiKey;
37
- });
38
- }
11
+ const { processEvent } = require("./utils");
12
+ const { queue } = require("./bullboard");
39
13
  /**
40
14
  * This module is built purely to kick off the worker farm and manage the inputs/outputs
41
15
  */
42
- module.exports.init = function () {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- yield actions.init();
45
- triggers.automationQueue.process((job) => __awaiter(this, void 0, void 0, function* () {
46
- try {
47
- if (env.USE_QUOTAS) {
48
- job.data.automation.apiKey = yield updateQuota(job.data.automation);
49
- }
50
- if (env.isProd()) {
51
- yield runWorker(job);
52
- }
53
- else {
54
- yield singleThread(job);
55
- }
56
- }
57
- catch (err) {
58
- console.error(`${job.data.automation.appId} automation ${job.data.automation._id} was unable to run - ${err}`);
59
- }
60
- }));
61
- });
16
+ exports.init = function () {
17
+ // this promise will not complete
18
+ return queue.process((job) => __awaiter(this, void 0, void 0, function* () {
19
+ yield processEvent(job);
20
+ }));
21
+ };
22
+ exports.getQueues = () => {
23
+ return [queue];
62
24
  };
25
+ exports.queue = queue;
@@ -10,12 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const { execSync } = require("child_process");
12
12
  const { processStringSync } = require("@budibase/string-templates");
13
- module.exports.definition = {
13
+ exports.definition = {
14
14
  name: "Bash Scripting",
15
15
  tagline: "Execute a bash command",
16
- icon: "ri-terminal-box-line",
16
+ icon: "JourneyEvent",
17
17
  description: "Run a bash script",
18
18
  type: "ACTION",
19
+ internal: true,
19
20
  stepId: "EXECUTE_BASH",
20
21
  inputs: {},
21
22
  schema: {
@@ -33,14 +34,18 @@ module.exports.definition = {
33
34
  properties: {
34
35
  stdout: {
35
36
  type: "string",
36
- description: "Standard output of your bash command or script.",
37
+ description: "Standard output of your bash command or script",
38
+ },
39
+ success: {
40
+ type: "boolean",
41
+ description: "Whether the command was successful",
37
42
  },
38
43
  },
39
44
  },
40
45
  required: ["stdout"],
41
46
  },
42
47
  };
43
- module.exports.run = function ({ inputs, context }) {
48
+ exports.run = function ({ inputs, context }) {
44
49
  return __awaiter(this, void 0, void 0, function* () {
45
50
  if (inputs.code == null) {
46
51
  return {
@@ -49,19 +54,20 @@ module.exports.run = function ({ inputs, context }) {
49
54
  }
50
55
  try {
51
56
  const command = processStringSync(inputs.code, context);
52
- let stdout;
57
+ let stdout, success = true;
53
58
  try {
54
59
  stdout = execSync(command, { timeout: 500 }).toString();
55
60
  }
56
61
  catch (err) {
57
62
  stdout = err.message;
63
+ success = false;
58
64
  }
59
65
  return {
60
66
  stdout,
67
+ success,
61
68
  };
62
69
  }
63
70
  catch (err) {
64
- console.error(err);
65
71
  return {
66
72
  success: false,
67
73
  response: err,
@@ -12,12 +12,13 @@ const rowController = require("../../api/controllers/row");
12
12
  const automationUtils = require("../automationUtils");
13
13
  const env = require("../../environment");
14
14
  const usage = require("../../utilities/usageQuota");
15
- module.exports.definition = {
15
+ exports.definition = {
16
16
  name: "Create Row",
17
17
  tagline: "Create a {{inputs.enriched.table.name}} row",
18
- icon: "ri-save-3-line",
18
+ icon: "TableRowAddBottom",
19
19
  description: "Add a row to your database",
20
20
  type: "ACTION",
21
+ internal: true,
21
22
  stepId: "CREATE_ROW",
22
23
  inputs: {},
23
24
  schema: {
@@ -51,7 +52,7 @@ module.exports.definition = {
51
52
  },
52
53
  success: {
53
54
  type: "boolean",
54
- description: "Whether the action was successful",
55
+ description: "Whether the row creation was successful",
55
56
  },
56
57
  id: {
57
58
  type: "string",
@@ -66,7 +67,7 @@ module.exports.definition = {
66
67
  },
67
68
  },
68
69
  };
69
- module.exports.run = function ({ inputs, appId, apiKey, emitter }) {
70
+ exports.run = function ({ inputs, appId, apiKey, emitter }) {
70
71
  return __awaiter(this, void 0, void 0, function* () {
71
72
  if (inputs.row == null || inputs.row.tableId == null) {
72
73
  return {
@@ -102,7 +103,6 @@ module.exports.run = function ({ inputs, appId, apiKey, emitter }) {
102
103
  };
103
104
  }
104
105
  catch (err) {
105
- console.error(err);
106
106
  return {
107
107
  success: false,
108
108
  response: err,
@@ -9,12 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  let { wait } = require("../../utilities");
12
- module.exports.definition = {
12
+ exports.definition = {
13
13
  name: "Delay",
14
- icon: "ri-time-line",
14
+ icon: "Clock",
15
15
  tagline: "Delay for {{inputs.time}} milliseconds",
16
16
  description: "Delay the automation until an amount of time has passed",
17
17
  stepId: "DELAY",
18
+ internal: true,
18
19
  inputs: {},
19
20
  schema: {
20
21
  inputs: {
@@ -26,11 +27,23 @@ module.exports.definition = {
26
27
  },
27
28
  required: ["time"],
28
29
  },
30
+ outputs: {
31
+ properties: {
32
+ success: {
33
+ type: "boolean",
34
+ description: "Whether the delay was successful",
35
+ },
36
+ },
37
+ required: ["success"],
38
+ },
29
39
  },
30
40
  type: "LOGIC",
31
41
  };
32
- module.exports.run = function delay({ inputs }) {
42
+ exports.run = function delay({ inputs }) {
33
43
  return __awaiter(this, void 0, void 0, function* () {
34
44
  yield wait(inputs.time);
45
+ return {
46
+ success: true,
47
+ };
35
48
  });
36
49
  };
@@ -11,13 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  const rowController = require("../../api/controllers/row");
12
12
  const env = require("../../environment");
13
13
  const usage = require("../../utilities/usageQuota");
14
- module.exports.definition = {
14
+ exports.definition = {
15
15
  description: "Delete a row from your database",
16
- icon: "ri-delete-bin-line",
16
+ icon: "TableRowRemoveCenter",
17
17
  name: "Delete Row",
18
18
  tagline: "Delete a {{inputs.enriched.table.name}} row",
19
19
  type: "ACTION",
20
20
  stepId: "DELETE_ROW",
21
+ internal: true,
21
22
  inputs: {},
22
23
  schema: {
23
24
  inputs: {
@@ -51,14 +52,14 @@ module.exports.definition = {
51
52
  },
52
53
  success: {
53
54
  type: "boolean",
54
- description: "Whether the action was successful",
55
+ description: "Whether the deletion was successful",
55
56
  },
56
57
  },
57
58
  required: ["row", "success"],
58
59
  },
59
60
  },
60
61
  };
61
- module.exports.run = function ({ inputs, appId, apiKey, emitter }) {
62
+ exports.run = function ({ inputs, appId, apiKey, emitter }) {
62
63
  return __awaiter(this, void 0, void 0, function* () {
63
64
  if (inputs.id == null || inputs.revision == null) {
64
65
  return {
@@ -93,7 +94,6 @@ module.exports.run = function ({ inputs, appId, apiKey, emitter }) {
93
94
  };
94
95
  }
95
96
  catch (err) {
96
- console.error(err);
97
97
  return {
98
98
  success: false,
99
99
  response: err,
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ const fetch = require("node-fetch");
12
+ const { getFetchResponse } = require("./utils");
13
+ const DEFAULT_USERNAME = "Budibase Automate";
14
+ const DEFAULT_AVATAR_URL = "https://i.imgur.com/a1cmTKM.png";
15
+ exports.definition = {
16
+ name: "Discord Message",
17
+ tagline: "Send a message to a Discord server",
18
+ description: "Send a message to a Discord server",
19
+ icon: "ri-discord-line",
20
+ stepId: "discord",
21
+ type: "ACTION",
22
+ internal: false,
23
+ inputs: {},
24
+ schema: {
25
+ inputs: {
26
+ properties: {
27
+ url: {
28
+ type: "string",
29
+ title: "Discord Webhook URL",
30
+ },
31
+ username: {
32
+ type: "string",
33
+ title: "Bot Name",
34
+ },
35
+ avatar_url: {
36
+ type: "string",
37
+ title: "Bot Avatar URL",
38
+ },
39
+ content: {
40
+ type: "string",
41
+ title: "Message",
42
+ },
43
+ },
44
+ required: ["url", "content"],
45
+ },
46
+ outputs: {
47
+ properties: {
48
+ httpStatus: {
49
+ type: "number",
50
+ description: "The HTTP status code of the request",
51
+ },
52
+ response: {
53
+ type: "string",
54
+ description: "The response from the Discord Webhook",
55
+ },
56
+ success: {
57
+ type: "boolean",
58
+ description: "Whether the message sent successfully",
59
+ },
60
+ },
61
+ },
62
+ },
63
+ };
64
+ exports.run = function ({ inputs }) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ let { url, username, avatar_url, content } = inputs;
67
+ if (!username) {
68
+ username = DEFAULT_USERNAME;
69
+ }
70
+ if (!avatar_url) {
71
+ avatar_url = DEFAULT_AVATAR_URL;
72
+ }
73
+ const response = yield fetch(url, {
74
+ method: "post",
75
+ body: JSON.stringify({
76
+ username,
77
+ avatar_url,
78
+ content,
79
+ }),
80
+ headers: {
81
+ "Content-Type": "application/json",
82
+ },
83
+ });
84
+ const { status, message } = yield getFetchResponse(response);
85
+ return {
86
+ httpStatus: status,
87
+ success: status === 200,
88
+ response: message,
89
+ };
90
+ });
91
+ };
@@ -20,13 +20,15 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  return t;
21
21
  };
22
22
  const queryController = require("../../api/controllers/query");
23
- module.exports.definition = {
23
+ const { buildCtx } = require("./utils");
24
+ exports.definition = {
24
25
  name: "External Data Connector",
25
26
  tagline: "Execute Data Connector",
26
- icon: "ri-database-2-line",
27
+ icon: "Data",
27
28
  description: "Execute a query in an external data connector",
28
29
  type: "ACTION",
29
30
  stepId: "EXECUTE_QUERY",
31
+ internal: true,
30
32
  inputs: {},
31
33
  schema: {
32
34
  inputs: {
@@ -61,7 +63,7 @@ module.exports.definition = {
61
63
  required: ["response", "success"],
62
64
  },
63
65
  };
64
- module.exports.run = function ({ inputs, appId, emitter }) {
66
+ exports.run = function ({ inputs, appId, emitter }) {
65
67
  return __awaiter(this, void 0, void 0, function* () {
66
68
  if (inputs.query == null) {
67
69
  return {
@@ -72,27 +74,22 @@ module.exports.run = function ({ inputs, appId, emitter }) {
72
74
  };
73
75
  }
74
76
  const _a = inputs.query, { queryId } = _a, rest = __rest(_a, ["queryId"]);
75
- const ctx = {
77
+ const ctx = buildCtx(appId, emitter, {
78
+ body: {
79
+ parameters: rest,
80
+ },
76
81
  params: {
77
82
  queryId,
78
83
  },
79
- request: {
80
- body: {
81
- parameters: rest,
82
- },
83
- },
84
- appId,
85
- eventEmitter: emitter,
86
- };
87
- yield queryController.execute(ctx);
84
+ });
88
85
  try {
86
+ yield queryController.execute(ctx);
89
87
  return {
90
88
  response: ctx.body,
91
- success: ctx.status === 200,
89
+ success: true,
92
90
  };
93
91
  }
94
92
  catch (err) {
95
- console.error(err);
96
93
  return {
97
94
  success: false,
98
95
  response: err,
@@ -9,12 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const scriptController = require("../../api/controllers/script");
12
- module.exports.definition = {
12
+ const { buildCtx } = require("./utils");
13
+ exports.definition = {
13
14
  name: "JS Scripting",
14
15
  tagline: "Execute JavaScript Code",
15
- icon: "ri-terminal-box-line",
16
+ icon: "Code",
16
17
  description: "Run a piece of JavaScript code in your automation",
17
18
  type: "ACTION",
19
+ internal: true,
18
20
  stepId: "EXECUTE_SCRIPT",
19
21
  inputs: {},
20
22
  schema: {
@@ -32,7 +34,7 @@ module.exports.definition = {
32
34
  properties: {
33
35
  value: {
34
36
  type: "string",
35
- description: "The result of the last statement of the executed script.",
37
+ description: "The result of the return statement",
36
38
  },
37
39
  success: {
38
40
  type: "boolean",
@@ -43,7 +45,7 @@ module.exports.definition = {
43
45
  required: ["success"],
44
46
  },
45
47
  };
46
- module.exports.run = function ({ inputs, appId, context, emitter }) {
48
+ exports.run = function ({ inputs, appId, context, emitter }) {
47
49
  return __awaiter(this, void 0, void 0, function* () {
48
50
  if (inputs.code == null) {
49
51
  return {
@@ -53,25 +55,20 @@ module.exports.run = function ({ inputs, appId, context, emitter }) {
53
55
  },
54
56
  };
55
57
  }
56
- const ctx = {
57
- request: {
58
- body: {
59
- script: inputs.code,
60
- context,
61
- },
58
+ const ctx = buildCtx(appId, emitter, {
59
+ body: {
60
+ script: inputs.code,
61
+ context,
62
62
  },
63
- user: { appId },
64
- eventEmitter: emitter,
65
- };
63
+ });
66
64
  try {
67
65
  yield scriptController.execute(ctx);
68
66
  return {
69
- success: ctx.status === 200,
67
+ success: true,
70
68
  value: ctx.body,
71
69
  };
72
70
  }
73
71
  catch (err) {
74
- console.error(err);
75
72
  return {
76
73
  success: false,
77
74
  response: err,