-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core)!: enhanced user search params #2639
Conversation
COMPARE TO
|
Name | Diff |
---|---|
packages/console/src/pages/Users/index.tsx | 馃搱 +2 Bytes |
packages/core/nodemon.json | 馃搱 +29 Bytes |
packages/core/package.json | 馃搱 +85 Bytes |
packages/core/src/env-set/parameters.ts | 馃搱 +67 Bytes |
packages/core/src/lib/passcode.ts | 馃搱 +39 Bytes |
packages/core/src/lib/sign-in-experience/sign-in.ts | 馃搱 +63 Bytes |
packages/core/src/middleware/koa-auth.ts | 馃搱 +65 Bytes |
packages/core/src/middleware/koa-pagination.ts | 馃搱 +68 Bytes |
packages/core/src/queries/user.test.ts | 馃搱 +4.54 KB |
packages/core/src/queries/user.ts | 馃搱 +8 Bytes |
packages/core/src/routes/admin-user.test.ts | 馃搱 +54 Bytes |
packages/core/src/routes/admin-user.ts | 馃搱 +36 Bytes |
packages/core/src/routes/connector.ts | 馃搱 +43 Bytes |
packages/core/src/routes/interaction/utils/sign-in-experience-validation.ts | 馃搱 +90 Bytes |
packages/core/src/routes/sign-in-experience.ts | 馃搱 +69 Bytes |
packages/core/src/utils/search.test.ts | 馃搱 +6.63 KB |
packages/core/src/utils/search.ts | 馃搱 +7.63 KB |
packages/core/src/utils/test-utils.ts | 馃搱 +377 Bytes |
packages/core/src/utils/zod.ts | 馃搱 +56 Bytes |
packages/integration-tests/src/api/admin-user.ts | 馃搱 +25 Bytes |
packages/integration-tests/src/helpers.ts | 馃搱 +942 Bytes |
packages/integration-tests/src/tests/api/admin-user.search.test.ts | 馃搱 +7.91 KB |
packages/phrases/src/locales/de/errors.ts | 馃搱 +86 Bytes |
packages/phrases/src/locales/en/errors.ts | 馃搱 +70 Bytes |
packages/phrases/src/locales/fr/errors.ts | 馃搱 +86 Bytes |
packages/phrases/src/locales/ko/errors.ts | 馃搱 +86 Bytes |
packages/phrases/src/locales/pt-br/errors.ts | 馃搱 +86 Bytes |
packages/phrases/src/locales/pt-pt/errors.ts | 馃搱 +86 Bytes |
packages/phrases/src/locales/tr-tr/errors.ts | 馃搱 +86 Bytes |
packages/phrases/src/locales/zh-cn/errors.ts | 馃搱 +86 Bytes |
packages/schemas/src/types/index.ts | 馃搱 +29 Bytes |
packages/schemas/src/types/search.ts | 馃搱 +835 Bytes |
This branch has been deployed using Uffizzi. Preview URL: View deployment details here: This is an automated comment. To turn off commenting, visit uffizzi.com. |
59efcef
to
bb24b1a
Compare
94de1e8
to
83b2931
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we support array values? Like /api/users?search=id:1,2,3
yes, integration tests covered this. added to description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
implement #2167
This PR enhanced
GET /users
API with more search options.馃挜 Breaking change 馃挜
If you want to perform the original fuzzy search, you need to manually add
%
around the keyword. E.g.:Original:
GET /users?search=foo
Now:
GET /users?search=%foo%
Perform a search request
A search request consists of the following parameter keys:
search
,search.*
mode
,mode.*
(default value'like'
, available['exact', 'like', 'similar_to', 'posix']
)joint
orjointMode
(default value'or'
, available['or', 'and']
)isCaseSensitive
(default valuefalse
)hideAdminUser
(default valuefalse
)Pagination stays the same way. Let's go through them via some examples. All search params will be formatted as a constructor of
URLSearchParams
.Basic fuzzy search
If you want to perform a fuzzy search over all available fields, just provide a value for key
search
. It will use thelike
operator under the hood:This search will iterate over all available fields in a user search, i.e.
id
,primaryEmail
,primaryPhone
,username
,name
.Specify fields
What if you want to limit the search in
name
only? To search someone that includesfoo
in their name, just use the.
symbol to specify the field:Remember nested fields are not supported, e.g.
search.name.first
will result an error.You can also specify multiple fields at the same time:
Means to search users that have
foo
in name OR their email ends with@gmail.com
.Changing the joint mode
If you want the API only returns the result that satisfies ALL the conditions, set the joint mode to
and
:Means to search users that have
foo
in name AND their email ends with@gmail.com
.Exact match and case sensitivity
Say you want to search whose name is exact "Alice". You can set
mode.name
to use exact match.You may find it has the same effect when using the
like
mode (default) v.s. specifyingexact
. One difference isexact
mode uses=
for comparing whilelike
useslike
orilike
. Theoretically=
should have a better performance.Plus, in
exact
mode, you can pass multiple values for matching, and they will be connected withor
:It will match the users with name "Alice" OR "Bob".
By default search is case-insensitive. To be more precise, set the search as case-sensitive:
Note
isCaseSensitive
is a global config. Thus EVERY field will follow it.Regular expression (RegEx)
PostgreSQL supports two types of regular expressions, similar to and posix. Set
mode
tosimilar_to
orposix
to search by regular expressions:Match mode override
By default, all keywords will inherit the match mode from the general search:
To override for specific field:
Hide admin user
For convenience, you can apply
hideAdminUser
to quickly filter out all admins from the result:Testing