@limrun/ui 0.14.1 → 0.14.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limrun/ui",
3
- "version": "0.14.1",
3
+ "version": "0.14.2",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "tag": "next"
@@ -0,0 +1,34 @@
1
+ // Covers `withAuthenticationToken` only — the rest of <RemoteControl> is
2
+ // integration-tested (see vitest.config.ts).
3
+ //
4
+ // Assertions parse the result and read decoded parameter values, so they
5
+ // don't depend on whether a space serializes as `+` or `%20`.
6
+
7
+ import { describe, expect, test } from 'vitest';
8
+ import { withAuthenticationToken } from './remote-control';
9
+
10
+ describe('withAuthenticationToken', () => {
11
+ test('adds the token alongside query parameters already on the endpoint', () => {
12
+ const result = new URL(
13
+ withAuthenticationToken('wss://example.com/socket?transport=webrtc', 'instance-token'),
14
+ );
15
+
16
+ expect(result.searchParams.get('transport')).toBe('webrtc');
17
+ expect(result.searchParams.get('token')).toBe('instance-token');
18
+ });
19
+
20
+ test('keeps a token containing URL syntax as a single decoded value', () => {
21
+ const token = 'instance token&scope=preview';
22
+ const result = new URL(withAuthenticationToken('wss://example.com/socket?transport=webrtc', token));
23
+
24
+ expect(result.searchParams.get('token')).toBe(token);
25
+ expect(result.searchParams.get('transport')).toBe('webrtc');
26
+ expect(result.searchParams.get('scope')).toBeNull();
27
+ });
28
+
29
+ test('replaces an existing token instead of duplicating it', () => {
30
+ const result = new URL(withAuthenticationToken('wss://example.com/socket?token=stale', 'fresh-token'));
31
+
32
+ expect(result.searchParams.getAll('token')).toEqual(['fresh-token']);
33
+ });
34
+ });
@@ -437,6 +437,13 @@ const detectPlatform = (url: string): DevicePlatform => {
437
437
  return 'ios';
438
438
  };
439
439
 
440
+ // The endpoint may already carry query parameters, and the token may contain URL syntax.
441
+ export const withAuthenticationToken = (url: string, token: string): string => {
442
+ const endpoint = new URL(url);
443
+ endpoint.searchParams.set('token', token);
444
+ return endpoint.toString();
445
+ };
446
+
440
447
  type DeviceConfig = {
441
448
  videoBorderRadiusMultiplier: number;
442
449
  loadingLogo: string;
@@ -2276,8 +2283,7 @@ export const RemoteControl = forwardRef<RemoteControlHandle, RemoteControlProps>
2276
2283
  parsed.protocol === 'wss:' ? 'https:'
2277
2284
  : parsed.protocol === 'ws:' ? 'http:'
2278
2285
  : parsed.protocol;
2279
- parsed.searchParams.set('token', token);
2280
- probeUrl = parsed.toString();
2286
+ probeUrl = withAuthenticationToken(parsed.toString(), token);
2281
2287
  } catch {
2282
2288
  return false;
2283
2289
  }
@@ -2401,7 +2407,7 @@ export const RemoteControl = forwardRef<RemoteControlHandle, RemoteControlProps>
2401
2407
  }, CONNECTION_SUCCESS_TIMEOUT_MS);
2402
2408
 
2403
2409
  try {
2404
- const ws = new WebSocket(`${url}?token=${token}`);
2410
+ const ws = new WebSocket(withAuthenticationToken(url, token));
2405
2411
  wsRef.current = ws;
2406
2412
 
2407
2413
  // Wait for WebSocket to connect
package/vitest.config.ts CHANGED
@@ -12,8 +12,9 @@ import { defineConfig } from 'vitest/config';
12
12
  //
13
13
  // The actual <RemoteControl> component is intentionally NOT under unit
14
14
  // test here — its WebRTC plumbing is integration-tested via the demo +
15
- // staging instance. These tests cover the smaller, pure-logic modules:
16
- // `core/ax-tree.ts` and `core/ax-fetcher.ts`.
15
+ // staging instance. These tests cover the smaller, pure-logic pieces:
16
+ // `core/ax-tree.ts`, `core/ax-fetcher.ts` and the URL helper exported from
17
+ // `components/remote-control.tsx`.
17
18
  export default defineConfig({
18
19
  test: {
19
20
  environment: 'jsdom',