@budibase/backend-core 3.2.5 → 3.2.7
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 +7 -1
- package/dist/index.js.map +2 -2
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +11 -4
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/environment.d.ts +1 -0
- package/dist/src/environment.js +6 -1
- package/dist/src/environment.js.map +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/configs/configs.ts
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AIConfig,
|
|
3
|
-
Config,
|
|
4
|
-
ConfigType,
|
|
5
|
-
GoogleConfig,
|
|
6
|
-
GoogleInnerConfig,
|
|
7
|
-
OIDCConfig,
|
|
8
|
-
OIDCInnerConfig,
|
|
9
|
-
OIDCLogosConfig,
|
|
10
|
-
SCIMConfig,
|
|
11
|
-
SCIMInnerConfig,
|
|
12
|
-
SettingsConfig,
|
|
13
|
-
SettingsInnerConfig,
|
|
14
|
-
SMTPConfig,
|
|
15
|
-
SMTPInnerConfig,
|
|
16
|
-
} from "@budibase/types"
|
|
17
|
-
import { DocumentType, SEPARATOR } from "../constants"
|
|
18
|
-
import { CacheKey, TTL, withCache } from "../cache"
|
|
19
|
-
import * as context from "../context"
|
|
20
|
-
import env from "../environment"
|
|
21
|
-
|
|
22
|
-
// UTILS
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Generates a new configuration ID.
|
|
26
|
-
* @returns The new configuration ID which the config doc can be stored under.
|
|
27
|
-
*/
|
|
28
|
-
export function generateConfigID(type: ConfigType) {
|
|
29
|
-
return `${DocumentType.CONFIG}${SEPARATOR}${type}`
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function getConfig<T extends Config>(
|
|
33
|
-
type: ConfigType
|
|
34
|
-
): Promise<T | undefined> {
|
|
35
|
-
const db = context.getGlobalDB()
|
|
36
|
-
try {
|
|
37
|
-
// await to catch error
|
|
38
|
-
return (await db.get(generateConfigID(type))) as T
|
|
39
|
-
} catch (e: any) {
|
|
40
|
-
if (e.status === 404) {
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
throw e
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export async function save(
|
|
48
|
-
config: Config
|
|
49
|
-
): Promise<{ id: string; rev: string }> {
|
|
50
|
-
const db = context.getGlobalDB()
|
|
51
|
-
return db.put(config)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// SETTINGS
|
|
55
|
-
|
|
56
|
-
export async function getSettingsConfigDoc(): Promise<SettingsConfig> {
|
|
57
|
-
let config = await getConfig<SettingsConfig>(ConfigType.SETTINGS)
|
|
58
|
-
|
|
59
|
-
if (!config) {
|
|
60
|
-
config = {
|
|
61
|
-
_id: generateConfigID(ConfigType.SETTINGS),
|
|
62
|
-
type: ConfigType.SETTINGS,
|
|
63
|
-
config: {},
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// overridden fields
|
|
68
|
-
config.config.platformUrl = await getPlatformUrl({
|
|
69
|
-
tenantAware: true,
|
|
70
|
-
config: config.config,
|
|
71
|
-
})
|
|
72
|
-
config.config.analyticsEnabled = await analyticsEnabled({
|
|
73
|
-
config: config.config,
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
return config
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export async function getSettingsConfig(): Promise<SettingsInnerConfig> {
|
|
80
|
-
return (await getSettingsConfigDoc()).config
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export async function getPlatformUrl(
|
|
84
|
-
opts: { tenantAware: boolean; config?: SettingsInnerConfig } = {
|
|
85
|
-
tenantAware: true,
|
|
86
|
-
}
|
|
87
|
-
) {
|
|
88
|
-
let platformUrl = env.PLATFORM_URL || "http://localhost:10000"
|
|
89
|
-
|
|
90
|
-
if (!env.SELF_HOSTED && env.MULTI_TENANCY && opts.tenantAware) {
|
|
91
|
-
// cloud and multi tenant - add the tenant to the default platform url
|
|
92
|
-
const tenantId = context.getTenantId()
|
|
93
|
-
if (!platformUrl.includes("localhost:")) {
|
|
94
|
-
platformUrl = platformUrl.replace("://", `://${tenantId}.`)
|
|
95
|
-
}
|
|
96
|
-
} else if (env.SELF_HOSTED) {
|
|
97
|
-
const config = opts?.config
|
|
98
|
-
? opts.config
|
|
99
|
-
: // direct to db to prevent infinite loop
|
|
100
|
-
(await getConfig<SettingsConfig>(ConfigType.SETTINGS))?.config
|
|
101
|
-
if (config?.platformUrl) {
|
|
102
|
-
platformUrl = config.platformUrl
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return platformUrl
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const analyticsEnabled = async (opts?: {
|
|
110
|
-
config?: SettingsInnerConfig
|
|
111
|
-
}) => {
|
|
112
|
-
// cloud - always use the environment variable
|
|
113
|
-
if (!env.SELF_HOSTED) {
|
|
114
|
-
return !!env.ENABLE_ANALYTICS
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// self host - prefer the settings doc
|
|
118
|
-
// use cache as events have high throughput
|
|
119
|
-
const enabledInDB = await withCache(
|
|
120
|
-
CacheKey.ANALYTICS_ENABLED,
|
|
121
|
-
TTL.ONE_DAY,
|
|
122
|
-
async () => {
|
|
123
|
-
const config = opts?.config
|
|
124
|
-
? opts.config
|
|
125
|
-
: // direct to db to prevent infinite loop
|
|
126
|
-
(await getConfig<SettingsConfig>(ConfigType.SETTINGS))?.config
|
|
127
|
-
|
|
128
|
-
// need to do explicit checks in case the field is not set
|
|
129
|
-
if (config?.analyticsEnabled === false) {
|
|
130
|
-
return false
|
|
131
|
-
} else if (config?.analyticsEnabled === true) {
|
|
132
|
-
return true
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
if (enabledInDB !== undefined) {
|
|
138
|
-
return enabledInDB
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// fallback to the environment variable
|
|
142
|
-
// explicitly check for 0 or false here, undefined or otherwise is treated as true
|
|
143
|
-
const envEnabled: any = env.ENABLE_ANALYTICS
|
|
144
|
-
if (envEnabled === 0 || envEnabled === false) {
|
|
145
|
-
return false
|
|
146
|
-
} else {
|
|
147
|
-
return true
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// GOOGLE
|
|
152
|
-
|
|
153
|
-
async function getGoogleConfigDoc(): Promise<GoogleConfig | undefined> {
|
|
154
|
-
return await getConfig<GoogleConfig>(ConfigType.GOOGLE)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export async function getGoogleConfig(): Promise<
|
|
158
|
-
GoogleInnerConfig | undefined
|
|
159
|
-
> {
|
|
160
|
-
const config = await getGoogleConfigDoc()
|
|
161
|
-
return config?.config
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export async function getGoogleDatasourceConfig(): Promise<
|
|
165
|
-
GoogleInnerConfig | undefined
|
|
166
|
-
> {
|
|
167
|
-
if (!env.SELF_HOSTED) {
|
|
168
|
-
// always use the env vars in cloud
|
|
169
|
-
return getDefaultGoogleConfig()
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// prefer the config in self-host
|
|
173
|
-
let config = await getGoogleConfig()
|
|
174
|
-
|
|
175
|
-
// fallback to env vars
|
|
176
|
-
if (!config || !config.activated) {
|
|
177
|
-
config = getDefaultGoogleConfig()
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return config
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function getDefaultGoogleConfig(): GoogleInnerConfig | undefined {
|
|
184
|
-
if (env.GOOGLE_CLIENT_ID && env.GOOGLE_CLIENT_SECRET) {
|
|
185
|
-
return {
|
|
186
|
-
clientID: env.GOOGLE_CLIENT_ID!,
|
|
187
|
-
clientSecret: env.GOOGLE_CLIENT_SECRET!,
|
|
188
|
-
activated: true,
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// OIDC
|
|
194
|
-
|
|
195
|
-
export async function getOIDCLogosDoc(): Promise<OIDCLogosConfig | undefined> {
|
|
196
|
-
return getConfig<OIDCLogosConfig>(ConfigType.OIDC_LOGOS)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
async function getOIDCConfigDoc(): Promise<OIDCConfig | undefined> {
|
|
200
|
-
return getConfig<OIDCConfig>(ConfigType.OIDC)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export async function getOIDCConfig(): Promise<OIDCInnerConfig | undefined> {
|
|
204
|
-
const config = (await getOIDCConfigDoc())?.config
|
|
205
|
-
// default to the 0th config
|
|
206
|
-
return config?.configs && config.configs[0]
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @param configId The config id of the inner config to retrieve
|
|
211
|
-
*/
|
|
212
|
-
export async function getOIDCConfigById(
|
|
213
|
-
configId: string
|
|
214
|
-
): Promise<OIDCInnerConfig | undefined> {
|
|
215
|
-
const config = (await getConfig<OIDCConfig>(ConfigType.OIDC))?.config
|
|
216
|
-
return config && config.configs.filter((c: any) => c.uuid === configId)[0]
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// SMTP
|
|
220
|
-
|
|
221
|
-
export async function getSMTPConfigDoc(): Promise<SMTPConfig | undefined> {
|
|
222
|
-
return getConfig<SMTPConfig>(ConfigType.SMTP)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export async function getSMTPConfig(
|
|
226
|
-
isAutomation?: boolean
|
|
227
|
-
): Promise<SMTPInnerConfig | undefined> {
|
|
228
|
-
const config = await getSMTPConfigDoc()
|
|
229
|
-
if (config) {
|
|
230
|
-
return config.config
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// always allow fallback in self host
|
|
234
|
-
// in cloud don't allow for automations
|
|
235
|
-
const allowFallback = env.SELF_HOSTED || !isAutomation
|
|
236
|
-
|
|
237
|
-
// Use an SMTP fallback configuration from env variables
|
|
238
|
-
if (env.SMTP_FALLBACK_ENABLED && allowFallback) {
|
|
239
|
-
return {
|
|
240
|
-
port: env.SMTP_PORT,
|
|
241
|
-
host: env.SMTP_HOST!,
|
|
242
|
-
secure: false,
|
|
243
|
-
from: env.SMTP_FROM_ADDRESS!,
|
|
244
|
-
auth: {
|
|
245
|
-
user: env.SMTP_USER!,
|
|
246
|
-
pass: env.SMTP_PASSWORD!,
|
|
247
|
-
},
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// SCIM
|
|
253
|
-
|
|
254
|
-
export async function getSCIMConfig(): Promise<SCIMInnerConfig | undefined> {
|
|
255
|
-
const config = await getConfig<SCIMConfig>(ConfigType.SCIM)
|
|
256
|
-
return config?.config
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// AI
|
|
260
|
-
|
|
261
|
-
export async function getAIConfig(): Promise<AIConfig | undefined> {
|
|
262
|
-
return getConfig<AIConfig>(ConfigType.AI)
|
|
263
|
-
}
|
package/src/configs/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./configs"
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { generator, structures } from "../../../tests"
|
|
2
|
-
import { DBTestConfiguration, testEnv } from "../../../tests/extra"
|
|
3
|
-
import { ConfigType } from "@budibase/types"
|
|
4
|
-
import env from "../../environment"
|
|
5
|
-
import * as configs from "../configs"
|
|
6
|
-
|
|
7
|
-
const DEFAULT_URL = "http://localhost:10000"
|
|
8
|
-
const ENV_URL = "http://env.com"
|
|
9
|
-
|
|
10
|
-
describe("configs", () => {
|
|
11
|
-
const config = new DBTestConfiguration()
|
|
12
|
-
|
|
13
|
-
const setDbPlatformUrl = async (dbUrl: string) => {
|
|
14
|
-
const settingsConfig = {
|
|
15
|
-
_id: configs.generateConfigID(ConfigType.SETTINGS),
|
|
16
|
-
type: ConfigType.SETTINGS,
|
|
17
|
-
config: {
|
|
18
|
-
platformUrl: dbUrl,
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
await configs.save(settingsConfig)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
config.newTenant()
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
describe("getPlatformUrl", () => {
|
|
29
|
-
describe("self host", () => {
|
|
30
|
-
beforeEach(async () => {
|
|
31
|
-
testEnv.selfHosted()
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
it("gets the default url", async () => {
|
|
35
|
-
await config.doInTenant(async () => {
|
|
36
|
-
const url = await configs.getPlatformUrl()
|
|
37
|
-
expect(url).toBe(DEFAULT_URL)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it("gets the platform url from the environment", async () => {
|
|
42
|
-
await config.doInTenant(async () => {
|
|
43
|
-
env._set("PLATFORM_URL", ENV_URL)
|
|
44
|
-
const url = await configs.getPlatformUrl()
|
|
45
|
-
expect(url).toBe(ENV_URL)
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it("gets the platform url from the database", async () => {
|
|
50
|
-
await config.doInTenant(async () => {
|
|
51
|
-
const dbUrl = generator.url()
|
|
52
|
-
await setDbPlatformUrl(dbUrl)
|
|
53
|
-
const url = await configs.getPlatformUrl()
|
|
54
|
-
expect(url).toBe(dbUrl)
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
describe("cloud", () => {
|
|
60
|
-
function getTenantAwareUrl() {
|
|
61
|
-
return `http://${config.tenantId}.env.com`
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
beforeEach(async () => {
|
|
65
|
-
testEnv.cloudHosted()
|
|
66
|
-
testEnv.multiTenant()
|
|
67
|
-
|
|
68
|
-
env._set("PLATFORM_URL", ENV_URL)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it("gets the platform url from the environment without tenancy", async () => {
|
|
72
|
-
await config.doInTenant(async () => {
|
|
73
|
-
const url = await configs.getPlatformUrl({ tenantAware: false })
|
|
74
|
-
expect(url).toBe(ENV_URL)
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it("gets the platform url from the environment with tenancy", async () => {
|
|
79
|
-
await config.doInTenant(async () => {
|
|
80
|
-
const url = await configs.getPlatformUrl()
|
|
81
|
-
expect(url).toBe(getTenantAwareUrl())
|
|
82
|
-
})
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it("never gets the platform url from the database", async () => {
|
|
86
|
-
await config.doInTenant(async () => {
|
|
87
|
-
await setDbPlatformUrl(generator.url())
|
|
88
|
-
const url = await configs.getPlatformUrl()
|
|
89
|
-
expect(url).toBe(getTenantAwareUrl())
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
describe("getSettingsConfig", () => {
|
|
96
|
-
beforeAll(async () => {
|
|
97
|
-
testEnv.selfHosted()
|
|
98
|
-
env._set("PLATFORM_URL", "")
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
it("returns the platform url with an existing config", async () => {
|
|
102
|
-
await config.doInTenant(async () => {
|
|
103
|
-
const dbUrl = generator.url()
|
|
104
|
-
await setDbPlatformUrl(dbUrl)
|
|
105
|
-
const config = await configs.getSettingsConfig()
|
|
106
|
-
expect(config.platformUrl).toBe(dbUrl)
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
it("returns the platform url without an existing config", async () => {
|
|
111
|
-
await config.doInTenant(async () => {
|
|
112
|
-
const config = await configs.getSettingsConfig()
|
|
113
|
-
expect(config.platformUrl).toBe(DEFAULT_URL)
|
|
114
|
-
})
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
describe("getGoogleDatasourceConfig", () => {
|
|
119
|
-
function setEnvVars() {
|
|
120
|
-
env.GOOGLE_CLIENT_SECRET = "test"
|
|
121
|
-
env.GOOGLE_CLIENT_ID = "test"
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function unsetEnvVars() {
|
|
125
|
-
env.GOOGLE_CLIENT_SECRET = undefined
|
|
126
|
-
env.GOOGLE_CLIENT_ID = undefined
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
describe("cloud", () => {
|
|
130
|
-
beforeEach(() => {
|
|
131
|
-
testEnv.cloudHosted()
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
it("returns from env vars", async () => {
|
|
135
|
-
await config.doInTenant(async () => {
|
|
136
|
-
setEnvVars()
|
|
137
|
-
const config = await configs.getGoogleDatasourceConfig()
|
|
138
|
-
unsetEnvVars()
|
|
139
|
-
|
|
140
|
-
expect(config).toEqual({
|
|
141
|
-
activated: true,
|
|
142
|
-
clientID: "test",
|
|
143
|
-
clientSecret: "test",
|
|
144
|
-
})
|
|
145
|
-
})
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
it("returns undefined when no env vars are configured", async () => {
|
|
149
|
-
await config.doInTenant(async () => {
|
|
150
|
-
const config = await configs.getGoogleDatasourceConfig()
|
|
151
|
-
expect(config).toBeUndefined()
|
|
152
|
-
})
|
|
153
|
-
})
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
describe("self host", () => {
|
|
157
|
-
beforeEach(() => {
|
|
158
|
-
testEnv.selfHosted()
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
it("returns from config", async () => {
|
|
162
|
-
await config.doInTenant(async () => {
|
|
163
|
-
const googleDoc = structures.sso.googleConfigDoc()
|
|
164
|
-
await configs.save(googleDoc)
|
|
165
|
-
const config = await configs.getGoogleDatasourceConfig()
|
|
166
|
-
expect(config).toEqual(googleDoc.config)
|
|
167
|
-
})
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
it("falls back to env vars when config is disabled", async () => {
|
|
171
|
-
await config.doInTenant(async () => {
|
|
172
|
-
setEnvVars()
|
|
173
|
-
const config = await configs.getGoogleDatasourceConfig()
|
|
174
|
-
unsetEnvVars()
|
|
175
|
-
expect(config).toEqual({
|
|
176
|
-
activated: true,
|
|
177
|
-
clientID: "test",
|
|
178
|
-
clientSecret: "test",
|
|
179
|
-
})
|
|
180
|
-
})
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
})
|
|
184
|
-
})
|
package/src/constants/db.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { prefixed, DocumentType } from "@budibase/types"
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
SEPARATOR,
|
|
5
|
-
UNICODE_MAX,
|
|
6
|
-
DocumentType,
|
|
7
|
-
InternalTable,
|
|
8
|
-
} from "@budibase/types"
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Can be used to create a few different forms of querying a view.
|
|
12
|
-
*/
|
|
13
|
-
export enum AutomationViewMode {
|
|
14
|
-
ALL = "all",
|
|
15
|
-
AUTOMATION = "automation",
|
|
16
|
-
STATUS = "status",
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export enum ViewName {
|
|
20
|
-
USER_BY_APP = "by_app",
|
|
21
|
-
USER_BY_EMAIL = "by_email2",
|
|
22
|
-
BY_API_KEY = "by_api_key",
|
|
23
|
-
LINK = "by_link",
|
|
24
|
-
ROUTING = "screen_routes",
|
|
25
|
-
AUTOMATION_LOGS = "automation_logs",
|
|
26
|
-
ACCOUNT_BY_EMAIL = "account_by_email",
|
|
27
|
-
PLATFORM_USERS_LOWERCASE = "platform_users_lowercase_2",
|
|
28
|
-
USER_BY_GROUP = "user_by_group",
|
|
29
|
-
APP_BACKUP_BY_TRIGGER = "by_trigger",
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const DeprecatedViews: Record<string, string[]> = {
|
|
33
|
-
[ViewName.USER_BY_EMAIL]: [
|
|
34
|
-
// removed due to inaccuracy in view doc filter logic
|
|
35
|
-
"by_email",
|
|
36
|
-
],
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const StaticDatabases = {
|
|
40
|
-
GLOBAL: {
|
|
41
|
-
name: "global-db",
|
|
42
|
-
docs: {
|
|
43
|
-
apiKeys: "apikeys",
|
|
44
|
-
usageQuota: "usage_quota",
|
|
45
|
-
licenseInfo: "license_info",
|
|
46
|
-
environmentVariables: "environmentvariables",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
// contains information about tenancy and so on
|
|
50
|
-
PLATFORM_INFO: {
|
|
51
|
-
name: "global-info",
|
|
52
|
-
docs: {
|
|
53
|
-
tenants: "tenants",
|
|
54
|
-
install: "install",
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
AUDIT_LOGS: {
|
|
58
|
-
name: "audit-logs",
|
|
59
|
-
},
|
|
60
|
-
SCIM_LOGS: {
|
|
61
|
-
name: "scim-logs",
|
|
62
|
-
},
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const APP_PREFIX = prefixed(DocumentType.APP)
|
|
66
|
-
export const APP_DEV = prefixed(DocumentType.APP_DEV)
|
|
67
|
-
export const APP_DEV_PREFIX = APP_DEV
|
|
68
|
-
export const SQS_DATASOURCE_INTERNAL = "internal"
|
|
69
|
-
export const BUDIBASE_DATASOURCE_TYPE = "budibase"
|
|
70
|
-
export const SQLITE_DESIGN_DOC_ID = "_design/sqlite"
|
|
71
|
-
export const DEFAULT_JOBS_TABLE_ID = "ta_bb_jobs"
|
|
72
|
-
export const DEFAULT_INVENTORY_TABLE_ID = "ta_bb_inventory"
|
|
73
|
-
export const DEFAULT_EXPENSES_TABLE_ID = "ta_bb_expenses"
|
|
74
|
-
export const DEFAULT_EMPLOYEE_TABLE_ID = "ta_bb_employee"
|
|
75
|
-
export { DEFAULT_BB_DATASOURCE_ID } from "@budibase/shared-core"
|
package/src/constants/index.ts
DELETED
package/src/constants/misc.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export enum UserStatus {
|
|
2
|
-
ACTIVE = "active",
|
|
3
|
-
INACTIVE = "inactive",
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export enum Cookie {
|
|
7
|
-
Auth = "budibase:auth",
|
|
8
|
-
Init = "budibase:init",
|
|
9
|
-
ACCOUNT_RETURN_URL = "budibase:account:returnurl",
|
|
10
|
-
DatasourceAuth = "budibase:datasourceauth",
|
|
11
|
-
OIDC_CONFIG = "budibase:oidc:config",
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { Header } from "@budibase/shared-core"
|
|
15
|
-
|
|
16
|
-
export enum GlobalRole {
|
|
17
|
-
OWNER = "owner",
|
|
18
|
-
ADMIN = "admin",
|
|
19
|
-
BUILDER = "builder",
|
|
20
|
-
WORKSPACE_MANAGER = "workspace_manager",
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export enum Config {
|
|
24
|
-
SETTINGS = "settings",
|
|
25
|
-
ACCOUNT = "account",
|
|
26
|
-
SMTP = "smtp",
|
|
27
|
-
GOOGLE = "google",
|
|
28
|
-
OIDC = "oidc",
|
|
29
|
-
OIDC_LOGOS = "logos_oidc",
|
|
30
|
-
SCIM = "scim",
|
|
31
|
-
AI = "AI",
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const MIN_VALID_DATE = new Date(-2147483647000)
|
|
35
|
-
export const MAX_VALID_DATE = new Date(2147483647000)
|
|
36
|
-
export const DEFAULT_TENANT_ID = "default"
|
package/src/context/Context.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "async_hooks"
|
|
2
|
-
import { ContextMap } from "./types"
|
|
3
|
-
|
|
4
|
-
export default class Context {
|
|
5
|
-
static storage = new AsyncLocalStorage<ContextMap>()
|
|
6
|
-
|
|
7
|
-
static run<T>(context: ContextMap, func: () => T) {
|
|
8
|
-
return Context.storage.run(context, () => func())
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static get(): ContextMap {
|
|
12
|
-
return Context.storage.getStore() as ContextMap
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/context/identity.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IdentityContext,
|
|
3
|
-
IdentityType,
|
|
4
|
-
User,
|
|
5
|
-
isCloudAccount,
|
|
6
|
-
Account,
|
|
7
|
-
AccountUserContext,
|
|
8
|
-
UserContext,
|
|
9
|
-
Ctx,
|
|
10
|
-
} from "@budibase/types"
|
|
11
|
-
import * as context from "."
|
|
12
|
-
|
|
13
|
-
export function getIdentity(): IdentityContext | undefined {
|
|
14
|
-
return context.getIdentity()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function doInIdentityContext(identity: IdentityContext, task: any) {
|
|
18
|
-
return context.doInIdentityContext(identity, task)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// used in server/worker
|
|
22
|
-
export function doInUserContext(user: User, ctx: Ctx, task: any) {
|
|
23
|
-
const userContext: UserContext = {
|
|
24
|
-
...user,
|
|
25
|
-
_id: user._id as string,
|
|
26
|
-
type: IdentityType.USER,
|
|
27
|
-
hostInfo: {
|
|
28
|
-
ipAddress: ctx.request.ip,
|
|
29
|
-
// filled in by koa-useragent package
|
|
30
|
-
userAgent: ctx.userAgent.source,
|
|
31
|
-
},
|
|
32
|
-
}
|
|
33
|
-
return doInIdentityContext(userContext, task)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// used in account portal
|
|
37
|
-
export function doInAccountContext(account: Account, task: any) {
|
|
38
|
-
const _id = getAccountUserId(account)
|
|
39
|
-
const tenantId = account.tenantId
|
|
40
|
-
const accountContext: AccountUserContext = {
|
|
41
|
-
_id,
|
|
42
|
-
type: IdentityType.USER,
|
|
43
|
-
tenantId,
|
|
44
|
-
account,
|
|
45
|
-
}
|
|
46
|
-
return doInIdentityContext(accountContext, task)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function getAccountUserId(account: Account) {
|
|
50
|
-
let userId: string
|
|
51
|
-
if (isCloudAccount(account)) {
|
|
52
|
-
userId = account.budibaseUserId
|
|
53
|
-
} else {
|
|
54
|
-
// use account id as user id for self-hosting
|
|
55
|
-
userId = account.accountId
|
|
56
|
-
}
|
|
57
|
-
return userId
|
|
58
|
-
}
|
package/src/context/index.ts
DELETED