@budibase/server 1.3.12-alpha.3 → 1.3.14

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 (274) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/{index.7886c551.css → index.a70e216a.css} +2 -2
  3. package/builder/assets/index.d8428ac8.js +876 -0
  4. package/builder/assets/vendor.5e1fe644.css +1 -0
  5. package/builder/assets/vendor.67dbd8fa.js +248 -0
  6. package/builder/index.html +4 -2
  7. package/coverage/clover.xml +335 -355
  8. package/coverage/coverage-final.json +22 -22
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/backup.js.html +8 -5
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +13 -82
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +20 -20
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +32 -32
  18. package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
  19. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/screen.js.html +12 -204
  34. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  47. package/coverage/lcov-report/api/index.html +1 -1
  48. package/coverage/lcov-report/api/index.js.html +12 -12
  49. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/index.html +1 -1
  60. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  74. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  77. package/coverage/lcov-report/automations/actions.js.html +1 -1
  78. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  79. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  80. package/coverage/lcov-report/automations/index.html +24 -24
  81. package/coverage/lcov-report/automations/index.js.html +18 -9
  82. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/index.html +1 -1
  89. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggers.js.html +126 -24
  108. package/coverage/lcov-report/constants/index.html +1 -1
  109. package/coverage/lcov-report/constants/index.js.html +1 -1
  110. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  111. package/coverage/lcov-report/constants/screens.js.html +1 -1
  112. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  113. package/coverage/lcov-report/db/index.html +18 -18
  114. package/coverage/lcov-report/db/index.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  116. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  117. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  118. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  119. package/coverage/lcov-report/db/newid.js.html +2 -2
  120. package/coverage/lcov-report/db/utils.js.html +20 -56
  121. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  122. package/coverage/lcov-report/events/index.html +1 -1
  123. package/coverage/lcov-report/events/index.js.html +1 -1
  124. package/coverage/lcov-report/events/utils.js.html +1 -1
  125. package/coverage/lcov-report/index.html +48 -48
  126. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  127. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  128. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  129. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  130. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  131. package/coverage/lcov-report/middleware/index.html +1 -1
  132. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  133. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  134. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  135. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  136. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  137. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  138. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  139. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  140. package/coverage/lcov-report/utilities/global.js.html +16 -16
  141. package/coverage/lcov-report/utilities/index.html +19 -19
  142. package/coverage/lcov-report/utilities/index.js.html +66 -42
  143. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  144. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  145. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  146. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/rowProcessor/index.html +5 -5
  148. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
  150. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  151. package/coverage/lcov-report/utilities/security.js.html +2 -2
  152. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  153. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  154. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +6 -3
  155. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  156. package/coverage/lcov-report/utilities/users.js.html +1 -1
  157. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  158. package/coverage/lcov.info +604 -652
  159. package/dist/api/controllers/application.js +5 -10
  160. package/dist/api/controllers/backup.js +2 -1
  161. package/dist/api/controllers/component.js +1 -18
  162. package/dist/api/controllers/datasource.js +4 -4
  163. package/dist/api/controllers/deploy/index.js +17 -2
  164. package/dist/api/controllers/integration.js +4 -4
  165. package/dist/api/controllers/row/ExternalRequest.js +1 -1
  166. package/dist/api/controllers/screen.js +2 -51
  167. package/dist/api/controllers/static/index.js +0 -1
  168. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  169. package/dist/api/controllers/static/templates/preview.hbs +1 -3
  170. package/dist/api/routes/index.js +0 -2
  171. package/dist/api/routes/static.js +1 -1
  172. package/dist/app.js +0 -9
  173. package/dist/automations/index.js +10 -5
  174. package/dist/automations/triggers.js +39 -5
  175. package/dist/automations/utils.js +16 -7
  176. package/dist/db/utils.js +1 -10
  177. package/dist/environment.js +0 -1
  178. package/dist/integrations/airtable.js +129 -126
  179. package/dist/integrations/arangodb.js +89 -86
  180. package/dist/integrations/base/query.js +2 -2
  181. package/dist/integrations/couchdb.js +83 -80
  182. package/dist/integrations/dynamodb.js +164 -161
  183. package/dist/integrations/elasticsearch.js +138 -135
  184. package/dist/integrations/firebase.js +157 -154
  185. package/dist/integrations/googlesheets.js +327 -323
  186. package/dist/integrations/index.js +51 -93
  187. package/dist/integrations/microsoftSqlServer.js +243 -240
  188. package/dist/integrations/mongodb.js +242 -239
  189. package/dist/integrations/mysql.js +219 -215
  190. package/dist/integrations/oracle.js +322 -318
  191. package/dist/integrations/postgres.js +265 -262
  192. package/dist/integrations/redis.js +139 -134
  193. package/dist/integrations/rest.js +296 -278
  194. package/dist/integrations/s3.js +64 -61
  195. package/dist/integrations/snowflake.js +86 -83
  196. package/dist/package.json +6 -8
  197. package/dist/threads/automation.js +6 -0
  198. package/dist/threads/query.js +2 -2
  199. package/dist/tsconfig.build.tsbuildinfo +1 -1
  200. package/dist/utilities/fileSystem/index.js +6 -71
  201. package/dist/utilities/index.js +8 -0
  202. package/dist/utilities/rowProcessor/utils.js +1 -1
  203. package/dist/utilities/usageQuota/rows.js +2 -1
  204. package/package.json +7 -9
  205. package/scripts/dev/manage.js +0 -1
  206. package/src/api/controllers/application.ts +2 -6
  207. package/src/api/controllers/backup.js +2 -1
  208. package/src/api/controllers/component.js +2 -25
  209. package/src/api/controllers/datasource.js +4 -4
  210. package/src/api/controllers/deploy/index.ts +17 -4
  211. package/src/api/controllers/integration.js +4 -4
  212. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  213. package/src/api/controllers/screen.js +1 -65
  214. package/src/api/controllers/static/index.ts +0 -1
  215. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  216. package/src/api/controllers/static/templates/preview.hbs +1 -3
  217. package/src/api/routes/index.ts +0 -2
  218. package/src/api/routes/static.ts +1 -1
  219. package/src/api/routes/tests/query.spec.js +28 -11
  220. package/src/api/routes/tests/static.spec.js +2 -2
  221. package/src/app.ts +0 -12
  222. package/src/automations/index.js +6 -3
  223. package/src/automations/triggers.js +44 -10
  224. package/src/automations/utils.ts +21 -9
  225. package/src/db/utils.js +0 -12
  226. package/src/definitions/datasource.ts +1 -0
  227. package/src/environment.js +0 -1
  228. package/src/integrations/airtable.ts +118 -116
  229. package/src/integrations/arangodb.ts +89 -87
  230. package/src/integrations/base/query.ts +2 -2
  231. package/src/integrations/couchdb.ts +89 -83
  232. package/src/integrations/dynamodb.ts +175 -173
  233. package/src/integrations/elasticsearch.ts +122 -120
  234. package/src/integrations/firebase.ts +159 -157
  235. package/src/integrations/googlesheets.ts +338 -328
  236. package/src/integrations/index.ts +21 -59
  237. package/src/integrations/microsoftSqlServer.ts +251 -249
  238. package/src/integrations/mongodb.ts +258 -261
  239. package/src/integrations/mysql.ts +234 -229
  240. package/src/integrations/oracle.ts +380 -373
  241. package/src/integrations/postgres.ts +268 -264
  242. package/src/integrations/redis.ts +132 -128
  243. package/src/integrations/rest.ts +330 -312
  244. package/src/integrations/s3.ts +71 -68
  245. package/src/integrations/snowflake.ts +82 -80
  246. package/src/integrations/tests/{airtable.spec.ts → airtable.spec.js} +18 -21
  247. package/src/integrations/tests/{arangodb.spec.ts → arangodb.spec.js} +9 -12
  248. package/src/integrations/tests/{couchdb.spec.ts → couchdb.spec.js} +27 -33
  249. package/src/integrations/tests/{dynamodb.spec.ts → dynamodb.spec.js} +41 -45
  250. package/src/integrations/tests/{elasticsearch.spec.ts → elasticsearch.spec.js} +21 -22
  251. package/src/integrations/tests/{firebase.spec.ts → firebase.spec.js} +28 -33
  252. package/src/integrations/tests/{microsoftSqlServer.spec.ts → microsoftSqlServer.spec.js} +11 -12
  253. package/src/integrations/tests/{mongo.spec.ts → mongo.spec.js} +35 -46
  254. package/src/integrations/tests/{mysql.spec.ts → mysql.spec.js} +15 -17
  255. package/src/integrations/tests/{oracle.spec.ts → oracle.spec.js} +17 -19
  256. package/src/integrations/tests/{postgres.spec.ts → postgres.spec.js} +17 -19
  257. package/src/integrations/tests/{redis.spec.ts → redis.spec.js} +18 -27
  258. package/src/integrations/tests/{rest.spec.ts → rest.spec.js} +49 -22
  259. package/src/integrations/tests/{s3.spec.ts → s3.spec.js} +8 -10
  260. package/src/integrations/tests/{sql.spec.ts → sql.spec.js} +177 -228
  261. package/src/module.d.ts +0 -1
  262. package/src/threads/automation.ts +6 -0
  263. package/src/threads/query.ts +2 -2
  264. package/src/utilities/fileSystem/index.js +6 -75
  265. package/src/utilities/index.js +8 -0
  266. package/src/utilities/rowProcessor/utils.js +1 -1
  267. package/src/utilities/usageQuota/rows.js +2 -1
  268. package/builder/assets/index.e759397f.js +0 -994
  269. package/dist/api/controllers/plugin.js +0 -119
  270. package/dist/api/routes/plugin.js +0 -38
  271. package/dist/watch.js +0 -77
  272. package/src/api/controllers/plugin.ts +0 -110
  273. package/src/api/routes/plugin.ts +0 -13
  274. package/src/watch.ts +0 -38
