web-manager 4.3.2 → 4.3.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.
@@ -1,666 +0,0 @@
1
- /*
2
- */
3
- function Account(init) {
4
- var self = this;
5
-
6
- init = init || {};
7
- self.properties = {};
8
- self.accountPageInitialized = false;
9
-
10
- // Initialize libraries
11
- try {
12
- self.dom = init.dom || self.Manager.dom();
13
- self.utilities = init.utilities || self.Manager.utilities();
14
- } catch (e) {
15
- console.error('Failed to initialize libraries');
16
- }
17
-
18
- // Initialize account page
19
- try {
20
- // If we're NOT in the browser, skip
21
- if (typeof window !== 'undefined') {
22
- var url = new URL(window.location.href);
23
-
24
- if (url.pathname.startsWith('/account')) {
25
- self.initializeAccountPage();
26
- }
27
- }
28
- } catch (e) {
29
- console.error('Failed to initialize account page');
30
- }
31
- }
32
-
33
- Account.prototype.initializeAccountPage = function (options) {
34
- var self = this;
35
-
36
- if (self.accountPageInitialized) { return }
37
-
38
- document.addEventListener('click', function (event) {
39
- if (event.target.matches('.auth-delete-account-btn')) {
40
- self.delete().catch(function (e) {});
41
- }
42
- })
43
-
44
- self.accountPageInitialized = true;
45
-
46
- }
47
-
48
- Account.prototype.delete = function (options) {
49
- var self = this;
50
-
51
- var user = firebase.auth().currentUser;
52
- var errorElement = self.dom.select('.auth-delete-account-error-message-element');
53
- var confirmValue = self.dom.select('.auth-delete-account-confirmation-input').getValue()
54
- var deleteButton = self.dom.select('.auth-delete-account-btn')
55
-
56
- deleteButton.setAttribute('disabled', true).addClass('disabled');
57
- errorElement.setAttribute('hidden', true);
58
-
59
- return new Promise(function(resolve, reject) {
60
- function _error(e) {
61
- var er = new Error(e);
62
- errorElement.removeAttribute('hidden').setInnerHTML(er);
63
- deleteButton.removeAttribute('disabled').removeClass('disabled');
64
- return reject(er);
65
- }
66
- if (!confirmValue) {
67
- return _error('Please confirm that you wish to have your account deleted.')
68
- } else if (!user) {
69
- return _error('Please log in first.')
70
- } else {
71
- user.getIdToken(false)
72
- .then(function(token) {
73
- fetch(self.Manager.properties.global.functionsUrl + '/bm_api', {
74
- // fetch('http://localhost:5001/optiic-api/us-central1/bm_api', {
75
- method: 'POST',
76
- headers: { 'Content-Type': 'application/json' },
77
- body: JSON.stringify({
78
- authenticationToken: token,
79
- command: 'delete-user',
80
- payload: {},
81
- }),
82
- })
83
- .then(function (res) {
84
- if (res.ok) {
85
- res.json()
86
- .then(function (data) {
87
- console.log('Successfully deleted account', data);
88
- self.Manager.auth().signOut();
89
- return resolve(data);
90
- })
91
- } else {
92
- return res.text()
93
- .then(function (data) {
94
- throw new Error(data || res.statusText || 'Unknown error.')
95
- })
96
- }
97
- })
98
- .catch(function (e) {
99
- return _error(e);
100
- })
101
- })
102
- .catch(function () {
103
- return _error(e);
104
- })
105
- }
106
- });
107
- }
108
-
109
- Account.prototype.resolve = function (account, options) {
110
- var self = this;
111
- return new Promise(function(resolve, reject) {
112
- var currentUser = firebase.auth().currentUser;
113
-
114
- account = account || {};
115
- options = options || {};
116
- options.fetchNewAccount = typeof options.fetchNewAccount === 'undefined' ? true : options.fetchNewAccount;
117
-
118
- // If there is no user logged in or we choose not to fetch the account, resolve a default account
119
- if (!currentUser || !currentUser.uid || !options.fetchNewAccount) {
120
- return resolve(
121
- self.handleAccount(
122
- self._resolveAccount(currentUser, account, options)
123
- )
124
- );
125
- }
126
-
127
- // Otherwise, fetch the account from the database and resolve it
128
- firebase.firestore().doc('users/' + currentUser.uid)
129
- .get()
130
- .then(function (doc) {
131
- return resolve(
132
- self.handleAccount(
133
- self._resolveAccount(currentUser, doc.data(), options)
134
- )
135
- );
136
- })
137
- });
138
- }
139
-
140
- Account.prototype.handleAccount = function (account) {
141
- var self = this;
142
- var planId = account.plan.id;
143
-
144
- // Handle plans
145
- handlePlanVisibility(planId);
146
-
147
- // Enable exit popup if it's already enabled and the plan is basic
148
- if (self.Manager.properties.options.exitPopup.enabled === true) {
149
- self.Manager.properties.options.exitPopup.enabled = planId === 'basic';
150
- }
151
-
152
- // Handle others
153
- // ...
154
-
155
- return account;
156
- }
157
-
158
- function handlePlanVisibility(planId) {
159
- var elements = document.querySelectorAll('[data-plan-id][data-plan-visibility]');
160
-
161
- // Initially hide all elements
162
- elements.forEach(function($el) {
163
- $el.setAttribute('hidden', true);
164
- });
165
-
166
- // Toggle visibility based on plan
167
- elements.forEach(function($el) {
168
- var requiredPlans = $el.getAttribute('data-plan-id').split(',');
169
- var visibility = $el.getAttribute('data-plan-visibility') || 'visible';
170
-
171
- var shouldBeVisible = false;
172
-
173
- // Special case for '$paid'
174
- if (requiredPlans.includes('$paid')) {
175
- shouldBeVisible = planId !== 'basic';
176
- } else {
177
- shouldBeVisible = requiredPlans.includes(planId);
178
- }
179
-
180
- var shouldHide = shouldBeVisible
181
- ? visibility === 'hidden'
182
- : visibility === 'visible';
183
-
184
- if (shouldHide) {
185
- $el.setAttribute('hidden', true);
186
- } else {
187
- $el.removeAttribute('hidden');
188
- }
189
- });
190
- }
191
-
192
- function splitDashesAndUppercase(str) {
193
- return str.split('-').map(function (word) {
194
- return uppercase(word);
195
- }).join(' ');
196
- }
197
-
198
- function uppercase(str) {
199
- return str.charAt(0).toUpperCase() + str.slice(1);
200
- }
201
-
202
- function getMonth(date) {
203
- var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
204
-
205
- return monthNames[date.getMonth()];
206
- }
207
-
208
- Account.prototype._resolveAccount2 = function (firebaseUser, account, options) {
209
- // TODO: USE resolve-account library Instead
210
-
211
- /*
212
- const resolver = new (require('resolve-account'))({
213
- Manager: self.Manager,
214
- utilities: utilities,
215
- dom: dom,
216
- });
217
-
218
-
219
- self.properties = resolver.resolve(firebaseUser, account, options)
220
-
221
- return self.properties;
222
-
223
- */
224
-
225
- }
226
-
227
- /*
228
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
229
- THIS HAS BEEN MOVED TO the resolve-account lib
230
- still here until figure out how to import resolve-account here
231
- any changes to resolve-account must go here too
232
- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
233
- */
234
- Account.prototype._resolveAccount = function (firebaseUser, account, options) {
235
- var self = this;
236
-
237
- firebaseUser = firebaseUser || {};
238
- account = account || {};
239
- options = options || {};
240
-
241
- var defaultPlanId = options.defaultPlanId || 'basic';
242
-
243
- var currentURL;
244
- var isDevelopment;
245
- var timestampOld = '1970-01-01T00:00:00.000Z';
246
- var timestampUNIXOld = 0;
247
-
248
- // TODO: ADD THESE THINGS: USAGE RESOVLER ETC
249
- console.log('++++++account 1', JSON.stringify(account, null, 2));
250
- console.log('++++++options 1', JSON.stringify(options, null, 2));
251
-
252
- // @@@DEVELOPER
253
- // account.plan = {};
254
-
255
- // Resolve auth
256
- account.auth = account.auth || {};
257
- account.auth.uid = account.auth.uid || firebaseUser.uid || null;
258
- account.auth.email = account.auth.email || firebaseUser.email || null;
259
- account.auth.temporary = account.auth.temporary || false;
260
-
261
- // Resolve plan
262
- account.plan = account.plan || {};
263
- account.plan.id = account.plan.id || defaultPlanId;
264
-
265
- account.plan.status = account.plan.status || 'cancelled';
266
-
267
- account.plan.expires = account.plan.expires || {};
268
- account.plan.expires.timestamp = new Date(account.plan.expires.timestamp || 0).toISOString();
269
- account.plan.expires.timestampUNIX = Math.round(new Date(account.plan.expires.timestamp || 0).getTime() / 1000);
270
-
271
- account.plan.trial = account.plan.trial || {};
272
- account.plan.trial.activated = account.plan.trial.activated || false;
273
- account.plan.trial.expires = account.plan.trial.expires || {};
274
- account.plan.trial.expires.timestamp = new Date(account.plan.trial.expires.timestamp || 0).toISOString()
275
- account.plan.trial.expires.timestampUNIX = Math.round(new Date(account.plan.trial.expires.timestamp || 0).getTime() / 1000);
276
-
277
- // @@@DEVELOPER
278
- // var date = '2024-04-23T00:07:29.183Z';
279
- // // var date = `2024-03-23T00:07:29.183Z`;
280
- // // account.plan.id = 'basic';
281
- // account.plan.id = 'premium';
282
- // account.plan.trial = {
283
- // activated: false,
284
- // expires: {
285
- // timestamp: new Date(date).toISOString(),
286
- // timestampUNIX: Math.round(new Date(date).getTime() / 1000),
287
- // },
288
- // }
289
- // account.plan.expires = {
290
- // timestamp: new Date(date).toISOString(),
291
- // timestampUNIX: Math.round(new Date(date).getTime() / 1000),
292
- // }
293
- // account.plan.status = 'cancelled';
294
- // account.plan = {
295
- // "id": "premium",
296
- // "payment": {
297
- // "frequency": "monthly",
298
- // "startDate": {
299
- // "timestampUNIX": 1711373195,
300
- // "timestamp": "2024-03-25T13:26:35.000Z"
301
- // },
302
- // "updatedBy": {
303
- // "date": {
304
- // "timestamp": "2024-04-02T13:46:47.441Z",
305
- // "timestampUNIX": 1712065607
306
- // },
307
- // "event": {
308
- // "name": "subscription-profile-fixer",
309
- // "id": "subscription-profile-fixer"
310
- // }
311
- // },
312
- // "resourceId": "AzyrfuU82V0cZ87qp",
313
- // "orderId": "0908-176942-1223",
314
- // "active": false,
315
- // "processor": "chargebee"
316
- // },
317
- // "trial": {
318
- // "expires": {
319
- // "timestamp": "1970-01-01T00:00:00.000Z",
320
- // "timestampUNIX": 0
321
- // },
322
- // "activated": true
323
- // },
324
- // "expires": {
325
- // "timestampUNIX": 1714656799,
326
- // "timestamp": "2024-05-02T13:33:19.000Z"
327
- // },
328
- // "limits": {},
329
- // "status": "cancelled"
330
- // },
331
-
332
- account.plan.limits = account.plan.limits || {};
333
- // account.plan.devices = account.plan.devices || 1;
334
-
335
- account.plan.payment = account.plan.payment || {};
336
- account.plan.payment.processor = account.plan.payment.processor || 'unknown';
337
- account.plan.payment.orderId = account.plan.payment.orderId || 'unknown';
338
- account.plan.payment.resourceId = account.plan.payment.resourceId || 'unknown';
339
- account.plan.payment.frequency = account.plan.payment.frequency || 'unknown';
340
- account.plan.payment.active = account.plan.payment.active || false;
341
-
342
- account.plan.payment.startDate = account.plan.payment.startDate || {};
343
- account.plan.payment.startDate.timestamp = account.plan.payment.startDate.timestamp || timestampOld;
344
- account.plan.payment.startDate.timestampUNIX = account.plan.payment.startDate.timestampUNIX || timestampUNIXOld;
345
-
346
- account.plan.payment.updatedBy = account.plan.payment.updatedBy || {};
347
- account.plan.payment.updatedBy.event = account.plan.payment.updatedBy.event || {};
348
- account.plan.payment.updatedBy.event.id = account.plan.payment.updatedBy.event.id || 'unknown';
349
- account.plan.payment.updatedBy.event.name = account.plan.payment.updatedBy.event.name || 'unknown';
350
- account.plan.payment.updatedBy.date = account.plan.payment.updatedBy.date || {};
351
- account.plan.payment.updatedBy.date.timestamp = account.plan.payment.updatedBy.date.timestamp || timestampOld;
352
- account.plan.payment.updatedBy.date.timestampUNIX = account.plan.payment.updatedBy.date.timestampUNIX || timestampUNIXOld;
353
-
354
- // Set some variables
355
- // In a try/catch because this lib is used in node sometimes
356
- try {
357
- currentURL = new URL(window.location.href);
358
- isDevelopment = self.utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
359
-
360
- if (isDevelopment) {
361
- currentURL.searchParams
362
- .forEach(function(value, key) {
363
- var accountValue = self.utilities.get(account, key, undefined)
364
- if (typeof accountValue !== 'undefined') {
365
- if (value === 'true') { value = true }
366
- if (value === 'false') { value = false }
367
-
368
- self.utilities.set(account, key, value)
369
- }
370
- });
371
- }
372
- } catch (e) {
373
- if (typeof window !== 'undefined') {
374
- console.error('Unable to check query strings', e);
375
- }
376
- }
377
-
378
- var now = new Date();
379
- var planExpireDate = new Date(account.plan.expires.timestamp);
380
- var daysTillExpire = Math.floor((planExpireDate - now) / 86400000);
381
- var difference = (planExpireDate.getTime() - now.getTime()) / (24 * 3600 * 1000);
382
- var trialExpireDate = new Date(account.plan.trial.expires.timestamp);
383
- var daysTillTrialExpire = Math.floor((trialExpireDate - now) / 86400000);
384
- var startDate = new Date(account.plan.payment.startDate.timestamp);
385
- var unresolvedPlanId = account.plan.id;
386
- var planIsActive = difference > -1 && account.plan.id !== defaultPlanId;
387
- var planIsSuspended = account.plan.status === 'suspended';
388
-
389
- if (planIsActive) {
390
- account.plan.id = account.plan.id;
391
- } else {
392
- account.plan.id = defaultPlanId;
393
- }
394
-
395
- var isBasicPlan = account.plan.id === defaultPlanId;
396
-
397
- // Resolve oAuth2
398
- account.oauth2 = account.oauth2 || {};
399
- // account.oauth2.google = account.oauth2.google || {};
400
- // account.oauth2.discord = account.oauth2.discord || {};
401
-
402
- // Resolve roles
403
- account.roles = account.roles || {};
404
- account.roles.betaTester = account.roles.betaTester === true || account.roles.betaTester === 'true';
405
- account.roles.developer = account.roles.developer === true || account.roles.developer === 'true';
406
- account.roles.admin = account.roles.admin === true || account.roles.admin === 'true';
407
- account.roles.vip = account.roles.vip === true || account.roles.vip === 'true';
408
- account.roles.og = account.roles.og === true || account.roles.og === 'true';
409
- account.roles.promoExempt = account.roles.promoExempt === true || account.roles.promoExempt === 'true';
410
-
411
- // Resolve affiliate
412
- account.affiliate = account.affiliate || {};
413
- account.affiliate.code = account.affiliate.code || 'unknown';
414
- account.affiliate.referrals = account.affiliate.referrals || [];
415
- account.affiliate.referrer = account.affiliate.referrer || 'unknown';
416
-
417
- // Resolve activity
418
- account.activity = account.activity || {};
419
- account.activity.lastActivity = account.activity.lastActivity || {};
420
- account.activity.lastActivity.timestamp = account.activity.lastActivity.timestamp || timestampOld;
421
- account.activity.lastActivity.timestampUNIX = account.activity.lastActivity.timestampUNIX || timestampUNIXOld;
422
-
423
- account.activity.created = account.activity.created || {};
424
- account.activity.created.timestamp = account.activity.created.timestamp || timestampOld;
425
- account.activity.created.timestampUNIX = account.activity.created.timestampUNIX || timestampUNIXOld;
426
-
427
- account.activity.geolocation = account.activity.geolocation || {};
428
- account.activity.geolocation.ip = account.activity.geolocation.ip || 'unknown';
429
- account.activity.geolocation.continent = account.activity.geolocation.continent || 'unknown';
430
- account.activity.geolocation.country = account.activity.geolocation.country || 'unknown';
431
- account.activity.geolocation.region = account.activity.geolocation.region || 'unknown';
432
- account.activity.geolocation.city = account.activity.geolocation.city || 'unknown';
433
- account.activity.geolocation.latitude = account.activity.geolocation.latitude || 0;
434
- account.activity.geolocation.longitude = account.activity.geolocation.longitude || 0;
435
-
436
- account.activity.client = account.activity.client || {};
437
- account.activity.client.userAgent = account.activity.client.userAgent || 'unknown';
438
- account.activity.client.language = account.activity.client.language || 'unknown';
439
- account.activity.client.platform = account.activity.client.platform || 'unknown';
440
- account.activity.client.mobile = account.activity.client.mobile || null;
441
-
442
- // Api
443
- account.api = account.api || {};
444
- account.api.clientId = account.api.clientId || 'unknown';
445
- account.api.privateKey = account.api.privateKey || 'unknown';
446
-
447
- // Usage
448
- account.usage = account.usage || {};
449
-
450
- account.usage.requests = account.usage.requests || {};
451
- account.usage.requests.total = account.usage.requests.total || 0;
452
- account.usage.requests.period = account.usage.requests.period || 0;
453
-
454
- account.usage.requests.last = account.usage.requests.last || {};
455
- account.usage.requests.last.id = account.usage.requests.last.id || '';
456
- account.usage.requests.last.timestamp = account.usage.requests.last.timestamp || timestampOld;
457
- account.usage.requests.last.timestampUNIX = account.usage.requests.last.timestampUNIX || timestampUNIXOld;
458
-
459
- // Personal
460
- account.personal = account.personal || {};
461
-
462
- account.personal.birthday = account.personal.birthday || {};
463
- account.personal.birthday.timestamp = account.personal.birthday.timestamp || timestampOld;
464
- account.personal.birthday.timestampUNIX = account.personal.birthday.timestampUNIX || timestampUNIXOld;
465
-
466
- account.personal.gender = account.personal.gender || '';
467
-
468
- account.personal.location = account.personal.location || {};
469
- account.personal.location.country = account.personal.location.country || '';
470
- account.personal.location.region = account.personal.location.region || '';
471
- account.personal.location.city = account.personal.location.city || '';
472
-
473
- account.personal.name = account.personal.name || {};
474
- account.personal.name.first = account.personal.name.first || '';
475
- account.personal.name.last = account.personal.name.last || '';
476
-
477
- account.personal.telephone = account.personal.telephone || {};
478
- account.personal.telephone.countryCode = account.personal.telephone.countryCode || 0;
479
- account.personal.telephone.national = account.personal.telephone.national || 0;
480
-
481
- account.personal.company = account.personal.company || {};
482
- account.personal.company.name = account.personal.company.name || '';
483
- account.personal.company.position = account.personal.company.position || '';
484
-
485
- // Set UI elements
486
- // In a try/catch because this lib is used in node sometimes
487
- try {
488
- var cancelURL = isDevelopment ? 'http://localhost:4001/cancel' : 'https://itwcreativeworks.com/portal/account/payment/manage';
489
-
490
- var billingSubscribeBtn = self.dom.select('.auth-billing-subscribe-btn');
491
- var billingUpdateBtn = self.dom.select('.auth-billing-update-btn');
492
- var billingPlanId = self.dom.select('.auth-billing-plan-id-element');
493
- var billingFrequencyEl = self.dom.select('.auth-billing-frequency-element');
494
- var billingStatusEl = self.dom.select('.auth-billing-status-element');
495
- var billingStatusColorEl = self.dom.select('.auth-billing-status-color-element');
496
- var billingStartDateEl = self.dom.select('.auth-billing-start-date-element');
497
- var billingExpirationDateEl = self.dom.select('.auth-billing-expiration-date-element');
498
- var billingSuspendedMessageEl = self.dom.select('.auth-billing-suspended-message-element');
499
- var billingTrialExpirationDateEl = self.dom.select('.auth-billing-trial-expiration-date-element');
500
-
501
- var $referralCount = self.dom.select('.auth-referral-count-element');
502
- var $referralCode = self.dom.select('.auth-referral-code-element');
503
- var $referralLink = self.dom.select('.auth-referral-link-element');
504
- var $referralSocialLink = self.dom.select('a.auth-referral-social-link[data-provider]');
505
-
506
- var authCreatedEl = self.dom.select('.auth-created-element');
507
- var authPhoneInput = self.dom.select('.auth-phone-input');
508
-
509
- var updateURL = new URL(cancelURL);
510
- var referralURL = new URL(window.location.origin || window.location.host);
511
- var accountCreationDate = new Date(+self.utilities.get(firebaseUser, 'metadata.createdAt', '0'));
512
-
513
- function _setAuthItem(selector, value) {
514
- self.dom.select(selector).each(function(e, i) {
515
- if (e.tagName === 'INPUT') {
516
- self.dom.select(e).setValue(value);
517
- } else {
518
- self.dom.select(e).setInnerHTML(value);
519
- }
520
- });
521
- }
522
-
523
- referralURL.pathname = '/';
524
- referralURL.searchParams.set('aff', account.affiliate.code)
525
-
526
- authCreatedEl.setInnerHTML(
527
- new Date(accountCreationDate)
528
- .toLocaleString(undefined, {
529
- year: 'numeric', month: 'long', day: 'numeric',
530
- })
531
- )
532
- authPhoneInput.setInnerHTML(firebaseUser.phoneNumber).setValue(firebaseUser.phoneNumber)
533
-
534
- updateURL.searchParams.set('orderId', account.plan.payment.orderId);
535
- updateURL.searchParams.set('resourceId', account.plan.payment.resourceId);
536
-
537
- billingUpdateBtn.setAttribute('hidden', true).setAttribute('href', updateURL.toString());
538
- billingSubscribeBtn.setAttribute('hidden', true);
539
- billingSuspendedMessageEl.setAttribute('hidden', true);
540
- billingTrialExpirationDateEl.setAttribute('hidden', true);
541
-
542
- // Update active UI
543
- if (planIsActive) {
544
- billingUpdateBtn.removeAttribute('hidden');
545
- } else {
546
- billingSubscribeBtn.removeAttribute('hidden');
547
- }
548
-
549
- // Update suspended UI
550
- if (planIsSuspended) {
551
- billingUpdateBtn.removeAttribute('hidden');
552
- billingSubscribeBtn.setAttribute('hidden', true);
553
-
554
- billingSuspendedMessageEl.removeAttribute('hidden');
555
- }
556
-
557
- // Update trial UI
558
- if (
559
- account.plan.trial.activated
560
- && daysTillTrialExpire > 0
561
- ) {
562
- billingTrialExpirationDateEl
563
- .removeAttribute('hidden')
564
- .setInnerHTML('<i class="fas fa-gift mr-1"></i> Your free trial expires in ' + daysTillTrialExpire + ' days');
565
- }
566
-
567
- // Change the status to 'failed' if the plan is suspended because room temperature IQ people think 'suspended' means 'cancelled'
568
- var visibleStatus = uppercase(account.plan.status === 'suspended' ? 'failed payment' : account.plan.status);
569
- // If user is on trial, start date is trial exp date
570
- var visibleStartDate = null;
571
- // If basic, just show account creation date
572
- if (unresolvedPlanId === defaultPlanId) {
573
- visibleStartDate = accountCreationDate;
574
- billingStatusEl.setAttribute('hidden', true);
575
- } else {
576
- if (account.plan.status === 'cancelled') {
577
- visibleStartDate = account.plan.payment.startDate.timestamp;
578
- } else {
579
- if (account.plan.trial.activated) {
580
- visibleStartDate = account.plan.trial.expires.timestamp;
581
- }
582
- }
583
-
584
- visibleStartDate = visibleStartDate || accountCreationDate;
585
- }
586
- var visibleFrequency = account.plan.payment.frequency === 'unknown' ? 'monthly' : account.plan.payment.frequency;
587
-
588
- // Update billing UI
589
- // billingPlanId.setInnerHTML(splitDashesAndUppercase(account.plan.id));
590
- billingPlanId.setInnerHTML(splitDashesAndUppercase(unresolvedPlanId)); // Show unresolved because we want to show what plan they have bought not what the expirattion status resolves to
591
- billingFrequencyEl.setInnerHTML(visibleFrequency);
592
- billingStatusEl.setInnerHTML(visibleStatus);
593
- billingStatusColorEl
594
- .removeClass('bg-soft-success').removeClass('bg-soft-danger').removeClass('bg-soft-warning')
595
- .removeClass('text-success').removeClass('text-danger').removeClass('text-warning')
596
- if (account.plan.status === 'active') {
597
- billingStatusColorEl.addClass('bg-soft-success').addClass('text-success');
598
- } else {
599
- billingStatusColorEl.addClass('bg-soft-danger').addClass('text-danger');
600
- }
601
- billingStartDateEl.setInnerHTML(new Date(visibleStartDate).toLocaleString(undefined, {
602
- year: 'numeric', month: 'long', day: 'numeric',
603
- }));
604
- // billingExpirationDateEl.setInnerHTML(isBasicPlan && daysTillExpire < 366
605
- billingExpirationDateEl.setInnerHTML('<i class="fas fa-exclamation-triangle mr-1"></i> Expires in ' + daysTillExpire + ' days ');
606
- if (daysTillExpire > 0 && daysTillExpire < 366) {
607
- billingExpirationDateEl.removeAttribute('hidden');
608
- }
609
-
610
- // Update payment method UI
611
- if (account.plan.status === 'suspended') {
612
- self.dom.select('.master-alert-suspended').removeAttribute('hidden');
613
- }
614
-
615
- // Update API UI
616
- _setAuthItem('.auth-apikey-element', self.utilities.get(account, 'api.privateKey', 'n/a'));
617
-
618
- // Update referral UI
619
- $referralCount.setInnerHTML(account.affiliate.referrals.length);
620
- $referralCode.setInnerHTML(account.affiliate.code).setValue(account.affiliate.code);
621
- $referralCode.setInnerHTML(referralURL.toString()).setValue(referralURL.toString());
622
-
623
- var affiliateLinkURI = encodeURIComponent(referralURL.toString());
624
- var affiliateLinkTextURI = encodeURIComponent('Sign up for ' + self.utilities.get(self.Manager, 'properties.global.brand.name', 'this') + ', a useful service:');
625
-
626
- // Update social links
627
- $referralSocialLink
628
- .each(function ($el) {
629
- var provider = $el.dataset.provider;
630
- var text = encodeURIComponent($el.dataset.shareText || '');
631
-
632
- $el.setAttribute('target', '_blank')
633
-
634
- if (provider === 'facebook') {
635
- $el.setAttribute('href', 'https://www.facebook.com/sharer.php?u=' + (affiliateLinkURI) + '')
636
- } else if (provider === 'twitter') {
637
- $el.setAttribute('href', 'https://twitter.com/share?url=' + (affiliateLinkURI) + '&text=' + (text || affiliateLinkTextURI) + '')
638
- } else if (provider === 'pinterest') {
639
- $el.setAttribute('href', 'https://pinterest.com/pin/create/button/?url=' + (affiliateLinkURI) + '&description=' + (text || affiliateLinkTextURI) + '')
640
- } else if (provider === 'tumblr') {
641
- $el.setAttribute('href', 'https://www.tumblr.com/share/link?url=' + (affiliateLinkURI) + '&text=' + (text || affiliateLinkTextURI) + '')
642
- } else if (provider === 'linkedin') {
643
- $el.setAttribute('href', 'https://www.linkedin.com/sharing/share-offsite/?url=' + (affiliateLinkURI) + '&title=' + (text || affiliateLinkTextURI) + '')
644
- // $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`)
645
- // $el.setAttribute('href', `http://www.linkedin.com/shareArticle?mini=false&url=' + affiliateLinkURI + '&title=' + text || affiliateLinkTextURI + '`)
646
- } else if (provider === 'reddit') {
647
- $el.setAttribute('href', 'http://www.reddit.com/submit?url=' + (affiliateLinkURI) + '&title=' + (text || affiliateLinkTextURI) + '')
648
- }
649
- })
650
-
651
- // TODO: ADD THESE THINGS: USAGE RESOVLER ETC
652
- console.log('++++++account 2', JSON.stringify(account, null, 2));
653
- console.log('++++++options 2', JSON.stringify(options, null, 2));
654
-
655
- } catch (e) {
656
- if (typeof window !== 'undefined') {
657
- console.error('Unable to set DOM elements', e);
658
- }
659
- }
660
-
661
- self.properties = account;
662
-
663
- return self.properties;
664
- }
665
-
666
- module.exports = Account;