@budibase/server 2.0.39 → 2.0.40-alpha.1

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 (297) 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.b09e13ca.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/elasticsearch.js +26 -2
  187. package/dist/integrations/mongodb.js +300 -11
  188. package/dist/integrations/rest.js +38 -5
  189. package/dist/migrations/functions/backfill/app/tables.js +5 -8
  190. package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
  191. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
  192. package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
  193. package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
  194. package/dist/migrations/index.js +10 -38
  195. package/dist/package.json +14 -14
  196. package/dist/sdk/app/automations/index.js +29 -0
  197. package/dist/sdk/app/automations/webhook.js +54 -0
  198. package/dist/sdk/app/backups/constants.js +5 -0
  199. package/dist/sdk/app/backups/exports.js +172 -0
  200. package/dist/sdk/app/backups/imports.js +190 -0
  201. package/dist/sdk/app/backups/index.js +29 -0
  202. package/dist/sdk/app/backups/statistics.js +73 -0
  203. package/dist/sdk/app/tables/index.js +61 -0
  204. package/dist/sdk/index.js +17 -0
  205. package/dist/startup.js +152 -0
  206. package/dist/tests/utilities/TestConfiguration.js +12 -2
  207. package/dist/threads/automation.js +12 -17
  208. package/dist/tsconfig.build.tsbuildinfo +1 -1
  209. package/dist/utilities/csvParser.js +1 -0
  210. package/dist/utilities/fileSystem/index.js +3 -95
  211. package/dist/utilities/fileSystem/utilities.js +2 -1
  212. package/dist/utilities/rowProcessor/index.js +5 -0
  213. package/dist/utilities/usageQuota/rows.js +6 -4
  214. package/package.json +15 -15
  215. package/specs/openapi.json +3 -0
  216. package/specs/openapi.yaml +3 -0
  217. package/src/api/controllers/application.ts +5 -12
  218. package/src/api/controllers/{backup.js → backup.ts} +7 -7
  219. package/src/api/controllers/cloud.js +44 -40
  220. package/src/api/controllers/deploy/index.ts +20 -8
  221. package/src/api/controllers/dev.js +1 -1
  222. package/src/api/controllers/query/index.ts +8 -2
  223. package/src/api/controllers/row/index.ts +50 -65
  224. package/src/api/controllers/row/internal.js +1 -1
  225. package/src/api/controllers/static/index.ts +4 -2
  226. package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  227. package/src/api/controllers/static/templates/preview.hbs +10 -0
  228. package/src/api/controllers/table/bulkFormula.js +4 -3
  229. package/src/api/controllers/table/external.js +4 -4
  230. package/src/api/controllers/table/index.js +4 -4
  231. package/src/api/controllers/table/internal.ts +8 -9
  232. package/src/api/controllers/table/utils.ts +4 -53
  233. package/src/api/controllers/view/index.js +2 -2
  234. package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
  235. package/src/api/routes/backup.ts +10 -0
  236. package/src/api/routes/index.ts +11 -5
  237. package/src/api/routes/tests/backup.spec.js +1 -1
  238. package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
  239. package/src/api/routes/tests/row.spec.js +22 -27
  240. package/src/api/routes/utils/validators.js +2 -2
  241. package/src/api/routes/{webhook.js → webhook.ts} +7 -6
  242. package/src/app.ts +3 -91
  243. package/src/automations/automationUtils.js +2 -2
  244. package/src/automations/bullboard.js +14 -34
  245. package/src/automations/index.js +4 -4
  246. package/src/automations/steps/updateRow.js +2 -2
  247. package/src/automations/tests/automation.spec.js +1 -6
  248. package/src/automations/triggers.js +6 -6
  249. package/src/automations/utils.ts +30 -32
  250. package/src/constants/index.js +4 -10
  251. package/src/db/utils.js +17 -110
  252. package/src/definitions/automations.ts +1 -18
  253. package/src/definitions/datasource.ts +1 -0
  254. package/src/index.ts +1 -0
  255. package/src/integrations/arangodb.ts +2 -0
  256. package/src/integrations/base/sqlTable.ts +1 -0
  257. package/src/integrations/elasticsearch.ts +32 -2
  258. package/src/integrations/mongodb.ts +290 -27
  259. package/src/integrations/rest.ts +17 -5
  260. package/src/integrations/tests/mongo.spec.ts +19 -19
  261. package/src/integrations/tests/rest.spec.ts +38 -22
  262. package/src/migrations/functions/backfill/app/tables.ts +7 -13
  263. package/src/migrations/functions/backfill/global.ts +1 -1
  264. package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
  265. package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +6 -5
  266. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
  267. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
  268. package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
  269. package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
  270. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
  271. package/src/migrations/index.ts +21 -45
  272. package/src/migrations/tests/index.spec.ts +0 -1
  273. package/src/sdk/app/automations/index.ts +5 -0
  274. package/src/sdk/app/automations/webhook.ts +43 -0
  275. package/src/sdk/app/backups/constants.ts +2 -0
  276. package/src/sdk/app/backups/exports.ts +171 -0
  277. package/src/sdk/app/backups/imports.ts +206 -0
  278. package/src/sdk/app/backups/index.ts +9 -0
  279. package/src/sdk/app/backups/statistics.ts +78 -0
  280. package/src/sdk/app/tables/index.ts +61 -0
  281. package/src/sdk/index.ts +15 -0
  282. package/src/startup.ts +138 -0
  283. package/src/tests/utilities/TestConfiguration.js +12 -2
  284. package/src/threads/automation.ts +20 -27
  285. package/src/utilities/csvParser.js +1 -0
  286. package/src/utilities/fileSystem/index.js +2 -119
  287. package/src/utilities/fileSystem/utilities.js +2 -0
  288. package/src/utilities/rowProcessor/index.js +5 -0
  289. package/src/utilities/usageQuota/rows.js +7 -3
  290. package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
  291. package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
  292. package/coverage/lcov-report/api/routes/backup.js.html +0 -115
  293. package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
  294. package/dist/automations/listeners.js +0 -102
  295. package/src/api/routes/backup.js +0 -10
  296. package/src/automations/listeners.ts +0 -78
  297. package/src/migrations/functions/pluginCount.ts +0 -12
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const context_1 = require("@budibase/backend-core/context");
13
+ const utils_1 = require("../../../db/utils");
14
+ const utils_2 = require("../../../integrations/utils");
15
+ function getAllInternalTables(db) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ if (!db) {
18
+ db = (0, context_1.getAppDB)();
19
+ }
20
+ const internalTables = yield db.allDocs((0, utils_1.getTableParams)(null, {
21
+ include_docs: true,
22
+ }));
23
+ return internalTables.rows.map((tableDoc) => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: utils_1.BudibaseInternalDB._id })));
24
+ });
25
+ }
26
+ function getAllExternalTables(datasourceId) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const db = (0, context_1.getAppDB)();
29
+ const datasource = yield db.get(datasourceId);
30
+ if (!datasource || !datasource.entities) {
31
+ throw "Datasource is not configured fully.";
32
+ }
33
+ return datasource.entities;
34
+ });
35
+ }
36
+ function getExternalTable(datasourceId, tableName) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const entities = yield getAllExternalTables(datasourceId);
39
+ return entities[tableName];
40
+ });
41
+ }
42
+ function getTable(tableId) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const db = (0, context_1.getAppDB)();
45
+ if ((0, utils_2.isExternalTable)(tableId)) {
46
+ let { datasourceId, tableName } = (0, utils_2.breakExternalTableId)(tableId);
47
+ const datasource = yield db.get(datasourceId);
48
+ const table = yield getExternalTable(datasourceId, tableName);
49
+ return Object.assign(Object.assign({}, table), { sql: (0, utils_2.isSQL)(datasource) });
50
+ }
51
+ else {
52
+ return db.get(tableId);
53
+ }
54
+ });
55
+ }
56
+ exports.default = {
57
+ getAllInternalTables,
58
+ getAllExternalTables,
59
+ getExternalTable,
60
+ getTable,
61
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const backups_1 = __importDefault(require("./app/backups"));
7
+ const tables_1 = __importDefault(require("./app/tables"));
8
+ const automations_1 = __importDefault(require("./app/automations"));
9
+ const sdk = {
10
+ backups: backups_1.default,
11
+ tables: tables_1.default,
12
+ automations: automations_1.default,
13
+ };
14
+ // default export for TS
15
+ exports.default = sdk;
16
+ // default export for JS
17
+ module.exports = sdk;
@@ -0,0 +1,152 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.startup = void 0;
39
+ const env = __importStar(require("./environment"));
40
+ const redis_1 = __importDefault(require("./utilities/redis"));
41
+ const workerRequests_1 = require("./utilities/workerRequests");
42
+ const backend_core_1 = require("@budibase/backend-core");
43
+ const fs_1 = __importDefault(require("fs"));
44
+ const watch_1 = require("./watch");
45
+ const automations_1 = __importDefault(require("./automations"));
46
+ const fileSystem_1 = __importDefault(require("./utilities/fileSystem"));
47
+ const events_1 = __importDefault(require("./events"));
48
+ const migrations = __importStar(require("./migrations"));
49
+ const bullboard_1 = __importDefault(require("./automations/bullboard"));
50
+ const pro = __importStar(require("@budibase/pro"));
51
+ const api_1 = __importDefault(require("./api"));
52
+ const sdk_1 = __importDefault(require("./sdk"));
53
+ const pino = require("koa-pino-logger");
54
+ let STARTUP_RAN = false;
55
+ function initRoutes(app) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ app.use(pino((0, backend_core_1.pinoSettings)()));
58
+ if (!env.isTest()) {
59
+ const plugin = yield bullboard_1.default.init();
60
+ app.use(plugin);
61
+ }
62
+ app.context.eventEmitter = events_1.default;
63
+ app.context.auth = {};
64
+ // api routes
65
+ app.use(api_1.default.router.routes());
66
+ });
67
+ }
68
+ function initPro() {
69
+ return __awaiter(this, void 0, void 0, function* () {
70
+ yield pro.init({
71
+ backups: {
72
+ processing: {
73
+ exportAppFn: sdk_1.default.backups.exportApp,
74
+ importAppFn: sdk_1.default.backups.importApp,
75
+ statsFn: sdk_1.default.backups.calculateBackupStats,
76
+ },
77
+ },
78
+ });
79
+ });
80
+ }
81
+ function shutdown(server) {
82
+ server.close();
83
+ server.destroy();
84
+ }
85
+ function startup(app, server) {
86
+ var _a;
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (STARTUP_RAN) {
89
+ return;
90
+ }
91
+ STARTUP_RAN = true;
92
+ if (server) {
93
+ console.log(`Budibase running on ${JSON.stringify(server.address())}`);
94
+ env._set("PORT", server.address().port);
95
+ }
96
+ events_1.default.emitPort(env.PORT);
97
+ fileSystem_1.default.init();
98
+ yield redis_1.default.init();
99
+ // run migrations on startup if not done via http
100
+ // not recommended in a clustered environment
101
+ if (!env.HTTP_MIGRATIONS && !env.isTest()) {
102
+ try {
103
+ yield migrations.migrate();
104
+ }
105
+ catch (e) {
106
+ backend_core_1.logging.logAlert("Error performing migrations. Exiting.", e);
107
+ shutdown();
108
+ }
109
+ }
110
+ // check and create admin user if required
111
+ if (env.SELF_HOSTED &&
112
+ !env.MULTI_TENANCY &&
113
+ env.BB_ADMIN_USER_EMAIL &&
114
+ env.BB_ADMIN_USER_PASSWORD) {
115
+ const checklist = yield (0, workerRequests_1.getChecklist)();
116
+ if (!((_a = checklist === null || checklist === void 0 ? void 0 : checklist.adminUser) === null || _a === void 0 ? void 0 : _a.checked)) {
117
+ try {
118
+ const tenantId = backend_core_1.tenancy.getTenantId();
119
+ const user = yield (0, workerRequests_1.createAdminUser)(env.BB_ADMIN_USER_EMAIL, env.BB_ADMIN_USER_PASSWORD, tenantId);
120
+ // Need to set up an API key for automated integration tests
121
+ if (env.isTest()) {
122
+ yield (0, workerRequests_1.generateApiKey)(user._id);
123
+ }
124
+ console.log("Admin account automatically created for", env.BB_ADMIN_USER_EMAIL);
125
+ }
126
+ catch (e) {
127
+ backend_core_1.logging.logAlert("Error creating initial admin user. Exiting.", e);
128
+ shutdown();
129
+ }
130
+ }
131
+ }
132
+ // monitor plugin directory if required
133
+ if (env.SELF_HOSTED &&
134
+ !env.MULTI_TENANCY &&
135
+ env.PLUGINS_DIR &&
136
+ fs_1.default.existsSync(env.PLUGINS_DIR)) {
137
+ (0, watch_1.watch)();
138
+ }
139
+ // check for version updates
140
+ yield backend_core_1.installation.checkInstallVersion();
141
+ // get the references to the queue promises, don't await as
142
+ // they will never end, unless the processing stops
143
+ let queuePromises = [];
144
+ queuePromises.push(automations_1.default.init());
145
+ queuePromises.push(initPro());
146
+ if (app) {
147
+ // bring routes online as final step once everything ready
148
+ yield initRoutes(app);
149
+ }
150
+ });
151
+ }
152
+ exports.startup = startup;
@@ -24,7 +24,8 @@ const newid = require("../../db/newid");
24
24
  const context = require("@budibase/backend-core/context");
