@metamask-previews/notification-services-controller 29.0.2-preview-122ecfd → 29.0.2-preview-247ba396c
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 +7 -0
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.ts +16 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.d.ts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController-method-action-types.js.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.d.ts +24 -2
- package/dist/NotificationServicesController/NotificationServicesController.d.ts.map +1 -1
- package/dist/NotificationServicesController/NotificationServicesController.js +58 -1
- package/dist/NotificationServicesController/NotificationServicesController.js.map +1 -1
- package/dist/NotificationServicesController/index.d.ts +1 -1
- package/dist/NotificationServicesController/index.d.ts.map +1 -1
- package/dist/NotificationServicesController/index.js.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.d.ts +1 -0
- package/dist/NotificationServicesController/mocks/mockResponses.d.ts.map +1 -1
- package/dist/NotificationServicesController/mocks/mockResponses.js +21 -1
- package/dist/NotificationServicesController/mocks/mockResponses.js.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.d.ts +11 -1
- package/dist/NotificationServicesController/services/api-notifications.d.ts.map +1 -1
- package/dist/NotificationServicesController/services/api-notifications.js +40 -4
- package/dist/NotificationServicesController/services/api-notifications.js.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.d.ts.map +1 -1
- package/dist/NotificationServicesController/services/feature-announcements.js.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.ts +1 -0
- package/dist/NotificationServicesController/types/notification-api/notification-api.d.ts.map +1 -1
- package/dist/NotificationServicesController/types/notification-api/notification-api.js.map +1 -1
- package/dist/NotificationServicesController/utils/utils.d.ts +14 -5
- package/dist/NotificationServicesController/utils/utils.d.ts.map +1 -1
- package/dist/NotificationServicesController/utils/utils.js +17 -14
- package/dist/NotificationServicesController/utils/utils.js.map +1 -1
- package/package.json +2 -2
|
@@ -22,6 +22,7 @@ export const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env = 'prd') => `${TRIGGER_AP
|
|
|
22
22
|
export const NOTIFICATION_API_LIST_ENDPOINT = (env = 'prd') => `${NOTIFICATION_API(env)}/api/v4/notifications`;
|
|
23
23
|
// Marks notifications as read
|
|
24
24
|
export const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (env = 'prd') => `${NOTIFICATION_API(env)}/api/v4/notifications/mark-as-read`;
|
|
25
|
+
export const NOTIFICATION_API_CATEGORIES_LIST_ENDPOINT = (env = 'prd') => `${NOTIFICATION_API(env)}/api/v4/notifications/categories`;
|
|
25
26
|
/**
|
|
26
27
|
* fetches notification config (accounts enabled vs disabled)
|
|
27
28
|
*
|
|
@@ -45,7 +46,11 @@ export async function getNotificationsApiConfigCached(bearerToken, addresses, en
|
|
|
45
46
|
return cached;
|
|
46
47
|
}
|
|
47
48
|
const body = normalizedAddresses.map((address) => ({ address }));
|
|
48
|
-
const result = await makeApiCall(
|
|
49
|
+
const result = await makeApiCall(TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env), {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
body,
|
|
52
|
+
bearerToken,
|
|
53
|
+
})
|
|
49
54
|
.then((response) => (response.ok ? response.json() : null))
|
|
50
55
|
.catch(() => null);
|
|
51
56
|
if (result === null) {
|
|
@@ -78,7 +83,11 @@ export async function updateOnChainNotifications(bearerToken, addresses, env = '
|
|
|
78
83
|
address: item.address.toLowerCase(),
|
|
79
84
|
}));
|
|
80
85
|
const body = normalizedAddresses;
|
|
81
|
-
const response = await makeApiCall(
|
|
86
|
+
const response = await makeApiCall(TRIGGER_API_NOTIFICATIONS_ENDPOINT(env), {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
body,
|
|
89
|
+
bearerToken,
|
|
90
|
+
});
|
|
82
91
|
if (!response.ok) {
|
|
83
92
|
throw new Error(`Failed to update on-chain notifications: ${response.status}`);
|
|
84
93
|
}
|
|
@@ -105,7 +114,11 @@ export async function getAPINotifications(bearerToken, addresses, locale, platfo
|
|
|
105
114
|
locale,
|
|
106
115
|
platform,
|
|
107
116
|
};
|
|
108
|
-
const notifications = await makeApiCall(
|
|
117
|
+
const notifications = await makeApiCall(NOTIFICATION_API_LIST_ENDPOINT(env), {
|
|
118
|
+
method: 'POST',
|
|
119
|
+
body,
|
|
120
|
+
bearerToken,
|
|
121
|
+
})
|
|
109
122
|
.then((response) => response.ok ? response.json() : null)
|
|
110
123
|
.catch(() => null);
|
|
111
124
|
// Transform and sort notifications
|
|
@@ -142,10 +155,33 @@ export async function markNotificationsAsRead(bearerToken, notificationIds, env
|
|
|
142
155
|
ids: notificationIds,
|
|
143
156
|
};
|
|
144
157
|
try {
|
|
145
|
-
await makeApiCall(
|
|
158
|
+
await makeApiCall(NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env), {
|
|
159
|
+
method: 'POST',
|
|
160
|
+
body,
|
|
161
|
+
bearerToken,
|
|
162
|
+
});
|
|
146
163
|
}
|
|
147
164
|
catch (error) {
|
|
148
165
|
log.error('Error marking notifications as read:', error);
|
|
149
166
|
}
|
|
150
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Fetches the notification categories manifest (server-driven settings taxonomy).
|
|
170
|
+
*
|
|
171
|
+
* This endpoint is unauthenticated and returns the same manifest for every user.
|
|
172
|
+
*
|
|
173
|
+
* @param env - the environment to use for the API call
|
|
174
|
+
* @returns The list of notification categories, or an empty array on transport or parse errors.
|
|
175
|
+
*/
|
|
176
|
+
export async function getNotificationsCategories(env = 'prd') {
|
|
177
|
+
const categories = await makeApiCall(NOTIFICATION_API_CATEGORIES_LIST_ENDPOINT(env), {
|
|
178
|
+
method: 'GET',
|
|
179
|
+
})
|
|
180
|
+
.then((response) => response.ok ? response.json() : null)
|
|
181
|
+
.catch((error) => {
|
|
182
|
+
log.error('Error fetching notifications categories', error);
|
|
183
|
+
return null;
|
|
184
|
+
});
|
|
185
|
+
return categories ?? [];
|
|
186
|
+
}
|
|
151
187
|
//# sourceMappingURL=api-notifications.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-notifications.js","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAM3E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAI1E,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEhC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,GAAQ,KAAK,EAAU,EAAE,CACtD,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,yCAAyC;CAC/C,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAG,GAAQ,KAAK,EAAU,EAAE,CAC3D,oBAAoB,CAAC,GAAG,CAAC,IAAI,oBAAoB,CAAC,GAAG,CAAC;AAExD,uDAAuD;AACvD,MAAM,CAAC,MAAM,wCAAwC,GAAG,CACtD,GAAG,GAAQ,KAAK,EACR,EAAE,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAE9D,+EAA+E;AAC/E,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAAC,GAAG,GAAQ,KAAK,EAAU,EAAE,CAC7E,GAAG,WAAW,CAAC,GAAG,CAAC,uBAAuB,CAAC;AAE7C,gDAAgD;AAChD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KAAK,EAAE,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;AACH,CAAC","sourcesContent":["import log from 'loglevel';\n\nimport { toRawAPINotification } from '../../shared/to-raw-notification.js';\nimport type {\n NormalisedAPINotification,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api/index.js';\nimport { makeApiCall } from '../utils/utils.js';\nimport { notificationsConfigCache } from './notification-config-cache.js';\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd'): string =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd'): string =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Creates/updates account notification subscriptions for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each address provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd'): string =>\n `${NOTIFICATION_API(env)}/api/v4/notifications`;\n\n// Marks notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${NOTIFICATION_API(env)}/api/v4/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 the config for each requested address, or `null` if the config could\n * not be read. An empty array means the API answered and no address is\n * subscribed; callers must not read a failure as \"nothing is enabled\", since\n * acting on that would re-subscribe or unregister addresses behind the user.\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n): Promise<{ address: string; enabled: boolean }[] | null> {\n if (addresses.length === 0) {\n return [];\n }\n\n const normalizedAddresses = addresses.map((addr) => addr.toLowerCase());\n\n const cached = notificationsConfigCache.get(normalizedAddresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses.map((address) => ({ address }));\n const result = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<Response | null>((response) => (response.ok ? response.json() : null))\n .catch(() => null);\n\n if (result === null) {\n return null;\n }\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * Creates or removes wallet-activity subscriptions for the given addresses.\n *\n * The endpoint is a per-address upsert-or-delete batch rather than a full\n * replace, so two installations authenticating as the same profile do not\n * clobber each other's subscriptions.\n *\n * @param bearerToken - jwt\n * @param addresses - addresses to subscribe (`enabled: true`) or unsubscribe (`enabled: false`)\n * @param env - the environment to use for the API call\n * @throws if the request could not be made or the API rejected it, so callers\n * do not report a subscription change the server never applied.\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n): Promise<void> {\n if (addresses.length === 0) {\n return;\n }\n\n const normalizedAddresses = addresses.map((item) => ({\n ...item,\n address: item.address.toLowerCase(),\n }));\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses;\n const response = await makeApiCall(\n bearerToken,\n TRIGGER_API_NOTIFICATIONS_ENDPOINT(env),\n 'POST',\n body,\n );\n\n if (!response.ok) {\n throw new Error(\n `Failed to update on-chain notifications: ${response.status}`,\n );\n }\n\n // Seeded only once the server has accepted the change: the settings UI reads\n // this back for the whole TTL, so a rejected write must not look applied.\n notificationsConfigCache.set(normalizedAddresses);\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 An array of {@link NormalisedAPINotification}. Returns an empty array on transport or parse errors.\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/v4/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v4/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((addr) => addr.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(\n bearerToken,\n NOTIFICATION_API_LIST_ENDPOINT(env),\n 'POST',\n body,\n )\n .then<APIResponse | null>((response) =>\n response.ok ? response.json() : null,\n )\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((notification): UnprocessedRawNotification | undefined => {\n if (!notification.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(notification);\n } catch {\n return undefined;\n }\n })\n .filter((item): item is NormalisedAPINotification => Boolean(item));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v4/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(\n bearerToken,\n NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env),\n 'POST',\n body,\n );\n } catch (error) {\n log.error('Error marking notifications as read:', error);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"api-notifications.js","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/api-notifications.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAO3E,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAI1E,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,wCAAwC;IAC7C,GAAG,EAAE,oCAAoC;CACZ,CAAC;AAEhC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAG,GAAQ,KAAK,EAAU,EAAE,CACtD,eAAe,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC;AAE9C,MAAM,oBAAoB,GAAG;IAC3B,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,6CAA6C;IAClD,GAAG,EAAE,yCAAyC;CAC/C,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,GAAG,GAAQ,KAAK,EAAU,EAAE,CAC3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AC","sourcesContent":["import log from 'loglevel';\n\nimport { toRawAPINotification } from '../../shared/to-raw-notification.js';\nimport type {\n NormalisedAPINotification,\n NotificationsCategory,\n Schema,\n UnprocessedRawNotification,\n} from '../types/notification-api/index.js';\nimport { makeApiCall } from '../utils/utils.js';\nimport { notificationsConfigCache } from './notification-config-cache.js';\n\nexport type ENV = 'prd' | 'uat' | 'dev';\n\nconst TRIGGER_API_ENV = {\n dev: 'https://trigger.dev-api.cx.metamask.io',\n uat: 'https://trigger.uat-api.cx.metamask.io',\n prd: 'https://trigger.api.cx.metamask.io',\n} satisfies Record<ENV, string>;\n\nexport const TRIGGER_API = (env: ENV = 'prd'): string =>\n TRIGGER_API_ENV[env] ?? TRIGGER_API_ENV.prd;\n\nconst NOTIFICATION_API_ENV = {\n dev: 'https://notification.dev-api.cx.metamask.io',\n uat: 'https://notification.uat-api.cx.metamask.io',\n prd: 'https://notification.api.cx.metamask.io',\n};\n\nexport const NOTIFICATION_API = (env: ENV = 'prd'): string =>\n NOTIFICATION_API_ENV[env] ?? NOTIFICATION_API_ENV.prd;\n\n// Gets notification settings for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${TRIGGER_API(env)}/api/v2/notifications/query`;\n\n// Creates/updates account notification subscriptions for each account provided\nexport const TRIGGER_API_NOTIFICATIONS_ENDPOINT = (env: ENV = 'prd'): string =>\n `${TRIGGER_API(env)}/api/v2/notifications`;\n\n// Lists notifications for each address provided\nexport const NOTIFICATION_API_LIST_ENDPOINT = (env: ENV = 'prd'): string =>\n `${NOTIFICATION_API(env)}/api/v4/notifications`;\n\n// Marks notifications as read\nexport const NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${NOTIFICATION_API(env)}/api/v4/notifications/mark-as-read`;\n\nexport const NOTIFICATION_API_CATEGORIES_LIST_ENDPOINT = (\n env: ENV = 'prd',\n): string => `${NOTIFICATION_API(env)}/api/v4/notifications/categories`;\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 the config for each requested address, or `null` if the config could\n * not be read. An empty array means the API answered and no address is\n * subscribed; callers must not read a failure as \"nothing is enabled\", since\n * acting on that would re-subscribe or unregister addresses behind the user.\n */\nexport async function getNotificationsApiConfigCached(\n bearerToken: string,\n addresses: string[],\n env: ENV = 'prd',\n): Promise<{ address: string; enabled: boolean }[] | null> {\n if (addresses.length === 0) {\n return [];\n }\n\n const normalizedAddresses = addresses.map((addr) => addr.toLowerCase());\n\n const cached = notificationsConfigCache.get(normalizedAddresses);\n if (cached) {\n return cached;\n }\n\n type RequestBody = { address: string }[];\n type Response = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses.map((address) => ({ address }));\n const result = await makeApiCall(\n TRIGGER_API_NOTIFICATIONS_QUERY_ENDPOINT(env),\n {\n method: 'POST',\n body,\n bearerToken,\n },\n )\n .then<Response | null>((response) => (response.ok ? response.json() : null))\n .catch(() => null);\n\n if (result === null) {\n return null;\n }\n\n if (result.length > 0) {\n notificationsConfigCache.set(result);\n }\n\n return result;\n}\n\n/**\n * Creates or removes wallet-activity subscriptions for the given addresses.\n *\n * The endpoint is a per-address upsert-or-delete batch rather than a full\n * replace, so two installations authenticating as the same profile do not\n * clobber each other's subscriptions.\n *\n * @param bearerToken - jwt\n * @param addresses - addresses to subscribe (`enabled: true`) or unsubscribe (`enabled: false`)\n * @param env - the environment to use for the API call\n * @throws if the request could not be made or the API rejected it, so callers\n * do not report a subscription change the server never applied.\n */\nexport async function updateOnChainNotifications(\n bearerToken: string,\n addresses: { address: string; enabled: boolean }[],\n env: ENV = 'prd',\n): Promise<void> {\n if (addresses.length === 0) {\n return;\n }\n\n const normalizedAddresses = addresses.map((item) => ({\n ...item,\n address: item.address.toLowerCase(),\n }));\n\n type RequestBody = { address: string; enabled: boolean }[];\n const body: RequestBody = normalizedAddresses;\n const response = await makeApiCall(TRIGGER_API_NOTIFICATIONS_ENDPOINT(env), {\n method: 'POST',\n body,\n bearerToken,\n });\n\n if (!response.ok) {\n throw new Error(\n `Failed to update on-chain notifications: ${response.status}`,\n );\n }\n\n // Seeded only once the server has accepted the change: the settings UI reads\n // this back for the whole TTL, so a rejected write must not look applied.\n notificationsConfigCache.set(normalizedAddresses);\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 An array of {@link NormalisedAPINotification}. Returns an empty array on transport or parse errors.\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/v4/notifications']['post']['requestBody']['content']['application/json'];\n type APIResponse =\n Schema.paths['/api/v4/notifications']['post']['responses']['200']['content']['application/json'];\n\n const body: RequestBody = {\n addresses: addresses.map((addr) => addr.toLowerCase()),\n locale,\n platform,\n };\n const notifications = await makeApiCall(NOTIFICATION_API_LIST_ENDPOINT(env), {\n method: 'POST',\n body,\n bearerToken,\n })\n .then<APIResponse | null>((response) =>\n response.ok ? response.json() : null,\n )\n .catch(() => null);\n\n // Transform and sort notifications\n const transformedNotifications = notifications\n ?.map((notification): UnprocessedRawNotification | undefined => {\n if (!notification.notification_type) {\n return undefined;\n }\n\n try {\n return toRawAPINotification(notification);\n } catch {\n return undefined;\n }\n })\n .filter((item): item is NormalisedAPINotification => Boolean(item));\n\n return transformedNotifications ?? [];\n}\n\n/**\n * Marks the specified notifications as read.\n * This method sends a POST request to the notifications service to mark the provided notification IDs as read.\n * If the operation is successful, it completes without error. If the operation fails, it throws an error with details.\n *\n * @param bearerToken - The JSON Web Token used for authentication in the API call.\n * @param notificationIds - An array of notification IDs to be marked as read.\n * @param env - the environment to use for the API call\n * @returns A promise that resolves to void. The promise will reject if there's an error during the API call or if the response status is not 200.\n */\nexport async function markNotificationsAsRead(\n bearerToken: string,\n notificationIds: string[],\n env: ENV = 'prd',\n): Promise<void> {\n if (notificationIds.length === 0) {\n return;\n }\n\n type ResponseBody =\n Schema.paths['/api/v4/notifications/mark-as-read']['post']['requestBody']['content']['application/json'];\n const body: ResponseBody = {\n ids: notificationIds,\n };\n\n try {\n await makeApiCall(NOTIFICATION_API_MARK_ALL_AS_READ_ENDPOINT(env), {\n method: 'POST',\n body,\n bearerToken,\n });\n } catch (error) {\n log.error('Error marking notifications as read:', error);\n }\n}\n\n/**\n * Fetches the notification categories manifest (server-driven settings taxonomy).\n *\n * This endpoint is unauthenticated and returns the same manifest for every user.\n *\n * @param env - the environment to use for the API call\n * @returns The list of notification categories, or an empty array on transport or parse errors.\n */\nexport async function getNotificationsCategories(\n env: ENV = 'prd',\n): Promise<NotificationsCategory[]> {\n type APIResponse =\n Schema.paths['/api/v4/notifications/categories']['get']['responses']['200']['content']['application/json'];\n\n const categories: APIResponse | null = await makeApiCall(\n NOTIFICATION_API_CATEGORIES_LIST_ENDPOINT(env),\n {\n method: 'GET',\n },\n )\n .then<APIResponse | null>((response) =>\n response.ok ? response.json() : null,\n )\n .catch((error) => {\n log.error('Error fetching notifications categories', error);\n\n return null;\n });\n\n return categories ?? [];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-announcements.d.ts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AAKhE,OAAO,KAAK,EAEV,uBAAuB,EACxB,MAAM,4DAA4D,CAAC;AAOpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAW3E,eAAO,MAAM,wBAAwB,4EAAqF,CAAC;AAC3H,eAAO,MAAM,wBAAwB,iLAAyJ,CAAC;AAE/L,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE;QAGT,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;QAEhB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAC/B,GAAG,iBACO,MAAM,KACpB,MAUF,CAAC;
|
|
1
|
+
{"version":3,"file":"feature-announcements.d.ts","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AAKhE,OAAO,KAAK,EAEV,uBAAuB,EACxB,MAAM,4DAA4D,CAAC;AAOpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAW3E,eAAO,MAAM,wBAAwB,4EAAqF,CAAC;AAC3H,eAAO,MAAM,wBAAwB,iLAAyJ,CAAC;AAE/L,KAAK,GAAG,GAAG;IACT,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,EAAE;QAGT,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;QAEhB,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC;KACjB,CAAC;IACF,KAAK,CAAC,EAAE,uBAAuB,EAAE,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,yBAAyB,QAC/B,GAAG,iBACO,MAAM,KACpB,MAUF,CAAC;AAkJF;;;;;;GAMG;AACH,wBAAsB,mCAAmC,CACvD,GAAG,EAAE,GAAG,EACR,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,aAAa,EAAE,CAAC,CAc1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature-announcements.js","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAa3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,uFAAuF;AACvF,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAE9C,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAC7C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,cAAc,WAAW,gBAAgB,8BAA8B,CAAC;AAC3H,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,wBAAwB,iBAAiB,oBAAoB,mEAAmE,iBAAiB,EAAE,CAAC;AAuB/L,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,GAAQ,EACR,YAAqB,EACb,EAAE;IACV,MAAM,MAAM,GAAG,YAAY,CAAC,CAAC,C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@contentful/rich-text-html-renderer';\nimport type { Entry, Asset, EntryCollection } from 'contentful';\n\nimport { TRIGGER_TYPES } from '../constants/notification-schema.js';\nimport { processFeatureAnnouncement } from '../processors/process-feature-announcement.js';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement.js';\nimport type {\n ImageFields,\n TypeFeatureAnnouncement,\n} from '../types/feature-announcement/type-feature-announcement.js';\nimport type {\n TypeExternalLinkFields,\n TypePortfolioLinkFields,\n TypeExtensionLinkFields,\n TypeMobileLinkFields,\n} from '../types/feature-announcement/type-links.js';\nimport type { INotification } from '../types/notification/notification.js';\nimport { isVersionInBounds } from '../utils/isVersionInBounds.js';\n\n// Feature announcements older than this (by sys.updatedAt) are excluded from the feed.\nconst FEATURE_ANNOUNCEMENT_MAX_AGE_MONTHS = 3;\n\nconst DEFAULT_SPACE_ID = ':space_id';\nconst DEFAULT_ACCESS_TOKEN = ':access_token';\nconst DEFAULT_CLIENT_ID = ':client_id';\nconst DEFAULT_DOMAIN = 'cdn.contentful.com';\nconst PREVIEW_DOMAIN = 'preview.contentful.com';\nexport const FEATURE_ANNOUNCEMENT_API = `https://${DEFAULT_DOMAIN}/spaces/${DEFAULT_SPACE_ID}/environments/master/entries`;\nexport const FEATURE_ANNOUNCEMENT_URL = `${FEATURE_ANNOUNCEMENT_API}?access_token=${DEFAULT_ACCESS_TOKEN}&content_type=productAnnouncement&include=10&fields.clients[in]=${DEFAULT_CLIENT_ID}`;\n\ntype Env = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n platformVersion?: string;\n};\n\n/**\n * Contentful API Response Shape\n */\nexport type ContentfulResult = {\n includes?: {\n // Property names match Contentful API response structure\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Entry?: Entry[];\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Asset?: Asset[];\n };\n items?: TypeFeatureAnnouncement[];\n};\n\nexport const getFeatureAnnouncementUrl = (\n env: Env,\n previewToken?: string,\n): string => {\n const domain = previewToken ? PREVIEW_DOMAIN : DEFAULT_DOMAIN;\n const replacedUrl = FEATURE_ANNOUNCEMENT_URL.replace(\n DEFAULT_SPACE_ID,\n env.spaceId,\n )\n .replace(DEFAULT_ACCESS_TOKEN, previewToken ?? env.accessToken)\n .replace(DEFAULT_CLIENT_ID, env.platform)\n .replace(DEFAULT_DOMAIN, domain);\n return encodeURI(replacedUrl);\n};\n\nconst fetchFeatureAnnouncementNotifications = async (\n env: Env,\n previewToken?: string,\n): Promise<FeatureAnnouncementRawNotification[]> => {\n const url = getFeatureAnnouncementUrl(env, previewToken);\n\n const data = await fetch(url)\n .then((response) => response.json())\n .catch(() => null);\n\n if (!data) {\n return [];\n }\n\n const findIncludedItem = (\n sysId: string,\n ):\n | ImageFields['fields']\n | TypeExtensionLinkFields['fields']\n | TypePortfolioLinkFields['fields']\n | TypeMobileLinkFields['fields']\n | TypeExternalLinkFields['fields']\n | Asset['fields']\n | null => {\n const typedData: EntryCollection<\n | ImageFields\n | TypeExtensionLinkFields\n | TypePortfolioLinkFields\n | TypeMobileLinkFields\n | TypeExternalLinkFields\n > = data;\n const item =\n typedData?.includes?.Entry?.find(\n (entry: Entry) => entry?.sys?.id === sysId,\n ) ??\n typedData?.includes?.Asset?.find(\n (asset: Asset) => asset?.sys?.id === sysId,\n );\n return item ? item?.fields : null;\n };\n\n const contentfulNotifications = data?.items ?? [];\n const rawNotifications: FeatureAnnouncementRawNotification[] =\n contentfulNotifications\n .filter((item: TypeFeatureAnnouncement) => {\n const updatedAt = new Date(item.sys.updatedAt);\n const limitDate = new Date();\n limitDate.setMonth(\n limitDate.getMonth() - FEATURE_ANNOUNCEMENT_MAX_AGE_MONTHS,\n );\n return updatedAt > limitDate;\n })\n .map((item: TypeFeatureAnnouncement) => {\n const { fields } = item;\n const imageFields = fields.image\n ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields'])\n : undefined;\n\n const externalLinkFields = fields.externalLink\n ? (findIncludedItem(\n fields.externalLink.sys.id,\n ) as TypeExternalLinkFields['fields'])\n : undefined;\n const portfolioLinkFields = fields.portfolioLink\n ? (findIncludedItem(\n fields.portfolioLink.sys.id,\n ) as TypePortfolioLinkFields['fields'])\n : undefined;\n const extensionLinkFields = fields.extensionLink\n ? (findIncludedItem(\n fields.extensionLink.sys.id,\n ) as TypeExtensionLinkFields['fields'])\n : undefined;\n const mobileLinkFields = fields.mobileLink\n ? (findIncludedItem(\n fields.mobileLink.sys.id,\n ) as TypeMobileLinkFields['fields'])\n : undefined;\n\n const notification: FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,\n createdAt: new Date(item.sys.createdAt).toString(),\n data: {\n id: fields.id,\n category: fields.category,\n title: fields.title,\n longDescription: documentToHtmlString(fields.longDescription),\n shortDescription: fields.shortDescription,\n image: {\n title: imageFields?.title,\n description: imageFields?.description,\n url: imageFields?.file?.url ?? '',\n },\n externalLink: externalLinkFields && {\n externalLinkText: externalLinkFields?.externalLinkText,\n externalLinkUrl: externalLinkFields?.externalLinkUrl,\n },\n portfolioLink: portfolioLinkFields && {\n portfolioLinkText: portfolioLinkFields?.portfolioLinkText,\n portfolioLinkUrl: portfolioLinkFields?.portfolioLinkUrl,\n },\n extensionLink: extensionLinkFields && {\n extensionLinkText: extensionLinkFields?.extensionLinkText,\n extensionLinkRoute: extensionLinkFields?.extensionLinkRoute,\n },\n mobileLink: mobileLinkFields && {\n mobileLinkText: mobileLinkFields?.mobileLinkText,\n mobileLinkUrl: mobileLinkFields?.mobileLinkUrl,\n },\n extensionMinimumVersionNumber: fields.extensionMinimumVersionNumber,\n mobileMinimumVersionNumber: fields.mobileMinimumVersionNumber,\n extensionMaximumVersionNumber: fields.extensionMaximumVersionNumber,\n mobileMaximumVersionNumber: fields.mobileMaximumVersionNumber,\n },\n };\n\n return notification;\n });\n\n const versionKeys = {\n extension: {\n min: 'extensionMinimumVersionNumber',\n max: 'extensionMaximumVersionNumber',\n },\n mobile: {\n min: 'mobileMinimumVersionNumber',\n max: 'mobileMaximumVersionNumber',\n },\n } as const;\n\n const filteredRawNotifications = rawNotifications.filter(\n (rawNotification) => {\n const minVersion = rawNotification.data?.[versionKeys[env.platform].min];\n const maxVersion = rawNotification.data?.[versionKeys[env.platform].max];\n return isVersionInBounds({\n currentVersion: env.platformVersion,\n minVersion,\n maxVersion,\n });\n },\n );\n\n return filteredRawNotifications;\n};\n\n/**\n * Gets Feature Announcement from our services\n *\n * @param env - environment for feature announcements\n * @param previewToken - the preview token to use if needed\n * @returns Raw Feature Announcements\n */\nexport async function getFeatureAnnouncementNotifications(\n env: Env,\n previewToken?: string,\n): Promise<INotification[]> {\n if (env?.accessToken && env?.spaceId && env?.platform) {\n const rawNotifications = await fetchFeatureAnnouncementNotifications(\n env,\n previewToken,\n );\n const notifications = rawNotifications.map((notification) =>\n processFeatureAnnouncement(notification),\n );\n\n return notifications;\n }\n\n return [];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"feature-announcements.js","sourceRoot":"","sources":["../../../src/NotificationServicesController/services/feature-announcements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAG3E,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAa3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE,uFAAuF;AACvF,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAE9C,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAC7C,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAChD,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,cAAc,WAAW,gBAAgB,8BAA8B,CAAC;AAC3H,MAAM,CAAC,MAA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G,gBAAgB,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CAC1D,0BAA0B,CAAC,YAAY,CAAC,CACzC,CAAC;QAEF,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import { documentToHtmlString } from '@contentful/rich-text-html-renderer';\nimport type { Entry, Asset, EntryCollection } from 'contentful';\n\nimport { TRIGGER_TYPES } from '../constants/notification-schema.js';\nimport { processFeatureAnnouncement } from '../processors/process-feature-announcement.js';\nimport type { FeatureAnnouncementRawNotification } from '../types/feature-announcement/feature-announcement.js';\nimport type {\n ImageFields,\n TypeFeatureAnnouncement,\n} from '../types/feature-announcement/type-feature-announcement.js';\nimport type {\n TypeExternalLinkFields,\n TypePortfolioLinkFields,\n TypeExtensionLinkFields,\n TypeMobileLinkFields,\n} from '../types/feature-announcement/type-links.js';\nimport type { INotification } from '../types/notification/notification.js';\nimport { isVersionInBounds } from '../utils/isVersionInBounds.js';\n\n// Feature announcements older than this (by sys.updatedAt) are excluded from the feed.\nconst FEATURE_ANNOUNCEMENT_MAX_AGE_MONTHS = 3;\n\nconst DEFAULT_SPACE_ID = ':space_id';\nconst DEFAULT_ACCESS_TOKEN = ':access_token';\nconst DEFAULT_CLIENT_ID = ':client_id';\nconst DEFAULT_DOMAIN = 'cdn.contentful.com';\nconst PREVIEW_DOMAIN = 'preview.contentful.com';\nexport const FEATURE_ANNOUNCEMENT_API = `https://${DEFAULT_DOMAIN}/spaces/${DEFAULT_SPACE_ID}/environments/master/entries`;\nexport const FEATURE_ANNOUNCEMENT_URL = `${FEATURE_ANNOUNCEMENT_API}?access_token=${DEFAULT_ACCESS_TOKEN}&content_type=productAnnouncement&include=10&fields.clients[in]=${DEFAULT_CLIENT_ID}`;\n\ntype Env = {\n spaceId: string;\n accessToken: string;\n platform: 'extension' | 'mobile';\n platformVersion?: string;\n};\n\n/**\n * Contentful API Response Shape\n */\nexport type ContentfulResult = {\n includes?: {\n // Property names match Contentful API response structure\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Entry?: Entry[];\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Asset?: Asset[];\n };\n items?: TypeFeatureAnnouncement[];\n};\n\nexport const getFeatureAnnouncementUrl = (\n env: Env,\n previewToken?: string,\n): string => {\n const domain = previewToken ? PREVIEW_DOMAIN : DEFAULT_DOMAIN;\n const replacedUrl = FEATURE_ANNOUNCEMENT_URL.replace(\n DEFAULT_SPACE_ID,\n env.spaceId,\n )\n .replace(DEFAULT_ACCESS_TOKEN, previewToken ?? env.accessToken)\n .replace(DEFAULT_CLIENT_ID, env.platform)\n .replace(DEFAULT_DOMAIN, domain);\n return encodeURI(replacedUrl);\n};\n\nconst fetchFeatureAnnouncementNotifications = async (\n env: Env,\n previewToken?: string,\n): Promise<FeatureAnnouncementRawNotification[]> => {\n const url = getFeatureAnnouncementUrl(env, previewToken);\n\n const data = await fetch(url)\n .then((response) => response.json())\n .catch(() => null);\n\n if (!data) {\n return [];\n }\n\n const findIncludedItem = (\n sysId: string,\n ):\n | ImageFields['fields']\n | TypeExtensionLinkFields['fields']\n | TypePortfolioLinkFields['fields']\n | TypeMobileLinkFields['fields']\n | TypeExternalLinkFields['fields']\n | null => {\n const typedData: EntryCollection<\n | ImageFields\n | TypeExtensionLinkFields\n | TypePortfolioLinkFields\n | TypeMobileLinkFields\n | TypeExternalLinkFields\n > = data;\n const item =\n typedData?.includes?.Entry?.find(\n (entry: Entry) => entry?.sys?.id === sysId,\n ) ??\n typedData?.includes?.Asset?.find(\n (asset: Asset) => asset?.sys?.id === sysId,\n );\n return item ? item?.fields : null;\n };\n\n const contentfulNotifications = data?.items ?? [];\n const rawNotifications: FeatureAnnouncementRawNotification[] =\n contentfulNotifications\n .filter((item: TypeFeatureAnnouncement) => {\n const updatedAt = new Date(item.sys.updatedAt);\n const limitDate = new Date();\n limitDate.setMonth(\n limitDate.getMonth() - FEATURE_ANNOUNCEMENT_MAX_AGE_MONTHS,\n );\n return updatedAt > limitDate;\n })\n .map((item: TypeFeatureAnnouncement) => {\n const { fields } = item;\n const imageFields = fields.image\n ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields'])\n : undefined;\n\n const externalLinkFields = fields.externalLink\n ? (findIncludedItem(\n fields.externalLink.sys.id,\n ) as TypeExternalLinkFields['fields'])\n : undefined;\n const portfolioLinkFields = fields.portfolioLink\n ? (findIncludedItem(\n fields.portfolioLink.sys.id,\n ) as TypePortfolioLinkFields['fields'])\n : undefined;\n const extensionLinkFields = fields.extensionLink\n ? (findIncludedItem(\n fields.extensionLink.sys.id,\n ) as TypeExtensionLinkFields['fields'])\n : undefined;\n const mobileLinkFields = fields.mobileLink\n ? (findIncludedItem(\n fields.mobileLink.sys.id,\n ) as TypeMobileLinkFields['fields'])\n : undefined;\n\n const notification: FeatureAnnouncementRawNotification = {\n type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT,\n createdAt: new Date(item.sys.createdAt).toString(),\n data: {\n id: fields.id,\n category: fields.category,\n title: fields.title,\n longDescription: documentToHtmlString(fields.longDescription),\n shortDescription: fields.shortDescription,\n image: {\n title: imageFields?.title,\n description: imageFields?.description,\n url: imageFields?.file?.url ?? '',\n },\n externalLink: externalLinkFields && {\n externalLinkText: externalLinkFields?.externalLinkText,\n externalLinkUrl: externalLinkFields?.externalLinkUrl,\n },\n portfolioLink: portfolioLinkFields && {\n portfolioLinkText: portfolioLinkFields?.portfolioLinkText,\n portfolioLinkUrl: portfolioLinkFields?.portfolioLinkUrl,\n },\n extensionLink: extensionLinkFields && {\n extensionLinkText: extensionLinkFields?.extensionLinkText,\n extensionLinkRoute: extensionLinkFields?.extensionLinkRoute,\n },\n mobileLink: mobileLinkFields && {\n mobileLinkText: mobileLinkFields?.mobileLinkText,\n mobileLinkUrl: mobileLinkFields?.mobileLinkUrl,\n },\n extensionMinimumVersionNumber: fields.extensionMinimumVersionNumber,\n mobileMinimumVersionNumber: fields.mobileMinimumVersionNumber,\n extensionMaximumVersionNumber: fields.extensionMaximumVersionNumber,\n mobileMaximumVersionNumber: fields.mobileMaximumVersionNumber,\n },\n };\n\n return notification;\n });\n\n const versionKeys = {\n extension: {\n min: 'extensionMinimumVersionNumber',\n max: 'extensionMaximumVersionNumber',\n },\n mobile: {\n min: 'mobileMinimumVersionNumber',\n max: 'mobileMaximumVersionNumber',\n },\n } as const;\n\n const filteredRawNotifications = rawNotifications.filter(\n (rawNotification) => {\n const minVersion = rawNotification.data?.[versionKeys[env.platform].min];\n const maxVersion = rawNotification.data?.[versionKeys[env.platform].max];\n return isVersionInBounds({\n currentVersion: env.platformVersion,\n minVersion,\n maxVersion,\n });\n },\n );\n\n return filteredRawNotifications;\n};\n\n/**\n * Gets Feature Announcement from our services\n *\n * @param env - environment for feature announcements\n * @param previewToken - the preview token to use if needed\n * @returns Raw Feature Announcements\n */\nexport async function getFeatureAnnouncementNotifications(\n env: Env,\n previewToken?: string,\n): Promise<INotification[]> {\n if (env?.accessToken && env?.spaceId && env?.platform) {\n const rawNotifications = await fetchFeatureAnnouncementNotifications(\n env,\n previewToken,\n );\n const notifications = rawNotifications.map((notification) =>\n processFeatureAnnouncement(notification),\n );\n\n return notifications;\n }\n\n return [];\n}\n"]}
|
|
@@ -19,6 +19,7 @@ export type BlockExplorer = components['schemas']['BlockExplorer'];
|
|
|
19
19
|
export type UnprocessedRawNotification = components['schemas']['NotificationOutputV4'][number];
|
|
20
20
|
export type PlatformNotification = components['schemas']['PlatformNotificationV4'];
|
|
21
21
|
export type OnChainNotification = components['schemas']['OnChainNotificationV4'];
|
|
22
|
+
export type NotificationsCategory = components['schemas']['NotificationCategory'];
|
|
22
23
|
type ConvertToEnum<Kind> = {
|
|
23
24
|
[K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;
|
|
24
25
|
}[TRIGGER_TYPES];
|
package/dist/NotificationServicesController/types/notification-api/notification-api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-api.d.ts","sour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;KACH,CACF;CACF,CAAC,qBAAqB,CAAC,CAAC;AAEzB;;;;GAIG;AACH,KAAK,6BAA6B,CAChC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,IACnD,OAAO,CACT,CAAC,GAAG;IACF,IAAI,EAAE,aAAa,CAAC,QAAQ,CAAC;CAC9B,CACF,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,OAAO,CAC1C,4BAA4B,CAAC,mBAAmB,CAAC,CAClD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,OAAO,CAC3C,6BAA6B,CAAC,oBAAoB,CAAC,CACpD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACjC,sBAAsB,GACtB,uBAAuB,CAAC;AAE5B,MAAM,MAAM,wCAAwC,GAAG,OAAO,CAC5D,sBAAsB,EACtB;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,WAAW,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAChD,CAAC"}
|
|
1
|
+
{"version":3,"file":"notification-api.d.ts","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,0BAA0B,GACpC,UAAU,CAAC,SAAS,CAAC,CAAC,4BAA4B,CAAC,CAAC;AACtD,MAAM,MAAM,gCAAgC,GAC1C,UAAU,CAAC,SAAS,CAAC,CAAC,kCAAkC,CAAC,CAAC;AAC5D,MAAM,MAAM,uBAAuB,GACjC,UAAU,CAAC,SAAS,CAAC,CAAC,yBAAyB,CAAC,CAAC;AACnD,MAAM,MAAM,4BAA4B,GACtC,UAAU,CAAC,SAAS,CAAC,CAAC,8BAA8B,CAAC,CAAC;AACxD,MAAM,MAAM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AsB,EACtB;IAAE,OAAO,EAAE;QAAE,IAAI,EAAE;YAAE,WAAW,EAAE,OAAO,CAAA;SAAE,CAAA;KAAE,CAAA;CAAE,CAChD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-api.js","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"","sourcesContent":["import { TRIGGER_TYPES } from '../../constants/notification-schema.js';\nimport type { Compute } from '../type-utils.js';\n// Types derived from external Notification API schema - naming follows API conventions\n/* eslint-disable @typescript-eslint/naming-convention */\nimport type { components } from './schema.js';\n\nexport type Data_MetamaskSwapCompleted =\n components['schemas']['Data_MetamaskSwapCompleted'];\nexport type Data_LidoStakeReadyToBeWithdrawn =\n components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];\nexport type Data_LidoStakeCompleted =\n components['schemas']['Data_LidoStakeCompleted'];\nexport type Data_LidoWithdrawalRequested =\n components['schemas']['Data_LidoWithdrawalRequested'];\nexport type Data_LidoWithdrawalCompleted =\n components['schemas']['Data_LidoWithdrawalCompleted'];\nexport type Data_RocketPoolStakeCompleted =\n components['schemas']['Data_RocketPoolStakeCompleted'];\nexport type Data_RocketPoolUnstakeCompleted =\n components['schemas']['Data_RocketPoolUnstakeCompleted'];\nexport type Data_ETHSent = components['schemas']['Data_ETHSent'];\nexport type Data_ETHReceived = components['schemas']['Data_ETHReceived'];\nexport type Data_ERC20Sent = components['schemas']['Data_ERC20Sent'];\nexport type Data_ERC20Received = components['schemas']['Data_ERC20Received'];\nexport type Data_ERC721Sent = components['schemas']['Data_ERC721Sent'];\nexport type Data_ERC721Received = components['schemas']['Data_ERC721Received'];\nexport type NetworkMetadata = components['schemas']['NetworkMetadata'];\nexport type BlockExplorer = components['schemas']['BlockExplorer'];\n\nexport type UnprocessedRawNotification =\n components['schemas']['NotificationOutputV4'][number];\nexport type PlatformNotification =\n components['schemas']['PlatformNotificationV4'];\nexport type OnChainNotification =\n components['schemas']['OnChainNotificationV4'];\n\ntype ConvertToEnum<Kind> = {\n [K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;\n}[TRIGGER_TYPES];\n\n/**\n * Type-Computation.\n * Adds a `type` field to on-chain notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizeOnChainNotification<\n N extends OnChainNotification = OnChainNotification,\n NotificationDataKinds extends string = NonNullable<\n N['payload']['data']\n >['kind'],\n> = {\n [K in NotificationDataKinds]: Compute<\n Omit<N, 'payload'> & {\n type: ConvertToEnum<K>;\n payload: Compute<\n Omit<N['payload'], 'data'> & {\n data: Extract<NonNullable<N['payload']['data']>, { kind: K }>;\n }\n >;\n }\n >;\n}[NotificationDataKinds];\n\n/**\n * Type-Computation.\n * Adds a `type` field to platform notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizePlatformNotification<\n N extends PlatformNotification = PlatformNotification,\n> = Compute<\n N & {\n type: TRIGGER_TYPES.PLATFORM;\n }\n>;\n\nexport type OnChainRawNotification = Compute<\n NormalizeOnChainNotification<OnChainNotification>\n>;\n\nexport type PlatformRawNotification = Compute<\n NormalizePlatformNotification<PlatformNotification>\n>;\n\nexport type NormalisedAPINotification =\n | OnChainRawNotification\n | PlatformRawNotification;\n\nexport type OnChainRawNotificationsWithNetworkFields = Extract<\n OnChainRawNotification,\n { payload: { data: { network_fee: unknown } } }\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"notification-api.js","sourceRoot":"","sources":["../../../../src/NotificationServicesController/types/notification-api/notification-api.ts"],"names":[],"mappings":"","sourcesContent":["import { TRIGGER_TYPES } from '../../constants/notification-schema.js';\nimport type { Compute } from '../type-utils.js';\n// Types derived from external Notification API schema - naming follows API conventions\n/* eslint-disable @typescript-eslint/naming-convention */\nimport type { components } from './schema.js';\n\nexport type Data_MetamaskSwapCompleted =\n components['schemas']['Data_MetamaskSwapCompleted'];\nexport type Data_LidoStakeReadyToBeWithdrawn =\n components['schemas']['Data_LidoStakeReadyToBeWithdrawn'];\nexport type Data_LidoStakeCompleted =\n components['schemas']['Data_LidoStakeCompleted'];\nexport type Data_LidoWithdrawalRequested =\n components['schemas']['Data_LidoWithdrawalRequested'];\nexport type Data_LidoWithdrawalCompleted =\n components['schemas']['Data_LidoWithdrawalCompleted'];\nexport type Data_RocketPoolStakeCompleted =\n components['schemas']['Data_RocketPoolStakeCompleted'];\nexport type Data_RocketPoolUnstakeCompleted =\n components['schemas']['Data_RocketPoolUnstakeCompleted'];\nexport type Data_ETHSent = components['schemas']['Data_ETHSent'];\nexport type Data_ETHReceived = components['schemas']['Data_ETHReceived'];\nexport type Data_ERC20Sent = components['schemas']['Data_ERC20Sent'];\nexport type Data_ERC20Received = components['schemas']['Data_ERC20Received'];\nexport type Data_ERC721Sent = components['schemas']['Data_ERC721Sent'];\nexport type Data_ERC721Received = components['schemas']['Data_ERC721Received'];\nexport type NetworkMetadata = components['schemas']['NetworkMetadata'];\nexport type BlockExplorer = components['schemas']['BlockExplorer'];\n\nexport type UnprocessedRawNotification =\n components['schemas']['NotificationOutputV4'][number];\nexport type PlatformNotification =\n components['schemas']['PlatformNotificationV4'];\nexport type OnChainNotification =\n components['schemas']['OnChainNotificationV4'];\n\nexport type NotificationsCategory =\n components['schemas']['NotificationCategory'];\n\ntype ConvertToEnum<Kind> = {\n [K in TRIGGER_TYPES]: Kind extends `${K}` ? K : never;\n}[TRIGGER_TYPES];\n\n/**\n * Type-Computation.\n * Adds a `type` field to on-chain notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizeOnChainNotification<\n N extends OnChainNotification = OnChainNotification,\n NotificationDataKinds extends string = NonNullable<\n N['payload']['data']\n >['kind'],\n> = {\n [K in NotificationDataKinds]: Compute<\n Omit<N, 'payload'> & {\n type: ConvertToEnum<K>;\n payload: Compute<\n Omit<N['payload'], 'data'> & {\n data: Extract<NonNullable<N['payload']['data']>, { kind: K }>;\n }\n >;\n }\n >;\n}[NotificationDataKinds];\n\n/**\n * Type-Computation.\n * Adds a `type` field to platform notifications for easier enum checking.\n * Preserves the original nested payload structure.\n */\ntype NormalizePlatformNotification<\n N extends PlatformNotification = PlatformNotification,\n> = Compute<\n N & {\n type: TRIGGER_TYPES.PLATFORM;\n }\n>;\n\nexport type OnChainRawNotification = Compute<\n NormalizeOnChainNotification<OnChainNotification>\n>;\n\nexport type PlatformRawNotification = Compute<\n NormalizePlatformNotification<PlatformNotification>\n>;\n\nexport type NormalisedAPINotification =\n | OnChainRawNotification\n | PlatformRawNotification;\n\nexport type OnChainRawNotificationsWithNetworkFields = Extract<\n OnChainRawNotification,\n { payload: { data: { network_fee: unknown } } }\n>;\n"]}
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
type JsonRequestMethod = 'POST';
|
|
2
|
+
type NoBodyMethod = 'GET' | 'DELETE';
|
|
3
|
+
type MakeApiCallOptions<Body> = {
|
|
4
|
+
method: NoBodyMethod;
|
|
5
|
+
bearerToken?: string;
|
|
6
|
+
} | {
|
|
7
|
+
method: JsonRequestMethod;
|
|
8
|
+
body: Body;
|
|
9
|
+
bearerToken?: string;
|
|
10
|
+
};
|
|
1
11
|
/**
|
|
2
|
-
* Performs an API call with
|
|
12
|
+
* Performs an API call with optional bearer authentication and JSON body support.
|
|
3
13
|
*
|
|
4
|
-
* @param bearerToken - The JSON Web Token for authorization.
|
|
5
14
|
* @param endpoint - The URL of the API endpoint to call.
|
|
6
|
-
* @param
|
|
7
|
-
* @param body - The body of the request. It should be an object that can be serialized to JSON.
|
|
15
|
+
* @param options - Request configuration.
|
|
8
16
|
* @returns A Promise that resolves to the response of the fetch request.
|
|
9
17
|
*/
|
|
10
|
-
export declare function makeApiCall<Body>(
|
|
18
|
+
export declare function makeApiCall<Body = never>(endpoint: string, options: MakeApiCallOptions<Body>): Promise<Response>;
|
|
19
|
+
export {};
|
|
11
20
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/utils.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/utils.ts"],"names":[],"mappings":"AAAA,KAAK,iBAAiB,GAAG,MAAM,CAAC;AAChC,KAAK,YAAY,GAAG,KAAK,GAAG,QAAQ,CAAC;AAErC,KAAK,kBAAkB,CAAC,IAAI,IACxB;IACE,MAAM,EAAE,YAAY,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,GACD;IACE,MAAM,EAAE,iBAAiB,CAAC;IAC1B,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEN;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,IAAI,GAAG,KAAK,EAC5C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,kBAAkB,CAAC,IAAI,CAAC,GAChC,OAAO,CAAC,QAAQ,CAAC,CAkBnB"}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Performs an API call with
|
|
2
|
+
* Performs an API call with optional bearer authentication and JSON body support.
|
|
3
3
|
*
|
|
4
|
-
* @param bearerToken - The JSON Web Token for authorization.
|
|
5
4
|
* @param endpoint - The URL of the API endpoint to call.
|
|
6
|
-
* @param
|
|
7
|
-
* @param body - The body of the request. It should be an object that can be serialized to JSON.
|
|
5
|
+
* @param options - Request configuration.
|
|
8
6
|
* @returns A Promise that resolves to the response of the fetch request.
|
|
9
7
|
*/
|
|
10
|
-
export async function makeApiCall(
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
headers
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
export async function makeApiCall(endpoint, options) {
|
|
9
|
+
const headers = {};
|
|
10
|
+
if (options.bearerToken) {
|
|
11
|
+
headers.Authorization = `Bearer ${options.bearerToken}`;
|
|
12
|
+
}
|
|
13
|
+
let body;
|
|
14
|
+
if (options.method === 'POST') {
|
|
15
|
+
headers['Content-Type'] = 'application/json';
|
|
16
|
+
body = JSON.stringify(options.body);
|
|
17
|
+
}
|
|
18
|
+
return fetch(endpoint, {
|
|
19
|
+
method: options.method,
|
|
20
|
+
headers,
|
|
21
|
+
body,
|
|
22
|
+
});
|
|
20
23
|
}
|
|
21
24
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/NotificationServicesController/utils/utils.ts"],"names":[],"mappings":"AAcA;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,QAAgB,EAChB,OAAiC;IAEjC,MAAM,OAAO,GAAgB,EAAE,CAAC;IAEhC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,OAAO,CAAC,aAAa,GAAG,UAAU,OAAO,CAAC,WAAW,EAAE,CAAC;IAC1D,CAAC;IAED,IAAI,IAAwB,CAAC;IAC7B,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC9B,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;QAC7C,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,EAAE;QACrB,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,OAAO;QACP,IAAI;KACL,CAAC,CAAC;AACL,CAAC","sourcesContent":["type JsonRequestMethod = 'POST';\ntype NoBodyMethod = 'GET' | 'DELETE';\n\ntype MakeApiCallOptions<Body> =\n | {\n method: NoBodyMethod;\n bearerToken?: string;\n }\n | {\n method: JsonRequestMethod;\n body: Body;\n bearerToken?: string;\n };\n\n/**\n * Performs an API call with optional bearer authentication and JSON body support.\n *\n * @param endpoint - The URL of the API endpoint to call.\n * @param options - Request configuration.\n * @returns A Promise that resolves to the response of the fetch request.\n */\nexport async function makeApiCall<Body = never>(\n endpoint: string,\n options: MakeApiCallOptions<Body>,\n): Promise<Response> {\n const headers: HeadersInit = {};\n\n if (options.bearerToken) {\n headers.Authorization = `Bearer ${options.bearerToken}`;\n }\n\n let body: string | undefined;\n if (options.method === 'POST') {\n headers['Content-Type'] = 'application/json';\n body = JSON.stringify(options.body);\n }\n\n return fetch(endpoint, {\n method: options.method,\n headers,\n body,\n });\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/notification-services-controller",
|
|
3
|
-
"version": "29.0.2-preview-
|
|
3
|
+
"version": "29.0.2-preview-247ba396c",
|
|
4
4
|
"description": "Manages New MetaMask decentralized Notification system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"@types/readable-stream": "^2.3.0",
|
|
97
97
|
"@types/semver": "^7.8.0",
|
|
98
98
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
99
|
-
"contentful": "^
|
|
99
|
+
"contentful": "^10.15.0",
|
|
100
100
|
"deepmerge": "^4.3.1",
|
|
101
101
|
"jest": "^30.5.2",
|
|
102
102
|
"jest-environment-jsdom": "^30.5.2",
|