@@ -10,6 +10,10 @@ import { OAuthError } from "./errors";
1010import { createCallbackServer , type CallbackResult } from "./server" ;
1111import type { GetAuthCodeOptions } from "./types" ;
1212
13+ const DEFAULT_PORT = 3000 ;
14+ const DEFAULT_HOSTNAME = "localhost" ;
15+ const DEFAULT_CALLBACK_PATH = "/callback" ;
16+
1317export type { CallbackResult , CallbackServer , ServerOptions } from "./server" ;
1418export { OAuthError , TimeoutError } from "./errors" ;
1519export type { GetAuthCodeOptions } from "./types" ;
@@ -44,9 +48,9 @@ export function getRedirectUrl(
4448 } = { } ,
4549) : string {
4650 const {
47- port = 3000 ,
48- hostname = "localhost" ,
49- callbackPath = "/callback" ,
51+ port = DEFAULT_PORT ,
52+ hostname = DEFAULT_HOSTNAME ,
53+ callbackPath = DEFAULT_CALLBACK_PATH ,
5054 } = options ;
5155 return `http://${ hostname } :${ port } ${ callbackPath } ` ;
5256}
@@ -94,10 +98,10 @@ export async function getAuthCode(
9498 typeof input === "string" ? await authorizationUrlToOptions ( input ) : input ;
9599
96100 const {
97- port = 3000 ,
98- hostname = "localhost" ,
101+ port = DEFAULT_PORT ,
102+ hostname = DEFAULT_HOSTNAME ,
99103 timeout = 30000 ,
100- callbackPath = "/callback" ,
104+ callbackPath = DEFAULT_CALLBACK_PATH ,
101105 successHtml,
102106 errorHtml,
103107 signal,
@@ -119,10 +123,13 @@ export async function getAuthCode(
119123 // Best-effort launch: fire-and-forget, swallow errors (managed mode only)
120124 if (
121125 "authorizationUrl" in options &&
122- typeof ( options as any ) . launch === "function"
126+ options . authorizationUrl &&
127+ "launch" in options &&
128+ typeof options . launch === "function"
123129 ) {
124- const { authorizationUrl, launch } = options as any ;
125- void Promise . resolve ( launch ( authorizationUrl ) ) . catch ( ( ) => { } ) ;
130+ void Promise . resolve ( options . launch ( options . authorizationUrl ) ) . catch (
131+ ( ) => { } ,
132+ ) ;
126133 }
127134
128135 const result = await server . waitForCallback ( callbackPath , timeout ) ;
0 commit comments