@vulog/aima-product 1.1.89 → 1.1.91

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +293 -0
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1 +1,294 @@
1
1
  # @vulog/aima-product
2
+
3
+ Product management module for the AIMA platform. This module provides functionality to retrieve and manage products available in the fleet.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vulog/aima-client @vulog/aima-core @vulog/aima-product
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Initialize Client
14
+
15
+ ```javascript
16
+ import { getClient } from '@vulog/aima-client';
17
+ import { getProductById, getProducts } from '@vulog/aima-product';
18
+
19
+ const client = getClient({
20
+ apiKey: 'your-api-key',
21
+ baseUrl: 'https://your-api-base-url',
22
+ clientId: 'your-client-id',
23
+ clientSecret: 'your-client-secret',
24
+ fleetId: 'your-fleet-id',
25
+ });
26
+ ```
27
+
28
+ ## API Reference
29
+
30
+ ### getProductById
31
+
32
+ Retrieve a specific product by its ID.
33
+
34
+ ```javascript
35
+ const product = await getProductById(client, 'product-id-here');
36
+ ```
37
+
38
+ **Parameters:**
39
+ - `client`: AIMA client instance
40
+ - `productId`: Product identifier
41
+
42
+ **Returns:** Product object with detailed information
43
+
44
+ ### getProducts
45
+
46
+ Retrieve all available products.
47
+
48
+ ```javascript
49
+ const products = await getProducts(client);
50
+ ```
51
+
52
+ **Parameters:**
53
+ - `client`: AIMA client instance
54
+
55
+ **Returns:** Array of all available products
56
+
57
+ ## Types
58
+
59
+ ### Product
60
+
61
+ ```typescript
62
+ interface Product {
63
+ id: string;
64
+ name: string;
65
+ description: string;
66
+ price: number;
67
+ currency: string;
68
+ category: string;
69
+ isActive: boolean;
70
+ isAvailable: boolean;
71
+ taxes: ProductTaxe[];
72
+ metadata: Record<string, any>;
73
+ createdAt: string;
74
+ updatedAt: string;
75
+ }
76
+ ```
77
+
78
+ ### ProductTaxe
79
+
80
+ ```typescript
81
+ interface ProductTaxe {
82
+ id: string;
83
+ name: string;
84
+ rate: number; // percentage (e.g., 20 for 20%)
85
+ type: 'VAT' | 'SALES_TAX' | 'CUSTOM';
86
+ isInclusive: boolean; // true if tax is included in base price
87
+ }
88
+ ```
89
+
90
+ ## Error Handling
91
+
92
+ Functions will throw appropriate errors if:
93
+ - Invalid product ID is provided
94
+ - Product not found
95
+ - Network errors occur
96
+
97
+ ## Examples
98
+
99
+ ### Basic Product Operations
100
+
101
+ ```javascript
102
+ import { getClient } from '@vulog/aima-client';
103
+ import { getProductById, getProducts } from '@vulog/aima-product';
104
+
105
+ const client = getClient({
106
+ apiKey: 'your-api-key',
107
+ baseUrl: 'https://your-api-base-url',
108
+ clientId: 'your-client-id',
109
+ clientSecret: 'your-client-secret',
110
+ fleetId: 'your-fleet-id',
111
+ });
112
+
113
+ async function productOperations() {
114
+ try {
115
+ // Get all products
116
+ const products = await getProducts(client);
117
+ console.log(`Found ${products.length} products`);
118
+
119
+ // Get specific product
120
+ const product = await getProductById(client, 'premium-insurance-id');
121
+ console.log('Product details:', product);
122
+
123
+ return { products, product };
124
+ } catch (error) {
125
+ console.error('Product operation error:', error);
126
+ throw error;
127
+ }
128
+ }
129
+ ```
130
+
131
+ ### Product Search and Filtering
132
+
133
+ ```javascript
134
+ async function searchProducts(client, searchTerm, category) {
135
+ try {
136
+ const allProducts = await getProducts(client);
137
+
138
+ let filteredProducts = allProducts;
139
+
140
+ // Filter by search term
141
+ if (searchTerm) {
142
+ filteredProducts = filteredProducts.filter(product =>
143
+ product.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
144
+ product.description.toLowerCase().includes(searchTerm.toLowerCase())
145
+ );
146
+ }
147
+
148
+ // Filter by category
149
+ if (category) {
150
+ filteredProducts = filteredProducts.filter(product =>
151
+ product.category === category
152
+ );
153
+ }
154
+
155
+ // Filter only active and available products
156
+ filteredProducts = filteredProducts.filter(product =>
157
+ product.isActive && product.isAvailable
158
+ );
159
+
160
+ console.log(`Found ${filteredProducts.length} products matching criteria`);
161
+
162
+ return filteredProducts;
163
+ } catch (error) {
164
+ console.error('Product search error:', error);
165
+ throw error;
166
+ }
167
+ }
168
+
169
+ // Usage examples
170
+ async function searchExamples() {
171
+ // Search for insurance products
172
+ const insuranceProducts = await searchProducts(client, 'insurance', 'INSURANCE');
173
+
174
+ // Search for products containing "premium"
175
+ const premiumProducts = await searchProducts(client, 'premium');
176
+
177
+ // Get all active products
178
+ const activeProducts = await searchProducts(client);
179
+ }
180
+ ```
181
+
182
+ ### Product Price Calculation
183
+
184
+ ```javascript
185
+ function calculateProductPrice(product, quantity = 1) {
186
+ const basePrice = product.price * quantity;
187
+ let totalPrice = basePrice;
188
+ const taxes = [];
189
+
190
+ // Calculate taxes
191
+ product.taxes.forEach(tax => {
192
+ if (!tax.isInclusive) {
193
+ const taxAmount = (basePrice * tax.rate) / 100;
194
+ totalPrice += taxAmount;
195
+ taxes.push({
196
+ name: tax.name,
197
+ rate: tax.rate,
198
+ amount: taxAmount
199
+ });
200
+ }
201
+ });
202
+
203
+ return {
204
+ basePrice,
205
+ totalPrice,
206
+ taxes,
207
+ currency: product.currency,
208
+ quantity,
209
+ breakdown: {
210
+ unitPrice: product.price,
211
+ subtotal: basePrice,
212
+ taxTotal: taxes.reduce((sum, tax) => sum + tax.amount, 0)
213
+ }
214
+ };
215
+ }
216
+
217
+ // Usage example
218
+ async function calculateProductCost(productId, quantity) {
219
+ try {
220
+ const product = await getProductById(client, productId);
221
+ const cost = calculateProductPrice(product, quantity);
222
+
223
+ console.log(`Product: ${product.name}`);
224
+ console.log(`Quantity: ${quantity}`);
225
+ console.log(`Unit Price: ${product.price} ${product.currency}`);
226
+ console.log(`Subtotal: ${cost.basePrice} ${product.currency}`);
227
+ console.log(`Total: ${cost.totalPrice} ${product.currency}`);
228
+
229
+ if (cost.taxes.length > 0) {
230
+ console.log('Taxes:');
231
+ cost.taxes.forEach(tax => {
232
+ console.log(` ${tax.name}: ${tax.amount} ${product.currency} (${tax.rate}%)`);
233
+ });
234
+ }
235
+
236
+ return cost;
237
+ } catch (error) {
238
+ console.error('Product cost calculation error:', error);
239
+ throw error;
240
+ }
241
+ }
242
+ ```
243
+
244
+ ### Product Categories Analysis
245
+
246
+ ```javascript
247
+ async function analyzeProductCategories(client) {
248
+ try {
249
+ const products = await getProducts(client);
250
+
251
+ // Group products by category
252
+ const categories = products.reduce((acc, product) => {
253
+ const category = product.category || 'UNCATEGORIZED';
254
+ if (!acc[category]) {
255
+ acc[category] = {
256
+ count: 0,
257
+ products: [],
258
+ totalValue: 0,
259
+ averagePrice: 0
260
+ };
261
+ }
262
+
263
+ acc[category].count++;
264
+ acc[category].products.push(product);
265
+ acc[category].totalValue += product.price;
266
+
267
+ return acc;
268
+ }, {});
269
+
270
+ // Calculate averages
271
+ Object.keys(categories).forEach(category => {
272
+ const cat = categories[category];
273
+ cat.averagePrice = cat.totalValue / cat.count;
274
+ });
275
+
276
+ console.log('Product Categories Analysis:');
277
+ console.log('============================');
278
+
279
+ Object.entries(categories).forEach(([category, data]) => {
280
+ console.log(`\n${category}:`);
281
+ console.log(` Count: ${data.count} products`);
282
+ console.log(` Total Value: ${data.totalValue} ${products[0]?.currency || 'N/A'}`);
283
+ console.log(` Average Price: ${data.averagePrice.toFixed(2)} ${products[0]?.currency || 'N/A'}`);
284
+ console.log(` Active Products: ${data.products.filter(p => p.isActive).length}`);
285
+ console.log(` Available Products: ${data.products.filter(p => p.isAvailable).length}`);
286
+ });
287
+
288
+ return categories;
289
+ } catch (error) {
290
+ console.error('Category analysis error:', error);
291
+ throw error;
292
+ }
293
+ }
294
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-product",
3
- "version": "1.1.89",
3
+ "version": "1.1.91",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -19,8 +19,8 @@
19
19
  "author": "Vulog",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@vulog/aima-client": "1.1.89",
23
- "@vulog/aima-core": "1.1.89"
22
+ "@vulog/aima-client": "1.1.91",
23
+ "@vulog/aima-core": "1.1.91"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "zod": "^3.25.76"