@momsfriendlydevco/cowboy 1.0.11 → 1.0.14

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/lib/request.js CHANGED
@@ -73,7 +73,7 @@ export default class CowboyRequest {
73
73
  * @returns {Promise} A promise which will resolve when the body has been parsed
74
74
  */
75
75
  async parseBody(forceType) {
76
- let type = (forceType || this.headers['content-type'])
76
+ let type = (forceType || this.headers['content-type'] || '')
77
77
  .replace(/^([a-z\-\/]+).*$/, '$1'); // Scrap everything after the mime
78
78
 
79
79
  switch (type) {
@@ -107,7 +107,7 @@ export default class CowboyRequest {
107
107
  throw new Error('Invalid text body');
108
108
  }
109
109
  default:
110
- debug('EMPTY BODY PAYLOAD');
110
+ debug('Empty Body Payload');
111
111
  this.body = {};
112
112
  }
113
113
  }
@@ -1,10 +1,15 @@
1
1
  import joyful from '@momsfriendlydevco/joyful';
2
2
 
3
+ /**
4
+ * Run a Joi / Joyful validation function against a specific subkey within `req
5
+ *
6
+ * @param {String} subkey The subkey to run against
7
+ * @param {Function|Object} Callback to use with Joyful to validate with
8
+ * @returns {Void} Either a successful middleware cycle (if validatio succeeds) or a call to `res.status(400)` if failed
9
+ */
3
10
  export default function CowboyMiddlewareValidate(subkey, validator) {
4
11
  return (req, res) => {
5
- let joyfulResult = joyful({
6
- [subkey]: validator,
7
- });
12
+ let joyfulResult = joyful(req[subkey], validator);
8
13
 
9
14
  if (joyfulResult !== true) { // Failed body validation?
10
15
  return res
@@ -1,7 +1,5 @@
1
1
  import CowboyMiddlewareValidate from '#middleware/validate';
2
2
 
3
3
  export default function CowboyMiddlewareValidateBody(validator) {
4
- return CowboyMiddlewareValidate('body', {
5
- body: validator,
6
- })
4
+ return CowboyMiddlewareValidate('body', validator);
7
5
  }
@@ -1,7 +1,5 @@
1
1
  import CowboyMiddlewareValidate from '#middleware/validate';
2
2
 
3
3
  export default function CowboyMiddlewareValidateParams(validator) {
4
- return CowboyMiddlewareValidate('params', {
5
- params: validator,
6
- })
4
+ return CowboyMiddlewareValidate('params', validator);
7
5
  }
@@ -1,7 +1,5 @@
1
1
  import CowboyMiddlewareValidate from '#middleware/validate';
2
2
 
3
3
  export default function CowboyMiddlewareValidateQuery(validator) {
4
- return CowboyMiddlewareValidate('query', {
5
- query: validator,
6
- })
4
+ return CowboyMiddlewareValidate('query', validator);
7
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momsfriendlydevco/cowboy",
3
- "version": "1.0.11",
3
+ "version": "1.0.14",
4
4
  "description": "Wrapper around Cloudflare Wrangler to provide a more Express-like experience",
5
5
  "scripts": {
6
6
  "lint": "eslint ."