feat: add types of geetest (#23069)

This commit is contained in:
York Yao 2018-01-24 02:35:45 +08:00 committed by Andy
parent 27b74af5a2
commit 7a3a2f77d5
4 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,41 @@
import Geetest = require('geetest');
const captcha = new Geetest({
geetest_id: 'xxx',
geetest_key: 'xxx',
});
captcha.register((err, data) => {
if (err) {
return;
}
const body = {
gt: data.geetest_id,
challenge: data.challenge,
success: data.success,
};
});
captcha.register().then((data) => {
const body = {
gt: data.geetest_id,
challenge: data.challenge,
success: data.success,
};
}, (err) => {
});
captcha.validate({
challenge: 'xxx',
validate: 'xxx',
seccode: 'xxx',
}, (err, success) => {
});
captcha.validate({
challenge: 'xxx',
validate: 'xxx',
seccode: 'xxx',
}).then((success) => {
}, (err) => {
});

37
types/geetest/index.d.ts vendored Normal file
View File

@ -0,0 +1,37 @@
// Type definitions for geetest 4.1
// Project: https://github.com/GeeTeam/gt-node-sdk#readme
// Definitions by: York Yao <https://github.com/plantain-00>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Options {
geetest_id: string;
geetest_key: string;
protocol?: string;
api_server?: string;
}
type Success = 0 | 1;
interface Data {
geetest_id: string;
gt: string;
challenge: string;
success: Success;
new_captcha: string;
}
interface Result {
challenge: string;
validate: string;
seccode: string;
}
declare class Geetest {
constructor(options: Options);
register(callback: (error: Error, data: Data) => void): void;
register(): Promise<Data>;
validate(result: Result, callback: (error: Error, success: Success) => void): void;
validate(result: Result): Promise<Success>;
}
export = Geetest;

View File

@ -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",
"geetest-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }