@vulog/aima-product 1.2.45 → 1.2.46

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 +47 -255
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,294 +1,86 @@
1
1
  # @vulog/aima-product
2
2
 
3
- Product management module for the AIMA platform. This module provides functionality to retrieve and manage products available in the fleet.
3
+ Product catalog retrieve products by ID or list all fleet products.
4
4
 
5
5
  ## Installation
6
6
 
7
- ```bash
8
- npm install @vulog/aima-client @vulog/aima-core @vulog/aima-product
7
+ ```sh
8
+ npm install @vulog/aima-product @vulog/aima-client @vulog/aima-core
9
9
  ```
10
10
 
11
11
  ## Usage
12
12
 
13
- ### Initialize Client
14
-
15
- ```javascript
13
+ ```ts
16
14
  import { getClient } from '@vulog/aima-client';
17
15
  import { getProductById, getProducts } from '@vulog/aima-product';
18
16
 
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
- });
17
+ const client = getClient({ ... });
18
+
19
+ const product = await getProductById(client, 'product-id');
20
+
21
+ const allProducts = await getProducts(client);
26
22
  ```
27
23
 
28
24
  ## API Reference
29
25
 
30
26
  ### getProductById
31
27
 
32
- Retrieve a specific product by its ID.
33
-
34
- ```javascript
35
- const product = await getProductById(client, 'product-id-here');
28
+ ```ts
29
+ getProductById(client: Client, id: string): Promise<Product>
36
30
  ```
37
31
 
38
- **Parameters:**
39
- - `client`: AIMA client instance
40
- - `productId`: Product identifier
41
-
42
- **Returns:** Product object with detailed information
32
+ Retrieves a single product by ID. Strips `fleetId` from the API response.
43
33
 
44
- ### getProducts
34
+ | Param | Type | Description |
35
+ | -------- | -------- | ------------------------- |
36
+ | `client` | `Client` | Authenticated AIMA client |
37
+ | `id` | `string` | Product identifier |
45
38
 
46
- Retrieve all available products.
39
+ **Returns:** `Promise<Product>`
47
40
 
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
41
+ ---
58
42
 
59
- ### Product
43
+ ### getProducts
60
44
 
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
- }
45
+ ```ts
46
+ getProducts(client: Client): Promise<Product[]>
76
47
  ```
77
48
 
78
- ### ProductTaxe
49
+ Returns all products for the fleet. Strips `fleetId` from each product in the response.
79
50
 
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
- ```
51
+ | Param | Type | Description |
52
+ | -------- | -------- | ------------------------- |
53
+ | `client` | `Client` | Authenticated AIMA client |
89
54
 
90
- ## Error Handling
55
+ **Returns:** `Promise<Product[]>`
91
56
 
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
57
+ ## Types
132
58
 
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
- }
59
+ ### ProductTaxe
168
60
 
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);
61
+ ```ts
62
+ {
63
+ taxName?: string;
64
+ taxRate: number;
179
65
  }
180
66
  ```
181
67
 
182
- ### Product Price Calculation
68
+ ### Product
183
69
 
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
- }
70
+ Extends `ProductTaxe`.
216
71
 
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
- }
72
+ ```ts
73
+ {
74
+ id: string;
75
+ type: string;
76
+ name: string;
77
+ price: number;
78
+ taxIncluded: boolean;
79
+ taxName?: string;
80
+ priceRate?: number;
81
+ serviceIds: string[];
82
+ taxes: (ProductTaxe & { id: string })[];
83
+ pricePerUnitExceedingAllowance: number;
84
+ distanceIncluded: number;
241
85
  }
242
86
  ```
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@vulog/aima-product",
3
3
  "type": "module",
4
- "version": "1.2.45",
4
+ "version": "1.2.46",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.cts",
@@ -32,8 +32,8 @@
32
32
  "author": "Vulog",
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@vulog/aima-client": "1.2.45",
36
- "@vulog/aima-core": "1.2.45"
35
+ "@vulog/aima-client": "1.2.46",
36
+ "@vulog/aima-core": "1.2.46"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "zod": "^4.3.6"