@metamask/notification-services-controller 19.0.0 → 21.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 (227) hide show
  1. package/CHANGELOG.md +36 -2
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +20 -38
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +5 -2
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +5 -2
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +20 -15
  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 +5 -5
  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} +57 -24
  65. package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -0
  66. package/dist/NotificationServicesController/services/{onchain-notifications.d.cts → api-notifications.d.cts} +20 -13
  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} +20 -13
  69. package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -0
  70. package/dist/NotificationServicesController/services/{onchain-notifications.mjs → api-notifications.mjs} +49 -22
  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 +4 -0
  109. package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -0
  110. package/dist/NotificationServicesController/types/notification-api/schema.d.cts +365 -0
  111. package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -0
  112. package/dist/NotificationServicesController/types/notification-api/schema.d.mts +365 -0
  113. package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -0
  114. package/dist/NotificationServicesController/types/notification-api/schema.mjs +3 -0
  115. package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -0
  116. package/dist/NotificationServicesController/ui/constants.d.cts +27 -27
  117. package/dist/NotificationServicesController/ui/constants.d.mts +27 -27
  118. package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
  119. package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
  120. package/dist/NotificationServicesController/utils/should-auto-expire.cjs +12 -0
  121. package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -0
  122. package/dist/NotificationServicesController/utils/should-auto-expire.d.cts +2 -0
  123. package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -0
  124. package/dist/NotificationServicesController/utils/should-auto-expire.d.mts +2 -0
  125. package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -0
  126. package/dist/NotificationServicesController/utils/should-auto-expire.mjs +8 -0
  127. package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -0
  128. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +2 -0
  129. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  130. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +2 -0
  131. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  132. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +2 -0
  133. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  134. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +2 -0
  135. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  136. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +1 -1
  137. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
  138. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +1 -1
  139. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
  140. package/dist/NotificationServicesPushController/services/endpoints.cjs +10 -3
  141. package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
  142. package/dist/NotificationServicesPushController/services/endpoints.d.cts +3 -1
  143. package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
  144. package/dist/NotificationServicesPushController/services/endpoints.d.mts +3 -1
  145. package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
  146. package/dist/NotificationServicesPushController/services/endpoints.mjs +7 -2
  147. package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
  148. package/dist/NotificationServicesPushController/services/push/push-web.cjs +5 -2
  149. package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +1 -1
  150. package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +1 -1
  151. package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +1 -1
  152. package/dist/NotificationServicesPushController/services/push/push-web.mjs +6 -3
  153. package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +1 -1
  154. package/dist/NotificationServicesPushController/services/services.cjs +2 -1
  155. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  156. package/dist/NotificationServicesPushController/services/services.d.cts +3 -0
  157. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  158. package/dist/NotificationServicesPushController/services/services.d.mts +3 -0
  159. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  160. package/dist/NotificationServicesPushController/services/services.mjs +2 -1
  161. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  162. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
  163. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
  164. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +51 -43
  165. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  166. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +4 -2
  167. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  168. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +4 -2
  169. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  170. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +51 -43
  171. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  172. package/dist/NotificationServicesPushController/web/push-utils.cjs +5 -2
  173. package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -1
  174. package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -1
  175. package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -1
  176. package/dist/NotificationServicesPushController/web/push-utils.mjs +6 -3
  177. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
  178. package/dist/shared/is-onchain-notification.cjs +1 -2
  179. package/dist/shared/is-onchain-notification.cjs.map +1 -1
  180. package/dist/shared/is-onchain-notification.d.cts.map +1 -1
  181. package/dist/shared/is-onchain-notification.d.mts.map +1 -1
  182. package/dist/shared/is-onchain-notification.mjs +1 -2
  183. package/dist/shared/is-onchain-notification.mjs.map +1 -1
  184. package/dist/shared/to-raw-notification.cjs +22 -6
  185. package/dist/shared/to-raw-notification.cjs.map +1 -1
  186. package/dist/shared/to-raw-notification.d.cts +2 -2
  187. package/dist/shared/to-raw-notification.d.cts.map +1 -1
  188. package/dist/shared/to-raw-notification.d.mts +2 -2
  189. package/dist/shared/to-raw-notification.d.mts.map +1 -1
  190. package/dist/shared/to-raw-notification.mjs +20 -4
  191. package/dist/shared/to-raw-notification.mjs.map +1 -1
  192. package/package.json +9 -7
  193. package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs +0 -19
  194. package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs.map +0 -1
  195. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts +0 -10
  196. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts.map +0 -1
  197. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts +0 -10
  198. package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts.map +0 -1
  199. package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs +0 -15
  200. package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs.map +0 -1
  201. package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +0 -1
  202. package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +0 -1
  203. package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +0 -1
  204. package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +0 -1
  205. package/dist/NotificationServicesController/types/on-chain-notification/index.cjs.map +0 -1
  206. package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts +0 -2
  207. package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts.map +0 -1
  208. package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts +0 -2
  209. package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts.map +0 -1
  210. package/dist/NotificationServicesController/types/on-chain-notification/index.mjs.map +0 -1
  211. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.cjs.map +0 -1
  212. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts +0 -49
  213. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts.map +0 -1
  214. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts +0 -49
  215. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts.map +0 -1
  216. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs +0 -2
  217. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs.map +0 -1
  218. package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs +0 -10
  219. package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs.map +0 -1
  220. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts +0 -681
  221. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts.map +0 -1
  222. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts +0 -681
  223. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts.map +0 -1
  224. package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs +0 -9
  225. package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs.map +0 -1
  226. /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.cjs +0 -0
  227. /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.mjs +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"process-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,6CAAyC;AAEjE,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACrB,+CAA2C;AAiB5C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,oBAAoB,EAClC,iBAAiB,GAAE,MAAM,EAAO,GAC/B,aAAa,CAuBf;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,oBAAoB,EAClC,iBAAiB,GAAE,MAAM,EAAO,GAC/B,aAAa,GAAG,SAAS,CAU3B;AAGD,eAAO,MAAM,6BAA6B,OACpC,oBAAoB,EAAE,WACjB,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAC2D,CAAC"}
1
+ {"version":3,"file":"process-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,aAAa,EAEd,6CAAyC;AAE1C,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACrB,+CAA2C;AAkB5C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,oBAAoB,EAClC,iBAAiB,GAAE,MAAM,EAAO,GAC/B,aAAa,CAuBf;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,oBAAoB,EAClC,iBAAiB,GAAE,MAAM,EAAO,GAC/B,aAAa,GAAG,SAAS,CAU3B;AAGD,eAAO,MAAM,6BAA6B,OACpC,oBAAoB,EAAE,WACjB,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAC2D,CAAC"}
@@ -1,8 +1,8 @@
1
+ import { processAPINotifications } from "./process-api-notifications.mjs";
1
2
  import { isFeatureAnnouncementRead, processFeatureAnnouncement } from "./process-feature-announcement.mjs";
2
- import { processOnChainNotification } from "./process-onchain-notifications.mjs";
3
3
  import { processSnapNotification } from "./process-snap-notifications.mjs";
4
- import { TRIGGER_TYPES } from "../constants/notification-schema.mjs";
5
- const isOnChainNotification = (n) => Object.values(TRIGGER_TYPES).includes(n.type);
4
+ import { TRIGGER_TYPES, NOTIFICATION_API_TRIGGER_TYPES_SET } from "../constants/notification-schema.mjs";
5
+ const isOnChainNotification = (n) => NOTIFICATION_API_TRIGGER_TYPES_SET.has(n.type);
6
6
  const isFeatureAnnouncement = (n) => n.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;
7
7
  const isSnapNotification = (n) => n.type === TRIGGER_TYPES.SNAP;
