@@ -49,13 +49,10 @@ function createEntityHandler(
4949 entityName : string
5050) : EntityHandler {
5151 const baseURL = `/apps/${ appId } /entities/${ entityName } ` ;
52- const isDevMode = new URLSearchParams ( window . location . search ) . get ( "use_dev_table" ) === "true" ;
53-
54- axios . interceptors . request . use ( ( config ) => {
55- config . headers = config . headers ?? { } ;
56- config . headers [ "X-Dev-Mode" ] = String ( isDevMode ) ;
57- return config ;
58- } ) ;
52+ const isDevMode = typeof window !== "undefined"
53+ ? new URLSearchParams ( window . location . search ) . get ( "use_dev_table" ) === "true"
54+ : false ;
55+ const headers = { "X-Use-Dev-Table" : String ( isDevMode ) } ;
5956
6057 return {
6158 // List entities with optional pagination and sorting
@@ -67,7 +64,7 @@ function createEntityHandler(
6764 if ( fields )
6865 params . fields = Array . isArray ( fields ) ? fields . join ( "," ) : fields ;
6966
70- return axios . get ( baseURL , { params } ) ;
67+ return axios . get ( baseURL , { params, headers } ) ;
7168 } ,
7269
7370 // Filter entities based on query
@@ -88,37 +85,37 @@ function createEntityHandler(
8885 if ( fields )
8986 params . fields = Array . isArray ( fields ) ? fields . join ( "," ) : fields ;
9087
91- return axios . get ( baseURL , { params } ) ;
88+ return axios . get ( baseURL , { params, headers } ) ;
9289 } ,
9390
9491 // Get entity by ID
9592 async get ( id : string ) {
96- return axios . get ( `${ baseURL } /${ id } ` ) ;
93+ return axios . get ( `${ baseURL } /${ id } ` , { headers } ) ;
9794 } ,
9895
9996 // Create new entity
10097 async create ( data : Record < string , any > ) {
101- return axios . post ( baseURL , data ) ;
98+ return axios . post ( baseURL , data , { headers } ) ;
10299 } ,
103100
104101 // Update entity by ID
105102 async update ( id : string , data : Record < string , any > ) {
106- return axios . put ( `${ baseURL } /${ id } ` , data ) ;
103+ return axios . put ( `${ baseURL } /${ id } ` , data , { headers } ) ;
107104 } ,
108105
109106 // Delete entity by ID
110107 async delete ( id : string ) {
111- return axios . delete ( `${ baseURL } /${ id } ` ) ;
108+ return axios . delete ( `${ baseURL } /${ id } ` , { headers } ) ;
112109 } ,
113110
114111 // Delete multiple entities based on query
115112 async deleteMany ( query : Record < string , any > ) {
116- return axios . delete ( baseURL , { data : query } ) ;
113+ return axios . delete ( baseURL , { data : query , headers } ) ;
117114 } ,
118115
119116 // Create multiple entities in a single request
120117 async bulkCreate ( data : Record < string , any > [ ] ) {
121- return axios . post ( `${ baseURL } /bulk` , data ) ;
118+ return axios . post ( `${ baseURL } /bulk` , data , { headers } ) ;
122119 } ,
123120
124121 // Import entities from a file
@@ -128,6 +125,7 @@ function createEntityHandler(
128125
129126 return axios . post ( `${ baseURL } /import` , formData , {
130127 headers : {
128+ ...headers ,
131129 "Content-Type" : "multipart/form-data" ,
132130 } ,
133131 } ) ;
0 commit comments