@budibase/server 2.0.34-alpha.1 → 2.0.34-alpha.10

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 (190) hide show
  1. package/__mocks__/node-fetch.ts +12 -2
  2. package/builder/assets/{index.cf543543.js → index.02132811.js} +201 -201
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +429 -499
  5. package/coverage/coverage-final.json +49 -51
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  7. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/cloud.js.html +13 -13
  9. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/dev.js.html +20 -20
  11. package/coverage/lcov-report/api/controllers/index.html +9 -24
  12. package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
  13. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  15. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  16. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  18. package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
  19. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  21. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  23. package/coverage/lcov-report/api/controllers/row/internal.js.html +2 -2
  24. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  33. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  36. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  39. package/coverage/lcov-report/api/index.html +1 -1
  40. package/coverage/lcov-report/api/index.js.html +26 -26
  41. package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
  42. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  43. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  44. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  45. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  46. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  47. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  48. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  49. package/coverage/lcov-report/api/routes/index.html +5 -20
  50. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  51. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  53. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  54. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  55. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  56. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  57. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  58. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  59. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  61. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  62. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  63. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  64. package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
  65. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  66. package/coverage/lcov-report/automations/actions.js.html +1 -1
  67. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  68. package/coverage/lcov-report/automations/bullboard.js.html +25 -10
  69. package/coverage/lcov-report/automations/index.html +16 -16
  70. package/coverage/lcov-report/automations/index.js.html +4 -4
  71. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  72. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  73. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  74. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  75. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/index.html +15 -15
  78. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
  87. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  88. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  89. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  90. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  91. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggers.js.html +23 -23
  97. package/coverage/lcov-report/constants/index.html +5 -5
  98. package/coverage/lcov-report/constants/index.js.html +4 -16
  99. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  100. package/coverage/lcov-report/constants/screens.js.html +1 -1
  101. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  102. package/coverage/lcov-report/db/index.html +1 -1
  103. package/coverage/lcov-report/db/index.js.html +1 -1
  104. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  105. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  106. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  107. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  108. package/coverage/lcov-report/db/newid.js.html +1 -1
  109. package/coverage/lcov-report/db/utils.js.html +2 -2
  110. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  111. package/coverage/lcov-report/events/index.html +1 -1
  112. package/coverage/lcov-report/events/index.js.html +2 -2
  113. package/coverage/lcov-report/events/utils.js.html +1 -1
  114. package/coverage/lcov-report/index.html +52 -52
  115. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  116. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  117. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  118. package/coverage/lcov-report/middleware/builder.js.html +9 -9
  119. package/coverage/lcov-report/middleware/currentapp.js.html +14 -14
  120. package/coverage/lcov-report/middleware/index.html +1 -1
  121. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  122. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  123. package/coverage/lcov-report/middleware/resourceId.js.html +22 -22
  124. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  125. package/coverage/lcov-report/middleware/utils.js.html +3 -3
  126. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  127. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  128. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  129. package/coverage/lcov-report/utilities/global.js.html +1 -1
  130. package/coverage/lcov-report/utilities/index.html +20 -20
  131. package/coverage/lcov-report/utilities/index.js.html +2 -2
  132. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  133. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  134. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  135. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  136. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  137. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  138. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  139. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  140. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  141. package/coverage/lcov-report/utilities/security.js.html +1 -1
  142. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  143. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  144. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  145. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  146. package/coverage/lcov-report/utilities/users.js.html +1 -1
  147. package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
  148. package/coverage/lcov.info +496 -600
  149. package/dist/api/controllers/row/index.js +34 -80
  150. package/dist/api/controllers/row/internal.js +1 -1
  151. package/dist/api/controllers/static/index.js +1 -0
  152. package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  153. package/dist/api/controllers/webhook.js +88 -89
  154. package/dist/api/routes/utils/validators.js +2 -2
  155. package/dist/api/routes/webhook.js +39 -11
  156. package/dist/app.js +2 -84
  157. package/dist/automations/bullboard.js +7 -2
  158. package/dist/automations/utils.js +5 -37
  159. package/dist/constants/index.js +0 -3
  160. package/dist/package.json +6 -6
  161. package/dist/sdk/app/automations/index.js +29 -0
  162. package/dist/sdk/app/automations/webhook.js +54 -0
  163. package/dist/sdk/app/backups/imports.js +29 -1
  164. package/dist/sdk/index.js +2 -0
  165. package/dist/startup.js +152 -0
  166. package/dist/tests/utilities/TestConfiguration.js +8 -0
  167. package/dist/tsconfig.build.tsbuildinfo +1 -1
  168. package/package.json +7 -7
  169. package/src/api/controllers/row/index.ts +42 -80
  170. package/src/api/controllers/row/internal.js +1 -1
  171. package/src/api/controllers/static/index.ts +2 -0
  172. package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
  173. package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
  174. package/src/api/routes/utils/validators.js +2 -2
  175. package/src/api/routes/{webhook.js → webhook.ts} +7 -6
  176. package/src/app.ts +3 -108
  177. package/src/automations/bullboard.js +6 -1
  178. package/src/automations/utils.ts +12 -20
  179. package/src/constants/index.js +0 -4
  180. package/src/definitions/automations.ts +1 -6
  181. package/src/migrations/functions/tests/syncQuotas.spec.js +1 -3
  182. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
  183. package/src/sdk/app/automations/index.ts +5 -0
  184. package/src/sdk/app/automations/webhook.ts +43 -0
  185. package/src/sdk/app/backups/imports.ts +43 -6
  186. package/src/sdk/index.ts +2 -0
  187. package/src/startup.ts +138 -0
  188. package/src/tests/utilities/TestConfiguration.js +7 -0
  189. package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
  190. package/coverage/lcov-report/api/routes/webhook.js.html +0 -163
