@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.
Files changed (276) hide show
  1. package/dist/index.js +7 -1
  2. package/dist/index.js.map +2 -2
  3. package/dist/index.js.meta.json +1 -1
  4. package/dist/package.json +11 -4
  5. package/dist/plugins.js.meta.json +1 -1
  6. package/dist/src/environment.d.ts +1 -0
  7. package/dist/src/environment.js +6 -1
  8. package/dist/src/environment.js.map +1 -1
  9. package/package.json +11 -4
  10. package/src/accounts/accounts.ts +0 -82
  11. package/src/accounts/api.ts +0 -59
  12. package/src/accounts/index.ts +0 -1
  13. package/src/auth/auth.ts +0 -210
  14. package/src/auth/index.ts +0 -1
  15. package/src/auth/tests/auth.spec.ts +0 -14
  16. package/src/blacklist/blacklist.ts +0 -54
  17. package/src/blacklist/index.ts +0 -1
  18. package/src/blacklist/tests/blacklist.spec.ts +0 -46
  19. package/src/cache/appMetadata.ts +0 -88
  20. package/src/cache/base/index.ts +0 -150
  21. package/src/cache/docWritethrough.ts +0 -105
  22. package/src/cache/generic.ts +0 -33
  23. package/src/cache/index.ts +0 -8
  24. package/src/cache/invite.ts +0 -86
  25. package/src/cache/passwordReset.ts +0 -49
  26. package/src/cache/tests/docWritethrough.spec.ts +0 -296
  27. package/src/cache/tests/user.spec.ts +0 -145
  28. package/src/cache/tests/writethrough.spec.ts +0 -139
  29. package/src/cache/user.ts +0 -154
  30. package/src/cache/writethrough.ts +0 -133
  31. package/src/configs/configs.ts +0 -263
  32. package/src/configs/index.ts +0 -1
  33. package/src/configs/tests/configs.spec.ts +0 -184
  34. package/src/constants/db.ts +0 -75
  35. package/src/constants/index.ts +0 -2
  36. package/src/constants/misc.ts +0 -36
  37. package/src/context/Context.ts +0 -14
  38. package/src/context/identity.ts +0 -58
  39. package/src/context/index.ts +0 -3
  40. package/src/context/mainContext.ts +0 -422
  41. package/src/context/tests/index.spec.ts +0 -255
  42. package/src/context/types.ts +0 -26
  43. package/src/db/Replication.ts +0 -94
  44. package/src/db/couch/DatabaseImpl.ts +0 -511
  45. package/src/db/couch/connections.ts +0 -89
  46. package/src/db/couch/index.ts +0 -4
  47. package/src/db/couch/pouchDB.ts +0 -97
  48. package/src/db/couch/pouchDump.ts +0 -0
  49. package/src/db/couch/tests/DatabaseImpl.spec.ts +0 -118
  50. package/src/db/couch/utils.ts +0 -55
  51. package/src/db/db.ts +0 -34
  52. package/src/db/errors.ts +0 -14
  53. package/src/db/index.ts +0 -12
  54. package/src/db/instrumentation.ts +0 -199
  55. package/src/db/lucene.ts +0 -721
  56. package/src/db/searchIndexes/index.ts +0 -1
  57. package/src/db/searchIndexes/searchIndexes.ts +0 -62
  58. package/src/db/tests/DatabaseImpl.spec.ts +0 -55
  59. package/src/db/tests/connections.spec.ts +0 -22
  60. package/src/db/tests/index.spec.ts +0 -32
  61. package/src/db/tests/lucene.spec.ts +0 -400
  62. package/src/db/tests/pouch.spec.js +0 -62
  63. package/src/db/tests/utils.spec.ts +0 -63
  64. package/src/db/utils.ts +0 -208
  65. package/src/db/views.ts +0 -245
  66. package/src/docIds/conversions.ts +0 -60
  67. package/src/docIds/ids.ts +0 -126
  68. package/src/docIds/index.ts +0 -2
  69. package/src/docIds/newid.ts +0 -5
  70. package/src/docIds/params.ts +0 -189
  71. package/src/docUpdates/index.ts +0 -24
  72. package/src/environment.ts +0 -293
  73. package/src/errors/errors.ts +0 -119
  74. package/src/errors/index.ts +0 -1
  75. package/src/events/analytics.ts +0 -6
  76. package/src/events/asyncEvents/index.ts +0 -2
  77. package/src/events/asyncEvents/publisher.ts +0 -12
  78. package/src/events/asyncEvents/queue.ts +0 -22
  79. package/src/events/backfill.ts +0 -183
  80. package/src/events/documentId.ts +0 -56
  81. package/src/events/events.ts +0 -47
  82. package/src/events/identification.ts +0 -311
  83. package/src/events/index.ts +0 -15
  84. package/src/events/processors/AnalyticsProcessor.ts +0 -64
  85. package/src/events/processors/AuditLogsProcessor.ts +0 -92
  86. package/src/events/processors/LoggingProcessor.ts +0 -36
  87. package/src/events/processors/Processors.ts +0 -52
  88. package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -38
  89. package/src/events/processors/index.ts +0 -19
  90. package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
  91. package/src/events/processors/posthog/index.ts +0 -3
  92. package/src/events/processors/posthog/rateLimiting.ts +0 -106
  93. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -164
  94. package/src/events/processors/types.ts +0 -1
  95. package/src/events/publishers/account.ts +0 -41
  96. package/src/events/publishers/ai.ts +0 -21
  97. package/src/events/publishers/app.ts +0 -168
  98. package/src/events/publishers/auditLog.ts +0 -26
  99. package/src/events/publishers/auth.ts +0 -73
  100. package/src/events/publishers/automation.ts +0 -110
  101. package/src/events/publishers/backfill.ts +0 -74
  102. package/src/events/publishers/backup.ts +0 -42
  103. package/src/events/publishers/datasource.ts +0 -48
  104. package/src/events/publishers/email.ts +0 -17
  105. package/src/events/publishers/environmentVariable.ts +0 -38
  106. package/src/events/publishers/group.ts +0 -99
  107. package/src/events/publishers/index.ts +0 -25
  108. package/src/events/publishers/installation.ts +0 -38
  109. package/src/events/publishers/layout.ts +0 -26
  110. package/src/events/publishers/license.ts +0 -84
  111. package/src/events/publishers/org.ts +0 -37
  112. package/src/events/publishers/plugin.ts +0 -47
  113. package/src/events/publishers/query.ts +0 -89
  114. package/src/events/publishers/role.ts +0 -62
  115. package/src/events/publishers/rows.ts +0 -29
  116. package/src/events/publishers/screen.ts +0 -36
  117. package/src/events/publishers/serve.ts +0 -43
  118. package/src/events/publishers/table.ts +0 -70
  119. package/src/events/publishers/user.ts +0 -202
  120. package/src/events/publishers/view.ts +0 -107
  121. package/src/features/features.ts +0 -277
  122. package/src/features/index.ts +0 -2
  123. package/src/features/tests/features.spec.ts +0 -267
  124. package/src/features/tests/utils.ts +0 -64
  125. package/src/helpers.ts +0 -9
  126. package/src/index.ts +0 -59
  127. package/src/installation.ts +0 -115
  128. package/src/logging/alerts.ts +0 -26
  129. package/src/logging/correlation/correlation.ts +0 -15
  130. package/src/logging/correlation/index.ts +0 -1
  131. package/src/logging/correlation/middleware.ts +0 -18
  132. package/src/logging/index.ts +0 -4
  133. package/src/logging/pino/logger.ts +0 -239
  134. package/src/logging/pino/middleware.ts +0 -48
  135. package/src/logging/system.ts +0 -81
  136. package/src/logging/tests/system.spec.ts +0 -61
  137. package/src/middleware/adminOnly.ts +0 -9
  138. package/src/middleware/auditLog.ts +0 -6
  139. package/src/middleware/authenticated.ts +0 -247
  140. package/src/middleware/builderOnly.ts +0 -21
  141. package/src/middleware/builderOrAdmin.ts +0 -21
  142. package/src/middleware/contentSecurityPolicy.ts +0 -113
  143. package/src/middleware/csrf.ts +0 -81
  144. package/src/middleware/errorHandling.ts +0 -43
  145. package/src/middleware/index.ts +0 -24
  146. package/src/middleware/internalApi.ts +0 -23
  147. package/src/middleware/ip.ts +0 -12
  148. package/src/middleware/joi-validator.ts +0 -58
  149. package/src/middleware/matchers.ts +0 -39
  150. package/src/middleware/passport/datasource/google.ts +0 -102
  151. package/src/middleware/passport/local.ts +0 -54
  152. package/src/middleware/passport/sso/google.ts +0 -77
  153. package/src/middleware/passport/sso/oidc.ts +0 -152
  154. package/src/middleware/passport/sso/sso.ts +0 -138
  155. package/src/middleware/passport/sso/tests/google.spec.ts +0 -68
  156. package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -144
  157. package/src/middleware/passport/sso/tests/sso.spec.ts +0 -197
  158. package/src/middleware/passport/utils.ts +0 -38
  159. package/src/middleware/querystringToBody.ts +0 -28
  160. package/src/middleware/tenancy.ts +0 -36
  161. package/src/middleware/tests/builder.spec.ts +0 -181
  162. package/src/middleware/tests/contentSecurityPolicy.spec.ts +0 -75
  163. package/src/middleware/tests/matchers.spec.ts +0 -100
  164. package/src/migrations/definitions.ts +0 -40
  165. package/src/migrations/index.ts +0 -2
  166. package/src/migrations/migrations.ts +0 -186
  167. package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
  168. package/src/migrations/tests/migrations.spec.ts +0 -64
  169. package/src/objectStore/buckets/app.ts +0 -53
  170. package/src/objectStore/buckets/global.ts +0 -29
  171. package/src/objectStore/buckets/index.ts +0 -3
  172. package/src/objectStore/buckets/plugins.ts +0 -71
  173. package/src/objectStore/buckets/tests/app.spec.ts +0 -161
  174. package/src/objectStore/buckets/tests/global.spec.ts +0 -74
  175. package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
  176. package/src/objectStore/cloudfront.ts +0 -41
  177. package/src/objectStore/index.ts +0 -3
  178. package/src/objectStore/objectStore.ts +0 -585
  179. package/src/objectStore/utils.ts +0 -113
  180. package/src/platform/index.ts +0 -3
  181. package/src/platform/platformDb.ts +0 -6
  182. package/src/platform/tenants.ts +0 -101
  183. package/src/platform/tests/tenants.spec.ts +0 -26
  184. package/src/platform/users.ts +0 -129
  185. package/src/plugin/index.ts +0 -1
  186. package/src/plugin/tests/validation.spec.ts +0 -209
  187. package/src/plugin/utils.ts +0 -175
  188. package/src/queue/constants.ts +0 -8
  189. package/src/queue/inMemoryQueue.ts +0 -189
  190. package/src/queue/index.ts +0 -2
  191. package/src/queue/listeners.ts +0 -199
  192. package/src/queue/queue.ts +0 -84
  193. package/src/redis/index.ts +0 -6
  194. package/src/redis/init.ts +0 -118
  195. package/src/redis/redis.ts +0 -358
  196. package/src/redis/redlockImpl.ts +0 -155
  197. package/src/redis/tests/redis.spec.ts +0 -207
  198. package/src/redis/tests/redlockImpl.spec.ts +0 -105
  199. package/src/redis/utils.ts +0 -128
  200. package/src/security/auth.ts +0 -24
  201. package/src/security/encryption.ts +0 -185
  202. package/src/security/index.ts +0 -1
  203. package/src/security/permissions.ts +0 -166
  204. package/src/security/roles.ts +0 -655
  205. package/src/security/secrets.ts +0 -20
  206. package/src/security/sessions.ts +0 -123
  207. package/src/security/tests/auth.spec.ts +0 -45
  208. package/src/security/tests/encryption.spec.ts +0 -31
  209. package/src/security/tests/permissions.spec.ts +0 -146
  210. package/src/security/tests/secrets.spec.ts +0 -35
  211. package/src/security/tests/sessions.spec.ts +0 -12
  212. package/src/sql/designDoc.ts +0 -17
  213. package/src/sql/index.ts +0 -5
  214. package/src/sql/sql.ts +0 -1854
  215. package/src/sql/sqlTable.ts +0 -319
  216. package/src/sql/utils.ts +0 -193
  217. package/src/tenancy/db.ts +0 -6
  218. package/src/tenancy/index.ts +0 -2
  219. package/src/tenancy/tenancy.ts +0 -148
  220. package/src/tenancy/tests/tenancy.spec.ts +0 -184
  221. package/src/timers/index.ts +0 -1
  222. package/src/timers/timers.ts +0 -22
  223. package/src/users/db.ts +0 -582
  224. package/src/users/events.ts +0 -176
  225. package/src/users/index.ts +0 -4
  226. package/src/users/lookup.ts +0 -99
  227. package/src/users/test/db.spec.ts +0 -188
  228. package/src/users/test/utils.spec.ts +0 -67
  229. package/src/users/users.ts +0 -353
  230. package/src/users/utils.ts +0 -81
  231. package/src/utils/Duration.ts +0 -56
  232. package/src/utils/hashing.ts +0 -15
  233. package/src/utils/index.ts +0 -4
  234. package/src/utils/stringUtils.ts +0 -8
  235. package/src/utils/tests/Duration.spec.ts +0 -19
  236. package/src/utils/tests/utils.spec.ts +0 -204
  237. package/src/utils/utils.ts +0 -249
  238. package/tests/core/logging.ts +0 -34
  239. package/tests/core/users/users.spec.js +0 -53
  240. package/tests/core/utilities/index.ts +0 -7
  241. package/tests/core/utilities/jestUtils.ts +0 -33
  242. package/tests/core/utilities/mocks/alerts.ts +0 -4
  243. package/tests/core/utilities/mocks/date.ts +0 -3
  244. package/tests/core/utilities/mocks/events.ts +0 -132
  245. package/tests/core/utilities/mocks/index.ts +0 -9
  246. package/tests/core/utilities/mocks/licenses.ts +0 -119
  247. package/tests/core/utilities/queue.ts +0 -9
  248. package/tests/core/utilities/structures/Chance.ts +0 -20
  249. package/tests/core/utilities/structures/accounts.ts +0 -80
  250. package/tests/core/utilities/structures/apps.ts +0 -21
  251. package/tests/core/utilities/structures/common.ts +0 -7
  252. package/tests/core/utilities/structures/db.ts +0 -12
  253. package/tests/core/utilities/structures/documents/index.ts +0 -1
  254. package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
  255. package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
  256. package/tests/core/utilities/structures/generator.ts +0 -3
  257. package/tests/core/utilities/structures/index.ts +0 -15
  258. package/tests/core/utilities/structures/koa.ts +0 -16
  259. package/tests/core/utilities/structures/licenses.ts +0 -190
  260. package/tests/core/utilities/structures/plugins.ts +0 -19
  261. package/tests/core/utilities/structures/quotas.ts +0 -72
  262. package/tests/core/utilities/structures/scim.ts +0 -80
  263. package/tests/core/utilities/structures/sso.ts +0 -118
  264. package/tests/core/utilities/structures/tenants.ts +0 -5
  265. package/tests/core/utilities/structures/userGroups.ts +0 -10
  266. package/tests/core/utilities/structures/users.ts +0 -89
  267. package/tests/core/utilities/testContainerUtils.ts +0 -165
  268. package/tests/core/utilities/utils/index.ts +0 -2
  269. package/tests/core/utilities/utils/queue.ts +0 -27
  270. package/tests/core/utilities/utils/time.ts +0 -3
  271. package/tests/extra/DBTestConfiguration.ts +0 -36
  272. package/tests/extra/index.ts +0 -2
  273. package/tests/extra/testEnv.ts +0 -95
  274. package/tests/index.ts +0 -2
  275. package/tests/jestEnv.ts +0 -10
  276. package/tests/jestSetup.ts +0 -36
@@ -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
- })
@@ -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
- }
@@ -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
- })
@@ -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
- }
@@ -1,8 +0,0 @@
1
- export enum JobQueue {
2
- AUTOMATION = "automationQueue",
3
- APP_BACKUP = "appBackupQueue",
4
- AUDIT_LOG = "auditLogQueue",
5
- SYSTEM_EVENT_QUEUE = "systemEventQueue",
6
- APP_MIGRATION = "appMigration",
7
- DOC_WRITETHROUGH_QUEUE = "docWritethroughQueue",
8
- }