'use strict' ; import { Router , RequestHandler , Request , Response , NextFunction } from 'express' ; import { setupMetaverseAPI , finishMetaverseAPI } from '@Route-Tools/middleware' ; import { accountFromAuthToken } from '@Route-Tools/middleware' ; import { Tokens , TokenScope } from '@Entities/Tokens' ; import { Logger } from '@Tools/Logging' ; import { PaginationInfo } from '@Entities/EntityFilters/PaginationInfo' ; import { AccountScopeFilter } from '@Entities/EntityFilters/AccountScopeFilter' ; const procGetTokens = async ( req , resp , next ) => { Logger . debug ( 'procGetTokens' ) ; if ( req . vAuthAccount ) { const pager = new PaginationInfo ( ) ; const scoper = new AccountScopeFilter ( req . vAuthAccount , 'accountId' ) ; pager . parametersFromRequest ( req ) ; scoper . parametersFromRequest ( req ) ; const toks = [ ] ; for await ( const tok of Tokens . enumerateAsync ( pager , scoper ) ) { toks . push ( { 'tokenId' : tok . id , 'id' : tok . id , 'token' : tok . token , 'accountId' : tok . accountId , 'refresh_token' : tok . refreshToken , 'scope' : tok . scope , 'creation_time' : tok . whenCreated ?. toISOString ( ) , 'creation_time_s' : tok . whenCreated ?. getTime ( ) . toString ( ) , 'expiration_time' : tok . expirationTime ?. toISOString ( ) , 'expiration_time_s' : tok . expirationTime ?. getTime ( ) . toString ( ) } ) ; } ; req . vRestResp . Data = { tokens : toks } ; scoper . addResponseFields ( req ) ; pager . addResponseFields ( req ) ; } else { req . vRestResp . respondFailure ( req . vAccountError ?? 'Not logged in' ) ; } ; next ( ) ; } ; export const name = '/api/v1/tokens' ; export const router = Router ( ) ; router . get ( '/api/v1/tokens' , [ setupMetaverseAPI , accountFromAuthToken , procGetTokens , finishMetaverseAPI ] ) ;