@@ -1,13 +1,11 @@
1
- const TestConfig = require("../../../tests/utilities/TestConfiguration")
2
-
3
1
  const syncApps = jest.fn()
4
2
  const syncRows = jest.fn()
5
3
  const syncPlugins = jest.fn()
6
-
7
4
  jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
8
5
  jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
9
6
  jest.mock("../usageQuotas/syncPlugins", () => ({ run: syncPlugins }) )
10
7
 
8
+ const TestConfig = require("../../../tests/utilities/TestConfiguration")
11
9
  const migration = require("../syncQuotas")
12
10
 
13
11
  describe("run", () => {
@@ -1,11 +1,13 @@
1
+ jest.mock("@budibase/backend-core/db", () => ({
2
+ ...jest.requireActual("@budibase/backend-core/db"),
3
+ createNewUserEmailView: jest.fn(),
4
+ }))
5
+ const coreDb = require("@budibase/backend-core/db")
1
6
  const TestConfig = require("../../../tests/utilities/TestConfiguration")
2
7
  const { TENANT_ID } = require("../../../tests/utilities/structures")
3
8
  const { getGlobalDB, doInTenant } = require("@budibase/backend-core/tenancy")
4
9
 
5
10
  // mock email view creation
6
- const coreDb = require("@budibase/backend-core/db")
7
- const createNewUserEmailView = jest.fn()
8
- coreDb.createNewUserEmailView = createNewUserEmailView
9
11
 
10
12
  const migration = require("../userEmailViewCasing")
11
13
 
@@ -22,7 +24,7 @@ describe("run", () => {
22
24
  await doInTenant(TENANT_ID, async () => {
23
25
  const globalDb = getGlobalDB()
24
26
  await migration.run(globalDb)
25
- expect(createNewUserEmailView).toHaveBeenCalledTimes(1)
27
+ expect(coreDb.createNewUserEmailView).toHaveBeenCalledTimes(1)
26
28
  })
27
29
  })
28
30
  })
@@ -0,0 +1,5 @@
1
+ import * as webhook from "./webhook"
2
+
3
+ export default {
4
+ webhook,
5
+ }
@@ -0,0 +1,43 @@
1
+ import { Webhook, WebhookActionType } from "@budibase/types"
2
+ import { db as dbCore, context } from "@budibase/backend-core"
3
+ import { generateWebhookID } from "../../../db/utils"
4
+
5
+ function isWebhookID(id: string) {
6
+ return id.startsWith(dbCore.DocumentType.WEBHOOK)
7
+ }
8
+
9
+ export function newDoc(
10
+ name: string,
11
+ type: WebhookActionType,
12
+ target: string
13
+ ): Webhook {
14
+ return {
15
+ live: true,
16
+ name,
17
+ action: {
18
+ type,
19
+ target,
20
+ },
21
+ }
22
+ }
23
+
24
+ export async function save(webhook: Webhook) {
25
+ const db = context.getAppDB()
26
+ // check that the webhook exists
27
+ if (webhook._id && isWebhookID(webhook._id)) {
28
+ await db.get(webhook._id)
29
+ } else {
30
+ webhook._id = generateWebhookID()
31
+ }
32
+ const response = await db.put(webhook)
33
+ webhook._rev = response.rev
34
+ return webhook
35
+ }
36
+
37
+ export async function destroy(id: string, rev: string) {
38
+ const db = context.getAppDB()
39
+ if (!id || !isWebhookID(id)) {
40
+ throw new Error("Provided webhook ID is not valid.")
41
+ }
42
+ return await db.remove(id, rev)
43
+ }
@@ -1,20 +1,25 @@
1
1
  import { db as dbCore } from "@budibase/backend-core"
2
- import { TABLE_ROW_PREFIX } from "../../../db/utils"
2
+ import { getAutomationParams, TABLE_ROW_PREFIX } from "../../../db/utils"
3
3
  import { budibaseTempDir } from "../../../utilities/budibaseDir"
4
4
  import { DB_EXPORT_FILE, GLOBAL_DB_EXPORT_FILE } from "./constants"
5
5
  import {
6
- uploadDirectory,
7
6
  upload,
7
+ uploadDirectory,
8
8
  } from "../../../utilities/fileSystem/utilities"
9
9
  import { downloadTemplate } from "../../../utilities/fileSystem"
10
- import { ObjectStoreBuckets, FieldTypes } from "../../../constants"
10
+ import { FieldTypes, ObjectStoreBuckets } from "../../../constants"
11
11
  import { join } from "path"
12
12
  import fs from "fs"
13
13
  import sdk from "../../"
14
- import { CouchFindOptions, RowAttachment } from "@budibase/types"
14
+ import {
15
+ Automation,
16
+ AutomationTriggerStepId,
17
+ CouchFindOptions,
18
+ RowAttachment,
19
+ } from "@budibase/types"
20
+ import PouchDB from "pouchdb"
15
21
  const uuid = require("uuid/v4")
16
22
  const tar = require("tar")
17
- import PouchDB from "pouchdb"
18
23
 
