feat: complete Phases 2 to 5 inclusive - Access Core, Web Cockpit, Hardware enqueuing, Optical Scanner and QA (v0.5.0-beta)

This commit is contained in:
Carlos Tello
2026-10-13 15:47:43 -03:00
parent 78c1a306de
commit 1ba74f7929
53 changed files with 4000 additions and 279 deletions
+54
View File
@@ -0,0 +1,54 @@
// ==============================================================================
// API de Control de Accesos (Ingreso, Salida, Activos, Búsquedas y DNI)
// ==============================================================================
import { request } from './client';
import {
EntryFormData,
ExitRequestData,
TicketResponse,
ActiveTicket,
PersonSearchItem,
LotSearchItem,
DNIParsedResult,
} from '../types';
export const accessApi = {
registerEntry: (data: EntryFormData) => {
return request<TicketResponse>('/access/entry', {
method: 'POST',
body: JSON.stringify(data),
});
},
registerExit: (data: ExitRequestData) => {
return request<TicketResponse>('/access/exit', {
method: 'POST',
body: JSON.stringify(data),
});
},
getActiveTickets: () => {
return request<ActiveTicket[]>('/access/tickets/active', {
method: 'GET',
});
},
searchPeople: (query: string) => {
return request<PersonSearchItem[]>(`/access/people/search?q=${encodeURIComponent(query)}`, {
method: 'GET',
});
},
searchLots: (query: string) => {
return request<LotSearchItem[]>(`/access/lots/search?q=${encodeURIComponent(query)}`, {
method: 'GET',
});
},
parseDni: (rawData: string) => {
return request<DNIParsedResult>('/access/parse-dni', {
method: 'POST',
body: JSON.stringify({ raw_data: rawData }),
});
},
};
+32
View File
@@ -0,0 +1,32 @@
// ==============================================================================
// API de Autenticación
// ==============================================================================
import { request } from './client';
import { UserSession } from '../types';
export interface LoginResponse {
status: string;
user: UserSession;
workstation: string;
}
export const authApi = {
login: (username: string, password: string, workstation_name: string) => {
return request<LoginResponse>('/auth/login', {
method: 'POST',
body: JSON.stringify({ username, password, workstation_name }),
});
},
logout: () => {
return request<{ status: string; message: string }>('/auth/logout', {
method: 'POST',
});
},
getMe: () => {
return request<UserSession>('/auth/me', {
method: 'GET',
});
},
};
+51
View File
@@ -0,0 +1,51 @@
// ==============================================================================
// Cliente HTTP Fetch con soporte para cookies HttpOnly y tipado estricto
// ==============================================================================
const BASE_URL = '/api/v1';
export class ApiError extends Error {
status: number;
data: any;
constructor(status: number, message: string, data?: any) {
super(message);
this.status = status;
this.data = data;
this.name = 'ApiError';
}
}
export async function request<T>(endpoint: string, options: RequestInit = {}): Promise<T> {
const url = endpoint.startsWith('http') ? endpoint : `${BASE_URL}${endpoint}`;
const headers = new Headers(options.headers || {});
if (!headers.has('Content-Type') && !(options.body instanceof FormData)) {
headers.set('Content-Type', 'application/json');
}
const response = await fetch(url, {
...options,
headers,
credentials: 'include', // Para incluir cookie HttpOnly access_token
});
if (response.status === 204) {
return {} as T;
}
const contentType = response.headers.get('content-type');
let data: any = null;
if (contentType && contentType.includes('application/json')) {
data = await response.json();
} else {
data = await response.text();
}
if (!response.ok) {
const errorMsg = data?.detail || data?.message || `Error HTTP ${response.status}`;
throw new ApiError(response.status, errorMsg, data);
}
return data as T;
}
+22
View File
@@ -0,0 +1,22 @@
// ==============================================================================
// API de Hardware y Apertura Manual
// ==============================================================================
import { request } from './client';
export interface HardwareCommandResponse {
status: string;
modulo_id: number;
address: number;
payload: string;
message: string;
latencia_ms: number;
}
export const hardwareApi = {
manualOpen: (moduloId: number, motivo: string = 'APERTURA_MANUAL_GUARDIA', ticketId: number = 0) => {
return request<HardwareCommandResponse>(`/hardware/modules/${moduloId}/open`, {
method: 'POST',
body: JSON.stringify({ modulo_id: moduloId, motivo, ticket_id: ticketId }),
});
},
};
+13
View File
@@ -0,0 +1,13 @@
// ==============================================================================
// API de Puestos de Control y Estaciones
// ==============================================================================
import { request } from './client';
import { WorkstationConfig } from '../types';
export const workstationApi = {
getConfig: (workstationName: string) => {
return request<WorkstationConfig>(`/control-posts/${encodeURIComponent(workstationName)}/config`, {
method: 'GET',
});
},
};