dl-commons 0.0.1-testing.57 → 0.0.2-testing.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/models/consts/env-vars.const.d.ts +1 -0
- package/dist/models/consts/env-vars.const.js +2 -1
- package/dist/models/consts/env-vars.const.js.map +1 -1
- package/dist/models/interfaces/smtp-api-config.interface.d.ts +5 -0
- package/dist/models/interfaces/smtp-api-config.interface.js +3 -0
- package/dist/models/interfaces/smtp-api-config.interface.js.map +1 -0
- package/dist/models/interfaces/smtp.interface.d.ts +5 -0
- package/dist/models/interfaces/smtp.interface.js +3 -0
- package/dist/models/interfaces/smtp.interface.js.map +1 -0
- package/dist/models/interfaces/user.interface.d.ts +1 -0
- package/dist/services/sessions.service.d.ts +2 -1
- package/dist/services/sessions.service.js.map +1 -1
- package/dist/services/smtp.service.d.ts +11 -0
- package/dist/services/smtp.service.js +71 -0
- package/dist/services/smtp.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/index.ts +7 -1
- package/src/models/consts/env-vars.const.ts +1 -0
- package/src/models/interfaces/smtp-api-config.interface.ts +5 -0
- package/src/models/interfaces/smtp.interface.ts +5 -0
- package/src/models/interfaces/user.interface.ts +1 -0
- package/src/services/sessions.service.ts +2 -1
- package/src/services/smtp.service.ts +71 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { validationExceptionFactory } from './factories/exception.factory';
|
|
|
5
5
|
import { BaseExceptionsFilter } from './filters/base-exception.filter';
|
|
6
6
|
import { AccessTokenGuard } from './guards/access-token.guard';
|
|
7
7
|
import { AllowPermissions, PermissionGuard } from './guards/permission.guard';
|
|
8
|
-
import { APP__PORT, APP__DEBUG, APP__ACCESS_TOKEN, MONGO__CS, REDIS__CS, KAFKA__BROKERS } from './models/consts/env-vars.const';
|
|
8
|
+
import { APP__PORT, APP__DEBUG, APP__ACCESS_TOKEN, MONGO__CS, REDIS__CS, KAFKA__BROKERS, APP__MONGO__CS, DL_SESSIONS__MONGO__CS } from './models/consts/env-vars.const';
|
|
9
9
|
import { I18nDTO } from './models/dtos/commons/i18n.dto';
|
|
10
10
|
import {
|
|
11
11
|
IMongoPage,
|
|
@@ -60,6 +60,8 @@ import { IGroupSession } from './models/interfaces/group-session.interface';
|
|
|
60
60
|
import { GroupState } from './models/enums/group-state.enum';
|
|
61
61
|
import { GroupSessionSchema, GroupSessionDocument, GroupSession } from './models/schemas/embedded/group-session.schema';
|
|
62
62
|
import { TeacherSchema, TeacherDocument, Teacher } from './models/schemas/embedded/teacher.schema';
|
|
63
|
+
import { ISMTPAPIConfig } from './models/interfaces/smtp-api-config.interface';
|
|
64
|
+
import { SMTPService } from './services/smtp.service';
|
|
63
65
|
|
|
64
66
|
export {
|
|
65
67
|
/**
|
|
@@ -67,6 +69,7 @@ export {
|
|
|
67
69
|
*/
|
|
68
70
|
SessionsService,
|
|
69
71
|
DictionariesService,
|
|
72
|
+
SMTPService,
|
|
70
73
|
|
|
71
74
|
/**
|
|
72
75
|
* Rest Wrapper
|
|
@@ -95,6 +98,8 @@ export {
|
|
|
95
98
|
APP__PORT,
|
|
96
99
|
APP__DEBUG,
|
|
97
100
|
APP__ACCESS_TOKEN,
|
|
101
|
+
APP__MONGO__CS,
|
|
102
|
+
DL_SESSIONS__MONGO__CS,
|
|
98
103
|
MONGO__CS,
|
|
99
104
|
REDIS__CS,
|
|
100
105
|
KAFKA__BROKERS,
|
|
@@ -134,6 +139,7 @@ export {
|
|
|
134
139
|
IStudentEmbedded,
|
|
135
140
|
ITeacher,
|
|
136
141
|
IGroupSession,
|
|
142
|
+
ISMTPAPIConfig,
|
|
137
143
|
|
|
138
144
|
/**
|
|
139
145
|
* Schemas & Documents
|
|
@@ -7,6 +7,7 @@ import { firstValueFrom } from 'rxjs';
|
|
|
7
7
|
import { Model } from 'mongoose';
|
|
8
8
|
import { Session, SessionDocument } from '../models/schemas/session.schema';
|
|
9
9
|
import { InjectModel } from '@nestjs/mongoose';
|
|
10
|
+
import { Types } from 'mongoose';
|
|
10
11
|
|
|
11
12
|
@Injectable()
|
|
12
13
|
export class SessionsService {
|
|
@@ -26,7 +27,7 @@ export class SessionsService {
|
|
|
26
27
|
//#endregion
|
|
27
28
|
|
|
28
29
|
//#region Public API
|
|
29
|
-
public async create(userId: string, userAgent: string, ip: string) {
|
|
30
|
+
public async create(userId: string | Types.ObjectId, userAgent: string, ip: string) {
|
|
30
31
|
try {
|
|
31
32
|
const endpoint = `${this._baseUrl}/v1/sessions/${userId}`;
|
|
32
33
|
const headers = { 'user-agent': userAgent, 'x-ip': ip };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { ConfigService } from '@nestjs/config';
|
|
3
|
+
import { catchError, firstValueFrom, map } from 'rxjs';
|
|
4
|
+
import { Injectable } from '@nestjs/common';
|
|
5
|
+
import { RESTResponseBody, RESTError } from '../models/dtos/wrappers/rest-wrapper.class';
|
|
6
|
+
import { ISMTP } from '../models/interfaces/smtp.interface';
|
|
7
|
+
|
|
8
|
+
@Injectable()
|
|
9
|
+
export class SMTPService {
|
|
10
|
+
//#region Private Members
|
|
11
|
+
private _baseUrl: string;
|
|
12
|
+
//#endregion
|
|
13
|
+
|
|
14
|
+
//#region Constructor
|
|
15
|
+
constructor(private readonly _httpService: HttpService, private readonly _configService: ConfigService) {
|
|
16
|
+
this._baseUrl = this._configService.getOrThrow('DL_SMTP__REST__BASE_URL');
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
|
|
20
|
+
//#region Public API
|
|
21
|
+
public async send(subject: string, from: string, to: string, html: string, profileId: string) {
|
|
22
|
+
const requestBody = {
|
|
23
|
+
data: {
|
|
24
|
+
from,
|
|
25
|
+
to: [to],
|
|
26
|
+
subject,
|
|
27
|
+
html,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const response$ = this._httpService.post<RESTResponseBody<ISMTP>>(`${this._baseUrl}/v1/emails/send`, requestBody, { params: { profileId } });
|
|
32
|
+
const response = await firstValueFrom(response$);
|
|
33
|
+
|
|
34
|
+
if (response.data.errors) {
|
|
35
|
+
throw new RESTError('smtp_api_error', response.data.errors);
|
|
36
|
+
}
|
|
37
|
+
if (!response.data || !response.data.result) {
|
|
38
|
+
throw new RESTError('smtp_api_error', 'empty response');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return response.data.result.data;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public send$(subject: string, from: string, to: string, html: string, profileId: string) {
|
|
45
|
+
const requestBody = {
|
|
46
|
+
data: {
|
|
47
|
+
from,
|
|
48
|
+
to: [to],
|
|
49
|
+
subject,
|
|
50
|
+
html,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const response$ = this._httpService.post<RESTResponseBody<ISMTP>>(`${this._baseUrl}/v1/emails/send`, requestBody, { params: { profileId } });
|
|
55
|
+
return response$.pipe(
|
|
56
|
+
map((response) => {
|
|
57
|
+
if (response.data.errors) {
|
|
58
|
+
throw new RESTError('smtp_api_error', response.data.errors);
|
|
59
|
+
}
|
|
60
|
+
if (!response.data || !response.data.result) {
|
|
61
|
+
throw new RESTError('smtp_api_error', 'empty response');
|
|
62
|
+
}
|
|
63
|
+
return response.data.result.data;
|
|
64
|
+
}),
|
|
65
|
+
catchError((e) => {
|
|
66
|
+
throw new RESTError('smtp_api_error', e);
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
}
|