/**
* WordPress API Client
* Handles all REST API communication with WordPress
*
* This module has been refactored to use a modular architecture with
* domain-specific operations extracted into separate modules under ./operations/
*/
import type { IWordPressClient, WordPressClientConfig, AuthConfig, HTTPMethod, RequestOptions, ClientStats, RawResponse } from "../types/client.js";
import type { WordPressPost, WordPressPage, WordPressMedia, WordPressUser, WordPressComment, WordPressCategory, WordPressTag, WordPressSiteSettings, WordPressApplicationPassword, PostQueryParams, MediaQueryParams, UserQueryParams, CommentQueryParams, CreatePostRequest, UpdatePostRequest, CreatePageRequest, UpdatePageRequest, CreateUserRequest, UpdateUserRequest, CreateCommentRequest, UpdateCommentRequest, CreateCategoryRequest, UpdateCategoryRequest, CreateTagRequest, UpdateTagRequest, UploadMediaRequest, UpdateMediaRequest, WordPressSiteInfo, WordPressSearchResult } from "../types/wordpress.js";
/**
* WordPress REST API Client
*
* A comprehensive client for interacting with the WordPress REST API v2.
* Provides full CRUD operations for posts, pages, media, users, comments,
* categories, tags, and site settings with robust error handling and performance optimization.
*
* Features:
* - Multiple authentication methods (App Passwords, JWT, Basic Auth, API Key)
* - Automatic retry logic with exponential backoff
* - Request rate limiting and queue management
* - Comprehensive error handling with detailed messages
* - Performance monitoring and request statistics
* - Caching support for improved performance
* - Multi-site configuration support
* - Modular architecture with domain-specific operations
*
* @example
* ```typescript
* // Initialize with app password authentication
* const client = new WordPressClient({
* baseUrl: 'https://mysite.com',
* auth: {
* method: 'app-password',
* username: 'admin',
* password: 'xxxx xxxx xxxx xxxx xxxx xxxx'
* }
* });
*
* // Create a new post
* const post = await client.createPost({
* title: 'My New Post',
* content: '
This is the content
',
* status: 'publish'
* });
*
* // List posts with filtering
* const posts = await client.getPosts({
* search: 'WordPress',
* status: 'publish',
* per_page: 10
* });
* ```
*
* @since 1.0.0
* @author MCP WordPress Team
* @implements {IWordPressClient}
*/
export declare class WordPressClient implements IWordPressClient {
private baseUrl;
private apiUrl;
private timeout;
private maxRetries;
private auth;
private requestQueue;
private lastRequestTime;
private requestInterval;
private authenticated;
private jwtToken;
private _stats;
private readonly postsOps;
private readonly pagesOps;
private readonly mediaOps;
private readonly usersOps;
private readonly commentsOps;
private readonly taxonomiesOps;
private readonly siteOps;
/**
* Creates a new WordPress API client instance.
*
* Initializes the client with configuration options for connecting to a WordPress site.
* Supports multiple authentication methods and automatic environment variable detection.
*
* @param {Partial} [options={}] - Configuration options for the client
* @param {string} [options.baseUrl] - WordPress site URL (falls back to WORDPRESS_SITE_URL env var)
* @param {number} [options.timeout=30000] - Request timeout in milliseconds
* @param {number} [options.maxRetries=3] - Maximum number of retry attempts for failed requests
* @param {AuthConfig} [options.auth] - Authentication configuration (auto-detected from env if not provided)
* @param {boolean} [options.enableCache=true] - Whether to enable response caching
* @param {number} [options.cacheMaxAge=300000] - Cache max age in milliseconds (5 minutes default)
*
* @throws {Error} When required configuration is missing or invalid
*
* @since 1.0.0
*/
constructor(options?: Partial);
get config(): WordPressClientConfig;
get isAuthenticated(): boolean;
/**
* Replace this client's authentication configuration for the current
* session. Does not itself verify the new credentials — call
* authenticate() afterward to confirm they work.
*/
setAuthConfig(auth: AuthConfig): void;
get stats(): ClientStats;
getSiteUrl(): string;
/**
* Validate and sanitize URL for security
*/
private validateAndSanitizeUrl;
private getAuthFromEnv;
private validateConfig;
initialize(): Promise;
disconnect(): Promise;
/**
* Add authentication headers to request
*/
private addAuthHeaders;
/**
* Rate limiting implementation
*/
private rateLimit;
/**
* Delay utility
*/
private delay;
authenticate(): Promise;
/**
* Authenticate using Basic/Application Password
*/
private authenticateWithBasic;
/**
* Authenticate using JWT
*/
private authenticateWithJWT;
/**
* Authenticate using Cookie
*/
private authenticateWithCookie;
/**
* Make authenticated request to WordPress REST API
*/
request(method: HTTPMethod, endpoint: string, data?: unknown, options?: RequestOptions): Promise;
/**
* Same as request(), but also returns the real HTTP status and response
* headers WordPress sent back — used by the cache layer to preserve
* genuine server-provided validators (ETag, Last-Modified, Cache-Control)
* instead of synthesizing its own.
*/
requestWithMetadata(method: HTTPMethod, endpoint: string, data?: unknown, options?: RequestOptions): Promise>;
private headersToRecord;
private requestRaw;
private attachRequestBody;
private normalizeRequestError;
private shouldRetryError;
private isRetryableBody;
private handleErrorResponseWithFallback;
private tryIndexPhpFallback;
private parseResponse;
private updateAverageResponseTime;
get(endpoint: string, options?: RequestOptions): Promise;
post(endpoint: string, data?: unknown, options?: RequestOptions): Promise;
put(endpoint: string, data?: unknown, options?: RequestOptions): Promise;
patch(endpoint: string, data?: unknown, options?: RequestOptions): Promise;
delete(endpoint: string, options?: RequestOptions): Promise;
getPosts(params?: PostQueryParams): Promise;
getPost(id: number, context?: "view" | "embed" | "edit"): Promise;
createPost(data: CreatePostRequest): Promise;
updatePost(data: UpdatePostRequest): Promise;
deletePost(id: number, force?: boolean): Promise<{
deleted: boolean;
previous?: WordPressPost;
}>;
getPostRevisions(id: number): Promise;
getPages(params?: PostQueryParams): Promise;
getPage(id: number, context?: "view" | "embed" | "edit"): Promise;
createPage(data: CreatePageRequest): Promise;
updatePage(data: UpdatePageRequest): Promise;
deletePage(id: number, force?: boolean): Promise<{
deleted: boolean;
previous?: WordPressPage;
}>;
getPageRevisions(id: number): Promise;
getMedia(params?: MediaQueryParams): Promise;
getMediaItem(id: number, context?: "view" | "embed" | "edit"): Promise;
uploadMedia(data: UploadMediaRequest): Promise;
uploadFile(fileData: Buffer, filename: string, mimeType: string, meta?: Partial, options?: RequestOptions): Promise;
updateMedia(data: UpdateMediaRequest): Promise;
deleteMedia(id: number, force?: boolean): Promise<{
deleted: boolean;
previous?: WordPressMedia;
}>;
getUsers(params?: UserQueryParams): Promise;
getUser(id: number | "me", context?: "view" | "embed" | "edit"): Promise;
createUser(data: CreateUserRequest): Promise;
updateUser(data: UpdateUserRequest): Promise;
deleteUser(id: number, reassign?: number): Promise<{
deleted: boolean;
previous?: WordPressUser;
}>;
getCurrentUser(): Promise;
getComments(params?: CommentQueryParams): Promise;
getComment(id: number, context?: "view" | "embed" | "edit"): Promise;
createComment(data: CreateCommentRequest): Promise;
updateComment(data: UpdateCommentRequest): Promise;
deleteComment(id: number, force?: boolean): Promise<{
deleted: boolean;
previous?: WordPressComment;
}>;
approveComment(id: number): Promise;
rejectComment(id: number): Promise;
spamComment(id: number): Promise;
getCategories(params?: Record): Promise;
getCategory(id: number): Promise;
createCategory(data: CreateCategoryRequest): Promise;
updateCategory(data: UpdateCategoryRequest): Promise;
deleteCategory(id: number, force?: boolean): Promise<{
deleted: boolean;
previous?: WordPressCategory;
}>;
getTags(params?: Record): Promise;
getTag(id: number): Promise;
createTag(data: CreateTagRequest): Promise;
updateTag(data: UpdateTagRequest): Promise;
deleteTag(id: number, force?: boolean): Promise<{
deleted: boolean;
previous?: WordPressTag;
}>;
getSiteSettings(): Promise;
updateSiteSettings(settings: Partial): Promise;
getSiteInfo(): Promise;
getApplicationPasswords(userId?: number | "me"): Promise;
createApplicationPassword(userId: number | "me", name: string, appId?: string): Promise;
deleteApplicationPassword(userId: number | "me", uuid: string): Promise<{
deleted: boolean;
}>;
search(query: string, types?: string[], subtype?: string): Promise;
ping(): Promise;
getServerInfo(): Promise>;
validateEndpoint(endpoint: string): boolean;
buildUrl(endpoint: string, params?: Record): string;
}
//# sourceMappingURL=api.d.ts.map