@fastify/sensible
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -13,3 +13,3 @@ interface HttpError extends Error { | ||
type HttpErrorCodes = 400 | '400' // BadRequest | ||
export type HttpErrorCodes = 400 | '400' // BadRequest | ||
| 401 | '401' // Unauthorized | ||
@@ -56,3 +56,3 @@ | 402 | '402' // PaymentRequired | ||
type HttpErrorNames = 'badRequest' | ||
export type HttpErrorNames = 'badRequest' | ||
| 'unauthorized' | ||
@@ -59,0 +59,0 @@ | 'paymentRequired' |
{ | ||
"name": "@fastify/sensible", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "Defaults for Fastify that everyone can agree on", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -57,3 +57,3 @@ # @fastify/sensible | ||
fastify.register(require('@fastify/sensible'), { | ||
sharedSchemaId: 'httpError' | ||
sharedSchemaId: 'HttpError' | ||
}) | ||
@@ -64,3 +64,3 @@ | ||
response: { | ||
404: { $ref: 'httpError' } | ||
404: { $ref: 'HttpError' } | ||
} | ||
@@ -67,0 +67,0 @@ } |
import { FastifyPluginCallback, FastifyReply } from 'fastify' | ||
import { HttpErrors, HttpErrorCodes, HttpErrorNames } from "../lib/httpError" | ||
import * as Errors from '../lib/httpError' | ||
type FastifySensible = FastifyPluginCallback<fastifySensible.SensibleOptions> | ||
type singleValueTypes = 'must-revalidate' | | ||
'no-cache' | | ||
'no-store' | | ||
'no-transform' | | ||
'public' | | ||
'private' | | ||
'proxy-revalidate' | | ||
'immutable' | ||
type singleValueTypes = | ||
| 'must-revalidate' | ||
| 'no-cache' | ||
| 'no-store' | ||
| 'no-transform' | ||
| 'public' | ||
| 'private' | ||
| 'proxy-revalidate' | ||
| 'immutable' | ||
type multiValueTypes = 'max-age' | | ||
's-maxage' | | ||
'stale-while-revalidate' | | ||
'stale-if-error' | ||
type multiValueTypes = | ||
| 'max-age' | ||
| 's-maxage' | ||
| 'stale-while-revalidate' | ||
| 'stale-if-error' | ||
type staleTypes = 'while-revalidate' | 'if-error' | ||
type HttpErrorReplys = { | ||
getHttpError: (code: HttpErrorCodes, message?: string) => FastifyReply; | ||
} & Record<HttpErrorNames, (msg?: string) => FastifyReply>; | ||
declare module 'fastify' { | ||
@@ -48,3 +47,3 @@ namespace SensibleTypes { | ||
interface FastifyReply extends HttpErrorReplys { | ||
interface FastifyReply extends fastifySensible.HttpErrorReplys { | ||
vary: { | ||
@@ -72,4 +71,32 @@ (field: string | string[]): void; | ||
export interface SensibleOptions { | ||
/** | ||
* This option registers a shared JSON Schema to be used by all response schemas. | ||
* | ||
* @example | ||
* ```js | ||
* fastify.register(require('@fastify/sensible'), { | ||
* sharedSchemaId: 'HttpError' | ||
* }) | ||
* | ||
* fastify.get('/async', { | ||
* schema: { | ||
* response: { 404: { $ref: 'HttpError' } } | ||
* } | ||
* handler: async (req, reply) => { | ||
* return reply.notFound() | ||
* } | ||
* }) | ||
* ``` | ||
*/ | ||
sharedSchemaId?: string; | ||
} | ||
export type HttpErrors = Errors.HttpErrors; | ||
export type HttpErrorCodes = Errors.HttpErrorCodes; | ||
export type HttpErrorNames = Errors.HttpErrorNames; | ||
export type HttpErrorReplys = { | ||
getHttpError: (code: HttpErrorCodes, message?: string) => FastifyReply; | ||
} & Record<HttpErrorNames, (msg?: string) => FastifyReply> | ||
export const fastifySensible: FastifySensible | ||
@@ -80,2 +107,2 @@ export { fastifySensible as default } | ||
declare function fastifySensible(...params: Parameters<FastifySensible>): ReturnType<FastifySensible> | ||
export = fastifySensible | ||
export = fastifySensible |
@@ -1,4 +0,4 @@ | ||
import { expectType, expectAssignable, expectError } from 'tsd' | ||
import { expectType, expectAssignable, expectError, expectNotAssignable } from 'tsd' | ||
import fastify from 'fastify' | ||
import fastifySensible from '..' | ||
import fastifySensible, { SensibleOptions } from '..' | ||
@@ -9,2 +9,6 @@ const app = fastify() | ||
expectAssignable<SensibleOptions>({}); | ||
expectAssignable<SensibleOptions>({ sharedSchemaId: 'HttpError' }); | ||
expectNotAssignable<SensibleOptions>({ notSharedSchemaId: 'HttpError' }); | ||
app.get('/', (req, reply) => { | ||
@@ -11,0 +15,0 @@ expectAssignable<typeof reply>(reply.badRequest()) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
61337
1513
2