@metamask-previews/notification-services-controller 0.19.0-preview-2a6578b3 → 0.20.0-preview-224dff25

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 (176) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.cjs +22 -1
  3. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.cjs.map +1 -1
  4. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.d.cts +22 -0
  5. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.d.cts.map +1 -1
  6. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.d.mts +22 -0
  7. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.d.mts.map +1 -1
  8. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.mjs +22 -1
  9. package/dist/NotificationServicesController/__fixtures__/mock-raw-notifications.mjs.map +1 -1
  10. package/dist/NotificationServicesController/__fixtures__/mockResponses.cjs +2 -2
  11. package/dist/NotificationServicesController/__fixtures__/mockResponses.cjs.map +1 -1
  12. package/dist/NotificationServicesController/__fixtures__/mockResponses.mjs +2 -2
  13. package/dist/NotificationServicesController/__fixtures__/mockResponses.mjs.map +1 -1
  14. package/dist/NotificationServicesController/__fixtures__/test-utils.cjs +1 -1
  15. package/dist/NotificationServicesController/__fixtures__/test-utils.cjs.map +1 -1
  16. package/dist/NotificationServicesController/__fixtures__/test-utils.mjs +1 -1
  17. package/dist/NotificationServicesController/__fixtures__/test-utils.mjs.map +1 -1
  18. package/dist/NotificationServicesController/constants/notification-schema.cjs +0 -1
  19. package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
  20. package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
  21. package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
  22. package/dist/NotificationServicesController/constants/notification-schema.mjs +0 -1
  23. package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
  24. package/dist/NotificationServicesController/index.cjs +1 -3
  25. package/dist/NotificationServicesController/index.cjs.map +1 -1
  26. package/dist/NotificationServicesController/index.d.cts +2 -2
  27. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  28. package/dist/NotificationServicesController/index.d.mts +2 -2
  29. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  30. package/dist/NotificationServicesController/index.mjs +0 -2
  31. package/dist/NotificationServicesController/index.mjs.map +1 -1
  32. package/dist/NotificationServicesController/processors/process-notifications.cjs +1 -1
  33. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  34. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  35. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  36. package/dist/NotificationServicesController/processors/process-notifications.mjs +1 -1
  37. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  38. package/dist/NotificationServicesController/services/feature-announcements.cjs +1 -0
  39. package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
  40. package/dist/NotificationServicesController/services/feature-announcements.d.cts +1 -0
  41. package/dist/NotificationServicesController/services/feature-announcements.d.cts.map +1 -1
  42. package/dist/NotificationServicesController/services/feature-announcements.d.mts +1 -0
  43. package/dist/NotificationServicesController/services/feature-announcements.d.mts.map +1 -1
  44. package/dist/NotificationServicesController/services/feature-announcements.mjs +1 -0
  45. package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
  46. package/dist/NotificationServicesController/services/onchain-notifications.cjs +1 -4
  47. package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +1 -1
  48. package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +1 -1
  49. package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +1 -1
  50. package/dist/NotificationServicesController/services/onchain-notifications.mjs +1 -4
  51. package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +1 -1
  52. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.cjs.map +1 -1
  53. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.cts +1 -1
  54. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.cts.map +1 -1
  55. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.mts +1 -1
  56. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.mts.map +1 -1
  57. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.mjs.map +1 -1
  58. package/dist/NotificationServicesController/types/feature-announcement/index.cjs +0 -17
  59. package/dist/NotificationServicesController/types/feature-announcement/index.cjs.map +1 -1
  60. package/dist/NotificationServicesController/types/feature-announcement/index.d.cts +3 -3
  61. package/dist/NotificationServicesController/types/feature-announcement/index.d.cts.map +1 -1
  62. package/dist/NotificationServicesController/types/feature-announcement/index.d.mts +3 -3
  63. package/dist/NotificationServicesController/types/feature-announcement/index.d.mts.map +1 -1
  64. package/dist/NotificationServicesController/types/feature-announcement/index.mjs +1 -3
  65. package/dist/NotificationServicesController/types/feature-announcement/index.mjs.map +1 -1
  66. package/dist/NotificationServicesController/types/index.cjs +0 -19
  67. package/dist/NotificationServicesController/types/index.cjs.map +1 -1
  68. package/dist/NotificationServicesController/types/index.d.cts +5 -5
  69. package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
  70. package/dist/NotificationServicesController/types/index.d.mts +5 -5
  71. package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
  72. package/dist/NotificationServicesController/types/index.mjs +1 -5
  73. package/dist/NotificationServicesController/types/index.mjs.map +1 -1
  74. package/dist/NotificationServicesController/types/notification/index.cjs +0 -15
  75. package/dist/NotificationServicesController/types/notification/index.cjs.map +1 -1
  76. package/dist/NotificationServicesController/types/notification/index.d.cts +1 -1
  77. package/dist/NotificationServicesController/types/notification/index.d.cts.map +1 -1
  78. package/dist/NotificationServicesController/types/notification/index.d.mts +1 -1
  79. package/dist/NotificationServicesController/types/notification/index.d.mts.map +1 -1
  80. package/dist/NotificationServicesController/types/notification/index.mjs +1 -1
  81. package/dist/NotificationServicesController/types/notification/index.mjs.map +1 -1
  82. package/dist/NotificationServicesController/types/notification/notification.cjs.map +1 -1
  83. package/dist/NotificationServicesController/types/notification/notification.d.cts.map +1 -1
  84. package/dist/NotificationServicesController/types/notification/notification.d.mts.map +1 -1
  85. package/dist/NotificationServicesController/types/notification/notification.mjs.map +1 -1
  86. package/dist/NotificationServicesController/types/on-chain-notification/index.cjs +0 -15
  87. package/dist/NotificationServicesController/types/on-chain-notification/index.cjs.map +1 -1
  88. package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts +1 -1
  89. package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts.map +1 -1
  90. package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts +1 -1
  91. package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts.map +1 -1
  92. package/dist/NotificationServicesController/types/on-chain-notification/index.mjs +1 -1
  93. package/dist/NotificationServicesController/types/on-chain-notification/index.mjs.map +1 -1
  94. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.cjs.map +1 -1
  95. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts +1 -1
  96. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts.map +1 -1
  97. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts +1 -1
  98. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts.map +1 -1
  99. package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs.map +1 -1
  100. package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs +2 -1
  101. package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs.map +1 -1
  102. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts.map +1 -1
  103. package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts.map +1 -1
  104. package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs +2 -1
  105. package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs.map +1 -1
  106. package/dist/NotificationServicesController/types/snaps/index.cjs +0 -15
  107. package/dist/NotificationServicesController/types/snaps/index.cjs.map +1 -1
  108. package/dist/NotificationServicesController/types/snaps/index.d.cts +1 -1
  109. package/dist/NotificationServicesController/types/snaps/index.d.cts.map +1 -1
  110. package/dist/NotificationServicesController/types/snaps/index.d.mts +1 -1
  111. package/dist/NotificationServicesController/types/snaps/index.d.mts.map +1 -1
  112. package/dist/NotificationServicesController/types/snaps/index.mjs +1 -1
  113. package/dist/NotificationServicesController/types/snaps/index.mjs.map +1 -1
  114. package/dist/NotificationServicesController/types/user-storage/index.cjs +0 -15
  115. package/dist/NotificationServicesController/types/user-storage/index.cjs.map +1 -1
  116. package/dist/NotificationServicesController/types/user-storage/index.d.cts +1 -1
  117. package/dist/NotificationServicesController/types/user-storage/index.d.cts.map +1 -1
  118. package/dist/NotificationServicesController/types/user-storage/index.d.mts +1 -1
  119. package/dist/NotificationServicesController/types/user-storage/index.d.mts.map +1 -1
  120. package/dist/NotificationServicesController/types/user-storage/index.mjs +1 -1
  121. package/dist/NotificationServicesController/types/user-storage/index.mjs.map +1 -1
  122. package/dist/NotificationServicesController/utils/utils.cjs.map +1 -1
  123. package/dist/NotificationServicesController/utils/utils.mjs.map +1 -1
  124. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +1 -3
  125. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  126. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +1 -3
  127. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  128. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +1 -3
  129. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  130. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +1 -3
  131. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  132. package/dist/NotificationServicesPushController/__fixtures__/mockResponse.cjs +0 -2
  133. package/dist/NotificationServicesPushController/__fixtures__/mockResponse.cjs.map +1 -1
  134. package/dist/NotificationServicesPushController/__fixtures__/mockResponse.d.cts.map +1 -1
  135. package/dist/NotificationServicesPushController/__fixtures__/mockResponse.d.mts.map +1 -1
  136. package/dist/NotificationServicesPushController/__fixtures__/mockResponse.mjs +0 -2
  137. package/dist/NotificationServicesPushController/__fixtures__/mockResponse.mjs.map +1 -1
  138. package/dist/NotificationServicesPushController/index.cjs +1 -3
  139. package/dist/NotificationServicesPushController/index.cjs.map +1 -1
  140. package/dist/NotificationServicesPushController/index.d.cts +2 -2
  141. package/dist/NotificationServicesPushController/index.d.cts.map +1 -1
  142. package/dist/NotificationServicesPushController/index.d.mts +2 -2
  143. package/dist/NotificationServicesPushController/index.d.mts.map +1 -1
  144. package/dist/NotificationServicesPushController/index.mjs +0 -2
  145. package/dist/NotificationServicesPushController/index.mjs.map +1 -1
  146. package/dist/NotificationServicesPushController/services/push/push-web.cjs +2 -1
  147. package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +1 -1
  148. package/dist/NotificationServicesPushController/services/push/push-web.d.cts +1 -0
  149. package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +1 -1
  150. package/dist/NotificationServicesPushController/services/push/push-web.d.mts +1 -0
  151. package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +1 -1
  152. package/dist/NotificationServicesPushController/services/push/push-web.mjs +2 -1
  153. package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +1 -1
  154. package/dist/NotificationServicesPushController/services/services.cjs +0 -2
  155. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  156. package/dist/NotificationServicesPushController/services/services.d.cts +1 -1
  157. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  158. package/dist/NotificationServicesPushController/services/services.d.mts +1 -1
  159. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  160. package/dist/NotificationServicesPushController/services/services.mjs +0 -2
  161. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  162. package/dist/NotificationServicesPushController/types/index.cjs +0 -15
  163. package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
  164. package/dist/NotificationServicesPushController/types/index.d.cts +1 -1
  165. package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
  166. package/dist/NotificationServicesPushController/types/index.d.mts +1 -1
  167. package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
  168. package/dist/NotificationServicesPushController/types/index.mjs +1 -1
  169. package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
  170. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +2 -2
  171. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  172. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  173. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  174. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +2 -2
  175. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  176. package/package.json +4 -4
