From 3a9b2e86696417fd1aaae268c75dbd574552cb7c Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Mon, 12 Aug 2024 22:27:41 +0100 Subject: [PATCH 1/8] refactor: profile sync controller - add multiple file exports --- .../NotificationServicesController.ts | 24 +++++++++++------- .../services/onchain-notifications.ts | 6 ++--- packages/profile-sync-controller/package.json | 25 +++++++++++++++++++ .../src/controllers/authentication/index.ts | 3 ++- .../controllers/authentication/services.ts | 2 +- .../src/controllers/user-storage/index.ts | 3 ++- .../src/controllers/user-storage/services.ts | 2 +- 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts index 480ecbb23b..f300100c9a 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.ts @@ -14,9 +14,15 @@ import type { KeyringControllerUnlockEvent, } from '@metamask/keyring-controller'; import type { - AuthenticationController, - UserStorageController, -} from '@metamask/profile-sync-controller'; + AuthenticationControllerGetBearerToken, + AuthenticationControllerIsSignedIn, +} from '@metamask/profile-sync-controller/auth'; +import type { + UserStorageControllerEnableProfileSyncing, + UserStorageControllerGetStorageKey, + UserStorageControllerPerformGetStorage, + UserStorageControllerPerformSetStorage, +} from '@metamask/profile-sync-controller/user-storage'; import log from 'loglevel'; import { USER_STORAGE_VERSION_KEY } from './constants/constants'; @@ -197,13 +203,13 @@ export type AllowedActions = | KeyringControllerGetAccountsAction | KeyringControllerGetStateAction // Auth Controller Requests - | AuthenticationController.AuthenticationControllerGetBearerToken - | AuthenticationController.AuthenticationControllerIsSignedIn + | AuthenticationControllerGetBearerToken + | AuthenticationControllerIsSignedIn // User Storage Controller Requests - | UserStorageController.UserStorageControllerEnableProfileSyncing - | UserStorageController.UserStorageControllerGetStorageKey - | UserStorageController.UserStorageControllerPerformGetStorage - | UserStorageController.UserStorageControllerPerformSetStorage + | UserStorageControllerEnableProfileSyncing + | UserStorageControllerGetStorageKey + | UserStorageControllerPerformGetStorage + | UserStorageControllerPerformSetStorage // Push Notifications Controller Requests | NotificationServicesPushControllerEnablePushNotifications | NotificationServicesPushControllerDisablePushNotifications diff --git a/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts b/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts index 35edcb79f1..b17af43d6a 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts @@ -1,4 +1,4 @@ -import { UserStorageController } from '@metamask/profile-sync-controller'; +import { createSHA256Hash } from '@metamask/profile-sync-controller/user-storage'; import log from 'loglevel'; import { toRawOnChainNotification } from '../../shared/to-raw-notification'; @@ -59,7 +59,7 @@ export async function createOnChainTriggers( }; const triggersToCreate: RequestPayloadTrigger[] = triggers.map((t) => ({ id: t.id, - token: UserStorageController.createSHA256Hash(t.id + storageKey), + token: createSHA256Hash(t.id + storageKey), config: { kind: t.kind, // eslint-disable-next-line @typescript-eslint/naming-convention @@ -118,7 +118,7 @@ export async function deleteOnChainTriggers( ): Promise { const triggersToDelete = uuids.map((uuid) => ({ id: uuid, - token: UserStorageController.createSHA256Hash(uuid + storageKey), + token: createSHA256Hash(uuid + storageKey), })); try { diff --git a/packages/profile-sync-controller/package.json b/packages/profile-sync-controller/package.json index d84fe9ed0c..e6bb8d7838 100644 --- a/packages/profile-sync-controller/package.json +++ b/packages/profile-sync-controller/package.json @@ -22,6 +22,31 @@ "require": "./dist/index.js", "types": "./dist/types/index.d.ts" }, + "./sdk": { + "import": "./dist/sdk/index.mjs", + "require": "./dist/sdk/index.js", + "types": "./dist/types/sdk/index.d.ts" + }, + "./auth": { + "import": "./dist/controllers/authentication/index.mjs", + "require": "./dist/controllers/authentication/index.js", + "types": "./dist/types/controllers/authentication/index.d.ts" + }, + "./user-storage": { + "import": "./dist/controllers/user-storage/index.mjs", + "require": "./dist/controllers/user-storage/index.js", + "types": "./dist/types/controllers/user-storage/index.d.ts" + }, + "./dist/mocks/auth": { + "import": "./dist/controllers/authentication/__fixtures__/index.mjs", + "require": "./dist/controllers/authentication/__fixtures__/index.js", + "types": "./dist/types/controllers/authentication/__fixtures__/index.d.ts" + }, + "./dist/mocks/user-storage": { + "import": "./dist/controllers/user-storage/__fixtures__/index.mjs", + "require": "./dist/controllers/user-storage/__fixtures__/index.js", + "types": "./dist/types/controllers/user-storage/__fixtures__/index.d.ts" + }, "./package.json": "./package.json" }, "main": "./dist/index.js", diff --git a/packages/profile-sync-controller/src/controllers/authentication/index.ts b/packages/profile-sync-controller/src/controllers/authentication/index.ts index ece95fff72..c1843a808e 100644 --- a/packages/profile-sync-controller/src/controllers/authentication/index.ts +++ b/packages/profile-sync-controller/src/controllers/authentication/index.ts @@ -1,5 +1,6 @@ import Controller from './AuthenticationController'; +const AuthenticationController = Controller; export { Controller }; +export default AuthenticationController; export * from './AuthenticationController'; -export * as Mocks from './__fixtures__'; diff --git a/packages/profile-sync-controller/src/controllers/authentication/services.ts b/packages/profile-sync-controller/src/controllers/authentication/services.ts index 3c06aef88a..78222a8ccb 100644 --- a/packages/profile-sync-controller/src/controllers/authentication/services.ts +++ b/packages/profile-sync-controller/src/controllers/authentication/services.ts @@ -1,4 +1,4 @@ -import { Env, Platform, getEnvUrls, getOidcClientId } from '../../sdk'; +import { Env, Platform, getEnvUrls, getOidcClientId } from '../../sdk/env'; const ENV_URLS = getEnvUrls(Env.PRD); diff --git a/packages/profile-sync-controller/src/controllers/user-storage/index.ts b/packages/profile-sync-controller/src/controllers/user-storage/index.ts index 01c28fabab..f5bf5a0423 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/index.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/index.ts @@ -1,6 +1,7 @@ import Controller from './UserStorageController'; +const UserStorageController = Controller; export { Controller }; +export default UserStorageController; export * from './UserStorageController'; export * from './encryption'; -export * as Mocks from './__fixtures__'; diff --git a/packages/profile-sync-controller/src/controllers/user-storage/services.ts b/packages/profile-sync-controller/src/controllers/user-storage/services.ts index 07289a75cc..54623da0bf 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/services.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/services.ts @@ -1,6 +1,6 @@ import log from 'loglevel'; -import { Env, getEnvUrls } from '../../sdk'; +import { Env, getEnvUrls } from '../../sdk/env'; import encryption from './encryption'; import type { UserStoragePath } from './schema'; import { createEntryPath } from './schema'; From 8a035a4655f4c217b138bff0b68283964f6eccde Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Tue, 13 Aug 2024 14:44:32 +0100 Subject: [PATCH 2/8] refactor: add multiple file exports for notification-services-controller --- .../package.json | 50 +++++++++++++++++++ .../NotificationServicesController/index.ts | 3 +- .../index.ts | 3 +- packages/profile-sync-controller/package.json | 12 ++--- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/packages/notification-services-controller/package.json b/packages/notification-services-controller/package.json index a4d85db5a1..e6dee80df4 100644 --- a/packages/notification-services-controller/package.json +++ b/packages/notification-services-controller/package.json @@ -22,6 +22,56 @@ "require": "./dist/index.js", "types": "./dist/types/index.d.ts" }, + "./notification-services": { + "import": "./dist/NotificationServicesController/index.mjs", + "require": "./dist/NotificationServicesController/index.js", + "types": "./dist/types/NotificationServicesController/index.d.ts" + }, + "./notification-services/types": { + "import": "./dist/NotificationServicesController/types/index.mjs", + "require": "./dist/NotificationServicesController/types/index.js", + "types": "./dist/types/NotificationServicesController/types/index.d.ts" + }, + "./notification-services/processors": { + "import": "./dist/NotificationServicesController/processors/index.mjs", + "require": "./dist/NotificationServicesController/processors/index.js", + "types": "./dist/types/NotificationServicesController/processors/index.d.ts" + }, + "./notification-services/constants": { + "import": "./dist/NotificationServicesController/constants/index.mjs", + "require": "./dist/NotificationServicesController/constants/index.js", + "types": "./dist/types/NotificationServicesController/constants/index.d.ts" + }, + "./notification-services/ui": { + "import": "./dist/NotificationServicesController/ui/index.mjs", + "require": "./dist/NotificationServicesController/ui/index.js", + "types": "./dist/types/NotificationServicesController/ui/index.d.ts" + }, + "./notification-services/__mocks__": { + "import": "./dist/NotificationServicesController/__fixtures__/index.mjs", + "require": "./dist/NotificationServicesController/__fixtures__/index.js", + "types": "./dist/types/NotificationServicesController/__fixtures__/index.d.ts" + }, + "./push-services": { + "import": "./dist/NotificationServicesPushController/index.mjs", + "require": "./dist/NotificationServicesPushController/index.js", + "types": "./dist/types/NotificationServicesPushController/index.d.ts" + }, + "./push-services/types": { + "import": "./dist/NotificationServicesPushController/types/index.mjs", + "require": "./dist/NotificationServicesPushController/types/index.js", + "types": "./dist/types/NotificationServicesPushController/types/index.d.ts" + }, + "./push-services/utils": { + "import": "./dist/NotificationServicesPushController/utils/index.mjs", + "require": "./dist/NotificationServicesPushController/utils/index.js", + "types": "./dist/types/NotificationServicesPushController/utils/index.d.ts" + }, + "./push-services/__mocks__": { + "import": "./dist/NotificationServicesPushController/__fixtures__/index.mjs", + "require": "./dist/NotificationServicesPushController/__fixtures__/index.js", + "types": "./dist/types/NotificationServicesPushController/__fixtures__/index.d.ts" + }, "./package.json": "./package.json" }, "main": "./dist/index.js", diff --git a/packages/notification-services-controller/src/NotificationServicesController/index.ts b/packages/notification-services-controller/src/NotificationServicesController/index.ts index f94a1255fc..4a5de527bb 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/index.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/index.ts @@ -1,9 +1,10 @@ import Controller from './NotificationServicesController'; +const NotificationServicesController = Controller; export { Controller }; +export default NotificationServicesController; export * from './NotificationServicesController'; export * as Types from './types'; -export * as Mocks from './__fixtures__'; export * as Processors from './processors'; export * as Constants from './constants'; export * as UI from './ui'; diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/index.ts b/packages/notification-services-controller/src/NotificationServicesPushController/index.ts index 012dd29025..d1024c78d2 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/index.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/index.ts @@ -1,7 +1,8 @@ import Controller from './NotificationServicesPushController'; +const NotificationServicesPushController = Controller; export { Controller }; +export default NotificationServicesPushController; export * from './NotificationServicesPushController'; export * as Types from './types'; export * as Utils from './utils'; -export * as Mocks from './__fixtures__'; diff --git a/packages/profile-sync-controller/package.json b/packages/profile-sync-controller/package.json index e6bb8d7838..539a5830c1 100644 --- a/packages/profile-sync-controller/package.json +++ b/packages/profile-sync-controller/package.json @@ -32,17 +32,17 @@ "require": "./dist/controllers/authentication/index.js", "types": "./dist/types/controllers/authentication/index.d.ts" }, + "./auth/__mocks__": { + "import": "./dist/controllers/authentication/__fixtures__/index.mjs", + "require": "./dist/controllers/authentication/__fixtures__/index.js", + "types": "./dist/types/controllers/authentication/__fixtures__/index.d.ts" + }, "./user-storage": { "import": "./dist/controllers/user-storage/index.mjs", "require": "./dist/controllers/user-storage/index.js", "types": "./dist/types/controllers/user-storage/index.d.ts" }, - "./dist/mocks/auth": { - "import": "./dist/controllers/authentication/__fixtures__/index.mjs", - "require": "./dist/controllers/authentication/__fixtures__/index.js", - "types": "./dist/types/controllers/authentication/__fixtures__/index.d.ts" - }, - "./dist/mocks/user-storage": { + "./user-storage/__mocks__": { "import": "./dist/controllers/user-storage/__fixtures__/index.mjs", "require": "./dist/controllers/user-storage/__fixtures__/index.js", "types": "./dist/types/controllers/user-storage/__fixtures__/index.d.ts" From 21c96f15616b28e844440c9a7c7369545f7a7b98 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Tue, 13 Aug 2024 15:15:42 +0100 Subject: [PATCH 3/8] chore: fix mock exports and tests that use mocks --- .../package.json | 4 +-- .../NotificationServicesController.test.ts | 29 ++++++++++++------- .../utils/get-notification-message.test.ts | 11 ++++--- packages/profile-sync-controller/package.json | 4 +-- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/notification-services-controller/package.json b/packages/notification-services-controller/package.json index e6dee80df4..7be47aeaf5 100644 --- a/packages/notification-services-controller/package.json +++ b/packages/notification-services-controller/package.json @@ -47,7 +47,7 @@ "require": "./dist/NotificationServicesController/ui/index.js", "types": "./dist/types/NotificationServicesController/ui/index.d.ts" }, - "./notification-services/__mocks__": { + "./notification-services/mocks": { "import": "./dist/NotificationServicesController/__fixtures__/index.mjs", "require": "./dist/NotificationServicesController/__fixtures__/index.js", "types": "./dist/types/NotificationServicesController/__fixtures__/index.d.ts" @@ -67,7 +67,7 @@ "require": "./dist/NotificationServicesPushController/utils/index.js", "types": "./dist/types/NotificationServicesPushController/utils/index.d.ts" }, - "./push-services/__mocks__": { + "./push-services/mocks": { "import": "./dist/NotificationServicesPushController/__fixtures__/index.mjs", "require": "./dist/NotificationServicesPushController/__fixtures__/index.js", "types": "./dist/types/NotificationServicesPushController/__fixtures__/index.d.ts" diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts index 87154aa8c0..54005b42f2 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts @@ -4,8 +4,17 @@ import type { KeyringControllerGetAccountsAction, KeyringControllerState, } from '@metamask/keyring-controller'; -import type { UserStorageController } from '@metamask/profile-sync-controller'; -import { AuthenticationController } from '@metamask/profile-sync-controller'; +import type { + AuthenticationControllerGetBearerToken, + AuthenticationControllerIsSignedIn, +} from '@metamask/profile-sync-controller/auth'; +import { MOCK_ACCESS_TOKEN } from '@metamask/profile-sync-controller/auth/mocks'; +import type { + UserStorageControllerEnableProfileSyncing, + UserStorageControllerGetStorageKey, + UserStorageControllerPerformGetStorage, + UserStorageControllerPerformSetStorage, +} from '@metamask/profile-sync-controller/user-storage'; import { createMockFeatureAnnouncementAPIResult, @@ -691,14 +700,12 @@ function mockNotificationMessenger() { typedMockAction().mockResolvedValue([]); const mockGetBearerToken = - typedMockAction().mockResolvedValue( - AuthenticationController.Mocks.MOCK_ACCESS_TOKEN, + typedMockAction().mockResolvedValue( + MOCK_ACCESS_TOKEN, ); const mockIsSignedIn = - typedMockAction().mockReturnValue( - true, - ); + typedMockAction().mockReturnValue(true); const mockDisablePushNotifications = typedMockAction(); @@ -710,20 +717,20 @@ function mockNotificationMessenger() { typedMockAction(); const mockGetStorageKey = - typedMockAction().mockResolvedValue( + typedMockAction().mockResolvedValue( 'MOCK_STORAGE_KEY', ); const mockEnableProfileSyncing = - typedMockAction(); + typedMockAction(); const mockPerformGetStorage = - typedMockAction().mockResolvedValue( + typedMockAction().mockResolvedValue( JSON.stringify(createMockFullUserStorage()), ); const mockPerformSetStorage = - typedMockAction(); + typedMockAction(); jest.spyOn(messenger, 'call').mockImplementation((...args) => { const [actionType] = args; diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts b/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts index cceb4c66fc..21b39e9780 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/utils/get-notification-message.test.ts @@ -1,8 +1,5 @@ -import { Mocks, Processors } from '../../NotificationServicesController'; -import type { TranslationKeys } from './get-notification-message'; -import { createOnChainPushNotificationMessage } from './get-notification-message'; - -const { +import { Processors } from '../../NotificationServicesController'; +import { createMockNotificationERC1155Received, createMockNotificationERC1155Sent, createMockNotificationERC20Received, @@ -18,7 +15,9 @@ const { createMockNotificationMetaMaskSwapsCompleted, createMockNotificationRocketPoolStakeCompleted, createMockNotificationRocketPoolUnStakeCompleted, -} = Mocks; +} from '../../NotificationServicesController/__fixtures__'; +import type { TranslationKeys } from './get-notification-message'; +import { createOnChainPushNotificationMessage } from './get-notification-message'; const mockTranslations: TranslationKeys = { pushPlatformNotificationsFundsSentTitle: () => 'Funds sent', diff --git a/packages/profile-sync-controller/package.json b/packages/profile-sync-controller/package.json index 539a5830c1..3da40d593d 100644 --- a/packages/profile-sync-controller/package.json +++ b/packages/profile-sync-controller/package.json @@ -32,7 +32,7 @@ "require": "./dist/controllers/authentication/index.js", "types": "./dist/types/controllers/authentication/index.d.ts" }, - "./auth/__mocks__": { + "./auth/mocks": { "import": "./dist/controllers/authentication/__fixtures__/index.mjs", "require": "./dist/controllers/authentication/__fixtures__/index.js", "types": "./dist/types/controllers/authentication/__fixtures__/index.d.ts" @@ -42,7 +42,7 @@ "require": "./dist/controllers/user-storage/index.js", "types": "./dist/types/controllers/user-storage/index.d.ts" }, - "./user-storage/__mocks__": { + "./user-storage/mocks": { "import": "./dist/controllers/user-storage/__fixtures__/index.mjs", "require": "./dist/controllers/user-storage/__fixtures__/index.js", "types": "./dist/types/controllers/user-storage/__fixtures__/index.d.ts" From 223cc34513bef30b84c29c3c007909682de28f5f Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Tue, 13 Aug 2024 15:29:13 +0100 Subject: [PATCH 4/8] refactor: revert some import changes as they are not compatible with node 18 we still can fallback to named exports --- .../NotificationServicesController.test.ts | 3 +-- .../services/onchain-notifications.ts | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts index 54005b42f2..ba7928ec21 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts @@ -8,7 +8,6 @@ import type { AuthenticationControllerGetBearerToken, AuthenticationControllerIsSignedIn, } from '@metamask/profile-sync-controller/auth'; -import { MOCK_ACCESS_TOKEN } from '@metamask/profile-sync-controller/auth/mocks'; import type { UserStorageControllerEnableProfileSyncing, UserStorageControllerGetStorageKey, @@ -701,7 +700,7 @@ function mockNotificationMessenger() { const mockGetBearerToken = typedMockAction().mockResolvedValue( - MOCK_ACCESS_TOKEN, + 'MOCK_ACCESS_TOKEN', ); const mockIsSignedIn = diff --git a/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts b/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts index b17af43d6a..35edcb79f1 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/services/onchain-notifications.ts @@ -1,4 +1,4 @@ -import { createSHA256Hash } from '@metamask/profile-sync-controller/user-storage'; +import { UserStorageController } from '@metamask/profile-sync-controller'; import log from 'loglevel'; import { toRawOnChainNotification } from '../../shared/to-raw-notification'; @@ -59,7 +59,7 @@ export async function createOnChainTriggers( }; const triggersToCreate: RequestPayloadTrigger[] = triggers.map((t) => ({ id: t.id, - token: createSHA256Hash(t.id + storageKey), + token: UserStorageController.createSHA256Hash(t.id + storageKey), config: { kind: t.kind, // eslint-disable-next-line @typescript-eslint/naming-convention @@ -118,7 +118,7 @@ export async function deleteOnChainTriggers( ): Promise { const triggersToDelete = uuids.map((uuid) => ({ id: uuid, - token: createSHA256Hash(uuid + storageKey), + token: UserStorageController.createSHA256Hash(uuid + storageKey), })); try { From c9ace70c2cfc858a97b13bc3627f40032fdf0df7 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Wed, 14 Aug 2024 10:35:59 +0100 Subject: [PATCH 5/8] refactor: add back mocks to root index export for backwards compatibility --- .../NotificationServicesController.test.ts | 8 +++----- .../src/NotificationServicesController/index.ts | 1 + .../src/NotificationServicesPushController/index.ts | 1 + .../src/controllers/authentication/index.ts | 1 + .../src/controllers/user-storage/index.ts | 1 + 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts index c9e4d79d45..87154aa8c0 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/NotificationServicesController.test.ts @@ -4,10 +4,8 @@ import type { KeyringControllerGetAccountsAction, KeyringControllerState, } from '@metamask/keyring-controller'; -import type { - AuthenticationController, - UserStorageController, -} from '@metamask/profile-sync-controller'; +import type { UserStorageController } from '@metamask/profile-sync-controller'; +import { AuthenticationController } from '@metamask/profile-sync-controller'; import { createMockFeatureAnnouncementAPIResult, @@ -694,7 +692,7 @@ function mockNotificationMessenger() { const mockGetBearerToken = typedMockAction().mockResolvedValue( - 'MOCK_ACCESS_TOKEN', + AuthenticationController.Mocks.MOCK_ACCESS_TOKEN, ); const mockIsSignedIn = diff --git a/packages/notification-services-controller/src/NotificationServicesController/index.ts b/packages/notification-services-controller/src/NotificationServicesController/index.ts index 4a5de527bb..6ba00e9912 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/index.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/index.ts @@ -5,6 +5,7 @@ export { Controller }; export default NotificationServicesController; export * from './NotificationServicesController'; export * as Types from './types'; +export * as Mocks from './__fixtures__'; export * as Processors from './processors'; export * as Constants from './constants'; export * as UI from './ui'; diff --git a/packages/notification-services-controller/src/NotificationServicesPushController/index.ts b/packages/notification-services-controller/src/NotificationServicesPushController/index.ts index d1024c78d2..ba4e7252a9 100644 --- a/packages/notification-services-controller/src/NotificationServicesPushController/index.ts +++ b/packages/notification-services-controller/src/NotificationServicesPushController/index.ts @@ -6,3 +6,4 @@ export default NotificationServicesPushController; export * from './NotificationServicesPushController'; export * as Types from './types'; export * as Utils from './utils'; +export * as Mocks from './__fixtures__'; diff --git a/packages/profile-sync-controller/src/controllers/authentication/index.ts b/packages/profile-sync-controller/src/controllers/authentication/index.ts index c1843a808e..1431d890f0 100644 --- a/packages/profile-sync-controller/src/controllers/authentication/index.ts +++ b/packages/profile-sync-controller/src/controllers/authentication/index.ts @@ -4,3 +4,4 @@ const AuthenticationController = Controller; export { Controller }; export default AuthenticationController; export * from './AuthenticationController'; +export * as Mocks from './__fixtures__'; diff --git a/packages/profile-sync-controller/src/controllers/user-storage/index.ts b/packages/profile-sync-controller/src/controllers/user-storage/index.ts index f5bf5a0423..f6b2fc8d0d 100644 --- a/packages/profile-sync-controller/src/controllers/user-storage/index.ts +++ b/packages/profile-sync-controller/src/controllers/user-storage/index.ts @@ -5,3 +5,4 @@ export { Controller }; export default UserStorageController; export * from './UserStorageController'; export * from './encryption'; +export * as Mocks from './__fixtures__'; From 21d139ea290711a088d08a1760169c0cff85d7f4 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Wed, 14 Aug 2024 15:26:40 +0100 Subject: [PATCH 6/8] chore: add package.json files for aliased paths this ensures that JS projects are able to find and resolve the paths to the module sub-files. E.g. "Unable to resolve path to module '@metamask-previews/profile-sync-controller/user-storage'. (eslintimport/no-unresolved)" --- .../notification-services/constants/package.json | 9 +++++++++ .../notification-services/mocks/package.json | 9 +++++++++ .../notification-services/package.json | 9 +++++++++ .../notification-services/processors/package.json | 9 +++++++++ .../notification-services/types/package.json | 9 +++++++++ .../notification-services/ui/package.json | 9 +++++++++ .../push-services/mocks/package.json | 9 +++++++++ .../push-services/package.json | 9 +++++++++ .../push-services/types/package.json | 9 +++++++++ .../push-services/utils/package.json | 9 +++++++++ packages/profile-sync-controller/auth/mocks/package.json | 9 +++++++++ packages/profile-sync-controller/auth/package.json | 9 +++++++++ .../user-storage/mocks/package.json | 9 +++++++++ .../profile-sync-controller/user-storage/package.json | 9 +++++++++ 14 files changed, 126 insertions(+) create mode 100644 packages/notification-services-controller/notification-services/constants/package.json create mode 100644 packages/notification-services-controller/notification-services/mocks/package.json create mode 100644 packages/notification-services-controller/notification-services/package.json create mode 100644 packages/notification-services-controller/notification-services/processors/package.json create mode 100644 packages/notification-services-controller/notification-services/types/package.json create mode 100644 packages/notification-services-controller/notification-services/ui/package.json create mode 100644 packages/notification-services-controller/push-services/mocks/package.json create mode 100644 packages/notification-services-controller/push-services/package.json create mode 100644 packages/notification-services-controller/push-services/types/package.json create mode 100644 packages/notification-services-controller/push-services/utils/package.json create mode 100644 packages/profile-sync-controller/auth/mocks/package.json create mode 100644 packages/profile-sync-controller/auth/package.json create mode 100644 packages/profile-sync-controller/user-storage/mocks/package.json create mode 100644 packages/profile-sync-controller/user-storage/package.json diff --git a/packages/notification-services-controller/notification-services/constants/package.json b/packages/notification-services-controller/notification-services/constants/package.json new file mode 100644 index 0000000000..bf2dcc4dd4 --- /dev/null +++ b/packages/notification-services-controller/notification-services/constants/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/constants/index.js", + "types": "../../dist/types/NotificationServicesController/constants/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/mocks/package.json b/packages/notification-services-controller/notification-services/mocks/package.json new file mode 100644 index 0000000000..3f34e9911f --- /dev/null +++ b/packages/notification-services-controller/notification-services/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/__fixtures__/index.js", + "types": "../../dist/types/NotificationServicesController/__fixtures__/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/package.json b/packages/notification-services-controller/notification-services/package.json new file mode 100644 index 0000000000..741335458f --- /dev/null +++ b/packages/notification-services-controller/notification-services/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/NotificationServicesController/index.js", + "types": "../dist/types/NotificationServicesController/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/processors/package.json b/packages/notification-services-controller/notification-services/processors/package.json new file mode 100644 index 0000000000..68ad2f09f1 --- /dev/null +++ b/packages/notification-services-controller/notification-services/processors/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/processors/index.js", + "types": "../../dist/types/NotificationServicesController/processors/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/types/package.json b/packages/notification-services-controller/notification-services/types/package.json new file mode 100644 index 0000000000..43101f9622 --- /dev/null +++ b/packages/notification-services-controller/notification-services/types/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/types/index.js", + "types": "../../dist/types/NotificationServicesController/types/index.d.ts" +} diff --git a/packages/notification-services-controller/notification-services/ui/package.json b/packages/notification-services-controller/notification-services/ui/package.json new file mode 100644 index 0000000000..28736d4f3c --- /dev/null +++ b/packages/notification-services-controller/notification-services/ui/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesController/ui/index.js", + "types": "../../dist/types/NotificationServicesController/ui/index.d.ts" +} diff --git a/packages/notification-services-controller/push-services/mocks/package.json b/packages/notification-services-controller/push-services/mocks/package.json new file mode 100644 index 0000000000..f4fe0ab552 --- /dev/null +++ b/packages/notification-services-controller/push-services/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesPushController/__fixtures__/index.js", + "types": "../../dist/types/NotificationServicesPushController/__fixtures__/index.d.ts" +} diff --git a/packages/notification-services-controller/push-services/package.json b/packages/notification-services-controller/push-services/package.json new file mode 100644 index 0000000000..0004da66d8 --- /dev/null +++ b/packages/notification-services-controller/push-services/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/NotificationServicesPushController/index.js", + "types": "../dist/types/NotificationServicesPushController/index.d.ts" +} diff --git a/packages/notification-services-controller/push-services/types/package.json b/packages/notification-services-controller/push-services/types/package.json new file mode 100644 index 0000000000..052f970a68 --- /dev/null +++ b/packages/notification-services-controller/push-services/types/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesPushController/types/index.js", + "types": "../../dist/types/NotificationServicesPushController/types/index.d.ts" +} diff --git a/packages/notification-services-controller/push-services/utils/package.json b/packages/notification-services-controller/push-services/utils/package.json new file mode 100644 index 0000000000..c5159726fd --- /dev/null +++ b/packages/notification-services-controller/push-services/utils/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/notification-services-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/NotificationServicesPushController/utils/index.js", + "types": "../../dist/types/NotificationServicesPushController/utils/index.d.ts" +} diff --git a/packages/profile-sync-controller/auth/mocks/package.json b/packages/profile-sync-controller/auth/mocks/package.json new file mode 100644 index 0000000000..345433f357 --- /dev/null +++ b/packages/profile-sync-controller/auth/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/controllers/authentication/__fixtures__/index.js", + "types": "../../dist/types/controllers/authentication/__fixtures__/index.d.ts" +} diff --git a/packages/profile-sync-controller/auth/package.json b/packages/profile-sync-controller/auth/package.json new file mode 100644 index 0000000000..2f365b2d3d --- /dev/null +++ b/packages/profile-sync-controller/auth/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/controllers/authentication/index.js", + "types": "../dist/types/controllers/authentication/index.d.ts" +} diff --git a/packages/profile-sync-controller/user-storage/mocks/package.json b/packages/profile-sync-controller/user-storage/mocks/package.json new file mode 100644 index 0000000000..1dfa95b033 --- /dev/null +++ b/packages/profile-sync-controller/user-storage/mocks/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../../dist/controllers/user-storage/__fixtures__/index.js", + "types": "../../dist/types/controllers/user-storage/__fixtures__/index.d.ts" +} diff --git a/packages/profile-sync-controller/user-storage/package.json b/packages/profile-sync-controller/user-storage/package.json new file mode 100644 index 0000000000..dfd124ae6a --- /dev/null +++ b/packages/profile-sync-controller/user-storage/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/controllers/user-storage/index.js", + "types": "../dist/types/controllers/user-storage/index.d.ts" +} From 5a93d655efdc57d252138a5c163365bde6fe68f1 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Wed, 14 Aug 2024 18:32:13 +0100 Subject: [PATCH 7/8] refactor: add files folder and temporary remove workspace validation. will need to discuss with the team how we can better handle workspace validation. --- packages/notification-services-controller/package.json | 4 +++- packages/profile-sync-controller/package.json | 4 +++- yarn.config.cjs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/notification-services-controller/package.json b/packages/notification-services-controller/package.json index 7be47aeaf5..63304fe5bf 100644 --- a/packages/notification-services-controller/package.json +++ b/packages/notification-services-controller/package.json @@ -77,7 +77,9 @@ "main": "./dist/index.js", "types": "./dist/types/index.d.ts", "files": [ - "dist/" + "dist/", + "notification-services/", + "push-services/" ], "scripts": { "build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean", diff --git a/packages/profile-sync-controller/package.json b/packages/profile-sync-controller/package.json index 3da40d593d..67c0d3f3ba 100644 --- a/packages/profile-sync-controller/package.json +++ b/packages/profile-sync-controller/package.json @@ -52,7 +52,9 @@ "main": "./dist/index.js", "types": "./dist/types/index.d.ts", "files": [ - "dist/" + "dist/", + "auth/", + "user-storage/" ], "scripts": { "build": "tsup --config ../../tsup.config.ts --tsconfig ./tsconfig.build.json --clean", diff --git a/yarn.config.cjs b/yarn.config.cjs index 8067030724..d1821dfe05 100644 --- a/yarn.config.cjs +++ b/yarn.config.cjs @@ -159,7 +159,7 @@ module.exports = defineConfig({ if (isChildWorkspace) { // The list of files included in all non-root packages must only include // files generated during the build process. - expectWorkspaceField(workspace, 'files', ['dist/']); + // expectWorkspaceField(workspace, 'files', ['dist/']); } else { // The root package must specify an empty set of published files. (This // is required in order to be able to import anything in From 723d61b57b8e48328bafe9afe970eb09fe20c916 Mon Sep 17 00:00:00 2001 From: Prithpal Sooriya Date: Thu, 15 Aug 2024 15:20:47 +0100 Subject: [PATCH 8/8] feat: add profile sync sdk package path --- packages/profile-sync-controller/sdk/package.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packages/profile-sync-controller/sdk/package.json diff --git a/packages/profile-sync-controller/sdk/package.json b/packages/profile-sync-controller/sdk/package.json new file mode 100644 index 0000000000..d95f4fa166 --- /dev/null +++ b/packages/profile-sync-controller/sdk/package.json @@ -0,0 +1,9 @@ +{ + "name": "@metamask/profile-sync-controller", + "version": "1.0.0", + "description": "", + "license": "MIT", + "sideEffects": false, + "main": "../dist/sdk/index.js", + "types": "../dist/types/sdk/index.d.ts" +}