vue3-smart-captcha
Version:
Yandex Smart Captcha for Vue3 projects
179 lines (145 loc) • 5.54 kB
TypeScript
import { ComponentOptionsMixin } from 'vue';
import { ComponentProvideOptions } from 'vue';
import { DefineComponent } from 'vue';
import { ExtractPropTypes } from 'vue';
import { Plugin as Plugin_2 } from 'vue';
import { PropType } from 'vue';
import { PublicProps } from 'vue';
import { Ref } from 'vue';
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
declare type __VLS_Prettify<T> = {
[K in keyof T]: T[K];
} & {};
declare type __VLS_TypePropsToRuntimeProps<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? {
type: PropType<__VLS_NonUndefinedable<T[K]>>;
} : {
type: PropType<T[K]>;
required: true;
};
};
declare type __VLS_WithDefaults<P, D> = {
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
default: D[K];
}> : P[K];
};
declare type BaseEventCallback = () => void
declare type CaptchaContainer = Ref | HTMLElement | string;
declare type CaptchaSubscriptionEventCallback = BaseEventCallback | SuccessEventCallback | JavascriptErrorEventCallback
declare const _default: DefineComponent<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<SmartCaptchaComponentProps>, {
loadWidget: boolean;
timeout: number;
}>>, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
success: (token: string) => void;
challengeHidden: () => void;
challengeVisible: () => void;
javascriptError: (error: JavascriptError) => void;
networkError: () => void;
tokenExpired: () => void;
initialized: (id: number) => void;
}, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<SmartCaptchaComponentProps>, {
loadWidget: boolean;
timeout: number;
}>>> & Readonly<{
onSuccess?: ((token: string) => any) | undefined;
onChallengeHidden?: (() => any) | undefined;
onChallengeVisible?: (() => any) | undefined;
onJavascriptError?: ((error: JavascriptError) => any) | undefined;
onNetworkError?: (() => any) | undefined;
onTokenExpired?: (() => any) | undefined;
onInitialized?: ((id: number) => any) | undefined;
}>, {
loadWidget: boolean;
timeout: number;
}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
export { _default as SmartCaptcha }
export default _default;
declare interface JavascriptError { filename: string, message: string, col: number, line: number }
declare type JavascriptErrorEventCallback = (error: JavascriptError) => void
declare type RenderProps = Partial<SmartCaptchaRenderProps> | string;
declare type ShieldPosition =
| 'top-left'
| 'center-left'
| 'bottom-left'
| 'top-right'
| 'center-right'
| 'bottom-right'
declare type SmartCaptchaComponentProps = SmartCaptchaRenderProps & {
loadWidget?: boolean;
timeout?: number;
};
export declare const SmartCaptchaPlugin: Plugin_2;
/**
* @link https://cloud.yandex.ru/docs/smartcaptcha/concepts/widget-methods#render
*/
declare interface SmartCaptchaRenderProps {
sitekey: string,
callback?: (token: Token) => void,
hl?: SupportedLang,
test?: boolean,
webview?: boolean,
invisible?: boolean,
shieldPosition?: ShieldPosition,
hideShield?: boolean,
}
export declare class SmartCaptchaUtils {
readonly SCRIPT_RENDER_ONLOAD_SRC = "https://smartcaptcha.yandexcloud.net/captcha.js?render=onload";
execute(widgetID?: WidgetId): void;
reset(widgetID?: WidgetId): void;
destroy(widgetID?: WidgetId): void;
getResponse(widgetID?: WidgetId): Token | undefined;
subscribe(widgetId: WidgetId, event: SubscribeEvent, cb: CaptchaSubscriptionEventCallback): void;
}
/**
* @link https://cloud.yandex.ru/docs/smartcaptcha/concepts/widget-methods#subscribe
*/
declare type SubscribeEvent =
| 'challenge-visible'
| 'challenge-hidden'
| 'network-error'
| 'success'
| 'token-expired'
| 'javascript-error'
declare type SuccessEventCallback = (token: Token) => void
declare type SupportedLang =
| 'ru'
| 'en'
| 'be'
| 'kk'
| 'tt'
| 'uk'
| 'uz'
| 'tr'
export declare type Token = string
export declare const useSmartCaptcha: (container: CaptchaContainer, renderProps?: RenderProps, load?: boolean, timeout?: number) => {
widgetId: Ref<number | undefined, number | undefined>;
token: Ref<string | undefined, string | undefined>;
execute: () => void;
reset: () => void;
destroy: () => void;
getResponse: () => Token | undefined;
subscribeTo: <T extends CaptchaSubscriptionEventCallback>(event: SubscribeEvent, cb: T) => void;
};
export declare type WidgetId = number
/**
* @link https://cloud.yandex.ru/docs/smartcaptcha/concepts/widget-methods#methods
*/
export declare interface WindowSmartCaptcha {
render: (
container: HTMLElement | string,
params: SmartCaptchaRenderProps
) => WidgetId
getResponse: (widgetId?: WidgetId) => Token
execute: (widgetId?: WidgetId) => void
reset: (widgetId?: WidgetId) => void
destroy: (widgetId?: WidgetId) => void
subscribe(widgetId: WidgetId, event: 'success', callback: SuccessEventCallback): () => void
subscribe(widgetId: WidgetId, event: 'javascript-error', callback: JavascriptErrorEventCallback): () => void
subscribe(widgetId: WidgetId, event: Exclude<SubscribeEvent, 'success', 'javascript-error'>, callback: BaseEventCallback): () => void
}
export { }
declare global {
interface Window {
smartCaptcha?: SmartCaptcha
}
}