@@ -838,61 +838,6 @@ type getAccountInfoResponse struct {
838838 Users []* userQueryResponse `json:"users"`
839839}
840840
841- // QueryUserInfoResponse is the response structure for the accounts:query endpoint.
842- type QueryUserInfoResponse struct {
843- Users []* UserRecord
844- Count int64
845- }
846-
847- type queryUsersResponse struct {
848- Users []* userQueryResponse `json:"userInfo"`
849- Count int64 `json:"recordsCount,string,omitempty"`
850- }
851-
852- // SQLExpression is a query condition used to filter results.
853- type SQLExpression struct {
854- Email string `json:"email,omitempty"`
855- UserID string `json:"userId,omitempty"`
856- PhoneNumber string `json:"phoneNumber,omitempty"`
857- }
858-
859- // QueryUsersRequest is the request structure for the accounts:query endpoint.
860- type QueryUsersRequest struct {
861- ReturnUserInfo bool `json:"returnUserInfo"`
862- Limit int64 `json:"limit,string,omitempty"`
863- Offset int64 `json:"offset,string,omitempty"`
864- SortBy string `json:"sortBy,omitempty"`
865- Order string `json:"order,omitempty"`
866- TenantID string `json:"tenantId,omitempty"`
867- Expression []* SQLExpression `json:"expression,omitempty"`
868- }
869-
870- // SortByField is a field to use for sorting user accounts.
871- type SortByField string
872-
873- const (
874- // UserID sorts results by userId.
875- UserID SortByField = "USER_ID"
876- // Name sorts results by name.
877- Name SortByField = "NAME"
878- // CreatedAt sorts results by createdAt.
879- CreatedAt SortByField = "CREATED_AT"
880- // LastLoginAt sorts results by lastLoginAt.
881- LastLoginAt SortByField = "LAST_LOGIN_AT"
882- // UserEmail sorts results by userEmail.
883- UserEmail SortByField = "USER_EMAIL"
884- )
885-
886- // Order is an order for sorting query results.
887- type Order string
888-
889- const (
890- // Asc sorts in ascending order.
891- Asc Order = "ASC"
892- // Desc sorts in descending order.
893- Desc Order = "DESC"
894- )
895-
896841func (c * baseClient ) getUser (ctx context.Context , query * userQuery ) (* UserRecord , error ) {
897842 var parsed getAccountInfoResponse
898843 resp , err := c .post (ctx , "/accounts:lookup" , query .build (), & parsed )
@@ -1103,6 +1048,129 @@ func (c *baseClient) GetUsers(
11031048 return & GetUsersResult {userRecords , notFound }, nil
11041049}
11051050
1051+ // QueryUserInfoResponse is the response structure for the accounts:query endpoint.
1052+ type QueryUserInfoResponse struct {
1053+ Users []* UserRecord
1054+ Count int64
1055+ }
1056+
1057+ type queryUsersResponse struct {
1058+ Users []* userQueryResponse `json:"userInfo"`
1059+ Count int64 `json:"recordsCount,string,omitempty"`
1060+ }
1061+
1062+ // SQLExpression is a query condition used to filter results.
1063+ type SQLExpression struct {
1064+ Email string `json:"email,omitempty"`
1065+ UID string `json:"userId,omitempty"`
1066+ PhoneNumber string `json:"phoneNumber,omitempty"`
1067+ }
1068+
1069+ // QueryUsersRequest is the request structure for the accounts:query endpoint.
1070+ type QueryUsersRequest struct {
1071+ ReturnUserInfo bool `json:"returnUserInfo"`
1072+ Limit int64 `json:"limit,string,omitempty"`
1073+ Offset int64 `json:"offset,string,omitempty"`
1074+ SortBy SortByField `json:"-"`
1075+ Order Order `json:"-"`
1076+ TenantID string `json:"tenantId,omitempty"`
1077+ Expression []* SQLExpression `json:"expression,omitempty"`
1078+ }
1079+
1080+ // MarshalJSON marshals a QueryUsersRequest into JSON (for internal use only).
1081+ func (q * QueryUsersRequest ) MarshalJSON () ([]byte , error ) {
1082+ var sortBy string
1083+ if q .SortBy != sortByUnspecified {
1084+ sortBys := map [SortByField ]string {
1085+ UID : "USER_ID" ,
1086+ Name : "NAME" ,
1087+ CreatedAt : "CREATED_AT" ,
1088+ LastLoginAt : "LAST_LOGIN_AT" ,
1089+ UserEmail : "USER_EMAIL" ,
1090+ }
1091+ sortBy = sortBys [q .SortBy ]
1092+ }
1093+
1094+ var order string
1095+ if q .Order != orderUnspecified {
1096+ orders := map [Order ]string {
1097+ Asc : "ASC" ,
1098+ Desc : "DESC" ,
1099+ }
1100+ order = orders [q .Order ]
1101+ }
1102+
1103+ type queryUsersRequestInternal QueryUsersRequest
1104+ temp := & struct {
1105+ SortBy string `json:"sortBy,omitempty"`
1106+ Order string `json:"order,omitempty"`
1107+ * queryUsersRequestInternal
1108+ }{
1109+ SortBy : sortBy ,
1110+ Order : order ,
1111+ queryUsersRequestInternal : (* queryUsersRequestInternal )(q ),
1112+ }
1113+ return json .Marshal (temp )
1114+ }
1115+
1116+ // SortByField is a field to use for sorting user accounts.
1117+ type SortByField int
1118+
1119+ const (
1120+ sortByUnspecified SortByField = iota
1121+ // UID sorts results by userId.
1122+ UID
1123+ // Name sorts results by name.
1124+ Name
1125+ // CreatedAt sorts results by createdAt.
1126+ CreatedAt
1127+ // LastLoginAt sorts results by lastLoginAt.
1128+ LastLoginAt
1129+ // UserEmail sorts results by userEmail.
1130+ UserEmail
1131+ )
1132+
1133+ // Order is an order for sorting query results.
1134+ type Order int
1135+
1136+ const (
1137+ orderUnspecified Order = iota
1138+ // Asc sorts in ascending order.
1139+ Asc
1140+ // Desc sorts in descending order.
1141+ Desc
1142+ )
1143+
1144+ // QueryUsers queries for user accounts based on the provided query configuration.
1145+ func (c * baseClient ) QueryUsers (ctx context.Context , query * QueryUsersRequest ) (* QueryUserInfoResponse , error ) {
1146+ if query == nil {
1147+ return nil , fmt .Errorf ("query request must not be nil" )
1148+ }
1149+
1150+ var parsed queryUsersResponse
1151+ _ , err := c .post (ctx , "/accounts:query" , query , & parsed )
1152+ if err != nil {
1153+ return nil , err
1154+ }
1155+
1156+ //log.Printf("QueryUsers() with response = %d, %d", parsed.Count, len(parsed.Users))
1157+
1158+ var userRecords []* UserRecord
1159+ for _ , user := range parsed .Users {
1160+ userRecord , err := user .makeUserRecord ()
1161+ if err != nil {
1162+ return nil , fmt .Errorf ("error while parsing response: %w" , err )
1163+ }
1164+ userRecords = append (userRecords , userRecord )
1165+ }
1166+
1167+ return & QueryUserInfoResponse {
1168+ Users : userRecords ,
1169+ Count : parsed .Count ,
1170+ }, nil
1171+ }
1172+
1173+
11061174type userQueryResponse struct {
11071175 UID string `json:"localId,omitempty"`
11081176 DisplayName string `json:"displayName,omitempty"`
@@ -1366,35 +1434,6 @@ type DeleteUsersErrorInfo struct {
13661434// array of errors that correspond to the failed deletions. An error is
13671435// returned if any of the identifiers are invalid or if more than 1000
13681436// identifiers are specified.
1369- // QueryUsers queries for user accounts based on the provided query configuration.
1370- func (c * baseClient ) QueryUsers (ctx context.Context , query * QueryUsersRequest ) (* QueryUserInfoResponse , error ) {
1371- if query == nil {
1372- return nil , fmt .Errorf ("query request must not be nil" )
1373- }
1374-
1375- var parsed queryUsersResponse
1376- _ , err := c .post (ctx , "/accounts:query" , query , & parsed )
1377- if err != nil {
1378- return nil , err
1379- }
1380-
1381- //log.Printf("QueryUsers() with response = %d, %d", parsed.Count, len(parsed.Users))
1382-
1383- var userRecords []* UserRecord
1384- for _ , user := range parsed .Users {
1385- userRecord , err := user .makeUserRecord ()
1386- if err != nil {
1387- return nil , fmt .Errorf ("error while parsing response: %w" , err )
1388- }
1389- userRecords = append (userRecords , userRecord )
1390- }
1391-
1392- return & QueryUserInfoResponse {
1393- Users : userRecords ,
1394- Count : parsed .Count ,
1395- }, nil
1396- }
1397-
13981437func (c * baseClient ) DeleteUsers (ctx context.Context , uids []string ) (* DeleteUsersResult , error ) {
13991438 if len (uids ) == 0 {
14001439 return & DeleteUsersResult {}, nil
0 commit comments