@metamask-previews/notification-services-controller 10.0.0-preview-4e3fd4c0 → 12.0.0-preview-08a4995

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 (160) hide show
  1. package/CHANGELOG.md +39 -1
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +78 -188
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts +10 -16
  5. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts +10 -16
  7. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs +79 -189
  9. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  10. package/dist/NotificationServicesController/constants/index.cjs +0 -1
  11. package/dist/NotificationServicesController/constants/index.cjs.map +1 -1
  12. package/dist/NotificationServicesController/constants/index.d.cts +0 -1
  13. package/dist/NotificationServicesController/constants/index.d.cts.map +1 -1
  14. package/dist/NotificationServicesController/constants/index.d.mts +0 -1
  15. package/dist/NotificationServicesController/constants/index.d.mts.map +1 -1
  16. package/dist/NotificationServicesController/constants/index.mjs +0 -1
  17. package/dist/NotificationServicesController/constants/index.mjs.map +1 -1
  18. package/dist/NotificationServicesController/constants/notification-schema.cjs +1 -0
  19. package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
  20. package/dist/NotificationServicesController/constants/notification-schema.d.cts +1 -0
  21. package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
  22. package/dist/NotificationServicesController/constants/notification-schema.d.mts +1 -0
  23. package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
  24. package/dist/NotificationServicesController/constants/notification-schema.mjs +1 -0
  25. package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
  26. package/dist/NotificationServicesController/mocks/index.cjs +0 -2
  27. package/dist/NotificationServicesController/mocks/index.cjs.map +1 -1
  28. package/dist/NotificationServicesController/mocks/index.d.cts +0 -2
  29. package/dist/NotificationServicesController/mocks/index.d.cts.map +1 -1
  30. package/dist/NotificationServicesController/mocks/index.d.mts +0 -2
  31. package/dist/NotificationServicesController/mocks/index.d.mts.map +1 -1
  32. package/dist/NotificationServicesController/mocks/index.mjs +0 -2
  33. package/dist/NotificationServicesController/mocks/index.mjs.map +1 -1
  34. package/dist/NotificationServicesController/mocks/mockResponses.cjs +9 -9
  35. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  36. package/dist/NotificationServicesController/mocks/mockResponses.d.cts +7 -4
  37. package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
  38. package/dist/NotificationServicesController/mocks/mockResponses.d.mts +7 -4
  39. package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
  40. package/dist/NotificationServicesController/mocks/mockResponses.mjs +7 -7
  41. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  42. package/dist/NotificationServicesController/processors/process-notifications.cjs +4 -1
  43. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  44. package/dist/NotificationServicesController/processors/process-notifications.d.cts +623 -0
  45. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  46. package/dist/NotificationServicesController/processors/process-notifications.d.mts +623 -0
  47. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  48. package/dist/NotificationServicesController/processors/process-notifications.mjs +2 -0
  49. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  50. package/dist/NotificationServicesController/services/notification-config-cache.cjs +61 -0
  51. package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -0
  52. package/dist/NotificationServicesController/services/notification-config-cache.d.cts +15 -0
  53. package/dist/NotificationServicesController/services/notification-config-cache.d.cts.map +1 -0
  54. package/dist/NotificationServicesController/services/notification-config-cache.d.mts +15 -0
  55. package/dist/NotificationServicesController/services/notification-config-cache.d.mts.map +1 -0
  56. package/dist/NotificationServicesController/services/notification-config-cache.mjs +57 -0
  57. package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -0
  58. package/dist/NotificationServicesController/services/onchain-notifications.cjs +67 -140
  59. package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
  60. package/dist/NotificationServicesController/services/onchain-notifications.d.cts +25 -31
  61. package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
  62. package/dist/NotificationServicesController/services/onchain-notifications.d.mts +25 -31
  63. package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
  64. package/dist/NotificationServicesController/services/onchain-notifications.mjs +65 -137
  65. package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +1 -1
  66. package/dist/NotificationServicesController/types/index.cjs.map +1 -1
  67. package/dist/NotificationServicesController/types/index.d.cts +0 -1
  68. package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
  69. package/dist/NotificationServicesController/types/index.d.mts +0 -1
  70. package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
  71. package/dist/NotificationServicesController/types/index.mjs.map +1 -1
  72. package/dist/NotificationServicesController/ui/constants.cjs +6 -0
  73. package/dist/NotificationServicesController/ui/constants.cjs.map +1 -1
  74. package/dist/NotificationServicesController/ui/constants.d.cts +6 -0
  75. package/dist/NotificationServicesController/ui/constants.d.cts.map +1 -1
  76. package/dist/NotificationServicesController/ui/constants.d.mts +6 -0
  77. package/dist/NotificationServicesController/ui/constants.d.mts.map +1 -1
  78. package/dist/NotificationServicesController/ui/constants.mjs +6 -0
  79. package/dist/NotificationServicesController/ui/constants.mjs.map +1 -1
  80. package/dist/NotificationServicesController/utils/utils.cjs +1 -350
  81. package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
  82. package/dist/NotificationServicesController/utils/utils.d.cts +0 -141
  83. package/dist/NotificationServicesController/utils/utils.d.cts.map +1 -1
  84. package/dist/NotificationServicesController/utils/utils.d.mts +0 -141
  85. package/dist/NotificationServicesController/utils/utils.d.mts.map +1 -1
  86. package/dist/NotificationServicesController/utils/utils.mjs +0 -337
  87. package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
  88. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +22 -15
  89. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  90. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +6 -5
  91. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  92. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +6 -5
  93. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  94. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +23 -16
  95. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  96. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +1 -16
  97. package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
  98. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts +0 -7
  99. package/dist/NotificationServicesPushController/mocks/mockResponse.d.cts.map +1 -1
  100. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts +0 -7
  101. package/dist/NotificationServicesPushController/mocks/mockResponse.d.mts.map +1 -1
  102. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +0 -14
  103. package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
  104. package/dist/NotificationServicesPushController/services/endpoints.cjs +1 -1
  105. package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
  106. package/dist/NotificationServicesPushController/services/endpoints.d.cts +1 -1
  107. package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
  108. package/dist/NotificationServicesPushController/services/endpoints.d.mts +1 -1
  109. package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
  110. package/dist/NotificationServicesPushController/services/endpoints.mjs +1 -1
  111. package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
  112. package/dist/NotificationServicesPushController/services/services.cjs +18 -41
  113. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  114. package/dist/NotificationServicesPushController/services/services.d.cts +19 -33
  115. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  116. package/dist/NotificationServicesPushController/services/services.d.mts +19 -33
  117. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  118. package/dist/NotificationServicesPushController/services/services.mjs +17 -39
  119. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  120. package/package.json +3 -3
  121. package/dist/NotificationServicesController/constants/constants.cjs +0 -7
  122. package/dist/NotificationServicesController/constants/constants.cjs.map +0 -1
  123. package/dist/NotificationServicesController/constants/constants.d.cts +0 -3
  124. package/dist/NotificationServicesController/constants/constants.d.cts.map +0 -1
  125. package/dist/NotificationServicesController/constants/constants.d.mts +0 -3
  126. package/dist/NotificationServicesController/constants/constants.d.mts.map +0 -1
  127. package/dist/NotificationServicesController/constants/constants.mjs +0 -4
  128. package/dist/NotificationServicesController/constants/constants.mjs.map +0 -1
  129. package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs +0 -22
  130. package/dist/NotificationServicesController/mocks/mock-notification-trigger.cjs.map +0 -1
  131. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts +0 -9
  132. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.cts.map +0 -1
  133. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts +0 -9
  134. package/dist/NotificationServicesController/mocks/mock-notification-trigger.d.mts.map +0 -1
  135. package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs +0 -18
  136. package/dist/NotificationServicesController/mocks/mock-notification-trigger.mjs.map +0 -1
  137. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs +0 -82
  138. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.cjs.map +0 -1
  139. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts +0 -35
  140. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.cts.map +0 -1
  141. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts +0 -35
  142. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.d.mts.map +0 -1
  143. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs +0 -76
  144. package/dist/NotificationServicesController/mocks/mock-notification-user-storage.mjs.map +0 -1
  145. package/dist/NotificationServicesController/types/user-storage/index.cjs +0 -3
  146. package/dist/NotificationServicesController/types/user-storage/index.cjs.map +0 -1
  147. package/dist/NotificationServicesController/types/user-storage/index.d.cts +0 -2
  148. package/dist/NotificationServicesController/types/user-storage/index.d.cts.map +0 -1
  149. package/dist/NotificationServicesController/types/user-storage/index.d.mts +0 -2
  150. package/dist/NotificationServicesController/types/user-storage/index.d.mts.map +0 -1
  151. package/dist/NotificationServicesController/types/user-storage/index.mjs +0 -2
  152. package/dist/NotificationServicesController/types/user-storage/index.mjs.map +0 -1
  153. package/dist/NotificationServicesController/types/user-storage/user-storage.cjs +0 -3
  154. package/dist/NotificationServicesController/types/user-storage/user-storage.cjs.map +0 -1
  155. package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts +0 -26
  156. package/dist/NotificationServicesController/types/user-storage/user-storage.d.cts.map +0 -1
  157. package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts +0 -26
  158. package/dist/NotificationServicesController/types/user-storage/user-storage.d.mts.map +0 -1
  159. package/dist/NotificationServicesController/types/user-storage/user-storage.mjs +0 -2
  160. package/dist/NotificationServicesController/types/user-storage/user-storage.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,+DAA2D;AAE3D,wDAA2B;AAE3B,sDAI6B;AAK7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAyE/C,QAAA,YAAY,G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QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;QAC9B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC;YAC5B,KAAK,CAAC,QAAQ,GAAG,EAAE,CAAC;YACpB,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC7B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;YAC3B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;kBApGkB,kCAAkC","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\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 {\n activatePushNotifications,\n deactivatePushNotifications,\n updateTriggerPushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\nimport type { Types } from '../NotificationServicesController';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `${typeof controllerName}:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 };\nexport type NotificationServicesPushControllerSubscribeToNotificationsAction = {\n type: `${typeof controllerName}:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\n};\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction\n | NotificationServicesPushControllerSubscribeToNotificationsAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type AllowedEvents = never;\n\nexport type NotificationServicesPushControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n persist: true,\n anonymous: true,\n },\n fcmToken: {\n persist: true,\n anonymous: true,\n },\n isUpdatingFCMToken: {\n persist: false,\n anonymous: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\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 */\nexport default class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\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 ?? defaultPushEnv;\n this.#config = config;\n\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\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 this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n this.subscribeToPushNotifications.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\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 #updatePushState(command: StateCommand) {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n state.isPushEnabled = false;\n state.fcmToken = '';\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n public async subscribeToPushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\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 public async enablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n }).catch(() => null);\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\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 public async updateTriggerPushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const { fcmToken } = await updateTriggerPushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n deleteRegToken: this.#config.pushService.deleteRegToken,\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"NotificationServicesPushController.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,+DAA2D;AAE3D,wDAA2B;AAE3B,sDAG6B;AAK7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAyE/C,QAAA,YAAY,GAA4C;IACnE,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,EAAE;IACZ,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AACF,MAAM,QAAQ,GAA2D;IACvE,aAAa,EAAE;QACb,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,IAAI;KAChB;CACF,CAAC;AAEF,MAAM,cAAc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C,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC7B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;YAC3B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;kBArGkB,kCAAkC","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\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 {\n activatePushNotifications,\n deactivatePushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\nimport type { Types } from '../NotificationServicesController';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `${typeof controllerName}:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 };\nexport type NotificationServicesPushControllerSubscribeToNotificationsAction = {\n type: `${typeof controllerName}:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\n};\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction\n | NotificationServicesPushControllerSubscribeToNotificationsAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type AllowedEvents = never;\n\nexport type NotificationServicesPushControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n persist: true,\n anonymous: true,\n },\n fcmToken: {\n persist: true,\n anonymous: true,\n },\n isUpdatingFCMToken: {\n persist: false,\n anonymous: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\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 */\nexport default class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\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 ?? defaultPushEnv;\n this.#config = config;\n\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\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 this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n this.subscribeToPushNotifications.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\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 #updatePushState(command: StateCommand) {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n // Note we do not want to clear the old FCM token\n // We can send it as an old token to our backend to cleanup next time turned on\n state.isPushEnabled = false;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n public async subscribeToPushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\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 addresses - An array of addresses to enable push notifications for.\n */\n public async enablePushNotifications(addresses: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n });\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param addresses - An array of addresses that should trigger push notifications.\n * @deprecated - this is not used anymore and will most likely be removed\n */\n public async updateTriggerPushNotifications(addresses: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
@@ -89,9 +89,9 @@ export default class NotificationServicesPushController extends BaseController<t
89
89
  * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.
90
90
  * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.
91
91
  *
92
- * @param UUIDs - An array of UUIDs to enable push notifications for.
92
+ * @param addresses - An array of addresses to enable push notifications for.
93
93
  */
94
- enablePushNotifications(UUIDs: string[]): Promise<void>;
94
+ enablePushNotifications(addresses: string[]): Promise<void>;
95
95
  /**
96
96
  * Disables push notifications for the application.
97
97
  * This removes the registration token on this device, and ensures we unsubscribe from any listeners
@@ -99,12 +99,13 @@ export default class NotificationServicesPushController extends BaseController<t
99
99
  disablePushNotifications(): Promise<void>;
100
100
  /**
101
101
  * Updates the triggers for push notifications.
102
- * This method is responsible for updating the server with the new set of UUIDs that should trigger push notifications.
102
+ * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.
103
103
  * It uses the current FCM token and a BearerToken for authentication.
104
104
  *
105
- * @param UUIDs - An array of UUIDs that should trigger push notifications.
105
+ * @param addresses - An array of addresses that should trigger push notifications.
106
+ * @deprecated - this is not used anymore and will most likely be removed
106
107
  */
107
- updateTriggerPushNotifications(UUIDs: string[]): Promise<void>;
108
+ updateTriggerPushNotifications(addresses: string[]): Promise<void>;
108
109
  }
