Add macOS companion node status and system.nodes APIs
This commit is contained in:
@@ -34,6 +34,16 @@ export interface NodeLocationGetParams {
|
||||
connectionId: string;
|
||||
}
|
||||
|
||||
export interface NodeStatusSetParams {
|
||||
connectionId: string;
|
||||
platform: 'macos' | 'ios' | 'android' | 'linux' | 'windows' | 'unknown';
|
||||
appVersion?: string;
|
||||
deviceName?: string;
|
||||
statusText?: string;
|
||||
batteryPct?: number;
|
||||
powerSource?: 'ac' | 'battery' | 'unknown';
|
||||
}
|
||||
|
||||
// ── Server → Client ────────────────────────────────────────────
|
||||
|
||||
export interface GatewayResponse {
|
||||
@@ -245,6 +255,44 @@ export function parseNodeLocationGetParams(params: unknown): NodeLocationGetPara
|
||||
};
|
||||
}
|
||||
|
||||
export function parseNodeStatusSetParams(params: unknown): NodeStatusSetParams | null {
|
||||
if (!params || typeof params !== 'object') {
|
||||
return null;
|
||||
}
|
||||
const p = params as Record<string, unknown>;
|
||||
if (typeof p.connectionId !== 'string' || !p.connectionId.trim()) {
|
||||
return null;
|
||||
}
|
||||
if (typeof p.platform !== 'string' || !['macos', 'ios', 'android', 'linux', 'windows', 'unknown'].includes(p.platform)) {
|
||||
return null;
|
||||
}
|
||||
if (p.appVersion !== undefined && typeof p.appVersion !== 'string') {
|
||||
return null;
|
||||
}
|
||||
if (p.deviceName !== undefined && typeof p.deviceName !== 'string') {
|
||||
return null;
|
||||
}
|
||||
if (p.statusText !== undefined && typeof p.statusText !== 'string') {
|
||||
return null;
|
||||
}
|
||||
if (p.batteryPct !== undefined && (typeof p.batteryPct !== 'number' || !Number.isFinite(p.batteryPct) || p.batteryPct < 0 || p.batteryPct > 100)) {
|
||||
return null;
|
||||
}
|
||||
if (p.powerSource !== undefined && !['ac', 'battery', 'unknown'].includes(String(p.powerSource))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
connectionId: p.connectionId,
|
||||
platform: p.platform as NodeStatusSetParams['platform'],
|
||||
appVersion: typeof p.appVersion === 'string' ? p.appVersion : undefined,
|
||||
deviceName: typeof p.deviceName === 'string' ? p.deviceName : undefined,
|
||||
statusText: typeof p.statusText === 'string' ? p.statusText : undefined,
|
||||
batteryPct: typeof p.batteryPct === 'number' ? p.batteryPct : undefined,
|
||||
powerSource: p.powerSource as NodeStatusSetParams['powerSource'] | undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export function makeResponse(id: number, result: unknown): GatewayResponse {
|
||||
return { id, result };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user