@metamask-previews/notification-services-controller 24.1.2-preview-ecd6b75 → 24.1.2-preview-81b5f29eb

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 (92) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/NotificationServicesController/NotificationServicesController.cjs +4 -2
  3. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  5. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController.mjs +4 -2
  7. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  8. package/dist/NotificationServicesController/index.cjs +3 -1
  9. package/dist/NotificationServicesController/index.cjs.map +1 -1
  10. package/dist/NotificationServicesController/index.d.cts +1 -0
  11. package/dist/NotificationServicesController/index.d.cts.map +1 -1
  12. package/dist/NotificationServicesController/index.d.mts +1 -0
  13. package/dist/NotificationServicesController/index.d.mts.map +1 -1
  14. package/dist/NotificationServicesController/index.mjs +1 -0
  15. package/dist/NotificationServicesController/index.mjs.map +1 -1
  16. package/dist/NotificationServicesController/processors/process-api-notifications.cjs +2 -0
  17. package/dist/NotificationServicesController/processors/process-api-notifications.cjs.map +1 -1
  18. package/dist/NotificationServicesController/processors/process-api-notifications.d.cts.map +1 -1
  19. package/dist/NotificationServicesController/processors/process-api-notifications.d.mts.map +1 -1
  20. package/dist/NotificationServicesController/processors/process-api-notifications.mjs +2 -0
  21. package/dist/NotificationServicesController/processors/process-api-notifications.mjs.map +1 -1
  22. package/dist/NotificationServicesController/processors/process-feature-announcement.cjs +2 -0
  23. package/dist/NotificationServicesController/processors/process-feature-announcement.cjs.map +1 -1
  24. package/dist/NotificationServicesController/processors/process-feature-announcement.d.cts.map +1 -1
  25. package/dist/NotificationServicesController/processors/process-feature-announcement.d.mts.map +1 -1
  26. package/dist/NotificationServicesController/processors/process-feature-announcement.mjs +2 -0
  27. package/dist/NotificationServicesController/processors/process-feature-announcement.mjs.map +1 -1
  28. package/dist/NotificationServicesController/processors/process-snap-notifications.cjs +2 -0
  29. package/dist/NotificationServicesController/processors/process-snap-notifications.cjs.map +1 -1
  30. package/dist/NotificationServicesController/processors/process-snap-notifications.d.cts.map +1 -1
  31. package/dist/NotificationServicesController/processors/process-snap-notifications.d.mts.map +1 -1
  32. package/dist/NotificationServicesController/processors/process-snap-notifications.mjs +2 -0
  33. package/dist/NotificationServicesController/processors/process-snap-notifications.mjs.map +1 -1
  34. package/dist/NotificationServicesController/types/notification/notification.cjs.map +1 -1
  35. package/dist/NotificationServicesController/types/notification/notification.d.cts +1 -0
  36. package/dist/NotificationServicesController/types/notification/notification.d.cts.map +1 -1
  37. package/dist/NotificationServicesController/types/notification/notification.d.mts +1 -0
  38. package/dist/NotificationServicesController/types/notification/notification.d.mts.map +1 -1
  39. package/dist/NotificationServicesController/types/notification/notification.mjs.map +1 -1
  40. package/dist/NotificationServicesController/utils/get-notification-subtype.cjs +49 -0
  41. package/dist/NotificationServicesController/utils/get-notification-subtype.cjs.map +1 -0
  42. package/dist/NotificationServicesController/utils/get-notification-subtype.d.cts +22 -0
  43. package/dist/NotificationServicesController/utils/get-notification-subtype.d.cts.map +1 -0
  44. package/dist/NotificationServicesController/utils/get-notification-subtype.d.mts +22 -0
  45. package/dist/NotificationServicesController/utils/get-notification-subtype.d.mts.map +1 -0
  46. package/dist/NotificationServicesController/utils/get-notification-subtype.mjs +45 -0
  47. package/dist/NotificationServicesController/utils/get-notification-subtype.mjs.map +1 -0
  48. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  49. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +3 -4
  50. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  51. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +3 -4
  52. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  53. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  54. package/dist/NotificationServicesPushController/types/index.cjs.map +1 -1
  55. package/dist/NotificationServicesPushController/types/index.d.cts +1 -0
  56. package/dist/NotificationServicesPushController/types/index.d.cts.map +1 -1
  57. package/dist/NotificationServicesPushController/types/index.d.mts +1 -0
  58. package/dist/NotificationServicesPushController/types/index.d.mts.map +1 -1
  59. package/dist/NotificationServicesPushController/types/index.mjs.map +1 -1
  60. package/dist/NotificationServicesPushController/types/push-analytics.cjs +5 -0
  61. package/dist/NotificationServicesPushController/types/push-analytics.cjs.map +1 -0
  62. package/dist/NotificationServicesPushController/types/push-analytics.d.cts +20 -0
  63. package/dist/NotificationServicesPushController/types/push-analytics.d.cts.map +1 -0
  64. package/dist/NotificationServicesPushController/types/push-analytics.d.mts +20 -0
  65. package/dist/NotificationServicesPushController/types/push-analytics.d.mts.map +1 -0
  66. package/dist/NotificationServicesPushController/types/push-analytics.mjs +4 -0
  67. package/dist/NotificationServicesPushController/types/push-analytics.mjs.map +1 -0
  68. package/dist/NotificationServicesPushController/utils/index.cjs +1 -0
  69. package/dist/NotificationServicesPushController/utils/index.cjs.map +1 -1
  70. package/dist/NotificationServicesPushController/utils/index.d.cts +1 -0
  71. package/dist/NotificationServicesPushController/utils/index.d.cts.map +1 -1
  72. package/dist/NotificationServicesPushController/utils/index.d.mts +1 -0
  73. package/dist/NotificationServicesPushController/utils/index.d.mts.map +1 -1
  74. package/dist/NotificationServicesPushController/utils/index.mjs +1 -0
  75. package/dist/NotificationServicesPushController/utils/index.mjs.map +1 -1
  76. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.cjs +27 -0
  77. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.cjs.map +1 -0
  78. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.d.cts +12 -0
  79. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.d.cts.map +1 -0
  80. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.d.mts +12 -0
  81. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.d.mts.map +1 -0
  82. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.mjs +23 -0
  83. package/dist/NotificationServicesPushController/utils/to-push-analytics-payload.mjs.map +1 -0
  84. package/dist/NotificationServicesPushController/web/push-utils.cjs +13 -25
  85. package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -1
  86. package/dist/NotificationServicesPushController/web/push-utils.d.cts +3 -3
  87. package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -1
  88. package/dist/NotificationServicesPushController/web/push-utils.d.mts +3 -3
  89. package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -1
  90. package/dist/NotificationServicesPushController/web/push-utils.mjs +13 -25
  91. package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
  92. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { getNotificationSubtype } from "../utils/get-notification-subtype.mjs";
1
2
  import { shouldAutoExpire } from "../utils/should-auto-expire.mjs";
