@@ -136,16 +136,24 @@ export function collectExternalUsageLinks(presentations: LimitPresentations) {
136136 return [ ...links . values ( ) ] ;
137137}
138138
139- function accountKey ( driver : ServerProvider [ "driver" ] , email : string | undefined ) : string | null {
139+ /** Prefer the reported email; use an identical credential when no email is available. */
140+ function accountKey (
141+ driver : ServerProvider [ "driver" ] ,
142+ email : string | undefined ,
143+ limits ?: ServerProviderUsageLimits ,
144+ ) : string | null {
140145 const normalizedEmail = email ?. trim ( ) . toLowerCase ( ) ;
141- return normalizedEmail ? `${ driver } :${ normalizedEmail } ` : null ;
146+ if ( normalizedEmail ) return `${ driver } :${ normalizedEmail } ` ;
147+ return limits ?. credentialFingerprint
148+ ? `${ driver } :credential:${ limits . credentialFingerprint } `
149+ : null ;
142150}
143151
144152/**
145153 * One subscription account as the pooled views see it, whichever way it was
146- * reported. The same email signed in natively on two environments, or reported
147- * by a hub as well as natively, is one account: its quota is one bucket, so
148- * counting it twice would misstate what is left.
154+ * reported. Matching emails or credentials across environments name
155+ * one account. Its quota is one bucket, so counting it twice would misstate
156+ * what is left.
149157 */
150158export interface LimitAccount {
151159 readonly key : string ;
@@ -243,7 +251,7 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
243251 for ( const provider of providersWithLimits ( presentation . serverConfig ?. providers ?? [ ] ) ) {
244252 if ( ! provider . usageLimits || limitsNotice ( provider . usageLimits ) !== null ) continue ;
245253 merge (
246- accountKey ( provider . driver , provider . auth . email ) ??
254+ accountKey ( provider . driver , provider . auth . email , provider . usageLimits ) ??
247255 `${ environmentId } :${ provider . instanceId } ` ,
248256 {
249257 key : `${ environmentId } :${ provider . instanceId } ` ,
@@ -271,27 +279,31 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
271279 : source . label ;
272280 for ( const account of source . accounts ) {
273281 if ( limitsNotice ( account . usageLimits ) !== null ) continue ;
274- merge ( accountKey ( account . driver , account . email ) ?? `${ source . id } :${ account . id } ` , {
275- key : `${ source . id } :${ account . id } ` ,
276- driver : account . driver ,
277- displayName : account . email ? null : account . id . replace ( / \. j s o n $ / i, "" ) ,
278- email : account . email ,
279- plan : account . plan ,
280- accentColor : undefined ,
281- environments : [ ] ,
282- sourceLabel,
283- redeem : account . usageLimits . resetCredits ?. nextCreditId
284- ? {
285- environmentId,
286- input : {
287- sourceId : source . id ,
288- accountId : account . id ,
289- creditId : account . usageLimits . resetCredits . nextCreditId ,
290- } ,
291- }
292- : null ,
293- limits : account . usageLimits ,
294- } ) ;
282+ merge (
283+ accountKey ( account . driver , account . email , account . usageLimits ) ??
284+ `${ source . id } :${ account . id } ` ,
285+ {
286+ key : `${ source . id } :${ account . id } ` ,
287+ driver : account . driver ,
288+ displayName : account . email ? null : account . id . replace ( / \. j s o n $ / i, "" ) ,
289+ email : account . email ,
290+ plan : account . plan ,
291+ accentColor : undefined ,
292+ environments : [ ] ,
293+ sourceLabel,
294+ redeem : account . usageLimits . resetCredits ?. nextCreditId
295+ ? {
296+ environmentId,
297+ input : {
298+ sourceId : source . id ,
299+ accountId : account . id ,
300+ creditId : account . usageLimits . resetCredits . nextCreditId ,
301+ } ,
302+ }
303+ : null ,
304+ limits : account . usageLimits ,
305+ } ,
306+ ) ;
295307 }
296308 }
297309 }
@@ -647,7 +659,7 @@ export function collectProviderUsageLimits(
647659 ) ;
648660 const nativeAccounts = new Set (
649661 native . flatMap ( ( provider ) => {
650- const key = accountKey ( provider . driver , provider . auth . email ) ;
662+ const key = accountKey ( provider . driver , provider . auth . email , provider . usageLimits ) ;
651663 return key && provider . usageLimits ?. windows . length && ! provider . usageLimits . unavailable
652664 ? [ key ]
653665 : [ ] ;
@@ -657,13 +669,13 @@ export function collectProviderUsageLimits(
657669 const notices : string [ ] = [ ] ;
658670 for ( const provider of native ) {
659671 if ( ! provider . usageLimits ) continue ;
660- const key = accountKey ( provider . driver , provider . auth . email ) ;
672+ const key = accountKey ( provider . driver , provider . auth . email , provider . usageLimits ) ;
661673 const hubCredits = sources
662674 . flatMap ( ( source ) => source . accounts . map ( ( account ) => ( { source, account } ) ) )
663675 . filter (
664676 ( { account } ) =>
665677 key !== null &&
666- accountKey ( account . driver , account . email ) === key &&
678+ accountKey ( account . driver , account . email , account . usageLimits ) === key &&
667679 account . usageLimits . resetCredits &&
668680 ! limitsNotice ( account . usageLimits ) ,
669681 )
@@ -710,7 +722,7 @@ export function collectProviderUsageLimits(
710722 for ( const source of sources ) {
711723 const matching = source . accounts . filter ( ( account ) => account . driver === selected . driver ) ;
712724 for ( const account of matching ) {
713- const key = accountKey ( account . driver , account . email ) ;
725+ const key = accountKey ( account . driver , account . email , account . usageLimits ) ;
714726 if ( key && nativeAccounts . has ( key ) ) continue ;
715727 accounts . push ( {
716728 id : `${ source . id } :${ account . id } ` ,
0 commit comments