Skip to content

Commit b68d1b9

Browse files
committed
feat(env): read SOCKET_API_TOKEN as canonical api-token name
Adds SOCKET_API_TOKEN to the head of getSocketCliApiToken()'s fallback chain. Legacy names (SOCKET_CLI_API_TOKEN, SOCKET_CLI_API_KEY, SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY) remain supported. Matches the fleet-wide rename of the GitHub repo secret to SOCKET_API_TOKEN, and gives a single canonical env name Socket tools can standardize on going forward.
1 parent f49b2fe commit b68d1b9

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/env/socket-cli.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ export function getSocketCliApiTimeout(): number {
9393
}
9494

9595
/**
96-
* Socket CLI API authentication token (alternative name).
97-
* Checks SOCKET_CLI_API_TOKEN, SOCKET_CLI_API_KEY, SOCKET_SECURITY_API_TOKEN, SOCKET_SECURITY_API_KEY.
98-
* Maintains full v1.x backward compatibility.
96+
* Socket CLI API authentication token.
97+
* Checks SOCKET_API_TOKEN (canonical), then the legacy names
98+
* SOCKET_CLI_API_TOKEN, SOCKET_CLI_API_KEY, SOCKET_SECURITY_API_TOKEN,
99+
* SOCKET_SECURITY_API_KEY. Maintains full v1.x backward compatibility.
99100
*
100101
* @returns API token or undefined
101102
*
@@ -110,6 +111,7 @@ export function getSocketCliApiTimeout(): number {
110111
/*@__NO_SIDE_EFFECTS__*/
111112
export function getSocketCliApiToken(): string | undefined {
112113
return (
114+
getEnvValue('SOCKET_API_TOKEN') ||
113115
getEnvValue('SOCKET_CLI_API_TOKEN') ||
114116
getEnvValue('SOCKET_CLI_API_KEY') ||
115117
getEnvValue('SOCKET_SECURITY_API_TOKEN') ||

test/unit/env/socket-cli.test.mts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,22 @@ describe('socket-cli env', () => {
9595
})
9696

9797
describe('getSocketCliApiToken', () => {
98-
it('should return token when set', () => {
98+
it('should return token when SOCKET_CLI_API_TOKEN is set', () => {
9999
setEnv('SOCKET_CLI_API_TOKEN', 'test-token-123')
100100
expect(getSocketCliApiToken()).toBe('test-token-123')
101101
})
102102

103+
it('should return token when SOCKET_API_TOKEN is set', () => {
104+
setEnv('SOCKET_API_TOKEN', 'canonical-token')
105+
expect(getSocketCliApiToken()).toBe('canonical-token')
106+
})
107+
108+
it('should prefer SOCKET_API_TOKEN over legacy names', () => {
109+
setEnv('SOCKET_API_TOKEN', 'canonical-token')
110+
setEnv('SOCKET_CLI_API_TOKEN', 'legacy-token')
111+
expect(getSocketCliApiToken()).toBe('canonical-token')
112+
})
113+
103114
it('should return undefined when not set', () => {
104115
setEnv('SOCKET_CLI_API_TOKEN', undefined)
105116
expect(getSocketCliApiToken()).toBeUndefined()

0 commit comments

Comments
 (0)