aloux-iam 0.0.112 → 0.0.113

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.
@@ -1,91 +1,101 @@
1
- const { S3Client, PutObjectCommand, DeleteObjectsCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3")
2
- const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses")
3
- const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns")
4
- const path = require('path')
5
- const self = module.exports
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
- try {
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/" + extension,
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
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
15
- const extension = path.extname(file.name)
16
- const params = {
17
- Bucket: process.env.AWS_BUCKET,
18
- Key: pathFile + extension,
19
- ContentType: 'application/' + extension,
20
- Body: file.data,
21
- ACL: 'public-read'
22
- }
23
- const command = new PutObjectCommand(params)
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
- try {
41
- let evidence
42
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
43
- if (files.length > 0) {
44
- const params = {
45
- Bucket: process.env.AWS_BUCKET,
46
- Delete: {
47
- Objects: files,
48
- Quiet: true
49
- },
50
- }
51
- const command = new DeleteObjectsCommand(params)
52
- evidence = await s3Client.send(command)
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
- try {
69
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
78
+ try {
79
+ const s3Client = new S3Client({ region: process.env.AWS_REGION });
70
80
 
71
- const params = {
72
- Bucket: process.env.AWS_BUCKET,
73
- Key: file,
74
- }
81
+ const params = {
82
+ Bucket: process.env.AWS_BUCKET,
83
+ Key: file,
84
+ };
75
85
 
76
- const command = new DeleteObjectCommand(params)
77
- const evidence = await s3Client.send(command)
86
+ const command = new DeleteObjectCommand(params);
87
+ const evidence = await s3Client.send(command);
78
88
 
79
- return evidence
80
- } catch (error) {
81
- throw {
82
- code: 400,
83
- title: 'Error en los parametros',
84
- detail: new Error(error),
85
- suggestion: 'Contacta con el administrador'
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
- try {
97
- const client = new SESClient({ region: process.env.AWS_REGION })
98
- const params = {
99
- Destination: {
100
- ToAddresses: [
101
- email
102
- ]
103
- },
104
- Message: {
105
- Body: {
106
- Html: {
107
- Charset: "UTF-8",
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="`+ message + `">Acceder
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
- Subject: {
136
- Charset: "UTF-8",
137
- Data: subject
138
- }
139
- },
140
- Source: process.env.AWS_EMAIL_SENDER//verified mail
141
- }
142
- const command = new SendEmailCommand(params)
143
- await client.send(command)
144
- return true
145
- } catch (error) {
146
- throw {
147
- code: 400,
148
- title: 'Error en los parametros',
149
- detail: new Error(error),
150
- suggestion: 'Contacta con el administrador'
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
- try {
162
- const client = new SESClient({ region: process.env.AWS_REGION })
163
- const params = {
164
- Destination: {
165
- ToAddresses: [
166
- email
167
- ]
168
- },
169
- Message: {
170
- Body: {
171
- Html: {
172
- Charset: "UTF-8",
173
- Data: message
174
- }
175
- },
176
- Subject: {
177
- Charset: "UTF-8",
178
- Data: subject
179
- }
180
- },
181
- Source: process.env.AWS_EMAIL_SENDER//verified mail
182
- }
183
- const command = new SendEmailCommand(params)
184
- await client.send(command)
185
- return true
186
- } catch (error) {
187
- throw {
188
- code: 400,
189
- title: 'Error en los parametros',
190
- detail: new Error(error),
191
- suggestion: 'Contacta con el administrador'
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
- try {
202
- const client = new SNSClient({ region: process.env.AWS_REGION })
203
- const params = {
204
- PhoneNumber: phoneNumber,
205
- Message: message
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
- const command = new PublishCommand(params)
209
- await client.send(command)
210
- return true
211
- } catch (error) {
212
- throw {
213
- code: 400,
214
- title: 'Error en los parametros',
215
- detail: new Error(error),
216
- suggestion: 'Contacta con el administrador'
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aloux-iam",
3
- "version": "0.0.112",
3
+ "version": "0.0.113",
4
4
  "description": "Aloux IAM for APIs ",
5
5
  "main": "index.js",
6
6
  "scripts": {