44 * Usage: moa login <service> [--profile=<name>]
55 */
66
7- import { Args , Command , Flags } from '@oclif/core' ;
87import { confirm , password } from '@inquirer/prompts' ;
9- import { getAuthManager , Credentials } from '../../lib/auth/auth-manager.js' ;
8+ import { Args , Command , Flags } from '@oclif/core' ;
9+
10+ import { Credentials , getAuthManager } from '../../lib/auth/auth-manager.js' ;
1011import { getConfigManager } from '../../lib/config/config-manager.js' ;
1112
1213const SUPPORTED_PROVIDERS = [ 'hubspot' , 'semrush' , 'meta' ] as const ;
@@ -20,27 +21,24 @@ export default class Login extends Command {
2021 required : true ,
2122 } ) ,
2223 } ;
23-
24- static override description = 'Authenticate with a SaaS provider' ;
25-
26- static override examples = [
24+ static override description = 'Authenticate with a SaaS provider' ;
25+ static override examples = [
2726 '<%= config.bin %> <%= command.id %> hubspot' ,
2827 '<%= config.bin %> <%= command.id %> hubspot --profile=client-a' ,
2928 '<%= config.bin %> <%= command.id %> semrush --profile=agency' ,
3029 ] ;
31-
32- static override flags = {
30+ static override flags = {
3331 profile : Flags . string ( {
3432 char : 'p' ,
35- description : 'Profile name to store credentials under' ,
3633 default : 'default' ,
34+ description : 'Profile name to store credentials under' ,
3735 } ) ,
3836 } ;
3937
4038 async run ( ) : Promise < void > {
4139 const { args, flags } = await this . parse ( Login ) ;
4240 const service = args . service as SupportedProvider ;
43- const profile = flags . profile ;
41+ const { profile} = flags ;
4442
4543 // Set active profile
4644 const configManager = getConfigManager ( ) ;
@@ -55,8 +53,8 @@ export default class Login extends Command {
5553
5654 if ( existing ) {
5755 const overwrite = await confirm ( {
58- message : 'Credentials already exist for this service/profile. Overwrite?' ,
5956 default : false ,
57+ message : 'Credentials already exist for this service/profile. Overwrite?' ,
6058 } ) ;
6159 if ( ! overwrite ) {
6260 this . log ( 'Login cancelled.' ) ;
@@ -79,14 +77,21 @@ export default class Login extends Command {
7977 service : SupportedProvider
8078 ) : Promise < Credentials > {
8179 switch ( service ) {
82- case 'hubspot' :
80+ case 'hubspot' : {
8381 return this . promptHubSpotCredentials ( ) ;
84- case 'semrush' :
85- return this . promptSemrushCredentials ( ) ;
86- case 'meta' :
82+ }
83+
84+ case 'meta' : {
8785 return this . promptMetaCredentials ( ) ;
88- default :
86+ }
87+
88+ case 'semrush' : {
89+ return this . promptSemrushCredentials ( ) ;
90+ }
91+
92+ default : {
8993 throw new Error ( `Unsupported provider: ${ service } ` ) ;
94+ }
9095 }
9196 }
9297
@@ -95,8 +100,8 @@ export default class Login extends Command {
95100 this . log ( 'Create one at: https://developers.hubspot.com/docs/api/private-apps\n' ) ;
96101
97102 const token = await password ( {
98- message : 'Enter your HubSpot Private App token:' ,
99103 mask : '*' ,
104+ message : 'Enter your HubSpot Private App token:' ,
100105 } ) ;
101106
102107 return {
@@ -105,33 +110,33 @@ export default class Login extends Command {
105110 } ;
106111 }
107112
108- private async promptSemrushCredentials ( ) : Promise < Credentials > {
109- this . log ( 'Semrush uses API keys for authentication .' ) ;
110- this . log ( 'Find your API key at: https://www.semrush .com/accounts/profile /\n' ) ;
113+ private async promptMetaCredentials ( ) : Promise < Credentials > {
114+ this . log ( 'Meta Ads uses OAuth2 access tokens .' ) ;
115+ this . log ( 'Generate a token at: https://developers.facebook .com/tools/explorer /\n' ) ;
111116
112117 const token = await password ( {
113- message : 'Enter your Semrush API key:' ,
114118 mask : '*' ,
119+ message : 'Enter your Meta access token:' ,
115120 } ) ;
116121
117122 return {
118123 token,
119- tokenType : 'api_key ' ,
124+ tokenType : 'oauth ' ,
120125 } ;
121126 }
122127
123- private async promptMetaCredentials ( ) : Promise < Credentials > {
124- this . log ( 'Meta Ads uses OAuth2 access tokens .' ) ;
125- this . log ( 'Generate a token at: https://developers.facebook .com/tools/explorer /\n' ) ;
128+ private async promptSemrushCredentials ( ) : Promise < Credentials > {
129+ this . log ( 'Semrush uses API keys for authentication .' ) ;
130+ this . log ( 'Find your API key at: https://www.semrush .com/accounts/profile /\n' ) ;
126131
127132 const token = await password ( {
128- message : 'Enter your Meta access token:' ,
129133 mask : '*' ,
134+ message : 'Enter your Semrush API key:' ,
130135 } ) ;
131136
132137 return {
133138 token,
134- tokenType : 'oauth ' ,
139+ tokenType : 'api_key ' ,
135140 } ;
136141 }
137142}
0 commit comments