109
110
  export {};
110
111
  //# sourceMappingURL=NotificationServicesPushController.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController.d.cts","sourceRoot":"","sources":["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,EACvC,2CAA2C,CAC5C;;gBAOa,EACV,SAAS,EACT,KAAK,EACL,GAAG,EACH,MAAM,GACP,EAAE;QACD,SAAS,EAAE,2CAA2C,CAAC;QACvD,KAAK,EAAE,uCAAuC,CAAC;QAC/C,sDAAsD;QACtD,GAAG,CAAC,EAAE,mBAAmB,CAAC;QAC1B,MAAM,EAAE,gBAAgB,CAAC;KAC1B;IAgFY,4BAA4B;IAoBzC;;;;;;;;;OASG;IACU,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE;IA+CpD;;;OAGG;IACU,wBAAwB;IAmCrC;;;;;;OAMG;IACU,8BAA8B,CAAC,KAAK,EAAE,MAAM,EAAE;CAqC5D"}
1
+ {"version":3,"file":"NotificationServicesPushController.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAOlF,OAAO,KAAK,EAAE,mBAAmB,EAAE,0BAAgB;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,2CAAuC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,oDAA0C;AAE/D,QAAA,MAAM,cAAc,uCAAuC,CAAC;AAE5D,MAAM,MAAM,uCAAuC,GAAG;IACpD,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,gDAAgD,GAC1D,wBAAwB,CACtB,OAAO,cAAc,EACrB,uCAAuC,CACxC,CAAC;AAEJ,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,GAAG,OAAO,cAAc,0BAA0B,CAAC;IACzD,OAAO,EAAE,kCAAkC,CAAC,yBAAyB,CAAC,C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AAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,uCAI1B,CAAC;AA2BF,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IAEjC;;;;;OAKG;IACH,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAOF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,kCAAmC,SAAQ,cAAc,CAC5E,OAAO,cAAc,EACrB,uCAAuC,EACvC,2CAA2C,CAC5C;;gBAOa,EACV,SAAS,EACT,KAAK,EACL,GAAG,EACH,MAAM,GACP,EAAE;QACD,SAAS,EAAE,2CAA2C,CAAC;QACvD,KAAK,EAAE,uCAAuC,CAAC;QAC/C,sDAAsD;QACtD,GAAG,CAAC,EAAE,mBAAmB,CAAC;QAC1B,MAAM,EAAE,gBAAgB,CAAC;KAC1B;IAiFY,4BAA4B;IAoBzC;;;;;;;;;OASG;IACU,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE;IAkDxD;;;OAGG;IACU,wBAAwB;IAmCrC;;;;;;;OAOG;IACU,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE;CAuChE"}
@@ -89,9 +89,9 @@ export default class NotificationServicesPushController extends BaseController<t
89
89
  * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.
