@budibase/worker 2.2.12-alpha.5 → 2.2.12-alpha.50

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 (147) hide show
  1. package/coverage/clover.xml +498 -526
  2. package/coverage/coverage-final.json +83 -81
  3. package/coverage/lcov-report/index.html +127 -127
  4. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +33 -33
  5. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +20 -20
  6. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +1 -1
  7. package/coverage/lcov-report/src/api/controllers/global/events.ts.html +136 -0
  8. package/coverage/lcov-report/src/api/controllers/global/index.html +67 -52
  9. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +10 -10
  10. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +5 -5
  11. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +10 -10
  12. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +5 -5
  13. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +59 -20
  14. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +4 -4
  15. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +2 -2
  16. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +2 -2
  17. package/coverage/lcov-report/src/api/controllers/system/index.html +11 -11
  18. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +2 -2
  19. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +1 -1
  20. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +2 -2
  21. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +3 -3
  22. package/coverage/lcov-report/src/api/index.html +1 -1
  23. package/coverage/lcov-report/src/api/index.ts.html +19 -7
  24. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +4 -4
  25. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +10 -10
  26. package/coverage/lcov-report/src/api/routes/global/email.ts.html +4 -4
  27. package/coverage/lcov-report/src/api/routes/global/events.ts.html +109 -0
  28. package/coverage/lcov-report/src/api/routes/global/index.html +37 -22
  29. package/coverage/lcov-report/src/api/routes/global/license.ts.html +3 -3
  30. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +4 -4
  31. package/coverage/lcov-report/src/api/routes/global/self.ts.html +4 -4
  32. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +4 -4
  33. package/coverage/lcov-report/src/api/routes/global/users.ts.html +48 -6
  34. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +4 -4
  35. package/coverage/lcov-report/src/api/routes/index.html +7 -7
  36. package/coverage/lcov-report/src/api/routes/index.ts.html +11 -5
  37. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +4 -4
  38. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +4 -4
  39. package/coverage/lcov-report/src/api/routes/system/index.html +15 -15
  40. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +4 -4
  41. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +4 -4
  42. package/coverage/lcov-report/src/api/routes/system/status.ts.html +4 -4
  43. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +4 -4
  44. package/coverage/lcov-report/src/api/routes/validation/index.html +3 -3
  45. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +1 -1
  46. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +3 -3
  47. package/coverage/lcov-report/src/constants/index.html +15 -15
  48. package/coverage/lcov-report/src/constants/index.ts.html +43 -43
  49. package/coverage/lcov-report/src/constants/templates/index.html +15 -15
  50. package/coverage/lcov-report/src/constants/templates/index.ts.html +14 -14
  51. package/coverage/lcov-report/src/db/index.html +3 -3
  52. package/coverage/lcov-report/src/db/index.ts.html +4 -4
  53. package/coverage/lcov-report/src/environment.ts.html +19 -19
  54. package/coverage/lcov-report/src/index.html +27 -27
  55. package/coverage/lcov-report/src/index.ts.html +19 -16
  56. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +2 -2
  57. package/coverage/lcov-report/src/middleware/index.html +1 -1
  58. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +7 -7
  59. package/coverage/lcov-report/src/migrations/functions/index.html +11 -11
  60. package/coverage/lcov-report/src/migrations/index.html +15 -15
  61. package/coverage/lcov-report/src/migrations/index.ts.html +12 -12
  62. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +9 -9
  63. package/coverage/lcov-report/src/sdk/accounts/index.html +13 -13
  64. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +1 -1
  65. package/coverage/lcov-report/src/sdk/index.html +5 -5
  66. package/coverage/lcov-report/src/sdk/index.ts.html +4 -4
  67. package/coverage/lcov-report/src/sdk/users/events.ts.html +16 -16
  68. package/coverage/lcov-report/src/sdk/users/index.html +29 -29
  69. package/coverage/lcov-report/src/sdk/users/index.ts.html +1 -1
  70. package/coverage/lcov-report/src/sdk/users/users.ts.html +49 -43
  71. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +26 -26
  72. package/coverage/lcov-report/src/tests/api/accounts.ts.html +2 -2
  73. package/coverage/lcov-report/src/tests/api/auth.ts.html +2 -2
  74. package/coverage/lcov-report/src/tests/api/base.ts.html +3 -3
  75. package/coverage/lcov-report/src/tests/api/configs.ts.html +2 -2
  76. package/coverage/lcov-report/src/tests/api/email.ts.html +2 -2
  77. package/coverage/lcov-report/src/tests/api/environment.ts.html +2 -2
  78. package/coverage/lcov-report/src/tests/api/groups.ts.html +2 -2
  79. package/coverage/lcov-report/src/tests/api/index.html +42 -42
  80. package/coverage/lcov-report/src/tests/api/index.ts.html +2 -2
  81. package/coverage/lcov-report/src/tests/api/license.ts.html +7 -7
  82. package/coverage/lcov-report/src/tests/api/migrations.ts.html +3 -3
  83. package/coverage/lcov-report/src/tests/api/restore.ts.html +3 -3
  84. package/coverage/lcov-report/src/tests/api/roles.ts.html +7 -7
  85. package/coverage/lcov-report/src/tests/api/self.ts.html +2 -2
  86. package/coverage/lcov-report/src/tests/api/status.ts.html +2 -2
  87. package/coverage/lcov-report/src/tests/api/templates.ts.html +10 -10
  88. package/coverage/lcov-report/src/tests/api/tenants.ts.html +6 -6
  89. package/coverage/lcov-report/src/tests/api/users.ts.html +13 -10
  90. package/coverage/lcov-report/src/tests/controllers.ts.html +11 -11
  91. package/coverage/lcov-report/src/tests/index.html +34 -34
  92. package/coverage/lcov-report/src/tests/index.ts.html +15 -51
  93. package/coverage/lcov-report/src/tests/mocks/email.ts.html +2 -2
  94. package/coverage/lcov-report/src/tests/mocks/index.html +5 -5
  95. package/coverage/lcov-report/src/tests/mocks/index.ts.html +5 -5
  96. package/coverage/lcov-report/src/tests/structures/configs.ts.html +7 -7
  97. package/coverage/lcov-report/src/tests/structures/groups.ts.html +2 -2
  98. package/coverage/lcov-report/src/tests/structures/index.html +15 -15
  99. package/coverage/lcov-report/src/tests/structures/index.ts.html +10 -10
  100. package/coverage/lcov-report/src/tests/structures/users.ts.html +8 -8
  101. package/coverage/lcov-report/src/utilities/appService.ts.html +38 -11
  102. package/coverage/lcov-report/src/utilities/email.ts.html +17 -17
  103. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +2 -2
  104. package/coverage/lcov-report/src/utilities/index.html +27 -27
  105. package/coverage/lcov-report/src/utilities/index.ts.html +2 -2
  106. package/coverage/lcov-report/src/utilities/redis.ts.html +14 -14
  107. package/coverage/lcov-report/src/utilities/templates.ts.html +3 -3
  108. package/coverage/lcov-report/src/utilities/users.ts.html +2 -2
  109. package/coverage/lcov.info +1658 -1644
  110. package/jest.config.ts +5 -2
  111. package/package.json +8 -6
  112. package/src/api/controllers/global/auth.ts +1 -1
  113. package/src/api/controllers/global/events.ts +17 -0
  114. package/src/api/controllers/global/users.ts +13 -0
  115. package/src/api/index.ts +4 -0
  116. package/src/api/routes/global/auth.ts +1 -1
  117. package/src/api/routes/global/configs.ts +7 -7
  118. package/src/api/routes/global/email.ts +1 -1
  119. package/src/api/routes/global/events.ts +8 -0
  120. package/src/api/routes/global/roles.ts +1 -1
  121. package/src/api/routes/global/self.ts +1 -1
  122. package/src/api/routes/global/templates.ts +1 -1
  123. package/src/api/routes/global/tests/templates.spec.ts +0 -8
  124. package/src/api/routes/global/users.ts +15 -1
  125. package/src/api/routes/global/workspaces.ts +1 -1
  126. package/src/api/routes/index.ts +2 -0
  127. package/src/api/routes/system/accounts.ts +1 -1
  128. package/src/api/routes/system/environment.ts +1 -1
  129. package/src/api/routes/system/migrations.ts +1 -1
  130. package/src/api/routes/system/restore.ts +1 -1
  131. package/src/api/routes/system/status.ts +1 -1
  132. package/src/api/routes/system/tenants.ts +1 -1
  133. package/src/api/routes/system/tests/environment.spec.ts +1 -1
  134. package/src/db/index.ts +1 -1
  135. package/src/environment.ts +1 -1
  136. package/src/index.ts +4 -3
  137. package/src/middleware/cloudRestricted.ts +1 -1
  138. package/src/sdk/users/users.ts +5 -3
  139. package/src/tests/TestConfiguration.ts +2 -2
  140. package/src/tests/api/users.ts +2 -1
  141. package/src/tests/index.ts +6 -18
  142. package/src/tests/jestEnv.ts +11 -0
  143. package/src/tests/jestSetup.ts +0 -14
  144. package/src/tests/mocks/index.ts +1 -1
  145. package/src/tests/structures/index.ts +4 -4
  146. package/src/utilities/appService.ts +12 -3
  147. package/tsconfig.json +2 -1
package/jest.config.ts CHANGED
@@ -2,11 +2,14 @@ import { Config } from "@jest/types"
2
2
  import * as fs from "fs"
3
3
 
4
4
  const config: Config.InitialOptions = {
5
- preset: "ts-jest",
6
5
  testEnvironment: "node",
7
- setupFiles: ["./src/tests/jestSetup.ts"],
6
+ setupFiles: ["./src/tests/jestEnv.ts"],
7
+ setupFilesAfterEnv: ["./src/tests/jestSetup.ts"],
8
8
  collectCoverageFrom: ["src/**/*.{js,ts}"],
9
9
  coverageReporters: ["lcov", "json", "clover"],
10
+ transform: {
11
+ "^.+\\.ts?$": "@swc/jest",
12
+ },
10
13
  }
11
14
 
12
15
  if (!process.env.CI) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.2.12-alpha.5",
4
+ "version": "2.2.12-alpha.50",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -36,10 +36,10 @@
36
36
  "author": "Budibase",
37
37
  "license": "GPL-3.0",
38
38
  "dependencies": {
39
- "@budibase/backend-core": "2.2.12-alpha.5",
40
- "@budibase/pro": "2.2.12-alpha.4",
41
- "@budibase/string-templates": "2.2.12-alpha.5",
42
- "@budibase/types": "2.2.12-alpha.5",
39
+ "@budibase/backend-core": "2.2.12-alpha.50",
40
+ "@budibase/pro": "2.2.12-alpha.49",
41
+ "@budibase/string-templates": "2.2.12-alpha.50",
42
+ "@budibase/types": "2.2.12-alpha.50",
43
43
  "@koa/router": "8.0.8",
44
44
  "@sentry/node": "6.17.7",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
@@ -70,6 +70,8 @@
70
70
  "server-destroy": "1.0.1"
71
71
  },
