-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test-d.ts
35 lines (29 loc) · 896 Bytes
/
index.test-d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {expectAssignable} from 'tsd'
import fastify, {
FastifyRequest
} from 'fastify'
import fastifyApiKey from '.'
const app = fastify()
app.register(fastifyApiKey, {
getSecret: async function validatePromise(request, keyId) {
expectAssignable<FastifyRequest>(request)
expectAssignable<string>(keyId)
},
requestLifetime: 300
})
app.register(fastifyApiKey, {
getSecret: function validateCallback(request, keyId, cb) {
expectAssignable<FastifyRequest>(request)
expectAssignable<string>(keyId)
expectAssignable<(e: Error | null | undefined, secret: string | undefined) => void>(cb)
},
requestLifetime: 300
})
app.addHook("preHandler", async (request, reply) => {
expectAssignable<Function>(request.apiKeyVerify)
try {
await request.apiKeyVerify();
} catch (err) {
reply.send(err);
}
});