90
90
  * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.
91
91
  *
92
- * @param UUIDs - An array of UUIDs to enable push notifications for.
92
+ * @param addresses - An array of addresses to enable push notifications for.
93
93
  */
94
- enablePushNotifications(UUIDs: string[]): Promise<void>;
94
+ enablePushNotifications(addresses: string[]): Promise<void>;
95
95
  /**
96
96
  * Disables push notifications for the application.
97
97
  * This removes the registration token on this device, and ensures we unsubscribe from any listeners
@@ -99,12 +99,13 @@ export default class NotificationServicesPushController extends BaseController<t
99
99
  disablePushNotifications(): Promise<void>;
100
100
  /**
101
101
  * Updates the triggers for push notifications.
102
- * This method is responsible for updating the server with the new set of UUIDs that should trigger push notifications.
102
+ * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.
103
103
  * It uses the current FCM token and a BearerToken for authentication.
104
104
  *
105
- * @param UUIDs - An array of UUIDs that should trigger push notifications.
105
+ * @param addresses - An array of addresses that should trigger push notifications.
106
+ * @deprecated - this is not used anymore and will most likely be removed
106
107
  */
107
- updateTriggerPushNotifications(UUIDs: string[]): Promise<void>;
108
+ updateTriggerPushNotifications(addresses: string[]): Promise<void>;
108
109
  }
