/** * Main HTTP client for the CommonGrants API. */ import { type ClientConfig, type ResolvedConfig } from "./config"; import { type AuthMethod } from "./auth"; import { Opportunities } from "./resources/opportunities"; import { type OnParseError, type ParseFailure } from "./results"; import type { Paginated } from "../types"; import type { z } from "zod"; /** Options for GET requests */ export interface GetOptions { /** Query parameters to append to the URL */ params?: Record; /** Abort signal for cancellation */ signal?: AbortSignal; } /** Options for POST requests */ export interface PostOptions { /** Abort signal for cancellation */ signal?: AbortSignal; } /** Options for the fetchMany auto-pagination method. */ export interface FetchManyOptions { /** Starting page number (default: 1) */ page?: number; /** Items per page (uses client default if not specified) */ pageSize?: number; /** Maximum total items to fetch (uses client default if not specified) */ maxItems?: number; /** Abort signal for cancellation */ signal?: AbortSignal; /** HTTP method (default: "GET") */ method?: "GET" | "POST"; /** Request body for POST requests (pagination will be merged in) */ body?: Record; /** Schema to parse/validate each item (any object with a `.safeParse()` method, e.g. a Zod schema) */ schema?: { safeParse: (data: unknown) => z.ZodSafeParseResult; }; /** Row-parse failure handling: partition into `errors` (default) or throw on first failure */ onParseError?: OnParseError; } /** * HTTP client for interacting with the CommonGrants API. * * @example * ```ts * import { Client, Auth } from "@common-grants/sdk/client"; * * const client = new Client({ * baseUrl: "https://api.example.org", * auth: Auth.bearer("your-token"), * }); * * // Get an opportunity * const opp = await client.opportunities.get("opp-123"); * console.log(opp.title); * * // List opportunities * const list = await client.opportunities.list({ page: 1 }); * ``` */ export declare class Client { private readonly config; private readonly auth; /** Opportunities resource namespace (base schema; plugin-typed via plugin.getClient()) */ readonly opportunities: Opportunities; constructor(options: ClientConfig & { auth?: AuthMethod; }); /** * Makes an authenticated fetch request to the API. * This is the lowest-level method - use `get()` or `post()` for convenience. * * @param path - API path (will be appended to baseUrl) * @param init - Fetch init options * @returns Fetch Response * * @example * ```ts * const response = await client.fetch("/common-grants/opportunities", { * method: "DELETE", * }); * ``` */ fetch(path: string, init?: RequestInit): Promise; /** * Makes an authenticated GET request to the API. * * @param path - API path (will be appended to baseUrl) * @param options - GET request options * @returns Fetch Response * * @example * ```ts * const response = await client.get("/common-grants/opportunities", { * params: { page: 1, pageSize: 10 } * }); * const data = await response.json(); * ``` */ get(path: string, options?: GetOptions): Promise; /** * Makes an authenticated POST request to the API. * * @param path - API path (will be appended to baseUrl) * @param body - Request body (will be JSON stringified) * @param options - POST request options * @returns Fetch Response * * @example * ```ts * const response = await client.post("/common-grants/opportunities/search", { * filters: { status: "open" }, * pagination: { page: 1, pageSize: 10 } * }); * const data = await response.json(); * ``` */ post(path: string, body: unknown, options?: PostOptions): Promise; /** * Makes an authenticated PUT request to the API. * * @param path - API path (will be appended to baseUrl) * @param body - Request body (will be JSON stringified) * @param options - Request options * @returns Fetch Response */ put(path: string, body: unknown, options?: PostOptions): Promise; /** * Makes an authenticated PATCH request to the API. * * @param path - API path (will be appended to baseUrl) * @param body - Request body (will be JSON stringified) * @param options - Request options * @returns Fetch Response */ patch(path: string, body: unknown, options?: PostOptions): Promise; /** * Fetches all items from a paginated endpoint with auto-pagination. * * @param path - API path (will be appended to baseUrl) * @param options - Pagination options * @returns All items aggregated from paginated responses * * @example * ```ts * // GET with auto-pagination * const result = await client.fetchMany("/common-grants/opportunities"); * * // POST with auto-pagination (for search endpoints) * const searched = await client.fetchMany("/common-grants/opportunities/search", { * method: "POST", * body: { filters: { status: "open" } } * }); * ``` */ fetchMany(path: string, options?: FetchManyOptions): Promise & { errors: ParseFailure[]; }>; /** * Fetches a single page from a paginated endpoint and returns the parsed * items plus metadata needed to drive fetchMany's aggregation loop. */ private fetchOnePage; /** Constructs the full URL for an API path. */ private url; /** Gets the resolved client configuration. */ getConfig(): ResolvedConfig; } //# sourceMappingURL=client.d.ts.map