Skip to main content
Version: 🚧 Canary

🧱 Address blocks

Address blocks are reusable postal-code lookup operations exported through blocks from @nodeblocks/backend-sdk. They perform the driver lookup and return neverthrow results instead of throwing expected lookup failures.

Inventory

ExportKindInputsResult / behavior / errors
FindAddressServiceErrorError classMessage, optional dataWraps unexpected driver failures.
AddressNotFoundErrorError classMessage, optional dataRepresents a driver lookup that has no address.
AddressTypeNone{prefecture, city, postalCode, town?} or null.
FindAddressDriverTypePostal codeContract for findAddress(postalCode).
findAddressAsync functionDriver, postal code, optional cacheNormalizes hyphens, uses cache, and returns an address result.

Details

FindAddressServiceError

Implementation

Extends BlockError and has no intrinsic HTTP status. findAddress returns this error when the driver rejects with a non-BlockError; findAddressRoute maps it to 500.

AddressNotFoundError

Implementation

Extends FindAddressServiceError and has no intrinsic HTTP status. A null driver result becomes this error in findAddress; findAddressRoute maps it to 404.

Address

Implementation

The public type is {prefecture, city, postalCode, town?} | null. Drivers may return null, but findAddress converts that result to err(AddressNotFoundError); its successful result therefore contains an address object.

Used by FindAddressDriver, findAddress, and the findAddressCache configuration accepted by the Address service.

FindAddressDriver

Implementation

Hosts provide findAddress(postalCode: string): Promise<Address>. The Japan Post driver satisfies this contract. The Address service injects a driver as findAddressDriver, and findAddress consumes it.

findAddress

Implementation

Signature: findAddress(findAddressDriver, postalCode, cache?): Promise<Result<Address, FindAddressServiceError>>, where cache is ReturnType<typeof createCache<string, Address>>.

It removes every hyphen before cache and driver access, but does not validate the resulting postal code; the injected driver determines input validity. A truthy cached value is returned directly. On a cache miss it calls the driver, writes the driver result to the cache, and converts a null result into err(AddressNotFoundError('No matching address found.')). A non-BlockError rejection becomes err(FindAddressServiceError('Failed to find address.', {cause})); an existing BlockError is preserved.

Because the cache-hit check is truthiness-based, a cached null does not produce a hit. Used by findAddressRoute, which maps AddressNotFoundError to 404 and FindAddressServiceError to 500.