109
110
  export {};
110
111
  //# sourceMappingURL=NotificationServicesPushController.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAQlF,OAAO,KAAK,EAAE,mBAAmB,EAAE,0BAAgB;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,2CAAuC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,oDAA0C;AAE/D,QAAA,MAAM,cAAc,uCAAuC,CAAC;AAE5D,MAAM,MAAM,uCAAuC,GAAG;IACpD,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,gDAAgD,GAC1D,wBAAwB,CACtB,OAAO,cAAc,EACrB,uCAAuC,CACxC,CAAC;AAEJ,MAAM,MAAM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KAAK,CAAC;AAElC,MAAM,MAAM,2CAA2C,GAAG,mBAAmB,CAC3E,OAAO,cAAc,EACrB,OAAO,GAAG,cAAc,EACxB,MAAM,GAAG,aAAa,EACtB,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,uCAI1B,CAAC;AA2BF,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,MAAM,CAAC;IAEzB;;;OAGG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAE/B;;OAEG;IACH,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IAEjC;;;;;OAKG;IACH,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAOF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,kCAAmC,SAAQ,cAAc,CAC5E,OAAO,cAAc,EACrB,uCAAuC,EACvC,2CAA2C,CAC5C;;gBAOa,EACV,SAAS,EACT,KAAK,EACL,GAAG,EACH,MAAM,GACP,EAAE;QACD,SAAS,EAAE,2CAA2C,CAAC;QACvD,KAAK,EAAE,uCAAuC,CAAC;QAC/C,sDAAsD;QACtD,GAAG,CAAC,EAAE,mBAAmB,CAAC;QAC1B,MAAM,EAAE,gBAAgB,CAAC;KAC1B;IAgFY,4BAA4B;IAoBzC;;;;;;;;;OASG;IACU,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE;IA+CpD;;;OAGG;IACU,wBAAwB;IAmCrC;;;;;;OAMG;IACU,8BAA8B,CAAC,KAAK,EAAE,MAAM,EAAE;CAqC5D"}
