/** * Cliente API — Datos fiscales del emisor (una configuración por empresa). */ import { api } from '$lib/api'; import type { SatTaxRegime } from './catalogs'; /** RFC de persona moral (3 letras) o física (4 letras) + fecha + homoclave. */ export const RFC_REGEX = /^[A-ZÑ&]{3,4}\d{6}[A-Z0-9]{3}$/; export interface IssuerSettings { id: number; tenant_id: number; company_id: number; legal_name: string; rfc: string; tax_regime_id: number; tax_regime: SatTaxRegime | null; zip_code: string | null; updated_by: string | null; created_at: string; updated_at: string; } export interface IssuerSettingsInput { legal_name: string; rfc: string; tax_regime_id: number; zip_code?: string | null; } export const issuerAPI = { /** * Devuelve `null` cuando la empresa todavía no captura sus datos fiscales: el * backend responde 404 y la pantalla debe abrirse en modo alta, no en error. */ async get(companyId: number): Promise { const res = await api.get(`/v1/fin/settings/issuer?company_id=${companyId}`); if (res.status === 404) return null; if (res.error) throw new Error(res.error); return res.data!; }, async save(data: IssuerSettingsInput, companyId: number): Promise { const res = await api.put( `/v1/fin/settings/issuer?company_id=${companyId}`, data ); if (res.error) throw new Error(res.error); return res.data!; } };