@metamask-previews/notification-services-controller 10.0.0-preview-5dcecbb7 → 10.0.0-preview-8dfa2801

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.
Files changed (160) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +76 -188
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +10 -16
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +10 -16
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +77 -189
  9. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  10. package/dist/NotificationServicesController/constants/index.cjs +0 -1
  11. package/dist/NotificationServicesController/constants/index.cjs.map +1 -1
  12. package/dist/NotificationServicesController/constants/index.d.cts +0 -1
  13. package/dist/NotificationServicesController/constants/index.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/constants/index.d.mts +0 -1
  15. package/dist/NotificationServicesController/constants/index.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/constants/index.mjs +0 -1
  17. package/dist/NotificationServicesController/constants/index.mjs.map +1 -1
  18. package/dist/NotificationServicesController/constants/notification-schema.cjs +1 -0
  19. package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
  20. package/dist/NotificationServicesController/constants/notification-schema.d.cts +1 -0
  21. package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
  22. package/dist/NotificationServicesController/constants/notification-schema.d.mts +1 -0
  23. package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
  24. package/dist/NotificationServicesController/constants/notification-schema.mjs +1 -0
  25. package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
  26. package/dist/NotificationServicesController/mocks/index.cjs +0 -2
  27. package/dist/NotificationServicesController/mocks/index.cjs.map +1 -1
  28. package/dist/NotificationServicesController/mocks/index.d.cts +0 -2
  29. package/dist/NotificationServicesController/mocks/index.d.cts.map +1 -1
  30. package/dist/NotificationServicesController/mocks/index.d.mts +0 -2
  31. package/dist/NotificationServicesController/mocks/index.d.mts.map +1 -1
  32. package/dist/NotificationServicesController/mocks/index.mjs +0 -2
  33. package/dist/NotificationServicesController/mocks/index.mjs.map +1 -1
  34. package/dist/NotificationServicesController/mocks/mockResponses.cjs +9 -9
  35. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  36. package/dist/NotificationServicesController/mocks/mockResponses.d.cts +7 -4
  37. package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
  38. package/dist/NotificationServicesController/mocks/mockResponses.d.mts +7 -4
  39. package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
  40. package/dist/NotificationServicesController/mocks/mockResponses.mjs +7 -7
  41. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  42. package/dist/NotificationServicesController/processors/process-notifications.cjs +4 -1
  43. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  44. package/dist/NotificationServicesController/processors/process-notifications.d.cts +623 -0
  45. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  46. package/dist/NotificationServicesController/processors/process-notifications.d.mts +623 -0
  47. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  48. package/dist/NotificationServicesController/processors/process-notifications.mjs +2 -0
  49. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  50. package/dist/NotificationServicesController/services/notification-config-cache.cjs +72 -0
  51. package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -0
  52. package/dist/NotificationServicesController/services/notification-config-cache.d.cts +19 -0
  53. package/dist/NotificationServicesController/services/notification-config-cache.d.cts.map +1 -0
  54. package/dist/NotificationServicesController/services/notification-config-cache.d.mts +19 -0
  55. package/dist/NotificationServicesController/services/notification-config-cache.d.mts.map +1 -0
  56. package/dist/NotificationServicesController/services/notification-config-cache.mjs +68 -0
  57. package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -0
  58. package/dist/NotificationServicesController/services/onchain-notifications.cjs +67 -140
  59. package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
  60. package/dist/NotificationServicesController/services/onchain-notifications.d.cts +25 -31
  61. package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
  62. package/dist/NotificationServicesController/services/onchain-notifications.d.mts +25 -31
  63. package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
  64. package/dist/NotificationServicesController/services/onchain-notifications.mjs +65 -137
  65. package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +1 -1
  66. package/dist/NotificationServicesController/types/index.cjs.map +1 -1
  67. package/dist/NotificationServicesController/types/index.d.cts +0 -1
  68. package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
  69. package/dist/NotificationServicesController/types/index.d.mts +0 -1
  70. package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
  71. package/dist/NotificationServicesController/types/index.mjs.map +1 -1
  72. package/dist/NotificationServicesController/ui/constants.cjs +6 -0
  73. package/dist/NotificationServicesController/ui/constants.cjs.map +1 -1
  74. package/dist/NotificationServicesController/ui/constants.d.cts +6 -0
  75. package/dist/NotificationServicesController/ui/constants.d.cts.map +1 -1
  76. package/dist/NotificationServicesController/ui/constants.d.mts +6 -0
  77. package/dist/NotificationServicesController/ui/constants.d.mts.map +1 -1
  78. package/dist/NotificationServicesController/ui/constants.mjs +6 -0
  79. package/dist/NotificationServicesController/ui/constants.mjs.map +1 -1
  80. package/dist/NotificationServicesController/utils/utils.cjs +1 -350
  81. package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
  82. package/dist/NotificationServicesController/utils/utils.d.cts +0 -141
  83. package/dist/NotificationServicesController/utils/utils.d.cts.map +1 -1
  84. package/dist/NotificationServicesController/utils/utils.d.mts +0 -141
  85. package/dist/NotificationServicesController/utils/utils.d.mts.map +1 -1
  86. package/dist/NotificationServicesController/utils/utils.mjs +0 -337
  87. package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
  88. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +22 -15
  89. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  90. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +6 -5
  91. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  92. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +6 -5
  93. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  94. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +23 -16
  95. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  96. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +1 -16
  97. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
  98. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +0 -7
  99. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
  100. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +0 -7
  101. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
  102. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +0 -14
  103. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
  104. package/dist/NotificationServicesPushController/services/endpoints.cjs +1 -1
  105. package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
  106. package/dist/NotificationServicesPushController/services/endpoints.d.cts +1 -1
  107. package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
  108. package/dist/NotificationServicesPushController/services/endpoints.d.mts +1 -1
  109. package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
  110. package/dist/NotificationServicesPushController/services/endpoints.mjs +1 -1
  111. package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
  112. package/dist/NotificationServicesPushController/services/services.cjs +18 -41
  113. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  114. package/dist/NotificationServicesPushController/services/services.d.cts +19 -33
  115. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  116. package/dist/NotificationServicesPushController/services/services.d.mts +19 -33
  117. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  118. package/dist/NotificationServicesPushController/services/services.mjs +17 -39
  119. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  120. package/package.json +1 -1
  121. package/dist/NotificationServicesController/constants/constants.cjs +0 -7
  122. package/dist/NotificationServicesController/constants/constants.cjs.map +0 -1
  123. package/dist/NotificationServicesController/constants/constants.d.cts +0 -3
  124. package/dist/NotificationServicesController/constants/constants.d.cts.map +0 -1
  125. package/dist/NotificationServicesController/constants/constants.d.mts +0 -3
  126. package/dist/NotificationServicesController/constants/constants.d.mts.map +0 -1
  127. package/dist/NotificationServicesController/constants/constants.mjs +0 -4
  128. package/dist/NotificationServicesController/constants/constants.mjs.map +0 -1
  129. package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs +0 -22
  130. package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs.map +0 -1
  131. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts +0 -9
  132. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts.map +0 -1
  133. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts +0 -9
  134. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts.map +0 -1
  135. package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs +0 -18
  136. package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs.map +0 -1
  137. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs +0 -82
  138. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs.map +0 -1
  139. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts +0 -35
  140. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts.map +0 -1
  141. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts +0 -35
  142. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts.map +0 -1
  143. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs +0 -76
  144. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs.map +0 -1
  145. package/dist/NotificationServicesController/types/user-storage/index.cjs +0 -3
  146. package/dist/NotificationServicesController/types/user-storage/index.cjs.map +0 -1
  147. package/dist/NotificationServicesController/types/user-storage/index.d.cts +0 -2
  148. package/dist/NotificationServicesController/types/user-storage/index.d.cts.map +0 -1
  149. package/dist/NotificationServicesController/types/user-storage/index.d.mts +0 -2
  150. package/dist/NotificationServicesController/types/user-storage/index.d.mts.map +0 -1
  151. package/dist/NotificationServicesController/types/user-storage/index.mjs +0 -2
  152. package/dist/NotificationServicesController/types/user-storage/index.mjs.map +0 -1
  153. package/dist/NotificationServicesController/types/user-storage/user-storage.cjs +0 -3
  154. package/dist/NotificationServicesController/types/user-storage/user-storage.cjs.map +0 -1
  155. package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts +0 -26
  156. package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts.map +0 -1
  157. package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts +0 -26
  158. package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts.map +0 -1
  159. package/dist/NotificationServicesController/types/user-storage/user-storage.mjs +0 -2
  160. package/dist/NotificationServicesController/types/user-storage/user-storage.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -9,8 +9,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
