Use Zillow parcel hints for CAD lookup
This commit is contained in:
@@ -197,6 +197,7 @@ This command currently:
|
||||
Important rules:
|
||||
- listing-site geo IDs are hints only; do **not** treat them as assessor record keys
|
||||
- parcel/APN/account identifiers from Zillow/HAR/Redfin are much stronger keys than listing geo IDs
|
||||
- if Zillow exposes a parcel/APN/account number on the listing, capture it and feed that identifier into CAD lookup before relying on address-only matching
|
||||
- if a direct public-record property page is available, use its data in the assessment and link it explicitly
|
||||
- when the helper exposes official CAD owner, legal-description, property-ID/account, value, or exemption data, treat those as primary-source facts in the model's assessment
|
||||
- if the jurisdiction can be identified but the property detail page is not directly retrievable, still link the official jurisdiction page and say what could not be confirmed
|
||||
@@ -210,6 +211,7 @@ Process:
|
||||
1. run `locate-public-records` from the subject address
|
||||
2. use the returned Texas Comptroller county directory page as the official jurisdiction reference
|
||||
3. use the returned CAD website for address / account / parcel lookup
|
||||
- when Zillow exposes the parcel/APN/account number, prefer that over address-only search
|
||||
4. when accessible, capture:
|
||||
- account number
|
||||
- owner name
|
||||
@@ -221,6 +223,9 @@ Process:
|
||||
|
||||
In the final assessment, explicitly label official public-record facts as such.
|
||||
|
||||
Nueces-specific note:
|
||||
- when searching Nueces CAD by parcel / Geographic ID, format the identifier with a dash after the first 4 digits and after the first 8 digits, for example `123456789012` -> `1234-5678-9012`
|
||||
|
||||
## Minimum data to capture
|
||||
|
||||
For the target property, capture when available:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { extractZillowIdentifierHints } from "../../web-automation/scripts/zillow-identifiers.js";
|
||||
import { discoverListingSources, type ListingDiscoveryResult } from "./listing-discovery.js";
|
||||
import { extractPhotoData, type PhotoExtractionResult, type PhotoSource } from "./photo-review.js";
|
||||
import { resolvePublicRecords, type PublicRecordsResolution } from "./public-records.js";
|
||||
@@ -36,6 +37,7 @@ interface AssessPropertyDeps {
|
||||
renderReportPdfFn?: typeof renderReportPdf;
|
||||
discoverListingSourcesFn?: typeof discoverListingSources;
|
||||
extractPhotoDataFn?: typeof extractPhotoData;
|
||||
extractZillowIdentifierHintsFn?: typeof extractZillowIdentifierHints;
|
||||
}
|
||||
|
||||
interface PurposeGuidance {
|
||||
@@ -195,14 +197,17 @@ function inferSourceFromUrl(rawUrl: string): PhotoSource | null {
|
||||
}
|
||||
}
|
||||
|
||||
async function resolvePhotoReview(
|
||||
options: AssessPropertyOptions,
|
||||
discoverListingSourcesFn: typeof discoverListingSources,
|
||||
extractPhotoDataFn: typeof extractPhotoData
|
||||
): Promise<{
|
||||
interface ResolvedListingCandidates {
|
||||
attempts: string[];
|
||||
listingUrls: Array<{ label: string; url: string }>;
|
||||
photoReview: Record<string, unknown>;
|
||||
}> {
|
||||
zillowUrl: string | null;
|
||||
harUrl: string | null;
|
||||
}
|
||||
|
||||
async function resolveListingCandidates(
|
||||
options: AssessPropertyOptions,
|
||||
discoverListingSourcesFn: typeof discoverListingSources
|
||||
): Promise<ResolvedListingCandidates> {
|
||||
const attempts: string[] = [];
|
||||
const listingUrls: Array<{ label: string; url: string }> = [];
|
||||
|
||||
@@ -241,9 +246,27 @@ async function resolvePhotoReview(
|
||||
addListingUrl("Discovered HAR Listing", harUrl);
|
||||
}
|
||||
|
||||
return {
|
||||
attempts,
|
||||
listingUrls,
|
||||
zillowUrl,
|
||||
harUrl,
|
||||
};
|
||||
}
|
||||
|
||||
async function resolvePhotoReview(
|
||||
listingCandidates: ResolvedListingCandidates,
|
||||
extractPhotoDataFn: typeof extractPhotoData,
|
||||
additionalAttempts: string[] = []
|
||||
): Promise<{
|
||||
listingUrls: Array<{ label: string; url: string }>;
|
||||
photoReview: Record<string, unknown>;
|
||||
}> {
|
||||
const attempts: string[] = [...listingCandidates.attempts, ...additionalAttempts];
|
||||
const listingUrls = [...listingCandidates.listingUrls];
|
||||
const candidates: Array<{ source: PhotoSource; url: string }> = [];
|
||||
if (zillowUrl) candidates.push({ source: "zillow", url: zillowUrl });
|
||||
if (harUrl) candidates.push({ source: "har", url: harUrl });
|
||||
if (listingCandidates.zillowUrl) candidates.push({ source: "zillow", url: listingCandidates.zillowUrl });
|
||||
if (listingCandidates.harUrl) candidates.push({ source: "har", url: listingCandidates.harUrl });
|
||||
|
||||
let extracted: PhotoExtractionResult | null = null;
|
||||
for (const candidate of candidates) {
|
||||
@@ -411,21 +434,52 @@ export async function assessProperty(
|
||||
const renderReportPdfFn = deps.renderReportPdfFn || renderReportPdf;
|
||||
const discoverListingSourcesFn = deps.discoverListingSourcesFn || discoverListingSources;
|
||||
const extractPhotoDataFn = deps.extractPhotoDataFn || extractPhotoData;
|
||||
const extractZillowIdentifierHintsFn =
|
||||
deps.extractZillowIdentifierHintsFn || extractZillowIdentifierHints;
|
||||
|
||||
const listingCandidates = await resolveListingCandidates(
|
||||
{ ...options, assessmentPurpose: purpose },
|
||||
discoverListingSourcesFn
|
||||
);
|
||||
|
||||
const identifierAttempts: string[] = [];
|
||||
let effectiveParcelId = options.parcelId;
|
||||
if (!effectiveParcelId && listingCandidates.zillowUrl) {
|
||||
try {
|
||||
const hints = await extractZillowIdentifierHintsFn(listingCandidates.zillowUrl);
|
||||
effectiveParcelId = hints.parcelId || hints.apn || effectiveParcelId;
|
||||
if (Array.isArray(hints.notes) && hints.notes.length) {
|
||||
identifierAttempts.push(...hints.notes);
|
||||
}
|
||||
} catch (error) {
|
||||
identifierAttempts.push(
|
||||
`Zillow parcel/APN extraction failed: ${error instanceof Error ? error.message : String(error)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const effectiveListingSourceUrl =
|
||||
options.listingSourceUrl || listingCandidates.zillowUrl || listingCandidates.harUrl || undefined;
|
||||
|
||||
const publicRecords = await resolvePublicRecordsFn(options.address, {
|
||||
parcelId: options.parcelId,
|
||||
parcelId: effectiveParcelId,
|
||||
listingGeoId: options.listingGeoId,
|
||||
listingSourceUrl: options.listingSourceUrl
|
||||
listingSourceUrl: effectiveListingSourceUrl
|
||||
});
|
||||
|
||||
const photoResolution = await resolvePhotoReview(
|
||||
{ ...options, assessmentPurpose: purpose },
|
||||
discoverListingSourcesFn,
|
||||
extractPhotoDataFn
|
||||
listingCandidates,
|
||||
extractPhotoDataFn,
|
||||
identifierAttempts
|
||||
);
|
||||
|
||||
const reportPayload = buildAssessmentReportPayload(
|
||||
{ ...options, assessmentPurpose: purpose },
|
||||
{
|
||||
...options,
|
||||
assessmentPurpose: purpose,
|
||||
parcelId: effectiveParcelId,
|
||||
listingSourceUrl: effectiveListingSourceUrl
|
||||
},
|
||||
publicRecords,
|
||||
photoResolution.listingUrls,
|
||||
photoResolution.photoReview
|
||||
|
||||
@@ -175,6 +175,16 @@ function buildCadSearchKeywords(address: string, year: number): string {
|
||||
return `${collapseWhitespace(address)} Year:${year}`.trim();
|
||||
}
|
||||
|
||||
function formatNuecesGeographicId(parcelId: string | null | undefined): string | null {
|
||||
const normalized = collapseWhitespace(parcelId).replace(/[^0-9]/g, "");
|
||||
if (!normalized) return null;
|
||||
if (normalized.length <= 4) return normalized;
|
||||
if (normalized.length <= 8) {
|
||||
return `${normalized.slice(0, 4)}-${normalized.slice(4)}`;
|
||||
}
|
||||
return `${normalized.slice(0, 4)}-${normalized.slice(4, 8)}-${normalized.slice(8)}`;
|
||||
}
|
||||
|
||||
function parseAddressForCadSearch(address: string): {
|
||||
rawAddress: string;
|
||||
streetNumber: string | null;
|
||||
@@ -327,6 +337,7 @@ function pickBestCadResult(
|
||||
async function enrichNuecesCadPropertyDetails(
|
||||
address: string,
|
||||
appraisalDistrictWebsite: string,
|
||||
parcelId: string | null | undefined,
|
||||
fetchText: FetchLike
|
||||
): Promise<PropertyDetailsResolution | null> {
|
||||
const parsedAddress = parseAddressForCadSearch(address);
|
||||
@@ -341,10 +352,12 @@ async function enrichNuecesCadPropertyDetails(
|
||||
if (!searchToken) return null;
|
||||
|
||||
const searchYear = parseCurrentYearFromSearchHome(searchHomeHtml);
|
||||
const formattedGeographicId = formatNuecesGeographicId(parcelId);
|
||||
const searchKeywords =
|
||||
parsedAddress.streetNumber && parsedAddress.streetName
|
||||
formattedGeographicId ||
|
||||
(parsedAddress.streetNumber && parsedAddress.streetName
|
||||
? `StreetNumber:${parsedAddress.streetNumber} StreetName:"${parsedAddress.streetName}"`
|
||||
: buildCadSearchKeywords(address, searchYear);
|
||||
: buildCadSearchKeywords(address, searchYear));
|
||||
|
||||
const fetchSearchPage = async (page: number): Promise<any> => {
|
||||
const searchResultsUrl = `${normalizedPropertySearchUrl}/search/SearchResults?keywords=${encodeURIComponent(searchKeywords)}`;
|
||||
@@ -478,6 +491,7 @@ async function enrichNuecesCadPropertyDetails(
|
||||
|
||||
async function tryEnrichPropertyDetails(
|
||||
address: string,
|
||||
parcelId: string | null | undefined,
|
||||
appraisalDistrictWebsite: string | null,
|
||||
fetchText: FetchLike
|
||||
): Promise<PropertyDetailsResolution | null> {
|
||||
@@ -487,7 +501,7 @@ async function tryEnrichPropertyDetails(
|
||||
const normalizedWebsite = normalizeUrl(website).toLowerCase();
|
||||
try {
|
||||
if (normalizedWebsite.includes("nuecescad.net") || normalizedWebsite.includes("ncadistrict.com")) {
|
||||
return await enrichNuecesCadPropertyDetails(address, website, fetchText);
|
||||
return await enrichNuecesCadPropertyDetails(address, website, parcelId, fetchText);
|
||||
}
|
||||
} catch {
|
||||
return null;
|
||||
@@ -729,6 +743,7 @@ export async function resolvePublicRecords(
|
||||
taxAssessorCollector = offices.taxAssessorCollector;
|
||||
propertyDetails = await tryEnrichPropertyDetails(
|
||||
address,
|
||||
options.parcelId,
|
||||
typeof offices.appraisalDistrict?.Website === "string"
|
||||
? offices.appraisalDistrict.Website
|
||||
: null,
|
||||
|
||||
@@ -146,6 +146,47 @@ test("assessProperty auto-discovers listing sources, runs Zillow photos first, a
|
||||
assert.deepEqual(result.reportPayload?.recipientEmails, []);
|
||||
});
|
||||
|
||||
test("assessProperty uses parcel/APN hints extracted from Zillow before CAD lookup when parcel ID was not provided", async () => {
|
||||
const seenPublicRecordOptions: Array<Record<string, unknown>> = [];
|
||||
|
||||
const result = await assessProperty(
|
||||
{
|
||||
address: "6702 Everhart Rd APT T106, Corpus Christi, TX 78413",
|
||||
assessmentPurpose: "college housing for daughter attending TAMU-CC"
|
||||
},
|
||||
{
|
||||
resolvePublicRecordsFn: async (_address, options) => {
|
||||
seenPublicRecordOptions.push({ ...options });
|
||||
return samplePublicRecords;
|
||||
},
|
||||
discoverListingSourcesFn: async () => ({
|
||||
attempts: ["Zillow discovery located a property page from the address."],
|
||||
zillowUrl:
|
||||
"https://www.zillow.com/homedetails/6702-Everhart-Rd-APT-T106-Corpus-Christi-TX-78413/2067445642_zpid/",
|
||||
harUrl: null
|
||||
}),
|
||||
extractZillowIdentifierHintsFn: async () => ({
|
||||
parcelId: "1234567890",
|
||||
notes: ["Zillow listing exposed parcel/APN number 1234567890."]
|
||||
}),
|
||||
extractPhotoDataFn: async (source, url) => ({
|
||||
source,
|
||||
requestedUrl: url,
|
||||
finalUrl: url,
|
||||
expectedPhotoCount: 29,
|
||||
complete: true,
|
||||
photoCount: 29,
|
||||
imageUrls: ["https://photos.example/1.jpg"],
|
||||
notes: [`${source} extractor succeeded.`]
|
||||
})
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(seenPublicRecordOptions.length, 1);
|
||||
assert.equal(seenPublicRecordOptions[0]?.parcelId, "1234567890");
|
||||
});
|
||||
|
||||
test("assessProperty asks for recipient email only when PDF render is explicitly requested", async () => {
|
||||
const result = await assessProperty(
|
||||
{
|
||||
|
||||
@@ -291,3 +291,90 @@ test("resolvePublicRecords enriches official CAD property facts when a supported
|
||||
fetchedUrls.some((url) => url.includes("esearch.nuecescad.net/property/view/14069438"))
|
||||
);
|
||||
});
|
||||
|
||||
test("resolvePublicRecords uses formatted Nueces Geographic ID search when a parcel ID is available", async () => {
|
||||
const fetchedUrls: string[] = [];
|
||||
const enrichedFetchText = async (url: string): Promise<string> => {
|
||||
fetchedUrls.push(url);
|
||||
|
||||
if (url.includes("geocoding.geo.census.gov")) {
|
||||
return JSON.stringify(geocoderPayload);
|
||||
}
|
||||
if (url.endsWith("/county-directory/")) {
|
||||
return countyIndexHtml;
|
||||
}
|
||||
if (url.endsWith("/county-directory/nueces.php")) {
|
||||
return countyPageHtml.replace(
|
||||
"http://www.ncadistrict.com/",
|
||||
"https://nuecescad.net/"
|
||||
);
|
||||
}
|
||||
if (url === "https://nuecescad.net/") {
|
||||
return `
|
||||
<html>
|
||||
<body>
|
||||
<a href="https://esearch.nuecescad.net/">Property Search</a>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
if (url === "https://esearch.nuecescad.net/") {
|
||||
return `
|
||||
<html>
|
||||
<head>
|
||||
<meta name="search-token" content="token-value|2026-03-28T00:00:00Z" />
|
||||
</head>
|
||||
<body>
|
||||
Property Search
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
if (url.includes("/search/SearchResults?")) {
|
||||
assert.match(url, /keywords=1234-5678-9012/);
|
||||
return JSON.stringify({
|
||||
success: true,
|
||||
resultsList: [
|
||||
{
|
||||
propertyId: "200016970",
|
||||
ownerName: "NGUYEN TRANG THUY",
|
||||
ownerId: "677681",
|
||||
address: "6702 Everhart Rd Apt T106, Corpus Christi, TX 78413",
|
||||
legalDescription: "UNIT T106 EXAMPLE CONDO",
|
||||
appraisedValueDisplay: "$128,876",
|
||||
detailUrl: "/property/view/200016970?year=2026"
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
if (url === "https://esearch.nuecescad.net/property/view/200016970?year=2026") {
|
||||
return `
|
||||
<html>
|
||||
<body>
|
||||
<div class="property-summary">
|
||||
<div>Owner Name</div><div>NGUYEN TRANG THUY</div>
|
||||
<div>Account Number</div><div>200016970</div>
|
||||
<div>Situs Address</div><div>6702 Everhart Rd Apt T106, Corpus Christi, TX 78413</div>
|
||||
<div>Legal Description</div><div>UNIT T106 EXAMPLE CONDO</div>
|
||||
<div>Land Value</div><div>$20,000</div>
|
||||
<div>Improvement Value</div><div>$108,876</div>
|
||||
<div>Market Value</div><div>$128,876</div>
|
||||
<div>Assessed Value</div><div>$128,876</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
}
|
||||
throw new Error(`Unexpected URL: ${url}`);
|
||||
};
|
||||
|
||||
const payload = await resolvePublicRecords("6702 Everhart Rd APT T106, Corpus Christi, TX 78413", {
|
||||
parcelId: "123456789012",
|
||||
fetchText: enrichedFetchText
|
||||
});
|
||||
|
||||
assert.equal(payload.propertyDetails?.propertyId, "200016970");
|
||||
assert.ok(
|
||||
fetchedUrls.some((url) => url.includes("keywords=1234-5678-9012"))
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user