@noukha-technologies/scheme-engine
v1.0.1
Published
Scheme engine for Naga to calculate the reward for a given scheme
Readme
@coder_18/scheme-engine
A powerful reward calculation engine for discount schemes. This package provides a flexible and extensible solution for calculating rewards, discounts, and free products based on complex business rules and conditions.
Features
- 🎯 Flexible Scheme Evaluation - Support for multiple condition types (invoice, line item, combo, assorted, flexible product)
- 🔄 Callback-based Architecture - No direct database dependencies, works with any data source
- 📊 Comprehensive Results - Detailed breakdown of applied schemes, discounts, and rewards
- 🚀 Performance Monitoring - Built-in performance metrics and monitoring callbacks
- 📦 Zero Runtime Dependencies - Lightweight and fast
- 💪 TypeScript Support - Full TypeScript definitions included
Installation
npm install @coder_18/scheme-engineQuick Start
import { calculateReward } from '@coder_18/scheme-engine';
import type { IProductItem, IScheme } from '@coder_18/scheme-engine';
const products: IProductItem[] = [
{
productId: 'PROD001',
quantity: 5,
unitPrice: 100,
brandId: 'BRAND001',
categoryId: 'CAT001'
}
];
const result = await calculateReward({
products,
warehouseId: 'WH001',
channelId: 'CH001',
businessTypeId: 'BT001',
// Required: Fetch candidate schemes
fetchCandidateSchemes: async (params) => {
// Your implementation to fetch schemes from database
// Build query based on params and return IScheme[]
return [];
},
// Required: Fetch all available schemes
fetchAllAvailableSchemes: async (params) => {
// Your implementation to fetch all schemes
return [];
}
});
console.log('Total Discount:', result.totalDiscount);
console.log('Applied Schemes:', result.appliedSchemes);Requirements
- Node.js >= 16.0.0
- TypeScript (recommended) or JavaScript (ES2020+)
Documentation
For detailed documentation, please refer to:
- API Documentation - Complete API reference
- How It Works - Internal architecture and flow
- Architecture - Design patterns and structure
- Testing - Testing guide and examples
Examples
See the examples directory for:
- Basic Usage - Minimal setup example
- Offline Mode - Using product data provider
- Performance Monitoring - Performance metrics
- Product Provider - Advanced product data handling
License
MIT
Repository
Support
For issues and questions, please use the GitHub Issues page.
