@ze-norm/cli 0.4.0 → 0.5.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"device-flow.d.ts","sourceRoot":"","sources":["../../src/auth/device-flow.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"device-flow.d.ts","sourceRoot":"","sources":["../../src/auth/device-flow.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AA+RpD;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAkDpE"}
|
package/dist/auth/device-flow.js
CHANGED
|
@@ -4,7 +4,7 @@ import { exec } from "node:child_process";
|
|
|
4
4
|
import { platform } from "node:os";
|
|
5
5
|
import { URL, URLSearchParams } from "node:url";
|
|
6
6
|
import { log } from "../util/logger.js";
|
|
7
|
-
import { CLI_CALLBACK_PORTS, PRODUCTION_CLERK_CLIENT_ID, PRODUCTION_CLERK_ISSUER, } from "../config/defaults.js";
|
|
7
|
+
import { CLI_CALLBACK_PORTS, PRODUCTION_CLERK_CLIENT_ID, PRODUCTION_CLERK_ISSUER, PRODUCTION_WEB_URL, } from "../config/defaults.js";
|
|
8
8
|
/**
|
|
9
9
|
* Find the first pre-registered callback port that is free to bind. Clerk
|
|
10
10
|
* matches redirect_uris exactly, so the local listener must use one of the
|
|
@@ -28,6 +28,19 @@ async function pickFreeCallbackPort() {
|
|
|
28
28
|
function getClerkIssuer() {
|
|
29
29
|
return process.env["ZENORM_CLERK_ISSUER"] ?? PRODUCTION_CLERK_ISSUER;
|
|
30
30
|
}
|
|
31
|
+
/** Where the browser tab lands after a successful login. */
|
|
32
|
+
function getWebUrl() {
|
|
33
|
+
return process.env["ZENORM_WEB_URL"] ?? PRODUCTION_WEB_URL;
|
|
34
|
+
}
|
|
35
|
+
/** Escape user-influenced text before interpolating into the result page HTML. */
|
|
36
|
+
function escapeHtml(value) {
|
|
37
|
+
return value
|
|
38
|
+
.replace(/&/g, "&")
|
|
39
|
+
.replace(/</g, "<")
|
|
40
|
+
.replace(/>/g, ">")
|
|
41
|
+
.replace(/"/g, """)
|
|
42
|
+
.replace(/'/g, "'");
|
|
43
|
+
}
|
|
31
44
|
function getClerkClientId() {
|
|
32
45
|
return (process.env["ZENORM_CLERK_CLIENT_ID"] ??
|
|
33
46
|
process.env["VITE_CLERK_PUBLISHABLE_KEY"] ??
|
|
@@ -62,6 +75,100 @@ function tryOpenBrowser(url) {
|
|
|
62
75
|
}
|
|
63
76
|
});
|
|
64
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Render a self-contained, branded error page for the localhost callback.
|
|
80
|
+
*
|
|
81
|
+
* Only the failure paths render a page — a successful login 302-redirects the
|
|
82
|
+
* browser into the app instead. Served by the raw `http` server (no
|
|
83
|
+
* React/bundler available), so the page is fully inline: dark theme, ZeNorm
|
|
84
|
+
* wordmark, and the same card framing the web app uses on /sign-in.
|
|
85
|
+
*/
|
|
86
|
+
function renderCallbackPage(heading, body) {
|
|
87
|
+
const accent = "#f87171";
|
|
88
|
+
const glyph = "!";
|
|
89
|
+
return `<!doctype html>
|
|
90
|
+
<html lang="en">
|
|
91
|
+
<head>
|
|
92
|
+
<meta charset="utf-8" />
|
|
93
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
94
|
+
<title>ZeNorm CLI · ${heading}</title>
|
|
95
|
+
<style>
|
|
96
|
+
:root { color-scheme: dark; }
|
|
97
|
+
* { box-sizing: border-box; }
|
|
98
|
+
body {
|
|
99
|
+
margin: 0;
|
|
100
|
+
min-height: 100vh;
|
|
101
|
+
display: grid;
|
|
102
|
+
place-items: center;
|
|
103
|
+
padding: 24px;
|
|
104
|
+
background:
|
|
105
|
+
radial-gradient(ellipse 540px 360px at 50% 38%, rgba(99,102,241,0.16), transparent 70%),
|
|
106
|
+
#0a0a0b;
|
|
107
|
+
color: #ededee;
|
|
108
|
+
font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
|
|
109
|
+
Roboto, Helvetica, Arial, sans-serif;
|
|
110
|
+
-webkit-font-smoothing: antialiased;
|
|
111
|
+
}
|
|
112
|
+
.card {
|
|
113
|
+
position: relative;
|
|
114
|
+
width: 100%;
|
|
115
|
+
max-width: 380px;
|
|
116
|
+
border: 1px solid rgba(255,255,255,0.10);
|
|
117
|
+
border-radius: 12px;
|
|
118
|
+
background: rgba(20,20,22,0.72);
|
|
119
|
+
backdrop-filter: blur(6px);
|
|
120
|
+
box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset,
|
|
121
|
+
0 28px 70px -32px rgba(0,0,0,0.6);
|
|
122
|
+
padding: 40px 28px 32px;
|
|
123
|
+
text-align: center;
|
|
124
|
+
}
|
|
125
|
+
.eyebrow {
|
|
126
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
127
|
+
font-size: 10px;
|
|
128
|
+
letter-spacing: 0.22em;
|
|
129
|
+
text-transform: uppercase;
|
|
130
|
+
color: rgba(237,237,238,0.55);
|
|
131
|
+
margin-bottom: 22px;
|
|
132
|
+
}
|
|
133
|
+
.badge {
|
|
134
|
+
width: 48px; height: 48px;
|
|
135
|
+
margin: 0 auto 20px;
|
|
136
|
+
display: grid; place-items: center;
|
|
137
|
+
border-radius: 999px;
|
|
138
|
+
border: 1px solid ${accent}55;
|
|
139
|
+
background: ${accent}1a;
|
|
140
|
+
color: ${accent};
|
|
141
|
+
font-size: 22px; font-weight: 600;
|
|
142
|
+
line-height: 1;
|
|
143
|
+
}
|
|
144
|
+
h1 {
|
|
145
|
+
margin: 0 0 8px;
|
|
146
|
+
font-size: 1.5rem;
|
|
147
|
+
letter-spacing: -0.01em;
|
|
148
|
+
font-weight: 600;
|
|
149
|
+
}
|
|
150
|
+
p { margin: 0; color: rgba(237,237,238,0.62); font-size: 0.9rem; line-height: 1.5; }
|
|
151
|
+
.footer {
|
|
152
|
+
margin-top: 24px;
|
|
153
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
154
|
+
font-size: 10px;
|
|
155
|
+
letter-spacing: 0.18em;
|
|
156
|
+
text-transform: uppercase;
|
|
157
|
+
color: rgba(237,237,238,0.4);
|
|
158
|
+
}
|
|
159
|
+
</style>
|
|
160
|
+
</head>
|
|
161
|
+
<body>
|
|
162
|
+
<div class="card">
|
|
163
|
+
<div class="eyebrow">ZeNorm CLI</div>
|
|
164
|
+
<div class="badge">${glyph}</div>
|
|
165
|
+
<h1>${heading}</h1>
|
|
166
|
+
<p>${body}</p>
|
|
167
|
+
<div class="footer">Spec authoring, traced end-to-end</div>
|
|
168
|
+
</div>
|
|
169
|
+
</body>
|
|
170
|
+
</html>`;
|
|
171
|
+
}
|
|
65
172
|
/**
|
|
66
173
|
* Start a localhost HTTP server and wait for the OAuth callback.
|
|
67
174
|
* Resolves with the authorization code once the redirect arrives.
|
|
@@ -80,21 +187,26 @@ function waitForCallback(port, expectedState) {
|
|
|
80
187
|
const error = url.searchParams.get("error");
|
|
81
188
|
if (error) {
|
|
82
189
|
const desc = url.searchParams.get("error_description") ?? error;
|
|
83
|
-
res.writeHead(200, { "Content-Type": "text/html" });
|
|
84
|
-
res.end(
|
|
190
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
191
|
+
res.end(renderCallbackPage("Login failed", `${escapeHtml(desc)}. You can close this tab and try again.`));
|
|
85
192
|
server.close();
|
|
86
193
|
reject(new Error(`Authorization failed: ${desc}`));
|
|
87
194
|
return;
|
|
88
195
|
}
|
|
89
196
|
if (!code || state !== expectedState) {
|
|
90
|
-
res.writeHead(400, { "Content-Type": "text/html" });
|
|
91
|
-
res.end(
|
|
197
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
198
|
+
res.end(renderCallbackPage("Invalid callback", "Missing code or state mismatch. You can close this tab and try again."));
|
|
92
199
|
server.close();
|
|
93
200
|
reject(new Error("Invalid callback: missing code or state mismatch"));
|
|
94
201
|
return;
|
|
95
202
|
}
|
|
96
|
-
|
|
97
|
-
|
|
203
|
+
// No standalone success page — send the browser straight into the app
|
|
204
|
+
// (the user is already signed in), so the tab lands on the real product
|
|
205
|
+
// instead of a "you can close this tab" interstitial. The CLI reports
|
|
206
|
+
// success in the terminal. Errors still render the branded page below,
|
|
207
|
+
// since those can't sensibly drop the user into the dashboard.
|
|
208
|
+
res.writeHead(302, { Location: `${getWebUrl()}/dashboard` });
|
|
209
|
+
res.end();
|
|
98
210
|
server.close();
|
|
99
211
|
resolve(code);
|
|
100
212
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare const PRODUCTION_API_URL = "https://api.zenorm.com";
|
|
2
2
|
export declare const PRODUCTION_CLERK_ISSUER = "https://clerk.zenorm.com";
|
|
3
|
+
export declare const PRODUCTION_WEB_URL = "https://zenorm.com";
|
|
3
4
|
export declare const PRODUCTION_CLERK_CLIENT_ID = "nUFCpxIFWJ4YSB3A";
|
|
4
5
|
export declare const CLI_CALLBACK_PORTS: readonly [4571, 4572, 4573];
|
|
5
6
|
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/config/defaults.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAC3D,eAAO,MAAM,uBAAuB,6BAA6B,CAAC;AAIlE,eAAO,MAAM,kBAAkB,uBAAuB,CAAC;AAWvD,eAAO,MAAM,0BAA0B,qBAAqB,CAAC;AAK7D,eAAO,MAAM,kBAAkB,6BAA8B,CAAC"}
|
package/dist/config/defaults.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
export const PRODUCTION_API_URL = "https://api.zenorm.com";
|
|
2
2
|
export const PRODUCTION_CLERK_ISSUER = "https://clerk.zenorm.com";
|
|
3
|
+
// Prod web app. After a successful login the localhost callback 302-redirects
|
|
4
|
+
// the browser here so the tab lands on the real product (already signed in)
|
|
5
|
+
// instead of a standalone "you can close this tab" page.
|
|
6
|
+
export const PRODUCTION_WEB_URL = "https://zenorm.com";
|
|
3
7
|
// Clerk OAuth Application client id for the public CLI (prod instance
|
|
4
8
|
// clerk.zenorm.com). NOT the publishable key — this is the OAuth 2.0 client id
|
|
5
9
|
// from the "ZeNorm CLI" OAuth app. Its registered redirect_uris are the fixed
|
|
6
10
|
// localhost callback ports in CLI_CALLBACK_PORTS below.
|
|
11
|
+
//
|
|
12
|
+
// NOTE: this OAuth app has `consent_screen_enabled` set to FALSE out-of-band on
|
|
13
|
+
// the Clerk instance (via the Clerk Backend API, not tracked in this repo).
|
|
14
|
+
// That is what lets an already-signed-in `zenorm login` skip Clerk's OAuth
|
|
15
|
+
// consent screen and redirect straight to the localhost callback. To restore
|
|
16
|
+
// the consent screen, PATCH the OAuth app back to `consent_screen_enabled:true`.
|
|
7
17
|
export const PRODUCTION_CLERK_CLIENT_ID = "nUFCpxIFWJ4YSB3A";
|
|
8
18
|
// Fixed localhost callback ports the device-auth flow binds, in order. Clerk
|
|
9
19
|
// enforces exact redirect_uri matching, so these MUST stay in sync with the
|