feat(frontend): add test deps, VAT types, and business info store

Add jsdom and vitest dev dependencies. Add total_vat_amount and total_net_amount to PaymentSummary type. Create shared businessInfo store for caching public business settings.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-22 17:06:31 +01:00
co-authored by Sisyphus
parent 21560ea451
commit 194aacf68c
3 changed files with 41 additions and 1 deletions
+3 -1
View File
@@ -36,6 +36,7 @@
"eslint-plugin-svelte": "^3.0.0", "eslint-plugin-svelte": "^3.0.0",
"formsnap": "^2.0.1", "formsnap": "^2.0.1",
"globals": "^17.3.0", "globals": "^17.3.0",
"jsdom": "^29.1.1",
"mode-watcher": "^1.1.0", "mode-watcher": "^1.1.0",
"prettier": "^3.8.1", "prettier": "^3.8.1",
"prettier-plugin-svelte": "^3.5.0", "prettier-plugin-svelte": "^3.5.0",
@@ -54,7 +55,8 @@
"tw-animate-css": "^1.4.0", "tw-animate-css": "^1.4.0",
"typescript": "^5.9.3", "typescript": "^5.9.3",
"typescript-eslint": "^8.20.0", "typescript-eslint": "^8.20.0",
"vite": "^7.0.4" "vite": "^7.0.4",
"vitest": "^4.1.9"
}, },
"dependencies": { "dependencies": {
"@discourse/jxl": "^1.3.0", "@discourse/jxl": "^1.3.0",
@@ -0,0 +1,36 @@
// src/lib/stores/businessInfo.svelte.ts
import type { BusinessSettings } from '$lib/types/settings';
let businessInfo = $state<BusinessSettings | null>(null);
let loadingPromise: Promise<BusinessSettings | null> | null = null;
/**
* Fetches /api/business-info exactly once and caches the result.
* Subsequent calls return the cached promise or resolved value.
* Errors are handled gracefully — returns null.
*/
export async function ensureBusinessInfo(): Promise<BusinessSettings | null> {
if (businessInfo !== null) return businessInfo;
if (loadingPromise) return loadingPromise;
loadingPromise = fetch('/api/business-info')
.then((r) => (r.ok ? r.json() : null))
.then((data) => {
businessInfo = data as BusinessSettings | null;
return businessInfo;
})
.catch(() => {
businessInfo = null;
return null;
});
return loadingPromise;
}
/**
* Returns the current cached business info (reactive via $state).
* Use in $derived or $effect to track changes.
*/
export function getBusinessInfo(): BusinessSettings | null {
return businessInfo;
}
+2
View File
@@ -48,6 +48,8 @@ export interface PaymentSummary {
paid_amount: number; paid_amount: number;
refunded_amount: number; refunded_amount: number;
remaining_amount: number; remaining_amount: number;
total_vat_amount: number;
total_net_amount: number;
payments: Payment[]; payments: Payment[];
refunds: Refund[]; refunds: Refund[];
} }