@captcha-kit/core 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +169 -0
  3. package/dist/Factory/CaptchaFactory.d.ts +16 -0
  4. package/dist/Factory/CaptchaFactory.js +32 -0
  5. package/dist/Factory/index.d.ts +1 -0
  6. package/dist/Factory/index.js +1 -0
  7. package/dist/Function/getCaptchaFormElement.d.ts +8 -0
  8. package/dist/Function/getCaptchaFormElement.js +8 -0
  9. package/dist/Function/getCaptchaScript.d.ts +8 -0
  10. package/dist/Function/getCaptchaScript.js +8 -0
  11. package/dist/Function/index.d.ts +3 -0
  12. package/dist/Function/index.js +3 -0
  13. package/dist/Function/verifyCaptcha.d.ts +9 -0
  14. package/dist/Function/verifyCaptcha.js +9 -0
  15. package/dist/Interface/CaptchaFactoryInterface.d.ts +15 -0
  16. package/dist/Interface/CaptchaFactoryInterface.js +1 -0
  17. package/dist/Interface/CaptchaInterface.d.ts +18 -0
  18. package/dist/Interface/CaptchaInterface.js +1 -0
  19. package/dist/Interface/index.d.ts +2 -0
  20. package/dist/Interface/index.js +2 -0
  21. package/dist/Type/Types.d.ts +3 -0
  22. package/dist/Type/Types.js +1 -0
  23. package/dist/Type/index.d.ts +1 -0
  24. package/dist/Type/index.js +1 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.js +4 -0
  27. package/eslint.config.mjs +6 -0
  28. package/package.json +32 -0
  29. package/src/Factory/CaptchaFactory.ts +44 -0
  30. package/src/Factory/index.ts +1 -0
  31. package/src/Function/getCaptchaFormElement.tsx +11 -0
  32. package/src/Function/getCaptchaScript.tsx +11 -0
  33. package/src/Function/index.tsx +3 -0
  34. package/src/Function/verifyCaptcha.ts +12 -0
  35. package/src/Interface/CaptchaFactoryInterface.ts +17 -0
  36. package/src/Interface/CaptchaInterface.ts +21 -0
  37. package/src/Interface/index.ts +2 -0
  38. package/src/Type/Types.ts +6 -0
  39. package/src/Type/index.ts +1 -0
  40. package/src/index.tsx +4 -0
  41. package/tests/getCaptchaFormElement.test.tsx +25 -0
  42. package/tests/getCaptchaScript.test.tsx +25 -0
  43. package/tests/verifyCaptcha.test.ts +31 -0
  44. package/tsconfig.eslint.json +4 -0
  45. package/tsconfig.json +38 -0
  46. 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
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["**/*.ts", "**/*.tsx"],
4
+ }
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
+ }
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'node',
7
+ include: ['tests/**/*.test.ts']
8
+ }
9
+ });