{"_rev":"4-9393029fffda9d9e75515eeba952326d","time":{"created":"2026-05-14T17:27:36.469Z","modified":"2026-05-14T17:27:37.039Z","0.1.0":"2026-05-14T17:18:50.337Z","0.1.1":"2026-05-14T17:27:36.749Z"},"_id":"@api-gouv-dinum/api-entreprise","name":"@api-gouv-dinum/api-entreprise","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.1":{"name":"@api-gouv-dinum/api-entreprise","version":"0.1.1","description":"Official Node.js client for API Entreprise v3","type":"module","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"}},"scripts":{"build":"tsup","test":"vitest run","test:watch":"vitest"},"engines":{"node":">=18.0.0"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/datagouv/apistration.git","directory":"clients/node/api-entreprise"},"keywords":["api-entreprise","api-gouv","france","siret","siren"],"devDependencies":{"@types/node":"^25.8.0","tsup":"^8.0.0","typescript":"^5.4.0","vitest":"^3.0.0"},"_id":"@api-gouv-dinum/api-entreprise@0.1.1","bugs":{"url":"https://github.com/datagouv/apistration/issues"},"homepage":"https://github.com/datagouv/apistration#readme","_nodeVersion":"25.2.1","_npmVersion":"11.6.2","dist":{"integrity":"sha512-4ABGAD4wgXMlt7DuYZtXQf763/pupMKpvxN/BrEMYn5G9mI86qOsCaq6U9y62+zC49PhJj1tQ8GiZbn4pSBGcA==","shasum":"c9d0b36919016aaa9b192ed74b5b278048cd36da","tarball":"https://registry.npmjs.org/@api-gouv-dinum/api-entreprise/-/api-entreprise-0.1.1.tgz","fileCount":9,"unpackedSize":383747,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAmYkV4iZnAmXgaxWVXRZqr+wm+vRU5lO/HBud72/Tb+AiA+2XN+pAHRkNSuIu2deRu57H6YObY0qUvszXDod4Aq5g=="}]},"_npmUser":{"name":"api-gouv","email":"equipe@entreprise.api.gouv.fr"},"directories":{},"maintainers":[{"name":"api-gouv","email":"equipe@entreprise.api.gouv.fr"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/api-entreprise_0.1.1_1778779656581_0.4265957209306108"},"_hasShrinkwrap":false}},"maintainers":[{"name":"api-gouv","email":"equipe@entreprise.api.gouv.fr"}],"description":"Official Node.js client for API Entreprise v3","homepage":"https://github.com/datagouv/apistration#readme","keywords":["api-entreprise","api-gouv","france","siret","siren"],"repository":{"type":"git","url":"git+https://github.com/datagouv/apistration.git","directory":"clients/node/api-entreprise"},"bugs":{"url":"https://github.com/datagouv/apistration/issues"},"license":"MIT","readme":"# @api-gouv-dinum/api-entreprise\n\nOfficial Node.js client for [API Entreprise v3](https://entreprise.api.gouv.fr).\n\n## Installation\n\n```bash\nnpm install @api-gouv-dinum/api-entreprise\n```\n\nRequires Node.js >= 18.0.0 (uses native `fetch`).\n\n## Configuration\n\n```typescript\nimport { Client } from '@api-gouv-dinum/api-entreprise';\n\nconst client = new Client({\n  token: 'your-jwt-token',\n  environment: 'production', // or 'staging'\n  defaultParams: {\n    recipient: '13002526500013', // SIRET of your administration\n    context: 'Aide sociale',\n    object: 'Dossier 12345',\n  },\n});\n```\n\nEnvironment variables are also supported:\n- `API_ENTREPRISE_TOKEN`\n- `API_ENTREPRISE_ENV` (`production` | `staging`)\n- `API_ENTREPRISE_BASE_URL` (custom override)\n\n## Quickstart\n\n```typescript\nconst response = await client.insee.etablissements('41816609600069');\nconsole.log(response.data);\nconsole.log(response.meta);\nconsole.log(response.rateLimit);\n```\n\nLow-level escape hatch for unwrapped endpoints:\n\n```typescript\nconst response = await client.get('/v4/insee/sirene/etablissements/41816609600069', {\n  params: { recipient: '13002526500013', context: 'test', object: 'demo' },\n});\n```\n\n## Error handling\n\n```typescript\nimport {\n  AuthenticationError,\n  AuthorizationError,\n  NotFoundError,\n  ValidationError,\n  RateLimitError,\n  ProviderError,\n  ProviderUnavailableError,\n  TransportError,\n} from '@api-gouv-dinum/api-entreprise';\n\ntry {\n  await client.insee.etablissements('41816609600069');\n} catch (error) {\n  if (error instanceof RateLimitError) {\n    console.log('Retry after', error.retryAfter, 'seconds');\n  } else if (error instanceof ProviderError) {\n    console.log('Provider down, retry in', error.retryAfter, 's');\n  } else if (error instanceof ValidationError) {\n    console.log('Invalid params:', error.firstErrorDetail);\n  }\n}\n```\n\n## Testing\n\nStub the global `fetch` in your tests. Example with [nock](https://github.com/nock/nock) or simple mock:\n\n### Stubbing a 200 response\n\n```typescript\nimport { Client } from '@api-gouv-dinum/api-entreprise';\nimport { vi } from 'vitest';\n\nglobalThis.fetch = vi.fn().mockResolvedValue({\n  ok: true,\n  status: 200,\n  text: () => Promise.resolve(JSON.stringify({\n    data: { siret: '41816609600069' },\n    links: {},\n    meta: {},\n  })),\n  headers: new Headers({\n    'RateLimit-Limit': '100',\n    'RateLimit-Remaining': '99',\n    'RateLimit-Reset': String(Math.floor(Date.now() / 1000) + 60),\n  }),\n});\n\nconst client = new Client({\n  token: 'test-token',\n  environment: 'staging',\n  defaultParams: { recipient: '41816609600069', context: 'test', object: 'test' },\n});\n\nconst response = await client.insee.etablissements('41816609600069');\nexpect(response.data.siret).toBe('41816609600069');\nexpect(response.rateLimit!.remaining).toBe(99);\n```\n\n### Stubbing a 429 rate limit\n\n```typescript\nconst futureReset = Math.floor(Date.now() / 1000) + 30;\n\nglobalThis.fetch = vi.fn().mockResolvedValue({\n  ok: false,\n  status: 429,\n  text: () => Promise.resolve(JSON.stringify({\n    errors: [{ code: '00429', title: 'Too Many Requests' }],\n  })),\n  headers: new Headers({ 'RateLimit-Reset': String(futureReset) }),\n});\n\ntry {\n  await client.get('/v3/test');\n} catch (error) {\n  expect(error).toBeInstanceOf(RateLimitError);\n  expect(error.retryAfter).toBeGreaterThan(0);\n}\n```\n","readmeFilename":"README.md"}