@metamask-previews/notification-services-controller 0.21.0-preview-5575cd05 → 0.21.0-preview-a1eb992b

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 (119) hide show
  1. package/dist/NotificationServicesController/NotificationServicesController.cjs +74 -62
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  3. package/dist/NotificationServicesController/NotificationServicesController.d.cts +34 -10
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  5. package/dist/NotificationServicesController/NotificationServicesController.d.mts +34 -10
  6. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  7. package/dist/NotificationServicesController/NotificationServicesController.mjs +74 -62
  8. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  9. package/dist/NotificationServicesController/index.cjs +0 -1
  10. package/dist/NotificationServicesController/index.cjs.map +1 -1
  11. package/dist/NotificationServicesController/index.d.cts +0 -1
  12. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  13. package/dist/NotificationServicesController/index.d.mts +0 -1
  14. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  15. package/dist/NotificationServicesController/index.mjs +0 -1
  16. package/dist/NotificationServicesController/index.mjs.map +1 -1
  17. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +56 -56
  18. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  19. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +24 -18
  20. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  21. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +24 -18
  22. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  23. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +57 -57
  24. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  25. package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs +13 -1
  26. package/dist/NotificationServicesPushController/__fixtures__/mockServices.cjs.map +1 -1
  27. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts +1 -0
  28. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.cts.map +1 -1
  29. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts +1 -0
  30. package/dist/NotificationServicesPushController/__fixtures__/mockServices.d.mts.map +1 -1
  31. package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs +12 -1
  32. package/dist/NotificationServicesPushController/__fixtures__/mockServices.mjs.map +1 -1
  33. package/dist/NotificationServicesPushController/constants.cjs +14 -0
  34. package/dist/NotificationServicesPushController/constants.cjs.map +1 -0
  35. package/dist/NotificationServicesPushController/constants.d.cts +11 -0
  36. package/dist/NotificationServicesPushController/constants.d.cts.map +1 -0
  37. package/dist/NotificationServicesPushController/constants.d.mts +11 -0
  38. package/dist/NotificationServicesPushController/constants.d.mts.map +1 -0
  39. package/dist/NotificationServicesPushController/constants.mjs +11 -0
  40. package/dist/NotificationServicesPushController/constants.mjs.map +1 -0
  41. package/dist/NotificationServicesPushController/{types/push-service-interface.cjs → services/push/index.cjs} +1 -1
  42. package/dist/NotificationServicesPushController/services/push/index.cjs.map +1 -0
  43. package/dist/NotificationServicesPushController/services/push/index.d.cts +6 -0
  44. package/dist/NotificationServicesPushController/services/push/index.d.cts.map +1 -0
  45. package/dist/NotificationServicesPushController/services/push/index.d.mts +6 -0
  46. package/dist/NotificationServicesPushController/services/push/index.d.mts.map +1 -0
  47. package/dist/NotificationServicesPushController/services/push/index.mjs +2 -0
  48. package/dist/NotificationServicesPushController/services/push/index.mjs.map +1 -0
  49. package/dist/NotificationServicesPushController/services/services.cjs +93 -15
  50. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  51. package/dist/NotificationServicesPushController/services/services.d.cts +27 -4
  52. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  53. package/dist/NotificationServicesPushController/services/services.d.mts +27 -4
  54. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  55. package/dist/NotificationServicesPushController/services/services.mjs +94 -14
  56. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  57. package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
  58. package/dist/NotificationServicesPushController/types/index.d.cts +0 -1
  59. package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
  60. package/dist/NotificationServicesPushController/types/index.d.mts +0 -1
  61. package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
  62. package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
  63. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +19 -1
  64. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  65. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +7 -0
  66. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  67. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +7 -0
  68. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  69. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +17 -0
  70. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  71. package/package.json +1 -11
  72. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs +0 -14
  73. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.cjs.map +0 -1
  74. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts +0 -3
  75. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.cts.map +0 -1
  76. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts +0 -3
  77. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.d.mts.map +0 -1
  78. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs +0 -10
  79. package/dist/NotificationServicesPushController/__fixtures__/mockMessenger.mjs.map +0 -1
  80. package/dist/NotificationServicesPushController/types/push-service-interface.cjs.map +0 -1
  81. package/dist/NotificationServicesPushController/types/push-service-interface.d.cts +0 -30
  82. package/dist/NotificationServicesPushController/types/push-service-interface.d.cts.map +0 -1
  83. package/dist/NotificationServicesPushController/types/push-service-interface.d.mts +0 -30
  84. package/dist/NotificationServicesPushController/types/push-service-interface.d.mts.map +0 -1
  85. package/dist/NotificationServicesPushController/types/push-service-interface.mjs +0 -2
  86. package/dist/NotificationServicesPushController/types/push-service-interface.mjs.map +0 -1
  87. package/dist/NotificationServicesPushController/web/index.cjs +0 -8
  88. package/dist/NotificationServicesPushController/web/index.cjs.map +0 -1
  89. package/dist/NotificationServicesPushController/web/index.d.cts +0 -2
  90. package/dist/NotificationServicesPushController/web/index.d.cts.map +0 -1
  91. package/dist/NotificationServicesPushController/web/index.d.mts +0 -2
  92. package/dist/NotificationServicesPushController/web/index.d.mts.map +0 -1
  93. package/dist/NotificationServicesPushController/web/index.mjs +0 -2
  94. package/dist/NotificationServicesPushController/web/index.mjs.map +0 -1
  95. package/dist/NotificationServicesPushController/web/push-utils.cjs +0 -170
  96. package/dist/NotificationServicesPushController/web/push-utils.cjs.map +0 -1
  97. package/dist/NotificationServicesPushController/web/push-utils.d.cts +0 -37
  98. package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +0 -1
  99. package/dist/NotificationServicesPushController/web/push-utils.d.mts +0 -37
  100. package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +0 -1
  101. package/dist/NotificationServicesPushController/web/push-utils.mjs +0 -168
  102. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +0 -1
  103. package/dist/shared/index.cjs +0 -19
  104. package/dist/shared/index.cjs.map +0 -1
  105. package/dist/shared/index.d.cts +0 -3
  106. package/dist/shared/index.d.cts.map +0 -1
  107. package/dist/shared/index.d.mts +0 -3
  108. package/dist/shared/index.d.mts.map +0 -1
  109. package/dist/shared/index.mjs +0 -3
  110. package/dist/shared/index.mjs.map +0 -1
  111. package/dist/shared/is-onchain-notification.cjs +0 -22
  112. package/dist/shared/is-onchain-notification.cjs.map +0 -1
  113. package/dist/shared/is-onchain-notification.d.cts +0 -9
  114. package/dist/shared/is-onchain-notification.d.cts.map +0 -1
  115. package/dist/shared/is-onchain-notification.d.mts +0 -9
  116. package/dist/shared/is-onchain-notification.d.mts.map +0 -1
  117. package/dist/shared/is-onchain-notification.mjs +0 -18
  118. package/dist/shared/is-onchain-notification.mjs.map +0 -1
  119. package/push-services/web/package.json +0 -150
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _NotificationServicesPushController_instances, _NotificationServicesPushController_pushListenerUnsubscribe, _NotificationServicesPushController_env, _NotificationServicesPushController_config, _NotificationServicesPushController_registerMessageHandlers, _NotificationServicesPushController_getAndAssertBearerToken, _NotificationServicesPushController_updatePushState;
12
+ var _NotificationServicesPushController_instances, _NotificationServicesPushController_pushListenerUnsubscribe, _NotificationServicesPushController_env, _NotificationServicesPushController_config, _NotificationServicesPushController_registerMessageHandlers, _NotificationServicesPushController_getAndAssertBearerToken;
13
13
  function $importDefault(module) {
14
14
  if (module?.__esModule) {
15
15
  return module.default;
@@ -19,32 +19,18 @@ 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 { createRegToken, deleteRegToken } from "./services/push/push-web.mjs";
23
+ import { activatePushNotifications, deactivatePushNotifications, listenToPushNotifications, updateTriggerPushNotifications } from "./services/services.mjs";
23
24
  const controllerName = 'NotificationServicesPushController';
24
25
  export const defaultState = {
25
- isPushEnabled: true,
26
26
  fcmToken: '',
27
27
  };
28
28
  const metadata = {
29
- isPushEnabled: {
30
- persist: true,
31
- anonymous: true,
32
- },
33
29
  fcmToken: {
34
30
  persist: true,
35
31
  anonymous: true,
36
32
  },
37
33
  };
38
- const defaultPushEnv = {
39
- apiKey: '',
40
- authDomain: '',
41
- storageBucket: '',
42
- projectId: '',
43
- messagingSenderId: '',
44
- appId: '',
45
- measurementId: '',
46
- vapidKey: '',
47
- };
48
34
  /**
49
35
  * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.
50
36
  * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.
@@ -64,20 +50,29 @@ class NotificationServicesPushController extends BaseController {
64
50
  _NotificationServicesPushController_pushListenerUnsubscribe.set(this, undefined);
65
51
  _NotificationServicesPushController_env.set(this, void 0);
66
52
  _NotificationServicesPushController_config.set(this, void 0);
67
- __classPrivateFieldSet(this, _NotificationServicesPushController_env, env ?? defaultPushEnv, "f");
53
+ __classPrivateFieldSet(this, _NotificationServicesPushController_env, env, "f");
68
54
  __classPrivateFieldSet(this, _NotificationServicesPushController_config, config, "f");
69
55
  __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_registerMessageHandlers).call(this);
70
56
  }
71
57
  async subscribeToPushNotifications() {
72
- if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushFeatureEnabled) {
73
- return;
74
- }
75
58
  if (__classPrivateFieldGet(this, _NotificationServicesPushController_pushListenerUnsubscribe, "f")) {
76
59
  __classPrivateFieldGet(this, _NotificationServicesPushController_pushListenerUnsubscribe, "f").call(this);
77
60
  __classPrivateFieldSet(this, _NotificationServicesPushController_pushListenerUnsubscribe, undefined, "f");
78
61
  }
79
62
  try {
80
- __classPrivateFieldSet(this, _NotificationServicesPushController_pushListenerUnsubscribe, (await __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.subscribeToPushNotifications(__classPrivateFieldGet(this, _NotificationServicesPushController_env, "f"))) ?? undefined, "f");
63
+ __classPrivateFieldSet(this, _NotificationServicesPushController_pushListenerUnsubscribe, await listenToPushNotifications({
64
+ env: __classPrivateFieldGet(this, _NotificationServicesPushController_env, "f"),
65
+ listenToPushReceived: async (n) => {
66
+ this.messagingSystem.publish('NotificationServicesPushController:onNewNotifications', n);
67
+ await __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").onPushNotificationReceived(n);
68
+ },
69
+ listenToPushClicked: (e, n) => {
70
+ if (n) {
71
+ this.messagingSystem.publish('NotificationServicesPushController:pushNotificationClicked', n);
72
+ }
73
+ __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").onPushNotificationClicked(e, n);
74
+ },
75
+ }), "f");
81
76
  }
82
77
  catch {
83
78
  // Do nothing, we are silently failing if push notification registration fails
@@ -92,9 +87,10 @@ class NotificationServicesPushController extends BaseController {
92
87
  * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.
93
88
  *
94
89
  * @param UUIDs - An array of UUIDs to enable push notifications for.
90
+ * @param fcmToken - The optional FCM token to use for push notifications.
95
91
  */
96
- async enablePushNotifications(UUIDs) {
97
- if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushFeatureEnabled) {
92
+ async enablePushNotifications(UUIDs, fcmToken) {
93
+ if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushEnabled) {
98
94
  return;
99
95
  }
100
96
  // Handle creating new reg token (if available)
@@ -103,15 +99,18 @@ class NotificationServicesPushController extends BaseController {
103
99
  // If there is a bearer token, lets try to refresh/create new reg token
104
100
  if (bearerToken) {
105
101
  // Activate Push Notifications
106
- const fcmToken = await activatePushNotifications({
102
+ const regToken = await activatePushNotifications({
107
103
  bearerToken,
108
104
  triggers: UUIDs,
109
105
  env: __classPrivateFieldGet(this, _NotificationServicesPushController_env, "f"),
110
- createRegToken: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.createRegToken,
106
+ fcmToken,
107
+ createRegToken,
111
108
  platform: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").platform,
112
109
  }).catch(() => null);
113
- if (fcmToken) {
114
- __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_updatePushState).call(this, { type: 'enable', fcmToken });
110
+ if (regToken) {
111
+ this.update((state) => {
112
+ state.fcmToken = regToken;
113
+ });
115
114
  }
116
115
  }
117
116
  }
@@ -123,17 +122,26 @@ class NotificationServicesPushController extends BaseController {
123
122
  }
124
123
  /**
125
124
  * Disables push notifications for the application.
126
- * This removes the registration token on this device, and ensures we unsubscribe from any listeners
125
+ * This method handles the process of disabling push notifications by:
126
+ * 1. Unregistering the service worker to stop listening for messages.
127
+ * 2. Sending a request to the server to unregister the device using the FCM token.
128
+ * 3. Removing the FCM token from the state to complete the process.
129
+ *
130
+ * @param UUIDs - An array of UUIDs for which push notifications should be disabled.
127
131
  */
128
- async disablePushNotifications() {
129
- if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushFeatureEnabled) {
132
+ async disablePushNotifications(UUIDs) {
133
+ if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushEnabled) {
130
134
  return;
131
135
  }
136
+ const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_getAndAssertBearerToken).call(this);
137
+ let isPushNotificationsDisabled;
132
138
  try {
133
139
  // Send a request to the server to unregister the token/device
134
- await deactivatePushNotifications({
140
+ isPushNotificationsDisabled = await deactivatePushNotifications({
141
+ bearerToken,
142
+ triggers: UUIDs,
135
143
  env: __classPrivateFieldGet(this, _NotificationServicesPushController_env, "f"),
136
- deleteRegToken: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.deleteRegToken,
144
+ deleteRegToken,
137
145
  regToken: this.state.fcmToken,
138
146
  });
139
147
  }
@@ -142,10 +150,18 @@ class NotificationServicesPushController extends BaseController {
142
150
  log.error(errorMessage);
143
151
  throw new Error(errorMessage);
144
152
  }
153
+ // Remove the FCM token from the state
154
+ if (!isPushNotificationsDisabled) {
155
+ return;
156
+ }
145
157
  // Unsubscribe from push notifications
146
158
  __classPrivateFieldGet(this, _NotificationServicesPushController_pushListenerUnsubscribe, "f")?.call(this);
147
159
  // Update State
148
- __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_updatePushState).call(this, { type: 'disable' });
160
+ if (isPushNotificationsDisabled) {
161
+ this.update((state) => {
162
+ state.fcmToken = '';
163
+ });
164
+ }
149
165
  }
150
166
  /**
151
167
  * Updates the triggers for push notifications.
@@ -155,7 +171,7 @@ class NotificationServicesPushController extends BaseController {
155
171
  * @param UUIDs - An array of UUIDs that should trigger push notifications.
156
172
  */
157
173
  async updateTriggerPushNotifications(UUIDs) {
158
- if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushFeatureEnabled) {
174
+ if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushEnabled) {
159
175
  return;
160
176
  }
161
177
  const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_getAndAssertBearerToken).call(this);
@@ -164,13 +180,16 @@ class NotificationServicesPushController extends BaseController {
164
180
  bearerToken,
165
181
  triggers: UUIDs,
166
182
  env: __classPrivateFieldGet(this, _NotificationServicesPushController_env, "f"),
167
- createRegToken: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.createRegToken,
168
- deleteRegToken: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").pushService.deleteRegToken,
183
+ createRegToken,
184
+ deleteRegToken,
169
185
  platform: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").platform,
186
+ regToken: this.state.fcmToken,
170
187
  });
171
188
  // update the state with the new FCM token
172
189
  if (fcmToken) {
173
- __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_updatePushState).call(this, { type: 'update', fcmToken });
190
+ this.update((state) => {
191
+ state.fcmToken = fcmToken;
192
+ });
174
193
  }
175
194
  }
176
195
  catch (error) {
@@ -192,25 +211,6 @@ _NotificationServicesPushController_pushListenerUnsubscribe = new WeakMap(), _No
192
211
  throw new Error('BearerToken token is missing');
193
212
  }
194
213
  return bearerToken;
195
- }, _NotificationServicesPushController_updatePushState = function _NotificationServicesPushController_updatePushState(command) {
196
- if (command.type === 'enable') {
197
- this.update((state) => {
198
- state.isPushEnabled = true;
199
- state.fcmToken = command.fcmToken;
200
- });
201
- }
202
- if (command.type === 'disable') {
203
- this.update((state) => {
204
- state.isPushEnabled = false;
205
- state.fcmToken = '';
206
- });
207
- }
208
- if (command.type === 'update') {
209
- this.update((state) => {
210
- state.isPushEnabled = true;
211
- state.fcmToken = command.fcmToken;
212
- });
213
- }
214
214
  };
