web-manager 2.1.26 → 2.1.30

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 +63 -32
  2. package/lib/account.js +62 -48
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -536,6 +536,7 @@ function Manager() {
536
536
  libraries: {
537
537
  firebase_app: {
538
538
  enabled: true,
539
+ load: false,
539
540
  config: {
540
541
  apiKey: '',
541
542
  authDomain: '',
@@ -547,13 +548,16 @@ function Manager() {
547
548
  }
548
549
  },
549
550
  firebase_firestore: {
550
- enabled: true
551
+ enabled: true,
552
+ load: false,
551
553
  },
552
554
  firebase_messaging: {
553
- enabled: true
555
+ enabled: true,
556
+ load: false,
554
557
  },
555
558
  firebase_auth: {
556
559
  enabled: true,
560
+ load: false,
557
561
  },
558
562
  lazysizes: {
559
563
  enabled: true
@@ -1212,12 +1216,11 @@ function Manager() {
1212
1216
  // if (typeof window.firebase !== 'undefined') {
1213
1217
  // return resolve();
1214
1218
  // }
1215
- if (options.libraries.firebase_app.enabled === true) {
1216
- import('firebase/app')
1217
- .then(function(mod) {
1219
+ var setting = options.libraries.firebase_app
1220
+ if (setting.enabled === true) {
1221
+ function _post() {
1218
1222
  // This.log('Loaded Firebase.');
1219
- window.firebase = mod.default;
1220
- window.app = firebase.initializeApp(options.libraries.firebase_app.config);
1223
+ window.app = firebase.initializeApp(setting.config);
1221
1224
 
1222
1225
  Promise.all([
1223
1226
  load_firebase_auth(This, options),
@@ -1226,10 +1229,20 @@ function Manager() {
1226
1229
  ])
1227
1230
  .then(resolve)
1228
1231
  .catch(reject);
1229
- })
1230
- .catch(reject);
1232
+ }
1233
+ if (setting.load) {
1234
+ setting.load()
1235
+ _post()
1236
+ } else {
1237
+ import('firebase/app')
1238
+ .then(function(mod) {
1239
+ window.firebase = mod.default;
1240
+ _post()
1241
+ })
1242
+ .catch(reject);
1243
+ }
1231
1244
  } else {
1232
- return resolve();
1245
+ resolve();
1233
1246
  }
1234
1247
  });
1235
1248
  }
@@ -1240,12 +1253,18 @@ function Manager() {
1240
1253
  // if (typeof utilities.get(window, 'firebase.auth', undefined) !== 'undefined') {
1241
1254
  // return resolve();
1242
1255
  // }
1243
- if (options.libraries.firebase_auth.enabled === true) {
1244
- import('firebase/auth')
1245
- .then(resolve)
1246
- .catch(reject);
1256
+ var setting = options.libraries.firebase_auth;
1257
+ if (setting.enabled === true) {
1258
+ if (setting.load) {
1259
+ setting.load()
1260
+ resolve()
1261
+ } else {
1262
+ import('firebase/auth')
1263
+ .then(resolve)
1264
+ .catch(reject);
1265
+ }
1247
1266
  } else {
1248
- return resolve();
1267
+ resolve();
1249
1268
  }
1250
1269
 
1251
1270
  });
@@ -1257,12 +1276,18 @@ function Manager() {
1257
1276
  // if (typeof utilities.get(window, 'firebase.firestore', undefined) !== 'undefined') {
1258
1277
  // return resolve();
1259
1278
  // }
1260
- if (options.libraries.firebase_firestore.enabled === true) {
1261
- import('firebase/firestore')
1262
- .then(resolve)
1263
- .catch(reject);
1279
+ var setting = options.libraries.firebase_firestore;
1280
+ if (setting.enabled === true) {
1281
+ if (setting.load) {
1282
+ setting.load()
1283
+ resolve()
1284
+ } else {
1285
+ import('firebase/firestore')
1286
+ .then(resolve)
1287
+ .catch(reject);
1288
+ }
1264
1289
  } else {
1265
- return resolve();
1290
+ resolve();
1266
1291
  }
1267
1292
  });
1268
1293
  }
@@ -1272,12 +1297,18 @@ function Manager() {
1272
1297
  // if (typeof utilities.get(window, 'firebase.messaging', undefined) !== 'undefined') {
1273
1298
  // return resolve();
1274
1299
  // }
1275
- if (options.libraries.firebase_messaging.enabled === true) {
1276
- import('firebase/messaging')
1277
- .then(resolve)
1278
- .catch(reject);
1300
+ var setting = options.libraries.firebase_messaging;
1301
+ if (setting.enabled === true) {
1302
+ if (setting.load) {
1303
+ setting.load()
1304
+ resolve()
1305
+ } else {
1306
+ import('firebase/messaging')
1307
+ .then(resolve)
1308
+ .catch(reject);
1309
+ }
1279
1310
  } else {
1280
- return resolve();
1311
+ resolve();
1281
1312
  }
1282
1313
  });
1283
1314
  }
@@ -1304,7 +1335,7 @@ function Manager() {
1304
1335
  })
1305
1336
  .catch(reject);
1306
1337
  } else {
1307
- return resolve();
1338
+ resolve();
1308
1339
  }
