Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
  • Loading branch information
112RG committed Oct 2, 2023
1 parent 2c4c501 commit bc1f51a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"captcha"
],
"main": "index.js",
"types": "types/index.d.ts",
"scripts": {
"lint": "standard | snazzy",
"lint:fix": "standard --fix",
Expand All @@ -33,6 +34,7 @@
"standard": "^17.1.0",
"tap": "^18.4.0",
"ts-standard": "^12.0.2",
"tsd": "^0.29.0"
},
"dependencies": {
"fastify-plugin": "^4.5.1"
Expand Down
42 changes: 42 additions & 0 deletions types/index.d.ts
@@ -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
20 changes: 20 additions & 0 deletions types/index.test-d.ts
@@ -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)

0 comments on commit bc1f51a

Please sign in to comment.