-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: plugin types * wip: declare `fastify` decorators * fix: plugin is a `FastifyPluginCallback` - not `async` * wip: `import type`s * wip: initial tests for plugin * wip: refactor types test * wip: shorten type names * wip: add decorator tests * wip: test shape of plugin * wip: add types to `package.json`
- Loading branch information
1 parent
1110d4f
commit 8705d76
Showing
4 changed files
with
1,511 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { type FastifyJWTOptions, type VerifyPayloadType } from '@fastify/jwt' | ||
import { type FastifyPluginCallback, type FastifyReply, type FastifyRequest } from 'fastify' | ||
import { type GetJwksOptions } from 'get-jwks' | ||
import { type URL, type UrlObject } from 'url' | ||
|
||
export interface JWTOptions extends FastifyJWTOptions { | ||
namespace?: string | ||
jwks?: boolean | GetJwksOptions | ||
} | ||
|
||
export interface WebhookOptions { | ||
url: string | URL | UrlObject | ||
} | ||
|
||
export type CreateSession = (request?: FastifyRequest, reply?: FastifyReply) => Promise<void> | ||
|
||
export interface AuthStrategy { | ||
name: string, | ||
createSession: CreateSession | ||
} | ||
|
||
export interface FastifyUserPluginOptions { | ||
jwt?: JWTOptions | ||
webhook?: WebhookOptions | ||
authStrategies?: AuthStrategy[] | ||
} | ||
|
||
export type AddAuthStrategyDecorator = (strategy: AuthStrategy) => void | ||
export type ExtractUserDecorator = () => Promise<any> | ||
export type CreateSessionDecorator = () => Promise<void> | ||
export type CreateJWTSessionDecorator = () => Promise<VerifyPayloadType> | ||
export type CreateWebhookSessionDecorator = () => Promise<void> | ||
|
||
declare module 'fastify' { | ||
interface FastifyInstance { | ||
addAuthStrategy: AddAuthStrategyDecorator | ||
} | ||
interface FastifyRequest { | ||
extractUser: ExtractUserDecorator | ||
createSession: CreateSessionDecorator | ||
createJWTSession: CreateJWTSessionDecorator | ||
createWebhookSession: CreateWebhookSessionDecorator | ||
} | ||
} | ||
|
||
declare const fastifyUser: FastifyPluginCallback<FastifyUserPluginOptions> | ||
|
||
export default fastifyUser |
Oops, something went wrong.