Skip to content

Commit 589462e

Browse files
Cipriano GiuseppeCipriano Giuseppe
authored andcommitted
Add support for Portals Web API
1 parent 4eca6bf commit 589462e

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

package-lock.json

Lines changed: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dynamics-web-api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ export interface BaseRequest {
11961196
inChangeSet?: boolean;
11971197
}
11981198

1199-
export interface BatchRequest extends BaseRequest{
1199+
export interface BatchRequest extends BaseRequest {
12001200
/** Sets Prefer header to "odata.continue-on-error" that allows more requests be processed when errors occur. The batch request will return '200 OK' and individual response errors will be returned in the batch response body. */
12011201
continueOnError?: boolean;
12021202
}
@@ -1703,6 +1703,8 @@ 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;
17061708
}
17071709

17081710
export interface ProxyConfig {

src/utils/Config.ts

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

16-
const getApiUrl = (serverUrl: string | undefined | null, apiConfig: ApiConfig): string => {
17-
if (!serverUrl) serverUrl = Utility.getClientUrl();
18-
19-
return `${serverUrl}/api/${apiConfig.path}/v${apiConfig.version}/`;
16+
const getApiUrl = (serverUrl: string | undefined | null, apiConfig: ApiConfig, portalsApi: boolean | undefined | null): string => {
17+
if (portalsApi) {
18+
return `${window.location.origin}/_api/`;
19+
} else {
20+
if (!serverUrl) serverUrl = Utility.getClientUrl();
21+
return `${serverUrl}/api/${apiConfig.path}/v${apiConfig.version}/`;
22+
}
2023
};
2124

2225
const mergeApiConfigs = (apiConfig: ApiConfig | undefined, apiType: ApiType, internalConfig: InternalConfig): void => {
@@ -32,7 +35,7 @@ const mergeApiConfigs = (apiConfig: ApiConfig | undefined, apiType: ApiType, int
3235
internalApiConfig.path = apiConfig.path;
3336
}
3437

35-
internalApiConfig.url = getApiUrl(internalConfig.serverUrl, internalApiConfig);
38+
internalApiConfig.url = getApiUrl(internalConfig.serverUrl, internalApiConfig, internalConfig.portalsApi);
3639
};
3740

3841
export class ConfigurationUtility {
@@ -124,6 +127,7 @@ export class ConfigurationUtility {
124127
version: "1.0",
125128
url: "",
126129
},
130+
portalsApi: null,
127131
};
128132
}
129133
}

0 commit comments

Comments
 (0)