policyengine-household-wizard 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "policyengine-household-wizard",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Shared wizard primitives and US and UK household draft contracts for PolicyEngine apps.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -367,6 +367,10 @@ export function toV1HouseholdPayload(
367
367
  const spmUnits: V1GroupCollection = {
368
368
  [keys.spmUnit]: { members: [...memberIds] },
369
369
  };
370
+ const childcare = toAmount(draft.childcareExpenses);
371
+ if (childcare !== undefined) {
372
+ spmUnits[keys.spmUnit].spm_unit_pre_subsidy_childcare_expenses = yearMap(year, childcare);
373
+ }
370
374
  const households: V1GroupCollection = {
371
375
  [keys.household]: householdRecord,
372
376
  };
@@ -46,6 +46,7 @@ export function cloneDraft(draft: USHouseholdDraft): USHouseholdDraft {
46
46
  zip: draft.zip,
47
47
  maritalStatus: draft.maritalStatus,
48
48
  year: draft.year,
49
+ childcareExpenses: draft.childcareExpenses,
49
50
  extras: draft.extras ? structuredClone(draft.extras) : undefined,
50
51
  people: draft.people.map((person) => ({
51
52
  ...person,
@@ -110,6 +110,7 @@ interface LegacyDraftShape {
110
110
  partnerAge?: number | string | null;
111
111
  spouseAge?: number | string | null;
112
112
  year?: number;
113
+ childcareExpenses?: number | string | null;
113
114
  }
114
115
 
115
116
  function coerceAge(value: unknown): number | null {
@@ -233,6 +234,8 @@ export function normalizeLegacyDraft(
233
234
  }
234
235
  const legacy = raw as LegacyDraftShape;
235
236
  const draft = createBlankDraft(options.year ?? legacy.year ?? DEFAULT_HOUSEHOLD_YEAR);
237
+ const childcare = coerceNumber(legacy.childcareExpenses);
238
+ if (childcare !== undefined) draft.childcareExpenses = childcare;
236
239
 
237
240
  // Location.
238
241
  if (typeof legacy.state === 'string' && isUSStateCode(legacy.state)) {
@@ -1,4 +1,5 @@
1
1
  import { createBlankDraft } from './draft';
2
+ import { toAmount } from './amount';
2
3
  import type { USHouseholdDraft, USPersonDraft } from './types';
3
4
 
4
5
  /**
@@ -10,6 +11,7 @@ import type { USHouseholdDraft, USPersonDraft } from './types';
10
11
  * &p=adult:35:e50000,adult:33:e20000,dep:6`
11
12
  *
12
13
  * Fields are pipe-separated within each person; people are comma-separated.
14
+ * `childcare=3000` carries annual household childcare costs, including 0.
13
15
  * Only the keys below are written: other person fields, such as tips,
14
16
  * investment income and expenses, are dropped from links for now.
15
17
  * Income/flag keys are single letters to keep the URL short:
@@ -103,6 +105,8 @@ export function serializeDraft(draft: USHouseholdDraft): string {
103
105
  if (draft.zip) params.set('zip', draft.zip);
104
106
  if (draft.maritalStatus) params.set('marital', draft.maritalStatus);
105
107
  params.set('year', String(draft.year));
108
+ const childcare = toAmount(draft.childcareExpenses);
109
+ if (childcare !== undefined) params.set('childcare', String(childcare));
106
110
  if (draft.people.length > 0) {
107
111
  params.set('p', draft.people.map(serializePerson).join(','));
108
112
  }
@@ -112,6 +116,8 @@ export function serializeDraft(draft: USHouseholdDraft): string {
112
116
  export function deserializeDraft(query: string | URLSearchParams): USHouseholdDraft {
113
117
  const params = typeof query === 'string' ? new URLSearchParams(query) : query;
114
118
  const draft = createBlankDraft();
119
+ const childcare = toAmount(params.get('childcare'));
120
+ if (childcare !== undefined) draft.childcareExpenses = childcare;
115
121
 
116
122
  const state = params.get('state');
117
123
  if (state) draft.state = state;
@@ -202,6 +202,14 @@ export interface USHouseholdDraft {
202
202
  * differentiates them. Order is significant for UI labels ("Adult 1", etc.).
203
203
  */
204
204
  people: USPersonDraft[];
205
+ /**
206
+ * Annual household childcare costs before childcare subsidies, in dollars.
207
+ * The V1 adapter sends this total once as the SPM-unit input
208
+ * `spm_unit_pre_subsidy_childcare_expenses`; the model allocates costs among
209
+ * children and subtracts subsidies. Do not repeat the total for each child.
210
+ * Leave unset when the app does not ask about childcare costs.
211
+ */
212
+ childcareExpenses?: number;
205
213
  /** Year the household is being modeled for. */
206
214
  year: number;
207
215
  /** App-controlled household-level fields ignored by the shared adapters. */
@@ -47,6 +47,21 @@ export function validate(
47
47
  const { requireCounty = false, requireAges = true } = options;
48
48
  const issues: ValidationIssue[] = [];
49
49
 
50
+ const childcare = toAmount(draft.childcareExpenses);
51
+ if (draft.childcareExpenses != null && childcare === undefined) {
52
+ issues.push({
53
+ code: 'childcareExpenses.invalid',
54
+ path: 'childcareExpenses',
55
+ message: 'Childcare expenses must be a finite amount.',
56
+ });
57
+ } else if (childcare !== undefined && childcare < 0) {
58
+ issues.push({
59
+ code: 'childcareExpenses.negative',
60
+ path: 'childcareExpenses',
61
+ message: 'Childcare expenses cannot be negative.',
62
+ });
63
+ }
64
+
50
65
  if (!draft.state) {
51
66
  issues.push({
52
67
  code: 'state.required',