@metamask-previews/notification-services-controller 20.0.0-preview-babd23f → 20.0.0-preview-dabf9bd8
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 +0 -5
- package/dist/NotificationServicesController/NotificationServicesController.cjs +11 -14
- package/dist/NotificationServicesController/NotificationServicesController.cjs.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.cts +0 -3
- package/dist/NotificationServicesController/NotificationServicesController.d.cts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.mts +0 -3
- package/dist/NotificationServicesController/NotificationServicesController.d.mts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.mjs +11 -14
- package/dist/NotificationServicesController/NotificationServicesController.mjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.cjs +4 -4
- package/dist/NotificationServicesController/mocks/mockResponses.cjs.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.mjs +4 -4
- package/dist/NotificationServicesController/mocks/mockResponses.mjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.cjs +14 -34
- package/dist/NotificationServicesController/services/api-notifications.cjs.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.cts +10 -15
- package/dist/NotificationServicesController/services/api-notifications.d.cts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.mts +10 -15
- package/dist/NotificationServicesController/services/api-notifications.d.mts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.mjs +14 -28
- package/dist/NotificationServicesController/services/api-notifications.mjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs +0 -2
- package/dist/NotificationServicesPushController/NotificationServicesPushController.cjs.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts +0 -2
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts +0 -2
- package/dist/NotificationServicesPushController/NotificationServicesPushController.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/NotificationServicesPushController.mjs +0 -2
- 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 +3 -10
- package/dist/NotificationServicesPushController/services/endpoints.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.cts +1 -3
- package/dist/NotificationServicesPushController/services/endpoints.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.d.mts +1 -3
- package/dist/NotificationServicesPushController/services/endpoints.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/endpoints.mjs +2 -7
- package/dist/NotificationServicesPushController/services/endpoints.mjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.cjs +1 -2
- package/dist/NotificationServicesPushController/services/services.cjs.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.cts +0 -3
- package/dist/NotificationServicesPushController/services/services.d.cts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.d.mts +0 -3
- package/dist/NotificationServicesPushController/services/services.d.mts.map +1 -1
- package/dist/NotificationServicesPushController/services/services.mjs +1 -2
- package/dist/NotificationServicesPushController/services/services.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -8,43 +8,26 @@ 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
|
-
|
|
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;
|
|
11
|
+
exports.TRIGGER_API = 'https://trigger.api.cx.metamask.io';
|
|
12
|
+
exports.NOTIFICATION_API = 'https://notification.api.cx.metamask.io';
|
|
25
13
|
// Gets notification settings for each account provided
|
|
26
|
-
|
|
27
|
-
exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT;
|
|
14
|
+
exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = `${exports.TRIGGER_API}/api/v2/notifications/query`;
|
|
28
15
|
// Used to create/update account notifications for each account provided
|
|
29
|
-
|
|
30
|
-
exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = TRIGGER_API_NOTIFICATIONS_ENDPOINT;
|
|
16
|
+
exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT = `${exports.TRIGGER_API}/api/v2/notifications`;
|
|
31
17
|
// Lists notifications for each account provided
|
|
32
|
-
|
|
33
|
-
exports.NOTIFICATION_API_LIST_ENDPOINT = NOTIFICATION_API_LIST_ENDPOINT;
|
|
18
|
+
exports.NOTIFICATION_API_LIST_ENDPOINT = `${exports.NOTIFICATION_API}/api/v3/notifications`;
|
|
34
19
|
// Makrs notifications as read
|
|
35
|
-
|
|
36
|
-
exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT;
|
|
20
|
+
exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${exports.NOTIFICATION_API}/api/v3/notifications/mark-as-read`;
|
|
37
21
|
/**
|
|
38
22
|
* fetches notification config (accounts enabled vs disabled)
|
|
39
23
|
*
|
|
40
24
|
* @param bearerToken - jwt
|
|
41
25
|
* @param addresses - list of addresses to check
|
|
42
|
-
* @param env - the environment to use for the API call
|
|
43
26
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
44
27
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
45
28
|
* @returns object of notification config, or null if missing
|
|
46
29
|
*/
|
|
47
|
-
async function getNotificationsApiConfigCached(bearerToken, addresses
|
|
30
|
+
async function getNotificationsApiConfigCached(bearerToken, addresses) {
|
|
48
31
|
if (addresses.length === 0) {
|
|
49
32
|
return [];
|
|
50
33
|
}
|
|
@@ -54,7 +37,7 @@ async function getNotificationsApiConfigCached(bearerToken, addresses, env = 'pr
|
|
|
54
37
|
return cached;
|
|
55
38
|
}
|
|
56
39
|
const body = addresses.map((address) => ({ address }));
|
|
57
|
-
const data = await (0, utils_1.makeApiCall)(bearerToken,
|
|
40
|
+
const data = await (0, utils_1.makeApiCall)(bearerToken, exports.TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT, 'POST', body)
|
|
58
41
|
.then((r) => (r.ok ? r.json() : null))
|
|
59
42
|
.catch(() => null);
|
|
60
43
|
const result = data ?? [];
|
|
@@ -69,10 +52,9 @@ exports.getNotificationsApiConfigCached = getNotificationsApiConfigCached;
|
|
|
69
52
|
*
|
|
70
53
|
* @param bearerToken - jwt
|
|
71
54
|
* @param addresses - list of addresses to check
|
|
72
|
-
* @param env - the environment to use for the API call
|
|
73
55
|
* @returns void
|
|
74
56
|
*/
|
|
75
|
-
async function updateOnChainNotifications(bearerToken, addresses
|
|
57
|
+
async function updateOnChainNotifications(bearerToken, addresses) {
|
|
76
58
|
if (addresses.length === 0) {
|
|
77
59
|
return;
|
|
78
60
|
}
|
|
@@ -81,7 +63,7 @@ async function updateOnChainNotifications(bearerToken, addresses, env = 'prd') {
|
|
|
81
63
|
return a;
|
|
82
64
|
});
|
|
83
65
|
const body = addresses;
|
|
84
|
-
await (0, utils_1.makeApiCall)(bearerToken,
|
|
66
|
+
await (0, utils_1.makeApiCall)(bearerToken, exports.TRIGGER_API_NOTIFICATIONS_ENDPOINT, 'POST', body)
|
|
85
67
|
.then(() => notification_config_cache_1.notificationsConfigCache.set(addresses))
|
|
86
68
|
.catch(() => null);
|
|
87
69
|
}
|
|
@@ -93,10 +75,9 @@ exports.updateOnChainNotifications = updateOnChainNotifications;
|
|
|
93
75
|
* @param addresses - List of addresses
|
|
94
76
|
* @param locale - to generate translated notifications
|
|
95
77
|
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
96
|
-
* @param env - the environment to use for the API call
|
|
97
78
|
* @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.
|
|
98
79
|
*/
|
|
99
|
-
async function getAPINotifications(bearerToken, addresses, locale, platform
|
|
80
|
+
async function getAPINotifications(bearerToken, addresses, locale, platform) {
|
|
100
81
|
if (addresses.length === 0) {
|
|
101
82
|
return [];
|
|
102
83
|
}
|
|
@@ -105,7 +86,7 @@ async function getAPINotifications(bearerToken, addresses, locale, platform, env
|
|
|
105
86
|
locale,
|
|
106
87
|
platform,
|
|
107
88
|
};
|
|
108
|
-
const notifications = await (0, utils_1.makeApiCall)(bearerToken,
|
|
89
|
+
const notifications = await (0, utils_1.makeApiCall)(bearerToken, exports.NOTIFICATION_API_LIST_ENDPOINT, 'POST', body)
|
|
109
90
|
.then((r) => (r.ok ? r.json() : null))
|
|
110
91
|
.catch(() => null);
|
|
111
92
|
// Transform and sort notifications
|
|
@@ -132,10 +113,9 @@ exports.getAPINotifications = getAPINotifications;
|
|
|
132
113
|
*
|
|
133
114
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
134
115
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
135
|
-
* @param env - the environment to use for the API call
|
|
136
116
|
* @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.
|
|
137
117
|
*/
|
|
138
|
-
async function markNotificationsAsRead(bearerToken, notificationIds
|
|
118
|
+
async function markNotificationsAsRead(bearerToken, notificationIds) {
|
|
139
119
|
if (notificationIds.length === 0) {
|
|
140
120
|
return;
|
|
141
121
|
}
|
|
@@ -143,7 +123,7 @@ async function markNotificationsAsRead(bearerToken, notificationIds, env = 'prd'
|
|
|
143
123
|
ids: notificationIds,
|
|
144
124
|
};
|
|
145
125
|
try {
|
|
146
|
-
await (0, utils_1.makeApiCall)(bearerToken,
|
|
126
|
+
await (0, utils_1.makeApiCall)(bearerToken, exports.NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, 'POST', body);
|
|
147
127
|
}
|
|
148
128
|
catch (err) {
|
|
149
129
|
loglevel_1.default.error('Error marking notifications as read:', err);
|
|
@@ -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,EAAE,EAAE,CAC9C,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;A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;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
|
+
{"version":3,"file":"api-notifications.cjs","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":";;;;;;AAAA,wDAA2B;AAE3B,+EAAuE;AACvE,8EAAwE;AAMxE,8CAA6C;AAShC,QAAA,WAAW,GAAG,oCAAoC,CAAC;AACnD,QAAA,gBAAgB,GAAG,yCAAyC,CAAC;AAE1E,uDAAuD;AAC1C,QAAA,wCAAwC,GAAG,GAAG,mBAAW,6BAA6B,CAAC;AAEpG,wEAAwE;AAC3D,QAAA,kCAAkC,GAAG,GAAG,mBAAW,uBAAuB,CAAC;AAExF,gDAAgD;AACnC,QAAA,8BAA8B,GAAG,GAAG,wBAAgB,uBAAuB,CAAC;AAEzF,8BAA8B;AACjB,QAAA,0CAA0C,GAAG,GAAG,wBAAgB,oCAAoC,CAAC;AAElH;;;;;;;;GAQG;AACI,KAAK,UAAU,+BAA+B,CACnD,WAAmB,EACnB,SAAmB;IAEnB,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EA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IAE7D,OAAO,wBAAwB,IAAI,EAAE,CAAC;AACxC,CAAC;AA7CD,kDA6CC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,uBAAuB,CAC3C,WAAmB,EACnB,eAAyB;IAEzB,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,kDAA0C,EAC1C,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;AAxBD,0DAwBC","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 const TRIGGER_API = 'https://trigger.api.cx.metamask.io';\nexport const NOTIFICATION_API = 'https://notification.api.cx.metamask.io';\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = `${TRIGGER_API}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = `${TRIGGER_API}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = `${NOTIFICATION_API}/api/v3/notifications`;\n\n// Makrs notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${NOTIFICATION_API}/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 * 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) {\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,\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 * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\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,\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 * @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): 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,\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 * @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): 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,\n 'POST',\n body,\n );\n } catch (err) {\n log.error('Error marking notifications as read:', err);\n }\n}\n"]}
|
|
@@ -5,24 +5,22 @@ export type NotificationTrigger = {
|
|
|
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
|
|
14
|
-
export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT: (env?: ENV) => string;
|
|
8
|
+
export declare const TRIGGER_API = "https://trigger.api.cx.metamask.io";
|
|
9
|
+
export declare const NOTIFICATION_API = "https://notification.api.cx.metamask.io";
|
|
10
|
+
export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications/query";
|
|
11
|
+
export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications";
|
|
12
|
+
export declare const NOTIFICATION_API_LIST_ENDPOINT = "https://notification.api.cx.metamask.io/api/v3/notifications";
|
|
13
|
+
export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = "https://notification.api.cx.metamask.io/api/v3/notifications/mark-as-read";
|
|
15
14
|
/**
|
|
16
15
|
* fetches notification config (accounts enabled vs disabled)
|
|
17
16
|
*
|
|
18
17
|
* @param bearerToken - jwt
|
|
19
18
|
* @param addresses - list of addresses to check
|
|
20
|
-
* @param env - the environment to use for the API call
|
|
21
19
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
22
20
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
23
21
|
* @returns object of notification config, or null if missing
|
|
24
22
|
*/
|
|
25
|
-
export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[]
|
|
23
|
+
export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[]): Promise<{
|
|
26
24
|
address: string;
|
|
27
25
|
enabled: boolean;
|
|
28
26
|
}[]>;
|
|
@@ -31,13 +29,12 @@ export declare function getNotificationsApiConfigCached(bearerToken: string, add
|
|
|
31
29
|
*
|
|
32
30
|
* @param bearerToken - jwt
|
|
33
31
|
* @param addresses - list of addresses to check
|
|
34
|
-
* @param env - the environment to use for the API call
|
|
35
32
|
* @returns void
|
|
36
33
|
*/
|
|
37
34
|
export declare function updateOnChainNotifications(bearerToken: string, addresses: {
|
|
38
35
|
address: string;
|
|
39
36
|
enabled: boolean;
|
|
40
|
-
}[]
|
|
37
|
+
}[]): Promise<void>;
|
|
41
38
|
/**
|
|
42
39
|
* Fetches on-chain notifications for the given addresses
|
|
43
40
|
*
|
|
@@ -45,10 +42,9 @@ export declare function updateOnChainNotifications(bearerToken: string, addresse
|
|
|
45
42
|
* @param addresses - List of addresses
|
|
46
43
|
* @param locale - to generate translated notifications
|
|
47
44
|
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
48
|
-
* @param env - the environment to use for the API call
|
|
49
45
|
* @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.
|
|
50
46
|
*/
|
|
51
|
-
export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile'
|
|
47
|
+
export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile'): Promise<NormalisedAPINotification[]>;
|
|
52
48
|
/**
|
|
53
49
|
* Marks the specified notifications as read.
|
|
54
50
|
* This method sends a POST request to the notifications service to mark the provided notification IDs as read.
|
|
@@ -56,8 +52,7 @@ export declare function getAPINotifications(bearerToken: string, addresses: stri
|
|
|
56
52
|
*
|
|
57
53
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
58
54
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
59
|
-
* @param env - the environment to use for the API call
|
|
60
55
|
* @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.
|
|
61
56
|
*/
|
|
62
|
-
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]
|
|
57
|
+
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]): Promise<void>;
|
|
63
58
|
//# sourceMappingURL=api-notifications.d.cts.map
|
|
@@ -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,
|
|
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,eAAO,MAAM,WAAW,uCAAuC,CAAC;AAChE,eAAO,MAAM,gBAAgB,4CAA4C,CAAC;AAG1E,eAAO,MAAM,wCAAwC,kEAA8C,CAAC;AAGpG,eAAO,MAAM,kCAAkC,4DAAwC,CAAC;AAGxF,eAAO,MAAM,8BAA8B,iEAA6C,CAAC;AAGzF,eAAO,MAAM,0CAA0C,8EAA0D,CAAC;AAElH;;;;;;;;GAQG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE;;;KAgCpB;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,iBAqBnD;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAC/B,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAwCtC;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,IAAI,CAAC,CAqBf"}
|
|
@@ -5,24 +5,22 @@ export type NotificationTrigger = {
|
|
|
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
|
|
14
|
-
export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT: (env?: ENV) => string;
|
|
8
|
+
export declare const TRIGGER_API = "https://trigger.api.cx.metamask.io";
|
|
9
|
+
export declare const NOTIFICATION_API = "https://notification.api.cx.metamask.io";
|
|
10
|
+
export declare const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications/query";
|
|
11
|
+
export declare const TRIGGER_API_NOTIFICATIONS_ENDPOINT = "https://trigger.api.cx.metamask.io/api/v2/notifications";
|
|
12
|
+
export declare const NOTIFICATION_API_LIST_ENDPOINT = "https://notification.api.cx.metamask.io/api/v3/notifications";
|
|
13
|
+
export declare const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = "https://notification.api.cx.metamask.io/api/v3/notifications/mark-as-read";
|
|
15
14
|
/**
|
|
16
15
|
* fetches notification config (accounts enabled vs disabled)
|
|
17
16
|
*
|
|
18
17
|
* @param bearerToken - jwt
|
|
19
18
|
* @param addresses - list of addresses to check
|
|
20
|
-
* @param env - the environment to use for the API call
|
|
21
19
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
22
20
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
23
21
|
* @returns object of notification config, or null if missing
|
|
24
22
|
*/
|
|
25
|
-
export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[]
|
|
23
|
+
export declare function getNotificationsApiConfigCached(bearerToken: string, addresses: string[]): Promise<{
|
|
26
24
|
address: string;
|
|
27
25
|
enabled: boolean;
|
|
28
26
|
}[]>;
|
|
@@ -31,13 +29,12 @@ export declare function getNotificationsApiConfigCached(bearerToken: string, add
|
|
|
31
29
|
*
|
|
32
30
|
* @param bearerToken - jwt
|
|
33
31
|
* @param addresses - list of addresses to check
|
|
34
|
-
* @param env - the environment to use for the API call
|
|
35
32
|
* @returns void
|
|
36
33
|
*/
|
|
37
34
|
export declare function updateOnChainNotifications(bearerToken: string, addresses: {
|
|
38
35
|
address: string;
|
|
39
36
|
enabled: boolean;
|
|
40
|
-
}[]
|
|
37
|
+
}[]): Promise<void>;
|
|
41
38
|
/**
|
|
42
39
|
* Fetches on-chain notifications for the given addresses
|
|
43
40
|
*
|
|
@@ -45,10 +42,9 @@ export declare function updateOnChainNotifications(bearerToken: string, addresse
|
|
|
45
42
|
* @param addresses - List of addresses
|
|
46
43
|
* @param locale - to generate translated notifications
|
|
47
44
|
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
48
|
-
* @param env - the environment to use for the API call
|
|
49
45
|
* @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.
|
|
50
46
|
*/
|
|
51
|
-
export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile'
|
|
47
|
+
export declare function getAPINotifications(bearerToken: string, addresses: string[], locale: string, platform: 'extension' | 'mobile'): Promise<NormalisedAPINotification[]>;
|
|
52
48
|
/**
|
|
53
49
|
* Marks the specified notifications as read.
|
|
54
50
|
* This method sends a POST request to the notifications service to mark the provided notification IDs as read.
|
|
@@ -56,8 +52,7 @@ export declare function getAPINotifications(bearerToken: string, addresses: stri
|
|
|
56
52
|
*
|
|
57
53
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
58
54
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
59
|
-
* @param env - the environment to use for the API call
|
|
60
55
|
* @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.
|
|
61
56
|
*/
|
|
62
|
-
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]
|
|
57
|
+
export declare function markNotificationsAsRead(bearerToken: string, notificationIds: string[]): Promise<void>;
|
|
63
58
|
//# sourceMappingURL=api-notifications.d.mts.map
|
|
@@ -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,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,
|
|
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,eAAO,MAAM,WAAW,uCAAuC,CAAC;AAChE,eAAO,MAAM,gBAAgB,4CAA4C,CAAC;AAG1E,eAAO,MAAM,wCAAwC,kEAA8C,CAAC;AAGpG,eAAO,MAAM,kCAAkC,4DAAwC,CAAC;AAGxF,eAAO,MAAM,8BAA8B,iEAA6C,CAAC;AAGzF,eAAO,MAAM,0CAA0C,8EAA0D,CAAC;AAElH;;;;;;;;GAQG;AACH,wBAAsB,+BAA+B,CACnD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE;;;KAgCpB;AAED;;;;;;GAMG;AACH,wBAAsB,0BAA0B,CAC9C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,EAAE,iBAqBnD;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,GAC/B,OAAO,CAAC,yBAAyB,EAAE,CAAC,CAwCtC;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,IAAI,CAAC,CAqBf"}
|
|
@@ -9,37 +9,26 @@ const log = $importDefault($log);
|
|
|
9
9
|
import { notificationsConfigCache } from "./notification-config-cache.mjs";
|
|
10
10
|
import { toRawAPINotification } from "../../shared/to-raw-notification.mjs";
|
|
11
11
|
import { makeApiCall } from "../utils/utils.mjs";
|
|
12
|
-
const
|
|
13
|
-
|
|
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;
|
|
12
|
+
export const TRIGGER_API = 'https://trigger.api.cx.metamask.io';
|
|
13
|
+
export const NOTIFICATION_API = 'https://notification.api.cx.metamask.io';
|
|
24
14
|
// Gets notification settings for each account provided
|
|
25
|
-
export const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT =
|
|
15
|
+
export const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = `${TRIGGER_API}/api/v2/notifications/query`;
|
|
26
16
|
// Used to create/update account notifications for each account provided
|
|
27
|
-
export const TRIGGER_API_NOTIFICATIONS_ENDPOINT =
|
|
17
|
+
export const TRIGGER_API_NOTIFICATIONS_ENDPOINT = `${TRIGGER_API}/api/v2/notifications`;
|
|
28
18
|
// Lists notifications for each account provided
|
|
29
|
-
export const NOTIFICATION_API_LIST_ENDPOINT =
|
|
19
|
+
export const NOTIFICATION_API_LIST_ENDPOINT = `${NOTIFICATION_API}/api/v3/notifications`;
|
|
30
20
|
// Makrs notifications as read
|
|
31
|
-
export const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT =
|
|
21
|
+
export const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${NOTIFICATION_API}/api/v3/notifications/mark-as-read`;
|
|
32
22
|
/**
|
|
33
23
|
* fetches notification config (accounts enabled vs disabled)
|
|
34
24
|
*
|
|
35
25
|
* @param bearerToken - jwt
|
|
36
26
|
* @param addresses - list of addresses to check
|
|
37
|
-
* @param env - the environment to use for the API call
|
|
38
27
|
* NOTE the API will return addresses config with false if they have not been created before.
|
|
39
28
|
* NOTE this is cached for 1s to prevent multiple update calls
|
|
40
29
|
* @returns object of notification config, or null if missing
|
|
41
30
|
*/
|
|
42
|
-
export async function getNotificationsApiConfigCached(bearerToken, addresses
|
|
31
|
+
export async function getNotificationsApiConfigCached(bearerToken, addresses) {
|
|
43
32
|
if (addresses.length === 0) {
|
|
44
33
|
return [];
|
|
45
34
|
}
|
|
@@ -49,7 +38,7 @@ export async function getNotificationsApiConfigCached(bearerToken, addresses, en
|
|
|
49
38
|
return cached;
|
|
50
39
|
}
|
|
51
40
|
const body = addresses.map((address) => ({ address }));
|
|
52
|
-
const data = await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT
|
|
41
|
+
const data = await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT, 'POST', body)
|
|
53
42
|
.then((r) => (r.ok ? r.json() : null))
|
|
54
43
|
.catch(() => null);
|
|
55
44
|
const result = data ?? [];
|
|
@@ -63,10 +52,9 @@ export async function getNotificationsApiConfigCached(bearerToken, addresses, en
|
|
|
63
52
|
*
|
|
64
53
|
* @param bearerToken - jwt
|
|
65
54
|
* @param addresses - list of addresses to check
|
|
66
|
-
* @param env - the environment to use for the API call
|
|
67
55
|
* @returns void
|
|
68
56
|
*/
|
|
69
|
-
export async function updateOnChainNotifications(bearerToken, addresses
|
|
57
|
+
export async function updateOnChainNotifications(bearerToken, addresses) {
|
|
70
58
|
if (addresses.length === 0) {
|
|
71
59
|
return;
|
|
72
60
|
}
|
|
@@ -75,7 +63,7 @@ export async function updateOnChainNotifications(bearerToken, addresses, env = '
|
|
|
75
63
|
return a;
|
|
76
64
|
});
|
|
77
65
|
const body = addresses;
|
|
78
|
-
await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_ENDPOINT
|
|
66
|
+
await makeApiCall(bearerToken, TRIGGER_API_NOTIFICATIONS_ENDPOINT, 'POST', body)
|
|
79
67
|
.then(() => notificationsConfigCache.set(addresses))
|
|
80
68
|
.catch(() => null);
|
|
81
69
|
}
|
|
@@ -86,10 +74,9 @@ export async function updateOnChainNotifications(bearerToken, addresses, env = '
|
|
|
86
74
|
* @param addresses - List of addresses
|
|
87
75
|
* @param locale - to generate translated notifications
|
|
88
76
|
* @param platform - filter notifications for specific platforms ('extension' | 'mobile')
|
|
89
|
-
* @param env - the environment to use for the API call
|
|
90
77
|
* @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.
|
|
91
78
|
*/
|
|
92
|
-
export async function getAPINotifications(bearerToken, addresses, locale, platform
|
|
79
|
+
export async function getAPINotifications(bearerToken, addresses, locale, platform) {
|
|
93
80
|
if (addresses.length === 0) {
|
|
94
81
|
return [];
|
|
95
82
|
}
|
|
@@ -98,7 +85,7 @@ export async function getAPINotifications(bearerToken, addresses, locale, platfo
|
|
|
98
85
|
locale,
|
|
99
86
|
platform,
|
|
100
87
|
};
|
|
101
|
-
const notifications = await makeApiCall(bearerToken, NOTIFICATION_API_LIST_ENDPOINT
|
|
88
|
+
const notifications = await makeApiCall(bearerToken, NOTIFICATION_API_LIST_ENDPOINT, 'POST', body)
|
|
102
89
|
.then((r) => (r.ok ? r.json() : null))
|
|
103
90
|
.catch(() => null);
|
|
104
91
|
// Transform and sort notifications
|
|
@@ -124,10 +111,9 @@ export async function getAPINotifications(bearerToken, addresses, locale, platfo
|
|
|
124
111
|
*
|
|
125
112
|
* @param bearerToken - The JSON Web Token used for authentication in the API call.
|
|
126
113
|
* @param notificationIds - An array of notification IDs to be marked as read.
|
|
127
|
-
* @param env - the environment to use for the API call
|
|
128
114
|
* @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.
|
|
129
115
|
*/
|
|
130
|
-
export async function markNotificationsAsRead(bearerToken, notificationIds
|
|
116
|
+
export async function markNotificationsAsRead(bearerToken, notificationIds) {
|
|
131
117
|
if (notificationIds.length === 0) {
|
|
132
118
|
return;
|
|
133
119
|
}
|
|
@@ -135,7 +121,7 @@ export async function markNotificationsAsRead(bearerToken, notificationIds, env
|
|
|
135
121
|
ids: notificationIds,
|
|
136
122
|
};
|
|
137
123
|
try {
|
|
138
|
-
await makeApiCall(bearerToken, NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT
|
|
124
|
+
await makeApiCall(bearerToken, NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT, 'POST', body);
|
|
139
125
|
}
|
|
140
126
|
catch (err) {
|
|
141
127
|
log.error('Error marking notifications as read:', err);
|
|
@@ -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,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,E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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"]}
|
|
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;AAS7C,MAAM,CAAC,MAAM,WAAW,GAAG,oCAAoC,CAAC;AAChE,MAAM,CAAC,MAAM,gBAAgB,G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,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SACzD,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;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;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,WAAmB,EACnB,eAAyB;IAEzB,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,EAC1C,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 const TRIGGER_API = 'https://trigger.api.cx.metamask.io';\nexport const NOTIFICATION_API = 'https://notification.api.cx.metamask.io';\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = `${TRIGGER_API}/api/v2/notifications/query`;\n\n// Used to create/update account notifications for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = `${TRIGGER_API}/api/v2/notifications`;\n\n// Lists notifications for each account provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = `${NOTIFICATION_API}/api/v3/notifications`;\n\n// Makrs notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = `${NOTIFICATION_API}/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 * 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) {\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,\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 * @returns void\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\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,\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 * @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): 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,\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 * @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): 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,\n 'POST',\n body,\n );\n } catch (err) {\n log.error('Error marking notifications as read:', err);\n }\n}\n"]}
|
|
@@ -127,7 +127,6 @@ class NotificationServicesPushController extends base_controller_1.BaseControlle
|
|
|
127
127
|
locale: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").getLocale?.() ?? 'en',
|
|
128
128
|
oldToken: this.state.fcmToken,
|
|
129
129
|
},
|
|
130
|
-
controllerEnv: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").env ?? 'prd',
|
|
131
130
|
});
|
|
132
131
|
if (fcmToken) {
|
|
133
132
|
__classPrivateFieldGet(this, _NotificationServicesPushController_instances, "m", _NotificationServicesPushController_updatePushState).call(this, { type: 'enable', fcmToken });
|
|
@@ -209,7 +208,6 @@ class NotificationServicesPushController extends base_controller_1.BaseControlle
|
|
|
209
208
|
locale: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").getLocale?.() ?? 'en',
|
|
210
209
|
oldToken: this.state.fcmToken,
|
|
211
210
|
},
|
|
212
|
-
controllerEnv: __classPrivateFieldGet(this, _NotificationServicesPushController_config, "f").env ?? 'prd',
|
|
213
211
|
});
|
|
214
212
|
// update the state with the new FCM token
|
|
215
213
|
if (fcmToken) {
|