@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 +6 -0
- package/dist/Cognito.d.mts +114 -0
- package/dist/Cognito.d.ts +15 -1
- package/dist/Cognito.js +10 -1
- package/dist/Cognito.mjs +1 -1
- package/dist/chunk-EEMFQFKO.mjs +6 -0
- package/dist/chunk-PXDEYENQ.js +8 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.js +10 -1
- package/dist/index.mjs +1 -1
- package/package.json +19 -8
package/README.md
ADDED
@@ -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
|
-
|
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
|
-
|
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;
|
package/dist/index.d.mts
ADDED
package/dist/index.js
CHANGED
@@ -1 +1,10 @@
|
|
1
|
-
|
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
|
-
|
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.
|
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.
|
32
|
+
"@types/node": "^20.5.0",
|
22
33
|
"aws-sdk-client-mock": "^3.0.0",
|
23
|
-
"eslint": "^8.
|
34
|
+
"eslint": "^8.47.0",
|
24
35
|
"jest": "^29.6.2",
|
25
36
|
"ts-jest": "^29.1.1",
|
26
|
-
"tsup": "^
|
37
|
+
"tsup": "^7.2.0",
|
27
38
|
"typedoc": "^0.24.8",
|
28
|
-
"typescript": "^
|
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"
|