irdata_js 0.2.0 → 0.3.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 +42 -14
- package/dist/index.cjs +678 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{client.d.ts → index.d.cts} +67 -8
- package/dist/index.d.ts +138 -4
- package/dist/index.global.js +672 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +647 -4
- package/dist/index.js.map +1 -0
- package/package.json +21 -9
- package/dist/auth/AuthManager.d.ts +0 -25
- package/dist/auth/AuthManager.js +0 -170
- package/dist/auth/PKCEHelper.d.ts +0 -14
- package/dist/auth/PKCEHelper.js +0 -131
- package/dist/client.js +0 -213
- package/dist/errors.d.ts +0 -6
- package/dist/errors.js +0 -12
package/README.md
CHANGED
|
@@ -8,6 +8,19 @@ JavaScript library to interact with the iRacing /data API.
|
|
|
8
8
|
npm install irdata_js
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## CDN Usage
|
|
12
|
+
|
|
13
|
+
For direct usage in the browser without a build step, you can load the library via a CDN. The library is exposed as the global `irdata` variable.
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://unpkg.com/irdata_js/dist/index.global.js"></script>
|
|
17
|
+
<script>
|
|
18
|
+
const client = new irdata.IRacingClient({
|
|
19
|
+
// ...
|
|
20
|
+
});
|
|
21
|
+
</script>
|
|
22
|
+
```
|
|
23
|
+
|
|
11
24
|
## Quick Start
|
|
12
25
|
|
|
13
26
|
The library supports OAuth 2.0 authentication.
|
|
@@ -62,8 +75,11 @@ try {
|
|
|
62
75
|
const { data, metadata } = await client.getData('/member/info');
|
|
63
76
|
|
|
64
77
|
console.log(data); // The actual API response
|
|
78
|
+
console.log(metadata.contentType); // Response content type (e.g. 'application/json')
|
|
65
79
|
console.log(metadata.sizeBytes); // Response size in bytes
|
|
66
|
-
console.log(metadata.
|
|
80
|
+
console.log(metadata.fetchTimeMs); // Fetch duration in milliseconds
|
|
81
|
+
console.log(metadata.chunkCount); // Number of chunks (0 if not chunked)
|
|
82
|
+
console.log(metadata.chunkRows); // Total rows across all chunks (valid if chunkCount > 0)
|
|
67
83
|
} catch (error) {
|
|
68
84
|
console.error('Failed to fetch member info:', error);
|
|
69
85
|
}
|
|
@@ -71,14 +87,14 @@ try {
|
|
|
71
87
|
|
|
72
88
|
### 4. Handling Large Datasets (Chunks)
|
|
73
89
|
|
|
74
|
-
Some iRacing endpoints (like large result sets) return data in multiple "chunks" hosted on S3. When `metadata.
|
|
90
|
+
Some iRacing endpoints (like large result sets) return data in multiple "chunks" hosted on S3. When `metadata.chunkCount` is greater than 0, you can use the library to fetch the rest of the data.
|
|
75
91
|
|
|
76
92
|
#### Fetch all chunks at once
|
|
77
93
|
|
|
78
94
|
```javascript
|
|
79
95
|
const result = await client.getData('/results/get');
|
|
80
96
|
|
|
81
|
-
if (result.metadata.
|
|
97
|
+
if (result.metadata.chunkCount > 0) {
|
|
82
98
|
// Fetch and merge all chunks into a single array
|
|
83
99
|
const { data: allResults } = await client.getChunks(result.data);
|
|
84
100
|
console.log('Total results:', allResults.length);
|
|
@@ -90,8 +106,8 @@ if (result.metadata.chunksDetected) {
|
|
|
90
106
|
For extremely large datasets, you might want to fetch chunks one by one:
|
|
91
107
|
|
|
92
108
|
```javascript
|
|
93
|
-
if (result.metadata.
|
|
94
|
-
const totalChunks = result.
|
|
109
|
+
if (result.metadata.chunkCount > 0) {
|
|
110
|
+
const totalChunks = result.metadata.chunkCount;
|
|
95
111
|
|
|
96
112
|
for (let i = 0; i < totalChunks; i++) {
|
|
97
113
|
const { data: chunk } = await client.getChunk(result.data, i);
|
|
@@ -100,6 +116,8 @@ if (result.metadata.chunksDetected) {
|
|
|
100
116
|
}
|
|
101
117
|
```
|
|
102
118
|
|
|
119
|
+
> **Note:** iRacing's API incorrectly returns `application/octet-stream` as the `Content-Type` for JSON chunks. This library automatically detects and parses these as JSON.
|
|
120
|
+
|
|
103
121
|
## Development
|
|
104
122
|
|
|
105
123
|
### Build
|
|
@@ -110,19 +128,27 @@ npm run build
|
|
|
110
128
|
|
|
111
129
|
### Manual Verification (OAuth Flow)
|
|
112
130
|
|
|
113
|
-
This repository includes a local development proxy server to test the OAuth flow and API interaction, avoiding CORS issues during development.
|
|
131
|
+
This repository includes a local development proxy server and a demo application to test the OAuth flow and API interaction, avoiding CORS issues during development.
|
|
114
132
|
|
|
115
|
-
1. Create a file named `
|
|
133
|
+
1. Create a file named `config.json` in the `demo/` directory (ignored by git) with your configuration:
|
|
116
134
|
|
|
117
135
|
```json
|
|
118
136
|
{
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
137
|
+
"port": 80,
|
|
138
|
+
"basePath": "/irdata_js",
|
|
139
|
+
"redirectPath": "/irdata_js/callback",
|
|
140
|
+
"auth": {
|
|
141
|
+
"clientId": "YOUR_CLIENT_ID",
|
|
142
|
+
"redirectUri": "http://127.0.0.1/irdata_js/callback",
|
|
143
|
+
"tokenEndpoint": "http://127.0.0.1/irdata_js/token"
|
|
144
|
+
}
|
|
122
145
|
}
|
|
123
146
|
```
|
|
124
147
|
|
|
125
|
-
|
|
148
|
+
* `port`: The port the proxy server will listen on.
|
|
149
|
+
* `basePath`: The path prefix where the static files and proxy endpoints are served from.
|
|
150
|
+
* `redirectPath`: The path the proxy server intercepts for OAuth callbacks.
|
|
151
|
+
* `auth`: Your iRacing API credentials. Note that `tokenEndpoint` should include the `basePath`.
|
|
126
152
|
|
|
127
153
|
2. Start the proxy server:
|
|
128
154
|
|
|
@@ -130,10 +156,12 @@ This repository includes a local development proxy server to test the OAuth flow
|
|
|
130
156
|
npm run dev
|
|
131
157
|
```
|
|
132
158
|
|
|
133
|
-
|
|
159
|
+
*This command automatically generates the `demo/index.html` from the template using your configuration and starts the proxy server.*
|
|
160
|
+
*Depending on your system configuration, you might need elevated privileges (e.g., `sudo`) to listen on port 80.*
|
|
161
|
+
|
|
162
|
+
3. Open `http://127.0.0.1/irdata_js/` (or your configured `basePath`) in your browser.
|
|
163
|
+
* The demo app is configured to use the local proxy endpoints (e.g., `/irdata_js/token`, `/irdata_js/data`, `/irdata_js/passthrough`) to bypass CORS restrictions.
|
|
134
164
|
|
|
135
|
-
3. Open `http://127.0.0.1/examples/index.html` in your browser.
|
|
136
|
-
- The `index.html` is configured to use the local proxy endpoints (`/token`, `/data`, `/passthrough`) to bypass CORS restrictions enforced by the browser.
|
|
137
165
|
|
|
138
166
|
## License
|
|
139
167
|
|