@vulog/aima-config
v1.2.14
Published
Configuration management module for the AIMA platform. This module provides functionality to retrieve fleet configuration, cities, services, payment parameters, and manage labels.
Downloads
1,221
Readme
@vulog/aima-config
Configuration management module for the AIMA platform. This module provides functionality to retrieve fleet configuration, cities, services, payment parameters, and manage labels.
Installation
npm install @vulog/aima-client @vulog/aima-core @vulog/aima-configUsage
Initialize Client
import { getClient } from '@vulog/aima-client';
import {
getCities,
getServices,
getFleetConf,
getPaymentParameters,
createLabel,
updateLabel,
deleteLabel,
getLabels
} from '@vulog/aima-config';
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',
});API Reference
Configuration Data
getCities
Retrieve all cities available in the fleet.
const cities = await getCities(client);Parameters:
client: AIMA client instance
Returns: Array of city objects
getServices
Get all services available in the fleet.
const services = await getServices(client);Parameters:
client: AIMA client instance
Returns: Array of service objects
getFleetConf
Retrieve fleet configuration settings.
const fleetConfig = await getFleetConf(client);Parameters:
client: AIMA client instance
Returns: Fleet configuration object
getPaymentParameters
Get payment configuration parameters.
const paymentParams = await getPaymentParameters(client);Parameters:
client: AIMA client instance
Returns: Payment parameters object
Label Management
createLabel
Create a new label.
const label = await createLabel(client, {
name: 'Premium User',
color: '#FF5733',
description: 'High-value customers'
});Parameters:
client: AIMA client instancelabelData: Label creation dataname: Label namecolor: Label color (hex code)description: Label description
updateLabel
Update an existing label.
const updatedLabel = await updateLabel(client, 'label-id-here', {
name: 'Updated Label Name',
color: '#33FF57',
description: 'Updated description'
});deleteLabel
Delete a label.
const result = await deleteLabel(client, 'label-id-here');getLabels
Retrieve all labels.
const labels = await getLabels(client);Types
City
interface City {
id: string;
name: string;
country: string;
countryCode: string;
coordinates: {
latitude: number;
longitude: number;
};
timezone: string;
isActive: boolean;
}Service
interface Service {
id: string;
name: string;
description: string;
type: 'CAR_SHARING' | 'BIKE_SHARING' | 'SCOOTER_SHARING' | 'MULTIMODAL';
isActive: boolean;
features: string[];
pricing: any;
}FleetConfiguration
interface FleetConfiguration {
id: string;
name: string;
settings: {
timezone: string;
currency: string;
language: string;
features: string[];
limits: {
maxVehicles: number;
maxUsers: number;
maxStations: number;
};
};
createdAt: string;
updatedAt: string;
}Label
interface Label {
id: string;
name: string;
color: string;
description: string;
createdAt: string;
updatedAt: string;
}Error Handling
All functions include validation and will throw appropriate errors if:
- Required parameters are missing
- Invalid label IDs are provided
- Network errors occur
Examples
Complete Configuration Management
import { getClient } from '@vulog/aima-client';
import {
getCities,
getServices,
getFleetConf,
getPaymentParameters,
createLabel,
getLabels
} from '@vulog/aima-config';
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 configurationWorkflow() {
try {
// Get fleet configuration
const fleetConfig = await getFleetConf(client);
console.log('Fleet configuration:', fleetConfig);
// Get available cities
const cities = await getCities(client);
console.log(`Found ${cities.length} cities`);
// Get available services
const services = await getServices(client);
console.log(`Found ${services.length} services`);
// Get payment parameters
const paymentParams = await getPaymentParameters(client);
console.log('Payment parameters:', paymentParams);
// Create a new label
const label = await createLabel(client, {
name: 'VIP Customer',
color: '#FFD700',
description: 'Very Important Customer'
});
console.log('Created label:', label);
// Get all labels
const labels = await getLabels(client);
console.log(`Found ${labels.length} labels`);
return { fleetConfig, cities, services, paymentParams, labels };
} catch (error) {
console.error('Configuration workflow error:', error);
throw error;
}
}Service Analysis
async function analyzeServices(client) {
try {
const services = await getServices(client);
const analysis = {
totalServices: services.length,
activeServices: services.filter(s => s.isActive).length,
servicesByType: services.reduce((acc, service) => {
acc[service.type] = (acc[service.type] || 0) + 1;
return acc;
}, {}),
servicesWithFeatures: services.filter(s => s.features && s.features.length > 0).length,
averageFeaturesPerService: services.reduce((sum, s) => sum + (s.features?.length || 0), 0) / services.length
};
console.log('Service Analysis:');
console.log(`Total Services: ${analysis.totalServices}`);
console.log(`Active Services: ${analysis.activeServices}`);
console.log('Services by Type:', analysis.servicesByType);
console.log(`Services with Features: ${analysis.servicesWithFeatures}`);
console.log(`Average Features per Service: ${analysis.averageFeaturesPerService.toFixed(2)}`);
return analysis;
} catch (error) {
console.error('Service analysis error:', error);
throw error;
}
}City Management
async function manageCities(client) {
try {
const cities = await getCities(client);
// Group cities by country
const citiesByCountry = cities.reduce((acc, city) => {
if (!acc[city.country]) {
acc[city.country] = [];
}
acc[city.country].push(city);
return acc;
}, {});
// Find cities in specific timezone
const timezoneGroups = cities.reduce((acc, city) => {
if (!acc[city.timezone]) {
acc[city.timezone] = [];
}
acc[city.timezone].push(city);
return acc;
}, {});
console.log('City Management:');
console.log(`Total Cities: ${cities.length}`);
console.log(`Active Cities: ${cities.filter(c => c.isActive).length}`);
console.log('Cities by Country:', Object.keys(citiesByCountry).map(country =>
`${country}: ${citiesByCountry[country].length}`
));
console.log('Cities by Timezone:', Object.keys(timezoneGroups).map(tz =>
`${tz}: ${timezoneGroups[tz].length}`
));
return { cities, citiesByCountry, timezoneGroups };
} catch (error) {
console.error('City management error:', error);
throw error;
}
}