@rvoh/psychic 1.12.1 → 1.12.2

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/CHANGELOG.md ADDED
@@ -0,0 +1,351 @@
1
+ ## 1.12.2
2
+
3
+ - when using `combining` in requestBody for an OpenAPI decorator, it will now override any params brought in through serializable introspection.
4
+
5
+ ## 1.12.1
6
+
7
+ - increase depth of OpenAPI validation error logs
8
+ - fix generated resource controller spec
9
+
10
+ ## 1.12.0
11
+
12
+ - `scrollPagination` support
13
+ - sort client enums when syncing to reduce needless diff churn
14
+ - leverage RequestBody in generated resource controller specs
15
+
16
+ ## 1.11.1
17
+
18
+ - export PsychicLogos
19
+ - export colorize
20
+
21
+ ## 1.11.0
22
+
23
+ - match Dream change from `bypassModelIntegrityCheck` to `bypassDreamIntegrityChecks`
24
+ - match Dream change to allow automatic OpenAPI generation from `delegatedAttribute` serialization of associated models
25
+ - fix resource controller spec generator missing date and datetime in spec ensuring model owned by another user is not updated
26
+ - resource controller spec generator supports array attributes
27
+ - generated resource controller spec data type `DreamRequestAttributes`, not `UpdateableProperties`
28
+ - call `.toISO()` on all DateTime and CalendarDate properties going into request to conform to types
29
+ - only pluralize the route if not designated as `singular`; pluralize before generating controller name so the controller name matches the route in the routes file
30
+ - increase depth of inspection during error logging
31
+
32
+ ## 1.10.5
33
+
34
+ - add "combining" option to requestBody for OpenAPI decorator, enabling you to combine additional openapi fields to the request body, while still leveraging the powerful automatically-generated request body.
35
+ - syncing client enums now sync types along with values
36
+ - better dev logging
37
+
38
+ ## 1.10.4
39
+
40
+ Fix issue with rendering incorrect enum descriptions when suppressResponseEnums is set to true and enums are explicitly overridden in the openapi option.
41
+
42
+ ## 1.10.3
43
+
44
+ - respect `required: false` when generating OpenAPI spec
45
+
46
+ ## 1.10.2
47
+
48
+ - return 400 instead of throwing error and 500 when there is a column overflow at the database level (let database validation suffice for enforcing data length validation rather than requiring model level validation)
49
+
50
+ ## 1.10.1
51
+
52
+ - OpenAPI and castParam validation errors are logged only when `NODE_DEBUG=psychic`
53
+
54
+ ## 1.10.0
55
+
56
+ - remove OpenAPI and Dream validation error response configuration and do not respond with errors (don't introduce such a difference between development and production environments)
57
+ - log validation errors in test and dev (not prod to avoid DOS)
58
+ - remove distinction between 400 and 422 to block ability of attacker to get feedback on how far into the system their request made it
59
+
60
+ ## 1.9.0
61
+
62
+ 1. Validate params against OpenAPI at the latest possible of:
63
+ a. when the params are accessed
64
+ b. when about to render the action
65
+ This ensures that we return the proper 401/403 response instead of 400 for authenticated endpoints that fail authentication and prevents unauthenticated requests from gaining information about the API
66
+
67
+ 2. Ability to configure whether or not OpenAPI validation errors include detailed information
68
+
69
+ ## 1.8.6
70
+
71
+ remove dead env variable, now that we are open sourced
72
+
73
+ ## 1.8.5
74
+
75
+ Do not hard crash when initializing a psychic application when one of the openapi routes is not found for an openapi-decorated controller endpoint. We will continue to raise this exception when building openapi specs, but not when booting up the psychic application, since one can define routes that are i.e. not available in certain environments, and we don't want this to cause hard crashes when our app boots in those environments.
76
+
77
+ ## 1.8.4
78
+
79
+ - OpenAPI decorator with default 204 status does not throw an exception when passed a Dream model without a `serializers` getter
80
+ - OpenAPI decorator that defines an explicit OpenAPI shape for the default status code does not throw an exception when passed a Dream model without a `serializers` getter
81
+
82
+ ## 1.8.3
83
+
84
+ - don't build openapi when `bypassModelIntegrityCheck: true`
85
+
86
+ ## 1.8.2
87
+
88
+ - openapi validation properly coerces non-array query params to arrays when validating, since both express and ajv fail to do this under the hood properly. This solves issues where sending up array params with only a single item in them are not treated as arrays.
89
+
90
+ ## 1.8.1
91
+
92
+ - do not coerce types in ajv when processing request or response bodies during validation. Type coercion will still happen for headers and query params, since they will need to respect the schema type specified in the openapi docuement.
93
+
94
+ ## 1.8.0
95
+
96
+ - remove unused `clientRoot` config
97
+
98
+ ## 1.7.2
99
+
100
+ - generate admin routes in routes.admin.ts (requires `routes.admin.ts` next to `routes.ts`)
101
+
102
+ ## 1.7.1
103
+
104
+ - compute openapi doc during intiialization, rather than problematically reading from a file cache
105
+
106
+ ## 1.7.0
107
+
108
+ - `sanitizeResponseJson` config to automatically escape `<`, `>`, `&`, `/`, `\`, `'`, and `"` unicode representations when rendering json to satisfy security reviews (e.g., a pentest report recently called this out on one of our applications). For all practical purposes, this doesn't protect against anything (now that we have the `nosniff` header) since `JSON.parse` on the other end restores the original, dangerous string. Modern front end web frameworks already handle safely displaying arbitrary content, so further sanitization generally isn't needed. This version does provide the `sanitizeString` function that could be used to sanitize individual strings, replacing the above characters with string representations of the unicode characters that will survive Psychic converting to json and then parsing that json (i.e.: `<` will end up as the string "\u003c")
109
+
110
+ - Fix openapi serializer fallback issue introduced in 1.6.3, where we mistakenly double render data that has already been serialized.
111
+
112
+ ## 1.6.4
113
+
114
+ Raise an exception if attempting to import an openapi file during PsychicApp.init when in production. We will still swallow the exception in non-prod environments so that one can create a new openapi configuration and run sync without getting an error.
115
+
116
+ ## 1.6.3
117
+
118
+ - castParam accepts raw openapi shapes as type arguments, correctly casting the result to an interface representing the provided openapi shape.
119
+
120
+ ```ts
121
+ class MyController extends ApplicationController {
122
+ public index() {
123
+ const myParam = this.castParam('myParam', {
124
+ type: 'array',
125
+ items: {
126
+ anyOf: [{ type: 'string' }, { type: 'number' }],
127
+ },
128
+ })
129
+ myParam[0] // string | number
130
+ }
131
+ }
132
+ ```
133
+
134
+ - simplify the needlessly-robust new psychic router patterns by making expressApp optional, essentially reverting us back to the same psychic router we had prior to the recent openapi validation changes.
135
+
136
+ - fallback to serializer specified in openapi decorator before falling back to dream serializer when rendering dreams
137
+
138
+ ## 1.6.2
139
+
140
+ fix OpenAPI spec generation by DRYing up generation of request and response body
141
+
142
+ ## 1.6.1
143
+
144
+ fix issue preventing validation fallbacks from properly overriding on OpenAPI decorator calls when explicitly opting out of validation
145
+
146
+ ## 1.6.0
147
+
148
+ enables validation to be added to both openapi configurations, as well as to `OpenAPI` decorator calls, enabling the developer to granularly control validation logic for their endpoints.
149
+
150
+ To leverage global config:
151
+
152
+ ```ts
153
+ // conf/app.ts
154
+ export default async (psy: PsychicApp) => {
155
+ ...
156
+
157
+ psy.set('openapi', {
158
+ // ...
159
+ validate: {
160
+ headers: true,
161
+ requestBody: true,
162
+ query: true,
163
+ responseBody: AppEnv.isTest,
164
+ },
165
+ })
166
+ }
167
+ ```
168
+
169
+ To leverage endpoint config:
170
+
171
+ ```ts
172
+ // controllers/PetsController
173
+ export default class PetsController {
174
+ @OpenAPI(Pet, {
175
+ ...
176
+ validate: {
177
+ headers: true,
178
+ requestBody: true,
179
+ query: true,
180
+ responseBody: AppEnv.isTest,
181
+ }
182
+ })
183
+ public async index() {
184
+ ...
185
+ }
186
+ }
187
+ ```
188
+
189
+ This PR additionally formally introduces a new possible error type for 400 status codes, and to help distinguish, it also introduces a `type` field, which can be either `openapi` or `dream` to aid the developer in easily handling the various cases.
190
+
191
+ We have made a conscious decision to render openapi errors in the exact format that ajv returns, since it empowers the developer to utilize tools which can already respond to ajv errors.
192
+
193
+ For added flexibility, this PR includes the ability to provide configuration overrides for the ajv instance, as well as the ability to provide an initialization function to override ajv behavior, since much of the configuration for ajv is driven by method calls, rather than simple config.
194
+
195
+ ```ts
196
+ // controllers/PetsController
197
+ export default class PetsController {
198
+ @OpenAPI(Pet, {
199
+ ...
200
+ validate: {
201
+ ajvOptions: {
202
+ // this is off by default, but you will
203
+ // always want to keep this off in prod
204
+ // to avoid DoS vulnerabilities
205
+ allErrors: AppEnv.isTest,
206
+
207
+ // provide a custom init function to further
208
+ // configure your ajv instance before validating
209
+ init: ajv => {
210
+ ajv.addFormat('myFormat', {
211
+ type: 'string',
212
+ validate: data => MY_FORMAT_REGEX.test(data),
213
+ })
214
+ }
215
+ }
216
+ }
217
+ })
218
+ public async index() {
219
+ ...
220
+ }
221
+ }
222
+ ```
223
+
224
+ ## 1.5.5
225
+
226
+ - ensure that openapi-typescript and typescript are not required dependencies when running migrations with --skip-sync flag
227
+
228
+ ## 1.5.4
229
+
230
+ - fix issue when providing the `including` argument exclusively to an OpenAPI decorator's `requestBody`
231
+
232
+ ## 1.5.3
233
+
234
+ - add missing peer dependency for openapi-typescript, allow BIGINT type when generating openapi-typescript bigints
235
+
236
+ ## 1.5.2
237
+
238
+ - ensure that bigints are converted to number | string when generating openapi-typescript type files
239
+
240
+ ## 1.5.1
241
+
242
+ - fix issue with enum syncing related to multi-db engine support regression
243
+
244
+ ## 1.5.0
245
+
246
+ - add support for multiple database engines in dream
247
+
248
+ ## 1.2.3
249
+
250
+ - add support for the connectionName argument when generating a resource
251
+
252
+ ## 1.2.2
253
+
254
+ - bump supertest and express-session to close dependabot issues [53](https://github.com/rvohealth/psychic/security/dependabot/53), [56](https://github.com/rvohealth/psychic/security/dependabot/56), and [57](https://github.com/rvohealth/psychic/security/dependabot/57)
255
+
256
+ ## 1.2.1
257
+
258
+ - add ability to set custom import extension, which will be used when generating new files for your application
259
+
260
+ ## 1.2.0
261
+
262
+ - update for Dream 1.4.0
263
+
264
+ ## 1.1.11
265
+
266
+ - 400 is more appropriate than 422 for `DataTypeColumnTypeMismatch`
267
+
268
+ ## 1.1.10
269
+
270
+ - Don't include deletedAt in generated create/update actions in resource specs since deletedAt is for deleting
271
+
272
+ - return 422 if Dream throws `NotNullViolation` or `CheckConstraintViolation`
273
+
274
+ ## 1.1.9
275
+
276
+ - return 422 if dream throws `DataTypeColumnTypeMismatch`, which happens when a dream is saved to the database with data that cannot be inserted into the respective columns, usually because of a type mismatch.
277
+
278
+ - castParam will now encase params in an array when being explicitly casted as an array type, bypassing a known bug in express from causing arrays with single items in them to be treated as non-arrays.
279
+
280
+ ## 1.1.8
281
+
282
+ - Tap into CliFileWriter provided by dream to tap into file reversion for sync files, since the auto-sync function in psychic can fail and leave your file tree in a bad state.
283
+
284
+ ## 1.1.7
285
+
286
+ - Add support for middleware arrays, enabling express plugins like passport
287
+
288
+ ## 1.1.6
289
+
290
+ - fix regression caused by missing --schema-only option in psychic cli
291
+
292
+ ## 1.1.5
293
+
294
+ - pass packageManager through to dream, now that it accepts a packageManager setting.
295
+ - update dream shadowing within psychic application initialization to take place after initializers and plugins are processed, so that those initializers and plugins have an opportunity to adjust the settings.
296
+
297
+ ## 1.1.4
298
+
299
+ - fix regressions to redux bindings caused by default openapi path location changes
300
+ - resource generator can handle prefixing slashes
301
+
302
+ ## 1.1.3
303
+
304
+ - fix more minor issues with redux openapi bindings
305
+
306
+ ## 1.1.2
307
+
308
+ - Fix various issues with openapi redux bindings
309
+ - raise hard exception if accidentally using openapi route params in an expressjs route path
310
+
311
+ ## 1.1.1
312
+
313
+ Fix route printing regression causing route printouts to show the path instead of the action
314
+
315
+ ## v1.1.0
316
+
317
+ Provides easier access to express middleware by exposing `PsychicApp#use`, which enables a developer to provide express middleware directly through the psychcic application, without tapping into any hooks.
318
+
319
+ ```ts
320
+ psy.use((_, res) => {
321
+ res.send(
322
+ 'this will be run after psychic middleware (i.e. cors and bodyParser) are processed, but before routes are processed',
323
+ )
324
+ })
325
+ ```
326
+
327
+ Some middleware needs to be run before other middleware, so we expose an optional first argument which can be provided so explicitly send your middleware into express at various stages of the psychic configuration process. For example, to inject your middleware before cors and bodyParser are configured, provide `before-middleware` as the first argument. To initialize your middleware after the psychic default middleware, but before your routes have been processed, provide `after-middleware` as the first argument (or simply provide a callback function directly, since this is the default). To run after routes have been processed, provide `after-routes` as the first argument.
328
+
329
+ ```ts
330
+ psy.use('before-middleware', (_, res) => {
331
+ res.send('this will be run before psychic has configured any default middleware')
332
+ })
333
+
334
+ psy.use('after-middleware', (_, res) => {
335
+ res.send('this will be run after psychic has configured default middleware')
336
+ })
337
+
338
+ psy.use('after-routes', (_, res) => {
339
+ res.send('this will be run after psychic has processed all the routes in your conf/routes.ts file')
340
+ })
341
+ ```
342
+
343
+ Additionally, a new overload has been added to all CRUD methods on the PsychicRouter class, enabling you to provide RequestHandler middleware directly to psychic, like so:
344
+
345
+ ```ts
346
+ // conf/routes.ts
347
+
348
+ r.get('helloworld', (req, res, next) => {
349
+ res.json({ hello: 'world' })
350
+ })
351
+ ```
@@ -539,11 +539,7 @@ class OpenapiEndpointRenderer {
539
539
  const paramSafeColumns = (0, paramNamesForDreamClass_js_1.default)(dreamClass, { only, including });
540
540
  const paramsShape = {
541
541
  type: 'object',
542
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
543
- properties: {
544
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
545
- ...(combining || {}),
546
- },
542
+ properties: {},
547
543
  };
548
544
  const required = this.requestBody?.required;
549
545
  if (required) {
@@ -555,6 +551,10 @@ class OpenapiEndpointRenderer {
555
551
  });
556
552
  return acc;
557
553
  }, paramsShape.properties);
554
+ paramsShape.properties = {
555
+ ...paramsShape.properties,
556
+ ...(combining || {}),
557
+ };
558
558
  let processedSchema = new body_segment_js_1.default(paramsShape, {
559
559
  renderOpts,
560
560
  target: 'request',
@@ -533,11 +533,7 @@ export default class OpenapiEndpointRenderer {
533
533
  const paramSafeColumns = paramNamesForDreamClass(dreamClass, { only, including });
534
534
  const paramsShape = {
535
535
  type: 'object',
536
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
537
- properties: {
538
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
539
- ...(combining || {}),
540
- },
536
+ properties: {},
541
537
  };
542
538
  const required = this.requestBody?.required;
543
539
  if (required) {
@@ -549,6 +545,10 @@ export default class OpenapiEndpointRenderer {
549
545
  });
550
546
  return acc;
551
547
  }, paramsShape.properties);
548
+ paramsShape.properties = {
549
+ ...paramsShape.properties,
550
+ ...(combining || {}),
551
+ };
552
552
  let processedSchema = new OpenapiSegmentExpander(paramsShape, {
553
553
  renderOpts,
554
554
  target: 'request',
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "type": "module",
3
3
  "name": "@rvoh/psychic",
4
4
  "description": "Typescript web framework",
5
- "version": "1.12.1",
5
+ "version": "1.12.2",
6
6
  "author": "RVOHealth",
7
7
  "repository": {
8
8
  "type": "git",
@@ -98,4 +98,4 @@
98
98
  "winston": "^3.14.2"
99
99
  },
100
100
  "packageManager": "yarn@4.7.0"
101
- }
101
+ }