| 219 | |
| 220 | /** Determine which backend to use based on provided credentials. */ |
| 221 | export function resolveCredentials(params: CredentialParams): ResolvedCredentials { |
| 222 | const mode = params.connectionMode ?? (params.serviceAccountToken ? 'service_account' : 'connect') |
| 223 | |
| 224 | if (mode === 'service_account') { |
| 225 | if (!params.serviceAccountToken) { |
| 226 | throw new Error('Service Account token is required for Service Account mode') |
| 227 | } |
| 228 | return { mode, serviceAccountToken: params.serviceAccountToken } |
| 229 | } |
| 230 | |
| 231 | if (!params.serverUrl || !params.apiKey) { |
| 232 | throw new Error('Server URL and Connect token are required for Connect Server mode') |
| 233 | } |
| 234 | return { mode, serverUrl: params.serverUrl, apiKey: params.apiKey } |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Create a 1Password SDK client from a service account token. |