import { Agent } from 'http'; import { Response as FetchResponse } from 'node-fetch'; /** * @description HTTP methods supported by the API */ export type RequestMethod = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT'; /** * @description Represents a complete API request with its endpoint and parameters */ export type Request = { readonly requestLine: ReqLine; readonly parameters: Params; }; /** * @description Represents an API endpoint in the format "METHOD /path" * e.g., "GET /products" or "POST /orders" */ export type RequestLine = `${RequestMethod} ${string}`; /** * @description Represents all possible parameter types that can be sent with a request: */ export type Parameters = { /** * @description URL path parameters (e.g., /products/{id}) */ readonly path?: Record; /** * @description URL query parameters */ readonly query?: any; /** * @description Request body data */ readonly body?: any; /** * @description Custom HTTP headers */ readonly header?: Record; }; /** * @description Represents an API response with status code and optional body */ export type Response = { readonly status: number | string; readonly body?: any; }; export declare namespace Response { type SuccessStatus = 200 | 201 | 204; /** * @description Extracts and formats the possible success responses for an operation */ export type Success = T extends Operation ? Success : T extends { status: SuccessStatus; } ? T : never; export {}; } /** * @description Represents a complete API operation with its parameters and expected response */ export type Operation = { readonly parameters: Request['parameters']; readonly response: Response; }; export declare namespace Operation { /** * @description Extracts the minimal required input parameters for an operation */ export type MinimalInput = InputParameters; /** * @description Makes properties optional if they're on the 'query' object */ type MakeQueryParamsOptional = K extends 'query' ? Partial : OpParams[K]; /** * @description Makes properties optional if they can be empty objects */ type MakeEmptyObjectOptional = { readonly [K in keyof T as {} extends T[K] ? K : never]?: T[K]; } & { readonly [K in keyof T as {} extends T[K] ? never : K]: T[K]; }; /** * @description Prepares request parameters by making query params and any possibly empty params optional */ type InputParameters = MakeEmptyObjectOptional<{ [K in keyof OpParams]: MakeQueryParamsOptional; }>; export {}; } /** * @description Maps request lines to their corresponding operations */ export type OperationIndex = Record; export declare namespace OperationIndex { /** * @description Filters operations to only include those with optional parameters */ type FilterOptionalParams = { [K in keyof Ops as {} extends Ops[K]['parameters'] ? K : never]: Ops[K]; }; } /** * @description Resolves the path for a request * @example * ```ts * resolvePath('/products/{id}', { id: 123 }) * // returns '/products/123' * ``` */ export declare function resolvePath(parameterizedPath: string, pathParams: Record): string; /** * @description Transport function type that handles making the actual API requests */ export type Transport = (requestLine: string, params?: Parameters) => Promise; /** * @description Configuration options for the fetch-based transport */ export type FetchTransportOptions = { readonly baseUrl: string; readonly headers: Record; readonly agent?: Agent | undefined; readonly retry?: boolean | { /** * Return true if the request should be retried, false otherwise */ readonly shouldRetry?: (attemptNum: number, response: FetchResponse, requestLine: string) => boolean; /** * Return the backoff time in ms */ readonly backoffTime?: (numFailures: number, response: FetchResponse, requestLine: string) => number; }; }; /** * @description Creates a fetch transport function * @example * ```ts * const transport = fetchTransport({ * baseUrl: 'https://api.bigcommerce.com/stores/1234567890/v3', * headers: { * 'X-Auth-Token': '1234567890', * }, * }); * ``` * @param options - The options for the fetch transport * @returns */ export declare function fetchTransport(options: FetchTransportOptions): Transport;