メインコンテンツまでスキップ
バージョン: 🚧 Canary

🏠 Address

Address provides an authenticated Japanese postal-code lookup service backed by a host-supplied findAddressDriver.

Start here

import {drivers, services} from '@nodeblocks/backend-sdk';

const findAddressDriver = drivers.createJapanPostDriver(
process.env.JAPAN_POST_CLIENT_ID!,
process.env.JAPAN_POST_SECRET_KEY!,
);

app.use(
'/api',
services.addressService(
{identities},
{authSecrets: {authEncSecret: 'replace-me', authSignSecret: 'replace-me'}},
{findAddressDriver},
),
);
ConfigurationDefault / source behaviorEffect
authSecretsRequired; passed to the selected authentication utilityVerifies access tokens.
authModeOmitted or 'bearer' selects Bearer tokens'cookie' selects cookie authentication.
identity.typeIdsPassed through configuration unchanged when suppliedNot consumed by the Address route.
findAddressCacheNo cache when omittedCaches addresses by normalized postal code.
findAddressDriver optionRequired for lookup; defaults to undefinedProvides findAddress(postalCode).

Common tasks

TaskStart withContract
Look up an addressfindAddressFeaturefindAddressFeature and findAddressRoute
Build a Japan Post drivercreateJapanPostDrivercreateJapanPostDriver
Reuse address request definitionsAddress schemasAddress schemas
Mount the lookup serviceaddressServiceaddressService with a findAddressDriver option

Bearer HTTP workflow

With omitted authMode or authMode: 'bearer', send a valid access token and a query value accepted by findAddressSchema:

ADDRESS_API='https://api.example.test'
ACCESS_TOKEN='replace-with-a-valid-access-token'

curl "$ADDRESS_API/addresses?postalCode=100-0001" \
-H "Authorization: Bearer $ACCESS_TOKEN"

findAddressRoute returns the address JSON object with Express's default 200 status. The selected Bearer adapter can reject authentication with 401; an absent address maps to 404. User access-token security checks use the request verification data required by the configured/default authentication utility.

Configure authMode: 'cookie' and register cookie-parser before mounting the service. Send the same required query parameter with the access-token cookie established by the Authentication service:

ADDRESS_API='https://api.example.test'
ACCESS_TOKEN='replace-with-a-valid-access-token'

curl "$ADDRESS_API/addresses?postalCode=100-0001" \
--cookie "accessToken=$ACCESS_TOKEN"

The endpoint, request schema, response, and 404 behavior are unchanged. A missing or invalid cookie is rejected by the cookie authentication adapter; see Authentication for the token-cookie setup.

Custom feature composition

findAddressFeature is a schema-and-route composer. This fragment shows the source-equivalent service context required to mount it without addressService:

import {partial} from 'ramda';
import {features, primitives, utils} from '@nodeblocks/backend-sdk';

const router = primitives.defService(
partial(primitives.compose(features.findAddressFeature), [
{
authenticate: utils.getBearerTokenInfo,
configuration,
dataStores: {identities},
findAddressDriver,
},
]),
);

app.use('/api', router);

The fragment requires configuration.authSecrets, the identities collection, and a findAddressDriver; use findAddressRoute and findAddressSchema for the endpoint contract.

Reference map

PagePurpose
BlocksLookup contract, errors, and public types.
FeaturesSchema-to-route composition.
RoutesThe protected address endpoint.
SchemasReusable address data and lookup request schemas.
ValidatorsShared authentication requirement.

The Address service is the mountable integration surface for this category.

Japan Post driver supplies the lookup implementation. Authentication documents token transport used by this protected route.