@@ -79,16 +79,23 @@ export type LimitPresentations = ReadonlyMap<
7979 }
8080> ;
8181
82- function accountKey ( driver : ServerProvider [ "driver" ] , email : string | undefined ) : string | null {
82+ function accountKey (
83+ driver : ServerProvider [ "driver" ] ,
84+ email : string | undefined ,
85+ limits ?: ServerProviderUsageLimits ,
86+ ) : string | null {
8387 const normalizedEmail = email ?. trim ( ) . toLowerCase ( ) ;
84- return normalizedEmail ? `${ driver } :${ normalizedEmail } ` : null ;
88+ if ( normalizedEmail ) return `${ driver } :${ normalizedEmail } ` ;
89+ return limits ?. credentialFingerprint
90+ ? `${ driver } :credential:${ limits . credentialFingerprint } `
91+ : null ;
8592}
8693
8794/**
8895 * One subscription account as the pooled views see it, whichever way it was
89- * reported. The same email signed in natively on two environments, or reported
90- * by a hub as well as natively, is one account: its quota is one bucket, so
91- * counting it twice would misstate what is left.
96+ * reported. Matching emails or credentials across environments name
97+ * one account. Its quota is one bucket, so counting it twice would misstate
98+ * what is left.
9299 */
93100export interface LimitAccount {
94101 readonly key : string ;
@@ -186,7 +193,7 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
186193 for ( const provider of providersWithLimits ( presentation . serverConfig ?. providers ?? [ ] ) ) {
187194 if ( ! provider . usageLimits || limitsNotice ( provider . usageLimits ) !== null ) continue ;
188195 merge (
189- accountKey ( provider . driver , provider . auth . email ) ??
196+ accountKey ( provider . driver , provider . auth . email , provider . usageLimits ) ??
190197 `${ environmentId } :${ provider . instanceId } ` ,
191198 {
192199 key : `${ environmentId } :${ provider . instanceId } ` ,
@@ -214,27 +221,31 @@ export function collectLimitAccounts(presentations: LimitPresentations): readonl
214221 : source . label ;
215222 for ( const account of source . accounts ) {
216223 if ( limitsNotice ( account . usageLimits ) !== null ) continue ;
217- merge ( accountKey ( account . driver , account . email ) ?? `${ source . id } :${ account . id } ` , {
218- key : `${ source . id } :${ account . id } ` ,
219- driver : account . driver ,
220- displayName : account . email ? null : account . id . replace ( / \. j s o n $ / i, "" ) ,
221- email : account . email ,
222- plan : account . plan ,
223- accentColor : undefined ,
224- environments : [ ] ,
225- sourceLabel,
226- redeem : account . usageLimits . resetCredits ?. nextCreditId
227- ? {
228- environmentId,
229- input : {
230- sourceId : source . id ,
231- accountId : account . id ,
232- creditId : account . usageLimits . resetCredits . nextCreditId ,
233- } ,
234- }
235- : null ,
236- limits : account . usageLimits ,
237- } ) ;
224+ merge (
225+ accountKey ( account . driver , account . email , account . usageLimits ) ??
226+ `${ source . id } :${ account . id } ` ,
227+ {
228+ key : `${ source . id } :${ account . id } ` ,
229+ driver : account . driver ,
230+ displayName : account . email ? null : account . id . replace ( / \. j s o n $ / i, "" ) ,
231+ email : account . email ,
232+ plan : account . plan ,
233+ accentColor : undefined ,
234+ environments : [ ] ,
235+ sourceLabel,
236+ redeem : account . usageLimits . resetCredits ?. nextCreditId
237+ ? {
238+ environmentId,
239+ input : {
240+ sourceId : source . id ,
241+ accountId : account . id ,
242+ creditId : account . usageLimits . resetCredits . nextCreditId ,
243+ } ,
244+ }
245+ : null ,
246+ limits : account . usageLimits ,
247+ } ,
248+ ) ;
238249 }
239250 }
240251 }
@@ -590,7 +601,7 @@ export function collectProviderUsageLimits(
590601 ) ;
591602 const nativeAccounts = new Set (
592603 native . flatMap ( ( provider ) => {
593- const key = accountKey ( provider . driver , provider . auth . email ) ;
604+ const key = accountKey ( provider . driver , provider . auth . email , provider . usageLimits ) ;
594605 return key && provider . usageLimits ?. windows . length && ! provider . usageLimits . unavailable
595606 ? [ key ]
596607 : [ ] ;
@@ -600,13 +611,13 @@ export function collectProviderUsageLimits(
600611 const notices : string [ ] = [ ] ;
601612 for ( const provider of native ) {
602613 if ( ! provider . usageLimits ) continue ;
603- const key = accountKey ( provider . driver , provider . auth . email ) ;
614+ const key = accountKey ( provider . driver , provider . auth . email , provider . usageLimits ) ;
604615 const hubCredits = sources
605616 . flatMap ( ( source ) => source . accounts . map ( ( account ) => ( { source, account } ) ) )
606617 . filter (
607618 ( { account } ) =>
608619 key !== null &&
609- accountKey ( account . driver , account . email ) === key &&
620+ accountKey ( account . driver , account . email , account . usageLimits ) === key &&
610621 account . usageLimits . resetCredits &&
611622 ! limitsNotice ( account . usageLimits ) ,
612623 )
@@ -653,7 +664,7 @@ export function collectProviderUsageLimits(
653664 for ( const source of sources ) {
654665 const matching = source . accounts . filter ( ( account ) => account . driver === selected . driver ) ;
655666 for ( const account of matching ) {
656- const key = accountKey ( account . driver , account . email ) ;
667+ const key = accountKey ( account . driver , account . email , account . usageLimits ) ;
657668 if ( key && nativeAccounts . has ( key ) ) continue ;
658669 accounts . push ( {
659670 id : `${ source . id } :${ account . id } ` ,
0 commit comments