@@ -22,6 +22,19 @@ export const PVA_GOV_APP_ID = '9315aedd-209b-43b3-b149-2abff6a95d59';
22
22
export const PVA_GCC_HIGH_APP_ID = '69c6e40c-465f-4154-987d-da5cba10734e' ;
23
23
24
24
export type PowerVirtualAgentsMetadata = IContentProviderMetadata & {
25
+ clusterCategory ?:
26
+ | 'Dev'
27
+ | 'Prv'
28
+ | 'Test'
29
+ | 'Preprod'
30
+ | 'FirstRelease'
31
+ | 'Prod'
32
+ | 'Gov'
33
+ | 'High'
34
+ | 'DoD'
35
+ | 'Mooncake'
36
+ | 'Ex'
37
+ | 'Rx' ;
25
38
baseUrl : string ;
26
39
botId : string ;
27
40
dialogId ?: string ;
@@ -32,22 +45,35 @@ export type PowerVirtualAgentsMetadata = IContentProviderMetadata & {
32
45
} ;
33
46
34
47
const getAuthCredentials = ( baseUrl : string , metadata : PowerVirtualAgentsMetadata ) => {
48
+ const clusterCategory =
49
+ ( process . env . COMPOSER_PVA_CLUSTER as typeof metadata . clusterCategory ) ?? metadata . clusterCategory ;
35
50
const url = new URL ( baseUrl ) ;
36
- if ( url . hostname . includes ( '.int.' ) || url . hostname . includes ( '.ppe.' ) ) {
51
+ if (
52
+ ( clusterCategory && [ 'Test' , 'Preprod' , 'Dev' ] . includes ( clusterCategory ) ) ||
53
+ url . hostname . includes ( '.int.' ) ||
54
+ url . hostname . includes ( '.ppe.' ) ||
55
+ url . hostname . includes ( '.test.' )
56
+ ) {
37
57
log ( 'Using INT / PPE auth credentials.' ) ;
38
58
return {
39
59
clientId : COMPOSER_1P_APP_ID ,
40
60
scopes : [ `${ PVA_TEST_APP_ID } /.default` ] ,
41
61
targetResource : PVA_TEST_APP_ID ,
42
62
} ;
43
- } else if ( url . hostname . includes ( 'gcc.api.powerva.microsoft.us' ) ) {
63
+ } else if (
64
+ ( clusterCategory && [ 'Gov' ] . includes ( clusterCategory ) ) ||
65
+ url . hostname . includes ( 'gcc.api.powerva.microsoft.us' )
66
+ ) {
44
67
log ( 'Using GCC auth credentials.' ) ;
45
68
return {
46
69
clientId : COMPOSER_1P_APP_ID ,
47
70
scopes : [ `${ PVA_GOV_APP_ID } /.default` ] ,
48
71
targetResource : PVA_GOV_APP_ID ,
49
72
} ;
50
- } else if ( url . hostname . includes ( 'high.api.powerva.microsoft.us' ) ) {
73
+ } else if (
74
+ ( clusterCategory && [ 'High' ] . includes ( clusterCategory ) ) ||
75
+ url . hostname . includes ( 'high.api.powerva.microsoft.us' )
76
+ ) {
51
77
log ( 'Using GCC High auth credentials.' ) ;
52
78
return {
53
79
authority : `https://login.microsoftonline.us/${ metadata . tenantId } ` ,
@@ -56,55 +82,14 @@ const getAuthCredentials = (baseUrl: string, metadata: PowerVirtualAgentsMetadat
56
82
targetResource : PVA_GCC_HIGH_APP_ID ,
57
83
} ;
58
84
}
59
- log ( ' Using PROD auth credentials.' ) ;
85
+ log ( ` Using PROD auth credentials.\nCategory: ${ clusterCategory } \nURL: ${ baseUrl } ` ) ;
60
86
return {
61
87
clientId : COMPOSER_1P_APP_ID ,
62
88
scopes : [ `${ PVA_PROD_APP_ID } /.default` ] ,
63
89
targetResource : PVA_PROD_APP_ID ,
64
90
} ;
65
91
} ;
66
92
67
- const getBaseUrl = ( ) => {
68
- const pvaEnv = ( process . env . COMPOSER_PVA_ENV || '' ) . toLowerCase ( ) ;
69
- switch ( pvaEnv ) {
70
- case 'prod' : {
71
- const url = 'https://powerva.microsoft.com/api/botmanagement/v1' ;
72
- log ( 'PROD env detected, grabbing PVA content from %s' , url ) ;
73
- return url ;
74
- }
75
-
76
- case 'ppe' : {
77
- const url = 'https://bots.ppe.customercareintelligence.net/api/botmanagement/v1' ;
78
- log ( 'PPE env detected, grabbing PVA content from %s' , url ) ;
79
- return url ;
80
- }
81
-
82
- case 'int' : {
83
- const url = 'https://bots.int.customercareintelligence.net/api/botmanagement/v1' ;
84
- log ( 'INT env detected, grabbing PVA content from %s' , url ) ;
85
- return url ;
86
- }
87
-
88
- case 'gcc' : {
89
- const url = 'https://gcc.api.powerva.microsoft.us/api/botmanagement/v1' ;
90
- log ( 'GCC env detected, grabbing PVA content from %s' , url ) ;
91
- return url ;
92
- }
93
-
94
- case 'gcc-high' : {
95
- const url = 'https://high.api.powerva.microsoft.us/api/botmanagement/v1' ;
96
- log ( 'GCC High env detected, grabbing PVA content from %s' , url ) ;
97
- return url ;
98
- }
99
-
100
- default : {
101
- const url = 'https://bots.int.customercareintelligence.net/api/botmanagement/v1' ;
102
- log ( 'No env flag detected, grabbing PVA content from %s' , url ) ;
103
- return url ;
104
- }
105
- }
106
- } ;
107
-
108
93
function prettyPrintError ( err : string | Error ) : string {
109
94
if ( typeof err === 'string' ) {
110
95
return err ;
@@ -177,7 +162,7 @@ export class PowerVirtualAgentsProvider extends ExternalContentProvider<PowerVir
177
162
try {
178
163
// login to the 1P app and get an access token
179
164
const { baseUrl } = this . metadata ;
180
- const authCredentials = getAuthCredentials ( baseUrl || getBaseUrl ( ) , this . metadata ) ;
165
+ const authCredentials = getAuthCredentials ( baseUrl , this . metadata ) ;
181
166
const accessToken = await authService . getAccessToken ( authCredentials ) ;
182
167
if ( accessToken === '' ) {
183
168
throw 'User cancelled login flow.' ;
@@ -190,7 +175,7 @@ export class PowerVirtualAgentsProvider extends ExternalContentProvider<PowerVir
190
175
191
176
private getContentUrl ( ) : string {
192
177
const { envId, baseUrl, botId } = this . metadata ;
193
- return `${ baseUrl || getBaseUrl ( ) } /environments/${ envId } /bots/${ botId } /composer/content?includeTopics=true` ;
178
+ return `${ baseUrl } /environments/${ envId } /bots/${ botId } /composer/content?includeTopics=true` ;
194
179
}
195
180
196
181
private async getRequestHeaders ( ) {
@@ -206,7 +191,7 @@ export class PowerVirtualAgentsProvider extends ExternalContentProvider<PowerVir
206
191
private getDeepLink ( ) : string {
207
192
// use metadata (if provided) to create a deep link to a specific dialog / trigger / action etc. after opening bot.
208
193
let deepLink = '' ;
209
- const { dialogId, triggerId, actionId = '' } = this . metadata ;
194
+ const { dialogId, triggerId, actionId = '' , clusterCategory } = this . metadata ;
210
195
211
196
if ( dialogId ) {
212
197
deepLink += `dialogs/${ dialogId } ` ;
@@ -219,6 +204,9 @@ export class PowerVirtualAgentsProvider extends ExternalContentProvider<PowerVir
219
204
`"${ actionId } "` ,
220
205
) } ]`;
221
206
}
207
+ if ( clusterCategory ) {
208
+ deepLink += deepLink . includes ( '?' ) ? '&' : '?' + `cluster=${ clusterCategory } ` ;
209
+ }
222
210
// base64 encode to make parsing on the client side easier
223
211
return Buffer . from ( deepLink , 'utf-8' ) . toString ( 'base64' ) ;
224
212
}
0 commit comments