Skip to content

Commit a2cce63

Browse files
Merge pull request #253 from supertokens/feat/search-apis
feat: Add search APIs to dashboard recipe
2 parents fc00ff9 + 8237664 commit a2cce63

File tree

13 files changed

+114
-17
lines changed

13 files changed

+114
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [unreleased]
99

10+
## [0.10.5] - 2023-03-31
11+
12+
- Adds search APIs to the dashboard recipe
13+
1014
## [0.10.4] - 2023-03-30
1115

1216
- Adds a telemetry API to the dashboard recipe

coreDriverInterfaceSupported.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"2.16",
1313
"2.17",
1414
"2.18",
15-
"2.19"
15+
"2.19",
16+
"2.20"
1617
]
1718
}

recipe/dashboard/api/implementation.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
package api
1717

1818
import (
19+
"strconv"
20+
1921
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
2022
"github.com/supertokens/supertokens-golang/supertokens"
2123
)
@@ -52,6 +54,20 @@ func MakeAPIImplementation() dashboardmodels.APIInterface {
5254

5355
authMode := string(options.Config.AuthMode)
5456

57+
isSearchEnabled := false
58+
querier, err := supertokens.GetNewQuerierInstanceOrThrowError(options.RecipeID)
59+
if err != nil {
60+
return "", err
61+
}
62+
cdiVersion, err := querier.GetQuerierAPIVersion()
63+
if err != nil {
64+
return "", err
65+
}
66+
if supertokens.MaxVersion(cdiVersion, "2.20") == cdiVersion {
67+
// Only enable search for CDI version 2.20 and above
68+
isSearchEnabled = true
69+
}
70+
5571
return `
5672
<html>
5773
<head>
@@ -61,6 +77,7 @@ func MakeAPIImplementation() dashboardmodels.APIInterface {
6177
window.dashboardAppPath = "` + dashboardAppPath + `"
6278
window.connectionURI = "` + connectionURI + `"
6379
window.authMode = "` + authMode + `"
80+
window.isSearchEnabled = "` + strconv.FormatBool(isSearchEnabled) + `"
6481
</script>
6582
<script defer src="` + bundleDomain + `/static/js/bundle.js"></script></head>
6683
<link href="` + bundleDomain + `/static/css/main.css" rel="stylesheet" type="text/css">
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* Copyright (c) 2022, VRAI Labs and/or its affiliates. All rights reserved.
2+
*
3+
* This software is licensed under the Apache License, Version 2.0 (the
4+
* "License") as published by the Apache Software Foundation.
5+
*
6+
* You may not use this file except in compliance with the License. You may
7+
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations
13+
* under the License.
14+
*/
15+
16+
package search
17+
18+
import (
19+
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
20+
"github.com/supertokens/supertokens-golang/supertokens"
21+
)
22+
23+
type searchTagsResponse struct {
24+
Status string `json:"status"`
25+
Tags []interface{} `json:"tags"`
26+
}
27+
28+
func SearchTagsGet(apiImplementation dashboardmodels.APIInterface, options dashboardmodels.APIOptions) (searchTagsResponse, error) {
29+
querier, querierErr := supertokens.GetNewQuerierInstanceOrThrowError("dashboard")
30+
31+
if querierErr != nil {
32+
return searchTagsResponse{}, querierErr
33+
}
34+
35+
apiResponse, apiErr := querier.SendGetRequest("/user/search/tags", nil)
36+
if apiErr != nil {
37+
return searchTagsResponse{}, apiErr
38+
}
39+
40+
return searchTagsResponse{
41+
Status: "OK",
42+
Tags: apiResponse["tags"].([]interface{}),
43+
}, nil
44+
}

recipe/dashboard/api/usersGet.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package api
22

33
import (
4+
"net/url"
45
"strconv"
6+
"strings"
57
"sync"
68

79
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
@@ -64,7 +66,24 @@ func UsersGet(apiImplementation dashboardmodels.APIInterface, options dashboardm
6466

6567
var usersResponse supertokens.UserPaginationResult
6668

67-
if timeJoinedOrder == "ASC" {
69+
u, err := url.Parse(req.URL.String())
70+
if err != nil {
71+
return UsersGetResponse{}, err
72+
}
73+
74+
queryParams, err := url.ParseQuery(u.RawQuery)
75+
if err != nil {
76+
return UsersGetResponse{}, err
77+
}
78+
79+
queryParamsObject := map[string]string{}
80+
for i, s := range queryParams {
81+
queryParamsObject[i] = strings.Join(s, ";")
82+
}
83+
84+
if len(queryParamsObject) != 0 {
85+
usersResponse, err = supertokens.GetUsersWithSearchParams(timeJoinedOrder, paginationTokenPtr, &limit, nil, queryParamsObject)
86+
} else if timeJoinedOrder == "ASC" {
6887
usersResponse, err = supertokens.GetUsersOldestFirst(paginationTokenPtr, &limit, nil)
6988
} else {
7089
usersResponse, err = supertokens.GetUsersNewestFirst(paginationTokenPtr, &limit, nil)

recipe/dashboard/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ const userEmailVerifyTokenAPI = "/api/user/email/verify/token"
1212
const userPasswordAPI = "/api/user/password"
1313
const signInAPI = "/api/signin"
1414
const signOutAPI = "/api/signout"
15+
const searchTagsAPI = "/api/search/tags"
1516
const dashboardAnalyticsAPI = "/api/analytics"

recipe/dashboard/recipe.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net/http"
2121

2222
"github.com/supertokens/supertokens-golang/recipe/dashboard/api"
23+
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/search"
2324
"github.com/supertokens/supertokens-golang/recipe/dashboard/api/userdetails"
2425
"github.com/supertokens/supertokens-golang/recipe/dashboard/dashboardmodels"
2526
"github.com/supertokens/supertokens-golang/supertokens"
@@ -163,6 +164,8 @@ func (r *Recipe) handleAPIRequest(id string, req *http.Request, res http.Respons
163164
return userdetails.UserEmailVerifyTokenPost(r.APIImpl, options)
164165
} else if id == userPasswordAPI {
165166
return userdetails.UserPasswordPut(r.APIImpl, options)
167+
} else if id == searchTagsAPI {
168+
return search.SearchTagsGet(r.APIImpl, options)
166169
} else if id == signOutAPI {
167170
return api.SignOutPost(r.APIImpl, options)
168171
} else if id == dashboardAnalyticsAPI {

recipe/dashboard/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ func getApiIdIfMatched(path supertokens.NormalisedURLPath, method string) (*stri
139139
return &val, nil
140140
}
141141

142+
if method == http.MethodGet && strings.HasSuffix(path.GetAsStringDangerous(), searchTagsAPI) {
143+
val := searchTagsAPI
144+
return &val, nil
145+
}
146+
142147
if method == http.MethodPost && strings.HasSuffix(path.GetAsStringDangerous(), dashboardAnalyticsAPI) {
143148
val := dashboardAnalyticsAPI
144149
return &val, nil

supertokens/constants.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ const (
2121
)
2222

2323
// VERSION current version of the lib
24-
const VERSION = "0.10.4"
24+
const VERSION = "0.10.5"
2525

2626
var (
27-
cdiSupported = []string{"2.8", "2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15", "2.16", "2.17", "2.18", "2.19"}
27+
cdiSupported = []string{"2.8", "2.9", "2.10", "2.11", "2.12", "2.13", "2.14", "2.15", "2.16", "2.17", "2.18", "2.19", "2.20"}
2828
)
2929

30-
const DashboardVersion = "0.5"
30+
const DashboardVersion = "0.6"

supertokens/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ func GetUserCount(includeRecipeIds *[]string) (float64, error) {
6060
}
6161

6262
func GetUsersOldestFirst(paginationToken *string, limit *int, includeRecipeIds *[]string) (UserPaginationResult, error) {
63-
return getUsers("ASC", paginationToken, limit, includeRecipeIds)
63+
return GetUsersWithSearchParams("ASC", paginationToken, limit, includeRecipeIds, nil)
6464
}
6565

6666
func GetUsersNewestFirst(paginationToken *string, limit *int, includeRecipeIds *[]string) (UserPaginationResult, error) {
67-
return getUsers("DESC", paginationToken, limit, includeRecipeIds)
67+
return GetUsersWithSearchParams("DESC", paginationToken, limit, includeRecipeIds, nil)
6868
}
6969

7070
func DeleteUser(userId string) error {

0 commit comments

Comments
 (0)