@budibase/backend-core 2.9.19-alpha.0 → 2.9.20

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 (257) hide show
  1. package/dist/index.js +324 -266
  2. package/dist/index.js.map +4 -4
  3. package/dist/index.js.meta.json +1 -1
  4. package/dist/package.json +19 -4
  5. package/dist/plugins.js +1 -1
  6. package/dist/plugins.js.map +1 -1
  7. package/dist/plugins.js.meta.json +1 -1
  8. package/dist/src/security/permissions.d.ts +1 -1
  9. package/dist/tests.js +260 -222
  10. package/dist/tests.js.map +4 -4
  11. package/dist/tests.js.meta.json +1 -1
  12. package/package.json +19 -4
  13. package/__mocks__/aws-sdk.ts +0 -18
  14. package/dist/tsconfig.build.tsbuildinfo +0 -1
  15. package/jest-testcontainers-config.js +0 -8
  16. package/jest.config.ts +0 -35
  17. package/scripts/build.js +0 -6
  18. package/scripts/test.sh +0 -13
  19. package/src/accounts/accounts.ts +0 -82
  20. package/src/accounts/api.ts +0 -59
  21. package/src/accounts/index.ts +0 -1
  22. package/src/auth/auth.ts +0 -208
  23. package/src/auth/index.ts +0 -1
  24. package/src/auth/tests/auth.spec.ts +0 -14
  25. package/src/blacklist/blacklist.ts +0 -54
  26. package/src/blacklist/index.ts +0 -1
  27. package/src/blacklist/tests/blacklist.spec.ts +0 -46
  28. package/src/cache/appMetadata.ts +0 -88
  29. package/src/cache/base/index.ts +0 -92
  30. package/src/cache/generic.ts +0 -30
  31. package/src/cache/index.ts +0 -5
  32. package/src/cache/tests/writethrough.spec.ts +0 -138
  33. package/src/cache/user.ts +0 -69
  34. package/src/cache/writethrough.ts +0 -133
  35. package/src/configs/configs.ts +0 -257
  36. package/src/configs/index.ts +0 -1
  37. package/src/configs/tests/configs.spec.ts +0 -184
  38. package/src/constants/db.ts +0 -63
  39. package/src/constants/index.ts +0 -2
  40. package/src/constants/misc.ts +0 -50
  41. package/src/context/Context.ts +0 -14
  42. package/src/context/identity.ts +0 -58
  43. package/src/context/index.ts +0 -3
  44. package/src/context/mainContext.ts +0 -310
  45. package/src/context/tests/index.spec.ts +0 -147
  46. package/src/context/types.ts +0 -11
  47. package/src/db/Replication.ts +0 -84
  48. package/src/db/constants.ts +0 -10
  49. package/src/db/couch/DatabaseImpl.ts +0 -238
  50. package/src/db/couch/connections.ts +0 -77
  51. package/src/db/couch/index.ts +0 -5
  52. package/src/db/couch/pouchDB.ts +0 -97
  53. package/src/db/couch/pouchDump.ts +0 -0
  54. package/src/db/couch/utils.ts +0 -50
  55. package/src/db/db.ts +0 -39
  56. package/src/db/errors.ts +0 -14
  57. package/src/db/index.ts +0 -12
  58. package/src/db/lucene.ts +0 -732
  59. package/src/db/searchIndexes/index.ts +0 -1
  60. package/src/db/searchIndexes/searchIndexes.ts +0 -62
  61. package/src/db/tests/index.spec.js +0 -25
  62. package/src/db/tests/lucene.spec.ts +0 -298
  63. package/src/db/tests/pouch.spec.js +0 -62
  64. package/src/db/tests/utils.spec.ts +0 -63
  65. package/src/db/utils.ts +0 -207
  66. package/src/db/views.ts +0 -241
  67. package/src/docIds/conversions.ts +0 -59
  68. package/src/docIds/ids.ts +0 -113
  69. package/src/docIds/index.ts +0 -2
  70. package/src/docIds/newid.ts +0 -5
  71. package/src/docIds/params.ts +0 -174
  72. package/src/docUpdates/index.ts +0 -29
  73. package/src/environment.ts +0 -201
  74. package/src/errors/errors.ts +0 -119
  75. package/src/errors/index.ts +0 -1
  76. package/src/events/analytics.ts +0 -6
  77. package/src/events/asyncEvents/index.ts +0 -2
  78. package/src/events/asyncEvents/publisher.ts +0 -12
  79. package/src/events/asyncEvents/queue.ts +0 -22
  80. package/src/events/backfill.ts +0 -183
  81. package/src/events/documentId.ts +0 -56
  82. package/src/events/events.ts +0 -40
  83. package/src/events/identification.ts +0 -310
  84. package/src/events/index.ts +0 -14
  85. package/src/events/processors/AnalyticsProcessor.ts +0 -64
  86. package/src/events/processors/AuditLogsProcessor.ts +0 -93
  87. package/src/events/processors/LoggingProcessor.ts +0 -37
  88. package/src/events/processors/Processors.ts +0 -52
  89. package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -43
  90. package/src/events/processors/index.ts +0 -19
  91. package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
  92. package/src/events/processors/posthog/index.ts +0 -2
  93. package/src/events/processors/posthog/rateLimiting.ts +0 -106
  94. package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -168
  95. package/src/events/processors/types.ts +0 -1
  96. package/src/events/publishers/account.ts +0 -35
  97. package/src/events/publishers/app.ts +0 -155
  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 -24
  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 -88
  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/featureFlags/index.ts +0 -77
  122. package/src/featureFlags/tests/featureFlags.spec.ts +0 -85
  123. package/src/helpers.ts +0 -9
  124. package/src/index.ts +0 -53
  125. package/src/installation.ts +0 -107
  126. package/src/logging/alerts.ts +0 -26
  127. package/src/logging/correlation/correlation.ts +0 -13
  128. package/src/logging/correlation/index.ts +0 -1
  129. package/src/logging/correlation/middleware.ts +0 -17
  130. package/src/logging/index.ts +0 -4
  131. package/src/logging/pino/logger.ts +0 -232
  132. package/src/logging/pino/middleware.ts +0 -45
  133. package/src/logging/system.ts +0 -81
  134. package/src/logging/tests/system.spec.ts +0 -61
  135. package/src/middleware/adminOnly.ts +0 -9
  136. package/src/middleware/auditLog.ts +0 -6
  137. package/src/middleware/authenticated.ts +0 -193
  138. package/src/middleware/builderOnly.ts +0 -20
  139. package/src/middleware/builderOrAdmin.ts +0 -20
  140. package/src/middleware/csrf.ts +0 -81
  141. package/src/middleware/errorHandling.ts +0 -29
  142. package/src/middleware/index.ts +0 -21
  143. package/src/middleware/internalApi.ts +0 -23
  144. package/src/middleware/joi-validator.ts +0 -45
  145. package/src/middleware/matchers.ts +0 -47
  146. package/src/middleware/passport/datasource/google.ts +0 -95
  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 -154
  150. package/src/middleware/passport/sso/sso.ts +0 -165
  151. package/src/middleware/passport/sso/tests/google.spec.ts +0 -67
  152. package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -152
  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 -180
  158. package/src/middleware/tests/matchers.spec.ts +0 -134
  159. package/src/migrations/definitions.ts +0 -40
  160. package/src/migrations/index.ts +0 -2
  161. package/src/migrations/migrations.ts +0 -191
  162. package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
  163. package/src/migrations/tests/migrations.spec.ts +0 -64
  164. package/src/objectStore/buckets/app.ts +0 -40
  165. package/src/objectStore/buckets/global.ts +0 -29
  166. package/src/objectStore/buckets/index.ts +0 -3
  167. package/src/objectStore/buckets/plugins.ts +0 -71
  168. package/src/objectStore/buckets/tests/app.spec.ts +0 -171
  169. package/src/objectStore/buckets/tests/global.spec.ts +0 -74
  170. package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
  171. package/src/objectStore/cloudfront.ts +0 -41
  172. package/src/objectStore/index.ts +0 -3
  173. package/src/objectStore/objectStore.ts +0 -440
  174. package/src/objectStore/utils.ts +0 -27
  175. package/src/platform/index.ts +0 -3
  176. package/src/platform/platformDb.ts +0 -6
  177. package/src/platform/tenants.ts +0 -101
  178. package/src/platform/tests/tenants.spec.ts +0 -26
  179. package/src/platform/users.ts +0 -90
  180. package/src/plugin/index.ts +0 -1
  181. package/src/plugin/tests/validation.spec.ts +0 -83
  182. package/src/plugin/utils.ts +0 -156
  183. package/src/queue/constants.ts +0 -6
  184. package/src/queue/inMemoryQueue.ts +0 -141
  185. package/src/queue/index.ts +0 -2
  186. package/src/queue/listeners.ts +0 -195
  187. package/src/queue/queue.ts +0 -54
  188. package/src/redis/index.ts +0 -6
  189. package/src/redis/init.ts +0 -86
  190. package/src/redis/redis.ts +0 -308
  191. package/src/redis/redlockImpl.ts +0 -139
  192. package/src/redis/utils.ts +0 -117
  193. package/src/security/encryption.ts +0 -179
  194. package/src/security/permissions.ts +0 -159
  195. package/src/security/roles.ts +0 -420
  196. package/src/security/sessions.ts +0 -120
  197. package/src/security/tests/encryption.spec.ts +0 -31
  198. package/src/security/tests/permissions.spec.ts +0 -145
  199. package/src/security/tests/sessions.spec.ts +0 -12
  200. package/src/tenancy/db.ts +0 -6
  201. package/src/tenancy/index.ts +0 -2
  202. package/src/tenancy/tenancy.ts +0 -140
  203. package/src/tenancy/tests/tenancy.spec.ts +0 -184
  204. package/src/timers/index.ts +0 -1
  205. package/src/timers/timers.ts +0 -22
  206. package/src/users/db.ts +0 -460
  207. package/src/users/events.ts +0 -176
  208. package/src/users/index.ts +0 -4
  209. package/src/users/lookup.ts +0 -102
  210. package/src/users/users.ts +0 -276
  211. package/src/users/utils.ts +0 -55
  212. package/src/utils/hashing.ts +0 -14
  213. package/src/utils/index.ts +0 -3
  214. package/src/utils/stringUtils.ts +0 -8
  215. package/src/utils/tests/utils.spec.ts +0 -191
  216. package/src/utils/utils.ts +0 -239
  217. package/tests/core/logging.ts +0 -34
  218. package/tests/core/utilities/index.ts +0 -6
  219. package/tests/core/utilities/jestUtils.ts +0 -30
  220. package/tests/core/utilities/mocks/alerts.ts +0 -3
  221. package/tests/core/utilities/mocks/date.ts +0 -2
  222. package/tests/core/utilities/mocks/events.ts +0 -131
  223. package/tests/core/utilities/mocks/fetch.ts +0 -17
  224. package/tests/core/utilities/mocks/index.ts +0 -10
  225. package/tests/core/utilities/mocks/licenses.ts +0 -107
  226. package/tests/core/utilities/mocks/posthog.ts +0 -7
  227. package/tests/core/utilities/structures/Chance.ts +0 -20
  228. package/tests/core/utilities/structures/accounts.ts +0 -115
  229. package/tests/core/utilities/structures/apps.ts +0 -21
  230. package/tests/core/utilities/structures/common.ts +0 -7
  231. package/tests/core/utilities/structures/db.ts +0 -12
  232. package/tests/core/utilities/structures/documents/index.ts +0 -1
  233. package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
  234. package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
  235. package/tests/core/utilities/structures/generator.ts +0 -2
  236. package/tests/core/utilities/structures/index.ts +0 -15
  237. package/tests/core/utilities/structures/koa.ts +0 -16
  238. package/tests/core/utilities/structures/licenses.ts +0 -167
  239. package/tests/core/utilities/structures/plugins.ts +0 -19
  240. package/tests/core/utilities/structures/quotas.ts +0 -67
  241. package/tests/core/utilities/structures/scim.ts +0 -80
  242. package/tests/core/utilities/structures/shared.ts +0 -19
  243. package/tests/core/utilities/structures/sso.ts +0 -119
  244. package/tests/core/utilities/structures/tenants.ts +0 -5
  245. package/tests/core/utilities/structures/userGroups.ts +0 -10
  246. package/tests/core/utilities/structures/users.ts +0 -73
  247. package/tests/core/utilities/testContainerUtils.ts +0 -98
  248. package/tests/core/utilities/utils/index.ts +0 -1
  249. package/tests/core/utilities/utils/time.ts +0 -3
  250. package/tests/extra/DBTestConfiguration.ts +0 -36
  251. package/tests/extra/index.ts +0 -2
  252. package/tests/extra/testEnv.ts +0 -95
  253. package/tests/index.ts +0 -1
  254. package/tests/jestEnv.ts +0 -6
  255. package/tests/jestSetup.ts +0 -28
  256. package/tsconfig.build.json +0 -29
  257. package/tsconfig.json +0 -4
