@kcaptcha/client 0.1.0
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.
- package/dist/api.d.ts +32 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +1044 -0
- package/dist/kcaptcha.js +191 -0
- package/dist/options.d.ts +36 -0
- package/dist/renderer.d.ts +23 -0
- package/dist/styles.d.ts +1 -0
- package/dist/widget.d.ts +59 -0
- package/package.json +27 -0
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface Geometry {
|
|
2
|
+
width: number;
|
|
3
|
+
height: number;
|
|
4
|
+
spacing: number;
|
|
5
|
+
/** Each pipe is a flat polyline [x0, y0, x1, y1, ...]. */
|
|
6
|
+
pipes: number[][];
|
|
7
|
+
}
|
|
8
|
+
export interface Challenge {
|
|
9
|
+
token: string;
|
|
10
|
+
geometry: Geometry;
|
|
11
|
+
expiresIn: number;
|
|
12
|
+
}
|
|
13
|
+
export interface VerifyResult {
|
|
14
|
+
token: string;
|
|
15
|
+
expiresIn: number;
|
|
16
|
+
}
|
|
17
|
+
/** code examples: incorrect, expired, replayed, rate_limited, network_error, http_404 ... */
|
|
18
|
+
export declare class ApiError extends Error {
|
|
19
|
+
readonly code: string;
|
|
20
|
+
readonly status: number;
|
|
21
|
+
readonly retryAfter?: number | undefined;
|
|
22
|
+
constructor(code: string, status: number, retryAfter?: number | undefined);
|
|
23
|
+
}
|
|
24
|
+
export declare class KCaptchaApi {
|
|
25
|
+
private readonly endpoint;
|
|
26
|
+
constructor(endpoint: string);
|
|
27
|
+
/** POST <endpoint>/new-code */
|
|
28
|
+
newCode(): Promise<Challenge>;
|
|
29
|
+
/** POST <endpoint>/verify-captcha */
|
|
30
|
+
verify(token: string, answer: string): Promise<VerifyResult>;
|
|
31
|
+
private post;
|
|
32
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KCaptchaOptions } from './options';
|
|
2
|
+
export interface KCaptchaHandle {
|
|
3
|
+
readonly element: HTMLElement;
|
|
4
|
+
/** The pass token, or null if not verified. */
|
|
5
|
+
getToken(): string | null;
|
|
6
|
+
/** Uncheck the widget. Call this after a failed form submit: a pass token works only once. */
|
|
7
|
+
reset(): void;
|
|
8
|
+
/** Remove the widget and its hidden field. */
|
|
9
|
+
destroy(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare const version = "0.1.0";
|
|
12
|
+
export declare function isMounted(el: HTMLElement): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Render a kCAPTCHA widget into `target` (an element or a CSS selector).
|
|
15
|
+
* Returns null, after printing an error to the console and into the element,
|
|
16
|
+
* if the options are invalid, most importantly if `endpoint` is missing.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mount(target: HTMLElement | string, options: KCaptchaOptions): KCaptchaHandle | null;
|
|
19
|
+
export { KCaptchaOptionError } from './options';
|
|
20
|
+
export type { KCaptchaOptions } from './options';
|