* Get API credential for a source (handles basic auth JSON parsing)
(source: LoadedSource)
| 189 | * Get API credential for a source (handles basic auth JSON parsing) |
| 190 | */ |
| 191 | async getApiCredential(source: LoadedSource): Promise<ApiCredential | null> { |
| 192 | const cred = await this.load(source); |
| 193 | if (!cred?.value) return null; |
| 194 | |
| 195 | // Check for basic auth (JSON with username/password) |
| 196 | if (source.config.api?.authType === 'basic') { |
| 197 | try { |
| 198 | const parsed = JSON.parse(cred.value); |
| 199 | if (parsed.username && parsed.password) { |
| 200 | return parsed as BasicAuthCredential; |
| 201 | } |
| 202 | } catch { |
| 203 | // Not JSON, treat as regular credential |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | return cred.value; |
| 208 | } |
| 209 | |
| 210 | // ============================================================ |
| 211 | // Credential ID Resolution |