@metamask/notification-services-controller 20.0.0 → 22.0.0

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 (199) hide show
  1. package/CHANGELOG.md +41 -2
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +65 -51
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +4 -1
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +4 -1
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +65 -51
  9. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  10. package/dist/NotificationServicesController/constants/notification-schema.cjs +4 -12
  11. package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
  12. package/dist/NotificationServicesController/constants/notification-schema.d.cts +0 -12
  13. package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/constants/notification-schema.d.mts +0 -12
  15. package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/constants/notification-schema.mjs +3 -11
  17. package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
  18. package/dist/NotificationServicesController/index.cjs +1 -2
  19. package/dist/NotificationServicesController/index.cjs.map +1 -1
  20. package/dist/NotificationServicesController/index.d.cts +0 -1
  21. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  22. package/dist/NotificationServicesController/index.d.mts +0 -1
  23. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  24. package/dist/NotificationServicesController/index.mjs +0 -1
  25. package/dist/NotificationServicesController/index.mjs.map +1 -1
  26. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +120 -0
  27. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
  28. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
  29. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
  30. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +120 -0
  31. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
  32. package/dist/NotificationServicesController/mocks/mock-snap-notification.cjs.map +1 -1
  33. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts +1 -1
  34. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts.map +1 -1
  35. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts +1 -1
  36. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts.map +1 -1
  37. package/dist/NotificationServicesController/mocks/mock-snap-notification.mjs.map +1 -1
  38. package/dist/NotificationServicesController/mocks/mockResponses.cjs +10 -4
  39. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  40. package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
  41. package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
  42. package/dist/NotificationServicesController/mocks/mockResponses.mjs +10 -4
  43. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  44. package/dist/NotificationServicesController/processors/process-notifications.cjs +11 -9
  45. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  46. package/dist/NotificationServicesController/processors/process-notifications.d.cts +1 -563
  47. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  48. package/dist/NotificationServicesController/processors/process-notifications.d.mts +1 -563
  49. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  50. package/dist/NotificationServicesController/processors/process-notifications.mjs +11 -9
  51. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  52. package/dist/NotificationServicesController/processors/process-snap-notifications.cjs.map +1 -1
  53. package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts +1 -1
  54. package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts.map +1 -1
  55. package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts +1 -1
  56. package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts.map +1 -1
  57. package/dist/NotificationServicesController/processors/process-snap-notifications.mjs.map +1 -1
  58. package/dist/NotificationServicesController/services/api-notifications.cjs +54 -34
  59. package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
  60. package/dist/NotificationServicesController/services/api-notifications.d.cts +15 -10
  61. package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
  62. package/dist/NotificationServicesController/services/api-notifications.d.mts +15 -10
  63. package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
  64. package/dist/NotificationServicesController/services/api-notifications.mjs +48 -34
  65. package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
  66. package/dist/NotificationServicesController/services/feature-announcements.cjs +10 -10
  67. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  68. package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
  69. package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
  70. package/dist/NotificationServicesController/services/feature-announcements.mjs +10 -10
  71. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  72. package/dist/NotificationServicesController/services/notification-config-cache.cjs +4 -4
  73. package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -1
  74. package/dist/NotificationServicesController/services/notification-config-cache.mjs +4 -4
  75. package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -1
  76. package/dist/NotificationServicesController/services/perp-notifications.cjs +2 -2
  77. package/dist/NotificationServicesController/services/perp-notifications.cjs.map +1 -1
  78. package/dist/NotificationServicesController/services/perp-notifications.d.cts.map +1 -1
  79. package/dist/NotificationServicesController/services/perp-notifications.d.mts.map +1 -1
  80. package/dist/NotificationServicesController/services/perp-notifications.mjs +2 -2
  81. package/dist/NotificationServicesController/services/perp-notifications.mjs.map +1 -1
  82. package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -1
  83. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +2 -0
  84. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -1
  85. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +2 -0
  86. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -1
  87. package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -1
  88. package/dist/NotificationServicesController/types/notification-api/schema.cjs +2 -6
  89. package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -1
  90. package/dist/NotificationServicesController/types/notification-api/schema.d.cts +23 -0
  91. package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -1
  92. package/dist/NotificationServicesController/types/notification-api/schema.d.mts +23 -0
  93. package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -1
  94. package/dist/NotificationServicesController/types/notification-api/schema.mjs +2 -6
  95. package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -1
  96. package/dist/NotificationServicesController/types/perps/schema.cjs +2 -0
  97. package/dist/NotificationServicesController/types/perps/schema.cjs.map +1 -1
  98. package/dist/NotificationServicesController/types/perps/schema.d.cts.map +1 -1
  99. package/dist/NotificationServicesController/types/perps/schema.d.mts.map +1 -1
  100. package/dist/NotificationServicesController/types/perps/schema.mjs +2 -0
  101. package/dist/NotificationServicesController/types/perps/schema.mjs.map +1 -1
  102. package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
  103. package/dist/NotificationServicesController/utils/isVersionInBounds.d.cts.map +1 -1
  104. package/dist/NotificationServicesController/utils/isVersionInBounds.d.mts.map +1 -1
  105. package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
  106. package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -1
  107. package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -1
  108. package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -1
  109. package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -1
  110. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +2 -1
  111. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  112. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +2 -0
  113. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  114. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +2 -0
  115. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  116. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +2 -1
  117. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  118. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +1 -1
  119. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
  120. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +9 -24
  121. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
  122. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +9 -24
  123. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
  124. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +1 -1
  125. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
  126. package/dist/NotificationServicesPushController/services/endpoints.cjs +10 -3
  127. package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
  128. package/dist/NotificationServicesPushController/services/endpoints.d.cts +3 -1
  129. package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
  130. package/dist/NotificationServicesPushController/services/endpoints.d.mts +3 -1
  131. package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
  132. package/dist/NotificationServicesPushController/services/endpoints.mjs +7 -2
  133. package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
  134. package/dist/NotificationServicesPushController/services/services.cjs +2 -1
  135. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  136. package/dist/NotificationServicesPushController/services/services.d.cts +3 -0
  137. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  138. package/dist/NotificationServicesPushController/services/services.d.mts +3 -0
  139. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  140. package/dist/NotificationServicesPushController/services/services.mjs +2 -1
  141. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  142. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs +4 -4
  143. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
  144. package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts +2 -2
  145. package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts.map +1 -1
  146. package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts +2 -2
  147. package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts.map +1 -1
  148. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs +4 -4
  149. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
  150. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +62 -71
  151. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  152. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +9 -9
  153. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  154. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +9 -9
  155. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  156. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +62 -71
  157. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  158. package/dist/NotificationServicesPushController/web/push-utils.cjs +15 -7
  159. package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -1
  160. package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -1
  161. package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -1
  162. package/dist/NotificationServicesPushController/web/push-utils.mjs +16 -8
  163. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
  164. package/dist/shared/is-onchain-notification.cjs +3 -3
  165. package/dist/shared/is-onchain-notification.cjs.map +1 -1
  166. package/dist/shared/is-onchain-notification.d.cts +2 -2
  167. package/dist/shared/is-onchain-notification.d.cts.map +1 -1
  168. package/dist/shared/is-onchain-notification.d.mts +2 -2
  169. package/dist/shared/is-onchain-notification.d.mts.map +1 -1
  170. package/dist/shared/is-onchain-notification.mjs +3 -3
  171. package/dist/shared/is-onchain-notification.mjs.map +1 -1
  172. package/dist/shared/to-raw-notification.cjs.map +1 -1
  173. package/dist/shared/to-raw-notification.mjs.map +1 -1
  174. package/package.json +7 -21
  175. package/dist/NotificationServicesController/ui/constants.cjs +0 -75
  176. package/dist/NotificationServicesController/ui/constants.cjs.map +0 -1
  177. package/dist/NotificationServicesController/ui/constants.d.cts +0 -66
  178. package/dist/NotificationServicesController/ui/constants.d.cts.map +0 -1
  179. package/dist/NotificationServicesController/ui/constants.d.mts +0 -66
  180. package/dist/NotificationServicesController/ui/constants.d.mts.map +0 -1
  181. package/dist/NotificationServicesController/ui/constants.mjs +0 -71
  182. package/dist/NotificationServicesController/ui/constants.mjs.map +0 -1
  183. package/dist/NotificationServicesController/ui/index.cjs +0 -18
  184. package/dist/NotificationServicesController/ui/index.cjs.map +0 -1
  185. package/dist/NotificationServicesController/ui/index.d.cts +0 -2
  186. package/dist/NotificationServicesController/ui/index.d.cts.map +0 -1
  187. package/dist/NotificationServicesController/ui/index.d.mts +0 -2
  188. package/dist/NotificationServicesController/ui/index.d.mts.map +0 -1
  189. package/dist/NotificationServicesController/ui/index.mjs +0 -2
  190. package/dist/NotificationServicesController/ui/index.mjs.map +0 -1
  191. package/dist/NotificationServicesPushController/services/push/push-web.cjs +0 -145
  192. package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +0 -1
  193. package/dist/NotificationServicesPushController/services/push/push-web.d.cts +0 -34
  194. package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +0 -1
  195. package/dist/NotificationServicesPushController/services/push/push-web.d.mts +0 -34
  196. package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +0 -1
  197. package/dist/NotificationServicesPushController/services/push/push-web.mjs +0 -142
  198. package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +0 -1
  199. package/notification-services/ui/package.json +0 -9
package/CHANGELOG.md CHANGED
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [22.0.0]
11
+
12
+ ### Changed
13
+
14
+ - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
15
+ - Move peer dependencies for controller and service packages to direct dependencies ([#7209](https://github.com/MetaMask/core/pull/7209), [#7713](https://github.com/MetaMask/core/pull/7713), [#7849](https://github.com/MetaMask/core/pull/7849))
16
+ - The dependencies moved are:
17
+ - `@metamask/keyring-controller` (^25.1.0)
18
+ - `@metamask/profile-sync-controller` (^27.1.0)
19
+ - In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
20
+ - For example, this scenario would be valid: a client relies on `@metamask/controller-a` 1.0.0 and `@metamask/controller-b` 1.0.0, and `@metamask/controller-b` depends on `@metamask/controller-a` 1.1.0.
21
+ - Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication.
22
+ - Modified background push utilities to handle more edgecases and not throw errors ([#7275](https://github.com/MetaMask/core/pull/7275))
23
+ - Bump `@metamask/controller-utils` from `^11.16.0` to `^11.18.0` ([#7534](https://github.com/MetaMask/core/pull/7534), [#7583](https://github.com/MetaMask/core/pull/7583))
24
+ - Move notifications networks metadata to backend ([#7840](https://github.com/MetaMask/core/pull/7840))
25
+
26
+ ### Removed
27
+
28
+ - **BREAKING:** Removed the `"./notification-services/ui"` subpath export from `package.json` ([#7840](https://github.com/MetaMask/core/pull/7840))
29
+ - Consumers that import from `@metamask/notification-services-controller/notification-services/ui` must switch to network config provided by the backend.
30
+
31
+ ### Fixed
32
+
33
+ - Remove non-actionable internal `log.error` calls for expected silent-failure notification paths, while preserving thrown errors where propagation is required ([#7885](https://github.com/MetaMask/core/pull/7885))
34
+ - Fix `createOnChainTriggers` to preserve user preferences on notification re-subscriptions ([#7423](https://github.com/MetaMask/core/pull/7423))
35
+ - Previously, `isFeatureAnnouncementsEnabled` was unconditionally set to `true` on every re-subscription, overriding user preferences
36
+ - Now, existing preferences are preserved when `isNotificationServicesEnabled` is already `true`
37
+
38
+ ## [21.0.0]
39
+
40
+ ### Changed
41
+
42
+ - Bump `@metamask/controller-utils` from `^11.15.0` to `^11.16.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
43
+ - **BREAKING:** Bump `@metamask/profile-sync-controller` from `^26.0.0` to `^27.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
44
+ - **BREAKING:** Bump `@metamask/keyring-controller` from `^24.0.0` to `^25.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
45
+ - Add optional `env` parameter to the `NotificationServicesController` and `NotificationServicesPushController`
46
+ to support different environments (`prd`, `uat`, `dev`). ([#7175](https://github.com/MetaMask/core/pull/7175))
47
+
10
48
  ## [20.0.0]
11
49
 
12
50
  ### Changed
@@ -187,7 +225,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
187
225
  ### Removed
188
226
 
189
227
  - **BREAKING:** Migrated to notification v2 endpoints ([#5945](https://github.com/MetaMask/core/pull/5945))
190
-
191
228
  - removed `NotificationServicesPushController:updateTriggerPushNotifications` action from `NotificationServicesController`
192
229
  - removed `UserStorageController:getStorageKey` action from `NotificationServicesController`
193
230
  - removed `UserStorageController:performGetStorage` action from `NotificationServicesController`
@@ -620,7 +657,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
620
657
 
621
658
  - Initial release
622
659
 
623
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@20.0.0...HEAD
660
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@22.0.0...HEAD
661
+ [22.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@21.0.0...@metamask/notification-services-controller@22.0.0
662
+ [21.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@20.0.0...@metamask/notification-services-controller@21.0.0
624
663
  [20.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@19.0.0...@metamask/notification-services-controller@20.0.0
625
664
  [19.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.3.1...@metamask/notification-services-controller@19.0.0
626
665
  [18.3.1]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.3.0...@metamask/notification-services-controller@18.3.1
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
- var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_locale, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getBearerToken, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
16
+ var _NotificationServicesController_instances, _NotificationServicesController_keyringController, _NotificationServicesController_auth, _NotificationServicesController_pushNotifications, _NotificationServicesController_accounts, _NotificationServicesController_locale, _NotificationServicesController_featureAnnouncementEnv, _NotificationServicesController_env, _NotificationServicesController_registerMessageHandlers, _NotificationServicesController_clearLoadingStates, _NotificationServicesController_assertAuthEnabled, _NotificationServicesController_enableAuth, _NotificationServicesController_getBearerToken, _NotificationServicesController_setIsUpdatingMetamaskNotifications, _NotificationServicesController_setIsFetchingMetamaskNotifications, _NotificationServicesController_setIsCheckingAccountsPresence, _NotificationServicesController_updateUpdatingAccountsState, _NotificationServicesController_clearUpdatingAccountsState;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.defaultState = void 0;
19
19
  const base_controller_1 = require("@metamask/base-controller");
@@ -118,6 +118,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
118
118
  * @param args.env - environment variables for a given controller.
119
119
  * @param args.env.featureAnnouncements - env variables for feature announcements.
120
120
  * @param args.env.locale - users locale for better dynamic server notifications
121
+ * @param args.env.env - the environment to use for the controller
121
122
  */
122
123
  constructor({ messenger, state, env, }) {
123
124
  super({
@@ -167,16 +168,16 @@ class NotificationServicesController extends base_controller_1.BaseController {
167
168
  try {
168
169
  await this.messenger.call('NotificationServicesPushController:enablePushNotifications', addresses);
169
170
  }
170
- catch (e) {
171
- loglevel_1.default.error('Silently failed to enable push notifications', e);
171
+ catch {
172
+ // Do nothing, failing silently.
172
173
  }
173
174
  },
174
175
  disablePushNotifications: async () => {
175
176
  try {
176
177
  await this.messenger.call('NotificationServicesPushController:disablePushNotifications');
177
178
  }
178
- catch (e) {
179
- loglevel_1.default.error('Silently failed to disable push notifications', e);
179
+ catch {
180
+ // Do nothing, failing silently.
180
181
  }
181
182
  },
182
183
  subscribe: () => {
@@ -215,7 +216,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
215
216
  isNotificationAccountsSetup: false,
216
217
  getNotificationAccounts: () => {
217
218
  const { keyrings } = this.messenger.call('KeyringController:getState');
218
- const firstHDKeyring = keyrings.find((k) => k.type === keyring_controller_1.KeyringTypes.hd.toString());
219
+ const firstHDKeyring = keyrings.find((keyring) => keyring.type === keyring_controller_1.KeyringTypes.hd.toString());
219
220
  const keyringAccounts = firstHDKeyring?.accounts ?? null;
220
221
  return keyringAccounts;
221
222
  },
@@ -235,8 +236,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
235
236
  };
236
237
  }
237
238
  const accounts = nonChecksumAccounts
238
- .map((a) => (0, controller_utils_1.toChecksumHexAddress)(a))
239
- .filter((a) => (0, controller_utils_1.isValidHexAddress)(a));
239
+ .map((address) => (0, controller_utils_1.toChecksumHexAddress)(address))
240
+ .filter((address) => (0, controller_utils_1.isValidHexAddress)(address));
240
241
  const currentAccountsSet = new Set(accounts);
241
242
  const prevAccountsSet = new Set(this.state.subscriptionAccountsSeen);
242
243
  // Invalid value you cannot have zero accounts
@@ -249,8 +250,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
249
250
  };
250
251
  }
251
252
  // Calculate added and removed addresses
252
- const accountsAdded = accounts.filter((a) => !prevAccountsSet.has(a));
253
- const accountsRemoved = [...prevAccountsSet.values()].filter((a) => !currentAccountsSet.has(a));
253
+ const accountsAdded = accounts.filter((account) => !prevAccountsSet.has(account));
254
+ const accountsRemoved = [...prevAccountsSet.values()].filter((account) => !currentAccountsSet.has(account));
254
255
  // Update accounts seen
255
256
  this.update((state) => {
256
257
  state.subscriptionAccountsSeen = [...currentAccountsSet];
@@ -277,7 +278,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
277
278
  * And call effects to subscribe/unsubscribe to notifications.
278
279
  */
279
280
  subscribe: () => {
280
- this.messenger.subscribe('KeyringController:stateChange', async (totalAccounts, prevTotalAccounts) => {
281
+ this.messenger.subscribe('KeyringController:stateChange',
282
+ // Using void return for async callback - result is intentionally ignored
283
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
284
+ async (totalAccounts, prevTotalAccounts) => {
281
285
  const hasTotalAccountsChanged = totalAccounts !== prevTotalAccounts;
282
286
  if (!this.state.isNotificationServicesEnabled ||
283
287
  !hasTotalAccountsChanged) {
@@ -300,8 +304,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
300
304
  });
301
305
  _NotificationServicesController_locale.set(this, void 0);
302
306
  _NotificationServicesController_featureAnnouncementEnv.set(this, void 0);
307
+ _NotificationServicesController_env.set(this, void 0);
303
308
  __classPrivateFieldSet(this, _NotificationServicesController_featureAnnouncementEnv, env.featureAnnouncements, "f");
304
309
  __classPrivateFieldSet(this, _NotificationServicesController_locale, env.locale ?? (() => 'en'), "f");
310
+ __classPrivateFieldSet(this, _NotificationServicesController_env, env.env ?? 'prd', "f");
305
311
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerMessageHandlers).call(this);
306
312
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_clearLoadingStates).call(this);
307
313
  }
@@ -323,16 +329,16 @@ class NotificationServicesController extends base_controller_1.BaseController {
323
329
  try {
324
330
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
325
331
  const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
326
- const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts);
332
+ const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
327
333
  const addresses = addressesWithNotifications
328
- .filter((a) => Boolean(a.enabled))
329
- .map((a) => a.address);
334
+ .filter((addressConfig) => Boolean(addressConfig.enabled))
335
+ .map((addressConfig) => addressConfig.address);
330
336
  if (addresses.length > 0) {
331
337
  await __classPrivateFieldGet(this, _NotificationServicesController_pushNotifications, "f").enablePushNotifications(addresses);
332
338
  }
333
339
  }
334
- catch (e) {
335
- loglevel_1.default.error('Failed to enable push notifications', e);
340
+ catch {
341
+ // Do nothing, failing silently.
336
342
  }
337
343
  }
338
344
  /**
@@ -346,7 +352,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
346
352
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
347
353
  // Retrieve user storage
348
354
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
349
- const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts);
355
+ const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
350
356
  const result = {};
351
357
  addressesWithNotifications.forEach((a) => {
352
358
  result[a.address] = a.enabled;
@@ -372,12 +378,12 @@ class NotificationServicesController extends base_controller_1.BaseController {
372
378
  */
373
379
  async setFeatureAnnouncementsEnabled(featureAnnouncementsEnabled) {
374
380
  try {
375
- this.update((s) => {
376
- s.isFeatureAnnouncementsEnabled = featureAnnouncementsEnabled;
381
+ this.update((state) => {
382
+ state.isFeatureAnnouncementsEnabled = featureAnnouncementsEnabled;
377
383
  });
378
384
  }
379
- catch (e) {
380
- loglevel_1.default.error('Unable to toggle feature announcements', e);
385
+ catch (error) {
386
+ loglevel_1.default.error('Unable to toggle feature announcements', error);
381
387
  throw new Error('Unable to toggle feature announcements');
382
388
  }
383
389
  }
@@ -398,15 +404,15 @@ class NotificationServicesController extends base_controller_1.BaseController {
398
404
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
399
405
  const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
400
406
  // 1. See if has enabled notifications before
401
- const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts);
407
+ const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
402
408
  // Notifications API can return array with addresses set to false
403
409
  // So assert that at least one address is enabled
404
410
  let accountsWithNotifications = addressesWithNotifications
405
- .filter((a) => Boolean(a.enabled))
406
- .map((a) => a.address);
411
+ .filter((addressConfig) => Boolean(addressConfig.enabled))
412
+ .map((addressConfig) => addressConfig.address);
407
413
  // 2. Enable Notifications (if no accounts subscribed or we are resetting)
408
414
  if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {
409
- await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })));
415
+ await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
410
416
  accountsWithNotifications = accounts;
411
417
  }
412
418
  // 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)
@@ -417,13 +423,21 @@ class NotificationServicesController extends base_controller_1.BaseController {
417
423
  });
418
424
  // Update the state of the controller
419
425
  this.update((state) => {
420
- state.isNotificationServicesEnabled = true;
421
- state.isFeatureAnnouncementsEnabled = true;
422
- state.isMetamaskNotificationsFeatureSeen = true;
426
+ // User is re-subscribing (daily resub to get latest notifications)
427
+ if (state.isNotificationServicesEnabled) {
428
+ // Keep their existing preferences on re-subscribe
429
+ // No state updates needed - preserving user's current settings
430
+ }
431
+ else {
432
+ // User is turning on notifications from a disabled state
433
+ state.isNotificationServicesEnabled = true;
434
+ state.isFeatureAnnouncementsEnabled = true;
435
+ state.isMetamaskNotificationsFeatureSeen = true;
436
+ }
423
437
  });
424
438
  }
425
- catch (err) {
426
- loglevel_1.default.error('Failed to create On Chain triggers', err);
439
+ catch (error) {
440
+ loglevel_1.default.error('Failed to create On Chain triggers', error);
427
441
  throw new Error('Failed to create On Chain triggers');
428
442
  }
429
443
  finally {
@@ -442,8 +456,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
442
456
  await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_enableAuth).call(this);
443
457
  await this.createOnChainTriggers();
444
458
  }
445
- catch (e) {
446
- loglevel_1.default.error('Unable to enable notifications', e);
459
+ catch (error) {
460
+ loglevel_1.default.error('Unable to enable notifications', error);
447
461
  throw new Error('Unable to enable notifications');
448
462
  }
449
463
  finally {
@@ -498,10 +512,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
498
512
  // Get and Validate BearerToken and User Storage Key
499
513
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
500
514
  // Delete these UUIDs (Mutates User Storage)
501
- await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: false })));
515
+ await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: false })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
502
516
  }
503
- catch (err) {
504
- loglevel_1.default.error('Failed to delete OnChain triggers', err);
517
+ catch {
505
518
  throw new Error('Failed to delete OnChain triggers');
506
519
  }
507
520
  finally {
@@ -527,10 +540,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
527
540
  try {
528
541
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
529
542
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
530
- await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })));
543
+ await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })), __classPrivateFieldGet(this, _NotificationServicesController_env, "f"));
531
544
  }
532
- catch (err) {
533
- loglevel_1.default.error('Failed to update OnChain triggers', err);
545
+ catch (error) {
546
+ loglevel_1.default.error('Failed to update OnChain triggers', error);
534
547
  throw new Error('Failed to update OnChain triggers');
535
548
  }
536
549
  finally {
@@ -563,10 +576,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
563
576
  try {
564
577
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
565
578
  const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
566
- const addressesWithNotifications = (await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts))
567
- .filter((a) => Boolean(a.enabled))
568
- .map((a) => a.address);
569
- const notifications = await (0, api_notifications_1.getAPINotifications)(bearerToken, addressesWithNotifications, __classPrivateFieldGet(this, _NotificationServicesController_locale, "f").call(this), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform).catch(() => []);
579
+ const addressesWithNotifications = (await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")))
580
+ .filter((addressConfig) => Boolean(addressConfig.enabled))
581
+ .map((addressConfig) => addressConfig.address);
582
+ const notifications = await (0, api_notifications_1.getAPINotifications)(bearerToken, addressesWithNotifications, __classPrivateFieldGet(this, _NotificationServicesController_locale, "f").call(this), __classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f").platform, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")).catch(() => []);
570
583
  rawOnChainNotifications.push(...notifications);
571
584
  }
572
585
  catch {
@@ -584,7 +597,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
584
597
  ...snapNotifications,
585
598
  ];
586
599
  // Sort Notifications
587
- metamaskNotifications.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
600
+ metamaskNotifications.sort((notificationA, notificationB) => new Date(notificationB.createdAt).getTime() -
601
+ new Date(notificationA.createdAt).getTime());
588
602
  // Update State
589
603
  this.update((state) => {
590
604
  state.metamaskNotificationsList = metamaskNotifications;
@@ -593,9 +607,9 @@ class NotificationServicesController extends base_controller_1.BaseController {
593
607
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsFetchingMetamaskNotifications).call(this, false);
594
608
  return metamaskNotifications;
595
609
  }
596
- catch (err) {
610
+ catch (error) {
597
611
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsFetchingMetamaskNotifications).call(this, false);
598
- loglevel_1.default.error('Failed to fetch notifications', err);
612
+ loglevel_1.default.error('Failed to fetch notifications', error);
599
613
  throw new Error('Failed to fetch notifications');
600
614
  }
601
615
  }
@@ -676,7 +690,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
676
690
  const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
677
691
  if (bearerToken) {
678
692
  onchainNotificationIds = onChainNotifications.map((notification) => notification.id);
679
- await (0, api_notifications_1.markNotificationsAsRead)(bearerToken, onchainNotificationIds).catch(() => {
693
+ await (0, api_notifications_1.markNotificationsAsRead)(bearerToken, onchainNotificationIds, __classPrivateFieldGet(this, _NotificationServicesController_env, "f")).catch(() => {
680
694
  onchainNotificationIds = [];
681
695
  loglevel_1.default.warn('Unable to mark onchain notifications as read');
682
696
  });
@@ -691,8 +705,8 @@ class NotificationServicesController extends base_controller_1.BaseController {
691
705
  snapNotificationIds = snapNotifications.map((notification) => notification.id);
692
706
  }
693
707
  }
694
- catch (err) {
695
- loglevel_1.default.warn('Something failed when marking notifications as read', err);
708
+ catch (error) {
709
+ loglevel_1.default.warn('Something failed when marking notifications as read', error);
696
710
  }
697
711
  // Update the state (state is also used on counter & badge)
698
712
  this.update((state) => {
@@ -729,13 +743,13 @@ class NotificationServicesController extends base_controller_1.BaseController {
729
743
  * @returns A promise that resolves when the notification list has been successfully updated.
730
744
  */
731
745
  async updateMetamaskNotificationsList(notification) {
732
- if (this.state.metamaskNotificationsList.some((n) => n.id === notification.id)) {
746
+ if (this.state.metamaskNotificationsList.some((existingNotification) => existingNotification.id === notification.id)) {
733
747
  return;
734
748
  }
735
749
  const processedNotification = (0, process_notifications_1.safeProcessNotification)(notification);
736
750
  if (processedNotification) {
737
751
  this.update((state) => {
738
- const existingNotificationIds = new Set(state.metamaskNotificationsList.map((n) => n.id));
752
+ const existingNotificationIds = new Set(state.metamaskNotificationsList.map((existingNotification) => existingNotification.id));
739
753
  // Add the new notification only if its ID is not already present in the list
740
754
  if (!existingNotificationIds.has(processedNotification.id)) {
741
755
  state.metamaskNotificationsList = [
@@ -763,7 +777,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
763
777
  }
764
778
  }
765
779
  }
766
- _NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_locale = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
780
+ _NotificationServicesController_keyringController = new WeakMap(), _NotificationServicesController_auth = new WeakMap(), _NotificationServicesController_pushNotifications = new WeakMap(), _NotificationServicesController_accounts = new WeakMap(), _NotificationServicesController_locale = new WeakMap(), _NotificationServicesController_featureAnnouncementEnv = new WeakMap(), _NotificationServicesController_env = new WeakMap(), _NotificationServicesController_instances = new WeakSet(), _NotificationServicesController_registerMessageHandlers = function _NotificationServicesController_registerMessageHandlers() {
767
781
  this.messenger.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
768
782
  this.messenger.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
769
783
  this.messenger.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));