1- import { Effect } from "effect"
2-
3- import { request } from "./api-http.js"
4- import { asObject , type JsonRequest , type JsonValue } from "./api-json.js"
5- import { decodeProjectDetails } from "./api-project-codec.js"
6- import type { CreateCommand } from "./frontend-lib/core/domain.js"
1+ import type { JsonRequest } from "./api-json.js"
2+ import { type CreateCommand , defaultTemplateConfig } from "./frontend-lib/core/domain.js"
73
84type ResolvedCreateRequestPaths = {
95 readonly authorizedKeysPath : string
106 readonly authorizedKeysContents ?: string | undefined
117}
128
13- const projectPath = ( projectId : string , suffix = "" ) : string => `/projects/${ encodeURIComponent ( projectId ) } ${ suffix } `
14-
15- export const decodeProjectResponse = ( payload : JsonValue ) => {
16- const object = asObject ( payload )
17- return object === null
18- ? decodeProjectDetails ( payload )
19- : decodeProjectDetails ( object [ "project" ] ?? payload )
20- }
21-
22- export const createProjectRequestNeedsFollowUpUp = (
23- command : CreateCommand ,
24- resolvedPaths : ResolvedCreateRequestPaths
25- ) : boolean => command . runUp && resolvedPaths . authorizedKeysContents !== undefined
26-
27- export const createProjectRequestAllowsImmediateUp = (
28- command : CreateCommand ,
29- resolvedPaths : ResolvedCreateRequestPaths
30- ) : boolean => command . runUp && resolvedPaths . authorizedKeysContents === undefined
31-
329export const buildCreateProjectRequest = (
3310 command : CreateCommand ,
34- resolvedPaths : ResolvedCreateRequestPaths ,
35- shouldRunUpInCreateRequest : boolean
11+ resolvedPaths : ResolvedCreateRequestPaths
3612) => {
3713 const config = command . config
3814 return {
@@ -44,7 +20,9 @@ export const buildCreateProjectRequest = (
4420 containerName : config . containerName ,
4521 serviceName : config . serviceName ,
4622 volumeName : config . volumeName ,
47- authorizedKeysPath : resolvedPaths . authorizedKeysPath ,
23+ authorizedKeysPath : resolvedPaths . authorizedKeysContents === undefined
24+ ? resolvedPaths . authorizedKeysPath
25+ : defaultTemplateConfig . authorizedKeysPath ,
4826 authorizedKeysContents : resolvedPaths . authorizedKeysContents ,
4927 envGlobalPath : config . envGlobalPath ,
5028 envProjectPath : config . envProjectPath ,
@@ -62,21 +40,10 @@ export const buildCreateProjectRequest = (
6240 codexTokenLabel : config . codexAuthLabel ,
6341 claudeTokenLabel : config . claudeAuthLabel ,
6442 agentAutoMode : config . agentAuto ? ( config . agentMode ?? "auto" ) : undefined ,
65- up : shouldRunUpInCreateRequest ,
43+ up : command . runUp ,
6644 openSsh : false ,
6745 force : command . force ,
6846 forceEnv : command . forceEnv ,
6947 waitForClone : command . waitForClone
7048 } satisfies JsonRequest
7149}
72-
73- export const upCreatedProjectWithAuthorizedKeys = (
74- projectId : string ,
75- authorizedKeysContents : string
76- ) =>
77- request ( "POST" , projectPath ( projectId , "/up" ) , {
78- authorizedKeysContents,
79- useManagedAuthorizedKeys : true
80- } ) . pipe (
81- Effect . map ( ( payload ) => decodeProjectResponse ( payload ) )
82- )
0 commit comments