backend-manager 3.1.4 → 3.1.7
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
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const path = require('path');
|
|
7
|
+
const powertools = require('node-powertools');
|
|
7
8
|
|
|
8
9
|
function Middleware(m) {
|
|
9
10
|
const self = this;
|
|
@@ -27,16 +28,20 @@ Middleware.prototype.run = function (library, req, res, options) {
|
|
|
27
28
|
options = options || {};
|
|
28
29
|
options.setupAnalytics = typeof options.setupAnalytics === 'boolean' ? options.setupAnalytics : true;
|
|
29
30
|
options.setupUsage = typeof options.setupUsage === 'boolean' ? options.setupUsage : true;
|
|
31
|
+
options.authenticate = typeof options.authenticate === 'boolean' ? options.authenticate : true;
|
|
32
|
+
options.setupSettings = typeof options.setupSettings === 'undefined' ? true : options.setupSettings;
|
|
30
33
|
|
|
31
34
|
// Log
|
|
32
35
|
assistant.log(`Middleware.process(): Request (${geolocation.ip} @ ${geolocation.country}, ${geolocation.region}, ${geolocation.city})`, JSON.stringify(data));
|
|
33
36
|
|
|
37
|
+
const basePath = path.resolve(process.cwd(), `methods/${library.replace('.js', '')}`);
|
|
38
|
+
|
|
34
39
|
// Load library
|
|
35
40
|
try {
|
|
36
|
-
library = path.resolve(
|
|
41
|
+
library = path.resolve(basePath, `index.js`);
|
|
37
42
|
library = new (require(library))();
|
|
38
43
|
} catch (e) {
|
|
39
|
-
assistant.errorify(`Unable to load library @ (${library}): ${e.message}`, {sentry: true, send: true, log: true});
|
|
44
|
+
return assistant.errorify(`Unable to load library @ (${library}): ${e.message}`, {sentry: true, send: true, log: true});
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
// Setup usage
|
|
@@ -44,6 +49,11 @@ Middleware.prototype.run = function (library, req, res, options) {
|
|
|
44
49
|
assistant.usage = await Manager.Usage().init(assistant);
|
|
45
50
|
}
|
|
46
51
|
|
|
52
|
+
// Setup user
|
|
53
|
+
if (!options.setupUsage && options.authenticate) {
|
|
54
|
+
await assistant.authenticate();
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
// Setup analytics
|
|
48
58
|
if (options.setupAnalytics) {
|
|
49
59
|
const uuid = assistant?.usage?.user?.auth?.uid
|
|
@@ -56,6 +66,18 @@ Middleware.prototype.run = function (library, req, res, options) {
|
|
|
56
66
|
})
|
|
57
67
|
}
|
|
58
68
|
|
|
69
|
+
// Resolve settings
|
|
70
|
+
if (options.setupSettings) {
|
|
71
|
+
// try {
|
|
72
|
+
// const planId = assistant.request.user.plan.id;
|
|
73
|
+
// let settings = path.resolve(basePath, `settings.js`);
|
|
74
|
+
// settings = require(settings)(assistant)[planId];
|
|
75
|
+
// assistant.request.data = powertools.defaults(data, settings);
|
|
76
|
+
// } catch (e) {
|
|
77
|
+
// return assistant.errorify(`Unable to resolve settings @ (${library}): ${e.message}`, {sentry: true, send: true, log: true});
|
|
78
|
+
// }
|
|
79
|
+
}
|
|
80
|
+
|
|
59
81
|
// Process
|
|
60
82
|
try {
|
|
61
83
|
// Set properties
|
|
@@ -68,10 +90,10 @@ Middleware.prototype.run = function (library, req, res, options) {
|
|
|
68
90
|
// return res.status(200).json(result);
|
|
69
91
|
// })
|
|
70
92
|
.catch(e => {
|
|
71
|
-
assistant.errorify(e, {sentry: true, send: true, log: true});
|
|
93
|
+
return assistant.errorify(e, {sentry: true, send: true, log: true});
|
|
72
94
|
});
|
|
73
95
|
} catch (e) {
|
|
74
|
-
assistant.errorify(e, {sentry: true, send: true, log: true});
|
|
96
|
+
return assistant.errorify(e, {sentry: true, send: true, log: true});
|
|
75
97
|
}
|
|
76
98
|
});
|
|
77
99
|
};
|
|
@@ -12,7 +12,7 @@ function Settings(m) {
|
|
|
12
12
|
self.initialized = false;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
Settings.prototype.
|
|
15
|
+
Settings.prototype.resolve = function (assistant, options) {
|
|
16
16
|
const self = this;
|
|
17
17
|
|
|
18
18
|
return new Promise(async function(resolve, reject) {
|