@myrialabs/clopen 0.3.19 → 0.3.21

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.
Files changed (40) hide show
  1. package/backend/database/migrations/039_create_file_audit_log.ts +45 -0
  2. package/backend/database/migrations/index.ts +7 -0
  3. package/backend/database/queries/file-audit-log-queries.test.ts +377 -0
  4. package/backend/database/queries/file-audit-log-queries.ts +184 -0
  5. package/backend/database/queries/index.ts +2 -1
  6. package/backend/db-client/drivers/mysql.ts +28 -10
  7. package/backend/db-client/drivers/postgres.ts +34 -18
  8. package/backend/engine/adapters/claude/models.ts +43 -0
  9. package/backend/engine/install-recipes.ts +53 -140
  10. package/backend/engine/version-check.ts +145 -0
  11. package/backend/git/git-parser.ts +11 -0
  12. package/backend/git/git-service.ts +52 -7
  13. package/backend/http/files-upload.ts +84 -3
  14. package/backend/index.ts +27 -12
  15. package/backend/tunnel/tunnel-config.ts +76 -209
  16. package/backend/utils/client-ip.test.ts +55 -0
  17. package/backend/utils/client-ip.ts +42 -0
  18. package/backend/utils/ws.ts +6 -3
  19. package/backend/ws/auth/login.test.ts +271 -0
  20. package/backend/ws/auth/login.ts +36 -3
  21. package/backend/ws/auth/users.ts +3 -2
  22. package/backend/ws/chat/stream.ts +17 -6
  23. package/backend/ws/files/path-access.test.ts +60 -1
  24. package/backend/ws/files/path-access.ts +21 -0
  25. package/backend/ws/system-tools/install.ts +0 -1
  26. package/backend/ws/system-tools/status.ts +17 -4
  27. package/backend/ws/tunnel/config.ts +17 -25
  28. package/backend/ws/tunnel/operations.ts +63 -68
  29. package/dist/assets/main-BgOiIS43.js +360 -0
  30. package/dist/assets/{main-ClADBkFf.css → main-CJdJeen6.css} +1 -1
  31. package/dist/index.html +2 -2
  32. package/package.json +4 -1
  33. package/shared/types/git.ts +8 -0
  34. package/shared/utils/ws-client.ts +188 -38
  35. package/backend/tunnel/cloudflared/binary.ts +0 -171
  36. package/backend/tunnel/cloudflared/index.ts +0 -24
  37. package/backend/tunnel/cloudflared/tunnel.ts +0 -444
  38. package/backend/tunnel/global-tunnel-manager.ts +0 -687
  39. package/backend/tunnel/project-tunnel-manager.ts +0 -264
  40. package/dist/assets/main-BOUXyIaW.js +0 -362
@@ -5,34 +5,27 @@
5
5
  * - Quick tunnel: start/stop with random URL
6
6
  * - Remote tunnel: start/stop dashboard-managed tunnels
7
7
  * - Local tunnel: auth, create, delete, ingress, route-dns, start/stop
8
+ *
9
+ * Each handler that needs cloudflared calls `tunnelKit.bin.ensure()` first
10
+ * (it resolves from the managed dir or PATH, downloading on first use); the
11
+ * remaining calls are direct passthroughs to `tunnelKit.*` and the singleton
12
+ * `tunnelStore` for persistence.
8
13
  */
9
14
 
10
15
  import { t } from 'elysia';
11
16
  import { createRouter } from '$shared/utils/ws-server';
12
- import { globalTunnelManager } from '../../tunnel/global-tunnel-manager';
13
- import {
14
- getRemoteTunnelConfigById,
15
- getLocalTunnelConfigById,
16
- addLocalTunnelConfig,
17
- removeLocalTunnelConfig,
18
- addLocalTunnelIngress,
19
- removeLocalTunnelIngress,
20
- getAuthorizedZone,
21
- setAuthorizedZone,
22
- clearAuthorizedZone
23
- } from '../../tunnel/tunnel-config';
17
+ import { tunnelKit, tunnelStore, namedIngress, mapActiveTunnel } from '../../tunnel/tunnel-config';
24
18
  import { debug } from '$shared/utils/logger';
25
19
  import { ws } from '$backend/utils/ws';
26
20
 
27
21
  // Wire up ingress update callback to push via WS
28
- globalTunnelManager.setRemoteIngressUpdateCallback((configId, ingress) => {
29
- ws.emit.global('tunnel:remote:ingress-update', { configId, ingress });
22
+ tunnelKit.on('ingress-update', ({ id, ingress }) => {
23
+ ws.emit.global('tunnel:remote:ingress-update', { id, ingress });
30
24
  });
31
25
 
32
26
  // Wire up status changed callback to push tunnel list via WS
33
- globalTunnelManager.setStatusChangedCallback(() => {
34
- const tunnels = globalTunnelManager.getActiveTunnels();
35
- ws.emit.global('tunnel:status-changed', { tunnels });
27
+ tunnelKit.on('status-changed', () => {
28
+ ws.emit.global('tunnel:status-changed', { tunnels: tunnelKit.list().map(mapActiveTunnel) });
36
29
  });
37
30
 
38
31
  export const operationsHandler = createRouter()
@@ -51,8 +44,9 @@ export const operationsHandler = createRouter()
51
44
  const { port, autoStopMinutes = 60 } = data;
52
45
  debug.log('tunnel', `[WS] Quick tunnel start: port=${port}, autoStop=${autoStopMinutes}`);
53
46
 
54
- const result = await globalTunnelManager.startQuickTunnel(port, autoStopMinutes);
55
- return result;
47
+ await tunnelKit.bin.ensure();
48
+ const { publicUrl, timings } = await tunnelKit.quick.start({ service: port, autoStopMinutes });
49
+ return { publicUrl, timings };
56
50
  })
57
51
 
58
52
  .http('tunnel:quick:stop', {
@@ -61,7 +55,7 @@ export const operationsHandler = createRouter()
61
55
  }),
62
56
  response: t.Object({ stopped: t.Boolean() })
63
57
  }, async ({ data }) => {
64
- await globalTunnelManager.stopQuickTunnel(data.port);
58
+ await tunnelKit.quick.stop(data.port);
65
59
  return { stopped: true };
66
60
  })
67
61
 
@@ -71,31 +65,34 @@ export const operationsHandler = createRouter()
71
65
 
72
66
  .http('tunnel:remote:start', {
73
67
  data: t.Object({
74
- configId: t.String({ minLength: 1 })
68
+ id: t.String({ minLength: 1 })
75
69
  }),
76
70
  response: t.Any()
77
71
  }, async ({ data }) => {
78
- const config = getRemoteTunnelConfigById(data.configId);
72
+ const config = tunnelStore.getRemote(data.id);
79
73
  if (!config) throw new Error('Remote tunnel config not found');
80
74
 
81
- debug.log('tunnel', `[WS] Remote tunnel start: ${config.label}`);
82
- const result = await globalTunnelManager.startRemoteTunnel(config);
83
- return result;
75
+ debug.log('tunnel', `[WS] Remote tunnel start: ${config.name}`);
76
+ await tunnelKit.bin.ensure();
77
+ const { timings } = await tunnelKit.remote.start(
78
+ { id: config.id, token: config.token, name: config.name }
79
+ );
80
+ return { timings };
84
81
  })
85
82
 
86
83
  .http('tunnel:remote:stop', {
87
84
  data: t.Object({
88
- configId: t.String({ minLength: 1 })
85
+ id: t.String({ minLength: 1 })
89
86
  }),
90
87
  response: t.Object({ stopped: t.Boolean() })
91
88
  }, async ({ data }) => {
92
- await globalTunnelManager.stopRemoteTunnel(data.configId);
89
+ await tunnelKit.stop(data.id);
93
90
  return { stopped: true };
94
91
  })
95
92
 
96
93
  .http('tunnel:remote:ingress', {
97
94
  data: t.Object({
98
- configId: t.String({ minLength: 1 })
95
+ id: t.String({ minLength: 1 })
99
96
  }),
100
97
  response: t.Object({
101
98
  ingress: t.Array(t.Object({
@@ -104,8 +101,7 @@ export const operationsHandler = createRouter()
104
101
  }))
105
102
  })
106
103
  }, async ({ data }) => {
107
- const ingress = globalTunnelManager.getRemoteTunnelIngress(data.configId);
108
- return { ingress };
104
+ return { ingress: tunnelKit.remote.ingress(data.id) };
109
105
  })
110
106
 
111
107
  // ═══════════════════════════════════════
@@ -120,17 +116,15 @@ export const operationsHandler = createRouter()
120
116
  zone: t.Nullable(t.String())
121
117
  })
122
118
  }, async () => {
123
- const auth = globalTunnelManager.checkCloudflaredAuth();
124
- const zone = getAuthorizedZone();
125
- return { ...auth, zone };
119
+ return { ...tunnelKit.local.checkAuth(), zone: tunnelStore.getZone() };
126
120
  })
