@budibase/worker 2.2.12-alpha.7 → 2.2.12-alpha.71

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 (126) hide show
  1. package/Dockerfile +1 -1
  2. package/coverage/clover.xml +379 -345
  3. package/coverage/coverage-final.json +12 -10
  4. package/coverage/lcov-report/index.html +44 -44
  5. package/coverage/lcov-report/src/api/controllers/global/auth.ts.html +1 -1
  6. package/coverage/lcov-report/src/api/controllers/global/configs.ts.html +4 -4
  7. package/coverage/lcov-report/src/api/controllers/global/email.ts.html +1 -1
  8. package/coverage/lcov-report/src/api/controllers/global/events.ts.html +136 -0
  9. package/coverage/lcov-report/src/api/controllers/global/index.html +34 -19
  10. package/coverage/lcov-report/src/api/controllers/global/license.ts.html +1 -1
  11. package/coverage/lcov-report/src/api/controllers/global/roles.ts.html +1 -1
  12. package/coverage/lcov-report/src/api/controllers/global/self.ts.html +1 -1
  13. package/coverage/lcov-report/src/api/controllers/global/templates.ts.html +1 -1
  14. package/coverage/lcov-report/src/api/controllers/global/users.ts.html +47 -8
  15. package/coverage/lcov-report/src/api/controllers/global/workspaces.ts.html +1 -1
  16. package/coverage/lcov-report/src/api/controllers/system/accounts.ts.html +1 -1
  17. package/coverage/lcov-report/src/api/controllers/system/environment.ts.html +1 -1
  18. package/coverage/lcov-report/src/api/controllers/system/index.html +1 -1
  19. package/coverage/lcov-report/src/api/controllers/system/migrations.ts.html +1 -1
  20. package/coverage/lcov-report/src/api/controllers/system/restore.ts.html +1 -1
  21. package/coverage/lcov-report/src/api/controllers/system/status.ts.html +1 -1
  22. package/coverage/lcov-report/src/api/controllers/system/tenants.ts.html +1 -1
  23. package/coverage/lcov-report/src/api/index.html +1 -1
  24. package/coverage/lcov-report/src/api/index.ts.html +16 -4
  25. package/coverage/lcov-report/src/api/routes/global/auth.ts.html +1 -1
  26. package/coverage/lcov-report/src/api/routes/global/configs.ts.html +7 -7
  27. package/coverage/lcov-report/src/api/routes/global/email.ts.html +1 -1
  28. package/coverage/lcov-report/src/api/routes/global/events.ts.html +109 -0
  29. package/coverage/lcov-report/src/api/routes/global/index.html +22 -7
  30. package/coverage/lcov-report/src/api/routes/global/license.ts.html +1 -1
  31. package/coverage/lcov-report/src/api/routes/global/roles.ts.html +1 -1
  32. package/coverage/lcov-report/src/api/routes/global/self.ts.html +1 -1
  33. package/coverage/lcov-report/src/api/routes/global/templates.ts.html +1 -1
  34. package/coverage/lcov-report/src/api/routes/global/users.ts.html +47 -5
  35. package/coverage/lcov-report/src/api/routes/global/workspaces.ts.html +1 -1
  36. package/coverage/lcov-report/src/api/routes/index.html +5 -5
  37. package/coverage/lcov-report/src/api/routes/index.ts.html +10 -4
  38. package/coverage/lcov-report/src/api/routes/system/accounts.ts.html +1 -1
  39. package/coverage/lcov-report/src/api/routes/system/environment.ts.html +1 -1
  40. package/coverage/lcov-report/src/api/routes/system/index.html +1 -1
  41. package/coverage/lcov-report/src/api/routes/system/migrations.ts.html +1 -1
  42. package/coverage/lcov-report/src/api/routes/system/restore.ts.html +1 -1
  43. package/coverage/lcov-report/src/api/routes/system/status.ts.html +1 -1
  44. package/coverage/lcov-report/src/api/routes/system/tenants.ts.html +1 -1
  45. package/coverage/lcov-report/src/api/routes/validation/index.html +1 -1
  46. package/coverage/lcov-report/src/api/routes/validation/index.ts.html +1 -1
  47. package/coverage/lcov-report/src/api/routes/validation/users.ts.html +1 -1
  48. package/coverage/lcov-report/src/constants/index.html +1 -1
  49. package/coverage/lcov-report/src/constants/index.ts.html +1 -1
  50. package/coverage/lcov-report/src/constants/templates/index.html +1 -1
  51. package/coverage/lcov-report/src/constants/templates/index.ts.html +1 -1
  52. package/coverage/lcov-report/src/db/index.html +1 -1
  53. package/coverage/lcov-report/src/db/index.ts.html +1 -1
  54. package/coverage/lcov-report/src/environment.ts.html +1 -1
  55. package/coverage/lcov-report/src/index.html +10 -10
  56. package/coverage/lcov-report/src/index.ts.html +10 -7
  57. package/coverage/lcov-report/src/middleware/cloudRestricted.ts.html +1 -1
  58. package/coverage/lcov-report/src/middleware/index.html +1 -1
  59. package/coverage/lcov-report/src/migrations/functions/globalInfoSyncUsers.ts.html +1 -1
  60. package/coverage/lcov-report/src/migrations/functions/index.html +1 -1
  61. package/coverage/lcov-report/src/migrations/index.html +1 -1
  62. package/coverage/lcov-report/src/migrations/index.ts.html +1 -1
  63. package/coverage/lcov-report/src/sdk/accounts/accounts.ts.html +1 -1
  64. package/coverage/lcov-report/src/sdk/accounts/index.html +1 -1
  65. package/coverage/lcov-report/src/sdk/accounts/index.ts.html +1 -1
  66. package/coverage/lcov-report/src/sdk/index.html +1 -1
  67. package/coverage/lcov-report/src/sdk/index.ts.html +1 -1
  68. package/coverage/lcov-report/src/sdk/users/events.ts.html +34 -10
  69. package/coverage/lcov-report/src/sdk/users/index.html +19 -19
  70. package/coverage/lcov-report/src/sdk/users/index.ts.html +1 -1
  71. package/coverage/lcov-report/src/sdk/users/users.ts.html +11 -5
  72. package/coverage/lcov-report/src/tests/TestConfiguration.ts.html +1 -1
  73. package/coverage/lcov-report/src/tests/api/accounts.ts.html +1 -1
  74. package/coverage/lcov-report/src/tests/api/auth.ts.html +1 -1
  75. package/coverage/lcov-report/src/tests/api/base.ts.html +1 -1
  76. package/coverage/lcov-report/src/tests/api/configs.ts.html +1 -1
  77. package/coverage/lcov-report/src/tests/api/email.ts.html +1 -1
  78. package/coverage/lcov-report/src/tests/api/environment.ts.html +1 -1
  79. package/coverage/lcov-report/src/tests/api/groups.ts.html +1 -1
  80. package/coverage/lcov-report/src/tests/api/index.html +1 -1
  81. package/coverage/lcov-report/src/tests/api/index.ts.html +1 -1
  82. package/coverage/lcov-report/src/tests/api/license.ts.html +1 -1
  83. package/coverage/lcov-report/src/tests/api/migrations.ts.html +1 -1
  84. package/coverage/lcov-report/src/tests/api/restore.ts.html +1 -1
  85. package/coverage/lcov-report/src/tests/api/roles.ts.html +1 -1
  86. package/coverage/lcov-report/src/tests/api/self.ts.html +1 -1
  87. package/coverage/lcov-report/src/tests/api/status.ts.html +1 -1
  88. package/coverage/lcov-report/src/tests/api/templates.ts.html +1 -1
  89. package/coverage/lcov-report/src/tests/api/tenants.ts.html +1 -1
  90. package/coverage/lcov-report/src/tests/api/users.ts.html +5 -2
  91. package/coverage/lcov-report/src/tests/controllers.ts.html +1 -1
  92. package/coverage/lcov-report/src/tests/index.html +1 -1
  93. package/coverage/lcov-report/src/tests/index.ts.html +1 -1
  94. package/coverage/lcov-report/src/tests/mocks/email.ts.html +1 -1
  95. package/coverage/lcov-report/src/tests/mocks/index.html +1 -1
  96. package/coverage/lcov-report/src/tests/mocks/index.ts.html +1 -1
  97. package/coverage/lcov-report/src/tests/structures/configs.ts.html +1 -1
  98. package/coverage/lcov-report/src/tests/structures/groups.ts.html +1 -1
  99. package/coverage/lcov-report/src/tests/structures/index.html +1 -1
  100. package/coverage/lcov-report/src/tests/structures/index.ts.html +1 -1
  101. package/coverage/lcov-report/src/tests/structures/users.ts.html +1 -1
  102. package/coverage/lcov-report/src/utilities/appService.ts.html +36 -9
  103. package/coverage/lcov-report/src/utilities/email.ts.html +1 -1
  104. package/coverage/lcov-report/src/utilities/fileSystem.ts.html +1 -1
  105. package/coverage/lcov-report/src/utilities/index.html +11 -11
  106. package/coverage/lcov-report/src/utilities/index.ts.html +1 -1
  107. package/coverage/lcov-report/src/utilities/redis.ts.html +1 -1
  108. package/coverage/lcov-report/src/utilities/templates.ts.html +1 -1
  109. package/coverage/lcov-report/src/utilities/users.ts.html +1 -1
  110. package/coverage/lcov.info +658 -593
  111. package/package.json +6 -6
  112. package/scripts/dev/manage.js +2 -2
  113. package/src/api/controllers/global/configs.ts +1 -1
  114. package/src/api/controllers/global/events.ts +17 -0
  115. package/src/api/controllers/global/users.ts +13 -0
  116. package/src/api/index.ts +4 -0
  117. package/src/api/routes/global/configs.ts +6 -6
  118. package/src/api/routes/global/events.ts +8 -0
  119. package/src/api/routes/global/users.ts +14 -0
  120. package/src/api/routes/index.ts +2 -0
  121. package/src/index.ts +2 -1
  122. package/src/sdk/users/events.ts +8 -0
  123. package/src/sdk/users/users.ts +5 -3
  124. package/src/tests/api/users.ts +1 -0
  125. package/src/utilities/appService.ts +12 -3
  126. package/tsconfig.json +2 -1
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.7",
4
+ "version": "2.2.12-alpha.71",
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.7",
40
- "@budibase/pro": "2.2.12-alpha.6",
41
- "@budibase/string-templates": "2.2.12-alpha.7",
42
- "@budibase/types": "2.2.12-alpha.7",
39
+ "@budibase/backend-core": "2.2.12-alpha.71",
40
+ "@budibase/pro": "2.2.12-alpha.70",
41
+ "@budibase/string-templates": "2.2.12-alpha.71",
42
+ "@budibase/types": "2.2.12-alpha.71",
43
43
  "@koa/router": "8.0.8",
