aws-v3-sdk 1.0.6 → 1.0.8

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,4 +1,4 @@
1
- const { DynamoDB, DynamoDBClient, BatchGetItemCommand } = require('@aws-sdk/client-dynamodb')
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
3
  const ddb = new DynamoDBClient()
4
4
  const documentClient = DynamoDBDocumentClient.from(ddb)
@@ -43,6 +43,13 @@ class DocumentClient {
43
43
  }
44
44
 
45
45
  put (params, callback) {
46
+ let item = params.Item
47
+ try {
48
+ item = Object.fromEntries(Object.entries(item).filter(([key, value]) => value !== undefined))
49
+ } catch (error) {
50
+
51
+ }
52
+ params.Item = item
46
53
  const putCommand = new PutCommand(params)
47
54
  documentClient.send(putCommand, (err, response) => {
48
55
  if (err || !response) {
@@ -53,6 +60,17 @@ class DocumentClient {
53
60
  }
54
61
 
55
62
  delete (params, callback) {
63
+ const docClient = DynamoDBDocument.from(new DynamoDB())
64
+ docClient.delete(params, (err, response) => {
65
+ if (err) {
66
+ return callback(err)
67
+ } else {
68
+ return callback(null, response)
69
+ }
70
+ })
71
+ }
72
+
73
+ deletev3 (params, callback) {
56
74
  const putCommand = new DeleteCommand(params)
57
75
  documentClient.send(putCommand, (err, response) => {
58
76
  if (err) {
package/clients/lambda.js CHANGED
@@ -11,11 +11,6 @@ class Lambda {
11
11
  }
12
12
 
13
13
  async invoke (params, callback) {
14
- if (params.Payload) {
15
- params.InvokeArgs = fromUtf8(params.Payload)
16
- delete params.Payload
17
- }
18
-
19
14
  const command = new InvokeCommand(params)
20
15
  this.client.send(command).then(response => {
21
16
  response.Payload = toUtf8(response.Payload)
package/clients/s3.js CHANGED
@@ -1,8 +1,84 @@
1
- const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand } = require('@aws-sdk/client-s3')
1
+ const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand } = require('@aws-sdk/client-s3')
2
2
  const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
3
3
  const client = new S3Client({})
4
4
 
5
5
  class S3 {
6
+ getSignedUrl (type, params, callback) {
7
+ return new Promise((resolve, reject) => {
8
+ if (type === 'getObject') {
9
+ const Expires = params.Expires
10
+ delete params.Expires
11
+ const command = new GetObjectCommand(params)
12
+ getSignedUrl(client, command, { expiresIn: Expires }).then(url => {
13
+ resolve(url)
14
+ }).catch(err => {
15
+ resolve(err)
16
+ })
17
+ } else if (type === 'putObject') {
18
+ const Expires = params.Expires
19
+ delete params.Expires
20
+ const command = new PutObjectCommand(params)
21
+ getSignedUrl(client, command, { expiresIn: Expires }).then(url => {
22
+ resolve(url)
23
+ }).catch(err => {
24
+ resolve(err)
25
+ })
26
+ }
27
+ }).then(result => {
28
+ if (callback && typeof callback === 'function') {
29
+ callback(null, result)
30
+ }
31
+ return result
32
+ }).catch(error => {
33
+ if (callback && typeof callback === 'function') {
34
+ callback(error, null)
35
+ }
36
+ return Promise.reject(error)
37
+ })
38
+ }
39
+
40
+ createMultipartUpload (type, params, callback) {
41
+ return new Promise((resolve, reject) => {
42
+ const command = new CreateMultipartUploadCommand(params)
43
+ client.send(command).then(response => {
44
+ resolve(response)
45
+ }).catch(err => {
46
+ resolve(err)
47
+ })
48
+ }).then(result => {
49
+ if (callback && typeof callback === 'function') {
50
+ callback(null, result)
51
+ }
52
+ return result
53
+ }).catch(error => {
54
+ if (callback && typeof callback === 'function') {
55
+ callback(error, null)
56
+ }
57
+ return Promise.reject(error)
58
+ })
59
+ }
60
+
61
+ completeMultipartUpload (type, params, callback) {
62
+ return new Promise((resolve, reject) => {
63
+ const command = new CompleteMultipartUploadCommand(params)
64
+ client.send(command).then(response => {
65
+ resolve(response)
66
+ }).catch(err => {
67
+ resolve(err)
68
+ })
69
+ }).then(result => {
70
+ if (callback && typeof callback === 'function') {
71
+ callback(null, result)
72
+ }
73
+ return result
74
+ }).catch(error => {
75
+ if (callback && typeof callback === 'function') {
76
+ callback(error, null)
77
+ }
78
+ return Promise.reject(error)
79
+ })
80
+ }
81
+
6
82
  getObject (params, callback) {
7
83
  return new Promise((resolve, reject) => {
8
84
  const getObject = new GetObjectCommand(params)
@@ -30,6 +106,30 @@ class S3 {
30
106
  return Promise.reject(error)
31
107
  })
32
108
  }
109
+
110
+ putObject (params, callback) {
111
+ return new Promise((resolve, reject) => {
112
+ const putObject = new PutObjectCommand(params)
113
+ client.send(putObject, (err, data) => {
114
+ if (err || !data) {
115
+ resolve(err)
116
+ }
117
+ if (data) {
118
+ resolve(data)
119
+ }
120
+ })
121
+ }).then(result => {
122
+ if (callback && typeof callback === 'function') {
123
+ callback(null, result)
124
+ }
125
+ return result
126
+ }).catch(error => {
127
+ if (callback && typeof callback === 'function') {
128
+ callback(error, null)
129
+ }
130
+ return Promise.reject(error)
131
+ })
132
+ }
33
133
  }
34
134
 
35
135
  module.exports = S3
@@ -0,0 +1,53 @@
1
+ const { Client, Connection } = require('@opensearch-project/opensearch')
2
+ const { defaultProvider } = require('@aws-sdk/credential-provider-node')
3
+ const aws4 = require('aws4')
4
+
5
+ const { AWS_REGION, ELASTICSEARCH_AUDITS_ENDPOINT } = process.env
6
+
7
+ const host = 'https://' + ELASTICSEARCH_AUDITS_ENDPOINT
8
+
9
+ const createAwsConnector = (credentials, region) => {
10
+ class AmazonConnection extends Connection {
11
+ buildRequestObject (params) {
12
+ const request = super.buildRequestObject(params)
13
+ request.service = 'es'
14
+ request.region = region
15
+ request.headers = request.headers || {}
16
+ request.headers.host = request.hostname
17
+ return aws4.sign(request, credentials)
18
+ }
19
+ }
20
+ return {
21
+ Connection: AmazonConnection
22
+ }
23
+ }
24
+
25
+ const getClient = async () => {
26
+ const credentials = await defaultProvider()()
27
+ const cred = createAwsConnector(credentials, AWS_REGION)
28
+ return new Client({
29
+ ...cred,
30
+ node: host
31
+ })
32
+ }
33
+
34
+ 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
+ body: data,
48
+ refresh: true
49
+
50
+ })
51
+ return response.body
52
+ }
53
+ }
@@ -0,0 +1,53 @@
1
+ const { Client, Connection } = require('@opensearch-project/opensearch')
2
+ const { defaultProvider } = require('@aws-sdk/credential-provider-node')
3
+ const aws4 = require('aws4')
4
+
5
+ const { AWS_REGION, ELASTICSEARCH_ENDPOINT } = process.env
6
+
7
+ const host = 'https://' + ELASTICSEARCH_ENDPOINT
8
+
9
+ const createAwsConnector = (credentials, region) => {
10
+ class AmazonConnection extends Connection {
11
+ buildRequestObject (params) {
12
+ const request = super.buildRequestObject(params)
13
+ request.service = 'es'
14
+ request.region = region
15
+ request.headers = request.headers || {}
16
+ request.headers.host = request.hostname
17
+ return aws4.sign(request, credentials)
18
+ }
19
+ }
20
+ return {
21
+ Connection: AmazonConnection
22
+ }
23
+ }
24
+
25
+ const getClient = async () => {
26
+ const credentials = await defaultProvider()()
27
+ const cred = createAwsConnector(credentials, AWS_REGION)
28
+ return new Client({
29
+ ...cred,
30
+ node: host
31
+ })
32
+ }
33
+
34
+ exports.sendReqToES = 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
+ body: data,
48
+ refresh: true
49
+
50
+ })
51
+ return response.body
52
+ }
53
+ }
@@ -0,0 +1,9 @@
1
+ const { sendGetRequest } = require('./sendGetRequest')
2
+ const { sendAuditsReqToES } = require('./es-audits-wrapper')
3
+ const { sendReqToES } = require('./es-wrapper')
4
+
5
+ module.exports = {
6
+ sendGetRequest,
7
+ sendReqToES,
8
+ sendAuditsReqToES
9
+ }
@@ -0,0 +1,50 @@
1
+ const { Client, Connection } = require('@opensearch-project/opensearch')
2
+ const { defaultProvider } = require('@aws-sdk/credential-provider-node')
3
+ const aws4 = require('aws4')
4
+
5
+ const { AWS_REGION, ELASTICSEARCH_ENDPOINT } = process.env
6
+ const host = 'https://' + ELASTICSEARCH_ENDPOINT
7
+
8
+ const createAwsConnector = (credentials, region) => {
9
+ class AmazonConnection extends Connection {
10
+ buildRequestObject (params) {
11
+ const request = super.buildRequestObject(params)
12
+ request.service = 'es'
13
+ request.region = region
14
+ request.headers = request.headers || {}
15
+ request.headers.host = request.hostname
16
+ return aws4.sign(request, credentials)
17
+ }
18
+ }
19
+ return {
20
+ Connection: AmazonConnection
21
+ }
22
+ }
23
+
24
+ const getClient = async () => {
25
+ const credentials = await defaultProvider()()
26
+ const cred = createAwsConnector(credentials, AWS_REGION)
27
+ return new Client({
28
+ ...cred,
29
+ node: host
30
+ })
31
+ }
32
+
33
+ exports.sendGetRequest = async (index, query, from, size, sort) => {
34
+ const client = await getClient()
35
+ return new Promise((resolve, reject) => {
36
+ client.search({
37
+ index,
38
+ body: { query }
39
+ }).then(response => {
40
+ const data = response.body.hits.hits
41
+ const totalCount = response.body.hits.total
42
+ const mappedData = data.map(item => {
43
+ return item._source
44
+ })
45
+ resolve({ items: mappedData, data: mappedData, totalCount })
46
+ }).catch(e => {
47
+ resolve({ items: [], data: [], totalCount: 0 })
48
+ })
49
+ })
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-v3-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "AWS v3 SDK Utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,5 +11,8 @@
11
11
  "url": "git@tomymathew:tomymathew/aws-v3-sdk.git"
12
12
  },
13
13
  "author": "tomy mathew",
14
- "license": "ISC"
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "@opensearch-project/opensearch": "^2.3.1"
17
+ }
15
18
  }