exercises

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

global.d.ts (4441B)


      1 // Global type definitions
      2 declare global {
      3   interface Window {
      4     cartBtnPosition: () => DOMRect;
      5   }
      6 
      7   interface ProductCard {
      8     eid: string;
      9     product_name: string;
     10     description: string | null;
     11     category_name: string | null;
     12     final_price: string;
     13     initial_price: string | null;
     14     discount: string | null;
     15     stock: number;
     16     average_rating: string | null;
     17     reviews_count: number | null;
     18     brand: string | null;
     19   }
     20 
     21   interface Product {
     22     eid: string;
     23     product_id: string;
     24     sku: string;
     25     gtin: string | null;
     26     product_name: string;
     27     brand: string | null;
     28     description: string | null;
     29     url: string | null;
     30     final_price: string;
     31     initial_price: string | null;
     32     discount: string | null;
     33     currency: string;
     34     category_name: string | null;
     35     root_category_name: string | null;
     36     available_for_delivery: boolean | null;
     37     available_for_pickup: boolean | null;
     38     free_returns: boolean | null;
     39     sizes: string[];
     40     colors: string[];
     41     stock: number;
     42     is_active: boolean;
     43     deleted_at: string | null;
     44     created_at: string;
     45     updated_at: string;
     46     data_timestamp: string | null;
     47   }
     48 
     49   interface User {
     50     eid: string;
     51     email: string;
     52     is_active: boolean;
     53     deleted_at: string | null;
     54     created_at: string;
     55     updated_at: string;
     56   }
     57 
     58   // Order Models
     59   interface Order {
     60     id: number;
     61     eid: string;
     62     user_id: number | null;
     63     guest_user_id: number | null;
     64     order_number: string;
     65     customer_email: string;
     66     customer_phone: string | null;
     67     subtotal: string;
     68     tax_amount: string;
     69     shipping_amount: string;
     70     total: string;
     71     status: OrderStatus;
     72     payment_status: PaymentStatus;
     73     is_guest_order: boolean | null;
     74     created_at: string;
     75     updated_at: string;
     76   }
     77 
     78   interface OrderItem {
     79     id: number;
     80     eid: string;
     81     order_id: number;
     82     product_id: number;
     83     product_name: string;
     84     product_sku: string;
     85     quantity: number;
     86     unit_price: string;
     87     total_price: string;
     88     created_at: string;
     89   }
     90 
     91   interface ShippingAddress {
     92     id: number;
     93     eid: string;
     94     order_id: number;
     95     first_name: string;
     96     last_name: string;
     97     address_line1: string;
     98     address_line2: string | null;
     99     city: string;
    100     state: string;
    101     postal_code: string;
    102     country: string;
    103     phone: string | null;
    104     created_at: string;
    105     updated_at: string;
    106   }
    107 
    108   interface Payment {
    109     id: number;
    110     eid: string;
    111     order_id: number;
    112     payment_method: PaymentMethod;
    113     payment_reference: string | null;
    114     amount: string;
    115     status: PaymentStatus;
    116     processed_at: string | null;
    117     card_last4: string | null;
    118     card_brand: string | null;
    119     created_at: string;
    120     updated_at: string;
    121   }
    122 
    123   // Order Request/Response Types
    124   interface CreateShippingAddressRequest {
    125     first_name: string;
    126     last_name: string;
    127     address_line1: string;
    128     address_line2?: string | null;
    129     city: string;
    130     state: string;
    131     postal_code: string;
    132     country: string;
    133     phone?: string | null;
    134   }
    135 
    136   interface CreateOrderItemRequest {
    137     product_uuid: string;
    138     product_name: string;
    139     product_sku?: string | null;
    140     quantity: number;
    141     unit_price: string;
    142   }
    143 
    144   interface CreatePaymentRequest {
    145     payment_method: PaymentMethod;
    146     card_last4?: string | null;
    147     card_brand?: string | null;
    148   }
    149 
    150   interface CreateOrderRequest {
    151     customer_email: string;
    152     customer_phone?: string | null;
    153     shipping_address: CreateShippingAddressRequest;
    154     items: CreateOrderItemRequest[];
    155     payment: CreatePaymentRequest;
    156   }
    157 
    158   interface OrderResponse {
    159     order: Order;
    160     items: OrderItem[];
    161     shipping_address: ShippingAddress;
    162     payment: Payment;
    163   }
    164 
    165   interface PaginatedResponse<T = any> {
    166     products: T[];
    167     page: number;
    168     page_size: number;
    169     total: number;
    170     total_pages: number;
    171   }
    172 
    173   // Enums (matching Rust serde snake_case serialization)
    174   type OrderStatus = 'pending' | 'processing' | 'shipped' | 'delivered' | 'cancelled' | 'failed' | 'on_hold';
    175   type PaymentStatus = 'pending' | 'paid' | 'failed' | 'refunded' | 'partially_refunded' | 'cancelled' | 'authorized';
    176   type PaymentMethod = 'credit_card' | 'debit_card';
    177 
    178   interface AddtoCartEvent<T = HTMLElement> {
    179     product: ProductCard;
    180     quantity: number;
    181     element: T;
    182   }
    183 
    184   interface CartItem {
    185     product: ProductCard;
    186     quantity: number;
    187     addedAt?: Date;
    188   }
    189 }
    190 
    191 export {};