Create a TypeScript module that queries the NPPES NPI Registry API to search and retrieve healthcare provider records. Function signature: ```typescript lookupProvider(query: { name?: string, npi?: string, state?: string }): Promise<Provider[]> ``` The `Provider` interface should normalize the raw NPI response into: `{ id: string, name: string, credential: string, address: string, city: string, state: string, specialty: string, phone: string }`. Requirements: 1. Call `https://npiregistry.cms.hhs.gov/api/?version=2.1` with the provided query params 2. Handle pagination (API returns max 200 per page; implement limit at 50 for now) 3. Return empty array on 404 or no results 4. Throw a typed `NpiApiError` on 5xx or malformed JSON 5. Never return providers with deactivated status Write unit tests with 4 fixture cases: found by name, found by NPI, not found, API error. Use `vi.mock` to avoid real HTTP calls.
No contributions yet.