diff --git a/Composer/packages/electron-server/src/main.ts b/Composer/packages/electron-server/src/main.ts index ef42ea9685..d8fcd38ee5 100644 --- a/Composer/packages/electron-server/src/main.ts +++ b/Composer/packages/electron-server/src/main.ts @@ -343,6 +343,11 @@ async function run() { }; }); + ipcMain.handle('deeplink', async (evt, url: string) => { + const deeplink = parseDeepLinkUrl(url); + await getMainWindow()?.webContents.loadURL(getBaseUrl() + deeplink); + }); + await main(); setTimeout(() => startApp(signalThatMainWindowIsShowing), 500); await initApp(); diff --git a/Composer/packages/server/src/externalContentProvider/powerVirtualAgentsProvider.ts b/Composer/packages/server/src/externalContentProvider/powerVirtualAgentsProvider.ts index 8c0d18fef8..36fc6dfd43 100644 --- a/Composer/packages/server/src/externalContentProvider/powerVirtualAgentsProvider.ts +++ b/Composer/packages/server/src/externalContentProvider/powerVirtualAgentsProvider.ts @@ -22,6 +22,19 @@ export const PVA_GOV_APP_ID = '9315aedd-209b-43b3-b149-2abff6a95d59'; export const PVA_GCC_HIGH_APP_ID = '69c6e40c-465f-4154-987d-da5cba10734e'; export type PowerVirtualAgentsMetadata = IContentProviderMetadata & { + clusterCategory?: + | 'Dev' + | 'Prv' + | 'Test' + | 'Preprod' + | 'FirstRelease' + | 'Prod' + | 'Gov' + | 'High' + | 'DoD' + | 'Mooncake' + | 'Ex' + | 'Rx'; baseUrl: string; botId: string; dialogId?: string; @@ -32,22 +45,35 @@ export type PowerVirtualAgentsMetadata = IContentProviderMetadata & { }; const getAuthCredentials = (baseUrl: string, metadata: PowerVirtualAgentsMetadata) => { + const clusterCategory = + (process.env.COMPOSER_PVA_CLUSTER as typeof metadata.clusterCategory) ?? metadata.clusterCategory; const url = new URL(baseUrl); - if (url.hostname.includes('.int.') || url.hostname.includes('.ppe.')) { + if ( + (clusterCategory && ['Test', 'Preprod', 'Dev'].includes(clusterCategory)) || + url.hostname.includes('.int.') || + url.hostname.includes('.ppe.') || + url.hostname.includes('.test.') + ) { log('Using INT / PPE auth credentials.'); return { clientId: COMPOSER_1P_APP_ID, scopes: [`${PVA_TEST_APP_ID}/.default`], targetResource: PVA_TEST_APP_ID, }; - } else if (url.hostname.includes('gcc.api.powerva.microsoft.us')) { + } else if ( + (clusterCategory && ['Gov'].includes(clusterCategory)) || + url.hostname.includes('gcc.api.powerva.microsoft.us') + ) { log('Using GCC auth credentials.'); return { clientId: COMPOSER_1P_APP_ID, scopes: [`${PVA_GOV_APP_ID}/.default`], targetResource: PVA_GOV_APP_ID, }; - } else if (url.hostname.includes('high.api.powerva.microsoft.us')) { + } else if ( + (clusterCategory && ['High'].includes(clusterCategory)) || + url.hostname.includes('high.api.powerva.microsoft.us') + ) { log('Using GCC High auth credentials.'); return { authority: `https://login.microsoftonline.us/${metadata.tenantId}`, @@ -56,7 +82,7 @@ const getAuthCredentials = (baseUrl: string, metadata: PowerVirtualAgentsMetadat targetResource: PVA_GCC_HIGH_APP_ID, }; } - log('Using PROD auth credentials.'); + log(`Using PROD auth credentials.\nCategory: ${clusterCategory}\nURL: ${baseUrl}`); return { clientId: COMPOSER_1P_APP_ID, scopes: [`${PVA_PROD_APP_ID}/.default`], @@ -64,47 +90,6 @@ const getAuthCredentials = (baseUrl: string, metadata: PowerVirtualAgentsMetadat }; }; -const getBaseUrl = () => { - const pvaEnv = (process.env.COMPOSER_PVA_ENV || '').toLowerCase(); - switch (pvaEnv) { - case 'prod': { - const url = 'https://powerva.microsoft.com/api/botmanagement/v1'; - log('PROD env detected, grabbing PVA content from %s', url); - return url; - } - - case 'ppe': { - const url = 'https://bots.ppe.customercareintelligence.net/api/botmanagement/v1'; - log('PPE env detected, grabbing PVA content from %s', url); - return url; - } - - case 'int': { - const url = 'https://bots.int.customercareintelligence.net/api/botmanagement/v1'; - log('INT env detected, grabbing PVA content from %s', url); - return url; - } - - case 'gcc': { - const url = 'https://gcc.api.powerva.microsoft.us/api/botmanagement/v1'; - log('GCC env detected, grabbing PVA content from %s', url); - return url; - } - - case 'gcc-high': { - const url = 'https://high.api.powerva.microsoft.us/api/botmanagement/v1'; - log('GCC High env detected, grabbing PVA content from %s', url); - return url; - } - - default: { - const url = 'https://bots.int.customercareintelligence.net/api/botmanagement/v1'; - log('No env flag detected, grabbing PVA content from %s', url); - return url; - } - } -}; - function prettyPrintError(err: string | Error): string { if (typeof err === 'string') { return err; @@ -177,7 +162,7 @@ export class PowerVirtualAgentsProvider extends ExternalContentProvider { - let envBackup; - beforeAll(() => { - envBackup = { ...process.env }; - }); - - beforeEach(() => { - Object.assign(process.env, { COMPOSER_PVA_PUBLISH_ENV: '' }); - }); - - afterAll(() => { - Object.assign(process.env, envBackup); // restore the platform - }); - - it('fallback to prod', () => { - expect(getBaseUrl()).toBe(BASE_URLS.PROD); - }); - - it('int', () => { - Object.assign(process.env, { COMPOSER_PVA_PUBLISH_ENV: 'INT' }); - expect(getBaseUrl()).toBe(BASE_URLS.INT); - }); - - it('ppe', () => { - Object.assign(process.env, { COMPOSER_PVA_PUBLISH_ENV: 'PPE' }); - expect(getBaseUrl()).toBe(BASE_URLS.PPE); - }); - - it('prod', () => { - Object.assign(process.env, { COMPOSER_PVA_PUBLISH_ENV: 'PROD' }); - expect(getBaseUrl()).toBe(BASE_URLS.PROD); - }); - - it('gcc', () => { - Object.assign(process.env, { COMPOSER_PVA_PUBLISH_ENV: 'GCC' }); - expect(getBaseUrl()).toBe(BASE_URLS.GCC); - }); - - it('gcc high', () => { - Object.assign(process.env, { COMPOSER_PVA_PUBLISH_ENV: 'GCC-HIGH' }); - expect(getBaseUrl()).toBe(BASE_URLS.GCC_HIGH); - }); -}); +import { AUTH_CREDENTIALS } from './constants'; +import { getAuthCredentials } from './utils'; describe('it should return the proper PVA auth parameters for the base URL', () => { it('fallback to prod', () => { @@ -64,7 +20,7 @@ describe('it should return the proper PVA auth parameters for the base URL', () it('ppe', () => { const url = 'https://bots.ppe.customercareintelligence.net/api/botmanagement/v1'; - expect(getAuthCredentials(url)).toEqual(AUTH_CREDENTIALS.PPE); + expect(getAuthCredentials(url)).toEqual(AUTH_CREDENTIALS.INT); }); it('prod', () => { diff --git a/extensions/pvaPublish/src/node/utils.ts b/extensions/pvaPublish/src/node/utils.ts index ec075dddda..434ed046ca 100644 --- a/extensions/pvaPublish/src/node/utils.ts +++ b/extensions/pvaPublish/src/node/utils.ts @@ -4,71 +4,35 @@ import { URL } from 'url'; import { logger } from './logger'; -import { AUTH_CREDENTIALS, BASE_URLS } from './constants'; - -export const getBaseUrl = () => { - logger.log('Base URL not supplied in publishing target. Falling back to hardcoded URL...'); - const pvaEnv = (process.env.COMPOSER_PVA_PUBLISH_ENV || '').toLowerCase(); - switch (pvaEnv) { - case 'prod': { - const url = BASE_URLS.PROD; - logger.log('prod pva publish detected, operation using PVA url: ', url); - return url; - } - - case 'ppe': { - const url = BASE_URLS.PPE; - logger.log('ppe pva publish detected, operation using PVA url: ', url); - return url; - } - - case 'int': { - const url = BASE_URLS.INT; - logger.log('int pva publish env detected, operation using PVA url: ', url); - return url; - } - - case 'gcc': { - const url = BASE_URLS.GCC; - logger.log('gcc pva publish env detected, operation using PVA url: ', url); - return url; - } - - case 'gcc-high': { - const url = BASE_URLS.GCC_HIGH; - logger.log('gcc high pva publish env detected, operation using PVA url: ', url); - return url; - } - - default: { - const url = BASE_URLS.PROD; - logger.log('No pva publish env detected, operation using PVA url: ', url); - return url; - } - } -}; +import { AUTH_CREDENTIALS } from './constants'; +import { ClusterCategory } from './types'; /** - * Looks at the base URL for a request and returns the necessary authentication parameters + * Looks at the cluster category for a request and returns the necessary authentication parameters * to get an access token for the resource. */ -export const getAuthCredentials = (baseUrl = '', tenantId?: string) => { - if (baseUrl) { - const host = new URL(baseUrl).host; - - if (host === 'bots.int.customercareintelligence.net') { - return AUTH_CREDENTIALS.INT; - } else if (host === 'bots.ppe.customercareintelligence.net') { - return AUTH_CREDENTIALS.PPE; - } else if (host === 'gcc.api.powerva.microsoft.us') { - return AUTH_CREDENTIALS.GCC; - } else if (host === 'high.api.powerva.microsoft.us') { - return { - ...AUTH_CREDENTIALS.GCC_HIGH, - authority: `https://login.microsoftonline.us/${tenantId}`, - }; - } +export const getAuthCredentials = (baseUrl = '', tenantId?: string, clusterCategory?: ClusterCategory) => { + const host = new URL(baseUrl).host; + clusterCategory = (process.env.COMPOSER_PVA_CLUSTER as ClusterCategory) ?? clusterCategory; + if ( + ['Test', 'Preprod', 'Dev'].includes(clusterCategory) || + host.includes('.int.') || + host.includes('.ppe.') || + host.includes('.test.') + ) { + logger.log('Using INT / PPE auth credentials.'); + return AUTH_CREDENTIALS.INT; + } else if (['Gov'].includes(clusterCategory) || host === 'gcc.api.powerva.microsoft.us') { + logger.log('Using GCC auth credentials.'); + return AUTH_CREDENTIALS.GCC; + } else if (['High'].includes(clusterCategory) || host === 'high.api.powerva.microsoft.us') { + logger.log('Using GCC High auth credentials.'); + return { + ...AUTH_CREDENTIALS.GCC_HIGH, + authority: `https://login.microsoftonline.us/${tenantId}`, + }; } + logger.log(`Using PROD auth credentials.\nCategory: ${clusterCategory}\nURL: ${baseUrl}`); // fall back to prod return AUTH_CREDENTIALS.PROD; };