-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
types.ts
115 lines (100 loc) · 3.3 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { EventListener } from '../common';
import { AWSPinpointProviderConfig } from '../common/AWSPinpointProviderCommon/types';
import {
NotificationsProvider,
NotificationsSubCategory as NotificationsSubCategories,
UserInfo,
} from '../types';
export type NotificationsSubCategory = Extract<
NotificationsSubCategories,
'PushNotification'
>;
export interface PushNotificationInterface {
configure: (config: PushNotificationConfig) => PushNotificationConfig;
getModuleName: () => NotificationsSubCategory;
getPluggable: (providerName: string) => PushNotificationProvider;
addPluggable: (pluggable: PushNotificationProvider) => void;
removePluggable: (providerName: string) => void;
enable: () => void;
identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
getLaunchNotification: () => Promise<PushNotificationMessage>;
getBadgeCount: () => Promise<number>;
setBadgeCount: (count: number) => void;
getPermissionStatus: () => Promise<PushNotificationPermissionStatus>;
requestPermissions: (
permissions?: PushNotificationPermissions
) => Promise<boolean>;
onNotificationReceivedInBackground: (
handler: OnPushNotificationMessageHandler
) => EventListener<OnPushNotificationMessageHandler>;
onNotificationReceivedInForeground: (
handler: OnPushNotificationMessageHandler
) => EventListener<OnPushNotificationMessageHandler>;
onNotificationOpened: (
handler: OnPushNotificationMessageHandler
) => EventListener<OnPushNotificationMessageHandler>;
onTokenReceived: (
handler: OnTokenReceivedHandler
) => EventListener<OnTokenReceivedHandler>;
}
export interface PushNotificationProvider extends NotificationsProvider {
// return sub-category ('PushNotification')
getSubCategory(): NotificationsSubCategory;
// register device with provider
registerDevice(token: string): Promise<void>;
}
export interface PushNotificationConfig {
AWSPinpoint?: AWSPinpointProviderConfig;
}
export interface PushNotificationMessage {
title?: string;
body?: string;
imageUrl?: string;
deeplinkUrl?: string;
goToUrl?: string;
fcmOptions?: FcmPlatformOptions;
apnsOptions?: ApnsPlatformOptions;
data?: Record<string, unknown>;
}
interface FcmPlatformOptions {
channelId: string;
messageId: string;
senderId: string;
sendTime: Date;
}
interface ApnsPlatformOptions {
subtitle?: string;
}
export interface PushNotificationPermissions
extends Partial<Record<string, boolean>> {
alert?: boolean;
badge?: boolean;
sound?: boolean;
}
export enum PushNotificationPermissionStatus {
DENIED = 'DENIED',
GRANTED = 'GRANTED',
SHOULD_REQUEST = 'SHOULD_REQUEST',
SHOULD_EXPLAIN_THEN_REQUEST = 'SHOULD_EXPLAIN_THEN_REQUEST',
}
export type OnTokenReceivedHandler = (token: string) => any;
export type OnPushNotificationMessageHandler = (
message: PushNotificationMessage
) => any;
export const enum PushNotificationEvent {
BACKGROUND_MESSAGE_RECEIVED,
FOREGROUND_MESSAGE_RECEIVED,
LAUNCH_NOTIFICATION_OPENED,
NOTIFICATION_OPENED,
TOKEN_RECEIVED,
}
export interface NormalizedValues {
body?: string;
imageUrl?: string;
title?: string;
action?: Pick<PushNotificationMessage, 'goToUrl' | 'deeplinkUrl'>;
options?: Pick<PushNotificationMessage, 'apnsOptions' | 'fcmOptions'>;
data?: Record<string, unknown>;
}