Files
orca/src/shared/orca-cloud-setup-link.ts
T
Neil 21ac87b972 feat(cloud-start): setup return link, setup telemetry, X1 error model, B2 team-plans lookup (NP-4)
- N9: orca://cloud/setup/return?session=cs_… is routed (open-url + second
  instance), validated, focuses Orca and fans out to renderer listeners
  (onCloudSetupReturn) so the setup session re-reads at once.
- N10: cloud_setup_step_{started,done,failed}, cloud_setup_first_sandbox and
  cloud_setup_plan_chosen, enum-only, derived from the setup rows.
- X1: setup error kinds (timed_out, checkout_canceled, bank_step,
  trial_unavailable, team_create_failed, wrong_account) and their actions.
- B2: billing POST /v1/billing/team-plans returns other teams' plan state with
  the caller's own token; auth confirms membership from that token (no new
  credential). Desktop IPC billingTeamPlans + useSwitchToPlannedTeam. The team
  switch logic moves out of SidebarTeamSubmenu so the composer can reuse it.
2026-11-10 05:50:29 -08:00

41 lines
1.4 KiB
TypeScript

// N9: the setup done page (auth.onorca.dev/cloud/setup/done) opens
// orca://cloud/setup/return?session=<id>. The desktop never depends on it (polling already sees
// every step); the link only focuses Orca and asks the open setup tracker to re-read right away.
/** IPC channel main uses to hand a parsed return link to the renderer. */
export const ORCA_CLOUD_SETUP_RETURN_CHANNEL = 'cloudSetup:return'
/** Setup session ids are minted by the billing Worker: `cs_` + 22 base64url characters. */
export const CLOUD_SETUP_SESSION_ID_PATTERN = /^cs_[A-Za-z0-9_-]{22}$/
export type OrcaCloudSetupReturn = { sessionId: string }
/** Parses `orca://cloud/setup/return?session=cs_…`; anything else (or a malformed id) is null. */
export function parseOrcaCloudSetupReturnLink(raw: string): OrcaCloudSetupReturn | null {
let url: URL
try {
url = new URL(raw.trim())
} catch {
return null
}
if (
url.protocol !== 'orca:' ||
url.hostname !== 'cloud' ||
url.pathname.replace(/\/$/, '') !== '/setup/return'
) {
return null
}
const sessionId = url.searchParams.get('session')
return sessionId && CLOUD_SETUP_SESSION_ID_PATTERN.test(sessionId) ? { sessionId } : null
}
export function findOrcaCloudSetupReturnLink(argv: readonly string[]): OrcaCloudSetupReturn | null {
for (const arg of argv) {
const parsed = parseOrcaCloudSetupReturnLink(arg)
if (parsed) {
return parsed
}
}
return null
}