@@ -35,28 +35,29 @@ export class ApiClient {
3535 return this . accessToken ?. token . access_token as string | undefined ;
3636 } ;
3737
38- private authMiddleware = ( apiClient : ApiClient ) : Middleware => ( {
39- async onRequest ( { request, schemaPath } ) {
38+ private authMiddleware : Middleware = {
39+ onRequest : async ( { request, schemaPath } ) => {
4040 if ( schemaPath . startsWith ( "/api/private/unauth" ) || schemaPath . startsWith ( "/api/oauth" ) ) {
4141 return undefined ;
4242 }
4343
4444 try {
45- const accessToken = await apiClient . getAccessToken ( ) ;
45+ const accessToken = await this . getAccessToken ( ) ;
4646 request . headers . set ( "Authorization" , `Bearer ${ accessToken } ` ) ;
4747 return request ;
4848 } catch {
4949 // ignore not availble tokens, API will return 401
5050 }
5151 } ,
52- } ) ;
53- private errorMiddleware = ( ) : Middleware => ( {
52+ } ;
53+
54+ private readonly errorMiddleware : Middleware = {
5455 async onResponse ( { response } ) {
5556 if ( ! response . ok ) {
5657 throw await ApiClientError . fromResponse ( response ) ;
5758 }
5859 } ,
59- } ) ;
60+ } ;
6061
6162 constructor ( options ?: ApiClientOptions ) {
6263 this . options = {
@@ -85,12 +86,14 @@ export class ApiClient {
8586 tokenPath : "/api/oauth/token" ,
8687 } ,
8788 } ) ;
88- this . client . use ( this . authMiddleware ( this ) ) ;
89+ this . client . use ( this . authMiddleware ) ;
8990 }
90- this . client . use ( this . errorMiddleware ( ) ) ;
91+ this . client . use ( this . errorMiddleware ) ;
9192 }
9293
93- async getIpInfo ( ) {
94+ public async getIpInfo ( ) : Promise < {
95+ currentIpv4Address : string ;
96+ } > {
9497 const accessToken = await this . getAccessToken ( ) ;
9598
9699 const endpoint = "api/private/ipinfo" ;
@@ -108,10 +111,9 @@ export class ApiClient {
108111 throw await ApiClientError . fromResponse ( response ) ;
109112 }
110113
111- const responseBody = await response . json ( ) ;
112- return responseBody as {
114+ return ( await response . json ( ) ) as Promise < {
113115 currentIpv4Address : string ;
114- } ;
116+ } > ;
115117 }
116118
117119 // DO NOT EDIT. This is auto-generated code.
0 commit comments