@vulog/aima-pricing 1.1.88 → 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.
- package/README.md +264 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1 +1,265 @@
|
|
|
1
1
|
# @vulog/aima-pricing
|
|
2
|
+
|
|
3
|
+
Pricing management module for the AIMA platform. This module provides functionality to retrieve and manage pricing information for trips, products, and services.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @vulog/aima-client @vulog/aima-core @vulog/aima-pricing
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Initialize Client
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { getClient } from '@vulog/aima-client';
|
|
17
|
+
import { getPricingById } from '@vulog/aima-pricing';
|
|
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
|
+
### getPricingById
|
|
31
|
+
|
|
32
|
+
Retrieve pricing information by pricing ID.
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const pricing = await getPricingById(client, 'pricing-id-here');
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Parameters:**
|
|
39
|
+
- `client`: AIMA client instance
|
|
40
|
+
- `pricingId`: Pricing identifier
|
|
41
|
+
|
|
42
|
+
**Returns:** Pricing object with detailed pricing information
|
|
43
|
+
|
|
44
|
+
## Types
|
|
45
|
+
|
|
46
|
+
### Pricing
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface Pricing {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
description: string;
|
|
53
|
+
isActive: boolean;
|
|
54
|
+
parameters: PricingParameters;
|
|
55
|
+
plans: PricingPlan[];
|
|
56
|
+
taxRates: PricingTaxRate[];
|
|
57
|
+
createdAt: string;
|
|
58
|
+
updatedAt: string;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### PricingParameters
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
interface PricingParameters {
|
|
66
|
+
basePrice: number;
|
|
67
|
+
currency: string;
|
|
68
|
+
timeUnit: 'MINUTE' | 'HOUR' | 'DAY';
|
|
69
|
+
distanceUnit: 'KM' | 'MILE';
|
|
70
|
+
minimumCharge: number;
|
|
71
|
+
maximumCharge?: number;
|
|
72
|
+
freeTimeMinutes?: number;
|
|
73
|
+
freeDistanceKm?: number;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### PricingPlan
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
interface PricingPlan {
|
|
81
|
+
id: string;
|
|
82
|
+
name: string;
|
|
83
|
+
pricePerTimeUnit: number;
|
|
84
|
+
pricePerDistanceUnit: number;
|
|
85
|
+
timeThreshold: number; // in minutes
|
|
86
|
+
distanceThreshold: number; // in km
|
|
87
|
+
isDefault: boolean;
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### PricingTaxRate
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
interface PricingTaxRate {
|
|
95
|
+
id: string;
|
|
96
|
+
name: string;
|
|
97
|
+
rate: number; // percentage (e.g., 20 for 20%)
|
|
98
|
+
type: 'VAT' | 'SALES_TAX' | 'CUSTOM';
|
|
99
|
+
isInclusive: boolean; // true if tax is included in base price
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Error Handling
|
|
104
|
+
|
|
105
|
+
The function will throw appropriate errors if:
|
|
106
|
+
- Invalid pricing ID is provided
|
|
107
|
+
- Pricing not found
|
|
108
|
+
- Network errors occur
|
|
109
|
+
|
|
110
|
+
## Examples
|
|
111
|
+
|
|
112
|
+
### Basic Pricing Retrieval
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
import { getClient } from '@vulog/aima-client';
|
|
116
|
+
import { getPricingById } from '@vulog/aima-pricing';
|
|
117
|
+
|
|
118
|
+
const client = getClient({
|
|
119
|
+
apiKey: 'your-api-key',
|
|
120
|
+
baseUrl: 'https://your-api-base-url',
|
|
121
|
+
clientId: 'your-client-id',
|
|
122
|
+
clientSecret: 'your-client-secret',
|
|
123
|
+
fleetId: 'your-fleet-id',
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
async function getPricingInfo() {
|
|
127
|
+
try {
|
|
128
|
+
const pricing = await getPricingById(client, 'standard-pricing-id');
|
|
129
|
+
|
|
130
|
+
console.log('Pricing Information:');
|
|
131
|
+
console.log(`Name: ${pricing.name}`);
|
|
132
|
+
console.log(`Description: ${pricing.description}`);
|
|
133
|
+
console.log(`Base Price: ${pricing.parameters.basePrice} ${pricing.parameters.currency}`);
|
|
134
|
+
console.log(`Time Unit: ${pricing.parameters.timeUnit}`);
|
|
135
|
+
console.log(`Distance Unit: ${pricing.parameters.distanceUnit}`);
|
|
136
|
+
|
|
137
|
+
return pricing;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error('Pricing retrieval error:', error);
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Pricing Calculation Helper
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
function calculateTripCost(pricing, durationMinutes, distanceKm) {
|
|
149
|
+
const { parameters, plans, taxRates } = pricing;
|
|
150
|
+
|
|
151
|
+
// Find applicable pricing plan
|
|
152
|
+
const applicablePlan = plans.find(plan =>
|
|
153
|
+
durationMinutes >= plan.timeThreshold &&
|
|
154
|
+
distanceKm >= plan.distanceThreshold
|
|
155
|
+
) || plans.find(plan => plan.isDefault);
|
|
156
|
+
|
|
157
|
+
if (!applicablePlan) {
|
|
158
|
+
throw new Error('No applicable pricing plan found');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Calculate base cost
|
|
162
|
+
const timeCost = (durationMinutes / 60) * applicablePlan.pricePerTimeUnit;
|
|
163
|
+
const distanceCost = distanceKm * applicablePlan.pricePerDistanceUnit;
|
|
164
|
+
let baseCost = timeCost + distanceCost;
|
|
165
|
+
|
|
166
|
+
// Apply minimum/maximum charges
|
|
167
|
+
if (baseCost < parameters.minimumCharge) {
|
|
168
|
+
baseCost = parameters.minimumCharge;
|
|
169
|
+
}
|
|
170
|
+
if (parameters.maximumCharge && baseCost > parameters.maximumCharge) {
|
|
171
|
+
baseCost = parameters.maximumCharge;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Apply taxes
|
|
175
|
+
let totalCost = baseCost;
|
|
176
|
+
const taxes = [];
|
|
177
|
+
|
|
178
|
+
taxRates.forEach(taxRate => {
|
|
179
|
+
if (!taxRate.isInclusive) {
|
|
180
|
+
const taxAmount = (baseCost * taxRate.rate) / 100;
|
|
181
|
+
totalCost += taxAmount;
|
|
182
|
+
taxes.push({
|
|
183
|
+
name: taxRate.name,
|
|
184
|
+
rate: taxRate.rate,
|
|
185
|
+
amount: taxAmount
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
baseCost,
|
|
192
|
+
totalCost,
|
|
193
|
+
taxes,
|
|
194
|
+
currency: parameters.currency,
|
|
195
|
+
breakdown: {
|
|
196
|
+
timeCost,
|
|
197
|
+
distanceCost,
|
|
198
|
+
applicablePlan: applicablePlan.name
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Usage example
|
|
204
|
+
async function calculateCost(pricingId, durationMinutes, distanceKm) {
|
|
205
|
+
try {
|
|
206
|
+
const pricing = await getPricingById(client, pricingId);
|
|
207
|
+
const cost = calculateTripCost(pricing, durationMinutes, distanceKm);
|
|
208
|
+
|
|
209
|
+
console.log('Trip Cost Calculation:');
|
|
210
|
+
console.log(`Duration: ${durationMinutes} minutes`);
|
|
211
|
+
console.log(`Distance: ${distanceKm} km`);
|
|
212
|
+
console.log(`Base Cost: ${cost.baseCost} ${cost.currency}`);
|
|
213
|
+
console.log(`Total Cost: ${cost.totalCost} ${cost.currency}`);
|
|
214
|
+
|
|
215
|
+
if (cost.taxes.length > 0) {
|
|
216
|
+
console.log('Taxes:');
|
|
217
|
+
cost.taxes.forEach(tax => {
|
|
218
|
+
console.log(` ${tax.name}: ${tax.amount} ${cost.currency} (${tax.rate}%)`);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return cost;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error('Cost calculation error:', error);
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Pricing Comparison
|
|
231
|
+
|
|
232
|
+
```javascript
|
|
233
|
+
async function comparePricing(pricingIds) {
|
|
234
|
+
try {
|
|
235
|
+
const pricingList = await Promise.all(
|
|
236
|
+
pricingIds.map(id => getPricingById(client, id))
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
console.log('Pricing Comparison:');
|
|
240
|
+
console.log('==================');
|
|
241
|
+
|
|
242
|
+
pricingList.forEach(pricing => {
|
|
243
|
+
console.log(`\n${pricing.name}:`);
|
|
244
|
+
console.log(` Base Price: ${pricing.parameters.basePrice} ${pricing.parameters.currency}`);
|
|
245
|
+
console.log(` Time Unit: ${pricing.parameters.timeUnit}`);
|
|
246
|
+
console.log(` Distance Unit: ${pricing.parameters.distanceUnit}`);
|
|
247
|
+
console.log(` Minimum Charge: ${pricing.parameters.minimumCharge} ${pricing.parameters.currency}`);
|
|
248
|
+
|
|
249
|
+
if (pricing.parameters.maximumCharge) {
|
|
250
|
+
console.log(` Maximum Charge: ${pricing.parameters.maximumCharge} ${pricing.parameters.currency}`);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
console.log(` Plans: ${pricing.plans.length}`);
|
|
254
|
+
pricing.plans.forEach(plan => {
|
|
255
|
+
console.log(` - ${plan.name}: ${plan.pricePerTimeUnit}/${pricing.parameters.timeUnit}, ${plan.pricePerDistanceUnit}/${pricing.parameters.distanceUnit}`);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
return pricingList;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error('Pricing comparison error:', error);
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-pricing",
|
|
3
|
-
"version": "1.1.
|
|
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.
|
|
23
|
-
"@vulog/aima-core": "1.1.
|
|
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"
|