UNPKG

@iflow-mcp/claudeus-wp-mcp

Version:

The most comprehensive WordPress MCP server - 145 production-ready tools for complete WordPress management with AI

66 lines 2.63 kB
import { BaseApiClient } from './base-client.js'; import axios from 'axios'; import { createPaginationMeta } from '../types/index.js'; export class ShopAPI extends BaseApiClient { security; wcClient; constructor(client, security) { super(client.site); this.security = security; this.wcClient = axios.create({ baseURL: `${client.site.url}/wp-json`, auth: client.site.authType === 'basic' ? { username: client.site.username, password: client.site.auth } : undefined, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', ...(client.site.authType === 'jwt' ? { 'Authorization': `Bearer ${client.site.auth}` } : {}) } }); // Add response interceptor for better error handling this.wcClient.interceptors.response.use(response => response, error => { if (axios.isAxiosError(error)) { const axiosError = error; const errorMessage = axiosError.response?.data?.message || axiosError.message; const errorCode = axiosError.response?.status; throw new Error(`API Error (${errorCode}): ${errorMessage}`); } throw error; }); } async wcGet(endpoint, params) { try { const response = await this.wcClient.get(endpoint, { params }); // Extract pagination metadata from WooCommerce headers const pagination = createPaginationMeta(response.headers, params?.page || 1, params?.per_page || 10); return { data: response.data, pagination }; } catch (error) { if (axios.isAxiosError(error)) { const axiosError = error; if (axiosError.response?.data?.message) { throw new Error(`API Error: ${axiosError.response.data.message}`); } else if (axiosError.response?.status) { throw new Error(`HTTP Error ${axiosError.response.status}: ${axiosError.message}`); } } throw new Error(`Network Error: ${error.message}`); } } async getProducts(filters) { return this.wcGet('/wc/v3/products', filters); } async getOrders(filters) { return this.wcGet('/wc/v3/orders', filters); } async getSalesStats(filters) { return this.wcGet('/wc/v3/reports/sales', filters); } } //# sourceMappingURL=shop.js.map