{"_id":"@br-health-kit/cnes","name":"@br-health-kit/cnes","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@br-health-kit/cnes","version":"1.0.0","description":"Cliente tipado para a API do CNES (Cadastro Nacional de Estabelecimentos de Saude)","license":"MIT","engines":{"node":">=20"},"type":"module","sideEffects":false,"main":"./dist/index.cjs","module":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"dependencies":{"@br-health-kit/core":"1.0.0"},"publishConfig":{"access":"public"},"keywords":["cnes","datasus","estabelecimentos","saude","brasil"],"repository":{"type":"git","url":"git+https://github.com/arielff3/br-health-kit.git","directory":"packages/cnes"},"homepage":"https://github.com/arielff3/br-health-kit/tree/main/packages/cnes#readme","bugs":{"url":"https://github.com/arielff3/br-health-kit/issues"},"scripts":{"build":"tsup","clean":"node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""},"_id":"@br-health-kit/cnes@1.0.0","_integrity":"sha512-qEzRENqabwyfP+Vyb0dKVRyCiVp89zJx51gsI3wcE1vqSvaISn07q80U+qD5r0Ekv7ThKVCq56r+B7mrc5ZfiA==","_resolved":"C:\\Users\\ariel\\AppData\\Local\\Temp\\390abebf71b2dedfdb196336c836069b\\br-health-kit-cnes-1.0.0.tgz","_from":"file:br-health-kit-cnes-1.0.0.tgz","_nodeVersion":"22.17.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-qEzRENqabwyfP+Vyb0dKVRyCiVp89zJx51gsI3wcE1vqSvaISn07q80U+qD5r0Ekv7ThKVCq56r+B7mrc5ZfiA==","shasum":"e125e1e9b87b4dfdcc8ee028307cb900a1cbfb16","tarball":"https://registry.npmjs.org/@br-health-kit/cnes/-/cnes-1.0.0.tgz","fileCount":9,"unpackedSize":74742,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIG+wbKrj6NsEhNafdixxLrYCYSGHgP/dv7p84EadTDc1AiAZ7JA4+I3f6kMkyzx6du9Z+JEtBXdPUXXZ5IlGABGFNw=="}]},"_npmUser":{"name":"arielff03","email":"arielfrancoferreira5@gmail.com"},"directories":{},"maintainers":[{"name":"arielff03","email":"arielfrancoferreira5@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/cnes_1.0.0_1787770218047_0.9357902999623449"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-26T18:50:17.818Z","1.0.0":"2026-08-26T18:50:18.187Z","modified":"2026-08-26T18:50:18.477Z"},"maintainers":[{"name":"arielff03","email":"arielfrancoferreira5@gmail.com"}],"description":"Cliente tipado para a API do CNES (Cadastro Nacional de Estabelecimentos de Saude)","homepage":"https://github.com/arielff3/br-health-kit/tree/main/packages/cnes#readme","keywords":["cnes","datasus","estabelecimentos","saude","brasil"],"repository":{"type":"git","url":"git+https://github.com/arielff3/br-health-kit.git","directory":"packages/cnes"},"bugs":{"url":"https://github.com/arielff3/br-health-kit/issues"},"license":"MIT","readme":"# @br-health-kit/cnes\n\nA typed client for the CNES API, the Cadastro Nacional de Estabelecimentos de\nSaúde.\n\n```bash\nnpm install @br-health-kit/cnes\n```\n\n```ts\nimport { cnes } from '@br-health-kit/cnes'\n\nawait cnes.findEstablishment('2273993')\nawait cnes.listEstablishments({ ufCode: 33, limit: 10 })\n\ncnes.isValidCode('2273993')   // offline, syntactic\ncnes.normalizeCode(12345)     // '0012345'\n```\n\n## Why this package is a client, not a dataset\n\nEvery other package in the kit ships its data offline, versioned and\nreproducible. CNES cannot: the monthly DATASUS dump is **735 MB compressed**\nand covers roughly 380,000 establishments that change every month. Publishing\nthat on npm would be hostile to install and stale within weeks.\n\nSo this package owns the **shape** of the data rather than the data. It maps\nthe government API's 38 snake_case fields, with their nulls, their mixture of\nnumbers and strings, and their inconsistent naming (`numero_cnpj` next to\n`numero_cnpj_entidade`), onto a single typed model, and handles the timeouts\nand retries that talking to a government server requires.\n\n**The consequence, stated plainly:** results from this package are **not\nreproducible**. They reflect the API at the time of the call. When a result\nmust be pinned, for an audit or a billing batch, record what you received.\n\n## Two details that save debugging\n\n**Municipality codes have 6 digits, not 7.** DATASUS uses the IBGE code\nwithout its check digit: Rio de Janeiro is `330455`, not `3304557`. That is\nthe form the API both returns and accepts as a filter.\n\n**Leading zeros are restored.** Spreadsheets and JSON turn `0012345` into\n`12345`; `normalizeCode` undoes that before the call.\n\n## Errors\n\n- code absent from CNES: `null`, not an exception. It is a normal answer.\n- input that is not a CNES code: `InvalidCodeError`\n- API unreachable: `CnesRequestError`, after retry with backoff\n- 404 is not retried; 5xx and network failures are\n\n## Tests and the network\n\nThe client takes an injected `fetch`, so your suite does not have to depend on\na government server being up:\n\n```ts\nconst client = cnes.client({ fetch: myStub, baseUrl: 'http://localhost:1234' })\n```\n\n## Environment\n\nNode 20+, and any browser, through the same entry. There is no `/web` subpath\nhere because there is no local data to inject: this package is an API client.\n\nMind CORS, though. The Ministry of Health API is not built to be called from a\nbrowser, so in practice you usually want a proxy on your own backend, which is\nalso where the injectable `fetch` and `baseUrl` come in handy.\n\n## Provenance\n\nMinistry of Health data via `apidadosabertos.saude.gov.br`. Code under MIT.\n","readmeFilename":"README.md","_rev":"1-47b4386e092980aec0567ce8fb0743ae"}