backend-manager 3.1.10 → 3.1.12
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-manager",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.12",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"_test": "npm run prepare && ./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
|
|
12
12
|
"test": "./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
|
|
13
13
|
"test:usage": "./node_modules/mocha/bin/mocha test/usage.js --timeout=10000",
|
|
14
|
+
"test:payment-resolver": "./node_modules/mocha/bin/mocha test/payment-resolver.js --timeout=10000",
|
|
14
15
|
"start": "node src/index.js"
|
|
15
16
|
},
|
|
16
17
|
"engines": {
|
|
@@ -41,7 +42,7 @@
|
|
|
41
42
|
"cors": "^2.8.5",
|
|
42
43
|
"dotenv": "^16.3.1",
|
|
43
44
|
"firebase-admin": "^11.11.1",
|
|
44
|
-
"firebase-functions": "^4.
|
|
45
|
+
"firebase-functions": "^4.6.0",
|
|
45
46
|
"fs-jetpack": "^5.1.0",
|
|
46
47
|
"hcaptcha": "^0.1.1",
|
|
47
48
|
"inquirer": "^8.2.5",
|
|
@@ -7,11 +7,13 @@ function Module() {
|
|
|
7
7
|
|
|
8
8
|
Module.prototype.init = function (Manager, data) {
|
|
9
9
|
const self = this;
|
|
10
|
+
|
|
10
11
|
self.Manager = Manager;
|
|
11
12
|
self.libraries = Manager.libraries;
|
|
12
|
-
self.assistant = Manager.Assistant()
|
|
13
|
+
self.assistant = Manager.Assistant();
|
|
13
14
|
|
|
14
15
|
self.context = data.context;
|
|
16
|
+
|
|
15
17
|
return self;
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -201,21 +201,6 @@ BackendAssistant.prototype.log = function () {
|
|
|
201
201
|
const self = this;
|
|
202
202
|
|
|
203
203
|
const args = Array.prototype.slice.call(arguments);
|
|
204
|
-
const last = args[args.length - 1];
|
|
205
|
-
// const override = last && typeof last === 'object' && last.environment === 'production';
|
|
206
|
-
const pop = last?.environment === 'production' || last?.environment === 'development';
|
|
207
|
-
|
|
208
|
-
// if (self.meta.environment === 'development' || override) {
|
|
209
|
-
// if (override) {
|
|
210
|
-
// args.pop();
|
|
211
|
-
// }
|
|
212
|
-
// self._log.apply(self, args);
|
|
213
|
-
// }
|
|
214
|
-
|
|
215
|
-
// This makes all OLD logs work even if they use the old {environemnt: 'production'} syntax
|
|
216
|
-
if (pop) {
|
|
217
|
-
args.pop();
|
|
218
|
-
}
|
|
219
204
|
|
|
220
205
|
self._log.apply(self, args);
|
|
221
206
|
};
|
|
@@ -14,6 +14,8 @@ function SubscriptionResolver(Manager, profile, resource) {
|
|
|
14
14
|
SubscriptionResolver.prototype.resolve = function (options) {
|
|
15
15
|
const self = this;
|
|
16
16
|
|
|
17
|
+
const datePast = moment(0);
|
|
18
|
+
|
|
17
19
|
const resolved = {
|
|
18
20
|
status: '',
|
|
19
21
|
frequency: '',
|
|
@@ -25,28 +27,32 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
25
27
|
refunded: false,
|
|
26
28
|
},
|
|
27
29
|
start: {
|
|
28
|
-
timestamp:
|
|
29
|
-
timestampUNIX:
|
|
30
|
+
timestamp: datePast,
|
|
31
|
+
timestampUNIX: datePast,
|
|
30
32
|
},
|
|
31
33
|
expires: {
|
|
32
|
-
timestamp:
|
|
33
|
-
timestampUNIX:
|
|
34
|
+
timestamp: datePast,
|
|
35
|
+
timestampUNIX: datePast,
|
|
34
36
|
},
|
|
35
37
|
cancelled: {
|
|
36
|
-
timestamp:
|
|
37
|
-
timestampUNIX:
|
|
38
|
+
timestamp: datePast,
|
|
39
|
+
timestampUNIX: datePast,
|
|
38
40
|
},
|
|
39
41
|
lastPayment: {
|
|
40
42
|
amount: 0,
|
|
41
43
|
date: {
|
|
42
|
-
timestamp:
|
|
43
|
-
timestampUNIX:
|
|
44
|
+
timestamp: datePast,
|
|
45
|
+
timestampUNIX: datePast,
|
|
44
46
|
}
|
|
45
47
|
},
|
|
46
48
|
trial: {
|
|
47
49
|
claimed: false,
|
|
48
50
|
active: false,
|
|
49
51
|
daysLeft: 0,
|
|
52
|
+
expires: {
|
|
53
|
+
timestamp: datePast,
|
|
54
|
+
timestampUNIX: datePast,
|
|
55
|
+
},
|
|
50
56
|
},
|
|
51
57
|
details: {
|
|
52
58
|
message: '',
|
|
@@ -178,6 +184,7 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
178
184
|
// Set days left
|
|
179
185
|
if (resolved.trial.active) {
|
|
180
186
|
resolved.trial.daysLeft = Math.abs(resolved.expires.timestamp.diff(options.today, 'days'));
|
|
187
|
+
resolved.trial.expires.timestamp = moment(resolved.start.timestamp).add(14, 'days');
|
|
181
188
|
}
|
|
182
189
|
|
|
183
190
|
// Set expiration
|
|
@@ -240,6 +247,9 @@ SubscriptionResolver.prototype.resolve = function (options) {
|
|
|
240
247
|
resolved.cancelled.timestampUNIX = resolved.cancelled.timestamp.unix();
|
|
241
248
|
resolved.cancelled.timestamp = resolved.cancelled.timestamp.toISOString();
|
|
242
249
|
|
|
250
|
+
resolved.trial.expires.timestampUNIX = resolved.trial.expires.timestamp.unix();
|
|
251
|
+
resolved.trial.expires.timestamp = resolved.trial.expires.timestamp.toISOString();
|
|
252
|
+
|
|
243
253
|
// Fix trial days
|
|
244
254
|
resolved.trial.daysLeft = resolved.trial.daysLeft < 0 ? 0 : resolved.trial.daysLeft;
|
|
245
255
|
|
package/src/manager/index.js
CHANGED
|
@@ -730,6 +730,47 @@ Manager.prototype.storage = function (options) {
|
|
|
730
730
|
return self._internal.storage[options.name]
|
|
731
731
|
};
|
|
732
732
|
|
|
733
|
+
Manager.prototype.install = function (controller, options) {
|
|
734
|
+
const self = this;
|
|
735
|
+
|
|
736
|
+
// Set options defaults
|
|
737
|
+
options = options || {};
|
|
738
|
+
options.prefix = typeof options.prefix === 'undefined' ? null : options.prefix;
|
|
739
|
+
options.dir = typeof options.dir === 'undefined' ? '' : options.dir;
|
|
740
|
+
options.log = typeof options.log === 'undefined' ? false : options.log;
|
|
741
|
+
|
|
742
|
+
// Fix dir
|
|
743
|
+
options.dir = path.resolve(self.cwd, options.dir);
|
|
744
|
+
|
|
745
|
+
// If dir is a single file, install it. if its a directory, install all
|
|
746
|
+
const isDirectory = jetpack.exists(options.dir) === 'dir';
|
|
747
|
+
|
|
748
|
+
if (options.log) {
|
|
749
|
+
self.assistant.log(`Installing from ${options.dir}, prefix=${options.prefix}, isDirectory=${isDirectory}...`);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
function _install(prefix, file) {
|
|
753
|
+
if (!file.includes('.js')) {return}
|
|
754
|
+
const name = file.replace('.js', '');
|
|
755
|
+
const _prefix = prefix ? `${prefix}_${name}` : name;
|
|
756
|
+
|
|
757
|
+
const fullPath = path.resolve(options.dir, file);
|
|
758
|
+
|
|
759
|
+
if (options.log) {
|
|
760
|
+
self.assistant.log(`Installing ${_prefix} from ${fullPath}...`);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
controller[`${_prefix}`] = require(fullPath);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (isDirectory) {
|
|
767
|
+
jetpack.list(options.dir)
|
|
768
|
+
.forEach(file => _install(options.prefix, file))
|
|
769
|
+
} else {
|
|
770
|
+
_install(options.prefix, options.dir);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
|
|
733
774
|
Manager.prototype.require = function (p) {
|
|
734
775
|
return require(p);
|
|
735
776
|
};
|