@metamask/notification-services-controller 23.0.0 → 23.1.0

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 (82) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs +1 -1
  3. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.cjs.map +1 -1
  4. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.cts +1 -1
  5. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.mts +1 -1
  6. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.mjs +1 -1
  7. package/dist/NotificationServicesController/NotificationServicesController-method-action-types.mjs.map +1 -1
  8. package/dist/NotificationServicesController/NotificationServicesController.cjs +9 -0
  9. package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
  10. package/dist/NotificationServicesController/NotificationServicesController.d.cts +2 -2
  11. package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
  12. package/dist/NotificationServicesController/NotificationServicesController.d.mts +2 -2
  13. package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
  14. package/dist/NotificationServicesController/NotificationServicesController.mjs +9 -0
  15. package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
  16. package/dist/NotificationServicesController/mocks/mockResponses.cjs +2 -2
  17. package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
  18. package/dist/NotificationServicesController/mocks/mockResponses.mjs +2 -2
  19. package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
  20. package/dist/NotificationServicesController/processors/process-api-notifications.cjs.map +1 -1
  21. package/dist/NotificationServicesController/processors/process-api-notifications.d.cts +1 -1
  22. package/dist/NotificationServicesController/processors/process-api-notifications.d.cts.map +1 -1
  23. package/dist/NotificationServicesController/processors/process-api-notifications.d.mts +1 -1
  24. package/dist/NotificationServicesController/processors/process-api-notifications.d.mts.map +1 -1
  25. package/dist/NotificationServicesController/processors/process-api-notifications.mjs.map +1 -1
  26. package/dist/NotificationServicesController/processors/process-notifications.cjs +1 -1
  27. package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
  28. package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
  29. package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
  30. package/dist/NotificationServicesController/processors/process-notifications.mjs +1 -1
  31. package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
  32. package/dist/NotificationServicesController/services/api-notifications.cjs +1 -1
  33. package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
  34. package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
  35. package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
  36. package/dist/NotificationServicesController/services/api-notifications.mjs +1 -1
  37. package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
  38. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.cjs.map +1 -1
  39. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.cts +1 -1
  40. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.cts.map +1 -1
  41. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.mts +1 -1
  42. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.d.mts.map +1 -1
  43. package/dist/NotificationServicesController/types/feature-announcement/feature-announcement.mjs.map +1 -1
  44. package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -1
  45. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +1 -1
  46. package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -1
  47. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +1 -1
  48. package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -1
  49. package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -1
  50. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.cjs +1 -1
  51. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.cjs.map +1 -1
  52. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.cts +14 -2
  53. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.cts.map +1 -1
  54. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.mts +14 -2
  55. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.d.mts.map +1 -1
  56. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.mjs +1 -1
  57. package/dist/NotificationServicesPushController/NotificationServicesPushController-method-action-types.mjs.map +1 -1
  58. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +32 -0
  59. package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
  60. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +10 -1
  61. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
  62. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +10 -1
  63. package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
  64. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +33 -1
  65. package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
  66. package/dist/NotificationServicesPushController/index.cjs.map +1 -1
  67. package/dist/NotificationServicesPushController/index.d.cts +1 -1
  68. package/dist/NotificationServicesPushController/index.d.cts.map +1 -1
  69. package/dist/NotificationServicesPushController/index.d.mts +1 -1
  70. package/dist/NotificationServicesPushController/index.d.mts.map +1 -1
  71. package/dist/NotificationServicesPushController/index.mjs.map +1 -1
  72. package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
  73. package/dist/NotificationServicesPushController/services/services.d.cts +1 -1
  74. package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
  75. package/dist/NotificationServicesPushController/services/services.d.mts +1 -1
  76. package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
  77. package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
  78. package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
  79. package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
  80. package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
  81. package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
  82. package/package.json +23 -24
@@ -1 +1 @@
1
- {"version":3,"file":"process-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,wCAAoC;AACtE,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC3B,2CAAuC;AACxC,OAAO,EAAE,uBAAuB,EAAE,yCAAqC;AACvE,OAAO,EACL,aAAa,EACb,kCAAkC,EACnC,6CAAyC;AAS1C,MAAM,qBAAqB,GAAG,CAC5B,YAAkC,EACS,EAAE,CAC7C,kCAAkC,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AAE5D,MAAM,qBAAqB,GAAG,CAC5B,YAAkC,EACkB,EAAE,CACtD,YAAY,CAAC,IAAI,KAAK,aAAa,CAAC,qBAAqB,CAAC;AAE5D,MAAM,kBAAkB,GAAG,CACzB,YAAkC,EACG,EAAE,CACvC,YAAY,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAkC,EAClC,oBAA8B,EAAE;IAEhC,MAAM,iBAAiB,GAAG,CAAC,cAAqB,EAAS,EAAE;QACzD,MAAM,IAAI,GAAW,YAAY,EAAE,IAAI,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,4CAA4C,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC;IAEF,IAAI,qBAAqB,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC,YAAY,CAAC,CAAC;QACvE,qBAAqB,CAAC,MAAM,GAAG,yBAAyB,CACtD,qBAAqB,EACrB,iBAAiB,CAClB,CAAC;QACF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED,IAAI,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC;QACrC,OAAO,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,qBAAqB,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,OAAO,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,iBAAiB,CAAC,YAAY,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAAkC,EAClC,oBAA8B,EAAE;IAEhC,IAAI,CAAC;QACH,MAAM,qBAAqB,GAAG,mBAAmB,CAC/C,YAAY,EACZ,iBAAiB,CAClB,CAAC;QACF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,cAAc,GAAG,CAAO,IAAW,EAAgB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1E,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,aAAqC,EACrC,OAAiB,EACA,EAAE,CACnB,aAAa;KACV,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,uBAAuB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;KACrE,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { processAPINotifications } from './process-api-notifications';\nimport {\n isFeatureAnnouncementRead,\n processFeatureAnnouncement,\n} from './process-feature-announcement';\nimport { processSnapNotification } from './process-snap-notifications';\nimport {\n TRIGGER_TYPES,\n NOTIFICATION_API_TRIGGER_TYPES_SET,\n} from '../constants/notification-schema';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type {\n INotification,\n RawNotificationUnion,\n} from '../types/notification/notification';\nimport type { NormalisedAPINotification } from '../types/notification-api/notification-api';\nimport type { RawSnapNotification } from '../types/snaps';\n\nconst isOnChainNotification = (\n notification: RawNotificationUnion,\n): notification is NormalisedAPINotification =>\n NOTIFICATION_API_TRIGGER_TYPES_SET.has(notification.type);\n\nconst isFeatureAnnouncement = (\n notification: RawNotificationUnion,\n): notification is FeatureAnnouncementRawNotification =>\n notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n\nconst isSnapNotification = (\n notification: RawNotificationUnion,\n): notification is RawSnapNotification =>\n notification.type === TRIGGER_TYPES.SNAP;\n\n/**\n * Process feature announcement and wallet notifications into a shared/normalised notification shape.\n * We can still differentiate notifications by the `type` property\n *\n * @param notification - a feature announcement or on chain notification\n * @param readNotifications - all read notifications currently\n * @returns a processed notification\n */\nexport function processNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification {\n const exhaustedAllCases = (_uncheckedCase: never): never => {\n const type: string = notification?.type;\n throw new Error(`No processor found for notification kind ${type}`);\n };\n\n if (isFeatureAnnouncement(notification)) {\n const processedNotification = processFeatureAnnouncement(notification);\n processedNotification.isRead = isFeatureAnnouncementRead(\n processedNotification,\n readNotifications,\n );\n return processedNotification;\n }\n\n if (isSnapNotification(notification)) {\n return processSnapNotification(notification);\n }\n\n if (isOnChainNotification(notification)) {\n return processAPINotifications(notification);\n }\n\n return exhaustedAllCases(notification);\n}\n\n/**\n * Safe version of processing a notification. Rather than throwing an error if failed to process, it will return the Notification or undefined\n *\n * @param notification - notification to processes\n * @param readNotifications - all read notifications currently\n * @returns a process notification or undefined if failed to process\n */\nexport function safeProcessNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification | undefined {\n try {\n const processedNotification = processNotification(\n notification,\n readNotifications,\n );\n return processedNotification;\n } catch {\n return undefined;\n }\n}\n\nconst isNotUndefined = <Item>(item?: Item): item is Item => Boolean(item);\nexport const processAndFilterNotifications = (\n notifications: RawNotificationUnion[],\n readIds: string[],\n): INotification[] =>\n notifications\n .map((notification) => safeProcessNotification(notification, readIds))\n .filter(isNotUndefined);\n"]}
1
+ {"version":3,"file":"process-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kCAAkC,EACnC,6CAAyC;AAQ1C,OAAO,EAAE,uBAAuB,EAAE,wCAAoC;AACtE,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC3B,2CAAuC;AACxC,OAAO,EAAE,uBAAuB,EAAE,yCAAqC;AAEvE,MAAM,qBAAqB,GAAG,CAC5B,YAAkC,EACS,EAAE,CAC7C,kCAAkC,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;AAE5D,MAAM,qBAAqB,GAAG,CAC5B,YAAkC,EACkB,EAAE,CACtD,YAAY,CAAC,IAAI,KAAK,aAAa,CAAC,qBAAqB,CAAC;AAE5D,MAAM,kBAAkB,GAAG,CACzB,YAAkC,EACG,EAAE,CACvC,YAAY,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC;AAE3C;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,YAAkC,EAClC,oBAA8B,EAAE;IAEhC,MAAM,iBAAiB,GAAG,CAAC,cAAqB,EAAS,EAAE;QACzD,MAAM,IAAI,GAAW,YAAY,EAAE,IAAI,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,4CAA4C,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC;IAEF,IAAI,qBAAqB,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,MAAM,qBAAqB,GAAG,0BAA0B,CAAC,YAAY,CAAC,CAAC;QACvE,qBAAqB,CAAC,MAAM,GAAG,yBAAyB,CACtD,qBAAqB,EACrB,iBAAiB,CAClB,CAAC;QACF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED,IAAI,kBAAkB,CAAC,YAAY,CAAC,EAAE,CAAC;QACrC,OAAO,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,IAAI,qBAAqB,CAAC,YAAY,CAAC,EAAE,CAAC;QACxC,OAAO,uBAAuB,CAAC,YAAY,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,iBAAiB,CAAC,YAAY,CAAC,CAAC;AACzC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,YAAkC,EAClC,oBAA8B,EAAE;IAEhC,IAAI,CAAC;QACH,MAAM,qBAAqB,GAAG,mBAAmB,CAC/C,YAAY,EACZ,iBAAiB,CAClB,CAAC;QACF,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,cAAc,GAAG,CAAO,IAAW,EAAgB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1E,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,aAAqC,EACrC,OAAiB,EACA,EAAE,CACnB,aAAa;KACV,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,uBAAuB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;KACrE,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import {\n TRIGGER_TYPES,\n NOTIFICATION_API_TRIGGER_TYPES_SET,\n} from '../constants/notification-schema';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement';\nimport type { NormalisedAPINotification } from '../types/notification-api/notification-api';\nimport type {\n INotification,\n RawNotificationUnion,\n} from '../types/notification/notification';\nimport type { RawSnapNotification } from '../types/snaps';\nimport { processAPINotifications } from './process-api-notifications';\nimport {\n isFeatureAnnouncementRead,\n processFeatureAnnouncement,\n} from './process-feature-announcement';\nimport { processSnapNotification } from './process-snap-notifications';\n\nconst isOnChainNotification = (\n notification: RawNotificationUnion,\n): notification is NormalisedAPINotification =>\n NOTIFICATION_API_TRIGGER_TYPES_SET.has(notification.type);\n\nconst isFeatureAnnouncement = (\n notification: RawNotificationUnion,\n): notification is FeatureAnnouncementRawNotification =>\n notification.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n\nconst isSnapNotification = (\n notification: RawNotificationUnion,\n): notification is RawSnapNotification =>\n notification.type === TRIGGER_TYPES.SNAP;\n\n/**\n * Process feature announcement and wallet notifications into a shared/normalised notification shape.\n * We can still differentiate notifications by the `type` property\n *\n * @param notification - a feature announcement or on chain notification\n * @param readNotifications - all read notifications currently\n * @returns a processed notification\n */\nexport function processNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification {\n const exhaustedAllCases = (_uncheckedCase: never): never => {\n const type: string = notification?.type;\n throw new Error(`No processor found for notification kind ${type}`);\n };\n\n if (isFeatureAnnouncement(notification)) {\n const processedNotification = processFeatureAnnouncement(notification);\n processedNotification.isRead = isFeatureAnnouncementRead(\n processedNotification,\n readNotifications,\n );\n return processedNotification;\n }\n\n if (isSnapNotification(notification)) {\n return processSnapNotification(notification);\n }\n\n if (isOnChainNotification(notification)) {\n return processAPINotifications(notification);\n }\n\n return exhaustedAllCases(notification);\n}\n\n/**\n * Safe version of processing a notification. Rather than throwing an error if failed to process, it will return the Notification or undefined\n *\n * @param notification - notification to processes\n * @param readNotifications - all read notifications currently\n * @returns a process notification or undefined if failed to process\n */\nexport function safeProcessNotification(\n notification: RawNotificationUnion,\n readNotifications: string[] = [],\n): INotification | undefined {\n try {\n const processedNotification = processNotification(\n notification,\n readNotifications,\n );\n return processedNotification;\n } catch {\n return undefined;\n }\n}\n\nconst isNotUndefined = <Item>(item?: Item): item is Item => Boolean(item);\nexport const processAndFilterNotifications = (\n notifications: RawNotificationUnion[],\n readIds: string[],\n): INotification[] =>\n notifications\n .map((notification) => safeProcessNotification(notification, readIds))\n .filter(isNotUndefined);\n"]}
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.markNotificationsAsRead = exports.getAPINotifications = exports.updateOnChainNotifications = exports.getNotificationsApiConfigCached = exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = exports.NOTIFICATION_API_LIST_ENDPOINT = exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = exports.NOTIFICATION_API = exports.TRIGGER_API = void 0;
7
7
  const loglevel_1 = __importDefault(require("loglevel"));
