@@ -7,7 +7,12 @@ import {
77 MOCK_DEFAULT_TEMPLATES_DATA ,
88 MOCK_TEMPLATES_DATA ,
99} from '@/configs/mock-data'
10- import type { DefaultTemplate , Template } from '@/core/modules/templates/models'
10+ import type {
11+ DefaultTemplate ,
12+ ListTeamTemplatesOptions ,
13+ ListTeamTemplatesResult ,
14+ Template ,
15+ } from '@/core/modules/templates/models'
1116import {
1217 type AuthUserEmailResolver ,
1318 getAuthUserEmailsById ,
@@ -30,6 +35,9 @@ type TemplatesRepositoryDeps = {
3035
3136export interface TeamTemplatesRepository {
3237 getTeamTemplates ( ) : Promise < RepoResult < { templates : Template [ ] } > >
38+ listTeamTemplates (
39+ options : ListTeamTemplatesOptions
40+ ) : Promise < RepoResult < ListTeamTemplatesResult > >
3341 deleteTemplate ( templateId : string ) : Promise < RepoResult < { success : true } > >
3442 updateTemplateVisibility (
3543 templateId : string ,
@@ -87,6 +95,62 @@ export function createTemplatesRepository(
8795 ) ,
8896 } )
8997 } ,
98+ async listTeamTemplates ( options ) {
99+ if ( USE_MOCK_DATA ) {
100+ return ok ( { data : MOCK_TEMPLATES_DATA , nextCursor : null } )
101+ }
102+
103+ const res = await deps . apiClient . GET ( '/templates' , {
104+ params : {
105+ query : options ,
106+ } ,
107+ headers : {
108+ ...deps . authHeaders ( scope . accessToken , scope . teamId ) ,
109+ } ,
110+ } )
111+
112+ if ( ! res . response . ok || res . error ) {
113+ return err (
114+ repoErrorFromHttp (
115+ res . response . status ,
116+ res . error ?. message ?? 'Failed to fetch templates' ,
117+ res . error
118+ )
119+ )
120+ }
121+
122+ if ( ! res . data ?. data ?. length ) {
123+ return ok ( { data : [ ] , nextCursor : res . data ?. nextCursor ?? null } )
124+ }
125+
126+ const data = res . data . data . map ( ( t ) : Template | DefaultTemplate => ( {
127+ templateID : t . templateID ,
128+ buildID : t . buildID ,
129+ cpuCount : t . cpuCount ,
130+ memoryMB : t . memoryMB ,
131+ diskSizeMB : t . diskSizeMB ?? 0 ,
132+ public : t . public ,
133+ aliases : t . aliases ,
134+ names : t . names ,
135+ createdAt : t . createdAt ,
136+ updatedAt : t . updatedAt ,
137+ // Email resolution is deferred while the Supabase auth migration is
138+ // in progress; the endpoint returns only the creator id for now.
139+ createdBy : t . createdBy
140+ ? { id : t . createdBy . id , email : t . createdBy . email ?? '' }
141+ : null ,
142+ lastSpawnedAt : t . lastSpawnedAt ?? null ,
143+ spawnCount : t . spawnCount ,
144+ buildCount : t . buildCount ,
145+ envdVersion : t . envdVersion ?? '' ,
146+ ...( t . isDefault && {
147+ isDefault : true as const ,
148+ defaultDescription : t . defaultDescription ?? undefined ,
149+ } ) ,
150+ } ) )
151+
152+ return ok ( { data, nextCursor : res . data . nextCursor ?? null } )
153+ } ,
90154 async deleteTemplate ( templateId ) {
91155 const res = await deps . infraClient . DELETE ( '/templates/{templateID}' , {
92156 params : {
0 commit comments