aboutsummaryrefslogtreecommitdiff
path: root/apps/browser-extension/utils/types.ts
blob: 8cec2241152d6530ae2077ac32bb822b517ec6fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
 * Type definitions for the browser extension
 */

/**
 * Toast states for UI feedback
 */
export type ToastState = "loading" | "success" | "error"

/**
 * Message types for extension communication
 */
export interface ExtensionMessage {
	isFolderImport?: boolean
	bookmarkCollectionId?: string
	action?: string
	type?: string
	data?: unknown
	state?: ToastState
	importedMessage?: string
	totalImported?: number
	actionSource?: string
	selectedProject?: {
		id: string
		name: string
		containerTag: string
	}
}

/**
 * Memory data structure for saving content
 */
export interface MemoryData {
	html?: string
	markdown?: string
	content?: string
	highlightedText?: string
	url?: string
	ogImage?: string
	title?: string
}

/**
 * Supermemory API payload for storing memories
 */
export interface MemoryPayload {
	containerTags?: string[]
	content: string
	metadata: {
		sm_source: string
		[key: string]: unknown
	}
	customId?: string
}

/**
 * Twitter-specific memory metadata
 */
export interface TwitterMemoryMetadata {
	sm_source: "twitter_bookmarks"
	tweet_id: string
	author: string
	created_at: string
	likes: number
	retweets: number
}

/**
 * Storage data structure for Chrome storage
 */
export interface StorageData {
	bearerToken?: string
	twitterAuth?: {
		cookie: string
		csrf: string
		auth: string
	}
	tokens_logged?: boolean
	cookie?: string
	csrf?: string
	auth?: string
	defaultProject?: Project
	projectsCache?: {
		projects: Project[]
		timestamp: number
	}
}

/**
 * Context menu click info
 */
export interface ContextMenuClickInfo {
	menuItemId: string | number
	editable?: boolean
	frameId?: number
	frameUrl?: string
	linkUrl?: string
	mediaType?: string
	pageUrl?: string
	parentMenuItemId?: string | number
	selectionText?: string
	srcUrl?: string
	targetElementId?: number
	wasChecked?: boolean
}

/**
 * API Response types
 */
export interface APIResponse<T = unknown> {
	success: boolean
	data?: T
	error?: string
}

/**
 * Error types for better error handling
 */
export class ExtensionError extends Error {
	constructor(
		message: string,
		public code?: string,
		public statusCode?: number,
	) {
		super(message)
		this.name = "ExtensionError"
	}
}

export class TwitterAPIError extends ExtensionError {
	constructor(message: string, statusCode?: number) {
		super(message, "TWITTER_API_ERROR", statusCode)
		this.name = "TwitterAPIError"
	}
}

export class SupermemoryAPIError extends ExtensionError {
	constructor(message: string, statusCode?: number) {
		super(message, "SUPERMEMORY_API_ERROR", statusCode)
		this.name = "SupermemoryAPIError"
	}
}

export class AuthenticationError extends ExtensionError {
	constructor(message = "Authentication required") {
		super(message, "AUTH_ERROR")
		this.name = "AuthenticationError"
	}
}

export interface Project {
	id: string
	name: string
	containerTag: string
	createdAt: string
	updatedAt: string
	documentCount: number
}

export interface ProjectsResponse {
	projects: Project[]
}