-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
feat: Adding a new controller for Metametrics Data Deletion #24503
base: develop
Are you sure you want to change the base?
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Builds ready [614ccfd]
Page Load Metrics (880 ± 596 ms)
Bundle size diffs
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #24503 +/- ##
===========================================
+ Coverage 65.70% 65.78% +0.08%
===========================================
Files 1366 1368 +2
Lines 54361 54478 +117
Branches 14141 14162 +21
===========================================
+ Hits 35715 35838 +123
+ Misses 18646 18640 -6 ☔ View full report in Codecov by Sentry. |
Builds ready [d1cdd73]
Page Load Metrics (786 ± 599 ms)
Bundle size diffs
|
@@ -5085,6 +5086,42 @@ export function setName( | |||
}) as 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 you add a unit test for each of these?
app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.ts
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,138 @@ | |||
import { ObservableStore } from '@metamask/obs-store'; |
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.
We should add some unit tests for this file.
} | ||
|
||
async createMetaMetricsDataDeletionTask(): Promise<DataDeletionResponse> { | ||
const segmentSourceId = process.env.SEGMENT_DELETE_API_SOURCE_ID; |
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.
The definition of these constant variables can happen outside of this method and outside of the class. We don't need to re-define them every time the method is called.
); | ||
|
||
this.store.updateState({ | ||
metaMetricsDataDeletionId: data?.data?.regulateId as string, |
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 data?.data?.regulateId
is undefined
, should we return an error?
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 believe the api will return a regulate ID if the request did not error. So I have made the type to just string than string | undefined
, and initiated the state variable to empty string.
const { data } = await fetchDeletionRegulationStatus( | ||
this.store.getState().metaMetricsDataDeletionId as string, | ||
); | ||
const regulation = data?.data?.regulation as Record<string, string>; |
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 data?.data?.regulation
is undefined
, should we return an error?
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 believe the api will return a regulation if we have a valid Id, otherwise, it would probably error. I have added an empty check for deleteRegulateId
to make sure we have a value before we call the api..
const segmentSourceId = process.env.SEGMENT_DELETE_API_SOURCE_ID; | ||
const segmentRegulationEndpoint = process.env.SEGMENT_REGULATIONS_ENDPOINT; | ||
|
||
if (!segmentSourceId || !segmentRegulationEndpoint) { |
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.
Maybe this validation is unneeded here, and can just happen within the services?
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.
moved
); | ||
return response as DeleteRegulationAPIResponse; | ||
} catch (error: unknown) { | ||
throw new Error('Analytics Deletion Task Error'); |
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.
Any reason not to throw the error
object received in the catch?
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.
Removed the try-catch in the service class, and it is being handled in the controller.
const segmentRegulationEndpoint = process.env.SEGMENT_REGULATIONS_ENDPOINT; | ||
|
||
try { | ||
const response: unknown = await fetchWithTimeout( |
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 wonder if we can type the response in a way other that unknown
🤔
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.
The type was explicitly mentioned as it is erroring while converting the Response
type returned from fetchWithTimeout
to DeleteRegulationAPIResponse. We can also typecast while returning the response like this response as unknown as DeleteRegulationAPIResponse
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.
First review complete. I have left some comments
.metamaskrc.dist
Outdated
@@ -6,6 +6,8 @@ INFURA_PROJECT_ID=00000000000 | |||
|
|||
;PASSWORD=METAMASK PASSWORD | |||
;SEGMENT_WRITE_KEY= | |||
;SEGMENT_DELETE_API_SOURCE_ID= |
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.
Could you clarify what these environment variables are?
It was my understanding that we're using our own API for this, not using Segment directly. Our API will also be requesting deletion from more than just Segment. If that's the case, making these environment variables named SEGMENT_
seems inaccurate
app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.ts
Outdated
Show resolved
Hide resolved
app/scripts/controllers/metametrics-data-deletion/metametrics-data-deletion.ts
Outdated
Show resolved
Hide resolved
data: RegulationId | CurrentRegulationStatus; | ||
}; | ||
|
||
export enum DeleteRegulationStatus { |
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.
Are there API docs somewhere that can explain what status exist, and what they mean?
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.
The existing statuses are mentioned here:
https://docs.segmentapis.com/tag/Deletion-and-Suppression#operation/listRegulationsFromSource
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.
Could you update the comment to reference these docs?
fetchDeletionRegulationStatus, | ||
} from './services/services'; | ||
|
||
export type DataDeleteDate = string; |
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.
Nit: Ideally each type would have a TSDoc block that explains what the type is for. This is especially useful because the descriptions show up in Intellisense tooltips in supporting editors such as VSCode
00838c9
to
b540dfc
Compare
The `nock` library is not compatible with the fake timers we use in unit tests because it uses the Node.js `timers` API. This API is not mocked correctly by the version of Jest we are using. Jest uses `@sinon/fake-timers` internally, which didn't support mocking the Node.js `timers` API until v11.0.0 (see sinonjs/fake-timers#467) This package is updated in Jest as part of the v30 release, which is currently under development. To workaround this problem in the meantime, the `nock` package has been updated and patched to use global timers rather than the `timers` API. Global timers are mocked correctly. This was required for some unit tests that I will be submitting in a different PR, intended for #24503
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** The `nock` library is not compatible with the fake timers we use in unit tests because it uses the Node.js `timers` API. This API is not mocked correctly by the version of Jest we are using. Jest uses `@sinon/fake-timers` internally, which didn't support mocking the Node.js `timers` API until v11.0.0 (see sinonjs/fake-timers#467) This package is updated in Jest as part of the v30 release, which is currently under development. To workaround this problem in the meantime, the `nock` package has been updated and patched to use global timers rather than the `timers` API. Global timers are mocked correctly. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24805?quickstart=1) ## **Related issues** This was required for some unit tests that I will be submitting in a different PR, intended for #24503 ## **Manual testing steps** N/A ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** The `circuitBreakDuration`, `degradedThreshold`, and `timeout` are now configurable for the `DataDeletionService`. This configuration is relied upon in the unit tests, to be added in a later PR. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24806?quickstart=1) ## **Related issues** This is an improvement for the PR #24503 ## **Manual testing steps** N/A ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
Builds ready [3ef9147]
Page Load Metrics (945 ± 578 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** The `DataDeletionService` has been moved to a `services` directory, independent of controllers. This was done to reinforce that services are independent of controllers, and can be used outside of them. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24863?quickstart=1) ## **Related issues** This is an improvement for the PR #24503 ## **Manual testing steps** N/A ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
The `DataDeletionController` has been decoupled from the `MetaMetricsController` by updating the constructor parameters to expect just a function for getting the MetaMetrics ID, rather than the entire `MetaMetricsController` state. This vastly simplifies the API surface, making it easier to audit and test. It also prevents the `DataDeletionController` from having the capability to make changes to the `MetaMetricsController` state. This is an improvement for #24503
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** The `DataDeletionController` has been decoupled from the `MetaMetricsController` by updating the constructor parameters to expect just a function for getting the MetaMetrics ID, rather than the entire `MetaMetricsController` state. This vastly simplifies the API surface, making it easier to audit and test. It also prevents the `DataDeletionController` from having the capability to make changes to the `MetaMetricsController` state. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24870?quickstart=1) ## **Related issues** This is an improvement for #24503 ## **Manual testing steps** N/A ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** A single test has been added, along with a helper setup function that is designed to be used for further unit tests as well. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24879?quickstart=1) ## **Related issues** This is an improvement for the PR #24503 ## **Manual testing steps** N/A ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
Builds ready [4a07c1a]
Page Load Metrics (119 ± 139 ms)
|
## **Description** Add unit tests for the `createDataDeletionRegulationTask` method of `DataDeletionService`. One of the two service methods is now fully tested. The remaining method will be tested in a later PR. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24816?quickstart=1) ## **Related issues** This is an improvement for the PR #24503 ## **Manual testing steps** N/A ## **Screenshots/Recordings** N/A ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: Niranjana Binoy <[email protected]>
Description
We are adding a new controller,
MetaMetricsDataDeletionController,
and a service class for MetaMetrics data deletion. The service class will have the API interaction for the data deletion, which will create the data deletion regulation and check the status of an existing relation. The controller handles the state update and service class interactions.The PR also initiates the controller by updating the metamask-controller and updating actions.ts with the new functions.
Related issues
Fixes:
fixes #24405
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist