Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/profile-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `getXAuthorizationUrl` method to `ProfileController` for initiating the X OAuth flow. It requires a profile to exist, fetches the authorization URL via `ProfileService:getXAuthUrl` (the profile is resolved server-side from the verified bearer token), and returns the authorization URL and state parameter as ephemeral session data, without storing them in controller state ([#10668](https://github.com/MetaMask/core/pull/10668))
- Add `disconnectX` method to `ProfileController` for unlinking the X account from a profile. It delegates to `ProfileService:disconnectX`, and when the disconnected profile matches the profile in state, clears `xProfile` from controller state and sets `connectedToX` to `false` ([#10668](https://github.com/MetaMask/core/pull/10668))
- Add `disconnectX` method to `ProfileService` for sending an authenticated `DELETE` request to the `profiles/{profileId}/x` endpoint; a `404` response is treated as success (the X account is already disconnected) ([#10668](https://github.com/MetaMask/core/pull/10668))

### Changed

- `getXAuthorizationUrl` no longer accepts a `linkedAddress` parameter and now throws if no profile exists in state
- `connectX` now throws if no profile exists in state, and updates controller state (`xProfile`, `profile.connectedToX`) on success instead of deferring persistence to `createProfile`. `createProfile` no longer persists a linked X profile from its response
- Bump `@metamask/profile-sync-controller` from `^34.0.0` to `^34.0.3` ([#10752](https://github.com/MetaMask/core/pull/10752), [#10756](https://github.com/MetaMask/core/pull/10756), [#10761](https://github.com/MetaMask/core/pull/10761))

### Fixed

- Fix the `ProfileController` messenger event type: the controller exposes `ProfileController:stateChanged` (emitted on state changes), not `ProfileController:stateChange` ([#10668](https://github.com/MetaMask/core/pull/10668))

## [1.0.1]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export type ProfileControllerGetXProfileAction = {

/**
* Creates a new MetaMask profile, updates state, and returns the created profile.
* If the user had previously connected X, also updates xProfile in state.
*
* @param params - The profile creation parameters.
* @returns The created MetaMask profile.
Expand Down Expand Up @@ -81,20 +80,25 @@ export type ProfileControllerCheckUsernameAvailabilityAction = {
};

/**
* Completes the X OAuth PKCE flow, updates xProfile in state, and returns the X profile.
* Completes the X OAuth flow for the profile in state and returns the
* linked X profile. Updates controller state with the linked X profile
* and marks the profile in state as connected to X.
*
* @param params - The parameters for the X OAuth PKCE flow.
* @param params - The parameters for the X OAuth flow.
* @param params.code - The OAuth authorization code from the X redirect.
* @param params.state - The state parameter returned by the X redirect.
* @returns The linked X profile.
* @throws If no profile has been created yet.
*/
export type ProfileControllerConnectXAction = {
type: `ProfileController:connectX`;
handler: ProfileController['connectX'];
};

/**
* Fetches the X account linked to the current profile, updates state, and returns the X profile.
* Fetches the X account linked to the authenticated profile, updates state,
* and returns the X profile. The profile is resolved server-side from the
* verified bearer token.
*
* @returns The linked X profile.
*/
Expand All @@ -103,6 +107,32 @@ export type ProfileControllerFetchAndUpdateXAccountAction = {
handler: ProfileController['fetchAndUpdateXAccount'];
};

/**
* Initiates the X OAuth flow by fetching the authorization URL from the backend.
* The profile is resolved server-side from the verified bearer token.
* Returns session data for the caller to use; nothing is stored in controller state.
*
* @returns The X authorization URL and state parameter.
* @throws If no profile has been created yet.
*/
export type ProfileControllerGetXAuthorizationUrlAction = {
type: `ProfileController:getXAuthorizationUrl`;
handler: ProfileController['getXAuthorizationUrl'];
};

/**
* Disconnects the X account linked to the given profile. If the given
* profile matches the profile in state, clears `xProfile` from state and
* marks the profile in state as no longer connected to X.
*
* @param profileId - The ID of the profile to disconnect the linked X account
* from (sourced from {@link getProfile}).
*/
export type ProfileControllerDisconnectXAction = {
type: `ProfileController:disconnectX`;
handler: ProfileController['disconnectX'];
};

/**
* Union of all ProfileController action types.
*/
Expand All @@ -115,4 +145,6 @@ export type ProfileControllerMethodActions =
| ProfileControllerDeleteProfileAction
| ProfileControllerCheckUsernameAvailabilityAction
| ProfileControllerConnectXAction
| ProfileControllerFetchAndUpdateXAccountAction;
| ProfileControllerFetchAndUpdateXAccountAction
| ProfileControllerGetXAuthorizationUrlAction
| ProfileControllerDisconnectXAction;
Loading
Loading