aws-v3-sdk 2.0.0 → 2.0.1
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/clients/all.js +1 -0
- package/clients/dynamo/DocumentClient.js +0 -37
- package/clients/s3.js +1 -25
- package/clients/s3R.js +170 -0
- package/es-handler/es-audits-wrapper.js +1 -1
- package/es-handler/es-wrapper.js +16 -4
- package/es-handler/sendGetRequest.js +1 -1
- package/package.json +1 -1
package/clients/all.js
CHANGED
|
@@ -116,18 +116,6 @@ class DocumentClient {
|
|
|
116
116
|
})
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
transactWrite (params, callback) {
|
|
120
|
-
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
121
|
-
docClient.transactWrite(params, function (err, data) {
|
|
122
|
-
if (err) {
|
|
123
|
-
callback(err)
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
callback(null, data)
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
|
|
131
119
|
batchGet (params, callback) {
|
|
132
120
|
const docClient = DynamoDBDocument.from(ddb)
|
|
133
121
|
|
|
@@ -333,31 +321,6 @@ class DocumentClient {
|
|
|
333
321
|
return Promise.reject(error)
|
|
334
322
|
})
|
|
335
323
|
}
|
|
336
|
-
|
|
337
|
-
transactWriteAsync (params, callback) {
|
|
338
|
-
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
339
|
-
return new Promise((resolve, reject) => {
|
|
340
|
-
docClient.transactWrite(params, (err, response) => {
|
|
341
|
-
if (err || !response) {
|
|
342
|
-
return reject(err)
|
|
343
|
-
}
|
|
344
|
-
if (response) {
|
|
345
|
-
return resolve(response)
|
|
346
|
-
}
|
|
347
|
-
})
|
|
348
|
-
}).then(result => {
|
|
349
|
-
if (callback && typeof callback === 'function') {
|
|
350
|
-
callback(null, result)
|
|
351
|
-
}
|
|
352
|
-
return result
|
|
353
|
-
}).catch(error => {
|
|
354
|
-
if (callback && typeof callback === 'function') {
|
|
355
|
-
callback(error, null)
|
|
356
|
-
}
|
|
357
|
-
return Promise.reject(error)
|
|
358
|
-
})
|
|
359
|
-
}
|
|
360
324
|
}
|
|
361
325
|
|
|
362
|
-
|
|
363
326
|
module.exports = DocumentClient
|
package/clients/s3.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { S3Client, GetObjectCommand, PutObjectCommand,
|
|
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
3
|
|
|
4
4
|
const { Agent } = require('https')
|
|
@@ -147,30 +147,6 @@ 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
|
-
}
|
|
174
150
|
}
|
|
175
151
|
|
|
176
152
|
module.exports = S3
|
package/clients/s3R.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
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
|
package/es-handler/es-wrapper.js
CHANGED
|
@@ -28,7 +28,8 @@ const getClient = async () => {
|
|
|
28
28
|
const cred = createAwsConnector(credentials, REGION)
|
|
29
29
|
return new Client({
|
|
30
30
|
...cred,
|
|
31
|
-
node: host
|
|
31
|
+
node: host,
|
|
32
|
+
maxRetries: 0
|
|
32
33
|
})
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -39,7 +40,8 @@ exports.sendReqToES = async (method, index, type, id, data) => {
|
|
|
39
40
|
const response = await client.delete({
|
|
40
41
|
index,
|
|
41
42
|
type,
|
|
42
|
-
id
|
|
43
|
+
id,
|
|
44
|
+
refresh: false
|
|
43
45
|
})
|
|
44
46
|
return response.body
|
|
45
47
|
} else if (method === 'UPDATE') {
|
|
@@ -48,7 +50,17 @@ exports.sendReqToES = async (method, index, type, id, data) => {
|
|
|
48
50
|
index,
|
|
49
51
|
type,
|
|
50
52
|
body: data,
|
|
51
|
-
refresh:
|
|
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
|
|
52
64
|
})
|
|
53
65
|
return response.body
|
|
54
66
|
} else {
|
|
@@ -57,7 +69,7 @@ exports.sendReqToES = async (method, index, type, id, data) => {
|
|
|
57
69
|
index,
|
|
58
70
|
type,
|
|
59
71
|
body: data,
|
|
60
|
-
refresh:
|
|
72
|
+
refresh: false
|
|
61
73
|
})
|
|
62
74
|
return response.body
|
|
63
75
|
}
|
|
@@ -52,7 +52,7 @@ exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
|
|
|
52
52
|
options.size = size
|
|
53
53
|
}
|
|
54
54
|
if (_source) {
|
|
55
|
-
options._source =
|
|
55
|
+
options._source = _source
|
|
56
56
|
}
|
|
57
57
|
client.search(options).then(response => {
|
|
58
58
|
logger.debug(response, { response })
|