mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Add types for recaptcha2 (#25643)
This commit is contained in:
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// Type definitions for recaptcha2 1.3
|
||||
// Project: https://github.com/fereidani/recaptcha2#readme
|
||||
// Definitions by: Jonas Lochmann <https://github.com/l-jonas>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export = Recaptcha2;
|
||||
|
||||
declare class Recaptcha2 {
|
||||
constructor(options: Recaptcha2.Options);
|
||||
|
||||
getRequestOptions<T extends object>(body: T): Recaptcha2.RequestOptions<T>;
|
||||
validate(token: string): Promise<void>;
|
||||
validateRequest(req: object, ip: string): Promise<void>;
|
||||
translateErrors(errorCodes: string): string;
|
||||
translateErrors(errorCodes: string[]): string[];
|
||||
formElement(htmlClass: string): string;
|
||||
}
|
||||
|
||||
declare namespace Recaptcha2 {
|
||||
interface Options {
|
||||
siteKey: string;
|
||||
secretKey: string;
|
||||
ssl?: boolean;
|
||||
}
|
||||
|
||||
interface RequestOptions<T> {
|
||||
uri: string;
|
||||
method: 'POST';
|
||||
json: true;
|
||||
form: T;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import * as reCAPTCHA from 'recaptcha2';
|
||||
|
||||
const recaptcha = new reCAPTCHA({
|
||||
siteKey: 'your-site-key',
|
||||
secretKey: 'your-secret-key'
|
||||
});
|
||||
|
||||
const key = 'invalid';
|
||||
|
||||
recaptcha.validate(key)
|
||||
.then(() => {
|
||||
// validated and secure
|
||||
})
|
||||
.catch((errorCodes) => {
|
||||
// translate error codes to human readable text
|
||||
const message = recaptcha.translateErrors(errorCodes);
|
||||
});
|
||||
|
||||
const formSnippet = recaptcha.formElement('recaptcha');
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"recaptcha2-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user