@meshpoint/cli 1.0.0-rc.2 → 1.0.0-rc.4

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/dist/bin.js CHANGED
File without changes
package/dist/config.js CHANGED
@@ -6,7 +6,22 @@ import { projectIdFromRemote } from "@meshpoint/sdk";
6
6
  export function configPath(env = process.env, home = homedir()) {
7
7
  return path.join(env.XDG_CONFIG_HOME ?? path.join(home, ".config"), "meshpoint", "config.json");
8
8
  }
9
+ // Only https reaches the platform; plain http is for a local development server.
10
+ export function allowedBaseUrl(raw) {
11
+ let url;
12
+ try {
13
+ url = new URL(raw);
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ if (url.protocol === "https:")
19
+ return true;
20
+ return url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1");
21
+ }
9
22
  // Environment overrides the file; MESHPOINT_BASE_URL and MESHPOINT_TOKEN are enough on their own.
23
+ // The file's credentials never travel to an environment-supplied URL: a repository can set
24
+ // MESHPOINT_BASE_URL through a harness's project settings, and the hooks inherit that environment.
10
25
  export function loadConfig(env = process.env, home = homedir()) {
11
26
  let fromFile = {};
12
27
  try {
@@ -17,11 +32,13 @@ export function loadConfig(env = process.env, home = homedir()) {
17
32
  }
18
33
  const baseUrl = env.MESHPOINT_BASE_URL ?? fromFile.baseUrl;
19
34
  const token = env.MESHPOINT_TOKEN ?? fromFile.token;
20
- if (!baseUrl || !token)
35
+ if (!baseUrl || !token || !allowedBaseUrl(baseUrl))
21
36
  return null;
22
37
  // An environment token stands alone: file-held refresh state belongs to the file's token.
23
38
  if (env.MESHPOINT_TOKEN)
24
39
  return { baseUrl, token };
40
+ if (env.MESHPOINT_BASE_URL && env.MESHPOINT_BASE_URL !== fromFile.baseUrl)
41
+ return null;
25
42
  return { ...fromFile, baseUrl, token };
26
43
  }
27
44
  export function saveConfig(config, env = process.env, home = homedir()) {
package/dist/control.js CHANGED
@@ -69,6 +69,11 @@ export async function login(opts) {
69
69
  const address = server.address();
70
70
  if (!address || typeof address === "string")
71
71
  throw new Error("could not bind a local port");
72
+ const q = new URLSearchParams({ port: String(address.port), nonce, agent });
73
+ if (opts.org)
74
+ q.set("org", opts.org);
75
+ const startUrl = `${opts.baseUrl.replace(/\/+$/, "")}/v1/auth/start?${q}`;
76
+ let started = false;
72
77
  const grant = new Promise((resolve, reject) => {
73
78
  const timer = setTimeout(() => reject(new Error("login timed out; run meshpoint login again")), opts.timeoutMs ?? LOGIN_TIMEOUT_MS);
74
79
  server.on("request", (req, res) => {
@@ -77,6 +82,13 @@ export async function login(opts) {
77
82
  res.writeHead(status, { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" });
78
83
  res.end(`<!doctype html><meta charset="utf-8"><title>Meshpoint</title><body style="font-family:system-ui;padding:3rem"><p>${body}</p></body>`);
79
84
  };
85
+ // The browser is sent to this local page first, so the nonce never sits in a process argument
86
+ // list; the page redirects once to the platform and then goes away.
87
+ if (url.pathname === "/start" && !started) {
88
+ started = true;
89
+ res.writeHead(302, { location: startUrl, "cache-control": "no-store" });
90
+ return res.end();
91
+ }
80
92
  if (url.pathname !== "/callback" || url.searchParams.get("nonce") !== nonce)
81
93
  return reply(404, "Not found.");
82
94
  const error = url.searchParams.get("error");
@@ -89,7 +101,7 @@ export async function login(opts) {
89
101
  const code = url.searchParams.get("code");
90
102
  if (!code)
91
103
  return reply(400, "Missing code.");
92
- api(opts.baseUrl, "POST", "/v1/auth/exchange", { body: { code }, fetch: opts.fetch }).then((g) => {
104
+ api(opts.baseUrl, "POST", "/v1/auth/exchange", { body: { code, nonce }, fetch: opts.fetch }).then((g) => {
93
105
  reply(200, `Logged in to Meshpoint as ${escapeHtml(g.email)} (org ${escapeHtml(g.org_name)}). You can close this tab.`);
94
106
  clearTimeout(timer);
95
107
  resolve(g);
@@ -100,12 +112,8 @@ export async function login(opts) {
100
112
  });
101
113
  });
102
114
  });
103
- const q = new URLSearchParams({ port: String(address.port), nonce, agent });
104
- if (opts.org)
105
- q.set("org", opts.org);
106
- const startUrl = `${opts.baseUrl.replace(/\/+$/, "")}/v1/auth/start?${q}`;
107
115
  log(`Open this URL to log in (a browser should open):\n ${startUrl}`);
108
- (opts.open ?? openBrowser)(startUrl);
116
+ (opts.open ?? openBrowser)(`http://127.0.0.1:${address.port}/start`);
109
117
  try {
110
118
  return configFromGrant(opts.baseUrl, await grant);
111
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshpoint/cli",
3
- "version": "1.0.0-rc.2",
3
+ "version": "1.0.0-rc.4",
4
4
  "description": "Meshpoint CLI and harness adapters",
5
5
  "keywords": [
6
6
  "meshpoint",
@@ -38,7 +38,7 @@
38
38
  "prepublishOnly": "npm run check && npm run build"
39
39
  },
40
40
  "dependencies": {
41
- "@meshpoint/sdk": "^1.0.0-rc.1"
41
+ "@meshpoint/sdk": "^1.0.0-rc.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.0.0",