@zuvo/cli 0.1.0 → 0.1.2

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/bin/zuvo.js CHANGED
File without changes
package/dist/login.js CHANGED
@@ -12,11 +12,23 @@ const POLL_TIMEOUT_MS = 5 * 60 * 1000;
12
12
  async function openBrowser(url) {
13
13
  const platform = process.platform;
14
14
  if (platform === 'darwin') {
15
- await execFileAsync('open', [url]);
16
- return;
15
+ // `/usr/bin/open URL` can split on `&`, dropping `public_key`. `-u` treats
16
+ // the argument as one URL. AppleScript is the fallback on older macOS.
17
+ try {
18
+ await execFileAsync('open', ['-u', url]);
19
+ return;
20
+ }
21
+ catch {
22
+ await execFileAsync('osascript', [
23
+ '-e',
24
+ `open location ${JSON.stringify(url)}`,
25
+ ]);
26
+ return;
27
+ }
17
28
  }
18
29
  if (platform === 'win32') {
19
- await execFileAsync('cmd', ['/c', 'start', '', url]);
30
+ // cmd.exe treats `&` as a command separator. Quote the URL as one argument.
31
+ await execFileAsync('cmd', ['/c', 'start', '', `"${url.replaceAll('"', '')}"`]);
20
32
  return;
21
33
  }
22
34
  await execFileAsync('xdg-open', [url]);
@@ -57,14 +69,29 @@ export async function loginWithToken(token) {
57
69
  }
58
70
  await saveAccessToken(trimmed);
59
71
  }
72
+ export function packCliLoginPayload(opts) {
73
+ return Buffer.from(JSON.stringify({
74
+ session_id: opts.sessionId,
75
+ public_key: opts.publicKeyHex,
76
+ token_name: opts.tokenName,
77
+ }), 'utf8').toString('base64url');
78
+ }
79
+ export function buildCliLoginUrl(opts) {
80
+ const studio = opts.studioUrl.replace(/\/$/, '');
81
+ // A single query param so Windows `start`, macOS Terminal, and VS Code
82
+ // hyperlinks cannot truncate `public_key` at `&`.
83
+ return `${studio}/cli/login?p=${packCliLoginPayload(opts)}`;
84
+ }
60
85
  export async function loginBrowser(opts) {
61
86
  const { ecdh, publicKeyHex } = generateLoginKeyPair();
62
87
  const sessionId = randomUUID();
63
88
  const tokenName = opts.tokenName || defaultTokenName();
64
- const studio = studioUrlFromEnv(opts.studioUrl);
65
- const loginUrl = `${studio}/cli/login?session_id=${encodeURIComponent(sessionId)}` +
66
- `&public_key=${encodeURIComponent(publicKeyHex)}` +
67
- `&token_name=${encodeURIComponent(tokenName)}`;
89
+ const loginUrl = buildCliLoginUrl({
90
+ studioUrl: studioUrlFromEnv(opts.studioUrl),
91
+ sessionId,
92
+ publicKeyHex,
93
+ tokenName,
94
+ });
68
95
  console.log('Open this URL to authorize the CLI:');
69
96
  console.log(loginUrl);
70
97
  if (opts.openBrowser) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuvo/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Zuvo CLI — login, link, functions deploy, and db push",
6
6
  "license": "MIT",