web-manager 3.2.45 → 3.2.47
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +1 -1
- package/lib/account.js +51 -3
- package/lib/debug.js +4 -2
- package/lib/dom.js +1 -1
- package/lib/utilities.js +39 -14
- package/package.json +9 -2
- package/test/test.js +158 -0
package/index.js
CHANGED
@@ -1207,7 +1207,7 @@ function Manager() {
|
|
1207
1207
|
var buildTimeCurrent = self.properties.global.buildTime;
|
1208
1208
|
var buildTimeLive = new Date(data['npm-build'].timestamp);
|
1209
1209
|
|
1210
|
-
// Set buildTimeCurrent to 1 hour ahead
|
1210
|
+
// Set buildTimeCurrent to 1 hour ahead to account for the npm-build time which will ALWAYS be set to later since it happens later
|
1211
1211
|
buildTimeCurrent.setHours(buildTimeCurrent.getHours() + 1);
|
1212
1212
|
|
1213
1213
|
// Log
|
package/lib/account.js
CHANGED
@@ -267,8 +267,9 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
267
267
|
|
268
268
|
// @@@DEVELOPER
|
269
269
|
// var date = '2024-04-23T00:07:29.183Z';
|
270
|
-
// var date = `2024-03-23T00:07:29.183Z`;
|
271
|
-
// account.plan.id = 'basic';
|
270
|
+
// // var date = `2024-03-23T00:07:29.183Z`;
|
271
|
+
// // account.plan.id = 'basic';
|
272
|
+
// account.plan.id = 'premium';
|
272
273
|
// account.plan.trial = {
|
273
274
|
// activated: false,
|
274
275
|
// expires: {
|
@@ -281,6 +282,43 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
281
282
|
// timestampUNIX: Math.round(new Date(date).getTime() / 1000),
|
282
283
|
// }
|
283
284
|
// account.plan.status = 'cancelled';
|
285
|
+
// account.plan = {
|
286
|
+
// "id": "premium",
|
287
|
+
// "payment": {
|
288
|
+
// "frequency": "monthly",
|
289
|
+
// "startDate": {
|
290
|
+
// "timestampUNIX": 1711373195,
|
291
|
+
// "timestamp": "2024-03-25T13:26:35.000Z"
|
292
|
+
// },
|
293
|
+
// "updatedBy": {
|
294
|
+
// "date": {
|
295
|
+
// "timestamp": "2024-04-02T13:46:47.441Z",
|
296
|
+
// "timestampUNIX": 1712065607
|
297
|
+
// },
|
298
|
+
// "event": {
|
299
|
+
// "name": "subscription-profile-fixer",
|
300
|
+
// "id": "subscription-profile-fixer"
|
301
|
+
// }
|
302
|
+
// },
|
303
|
+
// "resourceId": "AzyrfuU82V0cZ87qp",
|
304
|
+
// "orderId": "0908-176942-1223",
|
305
|
+
// "active": false,
|
306
|
+
// "processor": "chargebee"
|
307
|
+
// },
|
308
|
+
// "trial": {
|
309
|
+
// "expires": {
|
310
|
+
// "timestamp": "1970-01-01T00:00:00.000Z",
|
311
|
+
// "timestampUNIX": 0
|
312
|
+
// },
|
313
|
+
// "activated": true
|
314
|
+
// },
|
315
|
+
// "expires": {
|
316
|
+
// "timestampUNIX": 1714656799,
|
317
|
+
// "timestamp": "2024-05-02T13:33:19.000Z"
|
318
|
+
// },
|
319
|
+
// "limits": {},
|
320
|
+
// "status": "cancelled"
|
321
|
+
// },
|
284
322
|
|
285
323
|
account.plan.limits = account.plan.limits || {};
|
286
324
|
// account.plan.devices = account.plan.devices || 1;
|
@@ -516,11 +554,21 @@ Account.prototype._resolveAccount = function (firebaseUser, account, options) {
|
|
516
554
|
// Change the status to 'failed' if the plan is suspended because room temperature IQ people think 'suspended' means 'cancelled'
|
517
555
|
var visibleStatus = uppercase(account.plan.status === 'suspended' ? 'failed payment' : account.plan.status);
|
518
556
|
// If user is on trial, start date is trial exp date
|
519
|
-
var visibleStartDate =
|
557
|
+
var visibleStartDate = null;
|
520
558
|
// If basic, just show account creation date
|
521
559
|
if (unresolvedPlanId === defaultPlanId) {
|
522
560
|
visibleStartDate = accountCreationDate;
|
523
561
|
billingStatusEl.setAttribute('hidden', true);
|
562
|
+
} else {
|
563
|
+
if (account.plan.status === 'cancelled') {
|
564
|
+
visibleStartDate = account.plan.payment.startDate.timestamp;
|
565
|
+
} else {
|
566
|
+
if (account.plan.trial.activated) {
|
567
|
+
visibleStartDate = account.plan.trial.expires.timestamp;
|
568
|
+
}
|
569
|
+
}
|
570
|
+
|
571
|
+
visibleStartDate = visibleStartDate || accountCreationDate;
|
524
572
|
}
|
525
573
|
var visibleFrequency = account.plan.payment.frequency === 'unknown' ? 'monthly' : account.plan.payment.frequency;
|
526
574
|
|
package/lib/debug.js
CHANGED
@@ -8,7 +8,7 @@ function Debug(utilObj) {
|
|
8
8
|
Debug.promise = function(status, data, options) {
|
9
9
|
options = options || {};
|
10
10
|
options.wait = options.wait || {enabled: false};
|
11
|
-
return new Promise((resolve, reject)
|
11
|
+
return new Promise(function (resolve, reject) {
|
12
12
|
if (status == 'resolve') {
|
13
13
|
if (options.wait.enabled) {
|
14
14
|
Debug.wait(options.wait.msec, options.wait.range)
|
@@ -48,7 +48,9 @@ Debug.wait = function(msec, range) {
|
|
48
48
|
msec = msec + randomNumPlus - randomNumMinus;
|
49
49
|
msec = (msec <= 0) ? 50 : msec;
|
50
50
|
console.log('[DEBUG] waiting...', msec);
|
51
|
-
return new Promise(
|
51
|
+
return new Promise(function (resolve, reject) {
|
52
|
+
setTimeout(resolve, msec);
|
53
|
+
});
|
52
54
|
}
|
53
55
|
|
54
56
|
module.exports = Debug;
|
package/lib/dom.js
CHANGED
package/lib/utilities.js
CHANGED
@@ -7,23 +7,26 @@ function Utilities(utilObj) {
|
|
7
7
|
this.utilities = utilObj;
|
8
8
|
}
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
.split('.')
|
16
|
-
.filter(Boolean);
|
10
|
+
Utilities.get = function (object, path, defaultValue) {
|
11
|
+
// If the path is not defined or it has false value
|
12
|
+
if (!path) {
|
13
|
+
return defaultValue;
|
14
|
+
}
|
17
15
|
|
18
|
-
|
16
|
+
// Check if the path is a string or array. If it is a string, convert it to array
|
17
|
+
const pathArray = Array.isArray(path) ? path : path.split('.');
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
// For each item in the path, dig into the object
|
20
|
+
let currentObject = object;
|
21
|
+
for (const key of pathArray) {
|
22
|
+
if (!currentObject || !currentObject.hasOwnProperty(key)) {
|
23
|
+
return defaultValue;
|
24
|
+
}
|
25
|
+
currentObject = currentObject[key];
|
26
26
|
}
|
27
|
+
|
28
|
+
// Return the value
|
29
|
+
return currentObject === undefined ? defaultValue : currentObject;
|
27
30
|
}
|
28
31
|
|
29
32
|
/* https://stackoverflow.com/questions/54733539/javascript-implementation-of-lodash-set-method */
|
@@ -48,6 +51,28 @@ Utilities.set = function (obj, path, value) {
|
|
48
51
|
return obj; // Return the top-level object to allow chaining
|
49
52
|
}
|
50
53
|
|
54
|
+
/* https://gist.github.com/jeneg/9767afdcca45601ea44930ea03e0febf */
|
55
|
+
Utilities.getLegacy = function (obj, path, def) {
|
56
|
+
if (!path) {
|
57
|
+
return def;
|
58
|
+
}
|
59
|
+
var fullPath = (path || '')
|
60
|
+
.replace(/\[/g, '.')
|
61
|
+
.replace(/]/g, '')
|
62
|
+
.split('.')
|
63
|
+
.filter(Boolean);
|
64
|
+
|
65
|
+
return fullPath.every(everyFunc) ? obj : def;
|
66
|
+
|
67
|
+
function everyFunc(step) {
|
68
|
+
// return !(step && (obj = obj[step]) === undefined);
|
69
|
+
// console.log(' CHECK > ', !(step && (obj = obj[step]) === undefined));
|
70
|
+
// console.log('step', step, 'obj', obj, 'objstep', obj[step]);
|
71
|
+
// return !(step && (obj = obj[step]) === undefined);
|
72
|
+
return !(step && (obj = obj[step]) === undefined);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
51
76
|
// https://dzone.com/articles/cross-browser-javascript-copy-and-paste
|
52
77
|
// https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
|
53
78
|
Utilities.clipboardCopy = function (input) {
|
package/package.json
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "web-manager",
|
3
|
-
"version": "3.2.
|
3
|
+
"version": "3.2.47",
|
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": {
|
7
|
-
"test": "
|
7
|
+
"test": "./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
|
8
|
+
|
9
|
+
"test_": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
|
10
|
+
"prepare_": "node -e 'require(`prepare-package`)()'"
|
8
11
|
},
|
9
12
|
"engines": {
|
10
13
|
"node": ">=6.0.0"
|
@@ -35,5 +38,9 @@
|
|
35
38
|
"cookieconsent": "^3.1.1",
|
36
39
|
"firebase": "^9.23.0",
|
37
40
|
"lazysizes": "^5.3.2"
|
41
|
+
},
|
42
|
+
"devDependencies": {
|
43
|
+
"lodash": "^4.17.21",
|
44
|
+
"mocha": "^8.4.0"
|
38
45
|
}
|
39
46
|
}
|
package/test/test.js
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
const package = require('../package.json');
|
2
|
+
const assert = require('assert');
|
3
|
+
|
4
|
+
beforeEach(() => {
|
5
|
+
});
|
6
|
+
|
7
|
+
before(() => {
|
8
|
+
});
|
9
|
+
|
10
|
+
after(() => {
|
11
|
+
});
|
12
|
+
|
13
|
+
/*
|
14
|
+
* ============
|
15
|
+
* Test Cases
|
16
|
+
* ============
|
17
|
+
*/
|
18
|
+
describe(`${package.name}`, () => {
|
19
|
+
const _ = require('../lib/utilities.js');
|
20
|
+
const lodash = require('lodash');
|
21
|
+
|
22
|
+
// Utilities
|
23
|
+
describe('.utilities()', () => {
|
24
|
+
const sample = {
|
25
|
+
main: {
|
26
|
+
true: true,
|
27
|
+
false: false,
|
28
|
+
zero: 0,
|
29
|
+
one: 1,
|
30
|
+
string: 'string',
|
31
|
+
stringEmpty: '',
|
32
|
+
object: {},
|
33
|
+
array: [],
|
34
|
+
null: null,
|
35
|
+
undefined: undefined,
|
36
|
+
nan: NaN,
|
37
|
+
infinity: Infinity,
|
38
|
+
negativeInfinity: -Infinity,
|
39
|
+
function: function () {},
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
// Normal Cases
|
44
|
+
describe('.get()', () => {
|
45
|
+
it('should return true', () => {
|
46
|
+
// console.log('---lodash', lodash.get(sample, 'main.true'));
|
47
|
+
// console.log('---_.get', _.get(sample, 'main.true'));
|
48
|
+
// console.log('---_.get2', _.get2(sample, 'main.true'));
|
49
|
+
|
50
|
+
assert.strictEqual(_.get(sample, 'main.true'), true);
|
51
|
+
});
|
52
|
+
|
53
|
+
it('should return false', () => {
|
54
|
+
assert.strictEqual(_.get(sample, 'main.false'), false);
|
55
|
+
});
|
56
|
+
|
57
|
+
it('should return 0', () => {
|
58
|
+
assert.strictEqual(_.get(sample, 'main.zero'), 0);
|
59
|
+
});
|
60
|
+
|
61
|
+
it('should return 1', () => {
|
62
|
+
assert.strictEqual(_.get(sample, 'main.one'), 1);
|
63
|
+
});
|
64
|
+
|
65
|
+
it('should return a string', () => {
|
66
|
+
assert.strictEqual(_.get(sample, 'main.string'), 'string');
|
67
|
+
});
|
68
|
+
|
69
|
+
it('should return an empty string', () => {
|
70
|
+
assert.strictEqual(_.get(sample, 'main.stringEmpty'), '');
|
71
|
+
});
|
72
|
+
|
73
|
+
it('should return an object', () => {
|
74
|
+
assert.deepStrictEqual(_.get(sample, 'main.object'), {});
|
75
|
+
});
|
76
|
+
|
77
|
+
it('should return an array', () => {
|
78
|
+
assert.deepStrictEqual(_.get(sample, 'main.array'), []);
|
79
|
+
});
|
80
|
+
|
81
|
+
it('should return null', () => {
|
82
|
+
assert.strictEqual(_.get(sample, 'main.null'), null);
|
83
|
+
});
|
84
|
+
|
85
|
+
it('should return undefined', () => {
|
86
|
+
assert.strictEqual(_.get(sample, 'main.undefined'), undefined);
|
87
|
+
});
|
88
|
+
|
89
|
+
it('should return NaN', () => {
|
90
|
+
assert.strictEqual(Number.isNaN(_.get(sample, 'main.nan')), true);
|
91
|
+
});
|
92
|
+
|
93
|
+
it('should return Infinity', () => {
|
94
|
+
assert.strictEqual(_.get(sample, 'main.infinity'), Infinity);
|
95
|
+
});
|
96
|
+
|
97
|
+
it('should return -Infinity', () => {
|
98
|
+
assert.strictEqual(_.get(sample, 'main.negativeInfinity'), -Infinity);
|
99
|
+
});
|
100
|
+
|
101
|
+
it('should return a function', () => {
|
102
|
+
assert.strictEqual(typeof _.get(sample, 'main.function'), 'function');
|
103
|
+
});
|
104
|
+
|
105
|
+
// Non-existent
|
106
|
+
it('should return undefined', () => {
|
107
|
+
assert.strictEqual(_.get(sample, 'main.nonexistent'), undefined);
|
108
|
+
});
|
109
|
+
|
110
|
+
// No path
|
111
|
+
it('should return undefined', () => {
|
112
|
+
assert.strictEqual(_.get(sample), undefined);
|
113
|
+
});
|
114
|
+
|
115
|
+
// Empty path
|
116
|
+
it('should return undefined', () => {
|
117
|
+
assert.strictEqual(_.get(sample, ''), undefined);
|
118
|
+
});
|
119
|
+
|
120
|
+
// Default value
|
121
|
+
it('should return default value', () => {
|
122
|
+
assert.strictEqual(_.get(sample, 'main.nonexistent', 'default'), 'default');
|
123
|
+
});
|
124
|
+
|
125
|
+
it('should return actual value', () => {
|
126
|
+
assert.strictEqual(_.get(sample, 'main.false', 'default'), false);
|
127
|
+
});
|
128
|
+
|
129
|
+
it('should return actual value', () => {
|
130
|
+
assert.strictEqual(_.get(sample, 'main.null', 'default'), null);
|
131
|
+
});
|
132
|
+
|
133
|
+
it('should return default value', () => {
|
134
|
+
assert.strictEqual(_.get(sample, 'main.undefined', 'default'), 'default');
|
135
|
+
});
|
136
|
+
|
137
|
+
// Non-object for object
|
138
|
+
it('should return undefined', () => {
|
139
|
+
assert.strictEqual(_.get(undefined, 'main.true'), undefined);
|
140
|
+
});
|
141
|
+
|
142
|
+
it('should return undefined', () => {
|
143
|
+
assert.strictEqual(_.get(null, 'main.true'), undefined);
|
144
|
+
});
|
145
|
+
|
146
|
+
it('should return undefined', () => {
|
147
|
+
assert.strictEqual(_.get(false, 'main.true'), undefined);
|
148
|
+
});
|
149
|
+
|
150
|
+
it('should return undefined', () => {
|
151
|
+
assert.strictEqual(_.get('', 'main.true'), undefined);
|
152
|
+
});
|
153
|
+
|
154
|
+
});
|
155
|
+
|
156
|
+
});
|
157
|
+
|
158
|
+
})
|