@@ -112,9 +112,9 @@ class GitHubAPIClient {
112112 private githubToken = ''
113113
114114 constructor ( ) {
115- // Try to get token from environment
116- if ( typeof process !== 'undefined' && process . env ?. GITHUB_TOKEN ) {
117- this . githubToken = process . env . GITHUB_TOKEN ;
115+ // Only read env token on the server to avoid exposing secrets client-side
116+ if ( typeof window === 'undefined' && typeof process !== 'undefined' && process . env ?. GITHUB_TOKEN ) {
117+ this . githubToken = process . env . GITHUB_TOKEN
118118 }
119119 }
120120
@@ -169,7 +169,9 @@ class GitHubAPIClient {
169169 return {
170170 hasToken : ! ! this . githubToken ,
171171 tokenPrefix : this . githubToken ? this . githubToken . substring ( 0 , 10 ) + '...' : 'NO_TOKEN' ,
172- source : this . githubToken === process . env . GITHUB_TOKEN ? 'ENV_VAR' : 'USER_SET'
172+ source : ( typeof window === 'undefined' && typeof process !== 'undefined' && process . env ?. GITHUB_TOKEN && this . githubToken === process . env . GITHUB_TOKEN )
173+ ? 'ENV_VAR'
174+ : ( this . githubToken ? 'USER_SET' : 'NONE' )
173175 }
174176 }
175177
@@ -238,8 +240,23 @@ class GitHubAPIClient {
238240
239241 const data = await response . json ( )
240242
241- // Check rate limit status
242- // Rate limit headers available but not currently used
243+ if ( typeof window !== 'undefined' ) {
244+ const updateRateLimit = ( window as typeof window & { updateRateLimit ?: ( headers : Headers ) => void } ) . updateRateLimit
245+ if ( updateRateLimit ) {
246+ const headers = new Headers ( )
247+ const remaining = response . headers . get ( 'x-ratelimit-remaining' ) || response . headers . get ( 'X-RateLimit-Remaining' )
248+ const limit = response . headers . get ( 'x-ratelimit-limit' ) || response . headers . get ( 'X-RateLimit-Limit' )
249+ const reset = response . headers . get ( 'x-ratelimit-reset' ) || response . headers . get ( 'X-RateLimit-Reset' )
250+ const used = response . headers . get ( 'x-ratelimit-used' ) || response . headers . get ( 'X-RateLimit-Used' )
251+ if ( remaining && limit && reset ) {
252+ headers . set ( 'x-ratelimit-remaining' , remaining )
253+ headers . set ( 'x-ratelimit-limit' , limit )
254+ headers . set ( 'x-ratelimit-reset' , reset )
255+ if ( used ) headers . set ( 'x-ratelimit-used' , used )
256+ updateRateLimit ( headers )
257+ }
258+ }
259+ }
243260
244261 this . cache . set ( cacheKey , { data, timestamp : Date . now ( ) } )
245262 return data
0 commit comments