215
215
  export default NotificationServicesPushController;
216
216
  //# sourceMappingURL=NotificationServicesPushController.mjs.map
@@ -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;AAwE5D,MAAM,CAAC,MAAM,YAAY,GAA4C;IACnE,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,EAAE;CACb,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;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,EA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CAAC,QAAQ,CAAC;QACpC,CAAC,CAAC,CAAC;KACJ;AACH,CAAC;eA1FkB,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};\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};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n persist: true,\n anonymous: true,\n },\n fcmToken: {\n persist: true,\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 * 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 }\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 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 });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n state.isPushEnabled = false;\n state.fcmToken = '';\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n });\n }\n }\n\n 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 async enablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\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 }).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 await this.subscribeToPushNotifications();\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 async disablePushNotifications() {\n if (!this.#config.isPushFeatureEnabled) {\n return;\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 }\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 async updateTriggerPushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n\n try {\n const { fcmToken } = await updateTriggerPushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n deleteRegToken: this.#config.pushService.deleteRegToken,\n platform: this.#config.platform,\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 }\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,EAAE,cAAc,EAAE,cAAc,EAAE,qCAAiC;AAC1E,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,yBAAyB,EACzB,8BAA8B,EAC/B,gCAA4B;AAI7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAuE5D,MAAM,CAAC,MAAM,YAAY,GAA4C;IACnE,QAAQ,EAAE,EAAE;CACb,CAAC;AACF,MAAM,QAAQ,GAA2D;IACvE,QAAQ,EAAE;QACR,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;CACF,CAAC;AAgCF;;;;;;GAM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AC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;oBACpB,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBAC5B,CAAC,CAAC,CAAC;aACJ;SACF;QAAC,OAAO,KAAK,EAAE;YACd,MAAM,YAAY,GAAG,qDACnB,KACF,EAAE,CAAC;YACH,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACxB,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;SAC/B;IACH,CAAC;CACF;;IAzMG,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,4DAA4D,EAC5D,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CACxC,CAAC;IACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,6DAA6D,EAC7D,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CACzC,CAAC;IACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,mEAAmE,EACnE,IAAI,CAAC,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC/C,CAAC;IACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,iEAAiE,EACjE,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,CAC7C,CAAC;AACJ,CAAC,gEAED,KAAK;IACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CACjD,yCAAyC,CAC1C,CAAC;IACF,IAAI,CAAC,WAAW,EAAE;QAChB,GAAG,CAAC,KAAK,CACP,oEAAoE,CACrE,CAAC;QACF,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;KACjD;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;eAlEkB,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 { createRegToken, deleteRegToken } from './services/push/push-web';\nimport {\n activatePushNotifications,\n deactivatePushNotifications,\n listenToPushNotifications,\n updateTriggerPushNotifications,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { Types } from '../NotificationServicesController';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n fcmToken: string;\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 fcmToken: '',\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n fcmToken: {\n persist: true,\n anonymous: true,\n },\n};\n\ntype ControllerConfig = {\n /**\n * Config to turn on/off push notifications.\n * This is currently linked to MV3 builds on extension.\n */\n isPushEnabled: boolean;\n\n /**\n * Must handle when a push notification is received.\n * You must call `registration.showNotification` or equivalent to show the notification on web/mobile\n */\n onPushNotificationReceived: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n\n /**\n * Must handle when a push notification is clicked.\n * You must call `event.notification.close();` or equivalent for closing and opening notification in a new window.\n */\n onPushNotificationClicked: (\n event: NotificationEvent,\n notification?: Types.INotification,\n ) => void;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n};\n\n/**\n * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.\n * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.\n * It is responsible for registering and unregistering the service worker that listens for push notifications,\n * managing the FCM token, and communicating with the server to register or unregister the device for push notifications.\n * Additionally, it provides functionality to update the server with new UUIDs that should trigger push notifications.\n */\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 env: PushNotificationEnv;\n config: ControllerConfig;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#env = env;\n this.#config = config;\n\n this.#registerMessageHandlers();\n }\n\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:enablePushNotifications',\n this.enablePushNotifications.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:disablePushNotifications',\n this.disablePushNotifications.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:updateTriggerPushNotifications',\n this.updateTriggerPushNotifications.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n 'NotificationServicesPushController:subscribeToPushNotifications',\n this.subscribeToPushNotifications.bind(this),\n );\n }\n\n async #getAndAssertBearerToken() {\n const bearerToken = await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!bearerToken) {\n log.error(\n 'Failed to enable push notifications: BearerToken token is missing.',\n );\n throw new Error('BearerToken token is missing');\n }\n\n return bearerToken;\n }\n\n async subscribeToPushNotifications() {\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe = await listenToPushNotifications({\n env: this.#env,\n listenToPushReceived: async (n) => {\n this.messagingSystem.publish(\n 'NotificationServicesPushController:onNewNotifications',\n n,\n );\n await this.#config.onPushNotificationReceived(n);\n },\n listenToPushClicked: (e, n) => {\n if (n) {\n this.messagingSystem.publish(\n 'NotificationServicesPushController:pushNotificationClicked',\n n,\n );\n }\n\n this.#config.onPushNotificationClicked(e, n);\n },\n });\n } 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 * @param fcmToken - The optional FCM token to use for push notifications.\n */\n async enablePushNotifications(UUIDs: string[], fcmToken?: string) {\n if (!this.#config.isPushEnabled) {\n return;\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 regToken = await activatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n fcmToken,\n createRegToken,\n platform: this.#config.platform,\n }).catch(() => null);\n\n if (regToken) {\n this.update((state) => {\n state.fcmToken = regToken;\n });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n await this.subscribeToPushNotifications();\n }\n\n /**\n * Disables push notifications for the application.\n * This method handles the process of disabling push notifications by:\n * 1. Unregistering the service worker to stop listening for messages.\n * 2. Sending a request to the server to unregister the device using the FCM token.\n * 3. Removing the FCM token from the state to complete the process.\n *\n * @param UUIDs - An array of UUIDs for which push notifications should be disabled.\n */\n async disablePushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n let isPushNotificationsDisabled: boolean;\n\n try {\n // Send a request to the server to unregister the token/device\n isPushNotificationsDisabled = await deactivatePushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n deleteRegToken,\n regToken: this.state.fcmToken,\n });\n } catch (error) {\n const errorMessage = `Failed to disable push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n }\n\n // Remove the FCM token from the state\n if (!isPushNotificationsDisabled) {\n return;\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n if (isPushNotificationsDisabled) {\n this.update((state) => {\n state.fcmToken = '';\n });\n }\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of UUIDs that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param UUIDs - An array of UUIDs that should trigger push notifications.\n */\n async updateTriggerPushNotifications(UUIDs: string[]) {\n if (!this.#config.isPushEnabled) {\n return;\n }\n\n const bearerToken = await this.#getAndAssertBearerToken();\n\n try {\n const { fcmToken } = await updateTriggerPushNotifications({\n bearerToken,\n triggers: UUIDs,\n env: this.#env,\n createRegToken,\n deleteRegToken,\n platform: this.#config.platform,\n regToken: this.state.fcmToken,\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.update((state) => {\n state.fcmToken = fcmToken;\n });\n }\n } catch (error) {\n const errorMessage = `Failed to update triggers for push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n }\n }\n}\n"]}
@@ -3,9 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.mockEndpointUpdatePushNotificationLinks = void 0;
6
+ exports.mockEndpointUpdatePushNotificationLinks = exports.mockEndpointGetPushNotificationLinks = void 0;
7
7
  const nock_1 = __importDefault(require("nock"));
8
8
  const mockResponse_1 = require("./mockResponse.cjs");
9
+ const mockEndpointGetPushNotificationLinks = (mockReply) => {
10
+ const mockResponse = (0, mockResponse_1.getMockRetrievePushNotificationLinksResponse)();
11
+ const reply = mockReply ?? {
12
+ status: 200,
13
+ body: mockResponse.response,
14
+ };
15
+ const mockEndpoint = (0, nock_1.default)(mockResponse.url)
16
+ .get('')
17
+ .reply(reply.status, reply.body);
18
+ return mockEndpoint;
19
+ };
20
+ exports.mockEndpointGetPushNotificationLinks = mockEndpointGetPushNotificationLinks;
9
21
  const mockEndpointUpdatePushNotificationLinks = (mockReply) => {
10
22
  const mockResponse = (0, mockResponse_1.getMockUpdatePushNotificationLinksResponse)();
11
23
  const reply = mockReply ?? {
@@ -1 +1 @@
1
- {"version":3,"file":"mockServices.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,qDAA4E;AAOrE,MAAM,uCAAuC,GAAG,CACrD,SAAqB,EACrB,EAAE;IACF,MAAM,YAAY,GAAG,IAAA,yDAA0C,GAAE,CAAC;IAClE,MAAM,KAAK,GAAG,SAAS,IAAI;QACzB,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,YAAY,CAAC,QAAQ;KAC5B,CAAC;IAEF,MAAM,YAAY,GAAG,IAAA,cAAI,EAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzE,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAZW,QAAA,uCAAuC,2CAYlD","sourcesContent":["import nock from 'nock';\n\nimport { getMockUpdatePushNotificationLinksResponse } from './mockResponse';\n\ntype MockReply = {\n status: nock.StatusCode;\n body?: nock.Body;\n};\n\nexport const mockEndpointUpdatePushNotificationLinks = (\n mockReply?: MockReply,\n) => {\n const mockResponse = getMockUpdatePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url).post('').reply(reply.status);\n\n return mockEndpoint;\n};\n"]}
1
+ {"version":3,"file":"mockServices.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB,qDAGwB;AAOjB,MAAM,oCAAoC,GAAG,CAAC,SAAqB,EAAE,EAAE;IAC5E,MAAM,YAAY,GAAG,IAAA,2DAA4C,GAAE,CAAC;IACpE,MAAM,KAAK,GAAG,SAAS,IAAI;QACzB,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,YAAY,CAAC,QAAQ;KAC5B,CAAC;IAEF,MAAM,YAAY,GAAG,IAAA,cAAI,EAAC,YAAY,CAAC,GAAG,CAAC;SACxC,GAAG,CAAC,EAAE,CAAC;SACP,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAEnC,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAZW,QAAA,oCAAoC,wCAY/C;AAEK,MAAM,uCAAuC,GAAG,CACrD,SAAqB,EACrB,EAAE;IACF,MAAM,YAAY,GAAG,IAAA,yDAA0C,GAAE,CAAC;IAClE,MAAM,KAAK,GAAG,SAAS,IAAI;QACzB,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,YAAY,CAAC,QAAQ;KAC5B,CAAC;IAEF,MAAM,YAAY,GAAG,IAAA,cAAI,EAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzE,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAZW,QAAA,uCAAuC,2CAYlD","sourcesContent":["import nock from 'nock';\n\nimport {\n getMockRetrievePushNotificationLinksResponse,\n getMockUpdatePushNotificationLinksResponse,\n} from './mockResponse';\n\ntype MockReply = {\n status: nock.StatusCode;\n body?: nock.Body;\n};\n\nexport const mockEndpointGetPushNotificationLinks = (mockReply?: MockReply) => {\n const mockResponse = getMockRetrievePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url)\n .get('')\n .reply(reply.status, reply.body);\n\n return mockEndpoint;\n};\n\nexport const mockEndpointUpdatePushNotificationLinks = (\n mockReply?: MockReply,\n) => {\n const mockResponse = getMockUpdatePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url).post('').reply(reply.status);\n\n return mockEndpoint;\n};\n"]}
@@ -3,6 +3,7 @@ type MockReply = {
3
3
  status: nock.StatusCode;
4
4
  body?: nock.Body;
5
5
  };
6
+ export declare const mockEndpointGetPushNotificationLinks: (mockReply?: MockReply) => nock.Scope;
6
7
  export declare const mockEndpointUpdatePushNotificationLinks: (mockReply?: MockReply) => nock.Scope;
7
8
  export {};
8
9
  //# sourceMappingURL=mockServices.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockServices.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,aAAa;AAIxB,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC;IACxB,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,uCAAuC,eACtC,SAAS,eAWtB,CAAC"}
1
+ {"version":3,"file":"mockServices.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,aAAa;AAOxB,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC;IACxB,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,oCAAoC,eAAgB,SAAS,eAYzE,CAAC;AAEF,eAAO,MAAM,uCAAuC,eACtC,SAAS,eAWtB,CAAC"}
@@ -3,6 +3,7 @@ type MockReply = {
3
3
  status: nock.StatusCode;
4
4
  body?: nock.Body;
5
5
  };
6
+ export declare const mockEndpointGetPushNotificationLinks: (mockReply?: MockReply) => nock.Scope;
6
7
  export declare const mockEndpointUpdatePushNotificationLinks: (mockReply?: MockReply) => nock.Scope;
7
8
  export {};
8
9
  //# sourceMappingURL=mockServices.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockServices.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,aAAa;AAIxB,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC;IACxB,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,uCAAuC,eACtC,SAAS,eAWtB,CAAC"}
1
+ {"version":3,"file":"mockServices.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,aAAa;AAOxB,KAAK,SAAS,GAAG;IACf,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC;IACxB,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,oCAAoC,eAAgB,SAAS,eAYzE,CAAC;AAEF,eAAO,MAAM,uCAAuC,eACtC,SAAS,eAWtB,CAAC"}
@@ -6,7 +6,18 @@ function $importDefault(module) {
6
6
  }
7
7
  import $nock from "nock";
8
8
  const nock = $importDefault($nock);
9
- import { getMockUpdatePushNotificationLinksResponse } from "./mockResponse.mjs";
9
+ import { getMockRetrievePushNotificationLinksResponse, getMockUpdatePushNotificationLinksResponse } from "./mockResponse.mjs";
10
+ export const mockEndpointGetPushNotificationLinks = (mockReply) => {
11
+ const mockResponse = getMockRetrievePushNotificationLinksResponse();
12
+ const reply = mockReply ?? {
13
+ status: 200,
14
+ body: mockResponse.response,
15
+ };
16
+ const mockEndpoint = nock(mockResponse.url)
17
+ .get('')
18
+ .reply(reply.status, reply.body);
19
+ return mockEndpoint;
20
+ };
10
21
  export const mockEndpointUpdatePushNotificationLinks = (mockReply) => {
11
22
  const mockResponse = getMockUpdatePushNotificationLinksResponse();
12
23
  const reply = mockReply ?? {
@@ -1 +1 @@
1
- {"version":3,"file":"mockServices.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,KAAI,aAAa;;AAExB,OAAO,EAAE,0CAA0C,EAAE,2BAAuB;AAO5E,MAAM,CAAC,MAAM,uCAAuC,GAAG,CACrD,SAAqB,EACrB,EAAE;IACF,MAAM,YAAY,GAAG,0CAA0C,EAAE,CAAC;IAClE,MAAM,KAAK,GAAG,SAAS,IAAI;QACzB,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,YAAY,CAAC,QAAQ;KAC5B,CAAC;IAEF,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzE,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC","sourcesContent":["import nock from 'nock';\n\nimport { getMockUpdatePushNotificationLinksResponse } from './mockResponse';\n\ntype MockReply = {\n status: nock.StatusCode;\n body?: nock.Body;\n};\n\nexport const mockEndpointUpdatePushNotificationLinks = (\n mockReply?: MockReply,\n) => {\n const mockResponse = getMockUpdatePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url).post('').reply(reply.status);\n\n return mockEndpoint;\n};\n"]}
1
+ {"version":3,"file":"mockServices.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/__fixtures__/mockServices.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,KAAI,aAAa;;AAExB,OAAO,EACL,4CAA4C,EAC5C,0CAA0C,EAC3C,2BAAuB;AAOxB,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAAC,SAAqB,EAAE,EAAE;IAC5E,MAAM,YAAY,GAAG,4CAA4C,EAAE,CAAC;IACpE,MAAM,KAAK,GAAG,SAAS,IAAI;QACzB,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,YAAY,CAAC,QAAQ;KAC5B,CAAC;IAEF,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC;SACxC,GAAG,CAAC,EAAE,CAAC;SACP,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;IAEnC,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uCAAuC,GAAG,CACrD,SAAqB,EACrB,EAAE;IACF,MAAM,YAAY,GAAG,0CAA0C,EAAE,CAAC;IAClE,MAAM,KAAK,GAAG,SAAS,IAAI;QACzB,MAAM,EAAE,GAAG;QACX,IAAI,EAAE,YAAY,CAAC,QAAQ;KAC5B,CAAC;IAEF,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzE,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC","sourcesContent":["import nock from 'nock';\n\nimport {\n getMockRetrievePushNotificationLinksResponse,\n getMockUpdatePushNotificationLinksResponse,\n} from './mockResponse';\n\ntype MockReply = {\n status: nock.StatusCode;\n body?: nock.Body;\n};\n\nexport const mockEndpointGetPushNotificationLinks = (mockReply?: MockReply) => {\n const mockResponse = getMockRetrievePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url)\n .get('')\n .reply(reply.status, reply.body);\n\n return mockEndpoint;\n};\n\nexport const mockEndpointUpdatePushNotificationLinks = (\n mockReply?: MockReply,\n) => {\n const mockResponse = getMockUpdatePushNotificationLinksResponse();\n const reply = mockReply ?? {\n status: 200,\n body: mockResponse.response,\n };\n\n const mockEndpoint = nock(mockResponse.url).post('').reply(reply.status);\n\n return mockEndpoint;\n};\n"]}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VAPID_KEY = exports.FIREBASE_MEASUREMENT_ID = exports.FIREBASE_APP_ID = exports.FIREBASE_MESSAGING_SENDER_ID = exports.FIREBASE_PROJECT_ID = exports.FIREBASE_STORAGE_BUCKET = exports.FIREBASE_AUTH_DOMAIN = exports.FIREBASE_API_KEY = exports.PUSH_NOTIFICATIONS_SERVICE_URL = exports.ENABLE_MV3 = void 0;
4
+ exports.ENABLE_MV3 = true;
5
+ exports.PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';
6
+ exports.FIREBASE_API_KEY = '';
7
+ exports.FIREBASE_AUTH_DOMAIN = '';
8
+ exports.FIREBASE_STORAGE_BUCKET = '';
9
+ exports.FIREBASE_PROJECT_ID = '';
10
+ exports.FIREBASE_MESSAGING_SENDER_ID = '';
11
+ exports.FIREBASE_APP_ID = '';
12
+ exports.FIREBASE_MEASUREMENT_ID = '';
13
+ exports.VAPID_KEY = '';
14
+ //# sourceMappingURL=constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,IAAI,CAAC;AAClB,QAAA,8BAA8B,GAAG,iCAAiC,CAAC;AAEnE,QAAA,gBAAgB,GAAG,EAAE,CAAC;AACtB,QAAA,oBAAoB,GAAG,EAAE,CAAC;AAC1B,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAC7B,QAAA,mBAAmB,GAAG,EAAE,CAAC;AACzB,QAAA,4BAA4B,GAAG,EAAE,CAAC;AAClC,QAAA,eAAe,GAAG,EAAE,CAAC;AACrB,QAAA,uBAAuB,GAAG,EAAE,CAAC;AAC7B,QAAA,SAAS,GAAG,EAAE,CAAC","sourcesContent":["export const ENABLE_MV3 = true;\nexport const PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';\n\nexport const FIREBASE_API_KEY = '';\nexport const FIREBASE_AUTH_DOMAIN = '';\nexport const FIREBASE_STORAGE_BUCKET = '';\nexport const FIREBASE_PROJECT_ID = '';\nexport const FIREBASE_MESSAGING_SENDER_ID = '';\nexport const FIREBASE_APP_ID = '';\nexport const FIREBASE_MEASUREMENT_ID = '';\nexport const VAPID_KEY = '';\n"]}
@@ -0,0 +1,11 @@
1
+ export declare const ENABLE_MV3 = true;
2
+ export declare const PUSH_NOTIFICATIONS_SERVICE_URL = "https://push.api.cx.metamask.io";
3
+ export declare const FIREBASE_API_KEY = "";
4
+ export declare const FIREBASE_AUTH_DOMAIN = "";
5
+ export declare const FIREBASE_STORAGE_BUCKET = "";
6
+ export declare const FIREBASE_PROJECT_ID = "";
7
+ export declare const FIREBASE_MESSAGING_SENDER_ID = "";
8
+ export declare const FIREBASE_APP_ID = "";
9
+ export declare const FIREBASE_MEASUREMENT_ID = "";
10
+ export declare const VAPID_KEY = "";
11
+ //# sourceMappingURL=constants.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,OAAO,CAAC;AAC/B,eAAO,MAAM,8BAA8B,oCAAoC,CAAC;AAEhF,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,SAAS,KAAK,CAAC"}
@@ -0,0 +1,11 @@
1
+ export declare const ENABLE_MV3 = true;
2
+ export declare const PUSH_NOTIFICATIONS_SERVICE_URL = "https://push.api.cx.metamask.io";
3
+ export declare const FIREBASE_API_KEY = "";
4
+ export declare const FIREBASE_AUTH_DOMAIN = "";
5
+ export declare const FIREBASE_STORAGE_BUCKET = "";
6
+ export declare const FIREBASE_PROJECT_ID = "";
7
+ export declare const FIREBASE_MESSAGING_SENDER_ID = "";
8
+ export declare const FIREBASE_APP_ID = "";
9
+ export declare const FIREBASE_MEASUREMENT_ID = "";
10
+ export declare const VAPID_KEY = "";
11
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,OAAO,CAAC;AAC/B,eAAO,MAAM,8BAA8B,oCAAoC,CAAC;AAEhF,eAAO,MAAM,gBAAgB,KAAK,CAAC;AACnC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,eAAO,MAAM,eAAe,KAAK,CAAC;AAClC,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,SAAS,KAAK,CAAC"}
@@ -0,0 +1,11 @@
1
+ export const ENABLE_MV3 = true;
2
+ export const PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';
3
+ export const FIREBASE_API_KEY = '';
4
+ export const FIREBASE_AUTH_DOMAIN = '';
5
+ export const FIREBASE_STORAGE_BUCKET = '';
6
+ export const FIREBASE_PROJECT_ID = '';
7
+ export const FIREBASE_MESSAGING_SENDER_ID = '';
8
+ export const FIREBASE_APP_ID = '';
9
+ export const FIREBASE_MEASUREMENT_ID = '';
10
+ export const VAPID_KEY = '';
11
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC;AAC/B,MAAM,CAAC,MAAM,8BAA8B,GAAG,iCAAiC,CAAC;AAEhF,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AACnC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AACtC,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAC/C,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC","sourcesContent":["export const ENABLE_MV3 = true;\nexport const PUSH_NOTIFICATIONS_SERVICE_URL = 'https://push.api.cx.metamask.io';\n\nexport const FIREBASE_API_KEY = '';\nexport const FIREBASE_AUTH_DOMAIN = '';\nexport const FIREBASE_STORAGE_BUCKET = '';\nexport const FIREBASE_PROJECT_ID = '';\nexport const FIREBASE_MESSAGING_SENDER_ID = '';\nexport const FIREBASE_APP_ID = '';\nexport const FIREBASE_MEASUREMENT_ID = '';\nexport const VAPID_KEY = '';\n"]}
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=push-service-interface.cjs.map
3
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"","sourcesContent":["import type * as Web from './push-web';\n\nexport type CreateRegToken = typeof Web.createRegToken;\nexport type DeleteRegToken = typeof Web.deleteRegToken;\nexport type ListenToPushNotificationsReceived =\n typeof Web.listenToPushNotificationsReceived;\nexport type ListenToPushNotificationsClicked =\n typeof Web.listenToPushNotificationsClicked;\n"]}
@@ -0,0 +1,6 @@
1
+ import type * as Web from "./push-web.cjs";
2
+ export type CreateRegToken = typeof Web.createRegToken;
3
+ export type DeleteRegToken = typeof Web.deleteRegToken;
4
+ export type ListenToPushNotificationsReceived = typeof Web.listenToPushNotificationsReceived;
5
+ export type ListenToPushNotificationsClicked = typeof Web.listenToPushNotificationsClicked;
6
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,uBAAmB;AAEvC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,iCAAiC,GAC3C,OAAO,GAAG,CAAC,iCAAiC,CAAC;AAC/C,MAAM,MAAM,gCAAgC,GAC1C,OAAO,GAAG,CAAC,gCAAgC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type * as Web from "./push-web.mjs";
2
+ export type CreateRegToken = typeof Web.createRegToken;
3
+ export type DeleteRegToken = typeof Web.deleteRegToken;
4
+ export type ListenToPushNotificationsReceived = typeof Web.listenToPushNotificationsReceived;
5
+ export type ListenToPushNotificationsClicked = typeof Web.listenToPushNotificationsClicked;
6
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,GAAG,uBAAmB;AAEvC,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,CAAC,cAAc,CAAC;AACvD,MAAM,MAAM,iCAAiC,GAC3C,OAAO,GAAG,CAAC,iCAAiC,CAAC;AAC/C,MAAM,MAAM,gCAAgC,GAC1C,OAAO,GAAG,CAAC,gCAAgC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/index.ts"],"names":[],"mappings":"","sourcesContent":["import type * as Web from './push-web';\n\nexport type CreateRegToken = typeof Web.createRegToken;\nexport type DeleteRegToken = typeof Web.deleteRegToken;\nexport type ListenToPushNotificationsReceived =\n typeof Web.listenToPushNotificationsReceived;\nexport type ListenToPushNotificationsClicked =\n typeof Web.listenToPushNotificationsClicked;\n"]}