# Changelog

Format based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
adhering to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.6.0] - 2026-10-12

> 0.4.0 and 0.5.0 were never published: this release carries everything since 0.3.0.

### ⚠ Changed — `TaxLineComponent.role` is required

Every component a `TaxResolver.computeLine` returns now states what it IS: `'primary'` (the jurisdiction's main consumption tax — VAT, GST, sales tax — printed as "the" rate) or `'duty'` (a levy charged beside it: a supplementary duty, an excise). A reader never infers it from `name`, which is display text. **A pack must set it** (`TaxComponentRole` is exported); the bundled `./flat` resolver does.

### Added — `./math`: the one rate arithmetic

`taxOnExclusive`, `taxInInclusive`, `scaledRate`, `divideHalfUp` and `InvalidTaxRateError`. A rate is an exact percent with at most four decimals (15, 7.5, 9.975) and is applied in integer minor units with bigint arithmetic, rounding the TAX amount half away from zero. No pack divides by `1 + rate` in floating point.

### Added — `./document`: the one algorithm from a priced document to its tax breakdown

`computeDocumentTax` takes a sale or purchase document (line net = amount − line discount; the document discount allocated over the discountable lines by largest remainder; each consideration rated by the pack on the document's price basis) and returns the breakdown stored on the document: inclusive means gross is the consideration, exclusive means net is. Totals are sums of the lines, never re-rounded, and every invariant is checked and THROWN (`TaxDocumentError`). `verifyDocumentTax` re-checks a stored breakdown; `refundTaxOf` and `partialTaxShare` read a refund off it. Needs `@classytic/primitives >=0.31.1` (`split-allocation`).

### Added — `./sale`: the one adapter from a sale to that input

`rateSale` turns a sale (web placement, the till, an offline till, a preview) into the document input: each line at its own class and quantity, the composed discount, and the delivery charge as its own line (`SALE_DELIVERY_LINE_ID`). An unknown class or a document the algorithm refuses is `SaleUnratedError` (422) — refused, never priced.

### Added — rule editions

`freezeRuleEdition` returns a deep, frozen copy of a pack's rule rows that shares nothing with its input (dates lose their setters too, since `Object.freeze` alone leaves `Date#setTime` working). `ruleEditionFingerprint(scope, edition)` is a stable fingerprint of an edition's content, so an answer can name the edition that produced it.

### Added — `createNotRegisteredTaxResolver` (`./flat`)

`createNotRegisteredTaxResolver(countryCode, reason)` is the resolver for a seller NOT registered for the tax: every class is not taxable, with the stated reason recorded on each line, so its sales are rated zero by a decision a reader can see.

### Changed — peer floor raised to current

`@classytic/primitives` `>=0.23.0` → **`>=0.31.1`**. Verified on a fresh install.

### Also in this release (first written for 0.4.0)

### Added — `./depreciation`: the contract for income-tax depreciation
`TaxDepreciationRegime` is what a country implements: `yearOf`/`yearsBetween` for its own tax-year labels, `listClasses`, `classOfCategory` (an unknown category maps to the residual class), `questions` (the facts the accountant confirms, renderable by a UI that knows no country), and `schedule(facts, throughYear)`. Rows carry the year's allowances and what a sale gives rise to (`disposal.outcomes`: balancing charge or loss, capital gain). The schedule is derived from register facts, never stored. `basis: 'pool'` is declared for block-of-assets regimes, and only `'asset'` is served. A question may be `onlyWhenDisposed` (e.g. a market value at sale). `yearEnd(year)` gives the instant closing values are compared with the books. Also `checkTaxTreatmentAnswers`, `taxDepreciationRegimeConformance` and `TaxDepreciationUnsupportedError`.

### Fixed — one credit identity, several documents
`creditFromRegister` merges entries sharing a `registerEntryKey` (`mergeRegisterEntries`, exported): two bills raised from one purchase order are one claim, tax added, base added only when every part recorded one.

- `./flat`: `createFlatTaxResolver({ countryCode, pricesIncludeTax, classes })` — the jurisdiction pack
  for a shop whose country has no dedicated pack: shop-declared rates (VAT 15%, GST 5%), inclusive or
  exclusive, exact bigint arithmetic rounded half-up. Implements `TaxResolver.computeLine`; an
  undeclared class is `unknown` (refused by `taxLineOrThrow`), and a 0% class must state its reason.

- `./input-credit`: the country-neutral purchase-register contract — `PurchaseRegisterEntry`,
  `InputCreditJudge` (a pack's rules), `InputCreditVerdict`, `InputCreditBasis`, and the pure
  `creditFromRegister` (claimable tax by rate + the refused-document worklist).
- `RuleProvenance.citations` / `StatuteCitation` — machine-checkable evidence on a rule row.

- `WithholdingComponent.requiresCounterpartyDocument` — the deduction is certified against the
  counterparty's own document, so the bill must carry its number.

### Added
- `WithholdingComponent.point?: 'invoice' | 'payment'` (`WithholdingPoint`) — when the jurisdiction takes
  the withholding. Absent means `'invoice'`, unchanged behaviour.
- `./tax-identity` — `TaxIdentityRules` (`label`, `expectedFormat?`, `isValid`, `format?`): how a
  jurisdiction reads a party's tax registration number. A pack exports one; the party stores
  `{ countryCode, taxId }` and names no jurisdiction.

## [0.3.0] - 2026-08-17

### Added

- **`obligationKeyOf(obligation, registrationId)`** — deterministic, registration-scoped idempotency key; runtime-guards against blank `registrationId` (silent shared-key bug)
- **`obligationEntryKey`** — per-entry key helper
- **`PartialObligationPostingError`** — thrown when a multi-entry obligation posts partially without a transaction session; carries `posted` / `failed` arrays
- **`UnknownTaxClassError`** / **`taxLineOrThrow`** — resolver-side refusal for unrecognised tax classes
- **`TaxLineResolution`** type exported from root barrel
- `PostObligationOptions.registrationId` — required field (was absent; callers must pass it)
- Peer `@classytic/primitives` floor raised to `>=0.23.0`

## [0.1.1] - 2026-07-08

### Added

- **Per-line computation shapes** (`TaxLineInput`, `TaxLineComputation`, `TaxLineComponent`) — country-neutral in / country-specific breakdown out; the host calls `resolver.computeLine(...)` and posts each component via `accountFor`.
- **Withholding shapes** (`WithholdingInput`, `WithholdingComponent`) — deducted-at-source surface (BD TDS/VDS, US 1099 backup withholding); keyed by payee + payment attributes, not by line tax class.
- **`TaxResolver.computeLine?` / `computeWithholding?`** (optional methods) — packs adopt incrementally; callers guard with `typeof resolver.computeLine === 'function'`. Returns `null`/`[]` for exempt or below-threshold cases.
- All five new types re-exported from the root barrel (`.`).

## [0.1.0] - 2026-07-04

Initial release — the shared contracts extracted once two jurisdictions
existed (BD in production at `@classytic/bd-tax`; CA demanded by the fajr
host). Every shape is lifted from a WORKING pairing, not invented:

- **`./resolver`** — the invoice-time contract, lifted verbatim from the
  be-prod consumer contract ↔ `createBdTaxResolver` pairing: `TaxResolver`,
  `TaxClassRate`, `FiscalPositionResult`, `PostingDirection`,
  `AccountingRegime` (widened to country vocabulary), plus
  `TaxPackDescriptor` for host/AI introspection.
- **`./obligation`** — the filing-time contract from the fajr
  `packages/tax/PLAN.md` design, hardened: `TaxEngine` / `TaxObligation`
  (integer minor units, generic breakdown) / `LedgerPostingAdapter` /
  `wireTaxToLedger` — sequential fail-fast posting with session
  threading (atomic under a host transaction), instead of the plan's
  order-losing `Promise.all`.
- **`./effective`** — the effective-dated window kernel extracted from
  bd-tax 0.3.0 (`isEffectiveAt` / `effectiveEntries` / `firstEffectiveAt`
  / `latestEntry`) + `RuleProvenance`.
- **`./registry`** — `createLayeredRules` + `createKeyedOverrides`,
  generalized from bd-tax's `extendBdTaxRules` seam as instance factories
  (per-pack isolation; packs may expose module-level facades).
- **`./ledger`** — `TaxCode` / `TaxRepartitionLine` / `TaxReportLine` /
  `TaxReportTemplate` / `TaxCodesByRegion`, the shapes previously
  duplicated in `@classytic/ledger-bd` and `@classytic/ledger-ca` (both
  carried "will eventually move to the tax package" notes — this is that
  move; country packs re-export from here going forward).

Aligned with `@classytic/primitives >= 0.9` via TYPE-ONLY imports
(declared as a peer; runtime stays dependency-free): `TaxPeriod extends
DateRange`, `currency` fields accept the branded `CurrencyCode`, and
minor-unit docs reference `minorUnitFactor`/`Money`.

Zero runtime dependencies. ESM only, Node ≥ 20,
`exactOptionalPropertyTypes`. 12 tests.
