aws-v3-sdk 1.0.33 → 1.0.40

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,2 +1,138 @@
1
- # aws-v3-sdk
2
- AWS JS SDK UTILS
1
+ # AWS SDK for JavaScript
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/aws-v3-sdk.svg)](https://www.npmjs.com/package/aws-v3-sdk)
4
+ [![NPM downloads](https://img.shields.io/npm/dm/aws-v3-sdk.svg)](https://www.npmjs.com/package/aws-v3-sdk)
5
+
6
+
7
+ ## Version 1.0.40
8
+
9
+ This package can be used to migrate to AWS SDK v3 from AWS SDK v2 without much change in exisint codebase.
10
+ This package takes the exisint AWS SDK v2 format and convert it to the AWS SDK v3 format.
11
+
12
+
13
+ AWS SDK V2
14
+ ```js
15
+ const AWS = require('aws-sdk')
16
+ const docClient = new AWS.DynamoDB.DocumentClient()
17
+ let params = {
18
+ TableName: TABLE_NAME,
19
+ Key: {
20
+ 'id': ID
21
+ }
22
+ }
23
+ docClient.get(params, function (err, data) {
24
+ console.log(data.Item)
25
+ })
26
+ ```
27
+ AWS SDK V3
28
+ ```js
29
+ const AWS = require('aws-v3-sdk')
30
+ const docClient = new AWS.DynamoDB.DocumentClient()
31
+ let params = {
32
+ TableName: TABLE_NAME,
33
+ Key: {
34
+ 'id': ID
35
+ }
36
+ }
37
+ docClient.get(params, function (err, data) {
38
+ console.log(data.Item)
39
+ })
40
+ ```
41
+
42
+ ## Table of Contents:
43
+ * [Supported Function](#supported-function)
44
+ * [Getting Started](#getting-Started)
45
+ * [Getting Help](#getting-help)
46
+ * [Contributing](#contributing)
47
+
48
+
49
+ ## Supported Functions
50
+
51
+ 1. Dynamo DB
52
+ 2. Lambda
53
+ 3. OpenSearch
54
+ 4. Cognito
55
+ 5. S3
56
+ 6. SNS
57
+ 7. SQS
58
+ 8. STS
59
+ 9. Cognito
60
+
61
+ ## Getting Started
62
+
63
+ ## How To Install
64
+
65
+ ### In Node.js
66
+
67
+ The preferred way to install the AWS SDK for Node.js is to use the
68
+ [npm](http://npmjs.org) package manager for Node.js. Simply type the following
69
+ into a terminal window:
70
+
71
+ ```sh
72
+ npm install aws-v3-sdk
73
+ ```
74
+
75
+ Then within your application, you can reference the react native compatible version of the SDK with the following:
76
+ We can use the old SDK format without migrating the code base. Just update the AWS import.
77
+
78
+ ```javascript
79
+ const AWS = require('aws-v3-sdk')
80
+
81
+ const s3 = new AWS.S3()
82
+
83
+ const params = {
84
+ Bucket: <BUCKET NAME>,
85
+ Key: <FILE KEY>,
86
+ Body: <STRING DATA,
87
+ ContentType: 'text/json'
88
+
89
+ }
90
+
91
+ s3.putObject(params, (err, data) => {
92
+ if (err) {
93
+ < DO Stuff HERE >
94
+ } else {
95
+ < DO Stuff HERE >
96
+ }
97
+ })
98
+ ```
99
+
100
+
101
+
102
+ ### Supported Functions
103
+
104
+ **Dynamo DB**
105
+ get
106
+ query
107
+ scan
108
+ put
109
+ delete
110
+ update
111
+ batchWrite
112
+ transactWrite
113
+ batchGet
114
+
115
+ S3
116
+ getSignedUrl
117
+ getObject
118
+ putObject
119
+ headObject
120
+ createMultipartUpload
121
+ completeMultipartUpload
122
+
123
+
124
+
125
+ ### Known Limitations
126
+ There are a few known limitations.
127
+
128
+ * This package has not been updated to handle all the AWS SDK APIs.
129
+
130
+
131
+ # Contributing
132
+ We welcome community contributions and pull requests. See [CONTRIBUTING.md](https://github.com/aws/aws-sdk-js/blob/master/CONTRIBUTING.md) for information on how to set up a development environment and submit code.
133
+
134
+ ## License
135
+
136
+ This SDK is distributed under the
137
+ [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0),
138
+ see LICENSE.txt and NOTICE.txt for more information.
package/clients/all.js CHANGED
@@ -3,7 +3,6 @@ module.exports = {
3
3
  DynamoDB: require('./dynamoDB'),
4
4
  EnvironmentCredentials: require('./credential'),
5
5
  S3: require('./s3'),
6
- S3R: require('./s3R'),
7
6
  STS: require('./sts'),
8
7
  SQS: require('./sqs'),
9
8
  SNS: require('./sns'),
@@ -1,130 +1,133 @@
1
- const { DynamoDB, DynamoDBClient } = require('@aws-sdk/client-dynamodb')
2
- const { DynamoDBDocument, DynamoDBDocumentClient, GetCommand, BatchWriteCommand, PutCommand, QueryCommand, ScanCommand, DeleteCommand } = require('@aws-sdk/lib-dynamodb')
1
+ const { DynamoDBClient } = require('@aws-sdk/client-dynamodb')
2
+ const {
3
+ DynamoDBDocumentClient,
4
+ GetCommand,
5
+ PutCommand,
6
+ QueryCommand,
7
+ ScanCommand,
8
+ DeleteCommand,
9
+ UpdateCommand,
10
+ BatchGetCommand,
11
+ TransactWriteCommand,
12
+ BatchWriteCommand
13
+ } = require('@aws-sdk/lib-dynamodb')
14
+
3
15
  const ddb = new DynamoDBClient()
4
16
  const documentClient = DynamoDBDocumentClient.from(ddb)
5
17
 
6
18
  class DocumentClientAsync {
7
- get (params, callback) {
8
- return new Promise((resolve, reject) => {
9
- const getCommand = new GetCommand(params)
10
- documentClient.send(getCommand, (err, response) => {
11
- if (err || !response) {
12
- return reject(err)
13
- }
14
- if (response.Item) {
15
- return resolve(response)
16
- } else if (!response.Item) {
17
- return resolve({})
18
- }
19
- })
20
- }).then(result => {
21
- if (callback && typeof callback === 'function') {
22
- callback(null, result)
23
- }
19
+ async get (params, callback) {
20
+ try {
21
+ const command = new GetCommand(params)
22
+ const result = await documentClient.send(command)
23
+ const response = result?.Item ? result : {}
24
+ if (typeof callback === 'function') callback(null, response)
25
+ return response
26
+ } catch (error) {
27
+ if (typeof callback === 'function') callback(error, null)
28
+ throw error
29
+ }
30
+ }
31
+
32
+ async query (params, callback) {
33
+ try {
34
+ const command = new QueryCommand(params)
35
+ const result = await documentClient.send(command)
36
+ if (typeof callback === 'function') callback(null, result)
24
37
  return result
25
- }).catch(error => {
26
- if (callback && typeof callback === 'function') {
27
- callback(error, null)
28
- }
29
- return Promise.reject(error)
30
- })
38
+ } catch (error) {
39
+ if (typeof callback === 'function') callback(error, null)
40
+ throw error
41
+ }
31
42
  }
32
43
 
33
- query (params, callback) {
34
- return new Promise((resolve, reject) => {
35
- const getCommand = new QueryCommand(params)
36
- documentClient.send(getCommand, (err, response) => {
37
- if (err || !response) {
38
- return resolve(err)
39
- }
40
- return resolve(response)
41
- })
42
- }).then(result => {
43
- if (callback && typeof callback === 'function') {
44
- callback(null, result)
45
- }
44
+ async scan (params, callback) {
45
+ try {
46
+ const command = new ScanCommand(params)
47
+ const result = await documentClient.send(command)
48
+ if (typeof callback === 'function') callback(null, result)
46
49
  return result
47
- }).catch(error => {
48
- if (callback && typeof callback === 'function') {
49
- callback(error, null)
50
+ } catch (error) {
51
+ if (typeof callback === 'function') callback(error, null)
52
+ throw error
53
+ }
54
+ }
55
+
56
+ async put (params, callback) {
57
+ try {
58
+ if (params?.Item) {
59
+ params.Item = Object.fromEntries(
60
+ Object.entries(params.Item).filter(([, v]) => v !== undefined)
61
+ )
50
62
  }
51
- return Promise.reject(error)
52
- })
63
+ const command = new PutCommand(params)
64
+ const result = await documentClient.send(command)
65
+ if (typeof callback === 'function') callback(null, result)
66
+ return result
67
+ } catch (error) {
68
+ if (typeof callback === 'function') callback(error, null)
69
+ throw error
70
+ }
53
71
  }
54
72
 
55
- put (params, callback) {
56
- return new Promise((resolve, reject) => {
57
- let item = params.Item
58
- try {
59
- item = Object.fromEntries(Object.entries(item).filter(([key, value]) => value !== undefined))
60
- } catch (error) {
73
+ async delete (params, callback) {
74
+ try {
75
+ const command = new DeleteCommand(params)
76
+ const result = await documentClient.send(command)
77
+ if (typeof callback === 'function') callback(null, result)
78
+ return result
79
+ } catch (error) {
80
+ if (typeof callback === 'function') callback(error, null)
81
+ throw error
82
+ }
83
+ }
61
84
 
62
- }
63
- params.Item = item
64
- const putCommand = new PutCommand(params)
65
- documentClient.send(putCommand, (err, response) => {
66
- if (err || !response) {
67
- return resolve(err)
68
- }
69
- return resolve(response)
70
- })
71
- }).then(result => {
72
- if (callback && typeof callback === 'function') {
73
- callback(null, result)
74
- }
85
+ async update (params, callback) {
86
+ try {
87
+ const command = new UpdateCommand(params)
88
+ const result = await documentClient.send(command)
89
+ if (typeof callback === 'function') callback(null, result)
75
90
  return result
76
- }).catch(error => {
77
- if (callback && typeof callback === 'function') {
78
- callback(error, null)
79
- }
80
- return Promise.reject(error)
81
- })
91
+ } catch (error) {
92
+ if (typeof callback === 'function') callback(error, null)
93
+ throw error
94
+ }
82
95
  }
83
96
 
84
- delete (params, callback) {
85
- return new Promise((resolve, reject) => {
86
- const docClient = DynamoDBDocument.from(new DynamoDB())
87
- docClient.delete(params, (err, response) => {
88
- if (err) {
89
- return resolve(err)
90
- } else {
91
- return resolve(response)
92
- }
93
- })
94
- }).then(result => {
95
- if (callback && typeof callback === 'function') {
96
- callback(null, result)
97
- }
97
+ async batchGet (params, callback) {
98
+ try {
99
+ const command = new BatchGetCommand(params)
100
+ const result = await documentClient.send(command)
101
+ if (typeof callback === 'function') callback(null, result)
98
102
  return result
99
- }).catch(error => {
100
- if (callback && typeof callback === 'function') {
101
- callback(error, null)
102
- }
103
- return Promise.reject(error)
104
- })
103
+ } catch (error) {
104
+ if (typeof callback === 'function') callback(error, null)
105
+ throw error
106
+ }
105
107
  }
106
108
 
107
- update (params, callback) {
108
- return new Promise((resolve, reject) => {
109
- const docClient = DynamoDBDocument.from(new DynamoDB())
110
- docClient.update(params, (err, response) => {
111
- if (err) {
112
- return resolve(err)
113
- } else {
114
- return resolve(response)
115
- }
116
- })
117
- }).then(result => {
118
- if (callback && typeof callback === 'function') {
119
- callback(null, result)
120
- }
109
+ async batchWrite (params, callback) {
110
+ try {
111
+ const command = new BatchWriteCommand(params)
112
+ const result = await documentClient.send(command)
113
+ if (typeof callback === 'function') callback(null, result)
121
114
  return result
122
- }).catch(error => {
123
- if (callback && typeof callback === 'function') {
124
- callback(error, null)
125
- }
126
- return Promise.reject(error)
127
- })
115
+ } catch (error) {
116
+ if (typeof callback === 'function') callback(error, null)
117
+ throw error
118
+ }
119
+ }
120
+
121
+ async transactWrite (params, callback) {
122
+ try {
123
+ const command = new TransactWriteCommand(params)
124
+ const result = await documentClient.send(command)
125
+ if (typeof callback === 'function') callback(null, result)
126
+ return result
127
+ } catch (error) {
128
+ if (typeof callback === 'function') callback(error, null)
129
+ throw error
130
+ }
128
131
  }
129
132
  }
130
133
 
package/clients/lambda.js CHANGED
@@ -21,35 +21,29 @@ class Lambda {
21
21
  }
22
22
 
23
23
  async invoke (params, callback) {
24
- const command = new InvokeCommand(params)
25
- this.client.send(command).then(response => {
26
- response.Payload = toUtf8(response.Payload)
27
- callback(null, response)
28
- }).catch(err => {
29
- callback(err)
30
- })
24
+ try {
25
+ const command = new InvokeCommand(params)
26
+ const result = await this.client.send(command)
27
+ result.Payload = toUtf8(result.Payload)
28
+ if (typeof callback === 'function') callback(null, result)
29
+ return result
30
+ } catch (error) {
31
+ if (typeof callback === 'function') callback(error, null)
32
+ throw error
33
+ }
31
34
  }
32
35
 
33
- invokeAsync (params, callback) {
34
- return new Promise((resolve, reject) => {
36
+ async invokeAsync (params, callback) {
37
+ try {
35
38
  const command = new InvokeCommand(params)
36
- this.client.send(command).then(response => {
37
- response.Payload = toUtf8(response.Payload)
38
- resolve(response)
39
- }).catch(err => {
40
- resolve(err)
41
- })
42
- }).then(result => {
43
- if (callback && typeof callback === 'function') {
44
- callback(null, result)
45
- }
39
+ const result = await this.client.send(command)
40
+ result.Payload = toUtf8(result.Payload)
41
+ if (typeof callback === 'function') callback(null, result)
46
42
  return result
47
- }).catch(error => {
48
- if (callback && typeof callback === 'function') {
49
- callback(error, null)
50
- }
51
- return Promise.reject(error)
52
- })
43
+ } catch (error) {
44
+ if (typeof callback === 'function') callback(error, null)
45
+ throw error
46
+ }
53
47
  }
54
48
  }
55
49
 
package/clients/s3.js CHANGED
@@ -1,4 +1,4 @@
1
- const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, UploadPartCommand } = require('@aws-sdk/client-s3')
1
+ const { S3Client, GetObjectCommand, PutObjectCommand, HeadObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, UploadPartCommand } = require('@aws-sdk/client-s3')
2
2
  const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
3
3
 
4
4
  const { Agent } = require('https')
@@ -147,6 +147,30 @@ class S3 {
147
147
  return Promise.reject(error)
148
148
  })
149
149
  }
150
+
151
+ headObject (params, callback) {
152
+ return new Promise((resolve, reject) => {
153
+ const headObject = new HeadObjectCommand(params)
154
+ client.send(headObject, (err, data) => {
155
+ if (err || !data) {
156
+ resolve(err)
157
+ }
158
+ if (data) {
159
+ resolve(data)
160
+ }
161
+ })
162
+ }).then(result => {
163
+ if (callback && typeof callback === 'function') {
164
+ callback(null, result)
165
+ }
166
+ return result
167
+ }).catch(error => {
168
+ if (callback && typeof callback === 'function') {
169
+ callback(error, null)
170
+ }
171
+ return Promise.reject(error)
172
+ })
173
+ }
150
174
  }
151
175
 
152
176
  module.exports = S3
@@ -48,7 +48,7 @@ exports.sendAuditsReqToES = async (method, index, type, id, data) => {
48
48
  index,
49
49
  type,
50
50
  body: data,
51
- refresh: false
51
+ refresh: true
52
52
 
53
53
  })
54
54
  return response.body
@@ -28,8 +28,7 @@ const getClient = async () => {
28
28
  const cred = createAwsConnector(credentials, REGION)
29
29
  return new Client({
30
30
  ...cred,
31
- node: host,
32
- maxRetries: 0
31
+ node: host
33
32
  })
34
33
  }
35
34
 
@@ -40,8 +39,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
40
39
  const response = await client.delete({
41
40
  index,
42
41
  type,
43
- id,
44
- refresh: false
42
+ id
45
43
  })
46
44
  return response.body
47
45
  } else if (method === 'UPDATE') {
@@ -50,17 +48,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
50
48
  index,
51
49
  type,
52
50
  body: data,
53
- refresh: false,
54
- retry_on_conflict: 10
55
- })
56
- return response.body
57
- } else if (method === 'UPDATE_BY_QUERY') {
58
- const response = await client.updateByQuery({
59
- index,
60
- type,
61
- body: data,
62
- refresh: false,
63
- retry_on_conflict: 10
51
+ refresh: true
64
52
  })
65
53
  return response.body
66
54
  } else {
@@ -69,7 +57,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
69
57
  index,
70
58
  type,
71
59
  body: data,
72
- refresh: false
60
+ refresh: true
73
61
  })
74
62
  return response.body
75
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-v3-sdk",
3
- "version": "1.0.33",
3
+ "version": "1.0.40",
4
4
  "description": "AWS v3 SDK Utils",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/clients/s3R.js DELETED
@@ -1,170 +0,0 @@
1
- const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand, CreateMultipartUploadCommand, CompleteMultipartUploadCommand, UploadPartCommand, ListObjectsV2Command } = require('@aws-sdk/client-s3')
2
- const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
3
- class S3R {
4
- constructor (params) {
5
- this.client = new S3Client(params)
6
- }
7
-
8
- getSignedUrl (type, params, callback) {
9
- return new Promise((resolve, reject) => {
10
- if (type === 'getObject') {
11
- const Expires = params.Expires
12
- delete params.Expires
13
- const command = new GetObjectCommand(params)
14
- getSignedUrl(this.client, command, { expiresIn: Expires }).then(url => {
15
- resolve(url)
16
- }).catch(err => {
17
- resolve(err)
18
- })
19
- } else if (type === 'putObject') {
20
- const Expires = params.Expires
21
- delete params.Expires
22
- const command = new PutObjectCommand(params)
23
- getSignedUrl(this.client, command, { expiresIn: Expires }).then(url => {
24
- resolve(url)
25
- }).catch(err => {
26
- resolve(err)
27
- })
28
- } else if (type === 'uploadPart') {
29
- const Expires = params.Expires
30
- delete params.Expires
31
- const command = new UploadPartCommand(params)
32
- getSignedUrl(this.client, command, { expiresIn: Expires }).then(url => {
33
- resolve(url)
34
- }).catch(err => {
35
- resolve(err)
36
- })
37
- }
38
- }).then(result => {
39
- if (callback && typeof callback === 'function') {
40
- callback(null, result)
41
- }
42
- return result
43
- }).catch(error => {
44
- if (callback && typeof callback === 'function') {
45
- callback(error, null)
46
- }
47
- return Promise.reject(error)
48
- })
49
- }
50
-
51
- createMultipartUpload (params, callback) {
52
- return new Promise((resolve, reject) => {
53
- const command = new CreateMultipartUploadCommand(params)
54
- this.client.send(command).then(response => {
55
- resolve(response)
56
- }).catch(err => {
57
- reject(err)
58
- })
59
- }).then(result => {
60
- if (callback && typeof callback === 'function') {
61
- callback(null, result)
62
- }
63
- return result
64
- }).catch(error => {
65
- if (callback && typeof callback === 'function') {
66
- callback(error, null)
67
- }
68
- return Promise.reject(error)
69
- })
70
- }
71
-
72
- completeMultipartUpload (params, callback) {
73
- return new Promise((resolve, reject) => {
74
- const command = new CompleteMultipartUploadCommand(params)
75
- this.client.send(command).then(response => {
76
- resolve(response)
77
- }).catch(err => {
78
- resolve(err)
79
- })
80
- }).then(result => {
81
- if (callback && typeof callback === 'function') {
82
- callback(null, result)
83
- }
84
- return result
85
- }).catch(error => {
86
- if (callback && typeof callback === 'function') {
87
- callback(error, null)
88
- }
89
- return Promise.reject(error)
90
- })
91
- }
92
-
93
- getObject (params, callback) {
94
- return new Promise((resolve, reject) => {
95
- const getObject = new GetObjectCommand(params)
96
- this.client.send(getObject).then(response => {
97
- const chunks = []
98
- const stream = response.Body
99
- stream.on('data', chunk => chunks.push(chunk))
100
- stream.on('end', () => {
101
- const imageBuffer = Buffer.concat(chunks)
102
- response.Body = imageBuffer
103
- resolve(response)
104
- })
105
- }).catch(err => {
106
- resolve(err)
107
- })
108
- }).then(result => {
109
- if (callback && typeof callback === 'function') {
110
- callback(null, result)
111
- }
112
- return result
113
- }).catch(error => {
114
- if (callback && typeof callback === 'function') {
115
- callback(error, null)
116
- }
117
- return Promise.reject(error)
118
- })
119
- }
120
-
121
- putObject (params, callback) {
122
- return new Promise((resolve, reject) => {
123
- const putObject = new PutObjectCommand(params)
124
- this.client.send(putObject, (err, data) => {
125
- if (err || !data) {
126
- resolve(err)
127
- }
128
- if (data) {
129
- resolve(data)
130
- }
131
- })
132
- }).then(result => {
133
- if (callback && typeof callback === 'function') {
134
- callback(null, result)
135
- }
136
- return result
137
- }).catch(error => {
138
- if (callback && typeof callback === 'function') {
139
- callback(error, null)
140
- }
141
- return Promise.reject(error)
142
- })
143
- }
144
-
145
- listObjectsV2 (params, callback) {
146
- return new Promise((resolve, reject) => {
147
- const command = new ListObjectsV2Command(params)
148
- this.client.send(command, (err, data) => {
149
- if (err || !data) {
150
- resolve(err)
151
- }
152
- if (data) {
153
- resolve(data)
154
- }
155
- })
156
- }).then(result => {
157
- if (callback && typeof callback === 'function') {
158
- callback(null, result)
159
- }
160
- return result
161
- }).catch(error => {
162
- if (callback && typeof callback === 'function') {
163
- callback(error, null)
164
- }
165
- return Promise.reject(error)
166
- })
167
- }
168
- }
169
-
170
- module.exports = S3R