1+ import { STORE_AUTH_CALLBACK_PATH , maskToken } from './config.js'
2+ import { retryStoreAuthWithPermanentDomainError } from './recovery.js'
13import { normalizeStoreFqdn } from '@shopify/cli-kit/node/context/fqdn'
24import { AbortError } from '@shopify/cli-kit/node/error'
35import { outputContent , outputDebug , outputToken } from '@shopify/cli-kit/node/output'
46import { timingSafeEqual } from 'crypto'
57import { createServer } from 'http'
6- import { STORE_AUTH_CALLBACK_PATH , maskToken } from './config.js'
7- import { retryStoreAuthWithPermanentDomainError } from './recovery.js'
88
99export interface WaitForAuthCodeOptions {
1010 store : string
@@ -15,16 +15,8 @@ export interface WaitForAuthCodeOptions {
1515}
1616
1717function renderAuthCallbackPage ( title : string , message : string ) : string {
18- const safeTitle = title
19- . replace ( / & / g, '&' )
20- . replace ( / < / g, '<' )
21- . replace ( / > / g, '>' )
22- . replace ( / " / g, '"' )
23- const safeMessage = message
24- . replace ( / & / g, '&' )
25- . replace ( / < / g, '<' )
26- . replace ( / > / g, '>' )
27- . replace ( / " / g, '"' )
18+ const safeTitle = title . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) . replace ( / " / g, '"' )
19+ const safeMessage = message . replace ( / & / g, '&' ) . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) . replace ( / " / g, '"' )
2820
2921 return `<!doctype html>
3022<html lang="en">
@@ -120,7 +112,9 @@ export async function waitForStoreAuthCode({
120112 res . setHeader ( 'Content-Type' , 'text/html' )
121113 res . setHeader ( 'Connection' , 'close' )
122114 res . once ( 'finish' , ( ) => settle ( ( ) => resolve ( code ) ) )
123- res . end ( renderAuthCallbackPage ( 'Authentication succeeded' , 'You can close this window and return to the terminal.' ) )
115+ res . end (
116+ renderAuthCallbackPage ( 'Authentication succeeded' , 'You can close this window and return to the terminal.' ) ,
117+ )
124118 } )
125119
126120 const settle = ( callback : ( ) => void ) => {
@@ -162,24 +156,22 @@ export async function waitForStoreAuthCode({
162156 settleWithError ( error )
163157 } )
164158
165- server . listen ( port , '127.0.0.1' , async ( ) => {
159+ server . listen ( port , '127.0.0.1' , ( ) => {
166160 isListening = true
167161 outputDebug (
168162 outputContent `PKCE callback server listening on http://127.0.0.1:${ outputToken . raw ( String ( port ) ) } ${ outputToken . raw ( STORE_AUTH_CALLBACK_PATH ) } ` ,
169163 )
170164
171165 if ( ! onListening ) return
172166
173- try {
174- await onListening ( )
175- } catch ( error ) {
167+ Promise . resolve ( onListening ( ) ) . catch ( ( error : unknown ) => {
176168 settleWithError ( error instanceof Error ? error : new Error ( String ( error ) ) )
177- }
169+ } )
178170 } )
179171 } )
180172}
181173
182- function constantTimeEqual ( a : string , b : string ) : boolean {
183- if ( a . length !== b . length ) return false
184- return timingSafeEqual ( Buffer . from ( a , 'utf8' ) , Buffer . from ( b , 'utf8' ) )
174+ function constantTimeEqual ( left : string , right : string ) : boolean {
175+ if ( left . length !== right . length ) return false
176+ return timingSafeEqual ( Buffer . from ( left , 'utf8' ) , Buffer . from ( right , 'utf8' ) )
185177}
0 commit comments