@metamask/notification-services-controller 0.1.0 → 0.1.2

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 (170) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/dist/NotificationServicesController/NotificationServicesController.js +8 -8
  3. package/dist/NotificationServicesController/NotificationServicesController.mjs +7 -7
  4. package/dist/NotificationServicesController/constants/constants.js +1 -1
  5. package/dist/NotificationServicesController/constants/constants.mjs +1 -1
  6. package/dist/NotificationServicesController/constants/index.js +6 -4
  7. package/dist/NotificationServicesController/constants/index.mjs +5 -3
  8. package/dist/NotificationServicesController/constants/notification-schema.js +5 -3
  9. package/dist/NotificationServicesController/constants/notification-schema.mjs +4 -2
  10. package/dist/NotificationServicesController/index.js +18 -13
  11. package/dist/NotificationServicesController/index.mjs +17 -12
  12. package/dist/NotificationServicesController/processors/index.js +5 -5
  13. package/dist/NotificationServicesController/processors/index.mjs +4 -4
  14. package/dist/NotificationServicesController/processors/process-feature-announcement.js +1 -1
  15. package/dist/NotificationServicesController/processors/process-feature-announcement.mjs +1 -1
  16. package/dist/NotificationServicesController/processors/process-notifications.js +4 -4
  17. package/dist/NotificationServicesController/processors/process-notifications.mjs +3 -3
  18. package/dist/NotificationServicesController/processors/process-onchain-notifications.js +1 -1
  19. package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs +1 -1
  20. package/dist/NotificationServicesController/services/feature-announcements.js +4 -4
  21. package/dist/NotificationServicesController/services/feature-announcements.mjs +3 -3
  22. package/dist/NotificationServicesController/services/onchain-notifications.js +5 -5
  23. package/dist/NotificationServicesController/services/onchain-notifications.mjs +4 -4
  24. package/dist/NotificationServicesController/types/index.js +2 -2
  25. package/dist/NotificationServicesController/types/index.mjs +2 -2
  26. package/dist/NotificationServicesController/ui/constants.js +14 -0
  27. package/dist/NotificationServicesController/ui/constants.mjs +14 -0
  28. package/dist/NotificationServicesController/ui/index.js +15 -0
  29. package/dist/NotificationServicesController/ui/index.js.map +1 -0
  30. package/dist/NotificationServicesController/ui/index.mjs +15 -0
  31. package/dist/NotificationServicesController/ui/index.mjs.map +1 -0
  32. package/dist/NotificationServicesController/utils/utils.js +4 -4
  33. package/dist/NotificationServicesController/utils/utils.mjs +3 -3
  34. package/dist/NotificationServicesPushController/NotificationServicesPushController.js +20 -16
  35. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +21 -17
  36. package/dist/NotificationServicesPushController/constants.js +1 -1
  37. package/dist/NotificationServicesPushController/constants.mjs +1 -1
  38. package/dist/NotificationServicesPushController/index.js +24 -20
  39. package/dist/NotificationServicesPushController/index.mjs +25 -21
  40. package/dist/NotificationServicesPushController/services/endpoints.js +1 -1
  41. package/dist/NotificationServicesPushController/services/endpoints.mjs +1 -1
  42. package/dist/NotificationServicesPushController/services/push/push-web.js +16 -14
  43. package/dist/NotificationServicesPushController/services/push/push-web.mjs +15 -13
  44. package/dist/NotificationServicesPushController/services/services.js +17 -15
  45. package/dist/NotificationServicesPushController/services/services.mjs +16 -14
  46. package/dist/NotificationServicesPushController/utils/get-notification-data.js +1 -1
  47. package/dist/NotificationServicesPushController/utils/get-notification-data.mjs +1 -1
  48. package/dist/NotificationServicesPushController/utils/get-notification-message.js +16 -14
  49. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +15 -13
  50. package/dist/NotificationServicesPushController/utils/index.js +17 -15
  51. package/dist/NotificationServicesPushController/utils/index.mjs +16 -14
  52. package/dist/{chunk-YRWUXGL3.js → chunk-2Z3NDVOV.js} +146 -114
  53. package/dist/chunk-2Z3NDVOV.js.map +1 -0
  54. package/dist/{chunk-RYAHBEX2.mjs → chunk-4VVOTF2Y.mjs} +51 -19
  55. package/dist/chunk-4VVOTF2Y.mjs.map +1 -0
  56. package/dist/{chunk-GFAESVZA.js → chunk-5FUMSWDD.js} +3 -3
  57. package/dist/chunk-5IPZMRR5.mjs +23 -0
  58. package/dist/chunk-5IPZMRR5.mjs.map +1 -0
  59. package/dist/{chunk-DKQBDI4C.js → chunk-5TUHE2FM.js} +41 -39
  60. package/dist/chunk-5TUHE2FM.js.map +1 -0
  61. package/dist/{chunk-SSWX2N73.mjs → chunk-6GUOLD7O.mjs} +2 -2
  62. package/dist/{chunk-NJBJIZLR.js → chunk-72H2V4J5.js} +6 -7
  63. package/dist/chunk-72H2V4J5.js.map +1 -0
  64. package/dist/chunk-7SDGAI6Z.mjs +29 -0
  65. package/dist/chunk-7SDGAI6Z.mjs.map +1 -0
  66. package/dist/{chunk-52NKJDI2.mjs → chunk-A5QFYBTR.mjs} +5 -6
  67. package/dist/chunk-A5QFYBTR.mjs.map +1 -0
  68. package/dist/{chunk-TT56I53C.mjs → chunk-ADYRLXWY.mjs} +2 -2
  69. package/dist/chunk-AQPBSNWA.js +23 -0
  70. package/dist/chunk-AQPBSNWA.js.map +1 -0
  71. package/dist/{chunk-PGMXFZ6Y.js → chunk-BUT7X5F2.js} +3 -3
  72. package/dist/chunk-D7VP2FPR.js +929 -0
  73. package/dist/chunk-D7VP2FPR.js.map +1 -0
  74. package/dist/{chunk-JLHFZ2UG.mjs → chunk-DCADU5QI.mjs} +3 -3
  75. package/dist/{chunk-VOZ7Y2OO.js → chunk-DNVD3CHQ.js} +8 -8
  76. package/dist/{chunk-FFQNSBPU.js → chunk-ENRKCWJ6.js} +7 -7
  77. package/dist/{chunk-UIRZIKC3.mjs → chunk-EZHMYHBX.mjs} +2 -2
  78. package/dist/{chunk-NMLYB3XT.js → chunk-GJHW5Z65.js} +4 -4
  79. package/dist/{chunk-ZMNXLHAC.js → chunk-HZEB53A6.js} +15 -35
  80. package/dist/chunk-HZEB53A6.js.map +1 -0
  81. package/dist/chunk-IGY2S5BC.js +36 -0
  82. package/dist/chunk-IGY2S5BC.js.map +1 -0
  83. package/dist/{chunk-SMKJEA45.mjs → chunk-ILPTPB4U.mjs} +4 -26
  84. package/dist/chunk-ILPTPB4U.mjs.map +1 -0
  85. package/dist/{chunk-VC6J62JI.mjs → chunk-J4D2NH6Y.mjs} +4 -2
  86. package/dist/chunk-J4D2NH6Y.mjs.map +1 -0
  87. package/dist/{chunk-RQWUD2FB.mjs → chunk-KCWTVLMK.mjs} +2 -2
  88. package/dist/{chunk-UPVIT75F.js → chunk-KWTSMLND.js} +6 -6
  89. package/dist/{chunk-NXXY4CAP.js → chunk-MT4VCZEE.js} +11 -36
  90. package/dist/chunk-MT4VCZEE.js.map +1 -0
  91. package/dist/{chunk-PIZCE3JD.js → chunk-NOYP2T77.js} +8 -30
  92. package/dist/{chunk-PIZCE3JD.js.map → chunk-NOYP2T77.js.map} +1 -1
  93. package/dist/{chunk-EQWVJX6K.mjs → chunk-QFJZBLYQ.mjs} +14 -34
  94. package/dist/chunk-QFJZBLYQ.mjs.map +1 -0
  95. package/dist/chunk-QY4UST5V.js +37 -0
  96. package/dist/chunk-QY4UST5V.js.map +1 -0
  97. package/dist/{chunk-LFD7J7KR.mjs → chunk-R373BQEU.mjs} +10 -35
  98. package/dist/chunk-R373BQEU.mjs.map +1 -0
  99. package/dist/chunk-S2FM5DOS.js +29 -0
  100. package/dist/chunk-S2FM5DOS.js.map +1 -0
  101. package/dist/chunk-U5UIDVOO.mjs +36 -0
  102. package/dist/chunk-U5UIDVOO.mjs.map +1 -0
  103. package/dist/{chunk-DY4ELDRQ.js → chunk-V6P5JEPT.js} +5 -3
  104. package/dist/chunk-V6P5JEPT.js.map +1 -0
  105. package/dist/{chunk-QTK2RMF7.mjs → chunk-X42WN3FE.mjs} +3 -3
  106. package/dist/{chunk-ODZ6V4PH.mjs → chunk-XVIUHFC3.mjs} +9 -7
  107. package/dist/chunk-XVIUHFC3.mjs.map +1 -0
  108. package/dist/chunk-YYWFWJTJ.mjs +929 -0
  109. package/dist/chunk-YYWFWJTJ.mjs.map +1 -0
  110. package/dist/{chunk-VE4DTN4R.mjs → chunk-ZHAD55AN.mjs} +5 -3
  111. package/dist/{chunk-VE4DTN4R.mjs.map → chunk-ZHAD55AN.mjs.map} +1 -1
  112. package/dist/index.js +22 -20
  113. package/dist/index.mjs +21 -19
  114. package/dist/tsconfig.build.tsbuildinfo +1 -1
  115. package/dist/types/NotificationServicesController/NotificationServicesController.d.ts +2 -0
  116. package/dist/types/NotificationServicesController/NotificationServicesController.d.ts.map +1 -1
  117. package/dist/types/NotificationServicesController/__fixtures__/index.d.ts +0 -1
  118. package/dist/types/NotificationServicesController/__fixtures__/index.d.ts.map +1 -1
  119. package/dist/types/NotificationServicesController/__fixtures__/mock-raw-notifications.d.ts.map +1 -1
  120. package/dist/types/NotificationServicesController/constants/notification-schema.d.ts +14 -8
  121. package/dist/types/NotificationServicesController/constants/notification-schema.d.ts.map +1 -1
  122. package/dist/types/NotificationServicesController/index.d.ts +1 -0
  123. package/dist/types/NotificationServicesController/index.d.ts.map +1 -1
  124. package/dist/types/NotificationServicesController/services/feature-announcements.d.ts.map +1 -1
  125. package/dist/types/NotificationServicesController/ui/constants.d.ts +20 -0
  126. package/dist/types/NotificationServicesController/ui/constants.d.ts.map +1 -0
  127. package/dist/types/NotificationServicesController/ui/index.d.ts +2 -0
  128. package/dist/types/NotificationServicesController/ui/index.d.ts.map +1 -0
  129. package/dist/types/NotificationServicesController/utils/utils.d.ts +1 -3
  130. package/dist/types/NotificationServicesController/utils/utils.d.ts.map +1 -1
  131. package/dist/types/NotificationServicesPushController/NotificationServicesPushController.d.ts +1 -0
  132. package/dist/types/NotificationServicesPushController/NotificationServicesPushController.d.ts.map +1 -1
  133. package/dist/types/NotificationServicesPushController/__fixtures__/index.d.ts +0 -1
  134. package/dist/types/NotificationServicesPushController/__fixtures__/index.d.ts.map +1 -1
  135. package/package.json +6 -6
  136. package/dist/chunk-26CCETCM.mjs +0 -70
  137. package/dist/chunk-4KZO4UUC.js +0 -4300
  138. package/dist/chunk-4KZO4UUC.js.map +0 -1
  139. package/dist/chunk-52NKJDI2.mjs.map +0 -1
  140. package/dist/chunk-CQ6CGSKZ.js +0 -35
  141. package/dist/chunk-CQ6CGSKZ.js.map +0 -1
  142. package/dist/chunk-DKQBDI4C.js.map +0 -1
  143. package/dist/chunk-DY4ELDRQ.js.map +0 -1
  144. package/dist/chunk-EQWVJX6K.mjs.map +0 -1
  145. package/dist/chunk-HCOBC2R5.mjs +0 -4300
  146. package/dist/chunk-HCOBC2R5.mjs.map +0 -1
  147. package/dist/chunk-LFD7J7KR.mjs.map +0 -1
  148. package/dist/chunk-NJBJIZLR.js.map +0 -1
  149. package/dist/chunk-NXXY4CAP.js.map +0 -1
  150. package/dist/chunk-ODZ6V4PH.mjs.map +0 -1
  151. package/dist/chunk-RYAHBEX2.mjs.map +0 -1
  152. package/dist/chunk-SMKJEA45.mjs.map +0 -1
  153. package/dist/chunk-V46WVGWN.js +0 -70
  154. package/dist/chunk-VC6J62JI.mjs.map +0 -1
  155. package/dist/chunk-YRWUXGL3.js.map +0 -1
  156. package/dist/chunk-ZMNXLHAC.js.map +0 -1
  157. /package/dist/{chunk-V46WVGWN.js.map → NotificationServicesController/ui/constants.js.map} +0 -0
  158. /package/dist/{chunk-26CCETCM.mjs.map → NotificationServicesController/ui/constants.mjs.map} +0 -0
  159. /package/dist/{chunk-GFAESVZA.js.map → chunk-5FUMSWDD.js.map} +0 -0
  160. /package/dist/{chunk-SSWX2N73.mjs.map → chunk-6GUOLD7O.mjs.map} +0 -0
  161. /package/dist/{chunk-TT56I53C.mjs.map → chunk-ADYRLXWY.mjs.map} +0 -0
  162. /package/dist/{chunk-PGMXFZ6Y.js.map → chunk-BUT7X5F2.js.map} +0 -0
  163. /package/dist/{chunk-JLHFZ2UG.mjs.map → chunk-DCADU5QI.mjs.map} +0 -0
  164. /package/dist/{chunk-VOZ7Y2OO.js.map → chunk-DNVD3CHQ.js.map} +0 -0
  165. /package/dist/{chunk-FFQNSBPU.js.map → chunk-ENRKCWJ6.js.map} +0 -0
  166. /package/dist/{chunk-UIRZIKC3.mjs.map → chunk-EZHMYHBX.mjs.map} +0 -0
  167. /package/dist/{chunk-NMLYB3XT.js.map → chunk-GJHW5Z65.js.map} +0 -0
  168. /package/dist/{chunk-RQWUD2FB.mjs.map → chunk-KCWTVLMK.mjs.map} +0 -0
  169. /package/dist/{chunk-UPVIT75F.js.map → chunk-KWTSMLND.js.map} +0 -0
  170. /package/dist/{chunk-QTK2RMF7.mjs.map → chunk-X42WN3FE.mjs.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/NotificationServicesPushController/services/push/push-web.ts"],"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 { getMessaging, onBackgroundMessage } 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 type { PushNotificationEnv } from '../../types/firebase';\n\nconst sw = self as unknown as ServiceWorkerGlobalScope;\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> => {\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 const token = await getToken(messaging, {\n serviceWorkerRegistration: sw.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 await deleteToken(messaging);\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\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) {\n const messaging = await getFirebaseMessaging(env);\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const notificationData: Types.NotificationUnion = payload?.data?.data\n ? JSON.parse(payload?.data?.data)\n : undefined;\n\n if (!notificationData) {\n return;\n }\n\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 sw.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n sw.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n"],"mappings":";;;;;AAIA,SAAS,QAAQ,qBAAqB;AACtC,SAAS,UAAU,mBAAmB;AACtC,SAAS,cAAc,2BAA2B;AAElD,OA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;AAAA,UAC7C,cAAc,SAAS,MAAM;AAAA,UAC7B;AAAA,QACF,CAAC;AACD,cAAM,IAAI,MAAM,kCAAkC;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AAEA,QAAM,cAAc,MAAM,6BAA6B;AACvD,SAAO;AACT;AAQO,SAAS,iCACd,SACA;AACA,QAAM,eAAe,CAAC,UAA6B;AAEjD,UAAM,OAA4B,OAAO,cAAc;AACvD,YAAQ,OAAO,IAAI;AAAA,EACrB;AAEA,KAAG,iBAAiB,qBAAqB,YAAY;AACrD,QAAM,cAAc,MAClB,GAAG,oBAAoB,qBAAqB,YAAY;AAC1D,SAAO;AACT;","names":[]}
@@ -1,35 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
- var _chunkDY4ELDRQjs = require('./chunk-DY4ELDRQ.js');
10
-
11
-
12
-
13
- var _chunkTLX5QQK5js = require('./chunk-TLX5QQK5.js');
14
-
15
-
16
- var _chunkV46WVGWNjs = require('./chunk-V46WVGWN.js');
17
-
18
- // src/NotificationServicesController/constants/index.ts
19
- var constants_exports = {};
20
- _chunkV46WVGWNjs.__export.call(void 0, constants_exports, {
21
- CHAIN_SYMBOLS: () => _chunkDY4ELDRQjs.CHAIN_SYMBOLS,
22
- NOTIFICATION_CHAINS: () => _chunkDY4ELDRQjs.NOTIFICATION_CHAINS,
23
- SUPPORTED_CHAINS: () => _chunkDY4ELDRQjs.SUPPORTED_CHAINS,
24
- TRIGGERS: () => _chunkDY4ELDRQjs.TRIGGERS,
25
- TRIGGER_TYPES: () => _chunkDY4ELDRQjs.TRIGGER_TYPES,
26
- TRIGGER_TYPES_GROUPS: () => _chunkDY4ELDRQjs.TRIGGER_TYPES_GROUPS,
27
- TRIGGER_TYPES_WALLET_SET: () => _chunkDY4ELDRQjs.TRIGGER_TYPES_WALLET_SET,
28
- USER_STORAGE_VERSION: () => _chunkTLX5QQK5js.USER_STORAGE_VERSION,
29
- USER_STORAGE_VERSION_KEY: () => _chunkTLX5QQK5js.USER_STORAGE_VERSION_KEY
30
- });
31
-
32
-
33
-
34
- exports.constants_exports = constants_exports;
35
- //# sourceMappingURL=chunk-CQ6CGSKZ.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/NotificationServicesController/constants/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './constants';\nexport * from './notification-schema';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AAE/B,OAAO,SAAS;AAYhB,IAAM,iBAAiB;AAqDvB,IAAM,WAAW;AAAA,EACf,UAAU;AAAA,IACR,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AA5EA;AAqHA,IAAqB,qCAArB,cAAgE,eAI9D;AAAA,EAOA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAKG;AACD,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,MAAM;AAAA,MACN,OAAO;AAAA,QACL,UAAU,OAAO,YAAY;AAAA,MAC/B;AAAA,IACF,CAAC;AAQH;AAeA,uBAAM;AA/CN,iDAAqD;AAErD;AAEA;AAsBE,uBAAK,MAAO;AACZ,uBAAK,SAAU;AAEf,0BAAK,sDAAL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyCA,MAAM,wBAAwB,OAAiB;AAC7C,QAAI,CAAC,mBAAK,SAAQ,eAAe;AAC/B;AAAA,IACF;AAEA,UAAM,cAAc,MAAM,sBAAK,sDAAL;AAE1B,QAAI;AAEF,YAAM,WAAW,MAAM,0BAA0B;AAAA,QAC/C;AAAA,QACA,U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["import type {\n RestrictedControllerMessenger,\n ControllerGetStateAction,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport log from 'loglevel';\n\nimport type { Types } from '../NotificationServicesController';\nimport { createRegToken, deleteRegToken } from './services/push/push-web';\nimport {\n activatePushNotifications,\n deactivatePushNotifications,\n listenToPushNotifications,\n updateTriggerPushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n fcmToken: string;\n};\n\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `${typeof controllerName}:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\n};\n\nexport type NotificationServicesPushControllerDisablePushNotificationsAction = {\n type: `${typeof controllerName}:disablePushNotifications`;\n handler: NotificationServicesPushController['disablePushNotifications'];\n};\nexport type NotificationServicesPushControllerUpdateTriggerPushNotificationsAction =\n {\n type: `${typeof controllerName}:updateTriggerPushNotifications`;\n handler: NotificationServicesPushController['updateTriggerPushNotifications'];\n };\n\nexport type Actions =\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction\n | ControllerGetStateAction<'state', NotificationServicesPushControllerState>;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClicked = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type AllowedEvents =\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClicked;\n\nexport type NotificationServicesPushControllerMessenger =\n RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n >;\n\nconst metadata = {\n fcmToken: {\n persist: true,\n anonymous: true,\n },\n};\n\ntype ControllerConfig = {\n /**\n * Config to turn on/off push notifications.\n * This is currently linked to MV3 builds on extension.\n */\n isPushEnabled: boolean;\n\n /**\n * Must handle when a push notification is received.\n * You must call `registration.showNotification` or equivalent to show the notification on web/mobile\n */\n onPushNotificationReceived: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n\n /**\n * Must handle when a push notification is clicked.\n * You must call `event.notification.close();` or equivalent for closing and opening notification in a new window.\n */\n onPushNotificationClicked: (\n event: NotificationEvent,\n notification?: Types.INotification,\n ) => void;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n};\n\n/**\n * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.\n * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.\n * It is responsible for registering and unregistering the service worker that listens for push notifications,\n * managing the FCM token, and communicating with the server to register or unregister the device for push notifications.\n * Additionally, it provides functionality to update the server with new UUIDs that should trigger push notifications.\n *\n * @augments {BaseController<typeof controllerName, NotificationServicesPushControllerState, NotificationServicesPushControllerMessenger>}\n */\nexport default class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n #env: PushNotificationEnv;\n\n #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n env: PushNotificationEnv;\n config: ControllerConfig;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: {\n fcmToken: state?.fcmToken || '',\n },\n });\n\n this.#env = env;\n this.#config = config;\n\n this.#registerMessageHandlers();\n }\n\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:enablePushNotifications',\n this.enablePushNotifications.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:disablePushNotifications',\n this.disablePushNotifications.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:updateTriggerPushNotifications',\n this.updateTriggerPushNotifications.bind(this),\n );\n }\n\n async #getAndAssertBearerToken() {\n const bearerToken = await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!bearerToken) {\n log.error(\n 'Failed to enable push notifications: BearerToken token is missing.',\n );\n throw new Error('BearerToken token is missing');\n }\n\n return bearerToken;\n }\n\n /**\n * Enables push notifications for the application.\n *\n * This method sets up the necessary infrastructure for handling push notifications by:\n * 1. Registering the service worker to listen for messages.\n * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.\n * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.\n *\n * @param UUIDs - An array of UUIDs to enable push notifications for.\n */\n async enablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n\n try {\n // Activate Push Notifications\n const regToken = await activatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken,\n platform: this.#config.platform,\n });\n\n if (!regToken) {\n return;\n }\n\n this.#pushListenerUnsubscribe = await listenToPushNotifications({\n env: this.#env,\n listenToPushReceived: async (n) => {\n this.messagingSystem.publish(\n 'NotificationServicesPushController:onNewNotifications',\n n,\n );\n await this.#config.onPushNotificationReceived(n);\n },\n listenToPushClicked: (e, n) => {\n if (n) {\n this.messagingSystem.publish(\n 'NotificationServicesPushController:pushNotificationClicked',\n n,\n );\n }\n\n this.#config.onPushNotificationClicked(e);\n },\n });\n\n // Update state\n this.update((state) => {\n state.fcmToken = regToken;\n });\n } catch (error) {\n log.error('Failed to enable push notifications:', error);\n throw new Error('Failed to enable push notifications');\n }\n }\n\n /**\n * Disables push notifications for the application.\n * This method handles the process of disabling push notifications by:\n * 1. Unregistering the service worker to stop listening for messages.\n * 2. Sending a request to the server to unregister the device using the FCM token.\n * 3. Removing the FCM token from the state to complete the process.\n *\n * @param UUIDs - An array of UUIDs for which push notifications should be disabled.\n */\n async disablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n let isPushNotificationsDisabled: boolean;\n\n try {\n // Send a request to the server to unregister the token/device\n isPushNotificationsDisabled = await deactivatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n deleteRegToken,\n regToken: this.state.fcmToken,\n });\n } catch (error) {\n const errorMessage = `Failed to disable push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n }\n\n // Remove the FCM token from the state\n if (!isPushNotificationsDisabled) {\n return;\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n if (isPushNotificationsDisabled) {\n this.update((state) => {\n state.fcmToken = '';\n });\n }\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of UUIDs that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param UUIDs - An array of UUIDs that should trigger push notifications.\n */\n async updateTriggerPushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n\n try {\n const { fcmToken } = await updateTriggerPushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken,\n deleteRegToken,\n platform: this.#config.platform,\n regToken: this.state.fcmToken,\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.update((state) => {\n state.fcmToken = fcmToken;\n });\n }\n } catch (error) {\n const errorMessage = `Failed to update triggers for push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/NotificationServicesController/constants/notification-schema.ts"],"names":["TRIGGER_TY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ACpB,oBAAoB;AAAA,IACtB;AAAA,EACF;AAAA,EACA,CAAC,yCAA8B,GAAG;AAAA,IAChC,kBAAkB;AAAA,MAChB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,IACtB;AAAA,EACF;AAAA,EACA,CAAC,yBAAsB,GAAG;AAAA,IACxB,kBAAkB;AAAA,MAChB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,IACtB;AAAA,EACF;AAAA,EACA,CAAC,iCAA0B,GAAG;AAAA,IAC5B,kBAAkB;AAAA,MAChB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,MACpB,oBAAoB;AAAA,IACtB;AAAA,EACF;AAAA,EACA,CAAC,6DAAwC,GAAG;AAAA,IAC1C,kBAAkB,CAAC,oBAAoB,QAAQ;AAAA,EACjD;AAAA,EACA,CAAC,iEAA0C,GAAG;AAAA,IAC5C,kBAAkB,CAAC,oBAAoB,QAAQ;AAAA,EACjD;AAAA,EACA,CAAC,iDAAkC,GAAG;AAAA,IACpC,kBAAkB,CAAC,oBAAoB,QAAQ;AAAA,EACjD;AAAA,EACA,CAAC,2DAAuC,GAAG;AAAA,IACzC,kBAAkB,CAAC,oBAAoB,QAAQ;AAAA,EACjD;AAAA,EACA,CAAC,2DAAuC,GAAG;AAAA,IACzC,kBAAkB,CAAC,oBAAoB,QAAQ;AAAA,EACjD;AACF","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nexport enum TRIGGER_TYPES {\n FEATURES_ANNOUNCEMENT = 'features_announcement',\n METAMASK_SWAP_COMPLETED = 'metamask_swap_completed',\n ERC20_SENT = 'erc20_sent',\n ERC20_RECEIVED = 'erc20_received',\n ETH_SENT = 'eth_sent',\n ETH_RECEIVED = 'eth_received',\n ROCKETPOOL_STAKE_COMPLETED = 'rocketpool_stake_completed',\n ROCKETPOOL_UNSTAKE_COMPLETED = 'rocketpool_unstake_completed',\n LIDO_STAKE_COMPLETED = 'lido_stake_completed',\n LIDO_WITHDRAWAL_REQUESTED = 'lido_withdrawal_requested',\n LIDO_WITHDRAWAL_COMPLETED = 'lido_withdrawal_completed',\n LIDO_STAKE_READY_TO_BE_WITHDRAWN = 'lido_stake_ready_to_be_withdrawn',\n ERC721_SENT = 'erc721_sent',\n ERC721_RECEIVED = 'erc721_received',\n ERC1155_SENT = 'erc1155_sent',\n ERC1155_RECEIVED = 'erc1155_received',\n}\n\nexport const TRIGGER_TYPES_WALLET_SET: Set<string> = new Set([\n TRIGGER_TYPES.METAMASK_SWAP_COMPLETED,\n TRIGGER_TYPES.ERC20_SENT,\n TRIGGER_TYPES.ERC20_RECEIVED,\n TRIGGER_TYPES.ETH_SENT,\n TRIGGER_TYPES.ETH_RECEIVED,\n TRIGGER_TYPES.ROCKETPOOL_STAKE_COMPLETED,\n TRIGGER_TYPES.ROCKETPOOL_UNSTAKE_COMPLETED,\n TRIGGER_TYPES.LIDO_STAKE_COMPLETED,\n TRIGGER_TYPES.LIDO_WITHDRAWAL_REQUESTED,\n TRIGGER_TYPES.LIDO_WITHDRAWAL_COMPLETED,\n TRIGGER_TYPES.LIDO_STAKE_READY_TO_BE_WITHDRAWN,\n TRIGGER_TYPES.ERC721_SENT,\n TRIGGER_TYPES.ERC721_RECEIVED,\n TRIGGER_TYPES.ERC1155_SENT,\n TRIGGER_TYPES.ERC1155_RECEIVED,\n]) satisfies Set<Exclude<TRIGGER_TYPES, TRIGGER_TYPES.FEATURES_ANNOUNCEMENT>>;\n\nexport enum TRIGGER_TYPES_GROUPS {\n RECEIVED = 'received',\n SENT = 'sent',\n DEFI = 'defi',\n}\n\nexport const NOTIFICATION_CHAINS = {\n ETHEREUM: '1',\n OPTIMISM: '10',\n BSC: '56',\n POLYGON: '137',\n ARBITRUM: '42161',\n AVALANCHE: '43114',\n LINEA: '59144',\n};\n\nexport const CHAIN_SYMBOLS = {\n [NOTIFICATION_CHAINS.ETHEREUM]: 'ETH',\n [NOTIFICATION_CHAINS.OPTIMISM]: 'ETH',\n [NOTIFICATION_CHAINS.BSC]: 'BNB',\n [NOTIFICATION_CHAINS.POLYGON]: 'MATIC',\n [NOTIFICATION_CHAINS.ARBITRUM]: 'ETH',\n [NOTIFICATION_CHAINS.AVALANCHE]: 'AVAX',\n [NOTIFICATION_CHAINS.LINEA]: 'ETH',\n};\n\nexport const SUPPORTED_CHAINS = [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.OPTIMISM,\n NOTIFICATION_CHAINS.BSC,\n NOTIFICATION_CHAINS.POLYGON,\n NOTIFICATION_CHAINS.ARBITRUM,\n NOTIFICATION_CHAINS.AVALANCHE,\n NOTIFICATION_CHAINS.LINEA,\n];\n\nexport type Trigger = {\n supported_chains: (typeof SUPPORTED_CHAINS)[number][];\n};\n\nexport const TRIGGERS: Partial<Record<TRIGGER_TYPES, Trigger>> = {\n [TRIGGER_TYPES.METAMASK_SWAP_COMPLETED]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.OPTIMISM,\n NOTIFICATION_CHAINS.BSC,\n NOTIFICATION_CHAINS.POLYGON,\n NOTIFICATION_CHAINS.ARBITRUM,\n NOTIFICATION_CHAINS.AVALANCHE,\n ],\n },\n [TRIGGER_TYPES.ERC20_SENT]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.OPTIMISM,\n NOTIFICATION_CHAINS.BSC,\n NOTIFICATION_CHAINS.POLYGON,\n NOTIFICATION_CHAINS.ARBITRUM,\n NOTIFICATION_CHAINS.AVALANCHE,\n NOTIFICATION_CHAINS.LINEA,\n ],\n },\n [TRIGGER_TYPES.ERC20_RECEIVED]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.OPTIMISM,\n NOTIFICATION_CHAINS.BSC,\n NOTIFICATION_CHAINS.POLYGON,\n NOTIFICATION_CHAINS.ARBITRUM,\n NOTIFICATION_CHAINS.AVALANCHE,\n NOTIFICATION_CHAINS.LINEA,\n ],\n },\n [TRIGGER_TYPES.ERC721_SENT]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.POLYGON,\n ],\n },\n [TRIGGER_TYPES.ERC721_RECEIVED]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.POLYGON,\n ],\n },\n [TRIGGER_TYPES.ERC1155_SENT]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.POLYGON,\n ],\n },\n [TRIGGER_TYPES.ERC1155_RECEIVED]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.POLYGON,\n ],\n },\n [TRIGGER_TYPES.ETH_SENT]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.OPTIMISM,\n NOTIFICATION_CHAINS.BSC,\n NOTIFICATION_CHAINS.POLYGON,\n NOTIFICATION_CHAINS.ARBITRUM,\n NOTIFICATION_CHAINS.AVALANCHE,\n NOTIFICATION_CHAINS.LINEA,\n ],\n },\n [TRIGGER_TYPES.ETH_RECEIVED]: {\n supported_chains: [\n NOTIFICATION_CHAINS.ETHEREUM,\n NOTIFICATION_CHAINS.OPTIMISM,\n NOTIFICATION_CHAINS.BSC,\n NOTIFICATION_CHAINS.POLYGON,\n NOTIFICATION_CHAINS.ARBITRUM,\n NOTIFICATION_CHAINS.AVALANCHE,\n NOTIFICATION_CHAINS.LINEA,\n ],\n },\n [TRIGGER_TYPES.ROCKETPOOL_STAKE_COMPLETED]: {\n supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],\n },\n [TRIGGER_TYPES.ROCKETPOOL_UNSTAKE_COMPLETED]: {\n supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],\n },\n [TRIGGER_TYPES.LIDO_STAKE_COMPLETED]: {\n supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],\n },\n [TRIGGER_TYPES.LIDO_WITHDRAWAL_REQUESTED]: {\n supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],\n },\n [TRIGGER_TYPES.LIDO_WITHDRAWAL_COMPLETED]: {\n supported_chains: [NOTIFICATION_CHAINS.ETHEREUM],\n },\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/NotificationServicesController/services/feature-announcements.ts"],"sourcesContent":["import { documentToHtmlString } from '@contentful/rich-text-html-renderer';\nimport type { Entry, Asset } from 'contentful';\nimport log from 'loglevel';\n\nimport { TRIGGER_TYPES } from '../constants/notification-schema';\nimport { processFeatureAnnouncement } from '../processors/process-feature-announcement';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n ImageFields,\n TypeFeatureAnnouncement,\n} from '../types/feature-announcement/type-feature-announcement';\nimport type { TypeExtensionLinkFields } from '../types/feature-announcement/type-links';\nimport type { INotification } from '../types/notification/notification';\n\nconst DEFAULT_SPACE_ID = ':space_id';\nconst DEFAULT_ACCESS_TOKEN = ':access_token';\nconst DEFAULT_CLIENT_ID = ':client_id';\nexport const FEATURE_ANNOUNCEMENT_API = `https://cdn.contentful.com/spaces/${DEFAULT_SPACE_ID}/environments/master/entries`;\nexport const FEATURE_ANNOUNCEMENT_URL = `${FEATURE_ANNOUNCEMENT_API}?access_token=${DEFAULT_ACCESS_TOKEN}&content_type=productAnnouncement&include=10&fields.clients=${DEFAULT_CLIENT_ID}`;\n\ntype Env = {\n spaceId: string;\n accessToken: string;\n platform: string;\n};\n\n/**\n * Contentful API Response Shape\n */\nexport type ContentfulResult = {\n includes?: {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Entry?: Entry[];\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Asset?: Asset[];\n };\n items?: TypeFeatureAnnouncement[];\n};\n\nconst fetchFromContentful = async (\n url: string,\n retries = 3,\n retryDelay = 1000,\n): Promise<ContentfulResult | null> => {\n let lastError: Error | null = null;\n\n for (let i = 0; i < retries; i++) {\n try {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Fetch failed with status: ${response.status}`);\n }\n return await response.json();\n } catch (error) {\n if (error instanceof Error) {\n lastError = error;\n }\n if (i < retries - 1) {\n await new Promise((resolve) => setTimeout(resolve, retryDelay));\n }\n }\n }\n\n log.error(\n `Error fetching from Contentful after ${retries} retries:`,\n lastError,\n );\n return null;\n};\n\nconst fetchFeatureAnnouncementNotifications = async (\n env: Env,\n): Promise<FeatureAnnouncementRawNotification[]> => {\n const url = FEATURE_ANNOUNCEMENT_URL.replace(DEFAULT_SPACE_ID, env.spaceId)\n .replace(DEFAULT_ACCESS_TOKEN, env.accessToken)\n .replace(DEFAULT_CLIENT_ID, env.platform);\n const data = await fetchFromContentful(url);\n\n if (!data) {\n return [];\n }\n\n const findIncludedItem = (sysId: string) => {\n const item =\n data?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) ||\n data?.includes?.Asset?.find((i: Asset) => i?.sys?.id === sysId);\n return item ? item?.fields : null;\n };\n\n const contentfulNotifications = data?.items ?? [];\n const rawNotifications: FeatureAnnouncementRawNotification[] =\n contentfulNotifications.map((n: TypeFeatureAnnouncement) => {\n const { fields } = n;\n const imageFields = fields.image\n ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields'])\n : undefined;\n const extensionLinkFields = fields.extensionLink\n ? (findIncludedItem(\n fields.extensionLink.sys.id,\n ) as TypeExtensionLinkFields['fields'])\n : undefined;\n\n const notification: FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,\n createdAt: new Date(n.sys.createdAt).toString(),\n data: {\n id: fields.id,\n category: fields.category,\n title: fields.title,\n longDescription: documentToHtmlString(fields.longDescription),\n shortDescription: fields.shortDescription,\n image: {\n title: imageFields?.title,\n description: imageFields?.description,\n url: imageFields?.file?.url ?? '',\n },\n extensionLink: extensionLinkFields && {\n extensionLinkText: extensionLinkFields?.extensionLinkText,\n extensionLinkRoute: extensionLinkFields?.extensionLinkRoute,\n },\n },\n };\n\n return notification;\n });\n\n return rawNotifications;\n};\n\n/**\n * Gets Feature Announcement from our services\n * @param env - environment for feature announcements\n * @returns Raw Feature Announcements\n */\nexport async function getFeatureAnnouncementNotifications(\n env: Env,\n): Promise<INotification[]> {\n const rawNotifications = await fetchFeatureAnnouncementNotifications(env);\n const notifications = rawNotifications.map((notification) =>\n processFeatureAnnouncement(notification),\n );\n\n return notifications;\n}\n"],"mappings":";;;;;AAAA,SAAS,4BAA4B;AAErC,OAAO,SAAS;AAYhB,IAAM,mBAAmB;AACzB,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB;AACnB,IAAM,2BAA2B,qCAAqC,gBAAgB;AACtF,IAAM,2BAA2B,GAAG,wBAAwB,iBAAiB,oBAAoB,+DAA+D,iBAAiB;AAqBxL,IAAM,sBAAsB,OAC1B,KACA,UAAU,GACV,aAAa,QACwB;AACrC,MAAI,YAA0B;AAE9B,WAAS,IAAI,GAAG,IAAI,SAAS,KAAK;AAChC,QAAI;AACF,YAAM,WAAW,MAAM,MAAM,GAAG;AAChC,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,IAAI,MAAM,6BAA6B,SAAS,MAAM,EAAE;AAAA,MAChE;AACA,aAAO,MAAM,SAAS,KAAK;AAAA,IAC7B,SAAS,OAAO;AACd,UAAI,iBAAiB,OAAO;AAC1B,oBAAY;AAAA,MACd;AACA,UAAI,IAAI,UAAU,GAAG;AACnB,cAAM,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,UAAU,CAAC;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AAEA,MAAI;AAAA,IACF,wCAAwC,OAAO;AAAA,IAC/C;AAAA,EACF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