dynamics-web-api
Advanced tools
Comparing version 1.2.4 to 1.2.5
@@ -1,2 +0,2 @@ | ||
/*! dwa v1.2.4 (c) 2017 Aleksandr Rogov */ | ||
/*! dwa v1.2.5 (c) 2017 Aleksandr Rogov */ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
@@ -3,0 +3,0 @@ if(typeof exports === 'object' && typeof module === 'object') |
@@ -1,2 +0,2 @@ | ||
/*! dynamics-web-api-callbacks v1.2.4 (c) 2017 Aleksandr Rogov */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],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 i=a[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.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=13)}([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,i){void 0!==e&&null!==e&&""!=e||a(t,r,i)},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")}},callbackParameterCheck:function(e,t,r){"function"!=typeof e&&a(t,r,"Function")}};e.exports=r},function(e,t){String.prototype.endsWith=function(e,t){var a=this.toString();("number"!=typeof t||!isFinite(t)||Math.floor(t)!==t||t>a.length)&&(t=a.length),t-=e.length;var r=a.lastIndexOf(e,t);return r!==-1&&r===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,a){a(0);e.exports=function(e,t,r,i,n,c,s){r.impersonate&&(!n||n&&!n.MSCRMCallerID)&&(n||(n={}),n.MSCRMCallerID=r.impersonate);var o;i&&(o=JSON.stringify(i,function(e,t){return e.endsWith("@odata.bind")&&"string"==typeof t&&!t.startsWith(r.webApiUrl)&&(t=r.webApiUrl+t),t}));var l;"undefined"!=typeof XMLHttpRequest&&(l=a(8));var u=function(a){a&&(n||(n={}),n.Authorization="Bearer "+a.accessToken),l(e,r.webApiUrl+t,o,n,c,s)};r.onTokenRefresh&&(!n||n&&!n.Authorization)?r.onTokenRefresh(u):u()}},function(e,t,a){function r(e,t,a,i,s){var o={},l=[];if(i=null!=i?i:"&",e){e.navigationProperty&&(n.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),a+="/"+e.navigationProperty),null!=e.select&&e.select.length&&(n.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&&(n.stringParameterCheck(e.filter,"DynamicsWebApi."+t,"request.filter"),l.push("$filter="+e.filter)),e.savedQuery&&l.push("savedQuery="+n.guidParameterCheck(e.savedQuery,"DynamicsWebApi."+t,"request.savedQuery")),e.userQuery&&l.push("userQuery="+n.guidParameterCheck(e.userQuery,"DynamicsWebApi."+t,"request.userQuery")),e.count&&(n.boolParameterCheck(e.count,"DynamicsWebApi."+t,"request.count"),l.push("$count="+e.count)),e.top&&e.top>0&&(n.numberParameterCheck(e.top,"DynamicsWebApi."+t,"request.top"),l.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(n.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&&(n.stringParameterCheck(e.ifmatch,"DynamicsWebApi."+t,"request.ifmatch"),o["If-Match"]=e.ifmatch),e.ifnonematch&&(n.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),o["If-None-Match"]=e.ifnonematch),e.impersonate&&(n.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),o.MSCRMCallerID=n.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(n.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),o.Authorization="Bearer "+e.token),e.expand&&e.expand.length)if(n.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)l.push("$expand="+encodeURI(e.expand));else{for(var p=[],m=0;m<e.expand.length;m++)if(e.expand[m].property){var h=r(e.expand[m],t+" $expand",null,";"),d=h.query;d&&d.length&&(d="("+d+")"),p.push(e.expand[m].property+d)}p.length&&l.push("$expand="+encodeURI(p.join(",")))}}return{url:a,query:l.join(i),headers:o}}function i(e,t,a){e.collection?n.stringParameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection"):n.parameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection");var i=e.collection.toLowerCase();e.id&&(e.id=n.guidParameterCheck(e.id,"DynamicsWebApi."+t,"request.id"),i+="("+e.id+")");var c=r(e,t,i,"&",a);return c.query&&(c.url+="?"+encodeURI(c.query)),{url:c.url,headers:c.headers}}var n=(a(0),a(1)),c=a(10),s={convertRequestOptions:r,convertRequest:i};e.exports=s},function(e,t,a){var r={buildFunctionParameters:a(9),getFetchXmlPagingCookie:a(12),convertToReferenceObject:a(11)};e.exports=r},function(e,t){e.exports=function(e,t){return"string"==typeof t&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.exec(t)?new Date(t):t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var a=e.split("\r\n"),r=0,i=a.length;r<i;r++){var n=a[r],c=n.indexOf(": ");c>0&&(t[n.substring(0,c)]=n.substring(c+2))}return t}},function(e,t,a){var r=a(6),i=a(7),n=function(e,t,a,n,c,s){var o=new XMLHttpRequest;if(o.open(e,t,!0),o.setRequestHeader("OData-MaxVersion","4.0"),o.setRequestHeader("OData-Version","4.0"),o.setRequestHeader("Accept","application/json"),o.setRequestHeader("Content-Type","application/json; charset=utf-8"),null!=n)for(var l in n)o.setRequestHeader(l,n[l]);o.onreadystatechange=function(){if(4===o.readyState){switch(o.status){case 200:case 201:case 204:case 304:var e=null;o.responseText&&(e=JSON.parse(o.responseText,r));c({data:e,headers:i(o.getAllResponseHeaders()),status:o.status});break;default:var t;try{t=JSON.parse(o.response).error}catch(e){t=o.response.length>0?{message:o.response}:{message:"Unexpected Error"}}t.status=o.status,s(t)}o=null}},o.onerror=function(){s({message:"Network Error"}),o=null},o.ontimeout=function(e){s({message:"Request Timed Out"}),o=null},a?o.send(a):o.send()};e.exports=n},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),a="",r="",i=1;i<=t.length;i++){var n=t[i-1],c=e[n];i>1&&(a+=",",r+="&"),a+=n+"=@p"+i,r+="@p"+i+"="+("string"==typeof c?"'"+c+"'":c)}return"("+a+")?"+r}return"()"}},function(e,t,a){var r=a(0),i=a(1);e.exports=function(e,t,a){var n=e.returnRepresentation,c=e.includeAnnotations,s=e.maxPageSize;if(e.prefer&&e.prefer.length){i.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?n=!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==n&&(n=a.returnRepresentation),c=c?c:a.includeAnnotations,s=s?s:a.maxPageSize);var o=[];return n&&(i.boolParameterCheck(n,"DynamicsWebApi."+t,"request.returnRepresentation"),o.push(r.Prefer.ReturnRepresentation)),c&&(i.stringParameterCheck(c,"DynamicsWebApi."+t,"request.includeAnnotations"),o.push('odata.include-annotations="'+c+'"')),s&&s>0&&(i.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?e:"",t=t?t:1,e=unescape(unescape(e));var a=/pagingcookie="(<cookie page="(\d+)".+<\/cookie>)/.exec(e);if(null!=a){var r=parseInt(a[2]);return{cookie:a[1].replace(/</g,"<").replace(/>/g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:r,nextPage:r+1}}return{cookie:"",page:t,nextPage:t+1}}},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);var a=function(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm)return Xrm.Page.context;throw new Error("Xrm Context is not available.")},o=function(){var e=a();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""},l=function(){return o()+"/api/data/v"+t.webApiVersion+"/"};this.setConfig=function(e){e.webApiVersion&&(c.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(c.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=l(),e.impersonate&&(t.impersonate=c.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(c.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(c.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(c.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(c.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation)},this.setConfig(e);var u=function(e,a,r,i,n,c){s(e,a,t,r,i,n,c)};this.create=function(e,a,r,i,s,o){c.parameterCheck(e,"DynamicsWebApi.create","object"),c.stringParameterCheck(a,"DynamicsWebApi.create","collection"),c.callbackParameterCheck(r,"DynamicsWebApi.create","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.create","errorCallback"),s&&c.stringOrArrayParameterCheck(s,"DynamicsWebApi.create","prefer"),o&&c.arrayParameterCheck(o,"DynamicsWebApi.create","select");var l={collection:a,select:o,prefer:s},p=n.convertRequest(l,"create",t),m=function(e){if(e.data)r(e.data);else{var t=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(t)[0])}};u("POST",p.url,e,p.headers,m,i)},this.updateRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.update","request"),c.parameterCheck(e.entity,"DynamicsWebApi.update","request.entity"),c.callbackParameterCheck(a,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.update","errorCallback");var i=n.convertRequest(e,"update",t);null==e.ifmatch&&(i.headers["If-Match"]="*");var s=function(e){a(e.data?e.data:!0)},o=e.ifmatch,l=function(e){o&&412==e.status?a(!1):r(e)};u("PATCH",i.url,e.entity,i.headers,s,l)},this.update=function(e,t,a,r,i,n,s){c.stringParameterCheck(e,"DynamicsWebApi.update","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.update","id"),c.parameterCheck(a,"DynamicsWebApi.update","object"),c.stringParameterCheck(t,"DynamicsWebApi.update","collection"),c.callbackParameterCheck(r,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.update","errorCallback"),n&&c.stringOrArrayParameterCheck(n,"DynamicsWebApi.update","prefer"),s&&c.arrayParameterCheck(s,"DynamicsWebApi.update","select");var o={collection:t,id:e,select:s,prefer:n,entity:a};this.updateRequest(o,r,i)},this.updateSingleProperty=function(e,a,r,i,s,o,l){c.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),c.parameterCheck(r,"DynamicsWebApi.updateSingleProperty","keyValuePair"),c.stringParameterCheck(a,"DynamicsWebApi.updateSingleProperty","collection"),c.callbackParameterCheck(i,"DynamicsWebApi.updateSingleProperty","successCallback"),c.callbackParameterCheck(s,"DynamicsWebApi.updateSingleProperty","errorCallback"),o&&c.stringOrArrayParameterCheck(o,"DynamicsWebApi.updateSingleProperty","prefer"),l&&c.arrayParameterCheck(l,"DynamicsWebApi.updateSingleProperty","select");var p=Object.keys(r)[0],m=r[p],h={collection:a,id:e,select:l,prefer:o,navigationProperty:p},d=n.convertRequest(h,"updateSingleProperty",t),b=function(e){e.data?i(e.data):i()};u("PUT",d.url,{value:m},d.headers,b,s)},this.deleteRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.delete","request"),c.callbackParameterCheck(a,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.delete","errorCallback");var i=n.convertRequest(e,"delete",t),s=function(){a(!0)},o=e.ifmatch,l=function(e){o&&412==e.status?a(!1):r(e)};u("DELETE",i.url,null,i.headers,s,l)},this.deleteRecord=function(e,t,a,r,i){c.stringParameterCheck(e,"DynamicsWebApi.delete","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.delete","id"),c.stringParameterCheck(t,"DynamicsWebApi.delete","collection"),c.callbackParameterCheck(a,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.delete","errorCallback"),null!=i&&c.stringParameterCheck(i,"DynamicsWebApi.delete","propertyName");var n=t.toLowerCase()+"("+e+")";null!=i&&(n+="/"+i),u("DELETE",n,null,null,function(e){a()},r)},this.retrieveRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.retrieve","request"),c.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback");var s=n.convertRequest(e,"retrieve",t),o=e.select,l=function(e){a(null!=o&&1==o.length&&o[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?i.convertToReferenceObject(e.data):e.data)};u("GET",s.url,null,s.headers,l,r)},this.retrieve=function(e,t,a,r,i,n){c.stringParameterCheck(e,"DynamicsWebApi.retrieve","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.retrieve","id"),c.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),c.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback"),i&&i.length&&c.arrayParameterCheck(i,"DynamicsWebApi.retrieve","select"),n&&n.length&&c.stringOrArrayParameterCheck(n,"DynamicsWebApi.retrieve","expand");var s={collection:t,id:e,select:i,expand:n};this.retrieveRequest(s,a,r)},this.upsertRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.upsert","request"),c.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity"),c.callbackParameterCheck(a,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.upsert","errorCallback");var i=n.convertRequest(e,"upsert",t),s=e.ifnonematch,o=e.ifmatch,l=function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){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])}else e.data?a(e.data):a()},p=function(e){s&&412==e.status?a():o&&404==e.status?a():r(e)};u("PATCH",i.url,e.entity,i.headers,l,p)},this.upsert=function(e,t,a,r,i,n,s){c.stringParameterCheck(e,"DynamicsWebApi.upsert","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.upsert","id"),c.parameterCheck(a,"DynamicsWebApi.upsert","object"),c.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),c.callbackParameterCheck(r,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.upsert","errorCallback"),n&&c.stringOrArrayParameterCheck(n,"DynamicsWebApi.upsert","prefer"),s&&c.arrayParameterCheck(s,"DynamicsWebApi.upsert","select");var o={collection:t,id:e,select:s,prefer:n,entity:a};this.upsertRequest(o,r,i)},this.count=function(e,t,a,r){if(null!=r&&(null==r||r.length))return this.retrieveMultipleRequest({collection:e,filter:r,count:!0},function(e){t(e.oDataCount?e.oDataCount:0)},a);c.stringParameterCheck(e,"DynamicsWebApi.count","collection"),c.callbackParameterCheck(t,"DynamicsWebApi.count","successCallback"),c.callbackParameterCheck(a,"DynamicsWebApi.count","errorCallback");var i=function(e){t(e.data?parseInt(e.data):0)};u("GET",e.toLowerCase()+"/$count",null,null,i,a)},this.countAll=function(e,t,a,r,i){return this.retrieveAllRequest({collection:e,filter:r,select:i},function(e){t(e&&e.value?e.value.length:0)},a)},this.retrieveMultiple=function(e,t,a,r,i,n){return this.retrieveMultipleRequest({collection:e,select:r,filter:i},t,a,n)};var p=function(e,a,r,i){c.callbackParameterCheck(a,"DynamicsWebApi.retrieveMultiple","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.retrieveMultiple","errorCallback"),i&&!e.collection&&(e.collection="any");var s=n.convertRequest(e,"retrieveMultiple",t);i&&(c.stringParameterCheck(i,"DynamicsWebApi.retrieveMultiple","nextPageLink"),s.url=i.replace(t.webApiUrl,""));var o=e.count,l=function(e){null!=e.data["@odata.nextLink"]&&(e.data.oDataNextLink=e.data["@odata.nextLink"]),o&&(e.data.oDataCount=null!=e.data["@odata.count"]?parseInt(e.data["@odata.count"]):0),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),a(e.data)};u("GET",s.url,null,s.headers,l,r)};this.retrieveMultipleRequest=p;var m=function(e,t,a,r,i){var i=i||[];p(e,function(r){i=i.concat(r.value),r.oDataNextLink?m(e,t,a,r.oDataNextLink,i):t({value:i})},a,r)};this.retrieveAllRequest=function(e,t,a){m(e,t,a)},this.executeFetchXml=function(e,a,r,s,o,l,p,m){c.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","collection"),c.stringParameterCheck(a,"DynamicsWebApi.executeFetchXml","fetchXml"),c.callbackParameterCheck(r,"DynamicsWebApi.executeFetchXml","successCallback"),c.callbackParameterCheck(s,"DynamicsWebApi.executeFetchXml","errorCallback"),null==l&&(l=1),c.numberParameterCheck(l,"DynamicsWebApi.executeFetchXml","pageNumber");var h='$1 page="'+l+'"';null!=p&&(c.stringParameterCheck(p,"DynamicsWebApi.executeFetchXml","pagingCookie"),h+=' paging-cookie="'+p+'"'),a=a.replace(/^(<fetch[\w\d\s'"=]+)/,h),o&&c.stringParameterCheck(o,"DynamicsWebApi.executeFetchXml","includeAnnotations"),m&&(m=c.guidParameterCheck(m,"DynamicsWebApi.executeFetchXml","impersonateUserId"));var d={collection:e,includeAnnotations:o,impersonate:m},b=n.convertRequest(d,"executeFetchXml",t),y=encodeURIComponent(a),f=function(e){null!=e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"]&&(e.data.PagingInfo=i.getFetchXmlPagingCookie(e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"],l)),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),r(e.data)};u("GET",b.url+"?fetchXml="+y,null,b.headers,f,s)},this.associate=function(e,a,r,i,n,s,o,l){c.stringParameterCheck(e,"DynamicsWebApi.associate","primarycollection"),c.stringParameterCheck(i,"DynamicsWebApi.associate","relatedcollection"),c.stringParameterCheck(r,"DynamicsWebApi.associate","relationshipName"),a=c.guidParameterCheck(a,"DynamicsWebApi.associate","primaryId"),n=c.guidParameterCheck(n,"DynamicsWebApi.associate","relatedId"),c.callbackParameterCheck(s,"DynamicsWebApi.associate","successCallback"),c.callbackParameterCheck(o,"DynamicsWebApi.associate","errorCallback");var p=function(){s()},m={};null!=l&&(l=c.guidParameterCheck(l,"DynamicsWebApi.associate","impersonateUserId"),m.MSCRMCallerID=l),u("POST",e+"("+a+")/"+r+"/$ref",{"@odata.id":t.webApiUrl+i+"("+n+")"},m,p,o)},this.disassociate=function(e,t,a,r,i,n,s){c.stringParameterCheck(e,"DynamicsWebApi.disassociate","primarycollection"),c.stringParameterCheck(a,"DynamicsWebApi.disassociate","relationshipName"),t=c.guidParameterCheck(t,"DynamicsWebApi.disassociate","primaryId"),r=c.guidParameterCheck(r,"DynamicsWebApi.disassociate","relatedId"),c.callbackParameterCheck(i,"DynamicsWebApi.disassociate","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.disassociate","errorCallback");var o=function(){i()},l={};null!=s&&(s=c.guidParameterCheck(s,"DynamicsWebApi.associate","impersonateUserId"),l.MSCRMCallerID=s),u("DELETE",e+"("+t+")/"+a+"("+r+")/$ref",null,l,o,n)},this.associateSingleValued=function(e,a,r,i,n,s,o,l){c.stringParameterCheck(e,"DynamicsWebApi.associateSingleValued","collection"),a=c.guidParameterCheck(a,"DynamicsWebApi.associateSingleValued","id"),n=c.guidParameterCheck(n,"DynamicsWebApi.associateSingleValued","relatedId"),c.stringParameterCheck(r,"DynamicsWebApi.associateSingleValued","singleValuedNavigationPropertyName"),c.stringParameterCheck(i,"DynamicsWebApi.associateSingleValued","relatedcollection"),c.callbackParameterCheck(s,"DynamicsWebApi.associateSingleValued","successCallback"),c.callbackParameterCheck(o,"DynamicsWebApi.associateSingleValued","errorCallback");var p=function(){s()},m={};null!=l&&(l=c.guidParameterCheck(l,"DynamicsWebApi.associate","impersonateUserId"),m.MSCRMCallerID=l),u("PUT",e+"("+a+")/"+r+"/$ref",{"@odata.id":t.webApiUrl+i+"("+n+")"},m,p,o)},this.disassociateSingleValued=function(e,t,a,r,i,n){c.stringParameterCheck(e,"DynamicsWebApi.disassociateSingleValued","collection"),t=c.guidParameterCheck(t,"DynamicsWebApi.disassociateSingleValued","id"),c.stringParameterCheck(a,"DynamicsWebApi.disassociateSingleValued","singleValuedNavigationPropertyName"),c.callbackParameterCheck(r,"DynamicsWebApi.disassociateSingleValued","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.disassociateSingleValued","errorCallback");var s={};null!=n&&(n=c.guidParameterCheck(n,"DynamicsWebApi.associate","impersonateUserId"),s.MSCRMCallerID=n),u("DELETE",e+"("+t+")/"+a+"/$ref",null,s,function(){r()},i)},this.executeUnboundFunction=function(e,t,a,r,i){return h(e,r,null,null,t,a,i)},this.executeBoundFunction=function(e,t,a,r,i,n,c){return h(a,n,t,e,r,i,c)};var h=function(e,t,a,r,n,s,o){c.stringParameterCheck(e,"DynamicsWebApi.executeFunction","functionName"),c.callbackParameterCheck(n,"DynamicsWebApi.executeFunction","successCallback"),c.callbackParameterCheck(s,"DynamicsWebApi.executeFunction","errorCallback");var l=e+i.buildFunctionParameters(t);null!=a&&(c.stringParameterCheck(a,"DynamicsWebApi.executeFunction","collection"),r=c.guidParameterCheck(r,"DynamicsWebApi.executeFunction","id"),l=a+"("+r+")/"+l);var p={};null!=o&&(p.MSCRMCallerID=c.guidParameterCheck(o,"DynamicsWebApi.associate","impersonateUserId")),u("GET",l,null,p,function(e){e.data?n(e.data):n()},s)};this.executeUnboundAction=function(e,t,a,r,i){return d(e,t,null,null,a,r,i)},this.executeBoundAction=function(e,t,a,r,i,n,c){return d(a,r,t,e,i,n,c)};var d=function(e,t,a,r,i,n,s){c.stringParameterCheck(e,"DynamicsWebApi.executeAction","actionName"),c.callbackParameterCheck(i,"DynamicsWebApi.executeAction","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.executeAction","errorCallback");var o=e;null!=a&&(c.stringParameterCheck(a,"DynamicsWebApi.executeAction","collection"),r=c.guidParameterCheck(r,"DynamicsWebApi.executeAction","id"),o=a+"("+r+")/"+o);var l={};null!=s&&(s=c.guidParameterCheck(s,"DynamicsWebApi.associate","impersonateUserId"),l.MSCRMCallerID=s),u("POST",o,t,l,function(e){e.data?i(e.data):i()},n)};this.initializeInstance=function(e){return e||(e=t),new r(e)}}var i=(a(0),a(5)),n=a(4),c=a(1),s=a(3);String.prototype.endsWith&&String.prototype.startsWith||a(2),e.exports=r}])}); | ||
/*! dynamics-web-api-callbacks v1.2.5 (c) 2017 Aleksandr Rogov */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],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=13)}([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")}},callbackParameterCheck:function(e,t,r){"function"!=typeof e&&a(t,r,"Function")}};e.exports=r},function(e,t){String.prototype.endsWith=function(e,t){var a=this.toString();("number"!=typeof t||!isFinite(t)||Math.floor(t)!==t||t>a.length)&&(t=a.length),t-=e.length;var r=a.lastIndexOf(e,t);return r!==-1&&r===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,a){a(0);e.exports=function(e,t,r,n,i,c,s){r.impersonate&&(!i||i&&!i.MSCRMCallerID)&&(i||(i={}),i.MSCRMCallerID=r.impersonate);var o;n&&(o=JSON.stringify(n,function(e,t){return e.endsWith("@odata.bind")&&"string"==typeof t&&!t.startsWith(r.webApiUrl)&&(t=r.webApiUrl+t),t}));var l;"undefined"!=typeof XMLHttpRequest&&(l=a(8));var u=function(a){a&&(i||(i={}),i.Authorization="Bearer "+a.accessToken),l(e,r.webApiUrl+t,o,i,c,s)};r.onTokenRefresh&&(!i||i&&!i.Authorization)?r.onTokenRefresh(u):u()}},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.expand&&e.expand.length)if(i.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)l.push("$expand="+encodeURI(e.expand));else{for(var p=[],m=0;m<e.expand.length;m++)if(e.expand[m].property){var h=r(e.expand[m],t+" $expand",null,";"),d=h.query;d&&d.length&&(d="("+d+")"),p.push(e.expand[m].property+d)}p.length&&l.push("$expand="+encodeURI(p.join(",")))}}return{url:a,query:l.join(n),headers:o}}function n(e,t,a){e.collection?i.stringParameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection"):i.parameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection");var n=e.collection.toLowerCase();e.id&&(e.id=i.guidParameterCheck(e.id,"DynamicsWebApi."+t,"request.id"),n+="("+e.id+")");var c=r(e,t,n,"&",a);return c.query&&(c.url+="?"+encodeURI(c.query)),{url:c.url,headers:c.headers}}var i=(a(0),a(1)),c=a(10),s={convertRequestOptions:r,convertRequest:n};e.exports=s},function(e,t,a){var r={buildFunctionParameters:a(9),getFetchXmlPagingCookie:a(12),convertToReferenceObject:a(11)};e.exports=r},function(e,t){e.exports=function(e,t){return"string"==typeof t&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.exec(t)?new Date(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;r<n;r++){var i=a[r],c=i.indexOf(": ");c>0&&(t[i.substring(0,c)]=i.substring(c+2))}return t}},function(e,t,a){var r=a(6),n=a(7),i=function(e,t,a,i,c,s){var o=new XMLHttpRequest;if(o.open(e,t,!0),o.setRequestHeader("OData-MaxVersion","4.0"),o.setRequestHeader("OData-Version","4.0"),o.setRequestHeader("Accept","application/json"),o.setRequestHeader("Content-Type","application/json; charset=utf-8"),null!=i)for(var l in i)o.setRequestHeader(l,i[l]);o.onreadystatechange=function(){if(4===o.readyState){switch(o.status){case 200:case 201:case 204:case 304:var e=null;o.responseText&&(e=JSON.parse(o.responseText,r));c({data:e,headers:n(o.getAllResponseHeaders()),status:o.status});break;default:var t;try{t=JSON.parse(o.response).error}catch(e){t=o.response.length>0?{message:o.response}:{message:"Unexpected Error"}}t.status=o.status,s(t)}o=null}},o.onerror=function(){s({message:"Network Error"}),o=null},o.ontimeout=function(e){s({message:"Request Timed Out"}),o=null},a?o.send(a):o.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?c:a.includeAnnotations,s=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?e:"",t=t?t:1,e=unescape(unescape(e));var a=/pagingcookie="(<cookie page="(\d+)".+<\/cookie>)/.exec(e);if(null!=a){var r=parseInt(a[2]);return{cookie:a[1].replace(/</g,"<").replace(/>/g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:r,nextPage:r+1}}return{cookie:"",page:t,nextPage:t+1}}},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);var a=function(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm)return Xrm.Page.context;throw new Error("Xrm Context is not available.")},o=function(){var e=a();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""},l=function(){return o()+"/api/data/v"+t.webApiVersion+"/"};this.setConfig=function(e){e.webApiVersion&&(c.stringParameterCheck(e.webApiVersion,"DynamicsWebApi.setConfig","config.webApiVersion"),t.webApiVersion=e.webApiVersion),e.webApiUrl?(c.stringParameterCheck(e.webApiUrl,"DynamicsWebApi.setConfig","config.webApiUrl"),t.webApiUrl=e.webApiUrl):t.webApiUrl=l(),e.impersonate&&(t.impersonate=c.guidParameterCheck(e.impersonate,"DynamicsWebApi.setConfig","config.impersonate")),e.onTokenRefresh&&(c.callbackParameterCheck(e.onTokenRefresh,"DynamicsWebApi.setConfig","config.onTokenRefresh"),t.onTokenRefresh=e.onTokenRefresh),e.includeAnnotations&&(c.stringParameterCheck(e.includeAnnotations,"DynamicsWebApi.setConfig","config.includeAnnotations"),t.includeAnnotations=e.includeAnnotations),e.maxPageSize&&(c.numberParameterCheck(e.maxPageSize,"DynamicsWebApi.setConfig","config.maxPageSize"),t.maxPageSize=e.maxPageSize),e.returnRepresentation&&(c.boolParameterCheck(e.returnRepresentation,"DynamicsWebApi.setConfig","config.returnRepresentation"),t.returnRepresentation=e.returnRepresentation)},this.setConfig(e);var u=function(e,a,r,n,i,c){s(e,a,t,r,n,i,c)};this.create=function(e,a,r,n,s,o){c.parameterCheck(e,"DynamicsWebApi.create","object"),c.stringParameterCheck(a,"DynamicsWebApi.create","collection"),c.callbackParameterCheck(r,"DynamicsWebApi.create","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.create","errorCallback"),s&&c.stringOrArrayParameterCheck(s,"DynamicsWebApi.create","prefer"),o&&c.arrayParameterCheck(o,"DynamicsWebApi.create","select");var l={collection:a,select:o,prefer:s},p=i.convertRequest(l,"create",t),m=function(e){if(e.data)r(e.data);else{var t=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(t)[0])}};u("POST",p.url,e,p.headers,m,n)},this.updateRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.update","request"),c.parameterCheck(e.entity,"DynamicsWebApi.update","request.entity"),c.callbackParameterCheck(a,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.update","errorCallback");var n=i.convertRequest(e,"update",t);null==e.ifmatch&&(n.headers["If-Match"]="*");var s=function(e){a(e.data?e.data:!0)},o=e.ifmatch,l=function(e){o&&412==e.status?a(!1):r(e)};u("PATCH",n.url,e.entity,n.headers,s,l)},this.update=function(e,t,a,r,n,i,s){c.stringParameterCheck(e,"DynamicsWebApi.update","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.update","id"),c.parameterCheck(a,"DynamicsWebApi.update","object"),c.stringParameterCheck(t,"DynamicsWebApi.update","collection"),c.callbackParameterCheck(r,"DynamicsWebApi.update","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.update","errorCallback"),i&&c.stringOrArrayParameterCheck(i,"DynamicsWebApi.update","prefer"),s&&c.arrayParameterCheck(s,"DynamicsWebApi.update","select");var o={collection:t,id:e,select:s,prefer:i,entity:a};this.updateRequest(o,r,n)},this.updateSingleProperty=function(e,a,r,n,s,o,l){c.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),c.parameterCheck(r,"DynamicsWebApi.updateSingleProperty","keyValuePair"),c.stringParameterCheck(a,"DynamicsWebApi.updateSingleProperty","collection"),c.callbackParameterCheck(n,"DynamicsWebApi.updateSingleProperty","successCallback"),c.callbackParameterCheck(s,"DynamicsWebApi.updateSingleProperty","errorCallback"),o&&c.stringOrArrayParameterCheck(o,"DynamicsWebApi.updateSingleProperty","prefer"),l&&c.arrayParameterCheck(l,"DynamicsWebApi.updateSingleProperty","select");var p=Object.keys(r)[0],m=r[p],h={collection:a,id:e,select:l,prefer:o,navigationProperty:p},d=i.convertRequest(h,"updateSingleProperty",t),b=function(e){e.data?n(e.data):n()};u("PUT",d.url,{value:m},d.headers,b,s)},this.deleteRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.delete","request"),c.callbackParameterCheck(a,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.delete","errorCallback");var n=i.convertRequest(e,"delete",t),s=function(){a(!0)},o=e.ifmatch,l=function(e){o&&412==e.status?a(!1):r(e)};u("DELETE",n.url,null,n.headers,s,l)},this.deleteRecord=function(e,t,a,r,n){c.stringParameterCheck(e,"DynamicsWebApi.delete","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.delete","id"),c.stringParameterCheck(t,"DynamicsWebApi.delete","collection"),c.callbackParameterCheck(a,"DynamicsWebApi.delete","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.delete","errorCallback"),null!=n&&c.stringParameterCheck(n,"DynamicsWebApi.delete","propertyName");var i=t.toLowerCase()+"("+e+")";null!=n&&(i+="/"+n),u("DELETE",i,null,null,function(e){a()},r)},this.retrieveRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.retrieve","request"),c.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback");var s=i.convertRequest(e,"retrieve",t),o=e.select,l=function(e){a(null!=o&&1==o.length&&o[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?n.convertToReferenceObject(e.data):e.data)};u("GET",s.url,null,s.headers,l,r)},this.retrieve=function(e,t,a,r,n,i){c.stringParameterCheck(e,"DynamicsWebApi.retrieve","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.retrieve","id"),c.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),c.callbackParameterCheck(a,"DynamicsWebApi.retrieve","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.retrieve","errorCallback"),n&&n.length&&c.arrayParameterCheck(n,"DynamicsWebApi.retrieve","select"),i&&i.length&&c.stringOrArrayParameterCheck(i,"DynamicsWebApi.retrieve","expand");var s={collection:t,id:e,select:n,expand:i};this.retrieveRequest(s,a,r)},this.upsertRequest=function(e,a,r){c.parameterCheck(e,"DynamicsWebApi.upsert","request"),c.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity"),c.callbackParameterCheck(a,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.upsert","errorCallback");var n=i.convertRequest(e,"upsert",t),s=e.ifnonematch,o=e.ifmatch,l=function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){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])}else e.data?a(e.data):a()},p=function(e){s&&412==e.status?a():o&&404==e.status?a():r(e)};u("PATCH",n.url,e.entity,n.headers,l,p)},this.upsert=function(e,t,a,r,n,i,s){c.stringParameterCheck(e,"DynamicsWebApi.upsert","id"),e=c.guidParameterCheck(e,"DynamicsWebApi.upsert","id"),c.parameterCheck(a,"DynamicsWebApi.upsert","object"),c.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),c.callbackParameterCheck(r,"DynamicsWebApi.upsert","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.upsert","errorCallback"),i&&c.stringOrArrayParameterCheck(i,"DynamicsWebApi.upsert","prefer"),s&&c.arrayParameterCheck(s,"DynamicsWebApi.upsert","select");var o={collection:t,id:e,select:s,prefer:i,entity:a};this.upsertRequest(o,r,n)},this.count=function(e,t,a,r){if(null!=r&&(null==r||r.length))return this.retrieveMultipleRequest({collection:e,filter:r,count:!0},function(e){t(e.oDataCount?e.oDataCount:0)},a);c.stringParameterCheck(e,"DynamicsWebApi.count","collection"),c.callbackParameterCheck(t,"DynamicsWebApi.count","successCallback"),c.callbackParameterCheck(a,"DynamicsWebApi.count","errorCallback");var n=function(e){t(e.data?parseInt(e.data):0)};u("GET",e.toLowerCase()+"/$count",null,null,n,a)},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 m({collection:e,select:r,filter:n},t,a)};var p=function(e,a,r,n){c.callbackParameterCheck(a,"DynamicsWebApi.retrieveMultiple","successCallback"),c.callbackParameterCheck(r,"DynamicsWebApi.retrieveMultiple","errorCallback"),n&&!e.collection&&(e.collection="any");var s=i.convertRequest(e,"retrieveMultiple",t);n&&(c.stringParameterCheck(n,"DynamicsWebApi.retrieveMultiple","nextPageLink"),s.url=n.replace(t.webApiUrl,""));var o=e.count,l=function(e){null!=e.data["@odata.nextLink"]&&(e.data.oDataNextLink=e.data["@odata.nextLink"]),o&&(e.data.oDataCount=null!=e.data["@odata.count"]?parseInt(e.data["@odata.count"]):0),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),a(e.data)};u("GET",s.url,null,s.headers,l,r)};this.retrieveMultipleRequest=p;var m=function(e,t,a,r,n){var n=n||[];p(e,function(r){n=n.concat(r.value),r.oDataNextLink?m(e,t,a,r.oDataNextLink,n):t({value:n})},a,r)};this.retrieveAllRequest=function(e,t,a){m(e,t,a)};var h=function(e,a,r,s,o,l,p,m){c.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","collection"),c.stringParameterCheck(a,"DynamicsWebApi.executeFetchXml","fetchXml"),c.callbackParameterCheck(r,"DynamicsWebApi.executeFetchXml","successCallback"),c.callbackParameterCheck(s,"DynamicsWebApi.executeFetchXml","errorCallback"),null==l&&(l=1),c.numberParameterCheck(l,"DynamicsWebApi.executeFetchXml","pageNumber");var h='$1 page="'+l+'"';null!=p&&(c.stringParameterCheck(p,"DynamicsWebApi.executeFetchXml","pagingCookie"),h+=' paging-cookie="'+p+'"'),a=a.replace(/^(<fetch[\w\d\s'"=]+)/,h),o&&c.stringParameterCheck(o,"DynamicsWebApi.executeFetchXml","includeAnnotations"),m&&(m=c.guidParameterCheck(m,"DynamicsWebApi.executeFetchXml","impersonateUserId"));var d={collection:e,includeAnnotations:o,impersonate:m},b=i.convertRequest(d,"executeFetchXml",t),f=encodeURIComponent(a),y=function(e){null!=e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"]&&(e.data.PagingInfo=n.getFetchXmlPagingCookie(e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"],l)),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),r(e.data)};u("GET",b.url+"?fetchXml="+f,null,b.headers,y,s)};this.fetch=this.executeFetchXml=h;var d=function(e,t,a,r,n,i,c,s,o){var o=o||[];h(e,t,function(i){o=o.concat(i.value),i.PagingInfo?d(e,t,a,r,n,i.PagingInfo.nextPage,i.PagingInfo.cookie,s,o):a({value:o})},r,n,i,c,s)};this.fetchAll=this.executeFetchXmlAll=function(e,t,a,r,n,i){return d(e,t,a,r,n,null,null,i)},this.associate=function(e,a,r,n,i,s,o,l){c.stringParameterCheck(e,"DynamicsWebApi.associate","primarycollection"),c.stringParameterCheck(n,"DynamicsWebApi.associate","relatedcollection"),c.stringParameterCheck(r,"DynamicsWebApi.associate","relationshipName"),a=c.guidParameterCheck(a,"DynamicsWebApi.associate","primaryId"),i=c.guidParameterCheck(i,"DynamicsWebApi.associate","relatedId"),c.callbackParameterCheck(s,"DynamicsWebApi.associate","successCallback"),c.callbackParameterCheck(o,"DynamicsWebApi.associate","errorCallback");var p=function(){s()},m={};null!=l&&(l=c.guidParameterCheck(l,"DynamicsWebApi.associate","impersonateUserId"),m.MSCRMCallerID=l),u("POST",e+"("+a+")/"+r+"/$ref",{"@odata.id":t.webApiUrl+n+"("+i+")"},m,p,o)},this.disassociate=function(e,t,a,r,n,i,s){c.stringParameterCheck(e,"DynamicsWebApi.disassociate","primarycollection"),c.stringParameterCheck(a,"DynamicsWebApi.disassociate","relationshipName"),t=c.guidParameterCheck(t,"DynamicsWebApi.disassociate","primaryId"),r=c.guidParameterCheck(r,"DynamicsWebApi.disassociate","relatedId"),c.callbackParameterCheck(n,"DynamicsWebApi.disassociate","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.disassociate","errorCallback");var o=function(){n()},l={};null!=s&&(s=c.guidParameterCheck(s,"DynamicsWebApi.associate","impersonateUserId"),l.MSCRMCallerID=s),u("DELETE",e+"("+t+")/"+a+"("+r+")/$ref",null,l,o,i)},this.associateSingleValued=function(e,a,r,n,i,s,o,l){c.stringParameterCheck(e,"DynamicsWebApi.associateSingleValued","collection"),a=c.guidParameterCheck(a,"DynamicsWebApi.associateSingleValued","id"),i=c.guidParameterCheck(i,"DynamicsWebApi.associateSingleValued","relatedId"),c.stringParameterCheck(r,"DynamicsWebApi.associateSingleValued","singleValuedNavigationPropertyName"),c.stringParameterCheck(n,"DynamicsWebApi.associateSingleValued","relatedcollection"),c.callbackParameterCheck(s,"DynamicsWebApi.associateSingleValued","successCallback"),c.callbackParameterCheck(o,"DynamicsWebApi.associateSingleValued","errorCallback");var p=function(){s()},m={};null!=l&&(l=c.guidParameterCheck(l,"DynamicsWebApi.associate","impersonateUserId"),m.MSCRMCallerID=l),u("PUT",e+"("+a+")/"+r+"/$ref",{"@odata.id":t.webApiUrl+n+"("+i+")"},m,p,o)},this.disassociateSingleValued=function(e,t,a,r,n,i){c.stringParameterCheck(e,"DynamicsWebApi.disassociateSingleValued","collection"),t=c.guidParameterCheck(t,"DynamicsWebApi.disassociateSingleValued","id"),c.stringParameterCheck(a,"DynamicsWebApi.disassociateSingleValued","singleValuedNavigationPropertyName"),c.callbackParameterCheck(r,"DynamicsWebApi.disassociateSingleValued","successCallback"),c.callbackParameterCheck(n,"DynamicsWebApi.disassociateSingleValued","errorCallback");var s={};null!=i&&(i=c.guidParameterCheck(i,"DynamicsWebApi.associate","impersonateUserId"),s.MSCRMCallerID=i),u("DELETE",e+"("+t+")/"+a+"/$ref",null,s,function(){r()},n)},this.executeUnboundFunction=function(e,t,a,r,n){return b(e,r,null,null,t,a,n)},this.executeBoundFunction=function(e,t,a,r,n,i,c){return b(a,i,t,e,r,n,c)};var b=function(e,t,a,r,i,s,o){c.stringParameterCheck(e,"DynamicsWebApi.executeFunction","functionName"),c.callbackParameterCheck(i,"DynamicsWebApi.executeFunction","successCallback"),c.callbackParameterCheck(s,"DynamicsWebApi.executeFunction","errorCallback");var l=e+n.buildFunctionParameters(t);null!=a&&(c.stringParameterCheck(a,"DynamicsWebApi.executeFunction","collection"),r=c.guidParameterCheck(r,"DynamicsWebApi.executeFunction","id"),l=a+"("+r+")/"+l);var p={};null!=o&&(p.MSCRMCallerID=c.guidParameterCheck(o,"DynamicsWebApi.associate","impersonateUserId")),u("GET",l,null,p,function(e){e.data?i(e.data):i()},s)};this.executeUnboundAction=function(e,t,a,r,n){return f(e,t,null,null,a,r,n)},this.executeBoundAction=function(e,t,a,r,n,i,c){return f(a,r,t,e,n,i,c)};var f=function(e,t,a,r,n,i,s){c.stringParameterCheck(e,"DynamicsWebApi.executeAction","actionName"),c.callbackParameterCheck(n,"DynamicsWebApi.executeAction","successCallback"),c.callbackParameterCheck(i,"DynamicsWebApi.executeAction","errorCallback");var o=e;null!=a&&(c.stringParameterCheck(a,"DynamicsWebApi.executeAction","collection"),r=c.guidParameterCheck(r,"DynamicsWebApi.executeAction","id"),o=a+"("+r+")/"+o);var l={};null!=s&&(s=c.guidParameterCheck(s,"DynamicsWebApi.associate","impersonateUserId"),l.MSCRMCallerID=s),u("POST",o,t,l,function(e){e.data?n(e.data):n()},i)};this.initializeInstance=function(e){return e||(e=t),new r(e)}}var n=(a(0),a(5)),i=a(4),c=a(1),s=a(3);String.prototype.endsWith&&String.prototype.startsWith||a(2),e.exports=r}])}); |
@@ -1,2 +0,2 @@ | ||
/*! dynamics-web-api v1.2.4 (c) 2017 Aleksandr Rogov */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=13)}([function(e,t){var r={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){r.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){r.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){r.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){r.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=r},function(e,t){function r(e,t,r){throw new Error(r?e+" requires the "+t+" parameter to be of type "+r:e+" requires the "+t+" parameter.")}var n={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,n,a){void 0!==e&&null!==e&&""!=e||r(t,n,a)},stringParameterCheck:function(e,t,n){"string"!=typeof e&&r(t,n,"String")},arrayParameterCheck:function(e,t,n){e.constructor!==Array&&r(t,n,"Array")},stringOrArrayParameterCheck:function(e,t,n){e.constructor!==Array&&"string"!=typeof e&&r(t,n,"String or Array")},numberParameterCheck:function(e,t,n){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;r(t,n,"Number")}},boolParameterCheck:function(e,t,n){"boolean"!=typeof e&&r(t,n,"Boolean")},guidParameterCheck:function(e,t,n){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){r(t,n,"GUID String")}},callbackParameterCheck:function(e,t,n){"function"!=typeof e&&r(t,n,"Function")}};e.exports=n},function(e,t){String.prototype.endsWith=function(e,t){var r=this.toString();("number"!=typeof t||!isFinite(t)||Math.floor(t)!==t||t>r.length)&&(t=r.length),t-=e.length;var n=r.lastIndexOf(e,t);return n!==-1&&n===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,r){r(0);e.exports=function(e,t,n,a,i,o,s){n.impersonate&&(!i||i&&!i.MSCRMCallerID)&&(i||(i={}),i.MSCRMCallerID=n.impersonate);var c;a&&(c=JSON.stringify(a,function(e,t){return e.endsWith("@odata.bind")&&"string"==typeof t&&!t.startsWith(n.webApiUrl)&&(t=n.webApiUrl+t),t}));var u;"undefined"!=typeof XMLHttpRequest&&(u=r(8));var l=function(r){r&&(i||(i={}),i.Authorization="Bearer "+r.accessToken),u(e,n.webApiUrl+t,c,i,o,s)};n.onTokenRefresh&&(!i||i&&!i.Authorization)?n.onTokenRefresh(l):l()}},function(e,t,r){function n(e,t,r,a,s){var c={},u=[];if(a=null!=a?a:"&",e){e.navigationProperty&&(i.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),r+="/"+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")?r+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?r+=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,s);if(l.length&&(c.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"),c["If-Match"]=e.ifmatch),e.ifnonematch&&(i.stringParameterCheck(e.ifnonematch,"DynamicsWebApi."+t,"request.ifnonematch"),c["If-None-Match"]=e.ifnonematch),e.impersonate&&(i.stringParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate"),c.MSCRMCallerID=i.guidParameterCheck(e.impersonate,"DynamicsWebApi."+t,"request.impersonate")),e.token&&(i.stringParameterCheck(e.token,"DynamicsWebApi."+t,"request.token"),c.Authorization="Bearer "+e.token),e.expand&&e.expand.length)if(i.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)u.push("$expand="+encodeURI(e.expand));else{for(var p=[],m=0;m<e.expand.length;m++)if(e.expand[m].property){var h=n(e.expand[m],t+" $expand",null,";"),d=h.query;d&&d.length&&(d="("+d+")"),p.push(e.expand[m].property+d)}p.length&&u.push("$expand="+encodeURI(p.join(",")))}}return{url:r,query:u.join(a),headers:c}}function a(e,t,r){e.collection?i.stringParameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection"):i.parameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection");var a=e.collection.toLowerCase();e.id&&(e.id=i.guidParameterCheck(e.id,"DynamicsWebApi."+t,"request.id"),a+="("+e.id+")");var o=n(e,t,a,"&",r);return o.query&&(o.url+="?"+encodeURI(o.query)),{url:o.url,headers:o.headers}}var i=(r(0),r(1)),o=r(10),s={convertRequestOptions:n,convertRequest:a};e.exports=s},function(e,t,r){var n={buildFunctionParameters:r(9),getFetchXmlPagingCookie:r(12),convertToReferenceObject:r(11)};e.exports=n},function(e,t){e.exports=function(e,t){return"string"==typeof t&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.exec(t)?new Date(t):t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var r=e.split("\r\n"),n=0,a=r.length;n<a;n++){var i=r[n],o=i.indexOf(": ");o>0&&(t[i.substring(0,o)]=i.substring(o+2))}return t}},function(e,t,r){var n=r(6),a=r(7),i=function(e,t,r,i,o,s){var c=new XMLHttpRequest;if(c.open(e,t,!0),c.setRequestHeader("OData-MaxVersion","4.0"),c.setRequestHeader("OData-Version","4.0"),c.setRequestHeader("Accept","application/json"),c.setRequestHeader("Content-Type","application/json; charset=utf-8"),null!=i)for(var u in i)c.setRequestHeader(u,i[u]);c.onreadystatechange=function(){if(4===c.readyState){switch(c.status){case 200:case 201:case 204:case 304:var e=null;c.responseText&&(e=JSON.parse(c.responseText,n));o({data:e,headers:a(c.getAllResponseHeaders()),status:c.status});break;default:var t;try{t=JSON.parse(c.response).error}catch(e){t=c.response.length>0?{message:c.response}:{message:"Unexpected Error"}}t.status=c.status,s(t)}c=null}},c.onerror=function(){s({message:"Network Error"}),c=null},c.ontimeout=function(e){s({message:"Request Timed Out"}),c=null},r?c.send(r):c.send()};e.exports=i},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),r="",n="",a=1;a<=t.length;a++){var i=t[a-1],o=e[i];a>1&&(r+=",",n+="&"),r+=i+"=@p"+a,n+="@p"+a+"="+("string"==typeof o?"'"+o+"'":o)}return"("+r+")?"+n}return"()"}},function(e,t,r){var n=r(0),a=r(1);e.exports=function(e,t,r){var i=e.returnRepresentation,o=e.includeAnnotations,s=e.maxPageSize;if(e.prefer&&e.prefer.length){a.stringOrArrayParameterCheck(e.prefer,"DynamicsWebApi."+t,"request.prefer");var c=e.prefer;"string"==typeof c&&(c=c.split(","));for(var u in c){var l=c[u].trim();l===n.Prefer.ReturnRepresentation?i=!0:l.startsWith("odata.include-annotations=")?o=l.replace("odata.include-annotations=","").replace(/"/g,""):l.startsWith("odata.maxpagesize=")&&(s=l.replace("odata.maxpagesize=","").replace(/"/g,""))}}r&&(null==i&&(i=r.returnRepresentation),o=o?o:r.includeAnnotations,s=s?s:r.maxPageSize);var c=[];return i&&(a.boolParameterCheck(i,"DynamicsWebApi."+t,"request.returnRepresentation"),c.push(n.Prefer.ReturnRepresentation)),o&&(a.stringParameterCheck(o,"DynamicsWebApi."+t,"request.includeAnnotations"),c.push('odata.include-annotations="'+o+'"')),s&&s>0&&(a.numberParameterCheck(s,"DynamicsWebApi."+t,"request.maxPageSize"),c.push("odata.maxpagesize="+s)),c.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?e:"",t=t?t:1,e=unescape(unescape(e));var r=/pagingcookie="(<cookie page="(\d+)".+<\/cookie>)/.exec(e);if(null!=r){var n=parseInt(r[2]);return{cookie:r[1].replace(/</g,"<").replace(/>/g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:n,nextPage:n+1}}return{cookie:"",page:t,nextPage:t+1}}},function(e,t,r){function n(e){var t={webApiVersion:"8.0",webApiUrl:null,impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t);var r=function(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm)return Xrm.Page.context;throw new Error("Xrm Context is not available.")},c=function(){var e=r();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""},u=function(){return c()+"/api/data/v"+t.webApiVersion+"/"};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=u(),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)},this.setConfig(e);var l=function(e,r,n,a){return new Promise(function(i,o){s(e,r,t,n,a,i,o)})};this.create=function(e,r,n,a){o.parameterCheck(e,"DynamicsWebApi.create","object"),o.stringParameterCheck(r,"DynamicsWebApi.create","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.create","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.create","select");var s={collection:r,select:a,prefer:n},c=i.convertRequest(s,"create",t);return l("POST",c.url,e,c.headers).then(function(e){if(e.data)return e.data;var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0]})},this.retrieveRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.retrieve","request");var r=i.convertRequest(e,"retrieve",t),n=e.select;return l("GET",r.url,null,r.headers).then(function(e){return null!=n&&1==n.length&&n[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?a.convertToReferenceObject(e.data):e.data})},this.retrieve=function(e,t,r,n){o.stringParameterCheck(e,"DynamicsWebApi.retrieve","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.retrieve","id"),o.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),r&&r.length&&o.arrayParameterCheck(r,"DynamicsWebApi.retrieve","select"),n&&n.length&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.retrieve","expand");var a={collection:t,id:e,select:r,expand:n};return this.retrieveRequest(a)},this.updateRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.update","request"),o.parameterCheck(e.entity,"DynamicsWebApi.update","request.entity"),null==e.ifmatch&&(e.ifmatch="*");var r=i.convertRequest(e,"update",t),n=e.ifmatch;return l("PATCH",r.url,e.entity,r.headers).then(function(e){return!e.data||e.data}).catch(function(e){if(n&&412==e.status)return!1;throw e})},this.update=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.update","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.update","id"),o.parameterCheck(r,"DynamicsWebApi.update","object"),o.stringParameterCheck(t,"DynamicsWebApi.update","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.update","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.update","select");var i={collection:t,id:e,select:a,prefer:n,entity:r};return this.updateRequest(i)},this.updateSingleProperty=function(e,r,n,a,s){o.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),o.parameterCheck(n,"DynamicsWebApi.updateSingleProperty","keyValuePair"),o.stringParameterCheck(r,"DynamicsWebApi.updateSingleProperty","collection");var c=Object.keys(n)[0],u=n[c];a&&o.stringOrArrayParameterCheck(a,"DynamicsWebApi.updateSingleProperty","prefer"),s&&o.arrayParameterCheck(s,"DynamicsWebApi.updateSingleProperty","select");var p={collection:r,id:e,select:s,prefer:a,navigationProperty:c},m=i.convertRequest(p,"updateSingleProperty",t);return l("PUT",m.url,{value:u},m.headers).then(function(e){if(e.data)return e.data})},this.deleteRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.delete","request");var r=i.convertRequest(e,"deleteRequest",t),n=e.ifmatch;return l("DELETE",r.url,null,r.headers).then(function(){return!0}).catch(function(e){if(n&&412==e.status)return!1;throw e})},this.deleteRecord=function(e,t,r){o.stringParameterCheck(e,"DynamicsWebApi.deleteRecord","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.deleteRecord","id"),o.stringParameterCheck(t,"DynamicsWebApi.deleteRecord","collection"),null!=r&&o.stringParameterCheck(r,"DynamicsWebApi.deleteRecord","propertyName");var n=t.toLowerCase()+"("+e+")";return null!=r&&(n+="/"+r),l("DELETE",n).then(function(){})},this.upsertRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.upsert","request"),o.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity");var r=i.convertRequest(e,"upsert",t),n=e.ifnonematch,a=e.ifmatch;return l("PATCH",r.url,e.entity,r.headers).then(function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0]}if(e.data)return e.data}).catch(function(e){if(!(n&&412==e.status||a&&404==e.status))throw e})},this.upsert=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.upsert","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.upsert","id"),o.parameterCheck(r,"DynamicsWebApi.upsert","object"),o.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.upsert","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.upsert","select");var i={collection:t,id:e,select:a,prefer:n,entity:r};return this.upsertRequest(i)};var p=function(e,r){r&&!e.collection&&(e.collection="any");var n=i.convertRequest(e,"retrieveMultiple",t);r&&(o.stringParameterCheck(r,"DynamicsWebApi.retrieveMultiple","nextPageLink"),n.url=r.replace(t.webApiUrl,""));var a=e.count;return l("GET",n.url,null,n.headers).then(function(e){return null!=e.data["@odata.nextLink"]&&(e.data.oDataNextLink=e.data["@odata.nextLink"]),a&&(e.data.oDataCount=null!=e.data["@odata.count"]?parseInt(e.data["@odata.count"]):0),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),e.data})};this.retrieveMultipleRequest=p;var m=function(e,t,r){var r=r||[];return p(e,t).then(function(t){return r=r.concat(t.value),t.oDataNextLink?m(e,t.oDataNextLink,r):{value:r}})};this.retrieveAllRequest=function(e){return m(e)},this.count=function(e,t){return null==t||null!=t&&!t.length?(o.stringParameterCheck(e,"DynamicsWebApi.count","collection"),l("GET",e.toLowerCase()+"/$count").then(function(e){return e.data?parseInt(e.data):0})):this.retrieveMultipleRequest({collection:e,filter:t,count:!0},null).then(function(e){return e.oDataCount?e.oDataCount:0})},this.countAll=function(e,t,r){return this.retrieveAllRequest({collection:e,filter:t,select:r}).then(function(e){return e&&e.value?e.value.length:0})},this.retrieveMultiple=function(e,t,r,n){return this.retrieveMultipleRequest({collection:e,select:t,filter:r},n)},this.executeFetchXml=function(e,r,n,s,c,u){o.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","type"),o.stringParameterCheck(r,"DynamicsWebApi.executeFetchXml","fetchXml"),null==s&&(s=1),o.numberParameterCheck(s,"DynamicsWebApi.executeFetchXml","pageNumber");var p='$1 page="'+s+'"';null!=c&&(o.stringParameterCheck(c,"DynamicsWebApi.executeFetchXml","pagingCookie"),p+=' paging-cookie="'+c+'"'),r=r.replace(/^(<fetch[\w\d\s'"=]+)/,p),n&&o.stringParameterCheck(n,"DynamicsWebApi.executeFetchXml","includeAnnotations"),u&&(u=o.guidParameterCheck(u,"DynamicsWebApi.executeFetchXml","impersonateUserId"));var m={collection:e,includeAnnotations:n,impersonate:u},h=i.convertRequest(m,"executeFetchXml",t),d=encodeURIComponent(r);return l("GET",h.url+"?fetchXml="+d,null,h.headers).then(function(e){return null!=e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"]&&(e.data.PagingInfo=a.getFetchXmlPagingCookie(e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"],s)),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),e.data})},this.associate=function(e,r,n,a,i,s){o.stringParameterCheck(e,"DynamicsWebApi.associate","primarycollection"),o.stringParameterCheck(a,"DynamicsWebApi.associate","relatedcollection"),o.stringParameterCheck(n,"DynamicsWebApi.associate","relationshipName"),r=o.guidParameterCheck(r,"DynamicsWebApi.associate","primaryId"),i=o.guidParameterCheck(i,"DynamicsWebApi.associate","relatedId");var c={};return null!=s&&(s=o.guidParameterCheck(s,"DynamicsWebApi.associate","impersonateUserId"),c.MSCRMCallerID=s),l("POST",e+"("+r+")/"+n+"/$ref",{"@odata.id":t.webApiUrl+a+"("+i+")"},c).then(function(){})},this.disassociate=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.disassociate","primarycollection"),o.stringParameterCheck(r,"DynamicsWebApi.disassociate","relationshipName"),t=o.guidParameterCheck(t,"DynamicsWebApi.disassociate","primaryId"),n=o.guidParameterCheck(n,"DynamicsWebApi.disassociate","relatedId");var i={};return null!=a&&(a=o.guidParameterCheck(a,"DynamicsWebApi.associate","impersonateUserId"),i.MSCRMCallerID=a),l("DELETE",e+"("+t+")/"+r+"("+n+")/$ref",null,i).then(function(){})},this.associateSingleValued=function(e,r,n,a,i,s){o.stringParameterCheck(e,"DynamicsWebApi.associateSingleValued","collection"),r=o.guidParameterCheck(r,"DynamicsWebApi.associateSingleValued","id"),i=o.guidParameterCheck(i,"DynamicsWebApi.associateSingleValued","relatedId"),o.stringParameterCheck(n,"DynamicsWebApi.associateSingleValued","singleValuedNavigationPropertyName"),o.stringParameterCheck(a,"DynamicsWebApi.associateSingleValued","relatedcollection");var c={};return null!=s&&(s=o.guidParameterCheck(s,"DynamicsWebApi.associate","impersonateUserId"),c.MSCRMCallerID=s),l("PUT",e+"("+r+")/"+n+"/$ref",{"@odata.id":t.webApiUrl+a+"("+i+")"},c).then(function(){})},this.disassociateSingleValued=function(e,t,r,n){o.stringParameterCheck(e,"DynamicsWebApi.disassociateSingleValued","collection"),t=o.guidParameterCheck(t,"DynamicsWebApi.disassociateSingleValued","id"),o.stringParameterCheck(r,"DynamicsWebApi.disassociateSingleValued","singleValuedNavigationPropertyName");var a={};return null!=n&&(n=o.guidParameterCheck(n,"DynamicsWebApi.associate","impersonateUserId"),a.MSCRMCallerID=n),l("DELETE",e+"("+t+")/"+r+"/$ref",null,a).then(function(){})},this.executeUnboundFunction=function(e,t,r){return h(e,t,null,null,r)},this.executeBoundFunction=function(e,t,r,n,a){return h(r,n,t,e,a)};var h=function(e,t,r,n,i){o.stringParameterCheck(e,"DynamicsWebApi.executeFunction","functionName");var s=e+a.buildFunctionParameters(t);null!=r&&(o.stringParameterCheck(r,"DynamicsWebApi.executeFunction","collection"),n=o.guidParameterCheck(n,"DynamicsWebApi.executeFunction","id"),s=r+"("+n+")/"+s);var c={};return null!=i&&(c.MSCRMCallerID=o.guidParameterCheck(i,"DynamicsWebApi.associate","impersonateUserId")),l("GET",s,null,c).then(function(e){if(e.data)return e.data})};this.executeUnboundAction=function(e,t,r){return d(e,t,null,null,r)},this.executeBoundAction=function(e,t,r,n,a){return d(r,n,t,e,a)};var d=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.executeAction","actionName");var i=e;null!=r&&(o.stringParameterCheck(r,"DynamicsWebApi.executeAction","collection"),n=o.guidParameterCheck(n,"DynamicsWebApi.executeAction","id"),i=r+"("+n+")/"+i);var s={};return null!=a&&(a=o.guidParameterCheck(a,"DynamicsWebApi.executeAction","impersonateUserId"),s.MSCRMCallerID=a),l("POST",i,t,s).then(function(e){if(e.data)return e.data})};this.initializeInstance=function(e){return e||(e=t),new n(e)}}var a=(r(0),r(5)),i=r(4),o=r(1),s=r(3);String.prototype.endsWith&&String.prototype.startsWith||r(2),e.exports=n}])}); | ||
/*! dynamics-web-api v1.2.5 (c) 2017 Aleksandr Rogov */ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DynamicsWebApi=t():e.DynamicsWebApi=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var a=r[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,t),a.l=!0,a.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=13)}([function(e,t){var r={Types:{ResponseBase:function(){this.oDataContext=""},Response:function(){r.Types.ResponseBase.call(this),this.value={}},ReferenceResponse:function(){r.Types.ResponseBase.call(this),this.id="",this.collection=""},MultipleResponse:function(){r.Types.ResponseBase.call(this),this.oDataNextLink="",this.oDataCount=0,this.value=[]},FetchXmlResponse:function(){r.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=r},function(e,t){function r(e,t,r){throw new Error(r?e+" requires the "+t+" parameter to be of type "+r:e+" requires the "+t+" parameter.")}var n={handleErrorResponse:function(e){throw new Error("Error: "+e.status+": "+e.message)},parameterCheck:function(e,t,n,a){void 0!==e&&null!==e&&""!=e||r(t,n,a)},stringParameterCheck:function(e,t,n){"string"!=typeof e&&r(t,n,"String")},arrayParameterCheck:function(e,t,n){e.constructor!==Array&&r(t,n,"Array")},stringOrArrayParameterCheck:function(e,t,n){e.constructor!==Array&&"string"!=typeof e&&r(t,n,"String or Array")},numberParameterCheck:function(e,t,n){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;r(t,n,"Number")}},boolParameterCheck:function(e,t,n){"boolean"!=typeof e&&r(t,n,"Boolean")},guidParameterCheck:function(e,t,n){try{return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(e)[0]}catch(e){r(t,n,"GUID String")}},callbackParameterCheck:function(e,t,n){"function"!=typeof e&&r(t,n,"Function")}};e.exports=n},function(e,t){String.prototype.endsWith=function(e,t){var r=this.toString();("number"!=typeof t||!isFinite(t)||Math.floor(t)!==t||t>r.length)&&(t=r.length),t-=e.length;var n=r.lastIndexOf(e,t);return n!==-1&&n===t},String.prototype.startsWith=function(e,t){return t=t||0,this.substr(t,e.length)===e}},function(e,t,r){r(0);e.exports=function(e,t,n,a,i,o,c){n.impersonate&&(!i||i&&!i.MSCRMCallerID)&&(i||(i={}),i.MSCRMCallerID=n.impersonate);var s;a&&(s=JSON.stringify(a,function(e,t){return e.endsWith("@odata.bind")&&"string"==typeof t&&!t.startsWith(n.webApiUrl)&&(t=n.webApiUrl+t),t}));var u;"undefined"!=typeof XMLHttpRequest&&(u=r(8));var l=function(r){r&&(i||(i={}),i.Authorization="Bearer "+r.accessToken),u(e,n.webApiUrl+t,s,i,o,c)};n.onTokenRefresh&&(!i||i&&!i.Authorization)?n.onTokenRefresh(l):l()}},function(e,t,r){function n(e,t,r,a,c){var s={},u=[];if(a=null!=a?a:"&",e){e.navigationProperty&&(i.stringParameterCheck(e.navigationProperty,"DynamicsWebApi."+t,"request.navigationProperty"),r+="/"+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")?r+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==t&&(null==e.navigationProperty?r+=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.expand&&e.expand.length)if(i.stringOrArrayParameterCheck(e.expand,"DynamicsWebApi."+t,"request.expand"),"string"==typeof e.expand)u.push("$expand="+encodeURI(e.expand));else{for(var p=[],m=0;m<e.expand.length;m++)if(e.expand[m].property){var h=n(e.expand[m],t+" $expand",null,";"),d=h.query;d&&d.length&&(d="("+d+")"),p.push(e.expand[m].property+d)}p.length&&u.push("$expand="+encodeURI(p.join(",")))}}return{url:r,query:u.join(a),headers:s}}function a(e,t,r){e.collection?i.stringParameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection"):i.parameterCheck(e.collection,"DynamicsWebApi."+t,"request.collection");var a=e.collection.toLowerCase();e.id&&(e.id=i.guidParameterCheck(e.id,"DynamicsWebApi."+t,"request.id"),a+="("+e.id+")");var o=n(e,t,a,"&",r);return o.query&&(o.url+="?"+encodeURI(o.query)),{url:o.url,headers:o.headers}}var i=(r(0),r(1)),o=r(10),c={convertRequestOptions:n,convertRequest:a};e.exports=c},function(e,t,r){var n={buildFunctionParameters:r(9),getFetchXmlPagingCookie:r(12),convertToReferenceObject:r(11)};e.exports=n},function(e,t){e.exports=function(e,t){return"string"==typeof t&&/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/.exec(t)?new Date(t):t}},function(e,t){e.exports=function(e){var t={};if(!e)return t;for(var r=e.split("\r\n"),n=0,a=r.length;n<a;n++){var i=r[n],o=i.indexOf(": ");o>0&&(t[i.substring(0,o)]=i.substring(o+2))}return t}},function(e,t,r){var n=r(6),a=r(7),i=function(e,t,r,i,o,c){var s=new XMLHttpRequest;if(s.open(e,t,!0),s.setRequestHeader("OData-MaxVersion","4.0"),s.setRequestHeader("OData-Version","4.0"),s.setRequestHeader("Accept","application/json"),s.setRequestHeader("Content-Type","application/json; charset=utf-8"),null!=i)for(var u in i)s.setRequestHeader(u,i[u]);s.onreadystatechange=function(){if(4===s.readyState){switch(s.status){case 200:case 201:case 204:case 304:var e=null;s.responseText&&(e=JSON.parse(s.responseText,n));o({data:e,headers:a(s.getAllResponseHeaders()),status:s.status});break;default:var t;try{t=JSON.parse(s.response).error}catch(e){t=s.response.length>0?{message:s.response}:{message:"Unexpected Error"}}t.status=s.status,c(t)}s=null}},s.onerror=function(){c({message:"Network Error"}),s=null},s.ontimeout=function(e){c({message:"Request Timed Out"}),s=null},r?s.send(r):s.send()};e.exports=i},function(e,t){e.exports=function(e){if(e){for(var t=Object.keys(e),r="",n="",a=1;a<=t.length;a++){var i=t[a-1],o=e[i];a>1&&(r+=",",n+="&"),r+=i+"=@p"+a,n+="@p"+a+"="+("string"==typeof o?"'"+o+"'":o)}return"("+r+")?"+n}return"()"}},function(e,t,r){var n=r(0),a=r(1);e.exports=function(e,t,r){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===n.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,""))}}r&&(null==i&&(i=r.returnRepresentation),o=o?o:r.includeAnnotations,c=c?c:r.maxPageSize);var s=[];return i&&(a.boolParameterCheck(i,"DynamicsWebApi."+t,"request.returnRepresentation"),s.push(n.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?e:"",t=t?t:1,e=unescape(unescape(e));var r=/pagingcookie="(<cookie page="(\d+)".+<\/cookie>)/.exec(e);if(null!=r){var n=parseInt(r[2]);return{cookie:r[1].replace(/</g,"<").replace(/>/g,">").replace(/\"/g,"'").replace(/\'/g,"""),page:n,nextPage:n+1}}return{cookie:"",page:t,nextPage:t+1}}},function(e,t,r){function n(e){var t={webApiVersion:"8.0",webApiUrl:null,impersonate:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null};e||(e=t);var r=function(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm)return Xrm.Page.context;throw new Error("Xrm Context is not available.")},s=function(){var e=r();if(e){var t=e.getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}return""},u=function(){return s()+"/api/data/v"+t.webApiVersion+"/"};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=u(),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)},this.setConfig(e);var l=function(e,r,n,a){return new Promise(function(i,o){c(e,r,t,n,a,i,o)})};this.create=function(e,r,n,a){o.parameterCheck(e,"DynamicsWebApi.create","object"),o.stringParameterCheck(r,"DynamicsWebApi.create","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.create","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.create","select");var c={collection:r,select:a,prefer:n},s=i.convertRequest(c,"create",t);return l("POST",s.url,e,s.headers).then(function(e){if(e.data)return e.data;var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0]})},this.retrieveRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.retrieve","request");var r=i.convertRequest(e,"retrieve",t),n=e.select;return l("GET",r.url,null,r.headers).then(function(e){return null!=n&&1==n.length&&n[0].endsWith("/$ref")&&null!=e.data["@odata.id"]?a.convertToReferenceObject(e.data):e.data})},this.retrieve=function(e,t,r,n){o.stringParameterCheck(e,"DynamicsWebApi.retrieve","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.retrieve","id"),o.stringParameterCheck(t,"DynamicsWebApi.retrieve","collection"),r&&r.length&&o.arrayParameterCheck(r,"DynamicsWebApi.retrieve","select"),n&&n.length&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.retrieve","expand");var a={collection:t,id:e,select:r,expand:n};return this.retrieveRequest(a)},this.updateRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.update","request"),o.parameterCheck(e.entity,"DynamicsWebApi.update","request.entity"),null==e.ifmatch&&(e.ifmatch="*");var r=i.convertRequest(e,"update",t),n=e.ifmatch;return l("PATCH",r.url,e.entity,r.headers).then(function(e){return!e.data||e.data}).catch(function(e){if(n&&412==e.status)return!1;throw e})},this.update=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.update","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.update","id"),o.parameterCheck(r,"DynamicsWebApi.update","object"),o.stringParameterCheck(t,"DynamicsWebApi.update","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.update","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.update","select");var i={collection:t,id:e,select:a,prefer:n,entity:r};return this.updateRequest(i)},this.updateSingleProperty=function(e,r,n,a,c){o.stringParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.updateSingleProperty","id"),o.parameterCheck(n,"DynamicsWebApi.updateSingleProperty","keyValuePair"),o.stringParameterCheck(r,"DynamicsWebApi.updateSingleProperty","collection");var s=Object.keys(n)[0],u=n[s];a&&o.stringOrArrayParameterCheck(a,"DynamicsWebApi.updateSingleProperty","prefer"),c&&o.arrayParameterCheck(c,"DynamicsWebApi.updateSingleProperty","select");var p={collection:r,id:e,select:c,prefer:a,navigationProperty:s},m=i.convertRequest(p,"updateSingleProperty",t);return l("PUT",m.url,{value:u},m.headers).then(function(e){if(e.data)return e.data})},this.deleteRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.delete","request");var r=i.convertRequest(e,"deleteRequest",t),n=e.ifmatch;return l("DELETE",r.url,null,r.headers).then(function(){return!0}).catch(function(e){if(n&&412==e.status)return!1;throw e})},this.deleteRecord=function(e,t,r){o.stringParameterCheck(e,"DynamicsWebApi.deleteRecord","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.deleteRecord","id"),o.stringParameterCheck(t,"DynamicsWebApi.deleteRecord","collection"),null!=r&&o.stringParameterCheck(r,"DynamicsWebApi.deleteRecord","propertyName");var n=t.toLowerCase()+"("+e+")";return null!=r&&(n+="/"+r),l("DELETE",n).then(function(){})},this.upsertRequest=function(e){o.parameterCheck(e,"DynamicsWebApi.upsert","request"),o.parameterCheck(e.entity,"DynamicsWebApi.upsert","request.entity");var r=i.convertRequest(e,"upsert",t),n=e.ifnonematch,a=e.ifmatch;return l("PATCH",r.url,e.entity,r.headers).then(function(e){if(e.headers["OData-EntityId"]||e.headers["odata-entityid"]){var t=e.headers["OData-EntityId"]?e.headers["OData-EntityId"]:e.headers["odata-entityid"];return/[0-9A-F]{8}[-]?([0-9A-F]{4}[-]?){3}[0-9A-F]{12}/i.exec(t)[0]}if(e.data)return e.data}).catch(function(e){if(!(n&&412==e.status||a&&404==e.status))throw e})},this.upsert=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.upsert","id"),e=o.guidParameterCheck(e,"DynamicsWebApi.upsert","id"),o.parameterCheck(r,"DynamicsWebApi.upsert","object"),o.stringParameterCheck(t,"DynamicsWebApi.upsert","collection"),n&&o.stringOrArrayParameterCheck(n,"DynamicsWebApi.upsert","prefer"),a&&o.arrayParameterCheck(a,"DynamicsWebApi.upsert","select");var i={collection:t,id:e,select:a,prefer:n,entity:r};return this.upsertRequest(i)};var p=function(e,r){r&&!e.collection&&(e.collection="any");var n=i.convertRequest(e,"retrieveMultiple",t);r&&(o.stringParameterCheck(r,"DynamicsWebApi.retrieveMultiple","nextPageLink"),n.url=r.replace(t.webApiUrl,""));var a=e.count;return l("GET",n.url,null,n.headers).then(function(e){return null!=e.data["@odata.nextLink"]&&(e.data.oDataNextLink=e.data["@odata.nextLink"]),a&&(e.data.oDataCount=null!=e.data["@odata.count"]?parseInt(e.data["@odata.count"]):0),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),e.data})};this.retrieveMultipleRequest=p;var m=function(e,t,r){var r=r||[];return p(e,t).then(function(t){return r=r.concat(t.value),t.oDataNextLink?m(e,t.oDataNextLink,r):{value:r}})};this.retrieveAllRequest=function(e){return m(e)},this.count=function(e,t){return null==t||null!=t&&!t.length?(o.stringParameterCheck(e,"DynamicsWebApi.count","collection"),l("GET",e.toLowerCase()+"/$count").then(function(e){return e.data?parseInt(e.data):0})):this.retrieveMultipleRequest({collection:e,filter:t,count:!0},null).then(function(e){return e.oDataCount?e.oDataCount:0})},this.countAll=function(e,t,r){return m({collection:e,filter:t,select:r}).then(function(e){return e&&e.value?e.value.length:0})},this.retrieveMultiple=function(e,t,r,n){return this.retrieveMultipleRequest({collection:e,select:t,filter:r},n)},this.retrieveAll=function(e,t,r){return m({collection:e,select:t,filter:r})};var h=function(e,r,n,c,s,u){o.stringParameterCheck(e,"DynamicsWebApi.executeFetchXml","type"),o.stringParameterCheck(r,"DynamicsWebApi.executeFetchXml","fetchXml"),c=c||1,o.numberParameterCheck(c,"DynamicsWebApi.executeFetchXml","pageNumber");var p='$1 page="'+c+'"';null!=s&&(o.stringParameterCheck(s,"DynamicsWebApi.executeFetchXml","pagingCookie"),p+=' paging-cookie="'+s+'"'),r=r.replace(/^(<fetch[\w\d\s'"=]+)/,p),n&&o.stringParameterCheck(n,"DynamicsWebApi.executeFetchXml","includeAnnotations"),u&&(u=o.guidParameterCheck(u,"DynamicsWebApi.executeFetchXml","impersonateUserId"));var m={collection:e,includeAnnotations:n,impersonate:u},h=i.convertRequest(m,"executeFetchXml",t),d=encodeURIComponent(r);return l("GET",h.url+"?fetchXml="+d,null,h.headers).then(function(e){return null!=e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"]&&(e.data.PagingInfo=a.getFetchXmlPagingCookie(e.data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"],c)),null!=e.data["@odata.context"]&&(e.data.oDataContext=e.data["@odata.context"]),e.data})};this.fetch=this.executeFetchXml=h;var d=function(e,t,r,n,a,i,o){var o=o||[];return h(e,t,r,n,a,i,o).then(function(n){return o=o.concat(n.value),n.PagingInfo?d(e,t,r,n.PagingInfo.nextPage,n.PagingInfo.cookie,i,o):{value:o}})};this.fetchAll=this.executeFetchXmlAll=function(e,t,r,n){return d(e,t,r,null,null,n)},this.associate=function(e,r,n,a,i,c){o.stringParameterCheck(e,"DynamicsWebApi.associate","primarycollection"),o.stringParameterCheck(a,"DynamicsWebApi.associate","relatedcollection"),o.stringParameterCheck(n,"DynamicsWebApi.associate","relationshipName"),r=o.guidParameterCheck(r,"DynamicsWebApi.associate","primaryId"),i=o.guidParameterCheck(i,"DynamicsWebApi.associate","relatedId");var s={};return null!=c&&(c=o.guidParameterCheck(c,"DynamicsWebApi.associate","impersonateUserId"),s.MSCRMCallerID=c),l("POST",e+"("+r+")/"+n+"/$ref",{"@odata.id":t.webApiUrl+a+"("+i+")"},s).then(function(){})},this.disassociate=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.disassociate","primarycollection"),o.stringParameterCheck(r,"DynamicsWebApi.disassociate","relationshipName"),t=o.guidParameterCheck(t,"DynamicsWebApi.disassociate","primaryId"),n=o.guidParameterCheck(n,"DynamicsWebApi.disassociate","relatedId");var i={};return null!=a&&(a=o.guidParameterCheck(a,"DynamicsWebApi.associate","impersonateUserId"),i.MSCRMCallerID=a),l("DELETE",e+"("+t+")/"+r+"("+n+")/$ref",null,i).then(function(){})},this.associateSingleValued=function(e,r,n,a,i,c){o.stringParameterCheck(e,"DynamicsWebApi.associateSingleValued","collection"),r=o.guidParameterCheck(r,"DynamicsWebApi.associateSingleValued","id"),i=o.guidParameterCheck(i,"DynamicsWebApi.associateSingleValued","relatedId"),o.stringParameterCheck(n,"DynamicsWebApi.associateSingleValued","singleValuedNavigationPropertyName"),o.stringParameterCheck(a,"DynamicsWebApi.associateSingleValued","relatedcollection");var s={};return null!=c&&(c=o.guidParameterCheck(c,"DynamicsWebApi.associate","impersonateUserId"),s.MSCRMCallerID=c),l("PUT",e+"("+r+")/"+n+"/$ref",{"@odata.id":t.webApiUrl+a+"("+i+")"},s).then(function(){})},this.disassociateSingleValued=function(e,t,r,n){o.stringParameterCheck(e,"DynamicsWebApi.disassociateSingleValued","collection"),t=o.guidParameterCheck(t,"DynamicsWebApi.disassociateSingleValued","id"),o.stringParameterCheck(r,"DynamicsWebApi.disassociateSingleValued","singleValuedNavigationPropertyName");var a={};return null!=n&&(n=o.guidParameterCheck(n,"DynamicsWebApi.associate","impersonateUserId"),a.MSCRMCallerID=n),l("DELETE",e+"("+t+")/"+r+"/$ref",null,a).then(function(){})},this.executeUnboundFunction=function(e,t,r){return f(e,t,null,null,r)},this.executeBoundFunction=function(e,t,r,n,a){return f(r,n,t,e,a)};var f=function(e,t,r,n,i){o.stringParameterCheck(e,"DynamicsWebApi.executeFunction","functionName");var c=e+a.buildFunctionParameters(t);null!=r&&(o.stringParameterCheck(r,"DynamicsWebApi.executeFunction","collection"),n=o.guidParameterCheck(n,"DynamicsWebApi.executeFunction","id"),c=r+"("+n+")/"+c);var s={};return null!=i&&(s.MSCRMCallerID=o.guidParameterCheck(i,"DynamicsWebApi.associate","impersonateUserId")),l("GET",c,null,s).then(function(e){if(e.data)return e.data})};this.executeUnboundAction=function(e,t,r){return g(e,t,null,null,r)},this.executeBoundAction=function(e,t,r,n,a){return g(r,n,t,e,a)};var g=function(e,t,r,n,a){o.stringParameterCheck(e,"DynamicsWebApi.executeAction","actionName");var i=e;null!=r&&(o.stringParameterCheck(r,"DynamicsWebApi.executeAction","collection"),n=o.guidParameterCheck(n,"DynamicsWebApi.executeAction","id"),i=r+"("+n+")/"+i);var c={};return null!=a&&(a=o.guidParameterCheck(a,"DynamicsWebApi.executeAction","impersonateUserId"),c.MSCRMCallerID=a),l("POST",i,t,c).then(function(e){if(e.data)return e.data})};this.initializeInstance=function(e){return e||(e=t),new n(e)}}var a=(r(0),r(5)),i=r(4),o=r(1),c=r(3);String.prototype.endsWith&&String.prototype.startsWith||r(2),e.exports=n}])}); |
@@ -656,2 +656,19 @@ var DWA = require("./dwa"); | ||
/** | ||
* Sends an asynchronous request to retrieve all records. | ||
* | ||
* @param {string} collection - The Name of the Entity Collection. | ||
* @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. | ||
* @param {string} [filter] - Use the $filter system query option to set criteria for which entities will be returned. | ||
*/ | ||
this.retrieveAll = function (collection, successCallback, errorCallback, select, filter) { | ||
return _retrieveAllRequest({ | ||
collection: collection, | ||
select: select, | ||
filter: filter | ||
}, successCallback, errorCallback); | ||
} | ||
/** | ||
* Sends an asynchronous request to retrieve records. | ||
@@ -745,3 +762,3 @@ * | ||
*/ | ||
this.executeFetchXml = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) { | ||
var executeFetchXml = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) { | ||
@@ -801,3 +818,36 @@ ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.executeFetchXml", "collection"); | ||
this.fetch = this.executeFetchXml = executeFetchXml; | ||
var _executeFetchXmlAll = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records) { | ||
var records = records || []; | ||
var internalSuccessCallback = function (response) { | ||
records = records.concat(response.value); | ||
if (response.PagingInfo) { | ||
_executeFetchXmlAll(collection, fetchXml, successCallback, errorCallback, includeAnnotations, response.PagingInfo.nextPage, response.PagingInfo.cookie, impersonateUserId, records); | ||
} | ||
else { | ||
successCallback({ value: records }); | ||
} | ||
}; | ||
executeFetchXml(collection, fetchXml, internalSuccessCallback, errorCallback, includeAnnotations, pageNumber, pagingCookie, impersonateUserId); | ||
} | ||
/** | ||
* 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} 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. | ||
* @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. | ||
*/ | ||
this.fetchAll = this.executeFetchXmlAll = function (collection, fetchXml, successCallback, errorCallback, includeAnnotations, impersonateUserId) { | ||
return _executeFetchXmlAll(collection, fetchXml, successCallback, errorCallback, includeAnnotations, null, null, impersonateUserId); | ||
} | ||
/** | ||
* Associate for a collection-valued navigation property. (1:N or N:N) | ||
@@ -804,0 +854,0 @@ * |
@@ -633,3 +633,3 @@ var DWA = require("./dwa"); | ||
this.countAll = function (collection, filter, select) { | ||
return this.retrieveAllRequest({ | ||
return _retrieveAllRequest({ | ||
collection: collection, | ||
@@ -664,4 +664,20 @@ filter: filter, | ||
/** | ||
* Sends an asynchronous request to count records. Returns: DWA.Types.FetchXmlResponse | ||
* Sends an asynchronous request to retrieve all records. | ||
* | ||
* @param {string} collection - The Name of the Entity Collection. | ||
* @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} | ||
*/ | ||
this.retrieveAll = function (collection, select, filter) { | ||
return _retrieveAllRequest({ | ||
collection: collection, | ||
select: select, | ||
filter: filter | ||
}); | ||
} | ||
/** | ||
* 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. | ||
@@ -675,3 +691,3 @@ * @param {string} fetchXml - FetchXML is a proprietary query language that provides capabilities to perform aggregation. | ||
*/ | ||
this.executeFetchXml = function (collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) { | ||
var executeFetchXml = function (collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId) { | ||
@@ -681,5 +697,3 @@ ErrorHelper.stringParameterCheck(collection, "DynamicsWebApi.executeFetchXml", "type"); | ||
if (pageNumber == null) { | ||
pageNumber = 1; | ||
} | ||
pageNumber = pageNumber || 1; | ||
@@ -731,2 +745,42 @@ ErrorHelper.numberParameterCheck(pageNumber, "DynamicsWebApi.executeFetchXml", "pageNumber"); | ||
/** | ||
* 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} 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. | ||
* @param {string} [pagingCookie] - Paging cookie. For retrieving the first page, pagingCookie should be null. | ||
* @param {string} [impersonateUserId] - A String representing the GUID value for the Dynamics 365 system user id. Impersonates the user. | ||
* @returns {Promise} | ||
*/ | ||
this.fetch = this.executeFetchXml = executeFetchXml; | ||
var _executeFetchXmlAll = function (collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records) { | ||
var records = records || []; | ||
return executeFetchXml(collection, fetchXml, includeAnnotations, pageNumber, pagingCookie, impersonateUserId, records).then(function (response) { | ||
records = records.concat(response.value); | ||
if (response.PagingInfo) { | ||
return _executeFetchXmlAll(collection, fetchXml, includeAnnotations, response.PagingInfo.nextPage, response.PagingInfo.cookie, impersonateUserId, records); | ||
} | ||
return { value: records }; | ||
}); | ||
} | ||
/** | ||
* 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} 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. | ||
* @returns {Promise} | ||
*/ | ||
this.fetchAll = this.executeFetchXmlAll = function (collection, fetchXml, includeAnnotations, impersonateUserId) { | ||
return _executeFetchXmlAll(collection, fetchXml, includeAnnotations, null, null, impersonateUserId); | ||
} | ||
/** | ||
* Associate for a collection-valued navigation property. (1:N or N:N) | ||
@@ -733,0 +787,0 @@ * |
{ | ||
"name": "dynamics-web-api", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "DynamicsWebApi is a Microsoft Dynamics CRM Web API helper library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -37,2 +37,3 @@ # DynamicsWebApi for Microsoft Dynamics CRM Web API | ||
* [Fetch XML Request](#fetch-xml-request) | ||
* [Fetch All records](#fetch-all-records) | ||
* [Execute Web API functions](#execute-web-api-functions) | ||
@@ -168,5 +169,5 @@ * [Execute Web API actions](#execute-web-api-actions) | ||
Basic functions are: `create`, `update`, `upsert`, `deleteRecord`, `retrieve`, `retrieveMultiple`, `count`, `countAll`, `executeFetchXml`, | ||
`associate`, `disassociate`, `associateSingleValued`, `disassociateSingleValued`, `executeBoundFunction`, `executeUnboundFunction`, | ||
`executeBoundAction`, `executeUnboundAction`. | ||
Basic functions are: `create`, `update`, `upsert`, `deleteRecord`, `retrieve`, `retrieveMultiple`, `retrieveAll`, `count`, `countAll`, | ||
`executeFetchXml`, `executeFetchXmlAll`, `associate`, `disassociate`, `associateSingleValued`, `disassociateSingleValued`, `executeBoundFunction`, | ||
`executeUnboundFunction`, `executeBoundAction`, `executeUnboundAction`. | ||
@@ -573,5 +574,19 @@ Advanced functions have a suffix `Request` added to the end of the applicable operation. | ||
Current function goes through all pages automatically. | ||
The following function retrieves records and goes through all pages automatically. | ||
```js | ||
//perform a multiple records retrieve operation | ||
dynamicsWebApi.retrieveAll("leads", ["fullname", "subject"], "statecode eq 0").then(function (response) { | ||
var records = response.value; | ||
//do something else with a records array. Access a record: response.value[0].subject; | ||
}) | ||
.catch(function (error){ | ||
//catch an error | ||
}); | ||
``` | ||
OR advanced function: | ||
```js | ||
//set the request parameters | ||
@@ -582,3 +597,3 @@ var request = { | ||
filter: "statecode eq 0", | ||
maxPageSize: 5 | ||
maxPageSize: 5 //just for an example | ||
}; | ||
@@ -721,2 +736,5 @@ | ||
Starting from version 1.2.5 DynamicsWebApi has an alias with a shorter name and same parameters: `dynamicsWebApi.fetch(...)`, | ||
that works in the same way as `executeFetchXml`. | ||
#### Paging | ||
@@ -756,2 +774,24 @@ | ||
#### Fetch All records | ||
The following function executes a FetchXml and goes through all pages automatically: | ||
```js | ||
var fetchXml = '<fetch mapping="logical">' + | ||
'<entity name="account">' + | ||
'<attribute name="accountid"/>' + | ||
'<attribute name="name"/>' + | ||
'</entity>' + | ||
'</fetch>'; | ||
dynamicsWebApi.executeFetchXmlAll("accounts", fetchXml).then(function (response) { | ||
//do something with results here; access records response.value[0].accountid | ||
}) | ||
//catch... | ||
``` | ||
Starting from version 1.2.5 DynamicsWebApi has an alias with a shorter name and same parameters: `dynamicsWebApi.fetchAll(...)`, | ||
that works in the same way as `executeFetchXmlAll`. | ||
### Execute Web API functions | ||
@@ -831,3 +871,3 @@ | ||
- [ ] overloaded functions with rich request options for all Web API operations. | ||
- [ ] get all pages requests, such as: countAll, retrieveMultipleAll, fetchXmlAll and etc. | ||
- [X] get all pages requests, such as: countAll, retrieveMultipleAll, fetchXmlAll and etc. Implemented in v.1.2.5. | ||
- [ ] "formatted" values in responses. For instance: Web API splits information about lookup fields into separate properties, the config option "formatted" will enable developers to retrieve all information about such fields in a single requests and access it through DynamicsWebApi custom response objects. | ||
@@ -834,0 +874,0 @@ - [ ] Intellisense for request objects. |
@@ -112,2 +112,9 @@ //<cookie pagenumber="2" pagingcookie="<cookie page="1"><accountid last="{EF72AE29-B3DE-E611-8102-5065F38A7BF1}" first="{475B158C-541C-E511-80D3-3863BB347BA8}" /></cookie>" istracking="False" /> | ||
}, | ||
fetchXmlResponsePage2NoCookie: { | ||
"@odata.context": "context", | ||
value: [ | ||
{ name: "name1", subject: "subject1" }, | ||
{ name: "name2", subject: "subject2" } | ||
], | ||
}, | ||
fetchXmlResponsePage1: { | ||
@@ -218,2 +225,6 @@ "@odata.context": "context", | ||
}, | ||
fetchXmlResponsePage2NoCookie: { | ||
status: 200, | ||
responseText: JSON.stringify(dataStubs.fetchXmls.fetchXmlResponsePage2NoCookie) | ||
}, | ||
fetchXmlResponsePage1: { | ||
@@ -220,0 +231,0 @@ status: 200, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
902404
13956
880