2
3
  /**
3
4
  * Checks if a feature announcement should be read.
@@ -23,6 +24,7 @@ export function processFeatureAnnouncement(notification) {
23
24
  return {
24
25
  type: notification.type,
25
26
  id: notification.data.id,
27
+ notification_subtype: getNotificationSubtype(notification),
26
28
  createdAt: new Date(notification.createdAt).toISOString(),
27
29
  data: notification.data,
28
30
  isRead: false,
@@ -1 +1 @@
1
- {"version":3,"file":"process-feature-announcement.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-feature-announcement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,wCAAoC;AAE/D;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CACvC,YAAqD,EACrD,6BAAuC;IAEvC,IAAI,6BAA6B,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,gBAAgB,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,YAAgD;IAEhD,OAAO;QACL,IAAI,EAAE,YAAY,CAAC,IAAI;QACvB,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE;QACxB,SAAS,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;QACzD,IAAI,EAAE,YAAY,CAAC,IAAI;QACvB,MAAM,EAAE,KAAK;KACd,CAAC;AACJ,CAAC","sourcesContent":["import type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type { INotification } from '../types/notification/notification';\nimport { shouldAutoExpire } from '../utils/should-auto-expire';\n\n/**\n * Checks if a feature announcement should be read.\n * Checks feature announcement state (from param), as well as if the notification is \"expired\"\n *\n * @param notification - notification to check\n * @param readPlatformNotificationsList - list of read notifications\n * @returns boolean if notification should be marked as read or unread\n */\nexport function isFeatureAnnouncementRead(\n notification: Pick<INotification, 'id' | 'createdAt'>,\n readPlatformNotificationsList: string[],\n): boolean {\n if (readPlatformNotificationsList.includes(notification.id)) {\n return true;\n }\n return shouldAutoExpire(new Date(notification.createdAt));\n}\n\n/**\n * Processes a feature announcement into a shared/normalised notification shape.\n *\n * @param notification - raw feature announcement\n * @returns a normalised feature announcement\n */\nexport function processFeatureAnnouncement(\n notification: FeatureAnnouncementRawNotification,\n): INotification {\n return {\n type: notification.type,\n id: notification.data.id,\n createdAt: new Date(notification.createdAt).toISOString(),\n data: notification.data,\n isRead: false,\n };\n}\n"]}
1
+ {"version":3,"file":"process-feature-announcement.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-feature-announcement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,8CAA0C;AAC3E,OAAO,EAAE,gBAAgB,EAAE,wCAAoC;AAE/D;;;;;;;GAOG;AACH,MAAM,UAAU,yBAAyB,CACvC,YAAqD,EACrD,6BAAuC;IAEvC,IAAI,6BAA6B,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,gBAAgB,CAAC,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,YAAgD;IAEhD,OAAO;QACL,IAAI,EAAE,YAAY,CAAC,IAAI;QACvB,EAAE,EAAE,YAAY,CAAC,IAAI,CAAC,EAAE;QACxB,oBAAoB,EAAE,sBAAsB,CAAC,YAAY,CAAC;QAC1D,SAAS,EAAE,IAAI,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE;QACzD,IAAI,EAAE,YAAY,CAAC,IAAI;QACvB,MAAM,EAAE,KAAK;KACd,CAAC;AACJ,CAAC","sourcesContent":["import type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type { INotification } from '../types/notification/notification';\nimport { getNotificationSubtype } from '../utils/get-notification-subtype';\nimport { shouldAutoExpire } from '../utils/should-auto-expire';\n\n/**\n * Checks if a feature announcement should be read.\n * Checks feature announcement state (from param), as well as if the notification is \"expired\"\n *\n * @param notification - notification to check\n * @param readPlatformNotificationsList - list of read notifications\n * @returns boolean if notification should be marked as read or unread\n */\nexport function isFeatureAnnouncementRead(\n notification: Pick<INotification, 'id' | 'createdAt'>,\n readPlatformNotificationsList: string[],\n): boolean {\n if (readPlatformNotificationsList.includes(notification.id)) {\n return true;\n }\n return shouldAutoExpire(new Date(notification.createdAt));\n}\n\n/**\n * Processes a feature announcement into a shared/normalised notification shape.\n *\n * @param notification - raw feature announcement\n * @returns a normalised feature announcement\n */\nexport function processFeatureAnnouncement(\n notification: FeatureAnnouncementRawNotification,\n): INotification {\n return {\n type: notification.type,\n id: notification.data.id,\n notification_subtype: getNotificationSubtype(notification),\n createdAt: new Date(notification.createdAt).toISOString(),\n data: notification.data,\n isRead: false,\n };\n}\n"]}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processSnapNotification = void 0;
4
4
  const uuid_1 = require("uuid");
