@metamask-previews/notification-services-controller 0.1.0-preview-95089367 → 0.1.0-preview-caf274f8
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.
- package/dist/NotificationServicesController/NotificationServicesController.js +3 -3
- package/dist/NotificationServicesController/NotificationServicesController.mjs +2 -2
- package/dist/NotificationServicesController/constants/constants.js +1 -1
- package/dist/NotificationServicesController/constants/constants.mjs +1 -1
- package/dist/NotificationServicesController/constants/index.js +2 -2
- package/dist/NotificationServicesController/constants/index.mjs +2 -2
- package/dist/NotificationServicesController/constants/notification-schema.js +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.mjs +1 -1
- package/dist/NotificationServicesController/index.js +6 -6
- package/dist/NotificationServicesController/index.mjs +5 -5
- package/dist/NotificationServicesController/processors/index.js +2 -2
- package/dist/NotificationServicesController/processors/index.mjs +2 -2
- package/dist/NotificationServicesController/processors/process-feature-announcement.js +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.mjs +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.js +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.mjs +1 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.js +1 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.js +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.mjs +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.js +1 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs +1 -1
- package/dist/NotificationServicesController/utils/utils.js +1 -1
- package/dist/NotificationServicesController/utils/utils.mjs +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.js +9 -9
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +8 -8
- package/dist/NotificationServicesPushController/constants.js +1 -1
- package/dist/NotificationServicesPushController/constants.mjs +1 -1
- package/dist/NotificationServicesPushController/index.js +12 -12
- package/dist/NotificationServicesPushController/index.mjs +11 -11
- package/dist/NotificationServicesPushController/services/endpoints.js +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.mjs +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.js +7 -7
- package/dist/NotificationServicesPushController/services/push/push-web.mjs +6 -6
- package/dist/NotificationServicesPushController/services/services.js +8 -8
- package/dist/NotificationServicesPushController/services/services.mjs +7 -7
- package/dist/NotificationServicesPushController/utils/get-notification-data.js +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.mjs +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.js +7 -7
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +6 -6
- package/dist/NotificationServicesPushController/utils/index.js +8 -8
- package/dist/NotificationServicesPushController/utils/index.mjs +7 -7
- package/dist/{chunk-QTK2RMF7.mjs → chunk-57S5B7X2.mjs} +2 -2
- package/dist/{chunk-UPVIT75F.js → chunk-6265FKB5.js} +3 -3
- package/dist/{chunk-DKQBDI4C.js → chunk-6GPIA5G3.js} +35 -35
- package/dist/{chunk-PGMXFZ6Y.js → chunk-ABFHAGGB.js} +3 -3
- package/dist/{chunk-SSWX2N73.mjs → chunk-AHEMTJDE.mjs} +2 -2
- package/dist/{chunk-TT56I53C.mjs → chunk-CQI6FYPZ.mjs} +2 -2
- package/dist/{chunk-JLHFZ2UG.mjs → chunk-DBTJ34DS.mjs} +3 -3
- package/dist/{chunk-YRWUXGL3.js → chunk-DOYL2MCR.js} +102 -82
- package/dist/chunk-DOYL2MCR.js.map +1 -0
- package/dist/{chunk-NJBJIZLR.js → chunk-H4RSHSWR.js} +6 -7
- package/dist/chunk-H4RSHSWR.js.map +1 -0
- package/dist/chunk-IGY2S5BC.js +36 -0
- package/dist/{chunk-CQ6CGSKZ.js → chunk-IK7KP7N3.js} +3 -3
- package/dist/{chunk-FFQNSBPU.js → chunk-KCIC5BWH.js} +7 -7
- package/dist/chunk-NBRY7XVG.mjs +925 -0
- package/dist/chunk-NBRY7XVG.mjs.map +1 -0
- package/dist/{chunk-NXXY4CAP.js → chunk-O6RMA2N6.js} +9 -36
- package/dist/chunk-O6RMA2N6.js.map +1 -0
- package/dist/{chunk-NMLYB3XT.js → chunk-QJTZL7TJ.js} +4 -4
- package/dist/{chunk-VE4DTN4R.mjs → chunk-QSFGJCPI.mjs} +2 -2
- package/dist/{chunk-52NKJDI2.mjs → chunk-TI4UC3G3.mjs} +5 -6
- package/dist/chunk-TI4UC3G3.mjs.map +1 -0
- package/dist/{chunk-LFD7J7KR.mjs → chunk-TS2NQOUA.mjs} +6 -33
- package/dist/chunk-TS2NQOUA.mjs.map +1 -0
- package/dist/chunk-U5UIDVOO.mjs +36 -0
- package/dist/chunk-XYIGTTEP.js +925 -0
- package/dist/chunk-XYIGTTEP.js.map +1 -0
- package/dist/{chunk-RYAHBEX2.mjs → chunk-YSNDM6BH.mjs} +26 -6
- package/dist/chunk-YSNDM6BH.mjs.map +1 -0
- package/dist/{chunk-ODZ6V4PH.mjs → chunk-ZFNFSLS6.mjs} +4 -4
- package/dist/index.js +12 -12
- package/dist/index.mjs +11 -11
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/NotificationServicesController/NotificationServicesController.d.ts +2 -0
- package/dist/types/NotificationServicesController/NotificationServicesController.d.ts.map +1 -1
- package/dist/types/NotificationServicesController/__fixtures__/index.d.ts +0 -1
- package/dist/types/NotificationServicesController/__fixtures__/index.d.ts.map +1 -1
- package/dist/types/NotificationServicesPushController/__fixtures__/index.d.ts +0 -1
- package/dist/types/NotificationServicesPushController/__fixtures__/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-26CCETCM.mjs +0 -70
- package/dist/chunk-4KZO4UUC.js +0 -4300
- package/dist/chunk-4KZO4UUC.js.map +0 -1
- package/dist/chunk-52NKJDI2.mjs.map +0 -1
- package/dist/chunk-HCOBC2R5.mjs +0 -4300
- package/dist/chunk-HCOBC2R5.mjs.map +0 -1
- package/dist/chunk-LFD7J7KR.mjs.map +0 -1
- package/dist/chunk-NJBJIZLR.js.map +0 -1
- package/dist/chunk-NXXY4CAP.js.map +0 -1
- package/dist/chunk-RYAHBEX2.mjs.map +0 -1
- package/dist/chunk-V46WVGWN.js +0 -70
- package/dist/chunk-YRWUXGL3.js.map +0 -1
- /package/dist/{chunk-QTK2RMF7.mjs.map → chunk-57S5B7X2.mjs.map} +0 -0
- /package/dist/{chunk-UPVIT75F.js.map → chunk-6265FKB5.js.map} +0 -0
- /package/dist/{chunk-DKQBDI4C.js.map → chunk-6GPIA5G3.js.map} +0 -0
- /package/dist/{chunk-PGMXFZ6Y.js.map → chunk-ABFHAGGB.js.map} +0 -0
- /package/dist/{chunk-SSWX2N73.mjs.map → chunk-AHEMTJDE.mjs.map} +0 -0
- /package/dist/{chunk-TT56I53C.mjs.map → chunk-CQI6FYPZ.mjs.map} +0 -0
- /package/dist/{chunk-JLHFZ2UG.mjs.map → chunk-DBTJ34DS.mjs.map} +0 -0
- /package/dist/{chunk-V46WVGWN.js.map → chunk-IGY2S5BC.js.map} +0 -0
- /package/dist/{chunk-CQ6CGSKZ.js.map → chunk-IK7KP7N3.js.map} +0 -0
- /package/dist/{chunk-FFQNSBPU.js.map → chunk-KCIC5BWH.js.map} +0 -0
- /package/dist/{chunk-NMLYB3XT.js.map → chunk-QJTZL7TJ.js.map} +0 -0
- /package/dist/{chunk-VE4DTN4R.mjs.map → chunk-QSFGJCPI.mjs.map} +0 -0
- /package/dist/{chunk-26CCETCM.mjs.map → chunk-U5UIDVOO.mjs.map} +0 -0
- /package/dist/{chunk-ODZ6V4PH.mjs.map → chunk-ZFNFSLS6.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,OAAO,SAAS;AAMhB,IAAM,KAAK;AAEX,IAAM,oBAAoB,OACxB,QACyB;AACzB,MAAI;AACF,WAAO,OAAO;AAAA,EAChB,QAAQ;AACN,UAAM,iBAAiB;AAAA,MACrB,QAAQ,IAAI;AAAA,MACZ,YAAY,IAAI;AAAA,MAChB,eAAe,IAAI;AAAA,MACnB,WAAW,IAAI;AAAA,MACf,mBAAmB,IAAI;AAAA,MACvB,OAAO,IAAI;AAAA,MACX,eAAe,IAAI;AAAA,IACrB;AACA,WAAO,cAAc,cAAc;AAAA,EACrC;AACF;AAEA,IAAM,uBAAuB,OAC3B,QACuB;AACvB,QAAM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