Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 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
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,42 @@ | ||
import { | ||
FastifyPluginCallback, | ||
} from 'fastify'; | ||
|
||
declare module 'fastify' { | ||
interface FastifyContextConfig { | ||
cfTurnstile?: fastifyCfTurnstile.FastifyCfTurnstileOptions; | ||
} | ||
} | ||
|
||
type FastifyCfTurnstile = FastifyPluginCallback<fastifyCfTurnstile.FastifyCfTurnstileOptions>; | ||
|
||
/** | ||
* Namespace for fastify-cf-turnstile plugin options. | ||
* | ||
* @namespace fastifyCfTurnstile | ||
*/ | ||
declare namespace fastifyCfTurnstile { | ||
/** | ||
* Options for configuring the fastify-cf-turnstile plugin. | ||
* | ||
* @interface FastifyCfTurnstileOptions | ||
*/ | ||
export interface FastifyCfTurnstileOptions { | ||
/** | ||
* CloudFlare Turnstile sitekey | ||
* @type {string} | ||
*/ | ||
sitekey: string | ||
|
||
/** | ||
* CloudFlare Turnstile privatekey | ||
* @type {string} | ||
*/ | ||
privatekey: string | ||
} | ||
export const fastifyCfTurnstile: FastifyCfTurnstile | ||
export { fastifyCfTurnstile as default } | ||
} | ||
|
||
declare function fastifyCfTurnstile(...params: Parameters<FastifyCfTurnstile>): ReturnType<FastifyCfTurnstile> | ||
export = fastifyCfTurnstile |
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,20 @@ | ||
import fastify, { | ||
FastifyInstance, | ||
} from 'fastify'; | ||
import { expectError, expectAssignable } from 'tsd'; | ||
import { FastifyCfTurnstileOptions, default as plugin } from '.'; | ||
|
||
const app: FastifyInstance = fastify(); | ||
|
||
const fastifyCfTurnstileOptions = { | ||
sitekey: 'test', | ||
privatekey: 'test' | ||
} | ||
|
||
app.register(plugin, { | ||
sitekey: 'test', | ||
privatekey: 'test' | ||
}) | ||
expectError(app.register(plugin, {})) | ||
|
||
expectAssignable<FastifyCfTurnstileOptions>(fastifyCfTurnstileOptions) |