This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
syno is a Node.js wrapper and CLI for the Synology DSM REST API (supports DSM 5.x, 6.x, and 7.x). Written in TypeScript with ESM + CJS dual output. Ships a CLI executable.
# Build (tsdown: ESM + CJS + DTS)
npm run build
# Run tests (vitest)
npm test
# Run tests in watch mode
npm run test:watch
# Lint TypeScript
npm run lint
# Type check
npm run typecheck
# Clean dist/
npm run clean
# Fetch/compile API definitions
npm run fetch-defs # Full pipeline (download + extract + compile)
npm run compile-defs # Just merge existing .api/.lib filesSYNO_PROTOCOL, SYNO_HOST, SYNO_PORT, SYNO_ACCOUNT, SYNO_PASSWORD
- API (
API.ts) — base class; makes HTTP requests via nativefetchto{protocol}://{host}:{port}/webapi/{path} - Auth (
Auth.ts) — extends API; handles login/logout viaSYNO.API.Auth, supports OTP - AuthenticatedAPI (
AuthenticatedAPI.ts) — extends API; auto-callsauth.login()if no session SID before each request - Syno (
Syno.ts) — top-level entry point; instantiates Auth + all station APIs
Each extends AuthenticatedAPI and uses Proxy-based dynamic method generation:
- DSM, FileStation, DownloadStation, AudioStation, VideoStation, VideoStationDTV, SurveillanceStation, SynologyPhotos
Uses buildMethodMap() to read definitions/{version}/_full.json and create a Map<string, MethodInfo>. createProxiedStation() wraps the station in a Proxy that intercepts property access to dispatch dynamic API methods.
src/lib/utils.ts—createFunctionName()pipeline: trimSyno -> deletePattern -> fixCamelCase -> listPluralize -> camelCasesrc/lib/errors.ts— Error resolvers for base, auth, FileStation, DownloadStation, SurveillanceStationsrc/lib/DefinitionLoader.ts— Loads and caches API definitions from JSON files
config.ts— URL parsing, YAML config loading, env var resolutionindex.ts— Commander v12 withparseAsync(), 8 station subcommands
tsdown (powered by rolldown): TypeScript -> ESM (dist/index.js) + CJS (dist/index.cjs) + DTS (dist/index.d.ts) + CLI (dist/cli.cjs with shebang)
src/— TypeScript source (library + CLI + tests)dist/— compiled/bundled output (gitignored)definitions/— Synology API definition JSON files;_full.jsonfiles per versionscripts/—fetch-definitions.tsfor downloading/compiling API definitions
- Strict mode enabled
- ESM with
.jsextensions in imports (NodeNext resolution) - Async/await only — no callbacks
- Native
fetch— no HTTP client dependencies