Repository navigation
Closed
Labels
Description
Refs: #388
Context
FloCafe uses signed, versioned Country Tax Packs to distribute regional tax categories, rules, and regulatory labels (such as GSTIN for India, CUIT for Argentina, RFC for Mexico). When a merchant saves business settings in Settings, the tax registration number is validated against a country-specific pattern.
Verified Current Behavior
- CountryPack Schema (
main/tax-packs/types.tslines 42-63):CountryPackdeclaresregistrationNumberLabel: string(e.g. "GSTIN", "CUIT"), but contains no validation pattern metadata. - Static Country Profiles (
main/countries.tslines 3-7, 27-33, 50-97):TaxIdFormat(pattern,description) is hardcoded statically in application source code. - Format Resolution (
main/services/tax.tslines 117-135):export function resolveTaxIdFormat(country: string): TaxIdFormat | null { if (!isTaxModuleActiveForCountry(country)) return null; return getCountryByCode(country)?.taxIdFormat || null; }
resolveTaxIdFormatqueriesgetCountryByCode(country)?.taxIdFormatfrom static application memory.
Problem
Because tax registration format regex patterns are embedded in the static application binary:
- An official signed country tax pack cannot update or correct a regulatory tax identifier validation rule without requiring a full FloCafe desktop release.
- Regulatory validation metadata remains split across two separate systems (
CountryPackfor rates/labels,countries.tsfor regex formats).
Architectural Decision
- Allow
CountryPackto optionally declare versioned tax registration number validation metadata (e.g.registrationNumberFormat?: TaxIdFormat). - Additive / Backward-Compatible Resolution Chain:
- Active signed tax pack
registrationNumberFormat(if present and valid). - Static country profile
taxIdFormatfallback (if present). - No enforced pattern (
null/ pass-through; never reject valid inputs if no format is declared).
- Active signed tax pack
- Additive Schema Extension: Keep
schemaVersion: 1with an optional field so existing installed packs continue loading without validation failures or breaking migrations. - Validation Scope: Registration number validation applies to current merchant configuration saves (
PUT /api/settings/business). Historical transactions, orders, and bills are immutable snapshots and must never be retroactively invalidated by pack updates. - TaxEngine Arithmetic: Calculation logic is separate and remains untouched.
Exact Implementation Scope
- Type Definitions (
main/tax-packs/types.ts):- Add optional
registrationNumberFormat?: TaxIdFormattoCountryPack.
- Add optional
- Format Resolution Service (
main/services/tax.ts):- Update
resolveTaxIdFormat(country)to:- Check
getActiveCountryPack(country)?.registrationNumberFormat. - If absent, fall back to
getCountryByCode(country)?.taxIdFormat. - If neither exists, return
null.
- Check
- Update
- Compatibility & Integrity:
- Ensure pack signature checks and pack loader accept the optional field cleanly.
- Maintain compatibility across existing local/custom packs and older databases.
- Tests:
- Extend
tests/tax-components.test.tsandtests/tax-pack-management.test.tsto verify pack-provided format resolution, fallback behavior, and backward compatibility with v1 packs lacking this field.
- Extend
Required Behavior
- An official tax pack defining
registrationNumberFormatenforces that pattern during Settings tax registration number updates. - An installed tax pack omitting
registrationNumberFormatfalls back gracefully to the staticcountries.tspattern. - A country with no declared pattern allows saving any non-empty registration string without format error.
- Existing installed schema-v1 tax packs load and activate without schema errors.
- Historical bills and transactions remain unaffected.
Backward Compatibility / Upgrade Behavior
- Fully backward-compatible additive field.
- No database migration or pack invalidation required.
Offline-First Requirements
- 100% offline. Operates using local SQLite-persisted tax pack manifests and local validators.
Non-Goals / What NOT to Do
- Do NOT rewrite TaxEngine calculation, rounding, or surcharge logic.
- Do NOT introduce a breaking
schemaVersion: 2bump that invalidates installed schema-v1 packs. - Do NOT retroactively validate or reject historical bills/orders.
- Do NOT make
registrationNumberFormatmandatory.
Acceptance Criteria
-
CountryPacktype definition includes optionalregistrationNumberFormat. -
resolveTaxIdFormat(country)prioritizes the active country tax pack format when present, falling back to staticcountries.ts. - Existing installed tax packs lacking the format field continue to load and function normally.
- Settings business update route (
PUT /api/settings/business) validates tax IDs against the resolved pattern. - Historical tax snapshots and transaction records remain unchanged.
Verification
npm run lint:backend
npm run test:tax-engine
npm run test:tax-components
npm run test:tax-pack-catalog
npm run test:tax-pack-management
npm testDependencies
- Independent of UI translation (refactor(i18n): migrate to scalable use-intl architecture #372). Belongs to Phase 4.
Relationship to Epic
- Part of Phase 4 — Compliance Boundary Cleanup in Epic refactor(regionalization): harden country, regional formatting, and international data boundaries #388.
Activity
refactor(tax-packs): version tax registration validation metadata wit…
refactor(tax-packs): version tax registration validation metadata wit…
refactor(tax-packs): version tax registration validation metadata wit…
itsbkm commentedon Aug 20, 2026
Implemented and merged via #405 ("refactor(tax-packs): version tax registration validation metadata with country packs"), which was referenced with "Refs #393" rather than a closing keyword so this wasn't auto-closed. Verified in code:
registrationNumberFormatis present onCountryPack(main/tax-packs/types.ts) andresolveTaxIdFormat()in main/services/tax.ts prefers the active pack's format before falling back to the staticcountries.tsprofile, per the acceptance criteria.khaira777 commentedon Aug 20, 2026
Status update — 2026-08-20
✅ Complete. This issue was implemented and merged via PR #405, and remains closed as completed.
khaira777 commentedon Aug 20, 2026
Status update — 2026-08-20
✅ Original issue complete and closed. PRs #405 and #407 are merged. Post-merge hardening is tracked separately in open PR #434, currently at
75883b36with CI in progress; the original issue remains closed because its implementation was already merged.fix: issue #393 tax id followups (#434)
khaira777 commentedon Aug 21, 2026
Final status update — 2026-08-21
✅ Complete, including post-merge hardening. Follow-up PR #434 merged at
8730fc04after all required CI and Greptile checks passed. The tax-registration validation, silent-save format propagation, and submitted-country format association are now delivered. This issue remains closed.