+ - **BREAKING:** Migrated to notification v2 endpoints ([#5945](https://github.com/MetaMask/core/pull/5945))
13
+
14
+ - `https://trigger.api.cx.metamask.io/api/v2` for managing out notification subscriptions
15
+ - `https://notification.api.cx.metamask.io/api/v2` for fetching notifications (in-app notifications)
16
+ - `https://push.api.cx.metamask.io/v2` for subscribing push notifications
17
+ - Renamed method `updateOnChainTriggersByAccount` to `enableAccounts` in `NotificationServicesController`
18
+ - Renamed method `deleteOnChainTriggersByAccount` to `disableAccounts` in `NotificationServicesController`
19
+ - Deprecated `updateTriggerPushNotifications` from `NotificationServicesPushController` and will be removed in a subsequent release.
20
+
12
21
  - Bump `@metamask/controller-utils` to `^11.10.0` ([#5935](https://github.com/MetaMask/core/pull/5935))
13
22
 
23
+ ### Removed
24
+
25
+ - **BREAKING:** Migrated to notification v2 endpoints ([#5945](https://github.com/MetaMask/core/pull/5945))
26
+
27
+ - removed `NotificationServicesPushController:updateTriggerPushNotifications` action from `NotificationServicesController`
28
+ - removed `UserStorageController:getStorageKey` action from `NotificationServicesController`
29
+ - removed `UserStorageController:performGetStorage` action from `NotificationServicesController`
30
+ - removed `UserStorageController:performSetStorage` action from `NotificationServicesController`
31
+
14
32
  ## [10.0.0]
15
33
 
16
34
  ### Changed
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_storage, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getValidStorageKeyAndBearerToken, _NotificationServicesController_assertUserStorage, _NotificationServicesController_getUserStorage, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
39
+ var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getBearerToken, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.defaultState = void 0;
42
42
  const base_controller_1 = require("@metamask/base-controller");
@@ -44,12 +44,10 @@ const controller_utils_1 = require("@metamask/controller-utils");
44
44
  const keyring_controller_1 = require("@metamask/keyring-controller");
45
45
  const utils_1 = require("@metamask/utils");
46
46
  const loglevel_1 = __importDefault(require("loglevel"));
47
- const constants_1 = require("./constants/constants.cjs");
48
47
  const notification_schema_1 = require("./constants/notification-schema.cjs");
49
48
  const process_notifications_1 = require("./processors/process-notifications.cjs");
50
49
  const FeatureNotifications = __importStar(require("./services/feature-announcements.cjs"));
51
50
  const OnChainNotifications = __importStar(require("./services/onchain-notifications.cjs"));
52
- const Utils = __importStar(require("./utils/utils.cjs"));
53
51
  // Unique name for the controller
54
52
  const controllerName = 'NotificationServicesController';
55
53
  const metadata = {
@@ -159,17 +157,6 @@ class NotificationServicesController extends base_controller_1.BaseController {
159
157
  return await this.messagingSystem.call('AuthenticationController:performSignIn');
160
158
  },
161
159
  });
162
- _NotificationServicesController_storage.set(this, {
163
- getStorageKey: () => {
164
- return this.messagingSystem.call('UserStorageController:getStorageKey');
165
- },
166
- getNotificationStorage: async () => {
167
- return await this.messagingSystem.call('UserStorageController:performGetStorage', 'notifications.notification_settings');
168
- },
169
- setNotificationStorage: async (state) => {
170
- return await this.messagingSystem.call('UserStorageController:performSetStorage', 'notifications.notification_settings', state);
171
- },
172
- });
173
160
  _NotificationServicesController_pushNotifications.set(this, {
174
161
  // Flag to check is notifications have been setup when the browser/extension is initialized.
175
162
  // We want to re-initialize push notifications when the browser/extension is refreshed
@@ -178,9 +165,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
178
165
  subscribeToPushNotifications: async () => {
179
166
  await this.messagingSystem.call('NotificationServicesPushController:subscribeToPushNotifications');
180
167
  },
181
- enablePushNotifications: async (UUIDs) => {
168
+ enablePushNotifications: async (addresses) => {
182
169
  try {
183
- await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications', UUIDs);
170
+ await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications', addresses);
184
171
  }
185
172
  catch (e) {
186
173
  loglevel_1.default.error('Silently failed to enable push notifications', e);
@@ -194,14 +181,6 @@ class NotificationServicesController extends base_controller_1.BaseController {
194
181
  loglevel_1.default.error('Silently failed to disable push notifications', e);
195
182
  }
196
183
  },
197
- updatePushNotifications: async (UUIDs) => {
198
- try {
199
- await this.messagingSystem.call('NotificationServicesPushController:updateTriggerPushNotifications', UUIDs);
200
- }
201
- catch (e) {
202
- loglevel_1.default.error('Silently failed to update push notifications', e);
203
- }
204
- },
205
184
  subscribe: () => {
206
185
  this.messagingSystem.subscribe('NotificationServicesPushController:onNewNotifications', (notification) => {
207
186
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -236,7 +215,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
236
215
  _NotificationServicesController_accounts.set(this, {
237
216
  // Flag to ensure we only setup once
238
217
  isNotificationAccountsSetup: false,
239
- getNotificationAccounts: async () => {
218
+ getNotificationAccounts: () => {
240
219
  const { keyrings } = this.messagingSystem.call('KeyringController:getState');
241
220
  const firstHDKeyring = keyrings.find((k) => k.type === keyring_controller_1.KeyringTypes.hd.toString());
242
221
  const keyringAccounts = firstHDKeyring?.accounts ?? null;
@@ -247,9 +226,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
247
226
  *
248
227
  * @returns addresses removed, added, and latest list of addresses
249
228
  */
250
- listAccounts: async () => {
229
+ listAccounts: () => {
251
230
  // Get previous and current account sets
252
- const nonChecksumAccounts = await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").getNotificationAccounts();
231
+ const nonChecksumAccounts = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").getNotificationAccounts();
253
232
  if (!nonChecksumAccounts) {
254
233
  return {
255
234
  accountsAdded: [],
@@ -286,13 +265,11 @@ class NotificationServicesController extends base_controller_1.BaseController {
286
265
  },
287
266
  /**
288
267
  * Initializes the cache/previous list. This is handy so we have an accurate in-mem state of the previous list of accounts.
289
- *
290
- * @returns result from list accounts
291
268
  */
292
- initialize: async () => {
269
+ initialize: () => {
293
270
  if (__classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked &&
294
271
  !__classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup) {
295
- await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
272
+ __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
296
273
  __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").isNotificationAccountsSetup = true;
297
274
  }
298
275
  },
@@ -308,15 +285,15 @@ class NotificationServicesController extends base_controller_1.BaseController {
308
285
  !hasTotalAccountsChanged) {
309
286
  return;
310
287
  }
311
- const { accountsAdded, accountsRemoved } = await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
288
+ const { accountsAdded, accountsRemoved } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
312
289
  const promises = [];
313
290
  if (accountsAdded.length > 0) {
314
- promises.push(this.updateOnChainTriggersByAccount(accountsAdded));
291
+ promises.push(this.enableAccounts(accountsAdded));
315
292
  }
316
293
  if (accountsRemoved.length > 0) {
317
- promises.push(this.deleteOnChainTriggersByAccount(accountsRemoved));
294
+ promises.push(this.disableAccounts(accountsRemoved));
318
295
  }
319
- await Promise.all(promises);
296
+ await Promise.allSettled(promises);
320
297
  }, (state) => {
321
298
  return (state?.keyrings?.flatMap?.((keyring) => keyring.accounts)?.length ??
322
299
  0);
@@ -330,10 +307,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
330
307
  }
331
308
  init() {
332
309
  __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").setupLockedStateSubscriptions(async () => {
333
- await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
310
+ __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
334
311
  await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications();
335
312
  });
336
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
337
313
  __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").initialize();
338
314
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
339
315
  __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").initializePushNotifications();
@@ -344,13 +320,20 @@ class NotificationServicesController extends base_controller_1.BaseController {
344
320
  * Public method to expose enabling push notifications
345
321
  */
346
322
  async enablePushNotifications() {
347
- await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
348
- const storage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
349
- if (!storage) {
350
- throw new Error('Unable to get triggers');
323
+ try {
324
+ const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
325
+ const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
326
+ const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
327
+ const addresses = addressesWithNotifications
328
+ .filter((a) => Boolean(a.enabled))
329
+ .map((a) => a.address);
330
+ if (addresses.length > 0) {
331
+ await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
332
+ }
333
+ }
334
+ catch (e) {
335
+ loglevel_1.default.error('Failed to enable push notifications', e);
351
336
  }
352
- const uuids = Utils.getAllUUIDs(storage);
353
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(uuids);
354
337
  }
355
338
  /**
356
339
  * Public method to expose disabling push notifications
@@ -362,10 +345,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
362
345
  try {
363
346
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
364
347
  // Retrieve user storage
365
- const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
366
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
367
- const presence = Utils.checkAccountsPresence(userStorage, accounts);
368
- return presence;
348
+ const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
349
+ const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
350
+ const result = {};
351
+ addressesWithNotifications.forEach((a) => {
352
+ result[a.address] = a.enabled;
353
+ });
354
+ return result;
369
355
  }
370
356
  catch (error) {
371
357
  loglevel_1.default.error('Failed to check accounts presence', error);
@@ -409,40 +395,32 @@ class NotificationServicesController extends base_controller_1.BaseController {
409
395
  async createOnChainTriggers(opts) {
410
396
  try {
411
397
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, true);
412
- const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getValidStorageKeyAndBearerToken).call(this);
413
- const { accounts } = await __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
414
- // Attempt Get User Storage
415
- // Will be null if entry does not exist, or a user is resetting their notifications
416
- // Will be defined if entry exists
417
- // Will throw if fails to get the user storage entry
418
- let userStorage = opts?.resetNotifications
419
- ? null
420
- : await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
421
- // If userStorage does not exist, create a new one
422
- // All the triggers created are set as: "disabled"
423
- if (userStorage?.[constants_1.USER_STORAGE_VERSION_KEY] === undefined) {
424
- userStorage = Utils.initializeUserStorage(accounts.map((account) => ({ address: account })), false);
425
- // Write the userStorage
426
- await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
398
+ const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
399
+ const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
400
+ // 1. See if has enabled notifications before
401
+ const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
402
+ // Notifications API can return array with addresses set to false
403
+ // So assert that at least one address is enabled
404
+ let accountsWithNotifications = addressesWithNotifications
405
+ .filter((a) => Boolean(a.enabled))
406
+ .map((a) => a.address);
407
+ // 2. Enable Notifications (if no accounts subscribed or we are resetting)
408
+ if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {
409
+ await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
410
+ accountsWithNotifications = accounts;
427
411
  }
428
- // Create the triggers
429
- const triggers = Utils.traverseUserStorageTriggers(userStorage);
430
- await OnChainNotifications.createOnChainTriggers(userStorage, storageKey, bearerToken, triggers);
431
- // Create push notifications triggers in background
432
- const allUUIDS = Utils.getAllUUIDs(userStorage);
433
- // We do not want to wait for this request as it may take a while (e.g. for Firebase to setup)
434
- __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(allUUIDS).catch(() => {
412
+ // 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)
413
+ __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f")
414
+ .enablePushNotifications(accountsWithNotifications)
415
+ .catch(() => {
435
416
  // Do Nothing
436
417
  });
437
- // Write the new userStorage (triggers are now "enabled")
438
- await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
439
418
  // Update the state of the controller
440
419
  this.update((state) => {
441
420
  state.isNotificationServicesEnabled = true;
442
421
  state.isFeatureAnnouncementsEnabled = true;
443
422
  state.isMetamaskNotificationsFeatureSeen = true;
444
423
  });
445
- return userStorage;
446
424
  }
447
425
  catch (err) {
448
426
  loglevel_1.default.error('Failed to create On Chain triggers', err);
@@ -455,10 +433,6 @@ class NotificationServicesController extends base_controller_1.BaseController {
455
433
  /**
456
434
  * Enables all MetaMask notifications for the user.
457
435
  * This is identical flow when initializing notifications for the first time.
458
- * 1. Enable Profile Syncing
459
- * 2. Get or Create Notification User Storage
460
- * 3. Upsert Triggers
461
- * 4. Update Push notifications
462
436
  *
463
437
  * @throws {Error} If there is an error during the process of enabling notifications.
464
438
  */
@@ -506,12 +480,11 @@ class NotificationServicesController extends base_controller_1.BaseController {
506
480
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsUpdatingMetamaskNotifications).call(this, false);
507
481
  }
508
482
  /**
509
- * Deletes on-chain triggers associated with a specific account.
483
+ * Deletes on-chain triggers associated with a specific account/s.
510
484
  * This method performs several key operations:
511
- * 1. Validates Auth & Storage
512
- * 2. Finds and deletes all triggers associated with the account
513
- * 3. Disables any related push notifications
514
- * 4. Updates Storage to reflect new state.
485
+ * 1. Validates Auth
486
+ * 2. Deletes accounts
487
+ * (note) We do not need to look through push notifications as we've deleted triggers
515
488
  *
516
489
  * **Action** - When a user disables notifications for a given account in settings.
517
490
  *
@@ -519,29 +492,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
519
492
  * @returns A promise that resolves to void or an object containing a success message.
520
493
  * @throws {Error} Throws an error if unauthenticated or from other operations.
521
494
  */
522
- async deleteOnChainTriggersByAccount(accounts) {
495
+ async disableAccounts(accounts) {
523
496
  try {
524
497
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
525
498
  // Get and Validate BearerToken and User Storage Key
526
- const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getValidStorageKeyAndBearerToken).call(this);
527
- // Get & Validate User Storage
528
- const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
529
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
530
- // Get the UUIDs to delete
531
- const UUIDs = accounts
532
- .map((a) => Utils.getUUIDsForAccount(userStorage, a.toLowerCase()))
533
- .flat();
534
- if (UUIDs.length === 0) {
535
- return userStorage;
536
- }
499
+ const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
537
500
  // Delete these UUIDs (Mutates User Storage)
538
- await OnChainNotifications.deleteOnChainTriggers(userStorage, storageKey, bearerToken, UUIDs);
539
- // Update Push Notifications with new list of IDs
540
- const remainingTriggerIds = Utils.getAllUUIDs(userStorage);
541
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").updatePushNotifications(remainingTriggerIds);
542
- // Update User Storage
543
- await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
544
- return userStorage;
501
+ await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: false })));
545
502
  }
546
503
  catch (err) {
547
504
  loglevel_1.default.error('Failed to delete OnChain triggers', err);
@@ -566,45 +523,11 @@ class NotificationServicesController extends base_controller_1.BaseController {
566
523
  * @returns A promise that resolves to the updated user storage.
567
524
  * @throws {Error} Throws an error if unauthenticated or from other operations.
568
525
  */
569
- async updateOnChainTriggersByAccount(accounts) {
526
+ async enableAccounts(accounts) {
570
527
  try {
571
528
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
572
- // Get and Validate BearerToken and User Storage Key
573
- const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getValidStorageKeyAndBearerToken).call(this);
574
- // Get & Validate User Storage
575
- const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getUserStorage).call(this);
576
- __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertUserStorage).call(this, userStorage);
577
- // Add any missing triggers
578
- accounts.forEach((a) => Utils.upsertAddressTriggers(a, userStorage));
579
- const newTriggers = Utils.traverseUserStorageTriggers(userStorage, {
580
- mapTrigger: (t) => {
581
- if (!t.enabled) {
582
- return t;
583
- }
584
- return undefined;
585
- },
586
- });
587
- // Create any missing triggers.
588
- if (newTriggers.length > 0) {
589
- // Write te updated userStorage (where triggers are disabled)
590
- await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
591
- // Create the triggers
592
- const triggers = Utils.traverseUserStorageTriggers(userStorage, {
593
- mapTrigger: (t) => {
594
- if (accounts.some((a) => a.toLowerCase() === t.address.toLowerCase())) {
595
- return t;
596
- }
597
- return undefined;
598
- },
599
- });
600
- await OnChainNotifications.createOnChainTriggers(userStorage, storageKey, bearerToken, triggers);
601
- }
602
- // Update Push Notifications Triggers
603
- const UUIDs = Utils.getAllUUIDs(userStorage);
604
- await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").updatePushNotifications(UUIDs);
605
- // Update the userStorage (where triggers are enabled)
606
- await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").setNotificationStorage(JSON.stringify(userStorage));
607
- return userStorage;
529
+ const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
530
+ await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
608
531
  }
609
532
  catch (err) {
610
533
  loglevel_1.default.error('Failed to update OnChain triggers', err);
@@ -631,37 +554,31 @@ class NotificationServicesController extends base_controller_1.BaseController {
631
554
  // Not used by Snaps
632
555
  const isGlobalNotifsEnabled = this.state.isNotificationServicesEnabled;
633
556
  // Raw Feature Notifications
634
- const rawFeatureAnnouncementNotifications = isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled
557
+ const rawAnnouncements = isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled
635
558
  ? await FeatureNotifications.getFeatureAnnouncementNotifications(__classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f"), previewToken).catch(() => [])
636
559
  : [];
637
560
  // Raw On Chain Notifications
638
561
  const rawOnChainNotifications = [];
639
562
  if (isGlobalNotifsEnabled) {
640
- const userStorage = await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f")
641
- .getNotificationStorage()
642
- .then((s) => s && JSON.parse(s))
643
- .catch(() => null);
644
- const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken().catch(() => null);
645
- if (userStorage && bearerToken) {
646
- const notifications = await OnChainNotifications.getOnChainNotifications(userStorage, bearerToken).catch(() => []);
563
+ try {
564
+ const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
565
+ const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
566
+ const addressesWithNotifications = (await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts)).map((a) => a.address);
567
+ const notifications = await OnChainNotifications.getOnChainNotifications(bearerToken, addressesWithNotifications).catch(() => []);
647
568
  rawOnChainNotifications.push(...notifications);
648
569
  }
570
+ catch {
571
+ // Do nothing
572
+ }
649
573
  }
650
574
  // Snap Notifications (original)
651
575
  // We do not want to remove them
652
576
  const snapNotifications = this.state.metamaskNotificationsList.filter((notification) => notification.type === notification_schema_1.TRIGGER_TYPES.SNAP);
653
- // Process Notifications
654
577
  const readIds = this.state.metamaskNotificationsReadList;
655
- const isNotUndefined = (t) => Boolean(t);
656
- const processAndFilter = (ns) => ns
657
- .map((n) => (0, process_notifications_1.safeProcessNotification)(n, readIds))
658
- .filter(isNotUndefined);
659
- const featureAnnouncementNotifications = processAndFilter(rawFeatureAnnouncementNotifications);
660
- const onChainNotifications = processAndFilter(rawOnChainNotifications);
661
578
  // Combine Notifications
662
579
  const metamaskNotifications = [
663
- ...featureAnnouncementNotifications,
664
- ...onChainNotifications,
580
+ ...(0, process_notifications_1.processAndFilterNotifications)(rawAnnouncements, readIds),
581
+ ...(0, process_notifications_1.processAndFilterNotifications)(rawOnChainNotifications, readIds),
665
582
  ...snapNotifications,
666
583
  ];
667
584
  // Sort Notifications
@@ -829,7 +746,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
829
746
  }
830
747
  }
831
748
  }
832
- _NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_storage = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
749
+ _NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
833
750
  this.messagingSystem.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
834
751
  this.messagingSystem.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
835
752
  this.messagingSystem.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
@@ -853,42 +770,13 @@ _NotificationServicesController_keyringController = new WeakMap(), _Notification
853
770
  if (!isSignedIn) {
854
771
  await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").signIn();
855
772
  }
856
- }, _NotificationServicesController_getValidStorageKeyAndBearerToken = async function _NotificationServicesController_getValidStorageKeyAndBearerToken() {
773
+ }, _NotificationServicesController_getBearerToken = async function _NotificationServicesController_getBearerToken() {
857
774
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_assertAuthEnabled).call(this);
858
775
  const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
859
- const storageKey = await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").getStorageKey();
860
- if (!bearerToken || !storageKey) {
861
- throw new Error('Missing BearerToken or storage key');
862
- }
863
- return { bearerToken, storageKey };
864
- }, _NotificationServicesController_assertUserStorage = function _NotificationServicesController_assertUserStorage(storage) {
865
- if (!storage) {
866
- throw new Error('User Storage does not exist');
867
- }
868
- }, _NotificationServicesController_getUserStorage =
869
- /**
870
- * Retrieves and parses the user storage from the storage key.
871
- *
872
- * This method attempts to retrieve the user storage using the specified storage key,
873
- * then parses the JSON string to an object. If the storage is not found or cannot be parsed,
874
- * it throws an error.
875
- *
876
- * @returns The parsed user storage object or null
877
- */
878
- async function _NotificationServicesController_getUserStorage() {
879
- const userStorageString = await __classPrivateFieldGet(this, _NotificationServicesController_storage, "f").getNotificationStorage();
880
- if (!userStorageString) {
881
- return null;
882
- }
883
- try {
884
- const userStorage = JSON.parse(userStorageString);
885
- Utils.cleanUserStorage(userStorage);
886
- return userStorage;
887
- }
888
- catch {
889
- loglevel_1.default.error('Unable to parse User Storage');
890
- return null;
776
+ if (!bearerToken) {
777
+ throw new Error('Missing BearerToken');
891
778
  }
779
+ return { bearerToken };
892
780
  }, _NotificationServicesController_setIsUpdatingMetamaskNotifications = function _NotificationServicesController_setIsUpdatingMetamaskNotifications(isUpdatingMetamaskNotifications) {
893
781
  this.update((state) => {
894
782
  state.isUpdatingMetamaskNotifications = isUpdatingMetamaskNotifications;