8
8
  /**
@@ -27,7 +27,7 @@ export function processNotification(notification, readNotifications = []) {
27
27
  return processSnapNotification(notification);
28
28
  }
29
29
  if (isOnChainNotification(notification)) {
30
- return processOnChainNotification(notification);
30
+ return processAPINotifications(notification);
31
31
  }
32
32
  return exhaustedAllCases(notification);
33
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"process-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC3B,2CAAuC;AACxC,OAAO,EAAE,0BAA0B,EAAE,4CAAwC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,yCAAqC;AACvE,OAAO,EAAE,aAAa,EAAE,6CAAyC;AASjE,MAAM,qBAAqB,GAAG,CAC5B,CAAuB,EACM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAEhF,MAAM,qBAAqB,GAAG,CAC5B,CAAuB,EACkB,EAAE,CAC3C,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC,qBAAqB,CAAC;AAEjD,MAAM,kBAAkB,GAAG,CACzB,CAAuB,EACG,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAkC,EAClC,oBAA8B,EAAE;IAEhC,MAAM,iBAAiB,GAAG,CAAC,CAAQ,EAAE,EAAE;QACrC,MAAM,IAAI,GAAW,YAAY,EAAE,IAAI,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,4CAA4C,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC;IAEF,IAAI,qBAAqB,CAAC,YAAY,CAAC,EAAE;QACvC,MAAM,CAAC,GAAG,0BAA0B,CAClC,YAAkD,CACnD,CAAC;QACF,CAAC,CAAC,MAAM,GAAG,yBAAyB,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;QAC3D,OAAO,CAAC,CAAC;KACV;IAED,IAAI,kBAAkB,CAAC,YAAY,CAAC,EAAE;QACpC,OAAO,uBAAuB,CAAC,YAAY,CAAC,CAAC;KAC9C;IAED,IAAI,qBAAqB,CAAC,YAAY,CAAC,EAAE;QACvC,OAAO,0BAA0B,CAAC,YAAY,CAAC,CAAC;KACjD;IAED,OAAO,iBAAiB,CAAC,YAAqB,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAAkC,EAClC,oBAA8B,EAAE;IAEhC,IAAI;QACF,MAAM,qBAAqB,GAAG,mBAAmB,CAC/C,YAAY,EACZ,iBAAiB,CAClB,CAAC;QACF,OAAO,qBAAqB,CAAC;KAC9B;IAAC,MAAM;QACN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAED,MAAM,cAAc,GAAG,CAAO,CAAQ,EAAa,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,EAA0B,EAC1B,OAAiB,EACjB,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import {\n isFeatureAnnouncementRead,\n processFeatureAnnouncement,\n} from './process-feature-announcement';\nimport { processOnChainNotification } from './process-onchain-notifications';\nimport { processSnapNotification } from './process-snap-notifications';\nimport { TRIGGER_TYPES } from '../constants/notification-schema';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n INotification,\n RawNotificationUnion,\n} from '../types/notification/notification';\nimport type { OnChainRawNotification } from '../types/on-chain-notification/on-chain-notification';\nimport type { RawSnapNotification } from '../types/snaps';\n\nconst isOnChainNotification = (\n n: RawNotificationUnion,\n): n is OnChainRawNotification => Object.values(TRIGGER_TYPES).includes(n.type);\n\nconst isFeatureAnnouncement = (\n n: RawNotificationUnion,\n): n is FeatureAnnouncementRawNotification =>\n n.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n\nconst isSnapNotification = (\n n: RawNotificationUnion,\n): n is RawSnapNotification => n.type === TRIGGER_TYPES.SNAP;\n\n/**\n * Process feature announcement and wallet notifications into a shared/normalised notification shape.\n * We can still differentiate notifications by the `type` property\n *\n * @param notification - a feature announcement or on chain notification\n * @param readNotifications - all read notifications currently\n * @returns a processed notification\n */\nexport function processNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification {\n const exhaustedAllCases = (_: never) => {\n const type: string = notification?.type;\n throw new Error(`No processor found for notification kind ${type}`);\n };\n\n if (isFeatureAnnouncement(notification)) {\n const n = processFeatureAnnouncement(\n notification as FeatureAnnouncementRawNotification,\n );\n n.isRead = isFeatureAnnouncementRead(n, readNotifications);\n return n;\n }\n\n if (isSnapNotification(notification)) {\n return processSnapNotification(notification);\n }\n\n if (isOnChainNotification(notification)) {\n return processOnChainNotification(notification);\n }\n\n return exhaustedAllCases(notification as never);\n}\n\n/**\n * Safe version of processing a notification. Rather than throwing an error if failed to process, it will return the Notification or undefined\n *\n * @param notification - notification to processes\n * @param readNotifications - all read notifications currently\n * @returns a process notification or undefined if failed to process\n */\nexport function safeProcessNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification | undefined {\n try {\n const processedNotification = processNotification(\n notification,\n readNotifications,\n );\n return processedNotification;\n } catch {\n return undefined;\n }\n}\n\nconst isNotUndefined = <Item>(t?: Item): t is Item => Boolean(t);\nexport const processAndFilterNotifications = (\n ns: RawNotificationUnion[],\n readIds: string[],\n) => ns.map((n) => safeProcessNotification(n, readIds)).filter(isNotUndefined);\n"]}
1
+ {"version":3,"file":"process-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,wCAAoC;AACtE,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC3B,2CAAuC;AACxC,OAAO,EAAE,uBAAuB,EAAE,yCAAqC;AACv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MAAM,qBAAqB,GAAG,mBAAmB,CAC/C,YAAY,EACZ,iBAAiB,CAClB,CAAC;QACF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,cAAc,GAAG,CAAO,CAAQ,EAAa,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,EAA0B,EAC1B,OAAiB,EACjB,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { processAPINotifications } from './process-api-notifications';\nimport {\n isFeatureAnnouncementRead,\n processFeatureAnnouncement,\n} from './process-feature-announcement';\nimport { processSnapNotification } from './process-snap-notifications';\nimport {\n TRIGGER_TYPES,\n NOTIFICATION_API_TRIGGER_TYPES_SET,\n} from '../constants/notification-schema';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n INotification,\n RawNotificationUnion,\n} from '../types/notification/notification';\nimport type { NormalisedAPINotification } from '../types/notification-api/notification-api';\nimport type { RawSnapNotification } from '../types/snaps';\n\nconst isOnChainNotification = (\n n: RawNotificationUnion,\n): n is NormalisedAPINotification =>\n NOTIFICATION_API_TRIGGER_TYPES_SET.has(n.type);\n\nconst isFeatureAnnouncement = (\n n: RawNotificationUnion,\n): n is FeatureAnnouncementRawNotification =>\n n.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n\nconst isSnapNotification = (\n n: RawNotificationUnion,\n): n is RawSnapNotification => n.type === TRIGGER_TYPES.SNAP;\n\n/**\n * Process feature announcement and wallet notifications into a shared/normalised notification shape.\n * We can still differentiate notifications by the `type` property\n *\n * @param notification - a feature announcement or on chain notification\n * @param readNotifications - all read notifications currently\n * @returns a processed notification\n */\nexport function processNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification {\n const exhaustedAllCases = (_: never) => {\n const type: string = notification?.type;\n throw new Error(`No processor found for notification kind ${type}`);\n };\n\n if (isFeatureAnnouncement(notification)) {\n const n = processFeatureAnnouncement(\n notification as FeatureAnnouncementRawNotification,\n );\n n.isRead = isFeatureAnnouncementRead(n, readNotifications);\n return n;\n }\n\n if (isSnapNotification(notification)) {\n return processSnapNotification(notification);\n }\n\n if (isOnChainNotification(notification)) {\n return processAPINotifications(notification);\n }\n\n return exhaustedAllCases(notification as never);\n}\n\n/**\n * Safe version of processing a notification. Rather than throwing an error if failed to process, it will return the Notification or undefined\n *\n * @param notification - notification to processes\n * @param readNotifications - all read notifications currently\n * @returns a process notification or undefined if failed to process\n */\nexport function safeProcessNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification | undefined {\n try {\n const processedNotification = processNotification(\n notification,\n readNotifications,\n );\n return processedNotification;\n } catch {\n return undefined;\n }\n}\n\nconst isNotUndefined = <Item>(t?: Item): t is Item => Boolean(t);\nexport const processAndFilterNotifications = (\n ns: RawNotificationUnion[],\n readIds: string[],\n) => ns.map((n) => safeProcessNotification(n, readIds)).filter(isNotUndefined);\n"]}
@@ -3,31 +3,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.markNotificationsAsRead = exports.getOnChainNotifications = exports.updateOnChainNotifications = exports.getOnChainNotificationsConfigCached = exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = exports.NOTIFICATION_API_LIST_ENDPOINT = exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = exports.NOTIFICATION_API = exports.TRIGGER_API = void 0;
6
+ exports.markNotificationsAsRead = exports.getAPINotifications = exports.updateOnChainNotifications = exports.getNotificationsApiConfigCached = exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = exports.NOTIFICATION_API_LIST_ENDPOINT = exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = exports.NOTIFICATION_API = exports.TRIGGER_API = void 0;
7
7
  const loglevel_1 = __importDefault(require("loglevel"));
8
8
  const notification_config_cache_1 = require("./notification-config-cache.cjs");
9
9
  const to_raw_notification_1 = require("../../shared/to-raw-notification.cjs");
10
10
  const utils_1 = require("../utils/utils.cjs");
11
- exports.TRIGGER_API = 'https://trigger.api.cx.metamask.io';
12
- exports.NOTIFICATION_API = 'https://notification.api.cx.metamask.io';
11
+ const TRIGGER_API_ENV = {
12
+ dev: 'https://trigger.dev-api.cx.metamask.io',
13
+ uat: 'https://trigger.uat-api.cx.metamask.io',
14
+ prd: 'https://trigger.api.cx.metamask.io',
15
+ };
16
+ const TRIGGER_API = (env = 'prd') => TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;
17
+ exports.TRIGGER_API = TRIGGER_API;
18
+ const NOTIFICATION_API_ENV = {
19
+ dev: 'https://notification.dev-api.cx.metamask.io',
20
+ uat: 'https://notification.uat-api.cx.metamask.io',
21
+ prd: 'https://notification.api.cx.metamask.io',
22
+ };
23
+ const NOTIFICATION_API = (env = 'prd') => NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;
24
+ exports.NOTIFICATION_API = NOTIFICATION_API;
13
25
  // Gets notification settings for each account provided
