diff --git a/eslint-suppressions.json b/eslint-suppressions.json index b7493f59e9a..236edf2cb1c 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1575,30 +1575,6 @@ "count": 1 } }, - "packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 2 - }, - "@typescript-eslint/naming-convention": { - "count": 2 - }, - "@typescript-eslint/prefer-nullish-coalescing": { - "count": 2 - }, - "id-length": { - "count": 3 - } - }, - "packages/notification-services-controller/src/NotificationServicesController/services/notification-config-cache.ts": { - "@typescript-eslint/naming-convention": { - "count": 1 - } - }, - "packages/notification-services-controller/src/NotificationServicesController/services/perp-notifications.test.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 1 - } - }, "packages/notification-services-controller/src/NotificationServicesController/services/perp-notifications.ts": { "@typescript-eslint/explicit-function-return-type": { "count": 1 diff --git a/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts b/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts index 5ea40ec34fb..ddd0c9cf64c 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/services/feature-announcements.ts @@ -37,19 +37,25 @@ type Env = { */ export type ContentfulResult = { includes?: { + // Property names match Contentful API response structure + // eslint-disable-next-line @typescript-eslint/naming-convention Entry?: Entry[]; + // eslint-disable-next-line @typescript-eslint/naming-convention Asset?: Asset[]; }; items?: TypeFeatureAnnouncement[]; }; -export const getFeatureAnnouncementUrl = (env: Env, previewToken?: string) => { +export const getFeatureAnnouncementUrl = ( + env: Env, + previewToken?: string, +): string => { const domain = previewToken ? PREVIEW_DOMAIN : DEFAULT_DOMAIN; const replacedUrl = FEATURE_ANNOUNCEMENT_URL.replace( DEFAULT_SPACE_ID, env.spaceId, ) - .replace(DEFAULT_ACCESS_TOKEN, previewToken || env.accessToken) + .replace(DEFAULT_ACCESS_TOKEN, previewToken ?? env.accessToken) .replace(DEFAULT_CLIENT_ID, env.platform) .replace(DEFAULT_DOMAIN, domain); return encodeURI(replacedUrl); @@ -62,14 +68,22 @@ const fetchFeatureAnnouncementNotifications = async ( const url = getFeatureAnnouncementUrl(env, previewToken); const data = await fetch(url) - .then((r) => r.json()) + .then((response) => response.json()) .catch(() => null); if (!data) { return []; } - const findIncludedItem = (sysId: string) => { + const findIncludedItem = ( + sysId: string, + ): + | ImageFields['fields'] + | TypeExtensionLinkFields['fields'] + | TypePortfolioLinkFields['fields'] + | TypeMobileLinkFields['fields'] + | TypeExternalLinkFields['fields'] + | null => { const typedData: EntryCollection< | ImageFields | TypeExtensionLinkFields @@ -78,15 +92,19 @@ const fetchFeatureAnnouncementNotifications = async ( | TypeExternalLinkFields > = data; const item = - typedData?.includes?.Entry?.find((i: Entry) => i?.sys?.id === sysId) || - typedData?.includes?.Asset?.find((i: Asset) => i?.sys?.id === sysId); + typedData?.includes?.Entry?.find( + (entry: Entry) => entry?.sys?.id === sysId, + ) ?? + typedData?.includes?.Asset?.find( + (asset: Asset) => asset?.sys?.id === sysId, + ); return item ? item?.fields : null; }; const contentfulNotifications = data?.items ?? []; const rawNotifications: FeatureAnnouncementRawNotification[] = - contentfulNotifications.map((n: TypeFeatureAnnouncement) => { - const { fields } = n; + contentfulNotifications.map((item: TypeFeatureAnnouncement) => { + const { fields } = item; const imageFields = fields.image ? (findIncludedItem(fields.image.sys.id) as ImageFields['fields']) : undefined; @@ -114,7 +132,7 @@ const fetchFeatureAnnouncementNotifications = async ( const notification: FeatureAnnouncementRawNotification = { type: TRIGGER_TYPES.FEATURES_ANNOUNCEMENT, - createdAt: new Date(n.sys.createdAt).toString(), + createdAt: new Date(item.sys.createdAt).toString(), data: { id: fields.id, category: fields.category, @@ -163,15 +181,17 @@ const fetchFeatureAnnouncementNotifications = async ( }, } as const; - const filteredRawNotifications = rawNotifications.filter((n) => { - const minVersion = n.data?.[versionKeys[env.platform].min]; - const maxVersion = n.data?.[versionKeys[env.platform].max]; - return isVersionInBounds({ - currentVersion: env.platformVersion, - minVersion, - maxVersion, - }); - }); + const filteredRawNotifications = rawNotifications.filter( + (rawNotification) => { + const minVersion = rawNotification.data?.[versionKeys[env.platform].min]; + const maxVersion = rawNotification.data?.[versionKeys[env.platform].max]; + return isVersionInBounds({ + currentVersion: env.platformVersion, + minVersion, + maxVersion, + }); + }, + ); return filteredRawNotifications; }; diff --git a/packages/notification-services-controller/src/NotificationServicesController/services/notification-config-cache.ts b/packages/notification-services-controller/src/NotificationServicesController/services/notification-config-cache.ts index 6efaef3c74b..fac64dc304e 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/services/notification-config-cache.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/services/notification-config-cache.ts @@ -8,10 +8,10 @@ export const NotificationConfigCacheTTL = 1000 * 60; // 60 seconds export class OnChainNotificationsCache { #cache: NotificationConfigCache | null = null; - readonly #TTL = NotificationConfigCacheTTL; + readonly #ttl = NotificationConfigCacheTTL; #isExpired(): boolean { - return !this.#cache || Date.now() - this.#cache.timestamp > this.#TTL; + return !this.#cache || Date.now() - this.#cache.timestamp > this.#ttl; } #hasAllAddresses(addresses: string[]): boolean { diff --git a/packages/notification-services-controller/src/NotificationServicesController/services/perp-notifications.test.ts b/packages/notification-services-controller/src/NotificationServicesController/services/perp-notifications.test.ts index 4ebb44d912a..c138c369133 100644 --- a/packages/notification-services-controller/src/NotificationServicesController/services/perp-notifications.test.ts +++ b/packages/notification-services-controller/src/NotificationServicesController/services/perp-notifications.test.ts @@ -14,7 +14,9 @@ describe('Perps Service - createPerpOrderNotification', () => { jest.clearAllMocks(); }); - const arrangeMocks = () => { + const arrangeMocks = (): { + consoleErrorSpy: jest.SpyInstance>; + } => { const consoleErrorSpy = jest .spyOn(console, 'error') .mockImplementation(jest.fn());