@vulog/aima-mobility-plans 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.
package/README.md CHANGED
@@ -1 +1,248 @@
1
- # @vulog/aima-product
1
+ # @vulog/aima-mobility-plans
2
+
3
+ Mobility plans and subscription management module for the AIMA platform. This module provides functionality to manage mobility plans, user subscriptions, and plan-related operations.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vulog/aima-client @vulog/aima-core @vulog/aima-mobility-plans
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Initialize Client
14
+
15
+ ```javascript
16
+ import { getClient } from '@vulog/aima-client';
17
+ import { getPlans, getUserPlans, subscribe, unsubscribe } from '@vulog/aima-mobility-plans';
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
+ ### getPlans
31
+
32
+ Retrieve all available mobility plans.
33
+
34
+ ```javascript
35
+ const plans = await getPlans(client);
36
+ ```
37
+
38
+ **Parameters:**
39
+ - `client`: AIMA client instance
40
+
41
+ **Returns:** Array of available mobility plans
42
+
43
+ ### getUserPlans
44
+
45
+ Get mobility plans for a specific user.
46
+
47
+ ```javascript
48
+ const userPlans = await getUserPlans(client, 'user-uuid-here');
49
+ ```
50
+
51
+ **Parameters:**
52
+ - `client`: AIMA client instance
53
+ - `entityId`: User UUID
54
+
55
+ **Returns:** Array of user's mobility plans
56
+
57
+ ### subscribe
58
+
59
+ Subscribe a user to a mobility plan.
60
+
61
+ ```javascript
62
+ const subscription = await subscribe(client, {
63
+ entityId: 'user-uuid-here',
64
+ planId: 'plan-id-here',
65
+ startDate: '2024-01-01T00:00:00Z'
66
+ });
67
+ ```
68
+
69
+ **Parameters:**
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)
75
+
76
+ ### unsubscribe
77
+
78
+ Unsubscribe a user from a mobility plan.
79
+
80
+ ```javascript
81
+ const result = await unsubscribe(client, {
82
+ entityId: 'user-uuid-here',
83
+ planId: 'plan-id-here',
84
+ endDate: '2024-12-31T23:59:59Z'
85
+ });
86
+ ```
87
+
88
+ **Parameters:**
89
+ - `client`: AIMA client instance
90
+ - `payload`: Unsubscription configuration object
91
+ - `entityId`: User UUID
92
+ - `planId`: Plan identifier
93
+ - `endDate`: Unsubscription end date (optional, defaults to current date)
94
+
95
+ ## Types
96
+
97
+ ### Plan
98
+
99
+ ```typescript
100
+ interface Plan {
101
+ id: string;
102
+ name: string;
103
+ description: string;
104
+ price: number;
105
+ currency: string;
106
+ duration: number; // in days
107
+ features: string[];
108
+ isActive: boolean;
109
+ createdAt: string;
110
+ updatedAt: string;
111
+ }
112
+ ```
113
+
114
+ ### Subscription
115
+
116
+ ```typescript
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
+ ```
129
+
130
+ ### Status
131
+
132
+ ```typescript
133
+ type Status = 'ACTIVE' | 'INACTIVE' | 'EXPIRED' | 'CANCELLED';
134
+ ```
135
+
136
+ ## Error Handling
137
+
138
+ All functions include validation and will throw appropriate errors if:
139
+ - Required parameters are missing
140
+ - Invalid plan or user IDs are provided
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
+ }
214
+ }
215
+ ```
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/dist/index.js CHANGED
@@ -60,7 +60,7 @@ var getUserPlans = async (client, entityId) => {
60
60
  // src/unsubscribe.ts
61
61
  var import_zod3 = require("zod");
62
62
  var schema3 = import_zod3.z.object({
63
- entityId: import_zod3.z.string().uuid(),
63
+ subscriptionId: import_zod3.z.string().uuid(),
64
64
  profileId: import_zod3.z.string().uuid()
65
65
  });
66
66
  var unsubscribe = async (client, subscriptionId, profileId) => {
@@ -75,7 +75,9 @@ var unsubscribe = async (client, subscriptionId, profileId) => {
75
75
  {
76
76
  profileId
77
77
  }
78
- ).then(({ data }) => data);
78
+ ).then(({ data }) => data).catch((err) => {
79
+ throw new Error("Unsubscribe failed", { cause: err });
80
+ });
79
81
  };
80
82
 
81
83
  // src/subscribe.ts
package/dist/index.mjs CHANGED
@@ -31,7 +31,7 @@ var getUserPlans = async (client, entityId) => {
31
31
  // src/unsubscribe.ts
32
32
  import { z as z3 } from "zod";
33
33
  var schema3 = z3.object({
34
- entityId: z3.string().uuid(),
34
+ subscriptionId: z3.string().uuid(),
35
35
  profileId: z3.string().uuid()
36
36
  });
37
37
  var unsubscribe = async (client, subscriptionId, profileId) => {
@@ -46,7 +46,9 @@ var unsubscribe = async (client, subscriptionId, profileId) => {
46
46
  {
47
47
  profileId
48
48
  }
49
- ).then(({ data }) => data);
49
+ ).then(({ data }) => data).catch((err) => {
50
+ throw new Error("Unsubscribe failed", { cause: err });
51
+ });
50
52
  };
51
53
 
52
54
  // src/subscribe.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulog/aima-mobility-plans",
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",
@@ -20,8 +20,8 @@
20
20
  "author": "Vulog",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@vulog/aima-client": "1.1.89",
24
- "@vulog/aima-core": "1.1.89"
23
+ "@vulog/aima-client": "1.1.91",
24
+ "@vulog/aima-core": "1.1.91"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "^3.25.76"
@@ -4,7 +4,7 @@ import { z } from 'zod';
4
4
  import { Plan } from './types';
5
5
 
6
6
  const schema = z.object({
7
- entityId: z.string().uuid(),
7
+ subscriptionId: z.string().uuid(),
8
8
  profileId: z.string().uuid(),
9
9
  });
10
10
 
@@ -39,5 +39,8 @@ export const unsubscribe = async (
39
39
  profileId,
40
40
  }
41
41
  )
42
- .then(({ data }) => data);
42
+ .then(({ data }) => data)
43
+ .catch((err) => {
44
+ throw new Error('Unsubscribe failed', { cause: err });
45
+ });
43
46
  };