@metamask/notification-services-controller 19.0.0 → 21.0.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.
- package/CHANGELOG.md +36 -2
- package/dist/NotificationServicesController/NotificationServicesController.cjs +20 -38
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +5 -2
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +5 -2
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +20 -15
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.cjs +4 -14
- package/dist/NotificationServicesController/constants/notification-schema.cjs.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.d.cts +3 -13
- package/dist/NotificationServicesController/constants/notification-schema.d.cts.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.d.mts +3 -13
- package/dist/NotificationServicesController/constants/notification-schema.d.mts.map +1 -1
- package/dist/NotificationServicesController/constants/notification-schema.mjs +3 -13
- package/dist/NotificationServicesController/constants/notification-schema.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs +427 -529
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts +20 -50
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts +20 -50
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs +424 -521
- package/dist/NotificationServicesController/mocks/mock-raw-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +5 -5
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts +2 -2
- package/dist/NotificationServicesController/mocks/mockResponses.d.cts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts +2 -2
- package/dist/NotificationServicesController/mocks/mockResponses.d.mts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs +5 -5
- package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/index.cjs +1 -1
- package/dist/NotificationServicesController/processors/index.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/index.d.cts +1 -1
- package/dist/NotificationServicesController/processors/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/index.d.mts +1 -1
- package/dist/NotificationServicesController/processors/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/index.mjs +1 -1
- package/dist/NotificationServicesController/processors/index.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-api-notifications.cjs +22 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.cjs.map +1 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.cts +10 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.cts.map +1 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.mts +10 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.d.mts.map +1 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.mjs +18 -0
- package/dist/NotificationServicesController/processors/process-api-notifications.mjs.map +1 -0
- package/dist/NotificationServicesController/processors/process-feature-announcement.cjs +2 -7
- package/dist/NotificationServicesController/processors/process-feature-announcement.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-feature-announcement.mjs +1 -6
- package/dist/NotificationServicesController/processors/process-feature-announcement.mjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.cjs +3 -3
- package/dist/NotificationServicesController/processors/process-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.cts +398 -458
- package/dist/NotificationServicesController/processors/process-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.d.mts +398 -458
- package/dist/NotificationServicesController/processors/process-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/processors/process-notifications.mjs +4 -4
- package/dist/NotificationServicesController/processors/process-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/services/{onchain-notifications.cjs → api-notifications.cjs} +57 -24
- package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -0
- package/dist/NotificationServicesController/services/{onchain-notifications.d.cts → api-notifications.d.cts} +20 -13
- package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -0
- package/dist/NotificationServicesController/services/{onchain-notifications.d.mts → api-notifications.d.mts} +20 -13
- package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -0
- package/dist/NotificationServicesController/services/{onchain-notifications.mjs → api-notifications.mjs} +49 -22
- package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -0
- package/dist/NotificationServicesController/services/feature-announcements.cjs.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.mjs.map +1 -1
- package/dist/NotificationServicesController/services/notification-config-cache.cjs.map +1 -1
- package/dist/NotificationServicesController/services/notification-config-cache.mjs.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.cjs +0 -1
- package/dist/NotificationServicesController/services/perp-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/perp-notifications.mjs +0 -1
- package/dist/NotificationServicesController/services/perp-notifications.mjs.map +1 -1
- package/dist/NotificationServicesController/types/index.cjs.map +1 -1
- package/dist/NotificationServicesController/types/index.d.cts +1 -1
- package/dist/NotificationServicesController/types/index.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/index.d.mts +1 -1
- package/dist/NotificationServicesController/types/index.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/index.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.cjs.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.d.cts +3 -11
- package/dist/NotificationServicesController/types/notification/notification.d.cts.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.d.mts +3 -11
- package/dist/NotificationServicesController/types/notification/notification.d.mts.map +1 -1
- package/dist/NotificationServicesController/types/notification/notification.mjs.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/index.cjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.cts +3 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.mts +3 -0
- package/dist/NotificationServicesController/types/notification-api/index.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/index.mjs.map +1 -0
- package/dist/NotificationServicesController/types/{on-chain-notification/on-chain-notification.cjs → notification-api/notification-api.cjs} +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.cjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts +64 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts +64 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.mjs +2 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.mjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.cjs +4 -0
- package/dist/NotificationServicesController/types/notification-api/schema.cjs.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts +365 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.cts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts +365 -0
- package/dist/NotificationServicesController/types/notification-api/schema.d.mts.map +1 -0
- package/dist/NotificationServicesController/types/notification-api/schema.mjs +3 -0
- package/dist/NotificationServicesController/types/notification-api/schema.mjs.map +1 -0
- package/dist/NotificationServicesController/ui/constants.d.cts +27 -27
- package/dist/NotificationServicesController/ui/constants.d.mts +27 -27
- package/dist/NotificationServicesController/utils/isVersionInBounds.cjs.map +1 -1
- package/dist/NotificationServicesController/utils/isVersionInBounds.mjs.map +1 -1
- package/dist/NotificationServicesController/utils/should-auto-expire.cjs +12 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.cjs.map +1 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.cts +2 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.cts.map +1 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.mts +2 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.d.mts.map +1 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.mjs +8 -0
- package/dist/NotificationServicesController/utils/should-auto-expire.mjs.map +1 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +2 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +2 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +2 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +2 -0
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.cjs.map +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs +1 -1
- package/dist/NotificationServicesPushController/mocks/mockResponse.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.cjs +10 -3
- package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.cts +3 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.mts +3 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.mjs +7 -2
- package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.cjs +5 -2
- package/dist/NotificationServicesPushController/services/push/push-web.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/push/push-web.mjs +6 -3
- package/dist/NotificationServicesPushController/services/push/push-web.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs +2 -1
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +3 -0
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +3 -0
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +2 -1
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-data.mjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs +51 -43
- package/dist/NotificationServicesPushController/utils/get-notification-message.cjs.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts +4 -2
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts +4 -2
- package/dist/NotificationServicesPushController/utils/get-notification-message.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs +51 -43
- package/dist/NotificationServicesPushController/utils/get-notification-message.mjs.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.cjs +5 -2
- package/dist/NotificationServicesPushController/web/push-utils.cjs.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/web/push-utils.mjs +6 -3
- package/dist/NotificationServicesPushController/web/push-utils.mjs.map +1 -1
- package/dist/shared/is-onchain-notification.cjs +1 -2
- package/dist/shared/is-onchain-notification.cjs.map +1 -1
- package/dist/shared/is-onchain-notification.d.cts.map +1 -1
- package/dist/shared/is-onchain-notification.d.mts.map +1 -1
- package/dist/shared/is-onchain-notification.mjs +1 -2
- package/dist/shared/is-onchain-notification.mjs.map +1 -1
- package/dist/shared/to-raw-notification.cjs +22 -6
- package/dist/shared/to-raw-notification.cjs.map +1 -1
- package/dist/shared/to-raw-notification.d.cts +2 -2
- package/dist/shared/to-raw-notification.d.cts.map +1 -1
- package/dist/shared/to-raw-notification.d.mts +2 -2
- package/dist/shared/to-raw-notification.d.mts.map +1 -1
- package/dist/shared/to-raw-notification.mjs +20 -4
- package/dist/shared/to-raw-notification.mjs.map +1 -1
- package/package.json +9 -7
- package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs +0 -19
- package/dist/NotificationServicesController/processors/process-onchain-notifications.cjs.map +0 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts +0 -10
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.cts.map +0 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts +0 -10
- package/dist/NotificationServicesController/processors/process-onchain-notifications.d.mts.map +0 -1
- package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs +0 -15
- package/dist/NotificationServicesController/processors/process-onchain-notifications.mjs.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.cjs.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.cts.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.d.mts.map +0 -1
- package/dist/NotificationServicesController/services/onchain-notifications.mjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.cjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts +0 -2
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts +0 -2
- package/dist/NotificationServicesController/types/on-chain-notification/index.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/index.mjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.cjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts +0 -49
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts +0 -49
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs +0 -2
- package/dist/NotificationServicesController/types/on-chain-notification/on-chain-notification.mjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs +0 -10
- package/dist/NotificationServicesController/types/on-chain-notification/schema.cjs.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts +0 -681
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.cts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts +0 -681
- package/dist/NotificationServicesController/types/on-chain-notification/schema.d.mts.map +0 -1
- package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs +0 -9
- package/dist/NotificationServicesController/types/on-chain-notification/schema.mjs.map +0 -1
- /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.cjs +0 -0
- /package/dist/NotificationServicesController/types/{on-chain-notification → notification-api}/index.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"process-notifications.d.mts","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,aAAa,EAEd,6CAAyC;AAE1C,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACrB,+CAA2C;AAkB5C;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,oBAAoB,EAClC,iBAAiB,GAAE,MAAM,EAAO,GAC/B,aAAa,CAuBf;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,oBAAoB,EAClC,iBAAiB,GAAE,MAAM,EAAO,GAC/B,aAAa,GAAG,SAAS,CAU3B;AAGD,eAAO,MAAM,6BAA6B,OACpC,oBAAoB,EAAE,WACjB,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAC2D,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { processAPINotifications } from "./process-api-notifications.mjs";
|
|
1
2
|
import { isFeatureAnnouncementRead, processFeatureAnnouncement } from "./process-feature-announcement.mjs";
|
|
2
|
-
import { processOnChainNotification } from "./process-onchain-notifications.mjs";
|
|
3
3
|
import { processSnapNotification } from "./process-snap-notifications.mjs";
|
|
4
|
-
import { TRIGGER_TYPES } from "../constants/notification-schema.mjs";
|
|
5
|
-
const isOnChainNotification = (n) =>
|
|
4
|
+
import { TRIGGER_TYPES, NOTIFICATION_API_TRIGGER_TYPES_SET } from "../constants/notification-schema.mjs";
|
|
5
|
+
const isOnChainNotification = (n) => NOTIFICATION_API_TRIGGER_TYPES_SET.has(n.type);
|
|
6
6
|
const isFeatureAnnouncement = (n) => n.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;
|
|
7
7
|
const isSnapNotification = (n) => n.type === TRIGGER_TYPES.SNAP;
|
|
8
8
|
/**
|
|
@@ -27,7 +27,7 @@ export function processNotification(notification, readNotifications = []) {
|
|
|
27
27
|
return processSnapNotification(notification);
|
|
28
28
|
}
|
|
29
29
|
if (isOnChainNotification(notification)) {
|
|
30
|
-
return
|
|
30
|
+
return processAPINotifications(notification);
|
|
31
31
|
}
|
|
32
32
|
return exhaustedAllCases(notification);
|
|
33
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"process-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC3B,2CAAuC;AACxC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"process-notifications.mjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/processors/process-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,E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;AAClD,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,CAAQ,EAAa,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAC3C,EAA0B,EAC1B,OAAiB,EACjB,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,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 n: RawNotificationUnion,\n): n is NormalisedAPINotification =>\n NOTIFICATION_API_TRIGGER_TYPES_SET.has(n.type);\n\nconst isFeatureAnnouncement = (\n n: RawNotificationUnion,\n): n is FeatureAnnouncementRawNotification =>\n n.type === TRIGGER_TYPES.FEATURES_ANNOUNCEMENT;\n\nconst isSnapNotification = (\n n: RawNotificationUnion,\n): n is RawSnapNotification => n.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 = (_: 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 n = processFeatureAnnouncement(\n notification as FeatureAnnouncementRawNotification,\n );\n n.isRead = isFeatureAnnouncementRead(n, readNotifications);\n return n;\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 as never);\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>(t?: Item): t is Item => Boolean(t);\nexport const processAndFilterNotifications = (\n ns: RawNotificationUnion[],\n readIds: string[],\n) => ns.map((n) => safeProcessNotification(n, readIds)).filter(isNotUndefined);\n"]}
|
|
@@ -3,31 +3,48 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.markNotificationsAsRead = exports.
|
|
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
8
|
const notification_config_cache_1 = require("./notification-config-cache.cjs");
|
|
9
9
|
const to_raw_notification_1 = require("../../shared/to-raw-notification.cjs");
|
|
10
10
|
const utils_1 = require("../utils/utils.cjs");
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const TRIGGER_API_ENV = {
|
|
12
|
+
dev: 'https://trigger.dev-api.cx.metamask.io',
|
|
13
|
+
uat: 'https://trigger.uat-api.cx.metamask.io',
|
|
14
|
+
prd: 'https://trigger.api.cx.metamask.io',
|
|
15
|
+
};
|
|
16
|
+
const TRIGGER_API = (env = 'prd') => TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;
|
|
17
|
+
exports.TRIGGER_API = TRIGGER_API;
|
|
18
|
+
const NOTIFICATION_API_ENV = {
|
|
19
|
+
dev: 'https://notification.dev-api.cx.metamask.io',
|
|
20
|
+
uat: 'https://notification.uat-api.cx.metamask.io',
|
|
21
|
+
prd: 'https://notification.api.cx.metamask.io',
|
|
22
|
+
};
|
|
23
|
+
const NOTIFICATION_API = (env = 'prd') => NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;
|
|
24
|
+
exports.NOTIFICATION_API = NOTIFICATION_API;
|
|
13
25
|
// Gets notification settings for each account provided
|
|
14
|
-
|
|
26
|
+
const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (env = 'prd') => `${(0, exports.TRIGGER_API)(env)}/api/v2/notifications/query`;
|
|
27
|
+
exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT;
|
|
15
28
|
// Used to create/update account notifications for each account provided
|
|
16
|
-
|
|
29
|
+
const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env = 'prd') => `${(0, exports.TRIGGER_API)(env)}/api/v2/notifications`;
|
|
30
|
+
exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = TRIGGER_API_NOTIFICATIONS_ENDPOINT;
|
|
17
31
|
// Lists notifications for each account provided
|
|
18
|
-
|
|
32
|
+
const NOTIFICATION_API_LIST_ENDPOINT = (env = 'prd') => `${(0, exports.NOTIFICATION_API)(env)}/api/v3/notifications`;
|
|
33
|
+
exports.NOTIFICATION_API_LIST_ENDPOINT = NOTIFICATION_API_LIST_ENDPOINT;
|
|
19
34
|
// Makrs notifications as read
|
|
20
|
-
|
|
35
|
+
const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env = 'prd') => `${(0, exports.NOTIFICATION_API)(env)}/api/v3/notifications/mark-as-read`;
|
|
36
|
+
exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT;
|
|
21
37
|
/**
|
|
22
38
|
* fetches notification config (accounts enabled vs disabled)
|
|
23
39
|
*
|
|
24
40
|
* @param bearerToken - jwt
|
|
25
41
|
* @param addresses - list of addresses to check
|
|
42
|
+
* @param env - the environment to use for the API call
|
|
26
43
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
27
44
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
28
45
|
* @returns object of notification config, or null if missing
|
|
29
46
|
*/
|
|
30
|
-
async function
|
|
47
|
+
async function getNotificationsApiConfigCached(bearerToken, addresses, env = 'prd') {
|
|
31
48
|
if (addresses.length === 0) {
|
|
32
49
|
return [];
|
|
33
50
|
}
|
|
@@ -37,7 +54,7 @@ async function getOnChainNotificationsConfigCached(bearerToken, addresses) {
|
|
|
37
54
|
return cached;
|
|
38
55
|
}
|
|
39
56
|
const body = addresses.map((address) => ({ address }));
|
|
40
|
-
const data = await (0, utils_1.makeApiCall)(bearerToken, exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT, 'POST', body)
|
|
57
|
+
const data = await (0, utils_1.makeApiCall)(bearerToken, (0, exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT)(env), 'POST', body)
|
|
41
58
|
.then((r) => (r.ok ? r.json() : null))
|
|
42
59
|
.catch(() => null);
|
|
43
60
|
const result = data ?? [];
|
|
@@ -46,15 +63,16 @@ async function getOnChainNotificationsConfigCached(bearerToken, addresses) {
|
|
|
46
63
|
}
|
|
47
64
|
return result;
|
|
48
65
|
}
|
|
49
|
-
exports.
|
|
66
|
+
exports.getNotificationsApiConfigCached = getNotificationsApiConfigCached;
|
|
50
67
|
/**
|
|
51
68
|
* updates notifications for a given addresses
|
|
52
69
|
*
|
|
53
70
|
* @param bearerToken - jwt
|
|
54
71
|
* @param addresses - list of addresses to check
|
|
72
|
+
* @param env - the environment to use for the API call
|
|
55
73
|
* @returns void
|
|
56
74
|
*/
|
|
57
|
-
async function updateOnChainNotifications(bearerToken, addresses) {
|
|
75
|
+
async function updateOnChainNotifications(bearerToken, addresses, env = 'prd') {
|
|
58
76
|
if (addresses.length === 0) {
|
|
59
77
|
return;
|
|
60
78
|
}
|
|
@@ -63,7 +81,7 @@ async function updateOnChainNotifications(bearerToken, addresses) {
|
|
|
63
81
|
return a;
|
|
64
82
|
});
|
|
65
83
|
const body = addresses;
|
|
66
|
-
await (0, utils_1.makeApiCall)(bearerToken, exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT, 'POST', body)
|
|
84
|
+
await (0, utils_1.makeApiCall)(bearerToken, (0, exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT)(env), 'POST', body)
|
|
67
85
|
.then(() => notification_config_cache_1.notificationsConfigCache.set(addresses))
|
|
68
86
|
.catch(() => null);
|
|
69
87
|
}
|
|
@@ -73,29 +91,40 @@ exports.updateOnChainNotifications = updateOnChainNotifications;
|
|
|
73
91
|
*
|
|
74
92
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
75
93
|
* @param addresses - List of addresses
|
|
76
|
-
* @
|
|
94
|
+
* @param locale - to generate translated notifications
|
|
95
|
+
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
96
|
+
* @param env - the environment to use for the API call
|
|
97
|
+
* @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.
|
|
77
98
|
*/
|
|
78
|
-
async function
|
|
99
|
+
async function getAPINotifications(bearerToken, addresses, locale, platform, env = 'prd') {
|
|
79
100
|
if (addresses.length === 0) {
|
|
80
101
|
return [];
|
|
81
102
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
103
|
+
const body = {
|
|
104
|
+
addresses: addresses.map((a) => a.toLowerCase()),
|
|
105
|
+
locale,
|
|
106
|
+
platform,
|
|
107
|
+
};
|
|
108
|
+
const notifications = await (0, utils_1.makeApiCall)(bearerToken, (0, exports.NOTIFICATION_API_LIST_ENDPOINT)(env), 'POST', body)
|
|
109
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
86
110
|
.catch(() => null);
|
|
87
111
|
// Transform and sort notifications
|
|
88
112
|
const transformedNotifications = notifications
|
|
89
113
|
?.map((n) => {
|
|
90
|
-
if (!n.
|
|
114
|
+
if (!n.notification_type) {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return (0, to_raw_notification_1.toRawAPINotification)(n);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
91
121
|
return undefined;
|
|
92
122
|
}
|
|
93
|
-
return (0, to_raw_notification_1.toRawOnChainNotification)(n);
|
|
94
123
|
})
|
|
95
124
|
.filter((n) => Boolean(n));
|
|
96
125
|
return transformedNotifications ?? [];
|
|
97
126
|
}
|
|
98
|
-
exports.
|
|
127
|
+
exports.getAPINotifications = getAPINotifications;
|
|
99
128
|
/**
|
|
100
129
|
* Marks the specified notifications as read.
|
|
101
130
|
* This method sends a POST request to the notifications service to mark the provided notification IDs as read.
|
|
@@ -103,18 +132,22 @@ exports.getOnChainNotifications = getOnChainNotifications;
|
|
|
103
132
|
*
|
|
104
133
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
105
134
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
135
|
+
* @param env - the environment to use for the API call
|
|
106
136
|
* @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.
|
|
107
137
|
*/
|
|
108
|
-
async function markNotificationsAsRead(bearerToken, notificationIds) {
|
|
138
|
+
async function markNotificationsAsRead(bearerToken, notificationIds, env = 'prd') {
|
|
109
139
|
if (notificationIds.length === 0) {
|
|
110
140
|
return;
|
|
111
141
|
}
|
|
142
|
+
const body = {
|
|
143
|
+
ids: notificationIds,
|
|
144
|
+
};
|
|
112
145
|
try {
|
|
113
|
-
await (0, utils_1.makeApiCall)(bearerToken, exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, 'POST',
|
|
146
|
+
await (0, utils_1.makeApiCall)(bearerToken, (0, exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT)(env), 'POST', body);
|
|
114
147
|
}
|
|
115
148
|
catch (err) {
|
|
116
149
|
loglevel_1.default.error('Error marking notifications as read:', err);
|
|
117
150
|
}
|
|
118
151
|
}
|
|
119
152
|
exports.markNotificationsAsRead = markNotificationsAsRead;
|
|
120
|
-
//# sourceMappingURL=
|
|
153
|
+
//# sourceMappingURL=api-notifications.cjs.map
|
|
@@ -0,0 +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,KA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AC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAkC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7D,OAAO,wBAAwB,IAAI,EAAE,CAAC;AACxC,CAAC;AA9CD,kDA8CC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,uBAAuB,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,IAAA,mBAAW,EACf,WAAW,EACX,IAAA,kDAA0C,EAAC,GAAG,CAAC,EAC/C,MAAM,EACN,IAAI,CACL,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,kBAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;IACzD,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') =>\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') =>\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 = (env: ENV = 'prd') =>\n `${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') =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd') =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Makrs notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env: ENV = 'prd') =>\n `${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) {\n if (addresses.length === 0) {\n return [];\n }\n\n addresses = addresses.map((a) => a.toLowerCase());\n\n const cached = notificationsConfigCache.get(addresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses.map((address) => ({ address }));\n const data = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n const result = data ?? [];\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) {\n if (addresses.length === 0) {\n return;\n }\n\n addresses = addresses.map((a) => {\n a.address = a.address.toLowerCase();\n return a;\n });\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(addresses))\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((a) => a.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>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((n): UnprocessedRawNotification | undefined => {\n if (!n.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(n);\n } catch {\n return undefined;\n }\n })\n .filter((n): n is NormalisedAPINotification => Boolean(n));\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 (err) {\n log.error('Error marking notifications as read:', err);\n }\n}\n"]}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NormalisedAPINotification } from "../types/notification-api/index.cjs";
|
|
2
2
|
export type NotificationTrigger = {
|
|
3
3
|
id: string;
|
|
4
4
|
chainId: string;
|
|
5
5
|
kind: string;
|
|
6
6
|
address: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
8
|
+
export type ENV = 'prd' | 'uat' | 'dev';
|
|
9
|
+
export declare const TRIGGER_API: (env?: ENV) => string;
|
|
10
|
+
export declare const NOTIFICATION_API: (env?: ENV) => string;
|
|
11
|
+
export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT: (env?: ENV) => string;
|
|
12
|
+
export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT: (env?: ENV) => string;
|
|
13
|
+
export declare const NOTIFICATION_API_LIST_ENDPOINT: (env?: ENV) => string;
|
|
14
|
+
export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT: (env?: ENV) => string;
|
|
14
15
|
/**
|
|
15
16
|
* fetches notification config (accounts enabled vs disabled)
|
|
16
17
|
*
|
|
17
18
|
* @param bearerToken - jwt
|
|
18
19
|
* @param addresses - list of addresses to check
|
|
20
|
+
* @param env - the environment to use for the API call
|
|
19
21
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
20
22
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
21
23
|
* @returns object of notification config, or null if missing
|
|
22
24
|
*/
|
|
23
|
-
export declare function
|
|
25
|
+
export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[], env?: ENV): Promise<{
|
|
24
26
|
address: string;
|
|
25
27
|
enabled: boolean;
|
|
26
28
|
}[]>;
|
|
@@ -29,20 +31,24 @@ export declare function getOnChainNotificationsConfigCached(bearerToken: string,
|
|
|
29
31
|
*
|
|
30
32
|
* @param bearerToken - jwt
|
|
31
33
|
* @param addresses - list of addresses to check
|
|
34
|
+
* @param env - the environment to use for the API call
|
|
32
35
|
* @returns void
|
|
33
36
|
*/
|
|
34
37
|
export declare function updateOnChainNotifications(bearerToken: string, addresses: {
|
|
35
38
|
address: string;
|
|
36
39
|
enabled: boolean;
|
|
37
|
-
}[]): Promise<void>;
|
|
40
|
+
}[], env?: ENV): Promise<void>;
|
|
38
41
|
/**
|
|
39
42
|
* Fetches on-chain notifications for the given addresses
|
|
40
43
|
*
|
|
41
44
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
42
45
|
* @param addresses - List of addresses
|
|
43
|
-
* @
|
|
46
|
+
* @param locale - to generate translated notifications
|
|
47
|
+
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
48
|
+
* @param env - the environment to use for the API call
|
|
49
|
+
* @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.
|
|
44
50
|
*/
|
|
45
|
-
export declare function
|
|
51
|
+
export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile', env?: ENV): Promise<NormalisedAPINotification[]>;
|
|
46
52
|
/**
|
|
47
53
|
* Marks the specified notifications as read.
|
|
48
54
|
* This method sends a POST request to the notifications service to mark the provided notification IDs as read.
|
|
@@ -50,7 +56,8 @@ export declare function getOnChainNotifications(bearerToken: string, addresses:
|
|
|
50
56
|
*
|
|
51
57
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
52
58
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
59
|
+
* @param env - the environment to use for the API call
|
|
53
60
|
* @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.
|
|
54
61
|
*/
|
|
55
|
-
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]): Promise<void>;
|
|
56
|
-
//# sourceMappingURL=
|
|
62
|
+
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[], env?: ENV): Promise<void>;
|
|
63
|
+
//# sourceMappingURL=api-notifications.d.cts.map
|
|
@@ -0,0 +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,WACS,CAAC;AAQ9C,eAAO,MAAM,gBAAgB,SAAS,GAAG,WACc,CAAC;AAGxD,eAAO,MAAM,wCAAwC,SAAS,GAAG,WACf,CAAC;AAGnD,eAAO,MAAM,kCAAkC,SAAS,GAAG,WACf,CAAC;AAG7C,eAAO,MAAM,8BAA8B,SAAS,GAAG,WACN,CAAC;AAGlD,eAAO,MAAM,0CAA0C,SAAS,GAAG,WACL,CAAC;AAE/D;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,GAAW;;;KAgCjB;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,iBAqBjB;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,CAwCtC;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,26 +1,28 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NormalisedAPINotification } from "../types/notification-api/index.mjs";
|
|
2
2
|
export type NotificationTrigger = {
|
|
3
3
|
id: string;
|
|
4
4
|
chainId: string;
|
|
5
5
|
kind: string;
|
|
6
6
|
address: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
8
|
+
export type ENV = 'prd' | 'uat' | 'dev';
|
|
9
|
+
export declare const TRIGGER_API: (env?: ENV) => string;
|
|
10
|
+
export declare const NOTIFICATION_API: (env?: ENV) => string;
|
|
11
|
+
export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT: (env?: ENV) => string;
|
|
12
|
+
export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT: (env?: ENV) => string;
|
|
13
|
+
export declare const NOTIFICATION_API_LIST_ENDPOINT: (env?: ENV) => string;
|
|
14
|
+
export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT: (env?: ENV) => string;
|
|
14
15
|
/**
|
|
15
16
|
* fetches notification config (accounts enabled vs disabled)
|
|
16
17
|
*
|
|
17
18
|
* @param bearerToken - jwt
|
|
18
19
|
* @param addresses - list of addresses to check
|
|
20
|
+
* @param env - the environment to use for the API call
|
|
19
21
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
20
22
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
21
23
|
* @returns object of notification config, or null if missing
|
|
22
24
|
*/
|
|
23
|
-
export declare function
|
|
25
|
+
export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[], env?: ENV): Promise<{
|
|
24
26
|
address: string;
|
|
25
27
|
enabled: boolean;
|
|
26
28
|
}[]>;
|
|
@@ -29,20 +31,24 @@ export declare function getOnChainNotificationsConfigCached(bearerToken: string,
|
|
|
29
31
|
*
|
|
30
32
|
* @param bearerToken - jwt
|
|
31
33
|
* @param addresses - list of addresses to check
|
|
34
|
+
* @param env - the environment to use for the API call
|
|
32
35
|
* @returns void
|
|
33
36
|
*/
|
|
34
37
|
export declare function updateOnChainNotifications(bearerToken: string, addresses: {
|
|
35
38
|
address: string;
|
|
36
39
|
enabled: boolean;
|
|
37
|
-
}[]): Promise<void>;
|
|
40
|
+
}[], env?: ENV): Promise<void>;
|
|
38
41
|
/**
|
|
39
42
|
* Fetches on-chain notifications for the given addresses
|
|
40
43
|
*
|
|
41
44
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
42
45
|
* @param addresses - List of addresses
|
|
43
|
-
* @
|
|
46
|
+
* @param locale - to generate translated notifications
|
|
47
|
+
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
48
|
+
* @param env - the environment to use for the API call
|
|
49
|
+
* @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.
|
|
44
50
|
*/
|
|
45
|
-
export declare function
|
|
51
|
+
export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile', env?: ENV): Promise<NormalisedAPINotification[]>;
|
|
46
52
|
/**
|
|
47
53
|
* Marks the specified notifications as read.
|
|
48
54
|
* This method sends a POST request to the notifications service to mark the provided notification IDs as read.
|
|
@@ -50,7 +56,8 @@ export declare function getOnChainNotifications(bearerToken: string, addresses:
|
|
|
50
56
|
*
|
|
51
57
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
52
58
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
59
|
+
* @param env - the environment to use for the API call
|
|
53
60
|
* @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.
|
|
54
61
|
*/
|
|
55
|
-
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]): Promise<void>;
|
|
56
|
-
//# sourceMappingURL=
|
|
62
|
+
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[], env?: ENV): Promise<void>;
|
|
63
|
+
//# sourceMappingURL=api-notifications.d.mts.map
|
|
@@ -0,0 +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,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,WACS,CAAC;AAQ9C,eAAO,MAAM,gBAAgB,SAAS,GAAG,WACc,CAAC;AAGxD,eAAO,MAAM,wCAAwC,SAAS,GAAG,WACf,CAAC;AAGnD,eAAO,MAAM,kCAAkC,SAAS,GAAG,WACf,CAAC;AAG7C,eAAO,MAAM,8BAA8B,SAAS,GAAG,WACN,CAAC;AAGlD,eAAO,MAAM,0CAA0C,SAAS,GAAG,WACL,CAAC;AAE/D;;;;;;;;;GASG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,GAAG,GAAE,GAAW;;;KAgCjB;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,iBAqBjB;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,CAwCtC;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,GAAE,GAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAqBf"}
|
|
@@ -7,28 +7,39 @@ function $importDefault(module) {
|
|
|
7
7
|
import $log from "loglevel";
|
|
8
8
|
const log = $importDefault($log);
|
|
9
9
|
import { notificationsConfigCache } from "./notification-config-cache.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { toRawAPINotification } from "../../shared/to-raw-notification.mjs";
|
|
11
11
|
import { makeApiCall } from "../utils/utils.mjs";
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const TRIGGER_API_ENV = {
|
|
13
|
+
dev: 'https://trigger.dev-api.cx.metamask.io',
|
|
14
|
+
uat: 'https://trigger.uat-api.cx.metamask.io',
|
|
15
|
+
prd: 'https://trigger.api.cx.metamask.io',
|
|
16
|
+
};
|
|
17
|
+
export const TRIGGER_API = (env = 'prd') => TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;
|
|
18
|
+
const NOTIFICATION_API_ENV = {
|
|
19
|
+
dev: 'https://notification.dev-api.cx.metamask.io',
|
|
20
|
+
uat: 'https://notification.uat-api.cx.metamask.io',
|
|
21
|
+
prd: 'https://notification.api.cx.metamask.io',
|
|
22
|
+
};
|
|
23
|
+
export const NOTIFICATION_API = (env = 'prd') => NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;
|
|
14
24
|
// Gets notification settings for each account provided
|
|
15
|
-
export const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = `${TRIGGER_API}/api/v2/notifications/query`;
|
|
25
|
+
export const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (env = 'prd') => `${TRIGGER_API(env)}/api/v2/notifications/query`;
|
|
16
26
|
// Used to create/update account notifications for each account provided
|
|
17
|
-
export const TRIGGER_API_NOTIFICATIONS_ENDPOINT = `${TRIGGER_API}/api/v2/notifications`;
|
|
27
|
+
export const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env = 'prd') => `${TRIGGER_API(env)}/api/v2/notifications`;
|
|
18
28
|
// Lists notifications for each account provided
|
|
19
|
-
export const NOTIFICATION_API_LIST_ENDPOINT = `${NOTIFICATION_API}/api/
|
|
29
|
+
export const NOTIFICATION_API_LIST_ENDPOINT = (env = 'prd') => `${NOTIFICATION_API(env)}/api/v3/notifications`;
|
|
20
30
|
// Makrs notifications as read
|
|
21
|
-
export const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${NOTIFICATION_API}/api/
|
|
31
|
+
export const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env = 'prd') => `${NOTIFICATION_API(env)}/api/v3/notifications/mark-as-read`;
|
|
22
32
|
/**
|
|
23
33
|
* fetches notification config (accounts enabled vs disabled)
|
|
24
34
|
*
|
|
25
35
|
* @param bearerToken - jwt
|
|
26
36
|
* @param addresses - list of addresses to check
|
|
37
|
+
* @param env - the environment to use for the API call
|
|
27
38
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
28
39
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
29
40
|
* @returns object of notification config, or null if missing
|
|
30
41
|
*/
|
|
31
|
-
export async function
|
|
42
|
+
export async function getNotificationsApiConfigCached(bearerToken, addresses, env = 'prd') {
|
|
32
43
|
if (addresses.length === 0) {
|
|
33
44
|
return [];
|
|
34
45
|
}
|
|
@@ -38,7 +49,7 @@ export async function getOnChainNotificationsConfigCached(bearerToken, addresses
|
|
|
38
49
|
return cached;
|
|
39
50
|
}
|
|
40
51
|
const body = addresses.map((address) => ({ address }));
|
|
41
|
-
const data = await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT, 'POST', body)
|
|
52
|
+
const data = await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env), 'POST', body)
|
|
42
53
|
.then((r) => (r.ok ? r.json() : null))
|
|
43
54
|
.catch(() => null);
|
|
44
55
|
const result = data ?? [];
|
|
@@ -52,9 +63,10 @@ export async function getOnChainNotificationsConfigCached(bearerToken, addresses
|
|
|
52
63
|
*
|
|
53
64
|
* @param bearerToken - jwt
|
|
54
65
|
* @param addresses - list of addresses to check
|
|
66
|
+
* @param env - the environment to use for the API call
|
|
55
67
|
* @returns void
|
|
56
68
|
*/
|
|
57
|
-
export async function updateOnChainNotifications(bearerToken, addresses) {
|
|
69
|
+
export async function updateOnChainNotifications(bearerToken, addresses, env = 'prd') {
|
|
58
70
|
if (addresses.length === 0) {
|
|
59
71
|
return;
|
|
60
72
|
}
|
|
@@ -63,7 +75,7 @@ export async function updateOnChainNotifications(bearerToken, addresses) {
|
|
|
63
75
|
return a;
|
|
64
76
|
});
|
|
65
77
|
const body = addresses;
|
|
66
|
-
await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_ENDPOINT, 'POST', body)
|
|
78
|
+
await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_ENDPOINT(env), 'POST', body)
|
|
67
79
|
.then(() => notificationsConfigCache.set(addresses))
|
|
68
80
|
.catch(() => null);
|
|
69
81
|
}
|
|
@@ -72,24 +84,35 @@ export async function updateOnChainNotifications(bearerToken, addresses) {
|
|
|
72
84
|
*
|
|
73
85
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
74
86
|
* @param addresses - List of addresses
|
|
75
|
-
* @
|
|
87
|
+
* @param locale - to generate translated notifications
|
|
88
|
+
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
89
|
+
* @param env - the environment to use for the API call
|
|
90
|
+
* @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.
|
|
76
91
|
*/
|
|
77
|
-
export async function
|
|
92
|
+
export async function getAPINotifications(bearerToken, addresses, locale, platform, env = 'prd') {
|
|
78
93
|
if (addresses.length === 0) {
|
|
79
94
|
return [];
|
|
80
95
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
96
|
+
const body = {
|
|
97
|
+
addresses: addresses.map((a) => a.toLowerCase()),
|
|
98
|
+
locale,
|
|
99
|
+
platform,
|
|
100
|
+
};
|
|
101
|
+
const notifications = await makeApiCall(bearerToken, NOTIFICATION_API_LIST_ENDPOINT(env), 'POST', body)
|
|
102
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
85
103
|
.catch(() => null);
|
|
86
104
|
// Transform and sort notifications
|
|
87
105
|
const transformedNotifications = notifications
|
|
88
106
|
?.map((n) => {
|
|
89
|
-
if (!n.
|
|
107
|
+
if (!n.notification_type) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
return toRawAPINotification(n);
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
90
114
|
return undefined;
|
|
91
115
|
}
|
|
92
|
-
return toRawOnChainNotification(n);
|
|
93
116
|
})
|
|
94
117
|
.filter((n) => Boolean(n));
|
|
95
118
|
return transformedNotifications ?? [];
|
|
@@ -101,17 +124,21 @@ export async function getOnChainNotifications(bearerToken, addresses) {
|
|
|
101
124
|
*
|
|
102
125
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
103
126
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
127
|
+
* @param env - the environment to use for the API call
|
|
104
128
|
* @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.
|
|
105
129
|
*/
|
|
106
|
-
export async function markNotificationsAsRead(bearerToken, notificationIds) {
|
|
130
|
+
export async function markNotificationsAsRead(bearerToken, notificationIds, env = 'prd') {
|
|
107
131
|
if (notificationIds.length === 0) {
|
|
108
132
|
return;
|
|
109
133
|
}
|
|
134
|
+
const body = {
|
|
135
|
+
ids: notificationIds,
|
|
136
|
+
};
|
|
110
137
|
try {
|
|
111
|
-
await makeApiCall(bearerToken, NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, 'POST',
|
|
138
|
+
await makeApiCall(bearerToken, NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env), 'POST', body);
|
|
112
139
|
}
|
|
113
140
|
catch (err) {
|
|
114
141
|
log.error('Error marking notifications as read:', err);
|
|
115
142
|
}
|
|
116
143
|
}
|
|
117
|
-
//# sourceMappingURL=
|
|
144
|
+
//# sourceMappingURL=api-notifications.mjs.map
|
|
@@ -0,0 +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,EAAE,EAAE,CAC9C,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,EAAE,EAAE,CACnD,oBAAoB,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,GAAG,CAAC;AAExD,uDAAuD;AACvD,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CAC3E,GAAG,WAAW,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAEnD,wEAAwE;AACxE,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CACrE,GAAG,WAAW,CAAC,GAAG,CAAC,uBAAuB,CAAC;AAE7C,gDAAgD;AAChD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAAC,MAAW,KAAK,EAAE,EAAE,CACjE,GAAG,gBAAgB,CAAC,GAAG,CAAC,uBAAuB,CAAC;AAElD,8BAA8B;AAC9B,MAAM,CAAC,MAAM,0CAA0C,GAAG,CAAC,MAAW,KAAK,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;IAErB,mCAAmC;IACnC,MAAM,wBAAwB,GAAG,aAAa;QAC5C,EAAE,GAAG,CAAC,CAAC,CAAC,EAA0C,EAAE;QAClD,IAAI,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;YACzB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,IAAI,CAAC;YACH,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC;QACjC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAkC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7D,OAAO,wBAAwB,IAAI,EAAE,CAAC;AACxC,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,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,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,GAAG,CAAC,CAAC;IACzD,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') =>\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') =>\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 = (env: ENV = 'prd') =>\n `${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') =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd') =>\n `${NOTIFICATION_API(env)}/api/v3/notifications`;\n\n// Makrs notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env: ENV = 'prd') =>\n `${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) {\n if (addresses.length === 0) {\n return [];\n }\n\n addresses = addresses.map((a) => a.toLowerCase());\n\n const cached = notificationsConfigCache.get(addresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses.map((address) => ({ address }));\n const data = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n const result = data ?? [];\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) {\n if (addresses.length === 0) {\n return;\n }\n\n addresses = addresses.map((a) => {\n a.address = a.address.toLowerCase();\n return a;\n });\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = addresses;\n await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n )\n .then(() => notificationsConfigCache.set(addresses))\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((a) => a.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>((r) => (r.ok ? r.json() : null))\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((n): UnprocessedRawNotification | undefined => {\n if (!n.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(n);\n } catch {\n return undefined;\n }\n })\n .filter((n): n is NormalisedAPINotification => Boolean(n));\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 (err) {\n log.error('Error marking notifications as read:', err);\n }\n}\n"]}
|