Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support identifier-type-specific query parameters for Users List #345

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions user/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,17 @@ func (c *Client) Delete(ctx context.Context, id string) (*clerk.DeletedResource,
type ListParams struct {
clerk.APIParams
clerk.ListParams
OrderBy *string `json:"order_by,omitempty"`
Query *string `json:"query,omitempty"`
EmailAddresses []string `json:"email_address,omitempty"`
ExternalIDs []string `json:"external_id,omitempty"`
PhoneNumbers []string `json:"phone_number,omitempty"`
Web3Wallets []string `json:"web3_wallet,omitempty"`
Usernames []string `json:"username,omitempty"`
UserIDs []string `json:"user_id,omitempty"`
OrderBy *string `json:"order_by,omitempty"`
Query *string `json:"query,omitempty"`
EmailAddressQuery *string `json:"email_address_query,omitempty"`
PhoneNumberQuery *string `json:"phone_number_query,omitempty"`
UsernameQuery *string `json:"username_query,omitempty"`
EmailAddresses []string `json:"email_address,omitempty"`
ExternalIDs []string `json:"external_id,omitempty"`
PhoneNumbers []string `json:"phone_number,omitempty"`
Web3Wallets []string `json:"web3_wallet,omitempty"`
Usernames []string `json:"username,omitempty"`
UserIDs []string `json:"user_id,omitempty"`
// OrganizationIDs filters users that have memberships to the given organizations. For each organization ID, the
// + and - can be prepended to the ID, which denote whether the respective organization should be included or
// excluded from the result set. Accepts up to 100 organization IDs.
Expand All @@ -233,6 +236,15 @@ func (params *ListParams) ToQuery() url.Values {
if params.Query != nil {
q.Add("query", *params.Query)
}
if params.EmailAddressQuery != nil {
q.Add("email_address_query", *params.EmailAddressQuery)
}
if params.PhoneNumberQuery != nil {
q.Add("phone_number_query", *params.PhoneNumberQuery)
}
if params.UsernameQuery != nil {
q.Add("username_query", *params.UsernameQuery)
}
for _, v := range params.EmailAddresses {
q.Add("email_address", v)
}
Expand Down
18 changes: 10 additions & 8 deletions user/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,21 @@ func TestUserClientList_Request(t *testing.T) {
T: t,
Method: http.MethodGet,
Query: &url.Values{
"limit": []string{"1"},
"offset": []string{"2"},
"order_by": []string{"-created_at"},
"email_address": []string{"[email protected]", "[email protected]"},
"organization_id": []string{"org_123", "org_456"},
"limit": []string{"1"},
"offset": []string{"2"},
"order_by": []string{"-created_at"},
"email_address": []string{"[email protected]", "[email protected]"},
"organization_id": []string{"org_123", "org_456"},
"email_address_query": []string{"@bar.com"},
},
},
}
client := NewClient(config)
params := &ListParams{
EmailAddresses: []string{"[email protected]", "[email protected]"},
OrderBy: clerk.String("-created_at"),
OrganizationIDs: []string{"org_123", "org_456"},
EmailAddresses: []string{"[email protected]", "[email protected]"},
OrderBy: clerk.String("-created_at"),
OrganizationIDs: []string{"org_123", "org_456"},
EmailAddressQuery: clerk.String("@bar.com"),
}
params.Limit = clerk.Int64(1)
params.Offset = clerk.Int64(2)
Expand Down
Loading