checkpoint-cli 0.5.2 → 1.0.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.
Files changed (2) hide show
  1. package/dist/index.js +48 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -29,6 +29,40 @@ function getSupabase() {
29
29
  },
30
30
  });
31
31
  }
32
+ async function ensureAuthenticatedClient() {
33
+ let sb = await getAuthenticatedClient();
34
+ if (sb)
35
+ return sb;
36
+ console.log(chalk_1.default.yellow(' No active login found. Starting browser sign-in...'));
37
+ console.log('');
38
+ try {
39
+ const tokens = await loginWithBrowser();
40
+ (0, config_js_1.saveConfig)({
41
+ access_token: tokens.access_token,
42
+ refresh_token: tokens.refresh_token,
43
+ app_url: (0, config_js_1.getAppUrl)(),
44
+ });
45
+ sb = await getAuthenticatedClient();
46
+ if (sb) {
47
+ const { data } = await sb.auth.getUser();
48
+ if (data.user?.email) {
49
+ console.log(chalk_1.default.green(` ✓ Logged in as ${chalk_1.default.white(data.user.email)}`));
50
+ }
51
+ else {
52
+ console.log(chalk_1.default.green(' ✓ Logged in'));
53
+ }
54
+ console.log('');
55
+ return sb;
56
+ }
57
+ }
58
+ catch (err) {
59
+ console.log(chalk_1.default.red(` ${err.message}`));
60
+ }
61
+ console.log(chalk_1.default.red(' Could not establish an authenticated session.'));
62
+ console.log(` Run ${chalk_1.default.cyan('checkpoint login')} and try again.`);
63
+ console.log('');
64
+ return null;
65
+ }
32
66
  /** Get an authenticated Supabase client, refreshing the token if needed. */
33
67
  async function getAuthenticatedClient() {
34
68
  const config = (0, config_js_1.loadConfig)();
@@ -68,17 +102,6 @@ async function getAuthenticatedClient() {
68
102
  }
69
103
  return sb;
70
104
  }
71
- function requireAuth() {
72
- const config = (0, config_js_1.loadConfig)();
73
- if (!config) {
74
- console.log('');
75
- console.log(chalk_1.default.red(' Not logged in.'));
76
- console.log('');
77
- console.log(` Run ${chalk_1.default.cyan('checkpoint login')} first.`);
78
- console.log('');
79
- process.exit(1);
80
- }
81
- }
82
105
  /* ── Injection Proxy ── */
83
106
  function startInjectionProxy(targetPort) {
84
107
  const scriptBody = (0, tracking_script_minimal_js_1.buildMinimalTrackingScript)().replace(/<\/script/gi, '<\\/script');
@@ -372,6 +395,12 @@ async function registerTunnel(sb, opts) {
372
395
  console.log(chalk_1.default.yellow(` ⚠ Could not register: ${error?.message ?? 'unknown'}`));
373
396
  return null;
374
397
  }
398
+ await sb.from('tunnel_members').insert({
399
+ tunnel_id: data.id,
400
+ user_id: userId,
401
+ role: 'owner',
402
+ status: 'active',
403
+ });
375
404
  return { shareUrl: `${APP_URL}/share/${shareId}`, tunnelId: data.id };
376
405
  }
377
406
  async function deactivateTunnel(sb, tunnelId) {
@@ -593,7 +622,6 @@ program
593
622
  .option('-n, --name <name>', 'Tunnel name. Reuse a name to resume the same share URL.')
594
623
  .option('--provider <provider>', 'Tunnel provider: cloudflared (default) or ngrok')
595
624
  .action(async (opts) => {
596
- requireAuth();
597
625
  const port = parseInt(opts.port, 10);
598
626
  console.log('');
599
627
  console.log(chalk_1.default.blue.bold(' ⟐ Checkpoint'));
@@ -622,10 +650,8 @@ program
622
650
  process.exit(1);
623
651
  }
624
652
  // Authenticate
625
- const sb = await getAuthenticatedClient();
653
+ const sb = await ensureAuthenticatedClient();
626
654
  if (!sb) {
627
- console.log(chalk_1.default.red(' Session expired. Run `checkpoint login` again.'));
628
- console.log('');
629
655
  process.exit(1);
630
656
  }
631
657
  // Detect provider
@@ -695,14 +721,11 @@ program
695
721
  .option('-n, --name <name>', 'Name for this tunnel', 'My Tunnel')
696
722
  .option('-p, --port <port>', 'Local port for reference', '3000')
697
723
  .action(async (opts) => {
698
- requireAuth();
699
724
  console.log('');
700
725
  console.log(chalk_1.default.blue.bold(' ⟐ Checkpoint'));
701
726
  console.log('');
702
- const sb = await getAuthenticatedClient();
727
+ const sb = await ensureAuthenticatedClient();
703
728
  if (!sb) {
704
- console.log(chalk_1.default.red(' Session expired. Run `checkpoint login` again.'));
705
- console.log('');
706
729
  process.exit(1);
707
730
  }
708
731
  if (!isValidUrl(opts.url)) {
@@ -760,6 +783,12 @@ program
760
783
  console.log(chalk_1.default.red(` Failed: ${error?.message ?? 'unknown error'}`));
761
784
  process.exit(1);
762
785
  }
786
+ await sb.from('tunnel_members').insert({
787
+ tunnel_id: data.id,
788
+ user_id: userData.user.id,
789
+ role: 'owner',
790
+ status: 'active',
791
+ });
763
792
  const shareUrl = `${APP_URL}/share/${shareId}`;
764
793
  console.log(chalk_1.default.green(' ✓ Registered'));
765
794
  console.log(` ${chalk_1.default.gray('Tunnel URL:')} ${chalk_1.default.cyan(opts.url)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "checkpoint-cli",
3
- "version": "0.5.2",
3
+ "version": "1.0.1",
4
4
  "description": "Share your localhost with reviewers — get visual feedback directly on the page",
5
5
  "keywords": [
6
6
  "checkpoint",