@metamask-previews/profile-controller 1.0.1-preview-131e5e6ee → 1.0.1-preview-2750df1dc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/ProfileController-method-action-types.d.ts +33 -5
- package/dist/ProfileController-method-action-types.d.ts.map +1 -1
- package/dist/ProfileController-method-action-types.js.map +1 -1
- package/dist/ProfileController.d.ts +37 -8
- package/dist/ProfileController.d.ts.map +1 -1
- package/dist/ProfileController.js +51 -9
- package/dist/ProfileController.js.map +1 -1
- package/dist/ProfileService-method-action-types.d.ts +17 -1
- package/dist/ProfileService-method-action-types.d.ts.map +1 -1
- package/dist/ProfileService-method-action-types.js.map +1 -1
- package/dist/ProfileService.d.ts +19 -5
- package/dist/ProfileService.d.ts.map +1 -1
- package/dist/ProfileService.js +46 -5
- package/dist/ProfileService.js.map +1 -1
- package/dist/ProfileServiceMock.d.ts +25 -0
- package/dist/ProfileServiceMock.d.ts.map +1 -0
- package/dist/ProfileServiceMock.js +65 -0
- package/dist/ProfileServiceMock.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `ProfileServiceMock` for mocking profile-api responses ([#10745](https://github.com/MetaMask/core/pull/10745))
|
|
13
|
+
- 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))
|
|
14
|
+
- 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))
|
|
15
|
+
- 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))
|
|
16
|
+
|
|
10
17
|
### Changed
|
|
11
18
|
|
|
19
|
+
- `getXAuthorizationUrl` no longer accepts a `linkedAddress` parameter and now throws if no profile exists in state
|
|
20
|
+
- `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
|
|
12
21
|
- 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))
|
|
13
22
|
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- 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))
|
|
26
|
+
|
|
14
27
|
## [1.0.1]
|
|
15
28
|
|
|
16
29
|
### Changed
|
|
@@ -23,7 +23,6 @@ export type ProfileControllerGetXProfileAction = {
|
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Creates a new MetaMask profile, updates state, and returns the created profile.
|
|
26
|
-
* If the user had previously connected X, also updates xProfile in state.
|
|
27
26
|
*
|
|
28
27
|
* @param params - The profile creation parameters.
|
|
29
28
|
* @returns The created MetaMask profile.
|
|
@@ -72,19 +71,24 @@ export type ProfileControllerCheckUsernameAvailabilityAction = {
|
|
|
72
71
|
handler: ProfileController['checkUsernameAvailability'];
|
|
73
72
|
};
|
|
74
73
|
/**
|
|
75
|
-
* Completes the X OAuth
|
|
74
|
+
* Completes the X OAuth flow for the profile in state and returns the
|
|
75
|
+
* linked X profile. Updates controller state with the linked X profile
|
|
76
|
+
* and marks the profile in state as connected to X.
|
|
76
77
|
*
|
|
77
|
-
* @param params - The parameters for the X OAuth
|
|
78
|
+
* @param params - The parameters for the X OAuth flow.
|
|
78
79
|
* @param params.code - The OAuth authorization code from the X redirect.
|
|
79
80
|
* @param params.state - The state parameter returned by the X redirect.
|
|
80
81
|
* @returns The linked X profile.
|
|
82
|
+
* @throws If no profile has been created yet.
|
|
81
83
|
*/
|
|
82
84
|
export type ProfileControllerConnectXAction = {
|
|
83
85
|
type: `ProfileController:connectX`;
|
|
84
86
|
handler: ProfileController['connectX'];
|
|
85
87
|
};
|
|
86
88
|
/**
|
|
87
|
-
* Fetches the X account linked to the
|
|
89
|
+
* Fetches the X account linked to the authenticated profile, updates state,
|
|
90
|
+
* and returns the X profile. The profile is resolved server-side from the
|
|
91
|
+
* verified bearer token.
|
|
88
92
|
*
|
|
89
93
|
* @returns The linked X profile.
|
|
90
94
|
*/
|
|
@@ -92,8 +96,32 @@ export type ProfileControllerFetchAndUpdateXAccountAction = {
|
|
|
92
96
|
type: `ProfileController:fetchAndUpdateXAccount`;
|
|
93
97
|
handler: ProfileController['fetchAndUpdateXAccount'];
|
|
94
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* Initiates the X OAuth flow by fetching the authorization URL from the backend.
|
|
101
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
102
|
+
* Returns session data for the caller to use; nothing is stored in controller state.
|
|
103
|
+
*
|
|
104
|
+
* @returns The X authorization URL and state parameter.
|
|
105
|
+
* @throws If no profile has been created yet.
|
|
106
|
+
*/
|
|
107
|
+
export type ProfileControllerGetXAuthorizationUrlAction = {
|
|
108
|
+
type: `ProfileController:getXAuthorizationUrl`;
|
|
109
|
+
handler: ProfileController['getXAuthorizationUrl'];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Disconnects the X account linked to the given profile. If the given
|
|
113
|
+
* profile matches the profile in state, clears `xProfile` from state and
|
|
114
|
+
* marks the profile in state as no longer connected to X.
|
|
115
|
+
*
|
|
116
|
+
* @param profileId - The ID of the profile to disconnect the linked X account
|
|
117
|
+
* from (sourced from {@link getProfile}).
|
|
118
|
+
*/
|
|
119
|
+
export type ProfileControllerDisconnectXAction = {
|
|
120
|
+
type: `ProfileController:disconnectX`;
|
|
121
|
+
handler: ProfileController['disconnectX'];
|
|
122
|
+
};
|
|
95
123
|
/**
|
|
96
124
|
* Union of all ProfileController action types.
|
|
97
125
|
*/
|
|
98
|
-
export type ProfileControllerMethodActions = ProfileControllerGetProfileAction | ProfileControllerGetXProfileAction | ProfileControllerCreateProfileAction | ProfileControllerReplaceProfileAction | ProfileControllerUpdateProfileAction | ProfileControllerDeleteProfileAction | ProfileControllerCheckUsernameAvailabilityAction | ProfileControllerConnectXAction | ProfileControllerFetchAndUpdateXAccountAction;
|
|
126
|
+
export type ProfileControllerMethodActions = ProfileControllerGetProfileAction | ProfileControllerGetXProfileAction | ProfileControllerCreateProfileAction | ProfileControllerReplaceProfileAction | ProfileControllerUpdateProfileAction | ProfileControllerDeleteProfileAction | ProfileControllerCheckUsernameAvailabilityAction | ProfileControllerConnectXAction | ProfileControllerFetchAndUpdateXAccountAction | ProfileControllerGetXAuthorizationUrlAction | ProfileControllerDisconnectXAction;
|
|
99
127
|
//# sourceMappingURL=ProfileController-method-action-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileController-method-action-types.d.ts","sourceRoot":"","sources":["../src/ProfileController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CAC3C,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"ProfileController-method-action-types.d.ts","sourceRoot":"","sources":["../src/ProfileController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE;;;;GAIG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,qCAAqC,GAAG;IAClD,IAAI,EAAE,kCAAkC,CAAC;IACzC,OAAO,EAAE,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oCAAoC,GAAG;IACjD,IAAI,EAAE,iCAAiC,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAC;CAC7C,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,iBAAiB,CAAC,2BAA2B,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,iBAAiB,CAAC,sBAAsB,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CAC3C,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,8BAA8B,GACtC,iCAAiC,GACjC,kCAAkC,GAClC,oCAAoC,GACpC,qCAAqC,GACrC,oCAAoC,GACpC,oCAAoC,GACpC,gDAAgD,GAChD,+BAA+B,GAC/B,6CAA6C,GAC7C,2CAA2C,GAC3C,kCAAkC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileController-method-action-types.js","sourceRoot":"","sources":["../src/ProfileController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ProfileController } from './ProfileController.js';\n\n/**\n * Returns the current MetaMask profile from state, or undefined if none has been created.\n *\n * @returns The MetaMask profile, or undefined.\n */\nexport type ProfileControllerGetProfileAction = {\n type: `ProfileController:getProfile`;\n handler: ProfileController['getProfile'];\n};\n\n/**\n * Returns the currently linked X profile from state, or undefined if none has been connected.\n *\n * @returns The X profile, or undefined.\n */\nexport type ProfileControllerGetXProfileAction = {\n type: `ProfileController:getXProfile`;\n handler: ProfileController['getXProfile'];\n};\n\n/**\n * Creates a new MetaMask profile, updates state, and returns the created profile.\n
|
|
1
|
+
{"version":3,"file":"ProfileController-method-action-types.js","sourceRoot":"","sources":["../src/ProfileController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ProfileController } from './ProfileController.js';\n\n/**\n * Returns the current MetaMask profile from state, or undefined if none has been created.\n *\n * @returns The MetaMask profile, or undefined.\n */\nexport type ProfileControllerGetProfileAction = {\n type: `ProfileController:getProfile`;\n handler: ProfileController['getProfile'];\n};\n\n/**\n * Returns the currently linked X profile from state, or undefined if none has been connected.\n *\n * @returns The X profile, or undefined.\n */\nexport type ProfileControllerGetXProfileAction = {\n type: `ProfileController:getXProfile`;\n handler: ProfileController['getXProfile'];\n};\n\n/**\n * Creates a new MetaMask profile, updates state, and returns the created profile.\n *\n * @param params - The profile creation parameters.\n * @returns The created MetaMask profile.\n */\nexport type ProfileControllerCreateProfileAction = {\n type: `ProfileController:createProfile`;\n handler: ProfileController['createProfile'];\n};\n\n/**\n * Fully replaces the current profile and updates state.\n *\n * @param input - The replacement profile data.\n * @throws If no profile has been created yet.\n */\nexport type ProfileControllerReplaceProfileAction = {\n type: `ProfileController:replaceProfile`;\n handler: ProfileController['replaceProfile'];\n};\n\n/**\n * Partially updates the current profile and updates state.\n *\n * @param input - The fields to update.\n * @throws If no profile has been created yet.\n */\nexport type ProfileControllerUpdateProfileAction = {\n type: `ProfileController:updateProfile`;\n handler: ProfileController['updateProfile'];\n};\n\n/**\n * Deletes the current profile and resets state, including clearing any linked X profile.\n *\n * @throws If no profile has been created yet.\n */\nexport type ProfileControllerDeleteProfileAction = {\n type: `ProfileController:deleteProfile`;\n handler: ProfileController['deleteProfile'];\n};\n\n/**\n * Checks whether a username is available.\n *\n * @param username - The username to check.\n * @returns Availability details including validity and normalized form.\n */\nexport type ProfileControllerCheckUsernameAvailabilityAction = {\n type: `ProfileController:checkUsernameAvailability`;\n handler: ProfileController['checkUsernameAvailability'];\n};\n\n/**\n * Completes the X OAuth flow for the profile in state and returns the\n * linked X profile. Updates controller state with the linked X profile\n * and marks the profile in state as connected to X.\n *\n * @param params - The parameters for the X OAuth flow.\n * @param params.code - The OAuth authorization code from the X redirect.\n * @param params.state - The state parameter returned by the X redirect.\n * @returns The linked X profile.\n * @throws If no profile has been created yet.\n */\nexport type ProfileControllerConnectXAction = {\n type: `ProfileController:connectX`;\n handler: ProfileController['connectX'];\n};\n\n/**\n * Fetches the X account linked to the authenticated profile, updates state,\n * and returns the X profile. The profile is resolved server-side from the\n * verified bearer token.\n *\n * @returns The linked X profile.\n */\nexport type ProfileControllerFetchAndUpdateXAccountAction = {\n type: `ProfileController:fetchAndUpdateXAccount`;\n handler: ProfileController['fetchAndUpdateXAccount'];\n};\n\n/**\n * Initiates the X OAuth flow by fetching the authorization URL from the backend.\n * The profile is resolved server-side from the verified bearer token.\n * Returns session data for the caller to use; nothing is stored in controller state.\n *\n * @returns The X authorization URL and state parameter.\n * @throws If no profile has been created yet.\n */\nexport type ProfileControllerGetXAuthorizationUrlAction = {\n type: `ProfileController:getXAuthorizationUrl`;\n handler: ProfileController['getXAuthorizationUrl'];\n};\n\n/**\n * Disconnects the X account linked to the given profile. If the given\n * profile matches the profile in state, clears `xProfile` from state and\n * marks the profile in state as no longer connected to X.\n *\n * @param profileId - The ID of the profile to disconnect the linked X account\n * from (sourced from {@link getProfile}).\n */\nexport type ProfileControllerDisconnectXAction = {\n type: `ProfileController:disconnectX`;\n handler: ProfileController['disconnectX'];\n};\n\n/**\n * Union of all ProfileController action types.\n */\nexport type ProfileControllerMethodActions =\n | ProfileControllerGetProfileAction\n | ProfileControllerGetXProfileAction\n | ProfileControllerCreateProfileAction\n | ProfileControllerReplaceProfileAction\n | ProfileControllerUpdateProfileAction\n | ProfileControllerDeleteProfileAction\n | ProfileControllerCheckUsernameAvailabilityAction\n | ProfileControllerConnectXAction\n | ProfileControllerFetchAndUpdateXAccountAction\n | ProfileControllerGetXAuthorizationUrlAction\n | ProfileControllerDisconnectXAction;\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseController } from '@metamask/base-controller';
|
|
2
|
-
import type { ControllerGetStateAction,
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangedEvent } from '@metamask/base-controller';
|
|
3
3
|
import type { Messenger } from '@metamask/messenger';
|
|
4
4
|
import type { CaipAccountId } from '@metamask/utils';
|
|
5
5
|
import type { ProfileControllerMethodActions } from './ProfileController-method-action-types.js';
|
|
6
|
-
import type { ProfileServiceCheckUsernameAvailabilityAction, ProfileServiceConnectXAction, ProfileServiceCreateProfileAction, ProfileServiceDeleteProfileAction, ProfileServiceGetXAccountAction, ProfileServiceReplaceProfileAction, ProfileServiceUpdateProfileAction } from './ProfileService-method-action-types.js';
|
|
6
|
+
import type { ProfileServiceCheckUsernameAvailabilityAction, ProfileServiceConnectXAction, ProfileServiceCreateProfileAction, ProfileServiceDeleteProfileAction, ProfileServiceDisconnectXAction, ProfileServiceGetXAccountAction, ProfileServiceGetXAuthUrlAction, ProfileServiceReplaceProfileAction, ProfileServiceUpdateProfileAction } from './ProfileService-method-action-types.js';
|
|
7
7
|
import type { CreateProfileParams, ReplaceProfileParams, UpdateProfileParams, UsernameAvailabilityResponse } from './ProfileService.js';
|
|
8
8
|
declare const controllerName = "ProfileController";
|
|
9
9
|
/** Representation of a profile stored in controller state. */
|
|
@@ -46,6 +46,13 @@ export type XProfile = {
|
|
|
46
46
|
/** The date and time the X profile was updated. */
|
|
47
47
|
updatedAt: string;
|
|
48
48
|
};
|
|
49
|
+
/** Ephemeral session data for initiating the X OAuth flow. Not stored in controller state. */
|
|
50
|
+
export type ConnectXSession = {
|
|
51
|
+
/** The X authorization URL to open in a system browser. */
|
|
52
|
+
authorizationUrl: string;
|
|
53
|
+
/** The OAuth state parameter to compare against the X redirect callback. */
|
|
54
|
+
state: string;
|
|
55
|
+
};
|
|
49
56
|
/** State managed by ProfileController. */
|
|
50
57
|
export type ProfileControllerState = {
|
|
51
58
|
profile: Profile;
|
|
@@ -56,10 +63,10 @@ export type ProfileControllerGetStateAction = ControllerGetStateAction<typeof co
|
|
|
56
63
|
/** Union of all actions exposed by ProfileController. */
|
|
57
64
|
export type ProfileControllerActions = ProfileControllerGetStateAction | ProfileControllerMethodActions;
|
|
58
65
|
/** The `ProfileController:stateChanged` event type. */
|
|
59
|
-
export type ProfileControllerChangeEvent =
|
|
66
|
+
export type ProfileControllerChangeEvent = ControllerStateChangedEvent<typeof controllerName, ProfileControllerState>;
|
|
60
67
|
/** Union of all events emitted by ProfileController. */
|
|
61
68
|
export type ProfileControllerEvents = ProfileControllerChangeEvent;
|
|
62
|
-
type AllowedActions = ProfileServiceCreateProfileAction | ProfileServiceReplaceProfileAction | ProfileServiceUpdateProfileAction | ProfileServiceDeleteProfileAction | ProfileServiceCheckUsernameAvailabilityAction | ProfileServiceConnectXAction | ProfileServiceGetXAccountAction;
|
|
69
|
+
type AllowedActions = ProfileServiceCreateProfileAction | ProfileServiceReplaceProfileAction | ProfileServiceUpdateProfileAction | ProfileServiceDeleteProfileAction | ProfileServiceCheckUsernameAvailabilityAction | ProfileServiceConnectXAction | ProfileServiceGetXAccountAction | ProfileServiceGetXAuthUrlAction | ProfileServiceDisconnectXAction;
|
|
63
70
|
export type AllowedEvents = never;
|
|
64
71
|
/** Messenger type for ProfileController, scoped to its actions, events, and allowed service calls. */
|
|
65
72
|
export type ProfileControllerMessenger = Messenger<typeof controllerName, ProfileControllerActions | AllowedActions, ProfileControllerEvents | AllowedEvents>;
|
|
@@ -97,7 +104,6 @@ export declare class ProfileController extends BaseController<typeof controllerN
|
|
|
97
104
|
getXProfile(): XProfile | undefined;
|
|
98
105
|
/**
|
|
99
106
|
* Creates a new MetaMask profile, updates state, and returns the created profile.
|
|
100
|
-
* If the user had previously connected X, also updates xProfile in state.
|
|
101
107
|
*
|
|
102
108
|
* @param params - The profile creation parameters.
|
|
103
109
|
* @returns The created MetaMask profile.
|
|
@@ -131,23 +137,46 @@ export declare class ProfileController extends BaseController<typeof controllerN
|
|
|
131
137
|
*/
|
|
132
138
|
checkUsernameAvailability(username: string): Promise<UsernameAvailabilityResponse>;
|
|
133
139
|
/**
|
|
134
|
-
* Completes the X OAuth
|
|
140
|
+
* Completes the X OAuth flow for the profile in state and returns the
|
|
141
|
+
* linked X profile. Updates controller state with the linked X profile
|
|
142
|
+
* and marks the profile in state as connected to X.
|
|
135
143
|
*
|
|
136
|
-
* @param params - The parameters for the X OAuth
|
|
144
|
+
* @param params - The parameters for the X OAuth flow.
|
|
137
145
|
* @param params.code - The OAuth authorization code from the X redirect.
|
|
138
146
|
* @param params.state - The state parameter returned by the X redirect.
|
|
139
147
|
* @returns The linked X profile.
|
|
148
|
+
* @throws If no profile has been created yet.
|
|
140
149
|
*/
|
|
141
150
|
connectX(params: {
|
|
142
151
|
code: string;
|
|
143
152
|
state: string;
|
|
144
153
|
}): Promise<XProfile>;
|
|
145
154
|
/**
|
|
146
|
-
* Fetches the X account linked to the
|
|
155
|
+
* Fetches the X account linked to the authenticated profile, updates state,
|
|
156
|
+
* and returns the X profile. The profile is resolved server-side from the
|
|
157
|
+
* verified bearer token.
|
|
147
158
|
*
|
|
148
159
|
* @returns The linked X profile.
|
|
149
160
|
*/
|
|
150
161
|
fetchAndUpdateXAccount(): Promise<XProfile>;
|
|
162
|
+
/**
|
|
163
|
+
* Initiates the X OAuth flow by fetching the authorization URL from the backend.
|
|
164
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
165
|
+
* Returns session data for the caller to use; nothing is stored in controller state.
|
|
166
|
+
*
|
|
167
|
+
* @returns The X authorization URL and state parameter.
|
|
168
|
+
* @throws If no profile has been created yet.
|
|
169
|
+
*/
|
|
170
|
+
getXAuthorizationUrl(): Promise<ConnectXSession>;
|
|
171
|
+
/**
|
|
172
|
+
* Disconnects the X account linked to the given profile. If the given
|
|
173
|
+
* profile matches the profile in state, clears `xProfile` from state and
|
|
174
|
+
* marks the profile in state as no longer connected to X.
|
|
175
|
+
*
|
|
176
|
+
* @param profileId - The ID of the profile to disconnect the linked X account
|
|
177
|
+
* from (sourced from {@link getProfile}).
|
|
178
|
+
*/
|
|
179
|
+
disconnectX(profileId: string): Promise<void>;
|
|
151
180
|
}
|
|
152
181
|
export {};
|
|
153
182
|
//# sourceMappingURL=ProfileController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileController.d.ts","sourceRoot":"","sources":["../src/ProfileController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"ProfileController.d.ts","sourceRoot":"","sources":["../src/ProfileController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,4CAA4C,CAAC;AACjG,OAAO,KAAK,EACV,6CAA6C,EAC7C,4BAA4B,EAC5B,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,+BAA+B,EAC/B,+BAA+B,EAC/B,kCAAkC,EAClC,iCAAiC,EAClC,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EACV,mBAAmB,EAGnB,oBAA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AC,OAAO,CAAC,CAUjE;IAED;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAU/D;IAED;;;;;OAKG;IACG,aAAa,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAU7D;IAED;;;;OAIG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAOnC;IAED;;;;;OAKG;IACG,yBAAyB,CAC7B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,4BAA4B,CAAC,CAKvC;IAED;;;;;;;;;;OAUG;IACG,QAAQ,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,CAYzE;IAED;;;;;;OAMG;IACG,sBAAsB,IAAI,OAAO,CAAC,QAAQ,CAAC,CAOhD;IAED;;;;;;;OAOG;IACG,oBAAoB,IAAI,OAAO,CAAC,eAAe,CAAC,CAIrD;IAED;;;;;;;OAOG;IACG,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlD;CACF"}
|
|
@@ -46,6 +46,8 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
46
46
|
'checkUsernameAvailability',
|
|
47
47
|
'connectX',
|
|
48
48
|
'fetchAndUpdateXAccount',
|
|
49
|
+
'getXAuthorizationUrl',
|
|
50
|
+
'disconnectX',
|
|
49
51
|
];
|
|
50
52
|
// === CONTROLLER ===
|
|
51
53
|
/** Manages MetaMask profile state and delegates API operations to ProfileService. */
|
|
@@ -148,7 +150,6 @@ export class ProfileController extends BaseController {
|
|
|
148
150
|
}
|
|
149
151
|
/**
|
|
150
152
|
* Creates a new MetaMask profile, updates state, and returns the created profile.
|
|
151
|
-
* If the user had previously connected X, also updates xProfile in state.
|
|
152
153
|
*
|
|
153
154
|
* @param params - The profile creation parameters.
|
|
154
155
|
* @returns The created MetaMask profile.
|
|
@@ -158,9 +159,6 @@ export class ProfileController extends BaseController {
|
|
|
158
159
|
const mapped = this.#mapApiResponseToProfile(response);
|
|
159
160
|
this.update((state) => {
|
|
160
161
|
state.profile = mapped;
|
|
161
|
-
if (response.x_profile) {
|
|
162
|
-
state.xProfile = this.#mapXResponseToXProfile(response.x_profile);
|
|
163
|
-
}
|
|
164
162
|
});
|
|
165
163
|
return mapped;
|
|
166
164
|
}
|
|
@@ -213,19 +211,33 @@ export class ProfileController extends BaseController {
|
|
|
213
211
|
return await this.messenger.call('ProfileService:checkUsernameAvailability', username);
|
|
214
212
|
}
|
|
215
213
|
/**
|
|
216
|
-
* Completes the X OAuth
|
|
214
|
+
* Completes the X OAuth flow for the profile in state and returns the
|
|
215
|
+
* linked X profile. Updates controller state with the linked X profile
|
|
216
|
+
* and marks the profile in state as connected to X.
|
|
217
217
|
*
|
|
218
|
-
* @param params - The parameters for the X OAuth
|
|
218
|
+
* @param params - The parameters for the X OAuth flow.
|
|
219
219
|
* @param params.code - The OAuth authorization code from the X redirect.
|
|
220
220
|
* @param params.state - The state parameter returned by the X redirect.
|
|
221
221
|
* @returns The linked X profile.
|
|
222
|
+
* @throws If no profile has been created yet.
|
|
222
223
|
*/
|
|
223
224
|
async connectX(params) {
|
|
224
|
-
|
|
225
|
-
|
|
225
|
+
this.#getProfileIdOrThrow();
|
|
226
|
+
const response = await this.messenger.call('ProfileService:connectX', {
|
|
227
|
+
code: params.code,
|
|
228
|
+
state: params.state,
|
|
229
|
+
});
|
|
230
|
+
const mapped = this.#mapXResponseToXProfile(response);
|
|
231
|
+
this.update((state) => {
|
|
232
|
+
state.xProfile = mapped;
|
|
233
|
+
state.profile.connectedToX = true;
|
|
234
|
+
});
|
|
235
|
+
return mapped;
|
|
226
236
|
}
|
|
227
237
|
/**
|
|
228
|
-
* Fetches the X account linked to the
|
|
238
|
+
* Fetches the X account linked to the authenticated profile, updates state,
|
|
239
|
+
* and returns the X profile. The profile is resolved server-side from the
|
|
240
|
+
* verified bearer token.
|
|
229
241
|
*
|
|
230
242
|
* @returns The linked X profile.
|
|
231
243
|
*/
|
|
@@ -237,5 +249,35 @@ export class ProfileController extends BaseController {
|
|
|
237
249
|
});
|
|
238
250
|
return mapped;
|
|
239
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Initiates the X OAuth flow by fetching the authorization URL from the backend.
|
|
254
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
255
|
+
* Returns session data for the caller to use; nothing is stored in controller state.
|
|
256
|
+
*
|
|
257
|
+
* @returns The X authorization URL and state parameter.
|
|
258
|
+
* @throws If no profile has been created yet.
|
|
259
|
+
*/
|
|
260
|
+
async getXAuthorizationUrl() {
|
|
261
|
+
this.#getProfileIdOrThrow();
|
|
262
|
+
const response = await this.messenger.call('ProfileService:getXAuthUrl');
|
|
263
|
+
return { authorizationUrl: response.url, state: response.state };
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Disconnects the X account linked to the given profile. If the given
|
|
267
|
+
* profile matches the profile in state, clears `xProfile` from state and
|
|
268
|
+
* marks the profile in state as no longer connected to X.
|
|
269
|
+
*
|
|
270
|
+
* @param profileId - The ID of the profile to disconnect the linked X account
|
|
271
|
+
* from (sourced from {@link getProfile}).
|
|
272
|
+
*/
|
|
273
|
+
async disconnectX(profileId) {
|
|
274
|
+
await this.messenger.call('ProfileService:disconnectX', profileId);
|
|
275
|
+
this.update((state) => {
|
|
276
|
+
if (state.profile.profileId === profileId) {
|
|
277
|
+
state.xProfile = undefined;
|
|
278
|
+
state.profile.connectedToX = false;
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
240
282
|
}
|
|
241
283
|
//# sourceMappingURL=ProfileController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileController.js","sourceRoot":"","sources":["../src/ProfileController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAA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C,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC1B,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { CaipAccountId } from '@metamask/utils';\n\nimport type { ProfileControllerMethodActions } from './ProfileController-method-action-types.js';\nimport type {\n ProfileServiceCheckUsernameAvailabilityAction,\n ProfileServiceConnectXAction,\n ProfileServiceCreateProfileAction,\n ProfileServiceDeleteProfileAction,\n ProfileServiceGetXAccountAction,\n ProfileServiceReplaceProfileAction,\n ProfileServiceUpdateProfileAction,\n} from './ProfileService-method-action-types.js';\nimport type {\n CreateProfileParams,\n CreateProfileResponse,\n ProfileApiResponse,\n ReplaceProfileParams,\n UpdateProfileParams,\n UsernameAvailabilityResponse,\n XConnectResponse,\n} from './ProfileService.js';\n\nconst controllerName = 'ProfileController';\n\n// === TYPES ===\n\n/** Representation of a profile stored in controller state. */\nexport type Profile = {\n /** The canonical profile ID connected to the profile. */\n profileId: string;\n /** The username for the profile. */\n username: string;\n /** The display name for the profile. */\n displayName: string;\n /** The bio for the profile. */\n bio: string;\n /** The linked addresses for the profile. */\n linkedAddresses: CaipAccountId[];\n /** The avatar URL for the profile. */\n avatarUrl: string;\n /** Whether the profile's trading activity is visible to the public. */\n tradingPrivacy: 'public' | 'private';\n /** Whether the profile is connected to X. */\n connectedToX: boolean;\n /** The date and time the profile was created. */\n createdAt: string;\n /** The date and time the profile was updated. */\n updatedAt: string;\n};\n\n/** Representation of a linked X (Twitter) profile stored in controller state. */\nexport type XProfile = {\n /** The unique identifier for the X profile. This is the user ID of the X profile. */\n xUserId: string;\n /** The URL for the X profile. */\n xProfileUrl: string;\n /** The username for the X profile. */\n username: string;\n /** The display name for the X profile. */\n displayName: string;\n /** The avatar URL for the X profile. */\n avatarUrl: string;\n /** The date and time the X profile was created. */\n createdAt: string;\n /** The date and time the X profile was updated. */\n updatedAt: string;\n};\n\n/** State managed by ProfileController. */\nexport type ProfileControllerState = {\n profile: Profile;\n xProfile?: XProfile;\n};\n\n// === MESSENGER ===\n\n/** The `ProfileController:getState` action type. */\nexport type ProfileControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ProfileControllerState\n>;\n\n/** Union of all actions exposed by ProfileController. */\nexport type ProfileControllerActions =\n | ProfileControllerGetStateAction\n | ProfileControllerMethodActions;\n\n/** The `ProfileController:stateChanged` event type. */\nexport type ProfileControllerChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n ProfileControllerState\n>;\n\n/** Union of all events emitted by ProfileController. */\nexport type ProfileControllerEvents = ProfileControllerChangeEvent;\n\ntype AllowedActions =\n | ProfileServiceCreateProfileAction\n | ProfileServiceReplaceProfileAction\n | ProfileServiceUpdateProfileAction\n | ProfileServiceDeleteProfileAction\n | ProfileServiceCheckUsernameAvailabilityAction\n | ProfileServiceConnectXAction\n | ProfileServiceGetXAccountAction;\n\nexport type AllowedEvents = never;\n\n/** Messenger type for ProfileController, scoped to its actions, events, and allowed service calls. */\nexport type ProfileControllerMessenger = Messenger<\n typeof controllerName,\n ProfileControllerActions | AllowedActions,\n ProfileControllerEvents | AllowedEvents\n>;\n\n// === STATE ===\n\nconst profileControllerMetadata = {\n profile: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n xProfile: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<ProfileControllerState>;\n\n/**\n * Returns the default initial state for ProfileController.\n *\n * @returns A ProfileControllerState with empty profile fields and no X profile.\n */\nexport function getDefaultProfileControllerState(): ProfileControllerState {\n return {\n profile: {\n profileId: '',\n username: '',\n displayName: '',\n bio: '',\n linkedAddresses: [],\n avatarUrl: '',\n tradingPrivacy: 'public',\n connectedToX: false,\n createdAt: '',\n updatedAt: '',\n },\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getProfile',\n 'getXProfile',\n 'createProfile',\n 'replaceProfile',\n 'updateProfile',\n 'deleteProfile',\n 'checkUsernameAvailability',\n 'connectX',\n 'fetchAndUpdateXAccount',\n] as const;\n\n// === CONTROLLER ===\n\n/** Manages MetaMask profile state and delegates API operations to ProfileService. */\nexport class ProfileController extends BaseController<\n typeof controllerName,\n ProfileControllerState,\n ProfileControllerMessenger\n> {\n /**\n * Creates a new ProfileController instance.\n *\n * @param options - Constructor options.\n * @param options.messenger - The messenger scoped to ProfileController.\n * @param options.state - Optional partial initial state to merge with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: ProfileControllerMessenger;\n state?: Partial<ProfileControllerState>;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: profileControllerMetadata,\n state: {\n ...getDefaultProfileControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Returns true if a profile has been created and exists in state.\n *\n * @returns True if a profile exists, false otherwise.\n */\n #hasProfile(): boolean {\n return this.state.profile.profileId !== '';\n }\n\n /**\n * Returns the profile ID from state, throwing if no profile exists yet.\n *\n * @returns The current profile ID.\n * @throws If no profile has been created.\n */\n #getProfileIdOrThrow(): string {\n const { profileId } = this.state.profile;\n if (!profileId) {\n throw new Error('ProfileController: no profile found in state');\n }\n return profileId;\n }\n\n /**\n * Maps an API response to a MetaMask profile.\n *\n * @param response - The API response to map.\n * @returns The mapped MetaMask profile.\n */\n #mapApiResponseToProfile(response: ProfileApiResponse): Profile {\n return {\n profileId: response.profile_id,\n username: response.username,\n displayName: response.display_name,\n bio: response.bio ?? '',\n linkedAddresses: response.linked_addresses,\n avatarUrl: response.avatar_url ?? '',\n tradingPrivacy: response.trading_privacy,\n connectedToX: response.connected_to_x,\n createdAt: response.created_at,\n updatedAt: response.updated_at,\n };\n }\n\n /**\n * Maps an API response to an X profile.\n *\n * @param response - The API response to map.\n * @returns The mapped X profile.\n */\n #mapXResponseToXProfile(response: XConnectResponse): XProfile {\n return {\n xUserId: response.x_user_id,\n xProfileUrl: response.x_profile_url,\n username: response.username,\n displayName: response.display_name,\n avatarUrl: response.avatar_url,\n createdAt: response.created_at,\n updatedAt: response.updated_at,\n };\n }\n\n /**\n * Returns the current MetaMask profile from state, or undefined if none has been created.\n *\n * @returns The MetaMask profile, or undefined.\n */\n getProfile(): Profile | undefined {\n if (!this.#hasProfile()) {\n return undefined;\n }\n return this.state.profile;\n }\n\n /**\n * Returns the currently linked X profile from state, or undefined if none has been connected.\n *\n * @returns The X profile, or undefined.\n */\n getXProfile(): XProfile | undefined {\n return this.state.xProfile;\n }\n\n /**\n * Creates a new MetaMask profile, updates state, and returns the created profile.\n * If the user had previously connected X, also updates xProfile in state.\n *\n * @param params - The profile creation parameters.\n * @returns The created MetaMask profile.\n */\n async createProfile(params: CreateProfileParams): Promise<Profile> {\n const response: CreateProfileResponse = await this.messenger.call(\n 'ProfileService:createProfile',\n params,\n );\n const mapped = this.#mapApiResponseToProfile(response);\n this.update((state) => {\n state.profile = mapped;\n if (response.x_profile) {\n state.xProfile = this.#mapXResponseToXProfile(response.x_profile);\n }\n });\n return mapped;\n }\n\n /**\n * Fully replaces the current profile and updates state.\n *\n * @param input - The replacement profile data.\n * @throws If no profile has been created yet.\n */\n async replaceProfile(input: ReplaceProfileParams): Promise<void> {\n const profileId = this.#getProfileIdOrThrow();\n const response = await this.messenger.call(\n 'ProfileService:replaceProfile',\n profileId,\n input,\n );\n this.update((state) => {\n state.profile = this.#mapApiResponseToProfile(response);\n });\n }\n\n /**\n * Partially updates the current profile and updates state.\n *\n * @param input - The fields to update.\n * @throws If no profile has been created yet.\n */\n async updateProfile(input: UpdateProfileParams): Promise<void> {\n const profileId = this.#getProfileIdOrThrow();\n const response = await this.messenger.call(\n 'ProfileService:updateProfile',\n profileId,\n input,\n );\n this.update((state) => {\n state.profile = this.#mapApiResponseToProfile(response);\n });\n }\n\n /**\n * Deletes the current profile and resets state, including clearing any linked X profile.\n *\n * @throws If no profile has been created yet.\n */\n async deleteProfile(): Promise<void> {\n const profileId = this.#getProfileIdOrThrow();\n await this.messenger.call('ProfileService:deleteProfile', profileId);\n this.update((state) => {\n state.profile = getDefaultProfileControllerState().profile;\n state.xProfile = undefined;\n });\n }\n\n /**\n * Checks whether a username is available.\n *\n * @param username - The username to check.\n * @returns Availability details including validity and normalized form.\n */\n async checkUsernameAvailability(\n username: string,\n ): Promise<UsernameAvailabilityResponse> {\n return await this.messenger.call(\n 'ProfileService:checkUsernameAvailability',\n username,\n );\n }\n\n /**\n * Completes the X OAuth PKCE flow, updates xProfile in state, and returns the X profile.\n *\n * @param params - The parameters for the X OAuth PKCE flow.\n * @param params.code - The OAuth authorization code from the X redirect.\n * @param params.state - The state parameter returned by the X redirect.\n * @returns The linked X profile.\n */\n async connectX(params: { code: string; state: string }): Promise<XProfile> {\n const response = await this.messenger.call(\n 'ProfileService:connectX',\n params,\n );\n return this.#mapXResponseToXProfile(response);\n }\n\n /**\n * Fetches the X account linked to the current profile, updates state, and returns the X profile.\n *\n * @returns The linked X profile.\n */\n async fetchAndUpdateXAccount(): Promise<XProfile> {\n const response = await this.messenger.call('ProfileService:getXAccount');\n const mapped = this.#mapXResponseToXProfile(response);\n this.update((state) => {\n state.xProfile = mapped;\n });\n return mapped;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ProfileController.js","sourceRoot":"","sources":["../src/ProfileController.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AA+B3D,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAsG3C,gBAAgB;AAEhB,MAAM,yBAAyB,GAAG;IAChC,OAAO,EAAE;QACP,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC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AI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC;QAC1B,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,oBAAoB;QACxB,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACzE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC;IACnE,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW,CAAC,SAAiB;QACjC,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,EAAE,SAAS,CAAC,CAAC;QACnE,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;gBAC1C,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;gBAC3B,KAAK,CAAC,OAAO,CAAC,YAAY,GAAG,KAAK,CAAC;YACrC,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { BaseController } from '@metamask/base-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { CaipAccountId } from '@metamask/utils';\n\nimport type { ProfileControllerMethodActions } from './ProfileController-method-action-types.js';\nimport type {\n ProfileServiceCheckUsernameAvailabilityAction,\n ProfileServiceConnectXAction,\n ProfileServiceCreateProfileAction,\n ProfileServiceDeleteProfileAction,\n ProfileServiceDisconnectXAction,\n ProfileServiceGetXAccountAction,\n ProfileServiceGetXAuthUrlAction,\n ProfileServiceReplaceProfileAction,\n ProfileServiceUpdateProfileAction,\n} from './ProfileService-method-action-types.js';\nimport type {\n CreateProfileParams,\n CreateProfileResponse,\n ProfileApiResponse,\n ReplaceProfileParams,\n UpdateProfileParams,\n UsernameAvailabilityResponse,\n ConnectXResponse,\n} from './ProfileService.js';\n\nconst controllerName = 'ProfileController';\n\n// === TYPES ===\n\n/** Representation of a profile stored in controller state. */\nexport type Profile = {\n /** The canonical profile ID connected to the profile. */\n profileId: string;\n /** The username for the profile. */\n username: string;\n /** The display name for the profile. */\n displayName: string;\n /** The bio for the profile. */\n bio: string;\n /** The linked addresses for the profile. */\n linkedAddresses: CaipAccountId[];\n /** The avatar URL for the profile. */\n avatarUrl: string;\n /** Whether the profile's trading activity is visible to the public. */\n tradingPrivacy: 'public' | 'private';\n /** Whether the profile is connected to X. */\n connectedToX: boolean;\n /** The date and time the profile was created. */\n createdAt: string;\n /** The date and time the profile was updated. */\n updatedAt: string;\n};\n\n/** Representation of a linked X (Twitter) profile stored in controller state. */\nexport type XProfile = {\n /** The unique identifier for the X profile. This is the user ID of the X profile. */\n xUserId: string;\n /** The URL for the X profile. */\n xProfileUrl: string;\n /** The username for the X profile. */\n username: string;\n /** The display name for the X profile. */\n displayName: string;\n /** The avatar URL for the X profile. */\n avatarUrl: string;\n /** The date and time the X profile was created. */\n createdAt: string;\n /** The date and time the X profile was updated. */\n updatedAt: string;\n};\n\n/** Ephemeral session data for initiating the X OAuth flow. Not stored in controller state. */\nexport type ConnectXSession = {\n /** The X authorization URL to open in a system browser. */\n authorizationUrl: string;\n /** The OAuth state parameter to compare against the X redirect callback. */\n state: string;\n};\n\n/** State managed by ProfileController. */\nexport type ProfileControllerState = {\n profile: Profile;\n xProfile?: XProfile;\n};\n\n// === MESSENGER ===\n\n/** The `ProfileController:getState` action type. */\nexport type ProfileControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n ProfileControllerState\n>;\n\n/** Union of all actions exposed by ProfileController. */\nexport type ProfileControllerActions =\n | ProfileControllerGetStateAction\n | ProfileControllerMethodActions;\n\n/** The `ProfileController:stateChanged` event type. */\nexport type ProfileControllerChangeEvent = ControllerStateChangedEvent<\n typeof controllerName,\n ProfileControllerState\n>;\n\n/** Union of all events emitted by ProfileController. */\nexport type ProfileControllerEvents = ProfileControllerChangeEvent;\n\ntype AllowedActions =\n | ProfileServiceCreateProfileAction\n | ProfileServiceReplaceProfileAction\n | ProfileServiceUpdateProfileAction\n | ProfileServiceDeleteProfileAction\n | ProfileServiceCheckUsernameAvailabilityAction\n | ProfileServiceConnectXAction\n | ProfileServiceGetXAccountAction\n | ProfileServiceGetXAuthUrlAction\n | ProfileServiceDisconnectXAction;\n\nexport type AllowedEvents = never;\n\n/** Messenger type for ProfileController, scoped to its actions, events, and allowed service calls. */\nexport type ProfileControllerMessenger = Messenger<\n typeof controllerName,\n ProfileControllerActions | AllowedActions,\n ProfileControllerEvents | AllowedEvents\n>;\n\n// === STATE ===\n\nconst profileControllerMetadata = {\n profile: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n xProfile: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n} satisfies StateMetadata<ProfileControllerState>;\n\n/**\n * Returns the default initial state for ProfileController.\n *\n * @returns A ProfileControllerState with empty profile fields and no X profile.\n */\nexport function getDefaultProfileControllerState(): ProfileControllerState {\n return {\n profile: {\n profileId: '',\n username: '',\n displayName: '',\n bio: '',\n linkedAddresses: [],\n avatarUrl: '',\n tradingPrivacy: 'public',\n connectedToX: false,\n createdAt: '',\n updatedAt: '',\n },\n };\n}\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getProfile',\n 'getXProfile',\n 'createProfile',\n 'replaceProfile',\n 'updateProfile',\n 'deleteProfile',\n 'checkUsernameAvailability',\n 'connectX',\n 'fetchAndUpdateXAccount',\n 'getXAuthorizationUrl',\n 'disconnectX',\n] as const;\n\n// === CONTROLLER ===\n\n/** Manages MetaMask profile state and delegates API operations to ProfileService. */\nexport class ProfileController extends BaseController<\n typeof controllerName,\n ProfileControllerState,\n ProfileControllerMessenger\n> {\n /**\n * Creates a new ProfileController instance.\n *\n * @param options - Constructor options.\n * @param options.messenger - The messenger scoped to ProfileController.\n * @param options.state - Optional partial initial state to merge with defaults.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: ProfileControllerMessenger;\n state?: Partial<ProfileControllerState>;\n }) {\n super({\n messenger,\n name: controllerName,\n metadata: profileControllerMetadata,\n state: {\n ...getDefaultProfileControllerState(),\n ...state,\n },\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Returns true if a profile has been created and exists in state.\n *\n * @returns True if a profile exists, false otherwise.\n */\n #hasProfile(): boolean {\n return this.state.profile.profileId !== '';\n }\n\n /**\n * Returns the profile ID from state, throwing if no profile exists yet.\n *\n * @returns The current profile ID.\n * @throws If no profile has been created.\n */\n #getProfileIdOrThrow(): string {\n const { profileId } = this.state.profile;\n if (!profileId) {\n throw new Error('ProfileController: no profile found in state');\n }\n return profileId;\n }\n\n /**\n * Maps an API response to a MetaMask profile.\n *\n * @param response - The API response to map.\n * @returns The mapped MetaMask profile.\n */\n #mapApiResponseToProfile(response: ProfileApiResponse): Profile {\n return {\n profileId: response.profile_id,\n username: response.username,\n displayName: response.display_name,\n bio: response.bio ?? '',\n linkedAddresses: response.linked_addresses,\n avatarUrl: response.avatar_url ?? '',\n tradingPrivacy: response.trading_privacy,\n connectedToX: response.connected_to_x,\n createdAt: response.created_at,\n updatedAt: response.updated_at,\n };\n }\n\n /**\n * Maps an API response to an X profile.\n *\n * @param response - The API response to map.\n * @returns The mapped X profile.\n */\n #mapXResponseToXProfile(response: ConnectXResponse): XProfile {\n return {\n xUserId: response.x_user_id,\n xProfileUrl: response.x_profile_url,\n username: response.username,\n displayName: response.display_name,\n avatarUrl: response.avatar_url,\n createdAt: response.created_at,\n updatedAt: response.updated_at,\n };\n }\n\n /**\n * Returns the current MetaMask profile from state, or undefined if none has been created.\n *\n * @returns The MetaMask profile, or undefined.\n */\n getProfile(): Profile | undefined {\n if (!this.#hasProfile()) {\n return undefined;\n }\n return this.state.profile;\n }\n\n /**\n * Returns the currently linked X profile from state, or undefined if none has been connected.\n *\n * @returns The X profile, or undefined.\n */\n getXProfile(): XProfile | undefined {\n return this.state.xProfile;\n }\n\n /**\n * Creates a new MetaMask profile, updates state, and returns the created profile.\n *\n * @param params - The profile creation parameters.\n * @returns The created MetaMask profile.\n */\n async createProfile(params: CreateProfileParams): Promise<Profile> {\n const response: CreateProfileResponse = await this.messenger.call(\n 'ProfileService:createProfile',\n params,\n );\n const mapped = this.#mapApiResponseToProfile(response);\n this.update((state) => {\n state.profile = mapped;\n });\n return mapped;\n }\n\n /**\n * Fully replaces the current profile and updates state.\n *\n * @param input - The replacement profile data.\n * @throws If no profile has been created yet.\n */\n async replaceProfile(input: ReplaceProfileParams): Promise<void> {\n const profileId = this.#getProfileIdOrThrow();\n const response = await this.messenger.call(\n 'ProfileService:replaceProfile',\n profileId,\n input,\n );\n this.update((state) => {\n state.profile = this.#mapApiResponseToProfile(response);\n });\n }\n\n /**\n * Partially updates the current profile and updates state.\n *\n * @param input - The fields to update.\n * @throws If no profile has been created yet.\n */\n async updateProfile(input: UpdateProfileParams): Promise<void> {\n const profileId = this.#getProfileIdOrThrow();\n const response = await this.messenger.call(\n 'ProfileService:updateProfile',\n profileId,\n input,\n );\n this.update((state) => {\n state.profile = this.#mapApiResponseToProfile(response);\n });\n }\n\n /**\n * Deletes the current profile and resets state, including clearing any linked X profile.\n *\n * @throws If no profile has been created yet.\n */\n async deleteProfile(): Promise<void> {\n const profileId = this.#getProfileIdOrThrow();\n await this.messenger.call('ProfileService:deleteProfile', profileId);\n this.update((state) => {\n state.profile = getDefaultProfileControllerState().profile;\n state.xProfile = undefined;\n });\n }\n\n /**\n * Checks whether a username is available.\n *\n * @param username - The username to check.\n * @returns Availability details including validity and normalized form.\n */\n async checkUsernameAvailability(\n username: string,\n ): Promise<UsernameAvailabilityResponse> {\n return await this.messenger.call(\n 'ProfileService:checkUsernameAvailability',\n username,\n );\n }\n\n /**\n * Completes the X OAuth flow for the profile in state and returns the\n * linked X profile. Updates controller state with the linked X profile\n * and marks the profile in state as connected to X.\n *\n * @param params - The parameters for the X OAuth flow.\n * @param params.code - The OAuth authorization code from the X redirect.\n * @param params.state - The state parameter returned by the X redirect.\n * @returns The linked X profile.\n * @throws If no profile has been created yet.\n */\n async connectX(params: { code: string; state: string }): Promise<XProfile> {\n this.#getProfileIdOrThrow();\n const response = await this.messenger.call('ProfileService:connectX', {\n code: params.code,\n state: params.state,\n });\n const mapped = this.#mapXResponseToXProfile(response);\n this.update((state) => {\n state.xProfile = mapped;\n state.profile.connectedToX = true;\n });\n return mapped;\n }\n\n /**\n * Fetches the X account linked to the authenticated profile, updates state,\n * and returns the X profile. The profile is resolved server-side from the\n * verified bearer token.\n *\n * @returns The linked X profile.\n */\n async fetchAndUpdateXAccount(): Promise<XProfile> {\n const response = await this.messenger.call('ProfileService:getXAccount');\n const mapped = this.#mapXResponseToXProfile(response);\n this.update((state) => {\n state.xProfile = mapped;\n });\n return mapped;\n }\n\n /**\n * Initiates the X OAuth flow by fetching the authorization URL from the backend.\n * The profile is resolved server-side from the verified bearer token.\n * Returns session data for the caller to use; nothing is stored in controller state.\n *\n * @returns The X authorization URL and state parameter.\n * @throws If no profile has been created yet.\n */\n async getXAuthorizationUrl(): Promise<ConnectXSession> {\n this.#getProfileIdOrThrow();\n const response = await this.messenger.call('ProfileService:getXAuthUrl');\n return { authorizationUrl: response.url, state: response.state };\n }\n\n /**\n * Disconnects the X account linked to the given profile. If the given\n * profile matches the profile in state, clears `xProfile` from state and\n * marks the profile in state as no longer connected to X.\n *\n * @param profileId - The ID of the profile to disconnect the linked X account\n * from (sourced from {@link getProfile}).\n */\n async disconnectX(profileId: string): Promise<void> {\n await this.messenger.call('ProfileService:disconnectX', profileId);\n this.update((state) => {\n if (state.profile.profileId === profileId) {\n state.xProfile = undefined;\n state.profile.connectedToX = false;\n }\n });\n }\n}\n"]}
|
|
@@ -78,6 +78,7 @@ export type ProfileServiceCheckUsernameAvailabilityAction = {
|
|
|
78
78
|
};
|
|
79
79
|
/**
|
|
80
80
|
* Fetches the X OAuth PKCE authorization URL and its associated state parameter.
|
|
81
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
81
82
|
*
|
|
82
83
|
* @returns An object containing the authorization URL and the state token.
|
|
83
84
|
* @throws {HttpError} If the API returns a non-2xx response.
|
|
@@ -89,6 +90,7 @@ export type ProfileServiceGetXAuthUrlAction = {
|
|
|
89
90
|
};
|
|
90
91
|
/**
|
|
91
92
|
* Completes the X OAuth PKCE flow and links the X account to the profile.
|
|
93
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
92
94
|
*
|
|
93
95
|
* @param params - The OAuth callback code and state from the X redirect.
|
|
94
96
|
* @returns The linked X account data.
|
|
@@ -101,6 +103,7 @@ export type ProfileServiceConnectXAction = {
|
|
|
101
103
|
};
|
|
102
104
|
/**
|
|
103
105
|
* Fetches the X account currently linked to the authenticated profile.
|
|
106
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
104
107
|
*
|
|
105
108
|
* @returns The linked X account data.
|
|
106
109
|
* @throws {HttpError} If the API returns a non-2xx response.
|
|
@@ -110,8 +113,21 @@ export type ProfileServiceGetXAccountAction = {
|
|
|
110
113
|
type: `ProfileService:getXAccount`;
|
|
111
114
|
handler: ProfileService['getXAccount'];
|
|
112
115
|
};
|
|
116
|
+
/**
|
|
117
|
+
* Disconnects the X account linked to the given profile.
|
|
118
|
+
* A `404` response is treated as success (the X account is already
|
|
119
|
+
* disconnected, or the profile is unknown), making the operation idempotent.
|
|
120
|
+
*
|
|
121
|
+
* @param profileId - The ID of the profile to disconnect the linked X account from.
|
|
122
|
+
* @returns The result of the mutation.
|
|
123
|
+
* @throws {HttpError} If the API returns a non-2xx response other than `404`.
|
|
124
|
+
*/
|
|
125
|
+
export type ProfileServiceDisconnectXAction = {
|
|
126
|
+
type: `ProfileService:disconnectX`;
|
|
127
|
+
handler: ProfileService['disconnectX'];
|
|
128
|
+
};
|
|
113
129
|
/**
|
|
114
130
|
* Union of all ProfileService action types.
|
|
115
131
|
*/
|
|
116
|
-
export type ProfileServiceMethodActions = ProfileServiceGetProfileAction | ProfileServiceCreateProfileAction | ProfileServiceReplaceProfileAction | ProfileServiceUpdateProfileAction | ProfileServiceDeleteProfileAction | ProfileServiceCheckUsernameAvailabilityAction | ProfileServiceGetXAuthUrlAction | ProfileServiceConnectXAction | ProfileServiceGetXAccountAction;
|
|
132
|
+
export type ProfileServiceMethodActions = ProfileServiceGetProfileAction | ProfileServiceCreateProfileAction | ProfileServiceReplaceProfileAction | ProfileServiceUpdateProfileAction | ProfileServiceDeleteProfileAction | ProfileServiceCheckUsernameAvailabilityAction | ProfileServiceGetXAuthUrlAction | ProfileServiceConnectXAction | ProfileServiceGetXAccountAction | ProfileServiceDisconnectXAction;
|
|
117
133
|
//# sourceMappingURL=ProfileService-method-action-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileService-method-action-types.d.ts","sourceRoot":"","sources":["../src/ProfileService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,cAAc,CAAC,2BAA2B,CAAC,CAAC;CACtD,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"ProfileService-method-action-types.d.ts","sourceRoot":"","sources":["../src/ProfileService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;CACvC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,+BAA+B,CAAC;IACtC,OAAO,EAAE,cAAc,CAAC,gBAAgB,CAAC,CAAC;CAC3C,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,cAAc,CAAC,eAAe,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,6CAA6C,GAAG;IAC1D,IAAI,EAAE,0CAA0C,CAAC;IACjD,OAAO,EAAE,cAAc,CAAC,2BAA2B,CAAC,CAAC;CACtD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;CACrC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;CACxC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,cAAc,CAAC,aAAa,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,8BAA8B,GAC9B,iCAAiC,GACjC,kCAAkC,GAClC,iCAAiC,GACjC,iCAAiC,GACjC,6CAA6C,GAC7C,+BAA+B,GAC/B,4BAA4B,GAC5B,+BAA+B,GAC/B,+BAA+B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileService-method-action-types.js","sourceRoot":"","sources":["../src/ProfileService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ProfileService } from './ProfileService.js';\n\n/**\n * Fetches a profile by its identifier.\n *\n * @param profileId - The profile identifier to fetch.\n * @returns The profile data from the API.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceGetProfileAction = {\n type: `ProfileService:getProfile`;\n handler: ProfileService['getProfile'];\n};\n\n/**\n * Creates a new MetaMask profile.\n *\n * @param params - The profile creation parameters.\n * @returns The created profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\nexport type ProfileServiceCreateProfileAction = {\n type: `ProfileService:createProfile`;\n handler: ProfileService['createProfile'];\n};\n\n/**\n * Fully replaces an existing profile (PUT).\n *\n * @param profileId - The identifier of the profile to replace.\n * @param params - The replacement profile data.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\nexport type ProfileServiceReplaceProfileAction = {\n type: `ProfileService:replaceProfile`;\n handler: ProfileService['replaceProfile'];\n};\n\n/**\n * Partially updates an existing profile (PATCH).\n *\n * @param profileId - The identifier of the profile to update.\n * @param params - The fields to update.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\nexport type ProfileServiceUpdateProfileAction = {\n type: `ProfileService:updateProfile`;\n handler: ProfileService['updateProfile'];\n};\n\n/**\n * Deletes a profile by its identifier.\n *\n * @param profileId - The identifier of the profile to delete.\n * @returns The result of the mutation.\n * @throws {HttpError} If the API returns a non-2xx response.\n */\nexport type ProfileServiceDeleteProfileAction = {\n type: `ProfileService:deleteProfile`;\n handler: ProfileService['deleteProfile'];\n};\n\n/**\n * Checks whether a username is available.\n *\n * @param username - The username to check.\n * @returns Availability details including validity and normalized form.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceCheckUsernameAvailabilityAction = {\n type: `ProfileService:checkUsernameAvailability`;\n handler: ProfileService['checkUsernameAvailability'];\n};\n\n/**\n * Fetches the X OAuth PKCE authorization URL and its associated state parameter.\n *\n * @returns An object containing the authorization URL and the state token.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceGetXAuthUrlAction = {\n type: `ProfileService:getXAuthUrl`;\n handler: ProfileService['getXAuthUrl'];\n};\n\n/**\n * Completes the X OAuth PKCE flow and links the X account to the profile.\n *\n * @param params - The OAuth callback code and state from the X redirect.\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceConnectXAction = {\n type: `ProfileService:connectX`;\n handler: ProfileService['connectX'];\n};\n\n/**\n * Fetches the X account currently linked to the authenticated profile.\n *\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceGetXAccountAction = {\n type: `ProfileService:getXAccount`;\n handler: ProfileService['getXAccount'];\n};\n\n/**\n * Union of all ProfileService action types.\n */\nexport type ProfileServiceMethodActions =\n | ProfileServiceGetProfileAction\n | ProfileServiceCreateProfileAction\n | ProfileServiceReplaceProfileAction\n | ProfileServiceUpdateProfileAction\n | ProfileServiceDeleteProfileAction\n | ProfileServiceCheckUsernameAvailabilityAction\n | ProfileServiceGetXAuthUrlAction\n | ProfileServiceConnectXAction\n | ProfileServiceGetXAccountAction;\n"]}
|
|
1
|
+
{"version":3,"file":"ProfileService-method-action-types.js","sourceRoot":"","sources":["../src/ProfileService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { ProfileService } from './ProfileService.js';\n\n/**\n * Fetches a profile by its identifier.\n *\n * @param profileId - The profile identifier to fetch.\n * @returns The profile data from the API.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceGetProfileAction = {\n type: `ProfileService:getProfile`;\n handler: ProfileService['getProfile'];\n};\n\n/**\n * Creates a new MetaMask profile.\n *\n * @param params - The profile creation parameters.\n * @returns The created profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\nexport type ProfileServiceCreateProfileAction = {\n type: `ProfileService:createProfile`;\n handler: ProfileService['createProfile'];\n};\n\n/**\n * Fully replaces an existing profile (PUT).\n *\n * @param profileId - The identifier of the profile to replace.\n * @param params - The replacement profile data.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\nexport type ProfileServiceReplaceProfileAction = {\n type: `ProfileService:replaceProfile`;\n handler: ProfileService['replaceProfile'];\n};\n\n/**\n * Partially updates an existing profile (PATCH).\n *\n * @param profileId - The identifier of the profile to update.\n * @param params - The fields to update.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\nexport type ProfileServiceUpdateProfileAction = {\n type: `ProfileService:updateProfile`;\n handler: ProfileService['updateProfile'];\n};\n\n/**\n * Deletes a profile by its identifier.\n *\n * @param profileId - The identifier of the profile to delete.\n * @returns The result of the mutation.\n * @throws {HttpError} If the API returns a non-2xx response.\n */\nexport type ProfileServiceDeleteProfileAction = {\n type: `ProfileService:deleteProfile`;\n handler: ProfileService['deleteProfile'];\n};\n\n/**\n * Checks whether a username is available.\n *\n * @param username - The username to check.\n * @returns Availability details including validity and normalized form.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceCheckUsernameAvailabilityAction = {\n type: `ProfileService:checkUsernameAvailability`;\n handler: ProfileService['checkUsernameAvailability'];\n};\n\n/**\n * Fetches the X OAuth PKCE authorization URL and its associated state parameter.\n * The profile is resolved server-side from the verified bearer token.\n *\n * @returns An object containing the authorization URL and the state token.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceGetXAuthUrlAction = {\n type: `ProfileService:getXAuthUrl`;\n handler: ProfileService['getXAuthUrl'];\n};\n\n/**\n * Completes the X OAuth PKCE flow and links the X account to the profile.\n * The profile is resolved server-side from the verified bearer token.\n *\n * @param params - The OAuth callback code and state from the X redirect.\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceConnectXAction = {\n type: `ProfileService:connectX`;\n handler: ProfileService['connectX'];\n};\n\n/**\n * Fetches the X account currently linked to the authenticated profile.\n * The profile is resolved server-side from the verified bearer token.\n *\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\nexport type ProfileServiceGetXAccountAction = {\n type: `ProfileService:getXAccount`;\n handler: ProfileService['getXAccount'];\n};\n\n/**\n * Disconnects the X account linked to the given profile.\n * A `404` response is treated as success (the X account is already\n * disconnected, or the profile is unknown), making the operation idempotent.\n *\n * @param profileId - The ID of the profile to disconnect the linked X account from.\n * @returns The result of the mutation.\n * @throws {HttpError} If the API returns a non-2xx response other than `404`.\n */\nexport type ProfileServiceDisconnectXAction = {\n type: `ProfileService:disconnectX`;\n handler: ProfileService['disconnectX'];\n};\n\n/**\n * Union of all ProfileService action types.\n */\nexport type ProfileServiceMethodActions =\n | ProfileServiceGetProfileAction\n | ProfileServiceCreateProfileAction\n | ProfileServiceReplaceProfileAction\n | ProfileServiceUpdateProfileAction\n | ProfileServiceDeleteProfileAction\n | ProfileServiceCheckUsernameAvailabilityAction\n | ProfileServiceGetXAuthUrlAction\n | ProfileServiceConnectXAction\n | ProfileServiceGetXAccountAction\n | ProfileServiceDisconnectXAction;\n"]}
|
package/dist/ProfileService.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const ProfileServiceErrorMessage: {
|
|
|
16
16
|
readonly GET_X_AUTH_URL_FAILED: 'ProfileService: failed to get X authentication URL';
|
|
17
17
|
readonly CONNECT_X_FAILED: 'ProfileService: failed to connect X account';
|
|
18
18
|
readonly GET_X_ACCOUNT_FAILED: 'ProfileService: failed to get X account';
|
|
19
|
+
readonly DISCONNECT_X_FAILED: 'ProfileService: failed to disconnect X account';
|
|
19
20
|
};
|
|
20
21
|
declare const ProfileApiResponseStruct: import("@metamask/superstruct").Struct<{
|
|
21
22
|
profile_id: string;
|
|
@@ -75,7 +76,7 @@ declare const XAuthUrlResponseStruct: import("@metamask/superstruct").Struct<{
|
|
|
75
76
|
url: import("@metamask/superstruct").Struct<string, null>;
|
|
76
77
|
state: import("@metamask/superstruct").Struct<string, null>;
|
|
77
78
|
}>;
|
|
78
|
-
declare const
|
|
79
|
+
declare const ConnectXResponseStruct: import("@metamask/superstruct").Struct<{
|
|
79
80
|
x_user_id: string;
|
|
80
81
|
x_profile_url: string;
|
|
81
82
|
username: string;
|
|
@@ -184,11 +185,11 @@ export type CreateProfileResponse = Infer<typeof CreateProfileResponseStruct>;
|
|
|
184
185
|
/** The response shape for a username availability check. */
|
|
185
186
|
export type UsernameAvailabilityResponse = Infer<typeof UsernameAvailabilityResponseStruct>;
|
|
186
187
|
/** The response shape returned when connecting or fetching an X account. */
|
|
187
|
-
export type
|
|
188
|
+
export type ConnectXResponse = Infer<typeof ConnectXResponseStruct>;
|
|
188
189
|
/** The response shape returned when requesting the X OAuth authentication URL. */
|
|
189
190
|
export type XAuthUrlResponse = Infer<typeof XAuthUrlResponseStruct>;
|
|
190
|
-
/** Alias for {@link
|
|
191
|
-
export type XAccountResponse =
|
|
191
|
+
/** Alias for {@link ConnectXResponse} returned when fetching the linked X account. */
|
|
192
|
+
export type XAccountResponse = ConnectXResponse;
|
|
192
193
|
/** Parameters for creating a new MetaMask profile. */
|
|
193
194
|
export type CreateProfileParams = Infer<typeof CreateProfileParamsStruct>;
|
|
194
195
|
/** Parameters for fully replacing an existing MetaMask profile (PUT). */
|
|
@@ -282,6 +283,7 @@ export declare class ProfileService extends BaseDataService<typeof serviceName,
|
|
|
282
283
|
checkUsernameAvailability(username: string): Promise<UsernameAvailabilityResponse>;
|
|
283
284
|
/**
|
|
284
285
|
* Fetches the X OAuth PKCE authorization URL and its associated state parameter.
|
|
286
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
285
287
|
*
|
|
286
288
|
* @returns An object containing the authorization URL and the state token.
|
|
287
289
|
* @throws {HttpError} If the API returns a non-2xx response.
|
|
@@ -290,21 +292,33 @@ export declare class ProfileService extends BaseDataService<typeof serviceName,
|
|
|
290
292
|
getXAuthUrl(): Promise<XAuthUrlResponse>;
|
|
291
293
|
/**
|
|
292
294
|
* Completes the X OAuth PKCE flow and links the X account to the profile.
|
|
295
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
293
296
|
*
|
|
294
297
|
* @param params - The OAuth callback code and state from the X redirect.
|
|
295
298
|
* @returns The linked X account data.
|
|
296
299
|
* @throws {HttpError} If the API returns a non-2xx response.
|
|
297
300
|
* @throws {StructError} If the response does not match the expected shape.
|
|
298
301
|
*/
|
|
299
|
-
connectX(params: ConnectXParams): Promise<
|
|
302
|
+
connectX(params: ConnectXParams): Promise<ConnectXResponse>;
|
|
300
303
|
/**
|
|
301
304
|
* Fetches the X account currently linked to the authenticated profile.
|
|
305
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
302
306
|
*
|
|
303
307
|
* @returns The linked X account data.
|
|
304
308
|
* @throws {HttpError} If the API returns a non-2xx response.
|
|
305
309
|
* @throws {StructError} If the response does not match the expected shape.
|
|
306
310
|
*/
|
|
307
311
|
getXAccount(): Promise<XAccountResponse>;
|
|
312
|
+
/**
|
|
313
|
+
* Disconnects the X account linked to the given profile.
|
|
314
|
+
* A `404` response is treated as success (the X account is already
|
|
315
|
+
* disconnected, or the profile is unknown), making the operation idempotent.
|
|
316
|
+
*
|
|
317
|
+
* @param profileId - The ID of the profile to disconnect the linked X account from.
|
|
318
|
+
* @returns The result of the mutation.
|
|
319
|
+
* @throws {HttpError} If the API returns a non-2xx response other than `404`.
|
|
320
|
+
*/
|
|
321
|
+
disconnectX(profileId: string): Promise<void>;
|
|
308
322
|
}
|
|
309
323
|
export {};
|
|
310
324
|
//# sourceMappingURL=ProfileService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileService.d.ts","sourceRoot":"","sources":["../src/ProfileService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,KAAK,EACV,0BAA0B,EAC1B,4BAA4B,EAC5B,oCAAoC,EACpC,kCAAkC,EACnC,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAYlF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAInD,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAE3F,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAM5C,uEAAuE;AACvE,eAAO,MAAM,0BAA0B;aACrC,kBAAkB,EAAE,yCAAyC;aAC7D,qBAAqB,EAAE,0CAA0C;aACjE,sBAAsB,EAAE,2CAA2C;aACnE,qBAAqB,EAAE,0CAA0C;aACjE,qBAAqB,EAAE,0CAA0C;aACjE,kCAAkC,EAChC,uDAAuD;aACzD,qBAAqB,EAAE,oDAAoD;aAC3E,gBAAgB,EAAE,6CAA6C;aAC/D,oBAAoB,EAAE,yCAAyC;
|
|
1
|
+
{"version":3,"file":"ProfileService.d.ts","sourceRoot":"","sources":["../src/ProfileService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO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AO,CAAC,gBAAgB,CAAC,CAehE;IAED;;;;;;;OAOG;IACG,WAAW,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAU7C;IAED;;;;;;;;OAQG;IACG,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBlD;CACF"}
|
package/dist/ProfileService.js
CHANGED
|
@@ -17,6 +17,7 @@ export const ProfileServiceErrorMessage = {
|
|
|
17
17
|
GET_X_AUTH_URL_FAILED: 'ProfileService: failed to get X authentication URL',
|
|
18
18
|
CONNECT_X_FAILED: 'ProfileService: failed to connect X account',
|
|
19
19
|
GET_X_ACCOUNT_FAILED: 'ProfileService: failed to get X account',
|
|
20
|
+
DISCONNECT_X_FAILED: 'ProfileService: failed to disconnect X account',
|
|
20
21
|
};
|
|
21
22
|
// ---------------------------------------------------------------------------
|
|
22
23
|
// Superstruct schemas
|
|
@@ -49,7 +50,7 @@ const XAuthUrlResponseStruct = structType({
|
|
|
49
50
|
url: sensitive(string()),
|
|
50
51
|
state: sensitive(string()),
|
|
51
52
|
});
|
|
52
|
-
const
|
|
53
|
+
const ConnectXResponseStruct = structType({
|
|
53
54
|
x_user_id: string(),
|
|
54
55
|
x_profile_url: string(),
|
|
55
56
|
username: string(),
|
|
@@ -60,7 +61,7 @@ const XConnectResponseStruct = structType({
|
|
|
60
61
|
});
|
|
61
62
|
const CreateProfileResponseStruct = intersection([
|
|
62
63
|
ProfileApiResponseStruct,
|
|
63
|
-
structType({ x_profile: optional(
|
|
64
|
+
structType({ x_profile: optional(ConnectXResponseStruct) }),
|
|
64
65
|
]);
|
|
65
66
|
const ConnectXParamsStruct = structType({
|
|
66
67
|
code: sensitive(string()),
|
|
@@ -104,6 +105,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
104
105
|
'getXAuthUrl',
|
|
105
106
|
'connectX',
|
|
106
107
|
'getXAccount',
|
|
108
|
+
'disconnectX',
|
|
107
109
|
];
|
|
108
110
|
// ---------------------------------------------------------------------------
|
|
109
111
|
// Service
|
|
@@ -273,6 +275,7 @@ export class ProfileService extends BaseDataService {
|
|
|
273
275
|
}
|
|
274
276
|
/**
|
|
275
277
|
* Fetches the X OAuth PKCE authorization URL and its associated state parameter.
|
|
278
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
276
279
|
*
|
|
277
280
|
* @returns An object containing the authorization URL and the state token.
|
|
278
281
|
* @throws {HttpError} If the API returns a non-2xx response.
|
|
@@ -289,6 +292,7 @@ export class ProfileService extends BaseDataService {
|
|
|
289
292
|
}
|
|
290
293
|
/**
|
|
291
294
|
* Completes the X OAuth PKCE flow and links the X account to the profile.
|
|
295
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
292
296
|
*
|
|
293
297
|
* @param params - The OAuth callback code and state from the X redirect.
|
|
294
298
|
* @returns The linked X account data.
|
|
@@ -296,18 +300,23 @@ export class ProfileService extends BaseDataService {
|
|
|
296
300
|
* @throws {StructError} If the response does not match the expected shape.
|
|
297
301
|
*/
|
|
298
302
|
async connectX(params) {
|
|
299
|
-
|
|
303
|
+
const response = await this.executeMutation({
|
|
300
304
|
mutationKey: [`${this.name}:connectX`],
|
|
301
|
-
responseStruct:
|
|
305
|
+
responseStruct: ConnectXResponseStruct,
|
|
302
306
|
mutationFn: async () => this.#fetch('profiles/x/connect', {
|
|
303
307
|
method: 'POST',
|
|
304
308
|
error: ProfileServiceErrorMessage.CONNECT_X_FAILED,
|
|
305
309
|
json: params,
|
|
306
310
|
}),
|
|
307
311
|
});
|
|
312
|
+
// The response does not identify the profile, so drop every cached
|
|
313
|
+
// profile: `connected_to_x` is now out of date.
|
|
314
|
+
await this.invalidateQueries({ queryKey: [`${this.name}:getProfile`] });
|
|
315
|
+
return response;
|
|
308
316
|
}
|
|
309
317
|
/**
|
|
310
318
|
* Fetches the X account currently linked to the authenticated profile.
|
|
319
|
+
* The profile is resolved server-side from the verified bearer token.
|
|
311
320
|
*
|
|
312
321
|
* @returns The linked X account data.
|
|
313
322
|
* @throws {HttpError} If the API returns a non-2xx response.
|
|
@@ -317,11 +326,43 @@ export class ProfileService extends BaseDataService {
|
|
|
317
326
|
return this.fetchQuery({
|
|
318
327
|
queryKey: [`${this.name}:getXAccount`],
|
|
319
328
|
staleTime: 0,
|
|
320
|
-
responseStruct:
|
|
329
|
+
responseStruct: ConnectXResponseStruct,
|
|
321
330
|
queryFn: async () => this.#fetch('profiles/x/account', {
|
|
322
331
|
error: ProfileServiceErrorMessage.GET_X_ACCOUNT_FAILED,
|
|
323
332
|
}),
|
|
324
333
|
});
|
|
325
334
|
}
|
|
335
|
+
/**
|
|
336
|
+
* Disconnects the X account linked to the given profile.
|
|
337
|
+
* A `404` response is treated as success (the X account is already
|
|
338
|
+
* disconnected, or the profile is unknown), making the operation idempotent.
|
|
339
|
+
*
|
|
340
|
+
* @param profileId - The ID of the profile to disconnect the linked X account from.
|
|
341
|
+
* @returns The result of the mutation.
|
|
342
|
+
* @throws {HttpError} If the API returns a non-2xx response other than `404`.
|
|
343
|
+
*/
|
|
344
|
+
async disconnectX(profileId) {
|
|
345
|
+
await this.executeMutation({
|
|
346
|
+
mutationKey: [`${this.name}:disconnectX`, profileId],
|
|
347
|
+
mutationFn: async () => {
|
|
348
|
+
try {
|
|
349
|
+
return await this.#fetch(`profiles/${encodeURIComponent(profileId)}/x`, {
|
|
350
|
+
method: 'DELETE',
|
|
351
|
+
error: ProfileServiceErrorMessage.DISCONNECT_X_FAILED,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
if (error instanceof HttpError && error.httpStatus === 404) {
|
|
356
|
+
return null;
|
|
357
|
+
}
|
|
358
|
+
throw error;
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
// The cached profile no longer reflects `connected_to_x`.
|
|
363
|
+
await this.invalidateQueries({
|
|
364
|
+
queryKey: [`${this.name}:getProfile`, profileId],
|
|
365
|
+
});
|
|
366
|
+
}
|
|
326
367
|
}
|
|
327
368
|
//# sourceMappingURL=ProfileService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileService.js","sourceRoot":"","sources":["../src/ProfileService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGvD,OAAO,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,EACN,IAAI,IAAI,UAAU,GACnB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAItD,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAE5C,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,uEAAuE;AACvE,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,kBAAkB,EAAE,yCAAyC;IAC7D,qBAAqB,EAAE,0CAA0C;IACjE,sBAAsB,EAAE,2CAA2C;IACnE,qBAAqB,EAAE,0CAA0C;IACjE,qBAAqB,EAAE,0CAA0C;IACjE,kCAAkC,EAChC,uDAAuD;IACzD,qBAAqB,EAAE,oDAAoD;IAC3E,gBAAgB,EAAE,6CAA6C;IAC/D,oBAAoB,EAAE,yCAAyC;CACvD,CAAC;AAEX,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,MAAM,oBAAoB,GAAG,KAAK,CAAC,CAAC,QAAQ,EAAE,SAAS,CAAU,CAAC,CAAC;AAEnE,MAAM,wBAAwB,GAAG,UAAU,CAAC;IAC1C,UAAU,EAAE,MAAM,EAAE;IACpB,QAAQ,EAAE,MAAM,EAAE;IAClB,YAAY,EAAE,MAAM,EAAE;IACtB,GAAG,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC;IACvB,gBAAgB,EAAE,KAAK,CAAC,mBAAmB,CAAC;IAC5C,UA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IAAI,CAAC,IAAI,WAAW,CAAC;YACtC,cAAc,EAAE,sBAAsB;YACtC,UAAU,EAAE,KAAK,IAAI,EAAE,CACrB,IAAI,CAAC,MAAM,CAAmB,oBAAoB,EAAE;gBAClD,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE,0BAA0B,CAAC,gBAAgB;gBAClD,IAAI,EAAE,MAAM;aACb,CAAC;SACL,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;YACrB,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,cAAc,CAAC;YACtC,SAAS,EAAE,CAAC;YACZ,cAAc,EAAE,sBAAsB;YACtC,OAAO,EAAE,KAAK,IAAI,EAAE,CAClB,IAAI,CAAC,MAAM,CAAmB,oBAAoB,EAAE;gBAClD,KAAK,EAAE,0BAA0B,CAAC,oBAAoB;aACvD,CAAC;SACL,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n CreateServicePolicyOptions,\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport {\n array,\n boolean,\n enums,\n intersection,\n nullable,\n optional,\n sensitive,\n string,\n type as structType,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { CaipAccountIdStruct } from '@metamask/utils';\n\nimport type { ProfileServiceMethodActions } from './ProfileService-method-action-types.js';\n\nexport const serviceName = 'ProfileService';\n\n// ---------------------------------------------------------------------------\n// Error messages\n// ---------------------------------------------------------------------------\n\n/** Human-readable error messages for each ProfileService operation. */\nexport const ProfileServiceErrorMessage = {\n GET_PROFILE_FAILED: 'ProfileService: failed to fetch profile',\n CREATE_PROFILE_FAILED: 'ProfileService: failed to create profile',\n REPLACE_PROFILE_FAILED: 'ProfileService: failed to replace profile',\n UPDATE_PROFILE_FAILED: 'ProfileService: failed to update profile',\n DELETE_PROFILE_FAILED: 'ProfileService: failed to delete profile',\n CHECK_USERNAME_AVAILABILITY_FAILED:\n 'ProfileService: failed to check username availability',\n GET_X_AUTH_URL_FAILED: 'ProfileService: failed to get X authentication URL',\n CONNECT_X_FAILED: 'ProfileService: failed to connect X account',\n GET_X_ACCOUNT_FAILED: 'ProfileService: failed to get X account',\n} as const;\n\n// ---------------------------------------------------------------------------\n// Superstruct schemas\n// ---------------------------------------------------------------------------\n\nconst TradingPrivacyStruct = enums(['public', 'private'] as const);\n\nconst ProfileApiResponseStruct = structType({\n profile_id: string(),\n username: string(),\n display_name: string(),\n bio: nullable(string()),\n linked_addresses: array(CaipAccountIdStruct),\n avatar_url: nullable(string()),\n trading_privacy: TradingPrivacyStruct,\n connected_to_x: boolean(),\n created_at: string(),\n updated_at: string(),\n});\n\nconst UsernameAvailabilityErrorStruct = structType({\n code: string(),\n message: string(),\n});\n\nconst UsernameAvailabilityResponseStruct = structType({\n username: string(),\n available: boolean(),\n valid: boolean(),\n normalized: string(),\n errors: array(UsernameAvailabilityErrorStruct),\n});\n\nconst XAuthUrlResponseStruct = structType({\n url: sensitive(string()),\n state: sensitive(string()),\n});\n\nconst XConnectResponseStruct = structType({\n x_user_id: string(),\n x_profile_url: string(),\n username: string(),\n display_name: string(),\n avatar_url: string(),\n created_at: string(),\n updated_at: string(),\n});\n\nconst CreateProfileResponseStruct = intersection([\n ProfileApiResponseStruct,\n structType({ x_profile: optional(XConnectResponseStruct) }),\n]);\n\nconst ConnectXParamsStruct = structType({\n code: sensitive(string()),\n state: sensitive(string()),\n});\n\nconst CreateProfileParamsStruct = structType({\n profile_id: string(),\n username: string(),\n display_name: string(),\n bio: optional(nullable(string())),\n linked_addresses: array(CaipAccountIdStruct),\n avatar_url: optional(string()),\n trading_privacy: TradingPrivacyStruct,\n});\n\nconst ReplaceProfileParamsStruct = structType({\n username: string(),\n display_name: string(),\n bio: optional(nullable(string())),\n linked_addresses: array(CaipAccountIdStruct),\n avatar_url: optional(string()),\n trading_privacy: TradingPrivacyStruct,\n});\n\nconst UpdateProfileParamsStruct = structType({\n username: optional(string()),\n display_name: optional(string()),\n bio: optional(nullable(string())),\n linked_addresses: optional(array(CaipAccountIdStruct)),\n avatar_url: optional(string()),\n trading_privacy: optional(TradingPrivacyStruct),\n});\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getProfile',\n 'createProfile',\n 'replaceProfile',\n 'updateProfile',\n 'deleteProfile',\n 'checkUsernameAvailability',\n 'getXAuthUrl',\n 'connectX',\n 'getXAccount',\n] as const;\n\n/** The shape of a profile returned by the MetaMask Profile API. */\nexport type ProfileApiResponse = Infer<typeof ProfileApiResponseStruct>;\n\n/** The response shape for createProfile — includes an optional linked X profile if the user had already connected X. */\nexport type CreateProfileResponse = Infer<typeof CreateProfileResponseStruct>;\n\n/** The response shape for a username availability check. */\nexport type UsernameAvailabilityResponse = Infer<\n typeof UsernameAvailabilityResponseStruct\n>;\n\n/** The response shape returned when connecting or fetching an X account. */\nexport type XConnectResponse = Infer<typeof XConnectResponseStruct>;\n\n/** The response shape returned when requesting the X OAuth authentication URL. */\nexport type XAuthUrlResponse = Infer<typeof XAuthUrlResponseStruct>;\n\n/** Alias for {@link XConnectResponse} returned when fetching the linked X account. */\nexport type XAccountResponse = XConnectResponse;\n\n/** Parameters for creating a new MetaMask profile. */\nexport type CreateProfileParams = Infer<typeof CreateProfileParamsStruct>;\n\n/** Parameters for fully replacing an existing MetaMask profile (PUT). */\nexport type ReplaceProfileParams = Infer<typeof ReplaceProfileParamsStruct>;\n\n/** Parameters for partially updating an existing MetaMask profile (PATCH). */\nexport type UpdateProfileParams = Infer<typeof UpdateProfileParamsStruct>;\n\n/** Parameters for completing the X OAuth PKCE flow. */\nexport type ConnectXParams = Infer<typeof ConnectXParamsStruct>;\n\n// ---------------------------------------------------------------------------\n// Messenger types\n// ---------------------------------------------------------------------------\n\n/** Union of all actions exposed by ProfileService, including cache invalidation. */\nexport type ProfileServiceActions =\n | ProfileServiceMethodActions\n | DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/** Event emitted when the ProfileService query cache is updated. */\nexport type ProfileServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<\n typeof serviceName\n>;\n\n/** Event emitted with per-query granularity when the ProfileService cache is updated. */\nexport type ProfileServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/** Union of all events emitted by ProfileService. */\nexport type ProfileServiceEvents =\n | ProfileServiceCacheUpdatedEvent\n | ProfileServiceGranularCacheUpdatedEvent;\n\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerTokenAction;\n\ntype AllowedEvents = never;\n\n/** Messenger type for ProfileService, scoped to its actions and events. */\nexport type ProfileServiceMessenger = Messenger<\n typeof serviceName,\n ProfileServiceActions | AllowedActions,\n ProfileServiceEvents | AllowedEvents\n>;\n\n// ---------------------------------------------------------------------------\n// Service\n// ---------------------------------------------------------------------------\n\n/** Communicates with the MetaMask Profile API and exposes all operations via the messenger. */\nexport class ProfileService extends BaseDataService<\n typeof serviceName,\n ProfileServiceMessenger\n> {\n readonly #baseUrl: string;\n\n get #v1Url(): string {\n return `${this.#baseUrl}/v1`;\n }\n\n /**\n * Creates a new ProfileService instance.\n *\n * @param options - Constructor options.\n * @param options.messenger - The messenger scoped to ProfileService.\n * @param options.baseUrl - Base URL for the MetaMask Profile API.\n * @param options.policyOptions - Optional service policy configuration.\n */\n constructor({\n messenger,\n baseUrl,\n policyOptions,\n }: {\n messenger: ProfileServiceMessenger;\n baseUrl: string;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({ name: serviceName, messenger, policyOptions });\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Gets the authentication headers for the request.\n *\n * @returns The authentication headers.\n */\n async #getAuthHeaders(): Promise<Record<string, string>> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return { Authorization: `Bearer ${token}` };\n }\n\n /**\n * Executes an authenticated HTTP request and returns the parsed JSON response.\n *\n * @param endpoint - The path relative to the v1 base URL.\n * @param options - Request options.\n * @param options.method - The HTTP method. Defaults to 'GET'.\n * @param options.error - The error message to use if the response is not OK.\n * @param options.json - Optional JSON body. If provided, sets Content-Type and serializes as body.\n * @returns The parsed JSON response.\n * @throws {HttpError} If the response is not a 2xx status code.\n */\n async #fetch(\n endpoint: string,\n options: { method: 'DELETE'; error: string },\n ): Promise<null>;\n\n async #fetch<ResponseType extends Json>(\n endpoint: string,\n options: {\n method?: string;\n error: string;\n json?: unknown;\n searchParams?: Record<string, string>;\n },\n ): Promise<ResponseType>;\n\n async #fetch<ResponseType extends Json>(\n endpoint: string,\n {\n method = 'GET',\n error,\n json,\n searchParams,\n }: {\n method?: string;\n error: string;\n json?: unknown;\n searchParams?: Record<string, string>;\n },\n ): Promise<ResponseType | null> {\n const authHeaders = await this.#getAuthHeaders();\n const url = new URL(`${this.#v1Url}/${endpoint}`);\n if (searchParams) {\n for (const [key, value] of Object.entries(searchParams)) {\n url.searchParams.append(key, value);\n }\n }\n const response = await fetch(url.toString(), {\n ...(method === 'GET' ? {} : { method }),\n headers: {\n ...authHeaders,\n ...(json === undefined ? {} : { 'Content-Type': 'application/json' }),\n },\n ...(json === undefined ? {} : { body: JSON.stringify(json) }),\n });\n if (!response.ok) {\n throw new HttpError(response.status, `${error}: ${response.status}`);\n }\n if (method === 'DELETE') {\n return null;\n }\n return (await response.json()) as ResponseType;\n }\n\n /**\n * Fetches a profile by its identifier.\n *\n * @param profileId - The profile identifier to fetch.\n * @returns The profile data from the API.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async getProfile(profileId: string): Promise<ProfileApiResponse> {\n return this.fetchQuery({\n queryKey: [`${this.name}:getProfile`, profileId],\n responseStruct: ProfileApiResponseStruct,\n queryFn: async () =>\n this.#fetch<ProfileApiResponse>(\n `profiles/${encodeURIComponent(profileId)}`,\n {\n error: ProfileServiceErrorMessage.GET_PROFILE_FAILED,\n },\n ),\n });\n }\n\n /**\n * Creates a new MetaMask profile.\n *\n * @param params - The profile creation parameters.\n * @returns The created profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\n async createProfile(\n params: CreateProfileParams,\n ): Promise<CreateProfileResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:createProfile`],\n responseStruct: CreateProfileResponseStruct,\n mutationFn: async () =>\n this.#fetch<CreateProfileResponse>('profiles', {\n method: 'POST',\n error: ProfileServiceErrorMessage.CREATE_PROFILE_FAILED,\n json: params,\n }),\n });\n }\n\n /**\n * Fully replaces an existing profile (PUT).\n *\n * @param profileId - The identifier of the profile to replace.\n * @param params - The replacement profile data.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\n async replaceProfile(\n profileId: string,\n params: ReplaceProfileParams,\n ): Promise<ProfileApiResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:replaceProfile`, profileId],\n responseStruct: ProfileApiResponseStruct,\n mutationFn: async () =>\n this.#fetch<ProfileApiResponse>(\n `profiles/${encodeURIComponent(profileId)}`,\n {\n method: 'PUT',\n error: ProfileServiceErrorMessage.REPLACE_PROFILE_FAILED,\n json: params,\n },\n ),\n });\n }\n\n /**\n * Partially updates an existing profile (PATCH).\n *\n * @param profileId - The identifier of the profile to update.\n * @param params - The fields to update.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\n async updateProfile(\n profileId: string,\n params: UpdateProfileParams,\n ): Promise<ProfileApiResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:updateProfile`, profileId],\n responseStruct: ProfileApiResponseStruct,\n mutationFn: async () =>\n this.#fetch<ProfileApiResponse>(\n `profiles/${encodeURIComponent(profileId)}`,\n {\n method: 'PATCH',\n error: ProfileServiceErrorMessage.UPDATE_PROFILE_FAILED,\n json: params,\n },\n ),\n });\n }\n\n /**\n * Deletes a profile by its identifier.\n *\n * @param profileId - The identifier of the profile to delete.\n * @returns The result of the mutation.\n * @throws {HttpError} If the API returns a non-2xx response.\n */\n async deleteProfile(profileId: string): Promise<void> {\n return this.executeMutation({\n mutationKey: [`${this.name}:deleteProfile`, profileId],\n mutationFn: async () =>\n this.#fetch(`profiles/${encodeURIComponent(profileId)}`, {\n method: 'DELETE',\n error: ProfileServiceErrorMessage.DELETE_PROFILE_FAILED,\n }),\n });\n }\n\n /**\n * Checks whether a username is available.\n *\n * @param username - The username to check.\n * @returns Availability details including validity and normalized form.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async checkUsernameAvailability(\n username: string,\n ): Promise<UsernameAvailabilityResponse> {\n return this.fetchQuery({\n queryKey: [`${this.name}:checkUsernameAvailability`, username],\n staleTime: 0,\n responseStruct: UsernameAvailabilityResponseStruct,\n queryFn: async () =>\n this.#fetch<UsernameAvailabilityResponse>(\n 'profiles/username/availability',\n {\n error:\n ProfileServiceErrorMessage.CHECK_USERNAME_AVAILABILITY_FAILED,\n searchParams: { username },\n },\n ),\n });\n }\n\n /**\n * Fetches the X OAuth PKCE authorization URL and its associated state parameter.\n *\n * @returns An object containing the authorization URL and the state token.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async getXAuthUrl(): Promise<XAuthUrlResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:getXAuthUrl`],\n responseStruct: XAuthUrlResponseStruct,\n mutationFn: async () =>\n this.#fetch<XAuthUrlResponse>('profiles/x/authentication-url', {\n error: ProfileServiceErrorMessage.GET_X_AUTH_URL_FAILED,\n }),\n });\n }\n\n /**\n * Completes the X OAuth PKCE flow and links the X account to the profile.\n *\n * @param params - The OAuth callback code and state from the X redirect.\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async connectX(params: ConnectXParams): Promise<XConnectResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:connectX`],\n responseStruct: XConnectResponseStruct,\n mutationFn: async () =>\n this.#fetch<XConnectResponse>('profiles/x/connect', {\n method: 'POST',\n error: ProfileServiceErrorMessage.CONNECT_X_FAILED,\n json: params,\n }),\n });\n }\n\n /**\n * Fetches the X account currently linked to the authenticated profile.\n *\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async getXAccount(): Promise<XAccountResponse> {\n return this.fetchQuery({\n queryKey: [`${this.name}:getXAccount`],\n staleTime: 0,\n responseStruct: XConnectResponseStruct,\n queryFn: async () =>\n this.#fetch<XConnectResponse>('profiles/x/account', {\n error: ProfileServiceErrorMessage.GET_X_ACCOUNT_FAILED,\n }),\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ProfileService.js","sourceRoot":"","sources":["../src/ProfileService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAO9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAGvD,OAAO,EACL,KAAK,EACL,OAAO,EACP,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,MAAM,EACN,IAAI,IAAI,UAAU,GACnB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAItD,MAAM,CAAC,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAE5C,8EAA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;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,UAAU,CAAC;YACrB,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,cAAc,CAAC;YACtC,SAAS,EAAE,CAAC;YACZ,cAAc,EAAE,sBAAsB;YACtC,OAAO,EAAE,KAAK,IAAI,EAAE,CAClB,IAAI,CAAC,MAAM,CAAmB,oBAAoB,EAAE;gBAClD,KAAK,EAAE,0BAA0B,CAAC,oBAAoB;aACvD,CAAC;SACL,CAAC,CAAC;IACL,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,CAAC,SAAiB;QACjC,MAAM,IAAI,CAAC,eAAe,CAAC;YACzB,WAAW,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,cAAc,EAAE,SAAS,CAAC;YACpD,UAAU,EAAE,KAAK,IAAI,EAAE;gBACrB,IAAI,CAAC;oBACH,OAAO,MAAM,IAAI,CAAC,MAAM,CACtB,YAAY,kBAAkB,CAAC,SAAS,CAAC,IAAI,EAC7C;wBACE,MAAM,EAAE,QAAQ;wBAChB,KAAK,EAAE,0BAA0B,CAAC,mBAAmB;qBACtD,CACF,CAAC;gBACJ,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,KAAK,YAAY,SAAS,IAAI,KAAK,CAAC,UAAU,KAAK,GAAG,EAAE,CAAC;wBAC3D,OAAO,IAAI,CAAC;oBACd,CAAC;oBACD,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;SACF,CAAC,CAAC;QACH,0DAA0D;QAC1D,MAAM,IAAI,CAAC,iBAAiB,CAAC;YAC3B,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,aAAa,EAAE,SAAS,CAAC;SACjD,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { BaseDataService } from '@metamask/base-data-service';\nimport type {\n CreateServicePolicyOptions,\n DataServiceCacheUpdatedEvent,\n DataServiceGranularCacheUpdatedEvent,\n DataServiceInvalidateQueriesAction,\n} from '@metamask/base-data-service';\nimport { HttpError } from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport {\n array,\n boolean,\n enums,\n intersection,\n nullable,\n optional,\n sensitive,\n string,\n type as structType,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { CaipAccountIdStruct } from '@metamask/utils';\n\nimport type { ProfileServiceMethodActions } from './ProfileService-method-action-types.js';\n\nexport const serviceName = 'ProfileService';\n\n// ---------------------------------------------------------------------------\n// Error messages\n// ---------------------------------------------------------------------------\n\n/** Human-readable error messages for each ProfileService operation. */\nexport const ProfileServiceErrorMessage = {\n GET_PROFILE_FAILED: 'ProfileService: failed to fetch profile',\n CREATE_PROFILE_FAILED: 'ProfileService: failed to create profile',\n REPLACE_PROFILE_FAILED: 'ProfileService: failed to replace profile',\n UPDATE_PROFILE_FAILED: 'ProfileService: failed to update profile',\n DELETE_PROFILE_FAILED: 'ProfileService: failed to delete profile',\n CHECK_USERNAME_AVAILABILITY_FAILED:\n 'ProfileService: failed to check username availability',\n GET_X_AUTH_URL_FAILED: 'ProfileService: failed to get X authentication URL',\n CONNECT_X_FAILED: 'ProfileService: failed to connect X account',\n GET_X_ACCOUNT_FAILED: 'ProfileService: failed to get X account',\n DISCONNECT_X_FAILED: 'ProfileService: failed to disconnect X account',\n} as const;\n\n// ---------------------------------------------------------------------------\n// Superstruct schemas\n// ---------------------------------------------------------------------------\n\nconst TradingPrivacyStruct = enums(['public', 'private'] as const);\n\nconst ProfileApiResponseStruct = structType({\n profile_id: string(),\n username: string(),\n display_name: string(),\n bio: nullable(string()),\n linked_addresses: array(CaipAccountIdStruct),\n avatar_url: nullable(string()),\n trading_privacy: TradingPrivacyStruct,\n connected_to_x: boolean(),\n created_at: string(),\n updated_at: string(),\n});\n\nconst UsernameAvailabilityErrorStruct = structType({\n code: string(),\n message: string(),\n});\n\nconst UsernameAvailabilityResponseStruct = structType({\n username: string(),\n available: boolean(),\n valid: boolean(),\n normalized: string(),\n errors: array(UsernameAvailabilityErrorStruct),\n});\n\nconst XAuthUrlResponseStruct = structType({\n url: sensitive(string()),\n state: sensitive(string()),\n});\n\nconst ConnectXResponseStruct = structType({\n x_user_id: string(),\n x_profile_url: string(),\n username: string(),\n display_name: string(),\n avatar_url: string(),\n created_at: string(),\n updated_at: string(),\n});\n\nconst CreateProfileResponseStruct = intersection([\n ProfileApiResponseStruct,\n structType({ x_profile: optional(ConnectXResponseStruct) }),\n]);\n\nconst ConnectXParamsStruct = structType({\n code: sensitive(string()),\n state: sensitive(string()),\n});\n\nconst CreateProfileParamsStruct = structType({\n profile_id: string(),\n username: string(),\n display_name: string(),\n bio: optional(nullable(string())),\n linked_addresses: array(CaipAccountIdStruct),\n avatar_url: optional(string()),\n trading_privacy: TradingPrivacyStruct,\n});\n\nconst ReplaceProfileParamsStruct = structType({\n username: string(),\n display_name: string(),\n bio: optional(nullable(string())),\n linked_addresses: array(CaipAccountIdStruct),\n avatar_url: optional(string()),\n trading_privacy: TradingPrivacyStruct,\n});\n\nconst UpdateProfileParamsStruct = structType({\n username: optional(string()),\n display_name: optional(string()),\n bio: optional(nullable(string())),\n linked_addresses: optional(array(CaipAccountIdStruct)),\n avatar_url: optional(string()),\n trading_privacy: optional(TradingPrivacyStruct),\n});\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getProfile',\n 'createProfile',\n 'replaceProfile',\n 'updateProfile',\n 'deleteProfile',\n 'checkUsernameAvailability',\n 'getXAuthUrl',\n 'connectX',\n 'getXAccount',\n 'disconnectX',\n] as const;\n\n/** The shape of a profile returned by the MetaMask Profile API. */\nexport type ProfileApiResponse = Infer<typeof ProfileApiResponseStruct>;\n\n/** The response shape for createProfile — includes an optional linked X profile if the user had already connected X. */\nexport type CreateProfileResponse = Infer<typeof CreateProfileResponseStruct>;\n\n/** The response shape for a username availability check. */\nexport type UsernameAvailabilityResponse = Infer<\n typeof UsernameAvailabilityResponseStruct\n>;\n\n/** The response shape returned when connecting or fetching an X account. */\nexport type ConnectXResponse = Infer<typeof ConnectXResponseStruct>;\n\n/** The response shape returned when requesting the X OAuth authentication URL. */\nexport type XAuthUrlResponse = Infer<typeof XAuthUrlResponseStruct>;\n\n/** Alias for {@link ConnectXResponse} returned when fetching the linked X account. */\nexport type XAccountResponse = ConnectXResponse;\n\n/** Parameters for creating a new MetaMask profile. */\nexport type CreateProfileParams = Infer<typeof CreateProfileParamsStruct>;\n\n/** Parameters for fully replacing an existing MetaMask profile (PUT). */\nexport type ReplaceProfileParams = Infer<typeof ReplaceProfileParamsStruct>;\n\n/** Parameters for partially updating an existing MetaMask profile (PATCH). */\nexport type UpdateProfileParams = Infer<typeof UpdateProfileParamsStruct>;\n\n/** Parameters for completing the X OAuth PKCE flow. */\nexport type ConnectXParams = Infer<typeof ConnectXParamsStruct>;\n\n// ---------------------------------------------------------------------------\n// Messenger types\n// ---------------------------------------------------------------------------\n\n/** Union of all actions exposed by ProfileService, including cache invalidation. */\nexport type ProfileServiceActions =\n | ProfileServiceMethodActions\n | DataServiceInvalidateQueriesAction<typeof serviceName>;\n\n/** Event emitted when the ProfileService query cache is updated. */\nexport type ProfileServiceCacheUpdatedEvent = DataServiceCacheUpdatedEvent<\n typeof serviceName\n>;\n\n/** Event emitted with per-query granularity when the ProfileService cache is updated. */\nexport type ProfileServiceGranularCacheUpdatedEvent =\n DataServiceGranularCacheUpdatedEvent<typeof serviceName>;\n\n/** Union of all events emitted by ProfileService. */\nexport type ProfileServiceEvents =\n | ProfileServiceCacheUpdatedEvent\n | ProfileServiceGranularCacheUpdatedEvent;\n\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerTokenAction;\n\ntype AllowedEvents = never;\n\n/** Messenger type for ProfileService, scoped to its actions and events. */\nexport type ProfileServiceMessenger = Messenger<\n typeof serviceName,\n ProfileServiceActions | AllowedActions,\n ProfileServiceEvents | AllowedEvents\n>;\n\n// ---------------------------------------------------------------------------\n// Service\n// ---------------------------------------------------------------------------\n\n/** Communicates with the MetaMask Profile API and exposes all operations via the messenger. */\nexport class ProfileService extends BaseDataService<\n typeof serviceName,\n ProfileServiceMessenger\n> {\n readonly #baseUrl: string;\n\n get #v1Url(): string {\n return `${this.#baseUrl}/v1`;\n }\n\n /**\n * Creates a new ProfileService instance.\n *\n * @param options - Constructor options.\n * @param options.messenger - The messenger scoped to ProfileService.\n * @param options.baseUrl - Base URL for the MetaMask Profile API.\n * @param options.policyOptions - Optional service policy configuration.\n */\n constructor({\n messenger,\n baseUrl,\n policyOptions,\n }: {\n messenger: ProfileServiceMessenger;\n baseUrl: string;\n policyOptions?: CreateServicePolicyOptions;\n }) {\n super({ name: serviceName, messenger, policyOptions });\n this.#baseUrl = baseUrl;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Gets the authentication headers for the request.\n *\n * @returns The authentication headers.\n */\n async #getAuthHeaders(): Promise<Record<string, string>> {\n const token = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n return { Authorization: `Bearer ${token}` };\n }\n\n /**\n * Executes an authenticated HTTP request and returns the parsed JSON response.\n *\n * @param endpoint - The path relative to the v1 base URL.\n * @param options - Request options.\n * @param options.method - The HTTP method. Defaults to 'GET'.\n * @param options.error - The error message to use if the response is not OK.\n * @param options.json - Optional JSON body. If provided, sets Content-Type and serializes as body.\n * @returns The parsed JSON response.\n * @throws {HttpError} If the response is not a 2xx status code.\n */\n async #fetch(\n endpoint: string,\n options: { method: 'DELETE'; error: string },\n ): Promise<null>;\n\n async #fetch<ResponseType extends Json>(\n endpoint: string,\n options: {\n method?: string;\n error: string;\n json?: unknown;\n searchParams?: Record<string, string>;\n },\n ): Promise<ResponseType>;\n\n async #fetch<ResponseType extends Json>(\n endpoint: string,\n {\n method = 'GET',\n error,\n json,\n searchParams,\n }: {\n method?: string;\n error: string;\n json?: unknown;\n searchParams?: Record<string, string>;\n },\n ): Promise<ResponseType | null> {\n const authHeaders = await this.#getAuthHeaders();\n const url = new URL(`${this.#v1Url}/${endpoint}`);\n if (searchParams) {\n for (const [key, value] of Object.entries(searchParams)) {\n url.searchParams.append(key, value);\n }\n }\n const response = await fetch(url.toString(), {\n ...(method === 'GET' ? {} : { method }),\n headers: {\n ...authHeaders,\n ...(json === undefined ? {} : { 'Content-Type': 'application/json' }),\n },\n ...(json === undefined ? {} : { body: JSON.stringify(json) }),\n });\n if (!response.ok) {\n throw new HttpError(response.status, `${error}: ${response.status}`);\n }\n if (method === 'DELETE') {\n return null;\n }\n return (await response.json()) as ResponseType;\n }\n\n /**\n * Fetches a profile by its identifier.\n *\n * @param profileId - The profile identifier to fetch.\n * @returns The profile data from the API.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async getProfile(profileId: string): Promise<ProfileApiResponse> {\n return this.fetchQuery({\n queryKey: [`${this.name}:getProfile`, profileId],\n responseStruct: ProfileApiResponseStruct,\n queryFn: async () =>\n this.#fetch<ProfileApiResponse>(\n `profiles/${encodeURIComponent(profileId)}`,\n {\n error: ProfileServiceErrorMessage.GET_PROFILE_FAILED,\n },\n ),\n });\n }\n\n /**\n * Creates a new MetaMask profile.\n *\n * @param params - The profile creation parameters.\n * @returns The created profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\n async createProfile(\n params: CreateProfileParams,\n ): Promise<CreateProfileResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:createProfile`],\n responseStruct: CreateProfileResponseStruct,\n mutationFn: async () =>\n this.#fetch<CreateProfileResponse>('profiles', {\n method: 'POST',\n error: ProfileServiceErrorMessage.CREATE_PROFILE_FAILED,\n json: params,\n }),\n });\n }\n\n /**\n * Fully replaces an existing profile (PUT).\n *\n * @param profileId - The identifier of the profile to replace.\n * @param params - The replacement profile data.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\n async replaceProfile(\n profileId: string,\n params: ReplaceProfileParams,\n ): Promise<ProfileApiResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:replaceProfile`, profileId],\n responseStruct: ProfileApiResponseStruct,\n mutationFn: async () =>\n this.#fetch<ProfileApiResponse>(\n `profiles/${encodeURIComponent(profileId)}`,\n {\n method: 'PUT',\n error: ProfileServiceErrorMessage.REPLACE_PROFILE_FAILED,\n json: params,\n },\n ),\n });\n }\n\n /**\n * Partially updates an existing profile (PATCH).\n *\n * @param profileId - The identifier of the profile to update.\n * @param params - The fields to update.\n * @returns The updated profile data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response do not match the expected shape.\n */\n async updateProfile(\n profileId: string,\n params: UpdateProfileParams,\n ): Promise<ProfileApiResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:updateProfile`, profileId],\n responseStruct: ProfileApiResponseStruct,\n mutationFn: async () =>\n this.#fetch<ProfileApiResponse>(\n `profiles/${encodeURIComponent(profileId)}`,\n {\n method: 'PATCH',\n error: ProfileServiceErrorMessage.UPDATE_PROFILE_FAILED,\n json: params,\n },\n ),\n });\n }\n\n /**\n * Deletes a profile by its identifier.\n *\n * @param profileId - The identifier of the profile to delete.\n * @returns The result of the mutation.\n * @throws {HttpError} If the API returns a non-2xx response.\n */\n async deleteProfile(profileId: string): Promise<void> {\n return this.executeMutation({\n mutationKey: [`${this.name}:deleteProfile`, profileId],\n mutationFn: async () =>\n this.#fetch(`profiles/${encodeURIComponent(profileId)}`, {\n method: 'DELETE',\n error: ProfileServiceErrorMessage.DELETE_PROFILE_FAILED,\n }),\n });\n }\n\n /**\n * Checks whether a username is available.\n *\n * @param username - The username to check.\n * @returns Availability details including validity and normalized form.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async checkUsernameAvailability(\n username: string,\n ): Promise<UsernameAvailabilityResponse> {\n return this.fetchQuery({\n queryKey: [`${this.name}:checkUsernameAvailability`, username],\n staleTime: 0,\n responseStruct: UsernameAvailabilityResponseStruct,\n queryFn: async () =>\n this.#fetch<UsernameAvailabilityResponse>(\n 'profiles/username/availability',\n {\n error:\n ProfileServiceErrorMessage.CHECK_USERNAME_AVAILABILITY_FAILED,\n searchParams: { username },\n },\n ),\n });\n }\n\n /**\n * Fetches the X OAuth PKCE authorization URL and its associated state parameter.\n * The profile is resolved server-side from the verified bearer token.\n *\n * @returns An object containing the authorization URL and the state token.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async getXAuthUrl(): Promise<XAuthUrlResponse> {\n return this.executeMutation({\n mutationKey: [`${this.name}:getXAuthUrl`],\n responseStruct: XAuthUrlResponseStruct,\n mutationFn: async () =>\n this.#fetch<XAuthUrlResponse>('profiles/x/authentication-url', {\n error: ProfileServiceErrorMessage.GET_X_AUTH_URL_FAILED,\n }),\n });\n }\n\n /**\n * Completes the X OAuth PKCE flow and links the X account to the profile.\n * The profile is resolved server-side from the verified bearer token.\n *\n * @param params - The OAuth callback code and state from the X redirect.\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async connectX(params: ConnectXParams): Promise<ConnectXResponse> {\n const response = await this.executeMutation({\n mutationKey: [`${this.name}:connectX`],\n responseStruct: ConnectXResponseStruct,\n mutationFn: async () =>\n this.#fetch<ConnectXResponse>('profiles/x/connect', {\n method: 'POST',\n error: ProfileServiceErrorMessage.CONNECT_X_FAILED,\n json: params,\n }),\n });\n // The response does not identify the profile, so drop every cached\n // profile: `connected_to_x` is now out of date.\n await this.invalidateQueries({ queryKey: [`${this.name}:getProfile`] });\n return response;\n }\n\n /**\n * Fetches the X account currently linked to the authenticated profile.\n * The profile is resolved server-side from the verified bearer token.\n *\n * @returns The linked X account data.\n * @throws {HttpError} If the API returns a non-2xx response.\n * @throws {StructError} If the response does not match the expected shape.\n */\n async getXAccount(): Promise<XAccountResponse> {\n return this.fetchQuery({\n queryKey: [`${this.name}:getXAccount`],\n staleTime: 0,\n responseStruct: ConnectXResponseStruct,\n queryFn: async () =>\n this.#fetch<ConnectXResponse>('profiles/x/account', {\n error: ProfileServiceErrorMessage.GET_X_ACCOUNT_FAILED,\n }),\n });\n }\n\n /**\n * Disconnects the X account linked to the given profile.\n * A `404` response is treated as success (the X account is already\n * disconnected, or the profile is unknown), making the operation idempotent.\n *\n * @param profileId - The ID of the profile to disconnect the linked X account from.\n * @returns The result of the mutation.\n * @throws {HttpError} If the API returns a non-2xx response other than `404`.\n */\n async disconnectX(profileId: string): Promise<void> {\n await this.executeMutation({\n mutationKey: [`${this.name}:disconnectX`, profileId],\n mutationFn: async () => {\n try {\n return await this.#fetch(\n `profiles/${encodeURIComponent(profileId)}/x`,\n {\n method: 'DELETE',\n error: ProfileServiceErrorMessage.DISCONNECT_X_FAILED,\n },\n );\n } catch (error) {\n if (error instanceof HttpError && error.httpStatus === 404) {\n return null;\n }\n throw error;\n }\n },\n });\n // The cached profile no longer reflects `connected_to_x`.\n await this.invalidateQueries({\n queryKey: [`${this.name}:getProfile`, profileId],\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ConnectXParams, CreateProfileParams, CreateProfileResponse, ProfileApiResponse, ProfileServiceMessenger, ReplaceProfileParams, UpdateProfileParams, UsernameAvailabilityResponse, XAccountResponse, XAuthUrlResponse, ConnectXResponse } from './ProfileService.js';
|
|
2
|
+
export declare const MOCK_PROFILE_API_RESPONSE: ProfileApiResponse;
|
|
3
|
+
export declare const MOCK_X_CONNECT_RESPONSE: ConnectXResponse;
|
|
4
|
+
export declare const MOCK_X_AUTH_URL_RESPONSE: XAuthUrlResponse;
|
|
5
|
+
export type MockProfileServiceHandlers = {
|
|
6
|
+
getProfile?: (profileId: string) => Promise<ProfileApiResponse>;
|
|
7
|
+
createProfile?: (params: CreateProfileParams) => Promise<CreateProfileResponse>;
|
|
8
|
+
replaceProfile?: (profileId: string, params: ReplaceProfileParams) => Promise<ProfileApiResponse>;
|
|
9
|
+
updateProfile?: (profileId: string, params: UpdateProfileParams) => Promise<ProfileApiResponse>;
|
|
10
|
+
deleteProfile?: (profileId: string) => Promise<void>;
|
|
11
|
+
checkUsernameAvailability?: (username: string) => Promise<UsernameAvailabilityResponse>;
|
|
12
|
+
getXAuthUrl?: () => Promise<XAuthUrlResponse>;
|
|
13
|
+
connectX?: (params: ConnectXParams) => Promise<ConnectXResponse>;
|
|
14
|
+
getXAccount?: () => Promise<XAccountResponse>;
|
|
15
|
+
disconnectX?: (profileId: string) => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Registers stub action handlers for all ProfileService methods on the provided messenger.
|
|
19
|
+
* Use this in place of instantiating a real ProfileService when the profile API is unavailable.
|
|
20
|
+
*
|
|
21
|
+
* @param messenger - The ProfileServiceMessenger to register handlers on.
|
|
22
|
+
* @param handlers - Optional per-method overrides. Unspecified methods return fixture data.
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildMockProfileService(messenger: ProfileServiceMessenger, handlers?: MockProfileServiceHandlers): void;
|
|
25
|
+
//# sourceMappingURL=ProfileServiceMock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProfileServiceMock.d.ts","sourceRoot":"","sources":["../src/ProfileServiceMock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,yBAAyB,EAAE,kBAiBvC,CAAC;AAEF,eA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 'mockuser',
|
|
4
|
+
display_name: 'Mock User',
|
|
5
|
+
bio: null,
|
|
6
|
+
linked_addresses: [
|
|
7
|
+
'eip155:1:0xab16a96D359eC26a11e2C2b3d8f8B8942d5Bfcdb',
|
|
8
|
+
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:EEivRh9T4GTLEJprEaKQyjSQzW13JRb5D7jSpvPQ8296',
|
|
9
|
+
'bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6',
|
|
10
|
+
'tron:728126428:TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH',
|
|
11
|
+
'stellar:pubnet:GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',
|
|
12
|
+
],
|
|
13
|
+
avatar_url: 'https://pbs.twimg.com/profile_images/mock.jpg',
|
|
14
|
+
trading_privacy: 'public',
|
|
15
|
+
connected_to_x: true,
|
|
16
|
+
created_at: '2024-01-01T00:00:00.000Z',
|
|
17
|
+
updated_at: '2024-01-01T00:00:00.000Z',
|
|
18
|
+
};
|
|
19
|
+
export const MOCK_X_CONNECT_RESPONSE = {
|
|
20
|
+
x_user_id: 'mock-x-user-id',
|
|
21
|
+
x_profile_url: 'https://x.com/mockuser',
|
|
22
|
+
username: 'mockuser',
|
|
23
|
+
display_name: 'Mock User',
|
|
24
|
+
avatar_url: 'https://pbs.twimg.com/profile_images/mock.jpg',
|
|
25
|
+
created_at: '2024-01-01T00:00:00.000Z',
|
|
26
|
+
updated_at: '2024-01-01T00:00:00.000Z',
|
|
27
|
+
};
|
|
28
|
+
export const MOCK_X_AUTH_URL_RESPONSE = {
|
|
29
|
+
url: 'https://x.com/i/oauth2/authorize?mock=true',
|
|
30
|
+
state: 'mock-oauth-state',
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Registers stub action handlers for all ProfileService methods on the provided messenger.
|
|
34
|
+
* Use this in place of instantiating a real ProfileService when the profile API is unavailable.
|
|
35
|
+
*
|
|
36
|
+
* @param messenger - The ProfileServiceMessenger to register handlers on.
|
|
37
|
+
* @param handlers - Optional per-method overrides. Unspecified methods return fixture data.
|
|
38
|
+
*/
|
|
39
|
+
export function buildMockProfileService(messenger, handlers = {}) {
|
|
40
|
+
messenger.registerActionHandler('ProfileService:getProfile', handlers.getProfile ??
|
|
41
|
+
(async (_profileId) => MOCK_PROFILE_API_RESPONSE));
|
|
42
|
+
messenger.registerActionHandler('ProfileService:createProfile', handlers.createProfile ??
|
|
43
|
+
(async (_params) => MOCK_PROFILE_API_RESPONSE));
|
|
44
|
+
messenger.registerActionHandler('ProfileService:replaceProfile', handlers.replaceProfile ??
|
|
45
|
+
(async (_profileId, _params) => MOCK_PROFILE_API_RESPONSE));
|
|
46
|
+
messenger.registerActionHandler('ProfileService:updateProfile', handlers.updateProfile ??
|
|
47
|
+
(async (_profileId, _params) => MOCK_PROFILE_API_RESPONSE));
|
|
48
|
+
messenger.registerActionHandler('ProfileService:deleteProfile', handlers.deleteProfile ?? (async (_profileId) => undefined));
|
|
49
|
+
messenger.registerActionHandler('ProfileService:checkUsernameAvailability', handlers.checkUsernameAvailability ??
|
|
50
|
+
(async (username) => ({
|
|
51
|
+
username,
|
|
52
|
+
available: true,
|
|
53
|
+
valid: true,
|
|
54
|
+
normalized: username,
|
|
55
|
+
errors: [],
|
|
56
|
+
})));
|
|
57
|
+
messenger.registerActionHandler('ProfileService:getXAuthUrl', handlers.getXAuthUrl ??
|
|
58
|
+
(async () => MOCK_X_AUTH_URL_RESPONSE));
|
|
59
|
+
messenger.registerActionHandler('ProfileService:connectX', handlers.connectX ??
|
|
60
|
+
(async (_params) => MOCK_X_CONNECT_RESPONSE));
|
|
61
|
+
messenger.registerActionHandler('ProfileService:getXAccount', handlers.getXAccount ??
|
|
62
|
+
(async () => MOCK_X_CONNECT_RESPONSE));
|
|
63
|
+
messenger.registerActionHandler('ProfileService:disconnectX', handlers.disconnectX ?? (async (_profileId) => undefined));
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=ProfileServiceMock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProfileServiceMock.js","sourceRoot":"","sources":["../src/ProfileServiceMock.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,MAAM,yBAAyB,GAAuB;IAC3D,UAAU,EAAE,iBAAiB;IAC7B,QAAQ,EAAE,UAAU;IACpB,YAAY,EAAE,WAAW;IACzB,GAAG,EAAE,IAAI;IACT,gBAAgB,EAAE;QAChB,qDAAqD;QACrD,sFAAsF;QACtF,4EAA4E;QAC5E,mDAAmD;QACnD,yEAAyE;KAC1E;IACD,UAAU,EAAE,+CAA+C;IAC3D,eAAe,EAAE,QAAQ;IACzB,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,0BAA0B;IACtC,UAAU,EAAE,0BAA0B;CACvC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAqB;IACvD,SAAS,EAAE,gBAAgB;IAC3B,aAAa,EAAE,wBAAwB;IACvC,QAAQ,EAAE,UAAU;IACpB,YAAY,EAAE,WAAW;IACzB,UAAU,EAAE,+CAA+C;IAC3D,UAAU,EAAE,0BAA0B;IACtC,UAAU,EAAE,0BAA0B;CACvC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAqB;IACxD,GAAG,EAAE,4CAA4C;IACjD,KAAK,EAAE,kBAAkB;CAC1B,CAAC;AAyBF;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,SAAkC,EAClC,QAAQ,GAA+B,EAAE;IAEzC,SAAS,CAAC,qBAAqB,CAC7B,2BAA2B,EAC3B,QAAQ,CAAC,UAAU;QACjB,CAAC,KAAK,EAAE,UAAU,EAA+B,EAAE,CACjD,yBAAyB,CAAC,CAC/B,CAAC;IAEF,SAAS,CAAC,qBAAqB,CAC7B,8BAA8B,EAC9B,QAAQ,CAAC,aAAa;QACpB,CAAC,KAAK,EAAE,OAAO,EA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,CAAC,WAAW,IAAI,CAAC,KAAK,EAAE,UAAU,EAAiB,EAAE,CAAC,SAAS,CAAC,CACzE,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ConnectXParams,\n CreateProfileParams,\n CreateProfileResponse,\n ProfileApiResponse,\n ProfileServiceMessenger,\n ReplaceProfileParams,\n UpdateProfileParams,\n UsernameAvailabilityResponse,\n XAccountResponse,\n XAuthUrlResponse,\n ConnectXResponse,\n} from './ProfileService.js';\n\nexport const MOCK_PROFILE_API_RESPONSE: ProfileApiResponse = {\n profile_id: 'mock-profile-id',\n username: 'mockuser',\n display_name: 'Mock User',\n bio: null,\n linked_addresses: [\n 'eip155:1:0xab16a96D359eC26a11e2C2b3d8f8B8942d5Bfcdb',\n 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp:EEivRh9T4GTLEJprEaKQyjSQzW13JRb5D7jSpvPQ8296',\n 'bip122:000000000019d6689c085ae165831e93:128Lkh3S7CkDTBZ8W7BbpsN3YYizJMp8p6',\n 'tron:728126428:TLyqzVGLV1srkB7dToTAEqgDSfPtXRJZYH',\n 'stellar:pubnet:GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H',\n ],\n avatar_url: 'https://pbs.twimg.com/profile_images/mock.jpg',\n trading_privacy: 'public',\n connected_to_x: true,\n created_at: '2024-01-01T00:00:00.000Z',\n updated_at: '2024-01-01T00:00:00.000Z',\n};\n\nexport const MOCK_X_CONNECT_RESPONSE: ConnectXResponse = {\n x_user_id: 'mock-x-user-id',\n x_profile_url: 'https://x.com/mockuser',\n username: 'mockuser',\n display_name: 'Mock User',\n avatar_url: 'https://pbs.twimg.com/profile_images/mock.jpg',\n created_at: '2024-01-01T00:00:00.000Z',\n updated_at: '2024-01-01T00:00:00.000Z',\n};\n\nexport const MOCK_X_AUTH_URL_RESPONSE: XAuthUrlResponse = {\n url: 'https://x.com/i/oauth2/authorize?mock=true',\n state: 'mock-oauth-state',\n};\n\nexport type MockProfileServiceHandlers = {\n getProfile?: (profileId: string) => Promise<ProfileApiResponse>;\n createProfile?: (\n params: CreateProfileParams,\n ) => Promise<CreateProfileResponse>;\n replaceProfile?: (\n profileId: string,\n params: ReplaceProfileParams,\n ) => Promise<ProfileApiResponse>;\n updateProfile?: (\n profileId: string,\n params: UpdateProfileParams,\n ) => Promise<ProfileApiResponse>;\n deleteProfile?: (profileId: string) => Promise<void>;\n checkUsernameAvailability?: (\n username: string,\n ) => Promise<UsernameAvailabilityResponse>;\n getXAuthUrl?: () => Promise<XAuthUrlResponse>;\n connectX?: (params: ConnectXParams) => Promise<ConnectXResponse>;\n getXAccount?: () => Promise<XAccountResponse>;\n disconnectX?: (profileId: string) => Promise<void>;\n};\n\n/**\n * Registers stub action handlers for all ProfileService methods on the provided messenger.\n * Use this in place of instantiating a real ProfileService when the profile API is unavailable.\n *\n * @param messenger - The ProfileServiceMessenger to register handlers on.\n * @param handlers - Optional per-method overrides. Unspecified methods return fixture data.\n */\nexport function buildMockProfileService(\n messenger: ProfileServiceMessenger,\n handlers: MockProfileServiceHandlers = {},\n): void {\n messenger.registerActionHandler(\n 'ProfileService:getProfile',\n handlers.getProfile ??\n (async (_profileId): Promise<ProfileApiResponse> =>\n MOCK_PROFILE_API_RESPONSE),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:createProfile',\n handlers.createProfile ??\n (async (_params): Promise<CreateProfileResponse> =>\n MOCK_PROFILE_API_RESPONSE),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:replaceProfile',\n handlers.replaceProfile ??\n (async (_profileId, _params): Promise<ProfileApiResponse> =>\n MOCK_PROFILE_API_RESPONSE),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:updateProfile',\n handlers.updateProfile ??\n (async (_profileId, _params): Promise<ProfileApiResponse> =>\n MOCK_PROFILE_API_RESPONSE),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:deleteProfile',\n handlers.deleteProfile ?? (async (_profileId): Promise<void> => undefined),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:checkUsernameAvailability',\n handlers.checkUsernameAvailability ??\n (async (username): Promise<UsernameAvailabilityResponse> => ({\n username,\n available: true,\n valid: true,\n normalized: username,\n errors: [],\n })),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:getXAuthUrl',\n handlers.getXAuthUrl ??\n (async (): Promise<XAuthUrlResponse> => MOCK_X_AUTH_URL_RESPONSE),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:connectX',\n handlers.connectX ??\n (async (_params): Promise<ConnectXResponse> => MOCK_X_CONNECT_RESPONSE),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:getXAccount',\n handlers.getXAccount ??\n (async (): Promise<XAccountResponse> => MOCK_X_CONNECT_RESPONSE),\n );\n\n messenger.registerActionHandler(\n 'ProfileService:disconnectX',\n handlers.disconnectX ?? (async (_profileId): Promise<void> => undefined),\n );\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export type { Profile, XProfile, ProfileControllerState, ProfileControllerGetStateAction, ProfileControllerActions, ProfileControllerChangeEvent, ProfileControllerEvents, ProfileControllerMessenger, } from './ProfileController.js';
|
|
1
|
+
export type { Profile, XProfile, ConnectXSession, ProfileControllerState, ProfileControllerGetStateAction, ProfileControllerActions, ProfileControllerChangeEvent, ProfileControllerEvents, ProfileControllerMessenger, } from './ProfileController.js';
|
|
2
2
|
export { ProfileController, getDefaultProfileControllerState, } from './ProfileController.js';
|
|
3
|
-
export type { ProfileControllerCheckUsernameAvailabilityAction, ProfileControllerConnectXAction, ProfileControllerCreateProfileAction, ProfileControllerDeleteProfileAction, ProfileControllerGetProfileAction, ProfileControllerFetchAndUpdateXAccountAction, ProfileControllerGetXProfileAction, ProfileControllerReplaceProfileAction, ProfileControllerUpdateProfileAction, } from './ProfileController-method-action-types.js';
|
|
4
|
-
export type { ProfileApiResponse, CreateProfileResponse, CreateProfileParams, ReplaceProfileParams, UpdateProfileParams, ConnectXParams, UsernameAvailabilityResponse, XAuthUrlResponse,
|
|
3
|
+
export type { ProfileControllerCheckUsernameAvailabilityAction, ProfileControllerConnectXAction, ProfileControllerCreateProfileAction, ProfileControllerDeleteProfileAction, ProfileControllerDisconnectXAction, ProfileControllerGetProfileAction, ProfileControllerFetchAndUpdateXAccountAction, ProfileControllerGetXProfileAction, ProfileControllerReplaceProfileAction, ProfileControllerGetXAuthorizationUrlAction, ProfileControllerUpdateProfileAction, } from './ProfileController-method-action-types.js';
|
|
4
|
+
export type { ProfileApiResponse, CreateProfileResponse, CreateProfileParams, ReplaceProfileParams, UpdateProfileParams, ConnectXParams, UsernameAvailabilityResponse, XAuthUrlResponse, ConnectXResponse, XAccountResponse, ProfileServiceActions, ProfileServiceEvents, ProfileServiceMessenger, } from './ProfileService.js';
|
|
5
5
|
export { ProfileService, ProfileServiceErrorMessage, } from './ProfileService.js';
|
|
6
|
-
export type {
|
|
6
|
+
export type { MockProfileServiceHandlers } from './ProfileServiceMock.js';
|
|
7
|
+
export { buildMockProfileService, MOCK_PROFILE_API_RESPONSE, MOCK_X_CONNECT_RESPONSE, MOCK_X_AUTH_URL_RESPONSE, } from './ProfileServiceMock.js';
|
|
8
|
+
export type { ProfileServiceCheckUsernameAvailabilityAction, ProfileServiceConnectXAction, ProfileServiceCreateProfileAction, ProfileServiceDeleteProfileAction, ProfileServiceDisconnectXAction, ProfileServiceGetProfileAction, ProfileServiceGetXAccountAction, ProfileServiceGetXAuthUrlAction, ProfileServiceReplaceProfileAction, ProfileServiceUpdateProfileAction, } from './ProfileService-method-action-types.js';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,QAAQ,EACR,sBAAsB,EACtB,+BAA+B,EAC/B,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,gDAAgD,EAChD,+BAA+B,EAC/B,oCAAoC,EACpC,oCAAoC,EACpC,iCAAiC,EACjC,6CAA6C,EAC7C,kCAAkC,EAClC,qCAAqC,EACrC,oCAAoC,GACrC,MAAM,4CAA4C,CAAC;AACpD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,6CAA6C,EAC7C,4BAA4B,EAC5B,iCAAiC,EACjC,iCAAiC,EACjC,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,EAC/B,kCAAkC,EAClC,iCAAiC,GAClC,MAAM,yCAAyC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,QAAQ,EACR,eAAe,EACf,sBAAsB,EACtB,+BAA+B,EAC/B,wBAAwB,EACxB,4BAA4B,EAC5B,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,gDAAgD,EAChD,+BAA+B,EAC/B,oCAAoC,EACpC,oCAAoC,EACpC,kCAAkC,EAClC,iCAAiC,EACjC,6CAA6C,EAC7C,kCAAkC,EAClC,qCAAqC,EACrC,2CAA2C,EAC3C,oCAAoC,GACrC,MAAM,4CAA4C,CAAC;AACpD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,cAAc,EACd,4BAA4B,EAC5B,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,0BAA0B,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EACV,6CAA6C,EAC7C,4BAA4B,EAC5B,iCAAiC,EACjC,iCAAiC,EACjC,+BAA+B,EAC/B,8BAA8B,EAC9B,+BAA+B,EAC/B,+BAA+B,EAC/B,kCAAkC,EAClC,iCAAiC,GAClC,MAAM,yCAAyC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { ProfileController, getDefaultProfileControllerState, } from './ProfileController.js';
|
|
2
2
|
export { ProfileService, ProfileServiceErrorMessage, } from './ProfileService.js';
|
|
3
|
+
export { buildMockProfileService, MOCK_PROFILE_API_RESPONSE, MOCK_X_CONNECT_RESPONSE, MOCK_X_AUTH_URL_RESPONSE, } from './ProfileServiceMock.js';
|
|
3
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,iBAAiB,EACjB,gCAAgC,GACjC,MAAM,wBAAwB,CAAC;AA6BhC,OAAO,EACL,cAAc,EACd,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,yBAAyB,CAAC","sourcesContent":["export type {\n Profile,\n XProfile,\n ConnectXSession,\n ProfileControllerState,\n ProfileControllerGetStateAction,\n ProfileControllerActions,\n ProfileControllerChangeEvent,\n ProfileControllerEvents,\n ProfileControllerMessenger,\n} from './ProfileController.js';\nexport {\n ProfileController,\n getDefaultProfileControllerState,\n} from './ProfileController.js';\nexport type {\n ProfileControllerCheckUsernameAvailabilityAction,\n ProfileControllerConnectXAction,\n ProfileControllerCreateProfileAction,\n ProfileControllerDeleteProfileAction,\n ProfileControllerDisconnectXAction,\n ProfileControllerGetProfileAction,\n ProfileControllerFetchAndUpdateXAccountAction,\n ProfileControllerGetXProfileAction,\n ProfileControllerReplaceProfileAction,\n ProfileControllerGetXAuthorizationUrlAction,\n ProfileControllerUpdateProfileAction,\n} from './ProfileController-method-action-types.js';\nexport type {\n ProfileApiResponse,\n CreateProfileResponse,\n CreateProfileParams,\n ReplaceProfileParams,\n UpdateProfileParams,\n ConnectXParams,\n UsernameAvailabilityResponse,\n XAuthUrlResponse,\n ConnectXResponse,\n XAccountResponse,\n ProfileServiceActions,\n ProfileServiceEvents,\n ProfileServiceMessenger,\n} from './ProfileService.js';\nexport {\n ProfileService,\n ProfileServiceErrorMessage,\n} from './ProfileService.js';\nexport type { MockProfileServiceHandlers } from './ProfileServiceMock.js';\nexport {\n buildMockProfileService,\n MOCK_PROFILE_API_RESPONSE,\n MOCK_X_CONNECT_RESPONSE,\n MOCK_X_AUTH_URL_RESPONSE,\n} from './ProfileServiceMock.js';\nexport type {\n ProfileServiceCheckUsernameAvailabilityAction,\n ProfileServiceConnectXAction,\n ProfileServiceCreateProfileAction,\n ProfileServiceDeleteProfileAction,\n ProfileServiceDisconnectXAction,\n ProfileServiceGetProfileAction,\n ProfileServiceGetXAccountAction,\n ProfileServiceGetXAuthUrlAction,\n ProfileServiceReplaceProfileAction,\n ProfileServiceUpdateProfileAction,\n} from './ProfileService-method-action-types.js';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/profile-controller",
|
|
3
|
-
"version": "1.0.1-preview-
|
|
3
|
+
"version": "1.0.1-preview-2750df1dc",
|
|
4
4
|
"description": "Controller for managing user profile data including username, bio, avatar, and linked accounts via the MetaMask Profile API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|