Mobility plans and subscription management module for the AIMA platform. This module provides functionality to manage mobility plans, user subscriptions, and plan-related operations.
npm install @vulog/aima-mobility-plansMobility plans and subscription management module for the AIMA platform. This module provides functionality to manage mobility plans, user subscriptions, and plan-related operations.
``bash`
npm install @vulog/aima-client @vulog/aima-core @vulog/aima-mobility-plans
`javascript
import { getClient } from '@vulog/aima-client';
import { getPlans, getUserPlans, subscribe, unsubscribe } from '@vulog/aima-mobility-plans';
const client = getClient({
apiKey: 'your-api-key',
baseUrl: 'https://your-api-base-url',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
fleetId: 'your-fleet-id',
});
`
Retrieve all available mobility plans.
`javascript`
const plans = await getPlans(client);
Parameters:
- client: AIMA client instance
Returns: Array of available mobility plans
Get mobility plans for a specific user.
`javascript`
const userPlans = await getUserPlans(client, 'user-uuid-here');
Parameters:
- client: AIMA client instanceentityId
- : User UUID
Returns: Array of user's mobility plans
Subscribe a user to a mobility plan.
`javascript`
const subscription = await subscribe(client, {
entityId: 'user-uuid-here',
planId: 'plan-id-here',
startDate: '2024-01-01T00:00:00Z'
});
Parameters:
- client: AIMA client instancepayload
- : Subscription configuration objectentityId
- : User UUIDplanId
- : Plan identifierstartDate
- : Subscription start date (optional, defaults to current date)
Unsubscribe a user from a mobility plan.
`javascript`
const result = await unsubscribe(client, {
entityId: 'user-uuid-here',
planId: 'plan-id-here',
endDate: '2024-12-31T23:59:59Z'
});
Parameters:
- client: AIMA client instancepayload
- : Unsubscription configuration objectentityId
- : User UUIDplanId
- : Plan identifierendDate
- : Unsubscription end date (optional, defaults to current date)
`typescript`
interface Plan {
id: string;
name: string;
description: string;
price: number;
currency: string;
duration: number; // in days
features: string[];
isActive: boolean;
createdAt: string;
updatedAt: string;
}
`typescript`
interface Subscription {
id: string;
entityId: string;
planId: string;
status: 'ACTIVE' | 'INACTIVE' | 'EXPIRED' | 'CANCELLED';
startDate: string;
endDate: string;
autoRenew: boolean;
createdAt: string;
updatedAt: string;
}
`typescript`
type Status = 'ACTIVE' | 'INACTIVE' | 'EXPIRED' | 'CANCELLED';
All functions include validation and will throw appropriate errors if:
- Required parameters are missing
- Invalid plan or user IDs are provided
- Subscription conflicts occur
- Network errors occur
`javascript
import { getClient } from '@vulog/aima-client';
import { getPlans, getUserPlans, subscribe, unsubscribe } from '@vulog/aima-mobility-plans';
const client = getClient({
apiKey: 'your-api-key',
baseUrl: 'https://your-api-base-url',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
fleetId: 'your-fleet-id',
});
async function mobilityPlanWorkflow() {
try {
// Get all available plans
const plans = await getPlans(client);
console.log('Available plans:', plans);
// Get user's current plans
const userPlans = await getUserPlans(client, 'user-uuid-here');
console.log('User plans:', userPlans);
// Subscribe user to a plan
const subscription = await subscribe(client, {
entityId: 'user-uuid-here',
planId: 'premium-plan-id',
startDate: '2024-01-01T00:00:00Z'
});
console.log('User subscribed:', subscription);
// Later, unsubscribe user from plan
const unsubscription = await unsubscribe(client, {
entityId: 'user-uuid-here',
planId: 'premium-plan-id',
endDate: '2024-12-31T23:59:59Z'
});
console.log('User unsubscribed:', unsubscription);
} catch (error) {
console.error('Mobility plan error:', error);
}
}
`
`javascript${plan.name}: ${plan.price} ${plan.currency} (${plan.duration} days)
async function comparePlans(client) {
try {
const plans = await getPlans(client);
// Sort plans by price
const sortedPlans = plans.sort((a, b) => a.price - b.price);
console.log('Plans sorted by price:');
sortedPlans.forEach(plan => {
console.log();Features: ${plan.features.join(', ')}
console.log();`
console.log('---');
});
return sortedPlans;
} catch (error) {
console.error('Plan comparison error:', error);
throw error;
}
}
`javascriptUser ${entityId} has:
async function checkUserPlanStatus(client, entityId) {
try {
const userPlans = await getUserPlans(client, entityId);
const activePlans = userPlans.filter(plan => plan.status === 'ACTIVE');
const expiredPlans = userPlans.filter(plan => plan.status === 'EXPIRED');
console.log();- ${activePlans.length} active plans
console.log();- ${expiredPlans.length} expired plans
console.log(); - ${plan.planId} (until ${plan.endDate})
if (activePlans.length > 0) {
console.log('Active plans:');
activePlans.forEach(plan => {
console.log();``
});
}
return {
activePlans,
expiredPlans,
totalPlans: userPlans.length
};
} catch (error) {
console.error('Plan status check error:', error);
throw error;
}
}