@vulog/aima-pricing 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 +82 -218
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,27 +1,26 @@
1
1
  # @vulog/aima-pricing
2
2
 
3
- Pricing management module for the AIMA platform. This module provides functionality to retrieve and manage pricing information for trips, products, and services.
3
+ Pricing configuration retrieve pricing by ID or by parameters.
4
4
 
5
5
  ## Installation
6
6
 
7
- ```bash
8
- npm install @vulog/aima-client @vulog/aima-core @vulog/aima-pricing
7
+ ```sh
8
+ npm install @vulog/aima-pricing @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
- 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',
15
+ import { getPricingById, getPricingByParameter } from '@vulog/aima-pricing';
16
+
17
+ const client = getClient({ ... });
18
+
19
+ const pricing = await getPricingById(client, 'pricing-uuid');
20
+
21
+ const pricingResponse = await getPricingByParameter(client, {
22
+ modelId: 42,
23
+ serviceId: 'service-id',
25
24
  });
26
25
  ```
27
26
 
@@ -29,237 +28,102 @@ const client = getClient({
29
28
 
30
29
  ### getPricingById
31
30
 
32
- Retrieve pricing information by pricing ID.
33
-
34
- ```javascript
35
- const pricing = await getPricingById(client, 'pricing-id-here');
31
+ ```ts
32
+ getPricingById(client: Client, id: string): Promise<Pricing>
36
33
  ```
37
34
 
38
- **Parameters:**
39
- - `client`: AIMA client instance
40
- - `pricingId`: Pricing identifier
35
+ Retrieves a pricing configuration by its UUID.
41
36
 
42
- **Returns:** Pricing object with detailed pricing information
37
+ | Param | Type | Description |
38
+ | -------- | -------- | ------------------------- |
39
+ | `client` | `Client` | Authenticated AIMA client |
40
+ | `id` | `string` | Pricing UUID |
43
41
 
44
- ## Types
42
+ **Returns:** `Promise<Pricing>`
45
43
 
46
- ### Pricing
44
+ ---
47
45
 
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
- }
46
+ ### getPricingByParameter
47
+
48
+ ```ts
49
+ getPricingByParameter(client: Client, pricingParameters?: Partial<PricingParameters>): Promise<PricingResponse>
60
50
  ```
61
51
 
52
+ Retrieves pricing configuration matching the given parameters. All parameters are optional and no validation is applied.
53
+
54
+ | Param | Type | Description |
55
+ | -------------------- | ------------------------------- | --------------------------------- |
56
+ | `client` | `Client` | Authenticated AIMA client |
57
+ | `pricingParameters` | `Partial<PricingParameters>?` | Filter parameters (all optional) |
58
+
59
+ **Returns:** `Promise<PricingResponse>`
60
+
61
+ ## Types
62
+
62
63
  ### PricingParameters
63
64
 
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;
65
+ ```ts
66
+ {
67
+ modelId: number;
68
+ serviceId: string;
69
+ vehicleId: string;
70
+ planId: string;
74
71
  }
75
72
  ```
76
73
 
77
- ### PricingPlan
74
+ ### Pricing
78
75
 
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;
76
+ ```ts
77
+ {
78
+ pricingId: string;
79
+ pricingParameters?: PricingParameters;
80
+ taxRates?: PricingTaxRate[];
81
+ plans?: PricingPlan[];
82
+ taxIncluded: boolean;
88
83
  }
89
84
  ```
90
85
 
91
86
  ### PricingTaxRate
92
87
 
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
88
+ ```ts
89
+ {
90
+ taxRate: number;
91
+ taxName?: string;
100
92
  }
101
93
  ```
102
94
 
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
- });
95
+ ### PricingPlan
125
96
 
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
- }
97
+ ```ts
98
+ {
99
+ distanceIncluded: number;
100
+ unit: string;
101
+ pricePerUnit: number;
102
+ durationInMonths: number;
103
+ name: string;
104
+ pricePerUnitExceedingAllowance: number;
105
+ ratePerUnit: number;
106
+ rollingContract: boolean;
142
107
  }
143
108
  ```
144
109
 
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
- }
110
+ ### PricingResponse
202
111
 
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
- }
112
+ ```ts
113
+ {
114
+ enable: boolean;
115
+ fleetId: string;
116
+ id: string;
117
+ updateDate: string;
118
+ userId: string;
119
+ version: number;
120
+ jsonSegment: {
121
+ jsonConfig: PricingJsonConfig[];
122
+ // ...additional fields
123
+ };
227
124
  }
228
125
  ```
229
126
 
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
- ```
127
+ ### PricingJsonConfig
128
+
129
+ Pricing JSON configuration segment. Structure depends on the fleet's pricing configuration.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vulog/aima-pricing",
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"