irdata_js 0.2.1 → 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 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.chunksDetected); // Boolean indicating if data is chunked
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.chunksDetected` is true, you can use the library to fetch the rest of the data.
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.chunksDetected) {
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.chunksDetected) {
94
- const totalChunks = result.data.chunk_info.chunk_file_names.length;
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