@juniyadi/cognito 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/dist/index.d.mts +126 -2
- package/dist/index.d.ts +126 -2
- package/dist/index.js +4 -6
- package/dist/index.mjs +6 -1
- package/package.json +6 -2
- package/dist/Cognito.d.mts +0 -114
- package/dist/Cognito.d.ts +0 -114
- package/dist/Cognito.js +0 -10
- package/dist/Cognito.mjs +0 -1
- package/dist/chunk-EEMFQFKO.mjs +0 -6
- package/dist/chunk-PXDEYENQ.js +0 -8
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Juni Yadi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
CHANGED
@@ -1,2 +1,126 @@
|
|
1
|
-
|
2
|
-
import '@aws-sdk/client-cognito-identity-provider';
|
1
|
+
import * as _aws_sdk_client_cognito_identity_provider from '@aws-sdk/client-cognito-identity-provider';
|
2
|
+
import { CognitoIdentityProviderClient, AdminSetUserPasswordCommandOutput, AdminDisableUserCommandOutput, AdminEnableUserCommandOutput, 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
|
+
* Enable a user in Cognito User Pool
|
79
|
+
* @param username - Username of the user
|
80
|
+
* @returns Promise<AdminEnableUserCommandOutput>
|
81
|
+
* @example
|
82
|
+
* const cognito = new Cognito();
|
83
|
+
* const users = await cognito.enableUser("johndoe@example.com");
|
84
|
+
* console.log(users.Users);
|
85
|
+
*
|
86
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminEnableUser.html
|
87
|
+
*/
|
88
|
+
enableUser: (username: string) => Promise<AdminEnableUserCommandOutput>;
|
89
|
+
/**
|
90
|
+
* Delete a user in Cognito User Pool
|
91
|
+
* @param username - Username of the user
|
92
|
+
* @returns Promise<AdminDeleteUserCommandOutput>
|
93
|
+
* @example
|
94
|
+
* const cognito = new Cognito();
|
95
|
+
* const users = await cognito.deleteUser("johndoe@example.com");
|
96
|
+
* console.log(users.Users);
|
97
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminDeleteUser.html
|
98
|
+
*/
|
99
|
+
deleteUser: (username: string) => Promise<AdminDeleteUserCommandOutput>;
|
100
|
+
/**
|
101
|
+
* List for users in Cognito User Pool
|
102
|
+
* @param opts
|
103
|
+
* @returns Promise<ListUsersCommandOutput>
|
104
|
+
* @example
|
105
|
+
* const cognito = new Cognito();
|
106
|
+
* const users = await cognito.listUsers({ email: "johndoe@example.com" });
|
107
|
+
* console.log(users.Users);
|
108
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html
|
109
|
+
*/
|
110
|
+
listUsers: (filter?: string) => Promise<_aws_sdk_client_cognito_identity_provider.ListUsersCommandOutput>;
|
111
|
+
/**
|
112
|
+
* Add a user to a group in Cognito User Pool
|
113
|
+
* @param username - Username of the user
|
114
|
+
* @param groupName - Name of the group
|
115
|
+
* @returns Promise<AdminAddUserToGroupCommandOutput>
|
116
|
+
* @example
|
117
|
+
* const cognito = new Cognito();
|
118
|
+
* const users = await cognito.addUserToGroup("johndoe@example.com", "Admin");
|
119
|
+
* console.log(users.Users);
|
120
|
+
*
|
121
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminAddUserToGroup.html
|
122
|
+
*/
|
123
|
+
addUserToGroup: (username: string, groupName: string) => Promise<AdminAddUserToGroupCommandOutput>;
|
124
|
+
}
|
125
|
+
|
126
|
+
export { Cognito, ICognito, ICognitoAttributes, ICognitoInviteUser };
|
package/dist/index.d.ts
CHANGED
@@ -1,2 +1,126 @@
|
|
1
|
-
|
2
|
-
import '@aws-sdk/client-cognito-identity-provider';
|
1
|
+
import * as _aws_sdk_client_cognito_identity_provider from '@aws-sdk/client-cognito-identity-provider';
|
2
|
+
import { CognitoIdentityProviderClient, AdminSetUserPasswordCommandOutput, AdminDisableUserCommandOutput, AdminEnableUserCommandOutput, 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
|
+
* Enable a user in Cognito User Pool
|
79
|
+
* @param username - Username of the user
|
80
|
+
* @returns Promise<AdminEnableUserCommandOutput>
|
81
|
+
* @example
|
82
|
+
* const cognito = new Cognito();
|
83
|
+
* const users = await cognito.enableUser("johndoe@example.com");
|
84
|
+
* console.log(users.Users);
|
85
|
+
*
|
86
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminEnableUser.html
|
87
|
+
*/
|
88
|
+
enableUser: (username: string) => Promise<AdminEnableUserCommandOutput>;
|
89
|
+
/**
|
90
|
+
* Delete a user in Cognito User Pool
|
91
|
+
* @param username - Username of the user
|
92
|
+
* @returns Promise<AdminDeleteUserCommandOutput>
|
93
|
+
* @example
|
94
|
+
* const cognito = new Cognito();
|
95
|
+
* const users = await cognito.deleteUser("johndoe@example.com");
|
96
|
+
* console.log(users.Users);
|
97
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminDeleteUser.html
|
98
|
+
*/
|
99
|
+
deleteUser: (username: string) => Promise<AdminDeleteUserCommandOutput>;
|
100
|
+
/**
|
101
|
+
* List for users in Cognito User Pool
|
102
|
+
* @param opts
|
103
|
+
* @returns Promise<ListUsersCommandOutput>
|
104
|
+
* @example
|
105
|
+
* const cognito = new Cognito();
|
106
|
+
* const users = await cognito.listUsers({ email: "johndoe@example.com" });
|
107
|
+
* console.log(users.Users);
|
108
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html
|
109
|
+
*/
|
110
|
+
listUsers: (filter?: string) => Promise<_aws_sdk_client_cognito_identity_provider.ListUsersCommandOutput>;
|
111
|
+
/**
|
112
|
+
* Add a user to a group in Cognito User Pool
|
113
|
+
* @param username - Username of the user
|
114
|
+
* @param groupName - Name of the group
|
115
|
+
* @returns Promise<AdminAddUserToGroupCommandOutput>
|
116
|
+
* @example
|
117
|
+
* const cognito = new Cognito();
|
118
|
+
* const users = await cognito.addUserToGroup("johndoe@example.com", "Admin");
|
119
|
+
* console.log(users.Users);
|
120
|
+
*
|
121
|
+
* @see https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminAddUserToGroup.html
|
122
|
+
*/
|
123
|
+
addUserToGroup: (username: string, groupName: string) => Promise<AdminAddUserToGroupCommandOutput>;
|
124
|
+
}
|
125
|
+
|
126
|
+
export { Cognito, ICognito, ICognitoAttributes, ICognitoInviteUser };
|
package/dist/index.js
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
3
|
+
var clientCognitoIdentityProvider = require('@aws-sdk/client-cognito-identity-provider');
|
4
|
+
var randomString = require('@juniyadi/random-string');
|
4
5
|
|
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});}};
|
5
7
|
|
6
|
-
|
7
|
-
Object.defineProperty(exports, 'Cognito', {
|
8
|
-
enumerable: true,
|
9
|
-
get: function () { return chunkPXDEYENQ_js.a; }
|
10
|
-
});
|
8
|
+
exports.Cognito = s;
|
package/dist/index.mjs
CHANGED
@@ -1 +1,6 @@
|
|
1
|
-
|
1
|
+
import { AdminCreateUserCommand, AdminSetUserPasswordCommand, AdminDisableUserCommand, AdminEnableUserCommand, AdminDeleteUserCommand, ListUsersCommand, AdminAddUserToGroupCommand, CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
|
2
|
+
import { generate } from '@juniyadi/random-string';
|
3
|
+
|
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
|
+
|
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.0",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"exports": {
|
@@ -44,9 +44,13 @@
|
|
44
44
|
"publishConfig": {
|
45
45
|
"access": "public"
|
46
46
|
},
|
47
|
+
"dependencies": {
|
48
|
+
"@juniyadi/random-string": "0.1.0"
|
49
|
+
},
|
47
50
|
"peerDependencies": {
|
48
51
|
"@aws-sdk/client-cognito-identity": "^3.388.0",
|
49
|
-
"@aws-sdk/client-cognito-identity-provider": "^3.388.0"
|
52
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.388.0",
|
53
|
+
"@juniyadi/random-string": "0.1.0"
|
50
54
|
},
|
51
55
|
"scripts": {
|
52
56
|
"docs": "typedoc --out docs src/index.ts",
|
package/dist/Cognito.d.mts
DELETED
@@ -1,114 +0,0 @@
|
|
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
DELETED
@@ -1,114 +0,0 @@
|
|
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.js
DELETED
package/dist/Cognito.mjs
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export { a as Cognito } from './chunk-EEMFQFKO.mjs';
|
package/dist/chunk-EEMFQFKO.mjs
DELETED
@@ -1,6 +0,0 @@
|
|
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 };
|
package/dist/chunk-PXDEYENQ.js
DELETED
@@ -1,8 +0,0 @@
|
|
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;
|