UNPKG

dynamics-web-api

Version:

DynamicsWebApi is a Microsoft Dataverse Web API helper library

13 lines 53.9 kB
/*! dynamics-web-api v2.5.0 (c) 2026 Aleksandr Rogov. License: MIT */ "use strict";var _dynamicsWebApiExports=(()=>{var Ae=Object.defineProperty;var Dn=Object.getOwnPropertyDescriptor;var In=Object.getOwnPropertyNames;var kn=Object.prototype.hasOwnProperty;var Ye=e=>{throw TypeError(e)};var b=(e,t)=>()=>(e&&(t=e(e=0)),t);var Je=(e,t)=>{for(var r in t)Ae(e,r,{get:t[r],enumerable:!0})},Sn=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of In(t))!kn.call(e,n)&&n!==r&&Ae(e,n,{get:()=>t[n],enumerable:!(o=Dn(t,n))||o.enumerable});return e};var je=e=>Sn(Ae({},"__esModule",{value:!0}),e);var Ze=(e,t,r)=>t.has(e)||Ye("Cannot "+r);var m=(e,t,r)=>(Ze(e,t,"read from private field"),r?r.call(e):t.get(e)),B=(e,t,r)=>t.has(e)?Ye("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),L=(e,t,r,o)=>(Ze(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);function et(){return window.crypto}var tt=b(()=>{"use strict"});function rt(e){return!!On.exec(e)}function V(e){let t=Mn.exec(e);return t?t[1]:null}function Z(e){if(!e)return null;let t=Un.exec(e);return t?t[1]:null}function Ee(e){return e.replace(_n,(t,r)=>r)}function nt(e){return e.split(wn).map((r,o)=>o%2===0?Ee(r):r).join("")}function ot(e){let t=$n.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}function at(e){let t=Bn.exec(e);if(!t)return null;let r=parseInt(t[2],10),o=qn(t[1]);return{page:r,sanitizedCookie:o}}function qn(e){let t={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(Fn,r=>t[r])}function ee(e){return e.startsWith("/")?e.slice(1):e}function it(e){return e.replace(Qn,t=>`\\u${("0000"+t.charCodeAt(0).toString(16)).slice(-4)}`)}function xe(e){return e.replace(Hn,"")}function mt(e){return Ln.test(e??"")?"PUT":"PATCH"}function Rt(e){return e.replace(Wn,"\\$&")}function gt(e){let t=Vn.exec(e);return t?t[1]:null}var W,On,Mn,Un,_n,$n,wn,Bn,Fn,Qn,Hn,st,be,pt,ct,lt,te,Te,Ln,ut,ft,dt,yt,Wn,Vn,h=b(()=>{"use strict";W="[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}",On=new RegExp(W,"i"),Mn=new RegExp("^{?("+W+")}?$","i"),Un=new RegExp("("+W+")\\)$","i"),_n=new RegExp(`{(${W})}`,"g"),$n=new RegExp(`\\/(\\w+)\\((${W})`,"i");wn=/(["'].*?["'])/;Bn=/pagingcookie="(<cookie page="(\d+)".+<\/cookie>)/,Fn=/[<>"']/g;Qn=/[\u007F-\uFFFF]/g;Hn=/"/g;st=/^([^()<>@,;:\\"\/[\]?={} \t]+)\s?:\s?(.*)/,be=/HTTP\/?\s*[\d.]*\s+(\d{3})\s+([\w\s]*)$/m,pt=/Content-Type: text\/plain/i,ct=/OData-EntityId.+/i,lt=/\w+$/g,te=/\r?\n/,Te=/(\w+)(\([\d\w-]+\))$/,Ln=/EntityDefinitions|RelationshipDefinitions|GlobalOptionSetDefinitions/;ut=/^<fetch.+top=/,ft=/^<fetch.+page=/,dt=/^(<fetch)/,yt=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[-+]\d{2}:\d{2})$/,Wn=/[+\-&|!(){}[\]^"~*?:\\\/]/g;Vn=/^odata\.callback;\s*url=["']?(.+?)["']?$/});function Gn(e){return e==null?"":typeof e=="string"&&!e.startsWith("Microsoft.Dynamics.CRM")&&!rt(e)?`'${e}'`:typeof e=="object"?JSON.stringify(e):e.toString()}function Xn(e){let t=Object.keys(e),r=[],o=[];return t.forEach((n,i)=>{let c=e[n];if(c==null)return;c=Gn(c);let s=i+1;r.push(`${n}=@p${s}`),o.push(`@p${s}=${V(c)||c}`)}),{key:`(${r.join(",")})`,queryParams:o}}function ht(e,t){return e.hasOwnProperty(t)||e.hasOwnProperty(t.toLowerCase())}function G(e,t){return e[t]?e[t]:e[t.toLowerCase()]}function Ct(e){return e?Xn(e):{key:"()"}}function At(e="",t=1){e=decodeURIComponent(decodeURIComponent(e));let r=at(e);return{cookie:r?.sanitizedCookie||"",page:r?.page||t,nextPage:r?.page?r.page+1:t+1}}function g(e){return typeof e>"u"||e==null}function O(){return et().randomUUID()}function Kn(){if(typeof GetGlobalContext<"u")return GetGlobalContext();if(typeof Xrm<"u"){if(!g(Xrm.Utility)&&!g(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!g(Xrm.Page)&&!g(Xrm.Page.context))return Xrm.Page.context}throw new Error("Xrm Context is not available. In most cases, it can be resolved by adding a reference to a ClientGlobalContext.js.aspx. Please refer to MSDN documentation for more details.")}function Et(){let t=Kn().getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}function re(){return!!window.shell}function zn(e){return typeof e=="object"&&!!e&&!Array.isArray(e)&&Object.prototype.toString.call(e)!=="[object Date]"}function T(e,t){let r={};for(let o in e)e.hasOwnProperty(o)&&!t?.includes(o)&&(zn(e[o])?r[o]=T(e[o]):Array.isArray(e[o])?r[o]=e[o].slice():r[o]=e[o]);return r}function l(e,t=[]){t.includes("signal")||t.push("signal");let r=T(e,t);return r.signal=e.signal,r}function xt(e,t,r,o){o=o||0;let n=o+r>t.length?t.length%r:r,i;i=new Uint8Array(n);for(let c=0;c<n;c++)i[c]=t[o+c];e.data=i,e.contentRange="bytes "+o+"-"+(o+n-1)+"/"+t.length}function bt(e){let t=new Uint8Array(e.length);for(var r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}function Tt(e,t){return`${e.config.dataApi.url}${ee(t)}`}var ve,d=b(()=>{"use strict";tt();h();ve=4194304});function D(e,t,r){throw new Error(r?`${e} requires a ${t} parameter to be of type ${r}.`:`${e} requires a ${t} parameter.`)}var a,f=b(()=>{"use strict";h();a=class e{static handleErrorResponse(t){throw new Error(`Error: ${t.status}: ${t.message}`)}static parameterCheck(t,r,o,n){(typeof t>"u"||t===null||t==="")&&D(r,o,n)}static stringParameterCheck(t,r,o){typeof t!="string"&&D(r,o,"String")}static maxLengthStringParameterCheck(t,r,o,n){if(t&&t.length>n)throw new Error(`${o} has a ${n} character limit.`)}static arrayParameterCheck(t,r,o){t.constructor!==Array&&D(r,o,"Array")}static stringOrArrayParameterCheck(t,r,o){t.constructor!==Array&&typeof t!="string"&&D(r,o,"String or Array")}static numberParameterCheck(t,r,o){if(typeof t!="number"){if(typeof t=="string"&&t&&!isNaN(parseInt(t)))return;D(r,o,"Number")}}static batchIsEmpty(){return[new Error("Payload of the batch operation is empty. Please make that you have other operations in between startBatch() and executeBatch() to successfuly build a batch payload.")]}static handleHttpError(t,r){let o=new Error;return Object.keys(t).forEach(n=>{o[n]=t[n]}),r&&Object.keys(r).forEach(n=>{o[n]=r[n]}),o}static boolParameterCheck(t,r,o){typeof t!="boolean"&&D(r,o,"Boolean")}static guidParameterCheck(t,r,o){let n=V(t);return n||D(r,o,"GUID String"),n}static keyParameterCheck(t,r,o){try{e.stringParameterCheck(t,r,o);let n=V(t);if(n)return n;let i=t.split(",");if(i.length)for(let c=0;c<i.length;c++)i[c]=i[c].trim().replace(/"/g,"'"),/^[\w\d\_]+\=(.+)$/i.exec(i[c])[0];return i.join(",")}catch{D(r,o,"String representing GUID or Alternate Key")}}static callbackParameterCheck(t,r,o){typeof t!="function"&&D(r,o,"Function")}static throwBatchIncompatible(t,r){if(r)throw r=!1,new Error(t+" cannot be used in a BATCH request.")}static throwBatchNotStarted(t){if(!t)throw new Error("Batch operation has not been started. Please call a DynamicsWebApi.startBatch() function prior to calling DynamicsWebApi.executeBatch() to perform a batch request correctly.")}}});var M,X,ne,k,Pt=b(()=>{"use strict";ne=class ne{};ne.Prefer=(X=class{static get(t){return`${ne.Prefer.IncludeAnnotations}="${t}"`}},X.ReturnRepresentation="return=representation",X.Annotations=(M=class{},M.AssociatedNavigationProperty="Microsoft.Dynamics.CRM.associatednavigationproperty",M.LookupLogicalName="Microsoft.Dynamics.CRM.lookuplogicalname",M.All="*",M.FormattedValue="OData.Community.Display.V1.FormattedValue",M.FetchXmlPagingCookie="Microsoft.Dynamics.CRM.fetchxmlpagingcookie",M),X.IncludeAnnotations="odata.include-annotations",X);k=ne});function S(e,t){if(typeof t=="string"){let r=yt.exec(t);if(r)return new Date(Date.UTC(+r[1],+r[2]-1,+r[3],+r[4],+r[5],+r[6]))}return t}var Pe=b(()=>{"use strict";h()});function to(e){let t={position:0},r={},o,n,i;do{if(i=t.position,n=ro(e,t),!n)break;o=st.exec(n),o!==null?r[o[1].toLowerCase()]=o[2]:t.position=i}while(n&&o);return r}function ro(e,t){return no(e,t,te)}function no(e,t,r){let o=t.position||0,n=e.slice(o),i=r.exec(n);if(!i)return null;let c=o+i.index;return t.position=c+i[0].length,e.substring(o,c)}function oo(e){let t=be.exec(e);return{httpStatusString:t[0],httpStatus:parseInt(t[1]),httpStatusMessage:t[2].trim()}}function ao(e){be.lastIndex=0;let t=lt.exec(e.trim());return t?.length?t[0]:void 0}function io(e,t,r){let o=ao(e);return Se(o)}function so(e,t,r){if(t?.[r]?.valueIfEmpty!==void 0)return t[r].valueIfEmpty;{let o=ct.exec(e);return Z(o?.[0])??void 0}}function po(e,t,r){let{httpStatusString:o,httpStatus:n,httpStatusMessage:i}=oo(e),c=e.substring(e.indexOf("{"),e.lastIndexOf("}")+1);if(!c)return pt.test(e)?io(e,t,r):so(e,t,r);let s=ke(c,t,r);if(n<400)return s;let E=to(e.substring(e.indexOf(o)+o.length+1,e.indexOf("{")));return a.handleHttpError(s,{status:n,statusText:i,statusMessage:i,headers:E})}function De(e,t,r=0){let o=e.substring(0,e.search(te)),n=e.split(o);n.shift(),n.pop();let i=[];for(let c of n){if(c.indexOf("--changesetresponse_")===-1){i.push(po(c,t,r++));continue}c=c.trim();let s=c.substring(c.search(te)+1).trim();i=i.concat(De(s,t,r++))}return i}var Ie=b(()=>{"use strict";f();h();oe()});function Oe(e,t){let r=null;if(e.indexOf("@")!==-1){let o=e.split("@");switch(o[1]){case"odata.context":r="oDataContext";break;case"odata.count":r="oDataCount",t=t!=null?parseInt(t):0;break;case"odata.nextLink":r="oDataNextLink";break;case"odata.deltaLink":r="oDataDeltaLink";break;case k.Prefer.Annotations.FormattedValue:r=o[0]+"_Formatted";break;case k.Prefer.Annotations.AssociatedNavigationProperty:r=o[0]+"_NavigationProperty";break;case k.Prefer.Annotations.LookupLogicalName:r=o[0]+"_LogicalName";break}}return[r,t]}function Me(e,t){if(t){if(t.isRef&&e["@odata.id"]!=null)return ot(e);if(t.toCount)return Oe("@odata.count",e["@odata.count"])[1]||0}for(let o in e){if(e[o]!=null)if(Array.isArray(e[o]))for(var r=0;r<e[o].length;r++)e[o][r]=Me(e[o][r]);else typeof e[o]=="object"&&Me(e[o]);let n=Oe(o,e[o]);if(n[0]&&(e[n[0]]=n[1]),o.indexOf("_x002e_")!==-1){let i=o.split("_x002e_");if(!e.hasOwnProperty(i[0]))e[i[0]]={_dwaType:"alias"};else if(typeof e[i[0]]!="object"||typeof e[i[0]]=="object"&&!e[i[0]].hasOwnProperty("_dwaType"))throw new Error("The alias name of the linked entity must be unique!");e[i[0]][i[1]]=e[o],n=Oe(i[1],e[o]),n[0]&&(e[i[0]][n[0]]=n[1])}}return t&&t.hasOwnProperty("pageNumber")&&e["@"+k.Prefer.Annotations.FetchXmlPagingCookie]!=null&&(e.PagingInfo=At(e["@"+k.Prefer.Annotations.FetchXmlPagingCookie],t.pageNumber)),e}function co(e){return window.atob(e)}function lo(e,t,r){let o=e;r?.hasOwnProperty("parse")&&(o=JSON.parse(o).value,o=co(o));let n={value:o};t["x-ms-file-name"]&&(n.fileName=t["x-ms-file-name"]),t["x-ms-file-size"]&&(n.fileSize=parseInt(t["x-ms-file-size"]));let i=G(t,"Location");return i&&(n.location=i),n}function mo(e){return e.indexOf("--batchresponse_")>-1}function uo(e){return ht(e,"Content-Disposition")}function fo(e){return G(e,"Content-Type")?.startsWith("application/json")==!0}function yo(e,t){let r=De(e,t);return t?.[0].convertedToBatch?r[0]:r}function Ro(e,t,r){return lo(e,t,r[0])}function ke(e,t,r=0){return Me(JSON.parse(e,S),t[r])}function Se(e){let t=Number(e);return isFinite(t)?t:e}function go(e,t){if(t?.[0]?.valueIfEmpty!==void 0)return t[0].valueIfEmpty;let r=G(e,"OData-EntityId");if(r)return Z(r)??void 0;let o=G(e,"Location");if(o){let n={location:o};return e["x-ms-chunk-size"]&&(n.chunkSize=parseInt(e["x-ms-chunk-size"])),e["x-ms-dyn-backgroundoperationid"]&&(n.backgroundOperationId=e["x-ms-dyn-backgroundoperationid"]),n}}function Ue(e,t,r){return e.length?mo(e)?yo(e,r):uo(t)?Ro(e,t,r):fo(t)?ke(e,r):Se(e):go(t,r)}var oe=b(()=>{"use strict";Pt();d();Pe();h();Ie()});function U(e){let t={};if(!e)return t;let r=e.split(`\r `);for(let o=0,n=r.length;o<n;o++){let i=r[o],c=i.indexOf(": ");c>0&&(t[i.substring(0,c)]=i.substring(c+2))}return t}var _e=b(()=>{"use strict"});var Dt={};Je(Dt,{XhrWrapper:()=>K,executeRequest:()=>ho});function ho(e){return new Promise((t,r)=>{Co(e,t,r)})}function Co(e,t,r){let o=e.data,n=e.headers,i=e.responseParams,c=e.abortSignal;if(c?.aborted){r(a.handleHttpError({name:"AbortError",code:20,message:"The user aborted a request."}));return}let s=new XMLHttpRequest;s.open(e.method,e.uri,e.isAsync||!1);for(let y in n)s.setRequestHeader(y,n[y]);s.onreadystatechange=function(){if(s.readyState===4){if(c&&c.removeEventListener("abort",E),!s||s.status===0)return;if(s.status>=200&&s.status<300||s.status===304){let y=U(s.getAllResponseHeaders()),x={data:Ue(s.responseText,y,i[e.requestId]),headers:y,status:s.status};s=null,t(x)}else{let y,A;try{A=U(s.getAllResponseHeaders());let j=Ue(s.responseText,A,i[e.requestId]);if(Array.isArray(j)){r(j);return}y=j.error}catch{s.response.length>0?y={message:s.response}:y={message:"Unexpected Error"}}let x={status:s.status,statusText:s.statusText,headers:A};s=null,r(a.handleHttpError(y,x))}}},e.timeout&&(s.timeout=e.timeout),s.onerror=function(){let y=U(s.getAllResponseHeaders());r(a.handleHttpError({status:s.status,statusText:s.statusText,message:s.responseText||"Network Error",headers:y})),s=null},s.ontimeout=function(){let y=U(s.getAllResponseHeaders());r(a.handleHttpError({name:"TimeoutError",status:s.status,statusText:s.statusText,message:s.responseText||"Request Timed Out",headers:y})),s=null},s.onabort=function(){if(!s)return;let y=U(s.getAllResponseHeaders());r(a.handleHttpError({status:s.status,statusText:s.statusText,message:"Request aborted",headers:y})),s=null};let E=()=>{if(!s)return;let y=U(s.getAllResponseHeaders());r(a.handleHttpError({name:"AbortError",code:20,status:s.status,statusText:s.statusText,message:"The user aborted a request.",headers:y})),s.abort(),s=null};c&&c.addEventListener("abort",E),o?s.send(o):s.send(),K.afterSendEvent&&K.afterSendEvent()}var K,It=b(()=>{"use strict";f();oe();_e();K=class{}});var Zo={};Je(Zo,{DynamicsWebApi:()=>Ke});d();f();var p="DynamicsWebApi";var R=`${p}.setConfig`,Yn=["dataApi","searchApi","serviceApi"],Jn=(e,t)=>{if(re())return new URL("_api",window.location.origin).toString()+"/";{e||(e=Et());let r="api";return t.path&&(r+=`/${t.path}`),t.version&&(r+=`/v${t.version}`),new URL(r,e).toString()+"/"}},jn=(e,t)=>{t&&(t.escapeSpecialCharacters!=null&&(a.boolParameterCheck(t.escapeSpecialCharacters,R,"config.searchApi.options.escapeSpecialCharacters"),e.escapeSpecialCharacters=t.escapeSpecialCharacters),t.enableResponseCompatibility!=null&&(a.boolParameterCheck(t.enableResponseCompatibility,R,"config.searchApi.options.enableResponseCompatibility"),e.enableSearchApiResponseCompatibility=t.enableResponseCompatibility))},Zn=(e,t,r)=>{let o=e[t],n=r?.[t];n?.version&&(a.stringParameterCheck(n.version,R,`config.${t}.version`),o.version=n.version),n?.path&&(a.stringParameterCheck(n.path,R,`config.${t}.path`),o.path=n.path),t==="searchApi"&&jn(o,n?.options),o.url=Jn(e.serverUrl,o)};function Ne(e,t){t?.serverUrl&&(a.stringParameterCheck(t.serverUrl,R,"config.serverUrl"),e.serverUrl=t.serverUrl),Yn.forEach(r=>{Zn(e,r,t)}),t?.impersonate&&(e.impersonate=a.guidParameterCheck(t.impersonate,R,"config.impersonate")),t?.impersonateAAD&&(e.impersonateAAD=a.guidParameterCheck(t.impersonateAAD,R,"config.impersonateAAD")),t?.onTokenRefresh&&(a.callbackParameterCheck(t.onTokenRefresh,R,"config.onTokenRefresh"),e.onTokenRefresh=t.onTokenRefresh),t?.includeAnnotations&&(a.stringParameterCheck(t.includeAnnotations,R,"config.includeAnnotations"),e.includeAnnotations=t.includeAnnotations),t?.timeout&&(a.numberParameterCheck(t.timeout,R,"config.timeout"),e.timeout=t.timeout),t?.maxPageSize&&(a.numberParameterCheck(t.maxPageSize,R,"config.maxPageSize"),e.maxPageSize=t.maxPageSize),t?.returnRepresentation!=null&&(a.boolParameterCheck(t.returnRepresentation,R,"config.returnRepresentation"),e.returnRepresentation=t.returnRepresentation),t?.useEntityNames!=null&&(a.boolParameterCheck(t.useEntityNames,R,"config.useEntityNames"),e.useEntityNames=t.useEntityNames),t?.propagateErrors!=null&&(a.boolParameterCheck(t.propagateErrors,R,"config.propagateErrors"),e.propagateErrors=t.propagateErrors),t?.headers&&(e.headers=t.headers)}function vt(){return{serverUrl:null,impersonate:null,impersonateAAD:null,onTokenRefresh:null,includeAnnotations:null,maxPageSize:null,returnRepresentation:null,proxy:null,dataApi:{path:"data",version:"9.2",url:""},searchApi:{path:"search",version:"1.0",url:""},serviceApi:{url:""}}}d();d();var I=null,Nt=e=>{I=e},F=e=>{if(g(I))return null;let t=I[e];if(!t){for(let r in I)if(I[r]===e)return e}return t};async function kt(e){return(It(),je(Dt)).executeRequest(e)}f();f();h();d();var $e=(e,t,r="",o="&")=>{let n=[];if(e){if(e.navigationProperty){if(a.stringParameterCheck(e.navigationProperty,`DynamicsWebApi.${e.functionName}`,"request.navigationProperty"),r+="/"+e.navigationProperty,e.navigationPropertyKey){let i=a.keyParameterCheck(e.navigationPropertyKey,`DynamicsWebApi.${e.functionName}`,"request.navigationPropertyKey");r+="("+i+")"}e.navigationProperty==="Attributes"&&e.metadataAttributeType&&(a.stringParameterCheck(e.metadataAttributeType,`DynamicsWebApi.${e.functionName}`,"request.metadataAttributeType"),r+="/"+e.metadataAttributeType)}if(e.select?.length&&(a.arrayParameterCheck(e.select,`DynamicsWebApi.${e.functionName}`,"request.select"),e.functionName=="retrieve"&&e.select.length==1&&e.select[0].endsWith("/$ref")?r+="/"+e.select[0]:(e.select[0].startsWith("/")&&e.functionName=="retrieve"&&(e.navigationProperty==null?r+=e.select.shift():e.select.shift()),e.select.length&&n.push("$select="+e.select.join(",")))),e.filter){a.stringParameterCheck(e.filter,`DynamicsWebApi.${e.functionName}`,"request.filter");let i=nt(e.filter);n.push("$filter="+encodeURIComponent(i))}if(e.fieldName&&(a.stringParameterCheck(e.fieldName,`DynamicsWebApi.${e.functionName}`,"request.fieldName"),e.property||(e.property=e.fieldName),delete e.fieldName),e.property&&(a.stringParameterCheck(e.property,`DynamicsWebApi.${e.functionName}`,"request.property"),r+="/"+e.property),e.savedQuery&&n.push("savedQuery="+a.guidParameterCheck(e.savedQuery,`DynamicsWebApi.${e.functionName}`,"request.savedQuery")),e.userQuery&&n.push("userQuery="+a.guidParameterCheck(e.userQuery,`DynamicsWebApi.${e.functionName}`,"request.userQuery")),e.apply&&(a.stringParameterCheck(e.apply,`DynamicsWebApi.${e.functionName}`,"request.apply"),n.push("$apply="+e.apply)),e.count&&(a.boolParameterCheck(e.count,`DynamicsWebApi.${e.functionName}`,"request.count"),n.push("$count="+e.count)),e.top&&e.top>0&&(a.numberParameterCheck(e.top,`DynamicsWebApi.${e.functionName}`,"request.top"),n.push("$top="+e.top)),e.orderBy!=null&&e.orderBy.length&&(a.arrayParameterCheck(e.orderBy,`DynamicsWebApi.${e.functionName}`,"request.orderBy"),n.push("$orderby="+e.orderBy.join(","))),e.partitionId&&(a.stringParameterCheck(e.partitionId,`DynamicsWebApi.${e.functionName}`,"request.partitionId"),n.push("partitionid='"+e.partitionId+"'")),e.downloadSize&&(a.stringParameterCheck(e.downloadSize,`DynamicsWebApi.${e.functionName}`,"request.downloadSize"),n.push("size="+e.downloadSize)),e.tag&&(a.stringParameterCheck(e.tag,`DynamicsWebApi.${e.functionName}`,"request.tag"),n.push("tag="+encodeURIComponent(e.tag))),e.queryParams?.length&&(a.arrayParameterCheck(e.queryParams,`DynamicsWebApi.${e.functionName}`,"request.queryParams"),n.push(e.queryParams.join("&"))),e.fileName&&(a.stringParameterCheck(e.fileName,`DynamicsWebApi.${e.functionName}`,"request.fileName"),n.push("x-ms-file-name="+e.fileName)),e.data&&a.parameterCheck(e.data,`DynamicsWebApi.${e.functionName}`,"request.data"),e.isBatch&&a.boolParameterCheck(e.isBatch,`DynamicsWebApi.${e.functionName}`,"request.isBatch"),e.fetchXml&&(a.stringParameterCheck(e.fetchXml,`DynamicsWebApi.${e.functionName}`,"request.fetchXml"),n.push("fetchXml="+encodeURIComponent(e.fetchXml))),g(e.inChangeSet)||a.boolParameterCheck(e.inChangeSet,`DynamicsWebApi.${e.functionName}`,"request.inChangeSet"),e.isBatch&&g(e.inChangeSet)&&(e.inChangeSet=!0),e.timeout&&a.numberParameterCheck(e.timeout,`DynamicsWebApi.${e.functionName}`,"request.timeout"),e.expand?.length)if(a.stringOrArrayParameterCheck(e.expand,`DynamicsWebApi.${e.functionName}`,"request.expand"),typeof e.expand=="string")n.push("$expand="+e.expand);else{let i=[];for(let{property:c,...s}of e.expand){if(!c)continue;let E={functionName:`${e.functionName} $expand`,...s},y=$e(E,t,"",";");y&&(y=`(${y})`),i.push(c+y)}i.length&&n.push("$expand="+i.join(","))}}return n.length?(o==="&"&&(r+="?"),r+n.join(o)):r};f();f();h();var St=(e,t)=>{let r=`DynamicsWebApi.${e.functionName}`,o={respondAsync:e.respondAsync,backgroundOperationCallbackUrl:e.backgroundOperationCallbackUrl??t?.backgroundOperationCallbackUrl,returnRepresentation:e.returnRepresentation??t?.returnRepresentation,includeAnnotations:e.includeAnnotations??t?.includeAnnotations,maxPageSize:e.maxPageSize??t?.maxPageSize,trackChanges:e.trackChanges,continueOnError:e.continueOnError},n=new Set;if(e.prefer?.length){a.stringOrArrayParameterCheck(e.prefer,r,"request.prefer");let i=typeof e.prefer=="string"?e.prefer.split(","):e.prefer;for(let c of i){let s=c.trim();s.includes("respond-async")?o.respondAsync=!0:s.startsWith("odata.callback")?o.backgroundOperationCallbackUrl=gt(s):s==="return=representation"?o.returnRepresentation=!0:s.includes("odata.include-annotations=")?o.includeAnnotations=xe(s.replace("odata.include-annotations=","")):s.startsWith("odata.maxpagesize=")?o.maxPageSize=Number(xe(s.replace("odata.maxpagesize=","")))||0:s.includes("odata.track-changes")?o.trackChanges=!0:s.includes("odata.continue-on-error")?o.continueOnError=!0:n.add(s)}}for(let i in o){let c=Ao[i];c&&o[i]&&(c.validator?.(o[i],r,`request.${i}`),c.condition(o[i],o)&&n.add(c.formatter(o[i],o)))}return Array.from(n).join(",")},Ao={respondAsync:{validator:a.boolParameterCheck,condition:e=>!!e,formatter:()=>"respond-async"},backgroundOperationCallbackUrl:{validator:a.stringParameterCheck,condition:(e,t)=>e&&t.respondAsync,formatter:e=>`odata.callback;url="${e}"`},returnRepresentation:{validator:a.boolParameterCheck,condition:e=>!!e,formatter:()=>"return=representation"},includeAnnotations:{validator:a.stringParameterCheck,condition:e=>!!e,formatter:e=>`odata.include-annotations="${e}"`},maxPageSize:{validator:(e,t)=>e>0?a.numberParameterCheck(e,t,"request.maxPageSize"):void 0,condition:e=>e>0,formatter:e=>`odata.maxpagesize=${e}`},trackChanges:{validator:a.boolParameterCheck,condition:e=>!!e,formatter:()=>"odata.track-changes"},continueOnError:{validator:a.boolParameterCheck,condition:e=>!!e,formatter:()=>"odata.continue-on-error"}};var Ot=(e,t)=>{let r={...t.headers,...e.userHeaders},o=St(e,t);if(o.length&&(r.Prefer=o),e.collection==="$metadata"&&(r.Accept="application/xml"),e.transferMode&&(r["x-ms-transfer-mode"]=e.transferMode),e.ifmatch!=null&&e.ifnonematch!=null)throw new Error(`DynamicsWebApi.${e.functionName}. Either one of request.ifmatch or request.ifnonematch parameters should be used in a call, not both.`);return e.ifmatch&&(a.stringParameterCheck(e.ifmatch,`DynamicsWebApi.${e.functionName}`,"request.ifmatch"),r["If-Match"]=e.ifmatch),e.ifnonematch&&(a.stringParameterCheck(e.ifnonematch,`DynamicsWebApi.${e.functionName}`,"request.ifnonematch"),r["If-None-Match"]=e.ifnonematch),e.impersonate&&(a.stringParameterCheck(e.impersonate,`DynamicsWebApi.${e.functionName}`,"request.impersonate"),r.MSCRMCallerID=a.guidParameterCheck(e.impersonate,`DynamicsWebApi.${e.functionName}`,"request.impersonate")),e.impersonateAAD&&(a.stringParameterCheck(e.impersonateAAD,`DynamicsWebApi.${e.functionName}`,"request.impersonateAAD"),r.CallerObjectId=a.guidParameterCheck(e.impersonateAAD,`DynamicsWebApi.${e.functionName}`,"request.impersonateAAD")),e.token&&(a.stringParameterCheck(e.token,`DynamicsWebApi.${e.functionName}`,"request.token"),r.Authorization="Bearer "+e.token),e.duplicateDetection&&(a.boolParameterCheck(e.duplicateDetection,`DynamicsWebApi.${e.functionName}`,"request.duplicateDetection"),r["MSCRM.SuppressDuplicateDetection"]="false"),e.bypassCustomPluginExecution&&(a.boolParameterCheck(e.bypassCustomPluginExecution,`DynamicsWebApi.${e.functionName}`,"request.bypassCustomPluginExecution"),r["MSCRM.BypassCustomPluginExecution"]="true"),e.noCache&&(a.boolParameterCheck(e.noCache,`DynamicsWebApi.${e.functionName}`,"request.noCache"),r["Cache-Control"]="no-cache"),e.mergeLabels&&(a.boolParameterCheck(e.mergeLabels,`DynamicsWebApi.${e.functionName}`,"request.mergeLabels"),r["MSCRM.MergeLabels"]="true"),e.contentId&&(a.stringParameterCheck(e.contentId,`DynamicsWebApi.${e.functionName}`,"request.contentId"),e.contentId.startsWith("$")||(r["Content-ID"]=e.contentId)),e.contentRange&&(a.stringParameterCheck(e.contentRange,`DynamicsWebApi.${e.functionName}`,"request.contentRange"),r["Content-Range"]=e.contentRange),e.range&&(a.stringParameterCheck(e.range,`DynamicsWebApi.${e.functionName}`,"request.range"),r.Range=e.range),r};f();var ae=(e,t)=>(e.path="",e.functionName=e.functionName||"",e.url?(a.stringParameterCheck(e.url,`DynamicsWebApi.${e.functionName}`,"request.url"),e.path=e.url.replace(t.dataApi.url,"")):(!e._isUnboundRequest&&!e.contentId&&!e.collection&&a.parameterCheck(e.collection,`DynamicsWebApi.${e.functionName}`,"request.collection"),e.contentId&&(a.stringParameterCheck(e.contentId,`DynamicsWebApi.${e.functionName}`,"request.contentId"),e.contentId.startsWith("$")&&(e.path=e.contentId)),e.collection!=null&&(a.stringParameterCheck(e.collection,`DynamicsWebApi.${e.functionName}`,"request.collection"),e.path+=e.path?`/${e.collection}`:e.collection,e.key&&(e.key=a.keyParameterCheck(e.key,`DynamicsWebApi.${e.functionName}`,"request.key"),e.path+=`(${e.key})`)),e.addPath&&(e.path&&(e.path+="/"),e.path+=e.addPath),e.path=$e(e,t,e.path)),e.hasOwnProperty("async")&&e.async!=null?a.boolParameterCheck(e.async,`DynamicsWebApi.${e.functionName}`,"request.async"):e.async=!0,e.headers=Ot(e,t),e);h();d();Pe();Ie();oe();_e();var Eo=e=>{let t=Te.exec(e);if(t&&t.length>2){let r=F(t[1]);if(!g(r))return e.replace(Te,`${r}$2`)}return e},xo=(e,t,r)=>(r.startsWith(e.dataApi.url)||(t.endsWith("@odata.bind")?r.startsWith("/")||(r=`/${r}`):r=`${e.dataApi.url}${ee(r)}`),r),ie=(e,t)=>{if(!e)return null;if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint32Array)return e;let r=JSON.stringify(e,(o,n)=>{if(o==="@odata.id"||o.endsWith("@odata.bind"))typeof n=="string"&&!n.startsWith("$")&&(n=Ee(n),t.useEntityNames&&(n=Eo(n)),o!=="@odata.id"&&(n=xo(t,o,n)));else if(o.startsWith("oData")||o.endsWith("_Formatted")||o.endsWith("_NavigationProperty")||o.endsWith("_LogicalName"))return;return n});return it(r)};var se=(e={},t)=>(e.Accept||(e.Accept="application/json"),e["OData-MaxVersion"]||(e["OData-MaxVersion"]="4.0"),e["OData-Version"]||(e["OData-Version"]="4.0"),e["Content-Range"]?e["Content-Type"]="application/octet-stream":!e["Content-Type"]&&t&&(e["Content-Type"]="application/json; charset=utf-8"),e);d();var we=(e,t,r)=>{let o=`dwa_batch_${O()}`,n=[],i=null,c=1e5,s=(y,A)=>{for(let x in y)x==="Authorization"||x==="Content-ID"||A.push(`${x}: ${y[x]}`)};e.forEach(y=>{y.functionName="executeBatch",r?.inChangeSet===!1&&(y.inChangeSet=!1);let A=y.method==="GET"?!1:!!y.inChangeSet;if(!A&&i&&(n.push(`\r --${i}--`),i=null,c=1e5),i||(n.push(`\r --${o}`),A&&(i=`changeset_${O()}`,n.push("Content-Type: multipart/mixed;boundary="+i))),A&&n.push(`\r --${i}`),n.push("Content-Type: application/http"),n.push("Content-Transfer-Encoding: binary"),A){let x=y.headers.hasOwnProperty("Content-ID")?y.headers["Content-ID"]:++c;n.push(`Content-ID: ${x}`)}y.path?.startsWith("$")?n.push(`\r ${y.method} ${y.path} HTTP/1.1`):n.push(`\r ${y.method} ${t.dataApi.url}${y.path} HTTP/1.1`),y.method==="GET"?n.push("Accept: application/json"):n.push("Content-Type: application/json"),y.headers&&s(y.headers,n),y.data&&n.push(`\r ${ie(y.data,t)}`)}),i&&n.push(`\r --${i}--`),n.push(`\r --${o}--\r `);let E=se(r?.userHeaders,r?.data);return E["Content-Type"]=`multipart/mixed;boundary=${o}`,{headers:E,body:n.join(`\r `)}};var Mt=(e,t)=>{z[e]?z[e].push(t):z[e]=[t]},bo=(e,t)=>{_[e]?_[e].push(t):_[e]=[t]},Be=e=>{delete z[e],_.hasOwnProperty(e)&&delete _[e]},Ut=async(e,t)=>{try{let r=await Do(e,t);return Be(e.requestId),r}catch(r){throw Be(e.requestId),r}finally{Be(e.requestId)}},_={},z={},To=["$metadata","EntityDefinitions","RelationshipDefinitions","GlobalOptionSetDefinitions","ManagedPropertyDefinitions","query","suggest","autocomplete"],vo=e=>To.indexOf(e)>-1,No=async(e,t)=>{if(!g(I))return F(e)||e;let r=ae({method:"GET",collection:"EntityDefinitions",select:["EntitySetName","LogicalName"],noCache:!0,functionName:"retrieveMultiple"},t),o=await Ut(r,t);Nt({});for(let n=0;n<o.data.value.length;n++)I[o.data.value[n].LogicalName]=o.data.value[n].EntitySetName;return F(e)||e},Po=async(e,t)=>{if(!e||vo(e)||(e=e.toLowerCase(),!t.useEntityNames))return e;try{return await No(e,t)}catch(r){throw new Error("Unable to fetch Collection Names. Error: "+r.message)}},Do=async(e,t)=>{e.headers=e.headers||{},e.responseParameters=e.responseParameters||{},e.requestId=e.requestId||O(),Mt(e.requestId,e.responseParameters);let r=null,o=e.responseParameters?.convertedToBatch;if(e.path==="$batch"&&!o){let c=_[e.requestId];if(!c)throw a.batchIsEmpty();let s=we(c,t,e);r=s.body,e.headers={...s.headers,...e.headers},delete _[e.requestId]}else r=o?e.data:ie(e.data,t),!o&&e.includeDefaultDataverseHeaders!==!1&&(e.headers=se(e.headers,e.data));t.impersonate&&!e.headers.MSCRMCallerID&&(e.headers.MSCRMCallerID=t.impersonate),t.impersonateAAD&&!e.headers.CallerObjectId&&(e.headers.CallerObjectId=t.impersonateAAD);let n=null;if(t.onTokenRefresh&&(!e.headers||e.headers&&!e.headers.Authorization)&&(n=await t.onTokenRefresh(),!n))throw new Error("Token is empty. Request is aborted.");n&&(e.headers.Authorization="Bearer "+(n.hasOwnProperty("accessToken")?n.accessToken:n)),re()&&(e.headers.__RequestVerificationToken=await window.shell.getTokenDeferred());let i=e.apiConfig?e.apiConfig.url:t.dataApi.url;return await kt({method:e.method,uri:i.toString()+e.path,data:r,proxy:t.proxy,isAsync:e.async,headers:e.headers,requestId:e.requestId,abortSignal:e.signal,responseParams:z,timeout:e.timeout||t.timeout})},_t=async(e,t)=>{if(e.responseParameters=e.responseParameters||{},e.userHeaders=e.headers,delete e.headers,!e.isBatch){let r=await Po(e.collection,t);if(e.collection=r,ae(e,t),e.responseParameters.convertedToBatch=!1,e.path.length>2e3){let o=we([e],t);e.headers.Authorization&&(o.headers.Authorization=e.headers.Authorization),e.method="POST",e.path="$batch",e.data=o.body,e.headers={...o.headers,...e.userHeaders},e.responseParameters.convertedToBatch=!0}return Ut(e,t)}ae(e,t),Mt(e.requestId,e.responseParameters),bo(e.requestId,e)};var $t=e=>F(e);var $,q,w,pe=class{constructor(t){B(this,$,vt());B(this,q,!1);B(this,w,null);this.setConfig=t=>Ne(m(this,$),t);this.makeRequest=t=>(t.isBatch=m(this,q),m(this,w)&&(t.requestId=m(this,w)),_t(t,m(this,$)));Ne(m(this,$),t)}get batchRequestId(){return m(this,w)}set batchRequestId(t){L(this,w,t)}get config(){return m(this,$)}get isBatch(){return m(this,q)}set isBatch(t){L(this,q,t)}};$=new WeakMap,q=new WeakMap,w=new WeakMap;f();d();var wt="associate",Y=`${p}.${wt}`,Bt=async(e,t)=>{a.parameterCheck(e,Y,"request"),a.parameterCheck(e.relatedKey,Y,"request.relatedKey"),a.stringParameterCheck(e.relationshipName,Y,"request.relationshipName");let r=e.relatedKey,o=e.relatedKey;(!t.isBatch||t.isBatch&&!e.relatedKey.startsWith("$"))&&(a.stringParameterCheck(e.relatedCollection,Y,"request.relatedCollection"),r=a.keyParameterCheck(e.relatedKey,Y,"request.relatedKey"),o=`${t.config.dataApi.url}${e.relatedCollection}(${r})`);let n=l(e,["primaryKey"]);n.method="POST",n.functionName=wt,n.navigationProperty=e.relationshipName+"/$ref",n.key=e.primaryKey,n.data={"@odata.id":o},await t.makeRequest(n)};f();d();var Ft="associateSingleValued",J=`${p}.${Ft}`,qt=async(e,t)=>{a.parameterCheck(e,J,"request"),a.parameterCheck(e.relatedKey,J,"request.relatedKey"),a.stringParameterCheck(e.navigationProperty,J,"request.navigationProperty");let r=e.relatedKey,o=e.relatedKey;(!t.isBatch||t.isBatch&&!e.relatedKey.startsWith("$"))&&(a.stringParameterCheck(e.relatedCollection,J,"request.relatedCollection"),r=a.keyParameterCheck(e.relatedKey,J,"request.relatedKey"),o=`${t.config.dataApi.url}${e.relatedCollection}(${r})`);let n=l(e,["primaryKey"]);n.method="PUT",n.functionName=Ft,n.navigationProperty+="/$ref",n.key=e.primaryKey,n.data={"@odata.id":o},await t.makeRequest(n)};f();d();var Ht="callAction",Qt=`${p}.${Ht}`,Lt=async(e,t)=>{a.parameterCheck(e,Qt,"request"),a.stringParameterCheck(e.actionName,Qt,"request.actionName");let r=l(e,["action"]);return r.method="POST",r.functionName=Ht,r.addPath=e.actionName,r._isUnboundRequest=!r.collection,r.data=e.action,(await t.makeRequest(r))?.data};f();d();var Vt="callFunction",Wt=`${p}.${Vt}`,Gt=async(e,t)=>{a.parameterCheck(e,Wt,"request");let r=y=>y.name||y.functionName,o=typeof e!="string",n=o?r(e):e,i=o?"request.name":"name",c=o?T(e,["name"]):{functionName:n};a.stringParameterCheck(n,Wt,i);let s=Ct(c.parameters);return c.method="GET",c.addPath=n+s.key,c.queryParams=s.queryParams,c._isUnboundRequest=!c.collection,c.functionName=Vt,(await t.makeRequest(c))?.data};f();d();var Xt="create",Io=`${p}.${Xt}`,v=async(e,t)=>{a.parameterCheck(e,Io,"request");let r;return e.functionName?r=e:(r=l(e),r.functionName=Xt),r.method="POST",(await t.makeRequest(r))?.data};f();d();var Kt="count",ko=`${p}.${Kt}`,zt=async(e,t)=>{a.parameterCheck(e,ko,"request");let r=l(e);return r.method="GET",r.functionName=Kt,r.filter?.length?r.count=!0:r.navigationProperty="$count",r.responseParameters={toCount:r.count},(await t.makeRequest(r))?.data};f();f();f();d();var Jt="retrieveMultiple",Yt=`${p}.${Jt}`,C=async(e,t,r)=>{a.parameterCheck(e,Yt,"request");let o;return e.functionName?o=e:(o=l(e),o.functionName=Jt),o.method="GET",r&&(a.stringParameterCheck(r,Yt,"nextPageLink"),o.url=r),(await t.makeRequest(o))?.data};var So="retrieveAll",Oo=`${p}.${So}`,ce=async(e,t,r,o=[])=>{let n=await C(e,t,r);o=o.concat(n.value);let i=n.oDataNextLink;if(i)return ce(e,t,i,o);let c={value:o};return n.oDataDeltaLink&&(c["@odata.deltaLink"]=n.oDataDeltaLink,c.oDataDeltaLink=n.oDataDeltaLink),c},Fe=(e,t)=>(a.throwBatchIncompatible(Oo,t.isBatch),ce(e,t));var Mo="countAll",jt=`${p}.${Mo}`,Zt=async(e,t)=>(a.throwBatchIncompatible(jt,t.isBatch),a.parameterCheck(e,jt,"request"),(await ce(e,t)).value.length);f();d();var er="disassociate",le=`${p}.${er}`,tr=async(e,t)=>{a.parameterCheck(e,le,"request");let r=l(e);r.method="DELETE",r.functionName=er,a.stringParameterCheck(e.relationshipName,le,"request.relationshipName");let o=a.keyParameterCheck(e.primaryKey,le,"request.primaryKey"),n=a.keyParameterCheck(e.relatedKey,le,"request.relatedId");r.key=o,r.navigationProperty=`${e.relationshipName}(${n})/$ref`,await t.makeRequest(r)};f();d();var rr="disassociateSingleValued",qe=`${p}.${rr}`,nr=async(e,t)=>{a.parameterCheck(e,qe,"request");let r=l(e);r.method="DELETE",r.functionName=rr,a.stringParameterCheck(e.navigationProperty,qe,"request.navigationProperty");let o=a.keyParameterCheck(e.primaryKey,qe,"request.primaryKey");r.navigationProperty+="/$ref",r.key=o,await t.makeRequest(r)};f();d();var or="retrieve",Uo=`${p}.${or}`,N=async(e,t)=>{a.parameterCheck(e,Uo,"request");let r;return e.functionName?r=e:(r=l(e),r.functionName=or),r.method="GET",r.responseParameters={isRef:r.select?.length===1&&r.select[0].endsWith("/$ref")},(await t.makeRequest(r))?.data};f();h();d();var ar="fetch",me=`${p}.${ar}`,ue=async(e,t)=>{a.parameterCheck(e,me,"request");let r=l(e);if(r.method="GET",r.functionName=ar,a.stringParameterCheck(r.fetchXml,me,"request.fetchXml"),r.fetchXml&&!ut.test(r.fetchXml)){let n="";ft.test(r.fetchXml)||(r.pageNumber=r.pageNumber||1,a.numberParameterCheck(r.pageNumber,me,"request.pageNumber"),n=`$1 page="${r.pageNumber}"`),r.pagingCookie!=null&&(a.stringParameterCheck(r.pagingCookie,me,"request.pagingCookie"),n+=` paging-cookie="${r.pagingCookie}"`),n&&(r.fetchXml=r.fetchXml.replace(dt,n))}return r.responseParameters={pageNumber:r.pageNumber},(await t.makeRequest(r))?.data};f();var _o="fetchAll",ir=`${p}.${_o}`,sr=async(e,t,r=[])=>{let o=await ue(e,t);return r=r.concat(o.value),o.PagingInfo?(e.pageNumber=o.PagingInfo.nextPage,e.pagingCookie=o.PagingInfo.cookie,sr(e,t,r)):{value:r}},pr=async(e,t)=>(a.parameterCheck(e,ir,"request"),a.throwBatchIncompatible(ir,t.isBatch),sr(e,t));f();h();d();var cr="update",$o=`${p}.${cr}`,P=async(e,t)=>{a.parameterCheck(e,$o,"request");let r;if(e.functionName?r=e:(r=l(e),r.functionName=cr),r.method??(r.method=mt(r.collection)),r.responseParameters={valueIfEmpty:!0},r.ifmatch??(r.ifmatch="*"),t.config.propagateErrors)return(await t.makeRequest(r))?.data;let o=r.ifmatch;try{return(await t.makeRequest(r))?.data}catch(n){if(o&&n.status===412)return!1;throw n}};f();d();var mr="updateSingleProperty",lr=`${p}.${mr}`,ur=async(e,t)=>{a.parameterCheck(e,lr,"request"),a.parameterCheck(e.fieldValuePair,lr,"request.fieldValuePair");var r=Object.keys(e.fieldValuePair)[0],o=e.fieldValuePair[r];let n=l(e);return n.navigationProperty=r,n.data={value:o},n.functionName=mr,n.method="PUT",delete n.fieldValuePair,(await t.makeRequest(n))?.data};f();d();var fr="upsert",wo=`${p}.${fr}`,dr=async(e,t)=>{a.parameterCheck(e,wo,"request");let r=l(e);if(r.method="PATCH",r.functionName=fr,t.config.propagateErrors)return(await t.makeRequest(r))?.data;let o=r.ifnonematch,n=r.ifmatch;try{return(await t.makeRequest(r))?.data}catch(i){if(o&&i.status===412)return null;if(n&&i.status===404)return null;throw i}};f();d();var yr="deleteRecord",Bo=`${p}.${yr}`,Q=async(e,t)=>{a.parameterCheck(e,Bo,"request");let r;if(e.functionName?r=e:(r=l(e),r.functionName=yr),r.method="DELETE",r.responseParameters={valueIfEmpty:!0},t.config.propagateErrors)return(await t.makeRequest(r))?.data;let o=r.ifmatch;try{return(await t.makeRequest(r))?.data}catch(n){if(o&&n.status===412)return!1;throw n}};f();d();var gr="uploadFile",Rr=`${p}.${gr}`,hr=async(e,t,r,o,n=0)=>{if(xt(e,r,o,n),await t.makeRequest(e),n+=o,n<=r.length)return hr(e,t,r,o,n)},Cr=async(e,t)=>{a.throwBatchIncompatible(Rr,t.isBatch),a.parameterCheck(e,Rr,"request");let r=l(e,["data"]);r.method="PATCH",r.functionName=gr,r.transferMode="chunked";let o=await t.makeRequest(r);return r.url=o?.data.location,delete r.transferMode,delete r.fieldName,delete r.property,delete r.fileName,hr(r,t,e.data,o?.data.chunkSize)};f();d();var Er="downloadFile",Ar=`${p}.${Er}`,xr=async(e,t,r=0,o="")=>{e.range="bytes="+r+"-"+(r+ve-1),e.downloadSize="full";let n=await t.makeRequest(e);return e.url=n?.data.location,o+=n?.data.value,r+=ve,r<=n?.data.fileSize?xr(e,t,r,o):{fileName:n?.data.fileName,fileSize:n?.data.fileSize,data:bt(o)}},br=(e,t)=>{a.throwBatchIncompatible(Ar,t.isBatch),a.parameterCheck(e,Ar,"request");let r=l(e);return r.method="GET",r.functionName=Er,r.responseParameters={parse:!0},xr(r,t)};d();f();var Fo="executeBatch",qo=`${p}.${Fo}`;async function Tr(e,t){a.throwBatchNotStarted(t.isBatch);let r=e?l(e):{};return r.collection="$batch",r.method="POST",r.functionName=qo,r.requestId=t.batchRequestId,t.batchRequestId=null,t.isBatch=!1,(await t.makeRequest(r))?.data}function vr(e){e.isBatch=!0,e.batchRequestId=O()}f();d();var Pr="createEntity",Nr=`${p}.${Pr}`,Dr=async(e,t)=>{a.parameterCheck(e,Nr,"request"),a.parameterCheck(e.data,Nr,"request.data");let r=l(e);return r.collection="EntityDefinitions",r.functionName=Pr,v(r,t)};f();d();var kr="updateEntity",Ir=`${p}.${kr}`,Sr=async(e,t)=>{a.parameterCheck(e,Ir,"request"),a.parameterCheck(e.data,Ir,"request.data");let r=l(e);return r.collection="EntityDefinitions",r.functionName=kr,r.key=r.data.MetadataId,r.method="PUT",await P(r,t)};f();d();var Qo="retrieveEntity",Or=`${p}.${Qo}`,Mr=async(e,t)=>{a.parameterCheck(e,Or,"request"),a.keyParameterCheck(e.key,Or,"request.key");let r=l(e);return r.collection="EntityDefinitions",r.functionName="retrieveEntity",await N(r,t)};d();var Ho="retrieveEntities",Ur=(e,t)=>{let r=t?l(t):{};return r.collection="EntityDefinitions",r.functionName=Ho,C(r,e)};d();f();var _r="createAttribute",Qe=`${p}.${_r}`,$r=(e,t)=>{a.parameterCheck(e,Qe,"request"),a.parameterCheck(e.data,Qe,"request.data"),a.keyParameterCheck(e.entityKey,Qe,"request.entityKey");let r=l(e);return r.collection="EntityDefinitions",r.functionName=_r,r.navigationProperty="Attributes",r.key=e.entityKey,v(r,t)};d();f();var wr="updateAttribute",fe=`${p}.${wr}`,Br=(e,t)=>{a.parameterCheck(e,fe,"request"),a.parameterCheck(e.data,fe,"request.data"),a.keyParameterCheck(e.entityKey,fe,"request.entityKey"),a.guidParameterCheck(e.data.MetadataId,fe,"request.data.MetadataId");let r=l(e);return r.collection="EntityDefinitions",r.functionName=wr,r.navigationProperty="Attributes",r.navigationPropertyKey=e.data.MetadataId,r.metadataAttributeType=e.castType,r.key=e.entityKey,r.method="PUT",P(r,t)};d();f();var Fr="retrieveAttributes",He=`${p}.${Fr}`,qr=(e,t)=>{a.parameterCheck(e,He,"request"),a.keyParameterCheck(e.entityKey,He,"request.entityKey"),e.castType&&a.stringParameterCheck(e.castType,He,"request.castType");let r=l(e);return r.collection="EntityDefinitions",r.functionName=Fr,r.navigationProperty="Attributes",r.key=e.entityKey,r.metadataAttributeType=e.castType,C(r,t)};d();f();var Qr="retrieveAttributes",de=`${p}.${Qr}`,Hr=(e,t)=>{a.parameterCheck(e,de,"request"),a.keyParameterCheck(e.entityKey,de,"request.entityKey"),a.keyParameterCheck(e.attributeKey,de,"request.attributeKey"),e.castType&&a.stringParameterCheck(e.castType,de,"request.castType");let r=l(e);return r.collection="EntityDefinitions",r.navigationProperty="Attributes",r.navigationPropertyKey=e.attributeKey,r.metadataAttributeType=e.castType,r.key=e.entityKey,r.functionName=Qr,N(r,t)};d();f();var Wr="createRelationship",Lr=`${p}.${Wr}`,Vr=(e,t)=>{a.parameterCheck(e,Lr,"request"),a.parameterCheck(e.data,Lr,"request.data");let r=l(e);return r.collection="RelationshipDefinitions",r.functionName=Wr,v(r,t)};d();f();var Gr="updateRelationship",ye=`${p}.${Gr}`;function Xr(e,t){a.parameterCheck(e,ye,"request"),a.parameterCheck(e.data,ye,"request.data"),a.guidParameterCheck(e.data.MetadataId,ye,"request.data.MetadataId"),e.castType&&a.stringParameterCheck(e.castType,ye,"request.castType");let r=l(e);return r.collection="RelationshipDefinitions",r.key=e.data.MetadataId,r.navigationProperty=e.castType,r.functionName=Gr,r.method="PUT",P(r,t)}d();f();var zr="deleteRelationship",Kr=`${p}.${zr}`;async function Yr(e,t){a.parameterCheck(e,Kr,"request"),a.keyParameterCheck(e.key,Kr,"request.key");let r=l(e);return r.collection="RelationshipDefinitions",r.functionName=zr,Q(r,t)}d();f();var Jr="retrieveRelationships",Lo=`DynamicsWebApi.${Jr}`;async function jr(e,t){let r=e?l(e):{};return r.collection="RelationshipDefinitions",r.functionName=Jr,e&&e.castType&&(a.stringParameterCheck(e.castType,Lo,"request.castType"),r.navigationProperty=e.castType),C(r,t)}d();f();var Zr="retrieveRelationship",Le=`DynamicsWebApi.${Zr}`;async function en(e,t){a.parameterCheck(e,Le,"request"),a.keyParameterCheck(e.key,Le,"request.key"),e.castType&&a.stringParameterCheck(e.castType,Le,"request.castType");let r=l(e);return r.collection="RelationshipDefinitions",r.navigationProperty=e.castType,r.functionName=Zr,N(r,t)}d();f();var rn="createGlobalOptionSet",tn=`DynamicsWebApi.${rn}`;async function nn(e,t){a.parameterCheck(e,tn,"request"),a.parameterCheck(e.data,tn,"request.data");let r=l(e);return r.collection="GlobalOptionSetDefinitions",r.functionName=rn,v(r,t)}d();f();var on="updateGlobalOptionSet",Re=`DynamicsWebApi.${on}`;async function an(e,t){a.parameterCheck(e,Re,"request"),a.parameterCheck(e.data,Re,"request.data"),a.guidParameterCheck(e.data.MetadataId,Re,"request.data.MetadataId"),e.castType&&a.stringParameterCheck(e.castType,Re,"request.castType");let r=l(e);return r.collection="GlobalOptionSetDefinitions",r.key=e.data.MetadataId,r.functionName=on,r.method="PUT",P(r,t)}d();f();var sn="deleteGlobalOptionSet",Wo=`DynamicsWebApi.${sn}`;async function pn(e,t){a.parameterCheck(e,Wo,"request");let r=l(e);return r.collection="GlobalOptionSetDefinitions",r.functionName=sn,Q(r,t)}d();f();var ln="retrieveGlobalOptionSet",cn=`DynamicsWebApi.${ln}`;async function mn(e,t){a.parameterCheck(e,cn,"request"),e.castType&&a.stringParameterCheck(e.castType,cn,"request.castType");let r=l(e);return r.collection="GlobalOptionSetDefinitions",r.navigationProperty=e.castType,r.functionName=ln,N(r,t)}d();f();var un="retrieveGlobalOptionSets",Vo=`DynamicsWebApi.${un}`;async function fn(e,t){let r=e?l(e):{};return r.collection="GlobalOptionSetDefinitions",r.functionName=un,e?.castType&&(a.stringParameterCheck(e.castType,Vo,"request.castType"),r.navigationProperty=e.castType),C(r,t)}d();f();var dn="retrieveCsdlMetadata",Go=`DynamicsWebApi.${dn}`;async function yn(e,t){let r=e?l(e):{};return r.collection="$metadata",r.functionName=dn,e?.addAnnotations&&(a.boolParameterCheck(e.addAnnotations,Go,"request.addAnnotations"),r.includeAnnotations="*"),(await t.makeRequest(r))?.data}d();f();h();function H(e,t,r){return e&&(r?.escapeSpecialCharacters===!0&&(e.search=Rt(e.search)),e.entities?.length&&(e.entities=Xo(e.entities,r?.version)),t==="query"?Ko(e,r?.version):zo(e,r?.version),e)}function Xo(e,t="1.0"){if(!e)return e;if(typeof e=="string"){if(t!=="1.0")return e;try{e=JSON.parse(e)}catch{throw new Error("The 'query.entities' property must be a valid JSON string.")}if(!Array.isArray(e))throw new Error("The 'query.entities' property must be an array of strings or objects.")}let r=i=>typeof i=="string"?i:i.name,o=i=>typeof i=="string"?{name:i}:i,n=e.map(i=>t==="1.0"?r(i):o(i));return t!=="1.0"?JSON.stringify(n):n}function Ko(e,t="1.0"){t==="1.0"?(n=>{if(n.count!=null&&(n.returnTotalRecordCount==null&&(n.returnTotalRecordCount=n.count),delete n.count),n.options){if(typeof n.options=="string")try{n.options=JSON.parse(n.options,Yo)}catch{throw new Error("The 'query.options' property must be a valid JSON string.")}n.searchMode||(n.searchMode=n.options.searchMode),n.searchType||(n.searchType=n.options.queryType==="lucene"?"full":n.options.queryType),delete n.options}for(let i of Jo)if(n[i]&&typeof n[i]=="string")try{n[i]=JSON.parse(n[i])}catch{throw new Error(`The 'query.${i}' property must be a valid JSON string.`)}})(e):(n=>{n.returnTotalRecordCount!=null&&(n.count==null&&(n.count=n.returnTotalRecordCount),delete n.returnTotalRecordCount),(n.searchMode||n.searchType)&&(typeof n.options!="string"&&(n.options||(n.options={}),n.options.searchMode||(n.options.searchMode=n.searchMode),n.options.queryType||(n.options.queryType=n.searchType==="full"?"lucene":n.searchType)),delete n.searchMode,delete n.searchType),n.orderBy&&typeof n.orderBy!="string"&&(n.orderby=JSON.stringify(n.orderBy),delete n.orderBy),n.facets&&typeof n.facets!="string"&&(n.facets=JSON.stringify(n.facets)),n.options&&typeof n.options!="string"&&(n.options=JSON.stringify(Rn(n.options)))})(e)}function zo(e,t="1.0"){t==="1.0"?(n=>{if(n.fuzzy!=null&&(n.useFuzzy==null&&(n.useFuzzy=n.fuzzy),delete n.fuzzy),delete n.options,n.orderBy&&typeof n.orderBy=="string")try{n.orderBy=JSON.parse(n.orderBy)}catch{throw new Error("The 'query.orderBy' property must be a valid JSON string.")}})(e):(n=>{n.useFuzzy!=null&&(n.fuzzy==null&&(n.fuzzy=n.useFuzzy),delete n.useFuzzy),n.orderBy&&typeof n.orderBy!="string"&&(n.orderby=JSON.stringify(n.orderBy),delete n.orderBy),n.options&&typeof n.options!="string"&&(n.options=JSON.stringify(Rn(n.options)))})(e)}function Rn(e){let t={};for(let r in e)t[r.toLowerCase()]=e[r];return t}function Yo(e,t){switch(e){case"searchmode":this.searchMode=t;break;case"querytype":this.queryType=t;break;default:return t}}var Jo=["orderBy","facets"];function gn(e,t){if(!e)return e;let r=()=>{let n=JSON.parse(e.response,S),i={...e,response:n};return t.enableSearchApiResponseCompatibility&&(i.value=n.Value,i.facets=n.Facets,i.totalrecordcount=n.Count,i.querycontext=n.QueryContext),i},o=()=>{let n={...e};return t.enableSearchApiResponseCompatibility&&(n.response={Count:e.totalrecordcount,Value:e.value,Facets:e.facets,QueryContext:e.querycontext,Error:null}),n};return t?.version==="2.0"?r():o()}var We="query",ge=`${p}.${We}`;async function Ve(e,t){a.parameterCheck(e,ge,"request");let r=typeof e!="string",o=r?"request.query.search":"term",n=r?T(e):{query:{search:e}};a.parameterCheck(n.query,ge,"request.query"),a.stringParameterCheck(n.query.search,ge,o),a.maxLengthStringParameterCheck(n.query.search,ge,o,100),n.collection="query",n.functionName=We,n.method="POST",n.data=H(n.query,We,t.config.searchApi),n.apiConfig=t.config.searchApi,delete n.query;let i=await t.makeRequest(n);return gn(i.data,t.config.searchApi)}d();f();function hn(e,t){if(!e)return e;let r=()=>{let n=JSON.parse(e.response,S);t.enableSearchApiResponseCompatibility&&n.Value?.forEach(c=>{c.document=c.Document,c.text=c.Text});let i={...e,response:n};return t.enableSearchApiResponseCompatibility&&(i.value=n.Value,i.querycontext=n.QueryContext),i},o=()=>{t.enableSearchApiResponseCompatibility&&e.value?.forEach(i=>{i.Document=i.document,i.Text=i.text});let n={...e};return t.enableSearchApiResponseCompatibility&&(n.response={Value:e.value,QueryContext:e.querycontext,Error:null}),n};return t?.version==="2.0"?r():o()}var Ge="suggest",he=`${p}.${Ge}`;async function Cn(e,t){a.parameterCheck(e,he,"request");let r=typeof e!="string",o=r?"request.query.search":"term",n=r?T(e):{query:{search:e}};a.parameterCheck(n.query,he,"request.query"),a.stringParameterCheck(n.query.search,he,o),a.maxLengthStringParameterCheck(n.query.search,he,o,100),n.functionName=n.collection=Ge,n.method="POST",n.data=H(n.query,Ge,t.config.searchApi),n.apiConfig=t.config.searchApi,delete n.query;let i=await t.makeRequest(n);return hn(i.data,t.config.searchApi)}d();f();function An(e,t){if(!e)return e;let r=()=>{let n=JSON.parse(e.response,S),i={...e,response:n};return t.enableSearchApiResponseCompatibility&&(i.value=n.Value,i.querycontext=n.QueryContext),i},o=()=>{let n={...e};return t.enabl