Skip to content

Ryan/hello types#130

Open
RyanLCox1 wants to merge 28 commits intomasterfrom
ryan/hello_types
Open

Ryan/hello types#130
RyanLCox1 wants to merge 28 commits intomasterfrom
ryan/hello_types

Conversation

@RyanLCox1
Copy link
Contributor

@RyanLCox1 RyanLCox1 commented Mar 3, 2026

Introduce typescript

refs #110

Convert index.mjs to index.ts so the build generates index.d.ts
naturally, and re-export the Sender chain interfaces so consumers
implementing custom senders via .withSender() can access them.
Without the return, code continued executing after reject() and could
crash on a null payload. Affects all API Client classes and sendBatch.
…g return

ClientBuilder: check for undefined instead of "" when building
comma-separated query values, preventing "undefined,value" strings.

HttpSender: add return after reject() so resolve() doesn't also run
on 400+ status responses.
Add missing return before client.send().then() so Mocha awaits the
assertions. Remove erroneous JSON.stringify() on mock payloads, and
fix us_zipcode test to assert on an actual Result field (status)
instead of a nonexistent city property.
buildSmartyResponse: use 0 instead of double-casting undefined to
bypass the type system for error responses with no HTTP status.

MockSenderWithResponse: use 0 instead of "" as any for statusCode.
Add private visibility to sender field in us_reverse_geo, international_street,
and international_postal_code Clients for consistency with all other Clients.

Remove trivial "has an inner sender" tests that accessed the now-private field.
Use narrowed payload type assertions instead of as any in
us_autocomplete_pro, international_address_autocomplete, and
us_extract Clients. Type StatusCodeSender catch handler as Response
with a specific error payload shape.
- Rename secondFlootSqft to secondFloorSqft (typo)
- Remove duplicate censusTract assignment
- Fix widow_tax_exemption to widowTaxExemption in FinancialResponse
  for consistency with the camelCase convention used everywhere else
This was the only place in the SDK where a mapped property retained
snake_case. Consistent with us_zipcode/Result which already maps to
stateAbbreviation. Updated tests to use API-format input and
SDK-format expected output separately.
Guard against null payload in international_street Client before
calling forEach, and guard against missing api_output in
us_extract Address before calling map.
LicenseSender, BaseUrlSender, AgentSender, CustomHeaderSender, and
SigningSender all wrapped this.sender.send(request) in a redundant
new Promise(). Since the inner send already returns a Promise, just
return it directly after doing synchronous work.
us_reverse_geo/Response.ts and util/sendBatch.ts were using .map()
purely for side effects. Use .forEach() to express intent clearly.
- us_street/Lookup.result: any[] → Candidate[]
- us_zipcode/Lookup.result: any[] → Result[]
- us_autocomplete_pro/Lookup.result: any[] → Suggestion[]
- international_street/Lookup.result: any[] → Candidate[]
- international_address_autocomplete/Lookup.result: any[] → Suggestion[]
- international_postal_code/Lookup.result: any[] → Result[]
- us_extract/Lookup.result: Record<string, any> → Result (with proper init)
- us_enrichment/Lookup.response: Record<string, any> → Record<string, unknown>
- All customParameters: Record<string, any> → Record<string, string>
- All addCustomParameter value params: any → string
Replace Record<string, any> with typed interfaces on all output fields
that SDK consumers access:

- us_street/Candidate: UsStreetComponents, UsStreetMetadata, UsStreetAnalysis, AnalysisComponents
- international_street/Candidate: IntlStreetComponents, IntlStreetAnalysis, IntlChanges, IntlChangesComponents, IntlStreetMetadata
- us_zipcode/Result: CityEntry, ZipcodeEntry, AlternateCounty
- us_reverse_geo/Result: ReverseGeoAddress, ReverseGeoCoordinate
- us_extract/Result: ExtractMeta

Constructor responseData params remain Record<string, any> (JSON boundary).
- Add BaseLookup interface to types.ts for Batch type safety
- Batch.lookups: any[] → BaseLookup[], add/getByIndex/getByInputId typed
- sendBatch: type response param as Response, generateRequestPayload returns
  Record<string, string | number>[], keep justified any on Result constructor
- InputData.data: Record<string, any> → Record<string, string | number>,
  formatData return typed as string | number
- buildInputData/buildUsStreetInputData return types narrowed
- Test casts for batch.getByIndex() → specific Lookup types
- international_street/Client: response: any → Response, cast payload
- international_postal_code/Client: response: any → Response
- us_reverse_geo/Client: response: any → SdkResponse, cast payload
- us_enrichment/Response: attributes: Record<string, any> → Record<string, unknown>
  on all 3 classes (Response, FinancialResponse, GeoResponse)
- us_enrichment/Client: payload casts narrowed to Record<string, unknown>
- GeoResponse: refactored to use local typed objects to avoid unknown reads
- proxy: any → AxiosProxyConfig | undefined
- buildClient: generic <T> return type instead of any
- MockSender: typed request fields, send accepts IRequest
- MockSenderWithResponse: typed payload/error params and send return
- MockSenderWithStatusCodesAndHeaders: statusCodes number[], headers
  Record<string, unknown>, error string, send accepts IRequest
The Client was assigning raw snake_case JSON payloads directly to
lookup.response, bypassing the Response/FinancialResponse/GeoResponse
constructors that transform keys to camelCase. Now each send method
constructs the appropriate Response type, and Lookup.response is typed
accordingly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant