UNPKG

@vulform/js

Version:

JavaScript SDK for VulForm contact form management

109 lines 2.98 kB
/** * VulForm JavaScript SDK * * A powerful, type-safe SDK for integrating VulForm contact forms * into any JavaScript application. */ import { VulFormError } from '@vulform/core'; export { VulFormError, type FormTemplate, type FormField, type FieldType, type VulFormProps, type FormError, type ValidationErrors, } from '@vulform/core'; export interface VulFormConfig { apiKey: string; baseUrl?: string; timeout?: number; retries?: number; onSuccess?: (response: SubmissionResponse) => void; onError?: (error: VulFormError) => void; onRateLimit?: (retryAfter: number) => void; debug?: boolean; } export interface FormData { [key: string]: string | number | boolean | File | undefined; name?: string; email?: string; subject?: string; message?: string; } export interface SubmissionResponse { success: boolean; id: string; message: string; timestamp: number; } export interface ValidationResult { valid: boolean; errors: ValidationError[]; warnings: ValidationWarning[]; } export interface ValidationError { field: string; message: string; code: string; } export interface ValidationWarning { field: string; message: string; suggestion?: string; } export interface AnalyticsEvent { type: 'form_view' | 'form_start' | 'form_abandon' | 'form_submit' | 'validation_error'; formId?: string; timestamp: number; metadata?: Record<string, any>; } export declare class VulForm { private config; private submitCount; private lastSubmitTime; private apiClient; constructor(config: VulFormConfig); /** * Submit a form with automatic retries and rate limiting */ submit(data: FormData): Promise<SubmissionResponse>; /** * Validate form data before submission */ validate(data: FormData): ValidationResult; /** * Real-time field validation */ validateField(fieldName: string, value: any): Promise<ValidationError | null>; /** * Track analytics events */ trackEvent(event: AnalyticsEvent): void; /** * Setup form with automatic tracking */ setupForm(formElement: HTMLFormElement): VulFormFormHandler; /** * Utilities */ private validateFormData; private isValidEmail; private makeRequest; private sleep; private getStoredEvents; private flushEvents; } /** * Form handler for automatic form enhancement */ export declare class VulFormFormHandler { private vulform; private form; private submitButton?; private originalSubmitText?; constructor(vulform: VulForm, form: HTMLFormElement); private setupFormHandling; private handleSubmit; private setupRealTimeValidation; private setLoading; private showSuccess; private showError; private showValidationErrors; private showFieldError; private showMessage; } export default VulForm; //# sourceMappingURL=index.d.ts.map