idea-aws 4.4.7 → 4.4.9
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 +5 -1
- package/dist/src/cognito.js +12 -9
- package/package.json +1 -1
package/dist/src/cognito.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export declare class Cognito {
|
|
|
32
32
|
* Identify a user by its userId (sub), returning its attributes.
|
|
33
33
|
*/
|
|
34
34
|
getUserBySub(sub: string, userPoolId: string): Promise<CognitoUserGeneric>;
|
|
35
|
+
/**
|
|
36
|
+
* Get the list of groups of a user by its email address.
|
|
37
|
+
*/
|
|
38
|
+
getUserGroupsByEmail(email: string, userPoolId: string): Promise<string[]>;
|
|
35
39
|
/**
|
|
36
40
|
* List all the users of the pool.
|
|
37
41
|
*/
|
|
@@ -41,7 +45,7 @@ export declare class Cognito {
|
|
|
41
45
|
}): Promise<CognitoUser[]>;
|
|
42
46
|
/**
|
|
43
47
|
* List all the users of the pool, including the information about the groups they're in.
|
|
44
|
-
* Note: it's slower than the alternative `
|
|
48
|
+
* Note: it's slower than the alternative `listUsers`: use it only when needed.
|
|
45
49
|
*/
|
|
46
50
|
listUsersWithGroupsDetail(cognitoUserPoolId: string): Promise<CognitoUser[]>;
|
|
47
51
|
/**
|
package/dist/src/cognito.js
CHANGED
|
@@ -99,6 +99,14 @@ class Cognito {
|
|
|
99
99
|
throw new Error('User not found');
|
|
100
100
|
return this.mapCognitoUserAttributesAsPlainObject(Users[0]);
|
|
101
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the list of groups of a user by its email address.
|
|
104
|
+
*/
|
|
105
|
+
async getUserGroupsByEmail(email, userPoolId) {
|
|
106
|
+
const command = new CognitoIP.AdminListGroupsForUserCommand({ UserPoolId: userPoolId, Username: email });
|
|
107
|
+
const { Groups } = await this.client.send(command);
|
|
108
|
+
return Groups.map(x => x.GroupName);
|
|
109
|
+
}
|
|
102
110
|
/**
|
|
103
111
|
* List all the users of the pool.
|
|
104
112
|
*/
|
|
@@ -115,23 +123,18 @@ class Cognito {
|
|
|
115
123
|
}
|
|
116
124
|
/**
|
|
117
125
|
* List all the users of the pool, including the information about the groups they're in.
|
|
118
|
-
* Note: it's slower than the alternative `
|
|
126
|
+
* Note: it's slower than the alternative `listUsers`: use it only when needed.
|
|
119
127
|
*/
|
|
120
128
|
async listUsersWithGroupsDetail(cognitoUserPoolId) {
|
|
121
|
-
const groups = await this.listGroups(cognitoUserPoolId);
|
|
122
|
-
|
|
123
|
-
for (const group of groups) {
|
|
129
|
+
const [users, groups] = await Promise.all([this.listUsers(cognitoUserPoolId), this.listGroups(cognitoUserPoolId)]);
|
|
130
|
+
await Promise.all(groups.map(async (group) => {
|
|
124
131
|
const usersOfGroup = await this.listUsersInGroup(group.name, cognitoUserPoolId);
|
|
125
132
|
usersOfGroup.forEach(userInGroup => {
|
|
126
133
|
const userAlreadyInOutputList = users.find(u => u.userId === userInGroup.userId);
|
|
127
134
|
if (userAlreadyInOutputList)
|
|
128
135
|
userAlreadyInOutputList.groups.push(group.name);
|
|
129
|
-
else {
|
|
130
|
-
userInGroup.groups.push(group.name);
|
|
131
|
-
users.push(userInGroup);
|
|
132
|
-
}
|
|
133
136
|
});
|
|
134
|
-
}
|
|
137
|
+
}));
|
|
135
138
|
return users;
|
|
136
139
|
}
|
|
137
140
|
/**
|