sfcc-dev-mcp
Version:
MCP server for Salesforce B2C Commerce Cloud development assistance including logs, debugging, and development tools
127 lines • 5.57 kB
JavaScript
/**
* OCAPI Client for Salesforce Commerce Cloud
*
* This module provides a unified interface for making authenticated requests to SFCC's Open Commerce API (OCAPI).
* It orchestrates specialized client modules for different domain areas while maintaining backward compatibility.
*/
import { OCAPISystemObjectsClient } from './ocapi/system-objects-client.js';
import { OCAPISitePreferencesClient } from './ocapi/site-preferences-client.js';
import { OCAPICodeVersionsClient } from './ocapi/code-versions-client.js';
import { OCAPIAuthClient } from './base/ocapi-auth-client.js';
import { Logger } from '../utils/logger.js';
/**
* OCAPI Client - Unified interface for SFCC OCAPI operations
*
* This class serves as a facade that orchestrates specialized client modules:
* - SystemObjectsClient: Handles system object definitions and attributes
* - SitePreferencesClient: Manages site preference operations
* - CodeVersionsClient: Manages code version operations
* - AuthClient: Manages OAuth authentication and token lifecycle
*/
export class OCAPIClient {
// Specialized client modules
systemObjects;
sitePreferences;
codeVersions;
authClient;
logger;
constructor(config) {
this.logger = Logger.getChildLogger('OCAPIClient');
this.logger.debug(`Initializing OCAPI client for hostname: ${config.hostname}`);
const finalConfig = {
version: 'v21_3',
...config,
};
// Initialize specialized clients
this.systemObjects = new OCAPISystemObjectsClient(finalConfig);
this.sitePreferences = new OCAPISitePreferencesClient(finalConfig);
this.codeVersions = new OCAPICodeVersionsClient(finalConfig);
this.authClient = new OCAPIAuthClient(finalConfig);
this.logger.debug('OCAPI client initialized with specialized modules');
}
// =============================================================================
// System Objects API - Delegated to SystemObjectsClient
// =============================================================================
/**
* Get all system object definitions
*/
async getSystemObjectDefinitions(params) {
return this.systemObjects.getSystemObjectDefinitions(params);
}
/**
* Get a specific system object definition by object type
*/
async getSystemObjectDefinition(objectType) {
return this.systemObjects.getSystemObjectDefinition(objectType);
}
/**
* Search for system object definitions using complex queries
*/
async searchSystemObjectDefinitions(searchRequest) {
return this.systemObjects.searchSystemObjectDefinitions(searchRequest);
}
/**
* Search attribute definitions for a specific system object type using complex queries
*/
async searchSystemObjectAttributeDefinitions(objectType, searchRequest) {
return this.systemObjects.searchSystemObjectAttributeDefinitions(objectType, searchRequest);
}
/**
* Search attribute groups for a specific system object type
*/
async searchSystemObjectAttributeGroups(objectType, searchRequest) {
return this.systemObjects.searchSystemObjectAttributeGroups(objectType, searchRequest);
}
/**
* Search attribute definitions for a specific custom object type using complex queries
*/
async searchCustomObjectAttributeDefinitions(objectType, searchRequest) {
return this.systemObjects.searchCustomObjectAttributeDefinitions(objectType, searchRequest);
}
// =============================================================================
// Site Preferences API - Delegated to SitePreferencesClient
// =============================================================================
/**
* Search site preferences across sites in the specified preference group and instance
*/
async searchSitePreferences(groupId, instanceType, searchRequest, options) {
return this.sitePreferences.searchSitePreferences(groupId, instanceType, searchRequest, options);
}
// =============================================================================
// Code Versions API - Delegated to CodeVersionsClient
// =============================================================================
/**
* Get all code versions from the SFCC instance
*
* @returns {Promise<any>} Code version result with data array containing version information
*/
async getCodeVersions() {
return this.codeVersions.getCodeVersions();
}
/**
* Activate a specific code version on the SFCC instance
*
* @param {string} codeVersionId - The ID of the code version to activate
* @param {string} codeVersionId - The ID of the code version to activate
* @returns {Promise<any>} Updated code version object
*/
async activateCodeVersion(codeVersionId) {
return this.codeVersions.activateCodeVersion(codeVersionId);
}
// =============================================================================
// Authentication & Token Management - Delegated to AuthClient
// =============================================================================
/**
* Get current token expiration for debugging
*/
getTokenExpiration() {
return this.authClient.getTokenExpiration();
}
/**
* Force refresh the token (useful for testing)
*/
async refreshToken() {
return this.authClient.refreshToken();
}
}
//# sourceMappingURL=ocapi-client.js.map