@vulog/aima-mobility-plans 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.
- package/README.md +67 -194
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,248 +1,121 @@
|
|
|
1
1
|
# @vulog/aima-mobility-plans
|
|
2
2
|
|
|
3
|
-
Mobility
|
|
3
|
+
Mobility plan subscriptions — list plans, subscribe, and unsubscribe.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
```
|
|
8
|
-
npm install @vulog/aima-
|
|
7
|
+
```sh
|
|
8
|
+
npm install @vulog/aima-mobility-plans @vulog/aima-client @vulog/aima-core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```javascript
|
|
13
|
+
```ts
|
|
16
14
|
import { getClient } from '@vulog/aima-client';
|
|
17
15
|
import { getPlans, getUserPlans, subscribe, unsubscribe } from '@vulog/aima-mobility-plans';
|
|
18
16
|
|
|
19
|
-
const client = getClient({
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
fleetId: 'your-fleet-id',
|
|
25
|
-
});
|
|
17
|
+
const client = getClient({ /* client options */ });
|
|
18
|
+
|
|
19
|
+
const plans = await getPlans(client, 'ACTIVE');
|
|
20
|
+
const userPlans = await getUserPlans(client, 'profile-uuid');
|
|
21
|
+
const result = await subscribe(client, 'plan-uuid', 'profile-uuid');
|
|
26
22
|
```
|
|
27
23
|
|
|
28
24
|
## API Reference
|
|
29
25
|
|
|
30
26
|
### getPlans
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
const plans = await getPlans(client);
|
|
28
|
+
```ts
|
|
29
|
+
getPlans(client: Client, status: Status): Promise<Plan[]>
|
|
36
30
|
```
|
|
37
31
|
|
|
38
|
-
|
|
39
|
-
- `client`: AIMA client instance
|
|
32
|
+
Returns all mobility plans matching the given status. `status` is required.
|
|
40
33
|
|
|
41
|
-
**
|
|
34
|
+
**Params:** `client` — Authenticated AIMA client; `status` — `'ACTIVE'` or `'INACTIVE'`
|
|
35
|
+
**Returns:** `Promise<Plan[]>`
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
---
|
|
44
38
|
|
|
45
|
-
|
|
39
|
+
### getUserPlans
|
|
46
40
|
|
|
47
|
-
```
|
|
48
|
-
|
|
41
|
+
```ts
|
|
42
|
+
getUserPlans(client: Client, entityId: string): Promise<Subscription[]>
|
|
49
43
|
```
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
- `client`: AIMA client instance
|
|
53
|
-
- `entityId`: User UUID
|
|
45
|
+
Returns subscriptions for a user profile. `entityId` must be a UUID. Only returns subscriptions with status `ACTIVE`, `PAYMENT_PENDING`, or `ACTIVATION_PENDING`.
|
|
54
46
|
|
|
55
|
-
**
|
|
47
|
+
**Params:** `client` — Authenticated AIMA client; `entityId` — profile UUID
|
|
48
|
+
**Returns:** `Promise<Subscription[]>`
|
|
56
49
|
|
|
57
|
-
|
|
50
|
+
---
|
|
58
51
|
|
|
59
|
-
|
|
52
|
+
### subscribe
|
|
60
53
|
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
entityId: 'user-uuid-here',
|
|
64
|
-
planId: 'plan-id-here',
|
|
65
|
-
startDate: '2024-01-01T00:00:00Z'
|
|
66
|
-
});
|
|
54
|
+
```ts
|
|
55
|
+
subscribe(client: Client, planId: string, profileId: string): Promise<SubscribeResponse>
|
|
67
56
|
```
|
|
68
57
|
|
|
69
|
-
|
|
70
|
-
- `client`: AIMA client instance
|
|
71
|
-
- `payload`: Subscription configuration object
|
|
72
|
-
- `entityId`: User UUID
|
|
73
|
-
- `planId`: Plan identifier
|
|
74
|
-
- `startDate`: Subscription start date (optional, defaults to current date)
|
|
58
|
+
Subscribes a profile to a plan. Both `planId` and `profileId` must be UUIDs.
|
|
75
59
|
|
|
76
|
-
|
|
60
|
+
**Params:** `client` — Authenticated AIMA client; `planId` — plan UUID; `profileId` — profile UUID
|
|
61
|
+
**Returns:** `Promise<SubscribeResponse>`
|
|
62
|
+
|
|
63
|
+
---
|
|
77
64
|
|
|
78
|
-
|
|
65
|
+
### unsubscribe
|
|
79
66
|
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
entityId: 'user-uuid-here',
|
|
83
|
-
planId: 'plan-id-here',
|
|
84
|
-
endDate: '2024-12-31T23:59:59Z'
|
|
85
|
-
});
|
|
67
|
+
```ts
|
|
68
|
+
unsubscribe(client: Client, subscriptionId: string, profileId: string): Promise<UnsubscribeResponse>
|
|
86
69
|
```
|
|
87
70
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
- `planId`: Plan identifier
|
|
93
|
-
- `endDate`: Unsubscription end date (optional, defaults to current date)
|
|
71
|
+
Cancels a subscription. The first argument is `subscriptionId` (not `planId`). Both must be UUIDs.
|
|
72
|
+
|
|
73
|
+
**Params:** `client` — Authenticated AIMA client; `subscriptionId` — subscription UUID; `profileId` — profile UUID
|
|
74
|
+
**Returns:** `Promise<UnsubscribeResponse>`
|
|
94
75
|
|
|
95
76
|
## Types
|
|
96
77
|
|
|
78
|
+
### Status
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
type Status = 'ACTIVE' | 'INACTIVE';
|
|
82
|
+
```
|
|
83
|
+
|
|
97
84
|
### Plan
|
|
98
85
|
|
|
99
|
-
```
|
|
86
|
+
```ts
|
|
100
87
|
interface Plan {
|
|
101
88
|
id: string;
|
|
102
89
|
name: string;
|
|
103
|
-
|
|
90
|
+
fleetId: string;
|
|
91
|
+
period: 'WEEK' | 'MONTH' | 'YEAR';
|
|
92
|
+
productId: string;
|
|
93
|
+
systemCreditIncluded: number;
|
|
104
94
|
price: number;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
cities: { cityId: string; serviceIds: string[] }[];
|
|
96
|
+
status: Status;
|
|
97
|
+
periodicTimeWallet: {
|
|
98
|
+
freeMinutes: number;
|
|
99
|
+
freeMinutesFrequency: 'DAILY' | 'WEEKLY' | 'MONTHLY';
|
|
100
|
+
};
|
|
101
|
+
services: string[];
|
|
111
102
|
}
|
|
112
103
|
```
|
|
113
104
|
|
|
114
105
|
### Subscription
|
|
115
106
|
|
|
116
|
-
|
|
117
|
-
interface Subscription {
|
|
118
|
-
id: string;
|
|
119
|
-
entityId: string;
|
|
120
|
-
planId: string;
|
|
121
|
-
status: 'ACTIVE' | 'INACTIVE' | 'EXPIRED' | 'CANCELLED';
|
|
122
|
-
startDate: string;
|
|
123
|
-
endDate: string;
|
|
124
|
-
autoRenew: boolean;
|
|
125
|
-
createdAt: string;
|
|
126
|
-
updatedAt: string;
|
|
127
|
-
}
|
|
128
|
-
```
|
|
107
|
+
A tuple type where each entry contains:
|
|
129
108
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
- Subscription conflicts occur
|
|
142
|
-
- Network errors occur
|
|
143
|
-
|
|
144
|
-
## Examples
|
|
145
|
-
|
|
146
|
-
### Complete Mobility Plan Management
|
|
147
|
-
|
|
148
|
-
```javascript
|
|
149
|
-
import { getClient } from '@vulog/aima-client';
|
|
150
|
-
import { getPlans, getUserPlans, subscribe, unsubscribe } from '@vulog/aima-mobility-plans';
|
|
151
|
-
|
|
152
|
-
const client = getClient({
|
|
153
|
-
apiKey: 'your-api-key',
|
|
154
|
-
baseUrl: 'https://your-api-base-url',
|
|
155
|
-
clientId: 'your-client-id',
|
|
156
|
-
clientSecret: 'your-client-secret',
|
|
157
|
-
fleetId: 'your-fleet-id',
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
async function mobilityPlanWorkflow() {
|
|
161
|
-
try {
|
|
162
|
-
// Get all available plans
|
|
163
|
-
const plans = await getPlans(client);
|
|
164
|
-
console.log('Available plans:', plans);
|
|
165
|
-
|
|
166
|
-
// Get user's current plans
|
|
167
|
-
const userPlans = await getUserPlans(client, 'user-uuid-here');
|
|
168
|
-
console.log('User plans:', userPlans);
|
|
169
|
-
|
|
170
|
-
// Subscribe user to a plan
|
|
171
|
-
const subscription = await subscribe(client, {
|
|
172
|
-
entityId: 'user-uuid-here',
|
|
173
|
-
planId: 'premium-plan-id',
|
|
174
|
-
startDate: '2024-01-01T00:00:00Z'
|
|
175
|
-
});
|
|
176
|
-
console.log('User subscribed:', subscription);
|
|
177
|
-
|
|
178
|
-
// Later, unsubscribe user from plan
|
|
179
|
-
const unsubscription = await unsubscribe(client, {
|
|
180
|
-
entityId: 'user-uuid-here',
|
|
181
|
-
planId: 'premium-plan-id',
|
|
182
|
-
endDate: '2024-12-31T23:59:59Z'
|
|
183
|
-
});
|
|
184
|
-
console.log('User unsubscribed:', unsubscription);
|
|
185
|
-
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.error('Mobility plan error:', error);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Plan Comparison Helper
|
|
193
|
-
|
|
194
|
-
```javascript
|
|
195
|
-
async function comparePlans(client) {
|
|
196
|
-
try {
|
|
197
|
-
const plans = await getPlans(client);
|
|
198
|
-
|
|
199
|
-
// Sort plans by price
|
|
200
|
-
const sortedPlans = plans.sort((a, b) => a.price - b.price);
|
|
201
|
-
|
|
202
|
-
console.log('Plans sorted by price:');
|
|
203
|
-
sortedPlans.forEach(plan => {
|
|
204
|
-
console.log(`${plan.name}: ${plan.price} ${plan.currency} (${plan.duration} days)`);
|
|
205
|
-
console.log(`Features: ${plan.features.join(', ')}`);
|
|
206
|
-
console.log('---');
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
return sortedPlans;
|
|
210
|
-
} catch (error) {
|
|
211
|
-
console.error('Plan comparison error:', error);
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
109
|
+
```ts
|
|
110
|
+
{
|
|
111
|
+
id: string;
|
|
112
|
+
profileId: string;
|
|
113
|
+
plan: Plan;
|
|
114
|
+
fleetId: string;
|
|
115
|
+
expiryDate: string;
|
|
116
|
+
unsubscribeDate: string;
|
|
117
|
+
activationDate: string;
|
|
118
|
+
invoiceIds: string[];
|
|
119
|
+
status: 'ACTIVE' | 'PAYMENT_PENDING' | 'ACTIVATION_PENDING';
|
|
214
120
|
}
|
|
215
121
|
```
|
|
216
|
-
|
|
217
|
-
### User Plan Status Check
|
|
218
|
-
|
|
219
|
-
```javascript
|
|
220
|
-
async function checkUserPlanStatus(client, entityId) {
|
|
221
|
-
try {
|
|
222
|
-
const userPlans = await getUserPlans(client, entityId);
|
|
223
|
-
|
|
224
|
-
const activePlans = userPlans.filter(plan => plan.status === 'ACTIVE');
|
|
225
|
-
const expiredPlans = userPlans.filter(plan => plan.status === 'EXPIRED');
|
|
226
|
-
|
|
227
|
-
console.log(`User ${entityId} has:`);
|
|
228
|
-
console.log(`- ${activePlans.length} active plans`);
|
|
229
|
-
console.log(`- ${expiredPlans.length} expired plans`);
|
|
230
|
-
|
|
231
|
-
if (activePlans.length > 0) {
|
|
232
|
-
console.log('Active plans:');
|
|
233
|
-
activePlans.forEach(plan => {
|
|
234
|
-
console.log(` - ${plan.planId} (until ${plan.endDate})`);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
return {
|
|
239
|
-
activePlans,
|
|
240
|
-
expiredPlans,
|
|
241
|
-
totalPlans: userPlans.length
|
|
242
|
-
};
|
|
243
|
-
} catch (error) {
|
|
244
|
-
console.error('Plan status check error:', error);
|
|
245
|
-
throw error;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vulog/aima-mobility-plans",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.46",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.cts",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"author": "Vulog",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@vulog/aima-client": "1.2.
|
|
37
|
-
"@vulog/aima-core": "1.2.
|
|
36
|
+
"@vulog/aima-client": "1.2.46",
|
|
37
|
+
"@vulog/aima-core": "1.2.46"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"zod": "^4.3.6"
|