@metamask/notification-services-controller 18.3.1 → 20.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 (207) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +47 -68
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +8 -7
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +8 -7
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +47 -45
  9. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  10. package/dist/NotificationServicesController/constants/notification-schema.cjs +4 -14
  11. package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
  12. package/dist/NotificationServicesController/constants/notification-schema.d.cts +3 -13
  13. package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/constants/notification-schema.d.mts +3 -13
  15. package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/constants/notification-schema.mjs +3 -13
  17. package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
  18. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +427 -529
  19. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
  20. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts +20 -50
  21. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
  22. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts +20 -50
  23. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
  24. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +424 -521
  25. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
  26. package/dist/NotificationServicesController/mocks/mockResponses.cjs +5 -5
  27. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  28. package/dist/NotificationServicesController/mocks/mockResponses.d.cts +2 -2
  29. package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
  30. package/dist/NotificationServicesController/mocks/mockResponses.d.mts +2 -2
  31. package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
  32. package/dist/NotificationServicesController/mocks/mockResponses.mjs +1 -1
  33. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  34. package/dist/NotificationServicesController/processors/index.cjs +1 -1
  35. package/dist/NotificationServicesController/processors/index.cjs.map +1 -1
  36. package/dist/NotificationServicesController/processors/index.d.cts +1 -1
  37. package/dist/NotificationServicesController/processors/index.d.cts.map +1 -1
  38. package/dist/NotificationServicesController/processors/index.d.mts +1 -1
  39. package/dist/NotificationServicesController/processors/index.d.mts.map +1 -1
  40. package/dist/NotificationServicesController/processors/index.mjs +1 -1
  41. package/dist/NotificationServicesController/processors/index.mjs.map +1 -1
  42. package/dist/NotificationServicesController/processors/process-api-notifications.cjs +22 -0
  43. package/dist/NotificationServicesController/processors/process-api-notifications.cjs.map +1 -0
  44. package/dist/NotificationServicesController/processors/process-api-notifications.d.cts +10 -0
  45. package/dist/NotificationServicesController/processors/process-api-notifications.d.cts.map +1 -0
  46. package/dist/NotificationServicesController/processors/process-api-notifications.d.mts +10 -0
  47. package/dist/NotificationServicesController/processors/process-api-notifications.d.mts.map +1 -0
  48. package/dist/NotificationServicesController/processors/process-api-notifications.mjs +18 -0
  49. package/dist/NotificationServicesController/processors/process-api-notifications.mjs.map +1 -0
  50. package/dist/NotificationServicesController/processors/process-feature-announcement.cjs +2 -7
  51. package/dist/NotificationServicesController/processors/process-feature-announcement.cjs.map +1 -1
  52. package/dist/NotificationServicesController/processors/process-feature-announcement.d.cts.map +1 -1
  53. package/dist/NotificationServicesController/processors/process-feature-announcement.d.mts.map +1 -1
  54. package/dist/NotificationServicesController/processors/process-feature-announcement.mjs +1 -6
  55. package/dist/NotificationServicesController/processors/process-feature-announcement.mjs.map +1 -1
  56. package/dist/NotificationServicesController/processors/process-notifications.cjs +3 -3
  57. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  58. package/dist/NotificationServicesController/processors/process-notifications.d.cts +398 -458
  59. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  60. package/dist/NotificationServicesController/processors/process-notifications.d.mts +398 -458
  61. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  62. package/dist/NotificationServicesController/processors/process-notifications.mjs +4 -4
  63. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  64. package/dist/NotificationServicesController/services/{onchain-notifications.cjs → api-notifications.cjs} +28 -15
  65. package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -0
  66. package/dist/NotificationServicesController/services/{onchain-notifications.d.cts → api-notifications.d.cts} +9 -7
  67. package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -0
  68. package/dist/NotificationServicesController/services/{onchain-notifications.d.mts → api-notifications.d.mts} +9 -7
  69. package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -0
  70. package/dist/NotificationServicesController/services/{onchain-notifications.mjs → api-notifications.mjs} +26 -13
  71. package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -0
  72. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  73. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  74. package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -1
  75. package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -1
  76. package/dist/NotificationServicesController/services/perp-notifications.cjs +0 -1
  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 +0 -1
  81. package/dist/NotificationServicesController/services/perp-notifications.mjs.map +1 -1
  82. package/dist/NotificationServicesController/types/index.cjs.map +1 -1
  83. package/dist/NotificationServicesController/types/index.d.cts +1 -1
  84. package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
  85. package/dist/NotificationServicesController/types/index.d.mts +1 -1
  86. package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
  87. package/dist/NotificationServicesController/types/index.mjs.map +1 -1
  88. package/dist/NotificationServicesController/types/notification/notification.cjs.map +1 -1
  89. package/dist/NotificationServicesController/types/notification/notification.d.cts +3 -11
  90. package/dist/NotificationServicesController/types/notification/notification.d.cts.map +1 -1
  91. package/dist/NotificationServicesController/types/notification/notification.d.mts +3 -11
  92. package/dist/NotificationServicesController/types/notification/notification.d.mts.map +1 -1
  93. package/dist/NotificationServicesController/types/notification/notification.mjs.map +1 -1
  94. package/dist/NotificationServicesController/types/notification-api/index.cjs.map +1 -0
  95. package/dist/NotificationServicesController/types/notification-api/index.d.cts +3 -0
  96. package/dist/NotificationServicesController/types/notification-api/index.d.cts.map +1 -0
  97. package/dist/NotificationServicesController/types/notification-api/index.d.mts +3 -0
  98. package/dist/NotificationServicesController/types/notification-api/index.d.mts.map +1 -0
  99. package/dist/NotificationServicesController/types/notification-api/index.mjs.map +1 -0
  100. package/dist/NotificationServicesController/types/{on-chain-notification/on-chain-notification.cjs → notification-api/notification-api.cjs} +1 -1
  101. package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -0
  102. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +64 -0
  103. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -0
  104. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +64 -0
  105. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -0
  106. package/dist/NotificationServicesController/types/notification-api/notification-api.mjs +2 -0
  107. package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -0
  108. package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -0
  109. package/dist/NotificationServicesController/types/notification-api/schema.d.cts +365 -0
  110. package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -0
  111. package/dist/NotificationServicesController/types/notification-api/schema.d.mts +365 -0
  112. package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -0
  113. package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -0
  114. package/dist/NotificationServicesController/ui/constants.d.cts +27 -27
  115. package/dist/NotificationServicesController/ui/constants.d.mts +27 -27
  116. package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
  117. package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
  118. package/dist/NotificationServicesController/utils/should-auto-expire.cjs +12 -0
  119. package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -0
  120. package/dist/NotificationServicesController/utils/should-auto-expire.d.cts +2 -0
  121. package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -0
  122. package/dist/NotificationServicesController/utils/should-auto-expire.d.mts +2 -0
  123. package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -0
  124. package/dist/NotificationServicesController/utils/should-auto-expire.mjs +8 -0
  125. package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -0
  126. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +8 -8
  127. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  128. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +4 -4
  129. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  130. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +4 -4
  131. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  132. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +8 -8
  133. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  134. package/dist/NotificationServicesPushController/services/push/push-web.cjs +5 -2
  135. package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +1 -1
  136. package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +1 -1
  137. package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +1 -1
  138. package/dist/NotificationServicesPushController/services/push/push-web.mjs +6 -3
  139. package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +1 -1
  140. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  141. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  142. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
  143. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
  144. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +51 -43
  145. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  146. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +4 -2
  147. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  148. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +4 -2
  149. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  150. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +51 -43
  151. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  152. package/dist/NotificationServicesPushController/web/push-utils.cjs +5 -2
  153. package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -1
  154. package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -1
  155. package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -1
  156. package/dist/NotificationServicesPushController/web/push-utils.mjs +6 -3
  157. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
  158. package/dist/shared/is-onchain-notification.cjs +1 -2
  159. package/dist/shared/is-onchain-notification.cjs.map +1 -1
  160. package/dist/shared/is-onchain-notification.d.cts.map +1 -1
  161. package/dist/shared/is-onchain-notification.d.mts.map +1 -1
  162. package/dist/shared/is-onchain-notification.mjs +1 -2
  163. package/dist/shared/is-onchain-notification.mjs.map +1 -1
  164. package/dist/shared/to-raw-notification.cjs +22 -6
  165. package/dist/shared/to-raw-notification.cjs.map +1 -1
  166. package/dist/shared/to-raw-notification.d.cts +2 -2
  167. package/dist/shared/to-raw-notification.d.cts.map +1 -1
  168. package/dist/shared/to-raw-notification.d.mts +2 -2
  169. package/dist/shared/to-raw-notification.d.mts.map +1 -1
  170. package/dist/shared/to-raw-notification.mjs +20 -4
  171. package/dist/shared/to-raw-notification.mjs.map +1 -1
  172. package/package.json +11 -8
  173. package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs +0 -19
  174. package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs.map +0 -1
  175. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts +0 -10
  176. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts.map +0 -1
  177. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts +0 -10
  178. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts.map +0 -1
  179. package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs +0 -15
  180. package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs.map +0 -1
  181. package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +0 -1
  182. package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +0 -1
  183. package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +0 -1
  184. package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +0 -1
  185. package/dist/NotificationServicesController/types/on-chain-notification/index.cjs.map +0 -1
  186. package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts +0 -2
  187. package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts.map +0 -1
  188. package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts +0 -2
  189. package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts.map +0 -1
  190. package/dist/NotificationServicesController/types/on-chain-notification/index.mjs.map +0 -1
  191. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.cjs.map +0 -1
  192. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts +0 -49
  193. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts.map +0 -1
  194. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts +0 -49
  195. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts.map +0 -1
  196. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs +0 -2
  197. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs.map +0 -1
  198. package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs.map +0 -1
  199. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts +0 -681
  200. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts.map +0 -1
  201. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts +0 -681
  202. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts.map +0 -1
  203. package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs.map +0 -1
  204. /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.cjs +0 -0
  205. /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.mjs +0 -0
  206. /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/schema.cjs +0 -0
  207. /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/schema.mjs +0 -0
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
+ ## [20.0.0]
11
+
12
+ ### Changed
13
+
14
+ - **BREAKING:** Moved Notification API from v2 to v3 ([#7102](https://github.com/MetaMask/core/pull/7102))
15
+ - API Endpoint Changes: Updated from `/api/v2/notifications` to `/api/v3/notifications` for listing notifications and marking as read
16
+ - Request Format: The list notifications endpoint now expects `{ addresses: string[], locale?: string }` instead of `{ address: string }[]`
17
+ - Response Structure: Notifications now include a `notification_type` field ('on-chain' or 'platform') and nested payload structure
18
+ - On-chain notifications: data moved from root level to `payload.data`
19
+ - Platform notifications: new type with `template` containing localized content (`title`, `body`, `image_url`, `cta`)
20
+ - Type System Overhaul:
21
+ - `OnChainRawNotification` → `NormalisedAPINotification` (union of on-chain and platform)
22
+ - `UnprocessedOnChainRawNotification` → `UnprocessedRawNotification`
23
+ - Removed specific DeFi notification types (Aave, ENS, Lido rewards, etc.) - now will be handled generically
24
+ - Added `TRIGGER_TYPES.PLATFORM` for platform notifications
25
+ - Function Signatures:
26
+ - `getOnChainNotifications()` → `getAPINotifications()` with new `locale` parameter
27
+ - `getOnChainNotificationsConfigCached()` → `getNotificationsApiConfigCached()`
28
+ - `processOnChainNotification()` → `processAPINotifications()`
29
+ - Service Imports: Update imports from `onchain-notifications` to `api-notifications`
30
+ - Auto-expiry: Reduced from 90 days to 30 days for notification auto-expiry
31
+ - Locale Support: Added locale parameter to controller constructor for localized server notifications
32
+
33
+ ## [19.0.0]
34
+
35
+ ### Changed
36
+
37
+ - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6538](https://github.com/MetaMask/core/pull/6538))
38
+ - Previously, `NotificationServicesController` and `NotificationServicesPushController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
39
+ - **BREAKING:** Metadata property `anonymous` renamed to `includeInDebugSnapshot` ([#6538](https://github.com/MetaMask/core/pull/6538))
40
+ - **BREAKING:** Bump `@metamask/keyring-controller` from `^23.0.0` to `^24.0.0` ([#6962](https://github.com/MetaMask/core/pull/6962))
41
+ - **BREAKING:** Bump `@metamask/profile-sync-controller` from `^25.0.0` to `^26.0.0` ([#6962](https://github.com/MetaMask/core/pull/6962))
42
+ - Bump `@metamask/base-controller` from `^8.4.2` to `^9.0.0` ([#6962](https://github.com/MetaMask/core/pull/6962))
43
+
44
+ ### Removed
45
+
46
+ - **BREAKING:** Remove package-level exports of `AllowedActions` and `AllowedEvents` from `NotificationServicesController` and `NotificationServicesPushController` ([#6538](https://github.com/MetaMask/core/pull/6538))
47
+
10
48
  ## [18.3.1]
11
49
 
12
50
  ### Changed
@@ -582,7 +620,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
582
620
 
583
621
  - Initial release
584
622
 
585
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.3.1...HEAD
623
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@20.0.0...HEAD
624
+ [20.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@19.0.0...@metamask/notification-services-controller@20.0.0
625
+ [19.0.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.3.1...@metamask/notification-services-controller@19.0.0
586
626
  [18.3.1]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.3.0...@metamask/notification-services-controller@18.3.1
587
627
  [18.3.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.2.0...@metamask/notification-services-controller@18.3.0
588
628
  [18.2.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@18.1.0...@metamask/notification-services-controller@18.2.0
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
26
3
  if (kind === "m") throw new TypeError("Private method is not writable");
27
4
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
@@ -36,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
15
  };
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;
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;
40
17
  Object.defineProperty(exports, "__esModule", { value: true });
41
18
  exports.defaultState = void 0;
42
19
  const base_controller_1 = require("@metamask/base-controller");
@@ -46,8 +23,8 @@ const utils_1 = require("@metamask/utils");
46
23
  const loglevel_1 = __importDefault(require("loglevel"));
47
24
  const notification_schema_1 = require("./constants/notification-schema.cjs");
48
25
  const process_notifications_1 = require("./processors/process-notifications.cjs");
49
- const FeatureNotifications = __importStar(require("./services/feature-announcements.cjs"));
50
- const OnChainNotifications = __importStar(require("./services/onchain-notifications.cjs"));
26
+ const api_notifications_1 = require("./services/api-notifications.cjs");
27
+ const feature_announcements_1 = require("./services/feature-announcements.cjs");
51
28
  const perp_notifications_1 = require("./services/perp-notifications.cjs");
52
29
  // Unique name for the controller
53
30
  const controllerName = 'NotificationServicesController';
@@ -55,61 +32,61 @@ const metadata = {
55
32
  subscriptionAccountsSeen: {
56
33
  includeInStateLogs: true,
57
34
  persist: true,
58
- anonymous: true,
35
+ includeInDebugSnapshot: true,
59
36
  usedInUi: true,
60
37
  },
61
38
  isMetamaskNotificationsFeatureSeen: {
62
39
  includeInStateLogs: true,
63
40
  persist: true,
64
- anonymous: false,
41
+ includeInDebugSnapshot: false,
65
42
  usedInUi: true,
66
43
  },
67
44
  isNotificationServicesEnabled: {
68
45
  includeInStateLogs: true,
69
46
  persist: true,
70
- anonymous: false,
47
+ includeInDebugSnapshot: false,
71
48
  usedInUi: true,
72
49
  },
73
50
  isFeatureAnnouncementsEnabled: {
74
51
  includeInStateLogs: true,
75
52
  persist: true,
76
- anonymous: false,
53
+ includeInDebugSnapshot: false,
77
54
  usedInUi: true,
78
55
  },
79
56
  metamaskNotificationsList: {
80
57
  includeInStateLogs: true,
81
58
  persist: true,
82
- anonymous: true,
59
+ includeInDebugSnapshot: true,
83
60
  usedInUi: true,
84
61
  },
85
62
  metamaskNotificationsReadList: {
86
63
  includeInStateLogs: false,
87
64
  persist: true,
88
- anonymous: true,
65
+ includeInDebugSnapshot: true,
89
66
  usedInUi: true,
90
67
  },
91
68
  isUpdatingMetamaskNotifications: {
92
69
  includeInStateLogs: false,
93
70
  persist: false,
94
- anonymous: false,
71
+ includeInDebugSnapshot: false,
95
72
  usedInUi: true,
96
73
  },
97
74
  isFetchingMetamaskNotifications: {
98
75
  includeInStateLogs: false,
99
76
  persist: false,
100
- anonymous: false,
77
+ includeInDebugSnapshot: false,
101
78
  usedInUi: true,
102
79
  },
103
80
  isUpdatingMetamaskNotificationsAccount: {
104
81
  includeInStateLogs: false,
105
82
  persist: false,
106
- anonymous: false,
83
+ includeInDebugSnapshot: false,
107
84
  usedInUi: true,
108
85
  },
109
86
  isCheckingAccountsPresence: {
110
87
  includeInStateLogs: false,
111
88
  persist: false,
112
- anonymous: false,
89
+ includeInDebugSnapshot: false,
113
90
  usedInUi: true,
114
91
  },
115
92
  };
@@ -140,7 +117,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
140
117
  * @param args.state - Initial state to set on this controller.
141
118
  * @param args.env - environment variables for a given controller.
142
119
  * @param args.env.featureAnnouncements - env variables for feature announcements.
143
- * @param args.env.isPushIntegrated - toggle push notifications on/off if client has integrated them.
120
+ * @param args.env.locale - users locale for better dynamic server notifications
144
121
  */
145
122
  constructor({ messenger, state, env, }) {
146
123
  super({
@@ -153,29 +130,29 @@ class NotificationServicesController extends base_controller_1.BaseController {
153
130
  _NotificationServicesController_keyringController.set(this, {
154
131
  isUnlocked: false,
155
132
  setupLockedStateSubscriptions: (onUnlock) => {
156
- const { isUnlocked } = this.messagingSystem.call('KeyringController:getState');
133
+ const { isUnlocked } = this.messenger.call('KeyringController:getState');
157
134
  __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = isUnlocked;
158
- this.messagingSystem.subscribe('KeyringController:unlock', () => {
135
+ this.messenger.subscribe('KeyringController:unlock', () => {
159
136
  __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = true;
160
137
  // messaging system cannot await promises
161
138
  // we don't need to wait for a result on this.
162
139
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
163
140
  onUnlock();
164
141
  });
165
- this.messagingSystem.subscribe('KeyringController:lock', () => {
142
+ this.messenger.subscribe('KeyringController:lock', () => {
166
143
  __classPrivateFieldGet(this, _NotificationServicesController_keyringController, "f").isUnlocked = false;
167
144
  });
168
145
  },
169
146
  });
170
147
  _NotificationServicesController_auth.set(this, {
171
148
  getBearerToken: async () => {
172
- return await this.messagingSystem.call('AuthenticationController:getBearerToken');
149
+ return await this.messenger.call('AuthenticationController:getBearerToken');
173
150
  },
174
151
  isSignedIn: () => {
175
- return this.messagingSystem.call('AuthenticationController:isSignedIn');
152
+ return this.messenger.call('AuthenticationController:isSignedIn');
176
153
  },
177
154
  signIn: async () => {
178
- return await this.messagingSystem.call('AuthenticationController:performSignIn');
155
+ return await this.messenger.call('AuthenticationController:performSignIn');
179
156
  },
180
157
  });
181
158
  _NotificationServicesController_pushNotifications.set(this, {
@@ -184,11 +161,11 @@ class NotificationServicesController extends base_controller_1.BaseController {
184
161
  // To ensure we subscribe to the most up-to-date notifications
185
162
  isSetup: false,
186
163
  subscribeToPushNotifications: async () => {
187
- await this.messagingSystem.call('NotificationServicesPushController:subscribeToPushNotifications');
164
+ await this.messenger.call('NotificationServicesPushController:subscribeToPushNotifications');
188
165
  },
189
166
  enablePushNotifications: async (addresses) => {
190
167
  try {
191
- await this.messagingSystem.call('NotificationServicesPushController:enablePushNotifications', addresses);
168
+ await this.messenger.call('NotificationServicesPushController:enablePushNotifications', addresses);
192
169
  }
193
170
  catch (e) {
194
171
  loglevel_1.default.error('Silently failed to enable push notifications', e);
@@ -196,14 +173,14 @@ class NotificationServicesController extends base_controller_1.BaseController {
196
173
  },
197
174
  disablePushNotifications: async () => {
198
175
  try {
199
- await this.messagingSystem.call('NotificationServicesPushController:disablePushNotifications');
176
+ await this.messenger.call('NotificationServicesPushController:disablePushNotifications');
200
177
  }
201
178
  catch (e) {
202
179
  loglevel_1.default.error('Silently failed to disable push notifications', e);
203
180
  }
204
181
  },
205
182
  subscribe: () => {
206
- this.messagingSystem.subscribe('NotificationServicesPushController:onNewNotifications', (notification) => {
183
+ this.messenger.subscribe('NotificationServicesPushController:onNewNotifications', (notification) => {
207
184
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
208
185
  this.updateMetamaskNotificationsList(notification);
209
186
  });
@@ -237,7 +214,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
237
214
  // Flag to ensure we only setup once
238
215
  isNotificationAccountsSetup: false,
239
216
  getNotificationAccounts: () => {
240
- const { keyrings } = this.messagingSystem.call('KeyringController:getState');
217
+ const { keyrings } = this.messenger.call('KeyringController:getState');
241
218
  const firstHDKeyring = keyrings.find((k) => k.type === keyring_controller_1.KeyringTypes.hd.toString());
242
219
  const keyringAccounts = firstHDKeyring?.accounts ?? null;
243
220
  return keyringAccounts;
@@ -300,7 +277,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
300
277
  * And call effects to subscribe/unsubscribe to notifications.
301
278
  */
302
279
  subscribe: () => {
303
- this.messagingSystem.subscribe('KeyringController:stateChange', async (totalAccounts, prevTotalAccounts) => {
280
+ this.messenger.subscribe('KeyringController:stateChange', async (totalAccounts, prevTotalAccounts) => {
304
281
  const hasTotalAccountsChanged = totalAccounts !== prevTotalAccounts;
305
282
  if (!this.state.isNotificationServicesEnabled ||
306
283
  !hasTotalAccountsChanged) {
@@ -321,8 +298,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
321
298
  });
322
299
  },
323
300
  });
301
+ _NotificationServicesController_locale.set(this, void 0);
324
302
  _NotificationServicesController_featureAnnouncementEnv.set(this, void 0);
325
303
  __classPrivateFieldSet(this, _NotificationServicesController_featureAnnouncementEnv, env.featureAnnouncements, "f");
304
+ __classPrivateFieldSet(this, _NotificationServicesController_locale, env.locale ?? (() => 'en'), "f");
326
305
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_registerMessageHandlers).call(this);
327
306
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_clearLoadingStates).call(this);
328
307
  }
@@ -344,7 +323,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
344
323
  try {
345
324
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
346
325
  const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
347
- const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
326
+ const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts);
348
327
  const addresses = addressesWithNotifications
349
328
  .filter((a) => Boolean(a.enabled))
350
329
  .map((a) => a.address);
@@ -367,7 +346,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
367
346
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsCheckingAccountsPresence).call(this, true);
368
347
  // Retrieve user storage
369
348
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
370
- const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
349
+ const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts);
371
350
  const result = {};
372
351
  addressesWithNotifications.forEach((a) => {
373
352
  result[a.address] = a.enabled;
@@ -419,7 +398,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
419
398
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
420
399
  const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
421
400
  // 1. See if has enabled notifications before
422
- const addressesWithNotifications = await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts);
401
+ const addressesWithNotifications = await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts);
423
402
  // Notifications API can return array with addresses set to false
424
403
  // So assert that at least one address is enabled
425
404
  let accountsWithNotifications = addressesWithNotifications
@@ -427,7 +406,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
427
406
  .map((a) => a.address);
428
407
  // 2. Enable Notifications (if no accounts subscribed or we are resetting)
429
408
  if (accountsWithNotifications.length === 0 || opts?.resetNotifications) {
430
- await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
409
+ await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })));
431
410
  accountsWithNotifications = accounts;
432
411
  }
433
412
  // 3. Lazily enable push notifications (FCM may take some time, so keeps UI unblocked)
@@ -519,7 +498,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
519
498
  // Get and Validate BearerToken and User Storage Key
520
499
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
521
500
  // Delete these UUIDs (Mutates User Storage)
522
- await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: false })));
501
+ await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: false })));
523
502
  }
524
503
  catch (err) {
525
504
  loglevel_1.default.error('Failed to delete OnChain triggers', err);
@@ -548,7 +527,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
548
527
  try {
549
528
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_updateUpdatingAccountsState).call(this, accounts);
550
529
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
551
- await OnChainNotifications.updateOnChainNotifications(bearerToken, accounts.map((address) => ({ address, enabled: true })));
530
+ await (0, api_notifications_1.updateOnChainNotifications)(bearerToken, accounts.map((address) => ({ address, enabled: true })));
552
531
  }
553
532
  catch (err) {
554
533
  loglevel_1.default.error('Failed to update OnChain triggers', err);
@@ -576,7 +555,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
576
555
  const isGlobalNotifsEnabled = this.state.isNotificationServicesEnabled;
577
556
  // Raw Feature Notifications
578
557
  const rawAnnouncements = isGlobalNotifsEnabled && this.state.isFeatureAnnouncementsEnabled
579
- ? await FeatureNotifications.getFeatureAnnouncementNotifications(__classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f"), previewToken).catch(() => [])
558
+ ? await (0, feature_announcements_1.getFeatureAnnouncementNotifications)(__classPrivateFieldGet(this, _NotificationServicesController_featureAnnouncementEnv, "f"), previewToken).catch(() => [])
580
559
  : [];
581
560
  // Raw On Chain Notifications
582
561
  const rawOnChainNotifications = [];
@@ -584,10 +563,10 @@ class NotificationServicesController extends base_controller_1.BaseController {
584
563
  try {
585
564
  const { bearerToken } = await __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_getBearerToken).call(this);
586
565
  const { accounts } = __classPrivateFieldGet(this, _NotificationServicesController_accounts, "f").listAccounts();
587
- const addressesWithNotifications = (await OnChainNotifications.getOnChainNotificationsConfigCached(bearerToken, accounts))
566
+ const addressesWithNotifications = (await (0, api_notifications_1.getNotificationsApiConfigCached)(bearerToken, accounts))
588
567
  .filter((a) => Boolean(a.enabled))
589
568
  .map((a) => a.address);
590
- const notifications = await OnChainNotifications.getOnChainNotifications(bearerToken, addressesWithNotifications).catch(() => []);
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(() => []);
591
570
  rawOnChainNotifications.push(...notifications);
592
571
  }
593
572
  catch {
@@ -610,7 +589,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
610
589
  this.update((state) => {
611
590
  state.metamaskNotificationsList = metamaskNotifications;
612
591
  });
613
- this.messagingSystem.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
592
+ this.messenger.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
614
593
  __classPrivateFieldGet(this, _NotificationServicesController_instances, "m", _NotificationServicesController_setIsFetchingMetamaskNotifications).call(this, false);
615
594
  return metamaskNotifications;
616
595
  }
@@ -664,7 +643,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
664
643
  for (const id of ids) {
665
644
  await this.deleteNotificationById(id);
666
645
  }
667
- this.messagingSystem.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
646
+ this.messenger.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
668
647
  }
669
648
  /**
670
649
  * Marks specified metamask notifications as read.
@@ -697,7 +676,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
697
676
  const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesController_auth, "f").getBearerToken();
698
677
  if (bearerToken) {
699
678
  onchainNotificationIds = onChainNotifications.map((notification) => notification.id);
700
- await OnChainNotifications.markNotificationsAsRead(bearerToken, onchainNotificationIds).catch(() => {
679
+ await (0, api_notifications_1.markNotificationsAsRead)(bearerToken, onchainNotificationIds).catch(() => {
701
680
  onchainNotificationIds = [];
702
681
  loglevel_1.default.warn('Unable to mark onchain notifications as read');
703
682
  });
@@ -740,7 +719,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
740
719
  return notification;
741
720
  });
742
721
  });
743
- this.messagingSystem.publish(`${controllerName}:markNotificationsAsRead`, this.state.metamaskNotificationsList);
722
+ this.messenger.publish(`${controllerName}:markNotificationsAsRead`, this.state.metamaskNotificationsList);
744
723
  }
745
724
  /**
746
725
  * Updates the list of MetaMask notifications by adding a new notification at the beginning of the list.
@@ -765,7 +744,7 @@ class NotificationServicesController extends base_controller_1.BaseController {
765
744
  ];
766
745
  }
767
746
  });
768
- this.messagingSystem.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
747
+ this.messenger.publish(`${controllerName}:notificationsListUpdated`, this.state.metamaskNotificationsList);
769
748
  }
770
749
  }
771
750
  /**
@@ -784,11 +763,11 @@ class NotificationServicesController extends base_controller_1.BaseController {
784
763
  }
785
764
  }
786
765
  }
787
- _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() {
788
- this.messagingSystem.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
789
- this.messagingSystem.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
790
- this.messagingSystem.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
791
- this.messagingSystem.registerActionHandler(`${controllerName}:deleteNotificationsById`, this.deleteNotificationsById.bind(this));
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() {
767
+ this.messenger.registerActionHandler(`${controllerName}:updateMetamaskNotificationsList`, this.updateMetamaskNotificationsList.bind(this));
768
+ this.messenger.registerActionHandler(`${controllerName}:disableNotificationServices`, this.disableNotificationServices.bind(this));
769
+ this.messenger.registerActionHandler(`${controllerName}:getNotificationsByType`, this.getNotificationsByType.bind(this));
770
+ this.messenger.registerActionHandler(`${controllerName}:deleteNotificationsById`, this.deleteNotificationsById.bind(this));
792
771
  }, _NotificationServicesController_clearLoadingStates = function _NotificationServicesController_clearLoadingStates() {
793
772
  this.update((state) => {
794
773
  state.isUpdatingMetamaskNotifications = false;