{"id":29135753,"url":"https://github.com/seratch/japanpost-api-ts","last_synced_at":"2026-03-17T23:06:33.390Z","repository":{"id":295622509,"uuid":"990676969","full_name":"seratch/japanpost-api-ts","owner":"seratch","description":"Japan Post Service API Client / 郵便番号・デジタルアドレス API クライアント","archived":false,"fork":false,"pushed_at":"2025-06-01T14:18:26.000Z","size":240,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-19T10:49:19.119Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seratch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-26T13:17:08.000Z","updated_at":"2025-12-08T13:51:44.000Z","dependencies_parsed_at":"2025-06-30T10:07:56.002Z","dependency_job_id":"903696fe-4ebb-4266-b82d-645c38cc1b83","html_url":"https://github.com/seratch/japanpost-api-ts","commit_stats":null,"previous_names":["seratch/japanpost-api-ts"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/seratch/japanpost-api-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fjapanpost-api-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fjapanpost-api-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fjapanpost-api-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fjapanpost-api-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seratch","download_url":"https://codeload.github.com/seratch/japanpost-api-ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seratch%2Fjapanpost-api-ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30635156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T22:38:22.569Z","status":"ssl_error","status_checked_at":"2026-03-17T22:38:11.804Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-30T10:07:53.067Z","updated_at":"2026-03-17T23:06:33.084Z","avatar_url":"https://github.com/seratch.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Japan Post Service API Client\n\n[![npm version](https://badge.fury.io/js/japanpost-api.svg)](https://badge.fury.io/js/japanpost-api)\n[![Tests](https://github.com/seratch/japanpost-api-ts/actions/workflows/tests.yml/badge.svg)](https://github.com/seratch/japanpost-api-ts/actions/workflows/tests.yml)\n\n\u003e 📖 **日本語版のREADMEは[こちら](README_ja.md)をご覧ください** / **For Japanese README, please see [here](README_ja.md)**\n\nA TypeScript client for the Japan Post Service API. This library provides convenient methods to interact with the official Japan Post API endpoints for authentication and address/zipcode search.\n\nRefer to the service's [official documentation](https://lp-api.da.pf.japanpost.jp/) for details.\n\n## Features\n\nHere are the key features:\n\n- ✅ **Obtain authentication tokens using client credentials**\n- 🔍 **Search for addresses by postal codes, business postal codes, and digital addresses**\n- 🏠 **Search for zip codes by address components**\n- 🔄 **Automatic token refresh handling**\n- 📄 **Easy pagination for search API calls**\n- ⚡ **Automatic retry with rate limit handling**\n- 🛡️ **Robust error handling (authentication, rate limits, network errors)**\n- ✅ **Automatic input parameter validation**\n- 🔧 **Circuit breaker pattern for fault tolerance**\n\n## Installation\n\n```bash\nnpm i japanpost-api\n```\n\n## Basic Usage\n\n```typescript\nimport { JapanPostAPI } from 'japanpost-api';\n\nconst client = new JapanPostAPI({\n  client_id: process.env.JAPAN_POST_CLIENT_ID!,\n  secret_key: process.env.JAPAN_POST_SECRET_KEY!,\n});\n\n// Search for addresses by postal codes, business postal codes, and digital addresses\nconst search = await client.searchcode({\n  search_code: 'A7E2FK2',\n});\nconsole.log(search.addresses);\n\n// Search for zip codes by address components\nconst addresszip = await client.addresszip({\n  pref_code: '13',\n  city_code: '13101',\n});\nconsole.log(addresszip.addresses);\n\n// Auto-pagination for searchcode API\nfor await (const page of client.searchcodeAll({\n  search_code: 'A7E2FK2',\n  limit: 10,\n})) {\n  console.log(page);\n}\n\n// Auto-pagination for addresszip API\nfor await (const page of client.addresszipAll({\n  pref_code: \"13\",\n  city_code: \"13101\",\n  limit: 10,\n})) {\n  console.log(page);\n}\n```\n\n## Advanced Configuration\n\n### Auto-retry and Circuit Breaker\n\n```typescript\nimport { \n  JapanPostAPI, \n  RetryOptions, \n  CircuitBreakerOptions \n} from 'japanpost-api';\n\nconst retryOptions: RetryOptions = {\n  maxRetries: 5,        // Maximum number of retries\n  baseDelay: 2000,      // Base delay in milliseconds\n  maxDelay: 30000,      // Maximum delay in milliseconds\n  backoffMultiplier: 2, // Exponential backoff multiplier\n};\n\nconst circuitBreakerOptions: CircuitBreakerOptions = {\n  failureThreshold: 3,  // Failure threshold\n  resetTimeout: 60000,  // Reset timeout in milliseconds\n};\n\nconst client = new JapanPostAPI(\n  {\n    client_id: process.env.JAPAN_POST_CLIENT_ID!,\n    secret_key: process.env.JAPAN_POST_SECRET_KEY!,\n  },\n  {\n    retryOptions,\n    circuitBreakerOptions,\n    enableValidation: true, // Enable validation (default: true)\n  }\n);\n```\n\n### Custom Error Handler\n\n```typescript\nimport { \n  AuthenticationError,\n  RateLimitError,\n  ValidationError,\n  NetworkError\n} from 'japanpost-api';\n\ntry {\n  const result = await client.searchcode({ search_code: '1000001' });\n  console.log(result);\n} catch (error) {\n  if (error instanceof AuthenticationError) {\n    console.error('Authentication error:', error.message);\n    // Logic to re-acquire token\n  } else if (error instanceof RateLimitError) {\n    console.error('Rate limit error:', error.message);\n    if (error.retryAfter) {\n      console.log(`Please retry after ${error.retryAfter} seconds`);\n    }\n  } else if (error instanceof ValidationError) {\n    console.error('Validation error:', error.message);\n    console.error('Problematic field:', error.field);\n    console.error('Problematic value:', error.value);\n  } else if (error instanceof NetworkError) {\n    console.error('Network error:', error.message);\n    console.error('Original error:', error.originalError);\n  } else {\n    console.error('Other error:', error);\n  }\n}\n```\n\n### Input Validation\n\n```typescript\nimport { \n  validateSearchcodeRequest,\n  validateAddresszipRequest,\n  isValidPrefCode,\n  getPrefCodeFromName\n} from 'japanpost-api';\n\n// Manual Validation\ntry {\n  validateSearchcodeRequest({ search_code: '1000001' });\n  console.log('Validation successful');\n} catch (error) {\n  console.error('Validation error:', error.message);\n}\n\n// Validate a given prefecture code\nif (isValidPrefCode('13')) {\n  console.log('Valid prefecture code');\n}\n\n// Look up prefecture code from its name\nconst prefCode = getPrefCodeFromName('Tokyo');\nconsole.log(prefCode); // '13'\n```\n\n### Monitoring Circuit Breaker's State\n\n```typescript\n// Get circuit breaker state\nconst state = client.getCircuitBreakerState();\nconsole.log(`Current state: ${state.state}`);\nconsole.log(`Failure count: ${state.failureCount}`);\n\n// Reset if necessary\nif (state.state === 'OPEN') {\n  client.resetCircuitBreaker();\n  console.log('Circuit breaker has been reset');\n}\n\n// Dynamically update retry settings\nclient.updateRetryOptions({\n  maxRetries: 10,\n  baseDelay: 5000,\n});\n```\n\n## Error Types\n\nThis library provides the following error types:\n\n- `AuthenticationError` - Authentication error (401)\n- `AuthorizationError` - Authorization error (403)\n- `RateLimitError` - Rate limit error (429)\n- `ClientError` - Client error (4xx)\n- `ServerError` - Server error (5xx)\n- `NetworkError` - Network error\n- `ValidationError` - Validation error\n- `GeneralAPIError` - Other API errors\n\n## Validation Features\n\nAutomatic validation of input parameters includes the following checks:\n\n### SearchcodeRequest\n- `search_code`: Postal code or digital address with 3 or more characters\n- `page`: Integer of 1 or greater\n- `limit`: Integer in the range 1-1000\n- `choikitype`: 1 or 2\n- `searchtype`: 1 or 2\n\n### AddresszipRequest\n- At least one search condition is required\n- `pref_code`: Prefecture code 01-47\n- `city_code`: 5-digit city code\n- Mutual exclusion control of `flg_getcity` and `flg_getpref`\n\n## TypeScript Support\n\nFull TypeScript support enables type-safe development:\n\n```typescript\nimport { SearchcodeRequest, SearchcodeResponse, PrefCode } from 'japanpost-api';\n\nconst request: SearchcodeRequest = {\n  search_code: '1000001',\n  limit: 100,\n};\n\nconst prefCode: PrefCode = '13'; // Type-safe prefecture code\n```\n\n## Contributing\n\nWe welcome contributions! This project uses automated releases based on [Conventional Commits](https://www.conventionalcommits.org/).\n\n### Quick Start for Contributors\n\n1. Fork and clone the repository\n2. Create a feature branch: `git checkout -b feature/your-feature`\n3. Make your changes with proper commit messages:\n   - `feat:` for new features\n   - `fix:` for bug fixes\n   - `docs:` for documentation changes\n4. Run tests: `npm test`\n5. Create a pull request\n\n### Automated Releases\n\nReleases are automatically published when changes are merged to the main branch:\n- `feat:` → Minor version bump\n- `fix:` → Patch version bump  \n- `feat!:` or `BREAKING CHANGE:` → Major version bump\n\nFor detailed information, see [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the MIT License. See [LICENSE.txt](LICENSE.txt) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseratch%2Fjapanpost-api-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseratch%2Fjapanpost-api-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseratch%2Fjapanpost-api-ts/lists"}