127
121
 
128
122
  .http('tunnel:local:logout', {
129
123
  data: t.Object({}),
130
124
  response: t.Object({ success: t.Boolean() })
131
125
  }, async () => {
132
- globalTunnelManager.logoutCloudflared();
133
- clearAuthorizedZone();
126
+ tunnelKit.local.logout();
127
+ tunnelStore.clearZone();
134
128
  return { success: true };
135
129
  })
136
130
 
@@ -140,7 +134,7 @@ export const operationsHandler = createRouter()
140
134
  }),
141
135
  response: t.Object({ success: t.Boolean(), zone: t.String() })
142
136
  }, async ({ data }) => {
143
- setAuthorizedZone(data.zone);
137
+ tunnelStore.setZone(data.zone);
144
138
  return { success: true, zone: data.zone };
145
139
  })
146
140
 
@@ -150,23 +144,24 @@ export const operationsHandler = createRouter()
150
144
  }, async ({ conn }) => {
151
145
  const userId = ws.getUserId(conn);
152
146
 
153
- await globalTunnelManager.loginCloudflared(
154
- (url) => {
147
+ await tunnelKit.bin.ensure();
148
+ tunnelKit.local.login({
149
+ onUrl: (url) => {
155
150
  ws.emit.user(userId, 'tunnel:local:login-url', { url });
156
151
  },
157
- () => {
152
+ onComplete: () => {
158
153
  ws.emit.user(userId, 'tunnel:local:login-complete', {});
159
154
  },
160
- (error) => {
161
- ws.emit.user(userId, 'tunnel:local:login-error', { message: error });
155
+ onError: (message) => {
156
+ ws.emit.user(userId, 'tunnel:local:login-error', { message });
162
157
  }
163
- );
158
+ });
164
159
  })
165
160
 
166
161
  .on('tunnel:local:login-cancel', {
167
162
  data: t.Object({})
168
163
  }, async () => {
169
- globalTunnelManager.cancelLogin();
164
+ tunnelKit.local.cancelLogin();
170
165
  })
171
166
 
172
167
  .http('tunnel:local:create', {
@@ -181,8 +176,9 @@ export const operationsHandler = createRouter()
181
176
  }, async ({ data }) => {
182
177
  debug.log('tunnel', `[WS] Creating local tunnel: ${data.name}`);
183
178
 
184
- const result = await globalTunnelManager.createLocalTunnel(data.name);
185
- const config = addLocalTunnelConfig(data.name, result.tunnelId, result.credentialsFile);
179
+ await tunnelKit.bin.ensure();
180
+ const result = await tunnelKit.local.create(data.name);
181
+ const config = tunnelStore.addLocal(data.name, result.tunnelId, result.credentialsFile);
186
182
 
187
183
  return { id: config.id, name: config.name, tunnelId: config.tunnelId };
188
184
  })
@@ -193,24 +189,22 @@ export const operationsHandler = createRouter()
193
189
  }),
194
190
  response: t.Object({ success: t.Boolean() })
195
191
  }, async ({ data }) => {
196
- const config = getLocalTunnelConfigById(data.id);
192
+ const config = tunnelStore.getLocal(data.id);
197
193
  if (!config) throw new Error('Local tunnel config not found');
198
194
 
199
- // Stop if running
200
- if (globalTunnelManager.isLocalTunnelActive(data.id)) {
201
- await globalTunnelManager.stopLocalTunnel(data.id);
202
- }
195
+ // Stop if running (tunnelKit.stop is a no-op for unknown ids).
196
+ await tunnelKit.stop(data.id);
203
197
 
204
198
  // Delete from Cloudflare
205
199
  try {
206
- await globalTunnelManager.deleteLocalTunnel(config.tunnelId, config.credentialsFile);
200
+ await tunnelKit.bin.ensure();
201
+ await tunnelKit.local.delete(config.tunnelId, config.credentialsFile);
207
202
  } catch (error) {
208
203
  debug.warn('tunnel', `Could not delete tunnel from Cloudflare (may already be deleted):`, error);
209
204
  }
210
205
 
211
- // Remove from config and cleanup files
212
- removeLocalTunnelConfig(data.id);
213
- globalTunnelManager.cleanupLocalTunnelFiles(config.tunnelId);
206
+ tunnelStore.removeLocal(data.id);
207
+ tunnelKit.local.cleanupFiles(config.tunnelId);
214
208
  return { success: true };
215
209
  })
216
210
 
@@ -230,18 +224,18 @@ export const operationsHandler = createRouter()
230
224
  dnsError: t.Nullable(t.String())
231
225
  })
232
226
  }, async ({ data }) => {
233
- const tunnelConfig = getLocalTunnelConfigById(data.id);
227
+ const tunnelConfig = tunnelStore.getLocal(data.id);
234
228
  if (!tunnelConfig) throw new Error('Local tunnel config not found');
235
229
 
236
- // Add ingress rule
237
- const config = addLocalTunnelIngress(data.id, data.hostname, data.service);
230
+ const config = tunnelStore.addLocalIngress(data.id, data.hostname, data.service);
238
231
  if (!config) throw new Error('Failed to add ingress rule');
239
232
 
240
233
  // Auto route DNS using tunnel UUID (more reliable than name)
241
234
  let dnsRouted = false;
242
235
  let dnsError: string | null = null;
243
236
  try {
244
- await globalTunnelManager.routeDns(tunnelConfig.tunnelId, data.hostname);
237
+ await tunnelKit.bin.ensure();
238
+ await tunnelKit.local.routeDns(tunnelConfig.tunnelId, data.hostname);
245
239
  dnsRouted = true;
246
240
  debug.log('tunnel', `DNS routed for ${data.hostname} -> tunnel ${tunnelConfig.tunnelId}`);
247
241
  } catch (error) {
@@ -249,7 +243,7 @@ export const operationsHandler = createRouter()
249
243
  debug.warn('tunnel', `Auto route-dns for ${data.hostname} failed:`, dnsError);
250
244
  }
251
245
 
252
- return { success: true, ingress: config.ingress, dnsRouted, dnsError };
246
+ return { success: true, ingress: namedIngress(config.ingress), dnsRouted, dnsError };
253
247
  })
254
248
 
255
249
  .http('tunnel:local:ingress:remove', {
@@ -265,13 +259,13 @@ export const operationsHandler = createRouter()
265
259
  }))
266
260
  })
267
261
  }, async ({ data }) => {
268
- const config = removeLocalTunnelIngress(data.id, data.hostname);
262
+ const config = tunnelStore.removeLocalIngress(data.id, data.hostname);
269
263
  if (!config) throw new Error('Local tunnel config not found');
270
264
 
271
265
  // Regenerate config.yml to stay in sync
272
- globalTunnelManager.writeLocalTunnelConfig(config);
266
+ tunnelKit.local.writeConfig(config);
273
267
 
274
- return { success: true, ingress: config.ingress };
268
+ return { success: true, ingress: namedIngress(config.ingress) };
275
269
  })
276
270
 
277
271
  .http('tunnel:local:start', {
@@ -280,12 +274,13 @@ export const operationsHandler = createRouter()
280
274
  }),
281
275
  response: t.Any()
282
276
  }, async ({ data }) => {
283
- const config = getLocalTunnelConfigById(data.id);
277
+ const config = tunnelStore.getLocal(data.id);
284
278
  if (!config) throw new Error('Local tunnel config not found');
285
279
 
286
280
  debug.log('tunnel', `[WS] Starting local tunnel: ${config.name}`);
287
- const result = await globalTunnelManager.startLocalTunnel(config);
288
- return result;
281
+ await tunnelKit.bin.ensure();
282
+ const { timings } = await tunnelKit.local.start(config);
283
+ return { timings };
289
284
  })
290
285
 
291
286
  .http('tunnel:local:stop', {
@@ -294,7 +289,7 @@ export const operationsHandler = createRouter()
294
289
  }),
295
290
  response: t.Object({ stopped: t.Boolean() })
296
291
  }, async ({ data }) => {
297
- await globalTunnelManager.stopLocalTunnel(data.id);
292
+ await tunnelKit.stop(data.id);
298
293
  return { stopped: true };
299
294
  })
300
295
 
@@ -308,7 +303,7 @@ export const operationsHandler = createRouter()
308
303
  tunnels: t.Array(t.Any())
309
304
  })
310
305
  }, async () => {
311
- return { tunnels: globalTunnelManager.getActiveTunnels() };
306
+ return { tunnels: tunnelKit.list().map(mapActiveTunnel) };
312
307
  })
313
308
 
314
309
  // ═══════════════════════════════════════
@@ -320,7 +315,7 @@ export const operationsHandler = createRouter()
320
315
  }))
321
316
 
322
317
  .emit('tunnel:remote:ingress-update', t.Object({
323
- configId: t.String(),
318
+ id: t.String(),
324
319
  ingress: t.Array(t.Object({
325
320
  hostname: t.Optional(t.String()),
326
321
  service: t.String()