checkpoint-cli 0.3.9 → 0.4.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/dist/index.js +31 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -282,6 +282,35 @@ async function registerTunnel(sb, opts) {
|
|
|
282
282
|
return null;
|
|
283
283
|
}
|
|
284
284
|
const APP_URL = (0, config_js_1.getAppUrl)();
|
|
285
|
+
const userId = userData.user.id;
|
|
286
|
+
// Try to find an existing tunnel with the same name for this user
|
|
287
|
+
const { data: existing } = await sb
|
|
288
|
+
.from('tunnels')
|
|
289
|
+
.select('id, share_id')
|
|
290
|
+
.eq('user_id', userId)
|
|
291
|
+
.eq('name', opts.name)
|
|
292
|
+
.order('created_at', { ascending: false })
|
|
293
|
+
.limit(1)
|
|
294
|
+
.single();
|
|
295
|
+
if (existing) {
|
|
296
|
+
// Reconnect: reuse the same share_id, update the tunnel URL
|
|
297
|
+
const { error } = await sb
|
|
298
|
+
.from('tunnels')
|
|
299
|
+
.update({
|
|
300
|
+
tunnel_url: opts.tunnelUrl,
|
|
301
|
+
local_port: opts.port,
|
|
302
|
+
status: 'active',
|
|
303
|
+
last_seen_at: new Date().toISOString(),
|
|
304
|
+
})
|
|
305
|
+
.eq('id', existing.id);
|
|
306
|
+
if (error) {
|
|
307
|
+
console.log(chalk_1.default.yellow(` ⚠ Could not reconnect: ${error.message}`));
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
console.log(chalk_1.default.green(' ✓ Reconnected to existing tunnel') + chalk_1.default.gray(` (${opts.name})`));
|
|
311
|
+
return { shareUrl: `${APP_URL}/share/${existing.share_id}`, tunnelId: existing.id };
|
|
312
|
+
}
|
|
313
|
+
// No existing tunnel — create a new one
|
|
285
314
|
const shareId = generateShareId();
|
|
286
315
|
const { data, error } = await sb.from('tunnels').insert({
|
|
287
316
|
name: opts.name,
|
|
@@ -289,7 +318,7 @@ async function registerTunnel(sb, opts) {
|
|
|
289
318
|
tunnel_url: opts.tunnelUrl,
|
|
290
319
|
share_id: shareId,
|
|
291
320
|
status: 'active',
|
|
292
|
-
user_id:
|
|
321
|
+
user_id: userId,
|
|
293
322
|
last_seen_at: new Date().toISOString(),
|
|
294
323
|
}).select('id').single();
|
|
295
324
|
if (error || !data) {
|
|
@@ -418,7 +447,7 @@ const program = new commander_1.Command();
|
|
|
418
447
|
program
|
|
419
448
|
.name('checkpoint')
|
|
420
449
|
.description('Share your localhost with reviewers — get visual feedback directly on the page')
|
|
421
|
-
.version('0.
|
|
450
|
+
.version('0.4.0');
|
|
422
451
|
// ── checkpoint login ──
|
|
423
452
|
program
|
|
424
453
|
.command('login')
|