11import { ForbiddenError , CustomError , isLiquidError } from './constants/errors.js'
2- import Cache , { CacheOptions } from './service/cache.js'
3- import Logger , { LoggerInterface } from './service/logger.js'
2+ import Cache from './service/cache.js'
3+ import Logger from './service/logger.js'
44import ScopeManager from './service/scope-manager.js'
55import { ApiClient } from './service/api-client.js'
6-
7- export { CacheOptions , LoggerInterface }
8-
9- export interface TokenInfo {
10- accessToken ?: string ;
11- accessTokenExpiresAt ?: string ;
12- scope ?: string ;
13- user ?: {
14- [ key : string ] : any ;
15- } ;
16- [ key : string ] : any ;
17- }
18-
19- export interface TokenResponse {
20- accessToken : string | null ;
21- accessTokenExpiry : Date ;
22- }
23-
24- export interface LiquidNodeAuthenticatorOptions {
25- host : string ;
26- clientId : string ;
27- clientSecret : string ;
28- scope ?: string | string [ ] ;
29- cacheOptions ?: CacheOptions ;
30- debugging ?: boolean ;
31- logger ?: LoggerInterface | any ;
32- }
33-
34- export type ConnectorOptions = LiquidNodeAuthenticatorOptions ;
6+ import type { CacheOptions } from './service/cache.js'
7+ import type { LoggerInterface } from './service/logger.js'
358
369/**
3710 * LiquidNodeAuthenticator provides methods for authenticating and obtaining access tokens
@@ -55,9 +28,9 @@ class LiquidNodeAuthenticator {
5528 * Creates an instance of LiquidNodeAuthenticator.
5629 *
5730 * @constructor
58- * @param {LiquidNodeAuthenticatorOptions } options - Configuration options for the LiquidNodeAuthenticator.
31+ * @param {LiquidNodeAuthenticator.Options } options - Configuration options for the LiquidNodeAuthenticator.
5932 */
60- constructor ( { host, clientId, clientSecret, scope = '*' , cacheOptions, debugging = true , logger } : LiquidNodeAuthenticatorOptions ) {
33+ constructor ( { host, clientId, clientSecret, scope = '*' , cacheOptions, debugging = true , logger } : LiquidNodeAuthenticator . Options ) {
6134 this . clientId = clientId
6235 this . clientSecret = clientSecret
6336 this . scope = Array . isArray ( scope ) ? scope . join ( ',' ) : scope
@@ -80,7 +53,7 @@ class LiquidNodeAuthenticator {
8053 * @throws {NetworkError } If a network error occurs during the authentication process.
8154 * @returns {Object } The user's token information if authentication is successful.
8255 */
83- async authenticate ( token : string ) : Promise < TokenInfo > {
56+ async authenticate ( token : string ) : Promise < LiquidNodeAuthenticator . TokenInfo > {
8457 try {
8558 if ( ! token ) { throw new ForbiddenError ( ) }
8659 const cacheKey = `token:${ token } `
@@ -126,7 +99,7 @@ class LiquidNodeAuthenticator {
12699 * @throws {UnauthorizedError } If the OAuth server returns an unauthorized status.
127100 * @returns {Object } The access token and its expiration details.
128101 */
129- async getAccessToken ( ) : Promise < TokenResponse > {
102+ async getAccessToken ( ) : Promise < LiquidNodeAuthenticator . TokenResponse > {
130103 try {
131104 const now = new Date ( )
132105 if ( this . accessTokenExpiry . getTime ( ) <= now . getTime ( ) ) {
@@ -156,12 +129,45 @@ class LiquidNodeAuthenticator {
156129 * Checks if a given scope is allowed based on the user's allowed scopes.
157130 *
158131 * @param {string } scope - The scope to check.
159- * @param {Object } token - The Express response object.
132+ * @param {Object } token - The token object returned from authenticate() .
160133 * @returns {boolean } True if the scope is allowed, false otherwise.
161134 */
162- checkTokenScope ( scope : string , token : TokenInfo | any ) : boolean {
135+ checkTokenScope ( scope : string , token : LiquidNodeAuthenticator . TokenInfo | any ) : boolean {
163136 return this . scopeManager . checkTokenScope ( scope , token )
164137 }
165138}
166139
167- export default LiquidNodeAuthenticator
140+ // eslint-disable-next-line @typescript-eslint/no-namespace
141+ namespace LiquidNodeAuthenticator {
142+ export interface TokenInfo {
143+ accessToken ?: string ;
144+ accessTokenExpiresAt ?: string ;
145+ scope ?: string ;
146+ user ?: {
147+ [ key : string ] : any ;
148+ } ;
149+ [ key : string ] : any ;
150+ }
151+
152+ export interface TokenResponse {
153+ accessToken : string | null ;
154+ accessTokenExpiry : Date ;
155+ }
156+
157+ export interface Options {
158+ host : string ;
159+ clientId : string ;
160+ clientSecret : string ;
161+ scope ?: string | string [ ] ;
162+ cacheOptions ?: CacheOptions ;
163+ debugging ?: boolean ;
164+ logger ?: LoggerInterface | any ;
165+ }
166+
167+ /** @deprecated Use Options instead */
168+ export type ConnectorOptions = Options ;
169+ /** @deprecated Use Options instead */
170+ export type LiquidNodeAuthenticatorOptions = Options ;
171+ }
172+
173+ export = LiquidNodeAuthenticator
0 commit comments