@aws-amplify/notifications 2.0.1-console-preview.11cf989.0 → 2.0.1-console-preview.4ae78ed.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/lib/common/AWSPinpointProviderCommon/index.d.ts +2 -2
- package/lib/common/AWSPinpointProviderCommon/index.js +1 -1
- package/lib/common/AWSPinpointProviderCommon/index.js.map +1 -1
- package/lib/common/AWSPinpointProviderCommon/types.d.ts +2 -2
- package/lib/inAppMessaging/index.d.ts +0 -1
- package/lib/inAppMessaging/index.js +0 -2
- package/lib/inAppMessaging/index.js.map +1 -1
- package/lib/inAppMessaging/providers/pinpoint/apis/identifyUser.d.ts +55 -2
- package/lib/inAppMessaging/providers/pinpoint/apis/identifyUser.js +89 -4
- package/lib/inAppMessaging/providers/pinpoint/apis/identifyUser.js.map +1 -1
- package/lib/inAppMessaging/providers/pinpoint/apis/syncMessages.js +1 -2
- package/lib/inAppMessaging/providers/pinpoint/apis/syncMessages.js.map +1 -1
- package/lib/inAppMessaging/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib/inAppMessaging/providers/pinpoint/types/errors.js +15 -0
- package/lib/inAppMessaging/providers/pinpoint/types/errors.js.map +1 -0
- package/lib/inAppMessaging/providers/pinpoint/types/index.d.ts +3 -0
- package/lib/inAppMessaging/providers/pinpoint/types/index.js +7 -0
- package/lib/inAppMessaging/providers/pinpoint/types/index.js.map +1 -0
- package/lib/inAppMessaging/providers/pinpoint/types/inputs.d.ts +6 -0
- package/lib/inAppMessaging/providers/pinpoint/types/inputs.js +5 -0
- package/lib/inAppMessaging/providers/pinpoint/types/inputs.js.map +1 -0
- package/lib/inAppMessaging/providers/pinpoint/types/options.d.ts +5 -0
- package/lib/inAppMessaging/providers/pinpoint/types/options.js +5 -0
- package/lib/inAppMessaging/providers/pinpoint/types/options.js.map +1 -0
- package/lib/inAppMessaging/types/config.d.ts +5 -0
- package/lib/inAppMessaging/types/config.js +3 -0
- package/lib/inAppMessaging/types/config.js.map +1 -0
- package/lib/inAppMessaging/types/event.d.ts +6 -0
- package/lib/inAppMessaging/types/event.js +5 -0
- package/lib/inAppMessaging/types/event.js.map +1 -0
- package/lib/inAppMessaging/types/index.d.ts +5 -0
- package/lib/inAppMessaging/types/index.js +5 -0
- package/lib/inAppMessaging/types/index.js.map +1 -0
- package/lib/inAppMessaging/types/inputs.d.ts +21 -0
- package/lib/inAppMessaging/types/inputs.js +5 -0
- package/lib/inAppMessaging/types/inputs.js.map +1 -0
- package/lib/inAppMessaging/types/message.d.ts +44 -0
- package/lib/inAppMessaging/types/message.js +5 -0
- package/lib/inAppMessaging/types/message.js.map +1 -0
- package/lib/inAppMessaging/types/options.d.ts +4 -0
- package/lib/inAppMessaging/types/options.js +5 -0
- package/lib/inAppMessaging/types/options.js.map +1 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +0 -2
- package/lib/index.js.map +1 -1
- package/lib/pushNotifications/providers/AWSPinpointProvider/index.js +4 -4
- package/lib/pushNotifications/providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib/pushNotifications/types.d.ts +3 -9
- package/lib-esm/common/AWSPinpointProviderCommon/index.d.ts +2 -2
- package/lib-esm/common/AWSPinpointProviderCommon/index.js +1 -1
- package/lib-esm/common/AWSPinpointProviderCommon/index.js.map +1 -1
- package/lib-esm/common/AWSPinpointProviderCommon/types.d.ts +2 -2
- package/lib-esm/inAppMessaging/index.d.ts +0 -1
- package/lib-esm/inAppMessaging/index.js +0 -1
- package/lib-esm/inAppMessaging/index.js.map +1 -1
- package/lib-esm/inAppMessaging/providers/pinpoint/apis/identifyUser.d.ts +55 -2
- package/lib-esm/inAppMessaging/providers/pinpoint/apis/identifyUser.js +89 -3
- package/lib-esm/inAppMessaging/providers/pinpoint/apis/identifyUser.js.map +1 -1
- package/lib-esm/inAppMessaging/providers/pinpoint/apis/syncMessages.js +2 -3
- package/lib-esm/inAppMessaging/providers/pinpoint/apis/syncMessages.js.map +1 -1
- package/lib-esm/inAppMessaging/providers/pinpoint/types/errors.d.ts +9 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/errors.js +13 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/errors.js.map +1 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/index.d.ts +3 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/index.js +4 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/index.js.map +1 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/inputs.d.ts +6 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/inputs.js +3 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/inputs.js.map +1 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/options.d.ts +5 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/options.js +3 -0
- package/lib-esm/inAppMessaging/providers/pinpoint/types/options.js.map +1 -0
- package/lib-esm/inAppMessaging/types/config.d.ts +5 -0
- package/lib-esm/inAppMessaging/types/config.js +1 -0
- package/lib-esm/inAppMessaging/types/config.js.map +1 -0
- package/lib-esm/inAppMessaging/types/event.d.ts +6 -0
- package/lib-esm/inAppMessaging/types/event.js +3 -0
- package/lib-esm/inAppMessaging/types/event.js.map +1 -0
- package/lib-esm/inAppMessaging/types/index.d.ts +5 -0
- package/lib-esm/inAppMessaging/types/index.js +3 -0
- package/lib-esm/inAppMessaging/types/index.js.map +1 -0
- package/lib-esm/inAppMessaging/types/inputs.d.ts +21 -0
- package/lib-esm/inAppMessaging/types/inputs.js +3 -0
- package/lib-esm/inAppMessaging/types/inputs.js.map +1 -0
- package/lib-esm/inAppMessaging/types/message.d.ts +44 -0
- package/lib-esm/inAppMessaging/types/message.js +3 -0
- package/lib-esm/inAppMessaging/types/message.js.map +1 -0
- package/lib-esm/inAppMessaging/types/options.d.ts +4 -0
- package/lib-esm/inAppMessaging/types/options.js +3 -0
- package/lib-esm/inAppMessaging/types/options.js.map +1 -0
- package/lib-esm/index.d.ts +1 -2
- package/lib-esm/index.js +0 -1
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/pushNotifications/providers/AWSPinpointProvider/index.js +4 -4
- package/lib-esm/pushNotifications/providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib-esm/pushNotifications/types.d.ts +3 -9
- package/package.json +4 -4
- package/src/common/AWSPinpointProviderCommon/index.ts +3 -3
- package/src/common/AWSPinpointProviderCommon/types.ts +2 -2
- package/src/inAppMessaging/index.ts +0 -13
- package/src/inAppMessaging/providers/pinpoint/apis/identifyUser.ts +90 -7
- package/src/inAppMessaging/providers/pinpoint/apis/syncMessages.ts +2 -6
- package/src/inAppMessaging/providers/pinpoint/types/errors.ts +12 -0
- package/src/inAppMessaging/providers/pinpoint/types/index.ts +6 -0
- package/src/inAppMessaging/providers/pinpoint/types/inputs.ts +11 -0
- package/src/inAppMessaging/providers/pinpoint/types/options.ts +9 -0
- package/src/inAppMessaging/types/config.ts +8 -0
- package/src/inAppMessaging/types/event.ts +14 -0
- package/src/inAppMessaging/types/index.ts +8 -0
- package/src/inAppMessaging/types/inputs.ts +29 -0
- package/src/inAppMessaging/types/message.ts +62 -0
- package/src/inAppMessaging/types/options.ts +7 -0
- package/src/index.ts +1 -14
- package/src/pushNotifications/providers/AWSPinpointProvider/index.ts +13 -20
- package/src/pushNotifications/types.ts +8 -9
- package/lib/inAppMessaging/providers/pinpoint/utils/utils.d.ts +0 -17
- package/lib/inAppMessaging/providers/pinpoint/utils/utils.js +0 -243
- package/lib/inAppMessaging/providers/pinpoint/utils/utils.js.map +0 -1
- package/lib/inAppMessaging/types.d.ts +0 -87
- package/lib/inAppMessaging/types.js +0 -12
- package/lib/inAppMessaging/types.js.map +0 -1
- package/lib-esm/inAppMessaging/providers/pinpoint/utils/utils.d.ts +0 -17
- package/lib-esm/inAppMessaging/providers/pinpoint/utils/utils.js +0 -241
- package/lib-esm/inAppMessaging/providers/pinpoint/utils/utils.js.map +0 -1
- package/lib-esm/inAppMessaging/types.d.ts +0 -87
- package/lib-esm/inAppMessaging/types.js +0 -10
- package/lib-esm/inAppMessaging/types.js.map +0 -1
- package/src/inAppMessaging/providers/pinpoint/utils/utils.ts +0 -304
- package/src/inAppMessaging/types.ts +0 -142
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { EventListener } from '../common';
|
|
2
|
-
import { AWSPinpointProviderConfig } from '../common/AWSPinpointProviderCommon/types';
|
|
3
|
-
import { NotificationsProvider, NotificationsSubCategory as NotificationsSubCategories, UserInfo } from '../types';
|
|
4
|
-
export declare type NotificationsSubCategory = Extract<NotificationsSubCategories, 'InAppMessaging'>;
|
|
5
|
-
export interface InAppMessagingInterface {
|
|
6
|
-
configure: (config: InAppMessagingConfig) => InAppMessagingConfig;
|
|
7
|
-
getModuleName: () => NotificationsSubCategory;
|
|
8
|
-
getPluggable: (providerName: string) => InAppMessagingProvider;
|
|
9
|
-
addPluggable: (pluggable: InAppMessagingProvider) => void;
|
|
10
|
-
removePluggable: (providerName: string) => void;
|
|
11
|
-
syncMessages: () => Promise<void[]>;
|
|
12
|
-
clearMessages: () => Promise<void[]>;
|
|
13
|
-
dispatchEvent: (event: InAppMessagingEvent) => Promise<void>;
|
|
14
|
-
identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
|
|
15
|
-
onMessageReceived: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
16
|
-
onMessageDisplayed: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
17
|
-
onMessageDismissed: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
18
|
-
onMessageActionTaken: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
19
|
-
notifyMessageInteraction: (message: InAppMessage, type: InAppMessageInteractionEvent) => void;
|
|
20
|
-
setConflictHandler: (handler: InAppMessageConflictHandler) => void;
|
|
21
|
-
}
|
|
22
|
-
export interface InAppMessagingProvider extends NotificationsProvider {
|
|
23
|
-
getSubCategory(): NotificationsSubCategory;
|
|
24
|
-
getInAppMessages(): Promise<any>;
|
|
25
|
-
processInAppMessages(messages: InAppMessage[], event: InAppMessagingEvent): Promise<InAppMessage[]>;
|
|
26
|
-
}
|
|
27
|
-
export interface InAppMessagingConfig {
|
|
28
|
-
listenForAnalyticsEvents?: boolean;
|
|
29
|
-
AWSPinpoint?: AWSPinpointProviderConfig;
|
|
30
|
-
}
|
|
31
|
-
export declare type InAppMessagingEvent = {
|
|
32
|
-
name: string;
|
|
33
|
-
attributes?: Record<string, string>;
|
|
34
|
-
metrics?: Record<string, number>;
|
|
35
|
-
};
|
|
36
|
-
export declare type InAppMessageLayout = 'BOTTOM_BANNER' | 'CAROUSEL' | 'FULL_SCREEN' | 'MIDDLE_BANNER' | 'MODAL' | 'TOP_BANNER';
|
|
37
|
-
export declare type InAppMessageAction = 'CLOSE' | 'DEEP_LINK' | 'LINK';
|
|
38
|
-
export declare type InAppMessageTextAlign = 'center' | 'left' | 'right';
|
|
39
|
-
interface InAppMessageContainer {
|
|
40
|
-
style?: InAppMessageStyle;
|
|
41
|
-
}
|
|
42
|
-
interface InAppMessageHeader {
|
|
43
|
-
content: string;
|
|
44
|
-
style?: InAppMessageStyle;
|
|
45
|
-
}
|
|
46
|
-
interface InAppMessageBody {
|
|
47
|
-
content: string;
|
|
48
|
-
style?: InAppMessageStyle;
|
|
49
|
-
}
|
|
50
|
-
export interface InAppMessageImage {
|
|
51
|
-
src: string;
|
|
52
|
-
}
|
|
53
|
-
export interface InAppMessageButton {
|
|
54
|
-
title: string;
|
|
55
|
-
action: InAppMessageAction;
|
|
56
|
-
url?: string;
|
|
57
|
-
style?: InAppMessageStyle;
|
|
58
|
-
}
|
|
59
|
-
export interface InAppMessageStyle {
|
|
60
|
-
backgroundColor?: string;
|
|
61
|
-
borderRadius?: number;
|
|
62
|
-
color?: string;
|
|
63
|
-
textAlign?: InAppMessageTextAlign;
|
|
64
|
-
}
|
|
65
|
-
export interface InAppMessageContent {
|
|
66
|
-
container?: InAppMessageContainer;
|
|
67
|
-
header?: InAppMessageHeader;
|
|
68
|
-
body?: InAppMessageBody;
|
|
69
|
-
image?: InAppMessageImage;
|
|
70
|
-
primaryButton?: InAppMessageButton;
|
|
71
|
-
secondaryButton?: InAppMessageButton;
|
|
72
|
-
}
|
|
73
|
-
export interface InAppMessage {
|
|
74
|
-
id: string;
|
|
75
|
-
layout: InAppMessageLayout;
|
|
76
|
-
content: InAppMessageContent[];
|
|
77
|
-
metadata?: any;
|
|
78
|
-
}
|
|
79
|
-
export declare type OnMessageInteractionEventHandler = (message: InAppMessage) => any;
|
|
80
|
-
export declare enum InAppMessageInteractionEvent {
|
|
81
|
-
MESSAGE_RECEIVED = "MESSAGE_RECEIVED_EVENT",
|
|
82
|
-
MESSAGE_DISPLAYED = "MESSAGE_DISPLAYED_EVENT",
|
|
83
|
-
MESSAGE_DISMISSED = "MESSAGE_DISMISSED_EVENT",
|
|
84
|
-
MESSAGE_ACTION_TAKEN = "MESSAGE_ACTION_TAKEN_EVENT"
|
|
85
|
-
}
|
|
86
|
-
export declare type InAppMessageConflictHandler = (messages: InAppMessage[]) => InAppMessage;
|
|
87
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export var InAppMessageInteractionEvent;
|
|
4
|
-
(function (InAppMessageInteractionEvent) {
|
|
5
|
-
InAppMessageInteractionEvent["MESSAGE_RECEIVED"] = "MESSAGE_RECEIVED_EVENT";
|
|
6
|
-
InAppMessageInteractionEvent["MESSAGE_DISPLAYED"] = "MESSAGE_DISPLAYED_EVENT";
|
|
7
|
-
InAppMessageInteractionEvent["MESSAGE_DISMISSED"] = "MESSAGE_DISMISSED_EVENT";
|
|
8
|
-
InAppMessageInteractionEvent["MESSAGE_ACTION_TAKEN"] = "MESSAGE_ACTION_TAKEN_EVENT";
|
|
9
|
-
})(InAppMessageInteractionEvent || (InAppMessageInteractionEvent = {}));
|
|
10
|
-
//# sourceMappingURL=types.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/inAppMessaging/types.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAmItC,MAAM,CAAN,IAAY,4BAKX;AALD,WAAY,4BAA4B;IACvC,2EAA2C,CAAA;IAC3C,6EAA6C,CAAA;IAC7C,6EAA6C,CAAA;IAC7C,mFAAmD,CAAA;AACpD,CAAC,EALW,4BAA4B,KAA5B,4BAA4B,QAKvC"}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { ConsoleLogger } from '@aws-amplify/core/internals/utils';
|
|
5
|
-
import type { InAppMessageCampaign as PinpointInAppMessage } from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
6
|
-
import isEmpty from 'lodash/isEmpty';
|
|
7
|
-
import {
|
|
8
|
-
InAppMessage,
|
|
9
|
-
InAppMessageAction,
|
|
10
|
-
InAppMessageContent,
|
|
11
|
-
InAppMessageLayout,
|
|
12
|
-
InAppMessageTextAlign,
|
|
13
|
-
InAppMessagingEvent,
|
|
14
|
-
} from '../../../types';
|
|
15
|
-
|
|
16
|
-
import { AWSPinpointMessageEvent, MetricsComparator } from '../types/types';
|
|
17
|
-
|
|
18
|
-
const DELIVERY_TYPE = 'IN_APP_MESSAGE';
|
|
19
|
-
|
|
20
|
-
let eventNameMemo = {};
|
|
21
|
-
let eventAttributesMemo = {};
|
|
22
|
-
let eventMetricsMemo = {};
|
|
23
|
-
|
|
24
|
-
export const logger = new ConsoleLogger('InAppMessaging.AWSPinpointProvider');
|
|
25
|
-
|
|
26
|
-
export const recordAnalyticsEvent = (
|
|
27
|
-
event: AWSPinpointMessageEvent,
|
|
28
|
-
message: InAppMessage
|
|
29
|
-
) => {
|
|
30
|
-
// TODO(V6) : Add back recording here without validation
|
|
31
|
-
// if (Amplify.Analytics && typeof Amplify.Analytics.record === 'function') {
|
|
32
|
-
// const { id, metadata } = message;
|
|
33
|
-
// Amplify.Analytics.record({
|
|
34
|
-
// name: event,
|
|
35
|
-
// attributes: {
|
|
36
|
-
// campaign_id: id,
|
|
37
|
-
// delivery_type: DELIVERY_TYPE,
|
|
38
|
-
// treatment_id: metadata?.treatmentId,
|
|
39
|
-
// },
|
|
40
|
-
// });
|
|
41
|
-
// } else {
|
|
42
|
-
// logger.debug('Analytics module is not registered into Amplify');
|
|
43
|
-
// }
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const getStartOfDay = (): string => {
|
|
47
|
-
const now = new Date();
|
|
48
|
-
now.setHours(0, 0, 0, 0);
|
|
49
|
-
return now.toISOString();
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const matchesEventType = (
|
|
53
|
-
{ CampaignId, Schedule }: PinpointInAppMessage,
|
|
54
|
-
{ name: eventType }: InAppMessagingEvent
|
|
55
|
-
) => {
|
|
56
|
-
const { EventType } = Schedule?.EventFilter?.Dimensions;
|
|
57
|
-
const memoKey = `${CampaignId}:${eventType}`;
|
|
58
|
-
if (!eventNameMemo.hasOwnProperty(memoKey)) {
|
|
59
|
-
eventNameMemo[memoKey] = !!EventType?.Values.includes(eventType);
|
|
60
|
-
}
|
|
61
|
-
return eventNameMemo[memoKey];
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const matchesAttributes = (
|
|
65
|
-
{ CampaignId, Schedule }: PinpointInAppMessage,
|
|
66
|
-
{ attributes }: InAppMessagingEvent
|
|
67
|
-
): boolean => {
|
|
68
|
-
const { Attributes } = Schedule?.EventFilter?.Dimensions;
|
|
69
|
-
if (isEmpty(Attributes)) {
|
|
70
|
-
// if message does not have attributes defined it does not matter what attributes are on the event
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
if (isEmpty(attributes)) {
|
|
74
|
-
// if message does have attributes but the event does not then it always fails the check
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const memoKey = `${CampaignId}:${JSON.stringify(attributes)}`;
|
|
78
|
-
if (!eventAttributesMemo.hasOwnProperty(memoKey)) {
|
|
79
|
-
eventAttributesMemo[memoKey] = Object.entries(Attributes).every(
|
|
80
|
-
([key, { Values }]) => Values.includes(attributes[key])
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
return eventAttributesMemo[memoKey];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export const matchesMetrics = (
|
|
87
|
-
{ CampaignId, Schedule }: PinpointInAppMessage,
|
|
88
|
-
{ metrics }: InAppMessagingEvent
|
|
89
|
-
): boolean => {
|
|
90
|
-
const { Metrics } = Schedule?.EventFilter?.Dimensions;
|
|
91
|
-
if (isEmpty(Metrics)) {
|
|
92
|
-
// if message does not have metrics defined it does not matter what metrics are on the event
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
if (isEmpty(metrics)) {
|
|
96
|
-
// if message does have metrics but the event does not then it always fails the check
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
const memoKey = `${CampaignId}:${JSON.stringify(metrics)}`;
|
|
100
|
-
if (!eventMetricsMemo.hasOwnProperty(memoKey)) {
|
|
101
|
-
eventMetricsMemo[memoKey] = Object.entries(Metrics).every(
|
|
102
|
-
([key, { ComparisonOperator, Value }]) => {
|
|
103
|
-
const compare = getComparator(ComparisonOperator);
|
|
104
|
-
// if there is some unknown comparison operator, treat as a comparison failure
|
|
105
|
-
return compare ? compare(Value, metrics[key]) : false;
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
return eventMetricsMemo[memoKey];
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export const getComparator = (operator: string): MetricsComparator => {
|
|
113
|
-
switch (operator) {
|
|
114
|
-
case 'EQUAL':
|
|
115
|
-
return (metricsVal, eventVal) => metricsVal === eventVal;
|
|
116
|
-
case 'GREATER_THAN':
|
|
117
|
-
return (metricsVal, eventVal) => metricsVal < eventVal;
|
|
118
|
-
case 'GREATER_THAN_OR_EQUAL':
|
|
119
|
-
return (metricsVal, eventVal) => metricsVal <= eventVal;
|
|
120
|
-
case 'LESS_THAN':
|
|
121
|
-
return (metricsVal, eventVal) => metricsVal > eventVal;
|
|
122
|
-
case 'LESS_THAN_OR_EQUAL':
|
|
123
|
-
return (metricsVal, eventVal) => metricsVal >= eventVal;
|
|
124
|
-
default:
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export const isBeforeEndDate = ({
|
|
130
|
-
Schedule,
|
|
131
|
-
}: PinpointInAppMessage): boolean => {
|
|
132
|
-
if (!Schedule?.EndDate) {
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
return new Date() < new Date(Schedule.EndDate);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export const isQuietTime = (message: PinpointInAppMessage): boolean => {
|
|
139
|
-
const { Schedule } = message;
|
|
140
|
-
if (!Schedule?.QuietTime) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const pattern = /^[0-2]\d:[0-5]\d$/; // basic sanity check, not a fully featured HH:MM validation
|
|
145
|
-
const { Start, End } = Schedule.QuietTime;
|
|
146
|
-
if (
|
|
147
|
-
!Start ||
|
|
148
|
-
!End ||
|
|
149
|
-
Start === End ||
|
|
150
|
-
!pattern.test(Start) ||
|
|
151
|
-
!pattern.test(End)
|
|
152
|
-
) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const now = new Date();
|
|
157
|
-
const start = new Date(now);
|
|
158
|
-
const end = new Date(now);
|
|
159
|
-
const [startHours, startMinutes] = Start.split(':');
|
|
160
|
-
const [endHours, endMinutes] = End.split(':');
|
|
161
|
-
|
|
162
|
-
start.setHours(
|
|
163
|
-
Number.parseInt(startHours, 10),
|
|
164
|
-
Number.parseInt(startMinutes, 10),
|
|
165
|
-
0,
|
|
166
|
-
0
|
|
167
|
-
);
|
|
168
|
-
end.setHours(
|
|
169
|
-
Number.parseInt(endHours, 10),
|
|
170
|
-
Number.parseInt(endMinutes, 10),
|
|
171
|
-
0,
|
|
172
|
-
0
|
|
173
|
-
);
|
|
174
|
-
|
|
175
|
-
// if quiet time includes midnight, bump the end time to the next day
|
|
176
|
-
if (start > end) {
|
|
177
|
-
end.setDate(end.getDate() + 1);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const isQuietTime = now >= start && now <= end;
|
|
181
|
-
if (isQuietTime) {
|
|
182
|
-
logger.debug('message filtered due to quiet time', message);
|
|
183
|
-
}
|
|
184
|
-
return isQuietTime;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export const clearMemo = () => {
|
|
188
|
-
eventNameMemo = {};
|
|
189
|
-
eventAttributesMemo = {};
|
|
190
|
-
eventMetricsMemo = {};
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// in the pinpoint console when a message is created with a Modal or Full Screen layout,
|
|
194
|
-
// it is assigned a layout value of MOBILE_FEED or OVERLAYS respectively in the message payload.
|
|
195
|
-
// In the future, Pinpoint will be updating the layout values in the aforementioned scenario
|
|
196
|
-
// to MODAL and FULL_SCREEN.
|
|
197
|
-
//
|
|
198
|
-
// This utility acts as a safeguard to ensure that:
|
|
199
|
-
// - 1. the usage of MOBILE_FEED and OVERLAYS as values for message layouts are not leaked
|
|
200
|
-
// outside the Pinpoint provider
|
|
201
|
-
// - 2. Amplify correctly handles the legacy layout values from Pinpoint after they are updated
|
|
202
|
-
export const interpretLayout = (
|
|
203
|
-
layout: PinpointInAppMessage['InAppMessage']['Layout']
|
|
204
|
-
): InAppMessageLayout => {
|
|
205
|
-
if (layout === 'MOBILE_FEED') {
|
|
206
|
-
return 'MODAL';
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (layout === 'OVERLAYS') {
|
|
210
|
-
return 'FULL_SCREEN';
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// cast as PinpointInAppMessage['InAppMessage']['Layout'] allows `string` as a value
|
|
214
|
-
return layout as InAppMessageLayout;
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
export const extractContent = ({
|
|
218
|
-
InAppMessage: message,
|
|
219
|
-
}: PinpointInAppMessage): InAppMessageContent[] => {
|
|
220
|
-
return (
|
|
221
|
-
message?.Content?.map(content => {
|
|
222
|
-
const {
|
|
223
|
-
BackgroundColor,
|
|
224
|
-
BodyConfig,
|
|
225
|
-
HeaderConfig,
|
|
226
|
-
ImageUrl,
|
|
227
|
-
PrimaryBtn,
|
|
228
|
-
SecondaryBtn,
|
|
229
|
-
} = content;
|
|
230
|
-
const defaultPrimaryButton = PrimaryBtn?.DefaultConfig;
|
|
231
|
-
const defaultSecondaryButton = SecondaryBtn?.DefaultConfig;
|
|
232
|
-
const extractedContent: InAppMessageContent = {};
|
|
233
|
-
if (BackgroundColor) {
|
|
234
|
-
extractedContent.container = {
|
|
235
|
-
style: {
|
|
236
|
-
backgroundColor: BackgroundColor,
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
if (HeaderConfig) {
|
|
241
|
-
extractedContent.header = {
|
|
242
|
-
content: HeaderConfig.Header,
|
|
243
|
-
style: {
|
|
244
|
-
color: HeaderConfig.TextColor,
|
|
245
|
-
textAlign:
|
|
246
|
-
HeaderConfig.Alignment.toLowerCase() as InAppMessageTextAlign,
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
if (BodyConfig) {
|
|
251
|
-
extractedContent.body = {
|
|
252
|
-
content: BodyConfig.Body,
|
|
253
|
-
style: {
|
|
254
|
-
color: BodyConfig.TextColor,
|
|
255
|
-
textAlign:
|
|
256
|
-
BodyConfig.Alignment.toLowerCase() as InAppMessageTextAlign,
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
if (ImageUrl) {
|
|
261
|
-
extractedContent.image = {
|
|
262
|
-
src: ImageUrl,
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
if (defaultPrimaryButton) {
|
|
266
|
-
extractedContent.primaryButton = {
|
|
267
|
-
title: defaultPrimaryButton.Text,
|
|
268
|
-
action: defaultPrimaryButton.ButtonAction as InAppMessageAction,
|
|
269
|
-
url: defaultPrimaryButton.Link,
|
|
270
|
-
style: {
|
|
271
|
-
backgroundColor: defaultPrimaryButton.BackgroundColor,
|
|
272
|
-
borderRadius: defaultPrimaryButton.BorderRadius,
|
|
273
|
-
color: defaultPrimaryButton.TextColor,
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
if (defaultSecondaryButton) {
|
|
278
|
-
extractedContent.secondaryButton = {
|
|
279
|
-
title: defaultSecondaryButton.Text,
|
|
280
|
-
action: defaultSecondaryButton.ButtonAction as InAppMessageAction,
|
|
281
|
-
url: defaultSecondaryButton.Link,
|
|
282
|
-
style: {
|
|
283
|
-
backgroundColor: defaultSecondaryButton.BackgroundColor,
|
|
284
|
-
borderRadius: defaultSecondaryButton.BorderRadius,
|
|
285
|
-
color: defaultSecondaryButton.TextColor,
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
return extractedContent;
|
|
290
|
-
}) ?? []
|
|
291
|
-
);
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
export const extractMetadata = ({
|
|
295
|
-
InAppMessage,
|
|
296
|
-
Priority,
|
|
297
|
-
Schedule,
|
|
298
|
-
TreatmentId,
|
|
299
|
-
}: PinpointInAppMessage): InAppMessage['metadata'] => ({
|
|
300
|
-
customData: InAppMessage?.CustomConfig,
|
|
301
|
-
endDate: Schedule?.EndDate,
|
|
302
|
-
priority: Priority,
|
|
303
|
-
treatmentId: TreatmentId,
|
|
304
|
-
});
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { EventListener } from '../common';
|
|
5
|
-
import { AWSPinpointProviderConfig } from '../common/AWSPinpointProviderCommon/types';
|
|
6
|
-
import {
|
|
7
|
-
NotificationsProvider,
|
|
8
|
-
NotificationsSubCategory as NotificationsSubCategories,
|
|
9
|
-
UserInfo,
|
|
10
|
-
} from '../types';
|
|
11
|
-
|
|
12
|
-
export type NotificationsSubCategory = Extract<
|
|
13
|
-
NotificationsSubCategories,
|
|
14
|
-
'InAppMessaging'
|
|
15
|
-
>;
|
|
16
|
-
|
|
17
|
-
export interface InAppMessagingInterface {
|
|
18
|
-
configure: (config: InAppMessagingConfig) => InAppMessagingConfig;
|
|
19
|
-
getModuleName: () => NotificationsSubCategory;
|
|
20
|
-
getPluggable: (providerName: string) => InAppMessagingProvider;
|
|
21
|
-
addPluggable: (pluggable: InAppMessagingProvider) => void;
|
|
22
|
-
removePluggable: (providerName: string) => void;
|
|
23
|
-
syncMessages: () => Promise<void[]>;
|
|
24
|
-
clearMessages: () => Promise<void[]>;
|
|
25
|
-
dispatchEvent: (event: InAppMessagingEvent) => Promise<void>;
|
|
26
|
-
identifyUser: (userId: string, userInfo: UserInfo) => Promise<void[]>;
|
|
27
|
-
onMessageReceived: (
|
|
28
|
-
handler: OnMessageInteractionEventHandler
|
|
29
|
-
) => EventListener<OnMessageInteractionEventHandler>;
|
|
30
|
-
onMessageDisplayed: (
|
|
31
|
-
handler: OnMessageInteractionEventHandler
|
|
32
|
-
) => EventListener<OnMessageInteractionEventHandler>;
|
|
33
|
-
onMessageDismissed: (
|
|
34
|
-
handler: OnMessageInteractionEventHandler
|
|
35
|
-
) => EventListener<OnMessageInteractionEventHandler>;
|
|
36
|
-
onMessageActionTaken: (
|
|
37
|
-
handler: OnMessageInteractionEventHandler
|
|
38
|
-
) => EventListener<OnMessageInteractionEventHandler>;
|
|
39
|
-
notifyMessageInteraction: (
|
|
40
|
-
message: InAppMessage,
|
|
41
|
-
type: InAppMessageInteractionEvent
|
|
42
|
-
) => void;
|
|
43
|
-
setConflictHandler: (handler: InAppMessageConflictHandler) => void;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface InAppMessagingProvider extends NotificationsProvider {
|
|
47
|
-
// return sub-category ('InAppMessaging')
|
|
48
|
-
getSubCategory(): NotificationsSubCategory;
|
|
49
|
-
|
|
50
|
-
// get in-app messages from provider
|
|
51
|
-
getInAppMessages(): Promise<any>;
|
|
52
|
-
|
|
53
|
-
// filters in-app messages based on event input and provider logic
|
|
54
|
-
processInAppMessages(
|
|
55
|
-
messages: InAppMessage[],
|
|
56
|
-
event: InAppMessagingEvent
|
|
57
|
-
): Promise<InAppMessage[]>;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface InAppMessagingConfig {
|
|
61
|
-
listenForAnalyticsEvents?: boolean;
|
|
62
|
-
AWSPinpoint?: AWSPinpointProviderConfig;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type InAppMessagingEvent = {
|
|
66
|
-
name: string;
|
|
67
|
-
attributes?: Record<string, string>;
|
|
68
|
-
metrics?: Record<string, number>;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export type InAppMessageLayout =
|
|
72
|
-
| 'BOTTOM_BANNER'
|
|
73
|
-
| 'CAROUSEL'
|
|
74
|
-
| 'FULL_SCREEN'
|
|
75
|
-
| 'MIDDLE_BANNER'
|
|
76
|
-
| 'MODAL'
|
|
77
|
-
| 'TOP_BANNER';
|
|
78
|
-
|
|
79
|
-
export type InAppMessageAction = 'CLOSE' | 'DEEP_LINK' | 'LINK';
|
|
80
|
-
|
|
81
|
-
export type InAppMessageTextAlign = 'center' | 'left' | 'right';
|
|
82
|
-
|
|
83
|
-
interface InAppMessageContainer {
|
|
84
|
-
style?: InAppMessageStyle;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
interface InAppMessageHeader {
|
|
88
|
-
content: string;
|
|
89
|
-
style?: InAppMessageStyle;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
interface InAppMessageBody {
|
|
93
|
-
content: string;
|
|
94
|
-
style?: InAppMessageStyle;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface InAppMessageImage {
|
|
98
|
-
src: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface InAppMessageButton {
|
|
102
|
-
title: string;
|
|
103
|
-
action: InAppMessageAction;
|
|
104
|
-
url?: string;
|
|
105
|
-
style?: InAppMessageStyle;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export interface InAppMessageStyle {
|
|
109
|
-
backgroundColor?: string;
|
|
110
|
-
borderRadius?: number;
|
|
111
|
-
color?: string;
|
|
112
|
-
textAlign?: InAppMessageTextAlign;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export interface InAppMessageContent {
|
|
116
|
-
container?: InAppMessageContainer;
|
|
117
|
-
header?: InAppMessageHeader;
|
|
118
|
-
body?: InAppMessageBody;
|
|
119
|
-
image?: InAppMessageImage;
|
|
120
|
-
primaryButton?: InAppMessageButton;
|
|
121
|
-
secondaryButton?: InAppMessageButton;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface InAppMessage {
|
|
125
|
-
id: string;
|
|
126
|
-
layout: InAppMessageLayout;
|
|
127
|
-
content: InAppMessageContent[];
|
|
128
|
-
metadata?: any;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export type OnMessageInteractionEventHandler = (message: InAppMessage) => any;
|
|
132
|
-
|
|
133
|
-
export enum InAppMessageInteractionEvent {
|
|
134
|
-
MESSAGE_RECEIVED = 'MESSAGE_RECEIVED_EVENT',
|
|
135
|
-
MESSAGE_DISPLAYED = 'MESSAGE_DISPLAYED_EVENT',
|
|
136
|
-
MESSAGE_DISMISSED = 'MESSAGE_DISMISSED_EVENT',
|
|
137
|
-
MESSAGE_ACTION_TAKEN = 'MESSAGE_ACTION_TAKEN_EVENT',
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export type InAppMessageConflictHandler = (
|
|
141
|
-
messages: InAppMessage[]
|
|
142
|
-
) => InAppMessage;
|