/ services / settingsSync / types.ts
types.ts
 1  /**
 2   * Settings Sync Types
 3   *
 4   * Zod schemas and types for the user settings sync API.
 5   * Based on the backend API contract from anthropic/anthropic#218817.
 6   */
 7  
 8  import { z } from 'zod/v4'
 9  import { lazySchema } from '../../utils/lazySchema.js'
10  
11  /**
12   * Content portion of user sync data - flat key-value storage.
13   * Keys are opaque strings (typically file paths).
14   * Values are UTF-8 string content (JSON, Markdown, etc).
15   */
16  export const UserSyncContentSchema = lazySchema(() =>
17    z.object({
18      entries: z.record(z.string(), z.string()),
19    }),
20  )
21  
22  /**
23   * Full response from GET /api/claude_code/user_settings
24   */
25  export const UserSyncDataSchema = lazySchema(() =>
26    z.object({
27      userId: z.string(),
28      version: z.number(),
29      lastModified: z.string(), // ISO 8601 timestamp
30      checksum: z.string(), // MD5 hash
31      content: UserSyncContentSchema(),
32    }),
33  )
34  
35  export type UserSyncData = z.infer<ReturnType<typeof UserSyncDataSchema>>
36  
37  /**
38   * Result from fetching user settings
39   */
40  export type SettingsSyncFetchResult = {
41    success: boolean
42    data?: UserSyncData
43    isEmpty?: boolean // true if 404 (no data exists)
44    error?: string
45    skipRetry?: boolean
46  }
47  
48  /**
49   * Result from uploading user settings
50   */
51  export type SettingsSyncUploadResult = {
52    success: boolean
53    checksum?: string
54    lastModified?: string
55    error?: string
56  }
57  
58  /**
59   * Keys used for sync entries
60   */
61  export const SYNC_KEYS = {
62    USER_SETTINGS: '~/.claude/settings.json',
63    USER_MEMORY: '~/.claude/CLAUDE.md',
64    projectSettings: (projectId: string) =>
65      `projects/${projectId}/.claude/settings.local.json`,
66    projectMemory: (projectId: string) => `projects/${projectId}/CLAUDE.local.md`,
67  } as const