Files
ember-market-frontend/lib/api.ts
NotII 054ea4802d fk
2025-04-08 02:10:47 +01:00

118 lines
3.0 KiB
TypeScript

// Re-export client API functions
export {
// Core client API functions
clientFetch,
fetchClient,
getAuthToken,
getCookie,
// Customer API
getCustomers,
getCustomerDetails,
// Types
type CustomerStats,
type CustomerResponse,
} from './api-client';
// Re-export product services
export {
getProducts,
getProductDetails,
createProduct,
updateProduct,
deleteProduct,
uploadProductImage,
getProductStock,
updateProductStock,
// Types
type Product,
type ProductsResponse,
type StockData,
} from './services/product-service';
// Re-export shipping services
export {
getShippingOptions,
getShippingOption,
createShippingOption,
updateShippingOption,
deleteShippingOption,
// Types
type ShippingOption,
type ShippingOptionsResponse,
} from './services/shipping-service';
// Define the PlatformStats interface to match the expected format
export interface PlatformStats {
orders: {
completed: number;
};
vendors: {
total: number;
};
transactions: {
volume: number;
averageOrderValue?: number;
};
}
// Re-export stats services
export {
getPlatformStats,
getVendorStats,
} from './services/stats-service';
// Re-export server API functions
export {
fetchServer,
getCustomersServer,
getCustomerDetailsServer,
getPlatformStatsServer
} from './server-api';
// Get clientFetch first so we can use it in the compatibility functions
import { clientFetch } from './api-client';
import { getProductDetails, updateProduct } from './services/product-service';
import { getPlatformStats } from './services/stats-service';
// Add missing functions for backward compatibility
// These are functions from the old style that we need to maintain compatibility
export const fetchData = async (endpoint: string, options: any = {}) => {
console.warn('fetchData is deprecated, use clientFetch instead');
return clientFetch(endpoint, options);
};
export const apiRequest = async (endpoint: string, method = 'GET', data: any = null, token: string | null = null) => {
console.warn('apiRequest is deprecated, use clientFetch instead');
const options: RequestInit & { headers: Record<string, string> } = {
method,
headers: { 'Content-Type': 'application/json' },
body: data ? JSON.stringify(data) : undefined,
};
if (token) {
options.headers.Authorization = `Bearer ${token}`;
}
return clientFetch(endpoint, options);
};
// Product-specific compatibility functions
export const fetchProductData = async (productId: string, token?: string) => {
console.warn('fetchProductData is deprecated, use getProductDetails instead');
return getProductDetails(productId);
};
export const saveProductData = async (productData: any, productId: string, token?: string) => {
console.warn('saveProductData is deprecated, use updateProduct instead');
return updateProduct(productId, productData);
};
// Stats compatibility function
export const fetchPlatformStats = async () => {
console.warn('fetchPlatformStats is deprecated, use getPlatformStats instead');
return getPlatformStats();
};