UNPKG

sfcc-dev-mcp

Version:

MCP server for Salesforce B2C Commerce Cloud development assistance including logs, debugging, and development tools

77 lines 2.68 kB
/** * WebDAV client setup and authentication management */ import { createClient } from 'webdav'; export class WebDAVClientManager { logger; client = null; constructor(logger) { this.logger = logger; } /** * Setup and configure WebDAV client with authentication */ setupClient(config) { let protocol = 'https'; if (config.hostname.startsWith('localhost') || config.hostname.startsWith('127.0.0.1')) { protocol = 'http'; } const webdavUrl = `${protocol}://${config.hostname}/on/demandware.servlet/webdav/Sites/Logs/`; this.logger.debug('Setting up WebDAV client:', { hostname: config.hostname, url: webdavUrl }); const authConfig = this.buildAuthConfig(config); // Add timeout configuration for better CI compatibility const clientConfig = { ...authConfig, timeout: 30000, // 30 second timeout (generous for CI environments) maxBodyLength: 10 * 1024 * 1024, // 10MB max body length maxContentLength: 10 * 1024 * 1024, // 10MB max content length }; this.client = createClient(webdavUrl, clientConfig); return this.client; } /** * Get the current WebDAV client instance */ getClient() { if (!this.client) { throw new Error('WebDAV client not initialized. Call setupClient() first.'); } return this.client; } /** * Build authentication configuration for WebDAV client */ buildAuthConfig(config) { if (config.username && config.password) { this.logger.debug('Using basic authentication'); return { username: config.username, password: config.password, }; } if (config.clientId && config.clientSecret) { this.logger.debug('Using OAuth authentication (client credentials as basic auth for WebDAV)'); return { username: config.clientId, password: config.clientSecret, }; } throw new Error('Either username/password or clientId/clientSecret must be provided'); } /** * Test WebDAV connection */ async testConnection() { try { const client = this.getClient(); await client.getDirectoryContents('/'); this.logger.debug('WebDAV connection test successful'); return true; } catch (error) { this.logger.error('WebDAV connection test failed:', error); return false; } } } //# sourceMappingURL=webdav-client-manager.js.map