1309
1340
  });
1310
1341
  }
@@ -1319,11 +1350,11 @@ function Manager() {
1319
1350
  .then(function(mod) {
1320
1351
  window.cookieconsent.initialise(options.libraries.cookieconsent.config);
1321
1352
  // This.log('Loaded Cookieconsent.');
1322
- return resolve();
1353
+ resolve();
1323
1354
  })
1324
1355
  .catch(reject);
1325
1356
  } else {
1326
- return resolve();
1357
+ resolve();
1327
1358
  }
1328
1359
 
1329
1360
  });
@@ -1347,11 +1378,11 @@ function Manager() {
1347
1378
  return reject(e);
1348
1379
  }
1349
1380
  // This.log('Loaded tawk.');
1350
- return resolve();
1381
+ resolve();
1351
1382
  })
1352
1383
 
1353
1384
  } else {
1354
- return resolve();
1385
+ resolve();
1355
1386
  }
1356
1387
  });
1357
1388
  }
@@ -1370,11 +1401,11 @@ function Manager() {
1370
1401
  config.environment = This.properties.meta.environment;
1371
1402
  Sentry.init(config);
1372
1403
  // This.log('Loaded Sentry.');
1373
- return resolve();
1404
+ resolve();
1374
1405
  })
1375
1406
  .catch(reject);
1376
1407
  } else {
1377
- return resolve();
1408
+ resolve();
1378
1409
  }
1379
1410
  });
1380
1411
  }
package/lib/account.js CHANGED
@@ -3,17 +3,21 @@
3
3
  var dom;
4
4
  var utilities;
5
5
 
6
- function Account() {
6
+ function Account(init) {
7
7
  var self = this;
8
+ init = init || {};
8
9
  self.properties = {};
9
-
10
- dom = self.Manager.dom();
11
- utilities = self.Manager.utilities();
12
-
13
10
  self.accountPageInitialized = false;
14
11
 
15
- if (new URL(window.location.href).pathname.includes('account')) {
16
- self.initializeAccountPage();
12
+ try {
13
+ dom = init.dom || self.Manager.dom();
14
+ utilities = init.utilities || self.Manager.utilities();
15
+
16
+ if (new URL(window.location.href).pathname.includes('account')) {
17
+ self.initializeAccountPage();
18
+ }
19
+ } catch (e) {
20
+ console.error('Failed to initialize libraries');
17
21
  }
18
22
 
19
23
  // var pastDate = new Date(0);
@@ -158,14 +162,14 @@ Account.prototype.resolve = function (account, options) {
158
162
  firebase.firestore().doc('users/' + currentUser.uid)
159
163
  .get()
160
164
  .then(function (doc) {
161
- return resolve(_resolveAccount(self, currentUser, doc.data(), options));
165
+ return resolve(self._resolveAccount(currentUser, doc.data(), options));
162
166
  })
163
167
  .catch(reject)
164
168
  } else {
165
169
  if (!currentUser) {
166
170
  return reject(new Error('No currently authenticated user'))
167
171
  }
168
- return resolve(_resolveAccount(self, currentUser, account, options));
172
+ return resolve(self._resolveAccount(currentUser, account, options));
169
173
  }
170
174
  });
171
175
  }
