@@ -183,6 +183,7 @@ import {
183183import { buildCapabilityBoostByAccount } from "./lib/runtime/capability-boost.js" ;
184184import { createRuntimeEventHandler } from "./lib/runtime/event-handler.js" ;
185185import { createFlaggedVerificationState } from "./lib/runtime/flagged-verify-types.js" ;
186+ import { hydrateRuntimeEmails } from "./lib/runtime/hydrate-emails.js" ;
186187import { ensureRuntimeLiveAccountSync } from "./lib/runtime/live-sync.js" ;
187188import { buildManualOAuthFlow } from "./lib/runtime/manual-oauth-flow.js" ;
188189import {
@@ -346,75 +347,17 @@ export const OpenAIOAuthPlugin: Plugin = async ({ client }: PluginInput) => {
346347
347348 const hydrateEmails = async (
348349 storage : AccountStorageV3 | null ,
349- ) : Promise < AccountStorageV3 | null > => {
350- if ( ! storage ) return storage ;
351- const skipHydrate =
352- process . env . VITEST_WORKER_ID !== undefined ||
353- process . env . NODE_ENV === "test" ||
354- process . env . CODEX_SKIP_EMAIL_HYDRATE === "1" ;
355- if ( skipHydrate ) return storage ;
356-
357- const accountsCopy = storage . accounts . map ( ( account ) =>
358- account ? { ...account } : account ,
359- ) ;
360- const accountsToHydrate = accountsCopy . filter (
361- ( account ) => account && ! account . email ,
362- ) ;
363- if ( accountsToHydrate . length === 0 ) return storage ;
364-
365- let changed = false ;
366- await Promise . all (
367- accountsToHydrate . map ( async ( account ) => {
368- try {
369- const refreshed = await queuedRefresh ( account . refreshToken ) ;
370- if ( refreshed . type !== "success" ) return ;
371- const id = extractAccountId ( refreshed . access ) ;
372- const email = sanitizeEmail (
373- extractAccountEmail ( refreshed . access , refreshed . idToken ) ,
374- ) ;
375- if (
376- id &&
377- id !== account . accountId &&
378- shouldUpdateAccountIdFromToken (
379- account . accountIdSource ,
380- account . accountId ,
381- )
382- ) {
383- account . accountId = id ;
384- account . accountIdSource = "token" ;
385- changed = true ;
386- }
387- if ( email && email !== account . email ) {
388- account . email = email ;
389- changed = true ;
390- }
391- if ( refreshed . access && refreshed . access !== account . accessToken ) {
392- account . accessToken = refreshed . access ;
393- changed = true ;
394- }
395- if (
396- typeof refreshed . expires === "number" &&
397- refreshed . expires !== account . expiresAt
398- ) {
399- account . expiresAt = refreshed . expires ;
400- changed = true ;
401- }
402- if ( refreshed . refresh && refreshed . refresh !== account . refreshToken ) {
403- account . refreshToken = refreshed . refresh ;
404- changed = true ;
405- }
406- } catch {
407- logWarn ( `[${ PLUGIN_NAME } ] Failed to hydrate email for account` ) ;
408- }
409- } ) ,
410- ) ;
411-
412- if ( changed ) {
413- storage . accounts = accountsCopy ;
414- await saveAccounts ( storage ) ;
415- }
416- return storage ;
417- } ;
350+ ) : Promise < AccountStorageV3 | null > =>
351+ hydrateRuntimeEmails ( storage , {
352+ queuedRefresh,
353+ extractAccountId,
354+ sanitizeEmail,
355+ extractAccountEmail,
356+ shouldUpdateAccountIdFromToken,
357+ saveAccounts,
358+ logWarn,
359+ pluginName : PLUGIN_NAME ,
360+ } ) ;
418361
419362 const applyUiRuntimeFromConfig = (
420363 pluginConfig : ReturnType < typeof loadPluginConfig > ,
0 commit comments