@addorimprove/prompt 0.1.0 → 0.1.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/prompt.js +8 -3
  2. package/package.json +1 -1
package/dist/prompt.js CHANGED
@@ -249,6 +249,11 @@ function buildAuthorizeUrl(p) {
249
249
  u.searchParams.set("redirect_uri", p.redirectUri);
250
250
  return u.toString();
251
251
  }
252
+ function renderCallbackPage(msg, redirectTo) {
253
+ const head = redirectTo ? `<meta http-equiv="refresh" content="0;url=${redirectTo}">` : "";
254
+ const tail = redirectTo ? `<p>Redirecting to your dashboard… If nothing happens, <a href="${redirectTo}">continue</a>.</p>` : `<p>You can close this tab and return to the terminal.</p>`;
255
+ return `<!doctype html><html><head><meta charset="utf-8">${head}</head>` + `<body style="font-family:sans-serif"><h2>${msg}</h2>${tail}</body></html>`;
256
+ }
252
257
  function parseCallback(reqUrl) {
253
258
  const u = new URL(reqUrl, "http://127.0.0.1");
254
259
  return {
@@ -297,9 +302,9 @@ async function login(baseUrlFlag) {
297
302
  timer.unref();
298
303
  const server = createServer((req, res) => {
299
304
  const { code: code2, state: gotState, error } = parseCallback(req.url ?? "");
300
- const finish = (status, msg) => {
305
+ const finish = (status, msg, redirectTo) => {
301
306
  res.writeHead(status, { "content-type": "text/html" });
302
- res.end(`<html><body style="font-family:sans-serif"><h2>${msg}</h2><p>You can close this tab and return to the terminal.</p></body></html>`);
307
+ res.end(renderCallbackPage(msg, redirectTo));
303
308
  };
304
309
  const fail = (err, status, msg) => {
305
310
  finish(status, msg);
@@ -313,7 +318,7 @@ async function login(baseUrlFlag) {
313
318
  return fail(new Error("state mismatch"), 400, "State mismatch — aborting.");
314
319
  if (!code2)
315
320
  return fail(new Error("missing code"), 400, "Missing authorization code.");
316
- finish(200, "Logged in to Prompt CLI.");
321
+ finish(200, "Logged in to Prompt CLI.", new URL("/", baseUrl).toString());
317
322
  clearTimeout(timer);
318
323
  server.close();
319
324
  resolve({ code: code2, redirectUri: redirectUri2 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@addorimprove/prompt",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "bin": { "prompt": "dist/prompt.js" },
6
6
  "files": ["dist"],