UNPKG

@feedal/embed

Version:

Feedal embed script to load feedback forms via JS or NPM

111 lines (110 loc) 3.23 kB
/** * Submission Persistence Manager for Feedal Widget * * This module handles tracking form submissions to prevent showing the same form * to users who have already submitted it. It supports multiple storage types and * configurable expiration periods. */ export interface SubmissionPersistenceOptions { /** * Whether to remember submissions and prevent showing forms again */ rememberSubmission?: boolean; /** * How long to remember submissions (in milliseconds) * Default: 30 days */ submissionExpiry?: number; /** * Where to store submission records * - local: localStorage (persists across browser sessions) * - session: sessionStorage (cleared when browser is closed) * - cookie: Browser cookies (configurable expiration) */ storageType?: 'local' | 'session' | 'cookie'; /** * Session key for controlling persistence * When this key changes, all previous submission records become invalid */ sessionKey?: string; } export declare class SubmissionPersistenceManager { private options; private formId; private static readonly storageKeyPrefix; private static readonly renderedKeyPrefix; private static readonly submittedKeyPrefix; constructor(formId: string, options?: SubmissionPersistenceOptions); /** * Check if the form has been submitted before * @returns boolean True if the form has been submitted and should not be shown */ hasSubmitted(): boolean; /** * Record a form submission */ recordSubmission(): void; /** * Clear submission records for this form */ clearSubmission(): void; /** * Clear all submission records across all forms */ static resetAllSubmissions(): void; /** * Store the rendered session key (form is ready to be submitted) */ setRenderedSessionKey(sessionKey: string): void; /** * Get the rendered session key */ getRenderedSessionKey(): string | null; /** * Clear the rendered session key */ clearRenderedSessionKey(): void; /** * Store the submitted session key (form has been submitted) */ setSubmittedSessionKey(sessionKey: string): void; /** * Get the submitted session key */ getSubmittedSessionKey(): string | null; /** * Clear the submitted session key */ clearSubmittedSessionKey(): void; /** * Clean up expired keys for this form */ cleanupExpiredKeys(): void; /** * Clear all form-related keys (rendered and submitted) */ clearAllFormKeys(): void; /** * Update the session key - this invalidates all previous submissions */ updateSessionKey(newSessionKey: string): void; /** * Check if a specific session key is still valid (not expired) */ isSessionKeyValid(sessionKey: string): boolean; private setStorageValue; private getStorageValue; private removeStorageValue; /** * Set a cookie with expiration */ private setCookie; /** * Get a cookie value by name */ private getCookie; /** * Delete a cookie by name */ private deleteCookie; }