-
Notifications
You must be signed in to change notification settings - Fork 70
/
component.ts
118 lines (111 loc) · 3.07 KB
/
component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2023 Sourcefuse Technologies
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import {
Binding,
Component,
ControllerClass,
CoreBindings,
inject,
} from '@loopback/core';
import {Class, Model, Repository} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {
BearerVerifierBindings,
BearerVerifierComponent,
BearerVerifierConfig,
BearerVerifierType,
CoreComponent,
SECURITY_SCHEME_SPEC,
ServiceSequence,
} from '@sourceloop/core';
import {AuthenticationComponent} from 'loopback4-authentication';
import {
AuthorizationBindings,
AuthorizationComponent,
} from 'loopback4-authorization';
import {
CollectorController,
OriginatorController,
ReplyAndForwardController,
} from './controllers';
import {InMailBindings} from './keys';
import {Attachment, Group, Message, Meta, Thread} from './models';
import {
AttachmentRepository,
GroupRepository,
MessageRepository,
MetaRepository,
ThreadRepository,
ThreadViewRepository,
} from './repositories';
import {IInMailServiceConfig} from './types';
export class InMailServiceComponent implements Component {
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[];
bindings?: Binding[];
constructor(
@inject(CoreBindings.APPLICATION_INSTANCE)
private readonly application: RestApplication,
@inject(InMailBindings.Config, {optional: true})
private readonly inMailConfig?: IInMailServiceConfig,
) {
this.application.component(CoreComponent);
this.models = [Meta, Thread, Message, Group, Attachment];
this.controllers = [
OriginatorController,
CollectorController,
ReplyAndForwardController,
];
this.repositories = [
MetaRepository,
ThreadRepository,
AttachmentRepository,
MessageRepository,
GroupRepository,
ThreadViewRepository,
];
if (!this.inMailConfig?.useCustomSequence) {
// Mount default sequence if needed
this.setupSequence();
}
// Set up default home page
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);
this.application.api({
openapi: '3.0.0',
info: {
title: 'In-mail Service',
version: '1.0.0',
},
paths: {},
components: {
securitySchemes: SECURITY_SCHEME_SPEC,
},
servers: [{url: '/'}],
});
}
/**
* Setup ServiceSequence by default if no other sequnce provided
*/
setupSequence() {
this.application.sequence(ServiceSequence);
}
}