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.
Files changed (3) hide show
  1. package/.prettierrc.yml +14 -0
  2. package/index.js +44 -11
  3. package/package.json +1 -1
@@ -0,0 +1,14 @@
1
+ # .prettierrc or .prettierrc.yaml
2
+ proseWrap: 'preserve'
3
+ trailingComma: 'es5'
4
+ tabWidth: 4
5
+ semi: true
6
+ singleQuote: true
7
+ quoteProps: 'preserve'
8
+ printWidth: 120
9
+ overrides:
10
+ - files:
11
+ - '*.json'
12
+ - '*.yml'
13
+ options:
14
+ tabWidth: 2
package/index.js CHANGED
@@ -10,9 +10,20 @@ exports.trackEvent = logEvent;
10
10
 
11
11
  exports.setUserProperties = _setUserProperties
12
12
 
13
- exports.setUserId = async userId => await _setUserProperties({
14
- external_user_id: userId,
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
- if (params.external_user_id) {
169
- params['previous_notifly_user_id'] = await _getNotiflyUserId();
170
- await Promise.all([
171
- AsyncStorage.setItem('notiflyExternalUserId', params.external_user_id),
172
- AsyncStorage.removeItem('notiflyUserId'),
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notifly-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {