Backend: - Notificación email al admin cuando llega primer pago aprobado (sin factura auto) - Endpoints GET /pagos-sin-factura y POST /emitir-factura-pago para admin global - Fix vinculación org Facturapi Horux 360 (69f23a5a242e0af47a41fa0d) - Fix webhook MP: validación defensiva de x-signature header - Fix autocompleto RFCs: eliminado filtro por contribuyenteId - Fix autocompleto conceptos: eliminado filtro por contribuyenteId - SAT fixes: anti-bot CSF scraper, request reuse, date range fix, stale job thresholds - SAT sync request reuse across jobs para evitar agotar cuota diaria - Typo fix MP_ACCESS_TOKEN en .env - Trial invitations system backend Frontend: - Nueva página /admin/facturas-pendientes con tabla y emisión manual - Métrica 'Facturas pendientes' en /clientes (clickable) - Navegación onboarding FIEL/CSD corregida - Sidebar themes sincronizados - Fix SAT portal migration scraper (NetIQ) - Trial invitation acceptance pages
108 lines
2.9 KiB
TypeScript
108 lines
2.9 KiB
TypeScript
import { apiClient } from './client';
|
|
|
|
export interface TenantSubscription {
|
|
id: string;
|
|
amount: number;
|
|
currentPeriodEnd: string | null;
|
|
status: string;
|
|
}
|
|
|
|
export interface Tenant {
|
|
id: string;
|
|
nombre: string;
|
|
rfc: string;
|
|
plan: string;
|
|
databaseName: string;
|
|
createdAt: string;
|
|
_count?: {
|
|
/** Memberships activos (matches el `_count.memberships` que retorna `getAllTenants`). */
|
|
memberships: number;
|
|
};
|
|
subscriptions?: TenantSubscription[];
|
|
}
|
|
|
|
export type TenantPlan = 'trial' | 'custom' | 'mi_empresa' | 'mi_empresa_plus' | 'business_control' | 'business_cloud';
|
|
|
|
export interface CreateTenantData {
|
|
nombre: string;
|
|
rfc: string;
|
|
plan?: TenantPlan;
|
|
adminEmail: string;
|
|
adminNombre: string;
|
|
amount?: number;
|
|
/** Solo plan custom: deadline para primer pago (formato ISO YYYY-MM-DD). */
|
|
firstPaymentDueAt?: string | null;
|
|
}
|
|
|
|
export async function getTenants(): Promise<Tenant[]> {
|
|
const response = await apiClient.get<Tenant[]>('/tenants');
|
|
return response.data;
|
|
}
|
|
|
|
export async function getTenant(id: string): Promise<Tenant> {
|
|
const response = await apiClient.get<Tenant>(`/tenants/${id}`);
|
|
return response.data;
|
|
}
|
|
|
|
export async function createTenant(data: CreateTenantData): Promise<Tenant> {
|
|
const response = await apiClient.post<Tenant>('/tenants', data);
|
|
return response.data;
|
|
}
|
|
|
|
export interface UpdateTenantData {
|
|
nombre?: string;
|
|
rfc?: string;
|
|
plan?: TenantPlan;
|
|
active?: boolean;
|
|
amount?: number;
|
|
firstPaymentDueAt?: string | null;
|
|
}
|
|
|
|
export async function updateTenant(id: string, data: UpdateTenantData): Promise<Tenant> {
|
|
const response = await apiClient.put<Tenant>(`/tenants/${id}`, data);
|
|
return response.data;
|
|
}
|
|
|
|
export async function deleteTenant(id: string): Promise<void> {
|
|
await apiClient.delete(`/tenants/${id}`);
|
|
}
|
|
|
|
// ============================================================================
|
|
// Self-serve multi-tenant (memberships del caller)
|
|
// ============================================================================
|
|
|
|
export interface MyTenantDetailed {
|
|
tenantId: string;
|
|
nombre: string;
|
|
rfc: string;
|
|
plan: string;
|
|
role: string;
|
|
isOwner: boolean;
|
|
trialEndsAt: string | null;
|
|
subscription: {
|
|
status: string;
|
|
plan: string;
|
|
amount: number;
|
|
frequency: string;
|
|
currentPeriodEnd: string | null;
|
|
pendingPlan: string | null;
|
|
pendingEffectiveAt: string | null;
|
|
} | null;
|
|
}
|
|
|
|
export async function getMyTenants(): Promise<MyTenantDetailed[]> {
|
|
const response = await apiClient.get<MyTenantDetailed[]>('/tenants/mine');
|
|
return response.data;
|
|
}
|
|
|
|
export interface AddMyTenantData {
|
|
nombre: string;
|
|
rfc: string;
|
|
plan?: 'mi_empresa' | 'mi_empresa_plus' | 'business_control' | 'business_cloud';
|
|
}
|
|
|
|
export async function addMyTenant(data: AddMyTenantData): Promise<{ tenant: Tenant }> {
|
|
const response = await apiClient.post<{ tenant: Tenant }>('/tenants/mine', data);
|
|
return response.data;
|
|
}
|