idea-aws 3.16.7 → 4.0.0
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 +2 -2
- package/dist/src/attachments.d.ts +1 -1
- package/dist/src/attachments.js +3 -3
- package/dist/src/cognito.d.ts +7 -7
- package/dist/src/cognito.js +103 -64
- package/dist/src/comprehend.d.ts +2 -2
- package/dist/src/comprehend.js +29 -6
- package/dist/src/dynamoDB.d.ts +46 -40
- package/dist/src/dynamoDB.js +66 -35
- package/dist/src/resourceController.js +33 -6
- package/dist/src/s3.d.ts +7 -7
- package/dist/src/s3.js +59 -31
- package/dist/src/secretsManager.d.ts +2 -2
- package/dist/src/secretsManager.js +27 -3
- package/dist/src/ses.d.ts +5 -5
- package/dist/src/ses.js +71 -30
- package/dist/src/sns.d.ts +2 -1
- package/dist/src/sns.js +35 -8
- package/dist/src/translate.d.ts +3 -5
- package/dist/src/translate.js +29 -7
- package/package.json +25 -12
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# IDEA AWS
|
|
2
2
|
|
|
3
|
-
AWS wrappers to use in IDEA's back-ends
|
|
3
|
+
AWS wrappers to use in IDEA's back-ends; note: internally we use AWS-SDK _v3_.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -18,4 +18,4 @@ Documentation generated with TypeDoc: [link](https://iter-idea.github.io/IDEA-AW
|
|
|
18
18
|
|
|
19
19
|
## Notes
|
|
20
20
|
|
|
21
|
-
The AWS-SDK is already pre-installed in every Lambda Function; therefore,
|
|
21
|
+
The AWS-SDK (v3) is already pre-installed in every Lambda Function; therefore, the clients are all in `devDependency`.
|
package/dist/src/attachments.js
CHANGED
|
@@ -22,15 +22,15 @@ class Attachments {
|
|
|
22
22
|
async put(project, teamId) {
|
|
23
23
|
const attachmentIdPrefix = this.IUID_ATTACHMENTS_PREFIX.concat('_').concat(project).concat('_').concat(teamId);
|
|
24
24
|
const attachmentId = await this.dynamo.IUNID(attachmentIdPrefix);
|
|
25
|
-
const signedURL = this.s3.signedURLPut(this.S3_ATTACHMENTS_BUCKET, attachmentId);
|
|
25
|
+
const signedURL = await this.s3.signedURLPut(this.S3_ATTACHMENTS_BUCKET, attachmentId);
|
|
26
26
|
signedURL.id = attachmentId;
|
|
27
27
|
return signedURL;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Get a signedURL to retrieve an attachment.
|
|
31
31
|
*/
|
|
32
|
-
get(attachmentId) {
|
|
33
|
-
const signedURL = this.s3.signedURLGet(this.S3_ATTACHMENTS_BUCKET, attachmentId);
|
|
32
|
+
async get(attachmentId) {
|
|
33
|
+
const signedURL = await this.s3.signedURLGet(this.S3_ATTACHMENTS_BUCKET, attachmentId);
|
|
34
34
|
signedURL.id = attachmentId;
|
|
35
35
|
return signedURL;
|
|
36
36
|
}
|
package/dist/src/cognito.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as CognitoIP from '@aws-sdk/client-cognito-identity-provider';
|
|
2
2
|
import { CognitoUser } from 'idea-toolbox';
|
|
3
3
|
/**
|
|
4
4
|
* A wrapper for AWS Cognito.
|
|
5
5
|
*/
|
|
6
6
|
export declare class Cognito {
|
|
7
|
-
protected cognito:
|
|
7
|
+
protected cognito: CognitoIP.CognitoIdentityProviderClient;
|
|
8
8
|
constructor(params?: {
|
|
9
9
|
region?: string;
|
|
10
10
|
});
|
|
@@ -17,9 +17,9 @@ export declare class Cognito {
|
|
|
17
17
|
* Get the attributes of the user, from the authorizer claims.
|
|
18
18
|
* @param claims authorizer claims
|
|
19
19
|
* @return user's data
|
|
20
|
-
* @deprecated use
|
|
20
|
+
* @deprecated use idea-toolbox's CognitoUser instead
|
|
21
21
|
*/
|
|
22
|
-
getUserByClaims(claims: any): CognitoUserGeneric;
|
|
22
|
+
getUserByClaims(claims: Record<string, any>): CognitoUserGeneric;
|
|
23
23
|
/**
|
|
24
24
|
* Map the complex structure returned by Cognito for a user's attributes in a simple key-value object.
|
|
25
25
|
*/
|
|
@@ -68,11 +68,11 @@ export declare class Cognito {
|
|
|
68
68
|
/**
|
|
69
69
|
* Sign in a user of a specific pool through username and password.
|
|
70
70
|
*/
|
|
71
|
-
signIn(email: string, password: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<
|
|
71
|
+
signIn(email: string, password: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<CognitoIP.AuthenticationResultType>;
|
|
72
72
|
/**
|
|
73
73
|
* Given a username and a refresh token (and pool data), refresh the session and return the new tokens.
|
|
74
74
|
*/
|
|
75
|
-
refreshSession(email: string, refreshToken: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<
|
|
75
|
+
refreshSession(email: string, refreshToken: string, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<CognitoIP.AuthenticationResultType>;
|
|
76
76
|
/**
|
|
77
77
|
* Change the email address (== username) associated to a user.
|
|
78
78
|
*/
|
|
@@ -84,7 +84,7 @@ export declare class Cognito {
|
|
|
84
84
|
/**
|
|
85
85
|
* Send to a user the instructions to change the password.
|
|
86
86
|
*/
|
|
87
|
-
forgotPassword(email: string, cognitoUserPoolClientId: string): Promise<
|
|
87
|
+
forgotPassword(email: string, cognitoUserPoolClientId: string): Promise<CognitoIP.CodeDeliveryDetailsType>;
|
|
88
88
|
/**
|
|
89
89
|
* Update a (Cognito)User's attributes, excluding the attributes that require specific methods.
|
|
90
90
|
*/
|
package/dist/src/cognito.js
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Cognito = void 0;
|
|
4
|
-
const
|
|
27
|
+
const CognitoIP = __importStar(require("@aws-sdk/client-cognito-identity-provider"));
|
|
5
28
|
const idea_toolbox_1 = require("idea-toolbox");
|
|
6
29
|
/**
|
|
7
30
|
* A wrapper for AWS Cognito.
|
|
8
31
|
*/
|
|
9
32
|
class Cognito {
|
|
10
33
|
constructor(params = {}) {
|
|
11
|
-
this.cognito = new
|
|
34
|
+
this.cognito = new CognitoIP.CognitoIdentityProviderClient({ region: params.region });
|
|
12
35
|
}
|
|
13
36
|
/**
|
|
14
37
|
* Change the region in which to find the user pool.
|
|
@@ -16,13 +39,13 @@ class Cognito {
|
|
|
16
39
|
*/
|
|
17
40
|
setRegion(region) {
|
|
18
41
|
// there is no quick way to change the region without re-creating the object
|
|
19
|
-
this.cognito = new
|
|
42
|
+
this.cognito = new CognitoIP.CognitoIdentityProviderClient({ region });
|
|
20
43
|
}
|
|
21
44
|
/**
|
|
22
45
|
* Get the attributes of the user, from the authorizer claims.
|
|
23
46
|
* @param claims authorizer claims
|
|
24
47
|
* @return user's data
|
|
25
|
-
* @deprecated use
|
|
48
|
+
* @deprecated use idea-toolbox's CognitoUser instead
|
|
26
49
|
*/
|
|
27
50
|
getUserByClaims(claims) {
|
|
28
51
|
if (!claims)
|
|
@@ -51,19 +74,28 @@ class Cognito {
|
|
|
51
74
|
* Identify a user by its email address, returning its attributes.
|
|
52
75
|
*/
|
|
53
76
|
async getUserByEmail(email, cognitoUserPoolId) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
const command = new CognitoIP.AdminGetUserCommand({ UserPoolId: cognitoUserPoolId, Username: email });
|
|
78
|
+
try {
|
|
79
|
+
const user = await this.cognito.send(command);
|
|
80
|
+
return this.mapCognitoUserAttributesAsPlainObject(user);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
if (error.name === 'UserNotFoundException')
|
|
84
|
+
throw new Error('User not found');
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
58
87
|
}
|
|
59
88
|
/**
|
|
60
89
|
* Identify a user by its userId (sub), returning its attributes.
|
|
61
90
|
*/
|
|
62
91
|
async getUserBySub(sub, cognitoUserPoolId) {
|
|
63
92
|
// as of today, there is no a direct way to find a user by its sub: we need to run a query against the users base
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
93
|
+
const command = new CognitoIP.ListUsersCommand({
|
|
94
|
+
UserPoolId: cognitoUserPoolId,
|
|
95
|
+
Filter: `sub = "${sub}"`,
|
|
96
|
+
Limit: 1
|
|
97
|
+
});
|
|
98
|
+
const usersList = await this.cognito.send(command);
|
|
67
99
|
const user = usersList?.Users[0];
|
|
68
100
|
if (!user)
|
|
69
101
|
throw new Error('User not found');
|
|
@@ -76,9 +108,8 @@ class Cognito {
|
|
|
76
108
|
const params = { UserPoolId: cognitoUserPoolId };
|
|
77
109
|
if (options.pagination)
|
|
78
110
|
params.PaginationToken = options.pagination;
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
|
|
111
|
+
const { Users, PaginationToken: pagination } = await this.cognito.send(new CognitoIP.ListUsersCommand(params));
|
|
112
|
+
const users = options.users.concat(Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
|
|
82
113
|
if (pagination)
|
|
83
114
|
return await this.listUsers(cognitoUserPoolId, { pagination, users });
|
|
84
115
|
else
|
|
@@ -134,12 +165,11 @@ class Cognito {
|
|
|
134
165
|
params.MessageAction = 'SUPPRESS';
|
|
135
166
|
if (options.temporaryPassword)
|
|
136
167
|
params.TemporaryPassword = options.temporaryPassword;
|
|
137
|
-
const
|
|
138
|
-
const userId = this.mapCognitoUserAttributesAsPlainObject(
|
|
139
|
-
if (userId)
|
|
140
|
-
return userId;
|
|
141
|
-
else
|
|
168
|
+
const { User } = await this.cognito.send(new CognitoIP.AdminCreateUserCommand(params));
|
|
169
|
+
const userId = this.mapCognitoUserAttributesAsPlainObject(User).sub;
|
|
170
|
+
if (!userId)
|
|
142
171
|
throw new Error('Creation failed');
|
|
172
|
+
return userId;
|
|
143
173
|
}
|
|
144
174
|
/**
|
|
145
175
|
* Resend the password to a user who never logged in.
|
|
@@ -154,7 +184,7 @@ class Cognito {
|
|
|
154
184
|
};
|
|
155
185
|
if (options.temporaryPassword)
|
|
156
186
|
params.TemporaryPassword = options.temporaryPassword;
|
|
157
|
-
await this.cognito.
|
|
187
|
+
await this.cognito.send(new CognitoIP.AdminCreateUserCommand(params));
|
|
158
188
|
}
|
|
159
189
|
/**
|
|
160
190
|
* Set a new password for a specific user identified by its email (admin-only).
|
|
@@ -174,7 +204,7 @@ class Cognito {
|
|
|
174
204
|
Password: password,
|
|
175
205
|
Permanent: options.permanent
|
|
176
206
|
};
|
|
177
|
-
await this.cognito.
|
|
207
|
+
await this.cognito.send(new CognitoIP.AdminSetUserPasswordCommand(params));
|
|
178
208
|
}
|
|
179
209
|
/**
|
|
180
210
|
* Delete a user by its email (username), in the pool specified.
|
|
@@ -182,41 +212,38 @@ class Cognito {
|
|
|
182
212
|
async deleteUser(email, cognitoUserPoolId) {
|
|
183
213
|
if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
|
|
184
214
|
throw new Error('Invalid email');
|
|
185
|
-
|
|
215
|
+
const command = new CognitoIP.AdminDeleteUserCommand({ UserPoolId: cognitoUserPoolId, Username: email });
|
|
216
|
+
await this.cognito.send(command);
|
|
186
217
|
}
|
|
187
218
|
/**
|
|
188
219
|
* Sign in a user of a specific pool through username and password.
|
|
189
220
|
*/
|
|
190
221
|
async signIn(email, password, cognitoUserPoolId, cognitoUserPoolClientId) {
|
|
191
|
-
const
|
|
192
|
-
.adminInitiateAuth({
|
|
222
|
+
const command = new CognitoIP.AdminInitiateAuthCommand({
|
|
193
223
|
UserPoolId: cognitoUserPoolId,
|
|
194
224
|
ClientId: cognitoUserPoolClientId,
|
|
195
225
|
AuthFlow: 'ADMIN_NO_SRP_AUTH',
|
|
196
226
|
AuthParameters: { USERNAME: email, PASSWORD: password }
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
return result.AuthenticationResult;
|
|
201
|
-
else
|
|
227
|
+
});
|
|
228
|
+
const { AuthenticationResult } = await this.cognito.send(command);
|
|
229
|
+
if (!AuthenticationResult)
|
|
202
230
|
throw new Error('Sign-in failed');
|
|
231
|
+
return AuthenticationResult;
|
|
203
232
|
}
|
|
204
233
|
/**
|
|
205
234
|
* Given a username and a refresh token (and pool data), refresh the session and return the new tokens.
|
|
206
235
|
*/
|
|
207
236
|
async refreshSession(email, refreshToken, cognitoUserPoolId, cognitoUserPoolClientId) {
|
|
208
|
-
const
|
|
209
|
-
.adminInitiateAuth({
|
|
237
|
+
const command = new CognitoIP.AdminInitiateAuthCommand({
|
|
210
238
|
UserPoolId: cognitoUserPoolId,
|
|
211
239
|
ClientId: cognitoUserPoolClientId,
|
|
212
240
|
AuthFlow: 'REFRESH_TOKEN_AUTH',
|
|
213
241
|
AuthParameters: { USERNAME: email, REFRESH_TOKEN: refreshToken }
|
|
214
|
-
})
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
return result.AuthenticationResult;
|
|
218
|
-
else
|
|
242
|
+
});
|
|
243
|
+
const { AuthenticationResult } = await this.cognito.send(command);
|
|
244
|
+
if (!AuthenticationResult)
|
|
219
245
|
throw new Error('Refresh failed');
|
|
246
|
+
return AuthenticationResult;
|
|
220
247
|
}
|
|
221
248
|
/**
|
|
222
249
|
* Change the email address (== username) associated to a user.
|
|
@@ -224,16 +251,15 @@ class Cognito {
|
|
|
224
251
|
async updateEmail(email, newEmail, cognitoUserPoolId) {
|
|
225
252
|
if ((0, idea_toolbox_1.isEmpty)(newEmail, 'email'))
|
|
226
253
|
throw new Error('Invalid new email');
|
|
227
|
-
|
|
228
|
-
.adminUpdateUserAttributes({
|
|
254
|
+
const command = new CognitoIP.AdminUpdateUserAttributesCommand({
|
|
229
255
|
UserPoolId: cognitoUserPoolId,
|
|
230
256
|
Username: email,
|
|
231
257
|
UserAttributes: [
|
|
232
258
|
{ Name: 'email', Value: newEmail },
|
|
233
259
|
{ Name: 'email_verified', Value: 'true' }
|
|
234
260
|
]
|
|
235
|
-
})
|
|
236
|
-
|
|
261
|
+
});
|
|
262
|
+
await this.cognito.send(command);
|
|
237
263
|
// sign out the user from all its devices and resolve
|
|
238
264
|
await this.globalSignOut(newEmail, cognitoUserPoolId);
|
|
239
265
|
}
|
|
@@ -244,21 +270,19 @@ class Cognito {
|
|
|
244
270
|
if (newPassword.length < 8)
|
|
245
271
|
throw new Error('Invalid new password');
|
|
246
272
|
const tokensForPasswordChange = await this.signIn(email, oldPassword, cognitoUserPoolId, cognitoUserPoolClientId);
|
|
247
|
-
|
|
248
|
-
.changePassword({
|
|
273
|
+
const command = new CognitoIP.ChangePasswordCommand({
|
|
249
274
|
AccessToken: tokensForPasswordChange.AccessToken,
|
|
250
275
|
PreviousPassword: oldPassword,
|
|
251
276
|
ProposedPassword: newPassword
|
|
252
|
-
})
|
|
253
|
-
|
|
277
|
+
});
|
|
278
|
+
await this.cognito.send(command);
|
|
254
279
|
}
|
|
255
280
|
/**
|
|
256
281
|
* Send to a user the instructions to change the password.
|
|
257
282
|
*/
|
|
258
283
|
async forgotPassword(email, cognitoUserPoolClientId) {
|
|
259
|
-
const {
|
|
260
|
-
|
|
261
|
-
.promise();
|
|
284
|
+
const command = new CognitoIP.ForgotPasswordCommand({ Username: email, ClientId: cognitoUserPoolClientId });
|
|
285
|
+
const { CodeDeliveryDetails } = await this.cognito.send(command);
|
|
262
286
|
return CodeDeliveryDetails;
|
|
263
287
|
}
|
|
264
288
|
/**
|
|
@@ -273,15 +297,19 @@ class Cognito {
|
|
|
273
297
|
Name: 'custom:'.concat(customAttribute),
|
|
274
298
|
Value: String(user.attributes[customAttribute])
|
|
275
299
|
}));
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
.
|
|
300
|
+
const command = new CognitoIP.AdminUpdateUserAttributesCommand({
|
|
301
|
+
UserPoolId: cognitoUserPoolId,
|
|
302
|
+
Username: user.email,
|
|
303
|
+
UserAttributes
|
|
304
|
+
});
|
|
305
|
+
await this.cognito.send(command);
|
|
279
306
|
}
|
|
280
307
|
/**
|
|
281
308
|
* Sign out the user from all devices.
|
|
282
309
|
*/
|
|
283
310
|
async globalSignOut(email, cognitoUserPoolId) {
|
|
284
|
-
|
|
311
|
+
const command = new CognitoIP.AdminUserGlobalSignOutCommand({ Username: email, UserPoolId: cognitoUserPoolId });
|
|
312
|
+
await this.cognito.send(command);
|
|
285
313
|
}
|
|
286
314
|
/**
|
|
287
315
|
* Confirm and conclude a registration, usign a confirmation code.
|
|
@@ -293,9 +321,12 @@ class Cognito {
|
|
|
293
321
|
throw new Error('Invalid confirmation code');
|
|
294
322
|
if (!cognitoUserPoolClientId)
|
|
295
323
|
throw new Error('Invalid client ID');
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
324
|
+
const command = new CognitoIP.ConfirmSignUpCommand({
|
|
325
|
+
Username: email,
|
|
326
|
+
ConfirmationCode: confirmationCode,
|
|
327
|
+
ClientId: cognitoUserPoolClientId
|
|
328
|
+
});
|
|
329
|
+
await this.cognito.send(command);
|
|
299
330
|
}
|
|
300
331
|
/**
|
|
301
332
|
* List the groups of the user pool.
|
|
@@ -304,7 +335,7 @@ class Cognito {
|
|
|
304
335
|
const params = { UserPoolId: cognitoUserPoolId };
|
|
305
336
|
if (options.pagination)
|
|
306
337
|
params.NextToken = options.pagination;
|
|
307
|
-
const res = await this.cognito.
|
|
338
|
+
const res = await this.cognito.send(new CognitoIP.ListGroupsCommand(params));
|
|
308
339
|
const pagination = res.NextToken;
|
|
309
340
|
const groups = options.groups.concat(res.Groups.map(g => ({ name: g.GroupName, description: g.Description })));
|
|
310
341
|
if (pagination)
|
|
@@ -316,13 +347,15 @@ class Cognito {
|
|
|
316
347
|
* Create a new group in the user pool.
|
|
317
348
|
*/
|
|
318
349
|
async createGroup(groupName, cognitoUserPoolId) {
|
|
319
|
-
|
|
350
|
+
const command = new CognitoIP.CreateGroupCommand({ GroupName: groupName, UserPoolId: cognitoUserPoolId });
|
|
351
|
+
await this.cognito.send(command);
|
|
320
352
|
}
|
|
321
353
|
/**
|
|
322
354
|
* Delete a group from the user pool.
|
|
323
355
|
*/
|
|
324
356
|
async deleteGroup(groupName, cognitoUserPoolId) {
|
|
325
|
-
|
|
357
|
+
const command = new CognitoIP.DeleteGroupCommand({ GroupName: groupName, UserPoolId: cognitoUserPoolId });
|
|
358
|
+
await this.cognito.send(command);
|
|
326
359
|
}
|
|
327
360
|
/**
|
|
328
361
|
* List the users part of a group in the user pool.
|
|
@@ -334,7 +367,7 @@ class Cognito {
|
|
|
334
367
|
};
|
|
335
368
|
if (options.pagination)
|
|
336
369
|
params.NextToken = options.pagination;
|
|
337
|
-
const res = await this.cognito.
|
|
370
|
+
const res = await this.cognito.send(new CognitoIP.ListUsersInGroupCommand(params));
|
|
338
371
|
const pagination = res.NextToken;
|
|
339
372
|
const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
|
|
340
373
|
if (pagination)
|
|
@@ -347,18 +380,24 @@ class Cognito {
|
|
|
347
380
|
*/
|
|
348
381
|
async addUserToGroup(email, group, cognitoUserPoolId) {
|
|
349
382
|
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
383
|
+
const command = new CognitoIP.AdminAddUserToGroupCommand({
|
|
384
|
+
UserPoolId: cognitoUserPoolId,
|
|
385
|
+
GroupName: group,
|
|
386
|
+
Username: user.userId
|
|
387
|
+
});
|
|
388
|
+
await this.cognito.send(command);
|
|
353
389
|
}
|
|
354
390
|
/**
|
|
355
391
|
* Remove a user (by email) from a group in the user pool.
|
|
356
392
|
*/
|
|
357
393
|
async removeUserFromGroup(email, group, cognitoUserPoolId) {
|
|
358
394
|
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
395
|
+
const command = new CognitoIP.AdminRemoveUserFromGroupCommand({
|
|
396
|
+
UserPoolId: cognitoUserPoolId,
|
|
397
|
+
GroupName: group,
|
|
398
|
+
Username: user.userId
|
|
399
|
+
});
|
|
400
|
+
await this.cognito.send(command);
|
|
362
401
|
}
|
|
363
402
|
}
|
|
364
403
|
exports.Cognito = Cognito;
|
package/dist/src/comprehend.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as AmazonComprehend from '@aws-sdk/client-comprehend';
|
|
2
2
|
import { Sentiment } from 'idea-toolbox';
|
|
3
3
|
/**
|
|
4
4
|
* A wrapper for Amazon Comprehend.
|
|
@@ -7,7 +7,7 @@ export declare class Comprehend {
|
|
|
7
7
|
/**
|
|
8
8
|
* The instance of Comprehend.
|
|
9
9
|
*/
|
|
10
|
-
protected comprehend: AmazonComprehend;
|
|
10
|
+
protected comprehend: AmazonComprehend.ComprehendClient;
|
|
11
11
|
constructor(params?: {
|
|
12
12
|
region?: string;
|
|
13
13
|
});
|
package/dist/src/comprehend.js
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.Comprehend = void 0;
|
|
4
|
-
const
|
|
27
|
+
const AmazonComprehend = __importStar(require("@aws-sdk/client-comprehend"));
|
|
5
28
|
/**
|
|
6
29
|
* A wrapper for Amazon Comprehend.
|
|
7
30
|
*/
|
|
8
31
|
class Comprehend {
|
|
9
32
|
constructor(params = {}) {
|
|
10
|
-
this.comprehend = new
|
|
33
|
+
this.comprehend = new AmazonComprehend.ComprehendClient({ region: params.region });
|
|
11
34
|
}
|
|
12
35
|
/**
|
|
13
36
|
* Inspects text and returns an inference of the prevailing sentiment (POSITIVE, NEUTRAL, MIXED, or NEGATIVE).
|
|
@@ -15,9 +38,8 @@ class Comprehend {
|
|
|
15
38
|
async detectSentiment(params) {
|
|
16
39
|
if (!params.language || !params.text)
|
|
17
40
|
throw new Error('Missing some parameters');
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
.promise();
|
|
41
|
+
const command = new AmazonComprehend.DetectSentimentCommand({ LanguageCode: params.language, Text: params.text });
|
|
42
|
+
const result = await this.comprehend.send(command);
|
|
21
43
|
return result.Sentiment;
|
|
22
44
|
}
|
|
23
45
|
/**
|
|
@@ -26,7 +48,8 @@ class Comprehend {
|
|
|
26
48
|
async detectDominantLanguage(params) {
|
|
27
49
|
if (!params.text)
|
|
28
50
|
throw new Error('Missing text');
|
|
29
|
-
const
|
|
51
|
+
const command = new AmazonComprehend.DetectDominantLanguageCommand({ Text: params.text });
|
|
52
|
+
const result = await this.comprehend.send(command);
|
|
30
53
|
if (!result.Languages.length)
|
|
31
54
|
throw new Error('Not found');
|
|
32
55
|
return result.Languages[0].LanguageCode;
|