Socket
Socket
Sign inDemoInstall

@fastify/sensible

Package Overview
Dependencies
Maintainers
20
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fastify/sensible - npm Package Compare versions

Comparing version 5.3.0 to 5.4.0

4

lib/httpError.d.ts

@@ -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())

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc