@metamask/notification-services-controller 21.0.0 → 22.1.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 (193) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +56 -42
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +3 -2
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +3 -2
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +56 -41
  9. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  10. package/dist/NotificationServicesController/constants/notification-schema.cjs +4 -12
  11. package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
  12. package/dist/NotificationServicesController/constants/notification-schema.d.cts +0 -12
  13. package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/constants/notification-schema.d.mts +0 -12
  15. package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/constants/notification-schema.mjs +3 -11
  17. package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
  18. package/dist/NotificationServicesController/index.cjs +1 -2
  19. package/dist/NotificationServicesController/index.cjs.map +1 -1
  20. package/dist/NotificationServicesController/index.d.cts +0 -1
  21. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  22. package/dist/NotificationServicesController/index.d.mts +0 -1
  23. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  24. package/dist/NotificationServicesController/index.mjs +0 -1
  25. package/dist/NotificationServicesController/index.mjs.map +1 -1
  26. package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs +2 -2
  27. package/dist/NotificationServicesController/mocks/mock-feature-announcements.cjs.map +1 -1
  28. package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.cts.map +1 -1
  29. package/dist/NotificationServicesController/mocks/mock-feature-announcements.d.mts.map +1 -1
  30. package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs +2 -2
  31. package/dist/NotificationServicesController/mocks/mock-feature-announcements.mjs.map +1 -1
  32. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +120 -0
  33. package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
  34. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
  35. package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
  36. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +120 -0
  37. package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
  38. package/dist/NotificationServicesController/mocks/mock-snap-notification.cjs.map +1 -1
  39. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts +1 -1
  40. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.cts.map +1 -1
  41. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts +1 -1
  42. package/dist/NotificationServicesController/mocks/mock-snap-notification.d.mts.map +1 -1
  43. package/dist/NotificationServicesController/mocks/mock-snap-notification.mjs.map +1 -1
  44. package/dist/NotificationServicesController/mocks/mockResponses.cjs +6 -0
  45. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  46. package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
  47. package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
  48. package/dist/NotificationServicesController/mocks/mockResponses.mjs +6 -0
  49. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  50. package/dist/NotificationServicesController/processors/process-notifications.cjs +11 -9
  51. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  52. package/dist/NotificationServicesController/processors/process-notifications.d.cts +1 -563
  53. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  54. package/dist/NotificationServicesController/processors/process-notifications.d.mts +1 -563
  55. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  56. package/dist/NotificationServicesController/processors/process-notifications.mjs +11 -9
  57. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  58. package/dist/NotificationServicesController/processors/process-snap-notifications.cjs.map +1 -1
  59. package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts +1 -1
  60. package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts.map +1 -1
  61. package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts +1 -1
  62. package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts.map +1 -1
  63. package/dist/NotificationServicesController/processors/process-snap-notifications.mjs.map +1 -1
  64. package/dist/NotificationServicesController/services/api-notifications.cjs +21 -21
  65. package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
  66. package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
  67. package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
  68. package/dist/NotificationServicesController/services/api-notifications.mjs +21 -21
  69. package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
  70. package/dist/NotificationServicesController/services/feature-announcements.cjs +19 -10
  71. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  72. package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
  73. package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
  74. package/dist/NotificationServicesController/services/feature-announcements.mjs +19 -10
  75. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  76. package/dist/NotificationServicesController/services/notification-config-cache.cjs +4 -4
  77. package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -1
  78. package/dist/NotificationServicesController/services/notification-config-cache.mjs +4 -4
  79. package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -1
  80. package/dist/NotificationServicesController/services/perp-notifications.cjs +2 -2
  81. package/dist/NotificationServicesController/services/perp-notifications.cjs.map +1 -1
  82. package/dist/NotificationServicesController/services/perp-notifications.d.cts.map +1 -1
  83. package/dist/NotificationServicesController/services/perp-notifications.d.mts.map +1 -1
  84. package/dist/NotificationServicesController/services/perp-notifications.mjs +2 -2
  85. package/dist/NotificationServicesController/services/perp-notifications.mjs.map +1 -1
  86. package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -1
  87. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +2 -0
  88. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -1
  89. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +2 -0
  90. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -1
  91. package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -1
  92. package/dist/NotificationServicesController/types/notification-api/schema.cjs +2 -0
  93. package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -1
  94. package/dist/NotificationServicesController/types/notification-api/schema.d.cts +23 -0
  95. package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -1
  96. package/dist/NotificationServicesController/types/notification-api/schema.d.mts +23 -0
  97. package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -1
  98. package/dist/NotificationServicesController/types/notification-api/schema.mjs +2 -0
  99. package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -1
  100. package/dist/NotificationServicesController/types/perps/schema.cjs +2 -0
  101. package/dist/NotificationServicesController/types/perps/schema.cjs.map +1 -1
  102. package/dist/NotificationServicesController/types/perps/schema.d.cts.map +1 -1
  103. package/dist/NotificationServicesController/types/perps/schema.d.mts.map +1 -1
  104. package/dist/NotificationServicesController/types/perps/schema.mjs +2 -0
  105. package/dist/NotificationServicesController/types/perps/schema.mjs.map +1 -1
  106. package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
  107. package/dist/NotificationServicesController/utils/isVersionInBounds.d.cts.map +1 -1
  108. package/dist/NotificationServicesController/utils/isVersionInBounds.d.mts.map +1 -1
  109. package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
  110. package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -1
  111. package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -1
  112. package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -1
  113. package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -1
  114. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +0 -1
  115. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  116. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +1 -1
  117. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  118. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +1 -1
  119. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  120. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +0 -1
  121. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  122. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
  123. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +9 -24
  124. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
  125. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +9 -24
  126. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
  127. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
  128. package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
  129. package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
  130. package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
  131. package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
  132. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  133. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  134. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  135. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  136. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs +4 -4
  137. package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
  138. package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts +2 -2
  139. package/dist/NotificationServicesPushController/utils/get-notification-data.d.cts.map +1 -1
  140. package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts +2 -2
  141. package/dist/NotificationServicesPushController/utils/get-notification-data.d.mts.map +1 -1
  142. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs +4 -4
  143. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
  144. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +62 -71
  145. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  146. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +9 -9
  147. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  148. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +9 -9
  149. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  150. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +62 -71
  151. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  152. package/dist/NotificationServicesPushController/web/push-utils.cjs +15 -7
  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 +16 -8
  157. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
  158. package/dist/shared/is-onchain-notification.cjs +3 -3
  159. package/dist/shared/is-onchain-notification.cjs.map +1 -1
  160. package/dist/shared/is-onchain-notification.d.cts +2 -2
  161. package/dist/shared/is-onchain-notification.d.cts.map +1 -1
  162. package/dist/shared/is-onchain-notification.d.mts +2 -2
  163. package/dist/shared/is-onchain-notification.d.mts.map +1 -1
  164. package/dist/shared/is-onchain-notification.mjs +3 -3
  165. package/dist/shared/is-onchain-notification.mjs.map +1 -1
  166. package/dist/shared/to-raw-notification.cjs.map +1 -1
  167. package/dist/shared/to-raw-notification.mjs.map +1 -1
  168. package/package.json +12 -25
  169. package/dist/NotificationServicesController/ui/constants.cjs +0 -75
  170. package/dist/NotificationServicesController/ui/constants.cjs.map +0 -1
  171. package/dist/NotificationServicesController/ui/constants.d.cts +0 -66
  172. package/dist/NotificationServicesController/ui/constants.d.cts.map +0 -1
  173. package/dist/NotificationServicesController/ui/constants.d.mts +0 -66
  174. package/dist/NotificationServicesController/ui/constants.d.mts.map +0 -1
  175. package/dist/NotificationServicesController/ui/constants.mjs +0 -71
  176. package/dist/NotificationServicesController/ui/constants.mjs.map +0 -1
  177. package/dist/NotificationServicesController/ui/index.cjs +0 -18
  178. package/dist/NotificationServicesController/ui/index.cjs.map +0 -1
  179. package/dist/NotificationServicesController/ui/index.d.cts +0 -2
  180. package/dist/NotificationServicesController/ui/index.d.cts.map +0 -1
  181. package/dist/NotificationServicesController/ui/index.d.mts +0 -2
  182. package/dist/NotificationServicesController/ui/index.d.mts.map +0 -1
  183. package/dist/NotificationServicesController/ui/index.mjs +0 -2
  184. package/dist/NotificationServicesController/ui/index.mjs.map +0 -1
  185. package/dist/NotificationServicesPushController/services/push/push-web.cjs +0 -145
  186. package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +0 -1
  187. package/dist/NotificationServicesPushController/services/push/push-web.d.cts +0 -34
  188. package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +0 -1
  189. package/dist/NotificationServicesPushController/services/push/push-web.d.mts +0 -34
  190. package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +0 -1
  191. package/dist/NotificationServicesPushController/services/push/push-web.mjs +0 -142
  192. package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +0 -1
  193. package/notification-services/ui/package.json +0 -9
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/ui/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EAEvB,6CAAyC;AAE1C,MAAM,CAAC,MAAM,kCAAkC,GAAG;IAChD,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE,UAAU;IAC7C,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE,UAAU;IAC7C,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,WAAW;IAC/C,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,SAAS;IACvC,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM;IACrC,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,OAAO;IACvC,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE,UAAU;IAC7C,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,SAAS;IAC3C,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,aAAa;CACM,CAAC;AAEpD,MAAM,CAAC,MAAM,oCAAoC,GAAG;IAClD,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE,KAAK;IACxC,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE,KAAK;IACxC,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE,MAAM;IAC1C,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,KAAK;IACnC,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,KAAK;IACpC,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE,KAAK;IACrC,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE,KAAK;IACxC,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,KAAK;IACvC,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE,KAAK;CACc,CAAC;AAOpD,MAAM,CAAC,MAAM,sCAAsC,GAAG;IACpD,WAAW;IACX,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE;QACjC,GAAG,EAAE,sBAAsB;QAC3B,IAAI,EAAE,WAAW;KAClB;IACD,WAAW;IACX,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE;QACjC,GAAG,EAAE,iCAAiC;QACtC,IAAI,EAAE,sBAAsB;KAC7B;IACD,MAAM;IACN,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE;QAC5B,GAAG,EAAE,qBAAqB;QAC1B,IAAI,EAAE,SAAS;KAChB;IACD,OAAO;IACP,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE;QAC7B,GAAG,EAAE,sBAAsB;QAC3B,IAAI,EAAE,UAAU;KACjB;IACD,UAAU;IACV,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE;QAChC,GAAG,EAAE,yBAAyB;QAC9B,IAAI,EAAE,aAAa;KACpB;IACD,WAAW;IACX,CAAC,sBAAsB,CAAC,QAAQ,CAAC,EAAE;QACjC,GAAG,EAAE,qBAAqB;QAC1B,IAAI,EAAE,UAAU;KACjB;IACD,YAAY;IACZ,CAAC,sBAAsB,CAAC,SAAS,CAAC,EAAE;QAClC,GAAG,EAAE,sBAAsB;QAC3B,IAAI,EAAE,WAAW;KAClB;IACD,QAAQ;IACR,CAAC,sBAAsB,CAAC,KAAK,CAAC,EAAE;QAC9B,GAAG,EAAE,yBAAyB;QAC9B,IAAI,EAAE,WAAW;KAClB;IACD,CAAC,sBAAsB,CAAC,GAAG,CAAC,EAAE;QAC5B,GAAG,EAAE,uBAAuB;QAC5B,IAAI,EAAE,UAAU;KACjB;CAC6D,CAAC;AAEjE,OAAO,EAAE,sBAAsB,EAAE,6CAAyC","sourcesContent":["import {\n NOTIFICATION_CHAINS_ID,\n type NOTIFICATION_CHAINS_IDS,\n} from '../constants/notification-schema';\n\nexport const NOTIFICATION_NETWORK_CURRENCY_NAME = {\n [NOTIFICATION_CHAINS_ID.ETHEREUM]: 'Ethereum',\n [NOTIFICATION_CHAINS_ID.ARBITRUM]: 'Arbitrum',\n [NOTIFICATION_CHAINS_ID.AVALANCHE]: 'Avalanche',\n [NOTIFICATION_CHAINS_ID.BSC]: 'Binance',\n [NOTIFICATION_CHAINS_ID.BASE]: 'Base',\n [NOTIFICATION_CHAINS_ID.LINEA]: 'Linea',\n [NOTIFICATION_CHAINS_ID.OPTIMISM]: 'Optimism',\n [NOTIFICATION_CHAINS_ID.POLYGON]: 'Polygon',\n [NOTIFICATION_CHAINS_ID.SEI]: 'Sei Network',\n} satisfies Record<NOTIFICATION_CHAINS_IDS, string>;\n\nexport const NOTIFICATION_NETWORK_CURRENCY_SYMBOL = {\n [NOTIFICATION_CHAINS_ID.ETHEREUM]: 'ETH',\n [NOTIFICATION_CHAINS_ID.ARBITRUM]: 'ETH',\n [NOTIFICATION_CHAINS_ID.AVALANCHE]: 'AVAX',\n [NOTIFICATION_CHAINS_ID.BSC]: 'BNB',\n [NOTIFICATION_CHAINS_ID.BASE]: 'ETH',\n [NOTIFICATION_CHAINS_ID.LINEA]: 'ETH',\n [NOTIFICATION_CHAINS_ID.OPTIMISM]: 'ETH',\n [NOTIFICATION_CHAINS_ID.POLYGON]: 'POL',\n [NOTIFICATION_CHAINS_ID.SEI]: 'SEI',\n} satisfies Record<NOTIFICATION_CHAINS_IDS, string>;\n\nexport type BlockExplorerConfig = {\n url: string;\n name: string;\n};\n\nexport const SUPPORTED_NOTIFICATION_BLOCK_EXPLORERS = {\n // ETHEREUM\n [NOTIFICATION_CHAINS_ID.ETHEREUM]: {\n url: 'https://etherscan.io',\n name: 'Etherscan',\n },\n // OPTIMISM\n [NOTIFICATION_CHAINS_ID.OPTIMISM]: {\n url: 'https://optimistic.etherscan.io',\n name: 'Optimistic Etherscan',\n },\n // BSC\n [NOTIFICATION_CHAINS_ID.BSC]: {\n url: 'https://bscscan.com',\n name: 'BscScan',\n },\n // BASE\n [NOTIFICATION_CHAINS_ID.BASE]: {\n url: 'https://basescan.org',\n name: 'BaseScan',\n },\n // POLYGON\n [NOTIFICATION_CHAINS_ID.POLYGON]: {\n url: 'https://polygonscan.com',\n name: 'PolygonScan',\n },\n // ARBITRUM\n [NOTIFICATION_CHAINS_ID.ARBITRUM]: {\n url: 'https://arbiscan.io',\n name: 'Arbiscan',\n },\n // AVALANCHE\n [NOTIFICATION_CHAINS_ID.AVALANCHE]: {\n url: 'https://snowtrace.io',\n name: 'Snowtrace',\n },\n // LINEA\n [NOTIFICATION_CHAINS_ID.LINEA]: {\n url: 'https://lineascan.build',\n name: 'LineaScan',\n },\n [NOTIFICATION_CHAINS_ID.SEI]: {\n url: 'https://seitrace.com/',\n name: 'SeiTrace',\n },\n} satisfies Record<NOTIFICATION_CHAINS_IDS, BlockExplorerConfig>;\n\nexport { NOTIFICATION_CHAINS_ID } from '../constants/notification-schema';\n"]}
@@ -1,18 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants.cjs"), exports);
18
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/ui/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA4B","sourcesContent":["export * from './constants';\n"]}
@@ -1,2 +0,0 @@
1
- export * from "./constants.cjs";
2
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/ui/index.ts"],"names":[],"mappings":"AAAA,gCAA4B"}
@@ -1,2 +0,0 @@
1
- export * from "./constants.mjs";
2
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/ui/index.ts"],"names":[],"mappings":"AAAA,gCAA4B"}
@@ -1,2 +0,0 @@
1
- export * from "./constants.mjs";
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/ui/index.ts"],"names":[],"mappings":"AAAA,gCAA4B","sourcesContent":["export * from './constants';\n"]}
@@ -1,145 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.listenToPushNotificationsClicked = exports.listenToPushNotificationsReceived = exports.deleteRegToken = exports.createRegToken = exports.supportedCache = void 0;
7
- const app_1 = require("firebase/app");
8
- const messaging_1 = require("firebase/messaging");
9
- const sw_1 = require("firebase/messaging/sw");
10
- const loglevel_1 = __importDefault(require("loglevel"));
11
- const NotificationServicesController_1 = require("../../../NotificationServicesController/index.cjs");
12
- const to_raw_notification_1 = require("../../../shared/to-raw-notification.cjs");
13
- // Exported to help testing
14
- // eslint-disable-next-line import-x/no-mutable-exports
15
- exports.supportedCache = null;
16
- const getPushAvailability = async () => {
17
- exports.supportedCache ?? (exports.supportedCache = await (0, sw_1.isSupported)());
18
- return exports.supportedCache;
19
- };
20
- const createFirebaseApp = async (env) => {
21
- try {
22
- return (0, app_1.getApp)();
23
- }
24
- catch {
25
- const firebaseConfig = {
26
- apiKey: env.apiKey,
27
- authDomain: env.authDomain,
28
- storageBucket: env.storageBucket,
29
- projectId: env.projectId,
30
- messagingSenderId: env.messagingSenderId,
31
- appId: env.appId,
32
- measurementId: env.measurementId,
33
- };
34
- return (0, app_1.initializeApp)(firebaseConfig);
35
- }
36
- };
37
- const getFirebaseMessaging = async (env) => {
38
- const supported = await getPushAvailability();
39
- if (!supported) {
40
- return null;
41
- }
42
- const app = await createFirebaseApp(env);
43
- return (0, sw_1.getMessaging)(app);
44
- };
45
- /**
46
- * Creates a registration token for Firebase Cloud Messaging.
47
- *
48
- * @param env - env to configure push notifications
49
- * @returns A promise that resolves with the registration token or null if an error occurs.
50
- */
51
- async function createRegToken(env) {
52
- try {
53
- const messaging = await getFirebaseMessaging(env);
54
- if (!messaging) {
55
- return null;
56
- }
57
- const token = await (0, messaging_1.getToken)(messaging, {
58
- serviceWorkerRegistration: self.registration,
59
- vapidKey: env.vapidKey,
60
- });
61
- return token;
62
- }
63
- catch {
64
- return null;
65
- }
66
- }
67
- exports.createRegToken = createRegToken;
68
- /**
69
- * Deletes the Firebase Cloud Messaging registration token.
70
- *
71
- * @param env - env to configure push notifications
72
- * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
73
- */
74
- async function deleteRegToken(env) {
75
- try {
76
- const messaging = await getFirebaseMessaging(env);
77
- if (!messaging) {
78
- return true;
79
- }
80
- await (0, messaging_1.deleteToken)(messaging);
81
- return true;
82
- }
83
- catch {
84
- return false;
85
- }
86
- }
87
- exports.deleteRegToken = deleteRegToken;
88
- /**
89
- * Service Worker Listener for when push notifications are received.
90
- *
91
- * @param env - push notification environment
92
- * @param handler - handler to actually showing notification, MUST BE PROVEDED
93
- * @returns unsubscribe handler
94
- */
95
- async function listenToPushNotificationsReceived(env, handler) {
96
- const messaging = await getFirebaseMessaging(env);
97
- if (!messaging) {
98
- return null;
99
- }
100
- const unsubscribePushNotifications = (0, sw_1.onBackgroundMessage)(messaging,
101
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
102
- async (payload) => {
103
- try {
104
- const data = payload?.data
105
- ?.data
106
- ? JSON.parse(payload?.data?.data)
107
- : undefined;
108
- if (!data) {
109
- return;
110
- }
111
- const notificationData = (0, to_raw_notification_1.toRawAPINotification)(data);
112
- const notification = NotificationServicesController_1.Processors.processNotification(notificationData);
113
- await handler(notification);
114
- }
115
- catch (error) {
116
- // Do Nothing, cannot parse a bad notification
117
- loglevel_1.default.error('Unable to send push notification:', {
118
- notification: payload?.data?.data,
119
- error,
120
- });
121
- throw new Error('Unable to send push notification');
122
- }
123
- });
124
- const unsubscribe = () => unsubscribePushNotifications();
125
- return unsubscribe;
126
- }
127
- exports.listenToPushNotificationsReceived = listenToPushNotificationsReceived;
128
- /**
129
- * Service Worker Listener for when a notification is clicked
130
- *
131
- * @param handler - listen to NotificationEvent from the service worker
132
- * @returns unsubscribe handler
133
- */
134
- function listenToPushNotificationsClicked(handler) {
135
- const clickHandler = (event) => {
136
- // Get Data
137
- const data = event?.notification?.data;
138
- handler(event, data);
139
- };
140
- self.addEventListener('notificationclick', clickHandler);
141
- const unsubscribe = () => self.removeEventListener('notificationclick', clickHandler);
142
- return unsubscribe;
143
- }
144
- exports.listenToPushNotificationsClicked = listenToPushNotificationsClicked;
145
- //# sourceMappingURL=push-web.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"push-web.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";;;;;;AAIA,sCAAqD;AACrD,kDAA2D;AAC3D,8CAI+B;AAE/B,wDAA2B;AAG3B,sGAAqE;AACrE,iFAA2E;AAK3E,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,sBAAc,KAAd,sBAAc,GAAK,MAAM,IAAA,gBAAW,GAAE,EAAC;IACvC,OAAO,sBAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAA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BAC7C,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI;gBACjC,KAAK;aACN,CAAC,CAAC;YACH,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;QACtD,CAAC;IACH,CAAC,CACF,CAAC;IAEF,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,4BAA4B,EAAE,CAAC;IACzD,OAAO,WAAW,CAAC;AACrB,CAAC;AAvCD,8EAuCC;AAED;;;;;GAKG;AACH,SAAgB,gCAAgC,CAC9C,OAA2E;IAE3E,MAAM,YAAY,GAAG,CAAC,KAAwB,EAAE,EAAE;QAChD,WAAW;QACX,MAAM,IAAI,GAAwB,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;QAC5D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC;AAbD,4EAaC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../../NotificationServicesController';\nimport { Processors } from '../../../NotificationServicesController';\nimport { toRawAPINotification } from '../../../shared/to-raw-notification';\nimport type { PushNotificationEnv } from '../../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVEDED\n * @returns unsubscribe handler\n */\nexport async function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedRawNotification | undefined = payload?.data\n ?.data\n ? JSON.parse(payload?.data?.data)\n : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawAPINotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nexport function listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification?: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n"]}
@@ -1,34 +0,0 @@
1
- /// <reference lib="webworker" />
2
- import type { Types } from "../../../NotificationServicesController/index.cjs";
3
- import type { PushNotificationEnv } from "../../types/firebase.cjs";
4
- export declare let supportedCache: boolean | null;
5
- /**
6
- * Creates a registration token for Firebase Cloud Messaging.
7
- *
8
- * @param env - env to configure push notifications
9
- * @returns A promise that resolves with the registration token or null if an error occurs.
10
- */
11
- export declare function createRegToken(env: PushNotificationEnv): Promise<string | null>;
12
- /**
13
- * Deletes the Firebase Cloud Messaging registration token.
14
- *
15
- * @param env - env to configure push notifications
16
- * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
17
- */
18
- export declare function deleteRegToken(env: PushNotificationEnv): Promise<boolean>;
19
- /**
20
- * Service Worker Listener for when push notifications are received.
21
- *
22
- * @param env - push notification environment
23
- * @param handler - handler to actually showing notification, MUST BE PROVEDED
24
- * @returns unsubscribe handler
25
- */
26
- export declare function listenToPushNotificationsReceived(env: PushNotificationEnv, handler: (notification: Types.INotification) => void | Promise<void>): Promise<(() => void) | null>;
27
- /**
28
- * Service Worker Listener for when a notification is clicked
29
- *
30
- * @param handler - listen to NotificationEvent from the service worker
31
- * @returns unsubscribe handler
32
- */
33
- export declare function listenToPushNotificationsClicked(handler: (e: NotificationEvent, notification?: Types.INotification) => void): () => void;
34
- //# sourceMappingURL=push-web.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"push-web.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,0DAAgD;AAGrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAA6B;AAMhE,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;;;;GAMG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACnE,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAoC9B;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,cAY5E"}
@@ -1,34 +0,0 @@
1
- /// <reference lib="webworker" />
2
- import type { Types } from "../../../NotificationServicesController/index.mjs";
3
- import type { PushNotificationEnv } from "../../types/firebase.mjs";
4
- export declare let supportedCache: boolean | null;
5
- /**
6
- * Creates a registration token for Firebase Cloud Messaging.
7
- *
8
- * @param env - env to configure push notifications
9
- * @returns A promise that resolves with the registration token or null if an error occurs.
10
- */
11
- export declare function createRegToken(env: PushNotificationEnv): Promise<string | null>;
12
- /**
13
- * Deletes the Firebase Cloud Messaging registration token.
14
- *
15
- * @param env - env to configure push notifications
16
- * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
17
- */
18
- export declare function deleteRegToken(env: PushNotificationEnv): Promise<boolean>;
19
- /**
20
- * Service Worker Listener for when push notifications are received.
21
- *
22
- * @param env - push notification environment
23
- * @param handler - handler to actually showing notification, MUST BE PROVEDED
24
- * @returns unsubscribe handler
25
- */
26
- export declare function listenToPushNotificationsReceived(env: PushNotificationEnv, handler: (notification: Types.INotification) => void | Promise<void>): Promise<(() => void) | null>;
27
- /**
28
- * Service Worker Listener for when a notification is clicked
29
- *
30
- * @param handler - listen to NotificationEvent from the service worker
31
- * @returns unsubscribe handler
32
- */
33
- export declare function listenToPushNotificationsClicked(handler: (e: NotificationEvent, notification?: Types.INotification) => void): () => void;
34
- //# sourceMappingURL=push-web.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"push-web.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,0DAAgD;AAGrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAA6B;AAMhE,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;;;;GAMG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACnE,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAoC9B;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,cAY5E"}
@@ -1,142 +0,0 @@
1
- function $importDefault(module) {
2
- if (module?.__esModule) {
3
- return module.default;
4
- }
5
- return module;
6
- }
7
- import { getApp, initializeApp } from "firebase/app";
8
- import { getToken, deleteToken } from "firebase/messaging";
9
- import { getMessaging, onBackgroundMessage, isSupported } from "firebase/messaging/sw";
10
- import $log from "loglevel";
11
- const log = $importDefault($log);
12
- import { Processors } from "../../../NotificationServicesController/index.mjs";
13
- import { toRawAPINotification } from "../../../shared/to-raw-notification.mjs";
14
- // Exported to help testing
15
- // eslint-disable-next-line import-x/no-mutable-exports
16
- export let supportedCache = null;
17
- const getPushAvailability = async () => {
18
- supportedCache ?? (supportedCache = await isSupported());
19
- return supportedCache;
20
- };
21
- const createFirebaseApp = async (env) => {
22
- try {
23
- return getApp();
24
- }
25
- catch {
26
- const firebaseConfig = {
27
- apiKey: env.apiKey,
28
- authDomain: env.authDomain,
29
- storageBucket: env.storageBucket,
30
- projectId: env.projectId,
31
- messagingSenderId: env.messagingSenderId,
32
- appId: env.appId,
33
- measurementId: env.measurementId,
34
- };
35
- return initializeApp(firebaseConfig);
36
- }
37
- };
38
- const getFirebaseMessaging = async (env) => {
39
- const supported = await getPushAvailability();
40
- if (!supported) {
41
- return null;
42
- }
43
- const app = await createFirebaseApp(env);
44
- return getMessaging(app);
45
- };
46
- /**
47
- * Creates a registration token for Firebase Cloud Messaging.
48
- *
49
- * @param env - env to configure push notifications
50
- * @returns A promise that resolves with the registration token or null if an error occurs.
51
- */
52
- export async function createRegToken(env) {
53
- try {
54
- const messaging = await getFirebaseMessaging(env);
55
- if (!messaging) {
56
- return null;
57
- }
58
- const token = await getToken(messaging, {
59
- serviceWorkerRegistration: self.registration,
60
- vapidKey: env.vapidKey,
61
- });
62
- return token;
63
- }
64
- catch {
65
- return null;
66
- }
67
- }
68
- /**
69
- * Deletes the Firebase Cloud Messaging registration token.
70
- *
71
- * @param env - env to configure push notifications
72
- * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.
73
- */
74
- export async function deleteRegToken(env) {
75
- try {
76
- const messaging = await getFirebaseMessaging(env);
77
- if (!messaging) {
78
- return true;
79
- }
80
- await deleteToken(messaging);
81
- return true;
82
- }
83
- catch {
84
- return false;
85
- }
86
- }
87
- /**
88
- * Service Worker Listener for when push notifications are received.
89
- *
90
- * @param env - push notification environment
91
- * @param handler - handler to actually showing notification, MUST BE PROVEDED
92
- * @returns unsubscribe handler
93
- */
94
- export async function listenToPushNotificationsReceived(env, handler) {
95
- const messaging = await getFirebaseMessaging(env);
96
- if (!messaging) {
97
- return null;
98
- }
99
- const unsubscribePushNotifications = onBackgroundMessage(messaging,
100
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
101
- async (payload) => {
102
- try {
103
- const data = payload?.data
104
- ?.data
105
- ? JSON.parse(payload?.data?.data)
106
- : undefined;
107
- if (!data) {
108
- return;
109
- }
110
- const notificationData = toRawAPINotification(data);
111
- const notification = Processors.processNotification(notificationData);
112
- await handler(notification);
113
- }
114
- catch (error) {
115
- // Do Nothing, cannot parse a bad notification
116
- log.error('Unable to send push notification:', {
117
- notification: payload?.data?.data,
118
- error,
119
- });
120
- throw new Error('Unable to send push notification');
121
- }
122
- });
123
- const unsubscribe = () => unsubscribePushNotifications();
124
- return unsubscribe;
125
- }
126
- /**
127
- * Service Worker Listener for when a notification is clicked
128
- *
129
- * @param handler - listen to NotificationEvent from the service worker
130
- * @returns unsubscribe handler
131
- */
132
- export function listenToPushNotificationsClicked(handler) {
133
- const clickHandler = (event) => {
134
- // Get Data
135
- const data = event?.notification?.data;
136
- handler(event, data);
137
- };
138
- self.addEventListener('notificationclick', clickHandler);
139
- const unsubscribe = () => self.removeEventListener('notificationclick', clickHandler);
140
- return unsubscribe;
141
- }
142
- //# sourceMappingURL=push-web.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"push-web.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";;;;;;AAIA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,qBAAqB;AACrD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B;AAC3D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACZ,8BAA8B;AAE/B,OAAO,IAAG,iBAAiB;;AAG3B,OAAO,EAAE,UAAU,EAAE,0DAAgD;AACrE,OAAO,EAAE,oBAAoB,EAAE,gDAA4C;AAK3E,2BAA2B;AAC3B,uDAAuD;AACvD,MAAM,CAAC,IAAI,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,cAAc,KAAd,cAAc,GAAK,MAAM,WAAW,EAAE,EAAC;IACvC,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAC7B,GAAwB,EACF,EAAE;IACxB,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,iBAAiB,EAAE,GAAG,CAAC,iBAAiB;YACxC,KAAK,EAAE,GAAG,CAAC,KAAK;YAChB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KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;QAC5D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../../NotificationServicesController';\nimport { Processors } from '../../../NotificationServicesController';\nimport { toRawAPINotification } from '../../../shared/to-raw-notification';\nimport type { PushNotificationEnv } from '../../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVEDED\n * @returns unsubscribe handler\n */\nexport async function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedRawNotification | undefined = payload?.data\n ?.data\n ? JSON.parse(payload?.data?.data)\n : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawAPINotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nexport function listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification?: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n"]}
@@ -1,9 +0,0 @@
1
- {
2
- "version": "1.0.0",
3
- "private": true,
4
- "description": "",
5
- "license": "MIT",
6
- "sideEffects": false,
7
- "main": "../../dist/NotificationServicesController/ui/index.cjs",
8
- "types": "../../dist/NotificationServicesController/ui/index.d.cts"
9
- }