@chitchat/sdk-react-native 0.1.0-dev.2 → 0.2.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
@@ -4,6 +4,10 @@
4
4
 
5
5
  This package is currently a **development prerelease**. Pin the version you have tested before shipping an application.
6
6
 
7
+ ## SDK foundation in v0.2
8
+
9
+ The native SDK validates both the TLS endpoint and the linked bridge result before sending frames. The bridge must expose every method in the documented connection contract; partial bridges fail fast instead of silently degrading to an unsafe transport.
10
+
7
11
  ## Read this before integrating
8
12
 
9
13
  This JavaScript package needs a linked native bridge. You pass that bridge as `nativeModule`; the SDK does not secretly create TCP sockets in JavaScript.
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { ReliableRealtimeClient, ReliableRealtimeClientOptions, RealtimeFrame } from '@chitchat/sdk-core';
2
+ export interface ChitChatNativeConnection { onFrame(listener: (frame: RealtimeFrame) => void): void; onClose(listener: (reason?: unknown) => void): void; send(frame: RealtimeFrame): Promise<void> | void; close(): Promise<void> | void; }
3
+ export interface ChitChatNativeModule { connect(input: { endpoint: string; token: string; protocol: 'chitchat.protobuf.v1'; tls: true }): Promise<ChitChatNativeConnection>; }
4
+ export function validateNativeTlsEndpoint(endpoint: string): string;
5
+ export function createNativeTcpTransportFactory(options: { nativeModule: ChitChatNativeModule }): ReliableRealtimeClientOptions['nativeTransportFactory'];
6
+ export function createChitChatNativeClient(options: Omit<ReliableRealtimeClientOptions, 'runtime' | 'nativeTransportFactory'> & { nativeModule: ChitChatNativeModule }): ReliableRealtimeClient;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@chitchat/sdk-react-native",
3
- "version": "0.1.0-dev.2",
3
+ "version": "0.2.0-dev.1",
4
4
  "main": "src/index.js",
5
- "exports": "./src/index.js",
6
- "files": ["src", "README.md", "LICENSE"],
5
+ "exports": { ".": { "types": "./index.d.ts", "require": "./src/index.js", "import": "./src/index.js" } },
6
+ "types": "index.d.ts",
7
+ "files": ["src", "index.d.ts", "README.md", "LICENSE"],
7
8
  "engines": { "node": ">=18" },
8
9
  "scripts": { "test": "node test/transport.test.js" },
9
- "dependencies": { "@chitchat/sdk-core": "0.1.0-dev.2" },
10
+ "dependencies": { "@chitchat/sdk-core": "0.2.0-dev.1" },
10
11
  "license": "UNLICENSED",
11
12
  "publishConfig": { "access": "public", "tag": "development" }
12
13
  }
package/src/index.js CHANGED
@@ -12,6 +12,11 @@ const validateNativeTlsEndpoint = (endpoint) => {
12
12
  return endpoint;
13
13
  };
14
14
 
15
+ const assertConnection = (connection) => {
16
+ if (!connection || ['onFrame', 'onClose', 'send', 'close'].some((name) => typeof connection[name] !== 'function')) throw new Error('Native TCP module returned an invalid connection');
17
+ return connection;
18
+ };
19
+
15
20
  const createNativeTcpTransportFactory = ({ nativeModule }) => {
16
21
  if (!nativeModule || typeof nativeModule.connect !== 'function') throw new Error('The official ChitChat native TCP module is required');
17
22
  return async ({ endpoint, token, protocol }) => {
@@ -21,12 +26,12 @@ const createNativeTcpTransportFactory = ({ nativeModule }) => {
21
26
  onMessage: (listener) => { onMessage = listener; },
22
27
  onClose: (listener) => { onClose = listener; },
23
28
  open: async () => {
24
- connection = await nativeModule.connect({ endpoint, token, protocol, tls: true });
29
+ connection = assertConnection(await nativeModule.connect({ endpoint, token, protocol, tls: true }));
25
30
  connection.onFrame((frame) => onMessage(frame));
26
31
  connection.onClose((reason) => onClose(reason));
27
32
  },
28
- send: (frame) => connection.send(frame),
29
- close: () => connection ? connection.close() : Promise.resolve()
33
+ send: (frame) => connection ? Promise.resolve(connection.send(frame)) : Promise.reject(new Error('Native TCP transport is not open')),
34
+ close: () => connection ? Promise.resolve(connection.close()) : Promise.resolve()
30
35
  };
31
36
  };
32
37
  };