@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
@@ -0,0 +1,87 @@
1
+ const fetch = require("node-fetch")
2
+ const { getFetchResponse } = require("./utils")
3
+
4
+ exports.definition = {
5
+ name: "Integromat Integration",
6
+ tagline: "Trigger an Integromat scenario",
7
+ description:
8
+ "Performs a webhook call to Integromat and gets the response (if configured)",
9
+ icon: "ri-shut-down-line",
10
+ stepId: "integromat",
11
+ type: "ACTION",
12
+ internal: false,
13
+ inputs: {},
14
+ schema: {
15
+ inputs: {
16
+ properties: {
17
+ url: {
18
+ type: "string",
19
+ title: "Webhook URL",
20
+ },
21
+ value1: {
22
+ type: "string",
23
+ title: "Input Value 1",
24
+ },
25
+ value2: {
26
+ type: "string",
27
+ title: "Input Value 2",
28
+ },
29
+ value3: {
30
+ type: "string",
31
+ title: "Input Value 3",
32
+ },
33
+ value4: {
34
+ type: "string",
35
+ title: "Input Value 4",
36
+ },
37
+ value5: {
38
+ type: "string",
39
+ title: "Input Value 5",
40
+ },
41
+ },
42
+ required: ["url", "value1", "value2", "value3", "value4", "value5"],
43
+ },
44
+ outputs: {
45
+ properties: {
46
+ success: {
47
+ type: "boolean",
48
+ description: "Whether call was successful",
49
+ },
50
+ httpStatus: {
51
+ type: "number",
52
+ description: "The HTTP status code returned",
53
+ },
54
+ response: {
55
+ type: "object",
56
+ description: "The webhook response - this can have properties",
57
+ },
58
+ },
59
+ required: ["success", "response"],
60
+ },
61
+ },
62
+ }
63
+
64
+ exports.run = async function ({ inputs }) {
65
+ const { url, value1, value2, value3, value4, value5 } = inputs
66
+
67
+ const response = await fetch(url, {
68
+ method: "post",
69
+ body: JSON.stringify({
70
+ value1,
71
+ value2,
72
+ value3,
73
+ value4,
74
+ value5,
75
+ }),
76
+ headers: {
77
+ "Content-Type": "application/json",
78
+ },
79
+ })
80
+
81
+ const { status, message } = await getFetchResponse(response)
82
+ return {
83
+ httpStatus: status,
84
+ success: status === 200,
85
+ response: message,
86
+ }
87
+ }
@@ -1,4 +1,5 @@
1
1
  const fetch = require("node-fetch")
2
+ const { getFetchResponse } = require("./utils")
2
3
 
