This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build # Full build: clean → tsc (ESM) → tsc (CJS) → rollup bundles
npm run test # Run all tests with mocha
npm run lint # ESLint check
npm run lint:fix # ESLint auto-fix
npm run report # Run tests with c8 coverage
npm run release # Bump version + update CHANGELOG (standard-version)
npm run gen-openapi # Regenerate TypeScript types from OpenAPI specsRun a single test file:
npx mocha --reporter=dot test/api/factory.spec.tsDebug HTTP requests:
DEBUG=ebay:* npm run testThe build produces two module formats from the same TypeScript source:
- ESM (
dist/):tscwithtsconfig.json(module: node16) - CJS (
lib/):tscwithtsconfig.cjs.json(module: commonjs) +lib/package.jsoninjected with{"type":"commonjs"}to prevent conflicts - Browser bundles: rollup processes
lib/index.js→ UMD (lib/ebay-api.min.js) anddist/eBayApi.js→ ESM (dist/ebay-api.min.mjs)
Base (config + req)
└── Api (+ auth + digital signature helpers)
├── Auth (OAuth2 + AuthNAuth)
├── ApiFactory (creates all API instances, lazily cached)
│ ├── Restful (base for all REST endpoints)
│ │ └── Each API endpoint class (Browse, Inventory, etc.)
│ └── Traditional (XML-based APIs)
│ └── XMLRequest (builds/parses XML, calls req)
└── eBayApi (main public entry point, lazy getters per API group)
IEBayApiRequest is the HTTP abstraction interface. The default implementation is AxiosRequest. Tests inject mock stubs implementing this interface directly.
- Create class in
src/api/restful/<group>/<name>/index.tsextendingRestful - Set
static id = 'Name'and implementget basePath()returning the eBay API path - Add the OpenAPI JSON spec to
specs/, configure it inredocly.yaml, runnpm run gen-openapito generate types insrc/types/restful/specs/ - Implement methods using
this.get(),this.post(), etc. (inherited fromRestful) - Wire it into
ApiFactoryand the relevant group index type
Token refresh: Both Restful and Traditional automatically retry on 401/EBayInvalidAccessToken by calling OAuth2.refreshToken() and replaying the request.
Digital Signature: Opt-in per request via .sign getter on any Restful instance (e.g., eBay.sell.finances.sign.getPayouts()). Traditional APIs also support sign: true in config.
returnResponse: By default, only response.data is returned. Pass returnResponse: true in apiConfig to get the full Axios response.
apix / apiz: Convenience getters on Restful to switch the API subdomain for specific eBay endpoints that use apix.ebay.com or apiz.ebay.com.
- All imports of interfaces and type aliases must use
import type(or inlinetypemodifier) in test files. The mocha 11 + Node.js v24 loader chain resolves.jsextensions synchronously, bypassing ts-node for transitive imports — runtime will throw if a type-only named export is imported as a value. - TypeScript
noUnusedLocalsandnoUnusedParametersare enabled — all declared variables/parameters must be used. - OpenAPI-generated type files in
src/types/restful/specs/are excluded from the maintsconfig.json'sincludearray but are referenced directly by the API classes.
eBay OpenAPI 3 specs live in specs/*.json. redocly.yaml maps each spec to a generated TypeScript file via openapi-typescript. Run npm run gen-openapi after updating any spec. The generated files define an operations type that each API class implements via OpenApi<operations>.
npm run release uses standard-version which reads .versionrc.json. It bumps package.json, package-lock.json, updates CHANGELOG.md, and patches the version string in README.md via scripts/update-readme-release.cjs.