11import { print , prompt } from 'gluegun' ;
2- import { Args , Command , Flags , ux } from '@oclif/core' ;
2+ import { Args , Command , Flags } from '@oclif/core' ;
33import { saveDeployKey } from '../command-helpers/auth.js' ;
44import { chooseNodeUrl } from '../command-helpers/node.js' ;
55
@@ -16,6 +16,11 @@ export default class AuthCommand extends Command {
1616 } ) ,
1717 } ;
1818
19+ private validateStudioDeployKey ( value : string | undefined ) : boolean {
20+ if ( ! value ) return false ;
21+ return / ^ [ 0 - 9 a - f A - F ] { 32 } $ / . test ( value ) ;
22+ }
23+
1924 async run ( ) {
2025 const {
2126 args : { 'deploy-key' : initialDeployKey } ,
@@ -25,23 +30,22 @@ export default class AuthCommand extends Command {
2530
2631 const { deployKey } = await prompt . ask < { deployKey : string } > ( [
2732 {
28- type : 'invisible ' ,
33+ type : 'input ' ,
2934 name : 'deployKey' ,
30- message : ( ) => 'What is the deploy key?' ,
31- initial : initialDeployKey ,
35+ message : ( ) => 'What is your Subgraph Studio deploy key?' ,
3236 required : true ,
37+ initial : initialDeployKey ,
38+ skip : this . validateStudioDeployKey ( initialDeployKey ) ,
3339 validate : value =>
34- value . length > 200
35- ? ux . error ( '✖ Deploy key must not exceed 200 characters' , { exit : 1 } )
36- : value ,
40+ this . validateStudioDeployKey ( value ) || `Invalid Subgraph Studio deploy key: ${ value } ` ,
3741 } ,
3842 ] ) ;
3943
4044 try {
4145 await saveDeployKey ( node ! , deployKey ) ;
4246 print . success ( `Deploy key set for ${ node } ` ) ;
4347 } catch ( e ) {
44- this . error ( e , { exit : 1 } ) ;
48+ this . error ( `Failed to set deploy key: ${ e . message } ` , { exit : 1 } ) ;
4549 }
4650 }
4751}
0 commit comments