@budibase/server 2.0.39 → 2.0.40

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 (295) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/__mocks__/node-fetch.ts +12 -2
  3. package/builder/assets/backups-default.8c011f1b.png +0 -0
  4. package/builder/assets/{index.e0ddd30b.css → index.442de33f.css} +2 -2
  5. package/builder/assets/{index.b20dee52.js → index.72aa3989.js} +340 -332
  6. package/builder/index.html +2 -2
  7. package/coverage/clover.xml +1125 -1250
  8. package/coverage/coverage-final.json +73 -77
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  10. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +79 -67
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/dev.js.html +21 -21
  14. package/coverage/lcov-report/api/controllers/index.html +17 -47
  15. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  16. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  19. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
  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 +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +13 -13
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
  30. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
  32. package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
  33. package/coverage/lcov-report/api/controllers/table/index.html +16 -16
  34. package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
  35. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  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 +3 -3
  40. package/coverage/lcov-report/api/controllers/view/utils.js.html +13 -13
  41. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -8
  42. package/coverage/lcov-report/api/index.html +1 -1
  43. package/coverage/lcov-report/api/index.js.html +30 -30
  44. package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
  45. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  46. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  47. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  48. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  49. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  50. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  52. package/coverage/lcov-report/api/routes/index.html +5 -35
  53. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  54. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  55. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  56. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  57. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  58. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  59. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  60. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  61. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  62. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  64. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  65. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  66. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  67. package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
  68. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  69. package/coverage/lcov-report/automations/actions.js.html +1 -1
  70. package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
  71. package/coverage/lcov-report/automations/bullboard.js.html +24 -84
  72. package/coverage/lcov-report/automations/index.html +21 -21
  73. package/coverage/lcov-report/automations/index.js.html +9 -9
  74. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  75. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/index.html +15 -15
  81. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -3
  89. package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
  90. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  91. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggers.js.html +49 -49
  100. package/coverage/lcov-report/constants/index.html +5 -5
  101. package/coverage/lcov-report/constants/index.js.html +10 -28
  102. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  103. package/coverage/lcov-report/constants/screens.js.html +1 -1
  104. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  105. package/coverage/lcov-report/db/index.html +19 -19
  106. package/coverage/lcov-report/db/index.js.html +1 -1
  107. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
  108. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  109. package/coverage/lcov-report/db/linkedRows/index.js.html +28 -28
  110. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +15 -15
  111. package/coverage/lcov-report/db/newid.js.html +2 -2
  112. package/coverage/lcov-report/db/utils.js.html +37 -316
  113. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  114. package/coverage/lcov-report/events/index.html +1 -1
  115. package/coverage/lcov-report/events/index.js.html +3 -3
  116. package/coverage/lcov-report/events/utils.js.html +9 -9
  117. package/coverage/lcov-report/index.html +88 -88
  118. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  119. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  120. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  121. package/coverage/lcov-report/middleware/builder.js.html +19 -19
  122. package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
  123. package/coverage/lcov-report/middleware/index.html +1 -1
  124. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  125. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  126. package/coverage/lcov-report/middleware/resourceId.js.html +28 -28
  127. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  128. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  129. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  130. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  131. package/coverage/lcov-report/utilities/csvParser.js.html +15 -12
  132. package/coverage/lcov-report/utilities/global.js.html +31 -31
  133. package/coverage/lcov-report/utilities/index.html +28 -28
  134. package/coverage/lcov-report/utilities/index.js.html +8 -8
  135. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  136. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
  137. package/coverage/lcov-report/utilities/queue/index.html +21 -21
  138. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  139. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  140. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  141. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +72 -57
  142. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
  143. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  144. package/coverage/lcov-report/utilities/security.js.html +2 -2
  145. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  146. package/coverage/lcov-report/utilities/usageQuota/index.html +14 -14
  147. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
  148. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  149. package/coverage/lcov-report/utilities/users.js.html +1 -1
  150. package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
  151. package/coverage/lcov.info +1691 -1899
  152. package/dist/api/controllers/application.js +4 -7
  153. package/dist/api/controllers/backup.js +19 -13
  154. package/dist/api/controllers/cloud.js +38 -35
  155. package/dist/api/controllers/deploy/index.js +11 -2
  156. package/dist/api/controllers/dev.js +1 -1
  157. package/dist/api/controllers/query/index.js +7 -2
  158. package/dist/api/controllers/row/index.js +40 -66
  159. package/dist/api/controllers/row/internal.js +1 -1
  160. package/dist/api/controllers/static/index.js +3 -2
  161. package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  162. package/dist/api/controllers/static/templates/preview.hbs +10 -0
  163. package/dist/api/controllers/table/bulkFormula.js +4 -3
  164. package/dist/api/controllers/table/external.js +5 -4
  165. package/dist/api/controllers/table/index.js +4 -4
  166. package/dist/api/controllers/table/internal.js +10 -3
  167. package/dist/api/controllers/table/utils.js +7 -49
  168. package/dist/api/controllers/view/index.js +2 -2
  169. package/dist/api/controllers/webhook.js +88 -89
  170. package/dist/api/routes/backup.js +34 -7
  171. package/dist/api/routes/index.js +9 -4
  172. package/dist/api/routes/utils/validators.js +2 -2
  173. package/dist/api/routes/webhook.js +39 -11
  174. package/dist/app.js +2 -68
  175. package/dist/automations/automationUtils.js +2 -2
  176. package/dist/automations/bullboard.js +12 -35
  177. package/dist/automations/index.js +4 -4
  178. package/dist/automations/steps/updateRow.js +2 -2
  179. package/dist/automations/triggers.js +6 -6
  180. package/dist/automations/utils.js +23 -49
  181. package/dist/constants/index.js +4 -8
  182. package/dist/db/utils.js +10 -75
  183. package/dist/index.js +1 -0
  184. package/dist/integrations/arangodb.js +2 -0
  185. package/dist/integrations/base/sqlTable.js +1 -0
  186. package/dist/integrations/mongodb.js +300 -11
  187. package/dist/integrations/rest.js +38 -5
  188. package/dist/migrations/functions/backfill/app/tables.js +5 -8
  189. package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
  190. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
  191. package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
  192. package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
  193. package/dist/migrations/index.js +10 -38
  194. package/dist/package.json +14 -14
  195. package/dist/sdk/app/automations/index.js +29 -0
  196. package/dist/sdk/app/automations/webhook.js +54 -0
  197. package/dist/sdk/app/backups/constants.js +5 -0
  198. package/dist/sdk/app/backups/exports.js +172 -0
  199. package/dist/sdk/app/backups/imports.js +190 -0
  200. package/dist/sdk/app/backups/index.js +29 -0
  201. package/dist/sdk/app/backups/statistics.js +73 -0
  202. package/dist/sdk/app/tables/index.js +61 -0
  203. package/dist/sdk/index.js +17 -0
  204. package/dist/startup.js +152 -0
  205. package/dist/tests/utilities/TestConfiguration.js +12 -2
  206. package/dist/threads/automation.js +12 -17
  207. package/dist/tsconfig.build.tsbuildinfo +1 -1
  208. package/dist/utilities/csvParser.js +1 -0
  209. package/dist/utilities/fileSystem/index.js +3 -95
  210. package/dist/utilities/fileSystem/utilities.js +2 -1
  211. package/dist/utilities/rowProcessor/index.js +5 -0
  212. package/dist/utilities/usageQuota/rows.js +6 -4
  213. package/package.json +15 -15
  214. package/specs/openapi.json +3 -0
  215. package/specs/openapi.yaml +3 -0
  216. package/src/api/controllers/application.ts +5 -12
  217. package/src/api/controllers/{backup.js → backup.ts} +7 -7
  218. package/src/api/controllers/cloud.js +44 -40
  219. package/src/api/controllers/deploy/index.ts +20 -8
  220. package/src/api/controllers/dev.js +1 -1
  221. package/src/api/controllers/query/index.ts +8 -2
  222. package/src/api/controllers/row/index.ts +50 -65
  223. package/src/api/controllers/row/internal.js +1 -1
  224. package/src/api/controllers/static/index.ts +4 -2
  225. package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  226. package/src/api/controllers/static/templates/preview.hbs +10 -0
  227. package/src/api/controllers/table/bulkFormula.js +4 -3
  228. package/src/api/controllers/table/external.js +4 -4
  229. package/src/api/controllers/table/index.js +4 -4
  230. package/src/api/controllers/table/internal.ts +8 -9
  231. package/src/api/controllers/table/utils.ts +4 -53
  232. package/src/api/controllers/view/index.js +2 -2
  233. package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
  234. package/src/api/routes/backup.ts +10 -0
  235. package/src/api/routes/index.ts +11 -5
  236. package/src/api/routes/tests/backup.spec.js +1 -1
  237. package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
  238. package/src/api/routes/tests/row.spec.js +22 -27
  239. package/src/api/routes/utils/validators.js +2 -2
  240. package/src/api/routes/{webhook.js → webhook.ts} +7 -6
  241. package/src/app.ts +3 -91
  242. package/src/automations/automationUtils.js +2 -2
  243. package/src/automations/bullboard.js +14 -34
  244. package/src/automations/index.js +4 -4
  245. package/src/automations/steps/updateRow.js +2 -2
  246. package/src/automations/tests/automation.spec.js +1 -6
  247. package/src/automations/triggers.js +6 -6
  248. package/src/automations/utils.ts +30 -32
  249. package/src/constants/index.js +4 -10
  250. package/src/db/utils.js +17 -110
  251. package/src/definitions/automations.ts +1 -18
  252. package/src/definitions/datasource.ts +1 -0
  253. package/src/index.ts +1 -0
  254. package/src/integrations/arangodb.ts +2 -0
  255. package/src/integrations/base/sqlTable.ts +1 -0
  256. package/src/integrations/mongodb.ts +290 -27
  257. package/src/integrations/rest.ts +17 -5
  258. package/src/integrations/tests/mongo.spec.ts +19 -19
  259. package/src/integrations/tests/rest.spec.ts +38 -22
  260. package/src/migrations/functions/backfill/app/tables.ts +7 -13
  261. package/src/migrations/functions/backfill/global.ts +1 -1
  262. package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
  263. package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +6 -5
  264. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
  265. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
  266. package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
  267. package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
  268. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
  269. package/src/migrations/index.ts +21 -45
  270. package/src/migrations/tests/index.spec.ts +0 -1
  271. package/src/sdk/app/automations/index.ts +5 -0
  272. package/src/sdk/app/automations/webhook.ts +43 -0
  273. package/src/sdk/app/backups/constants.ts +2 -0
  274. package/src/sdk/app/backups/exports.ts +171 -0
  275. package/src/sdk/app/backups/imports.ts +206 -0
  276. package/src/sdk/app/backups/index.ts +9 -0
  277. package/src/sdk/app/backups/statistics.ts +78 -0
  278. package/src/sdk/app/tables/index.ts +61 -0
  279. package/src/sdk/index.ts +15 -0
  280. package/src/startup.ts +138 -0
  281. package/src/tests/utilities/TestConfiguration.js +12 -2
  282. package/src/threads/automation.ts +20 -27
  283. package/src/utilities/csvParser.js +1 -0
  284. package/src/utilities/fileSystem/index.js +2 -119
  285. package/src/utilities/fileSystem/utilities.js +2 -0
  286. package/src/utilities/rowProcessor/index.js +5 -0
  287. package/src/utilities/usageQuota/rows.js +7 -3
  288. package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
  289. package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
  290. package/coverage/lcov-report/api/routes/backup.js.html +0 -115
  291. package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
  292. package/dist/automations/listeners.js +0 -102
  293. package/src/api/routes/backup.js +0 -10
  294. package/src/automations/listeners.ts +0 -78
  295. package/src/migrations/functions/pluginCount.ts +0 -12
