web-manager 3.0.10 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/README.md +14 -0
  2. package/lib/account.js +102 -8
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -283,6 +283,20 @@ For these, you must first call `.account().resolve()`
283
283
  * `.auth-billing-start-date-element`: Add to any element and it will display the user's plan start date
284
284
  * `.auth-billing-expiration-date-element`: Add to any element and it will display the user's plan expiration date
285
285
 
286
+ * `.auth-created-element`: Add to any element to show the local string for account creation date
287
+ * `.auth-phone-element`: Add to any element to display the user's phone
288
+
289
+ * `.auth-referral-count-element`: Update this element with the user's referral count
290
+ * `.auth-referral-code-element`: Update this element with the user's referral code
291
+ * `.auth-referral-link-element`: Update this element with the user's referral link
292
+ * `.auth-referral-social-link`: Update this element with the user's referral link for socials where `data-provider` is the social network
293
+
294
+ * Future additions (not added yet)
295
+ * `auth-link-provider-btn`: Initiate a link to the `data-provider` in this element
296
+ * `auth-unlink-provider-btn`: Initiate an unlink to the `data-provider` in this element
297
+ * `auth-signout-all-sessions-btn`: Call the server to sign out of all sessions and then log out of the current one.
298
+
299
+
286
300
  ```html
287
301
  <div class="auth-signedin-false-element">
288
302
  <form onsubmit="return false;">
package/lib/account.js CHANGED
@@ -202,6 +202,9 @@ Account.prototype._resolveAccount = function (currentUser, account, options) {
202
202
 
203
203
  var defaultPlanId = options.defaultPlanId || 'basic';
204
204
 
205
+ var currentURL;
206
+ var isDevelopment;
207
+
205
208
  // Resolve auth
206
209
  account.auth = account.auth || {};
207
210
  account.auth.email = account.auth.email || currentUser.email || null;
@@ -219,7 +222,7 @@ Account.prototype._resolveAccount = function (currentUser, account, options) {
219
222
 
220
223
  account.plan.payment = account.plan.payment || {};
221
224
  account.plan.payment.startDate = account.plan.payment.startDate || {};
222
- account.plan.payment.startDate.timestamp = account.plan.payment.startDate.timestamp || '1999-01-01T00:00:00Z';
225
+ account.plan.payment.startDate.timestamp = account.plan.payment.startDate.timestamp || '1970-01-01T00:00:00.000Z';
223
226
  account.plan.payment.startDate.timestampUNIX = account.plan.payment.startDate.timestampUNIX || 0;
224
227
  account.plan.payment.frequency = account.plan.payment.frequency || 'unknown';
225
228
  account.plan.payment.orderId = account.plan.payment.orderId || 'unknown';
@@ -231,14 +234,35 @@ Account.prototype._resolveAccount = function (currentUser, account, options) {
231
234
  account.plan.payment.updatedBy.event.id = account.plan.payment.updatedBy.event.id || 'unknown';
232
235
  account.plan.payment.updatedBy.event.name = account.plan.payment.updatedBy.event.name || 'unknown';
233
236
  account.plan.payment.updatedBy.date = account.plan.payment.updatedBy.date || {};
234
- account.plan.payment.updatedBy.date.timestamp = account.plan.payment.updatedBy.date.timestamp || '1999-01-01T00:00:00Z';
237
+ account.plan.payment.updatedBy.date.timestamp = account.plan.payment.updatedBy.date.timestamp || '1970-01-01T00:00:00.000Z';
235
238
  account.plan.payment.updatedBy.date.timestampUNIX = account.plan.payment.updatedBy.date.timestampUNIX || 0;
236
239
 
240
+ // Set some variables
241
+ // In a try/catch because this lib is used in node sometimes
242
+ try {
243
+ currentURL = new URL(window.location.href);
244
+ isDevelopment = utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
245
+
246
+ if (utilities.get(isDevelopment)) {
247
+ currentURL.searchParams
248
+ .forEach(function(value, key) {
249
+ var accountValue = utilities.get(account, key, undefined)
250
+ if (typeof accountValue !== undefined) {
251
+ if (value === 'true') { value = true }
252
+ if (value === 'false') { value = false }
253
+
254
+ utilities.set(account, key, value)
255
+ }
256
+ });
257
+ }
258
+ } catch (e) {
259
+ console.error('Unable to check query strings', e);
260
+ }
237
261
 
238
262
  var planExpireDate = new Date(account.plan.expires.timestamp);
239
263
  var now = new Date();
240
264
  var daysTillExpire = Math.floor((planExpireDate - now) / 86400000);
241
- let difference = (planExpireDate.getTime() - now.getTime())/(24*3600*1000);
265
+ var difference = (planExpireDate.getTime() - now.getTime())/(24*3600*1000);
242
266
  var startDate = new Date(account.plan.payment.startDate.timestamp);
243
267
  var planIsActive = difference > -1 && account.plan.id !== defaultPlanId;
244
268
 
@@ -270,11 +294,11 @@ Account.prototype._resolveAccount = function (currentUser, account, options) {
270
294
  // Resolve activity
271
295
  account.activity = account.activity || {};
272
296
  account.activity.lastActivity = account.activity.lastActivity || {};
273
- account.activity.lastActivity.timestamp = account.activity.lastActivity.timestamp || '1999-01-01T00:00:00Z';
297
+ account.activity.lastActivity.timestamp = account.activity.lastActivity.timestamp || '1970-01-01T00:00:00.000Z';
274
298
  account.activity.lastActivity.timestampUNIX = account.activity.lastActivity.timestampUNIX || 0;
275
299
 
276
300
  account.activity.created = account.activity.created || {};
277
- account.activity.created.timestamp = account.activity.created.timestamp || '1999-01-01T00:00:00Z';
301
+ account.activity.created.timestamp = account.activity.created.timestamp || '1970-01-01T00:00:00.000Z';
278
302
  account.activity.created.timestampUNIX = account.activity.created.timestampUNIX || 0;
279
303
 
280
304
  // Api
@@ -282,9 +306,30 @@ Account.prototype._resolveAccount = function (currentUser, account, options) {
282
306
  account.api.clientId = account.api.clientId || 'unknown';
283
307
  account.api.privateKey = account.api.privateKey || 'unknown';
284
308
 
309
+ // Personal
310
+ account.personal = account.personal || {};
311
+
312
+ account.personal.name = account.personal.name || {};
313
+ account.personal.name.first = account.personal.name.first || '';
314
+ account.personal.name.last = account.personal.name.last || '';
315
+
316
+ account.personal.telephone = account.personal.telephone || {};
317
+ account.personal.telephone.countryCode = account.personal.telephone.countryCode || 0;
318
+ account.personal.telephone.national = account.personal.telephone.national || 0;
319
+
320
+ account.personal.birthday = account.personal.birthday || {};
321
+ account.personal.birthday.timestamp = account.personal.birthday.timestamp || '1970-01-01T00:00:00.000Z';
322
+ account.personal.birthday.timestampUNIX = account.personal.birthday.timestampUNIX || 0;
323
+
324
+ account.personal.gender = account.personal.gender || '';
325
+
326
+ account.personal.location = account.personal.location || {};
327
+ account.personal.location.country = account.personal.location.country || '';
328
+
329
+
285
330
  // Set UI elements
331
+ // In a try/catch because this lib is used in node sometimes
286
332
  try {
287
- var isDevelopment = utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
288
333
  // var apiLinkURL = isDevelopment ? 'http://localhost:5000/discord-link' : 'https://api.{{ site.brand.name }}.com/discord-link';
289
334
  // var apiUnlinkURL = isDevelopment ? 'http://localhost:5000/discord-unlink' : 'https://api.{{ site.brand.name }}.com/discord-unlink';
290
335
  var cancelURL = isDevelopment ? 'http://localhost:4001/cancel/' : 'https://itwcreativeworks.com/portal/account/manage/';
@@ -295,8 +340,23 @@ Account.prototype._resolveAccount = function (currentUser, account, options) {
295
340
  var billingFrequencyEl = dom.select('.auth-billing-frequency-element');
296
341
  var billingStartDateEl = dom.select('.auth-billing-start-date-element');
297
342
  var billingExpirationDateEl = dom.select('.auth-billing-expiration-date-element');
343
+
344
+ var $referralCount = dom.select('.auth-referral-count-element');
345
+ var $referralCode = dom.select('.auth-referral-code-element');
346
+ var $referralLink = dom.select('.auth-referral-link-element');
347
+ var $referralSocialLink = dom.select('a.auth-referral-social-link[data-provider]');
348
+
349
+ var authCreatedEl = dom.select('.auth-created-element');
350
+ var authPhoneInput = dom.select('.auth-phone-input');
351
+
298
352
  var updateURL = new URL(cancelURL);
299
- var currentURL = new URL(window.location.href);
353
+ var referralURL = new URL(window.location.origin || window.location.host);
354
+
355
+ referralURL.pathname = '/';
356
+ referralURL.searchParams.set('aff', account.affiliate.code)
357
+
358
+ authCreatedEl.setInnerHTML(new Date(parseInt(currentUser.metadata.a)).toLocaleString(undefined, { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }))
359
+ authPhoneInput.setInnerHTML(currentUser.phoneNumber).setValue(currentUser.phoneNumber)
300
360
 
301
361
  billingSubscribeBtn.setAttribute('hidden', true);
302
362
  billingUpdateBtn.setAttribute('hidden', true);
@@ -321,10 +381,44 @@ Account.prototype._resolveAccount = function (currentUser, account, options) {
321
381
  ? '<i class="fas fa-exclamation-triangle mr-1"></i> Expires in ' + daysTillExpire + ' days '
322
382
  : '');
323
383
 
324
- _setAuthItem('.auth-apikey-element', utilities.get(account, 'api.privateKey', 'n/a'))
384
+ _setAuthItem('.auth-apikey-element', utilities.get(account, 'api.privateKey', 'n/a'));
385
+
386
+
387
+ $referralCount.setInnerHTML(account.affiliate.referrals.length);
388
+ $referralCode.setInnerHTML(account.affiliate.code).setValue(account.affiliate.code);
389
+ $referralCode.setInnerHTML(referralURL.toString()).setValue(referralURL.toString());
390
+
391
+ var affiliateLinkURI = encodeURIComponent(referralURL.toString());
392
+ var affiliateLinkTextURI = encodeURIComponent('Sign up for ' + utilities.get(self.Manager, 'properties.global.brand.name', 'this') + ', a useful service:');
393
+
394
+ $referralSocialLink
395
+ .each(function ($el) {
396
+ var provider = $el.dataset.provider;
397
+ var text = encodeURIComponent($el.dataset.shareText || '');
398
+
399
+ $el.setAttribute('target', '_blank')
400
+
401
+ if (provider === 'facebook') {
402
+ $el.setAttribute('href', 'https://www.facebook.com/sharer.php?u=' + (affiliateLinkURI) + '')
403
+ } else if (provider === 'twitter') {
404
+ $el.setAttribute('href', 'https://twitter.com/share?url=' + (affiliateLinkURI) + '&text=' + (text || affiliateLinkTextURI) + '')
405
+ } else if (provider === 'pinterest') {
406
+ $el.setAttribute('href', 'https://pinterest.com/pin/create/button/?url=' + (affiliateLinkURI) + '&description=' + (text || affiliateLinkTextURI) + '')
407
+ } else if (provider === 'tumblr') {
408
+ $el.setAttribute('href', 'https://www.tumblr.com/share/link?url=' + (affiliateLinkURI) + '&text=' + (text || affiliateLinkTextURI) + '')
409
+ } else if (provider === 'linkedin') {
410
+ $el.setAttribute('href', 'https://www.linkedin.com/sharing/share-offsite/?url=' + (affiliateLinkURI) + '&title=' + (text || affiliateLinkTextURI) + '')
411
+ // $el.setAttribute('href', `http://www.linkedin.com/shareArticle?mini=true&url=https://stackoverflow.com/questions/10713542/how-to-make-custom-linkedin-share-button/10737122&title=How%20to%20make%20custom%20linkedin%20share%20button&summary=some%20summary%20if%20you%20want&source=stackoverflow.com`)
412
+ // $el.setAttribute('href', `http://www.linkedin.com/shareArticle?mini=false&url=' + affiliateLinkURI + '&title=' + text || affiliateLinkTextURI + '`)
413
+ } else if (provider === 'reddit') {
414
+ $el.setAttribute('href', 'http://www.reddit.com/submit?url=' + (affiliateLinkURI) + '&title=' + (text || affiliateLinkTextURI) + '')
415
+ }
416
+ })
417
+
325
418
  } catch (e) {
326
419
  // console.error('Unable to set DOM elements', e);
327
420
  }
421
+
328
422
  self.properties = account;
329
423
 
330
424
  return self.properties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "3.0.10",
3
+ "version": "3.1.1",
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": {
@@ -28,4 +28,4 @@
28
28
  "firebase": "^8.10.1",
29
29
  "lazysizes": "^5.3.2"
30
30
  }
31
- }
31
+ }