19
24
  type TemplateType = {
20
25
  file?: {
@@ -81,12 +86,43 @@ async function updateAttachmentColumns(
81
86
  }
82
87
  }
83
88
 
89
+ async function updateAutomations(prodAppId: string, db: PouchDB.Database) {
90
+ const automations = (
91
+ await db.allDocs(
92
+ getAutomationParams(null, {
93
+ include_docs: true,
94
+ })
95
+ )
96
+ ).rows.map(row => row.doc) as Automation[]
97
+ const devAppId = dbCore.getDevAppID(prodAppId)
98
+ let toSave: Automation[] = []
99
+ for (let automation of automations) {
100
+ const oldDevAppId = automation.appId,
101
+ oldProdAppId = dbCore.getProdAppID(automation.appId)
102
+ if (
103
+ automation.definition.trigger.stepId === AutomationTriggerStepId.WEBHOOK
104
+ ) {
105
+ const old = automation.definition.trigger.inputs
106
+ automation.definition.trigger.inputs = {
107
+ schemaUrl: old.schemaUrl.replace(oldDevAppId, devAppId),
108
+ triggerUrl: old.triggerUrl.replace(oldProdAppId, prodAppId),
109
+ }
110
+ }
111
+ automation.appId = devAppId
112
+ toSave.push(automation)
113
+ }
114
+ await db.bulkDocs(toSave)
115
+ }
116
+
84
117
  /**
85
118
  * This function manages temporary template files which are stored by Koa.
86
119
  * @param {Object} template The template object retrieved from the Koa context object.
87
120
  * @returns {Object} Returns a fs read stream which can be loaded into the database.
88
121
  */
89
122
  async function getTemplateStream(template: TemplateType) {
123
+ if (template.file && template.file.type !== "text/plain") {
124
+ throw new Error("Cannot import a non-text based file.")
125
+ }
90
126
  if (template.file) {
91
127
  return fs.createReadStream(template.file.path)
92
128
  } else if (template.key) {
@@ -123,7 +159,7 @@ export async function importApp(
123
159
  ) {
124
160
  let prodAppId = dbCore.getProdAppID(appId)
125
161
  let dbStream: any
126
- const isTar = template.file && template.file.type === "application/gzip"
162
+ const isTar = template.file && template?.file?.type?.endsWith("gzip")
127
163
  const isDirectory =
128
164
  template.file && fs.lstatSync(template.file.path).isDirectory()
129
165
  if (template.file && (isTar || isDirectory)) {
@@ -165,5 +201,6 @@ export async function importApp(
165
201
  throw "Error loading database dump from template."
166
202
  }
167
203
  await updateAttachmentColumns(prodAppId, db)
204
+ await updateAutomations(prodAppId, db)
168
205
  return ok
169
206
  }
package/src/sdk/index.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  import { default as backups } from "./app/backups"
2
2
  import { default as tables } from "./app/tables"
3
+ import { default as automations } from "./app/automations"
3
4
 
4
5
  const sdk = {
5
6
  backups,
6
7
  tables,
8
+ automations,
7
9
  }
8
10
 
9
11
  // default export for TS
package/src/startup.ts ADDED
@@ -0,0 +1,138 @@
1
+ import * as env from "./environment"
2
+ import redis from "./utilities/redis"
3
+ import {
4
+ createAdminUser,
5
+ generateApiKey,
6
+ getChecklist,
7
+ } from "./utilities/workerRequests"
8
+ import {
9
+ installation,
10
+ pinoSettings,
11
+ tenancy,
12
+ logging,
13
+ } from "@budibase/backend-core"
14
+ import fs from "fs"
15
+ import { watch } from "./watch"
16
+ import automations from "./automations"
17
+ import fileSystem from "./utilities/fileSystem"
18
+ import eventEmitter from "./events"
19
+ import * as migrations from "./migrations"
20
+ import bullboard from "./automations/bullboard"
21
+ import * as pro from "@budibase/pro"
22
+ import api from "./api"
23
+ import sdk from "./sdk"
24
+ const pino = require("koa-pino-logger")
25
+
26
+ let STARTUP_RAN = false
27
+
28
+ async function initRoutes(app: any) {
29
+ app.use(pino(pinoSettings()))
30
+
31
+ if (!env.isTest()) {
32
+ const plugin = await bullboard.init()
33
+ app.use(plugin)
34
+ }
35
+
36
+ app.context.eventEmitter = eventEmitter
37
+ app.context.auth = {}
38
+
39
+ // api routes
40
+ app.use(api.router.routes())
41
+ }
42
+
43
+ async function initPro() {
44
+ await pro.init({
45
+ backups: {
46
+ processing: {
47
+ exportAppFn: sdk.backups.exportApp,
48
+ importAppFn: sdk.backups.importApp,
49
+ statsFn: sdk.backups.calculateBackupStats,
50
+ },
51
+ },
52
+ })
53
+ }
54
+
55
+ function shutdown(server?: any) {
56
+ server.close()
57
+ server.destroy()
58
+ }
59
+
60
+ export async function startup(app?: any, server?: any) {
61
+ if (STARTUP_RAN) {
62
+ return
63
+ }
64
+ STARTUP_RAN = true
65
+ if (server) {
66
+ console.log(`Budibase running on ${JSON.stringify(server.address())}`)
67
+ env._set("PORT", server.address().port)
68
+ }
69
+ eventEmitter.emitPort(env.PORT)
70
+ fileSystem.init()
71
+ await redis.init()
72
+
73
+ // run migrations on startup if not done via http
74
+ // not recommended in a clustered environment
75
+ if (!env.HTTP_MIGRATIONS && !env.isTest()) {
76
+ try {
77
+ await migrations.migrate()
78
+ } catch (e) {
79
+ logging.logAlert("Error performing migrations. Exiting.", e)
80
+ shutdown()
81
+ }
82
+ }
83
+
84
+ // check and create admin user if required
85
+ if (
86
+ env.SELF_HOSTED &&
87
+ !env.MULTI_TENANCY &&
88
+ env.BB_ADMIN_USER_EMAIL &&
89
+ env.BB_ADMIN_USER_PASSWORD
90
+ ) {
91
+ const checklist = await getChecklist()
92
+ if (!checklist?.adminUser?.checked) {
93
+ try {
94
+ const tenantId = tenancy.getTenantId()
95
+ const user = await createAdminUser(
96
+ env.BB_ADMIN_USER_EMAIL,
97
+ env.BB_ADMIN_USER_PASSWORD,
98
+ tenantId
99
+ )
100
+ // Need to set up an API key for automated integration tests
101
+ if (env.isTest()) {
102
+ await generateApiKey(user._id)
103
+ }
104
+
105
+ console.log(
106
+ "Admin account automatically created for",
107
+ env.BB_ADMIN_USER_EMAIL
108
+ )
109
+ } catch (e) {
110
+ logging.logAlert("Error creating initial admin user. Exiting.", e)
111
+ shutdown()
112
+ }
113
+ }
114
+ }
115
+
116
+ // monitor plugin directory if required
117
+ if (
118
+ env.SELF_HOSTED &&
119
+ !env.MULTI_TENANCY &&
120
+ env.PLUGINS_DIR &&
121
+ fs.existsSync(env.PLUGINS_DIR)
122
+ ) {
123
+ watch()
124
+ }
125
+
126
+ // check for version updates
127
+ await installation.checkInstallVersion()
128
+
129
+ // get the references to the queue promises, don't await as
130
+ // they will never end, unless the processing stops
131
+ let queuePromises = []
132
+ queuePromises.push(automations.init())
133
+ queuePromises.push(initPro())
134
+ if (app) {
135
+ // bring routes online as final step once everything ready
136
+ await initRoutes(app)
137
+ }
138
+ }
@@ -26,6 +26,7 @@ const context = require("@budibase/backend-core/context")
26
26
  const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db")
27
27
  const { encrypt } = require("@budibase/backend-core/encryption")
28
28
  const { DocumentType, generateUserMetadataID } = require("../../db/utils")
29
+ const { startup } = require("../../startup")
29
30
 
30
31
  const GLOBAL_USER_ID = "us_uuid1"
31
32
  const EMAIL = "babs@babs.com"
@@ -41,6 +42,9 @@ class TestConfiguration {
41
42
  this.server = require("../../app")
42
43
  // we need the request for logging in, involves cookies, hard to fake
43
44
  this.request = supertest(this.server)
45
+ this.started = true
46
+ } else {
47
+ this.started = false
44
48
  }
45
49
  this.appId = null
46
50
  this.allApps = []
@@ -95,6 +99,9 @@ class TestConfiguration {
95
99
 
96
100
  // use a new id as the name to avoid name collisions
97
101
  async init(appName = newid()) {
102
+ if (!this.started) {
103
+ await startup()
104
+ }
98
105
  this.user = await this.globalUser()
99
106
  this.globalUserId = this.user._id
100
107
  this.userMetadataId = generateUserMetadataID(this.globalUserId)