/** * Authenticated HTTP client for the JSM Operations REST API. * * Auth precedence: * 1. JSM_OAUTH_TOKEN -> Authorization: Bearer (3LO / Forge app tokens) * 2. JSM_EMAIL + JSM_API_TOKEN -> HTTP Basic (Atlassian account API token) * * Both are scoped by JSM_CLOUD_ID, which identifies the Atlassian site. */ import type { Paged } from "../types.js"; export interface JsmConfig { cloudId: string; email?: string | undefined; apiToken?: string | undefined; oauthToken?: string | undefined; } /** Thrown for auth/config problems detected before any network call. */ export declare class JsmConfigError extends Error { } /** What `request` accepts. Extracted so the signal is documented in one place. */ export interface RequestOptions { params?: Record | undefined; body?: unknown; /** Aborts the request. See the note on `request`. */ signal?: AbortSignal | undefined; } /** * Reads configuration from the environment and fails loudly if the server * cannot possibly authenticate. Called once at startup so misconfiguration * surfaces immediately rather than on the first tool call. */ export declare function loadConfig(env?: NodeJS.ProcessEnv): JsmConfig; export declare class JsmClient { private readonly http; /** * Second instance for the Jira platform API, which lives behind a different * gateway path than JSM Operations but takes the same credentials and the * same cloudId. Used only to resolve account ids to display names. */ private readonly jira; constructor(config: JsmConfig); /** * Issues a request and returns the raw response body. * Query params with `undefined` values are dropped by axios automatically. * * `signal` is how a caller with a shorter deadline than REQUEST_TIMEOUT_MS * imposes it. Code mode needs this: an invocation gets ten seconds and this * client waits thirty, so without the signal one slow request would keep * running for twenty seconds after the call that wanted it had already * failed its deadline. Optional, so every existing call site is unchanged. */ request(method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", path: string, options?: RequestOptions): Promise; /** * Issues a GET for a collection endpoint and normalises the envelope. * * The JSM Ops API returns collections under `data` on Opsgenie-derived * endpoints and under `values` on newer ones. Rather than guess per * endpoint, accept both and expose a single shape to the tools. */ getCollection(path: string, params?: Record, options?: { itemsKey?: string | undefined; signal?: AbortSignal | undefined; }): Promise>; /** * GET against the Jira platform API rather than JSM Operations. * * Deliberately does no envelope unwrapping: the Jira API has its own * conventions and callers here want the body as-is. */ jiraGet(path: string, params?: Record, options?: { signal?: AbortSignal | undefined; }): Promise; /** GET for endpoints returning a single object under `data`/`values`. */ getOne(path: string, params?: Record, options?: { signal?: AbortSignal | undefined; }): Promise; } /** * Strips the `data`/`values` envelope from a single-object response. * * Exported because reads are not the only callers: POST /v1/users/contacts and * the PATCH, activate and deactivate endpoints beside it answer * `{message, data}`, so a write that reported the body verbatim while its * sibling get unwrapped it handed the model the envelope where it expected the * contact — the id came back undefined and the object could not be read back. * A get and its sibling write disagreeing about the envelope is the bug; one * definition here is what keeps them from drifting apart again. */ export declare function unwrapEnvelope(raw: unknown): T; /** * What was being called, so an auth failure can name the scope that endpoint * actually needs instead of reciting the same alert-shaped advice everywhere. */ export interface ErrorHints { method?: string | undefined; /** Path below the cloud-id root, e.g. "/v1/alerts/{id}/tags". */ path?: string | undefined; } /** * Converts any thrown error into a message that tells the agent what to do * next, not just what went wrong. * * `hints` carries the method and path so the scope advice can be specific. * Without it the advice stays generic rather than guessing — an earlier version * hardcoded alert-shaped advice into every 401, 403 and 404, which meant a * failing attachment read was answered with a lecture about on-call schedules * and an instruction to check working credentials. */ export declare function handleApiError(error: unknown, context: string, hints?: ErrorHints): string; //# sourceMappingURL=client.d.ts.map