backend-manager 3.2.114 → 3.2.115
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 +1 -1
- package/src/manager/helpers/assistant.js +19 -6
- package/src/manager/index.js +8 -23
package/package.json
CHANGED
|
@@ -139,8 +139,16 @@ BackendAssistant.prototype.init = function (ref, options) {
|
|
|
139
139
|
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-CH-UA
|
|
140
140
|
*/
|
|
141
141
|
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
// Set request type
|
|
143
|
+
if (
|
|
144
|
+
self.ref.req.xhr || (self.ref.req?.headers?.accept || '').includes('json')
|
|
145
|
+
|| (self.ref.req?.headers?.['content-type'] || '').includes('json')
|
|
146
|
+
) {
|
|
147
|
+
self.request.type = 'ajax';
|
|
148
|
+
} else {
|
|
149
|
+
self.request.type = 'form';
|
|
150
|
+
}
|
|
151
|
+
self.request.path = self.ref.req.path || '';
|
|
144
152
|
self.request.user = self.resolveAccount({authenticated: false});
|
|
145
153
|
|
|
146
154
|
// Set body and query
|
|
@@ -602,8 +610,8 @@ BackendAssistant.prototype.authenticate = async function (options) {
|
|
|
602
610
|
// Check with custom BEM Token
|
|
603
611
|
let storedApiKey;
|
|
604
612
|
try {
|
|
605
|
-
const workingConfig =
|
|
606
|
-
storedApiKey =
|
|
613
|
+
const workingConfig = self.Manager?.config || functions.config();
|
|
614
|
+
const storedApiKey = workingConfig?.backend_manager?.key || '';
|
|
607
615
|
} catch (e) {
|
|
608
616
|
|
|
609
617
|
}
|
|
@@ -875,13 +883,18 @@ BackendAssistant.prototype.parseMultipartFormData = function (options) {
|
|
|
875
883
|
return reject(new Error('Cannot run .parseMultipartForm() until .init() has been called'));
|
|
876
884
|
}
|
|
877
885
|
const existingData = self.request.multipartData;
|
|
878
|
-
|
|
879
|
-
|
|
886
|
+
const getFields = existingData?.fields || {};
|
|
887
|
+
const getFiles = existingData?.files || {};
|
|
888
|
+
|
|
889
|
+
// If there are already fields or files, return them
|
|
890
|
+
if (Object.keys(getFields).length + Object.keys(getFiles).length > 0) {
|
|
880
891
|
return resolve(existingData);
|
|
881
892
|
}
|
|
882
893
|
|
|
894
|
+
// Set options
|
|
883
895
|
options = options || {};
|
|
884
896
|
|
|
897
|
+
// Set headers
|
|
885
898
|
const fs = require('fs');
|
|
886
899
|
const req = self.ref.req;
|
|
887
900
|
const res = self.ref.res;
|
package/src/manager/index.js
CHANGED
|
@@ -50,6 +50,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
50
50
|
options.setupFunctions = typeof options.setupFunctions === 'undefined' ? true : options.setupFunctions;
|
|
51
51
|
options.setupFunctionsLegacy = typeof options.setupFunctionsLegacy === 'undefined' ? false : options.setupFunctionsLegacy;
|
|
52
52
|
options.setupFunctionsIdentity = typeof options.setupFunctionsIdentity === 'undefined' ? true : options.setupFunctionsIdentity;
|
|
53
|
+
options.setupServer = typeof options.setupServer === 'undefined' ? true : options.setupServer;
|
|
53
54
|
options.initializeLocalStorage = typeof options.initializeLocalStorage === 'undefined' ? false : options.initializeLocalStorage;
|
|
54
55
|
options.resourceZone = typeof options.resourceZone === 'undefined' ? 'us-central1' : options.resourceZone;
|
|
55
56
|
options.sentry = typeof options.sentry === 'undefined' ? true : options.sentry;
|
|
@@ -67,7 +68,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
67
68
|
// Load libraries
|
|
68
69
|
self.libraries = {
|
|
69
70
|
// Third-party
|
|
70
|
-
functions: require('firebase-functions'),
|
|
71
|
+
functions: options.projectType === 'firebase' ? require('firebase-functions') : null,
|
|
71
72
|
admin: require('firebase-admin'),
|
|
72
73
|
cors: require('cors')({ origin: true }),
|
|
73
74
|
sentry: null,
|
|
@@ -92,7 +93,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
92
93
|
self.package = resolveProjectPackage();
|
|
93
94
|
self.config = merge(
|
|
94
95
|
requireJSON5(self.project.backendManagerConfigPath),
|
|
95
|
-
self.libraries.functions.config()
|
|
96
|
+
self.libraries.functions ? self.libraries.functions.config() : {}
|
|
96
97
|
);
|
|
97
98
|
|
|
98
99
|
// Saved config
|
|
@@ -224,7 +225,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
224
225
|
}
|
|
225
226
|
|
|
226
227
|
// Setup custom server
|
|
227
|
-
if (options.projectType === 'custom') {
|
|
228
|
+
if (options.projectType === 'custom' && options.setupServer) {
|
|
228
229
|
self.setupCustomServer(exporter, options);
|
|
229
230
|
}
|
|
230
231
|
|
|
@@ -356,8 +357,12 @@ Manager.prototype._preProcess = function (mod) {
|
|
|
356
357
|
|
|
357
358
|
Manager.prototype.Assistant = function(ref, options) {
|
|
358
359
|
const self = this;
|
|
360
|
+
|
|
361
|
+
// Set options defaults
|
|
359
362
|
ref = ref || {};
|
|
360
363
|
options = options || {};
|
|
364
|
+
|
|
365
|
+
// Create assistant instance
|
|
361
366
|
return (new self.libraries.Assistant()).init({
|
|
362
367
|
req: ref.req,
|
|
363
368
|
res: ref.res,
|
|
@@ -365,26 +370,6 @@ Manager.prototype.Assistant = function(ref, options) {
|
|
|
365
370
|
functions: self.libraries.functions,
|
|
366
371
|
Manager: self,
|
|
367
372
|
}, options)
|
|
368
|
-
// return (new self.libraries.Assistant()).init({
|
|
369
|
-
// req: ref.req,
|
|
370
|
-
// res: ref.res,
|
|
371
|
-
// admin: self.libraries.admin,
|
|
372
|
-
// functions: self.libraries.functions,
|
|
373
|
-
// Manager: self,
|
|
374
|
-
// }, {
|
|
375
|
-
// accept: options.accept,
|
|
376
|
-
// functionName: options.functionName,
|
|
377
|
-
// functionType: options.functionType,
|
|
378
|
-
// })
|
|
379
|
-
// self._inner.ip = (!self._inner.ip || self._inner.ip === '127.0.0.1') ? ass.request.ip : self._inner.ip;
|
|
380
|
-
// self._inner.country = self._inner.country || ass.request.country;
|
|
381
|
-
// self._inner.referrer = self._inner.referrer || ass.request.referrer;
|
|
382
|
-
// self._inner.userAgent = (!self._inner.userAgent || self._inner.userAgent === 'empty') ? ass.request.userAgent : self._inner.userAgent;
|
|
383
|
-
// self._inner.name = self._inner.name || ass.meta.name;
|
|
384
|
-
// if (ref.req) {
|
|
385
|
-
// console.log('ref.req.headers', ref.req.headers);
|
|
386
|
-
// }
|
|
387
|
-
// console.log('self._inner', self._inner);
|
|
388
373
|
};
|
|
389
374
|
|
|
390
375
|
Manager.prototype.User = function () {
|