@budibase/worker 2.13.35 → 2.13.37

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": "2.13.35",
4
+ "version": "2.13.37",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -21,7 +21,7 @@
21
21
  "debug": "yarn build && node --expose-gc --inspect=9223 dist/index.js",
22
22
  "run:docker:cluster": "pm2-runtime start pm2.config.js",
23
23
  "dev:stack:init": "node ./scripts/dev/manage.js init",
24
- "dev:builder": "npm run dev:stack:init && nodemon",
24
+ "dev": "npm run dev:stack:init && nodemon",
25
25
  "dev:built": "yarn run dev:stack:init && yarn run run:docker",
26
26
  "test": "bash scripts/test.sh",
27
27
  "test:watch": "jest --watch",
@@ -37,10 +37,10 @@
37
37
  "author": "Budibase",
38
38
  "license": "GPL-3.0",
39
39
  "dependencies": {
40
- "@budibase/backend-core": "2.13.35",
41
- "@budibase/pro": "2.13.35",
42
- "@budibase/string-templates": "2.13.35",
43
- "@budibase/types": "2.13.35",
40
+ "@budibase/backend-core": "2.13.37",
41
+ "@budibase/pro": "2.13.37",
42
+ "@budibase/string-templates": "2.13.37",
43
+ "@budibase/types": "2.13.37",
44
44
  "@koa/router": "8.0.8",
45
45
  "@techpass/passport-openidconnect": "0.3.2",
46
46
  "@types/global-agent": "2.1.1",
@@ -75,26 +75,26 @@
75
75
  "@swc/jest": "0.2.27",
76
76
  "@trendyol/jest-testcontainers": "2.1.1",
77
77
  "@types/jest": "29.5.5",
78
- "@types/jsonwebtoken": "8.5.1",
78
+ "@types/jsonwebtoken": "9.0.3",
79
79
  "@types/koa": "2.13.4",
80
80
  "@types/koa__router": "8.0.8",
81
81
  "@types/lodash": "4.14.200",
82
82
  "@types/node": "18.17.0",
83
83
  "@types/node-fetch": "2.6.4",
84
84
  "@types/server-destroy": "1.0.1",
85
- "@types/supertest": "2.0.12",
85
+ "@types/supertest": "2.0.14",
86
86
  "@types/uuid": "8.3.4",
87
- "jest": "29.6.2",
87
+ "jest": "29.7.0",
88
88
  "nodemon": "2.0.15",
89
89
  "rimraf": "3.0.2",
90
- "supertest": "6.2.2",
90
+ "supertest": "6.3.3",
91
91
  "timekeeper": "2.2.0",
92
92
  "typescript": "5.2.2",
93
93
  "update-dotenv": "1.1.1"
94
94
  },
95
95
  "nx": {
96
96
  "targets": {
97
- "dev:builder": {
97
+ "dev": {
98
98
  "dependsOn": [
99
99
  {
100
100
  "comment": "Required for pro usage when submodule not loaded",
@@ -107,5 +107,5 @@
107
107
  }
108
108
  }
109
109
  },
110
- "gitHead": "5c98ab7536b59b95c63de6e4d0200ecfd1103b02"
110
+ "gitHead": "a3ba9269d3867cb9695ed1e718f6cead49c7f6e2"
111
111
  }
@@ -26,6 +26,7 @@ import {
26
26
  migrations,
27
27
  platform,
28
28
  tenancy,
29
+ db,
29
30
  } from "@budibase/backend-core"
30
31
  import { checkAnyUserExists } from "../../../utilities/users"
31
32
  import { isEmailConfigured } from "../../../utilities/email"
@@ -185,9 +186,27 @@ export const getAppUsers = async (ctx: Ctx<SearchUsersRequest>) => {
185
186
  export const search = async (ctx: Ctx<SearchUsersRequest>) => {
186
187
  const body = ctx.request.body
187
188
 
188
- // TODO: for now only one supported search key, string.email
189
- if (body?.query && !userSdk.core.isSupportedUserSearch(body.query)) {
190
- ctx.throw(501, "Can only search by string.email or equal._id")
189
+ // TODO: for now only two supported search keys; string.email and equal._id
190
+ if (body?.query) {
191
+ // Clean numeric prefixing. This will overwrite duplicate search fields,
192
+ // but this is fine because we only support a single custom search on
193
+ // email and id
194
+ for (let filters of Object.values(body.query)) {
195
+ if (filters && typeof filters === "object") {
196
+ for (let [field, value] of Object.entries(filters)) {
197
+ delete filters[field]
198
+ const cleanedField = db.removeKeyNumbering(field)
199
+ if (filters[cleanedField] !== undefined) {
200
+ ctx.throw(400, "Only 1 filter per field is supported")
201
+ }
202
+ filters[cleanedField] = value
203
+ }
204
+ }
205
+ }
206
+ // Validate we aren't trying to search on any illegal fields
207
+ if (!userSdk.core.isSupportedUserSearch(body.query)) {
208
+ ctx.throw(400, "Can only search by string.email or equal._id")
209
+ }
191
210
  }
192
211
 
193
212
  if (body.paginate === false) {
@@ -590,6 +590,15 @@ describe("/api/global/users", () => {
590
590
  expect(response.body.data[0].email).toBe(user.email)
591
591
  })
592
592
 
593
+ it("should be able to search by email with numeric prefixing", async () => {
594
+ const user = await config.createUser()
595
+ const response = await config.api.users.searchUsers({
596
+ query: { string: { ["999:email"]: user.email } },
597
+ })
598
+ expect(response.body.data.length).toBe(1)
599
+ expect(response.body.data[0].email).toBe(user.email)
600
+ })
601
+
593
602
  it("should be able to search by _id", async () => {
594
603
  const user = await config.createUser()
595
604
  const response = await config.api.users.searchUsers({
@@ -599,13 +608,52 @@ describe("/api/global/users", () => {
599
608
  expect(response.body.data[0]._id).toBe(user._id)
600
609
  })
601
610
 
611
+ it("should be able to search by _id with numeric prefixing", async () => {
612
+ const user = await config.createUser()
613
+ const response = await config.api.users.searchUsers({
614
+ query: { equal: { ["1:_id"]: user._id } },
615
+ })
616
+ expect(response.body.data.length).toBe(1)
617
+ expect(response.body.data[0]._id).toBe(user._id)
618
+ })
619
+
620
+ it("should throw an error when using multiple filters on the same field", async () => {
621
+ const user = await config.createUser()
622
+ await config.api.users.searchUsers(
623
+ {
624
+ query: {
625
+ string: {
626
+ ["1:email"]: user.email,
627
+ ["2:email"]: "something else",
628
+ },
629
+ },
630
+ },
631
+ { status: 400 }
632
+ )
633
+ })
634
+
635
+ it("should throw an error when using multiple filters on the same field without prefixes", async () => {
636
+ const user = await config.createUser()
637
+ await config.api.users.searchUsers(
638
+ {
639
+ query: {
640
+ string: {
641
+ ["_id"]: user.email,
642
+ ["999:_id"]: "something else",
643
+ },
644
+ },
645
+ },
646
+ { status: 400 }
647
+ )
648
+ })
649
+
602
650
  it("should throw an error when unimplemented options used", async () => {
603
651
  const user = await config.createUser()
604
652
  await config.api.users.searchUsers(
605
653
  {
606
654
  query: { equal: { firstName: user.firstName } },
607
655
  },
608
- { status: 501 }
656
+ { status: 400 }
609
657
  )
610
658
  })
611
659