aloux-iam 0.0.112 → 0.0.114
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/lib/controllers/operationsAWS.js +168 -159
- package/package.json +1 -1
|
@@ -1,91 +1,101 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
const {
|
|
2
|
+
S3Client,
|
|
3
|
+
PutObjectCommand,
|
|
4
|
+
DeleteObjectsCommand,
|
|
5
|
+
DeleteObjectCommand,
|
|
6
|
+
} = require("@aws-sdk/client-s3");
|
|
7
|
+
const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");
|
|
8
|
+
const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns");
|
|
9
|
+
const path = require("path");
|
|
10
|
+
const self = module.exports;
|
|
6
11
|
|
|
7
12
|
/**
|
|
8
13
|
* pathFile = folder/file_name-file_id
|
|
9
14
|
* file = req.files.property
|
|
10
15
|
*/
|
|
11
16
|
self.upload = async (pathFile, file) => {
|
|
12
|
-
|
|
17
|
+
try {
|
|
18
|
+
const s3Client = new S3Client({ region: process.env.AWS_REGION });
|
|
19
|
+
const extension = path.extname(file.name);
|
|
20
|
+
const params = {
|
|
21
|
+
Bucket: process.env.AWS_BUCKET,
|
|
22
|
+
Key: pathFile + extension,
|
|
23
|
+
ContentType: "application/" + path.extname(file.name).replace(".", ""),
|
|
24
|
+
ContentDisposition: "inline",
|
|
25
|
+
Body: file.data,
|
|
26
|
+
ACL: "public-read",
|
|
27
|
+
};
|
|
28
|
+
const command = new PutObjectCommand(params);
|
|
29
|
+
await s3Client.send(command);
|
|
30
|
+
const evidence =
|
|
31
|
+
"https://" +
|
|
32
|
+
process.env.AWS_BUCKET +
|
|
33
|
+
".s3.amazonaws.com/" +
|
|
34
|
+
pathFile +
|
|
35
|
+
extension;
|
|
13
36
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
await s3Client.send(command)
|
|
25
|
-
const evidence = 'https://' + process.env.AWS_BUCKET + '.s3.amazonaws.com/' + pathFile + extension
|
|
26
|
-
|
|
27
|
-
return evidence
|
|
28
|
-
} catch (error) {
|
|
29
|
-
throw {
|
|
30
|
-
code: 400,
|
|
31
|
-
title: 'Error en los parametros',
|
|
32
|
-
detail: new Error(error),
|
|
33
|
-
suggestion: 'Contacta con el administrador'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
+
return evidence;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw {
|
|
40
|
+
code: 400,
|
|
41
|
+
title: "Error en los parametros",
|
|
42
|
+
detail: new Error(error),
|
|
43
|
+
suggestion: "Contacta con el administrador",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
37
47
|
|
|
38
48
|
// files = [{key: 'folder/file1'},{key: 'folder/file1'}]
|
|
39
49
|
self.deleteMany = async (files) => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return evidence
|
|
56
|
-
} catch (error) {
|
|
57
|
-
throw {
|
|
58
|
-
code: 400,
|
|
59
|
-
title: 'Error en los parametros',
|
|
60
|
-
detail: new Error(error),
|
|
61
|
-
suggestion: 'Contacta con el administrador'
|
|
62
|
-
}
|
|
50
|
+
try {
|
|
51
|
+
let evidence;
|
|
52
|
+
const s3Client = new S3Client({ region: process.env.AWS_REGION });
|
|
53
|
+
if (files.length > 0) {
|
|
54
|
+
const params = {
|
|
55
|
+
Bucket: process.env.AWS_BUCKET,
|
|
56
|
+
Delete: {
|
|
57
|
+
Objects: files,
|
|
58
|
+
Quiet: true,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const command = new DeleteObjectsCommand(params);
|
|
62
|
+
evidence = await s3Client.send(command);
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
|
|
65
|
+
return evidence;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw {
|
|
68
|
+
code: 400,
|
|
69
|
+
title: "Error en los parametros",
|
|
70
|
+
detail: new Error(error),
|
|
71
|
+
suggestion: "Contacta con el administrador",
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
65
75
|
|
|
66
76
|
// file = folder/file_name
|
|
67
77
|
self.delete = async (file) => {
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
try {
|
|
79
|
+
const s3Client = new S3Client({ region: process.env.AWS_REGION });
|
|
70
80
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
81
|
+
const params = {
|
|
82
|
+
Bucket: process.env.AWS_BUCKET,
|
|
83
|
+
Key: file,
|
|
84
|
+
};
|
|
75
85
|
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
const command = new DeleteObjectCommand(params);
|
|
87
|
+
const evidence = await s3Client.send(command);
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
+
return evidence;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
throw {
|
|
92
|
+
code: 400,
|
|
93
|
+
title: "Error en los parametros",
|
|
94
|
+
detail: new Error(error),
|
|
95
|
+
suggestion: "Contacta con el administrador",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
};
|
|
89
99
|
|
|
90
100
|
/**
|
|
91
101
|
* email: Destination email
|
|
@@ -93,19 +103,18 @@ self.delete = async (file) => {
|
|
|
93
103
|
* subject: Mail subject
|
|
94
104
|
*/
|
|
95
105
|
self.send = async (email, message, subject) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
Data: `<html>
|
|
106
|
+
try {
|
|
107
|
+
const client = new SESClient({ region: process.env.AWS_REGION });
|
|
108
|
+
const params = {
|
|
109
|
+
Destination: {
|
|
110
|
+
ToAddresses: [email],
|
|
111
|
+
},
|
|
112
|
+
Message: {
|
|
113
|
+
Body: {
|
|
114
|
+
Html: {
|
|
115
|
+
Charset: "UTF-8",
|
|
116
|
+
Data:
|
|
117
|
+
`<html>
|
|
109
118
|
<body style="font-family: Verdana, Geneva, sans-serif;">
|
|
110
119
|
<table align='center' width='100%' cellpadding='0' cellspacing='0'
|
|
111
120
|
style='max-width: 640px; padding: 20px 40px; background-color: #fff; box-shadow: 0 5px 15px 0 rgba(0, 0, 0, 0.1), 0 15px 35px 0 rgba(0, 0, 0, 0.05);'>
|
|
@@ -118,7 +127,9 @@ self.send = async (email, message, subject) => {
|
|
|
118
127
|
<div
|
|
119
128
|
style="background:#000000; color:#ffffff; font-size: 18px; text-decoration:none; padding:1rem 2.5rem; border-radius: 8px;">
|
|
120
129
|
<a style="color:#ffffff; font-size: 20px; text-decoration:none; padding:0;"
|
|
121
|
-
href="
|
|
130
|
+
href="` +
|
|
131
|
+
message +
|
|
132
|
+
`">Acceder
|
|
122
133
|
</a>
|
|
123
134
|
</div>
|
|
124
135
|
</a>
|
|
@@ -129,28 +140,28 @@ self.send = async (email, message, subject) => {
|
|
|
129
140
|
</tbody>
|
|
130
141
|
</table>
|
|
131
142
|
</body>
|
|
132
|
-
</html
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
143
|
+
</html>`,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
Subject: {
|
|
147
|
+
Charset: "UTF-8",
|
|
148
|
+
Data: subject,
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
Source: process.env.AWS_EMAIL_SENDER, //verified mail
|
|
152
|
+
};
|
|
153
|
+
const command = new SendEmailCommand(params);
|
|
154
|
+
await client.send(command);
|
|
155
|
+
return true;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
throw {
|
|
158
|
+
code: 400,
|
|
159
|
+
title: "Error en los parametros",
|
|
160
|
+
detail: new Error(error),
|
|
161
|
+
suggestion: "Contacta con el administrador",
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
154
165
|
|
|
155
166
|
/**
|
|
156
167
|
* email: Destination email
|
|
@@ -158,62 +169,60 @@ self.send = async (email, message, subject) => {
|
|
|
158
169
|
* subject: Mail subject
|
|
159
170
|
*/
|
|
160
171
|
self.sendCustom = async (email, message, subject) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
}
|
|
172
|
+
try {
|
|
173
|
+
const client = new SESClient({ region: process.env.AWS_REGION });
|
|
174
|
+
const params = {
|
|
175
|
+
Destination: {
|
|
176
|
+
ToAddresses: [email],
|
|
177
|
+
},
|
|
178
|
+
Message: {
|
|
179
|
+
Body: {
|
|
180
|
+
Html: {
|
|
181
|
+
Charset: "UTF-8",
|
|
182
|
+
Data: message,
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
Subject: {
|
|
186
|
+
Charset: "UTF-8",
|
|
187
|
+
Data: subject,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
Source: process.env.AWS_EMAIL_SENDER, //verified mail
|
|
191
|
+
};
|
|
192
|
+
const command = new SendEmailCommand(params);
|
|
193
|
+
await client.send(command);
|
|
194
|
+
return true;
|
|
195
|
+
} catch (error) {
|
|
196
|
+
throw {
|
|
197
|
+
code: 400,
|
|
198
|
+
title: "Error en los parametros",
|
|
199
|
+
detail: new Error(error),
|
|
200
|
+
suggestion: "Contacta con el administrador",
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
};
|
|
195
204
|
|
|
196
205
|
/**
|
|
197
206
|
* phoneNumber: Destination email
|
|
198
207
|
* message: Mail body
|
|
199
208
|
*/
|
|
200
209
|
self.sendMessagePhone = async (phoneNumber, message) => {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
210
|
+
try {
|
|
211
|
+
const client = new SNSClient({ region: process.env.AWS_REGION });
|
|
212
|
+
const params = {
|
|
213
|
+
PhoneNumber: phoneNumber,
|
|
214
|
+
Message: message,
|
|
215
|
+
};
|
|
207
216
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
217
|
+
const command = new PublishCommand(params);
|
|
218
|
+
await client.send(command);
|
|
219
|
+
return true;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
throw {
|
|
222
|
+
code: 400,
|
|
223
|
+
title: "Error en los parametros",
|
|
224
|
+
detail: new Error(error),
|
|
225
|
+
suggestion: "Contacta con el administrador",
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
};
|