bxo 0.0.10-dev.1 โ†’ 0.0.10-dev.2

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.
@@ -143,19 +143,18 @@ async function main() {
143
143
  console.log(` ๐Ÿ” Search Params:`, data.searchParams);
144
144
  console.log(` ๐Ÿ” Authorization:`, data.authorization || 'None');
145
145
 
146
- // Use convenience methods
147
- console.log(` ๐Ÿช Session Cookie:`, data.getCookie('sessionId'));
148
- console.log(` ๐Ÿ” Room Param:`, data.getSearchParam('room'));
149
- console.log(` ๐Ÿ‘ค Username:`, data.getUsername());
150
- console.log(` ๐Ÿ  Room:`, data.getRoom());
151
- console.log(` ๐Ÿ” Has Auth:`, data.hasAuth());
152
- console.log(` ๐Ÿ”‘ Auth Type:`, data.getAuthType());
153
- console.log(` ๐ŸŽซ Token:`, data.getToken());
146
+ // Use direct property access
147
+ console.log(` ๐Ÿช Session Cookie:`, data.cookies.sessionId);
148
+ console.log(` ๐Ÿ” Room Param:`, data.searchParams.room);
149
+ console.log(` ๐Ÿ‘ค Username:`, data.searchParams.user || data.searchParams.username);
150
+ console.log(` ๐Ÿ  Room:`, data.searchParams.room);
151
+ console.log(` ๐Ÿ” Has Auth:`, !!(data.authorization || data.searchParams.token || data.searchParams.auth));
152
+ console.log(` ๐Ÿ”‘ Auth Type:`, data.authorization ? (data.authorization.toLowerCase().startsWith('bearer ') ? 'bearer' : 'basic') : 'none');
153
+ console.log(` ๐ŸŽซ Token:`, data.searchParams.token || data.searchParams.auth);
154
154
 
155
- // Check for authentication using convenience methods
156
- if (data.hasAuth()) {
157
- const authType = data.getAuthType();
158
- console.log(` โœ… Authenticated user detected (${authType})`);
155
+ // Check for authentication using direct property access
156
+ if (data.authorization || data.searchParams.token || data.searchParams.auth) {
157
+ console.log(` โœ… Authenticated user detected`);
159
158
  ws.send(`Welcome authenticated user! Your WebSocket ID is: ${data.id}`);
160
159
  } else {
161
160
  ws.send(`Welcome! Your WebSocket ID is: ${data.id}`);
@@ -169,10 +168,10 @@ async function main() {
169
168
  console.log(` ๐Ÿ” Search params:`, data.searchParams);
170
169
  console.log(` ๐Ÿ” Auth:`, data.authorization || 'None');
171
170
 
172
- // Use convenience methods for cleaner code
173
- const username = data.getUsername() || 'Anonymous';
174
- const room = data.getRoom();
175
- const sessionId = data.getCookie('sessionId');
171
+ // Use direct property access
172
+ const username = data.searchParams.user || data.searchParams.username || 'Anonymous';
173
+ const room = data.searchParams.room;
174
+ const sessionId = data.cookies.sessionId;
176
175
 
177
176
  console.log(` ๐Ÿ‘ค Username: ${username}`);
178
177
  console.log(` ๐Ÿ  Room: ${room || 'None'}`);
@@ -181,7 +180,7 @@ async function main() {
181
180
  // Echo the message back with client ID and context
182
181
  let response = `[${data.id}] Echo: ${message}`;
183
182
 
184
- // Add context using convenience methods
183
+ // Add context using direct property access
185
184
  if (room) {
186
185
  response += ` (Room: ${room})`;
187
186
  }
@@ -219,10 +218,10 @@ async function main() {
219
218
  console.log(` ๐Ÿ” Search Params:`, data.searchParams);
220
219
  console.log(` ๐Ÿ” Authorization:`, data.authorization || 'None');
221
220
 
222
- // Use convenience methods for cleaner code
223
- const username = data.getUsername() || 'Anonymous';
224
- const sessionId = data.getCookie('sessionId');
225
- const hasAuth = data.hasAuth();
221
+ // Use direct property access
222
+ const username = data.searchParams.user || data.searchParams.username || 'Anonymous';
223
+ const sessionId = data.cookies.sessionId;
224
+ const hasAuth = !!(data.authorization || data.searchParams.token || data.searchParams.auth);
226
225
 
227
226
  console.log(` ๐Ÿ‘ค Username: ${username}`);
228
227
  console.log(` ๐Ÿช Session: ${sessionId || 'None'}`);
@@ -234,8 +233,8 @@ async function main() {
234
233
  message(ws, message) {
235
234
  const data = ws.data; // Fully typed WebSocketData
236
235
  const room = data.path.split('/').pop() || 'unknown';
237
- const username = data.getUsername() || 'Anonymous';
238
- const sessionId = data.getCookie('sessionId');
236
+ const username = data.searchParams.user || data.searchParams.username || 'Anonymous';
237
+ const sessionId = data.cookies.sessionId;
239
238
 
240
239
  console.log(`๐Ÿ’ฌ Message in room ${room} from ${data.id} (${username}):`, message);
241
240
  console.log(` ๐Ÿช Client cookies:`, data.cookies);
@@ -263,15 +262,12 @@ async function main() {
263
262
  console.log(` โ€ข ws.data.searchParams - Query parameters from URL`);
264
263
  console.log(` โ€ข ws.data.authorization - Authorization header`);
265
264
  console.log(` โ€ข Client IP, User Agent, Origin tracking`);
266
- console.log(`\n๐Ÿ”ง Typed Interface Methods:`);
267
- console.log(` โ€ข ws.data.getCookie(name) - Get specific cookie`);
268
- console.log(` โ€ข ws.data.getSearchParam(name) - Get specific search param`);
269
- console.log(` โ€ข ws.data.hasAuth() - Check if authenticated`);
270
- console.log(` โ€ข ws.data.getAuthType() - Get authentication type`);
271
- console.log(` โ€ข ws.data.getToken() - Get authentication token`);
272
- console.log(` โ€ข ws.data.getUsername() - Get username from params`);
273
- console.log(` โ€ข ws.data.getRoom() - Get room from params`);
274
- console.log(` โ€ข ws.data.getUser() - Get user from params`);
265
+ console.log(`\n๐Ÿ”ง Direct Property Access:`);
266
+ console.log(` โ€ข ws.data.cookies.name - Get specific cookie`);
267
+ console.log(` โ€ข ws.data.searchParams.name - Get specific search param`);
268
+ console.log(` โ€ข ws.data.authorization - Check authorization header`);
269
+ console.log(` โ€ข ws.data.id - Short client identifier`);
270
+ console.log(` โ€ข ws.data.connectionId - Detailed connection ID`);
275
271
  console.log(`\n๐Ÿงช Test URLs:`);
276
272
  console.log(` โ€ข Basic: ws://localhost:${app.server?.port}/ws`);
277
273
  console.log(` โ€ข With params: ws://localhost:${app.server?.port}/ws?room=test&user=john&theme=dark`);
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  ".": "./src/index.ts",
6
6
  "./plugins": "./plugins/index.ts"
7
7
  },
8
- "version": "0.0.10-dev.1",
8
+ "version": "0.0.10-dev.2",
9
9
  "type": "module",
10
10
  "devDependencies": {
11
11
  "@types/bun": "latest"
package/src/index.ts CHANGED
@@ -108,15 +108,8 @@ export type WebSocketClientInfo = {
108
108
 
109
109
  // WebSocket data interface - this is what you get when accessing ws.data
110
110
  export interface WebSocketData extends WebSocketClientInfo {
111
- // Additional methods for convenience
112
- getCookie(name: string): string | undefined;
113
- getSearchParam(name: string): string | string[] | undefined;
114
- hasAuth(): boolean;
115
- getAuthType(): 'bearer' | 'basic' | 'custom' | 'none';
116
- getToken(): string | undefined;
117
- getUsername(): string | undefined;
118
- getRoom(): string | undefined;
119
- getUser(): string | undefined;
111
+ // Simple interface with just the data properties
112
+ // No convenience methods - use direct property access
120
113
  }
121
114
 
122
115
  // WebSocket handler types
@@ -530,48 +523,9 @@ export default class BXO {
530
523
  authorization: authHeader || undefined // Authorization header
531
524
  };
532
525
 
533
- // Create enhanced WebSocket data with convenience methods
526
+ // Create simple WebSocket data object
534
527
  const clientInfo: WebSocketData = {
535
- ...baseClientInfo,
536
-
537
- // Convenience methods
538
- getCookie(name: string): string | undefined {
539
- return this.cookies[name];
540
- },
541
-
542
- getSearchParam(name: string): string | string[] | undefined {
543
- return this.searchParams[name];
544
- },
545
-
546
- hasAuth(): boolean {
547
- return !!this.authorization || !!this.searchParams.token || !!this.searchParams.auth;
548
- },
549
-
550
- getAuthType(): 'bearer' | 'basic' | 'custom' | 'none' {
551
- if (!this.authorization) return 'none';
552
- if (this.authorization.toLowerCase().startsWith('bearer ')) return 'bearer';
553
- if (this.authorization.toLowerCase().startsWith('basic ')) return 'basic';
554
- return 'custom';
555
- },
556
-
557
- getToken(): string | undefined {
558
- if (this.authorization?.toLowerCase().startsWith('bearer ')) {
559
- return this.authorization.substring(7);
560
- }
561
- return this.searchParams.token as string || this.searchParams.auth as string;
562
- },
563
-
564
- getUsername(): string | undefined {
565
- return this.searchParams.user as string || this.searchParams.username as string;
566
- },
567
-
568
- getRoom(): string | undefined {
569
- return this.searchParams.room as string;
570
- },
571
-
572
- getUser(): string | undefined {
573
- return this.searchParams.user as string;
574
- }
528
+ ...baseClientInfo
575
529
  };
576
530
 
577
531
  const success = server.upgrade(req, {