feat: add shared types and message definitions
Entry, Manifest, VaultConfig types mirroring the Rust data model, plus a discriminated-union Request type for all popup/content-to-service-worker messages. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
68
extension/src/shared/messages.ts
Normal file
68
extension/src/shared/messages.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import type { Entry, Manifest, ManifestEntry, VaultConfig, SetupState } from './types';
|
||||
|
||||
// --- Request types (popup/content -> service worker) ---
|
||||
|
||||
export type Request =
|
||||
| { type: 'unlock'; passphrase: string }
|
||||
| { type: 'lock' }
|
||||
| { type: 'is_unlocked' }
|
||||
| { type: 'list_entries'; group?: string }
|
||||
| { type: 'get_entry'; id: string }
|
||||
| { type: 'search_entries'; query: string }
|
||||
| { type: 'add_entry'; entry: Entry }
|
||||
| { type: 'update_entry'; id: string; entry: Entry }
|
||||
| { type: 'delete_entry'; id: string }
|
||||
| { type: 'get_totp'; id: string }
|
||||
| { type: 'get_autofill_candidates'; url: string }
|
||||
| { type: 'get_credentials'; id: string }
|
||||
| { type: 'sync' }
|
||||
| { type: 'get_setup_state' }
|
||||
| { type: 'save_setup'; config: VaultConfig; imageBase64: string }
|
||||
| { type: 'generate_password'; length: number }
|
||||
| { type: 'fill_credentials'; username: string; password: string };
|
||||
|
||||
// --- Response types (service worker -> popup/content) ---
|
||||
|
||||
export type Response =
|
||||
| { ok: true; data?: unknown }
|
||||
| { ok: false; error: string };
|
||||
|
||||
export interface UnlockResponse extends Extract<Response, { ok: true }> {
|
||||
data: undefined;
|
||||
}
|
||||
|
||||
export interface IsUnlockedResponse extends Extract<Response, { ok: true }> {
|
||||
data: { unlocked: boolean };
|
||||
}
|
||||
|
||||
export interface ListEntriesResponse extends Extract<Response, { ok: true }> {
|
||||
data: { entries: Array<[string, ManifestEntry]> };
|
||||
}
|
||||
|
||||
export interface GetEntryResponse extends Extract<Response, { ok: true }> {
|
||||
data: { entry: Entry };
|
||||
}
|
||||
|
||||
export interface SearchEntriesResponse extends Extract<Response, { ok: true }> {
|
||||
data: { entries: Array<[string, ManifestEntry]> };
|
||||
}
|
||||
|
||||
export interface TotpResponse extends Extract<Response, { ok: true }> {
|
||||
data: { code: string; remaining_seconds: number };
|
||||
}
|
||||
|
||||
export interface AutofillCandidatesResponse extends Extract<Response, { ok: true }> {
|
||||
data: { candidates: Array<[string, ManifestEntry]> };
|
||||
}
|
||||
|
||||
export interface CredentialsResponse extends Extract<Response, { ok: true }> {
|
||||
data: { username: string; password: string };
|
||||
}
|
||||
|
||||
export interface SetupStateResponse extends Extract<Response, { ok: true }> {
|
||||
data: SetupState;
|
||||
}
|
||||
|
||||
export interface GeneratePasswordResponse extends Extract<Response, { ok: true }> {
|
||||
data: { password: string };
|
||||
}
|
||||
Reference in New Issue
Block a user