@@ -21,6 +21,10 @@ export const CLOUD_CONFIG_API_ENDPOINT =
2121 process . env . NEXT_PUBLIC_CLOUD_CONFIG_API_ENDPOINT ||
2222 "http://localhost:3001/api" ;
2323
24+ export const CLOUD_CONFIG_ORG_ID =
25+ process . env . NEXT_PUBLIC_CLOUD_CONFIG_ORG_ID ||
26+ "Missing NEXT_PUBLIC_CLOUD_CONFIG_ORG_ID in .env" ;
27+
2428const couldConfigSecretClient =
2529 process . env . NEXT_PUBLIC_CLOUD_CONFIG_CLIENT_ENCRYPT_SECRET ;
2630
@@ -135,14 +139,14 @@ export const getCloudConfig = <T>({
135139 return config . value as T ;
136140} ;
137141
138- export const fetchCloudConfig = async ( {
139- orgId,
142+ export const fetchAllConfigs = async ( {
143+ orgId = CLOUD_CONFIG_ORG_ID ,
140144 serverSide = false ,
141145 accessToken,
142146 cache = "default" ,
143147 apiPrefix = CLOUD_CONFIG_API_ENDPOINT ,
144148} : {
145- orgId : string ;
149+ orgId ? : string ;
146150 serverSide ?: boolean ;
147151 accessToken ?: string ;
148152 cache ?: RequestCache ;
@@ -167,26 +171,28 @@ export const fetchCloudConfig = async ({
167171 cache : cache ,
168172 } ) ;
169173 if ( ! response . ok ) {
170- console . log ( "🚀 Debug fetchCloudConfig requestData:" , requestData ) ;
174+ console . log ( "🚀 Debug fetchAllConfigs requestData:" , requestData ) ;
171175
172176 throw new Error (
173- `😢 fetchCloudConfig failed: ${ response . status } /${ response . statusText } - ${ apiEndpoint } `
177+ `😢 fetchAllConfigs failed: ${ response . status } /${ response . statusText } - ${ apiEndpoint } `
174178 ) ;
175179 }
176180 const duration = Date . now ( ) - startTime ;
177181
178182 console . log (
179- `fetchCloudConfig in ${ ( duration / 1000 ) . toFixed ( 2 ) } seconds ${
183+ `fetchAllConfigs in ${ ( duration / 1000 ) . toFixed ( 2 ) } seconds ${
180184 duration > 2000 ? "💔" : "-"
181185 } ${ apiEndpoint } `
182186 ) ;
183187
184- return ( await response . json ( ) ) as CloudConfigData [ ] ;
188+ const configs = ( ( await response . json ( ) ) || [ ] ) as CloudConfigData [ ] ;
189+
190+ return parseAllConfigs ( configs , serverSide ) ;
185191 } catch ( error ) {
186- console . log ( "💔💔💔 fetchCloudConfig error:" , error ) ;
192+ console . log ( "💔💔💔 fetchAllConfigs error:" , error ) ;
187193 }
188194
189- return null ;
195+ return [ ] ;
190196} ;
191197
192198export default {
@@ -198,5 +204,5 @@ export default {
198204 parseSingleConfig,
199205 parseAllConfigs,
200206 getCloudConfig,
201- fetchCloudConfig ,
207+ fetchAllConfigs ,
202208} ;
0 commit comments