@follow-app/client-sdk
Version:
TypeScript client SDK for Follow RSS Server API
190 lines (164 loc) • 5 kB
text/typescript
// Import types from drizzle schema
import type { settings } from "@folo-services/drizzle"
import type { InferInsertModel, InferSelectModel } from "drizzle-orm"
import type { SerializedInsertModel, SerializedModel, SuccessResponse } from "../../types"
// Re-export database types specific to settings
export type SettingsModel = SerializedModel<InferSelectModel<typeof settings>>
export type SettingsInsert = SerializedInsertModel<InferInsertModel<typeof settings>>
// Settings tabs type based on constants
export type SettingsTab = "general" | "appearance" | "integration" | "ai"
// Settings value types for type safety
export type SettingsValue = Record<string, any>
// Generic settings payload structure
export type SettingsPayload = Record<string, any>
// Settings response structure matching server API
export type SettingsGetResponse = SuccessResponse<{
settings: Record<SettingsTab, SettingsPayload>
updated: Record<SettingsTab, string>
}>
// Settings get request query parameters
export interface SettingsGetQuery {
tab?: string // Comma-separated list of tabs to fetch
}
// Settings update request body
export type SettingsUpdateRequest = Record<string, any>
// Settings update response
export type SettingsUpdateResponse = SuccessResponse<null>
// Common settings value types based on typical use cases
export interface GeneralSettings {
language?: string
theme?: string
timezone?: string
notifications?: boolean
autoRefresh?: boolean
refreshInterval?: number
markAsReadOnScroll?: boolean
showUnreadCount?: boolean
defaultView?: number
compactMode?: boolean
[key: string]: any
}
export interface AppearanceSettings {
fontSize?: number
fontFamily?: string
lineHeight?: number
colorScheme?: "light" | "dark" | "system"
sidebarWidth?: number
contentWidth?: number
showSidebar?: boolean
showToolbar?: boolean
customCSS?: string
[key: string]: any
}
export interface IntegrationSettings {
webhookUrl?: string
webhookEnabled?: boolean
emailNotifications?: boolean
pushNotifications?: boolean
slackWebhook?: string
discordWebhook?: string
telegramBotToken?: string
telegramChatId?: string
[key: string]: any
}
export interface AISettings {
aiEnabled?: boolean
aiModel?: string
autoSummarize?: boolean
summaryLength?: "short" | "medium" | "long"
translationEnabled?: boolean
targetLanguage?: string
sentimentAnalysis?: boolean
categoryPrediction?: boolean
[key: string]: any
}
// Typed settings structure for better type safety
export interface TypedSettings {
general?: GeneralSettings
appearance?: AppearanceSettings
integration?: IntegrationSettings
ai?: AISettings
}
// Settings metadata for tracking updates
export interface SettingsMetadata {
tab: SettingsTab
lastUpdated: string
version?: number
}
// Settings management helper types
export interface SettingsManager {
get: (tab?: SettingsTab) => Promise<SettingsGetResponse>
update: (
tab: SettingsTab,
payload: SettingsPayload,
) => Promise<SettingsUpdateResponse>
getTab: (tab: SettingsTab) => Promise<SettingsPayload>
setTab: (
tab: SettingsTab,
payload: SettingsPayload,
) => Promise<SettingsUpdateResponse>
reset: (tab: SettingsTab) => Promise<SettingsUpdateResponse>
export: () => Promise<TypedSettings>
import: (settings: TypedSettings) => Promise<SettingsUpdateResponse>
}
// Settings API interface based on actual server routes
export interface SettingsAPI {
/**
* Get user settings
* @param args - Optional query parameters
* @returns Promise resolving to settings response
*/
get: (args?: { query?: SettingsGetQuery }) => Promise<SettingsGetResponse>
/**
* Update settings for a specific tab
* @param args - Tab parameter and settings payload
* @returns Promise resolving to update response
*/
update: (args: {
params: { tab: SettingsTab }
body: SettingsUpdateRequest
}) => Promise<SettingsUpdateResponse>
}
// Utility types for settings operations
export interface SettingsOperationResult {
success: boolean
error?: string
data?: any
}
// Settings validation result
export interface SettingsValidationResult {
valid: boolean
errors: string[]
warnings: string[]
}
// Settings diff for tracking changes
export interface SettingsDiff {
added: Record<string, any>
modified: Record<string, any>
removed: string[]
}
// Settings history entry
export interface SettingsHistoryEntry {
timestamp: string
tab: SettingsTab
changes: SettingsDiff
version: number
}
// Settings migration info
export interface SettingsMigration {
fromVersion: number
toVersion: number
migrationFn: (oldSettings: SettingsPayload) => SettingsPayload
}
// Settings backup structure
export interface SettingsBackup {
timestamp: string
version: number
settings: TypedSettings
metadata: SettingsMetadata[]
}
// Unified input types for new API
export interface SettingsUpdateInput {
tab: SettingsTab
[key: string]: any
}