idea-aws 4.2.0 → 4.3.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/dist/src/attachments.d.ts +5 -8
- package/dist/src/attachments.js +10 -9
- package/dist/src/cognito.d.ts +26 -22
- package/dist/src/cognito.js +75 -67
- package/dist/src/comprehend.d.ts +1 -4
- package/dist/src/comprehend.js +6 -7
- package/dist/src/dynamoDB.d.ts +3 -22
- package/dist/src/dynamoDB.js +36 -85
- package/dist/src/genericController.d.ts +1 -1
- package/dist/src/genericController.js +4 -4
- package/dist/src/logger.d.ts +6 -15
- package/dist/src/logger.js +7 -45
- package/dist/src/metrics.d.ts +1 -1
- package/dist/src/metrics.js +3 -3
- package/dist/src/resourceController.d.ts +3 -2
- package/dist/src/resourceController.js +44 -32
- package/dist/src/s3.d.ts +27 -17
- package/dist/src/s3.js +34 -37
- package/dist/src/secretsManager.d.ts +4 -1
- package/dist/src/secretsManager.js +7 -3
- package/dist/src/ses.d.ts +1 -4
- package/dist/src/ses.js +4 -8
- package/dist/src/sns.d.ts +10 -16
- package/dist/src/sns.js +18 -23
- package/dist/src/ssm.d.ts +8 -2
- package/dist/src/ssm.js +10 -8
- package/dist/src/translate.d.ts +1 -4
- package/dist/src/translate.js +12 -4
- package/package.json +9 -12
|
@@ -5,20 +5,17 @@ import { S3 } from './s3';
|
|
|
5
5
|
* A custom class that takes advantage of DynamoDB and S3 to easily manage attachments.
|
|
6
6
|
*/
|
|
7
7
|
export declare class Attachments {
|
|
8
|
-
|
|
9
|
-
* The instance of DynamoDB.
|
|
10
|
-
*/
|
|
11
|
-
protected dynamo: DynamoDB;
|
|
12
|
-
/**
|
|
13
|
-
* The instance of S3.
|
|
14
|
-
*/
|
|
8
|
+
protected ddb: DynamoDB;
|
|
15
9
|
protected s3: S3;
|
|
16
10
|
/**
|
|
17
11
|
* The bucket where from to retrieve the attachments. Fallback to IDEA's default one.
|
|
18
12
|
*/
|
|
19
13
|
protected S3_ATTACHMENTS_BUCKET: string;
|
|
14
|
+
/**
|
|
15
|
+
* The prefix for attachment IDs. Fallback to IDEA's default one.
|
|
16
|
+
*/
|
|
20
17
|
protected IUID_ATTACHMENTS_PREFIX: string;
|
|
21
|
-
constructor();
|
|
18
|
+
constructor(ddb: DynamoDB, s3: S3);
|
|
22
19
|
/**
|
|
23
20
|
* Get a signedURL to put an attachment.
|
|
24
21
|
*/
|
package/dist/src/attachments.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Attachments = void 0;
|
|
4
|
-
const dynamoDB_1 = require("./dynamoDB");
|
|
5
|
-
const s3_1 = require("./s3");
|
|
6
4
|
/**
|
|
7
5
|
* A custom class that takes advantage of DynamoDB and S3 to easily manage attachments.
|
|
8
6
|
*/
|
|
9
7
|
class Attachments {
|
|
10
|
-
constructor() {
|
|
8
|
+
constructor(ddb, s3) {
|
|
9
|
+
this.ddb = ddb;
|
|
10
|
+
this.s3 = s3;
|
|
11
11
|
/**
|
|
12
12
|
* The bucket where from to retrieve the attachments. Fallback to IDEA's default one.
|
|
13
13
|
*/
|
|
14
|
-
this.S3_ATTACHMENTS_BUCKET = process.env
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
this.S3_ATTACHMENTS_BUCKET = process.env.S3_ATTACHMENTS_BUCKET ?? 'idea-attachments';
|
|
15
|
+
/**
|
|
16
|
+
* The prefix for attachment IDs. Fallback to IDEA's default one.
|
|
17
|
+
*/
|
|
18
|
+
this.IUID_ATTACHMENTS_PREFIX = process.env.IUID_ATTACHMENTS_PREFIX ?? 'ATT';
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Get a signedURL to put an attachment.
|
|
21
22
|
*/
|
|
22
23
|
async put(project, teamId) {
|
|
23
|
-
const attachmentIdPrefix = this.IUID_ATTACHMENTS_PREFIX.concat('_'
|
|
24
|
-
const attachmentId = await this.
|
|
24
|
+
const attachmentIdPrefix = this.IUID_ATTACHMENTS_PREFIX.concat('_', project, '_', teamId);
|
|
25
|
+
const attachmentId = await this.ddb.IUNID(attachmentIdPrefix);
|
|
25
26
|
const signedURL = await this.s3.signedURLPut(this.S3_ATTACHMENTS_BUCKET, attachmentId);
|
|
26
27
|
signedURL.id = attachmentId;
|
|
27
28
|
return signedURL;
|
package/dist/src/cognito.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { CognitoUser } from 'idea-toolbox';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class Cognito {
|
|
7
7
|
protected cognito: CognitoIP.CognitoIdentityProviderClient;
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(options?: {
|
|
9
9
|
region?: string;
|
|
10
10
|
});
|
|
11
11
|
/**
|
|
@@ -27,15 +27,15 @@ export declare class Cognito {
|
|
|
27
27
|
/**
|
|
28
28
|
* Identify a user by its email address, returning its attributes.
|
|
29
29
|
*/
|
|
30
|
-
getUserByEmail(email: string,
|
|
30
|
+
getUserByEmail(email: string, userPoolId: string): Promise<CognitoUserGeneric>;
|
|
31
31
|
/**
|
|
32
32
|
* Identify a user by its userId (sub), returning its attributes.
|
|
33
33
|
*/
|
|
34
|
-
getUserBySub(sub: string,
|
|
34
|
+
getUserBySub(sub: string, userPoolId: string): Promise<CognitoUserGeneric>;
|
|
35
35
|
/**
|
|
36
36
|
* List all the users of the pool.
|
|
37
37
|
*/
|
|
38
|
-
listUsers(
|
|
38
|
+
listUsers(userPoolId: string, options?: {
|
|
39
39
|
pagination?: string;
|
|
40
40
|
users: CognitoUser[];
|
|
41
41
|
}): Promise<CognitoUser[]>;
|
|
@@ -48,85 +48,89 @@ export declare class Cognito {
|
|
|
48
48
|
* Create a new user (by its email) in the pool specified.
|
|
49
49
|
* @return userId of the new user
|
|
50
50
|
*/
|
|
51
|
-
createUser(cognitoUserOrEmail: CognitoUser | string,
|
|
51
|
+
createUser(cognitoUserOrEmail: CognitoUser | string, userPoolId: string, options?: CreateUserOptions): Promise<string>;
|
|
52
52
|
/**
|
|
53
53
|
* Resend the password to a user who never logged in.
|
|
54
54
|
*/
|
|
55
|
-
resendPassword(email: string,
|
|
55
|
+
resendPassword(email: string, userPoolId: string, options?: CreateUserOptions): Promise<void>;
|
|
56
56
|
/**
|
|
57
57
|
* Set a new password for a specific user identified by its email (admin-only).
|
|
58
58
|
* If not specified, the password is generated randomly, and the user must change it at the first login.
|
|
59
59
|
*/
|
|
60
|
-
setPassword(email: string,
|
|
60
|
+
setPassword(email: string, userPoolId: string, options?: {
|
|
61
61
|
password?: string;
|
|
62
62
|
permanent?: boolean;
|
|
63
63
|
}): Promise<void>;
|
|
64
64
|
/**
|
|
65
65
|
* Delete a user by its email (username), in the pool specified.
|
|
66
66
|
*/
|
|
67
|
-
deleteUser(email: string,
|
|
67
|
+
deleteUser(email: string, userPoolId: string): Promise<void>;
|
|
68
68
|
/**
|
|
69
69
|
* Sign in a user of a specific pool through username and password.
|
|
70
70
|
*/
|
|
71
|
-
signIn(email: string, password: string,
|
|
71
|
+
signIn(email: string, password: string, userPoolId: string, userPoolClientId: 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,
|
|
75
|
+
refreshSession(email: string, refreshToken: string, userPoolId: string, userPoolClientId: string): Promise<CognitoIP.AuthenticationResultType>;
|
|
76
76
|
/**
|
|
77
77
|
* Change the email address (== username) associated to a user.
|
|
78
78
|
*/
|
|
79
|
-
updateEmail(email: string, newEmail: string,
|
|
79
|
+
updateEmail(email: string, newEmail: string, userPoolId: string): Promise<void>;
|
|
80
80
|
/**
|
|
81
81
|
* Change the password to sign in for a user.
|
|
82
82
|
*/
|
|
83
|
-
updatePassword(email: string, oldPassword: string, newPassword: string,
|
|
83
|
+
updatePassword(email: string, oldPassword: string, newPassword: string, userPoolId: string, userPoolClientId: string): Promise<void>;
|
|
84
84
|
/**
|
|
85
85
|
* Send to a user the instructions to change the password.
|
|
86
86
|
*/
|
|
87
|
-
forgotPassword(email: string,
|
|
87
|
+
forgotPassword(email: string, userPoolClientId: string): Promise<CognitoIP.CodeDeliveryDetailsType>;
|
|
88
|
+
/**
|
|
89
|
+
* Complete the flow of a password forgot.
|
|
90
|
+
*/
|
|
91
|
+
confirmForgotPassword(email: string, newPassword: string, confirmationCode: string, userPoolClientId: string): Promise<void>;
|
|
88
92
|
/**
|
|
89
93
|
* Update a (Cognito)User's attributes, excluding the attributes that require specific methods.
|
|
90
94
|
*/
|
|
91
|
-
updateUser(user: CognitoUser,
|
|
95
|
+
updateUser(user: CognitoUser, userPoolId: string): Promise<void>;
|
|
92
96
|
/**
|
|
93
97
|
* Sign out the user from all devices.
|
|
94
98
|
*/
|
|
95
|
-
globalSignOut(email: string,
|
|
99
|
+
globalSignOut(email: string, userPoolId: string): Promise<void>;
|
|
96
100
|
/**
|
|
97
101
|
* Confirm and conclude a registration, usign a confirmation code.
|
|
98
102
|
*/
|
|
99
|
-
confirmSignUp(email: string, confirmationCode: string,
|
|
103
|
+
confirmSignUp(email: string, confirmationCode: string, userPoolClientId: string): Promise<void>;
|
|
100
104
|
/**
|
|
101
105
|
* List the groups of the user pool.
|
|
102
106
|
*/
|
|
103
|
-
listGroups(
|
|
107
|
+
listGroups(userPoolId: string, options?: {
|
|
104
108
|
pagination?: string;
|
|
105
109
|
groups: CognitoGroup[];
|
|
106
110
|
}): Promise<CognitoGroup[]>;
|
|
107
111
|
/**
|
|
108
112
|
* Create a new group in the user pool.
|
|
109
113
|
*/
|
|
110
|
-
createGroup(groupName: string,
|
|
114
|
+
createGroup(groupName: string, userPoolId: string): Promise<void>;
|
|
111
115
|
/**
|
|
112
116
|
* Delete a group from the user pool.
|
|
113
117
|
*/
|
|
114
|
-
deleteGroup(groupName: string,
|
|
118
|
+
deleteGroup(groupName: string, userPoolId: string): Promise<void>;
|
|
115
119
|
/**
|
|
116
120
|
* List the users part of a group in the user pool.
|
|
117
121
|
*/
|
|
118
|
-
listUsersInGroup(group: string,
|
|
122
|
+
listUsersInGroup(group: string, userPoolId: string, options?: {
|
|
119
123
|
pagination?: string;
|
|
120
124
|
users: CognitoUser[];
|
|
121
125
|
}): Promise<CognitoUser[]>;
|
|
122
126
|
/**
|
|
123
127
|
* Add a user (by email) to a group in the user pool.
|
|
124
128
|
*/
|
|
125
|
-
addUserToGroup(email: string, group: string,
|
|
129
|
+
addUserToGroup(email: string, group: string, userPoolId: string): Promise<void>;
|
|
126
130
|
/**
|
|
127
131
|
* Remove a user (by email) from a group in the user pool.
|
|
128
132
|
*/
|
|
129
|
-
removeUserFromGroup(email: string, group: string,
|
|
133
|
+
removeUserFromGroup(email: string, group: string, userPoolId: string): Promise<void>;
|
|
130
134
|
}
|
|
131
135
|
/**
|
|
132
136
|
* The attributes of a generic Cognito user of which we don't know the custom attributes.
|
package/dist/src/cognito.js
CHANGED
|
@@ -30,8 +30,7 @@ const idea_toolbox_1 = require("idea-toolbox");
|
|
|
30
30
|
* A wrapper for AWS Cognito.
|
|
31
31
|
*/
|
|
32
32
|
class Cognito {
|
|
33
|
-
constructor(
|
|
34
|
-
const options = Object.assign({}, params);
|
|
33
|
+
constructor(options = {}) {
|
|
35
34
|
this.cognito = new CognitoIP.CognitoIdentityProviderClient({ region: options.region });
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
@@ -66,16 +65,19 @@ class Cognito {
|
|
|
66
65
|
*/
|
|
67
66
|
mapCognitoUserAttributesAsPlainObject(user) {
|
|
68
67
|
const userAttributes = {};
|
|
69
|
-
(user.Attributes
|
|
68
|
+
(user.Attributes ?? user.UserAttributes ?? []).forEach((a) => (userAttributes[a.Name] = a.Value));
|
|
70
69
|
if (!userAttributes.userId)
|
|
71
70
|
userAttributes.userId = userAttributes.sub;
|
|
72
71
|
return userAttributes;
|
|
73
72
|
}
|
|
73
|
+
//
|
|
74
|
+
// ADMIN
|
|
75
|
+
//
|
|
74
76
|
/**
|
|
75
77
|
* Identify a user by its email address, returning its attributes.
|
|
76
78
|
*/
|
|
77
|
-
async getUserByEmail(email,
|
|
78
|
-
const command = new CognitoIP.AdminGetUserCommand({ UserPoolId:
|
|
79
|
+
async getUserByEmail(email, userPoolId) {
|
|
80
|
+
const command = new CognitoIP.AdminGetUserCommand({ UserPoolId: userPoolId, Username: email });
|
|
79
81
|
try {
|
|
80
82
|
const user = await this.cognito.send(command);
|
|
81
83
|
return this.mapCognitoUserAttributesAsPlainObject(user);
|
|
@@ -89,30 +91,25 @@ class Cognito {
|
|
|
89
91
|
/**
|
|
90
92
|
* Identify a user by its userId (sub), returning its attributes.
|
|
91
93
|
*/
|
|
92
|
-
async getUserBySub(sub,
|
|
94
|
+
async getUserBySub(sub, userPoolId) {
|
|
93
95
|
// 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
|
|
94
|
-
const command = new CognitoIP.ListUsersCommand({
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
Limit: 1
|
|
98
|
-
});
|
|
99
|
-
const usersList = await this.cognito.send(command);
|
|
100
|
-
const user = usersList?.Users[0];
|
|
101
|
-
if (!user)
|
|
96
|
+
const command = new CognitoIP.ListUsersCommand({ UserPoolId: userPoolId, Filter: `sub = "${sub}"`, Limit: 1 });
|
|
97
|
+
const { Users } = await this.cognito.send(command);
|
|
98
|
+
if (Users.length < 1)
|
|
102
99
|
throw new Error('User not found');
|
|
103
|
-
return this.mapCognitoUserAttributesAsPlainObject(
|
|
100
|
+
return this.mapCognitoUserAttributesAsPlainObject(Users[0]);
|
|
104
101
|
}
|
|
105
102
|
/**
|
|
106
103
|
* List all the users of the pool.
|
|
107
104
|
*/
|
|
108
|
-
async listUsers(
|
|
109
|
-
const params = { UserPoolId:
|
|
105
|
+
async listUsers(userPoolId, options = { users: [] }) {
|
|
106
|
+
const params = { UserPoolId: userPoolId };
|
|
110
107
|
if (options.pagination)
|
|
111
108
|
params.PaginationToken = options.pagination;
|
|
112
109
|
const { Users, PaginationToken: pagination } = await this.cognito.send(new CognitoIP.ListUsersCommand(params));
|
|
113
110
|
const users = options.users.concat(Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
|
|
114
111
|
if (pagination)
|
|
115
|
-
return await this.listUsers(
|
|
112
|
+
return await this.listUsers(userPoolId, { pagination, users });
|
|
116
113
|
else
|
|
117
114
|
return users;
|
|
118
115
|
}
|
|
@@ -141,7 +138,7 @@ class Cognito {
|
|
|
141
138
|
* Create a new user (by its email) in the pool specified.
|
|
142
139
|
* @return userId of the new user
|
|
143
140
|
*/
|
|
144
|
-
async createUser(cognitoUserOrEmail,
|
|
141
|
+
async createUser(cognitoUserOrEmail, userPoolId, options = {}) {
|
|
145
142
|
const email = typeof cognitoUserOrEmail === 'string'
|
|
146
143
|
? cognitoUserOrEmail
|
|
147
144
|
: cognitoUserOrEmail.email;
|
|
@@ -157,11 +154,7 @@ class Cognito {
|
|
|
157
154
|
UserAttributes.push({ Name: 'picture', Value: user.picture || '' });
|
|
158
155
|
Object.keys(user.attributes).forEach(a => UserAttributes.push({ Name: 'custom:'.concat(a), Value: String(user.attributes[a]) }));
|
|
159
156
|
}
|
|
160
|
-
const params = {
|
|
161
|
-
UserPoolId: cognitoUserPoolId,
|
|
162
|
-
Username: email,
|
|
163
|
-
UserAttributes
|
|
164
|
-
};
|
|
157
|
+
const params = { UserPoolId: userPoolId, Username: email, UserAttributes };
|
|
165
158
|
if (options.skipNotification)
|
|
166
159
|
params.MessageAction = 'SUPPRESS';
|
|
167
160
|
if (options.temporaryPassword)
|
|
@@ -175,11 +168,11 @@ class Cognito {
|
|
|
175
168
|
/**
|
|
176
169
|
* Resend the password to a user who never logged in.
|
|
177
170
|
*/
|
|
178
|
-
async resendPassword(email,
|
|
171
|
+
async resendPassword(email, userPoolId, options = {}) {
|
|
179
172
|
if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
|
|
180
173
|
throw new Error('Invalid email');
|
|
181
174
|
const params = {
|
|
182
|
-
UserPoolId:
|
|
175
|
+
UserPoolId: userPoolId,
|
|
183
176
|
Username: email,
|
|
184
177
|
MessageAction: 'RESEND'
|
|
185
178
|
};
|
|
@@ -191,7 +184,7 @@ class Cognito {
|
|
|
191
184
|
* Set a new password for a specific user identified by its email (admin-only).
|
|
192
185
|
* If not specified, the password is generated randomly, and the user must change it at the first login.
|
|
193
186
|
*/
|
|
194
|
-
async setPassword(email,
|
|
187
|
+
async setPassword(email, userPoolId, options = {}) {
|
|
195
188
|
if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
|
|
196
189
|
throw new Error('Invalid email');
|
|
197
190
|
const RANDOM_PASSWORD_LENGTH = 8;
|
|
@@ -200,7 +193,7 @@ class Cognito {
|
|
|
200
193
|
.toString(36)
|
|
201
194
|
.slice(2, 2 + RANDOM_PASSWORD_LENGTH);
|
|
202
195
|
const params = {
|
|
203
|
-
UserPoolId:
|
|
196
|
+
UserPoolId: userPoolId,
|
|
204
197
|
Username: email,
|
|
205
198
|
Password: password,
|
|
206
199
|
Permanent: options.permanent
|
|
@@ -210,19 +203,22 @@ class Cognito {
|
|
|
210
203
|
/**
|
|
211
204
|
* Delete a user by its email (username), in the pool specified.
|
|
212
205
|
*/
|
|
213
|
-
async deleteUser(email,
|
|
206
|
+
async deleteUser(email, userPoolId) {
|
|
214
207
|
if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
|
|
215
208
|
throw new Error('Invalid email');
|
|
216
|
-
const command = new CognitoIP.AdminDeleteUserCommand({ UserPoolId:
|
|
209
|
+
const command = new CognitoIP.AdminDeleteUserCommand({ UserPoolId: userPoolId, Username: email });
|
|
217
210
|
await this.cognito.send(command);
|
|
218
211
|
}
|
|
212
|
+
//
|
|
213
|
+
// USER
|
|
214
|
+
//
|
|
219
215
|
/**
|
|
220
216
|
* Sign in a user of a specific pool through username and password.
|
|
221
217
|
*/
|
|
222
|
-
async signIn(email, password,
|
|
218
|
+
async signIn(email, password, userPoolId, userPoolClientId) {
|
|
223
219
|
const command = new CognitoIP.AdminInitiateAuthCommand({
|
|
224
|
-
UserPoolId:
|
|
225
|
-
ClientId:
|
|
220
|
+
UserPoolId: userPoolId,
|
|
221
|
+
ClientId: userPoolClientId,
|
|
226
222
|
AuthFlow: 'ADMIN_NO_SRP_AUTH',
|
|
227
223
|
AuthParameters: { USERNAME: email, PASSWORD: password }
|
|
228
224
|
});
|
|
@@ -234,10 +230,10 @@ class Cognito {
|
|
|
234
230
|
/**
|
|
235
231
|
* Given a username and a refresh token (and pool data), refresh the session and return the new tokens.
|
|
236
232
|
*/
|
|
237
|
-
async refreshSession(email, refreshToken,
|
|
233
|
+
async refreshSession(email, refreshToken, userPoolId, userPoolClientId) {
|
|
238
234
|
const command = new CognitoIP.AdminInitiateAuthCommand({
|
|
239
|
-
UserPoolId:
|
|
240
|
-
ClientId:
|
|
235
|
+
UserPoolId: userPoolId,
|
|
236
|
+
ClientId: userPoolClientId,
|
|
241
237
|
AuthFlow: 'REFRESH_TOKEN_AUTH',
|
|
242
238
|
AuthParameters: { USERNAME: email, REFRESH_TOKEN: refreshToken }
|
|
243
239
|
});
|
|
@@ -249,11 +245,11 @@ class Cognito {
|
|
|
249
245
|
/**
|
|
250
246
|
* Change the email address (== username) associated to a user.
|
|
251
247
|
*/
|
|
252
|
-
async updateEmail(email, newEmail,
|
|
248
|
+
async updateEmail(email, newEmail, userPoolId) {
|
|
253
249
|
if ((0, idea_toolbox_1.isEmpty)(newEmail, 'email'))
|
|
254
250
|
throw new Error('Invalid new email');
|
|
255
251
|
const command = new CognitoIP.AdminUpdateUserAttributesCommand({
|
|
256
|
-
UserPoolId:
|
|
252
|
+
UserPoolId: userPoolId,
|
|
257
253
|
Username: email,
|
|
258
254
|
UserAttributes: [
|
|
259
255
|
{ Name: 'email', Value: newEmail },
|
|
@@ -262,15 +258,15 @@ class Cognito {
|
|
|
262
258
|
});
|
|
263
259
|
await this.cognito.send(command);
|
|
264
260
|
// sign out the user from all its devices and resolve
|
|
265
|
-
await this.globalSignOut(newEmail,
|
|
261
|
+
await this.globalSignOut(newEmail, userPoolId);
|
|
266
262
|
}
|
|
267
263
|
/**
|
|
268
264
|
* Change the password to sign in for a user.
|
|
269
265
|
*/
|
|
270
|
-
async updatePassword(email, oldPassword, newPassword,
|
|
266
|
+
async updatePassword(email, oldPassword, newPassword, userPoolId, userPoolClientId) {
|
|
271
267
|
if (newPassword.length < 8)
|
|
272
268
|
throw new Error('Invalid new password');
|
|
273
|
-
const tokensForPasswordChange = await this.signIn(email, oldPassword,
|
|
269
|
+
const tokensForPasswordChange = await this.signIn(email, oldPassword, userPoolId, userPoolClientId);
|
|
274
270
|
const command = new CognitoIP.ChangePasswordCommand({
|
|
275
271
|
AccessToken: tokensForPasswordChange.AccessToken,
|
|
276
272
|
PreviousPassword: oldPassword,
|
|
@@ -281,25 +277,37 @@ class Cognito {
|
|
|
281
277
|
/**
|
|
282
278
|
* Send to a user the instructions to change the password.
|
|
283
279
|
*/
|
|
284
|
-
async forgotPassword(email,
|
|
285
|
-
const command = new CognitoIP.ForgotPasswordCommand({ Username: email, ClientId:
|
|
280
|
+
async forgotPassword(email, userPoolClientId) {
|
|
281
|
+
const command = new CognitoIP.ForgotPasswordCommand({ Username: email, ClientId: userPoolClientId });
|
|
286
282
|
const { CodeDeliveryDetails } = await this.cognito.send(command);
|
|
287
283
|
return CodeDeliveryDetails;
|
|
288
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* Complete the flow of a password forgot.
|
|
287
|
+
*/
|
|
288
|
+
async confirmForgotPassword(email, newPassword, confirmationCode, userPoolClientId) {
|
|
289
|
+
const command = new CognitoIP.ConfirmForgotPasswordCommand({
|
|
290
|
+
ClientId: userPoolClientId,
|
|
291
|
+
Username: email,
|
|
292
|
+
ConfirmationCode: confirmationCode,
|
|
293
|
+
Password: newPassword
|
|
294
|
+
});
|
|
295
|
+
await this.cognito.send(command);
|
|
296
|
+
}
|
|
289
297
|
/**
|
|
290
298
|
* Update a (Cognito)User's attributes, excluding the attributes that require specific methods.
|
|
291
299
|
*/
|
|
292
|
-
async updateUser(user,
|
|
300
|
+
async updateUser(user, userPoolId) {
|
|
293
301
|
const UserAttributes = [
|
|
294
302
|
{ Name: 'name', Value: user.name },
|
|
295
|
-
{ Name: 'picture', Value: user.picture
|
|
303
|
+
{ Name: 'picture', Value: user.picture ?? '' }
|
|
296
304
|
];
|
|
297
305
|
Object.keys(user.attributes).forEach(customAttribute => UserAttributes.push({
|
|
298
306
|
Name: 'custom:'.concat(customAttribute),
|
|
299
307
|
Value: String(user.attributes[customAttribute])
|
|
300
308
|
}));
|
|
301
309
|
const command = new CognitoIP.AdminUpdateUserAttributesCommand({
|
|
302
|
-
UserPoolId:
|
|
310
|
+
UserPoolId: userPoolId,
|
|
303
311
|
Username: user.email,
|
|
304
312
|
UserAttributes
|
|
305
313
|
});
|
|
@@ -308,62 +316,62 @@ class Cognito {
|
|
|
308
316
|
/**
|
|
309
317
|
* Sign out the user from all devices.
|
|
310
318
|
*/
|
|
311
|
-
async globalSignOut(email,
|
|
312
|
-
const command = new CognitoIP.AdminUserGlobalSignOutCommand({ Username: email, UserPoolId:
|
|
319
|
+
async globalSignOut(email, userPoolId) {
|
|
320
|
+
const command = new CognitoIP.AdminUserGlobalSignOutCommand({ Username: email, UserPoolId: userPoolId });
|
|
313
321
|
await this.cognito.send(command);
|
|
314
322
|
}
|
|
315
323
|
/**
|
|
316
324
|
* Confirm and conclude a registration, usign a confirmation code.
|
|
317
325
|
*/
|
|
318
|
-
async confirmSignUp(email, confirmationCode,
|
|
326
|
+
async confirmSignUp(email, confirmationCode, userPoolClientId) {
|
|
319
327
|
if (!email)
|
|
320
328
|
throw new Error('Invalid email');
|
|
321
329
|
if (!confirmationCode)
|
|
322
330
|
throw new Error('Invalid confirmation code');
|
|
323
|
-
if (!
|
|
331
|
+
if (!userPoolClientId)
|
|
324
332
|
throw new Error('Invalid client ID');
|
|
325
333
|
const command = new CognitoIP.ConfirmSignUpCommand({
|
|
326
334
|
Username: email,
|
|
327
335
|
ConfirmationCode: confirmationCode,
|
|
328
|
-
ClientId:
|
|
336
|
+
ClientId: userPoolClientId
|
|
329
337
|
});
|
|
330
338
|
await this.cognito.send(command);
|
|
331
339
|
}
|
|
332
340
|
/**
|
|
333
341
|
* List the groups of the user pool.
|
|
334
342
|
*/
|
|
335
|
-
async listGroups(
|
|
336
|
-
const params = { UserPoolId:
|
|
343
|
+
async listGroups(userPoolId, options = { groups: [] }) {
|
|
344
|
+
const params = { UserPoolId: userPoolId };
|
|
337
345
|
if (options.pagination)
|
|
338
346
|
params.NextToken = options.pagination;
|
|
339
347
|
const res = await this.cognito.send(new CognitoIP.ListGroupsCommand(params));
|
|
340
348
|
const pagination = res.NextToken;
|
|
341
349
|
const groups = options.groups.concat(res.Groups.map(g => ({ name: g.GroupName, description: g.Description })));
|
|
342
350
|
if (pagination)
|
|
343
|
-
return await this.listGroups(
|
|
351
|
+
return await this.listGroups(userPoolId, { pagination, groups });
|
|
344
352
|
else
|
|
345
353
|
return groups;
|
|
346
354
|
}
|
|
347
355
|
/**
|
|
348
356
|
* Create a new group in the user pool.
|
|
349
357
|
*/
|
|
350
|
-
async createGroup(groupName,
|
|
351
|
-
const command = new CognitoIP.CreateGroupCommand({ GroupName: groupName, UserPoolId:
|
|
358
|
+
async createGroup(groupName, userPoolId) {
|
|
359
|
+
const command = new CognitoIP.CreateGroupCommand({ GroupName: groupName, UserPoolId: userPoolId });
|
|
352
360
|
await this.cognito.send(command);
|
|
353
361
|
}
|
|
354
362
|
/**
|
|
355
363
|
* Delete a group from the user pool.
|
|
356
364
|
*/
|
|
357
|
-
async deleteGroup(groupName,
|
|
358
|
-
const command = new CognitoIP.DeleteGroupCommand({ GroupName: groupName, UserPoolId:
|
|
365
|
+
async deleteGroup(groupName, userPoolId) {
|
|
366
|
+
const command = new CognitoIP.DeleteGroupCommand({ GroupName: groupName, UserPoolId: userPoolId });
|
|
359
367
|
await this.cognito.send(command);
|
|
360
368
|
}
|
|
361
369
|
/**
|
|
362
370
|
* List the users part of a group in the user pool.
|
|
363
371
|
*/
|
|
364
|
-
async listUsersInGroup(group,
|
|
372
|
+
async listUsersInGroup(group, userPoolId, options = { users: [] }) {
|
|
365
373
|
const params = {
|
|
366
|
-
UserPoolId:
|
|
374
|
+
UserPoolId: userPoolId,
|
|
367
375
|
GroupName: group
|
|
368
376
|
};
|
|
369
377
|
if (options.pagination)
|
|
@@ -372,17 +380,17 @@ class Cognito {
|
|
|
372
380
|
const pagination = res.NextToken;
|
|
373
381
|
const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
|
|
374
382
|
if (pagination)
|
|
375
|
-
return await this.listUsersInGroup(group,
|
|
383
|
+
return await this.listUsersInGroup(group, userPoolId, { pagination, users });
|
|
376
384
|
else
|
|
377
385
|
return users;
|
|
378
386
|
}
|
|
379
387
|
/**
|
|
380
388
|
* Add a user (by email) to a group in the user pool.
|
|
381
389
|
*/
|
|
382
|
-
async addUserToGroup(email, group,
|
|
383
|
-
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email,
|
|
390
|
+
async addUserToGroup(email, group, userPoolId) {
|
|
391
|
+
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, userPoolId));
|
|
384
392
|
const command = new CognitoIP.AdminAddUserToGroupCommand({
|
|
385
|
-
UserPoolId:
|
|
393
|
+
UserPoolId: userPoolId,
|
|
386
394
|
GroupName: group,
|
|
387
395
|
Username: user.userId
|
|
388
396
|
});
|
|
@@ -391,10 +399,10 @@ class Cognito {
|
|
|
391
399
|
/**
|
|
392
400
|
* Remove a user (by email) from a group in the user pool.
|
|
393
401
|
*/
|
|
394
|
-
async removeUserFromGroup(email, group,
|
|
395
|
-
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email,
|
|
402
|
+
async removeUserFromGroup(email, group, userPoolId) {
|
|
403
|
+
const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, userPoolId));
|
|
396
404
|
const command = new CognitoIP.AdminRemoveUserFromGroupCommand({
|
|
397
|
-
UserPoolId:
|
|
405
|
+
UserPoolId: userPoolId,
|
|
398
406
|
GroupName: group,
|
|
399
407
|
Username: user.userId
|
|
400
408
|
});
|
package/dist/src/comprehend.d.ts
CHANGED
|
@@ -4,11 +4,8 @@ import { Sentiment } from 'idea-toolbox';
|
|
|
4
4
|
* A wrapper for Amazon Comprehend.
|
|
5
5
|
*/
|
|
6
6
|
export declare class Comprehend {
|
|
7
|
-
/**
|
|
8
|
-
* The instance of Comprehend.
|
|
9
|
-
*/
|
|
10
7
|
protected comprehend: AmazonComprehend.ComprehendClient;
|
|
11
|
-
constructor(
|
|
8
|
+
constructor(options?: {
|
|
12
9
|
region?: string;
|
|
13
10
|
});
|
|
14
11
|
/**
|
package/dist/src/comprehend.js
CHANGED
|
@@ -29,8 +29,7 @@ const AmazonComprehend = __importStar(require("@aws-sdk/client-comprehend"));
|
|
|
29
29
|
* A wrapper for Amazon Comprehend.
|
|
30
30
|
*/
|
|
31
31
|
class Comprehend {
|
|
32
|
-
constructor(
|
|
33
|
-
const options = Object.assign({}, params);
|
|
32
|
+
constructor(options = {}) {
|
|
34
33
|
this.comprehend = new AmazonComprehend.ComprehendClient({ region: options.region });
|
|
35
34
|
}
|
|
36
35
|
/**
|
|
@@ -40,8 +39,8 @@ class Comprehend {
|
|
|
40
39
|
if (!params.language || !params.text)
|
|
41
40
|
throw new Error('Missing some parameters');
|
|
42
41
|
const command = new AmazonComprehend.DetectSentimentCommand({ LanguageCode: params.language, Text: params.text });
|
|
43
|
-
const
|
|
44
|
-
return
|
|
42
|
+
const { Sentiment } = await this.comprehend.send(command);
|
|
43
|
+
return Sentiment;
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
47
46
|
* Determines the dominant language of the input text.
|
|
@@ -50,10 +49,10 @@ class Comprehend {
|
|
|
50
49
|
if (!params.text)
|
|
51
50
|
throw new Error('Missing text');
|
|
52
51
|
const command = new AmazonComprehend.DetectDominantLanguageCommand({ Text: params.text });
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
52
|
+
const { Languages } = await this.comprehend.send(command);
|
|
53
|
+
if (!Languages.length)
|
|
55
54
|
throw new Error('Not found');
|
|
56
|
-
return
|
|
55
|
+
return Languages[0].LanguageCode;
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
exports.Comprehend = Comprehend;
|
package/dist/src/dynamoDB.d.ts
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import * as DDB from '@aws-sdk/lib-dynamodb';
|
|
2
2
|
import * as DDBUtils from '@aws-sdk/util-dynamodb';
|
|
3
|
-
import { Logger } from './logger';
|
|
4
3
|
/**
|
|
5
4
|
* A wrapper for AWS DynamoDB.
|
|
6
5
|
*/
|
|
7
6
|
export declare class DynamoDB {
|
|
8
7
|
protected dynamo: DDB.DynamoDBDocument;
|
|
9
|
-
|
|
10
|
-
constructor(params?: {
|
|
11
|
-
debug?: boolean;
|
|
12
|
-
});
|
|
8
|
+
constructor();
|
|
13
9
|
/**
|
|
14
10
|
* Convert a JSON object from DynamoDB format to simple JSON.
|
|
15
11
|
* @data the data in DynamoDB's original format to convert in plain objects
|
|
16
12
|
* @options the options to use to convert the data
|
|
17
13
|
*/
|
|
18
14
|
unmarshall(data: Record<string, any>, options?: DDBUtils.unmarshallOptions): Record<string, any>;
|
|
19
|
-
/**
|
|
20
|
-
* Returns an IUID: IDEA's Unique IDentifier, which is an id unique through an IDEA's AWS account and region.
|
|
21
|
-
* Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
|
|
22
|
-
* @deprecated use IUNID instead (nano version)
|
|
23
|
-
* @param project project code
|
|
24
|
-
* @return the IUID
|
|
25
|
-
*/
|
|
26
|
-
IUID(project: string): Promise<string>;
|
|
27
15
|
/**
|
|
28
16
|
* Returns an IUNID: IDEA's Unique Nano IDentifier, which is an id unique through an IDEA's AWS account and region.
|
|
29
17
|
* Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
|
|
@@ -31,14 +19,7 @@ export declare class DynamoDB {
|
|
|
31
19
|
* @return the IUNID
|
|
32
20
|
*/
|
|
33
21
|
IUNID(project: string): Promise<string>;
|
|
34
|
-
|
|
35
|
-
* Returns an ISID: IDEA's Short IDentifier, which is a short, unique id intended to be used in small namespaces.
|
|
36
|
-
* Note: no need of an auth check for external uses: the permissions depend from the context in which it's executed.
|
|
37
|
-
* @param project project code
|
|
38
|
-
* @return the ISID
|
|
39
|
-
*/
|
|
40
|
-
ISID(project: string): Promise<string>;
|
|
41
|
-
protected identifiersGeneratorHelper(project: string, type: 'IUNID' | 'IUID' | 'ISID', attempt: number, maxAttempts: number): Promise<string>;
|
|
22
|
+
protected IUNIDHelper(project: string, attempt: number, maxAttempts: number): Promise<string>;
|
|
42
23
|
/**
|
|
43
24
|
* Manage atomic counters (atomic autoincrement values) in IDEA's projects.
|
|
44
25
|
* They key of an atomic counter should be composed as the following: `DynamoDBTableName_uniqueKey`.
|
|
@@ -113,7 +94,7 @@ export declare class DynamoDB {
|
|
|
113
94
|
*/
|
|
114
95
|
scanClassic(params: DDB.ScanCommandInput): Promise<DDB.ScanCommandOutput>;
|
|
115
96
|
/**
|
|
116
|
-
* Execute a series of
|
|
97
|
+
* Execute a series of write operations in a single transaction.
|
|
117
98
|
* @param ops the operations to execute in the transaction
|
|
118
99
|
*/
|
|
119
100
|
transactWrites(ops: {
|