@mp-lb/forum-cli 0.1.51 → 0.1.52

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.js CHANGED
@@ -5145,13 +5145,13 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
5145
5145
  }
5146
5146
  return propValues;
5147
5147
  });
5148
- const isObject4 = isObject;
5148
+ const isObject5 = isObject;
5149
5149
  const catchall = def.catchall;
5150
5150
  let value;
5151
5151
  inst._zod.parse = (payload, ctx) => {
5152
5152
  value ?? (value = _normalized.value);
5153
5153
  const input = payload.value;
5154
- if (!isObject4(input)) {
5154
+ if (!isObject5(input)) {
5155
5155
  payload.issues.push({
5156
5156
  expected: "object",
5157
5157
  code: "invalid_type",
@@ -5278,7 +5278,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
5278
5278
  return (payload, ctx) => fn(shape, payload, ctx);
5279
5279
  };
5280
5280
  let fastpass;
5281
- const isObject4 = isObject;
5281
+ const isObject5 = isObject;
5282
5282
  const jit = !globalConfig.jitless;
5283
5283
  const allowsEval2 = allowsEval;
5284
5284
  const fastEnabled = jit && allowsEval2.value;
@@ -5287,7 +5287,7 @@ var $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) =>
5287
5287
  inst._zod.parse = (payload, ctx) => {
5288
5288
  value ?? (value = _normalized.value);
5289
5289
  const input = payload.value;
5290
- if (!isObject4(input)) {
5290
+ if (!isObject5(input)) {
5291
5291
  payload.issues.push({
5292
5292
  expected: "object",
5293
5293
  code: "invalid_type",
@@ -24191,6 +24191,29 @@ var skillScanSchema = external_exports.object({
24191
24191
  )
24192
24192
  });
24193
24193
 
24194
+ // ../../packages/core/src/cliSessions/cliSessionSchema.ts
24195
+ var cliSessionSchema = external_exports.object({
24196
+ id: external_exports.string().trim().min(1),
24197
+ userId: external_exports.string().trim().min(1),
24198
+ workspaceId: external_exports.string().trim().min(1),
24199
+ clientLabel: external_exports.string().trim().min(1).max(120).nullable().default(null),
24200
+ createdAt: external_exports.string().datetime(),
24201
+ expiresAt: external_exports.string().datetime(),
24202
+ lastUsedAt: external_exports.string().datetime().nullable().default(null),
24203
+ revokedAt: external_exports.string().datetime().nullable().default(null)
24204
+ });
24205
+
24206
+ // ../../packages/core/src/cliSessions/revokeOwnCliSessionInputSchema.ts
24207
+ var revokeOwnCliSessionInputSchema = external_exports.object({
24208
+ sessionId: external_exports.string().trim().min(1)
24209
+ });
24210
+
24211
+ // ../../packages/core/src/cliSessions/listOwnCliSessionsInputSchema.ts
24212
+ var listOwnCliSessionsInputSchema = external_exports.object({});
24213
+
24214
+ // ../../packages/core/src/cliSessions/revokeCurrentCliSessionInputSchema.ts
24215
+ var revokeCurrentCliSessionInputSchema = external_exports.object({});
24216
+
24194
24217
  // ../../packages/store-tree/src/patterns.ts
24195
24218
  var escapeRegex2 = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
24196
24219
  var basename2 = (path28) => {
@@ -24252,6 +24275,9 @@ var storeRootPathFromId2 = (storeId) => {
24252
24275
  return `/${normalizeStoreId2(storeId)}`;
24253
24276
  };
24254
24277
 
24278
+ // src/auth.ts
24279
+ import { hostname as hostname3 } from "os";
24280
+
24255
24281
  // src/openInBrowser.ts
24256
24282
  import { execFile } from "child_process";
24257
24283
  import { promisify } from "util";
@@ -24622,7 +24648,8 @@ var interactiveLogin = async ({
24622
24648
  {
24623
24649
  method: "POST",
24624
24650
  headers: { "Content-Type": "application/json" },
24625
- body: "{}"
24651
+ // Shown in `fm auth sessions` so users can tell their sessions apart.
24652
+ body: JSON.stringify({ clientLabel: hostname3() })
24626
24653
  }
24627
24654
  );
24628
24655
  if (!startResponse.ok) {
@@ -31906,6 +31933,7 @@ var isTransientForumApiFailure = (error51) => {
31906
31933
  var retrySafeOperations = /* @__PURE__ */ new Set([
31907
31934
  "stores.list",
31908
31935
  "stores.readByRef",
31936
+ "cliSessions.list",
31909
31937
  "userPreferences.read",
31910
31938
  "files.listDirectory",
31911
31939
  "files.listDirectoryByRef",
@@ -32027,6 +32055,12 @@ var createStoreClient = ({
32027
32055
  scanSkills: (input) => call("skills.scan", () => trpc.skills.scan.query(input)),
32028
32056
  listSkillFolders: (input) => call("skills.folders", () => trpc.skills.folders.query(input)),
32029
32057
  readSkill: (input) => call("skills.read", () => trpc.skills.read.query(input)),
32058
+ listCliSessions: () => call("cliSessions.list", () => trpc.cliSessions.list.query({})),
32059
+ revokeCliSession: (input) => call("cliSessions.revoke", () => trpc.cliSessions.revoke.mutate(input)),
32060
+ revokeCurrentCliSession: () => call(
32061
+ "cliSessions.revokeCurrent",
32062
+ () => trpc.cliSessions.revokeCurrent.mutate({})
32063
+ ),
32030
32064
  readUserPreferences: () => call("userPreferences.read", () => trpc.userPreferences.read.query({})),
32031
32065
  readPublicEncryptionKeys: (input) => call(
32032
32066
  "userPreferences.readPublicEncryptionKeys",
@@ -32414,6 +32448,98 @@ var readConfig = async (stateDir) => {
32414
32448
  };
32415
32449
  };
32416
32450
 
32451
+ // src/authSessions/describeLogoutOutcome.ts
32452
+ var describeLogoutOutcome = (outcome) => {
32453
+ if (outcome.kind === "no-credential") {
32454
+ return ["Logged out. No local CLI credential was stored."];
32455
+ }
32456
+ if (outcome.kind === "revoked") {
32457
+ return ["Logged out. CLI session revoked and local credential removed."];
32458
+ }
32459
+ if (outcome.kind === "already-invalid") {
32460
+ return [
32461
+ "Logged out. Local CLI credential removed.",
32462
+ "The server had already ended this session (revoked or expired)."
32463
+ ];
32464
+ }
32465
+ return [
32466
+ "Logged out locally. Local CLI credential removed.",
32467
+ `Could not revoke the session on the server: ${outcome.reason}`,
32468
+ "Anyone holding a copy of the token can use it until it expires. Revoke it with `fm auth sessions` and `fm auth revoke <sessionId>` from another login."
32469
+ ];
32470
+ };
32471
+
32472
+ // src/authSessions/formatCliSessionRows.ts
32473
+ var formatTimestamp = (value) => value ? value.replace("T", " ").replace(/\.\d+Z$/, "Z") : "never";
32474
+ var formatCliSessionRows = (sessions) => [
32475
+ ["SESSION", "CLIENT", "WORKSPACE", "CREATED", "LAST USED", "EXPIRES"],
32476
+ ...sessions.map((session) => [
32477
+ `${session.id}${session.isCurrent ? " (this CLI)" : ""}`,
32478
+ session.clientLabel ?? "-",
32479
+ session.workspaceId,
32480
+ formatTimestamp(session.createdAt),
32481
+ formatTimestamp(session.lastUsedAt),
32482
+ formatTimestamp(session.expiresAt)
32483
+ ])
32484
+ ];
32485
+
32486
+ // src/authSessions/readTrpcErrorCode.ts
32487
+ var isObject4 = (value) => Boolean(value) && typeof value === "object";
32488
+ var readTrpcErrorCode = (error51) => {
32489
+ let current = error51;
32490
+ for (let depth = 0; depth < 5 && isObject4(current); depth += 1) {
32491
+ const data = current.data;
32492
+ if (isObject4(data) && typeof data.code === "string") {
32493
+ return data.code;
32494
+ }
32495
+ current = current.cause;
32496
+ }
32497
+ return null;
32498
+ };
32499
+
32500
+ // src/authSessions/logoutCliSession.ts
32501
+ var defaultRemoteTimeoutMs = 1e4;
32502
+ var withTimeout = async (operation, timeoutMs) => {
32503
+ let timer;
32504
+ try {
32505
+ await Promise.race([
32506
+ operation,
32507
+ new Promise((_, reject) => {
32508
+ timer = setTimeout(
32509
+ () => reject(new Error(`timed out after ${timeoutMs}ms`)),
32510
+ timeoutMs
32511
+ );
32512
+ })
32513
+ ]);
32514
+ } finally {
32515
+ clearTimeout(timer);
32516
+ }
32517
+ };
32518
+ var logoutCliSession = async ({
32519
+ clearLocalCredential,
32520
+ hasStoredCredential,
32521
+ remoteTimeoutMs = defaultRemoteTimeoutMs,
32522
+ revokeCurrentSession
32523
+ }) => {
32524
+ if (!hasStoredCredential) {
32525
+ await clearLocalCredential();
32526
+ return { kind: "no-credential" };
32527
+ }
32528
+ let outcome;
32529
+ try {
32530
+ await withTimeout(revokeCurrentSession(), remoteTimeoutMs);
32531
+ outcome = { kind: "revoked" };
32532
+ } catch (error51) {
32533
+ outcome = readTrpcErrorCode(error51) === "UNAUTHORIZED" ? { kind: "already-invalid" } : {
32534
+ kind: "remote-failed",
32535
+ reason: error51 instanceof Error ? error51.message : String(error51)
32536
+ };
32537
+ } finally {
32538
+ await clearLocalCredential();
32539
+ }
32540
+ return outcome;
32541
+ };
32542
+
32417
32543
  // src/credentials/removePrivateFile.ts
32418
32544
  import { rm as rm5 } from "fs/promises";
32419
32545
  var removePrivateFile = async (filePath) => {
@@ -34143,6 +34269,8 @@ Usage:
34143
34269
 
34144
34270
  Auth, config:
34145
34271
  fm auth login|logout|status [--no-open]
34272
+ fm auth sessions list your active CLI sessions
34273
+ fm auth revoke <sessionId> revoke one of your CLI sessions
34146
34274
  fm config show [--state-dir <path>]
34147
34275
  fm config get <key> [--reveal] [--state-dir <path>]
34148
34276
  fm config set <key> <value> [--state-dir <path>]
@@ -38783,8 +38911,19 @@ var main = async (argv = process.argv.slice(2)) => {
38783
38911
  return;
38784
38912
  }
38785
38913
  if (subcommand === "logout") {
38786
- await deleteStoredToken(parsed.stateDir);
38787
- renderOutput("Logged out. Local CLI credential removed.");
38914
+ const storedToken = await readStoredToken(parsed.stateDir);
38915
+ const outcome = await withActivity(
38916
+ "Logging out",
38917
+ () => logoutCliSession({
38918
+ clearLocalCredential: () => deleteStoredToken(parsed.stateDir),
38919
+ hasStoredCredential: storedToken !== null,
38920
+ revokeCurrentSession: () => createClient({
38921
+ apiBaseUrl: ensureApiBaseUrl(config3.apiBaseUrl),
38922
+ token: storedToken
38923
+ }).revokeCurrentCliSession()
38924
+ })
38925
+ );
38926
+ describeLogoutOutcome(outcome).forEach((line) => renderOutput(line));
38788
38927
  if (process.env.DOCTRINE_TOKEN) {
38789
38928
  renderOutput("DOCTRINE_TOKEN is still set in this environment.");
38790
38929
  }
@@ -38794,7 +38933,29 @@ var main = async (argv = process.argv.slice(2)) => {
38794
38933
  renderOutput(config3.token ? "Authenticated" : "Not authenticated");
38795
38934
  return;
38796
38935
  }
38797
- throw new Error(`Usage: ${commandNames} auth login|logout|status`);
38936
+ if (subcommand === "sessions") {
38937
+ const sessions = await createClient(config3).listCliSessions();
38938
+ if (parsed.json) {
38939
+ renderOutput(sessions);
38940
+ return;
38941
+ }
38942
+ renderOutput(
38943
+ sessions.length === 0 ? "No active CLI sessions." : styleText.table(formatCliSessionRows(sessions))
38944
+ );
38945
+ return;
38946
+ }
38947
+ if (subcommand === "revoke") {
38948
+ const sessionId = rest[1]?.trim();
38949
+ if (!sessionId || rest.length > 2) {
38950
+ throw new Error(`Usage: ${commandNames} auth revoke <sessionId>`);
38951
+ }
38952
+ await createClient(config3).revokeCliSession({ sessionId });
38953
+ renderOutput(`Revoked CLI session ${sessionId}.`);
38954
+ return;
38955
+ }
38956
+ throw new Error(
38957
+ `Usage: ${commandNames} auth login|logout|status|sessions|revoke`
38958
+ );
38798
38959
  }
38799
38960
  if (command === "config") {
38800
38961
  const subcommand = rest[0];