This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Official NFE.io SDK for Node.js -- TypeScript native client for Brazilian electronic fiscal document APIs (NFS-e, NF-e, CT-e, CF-e). Version 3.x is a complete rewrite from the legacy v2 JavaScript/callback codebase (v2 lives in git history and is published as nfe-io@2.x on npm).
npm run validate:spec # Validate OpenAPI YAML specs
npm run generate # Generate TypeScript types from OpenAPI specs into src/generated/
npm run build # Full pipeline: validate:spec -> generate -> clean -> typecheck -> tsdown
npm run typecheck # TypeScript strict check (tsc --noEmit)
npm run lint # ESLint with auto-fix
npm run format # Prettier formattingnpm test # Run all tests (vitest, watch mode)
npm test -- --run # Run all tests once (no watch)
npm run test:unit # Unit tests only (tests/unit/)
npm run test:integration # Integration tests only (tests/integration/)
npm run test:coverage # Tests with v8 coverage report
npm test -- tests/unit/specific-file.test.ts # Run a single test fileCoverage thresholds: 80% for branches, functions, lines, and statements. Test setup is in tests/setup.ts with mock data generators and test constants.
src/index.ts-- Barrel export for all public API (NfeClient, types, errors)src/core/client.ts-- MainNfeClientclass with lazy-initialized resource getters and polling utilitiessrc/core/types.ts-- All TypeScript type definitions (config, resources, HTTP)src/core/http/client.ts-- Fetch-based HTTP client with retry, timeout, rate-limit handlingsrc/core/errors/-- Error hierarchy:NfeErrorbase, thenAuthenticationError,ValidationError,NotFoundError,RateLimitError,TimeoutError,ConnectionError, etc.src/core/resources/-- 17 resource implementations (service-invoices, companies, webhooks, etc.)src/generated/-- AUTO-GENERATED from OpenAPI specs. NEVER edit manually.
Specs live in openapi/spec/*.yaml. The generation script (scripts/generate-types.ts) produces typed interfaces in src/generated/. The build pipeline always validates and regenerates before compiling.
- Company-scoped operations: Most resource methods take
company_idas first parameter - Async invoice processing:
serviceInvoices.create()may return 202 + Location header; use polling utilities (pollUntilComplete,pollWithExponentialBackoff) for completion - Discriminated union returns: Create operations return typed results distinguishing immediate (201) vs async (202) responses
- Lazy resource initialization: Resources on
NfeClientare instantiated on first property access - Multiple API endpoints: Separate HTTP clients for different service APIs (main, CT-e, legal entity, natural person, etc.)
Dual format via tsdown (Rolldown): ESM (dist/index.js) + CommonJS (dist/index.cjs) + type declarations (dist/index.d.ts). Target: Node.js 22+.
- TypeScript strict mode with
noUncheckedIndexedAccess,exactOptionalPropertyTypes - Prettier: single quotes, trailing commas (ES5), 100 char width, semicolons
- ESLint: no
anytypes (warning), unused vars allowed with_prefix - No runtime dependencies -- everything uses Node.js built-ins (Fetch, AbortController, Buffer)
- Never edit files in
src/generated/-- they are overwritten by the generation pipeline - Run
npm run generateafter modifying any OpenAPI spec inopenapi/spec/ - Typecheck and tests must pass before commits (
npm run typecheck && npm test -- --run) - The CHANGELOG is written in Portuguese