@metamask-previews/notification-services-controller 29.0.2-preview-122ecfd → 29.0.2-preview-247ba396c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.ts +16 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.ts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.js.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.ts +24 -2
- package/dist/NotificationServicesController/NotificationServicesController.d.ts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.js +58 -1
- package/dist/NotificationServicesController/NotificationServicesController.js.map +1 -1
- package/dist/NotificationServicesController/index.d.ts +1 -1
- package/dist/NotificationServicesController/index.d.ts.map +1 -1
- package/dist/NotificationServicesController/index.js.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.ts +1 -0
- package/dist/NotificationServicesController/mocks/mockResponses.d.ts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.js +21 -1
- package/dist/NotificationServicesController/mocks/mockResponses.js.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.ts +11 -1
- package/dist/NotificationServicesController/services/api-notifications.d.ts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.js +40 -4
- package/dist/NotificationServicesController/services/api-notifications.js.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.d.ts.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.js.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.ts +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.ts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.js.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.ts +14 -5
- package/dist/NotificationServicesController/utils/utils.d.ts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.js +17 -14
- package/dist/NotificationServicesController/utils/utils.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `fetchMetamaskNotificationsCategories()` controller method that fetches the notification categories manifest from `GET /api/v4/notifications/categories`, stores the result in new `metamaskNotificationsCategories` state, and exposes it through the messenger as `NotificationServicesController:fetchMetamaskNotificationsCategories` ([#9984](https://github.com/MetaMask/core/pull/9984))
|
|
13
|
+
- Add `metamaskNotificationsCategories` state field (`NotificationsCategory[]`) for the server-driven notification settings taxonomy ([#9984](https://github.com/MetaMask/core/pull/9984))
|
|
14
|
+
- Add `isFetchingMetamaskNotificationsCategories` state flag that reflects whether the categories request is in flight ([#9984](https://github.com/MetaMask/core/pull/9984))
|
|
15
|
+
- Export `NotificationsCategory` type from the notification-api schema ([#9984](https://github.com/MetaMask/core/pull/9984))
|
|
16
|
+
|
|
10
17
|
### Changed
|
|
11
18
|
|
|
12
19
|
- Bump `lodash-es` from `^4.17.21` to `^4.18.1` ([#10447](https://github.com/MetaMask/core/pull/10447))
|
package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.ts
CHANGED
|
@@ -193,8 +193,23 @@ export type NotificationServicesControllerSendPerpPlaceOrderNotificationAction =
|
|
|
193
193
|
type: `NotificationServicesController:sendPerpPlaceOrderNotification`;
|
|
194
194
|
handler: NotificationServicesController['sendPerpPlaceOrderNotification'];
|
|
195
195
|
};
|
|
196
|
+
/**
|
|
197
|
+
* Fetches the list of MetaMask notification categories from the notifications API,
|
|
198
|
+
* stores the result in controller state, and returns the categories.
|
|
199
|
+
*
|
|
200
|
+
* This method sets the categories-loading flag while the request is in flight
|
|
201
|
+
* so the UI can reflect the loading state. If the request fails, it logs the
|
|
202
|
+
* error and throws a generic failure error.
|
|
203
|
+
*
|
|
204
|
+
* @returns A promise that resolves to the fetched notification categories.
|
|
205
|
+
* @throws {Error} If the categories request fails.
|
|
206
|
+
*/
|
|
207
|
+
export type NotificationServicesControllerFetchMetamaskNotificationsCategoriesAction = {
|
|
208
|
+
type: `NotificationServicesController:fetchMetamaskNotificationsCategories`;
|
|
209
|
+
handler: NotificationServicesController['fetchMetamaskNotificationsCategories'];
|
|
210
|
+
};
|
|
196
211
|
/**
|
|
197
212
|
* Union of all NotificationServicesController action types.
|
|
198
213
|
*/
|
|
199
|
-
export type NotificationServicesControllerMethodActions = NotificationServicesControllerInitAction | NotificationServicesControllerEnablePushNotificationsAction | NotificationServicesControllerDisablePushNotificationsAction | NotificationServicesControllerCheckAccountsPresenceAction | NotificationServicesControllerSetFeatureAnnouncementsEnabledAction | NotificationServicesControllerCreateOnChainTriggersAction | NotificationServicesControllerEnableMetamaskNotificationsAction | NotificationServicesControllerDisableNotificationServicesAction | NotificationServicesControllerDisableAccountsAction | NotificationServicesControllerEnableAccountsAction | NotificationServicesControllerFetchAndUpdateMetamaskNotificationsAction | NotificationServicesControllerGetNotificationsByTypeAction | NotificationServicesControllerDeleteNotificationByIdAction | NotificationServicesControllerDeleteNotificationsByIdAction | NotificationServicesControllerMarkMetamaskNotificationsAsReadAction | NotificationServicesControllerUpdateMetamaskNotificationsListAction | NotificationServicesControllerSendPerpPlaceOrderNotificationAction;
|
|
214
|
+
export type NotificationServicesControllerMethodActions = NotificationServicesControllerInitAction | NotificationServicesControllerEnablePushNotificationsAction | NotificationServicesControllerDisablePushNotificationsAction | NotificationServicesControllerCheckAccountsPresenceAction | NotificationServicesControllerSetFeatureAnnouncementsEnabledAction | NotificationServicesControllerCreateOnChainTriggersAction | NotificationServicesControllerEnableMetamaskNotificationsAction | NotificationServicesControllerDisableNotificationServicesAction | NotificationServicesControllerDisableAccountsAction | NotificationServicesControllerEnableAccountsAction | NotificationServicesControllerFetchAndUpdateMetamaskNotificationsAction | NotificationServicesControllerGetNotificationsByTypeAction | NotificationServicesControllerDeleteNotificationByIdAction | NotificationServicesControllerDeleteNotificationsByIdAction | NotificationServicesControllerMarkMetamaskNotificationsAsReadAction | NotificationServicesControllerUpdateMetamaskNotificationsListAction | NotificationServicesControllerSendPerpPlaceOrderNotificationAction | NotificationServicesControllerFetchMetamaskNotificationsCategoriesAction;
|
|
200
215
|
//# sourceMappingURL=NotificationServicesController-method-action-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationServicesController-method-action-types.d.ts","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAE1F,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,8BAA8B,CAAC,MAAM,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2DAA2D,GAAG;IACxE,IAAI,EAAE,wDAAwD,CAAC;IAC/D,OAAO,EAAE,8BAA8B,CAAC,yBAAyB,CAAC,CAAC;CACpE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4DAA4D,GAAG;IACzE,IAAI,EAAE,yDAAyD,CAAC;IAChE,OAAO,EAAE,8BAA8B,CAAC,0BAA0B,CAAC,CAAC;CACrE,CAAC;AAEF,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE,sDAAsD,CAAC;IAC7D,OAAO,EAAE,8BAA8B,CAAC,uBAAuB,CAAC,CAAC;CAClE,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,kEAAkE,GAC5E;IACE,IAAI,EAAE,+DAA+D,CAAC;IACtE,OAAO,EAAE,8BAA8B,CAAC,gCAAgC,CAAC,CAAC;CAC3E,CAAC;AAEJ;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,yDAAyD,GAAG;IACtE,IAAI,EAAE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AE,8BAA8B,CAAC,yBAAyB,CAAC,CAAC;CACpE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mEAAmE,GAC7E;IACE,IAAI,EAAE,gEAAgE,CAAC;IACvE,OAAO,EAAE,8BAA8B,CAAC,iCAAiC,CAAC,CAAC;CAC5E,CAAC;AAEJ;;;;;;GAMG;AACH,MAAM,MAAM,mEAAmE,GAC7E;IACE,IAAI,EAAE,gEAAgE,CAAC;IACvE,OAAO,EAAE,8BAA8B,CAAC,iCAAiC,CAAC,CAAC;CAC5E,CAAC;AAEJ;;;;;GAKG;AACH,MAAM,MAAM,kEAAkE,GAC5E;IACE,IAAI,EAAE,+DAA+D,CAAC;IACtE,OAAO,EAAE,8BAA8B,CAAC,gCAAgC,CAAC,CAAC;CAC3E,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,2CAA2C,GACnD,wCAAwC,GACxC,2DAA2D,GAC3D,4DAA4D,GAC5D,yDAAyD,GACzD,kEAAkE,GAClE,yDAAyD,GACzD,+DAA+D,GAC/D,+DAA+D,GAC/D,mDAAmD,GACnD,kDAAkD,GAClD,uEAAuE,GACvE,0DAA0D,GAC1D,0DAA0D,GAC1D,2DAA2D,GAC3D,mEAAmE,GACnE,mEAAmE,GACnE,kEAAkE,CAAC"}
|
|
1
|
+
{"version":3,"file":"NotificationServicesController-method-action-types.d.ts","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAE1F,MAAM,MAAM,wCAAwC,GAAG;IACrD,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,8BAA8B,CAAC,MAAM,CAAC,CAAC;CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2DAA2D,GAAG;IACxE,IAAI,EAAE,wDAAwD,CAAC;IAC/D,OAAO,EAAE,8BAA8B,CAAC,yBAAy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,GACxC,2DAA2D,GAC3D,4DAA4D,GAC5D,yDAAyD,GACzD,kEAAkE,GAClE,yDAAyD,GACzD,+DAA+D,GAC/D,+DAA+D,GAC/D,mDAAmD,GACnD,kDAAkD,GAClD,uEAAuE,GACvE,0DAA0D,GAC1D,0DAA0D,GAC1D,2DAA2D,GAC3D,mEAAmE,GACnE,mEAAmE,GACnE,kEAAkE,GAClE,wEAAwE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationServicesController-method-action-types.js","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NotificationServicesController } from './NotificationServicesController.js';\n\nexport type NotificationServicesControllerInitAction = {\n type: `NotificationServicesController:init`;\n handler: NotificationServicesController['init'];\n};\n\n/**\n * Public method to expose enabling push notifications\n */\nexport type NotificationServicesControllerEnablePushNotificationsAction = {\n type: `NotificationServicesController:enablePushNotifications`;\n handler: NotificationServicesController['enablePushNotifications'];\n};\n\n/**\n * Public method to expose disabling push notifications\n */\nexport type NotificationServicesControllerDisablePushNotificationsAction = {\n type: `NotificationServicesController:disablePushNotifications`;\n handler: NotificationServicesController['disablePushNotifications'];\n};\n\nexport type NotificationServicesControllerCheckAccountsPresenceAction = {\n type: `NotificationServicesController:checkAccountsPresence`;\n handler: NotificationServicesController['checkAccountsPresence'];\n};\n\n/**\n * Sets the enabled state of feature announcements.\n *\n * **Action** - used in the notification settings to enable/disable feature announcements.\n *\n * @param featureAnnouncementsEnabled - A boolean value indicating the desired enabled state of the feature announcements.\n * @async\n * @throws {Error} If fails to update\n */\nexport type NotificationServicesControllerSetFeatureAnnouncementsEnabledAction =\n {\n type: `NotificationServicesController:setFeatureAnnouncementsEnabled`;\n handler: NotificationServicesController['setFeatureAnnouncementsEnabled'];\n };\n\n/**\n * This creates/re-creates on-chain triggers defined in User Storage.\n *\n * **Action** - Used during Sign In / Enabling of notifications.\n *\n * Notification preferences are initialized only when\n * {@link AuthenticatedUserStorageService} has no stored preferences yet.\n * Existing preferences are left as-is.\n *\n * @param opts - optional options to mutate this functionality\n * @param opts.hasMarketingConsent - The user's marketing-consent flag.\n * Used only during initialization to seed marketing push notifications.\n * @param opts.productAnnouncementEnabled - The user's product-announcement flag.\n * Used only during initialization to seed marketing in-app notifications.\n * @param opts.registerPushNotifications - Whether to attempt FCM/device push registration.\n * @returns The updated or newly created user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerCreateOnChainTriggersAction = {\n type: `NotificationServicesController:createOnChainTriggers`;\n handler: NotificationServicesController['createOnChainTriggers'];\n};\n\n/**\n * Enables all MetaMask notifications for the user.\n * This is identical flow when initializing notifications for the first time.\n *\n * @param opts - Optional options to mutate this functionality.\n * @throws {Error} If there is an error during the process of enabling notifications.\n */\nexport type NotificationServicesControllerEnableMetamaskNotificationsAction = {\n type: `NotificationServicesController:enableMetamaskNotifications`;\n handler: NotificationServicesController['enableMetamaskNotifications'];\n};\n\n/**\n * Disables all MetaMask notifications for the user.\n * This method ensures that the user is authenticated, retrieves all linked accounts,\n * and disables on-chain triggers for each account. It also sets the global notification\n * settings for MetaMask, feature announcements to false.\n *\n * @throws {Error} If the user is not authenticated or if there is an error during the process.\n */\nexport type NotificationServicesControllerDisableNotificationServicesAction = {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: NotificationServicesController['disableNotificationServices'];\n};\n\n/**\n * Disables wallet-activity subscriptions for the given accounts.\n *\n * This only writes the Trigger API. The device's FCM links stay in place,\n * because those links deliver every notification source for an address.\n *\n * **Action** - When a user disables wallet activity for a given account.\n *\n * @param accounts - The accounts whose wallet-activity subscriptions are disabled.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerDisableAccountsAction = {\n type: `NotificationServicesController:disableAccounts`;\n handler: NotificationServicesController['disableAccounts'];\n};\n\n/**\n * Enables wallet-activity subscriptions for the given accounts.\n *\n * This only writes the Trigger API. Linking the device token is handled\n * when the account is added or when notifications are enabled.\n *\n * **Action** - When a user enables wallet activity for an account.\n *\n * @param accounts - List of accounts to subscribe.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerEnableAccountsAction = {\n type: `NotificationServicesController:enableAccounts`;\n handler: NotificationServicesController['enableAccounts'];\n};\n\n/**\n * Fetches the list of metamask notifications.\n * This includes OnChain notifications; Feature Announcements; and Snap Notifications.\n *\n * **Action** - When a user views the notification list page/dropdown\n *\n * @param previewToken - the preview token to use if needed\n * @returns A promise that resolves to the list of notifications.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerFetchAndUpdateMetamaskNotificationsAction =\n {\n type: `NotificationServicesController:fetchAndUpdateMetamaskNotifications`;\n handler: NotificationServicesController['fetchAndUpdateMetamaskNotifications'];\n };\n\n/**\n * Gets the specified type of notifications from state.\n *\n * @param type - The trigger type.\n * @returns An array of notifications of the passed in type.\n * @throws Throws an error if an invalid trigger type is passed.\n */\nexport type NotificationServicesControllerGetNotificationsByTypeAction = {\n type: `NotificationServicesController:getNotificationsByType`;\n handler: NotificationServicesController['getNotificationsByType'];\n};\n\n/**\n * Used to delete a notification by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param id - The id of the notification to delete.\n */\nexport type NotificationServicesControllerDeleteNotificationByIdAction = {\n type: `NotificationServicesController:deleteNotificationById`;\n handler: NotificationServicesController['deleteNotificationById'];\n};\n\n/**\n * Used to batch delete notifications by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param ids - The ids of the notifications to delete.\n */\nexport type NotificationServicesControllerDeleteNotificationsByIdAction = {\n type: `NotificationServicesController:deleteNotificationsById`;\n handler: NotificationServicesController['deleteNotificationsById'];\n};\n\n/**\n * Marks specified metamask notifications as read.\n *\n * @param notifications - An array of notifications to be marked as read. Each notification should include its type and read status.\n * @returns A promise that resolves when the operation is complete.\n */\nexport type NotificationServicesControllerMarkMetamaskNotificationsAsReadAction =\n {\n type: `NotificationServicesController:markMetamaskNotificationsAsRead`;\n handler: NotificationServicesController['markMetamaskNotificationsAsRead'];\n };\n\n/**\n * Updates the list of MetaMask notifications by adding a new notification at the beginning of the list.\n * This method ensures that the most recent notification is displayed first in the UI.\n *\n * @param notification - The new notification object to be added to the list.\n * @returns A promise that resolves when the notification list has been successfully updated.\n */\nexport type NotificationServicesControllerUpdateMetamaskNotificationsListAction =\n {\n type: `NotificationServicesController:updateMetamaskNotificationsList`;\n handler: NotificationServicesController['updateMetamaskNotificationsList'];\n };\n\n/**\n * Creates an perp order notification subscription.\n * Requires notifications and auth to be enabled to start receiving this notifications\n *\n * @param input perp input\n */\nexport type NotificationServicesControllerSendPerpPlaceOrderNotificationAction =\n {\n type: `NotificationServicesController:sendPerpPlaceOrderNotification`;\n handler: NotificationServicesController['sendPerpPlaceOrderNotification'];\n };\n\n/**\n * Union of all NotificationServicesController action types.\n */\nexport type NotificationServicesControllerMethodActions =\n | NotificationServicesControllerInitAction\n | NotificationServicesControllerEnablePushNotificationsAction\n | NotificationServicesControllerDisablePushNotificationsAction\n | NotificationServicesControllerCheckAccountsPresenceAction\n | NotificationServicesControllerSetFeatureAnnouncementsEnabledAction\n | NotificationServicesControllerCreateOnChainTriggersAction\n | NotificationServicesControllerEnableMetamaskNotificationsAction\n | NotificationServicesControllerDisableNotificationServicesAction\n | NotificationServicesControllerDisableAccountsAction\n | NotificationServicesControllerEnableAccountsAction\n | NotificationServicesControllerFetchAndUpdateMetamaskNotificationsAction\n | NotificationServicesControllerGetNotificationsByTypeAction\n | NotificationServicesControllerDeleteNotificationByIdAction\n | NotificationServicesControllerDeleteNotificationsByIdAction\n | NotificationServicesControllerMarkMetamaskNotificationsAsReadAction\n | NotificationServicesControllerUpdateMetamaskNotificationsListAction\n | NotificationServicesControllerSendPerpPlaceOrderNotificationAction;\n"]}
|
|
1
|
+
{"version":3,"file":"NotificationServicesController-method-action-types.js","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NotificationServicesController } from './NotificationServicesController.js';\n\nexport type NotificationServicesControllerInitAction = {\n type: `NotificationServicesController:init`;\n handler: NotificationServicesController['init'];\n};\n\n/**\n * Public method to expose enabling push notifications\n */\nexport type NotificationServicesControllerEnablePushNotificationsAction = {\n type: `NotificationServicesController:enablePushNotifications`;\n handler: NotificationServicesController['enablePushNotifications'];\n};\n\n/**\n * Public method to expose disabling push notifications\n */\nexport type NotificationServicesControllerDisablePushNotificationsAction = {\n type: `NotificationServicesController:disablePushNotifications`;\n handler: NotificationServicesController['disablePushNotifications'];\n};\n\nexport type NotificationServicesControllerCheckAccountsPresenceAction = {\n type: `NotificationServicesController:checkAccountsPresence`;\n handler: NotificationServicesController['checkAccountsPresence'];\n};\n\n/**\n * Sets the enabled state of feature announcements.\n *\n * **Action** - used in the notification settings to enable/disable feature announcements.\n *\n * @param featureAnnouncementsEnabled - A boolean value indicating the desired enabled state of the feature announcements.\n * @async\n * @throws {Error} If fails to update\n */\nexport type NotificationServicesControllerSetFeatureAnnouncementsEnabledAction =\n {\n type: `NotificationServicesController:setFeatureAnnouncementsEnabled`;\n handler: NotificationServicesController['setFeatureAnnouncementsEnabled'];\n };\n\n/**\n * This creates/re-creates on-chain triggers defined in User Storage.\n *\n * **Action** - Used during Sign In / Enabling of notifications.\n *\n * Notification preferences are initialized only when\n * {@link AuthenticatedUserStorageService} has no stored preferences yet.\n * Existing preferences are left as-is.\n *\n * @param opts - optional options to mutate this functionality\n * @param opts.hasMarketingConsent - The user's marketing-consent flag.\n * Used only during initialization to seed marketing push notifications.\n * @param opts.productAnnouncementEnabled - The user's product-announcement flag.\n * Used only during initialization to seed marketing in-app notifications.\n * @param opts.registerPushNotifications - Whether to attempt FCM/device push registration.\n * @returns The updated or newly created user storage.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerCreateOnChainTriggersAction = {\n type: `NotificationServicesController:createOnChainTriggers`;\n handler: NotificationServicesController['createOnChainTriggers'];\n};\n\n/**\n * Enables all MetaMask notifications for the user.\n * This is identical flow when initializing notifications for the first time.\n *\n * @param opts - Optional options to mutate this functionality.\n * @throws {Error} If there is an error during the process of enabling notifications.\n */\nexport type NotificationServicesControllerEnableMetamaskNotificationsAction = {\n type: `NotificationServicesController:enableMetamaskNotifications`;\n handler: NotificationServicesController['enableMetamaskNotifications'];\n};\n\n/**\n * Disables all MetaMask notifications for the user.\n * This method ensures that the user is authenticated, retrieves all linked accounts,\n * and disables on-chain triggers for each account. It also sets the global notification\n * settings for MetaMask, feature announcements to false.\n *\n * @throws {Error} If the user is not authenticated or if there is an error during the process.\n */\nexport type NotificationServicesControllerDisableNotificationServicesAction = {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: NotificationServicesController['disableNotificationServices'];\n};\n\n/**\n * Disables wallet-activity subscriptions for the given accounts.\n *\n * This only writes the Trigger API. The device's FCM links stay in place,\n * because those links deliver every notification source for an address.\n *\n * **Action** - When a user disables wallet activity for a given account.\n *\n * @param accounts - The accounts whose wallet-activity subscriptions are disabled.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerDisableAccountsAction = {\n type: `NotificationServicesController:disableAccounts`;\n handler: NotificationServicesController['disableAccounts'];\n};\n\n/**\n * Enables wallet-activity subscriptions for the given accounts.\n *\n * This only writes the Trigger API. Linking the device token is handled\n * when the account is added or when notifications are enabled.\n *\n * **Action** - When a user enables wallet activity for an account.\n *\n * @param accounts - List of accounts to subscribe.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerEnableAccountsAction = {\n type: `NotificationServicesController:enableAccounts`;\n handler: NotificationServicesController['enableAccounts'];\n};\n\n/**\n * Fetches the list of metamask notifications.\n * This includes OnChain notifications; Feature Announcements; and Snap Notifications.\n *\n * **Action** - When a user views the notification list page/dropdown\n *\n * @param previewToken - the preview token to use if needed\n * @returns A promise that resolves to the list of notifications.\n * @throws {Error} Throws an error if unauthenticated or from other operations.\n */\nexport type NotificationServicesControllerFetchAndUpdateMetamaskNotificationsAction =\n {\n type: `NotificationServicesController:fetchAndUpdateMetamaskNotifications`;\n handler: NotificationServicesController['fetchAndUpdateMetamaskNotifications'];\n };\n\n/**\n * Gets the specified type of notifications from state.\n *\n * @param type - The trigger type.\n * @returns An array of notifications of the passed in type.\n * @throws Throws an error if an invalid trigger type is passed.\n */\nexport type NotificationServicesControllerGetNotificationsByTypeAction = {\n type: `NotificationServicesController:getNotificationsByType`;\n handler: NotificationServicesController['getNotificationsByType'];\n};\n\n/**\n * Used to delete a notification by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param id - The id of the notification to delete.\n */\nexport type NotificationServicesControllerDeleteNotificationByIdAction = {\n type: `NotificationServicesController:deleteNotificationById`;\n handler: NotificationServicesController['deleteNotificationById'];\n};\n\n/**\n * Used to batch delete notifications by id.\n *\n * Note: This function should only be used for notifications that are stored\n * in this controller directly, currently only snaps notifications.\n *\n * @param ids - The ids of the notifications to delete.\n */\nexport type NotificationServicesControllerDeleteNotificationsByIdAction = {\n type: `NotificationServicesController:deleteNotificationsById`;\n handler: NotificationServicesController['deleteNotificationsById'];\n};\n\n/**\n * Marks specified metamask notifications as read.\n *\n * @param notifications - An array of notifications to be marked as read. Each notification should include its type and read status.\n * @returns A promise that resolves when the operation is complete.\n */\nexport type NotificationServicesControllerMarkMetamaskNotificationsAsReadAction =\n {\n type: `NotificationServicesController:markMetamaskNotificationsAsRead`;\n handler: NotificationServicesController['markMetamaskNotificationsAsRead'];\n };\n\n/**\n * Updates the list of MetaMask notifications by adding a new notification at the beginning of the list.\n * This method ensures that the most recent notification is displayed first in the UI.\n *\n * @param notification - The new notification object to be added to the list.\n * @returns A promise that resolves when the notification list has been successfully updated.\n */\nexport type NotificationServicesControllerUpdateMetamaskNotificationsListAction =\n {\n type: `NotificationServicesController:updateMetamaskNotificationsList`;\n handler: NotificationServicesController['updateMetamaskNotificationsList'];\n };\n\n/**\n * Creates an perp order notification subscription.\n * Requires notifications and auth to be enabled to start receiving this notifications\n *\n * @param input perp input\n */\nexport type NotificationServicesControllerSendPerpPlaceOrderNotificationAction =\n {\n type: `NotificationServicesController:sendPerpPlaceOrderNotification`;\n handler: NotificationServicesController['sendPerpPlaceOrderNotification'];\n };\n\n/**\n * Fetches the list of MetaMask notification categories from the notifications API,\n * stores the result in controller state, and returns the categories.\n *\n * This method sets the categories-loading flag while the request is in flight\n * so the UI can reflect the loading state. If the request fails, it logs the\n * error and throws a generic failure error.\n *\n * @returns A promise that resolves to the fetched notification categories.\n * @throws {Error} If the categories request fails.\n */\nexport type NotificationServicesControllerFetchMetamaskNotificationsCategoriesAction =\n {\n type: `NotificationServicesController:fetchMetamaskNotificationsCategories`;\n handler: NotificationServicesController['fetchMetamaskNotificationsCategories'];\n };\n\n/**\n * Union of all NotificationServicesController action types.\n */\nexport type NotificationServicesControllerMethodActions =\n | NotificationServicesControllerInitAction\n | NotificationServicesControllerEnablePushNotificationsAction\n | NotificationServicesControllerDisablePushNotificationsAction\n | NotificationServicesControllerCheckAccountsPresenceAction\n | NotificationServicesControllerSetFeatureAnnouncementsEnabledAction\n | NotificationServicesControllerCreateOnChainTriggersAction\n | NotificationServicesControllerEnableMetamaskNotificationsAction\n | NotificationServicesControllerDisableNotificationServicesAction\n | NotificationServicesControllerDisableAccountsAction\n | NotificationServicesControllerEnableAccountsAction\n | NotificationServicesControllerFetchAndUpdateMetamaskNotificationsAction\n | NotificationServicesControllerGetNotificationsByTypeAction\n | NotificationServicesControllerDeleteNotificationByIdAction\n | NotificationServicesControllerDeleteNotificationsByIdAction\n | NotificationServicesControllerMarkMetamaskNotificationsAsReadAction\n | NotificationServicesControllerUpdateMetamaskNotificationsListAction\n | NotificationServicesControllerSendPerpPlaceOrderNotificationAction\n | NotificationServicesControllerFetchMetamaskNotificationsCategoriesAction;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AuthenticatedUserStorageServiceGetNotificationPreferencesAction, AuthenticatedUserStorageServicePutNotificationPreferencesAction, PerpsPreference, SocialAIPreference } from '@metamask/authenticated-user-storage';
|
|
2
|
-
import type { ControllerGetStateAction,
|
|
2
|
+
import type { ControllerGetStateAction, ControllerStateChangedEvent } from '@metamask/base-controller';
|
|
3
3
|
import { BaseController } from '@metamask/base-controller';
|
|
4
4
|
import type { KeyringControllerStateChangeEvent, KeyringControllerGetStateAction, KeyringControllerLockEvent, KeyringControllerUnlockEvent } from '@metamask/keyring-controller';
|
|
5
5
|
import type { Messenger } from '@metamask/messenger';
|
|
@@ -7,6 +7,7 @@ import type { AuthenticationController } from '@metamask/profile-sync-controller
|
|
|
7
7
|
import type { NotificationServicesPushControllerStateChangeEvent, NotificationServicesPushControllerOnNewNotificationEvent } from '../NotificationServicesPushController/index.js';
|
|
8
8
|
import type { NotificationServicesPushControllerMethodActions } from '../NotificationServicesPushController/NotificationServicesPushController-method-action-types.js';
|
|
9
9
|
import { TRIGGER_TYPES } from './constants/notification-schema.js';
|
|
10
|
+
import type { NotificationsCategory } from './index.js';
|
|
10
11
|
import type { NotificationServicesControllerMethodActions } from './NotificationServicesController-method-action-types.js';
|
|
11
12
|
import type { ENV } from './services/api-notifications.js';
|
|
12
13
|
import type { INotification, MarkAsReadNotificationsParam } from './types/notification/notification.js';
|
|
@@ -42,6 +43,10 @@ export type NotificationServicesControllerState = {
|
|
|
42
43
|
* List of read metamask notifications
|
|
43
44
|
*/
|
|
44
45
|
metamaskNotificationsReadList: string[];
|
|
46
|
+
/**
|
|
47
|
+
* List of notification categories
|
|
48
|
+
*/
|
|
49
|
+
metamaskNotificationsCategories: NotificationsCategory[];
|
|
45
50
|
/**
|
|
46
51
|
* Flag that indicates that the creating notifications is in progress
|
|
47
52
|
*/
|
|
@@ -52,6 +57,11 @@ export type NotificationServicesControllerState = {
|
|
|
52
57
|
* when fetching notifications
|
|
53
58
|
*/
|
|
54
59
|
isFetchingMetamaskNotifications: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Flag that indicates that fetching notification categories
|
|
62
|
+
* is in progress. Used for readiness checks for categories consumers
|
|
63
|
+
*/
|
|
64
|
+
isFetchingMetamaskNotificationsCategories: boolean;
|
|
55
65
|
/**
|
|
56
66
|
* Flag that indicates that the updating notifications for a specific address is in progress
|
|
57
67
|
*/
|
|
@@ -100,7 +110,7 @@ export { DEFAULT_AGENTIC_CLI_PREFERENCES, DEFAULT_PRICE_ALERT_PREFERENCES, } fro
|
|
|
100
110
|
export type NotificationServicesControllerGetStateAction = ControllerGetStateAction<typeof controllerName, NotificationServicesControllerState>;
|
|
101
111
|
export type Actions = NotificationServicesControllerGetStateAction | NotificationServicesControllerMethodActions;
|
|
102
112
|
type AllowedActions = KeyringControllerGetStateAction | AuthenticationController.AuthenticationControllerGetBearerTokenAction | AuthenticationController.AuthenticationControllerIsSignedInAction | AuthenticationController.AuthenticationControllerPerformSignInAction | AuthenticatedUserStorageServiceGetNotificationPreferencesAction | AuthenticatedUserStorageServicePutNotificationPreferencesAction | NotificationServicesPushControllerMethodActions;
|
|
103
|
-
export type NotificationServicesControllerStateChangeEvent =
|
|
113
|
+
export type NotificationServicesControllerStateChangeEvent = ControllerStateChangedEvent<typeof controllerName, NotificationServicesControllerState>;
|
|
104
114
|
export type NotificationListUpdatedEvent = {
|
|
105
115
|
type: `${typeof controllerName}:notificationsListUpdated`;
|
|
106
116
|
payload: [INotification[]];
|
|
@@ -282,5 +292,17 @@ export declare class NotificationServicesController extends BaseController<typeo
|
|
|
282
292
|
* @param input perp input
|
|
283
293
|
*/
|
|
284
294
|
sendPerpPlaceOrderNotification(input: OrderInput): Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Fetches the list of MetaMask notification categories from the notifications API,
|
|
297
|
+
* stores the result in controller state, and returns the categories.
|
|
298
|
+
*
|
|
299
|
+
* This method sets the categories-loading flag while the request is in flight
|
|
300
|
+
* so the UI can reflect the loading state. If the request fails, it logs the
|
|
301
|
+
* error and throws a generic failure error.
|
|
302
|
+
*
|
|
303
|
+
* @returns A promise that resolves to the fetched notification categories.
|
|
304
|
+
* @throws {Error} If the categories request fails.
|
|
305
|
+
*/
|
|
306
|
+
fetchMetamaskNotificationsCategories(): Promise<NotificationsCategory[]>;
|
|
285
307
|
}
|
|
286
308
|
//# sourceMappingURL=NotificationServicesController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationServicesController.d.ts","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,+DAA+D,EAC/D,+DAA+D,EAE/D,eAAe,EACf,kBAAkB,EACnB,MAAM,sCAAsC,CAAC;AAK9C,OAAO,KAAK,EACV,wBAAwB,EACxB,
|
|
1
|
+
{"version":3,"file":"NotificationServicesController.d.ts","sourceRoot":"","sources":["../../src/NotificationServicesController/NotificationServicesController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,+DAA+D,EAC/D,+DAA+D,EAE/D,eAAe,EACf,kBAAkB,EACnB,MAAM,sCAAsC,CAAC;AAK9C,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAK3D,OAAO,KAAK,EACV,iCAAiC,EACjC,+BAA+B,EAC/B,0BAA0B,EAC1B,4BAA4B,EAE7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAKlF,OAAO,KAAK,EAC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7 +6,7 @@ import { debounce } from 'lodash-es';
|
|
|
6
6
|
import log from 'loglevel';
|
|
7
7
|
import { TRIGGER_TYPES } from './constants/notification-schema.js';
|
|
8
8
|
import { processAndFilterNotifications, safeProcessNotification, } from './processors/process-notifications.js';
|
|
9
|
-
import { getAPINotifications, getNotificationsApiConfigCached, markNotificationsAsRead, updateOnChainNotifications, } from './services/api-notifications.js';
|
|
9
|
+
import { getAPINotifications, getNotificationsApiConfigCached, getNotificationsCategories, markNotificationsAsRead, updateOnChainNotifications, } from './services/api-notifications.js';
|
|
10
10
|
import { getFeatureAnnouncementNotifications } from './services/feature-announcements.js';
|
|
11
11
|
import { createPerpOrderNotification } from './services/perp-notifications.js';
|
|
12
12
|
// Unique name for the controller
|
|
@@ -49,6 +49,12 @@ const metadata = {
|
|
|
49
49
|
includeInDebugSnapshot: true,
|
|
50
50
|
usedInUi: true,
|
|
51
51
|
},
|
|
52
|
+
metamaskNotificationsCategories: {
|
|
53
|
+
includeInStateLogs: true,
|
|
54
|
+
persist: true,
|
|
55
|
+
includeInDebugSnapshot: true,
|
|
56
|
+
usedInUi: true,
|
|
57
|
+
},
|
|
52
58
|
isUpdatingMetamaskNotifications: {
|
|
53
59
|
includeInStateLogs: false,
|
|
54
60
|
persist: false,
|
|
@@ -73,6 +79,12 @@ const metadata = {
|
|
|
73
79
|
includeInDebugSnapshot: false,
|
|
74
80
|
usedInUi: true,
|
|
75
81
|
},
|
|
82
|
+
isFetchingMetamaskNotificationsCategories: {
|
|
83
|
+
includeInStateLogs: false,
|
|
84
|
+
persist: false,
|
|
85
|
+
includeInDebugSnapshot: false,
|
|
86
|
+
usedInUi: true,
|
|
87
|
+
},
|
|
76
88
|
};
|
|
77
89
|
export const defaultState = {
|
|
78
90
|
subscriptionAccountsSeen: [],
|
|
@@ -81,10 +93,12 @@ export const defaultState = {
|
|
|
81
93
|
isFeatureAnnouncementsEnabled: false,
|
|
82
94
|
metamaskNotificationsList: [],
|
|
83
95
|
metamaskNotificationsReadList: [],
|
|
96
|
+
metamaskNotificationsCategories: [],
|
|
84
97
|
isUpdatingMetamaskNotifications: false,
|
|
85
98
|
isFetchingMetamaskNotifications: false,
|
|
86
99
|
isUpdatingMetamaskNotificationsAccount: [],
|
|
87
100
|
isCheckingAccountsPresence: false,
|
|
101
|
+
isFetchingMetamaskNotificationsCategories: false,
|
|
88
102
|
};
|
|
89
103
|
const locallyPersistedNotificationTypes = new Set([
|
|
90
104
|
TRIGGER_TYPES.SNAP,
|
|
@@ -172,6 +186,7 @@ const MESSENGER_EXPOSED_METHODS = [
|
|
|
172
186
|
'disableAccounts',
|
|
173
187
|
'enableAccounts',
|
|
174
188
|
'fetchAndUpdateMetamaskNotifications',
|
|
189
|
+
'fetchMetamaskNotificationsCategories',
|
|
175
190
|
'getNotificationsByType',
|
|
176
191
|
'deleteNotificationById',
|
|
177
192
|
'deleteNotificationsById',
|
|
@@ -558,6 +573,20 @@ export class NotificationServicesController extends BaseController {
|
|
|
558
573
|
state.isUpdatingMetamaskNotificationsAccount.filter((existingAccount) => !accounts.includes(existingAccount));
|
|
559
574
|
});
|
|
560
575
|
}
|
|
576
|
+
/**
|
|
577
|
+
* Updates the state to indicate whether fetching of MetaMask notification categories is in progress.
|
|
578
|
+
*
|
|
579
|
+
* This method is used to set the `isFetchingMetamaskNotificationsCategories` state, which can be utilized
|
|
580
|
+
* to show or hide loading indicators in the UI when notifications categories are being fetched.
|
|
581
|
+
*
|
|
582
|
+
* @param isFetchingNotificationCategories - A boolean value representing the fetching state.
|
|
583
|
+
*/
|
|
584
|
+
#setIsFetchingNotificationsCategories(isFetchingNotificationCategories) {
|
|
585
|
+
this.update((state) => {
|
|
586
|
+
state.isFetchingMetamaskNotificationsCategories =
|
|
587
|
+
isFetchingNotificationCategories;
|
|
588
|
+
});
|
|
589
|
+
}
|
|
561
590
|
/**
|
|
562
591
|
* Public method to expose enabling push notifications
|
|
563
592
|
*/
|
|
@@ -1058,5 +1087,33 @@ export class NotificationServicesController extends BaseController {
|
|
|
1058
1087
|
// Do Nothing
|
|
1059
1088
|
}
|
|
1060
1089
|
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Fetches the list of MetaMask notification categories from the notifications API,
|
|
1092
|
+
* stores the result in controller state, and returns the categories.
|
|
1093
|
+
*
|
|
1094
|
+
* This method sets the categories-loading flag while the request is in flight
|
|
1095
|
+
* so the UI can reflect the loading state. If the request fails, it logs the
|
|
1096
|
+
* error and throws a generic failure error.
|
|
1097
|
+
*
|
|
1098
|
+
* @returns A promise that resolves to the fetched notification categories.
|
|
1099
|
+
* @throws {Error} If the categories request fails.
|
|
1100
|
+
*/
|
|
1101
|
+
async fetchMetamaskNotificationsCategories() {
|
|
1102
|
+
this.#setIsFetchingNotificationsCategories(true);
|
|
1103
|
+
try {
|
|
1104
|
+
const categories = await getNotificationsCategories();
|
|
1105
|
+
this.update((state) => {
|
|
1106
|
+
state.metamaskNotificationsCategories = categories;
|
|
1107
|
+
});
|
|
1108
|
+
return categories;
|
|
1109
|
+
}
|
|
1110
|
+
catch (error) {
|
|
1111
|
+
log.error('Failed to fetch notifications categories', error);
|
|
1112
|
+
throw new Error('Failed to fetch notifications categories');
|
|
1113
|
+
}
|
|
1114
|
+
finally {
|
|
1115
|
+
this.#setIsFetchingNotificationsCategories(false);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1061
1118
|
}
|
|
1062
1119
|
//# sourceMappingURL=NotificationServicesController.js.map
|