@budibase/worker 3.2.28 → 3.2.30

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "3.2.28",
4
+ "version": "3.2.30",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -114,5 +114,5 @@
114
114
  }
115
115
  }
116
116
  },
117
- "gitHead": "c45756b8f18fc7e36371a33149611f50748a662a"
117
+ "gitHead": "674ee960a79856f998b71845c0c86c6955a41f80"
118
118
  }
@@ -22,6 +22,8 @@ import {
22
22
  GetInitInfoResponse,
23
23
  PasswordResetResponse,
24
24
  PasswordResetUpdateResponse,
25
+ SetInitInfoResponse,
26
+ LoginResponse,
25
27
  } from "@budibase/types"
26
28
  import env from "../../../environment"
27
29
  import { Next } from "koa"
@@ -59,7 +61,10 @@ async function passportCallback(
59
61
  ctx.set(Header.TOKEN, token)
60
62
  }
61
63
 
62
- export const login = async (ctx: Ctx<LoginRequest, void>, next: Next) => {
64
+ export const login = async (
65
+ ctx: Ctx<LoginRequest, LoginResponse>,
66
+ next: Next
67
+ ) => {
63
68
  const email = ctx.request.body.username
64
69
 
65
70
  const user = await userSdk.db.getUserByEmail(email)
@@ -74,7 +79,10 @@ export const login = async (ctx: Ctx<LoginRequest, void>, next: Next) => {
74
79
  await context.identity.doInUserContext(user, ctx, async () => {
75
80
  await events.auth.login("local", user.email)
76
81
  })
77
- ctx.status = 200
82
+ ctx.body = {
83
+ message: "Login successful",
84
+ userId: user.userId,
85
+ }
78
86
  }
79
87
  )(ctx, next)
80
88
  }
