Skip to content

refactor(tax-packs): version tax registration validation metadata with country packs - #405

Merged
itsbkm merged 7 commits into
mainfrom
fix/tax-pack-registration-number-format
Aug 19, 2026
Merged

itsbkm merged 7 commits into
mainfrom
fix/tax-pack-registration-number-format

Conversation

@itsbkm

@itsbkm itsbkm commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • 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, falls back to the static countries.ts profile, then null — additive, backward compatible with existing schema-v1 packs.
  • 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 of a blocking error.

Refs #393

Test plan

  • npm run build (backend tsc) — clean
  • npm run lint (backend + frontend) — 0 errors
  • npm run build:frontend — clean, all routes prerender
  • node 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_enabled gating)
  • tests/tax-engine.test.ts, tests/tax-components.test.ts — pass
  • tests/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

@khaira777

Copy link
Copy Markdown
Contributor

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 main, so this branch now has a conflict in frontend/src/app/(dashboard)/settings/page.tsx.

Please rebase onto main and update the new UI code to use useTranslations('settings') with a leaf key (the Settings page no longer uses dotted settings.… keys):

// 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 settings.taxIdFormatWarning message key you added to en/es/pt/fa is already in the correct nested format with ICU params, so no change there. The backend and test changes are independent and shouldn't conflict.

Once rebased and pushed, CI should go green and we can merge. 🙏

@itsbkm
itsbkm force-pushed the fix/tax-pack-registration-number-format branch from 8655699 to 4f0235f Compare August 19, 2026 19:14
…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]>
@itsbkm
itsbkm force-pushed the fix/tax-pack-registration-number-format branch from c6f5b3a to b6b40a8 Compare August 19, 2026 20:23
@khaira777
khaira777 enabled auto-merge (squash) August 19, 2026 20:24
@khaira777
khaira777 disabled auto-merge August 19, 2026 20:25
@greptile-apps

greptile-apps Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR versions tax-registration format metadata through signed country packs and changes invalid tax IDs from blocking errors into frontend warnings.

  • Adds pack-level registration-format metadata and activation validation.
  • Resolves active-pack formats through business and tax settings responses.
  • Adds localized, non-blocking Tax ID guidance with bounded regex evaluation.
  • Extends tax-pack compatibility and resolution-chain tests.

Confidence Score: 4/5

The 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 tax_id_format before ensure-country activates the destination pack, and no post-activation state update refreshes that format.

Files Needing Attention: frontend/src/app/(dashboard)/settings/page.tsx

Important Files Changed

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
Loading

Reviews (6): Last reviewed commit: "fix(tests): correct CodeQL suppression c..." | Re-trigger Greptile

Comment thread main/tax-packs/types.ts Resolved
- 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]>
Comment thread main/routes/tax-packs.ts Resolved
itsbkm and others added 2 commits August 20, 2026 02:08
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]>
Comment thread tests/tax-pack-management.test.ts Fixed
itsbkm and others added 2 commits August 20, 2026 02:26
…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]>
Comment thread tests/tax-pack-management.test.ts Dismissed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants