Skip to content

refactor(amazon-cognito-identity-js): refactor issue 8969 better typings #9935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Yoshiitaka
Copy link

@Yoshiitaka Yoshiitaka commented May 25, 2022

Issue ##8969,

Better type definitions for amazon-cognito-identity-js.

Checklist

  • PR description included

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@siegerts siegerts added the first-time-contributor The contribution is the first for this user in the repo label May 25, 2022
@ShawnCockburn
Copy link

+1

@chintannp
Copy link
Contributor

Hey @Yoshiitaka ,
Thanks for your contribution to the AWS Amplify JS Library. We are actively reviewing your PR and will provide feedback soon if needed.

@chintannp
Copy link
Contributor

@Yoshiitaka ,
I won't be able fix the merge conflict as your forked branch is behind. Can you fix the merge conflicts so that we can review the PR and be able to merge it?

@Yoshiitaka
Copy link
Author

@chintannp
Thank you check this PR.
I updated the forked branch and fixed the conflicts part :)
Please Could you review this PR?

Copy link
Contributor

@elorzafe elorzafe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yoshiitaka thanks for this PR,

I have some concerns with typing some information that is available for getters, Another big concern is that attributes and token payload can be configured on the UserPool and could break the type.

What do you think?

Comment on lines 449 to 466
payload: {
sub: string;
email_verified: boolean;
iss: string;
phone_number_verified: boolean;
'cognito:username': string;
given_name: string;
origin_jti: string;
aud: string;
event_id: string;
token_use: string;
auth_time: number;
phone_number: string;
exp: number;
iat: number;
family_name: string;
jti: string;
email: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A problem here is that this payload can modified ona userpool lambda trigger

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm...
In other words, does this place have to be as follows, not a strict type?

payload: { [key: string]: any };

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct


export interface CognitoAccessToken {
jwtToken: string;
payload: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A the problem here is that decodePayload return type is { [id: string]: any }

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm..
In other words, does this place have to be as follows, not a strict type too?

payload: { [key: string]: any };

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, the interface could be more restricted. I need to verify if those claims are same across every userpool

Comment on lines 94 to 103
attributes: {
email: string;
email_verified: boolean;
family_name: string;
given_name: string;
phone_number: string;
phone_number_verified: boolean;
sub: string;
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those got lazily load, and after that those are available, the other problem is that a user can have more attributes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, I began think that it is better not to create strict type information for Cognito User attributes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, do you want to revert that change?

Copy link
Author

@Yoshiitaka Yoshiitaka Aug 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for comment. yes, revert this changes.

Comment on lines 401 to 405
public clockDrift: number;
public idToken: CognitoIdToken;
public accessToken: CognitoAccessToken;
public refreshToken: CognitoRefreshToken;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to expose this values if there are already getters?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm see... That is as you pointed out.
there are already created the getter,
there was no need to expose public values.
Thank you :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to revert that change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, revert this changes too.

@chintannp
Copy link
Contributor

@Yoshiitaka, In order to get this change out quickly, Can you please review and address the feedback provided by @elorzafe ?

@Yoshiitaka
Copy link
Author

Yoshiitaka commented Jul 30, 2022

@elorzafe
Thank you for reviewing.
This PR was dealt with a long time ago, So I will check the points to be pointed out and corrections from now.

Certainly, I was understood that the token payload may break the mold as you pointed out.

@Yoshiitaka
Copy link
Author

@chintannp
Sorry for the late confirmation and reply.
I will check the review pointed out from this and correct it.

@chintannp
Copy link
Contributor

@Yoshiitaka , Can you address the feedback provide by @elorzafe ?

@Yoshiitaka
Copy link
Author

@chintannp
I have already responded to @elorzafe 's feedback comment, So Please could you check it?

@codecov-commenter
Copy link

codecov-commenter commented Aug 23, 2022

Codecov Report

Merging #9935 (e463eda) into main (91fdcd9) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #9935   +/-   ##
=======================================
  Coverage   84.40%   84.40%           
=======================================
  Files         258      258           
  Lines       18698    18698           
  Branches     4021     4021           
=======================================
  Hits        15782    15782           
  Misses       2826     2826           
  Partials       90       90           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@aminya
Copy link

aminya commented Jan 18, 2023

When I use Hub.listen and get the payload.data, the found CognitoUser doesn't have any methods. That's because it is serialized. So, the properties should be still added. The getters are not enough.

@cwomack cwomack added the amazon-cognito-identity-js Used for issues related to this specific package within the monorepo label Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
amazon-cognito-identity-js Used for issues related to this specific package within the monorepo external-contributor first-time-contributor The contribution is the first for this user in the repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants