99 deviceCodeRequestBody ,
1010 deviceTokenRequestBody ,
1111} from "@sentry/toolkit-core/oauth-device" ;
12- import { nextDevicePollInterval } from "@sentry/toolkit-core/oauth-poll" ;
12+ import { advanceDevicePoll } from "@sentry/toolkit-core/oauth-poll" ;
1313import { safeParse } from "valibot" ;
1414import type { TokenResponse } from "../types/index.js" ;
1515import {
@@ -373,14 +373,16 @@ function pollForToken(deviceCode: string): Promise<TokenResponse> {
373373
374374type PollResult =
375375 | { status : "success" ; token : TokenResponse }
376- | { status : "authorization_pending" }
377- | { status : "slow_down" }
376+ | { status : "retry" ; intervalSeconds : number }
378377 | { status : "error" ; message : string } ;
379378
380379/**
381380 * Handle a single poll attempt, returning a result object
382381 */
383- async function attemptPoll ( deviceCode : string ) : Promise < PollResult > {
382+ async function attemptPoll (
383+ deviceCode : string ,
384+ intervalSeconds : number ,
385+ ) : Promise < PollResult > {
384386 try {
385387 const token = await pollForToken ( deviceCode ) ;
386388 return { status : "success" , token } ;
@@ -389,22 +391,21 @@ async function attemptPoll(deviceCode: string): Promise<PollResult> {
389391 throw error ;
390392 }
391393
392- switch ( error . code ) {
393- case "authorization_pending" :
394- return { status : "authorization_pending" } ;
395- case "slow_down" :
396- return { status : "slow_down" } ;
397- case "expired_token" :
394+ const outcome = advanceDevicePoll ( intervalSeconds , error . code ) ;
395+ switch ( outcome . status ) {
396+ case "retry" :
397+ return outcome ;
398+ case "expired" :
398399 return {
399400 status : "error" ,
400401 message : "Device code expired. Please run 'sentry auth login' again." ,
401402 } ;
402- case "access_denied " :
403+ case "denied " :
403404 return {
404405 status : "error" ,
405406 message : "Authorization was denied. Please try again." ,
406407 } ;
407- default :
408+ case "unexpected" :
408409 return { status : "error" , message : error . message } ;
409410 }
410411 }
@@ -456,14 +457,13 @@ export async function performDeviceFlow(
456457 while ( Date . now ( ) < timeoutAt ) {
457458 await sleep ( pollInterval * 1000 ) ;
458459
459- const result = await attemptPoll ( device_code ) ;
460+ const result = await attemptPoll ( device_code , pollInterval ) ;
460461
461462 switch ( result . status ) {
462463 case "success" :
463464 return result . token ;
464- case "authorization_pending" :
465- case "slow_down" :
466- pollInterval = nextDevicePollInterval ( pollInterval , result . status ) ;
465+ case "retry" :
466+ pollInterval = result . intervalSeconds ;
467467 continue ;
468468 case "error" :
469469 throw new DeviceFlowError ( "authorization_failed" , result . message ) ;
0 commit comments