@@ -88,10 +96,14 @@ export const logout = async (ctx: UserCtx<void, LogoutResponse>) => {
88
96
 
89
97
  // INIT
90
98
 
91
- export const setInitInfo = (ctx: UserCtx<SetInitInfoRequest, void>) => {
99
+ export const setInitInfo = (
100
+ ctx: UserCtx<SetInitInfoRequest, SetInitInfoResponse>
101
+ ) => {
92
102
  const initInfo = ctx.request.body
93
103
  setCookie(ctx, initInfo, Cookie.Init)
94
- ctx.status = 200
104
+ ctx.body = {
105
+ message: "Init info updated.",
106
+ }
95
107
  }
96
108
 
97
109
  export const getInitInfo = (ctx: UserCtx<void, GetInitInfoResponse>) => {
@@ -2,10 +2,13 @@ import {
2
2
  UserCtx,
3
3
  PostEventPublishRequest,
4
4
  EventPublishType,
5
+ PostEventPublishResponse,
5
6
  } from "@budibase/types"
6
7
  import { events } from "@budibase/backend-core"
7
8
 
8
- export async function publish(ctx: UserCtx<PostEventPublishRequest, void>) {
9
+ export async function publish(
10
+ ctx: UserCtx<PostEventPublishRequest, PostEventPublishResponse>
11
+ ) {
9
12
  switch (ctx.request.body.type) {
10
13
  case EventPublishType.ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED:
11
14
  await events.environmentVariable.upgradePanelOpened(ctx.user._id!)
@@ -13,5 +16,5 @@ export async function publish(ctx: UserCtx<PostEventPublishRequest, void>) {
13
16
  default:
14
17
  ctx.throw(400, "Invalid publish event type.")
15
18
  }
16
- ctx.status = 200
19
+ ctx.body = { message: "Event published." }
17
20
  }
@@ -1,29 +1,33 @@
1
1
  import { licensing, quotas } from "@budibase/pro"
2
2
  import {
3
3
  ActivateLicenseKeyRequest,
4
+ ActivateLicenseKeyResponse,
4
5
  ActivateOfflineLicenseTokenRequest,
6
+ ActivateOfflineLicenseTokenResponse,
5
7
  GetLicenseKeyResponse,
6
8
  GetOfflineIdentifierResponse,
7
9
  GetOfflineLicenseTokenResponse,
8
10
  GetQuotaUsageResponse,
11
+ RefreshOfflineLicenseResponse,
9
12
  UserCtx,
10
13
  } from "@budibase/types"
11
14
 
12
15
  // LICENSE KEY
13
16
 
14
17
  export async function activateLicenseKey(
15
- ctx: UserCtx<ActivateLicenseKeyRequest>
18
+ ctx: UserCtx<ActivateLicenseKeyRequest, ActivateLicenseKeyResponse>
16
19
  ) {
17
20
  const { licenseKey } = ctx.request.body
18
21
  await licensing.keys.activateLicenseKey(licenseKey)
19
- ctx.status = 200
22
+ ctx.body = {
23
+ message: "License activated.",
24
+ }
20
25
  }
21
26
 
22
27
  export async function getLicenseKey(ctx: UserCtx<void, GetLicenseKeyResponse>) {
23
28
  const licenseKey = await licensing.keys.getLicenseKey()
24
29
  if (licenseKey) {
25
30
  ctx.body = { licenseKey: "*" }
26
- ctx.status = 200
27
31
  } else {
28
32
  ctx.status = 404
29
33
  }
@@ -37,11 +41,16 @@ export async function deleteLicenseKey(ctx: UserCtx<void, void>) {
37
41
  // OFFLINE LICENSE
38
42
 
39
43
  export async function activateOfflineLicenseToken(
40
- ctx: UserCtx<ActivateOfflineLicenseTokenRequest, void>
44
+ ctx: UserCtx<
45
+ ActivateOfflineLicenseTokenRequest,
46
+ ActivateOfflineLicenseTokenResponse
47
+ >
41
48
  ) {
42
49
  const { offlineLicenseToken } = ctx.request.body
43
50
  await licensing.offline.activateOfflineLicenseToken(offlineLicenseToken)
44
- ctx.status = 200
51
+ ctx.body = {
52
+ message: "License token activated.",
53
+ }
45
54
  }
46
55
 
47
56
  export async function getOfflineLicenseToken(
@@ -50,7 +59,6 @@ export async function getOfflineLicenseToken(
50
59
  const offlineLicenseToken = await licensing.offline.getOfflineLicenseToken()
51
60
  if (offlineLicenseToken) {
52
61
  ctx.body = { offlineLicenseToken: "*" }
53
- ctx.status = 200
54
62
  } else {
55
63
  ctx.status = 404
56
64
  }
@@ -66,14 +74,17 @@ export async function getOfflineLicenseIdentifier(
66
74
  ) {
67
75
  const identifierBase64 = await licensing.offline.getIdentifierBase64()
68
76
  ctx.body = { identifierBase64 }
69
- ctx.status = 200
70
77
  }
71
78
 
72
79
  // LICENSES
73
80
 
74
- export const refresh = async (ctx: UserCtx<void, void>) => {
81
+ export const refresh = async (
82
+ ctx: UserCtx<void, RefreshOfflineLicenseResponse>
83
+ ) => {
75
84
  await licensing.cache.refresh()
76
- ctx.status = 200
85
+ ctx.body = {
86
+ message: "License refreshed.",
87
+ }
77
88
  }
78
89
 
79
90
  // USAGE
@@ -82,5 +93,4 @@ export const getQuotaUsage = async (
82
93
  ctx: UserCtx<void, GetQuotaUsageResponse>
83
94
  ) => {
84
95
  ctx.body = await quotas.getQuotaUsage()
85
- ctx.status = 200
86
96
  }
@@ -4,6 +4,7 @@ import {
4
4
  AcceptUserInviteRequest,
5
5
  AcceptUserInviteResponse,
6
6
  AddSSoUserRequest,
7
+ AddSSoUserResponse,
7
8
  BulkUserRequest,
8
9
  BulkUserResponse,
9
10
  CheckInviteResponse,
@@ -93,7 +94,9 @@ export const save = async (ctx: UserCtx<User, SaveUserResponse>) => {
93
94
  }
94
95
  }
95
96
 
96
- export const addSsoSupport = async (ctx: Ctx<AddSSoUserRequest, void>) => {
97
+ export const addSsoSupport = async (
98
+ ctx: Ctx<AddSSoUserRequest, AddSSoUserResponse>
99
+ ) => {
97
100
  const { email, ssoId } = ctx.request.body
98
101
  try {
99
102
  // Status is changed to 404 from getUserDoc if user is not found
@@ -113,7 +116,7 @@ export const addSsoSupport = async (ctx: Ctx<AddSSoUserRequest, void>) => {
113
116
  email,
114
117
  ssoId,
115
118
  })
116
- ctx.status = 200
119
+ ctx.body = { message: "SSO support added." }
117
120
  } catch (err: any) {
118
121
  ctx.throw(err.status || 400, err)
119
122
  }
@@ -19,7 +19,6 @@ export const save = async (
19
19
  metadata = await accounts.metadata.saveMetadata(metadata)
20
20
 
21
21
  ctx.body = metadata
22
- ctx.status = 200
23
22
  }
24
23
 
25
24
  export const destroy = async (ctx: Ctx<void, void>) => {
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  FetchMigrationDefinitionsResponse,
3
3
  RunGlobalMigrationRequest,
4
+ RunGlobalMigrationResponse,
4
5
  UserCtx,
5
6
  } from "@budibase/types"
6
7
 
7
8
  const { migrate, MIGRATIONS } = require("../../../migrations")
8
9
 
9
10
  export const runMigrations = async (
10
- ctx: UserCtx<RunGlobalMigrationRequest, void>
11
+ ctx: UserCtx<RunGlobalMigrationRequest, RunGlobalMigrationResponse>
11
12
  ) => {
12
13
  const options = ctx.request.body
13
14
  // don't await as can take a while, just return
14
15
  migrate(options)
15
- ctx.status = 200
16
+ ctx.body = { message: "Migration started." }
16
17
  }
17
18
 
18
19
  export const fetchDefinitions = async (
19
20
  ctx: UserCtx<void, FetchMigrationDefinitionsResponse>
20
21
  ) => {
21
22
  ctx.body = MIGRATIONS
22
- ctx.status = 200
23
23
  }
@@ -36,7 +36,7 @@ describe("/api/system/migrations", () => {
36
36
 
37
37
  it("runs migrations", async () => {
38
38
  const res = await config.api.migrations.runMigrations()
39
- expect(res.text).toBe("OK")
39
+ expect(res.body.message).toBeDefined()
40
40
  expect(migrateFn).toHaveBeenCalledTimes(1)
41
41
  })
42
42
  })