iracing-data-client 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,16 +1,17 @@
1
1
  # iRacing Data Client
2
2
 
3
- A TypeScript Data Client for the iRacing Data API with full type safety and authentication handling.
3
+ A TypeScript client for the iRacing Data API with full type safety and automatic OAuth2 authentication.
4
4
 
5
- ## Features
5
+ > **ℹ️ Authentication has been migrated to the new iRacing OAuth2 system.** The legacy email/password authentication has been replaced with OAuth2 client credentials. See the [Authentication guide](https://allymurray.github.io/iracing-data-client/getting-started/authentication/) for details.
6
6
 
7
- - 🏎️ Complete coverage of iRacing Data API (72+ endpoints)
8
- - 🔒 Built-in authentication with cookie management
7
+ - 🏎️ Complete coverage of the iRacing Data API (72+ endpoints)
8
+ - 🔒 OAuth2 authentication with automatic token refresh
9
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
10
  - 🔄 Automatic camelCase conversion for JavaScript conventions
11
+ - 🎯 Runtime parameter validation using Zod schemas
12
+ - 🛡️ Maintenance mode and rate limit detection
13
+
14
+ **[Documentation](https://allymurray.github.io/iracing-data-client)**
14
15
 
15
16
  ## Installation
16
17
 
@@ -24,6 +25,8 @@ yarn add iracing-data-client
24
25
 
25
26
  ## Quick Start
26
27
 
28
+ You'll need OAuth credentials from iRacing — see [OAuth Client Credentials](https://support.iracing.com/support/solutions/articles/31000177790-oauth-client-credentials) to register.
29
+
27
30
  ```typescript
28
31
  import { IRacingDataClient } from 'iracing-data-client';
29
32
 
@@ -37,87 +40,11 @@ const dataClient = new IRacingDataClient({
37
40
  },
38
41
  });
39
42
 
40
- // Fetch track data
41
43
  const tracks = await dataClient.track.get();
42
- console.log(tracks);
43
-
44
- // Get member info
45
44
  const member = await dataClient.member.get({ custIds: [123456] });
46
- console.log(member);
47
- ```
48
-
49
- ## Environment Variables
50
-
51
- Copy the example file and fill in your credentials:
52
-
53
- ```bash
54
- cp .env.example .env
55
- ```
56
-
57
- You'll need OAuth credentials from iRacing — see [OAuth Client Credentials](https://support.iracing.com/support/solutions/articles/31000177790-oauth-client-credentials) to register.
58
-
59
- ### Encrypting with dotenvx (recommended)
60
-
61
- We use [dotenvx](https://dotenvx.com) to encrypt `.env` files so secrets never exist as plaintext on disk:
62
-
63
- ```bash
64
- # Encrypt your .env file
65
- npx @dotenvx/dotenvx encrypt
66
-
67
- # Store the private key in your macOS Keychain
68
- security add-generic-password -a "iracing-data-client" -s "DOTENV_PRIVATE_KEY" -w "$(grep '^DOTENV_PRIVATE_KEY=' .env.keys | cut -d'=' -f2)"
69
- ```
70
-
71
- Once the key is in your keychain, you can delete `.env.keys` from disk.
72
-
73
- To run commands that need env vars, prefix with the key from keychain:
74
-
75
- ```bash
76
- DOTENV_PRIVATE_KEY=$(security find-generic-password -a "iracing-data-client" -s "DOTENV_PRIVATE_KEY" -w) pnpm test:integration
77
45
  ```
78
46
 
79
- To avoid typing the prefix every time, add an alias to your `~/.zshrc`:
80
-
81
- ```bash
82
- alias iracing-env='DOTENV_PRIVATE_KEY=$(security find-generic-password -a "iracing-data-client" -s "DOTENV_PRIVATE_KEY" -w)'
83
- ```
84
-
85
- Then just:
86
-
87
- ```bash
88
- iracing-env pnpm test:integration
89
- iracing-env pnpm sdk:test
90
- ```
91
-
92
- ### CI / GitHub Actions
93
-
94
- In CI, the encrypted `.env` file is restored from a GitHub secret and decrypted by dotenvx at runtime. This means adding or changing env vars only requires updating a single secret — the workflow YAML never needs to change.
95
-
96
- Two repository secrets are required:
97
-
98
- - **`DOTENV_PRIVATE_KEY`** — the decryption key (retrieve from your keychain)
99
- - **`DOTENV_ENV_FILE`** — the full content of your encrypted `.env` file
100
-
101
- To update `DOTENV_ENV_FILE`, copy the content of your local `.env` and paste it as the secret value in GitHub Settings > Secrets > Actions.
102
-
103
- ### Rotating keys
104
-
105
- If your private key is compromised, rotate it and update your keychain and GitHub secrets:
106
-
107
- ```bash
108
- # Generate a new key pair and re-encrypt all values
109
- npx @dotenvx/dotenvx rotate
110
-
111
- # Update the keychain entry
112
- security delete-generic-password -a "iracing-data-client" -s "DOTENV_PRIVATE_KEY"
113
- security add-generic-password -a "iracing-data-client" -s "DOTENV_PRIVATE_KEY" -w "$(grep '^DOTENV_PRIVATE_KEY=' .env.keys | cut -d'=' -f2)"
114
- ```
115
-
116
- After rotating, update the `DOTENV_PRIVATE_KEY` and `DOTENV_ENV_FILE` GitHub repository secrets to match.
117
-
118
- ## Available Services
119
-
120
- The Data Client is organized into the following services:
47
+ ## Services
121
48
 
122
49
  - **car** - Car assets and information
123
50
  - **carclass** - Car class data
@@ -127,7 +54,7 @@ The Data Client is organized into the following services:
127
54
  - **league** - League information and standings
128
55
  - **lookup** - Countries, drivers, licenses, etc.
129
56
  - **member** - Member profiles, awards, participation
130
- - **results** - Race results and lap data
57
+ - **results** - Race results and lap data
131
58
  - **season** - Season information and race guides
132
59
  - **series** - Series data and statistics
133
60
  - **stats** - Member statistics and world records
@@ -135,9 +62,9 @@ The Data Client is organized into the following services:
135
62
  - **timeAttack** - Time attack season results
136
63
  - **track** - Track assets and configuration
137
64
 
138
- ## Error Handling
65
+ See the [API reference](https://allymurray.github.io/iracing-data-client/api/services) for full details.
139
66
 
140
- The Data Client includes proper error handling for common iRacing API scenarios:
67
+ ## Error Handling
141
68
 
142
69
  ```typescript
143
70
  import { IRacingDataClient, IRacingError } from 'iracing-data-client';
@@ -148,107 +75,18 @@ try {
148
75
  if (error instanceof IRacingError) {
149
76
  if (error.isMaintenanceMode) {
150
77
  console.log('iRacing is in maintenance mode');
151
- // Handle gracefully
152
78
  return;
153
79
  }
154
-
80
+
155
81
  console.log(`API Error: ${error.message}`);
156
82
  console.log(`Status: ${error.status}`);
157
83
  }
158
84
  }
159
85
  ```
160
86
 
161
- ## Configuration Options
162
-
163
- ```typescript
164
- const dataClient = new IRacingDataClient({
165
- auth: {
166
- type: 'password-limited',
167
- clientId: 'your-client-id',
168
- clientSecret: 'your-client-secret',
169
- username: 'your-email@example.com',
170
- password: 'your-password',
171
- },
172
- });
173
- ```
174
-
175
- ## Development
176
-
177
- ### Scripts
178
-
179
- - `pnpm run sdk:generate` - Generate Data Client from API documentation
180
- - `pnpm run sdk:test` - Test the Data Client with live API calls
181
- - `pnpm run test` - Run unit tests
182
- - `pnpm run test:integration` - Run integration tests against the live API
183
- - `pnpm run typecheck` - Run TypeScript type checking
184
-
185
- ### Testing
186
-
187
- Scripts that need credentials use dotenvx automatically. Set `DOTENV_PRIVATE_KEY` and run:
188
-
189
- ```bash
190
- DOTENV_PRIVATE_KEY=$(security find-generic-password -a "iracing-data-client" -s "DOTENV_PRIVATE_KEY" -w) pnpm test:integration
191
- ```
192
-
193
- ### Generating the Data Client
194
-
195
- The Data Client is auto-generated from iRacing's API documentation:
196
-
197
- ```bash
198
- pnpm run sdk:generate
199
- ```
200
-
201
- This creates:
202
- - Individual service files in `src/[service]/service.ts`
203
- - Type definitions in `src/[service]/types.ts`
204
- - Main export file `src/index.ts`
205
- - HTTP client with authentication in `src/client.ts`
206
-
207
- ## API Reference
208
-
209
- ### Authentication
210
-
211
- The Data Client handles iRacing's OAuth2 authentication automatically. On first request, it will:
212
-
213
- 1. Authenticate using the Password Limited OAuth flow
214
- 2. Manage access and refresh tokens
215
- 3. Follow S3 redirect links to fetch actual data
216
- 4. Handle CSV responses where applicable
217
-
218
- ### Response Types
219
-
220
- All endpoints return fully typed responses. For example:
221
-
222
- ```typescript
223
- // Member service
224
- const members = await dataClient.member.get({ custIds: [123456] });
225
- // members is typed as MemberGetResponse[]
226
-
227
- // Track service
228
- const tracks = await dataClient.track.get();
229
- // tracks is typed as TrackGetResponse (TrackGetItem[])
230
- ```
231
-
232
- ### Parameter Validation
233
-
234
- All parameters are validated at runtime using Zod schemas:
235
-
236
- ```typescript
237
- // This will throw if seasonId is not a number
238
- await dataClient.season.list({ seasonId: 'invalid' }); // Validation error
239
- await dataClient.season.list({ seasonId: 12345 }); // Valid
240
- ```
241
-
242
87
  ## Contributing
243
88
 
244
- 1. Fork the repository
245
- 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
246
- 3. Make your changes
247
- 4. Run type checking (`npm run typecheck`)
248
- 5. Test with the live API (`npm run sdk:test`)
249
- 6. Commit your changes (`git commit -m 'Add amazing feature'`)
250
- 7. Push to the branch (`git push origin feature/amazing-feature`)
251
- 8. Open a Pull Request
89
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, including how to configure secrets with dotenvx and run integration tests.
252
90
 
253
91
  ## License
254
92
 
@@ -256,4 +94,4 @@ ISC License - see LICENSE file for details.
256
94
 
257
95
  ## Disclaimer
258
96
 
259
- This is an unofficial Data Client for the iRacing Data API. iRacing is a trademark of iRacing.com Motorsport Simulations, LLC.
97
+ This is an unofficial client for the iRacing Data API. iRacing is a trademark of iRacing.com Motorsport Simulations, LLC.