Skip to content

Commit

Permalink
chore(rtn-push-notification): run yarn lint:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Mar 4, 2024
1 parent ef7c71f commit b25dc69
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { EmitterSubscription } from 'react-native';

import { nativeEventEmitter } from '../nativeModule';
import { TokenPayload } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
): void => {
Expand Down
1 change: 1 addition & 0 deletions packages/rtn-push-notification/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
requestPermissions,
setBadgeCount,
} from './apis';

export {
PushNotificationMessage,
PushNotificationPermissionStatus,
Expand Down
3 changes: 2 additions & 1 deletion packages/rtn-push-notification/src/nativeModule.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
33 changes: 17 additions & 16 deletions packages/rtn-push-notification/src/types/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,19 +17,19 @@ export interface PushNotificationNativeModule extends NativeModule {
};
NativeHeadlessTaskKey?: string;
};
getLaunchNotification: () => Promise<NativeMessage | null>;
getBadgeCount?: () => Promise<number>;
setBadgeCount?: (count: number) => void;
getPermissionStatus: () => Promise<NativePermissionStatus>;
requestPermissions: (
getLaunchNotification(): Promise<NativeMessage | null>;
getBadgeCount?(): Promise<number>;
setBadgeCount?(count: number): void;
getPermissionStatus(): Promise<NativePermissionStatus>;
requestPermissions(
permissions: PushNotificationPermissions,
) => Promise<boolean>;
): Promise<boolean>;
}

export type NativeAction = {
export interface NativeAction {
deeplink?: string;
url?: string;
};
}

export type NativeMessage = (ApnsMessage | FcmMessage) & {
token?: never;
Expand All @@ -48,7 +49,7 @@ export interface NormalizedValues {
}

// iOS
export type ApnsMessage = {
export interface ApnsMessage {
aps: {
alert?: {
body?: string;
Expand All @@ -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;
Expand All @@ -79,14 +80,14 @@ export type FcmMessage = {
senderId?: string;
sendTime?: number;
completionHandlerId?: never;
};
}

export type AndroidPermissionStatus =
| 'ShouldRequest'
| 'ShouldExplainThenRequest'
| 'Granted'
| 'Denied';

export type TokenPayload = {
export interface TokenPayload {
token: string;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import isEmpty from 'lodash/isEmpty.js';

import {
ApnsMessage,
FcmMessage,
Expand All @@ -26,6 +27,7 @@ export const normalizeNativeMessage = (
return null;
}
const { body, imageUrl, title, action, options, data } = normalized;

return {
body,
data,
Expand All @@ -42,13 +44,15 @@ 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 };
};

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 };
};

Expand Down Expand Up @@ -76,6 +80,7 @@ const getApnsOptions = ({
}: ApnsMessage): Pick<PushNotificationMessage, 'apnsOptions'> => {
const { subtitle } = aps.alert ?? {};
const apnsOptions = { ...(subtitle && { subtitle }) };

return { ...(!isEmpty(apnsOptions) && { apnsOptions }) };
};

Expand All @@ -91,6 +96,7 @@ const getFcmOptions = ({
senderId,
sendTime: new Date(sendTime),
};

return { ...(!isEmpty(fcmOptions) && { fcmOptions }) };
};

Expand Down

0 comments on commit b25dc69

Please sign in to comment.