web-manager 3.1.30 → 3.1.33

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/index.js +28 -31
  2. package/lib/account.js +11 -0
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -31,6 +31,7 @@ var debug;
31
31
  // Shortcuts
32
32
  var select;
33
33
  var loadScript;
34
+ var store;
34
35
 
35
36
 
36
37
  /**
@@ -156,6 +157,7 @@ function Manager() {
156
157
 
157
158
  select = this.dom().select;
158
159
  loadScript = this.dom().loadScript;
160
+ store = this.storage();
159
161
  }
160
162
 
161
163
  /**
@@ -227,6 +229,7 @@ function Manager() {
227
229
  if (user) {
228
230
  if (!user.isAnonymous) {
229
231
  _authHandle_in(This, user);
232
+
230
233
  This.notifications().subscribe().catch(function (e) {
231
234
  console.error(e);
232
235
  });
@@ -240,10 +243,23 @@ function Manager() {
240
243
 
241
244
  function _authHandle_in(This, user) {
242
245
  // This.log('_authHandle_in', user);
243
- if (This.properties.page.status.didSignUp) {
246
+ // if (This.properties.page.status.didSignUp) {
247
+ var didSignUp = 'auth.didSignUp';
248
+ var done;
249
+ var hoursSinceCreation = Math.abs(new Date() - new Date(+user.metadata.a)) / 36e5;
250
+
251
+ function _done() {
252
+ if (!done) {
253
+ done = true;
254
+ store.set(didSignUp, true)
255
+ _authHandle_in_normal(This, user);
256
+ }
257
+ }
258
+
259
+ if (!store.get(didSignUp) && hoursSinceCreation < 0.5) {
244
260
  user.getIdToken(false)
245
261
  .then(function(token) {
246
- var done;
262
+
247
263
  fetch('https://us-central1-' + This.properties.options.libraries.firebase_app.config.projectId + '.cloudfunctions.net/bm_api', {
248
264
  method: 'POST',
249
265
  body: JSON.stringify({
@@ -251,43 +267,24 @@ function Manager() {
251
267
  command: 'user:sign-up',
252
268
  payload: {
253
269
  newsletterSignUp: select('.auth-newsletter-input').getValue(),
254
- affiliateCode: This.storage().get('auth.affiliateCode', ''),
255
- }
270
+ affiliateCode: store.get('auth.affiliateCode', ''),
271
+ },
256
272
  }),
257
273
  })
258
274
  .catch(function () {})
259
- .finally(function (response, status) {
260
- if (!done) {
261
- done = true;
262
- _authHandle_in_normal(This, user);
263
- }
264
- });
275
+ .finally(_done);
265
276
 
266
277
  setTimeout(function () {
267
- if (!done) {
268
- done = true;
269
- _authHandle_in_normal(This, user);
270
- }
278
+ _done()
271
279
  }, 5000);
272
280
 
273
281
  })
274
282
  .catch(function(error) {
275
283
  console.error(error);
276
- _authHandle_in_normal(This, user);
284
+ _done();
277
285
  });
278
-
279
- // } else if (This.properties.page.status.didSignIn) {
280
- // This.notifications().isSubscribed(function (status) {
281
- // if (status) {
282
- // This.notifications().subscribe()
283
- // .then(function () {
284
- //
285
- // })
286
- // }
287
- // })
288
- // _authHandle_in_normal(This, user);
289
286
  } else {
290
- _authHandle_in_normal(This, user);
287
+ _done();
291
288
  }
292
289
  }
293
290
 
@@ -640,7 +637,7 @@ function Manager() {
640
637
  var pagePathname = window.location.pathname;
641
638
  var qsAff = pageQueryString.get('aff');
642
639
  if (qsAff) {
643
- This.storage().set('auth.affiliateCode', qsAff);
640
+ store.set('auth.affiliateCode', qsAff);
644
641
  }
645
642
  var qsRedirect = pageQueryString.get('redirect');
646
643
  if (qsRedirect && This.isValidRedirectUrl(qsRedirect)) {
@@ -993,7 +990,7 @@ function Manager() {
993
990
  setAuthButtonDisabled(mode, true);
994
991
  firebase.auth().createUserWithEmailAndPassword(email, password)
995
992
  .then(function(credential) {
996
- This.properties.page.status.didSignUp = true;
993
+ // This.properties.page.status.didSignUp = true;
997
994
  // This.log('Good signup');
998
995
  // signupButtonDisabled(false);
999
996
  })
@@ -1080,7 +1077,7 @@ function Manager() {
1080
1077
  })
1081
1078
  .then(function (token) {
1082
1079
  var user = This.auth().getUser();
1083
- var localSubscription = This.storage().get('notifications', {});
1080
+ var localSubscription = store.get('notifications', {});
1084
1081
  var localHash = localSubscription.token + '|' + localSubscription.uid;
1085
1082
  var userHash = token + '|' + user.uid;
1086
1083
  // console.log('user', user);
@@ -1100,7 +1097,7 @@ function Manager() {
1100
1097
  function saveLocal() {
1101
1098
  // console.log('---------saveLocal');
1102
1099
  // This.log('Saved local token: ', token);
1103
- This.storage().set('notifications', {uid: user.uid, token: token, lastSynced: timestamp});
1100
+ store.set('notifications', {uid: user.uid, token: token, lastSynced: timestamp});
1104
1101
  }
1105
1102
 
1106
1103
  function saveServer(doc) {
package/lib/account.js CHANGED
@@ -328,6 +328,17 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
328
328
  account.activity.created.timestamp = account.activity.created.timestamp || '1970-01-01T00:00:00.000Z';
329
329
  account.activity.created.timestampUNIX = account.activity.created.timestampUNIX || 0;
330
330
 
331
+ account.activity.geolocation = account.activity.geolocation || {};
332
+ account.activity.geolocation.ip = account.activity.geolocation.ip || 'unknown';
333
+ account.activity.geolocation.continent = account.activity.geolocation.continent || 'unknown';
334
+ account.activity.geolocation.country = account.activity.geolocation.country || 'unknown';
335
+ account.activity.geolocation.city = account.activity.geolocation.city || 'unknown';
336
+ account.activity.geolocation.latitude = account.activity.geolocation.latitude || 'unknown';
337
+ account.activity.geolocation.longitude = account.activity.geolocation.longitude || 'unknown';
338
+ account.activity.geolocation.userAgent = account.activity.geolocation.userAgent || 'unknown';
339
+ account.activity.geolocation.language = account.activity.geolocation.language || 'unknown';
340
+ account.activity.geolocation.platform = account.activity.geolocation.platform || 'unknown';
341
+
331
342
  // Api
332
343
  account.api = account.api || {};
333
344
  account.api.clientId = account.api.clientId || 'unknown';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.1.30",
3
+ "version": "3.1.33",
4
4
  "description": "Easily access important variables such as the query string, current domain, and current page in a single object.",
5
5
  "main": "index.js",
6
6
  "scripts": {