@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,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { EventListener } from '../common';
|
|
2
|
+
import { UserInfo } from '../types';
|
|
3
|
+
import { InAppMessage, InAppMessageInteractionEvent, InAppMessagingInterface, InAppMessagingConfig, InAppMessageConflictHandler, InAppMessagingEvent, InAppMessagingProvider, NotificationsSubCategory, OnMessageInteractionEventHandler } from './types';
|
|
4
|
+
export default class InAppMessaging implements InAppMessagingInterface {
|
|
3
5
|
private config;
|
|
4
6
|
private conflictHandler;
|
|
5
7
|
private listeningForAnalyticEvents;
|
|
@@ -15,7 +17,7 @@ export default class InAppMessaging {
|
|
|
15
17
|
* Get the name of this module
|
|
16
18
|
* @returns {string} name of this module
|
|
17
19
|
*/
|
|
18
|
-
getModuleName():
|
|
20
|
+
getModuleName(): NotificationsSubCategory;
|
|
19
21
|
/**
|
|
20
22
|
* Get a plugin from added plugins
|
|
21
23
|
* @param {string} providerName - the name of the plugin to get
|
|
@@ -40,11 +42,11 @@ export default class InAppMessaging {
|
|
|
40
42
|
clearMessages: () => Promise<void[]>;
|
|
41
43
|
dispatchEvent: (event: InAppMessagingEvent) => Promise<void>;
|
|
42
44
|
identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
|
|
43
|
-
onMessageReceived: (handler: OnMessageInteractionEventHandler) =>
|
|
44
|
-
onMessageDisplayed: (handler: OnMessageInteractionEventHandler) =>
|
|
45
|
-
onMessageDismissed: (handler: OnMessageInteractionEventHandler) =>
|
|
46
|
-
onMessageActionTaken: (handler: OnMessageInteractionEventHandler) =>
|
|
47
|
-
notifyMessageInteraction: (message: InAppMessage,
|
|
45
|
+
onMessageReceived: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
46
|
+
onMessageDisplayed: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
47
|
+
onMessageDismissed: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
48
|
+
onMessageActionTaken: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
49
|
+
notifyMessageInteraction: (message: InAppMessage, type: InAppMessageInteractionEvent) => void;
|
|
48
50
|
setConflictHandler: (handler: InAppMessageConflictHandler) => void;
|
|
49
51
|
private analyticsListener;
|
|
50
52
|
private syncStorage;
|
|
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
var tslib_1 = require("tslib");
|
|
6
6
|
var core_1 = require("@aws-amplify/core");
|
|
7
7
|
var flatten_1 = tslib_1.__importDefault(require("lodash/flatten"));
|
|
8
|
+
var common_1 = require("../common");
|
|
8
9
|
var Providers_1 = require("./Providers");
|
|
9
|
-
var eventListeners_1 = require("./eventListeners");
|
|
10
10
|
var types_1 = require("./types");
|
|
11
11
|
var STORAGE_KEY_SUFFIX = '_inAppMessages';
|
|
12
12
|
var logger = new core_1.ConsoleLogger('Notifications.InAppMessaging');
|
|
@@ -144,7 +144,7 @@ var InAppMessaging = /** @class */ (function () {
|
|
|
144
144
|
messages = _a.sent();
|
|
145
145
|
flattenedMessages = flatten_1.default(messages);
|
|
146
146
|
if (flattenedMessages.length) {
|
|
147
|
-
|
|
147
|
+
common_1.notifyEventListeners(types_1.InAppMessageInteractionEvent.MESSAGE_RECEIVED, this.conflictHandler(flattenedMessages));
|
|
148
148
|
}
|
|
149
149
|
return [2 /*return*/];
|
|
150
150
|
}
|
|
@@ -171,19 +171,19 @@ var InAppMessaging = /** @class */ (function () {
|
|
|
171
171
|
}); }));
|
|
172
172
|
};
|
|
173
173
|
this.onMessageReceived = function (handler) {
|
|
174
|
-
return
|
|
174
|
+
return common_1.addEventListener(types_1.InAppMessageInteractionEvent.MESSAGE_RECEIVED, handler);
|
|
175
175
|
};
|
|
176
176
|
this.onMessageDisplayed = function (handler) {
|
|
177
|
-
return
|
|
177
|
+
return common_1.addEventListener(types_1.InAppMessageInteractionEvent.MESSAGE_DISPLAYED, handler);
|
|
178
178
|
};
|
|
179
179
|
this.onMessageDismissed = function (handler) {
|
|
180
|
-
return
|
|
180
|
+
return common_1.addEventListener(types_1.InAppMessageInteractionEvent.MESSAGE_DISMISSED, handler);
|
|
181
181
|
};
|
|
182
182
|
this.onMessageActionTaken = function (handler) {
|
|
183
|
-
return
|
|
183
|
+
return common_1.addEventListener(types_1.InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN, handler);
|
|
184
184
|
};
|
|
185
|
-
this.notifyMessageInteraction = function (message,
|
|
186
|
-
|
|
185
|
+
this.notifyMessageInteraction = function (message, type) {
|
|
186
|
+
common_1.notifyEventListeners(type, message);
|
|
187
187
|
};
|
|
188
188
|
this.setConflictHandler = function (handler) {
|
|
189
189
|
_this.conflictHandler = handler;
|
|
@@ -324,9 +324,7 @@ var InAppMessaging = /** @class */ (function () {
|
|
|
324
324
|
// always return the top sorted
|
|
325
325
|
return sorted[0];
|
|
326
326
|
};
|
|
327
|
-
this.config = {
|
|
328
|
-
storage: new core_1.StorageHelper().getStorage(),
|
|
329
|
-
};
|
|
327
|
+
this.config = { storage: new core_1.StorageHelper().getStorage() };
|
|
330
328
|
this.setConflictHandler(this.defaultConflictHandler);
|
|
331
329
|
}
|
|
332
330
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InAppMessaging.js","sourceRoot":"","sources":["../../src/InAppMessaging/InAppMessaging.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,0CAM2B;AAC3B,mEAAqC;
|
|
1
|
+
{"version":3,"file":"InAppMessaging.js","sourceRoot":"","sources":["../../src/InAppMessaging/InAppMessaging.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;;AAEtC,0CAM2B;AAC3B,mEAAqC;AAErC,oCAImB;AAEnB,yCAAkD;AAClD,iCAUiB;AAEjB,IAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAE5C,IAAM,MAAM,GAAG,IAAI,oBAAM,CAAC,8BAA8B,CAAC,CAAC;AAE1D;IAOC;QAAA,iBA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,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC;QAC5D,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACtD,CAAC;IA8BD;;;OAGG;IACH,sCAAa,GAAb;QACC,OAAO,gBAAgB,CAAC;IACzB,CAAC;IA+OF,qBAAC;AAAD,CAAC,AA7RD,IA6RC"}
|
|
@@ -1,38 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InAppMessage, InAppMessagingEvent, InAppMessagingProvider,
|
|
3
|
-
export default class AWSPinpointProvider implements InAppMessagingProvider {
|
|
4
|
-
static
|
|
5
|
-
static subCategory: NotificationsSubcategory;
|
|
6
|
-
static providerName: string;
|
|
7
|
-
private clientInfo;
|
|
8
|
-
private config;
|
|
1
|
+
import { AWSPinpointProviderCommon } from '../../../common';
|
|
2
|
+
import { InAppMessage, InAppMessagingEvent, InAppMessagingProvider, NotificationsSubCategory } from '../../types';
|
|
3
|
+
export default class AWSPinpointProvider extends AWSPinpointProviderCommon implements InAppMessagingProvider {
|
|
4
|
+
static subCategory: NotificationsSubCategory;
|
|
9
5
|
private configured;
|
|
10
|
-
private endpointInitialized;
|
|
11
|
-
private initialized;
|
|
12
6
|
private sessionMessageCountMap;
|
|
13
7
|
private sessionTracker;
|
|
14
8
|
constructor();
|
|
15
|
-
/**
|
|
16
|
-
* get the category of the plugin
|
|
17
|
-
*/
|
|
18
|
-
getCategory(): "Notifications";
|
|
19
9
|
/**
|
|
20
10
|
* get the sub-category of the plugin
|
|
21
11
|
*/
|
|
22
12
|
getSubCategory(): "InAppMessaging";
|
|
23
|
-
|
|
24
|
-
* get provider name of the plugin
|
|
25
|
-
*/
|
|
26
|
-
getProviderName(): string;
|
|
27
|
-
configure: (config?: {}) => object;
|
|
13
|
+
configure: (config?: {}) => Record<string, any>;
|
|
28
14
|
getInAppMessages: () => Promise<any>;
|
|
29
15
|
processInAppMessages: (messages: any[], event: InAppMessagingEvent) => Promise<InAppMessage[]>;
|
|
30
|
-
identifyUser: (userId: string, userInfo: UserInfo) => Promise<void>;
|
|
31
|
-
private init;
|
|
32
|
-
private initPinpointClient;
|
|
33
|
-
private getEndpointId;
|
|
34
|
-
private updateEndpoint;
|
|
35
|
-
private getCredentials;
|
|
36
16
|
private sessionStateChangeHandler;
|
|
37
17
|
private isBelowCap;
|
|
38
18
|
private getSessionCount;
|
|
@@ -3,49 +3,42 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
var tslib_1 = require("tslib");
|
|
6
|
-
var core_1 = require("@aws-amplify/core");
|
|
7
|
-
var cache_1 = require("@aws-amplify/cache");
|
|
8
6
|
var client_pinpoint_1 = require("@aws-sdk/client-pinpoint");
|
|
9
|
-
var
|
|
10
|
-
var eventListeners_1 = require("../../eventListeners");
|
|
7
|
+
var common_1 = require("../../../common");
|
|
11
8
|
var SessionTracker_1 = tslib_1.__importDefault(require("../../SessionTracker"));
|
|
12
9
|
var types_1 = require("../../types");
|
|
13
10
|
var types_2 = require("./types");
|
|
14
11
|
var utils_1 = require("./utils");
|
|
15
12
|
var MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount';
|
|
16
13
|
var MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount';
|
|
17
|
-
var AWSPinpointProvider = /** @class */ (function () {
|
|
14
|
+
var AWSPinpointProvider = /** @class */ (function (_super) {
|
|
15
|
+
tslib_1.__extends(AWSPinpointProvider, _super);
|
|
18
16
|
function AWSPinpointProvider() {
|
|
19
|
-
var _this = this;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.configured = false;
|
|
23
|
-
this.endpointInitialized = false;
|
|
24
|
-
this.initialized = false;
|
|
25
|
-
this.configure = function (config) {
|
|
17
|
+
var _this = _super.call(this, utils_1.logger) || this;
|
|
18
|
+
_this.configured = false;
|
|
19
|
+
_this.configure = function (config) {
|
|
26
20
|
if (config === void 0) { config = {}; }
|
|
27
|
-
_this.config = tslib_1.__assign(tslib_1.__assign({}, _this
|
|
28
|
-
utils_1.logger.debug('configure AWSPinpointProvider', _this.config);
|
|
21
|
+
_this.config = tslib_1.__assign(tslib_1.__assign({}, _super.prototype.configure.call(_this, config)), { endpointInfo: { channelType: client_pinpoint_1.ChannelType.IN_APP } });
|
|
29
22
|
// some configuration steps should not be re-run even if provider is re-configured for some reason
|
|
30
23
|
if (!_this.configured) {
|
|
31
24
|
_this.sessionTracker = new SessionTracker_1.default(_this.sessionStateChangeHandler);
|
|
32
25
|
_this.sessionTracker.start();
|
|
33
26
|
// wire up default Pinpoint message event handling
|
|
34
|
-
|
|
27
|
+
common_1.addEventListener(types_1.InAppMessageInteractionEvent.MESSAGE_DISPLAYED, function (message) {
|
|
35
28
|
_this.recordMessageEvent(message, types_2.AWSPinpointMessageEvent.MESSAGE_DISPLAYED);
|
|
36
|
-
}
|
|
37
|
-
|
|
29
|
+
});
|
|
30
|
+
common_1.addEventListener(types_1.InAppMessageInteractionEvent.MESSAGE_DISMISSED, function (message) {
|
|
38
31
|
_this.recordMessageEvent(message, types_2.AWSPinpointMessageEvent.MESSAGE_DISMISSED);
|
|
39
|
-
}
|
|
40
|
-
|
|
32
|
+
});
|
|
33
|
+
common_1.addEventListener(types_1.InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN, function (message) {
|
|
41
34
|
_this.recordMessageEvent(message, types_2.AWSPinpointMessageEvent.MESSAGE_ACTION_TAKEN);
|
|
42
|
-
}
|
|
35
|
+
});
|
|
43
36
|
}
|
|
44
37
|
_this.configured = true;
|
|
45
38
|
utils_1.dispatchInAppMessagingEvent('pinpointProvider_configured', null);
|
|
46
39
|
return _this.config;
|
|
47
40
|
};
|
|
48
|
-
|
|
41
|
+
_this.getInAppMessages = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
49
42
|
var _a, appId, endpointId, pinpointClient, input, command, response, messages, err_1;
|
|
50
43
|
return tslib_1.__generator(this, function (_b) {
|
|
51
44
|
switch (_b.label) {
|
|
@@ -72,7 +65,7 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
72
65
|
EndpointId: endpointId,
|
|
73
66
|
};
|
|
74
67
|
command = new client_pinpoint_1.GetInAppMessagesCommand(input);
|
|
75
|
-
|
|
68
|
+
this.logger.debug('getting in-app messages');
|
|
76
69
|
return [4 /*yield*/, pinpointClient.send(command)];
|
|
77
70
|
case 5:
|
|
78
71
|
response = _b.sent();
|
|
@@ -81,13 +74,13 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
81
74
|
return [2 /*return*/, messages];
|
|
82
75
|
case 6:
|
|
83
76
|
err_1 = _b.sent();
|
|
84
|
-
|
|
77
|
+
this.logger.error('Error getting in-app messages', err_1);
|
|
85
78
|
throw err_1;
|
|
86
79
|
case 7: return [2 /*return*/];
|
|
87
80
|
}
|
|
88
81
|
});
|
|
89
82
|
}); };
|
|
90
|
-
|
|
83
|
+
_this.processInAppMessages = function (messages, event) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
91
84
|
var highestPrioritySeen;
|
|
92
85
|
var _this = this;
|
|
93
86
|
return tslib_1.__generator(this, function (_a) {
|
|
@@ -136,204 +129,13 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
136
129
|
}
|
|
137
130
|
});
|
|
138
131
|
}); };
|
|
139
|
-
|
|
140
|
-
var err_2;
|
|
141
|
-
return tslib_1.__generator(this, function (_a) {
|
|
142
|
-
switch (_a.label) {
|
|
143
|
-
case 0:
|
|
144
|
-
if (!!this.initialized) return [3 /*break*/, 2];
|
|
145
|
-
return [4 /*yield*/, this.init()];
|
|
146
|
-
case 1:
|
|
147
|
-
_a.sent();
|
|
148
|
-
_a.label = 2;
|
|
149
|
-
case 2:
|
|
150
|
-
_a.trys.push([2, 4, , 5]);
|
|
151
|
-
return [4 /*yield*/, this.updateEndpoint(userId, userInfo)];
|
|
152
|
-
case 3:
|
|
153
|
-
_a.sent();
|
|
154
|
-
return [3 /*break*/, 5];
|
|
155
|
-
case 4:
|
|
156
|
-
err_2 = _a.sent();
|
|
157
|
-
utils_1.logger.error('Error identifying user', err_2);
|
|
158
|
-
throw err_2;
|
|
159
|
-
case 5: return [2 /*return*/];
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}); };
|
|
163
|
-
this.init = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
164
|
-
var _a, endpointId, storage, providerName, _b, err_3;
|
|
165
|
-
return tslib_1.__generator(this, function (_c) {
|
|
166
|
-
switch (_c.label) {
|
|
167
|
-
case 0:
|
|
168
|
-
_a = this.config, endpointId = _a.endpointId, storage = _a.storage;
|
|
169
|
-
providerName = this.getProviderName();
|
|
170
|
-
_c.label = 1;
|
|
171
|
-
case 1:
|
|
172
|
-
_c.trys.push([1, 6, , 7]);
|
|
173
|
-
if (!(typeof storage.sync === 'function')) return [3 /*break*/, 3];
|
|
174
|
-
return [4 /*yield*/, storage.sync()];
|
|
175
|
-
case 2:
|
|
176
|
-
_c.sent();
|
|
177
|
-
_c.label = 3;
|
|
178
|
-
case 3:
|
|
179
|
-
if (!!endpointId) return [3 /*break*/, 5];
|
|
180
|
-
_b = this.config;
|
|
181
|
-
return [4 /*yield*/, this.getEndpointId()];
|
|
182
|
-
case 4:
|
|
183
|
-
_b.endpointId = _c.sent();
|
|
184
|
-
_c.label = 5;
|
|
185
|
-
case 5:
|
|
186
|
-
this.initialized = true;
|
|
187
|
-
return [3 /*break*/, 7];
|
|
188
|
-
case 6:
|
|
189
|
-
err_3 = _c.sent();
|
|
190
|
-
utils_1.logger.error("Failed to initialize " + providerName, err_3);
|
|
191
|
-
return [3 /*break*/, 7];
|
|
192
|
-
case 7: return [2 /*return*/];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}); };
|
|
196
|
-
this.initPinpointClient = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
197
|
-
var _a, appId, credentials, pinpointClient, region;
|
|
198
|
-
return tslib_1.__generator(this, function (_b) {
|
|
199
|
-
_a = this.config, appId = _a.appId, credentials = _a.credentials, pinpointClient = _a.pinpointClient, region = _a.region;
|
|
200
|
-
if (!appId || !credentials || !region) {
|
|
201
|
-
throw new Error('One or more of credentials, appId or region is not configured');
|
|
202
|
-
}
|
|
203
|
-
if (pinpointClient) {
|
|
204
|
-
pinpointClient.destroy();
|
|
205
|
-
}
|
|
206
|
-
this.config.pinpointClient = new client_pinpoint_1.PinpointClient({
|
|
207
|
-
region: region,
|
|
208
|
-
credentials: credentials,
|
|
209
|
-
customUserAgent: core_1.getAmplifyUserAgent(),
|
|
210
|
-
});
|
|
211
|
-
return [2 /*return*/];
|
|
212
|
-
});
|
|
213
|
-
}); };
|
|
214
|
-
this.getEndpointId = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
215
|
-
var appId, cacheKey, cachedEndpointId, endpointId, ttl, expiration;
|
|
216
|
-
return tslib_1.__generator(this, function (_a) {
|
|
217
|
-
switch (_a.label) {
|
|
218
|
-
case 0:
|
|
219
|
-
appId = this.config.appId;
|
|
220
|
-
cacheKey = this.getSubCategory() + ":" + this.getProviderName() + ":" + appId;
|
|
221
|
-
return [4 /*yield*/, cache_1.Cache.getItem(cacheKey)];
|
|
222
|
-
case 1:
|
|
223
|
-
cachedEndpointId = _a.sent();
|
|
224
|
-
// Found in cache, just return it
|
|
225
|
-
if (cachedEndpointId) {
|
|
226
|
-
return [2 /*return*/, cachedEndpointId];
|
|
227
|
-
}
|
|
228
|
-
endpointId = uuid_1.v4();
|
|
229
|
-
ttl = 1000 * 60 * 60 * 24 * 365 * 100;
|
|
230
|
-
expiration = new Date().getTime() + ttl;
|
|
231
|
-
cache_1.Cache.setItem(cacheKey, endpointId, {
|
|
232
|
-
expires: expiration,
|
|
233
|
-
priority: 1,
|
|
234
|
-
});
|
|
235
|
-
return [2 /*return*/, endpointId];
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}); };
|
|
239
|
-
this.updateEndpoint = function (userId, userInfo) {
|
|
240
|
-
if (userId === void 0) { userId = null; }
|
|
241
|
-
if (userInfo === void 0) { userInfo = null; }
|
|
242
|
-
return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
243
|
-
var _a, appId, credentials, endpointId, _b, endpointInfo, pinpointClient, currentCredentials, credentialsUpdated, _c, address, attributes, demographic, location_1, metrics, optOut, _d, appVersion, make, model, platform, version, input, command, err_4;
|
|
244
|
-
var _e;
|
|
245
|
-
return tslib_1.__generator(this, function (_f) {
|
|
246
|
-
switch (_f.label) {
|
|
247
|
-
case 0:
|
|
248
|
-
_a = this.config, appId = _a.appId, credentials = _a.credentials, endpointId = _a.endpointId, _b = _a.endpointInfo, endpointInfo = _b === void 0 ? {} : _b, pinpointClient = _a.pinpointClient;
|
|
249
|
-
return [4 /*yield*/, this.getCredentials()];
|
|
250
|
-
case 1:
|
|
251
|
-
currentCredentials = _f.sent();
|
|
252
|
-
credentialsUpdated = !credentials ||
|
|
253
|
-
Object.keys(currentCredentials).some(function (key) { return currentCredentials[key] !== credentials[key]; });
|
|
254
|
-
// If endpoint is already initialized, and nothing else is changing, just early return
|
|
255
|
-
if (this.endpointInitialized &&
|
|
256
|
-
!credentialsUpdated &&
|
|
257
|
-
!userId &&
|
|
258
|
-
!userInfo) {
|
|
259
|
-
return [2 /*return*/];
|
|
260
|
-
}
|
|
261
|
-
// Update credentials
|
|
262
|
-
this.config.credentials = currentCredentials;
|
|
263
|
-
_f.label = 2;
|
|
264
|
-
case 2:
|
|
265
|
-
_f.trys.push([2, 6, , 7]);
|
|
266
|
-
if (!(!pinpointClient || credentialsUpdated)) return [3 /*break*/, 4];
|
|
267
|
-
return [4 /*yield*/, this.initPinpointClient()];
|
|
268
|
-
case 3:
|
|
269
|
-
_f.sent();
|
|
270
|
-
_f.label = 4;
|
|
271
|
-
case 4:
|
|
272
|
-
_c = userInfo !== null && userInfo !== void 0 ? userInfo : {}, address = _c.address, attributes = _c.attributes, demographic = _c.demographic, location_1 = _c.location, metrics = _c.metrics, optOut = _c.optOut;
|
|
273
|
-
_d = this.clientInfo, appVersion = _d.appVersion, make = _d.make, model = _d.model, platform = _d.platform, version = _d.version;
|
|
274
|
-
input = {
|
|
275
|
-
ApplicationId: appId,
|
|
276
|
-
EndpointId: endpointId,
|
|
277
|
-
EndpointRequest: {
|
|
278
|
-
RequestId: uuid_1.v4(),
|
|
279
|
-
EffectiveDate: new Date().toISOString(),
|
|
280
|
-
ChannelType: client_pinpoint_1.ChannelType.IN_APP,
|
|
281
|
-
Address: address !== null && address !== void 0 ? address : endpointInfo.address,
|
|
282
|
-
Attributes: tslib_1.__assign(tslib_1.__assign({}, endpointInfo.attributes), attributes),
|
|
283
|
-
Demographic: tslib_1.__assign({ AppVersion: appVersion, Make: make, Model: model, ModelVersion: version, Platform: platform }, core_1.transferKeyToUpperCase(tslib_1.__assign(tslib_1.__assign({}, endpointInfo.demographic), demographic))),
|
|
284
|
-
Location: core_1.transferKeyToUpperCase(tslib_1.__assign(tslib_1.__assign({}, endpointInfo.location), location_1)),
|
|
285
|
-
Metrics: tslib_1.__assign(tslib_1.__assign({}, endpointInfo.metrics), metrics),
|
|
286
|
-
OptOut: optOut !== null && optOut !== void 0 ? optOut : endpointInfo.optOut,
|
|
287
|
-
User: {
|
|
288
|
-
UserId: (_e = userId !== null && userId !== void 0 ? userId : endpointInfo.userId) !== null && _e !== void 0 ? _e : currentCredentials.identityId,
|
|
289
|
-
UserAttributes: attributes !== null && attributes !== void 0 ? attributes : endpointInfo.userAttributes,
|
|
290
|
-
},
|
|
291
|
-
},
|
|
292
|
-
};
|
|
293
|
-
command = new client_pinpoint_1.UpdateEndpointCommand(input);
|
|
294
|
-
utils_1.logger.debug('updating endpoint', input);
|
|
295
|
-
return [4 /*yield*/, this.config.pinpointClient.send(command)];
|
|
296
|
-
case 5:
|
|
297
|
-
_f.sent();
|
|
298
|
-
this.endpointInitialized = true;
|
|
299
|
-
return [3 /*break*/, 7];
|
|
300
|
-
case 6:
|
|
301
|
-
err_4 = _f.sent();
|
|
302
|
-
throw err_4;
|
|
303
|
-
case 7: return [2 /*return*/];
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
};
|
|
308
|
-
this.getCredentials = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
309
|
-
var credentials, err_5;
|
|
310
|
-
return tslib_1.__generator(this, function (_a) {
|
|
311
|
-
switch (_a.label) {
|
|
312
|
-
case 0:
|
|
313
|
-
_a.trys.push([0, 2, , 3]);
|
|
314
|
-
return [4 /*yield*/, core_1.Credentials.get()];
|
|
315
|
-
case 1:
|
|
316
|
-
credentials = _a.sent();
|
|
317
|
-
if (!credentials) {
|
|
318
|
-
utils_1.logger.debug('no credentials found');
|
|
319
|
-
return [2 /*return*/, null];
|
|
320
|
-
}
|
|
321
|
-
return [2 /*return*/, core_1.Credentials.shear(credentials)];
|
|
322
|
-
case 2:
|
|
323
|
-
err_5 = _a.sent();
|
|
324
|
-
utils_1.logger.error('Error getting credentials:', err_5);
|
|
325
|
-
return [2 /*return*/, null];
|
|
326
|
-
case 3: return [2 /*return*/];
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
}); };
|
|
330
|
-
this.sessionStateChangeHandler = function (state) {
|
|
132
|
+
_this.sessionStateChangeHandler = function (state) {
|
|
331
133
|
if (state === 'started') {
|
|
332
134
|
// reset all session counts
|
|
333
135
|
_this.sessionMessageCountMap = {};
|
|
334
136
|
}
|
|
335
137
|
};
|
|
336
|
-
|
|
138
|
+
_this.isBelowCap = function (_a) {
|
|
337
139
|
var CampaignId = _a.CampaignId, SessionCap = _a.SessionCap, DailyCap = _a.DailyCap, TotalCap = _a.TotalCap;
|
|
338
140
|
var _b = _this.getMessageCounts(CampaignId), sessionCount = _b.sessionCount, dailyCount = _b.dailyCount, totalCount = _b.totalCount;
|
|
339
141
|
return ((!SessionCap || sessionCount < SessionCap) &&
|
|
@@ -341,10 +143,10 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
341
143
|
(!TotalCap || totalCount < TotalCap));
|
|
342
144
|
};
|
|
343
145
|
// Use the current session count in memory or initialize as empty count
|
|
344
|
-
|
|
146
|
+
_this.getSessionCount = function (messageId) {
|
|
345
147
|
return _this.sessionMessageCountMap[messageId] || 0;
|
|
346
148
|
};
|
|
347
|
-
|
|
149
|
+
_this.getDailyCount = function () {
|
|
348
150
|
var storage = _this.config.storage;
|
|
349
151
|
var today = utils_1.getStartOfDay();
|
|
350
152
|
var item = storage.getItem(MESSAGE_DAILY_COUNT_KEY);
|
|
@@ -355,18 +157,18 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
355
157
|
// If the stored counter timestamp is today, use it as the count, otherwise reset to 0
|
|
356
158
|
return counter.lastCountTimestamp === today ? counter.count : 0;
|
|
357
159
|
};
|
|
358
|
-
|
|
160
|
+
_this.getTotalCountMap = function () {
|
|
359
161
|
var storage = _this.config.storage;
|
|
360
162
|
var item = storage.getItem(MESSAGE_TOTAL_COUNT_KEY);
|
|
361
163
|
// Parse stored count map or initialize as empty
|
|
362
164
|
return item ? JSON.parse(item) : {};
|
|
363
165
|
};
|
|
364
|
-
|
|
166
|
+
_this.getTotalCount = function (messageId) {
|
|
365
167
|
var countMap = _this.getTotalCountMap();
|
|
366
168
|
// Return stored count or initialize as empty count
|
|
367
169
|
return countMap[messageId] || 0;
|
|
368
170
|
};
|
|
369
|
-
|
|
171
|
+
_this.getMessageCounts = function (messageId) {
|
|
370
172
|
try {
|
|
371
173
|
return {
|
|
372
174
|
sessionCount: _this.getSessionCount(messageId),
|
|
@@ -375,13 +177,13 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
375
177
|
};
|
|
376
178
|
}
|
|
377
179
|
catch (err) {
|
|
378
|
-
|
|
180
|
+
_this.logger.error('Failed to get message counts from storage', err);
|
|
379
181
|
}
|
|
380
182
|
};
|
|
381
|
-
|
|
183
|
+
_this.setSessionCount = function (messageId, count) {
|
|
382
184
|
_this.sessionMessageCountMap[messageId] = count;
|
|
383
185
|
};
|
|
384
|
-
|
|
186
|
+
_this.setDailyCount = function (count) {
|
|
385
187
|
var storage = _this.config.storage;
|
|
386
188
|
var dailyCount = {
|
|
387
189
|
count: count,
|
|
@@ -391,24 +193,24 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
391
193
|
storage.setItem(MESSAGE_DAILY_COUNT_KEY, JSON.stringify(dailyCount));
|
|
392
194
|
}
|
|
393
195
|
catch (err) {
|
|
394
|
-
|
|
196
|
+
_this.logger.error('Failed to save daily message count to storage', err);
|
|
395
197
|
}
|
|
396
198
|
};
|
|
397
|
-
|
|
199
|
+
_this.setTotalCountMap = function (countMap) {
|
|
398
200
|
var storage = _this.config.storage;
|
|
399
201
|
try {
|
|
400
202
|
storage.setItem(MESSAGE_TOTAL_COUNT_KEY, JSON.stringify(countMap));
|
|
401
203
|
}
|
|
402
204
|
catch (err) {
|
|
403
|
-
|
|
205
|
+
_this.logger.error('Failed to save total count to storage', err);
|
|
404
206
|
}
|
|
405
207
|
};
|
|
406
|
-
|
|
208
|
+
_this.setTotalCount = function (messageId, count) {
|
|
407
209
|
var _a;
|
|
408
210
|
var updatedMap = tslib_1.__assign(tslib_1.__assign({}, _this.getTotalCountMap()), (_a = {}, _a[messageId] = count, _a));
|
|
409
211
|
_this.setTotalCountMap(updatedMap);
|
|
410
212
|
};
|
|
411
|
-
|
|
213
|
+
_this.incrementCounts = function (messageId) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
412
214
|
var _a, sessionCount, dailyCount, totalCount;
|
|
413
215
|
return tslib_1.__generator(this, function (_b) {
|
|
414
216
|
_a = this.getMessageCounts(messageId), sessionCount = _a.sessionCount, dailyCount = _a.dailyCount, totalCount = _a.totalCount;
|
|
@@ -418,7 +220,7 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
418
220
|
return [2 /*return*/];
|
|
419
221
|
});
|
|
420
222
|
}); };
|
|
421
|
-
|
|
223
|
+
_this.normalizeMessages = function (messages) {
|
|
422
224
|
return messages.map(function (message) {
|
|
423
225
|
var CampaignId = message.CampaignId, InAppMessage = message.InAppMessage;
|
|
424
226
|
return {
|
|
@@ -429,7 +231,7 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
429
231
|
};
|
|
430
232
|
});
|
|
431
233
|
};
|
|
432
|
-
|
|
234
|
+
_this.recordMessageEvent = function (message, event) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
433
235
|
return tslib_1.__generator(this, function (_a) {
|
|
434
236
|
switch (_a.label) {
|
|
435
237
|
case 0:
|
|
@@ -449,34 +251,17 @@ var AWSPinpointProvider = /** @class */ (function () {
|
|
|
449
251
|
}
|
|
450
252
|
});
|
|
451
253
|
}); };
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
storage: new core_1.StorageHelper().getStorage(),
|
|
455
|
-
};
|
|
456
|
-
this.clientInfo = (_a = core_1.ClientDevice.clientInfo()) !== null && _a !== void 0 ? _a : {};
|
|
254
|
+
_this.sessionMessageCountMap = {};
|
|
255
|
+
return _this;
|
|
457
256
|
}
|
|
458
|
-
/**
|
|
459
|
-
* get the category of the plugin
|
|
460
|
-
*/
|
|
461
|
-
AWSPinpointProvider.prototype.getCategory = function () {
|
|
462
|
-
return AWSPinpointProvider.category;
|
|
463
|
-
};
|
|
464
257
|
/**
|
|
465
258
|
* get the sub-category of the plugin
|
|
466
259
|
*/
|
|
467
260
|
AWSPinpointProvider.prototype.getSubCategory = function () {
|
|
468
261
|
return AWSPinpointProvider.subCategory;
|
|
469
262
|
};
|
|
470
|
-
/**
|
|
471
|
-
* get provider name of the plugin
|
|
472
|
-
*/
|
|
473
|
-
AWSPinpointProvider.prototype.getProviderName = function () {
|
|
474
|
-
return AWSPinpointProvider.providerName;
|
|
475
|
-
};
|
|
476
|
-
AWSPinpointProvider.category = 'Notifications';
|
|
477
263
|
AWSPinpointProvider.subCategory = 'InAppMessaging';
|
|
478
|
-
AWSPinpointProvider.providerName = 'AWSPinpoint';
|
|
479
264
|
return AWSPinpointProvider;
|
|
480
|
-
}());
|
|
265
|
+
}(common_1.AWSPinpointProviderCommon));
|
|
481
266
|
exports.default = AWSPinpointProvider;
|
|
482
267
|
//# sourceMappingURL=index.js.map
|