@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.
Files changed (272) hide show
  1. package/dist/index.js.map +1 -1
  2. package/dist/index.js.meta.json +1 -1
  3. package/dist/package.json +11 -4
  4. package/dist/plugins.js.meta.json +1 -1
  5. package/package.json +11 -4
  6. package/src/accounts/accounts.ts +0 -82
  7. package/src/accounts/api.ts +0 -59
  8. package/src/accounts/index.ts +0 -1
  9. package/src/auth/auth.ts +0 -210
  10. package/src/auth/index.ts +0 -1
  11. package/src/auth/tests/auth.spec.ts +0 -14
  12. package/src/blacklist/blacklist.ts +0 -54
  13. package/src/blacklist/index.ts +0 -1
  14. package/src/blacklist/tests/blacklist.spec.ts +0 -46
  15. package/src/cache/appMetadata.ts +0 -88
  16. package/src/cache/base/index.ts +0 -150
  17. package/src/cache/docWritethrough.ts +0 -105
  18. package/src/cache/generic.ts +0 -33
  19. package/src/cache/index.ts +0 -8
  20. package/src/cache/invite.ts +0 -86
  21. package/src/cache/passwordReset.ts +0 -49
  22. package/src/cache/tests/docWritethrough.spec.ts +0 -296
  23. package/src/cache/tests/user.spec.ts +0 -145
  24. package/src/cache/tests/writethrough.spec.ts +0 -139
  25. package/src/cache/user.ts +0 -154
  26. package/src/cache/writethrough.ts +0 -133
  27. package/src/configs/configs.ts +0 -263
  28. package/src/configs/index.ts +0 -1
  29. package/src/configs/tests/configs.spec.ts +0 -184
  30. package/src/constants/db.ts +0 -75
  31. package/src/constants/index.ts +0 -2
  32. package/src/constants/misc.ts +0 -36
  33. package/src/context/Context.ts +0 -14
  34. package/src/context/identity.ts +0 -58
  35. package/src/context/index.ts +0 -3
  36. package/src/context/mainContext.ts +0 -422
  37. package/src/context/tests/index.spec.ts +0 -255
  38. package/src/context/types.ts +0 -26
  39. package/src/db/Replication.ts +0 -94
  40. package/src/db/couch/DatabaseImpl.ts +0 -511
  41. package/src/db/couch/connections.ts +0 -89
  42. package/src/db/couch/index.ts +0 -4
  43. package/src/db/couch/pouchDB.ts +0 -97
  44. package/src/db/couch/pouchDump.ts +0 -0
  45. package/src/db/couch/tests/DatabaseImpl.spec.ts +0 -118
  46. package/src/db/couch/utils.ts +0 -55
  47. package/src/db/db.ts +0 -34
  48. package/src/db/errors.ts +0 -14
  49. package/src/db/index.ts +0 -12
  50. package/src/db/instrumentation.ts +0 -199
  51. package/src/db/lucene.ts +0 -721
  52. package/src/db/searchIndexes/index.ts +0 -1
  53. package/src/db/searchIndexes/searchIndexes.ts +0 -62
  54. package/src/db/tests/DatabaseImpl.spec.ts +0 -55
  55. package/src/db/tests/connections.spec.ts +0 -22
  56. package/src/db/tests/index.spec.ts +0 -32
  57. package/src/db/tests/lucene.spec.ts +0 -400
  58. package/src/db/tests/pouch.spec.js +0 -62
  59. package/src/db/tests/utils.spec.ts +0 -63
  60. package/src/db/utils.ts +0 -208
  61. package/src/db/views.ts +0 -245
  62. package/src/docIds/conversions.ts +0 -60
  63. package/src/docIds/ids.ts +0 -126
  64. package/src/docIds/index.ts +0 -2
  65. package/src/docIds/newid.ts +0 -5
  66. package/src/docIds/params.ts +0 -189
  67. package/src/docUpdates/index.ts +0 -24
  68. package/src/environment.ts +0 -293
  69. package/src/errors/errors.ts +0 -119
  70. package/src/errors/index.ts +0 -1
  71. package/src/events/analytics.ts +0 -6
  72. package/src/events/asyncEvents/index.ts +0 -2
  73. package/src/events/asyncEvents/publisher.ts +0 -12
  74. package/src/events/asyncEvents/queue.ts +0 -22
  75. package/src/events/backfill.ts +0 -183
  76. package/src/events/documentId.ts +0 -56
  77. package/src/events/events.ts +0 -47
  78. package/src/events/identification.ts +0 -311
  79. package/src/events/index.ts +0 -15
  80. package/src/events/processors/AnalyticsProcessor.ts +0 -64
  81. package/src/events/processors/AuditLogsProcessor.ts +0 -92
  82. package/src/events/processors/LoggingProcessor.ts +0 -36
  83. package/src/events/processors/Processors.ts +0 -52
  84. package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -38
  85. package/src/events/processors/index.ts +0 -19
  86. package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
  87. package/src/events/processors/posthog/index.ts +0 -3
  88. package/src/events/processors/posthog/rateLimiting.ts +0 -106
  89. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -164
  90. package/src/events/processors/types.ts +0 -1
  91. package/src/events/publishers/account.ts +0 -41
  92. package/src/events/publishers/ai.ts +0 -21
  93. package/src/events/publishers/app.ts +0 -168
  94. package/src/events/publishers/auditLog.ts +0 -26
  95. package/src/events/publishers/auth.ts +0 -73
  96. package/src/events/publishers/automation.ts +0 -110
  97. package/src/events/publishers/backfill.ts +0 -74
  98. package/src/events/publishers/backup.ts +0 -42
  99. package/src/events/publishers/datasource.ts +0 -48
  100. package/src/events/publishers/email.ts +0 -17
  101. package/src/events/publishers/environmentVariable.ts +0 -38
  102. package/src/events/publishers/group.ts +0 -99
  103. package/src/events/publishers/index.ts +0 -25
  104. package/src/events/publishers/installation.ts +0 -38
  105. package/src/events/publishers/layout.ts +0 -26
  106. package/src/events/publishers/license.ts +0 -84
  107. package/src/events/publishers/org.ts +0 -37
  108. package/src/events/publishers/plugin.ts +0 -47
  109. package/src/events/publishers/query.ts +0 -89
  110. package/src/events/publishers/role.ts +0 -62
  111. package/src/events/publishers/rows.ts +0 -29
  112. package/src/events/publishers/screen.ts +0 -36
  113. package/src/events/publishers/serve.ts +0 -43
  114. package/src/events/publishers/table.ts +0 -70
  115. package/src/events/publishers/user.ts +0 -202
  116. package/src/events/publishers/view.ts +0 -107
  117. package/src/features/features.ts +0 -277
  118. package/src/features/index.ts +0 -2
  119. package/src/features/tests/features.spec.ts +0 -267
  120. package/src/features/tests/utils.ts +0 -64
  121. package/src/helpers.ts +0 -9
  122. package/src/index.ts +0 -59
  123. package/src/installation.ts +0 -115
  124. package/src/logging/alerts.ts +0 -26
  125. package/src/logging/correlation/correlation.ts +0 -15
  126. package/src/logging/correlation/index.ts +0 -1
  127. package/src/logging/correlation/middleware.ts +0 -18
  128. package/src/logging/index.ts +0 -4
  129. package/src/logging/pino/logger.ts +0 -239
  130. package/src/logging/pino/middleware.ts +0 -48
  131. package/src/logging/system.ts +0 -81
  132. package/src/logging/tests/system.spec.ts +0 -61
  133. package/src/middleware/adminOnly.ts +0 -9
  134. package/src/middleware/auditLog.ts +0 -6
  135. package/src/middleware/authenticated.ts +0 -247
  136. package/src/middleware/builderOnly.ts +0 -21
  137. package/src/middleware/builderOrAdmin.ts +0 -21
  138. package/src/middleware/contentSecurityPolicy.ts +0 -113
  139. package/src/middleware/csrf.ts +0 -81
  140. package/src/middleware/errorHandling.ts +0 -43
  141. package/src/middleware/index.ts +0 -24
  142. package/src/middleware/internalApi.ts +0 -23
  143. package/src/middleware/ip.ts +0 -12
  144. package/src/middleware/joi-validator.ts +0 -58
  145. package/src/middleware/matchers.ts +0 -39
  146. package/src/middleware/passport/datasource/google.ts +0 -102
  147. package/src/middleware/passport/local.ts +0 -54
  148. package/src/middleware/passport/sso/google.ts +0 -77
  149. package/src/middleware/passport/sso/oidc.ts +0 -152
  150. package/src/middleware/passport/sso/sso.ts +0 -138
  151. package/src/middleware/passport/sso/tests/google.spec.ts +0 -68
  152. package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -144
  153. package/src/middleware/passport/sso/tests/sso.spec.ts +0 -197
  154. package/src/middleware/passport/utils.ts +0 -38
  155. package/src/middleware/querystringToBody.ts +0 -28
  156. package/src/middleware/tenancy.ts +0 -36
  157. package/src/middleware/tests/builder.spec.ts +0 -181
  158. package/src/middleware/tests/contentSecurityPolicy.spec.ts +0 -75
  159. package/src/middleware/tests/matchers.spec.ts +0 -100
  160. package/src/migrations/definitions.ts +0 -40
  161. package/src/migrations/index.ts +0 -2
  162. package/src/migrations/migrations.ts +0 -186
  163. package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
  164. package/src/migrations/tests/migrations.spec.ts +0 -64
  165. package/src/objectStore/buckets/app.ts +0 -53
  166. package/src/objectStore/buckets/global.ts +0 -29
  167. package/src/objectStore/buckets/index.ts +0 -3
  168. package/src/objectStore/buckets/plugins.ts +0 -71
  169. package/src/objectStore/buckets/tests/app.spec.ts +0 -161
  170. package/src/objectStore/buckets/tests/global.spec.ts +0 -74
  171. package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
  172. package/src/objectStore/cloudfront.ts +0 -41
  173. package/src/objectStore/index.ts +0 -3
  174. package/src/objectStore/objectStore.ts +0 -585
  175. package/src/objectStore/utils.ts +0 -113
  176. package/src/platform/index.ts +0 -3
  177. package/src/platform/platformDb.ts +0 -6
  178. package/src/platform/tenants.ts +0 -101
  179. package/src/platform/tests/tenants.spec.ts +0 -26
  180. package/src/platform/users.ts +0 -129
  181. package/src/plugin/index.ts +0 -1
  182. package/src/plugin/tests/validation.spec.ts +0 -209
  183. package/src/plugin/utils.ts +0 -175
  184. package/src/queue/constants.ts +0 -8
  185. package/src/queue/inMemoryQueue.ts +0 -189
  186. package/src/queue/index.ts +0 -2
  187. package/src/queue/listeners.ts +0 -199
  188. package/src/queue/queue.ts +0 -84
  189. package/src/redis/index.ts +0 -6
  190. package/src/redis/init.ts +0 -118
  191. package/src/redis/redis.ts +0 -358
  192. package/src/redis/redlockImpl.ts +0 -155
  193. package/src/redis/tests/redis.spec.ts +0 -207
  194. package/src/redis/tests/redlockImpl.spec.ts +0 -105
  195. package/src/redis/utils.ts +0 -128
  196. package/src/security/auth.ts +0 -24
  197. package/src/security/encryption.ts +0 -185
  198. package/src/security/index.ts +0 -1
  199. package/src/security/permissions.ts +0 -166
  200. package/src/security/roles.ts +0 -655
  201. package/src/security/secrets.ts +0 -20
  202. package/src/security/sessions.ts +0 -123
  203. package/src/security/tests/auth.spec.ts +0 -45
  204. package/src/security/tests/encryption.spec.ts +0 -31
  205. package/src/security/tests/permissions.spec.ts +0 -146
  206. package/src/security/tests/secrets.spec.ts +0 -35
  207. package/src/security/tests/sessions.spec.ts +0 -12
  208. package/src/sql/designDoc.ts +0 -17
  209. package/src/sql/index.ts +0 -5
  210. package/src/sql/sql.ts +0 -1854
  211. package/src/sql/sqlTable.ts +0 -319
  212. package/src/sql/utils.ts +0 -193
  213. package/src/tenancy/db.ts +0 -6
  214. package/src/tenancy/index.ts +0 -2
  215. package/src/tenancy/tenancy.ts +0 -148
  216. package/src/tenancy/tests/tenancy.spec.ts +0 -184
  217. package/src/timers/index.ts +0 -1
  218. package/src/timers/timers.ts +0 -22
  219. package/src/users/db.ts +0 -582
  220. package/src/users/events.ts +0 -176
  221. package/src/users/index.ts +0 -4
  222. package/src/users/lookup.ts +0 -99
  223. package/src/users/test/db.spec.ts +0 -188
  224. package/src/users/test/utils.spec.ts +0 -67
  225. package/src/users/users.ts +0 -353
  226. package/src/users/utils.ts +0 -81
  227. package/src/utils/Duration.ts +0 -56
  228. package/src/utils/hashing.ts +0 -15
  229. package/src/utils/index.ts +0 -4
  230. package/src/utils/stringUtils.ts +0 -8
  231. package/src/utils/tests/Duration.spec.ts +0 -19
  232. package/src/utils/tests/utils.spec.ts +0 -204
  233. package/src/utils/utils.ts +0 -249
  234. package/tests/core/logging.ts +0 -34
  235. package/tests/core/users/users.spec.js +0 -53
  236. package/tests/core/utilities/index.ts +0 -7
  237. package/tests/core/utilities/jestUtils.ts +0 -33
  238. package/tests/core/utilities/mocks/alerts.ts +0 -4
  239. package/tests/core/utilities/mocks/date.ts +0 -3
  240. package/tests/core/utilities/mocks/events.ts +0 -132
  241. package/tests/core/utilities/mocks/index.ts +0 -9
  242. package/tests/core/utilities/mocks/licenses.ts +0 -119
  243. package/tests/core/utilities/queue.ts +0 -9
  244. package/tests/core/utilities/structures/Chance.ts +0 -20
  245. package/tests/core/utilities/structures/accounts.ts +0 -80
  246. package/tests/core/utilities/structures/apps.ts +0 -21
  247. package/tests/core/utilities/structures/common.ts +0 -7
  248. package/tests/core/utilities/structures/db.ts +0 -12
  249. package/tests/core/utilities/structures/documents/index.ts +0 -1
  250. package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
  251. package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
  252. package/tests/core/utilities/structures/generator.ts +0 -3
  253. package/tests/core/utilities/structures/index.ts +0 -15
  254. package/tests/core/utilities/structures/koa.ts +0 -16
  255. package/tests/core/utilities/structures/licenses.ts +0 -190
  256. package/tests/core/utilities/structures/plugins.ts +0 -19
  257. package/tests/core/utilities/structures/quotas.ts +0 -72
  258. package/tests/core/utilities/structures/scim.ts +0 -80
  259. package/tests/core/utilities/structures/sso.ts +0 -118
  260. package/tests/core/utilities/structures/tenants.ts +0 -5
  261. package/tests/core/utilities/structures/userGroups.ts +0 -10
  262. package/tests/core/utilities/structures/users.ts +0 -89
  263. package/tests/core/utilities/testContainerUtils.ts +0 -165
  264. package/tests/core/utilities/utils/index.ts +0 -2
  265. package/tests/core/utilities/utils/queue.ts +0 -27
  266. package/tests/core/utilities/utils/time.ts +0 -3
  267. package/tests/extra/DBTestConfiguration.ts +0 -36
  268. package/tests/extra/index.ts +0 -2
  269. package/tests/extra/testEnv.ts +0 -95
  270. package/tests/index.ts +0 -2
  271. package/tests/jestEnv.ts +0 -10
  272. package/tests/jestSetup.ts +0 -36
