-
Notifications
You must be signed in to change notification settings - Fork 223
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
Conversation
src/utils/breaches.ts
Outdated
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 || []; | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 SubscriberBreach
es.
0cc2c74
to
afdb5d1
Compare
1808876
to
2a64cd3
Compare
@@ -101,7 +101,7 @@ function appendBreachResolutionChecklist( | |||
for (const { breaches } of verifiedEmails) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
a948e05
to
d9197e7
Compare
Preview URL 🚀 : https://blurts-server-pr-4876-mgjlpikfea-uk.a.run.app |
src/utils/breaches.ts
Outdated
|
||
const useBreachId = user.breach_resolution?.useBreachId; | ||
|
||
// Not entirely sure what this section of the code is doing, but it's not typed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
fbcdfcb
to
b0826a3
Compare
There was a problem hiding this 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.
src/utils/breaches.ts
Outdated
|
||
// get new breaches since last shown | ||
for (const emailEntry of verifiedEmails) { | ||
// /** @type {any[]} */ |
There was a problem hiding this comment.
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?
src/utils/breaches.ts
Outdated
|
||
function addRecencyIndex(foundBreaches: HibpLikeDbBreach[]) { | ||
// /** | ||
// * @type {any[]} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 //
.
Cleanup completed - database 'blurts-server-pr-4876' destroyed, cloud run service 'blurts-server-pr-4876' destroyed |
References:
Jira: MNTOR-3435
Description
Screenshot (if applicable)
Not applicable.
How to test
Checklist (Definition of Done)