@budibase/worker 2.0.30-alpha.0 → 2.0.30-alpha.2
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-alpha.
|
|
4
|
+
"version": "2.0.30-alpha.2",
|
|
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-alpha.
|
|
40
|
-
"@budibase/pro": "2.0.
|
|
41
|
-
"@budibase/string-templates": "2.0.30-alpha.
|
|
42
|
-
"@budibase/types": "2.0.30-alpha.
|
|
39
|
+
"@budibase/backend-core": "2.0.30-alpha.2",
|
|
40
|
+
"@budibase/pro": "2.0.30-alpha.1",
|
|
41
|
+
"@budibase/string-templates": "2.0.30-alpha.2",
|
|
42
|
+
"@budibase/types": "2.0.30-alpha.2",
|
|
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": "d5b65426c0d87bf44de3bd8ed396554387d55af4"
|
|
108
108
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 }
|
package/src/migrations/index.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { migrations,
|
|
2
|
-
import {
|
|
1
|
+
import { migrations, locks } from "@budibase/backend-core"
|
|
2
|
+
import {
|
|
3
|
+
Migration,
|
|
4
|
+
MigrationOptions,
|
|
5
|
+
MigrationName,
|
|
6
|
+
LockType,
|
|
7
|
+
LockName,
|
|
8
|
+
} from "@budibase/types"
|
|
3
9
|
import env from "../environment"
|
|
4
10
|
|
|
5
11
|
// migration functions
|
|
@@ -42,33 +48,14 @@ export const migrate = async (options?: MigrationOptions) => {
|
|
|
42
48
|
}
|
|
43
49
|
|
|
44
50
|
const migrateWithLock = async (options?: MigrationOptions) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
51
|
+
await locks.doWithLock(
|
|
52
|
+
{
|
|
53
|
+
type: LockType.TRY_ONCE,
|
|
54
|
+
name: LockName.MIGRATIONS,
|
|
55
|
+
ttl: 1000 * 60 * 15, // auto expire the migration lock after 15 minutes
|
|
56
|
+
},
|
|
57
|
+
async () => {
|
|
58
|
+
await migrations.runMigrations(MIGRATIONS, options)
|
|
60
59
|
}
|
|
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
|
-
}
|
|
60
|
+
)
|
|
74
61
|
}
|
package/src/sdk/users/events.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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"
|
|
5
4
|
|
|
6
5
|
export const handleDeleteEvents = async (user: any) => {
|
|
7
6
|
await events.user.deleted(user)
|
|
@@ -1,58 +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
|
-
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
|
-
}
|