@aws-amplify/notifications 1.1.7 → 1.1.8-unstable.2d934a3.3
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/Providers/AWSPinpointProvider/index.d.ts +2 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js +5 -6
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/utils.d.ts +1 -1
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/utils.js +2 -3
- package/lib/InAppMessaging/Providers/AWSPinpointProvider/utils.js.map +1 -1
- package/lib/PushNotification/Providers/AWSPinpointProvider/index.js +2 -3
- package/lib/PushNotification/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib/PushNotification/Providers/AWSPinpointProvider/utils.d.ts +1 -1
- package/lib/common/AWSPinpointProviderCommon/index.d.ts +2 -2
- package/lib/common/AWSPinpointProviderCommon/index.js +44 -61
- package/lib/common/AWSPinpointProviderCommon/index.js.map +1 -1
- package/lib/common/AWSPinpointProviderCommon/types.d.ts +1 -0
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.d.ts +2 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js +5 -6
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/utils.d.ts +1 -1
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/utils.js +2 -3
- package/lib-esm/InAppMessaging/Providers/AWSPinpointProvider/utils.js.map +1 -1
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.js +2 -3
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/index.js.map +1 -1
- package/lib-esm/PushNotification/Providers/AWSPinpointProvider/utils.d.ts +1 -1
- package/lib-esm/common/AWSPinpointProviderCommon/index.d.ts +2 -2
- package/lib-esm/common/AWSPinpointProviderCommon/index.js +45 -62
- package/lib-esm/common/AWSPinpointProviderCommon/index.js.map +1 -1
- package/lib-esm/common/AWSPinpointProviderCommon/types.d.ts +1 -0
- package/package.json +7 -8
- package/src/InAppMessaging/Providers/AWSPinpointProvider/index.ts +11 -10
- package/src/InAppMessaging/Providers/AWSPinpointProvider/utils.ts +3 -6
- package/src/PushNotification/Providers/AWSPinpointProvider/index.ts +3 -3
- package/src/PushNotification/Providers/AWSPinpointProvider/utils.ts +1 -1
- package/src/common/AWSPinpointProviderCommon/index.ts +32 -64
- package/src/common/AWSPinpointProviderCommon/types.ts +15 -0
|
@@ -5,19 +5,17 @@ import {
|
|
|
5
5
|
ClientDevice,
|
|
6
6
|
ConsoleLogger,
|
|
7
7
|
Credentials,
|
|
8
|
-
getAmplifyUserAgent,
|
|
9
8
|
StorageHelper,
|
|
10
9
|
transferKeyToUpperCase,
|
|
11
10
|
} from '@aws-amplify/core';
|
|
12
11
|
import { Cache } from '@aws-amplify/cache';
|
|
13
12
|
import {
|
|
14
13
|
Event as AWSPinpointAnalyticsEvent,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from '@aws-sdk/client-pinpoint';
|
|
14
|
+
putEvents,
|
|
15
|
+
PutEventsInput,
|
|
16
|
+
updateEndpoint,
|
|
17
|
+
UpdateEndpointInput,
|
|
18
|
+
} from '@aws-amplify/core/internals/aws-clients/pinpoint';
|
|
21
19
|
import { v4 as uuid } from 'uuid';
|
|
22
20
|
|
|
23
21
|
import {
|
|
@@ -107,23 +105,15 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
107
105
|
protected recordAnalyticsEvent = async (
|
|
108
106
|
event: AWSPinpointAnalyticsEvent
|
|
109
107
|
): Promise<void> => {
|
|
110
|
-
const { appId, credentials, endpointId, pinpointClient } = this.config;
|
|
111
|
-
const currentCredentials = await this.getCredentials();
|
|
112
|
-
// Shallow compare to determine if credentials stored here are outdated
|
|
113
|
-
const credentialsUpdated =
|
|
114
|
-
!credentials ||
|
|
115
|
-
Object.keys(currentCredentials).some(
|
|
116
|
-
key => currentCredentials[key] !== credentials[key]
|
|
117
|
-
);
|
|
118
108
|
// Update credentials
|
|
119
|
-
this.config.credentials =
|
|
109
|
+
this.config.credentials = await this.getCredentials();
|
|
110
|
+
// Assert required configuration properties to make `putEvents` request are present
|
|
111
|
+
this.assertNotEmptyConfiguration();
|
|
112
|
+
const { appId, credentials, endpointId, region } = this.config;
|
|
113
|
+
|
|
120
114
|
try {
|
|
121
|
-
// Initialize a new pinpoint client if one isn't already configured or if credentials changed
|
|
122
|
-
if (!pinpointClient || credentialsUpdated) {
|
|
123
|
-
await this.initPinpointClient();
|
|
124
|
-
}
|
|
125
115
|
// Create the PutEvents input
|
|
126
|
-
const input:
|
|
116
|
+
const input: PutEventsInput = {
|
|
127
117
|
ApplicationId: appId,
|
|
128
118
|
EventsRequest: {
|
|
129
119
|
BatchItem: {
|
|
@@ -136,9 +126,8 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
136
126
|
},
|
|
137
127
|
},
|
|
138
128
|
};
|
|
139
|
-
const command: PutEventsCommand = new PutEventsCommand(input);
|
|
140
129
|
this.logger.debug('recording analytics event');
|
|
141
|
-
await
|
|
130
|
+
await putEvents({ credentials, region }, input);
|
|
142
131
|
} catch (err) {
|
|
143
132
|
this.logger.error('Error recording analytics event', err);
|
|
144
133
|
throw err;
|
|
@@ -149,19 +138,12 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
149
138
|
userId: string = null,
|
|
150
139
|
userInfo: AWSPinpointUserInfo = null
|
|
151
140
|
): Promise<void> => {
|
|
152
|
-
const
|
|
153
|
-
appId,
|
|
154
|
-
credentials,
|
|
155
|
-
endpointId,
|
|
156
|
-
endpointInfo = {},
|
|
157
|
-
pinpointClient,
|
|
158
|
-
} = this.config;
|
|
159
|
-
const currentCredentials = await this.getCredentials();
|
|
141
|
+
const credentials = await this.getCredentials();
|
|
160
142
|
// Shallow compare to determine if credentials stored here are outdated
|
|
161
143
|
const credentialsUpdated =
|
|
162
|
-
!credentials ||
|
|
163
|
-
Object.keys(
|
|
164
|
-
key =>
|
|
144
|
+
!this.config.credentials ||
|
|
145
|
+
Object.keys(credentials).some(
|
|
146
|
+
key => credentials[key] !== this.config.credentials[key]
|
|
165
147
|
);
|
|
166
148
|
// If endpoint is already initialized, and nothing else is changing, just early return
|
|
167
149
|
if (
|
|
@@ -173,18 +155,17 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
173
155
|
return;
|
|
174
156
|
}
|
|
175
157
|
// Update credentials
|
|
176
|
-
this.config.credentials =
|
|
158
|
+
this.config.credentials = credentials;
|
|
159
|
+
// Assert required configuration properties to make `updateEndpoint` request are present
|
|
160
|
+
this.assertNotEmptyConfiguration();
|
|
161
|
+
const { appId, endpointId, endpointInfo = {}, region } = this.config;
|
|
177
162
|
try {
|
|
178
|
-
// Initialize a new pinpoint client if one isn't already configured or if credentials changed
|
|
179
|
-
if (!pinpointClient || credentialsUpdated) {
|
|
180
|
-
this.initPinpointClient();
|
|
181
|
-
}
|
|
182
163
|
const { address, attributes, demographic, location, metrics, optOut } =
|
|
183
164
|
userInfo ?? {};
|
|
184
165
|
const { appVersion, make, model, platform, version } = this.clientInfo;
|
|
185
166
|
// Create the UpdateEndpoint input, prioritizing passed in user info and falling back to
|
|
186
167
|
// defaults (if any) obtained from the config
|
|
187
|
-
const input:
|
|
168
|
+
const input: UpdateEndpointInput = {
|
|
188
169
|
ApplicationId: appId,
|
|
189
170
|
EndpointId: endpointId,
|
|
190
171
|
EndpointRequest: {
|
|
@@ -217,41 +198,19 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
217
198
|
},
|
|
218
199
|
OptOut: optOut ?? endpointInfo.optOut,
|
|
219
200
|
User: {
|
|
220
|
-
UserId:
|
|
221
|
-
userId ?? endpointInfo.userId ?? currentCredentials.identityId,
|
|
201
|
+
UserId: userId ?? endpointInfo.userId ?? credentials.identityId,
|
|
222
202
|
UserAttributes: attributes ?? endpointInfo.userAttributes,
|
|
223
203
|
},
|
|
224
204
|
},
|
|
225
205
|
};
|
|
226
|
-
const command: UpdateEndpointCommand = new UpdateEndpointCommand(input);
|
|
227
206
|
this.logger.debug('updating endpoint');
|
|
228
|
-
await
|
|
207
|
+
await updateEndpoint({ credentials, region }, input);
|
|
229
208
|
this.endpointInitialized = true;
|
|
230
209
|
} catch (err) {
|
|
231
210
|
throw err;
|
|
232
211
|
}
|
|
233
212
|
};
|
|
234
213
|
|
|
235
|
-
private initPinpointClient = (): void => {
|
|
236
|
-
const { appId, credentials, pinpointClient, region } = this.config;
|
|
237
|
-
|
|
238
|
-
if (!appId || !credentials || !region) {
|
|
239
|
-
throw new Error(
|
|
240
|
-
'One or more of credentials, appId or region is not configured'
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
if (pinpointClient) {
|
|
245
|
-
pinpointClient.destroy();
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
this.config.pinpointClient = new PinpointClient({
|
|
249
|
-
region,
|
|
250
|
-
credentials,
|
|
251
|
-
customUserAgent: getAmplifyUserAgent(`/${this.getSubCategory()}`),
|
|
252
|
-
});
|
|
253
|
-
};
|
|
254
|
-
|
|
255
214
|
private getEndpointId = async (): Promise<string> => {
|
|
256
215
|
const { appId } = this.config;
|
|
257
216
|
// Each Pinpoint channel requires its own Endpoint ID
|
|
@@ -292,4 +251,13 @@ export default abstract class AWSPinpointProviderCommon
|
|
|
292
251
|
return null;
|
|
293
252
|
}
|
|
294
253
|
};
|
|
254
|
+
|
|
255
|
+
private assertNotEmptyConfiguration = () => {
|
|
256
|
+
const { appId, credentials, region } = this.config;
|
|
257
|
+
if (!appId || !credentials || !region) {
|
|
258
|
+
throw new Error(
|
|
259
|
+
'One or more of credentials, appId or region is not configured'
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
295
263
|
}
|
|
@@ -12,3 +12,18 @@ export interface AWSPinpointUserInfo extends UserInfo {
|
|
|
12
12
|
address?: string;
|
|
13
13
|
optOut?: 'ALL' | 'NONE';
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
export type ChannelType =
|
|
17
|
+
| 'ADM'
|
|
18
|
+
| 'APNS'
|
|
19
|
+
| 'APNS_SANDBOX'
|
|
20
|
+
| 'APNS_VOIP'
|
|
21
|
+
| 'APNS_VOIP_SANDBOX'
|
|
22
|
+
| 'BAIDU'
|
|
23
|
+
| 'CUSTOM'
|
|
24
|
+
| 'EMAIL'
|
|
25
|
+
| 'GCM'
|
|
26
|
+
| 'IN_APP'
|
|
27
|
+
| 'PUSH'
|
|
28
|
+
| 'SMS'
|
|
29
|
+
| 'VOICE';
|