@aws-amplify/notifications 1.0.25 → 1.0.26-unstable.1116fef.4
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/lib/InAppMessaging/InAppMessaging.d.ts +10 -8
- package/lib/InAppMessaging/InAppMessaging.js +9 -11
- package/lib/InAppMessaging/InAppMessaging.js.map +1 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.d.ts +5 -25
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js +37 -252
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/types.d.ts +0 -9
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/types.js.map +1 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/utils.js +3 -9
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/utils.js.map +1 -1
- package/lib/InAppMessaging/index.d.ts +1 -3
- package/lib/InAppMessaging/index.js +0 -2
- package/lib/InAppMessaging/index.js.map +1 -1
- package/lib/InAppMessaging/types.d.ts +30 -42
- package/lib/InAppMessaging/types.js +2 -0
- package/lib/InAppMessaging/types.js.map +1 -1
- package/lib/Notifications.d.ts +6 -2
- package/lib/Notifications.js +45 -0
- package/lib/Notifications.js.map +1 -1
- package/lib/PushNotification/NotEnabledError.d.ts +3 -0
- package/lib/PushNotification/NotEnabledError.js +16 -0
- package/lib/PushNotification/NotEnabledError.js.map +1 -0
- package/lib/PushNotification/Platform/index.d.ts +2 -0
- package/lib/PushNotification/Platform/index.js +26 -0
- package/lib/PushNotification/Platform/index.js.map +1 -0
- package/lib/PushNotification/Platform/index.native.d.ts +2 -0
- package/lib/PushNotification/Platform/index.native.js +8 -0
- package/lib/PushNotification/Platform/index.native.js.map +1 -0
- package/lib/PushNotification/Platform/types.d.ts +5 -0
- package/lib/PushNotification/Platform/types.js +5 -0
- package/lib/PushNotification/Platform/types.js.map +1 -0
- package/lib/PushNotification/PlatformNotSupportedError.d.ts +3 -0
- package/lib/PushNotification/PlatformNotSupportedError.js +16 -0
- package/lib/PushNotification/PlatformNotSupportedError.js.map +1 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/index.d.ts +15 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/index.js +115 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/index.js.map +1 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/types.d.ts +9 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/types.js +16 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/types.js.map +1 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/utils.d.ts +7 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/utils.js +58 -0
- package/lib/PushNotification/Providers/AWSPinpointProvider/utils.js.map +1 -0
- package/lib/PushNotification/Providers/index.d.ts +1 -0
- package/lib/PushNotification/Providers/index.js +7 -0
- package/lib/PushNotification/Providers/index.js.map +1 -0
- package/lib/PushNotification/PushNotification.d.ts +39 -0
- package/lib/PushNotification/PushNotification.js +91 -0
- package/lib/PushNotification/PushNotification.js.map +1 -0
- package/lib/PushNotification/PushNotification.native.d.ts +63 -0
- package/lib/PushNotification/PushNotification.native.js +327 -0
- package/lib/PushNotification/PushNotification.native.js.map +1 -0
- package/lib/PushNotification/index.d.ts +2 -0
- package/lib/PushNotification/index.js +9 -0
- package/lib/PushNotification/index.js.map +1 -0
- package/lib/PushNotification/types.d.ts +77 -0
- package/lib/PushNotification/types.js +12 -0
- package/lib/PushNotification/types.js.map +1 -0
- package/lib/PushNotification/utils.d.ts +3 -0
- package/lib/PushNotification/utils.js +81 -0
- package/lib/PushNotification/utils.js.map +1 -0
- package/lib/common/AWSPinpointProviderCommon/index.d.ts +34 -0
- package/lib/common/AWSPinpointProviderCommon/index.js +281 -0
- package/lib/common/AWSPinpointProviderCommon/index.js.map +1 -0
- package/lib/common/AWSPinpointProviderCommon/types.d.ts +9 -0
- package/lib/common/AWSPinpointProviderCommon/types.js +5 -0
- package/lib/common/AWSPinpointProviderCommon/types.js.map +1 -0
- package/lib/common/constants.d.ts +1 -0
- package/lib/common/constants.js +6 -0
- package/lib/common/constants.js.map +1 -0
- package/lib/common/eventListeners/index.d.ts +4 -0
- package/lib/common/eventListeners/index.js +55 -0
- package/lib/common/eventListeners/index.js.map +1 -0
- package/lib/common/eventListeners/types.d.ts +7 -0
- package/lib/common/eventListeners/types.js +5 -0
- package/lib/common/eventListeners/types.js.map +1 -0
- package/lib/common/index.d.ts +4 -0
- package/lib/common/index.js +13 -0
- package/lib/common/index.js.map +1 -0
- package/lib/index.d.ts +5 -2
- package/lib/index.js +4 -0
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +34 -2
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -1
- package/lib-esm/InAppMessaging/InAppMessaging.d.ts +10 -8
- package/lib-esm/InAppMessaging/InAppMessaging.js +9 -11
- package/lib-esm/InAppMessaging/InAppMessaging.js.map +1 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.d.ts +5 -25
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js +39 -254
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/types.d.ts +0 -9
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/types.js.map +1 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/utils.js +2 -8
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/utils.js.map +1 -1
- package/lib-esm/InAppMessaging/index.d.ts +1 -3
- package/lib-esm/InAppMessaging/index.js +0 -1
- package/lib-esm/InAppMessaging/index.js.map +1 -1
- package/lib-esm/InAppMessaging/types.d.ts +30 -42
- package/lib-esm/InAppMessaging/types.js +2 -0
- package/lib-esm/InAppMessaging/types.js.map +1 -1
- package/lib-esm/Notifications.d.ts +6 -2
- package/lib-esm/Notifications.js +48 -3
- package/lib-esm/Notifications.js.map +1 -1
- package/lib-esm/PushNotification/NotEnabledError.d.ts +3 -0
- package/lib-esm/PushNotification/NotEnabledError.js +14 -0
- package/lib-esm/PushNotification/NotEnabledError.js.map +1 -0
- package/lib-esm/PushNotification/Platform/index.d.ts +2 -0
- package/lib-esm/PushNotification/Platform/index.js +24 -0
- package/lib-esm/PushNotification/Platform/index.js.map +1 -0
- package/lib-esm/PushNotification/Platform/index.native.d.ts +2 -0
- package/lib-esm/PushNotification/Platform/index.native.js +6 -0
- package/lib-esm/PushNotification/Platform/index.native.js.map +1 -0
- package/lib-esm/PushNotification/Platform/types.d.ts +5 -0
- package/lib-esm/PushNotification/Platform/types.js +3 -0
- package/lib-esm/PushNotification/Platform/types.js.map +1 -0
- package/lib-esm/PushNotification/PlatformNotSupportedError.d.ts +3 -0
- package/lib-esm/PushNotification/PlatformNotSupportedError.js +14 -0
- package/lib-esm/PushNotification/PlatformNotSupportedError.js.map +1 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.d.ts +15 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.js +113 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.js.map +1 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/types.d.ts +9 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/types.js +14 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/types.js.map +1 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/utils.d.ts +7 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/utils.js +56 -0
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/utils.js.map +1 -0
- package/lib-esm/PushNotification/Providers/index.d.ts +1 -0
- package/lib-esm/PushNotification/Providers/index.js +4 -0
- package/lib-esm/PushNotification/Providers/index.js.map +1 -0
- package/lib-esm/PushNotification/PushNotification.d.ts +39 -0
- package/lib-esm/PushNotification/PushNotification.js +89 -0
- package/lib-esm/PushNotification/PushNotification.js.map +1 -0
- package/lib-esm/PushNotification/PushNotification.native.d.ts +63 -0
- package/lib-esm/PushNotification/PushNotification.native.js +325 -0
- package/lib-esm/PushNotification/PushNotification.native.js.map +1 -0
- package/lib-esm/PushNotification/index.d.ts +2 -0
- package/lib-esm/PushNotification/index.js +5 -0
- package/lib-esm/PushNotification/index.js.map +1 -0
- package/lib-esm/PushNotification/types.d.ts +77 -0
- package/lib-esm/PushNotification/types.js +10 -0
- package/lib-esm/PushNotification/types.js.map +1 -0
- package/lib-esm/PushNotification/utils.d.ts +3 -0
- package/lib-esm/PushNotification/utils.js +79 -0
- package/lib-esm/PushNotification/utils.js.map +1 -0
- package/lib-esm/common/AWSPinpointProviderCommon/index.d.ts +34 -0
- package/lib-esm/common/AWSPinpointProviderCommon/index.js +279 -0
- package/lib-esm/common/AWSPinpointProviderCommon/index.js.map +1 -0
- package/lib-esm/common/AWSPinpointProviderCommon/types.d.ts +9 -0
- package/lib-esm/common/AWSPinpointProviderCommon/types.js +3 -0
- package/lib-esm/common/AWSPinpointProviderCommon/types.js.map +1 -0
- package/lib-esm/common/constants.d.ts +1 -0
- package/lib-esm/common/constants.js +4 -0
- package/lib-esm/common/constants.js.map +1 -0
- package/lib-esm/common/eventListeners/index.d.ts +4 -0
- package/lib-esm/common/eventListeners/index.js +53 -0
- package/lib-esm/common/eventListeners/index.js.map +1 -0
- package/lib-esm/common/eventListeners/types.d.ts +7 -0
- package/lib-esm/common/eventListeners/types.js +3 -0
- package/lib-esm/common/eventListeners/types.js.map +1 -0
- package/lib-esm/common/index.d.ts +4 -0
- package/lib-esm/common/index.js +6 -0
- package/lib-esm/common/index.js.map +1 -0
- package/lib-esm/index.d.ts +5 -2
- package/lib-esm/index.js +2 -0
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/types.d.ts +34 -2
- package/lib-esm/types.js +2 -0
- package/lib-esm/types.js.map +1 -1
- package/package.json +11 -50
- package/src/InAppMessaging/InAppMessaging.ts +27 -36
- package/src/InAppMessaging/Providers/AWSPinpointProvider/index.ts +45 -245
- package/src/InAppMessaging/Providers/AWSPinpointProvider/types.ts +0 -12
- package/src/InAppMessaging/Providers/AWSPinpointProvider/utils.ts +3 -12
- package/src/InAppMessaging/index.ts +0 -3
- package/src/InAppMessaging/types.ts +52 -56
- package/src/Notifications.ts +42 -4
- package/src/PushNotification/NotEnabledError.ts +11 -0
- package/src/PushNotification/Platform/index.native.ts +9 -0
- package/src/PushNotification/Platform/index.ts +22 -0
- package/src/PushNotification/Platform/types.ts +15 -0
- package/src/PushNotification/PlatformNotSupportedError.ts +9 -0
- package/src/PushNotification/Providers/AWSPinpointProvider/index.ts +137 -0
- package/src/PushNotification/Providers/AWSPinpointProvider/types.ts +13 -0
- package/src/PushNotification/Providers/AWSPinpointProvider/utils.ts +79 -0
- package/src/PushNotification/Providers/index.ts +4 -0
- package/src/PushNotification/PushNotification.native.ts +381 -0
- package/src/PushNotification/PushNotification.ts +107 -0
- package/src/PushNotification/index.ts +9 -0
- package/src/PushNotification/types.ts +114 -0
- package/src/PushNotification/utils.ts +112 -0
- package/src/common/AWSPinpointProviderCommon/index.ts +295 -0
- package/src/common/AWSPinpointProviderCommon/types.ts +14 -0
- package/src/common/constants.ts +5 -0
- package/src/common/eventListeners/index.ts +44 -0
- package/src/common/eventListeners/types.ts +12 -0
- package/src/common/index.ts +11 -0
- package/src/index.ts +9 -3
- package/src/types.ts +47 -2
- package/CHANGELOG.md +0 -215
- package/lib/InAppMessaging/eventListeners.d.ts +0 -3
- package/lib/InAppMessaging/eventListeners.js +0 -28
- package/lib/InAppMessaging/eventListeners.js.map +0 -1
- package/lib-esm/InAppMessaging/eventListeners.d.ts +0 -3
- package/lib-esm/InAppMessaging/eventListeners.js +0 -26
- package/lib-esm/InAppMessaging/eventListeners.js.map +0 -1
- package/src/InAppMessaging/eventListeners.ts +0 -42
|
@@ -1,58 +1,51 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { NotificationsCategory } from '../types';
|
|
4
|
-
import { AWSPinpointProviderConfig } from './Providers/AWSPinpointProvider/types';
|
|
5
|
-
|
|
6
|
-
export type NotificationsSubcategory = 'InAppMessaging';
|
|
7
|
-
|
|
8
|
-
export type UserInfo = {
|
|
9
|
-
attributes?: Record<string, string[]>;
|
|
10
|
-
demographic?: {
|
|
11
|
-
appVersion?: string;
|
|
12
|
-
locale?: string;
|
|
13
|
-
make?: string;
|
|
14
|
-
model?: string;
|
|
15
|
-
modelVersion?: string;
|
|
16
|
-
platform?: string;
|
|
17
|
-
platformVersion?: string;
|
|
18
|
-
timezone?: string;
|
|
19
|
-
};
|
|
20
|
-
location?: {
|
|
21
|
-
city?: string;
|
|
22
|
-
country?: string;
|
|
23
|
-
latitude?: number;
|
|
24
|
-
longitude?: number;
|
|
25
|
-
postalCode?: string;
|
|
26
|
-
region?: string;
|
|
27
|
-
};
|
|
28
|
-
metrics?: Record<string, number>;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export type InAppMessagingEvent = {
|
|
32
|
-
name: string;
|
|
33
|
-
attributes?: Record<string, string>;
|
|
34
|
-
metrics?: Record<string, number>;
|
|
35
|
-
};
|
|
36
3
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
4
|
+
import { EventListener } from '../common';
|
|
5
|
+
import { AWSPinpointProviderConfig } from '../common/AWSPinpointProviderCommon/types';
|
|
6
|
+
import {
|
|
7
|
+
NotificationsProvider,
|
|
8
|
+
NotificationsSubCategory as NotificationsSubCategories,
|
|
9
|
+
UserInfo,
|
|
10
|
+
} from '../types';
|
|
11
|
+
|
|
12
|
+
export type NotificationsSubCategory = Extract<
|
|
13
|
+
NotificationsSubCategories,
|
|
14
|
+
'InAppMessaging'
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export interface InAppMessagingInterface {
|
|
18
|
+
configure: (config: InAppMessagingConfig) => InAppMessagingConfig;
|
|
19
|
+
getModuleName: () => NotificationsSubCategory;
|
|
20
|
+
getPluggable: (providerName: string) => InAppMessagingProvider;
|
|
21
|
+
addPluggable: (pluggable: InAppMessagingProvider) => void;
|
|
22
|
+
removePluggable: (providerName: string) => void;
|
|
23
|
+
syncMessages: () => Promise<void[]>;
|
|
24
|
+
clearMessages: () => Promise<void[]>;
|
|
25
|
+
dispatchEvent: (event: InAppMessagingEvent) => Promise<void>;
|
|
26
|
+
identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
|
|
27
|
+
onMessageReceived: (
|
|
28
|
+
handler: OnMessageInteractionEventHandler
|
|
29
|
+
) => EventListener<OnMessageInteractionEventHandler>;
|
|
30
|
+
onMessageDisplayed: (
|
|
31
|
+
handler: OnMessageInteractionEventHandler
|
|
32
|
+
) => EventListener<OnMessageInteractionEventHandler>;
|
|
33
|
+
onMessageDismissed: (
|
|
34
|
+
handler: OnMessageInteractionEventHandler
|
|
35
|
+
) => EventListener<OnMessageInteractionEventHandler>;
|
|
36
|
+
onMessageActionTaken: (
|
|
37
|
+
handler: OnMessageInteractionEventHandler
|
|
38
|
+
) => EventListener<OnMessageInteractionEventHandler>;
|
|
39
|
+
notifyMessageInteraction: (
|
|
40
|
+
message: InAppMessage,
|
|
41
|
+
type: InAppMessageInteractionEvent
|
|
42
|
+
) => void;
|
|
43
|
+
setConflictHandler: (handler: InAppMessageConflictHandler) => void;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
export interface InAppMessagingProvider {
|
|
43
|
-
// you need to implement these methods
|
|
44
|
-
|
|
45
|
-
// configure your provider
|
|
46
|
-
configure(config: object): object;
|
|
47
|
-
|
|
48
|
-
// return category ('Notifications')
|
|
49
|
-
getCategory(): NotificationsCategory;
|
|
50
|
-
|
|
46
|
+
export interface InAppMessagingProvider extends NotificationsProvider {
|
|
51
47
|
// return sub-category ('InAppMessaging')
|
|
52
|
-
getSubCategory():
|
|
53
|
-
|
|
54
|
-
// return the name of you provider
|
|
55
|
-
getProviderName(): string;
|
|
48
|
+
getSubCategory(): NotificationsSubCategory;
|
|
56
49
|
|
|
57
50
|
// get in-app messages from provider
|
|
58
51
|
getInAppMessages(): Promise<any>;
|
|
@@ -62,11 +55,19 @@ export interface InAppMessagingProvider {
|
|
|
62
55
|
messages: InAppMessage[],
|
|
63
56
|
event: InAppMessagingEvent
|
|
64
57
|
): Promise<InAppMessage[]>;
|
|
58
|
+
}
|
|
65
59
|
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
export interface InAppMessagingConfig {
|
|
61
|
+
listenForAnalyticsEvents?: boolean;
|
|
62
|
+
AWSPinpoint?: AWSPinpointProviderConfig;
|
|
68
63
|
}
|
|
69
64
|
|
|
65
|
+
export type InAppMessagingEvent = {
|
|
66
|
+
name: string;
|
|
67
|
+
attributes?: Record<string, string>;
|
|
68
|
+
metrics?: Record<string, number>;
|
|
69
|
+
};
|
|
70
|
+
|
|
70
71
|
export type InAppMessageLayout =
|
|
71
72
|
| 'BOTTOM_BANNER'
|
|
72
73
|
| 'CAROUSEL'
|
|
@@ -129,11 +130,6 @@ export interface InAppMessage {
|
|
|
129
130
|
|
|
130
131
|
export type OnMessageInteractionEventHandler = (message: InAppMessage) => any;
|
|
131
132
|
|
|
132
|
-
export interface OnMessageInteractionEventListener {
|
|
133
|
-
handleEvent: OnMessageInteractionEventHandler;
|
|
134
|
-
remove: () => void;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
133
|
export enum InAppMessageInteractionEvent {
|
|
138
134
|
MESSAGE_RECEIVED = 'MESSAGE_RECEIVED_EVENT',
|
|
139
135
|
MESSAGE_DISPLAYED = 'MESSAGE_DISPLAYED_EVENT',
|
package/src/Notifications.ts
CHANGED
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { Amplify, ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
5
|
-
|
|
6
|
-
import
|
|
5
|
+
|
|
6
|
+
import InAppMessagingClass from './InAppMessaging';
|
|
7
|
+
import { InAppMessagingInterface as InAppMessaging } from './InAppMessaging/types';
|
|
8
|
+
import { PushNotificationInterface as PushNotification } from './PushNotification/types';
|
|
9
|
+
import { NotificationsCategory, NotificationsConfig, UserInfo } from './types';
|
|
7
10
|
|
|
8
11
|
const logger = new Logger('Notifications');
|
|
9
12
|
|
|
10
13
|
class NotificationsClass {
|
|
11
14
|
private config: Record<string, any> = {};
|
|
12
15
|
private inAppMessaging: InAppMessaging;
|
|
16
|
+
private pushNotification?: PushNotification;
|
|
13
17
|
|
|
14
18
|
constructor() {
|
|
15
|
-
this.inAppMessaging = new
|
|
19
|
+
this.inAppMessaging = new InAppMessagingClass();
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -35,12 +39,46 @@ class NotificationsClass {
|
|
|
35
39
|
// Configure sub-categories
|
|
36
40
|
this.inAppMessaging.configure(this.config.InAppMessaging);
|
|
37
41
|
|
|
42
|
+
if (this.config.Push) {
|
|
43
|
+
try {
|
|
44
|
+
const PushNotification = require('./PushNotification').default;
|
|
45
|
+
this.pushNotification = new PushNotification();
|
|
46
|
+
this.pushNotification.configure(this.config.Push);
|
|
47
|
+
} catch (err) {
|
|
48
|
+
logger.error(err);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
38
52
|
return this.config;
|
|
39
53
|
};
|
|
40
54
|
|
|
41
|
-
get InAppMessaging() {
|
|
55
|
+
get InAppMessaging(): InAppMessaging {
|
|
42
56
|
return this.inAppMessaging;
|
|
43
57
|
}
|
|
58
|
+
|
|
59
|
+
get Push(): PushNotification {
|
|
60
|
+
return this.pushNotification ?? ({} as PushNotification);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
identifyUser = (userId: string, userInfo: UserInfo): Promise<void[]> => {
|
|
64
|
+
const identifyFunctions: Function[] = [];
|
|
65
|
+
if (this.inAppMessaging) {
|
|
66
|
+
identifyFunctions.push(this.inAppMessaging.identifyUser);
|
|
67
|
+
}
|
|
68
|
+
if (this.pushNotification) {
|
|
69
|
+
identifyFunctions.push(this.pushNotification.identifyUser);
|
|
70
|
+
}
|
|
71
|
+
return Promise.all<void>(
|
|
72
|
+
identifyFunctions.map(async identifyFunction => {
|
|
73
|
+
try {
|
|
74
|
+
await identifyFunction(userId, userInfo);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
logger.error('Failed to identify user', err);
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
};
|
|
44
82
|
}
|
|
45
83
|
|
|
46
84
|
const Notifications = new NotificationsClass();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export default class NotEnabledError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(
|
|
7
|
+
'Function is unavailable as Push has not been enabled. Please call `Push.enable` before calling this function.'
|
|
8
|
+
);
|
|
9
|
+
this.name = 'NotEnabledError';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Platform as NativePlatform } from 'react-native';
|
|
5
|
+
import { Platform as PlatformInterface } from './types';
|
|
6
|
+
|
|
7
|
+
const { OS } = NativePlatform;
|
|
8
|
+
|
|
9
|
+
export const Platform: PlatformInterface = { OS };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Platform as PlatformInterface } from './types';
|
|
5
|
+
|
|
6
|
+
const userAgentIncludes = (text: string): boolean => {
|
|
7
|
+
return navigator?.userAgent?.includes(text);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const getOS = (): PlatformInterface['OS'] => {
|
|
11
|
+
if (userAgentIncludes('Android')) return 'android';
|
|
12
|
+
if (userAgentIncludes('like Mac')) return 'ios';
|
|
13
|
+
if (userAgentIncludes('Win')) return 'windows';
|
|
14
|
+
if (userAgentIncludes('Mac')) return 'macos';
|
|
15
|
+
if (userAgentIncludes('Linux')) return 'linux';
|
|
16
|
+
if (userAgentIncludes('X11')) return 'unix';
|
|
17
|
+
return 'unknown';
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const OS = getOS();
|
|
21
|
+
|
|
22
|
+
export const Platform: PlatformInterface = { OS };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export interface Platform {
|
|
5
|
+
OS: KnownOS | 'unknown';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type KnownOS =
|
|
9
|
+
| 'windows'
|
|
10
|
+
| 'macos'
|
|
11
|
+
| 'unix'
|
|
12
|
+
| 'linux'
|
|
13
|
+
| 'ios'
|
|
14
|
+
| 'android'
|
|
15
|
+
| 'web';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export default class PlatformNotSupportedError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super('Function not supported on current platform');
|
|
7
|
+
this.name = 'PlatformNotSupportedError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ChannelType } from '@aws-sdk/client-pinpoint';
|
|
5
|
+
import { addEventListener, AWSPinpointProviderCommon } from '../../../common';
|
|
6
|
+
import PlatformNotSupportedError from '../../PlatformNotSupportedError';
|
|
7
|
+
import { Platform } from '../../Platform';
|
|
8
|
+
import {
|
|
9
|
+
PushNotificationEvent,
|
|
10
|
+
PushNotificationMessage,
|
|
11
|
+
PushNotificationProvider,
|
|
12
|
+
NotificationsSubCategory,
|
|
13
|
+
} from '../../types';
|
|
14
|
+
import { AWSPinpointMessageEvent } from './types';
|
|
15
|
+
import {
|
|
16
|
+
dispatchPushNotificationEvent,
|
|
17
|
+
getAnalyticsEvent,
|
|
18
|
+
logger,
|
|
19
|
+
} from './utils';
|
|
20
|
+
|
|
21
|
+
export default class AWSPinpointProvider
|
|
22
|
+
extends AWSPinpointProviderCommon
|
|
23
|
+
implements PushNotificationProvider
|
|
24
|
+
{
|
|
25
|
+
static subCategory: NotificationsSubCategory = 'PushNotification';
|
|
26
|
+
|
|
27
|
+
private configured = false;
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super(logger);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* get the sub-category of the plugin
|
|
35
|
+
*/
|
|
36
|
+
getSubCategory() {
|
|
37
|
+
return AWSPinpointProvider.subCategory;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
configure = (config = {}): Record<string, any> => {
|
|
41
|
+
this.config = {
|
|
42
|
+
...super.configure(config),
|
|
43
|
+
endpointInfo: { channelType: this.getChannelType() },
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// some configuration steps should not be re-run even if provider is re-configured for some reason
|
|
47
|
+
if (!this.configured) {
|
|
48
|
+
// wire up default Pinpoint message event handling
|
|
49
|
+
addEventListener(
|
|
50
|
+
PushNotificationEvent.BACKGROUND_MESSAGE_RECEIVED,
|
|
51
|
+
message =>
|
|
52
|
+
this.recordMessageEvent(
|
|
53
|
+
message,
|
|
54
|
+
AWSPinpointMessageEvent.BACKGROUND_MESSAGE_RECEIVED
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
addEventListener(
|
|
58
|
+
PushNotificationEvent.FOREGROUND_MESSAGE_RECEIVED,
|
|
59
|
+
message =>
|
|
60
|
+
this.recordMessageEvent(
|
|
61
|
+
message,
|
|
62
|
+
AWSPinpointMessageEvent.FOREGROUND_MESSAGE_RECEIVED
|
|
63
|
+
)
|
|
64
|
+
);
|
|
65
|
+
const launchNotificationOpenedListener = addEventListener(
|
|
66
|
+
PushNotificationEvent.LAUNCH_NOTIFICATION_OPENED,
|
|
67
|
+
message => {
|
|
68
|
+
this.recordMessageEvent(
|
|
69
|
+
message,
|
|
70
|
+
AWSPinpointMessageEvent.NOTIFICATION_OPENED
|
|
71
|
+
);
|
|
72
|
+
// once we are done with it we can remove the listener
|
|
73
|
+
launchNotificationOpenedListener?.remove();
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
addEventListener(PushNotificationEvent.NOTIFICATION_OPENED, message => {
|
|
77
|
+
this.recordMessageEvent(
|
|
78
|
+
message,
|
|
79
|
+
AWSPinpointMessageEvent.NOTIFICATION_OPENED
|
|
80
|
+
);
|
|
81
|
+
// if we are in this state, we no longer need the listener as the app was launched via some other means
|
|
82
|
+
launchNotificationOpenedListener?.remove();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
this.configured = true;
|
|
87
|
+
dispatchPushNotificationEvent('pinpointProvider_configured', null);
|
|
88
|
+
return this.config;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
registerDevice = async (address: string): Promise<void> => {
|
|
92
|
+
if (!this.initialized) {
|
|
93
|
+
await this.init();
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
this.config.endpointInfo = {
|
|
97
|
+
...this.config.endpointInfo,
|
|
98
|
+
address,
|
|
99
|
+
};
|
|
100
|
+
await this.updateEndpoint();
|
|
101
|
+
} catch (err) {
|
|
102
|
+
this.logger.error('Error registering device', err);
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
private getChannelType = (): ChannelType => {
|
|
108
|
+
switch (Platform.OS) {
|
|
109
|
+
case 'android': {
|
|
110
|
+
// FCM was previously known as GCM and continues to be the channel type in Pinpoint
|
|
111
|
+
return ChannelType.GCM;
|
|
112
|
+
}
|
|
113
|
+
case 'ios': {
|
|
114
|
+
// If building in debug mode, use the APNs sandbox
|
|
115
|
+
return global['__DEV__'] ? ChannelType.APNS_SANDBOX : ChannelType.APNS;
|
|
116
|
+
}
|
|
117
|
+
default: {
|
|
118
|
+
throw new PlatformNotSupportedError();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
private recordMessageEvent = async (
|
|
124
|
+
message: PushNotificationMessage,
|
|
125
|
+
event: AWSPinpointMessageEvent
|
|
126
|
+
): Promise<void> => {
|
|
127
|
+
const analyticsEvent = getAnalyticsEvent(message, event);
|
|
128
|
+
if (!analyticsEvent) {
|
|
129
|
+
logger.debug('A notification missing event information was not recorded');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!this.initialized) {
|
|
133
|
+
await this.init();
|
|
134
|
+
}
|
|
135
|
+
return this.recordAnalyticsEvent(analyticsEvent);
|
|
136
|
+
};
|
|
137
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export enum AWSPinpointMessageEventSource {
|
|
5
|
+
CAMPAIGN = '_campaign',
|
|
6
|
+
JOURNEY = '_journey',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export enum AWSPinpointMessageEvent {
|
|
10
|
+
NOTIFICATION_OPENED = 'opened_notification',
|
|
11
|
+
BACKGROUND_MESSAGE_RECEIVED = 'received_background',
|
|
12
|
+
FOREGROUND_MESSAGE_RECEIVED = 'received_foreground',
|
|
13
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Event as AWSPinpointAnalyticsEvent } from '@aws-sdk/client-pinpoint';
|
|
5
|
+
import { ConsoleLogger, Hub } from '@aws-amplify/core';
|
|
6
|
+
import { AMPLIFY_SYMBOL } from '../../../common';
|
|
7
|
+
import { PushNotificationMessage } from '../../types';
|
|
8
|
+
import {
|
|
9
|
+
AWSPinpointMessageEventSource,
|
|
10
|
+
AWSPinpointMessageEvent,
|
|
11
|
+
} from './types';
|
|
12
|
+
|
|
13
|
+
const ANDROID_CAMPAIGN_ACTIVITY_ID_KEY =
|
|
14
|
+
'pinpoint.campaign.campaign_activity_id';
|
|
15
|
+
const ANDROID_CAMPAIGN_ID_KEY = 'pinpoint.campaign.campaign_id';
|
|
16
|
+
const ANDROID_CAMPAIGN_TREATMENT_ID_KEY = 'pinpoint.campaign.treatment_id';
|
|
17
|
+
|
|
18
|
+
export const logger = new ConsoleLogger('PushNotification.AWSPinpointProvider');
|
|
19
|
+
|
|
20
|
+
export const dispatchPushNotificationEvent = (
|
|
21
|
+
event: string,
|
|
22
|
+
data: any,
|
|
23
|
+
message?: string
|
|
24
|
+
) => {
|
|
25
|
+
Hub.dispatch(
|
|
26
|
+
'pushNotification',
|
|
27
|
+
{ event, data, message },
|
|
28
|
+
'PushNotification',
|
|
29
|
+
AMPLIFY_SYMBOL
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getAnalyticsEvent = (
|
|
34
|
+
{ data }: PushNotificationMessage,
|
|
35
|
+
event: AWSPinpointMessageEvent
|
|
36
|
+
): AWSPinpointAnalyticsEvent | null => {
|
|
37
|
+
if (!data) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const eventAttributes = getAnalyticsEventAttributes(data);
|
|
41
|
+
if (!eventAttributes) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const { source, attributes } = eventAttributes;
|
|
45
|
+
return {
|
|
46
|
+
Attributes: attributes,
|
|
47
|
+
EventType: `${source}.${event}`,
|
|
48
|
+
Timestamp: new Date().toISOString(),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getAnalyticsEventAttributes = (data: PushNotificationMessage['data']) => {
|
|
53
|
+
if (data.hasOwnProperty(ANDROID_CAMPAIGN_ID_KEY)) {
|
|
54
|
+
return {
|
|
55
|
+
source: AWSPinpointMessageEventSource.CAMPAIGN,
|
|
56
|
+
attributes: {
|
|
57
|
+
campaign_activity_id: data[ANDROID_CAMPAIGN_ACTIVITY_ID_KEY],
|
|
58
|
+
campaign_id: data[ANDROID_CAMPAIGN_ID_KEY],
|
|
59
|
+
treatment_id: data[ANDROID_CAMPAIGN_TREATMENT_ID_KEY],
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const pinpoint =
|
|
64
|
+
typeof data.pinpoint === 'string'
|
|
65
|
+
? JSON.parse(data.pinpoint)
|
|
66
|
+
: data.pinpoint;
|
|
67
|
+
if (pinpoint?.campaign) {
|
|
68
|
+
return {
|
|
69
|
+
source: AWSPinpointMessageEventSource.CAMPAIGN,
|
|
70
|
+
attributes: pinpoint.campaign,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (pinpoint?.journey) {
|
|
74
|
+
return {
|
|
75
|
+
source: AWSPinpointMessageEventSource.JOURNEY,
|
|
76
|
+
attributes: pinpoint.journey,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|