package/src/app.ts CHANGED
@@ -26,12 +26,10 @@ const bullboard = require("./automations/bullboard")
26
26
  const { logAlert } = require("@budibase/backend-core/logging")
27
27
  const { pinoSettings } = require("@budibase/backend-core")
28
28
  const { Thread } = require("./threads")
29
- const fs = require("fs")
30
29
  import redis from "./utilities/redis"
31
30
  import * as migrations from "./migrations"
32
31
  import { events, installation, tenancy } from "@budibase/backend-core"
33
32
  import { createAdminUser, getChecklist } from "./utilities/workerRequests"
34
- import { watch } from "./watch"
35
33
 
36
34
  const app = new Koa()
37
35
 
@@ -141,16 +139,6 @@ module.exports = server.listen(env.PORT || 0, async () => {
141
139
  }
142
140
  }
143
141
 
144
- // monitor plugin directory if required
145
- if (
146
- env.SELF_HOSTED &&
147
- !env.MULTI_TENANCY &&
148
- env.PLUGINS_DIR &&
149
- fs.existsSync(env.PLUGINS_DIR)
150
- ) {
151
- watch()
152
- }
153
-
154
142
  // check for version updates
155
143
  await installation.checkInstallVersion()
156
144
 
@@ -1,16 +1,19 @@
1
1
  const { processEvent } = require("./utils")
