Skip to content

Commit 2b40912

Browse files
Release v1.4.1
1 parent 83670a3 commit 2b40912

File tree

7 files changed

+290
-148
lines changed

7 files changed

+290
-148
lines changed

dist/dwa.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! dwa v1.4.0 (c) 2017 Aleksandr Rogov */
1+
/*! dwa v1.4.1 (c) 2018 Aleksandr Rogov */
22
(function webpackUniversalModuleDefinition(root, factory) {
33
if(typeof exports === 'object' && typeof module === 'object')
44
module.exports = factory();

dist/dynamics-web-api-callbacks.js

Lines changed: 143 additions & 75 deletions
Large diffs are not rendered by default.

dist/dynamics-web-api-callbacks.min.js

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

dist/dynamics-web-api.js

Lines changed: 140 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! dynamics-web-api v1.4.0 (c) 2017 Aleksandr Rogov */
1+
/*! dynamics-web-api v1.4.1 (c) 2018 Aleksandr Rogov */
22
(function webpackUniversalModuleDefinition(root, factory) {
33
if(typeof exports === 'object' && typeof module === 'object')
44
module.exports = factory();
@@ -762,9 +762,21 @@ if (!String.prototype.endsWith || !String.prototype.startsWith) {
762762
*/
763763

764764
/**
765-
* DynamicsWebApi - a Microsoft Dynamics CRM Web API helper library. Current version uses Promises instead of Callbacks.
766-
*
765+
* Constructor.
766+
* @constructor
767767
* @param {DWAConfig} [config] - configuration object
768+
* @example
769+
//Empty constructor (will work only inside CRM/D365)
770+
*var dynamicsWebApi = new DynamicsWebApi();
771+
* @example
772+
//Constructor with a configuration parameter (only for CRM/D365)
773+
*var dynamicsWebApi = new DynamicsWebApi({ webApiVersion: '9.0' });
774+
* @example
775+
//Constructor with a configuration parameter for CRM/D365 and Node.js
776+
*var dynamicsWebApi = new DynamicsWebApi({
777+
* webApiUrl: 'https:/myorg.api.crm.dynamics.com/api/data/v9.0/',
778+
* includeAnnotations: 'OData.Community.Display.V1.FormattedValue'
779+
*});
768780
*/
769781
function DynamicsWebApi(config) {
770782

@@ -786,6 +798,8 @@ function DynamicsWebApi(config) {
786798
* Sets the configuration parameters for DynamicsWebApi helper.
787799
*
788800
* @param {DWAConfig} config - configuration object
801+
* @example
802+
dynamicsWebApi.setConfig({ webApiVersion: '9.0' });
789803
*/
790804
this.setConfig = function (config) {
791805

@@ -833,20 +847,52 @@ function DynamicsWebApi(config) {
833847

834848
this.setConfig(config);
835849

836-
/**
837-
* Makes a request to web api
838-
*
839-
* @param {string} method - Method of the request.
840-
* @param {DWARequest} request - Request to Web Api
841-
* @param {string} [functionName] - Indictes the name of the function that called make request.
842-
* @returns {Promise}
843-
*/
844850
var _makeRequest = function (method, request, functionName) {
845851
return new Promise(function (resolve, reject) {
846852
Request.makeRequest(method, request, functionName, _internalConfig, resolve, reject);
847853
});
848854
};
849855

856+
/**
857+
* Sends an asynchronous request to create a new record.
858+
*
859+
* @param {DWARequest} request - An object that represents all possible options for a current request.
860+
* @returns {Promise}
861+
* @example
862+
*var lead = {
863+
* subject: "Test WebAPI",
864+
* firstname: "Test",
865+
* lastname: "WebAPI",
866+
* jobtitle: "Title"
867+
*};
868+
*
869+
*var request = {
870+
* entity: lead,
871+
* collection: "leads",
872+
* returnRepresentation: true
873+
*}
874+
*
875+
*dynamicsWebApi.createRequest(request).then(function (response) {
876+
*}).catch(function (error) {
877+
*});
878+
*/
879+
this.createRequest = function (request) {
880+
ErrorHelper.parameterCheck(request, 'DynamicsWebApi.create', 'request');
881+
882+
return _makeRequest('POST', request, 'create')
883+
.then(function (response) {
884+
if (response.data) {
885+
return response.data;
886+
}
887+
888+
var entityUrl = response.headers['OData-EntityId']
889+
? response.headers['OData-EntityId']
890+
: response.headers['odata-entityid'];
891+
var id = /[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(entityUrl)[0];
892+
return id;
893+
});
894+
};
895+
850896
/**
851897
* Sends an asynchronous request to create a new record.
852898
*
@@ -855,6 +901,17 @@ function DynamicsWebApi(config) {
855901
* @param {string|Array} [prefer] - Sets a Prefer header value. For example: ['retrun=representation', 'odata.include-annotations="*"']
856902
* @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned.
857903
* @returns {Promise}
904+
* @example
905+
*var lead = {
906+
* subject: "Test WebAPI",
907+
* firstname: "Test",
908+
* lastname: "WebAPI",
909+
* jobtitle: "Title"
910+
*};
911+
*
912+
*dynamicsWebApi.create(lead, "leads").then(function (id) {
913+
*}).catch(function (error) {
914+
*});
858915
*/
859916
this.create = function (object, collection, prefer, select) {
860917
ErrorHelper.parameterCheck(object, "DynamicsWebApi.create", "object");
@@ -875,25 +932,28 @@ function DynamicsWebApi(config) {
875932
entity: object
876933
};
877934

878-
return _makeRequest('POST', request, 'create')
879-
.then(function (response) {
880-
if (response.data) {
881-
return response.data;
882-
}
883-
884-
var entityUrl = response.headers['OData-EntityId']
885-
? response.headers['OData-EntityId']
886-
: response.headers['odata-entityid'];
887-
var id = /[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(entityUrl)[0];
888-
return id;
889-
});
935+
return this.createRequest(request);
890936
};
891937

892938
/**
893939
* Sends an asynchronous request to retrieve a record.
894940
*
895941
* @param {DWARequest} request - An object that represents all possible options for a current request.
896942
* @returns {Promise}
943+
* @example
944+
*var request = {
945+
* key: '7d577253-3ef0-4a0a-bb7f-8335c2596e70',
946+
* collection: "leads",
947+
* select: ["fullname", "subject"],
948+
* ifnonematch: 'W/"468026"',
949+
* includeAnnotations: "OData.Community.Display.V1.FormattedValue"
950+
*};
951+
*
952+
*dynamicsWebApi.retrieveRequest(request).then(function (response) {
953+
*
954+
*}).catch(function (error) {
955+
*
956+
*});
897957
*/
898958
this.retrieveRequest = function (request) {
899959
ErrorHelper.parameterCheck(request, 'DynamicsWebApi.retrieve', 'request');
@@ -1183,13 +1243,6 @@ function DynamicsWebApi(config) {
11831243
return this.upsertRequest(request);
11841244
}
11851245

1186-
/**
1187-
* Sends an asynchronous request to retrieve records.
1188-
*
1189-
* @param {DWARequest} request - An object that represents all possible options for a current request.
1190-
* @param {string} [nextPageLink] - Use the value of the @odata.nextLink property with a new GET request to return the next page of data. Pass null to retrieveMultipleOptions.
1191-
* @returns {Promise}
1192-
*/
11931246
var retrieveMultipleRequest = function (request, nextPageLink) {
11941247

11951248
if (nextPageLink) {
@@ -1211,6 +1264,13 @@ function DynamicsWebApi(config) {
12111264
});
12121265
};
12131266

1267+
/**
1268+
* Sends an asynchronous request to retrieve records.
1269+
*
1270+
* @param {DWARequest} request - An object that represents all possible options for a current request.
1271+
* @param {string} [nextPageLink] - Use the value of the @odata.nextLink property with a new GET request to return the next page of data. Pass null to retrieveMultipleOptions.
1272+
* @returns {Promise}
1273+
*/
12141274
this.retrieveMultipleRequest = retrieveMultipleRequest;
12151275

12161276
var _retrieveAllRequest = function (request, nextPageLink, records) {
@@ -1324,17 +1384,6 @@ function DynamicsWebApi(config) {
13241384
});
13251385
}
13261386

1327-
/**
1328-
* Sends an asynchronous request to execute FetchXml to retrieve records. Returns: DWA.Types.FetchXmlResponse
1329-
*
1330-
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
1331-
* @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation.
1332-
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
1333-
* @param {number} [pageNumber] - Page number.
1334-
* @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null.
1335-
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
1336-
* @returns {Promise}
1337-
*/
13381387
var executeFetchXml = function (collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) {
13391388

13401389
ErrorHelper.stringParameterCheck(fetchXml, "DynamicsWebApi.executeFetchXml", "fetchXml");
@@ -1383,7 +1432,20 @@ function DynamicsWebApi(config) {
13831432
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
13841433
* @returns {Promise}
13851434
*/
1386-
this.fetch = this.executeFetchXml = executeFetchXml;
1435+
this.fetch = executeFetchXml;
1436+
1437+
/**
1438+
* Sends an asynchronous request to execute FetchXml to retrieve records. Returns: DWA.Types.FetchXmlResponse
1439+
*
1440+
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
1441+
* @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation.
1442+
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
1443+
* @param {number} [pageNumber] - Page number.
1444+
* @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null.
1445+
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
1446+
* @returns {Promise}
1447+
*/
1448+
this.executeFetchXml = executeFetchXml;
13871449

13881450
var _executeFetchXmlAll = function (collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records) {
13891451
var records = records || [];
@@ -1399,6 +1461,10 @@ function DynamicsWebApi(config) {
13991461
});
14001462
}
14011463

1464+
var innerExecuteFetchXmlAll = function (collection, fetchXml, includeAnnotations, impersonateUserId) {
1465+
return _executeFetchXmlAll(collection, fetchXml, includeAnnotations, null, null, impersonateUserId);
1466+
}
1467+
14021468
/**
14031469
* Sends an asynchronous request to execute FetchXml to retrieve all records.
14041470
*
@@ -1408,9 +1474,18 @@ function DynamicsWebApi(config) {
14081474
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
14091475
* @returns {Promise}
14101476
*/
1411-
this.fetchAll = this.executeFetchXmlAll = function (collection, fetchXml, includeAnnotations, impersonateUserId) {
1412-
return _executeFetchXmlAll(collection, fetchXml, includeAnnotations, null, null, impersonateUserId);
1413-
}
1477+
this.fetchAll = innerExecuteFetchXmlAll;
1478+
1479+
/**
1480+
* Sends an asynchronous request to execute FetchXml to retrieve all records.
1481+
*
1482+
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
1483+
* @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation.
1484+
* @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie
1485+
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
1486+
* @returns {Promise}
1487+
*/
1488+
this.executeFetchXmlAll = innerExecuteFetchXmlAll;
14141489

14151490
/**
14161491
* Associate for a collection-valued navigation property. (1:N or N:N)
@@ -1545,16 +1620,6 @@ function DynamicsWebApi(config) {
15451620
return _executeFunction(functionName, parameters, collection, id, impersonateUserId);
15461621
}
15471622

1548-
/**
1549-
* Executes a function
1550-
*
1551-
* @param {string} id - A String representing the GUID value for the record.
1552-
* @param {string} collection - The name of the Entity Collection or Entity Logical name.
1553-
* @param {string} functionName - The name of the function.
1554-
* @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }.
1555-
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
1556-
* @returns {Promise}
1557-
*/
15581623
var _executeFunction = function (functionName, parameters, collection, id, impersonateUserId, isUnbound) {
15591624

15601625
ErrorHelper.stringParameterCheck(functionName, "DynamicsWebApi.executeFunction", "functionName");
@@ -1600,16 +1665,6 @@ function DynamicsWebApi(config) {
16001665
return _executeAction(actionName, requestObject, collection, id, impersonateUserId);
16011666
}
16021667

1603-
/**
1604-
* Executes a Web API action
1605-
*
1606-
* @param {string} [id] - A String representing the GUID value for the record.
1607-
* @param {string} [collection] - The name of the Entity Collection or Entity Logical name.
1608-
* @param {string} actionName - The name of the Web API action.
1609-
* @param {Object} requestObject - Action request body object.
1610-
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user.
1611-
* @returns {Promise}
1612-
*/
16131668
var _executeAction = function (actionName, requestObject, collection, id, impersonateUserId, isUnbound) {
16141669

16151670
ErrorHelper.stringParameterCheck(actionName, "DynamicsWebApi.executeAction", "actionName");
@@ -1645,10 +1700,27 @@ function DynamicsWebApi(config) {
16451700
}
16461701
};
16471702

1703+
/**
1704+
* DynamicsWebApi Utility helper class
1705+
* @typicalname dynamicsWebApi.utility
1706+
*/
16481707
DynamicsWebApi.prototype.utility = {
1708+
/**
1709+
* Searches for a collection name by provided entity name in a cached entity metadata.
1710+
* The returned collection name can be null.
1711+
*
1712+
* @param {string} entityName - entity name
1713+
* @returns {string} a collection name
1714+
*/
16491715
getCollectionName: Request.getCollectionName
16501716
};
16511717

1718+
/**
1719+
* Microsoft Dynamics CRM Web API helper library written in JavaScript.
1720+
* It is compatible with: Dynamics 365 (online), Dynamics 365 (on-premise), Dynamics CRM 2016, Dynamics CRM Online.
1721+
* @module dynamics-web-api
1722+
* @typicalname dynamicsWebApi
1723+
*/
16521724
module.exports = DynamicsWebApi;
16531725

16541726
/***/ }),
@@ -1945,7 +2017,9 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
19452017

19462018
if (request.filter) {
19472019
ErrorHelper.stringParameterCheck(request.filter, 'DynamicsWebApi.' + functionName, "request.filter");
1948-
requestArray.push("$filter=" + request.filter);
2020+
var removeBracketsFromGuidReg = /[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g;
2021+
var filterResult = request.filter.replace(removeBracketsFromGuidReg, ' $1 ').trim();
2022+
requestArray.push("$filter=" + filterResult);
19492023
}
19502024

19512025
if (request.savedQuery) {

dist/dynamics-web-api.min.js

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

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dynamics-web-api",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "DynamicsWebApi is a Microsoft Dynamics CRM Web API helper library",
55
"keywords": [
66
"crm",

0 commit comments

Comments
 (0)