@@ -26,6 +26,8 @@ import { Constants } from '../../../utils/constants/stringContants';
2626import { OrgPreferences } from '../../../utils/orgPreferences' ;
2727import { AnonymousApexRunner } from '../../../utils/apex/executor/AnonymousApexRunner' ;
2828import { ProjectPathUtil } from '../../../utils/projectPathUtil' ;
29+ import { PromptUtil } from '../../../utils/promptUtil' ;
30+ import { YES_SHORT , YES_LONG , NO_SHORT , NO_LONG } from '../../../utils/projectPathUtil' ;
2931
3032// Initialize Messages with the current plugin directory
3133Messages . importMessagesDirectory ( __dirname ) ;
@@ -204,31 +206,27 @@ export default class Migrate extends OmniStudioBaseCommand {
204206 }
205207
206208 private async getMigrationConsent ( ) : Promise < boolean > {
207- const TIMEOUT_MS = 5 * 60 * 1000 ; // 5 minutes timeout
209+ const askWithTimeOut = PromptUtil . askWithTimeOut ( messages ) ;
210+ let validResponse = false ;
211+ let consent = false ;
208212
209- let consent : boolean | null = null ;
210- let timeoutHandle : NodeJS . Timeout ;
211-
212- const timeoutPromise = new Promise < boolean > ( ( _ , reject ) => {
213- timeoutHandle = setTimeout ( ( ) => {
214- reject ( new Error ( messages . getMessage ( 'requestTimedOut' ) ) ) ;
215- } , TIMEOUT_MS ) ;
216- } ) ;
217-
218- while ( consent === null ) {
213+ while ( ! validResponse ) {
219214 try {
220- // Race between the confirmation prompt and the timeout
221- consent = await Promise . race ( [ Logger . confirm ( messages . getMessage ( 'migrationConsentMessage' ) ) , timeoutPromise ] ) ;
222- clearTimeout ( timeoutHandle ) ;
223- } catch ( error ) {
224- clearTimeout ( timeoutHandle ) ;
225- if ( error instanceof Error && error . message === messages . getMessage ( 'requestTimedOut' ) ) {
226- Logger . log ( messages . getMessage ( 'requestTimedOut' ) ) ;
227- return false ; // Return false on timeout
215+ const resp = await askWithTimeOut ( Logger . prompt . bind ( Logger ) , messages . getMessage ( 'migrationConsentMessage' ) ) ;
216+ const response = typeof resp === 'string' ? resp . trim ( ) . toLowerCase ( ) : '' ;
217+
218+ if ( response === YES_SHORT || response === YES_LONG ) {
219+ consent = true ;
220+ validResponse = true ;
221+ } else if ( response === NO_SHORT || response === NO_LONG ) {
222+ consent = false ;
223+ validResponse = true ;
228224 } else {
229- Logger . log ( messages . getMessage ( 'invalidYesNoResponse' ) ) ;
230- consent = null ;
225+ Logger . error ( messages . getMessage ( 'invalidYesNoResponse' ) ) ;
231226 }
227+ } catch ( err ) {
228+ Logger . error ( messages . getMessage ( 'requestTimedOut' ) ) ;
229+ process . exit ( 1 ) ;
232230 }
233231 }
234232
@@ -415,7 +413,7 @@ export default class Migrate extends OmniStudioBaseCommand {
415413 let errors : any [ ] = obj . errors || [ ] ;
416414 errors = errors . concat ( recordResults . errors || [ ] ) ;
417415
418- obj . status = recordResults . skipped
416+ obj . status = recordResults ? .skipped
419417 ? messages . getMessage ( 'labelStatusSkipped' )
420418 : ! recordResults || recordResults . hasErrors
421419 ? messages . getMessage ( 'labelStatusFailed' )
0 commit comments