@aws-amplify/notifications 1.6.4-user-agent-backup.c6dfb36.0 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/InAppMessaging/InAppMessaging.d.ts +43 -3
- package/lib/InAppMessaging/InAppMessaging.js +317 -9
- package/lib/InAppMessaging/InAppMessaging.js.map +1 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.d.ts +1 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js +2 -2
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib/InAppMessaging/types.d.ts +4 -5
- package/lib/InAppMessaging/types.js.map +1 -1
- package/lib/Notifications.js +1 -1
- package/lib/Notifications.js.map +1 -1
- package/lib/common/AWSPinpointProviderCommon/index.d.ts +2 -2
- package/lib/common/AWSPinpointProviderCommon/index.js +4 -8
- package/lib/common/AWSPinpointProviderCommon/index.js.map +1 -1
- package/lib/types.d.ts +1 -1
- package/lib-esm/InAppMessaging/InAppMessaging.d.ts +43 -3
- package/lib-esm/InAppMessaging/InAppMessaging.js +318 -10
- package/lib-esm/InAppMessaging/InAppMessaging.js.map +1 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.d.ts +1 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js +2 -2
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib-esm/InAppMessaging/types.d.ts +4 -5
- package/lib-esm/InAppMessaging/types.js.map +1 -1
- package/lib-esm/Notifications.js +1 -1
- package/lib-esm/Notifications.js.map +1 -1
- package/lib-esm/common/AWSPinpointProviderCommon/index.d.ts +2 -2
- package/lib-esm/common/AWSPinpointProviderCommon/index.js +4 -8
- package/lib-esm/common/AWSPinpointProviderCommon/index.js.map +1 -1
- package/lib-esm/types.d.ts +1 -1
- package/package.json +8 -9
- package/src/InAppMessaging/InAppMessaging.ts +300 -8
- package/src/InAppMessaging/Providers/AWSPinpointProvider/index.ts +2 -2
- package/src/InAppMessaging/types.ts +3 -7
- package/src/Notifications.ts +1 -1
- package/src/common/AWSPinpointProviderCommon/index.ts +4 -13
- package/src/types.ts +1 -5
- package/internals/package.json +0 -8
- package/lib/internals/InternalInAppMessaging.d.ts +0 -59
- package/lib/internals/InternalInAppMessaging.js +0 -349
- package/lib/internals/InternalInAppMessaging.js.map +0 -1
- package/lib/internals/index.d.ts +0 -1
- package/lib/internals/index.js +0 -7
- package/lib/internals/index.js.map +0 -1
- package/lib/internals/utils.d.ts +0 -2
- package/lib/internals/utils.js +0 -10
- package/lib/internals/utils.js.map +0 -1
- package/lib-esm/internals/InternalInAppMessaging.d.ts +0 -59
- package/lib-esm/internals/InternalInAppMessaging.js +0 -347
- package/lib-esm/internals/InternalInAppMessaging.js.map +0 -1
- package/lib-esm/internals/index.d.ts +0 -1
- package/lib-esm/internals/index.js +0 -4
- package/lib-esm/internals/index.js.map +0 -1
- package/lib-esm/internals/utils.d.ts +0 -2
- package/lib-esm/internals/utils.js +0 -8
- package/lib-esm/internals/utils.js.map +0 -1
- package/src/internals/InternalInAppMessaging.ts +0 -352
- package/src/internals/index.ts +0 -4
- package/src/internals/utils.ts +0 -20
package/lib-esm/types.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface NotificationsProvider {
|
|
|
7
7
|
getCategory(): NotificationsCategory;
|
|
8
8
|
getSubCategory(): NotificationsSubCategory;
|
|
9
9
|
getProviderName(): string;
|
|
10
|
-
identifyUser(userId: string, userInfo: UserInfo
|
|
10
|
+
identifyUser(userId: string, userInfo: UserInfo): Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
export interface NotificationsConfig {
|
|
13
13
|
Notifications?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/notifications",
|
|
3
|
-
"version": "1.6.4
|
|
3
|
+
"version": "1.6.4",
|
|
4
4
|
"description": "Notifications category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -46,13 +46,12 @@
|
|
|
46
46
|
"files": [
|
|
47
47
|
"lib",
|
|
48
48
|
"lib-esm",
|
|
49
|
-
"src"
|
|
50
|
-
"internals"
|
|
49
|
+
"src"
|
|
51
50
|
],
|
|
52
51
|
"dependencies": {
|
|
53
|
-
"@aws-amplify/cache": "5.1.10
|
|
54
|
-
"@aws-amplify/core": "5.8.4
|
|
55
|
-
"@aws-amplify/rtn-push-notification": "1.1.6
|
|
52
|
+
"@aws-amplify/cache": "5.1.10",
|
|
53
|
+
"@aws-amplify/core": "5.8.4",
|
|
54
|
+
"@aws-amplify/rtn-push-notification": "1.1.6",
|
|
56
55
|
"lodash": "^4.17.21",
|
|
57
56
|
"uuid": "^3.2.1"
|
|
58
57
|
},
|
|
@@ -66,14 +65,14 @@
|
|
|
66
65
|
"name": "Notifications (top-level class)",
|
|
67
66
|
"path": "./lib-esm/index.js",
|
|
68
67
|
"import": "{ Amplify, Notifications }",
|
|
69
|
-
"limit": "
|
|
68
|
+
"limit": "29.95 kB"
|
|
70
69
|
},
|
|
71
70
|
{
|
|
72
71
|
"name": "Notifications (with Analytics)",
|
|
73
72
|
"path": "./lib-esm/index.js",
|
|
74
73
|
"import": "{ Amplify, Notifications, Analytics }",
|
|
75
|
-
"limit": "
|
|
74
|
+
"limit": "29.95 kB"
|
|
76
75
|
}
|
|
77
76
|
],
|
|
78
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "f0df916a96cdd4b4f2ebbf45c3d3add6d5f16e37"
|
|
79
78
|
}
|
|
@@ -1,14 +1,78 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import {
|
|
5
|
+
ConsoleLogger as Logger,
|
|
6
|
+
HubCallback,
|
|
7
|
+
HubCapsule,
|
|
8
|
+
Hub,
|
|
9
|
+
StorageHelper,
|
|
10
|
+
} from '@aws-amplify/core';
|
|
11
|
+
import flatten from 'lodash/flatten';
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
addEventListener,
|
|
15
|
+
EventListener,
|
|
16
|
+
notifyEventListeners,
|
|
17
|
+
} from '../common';
|
|
4
18
|
import { UserInfo } from '../types';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
19
|
+
import { AWSPinpointProvider } from './Providers';
|
|
20
|
+
import {
|
|
21
|
+
InAppMessage,
|
|
22
|
+
InAppMessageInteractionEvent,
|
|
23
|
+
InAppMessagingInterface,
|
|
24
|
+
InAppMessagingConfig,
|
|
25
|
+
InAppMessageConflictHandler,
|
|
26
|
+
InAppMessagingEvent,
|
|
27
|
+
InAppMessagingProvider,
|
|
28
|
+
NotificationsSubCategory,
|
|
29
|
+
OnMessageInteractionEventHandler,
|
|
30
|
+
} from './types';
|
|
31
|
+
|
|
32
|
+
const STORAGE_KEY_SUFFIX = '_inAppMessages';
|
|
33
|
+
|
|
34
|
+
const logger = new Logger('Notifications.InAppMessaging');
|
|
35
|
+
|
|
36
|
+
export default class InAppMessaging implements InAppMessagingInterface {
|
|
37
|
+
private config: Record<string, any> = {};
|
|
38
|
+
private conflictHandler: InAppMessageConflictHandler;
|
|
39
|
+
private listeningForAnalyticEvents = false;
|
|
40
|
+
private pluggables: InAppMessagingProvider[] = [];
|
|
41
|
+
private storageSynced = false;
|
|
42
|
+
|
|
43
|
+
constructor() {
|
|
44
|
+
this.config = { storage: new StorageHelper().getStorage() };
|
|
45
|
+
this.setConflictHandler(this.defaultConflictHandler);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Configure InAppMessaging
|
|
50
|
+
* @param {Object} config - InAppMessaging configuration object
|
|
51
|
+
*/
|
|
52
|
+
configure = ({
|
|
53
|
+
listenForAnalyticsEvents = true,
|
|
54
|
+
...config
|
|
55
|
+
}: InAppMessagingConfig = {}): InAppMessagingConfig => {
|
|
56
|
+
this.config = { ...this.config, ...config };
|
|
57
|
+
|
|
58
|
+
logger.debug('configure InAppMessaging', this.config);
|
|
59
|
+
|
|
60
|
+
this.pluggables.forEach(pluggable => {
|
|
61
|
+
pluggable.configure(this.config[pluggable.getProviderName()]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (this.pluggables.length === 0) {
|
|
65
|
+
this.addPluggable(new AWSPinpointProvider());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (listenForAnalyticsEvents && !this.listeningForAnalyticEvents) {
|
|
69
|
+
Hub.listen('analytics', this.analyticsListener);
|
|
70
|
+
this.listeningForAnalyticEvents = true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return this.config;
|
|
74
|
+
};
|
|
7
75
|
|
|
8
|
-
export default class InAppMessaging
|
|
9
|
-
extends InternalInAppMessagingClass
|
|
10
|
-
implements InAppMessagingInterface
|
|
11
|
-
{
|
|
12
76
|
/**
|
|
13
77
|
* Get the name of this module
|
|
14
78
|
* @returns {string} name of this module
|
|
@@ -17,13 +81,241 @@ export default class InAppMessaging
|
|
|
17
81
|
return 'InAppMessaging';
|
|
18
82
|
}
|
|
19
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Get a plugin from added plugins
|
|
86
|
+
* @param {string} providerName - the name of the plugin to get
|
|
87
|
+
*/
|
|
88
|
+
getPluggable = (providerName: string): InAppMessagingProvider => {
|
|
89
|
+
const pluggable =
|
|
90
|
+
this.pluggables.find(
|
|
91
|
+
pluggable => pluggable.getProviderName() === providerName
|
|
92
|
+
) ?? null;
|
|
93
|
+
|
|
94
|
+
if (!pluggable) {
|
|
95
|
+
logger.debug(`No plugin found with name ${providerName}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return pluggable;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Add plugin into InAppMessaging
|
|
103
|
+
* @param {InAppMessagingProvider} pluggable - an instance of the plugin
|
|
104
|
+
*/
|
|
105
|
+
addPluggable = (pluggable: InAppMessagingProvider): void => {
|
|
106
|
+
if (
|
|
107
|
+
pluggable &&
|
|
108
|
+
pluggable.getCategory() === 'Notifications' &&
|
|
109
|
+
pluggable.getSubCategory() === 'InAppMessaging'
|
|
110
|
+
) {
|
|
111
|
+
if (this.getPluggable(pluggable.getProviderName())) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`Pluggable ${pluggable.getProviderName()} has already been added.`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
this.pluggables.push(pluggable);
|
|
117
|
+
pluggable.configure(this.config[pluggable.getProviderName()]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Remove a plugin from added plugins
|
|
123
|
+
* @param {string} providerName - the name of the plugin to remove
|
|
124
|
+
*/
|
|
125
|
+
removePluggable = (providerName: string): void => {
|
|
126
|
+
const index = this.pluggables.findIndex(
|
|
127
|
+
pluggable => pluggable.getProviderName() === providerName
|
|
128
|
+
);
|
|
129
|
+
if (index === -1) {
|
|
130
|
+
logger.debug(`No plugin found with name ${providerName}`);
|
|
131
|
+
} else {
|
|
132
|
+
this.pluggables.splice(index, 1);
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
20
136
|
/**
|
|
21
137
|
* Get the map resources that are currently available through the provider
|
|
22
138
|
* @param {string} provider
|
|
23
139
|
* @returns - Array of available map resources
|
|
24
140
|
*/
|
|
25
|
-
syncMessages = (): Promise<void[]> =>
|
|
141
|
+
syncMessages = (): Promise<void[]> =>
|
|
142
|
+
Promise.all<void>(
|
|
143
|
+
this.pluggables.map(async pluggable => {
|
|
144
|
+
try {
|
|
145
|
+
const messages = await pluggable.getInAppMessages();
|
|
146
|
+
const key = `${pluggable.getProviderName()}${STORAGE_KEY_SUFFIX}`;
|
|
147
|
+
await this.setMessages(key, messages);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
logger.error('Failed to sync messages', err);
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
clearMessages = (): Promise<void[]> =>
|
|
156
|
+
Promise.all<void>(
|
|
157
|
+
this.pluggables.map(async pluggable => {
|
|
158
|
+
const key = `${pluggable.getProviderName()}${STORAGE_KEY_SUFFIX}`;
|
|
159
|
+
await this.removeMessages(key);
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
dispatchEvent = async (event: InAppMessagingEvent): Promise<void> => {
|
|
164
|
+
const messages: InAppMessage[][] = await Promise.all<InAppMessage[]>(
|
|
165
|
+
this.pluggables.map(async pluggable => {
|
|
166
|
+
const key = `${pluggable.getProviderName()}${STORAGE_KEY_SUFFIX}`;
|
|
167
|
+
const messages = await this.getMessages(key);
|
|
168
|
+
return pluggable.processInAppMessages(messages, event);
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const flattenedMessages = flatten(messages);
|
|
173
|
+
|
|
174
|
+
if (flattenedMessages.length) {
|
|
175
|
+
notifyEventListeners(
|
|
176
|
+
InAppMessageInteractionEvent.MESSAGE_RECEIVED,
|
|
177
|
+
this.conflictHandler(flattenedMessages)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
26
181
|
|
|
27
182
|
identifyUser = (userId: string, userInfo: UserInfo): Promise<void[]> =>
|
|
28
|
-
|
|
183
|
+
Promise.all<void>(
|
|
184
|
+
this.pluggables.map(async pluggable => {
|
|
185
|
+
try {
|
|
186
|
+
await pluggable.identifyUser(userId, userInfo);
|
|
187
|
+
} catch (err) {
|
|
188
|
+
logger.error('Failed to identify user', err);
|
|
189
|
+
throw err;
|
|
190
|
+
}
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
onMessageReceived = (
|
|
195
|
+
handler: OnMessageInteractionEventHandler
|
|
196
|
+
): EventListener<OnMessageInteractionEventHandler> =>
|
|
197
|
+
addEventListener(InAppMessageInteractionEvent.MESSAGE_RECEIVED, handler);
|
|
198
|
+
|
|
199
|
+
onMessageDisplayed = (
|
|
200
|
+
handler: OnMessageInteractionEventHandler
|
|
201
|
+
): EventListener<OnMessageInteractionEventHandler> =>
|
|
202
|
+
addEventListener(InAppMessageInteractionEvent.MESSAGE_DISPLAYED, handler);
|
|
203
|
+
|
|
204
|
+
onMessageDismissed = (
|
|
205
|
+
handler: OnMessageInteractionEventHandler
|
|
206
|
+
): EventListener<OnMessageInteractionEventHandler> =>
|
|
207
|
+
addEventListener(InAppMessageInteractionEvent.MESSAGE_DISMISSED, handler);
|
|
208
|
+
|
|
209
|
+
onMessageActionTaken = (
|
|
210
|
+
handler: OnMessageInteractionEventHandler
|
|
211
|
+
): EventListener<OnMessageInteractionEventHandler> =>
|
|
212
|
+
addEventListener(
|
|
213
|
+
InAppMessageInteractionEvent.MESSAGE_ACTION_TAKEN,
|
|
214
|
+
handler
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
notifyMessageInteraction = (
|
|
218
|
+
message: InAppMessage,
|
|
219
|
+
type: InAppMessageInteractionEvent
|
|
220
|
+
): void => {
|
|
221
|
+
notifyEventListeners(type, message);
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
setConflictHandler = (handler: InAppMessageConflictHandler): void => {
|
|
225
|
+
this.conflictHandler = handler;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
private analyticsListener: HubCallback = ({ payload }: HubCapsule) => {
|
|
229
|
+
const { event, data } = payload;
|
|
230
|
+
switch (event) {
|
|
231
|
+
case 'record': {
|
|
232
|
+
this.dispatchEvent(data);
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
default:
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
private syncStorage = async (): Promise<void> => {
|
|
241
|
+
const { storage } = this.config;
|
|
242
|
+
try {
|
|
243
|
+
// Only run sync() if it's available (i.e. React Native)
|
|
244
|
+
if (typeof storage.sync === 'function') {
|
|
245
|
+
await storage.sync();
|
|
246
|
+
}
|
|
247
|
+
this.storageSynced = true;
|
|
248
|
+
} catch (err) {
|
|
249
|
+
logger.error('Failed to sync storage', err);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
private getMessages = async (key: string): Promise<any> => {
|
|
254
|
+
try {
|
|
255
|
+
if (!this.storageSynced) {
|
|
256
|
+
await this.syncStorage();
|
|
257
|
+
}
|
|
258
|
+
const { storage } = this.config;
|
|
259
|
+
const storedMessages = storage.getItem(key);
|
|
260
|
+
return storedMessages ? JSON.parse(storedMessages) : [];
|
|
261
|
+
} catch (err) {
|
|
262
|
+
logger.error('Failed to retrieve in-app messages from storage', err);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
private setMessages = async (
|
|
267
|
+
key: string,
|
|
268
|
+
messages: InAppMessage[]
|
|
269
|
+
): Promise<void> => {
|
|
270
|
+
if (!messages) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
if (!this.storageSynced) {
|
|
276
|
+
await this.syncStorage();
|
|
277
|
+
}
|
|
278
|
+
const { storage } = this.config;
|
|
279
|
+
storage.setItem(key, JSON.stringify(messages));
|
|
280
|
+
} catch (err) {
|
|
281
|
+
logger.error('Failed to store in-app messages', err);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
private removeMessages = async (key: string): Promise<void> => {
|
|
286
|
+
try {
|
|
287
|
+
if (!this.storageSynced) {
|
|
288
|
+
await this.syncStorage();
|
|
289
|
+
}
|
|
290
|
+
const { storage } = this.config;
|
|
291
|
+
storage.removeItem(key);
|
|
292
|
+
} catch (err) {
|
|
293
|
+
logger.error('Failed to remove in-app messages from storage', err);
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
private defaultConflictHandler = (messages: InAppMessage[]): InAppMessage => {
|
|
298
|
+
// default behavior is to return the message closest to expiry
|
|
299
|
+
// this function assumes that messages processed by providers already filters out expired messages
|
|
300
|
+
const sorted = messages.sort((a, b) => {
|
|
301
|
+
const endDateA = a.metadata?.endDate;
|
|
302
|
+
const endDateB = b.metadata?.endDate;
|
|
303
|
+
// if both message end dates are falsy or have the same date string, treat them as equal
|
|
304
|
+
if (endDateA === endDateB) {
|
|
305
|
+
return 0;
|
|
306
|
+
}
|
|
307
|
+
// if only message A has an end date, treat it as closer to expiry
|
|
308
|
+
if (endDateA && !endDateB) {
|
|
309
|
+
return -1;
|
|
310
|
+
}
|
|
311
|
+
// if only message B has an end date, treat it as closer to expiry
|
|
312
|
+
if (!endDateA && endDateB) {
|
|
313
|
+
return 1;
|
|
314
|
+
}
|
|
315
|
+
// otherwise, compare them
|
|
316
|
+
return new Date(endDateA) < new Date(endDateB) ? -1 : 1;
|
|
317
|
+
});
|
|
318
|
+
// always return the top sorted
|
|
319
|
+
return sorted[0];
|
|
320
|
+
};
|
|
29
321
|
}
|
|
@@ -111,7 +111,7 @@ export default class AWSPinpointProvider
|
|
|
111
111
|
return this.config;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
getInAppMessages = async (
|
|
114
|
+
getInAppMessages = async () => {
|
|
115
115
|
if (!this.initialized) {
|
|
116
116
|
await this.init();
|
|
117
117
|
}
|
|
@@ -129,7 +129,7 @@ export default class AWSPinpointProvider
|
|
|
129
129
|
};
|
|
130
130
|
this.logger.debug('getting in-app messages');
|
|
131
131
|
const response: GetInAppMessagesOutput = await getInAppMessages(
|
|
132
|
-
{ credentials, region
|
|
132
|
+
{ credentials, region },
|
|
133
133
|
input
|
|
134
134
|
);
|
|
135
135
|
const { InAppMessageCampaigns: messages } =
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { EventListener } from '../common';
|
|
5
5
|
import { AWSPinpointProviderConfig } from '../common/AWSPinpointProviderCommon/types';
|
|
6
6
|
import {
|
|
7
|
-
NotificationsConfig,
|
|
8
7
|
NotificationsProvider,
|
|
9
8
|
NotificationsSubCategory as NotificationsSubCategories,
|
|
10
9
|
UserInfo,
|
|
@@ -14,13 +13,10 @@ export type NotificationsSubCategory = Extract<
|
|
|
14
13
|
NotificationsSubCategories,
|
|
15
14
|
'InAppMessaging'
|
|
16
15
|
>;
|
|
17
|
-
export type InternalNotificationsSubCategory = 'InternalInAppMessaging';
|
|
18
16
|
|
|
19
17
|
export interface InAppMessagingInterface {
|
|
20
|
-
configure: (config:
|
|
21
|
-
getModuleName: () =>
|
|
22
|
-
| NotificationsSubCategory
|
|
23
|
-
| InternalNotificationsSubCategory;
|
|
18
|
+
configure: (config: InAppMessagingConfig) => InAppMessagingConfig;
|
|
19
|
+
getModuleName: () => NotificationsSubCategory;
|
|
24
20
|
getPluggable: (providerName: string) => InAppMessagingProvider;
|
|
25
21
|
addPluggable: (pluggable: InAppMessagingProvider) => void;
|
|
26
22
|
removePluggable: (providerName: string) => void;
|
|
@@ -52,7 +48,7 @@ export interface InAppMessagingProvider extends NotificationsProvider {
|
|
|
52
48
|
getSubCategory(): NotificationsSubCategory;
|
|
53
49
|
|
|
54
50
|
// get in-app messages from provider
|
|
55
|
-
getInAppMessages(
|
|
51
|
+
getInAppMessages(): Promise<any>;
|
|
56
52
|
|
|
57
53
|
// filters in-app messages based on event input and provider logic
|
|
58
54
|
processInAppMessages(
|
package/src/Notifications.ts
CHANGED
|
@@ -38,7 +38,7 @@ class NotificationsClass {
|
|
|
38
38
|
logger.debug('configure Notifications', config);
|
|
39
39
|
|
|
40
40
|
// Configure sub-categories
|
|
41
|
-
this.inAppMessaging.configure(
|
|
41
|
+
this.inAppMessaging.configure(this.config.InAppMessaging);
|
|
42
42
|
|
|
43
43
|
if (this.config.Push) {
|
|
44
44
|
try {
|
|
@@ -77,16 +77,12 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
77
77
|
return this.config;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
identifyUser = async (
|
|
81
|
-
userId: string,
|
|
82
|
-
userInfo: UserInfo,
|
|
83
|
-
userAgentValue?: string
|
|
84
|
-
): Promise<void> => {
|
|
80
|
+
identifyUser = async (userId: string, userInfo: UserInfo): Promise<void> => {
|
|
85
81
|
if (!this.initialized) {
|
|
86
82
|
await this.init();
|
|
87
83
|
}
|
|
88
84
|
try {
|
|
89
|
-
await this.updateEndpoint(userId, userInfo
|
|
85
|
+
await this.updateEndpoint(userId, userInfo);
|
|
90
86
|
} catch (err) {
|
|
91
87
|
this.logger.error('Error identifying user', err);
|
|
92
88
|
throw err;
|
|
@@ -165,8 +161,7 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
165
161
|
|
|
166
162
|
protected updateEndpoint = async (
|
|
167
163
|
userId: string = null,
|
|
168
|
-
userInfo: AWSPinpointUserInfo = null
|
|
169
|
-
userAgentValue?: string
|
|
164
|
+
userInfo: AWSPinpointUserInfo = null
|
|
170
165
|
): Promise<void> => {
|
|
171
166
|
const credentials = await this.getCredentials();
|
|
172
167
|
// Shallow compare to determine if credentials stored here are outdated
|
|
@@ -235,11 +230,7 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
235
230
|
};
|
|
236
231
|
this.logger.debug('updating endpoint');
|
|
237
232
|
await updateEndpoint(
|
|
238
|
-
{
|
|
239
|
-
credentials,
|
|
240
|
-
region,
|
|
241
|
-
userAgentValue: userAgentValue || this.getUserAgentValue(),
|
|
242
|
-
},
|
|
233
|
+
{ credentials, region, userAgentValue: this.getUserAgentValue() },
|
|
243
234
|
input
|
|
244
235
|
);
|
|
245
236
|
this.endpointInitialized = true;
|
package/src/types.ts
CHANGED
|
@@ -22,11 +22,7 @@ export interface NotificationsProvider {
|
|
|
22
22
|
getProviderName(): string;
|
|
23
23
|
|
|
24
24
|
// identify the current user with the provider
|
|
25
|
-
identifyUser(
|
|
26
|
-
userId: string,
|
|
27
|
-
userInfo: UserInfo,
|
|
28
|
-
userAgentValue?: string
|
|
29
|
-
): Promise<void>;
|
|
25
|
+
identifyUser(userId: string, userInfo: UserInfo): Promise<void>;
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
export interface NotificationsConfig {
|
package/internals/package.json
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { CustomUserAgentDetails } from '@aws-amplify/core';
|
|
2
|
-
import { EventListener } from '../common';
|
|
3
|
-
import { NotificationsConfig, UserInfo } from '../types';
|
|
4
|
-
import { InAppMessage, InAppMessageInteractionEvent, InAppMessagingInterface, InAppMessagingConfig, InAppMessageConflictHandler, InAppMessagingEvent, InAppMessagingProvider, OnMessageInteractionEventHandler, InternalNotificationsSubCategory, NotificationsSubCategory } from '../InAppMessaging/types';
|
|
5
|
-
export declare class InternalInAppMessagingClass implements InAppMessagingInterface {
|
|
6
|
-
private config;
|
|
7
|
-
private conflictHandler;
|
|
8
|
-
private listeningForAnalyticEvents;
|
|
9
|
-
private pluggables;
|
|
10
|
-
private storageSynced;
|
|
11
|
-
constructor();
|
|
12
|
-
/**
|
|
13
|
-
* Configure InAppMessaging
|
|
14
|
-
* @param {Object} config - InAppMessaging configuration object
|
|
15
|
-
*/
|
|
16
|
-
configure({ Notifications: notificationsConfig, }?: NotificationsConfig): InAppMessagingConfig;
|
|
17
|
-
/**
|
|
18
|
-
* Get the name of this module
|
|
19
|
-
* @returns {string} name of this module
|
|
20
|
-
*/
|
|
21
|
-
getModuleName(): NotificationsSubCategory | InternalNotificationsSubCategory;
|
|
22
|
-
/**
|
|
23
|
-
* Get a plugin from added plugins
|
|
24
|
-
* @param {string} providerName - the name of the plugin to get
|
|
25
|
-
*/
|
|
26
|
-
getPluggable: (providerName: string) => InAppMessagingProvider;
|
|
27
|
-
/**
|
|
28
|
-
* Add plugin into InAppMessaging
|
|
29
|
-
* @param {InAppMessagingProvider} pluggable - an instance of the plugin
|
|
30
|
-
*/
|
|
31
|
-
addPluggable: (pluggable: InAppMessagingProvider) => void;
|
|
32
|
-
/**
|
|
33
|
-
* Remove a plugin from added plugins
|
|
34
|
-
* @param {string} providerName - the name of the plugin to remove
|
|
35
|
-
*/
|
|
36
|
-
removePluggable: (providerName: string) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Get the map resources that are currently available through the provider
|
|
39
|
-
* @param {CustomUserAgentDetails} customUserAgentDetails optional parameter to send user agent details
|
|
40
|
-
* @returns - Array of available map resources
|
|
41
|
-
*/
|
|
42
|
-
syncMessages(customUserAgentDetails?: CustomUserAgentDetails): Promise<void[]>;
|
|
43
|
-
clearMessages(): Promise<void[]>;
|
|
44
|
-
dispatchEvent(event: InAppMessagingEvent): Promise<void>;
|
|
45
|
-
identifyUser(userId: string, userInfo: UserInfo, customUserAgentDetails?: CustomUserAgentDetails): Promise<void[]>;
|
|
46
|
-
onMessageReceived: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
47
|
-
onMessageDisplayed: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
48
|
-
onMessageDismissed: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
49
|
-
onMessageActionTaken: (handler: OnMessageInteractionEventHandler) => EventListener<OnMessageInteractionEventHandler>;
|
|
50
|
-
notifyMessageInteraction: (message: InAppMessage, type: InAppMessageInteractionEvent) => void;
|
|
51
|
-
setConflictHandler: (handler: InAppMessageConflictHandler) => void;
|
|
52
|
-
private analyticsListener;
|
|
53
|
-
private syncStorage;
|
|
54
|
-
private getMessages;
|
|
55
|
-
private setMessages;
|
|
56
|
-
private removeMessages;
|
|
57
|
-
private defaultConflictHandler;
|
|
58
|
-
}
|
|
59
|
-
export declare const InternalInAppMessaging: InternalInAppMessagingClass;
|