mblabs-roccato-backend-commons 1.0.7 → 1.1.0

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.
Files changed (95) hide show
  1. package/bitbucket-pipelines.yml +6 -48
  2. package/dist/database/entities/account.d.ts +1 -2
  3. package/dist/database/entities/account.js +2 -7
  4. package/dist/database/entities/address.d.ts +2 -1
  5. package/dist/database/entities/address.js +6 -5
  6. package/dist/database/entities/company-address.d.ts +2 -0
  7. package/dist/database/entities/company-address.js +7 -0
  8. package/dist/database/migrations/1748448589934-CreateAccountsTable.js +1 -6
  9. package/dist/database/migrations/1750432386920-CreateAddressTable.js +0 -5
  10. package/dist/database/migrations/index.js +0 -4
  11. package/dist/interfaces/aws.d.ts +41 -67
  12. package/dist/interfaces/azure.d.ts +38 -61
  13. package/dist/interfaces/firebase.d.ts +3 -7
  14. package/dist/interfaces/gcp.d.ts +5 -11
  15. package/dist/interfaces/grafana.d.ts +2 -6
  16. package/dist/interfaces/keycloak.d.ts +4 -171
  17. package/dist/interfaces/nodemailer.d.ts +16 -20
  18. package/dist/interfaces/redis.d.ts +8 -49
  19. package/dist/interfaces/sendgrid.d.ts +13 -15
  20. package/dist/services/aws/cloudwatch.d.ts +1 -1
  21. package/dist/services/aws/cloudwatch.js +38 -38
  22. package/dist/services/aws/pinpoint.d.ts +3 -3
  23. package/dist/services/aws/pinpoint.js +29 -29
  24. package/dist/services/aws/s3.d.ts +5 -5
  25. package/dist/services/aws/s3.js +55 -59
  26. package/dist/services/aws/secret-manager.d.ts +1 -1
  27. package/dist/services/aws/secret-manager.js +5 -5
  28. package/dist/services/aws/sqs.d.ts +3 -3
  29. package/dist/services/aws/sqs.js +16 -16
  30. package/dist/services/azure/application-insights.d.ts +4 -4
  31. package/dist/services/azure/application-insights.js +12 -12
  32. package/dist/services/azure/communication.d.ts +3 -3
  33. package/dist/services/azure/communication.js +17 -17
  34. package/dist/services/azure/keyvault.d.ts +1 -1
  35. package/dist/services/azure/keyvault.js +3 -3
  36. package/dist/services/azure/storage-blob.d.ts +3 -3
  37. package/dist/services/azure/storage-blob.js +22 -22
  38. package/dist/services/firebase.d.ts +2 -2
  39. package/dist/services/firebase.js +10 -12
  40. package/dist/services/gcp/drive.d.ts +1 -1
  41. package/dist/services/gcp/drive.js +4 -4
  42. package/dist/services/gcp/secrets.d.ts +1 -1
  43. package/dist/services/gcp/secrets.js +8 -6
  44. package/dist/services/gcp/sheets.d.ts +1 -1
  45. package/dist/services/gcp/sheets.js +6 -6
  46. package/dist/services/grafana.d.ts +2 -2
  47. package/dist/services/grafana.js +12 -12
  48. package/dist/services/keycloak.d.ts +2 -14
  49. package/dist/services/keycloak.js +24 -300
  50. package/dist/services/nodemailer.d.ts +2 -2
  51. package/dist/services/nodemailer.js +109 -19
  52. package/dist/services/redis.d.ts +8 -6
  53. package/dist/services/redis.js +24 -53
  54. package/dist/services/sendgrid.d.ts +1 -1
  55. package/dist/services/sendgrid.js +10 -10
  56. package/package.json +1 -1
  57. package/src/database/entities/account.ts +3 -5
  58. package/src/database/entities/address.ts +7 -4
  59. package/src/database/entities/company-address.ts +5 -0
  60. package/src/database/migrations/1748448589934-CreateAccountsTable.ts +1 -6
  61. package/src/database/migrations/1750432386920-CreateAddressTable.ts +0 -5
  62. package/src/database/migrations/index.ts +0 -4
  63. package/src/interfaces/aws.ts +55 -81
  64. package/src/interfaces/azure.ts +50 -71
  65. package/src/interfaces/firebase.ts +6 -10
  66. package/src/interfaces/gcp.ts +8 -14
  67. package/src/interfaces/grafana.ts +5 -9
  68. package/src/interfaces/keycloak.ts +7 -190
  69. package/src/interfaces/nodemailer.ts +18 -22
  70. package/src/interfaces/redis.ts +8 -54
  71. package/src/interfaces/sendgrid.ts +14 -16
  72. package/src/services/aws/cloudwatch.ts +39 -39
  73. package/src/services/aws/pinpoint.ts +30 -30
  74. package/src/services/aws/s3.ts +55 -59
  75. package/src/services/aws/secret-manager.ts +7 -8
  76. package/src/services/aws/sqs.ts +17 -23
  77. package/src/services/azure/application-insights.ts +12 -12
  78. package/src/services/azure/communication.ts +18 -18
  79. package/src/services/azure/keyvault.ts +3 -3
  80. package/src/services/azure/storage-blob.ts +30 -34
  81. package/src/services/firebase.ts +11 -21
  82. package/src/services/gcp/drive.ts +5 -8
  83. package/src/services/gcp/secrets.ts +10 -9
  84. package/src/services/gcp/sheets.ts +7 -10
  85. package/src/services/grafana.ts +12 -18
  86. package/src/services/keycloak.ts +25 -381
  87. package/src/services/nodemailer.ts +110 -19
  88. package/src/services/redis.ts +22 -58
  89. package/src/services/sendgrid.ts +11 -11
  90. package/dist/database/migrations/1750690818577-CreateAccountAddressTable.d.ts +0 -5
  91. package/dist/database/migrations/1750690818577-CreateAccountAddressTable.js +0 -94
  92. package/dist/database/migrations/1750691840822-CreateAccountDetailsTable.d.ts +0 -5
  93. package/dist/database/migrations/1750691840822-CreateAccountDetailsTable.js +0 -99
  94. package/src/database/migrations/1750690818577-CreateAccountAddressTable.ts +0 -98
  95. package/src/database/migrations/1750691840822-CreateAccountDetailsTable.ts +0 -99
