idea-aws 3.15.1 → 3.15.2

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.
@@ -53,6 +53,14 @@ export declare class Cognito {
53
53
  * Resend the password to a user who never logged in.
54
54
  */
55
55
  resendPassword(email: string, cognitoUserPoolId: string, options?: CreateUserOptions): Promise<void>;
56
+ /**
57
+ * Set a new password for a specific user identified by its email (admin-only).
58
+ * If not specified, the password is generated randomly, and the user must change it at the first login.
59
+ */
60
+ setPassword(email: string, cognitoUserPoolId: string, options?: {
61
+ password?: string;
62
+ permanent?: boolean;
63
+ }): Promise<void>;
56
64
  /**
57
65
  * Delete a user by its email (username), in the pool specified.
58
66
  */
@@ -156,6 +156,26 @@ class Cognito {
156
156
  params.TemporaryPassword = options.temporaryPassword;
157
157
  await this.cognito.adminCreateUser(params).promise();
158
158
  }
159
+ /**
160
+ * Set a new password for a specific user identified by its email (admin-only).
161
+ * If not specified, the password is generated randomly, and the user must change it at the first login.
162
+ */
163
+ async setPassword(email, cognitoUserPoolId, options = {}) {
164
+ if ((0, idea_toolbox_1.isEmpty)(email, 'email'))
165
+ throw new Error('Invalid email');
166
+ const RANDOM_PASSWORD_LENGTH = 8;
167
+ const password = options.password ??
168
+ Math.random()
169
+ .toString(36)
170
+ .slice(2, 2 + RANDOM_PASSWORD_LENGTH);
171
+ const params = {
172
+ UserPoolId: cognitoUserPoolId,
173
+ Username: email,
174
+ Password: password,
175
+ Permanent: options.permanent
176
+ };
177
+ await this.cognito.adminSetUserPassword(params).promise();
178
+ }
159
179
  /**
160
180
  * Delete a user by its email (username), in the pool specified.
161
181
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "3.15.1",
3
+ "version": "3.15.2",
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",