(
store: CliServerConnectionStore,
account: {
readonly origin: string;
readonly sub?: string;
readonly org?: string;
readonly email?: string;
},
)
| 2416 | // distinct profiles instead of clobbering each other (the way opencode keys |
| 2417 | // accounts by email/url). A re-login to the same account reuses its profile. |
| 2418 | const chooseLoginProfileName = ( |
| 2419 | store: CliServerConnectionStore, |
| 2420 | account: { |
| 2421 | readonly origin: string; |
| 2422 | readonly sub?: string; |
| 2423 | readonly org?: string; |
| 2424 | readonly email?: string; |
| 2425 | }, |
| 2426 | ): string => { |
| 2427 | const identity = |
| 2428 | account.sub && account.org ? `${account.origin}|${account.sub}|${account.org}` : null; |
| 2429 | if (identity) { |
| 2430 | const existing = store.profiles.find((p) => oauthAccountIdentity(p.connection) === identity); |
| 2431 | if (existing) return existing.name; |
| 2432 | } |
| 2433 | const base = sanitizeProfileName(account.email ?? account.sub ?? loginHostLabel(account.origin)); |
| 2434 | if (!store.profiles.some((p) => p.name === base)) return base; |
| 2435 | for (let suffix = 2; ; suffix += 1) { |
| 2436 | const candidate = `${base}-${suffix}`; |
| 2437 | if (!store.profiles.some((p) => p.name === candidate)) return candidate; |
| 2438 | } |
| 2439 | }; |
| 2440 | |
| 2441 | /** Where `executor login` lands with no flags and no stored profiles. */ |
| 2442 | const DEFAULT_LOGIN_ORIGIN = "https://executor.sh"; |
no test coverage detected