11// @ts -nocheck
2- ' use strict' ;
2+ " use strict" ;
33
4- const { version } = require ( ' ../package.json' ) ;
4+ const { version } = require ( " ../package.json" ) ;
55
66const PLAN_MAP = {
7- free : ' Free' ,
8- individual : ' Pro' ,
9- individual_pro : ' Pro+' ,
10- business : ' Business' ,
11- enterprise : ' Enterprise' ,
7+ free : " Free" ,
8+ individual : " Pro" ,
9+ individual_pro : " Pro+" ,
10+ business : " Business" ,
11+ enterprise : " Enterprise" ,
1212} ;
1313
1414/**
@@ -34,43 +34,46 @@ async function fetchUsage(token) {
3434 const timeout = setTimeout ( ( ) => controller . abort ( ) , 15_000 ) ;
3535 let res ;
3636 try {
37- res = await fetch ( ' https://api.github.com/copilot_internal/user' , {
37+ res = await fetch ( " https://api.github.com/copilot_internal/user" , {
3838 signal : controller . signal ,
3939 headers : {
4040 Authorization : `Bearer ${ token } ` ,
41- Accept : ' application/json' ,
42- ' User-Agent' : `vscode-github-copilot-usage/${ version } ` ,
41+ Accept : " application/json" ,
42+ " User-Agent" : `vscode-github-copilot-usage/${ version } ` ,
4343 } ,
4444 } ) ;
4545 } catch ( e ) {
4646 clearTimeout ( timeout ) ;
47- const isTimeout = e ?. name === 'AbortError' ;
48- throw makeError ( isTimeout ? 'TIMEOUT' : 'NETWORK_ERROR' , isTimeout ? 'Request timed out' : 'Network error' ) ;
47+ const isTimeout = e ?. name === "AbortError" ;
48+ throw makeError (
49+ isTimeout ? "TIMEOUT" : "NETWORK_ERROR" ,
50+ isTimeout ? "Request timed out" : "Network error" ,
51+ ) ;
4952 }
5053 clearTimeout ( timeout ) ;
5154
5255 if ( res . status === 401 ) {
53- throw makeError ( ' AUTH' , ' Not signed in (401)' ) ;
56+ throw makeError ( " AUTH" , " Not signed in (401)" ) ;
5457 }
5558 if ( res . status === 403 ) {
56- throw makeError ( ' FORBIDDEN' , `Forbidden (403)` ) ;
59+ throw makeError ( " FORBIDDEN" , `Forbidden (403)` ) ;
5760 }
5861
5962 if ( res . status === 429 ) {
60- throw makeError ( ' RATE_LIMIT' , ' Rate limited' ) ;
63+ throw makeError ( " RATE_LIMIT" , " Rate limited" ) ;
6164 }
6265
6366 if ( ! res . ok ) {
64- throw makeError ( res . status >= 500 ? ' SERVER_ERROR' : ' API_ERROR' , `API error: ${ res . status } ` ) ;
67+ throw makeError ( res . status >= 500 ? " SERVER_ERROR" : " API_ERROR" , `API error: ${ res . status } ` ) ;
6568 }
6669
6770 let data ;
6871 try {
6972 data = await res . json ( ) ;
7073 } catch {
71- throw makeError ( ' API_ERROR' , ' Invalid JSON from GitHub API' ) ;
74+ throw makeError ( " API_ERROR" , " Invalid JSON from GitHub API" ) ;
7275 }
73- const plan = PLAN_MAP [ data . copilot_plan ] ?? data . copilot_plan ?? ' Unknown' ;
76+ const plan = PLAN_MAP [ data . copilot_plan ] ?? data . copilot_plan ?? " Unknown" ;
7477
7578 const pi = data ?. quota_snapshots ?. premium_interactions ;
7679 if ( ! pi || pi . percent_remaining == null ) {
@@ -91,13 +94,15 @@ async function fetchUsage(token) {
9194 const entitlement = pi . entitlement ?? 0 ;
9295 const percentRemaining = Number ( pi . percent_remaining ) ;
9396 if ( ! Number . isFinite ( percentRemaining ) ) {
94- throw makeError ( ' API_ERROR' , ' Invalid percent_remaining from GitHub API' ) ;
97+ throw makeError ( " API_ERROR" , " Invalid percent_remaining from GitHub API" ) ;
9598 }
9699 const usedPct = Math . max ( 0 , Math . round ( ( 100 - percentRemaining ) * 10 ) / 10 ) ;
97- const used = entitlement > 0 ? Math . max ( 0 , Math . round ( ( entitlement * ( 100 - percentRemaining ) ) / 100 ) ) : 0 ;
100+ const used =
101+ entitlement > 0 ? Math . max ( 0 , Math . round ( ( entitlement * ( 100 - percentRemaining ) ) / 100 ) ) : 0 ;
98102
99103 const rawResetDate = data . quota_reset_date ? new Date ( data . quota_reset_date ) : null ;
100- const resetDate = rawResetDate && ! isNaN ( rawResetDate . getTime ( ) ) ? rawResetDate : getNextMonthReset ( ) ;
104+ const resetDate =
105+ rawResetDate && ! isNaN ( rawResetDate . getTime ( ) ) ? rawResetDate : getNextMonthReset ( ) ;
101106
102107 return {
103108 used,
0 commit comments