/** * Global Save Service * Provides save and export functionality that can be accessed from anywhere in the app. * This is the single source of truth for save/export logic. * * App.svelte delegates to globalSaveWorkflow() / globalExportWorkflow() rather than * reimplementing the logic, ensuring "blur active element" flushing and metadata * construction happen in exactly one place. */ import type { Workflow } from '../types/index.js'; import type { FlowDropEventHandlers, FlowDropFeatures } from '../types/events.js'; /** * Minimal interface for the enhanced API client used when an authProvider is present. * Matches the surface of EnhancedFlowDropApiClient that save needs. */ export interface SaveApiClient { saveWorkflow(workflow: Workflow): Promise; updateWorkflow(id: string, workflow: Workflow): Promise; } /** * Options accepted by globalSaveWorkflow(). * All fields are optional — omitting them falls back to the basic behaviour * (no event handlers, always show toasts, legacy workflowApi). */ export interface GlobalSaveOptions { /** Enhanced API client with authProvider support. Falls back to legacy workflowApi when absent. */ apiClient?: SaveApiClient | null; /** Event handler hooks (onBeforeSave, onAfterSave, onSaveError, onApiError). */ eventHandlers?: FlowDropEventHandlers; /** Feature flags (showToasts). Defaults to DEFAULT_FEATURES. */ features?: Partial; /** * Callback invoked after a successful save to clear the dirty state. * Pass workflowStore's markAsSaved here when calling from App.svelte. */ onMarkAsSaved?: () => void; /** * Callback invoked after a successful save with the persisted workflow. * Receives the server-returned workflow (which may have a different ID than * the one sent, e.g. server-assigned integer vs client UUID). * Use this to update draft storage keys or other ID-dependent state. */ onSaved?: (savedWorkflow: Workflow) => void; } /** * Options accepted by globalExportWorkflow(). */ export interface GlobalExportOptions { /** Feature flags (showToasts). Defaults to DEFAULT_FEATURES. */ features?: Partial; } /** * Save the current workflow to the backend. * * This is the single source of truth for save logic. App.svelte delegates * to this function rather than reimplementing the steps. * * Steps performed: * 1. Flush pending form changes (blur active element + tick) * 2. Optionally call onBeforeSave — return false cancels the save * 3. Build the canonical Workflow object (preserving metadata, format, etc.) * 4. Persist via enhanced apiClient or legacy workflowApi * 5. Update the store if the server assigned a new ID * 6. Call onMarkAsSaved / onAfterSave hooks * 7. Show toast notifications (respecting features.showToasts) */ export declare function globalSaveWorkflow(options?: GlobalSaveOptions): Promise; /** * Export the current workflow as a downloadable JSON file. * * This is the single source of truth for export logic. App.svelte delegates * to this function rather than reimplementing the steps. * * Preserves all metadata fields (format, tags, etc.) consistently with save. */ export declare function globalExportWorkflow(options?: GlobalExportOptions): Promise;