@@ -1,180 +0,0 @@
1
- import adminOnly from "../adminOnly"
2
- import builderOnly from "../builderOnly"
3
- import builderOrAdmin from "../builderOrAdmin"
4
- import { structures } from "../../../tests"
5
- import { ContextUser, ServiceType } from "@budibase/types"
6
- import { doInAppContext } from "../../context"
7
- import env from "../../environment"
8
- env._set("SERVICE_TYPE", ServiceType.APPS)
9
-
10
- const appId = "app_aaa"
11
- const basicUser = structures.users.user()
12
- const adminUser = structures.users.adminUser()
13
- const adminOnlyUser = structures.users.adminOnlyUser()
14
- const builderUser = structures.users.builderUser()
15
- const appBuilderUser = structures.users.appBuilderUser(appId)
16
-
17
- function buildUserCtx(user: ContextUser) {
18
- return {
19
- internal: false,
20
- user,
21
- throw: jest.fn(),
22
- } as any
23
- }
24
-
25
- function passed(throwFn: jest.Func, nextFn: jest.Func) {
26
- expect(throwFn).not.toBeCalled()
27
- expect(nextFn).toBeCalled()
28
- }
29
-
30
- function threw(throwFn: jest.Func) {
31
- // cant check next, the throw function doesn't actually throw - so it still continues
32
- expect(throwFn).toBeCalled()
33
- }
34
-
35
- describe("adminOnly middleware", () => {
36
- it("should allow admin user", () => {
37
- const ctx = buildUserCtx(adminUser),
38
- next = jest.fn()
39
- adminOnly(ctx, next)
40
- passed(ctx.throw, next)
41
- })
42
-
43
- it("should not allow basic user", () => {
44
- const ctx = buildUserCtx(basicUser),
45
- next = jest.fn()
46
- adminOnly(ctx, next)
47
- threw(ctx.throw)
48
- })
49
-
50
- it("should not allow builder user", () => {
51
- const ctx = buildUserCtx(builderUser),
52
- next = jest.fn()
53
- adminOnly(ctx, next)
54
- threw(ctx.throw)
55
- })
56
- })
57
-
58
- describe("builderOnly middleware", () => {
59
- it("should allow builder user", () => {
60
- const ctx = buildUserCtx(builderUser),
61
- next = jest.fn()
62
- builderOnly(ctx, next)
63
- passed(ctx.throw, next)
64
- })
65
-
66
- it("should allow app builder user", () => {
67
- const ctx = buildUserCtx(appBuilderUser),
68
- next = jest.fn()
69
- doInAppContext(appId, () => {
70
- builderOnly(ctx, next)
71
- })
72
- passed(ctx.throw, next)
73
- })
74
-
75
- it("should allow admin and builder user", () => {
76
- const ctx = buildUserCtx(adminUser),
77
- next = jest.fn()
78
- builderOnly(ctx, next)
79
- passed(ctx.throw, next)
80
- })
81
-
82
- it("should not allow admin user", () => {
83
- const ctx = buildUserCtx(adminOnlyUser),
84
- next = jest.fn()
85
- builderOnly(ctx, next)
86
- threw(ctx.throw)
87
- })
88
-
89
- it("should not allow app builder user to different app", () => {
90
- const ctx = buildUserCtx(appBuilderUser),
91
- next = jest.fn()
92
- doInAppContext("app_bbb", () => {
93
- builderOnly(ctx, next)
94
- })
95
- threw(ctx.throw)
96
- })
97
-
98
- it("should not allow basic user", () => {
99
- const ctx = buildUserCtx(basicUser),
100
- next = jest.fn()
101
- builderOnly(ctx, next)
102
- threw(ctx.throw)
103
- })
104
- })
105
-
106
- describe("builderOrAdmin middleware", () => {
107
- it("should allow builder user", () => {
108
- const ctx = buildUserCtx(builderUser),
109
- next = jest.fn()
110
- builderOrAdmin(ctx, next)
111
- passed(ctx.throw, next)
112
- })
113
-
114
- it("should allow builder and admin user", () => {
115
- const ctx = buildUserCtx(adminUser),
116
- next = jest.fn()
117
- builderOrAdmin(ctx, next)
118
- passed(ctx.throw, next)
119
- })
120
-
121
- it("should allow admin user", () => {
122
- const ctx = buildUserCtx(adminOnlyUser),
123
- next = jest.fn()
124
- builderOrAdmin(ctx, next)
125
- passed(ctx.throw, next)
126
- })
127
-
128
- it("should allow app builder user", () => {
129
- const ctx = buildUserCtx(appBuilderUser),
130
- next = jest.fn()
131
- doInAppContext(appId, () => {
132
- builderOrAdmin(ctx, next)
133
- })
134
- passed(ctx.throw, next)
135
- })
136
-
137
- it("should not allow basic user", () => {
138
- const ctx = buildUserCtx(basicUser),
139
- next = jest.fn()
140
- builderOrAdmin(ctx, next)
141
- threw(ctx.throw)
142
- })
143
- })
144
-
145
- describe("check service difference", () => {
146
- it("should not allow without app ID in apps", () => {
147
- env._set("SERVICE_TYPE", ServiceType.APPS)
148
- const appId = "app_a"
149
- const ctx = buildUserCtx({
150
- ...basicUser,
151
- builder: {
152
- apps: [appId],
153
- },
154
- })
155
- const next = jest.fn()
156
- doInAppContext(appId, () => {
157
- builderOnly(ctx, next)
158
- })
159
- passed(ctx.throw, next)
160
- doInAppContext("app_b", () => {
161
- builderOnly(ctx, next)
162
- })
163
- threw(ctx.throw)
164
- })
165
-
166
- it("should allow without app ID in worker", () => {
167
- env._set("SERVICE_TYPE", ServiceType.WORKER)
168
- const ctx = buildUserCtx({
169
- ...basicUser,
170
- builder: {
171
- apps: ["app_a"],
172
- },
173
- })
174
- const next = jest.fn()
175
- doInAppContext("app_b", () => {
176
- builderOnly(ctx, next)
177
- })
178
- passed(ctx.throw, next)
179
- })
180
- })
@@ -1,134 +0,0 @@
1
- import * as matchers from "../matchers"
2
- import { structures } from "../../../tests"
3
-
4
- describe("matchers", () => {
5
- it("matches by path and method", () => {
6
- const pattern = [
7
- {
8
- route: "/api/tests",
9
- method: "POST",
10
- },
11
- ]
12
- const ctx = structures.koa.newContext()
13
- ctx.request.url = "/api/tests"
14
- ctx.request.method = "POST"
15
-
16
- const built = matchers.buildMatcherRegex(pattern)
17
-
18
- expect(!!matchers.matches(ctx, built)).toBe(true)
19
- })
20
-
21
- it("wildcards path", () => {
22
- const pattern = [
23
- {
24
- route: "/api/tests",
25
- method: "POST",
26
- },
27
- ]
28
- const ctx = structures.koa.newContext()
29
- ctx.request.url = "/api/tests/id/something/else"
30
- ctx.request.method = "POST"
31
-
32
- const built = matchers.buildMatcherRegex(pattern)
33
-
34
- expect(!!matchers.matches(ctx, built)).toBe(true)
35
- })
36
-
37
- it("doesn't wildcard path with strict", () => {
38
- const pattern = [
39
- {
40
- route: "/api/tests",
41
- method: "POST",
42
- strict: true,
43
- },
44
- ]
45
- const ctx = structures.koa.newContext()
46
- ctx.request.url = "/api/tests/id/something/else"
47
- ctx.request.method = "POST"
48
-
49
- const built = matchers.buildMatcherRegex(pattern)
50
-
51
- expect(!!matchers.matches(ctx, built)).toBe(false)
52
- })
53
-
54
- it("matches with param", () => {
55
- const pattern = [
56
- {
57
- route: "/api/tests/:testId",
58
- method: "GET",
59
- },
60
- ]
61
- const ctx = structures.koa.newContext()
62
- ctx.request.url = "/api/tests/id"
63
- ctx.request.method = "GET"
64
-
65
- const built = matchers.buildMatcherRegex(pattern)
66
-
67
- expect(!!matchers.matches(ctx, built)).toBe(true)
68
- })
69
-
70
- // TODO: Support the below behaviour
71
- // Strict does not work when a param is present
72
- // it("matches with param with strict", () => {
73
- // const pattern = [{
74
- // route: "/api/tests/:testId",
75
- // method: "GET",
76
- // strict: true
77
- // }]
78
- // const ctx = structures.koa.newContext()
79
- // ctx.request.url = "/api/tests/id"
80
- // ctx.request.method = "GET"
81
- //
82
- // const built = matchers.buildMatcherRegex(pattern)
83
- //
84
- // expect(!!matchers.matches(ctx, built)).toBe(true)
85
- // })
86
-
87
- it("doesn't match by path", () => {
88
- const pattern = [
89
- {
90
- route: "/api/tests",
91
- method: "POST",
92
- },
93
- ]
94
- const ctx = structures.koa.newContext()
95
- ctx.request.url = "/api/unknown"
96
- ctx.request.method = "POST"
97
-
98
- const built = matchers.buildMatcherRegex(pattern)
99
-
100
- expect(!!matchers.matches(ctx, built)).toBe(false)
101
- })
102
-
103
- it("doesn't match by method", () => {
104
- const pattern = [
105
- {
106
- route: "/api/tests",
107
- method: "POST",
108
- },
109
- ]
110
- const ctx = structures.koa.newContext()
111
- ctx.request.url = "/api/tests"
112
- ctx.request.method = "GET"
113
-
114
- const built = matchers.buildMatcherRegex(pattern)
115
-
116
- expect(!!matchers.matches(ctx, built)).toBe(false)
117
- })
118
-
119
- it("matches by path and wildcard method", () => {
120
- const pattern = [
121
- {
122
- route: "/api/tests",
123
- method: "ALL",
124
- },
125
- ]
126
- const ctx = structures.koa.newContext()
127
- ctx.request.url = "/api/tests"
128
- ctx.request.method = "GET"
129
-
130
- const built = matchers.buildMatcherRegex(pattern)
131
-
132
- expect(!!matchers.matches(ctx, built)).toBe(true)
133
- })
134
- })
@@ -1,40 +0,0 @@
1
- import {
2
- MigrationType,
3
- MigrationName,
4
- MigrationDefinition,
5
- } from "@budibase/types"
6
-
7
- export const DEFINITIONS: MigrationDefinition[] = [
8
- {
9
- type: MigrationType.GLOBAL,
10
- name: MigrationName.USER_EMAIL_VIEW_CASING,
11
- },
12
- {
13
- type: MigrationType.GLOBAL,
14
- name: MigrationName.SYNC_QUOTAS,
15
- },
16
- {
17
- type: MigrationType.APP,
18
- name: MigrationName.APP_URLS,
19
- },
20
- {
21
- type: MigrationType.APP,
22
- name: MigrationName.EVENT_APP_BACKFILL,
23
- },
24
- {
25
- type: MigrationType.APP,
26
- name: MigrationName.TABLE_SETTINGS_LINKS_TO_ACTIONS,
27
- },
28
- {
29
- type: MigrationType.GLOBAL,
30
- name: MigrationName.EVENT_GLOBAL_BACKFILL,
31
- },
32
- {
33
- type: MigrationType.INSTALLATION,
34
- name: MigrationName.EVENT_INSTALLATION_BACKFILL,
35
- },
36
- {
37
- type: MigrationType.GLOBAL,
38
- name: MigrationName.GLOBAL_INFO_SYNC_USERS,
39
- },
40
- ]
@@ -1,2 +0,0 @@
1
- export * from "./migrations"
2
- export * from "./definitions"
@@ -1,191 +0,0 @@
1
- import { DEFAULT_TENANT_ID } from "../constants"
2
- import {
3
- DocumentType,
4
- StaticDatabases,
5
- getAllApps,
6
- getGlobalDBName,
7
- getDB,
8
- } from "../db"
9
- import environment from "../environment"
10
- import * as platform from "../platform"
11
- import * as context from "../context"
12
- import { DEFINITIONS } from "."
13
- import {
14
- Migration,
15
- MigrationOptions,
16
- MigrationType,
17
- MigrationNoOpOptions,
18
- App,
19
- } from "@budibase/types"
20
-
21
- export const getMigrationsDoc = async (db: any) => {
22
- // get the migrations doc
23
- try {
24
- return await db.get(DocumentType.MIGRATIONS)
25
- } catch (err: any) {
26
- if (err.status && err.status === 404) {
27
- return { _id: DocumentType.MIGRATIONS }
28
- } else {
29
- console.error(err)
30
- throw err
31
- }
32
- }
33
- }
34
-
35
- export const backPopulateMigrations = async (opts: MigrationNoOpOptions) => {
36
- // filter migrations to the type and populate a no-op migration
37
- const migrations: Migration[] = DEFINITIONS.filter(
38
- def => def.type === opts.type
39
- ).map(d => ({ ...d, fn: () => {} }))
40
- await runMigrations(migrations, { noOp: opts })
41
- }
42
-
43
- export const runMigration = async (
44
- migration: Migration,
45
- options: MigrationOptions = {}
46
- ) => {
47
- const migrationType = migration.type
48
- let tenantId: string | undefined
49
- if (migrationType !== MigrationType.INSTALLATION) {
50
- tenantId = context.getTenantId()
51
- }
52
- const migrationName = migration.name
53
- const silent = migration.silent
54
-
55
- const log = (message: string) => {
56
- if (!silent) {
57
- console.log(message)
58
- }
59
- }
60
-
61
- // get the db to store the migration in
62
- let dbNames: string[]
63
- if (migrationType === MigrationType.GLOBAL) {
64
- dbNames = [getGlobalDBName()]
65
- } else if (migrationType === MigrationType.APP) {
66
- if (options.noOp) {
67
- if (!options.noOp.appId) {
68
- throw new Error("appId is required for noOp app migration")
69
- }
70
- dbNames = [options.noOp.appId]
71
- } else {
72
- const apps = (await getAllApps(migration.appOpts)) as App[]
73
- dbNames = apps.map(app => app.appId)
74
- }
75
- } else if (migrationType === MigrationType.INSTALLATION) {
76
- dbNames = [StaticDatabases.PLATFORM_INFO.name]
77
- } else {
78
- throw new Error(`Unrecognised migration type [${migrationType}]`)
79
- }
80
-
81
- const length = dbNames.length
82
- let count = 0
83
-
84
- // run the migration against each db
85
- for (const dbName of dbNames) {
86
- count++
87
- const lengthStatement = length > 1 ? `[${count}/${length}]` : ""
88
-
89
- const db = getDB(dbName)
90
-
91
- try {
92
- const doc = await getMigrationsDoc(db)
93
-
94
- // the migration has already been run
95
- if (doc[migrationName]) {
96
- // check for force
97
- if (
98
- options.force &&
99
- options.force[migrationType] &&
100
- options.force[migrationType].includes(migrationName)
101
- ) {
102
- log(`[Migration: ${migrationName}] [DB: ${dbName}] Forcing`)
103
- } else {
104
- // no force, exit
105
- return
106
- }
107
- }
108
-
109
- // check if the migration is not a no-op
110
- if (!options.noOp) {
111
- log(
112
- `[Migration: ${migrationName}] [DB: ${dbName}] Running ${lengthStatement}`
113
- )
114
-
115
- if (migration.preventRetry) {
116
- // eagerly set the completion date
117
- // so that we never run this migration twice even upon failure
118
- doc[migrationName] = Date.now()
119
- const response = await db.put(doc)
120
- doc._rev = response.rev
121
- }
122
-
123
- // run the migration
124
- if (migrationType === MigrationType.APP) {
125
- await context.doInAppContext(db.name, async () => {
126
- await migration.fn(db)
127
- })
128
- } else {
129
- await migration.fn(db)
130
- }
131
-
132
- log(`[Migration: ${migrationName}] [DB: ${dbName}] Complete`)
133
- }
134
-
135
- // mark as complete
136
- doc[migrationName] = Date.now()
137
- await db.put(doc)
138
- } catch (err) {
139
- console.error(
140
- `[Migration: ${migrationName}] [DB: ${dbName}] Error: `,
141
- err
142
- )
143
- throw err
144
- }
145
- }
146
- }
147
-
148
- export const runMigrations = async (
149
- migrations: Migration[],
150
- options: MigrationOptions = {}
151
- ) => {
152
- let tenantIds
153
-
154
- if (environment.MULTI_TENANCY) {
155
- if (options.noOp) {
156
- tenantIds = [options.noOp.tenantId]
157
- } else if (!options.tenantIds || !options.tenantIds.length) {
158
- // run for all tenants
159
- tenantIds = await platform.tenants.getTenantIds()
160
- } else {
161
- tenantIds = options.tenantIds
162
- }
163
- } else {
164
- // single tenancy
165
- tenantIds = [DEFAULT_TENANT_ID]
166
- }
167
-
168
- if (tenantIds.length > 1) {
169
- console.log(`Checking migrations for ${tenantIds.length} tenants`)
170
- } else {
171
- console.log("Checking migrations")
172
- }
173
-
174
- let count = 0
175
- // for all tenants
176
- for (const tenantId of tenantIds) {
177
- count++
178
- if (tenantIds.length > 1) {
179
- console.log(`Progress [${count}/${tenantIds.length}]`)
180
- }
181
- // for all migrations
182
- for (const migration of migrations) {
183
- // run the migration
184
- await context.doInTenant(
185
- tenantId,
186
- async () => await runMigration(migration, options)
187
- )
188
- }
189
- }
190
- console.log("Migrations complete")
191
- }
@@ -1,11 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`migrations should match snapshot 1`] = `
4
- {
5
- "_id": "migrations",
6
- "_rev": "1-2f64479842a0513aa8b97f356b0b9127",
7
- "createdAt": "2020-01-01T00:00:00.000Z",
8
- "test": 1577836800000,
9
- "updatedAt": "2020-01-01T00:00:00.000Z",
10
- }
11
- `;
@@ -1,64 +0,0 @@
1
- import { testEnv, DBTestConfiguration } from "../../../tests/extra"
2
- import * as migrations from "../index"
3
- import * as context from "../../context"
4
- import { MigrationType } from "@budibase/types"
5
-
6
- testEnv.multiTenant()
7
-
8
- describe("migrations", () => {
9
- const config = new DBTestConfiguration()
10
-
11
- const migrationFunction = jest.fn()
12
-
13
- const MIGRATIONS = [
14
- {
15
- type: MigrationType.GLOBAL,
16
- name: "test" as any,
17
- fn: migrationFunction,
18
- },
19
- ]
20
-
21
- beforeEach(() => {
22
- config.newTenant()
23
- })
24
-
25
- afterEach(async () => {
26
- jest.clearAllMocks()
27
- })
28
-
29
- const migrate = () => {
30
- return migrations.runMigrations(MIGRATIONS, {
31
- tenantIds: [config.tenantId],
32
- })
33
- }
34
-
35
- it("should run a new migration", async () => {
36
- await config.doInTenant(async () => {
37
- await migrate()
38
- expect(migrationFunction).toHaveBeenCalled()
39
- const db = context.getGlobalDB()
40
- const doc = await migrations.getMigrationsDoc(db)
41
- expect(doc.test).toBeDefined()
42
- })
43
- })
44
-
45
- it("should match snapshot", async () => {
46
- await config.doInTenant(async () => {
47
- await migrate()
48
- const doc = await migrations.getMigrationsDoc(context.getGlobalDB())
49
- expect(doc).toMatchSnapshot()
50
- })
51
- })
52
-
53
- it("should skip a previously run migration", async () => {
54
- await config.doInTenant(async () => {
55
- const db = context.getGlobalDB()
56
- await migrate()
57
- const previousDoc = await migrations.getMigrationsDoc(db)
58
- await migrate()
59
- const currentDoc = await migrations.getMigrationsDoc(db)
60
- expect(migrationFunction).toHaveBeenCalledTimes(1)
61
- expect(currentDoc.test).toBe(previousDoc.test)
62
- })
63
- })
64
- })
@@ -1,40 +0,0 @@
1
- import env from "../../environment"
2
- import * as objectStore from "../objectStore"
3
- import * as cloudfront from "../cloudfront"
4
-
5
- /**
6
- * In production the client library is stored in the object store, however in development
7
- * we use the symlinked version produced by lerna, located in node modules. We link to this
8
- * via a specific endpoint (under /api/assets/client).
9
- * @param {string} appId In production we need the appId to look up the correct bucket, as the
10
- * version of the client lib may differ between apps.
11
- * @param {string} version The version to retrieve.
12
- * @return {string} The URL to be inserted into appPackage response or server rendered
13
- * app index file.
14
- */
15
- export const clientLibraryUrl = (appId: string, version: string) => {
16
- if (env.isProd()) {
17
- let file = `${objectStore.sanitizeKey(appId)}/budibase-client.js`
18
- if (env.CLOUDFRONT_CDN) {
19
- // append app version to bust the cache
20
- if (version) {
21
- file += `?v=${version}`
22
- }
23
- // don't need to use presigned for client with cloudfront
24
- // file is public
25
- return cloudfront.getUrl(file)
26
- } else {
27
- return objectStore.getPresignedUrl(env.APPS_BUCKET_NAME, file)
28
- }
29
- } else {
30
- return `/api/assets/client`
31
- }
32
- }
33
-
34
- export const getAppFileUrl = (s3Key: string) => {
35
- if (env.CLOUDFRONT_CDN) {
36
- return cloudfront.getPresignedUrl(s3Key)
37
- } else {
38
- return objectStore.getPresignedUrl(env.APPS_BUCKET_NAME, s3Key)
39
- }
40
- }
@@ -1,29 +0,0 @@
1
- import env from "../../environment"
2
- import * as context from "../../context"
3
- import * as objectStore from "../objectStore"
4
- import * as cloudfront from "../cloudfront"
5
-
6
- // URLs
7
-
8
- export const getGlobalFileUrl = (type: string, name: string, etag?: string) => {
9
- let file = getGlobalFileS3Key(type, name)
10
- if (env.CLOUDFRONT_CDN) {
11
- if (etag) {
12
- file = `${file}?etag=${etag}`
13
- }
14
- return cloudfront.getPresignedUrl(file)
15
- } else {
16
- return objectStore.getPresignedUrl(env.GLOBAL_BUCKET_NAME, file)
17
- }
18
- }
19
-
20
- // KEYS
21
-
22
- export const getGlobalFileS3Key = (type: string, name: string) => {
23
- let file = `${type}/${name}`
24
- if (env.MULTI_TENANCY) {
25
- const tenantId = context.getTenantId()
26
- file = `${tenantId}/${file}`
27
- }
28
- return file
29
- }
@@ -1,3 +0,0 @@
1
- export * from "./app"
2
- export * from "./global"
3
- export * from "./plugins"