Files
ember-market-frontend/lib
NotII 2c48ecd2b4 Add product applicability controls to promotion forms
Introduces product selection and exclusion controls to both new and edit promotion forms, allowing promotions to target all, specific, or all-but-specific products. Adds a reusable ProductSelector component, updates promotion types to support new fields, and adjusts cookie max-age for authentication. Also adds two new business quotes.
2025-08-07 16:05:31 +01:00
..
2025-06-30 15:55:27 +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.