/** * The request core that endpoint wrappers build on. It sends a request * through the host's transport, turns network failures and error responses * into the shared errors, and reads JSON bodies. `@sentry/api` operations * get a client that sends through the same path, and {@link listPage} walks * their pages. * * The host supplies the transport (retries, caching), the per-request * headers (credentials, user agent, attribution), and logging. */ import { type SentryClient } from "@sentry/api"; import { type ResponseSchema } from "./validate.js"; /** What the core needs from the host's transport. */ export type ApiRequestTransport = { request(url: string, init: RequestInit): Promise; }; export type ApiClientLogger = { warn(message: string, extra: Record): void; }; export type ApiClientCoreOptions = { transport: ApiRequestTransport; /** * Headers for every request after `Content-Type`, such as Authorization * and User-Agent. Called once per request; may throw for a bad credential. * They replace any headers the caller passes. */ headers: () => Record; logger: ApiClientLogger; }; export type ApiRequestOptions = { /** Error statuses returned as the response instead of thrown. */ allowStatuses?: number[]; }; export type ApiClientCore = { /** * Send a request to `origin` + {@link API_BASE_PATH} + `path`. * * @throws {ApiError} For an error status not in `allowStatuses` * @throws {ConfigurationError} When the host is unreachable or misconfigured * @throws {Error} For other network failures, with a readable message */ request(origin: string, path: string, init?: RequestInit, options?: ApiRequestOptions): Promise; /** {@link ApiClientCore.request}, then the parsed JSON body. */ requestJson(origin: string, path: string, init?: RequestInit): Promise; /** * A `@sentry/api` client for one GET to `expectedPath` on `origin`. The * operation builds the path and query; the request goes through * {@link ApiClientCore.request}. Any other target or method throws. */ sdkClient(origin: string, expectedPath: string): SentryClient["client"]; }; /** Where an endpoint wrapper sends: the core, and the region or host origin. */ export type ApiTarget = { core: ApiClientCore; origin: string; }; /** Most pages {@link listPage} fetches for one call. */ export declare const MAX_LIST_PAGES = 50; /** Rows from {@link listPage}, and the cursor for the next call. */ export type ListPage = { items: T[]; nextCursor: string | null; }; /** The cursor of the next page in a list response's `Link` header, if any. */ export declare function nextPageCursor(response: Response): string | null; export declare function createApiClientCore({ transport, headers, logger, }: ApiClientCoreOptions): ApiClientCore; /** * Fetch up to `limit` rows from a list endpoint, starting at `cursor`. * * Walks pages with {@link paginate}, so every request in a walk uses the same * `per_page`: a fresh walk splits `limit` evenly, and a page-number cursor * (`OffsetPaginator`) keeps the page size it encodes. Each page is validated * with `schema`. The walk stops once it has `limit` rows, the server has no * next page, or it has fetched {@link MAX_LIST_PAGES} pages, and returns a * cursor that resumes at the first row not returned. * * @throws {ApiValidationError} When `limit` is not between 1 and * `API_MAX_PER_PAGE * MAX_LIST_PAGES` * @throws {ApiResponseValidationError} When a page does not match `schema` * @throws {Error} When a page has more rows than requested or a cursor repeats */ export declare function listPage(fetchPage: (perPage: number, cursor: string | undefined) => Promise<{ data: unknown; response: Response; }>, schema: ResponseSchema, limit: number, initialCursor?: string | null): Promise>;