Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
85d7dd8
Make Household model canonical for v1/v2 conversion
anth-volk Apr 9, 2026
9baa734
Add household shadow create flow
anth-volk Apr 9, 2026
240a3cf
Implement immutable household reassignment flow
anth-volk Apr 9, 2026
7538883
Adopt household model read paths
anth-volk Apr 10, 2026
761f658
Remove household adapter leftovers
anth-volk Apr 10, 2026
896b0be
Stabilize populations page test fixtures
anth-volk Apr 11, 2026
3c6aa91
Fix household migration lint issues
anth-volk Apr 11, 2026
5cd0488
Centralize household conversions in model
anth-volk Apr 11, 2026
3516830
Refactor household model internals
anth-volk Apr 13, 2026
f996dea
Introduce household type families
anth-volk Apr 13, 2026
6f89b09
Store canonical household setup in model
anth-volk Apr 13, 2026
6e11381
Refactor household v1 codec
anth-volk Apr 13, 2026
e5a8e1e
Refactor household v2 codec
anth-volk Apr 13, 2026
d252f8d
Relax stored v2 household parsing
anth-volk Apr 13, 2026
e9ced23
Collapse legacy household state types
anth-volk Apr 13, 2026
f98951d
Clarify household hook boundaries
anth-volk Apr 13, 2026
7e33404
Finalize household type refactor cleanup
anth-volk Apr 13, 2026
4271e4d
Format household migration files
anth-volk Apr 13, 2026
7930184
Deduplicate Next app query context deps
anth-volk Apr 13, 2026
f455a16
Preserve multi-group household drafts
anth-volk Apr 14, 2026
6f33283
Simplify builder marital units
anth-volk Apr 14, 2026
4eede2e
Revert Next alias dedupe config
anth-volk Apr 14, 2026
43f1478
Clean up household count access
anth-volk Apr 14, 2026
c202f37
Fix household shared-save normalization
anth-volk Apr 15, 2026
61bbec0
Align app households with plural v2 groups
anth-volk Apr 16, 2026
764f6b8
Simplify household model cleanup paths
anth-volk Apr 16, 2026
438d6a8
Clarify household app surfaces
anth-volk Apr 16, 2026
2d8a340
Remove deprecated household type imports
anth-volk Apr 16, 2026
97415f9
Add targeted household association recovery
anth-volk Apr 16, 2026
69861fd
Tighten country-specific v2 household types
anth-volk Apr 16, 2026
e506c87
Fix builder household immutability
anth-volk Apr 16, 2026
3720744
Trigger calculator-next rebuild
anth-volk Apr 16, 2026
7c4772f
Fix calculator typecheck regressions
anth-volk Apr 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 0 additions & 138 deletions app/src/adapters/HouseholdAdapter.ts

This file was deleted.

1 change: 0 additions & 1 deletion app/src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
export { PolicyAdapter } from './PolicyAdapter';
export { SimulationAdapter } from './SimulationAdapter';
export { ReportAdapter } from './ReportAdapter';
export { HouseholdAdapter } from './HouseholdAdapter';

// User Ingredient Adapters
export { UserReportAdapter } from './UserReportAdapter';
Expand Down
4 changes: 2 additions & 2 deletions app/src/api/household.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BASE_URL } from '@/constants';
import { HouseholdMetadata } from '@/types/metadata/householdMetadata';
import type { V1HouseholdMetadataEnvelope } from '@/models/household/v1Types';
import { HouseholdCreationPayload } from '@/types/payloads';