@@ -11,36 +11,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  const { createBullBoard } = require("@bull-board/api");
12
12
  const { BullAdapter } = require("@bull-board/api/bullAdapter");
13
13
  const { KoaAdapter } = require("@bull-board/koa");
14
- const env = require("../environment");
15
- const Queue = env.isTest()
16
- ? require("../utilities/queue/inMemoryQueue")
17
- : require("bull");
18
- const { JobQueues } = require("../constants");
19
- const { utils } = require("@budibase/backend-core/redis");
20
- const { opts, redisProtocolUrl } = utils.getRedisOptions();
21
- const listeners = require("./listeners");
22
- const CLEANUP_PERIOD_MS = 60 * 1000;
23
- const queueConfig = redisProtocolUrl || { redis: opts };
24
- let cleanupInternal = null;
25
- let automationQueue = new Queue(JobQueues.AUTOMATIONS, queueConfig);
26
- listeners.addListeners(automationQueue);
27
- function cleanup() {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- yield automationQueue.clean(CLEANUP_PERIOD_MS, "completed");
30
- });
31
- }
14
+ const { queue } = require("@budibase/backend-core");
15
+ const automation = require("../threads/automation");
16
+ const { backups } = require("@budibase/pro");
17
+ let automationQueue = queue.createQueue(queue.JobQueue.AUTOMATION, automation.removeStalled);
32
18
  const PATH_PREFIX = "/bulladmin";
33
- exports.init = () => {
34
- // cleanup the events every 5 minutes
35
- if (!cleanupInternal) {
36
- cleanupInternal = setInterval(cleanup, CLEANUP_PERIOD_MS);
37
- // fire off an initial cleanup
38
- cleanup().catch(err => {
39
- console.error(`Unable to cleanup automation queue initially - ${err}`);
40
- });
41
- }
19
+ exports.init = () => __awaiter(void 0, void 0, void 0, function* () {
42
20
  // Set up queues for bull board admin
21
+ const backupQueue = yield backups.getBackupQueue();
43
22
  const queues = [automationQueue];
23
+ if (backupQueue) {
24
+ queues.push(backupQueue);
25
+ }
44
26
  const adapters = [];
45
27
  const serverAdapter = new KoaAdapter();
46
28
  for (let queue of queues) {
@@ -52,13 +34,8 @@ exports.init = () => {
52
34
  });
53
35
  serverAdapter.setBasePath(PATH_PREFIX);
54
36
  return serverAdapter.registerPlugin();
55
- };
37
+ });
56
38
  exports.shutdown = () => __awaiter(void 0, void 0, void 0, function* () {
57
- if (automationQueue) {
58
- clearInterval(cleanupInternal);
59
- yield automationQueue.close();
60
- automationQueue = null;
61
- }
62
- console.log("Bull shutdown");
39
+ yield queue.shutdown();
63
40
  });
64
- exports.queue = automationQueue;
41
+ exports.automationQueue = automationQueue;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  const { processEvent } = require("./utils");
12
- const { queue, shutdown } = require("./bullboard");
12
+ const { automationQueue, shutdown } = require("./bullboard");
13
13
  const { TRIGGER_DEFINITIONS, rebootTrigger } = require("./triggers");
14
14
  const { ACTION_DEFINITIONS } = require("./actions");
15
15
  /**
@@ -18,7 +18,7 @@ const { ACTION_DEFINITIONS } = require("./actions");
18
18
  exports.init = function () {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
20
  // this promise will not complete
21
- const promise = queue.process((job) => __awaiter(this, void 0, void 0, function* () {
21
+ const promise = automationQueue.process((job) => __awaiter(this, void 0, void 0, function* () {
22
22
  yield processEvent(job);
23
23
  }));
24
24
  // on init we need to trigger any reboot automations
@@ -27,11 +27,11 @@ exports.init = function () {
27
27
  });
28
28
  };
29
29
  exports.getQueues = () => {
30
- return [queue];
30
+ return [automationQueue];
31
31
  };
32
32
  exports.shutdown = () => {
33
33
  return shutdown();
34
34
  };
35
- exports.queue = queue;
35
+ exports.automationQueue = automationQueue;
36
36
  exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS;
37
37
  exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS;
@@ -74,9 +74,9 @@ exports.run = function ({ inputs, appId, emitter }) {
74
74
  };
75
75
  }
76
76
  const tableId = inputs.row.tableId;
77
- // clear any falsy properties so that they aren't updated
77
+ // clear any undefined, null or empty string properties so that they aren't updated
78
78
  for (let propKey of Object.keys(inputs.row)) {
79
- if (!inputs.row[propKey] || inputs.row[propKey] === "") {
79
+ if (inputs.row[propKey] == null || inputs.row[propKey] === "") {
80
80
  delete inputs.row[propKey];
81
81
  }
82
82
  }
@@ -14,7 +14,7 @@ const { coerce } = require("../utilities/rowProcessor");
14
14
  const { definitions } = require("./triggerInfo");
15
15
  const { isDevAppID } = require("../db/utils");
16
16
  // need this to call directly, so we can get a response
17
- const { queue } = require("./bullboard");
17
+ const { automationQueue } = require("./bullboard");
18
18
  const { checkTestFlag } = require("../utilities/redis");
19
19
  const utils = require("./utils");
20
20
  const env = require("../environment");
@@ -57,7 +57,7 @@ function queueRelevantRowAutomations(event, eventType) {
57
57
  }
58
58
  if (automationTrigger.inputs &&
59
59
  automationTrigger.inputs.tableId === event.row.tableId) {
60
- yield queue.add({ automation, event }, JOB_OPTS);
60
+ yield automationQueue.add({ automation, event }, JOB_OPTS);
61
61
  }
62
62
  }
63
63
  }));
@@ -110,14 +110,14 @@ exports.externalTrigger = function (automation, params, { getResponses } = {}) {
110
110
  return utils.processEvent({ data });
111
111
  }
112
112
  else {
113
- return queue.add(data, JOB_OPTS);
113
+ return automationQueue.add(data, JOB_OPTS);
114
114
  }
115
115
  });
116
116
  };
117
117
  exports.rebootTrigger = () => __awaiter(void 0, void 0, void 0, function* () {
118
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) {
119
+ // startup and only usable in self host and single tenant environments
120
+ if (env.isInThread() || !env.SELF_HOSTED || env.MULTI_TENANCY) {
121
121
  return;
122
122
  }
123
123
  // iterate through all production apps, find the reboot crons
@@ -136,7 +136,7 @@ exports.rebootTrigger = () => __awaiter(void 0, void 0, void 0, function* () {
136
136
  timestamp: Date.now(),
137
137
  },
138
138
  };
139
- rebootEvents.push(queue.add(job, JOB_OPTS));
139
+ rebootEvents.push(automationQueue.add(job, JOB_OPTS));
140
140
  }
141
141
  }
142
142
  yield Promise.all(rebootEvents);
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,10 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
13
  };
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.isErrorInOutput = exports.isRecurring = exports.cleanupAutomations = exports.checkForWebhooks = exports.enableCronTrigger = exports.isRebootTrigger = exports.isCronTrigger = exports.clearMetadata = exports.disableCron = exports.disableAllCrons = exports.removeDeprecated = exports.updateTestHistory = exports.processEvent = void 0;
15
+ exports.isErrorInOutput = exports.isRecurring = exports.cleanupAutomations = exports.checkForWebhooks = exports.enableCronTrigger = exports.isRebootTrigger = exports.isCronTrigger = exports.clearMetadata = exports.disableCronById = exports.disableAllCrons = exports.removeDeprecated = exports.updateTestHistory = exports.processEvent = void 0;
39
16
  const threads_1 = require("../threads");
40
17
  const triggerInfo_1 = require("./triggerInfo");
41
- const webhooks = __importStar(require("../api/controllers/webhook"));
42
18
  const bullboard_1 = require("./bullboard");
43
19
  const newid_1 = __importDefault(require("../db/newid"));
44
20
  const utilities_1 = require("../utilities");
@@ -49,6 +25,8 @@ const fp_1 = require("lodash/fp");
49
25
  const context_1 = require("@budibase/backend-core/context");
50
26
  const backend_core_1 = require("@budibase/backend-core");
51
27
  const pro_1 = require("@budibase/pro");
28
+ const types_1 = require("@budibase/types");
29
+ const sdk_1 = __importDefault(require("../sdk"));
52
30
  const REBOOT_CRON = "@reboot";
53
31
  const WH_STEP_ID = triggerInfo_1.definitions.WEBHOOK.stepId;
54
32
  const CRON_STEP_ID = triggerInfo_1.definitions.CRON.stepId;
@@ -59,12 +37,14 @@ const jobMessage = (job, message) => {
59
37
  function processEvent(job) {
60
38
  return __awaiter(this, void 0, void 0, function* () {
61
39
  try {
40
+ const automationId = job.data.automation._id;
62
41
  console.log(jobMessage(job, "running"));
63
42
  // need to actually await these so that an error can be captured properly
64
- const tenantId = backend_core_1.tenancy.getTenantIDFromAppID(job.data.event.appId);
65
- return yield backend_core_1.tenancy.doInTenant(tenantId, () => __awaiter(this, void 0, void 0, function* () {
43
+ return yield backend_core_1.context.doInContext(job.data.event.appId, () => __awaiter(this, void 0, void 0, function* () {
66
44
  const runFn = () => Runner.run(job);
67
- return pro_1.quotas.addAutomation(runFn);
45
+ return pro_1.quotas.addAutomation(runFn, {
46
+ automationId,
47
+ });
68
48
  }));
69
49
  }
70
50
  catch (err) {
@@ -106,12 +86,12 @@ exports.removeDeprecated = removeDeprecated;
106
86
  function disableAllCrons(appId) {
107
87
  return __awaiter(this, void 0, void 0, function* () {
108
88
  const promises = [];
109
- const jobs = yield bullboard_1.queue.getRepeatableJobs();
89
+ const jobs = yield bullboard_1.automationQueue.getRepeatableJobs();
110
90
  for (let job of jobs) {
111
91
  if (job.key.includes(`${appId}_cron`)) {
112
- promises.push(bullboard_1.queue.removeRepeatableByKey(job.key));
92
+ promises.push(bullboard_1.automationQueue.removeRepeatableByKey(job.key));
113
93
  if (job.id) {
114
- promises.push(bullboard_1.queue.removeJobs(job.id));
94
+ promises.push(bullboard_1.automationQueue.removeJobs(job.id));
115
95
  }
116
96
  }
117
97
  }
@@ -119,14 +99,18 @@ function disableAllCrons(appId) {
119
99
  });
120
100
  }
121
101
  exports.disableAllCrons = disableAllCrons;
122
- function disableCron(jobId, jobKey) {
102
+ function disableCronById(jobId) {
123
103
  return __awaiter(this, void 0, void 0, function* () {
124
- yield bullboard_1.queue.removeRepeatableByKey(jobKey);
125
- yield bullboard_1.queue.removeJobs(jobId);
104
+ const repeatJobs = yield bullboard_1.automationQueue.getRepeatableJobs();
105
+ for (let repeatJob of repeatJobs) {
106
+ if (repeatJob.id === jobId) {
107
+ yield bullboard_1.automationQueue.removeRepeatableByKey(repeatJob.key);
108
+ }
109
+ }
126
110
  console.log(`jobId=${jobId} disabled`);
127
111
  });
128
112
  }
129
- exports.disableCron = disableCron;
113
+ exports.disableCronById = disableCronById;
130
114
  function clearMetadata() {
131
115
  return __awaiter(this, void 0, void 0, function* () {
132
116
  const db = (0, context_1.getProdAppDB)();
@@ -165,7 +149,7 @@ function enableCronTrigger(appId, automation) {
165
149
  (trigger === null || trigger === void 0 ? void 0 : trigger.inputs.cron)) {
166
150
  // make a job id rather than letting Bull decide, makes it easier to handle on way out
167
151
  const jobId = `${appId}_cron_${(0, newid_1.default)()}`;
168
- const job = yield bullboard_1.queue.add({
152
+ const job = yield bullboard_1.automationQueue.add({
169
153
  automation,
170
154
  event: { appId, timestamp: Date.now() },
171
155
  }, { repeat: { cron: trigger.inputs.cron }, jobId });
@@ -211,16 +195,12 @@ function checkForWebhooks({ oldAuto, newAuto }) {
211
195
  let db = (0, context_1.getAppDB)();
212
196
  // need to get the webhook to get the rev
213
197
  const webhook = yield db.get(oldTrigger.webhookId);
214
- const ctx = {
215
- appId,
216
- params: { id: webhook._id, rev: webhook._rev },
217
- };
218
198
  // might be updating - reset the inputs to remove the URLs
219
199
  if (newTrigger) {
220
200
  delete newTrigger.webhookId;
221
201
  newTrigger.inputs = {};
222
202
  }
223
- yield webhooks.destroy(ctx);
203
+ yield sdk_1.default.automations.webhook.destroy(webhook._id, webhook._rev);
224
204
  }
225
205
  catch (err) {
226
206
  // don't worry about not being able to delete, if it doesn't exist all good
@@ -229,14 +209,8 @@ function checkForWebhooks({ oldAuto, newAuto }) {
229
209
  // need to create webhook
230
210
  if ((!isWebhookTrigger(oldAuto) || triggerChanged) &&
231
211
  isWebhookTrigger(newAuto)) {
232
- const ctx = {
233
- appId,
234
- request: {
235
- body: new webhooks.Webhook("Automation webhook", constants_1.WebhookType.AUTOMATION, newAuto._id),
236
- },
237
- };
238
- yield webhooks.save(ctx);
239
- const id = ctx.body.webhook._id;
212
+ const webhook = yield sdk_1.default.automations.webhook.save(sdk_1.default.automations.webhook.newDoc("Automation webhook", types_1.WebhookActionType.AUTOMATION, newAuto._id));
213
+ const id = webhook._id;
240
214
  newTrigger.webhookId = id;
241
215
  // the app ID has to be development for this endpoint
242
216
  // it can only be used when building the app
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
2
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
3
3
  const { UserStatus } = require("@budibase/backend-core/constants");
4
- const { ObjectStoreBuckets } = require("@budibase/backend-core/objectStore");
5
- exports.JobQueues = {
6
- AUTOMATIONS: "automationQueue",
7
- };
4
+ const { objectStore } = require("@budibase/backend-core");
8
5
  const FilterTypes = {
9
6
  STRING: "string",
10
7
  FUZZY: "fuzzy",
@@ -28,6 +25,7 @@ exports.NoEmptyFilterStrings = [
28
25
  ];
29
26
  exports.FieldTypes = {
30
27
  STRING: "string",
28
+ BARCODEQR: "barcodeqr",
31
29
  LONGFORM: "longform",
32
30
  OPTIONS: "options",
33
31
  NUMBER: "number",
@@ -47,6 +45,7 @@ exports.CanSwitchTypes = [
47
45
  exports.FieldTypes.STRING,
48
46
  exports.FieldTypes.OPTIONS,
49
47
  exports.FieldTypes.LONGFORM,
48
+ exports.FieldTypes.BARCODEQR,
50
49
  ],
51
50
  [exports.FieldTypes.BOOLEAN, exports.FieldTypes.NUMBER],
52
51
  ];
@@ -177,14 +176,11 @@ exports.BuildSchemaErrors = {
177
176
  NO_KEY: "no_key",
178
177
  INVALID_COLUMN: "invalid_column",
179
178
  };
180
- exports.WebhookType = {
181
- AUTOMATION: "automation",
182
- };
183
179
  exports.AutomationErrors = {
184
180
  INCORRECT_TYPE: "INCORRECT_TYPE",
185
181
  MAX_ITERATIONS: "MAX_ITERATIONS_REACHED",
186
182
  FAILURE_CONDITION: "FAILURE_CONDITION_MET",
187
183
  };
188
184
  // pass through the list from the auth/core lib
189
- exports.ObjectStoreBuckets = ObjectStoreBuckets;
185
+ exports.ObjectStoreBuckets = objectStore.ObjectStoreBuckets;
190
186
  exports.MAX_AUTOMATION_RECURRING_ERRORS = 5;
package/dist/db/utils.js CHANGED
@@ -1,16 +1,13 @@
1
1
  "use strict";
2
2
  const newid = require("./newid");
3
- const { DocumentType: CoreDocTypes, getRoleParams, generateRoleID, APP_DEV_PREFIX, APP_PREFIX, SEPARATOR, StaticDatabases, isDevAppID, isProdAppID, getDevelopmentAppID, generateAppID, getQueryIndex, ViewName, } = require("@budibase/backend-core/db");
3
+ const { DocumentType: CoreDocType, InternalTable, getRoleParams, generateRoleID, APP_DEV_PREFIX, APP_PREFIX, SEPARATOR, StaticDatabases, isDevAppID, isProdAppID, getDevelopmentAppID, generateAppID, getQueryIndex, ViewName, getDocParams, getRowParams, generateRowID, getUserMetadataParams, generateUserMetadataID, getGlobalIDFromUserMetadataID, } = require("@budibase/backend-core/db");
4
4
  const UNICODE_MAX = "\ufff0";
5
5
  const AppStatus = {
6
6
  DEV: "development",
7
7
  ALL: "all",
8
8
  DEPLOYED: "published",
9
9
  };
10
- const DocumentType = Object.assign(Object.assign({}, CoreDocTypes), { TABLE: "ta", ROW: "ro", USER: "us", AUTOMATION: "au", LINK: "li", WEBHOOK: "wh", INSTANCE: "inst", LAYOUT: "layout", SCREEN: "screen", DATASOURCE: "datasource", DATASOURCE_PLUS: "datasource_plus", QUERY: "query", DEPLOYMENTS: "deployments", METADATA: "metadata", MEM_VIEW: "view", USER_FLAG: "flag", AUTOMATION_METADATA: "meta_au" });
11
- const InternalTables = {
12
- USER_METADATA: "ta_users",
13
- };
10
+ const DocumentType = CoreDocType;
14
11
  const SearchIndexes = {
15
12
  ROWS: "rows",
16
13
  };
@@ -26,11 +23,11 @@ exports.APP_PREFIX = APP_PREFIX;
26
23
  exports.APP_DEV_PREFIX = APP_DEV_PREFIX;
27
24
  exports.isDevAppID = isDevAppID;
28
25
  exports.isProdAppID = isProdAppID;
29
- exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`;
30
- exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`;
26
+ exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`;
27
+ exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`;
31
28
  exports.TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`;
32
29
  exports.ViewName = ViewName;
33
- exports.InternalTables = InternalTables;
30
+ exports.InternalTables = InternalTable;
34
31
  exports.DocumentType = DocumentType;
35
32
  exports.SEPARATOR = SEPARATOR;
36
33
  exports.UNICODE_MAX = UNICODE_MAX;
@@ -42,25 +39,12 @@ exports.generateDevAppID = getDevelopmentAppID;
42
39
  exports.generateRoleID = generateRoleID;
43
40
  exports.getRoleParams = getRoleParams;
44
41
  exports.getQueryIndex = getQueryIndex;
45
- /**
46
- * If creating DB allDocs/query params with only a single top level ID this can be used, this
47
- * is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
48
- * More complex cases such as link docs and rows which have multiple levels of IDs that their
49
- * ID consists of need their own functions to build the allDocs parameters.
50
- * @param {string} docType The type of document which input params are being built for, e.g. user,
51
- * link, app, table and so on.
52
- * @param {string|null} docId The ID of the document minus its type - this is only needed if looking
53
- * for a singular document.
54
- * @param {object} otherProps Add any other properties onto the request, e.g. include_docs.
55
- * @returns {object} Parameters which can then be used with an allDocs request.
56
- */
57
- function getDocParams(docType, docId = null, otherProps = {}) {
58
- if (docId == null) {
59
- docId = "";
60
- }
61
- return Object.assign(Object.assign({}, otherProps), { startkey: `${docType}${SEPARATOR}${docId}`, endkey: `${docType}${SEPARATOR}${docId}${UNICODE_MAX}` });
62
- }
63
42
  exports.getDocParams = getDocParams;
