@three333/termbuddy 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/protocol.ts CHANGED
@@ -9,10 +9,22 @@ export type DiscoveryPacket = {
9
9
  sentAt: number;
10
10
  };
11
11
 
12
+ export type ProjectileKind = "ROSE" | "POOP" | "HAMMER";
13
+ export type ProjectileDirection = "LEFT_TO_RIGHT" | "RIGHT_TO_LEFT";
14
+
12
15
  export type TcpPacket =
13
16
  | {type: 'hello'; hostName: string; clientName: string; sentAt: number}
14
- | {type: 'status'; state: ActivityState; sentAt: number}
17
+ | {type: 'status'; state: ActivityState; senderName?: string; sentAt: number}
15
18
  | {type: 'ping'; sentAt: number}
16
- | {type: 'pong'; sentAt: number};
19
+ | {type: 'pong'; sentAt: number}
20
+ | {type: 'projectile'; kind: ProjectileKind; direction: ProjectileDirection; senderName?: string; sentAt: number}
21
+ | {type: 'peer_joined'; peerName: string; sentAt: number}
22
+ | {type: 'peer_left'; peerName: string; sentAt: number};
23
+
24
+ export type Peer = {
25
+ id: string;
26
+ name: string;
27
+ state: ActivityState;
28
+ };
17
29
 
18
30
  export type ConnectionStatus = 'waiting' | 'connecting' | 'connected' | 'disconnected';
@@ -28,9 +28,13 @@ export async function loadStoredApiKey(): Promise<string | null> {
28
28
  }
29
29
 
30
30
  export async function saveStoredApiKey(apiKey: string): Promise<void> {
31
+ const trimmed = apiKey.trim();
32
+ if (trimmed.length === 0) {
33
+ throw new Error('API key cannot be empty');
34
+ }
31
35
  const absolute = path.resolve(process.cwd(), KEY_RELATIVE_PATH);
32
36
  await ensureDirForFile(absolute);
33
- const payload: KeyFile = {apiKey};
37
+ const payload: KeyFile = {apiKey: trimmed};
34
38
  await fs.writeFile(absolute, `${JSON.stringify(payload, null, 2)}\n`, 'utf8');
35
39
  }
36
40