@captcha-kit/core 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +674 -0
- package/README.md +169 -0
- package/dist/Factory/CaptchaFactory.d.ts +16 -0
- package/dist/Factory/CaptchaFactory.js +32 -0
- package/dist/Factory/index.d.ts +1 -0
- package/dist/Factory/index.js +1 -0
- package/dist/Function/getCaptchaFormElement.d.ts +8 -0
- package/dist/Function/getCaptchaFormElement.js +8 -0
- package/dist/Function/getCaptchaScript.d.ts +8 -0
- package/dist/Function/getCaptchaScript.js +8 -0
- package/dist/Function/index.d.ts +3 -0
- package/dist/Function/index.js +3 -0
- package/dist/Function/verifyCaptcha.d.ts +9 -0
- package/dist/Function/verifyCaptcha.js +9 -0
- package/dist/Interface/CaptchaFactoryInterface.d.ts +15 -0
- package/dist/Interface/CaptchaFactoryInterface.js +1 -0
- package/dist/Interface/CaptchaInterface.d.ts +18 -0
- package/dist/Interface/CaptchaInterface.js +1 -0
- package/dist/Interface/index.d.ts +2 -0
- package/dist/Interface/index.js +2 -0
- package/dist/Type/Types.d.ts +3 -0
- package/dist/Type/Types.js +1 -0
- package/dist/Type/index.d.ts +1 -0
- package/dist/Type/index.js +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/eslint.config.mjs +6 -0
- package/package.json +32 -0
- package/src/Factory/CaptchaFactory.ts +44 -0
- package/src/Factory/index.ts +1 -0
- package/src/Function/getCaptchaFormElement.tsx +11 -0
- package/src/Function/getCaptchaScript.tsx +11 -0
- package/src/Function/index.tsx +3 -0
- package/src/Function/verifyCaptcha.ts +12 -0
- package/src/Interface/CaptchaFactoryInterface.ts +17 -0
- package/src/Interface/CaptchaInterface.ts +21 -0
- package/src/Interface/index.ts +2 -0
- package/src/Type/Types.ts +6 -0
- package/src/Type/index.ts +1 -0
- package/src/index.tsx +4 -0
- package/tests/getCaptchaFormElement.test.tsx +25 -0
- package/tests/getCaptchaScript.test.tsx +25 -0
- package/tests/verifyCaptcha.test.ts +31 -0
- package/tsconfig.eslint.json +4 -0
- package/tsconfig.json +38 -0
- package/vitest.config.ts +9 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
2
|
+
import { verifyCaptcha } from '../src/Function/verifyCaptcha';
|
3
|
+
import type { TypeBaseConfig } from '../src/Type/Types';
|
4
|
+
|
5
|
+
vi.mock('../src/Factory', () => {
|
6
|
+
return {
|
7
|
+
CaptchaFactory: vi.fn().mockImplementation(() => {
|
8
|
+
return {
|
9
|
+
create: vi.fn().mockResolvedValue({
|
10
|
+
verifyCaptcha: (formFieldValues: Record<string, any>) => {
|
11
|
+
return formFieldValues.response === 'valid-response';
|
12
|
+
}
|
13
|
+
})
|
14
|
+
};
|
15
|
+
})
|
16
|
+
};
|
17
|
+
});
|
18
|
+
|
19
|
+
describe('verifyCaptcha', () => {
|
20
|
+
const config: TypeBaseConfig = { CAPTCHA_PROVIDER: 'test-provider' };
|
21
|
+
|
22
|
+
it('should return true for valid captcha response', async () => {
|
23
|
+
const result = await verifyCaptcha({ response: 'valid-response' }, config);
|
24
|
+
expect(result).toBe(true);
|
25
|
+
});
|
26
|
+
|
27
|
+
it('should return false for invalid captcha response', async () => {
|
28
|
+
const result = await verifyCaptcha({ response: 'invalid-response' }, config);
|
29
|
+
expect(result).toBe(false);
|
30
|
+
});
|
31
|
+
});
|
package/tsconfig.json
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"jsx": "react",
|
4
|
+
"lib": ["ESNext", "DOM"],
|
5
|
+
"target": "ESNext",
|
6
|
+
"module": "ESNext",
|
7
|
+
|
8
|
+
// Node module resolution
|
9
|
+
"moduleResolution": "node",
|
10
|
+
"verbatimModuleSyntax": true,
|
11
|
+
"esModuleInterop": true,
|
12
|
+
|
13
|
+
// Emit options
|
14
|
+
"declaration": true,
|
15
|
+
"emitDeclarationOnly": false,
|
16
|
+
"rootDir": "./src",
|
17
|
+
"outDir": "./dist",
|
18
|
+
"resolveJsonModule": true,
|
19
|
+
"allowSyntheticDefaultImports": true,
|
20
|
+
|
21
|
+
// Best practices
|
22
|
+
"strict": true,
|
23
|
+
"skipLibCheck": true,
|
24
|
+
"noFallthroughCasesInSwitch": true,
|
25
|
+
|
26
|
+
// Some stricter flags (disabled by default)
|
27
|
+
"noUnusedLocals": true,
|
28
|
+
"noUnusedParameters": true,
|
29
|
+
"noPropertyAccessFromIndexSignature": true,
|
30
|
+
|
31
|
+
"baseUrl": ".",
|
32
|
+
"paths": {
|
33
|
+
"@captcha-kit/*": ["../*/dist"]
|
34
|
+
}
|
35
|
+
},
|
36
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
37
|
+
"exclude": ["node_modules", "dist", "tests"]
|
38
|
+
}
|