1
+ {"version":3,"file":"NotificationServicesPushController.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EA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C/C,sDAAsD;QACtD,GAAG,CAAC,EAAE,mBAAmB,CAAC;QAC1B,MAAM,EAAE,gBAAgB,CAAC;KAC1B;IAiFY,4BAA4B;IAoBzC;;;;;;;;;OASG;IACU,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE;IAkDxD;;;OAGG;IACU,wBAAwB;IAmCrC;;;;;;;OAOG;IACU,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE;CAuChE"}
@@ -19,7 +19,7 @@ function $importDefault(module) {
19
19
  import { BaseController } from "@metamask/base-controller";
20
20
  import $log from "loglevel";
21
21
  const log = $importDefault($log);
22
- import { activatePushNotifications, deactivatePushNotifications, updateTriggerPushNotifications } from "./services/services.mjs";
22
+ import { activatePushNotifications, deactivatePushNotifications } from "./services/services.mjs";
23
23
  const controllerName = 'NotificationServicesPushController';
24
24
  export const defaultState = {
25
25
  isPushEnabled: true,
@@ -97,9 +97,9 @@ class NotificationServicesPushController extends BaseController {
97
97
  * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.
98
98
  * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.
99
99
  *
100
- * @param UUIDs - An array of UUIDs to enable push notifications for.
100
+ * @param addresses - An array of addresses to enable push notifications for.
101
101
  */
102
- async enablePushNotifications(UUIDs) {
102
+ async enablePushNotifications(addresses) {
103
103
  if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushFeatureEnabled) {
104
104
  return;
105
105
  }
@@ -114,12 +114,15 @@ class NotificationServicesPushController extends BaseController {
114
114
  // Activate Push Notifications
115
115
  const fcmToken = await activatePushNotifications({
116
116
  bearerToken,
117
- triggers: UUIDs,
117
+ addresses,
118
118
  env: __classPrivateFieldGet(this, _NotificationServicesPushController_env, "f"),
119
119
  createRegToken: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.createRegToken,
120
- platform: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").platform,
121
- locale: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").getLocale?.() ?? 'en',
122
- }).catch(() => null);
120
+ regToken: {
121
+ platform: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").platform,
122
+ locale: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").getLocale?.() ?? 'en',
123
+ oldToken: this.state.fcmToken,
124
+ },
125
+ });
123
126
  if (fcmToken) {
124
127
  __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_updatePushState).call(this, { type: 'enable', fcmToken });
125
128
  }
@@ -175,12 +178,13 @@ class NotificationServicesPushController extends BaseController {
175
178
  }
176
179
  /**
177
180
  * Updates the triggers for push notifications.
178
- * This method is responsible for updating the server with the new set of UUIDs that should trigger push notifications.
181
+ * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.
179
182
  * It uses the current FCM token and a BearerToken for authentication.
180
183
  *
181
- * @param UUIDs - An array of UUIDs that should trigger push notifications.
184
+ * @param addresses - An array of addresses that should trigger push notifications.
185
+ * @deprecated - this is not used anymore and will most likely be removed
182
186
  */
183
- async updateTriggerPushNotifications(UUIDs) {
187
+ async updateTriggerPushNotifications(addresses) {
184
188
  if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushFeatureEnabled) {
185
189
  return;
186
190
  }
@@ -189,14 +193,16 @@ class NotificationServicesPushController extends BaseController {
189
193
  });
190
194
  try {
191
195
  const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_getAndAssertBearerToken).call(this);
192
- const { fcmToken } = await updateTriggerPushNotifications({
196
+ const fcmToken = await activatePushNotifications({
193
197
  bearerToken,
194
- triggers: UUIDs,
198
+ addresses,
195
199
  env: __classPrivateFieldGet(this, _NotificationServicesPushController_env, "f"),
196
200
  createRegToken: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.createRegToken,
197
- deleteRegToken: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.deleteRegToken,
198
- platform: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").platform,
199
- locale: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").getLocale?.() ?? 'en',
201
+ regToken: {
202
+ platform: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").platform,
203
+ locale: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").getLocale?.() ?? 'en',
204
+ oldToken: this.state.fcmToken,
205
+ },
200
206
  });
201
207
  // update the state with the new FCM token
202
208
  if (fcmToken) {
@@ -241,8 +247,9 @@ _NotificationServicesPushController_pushListenerUnsubscribe = new WeakMap(), _No
241
247
  }
242
248
  if (command.type === 'disable') {
243
249
  this.update((state) => {
250
+ // Note we do not want to clear the old FCM token
251
+ // We can send it as an old token to our backend to cleanup next time turned on
244
252
  state.isPushEnabled = false;
245
- state.fcmToken = '';
246
253
  state.isUpdatingFCMToken = false;
247
254
  });
248
255
  }
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,8BAA8B,EAC/B,gCAA4B;AAK7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAyE5D,MAAM,CAAC,MAAM,YAAY,GAA4C;IACnE,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,EAAE;IACZ,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AACF,MAAM,QAAQ,GAA2D;IACvE,aAAa,EAAE;QACb,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,IAAI;KAChB;CACF,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AC,CAAC;KACJ;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;QAC7B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;YAC3B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;eApGkB,kCAAkC","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\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 {\n activatePushNotifications,\n deactivatePushNotifications,\n updateTriggerPushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\nimport type { Types } from '../NotificationServicesController';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `${typeof controllerName}:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 };\nexport type NotificationServicesPushControllerSubscribeToNotificationsAction = {\n type: `${typeof controllerName}:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\n};\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction\n | NotificationServicesPushControllerSubscribeToNotificationsAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type AllowedEvents = never;\n\nexport type NotificationServicesPushControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n persist: true,\n anonymous: true,\n },\n fcmToken: {\n persist: true,\n anonymous: true,\n },\n isUpdatingFCMToken: {\n persist: false,\n anonymous: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\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 */\nexport default class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\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 ?? defaultPushEnv;\n this.#config = config;\n\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\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 this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n this.subscribeToPushNotifications.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\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 #updatePushState(command: StateCommand) {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n state.isPushEnabled = false;\n state.fcmToken = '';\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n public async subscribeToPushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\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 public async enablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n }).catch(() => null);\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\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 public async updateTriggerPushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const { fcmToken } = await updateTriggerPushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n deleteRegToken: this.#config.pushService.deleteRegToken,\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"NotificationServicesPushController.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC5B,gCAA4B;AAK7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAyE5D,MAAM,CAAC,MAAM,YAAY,GAA4C;IACnE,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,EAAE;IACZ,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AACF,MAAM,QAAQ,GAA2D;IACvE,aAAa,EAAE;QACb,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,kBAAkB,EAAE;QAClB,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,IAAI;KAChB;CACF,CAAC;AAEF,MAAM,cAAc,GAAwB;IAC1C,MAAM,EAAE,EAAE;IACV,UAAU,EAAE,EAAE;IACd,aAAa,EAAE,EAAE;IACjB,SAAS,EAAE,EAAE;IACb,iBAAiB,EAAE,EAAE;IACrB,KAAK,EAAE,EAAE;IACT,aAAa,EAAE,EAAE;IACjB,QAAQ,EAAE,EAAE;CACb,CAAC;AAiCF;;;;;;GAMG;AACH,MAAqB,kCAAmC,SAAQ,cAI/D;IAOC,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,CAAC;eArGkB,kCAAkC","sourcesContent":["import type {\n RestrictedMessenger,\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\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 {\n activatePushNotifications,\n deactivatePushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\nimport type { Types } from '../NotificationServicesController';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `${typeof controllerName}:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 };\nexport type NotificationServicesPushControllerSubscribeToNotificationsAction = {\n type: `${typeof controllerName}:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\n};\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction\n | NotificationServicesPushControllerSubscribeToNotificationsAction;\n\nexport type AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerToken;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type AllowedEvents = never;\n\nexport type NotificationServicesPushControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n persist: true,\n anonymous: true,\n },\n fcmToken: {\n persist: true,\n anonymous: true,\n },\n isUpdatingFCMToken: {\n persist: false,\n anonymous: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\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 */\nexport default class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\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 ?? defaultPushEnv;\n this.#config = config;\n\n this.#registerMessageHandlers();\n this.#clearLoadingStates();\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 this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n this.subscribeToPushNotifications.bind(this),\n );\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\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 #updatePushState(command: StateCommand) {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n // Note we do not want to clear the old FCM token\n // We can send it as an old token to our backend to cleanup next time turned on\n state.isPushEnabled = false;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n public async subscribeToPushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\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 addresses - An array of addresses to enable push notifications for.\n */\n public async enablePushNotifications(addresses: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n });\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param addresses - An array of addresses that should trigger push notifications.\n * @deprecated - this is not used anymore and will most likely be removed\n */\n public async updateTriggerPushNotifications(addresses: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n oldToken: this.state.fcmToken,\n },\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\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 } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
@@ -1,23 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getMockDeleteFCMRegistrationTokenResponse = exports.getMockCreateFCMRegistrationTokenResponse = exports.MOCK_FCM_RESPONSE = exports.getMockUpdatePushNotificationLinksResponse = exports.getMockRetrievePushNotificationLinksResponse = exports.MOCK_LINKS_RESPONSE = exports.MOCK_REG_TOKEN = void 0;
3
+ exports.getMockDeleteFCMRegistrationTokenResponse = exports.getMockCreateFCMRegistrationTokenResponse = exports.MOCK_FCM_RESPONSE = exports.getMockUpdatePushNotificationLinksResponse = exports.MOCK_REG_TOKEN = void 0;
4
4
  const endpoints_1 = require("../services/endpoints.cjs");
5
5
  exports.MOCK_REG_TOKEN = 'REG_TOKEN';
6
- exports.MOCK_LINKS_RESPONSE = {
7
- trigger_ids: ['1', '2', '3'],
8
- registration_tokens: [
9
- { token: 'reg_token_1', platform: 'portfolio', locale: 'en' },
10
- { token: 'reg_token_2', platform: 'extension', locale: 'en' },
11
- ],
12
- };
13
- const getMockRetrievePushNotificationLinksResponse = () => {
14
- return {
15
- url: endpoints_1.REGISTRATION_TOKENS_ENDPOINT,
16
- requestMethod: 'GET',
17
- response: exports.MOCK_LINKS_RESPONSE,
18
- };
19
- };
20
- exports.getMockRetrievePushNotificationLinksResponse = getMockRetrievePushNotificationLinksResponse;
21
6
  const getMockUpdatePushNotificationLinksResponse = () => {
22
7
  return {
23
8
  url: endpoints_1.REGISTRATION_TOKENS_ENDPOINT,
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AASxD,QAAA,cAAc,GAAG,WAAW,CAAC;AAC7B,QAAA,mBAAmB,GAAgB;IAC9C,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC5B,mBAAmB,EAAE;QACnB,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE;QAC7D,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE;KAC9D;CACF,CAAC;AAEK,MAAM,4CAA4C,GAAG,GAAG,EAAE;IAC/D,OAAO;QACL,GAAG,EAAE,wCAA4B;QACjC,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,2BAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,4CAA4C,gDAMvD;AAEK,MAAM,0CAA0C,GAAG,GAAG,EAAE;IAC7D,OAAO;QACL,GAAG,EAAE,wCAA4B;QACjC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEK,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,yBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD;AAEK,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\nimport type { LinksResult } from '../services/services';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\nexport const MOCK_LINKS_RESPONSE: LinksResult = {\n trigger_ids: ['1', '2', '3'],\n registration_tokens: [\n { token: 'reg_token_1', platform: 'portfolio', locale: 'en' },\n { token: 'reg_token_2', platform: 'extension', locale: 'en' },\n ],\n};\n\nexport const getMockRetrievePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_LINKS_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUpdatePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
1
+ {"version":3,"file":"mockResponse.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":";;;AAAA,yDAAqE;AAQxD,QAAA,cAAc,GAAG,WAAW,CAAC;AAEnC,MAAM,0CAA0C,GAAG,GAAG,EAAE;IAC7D,OAAO;QACL,GAAG,EAAE,wCAA4B;QACjC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,0CAA0C,8CAMrD;AAEW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEK,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,yBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD;AAEK,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC;AANW,QAAA,yCAAyC,6CAMpD","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
@@ -1,11 +1,4 @@
1
- import type { LinksResult } from "../services/services.cjs";
2
1
  export declare const MOCK_REG_TOKEN = "REG_TOKEN";
3
- export declare const MOCK_LINKS_RESPONSE: LinksResult;
4
- export declare const getMockRetrievePushNotificationLinksResponse: () => {
5
- url: string;
6
- requestMethod: "GET";
7
- response: LinksResult;
8
- };
9
2
  export declare const getMockUpdatePushNotificationLinksResponse: () => {
10
3
  url: string;
11
4
  requestMethod: "POST";
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAA6B;AAQxD,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,mBAAmB,EAAE,WAMjC,CAAC;AAEF,eAAO,MAAM,4CAA4C;;;;CAMxD,CAAC;AAEF,eAAO,MAAM,0CAA0C;;;;CAMtD,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;;;;;;;;;;CAMrD,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;CAMrD,CAAC"}
1
+ {"version":3,"file":"mockResponse.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C;;;;CAMtD,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;;;;;;;;;;CAMrD,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;CAMrD,CAAC"}
@@ -1,11 +1,4 @@
1
- import type { LinksResult } from "../services/services.mjs";
2
1
  export declare const MOCK_REG_TOKEN = "REG_TOKEN";
3
- export declare const MOCK_LINKS_RESPONSE: LinksResult;
4
- export declare const getMockRetrievePushNotificationLinksResponse: () => {
5
- url: string;
6
- requestMethod: "GET";
7
- response: LinksResult;
8
- };
9
2
  export declare const getMockUpdatePushNotificationLinksResponse: () => {
10
3
  url: string;
11
4
  requestMethod: "POST";
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,iCAA6B;AAQxD,eAAO,MAAM,cAAc,cAAc,CAAC;AAC1C,eAAO,MAAM,mBAAmB,EAAE,WAMjC,CAAC;AAEF,eAAO,MAAM,4CAA4C;;;;CAMxD,CAAC;AAEF,eAAO,MAAM,0CAA0C;;;;CAMtD,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;;;;;;;;;;CAMrD,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;CAMrD,CAAC"}
1
+ {"version":3,"file":"mockResponse.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,cAAc,cAAc,CAAC;AAE1C,eAAO,MAAM,0CAA0C;;;;CAMtD,CAAC;AAEF,eAAO,MAAM,iBAAiB;;;;;;;;;CAS7B,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;;;;;;;;;;CAMrD,CAAC;AAEF,eAAO,MAAM,yCAAyC;;;;CAMrD,CAAC"}
@@ -1,19 +1,5 @@
1
1
  import { REGISTRATION_TOKENS_ENDPOINT } from "../services/endpoints.mjs";
2
2
  export const MOCK_REG_TOKEN = 'REG_TOKEN';
3
- export const MOCK_LINKS_RESPONSE = {
4
- trigger_ids: ['1', '2', '3'],
5
- registration_tokens: [
6
- { token: 'reg_token_1', platform: 'portfolio', locale: 'en' },
7
- { token: 'reg_token_2', platform: 'extension', locale: 'en' },
8
- ],
9
- };
10
- export const getMockRetrievePushNotificationLinksResponse = () => {
11
- return {
12
- url: REGISTRATION_TOKENS_ENDPOINT,
13
- requestMethod: 'GET',
14
- response: MOCK_LINKS_RESPONSE,
15
- };
16
- };
17
3
  export const getMockUpdatePushNotificationLinksResponse = () => {
18
4
  return {
19
5
  url: REGISTRATION_TOKENS_ENDPOINT,
@@ -1 +1 @@
1
- {"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AASrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAgB;IAC9C,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC5B,mBAAmB,EAAE;QACnB,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE;QAC7D,EAAE,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE;KAC9D;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,4CAA4C,GAAG,GAAG,EAAE;IAC/D,OAAO;QACL,GAAG,EAAE,4BAA4B;QACjC,aAAa,EAAE,KAAK;QACpB,QAAQ,EAAE,mBAAmB;KACP,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAG,EAAE;IAC7D,OAAO;QACL,GAAG,EAAE,4BAA4B;QACjC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\nimport type { LinksResult } from '../services/services';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\nexport const MOCK_LINKS_RESPONSE: LinksResult = {\n trigger_ids: ['1', '2', '3'],\n registration_tokens: [\n { token: 'reg_token_1', platform: 'portfolio', locale: 'en' },\n { token: 'reg_token_2', platform: 'extension', locale: 'en' },\n ],\n};\n\nexport const getMockRetrievePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'GET',\n response: MOCK_LINKS_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockUpdatePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
1
+ {"version":3,"file":"mockResponse.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/mocks/mockResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,kCAA8B;AAQrE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,MAAM,CAAC,MAAM,0CAA0C,GAAG,GAAG,EAAE;IAC7D,OAAO;QACL,GAAG,EAAE,4BAA4B;QACjC,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE;QACH,QAAQ,EAAE,EAAE;QACZ,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,EAAE;QACR,iBAAiB,EAAE,EAAE;KACtB;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,iBAAiB;KACL,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yCAAyC,GAAG,GAAG,EAAE;IAC5D,OAAO;QACL,GAAG,EAAE,kEAAkE;QACvE,aAAa,EAAE,MAAM;QACrB,QAAQ,EAAE,EAAE;KACU,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import { REGISTRATION_TOKENS_ENDPOINT } from '../services/endpoints';\n\ntype MockResponse = {\n url: string | RegExp;\n requestMethod: 'GET' | 'POST' | 'PUT';\n response: unknown;\n};\n\nexport const MOCK_REG_TOKEN = 'REG_TOKEN';\n\nexport const getMockUpdatePushNotificationLinksResponse = () => {\n return {\n url: REGISTRATION_TOKENS_ENDPOINT,\n requestMethod: 'POST',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const MOCK_FCM_RESPONSE = {\n name: '',\n token: 'fcm-token',\n web: {\n endpoint: '',\n p256dh: '',\n auth: '',\n applicationPubKey: '',\n },\n};\n\nexport const getMockCreateFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: MOCK_FCM_RESPONSE,\n } satisfies MockResponse;\n};\n\nexport const getMockDeleteFCMRegistrationTokenResponse = () => {\n return {\n url: /^https:\\/\\/fcmregistrations\\.googleapis\\.com\\/v1\\/projects\\/.*$/u,\n requestMethod: 'POST',\n response: {},\n } satisfies MockResponse;\n};\n"]}
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.REGISTRATION_TOKENS_ENDPOINT = void 0;
4
4
  const url = 'https://push.api.cx.metamask.io';
5
- exports.REGISTRATION_TOKENS_ENDPOINT = `${url}/v1/link`;
5
+ exports.REGISTRATION_TOKENS_ENDPOINT = `${url}/api/v2/token`;
6
6
  //# sourceMappingURL=endpoints.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":";;;AAAA,MAAM,GAAG,GAAG,iCAAiC,CAAC;AACjC,QAAA,4BAA4B,GAAG,GAAG,GAAG,UAAU,CAAC","sourcesContent":["const url = 'https://push.api.cx.metamask.io';\nexport const REGISTRATION_TOKENS_ENDPOINT = `${url}/v1/link`;\n"]}
1
+ {"version":3,"file":"endpoints.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":";;;AAAA,MAAM,GAAG,GAAG,iCAAiC,CAAC;AACjC,QAAA,4BAA4B,GAAG,GAAG,GAAG,eAAe,CAAC","sourcesContent":["const url = 'https://push.api.cx.metamask.io';\nexport const REGISTRATION_TOKENS_ENDPOINT = `${url}/api/v2/token`;\n"]}
@@ -1,2 +1,2 @@
1
- export declare const REGISTRATION_TOKENS_ENDPOINT = "https://push.api.cx.metamask.io/v1/link";
1
+ export declare const REGISTRATION_TOKENS_ENDPOINT = "https://push.api.cx.metamask.io/api/v2/token";
2
2
  //# sourceMappingURL=endpoints.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,4BAA4B,4CAAmB,CAAC"}
1
+ {"version":3,"file":"endpoints.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,4BAA4B,iDAAwB,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const REGISTRATION_TOKENS_ENDPOINT = "https://push.api.cx.metamask.io/v1/link";
1
+ export declare const REGISTRATION_TOKENS_ENDPOINT = "https://push.api.cx.metamask.io/api/v2/token";
2
2
  //# sourceMappingURL=endpoints.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,4BAA4B,4CAAmB,CAAC"}
1
+ {"version":3,"file":"endpoints.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,4BAA4B,iDAAwB,CAAC"}
@@ -1,3 +1,3 @@
1
1
  const url = 'https://push.api.cx.metamask.io';
2
- export const REGISTRATION_TOKENS_ENDPOINT = `${url}/v1/link`;
2
+ export const REGISTRATION_TOKENS_ENDPOINT = `${url}/api/v2/token`;
3
3
  //# sourceMappingURL=endpoints.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"endpoints.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAAA,MAAM,GAAG,GAAG,iCAAiC,CAAC;AAC9C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,GAAG,UAAU,CAAC","sourcesContent":["const url = 'https://push.api.cx.metamask.io';\nexport const REGISTRATION_TOKENS_ENDPOINT = `${url}/v1/link`;\n"]}
1
+ {"version":3,"file":"endpoints.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/endpoints.ts"],"names":[],"mappings":"AAAA,MAAM,GAAG,GAAG,iCAAiC,CAAC;AAC9C,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,GAAG,eAAe,CAAC","sourcesContent":["const url = 'https://push.api.cx.metamask.io';\nexport const REGISTRATION_TOKENS_ENDPOINT = `${url}/api/v2/token`;\n"]}