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.
- package/bitbucket-pipelines.yml +6 -48
- package/dist/database/entities/account.d.ts +1 -2
- package/dist/database/entities/account.js +2 -7
- package/dist/database/entities/address.d.ts +2 -1
- package/dist/database/entities/address.js +6 -5
- package/dist/database/entities/company-address.d.ts +2 -0
- package/dist/database/entities/company-address.js +7 -0
- package/dist/database/migrations/1748448589934-CreateAccountsTable.js +1 -6
- package/dist/database/migrations/1750432386920-CreateAddressTable.js +0 -5
- package/dist/database/migrations/index.js +0 -4
- package/dist/interfaces/aws.d.ts +41 -67
- package/dist/interfaces/azure.d.ts +38 -61
- package/dist/interfaces/firebase.d.ts +3 -7
- package/dist/interfaces/gcp.d.ts +5 -11
- package/dist/interfaces/grafana.d.ts +2 -6
- package/dist/interfaces/keycloak.d.ts +4 -171
- package/dist/interfaces/nodemailer.d.ts +16 -20
- package/dist/interfaces/redis.d.ts +8 -49
- package/dist/interfaces/sendgrid.d.ts +13 -15
- package/dist/services/aws/cloudwatch.d.ts +1 -1
- package/dist/services/aws/cloudwatch.js +38 -38
- package/dist/services/aws/pinpoint.d.ts +3 -3
- package/dist/services/aws/pinpoint.js +29 -29
- package/dist/services/aws/s3.d.ts +5 -5
- package/dist/services/aws/s3.js +55 -59
- package/dist/services/aws/secret-manager.d.ts +1 -1
- package/dist/services/aws/secret-manager.js +5 -5
- package/dist/services/aws/sqs.d.ts +3 -3
- package/dist/services/aws/sqs.js +16 -16
- package/dist/services/azure/application-insights.d.ts +4 -4
- package/dist/services/azure/application-insights.js +12 -12
- package/dist/services/azure/communication.d.ts +3 -3
- package/dist/services/azure/communication.js +17 -17
- package/dist/services/azure/keyvault.d.ts +1 -1
- package/dist/services/azure/keyvault.js +3 -3
- package/dist/services/azure/storage-blob.d.ts +3 -3
- package/dist/services/azure/storage-blob.js +22 -22
- package/dist/services/firebase.d.ts +2 -2
- package/dist/services/firebase.js +10 -12
- package/dist/services/gcp/drive.d.ts +1 -1
- package/dist/services/gcp/drive.js +4 -4
- package/dist/services/gcp/secrets.d.ts +1 -1
- package/dist/services/gcp/secrets.js +8 -6
- package/dist/services/gcp/sheets.d.ts +1 -1
- package/dist/services/gcp/sheets.js +6 -6
- package/dist/services/grafana.d.ts +2 -2
- package/dist/services/grafana.js +12 -12
- package/dist/services/keycloak.d.ts +2 -14
- package/dist/services/keycloak.js +24 -300
- package/dist/services/nodemailer.d.ts +2 -2
- package/dist/services/nodemailer.js +109 -19
- package/dist/services/redis.d.ts +8 -6
- package/dist/services/redis.js +24 -53
- package/dist/services/sendgrid.d.ts +1 -1
- package/dist/services/sendgrid.js +10 -10
- package/package.json +1 -1
- package/src/database/entities/account.ts +3 -5
- package/src/database/entities/address.ts +7 -4
- package/src/database/entities/company-address.ts +5 -0
- package/src/database/migrations/1748448589934-CreateAccountsTable.ts +1 -6
- package/src/database/migrations/1750432386920-CreateAddressTable.ts +0 -5
- package/src/database/migrations/index.ts +0 -4
- package/src/interfaces/aws.ts +55 -81
- package/src/interfaces/azure.ts +50 -71
- package/src/interfaces/firebase.ts +6 -10
- package/src/interfaces/gcp.ts +8 -14
- package/src/interfaces/grafana.ts +5 -9
- package/src/interfaces/keycloak.ts +7 -190
- package/src/interfaces/nodemailer.ts +18 -22
- package/src/interfaces/redis.ts +8 -54
- package/src/interfaces/sendgrid.ts +14 -16
- package/src/services/aws/cloudwatch.ts +39 -39
- package/src/services/aws/pinpoint.ts +30 -30
- package/src/services/aws/s3.ts +55 -59
- package/src/services/aws/secret-manager.ts +7 -8
- package/src/services/aws/sqs.ts +17 -23
- package/src/services/azure/application-insights.ts +12 -12
- package/src/services/azure/communication.ts +18 -18
- package/src/services/azure/keyvault.ts +3 -3
- package/src/services/azure/storage-blob.ts +30 -34
- package/src/services/firebase.ts +11 -21
- package/src/services/gcp/drive.ts +5 -8
- package/src/services/gcp/secrets.ts +10 -9
- package/src/services/gcp/sheets.ts +7 -10
- package/src/services/grafana.ts +12 -18
- package/src/services/keycloak.ts +25 -381
- package/src/services/nodemailer.ts +110 -19
- package/src/services/redis.ts +22 -58
- package/src/services/sendgrid.ts +11 -11
- package/dist/database/migrations/1750690818577-CreateAccountAddressTable.d.ts +0 -5
- package/dist/database/migrations/1750690818577-CreateAccountAddressTable.js +0 -94
- package/dist/database/migrations/1750691840822-CreateAccountDetailsTable.d.ts +0 -5
- package/dist/database/migrations/1750691840822-CreateAccountDetailsTable.js +0 -99
- package/src/database/migrations/1750690818577-CreateAccountAddressTable.ts +0 -98
- package/src/database/migrations/1750691840822-CreateAccountDetailsTable.ts +0 -99
|
@@ -5,26 +5,24 @@ interface Credentials {
|
|
|
5
5
|
export namespace Sendgrid {
|
|
6
6
|
export namespace SendMail {
|
|
7
7
|
export interface Request {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}[];
|
|
22
|
-
};
|
|
8
|
+
to: string;
|
|
9
|
+
from: string;
|
|
10
|
+
subject?: string;
|
|
11
|
+
text?: string;
|
|
12
|
+
html?: string;
|
|
13
|
+
template?: string;
|
|
14
|
+
substitutions?: Record<string, unknown>;
|
|
15
|
+
attachments?: {
|
|
16
|
+
content: string;
|
|
17
|
+
filename: string;
|
|
18
|
+
type?: string;
|
|
19
|
+
disposition?: string;
|
|
20
|
+
}[];
|
|
23
21
|
credentials: Credentials;
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
}
|
|
27
25
|
|
|
28
26
|
export interface ISendgridService {
|
|
29
|
-
sendMail(req: Sendgrid.SendMail.Request): Promise<void>;
|
|
27
|
+
sendMail (req: Sendgrid.SendMail.Request): Promise<void>;
|
|
30
28
|
}
|
|
@@ -3,105 +3,105 @@ import { CloudWatchLogs } from '@aws-sdk/client-cloudwatch-logs';
|
|
|
3
3
|
import { AmazonCloudwatch, IAmazonCloudwatchService } from '../../interfaces/aws';
|
|
4
4
|
|
|
5
5
|
class AmazonCloudwatchService implements IAmazonCloudwatchService {
|
|
6
|
-
public async createLogEvent (
|
|
6
|
+
public async createLogEvent (req: AmazonCloudwatch.CreateLogEvent.Request): Promise<void> {
|
|
7
7
|
const client: CloudWatchLogs = new CloudWatchLogs({
|
|
8
8
|
credentials: {
|
|
9
|
-
accessKeyId: credentials.accessKey,
|
|
10
|
-
secretAccessKey: credentials.secretKey,
|
|
9
|
+
accessKeyId: req.credentials.accessKey,
|
|
10
|
+
secretAccessKey: req.credentials.secretKey,
|
|
11
11
|
},
|
|
12
|
-
region: credentials.region,
|
|
12
|
+
region: req.credentials.region,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
await this.createLogGroup(
|
|
16
|
-
await this.createLogStream(
|
|
15
|
+
await this.createLogGroup(req);
|
|
16
|
+
await this.createLogStream(req);
|
|
17
17
|
|
|
18
18
|
await client.putLogEvents({
|
|
19
|
-
logGroupName:
|
|
20
|
-
logStreamName:
|
|
21
|
-
logEvents:
|
|
19
|
+
logGroupName: req.group,
|
|
20
|
+
logStreamName: req.stream,
|
|
21
|
+
logEvents: req.events,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
private async getLogGroupByName (
|
|
26
|
-
const logGroups = await this.listApplicationLogGroups(
|
|
25
|
+
private async getLogGroupByName (req: AmazonCloudwatch.CreateLogEvent.Request) {
|
|
26
|
+
const logGroups = await this.listApplicationLogGroups(req);
|
|
27
27
|
|
|
28
|
-
return logGroups.find((logGroup) => logGroup.logGroupName ===
|
|
28
|
+
return logGroups.find((logGroup) => logGroup.logGroupName === req.group);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
private async getLogStreamByName (
|
|
32
|
-
const logStreams = await this.listApplicationLogStreams(
|
|
31
|
+
private async getLogStreamByName (req: AmazonCloudwatch.CreateLogEvent.Request) {
|
|
32
|
+
const logStreams = await this.listApplicationLogStreams(req);
|
|
33
33
|
|
|
34
|
-
return logStreams.find((logStream) => logStream.logStreamName ===
|
|
34
|
+
return logStreams.find((logStream) => logStream.logStreamName === req.stream);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
private async listApplicationLogGroups (
|
|
37
|
+
private async listApplicationLogGroups (req: AmazonCloudwatch.CreateLogEvent.Request) {
|
|
38
38
|
const client: CloudWatchLogs = new CloudWatchLogs({
|
|
39
39
|
credentials: {
|
|
40
|
-
accessKeyId: credentials.accessKey,
|
|
41
|
-
secretAccessKey: credentials.secretKey,
|
|
40
|
+
accessKeyId: req.credentials.accessKey,
|
|
41
|
+
secretAccessKey: req.credentials.secretKey,
|
|
42
42
|
},
|
|
43
|
-
region: credentials.region,
|
|
43
|
+
region: req.credentials.region,
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
const { logGroups } = await client.describeLogGroups({
|
|
47
|
-
logGroupNamePrefix:
|
|
47
|
+
logGroupNamePrefix: req.application,
|
|
48
48
|
});
|
|
49
49
|
|
|
50
50
|
return logGroups;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
private async listApplicationLogStreams (
|
|
53
|
+
private async listApplicationLogStreams (req: AmazonCloudwatch.CreateLogEvent.Request) {
|
|
54
54
|
const client: CloudWatchLogs = new CloudWatchLogs({
|
|
55
55
|
credentials: {
|
|
56
|
-
accessKeyId: credentials.accessKey,
|
|
57
|
-
secretAccessKey: credentials.secretKey,
|
|
56
|
+
accessKeyId: req.credentials.accessKey,
|
|
57
|
+
secretAccessKey: req.credentials.secretKey,
|
|
58
58
|
},
|
|
59
|
-
region: credentials.region,
|
|
59
|
+
region: req.credentials.region,
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
const { logStreams } = await client.describeLogStreams({
|
|
63
|
-
logGroupName:
|
|
63
|
+
logGroupName: req.group,
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
return logStreams;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
private async createLogGroup (
|
|
70
|
-
const logGroup = await this.getLogGroupByName(
|
|
69
|
+
private async createLogGroup (req: AmazonCloudwatch.CreateLogEvent.Request) {
|
|
70
|
+
const logGroup = await this.getLogGroupByName(req);
|
|
71
71
|
|
|
72
72
|
if (!logGroup) {
|
|
73
73
|
const client: CloudWatchLogs = new CloudWatchLogs({
|
|
74
74
|
credentials: {
|
|
75
|
-
accessKeyId: credentials.accessKey,
|
|
76
|
-
secretAccessKey: credentials.secretKey,
|
|
75
|
+
accessKeyId: req.credentials.accessKey,
|
|
76
|
+
secretAccessKey: req.credentials.secretKey,
|
|
77
77
|
},
|
|
78
|
-
region: credentials.region,
|
|
78
|
+
region: req.credentials.region,
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
await client.createLogGroup({
|
|
82
|
-
logGroupName:
|
|
82
|
+
logGroupName: req.group,
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
private async createLogStream (
|
|
88
|
-
const logStream = await this.getLogStreamByName(
|
|
87
|
+
private async createLogStream (req: AmazonCloudwatch.CreateLogEvent.Request) {
|
|
88
|
+
const logStream = await this.getLogStreamByName(req);
|
|
89
89
|
|
|
90
90
|
if (!logStream) {
|
|
91
91
|
const client: CloudWatchLogs = new CloudWatchLogs({
|
|
92
92
|
credentials: {
|
|
93
|
-
accessKeyId: credentials.accessKey,
|
|
94
|
-
secretAccessKey: credentials.secretKey,
|
|
93
|
+
accessKeyId: req.credentials.accessKey,
|
|
94
|
+
secretAccessKey: req.credentials.secretKey,
|
|
95
95
|
},
|
|
96
|
-
region: credentials.region,
|
|
96
|
+
region: req.credentials.region,
|
|
97
97
|
});
|
|
98
98
|
|
|
99
99
|
await client.createLogStream({
|
|
100
|
-
logGroupName:
|
|
101
|
-
logStreamName:
|
|
100
|
+
logGroupName: req.group,
|
|
101
|
+
logStreamName: req.stream,
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
export default new AmazonCloudwatchService();
|
|
107
|
+
export default new AmazonCloudwatchService();
|
|
@@ -3,16 +3,16 @@ import { PinpointClient, SendMessagesCommand, SendMessagesCommandInput } from '@
|
|
|
3
3
|
import { AmazonPinpoint, IAmazonPinpointService } from '../../interfaces/aws';
|
|
4
4
|
|
|
5
5
|
class AmazonPinpointService implements IAmazonPinpointService {
|
|
6
|
-
async sendMail (
|
|
6
|
+
async sendMail (req: AmazonPinpoint.SendMail.Request): Promise<void> {
|
|
7
7
|
const client = new PinpointClient({
|
|
8
8
|
credentials: {
|
|
9
|
-
accessKeyId: credentials.accessKey,
|
|
10
|
-
secretAccessKey: credentials.secretKey,
|
|
9
|
+
accessKeyId: req.credentials.accessKey,
|
|
10
|
+
secretAccessKey: req.credentials.secretKey,
|
|
11
11
|
},
|
|
12
|
-
region: credentials.region,
|
|
12
|
+
region: req.credentials.region,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
const recipient = Array.isArray(
|
|
15
|
+
const recipient = Array.isArray(req.emails) ? req.emails : [ req.emails ];
|
|
16
16
|
|
|
17
17
|
const addresses = recipient.reduce(
|
|
18
18
|
(acc, curr) => ({
|
|
@@ -24,7 +24,7 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
24
24
|
{}
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
const substitutions = Object.entries(
|
|
27
|
+
const substitutions = Object.entries(req.variables || {}).reduce(
|
|
28
28
|
(acc, [ key, value ]) => ({
|
|
29
29
|
...acc,
|
|
30
30
|
[key]: [ value ],
|
|
@@ -33,21 +33,21 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
33
33
|
);
|
|
34
34
|
|
|
35
35
|
const payload: SendMessagesCommandInput = {
|
|
36
|
-
ApplicationId:
|
|
36
|
+
ApplicationId: req.applicationId,
|
|
37
37
|
MessageRequest: {
|
|
38
38
|
Addresses: addresses,
|
|
39
39
|
MessageConfiguration: {
|
|
40
40
|
EmailMessage: {
|
|
41
|
-
FromAddress:
|
|
41
|
+
FromAddress: req.from,
|
|
42
42
|
Substitutions: substitutions,
|
|
43
43
|
SimpleEmail: {
|
|
44
44
|
Subject: {
|
|
45
45
|
Charset: 'utf-8',
|
|
46
|
-
Data:
|
|
46
|
+
Data: req.subject,
|
|
47
47
|
},
|
|
48
48
|
TextPart: {
|
|
49
49
|
Charset: 'utf-8',
|
|
50
|
-
Data:
|
|
50
|
+
Data: req.text,
|
|
51
51
|
},
|
|
52
52
|
},
|
|
53
53
|
},
|
|
@@ -58,16 +58,16 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
58
58
|
await client.send(new SendMessagesCommand(payload));
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
async sendTemplateMail (
|
|
61
|
+
async sendTemplateMail (req: AmazonPinpoint.SendTemplateMail.Request): Promise<void> {
|
|
62
62
|
const client = new PinpointClient({
|
|
63
63
|
credentials: {
|
|
64
|
-
accessKeyId: credentials.accessKey,
|
|
65
|
-
secretAccessKey: credentials.secretKey,
|
|
64
|
+
accessKeyId: req.credentials.accessKey,
|
|
65
|
+
secretAccessKey: req.credentials.secretKey,
|
|
66
66
|
},
|
|
67
|
-
region: credentials.region,
|
|
67
|
+
region: req.credentials.region,
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
const recipient = Array.isArray(
|
|
70
|
+
const recipient = Array.isArray(req.emails) ? req.emails : [ req.emails ];
|
|
71
71
|
|
|
72
72
|
const addresses = recipient.reduce(
|
|
73
73
|
(acc, curr) => ({
|
|
@@ -79,7 +79,7 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
79
79
|
{}
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
-
const substitutions = Object.entries(
|
|
82
|
+
const substitutions = Object.entries(req.variables || {}).reduce(
|
|
83
83
|
(acc, [ key, value ]) => ({
|
|
84
84
|
...acc,
|
|
85
85
|
[key]: [ value ],
|
|
@@ -88,18 +88,18 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
88
88
|
);
|
|
89
89
|
|
|
90
90
|
const payload: SendMessagesCommandInput = {
|
|
91
|
-
ApplicationId:
|
|
91
|
+
ApplicationId: req.applicationId,
|
|
92
92
|
MessageRequest: {
|
|
93
93
|
Addresses: addresses,
|
|
94
94
|
MessageConfiguration: {
|
|
95
95
|
EmailMessage: {
|
|
96
|
-
FromAddress:
|
|
96
|
+
FromAddress: req.from,
|
|
97
97
|
Substitutions: substitutions,
|
|
98
98
|
},
|
|
99
99
|
},
|
|
100
100
|
TemplateConfiguration: {
|
|
101
101
|
EmailTemplate: {
|
|
102
|
-
Name:
|
|
102
|
+
Name: req.template,
|
|
103
103
|
Version: 'latest',
|
|
104
104
|
},
|
|
105
105
|
},
|
|
@@ -109,16 +109,16 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
109
109
|
await client.send(new SendMessagesCommand(payload));
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
async sendSMS (
|
|
112
|
+
async sendSMS (req: AmazonPinpoint.SendSMS.Request): Promise<void> {
|
|
113
113
|
const client = new PinpointClient({
|
|
114
114
|
credentials: {
|
|
115
|
-
accessKeyId: credentials.accessKey,
|
|
116
|
-
secretAccessKey: credentials.secretKey,
|
|
115
|
+
accessKeyId: req.credentials.accessKey,
|
|
116
|
+
secretAccessKey: req.credentials.secretKey,
|
|
117
117
|
},
|
|
118
|
-
region: credentials.region,
|
|
118
|
+
region: req.credentials.region,
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
const recipient = Array.isArray(
|
|
121
|
+
const recipient = Array.isArray(req.phones) ? req.phones : [ req.phones ];
|
|
122
122
|
|
|
123
123
|
const addresses = recipient.reduce(
|
|
124
124
|
(acc, curr) => ({
|
|
@@ -130,7 +130,7 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
130
130
|
{}
|
|
131
131
|
);
|
|
132
132
|
|
|
133
|
-
const substitutions = Object.entries(
|
|
133
|
+
const substitutions = Object.entries(req.variables || {}).reduce(
|
|
134
134
|
(acc, [ key, value ]) => ({
|
|
135
135
|
...acc,
|
|
136
136
|
[key]: [ value ],
|
|
@@ -139,14 +139,14 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
139
139
|
);
|
|
140
140
|
|
|
141
141
|
const payload: SendMessagesCommandInput = {
|
|
142
|
-
ApplicationId:
|
|
142
|
+
ApplicationId: req.applicationId,
|
|
143
143
|
MessageRequest: {
|
|
144
144
|
Addresses: addresses,
|
|
145
145
|
MessageConfiguration: {
|
|
146
146
|
SMSMessage: {
|
|
147
|
-
Body:
|
|
148
|
-
MessageType:
|
|
149
|
-
SenderId:
|
|
147
|
+
Body: req.text,
|
|
148
|
+
MessageType: req.type,
|
|
149
|
+
SenderId: req.sender,
|
|
150
150
|
Substitutions: substitutions,
|
|
151
151
|
},
|
|
152
152
|
},
|
|
@@ -157,4 +157,4 @@ class AmazonPinpointService implements IAmazonPinpointService {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
export default new AmazonPinpointService();
|
|
160
|
+
export default new AmazonPinpointService();
|
package/src/services/aws/s3.ts
CHANGED
|
@@ -11,119 +11,115 @@ import { AmazonS3, IAmazonS3Service } from '../../interfaces/aws';
|
|
|
11
11
|
import FileService from '../../services/file';
|
|
12
12
|
|
|
13
13
|
class AmazonS3Service implements IAmazonS3Service {
|
|
14
|
-
async uploadBase64 (
|
|
14
|
+
async uploadBase64 (req: AmazonS3.UploadBase64.Request): Promise<AmazonS3.UploadBase64.Response> {
|
|
15
15
|
const client = new S3({
|
|
16
16
|
credentials: {
|
|
17
|
-
accessKeyId: credentials.accessKey,
|
|
18
|
-
secretAccessKey: credentials.secretKey,
|
|
17
|
+
accessKeyId: req.credentials.accessKey,
|
|
18
|
+
secretAccessKey: req.credentials.secretKey,
|
|
19
19
|
},
|
|
20
|
-
region: credentials.region,
|
|
20
|
+
region: req.credentials.region,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
const { buffer, extension } = FileService.getBase64Metadata(
|
|
23
|
+
const { buffer, extension } = FileService.getBase64Metadata(req.file);
|
|
24
24
|
|
|
25
|
-
const key =
|
|
26
|
-
?
|
|
25
|
+
const key = req.options?.filename
|
|
26
|
+
? req.options?.filename
|
|
27
27
|
: FileService.getUniqueFilename(extension);
|
|
28
28
|
|
|
29
29
|
const payload: PutObjectCommandInput = {
|
|
30
|
-
Key: this.getBucketPath(key,
|
|
30
|
+
Key: this.getBucketPath(key, req.options?.folder),
|
|
31
31
|
Body: buffer,
|
|
32
|
-
ContentEncoding:
|
|
33
|
-
ContentType:
|
|
34
|
-
Bucket:
|
|
35
|
-
ACL:
|
|
32
|
+
ContentEncoding: req.options?.contentEncoding,
|
|
33
|
+
ContentType: req.options?.contentType,
|
|
34
|
+
Bucket: req.bucket,
|
|
35
|
+
ACL: req.options?.isPrivate ? 'private' : 'public-read',
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
await client.putObject(payload);
|
|
39
39
|
|
|
40
40
|
const { url } = await this.getSignedUrl({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
},
|
|
47
|
-
credentials,
|
|
41
|
+
bucket: req.bucket,
|
|
42
|
+
credentials: req.credentials,
|
|
43
|
+
filename: key,
|
|
44
|
+
folder: req.options?.folder,
|
|
45
|
+
isUpload: false,
|
|
48
46
|
});
|
|
49
47
|
|
|
50
48
|
return {
|
|
51
49
|
key: payload.Key,
|
|
52
|
-
bucket:
|
|
50
|
+
bucket: req.bucket,
|
|
53
51
|
url,
|
|
54
52
|
};
|
|
55
53
|
}
|
|
56
54
|
|
|
57
|
-
async uploadBuffer (
|
|
55
|
+
async uploadBuffer (req: AmazonS3.UploadBuffer.Request): Promise<AmazonS3.UploadBuffer.Response> {
|
|
58
56
|
const client = new S3({
|
|
59
57
|
credentials: {
|
|
60
|
-
accessKeyId: credentials.accessKey,
|
|
61
|
-
secretAccessKey: credentials.secretKey,
|
|
58
|
+
accessKeyId: req.credentials.accessKey,
|
|
59
|
+
secretAccessKey: req.credentials.secretKey,
|
|
62
60
|
},
|
|
63
|
-
region: credentials.region,
|
|
61
|
+
region: req.credentials.region,
|
|
64
62
|
});
|
|
65
63
|
|
|
66
|
-
const key =
|
|
67
|
-
?
|
|
64
|
+
const key = req.options?.filename
|
|
65
|
+
? req.options?.filename
|
|
68
66
|
: FileService.getUniqueFilename('');
|
|
69
67
|
|
|
70
68
|
const payload: PutObjectCommandInput = {
|
|
71
|
-
Key: this.getBucketPath(key,
|
|
72
|
-
Body:
|
|
73
|
-
ContentEncoding:
|
|
74
|
-
ContentType:
|
|
75
|
-
Bucket:
|
|
76
|
-
ACL:
|
|
69
|
+
Key: this.getBucketPath(key, req.options?.folder),
|
|
70
|
+
Body: req.file,
|
|
71
|
+
ContentEncoding: req.options?.contentEncoding,
|
|
72
|
+
ContentType: req.options?.contentType,
|
|
73
|
+
Bucket: req.bucket,
|
|
74
|
+
ACL: req.options?.isPrivate ? 'private' : 'public-read',
|
|
77
75
|
};
|
|
78
76
|
|
|
79
77
|
await client.putObject(payload);
|
|
80
78
|
|
|
81
79
|
const { url } = await this.getSignedUrl({
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
credentials,
|
|
80
|
+
bucket: req.bucket,
|
|
81
|
+
credentials: req.credentials,
|
|
82
|
+
filename: key,
|
|
83
|
+
folder: req.options?.folder,
|
|
84
|
+
isUpload: false,
|
|
89
85
|
});
|
|
90
86
|
|
|
91
87
|
return {
|
|
92
88
|
key: payload.Key,
|
|
93
|
-
bucket:
|
|
89
|
+
bucket: req.bucket,
|
|
94
90
|
url,
|
|
95
91
|
};
|
|
96
92
|
}
|
|
97
93
|
|
|
98
|
-
async deleteFile (
|
|
94
|
+
async deleteFile (req: AmazonS3.DeleteFile.Request): Promise<void> {
|
|
99
95
|
const client = new S3({
|
|
100
96
|
credentials: {
|
|
101
|
-
accessKeyId: credentials.accessKey,
|
|
102
|
-
secretAccessKey: credentials.secretKey,
|
|
97
|
+
accessKeyId: req.credentials.accessKey,
|
|
98
|
+
secretAccessKey: req.credentials.secretKey,
|
|
103
99
|
},
|
|
104
|
-
region: credentials.region,
|
|
100
|
+
region: req.credentials.region,
|
|
105
101
|
});
|
|
106
102
|
|
|
107
103
|
const payload: DeleteObjectCommandInput = {
|
|
108
|
-
Key: this.getBucketPath(
|
|
109
|
-
Bucket:
|
|
104
|
+
Key: this.getBucketPath(req.filename, req.folder),
|
|
105
|
+
Bucket: req.bucket,
|
|
110
106
|
};
|
|
111
107
|
|
|
112
108
|
await client.deleteObject(payload);
|
|
113
109
|
}
|
|
114
110
|
|
|
115
|
-
async listFiles (
|
|
111
|
+
async listFiles (req: AmazonS3.ListFiles.Request): Promise<AmazonS3.ListFiles.Response> {
|
|
116
112
|
const client = new S3({
|
|
117
113
|
credentials: {
|
|
118
|
-
accessKeyId: credentials.accessKey,
|
|
119
|
-
secretAccessKey: credentials.secretKey,
|
|
114
|
+
accessKeyId: req.credentials.accessKey,
|
|
115
|
+
secretAccessKey: req.credentials.secretKey,
|
|
120
116
|
},
|
|
121
|
-
region: credentials.region,
|
|
117
|
+
region: req.credentials.region,
|
|
122
118
|
});
|
|
123
119
|
|
|
124
120
|
const { Contents } = await client.listObjectsV2({
|
|
125
|
-
Bucket:
|
|
126
|
-
Prefix:
|
|
121
|
+
Bucket: req.bucket,
|
|
122
|
+
Prefix: req.folder,
|
|
127
123
|
});
|
|
128
124
|
|
|
129
125
|
return {
|
|
@@ -131,21 +127,21 @@ class AmazonS3Service implements IAmazonS3Service {
|
|
|
131
127
|
};
|
|
132
128
|
}
|
|
133
129
|
|
|
134
|
-
async getSignedUrl (
|
|
130
|
+
async getSignedUrl (req: AmazonS3.GetSignedUrl.Request): Promise<AmazonS3.GetSignedUrl.Response> {
|
|
135
131
|
const client = new S3({
|
|
136
132
|
credentials: {
|
|
137
|
-
accessKeyId: credentials.accessKey,
|
|
138
|
-
secretAccessKey: credentials.secretKey,
|
|
133
|
+
accessKeyId: req.credentials.accessKey,
|
|
134
|
+
secretAccessKey: req.credentials.secretKey,
|
|
139
135
|
},
|
|
140
|
-
region: credentials.region,
|
|
136
|
+
region: req.credentials.region,
|
|
141
137
|
});
|
|
142
138
|
|
|
143
139
|
const payload = {
|
|
144
|
-
Key: this.getBucketPath(
|
|
145
|
-
Bucket:
|
|
140
|
+
Key: this.getBucketPath(req.filename, req.folder),
|
|
141
|
+
Bucket: req.bucket,
|
|
146
142
|
};
|
|
147
143
|
|
|
148
|
-
const method =
|
|
144
|
+
const method = req.isUpload
|
|
149
145
|
? new PutObjectCommand(payload)
|
|
150
146
|
: new GetObjectCommand(payload);
|
|
151
147
|
|
|
@@ -4,19 +4,18 @@ import { AmazonSecretManager, IAmazonSecretManagerService } from '../../interfac
|
|
|
4
4
|
import { parseRecord } from '../../utils/parser';
|
|
5
5
|
|
|
6
6
|
class AmazonSecretManagerService implements IAmazonSecretManagerService {
|
|
7
|
-
public async getSecret<T> (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}: AmazonSecretManager.GetSecret.Request): Promise<AmazonSecretManager.GetSecret.Response<T>> {
|
|
7
|
+
public async getSecret<T> (
|
|
8
|
+
req: AmazonSecretManager.GetSecret.Request
|
|
9
|
+
): Promise<AmazonSecretManager.GetSecret.Response<T>> {
|
|
11
10
|
const client: SecretsManager = new SecretsManager({
|
|
12
11
|
credentials: {
|
|
13
|
-
accessKeyId: credentials.accessKey,
|
|
14
|
-
secretAccessKey: credentials.secretKey,
|
|
12
|
+
accessKeyId: req.credentials.accessKey,
|
|
13
|
+
secretAccessKey: req.credentials.secretKey,
|
|
15
14
|
},
|
|
16
|
-
region: credentials.region,
|
|
15
|
+
region: req.credentials.region,
|
|
17
16
|
});
|
|
18
17
|
|
|
19
|
-
const { SecretString, SecretBinary } = await client.getSecretValue({ SecretId:
|
|
18
|
+
const { SecretString, SecretBinary } = await client.getSecretValue({ SecretId: req.secretId });
|
|
20
19
|
|
|
21
20
|
if (SecretString) {
|
|
22
21
|
const secret = parseRecord(SecretString) as T;
|
package/src/services/aws/sqs.ts
CHANGED
|
@@ -4,36 +4,33 @@ import { AmazonSQS, IAmazonSQSService } from '../../interfaces/aws';
|
|
|
4
4
|
import { parseRecord } from '../../utils';
|
|
5
5
|
|
|
6
6
|
class AmazonSQSService implements IAmazonSQSService {
|
|
7
|
-
async publishMessage (
|
|
7
|
+
async publishMessage (req: AmazonSQS.PublishMessage.Request): Promise<void> {
|
|
8
8
|
const client: SQS = new SQS({
|
|
9
9
|
credentials: {
|
|
10
|
-
accessKeyId: credentials.accessKey,
|
|
11
|
-
secretAccessKey: credentials.secretKey,
|
|
10
|
+
accessKeyId: req.credentials.accessKey,
|
|
11
|
+
secretAccessKey: req.credentials.secretKey,
|
|
12
12
|
},
|
|
13
|
-
region: credentials.region,
|
|
13
|
+
region: req.credentials.region,
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
const { QueueUrl } = await client.getQueueUrl({ QueueName:
|
|
16
|
+
const { QueueUrl } = await client.getQueueUrl({ QueueName: req.queue });
|
|
17
17
|
|
|
18
18
|
await client.sendMessage({
|
|
19
|
-
MessageBody: JSON.stringify(
|
|
19
|
+
MessageBody: JSON.stringify(req.message),
|
|
20
20
|
QueueUrl,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async consumeMessage<T> ({
|
|
25
|
-
credentials,
|
|
26
|
-
data,
|
|
27
|
-
}: AmazonSQS.ConsumeMessage.Request): Promise<AmazonSQS.ConsumeMessage.Response<T>> {
|
|
24
|
+
async consumeMessage<T> (req: AmazonSQS.ConsumeMessage.Request): Promise<AmazonSQS.ConsumeMessage.Response<T>> {
|
|
28
25
|
const client: SQS = new SQS({
|
|
29
26
|
credentials: {
|
|
30
|
-
accessKeyId: credentials.accessKey,
|
|
31
|
-
secretAccessKey: credentials.secretKey,
|
|
27
|
+
accessKeyId: req.credentials.accessKey,
|
|
28
|
+
secretAccessKey: req.credentials.secretKey,
|
|
32
29
|
},
|
|
33
|
-
region: credentials.region,
|
|
30
|
+
region: req.credentials.region,
|
|
34
31
|
});
|
|
35
32
|
|
|
36
|
-
const { QueueUrl } = await client.getQueueUrl({ QueueName:
|
|
33
|
+
const { QueueUrl } = await client.getQueueUrl({ QueueName: req.queue });
|
|
37
34
|
|
|
38
35
|
const { Messages } = await client.receiveMessage({
|
|
39
36
|
QueueUrl,
|
|
@@ -60,19 +57,16 @@ class AmazonSQSService implements IAmazonSQSService {
|
|
|
60
57
|
};
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
async consumeMessages<T> ({
|
|
64
|
-
credentials,
|
|
65
|
-
data,
|
|
66
|
-
}: AmazonSQS.ConsumeMessages.Request): Promise<AmazonSQS.ConsumeMessages.Response<T>> {
|
|
60
|
+
async consumeMessages<T> (req: AmazonSQS.ConsumeMessages.Request): Promise<AmazonSQS.ConsumeMessages.Response<T>> {
|
|
67
61
|
const client: SQS = new SQS({
|
|
68
62
|
credentials: {
|
|
69
|
-
accessKeyId: credentials.accessKey,
|
|
70
|
-
secretAccessKey: credentials.secretKey,
|
|
63
|
+
accessKeyId: req.credentials.accessKey,
|
|
64
|
+
secretAccessKey: req.credentials.secretKey,
|
|
71
65
|
},
|
|
72
|
-
region: credentials.region,
|
|
66
|
+
region: req.credentials.region,
|
|
73
67
|
});
|
|
74
68
|
|
|
75
|
-
const { QueueUrl } = await client.getQueueUrl({ QueueName:
|
|
69
|
+
const { QueueUrl } = await client.getQueueUrl({ QueueName: req.queue });
|
|
76
70
|
|
|
77
71
|
const { Messages } = await client.receiveMessage({
|
|
78
72
|
QueueUrl,
|
|
@@ -104,4 +98,4 @@ class AmazonSQSService implements IAmazonSQSService {
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
|
|
107
|
-
export default new AmazonSQSService();
|
|
101
|
+
export default new AmazonSQSService();
|