11import { commands , window , ExtensionContext } from 'vscode' ;
22import {
33 getConfig ,
4- deleteAccount ,
5- deleteConfigFile ,
6- renameAccount ,
7- updateDefaultAccount ,
8- getConfigDefaultAccount ,
9- getConfigAccounts ,
4+ getAllConfigAccounts ,
5+ getConfigDefaultAccountIfExists ,
6+ removeAccountFromConfig ,
7+ renameConfigAccount ,
8+ setConfigAccountAsDefault ,
109} from '@hubspot/local-dev-lib/config' ;
11- import { CLIConfig } from '@hubspot/local-dev-lib/types/Config' ;
12- import {
13- CLIAccount ,
14- CLIAccount_DEPRECATED ,
15- } from '@hubspot/local-dev-lib/types/Accounts' ;
16- import { getAccountIdentifier } from '@hubspot/local-dev-lib/config/getAccountIdentifier' ;
10+ import { HubSpotConfigAccount } from '@hubspot/local-dev-lib/types/Accounts' ;
1711
1812import { updateStatusBarItems } from '../features/statusBar' ;
1913import { COMMANDS , EVENTS , TRACKED_EVENTS } from '../lib/constants' ;
@@ -22,16 +16,15 @@ import { portalNameInvalid } from '../lib/config';
2216import { trackEvent } from '../lib/tracking' ;
2317import { showAutoDismissedStatusBarMessage } from '../lib/statusBar' ;
2418
25- const showRenameAccountPrompt = ( accountToRename : CLIAccount_DEPRECATED ) => {
19+ const showRenameAccountPrompt = ( accountToRename : HubSpotConfigAccount ) => {
2620 window
2721 . showInputBox ( {
2822 placeHolder : 'Enter a new name for the account' ,
2923 } )
3024 . then ( async ( newName : string | undefined ) => {
3125 if ( newName ) {
32- const oldName =
33- accountToRename . name || getAccountIdentifier ( accountToRename ) ;
34- const config : CLIConfig | null = getConfig ( ) ;
26+ const oldName = accountToRename . name ;
27+ const config = getConfig ( ) ;
3528 let invalidReason = '' ;
3629 if ( config ) {
3730 invalidReason = portalNameInvalid ( newName , config ) ;
@@ -44,7 +37,7 @@ const showRenameAccountPrompt = (accountToRename: CLIAccount_DEPRECATED) => {
4437 ) ;
4538 return ;
4639 }
47- renameAccount ( String ( oldName ) , newName ) ;
40+ renameConfigAccount ( String ( oldName ) , newName ) ;
4841 commands . executeCommand ( EVENTS . ACCOUNT . REFRESH ) ;
4942 showAutoDismissedStatusBarMessage (
5043 `Successfully renamed default account from ${ oldName } to ${ newName } .`
@@ -73,9 +66,9 @@ export const registerCommands = (context: ExtensionContext) => {
7366 typeof defaultAccount === 'string' ||
7467 typeof defaultAccount === 'number'
7568 ? defaultAccount
76- : defaultAccount . name || getAccountIdentifier ( defaultAccount ) ;
69+ : defaultAccount . name ;
7770 console . log ( 'Setting default account to: ' , newDefaultAccount ) ;
78- updateDefaultAccount ( newDefaultAccount ) ;
71+ setConfigAccountAsDefault ( newDefaultAccount ) ;
7972 trackEvent ( TRACKED_EVENTS . UPDATE_DEFAULT_ACCOUNT ) ;
8073 commands . executeCommand ( COMMANDS . REMOTE_FS . HARD_REFRESH ) ;
8174 if ( ! silenceNotification ) {
@@ -91,18 +84,18 @@ export const registerCommands = (context: ExtensionContext) => {
9184 commands . registerCommand (
9285 COMMANDS . CONFIG . SELECT_DEFAULT_ACCOUNT ,
9386 async ( ) => {
94- const defaultAccount = getConfigDefaultAccount ( ) ;
95- const accounts : CLIAccount [ ] = getConfigAccounts ( ) || [ ] ;
87+ const defaultAccount = getConfigDefaultAccountIfExists ( ) ;
88+ const accounts : HubSpotConfigAccount [ ] = getAllConfigAccounts ( ) || [ ] ;
9689
9790 if ( accounts && accounts . length !== 0 ) {
9891 window
9992 . showQuickPick (
100- accounts . map ( ( a : CLIAccount ) => {
93+ accounts . map ( ( a : HubSpotConfigAccount ) => {
10194 return {
10295 label : getDisplayedHubspotPortalInfo ( a ) ,
10396 description :
104- defaultAccount === getAccountIdentifier ( a ) ||
105- defaultAccount === a . name
97+ defaultAccount ?. accountId === a . accountId ||
98+ defaultAccount ?. name === a . name
10699 ? '(default)'
107100 : '' ,
108101 account : a ,
@@ -114,17 +107,15 @@ export const registerCommands = (context: ExtensionContext) => {
114107 )
115108 . then ( async ( selection ) => {
116109 if ( selection ) {
117- const newDefaultAccount =
118- selection . account . name ||
119- getAccountIdentifier ( selection . account ) ;
110+ const newDefaultAccount = selection . account . name ;
120111 if ( ! newDefaultAccount ) {
121112 window . showErrorMessage (
122113 'No account selected; Choose an account to set as default'
123114 ) ;
124115 return ;
125116 }
126117 trackEvent ( TRACKED_EVENTS . SELECT_DEFAULT_ACCOUNT ) ;
127- updateDefaultAccount ( newDefaultAccount ) ;
118+ setConfigAccountAsDefault ( newDefaultAccount ) ;
128119 showAutoDismissedStatusBarMessage (
129120 `Successfully set default account to ${ newDefaultAccount } .`
130121 ) ;
@@ -149,9 +140,7 @@ export const registerCommands = (context: ExtensionContext) => {
149140 commands . registerCommand (
150141 COMMANDS . CONFIG . DELETE_ACCOUNT ,
151142 async ( accountToDelete ) => {
152- const accounts : CLIAccount [ ] = getConfigAccounts ( ) || [ ] ;
153- const accountIdentifier =
154- accountToDelete . name || getAccountIdentifier ( accountToDelete ) ;
143+ const accountIdentifier = accountToDelete . name ;
155144
156145 await window
157146 . showInformationMessage (
@@ -161,17 +150,10 @@ export const registerCommands = (context: ExtensionContext) => {
161150 )
162151 . then ( async ( answer ) => {
163152 if ( answer === 'Yes' ) {
164- if ( accounts && accounts . length === 1 ) {
165- deleteConfigFile ( ) ;
166- showAutoDismissedStatusBarMessage (
167- `Successfully deleted account ${ accountIdentifier } . The config file has been deleted because there are no more authenticated accounts.`
168- ) ;
169- } else {
170- deleteAccount ( accountIdentifier ) ;
171- showAutoDismissedStatusBarMessage (
172- `Successfully deleted account ${ accountIdentifier } .`
173- ) ;
174- }
153+ removeAccountFromConfig ( accountIdentifier ) ;
154+ showAutoDismissedStatusBarMessage (
155+ `Successfully deleted account ${ accountIdentifier } .`
156+ ) ;
175157 trackEvent ( TRACKED_EVENTS . DELETE_ACCOUNT ) ;
176158 commands . executeCommand ( COMMANDS . REMOTE_FS . HARD_REFRESH ) ;
177159 commands . executeCommand ( EVENTS . ACCOUNT . REFRESH ) ;
0 commit comments