@rvoh/psychic 3.8.1 → 3.8.5

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.
@@ -94,17 +94,6 @@ export const DEFAULT_OPENAPI_COMPONENT_RESPONSES = {
94
94
  Conflict: {
95
95
  description: 'The request failed because a conflict was detected with the given request params',
96
96
  },
97
- // 422
98
- ValidationErrors: {
99
- description: 'The request failed to process due to validation errors with the provided values',
100
- content: {
101
- 'application/json': {
102
- schema: {
103
- $ref: '#/components/schemas/ValidationErrors',
104
- },
105
- },
106
- },
107
- },
108
97
  // 500
109
98
  InternalServerError: {
110
99
  description: 'the server encountered an unexpected condition that prevented it from fulfilling the request',
@@ -224,16 +224,14 @@ suggested fix: "${convertRouteParams(path)}"
224
224
  }
225
225
  /**
226
226
  * Automatically rescue certain errors and convert them into status codes.
227
- * Validation errors (OpenAPI or otherwise) are by default converted to
228
- * 400. 422 MUST ONLY be returned when accompanied by a ValidationErrors
229
- * payload (even if the errors object is empty) that is intended to be displayed
230
- * to the end user to indicate fields that must be corrected to be
231
- * accepted.
227
+ * Validation errors (OpenAPI or otherwise) are converted to 400. When a
228
+ * controller deliberately returns field-level validation details for display
229
+ * to an end user, prefer a 400 response carrying an errors payload in the
230
+ * same shape as Dream#errors: { errors: { field: ['message'] } }.
232
231
  *
233
- * Philosophy: do not return information (even difference between 400 & 422)
234
- * unless it is explicitly intended for that information to be used to enable
235
- * a front end interface to display information to support user-visible
236
- * validation (e.g. an email must be formatted correctly).
232
+ * Philosophy: do not return information unless it is explicitly intended for
233
+ * that information to be used by a front-end interface supporting
234
+ * user-visible validation (e.g. an email must be formatted correctly).
237
235
  *
238
236
  * By default, do not provide an attacker with any visibility into which layer
239
237
  * of the application rejected their request.
@@ -162,6 +162,8 @@ export default class Params {
162
162
  return this;
163
163
  }
164
164
  cast(paramName, paramValue, expectedType, opts) {
165
+ if (typeof paramValue === 'string')
166
+ paramValue = paramValue.trim();
165
167
  if (expectedType instanceof RegExp) {
166
168
  return this.matchRegexOrThrow(paramName, paramValue, expectedType);
167
169
  }
@@ -94,17 +94,6 @@ export const DEFAULT_OPENAPI_COMPONENT_RESPONSES = {
94
94
  Conflict: {
95
95
  description: 'The request failed because a conflict was detected with the given request params',
96
96
  },
97
- // 422
98
- ValidationErrors: {
99
- description: 'The request failed to process due to validation errors with the provided values',
100
- content: {
101
- 'application/json': {
102
- schema: {
103
- $ref: '#/components/schemas/ValidationErrors',
104
- },
105
- },
106
- },
107
- },
108
97
  // 500
109
98
  InternalServerError: {
110
99
  description: 'the server encountered an unexpected condition that prevented it from fulfilling the request',
@@ -224,16 +224,14 @@ suggested fix: "${convertRouteParams(path)}"
224
224
  }
225
225
  /**
226
226
  * Automatically rescue certain errors and convert them into status codes.
227
- * Validation errors (OpenAPI or otherwise) are by default converted to
228
- * 400. 422 MUST ONLY be returned when accompanied by a ValidationErrors
229
- * payload (even if the errors object is empty) that is intended to be displayed
230
- * to the end user to indicate fields that must be corrected to be
231
- * accepted.
227
+ * Validation errors (OpenAPI or otherwise) are converted to 400. When a
228
+ * controller deliberately returns field-level validation details for display
229
+ * to an end user, prefer a 400 response carrying an errors payload in the
230
+ * same shape as Dream#errors: { errors: { field: ['message'] } }.
232
231
  *
233
- * Philosophy: do not return information (even difference between 400 & 422)
234
- * unless it is explicitly intended for that information to be used to enable
235
- * a front end interface to display information to support user-visible
236
- * validation (e.g. an email must be formatted correctly).
232
+ * Philosophy: do not return information unless it is explicitly intended for
233
+ * that information to be used by a front-end interface supporting
234
+ * user-visible validation (e.g. an email must be formatted correctly).
237
235
  *
238
236
  * By default, do not provide an attacker with any visibility into which layer
239
237
  * of the application rejected their request.
@@ -162,6 +162,8 @@ export default class Params {
162
162
  return this;
163
163
  }
164
164
  cast(paramName, paramValue, expectedType, opts) {
165
+ if (typeof paramValue === 'string')
166
+ paramValue = paramValue.trim();
165
167
  if (expectedType instanceof RegExp) {
166
168
  return this.matchRegexOrThrow(paramName, paramValue, expectedType);
167
169
  }
@@ -49,16 +49,14 @@ export default class PsychicRouter {
49
49
  private get validationErrorLoggingEnabled();
50
50
  /**
51
51
  * Automatically rescue certain errors and convert them into status codes.
52
- * Validation errors (OpenAPI or otherwise) are by default converted to
53
- * 400. 422 MUST ONLY be returned when accompanied by a ValidationErrors
54
- * payload (even if the errors object is empty) that is intended to be displayed
55
- * to the end user to indicate fields that must be corrected to be
56
- * accepted.
52
+ * Validation errors (OpenAPI or otherwise) are converted to 400. When a
53
+ * controller deliberately returns field-level validation details for display
54
+ * to an end user, prefer a 400 response carrying an errors payload in the
55
+ * same shape as Dream#errors: { errors: { field: ['message'] } }.
57
56
  *
58
- * Philosophy: do not return information (even difference between 400 & 422)
59
- * unless it is explicitly intended for that information to be used to enable
60
- * a front end interface to display information to support user-visible
61
- * validation (e.g. an email must be formatted correctly).
57
+ * Philosophy: do not return information unless it is explicitly intended for
58
+ * that information to be used by a front-end interface supporting
59
+ * user-visible validation (e.g. an email must be formatted correctly).
62
60
  *
63
61
  * By default, do not provide an attacker with any visibility into which layer
64
62
  * of the application rejected their request.
package/package.json CHANGED
@@ -2,8 +2,11 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic",
4
4
  "description": "Typescript web framework",
5
- "version": "3.8.1",
5
+ "version": "3.8.5",
6
6
  "author": "RVOHealth",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
7
10
  "repository": {
8
11
  "type": "git",
9
12
  "url": "git+https://github.com/rvohealth/psychic.git"
@@ -134,5 +137,5 @@
134
137
  "vitest": "^4.1.0",
135
138
  "winston": "^3.14.2"
136
139
  },
137
- "packageManager": "pnpm@11.1.3+sha512.c85357fe17ca12dd23dd7071822666dfd7e3cb76fe214e3370b5ea2fb34f2a231185509b63e717f3cd0acb38dd3f8d82bcd5e8172400ae678b70ea4fbed0896d"
140
+ "packageManager": "pnpm@11.9.0+sha512.bd682d5d03fe525ef7c9fd6780c6884d1e756ac4c9c9fe00c538782824310dcf90e3ddc4f53835f06dfaebd5085e41855e0bcbb3b60de2ac5bbab89e5036f03b"
138
141
  }