-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathHybridAppUtilities.ts
More file actions
53 lines (44 loc) · 1.83 KB
/
Copy pathHybridAppUtilities.ts
File metadata and controls
53 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import axios from 'axios';
export class HybridAppUtility {
public static getHybridAppBaseRelativeUrl(appId: string | undefined): string {
if (!appId) {
throw new Error(`Invalid value for appId: '${appId}'`);
}
return `${appId}/providers/Microsoft.App/logicApps/${appId.split('/').pop()}`;
}
public static async getProxy<T>(uri: string, data: any, headers: Record<string, string>, params?: Record<string, any>): Promise<T> {
const [baseUri, path] = uri.split('hostruntime');
const appName = baseUri.split('/');
appName.pop();
return (
await axios.post<T>(`${baseUri}providers/Microsoft.App/logicapps/${appName.pop()}/invoke?api-version=${hybridApiVersion}`, data, {
headers: {
...headers,
'x-ms-logicapps-proxy-path': `${path}`,
'x-ms-logicapps-proxy-method': 'GET',
},
params,
})
).data;
}
public static async postProxy<T>(uri: string, data: any, headers: Record<string, string>, params?: Record<string, any>): Promise<T> {
const response = await HybridAppUtility.postProxyResponse<T>(uri, data, headers, params);
return response.data;
}
public static async postProxyResponse<T>(uri: string, data: any, headers: Record<string, string>, params?: Record<string, any>) {
const [baseUri, path] = uri.split('/hostruntime/');
const appName = baseUri.split('/').pop();
return await axios.post<T>(`${baseUri}/providers/Microsoft.App/logicapps/${appName}/invoke?api-version=${hybridApiVersion}`, data, {
headers: {
...headers,
'x-ms-logicapps-proxy-path': `/${path}`,
'x-ms-logicapps-proxy-method': 'POST',
},
params,
});
}
public static isHybridLogicApp(uri: string) {
return uri.toLowerCase().includes('microsoft.app');
}
}
export const hybridApiVersion = '2024-02-02-preview';