Skip to content

Introduce node clients#128

Merged
skelz0r merged 9 commits into
developfrom
clients/javascript
May 15, 2026
Merged

Introduce node clients#128
skelz0r merged 9 commits into
developfrom
clients/javascript

Conversation

@skelz0r
Copy link
Copy Markdown
Member

@skelz0r skelz0r commented May 15, 2026

https://www.npmjs.com/package/@api-gouv-dinum/api-entreprise
https://www.npmjs.com/package/@api-gouv-dinum/api-particulier

CI configuré + readme/claude setup pour les futures releases.

Quelques itérations sur le specs.md à la suite de l'implémentation en full autonomie de claude.

@skelz0r skelz0r self-assigned this May 15, 2026
@skelz0r skelz0r force-pushed the clients/javascript branch from cd29f97 to 5f317b4 Compare May 15, 2026 07:27
skelz0r added 9 commits May 15, 2026 09:28
In languages like JavaScript, spreading `{ ...defaults, ...{ key: undefined } }`
silently erases the default value for that key. The previous wording only said
"nil params are dropped" without specifying when relative to the merge step.
This led to a real bug during the Node.js port where per-call undefined params
from scaffolded resource methods would erase client-level defaults for
recipient/context/object.
…imeouts

The WHATWG fetch API (Node 18+, Deno, browsers) only exposes a single
AbortController timeout covering the full request lifecycle — there is no
way to set a connect timeout independently. The spec now allows accepting
both values for interface consistency while applying only the read timeout
when the transport doesn't support the split.
…ntent

The spec said "emit a deprecation warning through the language-native channel"
but didn't specify the mechanism per language or the minimum content of the
message. Without this, each port invents its own format, making deprecation
warnings inconsistent across SDKs. Now requires the path template + method
name in the message, and names the idiomatic API per language.
meta.retry_in is in seconds, but many languages (JS, Java) use milliseconds
for timers. During the Node.js port a real bug happened: the delay was
multiplied by 1000 when calling the sleep helper, which internally also
multiplied by 1000, turning a 0.5s retry into a 500s wait and causing test
timeouts. Added an explicit implementer warning.
The previous wording was Ruby/Faraday-centric ("strip [] when the library
appends it automatically"). Each HTTP library handles array serialization
differently — some auto-append brackets, some don't, some use indexed keys.
Added a reference table covering Ruby, Node, Python, and PHP so porters know
what to do without reverse-engineering Faraday's behavior. Also recommends
a wire-format assertion test since bracket bugs are silent.
TESTING.md is the staging conformance playbook that every new client must
pass before being declared SPECS-conformant. It was only referenced deep
in SPECS.md §12.4 — easy to miss when following the README's step-by-step
porting guide. Moved it to step 2, right after reading SPECS.md, so porters
discover it before writing any code.
- CLAUDE.md: add "Nouveau client" section listing the 5 places to update
  when implementing a new SDK (changelog, api_entreprise docs, api_particulier
  docs, clients/README, CLAUDE.md itself). Also add Node.js build commands
  to the "Lecture obligatoire" section.
- README.md: add node/ to the directory inventory table.
SPECS.md-conformant Node.js client matching the Ruby reference
implementation. Two packages: @api-gouv-dinum/api-entreprise and
@api-gouv-dinum/api-particulier, built with zero runtime dependencies
(native fetch, Node 18+).

Architecture:
- commons/ source of truth, vendored into each package via
  bin/sync-commons.ts (same pattern as Ruby)
- bin/scaffold-resources.ts generates resource classes from the
  OpenAPI YAML specs in commons/swagger/
- Dual ESM + CJS output via tsup, with .d.ts type declarations
- GitHub Actions CI (Node 18/20/22 matrix) + npm publish via
  Trusted Publishing (OIDC) on tag node-api-*-v*

Covered SPECS.md conformance:
- Immutable Configuration with with()/copy(), env var defaults
- BearerToken auth strategy (pluggable AuthStrategy interface)
- JSON:API response envelope (data, links, meta, rateLimit)
- Full error hierarchy: ClientError (Auth, Authorization, NotFound,
  Conflict, Validation, RateLimit) + ServerError (Provider,
  ProviderUnavailable) + TransportError
- SIRET/SIREN Luhn validation with La Poste exception
- RateLimit-* header parsing with retryAfter()
- Opt-in retry middleware (exponential backoff + jitter, honors
  Retry-After and meta.retry_in)
- User-Agent per §10 format
- Query string redaction for API Particulier (PII protection)
- Array params encoded as key[]=v1&key[]=v2
- Deprecation warnings via process.emitWarning

Tests: 176 passing (106 commons + 52 api-entreprise + 18 api-particulier)
covering the full §12.1 unit matrix and §12.2 integration scenarios.
Add changelog entry for the Node.js SDK release and update the SDK
tables in both API Entreprise and API Particulier documentation
pages to mark Node.js as available.
@skelz0r skelz0r force-pushed the clients/javascript branch from 5f317b4 to 3dca3b6 Compare May 15, 2026 07:32
@skelz0r skelz0r requested review from Samuelfaure and Un3x May 15, 2026 08:32
Copy link
Copy Markdown
Contributor

@Un3x Un3x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai tout lu (non)

@skelz0r skelz0r merged commit c4d2c56 into develop May 15, 2026
14 checks passed
@skelz0r skelz0r deleted the clients/javascript branch May 15, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants