@metamask-previews/notification-services-controller 0.2.0-preview-c081c503 → 0.2.0-preview-f59de5e

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 (75) hide show
  1. package/dist/NotificationServicesController/NotificationServicesController.js +4 -3
  2. package/dist/NotificationServicesController/NotificationServicesController.mjs +3 -2
  3. package/dist/NotificationServicesController/index.js +17 -16
  4. package/dist/NotificationServicesController/index.mjs +16 -15
  5. package/dist/NotificationServicesController/services/onchain-notifications.js +3 -2
  6. package/dist/NotificationServicesController/services/onchain-notifications.mjs +2 -1
  7. package/dist/NotificationServicesController/types/index.js +2 -2
  8. package/dist/NotificationServicesController/types/index.mjs +2 -2
  9. package/dist/NotificationServicesPushController/NotificationServicesPushController.js +14 -13
  10. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +13 -12
  11. package/dist/NotificationServicesPushController/index.js +18 -17
  12. package/dist/NotificationServicesPushController/index.mjs +17 -16
  13. package/dist/NotificationServicesPushController/services/push/push-web.js +12 -11
  14. package/dist/NotificationServicesPushController/services/push/push-web.mjs +11 -10
  15. package/dist/NotificationServicesPushController/services/services.js +13 -12
  16. package/dist/NotificationServicesPushController/services/services.mjs +12 -11
  17. package/dist/NotificationServicesPushController/utils/get-notification-message.js +10 -9
  18. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +10 -9
  19. package/dist/NotificationServicesPushController/utils/index.js +10 -9
  20. package/dist/NotificationServicesPushController/utils/index.mjs +10 -9
  21. package/dist/{chunk-MT4VCZEE.js → chunk-2BCJRWFF.js} +6 -6
  22. package/dist/{chunk-CGQRVA4Q.js → chunk-323GXNRE.js} +53 -8
  23. package/dist/chunk-323GXNRE.js.map +1 -0
  24. package/dist/{chunk-GJHW5Z65.js → chunk-4HOEZMSV.js} +4 -4
  25. package/dist/{chunk-5TUHE2FM.js → chunk-6GXEFQ64.js} +11 -11
  26. package/dist/chunk-6GXEFQ64.js.map +1 -0
  27. package/dist/chunk-DINCLRZT.mjs +12 -0
  28. package/dist/chunk-DINCLRZT.mjs.map +1 -0
  29. package/dist/chunk-DT6SLUWJ.js +12 -0
  30. package/dist/chunk-DT6SLUWJ.js.map +1 -0
  31. package/dist/{chunk-EZHMYHBX.mjs → chunk-FN6GVBCU.mjs} +9 -11
  32. package/dist/chunk-FN6GVBCU.mjs.map +1 -0
  33. package/dist/{chunk-72H2V4J5.js → chunk-GDKHOBJT.js} +7 -3
  34. package/dist/chunk-GDKHOBJT.js.map +1 -0
  35. package/dist/{chunk-DNVD3CHQ.js → chunk-H73GATCU.js} +9 -11
  36. package/dist/chunk-H73GATCU.js.map +1 -0
  37. package/dist/{chunk-R373BQEU.mjs → chunk-N4EKQQX7.mjs} +5 -5
  38. package/dist/{chunk-F2X3OS5R.js → chunk-OE2TTTBQ.js} +14 -14
  39. package/dist/{chunk-DSLFFOGF.mjs → chunk-OLYCBAVW.mjs} +48 -3
  40. package/dist/chunk-OLYCBAVW.mjs.map +1 -0
  41. package/dist/{chunk-W7PLAK7T.mjs → chunk-PGXUX4TK.mjs} +9 -9
  42. package/dist/{chunk-ADYRLXWY.mjs → chunk-WGGW6VCR.mjs} +2 -2
  43. package/dist/{chunk-XVIUHFC3.mjs → chunk-X3ZU3HL7.mjs} +4 -4
  44. package/dist/{chunk-XVIUHFC3.mjs.map → chunk-X3ZU3HL7.mjs.map} +1 -1
  45. package/dist/{chunk-A5QFYBTR.mjs → chunk-YHVXD5WW.mjs} +7 -3
  46. package/dist/chunk-YHVXD5WW.mjs.map +1 -0
  47. package/dist/index.js +16 -15
  48. package/dist/index.mjs +15 -14
  49. package/dist/shared/to-raw-notification.js +8 -0
  50. package/dist/shared/to-raw-notification.js.map +1 -0
  51. package/dist/shared/to-raw-notification.mjs +8 -0
  52. package/dist/shared/to-raw-notification.mjs.map +1 -0
  53. package/dist/tsconfig.build.tsbuildinfo +1 -1
  54. package/dist/types/NotificationServicesController/NotificationServicesController.d.ts +14 -5
  55. package/dist/types/NotificationServicesController/NotificationServicesController.d.ts.map +1 -1
  56. package/dist/types/NotificationServicesController/services/onchain-notifications.d.ts.map +1 -1
  57. package/dist/types/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.ts +1 -0
  58. package/dist/types/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.ts.map +1 -1
  59. package/dist/types/NotificationServicesPushController/services/push/push-web.d.ts.map +1 -1
  60. package/dist/types/shared/to-raw-notification.d.ts +11 -0
  61. package/dist/types/shared/to-raw-notification.d.ts.map +1 -0
  62. package/package.json +1 -1
  63. package/dist/chunk-5TUHE2FM.js.map +0 -1
  64. package/dist/chunk-72H2V4J5.js.map +0 -1
  65. package/dist/chunk-A5QFYBTR.mjs.map +0 -1
  66. package/dist/chunk-CGQRVA4Q.js.map +0 -1
  67. package/dist/chunk-DNVD3CHQ.js.map +0 -1
  68. package/dist/chunk-DSLFFOGF.mjs.map +0 -1
  69. package/dist/chunk-EZHMYHBX.mjs.map +0 -1
  70. /package/dist/{chunk-MT4VCZEE.js.map → chunk-2BCJRWFF.js.map} +0 -0
  71. /package/dist/{chunk-GJHW5Z65.js.map → chunk-4HOEZMSV.js.map} +0 -0
  72. /package/dist/{chunk-R373BQEU.mjs.map → chunk-N4EKQQX7.mjs.map} +0 -0
  73. /package/dist/{chunk-F2X3OS5R.js.map → chunk-OE2TTTBQ.js.map} +0 -0
  74. /package/dist/{chunk-W7PLAK7T.mjs.map → chunk-PGXUX4TK.mjs.map} +0 -0
  75. /package/dist/{chunk-ADYRLXWY.mjs.map → chunk-WGGW6VCR.mjs.map} +0 -0
@@ -1,16 +1,19 @@
1
+ import {
2
+ types_exports
3
+ } from "./chunk-B4ECJJ5C.mjs";
1
4
  import {
2
5
  ui_exports
3
6
  } from "./chunk-5JDAO4ZC.mjs";
7
+ import {
8
+ constants_exports
9
+ } from "./chunk-ZHAD55AN.mjs";
4
10
  import {
5
11
  processors_exports
6
12
  } from "./chunk-X42WN3FE.mjs";
7
- import {
8
- types_exports
9
- } from "./chunk-B4ECJJ5C.mjs";
10
13
  import {
11
14
  NotificationServicesController,
12
15
  defaultState
13
- } from "./chunk-DSLFFOGF.mjs";
16
+ } from "./chunk-OLYCBAVW.mjs";
14
17
  import {
15
18
  FEATURE_ANNOUNCEMENT_API
16
19
  } from "./chunk-QFJZBLYQ.mjs";
@@ -18,13 +21,10 @@ import {
18
21
  NOTIFICATION_API_LIST_ENDPOINT,
19
22
  NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT,
20
23
  TRIGGER_API_BATCH_ENDPOINT
21
- } from "./chunk-EZHMYHBX.mjs";
24
+ } from "./chunk-FN6GVBCU.mjs";
22
25
  import {
23
26
  initializeUserStorage
24
27
  } from "./chunk-ILPTPB4U.mjs";
25
- import {
26
- constants_exports
27
- } from "./chunk-ZHAD55AN.mjs";
28
28
  import {
29
29
  USER_STORAGE_VERSION_KEY
30
30
  } from "./chunk-6ZDVTRRT.mjs";
@@ -926,4 +926,4 @@ export {
926
926
  fixtures_exports,
927
927
  NotificationServicesController_exports
928
928
  };
929
- //# sourceMappingURL=chunk-W7PLAK7T.mjs.map
929
+ //# sourceMappingURL=chunk-PGXUX4TK.mjs.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  listenToPushNotificationsClicked,
3
3
  listenToPushNotificationsReceived
4
- } from "./chunk-A5QFYBTR.mjs";
4
+ } from "./chunk-YHVXD5WW.mjs";
5
5
  import {
6
6
  REGISTRATION_TOKENS_ENDPOINT
7
7
  } from "./chunk-IKWNHNJQ.mjs";
