Repository navigation
refactor(tax-packs): version tax registration validation metadata with country packs - #405
Conversation
|
Thanks @itsbkm! The tax-pack change looks good and matches #393. One update is needed before merge: #404 (the use-intl migration of the Settings page) just landed on Please rebase onto // before
{t('settings.taxIdFormatWarning', { country: form.countryCode, format: taxIdWarning })}
// after (leaf key — the `settings.` namespace is already the hook's scope)
{t('taxIdFormatWarning', { country: form.countryCode, format: taxIdWarning })}The Once rebased and pushed, CI should go green and we can merge. 🙏 |
8655699 to
4f0235f
Compare
…h country packs Lets a signed country tax pack declare an optional registrationNumberFormat so an official publisher can correct/update a regulatory tax-ID pattern without a FloCafe app release. resolveTaxIdFormat() now prefers the active pack's format, falling back to the static countries.ts profile, then null. PUT /api/settings/business and /settings/tax no longer hard-reject a tax ID that fails the resolved pattern (an incomplete GSTIN previously blocked the save entirely); the resolved format is now surfaced as tax_id_format on the business/tax settings responses and shown as a non-blocking warning under the Tax ID field in Settings instead. Refs #393 Co-Authored-By: Claude Sonnet 5 <[email protected]>
c6f5b3a to
b6b40a8
Compare
Greptile SummaryThe PR versions tax-registration format metadata through signed country packs and changes invalid tax IDs from blocking errors into frontend warnings.
Confidence Score: 4/5The PR is not yet safe to merge because first-time country activation can leave the Tax ID warning without the newly activated pack’s format until Settings reloads. The business save resolves and stores Files Needing Attention: frontend/src/app/(dashboard)/settings/page.tsx
|
| Filename | Overview |
|---|---|
| frontend/src/app/(dashboard)/settings/page.tsx | Adds non-blocking Tax ID warnings, stale-country suppression, bounded regex evaluation, and response-driven format state. |
| main/routes/settings.ts | Removes blocking Tax ID rejection and includes the resolved format in business and tax response shapes. |
| main/routes/tax-packs.ts | Adds activation checklist validation for registration-format shape, syntax, and a known catastrophic-regex pattern. |
| main/services/tax.ts | Prefers active-pack registration formats and bounds values before backend regex validation. |
| main/tax-packs/types.ts | Extends schema-v1 country packs with optional registration-number format metadata. |
| tests/tax-pack-management.test.ts | Covers format precedence, static fallback, null behavior, length bounds, and checklist validation. |
Sequence Diagram
sequenceDiagram
participant UI as Settings UI
participant Settings as Business Settings API
participant Packs as Tax Pack API
UI->>Settings: PUT /settings/business (new country)
Settings-->>UI: business + pre-activation tax_id_format
UI->>Packs: POST /tax-packs/ensure-country
Packs-->>UI: destination pack activated
Note over UI: Stored format is not refreshed after activation
Reviews (6): Last reviewed commit: "fix(tests): correct CodeQL suppression c..." | Re-trigger Greptile
- Suppress the tax-ID format warning when the country field has been edited but not yet saved: taxIdFormat is resolved for savedBusiness's country, so labeling a stale pattern with the newly selected country could show incorrect guidance until the save completes. - Add a 25th activation check validating that a pack's optional registrationNumberFormat, when declared, has a syntactically valid regex pattern and a non-empty description, closing the gap where a malformed value could pass activation unnoticed. Co-Authored-By: Claude Sonnet 5 <[email protected]>
check 25 only confirms a pack-declared registrationNumberFormat.pattern compiles, not that it's free of catastrophic backtracking. The Settings page runs that pattern against the Tax ID field on every keystroke, so an unsafe-but-syntactically-valid pattern combined with a long non-matching input could freeze the tab. Cap the tested value at 40 chars — well beyond any real registration-number scheme — bounding worst-case backtracking to milliseconds instead of an unbounded main-thread hang. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…tionNumber's regex The frontend Settings warning already caps the tested value at 40 chars before running a pack-declared registrationNumberFormat.pattern (same ReDoS concern as check 25 permitting a syntactically-valid-but-unsafe pattern). Apply the same bound to validateTaxRegistrationNumber in services/tax.ts, the one other place this pack-declared, not codebase-authored, pattern gets executed against user input. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…patterns A 40-char input bound alone doesn't neuter a truly pathological pattern (2^40 backtracking steps still freezes the tab). Add a heuristic to check 25 that rejects the textbook nested-quantifier ReDoS shape — (x+)+, (x*)+, (x+y+)*, etc. — at pack-activation time, so a pack that ships one by mistake can never go active. This isn't a formal safety proof (general ReDoS detection is undecidable), so keep the input-length bound as a backstop too, tightened from 40 to 24: the longest real registration- number scheme (India GSTIN) is 15 chars, so 24 leaves generous headroom while keeping any pattern that slips past the heuristic imperceptibly fast even in its worst case. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…est fixture The check-25 rejection test embeds the textbook (A+)+ catastrophic- backtracking shape as fixture data specifically to prove validationChecklist rejects it — CodeQL correctly recognizes the shape but can't tell this is a negative-test fixture that's never compiled or run against untrusted input outside that reject path. Suppress with an inline codeql[] comment. Co-Authored-By: Claude Sonnet 5 <[email protected]>
CodeQL's actual alert for the deliberately-catastrophic test pattern is js/redos, not js/polynomial-redos — the wrong query id meant the inline codeql[...] suppression never matched the alert. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Summary
registrationNumberFormatso an official publisher can correct/update a regulatory tax-ID pattern without a FloCafe app release.resolveTaxIdFormat()now prefers the active pack's format, falls back to the staticcountries.tsprofile, thennull— additive, backward compatible with existing schema-v1 packs.PUT /api/settings/businessand/settings/taxno longer hard-reject a tax ID that fails the resolved pattern (an incomplete GSTIN previously blocked the save entirely). The resolved format is now surfaced astax_id_formaton the business/tax settings responses and shown as a non-blocking warning under the Tax ID field in Settings instead of a blocking error.Refs #393
Test plan
npm run build(backendtsc) — cleannpm run lint(backend + frontend) — 0 errorsnpm run build:frontend— clean, all routes prerendernode tests/run-electron-node-test.cjs tests/tax-pack-management.test.ts— 155/155 passed (adds 5 new assertions covering the resolution chain: pack override wins, fallback to static, null pass-through,taxes_enabledgating)tests/tax-engine.test.ts,tests/tax-components.test.ts— passtests/translations.test.ts— pass (new i18n key added to en/es/pt/fa with parity)tests/e2e-argentina-flow.test.ts,tests/issue-265-morocco-profile.test.ts,tests/issue-263-phone-normalization.test.ts,tests/issue-266-currency-symbol-print.test.ts— pass (no regressions on settings/business responses)🤖 Generated with Claude Code