|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is `@short.io/client-node` — the official Short.io API client for Node.js, written in TypeScript. It provides 45+ typed functions for URL shortening, link management, QR codes, analytics, geographic targeting, and more. |
| 8 | + |
| 9 | +**Almost all code is auto-generated.** Only two files are hand-written: |
| 10 | +- `src/index.ts` — entry point, exports, and `setApiKey()` helper |
| 11 | +- `openapi/config.ts` — OpenAPI code generation config with semantic operation ID mappings |
| 12 | + |
| 13 | +Everything under `src/generated/` is produced by `@hey-api/openapi-ts` from the Short.io OpenAPI spec. |
| 14 | + |
| 15 | +## Build & Development Commands |
| 16 | + |
| 17 | +```bash |
| 18 | +# Install dependencies (uses Yarn 1.x) |
| 19 | +yarn install |
| 20 | + |
| 21 | +# Regenerate SDK from OpenAPI spec (https://api.short.io/openapi.json) |
| 22 | +npm run generate |
| 23 | + |
| 24 | +# Compile TypeScript (tsc + tsc-alias for path resolution) |
| 25 | +npm run compile |
| 26 | +``` |
| 27 | + |
| 28 | +There are no tests in this repository. The SDK is validated through OpenAPI spec conformance. |
| 29 | + |
| 30 | +## Architecture |
| 31 | + |
| 32 | +``` |
| 33 | +src/ |
| 34 | +├── index.ts # Hand-written: exports + setApiKey() |
| 35 | +└── generated/ # All auto-generated |
| 36 | + ├── sdk.gen.ts # 45+ API operation functions (createLink, listLinks, etc.) |
| 37 | + ├── types.gen.ts # All TypeScript types (~3800 lines) |
| 38 | + ├── client.gen.ts # Client singleton |
| 39 | + ├── client/ # HTTP client implementation (fetch-based) |
| 40 | + └── core/ # Auth, serializers, SSE, utilities |
| 41 | +``` |
| 42 | + |
| 43 | +**Layered design:** |
| 44 | +1. **Public API** (`src/index.ts`) — re-exports everything, provides `setApiKey()` |
| 45 | +2. **SDK functions** (`sdk.gen.ts`) — each API operation is a typed function using a consistent generic pattern |
| 46 | +3. **Client** (`client/`) — HTTP client factory with interceptors, config merging, URL building |
| 47 | +4. **Core** (`core/`) — auth handling, body/query/path serialization, SSE support |
| 48 | + |
| 49 | +**SDK function pattern** — every operation follows this signature: |
| 50 | +```typescript |
| 51 | +export const operationName = <ThrowOnError extends boolean = false>( |
| 52 | + options: Options<OperationData, ThrowOnError> |
| 53 | +) => (options.client ?? client).httpMethod<Response, Error, ThrowOnError>({...}) |
| 54 | +``` |
| 55 | + |
| 56 | +## Key Development Notes |
| 57 | + |
| 58 | +- **ESM-only** (`"type": "module"`) — no CommonJS support |
| 59 | +- **Strict TypeScript** with `noUnusedLocals`, incremental compilation |
| 60 | +- **Node.js 18.0.0+** required |
| 61 | +- **Runtime dependency:** `@hey-api/client-fetch` only |
| 62 | +- The `dist/` directory is gitignored; `npm run compile` produces it |
| 63 | +- `openapi.json` is also gitignored — it's fetched during generation |
| 64 | + |
| 65 | +## Modifying the SDK |
| 66 | + |
| 67 | +To update API operations: |
| 68 | +1. Edit operation ID mappings in `openapi/config.ts` (the `operationPatching` object maps HTTP endpoints to semantic function names like `'POST /links'` → `createLink`) |
| 69 | +2. Run `npm run generate` to regenerate from the live OpenAPI spec |
| 70 | +3. Run `npm run compile` to verify compilation |
| 71 | + |
| 72 | +Do **not** manually edit files under `src/generated/` — they will be overwritten on next generation. |
0 commit comments