backend-manager 4.0.31 → 4.1.0
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
|
@@ -113,6 +113,7 @@ BackendAssistant.prototype.init = function (ref, options) {
|
|
|
113
113
|
self.analytics = null;
|
|
114
114
|
self.usage = null;
|
|
115
115
|
self.settings = null;
|
|
116
|
+
self.schema = null;
|
|
116
117
|
|
|
117
118
|
// Set meta
|
|
118
119
|
self.meta = {};
|
|
@@ -251,12 +252,6 @@ BackendAssistant.prototype.init = function (ref, options) {
|
|
|
251
252
|
self.constant.pastTime.timestamp = '1999-01-01T00:00:00Z';
|
|
252
253
|
self.constant.pastTime.timestampUNIX = 915148800;
|
|
253
254
|
|
|
254
|
-
// Schema
|
|
255
|
-
// self.schema = {
|
|
256
|
-
// dir: '',
|
|
257
|
-
// name: '',
|
|
258
|
-
// }
|
|
259
|
-
|
|
260
255
|
// Log options
|
|
261
256
|
if (
|
|
262
257
|
(self.isDevelopment())
|
|
@@ -568,9 +563,10 @@ function _attachHeaderProperties(self, options, error) {
|
|
|
568
563
|
code: options.code,
|
|
569
564
|
tag: self.tag,
|
|
570
565
|
usage: {
|
|
571
|
-
current: self
|
|
572
|
-
limits: self
|
|
566
|
+
current: self.usage ? self.usage.getUsage() : {},
|
|
567
|
+
limits: self.usage ? self.usage.getLimit() : {},
|
|
573
568
|
},
|
|
569
|
+
schema: self.schema || {},
|
|
574
570
|
additional: options.additional || {},
|
|
575
571
|
}
|
|
576
572
|
const req = self.ref.req;
|
|
@@ -582,9 +578,10 @@ function _attachHeaderProperties(self, options, error) {
|
|
|
582
578
|
|
|
583
579
|
// Add bm-properties to Access-Control-Expose-Headers
|
|
584
580
|
const existingExposed = res.get('Access-Control-Expose-Headers') || '';
|
|
585
|
-
const newExposed = `${existingExposed}, bm-properties`.replace(/^, /, '');
|
|
586
581
|
|
|
582
|
+
// If it does not exist, add it
|
|
587
583
|
if (!existingExposed.match(/bm-properties/i)) {
|
|
584
|
+
const newExposed = `${existingExposed}, bm-properties`.replace(/^, /, '');
|
|
588
585
|
res.header('Access-Control-Expose-Headers', newExposed);
|
|
589
586
|
}
|
|
590
587
|
}
|
|
@@ -722,15 +719,21 @@ BackendAssistant.prototype.resolveAccount = function (user) {
|
|
|
722
719
|
|
|
723
720
|
BackendAssistant.prototype.parseRepo = function (repo) {
|
|
724
721
|
let repoSplit = repo.split('/');
|
|
722
|
+
|
|
723
|
+
// Remove .git from the end
|
|
725
724
|
for (var i = 0; i < repoSplit.length; i++) {
|
|
726
725
|
repoSplit[i] = repoSplit[i].replace('.git', '');
|
|
727
726
|
}
|
|
727
|
+
|
|
728
|
+
// Remove unnecessary parts
|
|
728
729
|
repoSplit = repoSplit.filter(function(value, index, arr){
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
730
|
+
return value !== 'http:'
|
|
731
|
+
&& value !== 'https:'
|
|
732
|
+
&& value !== ''
|
|
733
|
+
&& value !== 'github.com';
|
|
733
734
|
});
|
|
735
|
+
|
|
736
|
+
// Return
|
|
734
737
|
return {
|
|
735
738
|
user: repoSplit[0],
|
|
736
739
|
name: repoSplit[1],
|
|
@@ -28,6 +28,7 @@ Middleware.prototype.run = function (libPath, options) {
|
|
|
28
28
|
const assistant = Manager.Assistant({req: req, res: res});
|
|
29
29
|
|
|
30
30
|
const data = assistant.request.data;
|
|
31
|
+
const headers = assistant.request.headers;
|
|
31
32
|
const geolocation = assistant.request.geolocation;
|
|
32
33
|
const client = assistant.request.client;
|
|
33
34
|
|
|
@@ -47,6 +48,7 @@ Middleware.prototype.run = function (libPath, options) {
|
|
|
47
48
|
|
|
48
49
|
// Log
|
|
49
50
|
assistant.log(`Middleware.process(): Request (${geolocation.ip} @ ${geolocation.country}, ${geolocation.region}, ${geolocation.city})`, JSON.stringify(data));
|
|
51
|
+
assistant.log(`Middleware.process(): Headers`, JSON.stringify(headers));
|
|
50
52
|
|
|
51
53
|
// Set paths
|
|
52
54
|
const routesDir = path.resolve(options.routesDir, libPath.replace('.js', ''));
|
|
@@ -118,7 +120,7 @@ Middleware.prototype.run = function (libPath, options) {
|
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
// Log
|
|
121
|
-
assistant.log(`Middleware.process(): Resolved settings with schema
|
|
123
|
+
assistant.log(`Middleware.process(): Resolved settings with schema=${options.schema}`, JSON.stringify(assistant.settings));
|
|
122
124
|
} else {
|
|
123
125
|
assistant.settings = data;
|
|
124
126
|
}
|
|
@@ -47,13 +47,16 @@ Settings.prototype.resolve = function (assistant, schema, settings, options) {
|
|
|
47
47
|
schema = loadSchema(assistant, schemaPath, settings, options);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// Resolve settings
|
|
51
|
-
self.settings = powertools.defaults(settings, schema);
|
|
52
|
-
|
|
53
50
|
// If schema is not an object, throw an error
|
|
54
51
|
if (!schema || typeof schema !== 'object') {
|
|
55
52
|
throw assistant.errorify(`Invalid schema provided`, {code: 400});
|
|
56
53
|
}
|
|
54
|
+
|
|
55
|
+
// Resolve settings
|
|
56
|
+
self.settings = powertools.defaults(settings, schema);
|
|
57
|
+
// self.schema = _.merge({}, schema);
|
|
58
|
+
const resolvedSchema = {};
|
|
59
|
+
|
|
57
60
|
// console.log('---schema', schema);
|
|
58
61
|
// console.log('---options', options);
|
|
59
62
|
// console.log('---self.settings', self.settings);
|
|
@@ -99,8 +102,27 @@ Settings.prototype.resolve = function (assistant, schema, settings, options) {
|
|
|
99
102
|
assistant.warn(`Replacing ${path}: originalValue=${originalValue}, resolvedValue=${resolvedValue}, replaceValue=${replaceValue}`);
|
|
100
103
|
_.set(self.settings, path, replaceValue);
|
|
101
104
|
}
|
|
105
|
+
|
|
106
|
+
// Set defaults
|
|
107
|
+
// @@@TODO: FINISH THIS
|
|
108
|
+
// !!! NOT SURE WHAT TO DO FOR DEFAULT SINCE IT CAN BE A FN SOMETIMES ???
|
|
109
|
+
const resolvedNode = {
|
|
110
|
+
types: schemaNode.types || [],
|
|
111
|
+
// value: typeof replaceValue === 'undefined' ? undefined : replaceValue,
|
|
112
|
+
// default: ???,
|
|
113
|
+
required: isRequired,
|
|
114
|
+
available: typeof schemaNode.available === 'undefined' ? true : schemaNode.available,
|
|
115
|
+
min: typeof schemaNode.min === 'undefined' ? undefined : schemaNode.min,
|
|
116
|
+
max: typeof schemaNode.max === 'undefined' ? undefined : schemaNode.max,
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Update schema
|
|
120
|
+
_.set(resolvedSchema, path, resolvedNode);
|
|
102
121
|
});
|
|
103
122
|
|
|
123
|
+
// Set schema
|
|
124
|
+
self.schema = resolvedSchema;
|
|
125
|
+
|
|
104
126
|
// Resolve
|
|
105
127
|
return self.settings;
|
|
106
128
|
};
|
|
@@ -54,8 +54,10 @@ Utilities.prototype.iterateCollection = function (callback, options) {
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
// Insert orderBy
|
|
57
|
-
if (options.orderBy) {
|
|
57
|
+
if (typeof options.orderBy === 'string') {
|
|
58
58
|
query = query.orderBy(options.orderBy);
|
|
59
|
+
} else if (options.orderBy && typeof options.orderBy === 'object') {
|
|
60
|
+
query = query.orderBy(options.orderBy.field, options.orderBy.direction);
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
// Process the first batch differently
|