heyreach-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +128 -0
- package/dist/index.js +2612 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.js +2359 -0
- package/dist/mcp.js.map +1 -0
- package/package.json +48 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# Claude Code Instructions — HeyReach CLI
|
|
2
|
+
|
|
3
|
+
## Project Overview
|
|
4
|
+
|
|
5
|
+
CLI and MCP server for the [HeyReach](https://heyreach.io) LinkedIn automation platform. Wraps the HeyReach Public API (47 commands across 10 groups) into both a terminal CLI and an MCP server for AI assistants.
|
|
6
|
+
|
|
7
|
+
**Dual interface, single codebase:** Every API endpoint is defined once as a `CommandDefinition` object that powers both the CLI subcommand and the MCP tool.
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
### CommandDefinition Pattern
|
|
12
|
+
|
|
13
|
+
Every API endpoint lives in one file under `src/commands/<group>/<subcommand>.ts` and exports a single `CommandDefinition` object:
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
interface CommandDefinition {
|
|
17
|
+
name: string; // MCP tool name: "campaigns_list"
|
|
18
|
+
group: string; // CLI group: "campaigns"
|
|
19
|
+
subcommand: string; // CLI subcommand: "list"
|
|
20
|
+
description: string; // Shared help text
|
|
21
|
+
inputSchema: ZodObject; // Validates CLI flags AND MCP input
|
|
22
|
+
cliMappings: {...}; // Maps Zod fields to Commander args/options
|
|
23
|
+
endpoint: { method, path };
|
|
24
|
+
fieldMappings: {...}; // Where each field goes: path | query | body
|
|
25
|
+
handler: (input, client) => Promise<unknown>;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Adding a new endpoint = creating one file + adding it to the group index + allCommands array in `src/commands/index.ts`.**
|
|
30
|
+
|
|
31
|
+
### Key Files
|
|
32
|
+
|
|
33
|
+
- `src/core/types.ts` — CommandDefinition interface and shared types
|
|
34
|
+
- `src/core/client.ts` — HTTP client (X-API-KEY header, retry, rate limiting, offset/limit pagination)
|
|
35
|
+
- `src/core/handler.ts` — executeCommand() builds HTTP requests from CommandDefinition + input
|
|
36
|
+
- `src/core/auth.ts` — API key resolution (--api-key flag > env var > config file). Supports both workspace and org keys.
|
|
37
|
+
- `src/core/output.ts` — JSON output formatting, --fields, --quiet, --pretty
|
|
38
|
+
- `src/core/errors.ts` — Typed error classes (AuthError, RateLimitError, etc.)
|
|
39
|
+
- `src/core/config.ts` — ~/.heyreach/config.json manager
|
|
40
|
+
- `src/commands/index.ts` — Command registry, auto-registration, login/logout/status/config
|
|
41
|
+
- `src/mcp-entry.ts` — MCP server (registers all CommandDefinitions as tools)
|
|
42
|
+
- `src/index.ts` — CLI entry point
|
|
43
|
+
- `src/mcp.ts` — Direct MCP entry point
|
|
44
|
+
|
|
45
|
+
### Directory Structure
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
src/
|
|
49
|
+
├── index.ts # CLI entry
|
|
50
|
+
├── mcp.ts # MCP entry
|
|
51
|
+
├── mcp-entry.ts # MCP server factory
|
|
52
|
+
├── core/ # Shared infrastructure
|
|
53
|
+
│ ├── types.ts
|
|
54
|
+
│ ├── client.ts
|
|
55
|
+
│ ├── handler.ts
|
|
56
|
+
│ ├── auth.ts
|
|
57
|
+
│ ├── config.ts
|
|
58
|
+
│ ├── output.ts
|
|
59
|
+
│ └── errors.ts
|
|
60
|
+
├── commands/
|
|
61
|
+
│ ├── index.ts # Registry + registerAllCommands()
|
|
62
|
+
│ ├── campaigns/ # 8 commands (list, get, resume, pause, add-leads, stop-lead, get-leads, get-for-lead)
|
|
63
|
+
│ ├── inbox/ # 4 commands (list, get, send, set-seen)
|
|
64
|
+
│ ├── accounts/ # 2 commands (list, get) — LinkedIn accounts
|
|
65
|
+
│ ├── lists/ # 9 commands (get, list, create, get-leads, add-leads, delete-leads, delete-leads-by-url, get-companies, get-for-lead)
|
|
66
|
+
│ ├── stats/ # 1 command (overview)
|
|
67
|
+
│ ├── leads/ # 4 commands (get, add-tags, get-tags, replace-tags)
|
|
68
|
+
│ ├── lead-tags/ # 1 command (create)
|
|
69
|
+
│ ├── webhooks/ # 5 commands (create, get, list, update, delete)
|
|
70
|
+
│ ├── network/ # 2 commands (list, check) — MyNetwork
|
|
71
|
+
│ └── org/ # 11 commands — Organization Management API (requires --org-key)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Tech Stack
|
|
75
|
+
|
|
76
|
+
- **TypeScript** (ESM, strict mode)
|
|
77
|
+
- **Node.js 18+** (target node18 in tsup)
|
|
78
|
+
- **Commander.js** — CLI framework
|
|
79
|
+
- **Zod** — Input validation (shared between CLI and MCP)
|
|
80
|
+
- **@modelcontextprotocol/sdk** — MCP server
|
|
81
|
+
- **tsup** — Bundler (two entry points: index.ts, mcp.ts)
|
|
82
|
+
- **vitest** — Testing
|
|
83
|
+
|
|
84
|
+
## Development Commands
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
bun run build # Build with tsup → dist/
|
|
88
|
+
bun run dev # Run CLI with tsx (no build needed)
|
|
89
|
+
bun test # Run vitest
|
|
90
|
+
bun run typecheck # TypeScript type checking
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Quirks
|
|
94
|
+
|
|
95
|
+
- **Auth header is `X-API-KEY`** (not Bearer token)
|
|
96
|
+
- **Base URL:** `https://api.heyreach.io/api/public/`
|
|
97
|
+
- **Most list endpoints use POST** (not GET) — body contains offset/limit/filters
|
|
98
|
+
- **Pagination:** POST body `{ offset, limit }` → response `{ totalCount, items[] }`
|
|
99
|
+
- **MyNetwork endpoints use `pageNumber`/`pageSize`** instead of offset/limit
|
|
100
|
+
- **Rate limit:** 300 requests/minute (429 on exceed)
|
|
101
|
+
- **Dual API keys:** Workspace key (regular endpoints) vs Organization key (`org` group)
|
|
102
|
+
- **Organization API** has its own separate 300 req/min limit
|
|
103
|
+
- **V2 endpoints** (AddLeadsToCampaignV2, AddLeadsToListV2) return detailed counts; V1 returns just a number. CLI uses V2.
|
|
104
|
+
|
|
105
|
+
## Adding New Commands
|
|
106
|
+
|
|
107
|
+
1. Create `src/commands/<group>/<subcommand>.ts`
|
|
108
|
+
2. Export a `CommandDefinition` object following existing patterns
|
|
109
|
+
3. Import and add it to the group's `index.ts`
|
|
110
|
+
4. Add the group to `allCommands` in `src/commands/index.ts` (if new group)
|
|
111
|
+
5. Build and test: `bun run build && bun test`
|
|
112
|
+
|
|
113
|
+
Use `executeCommand()` from `src/core/handler.ts` as the handler for standard endpoints. Write custom handlers when the API requires special request transformation (e.g., splitting comma-separated CLI strings into arrays, nested filter objects).
|
|
114
|
+
|
|
115
|
+
## Important Conventions
|
|
116
|
+
|
|
117
|
+
- **All output is JSON to stdout** — never use console.log for anything except structured output. Use console.error for errors.
|
|
118
|
+
- **Zod validation runs before API calls** — gives clear validation errors
|
|
119
|
+
- **Org commands auto-use org API key** — the `registerCommand()` function detects `group === 'org'` and uses `resolveOrgAuth()` instead of `resolveAuth()`
|
|
120
|
+
- **Comma-separated CLI inputs** → Arrays are accepted as comma-separated strings (e.g., `--statuses "IN_PROGRESS,PAUSED"`) and split in the handler
|
|
121
|
+
- **JSON inputs** → Complex nested objects use `--xxx-json` flags (e.g., `--leads-json`, `--tags-json`, `--permissions-json`)
|
|
122
|
+
|
|
123
|
+
## Do Not
|
|
124
|
+
|
|
125
|
+
- Do not modify the output format — agents depend on JSON to stdout
|
|
126
|
+
- Do not add interactive prompts to API commands — only login should be interactive
|
|
127
|
+
- Do not create new command files without adding them to the group index and allCommands array
|
|
128
|
+
- Do not use `Authorization: Bearer` — HeyReach uses `X-API-KEY` header
|