Files
orca/src/main/orca-profiles/profile-cloud-dev-auth.ts
T
693ac1fb25 fix(browser): import Chromium cookies from Network DBs (#6875) (#7882)
* fix(browser): import Chromium cookies from Network DBs (#6875)

* fix(browser): complete Chromium cookie import paths

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
2026-07-09 22:12:04 -07:00

68 lines
2.0 KiB
TypeScript

import { randomUUID } from 'node:crypto'
import type { OrcaCloudCapabilities, OrcaCloudOrgSummary } from '../../shared/orca-profiles'
import type { OrcaCloudSessionExchangeResponse } from './profile-cloud-session-exchange'
const DEV_SESSION_TTL_MS = 7 * 24 * 60 * 60 * 1000
function cleanEnvString(value: string | undefined, fallback: string): string {
const trimmed = value?.trim()
return trimmed || fallback
}
function defaultDevOrganizations(): OrcaCloudOrgSummary[] {
return [
{ orgId: 'dev-personal', name: 'Personal', role: 'Owner' },
{ orgId: 'dev-acme', name: 'Acme Dev', role: 'Admin' }
]
}
function devCapabilities(): OrcaCloudCapabilities {
return {
flags: {
share: true,
team: true,
'share.create': true,
'share.manage': true,
'relay.use': true,
'team.member': true,
'enterprise.sso': true
},
refreshedAt: Date.now()
}
}
function devToken(prefix: string): string {
return `${prefix}-${randomUUID()}`
}
export function createDevOrcaCloudSession(
args: {
localProfileId?: string
cloudProfileId?: string
orgId?: string
} = {}
): OrcaCloudSessionExchangeResponse {
const organizations = defaultDevOrganizations()
const selectedOrg = organizations.find((organization) => organization.orgId === args.orgId)
const cloudProfileId =
args.cloudProfileId ??
(args.localProfileId ? `dev-cloud-${args.localProfileId}` : `dev-cloud-${randomUUID()}`)
return {
accessToken: devToken('dev-access'),
refreshToken: devToken('dev-refresh'),
expiresAt: Date.now() + DEV_SESSION_TTL_MS,
cloud: {
cloudProfileId,
userId: cleanEnvString(process.env.ORCA_CLOUD_DEV_USER_ID, 'dev-user'),
email: cleanEnvString(process.env.ORCA_CLOUD_DEV_EMAIL, 'dev@orca.local'),
displayName: cleanEnvString(process.env.ORCA_CLOUD_DEV_DISPLAY_NAME, 'Orca Dev'),
activeOrgId: selectedOrg?.orgId,
activeOrgName: selectedOrg?.name,
linkedAt: Date.now()
},
organizations,
capabilities: devCapabilities()
}
}