@@ -2,17 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const googleapis_1 = require("googleapis");
4
4
  class GoogleSheetsService {
5
- async readSheet({ credentials, data, }) {
5
+ async readSheet(req) {
6
6
  const instance = googleapis_1.google.sheets({
7
7
  version: 'v4',
8
- auth: credentials.apiKey,
8
+ auth: req.credentials.apiKey,
9
9
  });
10
- const { data: response } = await instance.spreadsheets.values.batchGet({
11
- spreadsheetId: data.spreadsheet,
12
- ranges: data.tabs,
10
+ const { data } = await instance.spreadsheets.values.batchGet({
11
+ spreadsheetId: req.spreadsheetId,
12
+ ranges: req.tabs,
13
13
  });
14
14
  return {
15
- sheet: response,
15
+ sheet: data,
16
16
  };
17
17
  }
18
18
  }
@@ -1,7 +1,7 @@
1
1
  import { Grafana, IGrafanaService } from '../interfaces/grafana';
2
2
  declare class GrafanaService implements IGrafanaService {
3
- getDashboard({ credentials, data, }: Grafana.GetDashboard.Request): Promise<Grafana.GetDashboard.Response>;
4
- searchDashboard({ credentials, data, }: Grafana.SearchDashboard.Request): Promise<Grafana.SearchDashboard.Response>;
3
+ getDashboard(req: Grafana.GetDashboard.Request): Promise<Grafana.GetDashboard.Response>;
4
+ searchDashboard(req: Grafana.SearchDashboard.Request): Promise<Grafana.SearchDashboard.Response>;
5
5
  }
6
6
  declare const _default: GrafanaService;
7
7
  export default _default;
@@ -5,33 +5,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const http_1 = __importDefault(require("./http"));
7
7
  class GrafanaService {
8
- async getDashboard({ credentials, data, }) {
9
- const { data: response } = await http_1.default.request({
8
+ async getDashboard(req) {
9
+ const { data } = await http_1.default.request({
10
10
  method: 'get',
11
- baseURL: credentials.url,
12
- resourcePath: `/api/dashboards/uid/${data.uid}`,
11
+ baseURL: req.credentials.url,
12
+ resourcePath: `/api/dashboards/uid/${req.uid}`,
13
13
  headers: {
14
- Authorization: `Bearer ${credentials.apiKey}`,
14
+ Authorization: `Bearer ${req.credentials.apiKey}`,
15
15
  },
16
16
  });
17
17
  return {
18
- dashboard: response,
18
+ dashboard: data,
19
19
  };
20
20
  }
21
- async searchDashboard({ credentials, data, }) {
22
- const { data: response } = await http_1.default.request({
21
+ async searchDashboard(req) {
22
+ const { data } = await http_1.default.request({
23
23
  method: 'get',
24
- baseURL: credentials.url,
24
+ baseURL: req.credentials.url,
25
25
  resourcePath: '/api/search',
26
26
  headers: {
27
- Authorization: `Bearer ${credentials.apiKey}`,
27
+ Authorization: `Bearer ${req.credentials.apiKey}`,
28
28
  },
29
29
  query: {
30
- query: data.query,
30
+ query: req.query,
31
31
  },
32
32
  });
33
33
  return {
34
- dashboards: response,
34
+ dashboards: data,
35
35
  };
36
36
  }
37
37
  }
@@ -1,19 +1,7 @@
1
1
  import { IKeycloakService, Keycloak } from '../interfaces/keycloak';
2
2
  declare class KeycloakService implements IKeycloakService {
3
- authenticate({ credentials, data, url, }: Keycloak.Authenticate.Request): Promise<Keycloak.Authenticate.Response>;
4
- authenticateServer({ credentials, url, }: Keycloak.AuthenticateServer.Request): Promise<Keycloak.AuthenticateServer.Response>;
5
- refreshAccess({ credentials, data, url, }: Keycloak.RefreshAccess.Request): Promise<Keycloak.RefreshAccess.Response>;
6
- revokeAccess({ credentials, data, url, }: Keycloak.RevokeAccess.Request): Promise<void>;
7
- createUser({ credentials, data, url, }: Keycloak.CreateUser.Request): Promise<void>;
8
- updateUser({ credentials, data, url, }: Keycloak.UpdateUser.Request): Promise<void>;
9
- getUser({ credentials, data, url, }: Keycloak.GetUser.Request): Promise<Keycloak.GetUser.Response>;
10
- deleteUser({ credentials, data, url, }: Keycloak.DeleteUser.Request): Promise<void>;
11
- changeUserPassword({ credentials, data, url, }: Keycloak.ChangeUserPassword.Request): Promise<void>;
12
- addRealm({ url, data, credentials, }: Keycloak.AddRealm.Request): Promise<void>;
13
- addRole({ url, data, credentials, }: Keycloak.AddRole.Request): Promise<void>;
14
- associateUserRole({ url, data, credentials, }: Keycloak.AssociateUserRole.Request): Promise<void>;
15
- getRoles({ url, data, credentials, }: Keycloak.GetRoles.Request): Promise<Keycloak.GetRoles.Response>;
16
- deleteRole({ url, data, credentials, }: Keycloak.DeleteRole.Request): Promise<void>;
3
+ authenticate(req: Keycloak.Authenticate.Request): Promise<Keycloak.Authenticate.Response>;
4
+ refreshAccess(req: Keycloak.RefreshAccess.Request): Promise<Keycloak.RefreshAccess.Response>;
17
5
  }
18
6
  declare const _default: KeycloakService;
19
7
  export default _default;
@@ -5,314 +5,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const http_1 = __importDefault(require("./http"));
7
7
  class KeycloakService {
8
- async authenticate({ credentials, data, url, }) {
9
- const { data: response } = await http_1.default.request({
10
- baseURL: url,
11
- method: 'post',
12
- resourcePath: `/auth/realms/${credentials.realm}/protocol/openid-connect/token/`,
13
- headers: {
14
- 'Cache-Control': 'no-cache',
15
- 'Content-Type': 'application/x-www-form-urlencoded',
16
- },
17
- body: new URLSearchParams({
18
- client_id: credentials.clientId,
19
- client_secret: credentials.clientSecret,
20
- grant_type: credentials.grantType,
21
- username: data.username,
22
- password: data.password,
23
- }),
24
- });
25
- return response;
26
- }
27
- async authenticateServer({ credentials, url, }) {
28
- const { data: response } = await http_1.default.request({
29
- baseURL: url,
30
- method: 'post',
31
- resourcePath: `/auth/realms/${credentials.realm}/protocol/openid-connect/token/`,
32
- headers: {
33
- 'Cache-Control': 'no-cache',
34
- 'Content-Type': 'application/x-www-form-urlencoded',
35
- },
36
- body: new URLSearchParams({
37
- client_id: credentials.clientId,
38
- client_secret: credentials.clientSecret,
39
- grant_type: credentials.grantType,
40
- }),
41
- });
42
- return response;
43
- }
44
- async refreshAccess({ credentials, data, url, }) {
45
- const { data: response } = await http_1.default.request({
46
- baseURL: url,
47
- method: 'post',
48
- resourcePath: `/auth/realms/${credentials.realm}/protocol/openid-connect/token`,
49
- headers: {
50
- 'Cache-Control': 'no-cache',
51
- 'Content-Type': 'application/x-www-form-urlencoded',
52
- },
53
- body: new URLSearchParams({
54
- client_id: credentials.clientId,
55
- client_secret: credentials.clientSecret,
56
- grant_type: 'refresh_token',
57
- refresh_token: data.refreshToken,
58
- }),
59
- });
60
- return response;
61
- }
62
- async revokeAccess({ credentials, data, url, }) {
63
- await http_1.default.request({
64
- baseURL: url,
65
- method: 'post',
66
- resourcePath: `/auth/realms/${credentials.realm}/protocol/openid-connect/revoke`,
67
- headers: {
68
- 'Cache-Control': 'no-cache',
69
- 'Content-Type': 'application/x-www-form-urlencoded',
70
- },
71
- body: new URLSearchParams({
72
- client_id: credentials.clientId,
73
- client_secret: credentials.clientSecret,
74
- token: data.accessToken,
75
- }),
8
+ async authenticate(req) {
9
+ const query = new URLSearchParams({
10
+ client_id: req.credentials.clientId,
11
+ client_secret: req.credentials.clientSecret,
12
+ grant_type: req.credentials.grantType,
13
+ username: req.username,
14
+ password: req.password,
76
15
  });
77
- }
78
- async createUser({ credentials, data, url, }) {
79
- const { access_token } = await this.authenticateServer({
80
- credentials,
81
- url,
82
- });
83
- await http_1.default.request({
84
- baseURL: url,
16
+ const { data } = await http_1.default.request({
17
+ baseURL: req.url,
85
18
  method: 'post',
86
19
  resourcePath: '/',
87
- headers: {
88
- 'Cache-Control': 'no-cache',
89
- 'Content-Type': 'application/json',
90
- 'Authorization': `Bearer ${access_token}`,
91
- },
92
- body: {
93
- email: data.email,
94
- username: data.username,
95
- firstName: data.firstName,
96
- lastName: data.lastName ?? '',
97
- enabled: true,
98
- emailVerified: true,
99
- credentials: [
100
- {
101
- type: 'password',
102
- value: data.password,
103
- temporary: data.isTemporaryPassword ?? false,
104
- },
105
- ],
106
- groups: data.groups,
107
- attributes: {
108
- isFirstAccess: true,
109
- },
110
- },
111
- });
112
- }
113
- async updateUser({ credentials, data, url, }) {
114
- const { access_token } = await this.authenticateServer({
115
- credentials,
116
- url,
117
- });
118
- await http_1.default.request({
119
- baseURL: url,
120
- method: 'put',
121
- resourcePath: `/auth/admin/realms/${credentials.realm}/users/${data.id}`,
122
- headers: {
123
- 'Cache-Control': 'no-cache',
124
- 'Content-Type': 'application/json',
125
- 'Authorization': `Bearer ${access_token}`,
126
- },
127
- body: {
128
- email: data.email,
129
- username: data.username,
130
- firstName: data.firstName,
131
- lastName: data.lastName ?? '',
132
- enabled: true,
133
- emailVerified: true,
134
- ...(data.password && {
135
- credentials: [
136
- {
137
- type: 'password',
138
- value: data.password,
139
- temporary: data.isTemporaryPassword ?? false,
140
- },
141
- ],
142
- }),
143
- groups: data.groups,
144
- attributes: {
145
- isFirstAccess: false,
146
- },
147
- },
148
- });
149
- }
150
- async getUser({ credentials, data, url, }) {
151
- const { access_token } = await this.authenticateServer({
152
- credentials,
153
- url,
154
- });
155
- const { data: response } = await http_1.default.request({
156
- baseURL: url,
157
- method: 'get',
158
- resourcePath: `/auth/admin/realms/${credentials.realm}/users/${data.id}`,
159
- headers: {
160
- 'Cache-Control': 'no-cache',
161
- 'Content-Type': 'application/json',
162
- 'Authorization': `Bearer ${access_token}`,
163
- },
164
- });
165
- return response;
166
- }
167
- async deleteUser({ credentials, data, url, }) {
168
- const { access_token } = await this.authenticateServer({
169
- credentials,
170
- url,
171
- });
172
- await http_1.default.request({
173
- baseURL: url,
174
- method: 'delete',
175
- resourcePath: `/auth/admin/realms/${credentials.realm}/users/${data.id}`,
176
- headers: {
177
- 'Cache-Control': 'no-cache',
178
- 'Content-Type': 'application/json',
179
- 'Authorization': `Bearer ${access_token}`,
180
- },
181
- });
182
- }
183
- async changeUserPassword({ credentials, data, url, }) {
184
- const { access_token } = await this.authenticateServer({
185
- credentials,
186
- url,
187
- });
188
- await http_1.default.request({
189
- baseURL: url,
190
- method: 'put',
191
- resourcePath: `/auth/admin/realms/${credentials.realm}/users/${data.id}/reset-password`,
192
- headers: {
193
- 'Cache-Control': 'no-cache',
194
- 'Content-Type': 'application/json',
195
- 'Authorization': `Bearer ${access_token}`,
196
- },
197
- body: {
198
- type: 'password',
199
- value: data.password,
200
- temporary: data.isTemporaryPassword ?? false,
201
- },
202
- });
203
- }
204
- async addRealm({ url, data, credentials, }) {
205
- const { access_token } = await this.authenticateServer({
206
- credentials,
207
- url,
208
- });
209
- await http_1.default.request({
210
- baseURL: url,
211
- method: 'post',
212
- resourcePath: '/auth/admin/realms',
213
- headers: {
214
- 'Cache-Control': 'no-cache',
215
- 'Content-Type': 'application/json',
216
- 'Authorization': `Bearer ${access_token}`,
217
- },
218
- body: {
219
- id: data.name,
220
- realm: data.name,
221
- enabled: data.enabled ?? false,
222
- loginWithEmailAllowed: false,
223
- duplicateEmailsAllowed: true,
224
- resetPasswordAllowed: false,
225
- editUsernameAllowed: true,
226
- bruteForceProtected: true,
227
- permanentLockout: false,
228
- maxFailureWaitSeconds: 900,
229
- minimumQuickLoginWaitSeconds: 60,
230
- waitIncrementSeconds: 60,
231
- quickLoginCheckMilliSeconds: 1000,
232
- maxDeltaTimeSeconds: 43200,
233
- failureFactor: 5,
234
- },
235
- });
236
- }
237
- async addRole({ url, data, credentials, }) {
238
- const { access_token } = await this.authenticateServer({
239
- credentials,
240
- url,
241
- });
242
- await http_1.default.request({
243
- baseURL: url,
244
- method: 'post',
245
- resourcePath: `/auth/admin/realms/${credentials.realm}/roles`,
246
- headers: {
247
- 'Cache-Control': 'no-cache',
248
- 'Content-Type': 'application/json',
249
- 'Authorization': `Bearer ${access_token}`,
250
- },
251
- body: {
252
- name: data.name,
253
- description: data.description,
254
- },
20
+ headers: {},
21
+ query: query,
255
22
  });
23
+ return data;
256
24
  }
257
- async associateUserRole({ url, data, credentials, }) {
258
- const { access_token } = await this.authenticateServer({
259
- credentials,
260
- url,
261
- });
262
- const { roles } = await this.getRoles({
263
- url,
264
- data: {
265
- search: data.role,
266
- },
267
- credentials,
25
+ async refreshAccess(req) {
26
+ const query = new URLSearchParams({
27
+ client_id: req.credentials.clientId,
28
+ client_secret: req.credentials.clientSecret,
29
+ grant_type: 'refresh_token',
30
+ refresh_token: req.refreshToken,
268
31
  });
269
- await http_1.default.request({
270
- baseURL: url,
32
+ const { data } = await http_1.default.request({
33
+ baseURL: req.url,
271
34
  method: 'post',
272
- resourcePath: `/auth/admin/realms/${credentials.realm}/users/${data.user}/role-mappings/realm`,
273
- headers: {
274
- 'Cache-Control': 'no-cache',
275
- 'Content-Type': 'application/json',
276
- 'Authorization': `Bearer ${access_token}`,
277
- },
278
- body: roles,
279
- });
280
- }
281
- async getRoles({ url, data, credentials, }) {
282
- const { access_token } = await this.authenticateServer({
283
- credentials,
284
- url,
285
- });
286
- const { data: response } = await http_1.default.request({
287
- baseURL: url,
288
- method: 'get',
289
- resourcePath: `/auth/admin/realms/${credentials.realm}/roles`,
290
- headers: {
291
- 'Cache-Control': 'no-cache',
292
- 'Content-Type': 'application/json',
293
- 'Authorization': `Bearer ${access_token}`,
294
- },
295
- query: data,
296
- });
297
- return {
298
- roles: response,
299
- };
300
- }
301
- async deleteRole({ url, data, credentials, }) {
302
- const { access_token } = await this.authenticateServer({
303
- credentials,
304
- url,
305
- });
306
- await http_1.default.request({
307
- baseURL: url,
308
- method: 'delete',
309
- resourcePath: `/auth/admin/realms/${credentials.realm}/roles-by-id/${data.id}`,
310
- headers: {
311
- 'Cache-Control': 'no-cache',
312
- 'Content-Type': 'application/json',
313
- 'Authorization': `Bearer ${access_token}`,
314
- },
35
+ resourcePath: '/',
36
+ headers: {},
37
+ query: query,
315
38
  });
39
+ return data;
316
40
  }
317
41
  }
318
42
  exports.default = new KeycloakService();
@@ -1,7 +1,7 @@
1
1
  import { INodeMailerService, NodeMailer } from '../interfaces/nodemailer';
2
2
  declare class NodeMailerService implements INodeMailerService {
3
- send({ credentials, data }: NodeMailer.Send.Request): Promise<void>;
4
- sendWithTemplate({ credentials, data }: NodeMailer.SendWithTemplate.Request): Promise<void>;
3
+ send(req: NodeMailer.Send.Request): Promise<void>;
4
+ sendWithTemplate(req: NodeMailer.SendWithTemplate.Request): Promise<void>;
5
5
  }
6
6
  declare const _default: NodeMailerService;
7
7
  export default _default;
@@ -5,44 +5,134 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const nodemailer_1 = __importDefault(require("nodemailer"));
7
7
  class NodeMailerService {
8
- async send({ credentials, data }) {
8
+ async send(req) {
9
9
  const transporter = nodemailer_1.default.createTransport({
10
- host: credentials.host,
11
- port: credentials.port,
12
- secure: credentials.secure,
13
- auth: credentials.auth,
10
+ host: req.credentials.host,
11
+ port: req.credentials.port,
12
+ secure: req.credentials.secure,
13
+ auth: req.credentials.auth,
14
14
  tls: {
15
15
  rejectUnauthorized: false,
16
16
  },
17
17
  });
18
18
  const options = {
19
- from: data.from,
20
- to: data.to,
21
- subject: data.subject,
22
- text: data.text,
19
+ from: req.from,
20
+ to: req.to,
21
+ subject: req.subject,
22
+ text: req.text,
23
23
  };
24
24
  await transporter.sendMail(options);
25
25
  transporter.close();
26
26
  }
27
- async sendWithTemplate({ credentials, data }) {
27
+ async sendWithTemplate(req) {
28
28
  const transporter = nodemailer_1.default.createTransport({
29
- host: credentials.host,
30
- port: credentials.port,
31
- secure: credentials.secure,
32
- auth: credentials.auth,
29
+ host: req.credentials.host,
30
+ port: req.credentials.port,
31
+ secure: req.credentials.secure,
32
+ auth: req.credentials.auth,
33
33
  tls: {
34
34
  rejectUnauthorized: false,
35
35
  },
36
36
  });
37
37
  const options = {
38
- from: data.from,
39
- to: data.to,
40
- subject: data.subject,
41
- html: data.html,
42
- attachments: data.attachments,
38
+ from: req.from,
39
+ to: req.to,
40
+ subject: req.subject,
41
+ html: req.html,
42
+ attachments: req.attachments,
43
43
  };
44
44
  await transporter.sendMail(options);
45
45
  transporter.close();
46
46
  }
47
47
  }
48
48
  exports.default = new NodeMailerService();
49
+ /* import { ISMTPTemplateMail, ISMTPTextMail } from '@shared/mechanisms/smtp/interfaces';
50
+ import { readTemplate, stringReplace } from '@shared/utils';
51
+ import mjml from 'mjml';
52
+ import nodemailer, { SendMailOptions, Transporter } from 'nodemailer';
53
+ import { join } from 'path';
54
+
55
+ class SMTPService {
56
+ static getTransporter (): Transporter {
57
+ const { host, auth, port, secure } = getEnv().mailing.smtp;
58
+
59
+ return nodemailer.createTransport({
60
+ host,
61
+ port,
62
+ secure,
63
+ auth,
64
+ tls: {
65
+ rejectUnauthorized: false,
66
+ },
67
+ });
68
+ }
69
+
70
+ static async send (params: ISMTPTextMail): Promise<void> {
71
+ const transporter = SMTPService.getTransporter();
72
+
73
+ const options: SendMailOptions = {
74
+ from: {
75
+ name: params.from.name,
76
+ address: params.from.address,
77
+ },
78
+ to: params.to,
79
+ subject: params.subject,
80
+ text: params.text,
81
+ };
82
+
83
+ await transporter.sendMail(options);
84
+ transporter.close();
85
+ }
86
+
87
+ static async sendWithTemplate (params: ISMTPTemplateMail): Promise<void> {
88
+ const transporter = SMTPService.getTransporter();
89
+
90
+ const options: SendMailOptions = {
91
+ from: {
92
+ name: params.from.name,
93
+ address: params.from.address,
94
+ },
95
+ to: params.to,
96
+ subject: params.subject,
97
+ html: params.template,
98
+ attachments: params.attachments,
99
+ };
100
+
101
+ await transporter.sendMail(options);
102
+ transporter.close();
103
+ }
104
+
105
+ static async getTemplate (filename: string, options?: Dictionary<string | number>) {
106
+ let template = null;
107
+
108
+ const path = join(__dirname, `./templates/${filename}`);
109
+
110
+ try {
111
+ template = await readTemplate(path, 'utf8');
112
+
113
+ if (!template) throw new BusinessError(BusinessErrorCodes.TEMPLATE_NOT_FOUND);
114
+
115
+ } catch (err) {
116
+ throw new BusinessError(BusinessErrorCodes.TEMPLATE_NOT_FOUND);
117
+ }
118
+
119
+ if (options) {
120
+ template = stringReplace(template, options);
121
+ }
122
+
123
+ if (filename.includes('.mjml')) {
124
+ const { html, errors } = mjml(template);
125
+
126
+ if (errors && errors.length) {
127
+ throw new BusinessError(BusinessErrorCodes.TEMPLATE_NOT_FOUND);
128
+ }
129
+
130
+ template = html;
131
+ }
132
+
133
+ return template;
134
+ }
135
+ }
136
+
137
+ export default SMTPService;
138
+ */
@@ -1,9 +1,11 @@
1
1
  import { IRedisService, Redis } from '../interfaces/redis';
2
2
  declare class RedisService implements IRedisService {
3
- set({ credentials, data }: Redis.Set.Request): Promise<void>;
4
- get<T>({ credentials, data }: Redis.Get.Request): Promise<Redis.Get.Response<T>>;
5
- del({ credentials, data }: Redis.Get.Request): Promise<void>;
6
- exists({ credentials, data }: Redis.Get.Request): Promise<Redis.Exists.Response>;
3
+ private credentials;
4
+ private client;
5
+ constructor(credentials: Redis.Credentials);
6
+ set(key: string, value: unknown, ttl?: number): Promise<void>;
7
+ get<T>(key: string): Promise<T | null>;
8
+ del(key: string): Promise<void>;
9
+ exists(key: string): Promise<boolean>;
7
10
  }
8
- declare const _default: RedisService;
9
- export default _default;
11
+ export default RedisService;