@@ -9,9 +9,24 @@ import { assetsFromFilesList, syncSite } from './sync'
9
9
import { defaultDocsJsonComments } from 'docs-website/src/lib/docs-json-examples'
10
10
import { DocsJsonType } from 'docs-website/src/lib/docs-json'
11
11
import { CloudflareClient , getZoneIdForDomain } from './cloudflare'
12
- import { filesSchema } from './spiceflow'
12
+
13
13
import { client as searchApi } from 'docs-website/src/lib/search-api'
14
14
15
+ // Export schemas for reuse
16
+ export const filesSchema = z . array (
17
+ z . object ( {
18
+ relativePath : z . string ( ) ,
19
+ contents : z . string ( ) ,
20
+ downloadUrl : z . string ( ) . optional ( ) ,
21
+ metadata : z
22
+ . object ( {
23
+ width : z . number ( ) . optional ( ) ,
24
+ height : z . number ( ) . optional ( ) ,
25
+ } )
26
+ . optional ( ) ,
27
+ } ) ,
28
+ )
29
+
15
30
export const publicApiApp = new Spiceflow ( { basePath : '/api/v1' } )
16
31
. state ( 'apiKey' , '' )
17
32
. state ( 'userId' , '' )
@@ -20,7 +35,7 @@ export const publicApiApp = new Spiceflow({ basePath: '/api/v1' })
20
35
. use ( openapi ( ) )
21
36
. use ( async ( { request, state } , next ) => {
22
37
const apiKey = request . headers . get ( 'x-api-key' )
23
-
38
+
24
39
if ( ! apiKey ) {
25
40
return new Response ( JSON . stringify ( { error : 'API key required' } ) , {
26
41
status : 401 ,
@@ -76,7 +91,7 @@ export const publicApiApp = new Spiceflow({ basePath: '/api/v1' })
76
91
async handler ( { request, state } ) {
77
92
const body = await request . json ( )
78
93
const { name, orgId, files, githubOwner, githubRepo, githubRepoId, githubBranch, githubFolder } = body
79
-
94
+
80
95
const userOrgAccess = await prisma . orgsUsers . findFirst ( {
81
96
where : {
82
97
userId : state . userId ,
@@ -555,18 +570,18 @@ export const publicApiApp = new Spiceflow({ basePath: '/api/v1' })
555
570
} )
556
571
. onError ( ( { error, request } ) => {
557
572
notifyError ( error , `Public API error: ${ request . method } ${ request . url } ` )
558
-
573
+
559
574
if ( error instanceof AppError ) {
560
575
return new Response ( JSON . stringify ( { error : error . message } ) , {
561
576
status : 400 ,
562
577
headers : { 'Content-Type' : 'application/json' }
563
578
} )
564
579
}
565
-
580
+
566
581
return new Response ( JSON . stringify ( { error : 'Internal server error' } ) , {
567
582
status : 500 ,
568
583
headers : { 'Content-Type' : 'application/json' }
569
584
} )
570
585
} )
571
586
572
- export type PublicApiApp = typeof publicApiApp
587
+ export type PublicApiApp = typeof publicApiApp
0 commit comments