2
2
  const { queue, shutdown } = require("./bullboard")
3
- const { TRIGGER_DEFINITIONS } = require("./triggers")
3
+ const { TRIGGER_DEFINITIONS, rebootTrigger } = require("./triggers")
4
4
  const { ACTION_DEFINITIONS } = require("./actions")
5
5
 
6
6
  /**
7
7
  * This module is built purely to kick off the worker farm and manage the inputs/outputs
8
8
  */
9
- exports.init = function () {
9
+ exports.init = async function () {
10
10
  // this promise will not complete
11
- return queue.process(async job => {
11
+ const promise = queue.process(async job => {
12
12
  await processEvent(job)
13
13
  })
14
+ // on init we need to trigger any reboot automations
15
+ await rebootTrigger()
16
+ return promise
14
17
  }
15
18
 
16
19
  exports.getQueues = () => {
@@ -9,6 +9,7 @@ const { checkTestFlag } = require("../utilities/redis")
9
9
  const utils = require("./utils")
10
10
  const env = require("../environment")
11
11
  const { doInAppContext, getAppDB } = require("@budibase/backend-core/context")
12
+ const { getAllApps } = require("@budibase/backend-core/db")
12
13
 
13
14
  const TRIGGER_DEFINITIONS = definitions
14
15
  const JOB_OPTS = {
@@ -16,24 +17,27 @@ const JOB_OPTS = {
16
17
  removeOnFail: true,
17
18
  }
18
19
 
20
+ async function getAllAutomations() {
21
+ const db = getAppDB()
22
+ let automations = await db.allDocs(
23
+ getAutomationParams(null, { include_docs: true })
24
+ )
25
+ return automations.rows.map(row => row.doc)
26
+ }
27
+
19
28
  async function queueRelevantRowAutomations(event, eventType) {
20
29
  if (event.appId == null) {
21
30
  throw `No appId specified for ${eventType} - check event emitters.`
22
31
  }
23
32
 
24
33
  doInAppContext(event.appId, async () => {
25
- const db = getAppDB()
26
- let automations = await db.allDocs(
27
- getAutomationParams(null, { include_docs: true })
28
- )
34
+ let automations = await getAllAutomations()
29
35
 
30
36
  // filter down to the correct event type
31
- automations = automations.rows
32
- .map(automation => automation.doc)
33
- .filter(automation => {
34
- const trigger = automation.definition.trigger
35
- return trigger && trigger.event === eventType
36
- })
37
+ automations = automations.filter(automation => {
38
+ const trigger = automation.definition.trigger
39
+ return trigger && trigger.event === eventType
40
+ })
37
41
 
38
42
  for (let automation of automations) {
39
43
  let automationDef = automation.definition
@@ -110,4 +114,34 @@ exports.externalTrigger = async function (
110
114
  }
111
115
  }
112
116
 
117
+ exports.rebootTrigger = async () => {
118
+ // reboot cron option is only available on the main thread at
119
+ // startup and only usable in self host
120
+ if (env.isInThread() || !env.SELF_HOSTED) {
121
+ return
122
+ }
123
+ // iterate through all production apps, find the reboot crons
124
+ // and trigger events for them
125
+ const appIds = await getAllApps({ dev: false, idsOnly: true })
126
+ for (let prodAppId of appIds) {
127
+ await doInAppContext(prodAppId, async () => {
128
+ let automations = await getAllAutomations()
129
+ let rebootEvents = []
130
+ for (let automation of automations) {
131
+ if (utils.isRebootTrigger(automation)) {
132
+ const job = {
133
+ automation,
134
+ event: {
135
+ appId: prodAppId,
136
+ timestamp: Date.now(),
137
+ },
138
+ }
139
+ rebootEvents.push(queue.add(job, JOB_OPTS))
140
+ }
141
+ }
142
+ await Promise.all(rebootEvents)
143
+ })
144
+ }
145
+ }
146
+
113
147
  exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS
@@ -17,6 +17,7 @@ import { tenancy } from "@budibase/backend-core"
17
17
  import { quotas } from "@budibase/pro"
18
18
  import { Automation } from "@budibase/types"
19
19
 
20
+ const REBOOT_CRON = "@reboot"
20
21
  const WH_STEP_ID = definitions.WEBHOOK.stepId
21
22
  const CRON_STEP_ID = definitions.CRON.stepId
22
23
  const Runner = new Thread(ThreadType.AUTOMATION)
@@ -109,22 +110,33 @@ export async function clearMetadata() {
109
110
  await db.bulkDocs(automationMetadata)
110
111
  }
111
112
 
113
+ export function isCronTrigger(auto: Automation) {
114
+ return (
115
+ auto &&
116
+ auto.definition.trigger &&
117
+ auto.definition.trigger.stepId === CRON_STEP_ID
118
+ )
119
+ }
120
+
121
+ export function isRebootTrigger(auto: Automation) {
122
+ const trigger = auto ? auto.definition.trigger : null
123
+ return isCronTrigger(auto) && trigger?.inputs.cron === REBOOT_CRON
124
+ }
125
+
112
126
  /**
113
127
  * This function handles checking of any cron jobs that need to be enabled/updated.
114
128
  * @param {string} appId The ID of the app in which we are checking for webhooks
115
129
  * @param {object|undefined} automation The automation object to be updated.
116
130
  */
117
- export async function enableCronTrigger(appId: any, automation: any) {
131
+ export async function enableCronTrigger(appId: any, automation: Automation) {
118
132
  const trigger = automation ? automation.definition.trigger : null
119
- function isCronTrigger(auto: any) {
120
- return (
121
- auto &&
122
- auto.definition.trigger &&
123
- auto.definition.trigger.stepId === CRON_STEP_ID
124
- )
125
- }
133
+
126
134
  // need to create cron job
127
- if (isCronTrigger(automation) && trigger?.inputs.cron) {
135
+ if (
136
+ isCronTrigger(automation) &&
137
+ !isRebootTrigger(automation) &&
138
+ trigger?.inputs.cron
139
+ ) {
128
140
  // make a job id rather than letting Bull decide, makes it easier to handle on way out
129
141
  const jobId = `${appId}_cron_${newid()}`
130
142
  const job: any = await queue.add(
package/src/db/utils.js CHANGED
@@ -42,7 +42,6 @@ const DocumentType = {
42
42
  MEM_VIEW: "view",
43
43
  USER_FLAG: "flag",
44
44
  AUTOMATION_METADATA: "meta_au",
45
- PLUGIN: "plg",
46
45
  }
47
46
 
48
47
  const InternalTables = {
@@ -371,10 +370,6 @@ exports.getMemoryViewParams = (otherProps = {}) => {
371
370
  return getDocParams(DocumentType.MEM_VIEW, null, otherProps)
372
371
  }
373
372
 
374
- exports.generatePluginID = name => {
375
- return `${DocumentType.PLUGIN}${SEPARATOR}${name}`
376
- }
377
-
378
373
  /**
379
374
  * This can be used with the db.allDocs to get a list of IDs
380
375
  */
@@ -384,10 +379,3 @@ exports.getMultiIDParams = ids => {
384
379
  include_docs: true,
385
380
  }
386
381
  }
387
-
388
- /**
389
- * Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
390
- */
391
- exports.getPluginParams = (pluginId = null, otherProps = {}) => {
392
- return getDocParams(DocumentType.PLUGIN, pluginId, otherProps)
393
- }
@@ -34,6 +34,7 @@ export interface RestConfig {
34
34
  defaultHeaders: {
35
35
  [key: string]: any
36
36
  }
37
+ legacyHttpParser: boolean
37
38
  authConfigs: AuthConfig[]
38
39
  staticVariables: {
39
40
  [key: string]: string
@@ -74,7 +74,6 @@ module.exports = {
74
74
  SQL_MAX_ROWS: process.env.SQL_MAX_ROWS,
75
75
  BB_ADMIN_USER_EMAIL: process.env.BB_ADMIN_USER_EMAIL,
76
76
  BB_ADMIN_USER_PASSWORD: process.env.BB_ADMIN_USER_PASSWORD,
77
- PLUGINS_DIR: process.env.PLUGINS_DIR || "/plugins",
78
77
  // flags
79
78
  ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
80
79
  DISABLE_THREADING: process.env.DISABLE_THREADING,
@@ -5,144 +5,146 @@ import {
5
5
  IntegrationBase,
6
6
  } from "@budibase/types"
7
7
 
8
- const Airtable = require("airtable")
8
+ module AirtableModule {
9
+ const Airtable = require("airtable")
9
10
 
10
- interface AirtableConfig {
11
- apiKey: string
12
- base: string
13
- }
11
+ interface AirtableConfig {
12
+ apiKey: string
13
+ base: string
14
+ }
14
15
 
15
- const SCHEMA: Integration = {
16
- docs: "https://airtable.com/api",
17
- description:
18
- "Airtable is a spreadsheet-database hybrid, with the features of a database but applied to a spreadsheet.",
19
- friendlyName: "Airtable",
20
- type: "Spreadsheet",
21
- datasource: {
22
- apiKey: {
23
- type: DatasourceFieldType.PASSWORD,
24
- default: "enter api key",
25
- required: true,
26
- },
27
- base: {
28
- type: DatasourceFieldType.STRING,
29
- default: "mybase",
30
- required: true,
31
- },
32
- },
33
- query: {
34
- create: {
35
- type: QueryType.FIELDS,
36
- customisable: true,
37
- fields: {
38
- table: {
39
- type: DatasourceFieldType.STRING,
40
- required: true,
41
- },
16
+ const SCHEMA: Integration = {
17
+ docs: "https://airtable.com/api",
18
+ description:
19
+ "Airtable is a spreadsheet-database hybrid, with the features of a database but applied to a spreadsheet.",
20
+ friendlyName: "Airtable",
21
+ type: "Spreadsheet",
22
+ datasource: {
23
+ apiKey: {
24
+ type: DatasourceFieldType.PASSWORD,
25
+ default: "enter api key",
26
+ required: true,
27
+ },
28
+ base: {
29
+ type: DatasourceFieldType.STRING,
30
+ default: "mybase",
31
+ required: true,
42
32
  },
43
33
  },
44
- read: {
45
- type: QueryType.FIELDS,
46
- fields: {
47
- table: {
48
- type: DatasourceFieldType.STRING,
49
- required: true,
50
- },
51
- view: {
52
- type: DatasourceFieldType.STRING,
53
- required: true,
54
- },
55
- numRecords: {
56
- type: DatasourceFieldType.NUMBER,
57
- default: 10,
34
+ query: {
35
+ create: {
36
+ type: QueryType.FIELDS,
37
+ customisable: true,
38
+ fields: {
39
+ table: {
40
+ type: DatasourceFieldType.STRING,
41
+ required: true,
42
+ },
58
43
  },
59
44
  },
60
- },
61
- update: {
62
- type: QueryType.FIELDS,
63
- customisable: true,
64
- fields: {
65
- id: {
66
- display: "Record ID",
67
- type: DatasourceFieldType.STRING,
68
- required: true,
45
+ read: {
46
+ type: QueryType.FIELDS,
47
+ fields: {
48
+ table: {
49
+ type: DatasourceFieldType.STRING,
50
+ required: true,
51
+ },
52
+ view: {
53
+ type: DatasourceFieldType.STRING,
54
+ required: true,
55
+ },
56
+ numRecords: {
57
+ type: DatasourceFieldType.NUMBER,
58
+ default: 10,
59
+ },
69
60
  },
70
- table: {
71
- type: DatasourceFieldType.STRING,
72
- required: true,
61
+ },
62
+ update: {
63
+ type: QueryType.FIELDS,
64
+ customisable: true,
65
+ fields: {
66
+ id: {
67
+ display: "Record ID",
68
+ type: DatasourceFieldType.STRING,
69
+ required: true,
70
+ },
71
+ table: {
72
+ type: DatasourceFieldType.STRING,
73
+ required: true,
74
+ },
73
75
  },
74
76
  },
77
+ delete: {
78
+ type: QueryType.JSON,
79
+ },
75
80
  },
76
- delete: {
77
- type: QueryType.JSON,
78
- },
79
- },
80
- }
81
+ }
81
82
 
82
- class AirtableIntegration implements IntegrationBase {
83
- private config: AirtableConfig
84
- private client: any
83
+ class AirtableIntegration implements IntegrationBase {
84
+ private config: AirtableConfig
85
+ private client: any
85
86
 
86
- constructor(config: AirtableConfig) {
87
- this.config = config
88
- this.client = new Airtable(config).base(config.base)
89
- }
87
+ constructor(config: AirtableConfig) {
88
+ this.config = config
89
+ this.client = new Airtable(config).base(config.base)
90
+ }
90
91
 
91
- async create(query: { table: any; json: any }) {
92
- const { table, json } = query
92
+ async create(query: { table: any; json: any }) {
93
+ const { table, json } = query
93
94
 
94
- try {
95
- return await this.client(table).create([
96
- {
97
- fields: json,
98
- },
99
- ])
100
- } catch (err) {
101
- console.error("Error writing to airtable", err)
102
- throw err
95
+ try {
96
+ return await this.client(table).create([
97
+ {
98
+ fields: json,
99
+ },
100
+ ])
101
+ } catch (err) {
102
+ console.error("Error writing to airtable", err)
103
+ throw err
104
+ }
103
105
  }
104
- }
105
106
 
106
- async read(query: { table: any; numRecords: any; view: any }) {
107
- try {
108
- const records = await this.client(query.table)
109
- .select({ maxRecords: query.numRecords || 10, view: query.view })
110
- .firstPage()
111
- // @ts-ignore
112
- return records.map(({ fields }) => fields)
113
- } catch (err) {
114
- console.error("Error writing to airtable", err)
115
- return []
107
+ async read(query: { table: any; numRecords: any; view: any }) {
108
+ try {
109
+ const records = await this.client(query.table)
110
+ .select({ maxRecords: query.numRecords || 10, view: query.view })
111
+ .firstPage()
112
+ // @ts-ignore
113
+ return records.map(({ fields }) => fields)
114
+ } catch (err) {
115
+ console.error("Error writing to airtable", err)
116
+ return []
117
+ }
116
118
  }
117
- }
118
119
 
119
- async update(query: { table: any; id: any; json: any }) {
120
- const { table, id, json } = query
120
+ async update(query: { table: any; id: any; json: any }) {
121
+ const { table, id, json } = query
121
122
 
122
- try {
123
- return await this.client(table).update([
124
- {
125
- id,
126
- fields: json,
127
- },
128
- ])
129
- } catch (err) {
130
- console.error("Error writing to airtable", err)
131
- throw err
123
+ try {
124
+ return await this.client(table).update([
125
+ {
126
+ id,
127
+ fields: json,
128
+ },
129
+ ])
130
+ } catch (err) {
131
+ console.error("Error writing to airtable", err)
132
+ throw err
133
+ }
132
134
  }
133
- }
134
135
 
135
- async delete(query: { table: any; ids: any }) {
136
- try {
137
- return await this.client(query.table).destroy(query.ids)
138
- } catch (err) {
139
- console.error("Error writing to airtable", err)
140
- throw err
136
+ async delete(query: { table: any; ids: any }) {
137
+ try {
138
+ return await this.client(query.table).destroy(query.ids)
139
+ } catch (err) {
140
+ console.error("Error writing to airtable", err)
141
+ throw err
142
+ }
141
143
  }
142
144
  }
143
- }
144
145
 
145
- export default {
146
- schema: SCHEMA,
147
- integration: AirtableIntegration,
146
+ module.exports = {
147
+ schema: SCHEMA,
148
+ integration: AirtableIntegration,
149
+ }
148
150
  }