idea-aws 3.11.7 → 3.12.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/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -33,12 +33,17 @@ export declare class Cognito {
33
33
  */
34
34
  getUserBySub(sub: string, cognitoUserPoolId: string): Promise<CognitoUserGeneric>;
35
35
  /**
36
- * Get all the users of the pool.
36
+ * List all the users of the pool.
37
37
  */
38
- getAllUsers(cognitoUserPoolId: string, options?: {
38
+ listUsers(cognitoUserPoolId: string, options?: {
39
39
  pagination?: string;
40
40
  users: CognitoUser[];
41
41
  }): Promise<CognitoUser[]>;
42
+ /**
43
+ * List all the users of the pool, including the information about the groups they're in.
44
+ * Note: it's slower than the alternative `getAllUsers`: use it only when needed.
45
+ */
46
+ listUsersWithGroupsDetail(cognitoUserPoolId: string): Promise<CognitoUser[]>;
42
47
  /**
43
48
  * Create a new user (by its email) in the pool specified.
44
49
  * @return userId of the new user
@@ -83,7 +88,10 @@ export declare class Cognito {
83
88
  /**
84
89
  * List the groups of the user pool.
85
90
  */
86
- listGroups(cognitoUserPoolId: string): Promise<CognitoGroup[]>;
91
+ listGroups(cognitoUserPoolId: string, options?: {
92
+ pagination?: string;
93
+ groups: CognitoGroup[];
94
+ }): Promise<CognitoGroup[]>;
87
95
  /**
88
96
  * Create a new group in the user pool.
89
97
  */
@@ -95,7 +103,10 @@ export declare class Cognito {
95
103
  /**
96
104
  * List the users part of a group in the user pool.
97
105
  */
98
- listUsersInGroup(group: string, cognitoUserPoolId: string): Promise<CognitoUser[]>;
106
+ listUsersInGroup(group: string, cognitoUserPoolId: string, options?: {
107
+ pagination?: string;
108
+ users: CognitoUser[];
109
+ }): Promise<CognitoUser[]>;
99
110
  /**
100
111
  * Add a user (by email) to a group in the user pool.
101
112
  */
@@ -70,9 +70,9 @@ class Cognito {
70
70
  return this.mapCognitoUserAttributesAsPlainObject(user);
71
71
  }
72
72
  /**
73
- * Get all the users of the pool.
73
+ * List all the users of the pool.
74
74
  */
75
- async getAllUsers(cognitoUserPoolId, options = { users: [] }) {
75
+ async listUsers(cognitoUserPoolId, options = { users: [] }) {
76
76
  const params = { UserPoolId: cognitoUserPoolId };
77
77
  if (options.pagination)
78
78
  params.PaginationToken = options.pagination;
@@ -80,10 +80,31 @@ class Cognito {
80
80
  const pagination = res.PaginationToken;
81
81
  const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
82
82
  if (pagination)
83
- return await this.getAllUsers(cognitoUserPoolId, { pagination, users });
83
+ return await this.listUsers(cognitoUserPoolId, { pagination, users });
84
84
  else
85
85
  return users;
86
86
  }
87
+ /**
88
+ * List all the users of the pool, including the information about the groups they're in.
89
+ * Note: it's slower than the alternative `getAllUsers`: use it only when needed.
90
+ */
91
+ async listUsersWithGroupsDetail(cognitoUserPoolId) {
92
+ const groups = await this.listGroups(cognitoUserPoolId);
93
+ const users = [];
94
+ for (const group of groups) {
95
+ const usersOfGroup = await this.listUsersInGroup(group.name, cognitoUserPoolId);
96
+ usersOfGroup.forEach(userInGroup => {
97
+ const userAlreadyInOutputList = users.find(u => u.userId === userInGroup.userId);
98
+ if (userAlreadyInOutputList)
99
+ userAlreadyInOutputList.groups.push(group.name);
100
+ else {
101
+ userInGroup.groups.push(group.name);
102
+ users.push(userInGroup);
103
+ }
104
+ });
105
+ }
106
+ return users;
107
+ }
87
108
  /**
88
109
  * Create a new user (by its email) in the pool specified.
89
110
  * @return userId of the new user
@@ -250,10 +271,17 @@ class Cognito {
250
271
  /**
251
272
  * List the groups of the user pool.
252
273
  */
253
- async listGroups(cognitoUserPoolId) {
254
- const groupsList = await this.cognito.listGroups({ UserPoolId: cognitoUserPoolId }).promise();
255
- const groups = groupsList.Groups.map(g => ({ name: g.GroupName, description: g.Description }));
256
- return groups;
274
+ async listGroups(cognitoUserPoolId, options = { groups: [] }) {
275
+ const params = { UserPoolId: cognitoUserPoolId };
276
+ if (options.pagination)
277
+ params.NextToken = options.pagination;
278
+ const res = await this.cognito.listGroups(params).promise();
279
+ const pagination = res.NextToken;
280
+ const groups = options.groups.concat(res.Groups.map(g => ({ name: g.GroupName, description: g.Description })));
281
+ if (pagination)
282
+ return await this.listGroups(cognitoUserPoolId, { pagination, groups });
283
+ else
284
+ return groups;
257
285
  }
258
286
  /**
259
287
  * Create a new group in the user pool.
@@ -270,12 +298,20 @@ class Cognito {
270
298
  /**
271
299
  * List the users part of a group in the user pool.
272
300
  */
273
- async listUsersInGroup(group, cognitoUserPoolId) {
274
- const usersInGroupList = await this.cognito
275
- .listUsersInGroup({ UserPoolId: cognitoUserPoolId, GroupName: group })
276
- .promise();
277
- const users = usersInGroupList.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u)));
278
- return users;
301
+ async listUsersInGroup(group, cognitoUserPoolId, options = { users: [] }) {
302
+ const params = {
303
+ UserPoolId: cognitoUserPoolId,
304
+ GroupName: group
305
+ };
306
+ if (options.pagination)
307
+ params.NextToken = options.pagination;
308
+ const res = await this.cognito.listUsersInGroup(params).promise();
309
+ const pagination = res.NextToken;
310
+ const users = options.users.concat(res.Users.map(u => new idea_toolbox_1.CognitoUser(this.mapCognitoUserAttributesAsPlainObject(u))));
311
+ if (pagination)
312
+ return await this.listUsersInGroup(group, cognitoUserPoolId, { pagination, users });
313
+ else
314
+ return users;
279
315
  }
280
316
  /**
281
317
  * Add a user (by email) to a group in the user pool.
@@ -125,12 +125,12 @@ export declare abstract class ResourceController extends GenericController {
125
125
  t(key: string, interpolateParams?: any): string;
126
126
  /**
127
127
  * Interpolates a string to replace parameters.
128
- * "This is a {{ key }}" ==> "This is a value", with params = { key: "value" }
128
+ * `"This is a {{ key }}"` ==> `"This is a value", with params = { key: "value" }`.
129
129
  */
130
130
  private interpolate;
131
131
  /**
132
132
  * Gets a value from an object by composed key.
133
- * getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'
133
+ * `getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA')` ==> `'valueI'`.
134
134
  */
135
135
  private getValue;
136
136
  /**
@@ -379,7 +379,7 @@ class ResourceController extends genericController_1.GenericController {
379
379
  }
380
380
  /**
381
381
  * Interpolates a string to replace parameters.
382
- * "This is a {{ key }}" ==> "This is a value", with params = { key: "value" }
382
+ * `"This is a {{ key }}"` ==> `"This is a value", with params = { key: "value" }`.
383
383
  */
384
384
  interpolate(expr, params) {
385
385
  if (!params || !expr)
@@ -391,7 +391,7 @@ class ResourceController extends genericController_1.GenericController {
391
391
  }
392
392
  /**
393
393
  * Gets a value from an object by composed key.
394
- * getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'
394
+ * `getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA')` ==> `'valueI'`.
395
395
  */
396
396
  getValue(target, key) {
397
397
  const keys = typeof key === 'string' ? key.split('.') : [key];
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.11.7",
3
+ "version": "3.12.0",
4
4
  "description": "AWS wrappers to use in IDEA's back-ends",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "lint": "eslint --ext .ts",
9
9
  "compile": "tsc --build",
10
- "docs": "typedoc",
10
+ "docs": "typedoc index.ts",
11
11
  "build": "./build.sh",
12
12
  "publishPackage": "./build.sh && npm publish"
13
13
  },
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "homepage": "https://iter-idea.github.io/IDEA-AWS",
37
37
  "dependencies": {
38
- "idea-toolbox": "^6.5.16",
38
+ "idea-toolbox": "^6.5.18",
39
39
  "nanoid": "^4.0.0",
40
40
  "nodemailer": "^6.7.5",
41
41
  "shortid": "^2.2.16",
@@ -43,7 +43,7 @@
43
43
  "uuid": "^8.3.2"
44
44
  },
45
45
  "devDependencies": {
46
- "@tsconfig/node14": "^1.0.0",
46
+ "@tsconfig/node16": "^1.0.3",
47
47
  "@types/aws-lambda": "^8.10.91",
48
48
  "@types/node": "^14.14.26",
49
49
  "@types/nodemailer": "^6.4.4",