UNPKG

amazon-seller-mcp

Version:

Model Context Protocol (MCP) client for Amazon Selling Partner API

48 lines 2.09 kB
/** * Inventory notifications handler * * This file implements the inventory change notification handler */ import { warn, info } from '../utils/logger.js'; /** * Sets up inventory change notifications * * @param inventoryClient Inventory client * @param notificationManager Notification manager */ export function setupInventoryChangeNotifications(inventoryClient, notificationManager) { // Store original updateInventory method const originalUpdateInventory = inventoryClient.updateInventory.bind(inventoryClient); // Override updateInventory method to add notification support inventoryClient.updateInventory = async function (params, emitNotification = true) { const { sku, quantity, fulfillmentChannel } = params; // Get current inventory if notification is enabled let previousQuantity = 0; if (emitNotification) { try { const currentInventory = await inventoryClient.getInventoryBySku(sku); const currentDetail = currentInventory.inventoryDetails.find((detail) => detail.fulfillmentChannelCode === fulfillmentChannel); previousQuantity = currentDetail?.quantity || 0; } catch (err) { // If we can't get the current inventory, just continue with the update warn(`Could not get current inventory for SKU ${sku}: ${err.message}`); } } // Call original method const result = await originalUpdateInventory(params); // Send notification if successful and notification is enabled if (emitNotification && result.status === 'SUCCESSFUL') { notificationManager.sendInventoryChangeNotification({ sku, fulfillmentChannel, previousQuantity, newQuantity: quantity, marketplaceId: inventoryClient.getConfig().marketplaceId, }); } return result; }; info('Inventory change notifications set up'); } //# sourceMappingURL=inventory-notifications.js.map