amazon-seller-mcp
Version:
Model Context Protocol (MCP) client for Amazon Selling Partner API
98 lines • 2.5 kB
JavaScript
/**
* Type definitions for API-related functionality
*/
/**
* API error types
*/
export var ApiErrorType;
(function (ApiErrorType) {
/**
* Request validation error
*/
ApiErrorType["VALIDATION_ERROR"] = "VALIDATION_ERROR";
/**
* Network error
*/
ApiErrorType["NETWORK_ERROR"] = "NETWORK_ERROR";
/**
* Authentication error
*/
ApiErrorType["AUTH_ERROR"] = "AUTH_ERROR";
/**
* Rate limit exceeded
*/
ApiErrorType["RATE_LIMIT_EXCEEDED"] = "RATE_LIMIT_EXCEEDED";
/**
* Server error
*/
ApiErrorType["SERVER_ERROR"] = "SERVER_ERROR";
/**
* Client error
*/
ApiErrorType["CLIENT_ERROR"] = "CLIENT_ERROR";
/**
* Unknown error
*/
ApiErrorType["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
})(ApiErrorType || (ApiErrorType = {}));
/**
* API error
*/
export class ApiError extends Error {
/**
* Error type
*/
type;
/**
* HTTP status code
*/
statusCode;
/**
* Error details
*/
details;
/**
* Original error
*/
cause;
/**
* Create a new API error
*
* @param message Error message
* @param type Error type
* @param statusCode HTTP status code
* @param details Error details
* @param cause Original error
*/
constructor(message, type, statusCode, details, cause) {
super(message);
this.name = 'ApiError';
this.type = type;
this.statusCode = statusCode;
this.details = details;
this.cause = cause;
}
}
/**
* Default retry strategy
*/
export const DEFAULT_RETRY_STRATEGY = {
maxRetries: 3,
shouldRetry: (error, retryCount) => {
// Retry on network errors, server errors, and rate limit errors
return (retryCount < 3 &&
(error.type === ApiErrorType.NETWORK_ERROR ||
error.type === ApiErrorType.SERVER_ERROR ||
error.type === ApiErrorType.RATE_LIMIT_EXCEEDED));
},
getDelayMs: (retryCount) => {
// Exponential backoff with jitter
const baseDelay = 1000; // 1 second
const maxDelay = 30000; // 30 seconds
const exponentialDelay = Math.min(maxDelay, baseDelay * Math.pow(2, retryCount));
// Add jitter (random delay between 0% and 25% of the exponential delay)
const jitter = Math.random() * 0.25 * exponentialDelay;
return exponentialDelay + jitter;
},
};
//# sourceMappingURL=api.js.map