/ mervelas / src / utils / authPortable.ts
Swadhin Biswas feat: implement mervelas cli engine, built-in tools, and reactive UI · 4/3/2026
0358986
25 lines · 785 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { execa } from 'execa'
import { getMacOsKeychainStorageServiceNames } from 'src/utils/secureStorage/macOsKeychainHelpers.js'

export async function maybeRemoveApiKeyFromMacOSKeychainThrows(): Promise<void> {
  if (process.platform === 'darwin') {
    let deletedAny = false
    for (const storageServiceName of getMacOsKeychainStorageServiceNames()) {
      const result = await execa(
        `security delete-generic-password -a $USER -s "${storageServiceName}"`,
        { shell: true, reject: false },
      )
      if (result.exitCode === 0) {
        deletedAny = true
      }
    }
    if (!deletedAny) {
      throw new Error('Failed to delete keychain entry')
    }
  }
}

export function normalizeApiKeyForConfig(apiKey: string): string {
  return apiKey.slice(-20)
}