Skip to content
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

MNTOR-3435 - Convert Breaches.js to Typescript #4876

Merged
merged 11 commits into from
Aug 5, 2024
Merged

Conversation

codemist
Copy link
Collaborator

References:

Jira: MNTOR-3435

Description

Screenshot (if applicable)

Not applicable.

How to test

Checklist (Definition of Done)

  • Localization strings (if needed) have been added.
  • Commits in this PR are minimal and have descriptive commit messages.
  • I've added or updated the relevant sections in readme and/or code comments
  • I've added a unit test to test for potential regressions of this bug.
  • If this PR implements a feature flag or experimentation, the Ship Behind Feature Flag status in Jira has been set
  • Product Owner accepted the User Story (demo of functionality completed) or waived the privilege.
  • All acceptance criteria are met.
  • Jira ticket has been updated (if needed) to match changes made during the development process.
  • Jira ticket has been updated (if needed) with suggestions for QA when this PR is deployed to stage.

@codemist codemist changed the base branch from main to MNTOR-3101-ts-utils-hibp July 26, 2024 13:15
Comment on lines 205 to 202
if (useBreachId) {
breach.IsResolved = breachResolutionV2[breach.Id]?.isResolved;
breach.ResolutionsChecked =
breachResolutionV2[breach.Id]?.resolutionsChecked || [];
} else {
// TODO: remove after MNTOR-978
breach.IsResolved = breachResolutionV2[breach.recencyIndex]?.isResolved;
breach.ResolutionsChecked =
breachResolutionV2[breach.recencyIndex]?.resolutionsChecked || [];
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Vinnl Had an issue here where the expected type is HibpLikeDbBreach but I think this expects the SubscriberBreach object instead, which would contain the IsResolved etc. property. Is this something worth refactoring?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think instead of trying to modify the foundBreachesWithRecency array (of type HibpLikeDbBreach[]) in place to try to make it look like SubscriberBreach[], it's probably best to just create a new array of SubscriberBreaches.

@codemist codemist requested a review from Vinnl July 26, 2024 13:17
@Vinnl Vinnl force-pushed the MNTOR-3101-ts-utils-hibp branch from 0cc2c74 to afdb5d1 Compare July 29, 2024 12:01
Base automatically changed from MNTOR-3101-ts-utils-hibp to main July 29, 2024 12:08
@codemist codemist force-pushed the MNTOR-3435-breaches branch from 1808876 to 2a64cd3 Compare July 29, 2024 14:19
@codemist codemist marked this pull request as ready for review July 29, 2024 14:19
@codemist codemist requested review from rhelmer and mansaj July 29, 2024 14:19
@@ -101,7 +101,7 @@ function appendBreachResolutionChecklist(
for (const { breaches } of verifiedEmails) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Vinnl I had to rebase this code, could you check that it did not affect the changes in the hibp.js typescript migration?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I added ec002a1 to restore a couple of changes that were resolved the wrong way around.

FWIW, if I have a merge conflict after rebasing from main, I simply look at the code that is in main - if the conflict is different from main and is not a change that I intentionally made as part of the PR, I restore it back to what's currently in main.

@codemist codemist force-pushed the MNTOR-3435-breaches branch from a948e05 to d9197e7 Compare July 29, 2024 15:20
Copy link


const useBreachId = user.breach_resolution?.useBreachId;

// Not entirely sure what this section of the code is doing, but it's not typed
Copy link
Collaborator

Choose a reason for hiding this comment

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

From git history, looks like this is backwards-compat code for #2757 - @mansaj should we keep this in place or can it be removed now? If it needs to stay I think having a comment here to explain the situation would be good.

Copy link
Collaborator Author

@codemist codemist Jul 30, 2024

Choose a reason for hiding this comment

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

@mansaj Keeping it here but explicitly typing it as any, unless you believe that can be safely removed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This recency code is no longer necessary, though we can refactor in another PR (as we talked about in the tech meeting)

Copy link
Collaborator Author

@codemist codemist Aug 2, 2024

Choose a reason for hiding this comment

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

@mansaj Removed the recency code in this commit b0826a3

Vinnl and others added 8 commits August 2, 2024 07:47
This removes the `Breach` type in functions/universal/breaches,
which was created when first introducing TypeScript and the flow
of data was still unclear, but by now had overlap with other types
and no clear provenance.

Instead, there are now three breach-related types, that represent
where the data came from:

- HibpGetBreachesResponse: this is an array of breach elements as
                           returned from the HIBP API, unprocessed.
                           Properties are in PascalCase, so are a
                           breach's data classes.
- BreachRow: this is a breach's data as stored in our database,
             along with some data we added to it, such as a favicon
             URL. Properties are snake_case, and data classes are
             lowercased and kebab-cased by the
             formatDataClassesArray function.
- HibpLikeDbBreach: this is a breach's data fetched from the
                    database, but stored in an object meant to look
                    like the ones in HibpGetBreachesResponse. In
                    other words, it contains the same data as
                    BreachRow (including lowercased, kebab-cased
                    data classes), but on PascalCase properties.

The latter is somewhat of a historical artefact, because we used
to try to load breaches from our database, then if our database
didn't contain any breaches yet, fetch them live from the HIBP API
and continue working with that.

We no longer do that: now, even after fetching them from the HIBP
API, we do a new query to get them from the database and process
them into HibpLikeDbBreach, so that we can assume a consisent data
structure everywhere we work with breaches.
@codemist codemist force-pushed the MNTOR-3435-breaches branch from fbcdfcb to b0826a3 Compare August 2, 2024 11:50
@codemist codemist requested a review from rhelmer August 2, 2024 11:57
Copy link
Collaborator

@rhelmer rhelmer left a comment

Choose a reason for hiding this comment

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

lgtm I only have a few comment-related suggestions.


// get new breaches since last shown
for (const emailEntry of verifiedEmails) {
// /** @type {any[]} */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this comment be removed now?


function addRecencyIndex(foundBreaches: HibpLikeDbBreach[]) {
// /**
// * @type {any[]}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question re: this type definition - we were using these JSDoc type annotations to get a little type checking for JS files before we fully switched to typescript but we shouldn't need them anymore.

console.error(errMsg);
captureMessage(errMsg);

// @ts-ignore: function will be deprecated
Copy link
Collaborator

@rhelmer rhelmer Aug 3, 2024

Choose a reason for hiding this comment

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

If you put @deprecated in a comment above the function definition then VSCode and other tooling will pick that up.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Heads-up that that needs to be in a JSDoc comment, i.e. one that starts with /** rather than just /* or //.

@codemist codemist merged commit 324cebb into main Aug 5, 2024
15 checks passed
@codemist codemist deleted the MNTOR-3435-breaches branch August 5, 2024 12:35
Copy link

github-actions bot commented Aug 5, 2024

Cleanup completed - database 'blurts-server-pr-4876' destroyed, cloud run service 'blurts-server-pr-4876' destroyed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants