Flows A1 to A6 and E3 end to end. A visitor types a RUC on the landing page, sees their real filing dates, registers, verifies a six digit code, grants consent, completes a three step setup and lands on the first run screen, with the profile, consent and audit rows to show for it. API: public RUC lookup behind a token bucket (10/min/IP), the full /me surface (profile, dependents, consents, notification prefs, data export, account deletion), an append-only audit module that exports an insert and nothing else, and a PII module that is the only thing allowed near those tables. Deletion and consent revocation both freeze the account and drop every session, reusing better-auth's ban flag rather than adding a second notion of disabled. Nothing is destroyed yet: the purge is a job for phase 4. deadlineDigit is always derived server side, never accepted from the client. Web: landing with the RUC hook, registration, OTP verification, consent, the setup wizard, the profile screen with "Tus datos", and legal pages that ship as marked placeholders per COPY.md section 13. Money, Skeleton, Switch and EmptyState components added. The seed is now complete for identity: Maria at 4123456-1, filing digit 6 and day 19, with a dependant, consents and prefs; Carlos as an IVA-only company. Two real defects found by building the screens and fixed with tests: the OTP boxes dropped a digit because the handler fired effects inside a setState updater that React 19 invokes twice, and the switch knob rendered outside its track because translate-x-5.5 does not resolve. 232 vitest tests, 26 Playwright tests across mobile and desktop, coverage still 100% on the rules, typecheck and lint clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
import type { LookupDto } from '@impuestos/contracts';
|
|
import {
|
|
computeRucDv,
|
|
deadlineDay,
|
|
deadlineDigit,
|
|
dueDateFor,
|
|
formatIsoDate,
|
|
fromDate,
|
|
nextDeadline,
|
|
addMonths,
|
|
} from '@impuestos/rules';
|
|
|
|
const RUC_WITH_DV = /^(\d{1,8})-(\d)$/;
|
|
const BARE_DIGITS = /^\d{1,8}$/;
|
|
|
|
/**
|
|
* The landing hook: type a RUC or a CI and see your own filing dates before creating an
|
|
* account. Public, so it reveals only what the number itself already encodes: the check
|
|
* digit and the calendario perpetuo day. It never touches the database.
|
|
*
|
|
* An unparseable number is a valid response with `valid: false`, not an error, so the
|
|
* landing can correct the user inline instead of dead ending (CONTRACTS.md section 3).
|
|
*/
|
|
export function lookupNumber(raw: string, now: Date): LookupDto {
|
|
const cleaned = raw.trim().replace(/[.\s]/g, '');
|
|
|
|
const withDv = RUC_WITH_DV.exec(cleaned);
|
|
if (withDv) {
|
|
const base = withDv[1] as string;
|
|
const dv = Number(withDv[2]);
|
|
return build({ base, dv, docType: 'ruc', valid: computeRucDv(base) === dv, now });
|
|
}
|
|
|
|
if (BARE_DIGITS.test(cleaned)) {
|
|
// A bare number is read as a CI. Individuals whose RUC is their CI plus a check digit
|
|
// can type either, and the filing day is the same for both.
|
|
return build({ base: cleaned, dv: null, docType: 'ci', valid: true, now });
|
|
}
|
|
|
|
return invalid();
|
|
}
|
|
|
|
function build(args: {
|
|
base: string;
|
|
dv: number | null;
|
|
docType: 'ruc' | 'ci';
|
|
valid: boolean;
|
|
now: Date;
|
|
}): LookupDto {
|
|
if (!args.valid) return { ...invalid(), docType: args.docType, base: args.base, dv: args.dv };
|
|
|
|
const digit = deadlineDigit(args.base);
|
|
return {
|
|
valid: true,
|
|
docType: args.docType,
|
|
base: args.base,
|
|
dv: args.dv,
|
|
deadlineDigit: digit,
|
|
deadlineDay: deadlineDay(digit),
|
|
nextDeadlines: nextThreeIvaDeadlines(digit, args.now),
|
|
};
|
|
}
|
|
|
|
/** The next three monthly IVA due dates, which is what the landing card shows. */
|
|
function nextThreeIvaDeadlines(digit: number, now: Date): string[] {
|
|
const first = nextDeadline({ digit, obligation: 'iva_120', from: now });
|
|
return [0, 1, 2].map((offset) =>
|
|
formatIsoDate(
|
|
offset === 0
|
|
? fromDate(first.dueDate)
|
|
: dueDateFor('iva_120', addMonths(first.period, offset), digit),
|
|
),
|
|
);
|
|
}
|
|
|
|
function invalid(): LookupDto {
|
|
return {
|
|
valid: false,
|
|
docType: 'ruc',
|
|
base: '',
|
|
dv: null,
|
|
deadlineDigit: 0,
|
|
deadlineDay: deadlineDay(0),
|
|
nextDeadlines: ['', '', ''],
|
|
};
|
|
}
|