25
25
  const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db");
26
26
  const { encrypt } = require("@budibase/backend-core/encryption");
27
- const { DocumentType } = require("../../db/utils");
27
+ const { DocumentType, generateUserMetadataID } = require("../../db/utils");
28
+ const { startup } = require("../../startup");
28
29
  const GLOBAL_USER_ID = "us_uuid1";
29
30
  const EMAIL = "babs@babs.com";
30
31
  const FIRSTNAME = "Barbara";
@@ -38,6 +39,10 @@ class TestConfiguration {
38
39
  this.server = require("../../app");
39
40
  // we need the request for logging in, involves cookies, hard to fake
40
41
  this.request = supertest(this.server);
42
+ this.started = true;
43
+ }
44
+ else {
45
+ this.started = false;
41
46
  }
42
47
  this.appId = null;
43
48
  this.allApps = [];
@@ -87,7 +92,12 @@ class TestConfiguration {
87
92
  // use a new id as the name to avoid name collisions
88
93
  init(appName = newid()) {
89
94
  return __awaiter(this, void 0, void 0, function* () {
90
- yield this.globalUser();
95
+ if (!this.started) {
96
+ yield startup();
97
+ }
98
+ this.user = yield this.globalUser();
99
+ this.globalUserId = this.user._id;
100
+ this.userMetadataId = generateUserMetadataID(this.globalUserId);
91
101
  return this.createApp(appName);
92
102
  });
93
103
  }
@@ -72,16 +72,12 @@ function getLoopIterations(loopStep, input) {
72
72
  * inputs and handles any outputs.
73
73
  */
74
74
  class Orchestrator {
75
- constructor(automation, triggerOutput, opts) {
75
+ constructor(job) {
76
+ let automation = job.data.automation, triggerOutput = job.data.event;
76
77
  const metadata = triggerOutput.metadata;
77
78
  this._chainCount = metadata ? metadata.automationChainCount : 0;
78
79
  this._appId = triggerOutput.appId;
79
- if (opts === null || opts === void 0 ? void 0 : opts.repeat) {
80
- this._repeat = {
81
- jobId: opts.repeat.jobId,
82
- jobKey: opts.repeat.key,
83
- };
84
- }
80
+ this._job = job;
85
81
  const triggerStepId = automation.definition.trigger.stepId;
86
82
  triggerOutput = this.cleanupTriggerOutputs(triggerStepId, triggerOutput);
87
83
  // remove from context
@@ -131,15 +127,14 @@ class Orchestrator {
131
127
  });
132
128
  }
133
129
  stopCron(reason) {
134
- var _a, _b;
135
130
  return __awaiter(this, void 0, void 0, function* () {
136
- if (!this._repeat) {
131
+ if (!this._job.opts.repeat) {
137
132
  return;
138
133
  }
139
134
  logWarn(`CRON disabled reason=${reason} - ${this._appId}/${this._automation._id}`);
140
135
  const automation = this._automation;
141
136
  const trigger = automation.definition.trigger;
142
- yield (0, utils_2.disableCron)((_a = this._repeat) === null || _a === void 0 ? void 0 : _a.jobId, (_b = this._repeat) === null || _b === void 0 ? void 0 : _b.jobKey);
137
+ yield (0, utils_2.disableCronById)(this._job.id);
143
138
  this.updateExecutionOutput(trigger.id, trigger.stepId, {}, {
144
139
  status: types_1.AutomationStatus.STOPPED_ERROR,
145
140
  success: false,
@@ -149,7 +144,7 @@ class Orchestrator {
149
144
  }
150
145
  checkIfShouldStop(metadata) {
151
146
  return __awaiter(this, void 0, void 0, function* () {
152
- if (!metadata.errorCount || !this._repeat) {
147
+ if (!metadata.errorCount || !this._job.opts.repeat) {
153
148
  return false;
154
149
  }
155
150
  if (metadata.errorCount >= constants_1.MAX_AUTOMATION_RECURRING_ERRORS) {
@@ -404,13 +399,13 @@ class Orchestrator {
404
399
  });
405
400
  }
406
401
  }
407
- function execute(input, callback) {
408
- const appId = input.data.event.appId;
402
+ function execute(job, callback) {
403
+ const appId = job.data.event.appId;
409
404
  if (!appId) {
410
405
  throw new Error("Unable to execute, event doesn't contain app ID.");
411
406
  }
412
407
  doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
413
- const automationOrchestrator = new Orchestrator(input.data.automation, input.data.event, input.opts);
408
+ const automationOrchestrator = new Orchestrator(job);
414
409
  try {
415
410
  const response = yield automationOrchestrator.execute();
416
411
  callback(null, response);
@@ -421,13 +416,13 @@ function execute(input, callback) {
421
416
  }));
422
417
  }
423
418
  exports.execute = execute;
424
- const removeStalled = (input) => __awaiter(void 0, void 0, void 0, function* () {
425
- const appId = input.data.event.appId;
419
+ const removeStalled = (job) => __awaiter(void 0, void 0, void 0, function* () {
420
+ const appId = job.data.event.appId;
426
421
  if (!appId) {
427
422
  throw new Error("Unable to execute, event doesn't contain app ID.");
428
423
  }
429
424
  yield doInAppContext(appId, () => __awaiter(void 0, void 0, void 0, function* () {
430
- const automationOrchestrator = new Orchestrator(input.data.automation, input.data.event, input.opts);
425
+ const automationOrchestrator = new Orchestrator(job);
431
426
  yield automationOrchestrator.stopCron("stalled");
432
427
  }));
433
428
  });