@rvoh/psychic 1.12.0 → 1.12.1

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.
@@ -170,7 +170,7 @@ describe('${fullyQualifiedControllerName}', () => {
170
170
 
171
171
  const { body } = await subject(200)
172
172
 
173
- expect(body).toEqual([])
173
+ expect(body.results).toEqual([])
174
174
  })
175
175
  })`}
176
176
  })`}${omitShow
@@ -345,7 +345,7 @@ suggested fix: "${(0, helpers_js_1.convertRouteParams)(path)}"
345
345
  controllerInstance['expressSendStatus'](400);
346
346
  }
347
347
  else {
348
- index_js_1.default.logWithLevel('error', err);
348
+ index_js_1.default.logWithLevel('error', node_util_1.default.inspect(err, { depth: ERROR_LOGGING_DEPTH }));
349
349
  if (index_js_1.default.getOrFail().specialHooks.serverError.length) {
350
350
  try {
351
351
  for (const hook of index_js_1.default.getOrFail().specialHooks.serverError) {
@@ -164,7 +164,7 @@ describe('${fullyQualifiedControllerName}', () => {
164
164
 
165
165
  const { body } = await subject(200)
166
166
 
167
- expect(body).toEqual([])
167
+ expect(body.results).toEqual([])
168
168
  })
169
169
  })`}
170
170
  })`}${omitShow
@@ -316,7 +316,7 @@ suggested fix: "${convertRouteParams(path)}"
316
316
  controllerInstance['expressSendStatus'](400);
317
317
  }
318
318
  else {
319
- PsychicApp.logWithLevel('error', err);
319
+ PsychicApp.logWithLevel('error', util.inspect(err, { depth: ERROR_LOGGING_DEPTH }));
320
320
  if (PsychicApp.getOrFail().specialHooks.serverError.length) {
321
321
  try {
322
322
  for (const hook of PsychicApp.getOrFail().specialHooks.serverError) {
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.0",
5
+ "version": "1.12.1",
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
+ }
package/CHANGELOG.md DELETED
@@ -1,342 +0,0 @@
1
- ## 1.12.0
2
-
3
- - `scrollPagination` support
4
- - sort client enums when syncing to reduce needless diff churn
5
- - leverage RequestBody in generated resource controller specs
6
-
7
- ## 1.11.1
8
-
9
- - export PsychicLogos
10
- - export colorize
11
-
12
- ## 1.11.0
13
-
14
- - match Dream change from `bypassModelIntegrityCheck` to `bypassDreamIntegrityChecks`
15
- - match Dream change to allow automatic OpenAPI generation from `delegatedAttribute` serialization of associated models
16
- - fix resource controller spec generator missing date and datetime in spec ensuring model owned by another user is not updated
17
- - resource controller spec generator supports array attributes
18
- - generated resource controller spec data type `DreamRequestAttributes`, not `UpdateableProperties`
19
- - call `.toISO()` on all DateTime and CalendarDate properties going into request to conform to types
20
- - 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
21
- - increase depth of inspection during error logging
22
-
23
- ## 1.10.5
24
-
25
- - 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.
26
- - syncing client enums now sync types along with values
27
- - better dev logging
28
-
29
- ## 1.10.4
30
-
31
- Fix issue with rendering incorrect enum descriptions when suppressResponseEnums is set to true and enums are explicitly overridden in the openapi option.
32
-
33
- ## 1.10.3
34
-
35
- - respect `required: false` when generating OpenAPI spec
36
-
37
- ## 1.10.2
38
-
39
- - 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)
40
-
41
- ## 1.10.1
42
-
43
- - OpenAPI and castParam validation errors are logged only when `NODE_DEBUG=psychic`
44
-
45
- ## 1.10.0
46
-
47
- - 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)
48
- - log validation errors in test and dev (not prod to avoid DOS)
49
- - remove distinction between 400 and 422 to block ability of attacker to get feedback on how far into the system their request made it
50
-
51
- ## 1.9.0
52
-
53
- 1. Validate params against OpenAPI at the latest possible of:
54
- a. when the params are accessed
55
- b. when about to render the action
56
- 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
57
-
58
- 2. Ability to configure whether or not OpenAPI validation errors include detailed information
59
-
60
- ## 1.8.6
61
-
62
- remove dead env variable, now that we are open sourced
63
-
64
- ## 1.8.5
65
-
66
- 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.
67
-
68
- ## 1.8.4
69
-
70
- - OpenAPI decorator with default 204 status does not throw an exception when passed a Dream model without a `serializers` getter
71
- - 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
72
-
73
- ## 1.8.3
74
-
75
- - don't build openapi when `bypassModelIntegrityCheck: true`
76
-
77
- ## 1.8.2
78
-
79
- - 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.
80
-
81
- ## 1.8.1
82
-
83
- - 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.
84
-
85
- ## 1.8.0
86
-
87
- - remove unused `clientRoot` config
88
-
89
- ## 1.7.2
90
-
91
- - generate admin routes in routes.admin.ts (requires `routes.admin.ts` next to `routes.ts`)
92
-
93
- ## 1.7.1
94
-
95
- - compute openapi doc during intiialization, rather than problematically reading from a file cache
96
-
97
- ## 1.7.0
98
-
99
- - `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")
100
-
101
- - Fix openapi serializer fallback issue introduced in 1.6.3, where we mistakenly double render data that has already been serialized.
102
-
103
- ## 1.6.4
104
-
105
- 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.
106
-
107
- ## 1.6.3
108
-
109
- - castParam accepts raw openapi shapes as type arguments, correctly casting the result to an interface representing the provided openapi shape.
110
-
111
- ```ts
112
- class MyController extends ApplicationController {
113
- public index() {
114
- const myParam = this.castParam('myParam', {
115
- type: 'array',
116
- items: {
117
- anyOf: [{ type: 'string' }, { type: 'number' }],
118
- },
119
- })
120
- myParam[0] // string | number
121
- }
122
- }
123
- ```
124
-
125
- - 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.
126
-
127
- - fallback to serializer specified in openapi decorator before falling back to dream serializer when rendering dreams
128
-
129
- ## 1.6.2
130
-
131
- fix OpenAPI spec generation by DRYing up generation of request and response body
132
-
133
- ## 1.6.1
134
-
135
- fix issue preventing validation fallbacks from properly overriding on OpenAPI decorator calls when explicitly opting out of validation
136
-
137
- ## 1.6.0
138
-
139
- 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.
140
-
141
- To leverage global config:
142
-
143
- ```ts
144
- // conf/app.ts
145
- export default async (psy: PsychicApp) => {
146
- ...
147
-
148
- psy.set('openapi', {
149
- // ...
150
- validate: {
151
- headers: true,
152
- requestBody: true,
153
- query: true,
154
- responseBody: AppEnv.isTest,
155
- },
156
- })
157
- }
158
- ```
159
-
160
- To leverage endpoint config:
161
-
162
- ```ts
163
- // controllers/PetsController
164
- export default class PetsController {
165
- @OpenAPI(Pet, {
166
- ...
167
- validate: {
168
- headers: true,
169
- requestBody: true,
170
- query: true,
171
- responseBody: AppEnv.isTest,
172
- }
173
- })
174
- public async index() {
175
- ...
176
- }
177
- }
178
- ```
179
-
180
- 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.
181
-
182
- 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.
183
-
184
- 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.
185
-
186
- ```ts
187
- // controllers/PetsController
188
- export default class PetsController {
189
- @OpenAPI(Pet, {
190
- ...
191
- validate: {
192
- ajvOptions: {
193
- // this is off by default, but you will
194
- // always want to keep this off in prod
195
- // to avoid DoS vulnerabilities
196
- allErrors: AppEnv.isTest,
197
-
198
- // provide a custom init function to further
199
- // configure your ajv instance before validating
200
- init: ajv => {
201
- ajv.addFormat('myFormat', {
202
- type: 'string',
203
- validate: data => MY_FORMAT_REGEX.test(data),
204
- })
205
- }
206
- }
207
- }
208
- })
209
- public async index() {
210
- ...
211
- }
212
- }
213
- ```
214
-
215
- ## 1.5.5
216
-
217
- - ensure that openapi-typescript and typescript are not required dependencies when running migrations with --skip-sync flag
218
-
219
- ## 1.5.4
220
-
221
- - fix issue when providing the `including` argument exclusively to an OpenAPI decorator's `requestBody`
222
-
223
- ## 1.5.3
224
-
225
- - add missing peer dependency for openapi-typescript, allow BIGINT type when generating openapi-typescript bigints
226
-
227
- ## 1.5.2
228
-
229
- - ensure that bigints are converted to number | string when generating openapi-typescript type files
230
-
231
- ## 1.5.1
232
-
233
- - fix issue with enum syncing related to multi-db engine support regression
234
-
235
- ## 1.5.0
236
-
237
- - add support for multiple database engines in dream
238
-
239
- ## 1.2.3
240
-
241
- - add support for the connectionName argument when generating a resource
242
-
243
- ## 1.2.2
244
-
245
- - 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)
246
-
247
- ## 1.2.1
248
-
249
- - add ability to set custom import extension, which will be used when generating new files for your application
250
-
251
- ## 1.2.0
252
-
253
- - update for Dream 1.4.0
254
-
255
- ## 1.1.11
256
-
257
- - 400 is more appropriate than 422 for `DataTypeColumnTypeMismatch`
258
-
259
- ## 1.1.10
260
-
261
- - Don't include deletedAt in generated create/update actions in resource specs since deletedAt is for deleting
262
-
263
- - return 422 if Dream throws `NotNullViolation` or `CheckConstraintViolation`
264
-
265
- ## 1.1.9
266
-
267
- - 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.
268
-
269
- - 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.
270
-
271
- ## 1.1.8
272
-
273
- - 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.
274
-
275
- ## 1.1.7
276
-
277
- - Add support for middleware arrays, enabling express plugins like passport
278
-
279
- ## 1.1.6
280
-
281
- - fix regression caused by missing --schema-only option in psychic cli
282
-
283
- ## 1.1.5
284
-
285
- - pass packageManager through to dream, now that it accepts a packageManager setting.
286
- - 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.
287
-
288
- ## 1.1.4
289
-
290
- - fix regressions to redux bindings caused by default openapi path location changes
291
- - resource generator can handle prefixing slashes
292
-
293
- ## 1.1.3
294
-
295
- - fix more minor issues with redux openapi bindings
296
-
297
- ## 1.1.2
298
-
299
- - Fix various issues with openapi redux bindings
300
- - raise hard exception if accidentally using openapi route params in an expressjs route path
301
-
302
- ## 1.1.1
303
-
304
- Fix route printing regression causing route printouts to show the path instead of the action
305
-
306
- ## v1.1.0
307
-
308
- 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.
309
-
310
- ```ts
311
- psy.use((_, res) => {
312
- res.send(
313
- 'this will be run after psychic middleware (i.e. cors and bodyParser) are processed, but before routes are processed',
314
- )
315
- })
316
- ```
317
-
318
- 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.
319
-
320
- ```ts
321
- psy.use('before-middleware', (_, res) => {
322
- res.send('this will be run before psychic has configured any default middleware')
323
- })
324
-
325
- psy.use('after-middleware', (_, res) => {
326
- res.send('this will be run after psychic has configured default middleware')
327
- })
328
-
329
- psy.use('after-routes', (_, res) => {
330
- res.send('this will be run after psychic has processed all the routes in your conf/routes.ts file')
331
- })
332
- ```
333
-
334
- 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:
335
-
336
- ```ts
337
- // conf/routes.ts
338
-
339
- r.get('helloworld', (req, res, next) => {
340
- res.json({ hello: 'world' })
341
- })
342
- ```