mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
- Signed out, Set up and start opens one tab. The authorize page shows the setup account step (A2). Once the code is exchanged, the loopback holds the tab, creates the billing setup session and 302s the same tab into the setup pages. - Signed in, the session is created and its start URL is opened. - IPC: orcaProfiles.cloudSetupStart / cloudSetupGet / cloudSetupLink (Copy setup link mints a fresh one-time link). - Renderer: cloud-setup-session.ts polls the session (2 s for 3 min, then 10 s), keeps a snapshot for the composer and tracker, and switches the profile to the team setup chose. - Plans dialog: Checkout joins the open setup session. A personal account (409 team_required) goes through setup instead, which makes or picks a team first. - Billing: POST /v1/cloud-setup/sessions/:id/link.
70 lines
2.4 KiB
TypeScript
70 lines
2.4 KiB
TypeScript
// Orca Cloud setup session (NP-4 N1): one browser tab that chains sign-in, team, plan or trial,
|
|
// Checkout (only when needed) and the GitHub App install. The billing service owns the session;
|
|
// the desktop starts it and polls it while the composer's setup panel shows each step.
|
|
|
|
export const CLOUD_SETUP_NEEDS = ['team', 'plan', 'github'] as const
|
|
export type CloudSetupNeed = (typeof CLOUD_SETUP_NEEDS)[number]
|
|
|
|
export const CLOUD_SETUP_SESSION_ID = /^cs_[A-Za-z0-9_-]{22}$/
|
|
|
|
export type CloudSetupStartArgs = {
|
|
/** https://github.com/<owner>/<repo> of the project, when the workspace needs GitHub access. */
|
|
repo?: string
|
|
needs: CloudSetupNeed[]
|
|
/** Ask which team even when the profile already has an active one. */
|
|
chooseTeam?: boolean
|
|
}
|
|
|
|
export type CloudSetupStartResult =
|
|
| { status: 'opened'; sessionId: string; expiresAt: number }
|
|
| { status: 'unconfigured' }
|
|
| { status: 'signed-out' }
|
|
| { status: 'cancelled' }
|
|
| { status: 'failed'; error: string }
|
|
|
|
export type CloudSetupStepState = 'done' | 'needed' | 'active' | 'pending' | 'failed' | 'optional'
|
|
|
|
export type CloudSetupSessionStep = {
|
|
id: 'account' | 'team' | 'plan' | 'github'
|
|
state: CloudSetupStepState
|
|
/** team: its name · plan: 'trial' | 'subscription' | 'checkout' · github: 'requested'. */
|
|
detail?: string
|
|
}
|
|
|
|
/** Error kinds the setup tracker shows (spec X1); `detail` carries e.g. the other account's email. */
|
|
export const CLOUD_SETUP_ERROR_KINDS = [
|
|
'timed_out',
|
|
'checkout_canceled',
|
|
'bank_step',
|
|
'trial_unavailable',
|
|
'team_create_failed',
|
|
'wrong_account'
|
|
] as const
|
|
export type CloudSetupErrorKind = (typeof CLOUD_SETUP_ERROR_KINDS)[number]
|
|
|
|
export type CloudSetupSession = {
|
|
id: string
|
|
steps: CloudSetupSessionStep[]
|
|
team: { orgId: string; name: string | null; created: boolean } | null
|
|
trial: { includedSeconds: number; usedSeconds: number; exhausted: boolean } | null
|
|
plan: 'subscription' | 'trial' | null
|
|
finished: boolean
|
|
error: { kind: CloudSetupErrorKind; detail?: string } | null
|
|
expiresAt: number
|
|
}
|
|
|
|
export type CloudSetupGetResult =
|
|
| { status: 'ok'; session: CloudSetupSession }
|
|
/** Expired, or it belongs to another account. */
|
|
| { status: 'not-found' }
|
|
| { status: 'unconfigured' }
|
|
| { status: 'signed-out' }
|
|
| { status: 'failed'; error: string }
|
|
|
|
export type CloudSetupLinkResult =
|
|
| { status: 'ok'; url: string }
|
|
| { status: 'not-found' }
|
|
| { status: 'unconfigured' }
|
|
| { status: 'signed-out' }
|
|
| { status: 'failed'; error: string }
|