43
+ exports.getRowParams = getRowParams;
44
+ exports.generateRowID = generateRowID;
45
+ exports.getUserMetadataParams = getUserMetadataParams;
46
+ exports.generateUserMetadataID = generateUserMetadataID;
47
+ exports.getGlobalIDFromUserMetadataID = getGlobalIDFromUserMetadataID;
64
48
  /**
65
49
  * Gets parameters for retrieving tables, this is a utility function for the getDocParams function.
66
50
  */
@@ -74,21 +58,6 @@ exports.getTableParams = (tableId = null, otherProps = {}) => {
74
58
  exports.generateTableID = () => {
75
59
  return `${DocumentType.TABLE}${SEPARATOR}${newid()}`;
76
60
  };
77
- /**
78
- * Gets the DB allDocs/query params for retrieving a row.
79
- * @param {string|null} tableId The table in which the rows have been stored.
80
- * @param {string|null} rowId The ID of the row which is being specifically queried for. This can be
81
- * left null to get all the rows in the table.
82
- * @param {object} otherProps Any other properties to add to the request.
83
- * @returns {object} Parameters which can then be used with an allDocs request.
84
- */
85
- exports.getRowParams = (tableId = null, rowId = null, otherProps = {}) => {
86
- if (tableId == null) {
87
- return getDocParams(DocumentType.ROW, null, otherProps);
88
- }
89
- const endOfKey = rowId == null ? `${tableId}${SEPARATOR}` : rowId;
90
- return getDocParams(DocumentType.ROW, endOfKey, otherProps);
91
- };
92
61
  /**
93
62
  * Given a row ID this will find the table ID within it (only works for internal tables).
94
63
  * @param {string} rowId The ID of the row.
@@ -100,40 +69,6 @@ exports.getTableIDFromRowID = rowId => {
100
69
  .split(SEPARATOR);
101
70
  return `${DocumentType.TABLE}${SEPARATOR}${components[0]}`;
102
71
  };
103
- /**
104
- * Gets a new row ID for the specified table.
105
- * @param {string} tableId The table which the row is being created for.
106
- * @param {string|null} id If an ID is to be used then the UUID can be substituted for this.
107
- * @returns {string} The new ID which a row doc can be stored under.
108
- */
109
- exports.generateRowID = (tableId, id = null) => {
110
- id = id || newid();
111
- return `${DocumentType.ROW}${SEPARATOR}${tableId}${SEPARATOR}${id}`;
112
- };
113
- /**
114
- * Gets parameters for retrieving users, this is a utility function for the getDocParams function.
115
- */
116
- exports.getUserMetadataParams = (userId = null, otherProps = {}) => {
117
- return exports.getRowParams(InternalTables.USER_METADATA, userId, otherProps);
118
- };
119
- /**
120
- * Generates a new user ID based on the passed in global ID.
121
- * @param {string} globalId The ID of the global user.
122
- * @returns {string} The new user ID which the user doc can be stored under.
123
- */
124
- exports.generateUserMetadataID = globalId => {
125
- return exports.generateRowID(InternalTables.USER_METADATA, globalId);
126
- };
127
- /**
128
- * Breaks up the ID to get the global ID.
129
- */
130
- exports.getGlobalIDFromUserMetadataID = id => {
131
- const prefix = `${DocumentType.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`;
132
- if (!id || !id.includes(prefix)) {
133
- return id;
134
- }
135
- return id.split(prefix)[1];
136
- };
137
72
  /**
138
73
  * Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
139
74
  */
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ function runServer() {
9
9
  checkDevelopmentEnvironment();
10
10
  fixPath();
11
11
  // this will setup http and https proxies form env variables
12
+ process.env.GLOBAL_AGENT_FORCE_GLOBAL_AGENT = "false";
12
13
  (0, global_agent_1.bootstrap)();
13
14
  require("./app");
14
15
  }
@@ -53,6 +53,8 @@ const SCHEMA = {
53
53
  class ArangoDBIntegration {
54
54
  constructor(config) {
55
55
  const newConfig = {
56
+ url: config.url,
57
+ databaseName: config.databaseName,
56
58
  auth: {
57
59
  username: config.username,
58
60
  password: config.password,
@@ -31,6 +31,7 @@ function generateSchema(schema, table, tables, oldTable = null, renamed) {
31
31
  case FieldTypes.STRING:
32
32
  case FieldTypes.OPTIONS:
33
33
  case FieldTypes.LONGFORM:
34
+ case FieldTypes.BARCODEQR:
34
35
  schema.text(key);
35
36
  break;
36
37
  case FieldTypes.NUMBER: