Skip to content

Commit 6daae6b

Browse files
author
Kamil Sobol
authored
cover notifications and analytics in client config (#1003)
1 parent b1c3e0d commit 6daae6b

File tree

10 files changed

+387
-2
lines changed

10 files changed

+387
-2
lines changed

.changeset/grumpy-avocados-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/client-config': minor
3+
---
4+
5+
Add typings for notifications and analytics categories in client config

.eslint_dictionary.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"amazonaws",
44
"amazoncognito",
55
"amplifyconfiguration",
6+
"apns",
67
"appleid",
78
"appsync",
89
"argv",

packages/client-config/API.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
import { AwsCredentialIdentityProvider } from '@aws-sdk/types';
88
import { DeployedBackendIdentifier } from '@aws-amplify/deployed-backend-client';
99

10+
// @public (undocumented)
11+
export type AnalyticsClientConfig = {
12+
Analytics?: {
13+
AWSPinpoint: {
14+
appId: string;
15+
region: string;
16+
};
17+
};
18+
};
19+
1020
// @public
1121
export type AuthClientConfig = {
1222
aws_cognito_region: string;
@@ -36,7 +46,7 @@ export type AuthClientConfig = {
3646
};
3747

3848
// @public
39-
export type ClientConfig = Partial<AuthClientConfig & GeoClientConfig & GraphqlClientConfig & StorageClientConfig & PlatformClientConfig & CustomClientConfig>;
49+
export type ClientConfig = Partial<AnalyticsClientConfig & AuthClientConfig & GeoClientConfig & GraphqlClientConfig & NotificationsClientConfig & StorageClientConfig & PlatformClientConfig & CustomClientConfig>;
4050

4151
// @public (undocumented)
4252
export enum ClientConfigFormat {
@@ -100,6 +110,42 @@ export type GraphqlClientConfig = {
100110
modelIntrospection?: unknown;
101111
};
102112

113+
// @public (undocumented)
114+
export type NotificationsClientConfig = {
115+
Notifications?: {
116+
SMS?: {
117+
AWSPinpoint: {
118+
appId: string;
119+
region: string;
120+
};
121+
};
122+
EMAIL?: {
123+
AWSPinpoint: {
124+
appId: string;
125+
region: string;
126+
};
127+
};
128+
APNS?: {
129+
AWSPinpoint: {
130+
appId: string;
131+
region: string;
132+
};
133+
};
134+
FCM?: {
135+
AWSPinpoint: {
136+
appId: string;
137+
region: string;
138+
};
139+
};
140+
InAppMessaging?: {
141+
AWSPinpoint: {
142+
appId: string;
143+
region: string;
144+
};
145+
};
146+
};
147+
};
148+
103149
// @public (undocumented)
104150
export type PlatformClientConfig = {
105151
aws_project_region: string;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export type AnalyticsClientConfig = {
2+
Analytics?: {
3+
AWSPinpoint: {
4+
appId: string;
5+
region: string;
6+
};
7+
};
8+
};

packages/client-config/src/client-config-types/client_config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import { PlatformClientConfig } from './platform_client_config.js';
44
import { StorageClientConfig } from './storage_client_config.js';
55
import { CustomClientConfig } from './custom_client_config.js';
66
import { GeoClientConfig } from './geo_client_config.js';
7+
import { AnalyticsClientConfig } from './analytics_client_config.js';
8+
import { NotificationsClientConfig } from './notifications_client_config.js';
79

810
/**
911
* Merged type of all category client config types
1012
*/
1113
export type ClientConfig = Partial<
12-
AuthClientConfig &
14+
AnalyticsClientConfig &
15+
AuthClientConfig &
1316
GeoClientConfig &
1417
GraphqlClientConfig &
18+
NotificationsClientConfig &
1519
StorageClientConfig &
1620
PlatformClientConfig &
1721
CustomClientConfig

packages/client-config/src/client-config-types/mobile/client_config_mobile_types.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
export type ClientConfigMobile = {
22
UserAgent: string;
33
Version: '1.0';
4+
analytics?: ClientConfigMobileAnalytics;
45
api?: ClientConfigMobileApi;
56
auth?: ClientConfigMobileAuth;
67
geo?: ClientConfigMobileGeo;
8+
notifications?: ClientConfigMobileNotifications;
79
};
810

911
export type ClientConfigMobileApi = {
@@ -91,3 +93,38 @@ export type ClientConfigMobileGeo = {
9193
};
9294
};
9395
};
96+
97+
export type ClientConfigMobileAnalytics = {
98+
plugins: {
99+
awsPinpointAnalyticsPlugin: {
100+
pinpointAnalytics: {
101+
appId: string;
102+
region: string;
103+
};
104+
pinpointTargeting: {
105+
region: string;
106+
};
107+
};
108+
};
109+
};
110+
111+
export type ClientConfigMobileNotifications = {
112+
plugins: {
113+
awsPinpointSmsNotificationsPlugin?: {
114+
appId: string;
115+
region: string;
116+
};
117+
awsPinpointEmailNotificationsPlugin?: {
118+
appId: string;
119+
region: string;
120+
};
121+
awsPinpointPushNotificationsPlugin?: {
122+
appId: string;
123+
region: string;
124+
};
125+
awsPinpointInAppMessagingNotificationsPlugin?: {
126+
appId: string;
127+
region: string;
128+
};
129+
};
130+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export type NotificationsClientConfig = {
2+
Notifications?: {
3+
SMS?: {
4+
AWSPinpoint: {
5+
appId: string;
6+
region: string;
7+
};
8+
};
9+
EMAIL?: {
10+
AWSPinpoint: {
11+
appId: string;
12+
region: string;
13+
};
14+
};
15+
APNS?: {
16+
AWSPinpoint: {
17+
appId: string;
18+
region: string;
19+
};
20+
};
21+
FCM?: {
22+
AWSPinpoint: {
23+
appId: string;
24+
region: string;
25+
};
26+
};
27+
InAppMessaging?: {
28+
AWSPinpoint: {
29+
appId: string;
30+
region: string;
31+
};
32+
};
33+
};
34+
};

packages/client-config/src/client-config-writer/client_config_converter.test.ts

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,193 @@ void describe('client config converter', () => {
279279

280280
assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
281281
});
282+
283+
void it('converts analytics config', () => {
284+
const clientConfig: ClientConfig = {
285+
Analytics: {
286+
AWSPinpoint: {
287+
appId: 'test_pinpoint_id',
288+
region: 'us-west-2',
289+
},
290+
},
291+
};
292+
293+
const expectedMobileConfig: ClientConfigMobile = {
294+
UserAgent: 'test_package_name/test_package_version;',
295+
Version: '1.0',
296+
analytics: {
297+
plugins: {
298+
awsPinpointAnalyticsPlugin: {
299+
pinpointAnalytics: {
300+
appId: 'test_pinpoint_id',
301+
region: 'us-west-2',
302+
},
303+
pinpointTargeting: {
304+
region: 'us-west-2',
305+
},
306+
},
307+
},
308+
},
309+
};
310+
311+
const actualMobileConfig = converter.convertToMobileConfig(clientConfig);
312+
313+
assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
314+
});
315+
316+
void it('converts full notifications config', () => {
317+
const clientConfig: ClientConfig = {
318+
Notifications: {
319+
SMS: {
320+
AWSPinpoint: {
321+
appId: 'sms_app_id',
322+
region: 'sms_region',
323+
},
324+
},
325+
EMAIL: {
326+
AWSPinpoint: {
327+
appId: 'email_app_id',
328+
region: 'email_region',
329+
},
330+
},
331+
FCM: {
332+
AWSPinpoint: {
333+
appId: 'push_app_id',
334+
region: 'push_region',
335+
},
336+
},
337+
APNS: {
338+
AWSPinpoint: {
339+
appId: 'push_app_id',
340+
region: 'push_region',
341+
},
342+
},
343+
InAppMessaging: {
344+
AWSPinpoint: {
345+
appId: 'in_app_messaging_app_id',
346+
region: 'in_app_messaging_region',
347+
},
348+
},
349+
},
350+
};
351+
352+
const expectedMobileConfig: ClientConfigMobile = {
353+
UserAgent: 'test_package_name/test_package_version;',
354+
Version: '1.0',
355+
notifications: {
356+
plugins: {
357+
awsPinpointEmailNotificationsPlugin: {
358+
appId: 'email_app_id',
359+
region: 'email_region',
360+
},
361+
awsPinpointInAppMessagingNotificationsPlugin: {
362+
appId: 'in_app_messaging_app_id',
363+
region: 'in_app_messaging_region',
364+
},
365+
awsPinpointPushNotificationsPlugin: {
366+
appId: 'push_app_id',
367+
region: 'push_region',
368+
},
369+
awsPinpointSmsNotificationsPlugin: {
370+
appId: 'sms_app_id',
371+
region: 'sms_region',
372+
},
373+
},
374+
},
375+
};
376+
377+
const actualMobileConfig = converter.convertToMobileConfig(clientConfig);
378+
379+
assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
380+
});
381+
382+
void it('converts apn notifications config', () => {
383+
const clientConfig: ClientConfig = {
384+
Notifications: {
385+
APNS: {
386+
AWSPinpoint: {
387+
appId: 'push_app_id',
388+
region: 'push_region',
389+
},
390+
},
391+
},
392+
};
393+
394+
const expectedMobileConfig: ClientConfigMobile = {
395+
UserAgent: 'test_package_name/test_package_version;',
396+
Version: '1.0',
397+
notifications: {
398+
plugins: {
399+
awsPinpointPushNotificationsPlugin: {
400+
appId: 'push_app_id',
401+
region: 'push_region',
402+
},
403+
},
404+
},
405+
};
406+
407+
const actualMobileConfig = converter.convertToMobileConfig(clientConfig);
408+
409+
assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
410+
});
411+
412+
void it('converts fcm notifications config', () => {
413+
const clientConfig: ClientConfig = {
414+
Notifications: {
415+
FCM: {
416+
AWSPinpoint: {
417+
appId: 'push_app_id',
418+
region: 'push_region',
419+
},
420+
},
421+
},
422+
};
423+
424+
const expectedMobileConfig: ClientConfigMobile = {
425+
UserAgent: 'test_package_name/test_package_version;',
426+
Version: '1.0',
427+
notifications: {
428+
plugins: {
429+
awsPinpointPushNotificationsPlugin: {
430+
appId: 'push_app_id',
431+
region: 'push_region',
432+
},
433+
},
434+
},
435+
};
436+
437+
const actualMobileConfig = converter.convertToMobileConfig(clientConfig);
438+
439+
assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
440+
});
441+
442+
void it('throw on ambiguous push config', () => {
443+
const clientConfig: ClientConfig = {
444+
Notifications: {
445+
FCM: {
446+
AWSPinpoint: {
447+
appId: 'push_app_id_1',
448+
region: 'push_region',
449+
},
450+
},
451+
APNS: {
452+
AWSPinpoint: {
453+
appId: 'push_app_id_2',
454+
region: 'push_region',
455+
},
456+
},
457+
},
458+
};
459+
460+
assert.throws(
461+
() => converter.convertToMobileConfig(clientConfig),
462+
(error: Error) => {
463+
assert.strictEqual(
464+
error.message,
465+
'Cannot convert client config to mobile config if both FCM and APNS are defined with different AWS Pinpoint instance'
466+
);
467+
return true;
468+
}
469+
);
470+
});
282471
});

0 commit comments

Comments
 (0)