@juniyadi/cognito 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +5 -3
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var clientCognitoIdentityProvider = require('@aws-sdk/client-cognito-identity-provider');
|
4
|
-
var
|
4
|
+
var randomString = require('@juniyadi/random-string');
|
5
5
|
|
6
|
-
var
|
6
|
+
var s=class{constructor(e){this.randomPassword=(e=12)=>randomString.generate(e,{lowercase:!0,uppercase:!0,numbers:!0});this.inviteUser=async e=>{let r=e.password||this.randomPassword(10),i=e.passwordTemporary||this.randomPassword(12),t={UserPoolId:this.userPoolId,Username:e.email,UserAttributes:[{Name:"email",Value:e.email},{Name:"name",Value:e.name},{Name:"email_verified",Value:"true"}],DesiredDeliveryMediums:["EMAIL"],ForceAliasCreation:!1,MessageAction:e.sendEmail?"RESEND":"SUPPRESS",TemporaryPassword:i};e.phoneNumber&&t.UserAttributes&&t.UserAttributes.push({Name:"phone_number",Value:e.phoneNumber}),e.attributes&&t.UserAttributes&&(t.UserAttributes=t.UserAttributes.concat(e.attributes));let o=new clientCognitoIdentityProvider.AdminCreateUserCommand(t);try{let n=await this.cognitoIdentityProvider.send(o);return e.autoConfirm&&n?.User?.UserStatus==="FORCE_CHANGE_PASSWORD"&&await this.changePassword(e.email,r),e.group&&await this.addUserToGroup(e.email,e.group),n}catch(n){throw n}};this.changePassword=async(e,r)=>{let i=new clientCognitoIdentityProvider.AdminSetUserPasswordCommand({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(i)};this.disableUser=async e=>{let r=new clientCognitoIdentityProvider.AdminDisableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.enableUser=async e=>{let r=new clientCognitoIdentityProvider.AdminEnableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new clientCognitoIdentityProvider.AdminDeleteUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new clientCognitoIdentityProvider.ListUsersCommand({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};this.addUserToGroup=async(e,r)=>{let i=new clientCognitoIdentityProvider.AdminAddUserToGroupCommand({UserPoolId:this.userPoolId,Username:e,GroupName:r});return this.cognitoIdentityProvider.send(i)};if(this.region=e?.region||process.env.AWS_REGION||"",this.userPoolId=e?.userPoolId||process.env.COGNITO_USER_POOL_ID||"",this.clientId=e?.clientId||process.env.COGNITO_CLIENT_ID||"",!this.region)throw new Error("AWS Region is required");if(!this.userPoolId)throw new Error("Cognito User Pool ID is required");if(!this.clientId)throw new Error("Cognito Client ID is required");this.cognitoIdentityProvider=new clientCognitoIdentityProvider.CognitoIdentityProviderClient({region:this.region});}};
|
7
7
|
|
8
|
-
exports.Cognito =
|
8
|
+
exports.Cognito = s;
|
package/dist/index.mjs
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { AdminCreateUserCommand, AdminSetUserPasswordCommand, AdminDisableUserCommand, AdminEnableUserCommand, AdminDeleteUserCommand, ListUsersCommand, AdminAddUserToGroupCommand, CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
|
2
|
-
import {
|
2
|
+
import { generate } from '@juniyadi/random-string';
|
3
3
|
|
4
|
-
var
|
4
|
+
var s=class{constructor(e){this.randomPassword=(e=12)=>generate(e,{lowercase:!0,uppercase:!0,numbers:!0});this.inviteUser=async e=>{let r=e.password||this.randomPassword(10),i=e.passwordTemporary||this.randomPassword(12),t={UserPoolId:this.userPoolId,Username:e.email,UserAttributes:[{Name:"email",Value:e.email},{Name:"name",Value:e.name},{Name:"email_verified",Value:"true"}],DesiredDeliveryMediums:["EMAIL"],ForceAliasCreation:!1,MessageAction:e.sendEmail?"RESEND":"SUPPRESS",TemporaryPassword:i};e.phoneNumber&&t.UserAttributes&&t.UserAttributes.push({Name:"phone_number",Value:e.phoneNumber}),e.attributes&&t.UserAttributes&&(t.UserAttributes=t.UserAttributes.concat(e.attributes));let o=new AdminCreateUserCommand(t);try{let n=await this.cognitoIdentityProvider.send(o);return e.autoConfirm&&n?.User?.UserStatus==="FORCE_CHANGE_PASSWORD"&&await this.changePassword(e.email,r),e.group&&await this.addUserToGroup(e.email,e.group),n}catch(n){throw n}};this.changePassword=async(e,r)=>{let i=new AdminSetUserPasswordCommand({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(i)};this.disableUser=async e=>{let r=new AdminDisableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.enableUser=async e=>{let r=new AdminEnableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new AdminDeleteUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new ListUsersCommand({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};this.addUserToGroup=async(e,r)=>{let i=new AdminAddUserToGroupCommand({UserPoolId:this.userPoolId,Username:e,GroupName:r});return this.cognitoIdentityProvider.send(i)};if(this.region=e?.region||process.env.AWS_REGION||"",this.userPoolId=e?.userPoolId||process.env.COGNITO_USER_POOL_ID||"",this.clientId=e?.clientId||process.env.COGNITO_CLIENT_ID||"",!this.region)throw new Error("AWS Region is required");if(!this.userPoolId)throw new Error("Cognito User Pool ID is required");if(!this.clientId)throw new Error("Cognito Client ID is required");this.cognitoIdentityProvider=new CognitoIdentityProviderClient({region:this.region});}};
|
5
5
|
|
6
|
-
export {
|
6
|
+
export { s as Cognito };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@juniyadi/cognito",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.1",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"exports": {
|
@@ -37,8 +37,9 @@
|
|
37
37
|
"tsup": "^7.2.0",
|
38
38
|
"typedoc": "^0.24.8",
|
39
39
|
"typescript": "^5.1.6",
|
40
|
-
"@juniyadi/tsconfig": "0.0.0",
|
41
40
|
"@juniyadi/config-typedoc": "0.0.0",
|
41
|
+
"@juniyadi/random-string": "0.1.0",
|
42
|
+
"@juniyadi/tsconfig": "0.0.0",
|
42
43
|
"eslint-config-juniyadi": "0.0.1"
|
43
44
|
},
|
44
45
|
"publishConfig": {
|
@@ -46,7 +47,8 @@
|
|
46
47
|
},
|
47
48
|
"peerDependencies": {
|
48
49
|
"@aws-sdk/client-cognito-identity": "^3.388.0",
|
49
|
-
"@aws-sdk/client-cognito-identity-provider": "^3.388.0"
|
50
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.388.0",
|
51
|
+
"@juniyadi/random-string": "0.1.0"
|
50
52
|
},
|
51
53
|
"scripts": {
|
52
54
|
"docs": "typedoc --out docs src/index.ts",
|