@@ -2,7 +2,6 @@ import { commands, window, ExtensionContext } from 'vscode';
22import { updateStatusBarItems } from '../statusBar' ;
33import { COMMANDS , TRACKED_EVENTS } from '../constants' ;
44import { getDisplayedHubspotPortalInfo } from '../helpers' ;
5- import { Portal } from '../types' ;
65import { portalNameInvalid } from '../validation' ;
76import { trackEvent } from '../tracking' ;
87import { showAutoDismissedStatusBarMessage } from '../messaging' ;
@@ -13,24 +12,31 @@ import {
1312 renameAccount ,
1413 updateDefaultAccount ,
1514} from '@hubspot/local-dev-lib/config' ;
15+ import { CLIConfig } from '@hubspot/local-dev-lib/types/Config' ;
16+ import { CLIAccount_DEPRECATED } from '@hubspot/local-dev-lib/types/Accounts' ;
1617
17- const showRenameAccountPrompt = ( accountToRename : Portal ) => {
18+ const showRenameAccountPrompt = ( accountToRename : CLIAccount_DEPRECATED ) => {
1819 window
1920 . showInputBox ( {
2021 placeHolder : 'Enter a new name for the account' ,
2122 } )
2223 . then ( async ( newName : string | undefined ) => {
2324 if ( newName ) {
2425 const oldName = accountToRename . name || accountToRename . portalId ;
25- const config = getConfig ( ) ;
26+ const config : CLIConfig | null = getConfig ( ) ;
2627 let invalidReason = '' ;
2728 if ( config ) {
28- // @ts -expect-error TODO: Fix this when updating local-dev-lib
2929 invalidReason = portalNameInvalid ( newName , config ) ;
3030 }
3131
3232 if ( ! invalidReason ) {
33- renameAccount ( oldName , newName ) ;
33+ if ( ! oldName ) {
34+ window . showErrorMessage (
35+ 'Could not determine account name to rename'
36+ ) ;
37+ return ;
38+ }
39+ renameAccount ( String ( oldName ) , newName ) ;
3440 showAutoDismissedStatusBarMessage (
3541 `Successfully renamed default account from ${ oldName } to ${ newName } .`
3642 ) ;
@@ -76,19 +82,16 @@ export const registerCommands = (context: ExtensionContext) => {
7682 commands . registerCommand (
7783 COMMANDS . CONFIG . SELECT_DEFAULT_ACCOUNT ,
7884 async ( ) => {
79- const config = getConfig ( ) ;
80- // @ts -expect-error TODO: Fix this when updating local-dev-lib
81- if ( config && config . portals ) {
85+ const config : CLIConfig | null = getConfig ( ) ;
86+
87+ if ( config && 'portals' in config && config . portals ) {
8288 window
8389 . showQuickPick (
84- // @ts -expect-error TODO: Fix this when updating local-dev-lib
85- config . portals . map ( ( p : Portal ) => {
90+ config . portals . map ( ( p : CLIAccount_DEPRECATED ) => {
8691 return {
8792 label : getDisplayedHubspotPortalInfo ( p ) ,
8893 description :
89- // @ts -expect-error TODO: Fix this when updating local-dev-lib
9094 config . defaultPortal === p . portalId ||
91- // @ts -expect-error TODO: Fix this when updating local-dev-lib
9295 config . defaultPortal === p . name
9396 ? '(default)'
9497 : '' ,
@@ -102,8 +105,13 @@ export const registerCommands = (context: ExtensionContext) => {
102105 . then ( async ( selection ) => {
103106 if ( selection ) {
104107 const newDefaultAccount =
105- // @ts -ignore selection is an object
106108 selection . portal . name || selection . portal . portalId ;
109+ if ( ! newDefaultAccount ) {
110+ window . showErrorMessage (
111+ 'No account selected; Choose an account to set as default'
112+ ) ;
113+ return ;
114+ }
107115 await trackEvent ( TRACKED_EVENTS . SELECT_DEFAULT_ACCOUNT ) ;
108116 updateDefaultAccount ( newDefaultAccount ) ;
109117 showAutoDismissedStatusBarMessage (
@@ -142,8 +150,11 @@ export const registerCommands = (context: ExtensionContext) => {
142150 )
143151 . then ( async ( answer ) => {
144152 if ( answer === 'Yes' ) {
145- // @ts -expect-error TODO: Fix this when updating local-dev-lib
146- if ( config && config . portals . length === 1 ) {
153+ if (
154+ config &&
155+ 'portals' in config &&
156+ config . portals . length === 1
157+ ) {
147158 deleteConfigFile ( ) ;
148159 showAutoDismissedStatusBarMessage (
149160 `Successfully deleted account ${ accountIdentifier } . The config file has been deleted because there are no more authenticated accounts.`
0 commit comments