@glassly/cli 2.0.7 → 2.0.8-dev.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glassly/cli",
3
- "version": "2.0.7",
3
+ "version": "2.0.8-dev.0",
4
4
  "description": "The glassly command: develop, pack, release, and publish Glassly miniapps. Bun-only.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  "typecheck": "tsc --noEmit"
23
23
  },
24
24
  "dependencies": {
25
- "@glassly/miniapp-cli": "0.1.7",
25
+ "@glassly/miniapp-cli": "0.1.7-dev.0",
26
26
  "commander": "^15.1.0",
27
27
  "qrcode": "^1.5.4"
28
28
  },
@@ -0,0 +1,46 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { deviceLoginUrl, getConfig, type CliConfig } from "./config";
3
+
4
+ const challenge = {
5
+ user_code: "ABCD-EFGH",
6
+ verification_uri_complete: "https://example.authkit.app/device?user_code=ABCD-EFGH",
7
+ };
8
+
9
+ function withEnv(env: Record<string, string | undefined>, read: () => CliConfig): CliConfig {
10
+ const saved = Object.fromEntries(Object.keys(env).map((key) => [key, process.env[key]]));
11
+ Object.assign(process.env, env);
12
+ for (const [key, value] of Object.entries(env)) if (value === undefined) delete process.env[key];
13
+ try {
14
+ return read();
15
+ } finally {
16
+ for (const [key, value] of Object.entries(saved)) {
17
+ if (value === undefined) delete process.env[key];
18
+ else process.env[key] = value;
19
+ }
20
+ }
21
+ }
22
+
23
+ const production = () =>
24
+ withEnv({ CLOUD_CONSOLE_URL: undefined, CLOUD_CORE_URL: undefined, WORKOS_CLIENT_ID: undefined }, getConfig);
25
+
26
+ describe("deviceLoginUrl", () => {
27
+ test("production login goes through console.glassly.ai", () => {
28
+ expect(deviceLoginUrl(production(), challenge)).toBe("https://console.glassly.ai/device?user_code=ABCD-EFGH");
29
+ });
30
+
31
+ test("other consoles keep the AuthKit link", () => {
32
+ const dev = withEnv({ CLOUD_CONSOLE_URL: "https://console.dev.glassly.ai" }, getConfig);
33
+ expect(deviceLoginUrl(dev, challenge)).toBe(challenge.verification_uri_complete);
34
+ });
35
+
36
+ test("another WorkOS client keeps the AuthKit link", () => {
37
+ const other = withEnv({ CLOUD_CONSOLE_URL: undefined, WORKOS_CLIENT_ID: "client_other" }, getConfig);
38
+ expect(deviceLoginUrl(other, challenge)).toBe(challenge.verification_uri_complete);
39
+ });
40
+
41
+ test("the user code is URL-encoded", () => {
42
+ expect(deviceLoginUrl(production(), { ...challenge, user_code: "AB&CD" })).toBe(
43
+ "https://console.glassly.ai/device?user_code=AB%26CD",
44
+ );
45
+ });
46
+ });
package/src/config.ts CHANGED
@@ -25,6 +25,19 @@ export function getConfig(): CliConfig {
25
25
  };
26
26
  }
27
27
 
28
+ // The browser link `glassly login` prints. Production goes through
29
+ // console.glassly.ai/device, which forwards to the WorkOS AuthKit device page
30
+ // (cloud/websites/console/functions/device.ts), so developers see a Glassly
31
+ // address. Other backends have no such route, so they get AuthKit's own link.
32
+ export function deviceLoginUrl(
33
+ config: CliConfig,
34
+ challenge: { user_code: string; verification_uri_complete: string },
35
+ ): string {
36
+ const production = config.consoleUrl === PRODUCTION.consoleUrl && config.workosClientId === PRODUCTION.workosClientId;
37
+ if (!production) return challenge.verification_uri_complete;
38
+ return `${config.consoleUrl}/device?user_code=${encodeURIComponent(challenge.user_code)}`;
39
+ }
40
+
28
41
  function normalizeUrl(value: string): string {
29
42
  const url = new URL(value);
30
43
  url.pathname = url.pathname.replace(/\/+$/, "");
package/src/index.ts CHANGED
@@ -49,7 +49,7 @@ import {
49
49
  type PreinstallEnvironment,
50
50
  type PreinstallPolicy,
51
51
  } from "./api";
52
- import { getConfig } from "./config";
52
+ import { deviceLoginUrl, getConfig } from "./config";
53
53
  import { clearCredentials, loadCredentials, saveCredentials, type CliCredentials } from "./credentials";
54
54
  import { openBrowser } from "./open-browser";
55
55
  import { encodeDevAttestation, ensureSigningKey, signBundleMetadata, signDevAttestation } from "./signing";
@@ -95,12 +95,13 @@ program
95
95
 
96
96
  console.log("Sign in to Glassly Developer Console");
97
97
  console.log("");
98
- console.log(`Open: ${challenge.verification_uri_complete}`);
98
+ const loginUrl = deviceLoginUrl(config, challenge);
99
+ console.log(`Open: ${loginUrl}`);
99
100
  console.log(`Code: ${challenge.user_code}`);
100
101
  console.log("");
101
102
 
102
103
  if (options.open) {
103
- const opened = await openBrowser(challenge.verification_uri_complete);
104
+ const opened = await openBrowser(loginUrl);
104
105
  if (!opened) console.log("Could not open a browser automatically.");
105
106
  }
106
107