Files
ember-market-frontend/lib
NotII 50d0100056 Improve profit analytics chart and modal data handling
Enhanced ProfitAnalyticsChart to display more robust skeleton loaders and improved summary card logic with fallbacks for missing data. Updated the chart to distinguish between tracked and total revenue, and improved cost data coverage display. In the profit analysis modal, profit margin tiers are now sorted by minimum quantity. Updated the ProfitOverview interface to include revenueFromTrackedProducts.
2025-08-26 21:36:08 +01:00
..
2025-04-08 01:32:00 +01:00
oh
2025-07-20 23:34:42 +01:00
2025-06-29 04:13:50 +01:00
2025-04-07 19:25:24 +01:00
2025-06-29 04:13:50 +01:00

API & Utilities Organization

This directory contains the API client and utility functions used throughout the application.

Directory Structure

lib/
├─ api.ts                # Main API entry point
├─ api-client.ts         # Client-side API functions
├─ server-api.ts         # Server-side API functions
├─ services/             # Service modules
│  ├─ index.ts           # Service re-exports
│  ├─ product-service.ts # Product API
│  ├─ shipping-service.ts # Shipping API
│  └─ stats-service.ts   # Statistics API
├─ utils/                # Utility functions
│  └─ index.ts           # Utility re-exports
├─ types.ts              # Common TypeScript types
├─ utils.ts              # General utilities
├─ auth-utils.ts         # Authentication utilities
└─ styles.ts             # Styling utilities

API Structure

  • api.ts - The main API entry point that re-exports all API functionality
  • api-client.ts - Client-side API functions and types
  • server-api.ts - Server-side API functions (for server components in the app/ directory)

How to Use

In Client Components

// Import what you need from the main API module
import { clientFetch, getCustomers, getProducts } from '@/lib/api';

// Example usage
const customers = await getCustomers(1, 25);
const products = await getProducts(1, 10);

In Server Components (app/ directory only)

// Server functions only work in Server Components in the app/ directory
import { getCustomersServer } from '@/lib/api';

// In a Server Component
export default async function Page() {
  const customers = await getCustomersServer(1, 25);
  // ...
}

Server Components Compatibility

The server-side API functions (fetchServer, getCustomersServer, etc.) can only be used in Server Components within the app/ directory. They will throw an error if used in:

  • Client Components
  • The pages/ directory
  • Any code that runs in the browser

This is because they rely on Next.js server-only features like the cookies() function from next/headers.

Utilities

For utilities, you can either import specific functions or use the utils index:

// Import specific utilities
import { cn } from '@/lib/utils';
import { getAuthToken } from '@/lib/auth-utils';

// Or import from the utils index
import { cn, getAuthToken } from '@/lib/utils';

Backward Compatibility

For backward compatibility, many functions are also re-exported from their original locations.