text: /*! dynamics-web-api v1.5.9 (c) 2019 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(i){if(n[i])return n[i].exports;var r=n[i]={i:i,l:!1,exports:{}};return e[i].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,i){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:i})},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,n){function i(e){return void 0===e||"unknown"==typeof e||null==e}function r(){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 a(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm){if(!i(Xrm.Utility)&&!i(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!i(Xrm.Page)&&!i(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=a(),t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}function s(e){return o()+"/api/data/v"+e+"/"}function c(){return"undefined"!=typeof Xrm?Xrm.Internal:null}var u={buildFunctionParameters:n(12),getFetchXmlPagingCookie:n(15),convertToReferenceObject:n(14),isNull:i,generateUUID:r,getXrmContext:a,getXrmInternal:c,getClientUrl:o,initWebApiUrl:s};e.exports=u},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 i={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,i,r){void 0!==e&&null!==e&&""!=e||n(t,i,r)},stringParameterCheck:function(e,t,i){"string"!=typeof e&&n(t,i,"String")},arrayParameterCheck:function(e,t,i){e.constructor!==Array&&n(t,i,"Array")},stringOrArrayParameterCheck:function(e,t,i){e.constructor!==Array&&"string"!=typeof e&&n(t,i,"String or Array")},numberParameterCheck:function(e,t,i){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;n(t,i,"Number")}},boolParameterCheck:function(e,t,i){"boolean"!=typeof e&&n(t,i,"Boolean")},guidParameterCheck:function(e,t,i){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){n(t,i,"GUID String")}},keyParameterCheck:function(e,t,r){try{i.stringParameterCheck(e,t,r);var a=/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e);if(a)return a[0];var o=e.split(",");if(o.length)for(var s=0;s<o.length;s++)o[s]=o[s].trim().replace('"',"'"),/^[\w\d\_]+\=('[^\'\r\n]+'|\d+)$/i.exec(o[s])[0];return o.join(",")}catch(e){n(t,r,"String representing GUID or Alternate Key")}},callbackParameterCheck:function(e,t,i){"function"!=typeof e&&n(t,i,"Function")},batchIncompatible:function(e,t){if(t)throw t=!1,new Error(e+" cannot be used in a BATCH request.")},batchNotStarted:function(e){if(!e)throw new Error("Batch operation has not been started. Please call a DynamicsWebApi.startBatch() function prior to calling DynamicsWebApi.executeBatch() to perform a batch request correctly.")}};e.exports=i},function(e,t){String.prototype.endsWith=function(e,t){var n=this.toString();("number"!=typeof t||!isFinite(t)||Math.floor(t)!==t||t>n.length)&&(t=n.length),t-=e.length;var i=n.lastIndexOf(e,t);return-1!==i&&i===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,n){function i(e){var t=h.getXrmInternal();if(!h.isNull(t))return t.getEntitySetName(e)||e;var n=null;if(!h.isNull(p)&&(n=p[e],h.isNull(n)))for(var i in p)if(p[i]==e)return e;return 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){if(e.endsWith("@odata.bind")||e.endsWith("@odata.id")){if("string"==typeof n&&!n.startsWith("$")){if(/\(\{[\w\d-]+\}\)/g.test(n)&&(n=n.replace(/(.+)\(\{([\w\d-]+)\}\)/g,"$1($2)")),t.useEntityNames){var r=/([\w_]+)(\([\d\w-]+\))$/,a=r.exec(n);if(a.length>2){var o=i(a[1]);h.isNull(o)||(n=n.replace(r,o+"$2"))}}n.startsWith(t.webApiUrl)||(e.endsWith("@odata.bind")?n.startsWith("/")||(n="/"+n):n=t.webApiUrl+n.replace(/^\//,""))}}else(e.startsWith("oData")||e.endsWith("_Formatted")||e.endsWith("_NavigationProperty")||e.endsWith("_LogicalName"))&&(n=void 0);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,i,o,s,c,u,l,p,m){s=s||{},c=c||{},d.push(c);var g=a(o,i);if(p)return void y.push({method:e,path:t,config:i,data:g,headers:s});if("$batch"===t){var b=f.convertToBatch(y);g=b.body,y.length=0,s=r(s),s["Content-Type"]="multipart/mixed;boundary="+b.boundary}else s=r(s);if(c.convertedToBatch=!1,t.length>2e3){var A="dwa_batch_"+h.generateUUID(),k=[];k.push("--"+A),k.push("Content-Type: application/http"),k.push("Content-Transfer-Encoding: binary\n"),k.push(e+" "+i.webApiUrl+t+" HTTP/1.1");for(var v in s)"Authorization"!==v&&(k.push(v+": "+s[v]),delete s[v]);k.push("\n--"+A+"--"),g=k.join("\n"),s=r(s),s["Content-Type"]="multipart/mixed;boundary="+A,t="$batch",e="POST",c.convertedToBatch=!0}i.impersonate&&!s.MSCRMCallerID&&(s.MSCRMCallerID=i.impersonate);var D;D=n(9);var C=function(n){n&&(s||(s={}),s.Authorization="Bearer "+(n.hasOwnProperty("accessToken")?n.accessToken:n)),D({method:e,uri:i.webApiUrl+t,data:g,additionalHeaders:s,responseParams:d,successCallback:u,errorCallback:l,isAsync:m,timeout:i.timeout})};i.onTokenRefresh&&(!s||s&&!s.Authorization)?i.onTokenRefresh(C):C()}function s(e,t,n,r){var a=function(t){p={};for(var r=0;r<t.data.value.length;r++)p[t.data.value[r].LogicalName]=t.data.value[r].LogicalCollectionName;n(i(e))},s=function(e){r({message:"Unable to fetch EntityDefinitions. Error: "+e.message})},c=m.convertRequest({collection:"EntityDefinitions",select:["LogicalCollectionName","LogicalName"],noCache:!0},"retrieveMultiple",t);o("GET",c.url,t,null,c.headers,null,a,s,!1,c.async)}function c(e){return["EntityDefinitions","$metadata","RelationshipDefinitions","GlobalOptionSetDefinitions","ManagedPropertyDefinitions"].indexOf(e)>-1}function u(e,t,n,r){if(c(e)||h.isNull(e))return void n(e);if(e=e.toLowerCase(),!t.useEntityNames)return void n(e);try{var a=i(e);h.isNull(a)?s(e,t,n,r):n(a)}catch(e){r({message:"Unable to fetch Collection Names. Error: "+e.message})}}function l(e,t,n,i,r,a,s){var c=function(c){t.collection=c;var u=m.convertRequest(t,n,i);o(e,u.url,i,t.data||t.entity,u.headers,r,a,s,t.isBatch,u.async)};u(t.collection,i,c,s)}var p,h=n(1),m=n(11),f=n(10),y=[],d=[];e.exports={sendRequest:o,makeRequest:l,getCollectionName:i}},function(e,t,n){"use strict";function i(e){var t={webApiVersion:"8.0",webApiUrl:null,impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null},n=!1;e||(e=t),this.setConfig=function(e){e.webApiVersion&&(a.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(a.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=r.initWebApiUrl(t.webApiVersion),e.impersonate&&(t.impersonate=a.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(a.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(a.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.timeout&&(a.numberParameterCheck(e.timeout,"DynamicsWebApi.setConfig","config.timeout"),t.timeout=e.timeout),e.maxPageSize&&(a.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(a.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation),e.useEntityNames&&(a.boolParameterCheck(e.useEntityNames,"DynamicsWebApi.setConfig","config.useEntityNames"),t.useEntityNames=e.useEntityNames)},this.setConfig(e);var s=function(e,i,r,a){return i.isBatch=n,new Promise(function(n,s){o.makeRequest(e,i,r,t,a,n,s)})};this.createRequest=function(e){return a.parameterCheck(e,"DynamicsWebApi.create","request"),s("POST",e,"create").then(function(e){return e.data})},this.create=function(e,t,n,i){a.parameterCheck(e,"DynamicsWebApi.create","object"),a.stringParameterCheck(t,"DynamicsWebApi.create","collection"),n&&a.stringOrArrayParameterCheck(n,"DynamicsWebApi.create","prefer"),i&&a.arrayParameterCheck(i,"DynamicsWebApi.create","select");var r={collection:t,select:i,prefer:n,entity:e};return this.createRequest(r)},this.retrieveRequest=function(e){a.parameterCheck(e,"DynamicsWebApi.retrieve","request");var t=null!=e.select&&1===e.select.length&&e.select[0].endsWith("/$ref");return s("GET",e,"retrieve",{isRef:t}).then(function(e){return e.data})},this.retrieve=function(e,t,n,i){a.stringParameterCheck(e,"DynamicsWebApi.retrieve","key"),e=a.keyParameterCheck(e,"DynamicsWebApi.retrieve","key"),a.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),n&&n.length&&a.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),i&&i.length&&a.stringOrArrayParameterCheck(i,"DynamicsWebApi.retrieve","expand");var r={collection:t,key:e,select:n,expand:i};return this.retrieveRequest(r)},this.updateRequest=function(e){a.parameterCheck(e,"DynamicsWebApi.update","request"),null==e.ifmatch&&(e.ifmatch="*");var t=/EntityDefinitions|RelationshipDefinitions|GlobalOptionSetDefinitions/.test(e.collection)?"PUT":"PATCH",n=e.ifmatch;return s(t,e,"update",{valueIfEmpty:!0}).then(function(e){return e.data}).catch(function(e){if(n&&412===e.status)return!1;throw e})},this.update=function(e,t,n,i,r){a.stringParameterCheck(e,"DynamicsWebApi.update","key"),e=a.keyParameterCheck(e,"DynamicsWebApi.update","key"),a.parameterCheck(n,"DynamicsWebApi.update","object"),a.stringParameterCheck(t,"DynamicsWebApi.update","collection"),i&&a.stringOrArrayParameterCheck(i,"DynamicsWebApi.update","prefer"),r&&a.arrayParameterCheck(r,"DynamicsWebApi.update","select");var o={collection:t,key:e,select:r,prefer:i,entity:n};return this.updateRequest(o)},this.updateSingleProperty=function(e,t,n,i,r){a.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),e=a.keyParameterCheck(e,"DynamicsWebApi.updateSingleProperty","key"),a.parameterCheck(n,"DynamicsWebApi.updateSingleProperty","keyValuePair"),a.stringParameterCheck(t,"DynamicsWebApi.updateSingleProperty","collection");var o=Object.keys(n)[0],c=n[o];return i&&a.stringOrArrayParameterCheck(i,"DynamicsWebApi.updateSingleProperty","prefer"),r&&a.arrayParameterCheck(r,"DynamicsWebApi.updateSingleProperty","select"),s("PUT",{collection:t,key:e,select:r,prefer:i,navigationProperty:o,data:{value:c}},"updateSingleProperty").then(function(e){return e.data})},this.deleteRequest=function(e){a.parameterCheck(e,"DynamicsWebApi.delete","request");var t=e.ifmatch;return s("DELETE",e,"delete",{valueIfEmpty:!0}).then(function(e){return e.data}).catch(function(e){if(t&&412===e.status)return!1;throw e})},this.deleteRecord=function(e,t,n){return a.stringParameterCheck(t,"DynamicsWebApi.deleteRecord","collection"),null!=n&&a.stringParameterCheck(n,"DynamicsWebApi.deleteRecord","propertyName"),s("DELETE",{navigationProperty:n,collection:t,key:e},"deleteRecord").then(function(){})},this.upsertRequest=function(e){a.parameterCheck(e,"DynamicsWebApi.upsert","request");var t=e.ifnonematch,n=e.ifmatch;return s("PATCH",e,"upsert").then(function(e){return e.data}).catch(function(e){if(!(t&&412===e.status||n&&404===e.status))throw e})},this.upsert=function(e,t,n,i,r){a.stringParameterCheck(e,"DynamicsWebApi.upsert","key"),e=a.keyParameterCheck(e,"DynamicsWebApi.upsert","key"),a.parameterCheck(n,"DynamicsWebApi.upsert","object"),a.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),i&&a.stringOrArrayParameterCheck(i,"DynamicsWebApi.upsert","prefer"),r&&a.arrayParameterCheck(r,"DynamicsWebApi.upsert","select");var o={collection:t,key:e,select:r,prefer:i,entity:n};return this.upsertRequest(o)};var c=function(e,t){return t&&(a.stringParameterCheck(t,"DynamicsWebApi.retrieveMultiple","nextPageLink"),e.url=t),s("GET",e,"retrieveMultiple").then(function(e){return e.data})};this.retrieveMultipleRequest=c;var u=function(e,t,n){return n=n||[],c(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 a.batchIncompatible("DynamicsWebApi.retrieveAllRequest",n),u(e)},this.count=function(e,t){var n={collection:e};return null==t||null!=t&&!t.length?n.navigationProperty="$count":(n.filter=t,n.count=!0),s("GET",n,"count",{toCount:n.count}).then(function(e){return e.data})},this.countAll=function(e,t,i){return a.batchIncompatible("DynamicsWebApi.countAll",n),u({collection:e,filter:t,select:i}).then(function(e){return e&&e.value?e.value.length:0})},this.retrieveMultiple=function(e,t,n,i){return this.retrieveMultipleRequest({collection:e,select:t,filter:n},i)},this.retrieveAll=function(e,t,i){return a.batchIncompatible("DynamicsWebApi.retrieveAll",n),u({collection:e,select:t,filter:i})};var l=function(e,t,n,i,r,o){a.stringParameterCheck(t,"DynamicsWebApi.executeFetchXml","fetchXml"),i=i||1,a.numberParameterCheck(i,"DynamicsWebApi.executeFetchXml","pageNumber");var c='$1 page="'+i+'"';return null!=r&&(a.stringParameterCheck(r,"DynamicsWebApi.executeFetchXml","pagingCookie"),c+=' paging-cookie="'+r+'"'),t=t.replace(/^(<fetch)/,c),s("GET",{collection:e,includeAnnotations:n,impersonate:o,fetchXml:t},"executeFetchXml",{pageNumber:i}).then(function(e){return e.data})};this.fetch=l,this.executeFetchXml=l;var p=function(e,t,n,i,r,a,o){return o=o||[],l(e,t,n,i,r,a).then(function(i){return o=o.concat(i.value),i.PagingInfo?p(e,t,n,i.PagingInfo.nextPage,i.PagingInfo.cookie,a,o):{value:o}})},h=function(e,t,i,r){return a.batchIncompatible("DynamicsWebApi.executeFetchXmlAll",n),p(e,t,i,null,null,r)};this.fetchAll=h,this.executeFetchXmlAll=h,this.associate=function(e,t,n,i,r,o){return a.stringParameterCheck(i,"DynamicsWebApi.associate","relatedcollection"),a.stringParameterCheck(n,"DynamicsWebApi.associate","relationshipName"),t=a.keyParameterCheck(t,"DynamicsWebApi.associate","primaryKey"),r=a.keyParameterCheck(r,"DynamicsWebApi.associate","relatedKey"),s("POST",{_additionalUrl:n+"/$ref",collection:e,key:t,impersonate:o,data:{"@odata.id":i+"("+r+")"}},"associate").then(function(){})},this.disassociate=function(e,t,n,i,r){return a.stringParameterCheck(n,"DynamicsWebApi.disassociate","relationshipName"),i=a.keyParameterCheck(i,"DynamicsWebApi.disassociate","relatedId"),s("DELETE",{_additionalUrl:n+"("+i+")/$ref",collection:e,key:t,impersonate:r},"disassociate").then(function(){})},this.associateSingleValued=function(e,t,n,i,r,o){return r=a.keyParameterCheck(r,"DynamicsWebApi.associateSingleValued","relatedKey"),a.stringParameterCheck(n,"DynamicsWebApi.associateSingleValued","singleValuedNavigationPropertyName"),a.stringParameterCheck(i,"DynamicsWebApi.associateSingleValued","relatedcollection"),s("PUT",{_additionalUrl:n+"/$ref",collection:e,key:t,impersonate:o,data:{"@odata.id":i+"("+r+")"}},"associateSingleValued").then(function(){})},this.disassociateSingleValued=function(e,t,n,i){return a.stringParameterCheck(n,"DynamicsWebApi.disassociateSingleValued","singleValuedNavigationPropertyName"),s("DELETE",{_additionalUrl:n+"/$ref",key:t,collection:e,impersonate:i},"disassociateSingleValued").then(function(){})},this.executeUnboundFunction=function(e,t,n){return m(e,t,null,null,n,!0)},this.executeBoundFunction=function(e,t,n,i,r){return m(n,i,t,e,r)};var m=function(e,t,n,i,o,c){a.stringParameterCheck(e,"DynamicsWebApi.executeFunction","functionName");var u={_additionalUrl:e+r.buildFunctionParameters(t),_unboundRequest:c,key:i,collection:n,impersonate:o};return s("GET",u,"executeFunction").then(function(e){return e.data})};this.executeUnboundAction=function(e,t,n){return f(e,t,null,null,n,!0)},this.executeBoundAction=function(e,t,n,i,r){return f(n,i,t,e,r)};var f=function(e,t,n,i,r,o){a.stringParameterCheck(e,"DynamicsWebApi.executeAction","actionName");var c={_additionalUrl:e,_unboundRequest:o,collection:n,key:i,impersonate:r,data:t},u=function(e){return e.data};return s("POST",c,"executeAction").then(u)};this.createEntity=function(e){a.parameterCheck(e,"DynamicsWebApi.createEntity","entityDefinition");var t={collection:"EntityDefinitions",entity:e};return this.createRequest(t)},this.updateEntity=function(e,t){a.parameterCheck(e,"DynamicsWebApi.updateEntity","entityDefinition"),a.guidParameterCheck(e.MetadataId,"DynamicsWebApi.updateEntity","entityDefinition.MetadataId");var n={collection:"EntityDefinitions",mergeLabels:t,key:e.MetadataId,entity:e};return this.updateRequest(n)},this.retrieveEntity=function(e,t,n){a.keyParameterCheck(e,"DynamicsWebApi.retrieveEntity","entityKey");var i={collection:"EntityDefinitions",key:e,select:t,expand:n};return this.retrieveRequest(i)},this.retrieveEntities=function(e,t){var n={collection:"EntityDefinitions",select:e,filter:t};return this.retrieveRequest(n)},this.createAttribute=function(e,t){a.keyParameterCheck(e,"DynamicsWebApi.createAttribute","entityKey"),a.parameterCheck(t,"DynamicsWebApi.createAttribute","attributeDefinition");var n={collection:"EntityDefinitions",key:e,entity:t,navigationProperty:"Attributes"};return this.createRequest(n)},this.updateAttribute=function(e,t,n,i){a.keyParameterCheck(e,"DynamicsWebApi.updateAttribute","entityKey"),a.parameterCheck(t,"DynamicsWebApi.updateAttribute","attributeDefinition"),a.guidParameterCheck(t.MetadataId,"DynamicsWebApi.updateAttribute","attributeDefinition.MetadataId"),n&&a.stringParameterCheck(n,"DynamicsWebApi.updateAttribute","attributeType");var r={collection:"EntityDefinitions",key:e,entity:t,navigationProperty:"Attributes",navigationPropertyKey:t.MetadataId,mergeLabels:i,metadataAttributeType:n};return this.updateRequest(r)},this.retrieveAttributes=function(e,t,n,i,r){a.keyParameterCheck(e,"DynamicsWebApi.retrieveAttributes","entityKey"),t&&a.stringParameterCheck(t,"DynamicsWebApi.retrieveAttributes","attributeType");var o={collection:"EntityDefinitions",key:e,navigationProperty:"Attributes",select:n,filter:i,expand:r,metadataAttributeType:t};return this.retrieveRequest(o)},this.retrieveAttribute=function(e,t,n,i,r){a.keyParameterCheck(e,"DynamicsWebApi.retrieveAttribute","entityKey"),a.keyParameterCheck(t,"DynamicsWebApi.retrieveAttribute","attributeKey"),n&&a.stringParameterCheck(n,"DynamicsWebApi.retrieveAttribute","attributeType");var o={collection:"EntityDefinitions",key:e,navigationProperty:"Attributes",select:i,expand:r,metadataAttributeType:n,navigationPropertyKey:t};return this.retrieveRequest(o)},this.createRelationship=function(e){a.parameterCheck(e,"DynamicsWebApi.createRelationship","relationshipDefinition");var t={collection:"RelationshipDefinitions",entity:e};return this.createRequest(t)},this.updateRelationship=function(e,t,n){a.parameterCheck(e,"DynamicsWebApi.updateRelationship","relationshipDefinition"),a.guidParameterCheck(e.MetadataId,"DynamicsWebApi.updateRelationship","relationshipDefinition.MetadataId");var i={collection:"RelationshipDefinitions",mergeLabels:n,key:e.MetadataId,entity:e,navigationProperty:t};return this.updateRequest(i)},this.deleteRelationship=function(e){a.keyParameterCheck(e,"DynamicsWebApi.deleteRelationship","metadataId");var t={collection:"RelationshipDefinitions",key:e};return this.deleteRequest(t)},this.retrieveRelationships=function(e,t,n){var i={collection:"RelationshipDefinitions",navigationProperty:e,select:t,filter:n};return this.retrieveMultipleRequest(i)},this.retrieveRelationship=function(e,t,n){a.keyParameterCheck(e,"DynamicsWebApi.retrieveRelationship","metadataId");var i={collection:"RelationshipDefinitions",navigationProperty:t,key:e,select:n};return this.retrieveRequest(i)},this.createGlobalOptionSet=function(e){a.parameterCheck(e,"DynamicsWebApi.createGlobalOptionSet","globalOptionSetDefinition");var t={collection:"GlobalOptionSetDefinitions",entity:e};return this.createRequest(t)},this.updateGlobalOptionSet=function(e,t){a.parameterCheck(e,"DynamicsWebApi.updateGlobalOptionSet","globalOptionSetDefinition"),a.guidParameterCheck(e.MetadataId,"DynamicsWebApi.updateGlobalOptionSet","globalOptionSetDefinition.MetadataId");var n={collection:"GlobalOptionSetDefinitions",mergeLabels:t,key:e.MetadataId,entity:e};return this.updateRequest(n)},this.deleteGlobalOptionSet=function(e){a.keyParameterCheck(e,"DynamicsWebApi.deleteGlobalOptionSet","globalOptionSetKey");var t={collection:"GlobalOptionSetDefinitions",key:e};return this.deleteRequest(t)},this.retrieveGlobalOptionSet=function(e,t,n){a.keyParameterCheck(e,"DynamicsWebApi.retrieveGlobalOptionSet","globalOptionSetKey");var i={collection:"GlobalOptionSetDefinitions",key:e,navigationProperty:t,select:n};return this.retrieveRequest(i)},this.retrieveGlobalOptionSets=function(e,t){var n={collection:"GlobalOptionSetDefinitions",navigationProperty:e,select:t};return this.retrieveMultipleRequest(n)},this.startBatch=function(){n=!0},this.executeBatch=function(){return a.batchNotStarted(n),n=!1,s("POST",{collection:"$batch"},"executeBatch").then(function(e){return e.data})},this.initializeInstance=function(e){return e||(e=t),new i(e)}}var r=(n(0),n(1)),a=n(2),o=n(4);String.prototype.endsWith&&String.prototype.startsWith||n(3),i.prototype.utility={getCollectionName:o.getCollectionName},e.exports=i},function(e,t){e.exports=function(e,t){var n;return"string"==typeof t&&(n=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[-+]\d{2}:\d{2})$/.exec(t))?new Date(Date.UTC(+n[1],+n[2]-1,+n[3],+n[4],+n[5],+n[6])):t}},function(e,t,n){function i(e,t){var n=null;if(-1!==e.indexOf("@")){var i=e.split("@");switch(i[1]){case"odata.context":n="oDataContext";break;case"odata.count":n="oDataCount",t=null!=t?parseInt(t):0;break;case"odata.nextLink":n="oDataNextLink";break;case o.Prefer.Annotations.FormattedValue:n=i[0]+"_Formatted";break;case o.Prefer.Annotations.AssociatedNavigationProperty:n=i[0]+"_NavigationProperty";break;case o.Prefer.Annotations.LookupLogicalName:n=i[0]+"_LogicalName"}}return[n,t]}function r(e,t){if(t){if(t.isRef&&null!=e["@odata.id"])return s.convertToReferenceObject(e);if(t.toCount)return i("@odata.count",e["@odata.count"])[1]||0}for(var n=Object.keys(e),a=0;a<n.length;a++){var c=n[a];if(null!=e[c]&&e[c].constructor===Array)for(var u=0;u<e[c].length;u++)e[c][u]=r(e[c][u]);var l=i(c,e[c]);if(l[0]&&(e[l[0]]=l[1]),-1!==c.indexOf("_x002e_")){var p=c.split("_x002e_");if(e.hasOwnProperty(p[0])){if("object"!=typeof e[p[0]]||"object"==typeof e[p[0]]&&!e[p[0]].hasOwnProperty("_dwaType"))throw new Error("The alias name of the linked entity must be unique!")}else e[p[0]]={_dwaType:"alias"};e[p[0]][p[1]]=e[c],l=i(p[1],e[c]),l[0]&&(e[p[0]][l[0]]=l[1])}}return t&&t.hasOwnProperty("pageNumber")&&null!=e["@"+o.Prefer.Annotations.FetchXmlPagingCookie]&&(e.PagingInfo=s.getFetchXmlPagingCookie(e["@"+o.Prefer.Annotations.FetchXmlPagingCookie],t.pageNumber)),e}function a(e,t,n){var i=e.substr(0,e.indexOf("\r\n")),o=e.split(i);o.shift(),o.pop(),n=n||0;for(var s=[],u=0;u<o.length;u++){var l=o[u];if(l.indexOf("--changesetresponse_")>-1){l=l.trim();var p=l.substring(l.indexOf("\r\n")+1).trim();s=s.concat(a(p,t,n))}else{var h=l.substring(l.indexOf("{"),l.lastIndexOf("}")+1);if(h)s.push(r(JSON.parse(h,c),t[n]));else if(/Content-Type: text\/plain/i.test(l)){var m=/\w+$/gi.exec(l.trim()),f=m&&m.length?m[0]:void 0;s.push(isNaN(f)?f:parseInt(f))}else if(t.length&&t[n].hasOwnProperty("valueIfEmpty"))s.push(t[n].valueIfEmpty);else{var y=/OData-EntityId.+/i.exec(l);y&&y.length?s.push(/([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(y[0])[1]):s.push(void 0)}}n++}return s}var o=n(0),s=n(1),c=n(6);String.prototype.endsWith&&String.prototype.startsWith||n(3),e.exports=function(e,t,n){var i=void 0;if(e.length)if(e.indexOf("--batchresponse_")>-1){var o=a(e,n);i=1===n.length&&n[0].convertedToBatch?o[0]:o}else i=r(JSON.parse(e,c),n[0]);else if(n.length&&n[0].hasOwnProperty("valueIfEmpty"))i=n[0].valueIfEmpty;else if(t["OData-EntityId"]||t["odata-entityid"]){var s=t["OData-EntityId"]?t["OData-EntityId"]:t["odata-entityid"],u=/([0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12})\)$/i.exec(s);u&&(i=u[1])}return i}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var n=e.split("\r\n"),i=0,r=n.length;i<r;i++){var a=n[i],o=a.indexOf(": ");o>0&&(t[a.substring(0,o)]=a.substring(o+2))}return t}},function(e,t,n){var i=n(7),r=n(8),a=function(e){var t=e.method,n=e.uri,a=e.data,o=e.additionalHeaders,s=e.responseParams,c=e.successCallback,u=e.errorCallback,l=e.isAsync,p=new XMLHttpRequest;p.open(t,n,l);for(var h in o)p.setRequestHeader(h,o[h]);p.onreadystatechange=function(){if(4===p.readyState){switch(p.status){case 200:case 201:case 204:case 304:var e=r(p.getAllResponseHeaders()),t=i(p.responseText,e,s),n={data:t,headers:e,status:p.status};c(n);break;default:var a;try{a=JSON.parse(p.response).error}catch(e){a=p.response.length>0?{message:p.response}:{message:"Unexpected Error"}}a.status=p.status,a.statusText=p.statusText,u(a)}p=null,s.length=0}},e.timeout&&(p.timeout=e.timeout),p.onerror=function(){u({status:p.status,statusText:p.statusText,message:p.responseText||"Network Error"}),s.length=0,p=null},p.ontimeout=function(){u({status:p.status,statusText:p.statusText,message:p.responseText||"Request Timed Out"}),s.length=0,p=null},a?p.send(a):p.send()};e.exports=a},function(e,t,n){var i=n(1),r=function(e){for(var t="dwa_batch_"+i.generateUUID(),n=[],r=null,a=1e5,o=0;o<e.length;o++){var s=e[o],c="GET"===s.method;if(c&&r&&(n.push("\n--"+r+"--"),r=null,a=1e5),r||(n.push("\n--"+t),c||(r="changeset_"+i.generateUUID(),n.push("Content-Type: multipart/mixed;boundary="+r))),c||n.push("\n--"+r),n.push("Content-Type: application/http"),n.push("Content-Transfer-Encoding: binary"),!c){var u=s.headers.hasOwnProperty("Content-ID")?s.headers["Content-ID"]:++a;n.push("Content-ID: "+u)}s.path.startsWith("$")?n.push("\n"+s.method+" "+s.path+" HTTP/1.1"):n.push("\n"+s.method+" "+s.config.webApiUrl+s.path+" HTTP/1.1"),c?n.push("Accept: application/json"):n.push("Content-Type: application/json");for(var l in s.headers)"Authorization"!==l&&"Content-ID"!==l&&n.push(l+": "+s.headers[l]);!c&&s.data&&s.data.length&&n.push("\n"+s.data)}return r&&n.push("\n--"+r+"--"),n.push("\n--"+t+"--"),{boundary:t,body:n.join("\n")}},a={convertToBatch:r};e.exports=a},function(e,t,n){function i(e,t,n,r,s){var c={},u=[];if(r=null!=r?r:"&",e){if(e.navigationProperty){if(a.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),n+="/"+e.navigationProperty,e.navigationPropertyKey){n+="("+a.keyParameterCheck(e.navigationPropertyKey,"DynamicsWebApi."+t,"request.navigationPropertyKey")+")"}"Attributes"===e.navigationProperty&&e.metadataAttributeType&&(a.stringParameterCheck(e.metadataAttributeType,"DynamicsWebApi."+t,"request.metadataAttributeType"),n+="/"+e.metadataAttributeType)}if(null!=e.select&&e.select.length&&(a.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){a.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter");for(var l=/[^"']{([\w\d]{8}[-]?(?:[\w\d]{4}[-]?){3}[\w\d]{12})}(?:[^"']|$)/g,p=e.filter;null!==(m=l.exec(p));){m.index===l.lastIndex&&regex.lastIndex++;var h=m[0].endsWith(")")?")":" ";p=p.replace(m[0]," "+m[1]+h)}u.push("$filter="+encodeURIComponent(p))}e.savedQuery&&u.push("savedQuery="+a.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&u.push("userQuery="+a.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(a.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),u.push("$count="+e.count)),e.top&&e.top>0&&(a.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),u.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(a.arrayParameterCheck(e.orderBy,"DynamicsWebApi."+t,"request.orderBy"),u.push("$orderby="+e.orderBy.join(",")));var f=o(e,t,s);if(f.length&&(c.Prefer=f),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&&(a.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),c["If-Match"]=e.ifmatch),e.ifnonematch&&(a.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),c["If-None-Match"]=e.ifnonematch),e.impersonate&&(a.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),c.MSCRMCallerID=a.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(a.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),c.Authorization="Bearer "+e.token),e.duplicateDetection&&(a.boolParameterCheck(e.duplicateDetection,"DynamicsWebApi."+t,"request.duplicateDetection"),c["MSCRM.SuppressDuplicateDetection"]="false"),e.entity&&a.parameterCheck(e.entity,"DynamicsWebApi."+t,"request.entity"),e.data&&a.parameterCheck(e.data,"DynamicsWebApi."+t,"request.data"),e.noCache&&(a.boolParameterCheck(e.noCache,"DynamicsWebApi."+t,"request.noCache"),c["Cache-Control"]="no-cache"),e.mergeLabels&&(a.boolParameterCheck(e.mergeLabels,"DynamicsWebApi."+t,"request.mergeLabels"),c["MSCRM.MergeLabels"]="true"),e.contentId&&(a.stringParameterCheck(e.contentId,"DynamicsWebApi."+t,"request.contentId"),e.contentId.startsWith("$")||(c["Content-ID"]=e.contentId)),e.isBatch&&a.boolParameterCheck(e.isBatch,"DynamicsWebApi."+t,"request.isBatch"),e.expand&&e.expand.length)if(a.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)u.push("$expand="+e.expand);else{for(var y=[],d=0;d<e.expand.length;d++)if(e.expand[d].property){var g=i(e.expand[d],t+" $expand",null,";"),b=g.query;b&&b.length&&(b="("+b+")"),y.push(e.expand[d].property+b)}y.length&&u.push("$expand="+y.join(","))}}return{url:n,query:u.join(r),headers:c}}function r(e,t,n){var r,o="";return e.url?(a.stringParameterCheck(e.url,"DynamicsWebApi."+t,"request.url"),o=e.url.replace(n.webApiUrl,""),r=i(e,t,o,"&",n)):(e._unboundRequest||e.collection||a.parameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection"),e.collection&&(a.stringParameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection"),o=e.collection,e.contentId&&(a.stringParameterCheck(e.contentId,"DynamicsWebApi."+t,"request.contentId"),e.contentId.startsWith("$")&&(o=e.contentId+"/"+o)),e.key?e.key=a.keyParameterCheck(e.key,"DynamicsWebApi."+t,"request.key"):e.id&&(e.key=a.guidParameterCheck(e.id,"DynamicsWebApi."+t,"request.id")),e.key&&(o+="("+e.key+")")),e._additionalUrl&&(o&&(o+="/"),o+=e._additionalUrl),r=i(e,t,o,"&",n),e.fetchXml?(a.stringParameterCheck(e.fetchXml,"DynamicsWebApi."+t,"request.fetchXml"),r.url+="?fetchXml="+encodeURIComponent(e.fetchXml)):r.query&&(r.url+="?"+r.query)),e.hasOwnProperty("async")&&null!=e.async?(a.boolParameterCheck(e.async,"DynamicsWebApi."+t,"request.async"),r.async=e.async):r.async=!0,{url:r.url,headers:r.headers,async:r.async}}var a=(n(0),n(2)),o=n(13),s={convertRequestOptions:i,convertRequest:r};e.exports=s},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),n="",i="",r=1;r<=t.length;r++){var a=t[r-1],o=e[a];null!==o&&("string"==typeof o?o="'"+o+"'":"object"==typeof o&&(o=JSON.stringify(o)),r>1&&(n+=",",i+="&"),n+=a+"=@p"+r,i+="@p"+r+"="+o)}return"("+n+")?"+i}return"()"}},function(e,t,n){var i=n(0),r=n(2);e.exports=function(e,t,n){var a,o=e.returnRepresentation,s=e.includeAnnotations,c=e.maxPageSize;if(e.prefer&&e.prefer.length){r.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer"),a=e.prefer,"string"==typeof a&&(a=a.split(","));for(var u in a){var l=a[u].trim();l===i.Prefer.ReturnRepresentation?o=!0:l.startsWith("odata.include-annotations=")?s=l.replace("odata.include-annotations=","").replace(/"/g,""):l.startsWith("odata.maxpagesize=")&&(c=l.replace("odata.maxpagesize=","").replace(/"/g,""))}}return a=[],n&&(null==o&&(o=n.returnRepresentation),s=s||n.includeAnnotations,c=c||n.maxPageSize),o&&(r.boolParameterCheck(o,"DynamicsWebApi."+t,"request.returnRepresentation"),a.push(i.Prefer.ReturnRepresentation)),s&&(r.stringParameterCheck(s,"DynamicsWebApi."+t,"request.includeAnnotations"),a.push('odata.include-annotations="'+s+'"')),c&&c>0&&(r.numberParameterCheck(c,"DynamicsWebApi."+t,"request.maxPageSize"),a.push("odata.maxpagesize="+c)),a.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="(<cookie page="(\d+)".+<\/cookie>)/.exec(e);if(null!=n){var i=parseInt(n[2]);return{cookie:n[1].replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"'").replace(/\'/g,"&quot;"),page:i,nextPage:i+1}}return{cookie:"",page:t,nextPage:t+1}}}])});