@metamask-previews/notification-services-controller 0.0.0-preview-23a96ae → 0.0.0-preview-7ff4bd7f
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/dist/NotificationServicesController/NotificationServicesController.js +3 -3
- package/dist/NotificationServicesController/NotificationServicesController.mjs +3 -3
- package/dist/NotificationServicesController/index.js +4 -4
- package/dist/NotificationServicesController/index.mjs +4 -4
- package/dist/NotificationServicesController/services/onchain-notifications.js +2 -2
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.js +5 -5
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +5 -5
- package/dist/NotificationServicesPushController/index.js +6 -6
- package/dist/NotificationServicesPushController/index.mjs +6 -6
- package/dist/NotificationServicesPushController/services/push/push-web.js +3 -3
- package/dist/NotificationServicesPushController/services/push/push-web.mjs +3 -3
- package/dist/NotificationServicesPushController/services/services.js +3 -3
- package/dist/NotificationServicesPushController/services/services.mjs +3 -3
- package/dist/NotificationServicesPushController/utils/get-notification-message.js +3 -3
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +3 -3
- package/dist/NotificationServicesPushController/utils/index.js +3 -3
- package/dist/NotificationServicesPushController/utils/index.mjs +3 -3
- package/dist/{chunk-AXZU6W3P.js → chunk-3NF7QYJN.js} +7 -7
- package/dist/chunk-3NF7QYJN.js.map +1 -0
- package/dist/{chunk-53Y2GNFU.js → chunk-3O5NGZWB.js} +336 -1
- package/dist/chunk-3O5NGZWB.js.map +1 -0
- package/dist/{chunk-5WWCWQCE.js → chunk-DKQBDI4C.js} +1 -1
- package/dist/chunk-DKQBDI4C.js.map +1 -0
- package/dist/{chunk-G5RGQ3AG.js → chunk-EG5NZ5DA.js} +5 -5
- package/dist/chunk-EG5NZ5DA.js.map +1 -0
- package/dist/{chunk-F6TSWKZK.mjs → chunk-IG3CMJBW.mjs} +336 -1
- package/dist/chunk-IG3CMJBW.mjs.map +1 -0
- package/dist/{chunk-ZDG7PIUJ.js → chunk-KPO4QJHS.js} +10 -10
- package/dist/chunk-KPO4QJHS.js.map +1 -0
- package/dist/{chunk-OUPWMPLU.mjs → chunk-ODZ6V4PH.mjs} +1 -1
- package/dist/chunk-ODZ6V4PH.mjs.map +1 -0
- package/dist/{chunk-6PPEQMF5.mjs → chunk-RNE2I5IN.mjs} +4 -4
- package/dist/chunk-RNE2I5IN.mjs.map +1 -0
- package/dist/{chunk-KKWCKF5W.mjs → chunk-UZXBH6WS.mjs} +2 -2
- package/dist/chunk-UZXBH6WS.mjs.map +1 -0
- package/dist/{chunk-G2ROCNJN.mjs → chunk-ZJRT7ACU.mjs} +4 -4
- package/dist/chunk-ZJRT7ACU.mjs.map +1 -0
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/NotificationServicesController/NotificationServicesController.d.ts +1 -1
- package/dist/types/NotificationServicesController/NotificationServicesController.d.ts.map +1 -1
- package/dist/types/NotificationServicesController/index.d.ts +2 -0
- package/dist/types/NotificationServicesController/index.d.ts.map +1 -1
- package/dist/types/NotificationServicesPushController/NotificationServicesPushController.d.ts +1 -1
- package/dist/types/NotificationServicesPushController/NotificationServicesPushController.d.ts.map +1 -1
- package/dist/types/NotificationServicesPushController/index.d.ts +2 -0
- package/dist/types/NotificationServicesPushController/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-53Y2GNFU.js.map +0 -1
- package/dist/chunk-5WWCWQCE.js.map +0 -1
- package/dist/chunk-6PPEQMF5.mjs.map +0 -1
- package/dist/chunk-AXZU6W3P.js.map +0 -1
- package/dist/chunk-F6TSWKZK.mjs.map +0 -1
- package/dist/chunk-G2ROCNJN.mjs.map +0 -1
- package/dist/chunk-G5RGQ3AG.js.map +0 -1
- package/dist/chunk-KKWCKF5W.mjs.map +0 -1
- package/dist/chunk-OUPWMPLU.mjs.map +0 -1
- package/dist/chunk-ZDG7PIUJ.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport log from 'loglevel';\n\nimport type { Types } from '../NotificationServicesController';\nimport { createRegToken, deleteRegToken } from './services/push/push-web';\nimport {\n activatePushNotifications,\n deactivatePushNotifications,\n listenToPushNotifications,\n updateTriggerPushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n fcmToken: string;\n};\n\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `${typeof controllerName}:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\n};\n\nexport type NotificationServicesPushControllerDisablePushNotificationsAction = {\n type: `${typeof controllerName}:disablePushNotifications`;\n handler: NotificationServicesPushController['disablePushNotifications'];\n};\nexport type NotificationServicesPushControllerUpdateTriggerPushNotificationsAction =\n {\n type: `${typeof controllerName}:updateTriggerPushNotifications`;\n handler: NotificationServicesPushController['updateTriggerPushNotifications'];\n };\n\nexport type Actions =\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction\n | ControllerGetStateAction<'state', NotificationServicesPushControllerState>;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClicked = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type AllowedEvents =\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClicked;\n\nexport type NotificationServicesPushControllerMessenger =\n RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n >;\n\nconst metadata = {\n fcmToken: {\n persist: true,\n anonymous: true,\n },\n};\n\ntype ControllerConfig = {\n /**\n * Config to turn on/off push notifications.\n * This is currently linked to MV3 builds on extension.\n */\n isPushEnabled: boolean;\n\n /**\n * Must handle when a push notification is received.\n * You must call `registration.showNotification` or equivalent to show the notification on web/mobile\n */\n onPushNotificationReceived: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n\n /**\n * Must handle when a push notification is clicked.\n * You must call `event.notification.close();` or equivalent for closing and opening notification in a new window.\n */\n onPushNotificationClicked: (\n event: NotificationEvent,\n notification?: Types.INotification,\n ) => void;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n};\n\n/**\n * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.\n * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.\n * It is responsible for registering and unregistering the service worker that listens for push notifications,\n * managing the FCM token, and communicating with the server to register or unregister the device for push notifications.\n * Additionally, it provides functionality to update the server with new UUIDs that should trigger push notifications.\n *\n * @augments {BaseController<typeof controllerName, NotificationServicesPushControllerState, NotificationServicesPushControllerMessenger>}\n */\nexport default class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n #env: PushNotificationEnv;\n\n #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n env: PushNotificationEnv;\n config: ControllerConfig;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: {\n fcmToken: state?.fcmToken || '',\n },\n });\n\n this.#env = env;\n this.#config = config;\n\n this.#registerMessageHandlers();\n }\n\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:enablePushNotifications',\n this.enablePushNotifications.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:disablePushNotifications',\n this.disablePushNotifications.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:updateTriggerPushNotifications',\n this.updateTriggerPushNotifications.bind(this),\n );\n }\n\n async #getAndAssertBearerToken() {\n const bearerToken = await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!bearerToken) {\n log.error(\n 'Failed to enable push notifications: BearerToken token is missing.',\n );\n throw new Error('BearerToken token is missing');\n }\n\n return bearerToken;\n }\n\n /**\n * Enables push notifications for the application.\n *\n * This method sets up the necessary infrastructure for handling push notifications by:\n * 1. Registering the service worker to listen for messages.\n * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.\n * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.\n *\n * @param UUIDs - An array of UUIDs to enable push notifications for.\n */\n async enablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n\n try {\n // Activate Push Notifications\n const regToken = await activatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken,\n platform: this.#config.platform,\n });\n\n if (!regToken) {\n return;\n }\n\n this.#pushListenerUnsubscribe = await listenToPushNotifications({\n env: this.#env,\n listenToPushReceived: async (n) => {\n this.messagingSystem.publish(\n 'NotificationServicesPushController:onNewNotifications',\n n,\n );\n await this.#config.onPushNotificationReceived(n);\n },\n listenToPushClicked: (e, n) => {\n if (n) {\n this.messagingSystem.publish(\n 'NotificationServicesPushController:pushNotificationClicked',\n n,\n );\n }\n\n this.#config.onPushNotificationClicked(e);\n },\n });\n\n // Update state\n this.update((state) => {\n state.fcmToken = regToken;\n });\n } catch (error) {\n log.error('Failed to enable push notifications:', error);\n throw new Error('Failed to enable push notifications');\n }\n }\n\n /**\n * Disables push notifications for the application.\n * This method handles the process of disabling push notifications by:\n * 1. Unregistering the service worker to stop listening for messages.\n * 2. Sending a request to the server to unregister the device using the FCM token.\n * 3. Removing the FCM token from the state to complete the process.\n *\n * @param UUIDs - An array of UUIDs for which push notifications should be disabled.\n */\n async disablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n let isPushNotificationsDisabled: boolean;\n\n try {\n // Send a request to the server to unregister the token/device\n isPushNotificationsDisabled = await deactivatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n deleteRegToken,\n regToken: this.state.fcmToken,\n });\n } catch (error) {\n const errorMessage = `Failed to disable push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n }\n\n // Remove the FCM token from the state\n if (!isPushNotificationsDisabled) {\n return;\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n if (isPushNotificationsDisabled) {\n this.update((state) => {\n state.fcmToken = '';\n });\n }\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of UUIDs that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param UUIDs - An array of UUIDs that should trigger push notifications.\n */\n async updateTriggerPushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n\n try {\n const { fcmToken } = await updateTriggerPushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken,\n deleteRegToken,\n platform: this.#config.platform,\n regToken: this.state.fcmToken,\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.update((state) => {\n state.fcmToken = fcmToken;\n });\n }\n } catch (error) {\n const errorMessage = `Failed to update triggers for push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n }\n }\n}\n"]}
|
|
@@ -6,13 +6,13 @@ var _chunkFFQNSBPUjs = require('./chunk-FFQNSBPU.js');
|
|
|
6
6
|
var _chunk7LWR54U7js = require('./chunk-7LWR54U7.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunkDKQBDI4Cjs = require('./chunk-DKQBDI4C.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
var _chunkB25TJ7KSjs = require('./chunk-B25TJ7KS.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunk3O5NGZWBjs = require('./chunk-3O5NGZWB.js');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
@@ -21,8 +21,8 @@ var _chunkV46WVGWNjs = require('./chunk-V46WVGWN.js');
|
|
|
21
21
|
// src/NotificationServicesPushController/index.ts
|
|
22
22
|
var NotificationServicesPushController_exports = {};
|
|
23
23
|
_chunkV46WVGWNjs.__export.call(void 0, NotificationServicesPushController_exports, {
|
|
24
|
+
Controller: () => _chunkDKQBDI4Cjs.NotificationServicesPushController,
|
|
24
25
|
Mocks: () => fixtures_exports,
|
|
25
|
-
NotificationServicesPushController: () => _chunk5WWCWQCEjs.NotificationServicesPushController,
|
|
26
26
|
Types: () => _chunk7LWR54U7js.types_exports,
|
|
27
27
|
Utils: () => _chunkFFQNSBPUjs.utils_exports
|
|
28
28
|
});
|
|
@@ -92,7 +92,7 @@ var getMockDeleteFCMRegistrationTokenResponse = () => {
|
|
|
92
92
|
};
|
|
93
93
|
|
|
94
94
|
// src/NotificationServicesPushController/__fixtures__/mockServices.ts
|
|
95
|
-
var import_nock = _chunkV46WVGWNjs.__toESM.call(void 0,
|
|
95
|
+
var import_nock = _chunkV46WVGWNjs.__toESM.call(void 0, _chunk3O5NGZWBjs.require_nock.call(void 0, ));
|
|
96
96
|
var mockEndpointGetPushNotificationLinks = (mockReply) => {
|
|
97
97
|
const mockResponse = getMockRetrievePushNotificationLinksResponse();
|
|
98
98
|
const reply = mockReply ?? {
|
|
@@ -116,4 +116,4 @@ var mockEndpointUpdatePushNotificationLinks = (mockReply) => {
|
|
|
116
116
|
|
|
117
117
|
|
|
118
118
|
exports.fixtures_exports = fixtures_exports; exports.NotificationServicesPushController_exports = NotificationServicesPushController_exports;
|
|
119
|
-
//# sourceMappingURL=chunk-
|
|
119
|
+
//# sourceMappingURL=chunk-EG5NZ5DA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/NotificationServicesPushController/index.ts","../src/NotificationServicesPushController/__fixtures__/index.ts","../src/NotificationServicesPushController/__fixtures__/mockResponse.ts","../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":["nock"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,IAAM,iBAAiB;AACvB,IAAM,sBAAmC;AAAA;AAAA,EAE9C,aAAa,CAAC,KAAK,KAAK,GAAG;AAAA;AAAA,EAE3B,qBAAqB;AAAA,IACnB,EAAE,OAAO,eAAe,UAAU,YAAY;AAAA,IAC9C,EAAE,OAAO,eAAe,UAAU,YAAY;AAAA,EAChD;AACF;AAEO,IAAM,+CAA+C,MAAM;AAChE,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,6CAA6C,MAAM;AAC9D,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,oBAAoB;AAAA,EAC/B,MAAM;AAAA,EACN,OAAO;AAAA,EACP,KAAK;AAAA,IACH,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,mBAAmB;AAAA,EACrB;AACF;AAEO,IAAM,4CAA4C,MAAM;AAC7D,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU;AAAA,EACZ;AACF;AAEO,IAAM,4CAA4C,MAAM;AAC7D,SAAO;AAAA,IACL,KAAK;AAAA,IACL,eAAe;AAAA,IACf,UAAU,CAAC;AAAA,EACb;AACF;;;AC7DA,kBAAiB;AAYV,IAAM,uCAAuC,CAAC,cAA0B;AAC7E,QAAM,eAAe,6CAA6C;AAClE,QAAM,QAAQ,aAAa;AAAA,IACzB,QAAQ;AAAA,IACR,MAAM,aAAa;AAAA,EACrB;AAEA,QAAM,mBAAe,YAAAA,SAAK,aAAa,GAAG,EACvC,IAAI,EAAE,EACN,MAAM,MAAM,QAAQ,MAAM,IAAI;AAEjC,SAAO;AACT;AAEO,IAAM,0CAA0C,CACrD,cACG;AACH,QAAM,eAAe,2CAA2C;AAChE,QAAM,QAAQ,aAAa;AAAA,IACzB,QAAQ;AAAA,IACR,MAAM,aAAa;AAAA,EACrB;AAEA,QAAM,mBAAe,YAAAA,SAAK,aAAa,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,MAAM,MAAM;AAEvE,SAAO;AACT","sourcesContent":["import Controller from './NotificationServicesPushController';\n\nexport { Controller };\nexport * from './NotificationServicesPushController';\nexport * as Types from './types';\nexport * as Utils from './utils';\nexport * as Mocks from './__fixtures__';\n","export * from './mockResponse';\nexport * from './mockServices';\n","import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\nimport type { LinksResult } from '../services/services';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\nexport const MOCK_LINKS_RESPONSE: LinksResult = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n trigger_ids: ['1', '2', '3'],\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_tokens: [\n { token: 'reg_token_1', platform: 'portfolio' },\n { token: 'reg_token_2', platform: 'extension' },\n ],\n};\n\nexport const getMockRetrievePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_LINKS_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUpdatePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n","import nock from 'nock';\n\nimport {\n getMockRetrievePushNotificationLinksResponse,\n getMockUpdatePushNotificationLinksResponse,\n} from './mockResponse';\n\ntype MockReply = {\n status: nock.StatusCode;\n body?: nock.Body;\n};\n\nexport const mockEndpointGetPushNotificationLinks = (mockReply?: MockReply) => {\n const mockResponse = getMockRetrievePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url)\n .get('')\n .reply(reply.status, reply.body);\n\n return mockEndpoint;\n};\n\nexport const mockEndpointUpdatePushNotificationLinks = (\n mockReply?: MockReply,\n) => {\n const mockResponse = getMockUpdatePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url).post('').reply(reply.status);\n\n return mockEndpoint;\n};\n"]}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
__commonJS,
|
|
8
8
|
__export,
|
|
9
9
|
__privateAdd,
|
|
10
|
+
__privateGet,
|
|
10
11
|
__privateMethod,
|
|
11
12
|
__require,
|
|
12
13
|
__toESM
|
|
@@ -4702,13 +4703,48 @@ var SHA256 = class extends HashMD {
|
|
|
4702
4703
|
};
|
|
4703
4704
|
var sha256 = /* @__PURE__ */ wrapConstructor(() => new SHA256());
|
|
4704
4705
|
|
|
4706
|
+
// ../../node_modules/@metamask/snaps-utils/dist/chunk-5R7UF7KM.mjs
|
|
4707
|
+
var HandlerType = /* @__PURE__ */ ((HandlerType2) => {
|
|
4708
|
+
HandlerType2["OnRpcRequest"] = "onRpcRequest";
|
|
4709
|
+
HandlerType2["OnSignature"] = "onSignature";
|
|
4710
|
+
HandlerType2["OnTransaction"] = "onTransaction";
|
|
4711
|
+
HandlerType2["OnCronjob"] = "onCronjob";
|
|
4712
|
+
HandlerType2["OnInstall"] = "onInstall";
|
|
4713
|
+
HandlerType2["OnUpdate"] = "onUpdate";
|
|
4714
|
+
HandlerType2["OnNameLookup"] = "onNameLookup";
|
|
4715
|
+
HandlerType2["OnKeyringRequest"] = "onKeyringRequest";
|
|
4716
|
+
HandlerType2["OnHomePage"] = "onHomePage";
|
|
4717
|
+
HandlerType2["OnUserInput"] = "onUserInput";
|
|
4718
|
+
return HandlerType2;
|
|
4719
|
+
})(HandlerType || {});
|
|
4720
|
+
var SNAP_EXPORT_NAMES = Object.values(HandlerType);
|
|
4721
|
+
|
|
4722
|
+
// ../profile-sync-controller/src/controllers/authentication/auth-snap-requests.ts
|
|
4723
|
+
var snapId = "npm:@metamask/message-signing-snap";
|
|
4724
|
+
function createSnapSignMessageRequest(message) {
|
|
4725
|
+
return {
|
|
4726
|
+
snapId,
|
|
4727
|
+
origin: "",
|
|
4728
|
+
handler: HandlerType.OnRpcRequest,
|
|
4729
|
+
request: {
|
|
4730
|
+
method: "signMessage",
|
|
4731
|
+
params: { message }
|
|
4732
|
+
}
|
|
4733
|
+
};
|
|
4734
|
+
}
|
|
4735
|
+
|
|
4705
4736
|
// ../profile-sync-controller/src/controllers/user-storage/index.ts
|
|
4706
4737
|
var user_storage_exports = {};
|
|
4707
4738
|
__export(user_storage_exports, {
|
|
4739
|
+
Controller: () => UserStorageController,
|
|
4740
|
+
Encryption: () => encryption_default,
|
|
4708
4741
|
Mocks: () => fixtures_exports,
|
|
4709
4742
|
createSHA256Hash: () => createSHA256Hash
|
|
4710
4743
|
});
|
|
4711
4744
|
|
|
4745
|
+
// ../profile-sync-controller/src/controllers/user-storage/UserStorageController.ts
|
|
4746
|
+
import { BaseController } from "@metamask/base-controller";
|
|
4747
|
+
|
|
4712
4748
|
// ../../node_modules/@noble/hashes/esm/scrypt.js
|
|
4713
4749
|
function XorAndSalsa(prev, pi, input, ii, out, oi) {
|
|
4714
4750
|
let y00 = prev[pi++] ^ input[ii++], y01 = prev[pi++] ^ input[ii++];
|
|
@@ -5083,6 +5119,305 @@ function createEntryPath(entryKey, storageKey) {
|
|
|
5083
5119
|
var ENV_URLS2 = getEnvUrls("prd" /* PRD */);
|
|
5084
5120
|
var USER_STORAGE_API = ENV_URLS2.userStorageApiUrl;
|
|
5085
5121
|
var USER_STORAGE_ENDPOINT = `${USER_STORAGE_API}/api/v1/userstorage`;
|
|
5122
|
+
async function getUserStorage(opts) {
|
|
5123
|
+
try {
|
|
5124
|
+
const path = createEntryPath(opts.entryKey, opts.storageKey);
|
|
5125
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);
|
|
5126
|
+
const userStorageResponse = await fetch(url.toString(), {
|
|
5127
|
+
headers: {
|
|
5128
|
+
"Content-Type": "application/json",
|
|
5129
|
+
Authorization: `Bearer ${opts.bearerToken}`
|
|
5130
|
+
}
|
|
5131
|
+
});
|
|
5132
|
+
if (userStorageResponse.status === 404) {
|
|
5133
|
+
return null;
|
|
5134
|
+
}
|
|
5135
|
+
if (userStorageResponse.status !== 200) {
|
|
5136
|
+
throw new Error("Unable to get User Storage");
|
|
5137
|
+
}
|
|
5138
|
+
const userStorage = await userStorageResponse.json();
|
|
5139
|
+
const encryptedData = userStorage?.Data ?? null;
|
|
5140
|
+
if (!encryptedData) {
|
|
5141
|
+
return null;
|
|
5142
|
+
}
|
|
5143
|
+
const decryptedData = encryption_default2.decryptString(
|
|
5144
|
+
encryptedData,
|
|
5145
|
+
opts.storageKey
|
|
5146
|
+
);
|
|
5147
|
+
return decryptedData;
|
|
5148
|
+
} catch (e) {
|
|
5149
|
+
log.error("Failed to get user storage", e);
|
|
5150
|
+
return null;
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
async function upsertUserStorage(data, opts) {
|
|
5154
|
+
const encryptedData = encryption_default2.encryptString(data, opts.storageKey);
|
|
5155
|
+
const path = createEntryPath(opts.entryKey, opts.storageKey);
|
|
5156
|
+
const url = new URL(`${USER_STORAGE_ENDPOINT}${path}`);
|
|
5157
|
+
const res = await fetch(url.toString(), {
|
|
5158
|
+
method: "PUT",
|
|
5159
|
+
headers: {
|
|
5160
|
+
"Content-Type": "application/json",
|
|
5161
|
+
Authorization: `Bearer ${opts.bearerToken}`
|
|
5162
|
+
},
|
|
5163
|
+
body: JSON.stringify({ data: encryptedData })
|
|
5164
|
+
});
|
|
5165
|
+
if (!res.ok) {
|
|
5166
|
+
throw new Error("user-storage - unable to upsert data");
|
|
5167
|
+
}
|
|
5168
|
+
}
|
|
5169
|
+
|
|
5170
|
+
// ../profile-sync-controller/src/controllers/user-storage/UserStorageController.ts
|
|
5171
|
+
var controllerName = "UserStorageController";
|
|
5172
|
+
var defaultState = {
|
|
5173
|
+
isProfileSyncingEnabled: true,
|
|
5174
|
+
isProfileSyncingUpdateLoading: false
|
|
5175
|
+
};
|
|
5176
|
+
var metadata = {
|
|
5177
|
+
isProfileSyncingEnabled: {
|
|
5178
|
+
persist: true,
|
|
5179
|
+
anonymous: true
|
|
5180
|
+
},
|
|
5181
|
+
isProfileSyncingUpdateLoading: {
|
|
5182
|
+
persist: false,
|
|
5183
|
+
anonymous: false
|
|
5184
|
+
}
|
|
5185
|
+
};
|
|
5186
|
+
var _auth, _notificationServices, _registerMessageHandlers, registerMessageHandlers_fn, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn, _createStorageKey, createStorageKey_fn, _snapSignMessage, snapSignMessage_fn, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn;
|
|
5187
|
+
var UserStorageController = class extends BaseController {
|
|
5188
|
+
constructor(params) {
|
|
5189
|
+
super({
|
|
5190
|
+
messenger: params.messenger,
|
|
5191
|
+
metadata,
|
|
5192
|
+
name: controllerName,
|
|
5193
|
+
state: { ...defaultState, ...params.state }
|
|
5194
|
+
});
|
|
5195
|
+
/**
|
|
5196
|
+
* Constructor helper for registering this controller's messaging system
|
|
5197
|
+
* actions.
|
|
5198
|
+
*/
|
|
5199
|
+
__privateAdd(this, _registerMessageHandlers);
|
|
5200
|
+
__privateAdd(this, _assertProfileSyncingEnabled);
|
|
5201
|
+
/**
|
|
5202
|
+
* Utility to get the bearer token and storage key
|
|
5203
|
+
*/
|
|
5204
|
+
__privateAdd(this, _getStorageKeyAndBearerToken);
|
|
5205
|
+
/**
|
|
5206
|
+
* Rather than storing the storage key, we can compute the storage key when needed.
|
|
5207
|
+
*
|
|
5208
|
+
* @returns the storage key
|
|
5209
|
+
*/
|
|
5210
|
+
__privateAdd(this, _createStorageKey);
|
|
5211
|
+
/**
|
|
5212
|
+
* Signs a specific message using an underlying auth snap.
|
|
5213
|
+
*
|
|
5214
|
+
* @param message - A specific tagged message to sign.
|
|
5215
|
+
* @returns A Signature created by the snap.
|
|
5216
|
+
*/
|
|
5217
|
+
__privateAdd(this, _snapSignMessage);
|
|
5218
|
+
__privateAdd(this, _setIsProfileSyncingUpdateLoading);
|
|
5219
|
+
__privateAdd(this, _auth, {
|
|
5220
|
+
getBearerToken: async () => {
|
|
5221
|
+
return await this.messagingSystem.call(
|
|
5222
|
+
"AuthenticationController:getBearerToken"
|
|
5223
|
+
);
|
|
5224
|
+
},
|
|
5225
|
+
getProfileId: async () => {
|
|
5226
|
+
const sessionProfile = await this.messagingSystem.call(
|
|
5227
|
+
"AuthenticationController:getSessionProfile"
|
|
5228
|
+
);
|
|
5229
|
+
return sessionProfile?.profileId;
|
|
5230
|
+
},
|
|
5231
|
+
isAuthEnabled: () => {
|
|
5232
|
+
return this.messagingSystem.call("AuthenticationController:isSignedIn");
|
|
5233
|
+
},
|
|
5234
|
+
signIn: async () => {
|
|
5235
|
+
return await this.messagingSystem.call(
|
|
5236
|
+
"AuthenticationController:performSignIn"
|
|
5237
|
+
);
|
|
5238
|
+
},
|
|
5239
|
+
signOut: async () => {
|
|
5240
|
+
return this.messagingSystem.call(
|
|
5241
|
+
"AuthenticationController:performSignOut"
|
|
5242
|
+
);
|
|
5243
|
+
}
|
|
5244
|
+
});
|
|
5245
|
+
__privateAdd(this, _notificationServices, {
|
|
5246
|
+
disableNotificationServices: async () => {
|
|
5247
|
+
return await this.messagingSystem.call(
|
|
5248
|
+
"NotificationServicesController:disableNotificationServices"
|
|
5249
|
+
);
|
|
5250
|
+
},
|
|
5251
|
+
selectIsNotificationServicesEnabled: async () => {
|
|
5252
|
+
return this.messagingSystem.call(
|
|
5253
|
+
"NotificationServicesController:selectIsNotificationServicesEnabled"
|
|
5254
|
+
);
|
|
5255
|
+
}
|
|
5256
|
+
});
|
|
5257
|
+
this.getMetaMetricsState = params.getMetaMetricsState;
|
|
5258
|
+
__privateMethod(this, _registerMessageHandlers, registerMessageHandlers_fn).call(this);
|
|
5259
|
+
}
|
|
5260
|
+
async enableProfileSyncing() {
|
|
5261
|
+
try {
|
|
5262
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
5263
|
+
const authEnabled = __privateGet(this, _auth).isAuthEnabled();
|
|
5264
|
+
if (!authEnabled) {
|
|
5265
|
+
await __privateGet(this, _auth).signIn();
|
|
5266
|
+
}
|
|
5267
|
+
this.update((state) => {
|
|
5268
|
+
state.isProfileSyncingEnabled = true;
|
|
5269
|
+
});
|
|
5270
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5271
|
+
} catch (e) {
|
|
5272
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5273
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5274
|
+
throw new Error(
|
|
5275
|
+
`${controllerName} - failed to enable profile syncing - ${errorMessage}`
|
|
5276
|
+
);
|
|
5277
|
+
}
|
|
5278
|
+
}
|
|
5279
|
+
async setIsProfileSyncingEnabled(isProfileSyncingEnabled) {
|
|
5280
|
+
this.update((state) => {
|
|
5281
|
+
state.isProfileSyncingEnabled = isProfileSyncingEnabled;
|
|
5282
|
+
});
|
|
5283
|
+
}
|
|
5284
|
+
async disableProfileSyncing() {
|
|
5285
|
+
const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;
|
|
5286
|
+
if (isAlreadyDisabled) {
|
|
5287
|
+
return;
|
|
5288
|
+
}
|
|
5289
|
+
try {
|
|
5290
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, true);
|
|
5291
|
+
const isNotificationServicesEnabled = await __privateGet(this, _notificationServices).selectIsNotificationServicesEnabled();
|
|
5292
|
+
if (isNotificationServicesEnabled) {
|
|
5293
|
+
await __privateGet(this, _notificationServices).disableNotificationServices();
|
|
5294
|
+
}
|
|
5295
|
+
const isMetaMetricsParticipation = this.getMetaMetricsState();
|
|
5296
|
+
if (!isMetaMetricsParticipation) {
|
|
5297
|
+
this.messagingSystem.call("AuthenticationController:performSignOut");
|
|
5298
|
+
}
|
|
5299
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5300
|
+
this.update((state) => {
|
|
5301
|
+
state.isProfileSyncingEnabled = false;
|
|
5302
|
+
});
|
|
5303
|
+
} catch (e) {
|
|
5304
|
+
__privateMethod(this, _setIsProfileSyncingUpdateLoading, setIsProfileSyncingUpdateLoading_fn).call(this, false);
|
|
5305
|
+
const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);
|
|
5306
|
+
throw new Error(
|
|
5307
|
+
`${controllerName} - failed to disable profile syncing - ${errorMessage}`
|
|
5308
|
+
);
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
/**
|
|
5312
|
+
* Allows retrieval of stored data. Data stored is string formatted.
|
|
5313
|
+
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
5314
|
+
*
|
|
5315
|
+
* @param entryKey - entry key that matches schema
|
|
5316
|
+
* @returns the decrypted string contents found from user storage (or null if not found)
|
|
5317
|
+
*/
|
|
5318
|
+
async performGetStorage(entryKey) {
|
|
5319
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
5320
|
+
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
5321
|
+
const result = await getUserStorage({
|
|
5322
|
+
entryKey,
|
|
5323
|
+
bearerToken,
|
|
5324
|
+
storageKey
|
|
5325
|
+
});
|
|
5326
|
+
return result;
|
|
5327
|
+
}
|
|
5328
|
+
/**
|
|
5329
|
+
* Allows storage of user data. Data stored must be string formatted.
|
|
5330
|
+
* Developers can extend the entry path and entry name through the `schema.ts` file.
|
|
5331
|
+
*
|
|
5332
|
+
* @param entryKey - entry key that matches schema
|
|
5333
|
+
* @param value - The string data you want to store.
|
|
5334
|
+
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
5335
|
+
*/
|
|
5336
|
+
async performSetStorage(entryKey, value) {
|
|
5337
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
5338
|
+
const { bearerToken, storageKey } = await __privateMethod(this, _getStorageKeyAndBearerToken, getStorageKeyAndBearerToken_fn).call(this);
|
|
5339
|
+
await upsertUserStorage(value, {
|
|
5340
|
+
entryKey,
|
|
5341
|
+
bearerToken,
|
|
5342
|
+
storageKey
|
|
5343
|
+
});
|
|
5344
|
+
}
|
|
5345
|
+
/**
|
|
5346
|
+
* Retrieves the storage key, for internal use only!
|
|
5347
|
+
*
|
|
5348
|
+
* @returns the storage key
|
|
5349
|
+
*/
|
|
5350
|
+
async getStorageKey() {
|
|
5351
|
+
__privateMethod(this, _assertProfileSyncingEnabled, assertProfileSyncingEnabled_fn).call(this);
|
|
5352
|
+
const storageKey = await __privateMethod(this, _createStorageKey, createStorageKey_fn).call(this);
|
|
5353
|
+
return storageKey;
|
|
5354
|
+
}
|
|
5355
|
+
};
|
|
5356
|
+
_auth = new WeakMap();
|
|
5357
|
+
_notificationServices = new WeakMap();
|
|
5358
|
+
_registerMessageHandlers = new WeakSet();
|
|
5359
|
+
registerMessageHandlers_fn = function() {
|
|
5360
|
+
this.messagingSystem.registerActionHandler(
|
|
5361
|
+
"UserStorageController:performGetStorage",
|
|
5362
|
+
this.performGetStorage.bind(this)
|
|
5363
|
+
);
|
|
5364
|
+
this.messagingSystem.registerActionHandler(
|
|
5365
|
+
"UserStorageController:performSetStorage",
|
|
5366
|
+
this.performSetStorage.bind(this)
|
|
5367
|
+
);
|
|
5368
|
+
this.messagingSystem.registerActionHandler(
|
|
5369
|
+
"UserStorageController:getStorageKey",
|
|
5370
|
+
this.getStorageKey.bind(this)
|
|
5371
|
+
);
|
|
5372
|
+
this.messagingSystem.registerActionHandler(
|
|
5373
|
+
"UserStorageController:enableProfileSyncing",
|
|
5374
|
+
this.enableProfileSyncing.bind(this)
|
|
5375
|
+
);
|
|
5376
|
+
this.messagingSystem.registerActionHandler(
|
|
5377
|
+
"UserStorageController:disableProfileSyncing",
|
|
5378
|
+
this.disableProfileSyncing.bind(this)
|
|
5379
|
+
);
|
|
5380
|
+
};
|
|
5381
|
+
_assertProfileSyncingEnabled = new WeakSet();
|
|
5382
|
+
assertProfileSyncingEnabled_fn = function() {
|
|
5383
|
+
if (!this.state.isProfileSyncingEnabled) {
|
|
5384
|
+
throw new Error(
|
|
5385
|
+
`${controllerName}: Unable to call method, user is not authenticated`
|
|
5386
|
+
);
|
|
5387
|
+
}
|
|
5388
|
+
};
|
|
5389
|
+
_getStorageKeyAndBearerToken = new WeakSet();
|
|
5390
|
+
getStorageKeyAndBearerToken_fn = async function() {
|
|
5391
|
+
const bearerToken = await __privateGet(this, _auth).getBearerToken();
|
|
5392
|
+
if (!bearerToken) {
|
|
5393
|
+
throw new Error("UserStorageController - unable to get bearer token");
|
|
5394
|
+
}
|
|
5395
|
+
const storageKey = await __privateMethod(this, _createStorageKey, createStorageKey_fn).call(this);
|
|
5396
|
+
return { bearerToken, storageKey };
|
|
5397
|
+
};
|
|
5398
|
+
_createStorageKey = new WeakSet();
|
|
5399
|
+
createStorageKey_fn = async function() {
|
|
5400
|
+
const id = await __privateGet(this, _auth).getProfileId();
|
|
5401
|
+
if (!id) {
|
|
5402
|
+
throw new Error("UserStorageController - unable to create storage key");
|
|
5403
|
+
}
|
|
5404
|
+
const storageKeySignature = await __privateMethod(this, _snapSignMessage, snapSignMessage_fn).call(this, `metamask:${id}`);
|
|
5405
|
+
const storageKey = createSHA256Hash(storageKeySignature);
|
|
5406
|
+
return storageKey;
|
|
5407
|
+
};
|
|
5408
|
+
_snapSignMessage = new WeakSet();
|
|
5409
|
+
snapSignMessage_fn = function(message) {
|
|
5410
|
+
return this.messagingSystem.call(
|
|
5411
|
+
"SnapController:handleRequest",
|
|
5412
|
+
createSnapSignMessageRequest(message)
|
|
5413
|
+
);
|
|
5414
|
+
};
|
|
5415
|
+
_setIsProfileSyncingUpdateLoading = new WeakSet();
|
|
5416
|
+
setIsProfileSyncingUpdateLoading_fn = function(isProfileSyncingUpdateLoading) {
|
|
5417
|
+
this.update((state) => {
|
|
5418
|
+
state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;
|
|
5419
|
+
});
|
|
5420
|
+
};
|
|
5086
5421
|
|
|
5087
5422
|
// ../profile-sync-controller/src/controllers/user-storage/__fixtures__/index.ts
|
|
5088
5423
|
var fixtures_exports = {};
|
|
@@ -5336,4 +5671,4 @@ export {
|
|
|
5336
5671
|
@noble/hashes/esm/utils.js:
|
|
5337
5672
|
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
5338
5673
|
*/
|
|
5339
|
-
//# sourceMappingURL=chunk-
|
|
5674
|
+
//# sourceMappingURL=chunk-IG3CMJBW.mjs.map
|