|
| 1 | +# Onboarding Guide |
| 2 | + |
| 3 | +**New Contributor Quickstart** — Start contributing to the Socket.dev SDK in 5 minutes. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 📋 Prerequisites |
| 8 | + |
| 9 | +``` |
| 10 | +Required: |
| 11 | + ✓ Node.js 20+ (LTS recommended) |
| 12 | + ✓ pnpm 9+ |
| 13 | + ✓ Git |
| 14 | + ✓ Socket.dev API key (for integration tests) |
| 15 | +``` |
| 16 | + |
| 17 | +--- |
| 18 | + |
| 19 | +## 🚀 Quick Start |
| 20 | + |
| 21 | +### 1. Clone & Setup |
| 22 | + |
| 23 | +```bash |
| 24 | +# Clone |
| 25 | +git clone https://github.com/SocketDev/socket-sdk-js.git |
| 26 | +cd socket-sdk-js |
| 27 | + |
| 28 | +# Install & verify |
| 29 | +pnpm install |
| 30 | +pnpm test |
| 31 | +``` |
| 32 | + |
| 33 | +**Expected:** ✓ 95% test coverage, ✓ 100% type coverage |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +### 2. Project Structure |
| 38 | + |
| 39 | +``` |
| 40 | +socket-sdk-js/ |
| 41 | +├── src/ # Source code |
| 42 | +│ ├── api/ # API client implementation |
| 43 | +│ ├── types/ # TypeScript types |
| 44 | +│ ├── utils/ # Helper utilities |
| 45 | +│ └── index.ts # Main SDK exports |
| 46 | +│ |
| 47 | +├── test/ # Tests |
| 48 | +│ ├── unit/ # Unit tests |
| 49 | +│ └── integration/ # Integration tests |
| 50 | +│ |
| 51 | +├── scripts/ # Build scripts |
| 52 | +└── docs/ # Documentation |
| 53 | + ├── api-reference.md # Complete API docs |
| 54 | + ├── usage-examples.md # Code samples |
| 55 | + ├── when-to-use-what.md |
| 56 | + ├── quota-management.md |
| 57 | + └── dev/ # Developer docs |
| 58 | + └── testing.md |
| 59 | +``` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +### 3. Essential Commands |
| 64 | + |
| 65 | +```bash |
| 66 | +# Development |
| 67 | +pnpm run dev # Watch mode |
| 68 | +pnpm build # Build for production |
| 69 | + |
| 70 | +# Testing |
| 71 | +pnpm test # Unit tests |
| 72 | +pnpm test:integration # Integration tests (requires API key) |
| 73 | +pnpm run cover # With coverage |
| 74 | + |
| 75 | +# Quality |
| 76 | +pnpm run check # Type check + lint |
| 77 | +pnpm run fix # Auto-fix issues |
| 78 | +``` |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## 🔑 API Key Setup |
| 83 | + |
| 84 | +For integration tests, set your Socket.dev API key: |
| 85 | + |
| 86 | +```bash |
| 87 | +# .env file |
| 88 | +SOCKET_API_KEY=your-api-key-here |
| 89 | + |
| 90 | +# Or export directly |
| 91 | +export SOCKET_API_KEY=your-api-key-here |
| 92 | +``` |
| 93 | + |
| 94 | +Get your API key at [socket.dev/settings/api-keys](https://socket.dev/settings/api-keys) |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## 💡 Development Workflow |
| 99 | + |
| 100 | +``` |
| 101 | +1. Branch → git checkout -b feature/my-change |
| 102 | +2. Implement → Edit src/ files |
| 103 | +3. Test → pnpm test (unit + integration) |
| 104 | +4. Verify → pnpm run fix && pnpm test |
| 105 | +5. Docs → Update API docs if needed |
| 106 | +6. Commit → Conventional commits |
| 107 | +7. PR → Submit pull request |
| 108 | +``` |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## 📚 Key Concepts |
| 113 | + |
| 114 | +### 1. API Versioning |
| 115 | + |
| 116 | +The SDK wraps the Socket.dev REST API v0: |
| 117 | + |
| 118 | +```typescript |
| 119 | +import { SocketSdk } from '@socketsecurity/sdk' |
| 120 | + |
| 121 | +const sdk = new SocketSdk('your-api-key') |
| 122 | +``` |
| 123 | + |
| 124 | +### 2. Rate Limiting |
| 125 | + |
| 126 | +Be mindful of API quotas: |
| 127 | +- Check rate limits before large operations |
| 128 | +- Use quota management utilities |
| 129 | + |
| 130 | +See [docs/quota-management.md](./quota-management.md) |
| 131 | + |
| 132 | +### 3. Type Safety |
| 133 | + |
| 134 | +Full TypeScript support for all API responses: |
| 135 | + |
| 136 | +```typescript |
| 137 | +import type { PackageMetadata } from '@socketsecurity/sdk' |
| 138 | + |
| 139 | +const metadata: PackageMetadata = await sdk.getPackage('npm', 'lodash') |
| 140 | +``` |
| 141 | + |
| 142 | +### 4. Error Handling |
| 143 | + |
| 144 | +All API errors are properly typed: |
| 145 | + |
| 146 | +```typescript |
| 147 | +try { |
| 148 | + await sdk.getPackage('npm', 'nonexistent') |
| 149 | +} catch (error) { |
| 150 | + if (error.statusCode === 404) { |
| 151 | + // Handle not found |
| 152 | + } |
| 153 | +} |
| 154 | +``` |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## 🧪 Testing |
| 159 | + |
| 160 | +### Unit Tests |
| 161 | + |
| 162 | +Test business logic without API calls: |
| 163 | + |
| 164 | +```typescript |
| 165 | +// test/unit/utils/parse-purl.test.ts |
| 166 | +import { describe, it, expect } from 'vitest' |
| 167 | +import { parsePurl } from '../../../src/utils/parse-purl' |
| 168 | + |
| 169 | +describe('parsePurl', () => { |
| 170 | + it('parses npm purl', () => { |
| 171 | + expect(parsePurl('pkg:npm/lodash@4.17.21')).toEqual({ |
| 172 | + ecosystem: 'npm', |
| 173 | + name: 'lodash', |
| 174 | + version: '4.17.21' |
| 175 | + }) |
| 176 | + }) |
| 177 | +}) |
| 178 | +``` |
| 179 | + |
| 180 | +### Integration Tests |
| 181 | + |
| 182 | +Test actual API calls (requires API key): |
| 183 | + |
| 184 | +```typescript |
| 185 | +// test/integration/package.test.ts |
| 186 | +import { SocketSdk } from '../../src' |
| 187 | + |
| 188 | +const sdk = new SocketSdk(process.env.SOCKET_API_KEY!) |
| 189 | + |
| 190 | +it('fetches package metadata', async () => { |
| 191 | + const data = await sdk.getPackage('npm', 'lodash') |
| 192 | + expect(data.name).toBe('lodash') |
| 193 | +}) |
| 194 | +``` |
| 195 | + |
| 196 | +--- |
| 197 | + |
| 198 | +## 📖 Additional Resources |
| 199 | + |
| 200 | +- [API Reference](./api-reference.md) - Complete method docs |
| 201 | +- [Usage Examples](./usage-examples.md) - Common patterns |
| 202 | +- [When to Use What](./when-to-use-what.md) - Method selection guide |
| 203 | +- [Quota Management](./quota-management.md) - Rate limiting |
| 204 | +- [Testing Guide](./dev/testing.md) - Testing best practices |
| 205 | +- [CLAUDE.md](../CLAUDE.md) - Development standards |
| 206 | + |
| 207 | +--- |
| 208 | + |
| 209 | +## ✅ Checklist |
| 210 | + |
| 211 | +- [ ] Installed dependencies (`pnpm install`) |
| 212 | +- [ ] Set up API key (for integration tests) |
| 213 | +- [ ] Tests passing (`pnpm test`) |
| 214 | +- [ ] Read [API Reference](./api-reference.md) |
| 215 | +- [ ] Understand rate limiting |
| 216 | +- [ ] Know commit format (conventional commits) |
| 217 | +- [ ] Ready to contribute! |
| 218 | + |
| 219 | +**Welcome!** 🎉 |
0 commit comments