aws-v3-sdk 1.0.14 → 1.0.16
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/cognito.js +57 -1
- package/clients/dynamo/DocumentClient.js +129 -1
- package/es-handler/index.js +4 -1
- package/es-handler/sendGetRequest.js +59 -0
- package/package.json +1 -1
package/clients/cognito.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { CognitoIdentityProviderClient, ListUsersCommand } = require('@aws-sdk/client-cognito-identity-provider')
|
|
1
|
+
const { CognitoIdentityProviderClient, ListUsersCommand, AdminCreateUserCommand, AdminEnableUserCommand, AdminDisableUserCommand, AdminSetUserMFAPreferenceCommand, AdminUserGlobalSignOutCommand, AdminDeleteUserCommand } = require('@aws-sdk/client-cognito-identity-provider')
|
|
2
2
|
|
|
3
3
|
class CognitoIdentityServiceProvider {
|
|
4
4
|
constructor (region) {
|
|
@@ -13,6 +13,62 @@ class CognitoIdentityServiceProvider {
|
|
|
13
13
|
callback(err)
|
|
14
14
|
})
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
async adminCreateUser (params, callback) {
|
|
18
|
+
const command = new AdminCreateUserCommand(params);
|
|
19
|
+
this.client.send(command).then(data => {
|
|
20
|
+
callback(null, data)
|
|
21
|
+
}).catch(err => {
|
|
22
|
+
callback(err)
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async adminSetUserMFAPreference (params, callback) {
|
|
27
|
+
const command = new AdminSetUserMFAPreferenceCommand(params);
|
|
28
|
+
this.client.send(command).then(data => {
|
|
29
|
+
callback(null, data)
|
|
30
|
+
}).catch(err => {
|
|
31
|
+
callback(err)
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async adminDeleteUser (params, callback) {
|
|
36
|
+
const command = new AdminDeleteUserCommand(params);
|
|
37
|
+
this.client.send(command).then(data => {
|
|
38
|
+
callback(null, data)
|
|
39
|
+
}).catch(err => {
|
|
40
|
+
callback(err)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async adminEnableUser (params, callback) {
|
|
45
|
+
const command = new AdminEnableUserCommand(params);
|
|
46
|
+
this.client.send(command).then(data => {
|
|
47
|
+
callback(null, data)
|
|
48
|
+
}).catch(err => {
|
|
49
|
+
callback(err)
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
async adminDisableUser (params, callback) {
|
|
55
|
+
const command = new AdminDisableUserCommand(params);
|
|
56
|
+
this.client.send(command).then(data => {
|
|
57
|
+
callback(null, data)
|
|
58
|
+
}).catch(err => {
|
|
59
|
+
callback(err)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async adminUserGlobalSignOut (params, callback) {
|
|
64
|
+
const command = new AdminUserGlobalSignOutCommand(params);
|
|
65
|
+
this.client.send(command).then(data => {
|
|
66
|
+
callback(null, data)
|
|
67
|
+
}).catch(err => {
|
|
68
|
+
callback(err)
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
16
72
|
}
|
|
17
73
|
|
|
18
74
|
module.exports = CognitoIdentityServiceProvider
|
|
@@ -81,7 +81,12 @@ class DocumentClient {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
update (params, callback) {
|
|
84
|
-
const
|
|
84
|
+
const options = {
|
|
85
|
+
marshallOptions: {
|
|
86
|
+
removeUndefinedValues: true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const docClient = DynamoDBDocument.from(ddb, options)
|
|
85
90
|
docClient.update(params, (err, response) => {
|
|
86
91
|
if (err) {
|
|
87
92
|
return callback(err)
|
|
@@ -113,6 +118,129 @@ class DocumentClient {
|
|
|
113
118
|
}
|
|
114
119
|
})
|
|
115
120
|
}
|
|
121
|
+
|
|
122
|
+
getAsync (params, callback) {
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
const getCommand = new GetCommand(params)
|
|
125
|
+
documentClient.send(getCommand, (err, response) => {
|
|
126
|
+
if (err || !response) {
|
|
127
|
+
return reject(err)
|
|
128
|
+
}
|
|
129
|
+
if (response.Item) {
|
|
130
|
+
return resolve(response)
|
|
131
|
+
} else if (!response.Item) {
|
|
132
|
+
return resolve({})
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
}).then(result => {
|
|
136
|
+
if (callback && typeof callback === 'function') {
|
|
137
|
+
callback(null, result)
|
|
138
|
+
}
|
|
139
|
+
return result
|
|
140
|
+
}).catch(error => {
|
|
141
|
+
if (callback && typeof callback === 'function') {
|
|
142
|
+
callback(error, null)
|
|
143
|
+
}
|
|
144
|
+
return Promise.reject(error)
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
queryAsync (params, callback) {
|
|
149
|
+
return new Promise((resolve, reject) => {
|
|
150
|
+
const getCommand = new QueryCommand(params)
|
|
151
|
+
documentClient.send(getCommand, (err, response) => {
|
|
152
|
+
if (err || !response) {
|
|
153
|
+
return resolve(err)
|
|
154
|
+
}
|
|
155
|
+
return resolve(response)
|
|
156
|
+
})
|
|
157
|
+
}).then(result => {
|
|
158
|
+
if (callback && typeof callback === 'function') {
|
|
159
|
+
callback(null, result)
|
|
160
|
+
}
|
|
161
|
+
return result
|
|
162
|
+
}).catch(error => {
|
|
163
|
+
if (callback && typeof callback === 'function') {
|
|
164
|
+
callback(error, null)
|
|
165
|
+
}
|
|
166
|
+
return Promise.reject(error)
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
putAsync (params, callback) {
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
let item = params.Item
|
|
173
|
+
try {
|
|
174
|
+
item = Object.fromEntries(Object.entries(item).filter(([key, value]) => value !== undefined))
|
|
175
|
+
} catch (error) {
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
params.Item = item
|
|
179
|
+
const putCommand = new PutCommand(params)
|
|
180
|
+
documentClient.send(putCommand, (err, response) => {
|
|
181
|
+
if (err || !response) {
|
|
182
|
+
return resolve(err)
|
|
183
|
+
}
|
|
184
|
+
return resolve(response)
|
|
185
|
+
})
|
|
186
|
+
}).then(result => {
|
|
187
|
+
if (callback && typeof callback === 'function') {
|
|
188
|
+
callback(null, result)
|
|
189
|
+
}
|
|
190
|
+
return result
|
|
191
|
+
}).catch(error => {
|
|
192
|
+
if (callback && typeof callback === 'function') {
|
|
193
|
+
callback(error, null)
|
|
194
|
+
}
|
|
195
|
+
return Promise.reject(error)
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
deleteAsync (params, callback) {
|
|
200
|
+
return new Promise((resolve, reject) => {
|
|
201
|
+
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
202
|
+
docClient.delete(params, (err, response) => {
|
|
203
|
+
if (err) {
|
|
204
|
+
return resolve(err)
|
|
205
|
+
} else {
|
|
206
|
+
return resolve(response)
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
}).then(result => {
|
|
210
|
+
if (callback && typeof callback === 'function') {
|
|
211
|
+
callback(null, result)
|
|
212
|
+
}
|
|
213
|
+
return result
|
|
214
|
+
}).catch(error => {
|
|
215
|
+
if (callback && typeof callback === 'function') {
|
|
216
|
+
callback(error, null)
|
|
217
|
+
}
|
|
218
|
+
return Promise.reject(error)
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
updateAsync (params, callback) {
|
|
223
|
+
return new Promise((resolve, reject) => {
|
|
224
|
+
const docClient = DynamoDBDocument.from(new DynamoDB())
|
|
225
|
+
docClient.update(params, (err, response) => {
|
|
226
|
+
if (err) {
|
|
227
|
+
return resolve(err)
|
|
228
|
+
} else {
|
|
229
|
+
return resolve(response)
|
|
230
|
+
}
|
|
231
|
+
})
|
|
232
|
+
}).then(result => {
|
|
233
|
+
if (callback && typeof callback === 'function') {
|
|
234
|
+
callback(null, result)
|
|
235
|
+
}
|
|
236
|
+
return result
|
|
237
|
+
}).catch(error => {
|
|
238
|
+
if (callback && typeof callback === 'function') {
|
|
239
|
+
callback(error, null)
|
|
240
|
+
}
|
|
241
|
+
return Promise.reject(error)
|
|
242
|
+
})
|
|
243
|
+
}
|
|
116
244
|
}
|
|
117
245
|
|
|
118
246
|
module.exports = DocumentClient
|
package/es-handler/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
const { sendGetRequest } = require('./sendGetRequest')
|
|
1
|
+
const { sendGetRequest, sendGetRequestCallback, getCount, multiSearch } = require('./sendGetRequest')
|
|
2
2
|
const { sendAuditsReqToES } = require('./es-audits-wrapper')
|
|
3
3
|
const { sendReqToES } = require('./es-wrapper')
|
|
4
4
|
|
|
5
5
|
module.exports = {
|
|
6
6
|
sendGetRequest,
|
|
7
|
+
sendGetRequestCallback,
|
|
8
|
+
getCount,
|
|
9
|
+
multiSearch,
|
|
7
10
|
sendReqToES,
|
|
8
11
|
sendAuditsReqToES
|
|
9
12
|
}
|
|
@@ -55,3 +55,62 @@ exports.sendGetRequest = async (index, query, from, size, sort, _source) => {
|
|
|
55
55
|
})
|
|
56
56
|
})
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
exports.sendGetRequestCallback = async (index, query, from, size, sort, callback) => {
|
|
60
|
+
const client = await getClient()
|
|
61
|
+
return new Promise((resolve, reject) => {
|
|
62
|
+
let body = { query }
|
|
63
|
+
if (sort) {
|
|
64
|
+
body = { query, sort }
|
|
65
|
+
}
|
|
66
|
+
client.search({
|
|
67
|
+
index,
|
|
68
|
+
from,
|
|
69
|
+
size,
|
|
70
|
+
body
|
|
71
|
+
}).then(response => {
|
|
72
|
+
const data = response.body.hits.hits
|
|
73
|
+
const totalCount = response.body.hits.total
|
|
74
|
+
const mappedData = data.map(item => {
|
|
75
|
+
return item._source
|
|
76
|
+
})
|
|
77
|
+
callback(null, { items: mappedData, data: mappedData, totalCount })
|
|
78
|
+
}).catch(e => {
|
|
79
|
+
callback(null, { items: [], data: [], totalCount: 0 })
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
exports.getCount = async (index, query) => {
|
|
85
|
+
const client = await getClient()
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
client.count({
|
|
88
|
+
index,
|
|
89
|
+
body: { query }
|
|
90
|
+
}).then(response => {
|
|
91
|
+
const data = response.body
|
|
92
|
+
resolve({ data })
|
|
93
|
+
}).catch(e => {
|
|
94
|
+
console.log(e);
|
|
95
|
+
resolve({ })
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
exports.multiSearch = async (query) => {
|
|
101
|
+
const client = await getClient()
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
let body = query
|
|
104
|
+
client.msearch({
|
|
105
|
+
body
|
|
106
|
+
}).then(response => {
|
|
107
|
+
resolve(response);
|
|
108
|
+
}).catch(e => {
|
|
109
|
+
console.log(e);
|
|
110
|
+
resolve({ items: [], data: [], totalCount: 0 })
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|