3
4
  const RequestType = {
4
5
  POST: "POST",
@@ -16,12 +17,13 @@ const BODY_REQUESTS = [RequestType.POST, RequestType.PUT, RequestType.PATCH]
16
17
  * GET/DELETE requests cannot handle body elements so they will not be sent if configured.
17
18
  */
18
19
 
19
- module.exports.definition = {
20
+ exports.definition = {
20
21
  name: "Outgoing webhook",
21
22
  tagline: "Send a {{inputs.requestMethod}} request",
22
- icon: "ri-send-plane-line",
23
+ icon: "Send",
23
24
  description: "Send a request of specified method to a URL",
24
25
  type: "ACTION",
26
+ internal: true,
25
27
  stepId: "OUTGOING_WEBHOOK",
26
28
  inputs: {
27
29
  requestMethod: "POST",
@@ -60,6 +62,10 @@ module.exports.definition = {
60
62
  type: "object",
61
63
  description: "The response from the webhook",
62
64
  },
65
+ httpStatus: {
66
+ type: "number",
67
+ description: "The HTTP status code returned",
68
+ },
63
69
  success: {
64
70
  type: "boolean",
65
71
  description: "Whether the action was successful",
@@ -70,7 +76,7 @@ module.exports.definition = {
70
76
  },
71
77
  }
72
78
 
73
- module.exports.run = async function ({ inputs }) {
79
+ exports.run = async function ({ inputs }) {
74
80
  let { requestMethod, url, requestBody, headers } = inputs
75
81
  if (!url.startsWith("http")) {
76
82
  url = `http://${url}`
@@ -91,12 +97,16 @@ module.exports.run = async function ({ inputs }) {
91
97
  "Content-Type": "application/json",
92
98
  }
93
99
 
94
- if (headers && headers.length !== 0) {
100
+ if (headers) {
95
101
  try {
96
- const customHeaders = JSON.parse(headers)
102
+ const customHeaders =
103
+ typeof headers === "string" ? JSON.parse(headers) : headers
97
104
  request.headers = { ...request.headers, ...customHeaders }
98
105
  } catch (err) {
99
- console.error(err)
106
+ return {
107
+ success: false,
108
+ response: "Unable to process headers, must be a JSON object.",
109
+ }
100
110
  }
101
111
  }
102
112
  }
@@ -107,19 +117,11 @@ module.exports.run = async function ({ inputs }) {
107
117
  JSON.parse(request.body)
108
118
  }
109
119
  const response = await fetch(url, request)
110
- const contentType = response.headers.get("content-type")
111
- const success = response.status === 200
112
- let resp
113
- if (!success) {
114
- resp = response.statusText
115
- } else if (contentType && contentType.indexOf("application/json") !== -1) {
116
- resp = await response.json()
117
- } else {
118
- resp = await response.text()
119
- }
120
+ const { status, message } = await getFetchResponse(response)
120
121
  return {
121
- response: resp,
122
- success: success,
122
+ httpStatus: status,
123
+ response: message,
124
+ success: status === 200,
123
125
  }
124
126
  } catch (err) {
125
127
  /* istanbul ignore next */
@@ -0,0 +1,119 @@
1
+ const rowController = require("../../api/controllers/row")
2
+ const tableController = require("../../api/controllers/table")
3
+ const { FieldTypes } = require("../../constants")
4
+
5
+ const SortOrders = {
6
+ ASCENDING: "ascending",
7
+ DESCENDING: "descending",
8
+ }
9
+
10
+ const SortOrdersPretty = {
11
+ [SortOrders.ASCENDING]: "Ascending",
12
+ [SortOrders.DESCENDING]: "Descending",
13
+ }
14
+
15
+ exports.definition = {
16
+ description: "Query rows from the database",
17
+ icon: "Search",
18
+ name: "Query rows",
19
+ tagline: "Query rows from {{inputs.enriched.table.name}} table",
20
+ type: "ACTION",
21
+ stepId: "QUERY_ROWS",
22
+ internal: true,
23
+ inputs: {},
24
+ schema: {
25
+ inputs: {
26
+ properties: {
27
+ tableId: {
28
+ type: "string",
29
+ customType: "table",
30
+ title: "Table",
31
+ },
32
+ filters: {
33
+ type: "object",
34
+ customType: "filters",
35
+ title: "Filtering",
36
+ },
37
+ sortColumn: {
38
+ type: "string",
39
+ title: "Sort Column",
40
+ customType: "column",
41
+ },
42
+ sortOrder: {
43
+ type: "string",
44
+ title: "Sort Order",
45
+ enum: Object.values(SortOrders),
46
+ pretty: Object.values(SortOrdersPretty),
47
+ },
48
+ limit: {
49
+ type: "number",
50
+ title: "Limit",
51
+ },
52
+ },
53
+ required: ["tableId"],
54
+ },
55
+ outputs: {
56
+ properties: {
57
+ rows: {
58
+ type: "array",
59
+ customType: "rows",
60
+ description: "The rows that were found",
61
+ },
62
+ success: {
63
+ type: "boolean",
64
+ description: "Whether the deletion was successful",
65
+ },
66
+ },
67
+ required: ["rows", "success"],
68
+ },
69
+ },
70
+ }
71
+
72
+ async function getTable(appId, tableId) {
73
+ const ctx = {
74
+ params: {
75
+ id: tableId,
76
+ },
77
+ appId,
78
+ }
79
+ await tableController.find(ctx)
80
+ return ctx.body
81
+ }
82
+
83
+ exports.run = async function ({ inputs, appId }) {
84
+ const { tableId, filters, sortColumn, sortOrder, limit } = inputs
85
+ const table = await getTable(appId, tableId)
86
+ let sortType = FieldTypes.STRING
87
+ if (table && table.schema && sortColumn) {
88
+ const fieldType = table.schema[sortColumn].type
89
+ sortType =
90
+ fieldType === FieldTypes.NUMBER ? FieldTypes.NUMBER : FieldTypes.STRING
91
+ }
92
+ const ctx = {
93
+ params: {
94
+ tableId,
95
+ },
96
+ request: {
97
+ body: {
98
+ sortOrder,
99
+ sortType,
100
+ sort: sortColumn,
101
+ query: filters || {},
102
+ limit,
103
+ },
104
+ },
105
+ appId,
106
+ }
107
+ try {
108
+ await rowController.search(ctx)
109
+ return {
110
+ rows: ctx.body ? ctx.body.rows : [],
111
+ success: ctx.status === 200,
112
+ }
113
+ } catch (err) {
114
+ return {
115
+ success: false,
116
+ response: err,
117
+ }
118
+ }
119
+ }
@@ -1,11 +1,12 @@
1
1
  const { sendSmtpEmail } = require("../../utilities/workerRequests")
2
2
 
3
- module.exports.definition = {
3
+ exports.definition = {
4
4
  description: "Send an email using SMTP",
5
5
  tagline: "Send SMTP email to {{inputs.to}}",
6
- icon: "ri-mail-open-line",
6
+ icon: "Email",
7
7
  name: "Send Email (SMTP)",
8
8
  type: "ACTION",
9
+ internal: true,
9
10
  stepId: "SEND_EMAIL_SMTP",
10
11
  inputs: {},
11
12
  schema: {
@@ -46,7 +47,7 @@ module.exports.definition = {
46
47
  },
47
48
  }
48
49
 
49
- module.exports.run = async function ({ inputs }) {
50
+ exports.run = async function ({ inputs }) {
50
51
  let { to, from, subject, contents } = inputs
51
52
  if (!contents) {
52
53
  contents = "<h1>No content</h1>"
@@ -58,7 +59,6 @@ module.exports.run = async function ({ inputs }) {
58
59
  response,
59
60
  }
60
61
  } catch (err) {
61
- console.error(err)
62
62
  return {
63
63
  success: false,
64
64
  response: err,
@@ -4,12 +4,13 @@
4
4
  * GET/DELETE requests cannot handle body elements so they will not be sent if configured.
5
5
  */
6
6
 
7
- module.exports.definition = {
7
+ exports.definition = {
8
8
  name: "Backend log",
9
9
  tagline: "Console log a value in the backend",
10
- icon: "ri-server-line",
10
+ icon: "Monitoring",
11
11
  description: "Logs the given text to the server (using console.log)",
12
12
  type: "ACTION",
13
+ internal: true,
13
14
  stepId: "SERVER_LOG",
14
15
  inputs: {
15
16
  text: "",
@@ -36,6 +37,9 @@ module.exports.definition = {
36
37
  },
37
38
  }
38
39
 
39
- module.exports.run = async function ({ inputs, appId }) {
40
+ exports.run = async function ({ inputs, appId }) {
40
41
  console.log(`App ${appId} - ${inputs.text}`)
42
+ return {
43
+ success: true,
44
+ }
41
45
  }
@@ -0,0 +1,64 @@
1
+ const fetch = require("node-fetch")
2
+ const { getFetchResponse } = require("./utils")
3
+
4
+ exports.definition = {
5
+ name: "Slack Message",
6
+ tagline: "Send a message to Slack",
7
+ description: "Send a message to Slack",
8
+ icon: "ri-slack-line",
9
+ stepId: "slack",
10
+ type: "ACTION",
11
+ internal: false,
12
+ inputs: {},
13
+ schema: {
14
+ inputs: {
15
+ properties: {
16
+ url: {
17
+ type: "string",
18
+ title: "Incoming Webhook URL",
19
+ },
20
+ text: {
21
+ type: "string",
22
+ title: "Message",
23
+ },
24
+ },
25
+ required: ["url", "text"],
26
+ },
27
+ outputs: {
28
+ properties: {
29
+ httpStatus: {
30
+ type: "number",
31
+ description: "The HTTP status code of the request",
32
+ },
33
+ success: {
34
+ type: "boolean",
35
+ description: "Whether the message sent successfully",
36
+ },
37
+ response: {
38
+ type: "string",
39
+ description: "The response from the Slack Webhook",
40
+ },
41
+ },
42
+ },
43
+ },
44
+ }
45
+
46
+ exports.run = async function ({ inputs }) {
47
+ let { url, text } = inputs
48
+ const response = await fetch(url, {
49
+ method: "post",
50
+ body: JSON.stringify({
51
+ text,
52
+ }),
53
+ headers: {
54
+ "Content-Type": "application/json",
55
+ },
56
+ })
57
+
58
+ const { status, message } = await getFetchResponse(response)
59
+ return {
60
+ httpStatus: status,
61
+ response: message,
62
+ success: status === 200,
63
+ }
64
+ }
@@ -1,12 +1,13 @@
1
1
  const rowController = require("../../api/controllers/row")
2
2
  const automationUtils = require("../automationUtils")
3
3
 
4
- module.exports.definition = {
4
+ exports.definition = {
5
5
  name: "Update Row",
6
6
  tagline: "Update a {{inputs.enriched.table.name}} row",
7
- icon: "ri-refresh-line",
7
+ icon: "Refresh",
8
8
  description: "Update a row in your database",
9
9
  type: "ACTION",
10
+ internal: true,
10
11
  stepId: "UPDATE_ROW",
11
12
  inputs: {},
12
13
  schema: {
@@ -53,7 +54,7 @@ module.exports.definition = {
53
54
  },
54
55
  }
55
56
 
56
- module.exports.run = async function ({ inputs, appId, emitter }) {
57
+ exports.run = async function ({ inputs, appId, emitter }) {
57
58
  if (inputs.rowId == null || inputs.row == null) {
58
59
  return {
59
60
  success: false,
@@ -100,7 +101,6 @@ module.exports.run = async function ({ inputs, appId, emitter }) {
100
101
  success: ctx.status === 200,
101
102
  }
102
103
  } catch (err) {
103
- console.error(err)
104
104
  return {
105
105
  success: false,
106
106
  response: err,
@@ -0,0 +1,36 @@
1
+ exports.getFetchResponse = async fetched => {
2
+ let status = fetched.status,
3
+ message
4
+ const contentType = fetched.headers.get("content-type")
5
+ try {
6
+ if (contentType && contentType.indexOf("application/json") !== -1) {
7
+ message = await fetched.json()
8
+ } else {
9
+ message = await fetched.text()
10
+ }
11
+ } catch (err) {
12
+ message = "Failed to retrieve response"
13
+ }
14
+ return { status, message }
15
+ }
16
+
17
+ // need to make sure all ctx structures have the
18
+ // throw added to them, so that controllers don't
19
+ // throw a ctx.throw undefined when error occurs
20
+ exports.buildCtx = (appId, emitter, { body, params } = {}) => {
21
+ const ctx = {
22
+ appId,
23
+ user: { appId },
24
+ eventEmitter: emitter,
25
+ throw: (code, error) => {
26
+ throw error
27
+ },
28
+ }
29
+ if (body) {
30
+ ctx.request = { body }
31
+ }
32
+ if (params) {
33
+ ctx.params = params
34
+ }
35
+ return ctx
36
+ }
@@ -0,0 +1,84 @@
1
+ const fetch = require("node-fetch")
2
+ const { getFetchResponse } = require("./utils")
3
+
4
+ exports.definition = {
5
+ name: "Zapier Webhook",
6
+ stepId: "zapier",
7
+ type: "ACTION",
8
+ internal: false,
9
+ description: "Trigger a Zapier Zap via webhooks",
10
+ tagline: "Trigger a Zapier Zap",
11
+ icon: "ri-flashlight-line",
12
+ schema: {
13
+ inputs: {
14
+ properties: {
15
+ url: {
16
+ type: "string",
17
+ title: "Webhook URL",
18
+ },
19
+ value1: {
20
+ type: "string",
21
+ title: "Payload Value 1",
22
+ },
23
+ value2: {
24
+ type: "string",
25
+ title: "Payload Value 2",
26
+ },
27
+ value3: {
28
+ type: "string",
29
+ title: "Payload Value 3",
30
+ },
31
+ value4: {
32
+ type: "string",
33
+ title: "Payload Value 4",
34
+ },
35
+ value5: {
36
+ type: "string",
37
+ title: "Payload Value 5",
38
+ },
39
+ },
40
+ required: ["url"],
41
+ },
42
+ outputs: {
43
+ properties: {
44
+ httpStatus: {
45
+ type: "number",
46
+ description: "The HTTP status code of the request",
47
+ },
48
+ response: {
49
+ type: "string",
50
+ description: "The response from Zapier",
51
+ },
52
+ },
53
+ },
54
+ },
55
+ }
56
+
57
+ exports.run = async function ({ inputs }) {
58
+ const { url, value1, value2, value3, value4, value5 } = inputs
59
+
60
+ // send the platform to make sure zaps always work, even
61
+ // if no values supplied
62
+ const response = await fetch(url, {
63
+ method: "post",
64
+ body: JSON.stringify({
65
+ platform: "budibase",
66
+ value1,
67
+ value2,
68
+ value3,
69
+ value4,
70
+ value5,
71
+ }),
72
+ headers: {
73
+ "Content-Type": "application/json",
74
+ },
75
+ })
76
+
77
+ const { status, message } = await getFetchResponse(response)
78
+
79
+ return {
80
+ success: status === 200,
81
+ httpStatus: status,
82
+ response: message,
83
+ }
84
+ }
@@ -1,34 +1,18 @@
1
1
  jest.mock("../../utilities/usageQuota")
2
2
  jest.mock("../thread")
3
3
  jest.spyOn(global.console, "error")
4
- jest.mock("worker-farm", () => {
5
- return () => {
6
- const value = jest
7
- .fn()
8
- .mockReturnValueOnce(undefined)
9
- .mockReturnValueOnce("Error")
10
- return (input, callback) => {
11
- workerJob = input
12
- if (callback) {
13
- callback(value())
14
- }
15
- }
16
- }
17
- })
18
4
 
19
5
  require("../../environment")
20
6
  const automation = require("../index")
21
7
  const usageQuota = require("../../utilities/usageQuota")
22
8
  const thread = require("../thread")
23
9
  const triggers = require("../triggers")
24
- const { basicAutomation, basicTable } = require("../../tests/utilities/structures")
10
+ const { basicAutomation } = require("../../tests/utilities/structures")
25
11
  const { wait } = require("../../utilities")
26
12
  const { makePartial } = require("../../tests/utilities")
27
13
  const { cleanInputValues } = require("../automationUtils")
28
14
  const setup = require("./utilities")
29
15
 
30
- let workerJob
31
-
32
16
  usageQuota.getAPIKey.mockReturnValue({ apiKey: "test" })
33
17
 
34
18
  describe("Run through some parts of the automations system", () => {
@@ -44,59 +28,12 @@ describe("Run through some parts of the automations system", () => {
44
28
  it("should be able to init in builder", async () => {
45
29
  await triggers.externalTrigger(basicAutomation(), { a: 1 })
46
30
  await wait(100)
47
- expect(workerJob).toBeUndefined()
48
31
  expect(thread).toHaveBeenCalled()
49
32
  })
50
33
 
51
34
  it("should be able to init in prod", async () => {
52
- await setup.runInProd(async () => {
53
- await triggers.externalTrigger(basicAutomation(), { a: 1 })
54
- await wait(100)
55
- // haven't added a mock implementation so getAPIKey of usageQuota just returns undefined
56
- expect(usageQuota.update).toHaveBeenCalledWith("test", "automationRuns", 1)
57
- expect(workerJob).toBeDefined()
58
- })
59
- })
60
-
61
- it("try error scenario", async () => {
62
- await setup.runInProd(async () => {
63
- // the second call will throw an error
64
- await triggers.externalTrigger(basicAutomation(), { a: 1 })
65
- await wait(100)
66
- expect(console.error).toHaveBeenCalled()
67
- })
68
- })
69
-
70
- it("should be able to check triggering row filling", async () => {
71
- const automation = basicAutomation()
72
- let table = basicTable()
73
- table.schema.boolean = {
74
- type: "boolean",
75
- constraints: {
76
- type: "boolean",
77
- },
78
- }
79
- table.schema.number = {
80
- type: "number",
81
- constraints: {
82
- type: "number",
83
- },
84
- }
85
- table.schema.datetime = {
86
- type: "datetime",
87
- constraints: {
88
- type: "datetime",
89
- },
90
- }
91
- table = await config.createTable(table)
92
- automation.definition.trigger.inputs.tableId = table._id
93
- const params = await triggers.fillRowOutput(automation, { appId: config.getAppId() })
94
- expect(params.row).toBeDefined()
95
- const date = new Date(params.row.datetime)
96
- expect(typeof params.row.name).toBe("string")
97
- expect(typeof params.row.boolean).toBe("boolean")
98
- expect(typeof params.row.number).toBe("number")
99
- expect(date.getFullYear()).toBe(1970)
35
+ await triggers.externalTrigger(basicAutomation(), { a: 1 })
36
+ await wait(100)
100
37
  })
101
38
 
102
39
  it("should check coercion", async () => {
@@ -146,4 +83,4 @@ describe("Run through some parts of the automations system", () => {
146
83
  expect(output.d).toBe(1)
147
84
  expect(output.e).toBe("help")
148
85
  })
149
- })
86
+ })
@@ -4,9 +4,9 @@ describe("test the delay logic", () => {
4
4
  it("should be able to run the delay", async () => {
5
5
  const time = 100
6
6
  const before = Date.now()
7
- await setup.runStep(setup.logic.DELAY.stepId, { time: time })
7
+ await setup.runStep(setup.actions.DELAY.stepId, { time: time })
8
8
  const now = Date.now()
9
9
  // divide by two just so that test will always pass as long as there was some sort of delay
10
10
  expect(now - before).toBeGreaterThanOrEqual(time / 2)
11
11
  })
12
- })
12
+ })