@@ -11,10 +11,11 @@ import constants from '../constants'
1111
1212export interface LocalConfig {
1313 apiBaseUrl ?: string | null | undefined
14- // @deprecated ; use apiToken
14+ // @deprecated ; use apiToken. when loading a config, if this prop exists it
15+ // is deleted and set to apiToken instead, and then persisted.
16+ // should only happen once for legacy users.
1517 apiKey ?: string | null | undefined
1618 apiProxy ?: string | null | undefined
17- // apiToken replaced apiKey.
1819 apiToken ?: string | null | undefined
1920 defaultOrg ?: string
2021 enforcedOrgs ?: string [ ] | readonly string [ ] | null | undefined
@@ -54,6 +55,12 @@ let pendingSave = false
5455export function overrideCachedConfig ( config : unknown ) {
5556 cachedConfig = config as LocalConfig
5657 readOnlyConfig = true
58+
59+ // Normalize apiKey to apiToken
60+ if ( cachedConfig [ 'apiKey' ] ) {
61+ cachedConfig [ 'apiToken' ] = cachedConfig [ 'apiKey' ]
62+ delete cachedConfig [ 'apiKey' ]
63+ }
5764}
5865
5966function getConfigValues ( ) : LocalConfig {
@@ -72,6 +79,13 @@ function getConfigValues(): LocalConfig {
7279 } catch {
7380 logger . warn ( `Failed to parse config at ${ configPath } ` )
7481 }
82+ // Normalize apiKey to apiToken and persist; one time migration per user
83+ if ( cachedConfig [ 'apiKey' ] ) {
84+ const token = cachedConfig [ 'apiKey' ]
85+ delete cachedConfig [ 'apiKey' ]
86+ // Persist it
87+ updateConfigValue ( 'apiToken' , token )
88+ }
7589 } else {
7690 fs . mkdirSync ( path . dirname ( configPath ) , { recursive : true } )
7791 }
@@ -120,9 +134,10 @@ function getConfigPath(): string | undefined {
120134}
121135
122136function normalizeConfigKey ( key : keyof LocalConfig ) : keyof LocalConfig {
123- const normalizedKey = key === 'apiToken' ? 'apiKey' : key
137+ // Note: apiKey was the old name of the token. When we load a config with
138+ // property apiKey, we'll copy that to apiToken and delete the old prop
139+ const normalizedKey = key === 'apiKey' ? 'apiToken' : key
124140 if (
125- normalizedKey !== 'apiKey' &&
126141 normalizedKey !== 'test' &&
127142 ! supportedConfigKeys . has ( normalizedKey as keyof LocalConfig )
128143 ) {
0 commit comments