1
- import axios , { AxiosInstance } from "axios" ;
1
+ import axios , { AxiosInstance , AxiosRequestConfig , AxiosResponse } from "axios" ;
2
+ import * as operations from "./models/operations" ;
2
3
import * as utils from "../internal/utils" ;
3
4
import { Security } from "./models/shared" ;
4
5
6
+
5
7
import { ApiEndpoints } from "./apiendpoints" ;
6
8
import { Apis } from "./apis" ;
7
9
import { Embeds } from "./embeds" ;
@@ -39,8 +41,8 @@ export class SDK {
39
41
public _securityClient : AxiosInstance ;
40
42
public _serverURL : string ;
41
43
private _language = "typescript" ;
42
- private _sdkVersion = "0.10 .0" ;
43
- private _genVersion = "0.20.0 " ;
44
+ private _sdkVersion = "0.11 .0" ;
45
+ private _genVersion = "0.20.1 " ;
44
46
45
47
constructor ( props : SDKProps ) {
46
48
this . _serverURL = props . serverUrl ?? ServerList [ ServerProd ] ;
@@ -58,6 +60,7 @@ export class SDK {
58
60
this . _securityClient = this . _defaultClient ;
59
61
}
60
62
63
+
61
64
this . apiEndpoints = new ApiEndpoints (
62
65
this . _defaultClient ,
63
66
this . _securityClient ,
@@ -112,4 +115,42 @@ export class SDK {
112
115
this . _genVersion
113
116
) ;
114
117
}
118
+
119
+ /**
120
+ * validateApiKey - Validate the current api key.
121
+ **/
122
+ validateApiKey (
123
+ config ?: AxiosRequestConfig
124
+ ) : Promise < operations . ValidateApiKeyResponse > {
125
+ const baseURL : string = this . _serverURL ;
126
+ const url : string = baseURL . replace ( / \/ $ / , "" ) + "/v1/auth/validate" ;
127
+
128
+ const client : AxiosInstance = this . _securityClient ! ;
129
+
130
+
131
+ const r = client . request ( {
132
+ url : url ,
133
+ method : "get" ,
134
+ ...config ,
135
+ } ) ;
136
+
137
+ return r . then ( ( httpRes : AxiosResponse ) => {
138
+ const contentType : string = httpRes ?. headers ?. [ "content-type" ] ?? "" ;
139
+
140
+ if ( httpRes ?. status == null ) throw new Error ( `status code not found in response: ${ httpRes } ` ) ;
141
+ const res : operations . ValidateApiKeyResponse = { statusCode : httpRes . status , contentType : contentType } ;
142
+ switch ( true ) {
143
+ case httpRes ?. status == 200 :
144
+ break ;
145
+ default :
146
+ if ( utils . matchContentType ( contentType , `application/json` ) ) {
147
+ res . error = httpRes ?. data ;
148
+ }
149
+ break ;
150
+ }
151
+
152
+ return res ;
153
+ } )
154
+ }
155
+
115
156
}
0 commit comments