UNPKG

vue-recaptcha

Version:

ReCAPTCHA vue component

83 lines (82 loc) 2.9 kB
import type { LiteralUnion, Opaque } from 'type-fest'; export type RecaptchaCallback = '__vueRecaptchaLoaded'; export interface RecaptchaV2CommonOptions { sitekey: string; tabindex?: string; callback?: (response: string) => void; 'expired-callback'?: () => void; 'error-callback'?: (error: Error) => void; } export interface RecaptchaV2CheckboxOptions extends RecaptchaV2CommonOptions { theme?: 'dark' | 'light'; size?: 'compact' | 'normal'; } export interface RecaptchaV2InvisibleOptions extends RecaptchaV2CommonOptions { size: 'invisible'; badge?: 'bottomright' | 'bottomleft' | 'inline'; } export type RecaptchaV2Options = RecaptchaV2CheckboxOptions | RecaptchaV2InvisibleOptions; export type WidgetID = Opaque<string, 'widget-id'>; export interface GRecaptcha { render(ele: Element, options: RecaptchaV2Options): WidgetID; reset(widgetId: WidgetID): void; execute(widgetId: WidgetID): void; execute(siteKey: string, options: { action: string; }): Promise<string>; } declare global { interface Window { grecaptcha: GRecaptcha & { enterprise?: GRecaptcha; }; __vueRecaptchaLoaded: () => void; } } export interface RecaptchaParams { render: LiteralUnion<'explicit', string>; hl?: string | undefined; trustedtypes?: 'true' | undefined; onload?: RecaptchaCallback; [k: string]: string | undefined; } export interface ScriptLoaderOptionsInput { useRecaptchaNet?: boolean; recaptchaApiURL?: string; nonce?: string; params: RecaptchaParams; } export interface ScriptLoaderOptions { /** * you can use recaptcha.net instead of google.com, if you set recaptchaApiURL, this option will be ignored */ useRecaptchaNet?: boolean; /** * you can use your own recaptcha api url, if you set this option, useRecaptchaNet will be ignored */ recaptchaApiURL: string; /** * nonce for script tag */ nonce?: string; /** * params for recaptcha api */ params: RecaptchaParams; } export interface ScriptLoaderFactory { (options: ScriptLoaderOptions): () => void; } export interface NormalizedScriptLoaderFactory { (options: ScriptLoaderOptionsInput): () => void; } /** * Helper function for define your own loadScript function */ export declare function defineScriptLoader(fn: ScriptLoaderFactory): NormalizedScriptLoaderFactory; export declare function normalizeScriptLoaderOptions(options: ScriptLoaderOptionsInput): ScriptLoaderOptions; export declare const recaptchaLoaded: import("p-defer").DeferredPromise<unknown>; export declare function toQueryString(params: RecaptchaParams): string; export declare function normalizeParams(raw: RecaptchaParams): string[][]; export declare function toStringPair(params: RecaptchaParams): string[][]; export declare function checkRecaptchaLoad(): any;