@vendian/cli 0.0.11 → 0.0.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.
Files changed (2) hide show
  1. package/cli-wrapper.mjs +86 -12
  2. package/package.json +1 -1
package/cli-wrapper.mjs CHANGED
@@ -36304,6 +36304,38 @@ function activeCloudAuthStatus({ env: env3 = process.env, platform: platform2 =
36304
36304
  profiles
36305
36305
  };
36306
36306
  }
36307
+ function activateCloudProfile({ backend, apiUrl, env: env3 = process.env, platform: platform2 = process.platform } = {}) {
36308
+ const targetApiUrl = resolveApiUrl({ backend, apiUrl, env: env3 });
36309
+ const config = loadCloudConfig(env3, platform2);
36310
+ const profiles = config.profiles && typeof config.profiles === "object" ? config.profiles : {};
36311
+ const profile = profiles[targetApiUrl];
36312
+ if (!profile || typeof profile !== "object" || !profile.access_token) {
36313
+ return {
36314
+ apiUrl: targetApiUrl,
36315
+ activeApiUrl: typeof config.active_api_url === "string" ? config.active_api_url : void 0,
36316
+ authenticated: false,
36317
+ activated: false,
36318
+ profiles
36319
+ };
36320
+ }
36321
+ const next = {
36322
+ ...config,
36323
+ version: config.version || 2,
36324
+ profiles,
36325
+ active_api_url: targetApiUrl
36326
+ };
36327
+ writeCloudConfig(next, { env: env3, platform: platform2 });
36328
+ return {
36329
+ apiUrl: targetApiUrl,
36330
+ activeApiUrl: targetApiUrl,
36331
+ profile,
36332
+ authenticated: true,
36333
+ activated: true,
36334
+ email: typeof profile.email === "string" ? profile.email : void 0,
36335
+ expiresAt: typeof profile.expires_at === "string" ? profile.expires_at : void 0,
36336
+ profiles
36337
+ };
36338
+ }
36307
36339
  async function getOAuthConfig(apiUrl, redirectUri) {
36308
36340
  const url = new URL(`${apiUrl}/api/v1/cli/auth/oauth/config`);
36309
36341
  url.searchParams.set("redirectUri", redirectUri);
@@ -36452,18 +36484,18 @@ function cloudConfigPath(env3 = process.env, platform2 = process.platform) {
36452
36484
  return path5.posix.join(root, "vendian", "cloud-auth.json");
36453
36485
  }
36454
36486
  function saveCloudToken(token, { env: env3 = process.env, platform: platform2 = process.platform } = {}) {
36455
- const file = cloudConfigPath(env3, platform2);
36487
+ const tokenApiUrl = String(token.apiUrl || "").replace(/\/$/, "");
36456
36488
  let raw = { version: 2, profiles: {}, active_api_url: token.apiUrl };
36457
36489
  try {
36458
- const existing = JSON.parse(fs6.readFileSync(file, "utf8"));
36490
+ const existing = loadCloudConfig(env3, platform2);
36459
36491
  if (existing && typeof existing === "object" && existing.profiles && typeof existing.profiles === "object") {
36460
36492
  raw.profiles = existing.profiles;
36461
36493
  }
36462
36494
  } catch {
36463
36495
  }
36464
- raw.active_api_url = token.apiUrl;
36465
- raw.profiles[token.apiUrl] = {
36466
- api_url: token.apiUrl,
36496
+ raw.active_api_url = tokenApiUrl;
36497
+ raw.profiles[tokenApiUrl] = {
36498
+ api_url: tokenApiUrl,
36467
36499
  access_token: token.accessToken,
36468
36500
  user_id: token.userId,
36469
36501
  email: token.email,
@@ -36471,6 +36503,10 @@ function saveCloudToken(token, { env: env3 = process.env, platform: platform2 =
36471
36503
  scopes: token.scopes,
36472
36504
  tooling_eligible: token.toolingEligible
36473
36505
  };
36506
+ return writeCloudConfig(raw, { env: env3, platform: platform2 });
36507
+ }
36508
+ function writeCloudConfig(raw, { env: env3 = process.env, platform: platform2 = process.platform } = {}) {
36509
+ const file = cloudConfigPath(env3, platform2);
36474
36510
  fs6.mkdirSync(path5.dirname(file), { recursive: true });
36475
36511
  fs6.writeFileSync(file, `${JSON.stringify(raw, null, 2)}
36476
36512
  `, { encoding: "utf8", mode: 384 });
@@ -36519,6 +36555,7 @@ async function setup({
36519
36555
  savePackageCredentials(next, packageCredentials, { platform: platform2 });
36520
36556
  }
36521
36557
  } else if (auth.authenticated) {
36558
+ activateCloudProfile({ backend, apiUrl, env: env3, platform: platform2 });
36522
36559
  console.log(`Cloud authentication already saved for ${auth.apiUrl}${auth.email ? ` (${auth.email})` : ""}.`);
36523
36560
  const refreshed = await refreshPackageAccessFromCloudAuth({ config: next, auth, env: env3, platform: platform2 });
36524
36561
  Object.assign(next, refreshed.config);
@@ -36742,7 +36779,7 @@ import fs12 from "node:fs";
36742
36779
  import readlinePromises from "node:readline/promises";
36743
36780
 
36744
36781
  // src/version.js
36745
- var CLI_VERSION = true ? "0.0.11" : process.env.npm_package_version || "0.0.0-dev";
36782
+ var CLI_VERSION = true ? "0.0.12" : process.env.npm_package_version || "0.0.0-dev";
36746
36783
 
36747
36784
  // src/npm-update.js
36748
36785
  var NPM_CHECK_INTERVAL_MS = 30 * 60 * 1e3;
@@ -37930,6 +37967,35 @@ function endpointRows({ env: env3 = process.env, platform: platform2 = process.p
37930
37967
  };
37931
37968
  });
37932
37969
  }
37970
+ async function switchOrLoginEndpoint({
37971
+ backend,
37972
+ apiUrl,
37973
+ env: env3 = process.env,
37974
+ platform: platform2 = process.platform,
37975
+ setupFn = setup,
37976
+ activateFn = activateCloudProfile
37977
+ } = {}) {
37978
+ const status = cloudAuthStatus({ backend, apiUrl, env: env3, platform: platform2 });
37979
+ if (status.authenticated) {
37980
+ const activated = activateFn({ backend, apiUrl, env: env3, platform: platform2 });
37981
+ return { apiUrl: status.apiUrl, reused: true, activated: Boolean(activated?.activated) };
37982
+ }
37983
+ await setupFn({ backend, apiUrl, forceAuth: true, env: env3, platform: platform2 });
37984
+ return { apiUrl: status.apiUrl, reused: false, activated: true };
37985
+ }
37986
+ function endpointErrorStatus(error) {
37987
+ const message = error && typeof error.message === "string" ? error.message : String(error || "Connection failed");
37988
+ return `${fig.cross} ${message}`;
37989
+ }
37990
+ function endpointStatusColor(status) {
37991
+ if (status.includes(fig.check)) {
37992
+ return colors.success;
37993
+ }
37994
+ if (status.includes(fig.cross)) {
37995
+ return colors.error;
37996
+ }
37997
+ return colors.muted;
37998
+ }
37933
37999
  function runtimeSummary({ env: env3 = process.env, platform: platform2 = process.platform, now = Date.now() } = {}) {
37934
38000
  const config = loadConfig(env3, platform2);
37935
38001
  const venvPath = managedVenvPath(env3, platform2);
@@ -38169,8 +38235,12 @@ function ConnectScreen({ env: env3, platform: platform2, onBack }) {
38169
38235
  return;
38170
38236
  }
38171
38237
  setStatus(`Connecting to ${value}...`);
38172
- await setup({ backend: value, forceAuth: true, env: env3, platform: platform2 });
38173
- setStatus(`${fig.check} Connected`);
38238
+ try {
38239
+ await switchOrLoginEndpoint({ backend: value, env: env3, platform: platform2 });
38240
+ setStatus(`${fig.check} Connected`);
38241
+ } catch (error) {
38242
+ setStatus(endpointErrorStatus(error));
38243
+ }
38174
38244
  }
38175
38245
  if (mode === "custom") {
38176
38246
  return h(
@@ -38185,11 +38255,15 @@ function ConnectScreen({ env: env3, platform: platform2, onBack }) {
38185
38255
  onSubmit: async (value) => {
38186
38256
  if (!value) return;
38187
38257
  setStatus("Connecting...");
38188
- await setup({ apiUrl: value, forceAuth: true, env: env3, platform: platform2 });
38189
- setStatus(`${fig.check} Connected`);
38258
+ try {
38259
+ await switchOrLoginEndpoint({ apiUrl: value, env: env3, platform: platform2 });
38260
+ setStatus(`${fig.check} Connected`);
38261
+ } catch (error) {
38262
+ setStatus(endpointErrorStatus(error));
38263
+ }
38190
38264
  }
38191
38265
  }),
38192
- status && h(Text2, { color: status.includes(fig.check) ? colors.success : colors.muted }, ` ${status}`),
38266
+ status && h(Text2, { color: endpointStatusColor(status) }, ` ${status}`),
38193
38267
  h(Text2, null, ""),
38194
38268
  h(FooterBar, { items: [{ key: "\u23CE", label: "Submit" }, { key: "esc", label: "Back" }] }),
38195
38269
  h(BackHint, { onBack })
@@ -38201,7 +38275,7 @@ function ConnectScreen({ env: env3, platform: platform2, onBack }) {
38201
38275
  h(Text2, { bold: true }, " Select environment:"),
38202
38276
  h(Text2, null, ""),
38203
38277
  h(SelectInput2, { items, onSelect: (item) => connect(item.value) }),
38204
- status && h(Text2, { color: status.includes(fig.check) ? colors.success : colors.muted }, ` ${status}`),
38278
+ status && h(Text2, { color: endpointStatusColor(status) }, ` ${status}`),
38205
38279
  h(Text2, null, ""),
38206
38280
  h(FooterBar, { items: [{ key: "\u2191\u2193", label: "Navigate" }, { key: "\u23CE", label: "Select" }, { key: "esc", label: "Back" }] })
38207
38281
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vendian/cli",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Public Vendian CLI bootstrapper and launcher",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,