feat: add @metamask/profile-controller package - #10558
Conversation
…ations and rename getXAccount
… types and connectX signature
… and update state
… satisfy Json return type
mcmire
left a comment
There was a problem hiding this comment.
Looks great! Most comments are minor and can be deferred to another PR. Only big question is around whether or not it makes sense to include React hooks in the same package.
| * @param identifier - The profile identifier to fetch. | ||
| * @returns A TanStack Query result containing the profile data. | ||
| */ | ||
| export function useGetProfile( |
There was a problem hiding this comment.
Hmm... we have tried to keep APIs that can be used within the background/"engine" of the client and APIs that can be used on the UI side in separate packages. This way if you want to use the controller/service in a project that doesn't use React (e.g. the agentic wallet) you can do so. That's why @metamask/react-data-query is a separate package from @metamask/base-data-service, for instance.
What are your thoughts on creating two packages? Or maybe we can just put these hooks in the client for now and extract them to a new package later?
There was a problem hiding this comment.
dc46832 That makes sense to split into a diff package. I can do a follow up PR later with the separate package. Looping in @joaosantos15 since this was a request from their team.
|
@metamaskbot publish-preview |
Explanation
@metamask/profile-controller, a new package for managing MetaMask user profile stateProfileServicecommunicates with the MetaMask Profile API (profile.api.cx.metamask.io), exposinggetProfile,createProfile,replaceProfile,updateProfile,deleteProfile,checkUsernameAvailability,getXAuthUrl,connectX, andgetXAccountvia the messenger, with superstruct validation on all inputs and responsesProfileControllermanages profile state derived from the API and exposes all operations via the messenger; also exportsuseGetProfileanduseCheckUsernameAvailabilityReact hooks for UI components via@metamask/react-data-queryReferences
N/A
Checklist
Note
Medium Risk
Adds authenticated profile CRUD, persisted user state, and X OAuth flows; mistakes could affect account identity data, though inputs/outputs are struct-validated and heavily tested.
Overview
Introduces
@metamask/profile-controller, a new monorepo package for MetaMask user profiles (username, bio, avatar, linked addresses, trading privacy) and optional X (Twitter) linking.ProfileService(extendsBaseDataService) calls the MetaMask Profile API with bearer auth fromAuthenticationController:getBearerToken, validates requests/responses with superstruct, and exposes CRUD, username availability, and X OAuth (getXAuthUrl,connectX,getXAccount) via messenger actions.ProfileControllerkeeps persistedprofile/ optionalxProfilestate, maps API shapes to UI-friendly types, and delegates mutations toProfileService(including guards when no profile exists and clearing state on delete). Broad Jest coverage is included for both layers.Repo wiring adds CODEOWNERS (
@MetaMask/accounts-engineers), README/package graph entries, root/tsconfig references,teams.json, and oxlint suppression for the new jest config.Reviewed by Cursor Bugbot for commit dc46832. Bugbot is set up for automated code reviews on this repo. Configure here.