@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
@@ -6,6 +6,7 @@ const joiValidator = require("../../middleware/joi-validator");
6
6
  const { BUILDER, PermissionLevels, PermissionTypes, } = require("@budibase/auth/permissions");
7
7
  const Joi = require("joi");
8
8
  const { bodyResource, paramResource } = require("../../middleware/resourceId");
9
+ const { middleware: appInfoMiddleware, AppType, } = require("../../middleware/appInfo");
9
10
  const router = Router();
10
11
  // prettier-ignore
11
12
  function generateStepSchema(allowStepTypes) {
@@ -17,7 +18,6 @@ function generateStepSchema(allowStepTypes) {
17
18
  tagline: Joi.string().required(),
18
19
  icon: Joi.string().required(),
19
20
  params: Joi.object(),
20
- // TODO: validate args a bit more deeply
21
21
  args: Joi.object(),
22
22
  type: Joi.string().required().valid(...allowStepTypes),
23
23
  }).unknown(true);
@@ -25,7 +25,6 @@ function generateStepSchema(allowStepTypes) {
25
25
  function generateValidator(existing = false) {
26
26
  // prettier-ignore
27
27
  return joiValidator.body(Joi.object({
28
- live: Joi.bool(),
29
28
  _id: existing ? Joi.string().required() : Joi.string(),
30
29
  _rev: existing ? Joi.string().required() : Joi.string(),
31
30
  name: Joi.string().required(),
@@ -39,12 +38,12 @@ function generateValidator(existing = false) {
39
38
  router
40
39
  .get("/api/automations/trigger/list", authorized(BUILDER), controller.getTriggerList)
41
40
  .get("/api/automations/action/list", authorized(BUILDER), controller.getActionList)
42
- .get("/api/automations/logic/list", authorized(BUILDER), controller.getLogicList)
43
41
  .get("/api/automations/definitions/list", authorized(BUILDER), controller.getDefinitionList)
44
42
  .get("/api/automations", authorized(BUILDER), controller.fetch)
45
43
  .get("/api/automations/:id", paramResource("id"), authorized(BUILDER), controller.find)
46
44
  .put("/api/automations", bodyResource("_id"), authorized(BUILDER), generateValidator(true), controller.update)
47
45
  .post("/api/automations", authorized(BUILDER), generateValidator(false), controller.create)
48
- .post("/api/automations/:id/trigger", paramResource("id"), authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE), controller.trigger)
49
- .delete("/api/automations/:id/:rev", paramResource("id"), authorized(BUILDER), controller.destroy);
46
+ .delete("/api/automations/:id/:rev", paramResource("id"), authorized(BUILDER), controller.destroy)
47
+ .post("/api/automations/:id/trigger", appInfoMiddleware({ appType: AppType.PROD }), paramResource("id"), authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE), controller.trigger)
48
+ .post("/api/automations/:id/test", appInfoMiddleware({ appType: AppType.DEV }), paramResource("id"), authorized(PermissionTypes.AUTOMATION, PermissionLevels.EXECUTE), controller.test);
50
49
  module.exports = router;
@@ -23,6 +23,7 @@ const datasourceRoutes = require("./datasource");
23
23
  const queryRoutes = require("./query");
24
24
  const hostingRoutes = require("./hosting");
25
25
  const backupRoutes = require("./backup");
26
+ const metadataRoutes = require("./metadata");
26
27
  const devRoutes = require("./dev");
27
28
  exports.mainRoutes = [
28
29
  authRoutes,
@@ -46,6 +47,7 @@ exports.mainRoutes = [
46
47
  queryRoutes,
47
48
  hostingRoutes,
48
49
  backupRoutes,
50
+ metadataRoutes,
49
51
  devRoutes,
50
52
  // these need to be handled last as they still use /api/:tableId
51
53
  // this could be breaking as koa may recognise other routes as this
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ const Router = require("@koa/router");
3
+ const controller = require("../controllers/metadata");
4
+ const { middleware: appInfoMiddleware, AppType, } = require("../../middleware/appInfo");
5
+ const authorized = require("../../middleware/authorized");
6
+ const { BUILDER } = require("@budibase/auth/permissions");
7
+ const router = Router();
8
+ router
9
+ .post("/api/metadata/:type/:entityId", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.saveMetadata)
10
+ .delete("/api/metadata/:type/:entityId", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.deleteMetadata)
11
+ .get("/api/metadata/type", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.getTypes)
12
+ .get("/api/metadata/:type/:entityId", authorized(BUILDER), appInfoMiddleware({ appType: AppType.DEV }), controller.getMetadata);
13
+ module.exports = router;
@@ -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,13 @@ 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
+ const ACTION_IMPLS = {
26
27
  SEND_EMAIL_SMTP: sendSmtpEmail.run,
27
28
  CREATE_ROW: createRow.run,
28
29
  UPDATE_ROW: updateRow.run,
@@ -32,9 +33,15 @@ const BUILTIN_ACTIONS = {
32
33
  EXECUTE_BASH: bash.run,
33
34
  EXECUTE_QUERY: executeQuery.run,
34
35
  SERVER_LOG: serverLog.run,
36
+ DELAY: delay.run,
37
+ FILTER: filter.run,
38
+ // these used to be lowercase step IDs, maintain for backwards compat
39
+ discord: discord.run,
40
+ slack: slack.run,
41
+ zapier: zapier.run,
42
+ integromat: integromat.run,
35
43
  };
36
- const BUILTIN_DEFINITIONS = {
37
- SEND_EMAIL: sendgridEmail.definition,
44
+ const ACTION_DEFINITIONS = {
38
45
  SEND_EMAIL_SMTP: sendSmtpEmail.definition,
39
46
  CREATE_ROW: createRow.definition,
40
47
  UPDATE_ROW: updateRow.definition,
@@ -44,47 +51,20 @@ const BUILTIN_DEFINITIONS = {
44
51
  EXECUTE_QUERY: executeQuery.definition,
45
52
  EXECUTE_BASH: bash.definition,
46
53
  SERVER_LOG: serverLog.definition,
54
+ DELAY: delay.definition,
55
+ FILTER: filter.definition,
56
+ // these used to be lowercase step IDs, maintain for backwards compat
57
+ discord: discord.definition,
58
+ slack: slack.definition,
59
+ zapier: zapier.definition,
60
+ integromat: integromat.definition,
47
61
  };
48
- let MANIFEST = null;
49
62
  /* 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 () {
63
+ exports.getAction = function (actionName) {
73
64
  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);
65
+ if (ACTION_IMPLS[actionName] != null) {
66
+ return ACTION_IMPLS[actionName];
84
67
  }
85
- return MANIFEST;
86
68
  });
87
69
  };
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;
70
+ exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS;
@@ -1,13 +1,20 @@
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 } = utils.getRedisOptions();
12
+ let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts });
6
13
  exports.pathPrefix = "/bulladmin";
7
14
  exports.init = () => {
8
15
  const expressApp = express();
9
16
  // Set up queues for bull board admin
10
- const queues = getQueues();
17
+ const queues = [automationQueue];
11
18
  const adapters = [];
12
19
  for (let queue of queues) {
13
20
  adapters.push(new BullAdapter(queue));
@@ -16,3 +23,4 @@ exports.init = () => {
16
23
  expressApp.use(exports.pathPrefix, router);
17
24
  return expressApp;
18
25
  };
26
+ 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
16
  icon: "ri-terminal-box-line",
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 });
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
18
  icon: "ri-save-3-line",
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
14
  icon: "ri-time-line",
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
16
  icon: "ri-delete-bin-line",
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,