k9guard 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,141 @@
1
+ type Difficulty = 'easy' | 'medium' | 'hard';
2
+ interface K9GuardOptions {
3
+ type: 'math' | 'text' | 'sequence' | 'scramble' | 'reverse' | 'mixed' | 'multi' | 'image' | 'emoji';
4
+ difficulty: Difficulty | 'adaptive';
5
+ sessionId?: string;
6
+ }
7
+ interface CustomQuestion {
8
+ question: string;
9
+ answer: string;
10
+ difficulty: Difficulty;
11
+ }
12
+ interface K9GuardCustomOptions {
13
+ type: 'custom';
14
+ questions: CustomQuestion[];
15
+ sessionId?: string;
16
+ }
17
+ interface AdaptiveAttempt {
18
+ timestamp: number;
19
+ success: boolean;
20
+ }
21
+ interface AdaptiveSession {
22
+ attempts: AdaptiveAttempt[];
23
+ currentDifficulty: Difficulty;
24
+ lastAdjustment: number;
25
+ attemptsSinceAdjustment: number;
26
+ }
27
+ interface StoredChallenge {
28
+ type: 'math' | 'text' | 'sequence' | 'scramble' | 'reverse' | 'mixed' | 'multi' | 'custom' | 'image' | 'emoji';
29
+ question: string;
30
+ answer: string | number;
31
+ nonce: string;
32
+ expiry: number;
33
+ hashedAnswer: string;
34
+ salt: string;
35
+ steps?: StoredChallenge[];
36
+ image?: string;
37
+ emojis?: string[];
38
+ category?: string;
39
+ }
40
+ interface CaptchaChallenge {
41
+ type: StoredChallenge['type'];
42
+ question: string;
43
+ nonce: string;
44
+ expiry: number;
45
+ steps?: CaptchaChallenge[];
46
+ image?: string;
47
+ emojis?: string[];
48
+ category?: string;
49
+ }
50
+ interface ImageCaptcha extends CaptchaChallenge {
51
+ type: 'image';
52
+ image: string;
53
+ }
54
+ interface MathCaptcha extends CaptchaChallenge {
55
+ type: 'math';
56
+ }
57
+ interface TextCaptcha extends CaptchaChallenge {
58
+ type: 'text';
59
+ }
60
+ interface SequenceCaptcha extends CaptchaChallenge {
61
+ type: 'sequence';
62
+ }
63
+ interface ScrambleCaptcha extends CaptchaChallenge {
64
+ type: 'scramble';
65
+ }
66
+ interface ReverseCaptcha extends CaptchaChallenge {
67
+ type: 'reverse';
68
+ }
69
+ interface MixedCaptcha extends CaptchaChallenge {
70
+ type: 'mixed';
71
+ }
72
+ interface CustomCaptcha extends CaptchaChallenge {
73
+ type: 'custom';
74
+ }
75
+ interface EmojiCaptcha extends CaptchaChallenge {
76
+ type: 'emoji';
77
+ emojis: string[];
78
+ category: string;
79
+ }
80
+
81
+ declare class K9Guard {
82
+ private options;
83
+ private generator;
84
+ private adaptiveTracker;
85
+ private defaultSessionId;
86
+ constructor(options: K9GuardOptions | K9GuardCustomOptions | {
87
+ type: 'custom';
88
+ questions: CustomQuestion[];
89
+ sessionId?: string;
90
+ });
91
+ private isAdaptive;
92
+ private resolveSessionId;
93
+ private processOptions;
94
+ generate(sessionId?: string): CaptchaChallenge;
95
+ validate(challenge: CaptchaChallenge, userInput: string, sessionId?: string): boolean;
96
+ clearSession(sessionId: string): boolean;
97
+ clearAllSessions(): void;
98
+ getSessionDifficulty(sessionId: string): Difficulty | null;
99
+ private isValidChallenge;
100
+ }
101
+
102
+ declare class CustomQuestionValidator {
103
+ private static readonly MAX_QUESTIONS;
104
+ private static readonly MAX_QUESTION_LENGTH;
105
+ private static readonly MAX_ANSWER_LENGTH;
106
+ private static readonly MIN_QUESTION_LENGTH;
107
+ private static readonly MIN_ANSWER_LENGTH;
108
+ private static readonly VALID_DIFFICULTY;
109
+ static validate(questions: unknown): {
110
+ valid: boolean;
111
+ error?: string;
112
+ };
113
+ private static validateSingle;
114
+ static sanitize(questions: CustomQuestion[]): CustomQuestion[];
115
+ }
116
+
117
+ declare class CustomQuestionGenerator {
118
+ private questions;
119
+ constructor(questions: CustomQuestion[]);
120
+ generate(difficulty?: Difficulty): {
121
+ question: string;
122
+ answer: string;
123
+ };
124
+ private selectRandom;
125
+ }
126
+
127
+ declare class AdaptiveTracker {
128
+ private sessions;
129
+ getDifficulty(sessionId: string): Difficulty;
130
+ recordAttempt(sessionId: string, success: boolean): void;
131
+ getSession(sessionId: string): AdaptiveSession | undefined;
132
+ clearSession(sessionId: string): boolean;
133
+ clearAll(): void;
134
+ get sessionCount(): number;
135
+ private createSession;
136
+ private adjustDifficulty;
137
+ private pruneExpired;
138
+ private evictOldest;
139
+ }
140
+
141
+ export { type AdaptiveAttempt, type AdaptiveSession, AdaptiveTracker, type CaptchaChallenge, type CustomCaptcha, type CustomQuestion, CustomQuestionGenerator, CustomQuestionValidator, type Difficulty, type EmojiCaptcha, type ImageCaptcha, type K9GuardCustomOptions, type K9GuardOptions, type MathCaptcha, type MixedCaptcha, type ReverseCaptcha, type ScrambleCaptcha, type SequenceCaptcha, type StoredChallenge, type TextCaptcha, K9Guard as default };
@@ -0,0 +1,141 @@
1
+ type Difficulty = 'easy' | 'medium' | 'hard';
2
+ interface K9GuardOptions {
3
+ type: 'math' | 'text' | 'sequence' | 'scramble' | 'reverse' | 'mixed' | 'multi' | 'image' | 'emoji';
4
+ difficulty: Difficulty | 'adaptive';
5
+ sessionId?: string;
6
+ }
7
+ interface CustomQuestion {
8
+ question: string;
9
+ answer: string;
10
+ difficulty: Difficulty;
11
+ }
12
+ interface K9GuardCustomOptions {
13
+ type: 'custom';
14
+ questions: CustomQuestion[];
15
+ sessionId?: string;
16
+ }
17
+ interface AdaptiveAttempt {
18
+ timestamp: number;
19
+ success: boolean;
20
+ }
21
+ interface AdaptiveSession {
22
+ attempts: AdaptiveAttempt[];
23
+ currentDifficulty: Difficulty;
24
+ lastAdjustment: number;
25
+ attemptsSinceAdjustment: number;
26
+ }
27
+ interface StoredChallenge {
28
+ type: 'math' | 'text' | 'sequence' | 'scramble' | 'reverse' | 'mixed' | 'multi' | 'custom' | 'image' | 'emoji';
29
+ question: string;
30
+ answer: string | number;
31
+ nonce: string;
32
+ expiry: number;
33
+ hashedAnswer: string;
34
+ salt: string;
35
+ steps?: StoredChallenge[];
36
+ image?: string;
37
+ emojis?: string[];
38
+ category?: string;
39
+ }
40
+ interface CaptchaChallenge {
41
+ type: StoredChallenge['type'];
42
+ question: string;
43
+ nonce: string;
44
+ expiry: number;
45
+ steps?: CaptchaChallenge[];
46
+ image?: string;
47
+ emojis?: string[];
48
+ category?: string;
49
+ }
50
+ interface ImageCaptcha extends CaptchaChallenge {
51
+ type: 'image';
52
+ image: string;
53
+ }
54
+ interface MathCaptcha extends CaptchaChallenge {
55
+ type: 'math';
56
+ }
57
+ interface TextCaptcha extends CaptchaChallenge {
58
+ type: 'text';
59
+ }
60
+ interface SequenceCaptcha extends CaptchaChallenge {
61
+ type: 'sequence';
62
+ }
63
+ interface ScrambleCaptcha extends CaptchaChallenge {
64
+ type: 'scramble';
65
+ }
66
+ interface ReverseCaptcha extends CaptchaChallenge {
67
+ type: 'reverse';
68
+ }
69
+ interface MixedCaptcha extends CaptchaChallenge {
70
+ type: 'mixed';
71
+ }
72
+ interface CustomCaptcha extends CaptchaChallenge {
73
+ type: 'custom';
74
+ }
75
+ interface EmojiCaptcha extends CaptchaChallenge {
76
+ type: 'emoji';
77
+ emojis: string[];
78
+ category: string;
79
+ }
80
+
81
+ declare class K9Guard {
82
+ private options;
83
+ private generator;
84
+ private adaptiveTracker;
85
+ private defaultSessionId;
86
+ constructor(options: K9GuardOptions | K9GuardCustomOptions | {
87
+ type: 'custom';
88
+ questions: CustomQuestion[];
89
+ sessionId?: string;
90
+ });
91
+ private isAdaptive;
92
+ private resolveSessionId;
93
+ private processOptions;
94
+ generate(sessionId?: string): CaptchaChallenge;
95
+ validate(challenge: CaptchaChallenge, userInput: string, sessionId?: string): boolean;
96
+ clearSession(sessionId: string): boolean;
97
+ clearAllSessions(): void;
98
+ getSessionDifficulty(sessionId: string): Difficulty | null;
99
+ private isValidChallenge;
100
+ }
101
+
102
+ declare class CustomQuestionValidator {
103
+ private static readonly MAX_QUESTIONS;
104
+ private static readonly MAX_QUESTION_LENGTH;
105
+ private static readonly MAX_ANSWER_LENGTH;
106
+ private static readonly MIN_QUESTION_LENGTH;
107
+ private static readonly MIN_ANSWER_LENGTH;
108
+ private static readonly VALID_DIFFICULTY;
109
+ static validate(questions: unknown): {
110
+ valid: boolean;
111
+ error?: string;
112
+ };
113
+ private static validateSingle;
114
+ static sanitize(questions: CustomQuestion[]): CustomQuestion[];
115
+ }
116
+
117
+ declare class CustomQuestionGenerator {
118
+ private questions;
119
+ constructor(questions: CustomQuestion[]);
120
+ generate(difficulty?: Difficulty): {
121
+ question: string;
122
+ answer: string;
123
+ };
124
+ private selectRandom;
125
+ }
126
+
127
+ declare class AdaptiveTracker {
128
+ private sessions;
129
+ getDifficulty(sessionId: string): Difficulty;
130
+ recordAttempt(sessionId: string, success: boolean): void;
131
+ getSession(sessionId: string): AdaptiveSession | undefined;
132
+ clearSession(sessionId: string): boolean;
133
+ clearAll(): void;
134
+ get sessionCount(): number;
135
+ private createSession;
136
+ private adjustDifficulty;
137
+ private pruneExpired;
138
+ private evictOldest;
139
+ }
140
+
141
+ export { type AdaptiveAttempt, type AdaptiveSession, AdaptiveTracker, type CaptchaChallenge, type CustomCaptcha, type CustomQuestion, CustomQuestionGenerator, CustomQuestionValidator, type Difficulty, type EmojiCaptcha, type ImageCaptcha, type K9GuardCustomOptions, type K9GuardOptions, type MathCaptcha, type MixedCaptcha, type ReverseCaptcha, type ScrambleCaptcha, type SequenceCaptcha, type StoredChallenge, type TextCaptcha, K9Guard as default };