@principal-ai/control-tower-core 0.1.4 → 0.1.6
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/dist/abstractions/AuthAdapter.d.ts +8 -5
- package/dist/abstractions/AuthAdapter.d.ts.map +1 -1
- package/dist/abstractions/AuthAdapter.js +2 -1
- package/dist/abstractions/DefaultLockManager.d.ts +2 -2
- package/dist/abstractions/DefaultLockManager.d.ts.map +1 -1
- package/dist/abstractions/DefaultLockManager.js +6 -2
- package/dist/abstractions/DefaultRoomManager.d.ts +2 -2
- package/dist/abstractions/DefaultRoomManager.d.ts.map +1 -1
- package/dist/abstractions/DefaultRoomManager.js +6 -2
- package/dist/abstractions/EventEmitter.js +5 -1
- package/dist/abstractions/LockManager.d.ts +1 -1
- package/dist/abstractions/LockManager.d.ts.map +1 -1
- package/dist/abstractions/LockManager.js +5 -1
- package/dist/abstractions/RoomManager.d.ts +1 -1
- package/dist/abstractions/RoomManager.d.ts.map +1 -1
- package/dist/abstractions/RoomManager.js +5 -1
- package/dist/abstractions/StorageAdapter.js +2 -1
- package/dist/abstractions/TransportAdapter.d.ts +6 -1
- package/dist/abstractions/TransportAdapter.d.ts.map +1 -1
- package/dist/abstractions/TransportAdapter.js +2 -1
- package/dist/abstractions/index.d.ts +8 -8
- package/dist/abstractions/index.d.ts.map +1 -1
- package/dist/abstractions/index.js +13 -5
- package/dist/adapters/mock/MockAuthAdapter.d.ts +5 -2
- package/dist/adapters/mock/MockAuthAdapter.d.ts.map +1 -1
- package/dist/adapters/mock/MockAuthAdapter.js +62 -14
- package/dist/adapters/mock/MockStorageAdapter.d.ts +1 -1
- package/dist/adapters/mock/MockStorageAdapter.d.ts.map +1 -1
- package/dist/adapters/mock/MockStorageAdapter.js +5 -1
- package/dist/adapters/mock/MockTransportAdapter.d.ts +2 -2
- package/dist/adapters/mock/MockTransportAdapter.d.ts.map +1 -1
- package/dist/adapters/mock/MockTransportAdapter.js +5 -1
- package/dist/adapters/mock/index.d.ts +3 -3
- package/dist/adapters/mock/index.d.ts.map +1 -1
- package/dist/adapters/mock/index.js +9 -3
- package/dist/adapters/websocket/WebSocketTransportAdapter.d.ts +60 -0
- package/dist/adapters/websocket/WebSocketTransportAdapter.d.ts.map +1 -0
- package/dist/adapters/websocket/WebSocketTransportAdapter.js +384 -0
- package/dist/adapters/websocket/index.d.ts +2 -0
- package/dist/adapters/websocket/index.d.ts.map +1 -0
- package/dist/adapters/websocket/index.js +5 -0
- package/dist/client/BaseClient.d.ts +5 -5
- package/dist/client/BaseClient.d.ts.map +1 -1
- package/dist/client/BaseClient.js +10 -4
- package/dist/client/ClientBuilder.d.ts +4 -4
- package/dist/client/ClientBuilder.d.ts.map +1 -1
- package/dist/client/ClientBuilder.js +7 -3
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +7 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -5
- package/dist/index.js.map +29 -14
- package/dist/index.mjs +3386 -17
- package/dist/index.mjs.map +29 -14
- package/dist/server/BaseServer.d.ts +21 -8
- package/dist/server/BaseServer.d.ts.map +1 -1
- package/dist/server/BaseServer.js +109 -2
- package/dist/server/ServerBuilder.d.ts +16 -7
- package/dist/server/ServerBuilder.d.ts.map +1 -1
- package/dist/server/ServerBuilder.js +23 -4
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +7 -2
- package/dist/types/auth.d.ts +14 -7
- package/dist/types/auth.d.ts.map +1 -1
- package/dist/types/auth.js +2 -1
- package/dist/types/events.d.ts +1 -1
- package/dist/types/events.d.ts.map +1 -1
- package/dist/types/events.js +2 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -1
- package/dist/types/lock.js +2 -1
- package/dist/types/room.d.ts +2 -2
- package/dist/types/room.d.ts.map +1 -1
- package/dist/types/room.js +2 -1
- package/package.json +5 -2
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketTransportAdapter = void 0;
|
|
4
|
+
const ws_1 = require("ws");
|
|
5
|
+
class WebSocketTransportAdapter {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.state = 'disconnected';
|
|
8
|
+
this.messageHandlers = new Set();
|
|
9
|
+
this.errorHandlers = new Set();
|
|
10
|
+
this.closeHandlers = new Set();
|
|
11
|
+
// Client management
|
|
12
|
+
this.clients = new Map();
|
|
13
|
+
this.mode = 'standalone';
|
|
14
|
+
this.config = {
|
|
15
|
+
authTimeout: config?.authTimeout ?? 5000,
|
|
16
|
+
closeOnAuthFailure: config?.closeOnAuthFailure ?? false,
|
|
17
|
+
requireAuth: config?.requireAuth ?? false,
|
|
18
|
+
...config
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
// Set the auth adapter
|
|
22
|
+
setAuthAdapter(auth) {
|
|
23
|
+
this.authAdapter = auth;
|
|
24
|
+
// Update requireAuth based on auth adapter's preference
|
|
25
|
+
if (auth.isAuthRequired) {
|
|
26
|
+
this.config.requireAuth = auth.isAuthRequired();
|
|
27
|
+
}
|
|
28
|
+
if (auth.getAuthTimeout) {
|
|
29
|
+
this.config.authTimeout = auth.getAuthTimeout();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Standalone mode implementation
|
|
33
|
+
async connect(url, _options) {
|
|
34
|
+
if (this.state === 'connected' || this.state === 'connecting') {
|
|
35
|
+
throw new Error('Already connected or connecting');
|
|
36
|
+
}
|
|
37
|
+
this.state = 'connecting';
|
|
38
|
+
this.serverUrl = url;
|
|
39
|
+
this.mode = 'standalone';
|
|
40
|
+
try {
|
|
41
|
+
// Extract port from URL
|
|
42
|
+
const urlObj = new URL(url);
|
|
43
|
+
const port = parseInt(urlObj.port) || (urlObj.protocol === 'wss:' ? 443 : 80);
|
|
44
|
+
// Create WebSocket server
|
|
45
|
+
this.wss = new ws_1.WebSocketServer({ port });
|
|
46
|
+
this.wss.on('connection', (ws, req) => {
|
|
47
|
+
this.handleConnection(ws, req);
|
|
48
|
+
});
|
|
49
|
+
this.wss.on('error', (error) => {
|
|
50
|
+
this.errorHandlers.forEach(handler => handler(error));
|
|
51
|
+
});
|
|
52
|
+
this.wss.on('close', () => {
|
|
53
|
+
this.state = 'disconnected';
|
|
54
|
+
this.closeHandlers.forEach(handler => handler(1000, 'Server closed'));
|
|
55
|
+
});
|
|
56
|
+
this.state = 'connected';
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
this.state = 'disconnected';
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Integration mode implementation
|
|
64
|
+
async attach(server, path = '/ws') {
|
|
65
|
+
if (this.state === 'connected' || this.state === 'connecting') {
|
|
66
|
+
throw new Error('Already connected or connecting');
|
|
67
|
+
}
|
|
68
|
+
this.state = 'connecting';
|
|
69
|
+
this.attachedServer = server;
|
|
70
|
+
this.webSocketPath = path;
|
|
71
|
+
this.mode = 'integration';
|
|
72
|
+
try {
|
|
73
|
+
// Create WebSocket server attached to the existing HTTP server
|
|
74
|
+
this.wss = new ws_1.WebSocketServer({
|
|
75
|
+
server,
|
|
76
|
+
path,
|
|
77
|
+
perMessageDeflate: false
|
|
78
|
+
});
|
|
79
|
+
this.wss.on('connection', (ws, req) => {
|
|
80
|
+
this.handleConnection(ws, req);
|
|
81
|
+
});
|
|
82
|
+
this.wss.on('error', (error) => {
|
|
83
|
+
this.errorHandlers.forEach(handler => handler(error));
|
|
84
|
+
});
|
|
85
|
+
this.state = 'connected';
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
this.state = 'disconnected';
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async attachToWebSocketServer(wss) {
|
|
93
|
+
if (this.state === 'connected' || this.state === 'connecting') {
|
|
94
|
+
throw new Error('Already connected or connecting');
|
|
95
|
+
}
|
|
96
|
+
this.state = 'connecting';
|
|
97
|
+
this.attachedWss = wss;
|
|
98
|
+
this.mode = 'integration';
|
|
99
|
+
try {
|
|
100
|
+
this.wss = wss;
|
|
101
|
+
this.wss.on('connection', (ws, req) => {
|
|
102
|
+
this.handleConnection(ws, req);
|
|
103
|
+
});
|
|
104
|
+
this.wss.on('error', (error) => {
|
|
105
|
+
this.errorHandlers.forEach(handler => handler(error));
|
|
106
|
+
});
|
|
107
|
+
this.state = 'connected';
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
this.state = 'disconnected';
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async handleConnection(ws, req) {
|
|
115
|
+
const clientId = this.generateId();
|
|
116
|
+
// Step 1: Try header authentication if auth adapter is available
|
|
117
|
+
let authenticated = false;
|
|
118
|
+
let authResult = null;
|
|
119
|
+
if (this.authAdapter && req.headers.authorization) {
|
|
120
|
+
const token = this.extractBearerToken(req.headers.authorization);
|
|
121
|
+
if (token) {
|
|
122
|
+
try {
|
|
123
|
+
authResult = await this.authAdapter.authenticate({
|
|
124
|
+
type: 'bearer',
|
|
125
|
+
token: token
|
|
126
|
+
});
|
|
127
|
+
authenticated = authResult.success;
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Header auth failed but don't reject connection
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Step 2: Create client with auth state
|
|
135
|
+
const client = {
|
|
136
|
+
id: clientId,
|
|
137
|
+
ws,
|
|
138
|
+
authenticated,
|
|
139
|
+
userId: authResult?.userId || (authResult?.user?.userId),
|
|
140
|
+
metadata: authResult?.metadata || authResult?.user?.metadata,
|
|
141
|
+
connectedAt: Date.now()
|
|
142
|
+
};
|
|
143
|
+
this.clients.set(clientId, client);
|
|
144
|
+
// Step 3: Set up message handling
|
|
145
|
+
ws.on('message', (data) => {
|
|
146
|
+
this.handleClientMessage(clientId, data);
|
|
147
|
+
});
|
|
148
|
+
ws.on('error', (error) => {
|
|
149
|
+
this.errorHandlers.forEach(handler => handler(error));
|
|
150
|
+
});
|
|
151
|
+
ws.on('close', (_code, _reason) => {
|
|
152
|
+
// Clear auth timeout if exists
|
|
153
|
+
if (client.authTimeout) {
|
|
154
|
+
clearTimeout(client.authTimeout);
|
|
155
|
+
}
|
|
156
|
+
this.clients.delete(clientId);
|
|
157
|
+
});
|
|
158
|
+
// Step 4: Set auth timeout if not authenticated and auth is required
|
|
159
|
+
if (!authenticated && this.config.requireAuth && this.authAdapter) {
|
|
160
|
+
client.authTimeout = setTimeout(() => {
|
|
161
|
+
if (!client.authenticated) {
|
|
162
|
+
ws.close(1008, 'Authentication timeout');
|
|
163
|
+
this.clients.delete(clientId);
|
|
164
|
+
}
|
|
165
|
+
}, this.config.authTimeout);
|
|
166
|
+
}
|
|
167
|
+
// Step 5: Notify about connection (with auth status)
|
|
168
|
+
const connectionMessage = {
|
|
169
|
+
id: this.generateId(),
|
|
170
|
+
type: 'connection',
|
|
171
|
+
payload: {
|
|
172
|
+
clientId,
|
|
173
|
+
authenticated,
|
|
174
|
+
userId: client.userId,
|
|
175
|
+
metadata: client.metadata
|
|
176
|
+
},
|
|
177
|
+
timestamp: Date.now()
|
|
178
|
+
};
|
|
179
|
+
this.messageHandlers.forEach(handler => handler(connectionMessage));
|
|
180
|
+
}
|
|
181
|
+
async handleClientMessage(clientId, data) {
|
|
182
|
+
const client = this.clients.get(clientId);
|
|
183
|
+
if (!client)
|
|
184
|
+
return;
|
|
185
|
+
try {
|
|
186
|
+
const message = JSON.parse(data.toString());
|
|
187
|
+
// Special handling for authentication messages
|
|
188
|
+
if (message.type === 'authenticate' && !client.authenticated && this.authAdapter) {
|
|
189
|
+
await this.handleAuthMessage(client, message);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
// Reject messages from unauthenticated clients if auth is required
|
|
193
|
+
if (this.config.requireAuth && !client.authenticated) {
|
|
194
|
+
this.sendToClient(client, {
|
|
195
|
+
id: this.generateId(),
|
|
196
|
+
type: 'error',
|
|
197
|
+
payload: { error: 'Authentication required' },
|
|
198
|
+
timestamp: Date.now()
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
// Add clientId to message payload for routing
|
|
203
|
+
const enrichedMessage = {
|
|
204
|
+
...message,
|
|
205
|
+
payload: {
|
|
206
|
+
...message.payload,
|
|
207
|
+
clientId
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
this.messageHandlers.forEach(handler => handler(enrichedMessage));
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
this.errorHandlers.forEach(handler => handler(error));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async handleAuthMessage(client, message) {
|
|
217
|
+
if (!this.authAdapter) {
|
|
218
|
+
this.sendToClient(client, {
|
|
219
|
+
id: this.generateId(),
|
|
220
|
+
type: 'auth_error',
|
|
221
|
+
payload: { error: 'No auth adapter configured' },
|
|
222
|
+
timestamp: Date.now()
|
|
223
|
+
});
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
const credentials = message.payload;
|
|
228
|
+
const result = await this.authAdapter.authenticate(credentials);
|
|
229
|
+
if (result.success) {
|
|
230
|
+
// Clear auth timeout
|
|
231
|
+
if (client.authTimeout) {
|
|
232
|
+
clearTimeout(client.authTimeout);
|
|
233
|
+
client.authTimeout = undefined;
|
|
234
|
+
}
|
|
235
|
+
// Update client state
|
|
236
|
+
client.authenticated = true;
|
|
237
|
+
client.userId = result.userId || result.user?.userId;
|
|
238
|
+
client.metadata = result.metadata || result.user?.metadata;
|
|
239
|
+
// Send success response
|
|
240
|
+
this.sendToClient(client, {
|
|
241
|
+
id: this.generateId(),
|
|
242
|
+
type: 'auth_success',
|
|
243
|
+
payload: {
|
|
244
|
+
userId: client.userId,
|
|
245
|
+
metadata: client.metadata
|
|
246
|
+
},
|
|
247
|
+
timestamp: Date.now()
|
|
248
|
+
});
|
|
249
|
+
// Notify handlers about authentication
|
|
250
|
+
const authMessage = {
|
|
251
|
+
id: this.generateId(),
|
|
252
|
+
type: 'client_authenticated',
|
|
253
|
+
payload: {
|
|
254
|
+
clientId: client.id,
|
|
255
|
+
userId: client.userId,
|
|
256
|
+
metadata: client.metadata
|
|
257
|
+
},
|
|
258
|
+
timestamp: Date.now()
|
|
259
|
+
};
|
|
260
|
+
this.messageHandlers.forEach(handler => handler(authMessage));
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
// Send error response
|
|
264
|
+
this.sendToClient(client, {
|
|
265
|
+
id: this.generateId(),
|
|
266
|
+
type: 'auth_error',
|
|
267
|
+
payload: { error: result.error || 'Authentication failed' },
|
|
268
|
+
timestamp: Date.now()
|
|
269
|
+
});
|
|
270
|
+
// Optionally close connection
|
|
271
|
+
if (this.config.closeOnAuthFailure) {
|
|
272
|
+
client.ws.close(1008, 'Authentication failed');
|
|
273
|
+
this.clients.delete(client.id);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
this.sendToClient(client, {
|
|
279
|
+
id: this.generateId(),
|
|
280
|
+
type: 'auth_error',
|
|
281
|
+
payload: { error: error.message },
|
|
282
|
+
timestamp: Date.now()
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
extractBearerToken(authHeader) {
|
|
287
|
+
if (authHeader.startsWith('Bearer ')) {
|
|
288
|
+
return authHeader.substring(7);
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
sendToClient(client, message) {
|
|
293
|
+
if (client.ws.readyState === ws_1.WebSocket.OPEN) {
|
|
294
|
+
client.ws.send(JSON.stringify(message));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async disconnect() {
|
|
298
|
+
if (this.state === 'disconnected') {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
this.state = 'disconnecting';
|
|
302
|
+
// Close all client connections
|
|
303
|
+
for (const [_clientId, client] of this.clients) {
|
|
304
|
+
try {
|
|
305
|
+
if (client.authTimeout) {
|
|
306
|
+
clearTimeout(client.authTimeout);
|
|
307
|
+
}
|
|
308
|
+
client.ws.close(1000, 'Server shutting down');
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
// Ignore errors when closing individual connections
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
this.clients.clear();
|
|
315
|
+
// Close the WebSocket server (only if we created it)
|
|
316
|
+
if (this.wss && this.mode === 'standalone') {
|
|
317
|
+
await new Promise((resolve) => {
|
|
318
|
+
this.wss.close(() => resolve());
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
this.state = 'disconnected';
|
|
322
|
+
this.wss = undefined;
|
|
323
|
+
this.attachedServer = undefined;
|
|
324
|
+
this.attachedWss = undefined;
|
|
325
|
+
}
|
|
326
|
+
async send(message) {
|
|
327
|
+
if (this.state !== 'connected') {
|
|
328
|
+
throw new Error('Not connected');
|
|
329
|
+
}
|
|
330
|
+
// Extract clientId from message payload for routing
|
|
331
|
+
const payload = message.payload;
|
|
332
|
+
const { clientId, ...clientMessage } = payload;
|
|
333
|
+
if (!clientId) {
|
|
334
|
+
throw new Error('Message must contain clientId in payload for routing');
|
|
335
|
+
}
|
|
336
|
+
const client = this.clients.get(clientId);
|
|
337
|
+
if (!client) {
|
|
338
|
+
throw new Error(`Client ${clientId} not found`);
|
|
339
|
+
}
|
|
340
|
+
if (client.ws.readyState !== ws_1.WebSocket.OPEN) {
|
|
341
|
+
throw new Error(`Client ${clientId} connection is not open`);
|
|
342
|
+
}
|
|
343
|
+
const messageToSend = {
|
|
344
|
+
...message,
|
|
345
|
+
payload: clientMessage
|
|
346
|
+
};
|
|
347
|
+
client.ws.send(JSON.stringify(messageToSend));
|
|
348
|
+
}
|
|
349
|
+
onMessage(handler) {
|
|
350
|
+
this.messageHandlers.add(handler);
|
|
351
|
+
}
|
|
352
|
+
onError(handler) {
|
|
353
|
+
this.errorHandlers.add(handler);
|
|
354
|
+
}
|
|
355
|
+
onClose(handler) {
|
|
356
|
+
this.closeHandlers.add(handler);
|
|
357
|
+
}
|
|
358
|
+
getState() {
|
|
359
|
+
return this.state;
|
|
360
|
+
}
|
|
361
|
+
isConnected() {
|
|
362
|
+
return this.state === 'connected';
|
|
363
|
+
}
|
|
364
|
+
// Utility methods
|
|
365
|
+
getConnectedClients() {
|
|
366
|
+
return Array.from(this.clients.values());
|
|
367
|
+
}
|
|
368
|
+
getAuthenticatedClients() {
|
|
369
|
+
return Array.from(this.clients.values()).filter(c => c.authenticated);
|
|
370
|
+
}
|
|
371
|
+
getClientCount() {
|
|
372
|
+
return this.clients.size;
|
|
373
|
+
}
|
|
374
|
+
getMode() {
|
|
375
|
+
return this.mode;
|
|
376
|
+
}
|
|
377
|
+
isAuthRequired() {
|
|
378
|
+
return this.config.requireAuth ?? false;
|
|
379
|
+
}
|
|
380
|
+
generateId() {
|
|
381
|
+
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
exports.WebSocketTransportAdapter = WebSocketTransportAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/websocket/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,KAAK,wBAAwB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketTransportAdapter = void 0;
|
|
4
|
+
var WebSocketTransportAdapter_js_1 = require("./WebSocketTransportAdapter.js");
|
|
5
|
+
Object.defineProperty(exports, "WebSocketTransportAdapter", { enumerable: true, get: function () { return WebSocketTransportAdapter_js_1.WebSocketTransportAdapter; } });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ConnectionState, Event, RoomState, RoomUser, LockRequest, Lock, Credentials } from '../types';
|
|
2
|
-
import type { ITransportAdapter } from '../abstractions/TransportAdapter';
|
|
3
|
-
import type { IAuthAdapter } from '../abstractions/AuthAdapter';
|
|
4
|
-
import type { IStorageAdapter } from '../abstractions/StorageAdapter';
|
|
5
|
-
import { TypedEventEmitter } from '../abstractions/EventEmitter';
|
|
1
|
+
import type { ConnectionState, Event, RoomState, RoomUser, LockRequest, Lock, Credentials } from '../types/index.js';
|
|
2
|
+
import type { ITransportAdapter } from '../abstractions/TransportAdapter.js';
|
|
3
|
+
import type { IAuthAdapter } from '../abstractions/AuthAdapter.js';
|
|
4
|
+
import type { IStorageAdapter } from '../abstractions/StorageAdapter.js';
|
|
5
|
+
import { TypedEventEmitter } from '../abstractions/EventEmitter.js';
|
|
6
6
|
export interface ClientConfig {
|
|
7
7
|
transport: ITransportAdapter;
|
|
8
8
|
auth?: IAuthAdapter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../src/client/BaseClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAGf,KAAK,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,WAAW,EACZ,MAAM,
|
|
1
|
+
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../src/client/BaseClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAGf,KAAK,EACL,SAAS,EACT,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,E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IzB,gBAAgB,IAAI,MAAM,GAAG,IAAI;IAIjC,SAAS,IAAI,MAAM,GAAG,IAAI;YAKZ,aAAa;YAkCb,WAAW;YAIX,WAAW;YAcX,gBAAgB;YAMhB,cAAc;YAQd,oBAAoB;YAIpB,kBAAkB;YAIlB,kBAAkB;YAIlB,gBAAgB;YAIhB,qBAAqB;YAQrB,iBAAiB;YAKjB,iBAAiB;IA0B/B,OAAO,CAAC,UAAU;CAGnB"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClient = void 0;
|
|
4
|
+
const EventEmitter_js_1 = require("../abstractions/EventEmitter.js");
|
|
5
|
+
class BaseClient extends EventEmitter_js_1.TypedEventEmitter {
|
|
3
6
|
constructor(config) {
|
|
4
7
|
super();
|
|
5
8
|
this.connectionState = 'disconnected';
|
|
@@ -33,8 +36,10 @@ export class BaseClient extends TypedEventEmitter {
|
|
|
33
36
|
// Authenticate if credentials provided and auth adapter available
|
|
34
37
|
if (credentials && this.auth) {
|
|
35
38
|
const authResult = await this.auth.authenticate(credentials);
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
if (authResult.success && authResult.token) {
|
|
40
|
+
this.authToken = authResult.token;
|
|
41
|
+
this.userId = authResult.user?.userId || authResult.userId || '';
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
const options = {
|
|
40
45
|
url,
|
|
@@ -280,3 +285,4 @@ export class BaseClient extends TypedEventEmitter {
|
|
|
280
285
|
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
281
286
|
}
|
|
282
287
|
}
|
|
288
|
+
exports.BaseClient = BaseClient;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ITransportAdapter } from '../abstractions/TransportAdapter';
|
|
2
|
-
import type { IAuthAdapter } from '../abstractions/AuthAdapter';
|
|
3
|
-
import type { IStorageAdapter } from '../abstractions/StorageAdapter';
|
|
4
|
-
import { BaseClient, type ClientConfig } from './BaseClient';
|
|
1
|
+
import type { ITransportAdapter } from '../abstractions/TransportAdapter.js';
|
|
2
|
+
import type { IAuthAdapter } from '../abstractions/AuthAdapter.js';
|
|
3
|
+
import type { IStorageAdapter } from '../abstractions/StorageAdapter.js';
|
|
4
|
+
import { BaseClient, type ClientConfig } from './BaseClient.js';
|
|
5
5
|
export declare class ClientBuilder {
|
|
6
6
|
private transport?;
|
|
7
7
|
private auth?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientBuilder.d.ts","sourceRoot":"","sources":["../../src/client/ClientBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ClientBuilder.d.ts","sourceRoot":"","sources":["../../src/client/ClientBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEhE,qBAAa,aAAa;IACxB,OAAO,CAAC,SAAS,CAAC,CAAoB;IACtC,OAAO,CAAC,IAAI,CAAC,CAAe;IAC5B,OAAO,CAAC,OAAO,CAAC,CAAkB;IAClC,OAAO,CAAC,YAAY,CAAC,CAA+B;IAEpD,aAAa,CAAC,SAAS,EAAE,iBAAiB,GAAG,IAAI;IAKjD,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAKlC,WAAW,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAK3C,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,GAAG,IAAI;IAKzE,KAAK,IAAI,UAAU;CAoBpB"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientBuilder = void 0;
|
|
4
|
+
const BaseClient_js_1 = require("./BaseClient.js");
|
|
5
|
+
class ClientBuilder {
|
|
3
6
|
withTransport(transport) {
|
|
4
7
|
this.transport = transport;
|
|
5
8
|
return this;
|
|
@@ -32,6 +35,7 @@ export class ClientBuilder {
|
|
|
32
35
|
backoffFactor: 2
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
|
-
return new BaseClient(config);
|
|
38
|
+
return new BaseClient_js_1.BaseClient(config);
|
|
36
39
|
}
|
|
37
40
|
}
|
|
41
|
+
exports.ClientBuilder = ClientBuilder;
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { BaseClient, type ClientConfig, type ClientEvents } from './BaseClient';
|
|
2
|
-
export { ClientBuilder } from './ClientBuilder';
|
|
1
|
+
export { BaseClient, type ClientConfig, type ClientEvents } from './BaseClient.js';
|
|
2
|
+
export { ClientBuilder } from './ClientBuilder.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/client/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ClientBuilder = exports.BaseClient = void 0;
|
|
1
4
|
// Client-side implementations
|
|
2
|
-
|
|
3
|
-
|
|
5
|
+
var BaseClient_js_1 = require("./BaseClient.js");
|
|
6
|
+
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return BaseClient_js_1.BaseClient; } });
|
|
7
|
+
var ClientBuilder_js_1 = require("./ClientBuilder.js");
|
|
8
|
+
Object.defineProperty(exports, "ClientBuilder", { enumerable: true, get: function () { return ClientBuilder_js_1.ClientBuilder; } });
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { EventType, BaseEvent, FileAction, FileChangeEvent, GitStatusEvent, CommitEvent, BranchChangeEvent, CursorPositionEvent, Event, TokenPayload, AuthResult, CredentialType, OAuthProvider, Credentials, JWTConfig, OAuthConfig, AuthProvider, RoomPermission, Room, RoomUser, UserStatus, RoomState, RoomConfig, LockType, LockPriority, Lock, LockRequest, LockQueueItem, LockState, ConnectionState, ConnectionOptions, Message, MessageHandler, ErrorHandler, CloseHandler } from './types';
|
|
2
|
-
export { ITransportAdapter, IStorageAdapter, StorageOperation, IAuthAdapter, TypedEventEmitter, EventListener, UnsubscribeFn, RoomManager, LockManager, DefaultRoomManager, DefaultLockManager } from './abstractions';
|
|
3
|
-
export { MockTransportAdapter, MockStorageAdapter, MockAuthAdapter } from './adapters/mock';
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { EventType, BaseEvent, FileAction, FileChangeEvent, GitStatusEvent, CommitEvent, BranchChangeEvent, CursorPositionEvent, Event, TokenPayload, AuthResult, CredentialType, OAuthProvider, Credentials, JWTConfig, OAuthConfig, AuthProvider, RoomPermission, Room, RoomUser, UserStatus, RoomState, RoomConfig, LockType, LockPriority, Lock, LockRequest, LockQueueItem, LockState, ConnectionState, ConnectionOptions, Message, MessageHandler, ErrorHandler, CloseHandler } from './types/index.js';
|
|
2
|
+
export { ITransportAdapter, IStorageAdapter, StorageOperation, IAuthAdapter, TypedEventEmitter, EventListener, UnsubscribeFn, RoomManager, LockManager, DefaultRoomManager, DefaultLockManager } from './abstractions/index.js';
|
|
3
|
+
export { MockTransportAdapter, MockStorageAdapter, MockAuthAdapter } from './adapters/mock/index.js';
|
|
4
|
+
export { WebSocketTransportAdapter, type WebSocketTransportConfig } from './adapters/websocket/index.js';
|
|
5
|
+
export { BaseClient, ClientBuilder, type ClientConfig, type ClientEvents } from './client/index.js';
|
|
6
|
+
export { BaseServer, ServerBuilder, type ServerConfig, type ServerEvents, type ConnectedClient } from './server/index.js';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,SAAS,EACT,SAAS,EACT,UAAU,EACV,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,EAEL,YAAY,EACZ,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,WAAW,EACX,YAAY,EAEZ,cAAc,EACd,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EAEV,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,aAAa,EACb,SAAS,EAET,eAAe,EACf,iBAAiB,EACjB,OAAO,EACP,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,SAAS,EACT,SAAS,EACT,UAAU,EACV,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,EAEL,YAAY,EACZ,UAAU,EACV,cAAc,EACd,aAAa,EACb,WAAW,EACX,SAAS,EACT,WAAW,EACX,YAAY,EAEZ,cAAc,EACd,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,UAAU,EAEV,QAAQ,EACR,YAAY,EACZ,IAAI,EACJ,WAAW,EACX,aAAa,EACb,SAAS,EAET,eAAe,EACf,iBAAiB,EACjB,OAAO,EACP,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,yBAAyB,EACzB,KAAK,wBAAwB,EAC9B,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EACL,UAAU,EACV,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,EAClB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,UAAU,EACV,aAAa,EACb,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACrB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServerBuilder = exports.BaseServer = exports.ClientBuilder = exports.BaseClient = exports.WebSocketTransportAdapter = exports.MockAuthAdapter = exports.MockStorageAdapter = exports.MockTransportAdapter = exports.DefaultLockManager = exports.DefaultRoomManager = exports.LockManager = exports.RoomManager = exports.TypedEventEmitter = void 0;
|
|
1
4
|
// Abstractions
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
var index_js_1 = require("./abstractions/index.js");
|
|
6
|
+
Object.defineProperty(exports, "TypedEventEmitter", { enumerable: true, get: function () { return index_js_1.TypedEventEmitter; } });
|
|
7
|
+
Object.defineProperty(exports, "RoomManager", { enumerable: true, get: function () { return index_js_1.RoomManager; } });
|
|
8
|
+
Object.defineProperty(exports, "LockManager", { enumerable: true, get: function () { return index_js_1.LockManager; } });
|
|
9
|
+
Object.defineProperty(exports, "DefaultRoomManager", { enumerable: true, get: function () { return index_js_1.DefaultRoomManager; } });
|
|
10
|
+
Object.defineProperty(exports, "DefaultLockManager", { enumerable: true, get: function () { return index_js_1.DefaultLockManager; } });
|
|
11
|
+
// Adapters
|
|
12
|
+
var index_js_2 = require("./adapters/mock/index.js");
|
|
13
|
+
Object.defineProperty(exports, "MockTransportAdapter", { enumerable: true, get: function () { return index_js_2.MockTransportAdapter; } });
|
|
14
|
+
Object.defineProperty(exports, "MockStorageAdapter", { enumerable: true, get: function () { return index_js_2.MockStorageAdapter; } });
|
|
15
|
+
Object.defineProperty(exports, "MockAuthAdapter", { enumerable: true, get: function () { return index_js_2.MockAuthAdapter; } });
|
|
16
|
+
var index_js_3 = require("./adapters/websocket/index.js");
|
|
17
|
+
Object.defineProperty(exports, "WebSocketTransportAdapter", { enumerable: true, get: function () { return index_js_3.WebSocketTransportAdapter; } });
|
|
5
18
|
// Client
|
|
6
|
-
|
|
19
|
+
var index_js_4 = require("./client/index.js");
|
|
20
|
+
Object.defineProperty(exports, "BaseClient", { enumerable: true, get: function () { return index_js_4.BaseClient; } });
|
|
21
|
+
Object.defineProperty(exports, "ClientBuilder", { enumerable: true, get: function () { return index_js_4.ClientBuilder; } });
|
|
7
22
|
// Server
|
|
8
|
-
|
|
23
|
+
var index_js_5 = require("./server/index.js");
|
|
24
|
+
Object.defineProperty(exports, "BaseServer", { enumerable: true, get: function () { return index_js_5.BaseServer; } });
|
|
25
|
+
Object.defineProperty(exports, "ServerBuilder", { enumerable: true, get: function () { return index_js_5.ServerBuilder; } });
|