@juniyadi/cognito 0.0.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/Cognito.d.ts +54 -1
- package/dist/Cognito.js +1 -124
- package/dist/Cognito.mjs +1 -106
- package/dist/index.js +1 -19
- package/dist/index.mjs +1 -2
- package/package.json +12 -4
- package/dist/Cognito.js.map +0 -1
- package/dist/Cognito.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
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,17 +19,31 @@ 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;
|
25
26
|
userPoolId: string;
|
26
27
|
clientId: string;
|
27
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
|
+
*/
|
28
39
|
constructor(opts?: ICognito);
|
29
40
|
/**
|
30
41
|
* Generate a random password of a given length
|
31
42
|
* @param length
|
32
43
|
* @returns string
|
44
|
+
* @example
|
45
|
+
* const password = randomPassword(12);
|
46
|
+
* console.log(password);
|
33
47
|
*/
|
34
48
|
randomPassword: (length?: number) => string;
|
35
49
|
/**
|
@@ -42,20 +56,59 @@ declare class Cognito {
|
|
42
56
|
* @param username - Username of the user
|
43
57
|
* @param password - New password for the user
|
44
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
|
45
64
|
*/
|
46
65
|
changePassword: (username: string, password: string) => Promise<AdminSetUserPasswordCommandOutput>;
|
47
66
|
/**
|
48
67
|
* Disable a user in Cognito User Pool
|
49
68
|
* @param username - Username of the user
|
50
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
|
51
75
|
*/
|
52
76
|
disableUser: (username: string) => Promise<AdminDisableUserCommandOutput>;
|
53
77
|
/**
|
54
78
|
* Delete a user in Cognito User Pool
|
55
79
|
* @param username - Username of the user
|
56
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
|
57
86
|
*/
|
58
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>;
|
59
112
|
}
|
60
113
|
|
61
114
|
export { Cognito, ICognito, ICognitoAttributes, ICognitoInviteUser };
|
package/dist/Cognito.js
CHANGED
@@ -1,124 +1 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var Cognito_exports = {};
|
20
|
-
__export(Cognito_exports, {
|
21
|
-
Cognito: () => Cognito
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(Cognito_exports);
|
24
|
-
var import_client_cognito_identity_provider = require("@aws-sdk/client-cognito-identity-provider");
|
25
|
-
var import_crypto = require("crypto");
|
26
|
-
class Cognito {
|
27
|
-
constructor(opts) {
|
28
|
-
this.randomPassword = (length = 12) => {
|
29
|
-
return (0, import_crypto.randomBytes)(256).toString("hex").slice(0, length);
|
30
|
-
};
|
31
|
-
this.inviteUser = async (opts) => {
|
32
|
-
var _a, _b;
|
33
|
-
const temporaryPassword = opts.passwordTemporary || this.randomPassword();
|
34
|
-
const items = {
|
35
|
-
UserPoolId: this.userPoolId,
|
36
|
-
Username: opts.email,
|
37
|
-
UserAttributes: [
|
38
|
-
{
|
39
|
-
Name: "email",
|
40
|
-
Value: opts.email
|
41
|
-
},
|
42
|
-
{
|
43
|
-
Name: "name",
|
44
|
-
Value: opts.name
|
45
|
-
},
|
46
|
-
{
|
47
|
-
Name: "email_verified",
|
48
|
-
Value: "true"
|
49
|
-
}
|
50
|
-
],
|
51
|
-
DesiredDeliveryMediums: ["EMAIL"],
|
52
|
-
ForceAliasCreation: false,
|
53
|
-
MessageAction: opts.sendEmail ? "RESEND" : "SUPPRESS",
|
54
|
-
TemporaryPassword: temporaryPassword
|
55
|
-
};
|
56
|
-
if (opts.phoneNumber && items.UserAttributes) {
|
57
|
-
items.UserAttributes.push({
|
58
|
-
Name: "phone_number",
|
59
|
-
Value: opts.phoneNumber
|
60
|
-
});
|
61
|
-
}
|
62
|
-
if (opts.attributes && items.UserAttributes) {
|
63
|
-
items.UserAttributes = items.UserAttributes.concat(opts.attributes);
|
64
|
-
}
|
65
|
-
const command = new import_client_cognito_identity_provider.AdminCreateUserCommand(items);
|
66
|
-
try {
|
67
|
-
const response = await this.cognitoIdentityProvider.send(command);
|
68
|
-
if (opts.autoConfirm && ((_a = response == null ? void 0 : response.User) == null ? void 0 : _a.UserStatus) === "FORCE_CHANGE_PASSWORD") {
|
69
|
-
const changePassword = await this.changePassword(
|
70
|
-
opts.email,
|
71
|
-
opts.password
|
72
|
-
);
|
73
|
-
if (((_b = changePassword == null ? void 0 : changePassword.$metadata) == null ? void 0 : _b.httpStatusCode) !== 200) {
|
74
|
-
throw new Error("Error changing password");
|
75
|
-
}
|
76
|
-
}
|
77
|
-
return response;
|
78
|
-
} catch (error) {
|
79
|
-
throw error;
|
80
|
-
}
|
81
|
-
};
|
82
|
-
this.changePassword = async (username, password) => {
|
83
|
-
const command = new import_client_cognito_identity_provider.AdminSetUserPasswordCommand({
|
84
|
-
UserPoolId: this.userPoolId,
|
85
|
-
Username: username,
|
86
|
-
Password: password,
|
87
|
-
Permanent: true
|
88
|
-
});
|
89
|
-
return this.cognitoIdentityProvider.send(command);
|
90
|
-
};
|
91
|
-
this.disableUser = async (username) => {
|
92
|
-
const command = new import_client_cognito_identity_provider.AdminDisableUserCommand({
|
93
|
-
UserPoolId: this.userPoolId,
|
94
|
-
Username: username
|
95
|
-
});
|
96
|
-
return this.cognitoIdentityProvider.send(command);
|
97
|
-
};
|
98
|
-
this.deleteUser = async (username) => {
|
99
|
-
await this.disableUser(username);
|
100
|
-
const command = new import_client_cognito_identity_provider.AdminDeleteUserCommand({
|
101
|
-
UserPoolId: this.userPoolId,
|
102
|
-
Username: username
|
103
|
-
});
|
104
|
-
return this.cognitoIdentityProvider.send(command);
|
105
|
-
};
|
106
|
-
this.region = (opts == null ? void 0 : opts.region) || process.env.AWS_REGION || "";
|
107
|
-
this.userPoolId = (opts == null ? void 0 : opts.userPoolId) || process.env.COGNITO_USER_POOL_ID || "";
|
108
|
-
this.clientId = (opts == null ? void 0 : opts.clientId) || process.env.COGNITO_CLIENT_ID || "";
|
109
|
-
if (!this.region)
|
110
|
-
throw new Error("AWS Region is required");
|
111
|
-
if (!this.userPoolId)
|
112
|
-
throw new Error("Cognito User Pool ID is required");
|
113
|
-
if (!this.clientId)
|
114
|
-
throw new Error("Cognito Client ID is required");
|
115
|
-
this.cognitoIdentityProvider = new import_client_cognito_identity_provider.CognitoIdentityProviderClient({
|
116
|
-
region: this.region
|
117
|
-
});
|
118
|
-
}
|
119
|
-
}
|
120
|
-
// Annotate the CommonJS export names for ESM import in node:
|
121
|
-
0 && (module.exports = {
|
122
|
-
Cognito
|
123
|
-
});
|
124
|
-
//# sourceMappingURL=Cognito.js.map
|
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,106 +1 @@
|
|
1
|
-
import {
|
2
|
-
AdminCreateUserCommand,
|
3
|
-
CognitoIdentityProviderClient,
|
4
|
-
AdminSetUserPasswordCommand,
|
5
|
-
AdminDisableUserCommand,
|
6
|
-
AdminDeleteUserCommand
|
7
|
-
} from "@aws-sdk/client-cognito-identity-provider";
|
8
|
-
import { randomBytes } from "crypto";
|
9
|
-
class Cognito {
|
10
|
-
constructor(opts) {
|
11
|
-
this.randomPassword = (length = 12) => {
|
12
|
-
return randomBytes(256).toString("hex").slice(0, length);
|
13
|
-
};
|
14
|
-
this.inviteUser = async (opts) => {
|
15
|
-
var _a, _b;
|
16
|
-
const temporaryPassword = opts.passwordTemporary || this.randomPassword();
|
17
|
-
const items = {
|
18
|
-
UserPoolId: this.userPoolId,
|
19
|
-
Username: opts.email,
|
20
|
-
UserAttributes: [
|
21
|
-
{
|
22
|
-
Name: "email",
|
23
|
-
Value: opts.email
|
24
|
-
},
|
25
|
-
{
|
26
|
-
Name: "name",
|
27
|
-
Value: opts.name
|
28
|
-
},
|
29
|
-
{
|
30
|
-
Name: "email_verified",
|
31
|
-
Value: "true"
|
32
|
-
}
|
33
|
-
],
|
34
|
-
DesiredDeliveryMediums: ["EMAIL"],
|
35
|
-
ForceAliasCreation: false,
|
36
|
-
MessageAction: opts.sendEmail ? "RESEND" : "SUPPRESS",
|
37
|
-
TemporaryPassword: temporaryPassword
|
38
|
-
};
|
39
|
-
if (opts.phoneNumber && items.UserAttributes) {
|
40
|
-
items.UserAttributes.push({
|
41
|
-
Name: "phone_number",
|
42
|
-
Value: opts.phoneNumber
|
43
|
-
});
|
44
|
-
}
|
45
|
-
if (opts.attributes && items.UserAttributes) {
|
46
|
-
items.UserAttributes = items.UserAttributes.concat(opts.attributes);
|
47
|
-
}
|
48
|
-
const command = new AdminCreateUserCommand(items);
|
49
|
-
try {
|
50
|
-
const response = await this.cognitoIdentityProvider.send(command);
|
51
|
-
if (opts.autoConfirm && ((_a = response == null ? void 0 : response.User) == null ? void 0 : _a.UserStatus) === "FORCE_CHANGE_PASSWORD") {
|
52
|
-
const changePassword = await this.changePassword(
|
53
|
-
opts.email,
|
54
|
-
opts.password
|
55
|
-
);
|
56
|
-
if (((_b = changePassword == null ? void 0 : changePassword.$metadata) == null ? void 0 : _b.httpStatusCode) !== 200) {
|
57
|
-
throw new Error("Error changing password");
|
58
|
-
}
|
59
|
-
}
|
60
|
-
return response;
|
61
|
-
} catch (error) {
|
62
|
-
throw error;
|
63
|
-
}
|
64
|
-
};
|
65
|
-
this.changePassword = async (username, password) => {
|
66
|
-
const command = new AdminSetUserPasswordCommand({
|
67
|
-
UserPoolId: this.userPoolId,
|
68
|
-
Username: username,
|
69
|
-
Password: password,
|
70
|
-
Permanent: true
|
71
|
-
});
|
72
|
-
return this.cognitoIdentityProvider.send(command);
|
73
|
-
};
|
74
|
-
this.disableUser = async (username) => {
|
75
|
-
const command = new AdminDisableUserCommand({
|
76
|
-
UserPoolId: this.userPoolId,
|
77
|
-
Username: username
|
78
|
-
});
|
79
|
-
return this.cognitoIdentityProvider.send(command);
|
80
|
-
};
|
81
|
-
this.deleteUser = async (username) => {
|
82
|
-
await this.disableUser(username);
|
83
|
-
const command = new AdminDeleteUserCommand({
|
84
|
-
UserPoolId: this.userPoolId,
|
85
|
-
Username: username
|
86
|
-
});
|
87
|
-
return this.cognitoIdentityProvider.send(command);
|
88
|
-
};
|
89
|
-
this.region = (opts == null ? void 0 : opts.region) || process.env.AWS_REGION || "";
|
90
|
-
this.userPoolId = (opts == null ? void 0 : opts.userPoolId) || process.env.COGNITO_USER_POOL_ID || "";
|
91
|
-
this.clientId = (opts == null ? void 0 : opts.clientId) || process.env.COGNITO_CLIENT_ID || "";
|
92
|
-
if (!this.region)
|
93
|
-
throw new Error("AWS Region is required");
|
94
|
-
if (!this.userPoolId)
|
95
|
-
throw new Error("Cognito User Pool ID is required");
|
96
|
-
if (!this.clientId)
|
97
|
-
throw new Error("Cognito Client ID is required");
|
98
|
-
this.cognitoIdentityProvider = new CognitoIdentityProviderClient({
|
99
|
-
region: this.region
|
100
|
-
});
|
101
|
-
}
|
102
|
-
}
|
103
|
-
export {
|
104
|
-
Cognito
|
105
|
-
};
|
106
|
-
//# sourceMappingURL=Cognito.mjs.map
|
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,19 +1 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
-
for (let key of __getOwnPropNames(from))
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
11
|
-
}
|
12
|
-
return to;
|
13
|
-
};
|
14
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
16
|
-
var src_exports = {};
|
17
|
-
module.exports = __toCommonJS(src_exports);
|
18
|
-
__reExport(src_exports, require("./Cognito"), module.exports);
|
19
|
-
//# sourceMappingURL=index.js.map
|
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,2 +1 @@
|
|
1
|
-
|
2
|
-
//# sourceMappingURL=index.mjs.map
|
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.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",
|
@@ -9,6 +9,11 @@
|
|
9
9
|
"files": [
|
10
10
|
"dist/**"
|
11
11
|
],
|
12
|
+
"repository": {
|
13
|
+
"type": "git",
|
14
|
+
"url": "https://github.com/JuniYadi/nodejs",
|
15
|
+
"directory": "packages/cognito"
|
16
|
+
},
|
12
17
|
"devDependencies": {
|
13
18
|
"@aws-sdk/client-cognito-identity": "^3.388.0",
|
14
19
|
"@aws-sdk/client-cognito-identity-provider": "^3.388.0",
|
@@ -19,9 +24,11 @@
|
|
19
24
|
"jest": "^29.6.2",
|
20
25
|
"ts-jest": "^29.1.1",
|
21
26
|
"tsup": "^5.12.9",
|
27
|
+
"typedoc": "^0.24.8",
|
22
28
|
"typescript": "^4.9.5",
|
23
|
-
"
|
24
|
-
"@juniyadi/
|
29
|
+
"@juniyadi/tsconfig": "0.0.0",
|
30
|
+
"@juniyadi/config-typedoc": "0.0.0",
|
31
|
+
"eslint-config-juniyadi": "0.0.1"
|
25
32
|
},
|
26
33
|
"publishConfig": {
|
27
34
|
"access": "public"
|
@@ -31,7 +38,8 @@
|
|
31
38
|
"@aws-sdk/client-cognito-identity-provider": "^3.388.0"
|
32
39
|
},
|
33
40
|
"scripts": {
|
34
|
-
"
|
41
|
+
"docs": "typedoc --out docs src/index.ts",
|
42
|
+
"build": "cross-env NODE_ENV=production tsup",
|
35
43
|
"dev": "tsup --watch",
|
36
44
|
"lint": "eslint \"src/**/*.ts*\"",
|
37
45
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
package/dist/Cognito.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/Cognito.ts"],"sourcesContent":["import {\n AdminCreateUserCommand,\n AdminCreateUserCommandInput,\n CognitoIdentityProviderClient,\n AdminSetUserPasswordCommand,\n AdminSetUserPasswordCommandOutput,\n AdminDisableUserCommand,\n AdminDisableUserCommandOutput,\n AdminDeleteUserCommand,\n AdminDeleteUserCommandOutput,\n} from \"@aws-sdk/client-cognito-identity-provider\";\nimport { randomBytes } from \"crypto\";\n\nexport interface ICognito {\n region?: string;\n userPoolId?: string;\n clientId?: string;\n}\n\nexport interface ICognitoAttributes {\n Name: string;\n Value: string;\n}\n\nexport interface ICognitoInviteUser {\n name: string;\n email: string;\n password: string;\n passwordTemporary?: string;\n autoConfirm?: boolean;\n phoneNumber?: string;\n sendEmail?: boolean;\n attributes?: ICognitoAttributes[];\n}\n\nexport class Cognito {\n public region: string;\n public userPoolId: string;\n public clientId: string;\n public cognitoIdentityProvider: CognitoIdentityProviderClient;\n\n constructor(opts?: ICognito) {\n this.region = opts?.region || process.env.AWS_REGION || \"\";\n this.userPoolId =\n opts?.userPoolId || process.env.COGNITO_USER_POOL_ID || \"\";\n this.clientId = opts?.clientId || process.env.COGNITO_CLIENT_ID || \"\";\n\n if (!this.region) throw new Error(\"AWS Region is required\");\n if (!this.userPoolId) throw new Error(\"Cognito User Pool ID is required\");\n if (!this.clientId) throw new Error(\"Cognito Client ID is required\");\n\n this.cognitoIdentityProvider = new CognitoIdentityProviderClient({\n region: this.region,\n });\n }\n\n /**\n * Generate a random password of a given length\n * @param length\n * @returns string\n */\n public randomPassword = (length = 12): string => {\n return randomBytes(256).toString(\"hex\").slice(0, length);\n };\n\n /**\n * Invite a user to the Cognito User Pool\n * @param opts\n */\n public inviteUser = async (opts: ICognitoInviteUser) => {\n const temporaryPassword = opts.passwordTemporary || this.randomPassword();\n\n const items: AdminCreateUserCommandInput = {\n UserPoolId: this.userPoolId,\n Username: opts.email,\n UserAttributes: [\n {\n Name: \"email\",\n Value: opts.email,\n },\n {\n Name: \"name\",\n Value: opts.name,\n },\n {\n Name: \"email_verified\",\n Value: \"true\",\n },\n ],\n DesiredDeliveryMediums: [\"EMAIL\"],\n ForceAliasCreation: false,\n MessageAction: opts.sendEmail ? \"RESEND\" : \"SUPPRESS\",\n TemporaryPassword: temporaryPassword,\n };\n\n // Add Phone Number to User Attributes if provided\n if (opts.phoneNumber && items.UserAttributes) {\n items.UserAttributes.push({\n Name: \"phone_number\",\n Value: opts.phoneNumber,\n });\n }\n\n // Add Other Attributes to User Attributes if provided\n if (opts.attributes && items.UserAttributes) {\n items.UserAttributes = items.UserAttributes.concat(opts.attributes);\n }\n\n const command = new AdminCreateUserCommand(items);\n try {\n const response = await this.cognitoIdentityProvider.send(command);\n\n /**\n * If the user is FORCE_CHANGE_PASSWORD, then change the password to the one provided\n * So that the user can login with the password provided\n */\n if (\n opts.autoConfirm &&\n response?.User?.UserStatus === \"FORCE_CHANGE_PASSWORD\"\n ) {\n const changePassword = await this.changePassword(\n opts.email,\n opts.password\n );\n\n if (changePassword?.$metadata?.httpStatusCode !== 200) {\n throw new Error(\"Error changing password\");\n }\n }\n\n return response;\n } catch (error) {\n throw error;\n }\n };\n\n /**\n * Change user password in Cognito User Pool\n * @param username - Username of the user\n * @param password - New password for the user\n * @returns Promise<AdminSetUserPasswordCommandOutput>\n */\n public changePassword = async (\n username: string,\n password: string\n ): Promise<AdminSetUserPasswordCommandOutput> => {\n const command = new AdminSetUserPasswordCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n Password: password,\n Permanent: true,\n });\n\n return this.cognitoIdentityProvider.send(command);\n };\n\n /**\n * Disable a user in Cognito User Pool\n * @param username - Username of the user\n * @returns Promise<AdminDisableUserCommandOutput>\n */\n public disableUser = async (\n username: string\n ): Promise<AdminDisableUserCommandOutput> => {\n const command = new AdminDisableUserCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n });\n\n return this.cognitoIdentityProvider.send(command);\n };\n\n /**\n * Delete a user in Cognito User Pool\n * @param username - Username of the user\n * @returns Promise<AdminDeleteUserCommandOutput>\n */\n public deleteUser = async (\n username: string\n ): Promise<AdminDeleteUserCommandOutput> => {\n // Disable the user first\n await this.disableUser(username);\n\n const command = new AdminDeleteUserCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n });\n\n return this.cognitoIdentityProvider.send(command);\n };\n}\n"],"mappings":"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","names":[]}
|
package/dist/Cognito.mjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/Cognito.ts"],"sourcesContent":["import {\n AdminCreateUserCommand,\n AdminCreateUserCommandInput,\n CognitoIdentityProviderClient,\n AdminSetUserPasswordCommand,\n AdminSetUserPasswordCommandOutput,\n AdminDisableUserCommand,\n AdminDisableUserCommandOutput,\n AdminDeleteUserCommand,\n AdminDeleteUserCommandOutput,\n} from \"@aws-sdk/client-cognito-identity-provider\";\nimport { randomBytes } from \"crypto\";\n\nexport interface ICognito {\n region?: string;\n userPoolId?: string;\n clientId?: string;\n}\n\nexport interface ICognitoAttributes {\n Name: string;\n Value: string;\n}\n\nexport interface ICognitoInviteUser {\n name: string;\n email: string;\n password: string;\n passwordTemporary?: string;\n autoConfirm?: boolean;\n phoneNumber?: string;\n sendEmail?: boolean;\n attributes?: ICognitoAttributes[];\n}\n\nexport class Cognito {\n public region: string;\n public userPoolId: string;\n public clientId: string;\n public cognitoIdentityProvider: CognitoIdentityProviderClient;\n\n constructor(opts?: ICognito) {\n this.region = opts?.region || process.env.AWS_REGION || \"\";\n this.userPoolId =\n opts?.userPoolId || process.env.COGNITO_USER_POOL_ID || \"\";\n this.clientId = opts?.clientId || process.env.COGNITO_CLIENT_ID || \"\";\n\n if (!this.region) throw new Error(\"AWS Region is required\");\n if (!this.userPoolId) throw new Error(\"Cognito User Pool ID is required\");\n if (!this.clientId) throw new Error(\"Cognito Client ID is required\");\n\n this.cognitoIdentityProvider = new CognitoIdentityProviderClient({\n region: this.region,\n });\n }\n\n /**\n * Generate a random password of a given length\n * @param length\n * @returns string\n */\n public randomPassword = (length = 12): string => {\n return randomBytes(256).toString(\"hex\").slice(0, length);\n };\n\n /**\n * Invite a user to the Cognito User Pool\n * @param opts\n */\n public inviteUser = async (opts: ICognitoInviteUser) => {\n const temporaryPassword = opts.passwordTemporary || this.randomPassword();\n\n const items: AdminCreateUserCommandInput = {\n UserPoolId: this.userPoolId,\n Username: opts.email,\n UserAttributes: [\n {\n Name: \"email\",\n Value: opts.email,\n },\n {\n Name: \"name\",\n Value: opts.name,\n },\n {\n Name: \"email_verified\",\n Value: \"true\",\n },\n ],\n DesiredDeliveryMediums: [\"EMAIL\"],\n ForceAliasCreation: false,\n MessageAction: opts.sendEmail ? \"RESEND\" : \"SUPPRESS\",\n TemporaryPassword: temporaryPassword,\n };\n\n // Add Phone Number to User Attributes if provided\n if (opts.phoneNumber && items.UserAttributes) {\n items.UserAttributes.push({\n Name: \"phone_number\",\n Value: opts.phoneNumber,\n });\n }\n\n // Add Other Attributes to User Attributes if provided\n if (opts.attributes && items.UserAttributes) {\n items.UserAttributes = items.UserAttributes.concat(opts.attributes);\n }\n\n const command = new AdminCreateUserCommand(items);\n try {\n const response = await this.cognitoIdentityProvider.send(command);\n\n /**\n * If the user is FORCE_CHANGE_PASSWORD, then change the password to the one provided\n * So that the user can login with the password provided\n */\n if (\n opts.autoConfirm &&\n response?.User?.UserStatus === \"FORCE_CHANGE_PASSWORD\"\n ) {\n const changePassword = await this.changePassword(\n opts.email,\n opts.password\n );\n\n if (changePassword?.$metadata?.httpStatusCode !== 200) {\n throw new Error(\"Error changing password\");\n }\n }\n\n return response;\n } catch (error) {\n throw error;\n }\n };\n\n /**\n * Change user password in Cognito User Pool\n * @param username - Username of the user\n * @param password - New password for the user\n * @returns Promise<AdminSetUserPasswordCommandOutput>\n */\n public changePassword = async (\n username: string,\n password: string\n ): Promise<AdminSetUserPasswordCommandOutput> => {\n const command = new AdminSetUserPasswordCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n Password: password,\n Permanent: true,\n });\n\n return this.cognitoIdentityProvider.send(command);\n };\n\n /**\n * Disable a user in Cognito User Pool\n * @param username - Username of the user\n * @returns Promise<AdminDisableUserCommandOutput>\n */\n public disableUser = async (\n username: string\n ): Promise<AdminDisableUserCommandOutput> => {\n const command = new AdminDisableUserCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n });\n\n return this.cognitoIdentityProvider.send(command);\n };\n\n /**\n * Delete a user in Cognito User Pool\n * @param username - Username of the user\n * @returns Promise<AdminDeleteUserCommandOutput>\n */\n public deleteUser = async (\n username: string\n ): Promise<AdminDeleteUserCommandOutput> => {\n // Disable the user first\n await this.disableUser(username);\n\n const command = new AdminDeleteUserCommand({\n UserPoolId: this.userPoolId,\n Username: username,\n });\n\n return this.cognitoIdentityProvider.send(command);\n };\n}\n"],"mappings":"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","names":[]}
|
package/dist/index.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./Cognito\";\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,sBAAd;","names":[]}
|
package/dist/index.mjs.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./Cognito\";\n"],"mappings":"AAAA,cAAc;","names":[]}
|