@budibase/worker 3.31.2 → 3.31.4

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/jest.config.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Config } from "jest"
2
- import * as fs from "fs"
3
2
 
4
3
  const config: Config = {
5
4
  globalSetup: "./../../globalSetup.ts",
@@ -16,13 +15,9 @@ const config: Config = {
16
15
  "@budibase/types": "<rootDir>/../types/src",
17
16
  "@budibase/shared-core": ["<rootDir>/../shared-core/src"],
18
17
  "@budibase/string-templates": ["<rootDir>/../string-templates/src"],
18
+ "@budibase/pro/(.*)": "<rootDir>/../pro/$1",
19
+ "@budibase/pro": "<rootDir>/../pro/src",
19
20
  },
20
21
  }
21
22
 
22
- // add pro sources if they exist
23
- if (fs.existsSync("../pro/src")) {
24
- config.moduleNameMapper!["@budibase/pro/(.*)"] = "<rootDir>/../pro/$1"
25
- config.moduleNameMapper!["@budibase/pro"] = "<rootDir>/../pro/src"
26
- }
27
-
28
23
  export default config
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "3.31.2",
4
+ "version": "3.31.4",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -91,23 +91,5 @@
91
91
  "supertest": "6.3.3",
92
92
  "timekeeper": "2.2.0"
93
93
  },
94
- "resolutions": {
95
- "@budibase/pro": "npm:@budibase/pro@latest"
96
- },
97
- "nx": {
98
- "targets": {
99
- "dev": {
100
- "dependsOn": [
101
- {
102
- "comment": "Required for pro usage when submodule not loaded",
103
- "projects": [
104
- "@budibase/backend-core"
105
- ],
106
- "target": "build:oss"
107
- }
108
- ]
109
- }
110
- }
111
- },
112
- "gitHead": "e43a157f7b7baa20d67d05b35fd94b2b205acb2b"
94
+ "gitHead": "7d5a486a8c245870743408abb7d03a33e19c8679"
113
95
  }
@@ -514,9 +514,6 @@ export async function find(ctx: UserCtx<void, FindConfigResponse>) {
514
514
  case ConfigType.OIDC_LOGOS:
515
515
  await enrichOIDCLogos(config)
516
516
  break
517
- case ConfigType.AI:
518
- await pro.sdk.ai.enrichAIConfig(config)
519
- break
520
517
  }
521
518
 
522
519
  stripSecrets(config, ctx)
@@ -14,6 +14,19 @@ import {
14
14
  } from "@budibase/types"
15
15
  import { db, groups, users as usersSdk } from "@budibase/pro"
16
16
 
17
+ const DEFAULT_PAGE_SIZE = 10
18
+
19
+ function parsePageSize(pageSize: unknown) {
20
+ if (pageSize === undefined || pageSize === null) {
21
+ return DEFAULT_PAGE_SIZE
22
+ }
23
+ const parsedPageSize = Number(pageSize)
24
+ if (!Number.isFinite(parsedPageSize) || parsedPageSize < 1) {
25
+ return DEFAULT_PAGE_SIZE
26
+ }
27
+ return Math.floor(parsedPageSize)
28
+ }
29
+
17
30
  export async function save(ctx: UserCtx) {
18
31
  const group: UserGroup = ctx.request.body
19
32
  group.name = group.name.trim()
@@ -101,7 +114,8 @@ export async function find(ctx: UserCtx) {
101
114
  }
102
115
 
103
116
  export async function searchUsers(ctx: Ctx<{}, SearchUserGroupResponse>) {
104
- const { pageSize = 10, bookmark, emailSearch } = ctx.request.query as any
117
+ const { bookmark, emailSearch } = ctx.request.query as any
118
+ const pageSize = parsePageSize((ctx.request.query as any).pageSize)
105
119
  const groupId = ctx.params.groupId
106
120
 
107
121
  const params: DatabaseQueryOpts = { limit: pageSize + 1 }
@@ -0,0 +1,84 @@
1
+ jest.mock("@budibase/pro", () => ({
2
+ db: {
3
+ groups: {
4
+ getGroupUsers: jest.fn(),
5
+ },
6
+ },
7
+ groups: {},
8
+ users: {},
9
+ csv: {},
10
+ }))
11
+
12
+ import { db } from "@budibase/pro"
13
+ import { searchUsers } from "../groups"
14
+
15
+ const createCtx = (pageSize: string): Parameters<typeof searchUsers>[0] =>
16
+ ({
17
+ request: {
18
+ query: {
19
+ pageSize,
20
+ },
21
+ },
22
+ params: {
23
+ groupId: "group_1",
24
+ },
25
+ body: undefined,
26
+ }) as unknown as Parameters<typeof searchUsers>[0]
27
+
28
+ describe("Global groups controller", () => {
29
+ beforeEach(() => {
30
+ jest.clearAllMocks()
31
+ })
32
+
33
+ it("coerces pageSize query param to a number before computing limit", async () => {
34
+ const getGroupUsers = db.groups.getGroupUsers as jest.Mock
35
+ getGroupUsers.mockResolvedValue(
36
+ Array.from({ length: 6 }).map((_, i) => ({
37
+ _id: `user_${i}`,
38
+ email: `user_${i}@example.com`,
39
+ }))
40
+ )
41
+
42
+ const ctx = createCtx("5")
43
+
44
+ await searchUsers(ctx)
45
+
46
+ expect(getGroupUsers).toHaveBeenCalledWith("group_1", {
47
+ limit: 6,
48
+ emailSearch: undefined,
49
+ bookmark: undefined,
50
+ })
51
+ expect(ctx.body).toEqual({
52
+ users: [
53
+ { _id: "user_0", email: "user_0@example.com" },
54
+ { _id: "user_1", email: "user_1@example.com" },
55
+ { _id: "user_2", email: "user_2@example.com" },
56
+ { _id: "user_3", email: "user_3@example.com" },
57
+ { _id: "user_4", email: "user_4@example.com" },
58
+ ],
59
+ bookmark: "user_5",
60
+ hasNextPage: true,
61
+ })
62
+ })
63
+
64
+ it("falls back to the default page size for invalid query values", async () => {
65
+ const getGroupUsers = db.groups.getGroupUsers as jest.Mock
66
+ getGroupUsers.mockResolvedValue(
67
+ Array.from({ length: 11 }).map((_, i) => ({
68
+ _id: `user_${i}`,
69
+ email: `user_${i}@example.com`,
70
+ }))
71
+ )
72
+
73
+ const ctx = createCtx("not-a-number")
74
+
75
+ await searchUsers(ctx)
76
+
77
+ expect(getGroupUsers).toHaveBeenCalledWith("group_1", {
78
+ limit: 11,
79
+ emailSearch: undefined,
80
+ bookmark: undefined,
81
+ })
82
+ expect(ctx.body.users).toHaveLength(10)
83
+ })
84
+ })
@@ -101,9 +101,6 @@ const environment = {
101
101
  PASSWORD_RESET_RATE_IP_WINDOW_SECONDS:
102
102
  parseIntSafe(process.env.PASSWORD_RESET_RATE_IP_WINDOW_SECONDS) || 900,
103
103
 
104
- // Budibase AI
105
- BUDIBASE_AI_API_KEY: process.env.BUDIBASE_AI_API_KEY,
106
- BUDIBASE_AI_DEFAULT_MODEL: process.env.BUDIBASE_AI_DEFAULT_MODEL,
107
104
  _set(key: any, value: any) {
108
105
  process.env[key] = value
109
106
  // @ts-ignore