{"version":3,"sources":["../src/cli/commands/logout-device.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport {\n  loadConfig,\n  clearConfig,\n  isLoggedIn,\n} from \"@/cli/utils/governance/config\";\nimport { logout as serverRevokeLogout, DeviceFlowError } from \"@/cli/utils/governance/device-flow\";\n\n/**\n * `langwatch logout --device` — server-revoke the refresh token\n * AND clear the local config. Best-effort: if the server call\n * fails (network down, 5xx), the local clear still happens —\n * otherwise \"logout\" leaves a usable token on disk and the user\n * has to remember to delete the file manually.\n *\n * Idempotent: safe to run when not logged in.\n *\n * The bare `langwatch logout` (no flag) is reserved by the existing\n * API-key flow; this is namespaced under `--device` to avoid\n * regressing the existing CLI surface.\n */\nexport const logoutDeviceCommand = async (): Promise<void> => {\n  const cfg = loadConfig();\n  if (!isLoggedIn(cfg)) {\n    clearConfig();\n    console.log(\"Not logged in. Local config cleared (idempotent).\");\n    return;\n  }\n\n  if (cfg.refresh_token) {\n    try {\n      // Send both tokens so the access_token is invalidated\n      // immediately (Sergey's e7a042c69 closes the 1h-survival gap).\n      await serverRevokeLogout(\n        { baseUrl: cfg.control_plane_url },\n        cfg.refresh_token,\n        cfg.access_token,\n      );\n    } catch (err) {\n      // Server-side revoke failed; we still want to clear locally\n      // per the spec (\"local wipe must happen even when remote\n      // revoke fails — otherwise leaves a usable token on disk\").\n      const msg = err instanceof DeviceFlowError ? err.message : String(err);\n      console.error(chalk.yellow(`warning: server-side revoke failed: ${msg}`));\n    }\n  }\n  clearConfig();\n  console.log(\"Logged out — local credentials cleared.\");\n};\n"],"mappings":";;;;;;;;;;;;AAAA,OAAO,WAAW;AAqBX,IAAM,sBAAsB,YAA2B;AAC5D,QAAM,MAAM,WAAW;AACvB,MAAI,CAAC,WAAW,GAAG,GAAG;AACpB,gBAAY;AACZ,YAAQ,IAAI,mDAAmD;AAC/D;AAAA,EACF;AAEA,MAAI,IAAI,eAAe;AACrB,QAAI;AAGF,YAAM;AAAA,QACJ,EAAE,SAAS,IAAI,kBAAkB;AAAA,QACjC,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF,SAAS,KAAK;AAIZ,YAAM,MAAM,eAAe,kBAAkB,IAAI,UAAU,OAAO,GAAG;AACrE,cAAQ,MAAM,MAAM,OAAO,uCAAuC,GAAG,EAAE,CAAC;AAAA,IAC1E;AAAA,EACF;AACA,cAAY;AACZ,UAAQ,IAAI,8CAAyC;AACvD;","names":[]}