Logos (PNG, JPEG, WebP) are decoded, trimmed to their ink box, downscaled to 1200 px and re-encoded as a content-addressed print PNG plus a white knockout variant when the logo has alpha; aspect, ink density, mean colour and kind (wordmark, mark, tall) are stored with the settings and frozen in the issue snapshot. Legacy logos are derived at startup. The Test Vendor logo PDF shrinks from 334 KB to 92 KB. Settings gains a Branding section with white and dark previews and a business-name toggle (migration M5).
79 lines
3.6 KiB
TypeScript
79 lines
3.6 KiB
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
import type {
|
|
BankAccount,
|
|
Client,
|
|
DraftSummary,
|
|
Invoice,
|
|
InvoiceInput,
|
|
InvoiceSeries,
|
|
InvoiceSummary,
|
|
Settings,
|
|
} from "./types";
|
|
import type { LogoAsset } from "./logo";
|
|
|
|
export interface ArchiveStatus {
|
|
archived: boolean;
|
|
sha256?: string;
|
|
fingerprint?: string;
|
|
archivedAt?: string;
|
|
}
|
|
|
|
export const api = {
|
|
getSettings: () => invoke<Settings>("get_settings"),
|
|
saveSettings: (settings: Settings) => invoke<Settings>("save_settings", { settings }),
|
|
|
|
listBanks: () => invoke<BankAccount[]>("list_banks"),
|
|
saveBank: (bank: BankAccount) => invoke<BankAccount>("save_bank", { bank }),
|
|
deleteBank: (id: number) => invoke<void>("delete_bank", { id }),
|
|
|
|
getActiveSeries: () => invoke<InvoiceSeries | null>("get_active_series"),
|
|
listSeries: () => invoke<InvoiceSeries[]>("list_series"),
|
|
startNewSeries: (prefix: string, padding: number) =>
|
|
invoke<InvoiceSeries>("start_new_series", { prefix, padding }),
|
|
|
|
listClients: () => invoke<Client[]>("list_clients"),
|
|
saveClient: (client: Client) => invoke<Client>("save_client", { client }),
|
|
deleteClient: (id: number) => invoke<void>("delete_client", { id }),
|
|
|
|
peekNextInvoiceNumber: () => invoke<string>("peek_next_invoice_number"),
|
|
issueInvoice: (input: InvoiceInput, renderPrefs: object) =>
|
|
invoke<Invoice>("issue_invoice", { input, renderPrefs }),
|
|
cancelInvoice: (id: number, reason: string) =>
|
|
invoke<Invoice>("cancel_invoice", { id, reason }),
|
|
listInvoices: () => invoke<InvoiceSummary[]>("list_invoices"),
|
|
getInvoice: (id: number) => invoke<Invoice>("get_invoice", { id }),
|
|
|
|
saveDraft: (id: number | null, payload: unknown) =>
|
|
invoke<number>("save_draft", { id, payload }),
|
|
listDrafts: () => invoke<DraftSummary[]>("list_drafts"),
|
|
getDraft: (id: number) => invoke<unknown>("get_draft", { id }),
|
|
deleteDraft: (id: number) => invoke<void>("delete_draft", { id }),
|
|
|
|
importAsset: (sourcePath: string, kind: string) =>
|
|
invoke<string>("import_asset", { sourcePath, kind }),
|
|
saveAssetBytes: (kind: string, fileName: string, dataBase64: string) =>
|
|
invoke<string>("save_asset_bytes", { kind, fileName, dataBase64 }),
|
|
importLogo: (sourcePath: string) => invoke<LogoAsset>("import_logo", { sourcePath }),
|
|
saveLogoBytes: (fileName: string, dataBase64: string) =>
|
|
invoke<LogoAsset>("save_logo_bytes", { fileName, dataBase64 }),
|
|
ensureLogoDerived: () => invoke<Settings>("ensure_logo_derived"),
|
|
removeLogo: () => invoke<Settings>("remove_logo"),
|
|
readAssetDataUri: (path: string) => invoke<string>("read_asset_data_uri", { path }),
|
|
removeAsset: (path: string) => invoke<void>("remove_asset", { path }),
|
|
|
|
// Raw-body commands: the payload is the bytes themselves (no base64); metadata goes in headers.
|
|
// Header values must be visible ASCII, hence the encodeURIComponent on paths.
|
|
archivePdf: (invoiceId: number, bytes: Uint8Array, fingerprint: string) =>
|
|
invoke<string>("archive_pdf", bytes, {
|
|
headers: { "x-invoice-id": String(invoiceId), "x-fingerprint": fingerprint },
|
|
}),
|
|
readArchive: async (invoiceId: number): Promise<Uint8Array> =>
|
|
new Uint8Array(await invoke<ArrayBuffer>("read_archive", { invoiceId })),
|
|
archiveStatus: (invoiceId: number) => invoke<ArchiveStatus>("archive_status", { invoiceId }),
|
|
writeExportFile: (path: string, bytes: Uint8Array) =>
|
|
invoke<string>("write_export_file", bytes, { headers: { "x-path": encodeURIComponent(path) } }),
|
|
getLastExportDir: () => invoke<string>("get_last_export_dir"),
|
|
revealInFolder: (path: string) => invoke<void>("reveal_in_folder", { path }),
|
|
openFile: (path: string) => invoke<void>("open_file", { path }),
|
|
};
|