@glasshome/widget-cli 0.4.10 → 0.4.12

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/cli.ts CHANGED
@@ -66,7 +66,12 @@ const { values: flags, positionals } = parseArgs({
66
66
  strict: false,
67
67
  });
68
68
 
69
- const explicitDir = flags.dir;
69
+ // strict:false widens every flag to string | boolean | undefined; a bare
70
+ // `--flag` with no value parses as `true`, which no string option accepts.
71
+ const str = (v: string | boolean | undefined): string | undefined =>
72
+ typeof v === "string" ? v : undefined;
73
+
74
+ const explicitDir = str(flags.dir);
70
75
  const [command, ...args] = positionals;
71
76
 
72
77
  if (command === "help" || flags.help) {
@@ -144,9 +149,9 @@ switch (effectiveCommand) {
144
149
  const hubUrlArg = args[0];
145
150
  const { runPublish } = await import("../src/commands/publish");
146
151
  await runPublish(resolveWidgetDir(), hubUrlArg, {
147
- name: flags.name,
148
- bump: flags.bump as "keep" | "patch" | "minor" | "major" | undefined,
149
- scope: flags.scope,
152
+ name: str(flags.name),
153
+ bump: str(flags.bump) as "keep" | "patch" | "minor" | "major" | undefined,
154
+ scope: str(flags.scope),
150
155
  });
151
156
  outro("Done");
152
157
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glasshome/widget-cli",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "description": "CLI for creating and managing GlassHome widgets",
5
5
  "type": "module",
6
6
  "bin": {
@@ -216,19 +216,19 @@ export async function runConnect(apiUrl: string, cwd: string): Promise<void> {
216
216
  });
217
217
 
218
218
  if (res.ok) {
219
- // better-auth's device-authorization plugin returns a
220
- // first-party session, not an OIDC token bundle. The bearer is
221
- // session.token; expiry is session.expiresAt (ISO/epoch/Date).
219
+ // better-auth's device-authorization plugin returns an OAuth-style
220
+ // bundle: { access_token, token_type, expires_in, scope }. The
221
+ // access_token IS the first-party session token.
222
222
  const data = (await res.json()) as {
223
- session?: { token: string; expiresAt: string | number | Date };
224
- user?: unknown;
223
+ access_token?: string;
224
+ expires_in?: number;
225
225
  };
226
- if (!data.session?.token) {
226
+ if (!data.access_token) {
227
227
  s.stop("Auth response missing session token");
228
228
  break;
229
229
  }
230
- token = data.session.token;
231
- const tokenExpiresAt = new Date(data.session.expiresAt).getTime();
230
+ token = data.access_token;
231
+ const tokenExpiresAt = Date.now() + (data.expires_in ?? 0) * 1000;
232
232
  storeHostToken(host, token, tokenExpiresAt);
233
233
  break;
234
234
  }
@@ -4,10 +4,12 @@ import { log, spinner } from "@clack/prompts";
4
4
  import open from "open";
5
5
  import { getHubUrl, storeToken } from "../utils/auth";
6
6
 
7
+ // Public client: PKCE authenticates it, no client secret. The redirect is an
8
+ // IP-loopback URI (RFC 8252) registered on the hub.
7
9
  const CLIENT_ID = "glasshome-widget-cli";
8
- const CLIENT_SECRET = "glasshome-cli-public";
10
+ const REDIRECT_HOST = "127.0.0.1";
9
11
  const REDIRECT_PORT = 9274;
10
- const REDIRECT_URI = `http://localhost:${REDIRECT_PORT}/callback`;
12
+ const REDIRECT_URI = `http://${REDIRECT_HOST}:${REDIRECT_PORT}/callback`;
11
13
  const LOGIN_TIMEOUT_MS = 120_000;
12
14
 
13
15
  function base64url(buf: Buffer): string {
@@ -35,7 +37,7 @@ export async function runLogin(hubUrl?: string): Promise<void> {
35
37
  }, LOGIN_TIMEOUT_MS);
36
38
 
37
39
  const server = createServer((req: IncomingMessage, res: ServerResponse) => {
38
- const url = new URL(req.url!, `http://localhost:${REDIRECT_PORT}`);
40
+ const url = new URL(req.url!, `http://${REDIRECT_HOST}:${REDIRECT_PORT}`);
39
41
 
40
42
  if (url.pathname !== "/callback") {
41
43
  res.writeHead(404);
@@ -70,7 +72,7 @@ export async function runLogin(hubUrl?: string): Promise<void> {
70
72
  resolve({ code, receivedState });
71
73
  });
72
74
 
73
- server.listen(REDIRECT_PORT, () => {
75
+ server.listen(REDIRECT_PORT, REDIRECT_HOST, () => {
74
76
  const authUrl = new URL(`${hub}/api/auth/oauth2/authorize`);
75
77
  authUrl.searchParams.set("client_id", CLIENT_ID);
76
78
  authUrl.searchParams.set("redirect_uri", REDIRECT_URI);
@@ -109,7 +111,6 @@ export async function runLogin(hubUrl?: string): Promise<void> {
109
111
  redirect_uri: REDIRECT_URI,
110
112
  code_verifier: codeVerifier,
111
113
  client_id: CLIENT_ID,
112
- client_secret: CLIENT_SECRET,
113
114
  }),
114
115
  });
115
116
 
package/src/utils/auth.ts CHANGED
@@ -114,7 +114,6 @@ export async function getToken(hubUrl: string): Promise<string | null> {
114
114
  grant_type: "refresh_token",
115
115
  refresh_token: stored.refreshToken,
116
116
  client_id: "glasshome-widget-cli",
117
- client_secret: "glasshome-cli-public",
118
117
  }),
119
118
  });
120
119