@@ -1048,7 +1048,7 @@ func (c *baseClient) GetUsers(
10481048 return & GetUsersResult {userRecords , notFound }, nil
10491049}
10501050
1051- // QueryUserInfoResponse is the response structure for the accounts:query endpoint .
1051+ // QueryUserInfoResponse is the response structure for the QueryUsers function .
10521052type QueryUserInfoResponse struct {
10531053 Users []* UserRecord
10541054 Count int64
@@ -1060,21 +1060,38 @@ type queryUsersResponse struct {
10601060}
10611061
10621062// Expression is a query condition used to filter results.
1063+ //
1064+ // Only one of Email, PhoneNumber, or UID should be specified.
1065+ // If more than one is specified, only the first (in the order of Email, PhoneNumber, UID) will be applied.
10631066type Expression struct {
1064- Email string `json:"email,omitempty"`
1065- UID string `json:"userId,omitempty"`
1067+ // Email is a case insensitive string that the account's email should match.
1068+ Email string `json:"email,omitempty"`
1069+ // PhoneNumber is a string that the account's phone number should match.
10661070 PhoneNumber string `json:"phoneNumber,omitempty"`
1071+ // UID is a string that the account's local ID should match.
1072+ UID string `json:"userId,omitempty"`
10671073}
10681074
1069- // QueryUsersRequest is the request structure for the accounts:query endpoint .
1075+ // QueryUsersRequest is the request structure for the QueryUsers function .
10701076type QueryUsersRequest struct {
1071- ReturnUserInfo * bool `json:"returnUserInfo,omitempty"`
1072- Limit int64 `json:"limit,string,omitempty"`
1073- Offset int64 `json:"offset,string,omitempty"`
1074- SortBy SortBy `json:"-"`
1075- Order Order `json:"-"`
1076- TenantID string `json:"tenantId,omitempty"`
1077- Expression []* Expression `json:"expression,omitempty"`
1077+ // ReturnUserInfo indicates whether to return the accounts matching the query.
1078+ // If false, only the count of accounts matching the query will be returned.
1079+ // Defaults to true.
1080+ ReturnUserInfo * bool `json:"returnUserInfo,omitempty"`
1081+ // Limit is the maximum number of accounts to return with an upper limit of 500.
1082+ // Defaults to 500. Only valid when ReturnUserInfo is set to true.
1083+ Limit int64 `json:"limit,string,omitempty"`
1084+ // Offset is the number of accounts to skip from the beginning of matching records.
1085+ // Only valid when ReturnUserInfo is set to true.
1086+ Offset int64 `json:"offset,string,omitempty"`
1087+ // SortBy is the field to use for sorting user accounts.
1088+ SortBy SortBy `json:"-"`
1089+ // Order is the order for sorting query results.
1090+ Order Order `json:"-"`
1091+ // TenantID is the ID of the tenant to which the result is scoped.
1092+ TenantID string `json:"tenantId,omitempty"`
1093+ // Expression is a list of query conditions used to filter results.
1094+ Expression []* Expression `json:"expression,omitempty"`
10781095}
10791096
10801097// build builds the query request (for internal use only).
@@ -1118,6 +1135,33 @@ func (q *QueryUsersRequest) build() interface{} {
11181135 }
11191136}
11201137
1138+ func (q * QueryUsersRequest ) validate () error {
1139+ if q .Limit != 0 && (q .Limit < 1 || q .Limit > 500 ) {
1140+ return fmt .Errorf ("limit must be between 1 and 500" )
1141+ }
1142+ if q .Offset < 0 {
1143+ return fmt .Errorf ("offset must be non-negative" )
1144+ }
1145+ for _ , exp := range q .Expression {
1146+ if exp .Email != "" {
1147+ if err := validateEmail (exp .Email ); err != nil {
1148+ return err
1149+ }
1150+ }
1151+ if exp .PhoneNumber != "" {
1152+ if err := validatePhone (exp .PhoneNumber ); err != nil {
1153+ return err
1154+ }
1155+ }
1156+ if exp .UID != "" {
1157+ if err := validateUID (exp .UID ); err != nil {
1158+ return err
1159+ }
1160+ }
1161+ }
1162+ return nil
1163+ }
1164+
11211165// SortBy is a field to use for sorting user accounts.
11221166type SortBy int
11231167
@@ -1151,6 +1195,9 @@ func (c *baseClient) QueryUsers(ctx context.Context, query *QueryUsersRequest) (
11511195 if query == nil {
11521196 return nil , fmt .Errorf ("query request must not be nil" )
11531197 }
1198+ if err := query .validate (); err != nil {
1199+ return nil , err
1200+ }
11541201
11551202 var parsed queryUsersResponse
11561203 _ , err := c .post (ctx , "/accounts:query" , query .build (), & parsed )
0 commit comments