i have these typescript functions that retrieve the internal fulfill_id based on product code or ean code:
interface OutputProduct {
    fulfill_id: string;
    fulfill_stock: number;
    submited_stock: string;
}

interface OutputData {
    products: OutputProduct[];
}

const RATE_LIMIT = 60;
const RATE_LIMIT_WINDOW = 65000;

// API helpers
const getProductByEan = async (ean: string): Promise<string> => {
    const response = await fetch(https://reports.fulfill.ro/api/v1/connectors/client/products/byEan/${ean}, {
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': Bearer ${env.FULFILL_API_KEY},
        },
    });

    if (!response.ok) {
        throw new Error(HTTP error! status: ${response.status});
    }
    const data = await response.json();
    return data.data.productId;
};

const getProductByProductCode = async (productCode: string): Promise<string> => {
    const response = await fetch(https://reports.fulfill.ro/api/v1/connectors/client/products/byProductCode/${productCode}, {
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': Bearer ${env.FULFILL_API_KEY},
        },
    });
    if (!response.ok) {
        throw new Error(HTTP error! status: ${response.status});
    }
    const data = await response.json();
    return data.data.productId;
};

const rateLimiter = async (fn: () => Promise<string>, index: number): Promise<string> => {
    const waitTime = Math.floor(index / RATE_LIMIT) * RATE_LIMIT_WINDOW;
    await new Promise(resolve => setTimeout(resolve, waitTime));
    return fn();
};

// Process products
const processProducts = async (inputData: InputData): Promise<OutputData> => {
    const getProductFn = inputData.idType === 'EAN' ? getProductByEan : getProductByProductCode;

    const outputProducts: OutputProduct[] = await Promise.all(
        inputData.products.map(async (product, index) => {
            const fulfill_id = await rateLimiter(() => getProductFn(product.id), index);
            return {
                fulfill_id,
                submited_stock: product.stock
            };
        })
    );

    return { products: outputProducts };
};

I need to add another field to output, fulfill_stock. For, this, i must fetch this api endpoint: https://reports.fulfill.ro/api/v1/connectors/client/products/stock/byId/{fulfill_id}
The response looks like this, and i need to extract stockInfo>availableStock field from response: "{
  "data": {
    "productId": 3028138,
    "description": "Suc BIO de rodie, fara zahar(cu garantie) Prosain",
    "productCode": "11540",
    "ean": "5940674949029",
    "externalId": 1618,
    "weight": 0,
    "productType": "With Expiration Date & Production Batch",
    "condition": "GOOD",
    "stockInfo": {
      "entries": 36,
      "exitsInShippedOrders": 0,
      "exitsInAllOrders": 12,
      "inStock": 36,
      "availableStock": 24
    }
  },
  "success": true
}"

Also, I need to improve the functions that retrieve the fulfill id based on product code or ean. If the product doenst exist and api returns this "{ "success": false, "error": { "message": "Entry for Product not found", "code": 404 } }", it shouldnt try to fetch stock endpoint, and the fulfill_id field should contain the original given id (ean or product code) but with an "error-" prefix