@@ -22,33 +22,31 @@ const hybridApiVersion = '2024-02-02-preview';
22
22
const consumptionApiVersion = '2019-05-01' ;
23
23
24
24
export const useConnectionsData = ( appId ?: string ) => {
25
- return useQuery (
26
- [ 'getConnectionsData' , appId ] ,
27
- async ( ) => {
28
- const uri = `${ baseUrl } /${ appId } /workflowsconfiguration/connections?api-version=2018-11-01` ;
29
- try {
30
- const response = await axios . get ( uri , {
31
- headers : {
32
- Authorization : `Bearer ${ environment . armToken } ` ,
33
- } ,
34
- } ) ;
35
- const { files, health } = response . data . properties ;
36
- if ( equals ( health . state , 'healthy' ) ) {
37
- return files [ 'connections.json' ] ;
38
- }
39
- const { error } = health ;
40
- throw new Error ( error . message ) ;
41
- } catch {
42
- return { } ;
43
- }
44
- } ,
45
- {
46
- enabled : ! ! appId ,
47
- refetchOnMount : false ,
48
- refetchOnReconnect : false ,
49
- refetchOnWindowFocus : false ,
25
+ return useQuery ( [ 'getConnectionsData' , appId ] , async ( ) => getConnectionsData ( appId as string ) , {
26
+ enabled : ! ! appId ,
27
+ refetchOnMount : false ,
28
+ refetchOnReconnect : false ,
29
+ refetchOnWindowFocus : false ,
30
+ } ) ;
31
+ } ;
32
+
33
+ export const getConnectionsData = async ( appId : string ) : Promise < ConnectionsData > => {
34
+ const uri = `${ baseUrl } /${ appId } /workflowsconfiguration/connections?api-version=2018-11-01` ;
35
+ try {
36
+ const response = await axios . get ( uri , {
37
+ headers : {
38
+ Authorization : `Bearer ${ environment . armToken } ` ,
39
+ } ,
40
+ } ) ;
41
+ const { files, health } = response . data . properties ;
42
+ if ( equals ( health . state , 'healthy' ) ) {
43
+ return files [ 'connections.json' ] ;
50
44
}
51
- ) ;
45
+ const { error } = health ;
46
+ throw new Error ( error . message ) ;
47
+ } catch {
48
+ return { } ;
49
+ }
52
50
} ;
53
51
54
52
export const useWorkflowAndArtifactsStandard = ( workflowId : string ) => {
@@ -293,66 +291,67 @@ export const listCallbackUrl = async (
293
291
} ;
294
292
295
293
export const useWorkflowApp = ( siteResourceId : string , hostingPlan : HostingPlanTypes ) => {
296
- return useQuery (
297
- [ 'workflowApp' , siteResourceId ] ,
298
- async ( ) => {
299
- const apiVersions = {
300
- consumption : '2016-10-01' ,
301
- standard : '2018-11-01' ,
302
- hybrid : '2023-11-02-preview' ,
303
- } ;
304
- const uri = `${ baseUrl } ${ siteResourceId } ?api-version=${ apiVersions [ hostingPlan ] || '2018-11-01' } ` ;
305
- const response = await axios . get ( uri , {
306
- headers : {
307
- Authorization : `Bearer ${ environment . armToken } ` ,
308
- } ,
309
- } ) ;
294
+ return useQuery ( [ 'workflowApp' , siteResourceId ] , async ( ) => getWorkflowApp ( siteResourceId , hostingPlan ) , {
295
+ refetchOnMount : false ,
296
+ refetchOnReconnect : false ,
297
+ refetchOnWindowFocus : false ,
298
+ } ) ;
299
+ } ;
310
300
311
- return response . data ;
301
+ export const getWorkflowAppFromCache = async ( siteResourceId : string , hostingPlan : HostingPlanTypes ) => {
302
+ const queryClient = getReactQueryClient ( ) ;
303
+ return queryClient . fetchQuery ( [ 'workflowApp' , siteResourceId ] , async ( ) => getWorkflowApp ( siteResourceId , hostingPlan ) ) ;
304
+ } ;
305
+
306
+ const getWorkflowApp = async ( siteResourceId : string , hostingPlan : HostingPlanTypes ) => {
307
+ const apiVersions = {
308
+ consumption : '2016-10-01' ,
309
+ standard : '2018-11-01' ,
310
+ hybrid : '2023-11-02-preview' ,
311
+ } ;
312
+ const uri = `${ baseUrl } ${ siteResourceId } ?api-version=${ apiVersions [ hostingPlan ] || '2018-11-01' } ` ;
313
+ const response = await axios . get ( uri , {
314
+ headers : {
315
+ Authorization : `Bearer ${ environment . armToken } ` ,
312
316
} ,
313
- {
314
- refetchOnMount : false ,
315
- refetchOnReconnect : false ,
316
- refetchOnWindowFocus : false ,
317
- }
318
- ) ;
317
+ } ) ;
318
+
319
+ return response . data ;
319
320
} ;
320
321
321
322
export const useAppSettings = ( siteResourceId : string ) => {
322
- return useQuery (
323
- [ 'appSettings' , siteResourceId ] ,
324
- async ( ) => {
325
- if ( HybridAppUtility . isHybridLogicApp ( siteResourceId ) ) {
326
- const containerAppInfo = (
327
- await axios . get ( `${ baseUrl } ${ siteResourceId } ?api-version=2024-02-02-preview` , {
328
- headers : {
329
- Authorization : `Bearer ${ environment . armToken } ` ,
330
- } ,
331
- } )
332
- ) . data ;
333
- containerAppInfo . properties = containerAppInfo . properties . template . containers [ 0 ] . env ;
334
- containerAppInfo . properties = containerAppInfo . properties . reduce ( ( acc : any , cur : any ) => {
335
- acc [ cur . name ] = cur . value ;
336
- return acc ;
337
- } , { } ) ;
338
- return containerAppInfo ;
339
- }
323
+ return useQuery ( [ 'appSettings' , siteResourceId ] , async ( ) => getAppSettings ( siteResourceId ) , {
324
+ refetchOnMount : false ,
325
+ refetchOnReconnect : false ,
326
+ refetchOnWindowFocus : false ,
327
+ } ) ;
328
+ } ;
340
329
341
- const uri = `${ baseUrl } ${ siteResourceId } /config/appsettings/list?api-version=2018-11-01` ;
342
- return (
343
- await axios . post ( uri , null , {
344
- headers : {
345
- Authorization : `Bearer ${ environment . armToken } ` ,
346
- } ,
347
- } )
348
- ) . data ;
349
- } ,
350
- {
351
- refetchOnMount : false ,
352
- refetchOnReconnect : false ,
353
- refetchOnWindowFocus : false ,
354
- }
355
- ) ;
330
+ export const getAppSettings = async ( siteResourceId : string ) => {
331
+ if ( HybridAppUtility . isHybridLogicApp ( siteResourceId ) ) {
332
+ const containerAppInfo = (
333
+ await axios . get ( `${ baseUrl } ${ siteResourceId } ?api-version=2024-02-02-preview` , {
334
+ headers : {
335
+ Authorization : `Bearer ${ environment . armToken } ` ,
336
+ } ,
337
+ } )
338
+ ) . data ;
339
+ containerAppInfo . properties = containerAppInfo . properties . template . containers [ 0 ] . env ;
340
+ containerAppInfo . properties = containerAppInfo . properties . reduce ( ( acc : any , cur : any ) => {
341
+ acc [ cur . name ] = cur . value ;
342
+ return acc ;
343
+ } , { } ) ;
344
+ return containerAppInfo ;
345
+ }
346
+
347
+ const uri = `${ baseUrl } ${ siteResourceId } /config/appsettings/list?api-version=2018-11-01` ;
348
+ return (
349
+ await axios . post ( uri , null , {
350
+ headers : {
351
+ Authorization : `Bearer ${ environment . armToken } ` ,
352
+ } ,
353
+ } )
354
+ ) . data ;
356
355
} ;
357
356
358
357
export const useCurrentTenantId = ( ) => {
0 commit comments