amazon-seller-mcp
Version:
Model Context Protocol (MCP) client for Amazon Selling Partner API
97 lines • 3.21 kB
JavaScript
/**
* Catalog API client for Amazon Selling Partner API
*/
import { BaseApiClient } from './base-client.js';
/**
* Catalog API client for Amazon Selling Partner API
*/
export class CatalogClient extends BaseApiClient {
/**
* API version
*/
apiVersion = 'catalog/2022-04-01';
/**
* Create a new CatalogClient instance
*
* @param authConfig Authentication configuration
*/
constructor(authConfig) {
super(authConfig);
}
/**
* Get a catalog item by ASIN
*
* @param params Parameters for retrieving a catalog item
* @returns Promise resolving to the catalog item
*/
async getCatalogItem(params) {
const { asin, includedData, locale } = params;
// Build query parameters
const query = {};
if (includedData && includedData.length > 0) {
query.includedData = includedData;
}
if (locale) {
query.locale = locale;
}
// Add marketplace ID
query.marketplaceIds = this.config.marketplaceId;
// Make API request
const requestOptions = {
method: 'GET',
path: `/${this.apiVersion}/items/${asin}`,
query: query,
};
// Use cache for catalog items (5 minutes TTL)
const cacheKey = `catalog:item:${asin}:${this.config.marketplaceId}:${JSON.stringify(includedData)}:${locale || 'default'}`;
return this.withCache(cacheKey, async () => {
const response = await this.request(requestOptions);
return response.data.payload;
}, 300 // 5 minutes TTL
);
}
/**
* Search catalog items
*
* @param params Parameters for searching catalog items
* @returns Promise resolving to the search results
*/
async searchCatalogItems(params) {
const { keywords, brandNames, classificationIds, pageSize, pageToken, includedData, locale } = params;
// Build query parameters
const query = {};
if (keywords) {
query.keywords = keywords;
}
if (brandNames && brandNames.length > 0) {
query.brandNames = brandNames;
}
if (classificationIds && classificationIds.length > 0) {
query.classificationIds = classificationIds;
}
if (pageSize) {
query.pageSize = Math.min(20, Math.max(1, pageSize)); // Ensure pageSize is between 1 and 20
}
if (pageToken) {
query.pageToken = pageToken;
}
if (includedData && includedData.length > 0) {
query.includedData = includedData;
}
if (locale) {
query.locale = locale;
}
// Add marketplace ID
query.marketplaceIds = this.config.marketplaceId;
// Make API request
const requestOptions = {
method: 'GET',
path: `/${this.apiVersion}/items`,
query: query,
};
// Don't cache search results as they may change frequently
const response = await this.request(requestOptions);
return response.data.payload;
}
}
//# sourceMappingURL=catalog-client.js.map