@@ -29,14 +29,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
29
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
30
30
  };
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.Mocks = exports.Utils = exports.Types = exports.Controller = void 0;
32
+ exports.Mocks = exports.Utils = exports.Controller = void 0;
33
33
  const NotificationServicesPushController_1 = __importDefault(require("./NotificationServicesPushController.cjs"));
34
34
  exports.Controller = NotificationServicesPushController_1.default;
35
35
  const NotificationServicesPushController = NotificationServicesPushController_1.default;
36
36
  exports.default = NotificationServicesPushController;
37
37
  __exportStar(require("./NotificationServicesPushController.cjs"), exports);
38
- exports.Types = __importStar(require("./types/index.cjs"));
39
- __exportStar(require("./types/index.cjs"), exports);
40
38
  exports.Utils = __importStar(require("./utils/index.cjs"));
41
39
  __exportStar(require("./utils/index.cjs"), exports);
42
40
  exports.Mocks = __importStar(require("./__fixtures__/index.cjs"));
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kHAA8D;AAGrD,qBAHF,4CAAU,CAGE;AADnB,MAAM,kCAAkC,GAAG,4CAAU,CAAC;AAEtD,kBAAe,kCAAkC,CAAC;AAClD,2EAAqD;AACrD,2DAAiC;AACjC,oDAAwB;AACxB,2DAAiC;AACjC,oDAAwB;AACxB,kEAAwC","sourcesContent":["import Controller from './NotificationServicesPushController';\n\nconst NotificationServicesPushController = Controller;\nexport { Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport * as Types from './types';\nexport * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './__fixtures__';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kHAA8D;AAGrD,qBAHF,4CAAU,CAGE;AADnB,MAAM,kCAAkC,GAAG,4CAAU,CAAC;AAEtD,kBAAe,kCAAkC,CAAC;AAClD,2EAAqD;AAGrD,2DAAiC;AACjC,oDAAwB;AACxB,kEAAwC","sourcesContent":["import Controller from './NotificationServicesPushController';\n\nconst NotificationServicesPushController = Controller;\nexport { Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './__fixtures__';\n"]}
@@ -3,8 +3,8 @@ declare const NotificationServicesPushController: typeof Controller;
3
3
  export { Controller };
4
4
  export default NotificationServicesPushController;
5
5
  export * from "./NotificationServicesPushController.cjs";
6
- export * as Types from "./types/index.cjs";
7
- export * from "./types/index.cjs";
6
+ export type * as Types from "./types/index.cjs";
7
+ export type * from "./types/index.cjs";
8
8
  export * as Utils from "./utils/index.cjs";
9
9
  export * from "./utils/index.cjs";
10
10
  export * as Mocks from "./__fixtures__/index.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,QAAA,MAAM,kCAAkC,mBAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,iCAAuB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,QAAA,MAAM,kCAAkC,mBAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,iCAAuB"}
@@ -3,8 +3,8 @@ declare const NotificationServicesPushController: typeof Controller;
3
3
  export { Controller };
4
4
  export default NotificationServicesPushController;
5
5
  export * from "./NotificationServicesPushController.mjs";
6
- export * as Types from "./types/index.mjs";
7
- export * from "./types/index.mjs";
6
+ export type * as Types from "./types/index.mjs";
7
+ export type * from "./types/index.mjs";
8
8
  export * as Utils from "./utils/index.mjs";
9
9
  export * from "./utils/index.mjs";
10
10
  export * as Mocks from "./__fixtures__/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,QAAA,MAAM,kCAAkC,mBAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,iCAAuB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,QAAA,MAAM,kCAAkC,mBAAa,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,YAAY,KAAK,KAAK,0BAAgB;AACtC,uCAA6B;AAC7B,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,iCAAuB"}
@@ -3,8 +3,6 @@ const NotificationServicesPushController = Controller;
3
3
  export { Controller };
4
4
  export default NotificationServicesPushController;
5
5
  export * from "./NotificationServicesPushController.mjs";
6
- export * as Types from "./types/index.mjs";
7
- export * from "./types/index.mjs";
8
6
  export * as Utils from "./utils/index.mjs";
9
7
  export * from "./utils/index.mjs";
10
8
  export * as Mocks from "./__fixtures__/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,MAAM,kCAAkC,GAAG,UAAU,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AACrD,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,iCAAuB","sourcesContent":["import Controller from './NotificationServicesPushController';\n\nconst NotificationServicesPushController = Controller;\nexport { Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport * as Types from './types';\nexport * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './__fixtures__';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,iDAA6C;AAE9D,MAAM,kCAAkC,GAAG,UAAU,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,kCAAkC,CAAC;AAClD,yDAAqD;AAGrD,OAAO,KAAK,KAAK,0BAAgB;AACjC,kCAAwB;AACxB,OAAO,KAAK,KAAK,iCAAuB","sourcesContent":["import Controller from './NotificationServicesPushController';\n\nconst NotificationServicesPushController = Controller;\nexport { Controller };\nexport default NotificationServicesPushController;\nexport * from './NotificationServicesPushController';\nexport type * as Types from './types';\nexport type * from './types';\nexport * as Utils from './utils';\nexport * from './utils';\nexport * as Mocks from './__fixtures__';\n"]}
@@ -80,13 +80,14 @@ async function deleteRegToken(env) {
80
80
  await (0, messaging_1.deleteToken)(messaging);
81
81
  return true;
82
82
  }
83
- catch (error) {
83
+ catch {
84
84
  return false;
85
85
  }
86
86
  }
87
87
  exports.deleteRegToken = deleteRegToken;
