@juniyadi/cognito 0.1.0 → 0.3.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/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # Cognito
2
+
3
+ ![npm](https://img.shields.io/npm/dm/@juniyadi/cognito)
4
+ ![npm](https://img.shields.io/npm/v/@juniyadi/cognito)
5
+ ![NPM](https://img.shields.io/npm/l/@juniyadi/cognito)
6
+ ![npm bundle size](https://img.shields.io/bundlephobia/min/@juniyadi/cognito)
@@ -0,0 +1,114 @@
1
+ import * as _aws_sdk_client_cognito_identity_provider from '@aws-sdk/client-cognito-identity-provider';
2
+ import { CognitoIdentityProviderClient, AdminSetUserPasswordCommandOutput, AdminDisableUserCommandOutput, AdminDeleteUserCommandOutput, AdminAddUserToGroupCommandOutput } from '@aws-sdk/client-cognito-identity-provider';
3
+
4
+ interface ICognito {
5
+ region?: string;
6
+ userPoolId?: string;
7
+ clientId?: string;
8
+ }
9
+ interface ICognitoAttributes {
10
+ Name: string;
11
+ Value: string;
12
+ }
13
+ interface ICognitoInviteUser {
14
+ name: string;
15
+ email: string;
16
+ password: string;
17
+ passwordTemporary?: string;
18
+ autoConfirm?: boolean;
19
+ phoneNumber?: string;
20
+ sendEmail?: boolean;
21
+ attributes?: ICognitoAttributes[];
22
+ group?: string;
23
+ }
24
+ declare class Cognito {
25
+ region: string;
26
+ userPoolId: string;
27
+ clientId: string;
28
+ cognitoIdentityProvider: CognitoIdentityProviderClient;
29
+ /**
30
+ * Create a new Cognito instance
31
+ * @param opts
32
+ * @example
33
+ * const cognito = new Cognito({
34
+ * region: "us-east-1",
35
+ * userPoolId: "us-east-1_123456789",
36
+ * clientId: "12345678901234567890",
37
+ * });
38
+ */
39
+ constructor(opts?: ICognito);
40
+ /**
41
+ * Generate a random password of a given length
42
+ * @param length
43
+ * @returns string
44
+ * @example
45
+ * const password = randomPassword(12);
46
+ * console.log(password);
47
+ */
48
+ randomPassword: (length?: number) => string;
49
+ /**
50
+ * Invite a user to the Cognito User Pool
51
+ * @param opts
52
+ */
53
+ inviteUser: (opts: ICognitoInviteUser) => Promise<_aws_sdk_client_cognito_identity_provider.AdminCreateUserCommandOutput>;
54
+ /**
55
+ * Change user password in Cognito User Pool
56
+ * @param username - Username of the user
57
+ * @param password - New password for the user
58
+ * @returns Promise<AdminSetUserPasswordCommandOutput>
59
+ * @example
60
+ * const cognito = new Cognito();
61
+ * const users = await cognito.changePassword("johndoe@example.com", "newPassword");
62
+ * console.log(users.Users);
63
+ * @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminSetUserPassword.html
64
+ */
65
+ changePassword: (username: string, password: string) => Promise<AdminSetUserPasswordCommandOutput>;
66
+ /**
67
+ * Disable a user in Cognito User Pool
68
+ * @param username - Username of the user
69
+ * @returns Promise<AdminDisableUserCommandOutput>
70
+ * @example
71
+ * const cognito = new Cognito();
72
+ * const users = await cognito.disableUser("johndoe@example.com");
73
+ * console.log(users.Users);
74
+ * @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminDisableUser.html
75
+ */
76
+ disableUser: (username: string) => Promise<AdminDisableUserCommandOutput>;
77
+ /**
78
+ * Delete a user in Cognito User Pool
79
+ * @param username - Username of the user
80
+ * @returns Promise<AdminDeleteUserCommandOutput>
81
+ * @example
82
+ * const cognito = new Cognito();
83
+ * const users = await cognito.deleteUser("johndoe@example.com");
84
+ * console.log(users.Users);
85
+ * @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminDeleteUser.html
86
+ */
87
+ deleteUser: (username: string) => Promise<AdminDeleteUserCommandOutput>;
88
+ /**
89
+ * List for users in Cognito User Pool
90
+ * @param opts
91
+ * @returns Promise<ListUsersCommandOutput>
92
+ * @example
93
+ * const cognito = new Cognito();
94
+ * const users = await cognito.listUsers({ email: "johndoe@example.com" });
95
+ * console.log(users.Users);
96
+ * @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html
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>;
112
+ }
113
+
114
+ export { Cognito, ICognito, ICognitoAttributes, ICognitoInviteUser };
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,10 @@
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';
2
+
3
+ var chunkPXDEYENQ_js = require('./chunk-PXDEYENQ.js');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, 'Cognito', {
8
+ enumerable: true,
9
+ get: function () { return chunkPXDEYENQ_js.a; }
10
+ });
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
+ export { a as Cognito } from './chunk-EEMFQFKO.mjs';
@@ -0,0 +1,6 @@
1
+ import { AdminCreateUserCommand, AdminSetUserPasswordCommand, AdminDisableUserCommand, AdminDeleteUserCommand, ListUsersCommand, AdminAddUserToGroupCommand, CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
2
+ import { randomBytes } from 'crypto';
3
+
4
+ var s=class{constructor(e){this.randomPassword=(e=12)=>randomBytes(256).toString("hex").slice(0,e);this.inviteUser=async e=>{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 n=new AdminCreateUserCommand(i);try{let t=await this.cognitoIdentityProvider.send(n);return e.autoConfirm&&t?.User?.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 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.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
+
6
+ export { s as a };
@@ -0,0 +1,8 @@
1
+ 'use strict';
2
+
3
+ var clientCognitoIdentityProvider = require('@aws-sdk/client-cognito-identity-provider');
4
+ var crypto = require('crypto');
5
+
6
+ var s=class{constructor(e){this.randomPassword=(e=12)=>crypto.randomBytes(256).toString("hex").slice(0,e);this.inviteUser=async e=>{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 n=new clientCognitoIdentityProvider.AdminCreateUserCommand(i);try{let t=await this.cognitoIdentityProvider.send(n);return e.autoConfirm&&t?.User?.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 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.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
+
8
+ exports.a = s;
@@ -0,0 +1,2 @@
1
+ export { Cognito, ICognito, ICognitoAttributes, ICognitoInviteUser } from './Cognito.mjs';
2
+ import '@aws-sdk/client-cognito-identity-provider';
package/dist/index.js CHANGED
@@ -1 +1,10 @@
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';
2
+
3
+ var chunkPXDEYENQ_js = require('./chunk-PXDEYENQ.js');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, 'Cognito', {
8
+ enumerable: true,
9
+ get: function () { return chunkPXDEYENQ_js.a; }
10
+ });
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
+ export { a as Cognito } from './chunk-EEMFQFKO.mjs';
package/package.json CHANGED
@@ -1,9 +1,20 @@
1
1
  {
2
2
  "name": "@juniyadi/cognito",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "main": "./dist/index.js",
5
- "module": "./dist/index.mjs",
6
5
  "types": "./dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "import": {
9
+ "default": "./dist/index.mjs",
10
+ "types": "./dist/index.d.mts"
11
+ },
12
+ "require": {
13
+ "default": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ }
17
+ },
7
18
  "sideEffects": false,
8
19
  "license": "MIT",
9
20
  "files": [
@@ -18,17 +29,17 @@
18
29
  "@aws-sdk/client-cognito-identity": "^3.388.0",
19
30
  "@aws-sdk/client-cognito-identity-provider": "^3.388.0",
20
31
  "@types/jest": "^29.5.3",
21
- "@types/node": "^20.4.9",
32
+ "@types/node": "^20.5.0",
22
33
  "aws-sdk-client-mock": "^3.0.0",
23
- "eslint": "^8.46.0",
34
+ "eslint": "^8.47.0",
24
35
  "jest": "^29.6.2",
25
36
  "ts-jest": "^29.1.1",
26
- "tsup": "^5.12.9",
37
+ "tsup": "^7.2.0",
27
38
  "typedoc": "^0.24.8",
28
- "typescript": "^4.9.5",
39
+ "typescript": "^5.1.6",
40
+ "@juniyadi/config-typedoc": "0.0.0",
29
41
  "@juniyadi/tsconfig": "0.0.0",
30
- "eslint-config-juniyadi": "0.0.1",
31
- "@juniyadi/config-typedoc": "0.0.0"
42
+ "eslint-config-juniyadi": "0.0.1"
32
43
  },
33
44
  "publishConfig": {
34
45
  "access": "public"