72
72
  "devDependencies": {
73
+ "@swc/core": "^1.3.25",
74
+ "@swc/jest": "^0.2.24",
73
75
  "@types/jest": "26.0.23",
74
76
  "@types/jsonwebtoken": "8.5.1",
75
77
  "@types/koa": "2.13.4",
@@ -95,5 +97,5 @@
95
97
  "typescript": "4.7.3",
96
98
  "update-dotenv": "1.1.1"
97
99
  },
98
- "gitHead": "1641ca6eacbaa560598d76801c2d4af1c3301f54"
100
+ "gitHead": "b6ca342ed964e28404648db0dc2ff63b82347a2a"
99
101
  }
@@ -13,7 +13,7 @@ import { isEmailConfigured, sendEmail } from "../../../utilities/email"
13
13
  import { checkResetPasswordCode } from "../../../utilities/redis"
14
14
  import env from "../../../environment"
15
15
  import sdk from "../../../sdk"
16
- import { Config, ConfigType, User } from "@budibase/types"
16
+ import { ConfigType, User } from "@budibase/types"
17
17
 
18
18
  const { setCookie, getCookie, clearCookie, hash, platformLogout } = utils
19
19
  const { Cookie, Header } = constants
@@ -0,0 +1,17 @@
1
+ import {
2
+ UserCtx,
3
+ PostEventPublishRequest,
4
+ EventPublishType,
5
+ } from "@budibase/types"
6
+ import { events } from "@budibase/backend-core"
7
+
8
+ export async function publish(ctx: UserCtx<PostEventPublishRequest, void>) {
9
+ switch (ctx.request.body.type) {
10
+ case EventPublishType.ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED:
11
+ await events.environmentVariable.upgradePanelOpened(ctx.user._id!)
12
+ break
13
+ default:
14
+ ctx.throw(400, "Invalid publish event type.")
15
+ }
16
+ ctx.status = 200
17
+ }
@@ -210,6 +210,19 @@ export const inviteMultiple = async (ctx: any) => {
210
210
  ctx.body = await sdk.users.invite(request)
211
211
  }
212
212
 
213
+ export const checkInvite = async (ctx: any) => {
214
+ const { code } = ctx.params
215
+ let invite
216
+ try {
217
+ invite = await checkInviteCode(code, false)
218
+ } catch (e) {
219
+ ctx.throw(400, "There was a problem with the invite")
220
+ }
221
+ ctx.body = {
222
+ email: invite.email,
223
+ }
224
+ }
225
+
213
226
  export const inviteAccept = async (ctx: any) => {
214
227
  const { inviteCode, password, firstName, lastName } = ctx.request.body
215
228
  try {
package/src/api/index.ts CHANGED
@@ -62,6 +62,10 @@ const PUBLIC_ENDPOINTS = [
62
62
  route: "/api/system/restored",
63
63
  method: "POST",
64
64
  },
65
+ {
66
+ route: "/api/global/users/invite",
67
+ method: "GET",
68
+ },
65
69
  ]
66
70
 
67
71
  const NO_TENANCY_ENDPOINTS = [
@@ -85,4 +85,4 @@ router
85
85
  .get("/api/global/auth/oidc/callback", authController.oidcAuth)
86
86
  .get("/api/admin/auth/oidc/callback", authController.oidcAuth)
87
87
 
88
- export = router
88
+ export default router
@@ -34,8 +34,8 @@ function settingValidation() {
34
34
  function googleValidation() {
35
35
  // prettier-ignore
36
36
  return Joi.object({
37
- clientID: Joi.string().required(),
38
- clientSecret: Joi.string().required(),
37
+ clientID: Joi.when('activated', { is: true, then: Joi.string().required() }),
38
+ clientSecret: Joi.when('activated', { is: true, then: Joi.string().required() }),
39
39
  activated: Joi.boolean().required(),
40
40
  }).unknown(true)
41
41
  }
@@ -45,12 +45,12 @@ function oidcValidation() {
45
45
  return Joi.object({
46
46
  configs: Joi.array().items(
47
47
  Joi.object({
48
- clientID: Joi.string().required(),
49
- clientSecret: Joi.string().required(),
50
- configUrl: Joi.string().required(),
48
+ clientID: Joi.when('activated', { is: true, then: Joi.string().required() }),
49
+ clientSecret: Joi.when('activated', { is: true, then: Joi.string().required() }),
50
+ configUrl: Joi.when('activated', { is: true, then: Joi.string().required() }),
51
51
  logo: Joi.string().allow("", null),
52
52
  name: Joi.string().allow("", null),
53
- uuid: Joi.string().required(),
53
+ uuid: Joi.when('activated', { is: true, then: Joi.string().required() }),
54
54
  activated: Joi.boolean().required(),
55
55
  scopes: Joi.array().optional()
56
56
  })
@@ -121,4 +121,4 @@ router
121
121
  controller.upload
122
122
  )
123
123
 
124
- export = router
124
+ export default router
@@ -33,4 +33,4 @@ router.post(
33
33
  controller.sendEmail
34
34
  )
35
35
 
36
- export = router
36
+ export default router
@@ -0,0 +1,8 @@
1
+ import Router from "@koa/router"
2
+ import * as controller from "../../controllers/global/events"
3
+
4
+ const router: Router = new Router()
5
+
6
+ router.post("/api/global/event/publish", controller.publish)
7
+
8
+ export default router
@@ -13,4 +13,4 @@ router
13
13
  controller.removeAppRole
14
14
  )
15
15
 
16
- export = router
16
+ export default router
@@ -15,4 +15,4 @@ router
15
15
  controller.updateSelf
16
16
  )
17
17
 
18
- export = router
18
+ export default router
@@ -34,4 +34,4 @@ router
34
34
  .get("/api/global/template/:id", controller.find)
35
35
  .delete("/api/global/template/:id/:rev", adminOnly, controller.destroy)
36
36
 
37
- export = router
37
+ export default router
@@ -1,17 +1,9 @@
1
- import {
2
- addBaseTemplates,
3
- EmailTemplates,
4
- getTemplates,
5
- } from "../../../../constants/templates"
6
1
  import {
7
2
  EmailTemplatePurpose,
8
3
  TemplateMetadata,
9
- TemplateMetadataNames,
10
4
  TemplateType,
11
5
  } from "../../../../constants"
12
6
  import { TestConfiguration } from "../../../../tests"
13
- import { join } from "path"
14
- import { readStaticFile } from "../../../../../src/utilities/fileSystem"
15
7
 
16
8
  // TODO
17
9
 
@@ -38,6 +38,13 @@ function buildInviteMultipleValidation() {
38
38
  ))
39
39
  }
40
40
 
41
+ function buildInviteLookupValidation() {
42
+ // prettier-ignore
43
+ return auth.joiValidator.params(Joi.object({
44
+ code: Joi.string().required()
45
+ }).unknown(true))
46
+ }
47
+
41
48
  const createUserAdminOnly = (ctx: any, next: any) => {
42
49
  if (!ctx.request.body._id) {
43
50
  return auth.adminOnly(ctx, next)
@@ -51,6 +58,8 @@ function buildInviteAcceptValidation() {
51
58
  return auth.joiValidator.body(Joi.object({
52
59
  inviteCode: Joi.string().required(),
53
60
  password: Joi.string().required(),
61
+ firstName: Joi.string().required(),
62
+ lastName: Joi.string().optional(),
54
63
  }).required().unknown(true))
55
64
  }
56
65
 
@@ -91,6 +100,11 @@ router
91
100
  )
92
101
 
93
102
  // non-global endpoints
103
+ .get(
104
+ "/api/global/users/invite/:code",
105
+ buildInviteLookupValidation(),
106
+ controller.checkInvite
107
+ )
94
108
  .post(
95
109
  "/api/global/users/invite/accept",
96
110
  buildInviteAcceptValidation(),
@@ -113,4 +127,4 @@ router
113
127
  selfController.updateSelf
114
128
  )
115
129
 
116
- export = router
130
+ export default router
@@ -34,4 +34,4 @@ router
34
34
  .get("/api/global/workspaces", controller.fetch)
35
35
  .get("/api/global/workspaces/:id", controller.find)
36
36
 
37
- export = router
37
+ export default router
@@ -7,6 +7,7 @@ import templateRoutes from "./global/templates"
7
7
  import emailRoutes from "./global/email"
8
8
  import authRoutes from "./global/auth"
9
9
  import roleRoutes from "./global/roles"
10
+ import eventRoutes from "./global/events"
10
11
  import environmentRoutes from "./system/environment"
11
12
  import tenantsRoutes from "./system/tenants"
12
13
  import statusRoutes from "./system/status"
@@ -34,4 +35,5 @@ export const routes: Router[] = [
34
35
  migrationRoutes,
35
36
  accountRoutes,
36
37
  restoreRoutes,
38
+ eventRoutes,
37
39
  ]
@@ -16,4 +16,4 @@ router
16
16
  controller.destroy
17
17
  )
18
18
 
19
- export = router
19
+ export default router
@@ -5,4 +5,4 @@ const router: Router = new Router()
5
5
 
6
6
  router.get("/api/system/environment", controller.fetch)
7
7
 
8
- export = router
8
+ export default router
@@ -16,4 +16,4 @@ router
16
16
  migrationsController.fetchDefinitions
17
17
  )
18
18
 
19
- export = router
19
+ export default router
@@ -5,4 +5,4 @@ const router: Router = new Router()
5
5
 
6
6
  router.post("/api/system/restored", controller.systemRestored)
7
7
 
8
- export = router
8
+ export default router
@@ -5,4 +5,4 @@ const router: Router = new Router()
5
5
 
6
6
  router.get("/api/system/status", controller.fetch)
7
7
 
8
- export = router
8
+ export default router
@@ -10,4 +10,4 @@ router.delete(
10
10
  controller.delete
11
11
  )
12
12
 
13
- export = router
13
+ export default router
@@ -20,7 +20,7 @@ describe("/api/system/environment", () => {
20
20
  const env = await config.api.environment.getEnvironment()
21
21
  expect(env.body).toEqual({
22
22
  cloud: true,
23
- disableAccountPortal: false,
23
+ disableAccountPortal: 0,
24
24
  isDev: false,
25
25
  multiTenancy: true,
26
26
  })
package/src/db/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import core from "@budibase/backend-core"
1
+ import * as core from "@budibase/backend-core"
2
2
  import env from "../environment"
3
3
 
4
4
  export const init = () => {
@@ -98,4 +98,4 @@ for (let [key, value] of Object.entries(environment)) {
98
98
  }
99
99
  }
100
100
 
101
- export = environment
101
+ export default environment
package/src/index.ts CHANGED
@@ -14,7 +14,7 @@ import { Event } from "@sentry/types/dist/event"
14
14
  import Application from "koa"
15
15
  import { bootstrap } from "global-agent"
16
16
  import * as db from "./db"
17
- import { auth, logging, events, pinoSettings } from "@budibase/backend-core"
17
+ import { auth, logging, events, middleware } from "@budibase/backend-core"
18
18
  db.init()
19
19
  import Koa from "koa"
20
20
  import koaBody from "koa-body"
@@ -36,7 +36,8 @@ app.keys = ["secret", "key"]
36
36
  // set up top level koa middleware
37
37
  app.use(koaBody({ multipart: true }))
38
38
  app.use(koaSession(app))
39
- app.use(logger(pinoSettings()))
39
+ app.use(middleware.logging)
40
+ app.use(logger(logging.pinoSettings()))
40
41
 
41
42
  // authentication
42
43
  app.use(auth.passport.initialize())
@@ -82,7 +83,7 @@ const shutdown = () => {
82
83
  server.destroy()
83
84
  }
84
85
 
85
- export = server.listen(parseInt(env.PORT || "4002"), async () => {
86
+ export default server.listen(parseInt(env.PORT || "4002"), async () => {
86
87
  console.log(`Worker running on ${JSON.stringify(server.address())}`)
87
88
  await redis.init()
88
89
  })
@@ -6,7 +6,7 @@ import { BBContext } from "@budibase/types"
6
6
  * This is a restricted endpoint in the cloud.
7
7
  * Ensure that the correct API key has been supplied.
8
8
  */
9
- export = async (ctx: BBContext, next: any) => {
9
+ export default async (ctx: BBContext, next: any) => {
10
10
  if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
11
11
  const apiKey = ctx.request.headers[constants.Header.API_KEY]
12
12
  if (apiKey !== env.INTERNAL_API_KEY) {
@@ -31,6 +31,7 @@ import {
31
31
  SearchUsersRequest,
32
32
  User,
33
33
  ThirdPartyUser,
34
+ isUser,
34
35
  } from "@budibase/types"
35
36
  import { sendEmail } from "../../utilities/email"
36
37
  import { EmailTemplatePurpose } from "../../constants"
@@ -265,8 +266,9 @@ export const save = async (
265
266
  await eventHelpers.handleSaveEvents(builtUser, dbUser)
266
267
  await addTenant(tenantId, _id, email)
267
268
  await cache.user.invalidateUser(response.id)
269
+
268
270
  // let server know to sync user
269
- await apps.syncUserInApps(_id)
271
+ await apps.syncUserInApps(_id, dbUser)
270
272
 
271
273
  await Promise.all(groupPromises)
272
274
 
@@ -572,7 +574,7 @@ export const destroy = async (id: string, currentUser: any) => {
572
574
  await cache.user.invalidateUser(userId)
573
575
  await sessions.invalidateSessions(userId, { reason: "deletion" })
574
576
  // let server know to sync user
575
- await apps.syncUserInApps(userId)
577
+ await apps.syncUserInApps(userId, dbUser)
576
578
  }
577
579
 
578
580
  const bulkDeleteProcessing = async (dbUser: User) => {
@@ -582,7 +584,7 @@ const bulkDeleteProcessing = async (dbUser: User) => {
582
584
  await cache.user.invalidateUser(userId)
583
585
  await sessions.invalidateSessions(userId, { reason: "bulk-deletion" })
584
586
  // let server know to sync user
585
- await apps.syncUserInApps(userId)
587
+ await apps.syncUserInApps(userId, dbUser)
586
588
  }
587
589
 
588
590
  export const invite = async (
@@ -51,7 +51,7 @@ class TestConfiguration {
51
51
 
52
52
  if (opts.openServer) {
53
53
  env.PORT = "0" // random port
54
- this.server = require("../index")
54
+ this.server = require("../index").default
55
55
  // we need the request for logging in, involves cookies, hard to fake
56
56
  this.request = supertest(this.server)
57
57
  }
@@ -327,4 +327,4 @@ class TestConfiguration {
327
327
  }
328
328
  }
329
329
 
330
- export = TestConfiguration
330
+ export default TestConfiguration
@@ -5,7 +5,7 @@ import {
5
5
  User,
6
6
  CreateAdminUserRequest,
7
7
  } from "@budibase/types"
8
- import * as structures from "../structures"
8
+ import structures from "../structures"
9
9
  import { generator } from "@budibase/backend-core/tests"
10
10
  import TestConfiguration from "../TestConfiguration"
11
11
  import { TestAPI, TestAPIOpts } from "./base"
@@ -48,6 +48,7 @@ export class UserAPI extends TestAPI {
48
48
  .send({
49
49
  password: "newpassword",
50
50
  inviteCode: code,
51
+ firstName: "Ted",
51
52
  })
52
53
  .expect("Content-Type", /json/)
53
54
  .expect(200)
@@ -1,18 +1,6 @@
1
- import mocks from "./mocks"
2
- import { generator } from "@budibase/backend-core/tests"
3
- import TestConfiguration from "./TestConfiguration"
4
- import structures from "./structures"
5
- import API from "./api"
6
- import { v4 as uuid } from "uuid"
7
-
8
- const pkg = {
9
- structures,
10
- generator,
11
- uuid,
12
- TENANT_1: structures.TENANT_1,
13
- mocks,
14
- TestConfiguration,
15
- API,
16
- }
17
-
18
- export = pkg
1
+ export { default as mocks } from "./mocks"
2
+ export { generator } from "@budibase/backend-core/tests"
3
+ export { default as TestConfiguration } from "./TestConfiguration"
4
+ export { default as structures } from "./structures"
5
+ export { default as API } from "./api"
6
+ export { v4 as uuid } from "uuid"
@@ -0,0 +1,11 @@
1
+ process.env.SELF_HOSTED = "0"
2
+ process.env.NODE_ENV = "jest"
3
+ process.env.JWT_SECRET = "test-jwtsecret"
4
+ process.env.LOG_LEVEL = "silent"
5
+ process.env.MULTI_TENANCY = "1"
6
+ process.env.MINIO_URL = "http://localhost"
7
+ process.env.MINIO_ACCESS_KEY = "test"
8
+ process.env.MINIO_SECRET_KEY = "test"
9
+ process.env.PLATFORM_URL = "http://localhost:10000"
10
+ process.env.INTERNAL_API_KEY = "tet"
11
+ process.env.DISABLE_ACCOUNT_PORTAL = "0"
@@ -1,17 +1,3 @@
1
- import env from "../environment"
2
-
3
- env._set("SELF_HOSTED", "0")
4
- env._set("NODE_ENV", "jest")
5
- env._set("JWT_SECRET", "test-jwtsecret")
6
- env._set("LOG_LEVEL", "silent")
7
- env._set("MULTI_TENANCY", true)
8
- env._set("MINIO_URL", "http://localhost")
9
- env._set("MINIO_ACCESS_KEY", "test")
10
- env._set("MINIO_SECRET_KEY", "test")
11
- env._set("PLATFORM_URL", "http://localhost:10000")
12
- env._set("INTERNAL_API_KEY", "test")
13
- env._set("DISABLE_ACCOUNT_PORTAL", false)
14
-
15
1
  import { mocks } from "@budibase/backend-core/tests"
16
2
 
17
3
  // must explicitly enable fetch mock
@@ -1,7 +1,7 @@
1
1
  import * as email from "./email"
2
2
  import { mocks } from "@budibase/backend-core/tests"
3
3
 
4
- export = {
4
+ export default {
5
5
  email,
6
6
  ...mocks,
7
7
  }
@@ -4,9 +4,9 @@ import * as users from "./users"
4
4
  import * as groups from "./groups"
5
5
  import { v4 as uuid } from "uuid"
6
6
 
7
- const TENANT_ID = "default"
8
- const TENANT_1 = "tenant1"
9
- const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
7
+ export const TENANT_ID = "default"
8
+ export const TENANT_1 = "tenant1"
9
+ export const CSRF_TOKEN = "e3727778-7af0-4226-b5eb-f43cbe60a306"
10
10
 
11
11
  const pkg = {
12
12
  ...structures,
@@ -19,4 +19,4 @@ const pkg = {
19
19
  groups,
20
20
  }
21
21
 
22
- export = pkg
22
+ export default pkg
@@ -1,7 +1,8 @@
1
1
  import fetch from "node-fetch"
2
- import { constants, tenancy } from "@budibase/backend-core"
2
+ import { constants, tenancy, logging } from "@budibase/backend-core"
3
3
  import { checkSlashesInUrl } from "../utilities"
4
4
  import env from "../environment"
5
+ import { SyncUserRequest, User } from "@budibase/types"
5
6
 
6
7
  async function makeAppRequest(url: string, method: string, body: any) {
7
8
  if (env.isTest()) {
@@ -17,14 +18,22 @@ async function makeAppRequest(url: string, method: string, body: any) {
17
18
  request.body = JSON.stringify(body)
18
19
  }
19
20
  request.method = method
21
+
22
+ // add x-budibase-correlation-id header
23
+ logging.correlation.setHeader(request.headers)
24
+
20
25
  return fetch(checkSlashesInUrl(env.APPS_URL + url), request)
21
26
  }
22
27
 
23
- export async function syncUserInApps(userId: string) {
28
+ export async function syncUserInApps(userId: string, previousUser?: User) {
29
+ const body: SyncUserRequest = {
30
+ previousUser,
31
+ }
32
+
24
33
  const response = await makeAppRequest(
25
34
  `/api/users/metadata/sync/${userId}`,
26
35
  "POST",
27
- {}
36
+ body
28
37
  )
29
38
  if (response && response.status !== 200) {
30
39
  throw "Unable to sync user."
package/tsconfig.json CHANGED
@@ -13,7 +13,8 @@
13
13
  }
14
14
  },
15
15
  "ts-node": {
16
- "require": ["tsconfig-paths/register"]
16
+ "require": ["tsconfig-paths/register"],
17
+ "swc": true
17
18
  },
18
19
  "references": [
19
20
  { "path": "../types" },