Skip to content

Commit 71b382d

Browse files
Cipriano GiuseppeCipriano Giuseppe
authored andcommitted
Add automatic switching to Portals Web API
1 parent 589462e commit 71b382d

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/dynamics-web-api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,8 +1703,6 @@ export interface Config {
17031703
dataApi?: ApiConfig;
17041704
/**Configuration object for Dataverse Search API (with path "search") */
17051705
searchApi?: ApiConfig;
1706-
/**A flag that switches to the Dynamics Portals Web API. Official Docs: https://learn.microsoft.com/en-us/power-pages/configure/web-api-overview */
1707-
portalsApi?: boolean | null;
17081706
}
17091707

17101708
export interface ProxyConfig {

src/utils/Config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export interface InternalConfig extends Config {
1313
searchApi: InternalApiConfig;
1414
}
1515

16-
const getApiUrl = (serverUrl: string | undefined | null, apiConfig: ApiConfig, portalsApi: boolean | undefined | null): string => {
17-
if (portalsApi) {
16+
const getApiUrl = (serverUrl: string | undefined | null, apiConfig: ApiConfig): string => {
17+
if (Utility.isRunningWithinPortals()) {
1818
return `${window.location.origin}/_api/`;
1919
} else {
2020
if (!serverUrl) serverUrl = Utility.getClientUrl();
@@ -35,7 +35,7 @@ const mergeApiConfigs = (apiConfig: ApiConfig | undefined, apiType: ApiType, int
3535
internalApiConfig.path = apiConfig.path;
3636
}
3737

38-
internalApiConfig.url = getApiUrl(internalConfig.serverUrl, internalApiConfig, internalConfig.portalsApi);
38+
internalApiConfig.url = getApiUrl(internalConfig.serverUrl, internalApiConfig);
3939
};
4040

4141
export class ConfigurationUtility {
@@ -127,7 +127,6 @@ export class ConfigurationUtility {
127127
version: "1.0",
128128
url: "",
129129
},
130-
portalsApi: null,
131130
};
132131
}
133132
}

src/utils/Utility.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,16 @@ export class Utility {
153153
return clientUrl;
154154
}
155155

156+
/**
157+
* Checks whether whether the app is currently running in a Dynamics Portals Environment.
158+
*
159+
* In that case we switch to the Web API for Dynamics Portals.
160+
* @returns {boolean}
161+
*/
162+
static isRunningWithinPortals(): boolean {
163+
return !!(window as any).shell;
164+
}
165+
156166
static isObject(obj: any): boolean {
157167
return typeof obj === "object" && !!obj && !Array.isArray(obj) && Object.prototype.toString.call(obj) !== "[object Date]";
158168
}

0 commit comments

Comments
 (0)