@@ -1,72 +0,0 @@
1
- import { MonthlyQuotaName, QuotaUsage } from "@budibase/types"
2
-
3
- export const usage = (users: number = 0, creators: number = 0): QuotaUsage => {
4
- return {
5
- _id: "usage_quota",
6
- quotaReset: new Date().toISOString(),
7
- apps: {
8
- app_1: {
9
- // @ts-ignore - the apps definition doesn't match up to actual usage
10
- usageQuota: {
11
- rows: 0,
12
- },
13
- },
14
- },
15
- monthly: {
16
- "01-2023": {
17
- automations: 0,
18
- dayPasses: 0,
19
- queries: 0,
20
- budibaseAICredits: 0,
21
- triggers: {},
22
- breakdown: {
23
- rowQueries: {
24
- parent: MonthlyQuotaName.QUERIES,
25
- values: {
26
- row_1: 0,
27
- row_2: 0,
28
- },
29
- },
30
- datasourceQueries: {
31
- parent: MonthlyQuotaName.QUERIES,
32
- values: {
33
- ds_1: 0,
34
- ds_2: 0,
35
- },
36
- },
37
- automations: {
38
- parent: MonthlyQuotaName.AUTOMATIONS,
39
- values: {
40
- auto_1: 0,
41
- auto_2: 0,
42
- },
43
- },
44
- },
45
- },
46
- "02-2023": {
47
- automations: 0,
48
- dayPasses: 0,
49
- queries: 0,
50
- budibaseAICredits: 0,
51
- triggers: {},
52
- },
53
- current: {
54
- automations: 0,
55
- dayPasses: 0,
56
- queries: 0,
57
- budibaseAICredits: 0,
58
- triggers: {},
59
- },
60
- },
61
- usageQuota: {
62
- apps: 0,
63
- plugins: 0,
64
- users,
65
- creators,
66
- userGroups: 0,
67
- rows: 0,
68
- aiCustomConfigs: 0,
69
- triggers: {},
70
- },
71
- }
72
- }
@@ -1,80 +0,0 @@
1
- import { ScimCreateGroupRequest, ScimCreateUserRequest } from "@budibase/types"
2
- import { uuid } from "./common"
3
- import { generator } from "./generator"
4
-
5
- interface CreateUserRequestFields {
6
- externalId: string
7
- email: string
8
- firstName: string
9
- lastName: string
10
- username: string
11
- }
12
-
13
- export function createUserRequest(userData?: Partial<CreateUserRequestFields>) {
14
- const defaultValues = {
15
- externalId: uuid(),
16
- email: `${uuid()}@example.com`,
17
- firstName: generator.first(),
18
- lastName: generator.last(),
19
- username: generator.name(),
20
- }
21
-
22
- const { externalId, email, firstName, lastName, username } = {
23
- ...defaultValues,
24
- ...userData,
25
- }
26
-
27
- let user: ScimCreateUserRequest = {
28
- schemas: [
29
- "urn:ietf:params:scim:schemas:core:2.0:User",
30
- "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
31
- ],
32
- externalId,
33
- userName: username,
34
- active: true,
35
- emails: [
36
- {
37
- primary: true,
38
- type: "work",
39
- value: email,
40
- },
41
- ],
42
- meta: {
43
- resourceType: "User",
44
- },
45
- roles: [],
46
- }
47
-
48
- if (firstName || lastName) {
49
- user.name = {
50
- formatted: [firstName, lastName].filter(s => s).join(" "),
51
- familyName: lastName,
52
- givenName: firstName,
53
- }
54
- }
55
-
56
- return user
57
- }
58
-
59
- export function createGroupRequest(groupData?: {
60
- externalId?: string
61
- displayName?: string
62
- }) {
63
- const { externalId = uuid(), displayName = generator.word() } =
64
- groupData || {}
65
-
66
- const group: ScimCreateGroupRequest = {
67
- schemas: [
68
- "urn:ietf:params:scim:schemas:core:2.0:Group",
69
- "http://schemas.microsoft.com/2006/11/ResourceManagement/ADSCIM/2.0/Group",
70
- ],
71
- externalId: externalId,
72
- displayName: displayName,
73
- meta: {
74
- resourceType: "Group",
75
- created: new Date(),
76
- lastModified: new Date(),
77
- },
78
- }
79
- return group
80
- }
@@ -1,118 +0,0 @@
1
- import {
2
- ConfigType,
3
- GoogleConfig,
4
- GoogleInnerConfig,
5
- JwtClaims,
6
- OAuth2,
7
- OIDCInnerConfig,
8
- OIDCWellKnownConfig,
9
- SSOAuthDetails,
10
- SSOProfile,
11
- SSOProviderType,
12
- User,
13
- } from "@budibase/types"
14
- import { generator } from "./generator"
15
- import { email, uuid } from "./common"
16
- import * as users from "./users"
17
- import sample from "lodash/sample"
18
-
19
- export function OAuth(): OAuth2 {
20
- return {
21
- refreshToken: generator.string(),
22
- accessToken: generator.string(),
23
- }
24
- }
25
-
26
- export function authDetails(userDoc?: User): SSOAuthDetails {
27
- if (!userDoc) {
28
- userDoc = users.user()
29
- }
30
-
31
- const userId = userDoc._id || uuid()
32
- const provider = generator.string()
33
-
34
- const profile = ssoProfile(userDoc)
35
- profile.provider = provider
36
- profile.id = userId
37
-
38
- return {
39
- email: userDoc.email,
40
- oauth2: OAuth(),
41
- profile,
42
- provider,
43
- providerType: providerType(),
44
- userId,
45
- }
46
- }
47
-
48
- export function providerType(): SSOProviderType {
49
- return sample(Object.values(SSOProviderType)) as SSOProviderType
50
- }
51
-
52
- export function ssoProfile(user?: User): SSOProfile {
53
- if (!user) {
54
- user = users.user()
55
- }
56
- return {
57
- id: user._id!,
58
- name: {
59
- givenName: user.firstName,
60
- familyName: user.lastName,
61
- },
62
- _json: {
63
- email: user.email,
64
- picture: "http://example.com",
65
- },
66
- provider: generator.string(),
67
- }
68
- }
69
-
70
- // OIDC
71
-
72
- export function oidcConfig(): OIDCInnerConfig {
73
- return {
74
- uuid: uuid(),
75
- activated: true,
76
- logo: "",
77
- name: generator.string(),
78
- configUrl: "http://someconfigurl",
79
- clientID: generator.string(),
80
- clientSecret: generator.string(),
81
- scopes: [],
82
- }
83
- }
84
-
85
- // response from .well-known/openid-configuration
86
- export function oidcWellKnownConfig(): OIDCWellKnownConfig {
87
- return {
88
- issuer: generator.string(),
89
- authorization_endpoint: generator.url(),
90
- token_endpoint: generator.url(),
91
- userinfo_endpoint: generator.url(),
92
- }
93
- }
94
-
95
- export function jwtClaims(): JwtClaims {
96
- return {
97
- email: email(),
98
- preferred_username: email(),
99
- }
100
- }
101
-
102
- // GOOGLE
103
-
104
- export function googleConfig(): GoogleInnerConfig {
105
- return {
106
- activated: true,
107
- clientID: generator.string(),
108
- clientSecret: generator.string(),
109
- }
110
- }
111
-
112
- export function googleConfigDoc(): GoogleConfig {
113
- return {
114
- _id: "config_google",
115
- type: ConfigType.GOOGLE,
116
- config: googleConfig(),
117
- }
118
- }
@@ -1,5 +0,0 @@
1
- import { newid } from "../../../../src/docIds/newid"
2
-
3
- export function id() {
4
- return `tenant-${newid()}`
5
- }
@@ -1,10 +0,0 @@
1
- import { UserGroup } from "@budibase/types"
2
- import { generator } from "./generator"
3
-
4
- export function userGroup(): UserGroup {
5
- return {
6
- name: generator.guid(),
7
- icon: generator.word(),
8
- color: generator.word(),
9
- }
10
- }
@@ -1,89 +0,0 @@
1
- import {
2
- AdminUser,
3
- AdminOnlyUser,
4
- BuilderUser,
5
- SSOAuthDetails,
6
- SSOUser,
7
- User,
8
- } from "@budibase/types"
9
- import { authDetails } from "./sso"
10
- import { uuid } from "./common"
11
- import { generator } from "./generator"
12
- import { tenant } from "."
13
-
14
- export const newEmail = () => {
15
- return `${uuid()}@example.com`
16
- }
17
-
18
- export const user = (userProps?: Partial<Omit<User, "userId">>): User => {
19
- const userId = userProps?._id
20
- return {
21
- _id: userId,
22
- userId,
23
- email: newEmail(),
24
- password: "password123!",
25
- roles: { app_test: "admin" },
26
- firstName: generator.first(),
27
- lastName: generator.last(),
28
- tenantId: tenant.id(),
29
- ...userProps,
30
- }
31
- }
32
-
33
- export const adminUser = (userProps?: any): AdminUser => {
34
- return {
35
- ...user(userProps),
36
- admin: {
37
- global: true,
38
- },
39
- builder: {
40
- global: true,
41
- },
42
- }
43
- }
44
-
45
- export const adminOnlyUser = (userProps?: any): AdminOnlyUser => {
46
- return {
47
- ...user(userProps),
48
- admin: {
49
- global: true,
50
- },
51
- }
52
- }
53
-
54
- export const builderUser = (userProps?: Partial<User>): BuilderUser => {
55
- return {
56
- ...user(userProps),
57
- builder: {
58
- global: true,
59
- },
60
- }
61
- }
62
-
63
- export const appBuilderUser = (appId: string, userProps?: any): BuilderUser => {
64
- return {
65
- ...user(userProps),
66
- builder: {
67
- apps: [appId],
68
- },
69
- }
70
- }
71
-
72
- export function ssoUser(
73
- opts: { user?: any; details?: SSOAuthDetails } = {}
74
- ): SSOUser {
75
- const base = user(opts.user)
76
- delete base.password
77
-
78
- if (!opts.details) {
79
- opts.details = authDetails(base)
80
- }
81
-
82
- return {
83
- ...base,
84
- forceResetPassword: false,
85
- oauth2: opts.details?.oauth2,
86
- provider: opts.details?.provider!,
87
- providerType: opts.details?.providerType!,
88
- }
89
- }
@@ -1,165 +0,0 @@
1
- import { execSync } from "child_process"
2
- import { cloneDeep } from "lodash"
3
- import { GenericContainer, StartedTestContainer } from "testcontainers"
4
-
5
- const IPV4_PORT_REGEX = new RegExp(`0\\.0\\.0\\.0:(\\d+)->(\\d+)/tcp`, "g")
6
-
7
- interface ContainerInfo {
8
- Command: string
9
- CreatedAt: string
10
- ID: string
11
- Image: string
12
- Labels: string
13
- LocalVolumes: string
14
- Mounts: string
15
- Names: string
16
- Networks: string
17
- Ports: string
18
- RunningFor: string
19
- Size: string
20
- State: string
21
- Status: string
22
- }
23
-
24
- function getTestcontainers(): ContainerInfo[] {
25
- // We use --format json to make sure the output is nice and machine-readable,
26
- // and we use --no-trunc so that the command returns full container IDs so we
27
- // can filter on them correctly.
28
- return execSync("docker ps --format json --no-trunc")
29
- .toString()
30
- .split("\n")
31
- .filter(x => x.length > 0)
32
- .map(x => JSON.parse(x) as ContainerInfo)
33
- .filter(
34
- x =>
35
- x.Labels.includes("org.testcontainers=true") &&
36
- x.Labels.includes("com.budibase=true")
37
- )
38
- }
39
-
40
- export function getContainerByImage(image: string) {
41
- const containers = getTestcontainers().filter(x => x.Image.startsWith(image))
42
- if (containers.length > 1) {
43
- let errorMessage = `Multiple containers found starting with image: "${image}"\n\n`
44
- for (const container of containers) {
45
- errorMessage += JSON.stringify(container, null, 2)
46
- }
47
- throw new Error(errorMessage)
48
- }
49
- return containers[0]
50
- }
51
-
52
- export function getContainerById(id: string) {
53
- return getTestcontainers().find(x => x.ID === id)
54
- }
55
-
56
- export interface Port {
57
- host: number
58
- container: number
59
- }
60
-
61
- export function getExposedV4Ports(container: ContainerInfo): Port[] {
62
- let ports: Port[] = []
63
- for (const match of container.Ports.matchAll(IPV4_PORT_REGEX)) {
64
- ports.push({ host: parseInt(match[1]), container: parseInt(match[2]) })
65
- }
66
- return ports
67
- }
68
-
69
- export function getExposedV4Port(container: ContainerInfo, port: number) {
70
- return getExposedV4Ports(container).find(x => x.container === port)?.host
71
- }
72
-
73
- export function setupEnv(...envs: any[]) {
74
- // We start couchdb in globalSetup.ts, in the root of the monorepo, so it
75
- // should be relatively safe to look for it by its image name.
76
- const couch = getContainerByImage("budibase/couchdb")
77
- if (!couch) {
78
- throw new Error("CouchDB container not found")
79
- }
80
-
81
- const couchPort = getExposedV4Port(couch, 5984)
82
- if (!couchPort) {
83
- throw new Error("CouchDB port not found")
84
- }
85
-
86
- const couchSqlPort = getExposedV4Port(couch, 4984)
87
- if (!couchSqlPort) {
88
- throw new Error("CouchDB SQL port not found")
89
- }
90
-
91
- const minio = getContainerByImage("minio/minio")
92
-
93
- const minioPort = getExposedV4Port(minio, 9000)
94
- if (!minioPort) {
95
- throw new Error("Minio port not found")
96
- }
97
-
98
- const configs = [
99
- { key: "COUCH_DB_PORT", value: `${couchPort}` },
100
- { key: "COUCH_DB_URL", value: `http://127.0.0.1:${couchPort}` },
101
- { key: "COUCH_DB_SQL_URL", value: `http://127.0.0.1:${couchSqlPort}` },
102
- { key: "MINIO_URL", value: `http://127.0.0.1:${minioPort}` },
103
- ]
104
-
105
- for (const config of configs.filter(x => !!x.value)) {
106
- for (const env of envs) {
107
- env._set(config.key, config.value)
108
- }
109
- }
110
- }
111
-
112
- export async function startContainer(container: GenericContainer) {
113
- const imageName = (container as any).imageName.string as string
114
- let key: string = imageName
115
- if (imageName.includes("@sha256")) {
116
- key = imageName.split("@")[0]
117
- }
118
- key = key.replace(/\//g, "-").replace(/:/g, "-")
119
-
120
- container = container
121
- .withReuse()
122
- .withLabels({ "com.budibase": "true" })
123
- .withName(`${key}_testcontainer`)
124
-
125
- let startedContainer: StartedTestContainer | undefined = undefined
126
- let lastError = undefined
127
- for (let i = 0; i < 10; i++) {
128
- try {
129
- // container.start() is not an idempotent operation, calling `start`
130
- // modifies the internal state of a GenericContainer instance such that
131
- // the hash it uses to determine reuse changes. We need to clone the
132
- // container before calling start to ensure that we're using the same
133
- // reuse hash every time.
134
- const containerCopy = cloneDeep(container)
135
- startedContainer = await containerCopy.start()
136
- lastError = undefined
137
- break
138
- } catch (e: any) {
139
- lastError = e
140
- await new Promise(resolve => setTimeout(resolve, 1000))
141
- }
142
- }
143
-
144
- if (!startedContainer) {
145
- if (lastError) {
146
- throw lastError
147
- }
148
- throw new Error(`failed to start container: ${imageName}`)
149
- }
150
-
151
- const info = getContainerById(startedContainer.getId())
152
- if (!info) {
153
- throw new Error("Container not found")
154
- }
155
-
156
- // Some Docker runtimes, when you expose a port, will bind it to both
157
- // 127.0.0.1 and ::1, so ipv4 and ipv6. The port spaces of ipv4 and ipv6
158
- // addresses are not shared, and testcontainers will sometimes give you back
159
- // the ipv6 port. There's no way to know that this has happened, and if you
160
- // try to then connect to `localhost:port` you may attempt to bind to the v4
161
- // address which could be unbound or even an entirely different container. For
162
- // that reason, we don't use testcontainers' `getExposedPort` function,
163
- // preferring instead our own method that guaranteed v4 ports.
164
- return getExposedV4Ports(info)
165
- }
@@ -1,2 +0,0 @@
1
- export * as time from "./time"
2
- export * as queue from "./queue"
@@ -1,27 +0,0 @@
1
- import { Queue } from "bull"
2
- import { GenericContainer, Wait } from "testcontainers"
3
- import { startContainer } from "../testContainerUtils"
4
-
5
- export async function useRealQueues() {
6
- const ports = await startContainer(
7
- new GenericContainer("redis")
8
- .withExposedPorts(6379)
9
- .withWaitStrategy(
10
- Wait.forSuccessfulCommand(`redis-cli`).withStartupTimeout(10000)
11
- )
12
- )
13
-
14
- const port = ports.find(x => x.container === 6379)?.host
15
- if (!port) {
16
- throw new Error("Redis port not found")
17
- }
18
- process.env.BULL_TEST_REDIS_PORT = port.toString()
19
- }
20
-
21
- export async function processMessages(queue: Queue) {
22
- do {
23
- await queue.whenCurrentJobsFinished()
24
- } while (await queue.count())
25
-
26
- await queue.whenCurrentJobsFinished()
27
- }
@@ -1,3 +0,0 @@
1
- export function addDaysToDate(date: Date, days: number) {
2
- return new Date(date.getTime() + days * 24 * 60 * 60 * 1000)
3
- }
@@ -1,36 +0,0 @@
1
- import "../core/utilities/mocks"
2
- import * as structures from "../core/utilities/structures"
3
- import * as testEnv from "./testEnv"
4
- import * as context from "../../src/context"
5
-
6
- class DBTestConfiguration {
7
- tenantId: string
8
-
9
- constructor() {
10
- // db tests need to be multi tenant to prevent conflicts
11
- testEnv.multiTenant()
12
- this.tenantId = structures.tenant.id()
13
- }
14
-
15
- newTenant() {
16
- this.tenantId = structures.tenant.id()
17
- }
18
-
19
- // TENANCY
20
-
21
- doInTenant<T>(task: () => Promise<T>) {
22
- return context.doInTenant(this.tenantId, () => {
23
- return task()
24
- })
25
- }
26
-
27
- getTenantId() {
28
- try {
29
- return context.getTenantId()
30
- } catch (e) {
31
- return this.tenantId!
32
- }
33
- }
34
- }
35
-
36
- export default DBTestConfiguration
@@ -1,2 +0,0 @@
1
- export * as testEnv from "./testEnv"
2
- export { default as DBTestConfiguration } from "./DBTestConfiguration"