From 92cbe9f74e9043820ca7da0f3db74bb1ad45de3f Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 14 Nov 2026 00:53:19 -0800 Subject: [PATCH 1/2] feat(cloud): move team, billing and Enterprise admin UI to the web console Owner decision: paid and admin settings do not belong in the open-source desktop app. Deletes the Enterprise pane (SSO, domains, SCIM, MFA policy, audit log), the Plan & billing section and plans dialog (checkout, usage history, plan-feature-copy), and Team management (members, invites, roles, leave, delete, create), with their hooks, fixtures, tests, i18n keys and the main/preload/IPC only they used. Each removed section is now one "Manage in browser" row. Main asks auth for a single-use console code (POST /v1/desktop/console/ticket {page, orgId?} -> {code}) and opens /console/
?code=... with shell.openExternal; on any failure it opens the page without a code. Endpoint, field names and origin live in cloud-console-config.ts (ORCA_CLOUD_CONSOLE_URL overrides the origin, default is the auth origin). Kept: sign-in, account identity and own MFA row, the team MFA gate/banners, the team switcher, the roster (presence, names), plan status badge and payment notice, in-context billing blockers (now "Compare plans" opens the console and re-checks on focus), cloud setup. --- src/main/billing/billing-client.test.ts | 72 +- src/main/billing/billing-client.ts | 23 - src/main/billing/billing-config.test.ts | 28 +- src/main/billing/billing-service-link.test.ts | 35 - src/main/billing/billing-service.ts | 43 +- .../billing/billing-setup-session-fallback.ts | 18 - src/main/billing/billing-usage-client.test.ts | 72 -- src/main/billing/billing-usage-client.ts | 67 -- src/main/cloud-api/cloud-api-client.test.ts | 65 +- src/main/cloud-api/cloud-api-client.ts | 22 - src/main/cloud-api/cloud-api-ipc.ts | 8 - .../profiles/orca-cloud-console-handlers.ts | 24 + .../profiles/orca-profile-billing-handlers.ts | 58 +- .../orca-profile-org-enterprise-handlers.ts | 63 -- .../orca-profile-org-members-handlers.ts | 235 +----- .../cloud-auth/profile-cloud-dev-auth.ts | 17 +- .../cloud-auth/profile-cloud-pkce.ts | 2 +- .../cloud-console/cloud-console-config.ts | 48 ++ .../cloud-console/cloud-console-link.test.ts | 94 +++ .../cloud-console/cloud-console-link.ts | 93 +++ .../profile-cloud-team-mfa-service.test.ts | 67 +- .../profile-cloud-team-mfa-service.ts | 149 +--- .../profile-cloud-dev-org-members.ts | 118 +-- .../profile-cloud-org-delete-client.test.ts | 157 ---- .../profile-cloud-org-delete-client.ts | 90 --- .../profile-cloud-org-delete-service.ts | 101 --- ...rofile-cloud-org-enterprise-client.test.ts | 143 ---- .../profile-cloud-org-enterprise-client.ts | 86 --- .../profile-cloud-org-enterprise-service.ts | 154 ---- .../profile-cloud-org-members-client.ts | 81 --- .../profile-cloud-org-members-service.ts | 232 +----- src/preload/api/cloud-api-bridge.ts | 12 +- src/preload/api/orca-profile-api.ts | 91 +-- src/preload/api/orca-profiles-bridge.ts | 20 +- src/renderer/src/App.tsx | 4 - .../billing/AccountMenuTrialRow.tsx | 4 +- .../PlanBillingOverageSave.fixture.tsx | 117 --- .../billing/PlanBillingOverageSave.test.tsx | 197 ------ .../billing/PlanBillingSection.fixture.tsx | 426 ----------- .../components/billing/PlanBillingSection.tsx | 365 ---------- .../billing/PlanBillingUsage.test.tsx | 220 ------ .../components/billing/PlanBillingUsage.tsx | 416 ----------- .../PlanBillingUsageHistory.fixture.tsx | 175 ----- .../billing/PlanBillingUsageHistory.tsx | 155 ---- .../components/billing/TrialPlanSummary.tsx | 67 -- .../components/billing/UsageHistoryChart.tsx | 152 ---- .../billing/billing-summary-store.ts | 2 +- .../checkout/CheckoutPanel.fixture.tsx | 90 --- .../billing/checkout/CheckoutPanel.test.tsx | 52 -- .../billing/checkout/CheckoutPanel.tsx | 305 -------- .../billing/checkout/checkout-flow.test.ts | 36 - .../billing/checkout/checkout-flow.ts | 68 -- .../billing/checkout/checkout-return.ts | 49 -- .../billing/checkout/use-checkout-flow.ts | 187 ----- .../components/billing/overage-save-state.tsx | 137 ---- .../components/billing/plan-billing-copy.ts | 47 +- .../billing/plan-billing-fixtures.ts | 60 +- .../components/billing/plan-billing-format.ts | 11 + .../billing/plan-billing-usage-copy.ts | 4 +- .../plan-billing-usage-history.test.ts | 163 ----- .../billing/plan-billing-usage-history.ts | 239 ------- .../billing/plans/EnterprisePlanCard.tsx | 69 -- .../billing/plans/PlanCardShell.tsx | 64 -- .../billing/plans/PlansDialogContent.tsx | 79 --- .../billing/plans/PlansDialogHost.tsx | 136 ---- .../billing/plans/PlansIntervalToggle.tsx | 59 -- .../billing/plans/PlansView.fixture.tsx | 173 ----- .../billing/plans/PlansView.test.tsx | 88 --- .../components/billing/plans/PlansView.tsx | 229 ------ .../billing/plans/PlansViewParts.tsx | 127 ---- .../components/billing/plans/TeamPlanCard.tsx | 226 ------ .../billing/plans/plan-catalog-fixtures.ts | 99 --- .../billing/plans/plan-feature-copy.test.ts | 76 -- .../billing/plans/plan-feature-copy.ts | 110 --- .../billing/plans/plans-model.test.ts | 108 --- .../components/billing/plans/plans-model.ts | 175 ----- .../billing/plans/plans-page-store.ts | 38 - .../billing/plans/plans-pricing.test.ts | 62 -- .../components/billing/plans/plans-pricing.ts | 59 -- .../billing/plans/use-org-seat-count.ts | 13 - .../register-plan-billing-menu-item.test.ts | 12 +- .../register-plan-billing-menu-item.ts | 13 +- .../billing/sandbox-hours-agree.test.ts | 21 - .../billing/team/TeamCreateView.tsx | 159 ----- .../billing/team/TeamDeleteDialog.fixture.tsx | 104 --- .../billing/team/TeamDeleteDialog.tsx | 137 ---- .../billing/team/TeamDeleteSection.tsx | 93 --- .../billing/team/TeamDialogContent.test.tsx | 33 - .../billing/team/TeamDialogHost.tsx | 327 --------- .../billing/team/TeamInviteComposer.test.tsx | 32 - .../billing/team/TeamInviteComposer.tsx | 281 -------- .../billing/team/TeamMemberList.test.tsx | 204 ------ .../billing/team/TeamMemberList.tsx | 361 ---------- .../billing/team/TeamPageView.fixture.tsx | 407 ----------- .../billing/team/TeamPageView.test.tsx | 100 --- .../components/billing/team/TeamPageView.tsx | 327 --------- .../billing/team/TeamPlanSummary.tsx | 243 ------- .../billing/team/parse-invite-emails.test.ts | 44 -- .../billing/team/parse-invite-emails.ts | 47 -- .../src/components/billing/team/team-copy.ts | 180 ----- .../billing/team/team-delete-copy.test.ts | 126 ---- .../billing/team/team-delete-copy.ts | 146 ---- .../billing/team/team-leave.test.ts | 34 - .../src/components/billing/team/team-leave.ts | 42 -- .../billing/team/team-member-mfa.ts | 42 -- .../billing/team/team-page-store.ts | 49 -- .../billing/team/team-roles.test.ts | 19 - .../src/components/billing/team/team-roles.ts | 22 +- .../billing/team/team-roster-rows.ts | 83 --- .../billing/team/team-seat-math.test.ts | 34 - .../components/billing/team/team-seat-math.ts | 60 -- .../billing/team/use-team-actions.ts | 314 -------- .../billing/team/use-team-delete.tsx | 238 ------- .../use-plan-billing-usage-history.test.tsx | 72 -- .../billing/use-plan-billing-usage-history.ts | 149 ---- .../billing/{plans => }/use-plan-catalog.ts | 2 +- ...argetCombobox.progressive-billing.test.tsx | 4 +- .../new-workspace/RunTargetCombobox.test.tsx | 22 +- .../orca-cloud-run-target-access.test.ts | 20 +- .../orca-cloud-run-target-access.ts | 12 +- .../run-on/OrcaCloudTrialUsedUpNotice.tsx | 9 +- .../orca-cloud-setup/use-cloud-setup-flow.ts | 2 +- .../orca-cloud/CloudWakeBillingFixButton.tsx | 6 +- .../orca-cloud/cloud-workspace-actions.ts | 4 +- ...loud-workspace-archive-delete-race.test.ts | 2 +- .../enterprise/AuditLogScrollRegion.tsx | 42 -- .../EnterpriseAuditLog.owner-name.test.tsx | 252 ------- .../enterprise/EnterpriseAuditLog.tsx | 427 ----------- .../enterprise/EnterpriseSettingsPane.tsx | 111 --- .../EnterpriseSettingsView.fixture.tsx | 151 ---- .../EnterpriseSettingsView.test.tsx | 626 ---------------- .../enterprise/EnterpriseSettingsView.tsx | 124 ---- .../settings/enterprise/EnterpriseUpsell.tsx | 56 -- .../enterprise-audit-account-copy.ts | 190 ----- .../enterprise/enterprise-audit-copy.ts | 235 ------ .../enterprise/enterprise-audit-sso-copy.ts | 109 --- .../enterprise-audit-workspace-copy.ts | 240 ------- .../enterprise/enterprise-audit.fixtures.ts | 206 ------ .../sso/EnterpriseDirectorySync.tsx | 143 ---- .../enterprise/sso/EnterpriseSsoDomains.tsx | 262 ------- .../sso/EnterpriseSsoView.fixture.tsx | 180 ----- .../enterprise/sso/EnterpriseSsoView.test.tsx | 292 -------- .../enterprise/sso/EnterpriseSsoView.tsx | 281 -------- .../enterprise/sso/enterprise-sso-parts.tsx | 39 - .../enterprise/sso/enterprise-sso.fixtures.ts | 90 --- .../sso/use-enterprise-sso.test.tsx | 117 --- .../enterprise/sso/use-enterprise-sso.ts | 206 ------ .../enterprise/use-enterprise-audit-log.ts | 196 ----- .../orca-cloud/CloudConsoleLinkRow.tsx | 68 ++ .../OrcaAccountBillingPane.fixture.tsx | 124 ---- .../orca-cloud/OrcaAccountBillingPane.tsx | 9 +- .../orca-cloud/OrcaCloudConsoleLinks.tsx | 69 ++ .../orca-cloud/OrcaCloudSettings.fixture.tsx | 16 +- .../orca-cloud/OrcaCloudSettingsPanes.tsx | 49 +- .../account-menu/SidebarTeamSubmenu.tsx | 4 +- .../team-mfa/EnterpriseMfaPolicy.tsx | 234 ------ .../src/components/team-mfa/RequireMfaRow.tsx | 282 -------- .../components/team-mfa/TeamMfa.fixture.tsx | 148 ---- .../src/components/team-mfa/team-mfa-copy.ts | 29 +- .../src/components/team-mfa/team-mfa.test.tsx | 215 ------ .../VmBuildBillingBlocker.test.tsx | 22 +- .../VmBuildBillingBlocker.tsx | 16 +- .../worktree-creation/VmBuildSheet.tsx | 10 +- .../vm-build-failure-toast.ts | 4 +- .../src/hooks/useEphemeralVmRecipeOptions.ts | 4 - .../src/i18n/en-runtime-required.json | 56 +- src/renderer/src/i18n/locales/en.json | 669 +----------------- .../src/lib/orca-cloud-after-checkout.test.ts | 62 -- .../src/lib/orca-cloud-after-checkout.ts | 82 --- .../src/lib/orca-cloud-session-events.ts | 4 +- .../src/lib/orca-cloud/open-cloud-console.ts | 30 + .../lib/orca-cloud/orca-sign-in-again.test.ts | 2 +- .../orca-profiles-auth-actions.ts | 2 +- .../web/preload-api/web-orca-profiles-api.ts | 20 +- src/shared/cloud-api/cloud-api-types.ts | 73 +- src/shared/orca-billing-plans.ts | 2 +- src/shared/orca-billing.ts | 32 - src/shared/orca-cloud-console.ts | 20 + src/shared/orca-org-delete.ts | 103 --- src/shared/orca-org-enterprise.ts | 189 ----- src/shared/orca-org-management.test.ts | 15 - src/shared/orca-org-management.ts | 47 -- src/shared/orca-profile-reconnect-reason.ts | 6 + src/shared/orca-profiles.ts | 29 - src/shared/orca-team-mfa-policy.ts | 47 +- .../languages/protected-copy-keys.json | 20 - 186 files changed, 686 insertions(+), 19666 deletions(-) delete mode 100644 src/main/billing/billing-service-link.test.ts delete mode 100644 src/main/billing/billing-setup-session-fallback.ts delete mode 100644 src/main/billing/billing-usage-client.test.ts delete mode 100644 src/main/billing/billing-usage-client.ts create mode 100644 src/main/ipc/profiles/orca-cloud-console-handlers.ts delete mode 100644 src/main/ipc/profiles/orca-profile-org-enterprise-handlers.ts create mode 100644 src/main/orca-profiles/cloud-console/cloud-console-config.ts create mode 100644 src/main/orca-profiles/cloud-console/cloud-console-link.test.ts create mode 100644 src/main/orca-profiles/cloud-console/cloud-console-link.ts delete mode 100644 src/main/orca-profiles/cloud-org/profile-cloud-org-delete-client.test.ts delete mode 100644 src/main/orca-profiles/cloud-org/profile-cloud-org-delete-client.ts delete mode 100644 src/main/orca-profiles/cloud-org/profile-cloud-org-delete-service.ts delete mode 100644 src/main/orca-profiles/cloud-org/profile-cloud-org-enterprise-client.test.ts delete mode 100644 src/main/orca-profiles/cloud-org/profile-cloud-org-enterprise-client.ts delete mode 100644 src/main/orca-profiles/cloud-org/profile-cloud-org-enterprise-service.ts delete mode 100644 src/renderer/src/components/billing/PlanBillingOverageSave.fixture.tsx delete mode 100644 src/renderer/src/components/billing/PlanBillingOverageSave.test.tsx delete mode 100644 src/renderer/src/components/billing/PlanBillingSection.fixture.tsx delete mode 100644 src/renderer/src/components/billing/PlanBillingSection.tsx delete mode 100644 src/renderer/src/components/billing/PlanBillingUsage.test.tsx delete mode 100644 src/renderer/src/components/billing/PlanBillingUsage.tsx delete mode 100644 src/renderer/src/components/billing/PlanBillingUsageHistory.fixture.tsx delete mode 100644 src/renderer/src/components/billing/PlanBillingUsageHistory.tsx delete mode 100644 src/renderer/src/components/billing/TrialPlanSummary.tsx delete mode 100644 src/renderer/src/components/billing/UsageHistoryChart.tsx delete mode 100644 src/renderer/src/components/billing/checkout/CheckoutPanel.fixture.tsx delete mode 100644 src/renderer/src/components/billing/checkout/CheckoutPanel.test.tsx delete mode 100644 src/renderer/src/components/billing/checkout/CheckoutPanel.tsx delete mode 100644 src/renderer/src/components/billing/checkout/checkout-flow.test.ts delete mode 100644 src/renderer/src/components/billing/checkout/checkout-flow.ts delete mode 100644 src/renderer/src/components/billing/checkout/checkout-return.ts delete mode 100644 src/renderer/src/components/billing/checkout/use-checkout-flow.ts delete mode 100644 src/renderer/src/components/billing/overage-save-state.tsx delete mode 100644 src/renderer/src/components/billing/plan-billing-usage-history.test.ts delete mode 100644 src/renderer/src/components/billing/plan-billing-usage-history.ts delete mode 100644 src/renderer/src/components/billing/plans/EnterprisePlanCard.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlanCardShell.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlansDialogContent.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlansDialogHost.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlansIntervalToggle.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlansView.fixture.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlansView.test.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlansView.tsx delete mode 100644 src/renderer/src/components/billing/plans/PlansViewParts.tsx delete mode 100644 src/renderer/src/components/billing/plans/TeamPlanCard.tsx delete mode 100644 src/renderer/src/components/billing/plans/plan-catalog-fixtures.ts delete mode 100644 src/renderer/src/components/billing/plans/plan-feature-copy.test.ts delete mode 100644 src/renderer/src/components/billing/plans/plan-feature-copy.ts delete mode 100644 src/renderer/src/components/billing/plans/plans-model.test.ts delete mode 100644 src/renderer/src/components/billing/plans/plans-model.ts delete mode 100644 src/renderer/src/components/billing/plans/plans-page-store.ts delete mode 100644 src/renderer/src/components/billing/plans/plans-pricing.test.ts delete mode 100644 src/renderer/src/components/billing/plans/plans-pricing.ts delete mode 100644 src/renderer/src/components/billing/plans/use-org-seat-count.ts delete mode 100644 src/renderer/src/components/billing/team/TeamCreateView.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamDeleteDialog.fixture.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamDeleteDialog.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamDeleteSection.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamDialogContent.test.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamDialogHost.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamInviteComposer.test.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamInviteComposer.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamMemberList.test.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamMemberList.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamPageView.fixture.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamPageView.test.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamPageView.tsx delete mode 100644 src/renderer/src/components/billing/team/TeamPlanSummary.tsx delete mode 100644 src/renderer/src/components/billing/team/parse-invite-emails.test.ts delete mode 100644 src/renderer/src/components/billing/team/parse-invite-emails.ts delete mode 100644 src/renderer/src/components/billing/team/team-copy.ts delete mode 100644 src/renderer/src/components/billing/team/team-delete-copy.test.ts delete mode 100644 src/renderer/src/components/billing/team/team-delete-copy.ts delete mode 100644 src/renderer/src/components/billing/team/team-leave.test.ts delete mode 100644 src/renderer/src/components/billing/team/team-leave.ts delete mode 100644 src/renderer/src/components/billing/team/team-member-mfa.ts delete mode 100644 src/renderer/src/components/billing/team/team-page-store.ts delete mode 100644 src/renderer/src/components/billing/team/team-roles.test.ts delete mode 100644 src/renderer/src/components/billing/team/team-roster-rows.ts delete mode 100644 src/renderer/src/components/billing/team/team-seat-math.test.ts delete mode 100644 src/renderer/src/components/billing/team/team-seat-math.ts delete mode 100644 src/renderer/src/components/billing/team/use-team-actions.ts delete mode 100644 src/renderer/src/components/billing/team/use-team-delete.tsx delete mode 100644 src/renderer/src/components/billing/use-plan-billing-usage-history.test.tsx delete mode 100644 src/renderer/src/components/billing/use-plan-billing-usage-history.ts rename src/renderer/src/components/billing/{plans => }/use-plan-catalog.ts (94%) delete mode 100644 src/renderer/src/components/settings/enterprise/AuditLogScrollRegion.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/EnterpriseAuditLog.owner-name.test.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/EnterpriseAuditLog.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/EnterpriseSettingsPane.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/EnterpriseSettingsView.fixture.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/EnterpriseSettingsView.test.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/EnterpriseSettingsView.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/EnterpriseUpsell.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/enterprise-audit-account-copy.ts delete mode 100644 src/renderer/src/components/settings/enterprise/enterprise-audit-copy.ts delete mode 100644 src/renderer/src/components/settings/enterprise/enterprise-audit-sso-copy.ts delete mode 100644 src/renderer/src/components/settings/enterprise/enterprise-audit-workspace-copy.ts delete mode 100644 src/renderer/src/components/settings/enterprise/enterprise-audit.fixtures.ts delete mode 100644 src/renderer/src/components/settings/enterprise/sso/EnterpriseDirectorySync.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/sso/EnterpriseSsoDomains.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/sso/EnterpriseSsoView.fixture.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/sso/EnterpriseSsoView.test.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/sso/EnterpriseSsoView.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/sso/enterprise-sso-parts.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/sso/enterprise-sso.fixtures.ts delete mode 100644 src/renderer/src/components/settings/enterprise/sso/use-enterprise-sso.test.tsx delete mode 100644 src/renderer/src/components/settings/enterprise/sso/use-enterprise-sso.ts delete mode 100644 src/renderer/src/components/settings/enterprise/use-enterprise-audit-log.ts create mode 100644 src/renderer/src/components/settings/orca-cloud/CloudConsoleLinkRow.tsx delete mode 100644 src/renderer/src/components/settings/orca-cloud/OrcaAccountBillingPane.fixture.tsx create mode 100644 src/renderer/src/components/settings/orca-cloud/OrcaCloudConsoleLinks.tsx delete mode 100644 src/renderer/src/components/team-mfa/EnterpriseMfaPolicy.tsx delete mode 100644 src/renderer/src/components/team-mfa/RequireMfaRow.tsx delete mode 100644 src/renderer/src/lib/orca-cloud-after-checkout.test.ts delete mode 100644 src/renderer/src/lib/orca-cloud-after-checkout.ts create mode 100644 src/renderer/src/lib/orca-cloud/open-cloud-console.ts create mode 100644 src/shared/orca-cloud-console.ts delete mode 100644 src/shared/orca-org-delete.ts delete mode 100644 src/shared/orca-org-enterprise.ts delete mode 100644 src/shared/orca-org-management.test.ts delete mode 100644 src/shared/orca-org-management.ts diff --git a/src/main/billing/billing-client.test.ts b/src/main/billing/billing-client.test.ts index 9945e868426..0668aa56758 100644 --- a/src/main/billing/billing-client.test.ts +++ b/src/main/billing/billing-client.test.ts @@ -1,10 +1,8 @@ import { beforeEach, describe, expect, it } from 'vitest' import { OrcaCloudRequestError } from '../orca-profiles/cloud-auth/profile-cloud-client' import { - BillingServiceError, assertStripeHostedUrl, claimTrial, - createCheckoutUrl, createPortalUrl, BillingOrgMismatchError, fetchEntitlement, @@ -64,10 +62,13 @@ describe('billing client', () => { describe('EP-9: the token is for the team this device shows', () => { beforeEach(() => resetBillingExplicitOrgForTests()) - it('asks auth for this device\'s team explicitly and accepts a token for it', async () => { + it("asks auth for this device's team explicitly and accepts a token for it", async () => { const seen: Seen[] = [] const bt = jwt({ sub: 'u1', org: 'org_paid' }) - const fetchImpl = fakeFetch({ [endpoints.billingTokenEndpoint]: Response.json({ billingToken: bt, expiresAt: 1 }) }, seen) + const fetchImpl = fakeFetch( + { [endpoints.billingTokenEndpoint]: Response.json({ billingToken: bt, expiresAt: 1 }) }, + seen + ) expect(await mintBillingToken(endpoints, 'a', 'org_paid', fetchImpl)).toBe(bt) expect(seen[0]?.init?.body).toBe(JSON.stringify({ orgId: 'org_paid' })) }) @@ -75,15 +76,21 @@ describe('billing client', () => { it('refuses a token auth minted for another team (another device switched the shared active team)', async () => { const fetchImpl: typeof fetch = async () => Response.json({ billingToken: jwt({ sub: 'u1', org: 'org_eval' }), expiresAt: 1 }) - await expect(mintBillingToken(endpoints, 'a', 'org_paid', fetchImpl)).rejects.toBeInstanceOf(BillingOrgMismatchError) + await expect(mintBillingToken(endpoints, 'a', 'org_paid', fetchImpl)).rejects.toBeInstanceOf( + BillingOrgMismatchError + ) // A personal account never accepts a team token either. - await expect(mintBillingToken(endpoints, 'a', null, fetchImpl)).rejects.toBeInstanceOf(BillingOrgMismatchError) + await expect(mintBillingToken(endpoints, 'a', null, fetchImpl)).rejects.toBeInstanceOf( + BillingOrgMismatchError + ) }) it('treats 403 not_a_member as a team-switch error, not a session failure', async () => { const fetchImpl: typeof fetch = async () => new Response(JSON.stringify({ error: 'not_a_member' }), { status: 403 }) - await expect(mintBillingToken(endpoints, 'a', 'org_gone', fetchImpl)).rejects.toBeInstanceOf(BillingOrgMismatchError) + await expect(mintBillingToken(endpoints, 'a', 'org_gone', fetchImpl)).rejects.toBeInstanceOf( + BillingOrgMismatchError + ) }) it('falls back to the empty body on an older auth (400), still checking the claim', async () => { @@ -114,48 +121,6 @@ describe('billing client', () => { await expect(call).rejects.toBeInstanceOf(OrcaCloudRequestError) }) - it('reports billing refusals as BillingServiceError, never as a session failure', async () => { - const call = createCheckoutUrl( - endpoints, - 'bt', - { plan: 'team', interval: 'month', seats: 1 }, - fakeFetch({ - 'https://billing.example.test/v1/billing/checkout': Response.json( - { error: 'already_subscribed' }, - { status: 409 } - ) - }) - ) - await expect(call).rejects.toMatchObject({ - statusCode: 409, - errorCode: 'already_subscribed' - }) - await expect(call).rejects.toBeInstanceOf(BillingServiceError) - }) - - it('sends plan, interval and seats and returns the hosted Checkout URL', async () => { - const seen: Seen[] = [] - const url = await createCheckoutUrl( - endpoints, - 'bt', - { plan: 'team', interval: 'year', seats: 3 }, - fakeFetch( - { - 'https://billing.example.test/v1/billing/checkout': Response.json({ - url: 'https://checkout.stripe.com/c/pay/cs_test_1' - }) - }, - seen - ) - ) - expect(url).toBe('https://checkout.stripe.com/c/pay/cs_test_1') - expect(JSON.parse(String(seen[0]?.init?.body))).toEqual({ - plan: 'team', - interval: 'year', - seats: 3 - }) - }) - it('only opens Stripe-hosted pages', async () => { expect(assertStripeHostedUrl('https://billing.stripe.com/p/session/x')).toBe( 'https://billing.stripe.com/p/session/x' @@ -255,8 +220,13 @@ describe('billing client', () => { expect(unsafe.offers).toBeNull() // A portal cancel's end date (cancel_at) comes through; older services omit it. expect( - (await fetchEntitlement(endpoints, 'bt', response({ cancelAtPeriodEnd: true, cancelAt: 1797167516000 }))) - .cancelAt + ( + await fetchEntitlement( + endpoints, + 'bt', + response({ cancelAtPeriodEnd: true, cancelAt: 1797167516000 }) + ) + ).cancelAt ).toBe(1797167516000) expect((await fetchEntitlement(endpoints, 'bt', response({}))).cancelAt).toBeNull() // A plan this desktop doesn't know (a newer service) is still a plan, never "no plan". diff --git a/src/main/billing/billing-client.ts b/src/main/billing/billing-client.ts index c38521d3b35..08f14fee3ba 100644 --- a/src/main/billing/billing-client.ts +++ b/src/main/billing/billing-client.ts @@ -2,7 +2,6 @@ // then call the billing service with it. Pure (fetch injected) so it is testable without Electron. import { z } from 'zod' import type { - OrcaBillingCheckoutArgs, OrcaBillingEntitlement, OrcaBillingOverageArgs, OrcaBillingTeamPlan @@ -183,28 +182,6 @@ export async function fetchEntitlement( ) } -export async function createCheckoutUrl( - endpoints: BillingEndpoints, - token: string, - args: OrcaBillingCheckoutArgs, - fetchImpl: typeof fetch = fetch -): Promise { - const body = await billingRequest( - endpoints, - token, - 'POST', - 'v1/billing/checkout', - { - plan: args.plan, - interval: args.interval, - seats: args.seats, - ...(args.setupSessionId ? { setupSessionId: args.setupSessionId } : {}) - }, - fetchImpl - ) - return assertStripeHostedUrl(UrlBody.safeParse(body).data?.url) -} - export async function createPortalUrl( endpoints: BillingEndpoints, token: string, diff --git a/src/main/billing/billing-config.test.ts b/src/main/billing/billing-config.test.ts index de153033268..e0381009f68 100644 --- a/src/main/billing/billing-config.test.ts +++ b/src/main/billing/billing-config.test.ts @@ -3,10 +3,7 @@ import { describe, expect, it, vi } from 'vitest' vi.mock('electron', () => ({ app: { isPackaged: false } })) import { getBillingEndpoints } from './billing-config' -import { - billingCheckoutArgsFromUnknown, - billingOverageArgsFromUnknown -} from '../ipc/profiles/orca-profile-billing-handlers' +import { billingOverageArgsFromUnknown } from '../ipc/profiles/orca-profile-billing-handlers' const authConfig = { apiBaseUrl: 'https://login.onorca.dev' } @@ -32,29 +29,6 @@ describe('billing config', () => { }) describe('billing IPC args', () => { - it('accepts a catalog plan id with an interval and 1..500 seats', () => { - expect(billingCheckoutArgsFromUnknown({ plan: 'team', interval: 'year', seats: 5 })).toEqual({ - plan: 'team', - interval: 'year', - seats: 5 - }) - // Billing's catalog names the plans (billing decides what it sells); the shape is checked here. - expect(billingCheckoutArgsFromUnknown({ plan: 'pro', interval: 'month', seats: 1 }).plan).toBe( - 'pro' - ) - for (const bad of [ - { plan: 'Pro Plan', interval: 'month', seats: 1 }, - { plan: '', interval: 'month', seats: 1 }, - { plan: 'team', interval: 'week', seats: 1 }, - { plan: 'team', interval: 'month', seats: 0 }, - { plan: 'team', interval: 'month', seats: 501 }, - { plan: 'team', interval: 'month', seats: 1, extra: true }, - null - ]) { - expect(() => billingCheckoutArgsFromUnknown(bad)).toThrow('invalid_orca_billing_checkout') - } - }) - it('accepts overage toggles with an optional whole-cent cap', () => { expect(billingOverageArgsFromUnknown({ enabled: false })).toEqual({ enabled: false }) expect(billingOverageArgsFromUnknown({ enabled: true, spendCapCents: 5000 })).toEqual({ diff --git a/src/main/billing/billing-service-link.test.ts b/src/main/billing/billing-service-link.test.ts deleted file mode 100644 index 2313cace95d..00000000000 --- a/src/main/billing/billing-service-link.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { describe, expect, it, vi } from 'vitest' - -vi.mock('electron', () => ({ app: { isPackaged: false }, shell: { openExternal: vi.fn() } })) - -import { withSetupSessionFallback } from './billing-setup-session-fallback' -import type { OrcaBillingCheckoutArgs, OrcaBillingLinkResult } from '../../shared/orca-billing' - -const ARGS: OrcaBillingCheckoutArgs = { - plan: 'team', - interval: 'month', - seats: 3, - setupSessionId: 'cs_x' -} - -describe('checkout "Copy link" setup-session fallback', () => { - it('retries without the setup session when billing says it is for someone else', async () => { - const run = vi.fn(async (args: OrcaBillingCheckoutArgs): Promise => - args.setupSessionId - ? { status: 'failed', error: 'setup_session_mismatch' } - : { status: 'ok', url: 'https://checkout.stripe.com/c/pay/cs_live_1' } - ) - await expect(withSetupSessionFallback(ARGS, run)).resolves.toEqual({ - status: 'ok', - url: 'https://checkout.stripe.com/c/pay/cs_live_1' - }) - expect(run).toHaveBeenCalledTimes(2) - expect(run.mock.calls[1][0]).not.toHaveProperty('setupSessionId') - }) - - it('keeps any other refusal as it is', async () => { - const run = vi.fn(async (): Promise => ({ status: 'forbidden' })) - await expect(withSetupSessionFallback(ARGS, run)).resolves.toEqual({ status: 'forbidden' }) - expect(run).toHaveBeenCalledTimes(1) - }) -}) diff --git a/src/main/billing/billing-service.ts b/src/main/billing/billing-service.ts index 2b4f0befc56..20eb0af3dee 100644 --- a/src/main/billing/billing-service.ts +++ b/src/main/billing/billing-service.ts @@ -6,27 +6,23 @@ import { appendFile } from 'node:fs/promises' import { join } from 'node:path' import { app, shell } from 'electron' import type { - OrcaBillingCheckoutArgs, OrcaBillingLinkResult, OrcaBillingOpenResult, OrcaBillingOverageArgs, OrcaBillingOverageResult, OrcaBillingStatusResult, OrcaBillingTeamPlansResult, - OrcaBillingTrialClaimResult, - OrcaBillingUsageHistoryResult + OrcaBillingTrialClaimResult } from '../../shared/orca-billing' import type { OrcaPlanCatalogResult } from '../../shared/orca-billing-plans' import { loadPlanCatalog } from './plan-catalog-client' import { openResultForError } from './billing-open-result' -import { withSetupSessionFallback } from './billing-setup-session-fallback' import { getOrcaCloudAuthConfig } from '../orca-profiles/cloud-auth/profile-cloud-auth-config' import { runWithFreshOrcaCloudSession } from '../orca-profiles/cloud-session/profile-cloud-session-refresh' import { ensureActiveOrcaProfile } from '../orca-profiles/profile-index-store' import { BillingServiceError, claimTrial, - createCheckoutUrl, createPortalUrl, fetchEntitlement, fetchTeamPlans, @@ -35,7 +31,6 @@ import { type BillingEndpoints } from './billing-client' import { getBillingEndpoints } from './billing-config' -import { fetchUsageHistory } from './billing-usage-client' import { getBillingDevKeyFile, mintDevBillingToken } from './billing-dev-token' import { cleanCloudServiceUrl } from '../../shared/cloud-service-url' import { listOrcaProfileOrgMembers } from '../orca-profiles/cloud-org/profile-cloud-org-members-service' @@ -117,7 +112,11 @@ function prepare(userDataPath: string): Ready { // The team this device shows, from the same profile whose session this is (a local // profile switch mid-call must not pair one profile's session with another's team); // never auth's shared "active team" (EP-9). - await mintBillingToken(endpoints, session.accessToken, active.profile.cloud?.activeOrgId ?? null), + await mintBillingToken( + endpoints, + session.accessToken, + active.profile.cloud?.activeOrgId ?? null + ), endpoints ) ) @@ -187,25 +186,6 @@ export async function getOrcaBillingStatus(userDataPath: string): Promise { - const ready = prepare(userDataPath) - if (!ready.ok) { - return { status: ready.status } - } - try { - const history = await ready.run((token, endpoints) => - fetchUsageHistory(endpoints, token, utcOffsetMinutes) - ) - return history === 'signed-out' ? { status: 'signed-out' } : { status: 'ok', history } - } catch (error) { - return { status: 'failed', error: message(error) } - } -} - /** Plan state for other teams the signed-in user is on (cloud start B2); never switches teams. */ export async function getOrcaBillingTeamPlans( userDataPath: string, @@ -268,17 +248,6 @@ async function openHosted( } } -export function openOrcaBillingCheckout( - userDataPath: string, - args: OrcaBillingCheckoutArgs -): Promise { - return withSetupSessionFallback(args, (checkoutArgs) => - openHosted(userDataPath, (token, endpoints) => - createCheckoutUrl(endpoints, token, checkoutArgs) - ) - ) -} - export function openOrcaBillingPortal(userDataPath: string): Promise { return openHosted(userDataPath, (token, endpoints) => createPortalUrl(endpoints, token)) } diff --git a/src/main/billing/billing-setup-session-fallback.ts b/src/main/billing/billing-setup-session-fallback.ts deleted file mode 100644 index d29a0244a09..00000000000 --- a/src/main/billing/billing-setup-session-fallback.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { OrcaBillingCheckoutArgs } from '../../shared/orca-billing' - -/** A setup session for another team or user (or an expired one) must not block buying. */ -export async function withSetupSessionFallback( - args: OrcaBillingCheckoutArgs, - run: (args: OrcaBillingCheckoutArgs) => Promise -): Promise { - const result = await run(args) - if ( - args.setupSessionId && - result.status === 'failed' && - /setup_session_mismatch/.test(result.error ?? '') - ) { - const { setupSessionId: _dropped, ...plain } = args - return run(plain) - } - return result -} diff --git a/src/main/billing/billing-usage-client.test.ts b/src/main/billing/billing-usage-client.test.ts deleted file mode 100644 index 342838d7cb7..00000000000 --- a/src/main/billing/billing-usage-client.test.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { fetchUsageHistory } from './billing-usage-client' - -const endpoints = { - billingApiUrl: 'https://billing.example.test', - billingTokenEndpoint: 'https://login.example.test/v1/desktop/auth/billing-token' -} - -type Seen = { url: string; init: RequestInit | undefined } - -function fakeFetch(responses: Record, seen: Seen[] = []): typeof fetch { - return async (input, init) => { - const url = String(input) - seen.push({ url, init }) - const response = responses[url] - if (!response) { - throw new Error(`unexpected ${url}`) - } - return response - } -} - -describe('fetchUsageHistory', () => { - const url = 'https://billing.example.test/v1/billing/usage?utcOffset=-480' - const body = { - days: [{ start: 1, seconds: 3600 }], - totalSeconds: 3600, - yourSeconds: 1800, - members: { top: [{ userId: 'u1', seconds: 3600 }], otherCount: 0, otherSeconds: 0 }, - sandboxes: { top: [{ sandboxId: 'sbx_1', seconds: 3600 }], otherCount: 0, otherSeconds: 0 } - } - - it('sends the local offset and maps both breakdowns to one row shape', async () => { - const seen: Seen[] = [] - const history = await fetchUsageHistory( - endpoints, - 'bt', - -480, - fakeFetch({ [url]: Response.json(body) }, seen) - ) - expect(seen[0]!.init?.method).toBe('GET') - expect(history.members).toEqual({ - top: [{ id: 'u1', seconds: 3600 }], - otherCount: 0, - otherSeconds: 0 - }) - expect(history.sandboxes?.top).toEqual([{ id: 'sbx_1', seconds: 3600 }]) - }) - - it('accepts a member’s view and rejects malformed rows', async () => { - const member = await fetchUsageHistory( - endpoints, - 'bt', - -480, - fakeFetch({ [url]: Response.json({ ...body, members: null, sandboxes: null }) }) - ) - expect(member.members).toBeNull() - await expect( - fetchUsageHistory( - endpoints, - 'bt', - -480, - fakeFetch({ - [url]: Response.json({ - ...body, - members: { top: [{ userId: '