1- import axios , { AxiosInstance } from "axios" ;
1+ import axios , { AxiosInstance , AxiosRequestConfig , AxiosResponse } from "axios" ;
2+ import * as operations from "./models/operations" ;
23import * as utils from "../internal/utils" ;
34import { Security } from "./models/shared" ;
45
6+
57import { ApiEndpoints } from "./apiendpoints" ;
68import { Apis } from "./apis" ;
79import { Embeds } from "./embeds" ;
@@ -39,8 +41,8 @@ export class SDK {
3941 public _securityClient : AxiosInstance ;
4042 public _serverURL : string ;
4143 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 " ;
4446
4547 constructor ( props : SDKProps ) {
4648 this . _serverURL = props . serverUrl ?? ServerList [ ServerProd ] ;
@@ -58,6 +60,7 @@ export class SDK {
5860 this . _securityClient = this . _defaultClient ;
5961 }
6062
63+
6164 this . apiEndpoints = new ApiEndpoints (
6265 this . _defaultClient ,
6366 this . _securityClient ,
@@ -112,4 +115,42 @@ export class SDK {
112115 this . _genVersion
113116 ) ;
114117 }
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+
115156}
0 commit comments