export async function fetchHouseholdById(
country: string,
household: string
): Promise<HouseholdMetadata> {
): Promise<V1HouseholdMetadataEnvelope> {
const url = `${BASE_URL}/${country}/household/${household}`;

const res = await fetch(url, {
Expand Down
2 changes: 1 addition & 1 deletion app/src/api/householdCalculation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PolicyEngineBundle } from '@/api/societyWideCalculation';
import { BASE_URL } from '@/constants';
import { HouseholdData } from '@/types/ingredients/Household';
import type { AppHouseholdInputData as HouseholdData } from '@/models/household/appTypes';

export interface HouseholdCalculationResponse {
status: 'ok' | 'error';
Expand Down
145 changes: 67 additions & 78 deletions app/src/api/v2/householdCalculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,55 @@
* Note: Variation/axes calculations are NOT supported in v2 alpha and remain on v1.
*/

import type { CountryId } from '@/libs/countries';
import type {
V2CreateHouseholdEnvelope,
V2HouseholdCalculationPayload,
V2HouseholdCalculationResult,
V2HouseholdEnvelope,
V2StoredHouseholdEnvelope,
V2UKCreateHouseholdEnvelope,
V2UKHouseholdCalculationResult,
V2USCreateHouseholdEnvelope,
V2USHouseholdCalculationResult,
} from '@/models/household/v2Types';
import { API_V2_BASE_URL } from './taxBenefitModels';
import { cancellableSleep, v2Fetch } from './v2Fetch';

/**
* V2-specific flat household shape used by calculation endpoints.
* This is the v2 API's native format — conversion from the app's
* internal Household type happens in the adapter layer (Phase 2).
*/
export interface V2HouseholdShape {
id?: string;
country_id: CountryId;
year: number;
label?: string | null;
people: Record<string, any>[];
tax_unit?: Record<string, any> | null;
family?: Record<string, any> | null;
spm_unit?: Record<string, any> | null;
marital_unit?: Record<string, any> | null;
household?: Record<string, any> | null;
benunit?: Record<string, any> | null;
}
export type { V2CreateHouseholdEnvelope, V2StoredHouseholdEnvelope };

/**
* Payload sent to POST /household/calculate
*/
export interface HouseholdCalculatePayload {
country_id: CountryId;
year: number;
people: Record<string, any>[];
tax_unit?: Record<string, any> | null;
family?: Record<string, any> | null;
spm_unit?: Record<string, any> | null;
marital_unit?: Record<string, any> | null;
household?: Record<string, any> | null;
benunit?: Record<string, any> | null;
policy_id?: string;
dynamic_id?: string;
}
export type HouseholdCalculatePayload = V2HouseholdCalculationPayload;
export type HouseholdCalculationResult = V2HouseholdCalculationResult;

function householdToCalculatePayload(
household: V2HouseholdShape,
household: V2HouseholdEnvelope,
policyId?: string,
dynamicId?: string
): HouseholdCalculatePayload {
return {
country_id: household.country_id,
year: household.year,
people: household.people,
tax_unit: household.tax_unit ?? null,
family: household.family ?? null,
spm_unit: household.spm_unit ?? null,
marital_unit: household.marital_unit ?? null,
household: household.household ?? null,
benunit: household.benunit ?? null,
policy_id: policyId,
dynamic_id: dynamicId,
};
switch (household.country_id) {
case 'us':
return {
country_id: 'us',
year: household.year,
people: household.people,
tax_unit: household.tax_unit,
family: household.family,
spm_unit: household.spm_unit,
marital_unit: household.marital_unit,
household: household.household,
policy_id: policyId,
dynamic_id: dynamicId,
};
case 'uk':
return {
country_id: 'uk',
year: household.year,
people: household.people,
household: household.household,
benunit: household.benunit,
policy_id: policyId,
dynamic_id: dynamicId,
};
}
}

// ============================================================================
Expand All @@ -91,19 +82,6 @@ export interface HouseholdJobStatusResponse {
error_message: string | null;
}

/**
* Calculation result structure from v2 alpha
*/
export interface HouseholdCalculationResult {
person: Record<string, any>[];
benunit?: Record<string, any>[] | null;
marital_unit?: Record<string, any>[] | null;
family?: Record<string, any>[] | null;
spm_unit?: Record<string, any>[] | null;
tax_unit?: Record<string, any>[] | null;
household: Record<string, any>[];
}

// ============================================================================
// API Functions
// ============================================================================
Expand Down Expand Up @@ -205,36 +183,47 @@ export async function pollHouseholdCalculationJobV2(
*/
export function calculationResultToHousehold(
result: HouseholdCalculationResult,
originalHousehold: V2HouseholdShape
): V2HouseholdShape {
return {
country_id: originalHousehold.country_id,
year: originalHousehold.year,
people: result.person,
// Extract first element from arrays (single household case)
tax_unit: result.tax_unit?.[0] ?? undefined,
family: result.family?.[0] ?? undefined,
spm_unit: result.spm_unit?.[0] ?? undefined,
marital_unit: result.marital_unit?.[0] ?? undefined,
household: result.household?.[0] ?? undefined,
benunit: result.benunit?.[0] ?? undefined,
};
originalHousehold: V2HouseholdEnvelope
): V2CreateHouseholdEnvelope {
switch (originalHousehold.country_id) {
case 'us':
return {
country_id: 'us',
year: originalHousehold.year,
label: originalHousehold.label,
people: (result as V2USHouseholdCalculationResult).person,
tax_unit: (result as V2USHouseholdCalculationResult).tax_unit ?? [],
family: (result as V2USHouseholdCalculationResult).family ?? [],
spm_unit: (result as V2USHouseholdCalculationResult).spm_unit ?? [],
marital_unit: (result as V2USHouseholdCalculationResult).marital_unit ?? [],
household: (result as V2USHouseholdCalculationResult).household ?? [],
} satisfies V2USCreateHouseholdEnvelope;
case 'uk':
return {
country_id: 'uk',
year: originalHousehold.year,
label: originalHousehold.label,
people: (result as V2UKHouseholdCalculationResult).person,
household: (result as V2UKHouseholdCalculationResult).household ?? [],
benunit: (result as V2UKHouseholdCalculationResult).benunit ?? [],
} satisfies V2UKCreateHouseholdEnvelope;
}
}

/**
* High-level function: Calculate household using v2 alpha API
* Creates job, polls for result, returns Household
*/
export async function calculateHouseholdV2Alpha(
household: V2HouseholdShape,
household: V2HouseholdEnvelope,
policyId?: string,
dynamicId?: string,
options: {
pollIntervalMs?: number;
timeoutMs?: number;
signal?: AbortSignal;
} = {}
): Promise<V2HouseholdShape> {
): Promise<V2CreateHouseholdEnvelope> {
// Convert to calculation payload format (arrays)
const payload = householdToCalculatePayload(household, policyId, dynamicId);

Expand Down
Loading
Loading