44
44
  "@sentry/node": "6.17.7",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
@@ -97,5 +97,5 @@
97
97
  "typescript": "4.7.3",
98
98
  "update-dotenv": "1.1.1"
99
99
  },
100
- "gitHead": "8c7bf5732e843eb43cd1f1590b38f2087d1e0b1c"
100
+ "gitHead": "4d79e749ea9a2c6ce499123b2b6df778e3641e68"
101
101
  }
@@ -21,14 +21,14 @@ async function init() {
21
21
  COUCH_DB_PASSWORD: "budibase",
22
22
  // empty string is false
23
23
  MULTI_TENANCY: "",
24
- DISABLE_ACCOUNT_PORTAL: "",
24
+ DISABLE_ACCOUNT_PORTAL: 1,
25
25
  ACCOUNT_PORTAL_URL: "http://localhost:10001",
26
26
  ACCOUNT_PORTAL_API_KEY: "budibase",
27
27
  PLATFORM_URL: "http://localhost:10000",
28
28
  APPS_URL: "http://localhost:4001",
29
29
  SERVICE: "worker-service",
30
30
  DEPLOYMENT_ENVIRONMENT: "development",
31
- TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS",
31
+ TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR",
32
32
  }
33
33
  let envFile = ""
34
34
  Object.keys(envFileJson).forEach(key => {
@@ -267,7 +267,7 @@ export async function publicSettings(ctx: Ctx) {
267
267
 
268
268
  // enrich the logo url
269
269
  // empty url means deleted
270
- if (config.config.logoUrl !== "") {
270
+ if (config.config.logoUrl && config.config.logoUrl !== "") {
271
271
  config.config.logoUrl = objectStore.getGlobalFileUrl(
272
272
  "settings",
273
273
  "logoUrl",
@@ -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 = [
@@ -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
  })
@@ -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
@@ -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(),
@@ -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
  ]
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 } 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,6 +36,7 @@ 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(middleware.logging)
39
40
  app.use(logger(logging.pinoSettings()))
40
41
 
41
42
  // authentication
@@ -73,6 +73,10 @@ export const handleSaveEvents = async (
73
73
  await events.user.permissionAdminRemoved(user)
74
74
  }
75
75
 
76
+ if (isOnboardingComplete(user, existingUser)) {
77
+ await events.user.onboardingComplete(user)
78
+ }
79
+
76
80
  if (
77
81
  !existingUser.forceResetPassword &&
78
82
  user.forceResetPassword &&
@@ -114,6 +118,10 @@ const isRemovingAdmin = (user: any, existingUser: any) => {
114
118
  return isRemovingPermission(user, existingUser, isAdmin)
115
119
  }
116
120
 
121
+ const isOnboardingComplete = (user: any, existingUser: any) => {
122
+ return !existingUser?.onboardedAt && typeof user.onboardedAt === "string"
123
+ }
124
+
117
125
  /**
118
126
  * Check if a permission is being added to a new or existing user.
119
127
  */
@@ -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 (
@@ -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,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" },