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

Filter by extension

Filter by extension

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

## [Unreleased]

### Changed

- **BREAKING:** Rename `AuthenticationController:getUserProfileMetaMetrics` to `AuthenticationController:getUserProfileLineage` ([#6211](https://github.com/MetaMask/core/pull/6211))
- Rename API endpoint from `/api/v2/profile/metametrics` to `/api/v2/profile/lineage`

## [22.0.0]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import type { LoginResponse } from '../../sdk';
import { Platform } from '../../sdk';
import { arrangeAuthAPIs } from '../../sdk/__fixtures__/auth';
import { MOCK_USER_PROFILE_METAMETRICS_RESPONSE } from '../../sdk/mocks/auth';
import { MOCK_USER_PROFILE_LINEAGE_RESPONSE } from '../../sdk/mocks/auth';

const MOCK_ENTROPY_SOURCE_IDS = [
'MOCK_ENTROPY_SOURCE_ID',
Expand Down Expand Up @@ -442,7 +442,7 @@ describe('authentication/authentication-controller - getUserProfileMetaMetrics()
metametrics,
});

await expect(controller.getUserProfileMetaMetrics()).rejects.toThrow(
await expect(controller.getUserProfileLineage()).rejects.toThrow(
expect.any(Error),
);
});
Expand All @@ -459,9 +459,9 @@ describe('authentication/authentication-controller - getUserProfileMetaMetrics()
metametrics,
});

const result = await controller.getUserProfileMetaMetrics();
const result = await controller.getUserProfileLineage();
expect(result).toBeDefined();
expect(result).toStrictEqual(MOCK_USER_PROFILE_METAMETRICS_RESPONSE);
expect(result).toStrictEqual(MOCK_USER_PROFILE_LINEAGE_RESPONSE);
});

it('should throw error if wallet is locked', async () => {
Expand All @@ -481,7 +481,7 @@ describe('authentication/authentication-controller - getUserProfileMetaMetrics()
metametrics,
});

await expect(controller.getUserProfileMetaMetrics()).rejects.toThrow(
await expect(controller.getUserProfileLineage()).rejects.toThrow(
expect.any(Error),
);
});
Expand Down Expand Up @@ -604,29 +604,29 @@ function createMockAuthenticationMessenger() {
* @returns mock auth endpoints
*/
function mockAuthenticationFlowEndpoints(params?: {
endpointFail: 'nonce' | 'login' | 'token' | 'metametrics';
endpointFail: 'nonce' | 'login' | 'token' | 'lineage';
}) {
const {
mockNonceUrl,
mockOAuth2TokenUrl,
mockSrpLoginUrl,
mockUserProfileMetaMetricsUrl,
mockUserProfileLineageUrl,
} = arrangeAuthAPIs({
mockNonceUrl:
params?.endpointFail === 'nonce' ? { status: 500 } : undefined,
mockSrpLoginUrl:
params?.endpointFail === 'login' ? { status: 500 } : undefined,
mockOAuth2TokenUrl:
params?.endpointFail === 'token' ? { status: 500 } : undefined,
mockUserProfileMetaMetrics:
params?.endpointFail === 'metametrics' ? { status: 500 } : undefined,
mockUserProfileLineageUrl:
params?.endpointFail === 'lineage' ? { status: 500 } : undefined,
});

return {
mockNonceUrl,
mockOAuth2TokenUrl,
mockSrpLoginUrl,
mockUserProfileMetaMetricsUrl,
mockUserProfileLineageUrl,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
LoginResponse,
SRPInterface,
UserProfile,
UserProfileMetaMetrics,
UserProfileLineage,
} from '../../sdk';
import {
assertMessageStartsWithMetamask,
Expand Down Expand Up @@ -68,7 +68,7 @@ type ActionsObj = CreateActionsObj<
| 'performSignOut'
| 'getBearerToken'
| 'getSessionProfile'
| 'getUserProfileMetaMetrics'
| 'getUserProfileLineage'
| 'isSignedIn'
>;
export type Actions =
Expand All @@ -85,8 +85,8 @@ export type AuthenticationControllerGetBearerToken =
ActionsObj['getBearerToken'];
export type AuthenticationControllerGetSessionProfile =
ActionsObj['getSessionProfile'];
export type AuthenticationControllerGetUserProfileMetaMetrics =
ActionsObj['getUserProfileMetaMetrics'];
export type AuthenticationControllerGetUserProfileLineage =
ActionsObj['getUserProfileLineage'];
export type AuthenticationControllerIsSignedIn = ActionsObj['isSignedIn'];

export type AuthenticationControllerStateChangeEvent =
Expand Down Expand Up @@ -238,8 +238,8 @@ export default class AuthenticationController extends BaseController<
);

this.messagingSystem.registerActionHandler(
'AuthenticationController:getUserProfileMetaMetrics',
this.getUserProfileMetaMetrics.bind(this),
'AuthenticationController:getUserProfileLineage',
this.getUserProfileLineage.bind(this),
);
}

Expand Down Expand Up @@ -342,9 +342,9 @@ export default class AuthenticationController extends BaseController<
return await this.#auth.getUserProfile(entropySourceId);
}

