@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
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare enum AWSPinpointMessageEventSource {
|
|
2
|
+
CAMPAIGN = "_campaign",
|
|
3
|
+
JOURNEY = "_journey"
|
|
4
|
+
}
|
|
5
|
+
export declare enum AWSPinpointMessageEvent {
|
|
6
|
+
NOTIFICATION_OPENED = "opened_notification",
|
|
7
|
+
BACKGROUND_MESSAGE_RECEIVED = "received_background",
|
|
8
|
+
FOREGROUND_MESSAGE_RECEIVED = "received_foreground"
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var AWSPinpointMessageEventSource;
|
|
6
|
+
(function (AWSPinpointMessageEventSource) {
|
|
7
|
+
AWSPinpointMessageEventSource["CAMPAIGN"] = "_campaign";
|
|
8
|
+
AWSPinpointMessageEventSource["JOURNEY"] = "_journey";
|
|
9
|
+
})(AWSPinpointMessageEventSource = exports.AWSPinpointMessageEventSource || (exports.AWSPinpointMessageEventSource = {}));
|
|
10
|
+
var AWSPinpointMessageEvent;
|
|
11
|
+
(function (AWSPinpointMessageEvent) {
|
|
12
|
+
AWSPinpointMessageEvent["NOTIFICATION_OPENED"] = "opened_notification";
|
|
13
|
+
AWSPinpointMessageEvent["BACKGROUND_MESSAGE_RECEIVED"] = "received_background";
|
|
14
|
+
AWSPinpointMessageEvent["FOREGROUND_MESSAGE_RECEIVED"] = "received_foreground";
|
|
15
|
+
})(AWSPinpointMessageEvent = exports.AWSPinpointMessageEvent || (exports.AWSPinpointMessageEvent = {}));
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/PushNotification/Providers/AWSPinpointProvider/types.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,IAAY,6BAGX;AAHD,WAAY,6BAA6B;IACxC,uDAAsB,CAAA;IACtB,qDAAoB,CAAA;AACrB,CAAC,EAHW,6BAA6B,GAA7B,qCAA6B,KAA7B,qCAA6B,QAGxC;AAED,IAAY,uBAIX;AAJD,WAAY,uBAAuB;IAClC,sEAA2C,CAAA;IAC3C,8EAAmD,CAAA;IACnD,8EAAmD,CAAA;AACpD,CAAC,EAJW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAIlC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Event as AWSPinpointAnalyticsEvent } from '@aws-sdk/client-pinpoint';
|
|
2
|
+
import { ConsoleLogger } from '@aws-amplify/core';
|
|
3
|
+
import { PushNotificationMessage } from '../../types';
|
|
4
|
+
import { AWSPinpointMessageEvent } from './types';
|
|
5
|
+
export declare const logger: ConsoleLogger;
|
|
6
|
+
export declare const dispatchPushNotificationEvent: (event: string, data: any, message?: string) => void;
|
|
7
|
+
export declare const getAnalyticsEvent: ({ data }: PushNotificationMessage, event: AWSPinpointMessageEvent) => AWSPinpointAnalyticsEvent;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var core_1 = require("@aws-amplify/core");
|
|
6
|
+
var common_1 = require("../../../common");
|
|
7
|
+
var types_1 = require("./types");
|
|
8
|
+
var ANDROID_CAMPAIGN_ACTIVITY_ID_KEY = 'pinpoint.campaign.campaign_activity_id';
|
|
9
|
+
var ANDROID_CAMPAIGN_ID_KEY = 'pinpoint.campaign.campaign_id';
|
|
10
|
+
var ANDROID_CAMPAIGN_TREATMENT_ID_KEY = 'pinpoint.campaign.treatment_id';
|
|
11
|
+
exports.logger = new core_1.ConsoleLogger('PushNotification.AWSPinpointProvider');
|
|
12
|
+
exports.dispatchPushNotificationEvent = function (event, data, message) {
|
|
13
|
+
core_1.Hub.dispatch('pushNotification', { event: event, data: data, message: message }, 'PushNotification', common_1.AMPLIFY_SYMBOL);
|
|
14
|
+
};
|
|
15
|
+
exports.getAnalyticsEvent = function (_a, event) {
|
|
16
|
+
var data = _a.data;
|
|
17
|
+
if (!data) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
var eventAttributes = getAnalyticsEventAttributes(data);
|
|
21
|
+
if (!eventAttributes) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
var source = eventAttributes.source, attributes = eventAttributes.attributes;
|
|
25
|
+
return {
|
|
26
|
+
Attributes: attributes,
|
|
27
|
+
EventType: source + "." + event,
|
|
28
|
+
Timestamp: new Date().toISOString(),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
var getAnalyticsEventAttributes = function (data) {
|
|
32
|
+
if (data.hasOwnProperty(ANDROID_CAMPAIGN_ID_KEY)) {
|
|
33
|
+
return {
|
|
34
|
+
source: types_1.AWSPinpointMessageEventSource.CAMPAIGN,
|
|
35
|
+
attributes: {
|
|
36
|
+
campaign_activity_id: data[ANDROID_CAMPAIGN_ACTIVITY_ID_KEY],
|
|
37
|
+
campaign_id: data[ANDROID_CAMPAIGN_ID_KEY],
|
|
38
|
+
treatment_id: data[ANDROID_CAMPAIGN_TREATMENT_ID_KEY],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
var pinpoint = typeof data.pinpoint === 'string'
|
|
43
|
+
? JSON.parse(data.pinpoint)
|
|
44
|
+
: data.pinpoint;
|
|
45
|
+
if (pinpoint === null || pinpoint === void 0 ? void 0 : pinpoint.campaign) {
|
|
46
|
+
return {
|
|
47
|
+
source: types_1.AWSPinpointMessageEventSource.CAMPAIGN,
|
|
48
|
+
attributes: pinpoint.campaign,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (pinpoint === null || pinpoint === void 0 ? void 0 : pinpoint.journey) {
|
|
52
|
+
return {
|
|
53
|
+
source: types_1.AWSPinpointMessageEventSource.JOURNEY,
|
|
54
|
+
attributes: pinpoint.journey,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/PushNotification/Providers/AWSPinpointProvider/utils.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAGtC,0CAAuD;AACvD,0CAAiD;AAEjD,iCAGiB;AAEjB,IAAM,gCAAgC,GACrC,wCAAwC,CAAC;AAC1C,IAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAChE,IAAM,iCAAiC,GAAG,gCAAgC,CAAC;AAE9D,QAAA,MAAM,GAAG,IAAI,oBAAa,CAAC,sCAAsC,CAAC,CAAC;AAEnE,QAAA,6BAA6B,GAAG,UAC5C,KAAa,EACb,IAAS,EACT,OAAgB;IAEhB,UAAG,CAAC,QAAQ,CACX,kBAAkB,EAClB,EAAE,KAAK,OAAA,EAAE,IAAI,MAAA,EAAE,OAAO,SAAA,EAAE,EACxB,kBAAkB,EAClB,uBAAc,CACd,CAAC;AACH,CAAC,CAAC;AAEW,QAAA,iBAAiB,GAAG,UAChC,EAAiC,EACjC,KAA8B;QAD5B,cAAI;IAGN,IAAI,CAAC,IAAI,EAAE;QACV,OAAO,IAAI,CAAC;KACZ;IACD,IAAM,eAAe,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;IAC1D,IAAI,CAAC,eAAe,EAAE;QACrB,OAAO,IAAI,CAAC;KACZ;IACO,IAAA,+BAAM,EAAE,uCAAU,CAAqB;IAC/C,OAAO;QACN,UAAU,EAAE,UAAU;QACtB,SAAS,EAAK,MAAM,SAAI,KAAO;QAC/B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACnC,CAAC;AACH,CAAC,CAAC;AAEF,IAAM,2BAA2B,GAAG,UAAC,IAAqC;IACzE,IAAI,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE;QACjD,OAAO;YACN,MAAM,EAAE,qCAA6B,CAAC,QAAQ;YAC9C,UAAU,EAAE;gBACX,oBAAoB,EAAE,IAAI,CAAC,gCAAgC,CAAC;gBAC5D,WAAW,EAAE,IAAI,CAAC,uBAAuB,CAAC;gBAC1C,YAAY,EAAE,IAAI,CAAC,iCAAiC,CAAC;aACrD;SACD,CAAC;KACF;IACD,IAAM,QAAQ,GACb,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ;QAChC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;IAClB,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,QAAQ,EAAE;QACvB,OAAO;YACN,MAAM,EAAE,qCAA6B,CAAC,QAAQ;YAC9C,UAAU,EAAE,QAAQ,CAAC,QAAQ;SAC7B,CAAC;KACF;IACD,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,EAAE;QACtB,OAAO;YACN,MAAM,EAAE,qCAA6B,CAAC,OAAO;YAC7C,UAAU,EAAE,QAAQ,CAAC,OAAO;SAC5B,CAAC;KACF;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as AWSPinpointProvider } from './AWSPinpointProvider';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var AWSPinpointProvider_1 = require("./AWSPinpointProvider");
|
|
6
|
+
exports.AWSPinpointProvider = AWSPinpointProvider_1.default;
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/PushNotification/Providers/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC,6DAAuE;AAA9D,oDAAA,OAAO,CAAuB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { NotificationsSubCategory, OnPushNotificationMessageHandler, OnTokenReceivedHandler, PushNotificationConfig, PushNotificationInterface, PushNotificationMessage, PushNotificationPermissions, PushNotificationPermissionStatus, PushNotificationProvider } from './types';
|
|
2
|
+
export default class PushNotification implements PushNotificationInterface {
|
|
3
|
+
/**
|
|
4
|
+
* Configure PushNotification
|
|
5
|
+
* @param {Object} config - PushNotification configuration object
|
|
6
|
+
*/
|
|
7
|
+
configure: (_?: PushNotificationConfig) => PushNotificationConfig;
|
|
8
|
+
/**
|
|
9
|
+
* Get the name of this module
|
|
10
|
+
* @returns {string} name of this module
|
|
11
|
+
*/
|
|
12
|
+
getModuleName(): NotificationsSubCategory;
|
|
13
|
+
/**
|
|
14
|
+
* Get a plugin from added plugins
|
|
15
|
+
* @param {string} providerName - the name of the plugin to get
|
|
16
|
+
*/
|
|
17
|
+
getPluggable: (_: string) => never;
|
|
18
|
+
/**
|
|
19
|
+
* Add plugin into PushNotification
|
|
20
|
+
* @param {PushNotificationProvider} pluggable - an instance of the plugin
|
|
21
|
+
*/
|
|
22
|
+
addPluggable: (_: PushNotificationProvider) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Remove a plugin from added plugins
|
|
25
|
+
* @param {string} providerName - the name of the plugin to remove
|
|
26
|
+
*/
|
|
27
|
+
removePluggable: () => void;
|
|
28
|
+
enable: () => void;
|
|
29
|
+
identifyUser: () => Promise<void[]>;
|
|
30
|
+
getLaunchNotification: () => Promise<PushNotificationMessage>;
|
|
31
|
+
getBadgeCount: () => Promise<number>;
|
|
32
|
+
setBadgeCount: (_: number) => void;
|
|
33
|
+
getPermissionStatus: () => Promise<PushNotificationPermissionStatus>;
|
|
34
|
+
requestPermissions: (_?: PushNotificationPermissions) => Promise<boolean>;
|
|
35
|
+
onNotificationReceivedInBackground: (_: OnPushNotificationMessageHandler) => any;
|
|
36
|
+
onNotificationReceivedInForeground: (_: OnPushNotificationMessageHandler) => any;
|
|
37
|
+
onTokenReceived: (_: OnTokenReceivedHandler) => any;
|
|
38
|
+
onNotificationOpened: (_: OnPushNotificationMessageHandler) => any;
|
|
39
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var PlatformNotSupportedError_1 = tslib_1.__importDefault(require("./PlatformNotSupportedError"));
|
|
7
|
+
var PushNotification = /** @class */ (function () {
|
|
8
|
+
function PushNotification() {
|
|
9
|
+
var _this = this;
|
|
10
|
+
/**
|
|
11
|
+
* Configure PushNotification
|
|
12
|
+
* @param {Object} config - PushNotification configuration object
|
|
13
|
+
*/
|
|
14
|
+
this.configure = function (_) {
|
|
15
|
+
if (_ === void 0) { _ = {}; }
|
|
16
|
+
throw new PlatformNotSupportedError_1.default();
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get a plugin from added plugins
|
|
20
|
+
* @param {string} providerName - the name of the plugin to get
|
|
21
|
+
*/
|
|
22
|
+
this.getPluggable = function (_) {
|
|
23
|
+
throw new PlatformNotSupportedError_1.default();
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Add plugin into PushNotification
|
|
27
|
+
* @param {PushNotificationProvider} pluggable - an instance of the plugin
|
|
28
|
+
*/
|
|
29
|
+
this.addPluggable = function (_) {
|
|
30
|
+
throw new PlatformNotSupportedError_1.default();
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Remove a plugin from added plugins
|
|
34
|
+
* @param {string} providerName - the name of the plugin to remove
|
|
35
|
+
*/
|
|
36
|
+
this.removePluggable = function () {
|
|
37
|
+
throw new PlatformNotSupportedError_1.default();
|
|
38
|
+
};
|
|
39
|
+
this.enable = function () {
|
|
40
|
+
throw new PlatformNotSupportedError_1.default();
|
|
41
|
+
};
|
|
42
|
+
this.identifyUser = function () {
|
|
43
|
+
throw new PlatformNotSupportedError_1.default();
|
|
44
|
+
};
|
|
45
|
+
this.getLaunchNotification = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
46
|
+
return tslib_1.__generator(this, function (_a) {
|
|
47
|
+
throw new PlatformNotSupportedError_1.default();
|
|
48
|
+
});
|
|
49
|
+
}); };
|
|
50
|
+
this.getBadgeCount = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
51
|
+
return tslib_1.__generator(this, function (_a) {
|
|
52
|
+
throw new PlatformNotSupportedError_1.default();
|
|
53
|
+
});
|
|
54
|
+
}); };
|
|
55
|
+
this.setBadgeCount = function (_) {
|
|
56
|
+
throw new PlatformNotSupportedError_1.default();
|
|
57
|
+
};
|
|
58
|
+
this.getPermissionStatus = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
59
|
+
return tslib_1.__generator(this, function (_a) {
|
|
60
|
+
throw new PlatformNotSupportedError_1.default();
|
|
61
|
+
});
|
|
62
|
+
}); };
|
|
63
|
+
this.requestPermissions = function (_) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
64
|
+
return tslib_1.__generator(this, function (_a) {
|
|
65
|
+
throw new PlatformNotSupportedError_1.default();
|
|
66
|
+
});
|
|
67
|
+
}); };
|
|
68
|
+
this.onNotificationReceivedInBackground = function (_) {
|
|
69
|
+
throw new PlatformNotSupportedError_1.default();
|
|
70
|
+
};
|
|
71
|
+
this.onNotificationReceivedInForeground = function (_) {
|
|
72
|
+
throw new PlatformNotSupportedError_1.default();
|
|
73
|
+
};
|
|
74
|
+
this.onTokenReceived = function (_) {
|
|
75
|
+
throw new PlatformNotSupportedError_1.default();
|
|
76
|
+
};
|
|
77
|
+
this.onNotificationOpened = function (_) {
|
|
78
|
+
throw new PlatformNotSupportedError_1.default();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the name of this module
|
|
83
|
+
* @returns {string} name of this module
|
|
84
|
+
*/
|
|
85
|
+
PushNotification.prototype.getModuleName = function () {
|
|
86
|
+
throw new PlatformNotSupportedError_1.default();
|
|
87
|
+
};
|
|
88
|
+
return PushNotification;
|
|
89
|
+
}());
|
|
90
|
+
exports.default = PushNotification;
|
|
91
|
+
//# sourceMappingURL=PushNotification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PushNotification.js","sourceRoot":"","sources":["../../src/PushNotification/PushNotification.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,kGAAoE;AAapE;IAAA;QAAA,iBA0FC;QAzFA;;;WAGG;QACH,cAAS,GAAG,UAAC,CAA8B;YAA9B,kBAAA,EAAA,MAA8B;YAC1C,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAUF;;;WAGG;QACH,iBAAY,GAAG,UAAC,CAAS;YACxB,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF;;;WAGG;QACH,iBAAY,GAAG,UAAC,CAA2B;YAC1C,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF;;;WAGG;QACH,oBAAe,GAAG;YACjB,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF,WAAM,GAAG;YACR,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF,iBAAY,GAAG;YACd,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF,0BAAqB,GAAG;;gBACvB,MAAM,IAAI,mCAAyB,EAAE,CAAC;;aACtC,CAAC;QAEF,kBAAa,GAAG;;gBACf,MAAM,IAAI,mCAAyB,EAAE,CAAC;;aACtC,CAAC;QAEF,kBAAa,GAAG,UAAC,CAAS;YACzB,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF,wBAAmB,GAAG;;gBACrB,MAAM,IAAI,mCAAyB,EAAE,CAAC;;aACtC,CAAC;QAEF,uBAAkB,GAAG,UACpB,CAA+B;;gBAE/B,MAAM,IAAI,mCAAyB,EAAE,CAAC;;aACtC,CAAC;QAEF,uCAAkC,GAAG,UACpC,CAAmC;YAEnC,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF,uCAAkC,GAAG,UACpC,CAAmC;YAEnC,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF,oBAAe,GAAG,UAAC,CAAyB;YAC3C,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;QAEF,yBAAoB,GAAG,UAAC,CAAmC;YAC1D,MAAM,IAAI,mCAAyB,EAAE,CAAC;QACvC,CAAC,CAAC;IACH,CAAC;IAjFA;;;OAGG;IACH,wCAAa,GAAb;QACC,MAAM,IAAI,mCAAyB,EAAE,CAAC;IACvC,CAAC;IA2EF,uBAAC;AAAD,CAAC,AA1FD,IA0FC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EventListener } from '../common';
|
|
2
|
+
import { UserInfo } from '../types';
|
|
3
|
+
import { NotificationsSubCategory, OnPushNotificationMessageHandler, OnTokenReceivedHandler, PushNotificationConfig, PushNotificationInterface, PushNotificationMessage, PushNotificationPermissions, PushNotificationPermissionStatus, PushNotificationProvider } from './types';
|
|
4
|
+
export default class PushNotification implements PushNotificationInterface {
|
|
5
|
+
private isEnabled;
|
|
6
|
+
private config;
|
|
7
|
+
private nativeEvent;
|
|
8
|
+
private nativeEventEmitter;
|
|
9
|
+
private nativeHeadlessTaskKey;
|
|
10
|
+
private nativeModule;
|
|
11
|
+
private pluggables;
|
|
12
|
+
private token;
|
|
13
|
+
constructor();
|
|
14
|
+
/**
|
|
15
|
+
* Configure PushNotification
|
|
16
|
+
* @param {Object} config - PushNotification configuration object
|
|
17
|
+
*/
|
|
18
|
+
configure: (config?: PushNotificationConfig) => PushNotificationConfig;
|
|
19
|
+
/**
|
|
20
|
+
* Get the name of this module
|
|
21
|
+
* @returns {string} name of this module
|
|
22
|
+
*/
|
|
23
|
+
getModuleName(): NotificationsSubCategory;
|
|
24
|
+
/**
|
|
25
|
+
* Get a plugin from added plugins
|
|
26
|
+
* @param {string} providerName - the name of the plugin to get
|
|
27
|
+
*/
|
|
28
|
+
getPluggable: (providerName: string) => PushNotificationProvider;
|
|
29
|
+
/**
|
|
30
|
+
* Add plugin into PushNotification
|
|
31
|
+
* @param {PushNotificationProvider} pluggable - an instance of the plugin
|
|
32
|
+
*/
|
|
33
|
+
addPluggable: (pluggable: PushNotificationProvider) => void;
|
|
34
|
+
/**
|
|
35
|
+
* Remove a plugin from added plugins
|
|
36
|
+
* @param {string} providerName - the name of the plugin to remove
|
|
37
|
+
*/
|
|
38
|
+
removePluggable: (providerName: string) => void;
|
|
39
|
+
enable: () => void;
|
|
40
|
+
identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
|
|
41
|
+
getLaunchNotification: () => Promise<PushNotificationMessage>;
|
|
42
|
+
getBadgeCount: () => Promise<number>;
|
|
43
|
+
setBadgeCount: (count: number) => void;
|
|
44
|
+
getPermissionStatus: () => Promise<PushNotificationPermissionStatus>;
|
|
45
|
+
requestPermissions: (permissions?: PushNotificationPermissions) => Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Background notifications on will start the app (as a headless JS instance running on a background service on
|
|
48
|
+
* Android) in the background. Handlers registered via `onNotificationReceivedInBackground` should return Promises if
|
|
49
|
+
* it needs to be asynchronous (e.g. to perform some network requests). The app should run in the background as long
|
|
50
|
+
* as there are handlers still running (however, if they run for more than 30 seconds on iOS, subsequent tasks could
|
|
51
|
+
* get deprioritized!). If it is necessary for a handler to execute while the app is in quit state, it should be
|
|
52
|
+
* registered in the application entry point (e.g. index.js) since the application will not fully mount in that case.
|
|
53
|
+
*
|
|
54
|
+
* @param handler a function to be run when a BACKGROUND_MESSAGE_RECEIVED event is received
|
|
55
|
+
* @returns an event listener which should be removed when no longer needed
|
|
56
|
+
*/
|
|
57
|
+
onNotificationReceivedInBackground: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
|
|
58
|
+
onNotificationReceivedInForeground: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
|
|
59
|
+
onNotificationOpened: (handler: OnPushNotificationMessageHandler) => EventListener<OnPushNotificationMessageHandler>;
|
|
60
|
+
onTokenReceived: (handler: OnTokenReceivedHandler) => EventListener<OnTokenReceivedHandler>;
|
|
61
|
+
private registerDevice;
|
|
62
|
+
private assertIsEnabled;
|
|
63
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
var tslib_1 = require("tslib");
|
|
6
|
+
var react_native_1 = require("react-native");
|
|
7
|
+
var core_1 = require("@aws-amplify/core");
|
|
8
|
+
var rtn_push_notification_1 = require("@aws-amplify/rtn-push-notification");
|
|
9
|
+
var common_1 = require("../common");
|
|
10
|
+
var NotEnabledError_1 = tslib_1.__importDefault(require("./NotEnabledError"));
|
|
11
|
+
var Providers_1 = require("./Providers");
|
|
12
|
+
var utils_1 = require("./utils");
|
|
13
|
+
var logger = new core_1.ConsoleLogger('Notifications.PushNotification');
|
|
14
|
+
var RTN_MODULE = '@aws-amplify/rtn-push-notification';
|
|
15
|
+
var BACKGROUND_TASK_TIMEOUT = 25; // seconds
|
|
16
|
+
var PushNotification = /** @class */ (function () {
|
|
17
|
+
function PushNotification() {
|
|
18
|
+
var _this = this;
|
|
19
|
+
this.isEnabled = false;
|
|
20
|
+
this.config = {};
|
|
21
|
+
this.pluggables = [];
|
|
22
|
+
/**
|
|
23
|
+
* Configure PushNotification
|
|
24
|
+
* @param {Object} config - PushNotification configuration object
|
|
25
|
+
*/
|
|
26
|
+
this.configure = function (config) {
|
|
27
|
+
if (config === void 0) { config = {}; }
|
|
28
|
+
_this.config = tslib_1.__assign(tslib_1.__assign({}, _this.config), config);
|
|
29
|
+
logger.debug('configure PushNotification', _this.config);
|
|
30
|
+
_this.pluggables.forEach(function (pluggable) {
|
|
31
|
+
pluggable.configure(_this.config[pluggable.getProviderName()]);
|
|
32
|
+
});
|
|
33
|
+
if (_this.pluggables.length === 0) {
|
|
34
|
+
_this.addPluggable(new Providers_1.AWSPinpointProvider());
|
|
35
|
+
}
|
|
36
|
+
return _this.config;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Get a plugin from added plugins
|
|
40
|
+
* @param {string} providerName - the name of the plugin to get
|
|
41
|
+
*/
|
|
42
|
+
this.getPluggable = function (providerName) {
|
|
43
|
+
var _a;
|
|
44
|
+
var pluggable = (_a = _this.pluggables.find(function (pluggable) { return pluggable.getProviderName() === providerName; })) !== null && _a !== void 0 ? _a : null;
|
|
45
|
+
if (!pluggable) {
|
|
46
|
+
logger.debug("No plugin found with name " + providerName);
|
|
47
|
+
}
|
|
48
|
+
return pluggable;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Add plugin into PushNotification
|
|
52
|
+
* @param {PushNotificationProvider} pluggable - an instance of the plugin
|
|
53
|
+
*/
|
|
54
|
+
this.addPluggable = function (pluggable) {
|
|
55
|
+
if (pluggable &&
|
|
56
|
+
pluggable.getCategory() === 'Notifications' &&
|
|
57
|
+
pluggable.getSubCategory() === 'PushNotification') {
|
|
58
|
+
if (_this.getPluggable(pluggable.getProviderName())) {
|
|
59
|
+
throw new Error("Pluggable " + pluggable.getProviderName() + " has already been added.");
|
|
60
|
+
}
|
|
61
|
+
_this.pluggables.push(pluggable);
|
|
62
|
+
pluggable.configure(_this.config[pluggable.getProviderName()]);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Remove a plugin from added plugins
|
|
67
|
+
* @param {string} providerName - the name of the plugin to remove
|
|
68
|
+
*/
|
|
69
|
+
this.removePluggable = function (providerName) {
|
|
70
|
+
var index = _this.pluggables.findIndex(function (pluggable) { return pluggable.getProviderName() === providerName; });
|
|
71
|
+
if (index === -1) {
|
|
72
|
+
logger.debug("No plugin found with name " + providerName);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
_this.pluggables.splice(index, 1);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
this.enable = function () {
|
|
79
|
+
if (_this.isEnabled) {
|
|
80
|
+
logger.info('Notification listeners have already been enabled');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
var _a = _this.nativeEvent, BACKGROUND_MESSAGE_RECEIVED = _a.BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED = _a.FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED = _a.LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED = _a.NOTIFICATION_OPENED, TOKEN_RECEIVED = _a.TOKEN_RECEIVED;
|
|
84
|
+
if (_this.nativeHeadlessTaskKey) {
|
|
85
|
+
// on platforms that can handle headless tasks, register one to broadcast background message received to
|
|
86
|
+
// library listeners
|
|
87
|
+
react_native_1.AppRegistry.registerHeadlessTask(_this.nativeHeadlessTaskKey, function () { return function (message) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
88
|
+
return tslib_1.__generator(this, function (_a) {
|
|
89
|
+
switch (_a.label) {
|
|
90
|
+
case 0:
|
|
91
|
+
// keep headless task running until handlers have completed their work
|
|
92
|
+
return [4 /*yield*/, common_1.notifyEventListenersAndAwaitHandlers(0 /* BACKGROUND_MESSAGE_RECEIVED */, utils_1.normalizeNativeMessage(message))];
|
|
93
|
+
case 1:
|
|
94
|
+
// keep headless task running until handlers have completed their work
|
|
95
|
+
_a.sent();
|
|
96
|
+
return [2 /*return*/];
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}); }; });
|
|
100
|
+
}
|
|
101
|
+
else if (BACKGROUND_MESSAGE_RECEIVED) {
|
|
102
|
+
// on platforms that can't handle headless tasks, listen for native background message received event and
|
|
103
|
+
// broadcast to library listeners
|
|
104
|
+
_this.nativeEventEmitter.addListener(BACKGROUND_MESSAGE_RECEIVED, function (message) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
105
|
+
var err_1;
|
|
106
|
+
var _a, _b;
|
|
107
|
+
return tslib_1.__generator(this, function (_c) {
|
|
108
|
+
switch (_c.label) {
|
|
109
|
+
case 0:
|
|
110
|
+
_c.trys.push([0, 2, 3, 4]);
|
|
111
|
+
return [4 /*yield*/, Promise.race([
|
|
112
|
+
common_1.notifyEventListenersAndAwaitHandlers(0 /* BACKGROUND_MESSAGE_RECEIVED */, utils_1.normalizeNativeMessage(message)),
|
|
113
|
+
// background tasks will get suspended and all future tasks be deprioritized by the OS if they run for
|
|
114
|
+
// more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from
|
|
115
|
+
// happening
|
|
116
|
+
new Promise(function (_, reject) {
|
|
117
|
+
setTimeout(function () {
|
|
118
|
+
return reject("onNotificationReceivedInBackground handlers should complete their work within " + BACKGROUND_TASK_TIMEOUT + " seconds, but they did not.");
|
|
119
|
+
}, BACKGROUND_TASK_TIMEOUT * 1000);
|
|
120
|
+
}),
|
|
121
|
+
])];
|
|
122
|
+
case 1:
|
|
123
|
+
_c.sent();
|
|
124
|
+
return [3 /*break*/, 4];
|
|
125
|
+
case 2:
|
|
126
|
+
err_1 = _c.sent();
|
|
127
|
+
logger.error(err_1);
|
|
128
|
+
return [3 /*break*/, 4];
|
|
129
|
+
case 3:
|
|
130
|
+
// notify native module that handlers have completed their work (or timed out)
|
|
131
|
+
(_b = (_a = this.nativeModule).completeNotification) === null || _b === void 0 ? void 0 : _b.call(_a, message.completionHandlerId);
|
|
132
|
+
return [7 /*endfinally*/];
|
|
133
|
+
case 4: return [2 /*return*/];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}); });
|
|
137
|
+
}
|
|
138
|
+
_this.nativeEventEmitter.addListener(
|
|
139
|
+
// listen for native foreground message received event and broadcast to library listeners
|
|
140
|
+
FOREGROUND_MESSAGE_RECEIVED, function (message) {
|
|
141
|
+
common_1.notifyEventListeners(1 /* FOREGROUND_MESSAGE_RECEIVED */, utils_1.normalizeNativeMessage(message));
|
|
142
|
+
});
|
|
143
|
+
var launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED
|
|
144
|
+
? _this.nativeEventEmitter.addListener(
|
|
145
|
+
// listen for native notification opened app (user tapped on notification, opening the app from quit -
|
|
146
|
+
// not background - state) event. This is broadcasted to an internal listener only as it is not intended
|
|
147
|
+
// for use otherwise as it produces inconsistent results when used within React Native app context
|
|
148
|
+
LAUNCH_NOTIFICATION_OPENED, function (message) {
|
|
149
|
+
common_1.notifyEventListeners(2 /* LAUNCH_NOTIFICATION_OPENED */, utils_1.normalizeNativeMessage(message));
|
|
150
|
+
// once we are done with it we can remove the listener
|
|
151
|
+
launchNotificationOpenedListener === null || launchNotificationOpenedListener === void 0 ? void 0 : launchNotificationOpenedListener.remove();
|
|
152
|
+
})
|
|
153
|
+
: null;
|
|
154
|
+
_this.nativeEventEmitter.addListener(
|
|
155
|
+
// listen for native notification opened (user tapped on notification, opening the app from background -
|
|
156
|
+
// not quit - state) event and broadcast to library listeners
|
|
157
|
+
NOTIFICATION_OPENED, function (message) {
|
|
158
|
+
common_1.notifyEventListeners(3 /* NOTIFICATION_OPENED */, utils_1.normalizeNativeMessage(message));
|
|
159
|
+
// if we are in this state, we no longer need the listener as the app was launched via some other means
|
|
160
|
+
launchNotificationOpenedListener === null || launchNotificationOpenedListener === void 0 ? void 0 : launchNotificationOpenedListener.remove();
|
|
161
|
+
});
|
|
162
|
+
_this.nativeEventEmitter.addListener(
|
|
163
|
+
// listen for native new token event, automatically re-register device with provider using new token and
|
|
164
|
+
// broadcast to library listeners
|
|
165
|
+
TOKEN_RECEIVED, function (_a) {
|
|
166
|
+
var token = _a.token;
|
|
167
|
+
// avoid a race condition where two endpoints are created with the same token on a fresh install
|
|
168
|
+
if (_this.token === token) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
_this.token = token;
|
|
172
|
+
_this.registerDevice();
|
|
173
|
+
common_1.notifyEventListeners(4 /* TOKEN_RECEIVED */, token);
|
|
174
|
+
});
|
|
175
|
+
_this.isEnabled = true;
|
|
176
|
+
};
|
|
177
|
+
this.identifyUser = function (userId, userInfo) {
|
|
178
|
+
_this.assertIsEnabled();
|
|
179
|
+
return Promise.all(_this.pluggables.map(function (pluggable) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
180
|
+
var err_2;
|
|
181
|
+
return tslib_1.__generator(this, function (_a) {
|
|
182
|
+
switch (_a.label) {
|
|
183
|
+
case 0:
|
|
184
|
+
_a.trys.push([0, 2, , 3]);
|
|
185
|
+
return [4 /*yield*/, pluggable.identifyUser(userId, userInfo)];
|
|
186
|
+
case 1:
|
|
187
|
+
_a.sent();
|
|
188
|
+
return [3 /*break*/, 3];
|
|
189
|
+
case 2:
|
|
190
|
+
err_2 = _a.sent();
|
|
191
|
+
logger.error('Failed to identify user', err_2);
|
|
192
|
+
throw err_2;
|
|
193
|
+
case 3: return [2 /*return*/];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}); }));
|
|
197
|
+
};
|
|
198
|
+
this.getLaunchNotification = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
199
|
+
var _a;
|
|
200
|
+
var _b, _c;
|
|
201
|
+
return tslib_1.__generator(this, function (_d) {
|
|
202
|
+
switch (_d.label) {
|
|
203
|
+
case 0:
|
|
204
|
+
this.assertIsEnabled();
|
|
205
|
+
_a = utils_1.normalizeNativeMessage;
|
|
206
|
+
return [4 /*yield*/, ((_c = (_b = this.nativeModule).getLaunchNotification) === null || _c === void 0 ? void 0 : _c.call(_b))];
|
|
207
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_d.sent()])];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}); };
|
|
211
|
+
this.getBadgeCount = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
212
|
+
var _a, _b;
|
|
213
|
+
return tslib_1.__generator(this, function (_c) {
|
|
214
|
+
this.assertIsEnabled();
|
|
215
|
+
return [2 /*return*/, (_b = (_a = this.nativeModule).getBadgeCount) === null || _b === void 0 ? void 0 : _b.call(_a)];
|
|
216
|
+
});
|
|
217
|
+
}); };
|
|
218
|
+
this.setBadgeCount = function (count) {
|
|
219
|
+
var _a, _b;
|
|
220
|
+
_this.assertIsEnabled();
|
|
221
|
+
return (_b = (_a = _this.nativeModule).setBadgeCount) === null || _b === void 0 ? void 0 : _b.call(_a, count);
|
|
222
|
+
};
|
|
223
|
+
this.getPermissionStatus = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
224
|
+
var _a;
|
|
225
|
+
var _b, _c;
|
|
226
|
+
return tslib_1.__generator(this, function (_d) {
|
|
227
|
+
switch (_d.label) {
|
|
228
|
+
case 0:
|
|
229
|
+
this.assertIsEnabled();
|
|
230
|
+
_a = utils_1.normalizeNativePermissionStatus;
|
|
231
|
+
return [4 /*yield*/, ((_c = (_b = this.nativeModule).getPermissionStatus) === null || _c === void 0 ? void 0 : _c.call(_b))];
|
|
232
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_d.sent()])];
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}); };
|
|
236
|
+
this.requestPermissions = function (permissions) {
|
|
237
|
+
if (permissions === void 0) { permissions = {
|
|
238
|
+
alert: true,
|
|
239
|
+
badge: true,
|
|
240
|
+
sound: true,
|
|
241
|
+
}; }
|
|
242
|
+
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
243
|
+
var _a, _b;
|
|
244
|
+
return tslib_1.__generator(this, function (_c) {
|
|
245
|
+
this.assertIsEnabled();
|
|
246
|
+
return [2 /*return*/, (_b = (_a = this.nativeModule).requestPermissions) === null || _b === void 0 ? void 0 : _b.call(_a, permissions)];
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Background notifications on will start the app (as a headless JS instance running on a background service on
|
|
252
|
+
* Android) in the background. Handlers registered via `onNotificationReceivedInBackground` should return Promises if
|
|
253
|
+
* it needs to be asynchronous (e.g. to perform some network requests). The app should run in the background as long
|
|
254
|
+
* as there are handlers still running (however, if they run for more than 30 seconds on iOS, subsequent tasks could
|
|
255
|
+
* get deprioritized!). If it is necessary for a handler to execute while the app is in quit state, it should be
|
|
256
|
+
* registered in the application entry point (e.g. index.js) since the application will not fully mount in that case.
|
|
257
|
+
*
|
|
258
|
+
* @param handler a function to be run when a BACKGROUND_MESSAGE_RECEIVED event is received
|
|
259
|
+
* @returns an event listener which should be removed when no longer needed
|
|
260
|
+
*/
|
|
261
|
+
this.onNotificationReceivedInBackground = function (handler) {
|
|
262
|
+
_this.assertIsEnabled();
|
|
263
|
+
return common_1.addEventListener(0 /* BACKGROUND_MESSAGE_RECEIVED */, handler);
|
|
264
|
+
};
|
|
265
|
+
this.onNotificationReceivedInForeground = function (handler) {
|
|
266
|
+
_this.assertIsEnabled();
|
|
267
|
+
return common_1.addEventListener(1 /* FOREGROUND_MESSAGE_RECEIVED */, handler);
|
|
268
|
+
};
|
|
269
|
+
this.onNotificationOpened = function (handler) {
|
|
270
|
+
_this.assertIsEnabled();
|
|
271
|
+
return common_1.addEventListener(3 /* NOTIFICATION_OPENED */, handler);
|
|
272
|
+
};
|
|
273
|
+
this.onTokenReceived = function (handler) {
|
|
274
|
+
_this.assertIsEnabled();
|
|
275
|
+
return common_1.addEventListener(4 /* TOKEN_RECEIVED */, handler);
|
|
276
|
+
};
|
|
277
|
+
this.registerDevice = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
278
|
+
var _this = this;
|
|
279
|
+
return tslib_1.__generator(this, function (_a) {
|
|
280
|
+
return [2 /*return*/, Promise.all(this.pluggables.map(function (pluggable) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
281
|
+
var err_3;
|
|
282
|
+
return tslib_1.__generator(this, function (_a) {
|
|
283
|
+
switch (_a.label) {
|
|
284
|
+
case 0:
|
|
285
|
+
_a.trys.push([0, 2, , 3]);
|
|
286
|
+
return [4 /*yield*/, pluggable.registerDevice(this.token)];
|
|
287
|
+
case 1:
|
|
288
|
+
_a.sent();
|
|
289
|
+
return [3 /*break*/, 3];
|
|
290
|
+
case 2:
|
|
291
|
+
err_3 = _a.sent();
|
|
292
|
+
logger.error('Failed to register device for push notifications', err_3);
|
|
293
|
+
throw err_3;
|
|
294
|
+
case 3: return [2 /*return*/];
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}); }))];
|
|
298
|
+
});
|
|
299
|
+
}); };
|
|
300
|
+
this.assertIsEnabled = function () {
|
|
301
|
+
if (!_this.isEnabled) {
|
|
302
|
+
throw new NotEnabledError_1.default();
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
try {
|
|
306
|
+
this.nativeModule = rtn_push_notification_1.AmplifyRTNPushNotification;
|
|
307
|
+
var _a = this.nativeModule.getConstants(), NativeEvent = _a.NativeEvent, NativeHeadlessTaskKey = _a.NativeHeadlessTaskKey;
|
|
308
|
+
this.nativeEvent = NativeEvent;
|
|
309
|
+
this.nativeHeadlessTaskKey = NativeHeadlessTaskKey;
|
|
310
|
+
this.nativeEventEmitter = new react_native_1.NativeEventEmitter(rtn_push_notification_1.AmplifyRTNPushNotification);
|
|
311
|
+
}
|
|
312
|
+
catch (err) {
|
|
313
|
+
err.message = "Unable to find " + RTN_MODULE + ". " + err.message;
|
|
314
|
+
throw err;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get the name of this module
|
|
319
|
+
* @returns {string} name of this module
|
|
320
|
+
*/
|
|
321
|
+
PushNotification.prototype.getModuleName = function () {
|
|
322
|
+
return 'PushNotification';
|
|
323
|
+
};
|
|
324
|
+
return PushNotification;
|
|
325
|
+
}());
|
|
326
|
+
exports.default = PushNotification;
|
|
327
|
+
//# sourceMappingURL=PushNotification.native.js.map
|