* fix(customers): stop personnummer landing unmasked as org_number, persist personal_number on v1, default payment terms from settings
Closes #1707. Closes #1708.
Personnummer (#1707, Discord kalletoxic):
- CreateCustomerSchema rejects an org_number shaped like a Swedish
personal identity number on business customer_types. Only
customer_type=individual rows are masked in lists, so accepting one
stored an unmasked personal identifier (GDPR art. 5.1 c). The shape
check uses the month-position rule (legal-entity orgnr always
carries >= 20), so real orgnr can never false-positive.
- The v1 create, v1 PATCH and bulk-create endpoints accepted
personal_number through the shared schema but silently dropped it.
They now store it encrypted, expose it masked (********-1234) on the
single-customer surfaces, and treat the masked form as unchanged,
mirroring the internal routes.
- Route-level guards on both PATCH routes (new 400
CUSTOMER_ORG_NUMBER_IS_PERSONAL) plus a client-side message in
CustomerForm (sv + en).
Payment terms (#1708, Discord kalletoxic):
- New resolveDefaultPaymentTerms: provided value, else
company_settings.invoice_default_days, else 30. Wired into the UI
new-customer dialog, the internal POST, v1 create (incl. dry-run),
bulk-create and the MCP staged create_customer.
apiskill regenerated; no migrations.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* docs: record what the CI build OOM actually was
main raised the build heap to 8192 in parallel with this branch, so the
fix itself is already in and this keeps it untouched. What was missing
is the diagnosis.
Measured with tsc --noEmit --extendedDiagnostics, type-checking the repo
needs 4 192 550 K at 506d030b and 4 187 096 K on this branch, 5 MB less
and 0.26% more instantiations. So the ceiling is the type-check pass at
steady state against Node 20's ~4 GB default old-space, not bundle
growth and not any single PR. Worth writing down so the next person who
sees "Ineffective mark-compacts near heap limit" does not go looking for
it in their own diff.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
40 lines
1.7 KiB
TypeScript
40 lines
1.7 KiB
TypeScript
/**
|
|
* Shape detection for Swedish personal identity numbers submitted where an
|
|
* organisationsnummer belongs.
|
|
*
|
|
* A legal-entity organisationsnummer always carries 20 or higher in its
|
|
* "month" position (SFS 1974:174 2 §), while a personnummer has a real
|
|
* calendar month 01-12 (samordningsnummer offsets the day by 60 instead).
|
|
* That makes the two distinguishable without a checksum: any 10- or
|
|
* 12-digit value with a month of 01-12 and a plausible day is a personal
|
|
* identity number, never a company.
|
|
*
|
|
* Used to stop a personnummer from being stored as a business org_number,
|
|
* where nothing masks it: list responses only mask identifiers on
|
|
* customer_type='individual' rows (GDPR art. 5.1 c data minimisation).
|
|
*
|
|
* Deliberately crypto-free so the client form, the Zod schemas and the
|
|
* server routes can all share it, same as mask-personal-number.ts.
|
|
*/
|
|
export function looksLikeSwedishPersonalNumber(value: string): boolean {
|
|
const digits = value.replace(/[\s+-]/g, '')
|
|
if (!/^(\d{10}|\d{12})$/.test(digits)) return false
|
|
|
|
if (digits.length === 12) {
|
|
// 12-digit organisationsnummer are written with a '16' century prefix
|
|
// (Skatteverket convention); personnummer centuries are 18/19/20.
|
|
const century = digits.slice(0, 2)
|
|
if (century !== '18' && century !== '19' && century !== '20') return false
|
|
}
|
|
|
|
const body = digits.length === 12 ? digits.slice(2) : digits
|
|
const month = parseInt(body.slice(2, 4), 10)
|
|
const day = parseInt(body.slice(4, 6), 10)
|
|
|
|
if (month < 1 || month > 12) return false
|
|
|
|
// Day 1-31 for a personnummer, 61-91 for a samordningsnummer (+60 offset).
|
|
const birthDay = day > 60 ? day - 60 : day
|
|
return birthDay >= 1 && birthDay <= 31
|
|
}
|