aws-v3-sdk 1.0.5 → 1.0.6
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 +8 -0
- package/clients/cognito.js +18 -0
- package/clients/dynamo/DocumentClient.js +100 -0
- package/{lib/clients → clients}/dynamoDB.js +0 -1
- package/{lib/clients → clients}/lambda.js +14 -2
- package/clients/s3.js +35 -0
- package/clients/sts.js +19 -0
- package/lib/aws.js +1 -1
- package/package.json +1 -1
- package/lib/clients/all.js +0 -5
- package/lib/clients/dynamo/DocumentClient.js +0 -23
- /package/{lib/clients → clients}/credential.js +0 -0
package/clients/all.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const { CognitoIdentityProviderClient, ListUsersCommand } = require('@aws-sdk/client-cognito-identity-provider')
|
|
2
|
+
|
|
3
|
+
class CognitoIdentityServiceProvider {
|
|
4
|
+
constructor (region) {
|
|
5
|
+
this.client = new CognitoIdentityProviderClient({ region }) // Replace with your desired region
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
async listUsers (params, callback) {
|
|
9
|
+
const command = new ListUsersCommand(params)
|
|
10
|
+
this.client.send(command).then(data => {
|
|
11
|
+
callback(null, data)
|
|
12
|
+
}).catch(err => {
|
|
13
|
+
callback(err)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
module.exports = CognitoIdentityServiceProvider
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const { DynamoDB, DynamoDBClient, BatchGetItemCommand } = require('@aws-sdk/client-dynamodb')
|
|
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
|
+
|
|
6
|
+
class DocumentClient {
|
|
7
|
+
get (params, callback) {
|
|
8
|
+
const getCommand = new GetCommand(params)
|
|
9
|
+
documentClient.send(getCommand, (err, response) => {
|
|
10
|
+
if (err || !response) {
|
|
11
|
+
return callback(err)
|
|
12
|
+
}
|
|
13
|
+
if (response.Item) {
|
|
14
|
+
return callback(null, response)
|
|
15
|
+
} else if (!response.Item) {
|
|
16
|
+
return callback(null, {})
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
query (params, callback) {
|
|
22
|
+
const getCommand = new QueryCommand(params)
|
|
23
|
+
documentClient.send(getCommand, (err, response) => {
|
|
24
|
+
if (err || !response) {
|
|
25
|
+
return callback(err)
|
|
26
|
+
}
|
|
27
|
+
return callback(null, response)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
scan (params, callback) {
|
|
32
|
+
const getCommand = new ScanCommand(params)
|
|
33
|
+
documentClient.send(getCommand, (err, response) => {
|
|
34
|
+
if (err || !response) {
|
|
35
|
+
return callback(err)
|
|
36
|
+
}
|
|
37
|
+
if (response.Items) {
|
|
38
|
+
return callback(null, response)
|
|
39
|
+
} else if (!response.Items) {
|
|
40
|
+
return callback(null)
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
put (params, callback) {
|
|
46
|
+
const putCommand = new PutCommand(params)
|
|
47
|
+
documentClient.send(putCommand, (err, response) => {
|
|
48
|
+
if (err || !response) {
|
|
49
|
+
return callback(err)
|
|
50
|
+
}
|
|
51
|
+
return callback(null, response)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
delete (params, callback) {
|
|
56
|
+
const putCommand = new DeleteCommand(params)
|
|
57
|
+
documentClient.send(putCommand, (err, response) => {
|
|
58
|
+
if (err) {
|
|
59
|
+
return callback(err)
|
|
60
|
+
}
|
|
61
|
+
return callback(null, response)
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
update (params, callback) {
|
|
66
|
+
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
67
|
+
docClient.update(params, (err, response) => {
|
|
68
|
+
if (err) {
|
|
69
|
+
return callback(err)
|
|
70
|
+
} else {
|
|
71
|
+
return callback(null, response)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
batchWrite (params, callback) {
|
|
77
|
+
const command = new BatchWriteCommand(params)
|
|
78
|
+
documentClient.send(command, (err, response) => {
|
|
79
|
+
if (err || !response) {
|
|
80
|
+
return callback(err)
|
|
81
|
+
}
|
|
82
|
+
if (response) {
|
|
83
|
+
return callback(null, response)
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
batchGet (params, callback) {
|
|
89
|
+
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
90
|
+
|
|
91
|
+
docClient.batchGet(params, function (err, data) {
|
|
92
|
+
if (err) callback(err)
|
|
93
|
+
else {
|
|
94
|
+
callback(null, data)
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
module.exports = DocumentClient
|
|
@@ -2,10 +2,22 @@ const { LambdaClient, InvokeCommand, InvokeAsyncCommand } = require('@aws-sdk/cl
|
|
|
2
2
|
const { toUtf8, fromUtf8 } = require('@aws-sdk/util-utf8-node')
|
|
3
3
|
|
|
4
4
|
class Lambda {
|
|
5
|
+
constructor (region, session) {
|
|
6
|
+
if (region && session) {
|
|
7
|
+
this.client = new LambdaClient({ region, credentials: session })
|
|
8
|
+
} else {
|
|
9
|
+
this.client = new LambdaClient()
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
async invoke (params, callback) {
|
|
6
|
-
|
|
14
|
+
if (params.Payload) {
|
|
15
|
+
params.InvokeArgs = fromUtf8(params.Payload)
|
|
16
|
+
delete params.Payload
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
const command = new InvokeCommand(params)
|
|
8
|
-
client.send(command).then(response => {
|
|
20
|
+
this.client.send(command).then(response => {
|
|
9
21
|
response.Payload = toUtf8(response.Payload)
|
|
10
22
|
callback(null, response)
|
|
11
23
|
}).catch(err => {
|
package/clients/s3.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const { S3Client, GetObjectCommand, PutObjectCommand, ListObjectsCommand, DeleteObjectsCommand } = require('@aws-sdk/client-s3')
|
|
2
|
+
const { getSignedUrl } = require('@aws-sdk/s3-request-presigner')
|
|
3
|
+
const client = new S3Client({})
|
|
4
|
+
|
|
5
|
+
class S3 {
|
|
6
|
+
getObject (params, callback) {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
const getObject = new GetObjectCommand(params)
|
|
9
|
+
client.send(getObject).then(response => {
|
|
10
|
+
const chunks = []
|
|
11
|
+
const stream = response.Body
|
|
12
|
+
stream.on('data', chunk => chunks.push(chunk))
|
|
13
|
+
stream.on('end', () => {
|
|
14
|
+
const imageBuffer = Buffer.concat(chunks)
|
|
15
|
+
response.Body = imageBuffer
|
|
16
|
+
resolve(response)
|
|
17
|
+
})
|
|
18
|
+
}).catch(err => {
|
|
19
|
+
resolve(err)
|
|
20
|
+
})
|
|
21
|
+
}).then(result => {
|
|
22
|
+
if (callback && typeof callback === 'function') {
|
|
23
|
+
callback(null, result)
|
|
24
|
+
}
|
|
25
|
+
return result
|
|
26
|
+
}).catch(error => {
|
|
27
|
+
if (callback && typeof callback === 'function') {
|
|
28
|
+
callback(error, null)
|
|
29
|
+
}
|
|
30
|
+
return Promise.reject(error)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = S3
|
package/clients/sts.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const { STSClient, AssumeRoleCommand } = require('@aws-sdk/client-sts')
|
|
2
|
+
|
|
3
|
+
class STS {
|
|
4
|
+
constructor (AWS_REGION) {
|
|
5
|
+
this.client = new STSClient({ region: AWS_REGION })
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
assumeRole (params, callback) {
|
|
9
|
+
console.log('params', params)
|
|
10
|
+
const command = new AssumeRoleCommand(params)
|
|
11
|
+
this.client.send(command).then(role => {
|
|
12
|
+
return callback(null, role)
|
|
13
|
+
}).catch(err => {
|
|
14
|
+
return callback(err)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = STS
|
package/lib/aws.js
CHANGED
package/package.json
CHANGED
package/lib/clients/all.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb')
|
|
2
|
-
const { DynamoDBDocumentClient, GetCommand } = require('@aws-sdk/lib-dynamodb')
|
|
3
|
-
const ddb = new DynamoDBClient()
|
|
4
|
-
const documentClient = DynamoDBDocumentClient.from(ddb)
|
|
5
|
-
|
|
6
|
-
class DocumentClient {
|
|
7
|
-
get (params, callback) {
|
|
8
|
-
const getCommand = new GetCommand(params)
|
|
9
|
-
documentClient.send(getCommand, (err, response) => {
|
|
10
|
-
console.log(response)
|
|
11
|
-
if (err || !response) {
|
|
12
|
-
return callback(err)
|
|
13
|
-
}
|
|
14
|
-
if (response.Item) {
|
|
15
|
-
return callback(null, response)
|
|
16
|
-
} else if (!response.Item) {
|
|
17
|
-
return callback(response)
|
|
18
|
-
}
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = DocumentClient
|
|
File without changes
|