1
1
import { print , prompt } from 'gluegun' ;
2
- import { Args , Command , Flags , ux } from '@oclif/core' ;
2
+ import { Args , Command , Flags } from '@oclif/core' ;
3
3
import { saveDeployKey } from '../command-helpers/auth.js' ;
4
4
import { chooseNodeUrl } from '../command-helpers/node.js' ;
5
5
@@ -16,6 +16,11 @@ export default class AuthCommand extends Command {
16
16
} ) ,
17
17
} ;
18
18
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
+
19
24
async run ( ) {
20
25
const {
21
26
args : { 'deploy-key' : initialDeployKey } ,
@@ -25,23 +30,22 @@ export default class AuthCommand extends Command {
25
30
26
31
const { deployKey } = await prompt . ask < { deployKey : string } > ( [
27
32
{
28
- type : 'invisible ' ,
33
+ type : 'input ' ,
29
34
name : 'deployKey' ,
30
- message : ( ) => 'What is the deploy key?' ,
31
- initial : initialDeployKey ,
35
+ message : ( ) => 'What is your Subgraph Studio deploy key?' ,
32
36
required : true ,
37
+ initial : initialDeployKey ,
38
+ skip : this . validateStudioDeployKey ( initialDeployKey ) ,
33
39
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 } ` ,
37
41
} ,
38
42
] ) ;
39
43
40
44
try {
41
45
await saveDeployKey ( node ! , deployKey ) ;
42
46
print . success ( `Deploy key set for ${ node } ` ) ;
43
47
} catch ( e ) {
44
- this . error ( e , { exit : 1 } ) ;
48
+ this . error ( `Failed to set deploy key: ${ e . message } ` , { exit : 1 } ) ;
45
49
}
46
50
}
47
51
}
0 commit comments