From b25dc69526eb4a1f10da88e9b76c905d5a954442 Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Mon, 4 Mar 2024 14:40:50 -0800 Subject: [PATCH] chore(rtn-push-notification): run yarn lint:fix --- .../src/apis/addMessageEventListener.ts | 1 + .../src/apis/addTokenEventListener.ts | 1 + .../src/apis/registerHeadlessTask.ts | 4 ++- packages/rtn-push-notification/src/index.ts | 1 + .../rtn-push-notification/src/nativeModule.ts | 3 +- .../rtn-push-notification/src/types/native.ts | 33 ++++++++++--------- .../src/utils/normalizeNativeMessage.ts | 6 ++++ 7 files changed, 31 insertions(+), 18 deletions(-) diff --git a/packages/rtn-push-notification/src/apis/addMessageEventListener.ts b/packages/rtn-push-notification/src/apis/addMessageEventListener.ts index 50367252c7b..57f9c072a9a 100644 --- a/packages/rtn-push-notification/src/apis/addMessageEventListener.ts +++ b/packages/rtn-push-notification/src/apis/addMessageEventListener.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { EmitterSubscription } from 'react-native'; + import { nativeEventEmitter } from '../nativeModule'; import { NativeMessage, PushNotificationMessage } from '../types'; import { normalizeNativeMessage } from '../utils'; diff --git a/packages/rtn-push-notification/src/apis/addTokenEventListener.ts b/packages/rtn-push-notification/src/apis/addTokenEventListener.ts index e049f22f1f0..8700e3b10f0 100644 --- a/packages/rtn-push-notification/src/apis/addTokenEventListener.ts +++ b/packages/rtn-push-notification/src/apis/addTokenEventListener.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { EmitterSubscription } from 'react-native'; + import { nativeEventEmitter } from '../nativeModule'; import { TokenPayload } from '../types'; diff --git a/packages/rtn-push-notification/src/apis/registerHeadlessTask.ts b/packages/rtn-push-notification/src/apis/registerHeadlessTask.ts index 895a2b0fc5c..9fee19ffa3c 100644 --- a/packages/rtn-push-notification/src/apis/registerHeadlessTask.ts +++ b/packages/rtn-push-notification/src/apis/registerHeadlessTask.ts @@ -2,10 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import { AppRegistry } from 'react-native'; -import { getConstants } from './getConstants'; + import { NativeMessage, PushNotificationMessage } from '../types'; import { normalizeNativeMessage } from '../utils'; +import { getConstants } from './getConstants'; + export const registerHeadlessTask = ( task: (message: PushNotificationMessage | null) => Promise, ): void => { diff --git a/packages/rtn-push-notification/src/index.ts b/packages/rtn-push-notification/src/index.ts index fa7318744bf..2e380ee3c3d 100644 --- a/packages/rtn-push-notification/src/index.ts +++ b/packages/rtn-push-notification/src/index.ts @@ -13,6 +13,7 @@ import { requestPermissions, setBadgeCount, } from './apis'; + export { PushNotificationMessage, PushNotificationPermissionStatus, diff --git a/packages/rtn-push-notification/src/nativeModule.ts b/packages/rtn-push-notification/src/nativeModule.ts index c7c4f6374df..a24b3e4be2a 100644 --- a/packages/rtn-push-notification/src/nativeModule.ts +++ b/packages/rtn-push-notification/src/nativeModule.ts @@ -1,7 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { NativeModules, NativeEventEmitter } from 'react-native'; +import { NativeEventEmitter, NativeModules } from 'react-native'; + import { LINKING_ERROR } from './constants'; import { PushNotificationNativeModule } from './types'; diff --git a/packages/rtn-push-notification/src/types/native.ts b/packages/rtn-push-notification/src/types/native.ts index 6791bfc09e7..fb43ad95c8a 100644 --- a/packages/rtn-push-notification/src/types/native.ts +++ b/packages/rtn-push-notification/src/types/native.ts @@ -2,11 +2,12 @@ // SPDX-License-Identifier: Apache-2.0 import { NativeModule } from 'react-native'; + import { PushNotificationMessage, PushNotificationPermissions } from './module'; export interface PushNotificationNativeModule extends NativeModule { - completeNotification?: (completionHandlerId: string) => void; - getConstants: () => { + completeNotification?(completionHandlerId: string): void; + getConstants(): { NativeEvent: { BACKGROUND_MESSAGE_RECEIVED?: string; FOREGROUND_MESSAGE_RECEIVED: string; @@ -16,19 +17,19 @@ export interface PushNotificationNativeModule extends NativeModule { }; NativeHeadlessTaskKey?: string; }; - getLaunchNotification: () => Promise; - getBadgeCount?: () => Promise; - setBadgeCount?: (count: number) => void; - getPermissionStatus: () => Promise; - requestPermissions: ( + getLaunchNotification(): Promise; + getBadgeCount?(): Promise; + setBadgeCount?(count: number): void; + getPermissionStatus(): Promise; + requestPermissions( permissions: PushNotificationPermissions, - ) => Promise; + ): Promise; } -export type NativeAction = { +export interface NativeAction { deeplink?: string; url?: string; -}; +} export type NativeMessage = (ApnsMessage | FcmMessage) & { token?: never; @@ -48,7 +49,7 @@ export interface NormalizedValues { } // iOS -export type ApnsMessage = { +export interface ApnsMessage { aps: { alert?: { body?: string; @@ -62,12 +63,12 @@ export type ApnsMessage = { }; rawData?: never; completionHandlerId?: string; -}; +} export type IosPermissionStatus = 'NotDetermined' | 'Authorized' | 'Denied'; // Android -export type FcmMessage = { +export interface FcmMessage { action?: NativeAction; aps?: never; body?: string; @@ -79,7 +80,7 @@ export type FcmMessage = { senderId?: string; sendTime?: number; completionHandlerId?: never; -}; +} export type AndroidPermissionStatus = | 'ShouldRequest' @@ -87,6 +88,6 @@ export type AndroidPermissionStatus = | 'Granted' | 'Denied'; -export type TokenPayload = { +export interface TokenPayload { token: string; -}; +} diff --git a/packages/rtn-push-notification/src/utils/normalizeNativeMessage.ts b/packages/rtn-push-notification/src/utils/normalizeNativeMessage.ts index d3bbaf68017..940335d797f 100644 --- a/packages/rtn-push-notification/src/utils/normalizeNativeMessage.ts +++ b/packages/rtn-push-notification/src/utils/normalizeNativeMessage.ts @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import isEmpty from 'lodash/isEmpty.js'; + import { ApnsMessage, FcmMessage, @@ -26,6 +27,7 @@ export const normalizeNativeMessage = ( return null; } const { body, imageUrl, title, action, options, data } = normalized; + return { body, data, @@ -42,6 +44,7 @@ const normalizeApnsMessage = (apnsMessage: ApnsMessage): NormalizedValues => { const action = getApnsAction(data?.pinpoint) ?? {}; const imageUrl = data?.['media-url']; const options = getApnsOptions(apnsMessage); + return { body, imageUrl, title, action, options, data }; }; @@ -49,6 +52,7 @@ const normalizeFcmMessage = (fcmMessage: FcmMessage): NormalizedValues => { const { body, imageUrl, rawData: data, title } = fcmMessage; const action = getFcmAction(fcmMessage.action) ?? {}; const options = getFcmOptions(fcmMessage); + return { body, imageUrl, title, action, options, data }; }; @@ -76,6 +80,7 @@ const getApnsOptions = ({ }: ApnsMessage): Pick => { const { subtitle } = aps.alert ?? {}; const apnsOptions = { ...(subtitle && { subtitle }) }; + return { ...(!isEmpty(apnsOptions) && { apnsOptions }) }; }; @@ -91,6 +96,7 @@ const getFcmOptions = ({ senderId, sendTime: new Date(sendTime), }; + return { ...(!isEmpty(fcmOptions) && { fcmOptions }) }; };