8
- const notification_config_cache_1 = require("./notification-config-cache.cjs");
9
8
  const to_raw_notification_1 = require("../../shared/to-raw-notification.cjs");
10
9
  const utils_1 = require("../utils/utils.cjs");
10
+ const notification_config_cache_1 = require("./notification-config-cache.cjs");
11
11
  const TRIGGER_API_ENV = {
12
12
  dev: 'https://trigger.dev-api.cx.metamask.io',
13
13
  uat: 'https://trigger.uat-api.cx.metamask.io',
@@ -1 +1 @@
1
- {"version":3,"file":"api-notifications.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA2B;AAE3B,+EAAuE;AACvE,8EAAwE;AAMxE,8CAA6C;AAW7C,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEzB,MAAM,WAAW,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACtD,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AADjC,QAAA,WAAW,eACsB;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,yCAAyC;CAC/C,CAAC;AAEK,MAAM,gBAAgB,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CAC3D,oBAAoB,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,GAAG,C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AI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAID,MAAM,IAAI,GAAiB;QACzB,GAAG,EAAE,eAAe;KACrB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,IAAA,mBAAW,EACf,WAAW,EACX,IAAA,kDAA0C,EAAC,GAAG,CAAC,EAC/C,MAAM,EACN,IAAI,CACL,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,kBAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAzBD,0DAyBC","sourcesContent":["import log from 'loglevel';\n\nimport { notificationsConfigCache } from './notification-config-cache';\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type {\n NormalisedAPINotification,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api';\nimport { makeApiCall } from '../utils/utils';\n\nexport type NotificationTrigger = {\n id: string;\n chainId: string;\n kind: string;\n address: string;\n};\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd'): string =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd'): string =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd'): string =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Marks notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;\n\n/**\n * fetches notification config (accounts enabled vs disabled)\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * NOTE the API will return addresses config with false if they have not been created before.\n * NOTE this is cached for 1s to prevent multiple update calls\n * @returns object of notification config, or null if missing\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n): Promise<{ address: string; enabled: boolean }[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n const normalizedAddresses = addresses.map((addr) => addr.toLowerCase());\n\n const cached = notificationsConfigCache.get(normalizedAddresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses.map((address) => ({ address }));\n const apiResponse = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((response) => (response.ok ? response.json() : null))\n .catch(() => null);\n\n const result = apiResponse ?? [];\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * updates notifications for a given addresses\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n): Promise<void> {\n if (addresses.length === 0) {\n return;\n }\n\n const normalizedAddresses = addresses.map((item) => ({\n ...item,\n address: item.address.toLowerCase(),\n }));\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(normalizedAddresses))\n .catch(() => null);\n}\n\n/**\n * Fetches on-chain notifications for the given addresses\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param addresses - List of addresses\n * @param locale - to generate translated notifications\n * @param platform - filter notifications for specific platforms ('extension' | 'mobile')\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.\n */\nexport async function getAPINotifications(\n bearerToken: string,\n addresses: string[],\n locale: string,\n platform: 'extension' | 'mobile',\n env: ENV = 'prd',\n): Promise<NormalisedAPINotification[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n type RequestBody =\n Schema.paths['/api/v3/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v3/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((addr) => addr.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(\n bearerToken,\n NOTIFICATION_API_LIST_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<APIResponse | null>((response) =>\n response.ok ? response.json() : null,\n )\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((notification): UnprocessedRawNotification | undefined => {\n if (!notification.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(notification);\n } catch {\n return undefined;\n }\n })\n .filter((item): item is NormalisedAPINotification => Boolean(item));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v3/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(\n bearerToken,\n NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env),\n 'POST',\n body,\n );\n } catch (error) {\n log.error('Error marking notifications as read:', error);\n }\n}\n"]}
1
+ {"version":3,"file":"api-notifications.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA2B;AAE3B,8EAAwE;AAMxE,8CAA6C;AAC7C,+EAAuE;AAWvE,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEzB,MAAM,WAAW,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACtD,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AADjC,QAAA,WAAW,eACsB;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,yCAAyC;CAC/C,CAAC;AAEK,MAAM,gBAAgB,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CAC3D,oBAAoB,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,GAAG,CAAC;AAD3C,QAAA,gBAAgB,oBAC2B;AAExD,uDAAuD;AAChD,MAAM,wCAAwC,GAAG,CACtD,MAAW,KAAK,EACR,EAAE,CAAC,GA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Ae;KACrB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,IAAA,mBAAW,EACf,WAAW,EACX,IAAA,kDAA0C,EAAC,GAAG,CAAC,EAC/C,MAAM,EACN,IAAI,CACL,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,kBAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC;AAzBD,0DAyBC","sourcesContent":["import log from 'loglevel';\n\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type {\n NormalisedAPINotification,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api';\nimport { makeApiCall } from '../utils/utils';\nimport { notificationsConfigCache } from './notification-config-cache';\n\nexport type NotificationTrigger = {\n id: string;\n chainId: string;\n kind: string;\n address: string;\n};\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd'): string =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd'): string =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd'): string =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Marks notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;\n\n/**\n * fetches notification config (accounts enabled vs disabled)\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * NOTE the API will return addresses config with false if they have not been created before.\n * NOTE this is cached for 1s to prevent multiple update calls\n * @returns object of notification config, or null if missing\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n): Promise<{ address: string; enabled: boolean }[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n const normalizedAddresses = addresses.map((addr) => addr.toLowerCase());\n\n const cached = notificationsConfigCache.get(normalizedAddresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses.map((address) => ({ address }));\n const apiResponse = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((response) => (response.ok ? response.json() : null))\n .catch(() => null);\n\n const result = apiResponse ?? [];\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * updates notifications for a given addresses\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n): Promise<void> {\n if (addresses.length === 0) {\n return;\n }\n\n const normalizedAddresses = addresses.map((item) => ({\n ...item,\n address: item.address.toLowerCase(),\n }));\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(normalizedAddresses))\n .catch(() => null);\n}\n\n/**\n * Fetches on-chain notifications for the given addresses\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param addresses - List of addresses\n * @param locale - to generate translated notifications\n * @param platform - filter notifications for specific platforms ('extension' | 'mobile')\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.\n */\nexport async function getAPINotifications(\n bearerToken: string,\n addresses: string[],\n locale: string,\n platform: 'extension' | 'mobile',\n env: ENV = 'prd',\n): Promise<NormalisedAPINotification[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n type RequestBody =\n Schema.paths['/api/v3/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v3/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((addr) => addr.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(\n bearerToken,\n NOTIFICATION_API_LIST_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<APIResponse | null>((response) =>\n response.ok ? response.json() : null,\n )\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((notification): UnprocessedRawNotification | undefined => {\n if (!notification.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(notification);\n } catch {\n return undefined;\n }\n })\n .filter((item): item is NormalisedAPINotification => Boolean(item));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v3/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(\n bearerToken,\n NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env),\n 'POST',\n body,\n );\n } catch (error) {\n log.error('Error marking notifications as read:', error);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"api-notifications.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,yBAAyB,EAG1B,4CAAkC;AAGnC,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,WAAW,SAAS,GAAG,KAAW,MACF,CAAC;AAQ9C,eAAO,MAAM,gBAAgB,SAAS,GAAG,KAAW,MACG,CAAC;AAGxD,eAAO,MAAM,wCAAwC,SAC9C,GAAG,KACP,MAA0D,CAAC;AAG9D,eAAO,MAAM,kCAAkC,SAAS,GAAG,KAAW,MAC1B,CAAC;AAG7C,eAAO,MAAM,8BAA8B,SAAS,GAAG,KAAW,MACjB,CAAC;AAGlD,eAAO,MAAM,0CAA0C,SAChD,GAAG,KACP,MAAsE,CAAC;AAE1E;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CA+BlD;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,EAClD,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,yBAAyB,EAAE,CAAC,CA0CtC;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf"}
1
+ {"version":3,"file":"api-notifications.d.cts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,yBAAyB,EAG1B,4CAAkC;AAInC,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,WAAW,SAAS,GAAG,KAAW,MACF,CAAC;AAQ9C,eAAO,MAAM,gBAAgB,SAAS,GAAG,KAAW,MACG,CAAC;AAGxD,eAAO,MAAM,wCAAwC,SAC9C,GAAG,KACP,MAA0D,CAAC;AAG9D,eAAO,MAAM,kCAAkC,SAAS,GAAG,KAAW,MAC1B,CAAC;AAG7C,eAAO,MAAM,8BAA8B,SAAS,GAAG,KAAW,MACjB,CAAC;AAGlD,eAAO,MAAM,0CAA0C,SAChD,GAAG,KACP,MAAsE,CAAC;AAE1E;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CA+BlD;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,EAClD,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,yBAAyB,EAAE,CAAC,CA0CtC;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -1 +1 @@
1
- {"version":3,"file":"api-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,yBAAyB,EAG1B,4CAAkC;AAGnC,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EA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ACzB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf"}
1
+ {"version":3,"file":"api-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,yBAAyB,EAG1B,4CAAkC;AAInC,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAQxC,eAAO,MAAM,WAAW,SAAS,GAAG,KAAW,MACF,CAAC;AAQ9C,eAAO,MAAM,gBAAgB,SAAS,GAAG,KAAW,MACG,CAAC;AAGxD,eAAO,MAAM,wCAAwC,SAC9C,GAAG,KACP,MAA0D,CAAC;AAG9D,eAAO,MAAM,kCAAkC,SAAS,GAAG,KAAW,MAC1B,CAAC;AAG7C,eAAO,MAAM,8BAA8B,SAAS,GAAG,KAAW,MACjB,CAAC;AAGlD,eAAO,MAAM,0CAA0C,SAChD,GAAG,KACP,MAAsE,CAAC;AAE1E;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,CAAC,CA+BlD;AAED;;;;;;;GAOG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,EAClD,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAoBf;AAED;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,EAChC,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,yBAAyB,EAAE,CAAC,CA0CtC;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf"}
@@ -6,9 +6,9 @@ function $importDefault(module) {
6
6
  }
7
7
  import $log from "loglevel";
8
8
  const log = $importDefault($log);
9
- import { notificationsConfigCache } from "./notification-config-cache.mjs";
10
9
  import { toRawAPINotification } from "../../shared/to-raw-notification.mjs";
11
10
  import { makeApiCall } from "../utils/utils.mjs";
11
+ import { notificationsConfigCache } from "./notification-config-cache.mjs";
12
12
  const TRIGGER_API_ENV = {
13
13
  dev: 'https://trigger.dev-api.cx.metamask.io',
14
14
  uat: 'https://trigger.uat-api.cx.metamask.io',
@@ -1 +1 @@
1
- {"version":3,"file":"api-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AACvE,OAAO,EAAE,oBAAoB,EAAE,6CAAyC;AAMxE,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAW7C,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEhC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACtD,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AAE9C,MAAM,oBAAoB,GAAG;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AAuB,CAC3C,WAAmB,EACnB,eAAyB,EACzB,MAAW,KAAK;IAEhB,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAID,MAAM,IAAI,GAAiB;QACzB,GAAG,EAAE,eAAe;KACrB,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,WAAW,CACf,WAAW,EACX,0CAA0C,CAAC,GAAG,CAAC,EAC/C,MAAM,EACN,IAAI,CACL,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport { notificationsConfigCache } from './notification-config-cache';\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type {\n NormalisedAPINotification,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api';\nimport { makeApiCall } from '../utils/utils';\n\nexport type NotificationTrigger = {\n id: string;\n chainId: string;\n kind: string;\n address: string;\n};\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd'): string =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd'): string =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd'): string =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Marks notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;\n\n/**\n * fetches notification config (accounts enabled vs disabled)\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * NOTE the API will return addresses config with false if they have not been created before.\n * NOTE this is cached for 1s to prevent multiple update calls\n * @returns object of notification config, or null if missing\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n): Promise<{ address: string; enabled: boolean }[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n const normalizedAddresses = addresses.map((addr) => addr.toLowerCase());\n\n const cached = notificationsConfigCache.get(normalizedAddresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses.map((address) => ({ address }));\n const apiResponse = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((response) => (response.ok ? response.json() : null))\n .catch(() => null);\n\n const result = apiResponse ?? [];\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * updates notifications for a given addresses\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n): Promise<void> {\n if (addresses.length === 0) {\n return;\n }\n\n const normalizedAddresses = addresses.map((item) => ({\n ...item,\n address: item.address.toLowerCase(),\n }));\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(normalizedAddresses))\n .catch(() => null);\n}\n\n/**\n * Fetches on-chain notifications for the given addresses\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param addresses - List of addresses\n * @param locale - to generate translated notifications\n * @param platform - filter notifications for specific platforms ('extension' | 'mobile')\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.\n */\nexport async function getAPINotifications(\n bearerToken: string,\n addresses: string[],\n locale: string,\n platform: 'extension' | 'mobile',\n env: ENV = 'prd',\n): Promise<NormalisedAPINotification[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n type RequestBody =\n Schema.paths['/api/v3/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v3/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((addr) => addr.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(\n bearerToken,\n NOTIFICATION_API_LIST_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<APIResponse | null>((response) =>\n response.ok ? response.json() : null,\n )\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((notification): UnprocessedRawNotification | undefined => {\n if (!notification.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(notification);\n } catch {\n return undefined;\n }\n })\n .filter((item): item is NormalisedAPINotification => Boolean(item));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v3/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(\n bearerToken,\n NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env),\n 'POST',\n body,\n );\n } catch (error) {\n log.error('Error marking notifications as read:', error);\n }\n}\n"]}
1
+ {"version":3,"file":"api-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,IAAG,iBAAiB;;AAE3B,OAAO,EAAE,oBAAoB,EAAE,6CAAyC;AAMxE,OAAO,EAAE,WAAW,EAAE,2BAAuB;AAC7C,OAAO,EAAE,wBAAwB,EAAE,wCAAoC;AAWvE,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEhC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CACtD,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,yCAAyC;CAC/C,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAW,KAAK,EAAU,EAAE,CAC3D,oBAAoB,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC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AM,WAAW,CACf,WAAW,EACX,0CAA0C,CAAC,GAAG,CAAC,EAC/C,MAAM,EACN,IAAI,CACL,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport { toRawAPINotification } from '../../shared/to-raw-notification';\nimport type {\n NormalisedAPINotification,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api';\nimport { makeApiCall } from '../utils/utils';\nimport { notificationsConfigCache } from './notification-config-cache';\n\nexport type NotificationTrigger = {\n id: string;\n chainId: string;\n kind: string;\n address: string;\n};\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd'): string =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd'): string =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd'): string =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Marks notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;\n\n/**\n * fetches notification config (accounts enabled vs disabled)\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * NOTE the API will return addresses config with false if they have not been created before.\n * NOTE this is cached for 1s to prevent multiple update calls\n * @returns object of notification config, or null if missing\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n): Promise<{ address: string; enabled: boolean }[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n const normalizedAddresses = addresses.map((addr) => addr.toLowerCase());\n\n const cached = notificationsConfigCache.get(normalizedAddresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses.map((address) => ({ address }));\n const apiResponse = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((response) => (response.ok ? response.json() : null))\n .catch(() => null);\n\n const result = apiResponse ?? [];\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * updates notifications for a given addresses\n *\n * @param bearerToken - jwt\n * @param addresses - list of addresses to check\n * @param env - the environment to use for the API call\n * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n): Promise<void> {\n if (addresses.length === 0) {\n return;\n }\n\n const normalizedAddresses = addresses.map((item) => ({\n ...item,\n address: item.address.toLowerCase(),\n }));\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(normalizedAddresses))\n .catch(() => null);\n}\n\n/**\n * Fetches on-chain notifications for the given addresses\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param addresses - List of addresses\n * @param locale - to generate translated notifications\n * @param platform - filter notifications for specific platforms ('extension' | 'mobile')\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to an array of NormalisedAPINotification objects. If no notifications are enabled or an error occurs, it may return an empty array.\n */\nexport async function getAPINotifications(\n bearerToken: string,\n addresses: string[],\n locale: string,\n platform: 'extension' | 'mobile',\n env: ENV = 'prd',\n): Promise<NormalisedAPINotification[]> {\n if (addresses.length === 0) {\n return [];\n }\n\n type RequestBody =\n Schema.paths['/api/v3/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v3/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((addr) => addr.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(\n bearerToken,\n NOTIFICATION_API_LIST_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<APIResponse | null>((response) =>\n response.ok ? response.json() : null,\n )\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((notification): UnprocessedRawNotification | undefined => {\n if (!notification.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(notification);\n } catch {\n return undefined;\n }\n })\n .filter((item): item is NormalisedAPINotification => Boolean(item));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v3/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(\n bearerToken,\n NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env),\n 'POST',\n body,\n );\n } catch (error) {\n log.error('Error marking notifications as read:', error);\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcement.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypeFeatureAnnouncement } from './type-feature-announcement';\nimport type { TRIGGER_TYPES } from '../../constants/notification-schema';\n\nexport type FeatureAnnouncementRawNotificationData = Omit<\n TypeFeatureAnnouncement['fields'],\n | 'image'\n | 'longDescription'\n | 'extensionLink'\n | 'portfolioLink'\n | 'externalLink'\n | 'mobileLink'\n> & {\n longDescription: string;\n image: {\n title?: string;\n description?: string;\n url: string;\n };\n\n // External Link\n externalLink?: {\n externalLinkText: string;\n externalLinkUrl: string;\n };\n\n // Portfolio Link\n portfolioLink?: {\n portfolioLinkText: string;\n portfolioLinkUrl: string;\n };\n\n // Extension Link\n extensionLink?: {\n extensionLinkText: string;\n extensionLinkRoute: string;\n };\n\n // Mobile Link\n mobileLink?: {\n mobileLinkText: string;\n mobileLinkUrl: string;\n };\n};\n\nexport type FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n createdAt: string;\n data: FeatureAnnouncementRawNotificationData;\n};\n"]}
1
+ {"version":3,"file":"feature-announcement.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"","sourcesContent":["import type { TRIGGER_TYPES } from '../../constants/notification-schema';\nimport type { TypeFeatureAnnouncement } from './type-feature-announcement';\n\nexport type FeatureAnnouncementRawNotificationData = Omit<\n TypeFeatureAnnouncement['fields'],\n | 'image'\n | 'longDescription'\n | 'extensionLink'\n | 'portfolioLink'\n | 'externalLink'\n | 'mobileLink'\n> & {\n longDescription: string;\n image: {\n title?: string;\n description?: string;\n url: string;\n };\n\n // External Link\n externalLink?: {\n externalLinkText: string;\n externalLinkUrl: string;\n };\n\n // Portfolio Link\n portfolioLink?: {\n portfolioLinkText: string;\n portfolioLinkUrl: string;\n };\n\n // Extension Link\n extensionLink?: {\n extensionLinkText: string;\n extensionLinkRoute: string;\n };\n\n // Mobile Link\n mobileLink?: {\n mobileLinkText: string;\n mobileLinkUrl: string;\n };\n};\n\nexport type FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n createdAt: string;\n data: FeatureAnnouncementRawNotificationData;\n};\n"]}
@@ -1,5 +1,5 @@
1
- import type { TypeFeatureAnnouncement } from "./type-feature-announcement.cjs";
2
1
  import type { TRIGGER_TYPES } from "../../constants/notification-schema.cjs";
2
+ import type { TypeFeatureAnnouncement } from "./type-feature-announcement.cjs";
3
3
  export type FeatureAnnouncementRawNotificationData = Omit<TypeFeatureAnnouncement['fields'], 'image' | 'longDescription' | 'extensionLink' | 'portfolioLink' | 'externalLink' | 'mobileLink'> & {
4
4
  longDescription: string;
5
5
  image: {
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcement.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wCAAoC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AAEzE,MAAM,MAAM,sCAAsC,GAAG,IAAI,CACvD,uBAAuB,CAAC,QAAQ,CAAC,EAC/B,OAAO,GACP,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,cAAc,GACd,YAAY,CACf,GAAG;IACF,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAGF,YAAY,CAAC,EAAE;QACb,gBAAgB,EAAE,MAAM,CAAC;QACzB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IAGF,UAAU,CAAC,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,sCAAsC,CAAC;CAC9C,CAAC"}
1
+ {"version":3,"file":"feature-announcement.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,wCAAoC;AAE3E,MAAM,MAAM,sCAAsC,GAAG,IAAI,CACvD,uBAAuB,CAAC,QAAQ,CAAC,EAC/B,OAAO,GACP,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,cAAc,GACd,YAAY,CACf,GAAG;IACF,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAGF,YAAY,CAAC,EAAE;QACb,gBAAgB,EAAE,MAAM,CAAC;QACzB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IAGF,UAAU,CAAC,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,sCAAsC,CAAC;CAC9C,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { TypeFeatureAnnouncement } from "./type-feature-announcement.mjs";
2
1
  import type { TRIGGER_TYPES } from "../../constants/notification-schema.mjs";
2
+ import type { TypeFeatureAnnouncement } from "./type-feature-announcement.mjs";
3
3
  export type FeatureAnnouncementRawNotificationData = Omit<TypeFeatureAnnouncement['fields'], 'image' | 'longDescription' | 'extensionLink' | 'portfolioLink' | 'externalLink' | 'mobileLink'> & {
4
4
  longDescription: string;
5
5
  image: {
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcement.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,wCAAoC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AAEzE,MAAM,MAAM,sCAAsC,GAAG,IAAI,CACvD,uBAAuB,CAAC,QAAQ,CAAC,EAC/B,OAAO,GACP,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,cAAc,GACd,YAAY,CACf,GAAG;IACF,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAGF,YAAY,CAAC,EAAE;QACb,gBAAgB,EAAE,MAAM,CAAC;QACzB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IAGF,UAAU,CAAC,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,sCAAsC,CAAC;CAC9C,CAAC"}
1
+ {"version":3,"file":"feature-announcement.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AACzE,OAAO,KAAK,EAAE,uBAAuB,EAAE,wCAAoC;AAE3E,MAAM,MAAM,sCAAsC,GAAG,IAAI,CACvD,uBAAuB,CAAC,QAAQ,CAAC,EAC/B,OAAO,GACP,iBAAiB,GACjB,eAAe,GACf,eAAe,GACf,cAAc,GACd,YAAY,CACf,GAAG;IACF,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IAGF,YAAY,CAAC,EAAE;QACb,gBAAgB,EAAE,MAAM,CAAC;QACzB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IAGF,aAAa,CAAC,EAAE;QACd,iBAAiB,EAAE,MAAM,CAAC;QAC1B,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IAGF,UAAU,CAAC,EAAE;QACX,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,kCAAkC,GAAG;IAC/C,IAAI,EAAE,aAAa,CAAC,qBAAqB,CAAC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,sCAAsC,CAAC;CAC9C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"feature-announcement.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypeFeatureAnnouncement } from './type-feature-announcement';\nimport type { TRIGGER_TYPES } from '../../constants/notification-schema';\n\nexport type FeatureAnnouncementRawNotificationData = Omit<\n TypeFeatureAnnouncement['fields'],\n | 'image'\n | 'longDescription'\n | 'extensionLink'\n | 'portfolioLink'\n | 'externalLink'\n | 'mobileLink'\n> & {\n longDescription: string;\n image: {\n title?: string;\n description?: string;\n url: string;\n };\n\n // External Link\n externalLink?: {\n externalLinkText: string;\n externalLinkUrl: string;\n };\n\n // Portfolio Link\n portfolioLink?: {\n portfolioLinkText: string;\n portfolioLinkUrl: string;\n };\n\n // Extension Link\n extensionLink?: {\n extensionLinkText: string;\n extensionLinkRoute: string;\n };\n\n // Mobile Link\n mobileLink?: {\n mobileLinkText: string;\n mobileLinkUrl: string;\n };\n};\n\nexport type FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n createdAt: string;\n data: FeatureAnnouncementRawNotificationData;\n};\n"]}
1
+ {"version":3,"file":"feature-announcement.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/feature-announcement/feature-announcement.ts"],"names":[],"mappings":"","sourcesContent":["import type { TRIGGER_TYPES } from '../../constants/notification-schema';\nimport type { TypeFeatureAnnouncement } from './type-feature-announcement';\n\nexport type FeatureAnnouncementRawNotificationData = Omit<\n TypeFeatureAnnouncement['fields'],\n | 'image'\n | 'longDescription'\n | 'extensionLink'\n | 'portfolioLink'\n | 'externalLink'\n | 'mobileLink'\n> & {\n longDescription: string;\n image: {\n title?: string;\n description?: string;\n url: string;\n };\n\n // External Link\n externalLink?: {\n externalLinkText: string;\n externalLinkUrl: string;\n };\n\n // Portfolio Link\n portfolioLink?: {\n portfolioLinkText: string;\n portfolioLinkUrl: string;\n };\n\n // Extension Link\n extensionLink?: {\n extensionLinkText: string;\n extensionLinkRoute: string;\n };\n\n // Mobile Link\n mobileLink?: {\n mobileLinkText: string;\n mobileLinkUrl: string;\n };\n};\n\nexport type FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n createdAt: string;\n data: FeatureAnnouncementRawNotificationData;\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"notification-api.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"","sourcesContent":["// Types derived from external Notification API schema - naming follows API conventions\n/* eslint-disable @typescript-eslint/naming-convention */\nimport type { components } from './schema';\nimport type { TRIGGER_TYPES } from '../../constants/notification-schema';\nimport type { Compute } from '../type-utils';\n\nexport type Data_MetamaskSwapCompleted =\n components['schemas']['Data_MetamaskSwapCompleted'];\nexport type Data_LidoStakeReadyToBeWithdrawn =\n components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];\nexport type Data_LidoStakeCompleted =\n components['schemas']['Data_LidoStakeCompleted'];\nexport type Data_LidoWithdrawalRequested =\n components['schemas']['Data_LidoWithdrawalRequested'];\nexport type Data_LidoWithdrawalCompleted =\n components['schemas']['Data_LidoWithdrawalCompleted'];\nexport type Data_RocketPoolStakeCompleted =\n components['schemas']['Data_RocketPoolStakeCompleted'];\nexport type Data_RocketPoolUnstakeCompleted =\n components['schemas']['Data_RocketPoolUnstakeCompleted'];\nexport type Data_ETHSent = components['schemas']['Data_ETHSent'];\nexport type Data_ETHReceived = components['schemas']['Data_ETHReceived'];\nexport type Data_ERC20Sent = components['schemas']['Data_ERC20Sent'];\nexport type Data_ERC20Received = components['schemas']['Data_ERC20Received'];\nexport type Data_ERC721Sent = components['schemas']['Data_ERC721Sent'];\nexport type Data_ERC721Received = components['schemas']['Data_ERC721Received'];\nexport type NetworkMetadata = components['schemas']['NetworkMetadata'];\nexport type BlockExplorer = components['schemas']['BlockExplorer'];\n\ntype Notification = components['schemas']['NotificationOutputV3'][number];\ntype PlatformNotification = Extract<\n Notification,\n { notification_type: 'platform' }\n>;\ntype OnChainNotification = Extract<\n Notification,\n { notification_type: 'on-chain' }\n>;\n\ntype ConvertToEnum<Kind> = {\n [K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;\n}[TRIGGER_TYPES];\n\n/**\n * Type-Computation.\n * Adds a `type` field to on-chain notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizeOnChainNotification<\n N extends OnChainNotification = OnChainNotification,\n NotificationDataKinds extends string = NonNullable<\n N['payload']['data']\n >['kind'],\n> = {\n [K in NotificationDataKinds]: Compute<\n Omit<N, 'payload'> & {\n type: ConvertToEnum<K>;\n payload: Compute<\n Omit<N['payload'], 'data'> & {\n data: Extract<NonNullable<N['payload']['data']>, { kind: K }>;\n }\n >;\n }\n >;\n}[NotificationDataKinds];\n\n/**\n * Type-Computation.\n * Adds a `type` field to platform notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizePlatformNotification<\n N extends PlatformNotification = PlatformNotification,\n NotificationKind extends string = N['notification_type'],\n> = {\n [K in NotificationKind]: Compute<\n N & {\n type: ConvertToEnum<K>;\n }\n >;\n}[NotificationKind];\n\nexport type OnChainRawNotification = Compute<\n NormalizeOnChainNotification<OnChainNotification>\n>;\n\nexport type PlatformRawNotification = Compute<\n NormalizePlatformNotification<PlatformNotification>\n>;\n\nexport type UnprocessedRawNotification = Notification;\n\nexport type NormalisedAPINotification =\n | OnChainRawNotification\n | PlatformRawNotification;\n\nexport type OnChainRawNotificationsWithNetworkFields = Extract<\n OnChainRawNotification,\n { payload: { data: { network_fee: unknown } } }\n>;\n"]}
1
+ {"version":3,"file":"notification-api.cjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"","sourcesContent":["import type { TRIGGER_TYPES } from '../../constants/notification-schema';\nimport type { Compute } from '../type-utils';\n// Types derived from external Notification API schema - naming follows API conventions\n/* eslint-disable @typescript-eslint/naming-convention */\nimport type { components } from './schema';\n\nexport type Data_MetamaskSwapCompleted =\n components['schemas']['Data_MetamaskSwapCompleted'];\nexport type Data_LidoStakeReadyToBeWithdrawn =\n components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];\nexport type Data_LidoStakeCompleted =\n components['schemas']['Data_LidoStakeCompleted'];\nexport type Data_LidoWithdrawalRequested =\n components['schemas']['Data_LidoWithdrawalRequested'];\nexport type Data_LidoWithdrawalCompleted =\n components['schemas']['Data_LidoWithdrawalCompleted'];\nexport type Data_RocketPoolStakeCompleted =\n components['schemas']['Data_RocketPoolStakeCompleted'];\nexport type Data_RocketPoolUnstakeCompleted =\n components['schemas']['Data_RocketPoolUnstakeCompleted'];\nexport type Data_ETHSent = components['schemas']['Data_ETHSent'];\nexport type Data_ETHReceived = components['schemas']['Data_ETHReceived'];\nexport type Data_ERC20Sent = components['schemas']['Data_ERC20Sent'];\nexport type Data_ERC20Received = components['schemas']['Data_ERC20Received'];\nexport type Data_ERC721Sent = components['schemas']['Data_ERC721Sent'];\nexport type Data_ERC721Received = components['schemas']['Data_ERC721Received'];\nexport type NetworkMetadata = components['schemas']['NetworkMetadata'];\nexport type BlockExplorer = components['schemas']['BlockExplorer'];\n\ntype Notification = components['schemas']['NotificationOutputV3'][number];\ntype PlatformNotification = Extract<\n Notification,\n { notification_type: 'platform' }\n>;\ntype OnChainNotification = Extract<\n Notification,\n { notification_type: 'on-chain' }\n>;\n\ntype ConvertToEnum<Kind> = {\n [K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;\n}[TRIGGER_TYPES];\n\n/**\n * Type-Computation.\n * Adds a `type` field to on-chain notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizeOnChainNotification<\n N extends OnChainNotification = OnChainNotification,\n NotificationDataKinds extends string = NonNullable<\n N['payload']['data']\n >['kind'],\n> = {\n [K in NotificationDataKinds]: Compute<\n Omit<N, 'payload'> & {\n type: ConvertToEnum<K>;\n payload: Compute<\n Omit<N['payload'], 'data'> & {\n data: Extract<NonNullable<N['payload']['data']>, { kind: K }>;\n }\n >;\n }\n >;\n}[NotificationDataKinds];\n\n/**\n * Type-Computation.\n * Adds a `type` field to platform notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizePlatformNotification<\n N extends PlatformNotification = PlatformNotification,\n NotificationKind extends string = N['notification_type'],\n> = {\n [K in NotificationKind]: Compute<\n N & {\n type: ConvertToEnum<K>;\n }\n >;\n}[NotificationKind];\n\nexport type OnChainRawNotification = Compute<\n NormalizeOnChainNotification<OnChainNotification>\n>;\n\nexport type PlatformRawNotification = Compute<\n NormalizePlatformNotification<PlatformNotification>\n>;\n\nexport type UnprocessedRawNotification = Notification;\n\nexport type NormalisedAPINotification =\n | OnChainRawNotification\n | PlatformRawNotification;\n\nexport type OnChainRawNotificationsWithNetworkFields = Extract<\n OnChainRawNotification,\n { payload: { data: { network_fee: unknown } } }\n>;\n"]}
@@ -1,6 +1,6 @@
1
- import type { components } from "./schema.cjs";
2
1
  import type { TRIGGER_TYPES } from "../../constants/notification-schema.cjs";
3
2
  import type { Compute } from "../type-utils.cjs";
3
+ import type { components } from "./schema.cjs";
4
4
  export type Data_MetamaskSwapCompleted = components['schemas']['Data_MetamaskSwapCompleted'];
5
5
  export type Data_LidoStakeReadyToBeWithdrawn = components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];
6
6
  export type Data_LidoStakeCompleted = components['schemas']['Data_LidoStakeCompleted'];
@@ -1 +1 @@
1
- {"version":3,"file":"notification-api.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAiB;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAE7C,MAAM,MAAM,0BAA0B,GACpC,UAAU,CAAC,SAAS,CAAC,CAAC,4BAA4B,CAAC,CAAC;AACtD,MAAM,MAAM,gCAAgC,GAC1C,UAAU,CAAC,SAAS,CAAC,CAAC,kCAAkC,CAAC,CAAC;AAC5D,MAAM,MAAM,uBAAuB,GACjC,UAAU,CAAC,SAAS,CAAC,CAAC,yBAAyB,CAAC,CAAC;AACnD,MAAM,MAAM,4BAA4B,GACtC,UAAU,CAAC,SAAS,CAAC,CAAC,8BAA8B,CAAC,CAAC;AACxD,MAAM,MAAM,4BAA4B,GACtC,UAAU,CAAC,SAAS,CAAC,CAAC,8BAA8B,CAAC,CAAC;AACxD,MAAM,MAAM,6BAA6B,GACvC,UAAU,CAAC,SAAS,CAAC,CAAC,+BAA+B,CAAC,CAAC;AACzD,MAAM,MAAM,+BAA+B,GACzC,UAAU,CAAC,SAAS,CAAC,CAAC,iCAAiC,CAAC,CAAC;AAC3D,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC;AACzE,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,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OAAO,CACd,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,GAAG;YAC3B,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE;gBAAE,IAAI,EAAE,CAAC,CAAA;aAAE,CAAC,CAAC;SAC/D,CACF,CAAC;KACH,CACF;CACF,CAAC,qBAAqB,CAAC,CAAC;AAEzB;;;;GAIG;AACH,KAAK,6BAA6B,CAChC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EACrD,gBAAgB,SAAS,MAAM,GAAG,CAAC,CAAC,mBAAmB,CAAC,IACtD;KACD,CAAC,IAAI,gBAAgB,GAAG,OAAO,CAC9B,CAAC,GAAG;QACF,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;KACxB,CACF;CACF,CAAC,gBAAgB,CAAC,CAAC;AAEpB,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAC1C,4BAA4B,CAAC,mBAAmB,CAAC,CAClD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC3C,6BAA6B,CAAC,oBAAoB,CAAC,CACpD,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC;AAEtD,MAAM,MAAM,yBAAyB,GACjC,sBAAsB,GACtB,uBAAuB,CAAC;AAE5B,MAAM,MAAM,wCAAwC,GAAG,OAAO,CAC5D,sBAAsB,EACtB;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,WAAW,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAChD,CAAC"}
1
+ {"version":3,"file":"notification-api.d.cts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAG7C,OAAO,KAAK,EAAE,UAAU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D,CAAC,IAAI,gBAAgB,GAAG,OAAO,CAC9B,CAAC,GAAG;QACF,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;KACxB,CACF;CACF,CAAC,gBAAgB,CAAC,CAAC;AAEpB,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAC1C,4BAA4B,CAAC,mBAAmB,CAAC,CAClD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC3C,6BAA6B,CAAC,oBAAoB,CAAC,CACpD,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC;AAEtD,MAAM,MAAM,yBAAyB,GACjC,sBAAsB,GACtB,uBAAuB,CAAC;AAE5B,MAAM,MAAM,wCAAwC,GAAG,OAAO,CAC5D,sBAAsB,EACtB;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,WAAW,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAChD,CAAC"}
@@ -1,6 +1,6 @@
1
- import type { components } from "./schema.mjs";
2
1
  import type { TRIGGER_TYPES } from "../../constants/notification-schema.mjs";
3
2
  import type { Compute } from "../type-utils.mjs";
3
+ import type { components } from "./schema.mjs";
4
4
  export type Data_MetamaskSwapCompleted = components['schemas']['Data_MetamaskSwapCompleted'];
5
5
  export type Data_LidoStakeReadyToBeWithdrawn = components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];
6
6
  export type Data_LidoStakeCompleted = components['schemas']['Data_LidoStakeCompleted'];
@@ -1 +1 @@
1
- {"version":3,"file":"notification-api.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAiB;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAE7C,MAAM,MAAM,0BAA0B,GACpC,UAAU,CAAC,SAAS,CAAC,CAAC,4BA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CAAC,CAAC,CAAC;KACxB,CACF;CACF,CAAC,gBAAgB,CAAC,CAAC;AAEpB,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAC1C,4BAA4B,CAAC,mBAAmB,CAAC,CAClD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC3C,6BAA6B,CAAC,oBAAoB,CAAC,CACpD,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC;AAEtD,MAAM,MAAM,yBAAyB,GACjC,sBAAsB,GACtB,uBAAuB,CAAC;AAE5B,MAAM,MAAM,wCAAwC,GAAG,OAAO,CAC5D,sBAAsB,EACtB;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,WAAW,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAChD,CAAC"}
1
+ {"version":3,"file":"notification-api.d.mts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gDAA4C;AACzE,OAAO,KAAK,EAAE,OAAO,EAAE,0BAAsB;AAG7C,OAAO,KAAK,EAAE,UAAU,EAAE,qBAAiB;AAE3C,MAAM,MAAM,0BAA0B,GACpC,UAAU,CAAC,SAAS,CAAC,CAAC,4BAA4B,CAAC,CAAC;AACtD,MAAM,MAAM,gCAAgC,GAC1C,UAAU,CAAC,SAAS,CAAC,CAAC,kCAAkC,CAAC,CAAC;AAC5D,MAAM,MAAM,uBAAuB,GACjC,UAAU,CAAC,SAAS,CAAC,CAAC,yBAAyB,CAAC,CAAC;AACnD,MAAM,MAAM,4BAA4B,GACtC,UAAU,CAAC,SAAS,CAAC,CAAC,8BAA8B,CAAC,CAAC;AACxD,MAAM,MAAM,4BAA4B,GACtC,UAAU,CAAC,SAAS,CAAC,CAAC,8BAA8B,CAAC,CAAC;AACxD,MAAM,MAAM,6BAA6B,GACvC,UAAU,CAAC,SAAS,CAAC,CAAC,+BAA+B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QAAE,IAAI,EAAE;YAAE,WAAW,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAChD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"notification-api.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"","sourcesContent":["// Types derived from external Notification API schema - naming follows API conventions\n/* eslint-disable @typescript-eslint/naming-convention */\nimport type { components } from './schema';\nimport type { TRIGGER_TYPES } from '../../constants/notification-schema';\nimport type { Compute } from '../type-utils';\n\nexport type Data_MetamaskSwapCompleted =\n components['schemas']['Data_MetamaskSwapCompleted'];\nexport type Data_LidoStakeReadyToBeWithdrawn =\n components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];\nexport type Data_LidoStakeCompleted =\n components['schemas']['Data_LidoStakeCompleted'];\nexport type Data_LidoWithdrawalRequested =\n components['schemas']['Data_LidoWithdrawalRequested'];\nexport type Data_LidoWithdrawalCompleted =\n components['schemas']['Data_LidoWithdrawalCompleted'];\nexport type Data_RocketPoolStakeCompleted =\n components['schemas']['Data_RocketPoolStakeCompleted'];\nexport type Data_RocketPoolUnstakeCompleted =\n components['schemas']['Data_RocketPoolUnstakeCompleted'];\nexport type Data_ETHSent = components['schemas']['Data_ETHSent'];\nexport type Data_ETHReceived = components['schemas']['Data_ETHReceived'];\nexport type Data_ERC20Sent = components['schemas']['Data_ERC20Sent'];\nexport type Data_ERC20Received = components['schemas']['Data_ERC20Received'];\nexport type Data_ERC721Sent = components['schemas']['Data_ERC721Sent'];\nexport type Data_ERC721Received = components['schemas']['Data_ERC721Received'];\nexport type NetworkMetadata = components['schemas']['NetworkMetadata'];\nexport type BlockExplorer = components['schemas']['BlockExplorer'];\n\ntype Notification = components['schemas']['NotificationOutputV3'][number];\ntype PlatformNotification = Extract<\n Notification,\n { notification_type: 'platform' }\n>;\ntype OnChainNotification = Extract<\n Notification,\n { notification_type: 'on-chain' }\n>;\n\ntype ConvertToEnum<Kind> = {\n [K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;\n}[TRIGGER_TYPES];\n\n/**\n * Type-Computation.\n * Adds a `type` field to on-chain notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizeOnChainNotification<\n N extends OnChainNotification = OnChainNotification,\n NotificationDataKinds extends string = NonNullable<\n N['payload']['data']\n >['kind'],\n> = {\n [K in NotificationDataKinds]: Compute<\n Omit<N, 'payload'> & {\n type: ConvertToEnum<K>;\n payload: Compute<\n Omit<N['payload'], 'data'> & {\n data: Extract<NonNullable<N['payload']['data']>, { kind: K }>;\n }\n >;\n }\n >;\n}[NotificationDataKinds];\n\n/**\n * Type-Computation.\n * Adds a `type` field to platform notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizePlatformNotification<\n N extends PlatformNotification = PlatformNotification,\n NotificationKind extends string = N['notification_type'],\n> = {\n [K in NotificationKind]: Compute<\n N & {\n type: ConvertToEnum<K>;\n }\n >;\n}[NotificationKind];\n\nexport type OnChainRawNotification = Compute<\n NormalizeOnChainNotification<OnChainNotification>\n>;\n\nexport type PlatformRawNotification = Compute<\n NormalizePlatformNotification<PlatformNotification>\n>;\n\nexport type UnprocessedRawNotification = Notification;\n\nexport type NormalisedAPINotification =\n | OnChainRawNotification\n | PlatformRawNotification;\n\nexport type OnChainRawNotificationsWithNetworkFields = Extract<\n OnChainRawNotification,\n { payload: { data: { network_fee: unknown } } }\n>;\n"]}
1
+ {"version":3,"file":"notification-api.mjs","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"","sourcesContent":["import type { TRIGGER_TYPES } from '../../constants/notification-schema';\nimport type { Compute } from '../type-utils';\n// Types derived from external Notification API schema - naming follows API conventions\n/* eslint-disable @typescript-eslint/naming-convention */\nimport type { components } from './schema';\n\nexport type Data_MetamaskSwapCompleted =\n components['schemas']['Data_MetamaskSwapCompleted'];\nexport type Data_LidoStakeReadyToBeWithdrawn =\n components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];\nexport type Data_LidoStakeCompleted =\n components['schemas']['Data_LidoStakeCompleted'];\nexport type Data_LidoWithdrawalRequested =\n components['schemas']['Data_LidoWithdrawalRequested'];\nexport type Data_LidoWithdrawalCompleted =\n components['schemas']['Data_LidoWithdrawalCompleted'];\nexport type Data_RocketPoolStakeCompleted =\n components['schemas']['Data_RocketPoolStakeCompleted'];\nexport type Data_RocketPoolUnstakeCompleted =\n components['schemas']['Data_RocketPoolUnstakeCompleted'];\nexport type Data_ETHSent = components['schemas']['Data_ETHSent'];\nexport type Data_ETHReceived = components['schemas']['Data_ETHReceived'];\nexport type Data_ERC20Sent = components['schemas']['Data_ERC20Sent'];\nexport type Data_ERC20Received = components['schemas']['Data_ERC20Received'];\nexport type Data_ERC721Sent = components['schemas']['Data_ERC721Sent'];\nexport type Data_ERC721Received = components['schemas']['Data_ERC721Received'];\nexport type NetworkMetadata = components['schemas']['NetworkMetadata'];\nexport type BlockExplorer = components['schemas']['BlockExplorer'];\n\ntype Notification = components['schemas']['NotificationOutputV3'][number];\ntype PlatformNotification = Extract<\n Notification,\n { notification_type: 'platform' }\n>;\ntype OnChainNotification = Extract<\n Notification,\n { notification_type: 'on-chain' }\n>;\n\ntype ConvertToEnum<Kind> = {\n [K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;\n}[TRIGGER_TYPES];\n\n/**\n * Type-Computation.\n * Adds a `type` field to on-chain notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizeOnChainNotification<\n N extends OnChainNotification = OnChainNotification,\n NotificationDataKinds extends string = NonNullable<\n N['payload']['data']\n >['kind'],\n> = {\n [K in NotificationDataKinds]: Compute<\n Omit<N, 'payload'> & {\n type: ConvertToEnum<K>;\n payload: Compute<\n Omit<N['payload'], 'data'> & {\n data: Extract<NonNullable<N['payload']['data']>, { kind: K }>;\n }\n >;\n }\n >;\n}[NotificationDataKinds];\n\n/**\n * Type-Computation.\n * Adds a `type` field to platform notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizePlatformNotification<\n N extends PlatformNotification = PlatformNotification,\n NotificationKind extends string = N['notification_type'],\n> = {\n [K in NotificationKind]: Compute<\n N & {\n type: ConvertToEnum<K>;\n }\n >;\n}[NotificationKind];\n\nexport type OnChainRawNotification = Compute<\n NormalizeOnChainNotification<OnChainNotification>\n>;\n\nexport type PlatformRawNotification = Compute<\n NormalizePlatformNotification<PlatformNotification>\n>;\n\nexport type UnprocessedRawNotification = Notification;\n\nexport type NormalisedAPINotification =\n | OnChainRawNotification\n | PlatformRawNotification;\n\nexport type OnChainRawNotificationsWithNetworkFields = Extract<\n OnChainRawNotification,\n { payload: { data: { network_fee: unknown } } }\n>;\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
3
+ * This file is auto generated.
4
4
  * Do not edit manually.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController-method-action-types.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { NotificationServicesPushController } from './NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerSubscribeToPushNotificationsAction =\n {\n type: `NotificationServicesPushController:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\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 */\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `NotificationServicesPushController:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerDisablePushNotificationsAction = {\n type: `NotificationServicesPushController:disablePushNotifications`;\n handler: NotificationServicesPushController['disablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerDeletePushNotificationLinksAction =\n {\n type: `NotificationServicesPushController:deletePushNotificationLinks`;\n handler: NotificationServicesPushController['deletePushNotificationLinks'];\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 */\nexport type NotificationServicesPushControllerUpdateTriggerPushNotificationsAction =\n {\n type: `NotificationServicesPushController:updateTriggerPushNotifications`;\n handler: NotificationServicesPushController['updateTriggerPushNotifications'];\n };\n\n/**\n * Union of all NotificationServicesPushController action types.\n */\nexport type NotificationServicesPushControllerMethodActions =\n | NotificationServicesPushControllerSubscribeToPushNotificationsAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerDeletePushNotificationLinksAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;\n"]}
1
+ {"version":3,"file":"NotificationServicesPushController-method-action-types.cjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NotificationServicesPushController } from './NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerSubscribeToPushNotificationsAction =\n {\n type: `NotificationServicesPushController:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\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 */\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `NotificationServicesPushController:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerDisablePushNotificationsAction = {\n type: `NotificationServicesPushController:disablePushNotifications`;\n handler: NotificationServicesPushController['disablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerAddPushNotificationLinksAction = {\n type: `NotificationServicesPushController:addPushNotificationLinks`;\n handler: NotificationServicesPushController['addPushNotificationLinks'];\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 */\nexport type NotificationServicesPushControllerDeletePushNotificationLinksAction =\n {\n type: `NotificationServicesPushController:deletePushNotificationLinks`;\n handler: NotificationServicesPushController['deletePushNotificationLinks'];\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 */\nexport type NotificationServicesPushControllerUpdateTriggerPushNotificationsAction =\n {\n type: `NotificationServicesPushController:updateTriggerPushNotifications`;\n handler: NotificationServicesPushController['updateTriggerPushNotifications'];\n };\n\n/**\n * Union of all NotificationServicesPushController action types.\n */\nexport type NotificationServicesPushControllerMethodActions =\n | NotificationServicesPushControllerSubscribeToPushNotificationsAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerAddPushNotificationLinksAction\n | NotificationServicesPushControllerDeletePushNotificationLinksAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;\n"]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  import type { NotificationServicesPushController } from "./NotificationServicesPushController.cjs";
@@ -29,6 +29,18 @@ export type NotificationServicesPushControllerDisablePushNotificationsAction = {
29
29
  type: `NotificationServicesPushController:disablePushNotifications`;
30
30
  handler: NotificationServicesPushController['disablePushNotifications'];
31
31
  };
32
+ /**
33
+ * Adds backend push notification links for the given addresses using the current FCM token.
34
+ * This is used when accounts are added after push notifications have already been enabled,
35
+ * so backend can link the existing device token to the newly added addresses.
36
+ *
37
+ * @param addresses - Addresses that should be linked to push notifications.
38
+ * @returns Whether the add request succeeded.
39
+ */
40
+ export type NotificationServicesPushControllerAddPushNotificationLinksAction = {
41
+ type: `NotificationServicesPushController:addPushNotificationLinks`;
42
+ handler: NotificationServicesPushController['addPushNotificationLinks'];
43
+ };
32
44
  /**
33
45
  * Deletes backend push notification links for the given addresses on the current platform.
34
46
  * This is used when accounts are removed (for example SRP removal), so backend can remove
@@ -56,5 +68,5 @@ export type NotificationServicesPushControllerUpdateTriggerPushNotificationsActi
56
68
  /**
57
69
  * Union of all NotificationServicesPushController action types.
58
70
  */
59
- export type NotificationServicesPushControllerMethodActions = NotificationServicesPushControllerSubscribeToPushNotificationsAction | NotificationServicesPushControllerEnablePushNotificationsAction | NotificationServicesPushControllerDisablePushNotificationsAction | NotificationServicesPushControllerDeletePushNotificationLinksAction | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;
71
+ export type NotificationServicesPushControllerMethodActions = NotificationServicesPushControllerSubscribeToPushNotificationsAction | NotificationServicesPushControllerEnablePushNotificationsAction | NotificationServicesPushControllerDisablePushNotificationsAction | NotificationServicesPushControllerAddPushNotificationLinksAction | NotificationServicesPushControllerDeletePushNotificationLinksAction | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;
60
72
  //# sourceMappingURL=NotificationServicesPushController-method-action-types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController-method-action-types.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kCAAkC,EAAE,iDAA6C;AAE/F,MAAM,MAAM,oEAAoE,GAC9E;IACE,IAAI,EAAE,iEAAiE,CAAC;IACxE,OAAO,EAAE,kCAAkC,CAAC,8BAA8B,CAAC,CAAC;CAC7E,CAAC;AAEJ;;;;;;;;;GASG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,kCAAkC,CAAC,yBAAyB,CAAC,CAAC;CACxE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gEAAgE,GAAG;IAC7E,IAAI,EAAE,6DAA6D,CAAC;IACpE,OAAO,EAAE,kCAAkC,CAAC,0BAA0B,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,mEAAmE,GAC7E;IACE,IAAI,EAAE,gEAAgE,CAAC;IACvE,OAAO,EAAE,kCAAkC,CAAC,6BAA6B,CAAC,CAAC;CAC5E,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,MAAM,sEAAsE,GAChF;IACE,IAAI,EAAE,mEAAmE,CAAC;IAC1E,OAAO,EAAE,kCAAkC,CAAC,gCAAgC,CAAC,CAAC;CAC/E,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,+CAA+C,GACvD,oEAAoE,GACpE,+DAA+D,GAC/D,gEAAgE,GAChE,mEAAmE,GACnE,sEAAsE,CAAC"}
1
+ {"version":3,"file":"NotificationServicesPushController-method-action-types.d.cts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kCAAkC,EAAE,iDAA6C;AAE/F,MAAM,MAAM,oEAAoE,GAC9E;IACE,IAAI,EAAE,iEAAiE,CAAC;IACxE,OAAO,EAAE,kCAAkC,CAAC,8BAA8B,CAAC,CAAC;CAC7E,CAAC;AAEJ;;;;;;;;;GASG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,kCAAkC,CAAC,yBAAyB,CAAC,CAAC;CACxE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gEAAgE,GAAG;IAC7E,IAAI,EAAE,6DAA6D,CAAC;IACpE,OAAO,EAAE,kCAAkC,CAAC,0BAA0B,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,gEAAgE,GAAG;IAC7E,IAAI,EAAE,6DAA6D,CAAC;IACpE,OAAO,EAAE,kCAAkC,CAAC,0BAA0B,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,mEAAmE,GAC7E;IACE,IAAI,EAAE,gEAAgE,CAAC;IACvE,OAAO,EAAE,kCAAkC,CAAC,6BAA6B,CAAC,CAAC;CAC5E,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,MAAM,sEAAsE,GAChF;IACE,IAAI,EAAE,mEAAmE,CAAC;IAC1E,OAAO,EAAE,kCAAkC,CAAC,gCAAgC,CAAC,CAAC;CAC/E,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,+CAA+C,GACvD,oEAAoE,GACpE,+DAA+D,GAC/D,gEAAgE,GAChE,gEAAgE,GAChE,mEAAmE,GACnE,sEAAsE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  import type { NotificationServicesPushController } from "./NotificationServicesPushController.mjs";
@@ -29,6 +29,18 @@ export type NotificationServicesPushControllerDisablePushNotificationsAction = {
29
29
  type: `NotificationServicesPushController:disablePushNotifications`;
30
30
  handler: NotificationServicesPushController['disablePushNotifications'];
31
31
  };
32
+ /**
33
+ * Adds backend push notification links for the given addresses using the current FCM token.
34
+ * This is used when accounts are added after push notifications have already been enabled,
35
+ * so backend can link the existing device token to the newly added addresses.
36
+ *
37
+ * @param addresses - Addresses that should be linked to push notifications.
38
+ * @returns Whether the add request succeeded.
39
+ */
40
+ export type NotificationServicesPushControllerAddPushNotificationLinksAction = {
41
+ type: `NotificationServicesPushController:addPushNotificationLinks`;
42
+ handler: NotificationServicesPushController['addPushNotificationLinks'];
43
+ };
32
44
  /**
33
45
  * Deletes backend push notification links for the given addresses on the current platform.
34
46
  * This is used when accounts are removed (for example SRP removal), so backend can remove
@@ -56,5 +68,5 @@ export type NotificationServicesPushControllerUpdateTriggerPushNotificationsActi
56
68
  /**
57
69
  * Union of all NotificationServicesPushController action types.
58
70
  */
59
- export type NotificationServicesPushControllerMethodActions = NotificationServicesPushControllerSubscribeToPushNotificationsAction | NotificationServicesPushControllerEnablePushNotificationsAction | NotificationServicesPushControllerDisablePushNotificationsAction | NotificationServicesPushControllerDeletePushNotificationLinksAction | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;
71
+ export type NotificationServicesPushControllerMethodActions = NotificationServicesPushControllerSubscribeToPushNotificationsAction | NotificationServicesPushControllerEnablePushNotificationsAction | NotificationServicesPushControllerDisablePushNotificationsAction | NotificationServicesPushControllerAddPushNotificationLinksAction | NotificationServicesPushControllerDeletePushNotificationLinksAction | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;
60
72
  //# sourceMappingURL=NotificationServicesPushController-method-action-types.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController-method-action-types.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kCAAkC,EAAE,iDAA6C;AAE/F,MAAM,MAAM,oEAAoE,GAC9E;IACE,IAAI,EAAE,iEAAiE,CAAC;IACxE,OAAO,EAAE,kCAAkC,CAAC,8BAA8B,CAAC,CAAC;CAC7E,CAAC;AAEJ;;;;;;;;;GASG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,kCAAkC,CAAC,yBAAyB,CAAC,CAAC;CACxE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gEAAgE,GAAG;IAC7E,IAAI,EAAE,6DAA6D,CAAC;IACpE,OAAO,EAAE,kCAAkC,CAAC,0BAA0B,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,mEAAmE,GAC7E;IACE,IAAI,EAAE,gEAAgE,CAAC;IACvE,OAAO,EAAE,kCAAkC,CAAC,6BAA6B,CAAC,CAAC;CAC5E,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,MAAM,sEAAsE,GAChF;IACE,IAAI,EAAE,mEAAmE,CAAC;IAC1E,OAAO,EAAE,kCAAkC,CAAC,gCAAgC,CAAC,CAAC;CAC/E,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,+CAA+C,GACvD,oEAAoE,GACpE,+DAA+D,GAC/D,gEAAgE,GAChE,mEAAmE,GACnE,sEAAsE,CAAC"}
1
+ {"version":3,"file":"NotificationServicesPushController-method-action-types.d.mts","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,kCAAkC,EAAE,iDAA6C;AAE/F,MAAM,MAAM,oEAAoE,GAC9E;IACE,IAAI,EAAE,iEAAiE,CAAC;IACxE,OAAO,EAAE,kCAAkC,CAAC,8BAA8B,CAAC,CAAC;CAC7E,CAAC;AAEJ;;;;;;;;;GASG;AACH,MAAM,MAAM,+DAA+D,GAAG;IAC5E,IAAI,EAAE,4DAA4D,CAAC;IACnE,OAAO,EAAE,kCAAkC,CAAC,yBAAyB,CAAC,CAAC;CACxE,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gEAAgE,GAAG;IAC7E,IAAI,EAAE,6DAA6D,CAAC;IACpE,OAAO,EAAE,kCAAkC,CAAC,0BAA0B,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,gEAAgE,GAAG;IAC7E,IAAI,EAAE,6DAA6D,CAAC;IACpE,OAAO,EAAE,kCAAkC,CAAC,0BAA0B,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,mEAAmE,GAC7E;IACE,IAAI,EAAE,gEAAgE,CAAC;IACvE,OAAO,EAAE,kCAAkC,CAAC,6BAA6B,CAAC,CAAC;CAC5E,CAAC;AAEJ;;;;;;;GAOG;AACH,MAAM,MAAM,sEAAsE,GAChF;IACE,IAAI,EAAE,mEAAmE,CAAC;IAC1E,OAAO,EAAE,kCAAkC,CAAC,gCAAgC,CAAC,CAAC;CAC/E,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,+CAA+C,GACvD,oEAAoE,GACpE,+DAA+D,GAC/D,gEAAgE,GAChE,gEAAgE,GAChE,mEAAmE,GACnE,sEAAsE,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This file is auto generated by `scripts/generate-method-action-types.ts`.
2
+ * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"NotificationServicesPushController-method-action-types.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { NotificationServicesPushController } from './NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerSubscribeToPushNotificationsAction =\n {\n type: `NotificationServicesPushController:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\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 */\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `NotificationServicesPushController:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerDisablePushNotificationsAction = {\n type: `NotificationServicesPushController:disablePushNotifications`;\n handler: NotificationServicesPushController['disablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerDeletePushNotificationLinksAction =\n {\n type: `NotificationServicesPushController:deletePushNotificationLinks`;\n handler: NotificationServicesPushController['deletePushNotificationLinks'];\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 */\nexport type NotificationServicesPushControllerUpdateTriggerPushNotificationsAction =\n {\n type: `NotificationServicesPushController:updateTriggerPushNotifications`;\n handler: NotificationServicesPushController['updateTriggerPushNotifications'];\n };\n\n/**\n * Union of all NotificationServicesPushController action types.\n */\nexport type NotificationServicesPushControllerMethodActions =\n | NotificationServicesPushControllerSubscribeToPushNotificationsAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerDeletePushNotificationLinksAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;\n"]}
1
+ {"version":3,"file":"NotificationServicesPushController-method-action-types.mjs","sourceRoot":"","sources":["../../src/NotificationServicesPushController/NotificationServicesPushController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { NotificationServicesPushController } from './NotificationServicesPushController';\n\nexport type NotificationServicesPushControllerSubscribeToPushNotificationsAction =\n {\n type: `NotificationServicesPushController:subscribeToPushNotifications`;\n handler: NotificationServicesPushController['subscribeToPushNotifications'];\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 */\nexport type NotificationServicesPushControllerEnablePushNotificationsAction = {\n type: `NotificationServicesPushController:enablePushNotifications`;\n handler: NotificationServicesPushController['enablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerDisablePushNotificationsAction = {\n type: `NotificationServicesPushController:disablePushNotifications`;\n handler: NotificationServicesPushController['disablePushNotifications'];\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 */\nexport type NotificationServicesPushControllerAddPushNotificationLinksAction = {\n type: `NotificationServicesPushController:addPushNotificationLinks`;\n handler: NotificationServicesPushController['addPushNotificationLinks'];\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 */\nexport type NotificationServicesPushControllerDeletePushNotificationLinksAction =\n {\n type: `NotificationServicesPushController:deletePushNotificationLinks`;\n handler: NotificationServicesPushController['deletePushNotificationLinks'];\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 */\nexport type NotificationServicesPushControllerUpdateTriggerPushNotificationsAction =\n {\n type: `NotificationServicesPushController:updateTriggerPushNotifications`;\n handler: NotificationServicesPushController['updateTriggerPushNotifications'];\n };\n\n/**\n * Union of all NotificationServicesPushController action types.\n */\nexport type NotificationServicesPushControllerMethodActions =\n | NotificationServicesPushControllerSubscribeToPushNotificationsAction\n | NotificationServicesPushControllerEnablePushNotificationsAction\n | NotificationServicesPushControllerDisablePushNotificationsAction\n | NotificationServicesPushControllerAddPushNotificationLinksAction\n | NotificationServicesPushControllerDeletePushNotificationLinksAction\n | NotificationServicesPushControllerUpdateTriggerPushNotificationsAction;\n"]}
@@ -23,6 +23,7 @@ const controllerName = 'NotificationServicesPushController';
23
23
  const MESSENGER_EXPOSED_METHODS = [
24
24
  'subscribeToPushNotifications',
25
25
  'enablePushNotifications',
26
+ 'addPushNotificationLinks',
26
27
  'disablePushNotifications',
27
28
  'updateTriggerPushNotifications',
28
29
  'deletePushNotificationLinks',
@@ -189,6 +190,37 @@ class NotificationServicesPushController extends base_controller_1.BaseControlle
189
190
  // Update State
190
191
  __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_updatePushState).call(this, { type: 'disable' });
191
192
  }
193
+ /**
194
+ * Adds backend push notification links for the given addresses using the current FCM token.
195
+ * This is used when accounts are added after push notifications have already been enabled,
196
+ * so backend can link the existing device token to the newly added addresses.
197
+ *
198
+ * @param addresses - Addresses that should be linked to push notifications.
199
+ * @returns Whether the add request succeeded.
200
+ */
201
+ async addPushNotificationLinks(addresses) {
202
+ if (!__classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").isPushFeatureEnabled ||
203
+ addresses.length === 0 ||
204
+ !this.state.fcmToken) {
205
+ return false;
206
+ }
207
+ try {
208
+ const bearerToken = await __classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_getAndAssertBearerToken).call(this);
209
+ return await (0, services_1.updateLinksAPI)({
210
+ bearerToken,
211
+ addresses,
212
+ regToken: {
213
+ token: this.state.fcmToken,
214
+ platform: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").platform,
215
+ locale: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").getLocale?.() ?? 'en',
216
+ },
217
+ env: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").env ?? 'prd',
218
+ });
219
+ }
220
+ catch {
221
+ return false;
222
+ }
223
+ }
192
224
  /**
193
225
  * Deletes backend push notification links for the given addresses on the current platform.
194
226
  * This is used when accounts are removed (for example SRP removal), so backend can remove