iracing-data-client 0.0.1
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/README.md +200 -0
- package/lib/index.d.mts +3299 -0
- package/lib/index.d.ts +3299 -0
- package/lib/index.js +4010 -0
- package/lib/index.js.map +1 -0
- package/lib/index.mjs +3858 -0
- package/lib/index.mjs.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# iRacing Data Client
|
|
2
|
+
|
|
3
|
+
A TypeScript Data Client for the iRacing Data API with full type safety and authentication handling.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🏎️ Complete coverage of iRacing Data API (72+ endpoints)
|
|
8
|
+
- 🔒 Built-in authentication with cookie management
|
|
9
|
+
- 📝 Full TypeScript support with generated types
|
|
10
|
+
- 🎯 Tree-shakeable imports using Zod schemas
|
|
11
|
+
- 🚀 Modular architecture with service-based organization
|
|
12
|
+
- 🛡️ Proper error handling with maintenance mode detection
|
|
13
|
+
- 🔄 Automatic camelCase conversion for JavaScript conventions
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install iracing-data-client
|
|
19
|
+
# or
|
|
20
|
+
pnpm add iracing-data-client
|
|
21
|
+
# or
|
|
22
|
+
yarn add iracing-data-client
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { IRacingDataClient } from 'iracing-data-client';
|
|
29
|
+
|
|
30
|
+
// Initialize with credentials
|
|
31
|
+
const dataClient = new IRacingDataClient({
|
|
32
|
+
email: 'your-email@example.com',
|
|
33
|
+
password: 'your-password'
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Fetch track data
|
|
37
|
+
const tracks = await dataClient.track.get();
|
|
38
|
+
console.log(tracks);
|
|
39
|
+
|
|
40
|
+
// Get member info
|
|
41
|
+
const member = await dataClient.member.get({ custIds: [123456] });
|
|
42
|
+
console.log(member);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Environment Variables
|
|
46
|
+
|
|
47
|
+
For testing and development, create a `.env` file:
|
|
48
|
+
|
|
49
|
+
```env
|
|
50
|
+
EMAIL=your-iracing-email@example.com
|
|
51
|
+
PASSWORD=your-iracing-password
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Available Services
|
|
55
|
+
|
|
56
|
+
The Data Client is organized into the following services:
|
|
57
|
+
|
|
58
|
+
- **car** - Car assets and information
|
|
59
|
+
- **carclass** - Car class data
|
|
60
|
+
- **constants** - Categories, divisions, event types
|
|
61
|
+
- **driverStatsByCategory** - Driver statistics by category
|
|
62
|
+
- **hosted** - Hosted session data
|
|
63
|
+
- **league** - League information and standings
|
|
64
|
+
- **lookup** - Countries, drivers, licenses, etc.
|
|
65
|
+
- **member** - Member profiles, awards, participation
|
|
66
|
+
- **results** - Race results and lap data
|
|
67
|
+
- **season** - Season information and race guides
|
|
68
|
+
- **series** - Series data and statistics
|
|
69
|
+
- **stats** - Member statistics and world records
|
|
70
|
+
- **team** - Team membership data
|
|
71
|
+
- **timeAttack** - Time attack season results
|
|
72
|
+
- **track** - Track assets and configuration
|
|
73
|
+
|
|
74
|
+
## Error Handling
|
|
75
|
+
|
|
76
|
+
The Data Client includes proper error handling for common iRacing API scenarios:
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
import { IRacingDataClient, IRacingError } from 'iracing-data-client';
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
const data = await dataClient.member.get({ custIds: [123] });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error instanceof IRacingError) {
|
|
85
|
+
if (error.isMaintenanceMode) {
|
|
86
|
+
console.log('iRacing is in maintenance mode');
|
|
87
|
+
// Handle gracefully
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
console.log(`API Error: ${error.message}`);
|
|
92
|
+
console.log(`Status: ${error.status}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Configuration Options
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const dataClient = new IRacingDataClient({
|
|
101
|
+
email: 'your-email@example.com', // iRacing account email
|
|
102
|
+
password: 'your-password', // iRacing account password
|
|
103
|
+
headers: { 'User-Agent': 'MyApp/1.0' }, // Custom headers (optional)
|
|
104
|
+
fetchFn: customFetch, // Custom fetch function (optional)
|
|
105
|
+
validateParams: true // Enable parameter validation (optional)
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
### Scripts
|
|
112
|
+
|
|
113
|
+
- `npm run sdk:generate` - Generate Data Client from API documentation
|
|
114
|
+
- `npm run sdk:test` - Test the Data Client with live API calls
|
|
115
|
+
- `npm run typecheck` - Run TypeScript type checking
|
|
116
|
+
- `npm run test` - Run unit tests
|
|
117
|
+
|
|
118
|
+
### Generating the Data Client
|
|
119
|
+
|
|
120
|
+
The Data Client is auto-generated from iRacing's API documentation:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm run sdk:generate
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
This creates:
|
|
127
|
+
- Individual service files in `src/[service]/service.ts`
|
|
128
|
+
- Type definitions in `src/[service]/types.ts`
|
|
129
|
+
- Main export file `src/index.ts`
|
|
130
|
+
- HTTP client with authentication in `src/client.ts`
|
|
131
|
+
|
|
132
|
+
### Testing
|
|
133
|
+
|
|
134
|
+
Test the Data Client against the live iRacing API:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npm run sdk:test
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Make sure your credentials are in the `.env` file.
|
|
141
|
+
|
|
142
|
+
## API Reference
|
|
143
|
+
|
|
144
|
+
### Authentication
|
|
145
|
+
|
|
146
|
+
The Data Client handles iRacing's cookie-based authentication automatically. On first request, it will:
|
|
147
|
+
|
|
148
|
+
1. Log in with your credentials
|
|
149
|
+
2. Store authentication cookies
|
|
150
|
+
3. Follow S3 redirect links to fetch actual data
|
|
151
|
+
4. Handle CSV responses where applicable
|
|
152
|
+
|
|
153
|
+
### Response Types
|
|
154
|
+
|
|
155
|
+
All endpoints return fully typed responses. For example:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Member service
|
|
159
|
+
const members = await dataClient.member.get({ custIds: [123456] });
|
|
160
|
+
// members is typed as MemberGetResponse[]
|
|
161
|
+
|
|
162
|
+
// Track service
|
|
163
|
+
const tracks = await dataClient.track.get();
|
|
164
|
+
// tracks is typed as TrackGetResponse (TrackGetItem[])
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Parameter Validation
|
|
168
|
+
|
|
169
|
+
When `validateParams: true` is set, the Data Client validates all parameters using Zod schemas:
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const dataClient = new IRacingDataClient({
|
|
173
|
+
email: 'test@example.com',
|
|
174
|
+
password: 'password',
|
|
175
|
+
validateParams: true
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
// This will throw if seasonId is not a number
|
|
179
|
+
await dataClient.season.list({ seasonId: 'invalid' }); // ❌ Validation error
|
|
180
|
+
await dataClient.season.list({ seasonId: 12345 }); // ✅ Valid
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
1. Fork the repository
|
|
186
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
187
|
+
3. Make your changes
|
|
188
|
+
4. Run type checking (`npm run typecheck`)
|
|
189
|
+
5. Test with the live API (`npm run sdk:test`)
|
|
190
|
+
6. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
191
|
+
7. Push to the branch (`git push origin feature/amazing-feature`)
|
|
192
|
+
8. Open a Pull Request
|
|
193
|
+
|
|
194
|
+
## License
|
|
195
|
+
|
|
196
|
+
ISC License - see LICENSE file for details.
|
|
197
|
+
|
|
198
|
+
## Disclaimer
|
|
199
|
+
|
|
200
|
+
This is an unofficial Data Client for the iRacing Data API. iRacing is a trademark of iRacing.com Motorsport Simulations, LLC.
|