From 8e7f72fa7058810157084bb9c7005cc4f5ce5706 Mon Sep 17 00:00:00 2001 From: Priyanshu Agrawal Date: Tue, 17 Dec 2024 19:19:37 +0530 Subject: [PATCH] Add sovereign cloud endpoints for PPAPI service --- l10n/bundle.l10n.json | 1 + .../vscode-powerplatform.xlf | 3 ++ package.json | 1 + src/client/extension.ts | 6 ++-- .../runtime-site-preview/PreviewSite.ts | 7 ++++- src/common/services/AuthenticationProvider.ts | 29 +++++++++++++++++-- src/common/services/Constants.ts | 3 ++ src/common/services/PPAPIService.ts | 10 +++++-- 8 files changed, 52 insertions(+), 8 deletions(-) diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 02f57d61..1da2a9f9 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -98,6 +98,7 @@ "Cancel": "Cancel", "Site runtime preview feature is not enabled.": "Site runtime preview feature is not enabled.", "No workspace folder opened. Please open a site folder to preview.": "No workspace folder opened. Please open a site folder to preview.", + "Initializing site preview. Please try again after few seconds.": "Initializing site preview. Please try again after few seconds.", "Website URL not found.": "Website URL not found.", "Opening site preview...": "Opening site preview...", "File might be referenced by name {0} here./{0} represents the name of the file": { diff --git a/loc/translations-export/vscode-powerplatform.xlf b/loc/translations-export/vscode-powerplatform.xlf index ca709b39..b599371f 100644 --- a/loc/translations-export/vscode-powerplatform.xlf +++ b/loc/translations-export/vscode-powerplatform.xlf @@ -214,6 +214,9 @@ Return to this chat and @powerpages can help you write and edit your website cod In your own words, describe what you need. You can get help with writing code for Power Pages sites in HTML, CSS, and JS languages. + + Initializing site preview. Please try again after few seconds. + Insert code into editor diff --git a/package.json b/package.json index 85b0b689..ee051b59 100644 --- a/package.json +++ b/package.json @@ -372,6 +372,7 @@ }, { "command": "microsoft.powerplatform.pages.preview-site", + "category": "Powerpages", "title": "%powerplatform.pages.previewSite.title%" } ], diff --git a/src/client/extension.ts b/src/client/extension.ts index e58bcf24..b0763d24 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -196,7 +196,7 @@ export async function activate( ) || []; - let websiteURL: string | undefined = ""; + let websiteURL: string | undefined = undefined; const isSiteRuntimePreviewEnabled = PreviewSite.isSiteRuntimePreviewEnabled(); vscode.commands.executeCommand("setContext", "microsoft.powerplatform.pages.siteRuntimePreviewEnabled", isSiteRuntimePreviewEnabled); @@ -282,11 +282,11 @@ export async function activate( _telemetry.sendTelemetryEvent("EnableSiteRuntimePreview", { isEnabled: isSiteRuntimePreviewEnabled.toString(), - websiteURL: websiteURL + websiteURL: websiteURL || "undefined" }); oneDSLoggerWrapper.getLogger().traceInfo("EnableSiteRuntimePreview", { isEnabled: isSiteRuntimePreviewEnabled.toString(), - websiteURL: websiteURL + websiteURL: websiteURL || "undefined" }); _context.subscriptions.push( diff --git a/src/client/runtime-site-preview/PreviewSite.ts b/src/client/runtime-site-preview/PreviewSite.ts index 66dc3d1b..6adfbbaa 100644 --- a/src/client/runtime-site-preview/PreviewSite.ts +++ b/src/client/runtime-site-preview/PreviewSite.ts @@ -89,7 +89,12 @@ export class PreviewSite { return; } - if (!websiteURL || websiteURL === "") { + if (websiteURL === undefined) { + await vscode.window.showWarningMessage(vscode.l10n.t("Initializing site preview. Please try again after few seconds.")); + return; + } + + if (websiteURL === "") { await vscode.window.showErrorMessage(vscode.l10n.t("Website URL not found.")); return; } diff --git a/src/common/services/AuthenticationProvider.ts b/src/common/services/AuthenticationProvider.ts index 34c3bdb6..4d2f284d 100644 --- a/src/common/services/AuthenticationProvider.ts +++ b/src/common/services/AuthenticationProvider.ts @@ -23,10 +23,35 @@ import { VSCODE_EXTENSION_PPAPI_WEBSITES_AUTHENTICATION_FAILED } from "./TelemetryConstants"; import { ERROR_CONSTANTS } from "../ErrorConstants"; -import { BAP_SERVICE_SCOPE_DEFAULT, INTELLIGENCE_SCOPE_DEFAULT, PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT, PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT, PROVIDER_ID, SCOPE_OPTION_CONTACTS_READ, SCOPE_OPTION_DEFAULT, SCOPE_OPTION_OFFLINE_ACCESS, SCOPE_OPTION_USERS_READ_BASIC_ALL, ServiceEndpointCategory } from "./Constants"; +import { + BAP_SERVICE_SCOPE_DEFAULT, + INTELLIGENCE_SCOPE_DEFAULT, + PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, + PPAPI_MOONCAKE_WEBSITES_SERVICE_SCOPE_DEFAULT, + PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT, + PPAPI_TEST_WEBSITES_SERVICE_SCOPE_DEFAULT, + PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT, + PROVIDER_ID, + SCOPE_OPTION_CONTACTS_READ, + SCOPE_OPTION_DEFAULT, + SCOPE_OPTION_OFFLINE_ACCESS, + SCOPE_OPTION_USERS_READ_BASIC_ALL, + ServiceEndpointCategory +} from "./Constants"; import jwt_decode from 'jwt-decode'; import { showErrorDialog } from "../utilities/errorHandlerUtil"; +const serviceScopeMapping: { [key in ServiceEndpointCategory]: string } = { + [ServiceEndpointCategory.NONE]: "", + [ServiceEndpointCategory.PROD]: PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.PREPROD]: PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.TEST]: PPAPI_TEST_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.MOONCAKE]: PPAPI_MOONCAKE_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.GCC]: PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.DOD]: PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.HIGH]: PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, +}; + export function getCommonHeadersForDataverse( accessToken: string, useOctetStreamContentType?: boolean @@ -300,7 +325,7 @@ export async function powerPlatformAPIAuthentication( firstTimeAuth = false ): Promise { let accessToken = ""; - const PPAPI_WEBSITES_ENDPOINT = [ServiceEndpointCategory.TEST, ServiceEndpointCategory.PREPROD].includes(serviceEndpointStamp) ? PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT : PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT; + const PPAPI_WEBSITES_ENDPOINT = serviceScopeMapping[serviceEndpointStamp]; try { let session = await vscode.authentication.getSession( PROVIDER_ID, diff --git a/src/common/services/Constants.ts b/src/common/services/Constants.ts index a77791ab..91119527 100644 --- a/src/common/services/Constants.ts +++ b/src/common/services/Constants.ts @@ -23,6 +23,9 @@ export const BAP_ENVIRONMENT_LIST_URL = `scopes/admin/environments?api-version={ export const PPAPI_WEBSITES_API_VERSION = '2022-03-01-preview'; export const PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.powerplatform.com/.default"; export const PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.preprod.powerplatform.com/.default"; +export const PPAPI_TEST_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.test.powerplatform.com/.default"; +export const PPAPI_MOONCAKE_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.powerplatform.cn/.default"; +export const PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.powerplatform.us/.default"; export const PPAPI_WEBSITES_ENDPOINT = `{rootURL}/powerpages/environments/{environmentId}/websites`; export enum ServiceEndpointCategory { diff --git a/src/common/services/PPAPIService.ts b/src/common/services/PPAPIService.ts index 438d3e27..79217703 100644 --- a/src/common/services/PPAPIService.ts +++ b/src/common/services/PPAPIService.ts @@ -93,11 +93,17 @@ export class PPAPIService { case ServiceEndpointCategory.PROD: ppapiEndpoint = "https://api.powerplatform.com"; break; - // All below endpoints are not supported yet case ServiceEndpointCategory.DOD: + ppapiEndpoint = "https://api.powerplatform.us"; + break; case ServiceEndpointCategory.GCC: - case ServiceEndpointCategory.HIGH: + ppapiEndpoint = "https://api.powerplatform.us"; + break; case ServiceEndpointCategory.MOONCAKE: + ppapiEndpoint = "https://api.powerplatform.cn"; + break; + // Below endpoints are not supported yet + case ServiceEndpointCategory.HIGH: default: sendTelemetryEvent(telemetry, { eventName: VSCODE_EXTENSION_GET_PPAPI_WEBSITES_ENDPOINT_UNSUPPORTED_REGION, data: serviceEndpointStamp }); break;