@juniyadi/cognito 0.1.0 → 0.2.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/Cognito.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _aws_sdk_client_cognito_identity_provider from '@aws-sdk/client-cognito-identity-provider';
2
- import { CognitoIdentityProviderClient, AdminSetUserPasswordCommandOutput, AdminDisableUserCommandOutput, AdminDeleteUserCommandOutput } from '@aws-sdk/client-cognito-identity-provider';
2
+ import { CognitoIdentityProviderClient, AdminSetUserPasswordCommandOutput, AdminDisableUserCommandOutput, AdminDeleteUserCommandOutput, AdminAddUserToGroupCommandOutput } from '@aws-sdk/client-cognito-identity-provider';
3
3
 
4
4
  interface ICognito {
5
5
  region?: string;
@@ -19,6 +19,7 @@ interface ICognitoInviteUser {
19
19
  phoneNumber?: string;
20
20
  sendEmail?: boolean;
21
21
  attributes?: ICognitoAttributes[];
22
+ group?: string;
22
23
  }
23
24
  declare class Cognito {
24
25
  region: string;
@@ -95,6 +96,19 @@ declare class Cognito {
95
96
  * @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html
96
97
  */
97
98
  listUsers: (filter?: string) => Promise<_aws_sdk_client_cognito_identity_provider.ListUsersCommandOutput>;
99
+ /**
100
+ * Add a user to a group in Cognito User Pool
101
+ * @param username - Username of the user
102
+ * @param groupName - Name of the group
103
+ * @returns Promise<AdminAddUserToGroupCommandOutput>
104
+ * @example
105
+ * const cognito = new Cognito();
106
+ * const users = await cognito.addUserToGroup("johndoe@example.com", "Admin");
107
+ * console.log(users.Users);
108
+ *
109
+ * @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminAddUserToGroup.html
110
+ */
111
+ addUserToGroup: (username: string, groupName: string) => Promise<AdminAddUserToGroupCommandOutput>;
98
112
  }
99
113
 
100
114
  export { Cognito, ICognito, ICognitoAttributes, ICognitoInviteUser };
package/dist/Cognito.js CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var U=(n,e)=>{for(var r in e)d(n,r,{get:e[r],enumerable:!0})},C=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of I(e))!P.call(n,s)&&s!==r&&d(n,s,{get:()=>e[s],enumerable:!(t=g(e,s))||t.enumerable});return n};var h=n=>C(d({},"__esModule",{value:!0}),n);var b={};U(b,{Cognito:()=>m});module.exports=h(b);var i=require("@aws-sdk/client-cognito-identity-provider"),c=require("crypto"),m=class{constructor(e){this.randomPassword=(e=12)=>(0,c.randomBytes)(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var u,l;let r=e.passwordTemporary||this.randomPassword(),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:r};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 s=new i.AdminCreateUserCommand(t);try{let o=await this.cognitoIdentityProvider.send(s);if(e.autoConfirm&&((u=o==null?void 0:o.User)==null?void 0:u.UserStatus)==="FORCE_CHANGE_PASSWORD"){let a=await this.changePassword(e.email,e.password);if(((l=a==null?void 0:a.$metadata)==null?void 0:l.httpStatusCode)!==200)throw new Error("Error changing password")}return o}catch(o){throw o}};this.changePassword=async(e,r)=>{let t=new i.AdminSetUserPasswordCommand({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(t)};this.disableUser=async e=>{let r=new i.AdminDisableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new i.AdminDeleteUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new i.ListUsersCommand({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 i.CognitoIdentityProviderClient({region:this.region})}};0&&(module.exports={Cognito});
1
+ "use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var I=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},P=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of c(e))!g.call(t,s)&&s!==r&&d(t,s,{get:()=>e[s],enumerable:!(n=l(e,s))||n.enumerable});return t};var U=t=>P(d({},"__esModule",{value:!0}),t);var C={};I(C,{Cognito:()=>a});module.exports=U(C);var i=require("@aws-sdk/client-cognito-identity-provider"),u=require("crypto"),a=class{constructor(e){this.randomPassword=(e=12)=>(0,u.randomBytes)(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var m;let r=e.passwordTemporary||this.randomPassword(),n={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:r};e.phoneNumber&&n.UserAttributes&&n.UserAttributes.push({Name:"phone_number",Value:e.phoneNumber}),e.attributes&&n.UserAttributes&&(n.UserAttributes=n.UserAttributes.concat(e.attributes));let s=new i.AdminCreateUserCommand(n);try{let o=await this.cognitoIdentityProvider.send(s);return e.autoConfirm&&((m=o==null?void 0:o.User)==null?void 0:m.UserStatus)==="FORCE_CHANGE_PASSWORD"&&await this.changePassword(e.email,e.password),e.group&&await this.addUserToGroup(e.email,e.group),o}catch(o){throw o}};this.changePassword=async(e,r)=>{let n=new i.AdminSetUserPasswordCommand({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(n)};this.disableUser=async e=>{let r=new i.AdminDisableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new i.AdminDeleteUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new i.ListUsersCommand({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};this.addUserToGroup=async(e,r)=>{let n=new i.AdminAddUserToGroupCommand({UserPoolId:this.userPoolId,Username:e,GroupName:r});return this.cognitoIdentityProvider.send(n)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 i.CognitoIdentityProviderClient({region:this.region})}};0&&(module.exports={Cognito});
package/dist/Cognito.mjs CHANGED
@@ -1 +1 @@
1
- import{AdminCreateUserCommand as m,CognitoIdentityProviderClient as u,AdminSetUserPasswordCommand as l,AdminDisableUserCommand as c,AdminDeleteUserCommand as g,ListUsersCommand as I}from"@aws-sdk/client-cognito-identity-provider";import{randomBytes as P}from"crypto";var a=class{constructor(e){this.randomPassword=(e=12)=>P(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var s,o;let r=e.passwordTemporary||this.randomPassword(),i={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:r};e.phoneNumber&&i.UserAttributes&&i.UserAttributes.push({Name:"phone_number",Value:e.phoneNumber}),e.attributes&&i.UserAttributes&&(i.UserAttributes=i.UserAttributes.concat(e.attributes));let d=new m(i);try{let t=await this.cognitoIdentityProvider.send(d);if(e.autoConfirm&&((s=t==null?void 0:t.User)==null?void 0:s.UserStatus)==="FORCE_CHANGE_PASSWORD"){let n=await this.changePassword(e.email,e.password);if(((o=n==null?void 0:n.$metadata)==null?void 0:o.httpStatusCode)!==200)throw new Error("Error changing password")}return t}catch(t){throw t}};this.changePassword=async(e,r)=>{let i=new l({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(i)};this.disableUser=async e=>{let r=new c({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new g({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new I({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 u({region:this.region})}};export{a as Cognito};
1
+ import{AdminCreateUserCommand as d,CognitoIdentityProviderClient as a,AdminSetUserPasswordCommand as m,AdminDisableUserCommand as u,AdminDeleteUserCommand as l,ListUsersCommand as c,AdminAddUserToGroupCommand as g}from"@aws-sdk/client-cognito-identity-provider";import{randomBytes as I}from"crypto";var s=class{constructor(e){this.randomPassword=(e=12)=>I(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var t;let r=e.passwordTemporary||this.randomPassword(),i={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:r};e.phoneNumber&&i.UserAttributes&&i.UserAttributes.push({Name:"phone_number",Value:e.phoneNumber}),e.attributes&&i.UserAttributes&&(i.UserAttributes=i.UserAttributes.concat(e.attributes));let o=new d(i);try{let n=await this.cognitoIdentityProvider.send(o);return e.autoConfirm&&((t=n==null?void 0:n.User)==null?void 0:t.UserStatus)==="FORCE_CHANGE_PASSWORD"&&await this.changePassword(e.email,e.password),e.group&&await this.addUserToGroup(e.email,e.group),n}catch(n){throw n}};this.changePassword=async(e,r)=>{let i=new m({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(i)};this.disableUser=async e=>{let r=new u({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new l({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new c({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};this.addUserToGroup=async(e,r)=>{let i=new g({UserPoolId:this.userPoolId,Username:e,GroupName:r});return this.cognitoIdentityProvider.send(i)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 a({region:this.region})}};export{s as Cognito};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var d=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var U=(n,e)=>{for(var r in e)d(n,r,{get:e[r],enumerable:!0})},C=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of I(e))!P.call(n,s)&&s!==r&&d(n,s,{get:()=>e[s],enumerable:!(t=g(e,s))||t.enumerable});return n};var h=n=>C(d({},"__esModule",{value:!0}),n);var w={};U(w,{Cognito:()=>m});module.exports=h(w);var i=require("@aws-sdk/client-cognito-identity-provider"),c=require("crypto"),m=class{constructor(e){this.randomPassword=(e=12)=>(0,c.randomBytes)(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var u,l;let r=e.passwordTemporary||this.randomPassword(),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:r};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 s=new i.AdminCreateUserCommand(t);try{let o=await this.cognitoIdentityProvider.send(s);if(e.autoConfirm&&((u=o==null?void 0:o.User)==null?void 0:u.UserStatus)==="FORCE_CHANGE_PASSWORD"){let a=await this.changePassword(e.email,e.password);if(((l=a==null?void 0:a.$metadata)==null?void 0:l.httpStatusCode)!==200)throw new Error("Error changing password")}return o}catch(o){throw o}};this.changePassword=async(e,r)=>{let t=new i.AdminSetUserPasswordCommand({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(t)};this.disableUser=async e=>{let r=new i.AdminDisableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new i.AdminDeleteUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new i.ListUsersCommand({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 i.CognitoIdentityProviderClient({region:this.region})}};0&&(module.exports={Cognito});
1
+ "use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var g=Object.prototype.hasOwnProperty;var I=(n,e)=>{for(var r in e)d(n,r,{get:e[r],enumerable:!0})},P=(n,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of c(e))!g.call(n,o)&&o!==r&&d(n,o,{get:()=>e[o],enumerable:!(t=l(e,o))||t.enumerable});return n};var U=n=>P(d({},"__esModule",{value:!0}),n);var h={};I(h,{Cognito:()=>a});module.exports=U(h);var i=require("@aws-sdk/client-cognito-identity-provider"),u=require("crypto"),a=class{constructor(e){this.randomPassword=(e=12)=>(0,u.randomBytes)(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var m;let r=e.passwordTemporary||this.randomPassword(),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:r};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 i.AdminCreateUserCommand(t);try{let s=await this.cognitoIdentityProvider.send(o);return e.autoConfirm&&((m=s==null?void 0:s.User)==null?void 0:m.UserStatus)==="FORCE_CHANGE_PASSWORD"&&await this.changePassword(e.email,e.password),e.group&&await this.addUserToGroup(e.email,e.group),s}catch(s){throw s}};this.changePassword=async(e,r)=>{let t=new i.AdminSetUserPasswordCommand({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(t)};this.disableUser=async e=>{let r=new i.AdminDisableUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new i.AdminDeleteUserCommand({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new i.ListUsersCommand({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};this.addUserToGroup=async(e,r)=>{let t=new i.AdminAddUserToGroupCommand({UserPoolId:this.userPoolId,Username:e,GroupName:r});return this.cognitoIdentityProvider.send(t)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 i.CognitoIdentityProviderClient({region:this.region})}};0&&(module.exports={Cognito});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{AdminCreateUserCommand as l,CognitoIdentityProviderClient as c,AdminSetUserPasswordCommand as g,AdminDisableUserCommand as I,AdminDeleteUserCommand as P,ListUsersCommand as U}from"@aws-sdk/client-cognito-identity-provider";import{randomBytes as C}from"crypto";var a=class{constructor(e){this.randomPassword=(e=12)=>C(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var s,o;let r=e.passwordTemporary||this.randomPassword(),i={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:r};e.phoneNumber&&i.UserAttributes&&i.UserAttributes.push({Name:"phone_number",Value:e.phoneNumber}),e.attributes&&i.UserAttributes&&(i.UserAttributes=i.UserAttributes.concat(e.attributes));let d=new l(i);try{let t=await this.cognitoIdentityProvider.send(d);if(e.autoConfirm&&((s=t==null?void 0:t.User)==null?void 0:s.UserStatus)==="FORCE_CHANGE_PASSWORD"){let n=await this.changePassword(e.email,e.password);if(((o=n==null?void 0:n.$metadata)==null?void 0:o.httpStatusCode)!==200)throw new Error("Error changing password")}return t}catch(t){throw t}};this.changePassword=async(e,r)=>{let i=new g({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(i)};this.disableUser=async e=>{let r=new I({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new P({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new U({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 c({region:this.region})}};export{a as Cognito};
1
+ import{AdminCreateUserCommand as m,CognitoIdentityProviderClient as u,AdminSetUserPasswordCommand as l,AdminDisableUserCommand as c,AdminDeleteUserCommand as g,ListUsersCommand as I,AdminAddUserToGroupCommand as P}from"@aws-sdk/client-cognito-identity-provider";import{randomBytes as U}from"crypto";var o=class{constructor(e){this.randomPassword=(e=12)=>U(256).toString("hex").slice(0,e);this.inviteUser=async e=>{var n;let r=e.passwordTemporary||this.randomPassword(),i={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:r};e.phoneNumber&&i.UserAttributes&&i.UserAttributes.push({Name:"phone_number",Value:e.phoneNumber}),e.attributes&&i.UserAttributes&&(i.UserAttributes=i.UserAttributes.concat(e.attributes));let s=new m(i);try{let t=await this.cognitoIdentityProvider.send(s);return e.autoConfirm&&((n=t==null?void 0:t.User)==null?void 0:n.UserStatus)==="FORCE_CHANGE_PASSWORD"&&await this.changePassword(e.email,e.password),e.group&&await this.addUserToGroup(e.email,e.group),t}catch(t){throw t}};this.changePassword=async(e,r)=>{let i=new l({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(i)};this.disableUser=async e=>{let r=new c({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.deleteUser=async e=>{await this.disableUser(e);let r=new g({UserPoolId:this.userPoolId,Username:e});return this.cognitoIdentityProvider.send(r)};this.listUsers=async e=>{let r=new I({UserPoolId:this.userPoolId,Filter:e||void 0});return this.cognitoIdentityProvider.send(r)};this.addUserToGroup=async(e,r)=>{let i=new P({UserPoolId:this.userPoolId,Username:e,GroupName:r});return this.cognitoIdentityProvider.send(i)};if(this.region=(e==null?void 0:e.region)||process.env.AWS_REGION||"",this.userPoolId=(e==null?void 0:e.userPoolId)||process.env.COGNITO_USER_POOL_ID||"",this.clientId=(e==null?void 0: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 u({region:this.region})}};export{o as Cognito};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juniyadi/cognito",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  "typedoc": "^0.24.8",
28
28
  "typescript": "^4.9.5",
29
29
  "@juniyadi/tsconfig": "0.0.0",
30
- "eslint-config-juniyadi": "0.0.1",
31
- "@juniyadi/config-typedoc": "0.0.0"
30
+ "@juniyadi/config-typedoc": "0.0.0",
31
+ "eslint-config-juniyadi": "0.0.1"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"