notifly-sdk 1.0.4 → 1.0.5
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/.prettierrc.yml +14 -0
- package/index.js +44 -11
- package/package.json +1 -1
package/.prettierrc.yml
ADDED
package/index.js
CHANGED
|
@@ -10,9 +10,20 @@ exports.trackEvent = logEvent;
|
|
|
10
10
|
|
|
11
11
|
exports.setUserProperties = _setUserProperties
|
|
12
12
|
|
|
13
|
-
exports.setUserId = async
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
exports.setUserId = async function (userID) {
|
|
14
|
+
try {
|
|
15
|
+
if (userID) {
|
|
16
|
+
await _setUserProperties({
|
|
17
|
+
external_user_id: userID,
|
|
18
|
+
})
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
await _removeUserId();
|
|
22
|
+
return;
|
|
23
|
+
} catch (err) {
|
|
24
|
+
console.warn('[Notifly] setUserId Failed.');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
16
27
|
|
|
17
28
|
exports.sessionStart = async function () {
|
|
18
29
|
const apiLevel = rnDeviceInfo.getApiLevel(); // only android
|
|
@@ -165,18 +176,40 @@ async function _getNotiflyUserId() {
|
|
|
165
176
|
}
|
|
166
177
|
|
|
167
178
|
async function _setUserProperties(params) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
try {
|
|
180
|
+
if (params.external_user_id) {
|
|
181
|
+
const [previousNotiflyUserID, previousExternalUserID] = await Promise.all([
|
|
182
|
+
_getNotiflyUserId(),
|
|
183
|
+
AsyncStorage.getItem('notiflyExternalUserId')
|
|
184
|
+
]);
|
|
185
|
+
params['previous_notifly_user_id'] = previousNotiflyUserID
|
|
186
|
+
params['previous_external_user_id'] = previousExternalUserID
|
|
187
|
+
await Promise.all([
|
|
188
|
+
AsyncStorage.setItem('notiflyExternalUserId', params.external_user_id),
|
|
189
|
+
AsyncStorage.removeItem('notiflyUserId'),
|
|
190
|
+
]);
|
|
191
|
+
}
|
|
192
|
+
return (await logEvent("set_user_properties", params, null, true));
|
|
193
|
+
} catch (err) {
|
|
194
|
+
console.warn('[Notifly] Failed to remove userID');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function _removeUserId() {
|
|
199
|
+
try {
|
|
200
|
+
await Promise.all([AsyncStorage.removeItem('notiflyExternalUserId'), AsyncStorage.removeItem('notiflyUserId')]);
|
|
201
|
+
return await logEvent('remove_external_user_id', {}, null, true);
|
|
202
|
+
} catch (err) {
|
|
203
|
+
console.warn('[Notifly] Failed to remove userID');
|
|
174
204
|
}
|
|
175
|
-
return (await logEvent("set_user_properties", params, null, true));
|
|
176
205
|
}
|
|
177
206
|
|
|
178
207
|
async function logEvent(eventName, eventParams, segmentation_event_param_keys = null, isInternalEvent = false) {
|
|
179
208
|
try {
|
|
209
|
+
if (!eventName) {
|
|
210
|
+
console.warn('[Notifly]event_name must be provided.');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
180
213
|
let token;
|
|
181
214
|
const [savedCognitoToken, notiflyUserId, externalUserId, prjId, externalDeviceId, osVersion, appVersion] = await Promise.all([
|
|
182
215
|
AsyncStorage.getItem('notiflyCognitoIdToken'),
|
|
@@ -271,4 +304,4 @@ async function _apiCall(apiUrl, requestOptions) {
|
|
|
271
304
|
const result = fetch(apiUrl, requestOptions)
|
|
272
305
|
.then(response => response.text());
|
|
273
306
|
return result;
|
|
274
|
-
}
|
|
307
|
+
}
|