5
+ const get_notification_subtype_1 = require("../utils/get-notification-subtype.cjs");
5
6
  /**
6
7
  * Processes a snap notification into a normalized shape.
7
8
  *
@@ -12,6 +13,7 @@ const processSnapNotification = (snapNotification) => {
12
13
  const { data, type, readDate } = snapNotification;
13
14
  return {
14
15
  id: (0, uuid_1.v4)(),
16
+ notification_subtype: (0, get_notification_subtype_1.getNotificationSubtype)(snapNotification),
15
17
  readDate,
16
18
  createdAt: new Date().toISOString(),
17
19
  isRead: false,
@@ -1 +1 @@
1
- {"version":3,"file":"process-snap-notifications.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":";;;AAAA,+BAAkC;AAKlC;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,gBAAqC,EACtB,EAAE;IACjB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,gBAAgB,CAAC;IAClD,OAAO;QACL,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,QAAQ;QACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,MAAM,EAAE,KAAK;QACb,IAAI;QACJ,IAAI;KACL,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,uBAAuB,2BAYlC","sourcesContent":["import { v4 as uuid } from 'uuid';\n\nimport type { INotification } from '../types';\nimport type { RawSnapNotification } from '../types/snaps';\n\n/**\n * Processes a snap notification into a normalized shape.\n *\n * @param snapNotification - A raw snap notification.\n * @returns a normalized snap notification.\n */\nexport const processSnapNotification = (\n snapNotification: RawSnapNotification,\n): INotification => {\n const { data, type, readDate } = snapNotification;\n return {\n id: uuid(),\n readDate,\n createdAt: new Date().toISOString(),\n isRead: false,\n type,\n data,\n };\n};\n"]}
1
+ {"version":3,"file":"process-snap-notifications.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":";;;AAAA,+BAAkC;AAIlC,oFAA2E;AAE3E;;;;;GAKG;AACI,MAAM,uBAAuB,GAAG,CACrC,gBAAqC,EACtB,EAAE;IACjB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,gBAAgB,CAAC;IAClD,OAAO;QACL,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,oBAAoB,EAAE,IAAA,iDAAsB,EAAC,gBAAgB,CAAC;QAC9D,QAAQ;QACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,MAAM,EAAE,KAAK;QACb,IAAI;QACJ,IAAI;KACL,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,uBAAuB,2BAalC","sourcesContent":["import { v4 as uuid } from 'uuid';\n\nimport type { INotification } from '../types';\nimport type { RawSnapNotification } from '../types/snaps';\nimport { getNotificationSubtype } from '../utils/get-notification-subtype';\n\n/**\n * Processes a snap notification into a normalized shape.\n *\n * @param snapNotification - A raw snap notification.\n * @returns a normalized snap notification.\n */\nexport const processSnapNotification = (\n snapNotification: RawSnapNotification,\n): INotification => {\n const { data, type, readDate } = snapNotification;\n return {\n id: uuid(),\n notification_subtype: getNotificationSubtype(snapNotification),\n readDate,\n createdAt: new Date().toISOString(),\n isRead: false,\n type,\n data,\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"process-snap-notifications.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAAiB;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAAuB;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,qBAChB,mBAAmB,KACpC,aAUF,CAAC"}
1
+ {"version":3,"file":"process-snap-notifications.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAAiB;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAAuB;AAG1D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,qBAChB,mBAAmB,KACpC,aAWF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"process-snap-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAAiB;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAAuB;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,qBAChB,mBAAmB,KACpC,aAUF,CAAC"}
1
+ {"version":3,"file":"process-snap-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,2BAAiB;AAC9C,OAAO,KAAK,EAAE,mBAAmB,EAAE,iCAAuB;AAG1D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,qBAChB,mBAAmB,KACpC,aAWF,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { v4 as uuid } from "uuid";
2
+ import { getNotificationSubtype } from "../utils/get-notification-subtype.mjs";
2
3
  /**
3
4
  * Processes a snap notification into a normalized shape.
4
5
  *
@@ -9,6 +10,7 @@ export const processSnapNotification = (snapNotification) => {
9
10
  const { data, type, readDate } = snapNotification;
10
11
  return {
11
12
  id: uuid(),
13
+ notification_subtype: getNotificationSubtype(snapNotification),
12
14
  readDate,
13
15
  createdAt: new Date().toISOString(),
14
16
  isRead: false,
@@ -1 +1 @@
1
- {"version":3,"file":"process-snap-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAKlC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,gBAAqC,EACtB,EAAE;IACjB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,gBAAgB,CAAC;IAClD,OAAO;QACL,EAAE,EAAE,IAAI,EAAE;QACV,QAAQ;QACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,MAAM,EAAE,KAAK;QACb,IAAI;QACJ,IAAI;KACL,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { v4 as uuid } from 'uuid';\n\nimport type { INotification } from '../types';\nimport type { RawSnapNotification } from '../types/snaps';\n\n/**\n * Processes a snap notification into a normalized shape.\n *\n * @param snapNotification - A raw snap notification.\n * @returns a normalized snap notification.\n */\nexport const processSnapNotification = (\n snapNotification: RawSnapNotification,\n): INotification => {\n const { data, type, readDate } = snapNotification;\n return {\n id: uuid(),\n readDate,\n createdAt: new Date().toISOString(),\n isRead: false,\n type,\n data,\n };\n};\n"]}
1
+ {"version":3,"file":"process-snap-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-snap-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAIlC,OAAO,EAAE,sBAAsB,EAAE,8CAA0C;AAE3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,gBAAqC,EACtB,EAAE;IACjB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,gBAAgB,CAAC;IAClD,OAAO;QACL,EAAE,EAAE,IAAI,EAAE;QACV,oBAAoB,EAAE,sBAAsB,CAAC,gBAAgB,CAAC;QAC9D,QAAQ;QACR,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;QACnC,MAAM,EAAE,KAAK;QACb,IAAI;QACJ,IAAI;KACL,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { v4 as uuid } from 'uuid';\n\nimport type { INotification } from '../types';\nimport type { RawSnapNotification } from '../types/snaps';\nimport { getNotificationSubtype } from '../utils/get-notification-subtype';\n\n/**\n * Processes a snap notification into a normalized shape.\n *\n * @param snapNotification - A raw snap notification.\n * @returns a normalized snap notification.\n */\nexport const processSnapNotification = (\n snapNotification: RawSnapNotification,\n): INotification => {\n const { data, type, readDate } = snapNotification;\n return {\n id: uuid(),\n notification_subtype: getNotificationSubtype(snapNotification),\n readDate,\n createdAt: new Date().toISOString(),\n isRead: false,\n type,\n data,\n };\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"notification.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"","sourcesContent":["import type { FeatureAnnouncementRawNotification } from '../feature-announcement/feature-announcement';\nimport type { NormalisedAPINotification } from '../notification-api/notification-api';\nimport type { RawSnapNotification } from '../snaps';\nimport type { Compute } from '../type-utils';\n\nexport type BaseNotification = {\n id: string;\n createdAt: string;\n isRead: boolean;\n};\n\nexport type RawNotificationUnion =\n | NormalisedAPINotification\n | FeatureAnnouncementRawNotification\n | RawSnapNotification;\n\n/**\n * The shape of a \"generic\" notification.\n * Other than the fields listed below, tt will also contain:\n * - `type` field (declared in the Raw shapes)\n * - `data` field (declared in the Raw shapes)\n */\nexport type INotification = Compute<\n | (FeatureAnnouncementRawNotification & BaseNotification)\n | (NormalisedAPINotification & BaseNotification)\n | (RawSnapNotification & BaseNotification & { readDate?: string | null })\n>;\n\nexport type MarkAsReadNotificationsParam = Pick<\n INotification,\n 'id' | 'type' | 'isRead'\n>[];\n"]}
1
+ {"version":3,"file":"notification.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"","sourcesContent":["import type { FeatureAnnouncementRawNotification } from '../feature-announcement/feature-announcement';\nimport type { NormalisedAPINotification } from '../notification-api/notification-api';\nimport type { RawSnapNotification } from '../snaps';\nimport type { Compute } from '../type-utils';\n\nexport type BaseNotification = {\n id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n notification_subtype: string;\n createdAt: string;\n isRead: boolean;\n};\n\nexport type RawNotificationUnion =\n | NormalisedAPINotification\n | FeatureAnnouncementRawNotification\n | RawSnapNotification;\n\n/**\n * The shape of a \"generic\" notification.\n * Other than the fields listed below, tt will also contain:\n * - `type` field (declared in the Raw shapes)\n * - `data` field (declared in the Raw shapes)\n */\nexport type INotification = Compute<\n | (FeatureAnnouncementRawNotification & BaseNotification)\n | (NormalisedAPINotification & BaseNotification)\n | (RawSnapNotification & BaseNotification & { readDate?: string | null })\n>;\n\nexport type MarkAsReadNotificationsParam = Pick<\n INotification,\n 'id' | 'type' | 'isRead'\n>[];\n"]}
@@ -4,6 +4,7 @@ import type { RawSnapNotification } from "../snaps/index.cjs";
4
4
  import type { Compute } from "../type-utils.cjs";
5
5
  export type BaseNotification = {
6
6
  id: string;
7
+ notification_subtype: string;
7
8
  createdAt: string;
8
9
  isRead: boolean;
9
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"notification.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,yDAAqD;AACvG,OAAO,KAAK,EAAE,yBAAyB,EAAE,iDAA6C;AACtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAE7C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB,kCAAkC,GAClC,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAC/B,CAAC,kCAAkC,GAAG,gBAAgB,CAAC,GACvD,CAAC,yBAAyB,GAAG,gBAAgB,CAAC,GAC9C,CAAC,mBAAmB,GAAG,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAC1E,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,aAAa,EACb,IAAI,GAAG,MAAM,GAAG,QAAQ,CACzB,EAAE,CAAC"}
1
+ {"version":3,"file":"notification.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,yDAAqD;AACvG,OAAO,KAAK,EAAE,yBAAyB,EAAE,iDAA6C;AACtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAE7C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IAEX,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB,kCAAkC,GAClC,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAC/B,CAAC,kCAAkC,GAAG,gBAAgB,CAAC,GACvD,CAAC,yBAAyB,GAAG,gBAAgB,CAAC,GAC9C,CAAC,mBAAmB,GAAG,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAC1E,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,aAAa,EACb,IAAI,GAAG,MAAM,GAAG,QAAQ,CACzB,EAAE,CAAC"}
@@ -4,6 +4,7 @@ import type { RawSnapNotification } from "../snaps/index.mjs";
4
4
  import type { Compute } from "../type-utils.mjs";
5
5
  export type BaseNotification = {
6
6
  id: string;
7
+ notification_subtype: string;
7
8
  createdAt: string;
8
9
  isRead: boolean;
9
10
  };
@@ -1 +1 @@
1
- {"version":3,"file":"notification.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,yDAAqD;AACvG,OAAO,KAAK,EAAE,yBAAyB,EAAE,iDAA6C;AACtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAE7C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB,kCAAkC,GAClC,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAC/B,CAAC,kCAAkC,GAAG,gBAAgB,CAAC,GACvD,CAAC,yBAAyB,GAAG,gBAAgB,CAAC,GAC9C,CAAC,mBAAmB,GAAG,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAC1E,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,aAAa,EACb,IAAI,GAAG,MAAM,GAAG,QAAQ,CACzB,EAAE,CAAC"}
1
+ {"version":3,"file":"notification.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,yDAAqD;AACvG,OAAO,KAAK,EAAE,yBAAyB,EAAE,iDAA6C;AACtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAAiB;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAE7C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,EAAE,MAAM,CAAC;IAEX,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B,yBAAyB,GACzB,kCAAkC,GAClC,mBAAmB,CAAC;AAExB;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAC/B,CAAC,kCAAkC,GAAG,gBAAgB,CAAC,GACvD,CAAC,yBAAyB,GAAG,gBAAgB,CAAC,GAC9C,CAAC,mBAAmB,GAAG,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,CAC1E,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,aAAa,EACb,IAAI,GAAG,MAAM,GAAG,QAAQ,CACzB,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"notification.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"","sourcesContent":["import type { FeatureAnnouncementRawNotification } from '../feature-announcement/feature-announcement';\nimport type { NormalisedAPINotification } from '../notification-api/notification-api';\nimport type { RawSnapNotification } from '../snaps';\nimport type { Compute } from '../type-utils';\n\nexport type BaseNotification = {\n id: string;\n createdAt: string;\n isRead: boolean;\n};\n\nexport type RawNotificationUnion =\n | NormalisedAPINotification\n | FeatureAnnouncementRawNotification\n | RawSnapNotification;\n\n/**\n * The shape of a \"generic\" notification.\n * Other than the fields listed below, tt will also contain:\n * - `type` field (declared in the Raw shapes)\n * - `data` field (declared in the Raw shapes)\n */\nexport type INotification = Compute<\n | (FeatureAnnouncementRawNotification & BaseNotification)\n | (NormalisedAPINotification & BaseNotification)\n | (RawSnapNotification & BaseNotification & { readDate?: string | null })\n>;\n\nexport type MarkAsReadNotificationsParam = Pick<\n INotification,\n 'id' | 'type' | 'isRead'\n>[];\n"]}
1
+ {"version":3,"file":"notification.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification/notification.ts"],"names":[],"mappings":"","sourcesContent":["import type { FeatureAnnouncementRawNotification } from '../feature-announcement/feature-announcement';\nimport type { NormalisedAPINotification } from '../notification-api/notification-api';\nimport type { RawSnapNotification } from '../snaps';\nimport type { Compute } from '../type-utils';\n\nexport type BaseNotification = {\n id: string;\n // eslint-disable-next-line @typescript-eslint/naming-convention\n notification_subtype: string;\n createdAt: string;\n isRead: boolean;\n};\n\nexport type RawNotificationUnion =\n | NormalisedAPINotification\n | FeatureAnnouncementRawNotification\n | RawSnapNotification;\n\n/**\n * The shape of a \"generic\" notification.\n * Other than the fields listed below, tt will also contain:\n * - `type` field (declared in the Raw shapes)\n * - `data` field (declared in the Raw shapes)\n */\nexport type INotification = Compute<\n | (FeatureAnnouncementRawNotification & BaseNotification)\n | (NormalisedAPINotification & BaseNotification)\n | (RawSnapNotification & BaseNotification & { readDate?: string | null })\n>;\n\nexport type MarkAsReadNotificationsParam = Pick<\n INotification,\n 'id' | 'type' | 'isRead'\n>[];\n"]}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNotificationSubtype = void 0;
4
+ const notification_schema_1 = require("../constants/notification-schema.cjs");
5
+ /**
6
+ * Derives the normalised `notification_subtype` for a processed in-app
7
+ * notification. This is the team-owned axis (e.g. `eth_received`) and is
8
+ * always derivable from an `INotification`, so every consumer (both clients)
9
+ * pulls it from one place rather than recomputing a fallback chain.
10
+ *
11
+ * - on-chain: the trigger kind (`payload.data.kind`, e.g. `eth_received`).
12
+ * - snap: the snap notification type (`snap`, already snake_case).
13
+ * - feature-announcement: §5.3 calls for a stable per-campaign id, pending
14
+ * confirmation from the announcements team that one exists. Until confirmed,
15
+ * we use the `features_announcement` label as the single value.
16
+ * - platform: the server-set `notification_subtype`. The backend stores it
17
+ * (notify-notification-services §4.3), but the `/api/v3/notifications` inbox
18
+ * response does not expose it yet, so it is absent from the generated
19
+ * `schema.ts` and we fall back to `type` (`platform`).
20
+ *
21
+ * @param notification - a raw or processed notification.
22
+ * @returns the normalised subtype string.
23
+ */
24
+ function getNotificationSubtype(notification) {
25
+ switch (notification.type) {
26
+ case notification_schema_1.TRIGGER_TYPES.FEATURES_ANNOUNCEMENT:
27
+ // §5.3 calls for a stable per-campaign id here, pending confirmation from
28
+ // the announcements team that one exists. Until confirmed, use the
29
+ // `features_announcement` label as the single value.
30
+ return notification_schema_1.TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;
31
+ case notification_schema_1.TRIGGER_TYPES.SNAP:
32
+ // Snap notification type, already snake_case in the existing shape.
33
+ return notification_schema_1.TRIGGER_TYPES.SNAP;
34
+ default:
35
+ // On-chain: the trigger kind (e.g. `eth_received`).
36
+ if (notification.notification_type === 'on-chain') {
37
+ return notification.payload.data.kind;
38
+ }
39
+ // Platform: §5.3 wants the server-set `notification_subtype`. It is
40
+ // stored backend-side (§4.3) but not returned on the `/api/v3/notifications`
41
+ // inbox response, so it is absent from `schema.ts`. Fall back to `type`
42
+ // (`platform`) until the inbox API exposes it.
43
+ // TODO: return notification.notification_subtype once the inbox API
44
+ // response includes it (needs a notify-notification-services change).
45
+ return notification.type;
46
+ }
47
+ }
48
+ exports.getNotificationSubtype = getNotificationSubtype;
49
+ //# sourceMappingURL=get-notification-subtype.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-notification-subtype.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/get-notification-subtype.ts"],"names":[],"mappings":";;;AAAA,8EAAiE;AAGjE;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAgB,sBAAsB,CACpC,YAAkC;IAElC,QAAQ,YAAY,CAAC,IAAI,EAAE,CAAC;QAC1B,KAAK,mCAAa,CAAC,qBAAqB;YACtC,0EAA0E;YAC1E,mEAAmE;YACnE,qDAAqD;YACrD,OAAO,mCAAa,CAAC,qBAAqB,CAAC;QAC7C,KAAK,mCAAa,CAAC,IAAI;YACrB,oEAAoE;YACpE,OAAO,mCAAa,CAAC,IAAI,CAAC;QAC5B;YACE,oDAAoD;YACpD,IAAI,YAAY,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;gBAClD,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YACxC,CAAC;YACD,oEAAoE;YACpE,6EAA6E;YAC7E,wEAAwE;YACxE,+CAA+C;YAC/C,oEAAoE;YACpE,sEAAsE;YACtE,OAAO,YAAY,CAAC,IAAI,CAAC;IAC7B,CAAC;AACH,CAAC;AAzBD,wDAyBC","sourcesContent":["import { TRIGGER_TYPES } from '../constants/notification-schema';\nimport type { RawNotificationUnion } from '../types/notification/notification';\n\n/**\n * Derives the normalised `notification_subtype` for a processed in-app\n * notification. This is the team-owned axis (e.g. `eth_received`) and is\n * always derivable from an `INotification`, so every consumer (both clients)\n * pulls it from one place rather than recomputing a fallback chain.\n *\n * - on-chain: the trigger kind (`payload.data.kind`, e.g. `eth_received`).\n * - snap: the snap notification type (`snap`, already snake_case).\n * - feature-announcement: §5.3 calls for a stable per-campaign id, pending\n * confirmation from the announcements team that one exists. Until confirmed,\n * we use the `features_announcement` label as the single value.\n * - platform: the server-set `notification_subtype`. The backend stores it\n * (notify-notification-services §4.3), but the `/api/v3/notifications` inbox\n * response does not expose it yet, so it is absent from the generated\n * `schema.ts` and we fall back to `type` (`platform`).\n *\n * @param notification - a raw or processed notification.\n * @returns the normalised subtype string.\n */\nexport function getNotificationSubtype(\n notification: RawNotificationUnion,\n): string {\n switch (notification.type) {\n case TRIGGER_TYPES.FEATURES_ANNOUNCEMENT:\n // §5.3 calls for a stable per-campaign id here, pending confirmation from\n // the announcements team that one exists. Until confirmed, use the\n // `features_announcement` label as the single value.\n return TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n case TRIGGER_TYPES.SNAP:\n // Snap notification type, already snake_case in the existing shape.\n return TRIGGER_TYPES.SNAP;\n default:\n // On-chain: the trigger kind (e.g. `eth_received`).\n if (notification.notification_type === 'on-chain') {\n return notification.payload.data.kind;\n }\n // Platform: §5.3 wants the server-set `notification_subtype`. It is\n // stored backend-side (§4.3) but not returned on the `/api/v3/notifications`\n // inbox response, so it is absent from `schema.ts`. Fall back to `type`\n // (`platform`) until the inbox API exposes it.\n // TODO: return notification.notification_subtype once the inbox API\n // response includes it (needs a notify-notification-services change).\n return notification.type;\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { RawNotificationUnion } from "../types/notification/notification.cjs";
2
+ /**
3
+ * Derives the normalised `notification_subtype` for a processed in-app
4
+ * notification. This is the team-owned axis (e.g. `eth_received`) and is
5
+ * always derivable from an `INotification`, so every consumer (both clients)
6
+ * pulls it from one place rather than recomputing a fallback chain.
7
+ *
8
+ * - on-chain: the trigger kind (`payload.data.kind`, e.g. `eth_received`).
9
+ * - snap: the snap notification type (`snap`, already snake_case).
10
+ * - feature-announcement: §5.3 calls for a stable per-campaign id, pending
11
+ * confirmation from the announcements team that one exists. Until confirmed,
12
+ * we use the `features_announcement` label as the single value.
13
+ * - platform: the server-set `notification_subtype`. The backend stores it
14
+ * (notify-notification-services §4.3), but the `/api/v3/notifications` inbox
15
+ * response does not expose it yet, so it is absent from the generated
16
+ * `schema.ts` and we fall back to `type` (`platform`).
17
+ *
18
+ * @param notification - a raw or processed notification.
19
+ * @returns the normalised subtype string.
20
+ */
21
+ export declare function getNotificationSubtype(notification: RawNotificationUnion): string;
22
+ //# sourceMappingURL=get-notification-subtype.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-notification-subtype.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/get-notification-subtype.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,+CAA2C;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,oBAAoB,GACjC,MAAM,CAuBR"}
@@ -0,0 +1,22 @@
1
+ import type { RawNotificationUnion } from "../types/notification/notification.mjs";
2
+ /**
3
+ * Derives the normalised `notification_subtype` for a processed in-app
4
+ * notification. This is the team-owned axis (e.g. `eth_received`) and is
5
+ * always derivable from an `INotification`, so every consumer (both clients)
6
+ * pulls it from one place rather than recomputing a fallback chain.
7
+ *
8
+ * - on-chain: the trigger kind (`payload.data.kind`, e.g. `eth_received`).
9
+ * - snap: the snap notification type (`snap`, already snake_case).
10
+ * - feature-announcement: §5.3 calls for a stable per-campaign id, pending
11
+ * confirmation from the announcements team that one exists. Until confirmed,
12
+ * we use the `features_announcement` label as the single value.
13
+ * - platform: the server-set `notification_subtype`. The backend stores it
14
+ * (notify-notification-services §4.3), but the `/api/v3/notifications` inbox
15
+ * response does not expose it yet, so it is absent from the generated
16
+ * `schema.ts` and we fall back to `type` (`platform`).
17
+ *
18
+ * @param notification - a raw or processed notification.
19
+ * @returns the normalised subtype string.
20
+ */
21
+ export declare function getNotificationSubtype(notification: RawNotificationUnion): string;
22
+ //# sourceMappingURL=get-notification-subtype.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-notification-subtype.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/get-notification-subtype.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,+CAA2C;AAE/E;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,oBAAoB,GACjC,MAAM,CAuBR"}
@@ -0,0 +1,45 @@
1
+ import { TRIGGER_TYPES } from "../constants/notification-schema.mjs";
2
+ /**
3
+ * Derives the normalised `notification_subtype` for a processed in-app
4
+ * notification. This is the team-owned axis (e.g. `eth_received`) and is
5
+ * always derivable from an `INotification`, so every consumer (both clients)
6
+ * pulls it from one place rather than recomputing a fallback chain.
7
+ *
8
+ * - on-chain: the trigger kind (`payload.data.kind`, e.g. `eth_received`).
9
+ * - snap: the snap notification type (`snap`, already snake_case).
10
+ * - feature-announcement: §5.3 calls for a stable per-campaign id, pending
11
+ * confirmation from the announcements team that one exists. Until confirmed,
12
+ * we use the `features_announcement` label as the single value.
13
+ * - platform: the server-set `notification_subtype`. The backend stores it
14
+ * (notify-notification-services §4.3), but the `/api/v3/notifications` inbox
15
+ * response does not expose it yet, so it is absent from the generated
16
+ * `schema.ts` and we fall back to `type` (`platform`).
17
+ *
18
+ * @param notification - a raw or processed notification.
19
+ * @returns the normalised subtype string.
20
+ */
21
+ export function getNotificationSubtype(notification) {
22
+ switch (notification.type) {
23
+ case TRIGGER_TYPES.FEATURES_ANNOUNCEMENT:
24
+ // §5.3 calls for a stable per-campaign id here, pending confirmation from
25
+ // the announcements team that one exists. Until confirmed, use the
26
+ // `features_announcement` label as the single value.
27
+ return TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;
28
+ case TRIGGER_TYPES.SNAP:
29
+ // Snap notification type, already snake_case in the existing shape.
30
+ return TRIGGER_TYPES.SNAP;
31
+ default:
32
+ // On-chain: the trigger kind (e.g. `eth_received`).
33
+ if (notification.notification_type === 'on-chain') {
34
+ return notification.payload.data.kind;
35
+ }
36
+ // Platform: §5.3 wants the server-set `notification_subtype`. It is
37
+ // stored backend-side (§4.3) but not returned on the `/api/v3/notifications`
38
+ // inbox response, so it is absent from `schema.ts`. Fall back to `type`
39
+ // (`platform`) until the inbox API exposes it.
40
+ // TODO: return notification.notification_subtype once the inbox API
41
+ // response includes it (needs a notify-notification-services change).
42
+ return notification.type;
43
+ }
44
+ }
45
+ //# sourceMappingURL=get-notification-subtype.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-notification-subtype.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/get-notification-subtype.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,6CAAyC;AAGjE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAAkC;IAElC,QAAQ,YAAY,CAAC,IAAI,EAAE,CAAC;QAC1B,KAAK,aAAa,CAAC,qBAAqB;YACtC,0EAA0E;YAC1E,mEAAmE;YACnE,qDAAqD;YACrD,OAAO,aAAa,CAAC,qBAAqB,CAAC;QAC7C,KAAK,aAAa,CAAC,IAAI;YACrB,oEAAoE;YACpE,OAAO,aAAa,CAAC,IAAI,CAAC;QAC5B;YACE,oDAAoD;YACpD,IAAI,YAAY,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;gBAClD,OAAO,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YACxC,CAAC;YACD,oEAAoE;YACpE,6EAA6E;YAC7E,wEAAwE;YACxE,+CAA+C;YAC/C,oEAAoE;YACpE,sEAAsE;YACtE,OAAO,YAAY,CAAC,IAAI,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import { TRIGGER_TYPES } from '../constants/notification-schema';\nimport type { RawNotificationUnion } from '../types/notification/notification';\n\n/**\n * Derives the normalised `notification_subtype` for a processed in-app\n * notification. This is the team-owned axis (e.g. `eth_received`) and is\n * always derivable from an `INotification`, so every consumer (both clients)\n * pulls it from one place rather than recomputing a fallback chain.\n *\n * - on-chain: the trigger kind (`payload.data.kind`, e.g. `eth_received`).\n * - snap: the snap notification type (`snap`, already snake_case).\n * - feature-announcement: §5.3 calls for a stable per-campaign id, pending\n * confirmation from the announcements team that one exists. Until confirmed,\n * we use the `features_announcement` label as the single value.\n * - platform: the server-set `notification_subtype`. The backend stores it\n * (notify-notification-services §4.3), but the `/api/v3/notifications` inbox\n * response does not expose it yet, so it is absent from the generated\n * `schema.ts` and we fall back to `type` (`platform`).\n *\n * @param notification - a raw or processed notification.\n * @returns the normalised subtype string.\n */\nexport function getNotificationSubtype(\n notification: RawNotificationUnion,\n): string {\n switch (notification.type) {\n case TRIGGER_TYPES.FEATURES_ANNOUNCEMENT:\n // §5.3 calls for a stable per-campaign id here, pending confirmation from\n // the announcements team that one exists. Until confirmed, use the\n // `features_announcement` label as the single value.\n return TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n case TRIGGER_TYPES.SNAP:\n // Snap notification type, already snake_case in the existing shape.\n return TRIGGER_TYPES.SNAP;\n default:\n // On-chain: the trigger kind (e.g. `eth_received`).\n if (notification.notification_type === 'on-chain') {\n return notification.payload.data.kind;\n }\n // Platform: §5.3 wants the server-set `notification_subtype`. It is\n // stored backend-side (§4.3) but not returned on the `/api/v3/notifications`\n // inbox response, so it is absent from `schema.ts`. Fall back to `type`\n // (`platform`) until the inbox API exposes it.\n // TODO: return notification.notification_subtype once the inbox API\n // response includes it (needs a notify-notification-services change).\n return notification.type;\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,+DAA2D;AAG3D,wDAA2B;AAM3B,sDAK6B;AAI7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAQ5D,MAAM,yBAAyB,GAAG;IAChC,8BAA8B;IAC9B,yBAAyB;IACzB,0BAA0B;IAC1B,0BAA0B;IAC1B,gCAAgC;IAChC,6BAA6B;CACrB,CAAC;AA0CE,QAAA,YAAY,GAA4C;IACnE,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,EAAE;IACZ,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AACF,MAAM,QAAQ,GAA2D;IACvE,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;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IACL,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;YAC3B,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;IAGC,MAAM,aAAa,GAA8B;QAC/C,QAAQ,EAAE,uBAAA,IAAI,kDAAQ,CAAC,QAAQ;QAC/B,MAAM,EAAE,uBAAA,IAAI,kDAAQ,CAAC,SAAS,EAAE,EAAE,IAAI,IAAI;KAC3C,CAAC;IAEF,IAAI,uBAAA,IAAI,kDAAQ,CAAC,EAAE,EAAE,CAAC;QACpB,aAAa,CAAC,EAAE,GAAG,uBAAA,IAAI,kDAAQ,CAAC,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,uBAAA,IAAI,kDAAQ,CAAC,UAAU,EAAE,CAAC;QAC5B,aAAa,CAAC,UAAU,GAAG,uBAAA,IAAI,kDAAQ,CAAC,UAAU,CAAC;IACrD,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport log from 'loglevel';\n\nimport type { Types } from '../NotificationServicesController';\nimport type { NotificationServicesPushControllerMethodActions } from './NotificationServicesPushController-method-action-types';\nimport type { ENV } from './services/endpoints';\nimport type { RegToken } from './services/services';\nimport {\n activatePushNotifications,\n deleteLinksAPI,\n deactivatePushNotifications,\n updateLinksAPI,\n} from './services/services';\nimport type { PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'subscribeToPushNotifications',\n 'enablePushNotifications',\n 'addPushNotificationLinks',\n 'disablePushNotifications',\n 'updateTriggerPushNotifications',\n 'deletePushNotificationLinks',\n] as const;\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerMethodActions;\n\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerTokenAction;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [Types.INotification];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [Types.INotification];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type NotificationServicesPushControllerMessenger = Messenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n fcmToken: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n isUpdatingFCMToken: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * App or extension version to include when registering push tokens.\n */\n appVersion?: string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Mobile operating system to include when registering push tokens.\n */\n os?: 'android' | 'ios';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n\n env?: ENV;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\n\ntype RegistrationTokenMetadata = Pick<\n RegToken,\n 'appVersion' | 'locale' | 'os' | 'platform'\n>;\n\n/**\n * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.\n * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.\n * It is responsible for registering and unregistering the service worker that listens for push notifications,\n * managing the FCM token, and communicating with the server to register or unregister the device for push notifications.\n * Additionally, it provides functionality to update the server with new UUIDs that should trigger push notifications.\n */\nexport class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\n env?: PushNotificationEnv;\n config: ControllerConfig;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#env = env ?? defaultPushEnv;\n this.#config = config;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#clearLoadingStates();\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n async #getAndAssertBearerToken(): Promise<string> {\n const bearerToken = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!bearerToken) {\n throw new Error('BearerToken token is missing');\n }\n\n return bearerToken;\n }\n\n #updatePushState(command: StateCommand): void {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n // Note we do not want to clear the old FCM token\n // We can send it as an old token to our backend to cleanup next time turned on\n state.isPushEnabled = false;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n #getRegistrationTokenMetadata(): RegistrationTokenMetadata {\n const tokenMetadata: RegistrationTokenMetadata = {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n };\n\n if (this.#config.os) {\n tokenMetadata.os = this.#config.os;\n }\n\n if (this.#config.appVersion) {\n tokenMetadata.appVersion = this.#config.appVersion;\n }\n\n return tokenMetadata;\n }\n\n public async subscribeToPushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\n }\n\n /**\n * Enables push notifications for the application.\n *\n * This method sets up the necessary infrastructure for handling push notifications by:\n * 1. Registering the service worker to listen for messages.\n * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.\n * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.\n *\n * @param addresses - An array of addresses to enable push notifications for.\n */\n public async enablePushNotifications(addresses: string[]): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n ...this.#getRegistrationTokenMetadata(),\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.deleteRegToken,\n regToken: this.state.fcmToken,\n });\n } catch (error) {\n const errorMessage = `Failed to disable push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\n }\n\n /**\n * Adds backend push notification links for the given addresses using the current FCM token.\n * This is used when accounts are added after push notifications have already been enabled,\n * so backend can link the existing device token to the newly added addresses.\n *\n * @param addresses - Addresses that should be linked to push notifications.\n * @returns Whether the add request succeeded.\n */\n public async addPushNotificationLinks(addresses: string[]): Promise<boolean> {\n if (\n !this.#config.isPushFeatureEnabled ||\n addresses.length === 0 ||\n !this.state.fcmToken\n ) {\n return false;\n }\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n return await updateLinksAPI({\n bearerToken,\n addresses,\n regToken: {\n token: this.state.fcmToken,\n ...this.#getRegistrationTokenMetadata(),\n },\n env: this.#config.env ?? 'prd',\n });\n } catch {\n return false;\n }\n }\n\n /**\n * Deletes backend push notification links for the given addresses on the current platform.\n * This is used when accounts are removed (for example SRP removal), so backend can remove\n * all associated FCM tokens for those address/platform pairs.\n *\n * @param addresses - Addresses that should be unlinked from push notifications.\n * @returns Whether the delete request succeeded.\n */\n public async deletePushNotificationLinks(\n addresses: string[],\n ): Promise<boolean> {\n if (\n !this.#config.isPushFeatureEnabled ||\n addresses.length === 0 ||\n !this.state.fcmToken\n ) {\n return false;\n }\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n return await deleteLinksAPI({\n bearerToken,\n addresses,\n platform: this.#config.platform,\n token: this.state.fcmToken,\n env: this.#config.env ?? 'prd',\n });\n } catch {\n return false;\n }\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param addresses - An array of addresses that should trigger push notifications.\n * @deprecated - this is not used anymore and will most likely be removed\n */\n public async updateTriggerPushNotifications(\n addresses: string[],\n ): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n ...this.#getRegistrationTokenMetadata(),\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\n }\n } catch (error) {\n const errorMessage = `Failed to update triggers for push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"NotificationServicesPushController.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAKA,+DAA2D;AAG3D,wDAA2B;AAK3B,sDAK6B;AAI7B,MAAM,cAAc,GAAG,oCAAoC,CAAC;AAQ5D,MAAM,yBAAyB,GAAG;IAChC,8BAA8B;IAC9B,yBAAyB;IACzB,0BAA0B;IAC1B,0BAA0B;IAC1B,gCAAgC;IAChC,6BAA6B;CACrB,CAAC;AA0CE,QAAA,YAAY,GAA4C;IACnE,aAAa,EAAE,IAAI;IACnB,QAAQ,EAAE,EAAE;IACZ,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AACF,MAAM,QAAQ,GAA2D;IACvE,aAAa,EAAE;QACb,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,QAAQ,EAAE;QACR,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;IACD,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,KAAK;QACzB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,IAAI;QAC5B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,cAAc,GAAwB;IAC1C,MAAM,EAAE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Q,GAAG,OAAO,CAAC,QAAQ,CAAC;YAClC,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC;IAGC,MAAM,aAAa,GAA8B;QAC/C,QAAQ,EAAE,uBAAA,IAAI,kDAAQ,CAAC,QAAQ;QAC/B,MAAM,EAAE,uBAAA,IAAI,kDAAQ,CAAC,SAAS,EAAE,EAAE,IAAI,IAAI;KAC3C,CAAC;IAEF,IAAI,uBAAA,IAAI,kDAAQ,CAAC,EAAE,EAAE,CAAC;QACpB,aAAa,CAAC,EAAE,GAAG,uBAAA,IAAI,kDAAQ,CAAC,EAAE,CAAC;IACrC,CAAC;IAED,IAAI,uBAAA,IAAI,kDAAQ,CAAC,UAAU,EAAE,CAAC;QAC5B,aAAa,CAAC,UAAU,GAAG,uBAAA,IAAI,kDAAQ,CAAC,UAAU,CAAC;IACrD,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { AuthenticationController } from '@metamask/profile-sync-controller';\nimport log from 'loglevel';\n\nimport type { NotificationServicesPushControllerMethodActions } from './NotificationServicesPushController-method-action-types';\nimport type { ENV } from './services/endpoints';\nimport type { RegToken } from './services/services';\nimport {\n activatePushNotifications,\n deleteLinksAPI,\n deactivatePushNotifications,\n updateLinksAPI,\n} from './services/services';\nimport type { PushAnalyticsPayload, PushNotificationEnv } from './types';\nimport type { PushService } from './types/push-service-interface';\n\nconst controllerName = 'NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerState = {\n isPushEnabled: boolean;\n fcmToken: string;\n isUpdatingFCMToken: boolean;\n};\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'subscribeToPushNotifications',\n 'enablePushNotifications',\n 'addPushNotificationLinks',\n 'disablePushNotifications',\n 'updateTriggerPushNotifications',\n 'deletePushNotificationLinks',\n] as const;\n\nexport type NotificationServicesPushControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type Actions =\n | NotificationServicesPushControllerGetStateAction\n | NotificationServicesPushControllerMethodActions;\n\ntype AllowedActions =\n AuthenticationController.AuthenticationControllerGetBearerTokenAction;\n\nexport type NotificationServicesPushControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n NotificationServicesPushControllerState\n >;\n\nexport type NotificationServicesPushControllerOnNewNotificationEvent = {\n type: `${typeof controllerName}:onNewNotifications`;\n payload: [PushAnalyticsPayload];\n};\n\nexport type NotificationServicesPushControllerPushNotificationClickedEvent = {\n type: `${typeof controllerName}:pushNotificationClicked`;\n payload: [PushAnalyticsPayload];\n};\n\nexport type Events =\n | NotificationServicesPushControllerStateChangeEvent\n | NotificationServicesPushControllerOnNewNotificationEvent\n | NotificationServicesPushControllerPushNotificationClickedEvent;\n\nexport type NotificationServicesPushControllerMessenger = Messenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events\n>;\n\nexport const defaultState: NotificationServicesPushControllerState = {\n isPushEnabled: true,\n fcmToken: '',\n isUpdatingFCMToken: false,\n};\nconst metadata: StateMetadata<NotificationServicesPushControllerState> = {\n isPushEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n fcmToken: {\n includeInStateLogs: false,\n persist: true,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n isUpdatingFCMToken: {\n includeInStateLogs: false,\n persist: false,\n includeInDebugSnapshot: true,\n usedInUi: true,\n },\n};\n\nconst defaultPushEnv: PushNotificationEnv = {\n apiKey: '',\n authDomain: '',\n storageBucket: '',\n projectId: '',\n messagingSenderId: '',\n appId: '',\n measurementId: '',\n vapidKey: '',\n};\n\nexport type ControllerConfig = {\n /**\n * User locale for server push notifications\n */\n getLocale?: () => string;\n\n /**\n * App or extension version to include when registering push tokens.\n */\n appVersion?: string;\n\n /**\n * Global switch to determine to use push notifications\n * Allows us to control Builds on extension (MV2 vs MV3)\n */\n isPushFeatureEnabled?: boolean;\n\n /**\n * determine the config used for push notification services\n */\n platform: 'extension' | 'mobile';\n\n /**\n * Mobile operating system to include when registering push tokens.\n */\n os?: 'android' | 'ios';\n\n /**\n * Push Service Interface\n * - create reg token\n * - delete reg token\n * - subscribe to push notifications\n */\n pushService: PushService;\n\n env?: ENV;\n};\n\ntype StateCommand =\n | { type: 'enable'; fcmToken: string }\n | { type: 'disable' }\n | { type: 'update'; fcmToken: string };\n\ntype RegistrationTokenMetadata = Pick<\n RegToken,\n 'appVersion' | 'locale' | 'os' | 'platform'\n>;\n\n/**\n * Manages push notifications for the application, including enabling, disabling, and updating triggers for push notifications.\n * This controller integrates with Firebase Cloud Messaging (FCM) to handle the registration and management of push notifications.\n * It is responsible for registering and unregistering the service worker that listens for push notifications,\n * managing the FCM token, and communicating with the server to register or unregister the device for push notifications.\n * Additionally, it provides functionality to update the server with new UUIDs that should trigger push notifications.\n */\nexport class NotificationServicesPushController extends BaseController<\n typeof controllerName,\n NotificationServicesPushControllerState,\n NotificationServicesPushControllerMessenger\n> {\n #pushListenerUnsubscribe: (() => void) | undefined = undefined;\n\n readonly #env: PushNotificationEnv;\n\n readonly #config: ControllerConfig;\n\n constructor({\n messenger,\n state,\n env,\n config,\n }: {\n messenger: NotificationServicesPushControllerMessenger;\n state: NotificationServicesPushControllerState;\n /** Push Environment is only required for extension */\n env?: PushNotificationEnv;\n config: ControllerConfig;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#env = env ?? defaultPushEnv;\n this.#config = config;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n this.#clearLoadingStates();\n }\n\n #clearLoadingStates(): void {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n async #getAndAssertBearerToken(): Promise<string> {\n const bearerToken = await this.messenger.call(\n 'AuthenticationController:getBearerToken',\n );\n if (!bearerToken) {\n throw new Error('BearerToken token is missing');\n }\n\n return bearerToken;\n }\n\n #updatePushState(command: StateCommand): void {\n if (command.type === 'enable') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'disable') {\n this.update((state) => {\n // Note we do not want to clear the old FCM token\n // We can send it as an old token to our backend to cleanup next time turned on\n state.isPushEnabled = false;\n state.isUpdatingFCMToken = false;\n });\n }\n\n if (command.type === 'update') {\n this.update((state) => {\n state.isPushEnabled = true;\n state.fcmToken = command.fcmToken;\n state.isUpdatingFCMToken = false;\n });\n }\n }\n\n #getRegistrationTokenMetadata(): RegistrationTokenMetadata {\n const tokenMetadata: RegistrationTokenMetadata = {\n platform: this.#config.platform,\n locale: this.#config.getLocale?.() ?? 'en',\n };\n\n if (this.#config.os) {\n tokenMetadata.os = this.#config.os;\n }\n\n if (this.#config.appVersion) {\n tokenMetadata.appVersion = this.#config.appVersion;\n }\n\n return tokenMetadata;\n }\n\n public async subscribeToPushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n if (this.#pushListenerUnsubscribe) {\n this.#pushListenerUnsubscribe();\n this.#pushListenerUnsubscribe = undefined;\n }\n\n try {\n this.#pushListenerUnsubscribe =\n (await this.#config.pushService.subscribeToPushNotifications(\n this.#env,\n )) ?? undefined;\n } catch {\n // Do nothing, we are silently failing if push notification registration fails\n }\n }\n\n /**\n * Enables push notifications for the application.\n *\n * This method sets up the necessary infrastructure for handling push notifications by:\n * 1. Registering the service worker to listen for messages.\n * 2. Fetching the Firebase Cloud Messaging (FCM) token from Firebase.\n * 3. Sending the FCM token to the server responsible for sending notifications, to register the device.\n *\n * @param addresses - An array of addresses to enable push notifications for.\n */\n public async enablePushNotifications(addresses: string[]): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n // Handle creating new reg token (if available)\n try {\n const bearerToken = await this.#getAndAssertBearerToken().catch(\n () => null,\n );\n\n // If there is a bearer token, lets try to refresh/create new reg token\n if (bearerToken) {\n // Activate Push Notifications\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n ...this.#getRegistrationTokenMetadata(),\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n if (fcmToken) {\n this.#updatePushState({ type: 'enable', fcmToken });\n }\n }\n } catch {\n // Do nothing, we are silently failing\n }\n\n // New token created, (re)subscribe to push notifications\n try {\n await this.subscribeToPushNotifications();\n } catch {\n // Do nothing we are silently failing\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n /**\n * Disables push notifications for the application.\n * This removes the registration token on this device, and ensures we unsubscribe from any listeners\n */\n public async disablePushNotifications(): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n // Send a request to the server to unregister the token/device\n await deactivatePushNotifications({\n env: this.#env,\n deleteRegToken: this.#config.pushService.deleteRegToken,\n regToken: this.state.fcmToken,\n });\n } catch (error) {\n const errorMessage = `Failed to disable push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n\n // Unsubscribe from push notifications\n this.#pushListenerUnsubscribe?.();\n\n // Update State\n this.#updatePushState({ type: 'disable' });\n }\n\n /**\n * Adds backend push notification links for the given addresses using the current FCM token.\n * This is used when accounts are added after push notifications have already been enabled,\n * so backend can link the existing device token to the newly added addresses.\n *\n * @param addresses - Addresses that should be linked to push notifications.\n * @returns Whether the add request succeeded.\n */\n public async addPushNotificationLinks(addresses: string[]): Promise<boolean> {\n if (\n !this.#config.isPushFeatureEnabled ||\n addresses.length === 0 ||\n !this.state.fcmToken\n ) {\n return false;\n }\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n return await updateLinksAPI({\n bearerToken,\n addresses,\n regToken: {\n token: this.state.fcmToken,\n ...this.#getRegistrationTokenMetadata(),\n },\n env: this.#config.env ?? 'prd',\n });\n } catch {\n return false;\n }\n }\n\n /**\n * Deletes backend push notification links for the given addresses on the current platform.\n * This is used when accounts are removed (for example SRP removal), so backend can remove\n * all associated FCM tokens for those address/platform pairs.\n *\n * @param addresses - Addresses that should be unlinked from push notifications.\n * @returns Whether the delete request succeeded.\n */\n public async deletePushNotificationLinks(\n addresses: string[],\n ): Promise<boolean> {\n if (\n !this.#config.isPushFeatureEnabled ||\n addresses.length === 0 ||\n !this.state.fcmToken\n ) {\n return false;\n }\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n return await deleteLinksAPI({\n bearerToken,\n addresses,\n platform: this.#config.platform,\n token: this.state.fcmToken,\n env: this.#config.env ?? 'prd',\n });\n } catch {\n return false;\n }\n }\n\n /**\n * Updates the triggers for push notifications.\n * This method is responsible for updating the server with the new set of addresses that should trigger push notifications.\n * It uses the current FCM token and a BearerToken for authentication.\n *\n * @param addresses - An array of addresses that should trigger push notifications.\n * @deprecated - this is not used anymore and will most likely be removed\n */\n public async updateTriggerPushNotifications(\n addresses: string[],\n ): Promise<void> {\n if (!this.#config.isPushFeatureEnabled) {\n return;\n }\n\n this.update((state) => {\n state.isUpdatingFCMToken = true;\n });\n\n try {\n const bearerToken = await this.#getAndAssertBearerToken();\n const fcmToken = await activatePushNotifications({\n bearerToken,\n addresses,\n env: this.#env,\n createRegToken: this.#config.pushService.createRegToken,\n regToken: {\n ...this.#getRegistrationTokenMetadata(),\n oldToken: this.state.fcmToken,\n },\n controllerEnv: this.#config.env ?? 'prd',\n });\n\n // update the state with the new FCM token\n if (fcmToken) {\n this.#updatePushState({ type: 'update', fcmToken });\n }\n } catch (error) {\n const errorMessage = `Failed to update triggers for push notifications: ${\n error as string\n }`;\n log.error(errorMessage);\n throw new Error(errorMessage);\n } finally {\n this.update((state) => {\n state.isUpdatingFCMToken = false;\n });\n }\n }\n}\n"]}
@@ -2,10 +2,9 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
4
  import type { AuthenticationController } from "@metamask/profile-sync-controller";
5
- import type { Types } from "../NotificationServicesController/index.cjs";
6
5
  import type { NotificationServicesPushControllerMethodActions } from "./NotificationServicesPushController-method-action-types.cjs";
7
6
  import type { ENV } from "./services/endpoints.cjs";
8
- import type { PushNotificationEnv } from "./types/index.cjs";
7
+ import type { PushAnalyticsPayload, PushNotificationEnv } from "./types/index.cjs";
9
8
  import type { PushService } from "./types/push-service-interface.cjs";
10
9
  declare const controllerName = "NotificationServicesPushController";
11
10
  export type NotificationServicesPushControllerState = {
@@ -19,11 +18,11 @@ type AllowedActions = AuthenticationController.AuthenticationControllerGetBearer
19
18
  export type NotificationServicesPushControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, NotificationServicesPushControllerState>;
20
19
  export type NotificationServicesPushControllerOnNewNotificationEvent = {
21
20
  type: `${typeof controllerName}:onNewNotifications`;
22
- payload: [Types.INotification];
21
+ payload: [PushAnalyticsPayload];
23
22
  };
24
23
  export type NotificationServicesPushControllerPushNotificationClickedEvent = {
25
24
  type: `${typeof controllerName}:pushNotificationClicked`;
26
- payload: [Types.INotification];
25
+ payload: [PushAnalyticsPayload];
27
26
  };
28
27
  export type Events = NotificationServicesPushControllerStateChangeEvent | NotificationServicesPushControllerOnNewNotificationEvent | NotificationServicesPushControllerPushNotificationClickedEvent;
29
28
  export type NotificationServicesPushControllerMessenger = Messenger<typeof controllerName, Actions | AllowedActions, Events>;
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController.d.cts","sourceRoot":"","sources":["../../src/NotificationServic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C,OAAO,CAAC;IAyB5E;;;;;;;OAOG;IACU,2BAA2B,CACtC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,OAAO,CAAC;IAuBnB;;;;;;;OAOG;IACU,8BAA8B,CACzC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,IAAI,CAAC;CAuCjB"}
1
+ {"version":3,"file":"NotificationServicesPushController.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAGlF,OAAO,KAAK,EAAE,+CAA+C,EAAE,qEAAiE;AAChI,OAAO,KAAK,EAAE,GAAG,EAAE,iCAA6B;AAQhD,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,0BAAgB;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,2CAAuC;AAElE,QAAA,MAAM,cAAc,uCAAuC,CAAC;AAE5D,MAAM,MAAM,uCAAuC,GAAG;IACpD,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAWF,MAAM,MAAM,gDAAgD,GAC1D,wBAAwB,CACtB,OAAO,cAAc,EACrB,uCAAuC,CACxC,CAAC;AAEJ,MAAM,MAAM,OAAO,GACf,gDAAgD,GAChD,+CAA+C,CAAC;AAEpD,KAAK,cAAc,GACjB,wBAAwB,CAAC,4CAA4C,CAAC;AAExE,MAAM,MAAM,kDAAkD,GAC5D,0BAA0B,CACxB,OAAO,cAAc,EACrB,uCAAuC,CACxC,CAAC;AAEJ,MAAM,MAAM,wDAAwD,GAAG;IACrE,IAAI,EAAE,GAAG,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;;;;;;;;OASG;IACU,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkDxE;;;OAGG;IACU,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCtD;;;;;;;OAOG;IACU,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAyB5E;;;;;;;OAOG;IACU,2BAA2B,CACtC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,OAAO,CAAC;IAuBnB;;;;;;;OAOG;IACU,8BAA8B,CACzC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,IAAI,CAAC;CAuCjB"}
@@ -2,10 +2,9 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
4
  import type { AuthenticationController } from "@metamask/profile-sync-controller";
5
- import type { Types } from "../NotificationServicesController/index.mjs";
6
5
  import type { NotificationServicesPushControllerMethodActions } from "./NotificationServicesPushController-method-action-types.mjs";
7
6
  import type { ENV } from "./services/endpoints.mjs";
8
- import type { PushNotificationEnv } from "./types/index.mjs";
7
+ import type { PushAnalyticsPayload, PushNotificationEnv } from "./types/index.mjs";
9
8
  import type { PushService } from "./types/push-service-interface.mjs";
10
9
  declare const controllerName = "NotificationServicesPushController";
11
10
  export type NotificationServicesPushControllerState = {
@@ -19,11 +18,11 @@ type AllowedActions = AuthenticationController.AuthenticationControllerGetBearer
19
18
  export type NotificationServicesPushControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, NotificationServicesPushControllerState>;
20
19
  export type NotificationServicesPushControllerOnNewNotificationEvent = {
21
20
  type: `${typeof controllerName}:onNewNotifications`;
22
- payload: [Types.INotification];
21
+ payload: [PushAnalyticsPayload];
23
22
  };
24
23
  export type NotificationServicesPushControllerPushNotificationClickedEvent = {
25
24
  type: `${typeof controllerName}:pushNotificationClicked`;
26
- payload: [Types.INotification];
25
+ payload: [PushAnalyticsPayload];
27
26
  };
28
27
  export type Events = NotificationServicesPushControllerStateChangeEvent | NotificationServicesPushControllerOnNewNotificationEvent | NotificationServicesPushControllerPushNotificationClickedEvent;
29
28
  export type NotificationServicesPushControllerMessenger = Messenger<typeof controllerName, Actions | AllowedActions, Events>;
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAGlF,OAAO,KAAK,EAAE,KAAK,EAAE,oDAA0C;AAC/D,OAAO,KAAK,EAAE,+CAA+C,EAAE,qEAAiE;AAChI,OAAO,KAAK,EAAE,GAAG,EAAE,iCAA6B;AAQhD,OAAO,KAAK,EAAE,mBAAmB,EAAE,0BAAgB;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,2CAAuC;AAElE,QAAA,MAAM,cAAc,uCAAuC,CAAC;AAE5D,MAAM,MAAM,uCAAuC,GAAG;IACpD,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAWF,MAAM,MAAM,gDAAgD,GAC1D,wBAAwB,CACtB,OAAO,cAAc,EACrB,uCAAuC,CACxC,CAAC;AAEJ,MAAM,MAAM,OAAO,GACf,gDAAgD,GAChD,+CAA+C,CAAC;AAEpD,KAAK,cAAc,GACjB,wBAAwB,CAAC,4CAA4C,CAAC;AAExE,MAAM,MAAM,kDAAkD,GAC5D,0BAA0B,CACxB,OAAO,cAAc,EACrB,uCAAuC,CACxC,CAAC;AAE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AAgB,CAAC;KAC1B;IAgFY,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB1D;;;;;;;;;OASG;IACU,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkDxE;;;OAGG;IACU,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAmCtD;;;;;;;OAOG;IACU,wBAAwB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAyB5E;;;;;;;OAOG;IACU,2BAA2B,CACtC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,OAAO,CAAC;IAuBnB;;;;;;;OAOG;IACU,8BAA8B,CACzC,SAAS,EAAE,MAAM,EAAE,GAClB,OAAO,CAAC,IAAI,CAAC;CAuCjB"}
1
+ {"version":3,"file":"NotificationServicesPushController.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,wBAAwB,EAAE,0CAA0C;AAGlF,OAAO,KAAK,EAAE,+CAA+C,EAAE,qEAAiE;AAChI,OAAO,KAAK,EAAE,GAAG,EAAE,iCAA6B;AAQhD,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,0BAAgB;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,2CAAuC;AAElE,QAAA,MAAM,cAAc,uCAAuC,CAAC;AAE5D,MAAM,MAAM,uCAAuC,GAAG;IACpD,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,CAAC;AAWF,MAAM,MAAM,gDAAgD,GAC1D,wBAAwB,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