UNPKG

@mcp-abap-adt/connection

Version:

ABAP connection layer for MCP ABAP ADT server

86 lines 3.33 kB
import { type AxiosResponse } from 'axios'; import type { SapConfig } from '../config/sapConfig.js'; import type { ILogger } from '../logger.js'; import type { AbapConnection, AbapRequestOptions } from './AbapConnection.js'; declare abstract class AbstractAbapConnection implements AbapConnection { private readonly config; protected readonly logger: ILogger | null; private axiosInstance; private csrfToken; private cookies; private cookieStore; private baseUrl; private sessionId; private sessionMode; protected constructor(config: SapConfig, logger: ILogger | null, sessionId?: string); /** * Set session type (stateful or stateless) * Controls whether x-sap-adt-sessiontype: stateful header is added to requests * - stateful: SAP maintains session state between requests (locks, transactions) * - stateless: Each request is independent */ setSessionType(type: 'stateful' | 'stateless'): void; /** * Enable stateful session mode (tells SAP to maintain stateful session) * This controls whether x-sap-adt-sessiontype: stateful header is used * @deprecated Use setSessionType("stateful") instead */ enableStatefulSession(): void; /** * Disable stateful session mode (switch to stateless) * @deprecated Use setSessionType("stateless") instead */ disableStatefulSession(): void; /** * Get current session mode */ getSessionMode(): 'stateless' | 'stateful'; /** * Set session ID * @deprecated Session ID is auto-generated, use setSessionType() to control session mode */ setSessionId(sessionId: string): void; /** * Get current session ID */ getSessionId(): string | null; getConfig(): SapConfig; reset(): void; getBaseUrl(): Promise<string>; getAuthHeaders(): Promise<Record<string, string>>; /** * Connect to SAP system and initialize session (get CSRF token and cookies) * This should be called explicitly before making the first request to ensure * proper authentication and session initialization. * * Concrete implementations must provide auth-specific connection logic: * - BaseAbapConnection: Basic auth with CSRF token fetch * - JwtAbapConnection: JWT auth with token refresh on 401/403 */ abstract connect(): Promise<void>; makeAdtRequest(options: AbapRequestOptions): Promise<AxiosResponse>; protected abstract buildAuthorizationHeader(): string; /** * Fetch CSRF token from SAP system * Protected method for use by concrete implementations in their connect() method */ protected fetchCsrfToken(url: string, retryCount?: number, retryDelay?: number): Promise<string>; /** * Get CSRF token (protected for use by subclasses) */ protected getCsrfToken(): string | null; /** * Set CSRF token (protected for use by subclasses) */ protected setCsrfToken(token: string | null): void; /** * Get cookies (protected for use by subclasses) */ protected getCookies(): string | null; private updateCookiesFromResponse; private getAxiosInstance; private ensureFreshCsrfToken; private shouldRetryCsrf; } export { AbstractAbapConnection }; //# sourceMappingURL=AbstractAbapConnection.d.ts.map