@tiflis-io/tiflis-code-tunnel 0.3.0

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/LICENSE ADDED
@@ -0,0 +1,100 @@
1
+ # Functional Source License, Version 1.1 (No Future Conversion)
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-NC
6
+
7
+ ## Notice
8
+
9
+ Copyright 2025 Roman Barinov <rbarinov@gmail.com>
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A "Competing
33
+ Use" means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Commercial Licensing
88
+
89
+ For commercial use that constitutes a Competing Use, you must obtain a separate
90
+ commercial license from the Licensor.
91
+
92
+ Contact: rbarinov@gmail.com
93
+
94
+ ## License Details
95
+
96
+ | Field | Value |
97
+ |-------|-------|
98
+ | Licensor | Roman Barinov |
99
+ | Software | Tiflis Code |
100
+ | Use Grant | Any Permitted Purpose |
package/README.md ADDED
@@ -0,0 +1,285 @@
1
+ # @tiflis/tiflis-code-tunnel
2
+
3
+ <p align="center">
4
+ <img src="../../assets/branding/logo.svg" width="80" height="80" alt="Tiflis Code">
5
+ </p>
6
+
7
+ <p align="center">
8
+ <strong>WebSocket reverse proxy for Tiflis Code workstation connections</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="#installation">Installation</a> •
13
+ <a href="#quick-start">Quick Start</a> •
14
+ <a href="#configuration">Configuration</a> •
15
+ <a href="#docker">Docker</a> •
16
+ <a href="#reverse-proxy">Reverse Proxy</a>
17
+ </p>
18
+
19
+ ---
20
+
21
+ ## Overview
22
+
23
+ The Tunnel Server acts as a secure reverse proxy between mobile clients (iOS/watchOS) and workstations running the Tiflis Code workstation server. It enables remote access to your workstation without requiring a public IP address.
24
+
25
+ ```
26
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────────┐
27
+ │ Mobile │◄───────►│ Tunnel │◄───────►│ Workstation │
28
+ │ (iOS/Watch)│ WSS │ Server │ WS │ Server │
29
+ └─────────────┘ └─────────────┘ └─────────────────┘
30
+ ```
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ # Using npm
36
+ npm install @tiflis-io/tiflis-code-tunnel
37
+
38
+ # Using pnpm
39
+ pnpm add @tiflis-io/tiflis-code-tunnel
40
+ ```
41
+
42
+ ## Quick Start
43
+
44
+ <p align="center">
45
+ <img src="../../assets/screenshots/tunnel/startup.png" alt="Tunnel Server Startup" width="700">
46
+ </p>
47
+
48
+ ### 1. Set Environment Variables
49
+
50
+ ```bash
51
+ # Required: API key for workstation registration (min 32 chars)
52
+ export TUNNEL_REGISTRATION_API_KEY="your-secure-api-key-at-least-32-characters"
53
+
54
+ # Optional
55
+ export PORT=3001
56
+ export LOG_LEVEL=info
57
+ ```
58
+
59
+ ### 2. Run the Server
60
+
61
+ ```bash
62
+ # Create a working directory with config (avoid leading dot in name)
63
+ mkdir -p ~/tiflis-tunnel && cd ~/tiflis-tunnel
64
+ npm init -y
65
+ npm install @tiflis-io/tiflis-code-tunnel
66
+
67
+ # Create .env file with your configuration
68
+ echo 'TUNNEL_REGISTRATION_API_KEY=your-secure-api-key-at-least-32-characters' > .env
69
+
70
+ # Run with dotenv-cli
71
+ npx dotenv-cli -e .env -- node node_modules/@tiflis-io/tiflis-code-tunnel/dist/main.js
72
+
73
+ # Or set environment variables directly
74
+ TUNNEL_REGISTRATION_API_KEY=your-secure-api-key-at-least-32-characters \
75
+ node node_modules/@tiflis-io/tiflis-code-tunnel/dist/main.js
76
+
77
+ # Development mode (from monorepo)
78
+ pnpm dev
79
+ ```
80
+
81
+ ### 3. Verify It's Running
82
+
83
+ ```bash
84
+ curl http://localhost:3001/health
85
+ ```
86
+
87
+ ## Configuration
88
+
89
+ All configuration is done via environment variables:
90
+
91
+ | Variable | Required | Default | Description |
92
+ | ----------------------------- | -------- | --------- | ------------------------------------------------------- |
93
+ | `TUNNEL_REGISTRATION_API_KEY` | ✅ | — | API key for workstation registration (min 32 chars) |
94
+ | `PORT` | ❌ | `3001` | HTTP/WebSocket port |
95
+ | `HOST` | ❌ | `0.0.0.0` | Host to bind to |
96
+ | `LOG_LEVEL` | ❌ | `info` | Log level: `trace`, `debug`, `info`, `warn`, `error` |
97
+ | `TRUST_PROXY` | ❌ | `false` | Set to `true` when behind a reverse proxy |
98
+ | `PUBLIC_BASE_URL` | ❌ | auto | Public WebSocket URL (e.g., `wss://tunnel.example.com`) |
99
+ | `WS_PATH` | ❌ | `/ws` | WebSocket endpoint path |
100
+
101
+ ### Example `.env` File
102
+
103
+ ```bash
104
+ NODE_ENV=production
105
+ PORT=3001
106
+ LOG_LEVEL=info
107
+ TUNNEL_REGISTRATION_API_KEY=your-secure-api-key-at-least-32-characters
108
+
109
+ # For reverse proxy setups
110
+ TRUST_PROXY=true
111
+ PUBLIC_BASE_URL=wss://tunnel.example.com
112
+ ```
113
+
114
+ ## Docker
115
+
116
+ ### Quick Start with Docker
117
+
118
+ ```bash
119
+ docker run -d \
120
+ --name tiflis-tunnel \
121
+ -p 3001:3001 \
122
+ -e TUNNEL_REGISTRATION_API_KEY="your-api-key-here-32-chars-min!!" \
123
+ ghcr.io/tiflis-io/tiflis-code-tunnel:latest
124
+ ```
125
+
126
+ ### Docker Compose
127
+
128
+ ```yaml
129
+ services:
130
+ tunnel:
131
+ image: ghcr.io/tiflis-io/tiflis-code-tunnel:latest
132
+ ports:
133
+ - "3001:3001"
134
+ environment:
135
+ NODE_ENV: production
136
+ LOG_LEVEL: info
137
+ TUNNEL_REGISTRATION_API_KEY: ${TUNNEL_REGISTRATION_API_KEY}
138
+ restart: unless-stopped
139
+ ```
140
+
141
+ ### Multi-Architecture Support
142
+
143
+ The Docker image supports both architectures:
144
+
145
+ - `linux/amd64` (x86_64)
146
+ - `linux/arm64` (Apple Silicon, AWS Graviton, Raspberry Pi)
147
+
148
+ ## Reverse Proxy
149
+
150
+ When deploying behind a reverse proxy with TLS termination:
151
+
152
+ ### Configuration
153
+
154
+ ```bash
155
+ TRUST_PROXY=true
156
+ PUBLIC_BASE_URL=wss://tunnel.example.com
157
+ ```
158
+
159
+ ### Nginx Example
160
+
161
+ ```nginx
162
+ upstream tiflis_tunnel {
163
+ server 127.0.0.1:3001;
164
+ }
165
+
166
+ server {
167
+ listen 443 ssl http2;
168
+ server_name tunnel.example.com;
169
+
170
+ ssl_certificate /path/to/cert.pem;
171
+ ssl_certificate_key /path/to/key.pem;
172
+
173
+ location /ws {
174
+ proxy_pass http://tiflis_tunnel;
175
+ proxy_http_version 1.1;
176
+ proxy_set_header Upgrade $http_upgrade;
177
+ proxy_set_header Connection "upgrade";
178
+ proxy_set_header Host $host;
179
+ proxy_set_header X-Real-IP $remote_addr;
180
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
181
+ proxy_set_header X-Forwarded-Proto $scheme;
182
+ proxy_read_timeout 86400s;
183
+ }
184
+
185
+ location /health {
186
+ proxy_pass http://tiflis_tunnel;
187
+ }
188
+ }
189
+ ```
190
+
191
+ ### Traefik with Docker Compose
192
+
193
+ See `deploy/docker-compose.traefik.yml` for a complete example with automatic Let's Encrypt certificates.
194
+
195
+ ## API Endpoints
196
+
197
+ | Endpoint | Method | Description |
198
+ | ---------- | --------- | ------------------------------------------- |
199
+ | `/health` | GET | Detailed health check with connection stats |
200
+ | `/healthz` | GET | Simple liveness probe |
201
+ | `/readyz` | GET | Readiness probe |
202
+ | `/ws` | WebSocket | Main WebSocket endpoint |
203
+
204
+ ### Health Check Response
205
+
206
+ ```json
207
+ {
208
+ "status": "healthy",
209
+ "version": "0.1.0",
210
+ "uptime": 3600,
211
+ "connections": {
212
+ "workstations": 2,
213
+ "clients": 5
214
+ },
215
+ "timestamp": "2025-01-15T12:00:00.000Z"
216
+ }
217
+ ```
218
+
219
+ ## Protocol
220
+
221
+ The tunnel server implements the Tiflis Code WebSocket Protocol. See [PROTOCOL.md](../../PROTOCOL.md) for the full specification.
222
+
223
+ ### Key Message Types
224
+
225
+ **Workstation Registration:**
226
+
227
+ ```json
228
+ {
229
+ "type": "workstation.register",
230
+ "payload": {
231
+ "api_key": "your-api-key",
232
+ "name": "My MacBook Pro",
233
+ "auth_key": "client-auth-key",
234
+ "reconnect": true,
235
+ "previous_tunnel_id": "Z6q62aKz-F96"
236
+ }
237
+ }
238
+ ```
239
+
240
+ **Tunnel ID Persistence:**
241
+
242
+ The tunnel server supports persistent `tunnel_id` values that survive tunnel server restarts:
243
+
244
+ - **First registration**: Tunnel server generates a new `tunnel_id`
245
+ - **Reconnection (same tunnel server)**: Workstation provides `previous_tunnel_id`, tunnel server restores it
246
+ - **Reconnection (after tunnel restart)**: Workstation provides `previous_tunnel_id`, tunnel server allows reclaiming it if available
247
+
248
+ This ensures workstations maintain stable identifiers even when the tunnel server is restarted.
249
+
250
+ **Mobile Client Connection:**
251
+
252
+ ```json
253
+ {
254
+ "type": "connect",
255
+ "payload": {
256
+ "tunnel_id": "abc123",
257
+ "auth_key": "client-auth-key",
258
+ "device_id": "device-uuid"
259
+ }
260
+ }
261
+ ```
262
+
263
+ ## Development
264
+
265
+ ```bash
266
+ # Clone the repository
267
+ git clone https://github.com/tiflis-io/tiflis-code.git
268
+ cd tiflis-code/packages/tunnel
269
+
270
+ # Install dependencies
271
+ pnpm install
272
+
273
+ # Run in development mode
274
+ TUNNEL_REGISTRATION_API_KEY="dev-key-32-characters-minimum!!" pnpm dev
275
+
276
+ # Run tests
277
+ pnpm test
278
+
279
+ # Build for production
280
+ pnpm build
281
+ ```
282
+
283
+ ## License
284
+
285
+ FSL-1.1-NC © [Roman Barinov](mailto:rbarinov@gmail.com)
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }