deepsource-mcp-server
Version:
Model Context Protocol server for DeepSource
120 lines (119 loc) • 4.61 kB
TypeScript
/**
* @fileoverview Base client for interacting with the DeepSource API
* This module provides a base client class with core functionality.
*/
import { AxiosInstance } from 'axios';
import { GraphQLResponse } from '../types/graphql-responses.js';
import { DeepSourceProject } from '../models/projects.js';
import { PaginatedResponse, PaginationParams } from '../utils/pagination/types.js';
/**
* Configuration options for the DeepSource client
* @public
*/
export interface DeepSourceClientConfig {
/** The base URL for the API */
baseURL?: string;
/** Request timeout in milliseconds */
timeout?: number;
/** Custom headers to include in requests */
headers?: Record<string, string>;
}
/**
* Base client for DeepSource API with core HTTP functionality
* @class
* @public
*/
export declare class BaseDeepSourceClient {
/**
* HTTP client for making API requests to DeepSource
* @protected
*/
protected client: AxiosInstance;
/**
* Logger instance for the client
* @protected
*/
protected logger: import("../utils/logging/logger.js").Logger;
/**
* Creates a new BaseDeepSourceClient instance
* @param apiKey - The DeepSource API key for authentication
* @param config - Optional configuration options
* @throws {Error} When apiKey is not provided
* @public
*/
constructor(apiKey: string, config?: DeepSourceClientConfig);
/**
* Execute a GraphQL query with variables against the DeepSource API
* @param query The GraphQL query to execute
* @param variables The variables for the query
* @returns The query response data
* @throws {ClassifiedError} When the query fails
* @protected
*/
protected executeGraphQL<T>(query: string, variables?: Record<string, unknown>): Promise<GraphQLResponse<T>>;
/**
* Execute a GraphQL query with automatic retry logic
* @param query The GraphQL query to execute
* @param variables The variables for the query
* @param endpoint The endpoint name for retry policy selection
* @returns The query response data
* @throws {ClassifiedError} When the query fails after all retries
* @protected
*/
protected executeGraphQLWithRetry<T>(query: string, variables?: Record<string, unknown>, endpoint?: string): Promise<GraphQLResponse<T>>;
/**
* Type guard to check if an error is an Axios error
* @param error The error to check
* @returns True if it's an Axios error
* @private
*/
private static isAxiosError;
/**
* Execute a GraphQL mutation against the DeepSource API
* @param mutation The GraphQL mutation to execute
* @param variables The variables for the mutation
* @returns The mutation response data
* @throws {ClassifiedError} When the mutation fails
* @protected
*/
protected executeGraphQLMutation<T>(mutation: string, variables?: Record<string, unknown>): Promise<T>;
/**
* Finds a project by its key using a simplified projects query
* @param projectKey The project key to find
* @returns The project if found, null otherwise
* @protected
*/
protected findProjectByKey(projectKey: string): Promise<DeepSourceProject | null>;
/**
* Normalizes pagination parameters to ensure they're valid
* @param params The pagination parameters to normalize
* @returns Normalized pagination parameters
* @protected
*/
protected static normalizePaginationParams(params: PaginationParams): PaginationParams;
/**
* Creates an empty paginated response
* @returns An empty paginated response
* @protected
*/
protected static createEmptyPaginatedResponse<T>(): PaginatedResponse<T>;
/**
* Extracts error messages from GraphQL errors array
* @param errors Array of GraphQL errors
* @returns Combined error message string
* @protected
*/
protected static extractErrorMessages(errors: Array<{
message: string;
}>): string;
/**
* Fetches data with automatic pagination support
* Handles multi-page fetching when max_pages is specified
* @template T The type of items being fetched
* @param fetcher Single page fetcher function
* @param params Pagination parameters including potential max_pages
* @returns Paginated response with all fetched items
* @protected
*/
protected fetchWithPagination<T>(fetcher: (params: PaginationParams) => Promise<PaginatedResponse<T>>, params: PaginationParams): Promise<PaginatedResponse<T>>;
}