UNPKG

autotrader-connect-api

Version:

Production-ready TypeScript wrapper for Auto Trader UK Connect APIs

202 lines 7.14 kB
/** * Search module for AutoTrader API * Handles search-related endpoints and operations */ import client from '../client'; /** * Perform enhanced vehicle search with facets and suggestions * @param filters Search filters and parameters * @returns Promise resolving to enhanced search results */ export async function searchVehicles(filters = {}) { const response = await client.get('/search', { params: { // Basic filters make: Array.isArray(filters.make) ? filters.make.join(',') : filters.make, model: Array.isArray(filters.model) ? filters.model.join(',') : filters.model, // Price and year ranges priceFrom: filters.priceRange?.min, priceTo: filters.priceRange?.max, yearFrom: filters.yearRange?.min, yearTo: filters.yearRange?.max, mileageFrom: filters.mileageRange?.min, mileageTo: filters.mileageRange?.max, // Location postcode: filters.postcode, radius: filters.radius, // Vehicle types fuelType: Array.isArray(filters.fuelType) ? filters.fuelType.join(',') : filters.fuelType, transmission: Array.isArray(filters.transmission) ? filters.transmission.join(',') : filters.transmission, bodyType: Array.isArray(filters.bodyType) ? filters.bodyType.join(',') : filters.bodyType, condition: Array.isArray(filters.condition) ? filters.condition.join(',') : filters.condition, // Advanced options includeNationwide: filters.includeNationwide, hideTradeSellerAds: filters.hideTradeSellerAds, hideDuplicateAds: filters.hideDuplicateAds, onlyRecentlyAdded: filters.onlyRecentlyAdded, onlyPriceReduced: filters.onlyPriceReduced, onlyWithPhotos: filters.onlyWithPhotos, onlyWithVideo: filters.onlyWithVideo, // Dealer preferences preferredDealers: filters.preferredDealers?.join(','), excludedDealers: filters.excludedDealers?.join(','), dealerRatingMin: filters.dealerRatingMin, // Finance financeRequired: filters.financeRequired, monthlyBudget: filters.monthlyBudget, depositAmount: filters.depositAmount, creditRating: filters.creditRating, // Sorting and pagination sortBy: filters.sortBy || 'relevance', sortOrder: filters.sortOrder || 'desc', page: filters.page || 1, pageSize: filters.pageSize || 25, // Request additional data includeFacets: true, includeSuggestions: true, includeMarketInsights: true, }, }); return response; } /** * Quick search for autocomplete and suggestions * @param params Quick search parameters * @returns Promise resolving to quick search results */ export async function quickSearch(params) { const response = await client.get('/search/quick', { params: { query: params.query, make: params.make, model: params.model, postcode: params.postcode, maxPrice: params.maxPrice, radius: params.radius, limit: params.limit || 10, }, }); return response.data; } /** * Get search suggestions based on partial input * @param query Partial search query * @param type Type of suggestions to get * @returns Promise resolving to suggestions */ export async function getSearchSuggestions(query, type) { const response = await client.get('/search/suggestions', { params: { query, type: type || 'all' }, }); return response.data; } /** * Save a search for future alerts * @param searchData Search data to save * @returns Promise resolving to saved search */ export async function saveSearch(searchData) { const response = await client.post('/search/saved', searchData); return response.data; } /** * Get user's saved searches * @returns Promise resolving to array of saved searches */ export async function getSavedSearches() { const response = await client.get('/search/saved'); return response.data; } /** * Update a saved search * @param searchId Saved search ID * @param updateData Updated search data * @returns Promise resolving to updated saved search */ export async function updateSavedSearch(searchId, updateData) { const response = await client.put(`/search/saved/${searchId}`, updateData); return response.data; } /** * Delete a saved search * @param searchId Saved search ID * @returns Promise resolving to deletion confirmation */ export async function deleteSavedSearch(searchId) { const response = await client.delete(`/search/saved/${searchId}`); return response.data; } /** * Execute a saved search * @param searchId Saved search ID * @returns Promise resolving to search results */ export async function executeSavedSearch(searchId) { const response = await client.get(`/search/saved/${searchId}/execute`); return response; } /** * Compare multiple vehicles * @param vehicleIds Array of vehicle IDs to compare * @returns Promise resolving to comparison data */ export async function compareVehicles(vehicleIds) { const response = await client.post('/search/compare', { vehicleIds, }); return response.data; } /** * Get popular searches * @param category Optional category filter * @returns Promise resolving to popular searches */ export async function getPopularSearches(category) { const response = await client.get('/search/popular', { params: { category }, }); return response.data; } /** * Get search analytics and insights * @param timeframe Time period for analytics * @returns Promise resolving to search analytics */ export async function getSearchAnalytics(timeframe = 'month') { const response = await client.get('/search/analytics', { params: { timeframe }, }); return response.data; } /** * Track search interaction * @param searchId Search ID * @param interaction Interaction data * @returns Promise resolving to tracking confirmation */ export async function trackSearchInteraction(searchId, interaction) { const response = await client.post(`/search/${searchId}/track`, { ...interaction, timestamp: interaction.timestamp || new Date().toISOString(), }); return response.data; } /** * Get related searches based on current search * @param filters Current search filters * @returns Promise resolving to related search suggestions */ export async function getRelatedSearches(filters) { const response = await client.post('/search/related', { filters }); return response.data; } /** * Get market insights for search results * @param filters Search filters to analyze * @returns Promise resolving to market insights */ export async function getMarketInsights(filters) { const response = await client.post('/search/market-insights', { filters }); return response.data; } //# sourceMappingURL=search.js.map