sonatype-mcp
Version:
Model Context Protocol server for Sonatype Nexus Repository Manager
96 lines (95 loc) • 2.89 kB
JavaScript
/**
* Component service for managing Nexus components
*/
export class ComponentService {
nexusClient;
constructor(nexusClient) {
this.nexusClient = nexusClient;
}
/**
* Search components
*/
async searchComponents(params = {}) {
const queryParams = {};
if (params.repository)
queryParams.repository = params.repository;
if (params.format)
queryParams.format = params.format;
if (params.group)
queryParams.group = params.group;
if (params.name)
queryParams.name = params.name;
if (params.version)
queryParams.version = params.version;
if (params.prerelease !== undefined)
queryParams.prerelease = params.prerelease.toString();
if (params.sort)
queryParams.sort = params.sort;
if (params.direction)
queryParams.direction = params.direction;
// Use continuation token for pagination instead of offset
const response = await this.nexusClient.get('/service/rest/v1/search', {
params: queryParams
});
return response;
}
/**
* Get component by ID
*/
async getComponent(id) {
const component = await this.nexusClient.get(`/service/rest/v1/components/${encodeURIComponent(id)}`);
return component;
}
/**
* Upload component to repository
*/
async uploadComponent(componentData) {
const component = await this.nexusClient.post(`/service/rest/v1/components`, componentData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
return component;
}
/**
* Delete component by ID
*/
async deleteComponent(id) {
await this.nexusClient.delete(`/service/rest/v1/components/${encodeURIComponent(id)}`);
}
/**
* Get component versions
*/
async getComponentVersions(repository, format, group, name) {
const searchParams = {
repository,
format,
group,
name,
sort: 'version',
direction: 'desc'
};
const response = await this.searchComponents(searchParams);
return response.items.map(component => component.version);
}
/**
* Get assets for a component
*/
async getAssets(componentId) {
const component = await this.getComponent(componentId);
return component.assets;
}
/**
* Get asset by ID
*/
async getAsset(id) {
const asset = await this.nexusClient.get(`/service/rest/v1/assets/${encodeURIComponent(id)}`);
return asset;
}
/**
* Delete asset by ID
*/
async deleteAsset(id) {
await this.nexusClient.delete(`/service/rest/v1/assets/${encodeURIComponent(id)}`);
}
}