import { JwtGenerator } from '../JwtGenerator' ; import { IAccessToken , IAccessTokenProvider , ITokenContext } from './interfaces' ; import { IExtraData } from '../../Cards/ICard' ; /**
 * Implementation of  IAccessTokenProvider that generates a
 * new JWT whenever it is requested by the clients.
 *
 * This class is meant to be used on the server side only.
  export class GeneratorJwtProvider implements IAccessTokenProvider { /**
     * Creates a new instance of `GeneratorJwtProvider` with the given
     *  JwtGenerator , additional data and default identity.
     *
     *  param { JwtGenerator } jwtGenerator param { IExtraData } additionalData param { string } defaultIdentity constructor ( private readonly jwtGenerator , private readonly additionalData ? , private readonly defaultIdentity ? ) { if ( jwtGenerator == null ) { throw new TypeError ( '`jwtGenerator` is required' ) ; } } /**
     * Returns a `Promise` fulfilled with the JWT obtained from the call
     * to  GeneratorJwtProvider . jwtGenerator JwtGenerator . generateToken * method, passing it the  GeneratorJwtProvider . additionalData and
     *  GeneratorJwtProvider . defaultIdentity param { ITokenContext } context returns { Promise < IAccessToken > } getToken ( context ) { return Promise . resolve ( ) . then ( ( ) => { const jwt = this . jwtGenerator . generateToken ( context . identity || this . defaultIdentity || '' , this . additionalData ) ; return jwt ; } ) ; } }