Skip to content

Commit 5737313

Browse files
Merge pull request #156 from 03-CiprianoG/master
Add support for Portals Web API
2 parents 4eca6bf + 5422769 commit 5737313

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
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: 1 addition & 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
}

src/utils/Config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ export interface InternalConfig extends Config {
1414
}
1515

1616
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}/`;
17+
if (Utility.isRunningWithinPortals()) {
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 => {

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 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)