diff --git a/dist/dwa.js b/dist/dwa.js index d4bc660..64fba89 100644 --- a/dist/dwa.js +++ b/dist/dwa.js @@ -1,4 +1,4 @@ -/*! dwa v1.3.4 (c) 2017 Aleksandr Rogov */ +/*! dwa v1.4.0 (c) 2017 Aleksandr Rogov */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); diff --git a/dist/dynamics-web-api-callbacks.js b/dist/dynamics-web-api-callbacks.js index 0b960e4..f8fb2e6 100644 --- a/dist/dynamics-web-api-callbacks.js +++ b/dist/dynamics-web-api-callbacks.js @@ -1,4 +1,4 @@ -/*! dynamics-web-api-callbacks v1.3.4 (c) 2017 Aleksandr Rogov */ +/*! dynamics-web-api-callbacks v1.4.0 (c) 2017 Aleksandr Rogov */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); @@ -484,6 +484,11 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) { ErrorHelper.parameterCheck(request.data, 'DynamicsWebApi.' + functionName, 'request.data') } + if (request.noCache) { + ErrorHelper.boolParameterCheck(request.noCache, 'DynamicsWebApi.' + functionName, 'request.noCache'); + headers['Cache-Control'] = 'no-cache'; + } + if (request.expand && request.expand.length) { ErrorHelper.stringOrArrayParameterCheck(request.expand, 'DynamicsWebApi.' + functionName, "request.expand"); if (typeof request.expand === 'string') { @@ -706,6 +711,38 @@ var DWA = __webpack_require__(0); var Utility = __webpack_require__(4); var RequestConverter = __webpack_require__(3); +var _entityNames; + +/** + * Searches for a collection name by provided entity name in a cached entity metadata. + * The returned collection name can be null. + * + * @param {string} entityName - entity name + * @returns {string} - a collection name + */ +function findCollectionName(entityName) { + var xrmInternal = Utility.getXrmInternal(); + if (!Utility.isNull(xrmInternal)) { + var collectionName = xrmInternal.getEntitySetName(entityName); + return collectionName || entityName; + } + + var collectionName = null; + + if (!Utility.isNull(_entityNames)) { + collectionName = _entityNames[entityName]; + if (Utility.isNull(collectionName)) { + for (var key in _entityNames) { + if (_entityNames[key] == entityName) { + return entityName; + } + } + } + } + + return collectionName; +} + function setStandardHeaders(additionalHeaders) { additionalHeaders["Accept"] = "application/json"; additionalHeaders["OData-MaxVersion"] = "4.0"; @@ -720,12 +757,26 @@ function stringifyData(data, config) { if (data) { stringifiedData = JSON.stringify(data, function (key, value) { /// Description - if (key.endsWith("@odata.bind")) { - if (typeof value === "string") { + if (key.endsWith('@odata.bind') || key.endsWith('@odata.id')) { + if (typeof value === 'string') { //remove brackets in guid if (/\(\{[\w\d-]+\}\)/g.test(value)) { value = value.replace(/(.+)\(\{([\w\d-]+)\}\)/g, '$1($2)'); } + + if (config.useEntityNames) { + //replace entity name with collection name + var regularExpression = /([\w_]+)(\([\d\w-]+\))$/; + var valueParts = regularExpression.exec(value); + if (valueParts.length > 2) { + var collectionName = findCollectionName(valueParts[1]); + + if (!Utility.isNull(collectionName)) { + value = value.replace(regularExpression, collectionName + '$2'); + } + } + } + //add full web api url if it's not set if (!value.startsWith(config.webApiUrl)) { value = config.webApiUrl + value.replace(/^\\/, ''); @@ -822,26 +873,25 @@ function sendRequest(method, path, config, data, additionalHeaders, successCallb } }; -var _entityNames; - function _getEntityNames(entityName, config, successCallback, errorCallback) { var resolve = function (result) { _entityNames = {}; - for (var i = 0; i < result.length; i++) { - _entityNames[result[i].LogicalName] = result[i].LogicalCollectionName; + for (var i = 0; i < result.data.value.length; i++) { + _entityNames[result.data.value[i].LogicalName] = result.data.value[i].LogicalCollectionName; } - successCallback(_entityNames[entityName]); + successCallback(findCollectionName(entityName)); }; var reject = function (error) { - errorCallback({ message: 'Cannot fetch EntityDefinitions. Error: ' + error.message }); + errorCallback({ message: 'Unable to fetch EntityDefinitions. Error: ' + error.message }); }; var request = RequestConverter.convertRequest({ collection: 'EntityDefinitions', - select: ['LogicalCollectionName', 'LogicalName'] + select: ['LogicalCollectionName', 'LogicalName'], + noCache: true }, 'retrieveMultiple', config); sendRequest('GET', request.url, config, null, request.headers, resolve, reject, request.async); @@ -868,17 +918,13 @@ function _getCollectionName(entityName, config, successCallback, errorCallback) } try { - var xrmInternal = Utility.getXrmInternal(); - if (!Utility.isNull(xrmInternal)) { - successCallback(xrmInternal.getEntitySetName(entityName)); + var collectionName = findCollectionName(entityName); + + if (Utility.isNull(collectionName)) { + _getEntityNames(entityName, config, successCallback, errorCallback); } else { - if (Utility.isNull(_entityNames)) { - _getEntityNames(entityName, config, successCallback, errorCallback); - } - else { - successCallback(_entityNames[entityName]); - } + successCallback(collectionName); } } catch (error) { @@ -897,7 +943,9 @@ function makeRequest(method, request, functionName, config, resolve, reject) { module.exports = { sendRequest: sendRequest, - makeRequest: makeRequest + makeRequest: makeRequest, + getCollectionName: findCollectionName, + } /***/ }), @@ -927,9 +975,35 @@ if (!String.prototype.endsWith || !String.prototype.startsWith) { * @property {string} includeAnnotations - Sets Prefer header with value "odata.include-annotations=" and the specified annotation. Annotations provide additional information about lookups, options sets and other complex attribute types. * @property {string} maxPageSize - Sets the odata.maxpagesize preference value to request the number of entities returned in the response. * @property {boolean} returnRepresentation - Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request. - * @property {boolean} useEntityNames - Indicates whether to use Entity Logical Names instead of Collection Logical Names + * @property {boolean} useEntityNames - Indicates whether to use Entity Logical Names instead of Collection Logical Names. */ +/** + * Dynamics Web Api Request + * @typedef {Object} DWARequest + * @property {boolean} async - XHR requests only! Indicates whether the requests should be made synchronously or asynchronously. Default value is true (asynchronously). + * @property {string} collection - The name of the Entity Collection or Entity Logical name. + * @property {string} id - A String representing the Primary Key (GUID) of the record. + * @property {Array} select - An Array (of Strings) representing the $select OData System Query Option to control which attributes will be returned. + * @property {Array} expand - An array of Expand Objects (described below the table) representing the $expand OData System Query Option value to control which related records are also returned. + * @property {string} key - A String representing collection record's Primary Key (GUID) or Alternate Key(s). + * @property {string} filter - Use the $filter system query option to set criteria for which entities will be returned. + * @property {number} maxPageSize - Sets the odata.maxpagesize preference value to request the number of entities returned in the response. + * @property {boolean} count - Boolean that sets the $count system query option with a value of true to include a count of entities that match the filter criteria up to 5000 (per page). Do not use $top with $count! + * @property {number} top - Limit the number of results returned by using the $top system query option. Do not use $top with $count! + * @property {Array} orderBy - An Array (of Strings) representing the order in which items are returned using the $orderby system query option. Use the asc or desc suffix to specify ascending or descending order respectively. The default is ascending if the suffix isn't applied. + * @property {string} includeAnnotations - Sets Prefer header with value "odata.include-annotations=" and the specified annotation. Annotations provide additional information about lookups, options sets and other complex attribute types. + * @property {string} ifmatch - Sets If-Match header value that enables to use conditional retrieval or optimistic concurrency in applicable requests. + * @property {string} ifnonematch - Sets If-None-Match header value that enables to use conditional retrieval in applicable requests. + * @property {boolean} returnRepresentation - Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request. + * @property {Object} entity - A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties). + * @property {string} impersonate - Impersonates the user. A String representing the GUID value for the Dynamics 365 system user id. + * @property {string} navigationProperty - A String representing the name of a single-valued navigation property. Useful when needed to retrieve information about a related record in a single request. + * @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'. + * @property {string} savedQuery - A String representing the GUID value of the saved query. + * @property {string} userQuery - A String representing the GUID value of the user query. + */ + /** * DynamicsWebApi - a Microsoft Dynamics CRM Web API helper library. Current version uses Promises instead of Callbacks. * @@ -1006,7 +1080,7 @@ function DynamicsWebApi(config) { * Makes a request to web api * * @param {string} method - Method of the request. - * @param {Object} request - Request to Web Api + * @param {DWARequest} request - Request to Web Api * @param {string} [functionName] - Indictes the name of the function that called make request. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1019,7 +1093,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to create a new record. * * @param {Object} object - A JavaScript object valid for create operations. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @param {string|Array} [prefer] - Sets a Prefer header value. For example: ['retrun=representation', 'odata.include-annotations="*"']. @@ -1068,7 +1142,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to update a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. */ @@ -1108,7 +1182,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to update a record. * * @param {string} key - A String representing the GUID value or Alternate Key(s) for the record to update. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Object} object - A JavaScript object valid for update operations. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1147,7 +1221,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to update a single value in the record. * * @param {string} key - A String representing the GUID value or Alternate Key(s) for the record to update. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Object} keyValuePair - keyValuePair object with a logical name of the field as a key and a value to update with. Example: {subject: "Update Record"} * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1195,7 +1269,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to delete a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. */ @@ -1229,7 +1303,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to delete a record. * * @param {string} key - A String representing the GUID value or Alternate Key(s) for the record to delete. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @param {string} [propertyName] - The name of the property which needs to be emptied. Instead of removing a whole record only the specified property will be cleared. @@ -1262,7 +1336,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. */ @@ -1290,7 +1364,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to retrieve a record. * * @param {string} key - A String representing the GUID value or Alternate Key(s) for the record to retrieve. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. @@ -1325,7 +1399,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to upsert a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. */ @@ -1377,7 +1451,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to upsert a record. * * @param {string} key - A String representing the GUID value or Alternate Key(s) for the record to upsert. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Object} object - A JavaScript object valid for update operations. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1417,7 +1491,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to count records. IMPORTANT! The count value does not represent the total number of entities in the system. It is limited by the maximum number of entities that can be returned. Returns: Number * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. @@ -1456,7 +1530,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to count records. Returns: Number * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. @@ -1477,7 +1551,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve records. * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1496,7 +1570,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve all records. * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @param {Array} [select] - Use the $select system query option to limit the properties returned. @@ -1513,7 +1587,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve records. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. * @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. @@ -1565,7 +1639,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve all records. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. */ @@ -1576,7 +1650,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to count records. Returns: DWA.Types.FetchXmlResponse * - * @param {string} collection - An object that represents all possible options for a current request. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1647,7 +1721,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to execute FetchXml to retrieve all records. * - * @param {string} collection - An object that represents all possible options for a current request. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1661,10 +1735,10 @@ function DynamicsWebApi(config) { /** * Associate for a collection-valued navigation property. (1:N or N:N) * - * @param {string} collection - Primary entity collection name. + * @param {string} collection - Primary Entity Collection name or Entity Name. * @param {string} primaryKey - Primary entity record id. * @param {string} relationshipName - Relationship name. - * @param {string} relatedCollection - Related colletion name. + * @param {string} relatedCollection - Related Entity Collection name or Entity Name. * @param {string} relatedKey - Related entity record id. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1689,7 +1763,7 @@ function DynamicsWebApi(config) { collection: collection, key: primaryKey, impersonate: impersonateUserId, - data: { "@odata.id": _internalConfig.webApiUrl + relatedCollection + "(" + relatedKey + ")" } + data: { "@odata.id": relatedCollection + "(" + relatedKey + ")" } }; _makeRequest('POST', request, 'associate', onSuccess, errorCallback); @@ -1698,7 +1772,7 @@ function DynamicsWebApi(config) { /** * Disassociate for a collection-valued navigation property. * - * @param {string} collection - Primary entity collection name. + * @param {string} collection - Primary Entity Collection name or Entity Name. * @param {string} primaryKey - Primary entity record id. * @param {string} relationshipName - Relationship name. * @param {string} relatedKey - Related entity record id. @@ -1732,7 +1806,7 @@ function DynamicsWebApi(config) { /** * Associate for a single-valued navigation property. (1:N) * - * @param {string} collection - Entity collection name that contains an attribute. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} key - Entity record Id that contains an attribute. * @param {string} singleValuedNavigationPropertyName - Single-valued navigation property name (usually it's a Schema Name of the lookup attribute). * @param {string} relatedCollection - Related collection name that the lookup (attribute) points to. @@ -1760,7 +1834,7 @@ function DynamicsWebApi(config) { collection: collection, key: key, impersonate: impersonateUserId, - data: { "@odata.id": _internalConfig.webApiUrl + relatedCollection + "(" + relatedKey + ")" } + data: { "@odata.id": relatedCollection + "(" + relatedKey + ")" } }; _makeRequest('PUT', request, 'associateSingleValued', onSuccess, errorCallback); @@ -1769,7 +1843,7 @@ function DynamicsWebApi(config) { /** * Removes a reference to an entity for a single-valued navigation property. (1:N) * - * @param {string} collection - Entity collection name that contains an attribute. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} key - Entity record Id that contains an attribute. * @param {string} singleValuedNavigationPropertyName - Single-valued navigation property name (usually it's a Schema Name of the lookup attribute). * @param {Function} successCallback - The function that will be passed through and be called by a successful response. @@ -1815,7 +1889,7 @@ function DynamicsWebApi(config) { * Executes a bound function * * @param {string} id - A String representing the GUID value for the record. - * @param {string} collection - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} functionName - The name of the function. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1830,7 +1904,7 @@ function DynamicsWebApi(config) { * Executes a function * * @param {string} id - A String representing the GUID value for the record. - * @param {string} collection - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} functionName - The name of the function. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. * @param {Function} errorCallback - The function that will be passed through and be called by a failed response. @@ -1878,7 +1952,7 @@ function DynamicsWebApi(config) { * Executes a bound Web API action (bound to a particular entity record) * * @param {string} id - A String representing the GUID value for the record. - * @param {string} collection - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} actionName - The name of the Web API action. * @param {Object} requestObject - Action request body object. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. @@ -1893,7 +1967,7 @@ function DynamicsWebApi(config) { * Executes a Web API action * * @param {string} [id] - A String representing the GUID value for the record. - * @param {string} [collection] - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} [collection] - The name of the Entity Collection or Entity Logical name. * @param {string} actionName - The name of the Web API action. * @param {Object} requestObject - Action request body object. * @param {Function} successCallback - The function that will be passed through and be called by a successful response. @@ -1940,6 +2014,10 @@ function DynamicsWebApi(config) { } }; +DynamicsWebApi.prototype.utility = { + getCollectionName: Request.getCollectionName +}; + module.exports = DynamicsWebApi; /***/ }), diff --git a/dist/dynamics-web-api-callbacks.min.js b/dist/dynamics-web-api-callbacks.min.js index 30b3036..ea4d4d2 100644 --- a/dist/dynamics-web-api-callbacks.min.js +++ b/dist/dynamics-web-api-callbacks.min.js @@ -1,2 +1,2 @@ -/*! dynamics-web-api-callbacks v1.3.4 (c) 2017 Aleksandr Rogov */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DynamicsWebApi",[],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(r){if(a[r])return a[r].exports;var n=a[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var a={};return t.m=e,t.c=a,t.i=function(e){return e},t.d=function(e,a,r){t.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(a,"a",a),a},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=6)}([function(e,t){var a={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){a.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){a.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){a.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){a.Types.ResponseBase.call(this),this.value=[],this.PagingInfo={cookie:"",page:0,nextPage:1}}},Prefer:{ReturnRepresentation:"return=representation",Annotations:{AssociatedNavigationProperty:"Microsoft.Dynamics.CRM.associatednavigationproperty",LookupLogicalName:"Microsoft.Dynamics.CRM.lookuplogicalname",All:"*",FormattedValue:"OData.Community.Display.V1.FormattedValue",FetchXmlPagingCookie:"Microsoft.Dynamics.CRM.fetchxmlpagingcookie"}}};e.exports=a},function(e,t){function a(e,t,a){throw new Error(a?e+" requires the "+t+" parameter to be of type "+a:e+" requires the "+t+" parameter.")}var r={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,r,n){void 0!==e&&null!==e&&""!=e||a(t,r,n)},stringParameterCheck:function(e,t,r){"string"!=typeof e&&a(t,r,"String")},arrayParameterCheck:function(e,t,r){e.constructor!==Array&&a(t,r,"Array")},stringOrArrayParameterCheck:function(e,t,r){e.constructor!==Array&&"string"!=typeof e&&a(t,r,"String or Array")},numberParameterCheck:function(e,t,r){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;a(t,r,"Number")}},boolParameterCheck:function(e,t,r){"boolean"!=typeof e&&a(t,r,"Boolean")},guidParameterCheck:function(e,t,r){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){a(t,r,"GUID String")}},keyParameterCheck:function(e,t,n){try{r.stringParameterCheck(e,t,n);var i=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e);if(i)return i[0];var c=e.split(",");if(c.length)for(var s=0;sa.length)&&(t=a.length),t-=e.length;var r=a.lastIndexOf(e,t);return-1!==r&&r===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,a){function r(e,t,a,n,s){var o={},l=[];if(n=null!=n?n:"&",e){e.navigationProperty&&(i.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),a+="/"+e.navigationProperty),null!=e.select&&e.select.length&&(i.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?a+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?a+=e.select.shift():e.select.shift()),e.select.length&&l.push("$select="+e.select.join(",")))),e.filter&&(i.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter"),l.push("$filter="+e.filter)),e.savedQuery&&l.push("savedQuery="+i.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&l.push("userQuery="+i.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(i.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),l.push("$count="+e.count)),e.top&&e.top>0&&(i.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),l.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(i.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),l.push("$orderby="+e.orderBy.join(",")));var u=c(e,t,s);if(u.length&&(o.Prefer=u),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(i.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),o["If-Match"]=e.ifmatch),e.ifnonematch&&(i.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),o["If-None-Match"]=e.ifnonematch),e.impersonate&&(i.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),o.MSCRMCallerID=i.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(i.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),o.Authorization="Bearer "+e.token),e.duplicateDetection&&(i.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),o["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&i.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&i.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.expand&&e.expand.length)if(i.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)l.push("$expand="+e.expand);else{for(var p=[],m=0;m2e3){var h="dwa_batch_"+p.generateUUID(),y=[];y.push("--"+h),y.push("Content-Type: application/http"),y.push("Content-Transfer-Encoding: binary\n"),y.push(e+" "+i.webApiUrl+t+" HTTP/1.1");for(var f in s)y.push(f+": "+s[f]),delete s[f];y.push("\n--"+h+"--"),m=y.join("\n"),s=r(s),s["Content-Type"]="multipart/mixed;boundary="+h,t="$batch",e="POST"}i.impersonate&&!s.MSCRMCallerID&&(s.MSCRMCallerID=i.impersonate);var d;d=a(10);var k=function(a){a&&(s||(s={}),s.Authorization="Bearer "+a.accessToken),d(e,i.webApiUrl+t,m,s,o,l,u)};i.onTokenRefresh&&(!s||s&&!s.Authorization)?i.onTokenRefresh(k):k()}function c(e,t,a,r){var n=function(t){u={};for(var r=0;r-1}function o(e,t,a,r){if(s(e)||p.isNull(e))return void a(e);if(e=e.toLowerCase(),!t.useEntityNames)return void a(e);try{var n=p.getXrmInternal();p.isNull(n)?p.isNull(u)?c(e,t,a,r):a(u[e]):a(n.getEntitySetName(e))}catch(e){r({message:"Unable to fetch Collection Names. Error: "+e.message})}}function l(e,t,a,r,n,c){var s=function(s){t.collection=s;var o=m.convertRequest(t,a,r);i(e,o.url,r,t.data||t.entity,o.headers,n,c,o.async)};o(t.collection,r,s,c)}var u,p=(a(0),a(4)),m=a(3);e.exports={sendRequest:i,makeRequest:l}},function(e,t,a){function r(e){var t={webApiVersion:"8.0",webApiUrl:"",impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(s.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(s.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=i.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=s.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(s.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(s.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(s.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(s.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(s.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var a=function(e,a,r,n,i){o.makeRequest(e,a,r,t,n,i)};this.create=function(e,r,n,i,o,l){s.parameterCheck(e,"DynamicsWebApi.create","object"),s.stringParameterCheck(r,"DynamicsWebApi.create","collection"),s.callbackParameterCheck(n,"DynamicsWebApi.create","successCallback"),s.callbackParameterCheck(i,"DynamicsWebApi.create","errorCallback"),o&&s.stringOrArrayParameterCheck(o,"DynamicsWebApi.create","prefer"),l&&s.arrayParameterCheck(l,"DynamicsWebApi.create","select");var u={collection:r,select:l,prefer:o,entity:e};c.convertRequest(u,"create",t);a("POST",u,"create",function(e){if(e.data)n(e.data);else{var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"],a=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0];n(a)}},i)},this.updateRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.update","request"),s.callbackParameterCheck(t,"DynamicsWebApi.update","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.update","errorCallback"),null==e.ifmatch&&(e.ifmatch="*");var n=function(e){t(e.data?e.data:!0)},i=e.ifmatch;a("PATCH",e,"update",n,function(e){i&&412==e.status?t(!1):r(e)})},this.update=function(e,t,a,r,n,i,c){s.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.update","key"),s.parameterCheck(a,"DynamicsWebApi.update","object"),s.stringParameterCheck(t,"DynamicsWebApi.update","collection"),s.callbackParameterCheck(r,"DynamicsWebApi.update","successCallback"),s.callbackParameterCheck(n,"DynamicsWebApi.update","errorCallback"),i&&s.stringOrArrayParameterCheck(i,"DynamicsWebApi.update","prefer"),c&&s.arrayParameterCheck(c,"DynamicsWebApi.update","select");var o={collection:t,key:e,select:c,prefer:i,entity:a};this.updateRequest(o,r,n)},this.updateSingleProperty=function(e,t,r,n,i,c,o){s.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),s.parameterCheck(r,"DynamicsWebApi.updateSingleProperty","keyValuePair"),s.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection"),s.callbackParameterCheck(n,"DynamicsWebApi.updateSingleProperty","successCallback"),s.callbackParameterCheck(i,"DynamicsWebApi.updateSingleProperty","errorCallback"),c&&s.stringOrArrayParameterCheck(c,"DynamicsWebApi.updateSingleProperty","prefer"),o&&s.arrayParameterCheck(o,"DynamicsWebApi.updateSingleProperty","select");var l=Object.keys(r)[0],u=r[l];a("PUT",{collection:t,key:e,select:o,prefer:c,navigationProperty:l,data:{value:u}},"updateSingleProperty",function(e){e.data?n(e.data):n()},i)},this.deleteRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.delete","request"),s.callbackParameterCheck(t,"DynamicsWebApi.delete","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.delete","errorCallback");var n=function(){t(!0)},i=e.ifmatch;a("DELETE",e,"delete",n,function(e){i&&412==e.status?t(!1):r(e)})},this.deleteRecord=function(e,t,r,n,i){s.stringParameterCheck(e,"DynamicsWebApi.delete","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.delete","key"),s.stringParameterCheck(t,"DynamicsWebApi.delete","collection"),s.callbackParameterCheck(r,"DynamicsWebApi.delete","successCallback"),s.callbackParameterCheck(n,"DynamicsWebApi.delete","errorCallback"),null!=i&&s.stringParameterCheck(i,"DynamicsWebApi.delete","propertyName"),a("DELETE",{key:e,collection:t,navigationProperty:i},"delete",function(e){r()},n)},this.retrieveRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.retrieve","request"),s.callbackParameterCheck(t,"DynamicsWebApi.retrieve","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback");var n=e.select;a("GET",e,"retrieve",function(e){t(null!=n&&1==n.length&&n[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?i.convertToReferenceObject(e.data):e.data)},r)},this.retrieve=function(e,t,a,r,n,i){s.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),s.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),s.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback"),n&&n.length&&s.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),i&&i.length&&s.stringOrArrayParameterCheck(i,"DynamicsWebApi.retrieve","expand");var c={collection:t,key:e,select:n,expand:i};this.retrieveRequest(c,a,r)},this.upsertRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.upsert","request"),s.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity"),s.callbackParameterCheck(t,"DynamicsWebApi.upsert","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.upsert","errorCallback");var n=e.ifnonematch,i=e.ifmatch;a("PATCH",e,"upsert",function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var a=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"],r=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(a)[0];t(r)}else e.data?t(e.data):t()},function(e){n&&412==e.status?t():i&&404==e.status?t():r(e)})},this.upsert=function(e,t,a,r,n,i,c){s.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),s.parameterCheck(a,"DynamicsWebApi.upsert","object"),s.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),s.callbackParameterCheck(r,"DynamicsWebApi.upsert","successCallback"),s.callbackParameterCheck(n,"DynamicsWebApi.upsert","errorCallback"),i&&s.stringOrArrayParameterCheck(i,"DynamicsWebApi.upsert","prefer"),c&&s.arrayParameterCheck(c,"DynamicsWebApi.upsert","select");var o={collection:t,key:e,select:c,prefer:i,entity:a};this.upsertRequest(o,r,n)},this.count=function(e,t,r,n){if(null!=n&&(null==n||n.length))return this.retrieveMultipleRequest({collection:e,filter:n,count:!0},function(e){t(e.oDataCount?e.oDataCount:0)},r);s.stringParameterCheck(e,"DynamicsWebApi.count","collection"),s.callbackParameterCheck(t,"DynamicsWebApi.count","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.count","errorCallback"),a("GET",{collection:e,navigationProperty:"$count"},"count",function(e){t(e.data?parseInt(e.data):0)},r)},this.countAll=function(e,t,a,r,n){return this.retrieveAllRequest({collection:e,filter:r,select:n},function(e){t(e&&e.value?e.value.length:0)},a)},this.retrieveMultiple=function(e,t,a,r,n,i){return this.retrieveMultipleRequest({collection:e,select:r,filter:n},t,a,i)},this.retrieveAll=function(e,t,a,r,n){return u({collection:e,select:r,filter:n},t,a)};var l=function(e,t,r,n){s.callbackParameterCheck(t,"DynamicsWebApi.retrieveMultiple","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.retrieveMultiple","errorCallback"),n&&(s.stringParameterCheck(n,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=n);var i=e.count;a("GET",e,"retrieveMultiple",function(e){i&&(e.data.oDataCount=e.data.oDataCount||0),t(e.data)},r)};this.retrieveMultipleRequest=l;var u=function(e,t,a,r,n){var n=n||[];l(e,function(r){n=n.concat(r.value),r.oDataNextLink?u(e,t,a,r.oDataNextLink,n):t({value:n})},a,r)};this.retrieveAllRequest=function(e,t,a){u(e,t,a)};var p=function(e,t,r,c,o,l,u,p){s.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","collection"),s.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),s.callbackParameterCheck(r,"DynamicsWebApi.executeFetchXml","successCallback"),s.callbackParameterCheck(c,"DynamicsWebApi.executeFetchXml","errorCallback"),l=l||1,s.numberParameterCheck(l,"DynamicsWebApi.executeFetchXml","pageNumber");var m='$1 page="'+l+'"';null!=u&&(s.stringParameterCheck(u,"DynamicsWebApi.executeFetchXml","pagingCookie"),m+=' paging-cookie="'+u+'"'),t=t.replace(/^(-1?r(e)[0]:JSON.parse(e,c),t=n(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var a=e.split("\r\n"),r=0,n=a.length;r0&&(t[i.substring(0,c)]=i.substring(c+2))}return t}},function(e,t,a){var r=a(8),n=a(9),i=function(e,t,a,i,c,s,o){var l=new XMLHttpRequest;l.open(e,t,o);for(var u in i)l.setRequestHeader(u,i[u]);l.onreadystatechange=function(){if(4===l.readyState){switch(l.status){case 200:case 201:case 204:case 304:var e=r(l.responseText),t={data:e,headers:n(l.getAllResponseHeaders()),status:l.status};c(t);break;default:var a;try{a=JSON.parse(l.response).error}catch(e){a=l.response.length>0?{message:l.response}:{message:"Unexpected Error"}}a.status=l.status,s(a)}l=null}},l.onerror=function(){s({message:"Network Error"}),l=null},l.ontimeout=function(e){s({message:"Request Timed Out"}),l=null},a?l.send(a):l.send()};e.exports=i},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),a="",r="",n=1;n<=t.length;n++){var i=t[n-1],c=e[i];n>1&&(a+=",",r+="&"),a+=i+"=@p"+n,r+="@p"+n+"="+("string"==typeof c?"'"+c+"'":c)}return"("+a+")?"+r}return"()"}},function(e,t,a){var r=a(0),n=a(1);e.exports=function(e,t,a){var i=e.returnRepresentation,c=e.includeAnnotations,s=e.maxPageSize;if(e.prefer&&e.prefer.length){n.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer");var o=e.prefer;"string"==typeof o&&(o=o.split(","));for(var l in o){var u=o[l].trim();u===r.Prefer.ReturnRepresentation?i=!0:u.startsWith("odata.include-annotations=")?c=u.replace("odata.include-annotations=","").replace(/"/g,""):u.startsWith("odata.maxpagesize=")&&(s=u.replace("odata.maxpagesize=","").replace(/"/g,""))}}a&&(null==i&&(i=a.returnRepresentation),c=c||a.includeAnnotations,s=s||a.maxPageSize);var o=[];return i&&(n.boolParameterCheck(i,"DynamicsWebApi."+t,"request.returnRepresentation"),o.push(r.Prefer.ReturnRepresentation)),c&&(n.stringParameterCheck(c,"DynamicsWebApi."+t,"request.includeAnnotations"),o.push('odata.include-annotations="'+c+'"')),s&&s>0&&(n.numberParameterCheck(s,"DynamicsWebApi."+t,"request.maxPageSize"),o.push("odata.maxpagesize="+s)),o.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e||"",t=t||1,e=unescape(unescape(e));var a=/pagingcookie="()/.exec(e);if(null!=a){var r=parseInt(a[2]);return{cookie:a[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:r,nextPage:r+1}}return{cookie:"",page:t,nextPage:t+1}}}])}); \ No newline at end of file +/*! dynamics-web-api-callbacks v1.4.0 (c) 2017 Aleksandr Rogov */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DynamicsWebApi",[],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(r){if(a[r])return a[r].exports;var n=a[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var a={};return t.m=e,t.c=a,t.i=function(e){return e},t.d=function(e,a,r){t.o(e,a)||Object.defineProperty(e,a,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var a=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(a,"a",a),a},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=6)}([function(e,t){var a={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){a.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){a.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){a.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){a.Types.ResponseBase.call(this),this.value=[],this.PagingInfo={cookie:"",page:0,nextPage:1}}},Prefer:{ReturnRepresentation:"return=representation",Annotations:{AssociatedNavigationProperty:"Microsoft.Dynamics.CRM.associatednavigationproperty",LookupLogicalName:"Microsoft.Dynamics.CRM.lookuplogicalname",All:"*",FormattedValue:"OData.Community.Display.V1.FormattedValue",FetchXmlPagingCookie:"Microsoft.Dynamics.CRM.fetchxmlpagingcookie"}}};e.exports=a},function(e,t){function a(e,t,a){throw new Error(a?e+" requires the "+t+" parameter to be of type "+a:e+" requires the "+t+" parameter.")}var r={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,r,n){void 0!==e&&null!==e&&""!=e||a(t,r,n)},stringParameterCheck:function(e,t,r){"string"!=typeof e&&a(t,r,"String")},arrayParameterCheck:function(e,t,r){e.constructor!==Array&&a(t,r,"Array")},stringOrArrayParameterCheck:function(e,t,r){e.constructor!==Array&&"string"!=typeof e&&a(t,r,"String or Array")},numberParameterCheck:function(e,t,r){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;a(t,r,"Number")}},boolParameterCheck:function(e,t,r){"boolean"!=typeof e&&a(t,r,"Boolean")},guidParameterCheck:function(e,t,r){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){a(t,r,"GUID String")}},keyParameterCheck:function(e,t,n){try{r.stringParameterCheck(e,t,n);var i=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e);if(i)return i[0];var c=e.split(",");if(c.length)for(var s=0;sa.length)&&(t=a.length),t-=e.length;var r=a.lastIndexOf(e,t);return-1!==r&&r===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,a){function r(e,t,a,n,s){var o={},l=[];if(n=null!=n?n:"&",e){e.navigationProperty&&(i.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),a+="/"+e.navigationProperty),null!=e.select&&e.select.length&&(i.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?a+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?a+=e.select.shift():e.select.shift()),e.select.length&&l.push("$select="+e.select.join(",")))),e.filter&&(i.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter"),l.push("$filter="+e.filter)),e.savedQuery&&l.push("savedQuery="+i.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&l.push("userQuery="+i.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(i.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),l.push("$count="+e.count)),e.top&&e.top>0&&(i.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),l.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(i.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),l.push("$orderby="+e.orderBy.join(",")));var u=c(e,t,s);if(u.length&&(o.Prefer=u),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(i.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),o["If-Match"]=e.ifmatch),e.ifnonematch&&(i.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),o["If-None-Match"]=e.ifnonematch),e.impersonate&&(i.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),o.MSCRMCallerID=i.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(i.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),o.Authorization="Bearer "+e.token),e.duplicateDetection&&(i.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),o["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&i.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&i.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.noCache&&(i.boolParameterCheck(e.noCache,"DynamicsWebApi."+t,"request.noCache"),o["Cache-Control"]="no-cache"),e.expand&&e.expand.length)if(i.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)l.push("$expand="+e.expand);else{for(var p=[],m=0;m2){var c=r(i[1]);m.isNull(c)||(a=a.replace(n,c+"$2"))}}a.startsWith(t.webApiUrl)||(a=t.webApiUrl+a.replace(/^\\/,""))}return a}),a=a.replace(/[\u007F-\uFFFF]/g,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4)})),a}function c(e,t,r,c,s,o,l,u){s||(s={}),s=n(s);var p=i(c,r);if(t.length>2e3){var h="dwa_batch_"+m.generateUUID(),y=[];y.push("--"+h),y.push("Content-Type: application/http"),y.push("Content-Transfer-Encoding: binary\n"),y.push(e+" "+r.webApiUrl+t+" HTTP/1.1");for(var f in s)y.push(f+": "+s[f]),delete s[f];y.push("\n--"+h+"--"),p=y.join("\n"),s=n(s),s["Content-Type"]="multipart/mixed;boundary="+h,t="$batch",e="POST"}r.impersonate&&!s.MSCRMCallerID&&(s.MSCRMCallerID=r.impersonate);var d;d=a(10);var k=function(a){a&&(s||(s={}),s.Authorization="Bearer "+a.accessToken),d(e,r.webApiUrl+t,p,s,o,l,u)};r.onTokenRefresh&&(!s||s&&!s.Authorization)?r.onTokenRefresh(k):k()}function s(e,t,a,n){var i=function(t){p={};for(var n=0;n-1}function l(e,t,a,n){if(o(e)||m.isNull(e))return void a(e);if(e=e.toLowerCase(),!t.useEntityNames)return void a(e);try{var i=r(e);m.isNull(i)?s(e,t,a,n):a(i)}catch(e){n({message:"Unable to fetch Collection Names. Error: "+e.message})}}function u(e,t,a,r,n,i){var s=function(s){t.collection=s;var o=h.convertRequest(t,a,r);c(e,o.url,r,t.data||t.entity,o.headers,n,i,o.async)};l(t.collection,r,s,i)}var p,m=(a(0),a(4)),h=a(3);e.exports={sendRequest:c,makeRequest:u,getCollectionName:r}},function(e,t,a){function r(e){var t={webApiVersion:"8.0",webApiUrl:"",impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(s.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(s.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=i.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=s.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(s.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(s.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(s.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(s.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(s.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var a=function(e,a,r,n,i){o.makeRequest(e,a,r,t,n,i)};this.create=function(e,r,n,i,o,l){s.parameterCheck(e,"DynamicsWebApi.create","object"),s.stringParameterCheck(r,"DynamicsWebApi.create","collection"),s.callbackParameterCheck(n,"DynamicsWebApi.create","successCallback"),s.callbackParameterCheck(i,"DynamicsWebApi.create","errorCallback"),o&&s.stringOrArrayParameterCheck(o,"DynamicsWebApi.create","prefer"),l&&s.arrayParameterCheck(l,"DynamicsWebApi.create","select");var u={collection:r,select:l,prefer:o,entity:e};c.convertRequest(u,"create",t);a("POST",u,"create",function(e){if(e.data)n(e.data);else{var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"],a=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0];n(a)}},i)},this.updateRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.update","request"),s.callbackParameterCheck(t,"DynamicsWebApi.update","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.update","errorCallback"),null==e.ifmatch&&(e.ifmatch="*");var n=function(e){t(e.data?e.data:!0)},i=e.ifmatch;a("PATCH",e,"update",n,function(e){i&&412==e.status?t(!1):r(e)})},this.update=function(e,t,a,r,n,i,c){s.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.update","key"),s.parameterCheck(a,"DynamicsWebApi.update","object"),s.stringParameterCheck(t,"DynamicsWebApi.update","collection"),s.callbackParameterCheck(r,"DynamicsWebApi.update","successCallback"),s.callbackParameterCheck(n,"DynamicsWebApi.update","errorCallback"),i&&s.stringOrArrayParameterCheck(i,"DynamicsWebApi.update","prefer"),c&&s.arrayParameterCheck(c,"DynamicsWebApi.update","select");var o={collection:t,key:e,select:c,prefer:i,entity:a};this.updateRequest(o,r,n)},this.updateSingleProperty=function(e,t,r,n,i,c,o){s.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),s.parameterCheck(r,"DynamicsWebApi.updateSingleProperty","keyValuePair"),s.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection"),s.callbackParameterCheck(n,"DynamicsWebApi.updateSingleProperty","successCallback"),s.callbackParameterCheck(i,"DynamicsWebApi.updateSingleProperty","errorCallback"),c&&s.stringOrArrayParameterCheck(c,"DynamicsWebApi.updateSingleProperty","prefer"),o&&s.arrayParameterCheck(o,"DynamicsWebApi.updateSingleProperty","select");var l=Object.keys(r)[0],u=r[l];a("PUT",{collection:t,key:e,select:o,prefer:c,navigationProperty:l,data:{value:u}},"updateSingleProperty",function(e){e.data?n(e.data):n()},i)},this.deleteRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.delete","request"),s.callbackParameterCheck(t,"DynamicsWebApi.delete","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.delete","errorCallback");var n=function(){t(!0)},i=e.ifmatch;a("DELETE",e,"delete",n,function(e){i&&412==e.status?t(!1):r(e)})},this.deleteRecord=function(e,t,r,n,i){s.stringParameterCheck(e,"DynamicsWebApi.delete","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.delete","key"),s.stringParameterCheck(t,"DynamicsWebApi.delete","collection"),s.callbackParameterCheck(r,"DynamicsWebApi.delete","successCallback"),s.callbackParameterCheck(n,"DynamicsWebApi.delete","errorCallback"),null!=i&&s.stringParameterCheck(i,"DynamicsWebApi.delete","propertyName"),a("DELETE",{key:e,collection:t,navigationProperty:i},"delete",function(e){r()},n)},this.retrieveRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.retrieve","request"),s.callbackParameterCheck(t,"DynamicsWebApi.retrieve","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback");var n=e.select;a("GET",e,"retrieve",function(e){t(null!=n&&1==n.length&&n[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?i.convertToReferenceObject(e.data):e.data)},r)},this.retrieve=function(e,t,a,r,n,i){s.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),s.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),s.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback"),n&&n.length&&s.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),i&&i.length&&s.stringOrArrayParameterCheck(i,"DynamicsWebApi.retrieve","expand");var c={collection:t,key:e,select:n,expand:i};this.retrieveRequest(c,a,r)},this.upsertRequest=function(e,t,r){s.parameterCheck(e,"DynamicsWebApi.upsert","request"),s.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity"),s.callbackParameterCheck(t,"DynamicsWebApi.upsert","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.upsert","errorCallback");var n=e.ifnonematch,i=e.ifmatch;a("PATCH",e,"upsert",function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var a=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"],r=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(a)[0];t(r)}else e.data?t(e.data):t()},function(e){n&&412==e.status?t():i&&404==e.status?t():r(e)})},this.upsert=function(e,t,a,r,n,i,c){s.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=s.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),s.parameterCheck(a,"DynamicsWebApi.upsert","object"),s.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),s.callbackParameterCheck(r,"DynamicsWebApi.upsert","successCallback"),s.callbackParameterCheck(n,"DynamicsWebApi.upsert","errorCallback"),i&&s.stringOrArrayParameterCheck(i,"DynamicsWebApi.upsert","prefer"),c&&s.arrayParameterCheck(c,"DynamicsWebApi.upsert","select");var o={collection:t,key:e,select:c,prefer:i,entity:a};this.upsertRequest(o,r,n)},this.count=function(e,t,r,n){if(null!=n&&(null==n||n.length))return this.retrieveMultipleRequest({collection:e,filter:n,count:!0},function(e){t(e.oDataCount?e.oDataCount:0)},r);s.stringParameterCheck(e,"DynamicsWebApi.count","collection"),s.callbackParameterCheck(t,"DynamicsWebApi.count","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.count","errorCallback"),a("GET",{collection:e,navigationProperty:"$count"},"count",function(e){t(e.data?parseInt(e.data):0)},r)},this.countAll=function(e,t,a,r,n){return this.retrieveAllRequest({collection:e,filter:r,select:n},function(e){t(e&&e.value?e.value.length:0)},a)},this.retrieveMultiple=function(e,t,a,r,n,i){return this.retrieveMultipleRequest({collection:e,select:r,filter:n},t,a,i)},this.retrieveAll=function(e,t,a,r,n){return u({collection:e,select:r,filter:n},t,a)};var l=function(e,t,r,n){s.callbackParameterCheck(t,"DynamicsWebApi.retrieveMultiple","successCallback"),s.callbackParameterCheck(r,"DynamicsWebApi.retrieveMultiple","errorCallback"),n&&(s.stringParameterCheck(n,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=n);var i=e.count;a("GET",e,"retrieveMultiple",function(e){i&&(e.data.oDataCount=e.data.oDataCount||0),t(e.data)},r)};this.retrieveMultipleRequest=l;var u=function(e,t,a,r,n){var n=n||[];l(e,function(r){n=n.concat(r.value),r.oDataNextLink?u(e,t,a,r.oDataNextLink,n):t({value:n})},a,r)};this.retrieveAllRequest=function(e,t,a){u(e,t,a)};var p=function(e,t,r,c,o,l,u,p){s.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","collection"),s.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),s.callbackParameterCheck(r,"DynamicsWebApi.executeFetchXml","successCallback"),s.callbackParameterCheck(c,"DynamicsWebApi.executeFetchXml","errorCallback"),l=l||1,s.numberParameterCheck(l,"DynamicsWebApi.executeFetchXml","pageNumber");var m='$1 page="'+l+'"';null!=u&&(s.stringParameterCheck(u,"DynamicsWebApi.executeFetchXml","pagingCookie"),m+=' paging-cookie="'+u+'"'),t=t.replace(/^(-1?r(e)[0]:JSON.parse(e,c),t=n(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var a=e.split("\r\n"),r=0,n=a.length;r0&&(t[i.substring(0,c)]=i.substring(c+2))}return t}},function(e,t,a){var r=a(8),n=a(9),i=function(e,t,a,i,c,s,o){var l=new XMLHttpRequest;l.open(e,t,o);for(var u in i)l.setRequestHeader(u,i[u]);l.onreadystatechange=function(){if(4===l.readyState){switch(l.status){case 200:case 201:case 204:case 304:var e=r(l.responseText),t={data:e,headers:n(l.getAllResponseHeaders()),status:l.status};c(t);break;default:var a;try{a=JSON.parse(l.response).error}catch(e){a=l.response.length>0?{message:l.response}:{message:"Unexpected Error"}}a.status=l.status,s(a)}l=null}},l.onerror=function(){s({message:"Network Error"}),l=null},l.ontimeout=function(e){s({message:"Request Timed Out"}),l=null},a?l.send(a):l.send()};e.exports=i},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),a="",r="",n=1;n<=t.length;n++){var i=t[n-1],c=e[i];n>1&&(a+=",",r+="&"),a+=i+"=@p"+n,r+="@p"+n+"="+("string"==typeof c?"'"+c+"'":c)}return"("+a+")?"+r}return"()"}},function(e,t,a){var r=a(0),n=a(1);e.exports=function(e,t,a){var i=e.returnRepresentation,c=e.includeAnnotations,s=e.maxPageSize;if(e.prefer&&e.prefer.length){n.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer");var o=e.prefer;"string"==typeof o&&(o=o.split(","));for(var l in o){var u=o[l].trim();u===r.Prefer.ReturnRepresentation?i=!0:u.startsWith("odata.include-annotations=")?c=u.replace("odata.include-annotations=","").replace(/"/g,""):u.startsWith("odata.maxpagesize=")&&(s=u.replace("odata.maxpagesize=","").replace(/"/g,""))}}a&&(null==i&&(i=a.returnRepresentation),c=c||a.includeAnnotations,s=s||a.maxPageSize);var o=[];return i&&(n.boolParameterCheck(i,"DynamicsWebApi."+t,"request.returnRepresentation"),o.push(r.Prefer.ReturnRepresentation)),c&&(n.stringParameterCheck(c,"DynamicsWebApi."+t,"request.includeAnnotations"),o.push('odata.include-annotations="'+c+'"')),s&&s>0&&(n.numberParameterCheck(s,"DynamicsWebApi."+t,"request.maxPageSize"),o.push("odata.maxpagesize="+s)),o.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e||"",t=t||1,e=unescape(unescape(e));var a=/pagingcookie="()/.exec(e);if(null!=a){var r=parseInt(a[2]);return{cookie:a[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:r,nextPage:r+1}}return{cookie:"",page:t,nextPage:t+1}}}])}); \ No newline at end of file diff --git a/dist/dynamics-web-api.js b/dist/dynamics-web-api.js index 42056e4..9091e1b 100644 --- a/dist/dynamics-web-api.js +++ b/dist/dynamics-web-api.js @@ -1,4 +1,4 @@ -/*! dynamics-web-api v1.3.4 (c) 2017 Aleksandr Rogov */ +/*! dynamics-web-api v1.4.0 (c) 2017 Aleksandr Rogov */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); @@ -469,6 +469,38 @@ var DWA = __webpack_require__(0); var Utility = __webpack_require__(3); var RequestConverter = __webpack_require__(10); +var _entityNames; + +/** + * Searches for a collection name by provided entity name in a cached entity metadata. + * The returned collection name can be null. + * + * @param {string} entityName - entity name + * @returns {string} - a collection name + */ +function findCollectionName(entityName) { + var xrmInternal = Utility.getXrmInternal(); + if (!Utility.isNull(xrmInternal)) { + var collectionName = xrmInternal.getEntitySetName(entityName); + return collectionName || entityName; + } + + var collectionName = null; + + if (!Utility.isNull(_entityNames)) { + collectionName = _entityNames[entityName]; + if (Utility.isNull(collectionName)) { + for (var key in _entityNames) { + if (_entityNames[key] == entityName) { + return entityName; + } + } + } + } + + return collectionName; +} + function setStandardHeaders(additionalHeaders) { additionalHeaders["Accept"] = "application/json"; additionalHeaders["OData-MaxVersion"] = "4.0"; @@ -483,12 +515,26 @@ function stringifyData(data, config) { if (data) { stringifiedData = JSON.stringify(data, function (key, value) { /// Description - if (key.endsWith("@odata.bind")) { - if (typeof value === "string") { + if (key.endsWith('@odata.bind') || key.endsWith('@odata.id')) { + if (typeof value === 'string') { //remove brackets in guid if (/\(\{[\w\d-]+\}\)/g.test(value)) { value = value.replace(/(.+)\(\{([\w\d-]+)\}\)/g, '$1($2)'); } + + if (config.useEntityNames) { + //replace entity name with collection name + var regularExpression = /([\w_]+)(\([\d\w-]+\))$/; + var valueParts = regularExpression.exec(value); + if (valueParts.length > 2) { + var collectionName = findCollectionName(valueParts[1]); + + if (!Utility.isNull(collectionName)) { + value = value.replace(regularExpression, collectionName + '$2'); + } + } + } + //add full web api url if it's not set if (!value.startsWith(config.webApiUrl)) { value = config.webApiUrl + value.replace(/^\\/, ''); @@ -585,26 +631,25 @@ function sendRequest(method, path, config, data, additionalHeaders, successCallb } }; -var _entityNames; - function _getEntityNames(entityName, config, successCallback, errorCallback) { var resolve = function (result) { _entityNames = {}; - for (var i = 0; i < result.length; i++) { - _entityNames[result[i].LogicalName] = result[i].LogicalCollectionName; + for (var i = 0; i < result.data.value.length; i++) { + _entityNames[result.data.value[i].LogicalName] = result.data.value[i].LogicalCollectionName; } - successCallback(_entityNames[entityName]); + successCallback(findCollectionName(entityName)); }; var reject = function (error) { - errorCallback({ message: 'Cannot fetch EntityDefinitions. Error: ' + error.message }); + errorCallback({ message: 'Unable to fetch EntityDefinitions. Error: ' + error.message }); }; var request = RequestConverter.convertRequest({ collection: 'EntityDefinitions', - select: ['LogicalCollectionName', 'LogicalName'] + select: ['LogicalCollectionName', 'LogicalName'], + noCache: true }, 'retrieveMultiple', config); sendRequest('GET', request.url, config, null, request.headers, resolve, reject, request.async); @@ -631,17 +676,13 @@ function _getCollectionName(entityName, config, successCallback, errorCallback) } try { - var xrmInternal = Utility.getXrmInternal(); - if (!Utility.isNull(xrmInternal)) { - successCallback(xrmInternal.getEntitySetName(entityName)); + var collectionName = findCollectionName(entityName); + + if (Utility.isNull(collectionName)) { + _getEntityNames(entityName, config, successCallback, errorCallback); } else { - if (Utility.isNull(_entityNames)) { - _getEntityNames(entityName, config, successCallback, errorCallback); - } - else { - successCallback(_entityNames[entityName]); - } + successCallback(collectionName); } } catch (error) { @@ -660,7 +701,9 @@ function makeRequest(method, request, functionName, config, resolve, reject) { module.exports = { sendRequest: sendRequest, - makeRequest: makeRequest + makeRequest: makeRequest, + getCollectionName: findCollectionName, + } /***/ }), @@ -682,36 +725,40 @@ if (!String.prototype.endsWith || !String.prototype.startsWith) { /** * Configuration object for DynamicsWebApi * @typedef {object} DWAConfig - * @property {string} webApiUrl - A String representing a URL to Web API (webApiVersion not required if webApiUrl specified) [not used inside of CRM] + * @property {string} webApiUrl - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. * @property {string} webApiVersion - The version of Web API to use, for example: "8.1" - * @property {string} impersonate - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. + * @property {string} impersonate - A String representing a URL to Web API (webApiVersion not required if webApiUrl specified) [not used inside of CRM] * @property {Function} onTokenRefresh - A function that is called when a security token needs to be refreshed. * @property {string} includeAnnotations - Sets Prefer header with value "odata.include-annotations=" and the specified annotation. Annotations provide additional information about lookups, options sets and other complex attribute types. * @property {string} maxPageSize - Sets the odata.maxpagesize preference value to request the number of entities returned in the response. - * @property {string} returnRepresentation - Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request. - */ + * @property {boolean} returnRepresentation - Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request. + * @property {boolean} useEntityNames - Indicates whether to use Entity Logical Names instead of Collection Logical Names. +*/ /** * Dynamics Web Api Request * @typedef {Object} DWARequest - * @property {string} collection - * @property {string} id - * @property {Array} select - * @property {Array} expand - * @property {string} filter - * @property {number} maxPageSize - * @property {boolean} count - * @property {number} top - * @property {Array} orderBy - * @property {string} includeAnnotations - * @property {string} ifmatch - * @property {string} ifnonematch - * @property {boolean} returnRepresentation - * @property {Object} entity - * @property {string} impersonate: "", - * @property {string} navigationProperty: "", - * @property {string} savedQuery: "", - * @property {string} userQuery: "" + * @property {boolean} async - XHR requests only! Indicates whether the requests should be made synchronously or asynchronously. Default value is true (asynchronously). + * @property {string} collection - The name of the Entity Collection or Entity Logical name. + * @property {string} id - A String representing the Primary Key (GUID) of the record. + * @property {Array} select - An Array (of Strings) representing the $select OData System Query Option to control which attributes will be returned. + * @property {Array} expand - An array of Expand Objects (described below the table) representing the $expand OData System Query Option value to control which related records are also returned. + * @property {string} key - A String representing collection record's Primary Key (GUID) or Alternate Key(s). + * @property {string} filter - Use the $filter system query option to set criteria for which entities will be returned. + * @property {number} maxPageSize - Sets the odata.maxpagesize preference value to request the number of entities returned in the response. + * @property {boolean} count - Boolean that sets the $count system query option with a value of true to include a count of entities that match the filter criteria up to 5000 (per page). Do not use $top with $count! + * @property {number} top - Limit the number of results returned by using the $top system query option. Do not use $top with $count! + * @property {Array} orderBy - An Array (of Strings) representing the order in which items are returned using the $orderby system query option. Use the asc or desc suffix to specify ascending or descending order respectively. The default is ascending if the suffix isn't applied. + * @property {string} includeAnnotations - Sets Prefer header with value "odata.include-annotations=" and the specified annotation. Annotations provide additional information about lookups, options sets and other complex attribute types. + * @property {string} ifmatch - Sets If-Match header value that enables to use conditional retrieval or optimistic concurrency in applicable requests. + * @property {string} ifnonematch - Sets If-None-Match header value that enables to use conditional retrieval in applicable requests. + * @property {boolean} returnRepresentation - Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request. + * @property {Object} entity - A JavaScript object with properties corresponding to the logical name of entity attributes (exceptions are lookups and single-valued navigation properties). + * @property {string} impersonate - Impersonates the user. A String representing the GUID value for the Dynamics 365 system user id. + * @property {string} navigationProperty - A String representing the name of a single-valued navigation property. Useful when needed to retrieve information about a related record in a single request. + * @property {boolean} noCache - If set to 'true', DynamicsWebApi adds a request header 'Cache-Control: no-cache'. Default value is 'false'. + * @property {string} savedQuery - A String representing the GUID value of the saved query. + * @property {string} userQuery - A String representing the GUID value of the user query. */ /** @@ -790,7 +837,7 @@ function DynamicsWebApi(config) { * Makes a request to web api * * @param {string} method - Method of the request. - * @param {Object} request - Request to Web Api + * @param {DWARequest} request - Request to Web Api * @param {string} [functionName] - Indictes the name of the function that called make request. * @returns {Promise} */ @@ -804,7 +851,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to create a new record. * * @param {Object} object - A JavaScript object valid for create operations. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string|Array} [prefer] - Sets a Prefer header value. For example: ['retrun=representation', 'odata.include-annotations="*"'] * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. * @returns {Promise} @@ -845,7 +892,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @returns {Promise} */ this.retrieveRequest = function (request) { @@ -866,7 +913,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to retrieve a record. * * @param {string} key - A String representing the GUID value or Aternate Key for the record to retrieve. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. * @param {string|Array} [expand] - A String or Array of Expand Objects representing the $expand Query Option value to control which related records need to be returned. * @returns {Promise} @@ -898,7 +945,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to update a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @returns {Promise} */ this.updateRequest = function (request) { @@ -933,7 +980,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to update a record. * * @param {string} key - A String representing the GUID value or Alternate Key for the record to update. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Object} object - A JavaScript object valid for update operations. * @param {string} [prefer] - If set to "return=representation" the function will return an updated object * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. @@ -969,7 +1016,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to update a single value in the record. * * @param {string} key - A String representing the GUID value or Alternate Key for the record to update. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Object} keyValuePair - keyValuePair object with a logical name of the field as a key and a value to update with. Example: {subject: "Update Record"} * @param {string|Array} [prefer] - If set to "return=representation" the function will return an updated object * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. @@ -1013,7 +1060,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to delete a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @returns {Promise} */ this.deleteRequest = function (request) { @@ -1040,7 +1087,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to delete a record. * * @param {string} key - A String representing the GUID value or Alternate Key for the record to delete. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} [propertyName] - The name of the property which needs to be emptied. Instead of removing a whole record only the specified property will be cleared. * @returns {Promise} */ @@ -1064,7 +1111,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to upsert a record. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @returns {Promise} */ this.upsertRequest = function (request) { @@ -1103,7 +1150,7 @@ function DynamicsWebApi(config) { * Sends an asynchronous request to upsert a record. * * @param {string} key - A String representing the GUID value or Alternate Key for the record to upsert. - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Object} object - A JavaScript object valid for update operations. * @param {string|Array} [prefer] - If set to "return=representation" the function will return an updated object * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. @@ -1139,7 +1186,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve records. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @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. * @returns {Promise} */ @@ -1183,7 +1230,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve all records. * - * @param {Object} request - An object that represents all possible options for a current request. + * @param {DWARequest} request - An object that represents all possible options for a current request. * @returns {Promise} */ this.retrieveAllRequest = function (request) { @@ -1193,7 +1240,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to count records. IMPORTANT! The count value does not represent the total number of entities in the system. It is limited by the maximum number of entities that can be returned. Returns: Number * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. * @returns {Promise} */ @@ -1226,7 +1273,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to count records. Returns: Number * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. * @param {Array} [select] - An Array representing the $select Query Option to control which attributes will be returned. * @returns {Promise} @@ -1247,7 +1294,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve records. * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. * @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. @@ -1264,7 +1311,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to retrieve all records. * - * @param {string} collection - The Name of the Entity Collection. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {Array} [select] - Use the $select system query option to limit the properties returned. * @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. * @returns {Promise} @@ -1280,7 +1327,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to execute FetchXml to retrieve records. Returns: DWA.Types.FetchXmlResponse * - * @param {string} collection - An object that represents all possible options for a current request. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. * @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie * @param {number} [pageNumber] - Page number. @@ -1328,7 +1375,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to execute FetchXml to retrieve records. Returns: DWA.Types.FetchXmlResponse * - * @param {string} collection - An object that represents all possible options for a current request. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. * @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie * @param {number} [pageNumber] - Page number. @@ -1355,7 +1402,7 @@ function DynamicsWebApi(config) { /** * Sends an asynchronous request to execute FetchXml to retrieve all records. * - * @param {string} collection - An object that represents all possible options for a current request. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. * @param {string} [includeAnnotations] - Use this parameter to include annotations to a result. For example: * or Microsoft.Dynamics.CRM.fetchxmlpagingcookie * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. @@ -1368,10 +1415,10 @@ function DynamicsWebApi(config) { /** * Associate for a collection-valued navigation property. (1:N or N:N) * - * @param {string} collection - Primary entity collection name. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} primaryKey - Primary entity record id. * @param {string} relationshipName - Relationship name. - * @param {string} relatedCollection - Related colletion name. + * @param {string} relatedCollection - Related name of the Entity Collection or Entity Logical name. * @param {string} relatedKey - Related entity record id. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. * @returns {Promise} @@ -1387,7 +1434,7 @@ function DynamicsWebApi(config) { collection: collection, key: primaryKey, impersonate: impersonateUserId, - data: { "@odata.id": _internalConfig.webApiUrl + relatedCollection + "(" + relatedKey + ")" } + data: { "@odata.id": relatedCollection + "(" + relatedKey + ")" } }; return _makeRequest("POST", request, 'associate') @@ -1397,7 +1444,7 @@ function DynamicsWebApi(config) { /** * Disassociate for a collection-valued navigation property. * - * @param {string} collection - Primary entity collection name. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} primaryKey - Primary entity record id. * @param {string} relationshipName - Relationship name. * @param {string} relatedKey - Related entity record id. @@ -1422,7 +1469,7 @@ function DynamicsWebApi(config) { /** * Associate for a single-valued navigation property. (1:N) * - * @param {string} collection - Entity collection name that contains an attribute. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} key - Entity record Id that contains an attribute. * @param {string} singleValuedNavigationPropertyName - Single-valued navigation property name (usually it's a Schema Name of the lookup attribute). * @param {string} relatedCollection - Related collection name that the lookup (attribute) points to. @@ -1441,7 +1488,7 @@ function DynamicsWebApi(config) { collection: collection, key: key, impersonate: impersonateUserId, - data: { "@odata.id": _internalConfig.webApiUrl + relatedCollection + "(" + relatedKey + ")" } + data: { "@odata.id": relatedCollection + "(" + relatedKey + ")" } }; return _makeRequest("PUT", request, 'associateSingleValued') @@ -1451,7 +1498,7 @@ function DynamicsWebApi(config) { /** * Removes a reference to an entity for a single-valued navigation property. (1:N) * - * @param {string} collection - Entity collection name that contains an attribute. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} key - Entity record Id that contains an attribute. * @param {string} singleValuedNavigationPropertyName - Single-valued navigation property name (usually it's a Schema Name of the lookup attribute). * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. @@ -1488,7 +1535,7 @@ function DynamicsWebApi(config) { * Executes a bound function * * @param {string} id - A String representing the GUID value for the record. - * @param {string} collection - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} functionName - The name of the function. * @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. @@ -1502,7 +1549,7 @@ function DynamicsWebApi(config) { * Executes a function * * @param {string} id - A String representing the GUID value for the record. - * @param {string} collection - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} functionName - The name of the function. * @param {Object} [parameters] - Function's input parameters. Example: { param1: "test", param2: 3 }. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. @@ -1543,7 +1590,7 @@ function DynamicsWebApi(config) { * Executes a bound Web API action (bound to a particular entity record) * * @param {string} id - A String representing the GUID value for the record. - * @param {string} collection - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} collection - The name of the Entity Collection or Entity Logical name. * @param {string} actionName - The name of the Web API action. * @param {Object} requestObject - Action request body object. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. @@ -1557,7 +1604,7 @@ function DynamicsWebApi(config) { * Executes a Web API action * * @param {string} [id] - A String representing the GUID value for the record. - * @param {string} [collection] - The name of the Entity Collection, for example, for account use accounts, opportunity - opportunities and etc. + * @param {string} [collection] - The name of the Entity Collection or Entity Logical name. * @param {string} actionName - The name of the Web API action. * @param {Object} requestObject - Action request body object. * @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. @@ -1598,6 +1645,10 @@ function DynamicsWebApi(config) { } }; +DynamicsWebApi.prototype.utility = { + getCollectionName: Request.getCollectionName +}; + module.exports = DynamicsWebApi; /***/ }), @@ -1963,6 +2014,11 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) { ErrorHelper.parameterCheck(request.data, 'DynamicsWebApi.' + functionName, 'request.data') } + if (request.noCache) { + ErrorHelper.boolParameterCheck(request.noCache, 'DynamicsWebApi.' + functionName, 'request.noCache'); + headers['Cache-Control'] = 'no-cache'; + } + if (request.expand && request.expand.length) { ErrorHelper.stringOrArrayParameterCheck(request.expand, 'DynamicsWebApi.' + functionName, "request.expand"); if (typeof request.expand === 'string') { diff --git a/dist/dynamics-web-api.min.js b/dist/dynamics-web-api.min.js index 6556cfa..e4dbca4 100644 --- a/dist/dynamics-web-api.min.js +++ b/dist/dynamics-web-api.min.js @@ -1,2 +1,2 @@ -/*! dynamics-web-api v1.3.4 (c) 2017 Aleksandr Rogov */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DynamicsWebApi",[],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=5)}([function(e,t){var n={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){n.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){n.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){n.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){n.Types.ResponseBase.call(this),this.value=[],this.PagingInfo={cookie:"",page:0,nextPage:1}}},Prefer:{ReturnRepresentation:"return=representation",Annotations:{AssociatedNavigationProperty:"Microsoft.Dynamics.CRM.associatednavigationproperty",LookupLogicalName:"Microsoft.Dynamics.CRM.lookuplogicalname",All:"*",FormattedValue:"OData.Community.Display.V1.FormattedValue",FetchXmlPagingCookie:"Microsoft.Dynamics.CRM.fetchxmlpagingcookie"}}};e.exports=n},function(e,t){function n(e,t,n){throw new Error(n?e+" requires the "+t+" parameter to be of type "+n:e+" requires the "+t+" parameter.")}var r={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,r,a){void 0!==e&&null!==e&&""!=e||n(t,r,a)},stringParameterCheck:function(e,t,r){"string"!=typeof e&&n(t,r,"String")},arrayParameterCheck:function(e,t,r){e.constructor!==Array&&n(t,r,"Array")},stringOrArrayParameterCheck:function(e,t,r){e.constructor!==Array&&"string"!=typeof e&&n(t,r,"String or Array")},numberParameterCheck:function(e,t,r){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;n(t,r,"Number")}},boolParameterCheck:function(e,t,r){"boolean"!=typeof e&&n(t,r,"Boolean")},guidParameterCheck:function(e,t,r){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){n(t,r,"GUID String")}},keyParameterCheck:function(e,t,a){try{r.stringParameterCheck(e,t,a);var i=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e);if(i)return i[0];var o=e.split(",");if(o.length)for(var c=0;cn.length)&&(t=n.length),t-=e.length;var r=n.lastIndexOf(e,t);return-1!==r&&r===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,n){function r(e){return void 0===e||"unknown"==typeof e||null==e}function a(){var e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})}function i(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm){if(!r(Xrm.Utility)&&!r(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!r(Xrm.Page)&&!r(Xrm.Page.context))return Xrm.Page.context}throw new Error("Xrm Context is not available. In most cases, it can be resolved by adding a reference to a ClientGlobalContext.js.aspx. Please refer to MSDN documentation for more details.")}function o(){var e=i();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""}function c(e){return o()+"/api/data/v"+e+"/"}function s(){return"undefined"!=typeof Xrm?Xrm.Internal:null}var u={buildFunctionParameters:n(11),getFetchXmlPagingCookie:n(14),convertToReferenceObject:n(13),isNull:r,generateUUID:a,getXrmContext:i,getXrmInternal:s,getClientUrl:o,initWebApiUrl:c};e.exports=u},function(e,t,n){function r(e){return e.Accept="application/json",e["OData-MaxVersion"]="4.0",e["OData-Version"]="4.0",e["Content-Type"]="application/json; charset=utf-8",e}function a(e,t){var n;return e&&(n=JSON.stringify(e,function(e,n){return e.endsWith("@odata.bind")&&"string"==typeof n&&(/\(\{[\w\d-]+\}\)/g.test(n)&&(n=n.replace(/(.+)\(\{([\w\d-]+)\}\)/g,"$1($2)")),n.startsWith(t.webApiUrl)||(n=t.webApiUrl+n.replace(/^\\/,""))),n}),n=n.replace(/[\u007F-\uFFFF]/g,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4)})),n}function i(e,t,i,o,c,s,u,l){c||(c={}),c=r(c);var f=a(o,i);if(t.length>2e3){var m="dwa_batch_"+p.generateUUID(),h=[];h.push("--"+m),h.push("Content-Type: application/http"),h.push("Content-Transfer-Encoding: binary\n"),h.push(e+" "+i.webApiUrl+t+" HTTP/1.1");for(var d in c)h.push(d+": "+c[d]),delete c[d];h.push("\n--"+m+"--"),f=h.join("\n"),c=r(c),c["Content-Type"]="multipart/mixed;boundary="+m,t="$batch",e="POST"}i.impersonate&&!c.MSCRMCallerID&&(c.MSCRMCallerID=i.impersonate);var y;y=n(9);var g=function(n){n&&(c||(c={}),c.Authorization="Bearer "+n.accessToken),y(e,i.webApiUrl+t,f,c,s,u,l)};i.onTokenRefresh&&(!c||c&&!c.Authorization)?i.onTokenRefresh(g):g()}function o(e,t,n,r){var a=function(t){l={};for(var r=0;r-1}function s(e,t,n,r){if(c(e)||p.isNull(e))return void n(e);if(e=e.toLowerCase(),!t.useEntityNames)return void n(e);try{var a=p.getXrmInternal();p.isNull(a)?p.isNull(l)?o(e,t,n,r):n(l[e]):n(a.getEntitySetName(e))}catch(e){r({message:"Unable to fetch Collection Names. Error: "+e.message})}}function u(e,t,n,r,a,o){var c=function(c){t.collection=c;var s=f.convertRequest(t,n,r);i(e,s.url,r,t.data||t.entity,s.headers,a,o,s.async)};s(t.collection,r,c,o)}var l,p=(n(0),n(3)),f=n(10);e.exports={sendRequest:i,makeRequest:u}},function(e,t,n){function r(e){var t={webApiVersion:"8.0",webApiUrl:null,impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(o.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(o.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=i.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=o.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(o.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(o.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(o.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(o.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(o.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var n=function(e,n,r){return new Promise(function(a,i){c.makeRequest(e,n,r,t,a,i)})};this.create=function(e,t,r,a){return o.parameterCheck(e,"DynamicsWebApi.create","object"),o.stringParameterCheck(t,"DynamicsWebApi.create","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.create","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.create","select"),n("POST",{collection:t,select:a,prefer:r,entity:e},"create").then(function(e){return e.data?e.data:/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"])[0]})},this.retrieveRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.retrieve","request");var t=e.select;return n("GET",e,"retrieve").then(function(e){return null!=t&&1==t.length&&t[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?i.convertToReferenceObject(e.data):e.data})},this.retrieve=function(e,t,n,r){o.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),o.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),n&&n.length&&o.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),r&&r.length&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.retrieve","expand");var a={collection:t,key:e,select:n,expand:r};return this.retrieveRequest(a)},this.updateRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.update","request"),null==e.ifmatch&&(e.ifmatch="*");var t=e.ifmatch;return n("PATCH",e,"update").then(function(e){return!e.data||e.data}).catch(function(e){if(t&&412==e.status)return!1;throw e})},this.update=function(e,t,n,r,a){o.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.update","key"),o.parameterCheck(n,"DynamicsWebApi.update","object"),o.stringParameterCheck(t,"DynamicsWebApi.update","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.update","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.update","select");var i={collection:t,key:e,select:a,prefer:r,entity:n};return this.updateRequest(i)},this.updateSingleProperty=function(e,t,r,a,i){o.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),o.parameterCheck(r,"DynamicsWebApi.updateSingleProperty","keyValuePair"),o.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection");var c=Object.keys(r)[0],s=r[c];return a&&o.stringOrArrayParameterCheck(a,"DynamicsWebApi.updateSingleProperty","prefer"),i&&o.arrayParameterCheck(i,"DynamicsWebApi.updateSingleProperty","select"),n("PUT",{collection:t,key:e,select:i,prefer:a,navigationProperty:c,data:{value:s}},"updateSingleProperty").then(function(e){if(e.data)return e.data})},this.deleteRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.delete","request");var t=e.ifmatch;return n("DELETE",e,"delete").then(function(){return!0}).catch(function(e){if(t&&412==e.status)return!1;throw e})},this.deleteRecord=function(e,t,r){return o.stringParameterCheck(t,"DynamicsWebApi.deleteRecord","collection"),null!=r&&o.stringParameterCheck(r,"DynamicsWebApi.deleteRecord","propertyName"),n("DELETE",{navigationProperty:r,collection:t,key:e},"deleteRecord").then(function(){})},this.upsertRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.upsert","request");var t=e.ifnonematch,r=e.ifmatch;return n("PATCH",e,"upsert").then(function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"])[0]}if(e.data)return e.data}).catch(function(e){if(!(t&&412==e.status||r&&404==e.status))throw e})},this.upsert=function(e,t,n,r,a){o.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),o.parameterCheck(n,"DynamicsWebApi.upsert","object"),o.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.upsert","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.upsert","select");var i={collection:t,key:e,select:a,prefer:r,entity:n};return this.upsertRequest(i)};var s=function(e,t){t&&(o.stringParameterCheck(t,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=t);var r=e.count;return n("GET",e,"retrieveMultiple").then(function(e){return r&&(e.data.oDataCount=e.data.oDataCount||0),e.data})};this.retrieveMultipleRequest=s;var u=function(e,t,n){var n=n||[];return s(e,t).then(function(t){return n=n.concat(t.value),t.oDataNextLink?u(e,t.oDataNextLink,n):{value:n}})};this.retrieveAllRequest=function(e){return u(e)},this.count=function(e,t){if(null==t||null!=t&&!t.length){return n("GET",{collection:e,navigationProperty:"$count"},"count").then(function(e){return e.data?parseInt(e.data):0})}return this.retrieveMultipleRequest({collection:e,filter:t,count:!0},null).then(function(e){return e.oDataCount?e.oDataCount:0})},this.countAll=function(e,t,n){return u({collection:e,filter:t,select:n}).then(function(e){return e&&e.value?e.value.length:0})},this.retrieveMultiple=function(e,t,n,r){return this.retrieveMultipleRequest({collection:e,select:t,filter:n},r)},this.retrieveAll=function(e,t,n){return u({collection:e,select:t,filter:n})};var l=function(e,t,r,c,s,u){o.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),c=c||1,o.numberParameterCheck(c,"DynamicsWebApi.executeFetchXml","pageNumber");var l='$1 page="'+c+'"';return null!=s&&(o.stringParameterCheck(s,"DynamicsWebApi.executeFetchXml","pagingCookie"),l+=' paging-cookie="'+s+'"'),t=t.replace(/^(-1?r(e)[0]:JSON.parse(e,o),t=a(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var n=e.split("\r\n"),r=0,a=n.length;r0&&(t[i.substring(0,o)]=i.substring(o+2))}return t}},function(e,t,n){var r=n(7),a=n(8),i=function(e,t,n,i,o,c,s){var u=new XMLHttpRequest;u.open(e,t,s);for(var l in i)u.setRequestHeader(l,i[l]);u.onreadystatechange=function(){if(4===u.readyState){switch(u.status){case 200:case 201:case 204:case 304:var e=r(u.responseText),t={data:e,headers:a(u.getAllResponseHeaders()),status:u.status};o(t);break;default:var n;try{n=JSON.parse(u.response).error}catch(e){n=u.response.length>0?{message:u.response}:{message:"Unexpected Error"}}n.status=u.status,c(n)}u=null}},u.onerror=function(){c({message:"Network Error"}),u=null},u.ontimeout=function(e){c({message:"Request Timed Out"}),u=null},n?u.send(n):u.send()};e.exports=i},function(e,t,n){function r(e,t,n,a,c){var s={},u=[];if(a=null!=a?a:"&",e){e.navigationProperty&&(i.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),n+="/"+e.navigationProperty),null!=e.select&&e.select.length&&(i.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?n+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?n+=e.select.shift():e.select.shift()),e.select.length&&u.push("$select="+e.select.join(",")))),e.filter&&(i.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter"),u.push("$filter="+e.filter)),e.savedQuery&&u.push("savedQuery="+i.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&u.push("userQuery="+i.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(i.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),u.push("$count="+e.count)),e.top&&e.top>0&&(i.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),u.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(i.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),u.push("$orderby="+e.orderBy.join(",")));var l=o(e,t,c);if(l.length&&(s.Prefer=l),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(i.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),s["If-Match"]=e.ifmatch),e.ifnonematch&&(i.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),s["If-None-Match"]=e.ifnonematch),e.impersonate&&(i.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),s.MSCRMCallerID=i.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(i.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),s.Authorization="Bearer "+e.token),e.duplicateDetection&&(i.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),s["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&i.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&i.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.expand&&e.expand.length)if(i.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)u.push("$expand="+e.expand);else{for(var p=[],f=0;f1&&(n+=",",r+="&"),n+=i+"=@p"+a,r+="@p"+a+"="+("string"==typeof o?"'"+o+"'":o)}return"("+n+")?"+r}return"()"}},function(e,t,n){var r=n(0),a=n(1);e.exports=function(e,t,n){var i=e.returnRepresentation,o=e.includeAnnotations,c=e.maxPageSize;if(e.prefer&&e.prefer.length){a.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer");var s=e.prefer;"string"==typeof s&&(s=s.split(","));for(var u in s){var l=s[u].trim();l===r.Prefer.ReturnRepresentation?i=!0:l.startsWith("odata.include-annotations=")?o=l.replace("odata.include-annotations=","").replace(/"/g,""):l.startsWith("odata.maxpagesize=")&&(c=l.replace("odata.maxpagesize=","").replace(/"/g,""))}}n&&(null==i&&(i=n.returnRepresentation),o=o||n.includeAnnotations,c=c||n.maxPageSize);var s=[];return i&&(a.boolParameterCheck(i,"DynamicsWebApi."+t,"request.returnRepresentation"),s.push(r.Prefer.ReturnRepresentation)),o&&(a.stringParameterCheck(o,"DynamicsWebApi."+t,"request.includeAnnotations"),s.push('odata.include-annotations="'+o+'"')),c&&c>0&&(a.numberParameterCheck(c,"DynamicsWebApi."+t,"request.maxPageSize"),s.push("odata.maxpagesize="+c)),s.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e||"",t=t||1,e=unescape(unescape(e));var n=/pagingcookie="()/.exec(e);if(null!=n){var r=parseInt(n[2]);return{cookie:n[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:r,nextPage:r+1}}return{cookie:"",page:t,nextPage:t+1}}}])}); \ No newline at end of file +/*! dynamics-web-api v1.4.0 (c) 2017 Aleksandr Rogov */ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("DynamicsWebApi",[],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var a=n[r]={i:r,l:!1,exports:{}};return e[r].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=5)}([function(e,t){var n={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){n.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){n.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){n.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){n.Types.ResponseBase.call(this),this.value=[],this.PagingInfo={cookie:"",page:0,nextPage:1}}},Prefer:{ReturnRepresentation:"return=representation",Annotations:{AssociatedNavigationProperty:"Microsoft.Dynamics.CRM.associatednavigationproperty",LookupLogicalName:"Microsoft.Dynamics.CRM.lookuplogicalname",All:"*",FormattedValue:"OData.Community.Display.V1.FormattedValue",FetchXmlPagingCookie:"Microsoft.Dynamics.CRM.fetchxmlpagingcookie"}}};e.exports=n},function(e,t){function n(e,t,n){throw new Error(n?e+" requires the "+t+" parameter to be of type "+n:e+" requires the "+t+" parameter.")}var r={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,r,a){void 0!==e&&null!==e&&""!=e||n(t,r,a)},stringParameterCheck:function(e,t,r){"string"!=typeof e&&n(t,r,"String")},arrayParameterCheck:function(e,t,r){e.constructor!==Array&&n(t,r,"Array")},stringOrArrayParameterCheck:function(e,t,r){e.constructor!==Array&&"string"!=typeof e&&n(t,r,"String or Array")},numberParameterCheck:function(e,t,r){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;n(t,r,"Number")}},boolParameterCheck:function(e,t,r){"boolean"!=typeof e&&n(t,r,"Boolean")},guidParameterCheck:function(e,t,r){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){n(t,r,"GUID String")}},keyParameterCheck:function(e,t,a){try{r.stringParameterCheck(e,t,a);var i=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e);if(i)return i[0];var o=e.split(",");if(o.length)for(var c=0;cn.length)&&(t=n.length),t-=e.length;var r=n.lastIndexOf(e,t);return-1!==r&&r===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,n){function r(e){return void 0===e||"unknown"==typeof e||null==e}function a(){var e=(new Date).getTime();return"undefined"!=typeof performance&&"function"==typeof performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)})}function i(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm){if(!r(Xrm.Utility)&&!r(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!r(Xrm.Page)&&!r(Xrm.Page.context))return Xrm.Page.context}throw new Error("Xrm Context is not available. In most cases, it can be resolved by adding a reference to a ClientGlobalContext.js.aspx. Please refer to MSDN documentation for more details.")}function o(){var e=i();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""}function c(e){return o()+"/api/data/v"+e+"/"}function s(){return"undefined"!=typeof Xrm?Xrm.Internal:null}var u={buildFunctionParameters:n(11),getFetchXmlPagingCookie:n(14),convertToReferenceObject:n(13),isNull:r,generateUUID:a,getXrmContext:i,getXrmInternal:s,getClientUrl:o,initWebApiUrl:c};e.exports=u},function(e,t,n){function r(e){var t=f.getXrmInternal();if(!f.isNull(t)){var n=t.getEntitySetName(e);return n||e}var n=null;if(!f.isNull(p)&&(n=p[e],f.isNull(n)))for(var r in p)if(p[r]==e)return e;return n}function a(e){return e.Accept="application/json",e["OData-MaxVersion"]="4.0",e["OData-Version"]="4.0",e["Content-Type"]="application/json; charset=utf-8",e}function i(e,t){var n;return e&&(n=JSON.stringify(e,function(e,n){if((e.endsWith("@odata.bind")||e.endsWith("@odata.id"))&&"string"==typeof n){if(/\(\{[\w\d-]+\}\)/g.test(n)&&(n=n.replace(/(.+)\(\{([\w\d-]+)\}\)/g,"$1($2)")),t.useEntityNames){var a=/([\w_]+)(\([\d\w-]+\))$/,i=a.exec(n);if(i.length>2){var o=r(i[1]);f.isNull(o)||(n=n.replace(a,o+"$2"))}}n.startsWith(t.webApiUrl)||(n=t.webApiUrl+n.replace(/^\\/,""))}return n}),n=n.replace(/[\u007F-\uFFFF]/g,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).substr(-4)})),n}function o(e,t,r,o,c,s,u,l){c||(c={}),c=a(c);var p=i(o,r);if(t.length>2e3){var m="dwa_batch_"+f.generateUUID(),h=[];h.push("--"+m),h.push("Content-Type: application/http"),h.push("Content-Transfer-Encoding: binary\n"),h.push(e+" "+r.webApiUrl+t+" HTTP/1.1");for(var d in c)h.push(d+": "+c[d]),delete c[d];h.push("\n--"+m+"--"),p=h.join("\n"),c=a(c),c["Content-Type"]="multipart/mixed;boundary="+m,t="$batch",e="POST"}r.impersonate&&!c.MSCRMCallerID&&(c.MSCRMCallerID=r.impersonate);var y;y=n(9);var g=function(n){n&&(c||(c={}),c.Authorization="Bearer "+n.accessToken),y(e,r.webApiUrl+t,p,c,s,u,l)};r.onTokenRefresh&&(!c||c&&!c.Authorization)?r.onTokenRefresh(g):g()}function c(e,t,n,a){var i=function(t){p={};for(var a=0;a-1}function u(e,t,n,a){if(s(e)||f.isNull(e))return void n(e);if(e=e.toLowerCase(),!t.useEntityNames)return void n(e);try{var i=r(e);f.isNull(i)?c(e,t,n,a):n(i)}catch(e){a({message:"Unable to fetch Collection Names. Error: "+e.message})}}function l(e,t,n,r,a,i){var c=function(c){t.collection=c;var s=m.convertRequest(t,n,r);o(e,s.url,r,t.data||t.entity,s.headers,a,i,s.async)};u(t.collection,r,c,i)}var p,f=(n(0),n(3)),m=n(10);e.exports={sendRequest:o,makeRequest:l,getCollectionName:r}},function(e,t,n){function r(e){var t={webApiVersion:"8.0",webApiUrl:null,impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t),this.setConfig=function(e){e.webApiVersion&&(o.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(o.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=i.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=o.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(o.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(o.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(o.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(o.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(o.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var n=function(e,n,r){return new Promise(function(a,i){c.makeRequest(e,n,r,t,a,i)})};this.create=function(e,t,r,a){return o.parameterCheck(e,"DynamicsWebApi.create","object"),o.stringParameterCheck(t,"DynamicsWebApi.create","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.create","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.create","select"),n("POST",{collection:t,select:a,prefer:r,entity:e},"create").then(function(e){return e.data?e.data:/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"])[0]})},this.retrieveRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.retrieve","request");var t=e.select;return n("GET",e,"retrieve").then(function(e){return null!=t&&1==t.length&&t[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?i.convertToReferenceObject(e.data):e.data})},this.retrieve=function(e,t,n,r){o.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),o.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),n&&n.length&&o.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),r&&r.length&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.retrieve","expand");var a={collection:t,key:e,select:n,expand:r};return this.retrieveRequest(a)},this.updateRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.update","request"),null==e.ifmatch&&(e.ifmatch="*");var t=e.ifmatch;return n("PATCH",e,"update").then(function(e){return!e.data||e.data}).catch(function(e){if(t&&412==e.status)return!1;throw e})},this.update=function(e,t,n,r,a){o.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.update","key"),o.parameterCheck(n,"DynamicsWebApi.update","object"),o.stringParameterCheck(t,"DynamicsWebApi.update","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.update","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.update","select");var i={collection:t,key:e,select:a,prefer:r,entity:n};return this.updateRequest(i)},this.updateSingleProperty=function(e,t,r,a,i){o.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),o.parameterCheck(r,"DynamicsWebApi.updateSingleProperty","keyValuePair"),o.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection");var c=Object.keys(r)[0],s=r[c];return a&&o.stringOrArrayParameterCheck(a,"DynamicsWebApi.updateSingleProperty","prefer"),i&&o.arrayParameterCheck(i,"DynamicsWebApi.updateSingleProperty","select"),n("PUT",{collection:t,key:e,select:i,prefer:a,navigationProperty:c,data:{value:s}},"updateSingleProperty").then(function(e){if(e.data)return e.data})},this.deleteRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.delete","request");var t=e.ifmatch;return n("DELETE",e,"delete").then(function(){return!0}).catch(function(e){if(t&&412==e.status)return!1;throw e})},this.deleteRecord=function(e,t,r){return o.stringParameterCheck(t,"DynamicsWebApi.deleteRecord","collection"),null!=r&&o.stringParameterCheck(r,"DynamicsWebApi.deleteRecord","propertyName"),n("DELETE",{navigationProperty:r,collection:t,key:e},"deleteRecord").then(function(){})},this.upsertRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.upsert","request");var t=e.ifnonematch,r=e.ifmatch;return n("PATCH",e,"upsert").then(function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"])[0]}if(e.data)return e.data}).catch(function(e){if(!(t&&412==e.status||r&&404==e.status))throw e})},this.upsert=function(e,t,n,r,a){o.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=o.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),o.parameterCheck(n,"DynamicsWebApi.upsert","object"),o.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),r&&o.stringOrArrayParameterCheck(r,"DynamicsWebApi.upsert","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.upsert","select");var i={collection:t,key:e,select:a,prefer:r,entity:n};return this.upsertRequest(i)};var s=function(e,t){t&&(o.stringParameterCheck(t,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=t);var r=e.count;return n("GET",e,"retrieveMultiple").then(function(e){return r&&(e.data.oDataCount=e.data.oDataCount||0),e.data})};this.retrieveMultipleRequest=s;var u=function(e,t,n){var n=n||[];return s(e,t).then(function(t){return n=n.concat(t.value),t.oDataNextLink?u(e,t.oDataNextLink,n):{value:n}})};this.retrieveAllRequest=function(e){return u(e)},this.count=function(e,t){if(null==t||null!=t&&!t.length){return n("GET",{collection:e,navigationProperty:"$count"},"count").then(function(e){return e.data?parseInt(e.data):0})}return this.retrieveMultipleRequest({collection:e,filter:t,count:!0},null).then(function(e){return e.oDataCount?e.oDataCount:0})},this.countAll=function(e,t,n){return u({collection:e,filter:t,select:n}).then(function(e){return e&&e.value?e.value.length:0})},this.retrieveMultiple=function(e,t,n,r){return this.retrieveMultipleRequest({collection:e,select:t,filter:n},r)},this.retrieveAll=function(e,t,n){return u({collection:e,select:t,filter:n})};var l=function(e,t,r,c,s,u){o.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),c=c||1,o.numberParameterCheck(c,"DynamicsWebApi.executeFetchXml","pageNumber");var l='$1 page="'+c+'"';return null!=s&&(o.stringParameterCheck(s,"DynamicsWebApi.executeFetchXml","pagingCookie"),l+=' paging-cookie="'+s+'"'),t=t.replace(/^(-1?r(e)[0]:JSON.parse(e,o),t=a(t)),t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var n=e.split("\r\n"),r=0,a=n.length;r0&&(t[i.substring(0,o)]=i.substring(o+2))}return t}},function(e,t,n){var r=n(7),a=n(8),i=function(e,t,n,i,o,c,s){var u=new XMLHttpRequest;u.open(e,t,s);for(var l in i)u.setRequestHeader(l,i[l]);u.onreadystatechange=function(){if(4===u.readyState){switch(u.status){case 200:case 201:case 204:case 304:var e=r(u.responseText),t={data:e,headers:a(u.getAllResponseHeaders()),status:u.status};o(t);break;default:var n;try{n=JSON.parse(u.response).error}catch(e){n=u.response.length>0?{message:u.response}:{message:"Unexpected Error"}}n.status=u.status,c(n)}u=null}},u.onerror=function(){c({message:"Network Error"}),u=null},u.ontimeout=function(e){c({message:"Request Timed Out"}),u=null},n?u.send(n):u.send()};e.exports=i},function(e,t,n){function r(e,t,n,a,c){var s={},u=[];if(a=null!=a?a:"&",e){e.navigationProperty&&(i.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),n+="/"+e.navigationProperty),null!=e.select&&e.select.length&&(i.arrayParameterCheck(e.select,"DynamicsWebApi."+t,"request.select"),"retrieve"==t&&1==e.select.length&&e.select[0].endsWith("/$ref")?n+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?n+=e.select.shift():e.select.shift()),e.select.length&&u.push("$select="+e.select.join(",")))),e.filter&&(i.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter"),u.push("$filter="+e.filter)),e.savedQuery&&u.push("savedQuery="+i.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&u.push("userQuery="+i.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(i.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),u.push("$count="+e.count)),e.top&&e.top>0&&(i.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),u.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(i.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),u.push("$orderby="+e.orderBy.join(",")));var l=o(e,t,c);if(l.length&&(s.Prefer=l),null!=e.ifmatch&&null!=e.ifnonematch)throw new Error("DynamicsWebApi."+t+". Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.");if(e.ifmatch&&(i.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),s["If-Match"]=e.ifmatch),e.ifnonematch&&(i.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),s["If-None-Match"]=e.ifnonematch),e.impersonate&&(i.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),s.MSCRMCallerID=i.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(i.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),s.Authorization="Bearer "+e.token),e.duplicateDetection&&(i.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),s["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&i.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&i.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.noCache&&(i.boolParameterCheck(e.noCache,"DynamicsWebApi."+t,"request.noCache"),s["Cache-Control"]="no-cache"),e.expand&&e.expand.length)if(i.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)u.push("$expand="+e.expand);else{for(var p=[],f=0;f1&&(n+=",",r+="&"),n+=i+"=@p"+a,r+="@p"+a+"="+("string"==typeof o?"'"+o+"'":o)}return"("+n+")?"+r}return"()"}},function(e,t,n){var r=n(0),a=n(1);e.exports=function(e,t,n){var i=e.returnRepresentation,o=e.includeAnnotations,c=e.maxPageSize;if(e.prefer&&e.prefer.length){a.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer");var s=e.prefer;"string"==typeof s&&(s=s.split(","));for(var u in s){var l=s[u].trim();l===r.Prefer.ReturnRepresentation?i=!0:l.startsWith("odata.include-annotations=")?o=l.replace("odata.include-annotations=","").replace(/"/g,""):l.startsWith("odata.maxpagesize=")&&(c=l.replace("odata.maxpagesize=","").replace(/"/g,""))}}n&&(null==i&&(i=n.returnRepresentation),o=o||n.includeAnnotations,c=c||n.maxPageSize);var s=[];return i&&(a.boolParameterCheck(i,"DynamicsWebApi."+t,"request.returnRepresentation"),s.push(r.Prefer.ReturnRepresentation)),o&&(a.stringParameterCheck(o,"DynamicsWebApi."+t,"request.includeAnnotations"),s.push('odata.include-annotations="'+o+'"')),c&&c>0&&(a.numberParameterCheck(c,"DynamicsWebApi."+t,"request.maxPageSize"),s.push("odata.maxpagesize="+c)),s.join(",")}},function(e,t){e.exports=function(e){var t=/\/(\w+)\(([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})/i.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}},function(e,t){e.exports=function(e,t){e=e||"",t=t||1,e=unescape(unescape(e));var n=/pagingcookie="()/.exec(e);if(null!=n){var r=parseInt(n[2]);return{cookie:n[1].replace(//g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:r,nextPage:r+1}}return{cookie:"",page:t,nextPage:t+1}}}])}); \ No newline at end of file diff --git a/package.json b/package.json index 86b62c0..dab94d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dynamics-web-api", - "version": "1.3.4", + "version": "1.4.0", "description": "DynamicsWebApi is a Microsoft Dynamics CRM Web API helper library", "keywords": [ "crm",