-
-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support fastify v3 #15
Changes from 8 commits
ae2e12e
f4424ef
7ff49ff
1acae18
448e01d
56b10b5
facafa1
62d605a
ca1a737
466714f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Node CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x] | ||
os: [ubuntu-latest, macOS-latest, windows-latest] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
|
||
- name: Install | ||
run: | | ||
npm install | ||
|
||
- name: Test | ||
run: | | ||
npm test |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,32 @@ | ||
import fastify = require('fastify'); | ||
|
||
import { Server, IncomingMessage, ServerResponse } from 'http'; | ||
import { | ||
FastifyRequest, | ||
FastifyPlugin, | ||
FastifyReply, | ||
onRequestHookHandler, | ||
preParsingHookHandler, | ||
preValidationHookHandler, | ||
preHandlerHookHandler | ||
} from 'fastify' | ||
|
||
declare module 'fastify' { | ||
interface FastifyInstance<HttpServer, HttpRequest, HttpResponse> { | ||
basicAuth: FastifyMiddleware<HttpServer, HttpRequest, HttpResponse>; | ||
interface FastifyInstance { | ||
basicAuth: onRequestHookHandler | | ||
preParsingHookHandler | | ||
preValidationHookHandler | | ||
preHandlerHookHandler | ||
} | ||
} | ||
|
||
declare const fastifyBasicAuth: fastify.Plugin< | ||
Server, | ||
IncomingMessage, | ||
ServerResponse, | ||
{ | ||
validate: ( | ||
username: string, | ||
password: string, | ||
req: fastify.FastifyRequest, | ||
reply: fastify.FastifyReply<ServerResponse>, | ||
done: (err?: Error) => void | ||
) => void; | ||
authenticate?: boolean | { realm: string }; | ||
} | ||
>; | ||
export interface FastifyBasicAuthOptions { | ||
validate( | ||
username: string, | ||
password: string, | ||
req: FastifyRequest, | ||
reply: FastifyReply, | ||
done: (err?: Error) => void | ||
): void | Promise<void>; | ||
authenticate?: boolean | { realm: string }; | ||
} | ||
|
||
export = fastifyBasicAuth; | ||
declare const fastifyBasicAuth: FastifyPlugin<FastifyBasicAuthOptions> | ||
export default fastifyBasicAuth; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { expectType, expectAssignable } from 'tsd' | ||
import fastify, { | ||
FastifyRequest, | ||
FastifyReply, | ||
onRequestHookHandler, | ||
preParsingHookHandler, | ||
preValidationHookHandler, | ||
preHandlerHookHandler | ||
} from 'fastify' | ||
import fastifyBasicAuth from '.' | ||
|
||
const app = fastify() | ||
|
||
app.register(fastifyBasicAuth, { | ||
validate: async function validatePromise (username, password, req, reply) { | ||
expectType<string>(username) | ||
expectType<string>(password) | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
} | ||
}) | ||
|
||
app.register(fastifyBasicAuth, { | ||
validate: function validateCallback (username, password, req, reply, done) { | ||
expectType<string>(username) | ||
expectType<string>(password) | ||
expectType<FastifyRequest>(req) | ||
expectType<FastifyReply>(reply) | ||
expectAssignable<(err?: Error) => void>(done) | ||
} | ||
}) | ||
|
||
expectAssignable<onRequestHookHandler>(app.basicAuth) | ||
expectAssignable<preParsingHookHandler>(app.basicAuth) | ||
expectAssignable<preValidationHookHandler>(app.basicAuth) | ||
expectAssignable<preHandlerHookHandler>(app.basicAuth) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"typescript": "tsc --project ./test/types/tsconfig.json", | ||
"test": "standard && tap test/*.test.js && npm run typescript" | ||
"test": "standard && tap test.js && tsd" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -26,15 +25,18 @@ | |
}, | ||
"homepage": "https://github.com/fastify/fastify-basic-auth#readme", | ||
"devDependencies": { | ||
"@types/node": "^12.7.12", | ||
"fastify": "^2.0.0", | ||
"fastify-auth": "^0.3.0", | ||
"standard": "^11.0.1", | ||
"tap": "^12.0.1" | ||
"fastify": "^3.0.0-alpha.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can use |
||
"fastify-auth": "^0.7.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be published and then it can be updated with the new types @mcollina is fastify-auth ready to go? I can publish major if so |
||
"standard": "^14.3.3", | ||
"tap": "^14.10.7", | ||
"tsd": "^0.11.0" | ||
}, | ||
"dependencies": { | ||
"basic-auth": "^2.0.0", | ||
"fastify-plugin": "^1.0.1", | ||
"http-errors": "^1.7.2" | ||
"basic-auth": "^2.0.1", | ||
"fastify-plugin": "^2.0.0", | ||
"http-errors": "^1.7.3" | ||
}, | ||
"engines": { | ||
"node": ">=10.0.0" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could be
>=3.x
now right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just do 3.x