@keystrokehq/cli 0.0.120 → 0.0.122

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/index.mjs CHANGED
@@ -3077,7 +3077,7 @@ function clearAccessToken(webUrl) {
3077
3077
  new Entry(SERVICE, accountForWebUrl(webUrl)).deletePassword();
3078
3078
  }
3079
3079
  //#endregion
3080
- //#region ../../packages/auth/dist/jwt-jroYvvqz.mjs
3080
+ //#region ../../packages/auth/dist/jwt-BVJ7dVm9.mjs
3081
3081
  /** OAuth device-flow client id for `keystroke auth login`. */
3082
3082
  const CLI_CLIENT_ID = "keystroke-cli";
3083
3083
  async function fetchJwtWithSession(authBaseUrl, sessionCredential) {
@@ -4725,18 +4725,18 @@ async function getJwtWithBearer(baseURL, sessionToken) {
4725
4725
  //#endregion
4726
4726
  //#region src/auth/jwt-cache.ts
4727
4727
  const caches = /* @__PURE__ */ new Map();
4728
- async function getCliJwt(webUrl, force = false) {
4729
- if (!getAccessToken(webUrl)) {
4730
- caches.delete(webUrl);
4728
+ async function getCliJwt(platformUrl, force = false) {
4729
+ if (!getAccessToken(platformUrl)) {
4730
+ caches.delete(platformUrl);
4731
4731
  return;
4732
4732
  }
4733
- let cache = caches.get(webUrl);
4733
+ let cache = caches.get(platformUrl);
4734
4734
  if (!cache) {
4735
4735
  cache = createJwtTokenCache(async () => {
4736
- const sessionToken = getAccessToken(webUrl);
4737
- return sessionToken ? getJwtWithBearer(webUrl, sessionToken) : null;
4736
+ const sessionToken = getAccessToken(platformUrl);
4737
+ return sessionToken ? getJwtWithBearer(platformUrl, sessionToken) : null;
4738
4738
  });
4739
- caches.set(webUrl, cache);
4739
+ caches.set(platformUrl, cache);
4740
4740
  }
4741
4741
  return cache.get(force);
4742
4742
  }
@@ -4820,11 +4820,11 @@ function getPlatformUrl(config) {
4820
4820
  //#region src/auth/resolve-cli-auth.ts
4821
4821
  /** Returns JWT bearer auth when a session refresh token is stored; otherwise none. */
4822
4822
  function resolveCliAuth(config) {
4823
- const webUrl = getWebUrl(config);
4824
- if (!getAccessToken(webUrl)) return { type: "none" };
4823
+ const platformUrl = getPlatformUrl(config);
4824
+ if (!getAccessToken(platformUrl)) return { type: "none" };
4825
4825
  return {
4826
4826
  type: "bearer",
4827
- getToken: () => getCliJwt(webUrl)
4827
+ getToken: () => getCliJwt(platformUrl)
4828
4828
  };
4829
4829
  }
4830
4830
  //#endregion
@@ -8660,11 +8660,11 @@ function toPlatformAuth(auth) {
8660
8660
  return { type: "none" };
8661
8661
  }
8662
8662
  function createCliPlatformClient(config) {
8663
- const webUrl = getWebUrl(config);
8663
+ const platformUrl = getPlatformUrl(config);
8664
8664
  return createPlatformClient({
8665
- baseUrl: getPlatformUrl(config),
8665
+ baseUrl: platformUrl,
8666
8666
  auth: toPlatformAuth(resolveCliAuth(config)),
8667
- refreshBearerToken: () => getCliJwt(webUrl, true),
8667
+ refreshBearerToken: () => getCliJwt(platformUrl, true),
8668
8668
  getActiveOrganizationId: () => config.get("activeOrganizationId") ?? null,
8669
8669
  onActiveOrganizationChange: (organizationId) => {
8670
8670
  if (organizationId) config.set("activeOrganizationId", organizationId);
@@ -8903,9 +8903,14 @@ function unreachableTarget(context) {
8903
8903
  function unreachableServerMessage(targetUrl) {
8904
8904
  return `Could not reach ${targetUrl ?? "the keystroke server"}. Is the server running? (keystroke dev or keystroke start)`;
8905
8905
  }
8906
+ function authApiOrigin(context) {
8907
+ if (context?.platformUrl) return context.platformUrl;
8908
+ if (context?.webUrl) return resolvePlatformUrlForWebUrl(context.webUrl, {});
8909
+ }
8906
8910
  function formatHttpClientError(error, context) {
8907
8911
  if (error.status === 401) {
8908
- if (context?.webUrl && !getAccessToken(context.webUrl)) return "Not logged in. Run `keystroke auth login` first.";
8912
+ const origin = authApiOrigin(context);
8913
+ if (origin && !getAccessToken(origin)) return "Not logged in. Run `keystroke auth login` first.";
8909
8914
  return "Authentication failed. Run `keystroke auth login` again.";
8910
8915
  }
8911
8916
  if (error.status === 0) return unreachableServerMessage(unreachableTarget(context));
@@ -9317,17 +9322,20 @@ function registerAuthLoginCommand(auth) {
9317
9322
  config.set("platformUrl", platformUrl);
9318
9323
  try {
9319
9324
  const result = await runDeviceLogin({
9320
- baseURL: webUrl,
9325
+ baseURL: platformUrl,
9321
9326
  clientId: CLI_CLIENT_ID,
9322
9327
  openUrl
9323
9328
  });
9324
- setAccessToken(webUrl, result.accessToken);
9325
- const user = await getSessionWithBearer(webUrl, result.accessToken);
9329
+ setAccessToken(platformUrl, result.accessToken);
9330
+ const user = await getSessionWithBearer(platformUrl, result.accessToken);
9326
9331
  if (user) process.stdout.write(`Logged in as ${user.name} (${user.email})\n`);
9327
9332
  else process.stdout.write(`Logged in to ${webUrl}\n`);
9328
9333
  await syncActiveOrganizationAfterLogin(config, { organizationId: options.org });
9329
9334
  } catch (error) {
9330
- process.stderr.write(`${formatCliError(error, "Login failed", { webUrl })}\n`);
9335
+ process.stderr.write(`${formatCliError(error, "Login failed", {
9336
+ webUrl,
9337
+ platformUrl
9338
+ })}\n`);
9331
9339
  process.exitCode = 1;
9332
9340
  }
9333
9341
  });
@@ -9338,10 +9346,12 @@ function registerAuthLogoutCommand(auth) {
9338
9346
  auth.command("logout").description("Clear stored credentials").option("--web-url <url>", "Web dashboard origin (default from config)").action((options) => {
9339
9347
  const config = createCliConfig();
9340
9348
  const webUrl = options.webUrl ?? getWebUrl(config);
9341
- clearAccessToken(webUrl);
9349
+ const platformUrl = getPlatformUrl(config);
9350
+ clearAccessToken(platformUrl);
9342
9351
  process.stdout.write(`${JSON.stringify({
9343
9352
  authenticated: false,
9344
- webUrl
9353
+ webUrl,
9354
+ platformUrl
9345
9355
  })}\n`);
9346
9356
  });
9347
9357
  }
@@ -9351,16 +9361,18 @@ function registerAuthStatusCommand(auth) {
9351
9361
  auth.command("status").description("Show authentication status").option("--web-url <url>", "Web dashboard origin (default from config)").action(async (options) => {
9352
9362
  const config = createCliConfig();
9353
9363
  const webUrl = options.webUrl ?? getWebUrl(config);
9354
- const token = getAccessToken(webUrl);
9364
+ const platformUrl = getPlatformUrl(config);
9365
+ const token = getAccessToken(platformUrl);
9355
9366
  if (!token) {
9356
9367
  process.stdout.write(`${JSON.stringify({
9357
9368
  authenticated: false,
9358
- webUrl
9369
+ webUrl,
9370
+ platformUrl
9359
9371
  })}\n`);
9360
9372
  return;
9361
9373
  }
9362
9374
  try {
9363
- const user = await getSessionWithBearer(webUrl, token);
9375
+ const user = await getSessionWithBearer(platformUrl, token);
9364
9376
  const organizations = user ? await listOrganizations(config).catch(() => []) : [];
9365
9377
  const activeOrganizationId = config.get("activeOrganizationId");
9366
9378
  const activeOrganization = activeOrganizationId ? organizations.find((entry) => entry.organization.id === activeOrganizationId) : void 0;
@@ -9373,7 +9385,10 @@ function registerAuthStatusCommand(auth) {
9373
9385
  })}\n`);
9374
9386
  if (!user) process.exitCode = 1;
9375
9387
  } catch (error) {
9376
- process.stderr.write(`${formatCliError(error, "Status check failed", { webUrl })}\n`);
9388
+ process.stderr.write(`${formatCliError(error, "Status check failed", {
9389
+ webUrl,
9390
+ platformUrl
9391
+ })}\n`);
9377
9392
  process.exitCode = 1;
9378
9393
  }
9379
9394
  });