14
- exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = `${exports.TRIGGER_API}/api/v2/notifications/query`;
26
+ const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (env = 'prd') => `${(0, exports.TRIGGER_API)(env)}/api/v2/notifications/query`;
27
+ exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT;
15
28
  // Used to create/update account notifications for each account provided
16
- exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = `${exports.TRIGGER_API}/api/v2/notifications`;
29
+ const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env = 'prd') => `${(0, exports.TRIGGER_API)(env)}/api/v2/notifications`;
30
+ exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = TRIGGER_API_NOTIFICATIONS_ENDPOINT;
17
31
  // Lists notifications for each account provided
18
- exports.NOTIFICATION_API_LIST_ENDPOINT = `${exports.NOTIFICATION_API}/api/v2/notifications`;
32
+ const NOTIFICATION_API_LIST_ENDPOINT = (env = 'prd') => `${(0, exports.NOTIFICATION_API)(env)}/api/v3/notifications`;
33
+ exports.NOTIFICATION_API_LIST_ENDPOINT = NOTIFICATION_API_LIST_ENDPOINT;
19
34
  // Makrs notifications as read
20
- exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${exports.NOTIFICATION_API}/api/v2/notifications/mark-as-read`;
35
+ const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env = 'prd') => `${(0, exports.NOTIFICATION_API)(env)}/api/v3/notifications/mark-as-read`;
36
+ exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT;
21
37
  /**
22
38
  * fetches notification config (accounts enabled vs disabled)
23
39
  *
24
40
  * @param bearerToken - jwt
25
41
  * @param addresses - list of addresses to check
42
+ * @param env - the environment to use for the API call
26
43
  * NOTE the API will return addresses config with false if they have not been created before.
27
44
  * NOTE this is cached for 1s to prevent multiple update calls
28
45
  * @returns object of notification config, or null if missing
29
46
  */
30
- async function getOnChainNotificationsConfigCached(bearerToken, addresses) {
47
+ async function getNotificationsApiConfigCached(bearerToken, addresses, env = 'prd') {
31
48
  if (addresses.length === 0) {
32
49
  return [];
33
50
  }
@@ -37,7 +54,7 @@ async function getOnChainNotificationsConfigCached(bearerToken, addresses) {
37
54
  return cached;
38
55
  }
39
56
  const body = addresses.map((address) => ({ address }));
40
- const data = await (0, utils_1.makeApiCall)(bearerToken, exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT, 'POST', body)
57
+ const data = await (0, utils_1.makeApiCall)(bearerToken, (0, exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT)(env), 'POST', body)
41
58
  .then((r) => (r.ok ? r.json() : null))
42
59
  .catch(() => null);
43
60
  const result = data ?? [];
@@ -46,15 +63,16 @@ async function getOnChainNotificationsConfigCached(bearerToken, addresses) {
46
63
  }
47
64
  return result;
48
65
  }
49
- exports.getOnChainNotificationsConfigCached = getOnChainNotificationsConfigCached;
66
+ exports.getNotificationsApiConfigCached = getNotificationsApiConfigCached;
50
67
  /**
51
68
  * updates notifications for a given addresses
52
69
  *
53
70
  * @param bearerToken - jwt
54
71
  * @param addresses - list of addresses to check
72
+ * @param env - the environment to use for the API call
55
73
  * @returns void
56
74
  */
57
- async function updateOnChainNotifications(bearerToken, addresses) {
75
+ async function updateOnChainNotifications(bearerToken, addresses, env = 'prd') {
58
76
  if (addresses.length === 0) {
59
77
  return;
60
78
  }
@@ -63,7 +81,7 @@ async function updateOnChainNotifications(bearerToken, addresses) {
63
81
  return a;
64
82
  });
65
83
  const body = addresses;
66
- await (0, utils_1.makeApiCall)(bearerToken, exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT, 'POST', body)
84
+ await (0, utils_1.makeApiCall)(bearerToken, (0, exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT)(env), 'POST', body)
67
85
  .then(() => notification_config_cache_1.notificationsConfigCache.set(addresses))
68
86
  .catch(() => null);
69
87
  }
@@ -73,29 +91,40 @@ exports.updateOnChainNotifications = updateOnChainNotifications;
73
91
  *
74
92
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
75
93
  * @param addresses - List of addresses
76
- * @returns A promise that resolves to an array of OnChainRawNotification objects. If no triggers are enabled or an error occurs, it may return an empty array.
94
+ * @param locale - to generate translated notifications
95
+ * @param platform - filter notifications for specific platforms ('extension' | 'mobile')
96
+ * @param env - the environment to use for the API call
97
+ * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.
77
98
  */
78
- async function getOnChainNotifications(bearerToken, addresses) {
99
+ async function getAPINotifications(bearerToken, addresses, locale, platform, env = 'prd') {
79
100
  if (addresses.length === 0) {
80
101
  return [];
81
102
  }
82
- addresses = addresses.map((a) => a.toLowerCase());
83
- const body = addresses.map((address) => ({ address }));
84
- const notifications = await (0, utils_1.makeApiCall)(bearerToken, exports.NOTIFICATION_API_LIST_ENDPOINT, 'POST', body)
85
- .then((r) => r.ok ? r.json() : null)
103
+ const body = {
104
+ addresses: addresses.map((a) => a.toLowerCase()),
105
+ locale,
106
+ platform,
107
+ };
108
+ const notifications = await (0, utils_1.makeApiCall)(bearerToken, (0, exports.NOTIFICATION_API_LIST_ENDPOINT)(env), 'POST', body)
109
+ .then((r) => (r.ok ? r.json() : null))
86
110
  .catch(() => null);
87
111
  // Transform and sort notifications
88
112
  const transformedNotifications = notifications
89
113
  ?.map((n) => {
90
- if (!n.data?.kind) {
114
+ if (!n.notification_type) {
115
+ return undefined;
116
+ }
117
+ try {
118
+ return (0, to_raw_notification_1.toRawAPINotification)(n);
119
+ }
120
+ catch {
91
121
  return undefined;
92
122
  }
93
- return (0, to_raw_notification_1.toRawOnChainNotification)(n);
94
123
  })
95
124
  .filter((n) => Boolean(n));
96
125
  return transformedNotifications ?? [];
97
126
  }
98
- exports.getOnChainNotifications = getOnChainNotifications;
127
+ exports.getAPINotifications = getAPINotifications;
99
128
  /**
100
129
  * Marks the specified notifications as read.
101
130
  * This method sends a POST request to the notifications service to mark the provided notification IDs as read.
@@ -103,18 +132,22 @@ exports.getOnChainNotifications = getOnChainNotifications;
103
132
  *
104
133
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
105
134
  * @param notificationIds - An array of notification IDs to be marked as read.
135
+ * @param env - the environment to use for the API call
106
136
  * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.
107
137
  */
108
- async function markNotificationsAsRead(bearerToken, notificationIds) {
138
+ async function markNotificationsAsRead(bearerToken, notificationIds, env = 'prd') {
109
139
  if (notificationIds.length === 0) {
110
140
  return;
111
141
  }
142
+ const body = {
143
+ ids: notificationIds,
144
+ };
112
145
  try {
113
- await (0, utils_1.makeApiCall)(bearerToken, exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, 'POST', { ids: notificationIds });
146
+ await (0, utils_1.makeApiCall)(bearerToken, (0, exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT)(env), 'POST', body);
114
147
  }
115
148
  catch (err) {
116
149
  loglevel_1.default.error('Error marking notifications as read:', err);
117
150
  }
118
151
  }
119
152
  exports.markNotificationsAsRead = markNotificationsAsRead;
120
- //# sourceMappingURL=onchain-notifications.cjs.map
153
+ //# sourceMappingURL=api-notifications.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-notifications.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA2B;AAE3B,+EAAuE;AACvE,8EAAwE;AAMxE,8CAA6C;AAW7C,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEzB,MAAM,WAAW,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC9C,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AADjC,QAAA,WAAW,eACsB;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,yCAAyC;CAC/C,CAAC;AAEK,MAAM,gBAAgB,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CACnD,oBAAoB,CAAC,GAAG,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AW,KAAK;IAEhB,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAID,MAAM,IAAI,GAAiB;QACzB,GAAG,EAAE,eAAe;KACrB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,IAAA,mBAAW,EACf,WAAW,EACX,IAAA,kDAA0C,EAAC,GAAG,CAAC,EAC/C,MAAM,EACN,IAAI,CACL,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,kBAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;IACzD,CAAC;AACH,CAAC;AAzBD,0DAyBC","sourcesContent":["import log from 'loglevel';\n\nimport { notificationsConfigCache } from './notification-config-cache';\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type {\n NormalisedAPINotification,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api';\nimport { makeApiCall } from '../utils/utils';\n\nexport type NotificationTrigger = {\n id: string;\n chainId: string;\n kind: string;\n address: string;\n};\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd') =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd') =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (env: ENV = 'prd') =>\n `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd') =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd') =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Makrs notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env: ENV = 'prd') =>\n `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;\n\n/**\n * fetches notification config (accounts enabled vs disabled)\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * NOTE the API will return addresses config with false if they have not been created before.\n * NOTE this is cached for 1s to prevent multiple update calls\n * @returns object of notification config, or null if missing\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n) {\n if (addresses.length === 0) {\n return [];\n }\n\n addresses = addresses.map((a) => a.toLowerCase());\n\n const cached = notificationsConfigCache.get(addresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses.map((address) => ({ address }));\n const data = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n const result = data ?? [];\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * updates notifications for a given addresses\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n) {\n if (addresses.length === 0) {\n return;\n }\n\n addresses = addresses.map((a) => {\n a.address = a.address.toLowerCase();\n return a;\n });\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(addresses))\n .catch(() => null);\n}\n\n/**\n * Fetches on-chain notifications for the given addresses\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param addresses - List of addresses\n * @param locale - to generate translated notifications\n * @param platform - filter notifications for specific platforms ('extension' | 'mobile')\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.\n */\nexport async function getAPINotifications(\n bearerToken: string,\n addresses: string[],\n locale: string,\n platform: 'extension' | 'mobile',\n env: ENV = 'prd',\n): Promise<NormalisedAPINotification[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n type RequestBody =\n Schema.paths['/api/v3/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v3/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((a) => a.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(\n bearerToken,\n NOTIFICATION_API_LIST_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<APIResponse | null>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((n): UnprocessedRawNotification | undefined => {\n if (!n.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(n);\n } catch {\n return undefined;\n }\n })\n .filter((n): n is NormalisedAPINotification => Boolean(n));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v3/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(\n bearerToken,\n NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env),\n 'POST',\n body,\n );\n } catch (err) {\n log.error('Error marking notifications as read:', err);\n }\n}\n"]}
@@ -1,26 +1,28 @@
1
- import type { OnChainRawNotification } from "../types/on-chain-notification/on-chain-notification.cjs";
1
+ import type { NormalisedAPINotification } from "../types/notification-api/index.cjs";
2
2
  export type NotificationTrigger = {
3
3
  id: string;
4
4
  chainId: string;
5
5
  kind: string;
6
6
  address: string;
7
7
  };
8
- export declare const TRIGGER_API = "https://trigger.api.cx.metamask.io";
9
- export declare const NOTIFICATION_API = "https://notification.api.cx.metamask.io";
10
- export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications/query";
11
- export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications";
12
- export declare const NOTIFICATION_API_LIST_ENDPOINT = "https://notification.api.cx.metamask.io/api/v2/notifications";
13
- export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = "https://notification.api.cx.metamask.io/api/v2/notifications/mark-as-read";
8
+ export type ENV = 'prd' | 'uat' | 'dev';
9
+ export declare const TRIGGER_API: (env?: ENV) => string;
10
+ export declare const NOTIFICATION_API: (env?: ENV) => string;
11
+ export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT: (env?: ENV) => string;
12
+ export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT: (env?: ENV) => string;
13
+ export declare const NOTIFICATION_API_LIST_ENDPOINT: (env?: ENV) => string;
14
+ export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT: (env?: ENV) => string;
14
15
  /**
15
16
  * fetches notification config (accounts enabled vs disabled)
16
17
  *
17
18
  * @param bearerToken - jwt
18
19
  * @param addresses - list of addresses to check
20
+ * @param env - the environment to use for the API call
19
21
  * NOTE the API will return addresses config with false if they have not been created before.
20
22
  * NOTE this is cached for 1s to prevent multiple update calls
21
23
  * @returns object of notification config, or null if missing
22
24
  */
23
- export declare function getOnChainNotificationsConfigCached(bearerToken: string, addresses: string[]): Promise<{
25
+ export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[], env?: ENV): Promise<{
24
26
  address: string;
25
27
  enabled: boolean;
26
28
  }[]>;
@@ -29,20 +31,24 @@ export declare function getOnChainNotificationsConfigCached(bearerToken: string,
29
31
  *
30
32
  * @param bearerToken - jwt
31
33
  * @param addresses - list of addresses to check
34
+ * @param env - the environment to use for the API call
32
35
  * @returns void
33
36
  */
34
37
  export declare function updateOnChainNotifications(bearerToken: string, addresses: {
35
38
  address: string;
36
39
  enabled: boolean;
37
- }[]): Promise<void>;
40
+ }[], env?: ENV): Promise<void>;
38
41
  /**
39
42
  * Fetches on-chain notifications for the given addresses
40
43
  *
41
44
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
42
45
  * @param addresses - List of addresses
43
- * @returns A promise that resolves to an array of OnChainRawNotification objects. If no triggers are enabled or an error occurs, it may return an empty array.
46
+ * @param locale - to generate translated notifications
47
+ * @param platform - filter notifications for specific platforms ('extension' | 'mobile')
48
+ * @param env - the environment to use for the API call
49
+ * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.
44
50
  */
45
- export declare function getOnChainNotifications(bearerToken: string, addresses: string[]): Promise<OnChainRawNotification[]>;
51
+ export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile', env?: ENV): Promise<NormalisedAPINotification[]>;
46
52
  /**
47
53
  * Marks the specified notifications as read.
48
54
  * This method sends a POST request to the notifications service to mark the provided notification IDs as read.
@@ -50,7 +56,8 @@ export declare function getOnChainNotifications(bearerToken: string, addresses:
50
56
  *
51
57
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
52
58
  * @param notificationIds - An array of notification IDs to be marked as read.
59
+ * @param env - the environment to use for the API call
53
60
  * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.
54
61
  */
55
- export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]): Promise<void>;
56
- //# sourceMappingURL=onchain-notifications.d.cts.map
62
+ export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[], env?: ENV): Promise<void>;
63
+ //# sourceMappingURL=api-notifications.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-notifications.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,yBAAyB,EAG1B,4CAAkC;AAGnC,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,WAAW,SAAS,GAAG,WACS,CAAC;AAQ9C,eAAO,MAAM,gBAAgB,SAAS,GAAG,WACc,CAAC;AAGxD,eAAO,MAAM,wCAAwC,SAAS,GAAG,WACf,CAAC;AAGnD,eAAO,MAAM,kCAAkC,SAAS,GAAG,WACf,CAAC;AAG7C,eAAO,MAAM,8BAA8B,SAAS,GAAG,WACN,CAAC;AAGlD,eAAO,MAAM,0CAA0C,SAAS,GAAG,WACL,CAAC;AAE/D;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,GAAW;;;KAgCjB;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,EAClD,GAAG,GAAE,GAAW,iBAqBjB;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAwCtC;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -1,26 +1,28 @@
1
- import type { OnChainRawNotification } from "../types/on-chain-notification/on-chain-notification.mjs";
1
+ import type { NormalisedAPINotification } from "../types/notification-api/index.mjs";
2
2
  export type NotificationTrigger = {
3
3
  id: string;
4
4
  chainId: string;
5
5
  kind: string;
6
6
  address: string;
7
7
  };
8
- export declare const TRIGGER_API = "https://trigger.api.cx.metamask.io";
9
- export declare const NOTIFICATION_API = "https://notification.api.cx.metamask.io";
10
- export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications/query";
11
- export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications";
12
- export declare const NOTIFICATION_API_LIST_ENDPOINT = "https://notification.api.cx.metamask.io/api/v2/notifications";
13
- export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = "https://notification.api.cx.metamask.io/api/v2/notifications/mark-as-read";
8
+ export type ENV = 'prd' | 'uat' | 'dev';
9
+ export declare const TRIGGER_API: (env?: ENV) => string;
10
+ export declare const NOTIFICATION_API: (env?: ENV) => string;
11
+ export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT: (env?: ENV) => string;
12
+ export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT: (env?: ENV) => string;
13
+ export declare const NOTIFICATION_API_LIST_ENDPOINT: (env?: ENV) => string;
14
+ export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT: (env?: ENV) => string;
14
15
  /**
15
16
  * fetches notification config (accounts enabled vs disabled)
16
17
  *
17
18
  * @param bearerToken - jwt
18
19
  * @param addresses - list of addresses to check
20
+ * @param env - the environment to use for the API call
19
21
  * NOTE the API will return addresses config with false if they have not been created before.
20
22
  * NOTE this is cached for 1s to prevent multiple update calls
21
23
  * @returns object of notification config, or null if missing
22
24
  */
23
- export declare function getOnChainNotificationsConfigCached(bearerToken: string, addresses: string[]): Promise<{
25
+ export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[], env?: ENV): Promise<{
24
26
  address: string;
25
27
  enabled: boolean;
26
28
  }[]>;
@@ -29,20 +31,24 @@ export declare function getOnChainNotificationsConfigCached(bearerToken: string,
29
31
  *
30
32
  * @param bearerToken - jwt
31
33
  * @param addresses - list of addresses to check
34
+ * @param env - the environment to use for the API call
32
35
  * @returns void
33
36
  */
34
37
  export declare function updateOnChainNotifications(bearerToken: string, addresses: {
35
38
  address: string;
36
39
  enabled: boolean;
37
- }[]): Promise<void>;
40
+ }[], env?: ENV): Promise<void>;
38
41
  /**
39
42
  * Fetches on-chain notifications for the given addresses
40
43
  *
41
44
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
42
45
  * @param addresses - List of addresses
43
- * @returns A promise that resolves to an array of OnChainRawNotification objects. If no triggers are enabled or an error occurs, it may return an empty array.
46
+ * @param locale - to generate translated notifications
47
+ * @param platform - filter notifications for specific platforms ('extension' | 'mobile')
48
+ * @param env - the environment to use for the API call
49
+ * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.
44
50
  */
45
- export declare function getOnChainNotifications(bearerToken: string, addresses: string[]): Promise<OnChainRawNotification[]>;
51
+ export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile', env?: ENV): Promise<NormalisedAPINotification[]>;
46
52
  /**
47
53
  * Marks the specified notifications as read.
48
54
  * This method sends a POST request to the notifications service to mark the provided notification IDs as read.
@@ -50,7 +56,8 @@ export declare function getOnChainNotifications(bearerToken: string, addresses:
50
56
  *
51
57
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
52
58
  * @param notificationIds - An array of notification IDs to be marked as read.
59
+ * @param env - the environment to use for the API call
53
60
  * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.
54
61
  */
55
- export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]): Promise<void>;
56
- //# sourceMappingURL=onchain-notifications.d.mts.map
62
+ export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[], env?: ENV): Promise<void>;
63
+ //# sourceMappingURL=api-notifications.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,yBAAyB,EAG1B,4CAAkC;AAGnC,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,WAAW,SAAS,GAAG,WACS,CAAC;AAQ9C,eAAO,MAAM,gBAAgB,SAAS,GAAG,WACc,CAAC;AAGxD,eAAO,MAAM,wCAAwC,SAAS,GAAG,WACf,CAAC;AAGnD,eAAO,MAAM,kCAAkC,SAAS,GAAG,WACf,CAAC;AAG7C,eAAO,MAAM,8BAA8B,SAAS,GAAG,WACN,CAAC;AAGlD,eAAO,MAAM,0CAA0C,SAAS,GAAG,WACL,CAAC;AAE/D;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,GAAW;;;KAgCjB;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,EAClD,GAAG,GAAE,GAAW,iBAqBjB;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAwCtC;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -7,28 +7,39 @@ function $importDefault(module) {
7
7
  import $log from "loglevel";
8
8
  const log = $importDefault($log);
9
9
  import { notificationsConfigCache } from "./notification-config-cache.mjs";
10
- import { toRawOnChainNotification } from "../../shared/to-raw-notification.mjs";
10
+ import { toRawAPINotification } from "../../shared/to-raw-notification.mjs";
11
11
  import { makeApiCall } from "../utils/utils.mjs";
12
- export const TRIGGER_API = 'https://trigger.api.cx.metamask.io';
13
- export const NOTIFICATION_API = 'https://notification.api.cx.metamask.io';
12
+ const TRIGGER_API_ENV = {
13
+ dev: 'https://trigger.dev-api.cx.metamask.io',
14
+ uat: 'https://trigger.uat-api.cx.metamask.io',
15
+ prd: 'https://trigger.api.cx.metamask.io',
16
+ };
17
+ export const TRIGGER_API = (env = 'prd') => TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;
18
+ const NOTIFICATION_API_ENV = {
19
+ dev: 'https://notification.dev-api.cx.metamask.io',
20
+ uat: 'https://notification.uat-api.cx.metamask.io',
21
+ prd: 'https://notification.api.cx.metamask.io',
22
+ };
23
+ export const NOTIFICATION_API = (env = 'prd') => NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;
14
24
  // Gets notification settings for each account provided
15
- export const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = `${TRIGGER_API}/api/v2/notifications/query`;
25
+ export const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (env = 'prd') => `${TRIGGER_API(env)}/api/v2/notifications/query`;
16
26
  // Used to create/update account notifications for each account provided
17
- export const TRIGGER_API_NOTIFICATIONS_ENDPOINT = `${TRIGGER_API}/api/v2/notifications`;
27
+ export const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env = 'prd') => `${TRIGGER_API(env)}/api/v2/notifications`;
18
28
  // Lists notifications for each account provided
19
- export const NOTIFICATION_API_LIST_ENDPOINT = `${NOTIFICATION_API}/api/v2/notifications`;
29
+ export const NOTIFICATION_API_LIST_ENDPOINT = (env = 'prd') => `${NOTIFICATION_API(env)}/api/v3/notifications`;
20
30
  // Makrs notifications as read
21
- export const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${NOTIFICATION_API}/api/v2/notifications/mark-as-read`;
31
+ export const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env = 'prd') => `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;
22
32
  /**
23
33
  * fetches notification config (accounts enabled vs disabled)
24
34
  *
25
35
  * @param bearerToken - jwt
26
36
  * @param addresses - list of addresses to check
37
+ * @param env - the environment to use for the API call
27
38
  * NOTE the API will return addresses config with false if they have not been created before.
28
39
  * NOTE this is cached for 1s to prevent multiple update calls
29
40
  * @returns object of notification config, or null if missing
30
41
  */
31
- export async function getOnChainNotificationsConfigCached(bearerToken, addresses) {
42
+ export async function getNotificationsApiConfigCached(bearerToken, addresses, env = 'prd') {
32
43
  if (addresses.length === 0) {
33
44
  return [];
34
45
  }
@@ -38,7 +49,7 @@ export async function getOnChainNotificationsConfigCached(bearerToken, addresses
38
49
  return cached;
39
50
  }
40
51
  const body = addresses.map((address) => ({ address }));
41
- const data = await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT, 'POST', body)
52
+ const data = await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env), 'POST', body)
42
53
  .then((r) => (r.ok ? r.json() : null))
43
54
  .catch(() => null);
44
55
  const result = data ?? [];
@@ -52,9 +63,10 @@ export async function getOnChainNotificationsConfigCached(bearerToken, addresses
52
63
  *
53
64
  * @param bearerToken - jwt
54
65
  * @param addresses - list of addresses to check
66
+ * @param env - the environment to use for the API call
55
67
  * @returns void
56
68
  */
57
- export async function updateOnChainNotifications(bearerToken, addresses) {
69
+ export async function updateOnChainNotifications(bearerToken, addresses, env = 'prd') {
58
70
  if (addresses.length === 0) {
59
71
  return;
60
72
  }
@@ -63,7 +75,7 @@ export async function updateOnChainNotifications(bearerToken, addresses) {
63
75
  return a;
64
76
  });
65
77
  const body = addresses;
66
- await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_ENDPOINT, 'POST', body)
78
+ await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_ENDPOINT(env), 'POST', body)
67
79
  .then(() => notificationsConfigCache.set(addresses))
68
80
  .catch(() => null);
69
81
  }
@@ -72,24 +84,35 @@ export async function updateOnChainNotifications(bearerToken, addresses) {
72
84
  *
73
85
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
74
86
  * @param addresses - List of addresses
75
- * @returns A promise that resolves to an array of OnChainRawNotification objects. If no triggers are enabled or an error occurs, it may return an empty array.
87
+ * @param locale - to generate translated notifications
88
+ * @param platform - filter notifications for specific platforms ('extension' | 'mobile')
89
+ * @param env - the environment to use for the API call
90
+ * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.
76
91
  */
77
- export async function getOnChainNotifications(bearerToken, addresses) {
92
+ export async function getAPINotifications(bearerToken, addresses, locale, platform, env = 'prd') {
78
93
  if (addresses.length === 0) {
79
94
  return [];
80
95
  }
81
- addresses = addresses.map((a) => a.toLowerCase());
82
- const body = addresses.map((address) => ({ address }));
83
- const notifications = await makeApiCall(bearerToken, NOTIFICATION_API_LIST_ENDPOINT, 'POST', body)
84
- .then((r) => r.ok ? r.json() : null)
96
+ const body = {
97
+ addresses: addresses.map((a) => a.toLowerCase()),
98
+ locale,
99
+ platform,
100
+ };
101
+ const notifications = await makeApiCall(bearerToken, NOTIFICATION_API_LIST_ENDPOINT(env), 'POST', body)
102
+ .then((r) => (r.ok ? r.json() : null))
85
103
  .catch(() => null);
86
104
  // Transform and sort notifications
87
105
  const transformedNotifications = notifications
88
106
  ?.map((n) => {
89
- if (!n.data?.kind) {
107
+ if (!n.notification_type) {
108
+ return undefined;
109
+ }
110
+ try {
111
+ return toRawAPINotification(n);
112
+ }
113
+ catch {
90
114
  return undefined;
91
115
  }
92
- return toRawOnChainNotification(n);
93
116
  })
94
117
  .filter((n) => Boolean(n));
95
118
  return transformedNotifications ?? [];
@@ -101,17 +124,21 @@ export async function getOnChainNotifications(bearerToken, addresses) {
101
124
  *
102
125
  * @param bearerToken - The JSON Web Token used for authentication in the API call.
103
126
  * @param notificationIds - An array of notification IDs to be marked as read.
127
+ * @param env - the environment to use for the API call
104
128
  * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.
105
129
  */
106
- export async function markNotificationsAsRead(bearerToken, notificationIds) {
130
+ export async function markNotificationsAsRead(bearerToken, notificationIds, env = 'prd') {
107
131
  if (notificationIds.length === 0) {
108
132
  return;
109
133
  }
134
+ const body = {
135
+ ids: notificationIds,
136
+ };
110
137
  try {
111
- await makeApiCall(bearerToken, NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, 'POST', { ids: notificationIds });
138
+ await makeApiCall(bearerToken, NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env), 'POST', body);
112
139
  }
113
140
  catch (err) {
114
141
  log.error('Error marking notifications as read:', err);
115
142
  }
116
143
  }
117
- //# sourceMappingURL=onchain-notifications.mjs.map
144
+ //# sourceMappingURL=api-notifications.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,oBAAoB,EAAE,6CAAyC;AAMxE,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAW7C,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEhC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC9C,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,yCAAyC;CAC/C,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CACnD,oBAAoB,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,GAAG,CAAC;AAExD,uDAAuD;AACvD,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC3E,G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,EAAE,CAAC;QACb,GAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;IACzD,CAAC;AACH,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport { notificationsConfigCache } from './notification-config-cache';\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type {\n NormalisedAPINotification,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api';\nimport { makeApiCall } from '../utils/utils';\n\nexport type NotificationTrigger = {\n id: string;\n chainId: string;\n kind: string;\n address: string;\n};\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd') =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd') =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (env: ENV = 'prd') =>\n `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd') =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd') =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Makrs notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env: ENV = 'prd') =>\n `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;\n\n/**\n * fetches notification config (accounts enabled vs disabled)\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * NOTE the API will return addresses config with false if they have not been created before.\n * NOTE this is cached for 1s to prevent multiple update calls\n * @returns object of notification config, or null if missing\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n) {\n if (addresses.length === 0) {\n return [];\n }\n\n addresses = addresses.map((a) => a.toLowerCase());\n\n const cached = notificationsConfigCache.get(addresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses.map((address) => ({ address }));\n const data = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n const result = data ?? [];\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * updates notifications for a given addresses\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n) {\n if (addresses.length === 0) {\n return;\n }\n\n addresses = addresses.map((a) => {\n a.address = a.address.toLowerCase();\n return a;\n });\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(addresses))\n .catch(() => null);\n}\n\n/**\n * Fetches on-chain notifications for the given addresses\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param addresses - List of addresses\n * @param locale - to generate translated notifications\n * @param platform - filter notifications for specific platforms ('extension' | 'mobile')\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.\n */\nexport async function getAPINotifications(\n bearerToken: string,\n addresses: string[],\n locale: string,\n platform: 'extension' | 'mobile',\n env: ENV = 'prd',\n): Promise<NormalisedAPINotification[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n type RequestBody =\n Schema.paths['/api/v3/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v3/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((a) => a.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(\n bearerToken,\n NOTIFICATION_API_LIST_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<APIResponse | null>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((n): UnprocessedRawNotification | undefined => {\n if (!n.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(n);\n } catch {\n return undefined;\n }\n })\n .filter((n): n is NormalisedAPINotification => Boolean(n));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v3/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(\n bearerToken,\n NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env),\n 'POST',\n body,\n );\n } catch (err) {\n log.error('Error marking notifications as read:', err);\n }\n}\n"]}