@kraki/head 0.1.0
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/LICENSE +21 -0
- package/dist/auth.d.ts +104 -0
- package/dist/auth.js +213 -0
- package/dist/auth.js.map +1 -0
- package/dist/channel-manager.d.ts +97 -0
- package/dist/channel-manager.js +215 -0
- package/dist/channel-manager.js.map +1 -0
- package/dist/cli.d.ts +21 -0
- package/dist/cli.js +156 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +31 -0
- package/dist/logger.js +103 -0
- package/dist/logger.js.map +1 -0
- package/dist/router.d.ts +30 -0
- package/dist/router.js +217 -0
- package/dist/router.js.map +1 -0
- package/dist/server.d.ts +78 -0
- package/dist/server.js +678 -0
- package/dist/server.js.map +1 -0
- package/dist/storage.d.ts +112 -0
- package/dist/storage.js +372 -0
- package/dist/storage.js.map +1 -0
- package/package.json +42 -0
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { WebSocket } from 'ws';
|
|
2
|
+
import type { Server } from 'http';
|
|
3
|
+
import { ChannelManager } from './channel-manager.js';
|
|
4
|
+
import { Router } from './router.js';
|
|
5
|
+
import type { AuthProvider } from './auth.js';
|
|
6
|
+
export interface HeadServerOptions {
|
|
7
|
+
/** Auth providers keyed by mode name. Falls back to authProvider if set. */
|
|
8
|
+
authProviders?: Map<string, AuthProvider>;
|
|
9
|
+
/** Supported auth mode names (for auth_info response) */
|
|
10
|
+
authModes?: string[];
|
|
11
|
+
/** Legacy single auth provider (used if authProviders not set) */
|
|
12
|
+
authProvider?: AuthProvider;
|
|
13
|
+
/** Enable E2E encryption mode */
|
|
14
|
+
e2e: boolean;
|
|
15
|
+
/** Max WebSocket message size in bytes. Default: 10MB */
|
|
16
|
+
maxPayload?: number;
|
|
17
|
+
/** Ping interval in ms. Default: 30000 (30s). Set 0 to disable. */
|
|
18
|
+
pingInterval?: number;
|
|
19
|
+
/** Pong timeout in ms. Default: 10000 (10s) */
|
|
20
|
+
pongTimeout?: number;
|
|
21
|
+
/** Allow QR pairing for adding devices. Default: true */
|
|
22
|
+
pairingEnabled?: boolean;
|
|
23
|
+
/** Pairing token TTL in seconds. Default: 300 (5 min) */
|
|
24
|
+
pairingTtl?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare class HeadServer {
|
|
27
|
+
private wss;
|
|
28
|
+
private cm;
|
|
29
|
+
private router;
|
|
30
|
+
private options;
|
|
31
|
+
private clients;
|
|
32
|
+
private pingTimer;
|
|
33
|
+
/** Dedup: track recently seen client message IDs to prevent duplicates */
|
|
34
|
+
private recentClientMsgIds;
|
|
35
|
+
private dedupCleanupTimer;
|
|
36
|
+
constructor(cm: ChannelManager, router: Router, options: HeadServerOptions);
|
|
37
|
+
/** Resolve the auth provider (multi-provider or legacy single). */
|
|
38
|
+
private getAuthProvider;
|
|
39
|
+
/** Get supported auth mode names. */
|
|
40
|
+
private getAuthModes;
|
|
41
|
+
/** Resolve auth provider by mode name (for multi-provider). */
|
|
42
|
+
private getAuthProviderForMode;
|
|
43
|
+
/** Get the GitHub OAuth client ID if configured (for auth_info_response). */
|
|
44
|
+
private getGitHubClientId;
|
|
45
|
+
/** Find the GitHubAuthProvider in the provider chain (unwrapping throttle). */
|
|
46
|
+
private findGitHubProvider;
|
|
47
|
+
/** Resolve the channel owner's user info for auth_ok. */
|
|
48
|
+
private getChannelOwnerUser;
|
|
49
|
+
/**
|
|
50
|
+
* Attach to an HTTP server for upgrade handling.
|
|
51
|
+
*/
|
|
52
|
+
attach(server: Server): void;
|
|
53
|
+
/**
|
|
54
|
+
* Accept a raw WebSocket connection (for testing without HTTP server).
|
|
55
|
+
*/
|
|
56
|
+
acceptConnection(ws: WebSocket): void;
|
|
57
|
+
private onConnection;
|
|
58
|
+
private onMessage;
|
|
59
|
+
private handleCreatePairingToken;
|
|
60
|
+
private handleDeleteSession;
|
|
61
|
+
/**
|
|
62
|
+
* One-shot pairing token request. Validates auth token inline,
|
|
63
|
+
* creates a pairing token, responds, and requires no device registration.
|
|
64
|
+
*/
|
|
65
|
+
private handleRequestPairingToken;
|
|
66
|
+
private handleAuth;
|
|
67
|
+
private handlePairingAuth;
|
|
68
|
+
private handleChallengeResponse;
|
|
69
|
+
private sendError;
|
|
70
|
+
private startPingInterval;
|
|
71
|
+
private startDedupCleanup;
|
|
72
|
+
/** Guard against unbounded dedup set growth */
|
|
73
|
+
private trackClientMsgId;
|
|
74
|
+
/**
|
|
75
|
+
* Close the server and all connections.
|
|
76
|
+
*/
|
|
77
|
+
close(): void;
|
|
78
|
+
}
|