Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProyectoFerretek/FerreMarket/llms.txt

Use this file to discover all available pages before exploring further.

All data flowing through FerreMarket is strictly typed via TypeScript interfaces defined in src/types/index.ts. This page is the canonical reference for every entity shape used across pages, components, and Supabase data-access functions — if a field exists in the database, it is represented here.

Producto

Represents a single hardware product in the FerreMarket catalog. Every product has a unique SKU, belongs to one category string, and carries a boolean flag that marks it as featured.
FieldTypeRequiredDescription
idstringUnique product identifier (database primary key)
skustringStock-keeping unit code; used as the Cloudflare R2 image filename
nombrestringDisplay name of the product
descripcionstringFull text description
precionumberUnit price (CLP)
categoriastringCategory identifier string (references a Categoria.id)
stocknumberCurrent units available in inventory
imagenstringURL to the product image (hosted on Cloudflare CDN)
destacadobooleanWhether the product is marked as featured
export interface Producto {
  id: string;
  sku: string;
  nombre: string;
  descripcion: string;
  precio: number;
  categoria: string;
  stock: number;
  imagen: string;
  destacado: boolean;
}

UpdateProducto

A trimmed payload used when updating an existing product. It omits id, sku, and imagen because those fields are not editable through the standard update flow — the image is managed separately via the Cloudflare Workers upload pipeline.
FieldTypeRequiredDescription
nombrestringUpdated display name
descripcionstringUpdated description
precionumberUpdated unit price (CLP)
categoriastringUpdated category identifier
stocknumberUpdated stock count
destacadobooleanUpdated featured flag
export interface UpdateProducto {
  nombre: string;
  descripcion: string;
  precio: number;
  categoria: string;
  stock: number;
  destacado: boolean;
}

Cliente

Represents a customer record. FerreMarket supports two customer subtypes — individual (natural person, identified by RUN) and empresa (business entity, identified by RUT) — within a single interface. Fields relevant only to one subtype are optional; tipoCliente discriminates between them.
FieldTypeRequiredDescription
idstringDatabase primary key (absent before first save)
estado'activo' | 'inactivo'Whether the customer account is active
fechaCreacionstringISO 8601 creation timestamp
ultimaModificacionstringISO 8601 last-modified timestamp
notasstringFree-text internal notes
comprasnumberTotal number of purchases made
totalComprasnumberCumulative spend across all purchases (CLP)
ultimaComprastringISO 8601 date of the most recent purchase
tipoClientestringSubtype discriminator: 'individual' or 'empresa'
nombrestringFirst name (individual) or commercial name (empresa)
apellidosstringLast name(s) — individual clients only
emailstringContact email address
telefonostringContact phone number
direccionstringPostal address
runstringChilean national ID number — individual clients only
rutstringChilean tax ID number — business clients only
girostringBusiness activity description — business clients only
nombreComercialstringTrading name — business clients only
razonSocialstringLegal registered name — business clients only
export interface Cliente {
  id?: string;
  estado: 'activo' | 'inactivo';
  fechaCreacion?: string;
  ultimaModificacion?: string;
  notas?: string;
  compras?: number;
  totalCompras?: number;
  ultimaCompra?: string;
  tipoCliente: string;

  nombre?: string;
  apellidos?: string;
  email?: string;
  telefono?: string;
  direccion?: string;
  run?: string; // RUN para clientes individuales
  rut?: string; // RUT para clientes empresariales
  giro?: string; // Giro para clientes empresariales
  nombreComercial?: string; // Nombre comercial para clientes empresariales
  razonSocial?: string;
}

Venta

