aws-v3-sdk 1.0.25 → 1.0.26

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/README.md CHANGED
@@ -1,4 +1,2 @@
1
1
  # aws-v3-sdk
2
2
  AWS JS SDK UTILS
3
-
4
- PROD Release
@@ -15,7 +15,7 @@ class CognitoIdentityServiceProvider {
15
15
  }
16
16
 
17
17
  async adminCreateUser (params, callback) {
18
- const command = new AdminCreateUserCommand(params);
18
+ const command = new AdminCreateUserCommand(params)
19
19
  this.client.send(command).then(data => {
20
20
  callback(null, data)
21
21
  }).catch(err => {
@@ -24,7 +24,7 @@ class CognitoIdentityServiceProvider {
24
24
  }
25
25
 
26
26
  async adminSetUserMFAPreference (params, callback) {
27
- const command = new AdminSetUserMFAPreferenceCommand(params);
27
+ const command = new AdminSetUserMFAPreferenceCommand(params)
28
28
  this.client.send(command).then(data => {
29
29
  callback(null, data)
30
30
  }).catch(err => {
@@ -33,7 +33,7 @@ class CognitoIdentityServiceProvider {
33
33
  }
34
34
 
35
35
  async adminDeleteUser (params, callback) {
36
- const command = new AdminDeleteUserCommand(params);
36
+ const command = new AdminDeleteUserCommand(params)
37
37
  this.client.send(command).then(data => {
38
38
  callback(null, data)
39
39
  }).catch(err => {
@@ -42,7 +42,7 @@ class CognitoIdentityServiceProvider {
42
42
  }
43
43
 
44
44
  async adminEnableUser (params, callback) {
45
- const command = new AdminEnableUserCommand(params);
45
+ const command = new AdminEnableUserCommand(params)
46
46
  this.client.send(command).then(data => {
47
47
  callback(null, data)
48
48
  }).catch(err => {
@@ -50,9 +50,8 @@ class CognitoIdentityServiceProvider {
50
50
  })
51
51
  }
52
52
 
53
-
54
53
  async adminDisableUser (params, callback) {
55
- const command = new AdminDisableUserCommand(params);
54
+ const command = new AdminDisableUserCommand(params)
56
55
  this.client.send(command).then(data => {
57
56
  callback(null, data)
58
57
  }).catch(err => {
@@ -61,14 +60,13 @@ class CognitoIdentityServiceProvider {
61
60
  }
62
61
 
63
62
  async adminUserGlobalSignOut (params, callback) {
64
- const command = new AdminUserGlobalSignOutCommand(params);
63
+ const command = new AdminUserGlobalSignOutCommand(params)
65
64
  this.client.send(command).then(data => {
66
65
  callback(null, data)
67
66
  }).catch(err => {
68
67
  callback(err)
69
68
  })
70
69
  }
71
-
72
70
  }
73
71
 
74
72
  module.exports = CognitoIdentityServiceProvider
@@ -1,8 +1,16 @@
1
1
  const { DynamoDB, DynamoDBClient } = require('@aws-sdk/client-dynamodb')
2
2
  const { DynamoDBDocument, DynamoDBDocumentClient, GetCommand, BatchWriteCommand, PutCommand, QueryCommand, ScanCommand, DeleteCommand } = require('@aws-sdk/lib-dynamodb')
3
- const ddb = new DynamoDBClient()
4
- const documentClient = DynamoDBDocumentClient.from(ddb)
5
3
 
4
+ const { Agent } = require('https')
5
+ const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
6
+
7
+ const ddb = new DynamoDBClient({
8
+ requestHandler: new NodeHttpHandler({
9
+ httpsAgent: new Agent({ keepAlive: false })
10
+ })
11
+ })
12
+
13
+ const documentClient = DynamoDBDocumentClient.from(ddb)
6
14
  class DocumentClient {
7
15
  get (params, callback) {
8
16
  const getCommand = new GetCommand(params)
@@ -60,7 +68,7 @@ class DocumentClient {
60
68
  }
61
69
 
62
70
  delete (params, callback) {
63
- const docClient = DynamoDBDocument.from(new DynamoDB())
71
+ const docClient = DynamoDBDocument.from(ddb)
64
72
  docClient.delete(params, (err, response) => {
65
73
  if (err) {
66
74
  return callback(err)
@@ -109,7 +117,7 @@ class DocumentClient {
109
117
  }
110
118
 
111
119
  batchGet (params, callback) {
112
- const docClient = DynamoDBDocument.from(new DynamoDB())
120
+ const docClient = DynamoDBDocument.from(ddb)
113
121
 
114
122
  docClient.batchGet(params, function (err, data) {
115
123
  if (err) callback(err)
@@ -180,7 +188,6 @@ class DocumentClient {
180
188
  return resolve(null)
181
189
  }
182
190
  })
183
-
184
191
  }).then(result => {
185
192
  if (callback && typeof callback === 'function') {
186
193
  callback(null, result)
@@ -225,7 +232,7 @@ class DocumentClient {
225
232
 
226
233
  deleteAsync (params, callback) {
227
234
  return new Promise((resolve, reject) => {
228
- const docClient = DynamoDBDocument.from(new DynamoDB())
235
+ const docClient = DynamoDBDocument.from(ddb)
229
236
  docClient.delete(params, (err, response) => {
230
237
  if (err) {
231
238
  return resolve(err)
@@ -248,7 +255,7 @@ class DocumentClient {
248
255
 
249
256
  updateAsync (params, callback) {
250
257
  return new Promise((resolve, reject) => {
251
- const docClient = DynamoDBDocument.from(new DynamoDB())
258
+ const docClient = DynamoDBDocument.from(ddb)
252
259
  docClient.update(params, (err, response) => {
253
260
  if (err) {
254
261
  return resolve(err)
@@ -269,10 +276,9 @@ class DocumentClient {
269
276
  })
270
277
  }
271
278
 
272
-
273
279
  batchGetAsync (params, callback) {
274
280
  return new Promise((resolve, reject) => {
275
- const docClient = DynamoDBDocument.from(new DynamoDB())
281
+ const docClient = DynamoDBDocument.from(ddb)
276
282
  docClient.batchGet(params, function (err, response) {
277
283
  if (err) reject(err)
278
284
  else {
package/clients/lambda.js CHANGED
@@ -1,12 +1,19 @@
1
1
  const { LambdaClient, InvokeCommand, InvokeAsyncCommand } = require('@aws-sdk/client-lambda')
2
2
  const { toUtf8, fromUtf8 } = require('@aws-sdk/util-utf8-node')
3
3
 
4
+ const { Agent } = require('https')
5
+ const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
6
+
7
+ const keepAliveOptions = new NodeHttpHandler({
8
+ httpsAgent: new Agent({ keepAlive: false })
9
+ })
10
+
4
11
  class Lambda {
5
12
  constructor (region, session) {
6
13
  if (region && session) {
7
- this.client = new LambdaClient({ region, credentials: session })
14
+ this.client = new LambdaClient({ region, credentials: session, requestHandler: keepAliveOptions })
8
15
  } else {
9
- this.client = new LambdaClient()
16
+ this.client = new LambdaClient({ requestHandler: keepAliveOptions })
10
17
  }
11
18
  }
12
19
 
package/clients/s3.js CHANGED
@@ -1,6 +1,14 @@
1
1
  const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, UploadPartCommand } = require('@aws-sdk/client-s3')
2
2
  const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
3
- const client = new S3Client({})
3
+
4
+ const { Agent } = require('https')
5
+ const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
6
+
7
+ const client = new S3Client({
8
+ requestHandler: new NodeHttpHandler({
9
+ httpsAgent: new Agent({ keepAlive: false })
10
+ })
11
+ })
4
12
 
5
13
  class S3 {
6
14
  getSignedUrl (type, params, callback) {
package/clients/sns.js CHANGED
@@ -1,13 +1,21 @@
1
- const { SNSClient, PublishCommand } = require("@aws-sdk/client-sns");
2
- const snsClient = new SNSClient({});
1
+ const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns')
2
+
3
+ const { Agent } = require('https')
4
+ const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
5
+
6
+ const snsClient = new SNSClient({
7
+ requestHandler: new NodeHttpHandler({
8
+ httpsAgent: new Agent({ keepAlive: false })
9
+ })
10
+ })
3
11
 
4
12
  class SNS {
5
13
  publish (params, callback) {
6
14
  return new Promise((resolve, reject) => {
7
- let publishCommand = new PublishCommand(params)
8
- const response = snsClient.send(publishCommand).then(response=>{
15
+ const publishCommand = new PublishCommand(params)
16
+ snsClient.send(publishCommand).then(response => {
9
17
  resolve(response)
10
- }).catch(err=>{
18
+ }).catch(err => {
11
19
  reject(err)
12
20
  })
13
21
  }).then(result => {
package/clients/sqs.js CHANGED
@@ -1,24 +1,30 @@
1
- const { SQSClient, ReceiveMessageCommand, DeleteMessageCommand, SendMessageCommand } = require("@aws-sdk/client-sqs");
2
- const snsClient = new SQSClient();
1
+ const { SQSClient, ReceiveMessageCommand, DeleteMessageCommand, SendMessageCommand } = require('@aws-sdk/client-sqs')
3
2
 
3
+ const { Agent } = require('https')
4
+ const { NodeHttpHandler } = require('@aws-sdk/node-http-handler')
5
+
6
+ const sqsClient = new SQSClient({
7
+ requestHandler: new NodeHttpHandler({
8
+ httpsAgent: new Agent({ keepAlive: false })
9
+ })
10
+ })
4
11
  class SQS {
5
- async sendMessage (params, callback) {
6
- const command = new SendMessageCommand(params)
7
- const response = await snsClient.send(command)
8
- return response
12
+ async sendMessage (params, callback) {
13
+ const command = new SendMessageCommand(params)
14
+ const response = await sqsClient.send(command)
15
+ return response
9
16
  }
10
17
 
11
18
  async receiveMessage (params, callback) {
12
19
  const command = new ReceiveMessageCommand(params)
13
- const response = await snsClient.send(command)
20
+ const response = await sqsClient.send(command)
14
21
  return response
15
- }
16
-
22
+ }
17
23
 
18
- async deleteMessage (params, callback) {
19
- const command = new DeleteMessageCommand(params)
20
- const response = await snsClient.send(command)
21
- return response
24
+ async deleteMessage (params, callback) {
25
+ const command = new DeleteMessageCommand(params)
26
+ const response = await sqsClient.send(command)
27
+ return response
22
28
  }
23
29
  }
24
30
 
@@ -1,6 +1,7 @@
1
1
  const { Client, Connection } = require('@opensearch-project/opensearch')
2
2
  const { defaultProvider } = require('@aws-sdk/credential-provider-node')
3
3
  const aws4 = require('aws4')
4
+ const logger = require('../utils/logger')
4
5
 
5
6
  const { REGION, ELASTICSEARCH_AUDITS_ENDPOINT } = process.env
6
7
 
@@ -32,23 +33,28 @@ const getClient = async () => {
32
33
  }
33
34
 
34
35
  exports.sendAuditsReqToES = async (method, index, type, id, data) => {
35
- const client = await getClient()
36
- if (method === 'DELETE') {
37
- const response = await client.delete({
38
- index,
39
- type,
40
- id
41
- })
42
- return response.body
43
- } else {
44
- const response = await client.index({
45
- id,
46
- index,
47
- type,
48
- body: data,
49
- refresh: true
36
+ try {
37
+ const client = await getClient()
38
+ if (method === 'DELETE') {
39
+ const response = await client.delete({
40
+ index,
41
+ type,
42
+ id
43
+ })
44
+ return response.body
45
+ } else {
46
+ const response = await client.index({
47
+ id,
48
+ index,
49
+ type,
50
+ body: data,
51
+ refresh: true
50
52
 
51
- })
52
- return response.body
53
+ })
54
+ return response.body
55
+ }
56
+ } catch (error) {
57
+ logger.error('ES Error', { error })
58
+ return error
53
59
  }
54
60
  }
@@ -1,6 +1,7 @@
1
1
  const { Client, Connection } = require('@opensearch-project/opensearch')
2
2
  const { defaultProvider } = require('@aws-sdk/credential-provider-node')
3
3
  const aws4 = require('aws4')
4
+ const logger = require('../utils/logger')
4
5
 
5
6
  const { REGION, ELASTICSEARCH_ENDPOINT } = process.env
6
7
 
@@ -61,6 +62,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
61
62
  return response.body
62
63
  }
63
64
  } catch (error) {
65
+ logger.error('ES Error', { error })
64
66
  return error
65
67
  }
66
68
  }
@@ -1,6 +1,7 @@
1
1
  const { Client, Connection } = require('@opensearch-project/opensearch')
2
2
  const { defaultProvider } = require('@aws-sdk/credential-provider-node')
3
3
  const aws4 = require('aws4')
4
+ const logger = require('../utils/logger')
4
5
 
5
6
  const { REGION, ELASTICSEARCH_ENDPOINT } = process.env
6
7
  const host = 'https://' + ELASTICSEARCH_ENDPOINT
@@ -33,25 +34,41 @@ const getClient = async () => {
33
34
  exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
34
35
  const client = await getClient()
35
36
  return new Promise((resolve, reject) => {
36
- let body = { query }
37
+ const body = {}
38
+ if (query) {
39
+ body.query = query
40
+ }
37
41
  if (sort) {
38
- body = { query, sort }
42
+ body.sort = sort
39
43
  }
40
- client.search({
44
+ const options = {
41
45
  index,
42
- from,
43
- size,
44
- _source,
45
46
  body
46
- }).then(response => {
47
+ }
48
+ if (from) {
49
+ options.from = from
50
+ }
51
+ if (size) {
52
+ options.size = size
53
+ }
54
+ if (_source) {
55
+ options._source = size
56
+ }
57
+ client.search(options).then(response => {
58
+ logger.debug(response, { response })
47
59
  const data = response.body.hits.hits
48
60
  const totalCount = response.body.hits.total
49
61
  const mappedData = data.map(item => {
50
62
  return item._source
51
63
  })
52
64
  resolve({ items: mappedData, data: mappedData, totalCount })
53
- }).catch(e => {
54
- resolve({ items: [], data: [], totalCount: 0 })
65
+ }).catch(err => {
66
+ if (err) {
67
+ logger.error('ES sendGetRequest Error', { err })
68
+ reject(err)
69
+ } else {
70
+ resolve({ items: [], data: [], totalCount: 0 })
71
+ }
55
72
  })
56
73
  })
57
74
  }
@@ -59,24 +76,37 @@ exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
59
76
  exports.sendGetRequestCallback = async (index, query, from, size, sort, callback) => {
60
77
  const client = await getClient()
61
78
  return new Promise((resolve, reject) => {
62
- let body = { query }
79
+ const body = {}
80
+ if (query) {
81
+ body.query = query
82
+ }
63
83
  if (sort) {
64
- body = { query, sort }
84
+ body.sort = sort
65
85
  }
66
- client.search({
86
+ const options = {
67
87
  index,
68
- from,
69
- size,
70
88
  body
71
- }).then(response => {
89
+ }
90
+ if (from) {
91
+ options.from = from
92
+ }
93
+ if (size) {
94
+ options.size = size
95
+ }
96
+ client.search(options).then(response => {
72
97
  const data = response.body.hits.hits
73
98
  const totalCount = response.body.hits.total
74
99
  const mappedData = data.map(item => {
75
100
  return item._source
76
101
  })
77
102
  callback(null, { items: mappedData, data: mappedData, totalCount })
78
- }).catch(e => {
79
- callback(null, { items: [], data: [], totalCount: 0 })
103
+ }).catch(err => {
104
+ if (err) {
105
+ logger.error('ES Error', { err })
106
+ reject(err)
107
+ } else {
108
+ resolve({ items: [], data: [], totalCount: 0 })
109
+ }
80
110
  })
81
111
  })
82
112
  }
@@ -90,9 +120,13 @@ exports.getCount = async (index, query) => {
90
120
  }).then(response => {
91
121
  const data = response.body
92
122
  resolve({ data })
93
- }).catch(e => {
94
- console.log(e);
95
- resolve({ })
123
+ }).catch(err => {
124
+ if (err) {
125
+ logger.error('ES Error', { err })
126
+ reject(err)
127
+ } else {
128
+ resolve({ items: [], data: [], totalCount: 0 })
129
+ }
96
130
  })
97
131
  })
98
132
  }
@@ -100,17 +134,18 @@ exports.getCount = async (index, query) => {
100
134
  exports.multiSearch = async (query) => {
101
135
  const client = await getClient()
102
136
  return new Promise((resolve, reject) => {
103
- let body = query
137
+ const body = query
104
138
  client.msearch({
105
139
  body
106
140
  }).then(response => {
107
- resolve(response);
108
- }).catch(e => {
109
- console.log(e);
110
- resolve({ items: [], data: [], totalCount: 0 })
141
+ resolve(response)
142
+ }).catch(err => {
143
+ if (err) {
144
+ logger.error('ES Error', { err })
145
+ reject(err)
146
+ } else {
147
+ resolve({ items: [], data: [], totalCount: 0 })
148
+ }
111
149
  })
112
150
  })
113
151
  }
114
-
115
-
116
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-v3-sdk",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
4
4
  "description": "AWS v3 SDK Utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,16 @@
1
+ const winston = require('winston')
2
+
3
+ const level = process.env.LOG_LEVEL || 'debug'
4
+ const logger = winston.createLogger({
5
+ level,
6
+ transports: [
7
+ new winston.transports.Console({
8
+ level,
9
+ timestamp: function () {
10
+ return (new Date()).toISOString()
11
+ }
12
+ })
13
+ ]
14
+ })
15
+
16
+ module.exports = logger