@@ -12,9 +12,12 @@ import { useQuery } from '@tanstack/react-query';
12
12
import { isSuccessResponse } from './HttpClient' ;
13
13
import { fetchFileData , fetchFilesFromFolder } from './vfsService' ;
14
14
import type { CustomCodeFileNameMapping } from '@microsoft/logic-apps-designer' ;
15
+ import { HybridAppUtility } from '../Utilities/HybridAppUtilities' ;
16
+ import type { HostingPlanTypes } from '../../../state/workflowLoadingSlice' ;
15
17
16
18
const baseUrl = 'https://management.azure.com' ;
17
19
const standardApiVersion = '2020-06-01' ;
20
+ const hybridApiVersion = '2024-02-02-preview' ;
18
21
const consumptionApiVersion = '2019-05-01' ;
19
22
20
23
export const useConnectionsData = ( appId ?: string ) => {
@@ -52,10 +55,13 @@ export const useWorkflowAndArtifactsStandard = (workflowId: string) => {
52
55
[ 'workflowArtifactsStandard' , workflowId ] ,
53
56
async ( ) => {
54
57
const artifacts = [ Artifact . ConnectionsFile , Artifact . ParametersFile ] ;
55
- const uri = `${ baseUrl } ${ validateResourceId ( workflowId ) } ?api-version=${ standardApiVersion } &$expand=${ artifacts . join ( ',' ) } ` ;
58
+ const uri = `${ baseUrl } ${ validateResourceId ( workflowId ) } ?api-version=${
59
+ HybridAppUtility . isHybridLogicApp ( workflowId ) ? hybridApiVersion : standardApiVersion
60
+ } &$expand=${ artifacts . join ( ',' ) } `;
56
61
const response = await axios . get ( uri , {
57
62
headers : {
58
63
Authorization : `Bearer ${ environment . armToken } ` ,
64
+ 'if-match' : '*' ,
59
65
} ,
60
66
} ) ;
61
67
@@ -69,13 +75,17 @@ export const useWorkflowAndArtifactsStandard = (workflowId: string) => {
69
75
) ;
70
76
} ;
71
77
72
- export const useAllCustomCodeFiles = ( appId ?: string , workflowName ?: string ) => {
73
- return useQuery ( [ 'workflowCustomCode' , appId , workflowName ] , async ( ) => await getAllCustomCodeFiles ( appId , workflowName ) , {
74
- enabled : ! ! appId && ! ! workflowName ,
75
- refetchOnMount : false ,
76
- refetchOnReconnect : false ,
77
- refetchOnWindowFocus : false ,
78
- } ) ;
78
+ export const useAllCustomCodeFiles = ( appId ?: string , workflowName ?: string , isHybridLogicApp ?: boolean ) => {
79
+ return useQuery (
80
+ [ 'workflowCustomCode' , appId , workflowName ] ,
81
+ async ( ) => await getAllCustomCodeFiles ( appId , workflowName , isHybridLogicApp ) ,
82
+ {
83
+ enabled : ! ! appId && ! ! workflowName ,
84
+ refetchOnMount : false ,
85
+ refetchOnReconnect : false ,
86
+ refetchOnWindowFocus : false ,
87
+ }
88
+ ) ;
79
89
} ;
80
90
81
91
interface HostJSON {
@@ -127,7 +137,14 @@ export const getCustomCodeAppFiles = async (
127
137
return appFiles ;
128
138
} ;
129
139
130
- const getAllCustomCodeFiles = async ( appId ?: string , workflowName ?: string ) : Promise < Record < string , string > > => {
140
+ const getAllCustomCodeFiles = async (
141
+ appId ?: string ,
142
+ workflowName ?: string ,
143
+ isHybridLogicApp ?: boolean
144
+ ) : Promise < Record < string , string > > => {
145
+ if ( isHybridLogicApp ) {
146
+ return { } ;
147
+ }
131
148
const customCodeFiles : Record < string , string > = { } ;
132
149
const uri = `${ baseUrl } ${ appId } /hostruntime/admin/vfs/${ workflowName } ` ;
133
150
const vfsObjects : VFSObject [ ] = ( await fetchFilesFromFolder ( uri ) ) . filter ( ( file ) => file . name !== Artifact . WorkflowFile ) ;
@@ -173,6 +190,19 @@ export const useRunInstanceStandard = (
173
190
return useQuery (
174
191
[ 'getRunInstance' , appId , workflowName , runId ] ,
175
192
async ( ) => {
193
+ if ( ! appId ) {
194
+ return ;
195
+ }
196
+ if ( HybridAppUtility . isHybridLogicApp ( appId ) ) {
197
+ return HybridAppUtility . getProxy < LogicAppsV2 . RunInstanceDefinition > (
198
+ `${ baseUrl } ${ appId } /hostruntime/runtime/webhooks/workflow/api/management/workflows/${ workflowName } /runs/${ runId } ?api-version=2018-11-01&$expand=properties/actions,workflow/properties` ,
199
+ null ,
200
+ {
201
+ Authorization : `Bearer ${ environment . armToken } ` ,
202
+ }
203
+ ) ;
204
+ }
205
+
176
206
const results = await axios . get < LogicAppsV2 . RunInstanceDefinition > (
177
207
`${ baseUrl } ${ appId } /hostruntime/runtime/webhooks/workflow/api/management/workflows/${ workflowName } /runs/${ runId } ?api-version=2018-11-01&$expand=properties/actions,workflow/properties` ,
178
208
{
@@ -229,16 +259,23 @@ export const listCallbackUrl = async (
229
259
) : Promise < CallbackInfo > => {
230
260
let callbackInfo : any ;
231
261
if ( triggerName ) {
232
- const result = await axios . post (
233
- `${ baseUrl } ${ workflowId } /triggers/${ triggerName } /listCallbackUrl?api-version=${ isConsumption ? '2016-10-01' : standardApiVersion } ` ,
234
- null ,
235
- {
236
- headers : {
237
- Authorization : `Bearer ${ environment . armToken } ` ,
238
- } ,
239
- }
240
- ) ;
241
- callbackInfo = result . data ;
262
+ const authToken = {
263
+ Authorization : `Bearer ${ environment . armToken } ` ,
264
+ } ;
265
+ if ( HybridAppUtility . isHybridLogicApp ( workflowId ) ) {
266
+ callbackInfo = HybridAppUtility . postProxy ( `${ baseUrl } ${ workflowId } /triggers/${ triggerName } /listCallbackUrl` , null , authToken ) ;
267
+ } else {
268
+ const result = await axios . post (
269
+ `${ baseUrl } ${ workflowId } /triggers/${ triggerName } /listCallbackUrl?api-version=${ isConsumption ? '2016-10-01' : standardApiVersion } ` ,
270
+ null ,
271
+ {
272
+ headers : {
273
+ ...authToken ,
274
+ } ,
275
+ }
276
+ ) ;
277
+ callbackInfo = result . data ;
278
+ }
242
279
} else {
243
280
callbackInfo = {
244
281
basePath : '' ,
@@ -262,11 +299,16 @@ export const listCallbackUrl = async (
262
299
} ;
263
300
} ;
264
301
265
- export const useWorkflowApp = ( siteResourceId : string , isConsumption = false ) => {
302
+ export const useWorkflowApp = ( siteResourceId : string , hostingPlan : HostingPlanTypes ) => {
266
303
return useQuery (
267
304
[ 'workflowApp' , siteResourceId ] ,
268
305
async ( ) => {
269
- const uri = `${ baseUrl } ${ siteResourceId } ?api-version=${ isConsumption ? '2016-10-01' : '2018-11-01' } ` ;
306
+ const apiVersions = {
307
+ consumption : '2016-10-01' ,
308
+ standard : '2018-11-01' ,
309
+ hybrid : '2023-11-02-preview' ,
310
+ } ;
311
+ const uri = `${ baseUrl } ${ siteResourceId } ?api-version=${ apiVersions [ hostingPlan ] || '2018-11-01' } ` ;
270
312
const response = await axios . get ( uri , {
271
313
headers : {
272
314
Authorization : `Bearer ${ environment . armToken } ` ,
@@ -287,14 +329,30 @@ export const useAppSettings = (siteResourceId: string) => {
287
329
return useQuery (
288
330
[ 'appSettings' , siteResourceId ] ,
289
331
async ( ) => {
290
- const uri = `${ baseUrl } ${ siteResourceId } /config/appsettings/list?api-version=2018-11-01` ;
291
- const response = await axios . post ( uri , null , {
292
- headers : {
293
- Authorization : `Bearer ${ environment . armToken } ` ,
294
- } ,
295
- } ) ;
332
+ if ( HybridAppUtility . isHybridLogicApp ( siteResourceId ) ) {
333
+ const containerAppInfo = (
334
+ await axios . get ( `${ baseUrl } ${ siteResourceId } ?api-version=2024-02-02-preview` , {
335
+ headers : {
336
+ Authorization : `Bearer ${ environment . armToken } ` ,
337
+ } ,
338
+ } )
339
+ ) . data ;
340
+ containerAppInfo . properties = containerAppInfo . properties . template . containers [ 0 ] . env ;
341
+ containerAppInfo . properties = containerAppInfo . properties . reduce ( ( acc : any , cur : any ) => {
342
+ acc [ cur . name ] = cur . value ;
343
+ return acc ;
344
+ } , { } ) ;
345
+ return containerAppInfo ;
346
+ }
296
347
297
- return response . data ;
348
+ const uri = `${ baseUrl } ${ siteResourceId } /config/appsettings/list?api-version=2018-11-01` ;
349
+ return (
350
+ await axios . post ( uri , null , {
351
+ headers : {
352
+ Authorization : `Bearer ${ environment . armToken } ` ,
353
+ } ,
354
+ } )
355
+ ) . data ;
298
356
} ,
299
357
{
300
358
refetchOnMount : false ,
@@ -440,13 +498,23 @@ export const saveWorkflowStandard = async (
440
498
// the host to go soft restart. We may need to look into if there's a race case where this may still happen
441
499
// eventually we want to move this logic to the backend to happen with deployWorkflowArtifacts
442
500
saveCustomCodeStandard ( customCodeData ) ;
443
- const response = await axios . post ( `${ baseUrl } ${ siteResourceId } /deployWorkflowArtifacts?api-version=${ standardApiVersion } ` , data , {
501
+
502
+ let url = null ;
503
+ if ( HybridAppUtility . isHybridLogicApp ( siteResourceId ) ) {
504
+ url = `${ baseUrl } ${ HybridAppUtility . getHybridAppBaseRelativeUrl (
505
+ siteResourceId
506
+ ) } /deployWorkflowArtifacts?api-version=${ hybridApiVersion } `;
507
+ } else {
508
+ url = `${ baseUrl } ${ siteResourceId } /deployWorkflowArtifacts?api-version=${ standardApiVersion } ` ;
509
+ }
510
+ const response = await axios . post ( url , data , {
444
511
headers : {
445
512
'If-Match' : '*' ,
446
513
'Content-Type' : 'application/json' ,
447
514
Authorization : `Bearer ${ environment . armToken } ` ,
448
515
} ,
449
516
} ) ;
517
+
450
518
if ( ! isSuccessResponse ( response . status ) ) {
451
519
alert ( 'Failed to save workflow' ) ;
452
520
return ;
@@ -504,18 +572,29 @@ const validateWorkflow = async (
504
572
requestPayload . properties . appsettings = { Values : settings } ;
505
573
}
506
574
507
- const response = await axios . post (
508
- `${ baseUrl } ${ siteResourceId } /hostruntime/runtime/webhooks/workflow/api/management/workflows/${ workflowName } /validate?api-version=${
509
- isConsumption ? consumptionApiVersion : standardApiVersion
510
- } `,
511
- requestPayload ,
512
- {
513
- headers : {
514
- 'Content-Type' : 'application/json' ,
575
+ let response = null ;
576
+ if ( HybridAppUtility . isHybridLogicApp ( siteResourceId ) ) {
577
+ response = await HybridAppUtility . postProxyResponse (
578
+ `${ baseUrl } ${ siteResourceId } /hostruntime/runtime/webhooks/workflow/api/management/workflows/${ workflowName } /validate` ,
579
+ requestPayload ,
580
+ {
515
581
Authorization : `Bearer ${ environment . armToken } ` ,
516
- } ,
517
- }
518
- ) ;
582
+ }
583
+ ) ;
584
+ } else {
585
+ response = await axios . post (
586
+ `${ baseUrl } ${ siteResourceId } /hostruntime/runtime/webhooks/workflow/api/management/workflows/${ workflowName } /validate?api-version=${
587
+ isConsumption ? consumptionApiVersion : standardApiVersion
588
+ } `,
589
+ requestPayload ,
590
+ {
591
+ headers : {
592
+ 'Content-Type' : 'application/json' ,
593
+ Authorization : `Bearer ${ environment . armToken } ` ,
594
+ } ,
595
+ }
596
+ ) ;
597
+ }
519
598
520
599
if ( response . status !== 200 ) {
521
600
return Promise . reject ( response ) ;
0 commit comments