@aws-amplify/notifications 2.0.21 → 2.0.22-unstable.1a6d358.0
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/dist/cjs/eventListeners/eventListeners.js +4 -7
- package/dist/cjs/eventListeners/eventListeners.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/clearMessages.js +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/clearMessages.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/dispatchEvent.js +7 -7
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/dispatchEvent.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/identifyUser.js +3 -2
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/identifyUser.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.js +2 -2
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.js +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/setConflictHandler.js +3 -27
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/setConflictHandler.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/syncMessages.js +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/apis/syncMessages.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.js +50 -0
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.js.map +1 -0
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/helpers.js +8 -8
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/helpers.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/index.js +4 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/index.js.map +1 -1
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.js +5 -6
- package/dist/cjs/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.js.map +1 -1
- package/dist/cjs/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js +14 -5
- package/dist/cjs/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js.map +1 -1
- package/dist/cjs/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent.js +1 -1
- package/dist/cjs/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent.js.map +1 -1
- package/dist/esm/eventListeners/eventListeners.d.ts +2 -2
- package/dist/esm/eventListeners/eventListeners.mjs +4 -7
- package/dist/esm/eventListeners/eventListeners.mjs.map +1 -1
- package/dist/esm/eventListeners/types.d.ts +6 -5
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/clearMessages.mjs +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/clearMessages.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/dispatchEvent.mjs +5 -4
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/dispatchEvent.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/identifyUser.d.ts +2 -2
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/identifyUser.mjs +3 -2
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/identifyUser.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.mjs +2 -2
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.d.ts +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.mjs +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.d.ts +1 -2
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.mjs +7 -27
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/setConflictHandler.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/syncMessages.mjs +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/apis/syncMessages.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/types/inputs.d.ts +3 -3
- package/dist/esm/inAppMessaging/providers/pinpoint/types/types.d.ts +4 -4
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.d.ts +13 -0
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.mjs +46 -0
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.mjs.map +1 -0
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/helpers.d.ts +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/helpers.mjs +8 -8
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/helpers.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.d.ts +1 -0
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.mjs +1 -0
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/index.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.d.ts +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.mjs +5 -6
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.mjs.map +1 -1
- package/dist/esm/inAppMessaging/providers/pinpoint/utils/userAgent.mjs.map +1 -1
- package/dist/esm/inAppMessaging/types/event.d.ts +2 -2
- package/dist/esm/inAppMessaging/types/inputs.d.ts +2 -2
- package/dist/esm/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.mjs +14 -5
- package/dist/esm/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.mjs.map +1 -1
- package/dist/esm/pushNotifications/providers/pinpoint/types/analytics.d.ts +2 -2
- package/dist/esm/pushNotifications/providers/pinpoint/types/inputs.d.ts +1 -1
- package/dist/esm/pushNotifications/providers/pinpoint/utils/createMessageEventRecorder.d.ts +1 -1
- package/dist/esm/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent.mjs +1 -1
- package/dist/esm/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent.mjs.map +1 -1
- package/dist/esm/pushNotifications/providers/pinpoint/utils/resolveConfig.mjs.map +1 -1
- package/dist/esm/pushNotifications/types/inputs.d.ts +2 -2
- package/dist/esm/pushNotifications/utils/resolveCredentials.mjs.map +1 -1
- package/package.json +104 -103
- package/src/eventListeners/eventListeners.ts +16 -9
- package/src/eventListeners/types.ts +7 -5
- package/src/inAppMessaging/errors/assertServiceError.ts +1 -0
- package/src/inAppMessaging/providers/pinpoint/apis/clearMessages.ts +3 -2
- package/src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.ts +18 -11
- package/src/inAppMessaging/providers/pinpoint/apis/identifyUser.ts +5 -7
- package/src/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.ts +5 -3
- package/src/inAppMessaging/providers/pinpoint/apis/notifyMessageInteraction.ts +1 -0
- package/src/inAppMessaging/providers/pinpoint/apis/onMessageActionTaken.ts +2 -0
- package/src/inAppMessaging/providers/pinpoint/apis/onMessageDismissed.ts +2 -0
- package/src/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.ts +3 -1
- package/src/inAppMessaging/providers/pinpoint/apis/onMessageReceived.ts +2 -0
- package/src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.ts +7 -34
- package/src/inAppMessaging/providers/pinpoint/apis/syncMessages.ts +12 -10
- package/src/inAppMessaging/providers/pinpoint/types/inputs.ts +8 -7
- package/src/inAppMessaging/providers/pinpoint/types/types.ts +4 -4
- package/src/inAppMessaging/providers/pinpoint/utils/conflictHandlerManager.ts +54 -0
- package/src/inAppMessaging/providers/pinpoint/utils/helpers.ts +19 -9
- package/src/inAppMessaging/providers/pinpoint/utils/index.ts +4 -0
- package/src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts +19 -11
- package/src/inAppMessaging/providers/pinpoint/utils/resolveConfig.ts +2 -0
- package/src/inAppMessaging/providers/pinpoint/utils/resolveCredentials.ts +2 -0
- package/src/inAppMessaging/providers/pinpoint/utils/userAgent.ts +2 -2
- package/src/inAppMessaging/types/event.ts +2 -2
- package/src/inAppMessaging/types/inputs.ts +4 -3
- package/src/pushNotifications/errors/errorHelpers.ts +2 -0
- package/src/pushNotifications/providers/pinpoint/apis/getBadgeCount.native.ts +2 -0
- package/src/pushNotifications/providers/pinpoint/apis/getBadgeCount.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/getLaunchNotification.native.ts +2 -0
- package/src/pushNotifications/providers/pinpoint/apis/getLaunchNotification.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/getPermissionStatus.native.ts +2 -0
- package/src/pushNotifications/providers/pinpoint/apis/getPermissionStatus.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/identifyUser.native.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/identifyUser.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts +21 -12
- package/src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onNotificationOpened.native.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onNotificationOpened.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInBackground.native.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInBackground.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInForeground.native.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onNotificationReceivedInForeground.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onTokenReceived.native.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/onTokenReceived.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/requestPermissions.native.ts +2 -0
- package/src/pushNotifications/providers/pinpoint/apis/requestPermissions.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/setBadgeCount.native.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/apis/setBadgeCount.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/types/analytics.ts +2 -2
- package/src/pushNotifications/providers/pinpoint/types/inputs.ts +4 -3
- package/src/pushNotifications/providers/pinpoint/utils/createMessageEventRecorder.ts +5 -1
- package/src/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent.ts +3 -1
- package/src/pushNotifications/providers/pinpoint/utils/getChannelType.ts +1 -0
- package/src/pushNotifications/providers/pinpoint/utils/resolveConfig.ts +3 -1
- package/src/pushNotifications/types/inputs.ts +4 -3
- package/src/pushNotifications/utils/getPushNotificationUserAgentString.ts +1 -1
- package/src/pushNotifications/utils/resolveCredentials.ts +3 -1
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.incrementMessageCounts = exports.sessionStateChangeHandler = exports.processInAppMessages = void 0;
|
|
7
|
-
const helpers_1 = require("./helpers");
|
|
8
7
|
const core_1 = require("@aws-amplify/core");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
9
|
const MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount';
|
|
10
10
|
const MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount';
|
|
11
11
|
const logger = new core_1.ConsoleLogger('InAppMessaging.processInAppMessages');
|
|
@@ -13,8 +13,7 @@ let sessionMessageCountMap = {};
|
|
|
13
13
|
async function processInAppMessages(messages, event) {
|
|
14
14
|
let highestPrioritySeen;
|
|
15
15
|
let acc = [];
|
|
16
|
-
for (
|
|
17
|
-
const message = messages[index];
|
|
16
|
+
for (const message of messages) {
|
|
18
17
|
const messageQualifies = (0, helpers_1.matchesEventType)(message, event) &&
|
|
19
18
|
(0, helpers_1.matchesAttributes)(message, event) &&
|
|
20
19
|
(0, helpers_1.matchesMetrics)(message, event) &&
|
|
@@ -67,14 +66,14 @@ async function incrementMessageCounts(messageId) {
|
|
|
67
66
|
exports.incrementMessageCounts = incrementMessageCounts;
|
|
68
67
|
function normalizeMessages(messages) {
|
|
69
68
|
return messages.map(message => {
|
|
70
|
-
const { CampaignId, InAppMessage } = message;
|
|
69
|
+
const { CampaignId, InAppMessage: pinpointInAppMessage } = message;
|
|
71
70
|
return {
|
|
72
71
|
// Default to empty string in rare cases we don't have a campaignId
|
|
73
72
|
id: CampaignId ?? '',
|
|
74
73
|
content: (0, helpers_1.extractContent)(message),
|
|
75
74
|
// Default to TOP_BANNER layout in rare cases we don't have a Layout
|
|
76
|
-
layout:
|
|
77
|
-
? (0, helpers_1.interpretLayout)(
|
|
75
|
+
layout: pinpointInAppMessage?.Layout
|
|
76
|
+
? (0, helpers_1.interpretLayout)(pinpointInAppMessage.Layout)
|
|
78
77
|
: 'TOP_BANNER',
|
|
79
78
|
metadata: (0, helpers_1.extractMetadata)(message),
|
|
80
79
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageProcessingHelpers.js","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.incrementMessageCounts = exports.sessionStateChangeHandler = exports.processInAppMessages = void 0;\nconst helpers_1 = require(\"./helpers\");\nconst core_1 = require(\"@aws-amplify/core\");\nconst MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount';\nconst MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount';\nconst logger = new core_1.ConsoleLogger('InAppMessaging.processInAppMessages');\nlet sessionMessageCountMap = {};\nasync function processInAppMessages(messages, event) {\n let highestPrioritySeen;\n let acc = [];\n for (let index = 0; index < messages.length; index++) {\n const message = messages[index];\n const messageQualifies = (0, helpers_1.matchesEventType)(message, event) &&\n (0, helpers_1.matchesAttributes)(message, event) &&\n (0, helpers_1.matchesMetrics)(message, event) &&\n (0, helpers_1.isBeforeEndDate)(message) &&\n (await isBelowCap(message));\n // filter all qualifying messages returning only those that are of (relative) highest priority\n if (messageQualifies) {\n // have not yet encountered message with priority\n if (!highestPrioritySeen) {\n // this message has priority, so reset the accumulator with this message only\n if (message.Priority) {\n highestPrioritySeen = message.Priority;\n acc = [message];\n }\n else {\n // this message also has no priority, so just add this message to accumulator\n acc.push(message);\n }\n // have previously encountered message with priority, so only messages with priority matter now\n }\n else if (message.Priority) {\n // this message has higher priority (lower number), so reset the accumulator with this message only\n if (message.Priority < highestPrioritySeen) {\n highestPrioritySeen = message.Priority;\n acc = [message];\n // this message has the same priority, so just add this message to accumulator\n }\n else if (message.Priority === highestPrioritySeen) {\n acc.push(message);\n }\n }\n }\n }\n return normalizeMessages(acc);\n}\nexports.processInAppMessages = processInAppMessages;\nfunction sessionStateChangeHandler(state) {\n if (state === 'started') {\n // reset all session counts\n sessionMessageCountMap = {};\n }\n}\nexports.sessionStateChangeHandler = sessionStateChangeHandler;\nasync function incrementMessageCounts(messageId) {\n const { sessionCount, dailyCount, totalCount } = await getMessageCounts(messageId);\n setSessionCount(messageId, sessionCount + 1);\n setDailyCount(dailyCount + 1);\n await setTotalCount(messageId, totalCount + 1);\n}\nexports.incrementMessageCounts = incrementMessageCounts;\nfunction normalizeMessages(messages) {\n return messages.map(message => {\n const { CampaignId, InAppMessage } = message;\n return {\n // Default to empty string in rare cases we don't have a campaignId\n id: CampaignId ?? '',\n content: (0, helpers_1.extractContent)(message),\n // Default to TOP_BANNER layout in rare cases we don't have a Layout\n layout: InAppMessage?.Layout\n ? (0, helpers_1.interpretLayout)(InAppMessage.Layout)\n : 'TOP_BANNER',\n metadata: (0, helpers_1.extractMetadata)(message),\n };\n });\n}\nasync function isBelowCap({ CampaignId, SessionCap, DailyCap, TotalCap, }) {\n const { sessionCount, dailyCount, totalCount } = await getMessageCounts(CampaignId);\n return ((!SessionCap || sessionCount < SessionCap) &&\n (!DailyCap || dailyCount < DailyCap) &&\n (!TotalCap || totalCount < TotalCap));\n}\nasync function getMessageCounts(messageId) {\n let messageCounts = {\n sessionCount: 0,\n dailyCount: 0,\n totalCount: 0,\n };\n try {\n // only return true counts if there is a messageId else default to 0\n if (messageId)\n messageCounts = {\n sessionCount: getSessionCount(messageId),\n dailyCount: await getDailyCount(),\n totalCount: await getTotalCount(messageId),\n };\n return messageCounts;\n }\n catch (err) {\n logger.error('Failed to get message counts from storage', err);\n // If there are no cached counts or there is an error,\n // we default to 0 allowing all the messages to be eligible\n return messageCounts;\n }\n}\nfunction getSessionCount(messageId) {\n return sessionMessageCountMap[messageId] ?? 0;\n}\nfunction setSessionCount(messageId, count) {\n sessionMessageCountMap[messageId] = count;\n}\nfunction setDailyCount(count) {\n const dailyCount = {\n count,\n lastCountTimestamp: getStartOfDay(),\n };\n try {\n core_1.defaultStorage.setItem(MESSAGE_DAILY_COUNT_KEY, JSON.stringify(dailyCount));\n }\n catch (err) {\n logger.error('Failed to save daily message count to storage', err);\n }\n}\nfunction setTotalCountMap(countMap) {\n try {\n core_1.defaultStorage.setItem(MESSAGE_TOTAL_COUNT_KEY, JSON.stringify(countMap));\n }\n catch (err) {\n logger.error('Failed to save total count to storage', err);\n }\n}\nasync function setTotalCount(messageId, count) {\n const totalCountMap = await getTotalCountMap();\n const updatedMap = {\n ...totalCountMap,\n [messageId]: count,\n };\n setTotalCountMap(updatedMap);\n}\nasync function getDailyCount() {\n const today = getStartOfDay();\n const item = await core_1.defaultStorage.getItem(MESSAGE_DAILY_COUNT_KEY);\n // Parse stored count or initialize as empty count\n const counter = item\n ? JSON.parse(item)\n : { count: 0, lastCountTimestamp: today };\n // If the stored counter timestamp is today, use it as the count, otherwise reset to 0\n return counter.lastCountTimestamp === today ? counter.count : 0;\n}\nasync function getTotalCountMap() {\n const item = await core_1.defaultStorage.getItem(MESSAGE_TOTAL_COUNT_KEY);\n // Parse stored count map or initialize as empty\n return item ? JSON.parse(item) : {};\n}\nasync function getTotalCount(messageId) {\n const countMap = await getTotalCountMap();\n // Return stored count or initialize as empty count\n return countMap[messageId] || 0;\n}\nconst getStartOfDay = () => {\n const now = new Date();\n now.setHours(0, 0, 0, 0);\n return now.toISOString();\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AAC3G,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACvC,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,uBAAuB,GAAG,2CAA2C,CAAC;AAC5E,MAAM,uBAAuB,GAAG,2CAA2C,CAAC;AAC5E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,qCAAqC,CAAC,CAAC;AAC/E,IAAI,sBAAsB,GAAG,EAAE,CAAC;AAChC,eAAe,oBAAoB,CAAC,QAAQ,EAAE,KAAK,EAAE;AACrD,IAAI,IAAI,mBAAmB,CAAC;AAC5B,IAAI,IAAI,GAAG,GAAG,EAAE,CAAC;AACjB,IAAI,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;AAC1D,QAAQ,MAAM,OA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,EAAE,CAAC;AAClD;AACA,IAAI,OAAO,OAAO,CAAC,kBAAkB,KAAK,KAAK,GAAG,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC;AACpE,CAAC;AACD,eAAe,gBAAgB,GAAG;AAClC,IAAI,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAC9E;AACA,IAAI,OAAO,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACxC,CAAC;AACD,eAAe,aAAa,CAAC,SAAS,EAAE;AACxC,IAAI,MAAM,QAAQ,GAAG,MAAM,gBAAgB,EAAE,CAAC;AAC9C;AACA,IAAI,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AACD,MAAM,aAAa,GAAG,MAAM;AAC5B,IAAI,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;AAC3B,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7B,IAAI,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC;;"}
|
|
1
|
+
{"version":3,"file":"messageProcessingHelpers.js","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/utils/messageProcessingHelpers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.incrementMessageCounts = exports.sessionStateChangeHandler = exports.processInAppMessages = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst helpers_1 = require(\"./helpers\");\nconst MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount';\nconst MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount';\nconst logger = new core_1.ConsoleLogger('InAppMessaging.processInAppMessages');\nlet sessionMessageCountMap = {};\nasync function processInAppMessages(messages, event) {\n let highestPrioritySeen;\n let acc = [];\n for (const message of messages) {\n const messageQualifies = (0, helpers_1.matchesEventType)(message, event) &&\n (0, helpers_1.matchesAttributes)(message, event) &&\n (0, helpers_1.matchesMetrics)(message, event) &&\n (0, helpers_1.isBeforeEndDate)(message) &&\n (await isBelowCap(message));\n // filter all qualifying messages returning only those that are of (relative) highest priority\n if (messageQualifies) {\n // have not yet encountered message with priority\n if (!highestPrioritySeen) {\n // this message has priority, so reset the accumulator with this message only\n if (message.Priority) {\n highestPrioritySeen = message.Priority;\n acc = [message];\n }\n else {\n // this message also has no priority, so just add this message to accumulator\n acc.push(message);\n }\n // have previously encountered message with priority, so only messages with priority matter now\n }\n else if (message.Priority) {\n // this message has higher priority (lower number), so reset the accumulator with this message only\n if (message.Priority < highestPrioritySeen) {\n highestPrioritySeen = message.Priority;\n acc = [message];\n // this message has the same priority, so just add this message to accumulator\n }\n else if (message.Priority === highestPrioritySeen) {\n acc.push(message);\n }\n }\n }\n }\n return normalizeMessages(acc);\n}\nexports.processInAppMessages = processInAppMessages;\nfunction sessionStateChangeHandler(state) {\n if (state === 'started') {\n // reset all session counts\n sessionMessageCountMap = {};\n }\n}\nexports.sessionStateChangeHandler = sessionStateChangeHandler;\nasync function incrementMessageCounts(messageId) {\n const { sessionCount, dailyCount, totalCount } = await getMessageCounts(messageId);\n setSessionCount(messageId, sessionCount + 1);\n setDailyCount(dailyCount + 1);\n await setTotalCount(messageId, totalCount + 1);\n}\nexports.incrementMessageCounts = incrementMessageCounts;\nfunction normalizeMessages(messages) {\n return messages.map(message => {\n const { CampaignId, InAppMessage: pinpointInAppMessage } = message;\n return {\n // Default to empty string in rare cases we don't have a campaignId\n id: CampaignId ?? '',\n content: (0, helpers_1.extractContent)(message),\n // Default to TOP_BANNER layout in rare cases we don't have a Layout\n layout: pinpointInAppMessage?.Layout\n ? (0, helpers_1.interpretLayout)(pinpointInAppMessage.Layout)\n : 'TOP_BANNER',\n metadata: (0, helpers_1.extractMetadata)(message),\n };\n });\n}\nasync function isBelowCap({ CampaignId, SessionCap, DailyCap, TotalCap, }) {\n const { sessionCount, dailyCount, totalCount } = await getMessageCounts(CampaignId);\n return ((!SessionCap || sessionCount < SessionCap) &&\n (!DailyCap || dailyCount < DailyCap) &&\n (!TotalCap || totalCount < TotalCap));\n}\nasync function getMessageCounts(messageId) {\n let messageCounts = {\n sessionCount: 0,\n dailyCount: 0,\n totalCount: 0,\n };\n try {\n // only return true counts if there is a messageId else default to 0\n if (messageId)\n messageCounts = {\n sessionCount: getSessionCount(messageId),\n dailyCount: await getDailyCount(),\n totalCount: await getTotalCount(messageId),\n };\n return messageCounts;\n }\n catch (err) {\n logger.error('Failed to get message counts from storage', err);\n // If there are no cached counts or there is an error,\n // we default to 0 allowing all the messages to be eligible\n return messageCounts;\n }\n}\nfunction getSessionCount(messageId) {\n return sessionMessageCountMap[messageId] ?? 0;\n}\nfunction setSessionCount(messageId, count) {\n sessionMessageCountMap[messageId] = count;\n}\nfunction setDailyCount(count) {\n const dailyCount = {\n count,\n lastCountTimestamp: getStartOfDay(),\n };\n try {\n core_1.defaultStorage.setItem(MESSAGE_DAILY_COUNT_KEY, JSON.stringify(dailyCount));\n }\n catch (err) {\n logger.error('Failed to save daily message count to storage', err);\n }\n}\nfunction setTotalCountMap(countMap) {\n try {\n core_1.defaultStorage.setItem(MESSAGE_TOTAL_COUNT_KEY, JSON.stringify(countMap));\n }\n catch (err) {\n logger.error('Failed to save total count to storage', err);\n }\n}\nasync function setTotalCount(messageId, count) {\n const totalCountMap = await getTotalCountMap();\n const updatedMap = {\n ...totalCountMap,\n [messageId]: count,\n };\n setTotalCountMap(updatedMap);\n}\nasync function getDailyCount() {\n const today = getStartOfDay();\n const item = await core_1.defaultStorage.getItem(MESSAGE_DAILY_COUNT_KEY);\n // Parse stored count or initialize as empty count\n const counter = item\n ? JSON.parse(item)\n : { count: 0, lastCountTimestamp: today };\n // If the stored counter timestamp is today, use it as the count, otherwise reset to 0\n return counter.lastCountTimestamp === today ? counter.count : 0;\n}\nasync function getTotalCountMap() {\n const item = await core_1.defaultStorage.getItem(MESSAGE_TOTAL_COUNT_KEY);\n // Parse stored count map or initialize as empty\n return item ? JSON.parse(item) : {};\n}\nasync function getTotalCount(messageId) {\n const countMap = await getTotalCountMap();\n // Return stored count or initialize as empty count\n return countMap[messageId] || 0;\n}\nconst getStartOfDay = () => {\n const now = new Date();\n now.setHours(0, 0, 0, 0);\n return now.toISOString();\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,yBAAyB,GAAG,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AAC3G,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AACvC,MAAM,uBAAuB,GAAG,2CAA2C,CAAC;AAC5E,MAAM,uBAAuB,GAAG,2CAA2C,CAAC;AAC5E,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,qCAAqC,CAAC,CAAC;AAC/E,IAAI,sBAAsB,GAAG,EAAE,CAAC;AAChC,eAAe,oBAAoB,CAAC,QAAQ,EAAE,KAAK,EAAE;AACrD,IAAI,IAAI,mBAAmB,CAAC;AAC5B,IAAI,IAAI,GAAG,GAAG,EAAE,CAAC;AACjB,IAAI,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;AACpC,QAAQ,MAAM,gBAAgB,GAAG,IAAI,SAAS,CAAC,gBAAgB,EAAE,OAAO,EAAE,KAAK,CAAC;AAChF,YAAY,IAAI,SAAS,CAAC,iBAAiB,EAAE,OAAO,EAAE,KAAK,CAAC;AAC5D,YAAY,IAAI,S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Ac,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAC9E;AACA,IAAI,OAAO,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AACxC,CAAC;AACD,eAAe,aAAa,CAAC,SAAS,EAAE;AACxC,IAAI,MAAM,QAAQ,GAAG,MAAM,gBAAgB,EAAE,CAAC;AAC9C;AACA,IAAI,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AACD,MAAM,aAAa,GAAG,MAAM;AAC5B,IAAI,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;AAC3B,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7B,IAAI,OAAO,GAAG,CAAC,WAAW,EAAE,CAAC;AAC7B,CAAC;;"}
|
package/dist/cjs/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js
CHANGED
|
@@ -47,8 +47,10 @@ const addNativeListeners = () => {
|
|
|
47
47
|
// background tasks will get suspended and all future tasks be deprioritized by the OS if they run for
|
|
48
48
|
// more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from
|
|
49
49
|
// happening
|
|
50
|
-
new Promise((
|
|
51
|
-
setTimeout(() =>
|
|
50
|
+
new Promise((_resolve, reject) => {
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
reject(new Error(`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`));
|
|
53
|
+
}, BACKGROUND_TASK_TIMEOUT * 1000);
|
|
52
54
|
}),
|
|
53
55
|
]);
|
|
54
56
|
}
|
|
@@ -77,8 +79,9 @@ const addNativeListeners = () => {
|
|
|
77
79
|
(0, eventListeners_1.notifyEventListeners)('launchNotificationOpened', message);
|
|
78
80
|
// once we are done with it we can remove the listener
|
|
79
81
|
launchNotificationOpenedListener?.remove();
|
|
82
|
+
launchNotificationOpenedListener = undefined;
|
|
80
83
|
})
|
|
81
|
-
:
|
|
84
|
+
: undefined;
|
|
82
85
|
addMessageEventListener(
|
|
83
86
|
// listen for native notification opened (user tapped on notification, opening the app from background -
|
|
84
87
|
// not quit - state) event and broadcast to library listeners
|
|
@@ -113,10 +116,16 @@ const addAnalyticsListeners = () => {
|
|
|
113
116
|
(0, eventListeners_1.addEventListener)('foregroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_foreground'));
|
|
114
117
|
launchNotificationOpenedListenerRemover = (0, eventListeners_1.addEventListener)('launchNotificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification',
|
|
115
118
|
// once we are done with it we can remove the listener
|
|
116
|
-
|
|
119
|
+
() => {
|
|
120
|
+
launchNotificationOpenedListenerRemover?.remove();
|
|
121
|
+
launchNotificationOpenedListenerRemover = undefined;
|
|
122
|
+
}));
|
|
117
123
|
(0, eventListeners_1.addEventListener)('notificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification',
|
|
118
124
|
// if we are in this state, we no longer need the listener as the app was launched via some other means
|
|
119
|
-
|
|
125
|
+
() => {
|
|
126
|
+
launchNotificationOpenedListenerRemover?.remove();
|
|
127
|
+
launchNotificationOpenedListenerRemover = undefined;
|
|
128
|
+
}));
|
|
120
129
|
};
|
|
121
130
|
const registerDevice = async (address) => {
|
|
122
131
|
const { credentials, identityId } = await (0, utils_2.resolveCredentials)();
|
package/dist/cjs/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializePushNotifications.native.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.initializePushNotifications = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst pinpoint_1 = require(\"@aws-amplify/core/internals/providers/pinpoint\");\nconst react_native_1 = require(\"@aws-amplify/react-native\");\nconst eventListeners_1 = require(\"../../../../eventListeners\");\nconst utils_2 = require(\"../../../utils\");\nconst utils_3 = require(\"../utils\");\nconst { addMessageEventListener, addTokenEventListener, completeNotification, getConstants, registerHeadlessTask, } = (0, react_native_1.loadAmplifyPushNotification)();\nconst logger = new core_1.ConsoleLogger('Notifications.PushNotification');\nconst BACKGROUND_TASK_TIMEOUT = 25; // seconds\nconst initializePushNotifications = () => {\n if ((0, utils_2.isInitialized)()) {\n logger.info('Push notifications have already been enabled');\n return;\n }\n addNativeListeners();\n addAnalyticsListeners();\n (0, utils_2.initialize)();\n};\nexports.initializePushNotifications = initializePushNotifications;\nconst addNativeListeners = () => {\n let launchNotificationOpenedListener;\n const { NativeEvent, NativeHeadlessTaskKey } = getConstants();\n const { BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED, TOKEN_RECEIVED, } = NativeEvent;\n // on platforms that can handle headless tasks, register one to broadcast background message received to\n // library listeners\n if (NativeHeadlessTaskKey) {\n registerHeadlessTask(async (message) => {\n // keep headless task running until handlers have completed their work\n await (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message);\n });\n }\n else if (BACKGROUND_MESSAGE_RECEIVED) {\n // on platforms that can't handle headless tasks, listen for native background message received event and\n // broadcast to library listeners\n addMessageEventListener(BACKGROUND_MESSAGE_RECEIVED, async (message, completionHandlerId) => {\n // keep background task running until handlers have completed their work\n try {\n await Promise.race([\n (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message),\n // background tasks will get suspended and all future tasks be deprioritized by the OS if they run for\n // more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from\n // happening\n new Promise((_, reject) => {\n setTimeout(() => reject(`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`), BACKGROUND_TASK_TIMEOUT * 1000);\n }),\n ]);\n }\n catch (err) {\n logger.error(err);\n }\n finally {\n // notify native module that handlers have completed their work (or timed out)\n if (completionHandlerId) {\n completeNotification(completionHandlerId);\n }\n }\n });\n }\n addMessageEventListener(\n // listen for native foreground message received event and broadcast to library listeners\n FOREGROUND_MESSAGE_RECEIVED, message => {\n (0, eventListeners_1.notifyEventListeners)('foregroundMessageReceived', message);\n });\n launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED\n ? addMessageEventListener(\n // listen for native notification opened app (user tapped on notification, opening the app from quit -\n // not background - state) event. This is broadcasted to an internal listener only as it is not intended\n // for use otherwise as it produces inconsistent results when used within React Native app context\n LAUNCH_NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('launchNotificationOpened', message);\n // once we are done with it we can remove the listener\n launchNotificationOpenedListener?.remove();\n })\n : null;\n addMessageEventListener(\n // listen for native notification opened (user tapped on notification, opening the app from background -\n // not quit - state) event and broadcast to library listeners\n NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('notificationOpened', message);\n // if we are in this state, we no longer need the listener as the app was launched via some other means\n launchNotificationOpenedListener?.remove();\n });\n addTokenEventListener(\n // listen for native new token event, automatically re-register device with provider using new token and\n // broadcast to library listeners\n TOKEN_RECEIVED, async (token) => {\n // avoid a race condition where two endpoints are created with the same token on a fresh install\n if ((0, utils_2.getToken)() === token) {\n return;\n }\n (0, utils_2.setToken)(token);\n (0, eventListeners_1.notifyEventListeners)('tokenReceived', token);\n try {\n await registerDevice(token);\n }\n catch (err) {\n logger.error('Failed to register device for push notifications', err);\n throw err;\n }\n });\n};\nconst addAnalyticsListeners = () => {\n let launchNotificationOpenedListenerRemover;\n // wire up default Pinpoint message event handling\n (0, eventListeners_1.addEventListener)('backgroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_background'));\n (0, eventListeners_1.addEventListener)('foregroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_foreground'));\n launchNotificationOpenedListenerRemover = (0, eventListeners_1.addEventListener)('launchNotificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // once we are done with it we can remove the listener\n launchNotificationOpenedListenerRemover?.remove));\n (0, eventListeners_1.addEventListener)('notificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // if we are in this state, we no longer need the listener as the app was launched via some other means\n launchNotificationOpenedListenerRemover?.remove));\n};\nconst registerDevice = async (address) => {\n const { credentials, identityId } = await (0, utils_2.resolveCredentials)();\n const { appId, region } = (0, utils_3.resolveConfig)();\n await (0, pinpoint_1.updateEndpoint)({\n address,\n appId,\n category: 'PushNotification',\n credentials,\n region,\n channelType: (0, utils_3.getChannelType)(),\n identityId,\n userAgentValue: (0, utils_2.getPushNotificationUserAgentString)(utils_1.PushNotificationAction.InitializePushNotifications),\n });\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,2BAA2B,GAAG,KAAK,CAAC,CAAC;AAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAAC;AAC7E,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC5D,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,YAAY,EAAE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ACtD,CAAC,CAAC;AACF,MAAM,cAAc,GAAG,OAAO,OAAO,KAAK;AAC1C,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,OAAO,CAAC,kBAAkB,GAAG,CAAC;AAChF,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,aAAa,GAAG,CAAC;AAC3D,IAAI,MAAM,IAAI,UAAU,CAAC,cAAc,EAAE;AACzC,QAAQ,OAAO;AACf,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,kBAAkB;AACpC,QAAQ,WAAW;AACnB,QAAQ,MAAM;AACd,QAAQ,WAAW,EAAE,IAAI,OAAO,CAAC,cAAc,GAAG;AAClD,QAAQ,UAAU;AAClB,QAAQ,cAAc,EAAE,IAAI,OAAO,CAAC,kCAAkC,EAAE,OAAO,CAAC,sBAAsB,CAAC,2BAA2B,CAAC;AACnI,KAAK,CAAC,CAAC;AACP,CAAC;;"}
|
|
1
|
+
{"version":3,"file":"initializePushNotifications.native.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/apis/initializePushNotifications.native.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.initializePushNotifications = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst pinpoint_1 = require(\"@aws-amplify/core/internals/providers/pinpoint\");\nconst react_native_1 = require(\"@aws-amplify/react-native\");\nconst eventListeners_1 = require(\"../../../../eventListeners\");\nconst utils_2 = require(\"../../../utils\");\nconst utils_3 = require(\"../utils\");\nconst { addMessageEventListener, addTokenEventListener, completeNotification, getConstants, registerHeadlessTask, } = (0, react_native_1.loadAmplifyPushNotification)();\nconst logger = new core_1.ConsoleLogger('Notifications.PushNotification');\nconst BACKGROUND_TASK_TIMEOUT = 25; // seconds\nconst initializePushNotifications = () => {\n if ((0, utils_2.isInitialized)()) {\n logger.info('Push notifications have already been enabled');\n return;\n }\n addNativeListeners();\n addAnalyticsListeners();\n (0, utils_2.initialize)();\n};\nexports.initializePushNotifications = initializePushNotifications;\nconst addNativeListeners = () => {\n let launchNotificationOpenedListener;\n const { NativeEvent, NativeHeadlessTaskKey } = getConstants();\n const { BACKGROUND_MESSAGE_RECEIVED, FOREGROUND_MESSAGE_RECEIVED, LAUNCH_NOTIFICATION_OPENED, NOTIFICATION_OPENED, TOKEN_RECEIVED, } = NativeEvent;\n // on platforms that can handle headless tasks, register one to broadcast background message received to\n // library listeners\n if (NativeHeadlessTaskKey) {\n registerHeadlessTask(async (message) => {\n // keep headless task running until handlers have completed their work\n await (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message);\n });\n }\n else if (BACKGROUND_MESSAGE_RECEIVED) {\n // on platforms that can't handle headless tasks, listen for native background message received event and\n // broadcast to library listeners\n addMessageEventListener(BACKGROUND_MESSAGE_RECEIVED, async (message, completionHandlerId) => {\n // keep background task running until handlers have completed their work\n try {\n await Promise.race([\n (0, eventListeners_1.notifyEventListenersAndAwaitHandlers)('backgroundMessageReceived', message),\n // background tasks will get suspended and all future tasks be deprioritized by the OS if they run for\n // more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from\n // happening\n new Promise((_resolve, reject) => {\n setTimeout(() => {\n reject(new Error(`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`));\n }, BACKGROUND_TASK_TIMEOUT * 1000);\n }),\n ]);\n }\n catch (err) {\n logger.error(err);\n }\n finally {\n // notify native module that handlers have completed their work (or timed out)\n if (completionHandlerId) {\n completeNotification(completionHandlerId);\n }\n }\n });\n }\n addMessageEventListener(\n // listen for native foreground message received event and broadcast to library listeners\n FOREGROUND_MESSAGE_RECEIVED, message => {\n (0, eventListeners_1.notifyEventListeners)('foregroundMessageReceived', message);\n });\n launchNotificationOpenedListener = LAUNCH_NOTIFICATION_OPENED\n ? addMessageEventListener(\n // listen for native notification opened app (user tapped on notification, opening the app from quit -\n // not background - state) event. This is broadcasted to an internal listener only as it is not intended\n // for use otherwise as it produces inconsistent results when used within React Native app context\n LAUNCH_NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('launchNotificationOpened', message);\n // once we are done with it we can remove the listener\n launchNotificationOpenedListener?.remove();\n launchNotificationOpenedListener = undefined;\n })\n : undefined;\n addMessageEventListener(\n // listen for native notification opened (user tapped on notification, opening the app from background -\n // not quit - state) event and broadcast to library listeners\n NOTIFICATION_OPENED, message => {\n (0, eventListeners_1.notifyEventListeners)('notificationOpened', message);\n // if we are in this state, we no longer need the listener as the app was launched via some other means\n launchNotificationOpenedListener?.remove();\n });\n addTokenEventListener(\n // listen for native new token event, automatically re-register device with provider using new token and\n // broadcast to library listeners\n TOKEN_RECEIVED, async (token) => {\n // avoid a race condition where two endpoints are created with the same token on a fresh install\n if ((0, utils_2.getToken)() === token) {\n return;\n }\n (0, utils_2.setToken)(token);\n (0, eventListeners_1.notifyEventListeners)('tokenReceived', token);\n try {\n await registerDevice(token);\n }\n catch (err) {\n logger.error('Failed to register device for push notifications', err);\n throw err;\n }\n });\n};\nconst addAnalyticsListeners = () => {\n let launchNotificationOpenedListenerRemover;\n // wire up default Pinpoint message event handling\n (0, eventListeners_1.addEventListener)('backgroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_background'));\n (0, eventListeners_1.addEventListener)('foregroundMessageReceived', (0, utils_3.createMessageEventRecorder)('received_foreground'));\n launchNotificationOpenedListenerRemover = (0, eventListeners_1.addEventListener)('launchNotificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // once we are done with it we can remove the listener\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n (0, eventListeners_1.addEventListener)('notificationOpened', (0, utils_3.createMessageEventRecorder)('opened_notification', \n // if we are in this state, we no longer need the listener as the app was launched via some other means\n () => {\n launchNotificationOpenedListenerRemover?.remove();\n launchNotificationOpenedListenerRemover = undefined;\n }));\n};\nconst registerDevice = async (address) => {\n const { credentials, identityId } = await (0, utils_2.resolveCredentials)();\n const { appId, region } = (0, utils_3.resolveConfig)();\n await (0, pinpoint_1.updateEndpoint)({\n address,\n appId,\n category: 'PushNotification',\n credentials,\n region,\n channelType: (0, utils_3.getChannelType)(),\n identityId,\n userAgentValue: (0, utils_2.getPushNotificationUserAgentString)(utils_1.PushNotificationAction.InitializePushNotifications),\n });\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,2BAA2B,GAAG,KAAK,CAAC,CAAC;AAC7C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,UAAU,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAAC;AAC7E,MAAM,cAAc,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAC5D,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC/D,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,YAAY,EAAE,oBAAoB,GAAG,GAAG,IAAI,cAAc,CAAC,2BAA2B,GAAG,CAAC;AACxK,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,gCAAgC,CAAC,CAAC;AAC1E,MAAM,uBAAuB,GAAG,EAAE,CAAC;AACnC,MAAM,2BAA2B,GAAG,MAAM;AAC1C,IA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GAAG,SAAS,CAAC;AAC5D,KAAK,CAAC,CAAC,CAAC;AACR,CAAC,CAAC;AACF,MAAM,cAAc,GAAG,OAAO,OAAO,KAAK;AAC1C,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,IAAI,OAAO,CAAC,kBAAkB,GAAG,CAAC;AAChF,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,OAAO,CAAC,aAAa,GAAG,CAAC;AAC3D,IAAI,MAAM,IAAI,UAAU,CAAC,cAAc,EAAE;AACzC,QAAQ,OAAO;AACf,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,kBAAkB;AACpC,QAAQ,WAAW;AACnB,QAAQ,MAAM;AACd,QAAQ,WAAW,EAAE,IAAI,OAAO,CAAC,cAAc,GAAG;AAClD,QAAQ,UAAU;AAClB,QAAQ,cAAc,EAAE,IAAI,OAAO,CAAC,kCAAkC,EAAE,OAAO,CAAC,sBAAsB,CAAC,2BAA2B,CAAC;AACnI,KAAK,CAAC,CAAC;AACP,CAAC;;"}
|
|
@@ -29,7 +29,7 @@ const getAnalyticsEventAttributes = (data) => {
|
|
|
29
29
|
if (!data) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
if (
|
|
32
|
+
if (Object.prototype.hasOwnProperty.call(data, ANDROID_CAMPAIGN_ID_KEY)) {
|
|
33
33
|
return {
|
|
34
34
|
source: '_campaign',
|
|
35
35
|
attributes: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAnalyticsEvent.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getAnalyticsEvent = void 0;\nconst ANDROID_CAMPAIGN_ACTIVITY_ID_KEY = 'pinpoint.campaign.campaign_activity_id';\nconst ANDROID_CAMPAIGN_ID_KEY = 'pinpoint.campaign.campaign_id';\nconst ANDROID_CAMPAIGN_TREATMENT_ID_KEY = 'pinpoint.campaign.treatment_id';\n/**\n * @internal\n */\nconst getAnalyticsEvent = ({ data }, event) => {\n if (!data) {\n return null;\n }\n const eventAttributes = getAnalyticsEventAttributes(data);\n if (!eventAttributes) {\n return null;\n }\n const { source, attributes } = eventAttributes;\n return {\n attributes,\n name: `${source}.${event}`,\n };\n};\nexports.getAnalyticsEvent = getAnalyticsEvent;\nconst getAnalyticsEventAttributes = (data) => {\n if (!data) {\n return;\n }\n if (
|
|
1
|
+
{"version":3,"file":"getAnalyticsEvent.js","sources":["../../../../../../src/pushNotifications/providers/pinpoint/utils/getAnalyticsEvent.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getAnalyticsEvent = void 0;\nconst ANDROID_CAMPAIGN_ACTIVITY_ID_KEY = 'pinpoint.campaign.campaign_activity_id';\nconst ANDROID_CAMPAIGN_ID_KEY = 'pinpoint.campaign.campaign_id';\nconst ANDROID_CAMPAIGN_TREATMENT_ID_KEY = 'pinpoint.campaign.treatment_id';\n/**\n * @internal\n */\nconst getAnalyticsEvent = ({ data }, event) => {\n if (!data) {\n return null;\n }\n const eventAttributes = getAnalyticsEventAttributes(data);\n if (!eventAttributes) {\n return null;\n }\n const { source, attributes } = eventAttributes;\n return {\n attributes,\n name: `${source}.${event}`,\n };\n};\nexports.getAnalyticsEvent = getAnalyticsEvent;\nconst getAnalyticsEventAttributes = (data) => {\n if (!data) {\n return;\n }\n if (Object.prototype.hasOwnProperty.call(data, ANDROID_CAMPAIGN_ID_KEY)) {\n return {\n source: '_campaign',\n attributes: {\n campaign_activity_id: data[ANDROID_CAMPAIGN_ACTIVITY_ID_KEY],\n campaign_id: data[ANDROID_CAMPAIGN_ID_KEY],\n treatment_id: data[ANDROID_CAMPAIGN_TREATMENT_ID_KEY],\n },\n };\n }\n const pinpoint = typeof data.pinpoint === 'string'\n ? JSON.parse(data.pinpoint)\n : data.pinpoint;\n if (pinpoint?.campaign) {\n return {\n source: '_campaign',\n attributes: pinpoint.campaign,\n };\n }\n if (pinpoint?.journey) {\n return {\n source: '_journey',\n attributes: pinpoint.journey,\n };\n }\n};\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iBAAiB,GAAG,KAAK,CAAC,CAAC;AACnC,MAAM,gCAAgC,GAAG,wCAAwC,CAAC;AAClF,MAAM,uBAAuB,GAAG,+BAA+B,CAAC;AAChE,MAAM,iCAAiC,GAAG,gCAAgC,CAAC;AAC3E;AACA;AACA;AACA,MAAM,iBAAiB,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,KAAK;AAC/C,IAAI,IAAI,CAAC,IAAI,EAAE;AACf,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,MAAM,eAAe,GAAG,2BAA2B,CAAC,IAAI,CAAC,CAAC;AAC9D,IAAI,IAAI,CAAC,eAAe,EAAE;AAC1B,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL,IAAI,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,eAAe,CAAC;AACnD,IAAI,OAAO;AACX,QAAQ,UAAU;AAClB,QAAQ,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAClC,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,2BAA2B,GAAG,CAAC,IAAI,KAAK;AAC9C,IAAI,IAAI,CAAC,IAAI,EAAE;AACf,QAAQ,OAAO;AACf,KAAK;AACL,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,uBAAuB,CAAC,EAAE;AAC7E,QAAQ,OAAO;AACf,YAAY,MAAM,EAAE,WAAW;AAC/B,YAAY,UAAU,EAAE;AACxB,gBAAgB,oBAAoB,EAAE,IAAI,CAAC,gCAAgC,CAAC;AAC5E,gBAAgB,WAAW,EAAE,IAAI,CAAC,uBAAuB,CAAC;AAC1D,gBAAgB,YAAY,EAAE,IAAI,CAAC,iCAAiC,CAAC;AACrE,aAAa;AACb,SAAS,CAAC;AACV,KAAK;AACL,IAAI,MAAM,QAAQ,GAAG,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ;AACtD,UAAU,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC;AACnC,UAAU,IAAI,CAAC,QAAQ,CAAC;AACxB,IAAI,IAAI,QAAQ,EAAE,QAAQ,EAAE;AAC5B,QAAQ,OAAO;AACf,YAAY,MAAM,EAAE,WAAW;AAC/B,YAAY,UAAU,EAAE,QAAQ,CAAC,QAAQ;AACzC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,IAAI,QAAQ,EAAE,OAAO,EAAE;AAC3B,QAAQ,OAAO;AACf,YAAY,MAAM,EAAE,UAAU;AAC9B,YAAY,UAAU,EAAE,QAAQ,CAAC,OAAO;AACxC,SAAS,CAAC;AACV,KAAK;AACL,CAAC;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventListenerRemover, EventType } from './types';
|
|
1
|
+
import { EventListenerHandler, EventListenerRemover, EventType } from './types';
|
|
2
2
|
export declare const notifyEventListeners: (type: EventType, ...args: any[]) => void;
|
|
3
3
|
export declare const notifyEventListenersAndAwaitHandlers: (type: EventType, ...args: any[]) => Promise<void[]>;
|
|
4
|
-
export declare const addEventListener: <EventHandler extends
|
|
4
|
+
export declare const addEventListener: <EventHandler extends EventListenerHandler>(type: EventType, handler: EventHandler) => EventListenerRemover;
|
|
@@ -7,12 +7,7 @@ const notifyEventListeners = (type, ...args) => {
|
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
9
|
const notifyEventListenersAndAwaitHandlers = (type, ...args) => Promise.all(Array.from(eventListeners[type] ?? []).map(async (listener) => {
|
|
10
|
-
|
|
11
|
-
await listener.handleEvent(...args);
|
|
12
|
-
}
|
|
13
|
-
catch (err) {
|
|
14
|
-
throw err;
|
|
15
|
-
}
|
|
10
|
+
await listener.handleEvent(...args);
|
|
16
11
|
}));
|
|
17
12
|
const addEventListener = (type, handler) => {
|
|
18
13
|
// If there is no listener set for the event type, just create it
|
|
@@ -27,7 +22,9 @@ const addEventListener = (type, handler) => {
|
|
|
27
22
|
};
|
|
28
23
|
eventListeners[type].add(listener);
|
|
29
24
|
return {
|
|
30
|
-
remove: () =>
|
|
25
|
+
remove: () => {
|
|
26
|
+
listener.remove();
|
|
27
|
+
},
|
|
31
28
|
};
|
|
32
29
|
};
|
|
33
30
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventListeners.mjs","sources":["../../../src/eventListeners/eventListeners.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst eventListeners = {};\nexport const notifyEventListeners = (type, ...args) => {\n eventListeners[type]?.forEach(listener => {\n listener.handleEvent(...args);\n });\n};\nexport const notifyEventListenersAndAwaitHandlers = (type, ...args) => Promise.all(Array.from(eventListeners[type] ?? []).map(async (listener) => {\n
|
|
1
|
+
{"version":3,"file":"eventListeners.mjs","sources":["../../../src/eventListeners/eventListeners.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst eventListeners = {};\nexport const notifyEventListeners = (type, ...args) => {\n eventListeners[type]?.forEach(listener => {\n listener.handleEvent(...args);\n });\n};\nexport const notifyEventListenersAndAwaitHandlers = (type, ...args) => Promise.all(Array.from(eventListeners[type] ?? []).map(async (listener) => {\n await listener.handleEvent(...args);\n}));\nexport const addEventListener = (type, handler) => {\n // If there is no listener set for the event type, just create it\n if (!eventListeners[type]) {\n eventListeners[type] = new Set();\n }\n const listener = {\n handleEvent: handler,\n remove: () => {\n eventListeners[type].delete(listener);\n },\n };\n eventListeners[type].add(listener);\n return {\n remove: () => {\n listener.remove();\n },\n };\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA,MAAM,cAAc,GAAG,EAAE,CAAC;AACd,MAAC,oBAAoB,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,KAAK;AACvD,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,IAAI;AAC9C,QAAQ,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;AACtC,KAAK,CAAC,CAAC;AACP,EAAE;AACU,MAAC,oCAAoC,GAAG,CAAC,IAAI,EAAE,GAAG,IAAI,KAAK,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,QAAQ,KAAK;AAClJ,IAAI,MAAM,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;AACxC,CAAC,CAAC,EAAE;AACQ,MAAC,gBAAgB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK;AACnD;AACA,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE;AAC/B,QAAQ,cAAc,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;AACzC,KAAK;AACL,IAAI,MAAM,QAAQ,GAAG;AACrB,QAAQ,WAAW,EAAE,OAAO;AAC5B,QAAQ,MAAM,EAAE,MAAM;AACtB,YAAY,cAAc,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAClD,SAAS;AACT,KAAK,CAAC;AACN,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACvC,IAAI,OAAO;AACX,QAAQ,MAAM,EAAE,MAAM;AACtB,YAAY,QAAQ,CAAC,MAAM,EAAE,CAAC;AAC9B,SAAS;AACT,KAAK,CAAC;AACN;;;;"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { InAppMessageInteractionEvent } from '../inAppMessaging/types';
|
|
2
2
|
import { PushNotificationEvent } from '../pushNotifications/types';
|
|
3
|
-
export
|
|
3
|
+
export type EventListenerHandler = (...args: any[]) => unknown;
|
|
4
|
+
export interface EventListener<EventHandler extends EventListenerHandler> {
|
|
4
5
|
handleEvent: EventHandler;
|
|
5
|
-
remove
|
|
6
|
+
remove(): void;
|
|
6
7
|
}
|
|
7
8
|
export type EventType = InAppMessageInteractionEvent | PushNotificationEvent;
|
|
8
|
-
export
|
|
9
|
-
remove
|
|
10
|
-
}
|
|
9
|
+
export interface EventListenerRemover {
|
|
10
|
+
remove(): void;
|
|
11
|
+
}
|
|
@@ -22,7 +22,7 @@ import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
|
22
22
|
async function clearMessages() {
|
|
23
23
|
assertIsInitialized();
|
|
24
24
|
const key = `${PINPOINT_KEY_PREFIX}${STORAGE_KEY_SUFFIX}`;
|
|
25
|
-
|
|
25
|
+
await defaultStorage.removeItem(key);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export { clearMessages };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clearMessages.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/clearMessages.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { defaultStorage } from '@aws-amplify/core';\nimport {
|
|
1
|
+
{"version":3,"file":"clearMessages.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/clearMessages.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { defaultStorage } from '@aws-amplify/core';\nimport { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX } from '../utils';\nimport { assertIsInitialized } from '../../../utils';\n/**\n * Clear locally cached messages.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown if In App messaging hasn't been initialized.\n * @returns A promise that will resolve when the operation is complete.\n * @example\n * ```ts\n * // Clear locally cached messages.\n * await clearMessages();\n *\n * ```\n */\nexport async function clearMessages() {\n assertIsInitialized();\n const key = `${PINPOINT_KEY_PREFIX}${STORAGE_KEY_SUFFIX}`;\n await defaultStorage.removeItem(key);\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,aAAa,GAAG;AACtC,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,MAAM,GAAG,GAAG,CAAC,EAAE,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC9D,IAAI,MAAM,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACzC;;;;"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import flatten from 'lodash/flatten.js';
|
|
1
2
|
import { defaultStorage } from '@aws-amplify/core';
|
|
3
|
+
import { notifyEventListeners } from '../../../../eventListeners/eventListeners.mjs';
|
|
2
4
|
import '@aws-amplify/core/internals/utils';
|
|
3
5
|
import '../../../errors/validation.mjs';
|
|
4
6
|
import { assertServiceError } from '../../../errors/assertServiceError.mjs';
|
|
7
|
+
import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
8
|
+
import { getConflictHandler } from '../utils/conflictHandlerManager.mjs';
|
|
5
9
|
import { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX } from '../utils/constants.mjs';
|
|
6
10
|
import { processInAppMessages } from '../utils/messageProcessingHelpers.mjs';
|
|
7
|
-
import flatten from 'lodash/flatten.js';
|
|
8
|
-
import { notifyEventListeners } from '../../../../eventListeners/eventListeners.mjs';
|
|
9
|
-
import { conflictHandler } from './setConflictHandler.mjs';
|
|
10
|
-
import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
11
11
|
|
|
12
12
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
13
13
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -46,6 +46,7 @@ async function dispatchEvent(input) {
|
|
|
46
46
|
const messages = await processInAppMessages(cachedMessages ? JSON.parse(cachedMessages) : [], input);
|
|
47
47
|
const flattenedMessages = flatten(messages);
|
|
48
48
|
if (flattenedMessages.length > 0) {
|
|
49
|
+
const conflictHandler = getConflictHandler();
|
|
49
50
|
notifyEventListeners('messageReceived', conflictHandler(flattenedMessages));
|
|
50
51
|
}
|
|
51
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatchEvent.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport
|
|
1
|
+
{"version":3,"file":"dispatchEvent.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/dispatchEvent.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport flatten from 'lodash/flatten.js';\nimport { defaultStorage } from '@aws-amplify/core';\nimport { notifyEventListeners } from '../../../../eventListeners';\nimport { assertServiceError, } from '../../../errors';\nimport { assertIsInitialized } from '../../../utils';\nimport { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX, getConflictHandler, processInAppMessages, } from '../utils';\n/**\n * Triggers an In-App message to be displayed. Use this after your campaigns have been synced to the device using\n * {@link syncMessages}. Based on the messages synced and the event passed to this API, it triggers the display\n * of the In-App message that meets the criteria.\n *\n * @remark\n * If an event would trigger multiple messages, the message closest to expiry will be chosen by default.\n * To change this behavior, you can use the {@link setConflictHandler} API to provide\n * your own logic for resolving message conflicts.\n *\n * @param input The input object that holds the event to be dispatched.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @throws service exceptions - Thrown when the underlying Pinpoint service returns an error.\n *\n * @returns A promise that will resolve when the operation is complete.\n *\n * @example\n * ```ts\n * // Sync message before disptaching an event\n * await syncMessages();\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nexport async function dispatchEvent(input) {\n assertIsInitialized();\n try {\n const key = `${PINPOINT_KEY_PREFIX}${STORAGE_KEY_SUFFIX}`;\n const cachedMessages = await defaultStorage.getItem(key);\n const messages = await processInAppMessages(cachedMessages ? JSON.parse(cachedMessages) : [], input);\n const flattenedMessages = flatten(messages);\n if (flattenedMessages.length > 0) {\n const conflictHandler = getConflictHandler();\n notifyEventListeners('messageReceived', conflictHandler(flattenedMessages));\n }\n }\n catch (error) {\n assertServiceError(error);\n throw error;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,aAAa,CAAC,KAAK,EAAE;AAC3C,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,IAAI;AACR,QAAQ,MAAM,GAAG,GAAG,CAAC,EAAE,mBAAmB,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAClE,QAAQ,MAAM,cAAc,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AACjE,QAAQ,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC;AAC7G,QAAQ,MAAM,iBAAiB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AACpD,QAAQ,IAAI,iBAAiB,CAAC,MAAM,GAAG,CAAC,EAAE;AAC1C,YAAY,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAC;AACzD,YAAY,oBAAoB,CAAC,iBAAiB,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACxF,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAClC,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL;;;;"}
|
|
@@ -4,7 +4,7 @@ import { IdentifyUserInput } from '../types';
|
|
|
4
4
|
* profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
|
|
5
5
|
* the same `userId`.
|
|
6
6
|
*
|
|
7
|
-
* @param
|
|
7
|
+
* @param input The input object that conforms to {@link IdentifyUserInput} used to construct requests sent to Pinpoint's UpdateEndpoint
|
|
8
8
|
* API.
|
|
9
9
|
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
|
|
10
10
|
* @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
|
|
@@ -48,4 +48,4 @@ import { IdentifyUserInput } from '../types';
|
|
|
48
48
|
* },
|
|
49
49
|
* });
|
|
50
50
|
*/
|
|
51
|
-
export declare const identifyUser: (
|
|
51
|
+
export declare const identifyUser: (input: IdentifyUserInput) => Promise<void>;
|
|
@@ -14,7 +14,7 @@ import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
|
14
14
|
* profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
|
|
15
15
|
* the same `userId`.
|
|
16
16
|
*
|
|
17
|
-
* @param
|
|
17
|
+
* @param input The input object that conforms to {@link IdentifyUserInput} used to construct requests sent to Pinpoint's UpdateEndpoint
|
|
18
18
|
* API.
|
|
19
19
|
* @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
|
|
20
20
|
* @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
|
|
@@ -58,7 +58,8 @@ import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
|
58
58
|
* },
|
|
59
59
|
* });
|
|
60
60
|
*/
|
|
61
|
-
const identifyUser = async (
|
|
61
|
+
const identifyUser = async (input) => {
|
|
62
|
+
const { userId, userProfile, options } = input;
|
|
62
63
|
assertIsInitialized();
|
|
63
64
|
const { credentials, identityId } = await resolveCredentials();
|
|
64
65
|
const { appId, region } = resolveConfig();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifyUser.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/identifyUser.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { InAppMessagingAction } from '@aws-amplify/core/internals/utils';\nimport { updateEndpoint, } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { CATEGORY, CHANNEL_TYPE, getInAppMessagingUserAgentString, resolveConfig, resolveCredentials, } from '../utils';\nimport { assertIsInitialized } from '../../../utils';\n/**\n * Sends information about a user to Pinpoint. Sending user information allows you to associate a user to their user\n * profile and activities or actions in your application. Activity can be tracked across devices & platforms by using\n * the same `userId`.\n *\n * @param
|
|
1
|
+
{"version":3,"file":"identifyUser.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/identifyUser.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { InAppMessagingAction } from '@aws-amplify/core/internals/utils';\nimport { updateEndpoint, } from '@aws-amplify/core/internals/providers/pinpoint';\nimport { CATEGORY, CHANNEL_TYPE, getInAppMessagingUserAgentString, resolveConfig, resolveCredentials, } from '../utils';\nimport { assertIsInitialized } from '../../../utils';\n/**\n * Sends information about a user to Pinpoint. Sending user information allows you to associate a user to their user\n * profile and activities or actions in your application. Activity can be tracked across devices & platforms by using\n * the same `userId`.\n *\n * @param input The input object that conforms to {@link IdentifyUserInput} used to construct requests sent to Pinpoint's UpdateEndpoint\n * API.\n * @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @returns A promise that will resolve when the operation is complete.\n * @example\n * ```ts\n * // Identify a user with Pinpoint\n * await identifyUser({\n * userId,\n * userProfile: {\n * email: 'userEmail@example.com'\n * customProperties: {\n * phoneNumber: ['555-555-5555'],\n * },\n * }\n * });\n * ```\n *\n * @example\n * ```ts\n * // Identify a user with Pinpoint specific options\n * await identifyUser({\n * userId,\n * userProfile: {\n * email: 'userEmail@example.com'\n * customProperties: {\n * phoneNumber: ['555-555-5555'],\n * },\n * demographic: {\n * platform: 'ios',\n * timezone: 'America/Los_Angeles'\n * }\n * },\n * options: {\n * address: 'device-address',\n * optOut: 'NONE',\n * userAttributes: {\n * interests: ['food']\n * },\n * },\n * });\n */\nexport const identifyUser = async (input) => {\n const { userId, userProfile, options } = input;\n assertIsInitialized();\n const { credentials, identityId } = await resolveCredentials();\n const { appId, region } = resolveConfig();\n const { address, optOut, userAttributes } = options ?? {};\n updateEndpoint({\n address,\n channelType: CHANNEL_TYPE,\n optOut,\n appId,\n category: CATEGORY,\n credentials,\n identityId,\n region,\n userAttributes,\n userId,\n userProfile,\n userAgentValue: getInAppMessagingUserAgentString(InAppMessagingAction.IdentifyUser),\n });\n};\n"],"names":[],"mappings":";;;;;;;;;AAAA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,YAAY,GAAG,OAAO,KAAK,KAAK;AAC7C,IAAI,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;AACnD,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,kBAAkB,EAAE,CAAC;AACnE,IAAI,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,aAAa,EAAE,CAAC;AAC9C,IAAI,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;AAC9D,IAAI,cAAc,CAAC;AACnB,QAAQ,OAAO;AACf,QAAQ,WAAW,EAAE,YAAY;AACjC,QAAQ,MAAM;AACd,QAAQ,KAAK;AACb,QAAQ,QAAQ,EAAE,QAAQ;AAC1B,QAAQ,WAAW;AACnB,QAAQ,UAAU;AAClB,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,MAAM;AACd,QAAQ,WAAW;AACnB,QAAQ,cAAc,EAAE,gCAAgC,CAAC,oBAAoB,CAAC,YAAY,CAAC;AAC3F,KAAK,CAAC,CAAC;AACP;;;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { sessionListener } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { Hub } from '@aws-amplify/core';
|
|
2
3
|
import { addEventListener } from '../../../../eventListeners/eventListeners.mjs';
|
|
3
4
|
import { recordAnalyticsEvent } from '../utils/helpers.mjs';
|
|
4
5
|
import { PinpointMessageEvent } from '../types/types.mjs';
|
|
5
|
-
import { Hub } from '@aws-amplify/core';
|
|
6
|
-
import { dispatchEvent } from './dispatchEvent.mjs';
|
|
7
6
|
import '../../../errors/validation.mjs';
|
|
8
7
|
import { sessionStateChangeHandler, incrementMessageCounts } from '../utils/messageProcessingHelpers.mjs';
|
|
9
8
|
import { isInitialized, initialize } from '../../../utils/statusHelpers.mjs';
|
|
9
|
+
import { dispatchEvent } from './dispatchEvent.mjs';
|
|
10
10
|
|
|
11
11
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
12
12
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializeInAppMessaging.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { sessionListener } from '@aws-amplify/core/internals/utils';\nimport {
|
|
1
|
+
{"version":3,"file":"initializeInAppMessaging.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/initializeInAppMessaging.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { sessionListener } from '@aws-amplify/core/internals/utils';\nimport { Hub } from '@aws-amplify/core';\nimport { addEventListener } from '../../../../eventListeners';\nimport { recordAnalyticsEvent } from '../utils/helpers';\nimport { PinpointMessageEvent } from '../types';\nimport { incrementMessageCounts, sessionStateChangeHandler } from '../utils';\nimport { initialize, isInitialized } from '../../../utils';\nimport { dispatchEvent } from './dispatchEvent';\n/**\n * Initialize and set up in-app messaging category. This API needs to be called to enable other InAppMessaging APIs.\n *\n * @remarks\n * Make sure to call this early in your app at the root entry point after configuring Amplify.\n * @example\n * ```ts\n * Amplify.configure(config);\n * initializeInAppMessaging();\n * ```\n */\nexport function initializeInAppMessaging() {\n if (isInitialized()) {\n return;\n }\n // register with the session listener\n sessionListener.addStateChangeListener(sessionStateChangeHandler, true);\n // wire up default Pinpoint message event handling\n addEventListener('messageDisplayed', (message) => {\n recordAnalyticsEvent(PinpointMessageEvent.MESSAGE_DISPLAYED, message);\n incrementMessageCounts(message.id);\n });\n addEventListener('messageDismissed', (message) => {\n recordAnalyticsEvent(PinpointMessageEvent.MESSAGE_DISMISSED, message);\n });\n addEventListener('messageActionTaken', (message) => {\n recordAnalyticsEvent(PinpointMessageEvent.MESSAGE_ACTION_TAKEN, message);\n });\n // listen to analytics hub events\n Hub.listen('analytics', analyticsListener);\n initialize();\n}\nfunction analyticsListener({ payload, }) {\n const { event, data } = payload;\n switch (event) {\n case 'record': {\n dispatchEvent(data);\n break;\n }\n default:\n break;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,wBAAwB,GAAG;AAC3C,IAAI,IAAI,aAAa,EAAE,EAAE;AACzB,QAAQ,OAAO;AACf,KAAK;AACL;AACA,IAAI,eAAe,CAAC,sBAAsB,CAAC,yBAAyB,EAAE,IAAI,CAAC,CAAC;AAC5E;AACA,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,CAAC,OAAO,KAAK;AACtD,QAAQ,oBAAoB,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AAC9E,QAAQ,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC3C,KAAK,CAAC,CAAC;AACP,IAAI,gBAAgB,CAAC,kBAAkB,EAAE,CAAC,OAAO,KAAK;AACtD,QAAQ,oBAAoB,CAAC,oBAAoB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC;AAC9E,KAAK,CAAC,CAAC;AACP,IAAI,gBAAgB,CAAC,oBAAoB,EAAE,CAAC,OAAO,KAAK;AACxD,QAAQ,oBAAoB,CAAC,oBAAoB,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;AACjF,KAAK,CAAC,CAAC;AACP;AACA,IAAI,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC;AAC/C,IAAI,UAAU,EAAE,CAAC;AACjB,CAAC;AACD,SAAS,iBAAiB,CAAC,EAAE,OAAO,GAAG,EAAE;AACzC,IAAI,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;AACpC,IAAI,QAAQ,KAAK;AACjB,QAAQ,KAAK,QAAQ,EAAE;AACvB,YAAY,aAAa,CAAC,IAAI,CAAC,CAAC;AAChC,YAAY,MAAM;AAClB,SAAS;AAGT,KAAK;AACL;;;;"}
|
|
@@ -6,7 +6,7 @@ import { OnMessageDisplayedInput } from '../types/inputs';
|
|
|
6
6
|
* @param {OnMessageDisplayedInput} input - The input object that holds the callback handler.
|
|
7
7
|
* @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
|
|
8
8
|
* configuration is incorrect, or if In App messaging hasn't been initialized.
|
|
9
|
-
* @returns {
|
|
9
|
+
* @returns {OnMessageDisplayedOutput} - An object that holds a remove method to stop listening to events.
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
12
|
* onMessageDisplayed((message) => {
|
|
@@ -9,7 +9,7 @@ import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
|
9
9
|
* @param {OnMessageDisplayedInput} input - The input object that holds the callback handler.
|
|
10
10
|
* @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library
|
|
11
11
|
* configuration is incorrect, or if In App messaging hasn't been initialized.
|
|
12
|
-
* @returns {
|
|
12
|
+
* @returns {OnMessageDisplayedOutput} - An object that holds a remove method to stop listening to events.
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
15
|
* onMessageDisplayed((message) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onMessageDisplayed.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { addEventListener } from '../../../../eventListeners';\nimport { assertIsInitialized } from '../../../utils';\n/**\n * Registers a callback that will be invoked on `messageDisplayed` events.\n *\n * @param {OnMessageDisplayedInput} input - The input object that holds the callback handler.\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @returns {
|
|
1
|
+
{"version":3,"file":"onMessageDisplayed.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/onMessageDisplayed.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { addEventListener } from '../../../../eventListeners';\nimport { assertIsInitialized } from '../../../utils';\n/**\n * Registers a callback that will be invoked on `messageDisplayed` events.\n *\n * @param {OnMessageDisplayedInput} input - The input object that holds the callback handler.\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n * @returns {OnMessageDisplayedOutput} - An object that holds a remove method to stop listening to events.\n * @example\n * ```ts\n * onMessageDisplayed((message) => {\n * // use the message\n * \t console.log(message.id);\n * });\n * ```\n */\nexport function onMessageDisplayed(input) {\n assertIsInitialized();\n return addEventListener('messageDisplayed', input);\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAI,OAAO,gBAAgB,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;AACvD;;;;"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare let conflictHandler: InAppMessageConflictHandler;
|
|
1
|
+
import { SetConflictHandlerInput } from '../types';
|
|
3
2
|
/**
|
|
4
3
|
* Set a conflict handler that will be used to resolve conflicts that may emerge
|
|
5
4
|
* when matching events with synced messages.
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|
|
2
|
+
import { setConflictHandler as setConflictHandler$1 } from '../utils/conflictHandlerManager.mjs';
|
|
3
|
+
import '@aws-amplify/core';
|
|
4
|
+
import '@aws-amplify/core/internals/utils';
|
|
5
|
+
import '../../../errors/validation.mjs';
|
|
6
|
+
import '../utils/messageProcessingHelpers.mjs';
|
|
2
7
|
|
|
3
8
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
let conflictHandler = defaultConflictHandler;
|
|
6
10
|
/**
|
|
7
11
|
* Set a conflict handler that will be used to resolve conflicts that may emerge
|
|
8
12
|
* when matching events with synced messages.
|
|
@@ -37,32 +41,8 @@ let conflictHandler = defaultConflictHandler;
|
|
|
37
41
|
*/
|
|
38
42
|
function setConflictHandler(input) {
|
|
39
43
|
assertIsInitialized();
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
function defaultConflictHandler(messages) {
|
|
43
|
-
// default behavior is to return the message closest to expiry
|
|
44
|
-
// this function assumes that messages processed by providers already filters out expired messages
|
|
45
|
-
const sorted = messages.sort((a, b) => {
|
|
46
|
-
const endDateA = a.metadata?.endDate;
|
|
47
|
-
const endDateB = b.metadata?.endDate;
|
|
48
|
-
// if both message end dates are falsy or have the same date string, treat them as equal
|
|
49
|
-
if (endDateA === endDateB) {
|
|
50
|
-
return 0;
|
|
51
|
-
}
|
|
52
|
-
// if only message A has an end date, treat it as closer to expiry
|
|
53
|
-
if (endDateA && !endDateB) {
|
|
54
|
-
return -1;
|
|
55
|
-
}
|
|
56
|
-
// if only message B has an end date, treat it as closer to expiry
|
|
57
|
-
if (!endDateA && endDateB) {
|
|
58
|
-
return 1;
|
|
59
|
-
}
|
|
60
|
-
// otherwise, compare them
|
|
61
|
-
return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
|
|
62
|
-
});
|
|
63
|
-
// always return the top sorted
|
|
64
|
-
return sorted[0];
|
|
44
|
+
setConflictHandler$1(input);
|
|
65
45
|
}
|
|
66
46
|
|
|
67
|
-
export {
|
|
47
|
+
export { setConflictHandler };
|
|
68
48
|
//# sourceMappingURL=setConflictHandler.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setConflictHandler.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertIsInitialized } from '../../../utils';\
|
|
1
|
+
{"version":3,"file":"setConflictHandler.mjs","sources":["../../../../../../src/inAppMessaging/providers/pinpoint/apis/setConflictHandler.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { assertIsInitialized } from '../../../utils';\nimport { setConflictHandler as setConflictHandlerInteral } from '../utils';\n/**\n * Set a conflict handler that will be used to resolve conflicts that may emerge\n * when matching events with synced messages.\n *\n * @remark\n * The conflict handler is not persisted across app restarts and so must be set again before dispatching an event for\n * any custom handling to take effect.\n *\n * @throws validation: {@link InAppMessagingValidationErrorCode} - Thrown when the provided parameters or library\n * configuration is incorrect, or if In App messaging hasn't been initialized.\n *\n * @param input The input object that holds the conflict handler to be used.\n *\n * @example\n * ```ts\n * // Sync messages before dispatching an event\n * await syncMessages();\n *\n * // Example custom conflict handler\n * const myConflictHandler = (messages) => {\n * \t\t// Return a random message\n * \t\tconst randomIndex = Math.floor(Math.random() * messages.length);\n * \t\treturn messages[randomIndex];\n * };\n *\n * // Set the conflict handler\n * setConflictHandler(myConflictHandler);\n *\n * // Dispatch an event\n * await dispatchEvent({ name: 'test_event' });\n * ```\n */\nexport function setConflictHandler(input) {\n assertIsInitialized();\n setConflictHandlerInteral(input);\n}\n"],"names":["setConflictHandlerInteral"],"mappings":";;;;;;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,kBAAkB,CAAC,KAAK,EAAE;AAC1C,IAAI,mBAAmB,EAAE,CAAC;AAC1B,IAAIA,oBAAyB,CAAC,KAAK,CAAC,CAAC;AACrC;;;;"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { InAppMessagingAction } from '@aws-amplify/core/internals/utils';
|
|
2
2
|
import { resolveEndpointId } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
3
3
|
import { defaultStorage } from '@aws-amplify/core';
|
|
4
|
+
import { getInAppMessages } from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
4
5
|
import { resolveConfig } from '../utils/resolveConfig.mjs';
|
|
5
6
|
import { resolveCredentials } from '../utils/resolveCredentials.mjs';
|
|
6
7
|
import { getInAppMessagingUserAgentString } from '../utils/userAgent.mjs';
|
|
7
8
|
import { PINPOINT_KEY_PREFIX, STORAGE_KEY_SUFFIX, CATEGORY, CHANNEL_TYPE } from '../utils/constants.mjs';
|
|
8
9
|
import '../utils/messageProcessingHelpers.mjs';
|
|
9
|
-
import { getInAppMessages } from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
10
10
|
import '../../../errors/validation.mjs';
|
|
11
11
|
import { assertServiceError } from '../../../errors/assertServiceError.mjs';
|
|
12
12
|
import { assertIsInitialized } from '../../../utils/statusHelpers.mjs';
|