(
store: CliServerConnectionStore,
account: {
readonly origin: string;
readonly sub?: string;
readonly org?: string;
readonly email?: string;
},
)
| 2334 | // distinct profiles instead of clobbering each other (the way opencode keys |
| 2335 | // accounts by email/url). A re-login to the same account reuses its profile. |
| 2336 | const chooseLoginProfileName = ( |
| 2337 | store: CliServerConnectionStore, |
| 2338 | account: { |
| 2339 | readonly origin: string; |
| 2340 | readonly sub?: string; |
| 2341 | readonly org?: string; |
| 2342 | readonly email?: string; |
| 2343 | }, |
| 2344 | ): string => { |
| 2345 | const identity = |
| 2346 | account.sub && account.org ? `${account.origin}|${account.sub}|${account.org}` : null; |
| 2347 | if (identity) { |
| 2348 | const existing = store.profiles.find((p) => oauthAccountIdentity(p.connection) === identity); |
| 2349 | if (existing) return existing.name; |
| 2350 | } |
| 2351 | const base = sanitizeProfileName(account.email ?? account.sub ?? loginHostLabel(account.origin)); |
| 2352 | if (!store.profiles.some((p) => p.name === base)) return base; |
| 2353 | for (let suffix = 2; ; suffix += 1) { |
| 2354 | const candidate = `${base}-${suffix}`; |
| 2355 | if (!store.profiles.some((p) => p.name === candidate)) return candidate; |
| 2356 | } |
| 2357 | }; |
| 2358 | |
| 2359 | /** Where `executor login` lands with no flags and no stored profiles. */ |
| 2360 | const DEFAULT_LOGIN_ORIGIN = "https://executor.sh"; |
no test coverage detected