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
|
/**
* Centralized storage layer using WXT's built-in storage API
*/
import { storage } from '#imports';
import type { Project } from "./types"
/**
* User authentication and profile data
*/
export interface UserData {
userId?: string
email?: string
name?: string
}
/**
* Twitter authentication tokens for API requests
*/
export interface TwitterAuthTokens {
cookie: string
csrf: string
auth: string
}
/**
* Local Storage Items (persistent across sessions)
*/
export const bearerToken = storage.defineItem<string>("local:bearer-token")
export const userData = storage.defineItem<UserData>("local:user-data")
export const defaultProject = storage.defineItem<Project>(
"local:sm-default-project",
)
export const autoSearchEnabled = storage.defineItem<boolean>(
"local:sm-auto-search-enabled",
{
fallback: false,
},
)
export const autoCapturePromptsEnabled = storage.defineItem<boolean>(
"local:sm-auto-capture-prompts-enabled",
{
fallback: false,
},
)
/**
* Session Storage Items (cleared when browser closes)
*/
export const tokensLogged = storage.defineItem<boolean>(
"session:tokens-logged",
{
fallback: false,
},
)
export const twitterCookie = storage.defineItem<string>(
"session:twitter-cookie",
)
export const twitterCsrf = storage.defineItem<string>("session:twitter-csrf")
export const twitterAuthToken = storage.defineItem<string>(
"session:twitter-auth-token",
)
/**
* Helper function to get Twitter authentication tokens
* @returns Promise resolving to tokens or null if not available
*/
export async function getTwitterTokens(): Promise<TwitterAuthTokens | null> {
const [cookie, csrf, auth] = await Promise.all([
twitterCookie.getValue(),
twitterCsrf.getValue(),
twitterAuthToken.getValue(),
])
if (!cookie || !csrf || !auth) {
return null
}
return {
cookie,
csrf,
auth,
}
}
/**
* Helper function to set Twitter authentication tokens
* @param tokens - Twitter authentication tokens to store
*/
export async function setTwitterTokens(
tokens: TwitterAuthTokens,
): Promise<void> {
await Promise.all([
twitterCookie.setValue(tokens.cookie),
twitterCsrf.setValue(tokens.csrf),
twitterAuthToken.setValue(tokens.auth),
])
}
/**
* Helper function to check if tokens have been logged (for one-time logging)
* @returns Promise resolving to boolean indicating if tokens were previously logged
*/
export async function getTokensLogged(): Promise<boolean> {
return (await tokensLogged.getValue()) ?? false
}
/**
* Helper function to mark tokens as logged
*/
export async function setTokensLogged(): Promise<void> {
await tokensLogged.setValue(true)
}
|