Represents a completed sales transaction. The productos array is a denormalised snapshot of what was sold — each entry carries the product ID, quantity, and the unit price at the time of sale (preserving historical accuracy even if the catalogue price later changes).
FieldTypeRequiredDescription
idstringUnique transaction identifier
fechastringISO 8601 timestamp when the sale occurred
clientestringID of the Cliente who made the purchase
productos{ id: string; cantidad: number; precioUnitario: number }[]Line items: product ID, quantity sold, and unit price at time of sale
totalnumberGrand total of the transaction (CLP)
metodoPagostringPayment method used (e.g. 'efectivo', 'tarjeta')
estadostringTransaction status (e.g. 'completada', 'pendiente', 'cancelada')
export interface Venta {
  id: string;
  fecha: string;
  cliente: string;
  productos: {
    id: string;
    cantidad: number;
    precioUnitario: number;
  }[];
  total: number;
  metodoPago: string;
  estado: string;
}

VentaFormulario

The form payload submitted when creating or editing a sale. It mirrors Venta but uses a narrower union type for estado to enforce valid values at form submission time.
FieldTypeRequiredDescription
fechastringISO 8601 sale date
clientestringID of the customer
productos{ id: string; cantidad: number; precioUnitario: number }[]Line items being submitted
totalnumberComputed grand total (CLP)
metodoPagostringPayment method
estado'completada' | 'pendiente' | 'cancelada'Sale status — restricted to valid enum values
export interface VentaFormulario {
  fecha: string;
  cliente: string;
  productos: {
    id: string;
    cantidad: number;
    precioUnitario: number;
  }[];
  total: number;
  metodoPago: string;
  estado: 'completada' | 'pendiente' | 'cancelada';
}

Usuario

Represents a system user account. Each Usuario has both an internal numeric id (the database row PK) and a uid (the Supabase Auth UUID). The rol field governs access level throughout the application.
FieldTypeRequiredDescription
idstringInternal database primary key
uidstringSupabase Auth UUID — links to auth.users
nombrestringDisplay name
emailstringLogin email address
rol'admin' | 'usuario' | 'cliente'Access role
estado'activo' | 'inactivo'Whether the account is enabled
fechaCreacionstringISO 8601 account creation timestamp
ultimaModificacionstringISO 8601 last profile update timestamp
ultimoAccesostringISO 8601 timestamp of the last successful login
avatarstringURL to the user’s profile picture
export interface Usuario {
  id: string;
  uid: string;
  nombre: string;
  email: string;
  rol: 'admin' | 'usuario' | 'cliente';
  estado: 'activo' | 'inactivo';
  fechaCreacion: string;
  ultimaModificacion: string;
  ultimoAcceso?: string;
  avatar?: string;
}

UsuarioFormData

The form payload for creating a new user or editing an existing one. Includes password and confirmPassword fields that are validated client-side and then forwarded to the create-user Edge Function — they are never stored directly in the usuarios table.
FieldTypeRequiredDescription
idstringDatabase ID — present only when editing an existing user
nombrestringDisplay name
emailstringLogin email address
passwordstringPlain-text password (sent to the Edge Function, never persisted)
confirmPasswordstringPassword confirmation — must match password
rol'admin' | 'usuario' | 'cliente'Access role to assign
estado'activo' | 'inactivo'Initial account state
export interface UsuarioFormData {
  id?: string; // Opcional para crear nuevos usuarios
  nombre: string;
  email: string;
  password: string;
  confirmPassword: string;
  rol: 'admin' | 'usuario' | 'cliente';
  estado: 'activo' | 'inactivo';
}

Promocion

