diff --git a/README.md b/README.md index 4783c53..15d7cfe 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/fastify/fastify-rate-limit/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/fastify/fastify-rate-limit/actions/workflows/ci.yml) [![NPM version](https://img.shields.io/npm/v/@fastify/rate-limit.svg?style=flat)](https://www.npmjs.com/package/@fastify/rate-limit) -[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/) +[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard) A low overhead rate limiter for your routes. diff --git a/package.json b/package.json index d6d45bc..43f34c9 100644 --- a/package.json +++ b/package.json @@ -6,8 +6,8 @@ "type": "commonjs", "types": "types/index.d.ts", "scripts": { - "lint": "standard", - "lint:fix": "standard --fix", + "lint": "eslint", + "lint:fix": "eslint --fix", "redis": "docker run -p 6379:6379 --name rate-limit-redis -d --rm redis", "test": "npm run test:unit && npm run test:typescript", "test:unit": "c8 --100 node --test", @@ -36,8 +36,8 @@ "fastify": "^5.0.0", "ioredis": "^5.4.1", "knex": "^3.1.0", + "neostandard": "^0.11.9", "sqlite3": "^5.1.7", - "standard": "^17.1.0", "tsd": "^0.31.1" }, "dependencies": { diff --git a/types/index.d.ts b/types/index.d.ts index 5cf44eb..f30c760 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,14 +8,14 @@ import { preHandlerAsyncHookHandler, RouteGenericInterface, RouteOptions -} from 'fastify'; +} from 'fastify' declare module 'fastify' { interface FastifyInstance { rateLimit< RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, - SchemaCompiler extends FastifySchema = FastifySchema, + SchemaCompiler extends FastifySchema = FastifySchema >(options?: fastifyRateLimit.RateLimitOptions): preHandlerAsyncHookHandler< RawServer, RawRequest, @@ -32,7 +32,7 @@ declare module 'fastify' { } } -type FastifyRateLimit = FastifyPluginCallback; +type FastifyRateLimit = FastifyPluginCallback declare namespace fastifyRateLimit { @@ -144,5 +144,5 @@ declare namespace fastifyRateLimit { export { fastifyRateLimit as default } } -declare function fastifyRateLimit(...params: Parameters): ReturnType +declare function fastifyRateLimit (...params: Parameters): ReturnType export = fastifyRateLimit diff --git a/types/index.test-d.ts b/types/index.test-d.ts index bc8e2d8..72e55e4 100644 --- a/types/index.test-d.ts +++ b/types/index.test-d.ts @@ -7,7 +7,7 @@ import fastify, { } from 'fastify' import * as http2 from 'http2' import { default as ioredis } from 'ioredis' -import pino from 'pino'; +import pino from 'pino' import fastifyRateLimit, { errorResponseBuilderContext, FastifyRateLimitOptions, @@ -16,15 +16,16 @@ import fastifyRateLimit, { } from '..' class CustomStore implements FastifyRateLimitStore { - constructor(options: FastifyRateLimitOptions) {} - incr( + constructor (options: FastifyRateLimitOptions) {} + incr ( key: string, callback: ( error: Error | null, result?: { current: number; ttl: number } ) => void ) {} - child(routeOptions: RouteOptions & { path: string; prefix: string }) { + + child (routeOptions: RouteOptions & { path: string; prefix: string }) { return ({}) } } @@ -49,13 +50,13 @@ const options1: RateLimitPluginOptions = { if (context.ban) { return { statusCode: 403, - error: "Forbidden", + error: 'Forbidden', message: `You can not access this service as you have sent too many requests that exceed your rate limit. Your IP: ${req.ip} and Limit: ${context.max}`, } } else { return { statusCode: 429, - error: "Too Many Requests", + error: 'Too Many Requests', message: `You hit the rate limit, please slow down! You can retry in ${context.after}`, } } @@ -144,7 +145,7 @@ const options9: RateLimitPluginOptions = { appWithImplicitHttp.register(fastifyRateLimit, options1) appWithImplicitHttp.register(fastifyRateLimit, options2) appWithImplicitHttp.register(fastifyRateLimit, options5) -appWithImplicitHttp.register(fastifyRateLimit,options9) +appWithImplicitHttp.register(fastifyRateLimit, options9) appWithImplicitHttp.register(fastifyRateLimit, options3).then(() => { const preHandler1: preHandlerAsyncHookHandler = appWithImplicitHttp.rateLimit() @@ -160,7 +161,7 @@ appWithImplicitHttp.register(fastifyRateLimit, options3).then(() => { // }) }) -appWithImplicitHttp.get('/', { config: { rateLimit: { max: 10, timeWindow: "60s" } } }, () => { return "limited" }) +appWithImplicitHttp.get('/', { config: { rateLimit: { max: 10, timeWindow: '60s' } } }, () => { return 'limited' }) const appWithHttp2: FastifyInstance< http2.Http2Server, @@ -176,7 +177,6 @@ appWithHttp2.register(fastifyRateLimit, options7) appWithHttp2.register(fastifyRateLimit, options8) appWithHttp2.register(fastifyRateLimit, options9) - appWithHttp2.get('/public', { config: { rateLimit: false