web-manager 2.1.27 → 2.1.31
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.
- package/index.js +24 -20
- package/lib/account.js +62 -48
- package/package.json +1 -1
package/index.js
CHANGED
@@ -1220,6 +1220,7 @@ function Manager() {
|
|
1220
1220
|
if (setting.enabled === true) {
|
1221
1221
|
function _post() {
|
1222
1222
|
// This.log('Loaded Firebase.');
|
1223
|
+
// console.log('_post.');
|
1223
1224
|
window.app = firebase.initializeApp(setting.config);
|
1224
1225
|
|
1225
1226
|
Promise.all([
|
@@ -1231,8 +1232,9 @@ function Manager() {
|
|
1231
1232
|
.catch(reject);
|
1232
1233
|
}
|
1233
1234
|
if (setting.load) {
|
1234
|
-
setting.load()
|
1235
|
-
_post
|
1235
|
+
setting.load(This)
|
1236
|
+
.then(_post)
|
1237
|
+
.catch(reject);
|
1236
1238
|
} else {
|
1237
1239
|
import('firebase/app')
|
1238
1240
|
.then(function(mod) {
|
@@ -1241,9 +1243,8 @@ function Manager() {
|
|
1241
1243
|
})
|
1242
1244
|
.catch(reject);
|
1243
1245
|
}
|
1244
|
-
return resolve()
|
1245
1246
|
} else {
|
1246
|
-
|
1247
|
+
resolve();
|
1247
1248
|
}
|
1248
1249
|
});
|
1249
1250
|
}
|
@@ -1257,15 +1258,16 @@ function Manager() {
|
|
1257
1258
|
var setting = options.libraries.firebase_auth;
|
1258
1259
|
if (setting.enabled === true) {
|
1259
1260
|
if (setting.load) {
|
1260
|
-
setting.load()
|
1261
|
-
resolve
|
1261
|
+
setting.load(This)
|
1262
|
+
.then(resolve)
|
1263
|
+
.catch(reject);
|
1262
1264
|
} else {
|
1263
1265
|
import('firebase/auth')
|
1264
1266
|
.then(resolve)
|
1265
1267
|
.catch(reject);
|
1266
1268
|
}
|
1267
1269
|
} else {
|
1268
|
-
|
1270
|
+
resolve();
|
1269
1271
|
}
|
1270
1272
|
|
1271
1273
|
});
|
@@ -1280,15 +1282,16 @@ function Manager() {
|
|
1280
1282
|
var setting = options.libraries.firebase_firestore;
|
1281
1283
|
if (setting.enabled === true) {
|
1282
1284
|
if (setting.load) {
|
1283
|
-
setting.load()
|
1284
|
-
resolve
|
1285
|
+
setting.load(This)
|
1286
|
+
.then(resolve)
|
1287
|
+
.catch(reject);
|
1285
1288
|
} else {
|
1286
1289
|
import('firebase/firestore')
|
1287
1290
|
.then(resolve)
|
1288
1291
|
.catch(reject);
|
1289
1292
|
}
|
1290
1293
|
} else {
|
1291
|
-
|
1294
|
+
resolve();
|
1292
1295
|
}
|
1293
1296
|
});
|
1294
1297
|
}
|
@@ -1301,15 +1304,16 @@ function Manager() {
|
|
1301
1304
|
var setting = options.libraries.firebase_messaging;
|
1302
1305
|
if (setting.enabled === true) {
|
1303
1306
|
if (setting.load) {
|
1304
|
-
setting.load()
|
1305
|
-
resolve
|
1307
|
+
setting.load(This)
|
1308
|
+
.then(resolve)
|
1309
|
+
.catch(reject);
|
1306
1310
|
} else {
|
1307
1311
|
import('firebase/messaging')
|
1308
1312
|
.then(resolve)
|
1309
1313
|
.catch(reject);
|
1310
1314
|
}
|
1311
1315
|
} else {
|
1312
|
-
|
1316
|
+
resolve();
|
1313
1317
|
}
|
1314
1318
|
});
|
1315
1319
|
}
|
@@ -1336,7 +1340,7 @@ function Manager() {
|
|
1336
1340
|
})
|
1337
1341
|
.catch(reject);
|
1338
1342
|
} else {
|
1339
|
-
|
1343
|
+
resolve();
|
1340
1344
|
}
|
1341
1345
|
});
|
1342
1346
|
}
|
@@ -1351,11 +1355,11 @@ function Manager() {
|
|
1351
1355
|
.then(function(mod) {
|
1352
1356
|
window.cookieconsent.initialise(options.libraries.cookieconsent.config);
|
1353
1357
|
// This.log('Loaded Cookieconsent.');
|
1354
|
-
|
1358
|
+
resolve();
|
1355
1359
|
})
|
1356
1360
|
.catch(reject);
|
1357
1361
|
} else {
|
1358
|
-
|
1362
|
+
resolve();
|
1359
1363
|
}
|
1360
1364
|
|
1361
1365
|
});
|
@@ -1379,11 +1383,11 @@ function Manager() {
|
|
1379
1383
|
return reject(e);
|
1380
1384
|
}
|
1381
1385
|
// This.log('Loaded tawk.');
|
1382
|
-
|
1386
|
+
resolve();
|
1383
1387
|
})
|
1384
1388
|
|
1385
1389
|
} else {
|
1386
|
-
|
1390
|
+
resolve();
|
1387
1391
|
}
|
1388
1392
|
});
|
1389
1393
|
}
|
@@ -1402,11 +1406,11 @@ function Manager() {
|
|
1402
1406
|
config.environment = This.properties.meta.environment;
|
1403
1407
|
Sentry.init(config);
|
1404
1408
|
// This.log('Loaded Sentry.');
|
1405
|
-
|
1409
|
+
resolve();
|
1406
1410
|
})
|
1407
1411
|
.catch(reject);
|
1408
1412
|
} else {
|
1409
|
-
|
1413
|
+
resolve();
|
1410
1414
|
}
|
1411
1415
|
});
|
1412
1416
|
}
|
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
|
-
|
16
|
-
self.
|
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(
|
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(
|
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
|
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((
|
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
|
-
|
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
|
-
|
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