@juniyadi/cognito 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
@@ -27,7 +27,7 @@ interface ICognitoAdminLoginResponse {
|
|
27
27
|
AccessToken: string;
|
28
28
|
IdToken: string;
|
29
29
|
RefreshToken: string;
|
30
|
-
NewDeviceMetadata
|
30
|
+
NewDeviceMetadata?: {
|
31
31
|
DeviceKey: string | null;
|
32
32
|
DeviceGroupKey: null;
|
33
33
|
};
|
@@ -144,7 +144,7 @@ declare class Cognito {
|
|
144
144
|
* const response = await cognito.adminLogin("username", "password");
|
145
145
|
* console.log(response);
|
146
146
|
*/
|
147
|
-
adminLogin: (username: string, password: string) => Promise<ICognitoAdminLoginResponse>;
|
147
|
+
adminLogin: (username: string, password: string, rememberMe?: boolean) => Promise<ICognitoAdminLoginResponse>;
|
148
148
|
/**
|
149
149
|
* Refresh Token for Admin User
|
150
150
|
*
|
package/dist/index.js
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
var clientCognitoIdentityProvider = require('@aws-sdk/client-cognito-identity-provider');
|
4
4
|
var amazonCognitoIdentityJs = require('amazon-cognito-identity-js');
|
5
5
|
var randomString = require('@juniyadi/random-string');
|
6
|
-
var
|
6
|
+
var u = require('dayjs');
|
7
7
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
9
9
|
|
10
|
-
var
|
10
|
+
var u__default = /*#__PURE__*/_interopDefault(u);
|
11
11
|
|
12
|
-
var
|
12
|
+
var c=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),t=e.passwordTemporary||this.randomPassword(12),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:t};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 d=new clientCognitoIdentityProvider.AdminCreateUserCommand(n);try{let i=await this.cognitoIdentityProvider.send(d);return e.autoConfirm&&i?.User?.UserStatus==="FORCE_CHANGE_PASSWORD"&&await this.changePassword(e.email,r),e.group&&await this.addUserToGroup(e.email,e.group),i}catch(i){throw i}};this.changePassword=async(e,r)=>{let t=new clientCognitoIdentityProvider.AdminSetUserPasswordCommand({UserPoolId:this.userPoolId,Username:e,Password:r,Permanent:!0});return this.cognitoIdentityProvider.send(t)};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 t=new clientCognitoIdentityProvider.AdminAddUserToGroupCommand({UserPoolId:this.userPoolId,Username:e,GroupName:r});return this.cognitoIdentityProvider.send(t)};this.adminLogin=async(e,r,t=!1)=>{try{let n,d=new amazonCognitoIdentityJs.AuthenticationDetails({Username:e,Password:r}),i=new amazonCognitoIdentityJs.CognitoUserPool({UserPoolId:this.userPoolId,ClientId:this.clientId}),m=new amazonCognitoIdentityJs.CognitoUser({Username:e,Pool:i}),a=await new Promise((o,s)=>{m.authenticateUser(d,{onSuccess:o,onFailure:s});});t&&(await new Promise((o,s)=>{m.setDeviceStatusRemembered({onSuccess:o,onFailure:s});}),n=await new Promise((o,s)=>{m.getDevice({onSuccess:o,onFailure:s});}));let l=a.getIdToken().getExpiration();return {TokenType:"Bearer",ExpiresIn:u__default.default.unix(l).diff(u__default.default(),"second")+1,AccessToken:a.getAccessToken().getJwtToken(),IdToken:a.getIdToken().getJwtToken(),RefreshToken:a.getRefreshToken().getToken(),NewDeviceMetadata:n?.Device?{DeviceKey:n.Device.DeviceKey,DeviceGroupKey:null}:void 0}}catch(n){throw n}};this.adminRefreshToken=async(e,r)=>{let t=new clientCognitoIdentityProvider.AdminInitiateAuthCommand({UserPoolId:this.userPoolId,ClientId:this.clientId,AuthFlow:"REFRESH_TOKEN_AUTH",AuthParameters:{REFRESH_TOKEN:e,DEVICE_KEY:r}});return this.cognitoIdentityProvider.send(t)};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});}};
|
13
13
|
|
14
|
-
exports.Cognito =
|
14
|
+
exports.Cognito = c;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@juniyadi/cognito",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.2.0",
|
4
4
|
"types": "./dist/index.d.ts",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"sideEffects": false,
|
@@ -14,8 +14,8 @@
|
|
14
14
|
"directory": "packages/cognito"
|
15
15
|
},
|
16
16
|
"devDependencies": {
|
17
|
-
"@aws-sdk/client-cognito-identity": "^3.
|
18
|
-
"@aws-sdk/client-cognito-identity-provider": "^3.
|
17
|
+
"@aws-sdk/client-cognito-identity": "^3.637.0",
|
18
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.637.0",
|
19
19
|
"@types/jest": "^29.5.12",
|
20
20
|
"@types/node": "^20.14.9",
|
21
21
|
"amazon-cognito-identity-js": "^6.3.12",
|
@@ -29,15 +29,15 @@
|
|
29
29
|
"typescript": "^5.5.2",
|
30
30
|
"@juniyadi/config-typedoc": "0.0.0",
|
31
31
|
"@juniyadi/random-string": "0.3.0",
|
32
|
-
"
|
33
|
-
"
|
32
|
+
"@juniyadi/tsconfig": "0.0.0",
|
33
|
+
"eslint-config-juniyadi": "0.0.1"
|
34
34
|
},
|
35
35
|
"publishConfig": {
|
36
36
|
"access": "public"
|
37
37
|
},
|
38
38
|
"peerDependencies": {
|
39
|
-
"@aws-sdk/client-cognito-identity": "^3.
|
40
|
-
"@aws-sdk/client-cognito-identity-provider": "^3.
|
39
|
+
"@aws-sdk/client-cognito-identity": "^3.637.0",
|
40
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.637.0",
|
41
41
|
"amazon-cognito-identity-js": "^6.3.12",
|
42
42
|
"dayjs": "^1.11.11",
|
43
43
|
"@juniyadi/random-string": "0.3.0"
|