feat: add core type definitions (PageInfo, ApiResponse, WsEvent, FingerprintProfile)

This commit is contained in:
2026-08-12 20:38:34 +08:00
parent 01701e461a
commit e3fe330745
5 changed files with 84 additions and 2 deletions
+10 -2
View File
@@ -1,2 +1,10 @@
// @visionl/core — placeholder, to be implemented in Task 2
export const VERSION = '0.1.0';
export { type PageInfo } from './types/page.js';
export { type ApiResponse, ErrorCode } from './types/api.js';
export { type WsEvent } from './types/ws.js';
export {
type FingerprintProfile,
type FingerprintPermissions,
type FingerprintBehavior,
type CanvasNoiseConfig,
type PermissionState,
} from './types/fingerprint.js';
+18
View File
@@ -0,0 +1,18 @@
// API request/response types / API 请求响应类型
export interface ApiResponse<T = unknown> {
ok: boolean;
data?: T;
error?: {
code: ErrorCode;
message: string;
};
}
export enum ErrorCode {
PAGE_NOT_FOUND = 'PAGE_NOT_FOUND',
DAEMON_UNREACHABLE = 'DAEMON_UNREACHABLE',
INVALID_URL = 'INVALID_URL',
ALIAS_EXISTS = 'ALIAS_EXISTS',
TIMEOUT = 'TIMEOUT',
INTERNAL = 'INTERNAL',
}
+37
View File
@@ -0,0 +1,37 @@
// Fingerprint profile type definitions / 指纹配置类型定义
export type PermissionState = 'prompt' | 'granted' | 'denied';
export interface FingerprintPermissions {
notifications: PermissionState;
geolocation: PermissionState;
camera: PermissionState;
microphone: PermissionState;
}
export interface CanvasNoiseConfig {
enabled: boolean;
strength: number; // 0-1 / 噪声强度 0-1
}
export interface FingerprintBehavior {
mouseMoveDelay: { min: number; max: number };
keyPressDelay: { min: number; max: number };
scrollStepDelay: { min: number; max: number };
}
export interface FingerprintProfile {
id: string;
name: string;
userAgent: string;
platform: string;
languages: string[];
acceptLanguage: string;
screen: { width: number; height: number; colorDepth: number; pixelRatio: number };
viewport: { width: number; height: number };
webgl: { vendor: string; renderer: string };
timezone: string;
geolocation?: { latitude: number; longitude: number; accuracy: number };
permissions: FingerprintPermissions;
behavior: FingerprintBehavior;
canvasNoise: CanvasNoiseConfig;
}
+9
View File
@@ -0,0 +1,9 @@
// Page state type definitions / 页面状态类型定义
export interface PageInfo {
id: string;
url: string;
alias?: string;
title: string;
status: 'active' | 'crashed';
profile: string;
}
+10
View File
@@ -0,0 +1,10 @@
// WebSocket event type definitions / WebSocket 事件类型定义
import type { PageInfo } from './page.js';
export type WsEvent =
| { type: 'page:created'; data: PageInfo }
| { type: 'page:closed'; data: { id: string } }
| { type: 'page:navigated'; data: { id: string; url: string; title: string } }
| { type: 'page:crashed'; data: { id: string; error: string } }
| { type: 'page:console'; data: { id: string; level: string; text: string } }
| { type: 'page:detection:warning'; data: { id: string; level: string; detail: string } };