import { Binding , Component , ControllerClass , CoreBindings , inject , ProviderMap , } from '@loopback/core' ; import { RestApplication } from '@loopback/rest' ; import { BearerVerifierBindings , BearerVerifierComponent , BearerVerifierConfig , BearerVerifierType , CoreComponent , SECURITY_SCHEME_SPEC , ServiceSequence , } from '@sourceloop/core' ; import { ChatServiceBindings } from './keys' ; import { IChatServiceConfig } from './types' ; import { AuthenticationComponent } from 'loopback4-authentication' ; import { AuthorizationBindings , AuthorizationComponent , } from 'loopback4-authorization' ; import { Class , Model , Repository } from '@loopback/repository' ; import { Message , MessageRecipient } from './models' ; import { MessageRecipientRepository , MessageRepository } from './repositories' ; import { MessageController , MessageMessageController , MessageMessageRecipientController , MessageRecipientController , MessageRecipientMessageController , } from './controllers' ; export class ChatServiceComponent implements Component { constructor ( @ inject ( CoreBindings . APPLICATION_INSTANCE ) private readonly application , @ inject ( ChatServiceBindings . Config , { optional : true } ) private readonly chatConfig ? ) { this . bindings = [ ] ; this . providers = { } ; this . application . component ( CoreComponent ) ; this . application . api ( { openapi : '3.0.0' , info : { title : 'Chat Service' , version : '1.0.0' , } , paths : { } , components : { securitySchemes : SECURITY_SCHEME_SPEC , } , servers : [ { url : '/' } ] , } ) ; if ( ! this . chatConfig ?. useCustomSequence ) { this . setupSequence ( ) ; } this . repositories = [ MessageRepository , MessageRecipientRepository ] ; this . models = [ Message , MessageRecipient ] ; this . controllers = [ MessageController , MessageRecipientController , MessageMessageController , MessageRecipientMessageController , MessageMessageRecipientController , ] ; } providers ? : ProviderMap = { } ; bindings ? : Binding [ ] = [ ] ; /**
     * An optional list of Repository classes to bind for dependency injection
     * via `app.repository()` API.
     */ repositories ? : Class < Repository < Model > > [ ] ; /**
     * An optional list of Model classes to bind for dependency injection
     * via `app.model()` API.
     */ models ? : Class < Model > [ ] ; /**
     * An array of controller classes
     */ controllers ? : ControllerClass [ ] ; /**
     * Setup ServiceSequence by default if no other sequnce provided
     *
     */ setupSequence ( ) { this . application . sequence ( ServiceSequence ) ; this . application . component ( AuthenticationComponent ) ; this . application . bind ( BearerVerifierBindings . Config ) . to ( { authServiceUrl : '' , type : BearerVerifierType . service , } as BearerVerifierConfig ) ; this . application . component ( BearerVerifierComponent ) ; this . application . bind ( AuthorizationBindings . CONFIG ) . to ( { allowAlwaysPaths : [ '/explorer' ] , } ) ; this . application . component ( AuthorizationComponent ) ; } }