@budibase/backend-core 3.2.4 → 3.2.6
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/dist/index.js.map +1 -1
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +11 -4
- package/dist/plugins.js.meta.json +1 -1
- package/package.json +11 -4
- package/src/accounts/accounts.ts +0 -82
- package/src/accounts/api.ts +0 -59
- package/src/accounts/index.ts +0 -1
- package/src/auth/auth.ts +0 -210
- package/src/auth/index.ts +0 -1
- package/src/auth/tests/auth.spec.ts +0 -14
- package/src/blacklist/blacklist.ts +0 -54
- package/src/blacklist/index.ts +0 -1
- package/src/blacklist/tests/blacklist.spec.ts +0 -46
- package/src/cache/appMetadata.ts +0 -88
- package/src/cache/base/index.ts +0 -150
- package/src/cache/docWritethrough.ts +0 -105
- package/src/cache/generic.ts +0 -33
- package/src/cache/index.ts +0 -8
- package/src/cache/invite.ts +0 -86
- package/src/cache/passwordReset.ts +0 -49
- package/src/cache/tests/docWritethrough.spec.ts +0 -296
- package/src/cache/tests/user.spec.ts +0 -145
- package/src/cache/tests/writethrough.spec.ts +0 -139
- package/src/cache/user.ts +0 -154
- package/src/cache/writethrough.ts +0 -133
- package/src/configs/configs.ts +0 -263
- package/src/configs/index.ts +0 -1
- package/src/configs/tests/configs.spec.ts +0 -184
- package/src/constants/db.ts +0 -75
- package/src/constants/index.ts +0 -2
- package/src/constants/misc.ts +0 -36
- package/src/context/Context.ts +0 -14
- package/src/context/identity.ts +0 -58
- package/src/context/index.ts +0 -3
- package/src/context/mainContext.ts +0 -422
- package/src/context/tests/index.spec.ts +0 -255
- package/src/context/types.ts +0 -26
- package/src/db/Replication.ts +0 -94
- package/src/db/couch/DatabaseImpl.ts +0 -511
- package/src/db/couch/connections.ts +0 -89
- package/src/db/couch/index.ts +0 -4
- package/src/db/couch/pouchDB.ts +0 -97
- package/src/db/couch/pouchDump.ts +0 -0
- package/src/db/couch/tests/DatabaseImpl.spec.ts +0 -118
- package/src/db/couch/utils.ts +0 -55
- package/src/db/db.ts +0 -34
- package/src/db/errors.ts +0 -14
- package/src/db/index.ts +0 -12
- package/src/db/instrumentation.ts +0 -199
- package/src/db/lucene.ts +0 -721
- package/src/db/searchIndexes/index.ts +0 -1
- package/src/db/searchIndexes/searchIndexes.ts +0 -62
- package/src/db/tests/DatabaseImpl.spec.ts +0 -55
- package/src/db/tests/connections.spec.ts +0 -22
- package/src/db/tests/index.spec.ts +0 -32
- package/src/db/tests/lucene.spec.ts +0 -400
- package/src/db/tests/pouch.spec.js +0 -62
- package/src/db/tests/utils.spec.ts +0 -63
- package/src/db/utils.ts +0 -208
- package/src/db/views.ts +0 -245
- package/src/docIds/conversions.ts +0 -60
- package/src/docIds/ids.ts +0 -126
- package/src/docIds/index.ts +0 -2
- package/src/docIds/newid.ts +0 -5
- package/src/docIds/params.ts +0 -189
- package/src/docUpdates/index.ts +0 -24
- package/src/environment.ts +0 -293
- package/src/errors/errors.ts +0 -119
- package/src/errors/index.ts +0 -1
- package/src/events/analytics.ts +0 -6
- package/src/events/asyncEvents/index.ts +0 -2
- package/src/events/asyncEvents/publisher.ts +0 -12
- package/src/events/asyncEvents/queue.ts +0 -22
- package/src/events/backfill.ts +0 -183
- package/src/events/documentId.ts +0 -56
- package/src/events/events.ts +0 -47
- package/src/events/identification.ts +0 -311
- package/src/events/index.ts +0 -15
- package/src/events/processors/AnalyticsProcessor.ts +0 -64
- package/src/events/processors/AuditLogsProcessor.ts +0 -92
- package/src/events/processors/LoggingProcessor.ts +0 -36
- package/src/events/processors/Processors.ts +0 -52
- package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -38
- package/src/events/processors/index.ts +0 -19
- package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
- package/src/events/processors/posthog/index.ts +0 -3
- package/src/events/processors/posthog/rateLimiting.ts +0 -106
- package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -164
- package/src/events/processors/types.ts +0 -1
- package/src/events/publishers/account.ts +0 -41
- package/src/events/publishers/ai.ts +0 -21
- package/src/events/publishers/app.ts +0 -168
- package/src/events/publishers/auditLog.ts +0 -26
- package/src/events/publishers/auth.ts +0 -73
- package/src/events/publishers/automation.ts +0 -110
- package/src/events/publishers/backfill.ts +0 -74
- package/src/events/publishers/backup.ts +0 -42
- package/src/events/publishers/datasource.ts +0 -48
- package/src/events/publishers/email.ts +0 -17
- package/src/events/publishers/environmentVariable.ts +0 -38
- package/src/events/publishers/group.ts +0 -99
- package/src/events/publishers/index.ts +0 -25
- package/src/events/publishers/installation.ts +0 -38
- package/src/events/publishers/layout.ts +0 -26
- package/src/events/publishers/license.ts +0 -84
- package/src/events/publishers/org.ts +0 -37
- package/src/events/publishers/plugin.ts +0 -47
- package/src/events/publishers/query.ts +0 -89
- package/src/events/publishers/role.ts +0 -62
- package/src/events/publishers/rows.ts +0 -29
- package/src/events/publishers/screen.ts +0 -36
- package/src/events/publishers/serve.ts +0 -43
- package/src/events/publishers/table.ts +0 -70
- package/src/events/publishers/user.ts +0 -202
- package/src/events/publishers/view.ts +0 -107
- package/src/features/features.ts +0 -277
- package/src/features/index.ts +0 -2
- package/src/features/tests/features.spec.ts +0 -267
- package/src/features/tests/utils.ts +0 -64
- package/src/helpers.ts +0 -9
- package/src/index.ts +0 -59
- package/src/installation.ts +0 -115
- package/src/logging/alerts.ts +0 -26
- package/src/logging/correlation/correlation.ts +0 -15
- package/src/logging/correlation/index.ts +0 -1
- package/src/logging/correlation/middleware.ts +0 -18
- package/src/logging/index.ts +0 -4
- package/src/logging/pino/logger.ts +0 -239
- package/src/logging/pino/middleware.ts +0 -48
- package/src/logging/system.ts +0 -81
- package/src/logging/tests/system.spec.ts +0 -61
- package/src/middleware/adminOnly.ts +0 -9
- package/src/middleware/auditLog.ts +0 -6
- package/src/middleware/authenticated.ts +0 -247
- package/src/middleware/builderOnly.ts +0 -21
- package/src/middleware/builderOrAdmin.ts +0 -21
- package/src/middleware/contentSecurityPolicy.ts +0 -113
- package/src/middleware/csrf.ts +0 -81
- package/src/middleware/errorHandling.ts +0 -43
- package/src/middleware/index.ts +0 -24
- package/src/middleware/internalApi.ts +0 -23
- package/src/middleware/ip.ts +0 -12
- package/src/middleware/joi-validator.ts +0 -58
- package/src/middleware/matchers.ts +0 -39
- package/src/middleware/passport/datasource/google.ts +0 -102
- package/src/middleware/passport/local.ts +0 -54
- package/src/middleware/passport/sso/google.ts +0 -77
- package/src/middleware/passport/sso/oidc.ts +0 -152
- package/src/middleware/passport/sso/sso.ts +0 -138
- package/src/middleware/passport/sso/tests/google.spec.ts +0 -68
- package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -144
- package/src/middleware/passport/sso/tests/sso.spec.ts +0 -197
- package/src/middleware/passport/utils.ts +0 -38
- package/src/middleware/querystringToBody.ts +0 -28
- package/src/middleware/tenancy.ts +0 -36
- package/src/middleware/tests/builder.spec.ts +0 -181
- package/src/middleware/tests/contentSecurityPolicy.spec.ts +0 -75
- package/src/middleware/tests/matchers.spec.ts +0 -100
- package/src/migrations/definitions.ts +0 -40
- package/src/migrations/index.ts +0 -2
- package/src/migrations/migrations.ts +0 -186
- package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
- package/src/migrations/tests/migrations.spec.ts +0 -64
- package/src/objectStore/buckets/app.ts +0 -53
- package/src/objectStore/buckets/global.ts +0 -29
- package/src/objectStore/buckets/index.ts +0 -3
- package/src/objectStore/buckets/plugins.ts +0 -71
- package/src/objectStore/buckets/tests/app.spec.ts +0 -161
- package/src/objectStore/buckets/tests/global.spec.ts +0 -74
- package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
- package/src/objectStore/cloudfront.ts +0 -41
- package/src/objectStore/index.ts +0 -3
- package/src/objectStore/objectStore.ts +0 -585
- package/src/objectStore/utils.ts +0 -113
- package/src/platform/index.ts +0 -3
- package/src/platform/platformDb.ts +0 -6
- package/src/platform/tenants.ts +0 -101
- package/src/platform/tests/tenants.spec.ts +0 -26
- package/src/platform/users.ts +0 -129
- package/src/plugin/index.ts +0 -1
- package/src/plugin/tests/validation.spec.ts +0 -209
- package/src/plugin/utils.ts +0 -175
- package/src/queue/constants.ts +0 -8
- package/src/queue/inMemoryQueue.ts +0 -189
- package/src/queue/index.ts +0 -2
- package/src/queue/listeners.ts +0 -199
- package/src/queue/queue.ts +0 -84
- package/src/redis/index.ts +0 -6
- package/src/redis/init.ts +0 -118
- package/src/redis/redis.ts +0 -358
- package/src/redis/redlockImpl.ts +0 -155
- package/src/redis/tests/redis.spec.ts +0 -207
- package/src/redis/tests/redlockImpl.spec.ts +0 -105
- package/src/redis/utils.ts +0 -128
- package/src/security/auth.ts +0 -24
- package/src/security/encryption.ts +0 -185
- package/src/security/index.ts +0 -1
- package/src/security/permissions.ts +0 -166
- package/src/security/roles.ts +0 -655
- package/src/security/secrets.ts +0 -20
- package/src/security/sessions.ts +0 -123
- package/src/security/tests/auth.spec.ts +0 -45
- package/src/security/tests/encryption.spec.ts +0 -31
- package/src/security/tests/permissions.spec.ts +0 -146
- package/src/security/tests/secrets.spec.ts +0 -35
- package/src/security/tests/sessions.spec.ts +0 -12
- package/src/sql/designDoc.ts +0 -17
- package/src/sql/index.ts +0 -5
- package/src/sql/sql.ts +0 -1854
- package/src/sql/sqlTable.ts +0 -319
- package/src/sql/utils.ts +0 -193
- package/src/tenancy/db.ts +0 -6
- package/src/tenancy/index.ts +0 -2
- package/src/tenancy/tenancy.ts +0 -148
- package/src/tenancy/tests/tenancy.spec.ts +0 -184
- package/src/timers/index.ts +0 -1
- package/src/timers/timers.ts +0 -22
- package/src/users/db.ts +0 -582
- package/src/users/events.ts +0 -176
- package/src/users/index.ts +0 -4
- package/src/users/lookup.ts +0 -99
- package/src/users/test/db.spec.ts +0 -188
- package/src/users/test/utils.spec.ts +0 -67
- package/src/users/users.ts +0 -353
- package/src/users/utils.ts +0 -81
- package/src/utils/Duration.ts +0 -56
- package/src/utils/hashing.ts +0 -15
- package/src/utils/index.ts +0 -4
- package/src/utils/stringUtils.ts +0 -8
- package/src/utils/tests/Duration.spec.ts +0 -19
- package/src/utils/tests/utils.spec.ts +0 -204
- package/src/utils/utils.ts +0 -249
- package/tests/core/logging.ts +0 -34
- package/tests/core/users/users.spec.js +0 -53
- package/tests/core/utilities/index.ts +0 -7
- package/tests/core/utilities/jestUtils.ts +0 -33
- package/tests/core/utilities/mocks/alerts.ts +0 -4
- package/tests/core/utilities/mocks/date.ts +0 -3
- package/tests/core/utilities/mocks/events.ts +0 -132
- package/tests/core/utilities/mocks/index.ts +0 -9
- package/tests/core/utilities/mocks/licenses.ts +0 -119
- package/tests/core/utilities/queue.ts +0 -9
- package/tests/core/utilities/structures/Chance.ts +0 -20
- package/tests/core/utilities/structures/accounts.ts +0 -80
- package/tests/core/utilities/structures/apps.ts +0 -21
- package/tests/core/utilities/structures/common.ts +0 -7
- package/tests/core/utilities/structures/db.ts +0 -12
- package/tests/core/utilities/structures/documents/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
- package/tests/core/utilities/structures/generator.ts +0 -3
- package/tests/core/utilities/structures/index.ts +0 -15
- package/tests/core/utilities/structures/koa.ts +0 -16
- package/tests/core/utilities/structures/licenses.ts +0 -190
- package/tests/core/utilities/structures/plugins.ts +0 -19
- package/tests/core/utilities/structures/quotas.ts +0 -72
- package/tests/core/utilities/structures/scim.ts +0 -80
- package/tests/core/utilities/structures/sso.ts +0 -118
- package/tests/core/utilities/structures/tenants.ts +0 -5
- package/tests/core/utilities/structures/userGroups.ts +0 -10
- package/tests/core/utilities/structures/users.ts +0 -89
- package/tests/core/utilities/testContainerUtils.ts +0 -165
- package/tests/core/utilities/utils/index.ts +0 -2
- package/tests/core/utilities/utils/queue.ts +0 -27
- package/tests/core/utilities/utils/time.ts +0 -3
- package/tests/extra/DBTestConfiguration.ts +0 -36
- package/tests/extra/index.ts +0 -2
- package/tests/extra/testEnv.ts +0 -95
- package/tests/index.ts +0 -2
- package/tests/jestEnv.ts +0 -10
- package/tests/jestSetup.ts +0 -36
package/src/platform/tenants.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { StaticDatabases } from "../constants"
|
|
2
|
-
import { getPlatformDB } from "./platformDb"
|
|
3
|
-
import { LockName, LockOptions, LockType, Tenants } from "@budibase/types"
|
|
4
|
-
import * as locks from "../redis/redlockImpl"
|
|
5
|
-
|
|
6
|
-
const TENANT_DOC = StaticDatabases.PLATFORM_INFO.docs.tenants
|
|
7
|
-
|
|
8
|
-
export const tenacyLockOptions: LockOptions = {
|
|
9
|
-
type: LockType.DEFAULT,
|
|
10
|
-
name: LockName.UPDATE_TENANTS_DOC,
|
|
11
|
-
ttl: 10 * 1000, // auto expire after 10 seconds
|
|
12
|
-
systemLock: true,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// READ
|
|
16
|
-
|
|
17
|
-
export async function getTenantIds(): Promise<string[]> {
|
|
18
|
-
const tenants = await getTenants()
|
|
19
|
-
return tenants.tenantIds
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async function getTenants(): Promise<Tenants> {
|
|
23
|
-
const db = getPlatformDB()
|
|
24
|
-
let tenants: Tenants
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
tenants = await db.get(TENANT_DOC)
|
|
28
|
-
} catch (e: any) {
|
|
29
|
-
// doesn't exist yet - create
|
|
30
|
-
if (e.status === 404) {
|
|
31
|
-
tenants = await createTenantsDoc()
|
|
32
|
-
} else {
|
|
33
|
-
throw e
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return tenants
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function exists(tenantId: string) {
|
|
41
|
-
const tenants = await getTenants()
|
|
42
|
-
return tenants.tenantIds.indexOf(tenantId) !== -1
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// CREATE / UPDATE
|
|
46
|
-
|
|
47
|
-
function newTenantsDoc(): Tenants {
|
|
48
|
-
return {
|
|
49
|
-
_id: TENANT_DOC,
|
|
50
|
-
tenantIds: [],
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function createTenantsDoc(): Promise<Tenants> {
|
|
55
|
-
const db = getPlatformDB()
|
|
56
|
-
let tenants = newTenantsDoc()
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const response = await db.put(tenants)
|
|
60
|
-
tenants._rev = response.rev
|
|
61
|
-
} catch (e: any) {
|
|
62
|
-
// don't throw 409 is doc has already been created
|
|
63
|
-
if (e.status === 409) {
|
|
64
|
-
return db.get(TENANT_DOC)
|
|
65
|
-
}
|
|
66
|
-
throw e
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return tenants
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function addTenant(tenantId: string) {
|
|
73
|
-
const db = getPlatformDB()
|
|
74
|
-
|
|
75
|
-
// use a lock as tenant creation is conflict prone
|
|
76
|
-
await locks.doWithLock(tenacyLockOptions, async () => {
|
|
77
|
-
const tenants = await getTenants()
|
|
78
|
-
|
|
79
|
-
// write the new tenant if it doesn't already exist
|
|
80
|
-
if (tenants.tenantIds.indexOf(tenantId) === -1) {
|
|
81
|
-
tenants.tenantIds.push(tenantId)
|
|
82
|
-
await db.put(tenants)
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// DELETE
|
|
88
|
-
|
|
89
|
-
export async function removeTenant(tenantId: string) {
|
|
90
|
-
try {
|
|
91
|
-
await locks.doWithLock(tenacyLockOptions, async () => {
|
|
92
|
-
const db = getPlatformDB()
|
|
93
|
-
const tenants = await getTenants()
|
|
94
|
-
tenants.tenantIds = tenants.tenantIds.filter(id => id !== tenantId)
|
|
95
|
-
await db.put(tenants)
|
|
96
|
-
})
|
|
97
|
-
} catch (err) {
|
|
98
|
-
console.error(`Error removing tenant ${tenantId} from info db`, err)
|
|
99
|
-
throw err
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { structures } from "../../../tests"
|
|
2
|
-
import { DBTestConfiguration } from "../../../tests/extra"
|
|
3
|
-
import * as tenants from "../tenants"
|
|
4
|
-
|
|
5
|
-
describe("tenants", () => {
|
|
6
|
-
new DBTestConfiguration()
|
|
7
|
-
|
|
8
|
-
describe("addTenant", () => {
|
|
9
|
-
it("concurrently adds multiple tenants safely", async () => {
|
|
10
|
-
const tenant1 = structures.tenant.id()
|
|
11
|
-
const tenant2 = structures.tenant.id()
|
|
12
|
-
const tenant3 = structures.tenant.id()
|
|
13
|
-
|
|
14
|
-
await Promise.all([
|
|
15
|
-
tenants.addTenant(tenant1),
|
|
16
|
-
tenants.addTenant(tenant2),
|
|
17
|
-
tenants.addTenant(tenant3),
|
|
18
|
-
])
|
|
19
|
-
|
|
20
|
-
const tenantIds = await tenants.getTenantIds()
|
|
21
|
-
expect(tenantIds.includes(tenant1)).toBe(true)
|
|
22
|
-
expect(tenantIds.includes(tenant2)).toBe(true)
|
|
23
|
-
expect(tenantIds.includes(tenant3)).toBe(true)
|
|
24
|
-
})
|
|
25
|
-
})
|
|
26
|
-
})
|
package/src/platform/users.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { getPlatformDB } from "./platformDb"
|
|
2
|
-
import { DEFAULT_TENANT_ID } from "../constants"
|
|
3
|
-
import env from "../environment"
|
|
4
|
-
import {
|
|
5
|
-
PlatformUser,
|
|
6
|
-
PlatformUserByEmail,
|
|
7
|
-
PlatformUserById,
|
|
8
|
-
PlatformUserBySsoId,
|
|
9
|
-
User,
|
|
10
|
-
} from "@budibase/types"
|
|
11
|
-
|
|
12
|
-
// READ
|
|
13
|
-
|
|
14
|
-
export async function lookupTenantId(userId: string) {
|
|
15
|
-
if (!env.MULTI_TENANCY) {
|
|
16
|
-
return DEFAULT_TENANT_ID
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const user = await getUserDoc(userId)
|
|
20
|
-
return user.tenantId
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function getUserDoc(emailOrId: string): Promise<PlatformUser> {
|
|
24
|
-
const db = getPlatformDB()
|
|
25
|
-
return db.get(emailOrId)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export async function updateUserDoc(platformUser: PlatformUserById) {
|
|
29
|
-
const db = getPlatformDB()
|
|
30
|
-
await db.put(platformUser)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// CREATE
|
|
34
|
-
|
|
35
|
-
function newUserIdDoc(id: string, tenantId: string): PlatformUserById {
|
|
36
|
-
return {
|
|
37
|
-
_id: id,
|
|
38
|
-
tenantId,
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function newUserEmailDoc(
|
|
43
|
-
userId: string,
|
|
44
|
-
email: string,
|
|
45
|
-
tenantId: string
|
|
46
|
-
): PlatformUserByEmail {
|
|
47
|
-
return {
|
|
48
|
-
_id: email,
|
|
49
|
-
userId,
|
|
50
|
-
tenantId,
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function newUserSsoIdDoc(
|
|
55
|
-
ssoId: string,
|
|
56
|
-
email: string,
|
|
57
|
-
userId: string,
|
|
58
|
-
tenantId: string
|
|
59
|
-
): PlatformUserBySsoId {
|
|
60
|
-
return {
|
|
61
|
-
_id: ssoId,
|
|
62
|
-
userId,
|
|
63
|
-
email,
|
|
64
|
-
tenantId,
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Add a new user id or email doc if it doesn't exist.
|
|
70
|
-
*/
|
|
71
|
-
async function addUserDoc(emailOrId: string, newDocFn: () => PlatformUser) {
|
|
72
|
-
const db = getPlatformDB()
|
|
73
|
-
let user: PlatformUser
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
await db.get(emailOrId)
|
|
77
|
-
} catch (e: any) {
|
|
78
|
-
if (e.status === 404) {
|
|
79
|
-
user = newDocFn()
|
|
80
|
-
await db.put(user)
|
|
81
|
-
} else {
|
|
82
|
-
throw e
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export async function addSsoUser(
|
|
88
|
-
ssoId: string,
|
|
89
|
-
email: string,
|
|
90
|
-
userId: string,
|
|
91
|
-
tenantId: string
|
|
92
|
-
) {
|
|
93
|
-
return addUserDoc(ssoId, () =>
|
|
94
|
-
newUserSsoIdDoc(ssoId, email, userId, tenantId)
|
|
95
|
-
)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function addUser(
|
|
99
|
-
tenantId: string,
|
|
100
|
-
userId: string,
|
|
101
|
-
email: string,
|
|
102
|
-
ssoId?: string
|
|
103
|
-
) {
|
|
104
|
-
const promises = [
|
|
105
|
-
addUserDoc(userId, () => newUserIdDoc(userId, tenantId)),
|
|
106
|
-
addUserDoc(email, () => newUserEmailDoc(userId, email, tenantId)),
|
|
107
|
-
]
|
|
108
|
-
|
|
109
|
-
if (ssoId) {
|
|
110
|
-
promises.push(addSsoUser(ssoId, email, userId, tenantId))
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
await Promise.all(promises)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// DELETE
|
|
117
|
-
|
|
118
|
-
export async function removeUser(user: User) {
|
|
119
|
-
const db = getPlatformDB()
|
|
120
|
-
const keys = [user._id!, user.email]
|
|
121
|
-
const userDocs = await db.allDocs<User>({
|
|
122
|
-
keys,
|
|
123
|
-
include_docs: true,
|
|
124
|
-
})
|
|
125
|
-
await db.bulkRemove(
|
|
126
|
-
userDocs.rows.map(row => row.doc!),
|
|
127
|
-
{ silenceErrors: true }
|
|
128
|
-
)
|
|
129
|
-
}
|
package/src/plugin/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./utils"
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
import { validate } from "../utils"
|
|
2
|
-
import fetch from "node-fetch"
|
|
3
|
-
import { PluginType } from "@budibase/types"
|
|
4
|
-
import nock from "nock"
|
|
5
|
-
|
|
6
|
-
const automationLink = `http://example.com/automation/schema.json`
|
|
7
|
-
const componentLink = `http://example.com/component/schema.json`
|
|
8
|
-
const datasourceLink = `http://example.com/datasource/schema.json`
|
|
9
|
-
|
|
10
|
-
function mockDatasourceSchema() {
|
|
11
|
-
nock("http://example.com")
|
|
12
|
-
.get("/datasource/schema.json")
|
|
13
|
-
.reply(200, {
|
|
14
|
-
type: "datasource",
|
|
15
|
-
metadata: {},
|
|
16
|
-
schema: {
|
|
17
|
-
docs: "https://docs.budibase.com",
|
|
18
|
-
friendlyName: "Basic HTTP",
|
|
19
|
-
type: "API",
|
|
20
|
-
description: "Performs a basic HTTP calls to a URL",
|
|
21
|
-
datasource: {
|
|
22
|
-
url: {
|
|
23
|
-
type: "string",
|
|
24
|
-
required: true,
|
|
25
|
-
},
|
|
26
|
-
cookie: {
|
|
27
|
-
type: "string",
|
|
28
|
-
required: false,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
query: {
|
|
32
|
-
create: {
|
|
33
|
-
type: "json",
|
|
34
|
-
},
|
|
35
|
-
read: {
|
|
36
|
-
type: "fields",
|
|
37
|
-
fields: {
|
|
38
|
-
queryString: {
|
|
39
|
-
display: "Query string",
|
|
40
|
-
type: "string",
|
|
41
|
-
required: false,
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
update: {
|
|
46
|
-
type: "json",
|
|
47
|
-
},
|
|
48
|
-
delete: {
|
|
49
|
-
type: "fields",
|
|
50
|
-
fields: {
|
|
51
|
-
id: {
|
|
52
|
-
type: "string",
|
|
53
|
-
required: true,
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function mockAutomationSchema() {
|
|
63
|
-
nock("http://example.com")
|
|
64
|
-
.get("/automation/schema.json")
|
|
65
|
-
.reply(200, {
|
|
66
|
-
type: "automation",
|
|
67
|
-
metadata: {},
|
|
68
|
-
schema: {
|
|
69
|
-
name: "{{ name }}",
|
|
70
|
-
tagline: "{{ description }}",
|
|
71
|
-
icon: "Actions",
|
|
72
|
-
description: "{{ description }}",
|
|
73
|
-
type: "action",
|
|
74
|
-
stepId: "{{ name }}",
|
|
75
|
-
inputs: {
|
|
76
|
-
text: "",
|
|
77
|
-
},
|
|
78
|
-
schema: {
|
|
79
|
-
inputs: {
|
|
80
|
-
properties: {
|
|
81
|
-
text: {
|
|
82
|
-
type: "string",
|
|
83
|
-
title: "Log",
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
required: ["text"],
|
|
87
|
-
},
|
|
88
|
-
outputs: {
|
|
89
|
-
properties: {
|
|
90
|
-
success: {
|
|
91
|
-
type: "boolean",
|
|
92
|
-
description: "Whether the action was successful",
|
|
93
|
-
},
|
|
94
|
-
message: {
|
|
95
|
-
type: "string",
|
|
96
|
-
description: "What was output",
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
required: ["success", "message"],
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function mockComponentSchema() {
|
|
107
|
-
nock("http://example.com")
|
|
108
|
-
.get("/component/schema.json")
|
|
109
|
-
.reply(200, {
|
|
110
|
-
type: "component",
|
|
111
|
-
metadata: {},
|
|
112
|
-
schema: {
|
|
113
|
-
name: "{{ name }}",
|
|
114
|
-
friendlyName: "{{ name }}",
|
|
115
|
-
description: "{{ description }}",
|
|
116
|
-
icon: "Text",
|
|
117
|
-
settings: [
|
|
118
|
-
{
|
|
119
|
-
type: "text",
|
|
120
|
-
key: "text",
|
|
121
|
-
label: "Text",
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async function getSchema(link: string) {
|
|
129
|
-
const response = await fetch(link)
|
|
130
|
-
if (response.status > 300) {
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
const text = await response.text()
|
|
134
|
-
return JSON.parse(text)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function runTest(opts: { link?: string; schema?: any }) {
|
|
138
|
-
let error
|
|
139
|
-
try {
|
|
140
|
-
let schema = opts.schema
|
|
141
|
-
if (opts.link) {
|
|
142
|
-
schema = await getSchema(opts.link)
|
|
143
|
-
}
|
|
144
|
-
validate(schema)
|
|
145
|
-
} catch (err) {
|
|
146
|
-
error = err
|
|
147
|
-
}
|
|
148
|
-
return error
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
describe("plugin validation", () => {
|
|
152
|
-
beforeEach(() => {
|
|
153
|
-
nock.cleanAll()
|
|
154
|
-
mockAutomationSchema()
|
|
155
|
-
mockComponentSchema()
|
|
156
|
-
mockDatasourceSchema()
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
describe("it should be able to validate an automation schema", () => {
|
|
160
|
-
it("should return automation skeleton schema is valid", async () => {
|
|
161
|
-
const error = await runTest({ link: automationLink })
|
|
162
|
-
expect(error).toBeUndefined()
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it("should fail given invalid automation schema", async () => {
|
|
166
|
-
const error = await runTest({
|
|
167
|
-
schema: {
|
|
168
|
-
type: PluginType.AUTOMATION,
|
|
169
|
-
schema: {},
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
expect(error).toBeDefined()
|
|
173
|
-
})
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
describe("it should be able to validate a component schema", () => {
|
|
177
|
-
it("should return component skeleton schema is valid", async () => {
|
|
178
|
-
const error = await runTest({ link: componentLink })
|
|
179
|
-
expect(error).toBeUndefined()
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it("should fail given invalid component schema", async () => {
|
|
183
|
-
const error = await runTest({
|
|
184
|
-
schema: {
|
|
185
|
-
type: PluginType.COMPONENT,
|
|
186
|
-
schema: {},
|
|
187
|
-
},
|
|
188
|
-
})
|
|
189
|
-
expect(error).toBeDefined()
|
|
190
|
-
})
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
describe("it should be able to validate a datasource schema", () => {
|
|
194
|
-
it("should return datasource skeleton schema is valid", async () => {
|
|
195
|
-
const error = await runTest({ link: datasourceLink })
|
|
196
|
-
expect(error).toBeUndefined()
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
it("should fail given invalid datasource schema", async () => {
|
|
200
|
-
const error = await runTest({
|
|
201
|
-
schema: {
|
|
202
|
-
type: PluginType.DATASOURCE,
|
|
203
|
-
schema: {},
|
|
204
|
-
},
|
|
205
|
-
})
|
|
206
|
-
expect(error).toBeDefined()
|
|
207
|
-
})
|
|
208
|
-
})
|
|
209
|
-
})
|
package/src/plugin/utils.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DatasourceFieldType,
|
|
3
|
-
QueryType,
|
|
4
|
-
PluginType,
|
|
5
|
-
AutomationStepType,
|
|
6
|
-
AutomationStepIdArray,
|
|
7
|
-
AutomationIOType,
|
|
8
|
-
AutomationCustomIOType,
|
|
9
|
-
DatasourceFeature,
|
|
10
|
-
} from "@budibase/types"
|
|
11
|
-
import joi from "joi"
|
|
12
|
-
|
|
13
|
-
const DATASOURCE_TYPES = [
|
|
14
|
-
"Relational",
|
|
15
|
-
"Non-relational",
|
|
16
|
-
"Spreadsheet",
|
|
17
|
-
"Object store",
|
|
18
|
-
"Graph",
|
|
19
|
-
"API",
|
|
20
|
-
]
|
|
21
|
-
|
|
22
|
-
function runJoi(validator: joi.Schema, schema: any) {
|
|
23
|
-
const { error } = validator.validate(schema)
|
|
24
|
-
if (error) {
|
|
25
|
-
throw error
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function validateComponent(schema: any) {
|
|
30
|
-
const validator = joi.object({
|
|
31
|
-
type: joi.string().allow(PluginType.COMPONENT).required(),
|
|
32
|
-
metadata: joi.object().unknown(true).required(),
|
|
33
|
-
hash: joi.string().optional(),
|
|
34
|
-
version: joi.string().optional(),
|
|
35
|
-
schema: joi
|
|
36
|
-
.object({
|
|
37
|
-
name: joi.string().required(),
|
|
38
|
-
settings: joi.array().items(joi.object().unknown(true)).required(),
|
|
39
|
-
})
|
|
40
|
-
.unknown(true),
|
|
41
|
-
})
|
|
42
|
-
runJoi(validator, schema)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function validateDatasource(schema: any) {
|
|
46
|
-
const fieldValidator = joi.object({
|
|
47
|
-
type: joi
|
|
48
|
-
.string()
|
|
49
|
-
.allow(...Object.values(DatasourceFieldType))
|
|
50
|
-
.required(),
|
|
51
|
-
required: joi.boolean().required(),
|
|
52
|
-
default: joi.any(),
|
|
53
|
-
display: joi.string(),
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const queryValidator = joi
|
|
57
|
-
.object({
|
|
58
|
-
type: joi.string().allow(...Object.values(QueryType)),
|
|
59
|
-
readable: joi.boolean(),
|
|
60
|
-
fields: joi.object().pattern(joi.string(), fieldValidator),
|
|
61
|
-
})
|
|
62
|
-
.required()
|
|
63
|
-
|
|
64
|
-
const validator = joi.object({
|
|
65
|
-
type: joi.string().allow(PluginType.DATASOURCE).required(),
|
|
66
|
-
metadata: joi.object().unknown(true).required(),
|
|
67
|
-
hash: joi.string().optional(),
|
|
68
|
-
version: joi.string().optional(),
|
|
69
|
-
schema: joi.object({
|
|
70
|
-
docs: joi.string(),
|
|
71
|
-
plus: joi.boolean().optional(),
|
|
72
|
-
isSQL: joi.boolean().optional(),
|
|
73
|
-
auth: joi
|
|
74
|
-
.object({
|
|
75
|
-
type: joi.string().required(),
|
|
76
|
-
})
|
|
77
|
-
.optional(),
|
|
78
|
-
features: joi
|
|
79
|
-
.object(
|
|
80
|
-
Object.fromEntries(
|
|
81
|
-
Object.values(DatasourceFeature).map(key => [
|
|
82
|
-
key,
|
|
83
|
-
joi.boolean().optional(),
|
|
84
|
-
])
|
|
85
|
-
)
|
|
86
|
-
)
|
|
87
|
-
.optional(),
|
|
88
|
-
relationships: joi.boolean().optional(),
|
|
89
|
-
description: joi.string().required(),
|
|
90
|
-
friendlyName: joi.string().required(),
|
|
91
|
-
type: joi.string().allow(...DATASOURCE_TYPES),
|
|
92
|
-
datasource: joi.object().pattern(joi.string(), fieldValidator).required(),
|
|
93
|
-
query: joi
|
|
94
|
-
.object()
|
|
95
|
-
.pattern(joi.string(), queryValidator)
|
|
96
|
-
.unknown(true)
|
|
97
|
-
.required(),
|
|
98
|
-
extra: joi.object().pattern(
|
|
99
|
-
joi.string(),
|
|
100
|
-
joi.object({
|
|
101
|
-
type: joi.string().required(),
|
|
102
|
-
displayName: joi.string().required(),
|
|
103
|
-
required: joi.boolean(),
|
|
104
|
-
data: joi.object(),
|
|
105
|
-
})
|
|
106
|
-
),
|
|
107
|
-
}),
|
|
108
|
-
})
|
|
109
|
-
runJoi(validator, schema)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function validateAutomation(schema: any) {
|
|
113
|
-
const basePropsValidator = joi.object().pattern(joi.string(), {
|
|
114
|
-
type: joi
|
|
115
|
-
.string()
|
|
116
|
-
.allow(...Object.values(AutomationIOType))
|
|
117
|
-
.required(),
|
|
118
|
-
customType: joi.string().allow(...Object.values(AutomationCustomIOType)),
|
|
119
|
-
title: joi.string(),
|
|
120
|
-
description: joi.string(),
|
|
121
|
-
enum: joi.array().items(joi.string()),
|
|
122
|
-
pretty: joi.array().items(joi.string()),
|
|
123
|
-
})
|
|
124
|
-
const stepSchemaValidator = joi
|
|
125
|
-
.object({
|
|
126
|
-
properties: basePropsValidator,
|
|
127
|
-
required: joi.array().items(joi.string()),
|
|
128
|
-
})
|
|
129
|
-
.concat(basePropsValidator)
|
|
130
|
-
.required()
|
|
131
|
-
const validator = joi.object({
|
|
132
|
-
type: joi.string().allow(PluginType.AUTOMATION).required(),
|
|
133
|
-
metadata: joi.object().unknown(true).required(),
|
|
134
|
-
hash: joi.string().optional(),
|
|
135
|
-
version: joi.string().optional(),
|
|
136
|
-
schema: joi.object({
|
|
137
|
-
name: joi.string().required(),
|
|
138
|
-
tagline: joi.string().required(),
|
|
139
|
-
icon: joi.string().required(),
|
|
140
|
-
description: joi.string().required(),
|
|
141
|
-
type: joi
|
|
142
|
-
.string()
|
|
143
|
-
.allow(AutomationStepType.ACTION, AutomationStepType.LOGIC)
|
|
144
|
-
.required(),
|
|
145
|
-
stepId: joi
|
|
146
|
-
.string()
|
|
147
|
-
.disallow(...AutomationStepIdArray)
|
|
148
|
-
.required(),
|
|
149
|
-
inputs: joi.object().optional(),
|
|
150
|
-
schema: joi
|
|
151
|
-
.object({
|
|
152
|
-
inputs: stepSchemaValidator,
|
|
153
|
-
outputs: stepSchemaValidator,
|
|
154
|
-
})
|
|
155
|
-
.required(),
|
|
156
|
-
}),
|
|
157
|
-
})
|
|
158
|
-
runJoi(validator, schema)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export function validate(schema: any) {
|
|
162
|
-
switch (schema?.type) {
|
|
163
|
-
case PluginType.COMPONENT:
|
|
164
|
-
validateComponent(schema)
|
|
165
|
-
break
|
|
166
|
-
case PluginType.DATASOURCE:
|
|
167
|
-
validateDatasource(schema)
|
|
168
|
-
break
|
|
169
|
-
case PluginType.AUTOMATION:
|
|
170
|
-
validateAutomation(schema)
|
|
171
|
-
break
|
|
172
|
-
default:
|
|
173
|
-
throw new Error(`Unknown plugin type - check schema.json: ${schema.type}`)
|
|
174
|
-
}
|
|
175
|
-
}
|
package/src/queue/constants.ts
DELETED