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.
@@ -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
  */
@@ -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['S3_ATTACHMENTS_BUCKET'] || 'idea-attachments';
15
- this.IUID_ATTACHMENTS_PREFIX = process.env['IUID_ATTACHMENTS_PREFIX'] || 'ATT';
16
- this.dynamo = new dynamoDB_1.DynamoDB();
17
- this.s3 = new s3_1.S3();
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('_').concat(project).concat('_').concat(teamId);
24
- const attachmentId = await this.dynamo.IUNID(attachmentIdPrefix);
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;
@@ -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(params?: {
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, cognitoUserPoolId: string): Promise<CognitoUserGeneric>;
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, cognitoUserPoolId: string): Promise<CognitoUserGeneric>;
34
+ getUserBySub(sub: string, userPoolId: string): Promise<CognitoUserGeneric>;
35
35
  /**
36
36
  * List all the users of the pool.
37
37
  */
38
- listUsers(cognitoUserPoolId: string, options?: {
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, cognitoUserPoolId: string, options?: CreateUserOptions): Promise<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, cognitoUserPoolId: string, options?: CreateUserOptions): Promise<void>;
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, cognitoUserPoolId: string, options?: {
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, cognitoUserPoolId: string): Promise<void>;
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, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<CognitoIP.AuthenticationResultType>;
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, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<CognitoIP.AuthenticationResultType>;
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, cognitoUserPoolId: string): Promise<void>;
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, cognitoUserPoolId: string, cognitoUserPoolClientId: string): Promise<void>;
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, cognitoUserPoolClientId: string): Promise<CognitoIP.CodeDeliveryDetailsType>;
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, cognitoUserPoolClientId: string): Promise<void>;
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, cognitoUserPoolId: string): Promise<void>;
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, cognitoUserPoolId: string): Promise<void>;
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, cognitoUserPoolClientId: string): Promise<void>;
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(cognitoUserPoolId: string, options?: {
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, cognitoUserPoolId: string): Promise<void>;
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, cognitoUserPoolId: string): Promise<void>;
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, cognitoUserPoolId: string, options?: {
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, cognitoUserPoolId: string): Promise<void>;
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, cognitoUserPoolId: string): Promise<void>;
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.
@@ -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(params) {
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 || user.UserAttributes || []).forEach((a) => (userAttributes[a.Name] = a.Value));
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, cognitoUserPoolId) {
78
- const command = new CognitoIP.AdminGetUserCommand({ UserPoolId: cognitoUserPoolId, Username: email });
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, cognitoUserPoolId) {
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
- UserPoolId: cognitoUserPoolId,
96
- Filter: `sub = "${sub}"`,
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(user);
100
+ return this.mapCognitoUserAttributesAsPlainObject(Users[0]);
104
101
  }
105
102
  /**
106
103
  * List all the users of the pool.
107
104
  */
108
- async listUsers(cognitoUserPoolId, options = { users: [] }) {
109
- const params = { UserPoolId: cognitoUserPoolId };
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(cognitoUserPoolId, { pagination, users });
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, cognitoUserPoolId, options = {}) {
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, cognitoUserPoolId, options = {}) {
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: cognitoUserPoolId,
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, cognitoUserPoolId, options = {}) {
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: cognitoUserPoolId,
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, cognitoUserPoolId) {
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: cognitoUserPoolId, Username: email });
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, cognitoUserPoolId, cognitoUserPoolClientId) {
218
+ async signIn(email, password, userPoolId, userPoolClientId) {
223
219
  const command = new CognitoIP.AdminInitiateAuthCommand({
224
- UserPoolId: cognitoUserPoolId,
225
- ClientId: cognitoUserPoolClientId,
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, cognitoUserPoolId, cognitoUserPoolClientId) {
233
+ async refreshSession(email, refreshToken, userPoolId, userPoolClientId) {
238
234
  const command = new CognitoIP.AdminInitiateAuthCommand({
239
- UserPoolId: cognitoUserPoolId,
240
- ClientId: cognitoUserPoolClientId,
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, cognitoUserPoolId) {
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: cognitoUserPoolId,
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, cognitoUserPoolId);
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, cognitoUserPoolId, cognitoUserPoolClientId) {
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, cognitoUserPoolId, cognitoUserPoolClientId);
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, cognitoUserPoolClientId) {
285
- const command = new CognitoIP.ForgotPasswordCommand({ Username: email, ClientId: cognitoUserPoolClientId });
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, cognitoUserPoolClientId) {
288
+ async confirmForgotPassword(email, newPassword, confirmationCode, userPoolClientId) {
293
289
  const command = new CognitoIP.ConfirmForgotPasswordCommand({
294
- ClientId: cognitoUserPoolClientId,
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, cognitoUserPoolId) {
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: cognitoUserPoolId,
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, cognitoUserPoolId) {
324
- const command = new CognitoIP.AdminUserGlobalSignOutCommand({ Username: email, UserPoolId: cognitoUserPoolId });
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, cognitoUserPoolClientId) {
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 (!cognitoUserPoolClientId)
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: cognitoUserPoolClientId
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(cognitoUserPoolId, options = { groups: [] }) {
348
- const params = { UserPoolId: cognitoUserPoolId };
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(cognitoUserPoolId, { pagination, groups });
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, cognitoUserPoolId) {
363
- const command = new CognitoIP.CreateGroupCommand({ GroupName: groupName, UserPoolId: cognitoUserPoolId });
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, cognitoUserPoolId) {
370
- const command = new CognitoIP.DeleteGroupCommand({ GroupName: groupName, UserPoolId: cognitoUserPoolId });
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, cognitoUserPoolId, options = { users: [] }) {
372
+ async listUsersInGroup(group, userPoolId, options = { users: [] }) {
377
373
  const params = {
378
- UserPoolId: cognitoUserPoolId,
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, cognitoUserPoolId, { pagination, users });
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, cognitoUserPoolId) {
395
- const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
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: cognitoUserPoolId,
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, cognitoUserPoolId) {
407
- const user = new idea_toolbox_1.CognitoUser(await this.getUserByEmail(email, cognitoUserPoolId));
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: cognitoUserPoolId,
405
+ UserPoolId: userPoolId,
410
406
  GroupName: group,
411
407
  Username: user.userId
412
408
  });
@@ -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(params?: {
8
+ constructor(options?: {
12
9
  region?: string;
13
10
  });
14
11
  /**
@@ -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(params) {
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 result = await this.comprehend.send(command);
44
- return result.Sentiment;
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 result = await this.comprehend.send(command);
54
- if (!result.Languages.length)
52
+ const { Languages } = await this.comprehend.send(command);
53
+ if (!Languages.length)
55
54
  throw new Error('Not found');
56
- return result.Languages[0].LanguageCode;
55
+ return Languages[0].LanguageCode;
57
56
  }
58
57
  }
59
58
  exports.Comprehend = Comprehend;
@@ -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
- logger: Logger;
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 max 10 write operations in a single transaction.
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: {