@aws-amplify/notifications 2.0.22 → 2.0.23-unstable.701f219.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
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { IdentifyUserOptions } from './options';
|
|
5
|
-
import {
|
|
6
|
-
InAppMessageConflictHandler,
|
|
7
|
-
OnMessageInteractionEventHandler,
|
|
8
|
-
} from './types';
|
|
9
4
|
import {
|
|
10
5
|
InAppMessage,
|
|
11
6
|
InAppMessageInteractionEvent,
|
|
@@ -13,6 +8,12 @@ import {
|
|
|
13
8
|
InAppMessagingIdentifyUserInput,
|
|
14
9
|
} from '../../../types';
|
|
15
10
|
|
|
11
|
+
import { IdentifyUserOptions } from './options';
|
|
12
|
+
import {
|
|
13
|
+
InAppMessageConflictHandler,
|
|
14
|
+
OnMessageInteractionEventHandler,
|
|
15
|
+
} from './types';
|
|
16
|
+
|
|
16
17
|
/**
|
|
17
18
|
* Input type for Pinpoint identifyUser API.
|
|
18
19
|
*/
|
|
@@ -52,7 +53,7 @@ export type OnMessageActionTakenInput = OnMessageInteractionEventHandler;
|
|
|
52
53
|
/**
|
|
53
54
|
* Input type for NotifyMessageInteraction API.
|
|
54
55
|
*/
|
|
55
|
-
export
|
|
56
|
+
export interface NotifyMessageInteractionInput {
|
|
56
57
|
message: InAppMessage;
|
|
57
58
|
type: InAppMessageInteractionEvent;
|
|
58
|
-
}
|
|
59
|
+
}
|
|
@@ -5,16 +5,16 @@ import { InAppMessage } from '../../../types';
|
|
|
5
5
|
|
|
6
6
|
export type InAppMessageCountMap = Record<string, number>;
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface DailyInAppMessageCounter {
|
|
9
9
|
count: number;
|
|
10
10
|
lastCountTimestamp: string;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export interface InAppMessageCounts {
|
|
14
14
|
sessionCount: number;
|
|
15
15
|
dailyCount: number;
|
|
16
16
|
totalCount: number;
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
18
|
|
|
19
19
|
export type MetricsComparator = (
|
|
20
20
|
metricsVal: number,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { InAppMessage } from '../../../types';
|
|
5
|
+
import { InAppMessageConflictHandler, SetConflictHandlerInput } from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The default conflict handler. Can be overridden by `setConflictHandler`.
|
|
9
|
+
*/
|
|
10
|
+
let conflictHandler: InAppMessageConflictHandler = (
|
|
11
|
+
messages: InAppMessage[],
|
|
12
|
+
): InAppMessage => {
|
|
13
|
+
// default behavior is to return the message closest to expiry
|
|
14
|
+
// this function assumes that messages processed by providers already filters out expired messages
|
|
15
|
+
const sorted = messages.sort((a, b) => {
|
|
16
|
+
const endDateA = a.metadata?.endDate;
|
|
17
|
+
const endDateB = b.metadata?.endDate;
|
|
18
|
+
// if both message end dates are falsy or have the same date string, treat them as equal
|
|
19
|
+
if (endDateA === endDateB) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
// if only message A has an end date, treat it as closer to expiry
|
|
23
|
+
if (endDateA && !endDateB) {
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
// if only message B has an end date, treat it as closer to expiry
|
|
27
|
+
if (!endDateA && endDateB) {
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// otherwise, compare them
|
|
32
|
+
return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// always return the top sorted
|
|
36
|
+
return sorted[0];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Sets conflict handler.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export const setConflictHandler = (input: SetConflictHandlerInput): void => {
|
|
45
|
+
conflictHandler = input;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns the current conflict handler.
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
export const getConflictHandler = (): InAppMessageConflictHandler =>
|
|
54
|
+
conflictHandler;
|
|
@@ -5,6 +5,8 @@ import { ConsoleLogger } from '@aws-amplify/core';
|
|
|
5
5
|
import { InAppMessagingAction } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
7
7
|
import isEmpty from 'lodash/isEmpty.js';
|
|
8
|
+
import { record as recordCore } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
9
|
+
|
|
8
10
|
import {
|
|
9
11
|
InAppMessage,
|
|
10
12
|
InAppMessageAction,
|
|
@@ -14,7 +16,7 @@ import {
|
|
|
14
16
|
InAppMessagingEvent,
|
|
15
17
|
} from '../../../types';
|
|
16
18
|
import { MetricsComparator, PinpointMessageEvent } from '../types';
|
|
17
|
-
|
|
19
|
+
|
|
18
20
|
import { resolveConfig } from './resolveConfig';
|
|
19
21
|
import { resolveCredentials } from './resolveCredentials';
|
|
20
22
|
import { CATEGORY } from './constants';
|
|
@@ -66,6 +68,7 @@ export const recordAnalyticsEvent = (
|
|
|
66
68
|
export const getStartOfDay = (): string => {
|
|
67
69
|
const now = new Date();
|
|
68
70
|
now.setHours(0, 0, 0, 0);
|
|
71
|
+
|
|
69
72
|
return now.toISOString();
|
|
70
73
|
};
|
|
71
74
|
|
|
@@ -75,9 +78,10 @@ export const matchesEventType = (
|
|
|
75
78
|
) => {
|
|
76
79
|
const { EventType } = Schedule?.EventFilter?.Dimensions ?? {};
|
|
77
80
|
const memoKey = `${CampaignId}:${eventType}`;
|
|
78
|
-
if (!
|
|
81
|
+
if (!Object.prototype.hasOwnProperty.call(eventNameMemo, memoKey)) {
|
|
79
82
|
eventNameMemo[memoKey] = !!EventType?.Values?.includes(eventType);
|
|
80
83
|
}
|
|
84
|
+
|
|
81
85
|
return eventNameMemo[memoKey];
|
|
82
86
|
};
|
|
83
87
|
|
|
@@ -95,13 +99,14 @@ export const matchesAttributes = (
|
|
|
95
99
|
return false;
|
|
96
100
|
}
|
|
97
101
|
const memoKey = `${CampaignId}:${JSON.stringify(attributes)}`;
|
|
98
|
-
if (!
|
|
102
|
+
if (!Object.prototype.hasOwnProperty.call(eventAttributesMemo, memoKey)) {
|
|
99
103
|
eventAttributesMemo[memoKey] =
|
|
100
104
|
!Attributes ||
|
|
101
105
|
Object.entries(Attributes).every(([key, { Values }]) =>
|
|
102
106
|
Values?.includes(attributes[key]),
|
|
103
107
|
);
|
|
104
108
|
}
|
|
109
|
+
|
|
105
110
|
return eventAttributesMemo[memoKey];
|
|
106
111
|
};
|
|
107
112
|
|
|
@@ -119,15 +124,17 @@ export const matchesMetrics = (
|
|
|
119
124
|
return false;
|
|
120
125
|
}
|
|
121
126
|
const memoKey = `${CampaignId}:${JSON.stringify(metrics)}`;
|
|
122
|
-
if (!
|
|
127
|
+
if (!Object.prototype.hasOwnProperty.call(eventMetricsMemo, memoKey)) {
|
|
123
128
|
eventMetricsMemo[memoKey] =
|
|
124
129
|
!Metrics ||
|
|
125
130
|
Object.entries(Metrics).every(([key, { ComparisonOperator, Value }]) => {
|
|
126
131
|
const compare = getComparator(ComparisonOperator);
|
|
132
|
+
|
|
127
133
|
// if there is some unknown comparison operator, treat as a comparison failure
|
|
128
134
|
return compare && !!Value ? compare(Value, metrics[key]) : false;
|
|
129
135
|
});
|
|
130
136
|
}
|
|
137
|
+
|
|
131
138
|
return eventMetricsMemo[memoKey];
|
|
132
139
|
};
|
|
133
140
|
|
|
@@ -156,6 +163,7 @@ export const isBeforeEndDate = ({
|
|
|
156
163
|
if (!Schedule?.EndDate) {
|
|
157
164
|
return true;
|
|
158
165
|
}
|
|
166
|
+
|
|
159
167
|
return new Date() < new Date(Schedule.EndDate);
|
|
160
168
|
};
|
|
161
169
|
|
|
@@ -201,11 +209,12 @@ export const isQuietTime = (message: PinpointInAppMessage): boolean => {
|
|
|
201
209
|
end.setDate(end.getDate() + 1);
|
|
202
210
|
}
|
|
203
211
|
|
|
204
|
-
const
|
|
205
|
-
if (
|
|
212
|
+
const isDuringQuietTime = now >= start && now <= end;
|
|
213
|
+
if (isDuringQuietTime) {
|
|
206
214
|
logger.debug('message filtered due to quiet time', message);
|
|
207
215
|
}
|
|
208
|
-
|
|
216
|
+
|
|
217
|
+
return isDuringQuietTime;
|
|
209
218
|
};
|
|
210
219
|
|
|
211
220
|
export const clearMemo = () => {
|
|
@@ -315,18 +324,19 @@ export const extractContent = ({
|
|
|
315
324
|
},
|
|
316
325
|
};
|
|
317
326
|
}
|
|
327
|
+
|
|
318
328
|
return extractedContent;
|
|
319
329
|
}) ?? []
|
|
320
330
|
);
|
|
321
331
|
};
|
|
322
332
|
|
|
323
333
|
export const extractMetadata = ({
|
|
324
|
-
InAppMessage,
|
|
334
|
+
InAppMessage: inAppMessage,
|
|
325
335
|
Priority,
|
|
326
336
|
Schedule,
|
|
327
337
|
TreatmentId,
|
|
328
338
|
}: PinpointInAppMessage): InAppMessage['metadata'] => ({
|
|
329
|
-
customData:
|
|
339
|
+
customData: inAppMessage?.CustomConfig,
|
|
330
340
|
endDate: Schedule?.EndDate,
|
|
331
341
|
priority: Priority,
|
|
332
342
|
treatmentId: TreatmentId,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
export {
|
|
5
|
+
getConflictHandler,
|
|
6
|
+
setConflictHandler,
|
|
7
|
+
} from './conflictHandlerManager';
|
|
4
8
|
export { resolveConfig } from './resolveConfig';
|
|
5
9
|
export { resolveCredentials } from './resolveCredentials';
|
|
6
10
|
export { getInAppMessagingUserAgentString } from './userAgent';
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
5
|
+
import { ConsoleLogger, defaultStorage } from '@aws-amplify/core';
|
|
6
|
+
import { SessionState } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
|
|
4
8
|
import { InAppMessage, InAppMessagingEvent } from '../../../types';
|
|
5
9
|
import {
|
|
6
|
-
InAppMessageCounts,
|
|
7
|
-
InAppMessageCountMap,
|
|
8
10
|
DailyInAppMessageCounter,
|
|
11
|
+
InAppMessageCountMap,
|
|
12
|
+
InAppMessageCounts,
|
|
9
13
|
} from '../types';
|
|
14
|
+
|
|
10
15
|
import {
|
|
11
16
|
extractContent,
|
|
12
17
|
extractMetadata,
|
|
@@ -16,9 +21,6 @@ import {
|
|
|
16
21
|
matchesEventType,
|
|
17
22
|
matchesMetrics,
|
|
18
23
|
} from './helpers';
|
|
19
|
-
import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
20
|
-
import { defaultStorage, ConsoleLogger } from '@aws-amplify/core';
|
|
21
|
-
import { SessionState } from '@aws-amplify/core/internals/utils';
|
|
22
24
|
|
|
23
25
|
const MESSAGE_DAILY_COUNT_KEY = 'pinpointProvider_inAppMessages_dailyCount';
|
|
24
26
|
const MESSAGE_TOTAL_COUNT_KEY = 'pinpointProvider_inAppMessages_totalCount';
|
|
@@ -32,8 +34,7 @@ export async function processInAppMessages(
|
|
|
32
34
|
): Promise<InAppMessage[]> {
|
|
33
35
|
let highestPrioritySeen: number | undefined;
|
|
34
36
|
let acc: PinpointInAppMessage[] = [];
|
|
35
|
-
for (
|
|
36
|
-
const message = messages[index];
|
|
37
|
+
for (const message of messages) {
|
|
37
38
|
const messageQualifies =
|
|
38
39
|
matchesEventType(message, event) &&
|
|
39
40
|
matchesAttributes(message, event) &&
|
|
@@ -65,6 +66,7 @@ export async function processInAppMessages(
|
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
}
|
|
69
|
+
|
|
68
70
|
return normalizeMessages(acc);
|
|
69
71
|
}
|
|
70
72
|
|
|
@@ -85,14 +87,15 @@ export async function incrementMessageCounts(messageId: string): Promise<void> {
|
|
|
85
87
|
|
|
86
88
|
function normalizeMessages(messages: PinpointInAppMessage[]): InAppMessage[] {
|
|
87
89
|
return messages.map(message => {
|
|
88
|
-
const { CampaignId, InAppMessage } = message;
|
|
90
|
+
const { CampaignId, InAppMessage: pinpointInAppMessage } = message;
|
|
91
|
+
|
|
89
92
|
return {
|
|
90
93
|
// Default to empty string in rare cases we don't have a campaignId
|
|
91
94
|
id: CampaignId ?? '',
|
|
92
95
|
content: extractContent(message),
|
|
93
96
|
// Default to TOP_BANNER layout in rare cases we don't have a Layout
|
|
94
|
-
layout:
|
|
95
|
-
? interpretLayout(
|
|
97
|
+
layout: pinpointInAppMessage?.Layout
|
|
98
|
+
? interpretLayout(pinpointInAppMessage.Layout)
|
|
96
99
|
: 'TOP_BANNER',
|
|
97
100
|
metadata: extractMetadata(message),
|
|
98
101
|
};
|
|
@@ -104,7 +107,7 @@ async function isBelowCap({
|
|
|
104
107
|
SessionCap,
|
|
105
108
|
DailyCap,
|
|
106
109
|
TotalCap,
|
|
107
|
-
}: PinpointInAppMessage): Promise<
|
|
110
|
+
}: PinpointInAppMessage): Promise<boolean> {
|
|
108
111
|
const { sessionCount, dailyCount, totalCount } =
|
|
109
112
|
await getMessageCounts(CampaignId);
|
|
110
113
|
|
|
@@ -131,6 +134,7 @@ async function getMessageCounts(
|
|
|
131
134
|
dailyCount: await getDailyCount(),
|
|
132
135
|
totalCount: await getTotalCount(messageId),
|
|
133
136
|
};
|
|
137
|
+
|
|
134
138
|
return messageCounts;
|
|
135
139
|
} catch (err) {
|
|
136
140
|
logger.error('Failed to get message counts from storage', err);
|
|
@@ -185,18 +189,21 @@ async function getDailyCount(): Promise<number> {
|
|
|
185
189
|
const counter: DailyInAppMessageCounter = item
|
|
186
190
|
? JSON.parse(item)
|
|
187
191
|
: { count: 0, lastCountTimestamp: today };
|
|
192
|
+
|
|
188
193
|
// If the stored counter timestamp is today, use it as the count, otherwise reset to 0
|
|
189
194
|
return counter.lastCountTimestamp === today ? counter.count : 0;
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
async function getTotalCountMap(): Promise<InAppMessageCountMap> {
|
|
193
198
|
const item = await defaultStorage.getItem(MESSAGE_TOTAL_COUNT_KEY);
|
|
199
|
+
|
|
194
200
|
// Parse stored count map or initialize as empty
|
|
195
201
|
return item ? JSON.parse(item) : {};
|
|
196
202
|
}
|
|
197
203
|
|
|
198
204
|
async function getTotalCount(messageId: string): Promise<number> {
|
|
199
205
|
const countMap = await getTotalCountMap();
|
|
206
|
+
|
|
200
207
|
// Return stored count or initialize as empty count
|
|
201
208
|
return countMap[messageId] || 0;
|
|
202
209
|
}
|
|
@@ -204,5 +211,6 @@ async function getTotalCount(messageId: string): Promise<number> {
|
|
|
204
211
|
const getStartOfDay = (): string => {
|
|
205
212
|
const now = new Date();
|
|
206
213
|
now.setHours(0, 0, 0, 0);
|
|
214
|
+
|
|
207
215
|
return now.toISOString();
|
|
208
216
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { Amplify } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
InAppMessagingValidationErrorCode,
|
|
7
8
|
assertValidationError,
|
|
@@ -15,5 +16,6 @@ export const resolveConfig = () => {
|
|
|
15
16
|
Amplify.getConfig().Notifications?.InAppMessaging?.Pinpoint ?? {};
|
|
16
17
|
assertValidationError(!!appId, InAppMessagingValidationErrorCode.NoAppId);
|
|
17
18
|
assertValidationError(!!region, InAppMessagingValidationErrorCode.NoRegion);
|
|
19
|
+
|
|
18
20
|
return { appId, region };
|
|
19
21
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { fetchAuthSession } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
InAppMessagingValidationErrorCode,
|
|
7
8
|
assertValidationError,
|
|
@@ -16,5 +17,6 @@ export const resolveCredentials = async () => {
|
|
|
16
17
|
!!credentials,
|
|
17
18
|
InAppMessagingValidationErrorCode.NoCredentials,
|
|
18
19
|
);
|
|
20
|
+
|
|
19
21
|
return { credentials, identityId };
|
|
20
22
|
};
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
4
|
Category,
|
|
5
|
-
getAmplifyUserAgentObject,
|
|
6
|
-
getAmplifyUserAgent,
|
|
7
5
|
InAppMessagingAction,
|
|
6
|
+
getAmplifyUserAgent,
|
|
7
|
+
getAmplifyUserAgentObject,
|
|
8
8
|
} from '@aws-amplify/core/internals/utils';
|
|
9
9
|
import { UserAgent } from '@aws-sdk/types';
|
|
10
10
|
|
|
@@ -7,8 +7,8 @@ export type InAppMessageInteractionEvent =
|
|
|
7
7
|
| 'messageDismissed'
|
|
8
8
|
| 'messageActionTaken';
|
|
9
9
|
|
|
10
|
-
export
|
|
10
|
+
export interface InAppMessagingEvent {
|
|
11
11
|
name: string;
|
|
12
12
|
attributes?: Record<string, string>;
|
|
13
13
|
metrics?: Record<string, number>;
|
|
14
|
-
}
|
|
14
|
+
}
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { UserProfile } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import { InAppMessagingServiceOptions } from './options';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Input type for `identifyUser`.
|
|
9
10
|
*/
|
|
10
|
-
export
|
|
11
|
+
export interface InAppMessagingIdentifyUserInput<
|
|
11
12
|
ServiceOptions extends
|
|
12
13
|
InAppMessagingServiceOptions = InAppMessagingServiceOptions,
|
|
13
|
-
>
|
|
14
|
+
> {
|
|
14
15
|
/**
|
|
15
16
|
* A User ID associated to the current device.
|
|
16
17
|
*/
|
|
@@ -25,4 +26,4 @@ export type InAppMessagingIdentifyUserInput<
|
|
|
25
26
|
* Options to be passed to the API.
|
|
26
27
|
*/
|
|
27
28
|
options?: ServiceOptions;
|
|
28
|
-
}
|
|
29
|
+
}
|
|
@@ -6,7 +6,9 @@ import {
|
|
|
6
6
|
AssertionFunction,
|
|
7
7
|
createAssertionFunction,
|
|
8
8
|
} from '@aws-amplify/core/internals/utils';
|
|
9
|
+
|
|
9
10
|
import { isInitialized } from '../utils/initializationManager';
|
|
11
|
+
|
|
10
12
|
import { PushNotificationError } from './PushNotificationError';
|
|
11
13
|
|
|
12
14
|
export enum PushNotificationValidationErrorCode {
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
|
|
5
|
+
|
|
5
6
|
import { assertIsInitialized } from '../../../errors/errorHelpers';
|
|
6
7
|
import { GetBadgeCount } from '../types';
|
|
7
8
|
|
|
@@ -9,5 +10,6 @@ const { getBadgeCount: getBadgeCountNative } = loadAmplifyPushNotification();
|
|
|
9
10
|
|
|
10
11
|
export const getBadgeCount: GetBadgeCount = async () => {
|
|
11
12
|
assertIsInitialized();
|
|
13
|
+
|
|
12
14
|
return getBadgeCountNative();
|
|
13
15
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
|
|
5
|
+
|
|
5
6
|
import { assertIsInitialized } from '../../../errors/errorHelpers';
|
|
6
7
|
import { GetLaunchNotification } from '../types';
|
|
7
8
|
|
|
@@ -10,5 +11,6 @@ const { getLaunchNotification: getLaunchNotificationNative } =
|
|
|
10
11
|
|
|
11
12
|
export const getLaunchNotification: GetLaunchNotification = async () => {
|
|
12
13
|
assertIsInitialized();
|
|
14
|
+
|
|
13
15
|
return getLaunchNotificationNative();
|
|
14
16
|
};
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
|
|
5
|
+
|
|
5
6
|
import { assertIsInitialized } from '../../../errors/errorHelpers';
|
|
6
7
|
import { GetPermissionStatus } from '../types';
|
|
7
8
|
|
|
@@ -10,5 +11,6 @@ const { getPermissionStatus: getPermissionStatusNative } =
|
|
|
10
11
|
|
|
11
12
|
export const getPermissionStatus: GetPermissionStatus = async () => {
|
|
12
13
|
assertIsInitialized();
|
|
14
|
+
|
|
13
15
|
return getPermissionStatusNative();
|
|
14
16
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { PushNotificationAction } from '@aws-amplify/core/internals/utils';
|
|
5
5
|
import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
6
|
+
|
|
6
7
|
import { assertIsInitialized } from '../../../errors/errorHelpers';
|
|
7
8
|
import {
|
|
8
9
|
getPushNotificationUserAgentString,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { UpdateEndpointException } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
5
5
|
import { PlatformNotSupportedError } from '@aws-amplify/core/internals/utils';
|
|
6
|
+
|
|
6
7
|
import { PushNotificationValidationErrorCode } from '../../../errors';
|
|
7
8
|
import { IdentifyUser, IdentifyUserInput } from '../types';
|
|
8
9
|
|
|
@@ -5,6 +5,7 @@ import { ConsoleLogger } from '@aws-amplify/core';
|
|
|
5
5
|
import { PushNotificationAction } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
import { updateEndpoint } from '@aws-amplify/core/internals/providers/pinpoint';
|
|
7
7
|
import { loadAmplifyPushNotification } from '@aws-amplify/react-native';
|
|
8
|
+
|
|
8
9
|
import {
|
|
9
10
|
EventListenerRemover,
|
|
10
11
|
addEventListener,
|
|
@@ -40,6 +41,7 @@ const BACKGROUND_TASK_TIMEOUT = 25; // seconds
|
|
|
40
41
|
export const initializePushNotifications = (): void => {
|
|
41
42
|
if (isInitialized()) {
|
|
42
43
|
logger.info('Push notifications have already been enabled');
|
|
44
|
+
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
47
|
addNativeListeners();
|
|
@@ -48,9 +50,9 @@ export const initializePushNotifications = (): void => {
|
|
|
48
50
|
};
|
|
49
51
|
|
|
50
52
|
const addNativeListeners = (): void => {
|
|
51
|
-
let launchNotificationOpenedListener:
|
|
52
|
-
typeof addMessageEventListener
|
|
53
|
-
|
|
53
|
+
let launchNotificationOpenedListener:
|
|
54
|
+
| ReturnType<typeof addMessageEventListener>
|
|
55
|
+
| undefined;
|
|
54
56
|
const { NativeEvent, NativeHeadlessTaskKey } = getConstants();
|
|
55
57
|
const {
|
|
56
58
|
BACKGROUND_MESSAGE_RECEIVED,
|
|
@@ -85,14 +87,14 @@ const addNativeListeners = (): void => {
|
|
|
85
87
|
// background tasks will get suspended and all future tasks be deprioritized by the OS if they run for
|
|
86
88
|
// more than 30 seconds so we reject with a error in a shorter amount of time to prevent this from
|
|
87
89
|
// happening
|
|
88
|
-
new Promise((
|
|
89
|
-
setTimeout(
|
|
90
|
-
(
|
|
91
|
-
|
|
90
|
+
new Promise((_resolve, reject) => {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
reject(
|
|
93
|
+
new Error(
|
|
92
94
|
`onNotificationReceivedInBackground handlers should complete their work within ${BACKGROUND_TASK_TIMEOUT} seconds, but they did not.`,
|
|
93
95
|
),
|
|
94
|
-
|
|
95
|
-
);
|
|
96
|
+
);
|
|
97
|
+
}, BACKGROUND_TASK_TIMEOUT * 1000);
|
|
96
98
|
}),
|
|
97
99
|
]);
|
|
98
100
|
} catch (err) {
|
|
@@ -125,9 +127,10 @@ const addNativeListeners = (): void => {
|
|
|
125
127
|
notifyEventListeners('launchNotificationOpened', message);
|
|
126
128
|
// once we are done with it we can remove the listener
|
|
127
129
|
launchNotificationOpenedListener?.remove();
|
|
130
|
+
launchNotificationOpenedListener = undefined;
|
|
128
131
|
},
|
|
129
132
|
)
|
|
130
|
-
:
|
|
133
|
+
: undefined;
|
|
131
134
|
|
|
132
135
|
addMessageEventListener(
|
|
133
136
|
// listen for native notification opened (user tapped on notification, opening the app from background -
|
|
@@ -178,7 +181,10 @@ const addAnalyticsListeners = (): void => {
|
|
|
178
181
|
createMessageEventRecorder(
|
|
179
182
|
'opened_notification',
|
|
180
183
|
// once we are done with it we can remove the listener
|
|
181
|
-
|
|
184
|
+
() => {
|
|
185
|
+
launchNotificationOpenedListenerRemover?.remove();
|
|
186
|
+
launchNotificationOpenedListenerRemover = undefined;
|
|
187
|
+
},
|
|
182
188
|
),
|
|
183
189
|
);
|
|
184
190
|
addEventListener(
|
|
@@ -186,7 +192,10 @@ const addAnalyticsListeners = (): void => {
|
|
|
186
192
|
createMessageEventRecorder(
|
|
187
193
|
'opened_notification',
|
|
188
194
|
// if we are in this state, we no longer need the listener as the app was launched via some other means
|
|
189
|
-
|
|
195
|
+
() => {
|
|
196
|
+
launchNotificationOpenedListenerRemover?.remove();
|
|
197
|
+
launchNotificationOpenedListenerRemover = undefined;
|
|
198
|
+
},
|
|
190
199
|
),
|
|
191
200
|
);
|
|
192
201
|
};
|