(
store: CliServerConnectionStore,
account: {
readonly origin: string;
readonly sub?: string;
readonly org?: string;
readonly email?: string;
},
)
| 2356 | // distinct profiles instead of clobbering each other (the way opencode keys |
| 2357 | // accounts by email/url). A re-login to the same account reuses its profile. |
| 2358 | const chooseLoginProfileName = ( |
| 2359 | store: CliServerConnectionStore, |
| 2360 | account: { |
| 2361 | readonly origin: string; |
| 2362 | readonly sub?: string; |
| 2363 | readonly org?: string; |
| 2364 | readonly email?: string; |
| 2365 | }, |
| 2366 | ): string => { |
| 2367 | const identity = |
| 2368 | account.sub && account.org ? `${account.origin}|${account.sub}|${account.org}` : null; |
| 2369 | if (identity) { |
| 2370 | const existing = store.profiles.find((p) => oauthAccountIdentity(p.connection) === identity); |
| 2371 | if (existing) return existing.name; |
| 2372 | } |
| 2373 | const base = sanitizeProfileName(account.email ?? account.sub ?? loginHostLabel(account.origin)); |
| 2374 | if (!store.profiles.some((p) => p.name === base)) return base; |
| 2375 | for (let suffix = 2; ; suffix += 1) { |
| 2376 | const candidate = `${base}-${suffix}`; |
| 2377 | if (!store.profiles.some((p) => p.name === candidate)) return candidate; |
| 2378 | } |
| 2379 | }; |
| 2380 | |
| 2381 | /** Where `executor login` lands with no flags and no stored profiles. */ |
| 2382 | const DEFAULT_LOGIN_ORIGIN = "https://executor.sh"; |
no test coverage detected