node-server-engine 2.2.0 → 2.3.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/README.md CHANGED
@@ -238,6 +238,8 @@ The main function of the endpoint is called the **handler**. This function shoul
238
238
 
239
239
  An endpoint usually has a **validator**. A validator is a schema that will be compared to the incoming request. The request will be denied if it contains illegal or malformed arguments. For more detail see the documentation of the underlying package [express-validator](https://express-validator.github.io/docs/schema-validation.html).
240
240
 
241
+ A request that fails validation is answered `400` with `errorCode: 'invalid-request'` and `details`, one entry per failed field: `{ field, location, message }` (the submitted values are not echoed back).
242
+
241
243
  ```javascript
242
244
  import { Endpoint, EndpointMethod } from 'node-server-engine';
243
245
 
@@ -29,13 +29,22 @@ let ValidationError = exports.ValidationError = /*#__PURE__*/function (_WebError
29
29
  ...hint,
30
30
  [error.type]: error.msg
31
31
  }), {});
32
+ // Which fields failed and why, so a client can point at them. The submitted values are left out.
33
+ const details = errors.map(error => error.type === 'field' ? {
34
+ field: error.path,
35
+ location: error.location,
36
+ message: error.msg
37
+ } : {
38
+ message: error.msg
39
+ });
32
40
  return _callSuper(this, ValidationError, [{
33
41
  message: 'Request did not pass validation',
34
42
  errorCode: 'invalid-request',
35
43
  statusCode: 400,
36
44
  severity: _const.LogSeverity.WARNING,
37
45
  data: hint,
38
- hint
46
+ hint,
47
+ details
39
48
  }]);
40
49
  }
41
50
  (0, _inherits2.default)(ValidationError, _WebError);
@@ -1 +1 @@
1
- {"version":3,"file":"ValidationError.js","names":["_const","require","_EngineError","_WebError2","_callSuper","t","o","e","_getPrototypeOf2","default","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","ValidationError","exports","_WebError","validationResult","_classCallCheck2","isEmpty","EngineError","message","errors","array","hint","reduce","error","type","msg","errorCode","statusCode","severity","LogSeverity","WARNING","data","_inherits2","_createClass2","WebError"],"sources":["../../../src/entities/ValidationError/ValidationError.ts"],"sourcesContent":["import {\n ValidationError as ExpressValidationError,\n Result\n} from 'express-validator';\nimport { LogSeverity } from 'const';\nimport { EngineError } from 'entities/EngineError';\nimport { WebError } from 'entities/WebError';\n\n/** Error class for request/message validation errors */\nexport class ValidationError extends WebError {\n /** Create an ValidationError this represents errors in parsing incoming messages/requests */\n public constructor(validationResult: Result<ExpressValidationError>) {\n if (validationResult.isEmpty())\n throw new EngineError({\n message:\n 'Attempted to create a validation error while validation was successful'\n });\n\n const errors = validationResult.array();\n // Hint that is sent to the client as logged as data\n const hint = errors.reduce(\n (hint, error) => ({ ...hint, [error.type]: error.msg as string }),\n {}\n );\n super({\n message: 'Request did not pass validation',\n errorCode: 'invalid-request',\n statusCode: 400,\n severity: LogSeverity.WARNING,\n data: hint,\n hint\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAA6C,SAAAG,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,CAAAC,OAAA,EAAAH,CAAA,OAAAI,2BAAA,CAAAD,OAAA,EAAAJ,CAAA,EAAAM,yBAAA,KAAAC,OAAA,CAAAC,SAAA,CAAAP,CAAA,EAAAC,CAAA,YAAAC,gBAAA,CAAAC,OAAA,EAAAJ,CAAA,EAAAS,WAAA,IAAAR,CAAA,CAAAS,KAAA,CAAAV,CAAA,EAAAE,CAAA;AAAA,SAAAI,0BAAA,cAAAN,CAAA,IAAAW,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAP,OAAA,CAAAC,SAAA,CAAAG,OAAA,iCAAAX,CAAA,aAAAM,yBAAA,YAAAA,CAAA,aAAAN,CAAA;AAE7C;AAAA,IACae,eAAe,GAAAC,OAAA,CAAAD,eAAA,0BAAAE,SAAA;EAC1B;EACA,SAAAF,gBAAmBG,gBAAgD,EAAE;IAAA,IAAAC,gBAAA,CAAAf,OAAA,QAAAW,eAAA;IACnE,IAAIG,gBAAgB,CAACE,OAAO,CAAC,CAAC,EAC5B,MAAM,IAAIC,wBAAW,CAAC;MACpBC,OAAO,EACL;IACJ,CAAC,CAAC;IAEJ,MAAMC,MAAM,GAAGL,gBAAgB,CAACM,KAAK,CAAC,CAAC;IACvC;IACA,MAAMC,IAAI,GAAGF,MAAM,CAACG,MAAM,CACxB,CAACD,IAAI,EAAEE,KAAK,MAAM;MAAE,GAAGF,IAAI;MAAE,CAACE,KAAK,CAACC,IAAI,GAAGD,KAAK,CAACE;IAAc,CAAC,CAAC,EACjE,CAAC,CACH,CAAC;IAAC,OAAA9B,UAAA,OAAAgB,eAAA,GACI;MACJO,OAAO,EAAE,iCAAiC;MAC1CQ,SAAS,EAAE,iBAAiB;MAC5BC,UAAU,EAAE,GAAG;MACfC,QAAQ,EAAEC,kBAAW,CAACC,OAAO;MAC7BC,IAAI,EAAEV,IAAI;MACVA;IACF,CAAC;EACH;EAAC,IAAAW,UAAA,CAAAhC,OAAA,EAAAW,eAAA,EAAAE,SAAA;EAAA,WAAAoB,aAAA,CAAAjC,OAAA,EAAAW,eAAA;AAAA,EAvBkCuB,mBAAQ","ignoreList":[]}
1
+ {"version":3,"file":"ValidationError.js","names":["_const","require","_EngineError","_WebError2","_callSuper","t","o","e","_getPrototypeOf2","default","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","ValidationError","exports","_WebError","validationResult","_classCallCheck2","isEmpty","EngineError","message","errors","array","hint","reduce","error","type","msg","details","map","field","path","location","errorCode","statusCode","severity","LogSeverity","WARNING","data","_inherits2","_createClass2","WebError"],"sources":["../../../src/entities/ValidationError/ValidationError.ts"],"sourcesContent":["import {\n ValidationError as ExpressValidationError,\n Result\n} from 'express-validator';\nimport { LogSeverity } from 'const';\nimport { EngineError } from 'entities/EngineError';\nimport { WebError } from 'entities/WebError';\n\n/** Error class for request/message validation errors */\nexport class ValidationError extends WebError {\n /** Create an ValidationError this represents errors in parsing incoming messages/requests */\n public constructor(validationResult: Result<ExpressValidationError>) {\n if (validationResult.isEmpty())\n throw new EngineError({\n message:\n 'Attempted to create a validation error while validation was successful'\n });\n\n const errors = validationResult.array();\n // Hint that is sent to the client as logged as data\n const hint = errors.reduce(\n (hint, error) => ({ ...hint, [error.type]: error.msg as string }),\n {}\n );\n // Which fields failed and why, so a client can point at them. The submitted values are left out.\n const details = errors.map((error) =>\n error.type === 'field'\n ? {\n field: error.path,\n location: error.location,\n message: error.msg as string\n }\n : { message: error.msg as string }\n );\n super({\n message: 'Request did not pass validation',\n errorCode: 'invalid-request',\n statusCode: 400,\n severity: LogSeverity.WARNING,\n data: hint,\n hint,\n details\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAIA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAA6C,SAAAG,WAAAC,CAAA,EAAAC,CAAA,EAAAC,CAAA,WAAAD,CAAA,OAAAE,gBAAA,CAAAC,OAAA,EAAAH,CAAA,OAAAI,2BAAA,CAAAD,OAAA,EAAAJ,CAAA,EAAAM,yBAAA,KAAAC,OAAA,CAAAC,SAAA,CAAAP,CAAA,EAAAC,CAAA,YAAAC,gBAAA,CAAAC,OAAA,EAAAJ,CAAA,EAAAS,WAAA,IAAAR,CAAA,CAAAS,KAAA,CAAAV,CAAA,EAAAE,CAAA;AAAA,SAAAI,0BAAA,cAAAN,CAAA,IAAAW,OAAA,CAAAC,SAAA,CAAAC,OAAA,CAAAC,IAAA,CAAAP,OAAA,CAAAC,SAAA,CAAAG,OAAA,iCAAAX,CAAA,aAAAM,yBAAA,YAAAA,CAAA,aAAAN,CAAA;AAE7C;AAAA,IACae,eAAe,GAAAC,OAAA,CAAAD,eAAA,0BAAAE,SAAA;EAC1B;EACA,SAAAF,gBAAmBG,gBAAgD,EAAE;IAAA,IAAAC,gBAAA,CAAAf,OAAA,QAAAW,eAAA;IACnE,IAAIG,gBAAgB,CAACE,OAAO,CAAC,CAAC,EAC5B,MAAM,IAAIC,wBAAW,CAAC;MACpBC,OAAO,EACL;IACJ,CAAC,CAAC;IAEJ,MAAMC,MAAM,GAAGL,gBAAgB,CAACM,KAAK,CAAC,CAAC;IACvC;IACA,MAAMC,IAAI,GAAGF,MAAM,CAACG,MAAM,CACxB,CAACD,IAAI,EAAEE,KAAK,MAAM;MAAE,GAAGF,IAAI;MAAE,CAACE,KAAK,CAACC,IAAI,GAAGD,KAAK,CAACE;IAAc,CAAC,CAAC,EACjE,CAAC,CACH,CAAC;IACD;IACA,MAAMC,OAAO,GAAGP,MAAM,CAACQ,GAAG,CAAEJ,KAAK,IAC/BA,KAAK,CAACC,IAAI,KAAK,OAAO,GAClB;MACEI,KAAK,EAAEL,KAAK,CAACM,IAAI;MACjBC,QAAQ,EAAEP,KAAK,CAACO,QAAQ;MACxBZ,OAAO,EAAEK,KAAK,CAACE;IACjB,CAAC,GACD;MAAEP,OAAO,EAAEK,KAAK,CAACE;IAAc,CACrC,CAAC;IAAC,OAAA9B,UAAA,OAAAgB,eAAA,GACI;MACJO,OAAO,EAAE,iCAAiC;MAC1Ca,SAAS,EAAE,iBAAiB;MAC5BC,UAAU,EAAE,GAAG;MACfC,QAAQ,EAAEC,kBAAW,CAACC,OAAO;MAC7BC,IAAI,EAAEf,IAAI;MACVA,IAAI;MACJK;IACF,CAAC;EACH;EAAC,IAAAW,UAAA,CAAArC,OAAA,EAAAW,eAAA,EAAAE,SAAA;EAAA,WAAAyB,aAAA,CAAAtC,OAAA,EAAAW,eAAA;AAAA,EAlCkC4B,mBAAQ","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-server-engine",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "Framework used to develop backend services. This package ships with a lot of features to standardize the creation of services, letting you focus on the business logic.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {