@budibase/worker 2.0.30-alpha.1 → 2.0.30
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.0.30
|
|
4
|
+
"version": "2.0.30",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"author": "Budibase",
|
|
37
37
|
"license": "GPL-3.0",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@budibase/backend-core": "2.0.30
|
|
40
|
-
"@budibase/pro": "2.0.
|
|
41
|
-
"@budibase/string-templates": "2.0.30
|
|
42
|
-
"@budibase/types": "2.0.30
|
|
39
|
+
"@budibase/backend-core": "^2.0.30",
|
|
40
|
+
"@budibase/pro": "2.0.29",
|
|
41
|
+
"@budibase/string-templates": "^2.0.30",
|
|
42
|
+
"@budibase/types": "^2.0.30",
|
|
43
43
|
"@koa/router": "8.0.8",
|
|
44
44
|
"@sentry/node": "6.17.7",
|
|
45
45
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
@@ -104,5 +104,5 @@
|
|
|
104
104
|
"./scripts/jestSetup.js"
|
|
105
105
|
]
|
|
106
106
|
},
|
|
107
|
-
"gitHead": "
|
|
107
|
+
"gitHead": "ec85bd13aeabb93d9a68ae32bf9c2504b216c6ac"
|
|
108
108
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const { StaticDatabases, doWithDB } = require("@budibase/backend-core/db")
|
|
2
|
+
const { getTenantId } = require("@budibase/backend-core/tenancy")
|
|
3
|
+
const { deleteTenant } = require("@budibase/backend-core/deprovision")
|
|
4
|
+
const { quotas } = require("@budibase/pro")
|
|
5
|
+
|
|
6
|
+
exports.exists = async ctx => {
|
|
7
|
+
const tenantId = ctx.request.params
|
|
8
|
+
ctx.body = {
|
|
9
|
+
exists: await doWithDB(StaticDatabases.PLATFORM_INFO.name, async db => {
|
|
10
|
+
let exists = false
|
|
11
|
+
try {
|
|
12
|
+
const tenantsDoc = await db.get(
|
|
13
|
+
StaticDatabases.PLATFORM_INFO.docs.tenants
|
|
14
|
+
)
|
|
15
|
+
if (tenantsDoc) {
|
|
16
|
+
exists = tenantsDoc.tenantIds.indexOf(tenantId) !== -1
|
|
17
|
+
}
|
|
18
|
+
} catch (err) {
|
|
19
|
+
// if error it doesn't exist
|
|
20
|
+
}
|
|
21
|
+
return exists
|
|
22
|
+
}),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.fetch = async ctx => {
|
|
27
|
+
ctx.body = await doWithDB(StaticDatabases.PLATFORM_INFO.name, async db => {
|
|
28
|
+
let tenants = []
|
|
29
|
+
try {
|
|
30
|
+
const tenantsDoc = await db.get(
|
|
31
|
+
StaticDatabases.PLATFORM_INFO.docs.tenants
|
|
32
|
+
)
|
|
33
|
+
if (tenantsDoc) {
|
|
34
|
+
tenants = tenantsDoc.tenantIds
|
|
35
|
+
}
|
|
36
|
+
} catch (err) {
|
|
37
|
+
// if error it doesn't exist
|
|
38
|
+
}
|
|
39
|
+
return tenants
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.delete = async ctx => {
|
|
44
|
+
const tenantId = getTenantId()
|
|
45
|
+
|
|
46
|
+
if (ctx.params.tenantId !== tenantId) {
|
|
47
|
+
ctx.throw(403, "Unauthorized")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
await deleteTenant(tenantId)
|
|
52
|
+
await quotas.bustCache()
|
|
53
|
+
ctx.status = 204
|
|
54
|
+
} catch (err) {
|
|
55
|
+
ctx.log.error(err)
|
|
56
|
+
throw err
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/migrations/index.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
import { migrations,
|
|
2
|
-
import {
|
|
3
|
-
Migration,
|
|
4
|
-
MigrationOptions,
|
|
5
|
-
MigrationName,
|
|
6
|
-
LockType,
|
|
7
|
-
LockName,
|
|
8
|
-
} from "@budibase/types"
|
|
1
|
+
import { migrations, redis } from "@budibase/backend-core"
|
|
2
|
+
import { Migration, MigrationOptions, MigrationName } from "@budibase/types"
|
|
9
3
|
import env from "../environment"
|
|
10
4
|
|
|
11
5
|
// migration functions
|
|
@@ -48,14 +42,33 @@ export const migrate = async (options?: MigrationOptions) => {
|
|
|
48
42
|
}
|
|
49
43
|
|
|
50
44
|
const migrateWithLock = async (options?: MigrationOptions) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
// get a new lock client
|
|
46
|
+
const redlock = await redis.clients.getMigrationsRedlock()
|
|
47
|
+
// lock for 15 minutes
|
|
48
|
+
const ttl = 1000 * 60 * 15
|
|
49
|
+
|
|
50
|
+
let migrationLock
|
|
51
|
+
|
|
52
|
+
// acquire lock
|
|
53
|
+
try {
|
|
54
|
+
migrationLock = await redlock.lock("migrations", ttl)
|
|
55
|
+
} catch (e: any) {
|
|
56
|
+
if (e.name === "LockError") {
|
|
57
|
+
return
|
|
58
|
+
} else {
|
|
59
|
+
throw e
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// run migrations
|
|
64
|
+
try {
|
|
65
|
+
await migrations.runMigrations(MIGRATIONS, options)
|
|
66
|
+
} finally {
|
|
67
|
+
// release lock
|
|
68
|
+
try {
|
|
69
|
+
await migrationLock.unlock()
|
|
70
|
+
} catch (e) {
|
|
71
|
+
console.error("unable to release migration lock")
|
|
72
|
+
}
|
|
73
|
+
}
|
|
61
74
|
}
|
package/src/sdk/users/events.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import env from "../../environment"
|
|
2
2
|
import { events, accounts, tenancy } from "@budibase/backend-core"
|
|
3
3
|
import { User, UserRoles, CloudAccount } from "@budibase/types"
|
|
4
|
+
import { users as pro } from "@budibase/pro"
|
|
4
5
|
|
|
5
6
|
export const handleDeleteEvents = async (user: any) => {
|
|
6
7
|
await events.user.deleted(user)
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const { StaticDatabases, doWithDB } = require("@budibase/backend-core/db")
|
|
2
|
-
const { getTenantId } = require("@budibase/backend-core/tenancy")
|
|
3
|
-
const { deleteTenant } = require("@budibase/backend-core/deprovision")
|
|
4
|
-
import { quotas } from "@budibase/pro"
|
|
5
|
-
|
|
6
|
-
export const exists = async (ctx: any) => {
|
|
7
|
-
const tenantId = ctx.request.params
|
|
8
|
-
ctx.body = {
|
|
9
|
-
exists: await doWithDB(
|
|
10
|
-
StaticDatabases.PLATFORM_INFO.name,
|
|
11
|
-
async (db: any) => {
|
|
12
|
-
let exists = false
|
|
13
|
-
try {
|
|
14
|
-
const tenantsDoc = await db.get(
|
|
15
|
-
StaticDatabases.PLATFORM_INFO.docs.tenants
|
|
16
|
-
)
|
|
17
|
-
if (tenantsDoc) {
|
|
18
|
-
exists = tenantsDoc.tenantIds.indexOf(tenantId) !== -1
|
|
19
|
-
}
|
|
20
|
-
} catch (err) {
|
|
21
|
-
// if error it doesn't exist
|
|
22
|
-
}
|
|
23
|
-
return exists
|
|
24
|
-
}
|
|
25
|
-
),
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const fetch = async (ctx: any) => {
|
|
30
|
-
ctx.body = await doWithDB(
|
|
31
|
-
StaticDatabases.PLATFORM_INFO.name,
|
|
32
|
-
async (db: any) => {
|
|
33
|
-
let tenants = []
|
|
34
|
-
try {
|
|
35
|
-
const tenantsDoc = await db.get(
|
|
36
|
-
StaticDatabases.PLATFORM_INFO.docs.tenants
|
|
37
|
-
)
|
|
38
|
-
if (tenantsDoc) {
|
|
39
|
-
tenants = tenantsDoc.tenantIds
|
|
40
|
-
}
|
|
41
|
-
} catch (err) {
|
|
42
|
-
// if error it doesn't exist
|
|
43
|
-
}
|
|
44
|
-
return tenants
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const _delete = async (ctx: any) => {
|
|
50
|
-
const tenantId = getTenantId()
|
|
51
|
-
|
|
52
|
-
if (ctx.params.tenantId !== tenantId) {
|
|
53
|
-
ctx.throw(403, "Unauthorized")
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
try {
|
|
57
|
-
await deleteTenant(tenantId)
|
|
58
|
-
await quotas.bustCache()
|
|
59
|
-
ctx.status = 204
|
|
60
|
-
} catch (err) {
|
|
61
|
-
ctx.log.error(err)
|
|
62
|
-
throw err
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { _delete as delete }
|