@chitchat/sdk-react-native 0.1.0-dev.0 → 0.1.0-dev.1

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/README.md CHANGED
@@ -2,4 +2,6 @@
2
2
 
3
3
  `createChitChatNativeClient` uses the official native TLS TCP bridge. The app developer supplies a session-token provider and imports the module; endpoint resolution, reconnects, durable outbox behavior, and TLS transport selection are handled by the SDK.
4
4
 
5
+ Use a TLS `host:port` endpoint such as `realtime.chitchat.example:5223`; HTTP and WebSocket URLs are rejected by the native package.
6
+
5
7
  The native bridge contract is deliberately small: `connect`, `onFrame`, `onClose`, `send`, and `close`. It is the location where Android/iOS certificate pinning and binary Protobuf framing are enforced.
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@chitchat/sdk-react-native",
3
- "version": "0.1.0-dev.0",
3
+ "version": "0.1.0-dev.1",
4
4
  "main": "src/index.js",
5
+ "exports": "./src/index.js",
5
6
  "files": ["src", "README.md", "LICENSE"],
6
7
  "engines": { "node": ">=18" },
7
- "dependencies": { "@chitchat/sdk-core": "0.1.0-dev.0" },
8
+ "scripts": { "test": "node test/transport.test.js" },
9
+ "dependencies": { "@chitchat/sdk-core": "0.1.0-dev.1" },
8
10
  "license": "UNLICENSED",
9
11
  "publishConfig": { "access": "public", "tag": "development" }
10
12
  }
package/src/index.js CHANGED
@@ -3,9 +3,19 @@
3
3
  let ReliableRealtimeClient;
4
4
  try { ({ ReliableRealtimeClient } = require('@chitchat/sdk-core')); } catch (_) { ({ ReliableRealtimeClient } = require('../../chitchat-core/src')); }
5
5
 
6
+ const validateNativeTlsEndpoint = (endpoint) => {
7
+ if (typeof endpoint !== 'string' || !endpoint.trim() || /\s/.test(endpoint)) throw new Error('A TLS host:port endpoint is required');
8
+ if (/^(https?|wss?):\/\//i.test(endpoint)) throw new Error('React Native realtime requires a TLS TCP host:port endpoint, not a HTTP/WebSocket URL');
9
+ let parsed;
10
+ try { parsed = new URL(`tls://${endpoint}`); } catch (_) { throw new Error('A valid TLS host:port endpoint is required'); }
11
+ if (!parsed.hostname || !parsed.port || Number(parsed.port) < 1 || Number(parsed.port) > 65535 || parsed.username || parsed.password || (parsed.pathname && parsed.pathname !== '/')) throw new Error('A valid TLS host:port endpoint is required');
12
+ return endpoint;
13
+ };
14
+
6
15
  const createNativeTcpTransportFactory = ({ nativeModule }) => {
7
16
  if (!nativeModule || typeof nativeModule.connect !== 'function') throw new Error('The official ChitChat native TCP module is required');
8
17
  return async ({ endpoint, token, protocol }) => {
18
+ validateNativeTlsEndpoint(endpoint);
9
19
  let connection; let onMessage = () => {}; let onClose = () => {};
10
20
  return {
11
21
  onMessage: (listener) => { onMessage = listener; },
@@ -23,4 +33,4 @@ const createNativeTcpTransportFactory = ({ nativeModule }) => {
23
33
 
24
34
  const createChitChatNativeClient = ({ endpoint, tokenProvider, nativeModule, ...options }) => new ReliableRealtimeClient({ endpoint, tokenProvider, runtime: 'native', nativeTransportFactory: createNativeTcpTransportFactory({ nativeModule }), ...options });
25
35
 
26
- module.exports = { createChitChatNativeClient, createNativeTcpTransportFactory };
36
+ module.exports = { createChitChatNativeClient, createNativeTcpTransportFactory, validateNativeTlsEndpoint };