fastify 4.24.2 → 4.25.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.
Files changed (67) hide show
  1. package/README.md +7 -2
  2. package/SECURITY.md +27 -0
  3. package/docs/Guides/Ecosystem.md +18 -6
  4. package/docs/Guides/Getting-Started.md +3 -3
  5. package/docs/Guides/Plugins-Guide.md +2 -2
  6. package/docs/Guides/Style-Guide.md +7 -7
  7. package/docs/Reference/ContentTypeParser.md +2 -0
  8. package/docs/Reference/Errors.md +171 -397
  9. package/docs/Reference/Hooks.md +8 -2
  10. package/docs/Reference/Index.md +2 -0
  11. package/docs/Reference/Reply.md +16 -5
  12. package/docs/Reference/Request.md +1 -1
  13. package/docs/Reference/Routes.md +5 -5
  14. package/docs/Reference/TypeScript.md +1 -1
  15. package/docs/Reference/Warnings.md +77 -0
  16. package/examples/use-plugin.js +2 -0
  17. package/fastify.js +37 -20
  18. package/integration/server.js +2 -0
  19. package/lib/decorate.js +2 -2
  20. package/lib/errors.js +1 -1
  21. package/lib/hooks.js +1 -1
  22. package/lib/pluginUtils.js +10 -1
  23. package/lib/reply.js +5 -5
  24. package/lib/request.js +14 -7
  25. package/lib/route.js +9 -5
  26. package/lib/server.js +20 -27
  27. package/lib/validation.js +5 -5
  28. package/lib/warnings.js +110 -40
  29. package/package.json +4 -4
  30. package/test/buffer.test.js +2 -0
  31. package/test/bundler/esbuild/src/fail-plugin-version.js +2 -0
  32. package/test/bundler/esbuild/src/index.js +2 -0
  33. package/test/bundler/webpack/src/fail-plugin-version.js +2 -0
  34. package/test/bundler/webpack/src/index.js +2 -0
  35. package/test/bundler/webpack/webpack.config.js +2 -0
  36. package/test/close-pipelining.test.js +4 -4
  37. package/test/close.test.js +3 -3
  38. package/test/constrained-routes.test.js +24 -24
  39. package/test/decorator.test.js +27 -22
  40. package/test/default-route.test.js +7 -7
  41. package/test/fastify-instance.test.js +120 -0
  42. package/test/hooks.on-ready.test.js +16 -0
  43. package/test/hooks.test.js +1 -3
  44. package/test/http2/constraint.test.js +1 -1
  45. package/test/internals/errors.test.js +28 -3
  46. package/test/internals/reply.test.js +33 -9
  47. package/test/logger/instantiation.test.js +2 -1
  48. package/test/plugin.4.test.js +28 -0
  49. package/test/register.test.js +5 -5
  50. package/test/reply-trailers.test.js +1 -1
  51. package/test/route.7.test.js +7 -6
  52. package/test/schema-examples.test.js +2 -2
  53. package/test/schema-feature.test.js +11 -11
  54. package/test/server.test.js +51 -0
  55. package/test/types/hooks.test-d.ts +124 -1
  56. package/test/types/instance.test-d.ts +12 -0
  57. package/test/types/logger.test-d.ts +14 -0
  58. package/test/types/reply.test-d.ts +25 -6
  59. package/test/types/request.test-d.ts +3 -2
  60. package/test/types/route.test-d.ts +38 -0
  61. package/test/versioned-routes.test.js +7 -6
  62. package/types/hooks.d.ts +183 -0
  63. package/types/instance.d.ts +12 -12
  64. package/types/reply.d.ts +7 -10
  65. package/types/request.d.ts +2 -1
  66. package/types/route.d.ts +31 -26
  67. package/types/utils.d.ts +10 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <div align="center"> <a href="https://fastify.io/">
1
+ <div align="center"> <a href="https://fastify.dev/">
2
2
  <img
3
3
  src="https://github.com/fastify/graphics/raw/HEAD/fastify-landscape-outlined.svg"
4
4
  width="650"
@@ -9,7 +9,7 @@
9
9
 
10
10
  <div align="center">
11
11
 
12
- [![CI](https://github.com/fastify/fastify/workflows/ci/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/ci.yml)
12
+ [![CI](https://github.com/fastify/fastify/actions/workflows/ci.yml/badge.svg)](https://github.com/fastify/fastify/actions/workflows/ci.yml)
13
13
  [![Package Manager
14
14
  CI](https://github.com/fastify/fastify/workflows/package-manager-ci/badge.svg?branch=main)](https://github.com/fastify/fastify/actions/workflows/package-manager-ci.yml)
15
15
  [![Web
@@ -28,6 +28,7 @@ downloads](https://img.shields.io/npm/dm/fastify.svg?style=flat)](https://www.np
28
28
  [![Security Responsible
29
29
  Disclosure](https://img.shields.io/badge/Security-Responsible%20Disclosure-yellow.svg)](https://github.com/fastify/fastify/blob/main/SECURITY.md)
30
30
  [![Discord](https://img.shields.io/discord/725613461949906985)](https://discord.gg/fastify)
31
+ [![Contribute with Gitpod](https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod&color=blue)](https://gitpod.io/#https://github.com/fastify/fastify)
31
32
 
32
33
  </div>
33
34
 
@@ -284,6 +285,10 @@ listed in alphabetical order.
284
285
  <https://twitter.com/matteocollina>, <https://www.npmjs.com/~matteo.collina>
285
286
  * [__Tomas Della Vedova__](https://github.com/delvedor),
286
287
  <https://twitter.com/delvedor>, <https://www.npmjs.com/~delvedor>
288
+ * [__Manuel Spigolon__](https://github.com/eomm),
289
+ <https://twitter.com/manueomm>, <https://www.npmjs.com/~eomm>
290
+ * [__James Sumners__](https://github.com/jsumners),
291
+ <https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
287
292
 
288
293
  ### Fastify Core team
289
294
  * [__Tommaso Allevi__](https://github.com/allevo),
package/SECURITY.md CHANGED
@@ -130,3 +130,30 @@ work as a member of the Fastify Core team.
130
130
  * [__KaKa Ng__](https://github.com/climba03003)
131
131
  * [__James Sumners__](https://github.com/jsumners),
132
132
  <https://twitter.com/jsumners79>, <https://www.npmjs.com/~jsumners>
133
+
134
+ ## OpenSSF CII Best Practices
135
+
136
+ [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/7585/badge)](https://bestpractices.coreinfrastructure.org/projects/7585)
137
+
138
+ There are three “tiers”: passing, silver, and gold.
139
+
140
+ ### Passing
141
+ We meet 100% of the “passing” criteria.
142
+
143
+ ### Silver
144
+ We meet 87% of the “silver” criteria. The gaps are as follows:
145
+ - we do not have a DCO or a CLA process for contributions.
146
+ - we do not currently document
147
+ “what the user can and cannot expect in terms of security” for our project.
148
+ - we do not currently document ”the architecture (aka high-level design)”
149
+ for our project.
150
+
151
+ ### Gold
152
+ We meet 70% of the “gold” criteria. The gaps are as follows:
153
+ - we do not yet have the “silver” badge; see all the gaps above.
154
+ - We do not include a copyright or license statement in each source file.
155
+ Efforts are underway to change this archaic practice into a
156
+ suggestion instead of a hard requirement.
157
+ - There are a few unanswered questions around cryptography that are
158
+ waiting for clarification.
159
+
@@ -125,11 +125,11 @@ section.
125
125
  throttling the download speed of a request.
126
126
  - [`@fastify/type-provider-json-schema-to-ts`](https://github.com/fastify/fastify-type-provider-json-schema-to-ts)
127
127
  Fastify
128
- [type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/)
128
+ [type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/)
129
129
  for [json-schema-to-ts](https://github.com/ThomasAribart/json-schema-to-ts).
130
130
  - [`@fastify/type-provider-typebox`](https://github.com/fastify/fastify-type-provider-typebox)
131
131
  Fastify
132
- [type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/)
132
+ [type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/)
133
133
  for [Typebox](https://github.com/sinclairzx81/typebox).
134
134
  - [`@fastify/under-pressure`](https://github.com/fastify/under-pressure) Measure
135
135
  process load with automatic handling of _"Service Unavailable"_ plugin for
@@ -138,6 +138,8 @@ section.
138
138
  the `Request` object with a method to access raw URL components.
139
139
  - [`@fastify/view`](https://github.com/fastify/point-of-view) Templates
140
140
  rendering (_ejs, pug, handlebars, marko_) plugin support for Fastify.
141
+ - [`@fastify/vite`](https://github.com/fastify/fastify-vite) Integration with
142
+ [Vite](https://vitejs.dev/), allows for serving SPA/MPA/SSR Vite applications.
141
143
  - [`@fastify/websocket`](https://github.com/fastify/fastify-websocket) WebSocket
142
144
  support for Fastify. Built upon [ws](https://github.com/websockets/ws).
143
145
 
@@ -145,6 +147,8 @@ section.
145
147
 
146
148
  - [`@applicazza/fastify-nextjs`](https://github.com/applicazza/fastify-nextjs)
147
149
  Alternate Fastify and Next.js integration.
150
+ - [`@blastorg/fastify-aws-dynamodb-cache`](https://github.com/blastorg/fastify-aws-dynamodb-cache)
151
+ A plugin to help with caching API responses using AWS DynamoDB.
148
152
  - [`@clerk/fastify`](https://github.com/clerkinc/javascript/tree/main/packages/fastify)
149
153
  Add authentication and user management to your Fastify application with Clerk.
150
154
  - [`@coobaha/typed-fastify`](https://github.com/Coobaha/typed-fastify) Strongly
@@ -195,8 +199,13 @@ section.
195
199
  Fast sodium-based crypto for @mgcrea/fastify-session
196
200
  - [`@mgcrea/pino-pretty-compact`](https://github.com/mgcrea/pino-pretty-compact)
197
201
  A custom compact pino-base prettifier
202
+ - [`@scalar/fastify-api-reference`](https://github.com/scalar/scalar/tree/main/packages/fastify-api-reference)
203
+ Beautiful OpenAPI/Swagger API references for Fastify
198
204
  - [`@trubavuong/fastify-seaweedfs`](https://github.com/trubavuong/fastify-seaweedfs)
199
205
  SeaweedFS for Fastify
206
+ - [`apitally`](https://github.com/apitally/nodejs-client) Fastify plugin to
207
+ integrate with [Apitally](https://apitally.io), a simple API monitoring &
208
+ API key management solution.
200
209
  - [`apollo-server-fastify`](https://github.com/apollographql/apollo-server/tree/master/packages/apollo-server-fastify)
201
210
  Run an [Apollo Server](https://github.com/apollographql/apollo-server) to
202
211
  serve GraphQL with Fastify.
@@ -466,8 +475,6 @@ middlewares into Fastify plugins
466
475
  Add `additionalProperties: false` by default to your JSON Schemas.
467
476
  - [`fastify-no-icon`](https://github.com/jsumners/fastify-no-icon) Plugin to
468
477
  eliminate thrown errors for `/favicon.ico` requests.
469
- - [`fastify-nodemailer`](https://github.com/lependu/fastify-nodemailer) Plugin
470
- to share [nodemailer](https://nodemailer.com) transporter across Fastify.
471
478
  - [`fastify-normalize-request-reply`](https://github.com/ericrglass/fastify-normalize-request-reply)
472
479
  Plugin to normalize the request and reply to the Express version 4.x request
473
480
  and response, which allows use of middleware, like swagger-stats, that was
@@ -618,16 +625,18 @@ middlewares into Fastify plugins
618
625
  Useful functions for Twitch Extension Backend Services (EBS).
619
626
  - [`fastify-type-provider-effect-schema`](https://github.com/daotl/fastify-type-provider-effect-schema)
620
627
  Fastify
621
- [type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/)
628
+ [type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/)
622
629
  for [@effect/schema](https://github.com/effect-ts/schema).
623
630
  - [`fastify-type-provider-zod`](https://github.com/turkerdev/fastify-type-provider-zod)
624
631
  Fastify
625
- [type provider](https://www.fastify.io/docs/latest/Reference/Type-Providers/)
632
+ [type provider](https://www.fastify.dev/docs/latest/Reference/Type-Providers/)
626
633
  for [zod](https://github.com/colinhacks/zod).
627
634
  - [`fastify-typeorm-plugin`](https://github.com/inthepocket/fastify-typeorm-plugin)
628
635
  Fastify plugin to work with TypeORM.
629
636
  - [`fastify-user-agent`](https://github.com/Eomm/fastify-user-agent) parses your
630
637
  request's `user-agent` header.
638
+ - [`fastify-uws`](https://github.com/geut/fastify-uws) A Fastify plugin to
639
+ use the web server [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js).
631
640
  - [`fastify-vhost`](https://github.com/patrickpissurno/fastify-vhost) Proxy
632
641
  subdomain HTTP requests to another server (useful if you want to point
633
642
  multiple subdomains to the same IP address, while running different servers on
@@ -653,6 +662,9 @@ middlewares into Fastify plugins
653
662
  Parse XML payload / request body into JS / JSON object.
654
663
  - [`fastify-xray`](https://github.com/jeromemacias/fastify-xray) Fastify plugin
655
664
  for AWS XRay recording.
665
+ - [`http-wizard`](https://github.com/flodlc/http-wizard)
666
+ Exports a typescript api client for your Fastify api and ensures fullstack type
667
+ safety for your project.
656
668
  - [`i18next-http-middleware`](https://github.com/i18next/i18next-http-middleware#fastify-usage)
657
669
  An [i18next](https://www.i18next.com) based i18n (internationalization)
658
670
  middleware to be used with Node.js web frameworks like Express or Fastify and
@@ -178,7 +178,7 @@ fastify.listen({ port: 3000 }, function (err, address) {
178
178
  /**
179
179
  * Encapsulates the routes
180
180
  * @param {FastifyInstance} fastify Encapsulated Fastify Instance
181
- * @param {Object} options plugin options, refer to https://www.fastify.io/docs/latest/Reference/Plugins/#plugin-options
181
+ * @param {Object} options plugin options, refer to https://www.fastify.dev/docs/latest/Reference/Plugins/#plugin-options
182
182
  */
183
183
  async function routes (fastify, options) {
184
184
  fastify.get('/', async (request, reply) => {
@@ -293,7 +293,7 @@ const fastifyPlugin = require('fastify-plugin')
293
293
  /**
294
294
  * Connects to a MongoDB database
295
295
  * @param {FastifyInstance} fastify Encapsulated Fastify Instance
296
- * @param {Object} options plugin options, refer to https://www.fastify.io/docs/latest/Reference/Plugins/#plugin-options
296
+ * @param {Object} options plugin options, refer to https://www.fastify.dev/docs/latest/Reference/Plugins/#plugin-options
297
297
  */
298
298
  async function dbConnector (fastify, options) {
299
299
  fastify.register(require('@fastify/mongodb'), {
@@ -312,7 +312,7 @@ module.exports = fastifyPlugin(dbConnector)
312
312
  /**
313
313
  * A plugin that provide encapsulated routes
314
314
  * @param {FastifyInstance} fastify encapsulated fastify instance
315
- * @param {Object} options plugin options, refer to https://www.fastify.io/docs/latest/Reference/Plugins/#plugin-options
315
+ * @param {Object} options plugin options, refer to https://www.fastify.dev/docs/latest/Reference/Plugins/#plugin-options
316
316
  */
317
317
  async function routes (fastify, options) {
318
318
  const collection = fastify.mongo.db.collection('test_collection')
@@ -493,8 +493,8 @@ use case, you can use the
493
493
 
494
494
  ```js
495
495
  const warning = require('process-warning')()
496
- warning.create('FastifyDeprecation', 'FST_ERROR_CODE', 'message')
497
- warning.emit('FST_ERROR_CODE')
496
+ warning.create('MyPluginWarning', 'MP_ERROR_CODE', 'message')
497
+ warning.emit('MP_ERROR_CODE')
498
498
  ```
499
499
 
500
500
  ## Let's start!
@@ -13,7 +13,7 @@ This guide is for anyone who loves to build with Fastify or wants to contribute
13
13
  to our documentation. You do not need to be an expert in writing technical
14
14
  documentation. This guide is here to help you.
15
15
 
16
- Visit the [contribute](https://www.fastify.io/contribute) page on our website or
16
+ Visit the [contribute](https://www.fastify.dev/contribute) page on our website or
17
17
  read the
18
18
  [CONTRIBUTING.md](https://github.com/fastify/fastify/blob/main/CONTRIBUTING.md)
19
19
  file on GitHub to join our Open Source folks.
@@ -70,12 +70,12 @@ markdown.
70
70
  **Example**
71
71
 
72
72
  ```
73
- To learn more about hooks, see [Fastify hooks](https://www.fastify.io/docs/latest/Reference/Hooks/).
73
+ To learn more about hooks, see [Fastify hooks](https://www.fastify.dev/docs/latest/Reference/Hooks/).
74
74
  ```
75
75
 
76
76
  Result:
77
77
  >To learn more about hooks, see [Fastify
78
- >hooks](https://www.fastify.io/docs/latest/Reference/Hooks/).
78
+ >hooks](https://www.fastify.dev/docs/latest/Reference/Hooks/).
79
79
 
80
80
 
81
81
 
@@ -224,18 +224,18 @@ hyperlink should look:
224
224
  <!-- More like this -->
225
225
 
226
226
  // Add clear & brief description
227
- [Fastify Plugins] (https://www.fastify.io/docs/latest/Plugins/)
227
+ [Fastify Plugins] (https://www.fastify.dev/docs/latest/Plugins/)
228
228
 
229
229
  <!--Less like this -->
230
230
 
231
231
  // incomplete description
232
- [Fastify] (https://www.fastify.io/docs/latest/Plugins/)
232
+ [Fastify] (https://www.fastify.dev/docs/latest/Plugins/)
233
233
 
234
234
  // Adding title in link brackets
235
- [](https://www.fastify.io/docs/latest/Plugins/ "fastify plugin")
235
+ [](https://www.fastify.dev/docs/latest/Plugins/ "fastify plugin")
236
236
 
237
237
  // Empty title
238
- [](https://www.fastify.io/docs/latest/Plugins/)
238
+ [](https://www.fastify.dev/docs/latest/Plugins/)
239
239
 
240
240
  // Adding links localhost URLs instead of using code strings (``)
241
241
  [http://localhost:3000/](http://localhost:3000/)
@@ -4,6 +4,8 @@
4
4
  Natively, Fastify only supports `'application/json'` and `'text/plain'` content
5
5
  types. If the content type is not one of these, an
6
6
  `FST_ERR_CTP_INVALID_MEDIA_TYPE` error will be thrown.
7
+ Other common content types are supported through the use of
8
+ [plugins](https://fastify.dev/ecosystem/).
7
9
 
8
10
  The default charset is `utf-8`. If you need to support different content types,
9
11
  you can use the `addContentTypeParser` API. *The default JSON and/or plain text