idea-aws 3.11.9 → 3.13.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/cognito.d.ts +15 -4
- package/dist/src/cognito.js +49 -13
- package/package.json +12 -12
package/dist/src/cognito.d.ts
CHANGED
|
@@ -33,12 +33,17 @@ export declare class Cognito {
|
|
|
33
33
|
*/
|
|
34
34
|
getUserBySub(sub: string, cognitoUserPoolId: string): Promise<CognitoUserGeneric>;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* List all the users of the pool.
|
|
37
37
|
*/
|
|
38
|
-
|
|
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
|
|
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
|
|
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
|
*/
|
package/dist/src/cognito.js
CHANGED
|
@@ -70,9 +70,9 @@ class Cognito {
|
|
|
70
70
|
return this.mapCognitoUserAttributesAsPlainObject(user);
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
*
|
|
73
|
+
* List all the users of the pool.
|
|
74
74
|
*/
|
|
75
|
-
async
|
|
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.
|
|
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
|
|
255
|
-
|
|
256
|
-
|
|
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
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idea-aws",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.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",
|
|
@@ -35,25 +35,25 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://iter-idea.github.io/IDEA-AWS",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"idea-toolbox": "^6.5.
|
|
39
|
-
"nanoid": "^
|
|
40
|
-
"nodemailer": "^6.7.
|
|
38
|
+
"idea-toolbox": "^6.5.19",
|
|
39
|
+
"nanoid": "^3.3.4",
|
|
40
|
+
"nodemailer": "^6.7.7",
|
|
41
41
|
"shortid": "^2.2.16",
|
|
42
42
|
"source-map-support": "^0.5.21",
|
|
43
43
|
"uuid": "^8.3.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@tsconfig/node16": "^1.0.3",
|
|
47
|
-
"@types/aws-lambda": "^8.10.
|
|
48
|
-
"@types/node": "^
|
|
47
|
+
"@types/aws-lambda": "^8.10.101",
|
|
48
|
+
"@types/node": "^18.6.3",
|
|
49
49
|
"@types/nodemailer": "^6.4.4",
|
|
50
50
|
"@types/shortid": "^0.0.29",
|
|
51
51
|
"@types/uuid": "^8.3.4",
|
|
52
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
53
|
-
"@typescript-eslint/parser": "^
|
|
54
|
-
"aws-sdk": "^2.
|
|
55
|
-
"eslint": "^
|
|
56
|
-
"typedoc": "^0.23.
|
|
57
|
-
"typescript": "^4.4
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.32.0",
|
|
53
|
+
"@typescript-eslint/parser": "^5.32.0",
|
|
54
|
+
"aws-sdk": "^2.1187.0",
|
|
55
|
+
"eslint": "^8.21.0",
|
|
56
|
+
"typedoc": "^0.23.10",
|
|
57
|
+
"typescript": "^4.7.4"
|
|
58
58
|
}
|
|
59
59
|
}
|