idea-aws 4.2.1 → 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 +23 -23
- package/dist/src/cognito.js +65 -69
- 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,89 +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
88
|
/**
|
|
89
89
|
* Complete the flow of a password forgot.
|
|
90
90
|
*/
|
|
91
|
-
confirmForgotPassword(email: string, newPassword: string, confirmationCode: string,
|
|
91
|
+
confirmForgotPassword(email: string, newPassword: string, confirmationCode: string, userPoolClientId: string): Promise<void>;
|
|
92
92
|
/**
|
|
93
93
|
* Update a (Cognito)User's attributes, excluding the attributes that require specific methods.
|
|
94
94
|
*/
|
|
95
|
-
updateUser(user: CognitoUser,
|
|
95
|
+
updateUser(user: CognitoUser, userPoolId: string): Promise<void>;
|
|
96
96
|
/**
|
|
97
97
|
* Sign out the user from all devices.
|
|
98
98
|
*/
|
|
99
|
-
globalSignOut(email: string,
|
|
99
|
+
globalSignOut(email: string, userPoolId: string): Promise<void>;
|
|
100
100
|
/**
|
|
101
101
|
* Confirm and conclude a registration, usign a confirmation code.
|
|
102
102
|
*/
|
|
103
|
-
confirmSignUp(email: string, confirmationCode: string,
|
|
103
|
+
confirmSignUp(email: string, confirmationCode: string, userPoolClientId: string): Promise<void>;
|
|
104
104
|
/**
|
|
105
105
|
* List the groups of the user pool.
|
|
106
106
|
*/
|
|
107
|
-
listGroups(
|
|
107
|
+
listGroups(userPoolId: string, options?: {
|
|
108
108
|
pagination?: string;
|
|
109
109
|
groups: CognitoGroup[];
|
|
110
110
|
}): Promise<CognitoGroup[]>;
|
|
111
111
|
/**
|
|
112
112
|
* Create a new group in the user pool.
|
|
113
113
|
*/
|
|
114
|
-
createGroup(groupName: string,
|
|
114
|
+
createGroup(groupName: string, userPoolId: string): Promise<void>;
|
|
115
115
|
/**
|
|
116
116
|
* Delete a group from the user pool.
|
|
117
117
|
*/
|
|
118
|
-
deleteGroup(groupName: string,
|
|
118
|
+
deleteGroup(groupName: string, userPoolId: string): Promise<void>;
|
|
119
119
|
/**
|
|
120
120
|
* List the users part of a group in the user pool.
|
|
121
121
|
*/
|
|
122
|
-
listUsersInGroup(group: string,
|
|
122
|
+
listUsersInGroup(group: string, userPoolId: string, options?: {
|
|
123
123
|
pagination?: string;
|
|
124
124
|
users: CognitoUser[];
|
|
125
125
|
}): Promise<CognitoUser[]>;
|
|
126
126
|
/**
|
|
127
127
|
* Add a user (by email) to a group in the user pool.
|
|
128
128
|
*/
|
|
129
|
-
addUserToGroup(email: string, group: string,
|
|
129
|
+
addUserToGroup(email: string, group: string, userPoolId: string): Promise<void>;
|
|
130
130
|
/**
|
|
131
131
|
* Remove a user (by email) from a group in the user pool.
|
|
132
132
|
*/
|
|
133
|
-
removeUserFromGroup(email: string, group: string,
|
|
133
|
+
removeUserFromGroup(email: string, group: string, userPoolId: string): Promise<void>;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
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,17 +277,17 @@ 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
|
}
|
|
289
285
|
/**
|
|
290
286
|
* Complete the flow of a password forgot.
|
|
291
287
|
*/
|
|
292
|
-
async confirmForgotPassword(email, newPassword, confirmationCode,
|
|
288
|
+
async confirmForgotPassword(email, newPassword, confirmationCode, userPoolClientId) {
|
|
293
289
|
const command = new CognitoIP.ConfirmForgotPasswordCommand({
|
|
294
|
-
ClientId:
|
|
290
|
+
ClientId: userPoolClientId,
|
|
295
291
|
Username: email,
|
|
296
292
|
ConfirmationCode: confirmationCode,
|
|
297
293
|
Password: newPassword
|
|
@@ -301,17 +297,17 @@ class Cognito {
|
|
|
301
297
|
/**
|
|
302
298
|
* Update a (Cognito)User's attributes, excluding the attributes that require specific methods.
|
|
303
299
|
*/
|
|
304
|
-
async updateUser(user,
|
|
300
|
+
async updateUser(user, userPoolId) {
|
|
305
301
|
const UserAttributes = [
|
|
306
302
|
{ Name: 'name', Value: user.name },
|
|
307
|
-
{ Name: 'picture', Value: user.picture
|
|
303
|
+
{ Name: 'picture', Value: user.picture ?? '' }
|
|
308
304
|
];
|
|
309
305
|
Object.keys(user.attributes).forEach(customAttribute => UserAttributes.push({
|
|
310
306
|
Name: 'custom:'.concat(customAttribute),
|
|
311
307
|
Value: String(user.attributes[customAttribute])
|
|
312
308
|
}));
|
|
313
309
|
const command = new CognitoIP.AdminUpdateUserAttributesCommand({
|
|
314
|
-
UserPoolId:
|
|
310
|
+
UserPoolId: userPoolId,
|
|
315
311
|
Username: user.email,
|
|
316
312
|
UserAttributes
|
|
317
313
|
});
|
|
@@ -320,62 +316,62 @@ class Cognito {
|
|
|
320
316
|
/**
|
|
321
317
|
* Sign out the user from all devices.
|
|
322
318
|
*/
|
|
323
|
-
async globalSignOut(email,
|
|
324
|
-
const command = new CognitoIP.AdminUserGlobalSignOutCommand({ Username: email, UserPoolId:
|
|
319
|
+
async globalSignOut(email, userPoolId) {
|
|
320
|
+
const command = new CognitoIP.AdminUserGlobalSignOutCommand({ Username: email, UserPoolId: userPoolId });
|
|
325
321
|
await this.cognito.send(command);
|
|
326
322
|
}
|
|
327
323
|
/**
|
|
328
324
|
* Confirm and conclude a registration, usign a confirmation code.
|
|
329
325
|
*/
|
|
330
|
-
async confirmSignUp(email, confirmationCode,
|
|
326
|
+
async confirmSignUp(email, confirmationCode, userPoolClientId) {
|
|
331
327
|
if (!email)
|
|
332
328
|
throw new Error('Invalid email');
|
|
333
329
|
if (!confirmationCode)
|
|
334
330
|
throw new Error('Invalid confirmation code');
|
|
335
|
-
if (!
|
|
331
|
+
if (!userPoolClientId)
|
|
336
332
|
throw new Error('Invalid client ID');
|
|
337
333
|
const command = new CognitoIP.ConfirmSignUpCommand({
|
|
338
334
|
Username: email,
|
|
339
335
|
ConfirmationCode: confirmationCode,
|
|
340
|
-
ClientId:
|
|
336
|
+
ClientId: userPoolClientId
|
|
341
337
|
});
|
|
342
338
|
await this.cognito.send(command);
|
|
343
339
|
}
|
|
344
340
|
/**
|
|
345
341
|
* List the groups of the user pool.
|
|
346
342
|
*/
|
|
347
|
-
async listGroups(
|
|
348
|
-
const params = { UserPoolId:
|
|
343
|
+
async listGroups(userPoolId, options = { groups: [] }) {
|
|
344
|
+
const params = { UserPoolId: userPoolId };
|
|
349
345
|
if (options.pagination)
|
|
350
346
|
params.NextToken = options.pagination;
|
|
351
347
|
const res = await this.cognito.send(new CognitoIP.ListGroupsCommand(params));
|
|
352
348
|
const pagination = res.NextToken;
|
|
353
349
|
const groups = options.groups.concat(res.Groups.map(g => ({ name: g.GroupName, description: g.Description })));
|
|
354
350
|
if (pagination)
|
|
355
|
-
return await this.listGroups(
|
|
351
|
+
return await this.listGroups(userPoolId, { pagination, groups });
|
|
356
352
|
else
|
|
357
353
|
return groups;
|
|
358
354
|
}
|
|
359
355
|
/**
|
|
360
356
|
* Create a new group in the user pool.
|
|
361
357
|
*/
|
|
362
|
-
async createGroup(groupName,
|
|
363
|
-
const command = new CognitoIP.CreateGroupCommand({ GroupName: groupName, UserPoolId:
|
|
358
|
+
async createGroup(groupName, userPoolId) {
|
|
359
|
+
const command = new CognitoIP.CreateGroupCommand({ GroupName: groupName, UserPoolId: userPoolId });
|
|
364
360
|
await this.cognito.send(command);
|
|
365
361
|
}
|
|
366
362
|
/**
|
|
367
363
|
* Delete a group from the user pool.
|
|
368
364
|
*/
|
|
369
|
-
async deleteGroup(groupName,
|
|
370
|
-
const command = new CognitoIP.DeleteGroupCommand({ GroupName: groupName, UserPoolId:
|
|
365
|
+
async deleteGroup(groupName, userPoolId) {
|
|
366
|
+
const command = new CognitoIP.DeleteGroupCommand({ GroupName: groupName, UserPoolId: userPoolId });
|
|
371
367
|
await this.cognito.send(command);
|
|
372
368
|
}
|
|
373
369
|
/**
|
|
374
370
|
* List the users part of a group in the user pool.
|
|
375
371
|
*/
|
|
376
|
-
async listUsersInGroup(group,
|
|
372
|
+
async listUsersInGroup(group, userPoolId, options = { users: [] }) {
|
|
377
373
|
const params = {
|
|
378
|
-
UserPoolId:
|
|
374
|
+
UserPoolId: userPoolId,
|
|
379
375
|
GroupName: group
|
|
380
376
|
};
|
|
381
377
|
if (options.pagination)
|
|
@@ -384,17 +380,17 @@ class Cognito {
|
|
|
384
380
|
const pagination = res.NextToken;
|
|
385
381
|
const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
|
|
386
382
|
if (pagination)
|
|
387
|
-
return await this.listUsersInGroup(group,
|
|
383
|
+
return await this.listUsersInGroup(group, userPoolId, { pagination, users });
|
|
388
384
|
else
|
|
389
385
|
return users;
|
|
390
386
|
}
|
|
391
387
|
/**
|
|
392
388
|
* Add a user (by email) to a group in the user pool.
|
|
393
389
|
*/
|
|
394
|
-
async addUserToGroup(email, group,
|
|
395
|
-
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));
|
|
396
392
|
const command = new CognitoIP.AdminAddUserToGroupCommand({
|
|
397
|
-
UserPoolId:
|
|
393
|
+
UserPoolId: userPoolId,
|
|
398
394
|
GroupName: group,
|
|
399
395
|
Username: user.userId
|
|
400
396
|
});
|
|
@@ -403,10 +399,10 @@ class Cognito {
|
|
|
403
399
|
/**
|
|
404
400
|
* Remove a user (by email) from a group in the user pool.
|
|
405
401
|
*/
|
|
406
|
-
async removeUserFromGroup(email, group,
|
|
407
|
-
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));
|
|
408
404
|
const command = new CognitoIP.AdminRemoveUserFromGroupCommand({
|
|
409
|
-
UserPoolId:
|
|
405
|
+
UserPoolId: userPoolId,
|
|
410
406
|
GroupName: group,
|
|
411
407
|
Username: user.userId
|
|
412
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: {
|