← back to Nationalrealestate

src/ingest/brokers/co_dre.ts

48 lines

/**
 * CO — DORA/DRE "Licensed Real Estate Professionals in Colorado" on
 * data.colorado.gov (4zse-6bnw, refreshed daily; 108,811 rows probed 2026-07-21
 * — but that includes MLOs, appraisers and HOAs). We keep only the real-estate
 * broker license types (~49k individuals) + Real Estate Company rows (~16.7k firms).
 * No employer linkage columns in this dataset → individual rows carry no firm.
 */
import { download } from '../run.ts';
import { parseCsvObjects } from './csv.ts';
import type { BrokerRow, FetchedFile, StateAdapter } from './types.ts';

const URL = 'https://data.colorado.gov/api/views/4zse-6bnw/rows.csv?accessType=DOWNLOAD';

export const coDre: StateAdapter = {
  state: 'CO',
  source: 'co_dre',
  url: URL,
  async fetch() {
    return [await download(URL, 'co_dre_licensed_re_professionals.csv')];
  },
  *parse(files: FetchedFile[]): Generator<BrokerRow> {
    for (const o of parseCsvObjects(files[0].path)) {
      const type = o.licensetype || '';
      if (!o.licensenumber) continue;
      const city = o.city || null;
      const st = (o.state || '').toUpperCase() || null;
      const status = o.licensestatus || null;
      if (type.startsWith('Real Estate Company')) {
        // company rows carry the name in `entityname`, not the person-name columns
        const name = o.entityname || o.lastname || [o.firstname, o.lastname].filter(Boolean).join(' ');
        if (!name) continue;
        yield {
          kind: 'firm', name, license_no: o.licensenumber,
          license_type: type, license_status: status, city, state_code: st,
        };
      } else if (/Real Estate Broker/.test(type)) {
        const name = [o.firstname, o.middlename, o.lastname].filter(Boolean).join(' ');
        if (!name) continue;
        yield {
          kind: 'broker', name, license_no: o.licensenumber,
          license_type: type, license_status: status, city, state_code: st,
        };
      }
      // MLO / appraiser / HOA / subdivision rows skipped — not the broker registry
    }
  },
};