mythix 2.4.7 → 2.4.10

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": "mythix",
3
- "version": "2.4.7",
3
+ "version": "2.4.10",
4
4
  "description": "Mythix is a NodeJS web-app framework",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  "express": "^4.17.3",
31
31
  "express-busboy": "github:th317erd/express-busboy#0754a570d7979097b31e48655b80d3fcd628d4e4",
32
32
  "form-data": "^4.0.0",
33
- "mythix-orm": "^1.5.1",
33
+ "mythix-orm": "^1.5.2",
34
34
  "nife": "^1.11.3",
35
35
  "prompts": "^2.4.2"
36
36
  }
@@ -367,8 +367,9 @@ function spawnCommand(args, options, _config) {
367
367
  });
368
368
  }
369
369
 
370
- async function executeCommand(configPath, applicationCommandsPath, yargsPath, simpleYargsPath, argv, commandPath, command, config) {
370
+ async function executeCommand(configPath, applicationCommandsPath, yargsPath, simpleYargsPath, argv, commandPath, command, _config) {
371
371
  try {
372
+ let config = _config || {};
372
373
  let Klass = CommandBase.commands[command];
373
374
  let nodeArguments = ((config.runtime || 'node') === 'node') ? (Klass.nodeArguments || []) : [];
374
375
  let args = nodeArguments.concat([ commandPath ], argv);
@@ -83,12 +83,18 @@ function nodeRequestHandler(routeName, requestOptions) {
83
83
  },
84
84
  requestOptions,
85
85
  extraConfig,
86
- { headers: Object.assign({}, headers, Utils.keysToLowerCase(extraConfig.headers || {})) },
86
+ {
87
+ headers: Utils.cleanObjectProperties(Object.assign(
88
+ {},
89
+ headers,
90
+ Utils.keysToLowerCase(extraConfig.headers || {})
91
+ )),
92
+ },
87
93
  );
88
94
 
89
95
  delete options.data;
90
96
 
91
- var thisRequest = HTTP.request(options, function(response) {
97
+ var thisRequest = HTTP.request(Utils.cleanObjectProperties(options), function(response) {
92
98
  var responseData = Buffer.alloc(0);
93
99
 
94
100
  response.on('data', function(chunk) {
@@ -172,7 +178,7 @@ function browserRequestHandler(routeName, requestOptions) {
172
178
  var url = requestOptions.url;
173
179
  var data = requestOptions.data;
174
180
  var extraConfig = {};
175
- var headers = Object.assign({ 'content-type': 'application/json; charset=UTF-8' }, Utils.keysToLowerCase(this.defaultHeaders || {}), Utils.keysToLowerCase(requestOptions.headers || {}));
181
+ var headers = Object.assign(Utils.keysToLowerCase(this.defaultHeaders || {}), Utils.keysToLowerCase(requestOptions.headers || {}));
176
182
 
177
183
  if (data) {
178
184
  if (!method.match(/^(GET|HEAD)$/i)) {
@@ -193,12 +199,18 @@ function browserRequestHandler(routeName, requestOptions) {
193
199
  { method },
194
200
  requestOptions,
195
201
  extraConfig,
196
- { headers: Object.assign({}, headers, Utils.keysToLowerCase(extraConfig.headers || {})) },
202
+ {
203
+ headers: Utils.cleanObjectProperties(Object.assign(
204
+ {},
205
+ headers,
206
+ Utils.keysToLowerCase(extraConfig.headers || {})
207
+ )),
208
+ },
197
209
  );
198
210
 
199
211
  delete options.data;
200
212
 
201
- globalScope.fetch(url, options).then(
213
+ globalScope.fetch(url, Utils.cleanObjectProperties(options)).then(
202
214
  function(response) {
203
215
  if (typeof requestOptions.responseHandler === 'function')
204
216
  return requestOptions.responseHandler(response);
@@ -271,6 +283,22 @@ function generateUtils() {
271
283
  return newObj;
272
284
  }
273
285
 
286
+ function cleanObjectProperties(obj) {
287
+ var keys = Object.keys(obj || {});
288
+ var newObj = {};
289
+
290
+ for (var i = 0, il = keys.length; i < il; i++) {
291
+ var key = keys[i];
292
+ var value = obj[key];
293
+ if (value == null || value == '')
294
+ continue;
295
+
296
+ newObj[key] = value;
297
+ }
298
+
299
+ return newObj;
300
+ }
301
+
274
302
  function injectURLParams(routeName, _options) {
275
303
  var options = _options || {};
276
304
  var params = options.params || {};
@@ -299,6 +327,7 @@ function generateUtils() {
299
327
  isEmpty,
300
328
  dataToQueryString,
301
329
  keysToLowerCase,
330
+ cleanObjectProperties,
302
331
  injectURLParams,
303
332
  };
304
333
  })();
@@ -350,11 +379,15 @@ function generateRoutes(_routes, _options) {
350
379
  contentType = contentType[0];
351
380
 
352
381
  clientOptions = {
353
- credentials: 'same-origin',
354
- headers: {
355
- 'Content-Type': contentType,
356
- },
382
+ credentials: 'same-origin',
357
383
  };
384
+
385
+ // Don't set content type for multipart/form-data
386
+ if (!(/multipart\/form-data/i).test(contentType)) {
387
+ clientOptions.headers = {
388
+ 'Content-Type': contentType,
389
+ };
390
+ }
358
391
  }
359
392
 
360
393
  clientOptions = JSON.stringify(clientOptions, (key, value) => {