dynamics-web-api
Version:
DynamicsWebApi is a Microsoft Dataverse Web API helper library
13 lines • 53.4 kB
JavaScript
/*! dynamics-web-api v2.3.2 (c) 2025 Aleksandr Rogov. License: MIT */
"use strict";var _dynamicsWebApiExports=(()=>{var Ce=Object.defineProperty;var Pn=Object.getOwnPropertyDescriptor;var Dn=Object.getOwnPropertyNames;var In=Object.prototype.hasOwnProperty;var ze=e=>{throw TypeError(e)};var b=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ye=(e,t)=>{for(var r in t)Ce(e,r,{get:t[r],enumerable:!0})},kn=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Dn(t))!In.call(e,n)&&n!==r&&Ce(e,n,{get:()=>t[n],enumerable:!(o=Pn(t,n))||o.enumerable});return e};var Je=e=>kn(Ce({},"__esModule",{value:!0}),e);var je=(e,t,r)=>t.has(e)||ze("Cannot "+r);var m=(e,t,r)=>(je(e,t,"read from private field"),r?r.call(e):t.get(e)),B=(e,t,r)=>t.has(e)?ze("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),L=(e,t,r,o)=>(je(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);function Ze(){return window.crypto}var et=b(()=>{"use strict"});function tt(e){return!!Sn.exec(e)}function V(e){let t=On.exec(e);return t?t[1]:null}function Z(e){if(!e)return null;let t=Mn.exec(e);return t?t[1]:null}function Ae(e){return e.replace(Un,(t,r)=>r)}function rt(e){return e.split($n).map((r,o)=>o%2===0?Ae(r):r).join("")}function nt(e){let t=_n.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}function ot(e){let t=wn.exec(e);if(!t)return null;let r=parseInt(t[2],10),o=Fn(t[1]);return{page:r,sanitizedCookie:o}}function Fn(e){let t={"<":"<",">":">",'"':""","'":"'"};return e.replace(Bn,r=>t[r])}function at(e){return e.replace(qn,"")}function it(e){return e.replace(Hn,t=>`\\u${("0000"+t.charCodeAt(0).toString(16)).slice(-4)}`)}function Ee(e){return e.replace(Qn,"")}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,Sn,On,Mn,Un,_n,$n,wn,Bn,qn,Hn,Qn,st,xe,pt,ct,lt,ee,be,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}",Sn=new RegExp(W,"i"),On=new RegExp("^{?("+W+")}?$","i"),Mn=new RegExp("("+W+")\\)$","i"),Un=new RegExp(`{(${W})}`,"g"),_n=new RegExp(`\\/(\\w+)\\((${W})`,"i");$n=/(["'].*?["'])/;wn=/pagingcookie="(<cookie page="(\d+)".+<\/cookie>)/,Bn=/[<>"']/g;qn=/^\//;Hn=/[\u007F-\uFFFF]/g;Qn=/"/g;st=/^([^()<>@,;:\\"\/[\]?={} \t]+)\s?:\s?(.*)/,xe=/HTTP\/?\s*[\d.]*\s+(\d{3})\s+([\w\s]*)$/m,pt=/Content-Type: text\/plain/i,ct=/OData-EntityId.+/i,lt=/\w+$/g,ee=/\r?\n/,be=/(\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")&&!tt(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 s=e[n];if(s==null)return;s=Gn(s);let p=i+1;r.push(`${n}=@p${p}`),o.push(`@p${p}=${V(s)||s}`)}),{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=ot(e);return{cookie:r?.sanitizedCookie||"",page:r?.page||t,nextPage:r?.page?r.page+1:t+1}}function R(e){return typeof e>"u"||e==null}function O(){return Ze().randomUUID()}function Kn(){if(typeof GetGlobalContext<"u")return GetGlobalContext();if(typeof Xrm<"u"){if(!R(Xrm.Utility)&&!R(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!R(Xrm.Page)&&!R(Xrm.Page.context))return Xrm.Page.context}throw new Error("Xrm Context is not available. In most cases, it can be resolved by adding a reference to a ClientGlobalContext.js.aspx. Please refer to MSDN documentation for more details.")}function Et(){let t=Kn().getClientUrl();return t.match(/\/$/)&&(t=t.substring(0,t.length-1)),t}function te(){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 s=0;s<n;s++)i[s]=t[o+s];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}var Te,d=b(()=>{"use strict";et();h();Te=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,u=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 s=0;s<i.length;s++)i[s]=i[s].trim().replace(/"/g,"'"),/^[\w\d\_]+\=(.+)$/i.exec(i[s])[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,re,k,Nt=b(()=>{"use strict";re=class re{};re.Prefer=(X=class{static get(t){return`${re.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=re});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 Ne=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,ee)}function no(e,t,r){let o=t.position||0,n=e.slice(o),i=r.exec(n);if(!i)return null;let s=o+i.index;return t.position=s+i[0].length,e.substring(o,s)}function oo(e){let t=xe.exec(e);return{httpStatusString:t[0],httpStatus:parseInt(t[1]),httpStatusMessage:t[2].trim()}}function ao(e){xe.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 ke(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),s=e.substring(e.indexOf("{"),e.lastIndexOf("}")+1);if(!s)return pt.test(e)?io(e,t,r):so(e,t,r);let p=Ie(s,t,r);if(n<400)return p;let E=to(e.substring(e.indexOf(o)+o.length+1,e.indexOf("{")));return a.handleHttpError(p,{status:n,statusText:i,statusMessage:i,headers:E})}function Pe(e,t,r=0){let o=e.substring(0,e.search(ee)),n=e.split(o);n.shift(),n.pop();let i=[];for(let s of n){if(s.indexOf("--changesetresponse_")===-1){i.push(po(s,t,r++));continue}s=s.trim();let p=s.substring(s.search(ee)+1).trim();i=i.concat(Pe(p,t,r++))}return i}var De=b(()=>{"use strict";u();h();ne()});function Se(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 Oe(e,t){if(t){if(t.isRef&&e["@odata.id"]!=null)return nt(e);if(t.toCount)return Se("@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]=Oe(e[o][r]);else typeof e[o]=="object"&&Oe(e[o]);let n=Se(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=Se(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=Pe(e,t);return t?.[0].convertedToBatch?r[0]:r}function Ro(e,t,r){return lo(e,t,r[0])}function Ie(e,t,r=0){return Oe(JSON.parse(e,S),t[r])}function ke(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 Me(e,t,r){return e.length?mo(e)?yo(e,r):uo(t)?Ro(e,t,r):fo(t)?Ie(e,r):ke(e):go(t,r)}var ne=b(()=>{"use strict";Nt();d();Ne();h();De()});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],s=i.indexOf(": ");s>0&&(t[i.substring(0,s)]=i.substring(s+2))}return t}var Ue=b(()=>{"use strict"});var Pt={};Ye(Pt,{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,s=e.abortSignal;if(s?.aborted){r(a.handleHttpError({name:"AbortError",code:20,message:"The user aborted a request."}));return}let p=new XMLHttpRequest;p.open(e.method,e.uri,e.isAsync||!1);for(let y in n)p.setRequestHeader(y,n[y]);p.onreadystatechange=function(){if(p.readyState===4){if(s&&s.removeEventListener("abort",E),!p||p.status===0)return;if(p.status>=200&&p.status<300||p.status===304){let y=U(p.getAllResponseHeaders()),x={data:Me(p.responseText,y,i[e.requestId]),headers:y,status:p.status};p=null,t(x)}else{let y,A;try{A=U(p.getAllResponseHeaders());let j=Me(p.responseText,A,i[e.requestId]);if(Array.isArray(j)){r(j);return}y=j.error}catch{p.response.length>0?y={message:p.response}:y={message:"Unexpected Error"}}let x={status:p.status,statusText:p.statusText,headers:A};p=null,r(a.handleHttpError(y,x))}}},e.timeout&&(p.timeout=e.timeout),p.onerror=function(){let y=U(p.getAllResponseHeaders());r(a.handleHttpError({status:p.status,statusText:p.statusText,message:p.responseText||"Network Error",headers:y})),p=null},p.ontimeout=function(){let y=U(p.getAllResponseHeaders());r(a.handleHttpError({name:"TimeoutError",status:p.status,statusText:p.statusText,message:p.responseText||"Request Timed Out",headers:y})),p=null},p.onabort=function(){if(!p)return;let y=U(p.getAllResponseHeaders());r(a.handleHttpError({status:p.status,statusText:p.statusText,message:"Request aborted",headers:y})),p=null};let E=()=>{if(!p)return;let y=U(p.getAllResponseHeaders());r(a.handleHttpError({name:"AbortError",code:20,status:p.status,statusText:p.statusText,message:"The user aborted a request.",headers:y})),p.abort(),p=null};s&&s.addEventListener("abort",E),o?p.send(o):p.send(),K.afterSendEvent&&K.afterSendEvent()}var K,Dt=b(()=>{"use strict";u();ne();Ue();K=class{}});var Jo={};Ye(Jo,{DynamicsWebApi:()=>Xe});d();u();var c="DynamicsWebApi";var g=`${c}.setConfig`,Yn=["dataApi","searchApi","serviceApi"],Jn=(e,t)=>{if(te())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,g,"config.searchApi.options.escapeSpecialCharacters"),e.escapeSpecialCharacters=t.escapeSpecialCharacters),t.enableResponseCompatibility!=null&&(a.boolParameterCheck(t.enableResponseCompatibility,g,"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,g,`config.${t}.version`),o.version=n.version),n?.path&&(a.stringParameterCheck(n.path,g,`config.${t}.path`),o.path=n.path),t==="searchApi"&&jn(o,n?.options),o.url=Jn(e.serverUrl,o)};function ve(e,t){t?.serverUrl&&(a.stringParameterCheck(t.serverUrl,g,"config.serverUrl"),e.serverUrl=t.serverUrl),Yn.forEach(r=>{Zn(e,r,t)}),t?.impersonate&&(e.impersonate=a.guidParameterCheck(t.impersonate,g,"config.impersonate")),t?.impersonateAAD&&(e.impersonateAAD=a.guidParameterCheck(t.impersonateAAD,g,"config.impersonateAAD")),t?.onTokenRefresh&&(a.callbackParameterCheck(t.onTokenRefresh,g,"config.onTokenRefresh"),e.onTokenRefresh=t.onTokenRefresh),t?.includeAnnotations&&(a.stringParameterCheck(t.includeAnnotations,g,"config.includeAnnotations"),e.includeAnnotations=t.includeAnnotations),t?.timeout&&(a.numberParameterCheck(t.timeout,g,"config.timeout"),e.timeout=t.timeout),t?.maxPageSize&&(a.numberParameterCheck(t.maxPageSize,g,"config.maxPageSize"),e.maxPageSize=t.maxPageSize),t?.returnRepresentation!=null&&(a.boolParameterCheck(t.returnRepresentation,g,"config.returnRepresentation"),e.returnRepresentation=t.returnRepresentation),t?.useEntityNames!=null&&(a.boolParameterCheck(t.useEntityNames,g,"config.useEntityNames"),e.useEntityNames=t.useEntityNames),t?.headers&&(e.headers=t.headers)}function Tt(){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,vt=e=>{I=e},F=e=>{if(R(I))return null;let t=I[e];if(!t){for(let r in I)if(I[r]===e)return e}return t};async function It(e){return(Dt(),Je(Pt)).executeRequest(e)}u();u();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=rt(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))),R(e.inChangeSet)||a.boolParameterCheck(e.inChangeSet,`DynamicsWebApi.${e.functionName}`,"request.inChangeSet"),e.isBatch&&R(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:s,...p}of e.expand){if(!s)continue;let E={functionName:`${e.functionName} $expand`,...p},y=_e(E,t,"",";");y&&(y=`(${y})`),i.push(s+y)}i.length&&n.push("$expand="+i.join(","))}}return n.length?(o==="&"&&(r+="?"),r+n.join(o)):r};u();u();h();var kt=(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 s of i){let p=s.trim();p.includes("respond-async")?o.respondAsync=!0:p.startsWith("odata.callback")?o.backgroundOperationCallbackUrl=gt(p):p==="return=representation"?o.returnRepresentation=!0:p.includes("odata.include-annotations=")?o.includeAnnotations=Ee(p.replace("odata.include-annotations=","")):p.startsWith("odata.maxpagesize=")?o.maxPageSize=Number(Ee(p.replace("odata.maxpagesize=","")))||0:p.includes("odata.track-changes")?o.trackChanges=!0:p.includes("odata.continue-on-error")?o.continueOnError=!0:n.add(p)}}for(let i in o){let s=Ao[i];s&&o[i]&&(s.validator?.(o[i],r,`request.${i}`),s.condition(o[i],o)&&n.add(s.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 St=(e,t)=>{let r={...t.headers,...e.userHeaders},o=kt(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};u();var oe=(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=St(e,t),e);h();d();Ne();De();ne();Ue();var ae=(e,t)=>{if(!e)return null;if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint32Array)return e;let r=i=>{let s=be.exec(i);if(s&&s.length>2){let p=F(s[1]);if(!R(p))return i.replace(be,`${p}$2`)}return i},o=(i,s)=>(s.startsWith(t.dataApi.url)||(i.endsWith("@odata.bind")?s.startsWith("/")||(s=`/${s}`):s=`${t.dataApi.url}${at(s)}`),s),n=JSON.stringify(e,(i,s)=>{if(i.endsWith("@odata.bind")||i.endsWith("@odata.id"))typeof s=="string"&&!s.startsWith("$")&&(s=Ae(s),t.useEntityNames&&(s=r(s)),s=o(i,s));else if(i.startsWith("oData")||i.endsWith("_Formatted")||i.endsWith("_NavigationProperty")||i.endsWith("_LogicalName"))return;return s});return it(n)};var ie=(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 $e=(e,t,r)=>{let o=`dwa_batch_${O()}`,n=[],i=null,s=1e5,p=(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,s=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"]:++s;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&&p(y.headers,n),y.data&&n.push(`\r
${ae(y.data,t)}`)}),i&&n.push(`\r
--${i}--`),n.push(`\r
--${o}--\r
`);let E=ie(r?.userHeaders,r?.data);return E["Content-Type"]=`multipart/mixed;boundary=${o}`,{headers:E,body:n.join(`\r
`)}};var Ot=(e,t)=>{z[e]?z[e].push(t):z[e]=[t]},Eo=(e,t)=>{_[e]?_[e].push(t):_[e]=[t]},we=e=>{delete z[e],_.hasOwnProperty(e)&&delete _[e]},Mt=async(e,t)=>{try{let r=await No(e,t);return we(e.requestId),r}catch(r){throw we(e.requestId),r}finally{we(e.requestId)}},_={},z={},xo=["$metadata","EntityDefinitions","RelationshipDefinitions","GlobalOptionSetDefinitions","ManagedPropertyDefinitions","query","suggest","autocomplete"],bo=e=>xo.indexOf(e)>-1,To=async(e,t)=>{if(!R(I))return F(e)||e;let r=oe({method:"GET",collection:"EntityDefinitions",select:["EntitySetName","LogicalName"],noCache:!0,functionName:"retrieveMultiple"},t),o=await Mt(r,t);vt({});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},vo=async(e,t)=>{if(!e||bo(e)||(e=e.toLowerCase(),!t.useEntityNames))return e;try{return await To(e,t)}catch(r){throw new Error("Unable to fetch Collection Names. Error: "+r.message)}},No=async(e,t)=>{e.headers=e.headers||{},e.responseParameters=e.responseParameters||{},e.requestId=e.requestId||O(),Ot(e.requestId,e.responseParameters);let r=null,o=e.responseParameters?.convertedToBatch;if(e.path==="$batch"&&!o){let s=_[e.requestId];if(!s)throw a.batchIsEmpty();let p=$e(s,t,e);r=p.body,e.headers={...p.headers,...e.headers},delete _[e.requestId]}else r=o?e.data:ae(e.data,t),!o&&e.includeDefaultDataverseHeaders!==!1&&(e.headers=ie(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)),te()&&(e.headers.__RequestVerificationToken=await window.shell.getTokenDeferred());let i=e.apiConfig?e.apiConfig.url:t.dataApi.url;return await It({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})},Ut=async(e,t)=>{if(e.responseParameters=e.responseParameters||{},e.userHeaders=e.headers,delete e.headers,!e.isBatch){let r=await vo(e.collection,t);if(e.collection=r,oe(e,t),e.responseParameters.convertedToBatch=!1,e.path.length>2e3){let o=$e([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 Mt(e,t)}oe(e,t),Ot(e.requestId,e.responseParameters),Eo(e.requestId,e)};var _t=e=>F(e);var $,q,w,se=class{constructor(t){B(this,$,Tt());B(this,q,!1);B(this,w,null);this.setConfig=t=>ve(m(this,$),t);this.makeRequest=t=>(t.isBatch=m(this,q),m(this,w)&&(t.requestId=m(this,w)),Ut(t,m(this,$)));ve(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;u();d();var $t="associate",Y=`${c}.${$t}`,wt=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=`${e.relatedCollection}(${r})`);let n=l(e,["primaryKey"]);n.method="POST",n.functionName=$t,n.navigationProperty=e.relationshipName+"/$ref",n.key=e.primaryKey,n.data={"@odata.id":o},await t.makeRequest(n)};u();d();var Bt="associateSingleValued",J=`${c}.${Bt}`,Ft=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=`${e.relatedCollection}(${r})`);let n=l(e,["primaryKey"]);n.method="PUT",n.functionName=Bt,n.navigationProperty+="/$ref",n.key=e.primaryKey,n.data={"@odata.id":o},await t.makeRequest(n)};u();d();var Ht="callAction",qt=`${c}.${Ht}`,Qt=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};u();d();var Wt="callFunction",Lt=`${c}.${Wt}`,Vt=async(e,t)=>{a.parameterCheck(e,Lt,"request");let r=y=>y.name||y.functionName,o=typeof e!="string",n=o?r(e):e,i=o?"request.name":"name",s=o?T(e,["name"]):{functionName:n};a.stringParameterCheck(n,Lt,i);let p=Ct(s.parameters);return s.method="GET",s.addPath=n+p.key,s.queryParams=p.queryParams,s._isUnboundRequest=!s.collection,s.functionName=Wt,(await t.makeRequest(s))?.data};u();d();var Gt="create",Po=`${c}.${Gt}`,v=async(e,t)=>{a.parameterCheck(e,Po,"request");let r;return e.functionName?r=e:(r=l(e),r.functionName=Gt),r.method="POST",(await t.makeRequest(r))?.data};u();d();var Xt="count",Do=`${c}.${Xt}`,Kt=async(e,t)=>{a.parameterCheck(e,Do,"request");let r=l(e);return r.method="GET",r.functionName=Xt,r.filter?.length?r.count=!0:r.navigationProperty="$count",r.responseParameters={toCount:r.count},(await t.makeRequest(r))?.data};u();u();u();d();var Yt="retrieveMultiple",zt=`${c}.${Yt}`,C=async(e,t,r)=>{a.parameterCheck(e,zt,"request");let o;return e.functionName?o=e:(o=l(e),o.functionName=Yt),o.method="GET",r&&(a.stringParameterCheck(r,zt,"nextPageLink"),o.url=r),(await t.makeRequest(o))?.data};var Io="retrieveAll",ko=`${c}.${Io}`,pe=async(e,t,r,o=[])=>{let n=await C(e,t,r);o=o.concat(n.value);let i=n.oDataNextLink;if(i)return pe(e,t,i,o);let s={value:o};return n.oDataDeltaLink&&(s["@odata.deltaLink"]=n.oDataDeltaLink,s.oDataDeltaLink=n.oDataDeltaLink),s},Be=(e,t)=>(a.throwBatchIncompatible(ko,t.isBatch),pe(e,t));var So="countAll",Jt=`${c}.${So}`,jt=async(e,t)=>(a.throwBatchIncompatible(Jt,t.isBatch),a.parameterCheck(e,Jt,"request"),(await pe(e,t)).value.length);u();d();var Zt="disassociate",ce=`${c}.${Zt}`,er=async(e,t)=>{a.parameterCheck(e,ce,"request");let r=l(e);r.method="DELETE",r.functionName=Zt,a.stringParameterCheck(e.relationshipName,ce,"request.relationshipName");let o=a.keyParameterCheck(e.primaryKey,ce,"request.primaryKey"),n=a.keyParameterCheck(e.relatedKey,ce,"request.relatedId");r.key=o,r.navigationProperty=`${e.relationshipName}(${n})/$ref`,await t.makeRequest(r)};u();d();var tr="disassociateSingleValued",Fe=`${c}.${tr}`,rr=async(e,t)=>{a.parameterCheck(e,Fe,"request");let r=l(e);r.method="DELETE",r.functionName=tr,a.stringParameterCheck(e.navigationProperty,Fe,"request.navigationProperty");let o=a.keyParameterCheck(e.primaryKey,Fe,"request.primaryKey");r.navigationProperty+="/$ref",r.key=o,await t.makeRequest(r)};u();d();var nr="retrieve",Oo=`${c}.${nr}`,N=async(e,t)=>{a.parameterCheck(e,Oo,"request");let r;return e.functionName?r=e:(r=l(e),r.functionName=nr),r.method="GET",r.responseParameters={isRef:r.select?.length===1&&r.select[0].endsWith("/$ref")},(await t.makeRequest(r))?.data};u();h();d();var or="fetch",le=`${c}.${or}`,me=async(e,t)=>{a.parameterCheck(e,le,"request");let r=l(e);if(r.method="GET",r.functionName=or,a.stringParameterCheck(r.fetchXml,le,"request.fetchXml"),r.fetchXml&&!ut.test(r.fetchXml)){let n="";ft.test(r.fetchXml)||(r.pageNumber=r.pageNumber||1,a.numberParameterCheck(r.pageNumber,le,"request.pageNumber"),n=`$1 page="${r.pageNumber}"`),r.pagingCookie!=null&&(a.stringParameterCheck(r.pagingCookie,le,"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};u();var Mo="fetchAll",ar=`${c}.${Mo}`,ir=async(e,t,r=[])=>{let o=await me(e,t);return r=r.concat(o.value),o.PagingInfo?(e.pageNumber=o.PagingInfo.nextPage,e.pagingCookie=o.PagingInfo.cookie,ir(e,t,r)):{value:r}},sr=async(e,t)=>(a.parameterCheck(e,ar,"request"),a.throwBatchIncompatible(ar,t.isBatch),ir(e,t));u();h();d();var pr="update",Uo=`${c}.${pr}`,P=async(e,t)=>{a.parameterCheck(e,Uo,"request");let r;e.functionName?r=e:(r=l(e),r.functionName=pr),r.method??(r.method=mt(r.collection)),r.responseParameters={valueIfEmpty:!0},r.ifmatch??(r.ifmatch="*");let o=r.ifmatch;try{return(await t.makeRequest(r))?.data}catch(n){if(o&&n.status===412)return!1;throw n}};u();d();var lr="updateSingleProperty",cr=`${c}.${lr}`,mr=async(e,t)=>{a.parameterCheck(e,cr,"request"),a.parameterCheck(e.fieldValuePair,cr,"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=lr,n.method="PUT",delete n.fieldValuePair,(await t.makeRequest(n))?.data};u();d();var ur="upsert",_o=`${c}.${ur}`,fr=async(e,t)=>{a.parameterCheck(e,_o,"request");let r=l(e);r.method="PATCH",r.functionName=ur;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}};u();d();var dr="deleteRecord",$o=`${c}.${dr}`,H=async(e,t)=>{a.parameterCheck(e,$o,"request");let r;e.functionName?r=e:(r=l(e),r.functionName=dr),r.method="DELETE",r.responseParameters={valueIfEmpty:!0};let o=r.ifmatch;try{return(await t.makeRequest(r))?.data}catch(n){if(o&&n.status===412)return!1;throw n}};u();d();var Rr="uploadFile",yr=`${c}.${Rr}`,gr=async(e,t,r,o,n=0)=>{if(xt(e,r,o,n),await t.makeRequest(e),n+=o,n<=r.length)return gr(e,t,r,o,n)},hr=async(e,t)=>{a.throwBatchIncompatible(yr,t.isBatch),a.parameterCheck(e,yr,"request");let r=l(e,["data"]);r.method="PATCH",r.functionName=Rr,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,gr(r,t,e.data,o?.data.chunkSize)};u();d();var Ar="downloadFile",Cr=`${c}.${Ar}`,Er=async(e,t,r=0,o="")=>{e.range="bytes="+r+"-"+(r+Te-1),e.downloadSize="full";let n=await t.makeRequest(e);return e.url=n?.data.location,o+=n?.data.value,r+=Te,r<=n?.data.fileSize?Er(e,t,r,o):{fileName:n?.data.fileName,fileSize:n?.data.fileSize,data:bt(o)}},xr=(e,t)=>{a.throwBatchIncompatible(Cr,t.isBatch),a.parameterCheck(e,Cr,"request");let r=l(e);return r.method="GET",r.functionName=Ar,r.responseParameters={parse:!0},Er(r,t)};d();u();var wo="executeBatch",Bo=`${c}.${wo}`;async function br(e,t){a.throwBatchNotStarted(t.isBatch);let r=e?l(e):{};return r.collection="$batch",r.method="POST",r.functionName=Bo,r.requestId=t.batchRequestId,t.batchRequestId=null,t.isBatch=!1,(await t.makeRequest(r))?.data}function Tr(e){e.isBatch=!0,e.batchRequestId=O()}u();d();var Nr="createEntity",vr=`${c}.${Nr}`,Pr=async(e,t)=>{a.parameterCheck(e,vr,"request"),a.parameterCheck(e.data,vr,"request.data");let r=l(e);return r.collection="EntityDefinitions",r.functionName=Nr,v(r,t)};u();d();var Ir="updateEntity",Dr=`${c}.${Ir}`,kr=async(e,t)=>{a.parameterCheck(e,Dr,"request"),a.parameterCheck(e.data,Dr,"request.data");let r=l(e);return r.collection="EntityDefinitions",r.functionName=Ir,r.key=r.data.MetadataId,r.method="PUT",await P(r,t)};u();d();var Fo="retrieveEntity",Sr=`${c}.${Fo}`,Or=async(e,t)=>{a.parameterCheck(e,Sr,"request"),a.keyParameterCheck(e.key,Sr,"request.key");let r=l(e);return r.collection="EntityDefinitions",r.functionName="retrieveEntity",await N(r,t)};d();var qo="retrieveEntities",Mr=(e,t)=>{let r=t?l(t):{};return r.collection="EntityDefinitions",r.functionName=qo,C(r,e)};d();u();var Ur="createAttribute",qe=`${c}.${Ur}`,_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=Ur,r.navigationProperty="Attributes",r.key=e.entityKey,v(r,t)};d();u();var $r="updateAttribute",ue=`${c}.${$r}`,wr=(e,t)=>{a.parameterCheck(e,ue,"request"),a.parameterCheck(e.data,ue,"request.data"),a.keyParameterCheck(e.entityKey,ue,"request.entityKey"),a.guidParameterCheck(e.data.MetadataId,ue,"request.data.MetadataId");let r=l(e);return r.collection="EntityDefinitions",r.functionName=$r,r.navigationProperty="Attributes",r.navigationPropertyKey=e.data.MetadataId,r.metadataAttributeType=e.castType,r.key=e.entityKey,r.method="PUT",P(r,t)};d();u();var Br="retrieveAttributes",He=`${c}.${Br}`,Fr=(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=Br,r.navigationProperty="Attributes",r.key=e.entityKey,r.metadataAttributeType=e.castType,C(r,t)};d();u();var qr="retrieveAttributes",fe=`${c}.${qr}`,Hr=(e,t)=>{a.parameterCheck(e,fe,"request"),a.keyParameterCheck(e.entityKey,fe,"request.entityKey"),a.keyParameterCheck(e.attributeKey,fe,"request.attributeKey"),e.castType&&a.stringParameterCheck(e.castType,fe,"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();u();var Lr="createRelationship",Qr=`${c}.${Lr}`,Wr=(e,t)=>{a.parameterCheck(e,Qr,"request"),a.parameterCheck(e.data,Qr,"request.data");let r=l(e);return r.collection="RelationshipDefinitions",r.functionName=Lr,v(r,t)};d();u();var Vr="updateRelationship",de=`${c}.${Vr}`;function Gr(e,t){a.parameterCheck(e,de,"request"),a.parameterCheck(e.data,de,"request.data"),a.guidParameterCheck(e.data.MetadataId,de,"request.data.MetadataId"),e.castType&&a.stringParameterCheck(e.castType,de,"request.castType");let r=l(e);return r.collection="RelationshipDefinitions",r.key=e.data.MetadataId,r.navigationProperty=e.castType,r.functionName=Vr,r.method="PUT",P(r,t)}d();u();var Kr="deleteRelationship",Xr=`${c}.${Kr}`;async function zr(e,t){a.parameterCheck(e,Xr,"request"),a.keyParameterCheck(e.key,Xr,"request.key");let r=l(e);return r.collection="RelationshipDefinitions",r.functionName=Kr,H(r,t)}d();u();var Yr="retrieveRelationships",Ho=`DynamicsWebApi.${Yr}`;async function Jr(e,t){let r=e?l(e):{};return r.collection="RelationshipDefinitions",r.functionName=Yr,e&&e.castType&&(a.stringParameterCheck(e.castType,Ho,"request.castType"),r.navigationProperty=e.castType),C(r,t)}d();u();var jr="retrieveRelationship",Qe=`DynamicsWebApi.${jr}`;async function Zr(e,t){a.parameterCheck(e,Qe,"request"),a.keyParameterCheck(e.key,Qe,"request.key"),e.castType&&a.stringParameterCheck(e.castType,Qe,"request.castType");let r=l(e);return r.collection="RelationshipDefinitions",r.navigationProperty=e.castType,r.functionName=jr,N(r,t)}d();u();var tn="createGlobalOptionSet",en=`DynamicsWebApi.${tn}`;async function rn(e,t){a.parameterCheck(e,en,"request"),a.parameterCheck(e.data,en,"request.data");let r=l(e);return r.collection="GlobalOptionSetDefinitions",r.functionName=tn,v(r,t)}d();u();var nn="updateGlobalOptionSet",ye=`DynamicsWebApi.${nn}`;async function on(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="GlobalOptionSetDefinitions",r.key=e.data.MetadataId,r.functionName=nn,r.method="PUT",P(r,t)}d();u();var an="deleteGlobalOptionSet",Qo=`DynamicsWebApi.${an}`;async function sn(e,t){a.parameterCheck(e,Qo,"request");let r=l(e);return r.collection="GlobalOptionSetDefinitions",r.functionName=an,H(r,t)}d();u();var cn="retrieveGlobalOptionSet",pn=`DynamicsWebApi.${cn}`;async function ln(e,t){a.parameterCheck(e,pn,"request"),e.castType&&a.stringParameterCheck(e.castType,pn,"request.castType");let r=l(e);return r.collection="GlobalOptionSetDefinitions",r.navigationProperty=e.castType,r.functionName=cn,N(r,t)}d();u();var mn="retrieveGlobalOptionSets",Lo=`DynamicsWebApi.${mn}`;async function un(e,t){let r=e?l(e):{};return r.collection="GlobalOptionSetDefinitions",r.functionName=mn,e?.castType&&(a.stringParameterCheck(e.castType,Lo,"request.castType"),r.navigationProperty=e.castType),C(r,t)}d();u();var fn="retrieveCsdlMetadata",Wo=`DynamicsWebApi.${fn}`;async function dn(e,t){let r=e?l(e):{};return r.collection="$metadata",r.functionName=fn,e?.addAnnotations&&(a.boolParameterCheck(e.addAnnotations,Wo,"request.addAnnotations"),r.includeAnnotations="*"),(await t.makeRequest(r))?.data}d();u();h();function Q(e,t,r){if(!e)return e;switch(r?.escapeSpecialCharacters===!0&&(e.search=Rt(e.search)),e.entities?.length&&(e.entities=Vo(e.entities,r?.version)),t){case"query":Go(e,r?.version);break;default:Xo(e,r?.version);break}return e}function Vo(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 Go(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,Ko)}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 zo)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(yn(n.options)))})(e)}function Xo(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(yn(n.options)))})(e)}function yn(e){let t={};for(let r in e)t[r.toLowerCase()]=e[r];return t}function Ko(e,t){switch(e){case"searchmode":this.searchMode=t;break;case"querytype":this.queryType=t;break;default:return t}}var zo=["orderBy","facets"];function Rn(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 Le="query",Re=`${c}.${Le}`;async function We(e,t){a.parameterCheck(e,Re,"request");let r=typeof e!="string",o=r?"request.query.search":"term",n=r?T(e):{query:{search:e}};a.parameterCheck(n.query,Re,"request.query"),a.stringParameterCheck(n.query.search,Re,o),a.maxLengthStringParameterCheck(n.query.search,Re,o,100),n.collection="query",n.functionName=Le,n.method="POST",n.data=Q(n.query,Le,t.config.searchApi),n.apiConfig=t.config.searchApi,delete n.query;let i=await t.makeRequest(n);return Rn(i.data,t.config.searchApi)}d();u();function gn(e,t){if(!e)return e;let r=()=>{let n=JSON.parse(e.response,S);t.enableSearchApiResponseCompatibility&&n.Value?.forEach(s=>{s.document=s.Document,s.text=s.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 Ve="suggest",ge=`${c}.${Ve}`;async function hn(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.functionName=n.collection=Ve,n.method="POST",n.data=Q(n.query,Ve,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();u();function Cn(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.enableSearchApiResponseCompatibility&&(n.response={Value:e.value,QueryContext:e.querycontext,Error:null}),n};return t?.version==="2.0"?r():o()}var Ge="autocomplete",he=`${c}.${Ge}`;async function An(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}};r&&a.parameterCheck(n.query,he,"request.query"),a.stringParameterCheck(n.query.search,he,o),a.maxLength