import { injectable , inject } from 'inversify' ; import { RPC_SERVER_FACTORY , RpcServerFactory , RpcServer , RpcMethod } from '@centsideas/rpc' ; import { AuthenticationCommandsService , AuthenticationCommands , GetEvents , } from '@centsideas/schemas' ; import { ServiceServer } from '@centsideas/utils' ; import { UserId } from '@centsideas/types' ; import { AuthenticationService } from './authentication.service' ; @ injectable ( ) export class AuthenticationServer extends ServiceServer implements AuthenticationCommands . Service { private rpcServer : RpcServer = this . rpcServerFactory ( { services : [ AuthenticationCommandsService ] , handlerClassInstance : this , } ) ; constructor ( private service , @ inject ( RPC_SERVER_FACTORY ) private rpcServerFactory ) { super ( ) ; } @ RpcMethod ( AuthenticationCommandsService ) async requestEmailSignIn ( { email } ) { await this . service . requestEmailSignIn ( email ) ; } @ RpcMethod ( AuthenticationCommandsService ) async confirmEmailSignIn ( { signInToken } ) { return this . service . confirmEmailSignIn ( signInToken ) ; } @ RpcMethod ( AuthenticationCommandsService ) async googleSignInUrl ( ) { return this . service . googleSignInUrl ( ) ; } @ RpcMethod ( AuthenticationCommandsService ) async googleSignIn ( { code } ) { return this . service . googleSignIn ( code ) ; } @ RpcMethod ( AuthenticationCommandsService ) async refreshToken ( { refreshToken } ) { return this . service . refresTokens ( refreshToken ) ; } @ RpcMethod ( AuthenticationCommandsService ) async signOut ( { refreshToken } ) { await this . service . signOut ( refreshToken ) ; } @ RpcMethod ( AuthenticationCommandsService ) async revokeRefreshToken ( { sessionId } ) { await this . service . revokeRefreshToken ( sessionId ) ; } @ RpcMethod ( AuthenticationCommandsService ) async getEvents ( { after } ) { const events = await this . service . getEvents ( after ) ; return { events } ; } @ RpcMethod ( AuthenticationCommandsService ) async getEventsByUserId ( { userId } ) { const events = await this . service . getEventsByUserId ( UserId . fromString ( userId ) ) ; return { events } ; } async healthcheck ( ) { return this . rpcServer . isRunning ; } async shutdownHandler ( ) { await this . rpcServer . disconnect ( ) ; } }