/** * Draft Storage Service for FlowDrop * * Handles saving and loading workflow drafts to/from localStorage. * Provides interval-based auto-save functionality. * * @module services/draftStorage */ import type { Workflow } from '../types/index.js'; /** * Draft metadata stored alongside the workflow */ interface DraftMetadata { /** Timestamp when the draft was saved */ savedAt: string; /** Workflow ID (if available) */ workflowId?: string; /** Workflow name */ workflowName?: string; } /** * Complete draft data stored in localStorage */ interface StoredDraft { /** The workflow data */ workflow: Workflow; /** Draft metadata */ metadata: DraftMetadata; } /** * Generate a storage key for a workflow * * If a custom key is provided, use it directly. * Otherwise, generate based on workflow ID or use "new" for unsaved workflows. * * @param workflowId - The workflow ID (optional) * @param customKey - Custom storage key provided by enterprise (optional) * @returns The storage key to use */ export declare function getDraftStorageKey(workflowId?: string, customKey?: string): string; /** * Save a workflow draft to localStorage * * @param workflow - The workflow to save * @param storageKey - The storage key to use * @returns true if saved successfully, false otherwise */ export declare function saveDraft(workflow: Workflow, storageKey: string): boolean; /** * Load a workflow draft from localStorage * * @param storageKey - The storage key to load from * @returns The stored draft, or null if not found */ export declare function loadDraft(storageKey: string): StoredDraft | null; /** * Delete a workflow draft from localStorage * * @param storageKey - The storage key to delete */ export declare function deleteDraft(storageKey: string): void; /** * Check if a draft exists for a given storage key * * @param storageKey - The storage key to check * @returns true if a draft exists */ export declare function hasDraft(storageKey: string): boolean; /** * Get draft metadata without loading the full workflow * * Useful for displaying draft information without parsing the entire workflow. * * @param storageKey - The storage key to check * @returns Draft metadata, or null if not found */ export declare function getDraftMetadata(storageKey: string): DraftMetadata | null; /** * Clear all FlowDrop drafts from localStorage * * Removes every key beginning with `flowdrop:draft:`. Intended to be called * from a host application's logout handler so workflow drafts do not persist * across user sessions on shared devices. * * @param extraKeys - Additional explicit keys to remove. Pass any custom * `draftStorageKey` values configured at mount time so they are cleared * alongside the default-prefixed keys. * @returns The number of entries removed. */ export declare function clearAllDrafts(extraKeys?: readonly string[]): number; /** * Draft auto-save manager * * Handles interval-based auto-saving of workflow drafts. * Should be instantiated per FlowDrop instance. */ export declare class DraftAutoSaveManager { /** Interval timer ID */ private intervalId; /** Storage key for drafts */ private storageKey; /** Auto-save interval in milliseconds */ private interval; /** Whether auto-save is enabled */ private enabled; /** Function to get current workflow */ private getWorkflow; /** Function to check if workflow is dirty */ private isDirty; /** Last saved workflow hash (for change detection) */ private lastSavedHash; /** * Create a new DraftAutoSaveManager * * @param options - Configuration options */ constructor(options: { storageKey: string; interval: number; enabled: boolean; getWorkflow: () => Workflow | null; isDirty: () => boolean; }); /** * Start auto-save interval * * Will save drafts at the configured interval if there are unsaved changes. */ start(): void; /** * Stop auto-save interval */ stop(): void; /** * Save draft if there are unsaved changes * * @returns true if a draft was saved */ saveIfDirty(): boolean; /** * Force save the current workflow as a draft * * Saves regardless of dirty state. * * @returns true if saved successfully */ forceSave(): boolean; /** * Clear the draft from storage */ clearDraft(): void; /** * Mark the current state as saved * * Updates the hash so the next saveIfDirty won't save unless there are new changes. */ markAsSaved(): void; /** * Update the storage key * * Useful when the workflow ID changes (e.g., after first save). * * @param newKey - The new storage key */ updateStorageKey(newKey: string): void; /** * Simple hash function for change detection * * Not cryptographically secure, just for detecting changes. * * @param workflow - The workflow to hash * @returns A simple hash string */ private hashWorkflow; /** * Check if auto-save is currently running */ isRunning(): boolean; /** * Get the current storage key */ getStorageKey(): string; } export {};