@@ -190,7 +194,9 @@ function getMonth(date) {
190
194
  return monthNames[date.getMonth()];
191
195
  }
192
196
 
193
- function _resolveAccount(self, currentUser, account, options) {
197
+ Account.prototype._resolveAccount = function (currentUser, account, options) {
198
+ var self = this;
199
+ currentUser = currentUser || {};
194
200
  account = account || {};
195
201
  options = options || {};
196
202
 
@@ -224,49 +230,17 @@ function _resolveAccount(self, currentUser, account, options) {
224
230
 
225
231
  var planExpireDate = new Date(account.plan.expires.timestamp);
226
232
  var now = new Date();
227
- var daysTillExpire = Math.floor(( planExpireDate - now ) / 86400000);
233
+ var daysTillExpire = Math.floor((planExpireDate - now) / 86400000);
228
234
  let difference = (planExpireDate.getTime() - now.getTime())/(24*3600*1000);
229
235
  var startDate = new Date(account.plan.payment.startDate.timestamp);
236
+ var planIsActive = difference > -1 && account.plan.id !== defaultPlanId;
230
237
 
231
- var isDevelopment = utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
232
- // var apiLinkURL = isDevelopment ? 'http://localhost:5000/discord-link' : 'https://api.{{ site.brand.name }}.com/discord-link';
233
- // var apiUnlinkURL = isDevelopment ? 'http://localhost:5000/discord-unlink' : 'https://api.{{ site.brand.name }}.com/discord-unlink';
234
- var cancelURL = isDevelopment ? 'http://localhost:4001/cancel/' : 'https://itwcreativeworks.com/portal/account/manage/';
235
-
236
- var billingSubscribeBtn = dom.select('.auth-billing-subscribe-btn');
237
- var billingUpdateBtn = dom.select('.auth-billing-update-btn');
238
- var billingPlanId = dom.select('.auth-billing-plan-id-element');
239
- var billingFrequencyEl = dom.select('.auth-billing-frequency-element');
240
- var billingStartDateEl = dom.select('.auth-billing-start-date-element');
241
- var billingExpirationDateEl = dom.select('.auth-billing-expiration-date-element');
242
- var updateURL = new URL(cancelURL);
243
- var currentURL = new URL(window.location.href);
244
-
245
- billingSubscribeBtn.setAttribute('hidden', true);
246
- billingUpdateBtn.setAttribute('hidden', true);
247
-
248
- if (difference > -1 && account.plan.id !== defaultPlanId) {
238
+ if (planIsActive) {
249
239
  account.plan.id = account.plan.id;
250
- updateURL.searchParams.set('appName', utilities.get(self.Manager, 'properties.global.brand.name', 'Unknown'));
251
- updateURL.searchParams.set('supportUrl', currentURL.origin + '/support');
252
- updateURL.searchParams.set('supportEmail', utilities.get(self.Manager, 'properties.contact.emailSupport', 'unknown@email.com'));
253
- updateURL.searchParams.set('userEmail', currentUser.email);
254
- updateURL.searchParams.set('userId', currentUser.uid);
255
- updateURL.searchParams.set('orderId', account.plan.payment.orderId);
256
- updateURL.searchParams.set('resourceId', account.plan.payment.resourceId);
257
- billingUpdateBtn.removeAttribute('hidden').setAttribute('href', updateURL.toString());
258
240
  } else {
259
241
  account.plan.id = defaultPlanId;
260
- billingSubscribeBtn.removeAttribute('hidden');
261
242
  }
262
243
 
263
- billingPlanId.setInnerHTML(uppercase(account.plan.id));
264
- billingFrequencyEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' (billed ' + uppercase(account.plan.payment.frequency) + ')' : '');
265
- billingStartDateEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' - Purchased ' + getMonth(startDate) + ' ' + startDate.getDate() + ', ' + startDate.getFullYear() : '');
266
- billingExpirationDateEl.setInnerHTML(account.plan.id !== defaultPlanId && daysTillExpire < 366
267
- ? '<i class="fas fa-exclamation-triangle mr-1"></i> Expires in ' + daysTillExpire + ' days '
268
- : '');
269
-
270
244
  // Resolve oAuth2
271
245
  account.oauth2 = account.oauth2 || {};
272
246
  account.oauth2.discord = account.oauth2.discord || {};
@@ -280,10 +254,50 @@ function _resolveAccount(self, currentUser, account, options) {
280
254
  account.roles.vip = account.roles.vip === true || account.roles.vip === 'true';
281
255
  account.roles.promoExempt = account.roles.promoExempt === true || account.roles.promoExempt === 'true';
282
256
 
283
- self.properties = account;
284
-
285
257
  // Set UI elements
286
- _setAuthItem('.auth-apikey-element', utilities.get(account, 'api.privateKey', 'n/a'))
258
+ try {
259
+ var isDevelopment = utilities.get(self.Manager, 'properties.meta.environment', '') === 'development';
260
+ // var apiLinkURL = isDevelopment ? 'http://localhost:5000/discord-link' : 'https://api.{{ site.brand.name }}.com/discord-link';
261
+ // var apiUnlinkURL = isDevelopment ? 'http://localhost:5000/discord-unlink' : 'https://api.{{ site.brand.name }}.com/discord-unlink';
262
+ var cancelURL = isDevelopment ? 'http://localhost:4001/cancel/' : 'https://itwcreativeworks.com/portal/account/manage/';
263
+
264
+ var billingSubscribeBtn = dom.select('.auth-billing-subscribe-btn');
265
+ var billingUpdateBtn = dom.select('.auth-billing-update-btn');
266
+ var billingPlanId = dom.select('.auth-billing-plan-id-element');
267
+ var billingFrequencyEl = dom.select('.auth-billing-frequency-element');
268
+ var billingStartDateEl = dom.select('.auth-billing-start-date-element');
269
+ var billingExpirationDateEl = dom.select('.auth-billing-expiration-date-element');
270
+ var updateURL = new URL(cancelURL);
271
+ var currentURL = new URL(window.location.href);
272
+
273
+ billingSubscribeBtn.setAttribute('hidden', true);
274
+ billingUpdateBtn.setAttribute('hidden', true);
275
+
276
+ if (planIsActive) {
277
+ updateURL.searchParams.set('appName', utilities.get(self.Manager, 'properties.global.brand.name', 'Unknown'));
278
+ updateURL.searchParams.set('supportUrl', currentURL.origin + '/support');
279
+ updateURL.searchParams.set('supportEmail', utilities.get(self.Manager, 'properties.contact.emailSupport', 'unknown@email.com'));
280
+ updateURL.searchParams.set('userEmail', currentUser.email);
281
+ updateURL.searchParams.set('userId', currentUser.uid);
282
+ updateURL.searchParams.set('orderId', account.plan.payment.orderId);
283
+ updateURL.searchParams.set('resourceId', account.plan.payment.resourceId);
284
+ billingUpdateBtn.removeAttribute('hidden').setAttribute('href', updateURL.toString());
285
+ } else {
286
+ billingSubscribeBtn.removeAttribute('hidden');
287
+ }
288
+
289
+ billingPlanId.setInnerHTML(uppercase(account.plan.id));
290
+ billingFrequencyEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' (billed ' + uppercase(account.plan.payment.frequency) + ')' : '');
291
+ billingStartDateEl.setInnerHTML(account.plan.id !== defaultPlanId ? ' - Purchased ' + getMonth(startDate) + ' ' + startDate.getDate() + ', ' + startDate.getFullYear() : '');
292
+ billingExpirationDateEl.setInnerHTML(account.plan.id !== defaultPlanId && daysTillExpire < 366
293
+ ? '<i class="fas fa-exclamation-triangle mr-1"></i> Expires in ' + daysTillExpire + ' days '
294
+ : '');
295
+
296
+ _setAuthItem('.auth-apikey-element', utilities.get(account, 'api.privateKey', 'n/a'))
297
+ } catch (e) {
298
+ console.error('Unable to set DOM elements', e);
299
+ }
300
+ self.properties = account;
287
301
 
288
302
  return self.properties;
289
303
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-manager",
3
- "version": "2.1.26",
3
+ "version": "2.1.30",
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": {