import { CommandArgument, CommandResult } from '../../utils/types.js'; import { BaseCLICommand } from './baseCommand.js'; /** One stored auth profile, as the SDK's credential API reports it (no secrets). */ export interface AuthProfile { alias: string; host?: string; type?: string; isDefault: boolean; } /** * The child script that reads the profile store through the SDK's own API. * * `now-sdk auth --list` prints aliases and field values unescaped, so a newline * in an alias or username can forge a profile header; no text parser can tell * those apart. This calls sdk-cli `fetchCredentials()`, the function `auth --list` * prints from, and writes one JSON envelope line instead. `fetchCredentials()` * returns previews only (alias, instanceUrl, type, isDefault, username), and * the script forwards no username. It runs in a child, not in this process, * because the SDK logger writes to stdout, which is the MCP stdio channel here; * in the child the logger is moved to stderr, so stdout carries only the * envelope (plus an `LOG_LEVEL` notice the logger prints while loading, which * `parseCliEnvelope` skips by reading the last line). * * `process.argv[1]` is the bundled `@servicenow/sdk` bin path: resolving from it * finds the same `@servicenow/sdk-cli` that `now-sdk` itself loads. sdk-cli has * no `exports` map, so its `dist/` paths resolve; if a future SDK adds one, the * read fails closed with the resolution error. * * A non-TTY stdout makes the SDK throw instead of prompting for a reset of an * unreadable store, and the thrown message is the one `auth --list` would log, * so the credential-store recovery rules match it unchanged. The script exits * once the envelope is flushed, so a handle the SDK leaves open (keyring, * timers) cannot hold the child until the runner's timeout. */ export declare const LIST_PROFILES_SCRIPT = "'use strict';\nconst reply = (envelope, code) => process.stdout.write(JSON.stringify(envelope) + '\\n', () => process.exit(code));\n(async () => {\n const sdkRequire = require('node:module').createRequire(process.argv[1]);\n sdkRequire('@servicenow/sdk-cli/dist/logger/index.js').logger.setStream('stderr');\n const { fetchCredentials } = sdkRequire('@servicenow/sdk-cli/dist/auth/index.js');\n const profiles = [];\n for (const [alias, creds] of await fetchCredentials()) {\n profiles.push({ alias, host: creds.instanceUrl, type: creds.type, isDefault: creds.isDefault === true });\n }\n reply({ ok: true, profiles }, 0);\n})().catch((e) => {\n const message = e instanceof Error\n ? (e.cause instanceof Error ? e.message + '\\n Caused by: ' + e.cause.message : e.message)\n : String(e);\n reply({ ok: false, error: { message } }, 1);\n});"; /** * The profiles in a successful {@link LIST_PROFILES_SCRIPT} run, or `undefined` * when the output is not a well-formed `ok: true` envelope. Any malformed entry * rejects the whole listing, so a partial read is never used. */ export declare function parseAuthProfiles(output: string): AuthProfile[] | undefined; /** * Reads the SDK's stored auth profiles for lazy auth validation (see * {@link LIST_PROFILES_SCRIPT}). Internal: not exposed to MCP clients. * * Deliberately read-only. The profile store and its default profile are global * state that every `now-sdk` run on the machine shares: `auth --add` always makes * the new profile the default (sdk-cli `storeCredentials(alias, cred, true)`), * and setting the previous default back cannot be made safe. A failure between * the two writes skips it, and two validations that overlap restore the wrong * default (W9 review). So the server never adds, deletes or selects a profile; * the user does that in a terminal. */ export declare class AuthCommand extends BaseCLICommand { name: string; description: string; arguments: CommandArgument[]; execute(args?: Record): Promise; } //# sourceMappingURL=authCommand.d.ts.map