npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vulog/aima-product

v1.2.14

Published

Product management module for the AIMA platform. This module provides functionality to retrieve and manage products available in the fleet.

Readme

@vulog/aima-product

Product management module for the AIMA platform. This module provides functionality to retrieve and manage products available in the fleet.

Installation

npm install @vulog/aima-client @vulog/aima-core @vulog/aima-product

Usage

Initialize Client

import { getClient } from '@vulog/aima-client';
import { getProductById, getProducts } from '@vulog/aima-product';

const client = getClient({
    apiKey: 'your-api-key',
    baseUrl: 'https://your-api-base-url',
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    fleetId: 'your-fleet-id',
});

API Reference

getProductById

Retrieve a specific product by its ID.

const product = await getProductById(client, 'product-id-here');

Parameters:

  • client: AIMA client instance
  • productId: Product identifier

Returns: Product object with detailed information

getProducts

Retrieve all available products.

const products = await getProducts(client);

Parameters:

  • client: AIMA client instance

Returns: Array of all available products

Types

Product

interface Product {
    id: string;
    name: string;
    description: string;
    price: number;
    currency: string;
    category: string;
    isActive: boolean;
    isAvailable: boolean;
    taxes: ProductTaxe[];
    metadata: Record<string, any>;
    createdAt: string;
    updatedAt: string;
}

ProductTaxe

interface ProductTaxe {
    id: string;
    name: string;
    rate: number; // percentage (e.g., 20 for 20%)
    type: 'VAT' | 'SALES_TAX' | 'CUSTOM';
    isInclusive: boolean; // true if tax is included in base price
}

Error Handling

Functions will throw appropriate errors if:

  • Invalid product ID is provided
  • Product not found
  • Network errors occur

Examples

Basic Product Operations

import { getClient } from '@vulog/aima-client';
import { getProductById, getProducts } from '@vulog/aima-product';

const client = getClient({
    apiKey: 'your-api-key',
    baseUrl: 'https://your-api-base-url',
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    fleetId: 'your-fleet-id',
});

async function productOperations() {
    try {
        // Get all products
        const products = await getProducts(client);
        console.log(`Found ${products.length} products`);
        
        // Get specific product
        const product = await getProductById(client, 'premium-insurance-id');
        console.log('Product details:', product);
        
        return { products, product };
    } catch (error) {
        console.error('Product operation error:', error);
        throw error;
    }
}

Product Search and Filtering

async function searchProducts(client, searchTerm, category) {
    try {
        const allProducts = await getProducts(client);
        
        let filteredProducts = allProducts;
        
        // Filter by search term
        if (searchTerm) {
            filteredProducts = filteredProducts.filter(product =>
                product.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
                product.description.toLowerCase().includes(searchTerm.toLowerCase())
            );
        }
        
        // Filter by category
        if (category) {
            filteredProducts = filteredProducts.filter(product =>
                product.category === category
            );
        }
        
        // Filter only active and available products
        filteredProducts = filteredProducts.filter(product =>
            product.isActive && product.isAvailable
        );
        
        console.log(`Found ${filteredProducts.length} products matching criteria`);
        
        return filteredProducts;
    } catch (error) {
        console.error('Product search error:', error);
        throw error;
    }
}

// Usage examples
async function searchExamples() {
    // Search for insurance products
    const insuranceProducts = await searchProducts(client, 'insurance', 'INSURANCE');
    
    // Search for products containing "premium"
    const premiumProducts = await searchProducts(client, 'premium');
    
    // Get all active products
    const activeProducts = await searchProducts(client);
}

Product Price Calculation

function calculateProductPrice(product, quantity = 1) {
    const basePrice = product.price * quantity;
    let totalPrice = basePrice;
    const taxes = [];
    
    // Calculate taxes
    product.taxes.forEach(tax => {
        if (!tax.isInclusive) {
            const taxAmount = (basePrice * tax.rate) / 100;
            totalPrice += taxAmount;
            taxes.push({
                name: tax.name,
                rate: tax.rate,
                amount: taxAmount
            });
        }
    });
    
    return {
        basePrice,
        totalPrice,
        taxes,
        currency: product.currency,
        quantity,
        breakdown: {
            unitPrice: product.price,
            subtotal: basePrice,
            taxTotal: taxes.reduce((sum, tax) => sum + tax.amount, 0)
        }
    };
}

// Usage example
async function calculateProductCost(productId, quantity) {
    try {
        const product = await getProductById(client, productId);
        const cost = calculateProductPrice(product, quantity);
        
        console.log(`Product: ${product.name}`);
        console.log(`Quantity: ${quantity}`);
        console.log(`Unit Price: ${product.price} ${product.currency}`);
        console.log(`Subtotal: ${cost.basePrice} ${product.currency}`);
        console.log(`Total: ${cost.totalPrice} ${product.currency}`);
        
        if (cost.taxes.length > 0) {
            console.log('Taxes:');
            cost.taxes.forEach(tax => {
                console.log(`  ${tax.name}: ${tax.amount} ${product.currency} (${tax.rate}%)`);
            });
        }
        
        return cost;
    } catch (error) {
        console.error('Product cost calculation error:', error);
        throw error;
    }
}

Product Categories Analysis

async function analyzeProductCategories(client) {
    try {
        const products = await getProducts(client);
        
        // Group products by category
        const categories = products.reduce((acc, product) => {
            const category = product.category || 'UNCATEGORIZED';
            if (!acc[category]) {
                acc[category] = {
                    count: 0,
                    products: [],
                    totalValue: 0,
                    averagePrice: 0
                };
            }
            
            acc[category].count++;
            acc[category].products.push(product);
            acc[category].totalValue += product.price;
            
            return acc;
        }, {});
        
        // Calculate averages
        Object.keys(categories).forEach(category => {
            const cat = categories[category];
            cat.averagePrice = cat.totalValue / cat.count;
        });
        
        console.log('Product Categories Analysis:');
        console.log('============================');
        
        Object.entries(categories).forEach(([category, data]) => {
            console.log(`\n${category}:`);
            console.log(`  Count: ${data.count} products`);
            console.log(`  Total Value: ${data.totalValue} ${products[0]?.currency || 'N/A'}`);
            console.log(`  Average Price: ${data.averagePrice.toFixed(2)} ${products[0]?.currency || 'N/A'}`);
            console.log(`  Active Products: ${data.products.filter(p => p.isActive).length}`);
            console.log(`  Available Products: ${data.products.filter(p => p.isAvailable).length}`);
        });
        
        return categories;
    } catch (error) {
        console.error('Category analysis error:', error);
        throw error;
    }
}