public async getUserProfileMetaMetrics(): Promise<UserProfileMetaMetrics> {
this.#assertIsUnlocked('getUserProfileMetaMetrics');
return await this.#auth.getUserProfileMetaMetrics();
public async getUserProfileLineage(): Promise<UserProfileLineage> {
this.#assertIsUnlocked('getUserProfileLineage');
return await this.#auth.getUserProfileLineage();
}

public isSignedIn(): boolean {
Expand Down
20 changes: 10 additions & 10 deletions packages/profile-sync-controller/src/sdk/__fixtures__/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
MOCK_OIDC_TOKEN_RESPONSE,
MOCK_OIDC_TOKEN_URL,
MOCK_PAIR_IDENTIFIERS_URL,
MOCK_PROFILE_METAMETRICS_URL,
MOCK_PROFILE_LINEAGE_URL,
MOCK_SIWE_LOGIN_RESPONSE,
MOCK_SIWE_LOGIN_URL,
MOCK_SRP_LOGIN_RESPONSE,
MOCK_SRP_LOGIN_URL,
MOCK_USER_PROFILE_METAMETRICS_RESPONSE,
MOCK_USER_PROFILE_LINEAGE_RESPONSE,
} from '../mocks/auth';

type MockReply = {
Expand Down Expand Up @@ -71,18 +71,18 @@ export const handleMockOAuth2Token = (mockReply?: MockReply) => {
return mockTokenEndpoint;
};

export const handleMockUserProfileMetaMetrics = (mockReply?: MockReply) => {
export const handleMockUserProfileLineage = (mockReply?: MockReply) => {
const reply = mockReply ?? {
status: 200,
body: MOCK_USER_PROFILE_METAMETRICS_RESPONSE,
body: MOCK_USER_PROFILE_LINEAGE_RESPONSE,
};
const mockUserProfileMetaMetricsEndpoint = nock(MOCK_PROFILE_METAMETRICS_URL)
const mockUserProfileLineageEndpoint = nock(MOCK_PROFILE_LINEAGE_URL)
.persist()
.get('')
.query(true)
.reply(reply.status, reply.body);

return mockUserProfileMetaMetricsEndpoint;
return mockUserProfileLineageEndpoint;
};

export const arrangeAuthAPIs = (options?: {
Expand All @@ -91,7 +91,7 @@ export const arrangeAuthAPIs = (options?: {
mockSrpLoginUrl?: MockReply;
mockSiweLoginUrl?: MockReply;
mockPairIdentifiers?: MockReply;
mockUserProfileMetaMetrics?: MockReply;
mockUserProfileLineageUrl?: MockReply;
}) => {
const mockNonceUrl = handleMockNonce(options?.mockNonceUrl);
const mockOAuth2TokenUrl = handleMockOAuth2Token(options?.mockOAuth2TokenUrl);
Expand All @@ -100,8 +100,8 @@ export const arrangeAuthAPIs = (options?: {
const mockPairIdentifiersUrl = handleMockPairIdentifiers(
options?.mockPairIdentifiers,
);
const mockUserProfileMetaMetricsUrl = handleMockUserProfileMetaMetrics(
options?.mockUserProfileMetaMetrics,
const mockUserProfileLineageUrl = handleMockUserProfileLineage(
options?.mockUserProfileLineageUrl,
);

return {
Expand All @@ -110,6 +110,6 @@ export const arrangeAuthAPIs = (options?: {
mockSrpLoginUrl,
mockSiweLoginUrl,
mockPairIdentifiersUrl,
mockUserProfileMetaMetricsUrl,
mockUserProfileLineageUrl,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
authenticate,
authorizeOIDC,
getNonce,
getUserProfileMetaMetrics,
getUserProfileLineage,
} from './services';
import type {
AuthConfig,
Expand All @@ -14,7 +14,7 @@ import type {
IBaseAuth,
LoginResponse,
UserProfile,
UserProfileMetaMetrics,
UserProfileLineage,
} from './types';
import { ValidationError } from '../errors';
import { validateLoginResponse } from '../utils/validate-login-response';
Expand Down Expand Up @@ -70,9 +70,9 @@ export class SIWEJwtBearerAuth implements IBaseAuth {
return this.#signer.address;
}

async getUserProfileMetaMetrics(): Promise<UserProfileMetaMetrics> {
async getUserProfileLineage(): Promise<UserProfileLineage> {
const accessToken = await this.getAccessToken();
return await getUserProfileMetaMetrics(this.#config.env, accessToken);
return await getUserProfileLineage(this.#config.env, accessToken);
}

async signMessage(message: string): Promise<string> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
authenticate,
authorizeOIDC,
getNonce,
getUserProfileMetaMetrics,
getUserProfileLineage,
} from './services';
import type {
AuthConfig,
Expand All @@ -14,7 +14,7 @@ import type {
IBaseAuth,
LoginResponse,
UserProfile,
UserProfileMetaMetrics,
UserProfileLineage,
} from './types';
import type { MetaMetricsAuth } from '../../shared/types/services';
import { ValidationError } from '../errors';
Expand Down Expand Up @@ -118,9 +118,9 @@ export class SRPJwtBearerAuth implements IBaseAuth {
return await this.#options.signing.getIdentifier(entropySourceId);
}

async getUserProfileMetaMetrics(): Promise<UserProfileMetaMetrics> {
async getUserProfileLineage(): Promise<UserProfileLineage> {
const accessToken = await this.getAccessToken();
return await getUserProfileMetaMetrics(this.#config.env, accessToken);
return await getUserProfileLineage(this.#config.env, accessToken);
}

async signMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
AccessToken,
ErrorMessage,
UserProfile,
UserProfileMetaMetrics,
UserProfileLineage,
} from './types';
import { AuthType } from './types';
import type { Env, Platform } from '../../shared/env';
Expand Down Expand Up @@ -30,8 +30,8 @@ export const SRP_LOGIN_URL = (env: Env) =>
export const SIWE_LOGIN_URL = (env: Env) =>
`${getEnvUrls(env).authApiUrl}/api/v2/siwe/login`;

export const PROFILE_METAMETRICS_URL = (env: Env) =>
`${getEnvUrls(env).authApiUrl}/api/v2/profile/metametrics`;
export const PROFILE_LINEAGE_URL = (env: Env) =>
`${getEnvUrls(env).authApiUrl}/api/v2/profile/lineage`;

const getAuthenticationUrl = (authType: AuthType, env: Env): string => {
switch (authType) {
Expand Down Expand Up @@ -262,20 +262,20 @@ export async function authenticate(
}

/**
* Service to get the Profile MetaMetrics
* Service to get the Profile Lineage
*
* @param env - server environment
* @param accessToken - JWT access token used to access protected resources
* @returns Profile MetaMetrics information.
* @returns Profile Lineage information.
*/
export async function getUserProfileMetaMetrics(
export async function getUserProfileLineage(
env: Env,
accessToken: string,
): Promise<UserProfileMetaMetrics> {
const profileMetaMetricsUrl = new URL(PROFILE_METAMETRICS_URL(env));
): Promise<UserProfileLineage> {
const profileLineageUrl = new URL(PROFILE_LINEAGE_URL(env));

try {
const response = await fetch(profileMetaMetricsUrl, {
const response = await fetch(profileLineageUrl, {
method: 'GET',
headers: {
Authorization: `Bearer ${accessToken}`,
Expand All @@ -289,13 +289,13 @@ export async function getUserProfileMetaMetrics(
);
}

const profileJson: UserProfileMetaMetrics = await response.json();
const profileJson: UserProfileLineage = await response.json();

return profileJson;
} catch (e) {
/* istanbul ignore next */
const errorMessage =
e instanceof Error ? e.message : JSON.stringify(e ?? '');
throw new SignInError(`failed to get profile metametrics: ${errorMessage}`);
throw new SignInError(`failed to get profile lineage: ${errorMessage}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export type Pair = {
signMessage: (message: string) => Promise<string>;
};

export type UserProfileMetaMetrics = {
export type UserProfileLineage = {
profile_id: string;
created_at: string;
lineage: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('Authentication - SRP Flow - getAccessToken(), getUserProfile() & getUs
mockNonceUrl,
mockSrpLoginUrl,
mockOAuth2TokenUrl,
mockUserProfileMetaMetricsUrl,
mockUserProfileLineageUrl,
} = arrangeAuthAPIs();

// Token
Expand All @@ -185,15 +185,15 @@ describe('Authentication - SRP Flow - getAccessToken(), getUserProfile() & getUs
const profileResponse = await auth.getUserProfile();
expect(profileResponse).toBeDefined();

// User Profile MetaMetrics
const userProfileMetaMetrics = await auth.getUserProfileMetaMetrics();
expect(userProfileMetaMetrics).toBeDefined();
// User Profile Lineage
const userProfileLineage = await auth.getUserProfileLineage();
expect(userProfileLineage).toBeDefined();

// API
expect(mockNonceUrl.isDone()).toBe(true);
expect(mockSrpLoginUrl.isDone()).toBe(true);
expect(mockOAuth2TokenUrl.isDone()).toBe(true);
expect(mockUserProfileMetaMetricsUrl.isDone()).toBe(true);
expect(mockUserProfileLineageUrl.isDone()).toBe(true);
});

it('the SRP signIn failed: nonce error', async () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/profile-sync-controller/src/sdk/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import type {
UserProfile,
Pair,
UserProfileMetaMetrics,
UserProfileLineage,
} from './authentication-jwt-bearer/types';
import { AuthType } from './authentication-jwt-bearer/types';
import { PairError, UnsupportedAuthTypeError } from './errors';
Expand Down Expand Up @@ -76,8 +76,8 @@ export class JwtBearerAuth implements SIWEInterface, SRPInterface {
return await this.#sdk.getIdentifier(entropySourceId);
}

async getUserProfileMetaMetrics(): Promise<UserProfileMetaMetrics> {
return await this.#sdk.getUserProfileMetaMetrics();
async getUserProfileLineage(): Promise<UserProfileLineage> {
return await this.#sdk.getUserProfileLineage();
}

async signMessage(
Expand Down
Loading
Loading