Represents a discount promotion. The interface covers percentage and fixed-amount discounts, usage caps, date windows, applicability filters (specific products/categories, customer types), and analytics metrics (revenue generated, conversion rate, average order value) that are updated incrementally as the promotion is used.
FieldTypeRequiredDescription
idstringUnique promotion identifier
codigostringHuman-readable promo code entered at checkout
nombrestringInternal name for the promotion
tipostringDiscount type (e.g. 'porcentaje', 'monto_fijo')
valornumberDiscount magnitude (percentage or fixed CLP amount)
valorMaximonumberMaximum CLP discount for percentage-type promotions
montoMinimonumberMinimum cart total (CLP) required to apply the promo
fechaIniciostringISO 8601 start date/time
fechaFinstringISO 8601 expiry date/time
limiteTotalUsosnumberMaximum total redemptions across all customers
limiteUsosPorClientenumberMaximum redemptions per individual customer
usosActualesnumberRunning total of times the code has been redeemed
estadostringPromotion status (e.g. 'activo', 'inactivo', 'expirado')
aplicaAstringScope: 'todos', 'productos', or 'categorias'
productosIncluidosstring[]Product IDs the promotion explicitly applies to
productosExcluidosstring[]Product IDs excluded from the promotion
categoriasIncluidasstring[]Category IDs the promotion applies to
categoriasExcluidasstring[]Category IDs excluded from the promotion
tipoClientestringCustomer type restriction: 'todos', 'individual', or 'empresa'
combinablebooleanWhether this promotion can stack with others
descripcionstringOptional marketing description of the promotion
fechaCreacionstringISO 8601 timestamp when the promotion was created
creadoPorstringName or ID of the user who created the promotion
ingresoGeneradonumberTotal CLP revenue attributed to this promotion
valorPromedioCompranumberAverage order value (CLP) of redemption transactions
tasaConversionnumberRatio of sessions that used the promo to total sessions exposed
horariosUsostring[]Array of time-slot strings representing when the promo was used
productosVendidosstring[]Product IDs sold under this promotion
export interface Promocion {
  id: string;
  codigo: string;
  nombre: string;
  tipo: string;
  valor: number;
  valorMaximo?: number;
  montoMinimo: number;
  fechaInicio: string; // ISO 8601
  fechaFin: string; // ISO 8601
  limiteTotalUsos?: number;
  limiteUsosPorCliente?: number;
  usosActuales: number;
  estado: string;
  aplicaA: string;
  productosIncluidos: string[];
  productosExcluidos: string[];
  categoriasIncluidas: string[];
  categoriasExcluidas: string[];
  tipoCliente: string;
  combinable: boolean;
  descripcion?: string;
  fechaCreacion: string; // ISO 8601
  creadoPor: string;
  ingresoGenerado: number;
  valorPromedioCompra: number;
  tasaConversion: number;
  horariosUso: string[];
  productosVendidos: string[];
}

Categoria

Represents a product category used to organise the catalog. The icono field holds a Lucide icon name string that drives icon rendering in the UI.
FieldTypeRequiredDescription
idstringUnique category identifier
nombrestringDisplay name (e.g. 'Herramientas', 'Pinturas')
iconostringLucide icon name string (e.g. 'tool', 'zap')
cantidadnumberNumber of products assigned to this category
export interface Categoria {
  id: string;
  nombre: string;
  icono: string;
  cantidad: number;
}

Notificacion

Represents a system notification surfaced in the app’s notification centre. Notifications are typed so the UI can apply distinct colours and icons per severity level.
FieldTypeRequiredDescription
idstringUnique notification identifier
mensajestringHuman-readable notification message
tipo'info' | 'alerta' | 'error'Severity/category of the notification
fechastringISO 8601 timestamp when the notification was generated
leidabooleanWhether the user has marked this notification as read
export interface Notificacion {
  id: string;
  mensaje: string;
  tipo: 'info' | 'alerta' | 'error';
  fecha: string;
  leida: boolean;
}

EstadisticaVenta

A single data point in a daily sales chart series. Arrays of EstadisticaVenta power the dashboard trend charts.
FieldTypeRequiredDescription
fechastringISO 8601 date string for the data point
ventasnumberTotal sales amount (CLP) recorded on that date
export interface EstadisticaVenta {
  fecha: string;
  ventas: number;
}

All interfaces above live in src/types/index.ts and are imported across every page and component in the application. When adding a new field to the database, update this file first to keep the type system in sync with the schema.

Build docs developers (and LLMs) love