88
88
  /**
89
89
  * Service Worker Listener for when push notifications are received.
90
+ *
90
91
  * @param env - push notification environment
91
92
  * @param handler - handler to actually showing notification, MUST BE PROVEDED
92
93
  * @returns unsubscribe handler
@@ -1 +1 @@
1
- {"version":3,"file":"push-web.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";;;;;;AAIA,sCAAqD;AACrD,kDAA2D;AAC3D,8CAI+B;AAE/B,wDAA2B;AAG3B,sGAAqE;AACrE,iFAA+E;AAK/E,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,sBAAc,KAAd,sBAAc,GAA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;gBACjC,KAAK;aACN,CAAC,CAAC;YACH,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;IACH,CAAC,CACF,CAAC;IAEF,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,4BAA4B,EAAE,CAAC;IACzD,OAAO,WAAW,CAAC;AACrB,CAAC;AArCD,8EAqCC;AAED;;;;;GAKG;AACH,SAAgB,gCAAgC,CAC9C,OAA2E;IAE3E,MAAM,YAAY,GAAG,CAAC,KAAwB,EAAE,EAAE;QAChD,WAAW;QACX,MAAM,IAAI,GAAwB,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;QAC5D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC;AAbD,4EAaC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../../NotificationServicesController';\nimport { Processors } from '../../../NotificationServicesController';\nimport { toRawOnChainNotification } from '../../../shared/to-raw-notification';\nimport type { PushNotificationEnv } from '../../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVEDED\n * @returns unsubscribe handler\n */\nexport async function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedOnChainRawNotification | undefined =\n payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawOnChainNotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nexport function listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification?: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n"]}
1
+ {"version":3,"file":"push-web.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";;;;;;AAIA,sCAAqD;AACrD,kDAA2D;AAC3D,8CAI+B;AAE/B,wDAA2B;AAG3B,sGAAqE;AACrE,iFAA+E;AAK/E,2BAA2B;AAC3B,uDAAuD;AAC5C,QAAA,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,sBAAc,KAAd,sBAAc,GAAK,MAAM,IAAA,gBAAW,GAAE,EAAC;IACvC,OAAO,sBAAc,CAAC;AACxB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAC7B,GAAwB,EACF,EAAE;IACxB,IAAI;QACF,OAAO,IAAA,YAAM,GAAE,CAAC;KACjB;IAAC,MAAM;QACN,MAAM,cAAc,GAAG;YACrB,MAAM,EAAE,GAA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C,CAC9C,OAA2E;IAE3E,MAAM,YAAY,GAAG,CAAC,KAAwB,EAAE,EAAE;QAChD,WAAW;QACX,MAAM,IAAI,GAAwB,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;QAC5D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC;AAbD,4EAaC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../../NotificationServicesController';\nimport { Processors } from '../../../NotificationServicesController';\nimport { toRawOnChainNotification } from '../../../shared/to-raw-notification';\nimport type { PushNotificationEnv } from '../../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVEDED\n * @returns unsubscribe handler\n */\nexport async function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedOnChainRawNotification | undefined =\n payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawOnChainNotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nexport function listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification?: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n"]}
@@ -18,6 +18,7 @@ export declare function createRegToken(env: PushNotificationEnv): Promise<string
18
18
  export declare function deleteRegToken(env: PushNotificationEnv): Promise<boolean>;
19
19
  /**
20
20
  * Service Worker Listener for when push notifications are received.
21
+ *
21
22
  * @param env - push notification environment
22
23
  * @param handler - handler to actually showing notification, MUST BE PROVEDED
23
24
  * @returns unsubscribe handler
@@ -1 +1 @@
1
- {"version":3,"file":"push-web.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,0DAAgD;AAGrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAA6B;AAMhE,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;;;GAKG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACnE,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAkC9B;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,cAY5E"}
1
+ {"version":3,"file":"push-web.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,0DAAgD;AAGrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAA6B;AAMhE,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;;;;GAMG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACnE,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAkC9B;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,cAY5E"}
@@ -18,6 +18,7 @@ export declare function createRegToken(env: PushNotificationEnv): Promise<string
18
18
  export declare function deleteRegToken(env: PushNotificationEnv): Promise<boolean>;
19
19
  /**
20
20
  * Service Worker Listener for when push notifications are received.
21
+ *
21
22
  * @param env - push notification environment
22
23
  * @param handler - handler to actually showing notification, MUST BE PROVEDED
23
24
  * @returns unsubscribe handler
@@ -1 +1 @@
1
- {"version":3,"file":"push-web.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,0DAAgD;AAGrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAA6B;AAMhE,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;;;GAKG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACnE,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAkC9B;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,cAY5E"}
1
+ {"version":3,"file":"push-web.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,KAAK,EAAE,0DAAgD;AAGrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAA6B;AAMhE,eAAO,IAAI,cAAc,EAAE,OAAO,GAAG,IAAW,CAAC;AAsCjD;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAexB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,mBAAmB,GACvB,OAAO,CAAC,OAAO,CAAC,CAYlB;AAED;;;;;;GAMG;AACH,wBAAsB,iCAAiC,CACrD,GAAG,EAAE,mBAAmB,EACxB,OAAO,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACnE,OAAO,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC,CAkC9B;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,OAAO,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,cAY5E"}
@@ -80,12 +80,13 @@ export async function deleteRegToken(env) {
80
80
  await deleteToken(messaging);
81
81
  return true;
82
82
  }
83
- catch (error) {
83
+ catch {
84
84
  return false;
85
85
  }
86
86
  }
87
87
  /**
88
88
  * Service Worker Listener for when push notifications are received.
89
+ *
89
90
  * @param env - push notification environment
90
91
  * @param handler - handler to actually showing notification, MUST BE PROVEDED
91
92
  * @returns unsubscribe handler
@@ -1 +1 @@
1
- {"version":3,"file":"push-web.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";;;;;;AAIA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,qBAAqB;AACrD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B;AAC3D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACZ,8BAA8B;AAE/B,OAAO,IAAG,iBAAiB;;AAG3B,OAAO,EAAE,UAAU,EAAE,0DAAgD;AACrE,OAAO,EAAE,wBAAwB,EAAE,gDAA4C;AAK/E,2BAA2B;AAC3B,uDAAuD;AACvD,MAAM,CAAC,IAAI,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB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AI;gBACjC,KAAK;aACN,CAAC,CAAC;YACH,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACrD;IACH,CAAC,CACF,CAAC;IAEF,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,4BAA4B,EAAE,CAAC;IACzD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC9C,OAA2E;IAE3E,MAAM,YAAY,GAAG,CAAC,KAAwB,EAAE,EAAE;QAChD,WAAW;QACX,MAAM,IAAI,GAAwB,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;QAC5D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../../NotificationServicesController';\nimport { Processors } from '../../../NotificationServicesController';\nimport { toRawOnChainNotification } from '../../../shared/to-raw-notification';\nimport type { PushNotificationEnv } from '../../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVEDED\n * @returns unsubscribe handler\n */\nexport async function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedOnChainRawNotification | undefined =\n payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawOnChainNotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nexport function listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification?: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n"]}
1
+ {"version":3,"file":"push-web.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesPushController/services/push/push-web.ts"],"names":[],"mappings":";;;;;;AAIA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,qBAAqB;AACrD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,2BAA2B;AAC3D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,WAAW,EACZ,8BAA8B;AAE/B,OAAO,IAAG,iBAAiB;;AAG3B,OAAO,EAAE,UAAU,EAAE,0DAAgD;AACrE,OAAO,EAAE,wBAAwB,EAAE,gDAA4C;AAK/E,2BAA2B;AAC3B,uDAAuD;AACvD,MAAM,CAAC,IAAI,cAAc,GAAmB,IAAI,CAAC;AAEjD,MAAM,mBAAmB,GAAG,KAAK,IAAI,EAAE;IACrC,cAAc,KAAd,cAAc,GAAK,MAAM,WAAW,EAAE,EAAC;IACvC,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;A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,GAAG,EAAE,CAAC,4BAA4B,EAAE,CAAC;IACzD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC9C,OAA2E;IAE3E,MAAM,YAAY,GAAG,CAAC,KAAwB,EAAE,EAAE;QAChD,WAAW;QACX,MAAM,IAAI,GAAwB,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC;QAC5D,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,IAAI,CAAC,gBAAgB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,GAAG,EAAE,CACvB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,YAAY,CAAC,CAAC;IAC9D,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["// We are defining that this file uses a webworker global scope.\n// eslint-disable-next-line spaced-comment\n/// <reference lib=\"webworker\" />\nimport type { FirebaseApp } from 'firebase/app';\nimport { getApp, initializeApp } from 'firebase/app';\nimport { getToken, deleteToken } from 'firebase/messaging';\nimport {\n getMessaging,\n onBackgroundMessage,\n isSupported,\n} from 'firebase/messaging/sw';\nimport type { Messaging, MessagePayload } from 'firebase/messaging/sw';\nimport log from 'loglevel';\n\nimport type { Types } from '../../../NotificationServicesController';\nimport { Processors } from '../../../NotificationServicesController';\nimport { toRawOnChainNotification } from '../../../shared/to-raw-notification';\nimport type { PushNotificationEnv } from '../../types/firebase';\n\ndeclare const self: ServiceWorkerGlobalScope;\n\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let supportedCache: boolean | null = null;\n\nconst getPushAvailability = async () => {\n supportedCache ??= await isSupported();\n return supportedCache;\n};\n\nconst createFirebaseApp = async (\n env: PushNotificationEnv,\n): Promise<FirebaseApp> => {\n try {\n return getApp();\n } catch {\n const firebaseConfig = {\n apiKey: env.apiKey,\n authDomain: env.authDomain,\n storageBucket: env.storageBucket,\n projectId: env.projectId,\n messagingSenderId: env.messagingSenderId,\n appId: env.appId,\n measurementId: env.measurementId,\n };\n return initializeApp(firebaseConfig);\n }\n};\n\nconst getFirebaseMessaging = async (\n env: PushNotificationEnv,\n): Promise<Messaging | null> => {\n const supported = await getPushAvailability();\n if (!supported) {\n return null;\n }\n\n const app = await createFirebaseApp(env);\n return getMessaging(app);\n};\n\n/**\n * Creates a registration token for Firebase Cloud Messaging.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with the registration token or null if an error occurs.\n */\nexport async function createRegToken(\n env: PushNotificationEnv,\n): Promise<string | null> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const token = await getToken(messaging, {\n serviceWorkerRegistration: self.registration,\n vapidKey: env.vapidKey,\n });\n return token;\n } catch {\n return null;\n }\n}\n\n/**\n * Deletes the Firebase Cloud Messaging registration token.\n *\n * @param env - env to configure push notifications\n * @returns A promise that resolves with true if the token was successfully deleted, false otherwise.\n */\nexport async function deleteRegToken(\n env: PushNotificationEnv,\n): Promise<boolean> {\n try {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return true;\n }\n\n await deleteToken(messaging);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Service Worker Listener for when push notifications are received.\n *\n * @param env - push notification environment\n * @param handler - handler to actually showing notification, MUST BE PROVEDED\n * @returns unsubscribe handler\n */\nexport async function listenToPushNotificationsReceived(\n env: PushNotificationEnv,\n handler: (notification: Types.INotification) => void | Promise<void>,\n): Promise<(() => void) | null> {\n const messaging = await getFirebaseMessaging(env);\n if (!messaging) {\n return null;\n }\n\n const unsubscribePushNotifications = onBackgroundMessage(\n messaging,\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (payload: MessagePayload) => {\n try {\n const data: Types.UnprocessedOnChainRawNotification | undefined =\n payload?.data?.data ? JSON.parse(payload?.data?.data) : undefined;\n\n if (!data) {\n return;\n }\n\n const notificationData = toRawOnChainNotification(data);\n const notification = Processors.processNotification(notificationData);\n await handler(notification);\n } catch (error) {\n // Do Nothing, cannot parse a bad notification\n log.error('Unable to send push notification:', {\n notification: payload?.data?.data,\n error,\n });\n throw new Error('Unable to send push notification');\n }\n },\n );\n\n const unsubscribe = () => unsubscribePushNotifications();\n return unsubscribe;\n}\n\n/**\n * Service Worker Listener for when a notification is clicked\n *\n * @param handler - listen to NotificationEvent from the service worker\n * @returns unsubscribe handler\n */\nexport function listenToPushNotificationsClicked(\n handler: (e: NotificationEvent, notification?: Types.INotification) => void,\n) {\n const clickHandler = (event: NotificationEvent) => {\n // Get Data\n const data: Types.INotification = event?.notification?.data;\n handler(event, data);\n };\n\n self.addEventListener('notificationclick', clickHandler);\n const unsubscribe = () =>\n self.removeEventListener('notificationclick', clickHandler);\n return unsubscribe;\n}\n"]}
@@ -64,9 +64,7 @@ exports.getPushNotificationLinks = getPushNotificationLinks;
64
64
  async function updateLinksAPI(bearerToken, triggers, regTokens) {
65
65
  try {
66
66
  const body = {
67
- // eslint-disable-next-line @typescript-eslint/naming-convention
68
67
  trigger_ids: triggers,
69
- // eslint-disable-next-line @typescript-eslint/naming-convention
70
68
  registration_tokens: regTokens,
71
69
  };
72
70
  const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {
@@ -1 +1 @@
1
- {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA2B;AAI3B,2DAAyC;AAEzC,kDAGyB;AAiBzB;;;;;GAKG;AACI,KAAK,UAAU,wBAAwB,CAC5C,WAAmB;IAEnB,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,4BAA4B,EAAE;YACnE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YAChB,kBAAG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AM,CAAC;IAElE;;;;MAIE;IACF,MAAM,4BAA4B,GAAG,MAAM,IAAA,4CAAiC,EAC1E,GAAG,EACH,oBAAoB,CACrB,CAAC;IACF,MAAM,6BAA6B,GACjC,IAAA,2CAAgC,EAAC,mBAAmB,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,4BAA4B,EAAE,EAAE,CAAC;QACjC,6BAA6B,EAAE,CAAC;IAClC,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC;AAvBD,8DAuBC","sourcesContent":["import log from 'loglevel';\n\nimport type { Types } from '../../NotificationServicesController';\nimport type { PushNotificationEnv } from '../types';\nimport * as endpoints from './endpoints';\nimport type { CreateRegToken, DeleteRegToken } from './push';\nimport {\n listenToPushNotificationsClicked,\n listenToPushNotificationsReceived,\n} from './push/push-web';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n};\n\n/**\n * Links API Response Shape\n */\nexport type LinksResult = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n trigger_ids: string[];\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_tokens: RegToken[];\n};\n\n/**\n * Fetches push notification links from a remote endpoint using a BearerToken for authorization.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @returns A promise that resolves with the links result or null if an error occurs.\n */\nexport async function getPushNotificationLinks(\n bearerToken: string,\n): Promise<LinksResult | null> {\n try {\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n headers: { Authorization: `Bearer ${bearerToken}` },\n });\n if (!response.ok) {\n log.error('Failed to fetch the push notification links');\n throw new Error('Failed to fetch the push notification links');\n }\n return response.json() as Promise<LinksResult>;\n } catch (error) {\n log.error('Failed to fetch the push notification links', error);\n return null;\n }\n}\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @param triggers - An array of trigger identifiers.\n * @param regTokens - An array of registration tokens.\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n bearerToken: string,\n triggers: string[],\n regTokens: RegToken[],\n): Promise<boolean> {\n try {\n const body: LinksResult = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n trigger_ids: triggers,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_tokens: regTokens,\n };\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n });\n return response.status === 200;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Push Links\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n fcmToken?: string;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { bearerToken, triggers, env, createRegToken, platform, fcmToken } =\n params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n\n if (!notificationLinks) {\n return null;\n }\n\n const regToken = fcmToken ?? (await createRegToken(env).catch(() => null));\n if (!regToken) {\n return null;\n }\n\n const newRegTokens = new Set(notificationLinks.registration_tokens);\n newRegTokens.add({ token: regToken, platform });\n\n await updateLinksAPI(bearerToken, triggers, Array.from(newRegTokens));\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token and unlinking triggers.\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, bearerToken, triggers, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return false;\n }\n\n const filteredRegTokens = notificationLinks.registration_tokens.filter(\n (r) => r.token !== regToken,\n );\n\n const isTokenRemovedFromAPI = await updateLinksAPI(\n bearerToken,\n triggers,\n filteredRegTokens,\n );\n if (!isTokenRemovedFromAPI) {\n return false;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n\ntype UpdateTriggerPushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n\n // Push Un-registration\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Updates the triggers linked to push notifications for a given registration token.\n * If the provided registration token does not exist or is not in the current set of registration tokens,\n * a new registration token is created and used for the update.\n *\n * @param params - Update Push Params\n * @returns A promise that resolves with an object containing:\n * - isTriggersLinkedToPushNotifications: boolean indicating if the triggers were successfully updated.\n * - fcmToken: the new or existing Firebase Cloud Messaging token used for the update, if applicable.\n */\nexport async function updateTriggerPushNotifications(\n params: UpdateTriggerPushNotificationsParams,\n): Promise<{\n isTriggersLinkedToPushNotifications: boolean;\n fcmToken?: string | null;\n}> {\n const {\n bearerToken,\n regToken,\n triggers,\n createRegToken,\n platform,\n deleteRegToken,\n env,\n } = params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return { isTriggersLinkedToPushNotifications: false };\n }\n // Create new registration token if doesn't exist\n const hasRegToken = Boolean(\n regToken &&\n notificationLinks.registration_tokens.some((r) => r.token === regToken),\n );\n\n let newRegToken: string | null = null;\n if (!hasRegToken) {\n await deleteRegToken(env);\n newRegToken = await createRegToken(env);\n if (!newRegToken) {\n throw new Error('Failed to create a new registration token');\n }\n notificationLinks.registration_tokens.push({\n token: newRegToken,\n platform,\n });\n }\n\n const isTriggersLinkedToPushNotifications = await updateLinksAPI(\n bearerToken,\n triggers,\n notificationLinks.registration_tokens,\n );\n\n return {\n isTriggersLinkedToPushNotifications,\n fcmToken: newRegToken ?? null,\n };\n}\n\ntype ListenToPushNotificationsParams = {\n env: PushNotificationEnv;\n listenToPushReceived: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n listenToPushClicked: (\n event: NotificationEvent,\n notification?: Types.INotification,\n ) => void;\n};\n\n/**\n * Listens to push notifications and invokes the provided callback function with the received notification data.\n *\n * @param params - listen params\n * @returns A promise that resolves to an unsubscribe function to stop listening to push notifications.\n */\nexport async function listenToPushNotifications(\n params: ListenToPushNotificationsParams,\n): Promise<() => void> {\n const { env, listenToPushReceived, listenToPushClicked } = params;\n\n /*\n Push notifications require 2 listeners that need tracking (when creating and for tearing down):\n 1. handling receiving a push notification (and the content we want to display)\n 2. handling when a user clicks on a push notification\n */\n const unsubscribePushNotifications = await listenToPushNotificationsReceived(\n env,\n listenToPushReceived,\n );\n const unsubscribeNotificationClicks =\n listenToPushNotificationsClicked(listenToPushClicked);\n\n const unsubscribe = () => {\n unsubscribePushNotifications?.();\n unsubscribeNotificationClicks();\n };\n\n return unsubscribe;\n}\n"]}
1
+ {"version":3,"file":"services.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA2B;AAE3B,2DAAyC;AAEzC,kDAGyB;AAkBzB;;;;;GAKG;AACI,KAAK,UAAU,wBAAwB,CAC5C,WAAmB;IAEnB,IAAI;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,4BAA4B,EAAE;YACnE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;SACpD,CAAC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oB,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAC;IAElE;;;;MAIE;IACF,MAAM,4BAA4B,GAAG,MAAM,IAAA,4CAAiC,EAC1E,GAAG,EACH,oBAAoB,CACrB,CAAC;IACF,MAAM,6BAA6B,GACjC,IAAA,2CAAgC,EAAC,mBAAmB,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,4BAA4B,EAAE,EAAE,CAAC;QACjC,6BAA6B,EAAE,CAAC;IAClC,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC;AAvBD,8DAuBC","sourcesContent":["import log from 'loglevel';\n\nimport * as endpoints from './endpoints';\nimport type { CreateRegToken, DeleteRegToken } from './push';\nimport {\n listenToPushNotificationsClicked,\n listenToPushNotificationsReceived,\n} from './push/push-web';\nimport type { Types } from '../../NotificationServicesController';\nimport type { PushNotificationEnv } from '../types';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n};\n\n/**\n * Links API Response Shape\n */\nexport type LinksResult = {\n trigger_ids: string[];\n\n registration_tokens: RegToken[];\n};\n\n/**\n * Fetches push notification links from a remote endpoint using a BearerToken for authorization.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @returns A promise that resolves with the links result or null if an error occurs.\n */\nexport async function getPushNotificationLinks(\n bearerToken: string,\n): Promise<LinksResult | null> {\n try {\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n headers: { Authorization: `Bearer ${bearerToken}` },\n });\n if (!response.ok) {\n log.error('Failed to fetch the push notification links');\n throw new Error('Failed to fetch the push notification links');\n }\n return response.json() as Promise<LinksResult>;\n } catch (error) {\n log.error('Failed to fetch the push notification links', error);\n return null;\n }\n}\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @param triggers - An array of trigger identifiers.\n * @param regTokens - An array of registration tokens.\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n bearerToken: string,\n triggers: string[],\n regTokens: RegToken[],\n): Promise<boolean> {\n try {\n const body: LinksResult = {\n trigger_ids: triggers,\n registration_tokens: regTokens,\n };\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n });\n return response.status === 200;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Push Links\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n fcmToken?: string;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { bearerToken, triggers, env, createRegToken, platform, fcmToken } =\n params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n\n if (!notificationLinks) {\n return null;\n }\n\n const regToken = fcmToken ?? (await createRegToken(env).catch(() => null));\n if (!regToken) {\n return null;\n }\n\n const newRegTokens = new Set(notificationLinks.registration_tokens);\n newRegTokens.add({ token: regToken, platform });\n\n await updateLinksAPI(bearerToken, triggers, Array.from(newRegTokens));\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token and unlinking triggers.\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, bearerToken, triggers, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return false;\n }\n\n const filteredRegTokens = notificationLinks.registration_tokens.filter(\n (r) => r.token !== regToken,\n );\n\n const isTokenRemovedFromAPI = await updateLinksAPI(\n bearerToken,\n triggers,\n filteredRegTokens,\n );\n if (!isTokenRemovedFromAPI) {\n return false;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n\ntype UpdateTriggerPushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n\n // Push Un-registration\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Updates the triggers linked to push notifications for a given registration token.\n * If the provided registration token does not exist or is not in the current set of registration tokens,\n * a new registration token is created and used for the update.\n *\n * @param params - Update Push Params\n * @returns A promise that resolves with an object containing:\n * - isTriggersLinkedToPushNotifications: boolean indicating if the triggers were successfully updated.\n * - fcmToken: the new or existing Firebase Cloud Messaging token used for the update, if applicable.\n */\nexport async function updateTriggerPushNotifications(\n params: UpdateTriggerPushNotificationsParams,\n): Promise<{\n isTriggersLinkedToPushNotifications: boolean;\n fcmToken?: string | null;\n}> {\n const {\n bearerToken,\n regToken,\n triggers,\n createRegToken,\n platform,\n deleteRegToken,\n env,\n } = params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return { isTriggersLinkedToPushNotifications: false };\n }\n // Create new registration token if doesn't exist\n const hasRegToken = Boolean(\n regToken &&\n notificationLinks.registration_tokens.some((r) => r.token === regToken),\n );\n\n let newRegToken: string | null = null;\n if (!hasRegToken) {\n await deleteRegToken(env);\n newRegToken = await createRegToken(env);\n if (!newRegToken) {\n throw new Error('Failed to create a new registration token');\n }\n notificationLinks.registration_tokens.push({\n token: newRegToken,\n platform,\n });\n }\n\n const isTriggersLinkedToPushNotifications = await updateLinksAPI(\n bearerToken,\n triggers,\n notificationLinks.registration_tokens,\n );\n\n return {\n isTriggersLinkedToPushNotifications,\n fcmToken: newRegToken ?? null,\n };\n}\n\ntype ListenToPushNotificationsParams = {\n env: PushNotificationEnv;\n listenToPushReceived: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n listenToPushClicked: (\n event: NotificationEvent,\n notification?: Types.INotification,\n ) => void;\n};\n\n/**\n * Listens to push notifications and invokes the provided callback function with the received notification data.\n *\n * @param params - listen params\n * @returns A promise that resolves to an unsubscribe function to stop listening to push notifications.\n */\nexport async function listenToPushNotifications(\n params: ListenToPushNotificationsParams,\n): Promise<() => void> {\n const { env, listenToPushReceived, listenToPushClicked } = params;\n\n /*\n Push notifications require 2 listeners that need tracking (when creating and for tearing down):\n 1. handling receiving a push notification (and the content we want to display)\n 2. handling when a user clicks on a push notification\n */\n const unsubscribePushNotifications = await listenToPushNotificationsReceived(\n env,\n listenToPushReceived,\n );\n const unsubscribeNotificationClicks =\n listenToPushNotificationsClicked(listenToPushClicked);\n\n const unsubscribe = () => {\n unsubscribePushNotifications?.();\n unsubscribeNotificationClicks();\n };\n\n return unsubscribe;\n}\n"]}
@@ -1,6 +1,6 @@
1
+ import type { CreateRegToken, DeleteRegToken } from "./push/index.cjs";
1
2
  import type { Types } from "../../NotificationServicesController/index.cjs";
2
3
  import type { PushNotificationEnv } from "../types/index.cjs";
3
- import type { CreateRegToken, DeleteRegToken } from "./push/index.cjs";
4
4
  export type RegToken = {
5
5
  token: string;
6
6
  platform: 'extension' | 'mobile' | 'portfolio';
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,c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,CAgClB;AAED,KAAK,oCAAoC,GAAG;IAE1C,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IAGnB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAG/C,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,oCAAoC,GAC3C,OAAO,CAAC;IACT,mCAAmC,EAAE,OAAO,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC,CA4CD;AAED,KAAK,+BAA+B,GAAG;IACrC,GAAG,EAAE,mBAAmB,CAAC;IACzB,oBAAoB,EAAE,CACpB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,mBAAmB,EAAE,CACnB,KAAK,EAAE,iBAAiB,EACxB,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAC/B,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,IAAI,CAAC,CAqBrB"}
1
+ {"version":3,"file":"services.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,yBAAe;AAK7D,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AAEpD,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAA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IAGnB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAG/C,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,oCAAoC,GAC3C,OAAO,CAAC;IACT,mCAAmC,EAAE,OAAO,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC,CA4CD;AAED,KAAK,+BAA+B,GAAG;IACrC,GAAG,EAAE,mBAAmB,CAAC;IACzB,oBAAoB,EAAE,CACpB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,mBAAmB,EAAE,CACnB,KAAK,EAAE,iBAAiB,EACxB,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAC/B,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,IAAI,CAAC,CAqBrB"}
@@ -1,6 +1,6 @@
1
+ import type { CreateRegToken, DeleteRegToken } from "./push/index.mjs";
1
2
  import type { Types } from "../../NotificationServicesController/index.mjs";
2
3
  import type { PushNotificationEnv } from "../types/index.mjs";
3
- import type { CreateRegToken, DeleteRegToken } from "./push/index.mjs";
4
4
  export type RegToken = {
5
5
  token: string;
6
6
  platform: 'extension' | 'mobile' | 'portfolio';
@@ -1 +1 @@
1
- {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AAEpD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,y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,KAAK,oCAAoC,GAAG;IAE1C,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;IAGnB,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAG/C,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,oCAAoC,GAC3C,OAAO,CAAC;IACT,mCAAmC,EAAE,OAAO,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC,CA4CD;AAED,KAAK,+BAA+B,GAAG;IACrC,GAAG,EAAE,mBAAmB,CAAC;IACzB,oBAAoB,EAAE,CACpB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,mBAAmB,EAAE,CACnB,KAAK,EAAE,iBAAiB,EACxB,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAC/B,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,IAAI,CAAC,CAqBrB"}
1
+ {"version":3,"file":"services.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,yBAAe;AAK7D,OAAO,KAAK,EAAE,KAAK,EAAE,uDAA6C;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AAEpD,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;CAChD,CAA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,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;IAG/C,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,8BAA8B,CAClD,MAAM,EAAE,oCAAoC,GAC3C,OAAO,CAAC;IACT,mCAAmC,EAAE,OAAO,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC,CA4CD;AAED,KAAK,+BAA+B,GAAG;IACrC,GAAG,EAAE,mBAAmB,CAAC;IACzB,oBAAoB,EAAE,CACpB,YAAY,EAAE,KAAK,CAAC,aAAa,KAC9B,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,mBAAmB,EAAE,CACnB,KAAK,EAAE,iBAAiB,EACxB,YAAY,CAAC,EAAE,KAAK,CAAC,aAAa,KAC/B,IAAI,CAAC;CACX,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,+BAA+B,GACtC,OAAO,CAAC,MAAM,IAAI,CAAC,CAqBrB"}
@@ -41,9 +41,7 @@ export async function getPushNotificationLinks(bearerToken) {
41
41
  export async function updateLinksAPI(bearerToken, triggers, regTokens) {
42
42
  try {
43
43
  const body = {
44
- // eslint-disable-next-line @typescript-eslint/naming-convention
45
44
  trigger_ids: triggers,
46
- // eslint-disable-next-line @typescript-eslint/naming-convention
47
45
  registration_tokens: regTokens,
48
46
  };
49
47
  const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {
@@ -1 +1 @@
1
- {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAI3B,OAAO,KAAK,SAAS,wBAAoB;AAEzC,OAAO,EACL,gCAAgC,EAChC,iCAAiC,EAClC,4BA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AQ,EACR,iBAAiB,CAAC,mBAAmB,CACtC,CAAC;IAEF,OAAO;QACL,mCAAmC;QACnC,QAAQ,EAAE,WAAW,IAAI,IAAI;KAC9B,CAAC;AACJ,CAAC;AAaD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,MAAuC;IAEvC,MAAM,EAAE,GAAG,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAC;IAElE;;;;MAIE;IACF,MAAM,4BAA4B,GAAG,MAAM,iCAAiC,CAC1E,GAAG,EACH,oBAAoB,CACrB,CAAC;IACF,MAAM,6BAA6B,GACjC,gCAAgC,CAAC,mBAAmB,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,4BAA4B,EAAE,EAAE,CAAC;QACjC,6BAA6B,EAAE,CAAC;IAClC,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport type { Types } from '../../NotificationServicesController';\nimport type { PushNotificationEnv } from '../types';\nimport * as endpoints from './endpoints';\nimport type { CreateRegToken, DeleteRegToken } from './push';\nimport {\n listenToPushNotificationsClicked,\n listenToPushNotificationsReceived,\n} from './push/push-web';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n};\n\n/**\n * Links API Response Shape\n */\nexport type LinksResult = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n trigger_ids: string[];\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_tokens: RegToken[];\n};\n\n/**\n * Fetches push notification links from a remote endpoint using a BearerToken for authorization.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @returns A promise that resolves with the links result or null if an error occurs.\n */\nexport async function getPushNotificationLinks(\n bearerToken: string,\n): Promise<LinksResult | null> {\n try {\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n headers: { Authorization: `Bearer ${bearerToken}` },\n });\n if (!response.ok) {\n log.error('Failed to fetch the push notification links');\n throw new Error('Failed to fetch the push notification links');\n }\n return response.json() as Promise<LinksResult>;\n } catch (error) {\n log.error('Failed to fetch the push notification links', error);\n return null;\n }\n}\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @param triggers - An array of trigger identifiers.\n * @param regTokens - An array of registration tokens.\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n bearerToken: string,\n triggers: string[],\n regTokens: RegToken[],\n): Promise<boolean> {\n try {\n const body: LinksResult = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n trigger_ids: triggers,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n registration_tokens: regTokens,\n };\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n });\n return response.status === 200;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Push Links\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n fcmToken?: string;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { bearerToken, triggers, env, createRegToken, platform, fcmToken } =\n params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n\n if (!notificationLinks) {\n return null;\n }\n\n const regToken = fcmToken ?? (await createRegToken(env).catch(() => null));\n if (!regToken) {\n return null;\n }\n\n const newRegTokens = new Set(notificationLinks.registration_tokens);\n newRegTokens.add({ token: regToken, platform });\n\n await updateLinksAPI(bearerToken, triggers, Array.from(newRegTokens));\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token and unlinking triggers.\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, bearerToken, triggers, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return false;\n }\n\n const filteredRegTokens = notificationLinks.registration_tokens.filter(\n (r) => r.token !== regToken,\n );\n\n const isTokenRemovedFromAPI = await updateLinksAPI(\n bearerToken,\n triggers,\n filteredRegTokens,\n );\n if (!isTokenRemovedFromAPI) {\n return false;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n\ntype UpdateTriggerPushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n\n // Push Un-registration\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Updates the triggers linked to push notifications for a given registration token.\n * If the provided registration token does not exist or is not in the current set of registration tokens,\n * a new registration token is created and used for the update.\n *\n * @param params - Update Push Params\n * @returns A promise that resolves with an object containing:\n * - isTriggersLinkedToPushNotifications: boolean indicating if the triggers were successfully updated.\n * - fcmToken: the new or existing Firebase Cloud Messaging token used for the update, if applicable.\n */\nexport async function updateTriggerPushNotifications(\n params: UpdateTriggerPushNotificationsParams,\n): Promise<{\n isTriggersLinkedToPushNotifications: boolean;\n fcmToken?: string | null;\n}> {\n const {\n bearerToken,\n regToken,\n triggers,\n createRegToken,\n platform,\n deleteRegToken,\n env,\n } = params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return { isTriggersLinkedToPushNotifications: false };\n }\n // Create new registration token if doesn't exist\n const hasRegToken = Boolean(\n regToken &&\n notificationLinks.registration_tokens.some((r) => r.token === regToken),\n );\n\n let newRegToken: string | null = null;\n if (!hasRegToken) {\n await deleteRegToken(env);\n newRegToken = await createRegToken(env);\n if (!newRegToken) {\n throw new Error('Failed to create a new registration token');\n }\n notificationLinks.registration_tokens.push({\n token: newRegToken,\n platform,\n });\n }\n\n const isTriggersLinkedToPushNotifications = await updateLinksAPI(\n bearerToken,\n triggers,\n notificationLinks.registration_tokens,\n );\n\n return {\n isTriggersLinkedToPushNotifications,\n fcmToken: newRegToken ?? null,\n };\n}\n\ntype ListenToPushNotificationsParams = {\n env: PushNotificationEnv;\n listenToPushReceived: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n listenToPushClicked: (\n event: NotificationEvent,\n notification?: Types.INotification,\n ) => void;\n};\n\n/**\n * Listens to push notifications and invokes the provided callback function with the received notification data.\n *\n * @param params - listen params\n * @returns A promise that resolves to an unsubscribe function to stop listening to push notifications.\n */\nexport async function listenToPushNotifications(\n params: ListenToPushNotificationsParams,\n): Promise<() => void> {\n const { env, listenToPushReceived, listenToPushClicked } = params;\n\n /*\n Push notifications require 2 listeners that need tracking (when creating and for tearing down):\n 1. handling receiving a push notification (and the content we want to display)\n 2. handling when a user clicks on a push notification\n */\n const unsubscribePushNotifications = await listenToPushNotificationsReceived(\n env,\n listenToPushReceived,\n );\n const unsubscribeNotificationClicks =\n listenToPushNotificationsClicked(listenToPushClicked);\n\n const unsubscribe = () => {\n unsubscribePushNotifications?.();\n unsubscribeNotificationClicks();\n };\n\n return unsubscribe;\n}\n"]}
1
+ {"version":3,"file":"services.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/services/services.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,KA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,GAAG,MAAM,cAAc,CAC9D,WAAW,EACX,QAAQ,EACR,iBAAiB,CAAC,mBAAmB,CACtC,CAAC;IAEF,OAAO;QACL,mCAAmC;QACnC,QAAQ,EAAE,WAAW,IAAI,IAAI;KAC9B,CAAC;AACJ,CAAC;AAaD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC7C,MAAuC;IAEvC,MAAM,EAAE,GAAG,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAC;IAElE;;;;MAIE;IACF,MAAM,4BAA4B,GAAG,MAAM,iCAAiC,CAC1E,GAAG,EACH,oBAAoB,CACrB,CAAC;IACF,MAAM,6BAA6B,GACjC,gCAAgC,CAAC,mBAAmB,CAAC,CAAC;IAExD,MAAM,WAAW,GAAG,GAAG,EAAE;QACvB,4BAA4B,EAAE,EAAE,CAAC;QACjC,6BAA6B,EAAE,CAAC;IAClC,CAAC,CAAC;IAEF,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport * as endpoints from './endpoints';\nimport type { CreateRegToken, DeleteRegToken } from './push';\nimport {\n listenToPushNotificationsClicked,\n listenToPushNotificationsReceived,\n} from './push/push-web';\nimport type { Types } from '../../NotificationServicesController';\nimport type { PushNotificationEnv } from '../types';\n\nexport type RegToken = {\n token: string;\n platform: 'extension' | 'mobile' | 'portfolio';\n};\n\n/**\n * Links API Response Shape\n */\nexport type LinksResult = {\n trigger_ids: string[];\n\n registration_tokens: RegToken[];\n};\n\n/**\n * Fetches push notification links from a remote endpoint using a BearerToken for authorization.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @returns A promise that resolves with the links result or null if an error occurs.\n */\nexport async function getPushNotificationLinks(\n bearerToken: string,\n): Promise<LinksResult | null> {\n try {\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n headers: { Authorization: `Bearer ${bearerToken}` },\n });\n if (!response.ok) {\n log.error('Failed to fetch the push notification links');\n throw new Error('Failed to fetch the push notification links');\n }\n return response.json() as Promise<LinksResult>;\n } catch (error) {\n log.error('Failed to fetch the push notification links', error);\n return null;\n }\n}\n\n/**\n * Updates the push notification links on a remote API.\n *\n * @param bearerToken - The JSON Web Token used for authorization.\n * @param triggers - An array of trigger identifiers.\n * @param regTokens - An array of registration tokens.\n * @returns A promise that resolves with true if the update was successful, false otherwise.\n */\nexport async function updateLinksAPI(\n bearerToken: string,\n triggers: string[],\n regTokens: RegToken[],\n): Promise<boolean> {\n try {\n const body: LinksResult = {\n trigger_ids: triggers,\n registration_tokens: regTokens,\n };\n const response = await fetch(endpoints.REGISTRATION_TOKENS_ENDPOINT, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${bearerToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify(body),\n });\n return response.status === 200;\n } catch {\n return false;\n }\n}\n\ntype ActivatePushNotificationsParams = {\n // Push Links\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n fcmToken?: string;\n};\n\n/**\n * Enables push notifications by registering the device and linking triggers.\n *\n * @param params - Activate Push Params\n * @returns A promise that resolves with an object containing the success status and the BearerToken token.\n */\nexport async function activatePushNotifications(\n params: ActivatePushNotificationsParams,\n): Promise<string | null> {\n const { bearerToken, triggers, env, createRegToken, platform, fcmToken } =\n params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n\n if (!notificationLinks) {\n return null;\n }\n\n const regToken = fcmToken ?? (await createRegToken(env).catch(() => null));\n if (!regToken) {\n return null;\n }\n\n const newRegTokens = new Set(notificationLinks.registration_tokens);\n newRegTokens.add({ token: regToken, platform });\n\n await updateLinksAPI(bearerToken, triggers, Array.from(newRegTokens));\n return regToken;\n}\n\ntype DeactivatePushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Un-registration\n env: PushNotificationEnv;\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Disables push notifications by removing the registration token and unlinking triggers.\n *\n * @param params - Deactivate Push Params\n * @returns A promise that resolves with true if notifications were successfully disabled, false otherwise.\n */\nexport async function deactivatePushNotifications(\n params: DeactivatePushNotificationsParams,\n): Promise<boolean> {\n const { regToken, bearerToken, triggers, env, deleteRegToken } = params;\n\n // if we don't have a reg token, then we can early return\n if (!regToken) {\n return true;\n }\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return false;\n }\n\n const filteredRegTokens = notificationLinks.registration_tokens.filter(\n (r) => r.token !== regToken,\n );\n\n const isTokenRemovedFromAPI = await updateLinksAPI(\n bearerToken,\n triggers,\n filteredRegTokens,\n );\n if (!isTokenRemovedFromAPI) {\n return false;\n }\n\n const isTokenRemovedFromFCM = await deleteRegToken(env);\n if (!isTokenRemovedFromFCM) {\n return false;\n }\n\n return true;\n}\n\ntype UpdateTriggerPushNotificationsParams = {\n // Push Links\n regToken: string;\n bearerToken: string;\n triggers: string[];\n\n // Push Registration\n env: PushNotificationEnv;\n createRegToken: CreateRegToken;\n platform: 'extension' | 'mobile' | 'portfolio';\n\n // Push Un-registration\n deleteRegToken: DeleteRegToken;\n};\n\n/**\n * Updates the triggers linked to push notifications for a given registration token.\n * If the provided registration token does not exist or is not in the current set of registration tokens,\n * a new registration token is created and used for the update.\n *\n * @param params - Update Push Params\n * @returns A promise that resolves with an object containing:\n * - isTriggersLinkedToPushNotifications: boolean indicating if the triggers were successfully updated.\n * - fcmToken: the new or existing Firebase Cloud Messaging token used for the update, if applicable.\n */\nexport async function updateTriggerPushNotifications(\n params: UpdateTriggerPushNotificationsParams,\n): Promise<{\n isTriggersLinkedToPushNotifications: boolean;\n fcmToken?: string | null;\n}> {\n const {\n bearerToken,\n regToken,\n triggers,\n createRegToken,\n platform,\n deleteRegToken,\n env,\n } = params;\n\n const notificationLinks = await getPushNotificationLinks(bearerToken);\n if (!notificationLinks) {\n return { isTriggersLinkedToPushNotifications: false };\n }\n // Create new registration token if doesn't exist\n const hasRegToken = Boolean(\n regToken &&\n notificationLinks.registration_tokens.some((r) => r.token === regToken),\n );\n\n let newRegToken: string | null = null;\n if (!hasRegToken) {\n await deleteRegToken(env);\n newRegToken = await createRegToken(env);\n if (!newRegToken) {\n throw new Error('Failed to create a new registration token');\n }\n notificationLinks.registration_tokens.push({\n token: newRegToken,\n platform,\n });\n }\n\n const isTriggersLinkedToPushNotifications = await updateLinksAPI(\n bearerToken,\n triggers,\n notificationLinks.registration_tokens,\n );\n\n return {\n isTriggersLinkedToPushNotifications,\n fcmToken: newRegToken ?? null,\n };\n}\n\ntype ListenToPushNotificationsParams = {\n env: PushNotificationEnv;\n listenToPushReceived: (\n notification: Types.INotification,\n ) => void | Promise<void>;\n listenToPushClicked: (\n event: NotificationEvent,\n notification?: Types.INotification,\n ) => void;\n};\n\n/**\n * Listens to push notifications and invokes the provided callback function with the received notification data.\n *\n * @param params - listen params\n * @returns A promise that resolves to an unsubscribe function to stop listening to push notifications.\n */\nexport async function listenToPushNotifications(\n params: ListenToPushNotificationsParams,\n): Promise<() => void> {\n const { env, listenToPushReceived, listenToPushClicked } = params;\n\n /*\n Push notifications require 2 listeners that need tracking (when creating and for tearing down):\n 1. handling receiving a push notification (and the content we want to display)\n 2. handling when a user clicks on a push notification\n */\n const unsubscribePushNotifications = await listenToPushNotificationsReceived(\n env,\n listenToPushReceived,\n );\n const unsubscribeNotificationClicks =\n listenToPushNotificationsClicked(listenToPushClicked);\n\n const unsubscribe = () => {\n unsubscribePushNotifications?.();\n unsubscribeNotificationClicks();\n };\n\n return unsubscribe;\n}\n"]}
@@ -1,18 +1,3 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./firebase.cjs"), exports);
18
3
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA2B","sourcesContent":["export * from './firebase';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export type * from './firebase';\n"]}
@@ -1,2 +1,2 @@
1
- export * from "./firebase.cjs";
1
+ export type * from "./firebase.cjs";
2
2
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,+BAA2B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,oCAAgC"}
@@ -1,2 +1,2 @@
1
- export * from "./firebase.mjs";
1
+ export type * from "./firebase.mjs";
2
2
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,+BAA2B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,oCAAgC"}
@@ -1,2 +1,2 @@
1
- export * from "./firebase.mjs";
1
+ export {};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"AAAA,+BAA2B","sourcesContent":["export * from './firebase';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/types/index.ts"],"names":[],"mappings":"","sourcesContent":["export type * from './firebase';\n"]}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createOnChainPushNotificationMessage = exports.isOnChainNotification = exports.createOnChainPushNotificationMessages = void 0;
4
- const NotificationServicesController_1 = require("../../NotificationServicesController/index.cjs");
5
4
  const get_notification_data_1 = require("./get-notification-data.cjs");
5
+ const NotificationServicesController_1 = require("../../NotificationServicesController/index.cjs");
6
6
  /**
7
7
  * On Chain Push Notification Messages.
8
8
  * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension
@@ -178,7 +178,7 @@ function createOnChainPushNotificationMessage(n, translations) {
178
178
  notificationMessage.defaultDescription ??
179
179
  null;
180
180
  }
181
- catch (e) {
181
+ catch {
182
182
  description = notificationMessage.defaultDescription ?? null;
183
183
  }
184
184
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"get-notification-message.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":";;;AAEA,mGAAiE;AACjE,uEAAkE;AAkDlE;;;;;;GAMG;AACI,MAAM,qCAAqC,GAAG,CACnD,eAAgC,EACP,EAAE;IAI3B,MAAM,CAAC,GAAkB,CAAC,GAAG,IAAI,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;QAEjC,4CAA4C;QAC5C,8DAA8D;QAC9D,MAAM,EAAE,GAAQ,eAAe,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,EAAE,CAAC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BAAmB,CAAC,KAAK,IAAI,EAAE;QACtC,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC;AA7BD,oFA6BC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport type { Types } from '../../NotificationServicesController';\nimport { Constants } from '../../NotificationServicesController';\nimport { getAmount, formatAmount } from './get-notification-data';\n\nexport type TranslationKeys = {\n pushPlatformNotificationsFundsSentTitle: () => string;\n pushPlatformNotificationsFundsSentDescriptionDefault: () => string;\n pushPlatformNotificationsFundsSentDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsFundsReceivedTitle: () => string;\n pushPlatformNotificationsFundsReceivedDescriptionDefault: () => string;\n pushPlatformNotificationsFundsReceivedDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsSwapCompletedTitle: () => string;\n pushPlatformNotificationsSwapCompletedDescription: () => string;\n pushPlatformNotificationsNftSentTitle: () => string;\n pushPlatformNotificationsNftSentDescription: () => string;\n pushPlatformNotificationsNftReceivedTitle: () => string;\n pushPlatformNotificationsNftReceivedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () => string;\n};\n\ntype PushNotificationMessage = {\n title: string;\n description: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: string | null;\n defaultDescription: string | null;\n getDescription?: (n: N) => string | null;\n};\n\ntype NotificationMessageDict = {\n [K in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: K }>\n >;\n};\n\n/**\n * On Chain Push Notification Messages.\n * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension\n *\n * @param translationKeys - all translations supported\n * @returns A translation push message object.\n */\nexport const createOnChainPushNotificationMessages = (\n translationKeys: TranslationKeys,\n): NotificationMessageDict => {\n type TranslationFn = <K extends keyof TranslationKeys>(\n ...args: [K, ...Parameters<TranslationKeys[K]>]\n ) => string;\n const t: TranslationFn = (...args) => {\n const [key, ...otherArgs] = args;\n\n // Coerce types for the translation function\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const fn: any = translationKeys[key];\n return fn(...otherArgs);\n };\n\n return {\n erc20_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: t('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsSwapCompletedDescription',\n ),\n },\n erc721_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n };\n};\n\n/**\n * Retrieves the symbol associated with a given chain ID.\n *\n * @param chainId - The ID of the chain.\n * @returns The symbol associated with the chain ID, or null if not found.\n */\nfunction getChainSymbol(chainId: number) {\n return Constants.CHAIN_SYMBOLS[chainId] ?? null;\n}\n\n/**\n * Checks if the given value is an OnChainRawNotification object.\n *\n * @param n - The value to check.\n * @returns True if the value is an OnChainRawNotification object, false otherwise.\n */\nexport function isOnChainNotification(\n n: unknown,\n): n is Types.OnChainRawNotification {\n const assumed = n as Types.OnChainRawNotification;\n\n // We don't have a validation/parsing library to check all possible types of an on chain notification\n // It is safe enough just to check \"some\" fields, and catch any errors down the line if the shape is bad.\n const isValidEnoughToBeOnChainNotification = [\n assumed?.id,\n assumed?.data,\n assumed?.trigger_id,\n ].every((field) => field !== undefined);\n return isValidEnoughToBeOnChainNotification;\n}\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param n - processed notification.\n * @param translations - translates keys into text\n * @returns The push notification message object, or null if the notification is invalid.\n */\nexport function createOnChainPushNotificationMessage(\n n: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!n?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[n.type];\n\n if (!notificationMessage) {\n return null;\n }\n\n let description: string | null = null;\n try {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage?.getDescription?.(n as any) ??\n notificationMessage.defaultDescription ??\n null;\n } catch (e) {\n description = notificationMessage.defaultDescription ?? null;\n }\n\n return {\n title: notificationMessage.title ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}
1
+ {"version":3,"file":"get-notification-message.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesPushController/utils/get-notification-message.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAElE,mGAAiE;AAkDjE;;;;;;GAMG;AACI,MAAM,qCAAqC,GAAG,CACnD,eAAgC,EACP,EAAE;IAI3B,MAAM,CAAC,GAAkB,CAAC,GAAG,IAAI,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC;QAEjC,4CAA4C;QAC5C,8DAA8D;QAC9D,MAAM,EAAE,GAAQ,eAAe,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC;IAC1B,CAAC,CAAC;IAEF,OAAO;QACL,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,CAAC,yCAAyC,CAAC;YACnD,kBAAkB,EAAE,CAAC,CACnB,sDAAsD,CACvD;YACD,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;gBACpB,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC;gBACtC,MAAM,WAAW,GAAG,CA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G;AACH,SAAgB,qBAAqB,CACnC,CAAU;IAEV,MAAM,OAAO,GAAG,CAAiC,CAAC;IAElD,qGAAqG;IACrG,yGAAyG;IACzG,MAAM,oCAAoC,GAAG;QAC3C,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,UAAU;KACpB,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC;IACxC,OAAO,oCAAoC,CAAC;AAC9C,CAAC;AAbD,sDAaC;AAED;;;;;;GAMG;AACH,SAAgB,oCAAoC,CAClD,CAAsB,EACtB,YAA6B;IAE7B,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IACD,MAAM,mBAAmB,GACvB,IAAA,6CAAqC,EAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAE9D,IAAI,CAAC,mBAAmB,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,IAAI,WAAW,GAAkB,IAAI,CAAC;IACtC,IAAI;QACF,WAAW;YACT,8DAA8D;YAC9D,mBAAmB,EAAE,cAAc,EAAE,CAAC,CAAQ,CAAC;gBAC/C,mBAAmB,CAAC,kBAAkB;gBACtC,IAAI,CAAC;KACR;IAAC,MAAM;QACN,WAAW,GAAG,mBAAmB,CAAC,kBAAkB,IAAI,IAAI,CAAC;KAC9D;IAED,OAAO;QACL,KAAK,EAAE,mBAAmB,CAAC,KAAK,IAAI,EAAE;QACtC,WAAW,EAAE,WAAW,IAAI,EAAE,EAAE,mCAAmC;KACpE,CAAC;AACJ,CAAC;AA7BD,oFA6BC","sourcesContent":["import { getAmount, formatAmount } from './get-notification-data';\nimport type { Types } from '../../NotificationServicesController';\nimport { Constants } from '../../NotificationServicesController';\n\nexport type TranslationKeys = {\n pushPlatformNotificationsFundsSentTitle: () => string;\n pushPlatformNotificationsFundsSentDescriptionDefault: () => string;\n pushPlatformNotificationsFundsSentDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsFundsReceivedTitle: () => string;\n pushPlatformNotificationsFundsReceivedDescriptionDefault: () => string;\n pushPlatformNotificationsFundsReceivedDescription: (\n ...args: [string, string]\n ) => string;\n pushPlatformNotificationsSwapCompletedTitle: () => string;\n pushPlatformNotificationsSwapCompletedDescription: () => string;\n pushPlatformNotificationsNftSentTitle: () => string;\n pushPlatformNotificationsNftSentDescription: () => string;\n pushPlatformNotificationsNftReceivedTitle: () => string;\n pushPlatformNotificationsNftReceivedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeCompletedDescription: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle: () => string;\n pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle: () => string;\n pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription: () => string;\n};\n\ntype PushNotificationMessage = {\n title: string;\n description: string;\n};\n\ntype NotificationMessage<N extends Types.INotification> = {\n title: string | null;\n defaultDescription: string | null;\n getDescription?: (n: N) => string | null;\n};\n\ntype NotificationMessageDict = {\n [K in Constants.TRIGGER_TYPES]?: NotificationMessage<\n Extract<Types.INotification, { type: K }>\n >;\n};\n\n/**\n * On Chain Push Notification Messages.\n * This is a list of all the push notifications we support. Update this for synced notifications on mobile and extension\n *\n * @param translationKeys - all translations supported\n * @returns A translation push message object.\n */\nexport const createOnChainPushNotificationMessages = (\n translationKeys: TranslationKeys,\n): NotificationMessageDict => {\n type TranslationFn = <K extends keyof TranslationKeys>(\n ...args: [K, ...Parameters<TranslationKeys[K]>]\n ) => string;\n const t: TranslationFn = (...args) => {\n const [key, ...otherArgs] = args;\n\n // Coerce types for the translation function\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const fn: any = translationKeys[key];\n return fn(...otherArgs);\n };\n\n return {\n erc20_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n eth_sent: {\n title: t('pushPlatformNotificationsFundsSentTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsSentDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsSentDescription',\n amount,\n symbol,\n );\n },\n },\n erc20_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = n?.data?.token?.symbol;\n const tokenAmount = n?.data?.token?.amount;\n const tokenDecimals = n?.data?.token?.decimals;\n if (!symbol || !tokenAmount || !tokenDecimals) {\n return null;\n }\n\n const amount = getAmount(tokenAmount, tokenDecimals, {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n eth_received: {\n title: t('pushPlatformNotificationsFundsReceivedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsFundsReceivedDescriptionDefault',\n ),\n getDescription: (n) => {\n const symbol = getChainSymbol(n?.chain_id);\n const tokenAmount = n?.data?.amount?.eth;\n if (!symbol || !tokenAmount) {\n return null;\n }\n\n const amount = formatAmount(parseFloat(tokenAmount), {\n shouldEllipse: true,\n });\n return t(\n 'pushPlatformNotificationsFundsReceivedDescription',\n amount,\n symbol,\n );\n },\n },\n metamask_swap_completed: {\n title: t('pushPlatformNotificationsSwapCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsSwapCompletedDescription',\n ),\n },\n erc721_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc1155_sent: {\n title: t('pushPlatformNotificationsNftSentTitle'),\n defaultDescription: t('pushPlatformNotificationsNftSentDescription'),\n },\n erc721_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n erc1155_received: {\n title: t('pushPlatformNotificationsNftReceivedTitle'),\n defaultDescription: t('pushPlatformNotificationsNftReceivedDescription'),\n },\n rocketpool_stake_completed: {\n title: t('pushPlatformNotificationsStakingRocketpoolStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolStakeCompletedDescription',\n ),\n },\n rocketpool_unstake_completed: {\n title: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingRocketpoolUnstakeCompletedDescription',\n ),\n },\n lido_stake_completed: {\n title: t('pushPlatformNotificationsStakingLidoStakeCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeCompletedDescription',\n ),\n },\n lido_stake_ready_to_be_withdrawn: {\n title: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnTitle',\n ),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoStakeReadyToBeWithdrawnDescription',\n ),\n },\n lido_withdrawal_requested: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalRequestedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalRequestedDescription',\n ),\n },\n lido_withdrawal_completed: {\n title: t('pushPlatformNotificationsStakingLidoWithdrawalCompletedTitle'),\n defaultDescription: t(\n 'pushPlatformNotificationsStakingLidoWithdrawalCompletedDescription',\n ),\n },\n };\n};\n\n/**\n * Retrieves the symbol associated with a given chain ID.\n *\n * @param chainId - The ID of the chain.\n * @returns The symbol associated with the chain ID, or null if not found.\n */\nfunction getChainSymbol(chainId: number) {\n return Constants.CHAIN_SYMBOLS[chainId] ?? null;\n}\n\n/**\n * Checks if the given value is an OnChainRawNotification object.\n *\n * @param n - The value to check.\n * @returns True if the value is an OnChainRawNotification object, false otherwise.\n */\nexport function isOnChainNotification(\n n: unknown,\n): n is Types.OnChainRawNotification {\n const assumed = n as Types.OnChainRawNotification;\n\n // We don't have a validation/parsing library to check all possible types of an on chain notification\n // It is safe enough just to check \"some\" fields, and catch any errors down the line if the shape is bad.\n const isValidEnoughToBeOnChainNotification = [\n assumed?.id,\n assumed?.data,\n assumed?.trigger_id,\n ].every((field) => field !== undefined);\n return isValidEnoughToBeOnChainNotification;\n}\n\n/**\n * Creates a push notification message based on the given on-chain raw notification.\n *\n * @param n - processed notification.\n * @param translations - translates keys into text\n * @returns The push notification message object, or null if the notification is invalid.\n */\nexport function createOnChainPushNotificationMessage(\n n: Types.INotification,\n translations: TranslationKeys,\n): PushNotificationMessage | null {\n if (!n?.type) {\n return null;\n }\n const notificationMessage =\n createOnChainPushNotificationMessages(translations)[n.type];\n\n if (!notificationMessage) {\n return null;\n }\n\n let description: string | null = null;\n try {\n description =\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n notificationMessage?.getDescription?.(n as any) ??\n notificationMessage.defaultDescription ??\n null;\n } catch {\n description = notificationMessage.defaultDescription ?? null;\n }\n\n return {\n title: notificationMessage.title ?? '', // Ensure title is always a string\n description: description ?? '', // Fallback to empty string if null\n };\n}\n"]}