@@ -146,4 +146,4 @@ export {
146
146
  updateTriggerPushNotifications,
147
147
  listenToPushNotifications
148
148
  };
149
- //# sourceMappingURL=chunk-ADYRLXWY.mjs.map
149
+ //# sourceMappingURL=chunk-WGGW6VCR.mjs.map
@@ -3,11 +3,11 @@ import {
3
3
  deactivatePushNotifications,
4
4
  listenToPushNotifications,
5
5
  updateTriggerPushNotifications
6
- } from "./chunk-ADYRLXWY.mjs";
6
+ } from "./chunk-WGGW6VCR.mjs";
7
7
  import {
8
8
  createRegToken,
9
9
  deleteRegToken
10
- } from "./chunk-A5QFYBTR.mjs";
10
+ } from "./chunk-YHVXD5WW.mjs";
11
11
  import {
12
12
  __privateAdd,
13
13
  __privateGet,
@@ -77,7 +77,7 @@ var NotificationServicesPushController = class extends BaseController {
77
77
  if (!regToken) {
78
78
  return;
79
79
  }
80
- __privateSet(this, _pushListenerUnsubscribe, await listenToPushNotifications({
80
+ __privateGet(this, _pushListenerUnsubscribe) ?? __privateSet(this, _pushListenerUnsubscribe, await listenToPushNotifications({
81
81
  env: __privateGet(this, _env),
82
82
  listenToPushReceived: async (n) => {
83
83
  this.messagingSystem.publish(
@@ -213,4 +213,4 @@ export {
213
213
  defaultState,
214
214
  NotificationServicesPushController
215
215
  };
216
- //# sourceMappingURL=chunk-XVIUHFC3.mjs.map
216
+ //# sourceMappingURL=chunk-X3ZU3HL7.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"sourcesContent":["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\nexport const defaultState: NotificationServicesPushControllerState = {\n fcmToken: '',\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: { ...defaultState, ...state },\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"],"mappings":";;;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AAE/B,OAAO,SAAS;AAYhB,IAAM,iBAAiB;AAqDhB,IAAM,eAAwD;AAAA,EACnE,UAAU;AACZ;AACA,IAAM,WAAW;AAAA,EACf,UAAU;AAAA,IACR,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AA/EA;AAwHA,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,EAAE,GAAG,cAAc,GAAG,MAAM;AAAA,IACrC,CAAC;AAQH;AAeA,uBAAM;AA7CN,iDAAqD;AAErD;AAEA;AAoBE,uBAAK,MAAO;AACZ,uBAAK,SAAU;AAEf,0BAAK,sDAAL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA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BAAG;AAC/B,QAAM,cAAc,MAAM,KAAK,gBAAgB;AAAA,IAC7C;AAAA,EACF;AACA,MAAI,CAAC,aAAa;AAChB,QAAI;AAAA,MACF;AAAA,IACF;AACA,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"sourcesContent":["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\nexport const defaultState: NotificationServicesPushControllerState = {\n fcmToken: '',\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: { ...defaultState, ...state },\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"],"mappings":";;;;;;;;;;;;;;;;;;AAIA,SAAS,sBAAsB;AAE/B,OAAO,SAAS;AAYhB,IAAM,iBAAiB;AAqDhB,IAAM,eAAwD;AAAA,EACnE,UAAU;AACZ;AACA,IAAM,WAAW;AAAA,EACf,UAAU;AAAA,IACR,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AACF;AA/EA;AAwHA,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,EAAE,GAAG,cAAc,GAAG,MAAM;AAAA,IACrC,CAAC;AAQH;AAeA,uBAAM;AA7CN,iDAAqD;AAErD;AAEA;AAoBE,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,UAAU;AAAA,QACV,KAAK,mBAAK;AAAA,QACV;AAAA,QACA,UAAU,mBAAK,SAAQ;AAAA,MACzB,CAAC;AAED,UAAI,CAAC,UAAU;AACb;AAAA,MACF;AAEA,yBAAK,6BAAL,mBAAK,0BAA6B,MAAM,0BAA0B;AAAA,QA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+B,OAAiB;AACpD,QAAI,CAAC,mBAAK,SAAQ,eAAe;AAC/B;AAAA,IACF;AAEA,UAAM,cAAc,MAAM,sBAAK,sDAAL;AAE1B,QAAI;AACF,YAAM,EAAE,SAAS,IAAI,MAAM,+BAA+B;AAAA,QACxD;AAAA,QACA,UAAU;AAAA,QACV,KAAK,mBAAK;AAAA,QACV;AAAA,QACA;AAAA,QACA,UAAU,mBAAK,SAAQ;AAAA,QACvB,UAAU,KAAK,MAAM;AAAA,MACvB,CAAC;AAGD,UAAI,UAAU;AACZ,aAAK,OAAO,CAAC,UAAU;AACrB,gBAAM,WAAW;AAAA,QACnB,CAAC;AAAA,MACH;AAAA,IACF,SAAS,OAAO;AACd,YAAM,eAAe,qDACnB,KACF;AACA,UAAI,MAAM,YAAY;AACtB,YAAM,IAAI,MAAM,YAAY;AAAA,IAC9B;AAAA,EACF;AACF;AAlNE;AAEA;AAEA;AA0BA;AAAA,6BAAwB,WAAS;AAC/B,OAAK,gBAAgB;AAAA,IACnB;AAAA,IACA,KAAK,wBAAwB,KAAK,IAAI;AAAA,EACxC;AACA,OAAK,gBAAgB;AAAA,IACnB;AAAA,IACA,KAAK,yBAAyB,KAAK,IAAI;AAAA,EACzC;AACA,OAAK,gBAAgB;AAAA,IACnB;AAAA,IACA,KAAK,+BAA+B,KAAK,IAAI;AAAA,EAC/C;AACF;AAEM;AAAA,6BAAwB,iBAAG;AAC/B,QAAM,cAAc,MAAM,KAAK,gBAAgB;AAAA,IAC7C;AAAA,EACF;AACA,MAAI,CAAC,aAAa;AAChB,QAAI;AAAA,MACF;AAAA,IACF;AACA,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AAEA,SAAO;AACT;","names":[]}
@@ -1,6 +1,9 @@
1
1
  import {
2
2
  processors_exports
3
3
  } from "./chunk-X42WN3FE.mjs";
4
+ import {
5
+ toRawOnChainNotification
6
+ } from "./chunk-DINCLRZT.mjs";
4
7
 
5
8
  // src/NotificationServicesPushController/services/push/push-web.ts
6
9
  import { getApp, initializeApp } from "firebase/app";
@@ -55,10 +58,11 @@ async function listenToPushNotificationsReceived(env, handler) {
55
58
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
56
59
  async (payload) => {
57
60
  try {
58
- const notificationData = payload?.data?.data ? JSON.parse(payload?.data?.data) : void 0;
59
- if (!notificationData) {
61
+ const data = payload?.data?.data ? JSON.parse(payload?.data?.data) : void 0;
62
+ if (!data) {
60
63
  return;
61
64
  }
65
+ const notificationData = toRawOnChainNotification(data);
62
66
  const notification = processors_exports.processNotification(notificationData);
63
67
  await handler(notification);
64
68
  } catch (error) {
@@ -89,4 +93,4 @@ export {
89
93
  listenToPushNotificationsReceived,
90
94
  listenToPushNotificationsClicked
91
95
  };
92
- //# sourceMappingURL=chunk-A5QFYBTR.mjs.map
96
+ //# sourceMappingURL=chunk-YHVXD5WW.mjs.map
@@ -0,0 +1 @@
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 { toRawOnChainNotification } from '../../../shared/to-raw-notification';\nimport type { PushNotificationEnv } from '../../types/firebase';\n\ndeclare const self: 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: 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 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 data: Types.UnprocessedOnChainRawNotification | undefined =\n payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawOnChainNotification(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"],"mappings":";;;;;;;;AAIA,SAAS,QAAQ,qBAAqB;AACtC,SAAS,UAAU,mBAAmB;AACtC,SAAS,cAAc,2BAA2B;AAElD,OAAO,SAAS;AAShB,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,MAAM,MAAM,kBAAkB,GAAG;AACvC,SAAO,aAAa,GAAG;AACzB;AAQA,eAAsB,eACpB,KACwB;AACxB,MAAI;AACF,UAAM,YAAY,MAAM,qBAAqB,GAAG;AAChD,UAAM,QAAQ,MAAM,SAAS,WAAW;AAAA,MACtC,2BAA2B,KAAK;AAAA,MAChC,UAAU,IAAI;AAAA,IAChB,CAAC;AACD,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQA,eAAsB,eACpB,KACkB;AAClB,MAAI;AACF,UAAM,YAAY,MAAM,qBAAqB,GAAG;AAChD,UAAM,YAAY,SAAS;AAC3B,WAAO;AAAA,EACT,SAAS,OAAO;AACd,WAAO;AAAA,EACT;AACF;AAQA,eAAsB,kCACpB,KACA,SACA;AACA,QAAM,YAAY,MAAM,qBAAqB,GAAG;AAChD,QAAM,+BAA+B;AAAA,IACnC;AAAA;AAAA,IAEA,OAAO,YAA4B;AACjC,UAAI;AACF,cAAM,OACJ,SAAS,MAAM,OAAO,KAAK,MAAM,SAAS,MAAM,IAAI,IAAI;AAE1D,YAAI,CAAC,MAAM;AACT;AAAA,QACF;AAEA,cAAM,mBAAmB,yBAAyB,IAAI;AACtD,cAAM,eAAe,mBAAW,oBAAoB,gBAAgB;AACpE,cAAM,QAAQ,YAAY;AAAA,MAC5B,SAAS,OAAO;AAEd,YAAI,MAAM,qCAAqC;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,OAAK,iBAAiB,qBAAqB,YAAY;AACvD,QAAM,cAAc,MAClB,KAAK,oBAAoB,qBAAqB,YAAY;AAC5D,SAAO;AACT;","names":[]}
package/dist/index.js CHANGED
@@ -1,22 +1,21 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMT4VCZEEjs = require('./chunk-MT4VCZEE.js');
3
+ var _chunk2BCJRWFFjs = require('./chunk-2BCJRWFF.js');
4
+ require('./chunk-7LWR54U7.js');
4
5
  require('./chunk-ENRKCWJ6.js');
5
6
  require('./chunk-BUT7X5F2.js');
6
7
  require('./chunk-EJ52BDLB.js');
7
- require('./chunk-7LWR54U7.js');
8
8
  require('./chunk-GETQWOTI.js');
9
- require('./chunk-5TUHE2FM.js');
10
- require('./chunk-GJHW5Z65.js');
11
- require('./chunk-72H2V4J5.js');
9
+ require('./chunk-6GXEFQ64.js');
10
+ require('./chunk-4HOEZMSV.js');
11
+ require('./chunk-GDKHOBJT.js');
12
12
  require('./chunk-B25TJ7KS.js');
13
13
 
14
14
 
15
- var _chunkF2X3OS5Rjs = require('./chunk-F2X3OS5R.js');
16
- require('./chunk-IG3KWCQU.js');
17
- require('./chunk-QOG3RCXM.js');
18
- require('./chunk-KWTSMLND.js');
15
+ var _chunkOE2TTTBQjs = require('./chunk-OE2TTTBQ.js');
19
16
  require('./chunk-232HZSEV.js');
17
+ require('./chunk-XZEVRYUE.js');
18
+ require('./chunk-3ZS2HAEG.js');
20
19
  require('./chunk-ZV3DFBO4.js');
21
20
  require('./chunk-DMH4NSLF.js');
22
21
  require('./chunk-IPI7BAW3.js');
@@ -25,21 +24,23 @@ require('./chunk-WRYFIWNK.js');
25
24
  require('./chunk-V5HMYDWE.js');
26
25
  require('./chunk-ZBNBZN5H.js');
27
26
  require('./chunk-PROWNV4M.js');
28
- require('./chunk-XZEVRYUE.js');
29
- require('./chunk-3ZS2HAEG.js');
30
- require('./chunk-CGQRVA4Q.js');
27
+ require('./chunk-IG3KWCQU.js');
28
+ require('./chunk-QOG3RCXM.js');
29
+ require('./chunk-QY4UST5V.js');
30
+ require('./chunk-KWTSMLND.js');
31
+ require('./chunk-323GXNRE.js');
31
32
  require('./chunk-5FUMSWDD.js');
32
33
  require('./chunk-LYEXYTOI.js');
33
34
  require('./chunk-HZEB53A6.js');
34
35
  require('./chunk-52CALMRA.js');
35
- require('./chunk-DNVD3CHQ.js');
36
+ require('./chunk-H73GATCU.js');
36
37
  require('./chunk-NOYP2T77.js');
37
- require('./chunk-QY4UST5V.js');
38
38
  require('./chunk-V6P5JEPT.js');
39
+ require('./chunk-DT6SLUWJ.js');
39
40
  require('./chunk-TLX5QQK5.js');
40
41
  require('./chunk-IGY2S5BC.js');
41
42
 
42
43
 
43
44
 
44
- exports.NotificationServicesController = _chunkF2X3OS5Rjs.NotificationServicesController_exports; exports.NotificationsServicesPushController = _chunkMT4VCZEEjs.NotificationServicesPushController_exports;
45
+ exports.NotificationServicesController = _chunkOE2TTTBQjs.NotificationServicesController_exports; exports.NotificationsServicesPushController = _chunk2BCJRWFFjs.NotificationServicesPushController_exports;
45
46
  //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1,22 +1,21 @@
1
1
  import {
2
2
  NotificationServicesPushController_exports
3
- } from "./chunk-R373BQEU.mjs";
3
+ } from "./chunk-N4EKQQX7.mjs";
4
+ import "./chunk-IOMDG67D.mjs";
4
5
  import "./chunk-DCADU5QI.mjs";
5
6
  import "./chunk-6GUOLD7O.mjs";
6
7
  import "./chunk-ODI2BTKS.mjs";
7
- import "./chunk-IOMDG67D.mjs";
8
8
  import "./chunk-RAUV5UV4.mjs";
9
- import "./chunk-XVIUHFC3.mjs";
10
- import "./chunk-ADYRLXWY.mjs";
11
- import "./chunk-A5QFYBTR.mjs";
9
+ import "./chunk-X3ZU3HL7.mjs";
10
+ import "./chunk-WGGW6VCR.mjs";
11
+ import "./chunk-YHVXD5WW.mjs";
12
12
  import "./chunk-IKWNHNJQ.mjs";
13
13
  import {
14
14
  NotificationServicesController_exports
15
- } from "./chunk-W7PLAK7T.mjs";
16
- import "./chunk-5JDAO4ZC.mjs";
17
- import "./chunk-YZYQYIKS.mjs";
18
- import "./chunk-X42WN3FE.mjs";
15
+ } from "./chunk-PGXUX4TK.mjs";
19
16
  import "./chunk-B4ECJJ5C.mjs";
17
+ import "./chunk-U74Q3BRP.mjs";
18
+ import "./chunk-G52DNXFH.mjs";
20
19
  import "./chunk-7RM3YNTD.mjs";
21
20
  import "./chunk-PNCS6GEX.mjs";
22
21
  import "./chunk-4QXAPVW3.mjs";
@@ -25,17 +24,19 @@ import "./chunk-IDO4JFV5.mjs";
25
24
  import "./chunk-A2RPVX47.mjs";
26
25
  import "./chunk-4BTNTREI.mjs";
27
26
  import "./chunk-QB5IFRLA.mjs";
28
- import "./chunk-U74Q3BRP.mjs";
29
- import "./chunk-G52DNXFH.mjs";
30
- import "./chunk-DSLFFOGF.mjs";
27
+ import "./chunk-5JDAO4ZC.mjs";
28
+ import "./chunk-YZYQYIKS.mjs";
29
+ import "./chunk-ZHAD55AN.mjs";
30
+ import "./chunk-X42WN3FE.mjs";
31
+ import "./chunk-OLYCBAVW.mjs";
31
32
  import "./chunk-KCWTVLMK.mjs";
32
33
  import "./chunk-BONB66A2.mjs";
33
34
  import "./chunk-QFJZBLYQ.mjs";
34
35
  import "./chunk-D42BBXBM.mjs";
35
- import "./chunk-EZHMYHBX.mjs";
36
+ import "./chunk-FN6GVBCU.mjs";
36
37
  import "./chunk-ILPTPB4U.mjs";
37
- import "./chunk-ZHAD55AN.mjs";
38
38
  import "./chunk-J4D2NH6Y.mjs";
39
+ import "./chunk-DINCLRZT.mjs";
39
40
  import "./chunk-6ZDVTRRT.mjs";
40
41
  import "./chunk-U5UIDVOO.mjs";
41
42
  export {
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkDT6SLUWJjs = require('../chunk-DT6SLUWJ.js');
4
+ require('../chunk-IGY2S5BC.js');
5
+
6
+
7
+ exports.toRawOnChainNotification = _chunkDT6SLUWJjs.toRawOnChainNotification;
8
+ //# sourceMappingURL=to-raw-notification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import {
2
+ toRawOnChainNotification
3
+ } from "../chunk-DINCLRZT.mjs";
4
+ import "../chunk-U5UIDVOO.mjs";
5
+ export {
6
+ toRawOnChainNotification
7
+ };
8
+ //# sourceMappingURL=to-raw-notification.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}