@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.
- package/__mocks__/node-fetch.ts +12 -2
- package/builder/assets/{index.cf543543.js → index.02132811.js} +201 -201
- package/builder/index.html +1 -1
- package/coverage/clover.xml +429 -499
- package/coverage/coverage-final.json +49 -51
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +13 -13
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +20 -20
- package/coverage/lcov-report/api/controllers/index.html +9 -24
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +4 -4
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +26 -26
- package/coverage/lcov-report/api/routes/analytics.js.html +7 -7
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/automation.js.html +11 -11
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +5 -20
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +9 -9
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +9 -9
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/screen.js.html +9 -9
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +10 -10
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +45 -45
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +25 -10
- package/coverage/lcov-report/automations/index.html +16 -16
- package/coverage/lcov-report/automations/index.js.html +4 -4
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +15 -15
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +23 -23
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +4 -16
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +1 -1
- package/coverage/lcov-report/db/utils.js.html +2 -2
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +2 -2
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +52 -52
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
- package/coverage/lcov-report/middleware/builder.js.html +9 -9
- package/coverage/lcov-report/middleware/currentapp.js.html +14 -14
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
- package/coverage/lcov-report/middleware/resourceId.js.html +22 -22
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +3 -3
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +20 -20
- package/coverage/lcov-report/utilities/index.js.html +2 -2
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +46 -46
- package/coverage/lcov.info +496 -600
- package/dist/api/controllers/row/index.js +34 -80
- package/dist/api/controllers/row/internal.js +1 -1
- package/dist/api/controllers/static/index.js +1 -0
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/dist/api/controllers/webhook.js +88 -89
- package/dist/api/routes/utils/validators.js +2 -2
- package/dist/api/routes/webhook.js +39 -11
- package/dist/app.js +2 -84
- package/dist/automations/bullboard.js +7 -2
- package/dist/automations/utils.js +5 -37
- package/dist/constants/index.js +0 -3
- package/dist/package.json +6 -6
- package/dist/sdk/app/automations/index.js +29 -0
- package/dist/sdk/app/automations/webhook.js +54 -0
- package/dist/sdk/app/backups/imports.js +29 -1
- package/dist/sdk/index.js +2 -0
- package/dist/startup.js +152 -0
- package/dist/tests/utilities/TestConfiguration.js +8 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/api/controllers/row/index.ts +42 -80
- package/src/api/controllers/row/internal.js +1 -1
- package/src/api/controllers/static/index.ts +2 -0
- package/src/api/controllers/static/templates/BudibaseApp.svelte +11 -0
- package/src/api/controllers/{webhook.js → webhook.ts} +33 -48
- package/src/api/routes/utils/validators.js +2 -2
- package/src/api/routes/{webhook.js → webhook.ts} +7 -6
- package/src/app.ts +3 -108
- package/src/automations/bullboard.js +6 -1
- package/src/automations/utils.ts +12 -20
- package/src/constants/index.js +0 -4
- package/src/definitions/automations.ts +1 -6
- package/src/migrations/functions/tests/syncQuotas.spec.js +1 -3
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +6 -4
- package/src/sdk/app/automations/index.ts +5 -0
- package/src/sdk/app/automations/webhook.ts +43 -0
- package/src/sdk/app/backups/imports.ts +43 -6
- package/src/sdk/index.ts +2 -0
- package/src/startup.ts +138 -0
- package/src/tests/utilities/TestConfiguration.js +7 -0
- package/coverage/lcov-report/api/controllers/webhook.js.html +0 -424
- 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,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 {
|
|
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 {
|
|
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
|
|
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
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)
|