aloux-iam 0.0.115 → 0.0.117

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,88 +1,88 @@
1
- const { adapt, managedwriter } = require('@google-cloud/bigquery-storage')
2
- const { WriterClient, JSONWriter } = managedwriter
3
- const { BigQuery } = require('@google-cloud/bigquery')
4
- const self = module.exports
5
-
6
- self.callAppendRows = async (row, table) => {
7
- const projectId = process.env.PROJECT_ID
8
- const datasetId = process.env.DATASET_ID
9
- const tableId = table
10
-
11
- const destinationTable = `projects/${projectId}/datasets/${datasetId}/tables/${tableId}`
12
- const writeClient = new WriterClient({ projectId })
13
- const bigquery = new BigQuery({ projectId: projectId })
14
-
15
- let results = {}
16
- try {
17
- const dataset = bigquery.dataset(datasetId)
18
- const table = await dataset.table(tableId)
19
- const [metadata] = await table.getMetadata()
20
- const { schema } = metadata
21
- const storageSchema =
22
- adapt.convertBigQuerySchemaToStorageTableSchema(schema)
23
- const protoDescriptor = adapt.convertStorageSchemaToProto2Descriptor(
24
- storageSchema,
25
- 'root'
26
- )
27
-
28
- const connection = await writeClient.createStreamConnection({
29
- streamId: managedwriter.DefaultStream,
30
- destinationTable,
31
- })
32
- const streamId = connection.getStreamId()
33
-
34
- const writer = new JSONWriter({
35
- streamId,
36
- connection,
37
- protoDescriptor,
38
- })
39
-
40
- let rows = []
41
- const pendingWrites = []
42
- rows = row
43
-
44
- // Send batch.
45
- pw = writer.appendRows(rows)
46
- pendingWrites.push(pw)
47
-
48
- results = await Promise.all(
49
- pendingWrites.map(pw => pw.getResult())
50
- )
51
-
52
- await connection.finalize()
53
- await writeClient.batchCommitWriteStream({
54
- parent: destinationTable,
55
- writeStreams: [streamId],
56
- })
57
-
58
- } catch (err) {
59
- throw {
60
- code: 400,
61
- title: 'Ocurrio un error',
62
- detail: err.toString(),
63
- suggestion: 'Revisa callAppendRows()'
64
- }
65
- } finally {
66
- writeClient.close()
67
- }
68
-
69
- return results
70
- }
71
-
72
- self.factoryDateTime = async (dateNumber) => {
73
- const d = new Date(dateNumber)
74
- let year = d.getFullYear()
75
- let month = d.getMonth() + 1
76
- let day = d.getDate()
77
- let hour = d.getHours()
78
- let min = d.getMinutes()
79
- let seg = d.getSeconds()
80
-
81
- month = month < 10 ? "0" + month : month
82
- day = day < 10 ? "0" + day : day
83
- hour = hour < 10 ? "0" + hour : hour
84
- min = min < 10 ? "0" + min : min
85
- seg = seg < 10 ? "0" + seg : seg
86
-
87
- return year + "-" + month + "-" + day + "T" + hour + ":" + min + ":" + seg
1
+ const { adapt, managedwriter } = require('@google-cloud/bigquery-storage')
2
+ const { WriterClient, JSONWriter } = managedwriter
3
+ const { BigQuery } = require('@google-cloud/bigquery')
4
+ const self = module.exports
5
+
6
+ self.callAppendRows = async (row, table) => {
7
+ const projectId = process.env.PROJECT_ID
8
+ const datasetId = process.env.DATASET_ID
9
+ const tableId = table
10
+
11
+ const destinationTable = `projects/${projectId}/datasets/${datasetId}/tables/${tableId}`
12
+ const writeClient = new WriterClient({ projectId })
13
+ const bigquery = new BigQuery({ projectId: projectId })
14
+
15
+ let results = {}
16
+ try {
17
+ const dataset = bigquery.dataset(datasetId)
18
+ const table = await dataset.table(tableId)
19
+ const [metadata] = await table.getMetadata()
20
+ const { schema } = metadata
21
+ const storageSchema =
22
+ adapt.convertBigQuerySchemaToStorageTableSchema(schema)
23
+ const protoDescriptor = adapt.convertStorageSchemaToProto2Descriptor(
24
+ storageSchema,
25
+ 'root'
26
+ )
27
+
28
+ const connection = await writeClient.createStreamConnection({
29
+ streamId: managedwriter.DefaultStream,
30
+ destinationTable,
31
+ })
32
+ const streamId = connection.getStreamId()
33
+
34
+ const writer = new JSONWriter({
35
+ streamId,
36
+ connection,
37
+ protoDescriptor,
38
+ })
39
+
40
+ let rows = []
41
+ const pendingWrites = []
42
+ rows = row
43
+
44
+ // Send batch.
45
+ pw = writer.appendRows(rows)
46
+ pendingWrites.push(pw)
47
+
48
+ results = await Promise.all(
49
+ pendingWrites.map(pw => pw.getResult())
50
+ )
51
+
52
+ await connection.finalize()
53
+ await writeClient.batchCommitWriteStream({
54
+ parent: destinationTable,
55
+ writeStreams: [streamId],
56
+ })
57
+
58
+ } catch (err) {
59
+ throw {
60
+ code: 400,
61
+ title: 'Ocurrio un error',
62
+ detail: err.toString(),
63
+ suggestion: 'Revisa callAppendRows()'
64
+ }
65
+ } finally {
66
+ writeClient.close()
67
+ }
68
+
69
+ return results
70
+ }
71
+
72
+ self.factoryDateTime = async (dateNumber) => {
73
+ const d = new Date(dateNumber)
74
+ let year = d.getFullYear()
75
+ let month = d.getMonth() + 1
76
+ let day = d.getDate()
77
+ let hour = d.getHours()
78
+ let min = d.getMinutes()
79
+ let seg = d.getSeconds()
80
+
81
+ month = month < 10 ? "0" + month : month
82
+ day = day < 10 ? "0" + day : day
83
+ hour = hour < 10 ? "0" + hour : hour
84
+ min = min < 10 ? "0" + min : min
85
+ seg = seg < 10 ? "0" + seg : seg
86
+
87
+ return year + "-" + month + "-" + day + "T" + hour + ":" + min + ":" + seg
88
88
  }
@@ -1,72 +1,72 @@
1
- const { S3Client, PutObjectCommand, DeleteObjectsCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3")
2
- const path = require('path')
3
- const utils = require('../config/utils')
4
- const self = module.exports
5
-
6
- /**
7
- * pathFile = folder/file_name-file_id
8
- * file = req.files.property
9
- */
10
- self.upload = async (pathFile, file) => {
11
- try {
12
-
13
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
14
- const extension = path.extname(file.name)
15
- const params = {
16
- Bucket: process.env.AWS_BUCKET,
17
- Key: pathFile + extension,
18
- ContentType: 'application/' + extension,
19
- Body: file.data,
20
- ACL: 'public-read'
21
- }
22
- const command = new PutObjectCommand(params)
23
- await s3Client.send(command)
24
- const evidence = 'https://' + process.env.AWS_BUCKET + '.s3.amazonaws.com/' + pathFile + extension
25
-
26
- return evidence
27
- } catch (error) {
28
- await utils.responseError(error)
29
- }
30
- }
31
-
32
- // files = [{key: 'folder/file1'},{key: 'folder/file1'}]
33
- self.deleteMany = async (files) => {
34
- try {
35
- let evidence
36
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
37
- if (files.length > 0) {
38
- const params = {
39
- Bucket: process.env.AWS_BUCKET,
40
- Delete: {
41
- Objects: files,
42
- Quiet: true
43
- },
44
- }
45
- const command = new DeleteObjectsCommand(params)
46
- evidence = await s3Client.send(command)
47
- }
48
-
49
- return evidence
50
- } catch (error) {
51
- await utils.responseError(error)
52
- }
53
- }
54
-
55
- // file = folder/file_name
56
- self.delete = async (file) => {
57
- try {
58
- const s3Client = new S3Client({ region: process.env.AWS_REGION })
59
-
60
- const params = {
61
- Bucket: process.env.AWS_BUCKET,
62
- Key: file,
63
- }
64
-
65
- const command = new DeleteObjectCommand(params)
66
- const evidence = await s3Client.send(command)
67
-
68
- return evidence
69
- } catch (error) {
70
- await utils.responseError(error)
71
- }
1
+ const { S3Client, PutObjectCommand, DeleteObjectsCommand, DeleteObjectCommand } = require("@aws-sdk/client-s3")
2
+ const path = require('path')
3
+ const utils = require('../config/utils')
4
+ const self = module.exports
5
+
6
+ /**
7
+ * pathFile = folder/file_name-file_id
8
+ * file = req.files.property
9
+ */
10
+ self.upload = async (pathFile, file) => {
11
+ try {
12
+
13
+ const s3Client = new S3Client({ region: process.env.AWS_REGION })
14
+ const extension = path.extname(file.name)
15
+ const params = {
16
+ Bucket: process.env.AWS_BUCKET,
17
+ Key: pathFile + extension,
18
+ ContentType: 'application/' + extension,
19
+ Body: file.data,
20
+ ACL: 'public-read'
21
+ }
22
+ const command = new PutObjectCommand(params)
23
+ await s3Client.send(command)
24
+ const evidence = 'https://' + process.env.AWS_BUCKET + '.s3.amazonaws.com/' + pathFile + extension
25
+
26
+ return evidence
27
+ } catch (error) {
28
+ await utils.responseError(error)
29
+ }
30
+ }
31
+
32
+ // files = [{key: 'folder/file1'},{key: 'folder/file1'}]
33
+ self.deleteMany = async (files) => {
34
+ try {
35
+ let evidence
36
+ const s3Client = new S3Client({ region: process.env.AWS_REGION })
37
+ if (files.length > 0) {
38
+ const params = {
39
+ Bucket: process.env.AWS_BUCKET,
40
+ Delete: {
41
+ Objects: files,
42
+ Quiet: true
43
+ },
44
+ }
45
+ const command = new DeleteObjectsCommand(params)
46
+ evidence = await s3Client.send(command)
47
+ }
48
+
49
+ return evidence
50
+ } catch (error) {
51
+ await utils.responseError(error)
52
+ }
53
+ }
54
+
55
+ // file = folder/file_name
56
+ self.delete = async (file) => {
57
+ try {
58
+ const s3Client = new S3Client({ region: process.env.AWS_REGION })
59
+
60
+ const params = {
61
+ Bucket: process.env.AWS_BUCKET,
62
+ Key: file,
63
+ }
64
+
65
+ const command = new DeleteObjectCommand(params)
66
+ const evidence = await s3Client.send(command)
67
+
68
+ return evidence
69
+ } catch (error) {
70
+ await utils.responseError(error)
71
+ }
72
72
  }
@@ -1,98 +1,98 @@
1
- const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses")
2
- const self = module.exports
3
-
4
- /**
5
- * email: Destination email
6
- * message: Link to login
7
- * subject: Mail subject
8
- */
9
- self.send = async (email, message, subject) => {
10
- try {
11
- const client = new SESClient({ region: process.env.AWS_REGION })
12
- const params = {
13
- Destination: {
14
- ToAddresses: [
15
- email
16
- ]
17
- },
18
- Message: {
19
- Body: {
20
- Html: {
21
- Charset: "UTF-8",
22
- Data: `<html>
23
- <body style="font-family: Verdana, Geneva, sans-serif;">
24
- <table align='center' width='100%' cellpadding='0' cellspacing='0'
25
- 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);'>
26
- <tbody>
27
- <tr>
28
- <td style='font-size: 14px; text-align: justify; line-height: 1.75;'>
29
- <p>A continuación, inicie sesión para establecer la contraseña de su usuario en la plataforma</p>
30
- <div style="width: 100%!important; text-align:center; margin-bottom: 1.5rem;">
31
- <a style="width: 100%!important; text-decoration:none;">
32
- <div
33
- style="background:#000000; color:#ffffff; font-size: 18px; text-decoration:none; padding:1rem 2.5rem; border-radius: 8px;">
34
- <a style="color:#ffffff; font-size: 20px; text-decoration:none; padding:0;"
35
- href="`+ message + `">Acceder
36
- </a>
37
- </div>
38
- </a>
39
- </div>
40
- <hr style="width:100%; background:#000000; padding:4px 0;">
41
- </td>
42
- </tr>
43
- </tbody>
44
- </table>
45
- </body>
46
- </html>`
47
- }
48
- },
49
- Subject: {
50
- Charset: "UTF-8",
51
- Data: subject
52
- }
53
- },
54
- Source: process.env.AWS_EMAIL_SENDER//verified mail
55
- }
56
- const command = new SendEmailCommand(params)
57
- await client.send(command)
58
- return true
59
- } catch (error) {
60
- await utils.responseError(error)
61
- }
62
- }
63
-
64
- /**
65
- * email: Destination email
66
- * message: Mail body
67
- * subject: Mail subject
68
- */
69
- self.sendCustom = async (email, message, subject) => {
70
- try {
71
- const client = new SESClient({ region: process.env.AWS_REGION })
72
- const params = {
73
- Destination: {
74
- ToAddresses: [
75
- email
76
- ]
77
- },
78
- Message: {
79
- Body: {
80
- Html: {
81
- Charset: "UTF-8",
82
- Data: message
83
- }
84
- },
85
- Subject: {
86
- Charset: "UTF-8",
87
- Data: subject
88
- }
89
- },
90
- Source: process.env.AWS_EMAIL_SENDER//verified mail
91
- }
92
- const command = new SendEmailCommand(params)
93
- await client.send(command)
94
- return true
95
- } catch (error) {
96
- await utils.responseError(error)
97
- }
1
+ const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses")
2
+ const self = module.exports
3
+
4
+ /**
5
+ * email: Destination email
6
+ * message: Link to login
7
+ * subject: Mail subject
8
+ */
9
+ self.send = async (email, message, subject) => {
10
+ try {
11
+ const client = new SESClient({ region: process.env.AWS_REGION })
12
+ const params = {
13
+ Destination: {
14
+ ToAddresses: [
15
+ email
16
+ ]
17
+ },
18
+ Message: {
19
+ Body: {
20
+ Html: {
21
+ Charset: "UTF-8",
22
+ Data: `<html>
23
+ <body style="font-family: Verdana, Geneva, sans-serif;">
24
+ <table align='center' width='100%' cellpadding='0' cellspacing='0'
25
+ 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);'>
26
+ <tbody>
27
+ <tr>
28
+ <td style='font-size: 14px; text-align: justify; line-height: 1.75;'>
29
+ <p>A continuación, inicie sesión para establecer la contraseña de su usuario en la plataforma</p>
30
+ <div style="width: 100%!important; text-align:center; margin-bottom: 1.5rem;">
31
+ <a style="width: 100%!important; text-decoration:none;">
32
+ <div
33
+ style="background:#000000; color:#ffffff; font-size: 18px; text-decoration:none; padding:1rem 2.5rem; border-radius: 8px;">
34
+ <a style="color:#ffffff; font-size: 20px; text-decoration:none; padding:0;"
35
+ href="`+ message + `">Acceder
36
+ </a>
37
+ </div>
38
+ </a>
39
+ </div>
40
+ <hr style="width:100%; background:#000000; padding:4px 0;">
41
+ </td>
42
+ </tr>
43
+ </tbody>
44
+ </table>
45
+ </body>
46
+ </html>`
47
+ }
48
+ },
49
+ Subject: {
50
+ Charset: "UTF-8",
51
+ Data: subject
52
+ }
53
+ },
54
+ Source: process.env.AWS_EMAIL_SENDER//verified mail
55
+ }
56
+ const command = new SendEmailCommand(params)
57
+ await client.send(command)
58
+ return true
59
+ } catch (error) {
60
+ await utils.responseError(error)
61
+ }
62
+ }
63
+
64
+ /**
65
+ * email: Destination email
66
+ * message: Mail body
67
+ * subject: Mail subject
68
+ */
69
+ self.sendCustom = async (email, message, subject) => {
70
+ try {
71
+ const client = new SESClient({ region: process.env.AWS_REGION })
72
+ const params = {
73
+ Destination: {
74
+ ToAddresses: [
75
+ email
76
+ ]
77
+ },
78
+ Message: {
79
+ Body: {
80
+ Html: {
81
+ Charset: "UTF-8",
82
+ Data: message
83
+ }
84
+ },
85
+ Subject: {
86
+ Charset: "UTF-8",
87
+ Data: subject
88
+ }
89
+ },
90
+ Source: process.env.AWS_EMAIL_SENDER//verified mail
91
+ }
92
+ const command = new SendEmailCommand(params)
93
+ await client.send(command)
94
+ return true
95
+ } catch (error) {
96
+ await utils.responseError(error)
97
+ }
98
98
  }
@@ -1,22 +1,22 @@
1
- const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns")
2
- const self = module.exports
3
-
4
- /**
5
- * phoneNumber: Destination email
6
- * message: Mail body
7
- */
8
- self.sendMessagePhone = async (phoneNumber, message) => {
9
- try {
10
- const client = new SNSClient({ region: process.env.AWS_REGION })
11
- const params = {
12
- PhoneNumber: phoneNumber,
13
- Message: message
14
- }
15
-
16
- const command = new PublishCommand(params)
17
- await client.send(command)
18
- return true
19
- } catch (error) {
20
- await utils.responseError(error)
21
- }
1
+ const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns")
2
+ const self = module.exports
3
+
4
+ /**
5
+ * phoneNumber: Destination email
6
+ * message: Mail body
7
+ */
8
+ self.sendMessagePhone = async (phoneNumber, message) => {
9
+ try {
10
+ const client = new SNSClient({ region: process.env.AWS_REGION })
11
+ const params = {
12
+ PhoneNumber: phoneNumber,
13
+ Message: message
14
+ }
15
+
16
+ const command = new PublishCommand(params)
17
+ await client.send(command)
18
+ return true
19
+ } catch (error) {
20
+ await utils.responseError(error)
21
+ }
22
22
  }