diff --git a/package-lock.json b/package-lock.json index 483503d..8df0680 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,23 +1,23 @@ { "name": "dynamics-web-api", - "version": "2.0.0-beta.3", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "dynamics-web-api", - "version": "2.0.0-beta.3", + "version": "2.0.0", "license": "MIT", "dependencies": { - "@types/node": "^20.4.2", - "@types/xrm": "^9.0.73", "http-proxy-agent": "^4.0.1", "https-proxy-agent": "^5.0.0" }, "devDependencies": { "@types/chai": "^4.3.5", "@types/mocha": "^10.0.1", + "@types/node": "^20.4.2", "@types/sinon": "^10.0.15", + "@types/xrm": "^9.0.73", "Base64": "^1.2.0", "chai": "^4.3.7", "copyfiles": "^2.4.1", @@ -1054,7 +1054,8 @@ "node_modules/@types/node": { "version": "20.4.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.2.tgz", - "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==" + "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==", + "dev": true }, "node_modules/@types/sinon": { "version": "10.0.15", @@ -1074,7 +1075,8 @@ "node_modules/@types/xrm": { "version": "9.0.73", "resolved": "https://registry.npmjs.org/@types/xrm/-/xrm-9.0.73.tgz", - "integrity": "sha512-3w/qsU74cyPGCO4BJe8vT/6i3BjX4Lga3XoZNuBPPlGxJatUVZXLuX5UfhBJBRCVRDl91tbWf/5yCHK3ftIViQ==" + "integrity": "sha512-3w/qsU74cyPGCO4BJe8vT/6i3BjX4Lga3XoZNuBPPlGxJatUVZXLuX5UfhBJBRCVRDl91tbWf/5yCHK3ftIViQ==", + "dev": true }, "node_modules/acorn": { "version": "8.10.0", @@ -6041,7 +6043,8 @@ "@types/node": { "version": "20.4.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.2.tgz", - "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==" + "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==", + "dev": true }, "@types/sinon": { "version": "10.0.15", @@ -6061,7 +6064,8 @@ "@types/xrm": { "version": "9.0.73", "resolved": "https://registry.npmjs.org/@types/xrm/-/xrm-9.0.73.tgz", - "integrity": "sha512-3w/qsU74cyPGCO4BJe8vT/6i3BjX4Lga3XoZNuBPPlGxJatUVZXLuX5UfhBJBRCVRDl91tbWf/5yCHK3ftIViQ==" + "integrity": "sha512-3w/qsU74cyPGCO4BJe8vT/6i3BjX4Lga3XoZNuBPPlGxJatUVZXLuX5UfhBJBRCVRDl91tbWf/5yCHK3ftIViQ==", + "dev": true }, "acorn": { "version": "8.10.0", diff --git a/src/dynamics-web-api.ts b/src/dynamics-web-api.ts index 1a9f80b..0dfe392 100644 --- a/src/dynamics-web-api.ts +++ b/src/dynamics-web-api.ts @@ -1196,7 +1196,7 @@ export interface BaseRequest { inChangeSet?: boolean; } -export interface BatchRequest extends BaseRequest{ +export interface BatchRequest extends BaseRequest { /** 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. */ continueOnError?: boolean; } diff --git a/src/utils/Config.ts b/src/utils/Config.ts index 56ea809..c62c762 100644 --- a/src/utils/Config.ts +++ b/src/utils/Config.ts @@ -14,9 +14,12 @@ export interface InternalConfig extends Config { } const getApiUrl = (serverUrl: string | undefined | null, apiConfig: ApiConfig): string => { - if (!serverUrl) serverUrl = Utility.getClientUrl(); - - return `${serverUrl}/api/${apiConfig.path}/v${apiConfig.version}/`; + if (Utility.isRunningWithinPortals()) { + return `${window.location.origin}/_api/`; + } else { + if (!serverUrl) serverUrl = Utility.getClientUrl(); + return `${serverUrl}/api/${apiConfig.path}/v${apiConfig.version}/`; + } }; const mergeApiConfigs = (apiConfig: ApiConfig | undefined, apiType: ApiType, internalConfig: InternalConfig): void => { diff --git a/src/utils/Utility.ts b/src/utils/Utility.ts index 740c75c..d15be21 100644 --- a/src/utils/Utility.ts +++ b/src/utils/Utility.ts @@ -153,6 +153,16 @@ export class Utility { return clientUrl; } + /** + * Checks whether the app is currently running in a Dynamics Portals Environment. + * + * In that case we switch to the Web API for Dynamics Portals. + * @returns {boolean} + */ + static isRunningWithinPortals(): boolean { + return !!(window as any).shell; + } + static isObject(obj: any): boolean { return typeof obj === "object" && !!obj && !Array.isArray(obj) && Object.prototype.toString.call(obj) !== "[object Date]"; }