Use this file to discover all available pages before exploring further.
The Clients module is the commercial foundation of B2B Import ERP. It centralises all information about the B2B companies your tenant serves — from the moment a company is registered as a prospect through its active commercial relationship, potential inactivation, and final archival. Every mutation is fully scoped to your tenant via Row Level Security and recorded in both the technical audit_log and the semantic business_events table.
Clients move through a defined set of states enforced by database-level triggers. No status change can be performed directly against the database; all transitions must go through domain services that validate permissions, record audit entries, and emit business events.
Client pauses operations or relationship placed on hold
ACTIVO → BLOQUEADO
Compliance or payment issue requires immediate restriction
BLOQUEADO → ACTIVO
Block lifted; client reinstated
INACTIVO → ACTIVO
Client relationship reactivated
INACTIVO → ARCHIVADO
Permanently closed; soft-deleted from active views
The transitions PROSPECTO → ARCHIVADO and BLOQUEADO → ARCHIVADO are not permitted. A blocked client must be unblocked first; a prospect must be activated before it can be archived.
Each client can have multiple contacts stored in the client_contacts table. One contact per client may be designated as the primary contact using the is_primary flag.
Field
Type
Description
id
uuid
Primary key
client_id
uuid
FK to clients.id
first_name
varchar(100)
Contact’s first name (required)
last_name
varchar(100)
Contact’s surname
position
varchar(150)
Job title or role
email
varchar(200)
Contact email
phone / mobile
varchar(50)
Direct phone numbers
is_primary
boolean
Marks the main point of contact
status
enum
ACTIVO · INACTIVO
Only one contact per client can hold is_primary = true. The trigger trg_handle_primary_contact automatically demotes the previous primary contact when a new one is promoted — no manual cleanup is required.
getClients(tenantCode?)Returns all non-deleted clients for the resolved tenant, ordered by creation date descending.
const clients = await getClients("acme");
createClient
createClient(tenantCode, clientData)Creates a new client in PROSPECTO status. The client_code is auto-generated by the database trigger as CLI-XXXXXX. An audit log entry is written automatically via process_audit_log().
Contact-level events (CONTACT_CREATED, CONTACT_UPDATED, CONTACT_DELETED, CONTACT_PRIMARY_CHANGED) and site events (CLIENT_SITE_CREATED, CLIENT_SITE_UPDATED, CLIENT_SITE_DELETED) are emitted by their respective triggers.
RLS policies enforce tenant_id isolation at the database row level. It is impossible for a user in tenant A to read or write records belonging to tenant B, regardless of the application layer.