Overview
The permit data integration fetches construction permits from two NYC Department of Buildings (DOB) datasets and merges them into a unified stream. This handles both work-type permits (General Construction, Plumbing, etc.) and job-level filings (New Building, Demolition).Two Implementations: The project has two permit fetching implementations:
permits.ts- Used by the main isometric view (App component), takesdaysBack: numberpermit-data.ts- Used by the alternative map view (PermitMap component), takes explicit date strings
permit-data.ts module used by PermitMap. For the isometric view’s implementation, see permits.ts.fetchPermits()
Fetches permits for a specific date range by querying two DOB NOW datasets and merging the results.src/permit-data.ts
Parameters
Start date in
YYYY-MM-DD format (e.g., '2024-01-01')End date in
YYYY-MM-DD format (e.g., '2024-01-07'). Range is inclusive.Maximum number of permits to fetch. Used to cap map markers for performance.
Returns
Returns aPromise<Permit[]> containing normalized permits from both datasets.
Implementation Details
Two-Dataset Strategy
The function queries two separate Socrata datasets:-
rbx6-tga4 — DOB NOW: Build – Approved Permits
Work-type permits: General Construction, Plumbing, Mechanical, Solar, Scaffold, etc.
Excludes New Building and Full Demolition. -
w9ak-ipjd — DOB NOW: Build – Job Filings
Job-level filings: New Building, Full Demolition, Alteration.
Only NB and DM records are pulled from this dataset.
Proxy Paths
All requests use proxy paths to avoid CORS issues:src/permit-data.ts
Query String Construction
Query strings are manually constructed using Socrata Query Language (SoQL):src/permit-data.ts
+ for URL encoding.
Date Cutoff Calculation
The function usesgetLatestDatasetDate() to determine the actual latest available data, rather than assuming the dataset is current:
src/permit-data.ts
Parallel Fetch
Both datasets are fetched in parallel for performance:src/permit-data.ts
Response Normalization
Work permits and job filings have different schemas and must be normalized: Work Permits:src/permit-data.ts
src/permit-data.ts
Final Merge
src/permit-data.ts
Example Request
Error Handling
src/permit-data.ts
getLatestDatasetDate()
Determines the actual latest available date in the permits dataset, accounting for data lag.src/permit-data.ts
Caching Strategy
The latest dataset date is cached for 10 minutes to avoid redundant API calls on every filter change:src/permit-data.ts
Query Implementation
Uses SoQL’smax() aggregation function:
src/permit-data.ts
Fallback Logic
If the API call fails or returns no data, falls back to 2 days ago:src/permit-data.ts
The 2-day fallback accounts for typical DOB dataset lag. Real-world observation shows datasets are usually 2-3 days behind real-time.
workTypeToCode()
Normalizes verbose work type strings to two-letter codes.src/permit-data.ts
Supported Mappings
| Work Type | Code |
|---|---|
| New Building | NB |
| Full Demolition | DM |
| General Construction | GC |
| Plumbing | PL |
| Mechanical | ME |
| Solar | SOL |
| Sidewalk Shed | SHD |
| Scaffold | SCF |
| Construction Fence | FNC |
| Sign | SG |
| Foundation | FND |
| Structural | STR |
| Boiler | BLR |
| Sprinkler | SPR |
| Earth Work | EW |
| Antenna | ANT |
| Curb Cut | CC |
| Standpipe | STP |
| Other | OTH |
Implementation
src/permit-data.ts
Type Definitions
Permit Interface
src/types.ts
Related Functions
See Utilities for helper functions:formatAddress(permit)— Formats permit addressformatDate(dateStr)— Formats ISO date stringsgetJobColor(jobType)— Returns hex color for job typegetJobEmoji(jobType)— Returns emoji for job typegetJobLabel(jobType)— Returns human-readable label