@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
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ exports.definition = {
3
+ name: "Cron Trigger",
4
+ event: "cron:trigger",
5
+ icon: "ri-timer-line",
6
+ tagline: "Cron Trigger (<b>{{inputs.cron}}</b>)",
7
+ description: "Triggers automation on a cron schedule.",
8
+ stepId: "CRON",
9
+ inputs: {},
10
+ schema: {
11
+ inputs: {
12
+ properties: {
13
+ cron: {
14
+ type: "string",
15
+ customType: "cron",
16
+ title: "Expression",
17
+ },
18
+ },
19
+ required: ["cron"],
20
+ },
21
+ outputs: {
22
+ properties: {
23
+ timestamp: {
24
+ type: "number",
25
+ description: "Timestamp the cron was executed",
26
+ },
27
+ },
28
+ required: ["timestamp"],
29
+ },
30
+ },
31
+ type: "TRIGGER",
32
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ const app = require("./app");
3
+ const cron = require("./cron");
4
+ const rowDeleted = require("./rowDeleted");
5
+ const rowSaved = require("./rowSaved");
6
+ const rowUpdated = require("./rowUpdated");
7
+ const webhook = require("./webhook");
8
+ exports.definitions = {
9
+ ROW_SAVED: rowSaved.definition,
10
+ ROW_UPDATED: rowUpdated.definition,
11
+ ROW_DELETED: rowDeleted.definition,
12
+ WEBHOOK: webhook.definition,
13
+ APP: app.definition,
14
+ CRON: cron.definition,
15
+ };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ exports.definition = {
3
+ name: "Row Deleted",
4
+ event: "row:delete",
5
+ icon: "ri-delete-bin-line",
6
+ tagline: "Row is deleted from {{inputs.enriched.table.name}}",
7
+ description: "Fired when a row is deleted from your database",
8
+ stepId: "ROW_DELETED",
9
+ inputs: {},
10
+ schema: {
11
+ inputs: {
12
+ properties: {
13
+ tableId: {
14
+ type: "string",
15
+ customType: "table",
16
+ title: "Table",
17
+ },
18
+ },
19
+ required: ["tableId"],
20
+ },
21
+ outputs: {
22
+ properties: {
23
+ row: {
24
+ type: "object",
25
+ customType: "row",
26
+ description: "The row that was deleted",
27
+ },
28
+ },
29
+ required: ["row"],
30
+ },
31
+ },
32
+ type: "TRIGGER",
33
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ exports.definition = {
3
+ name: "Row Created",
4
+ event: "row:save",
5
+ icon: "ri-save-line",
6
+ tagline: "Row is added to {{inputs.enriched.table.name}}",
7
+ description: "Fired when a row is added to your database",
8
+ stepId: "ROW_SAVED",
9
+ inputs: {},
10
+ schema: {
11
+ inputs: {
12
+ properties: {
13
+ tableId: {
14
+ type: "string",
15
+ customType: "table",
16
+ title: "Table",
17
+ },
18
+ },
19
+ required: ["tableId"],
20
+ },
21
+ outputs: {
22
+ properties: {
23
+ row: {
24
+ type: "object",
25
+ customType: "row",
26
+ description: "The new row that was created",
27
+ },
28
+ id: {
29
+ type: "string",
30
+ description: "Row ID - can be used for updating",
31
+ },
32
+ revision: {
33
+ type: "string",
34
+ description: "Revision of row",
35
+ },
36
+ },
37
+ required: ["row", "id"],
38
+ },
39
+ },
40
+ type: "TRIGGER",
41
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ exports.definition = {
3
+ name: "Row Updated",
4
+ event: "row:update",
5
+ icon: "ri-refresh-line",
6
+ tagline: "Row is updated in {{inputs.enriched.table.name}}",
7
+ description: "Fired when a row is updated in your database",
8
+ stepId: "ROW_UPDATED",
9
+ inputs: {},
10
+ schema: {
11
+ inputs: {
12
+ properties: {
13
+ tableId: {
14
+ type: "string",
15
+ customType: "table",
16
+ title: "Table",
17
+ },
18
+ },
19
+ required: ["tableId"],
20
+ },
21
+ outputs: {
22
+ properties: {
23
+ row: {
24
+ type: "object",
25
+ customType: "row",
26
+ description: "The row that was updated",
27
+ },
28
+ id: {
29
+ type: "string",
30
+ description: "Row ID - can be used for updating",
31
+ },
32
+ revision: {
33
+ type: "string",
34
+ description: "Revision of row",
35
+ },
36
+ },
37
+ required: ["row", "id"],
38
+ },
39
+ },
40
+ type: "TRIGGER",
41
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ exports.definition = {
3
+ name: "Webhook",
4
+ event: "web:trigger",
5
+ icon: "ri-global-line",
6
+ tagline: "Webhook endpoint is hit",
7
+ description: "Trigger an automation when a HTTP POST webhook is hit",
8
+ stepId: "WEBHOOK",
9
+ inputs: {},
10
+ schema: {
11
+ inputs: {
12
+ properties: {
13
+ schemaUrl: {
14
+ type: "string",
15
+ customType: "webhookUrl",
16
+ title: "Schema URL",
17
+ },
18
+ triggerUrl: {
19
+ type: "string",
20
+ customType: "webhookUrl",
21
+ title: "Trigger URL",
22
+ },
23
+ },
24
+ required: ["schemaUrl", "triggerUrl"],
25
+ },
26
+ outputs: {
27
+ properties: {
28
+ body: {
29
+ type: "object",
30
+ description: "Body of the request which hit the webhook",
31
+ },
32
+ },
33
+ required: ["body"],
34
+ },
35
+ },
36
+ type: "TRIGGER",
37
+ };
@@ -10,234 +10,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const CouchDB = require("../db");
12
12
  const emitter = require("../events/index");
13
- const env = require("../environment");
14
- const Queue = env.isTest()
15
- ? require("../utilities/queue/inMemoryQueue")
16
- : require("bull");
17
13
  const { getAutomationParams } = require("../db/utils");
18
14
  const { coerce } = require("../utilities/rowProcessor");
19
- const { utils } = require("@budibase/auth/redis");
20
- const { JobQueues } = require("../constants");
21
- const { isExternalTable, breakExternalTableId, } = require("../integrations/utils");
22
- const { getExternalTable } = require("../api/controllers/table/utils");
23
- const { opts } = utils.getRedisOptions();
24
- let automationQueue = new Queue(JobQueues.AUTOMATIONS, { redis: opts });
25
- const FAKE_STRING = "TEST";
26
- const FAKE_BOOL = false;
27
- const FAKE_NUMBER = 1;
28
- const FAKE_DATETIME = "1970-01-01T00:00:00.000Z";
29
- const BUILTIN_DEFINITIONS = {
30
- ROW_SAVED: {
31
- name: "Row Created",
32
- event: "row:save",
33
- icon: "ri-save-line",
34
- tagline: "Row is added to {{inputs.enriched.table.name}}",
35
- description: "Fired when a row is added to your database",
36
- stepId: "ROW_SAVED",
37
- inputs: {},
38
- schema: {
39
- inputs: {
40
- properties: {
41
- tableId: {
42
- type: "string",
43
- customType: "table",
44
- title: "Table",
45
- },
46
- },
47
- required: ["tableId"],
48
- },
49
- outputs: {
50
- properties: {
51
- row: {
52
- type: "object",
53
- customType: "row",
54
- description: "The new row that was created",
55
- },
56
- id: {
57
- type: "string",
58
- description: "Row ID - can be used for updating",
59
- },
60
- revision: {
61
- type: "string",
62
- description: "Revision of row",
63
- },
64
- },
65
- required: ["row", "id"],
66
- },
67
- },
68
- type: "TRIGGER",
69
- },
70
- ROW_UPDATED: {
71
- name: "Row Updated",
72
- event: "row:update",
73
- icon: "ri-refresh-line",
74
- tagline: "Row is updated in {{inputs.enriched.table.name}}",
75
- description: "Fired when a row is updated in your database",
76
- stepId: "ROW_UPDATED",
77
- inputs: {},
78
- schema: {
79
- inputs: {
80
- properties: {
81
- tableId: {
82
- type: "string",
83
- customType: "table",
84
- title: "Table",
85
- },
86
- },
87
- required: ["tableId"],
88
- },
89
- outputs: {
90
- properties: {
91
- row: {
92
- type: "object",
93
- customType: "row",
94
- description: "The row that was updated",
95
- },
96
- id: {
97
- type: "string",
98
- description: "Row ID - can be used for updating",
99
- },
100
- revision: {
101
- type: "string",
102
- description: "Revision of row",
103
- },
104
- },
105
- required: ["row", "id"],
106
- },
107
- },
108
- type: "TRIGGER",
109
- },
110
- ROW_DELETED: {
111
- name: "Row Deleted",
112
- event: "row:delete",
113
- icon: "ri-delete-bin-line",
114
- tagline: "Row is deleted from {{inputs.enriched.table.name}}",
115
- description: "Fired when a row is deleted from your database",
116
- stepId: "ROW_DELETED",
117
- inputs: {},
118
- schema: {
119
- inputs: {
120
- properties: {
121
- tableId: {
122
- type: "string",
123
- customType: "table",
124
- title: "Table",
125
- },
126
- },
127
- required: ["tableId"],
128
- },
129
- outputs: {
130
- properties: {
131
- row: {
132
- type: "object",
133
- customType: "row",
134
- description: "The row that was deleted",
135
- },
136
- },
137
- required: ["row"],
138
- },
139
- },
140
- type: "TRIGGER",
141
- },
142
- WEBHOOK: {
143
- name: "Webhook",
144
- event: "web:trigger",
145
- icon: "ri-global-line",
146
- tagline: "Webhook endpoint is hit",
147
- description: "Trigger an automation when a HTTP POST webhook is hit",
148
- stepId: "WEBHOOK",
149
- inputs: {},
150
- schema: {
151
- inputs: {
152
- properties: {
153
- schemaUrl: {
154
- type: "string",
155
- customType: "webhookUrl",
156
- title: "Schema URL",
157
- },
158
- triggerUrl: {
159
- type: "string",
160
- customType: "webhookUrl",
161
- title: "Trigger URL",
162
- },
163
- },
164
- required: ["schemaUrl", "triggerUrl"],
165
- },
166
- outputs: {
167
- properties: {
168
- body: {
169
- type: "object",
170
- description: "Body of the request which hit the webhook",
171
- },
172
- },
173
- required: ["body"],
174
- },
175
- },
176
- type: "TRIGGER",
177
- },
178
- APP: {
179
- name: "App Action",
180
- event: "app:trigger",
181
- icon: "ri-window-fill",
182
- tagline: "Automation fired from the frontend",
183
- description: "Trigger an automation from an action inside your app",
184
- stepId: "APP",
185
- inputs: {},
186
- schema: {
187
- inputs: {
188
- properties: {
189
- fields: {
190
- type: "object",
191
- customType: "triggerSchema",
192
- title: "Fields",
193
- },
194
- },
195
- required: [],
196
- },
197
- outputs: {
198
- properties: {
199
- fields: {
200
- type: "object",
201
- description: "Fields submitted from the app frontend",
202
- },
203
- },
204
- required: ["fields"],
205
- },
206
- },
207
- type: "TRIGGER",
208
- },
209
- CRON: {
210
- name: "Cron Trigger",
211
- event: "cron:trigger",
212
- icon: "ri-timer-line",
213
- tagline: "Cron Trigger (<b>{{inputs.cron}}</b>)",
214
- description: "Triggers automation on a cron schedule.",
215
- stepId: "CRON",
216
- inputs: {},
217
- schema: {
218
- inputs: {
219
- properties: {
220
- cron: {
221
- type: "string",
222
- customType: "cron",
223
- title: "Expression",
224
- },
225
- },
226
- required: ["cron"],
227
- },
228
- outputs: {
229
- properties: {
230
- timestamp: {
231
- type: "number",
232
- description: "Timestamp the cron was executed",
233
- },
234
- },
235
- required: ["timestamp"],
236
- },
237
- },
238
- type: "TRIGGER",
239
- },
240
- };
15
+ const { definitions } = require("./triggerInfo");
16
+ const { isDevAppID } = require("../db/utils");
17
+ // need this to call directly, so we can get a response
18
+ const { queue } = require("./bullboard");
19
+ const { checkTestFlag } = require("../utilities/redis");
20
+ const utils = require("./utils");
21
+ const env = require("../environment");
22
+ const TRIGGER_DEFINITIONS = definitions;
241
23
  function queueRelevantRowAutomations(event, eventType) {
242
24
  return __awaiter(this, void 0, void 0, function* () {
243
25
  if (event.appId == null) {
@@ -255,12 +37,18 @@ function queueRelevantRowAutomations(event, eventType) {
255
37
  for (let automation of automations) {
256
38
  let automationDef = automation.definition;
257
39
  let automationTrigger = automationDef ? automationDef.trigger : {};
258
- if (!automation.live ||
259
- !automationTrigger.inputs ||
260
- automationTrigger.inputs.tableId !== event.row.tableId) {
40
+ // don't queue events which are for dev apps, only way to test automations is
41
+ // running tests on them, in production the test flag will never
42
+ // be checked due to lazy evaluation (first always false)
43
+ if (!env.ALLOW_DEV_AUTOMATIONS &&
44
+ isDevAppID(event.appId) &&
45
+ !(yield checkTestFlag(automation._id))) {
261
46
  continue;
262
47
  }
263
- automationQueue.add({ automation, event });
48
+ if (automationTrigger.inputs &&
49
+ automationTrigger.inputs.tableId === event.row.tableId) {
50
+ yield queue.add({ automation, event });
51
+ }
264
52
  }
265
53
  });
266
54
  }
@@ -291,55 +79,9 @@ emitter.on("row:delete", function (event) {
291
79
  yield queueRelevantRowAutomations(event, "row:delete");
292
80
  });
293
81
  });
294
- function fillRowOutput(automation, params) {
82
+ exports.externalTrigger = function (automation, params, { getResponses } = {}) {
295
83
  return __awaiter(this, void 0, void 0, function* () {
296
- let triggerSchema = automation.definition.trigger;
297
- let tableId = triggerSchema.inputs.tableId;
298
- try {
299
- let table;
300
- if (!isExternalTable(tableId)) {
301
- const db = new CouchDB(params.appId);
302
- table = yield db.get(tableId);
303
- }
304
- else {
305
- const { datasourceId, tableName } = breakExternalTableId(tableId);
306
- table = yield getExternalTable(params.appId, datasourceId, tableName);
307
- }
308
- let row = {};
309
- for (let schemaKey of Object.keys(table.schema)) {
310
- const paramValue = params[schemaKey];
311
- let propSchema = table.schema[schemaKey];
312
- switch (propSchema.constraints.type) {
313
- case "string":
314
- row[schemaKey] = paramValue || FAKE_STRING;
315
- break;
316
- case "boolean":
317
- row[schemaKey] = paramValue || FAKE_BOOL;
318
- break;
319
- case "number":
320
- row[schemaKey] = paramValue || FAKE_NUMBER;
321
- break;
322
- case "datetime":
323
- row[schemaKey] = paramValue || FAKE_DATETIME;
324
- break;
325
- }
326
- }
327
- params.row = row;
328
- }
329
- catch (err) {
330
- /* istanbul ignore next */
331
- throw "Failed to find table for trigger";
332
- }
333
- return params;
334
- });
335
- }
336
- module.exports.externalTrigger = function (automation, params) {
337
- return __awaiter(this, void 0, void 0, function* () {
338
- // TODO: replace this with allowing user in builder to input values in future
339
84
  if (automation.definition != null && automation.definition.trigger != null) {
340
- if (automation.definition.trigger.inputs.tableId != null) {
341
- params = yield fillRowOutput(automation, params);
342
- }
343
85
  if (automation.definition.trigger.stepId === "APP") {
344
86
  // values are likely to be submitted as strings, so we shall convert to correct type
345
87
  const coercedFields = {};
@@ -350,12 +92,13 @@ module.exports.externalTrigger = function (automation, params) {
350
92
  params.fields = coercedFields;
351
93
  }
352
94
  }
353
- automationQueue.add({ automation, event: params });
95
+ const data = { automation, event: params };
96
+ if (getResponses) {
97
+ return utils.processEvent({ data });
98
+ }
99
+ else {
100
+ return queue.add(data);
101
+ }
354
102
  });
355
103
  };
356
- module.exports.getQueues = () => {
357
- return [automationQueue];
358
- };
359
- module.exports.fillRowOutput = fillRowOutput;
360
- module.exports.automationQueue = automationQueue;
361
- module.exports.BUILTIN_DEFINITIONS = BUILTIN_DEFINITIONS;
104
+ exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS;