/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/dynamics-web-api@2.4.0/dist/cjs/dynamics-web-api.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
/*! dynamics-web-api v2.4.0 (c) 2025 Aleksandr Rogov. License: MIT */
"use strict";var import_node_crypto,__create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__typeError=e=>{throw TypeError(e)},__esm=(e,t)=>function(){return e&&(t=(0,e[__getOwnPropNames(e)[0]])(e=0)),t},__export=(e,t)=>{for(var r in t)__defProp(e,r,{get:t[r],enumerable:!0})},__copyProps=(e,t,r,a)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of __getOwnPropNames(t))__hasOwnProp.call(e,n)||n===r||__defProp(e,n,{get:()=>t[n],enumerable:!(a=__getOwnPropDesc(t,n))||a.enumerable});return e},__toESM=(e,t,r)=>(r=null!=e?__create(__getProtoOf(e)):{},__copyProps(!t&&e&&e.__esModule?r:__defProp(r,"default",{value:e,enumerable:!0}),e)),__toCommonJS=e=>__copyProps(__defProp({},"__esModule",{value:!0}),e),__accessCheck=(e,t,r)=>t.has(e)||__typeError("Cannot "+r),__privateGet=(e,t,r)=>(__accessCheck(e,t,"read from private field"),r?r.call(e):t.get(e)),__privateAdd=(e,t,r)=>t.has(e)?__typeError("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),__privateSet=(e,t,r,a)=>(__accessCheck(e,t,"write to private field"),a?a.call(e,r):t.set(e,r),r),node_exports={};function getCrypto(){return import_node_crypto.default}__export(node_exports,{getCrypto:()=>getCrypto});var init_node=__esm({"src/helpers/crypto/node.ts"(){import_node_crypto=__toESM(require("crypto"))}});function getCrypto2(){return(init_node(),__toCommonJS(node_exports)).getCrypto()}var UUID,UUID_REGEX,EXTRACT_UUID_REGEX,EXTRACT_UUID_FROM_URL_REGEX,REMOVE_BRACKETS_FROM_UUID_REGEX,ENTITY_UUID_REGEX,QUOTATION_MARK_REGEX,PAGING_COOKIE_REGEX,SPECIAL_CHARACTER_REGEX,UNICODE_SYMBOLS_REGEX,DOUBLE_QUOTE_REGEX,BATCH_RESPONSE_HEADERS_REGEX,HTTP_STATUS_REGEX,CONTENT_TYPE_PLAIN_REGEX,ODATA_ENTITYID_REGEX,TEXT_REGEX,LINE_ENDING_REGEX,SEARCH_FOR_ENTITY_NAME_REGEX,SPECIAL_COLLECTION_FOR_UPDATE_REGEX,FETCH_XML_TOP_REGEX,FETCH_XML_PAGE_REGEX,FETCH_XML_REPLACE_REGEX,DATE_FORMAT_REGEX,SEARCH_SPECIAL_CHARACTERS_REGEX,PREFER_CALLBACK_URL_REGEX,init_Crypto=__esm({"src/helpers/Crypto.ts"(){}});function isUuid(e){return!!UUID_REGEX.exec(e)}function extractUuid(e){const t=EXTRACT_UUID_REGEX.exec(e);return t?t[1]:null}function extractUuidFromUrl(e){if(!e)return null;const t=EXTRACT_UUID_FROM_URL_REGEX.exec(e);return t?t[1]:null}function removeCurlyBracketsFromUuid(e){return e.replace(REMOVE_BRACKETS_FROM_UUID_REGEX,((e,t)=>t))}function safelyRemoveCurlyBracketsFromUrl(e){return e.split(QUOTATION_MARK_REGEX).map(((e,t)=>t%2==0?removeCurlyBracketsFromUuid(e):e)).join("")}function convertToReferenceObject(e){const t=ENTITY_UUID_REGEX.exec(e["@odata.id"]);return{id:t[2],collection:t[1],oDataContext:e["@odata.context"]}}function parsePagingCookie(e){const t=PAGING_COOKIE_REGEX.exec(e);if(!t)return null;return{page:parseInt(t[2],10),sanitizedCookie:sanitizeCookie(t[1])}}function sanitizeCookie(e){const t={"<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};return e.replace(SPECIAL_CHARACTER_REGEX,(e=>t[e]))}function removeLeadingSlash(e){return e.startsWith("/")?e.slice(1):e}function escapeUnicodeSymbols(e){return e.replace(UNICODE_SYMBOLS_REGEX,(e=>`\\u${("0000"+e.charCodeAt(0).toString(16)).slice(-4)}`))}function removeDoubleQuotes(e){return e.replace(DOUBLE_QUOTE_REGEX,"")}function getUpdateMethod(e){return SPECIAL_COLLECTION_FOR_UPDATE_REGEX.test(e??"")?"PUT":"PATCH"}function escapeSearchSpecialCharacters(e){return e.replace(SEARCH_SPECIAL_CHARACTERS_REGEX,"\\$&")}function extractPreferCallbackUrl(e){const t=PREFER_CALLBACK_URL_REGEX.exec(e);return t?t[1]:null}var downloadChunkSize,init_Regex=__esm({"src/helpers/Regex.ts"(){UUID="[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}",UUID_REGEX=new RegExp(UUID,"i"),EXTRACT_UUID_REGEX=new RegExp("^{?("+UUID+")}?$","i"),EXTRACT_UUID_FROM_URL_REGEX=new RegExp("("+UUID+")\\)$","i"),REMOVE_BRACKETS_FROM_UUID_REGEX=new RegExp(`{(${UUID})}`,"g"),ENTITY_UUID_REGEX=new RegExp(`\\/(\\w+)\\((${UUID})`,"i"),QUOTATION_MARK_REGEX=/(["'].*?["'])/,PAGING_COOKIE_REGEX=/pagingcookie="(<cookie page="(\d+)".+<\/cookie>)/,SPECIAL_CHARACTER_REGEX=/[<>"']/g,UNICODE_SYMBOLS_REGEX=/[\u007F-\uFFFF]/g,DOUBLE_QUOTE_REGEX=/"/g,BATCH_RESPONSE_HEADERS_REGEX=/^([^()<>@,;:\\"\/[\]?={} \t]+)\s?:\s?(.*)/,HTTP_STATUS_REGEX=/HTTP\/?\s*[\d.]*\s+(\d{3})\s+([\w\s]*)$/m,CONTENT_TYPE_PLAIN_REGEX=/Content-Type: text\/plain/i,ODATA_ENTITYID_REGEX=/OData-EntityId.+/i,TEXT_REGEX=/\w+$/g,LINE_ENDING_REGEX=/\r?\n/,SEARCH_FOR_ENTITY_NAME_REGEX=/(\w+)(\([\d\w-]+\))$/,SPECIAL_COLLECTION_FOR_UPDATE_REGEX=/EntityDefinitions|RelationshipDefinitions|GlobalOptionSetDefinitions/,FETCH_XML_TOP_REGEX=/^<fetch.+top=/,FETCH_XML_PAGE_REGEX=/^<fetch.+page=/,FETCH_XML_REPLACE_REGEX=/^(<fetch)/,DATE_FORMAT_REGEX=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:Z|[-+]\d{2}:\d{2})$/,SEARCH_SPECIAL_CHARACTERS_REGEX=/[+\-&|!(){}[\]^"~*?:\\\/]/g,PREFER_CALLBACK_URL_REGEX=/^odata\.callback;\s*url=["']?(.+?)["']?$/}});function formatParameterValue(e){return null==e?"":"string"!=typeof e||e.startsWith("Microsoft.Dynamics.CRM")||isUuid(e)?"object"==typeof e?JSON.stringify(e):e.toString():`'${e}'`}function processParameters(e){const t=Object.keys(e),r=[],a=[];return t.forEach(((t,n)=>{let i=e[t];if(null==i)return;i=formatParameterValue(i);const o=n+1;r.push(`${t}=@p${o}`),a.push(`@p${o}=${extractUuid(i)||i}`)})),{key:`(${r.join(",")})`,queryParams:a}}function hasHeader(e,t){return e.hasOwnProperty(t)||e.hasOwnProperty(t.toLowerCase())}function getHeader(e,t){return e[t]?e[t]:e[t.toLowerCase()]}function buildFunctionParameters(e){return e?processParameters(e):{key:"()"}}function getFetchXmlPagingCookie(e="",t=1){const r=parsePagingCookie(e=decodeURIComponent(decodeURIComponent(e)));return{cookie:(null==r?void 0:r.sanitizedCookie)||"",page:(null==r?void 0:r.page)||t,nextPage:(null==r?void 0:r.page)?r.page+1:t+1}}function isNull(e){return void 0===e||null==e}function generateUUID(){return getCrypto2().randomUUID()}function getXrmContext(){if("undefined"!=typeof GetGlobalContext)return GetGlobalContext();if("undefined"!=typeof Xrm){if(!isNull(Xrm.Utility)&&!isNull(Xrm.Utility.getGlobalContext))return Xrm.Utility.getGlobalContext();if(!isNull(Xrm.Page)&&!isNull(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 getClientUrl(){let e=getXrmContext().getClientUrl();return e.match(/\/$/)&&(e=e.substring(0,e.length-1)),e}function isRunningWithinPortals(){return!1}function isObject(e){return"object"==typeof e&&!!e&&!Array.isArray(e)&&"[object Date]"!==Object.prototype.toString.call(e)}function copyObject(e,t){let r={};for(let a in e)e.hasOwnProperty(a)&&!(null==t?void 0:t.includes(a))&&(isObject(e[a])?r[a]=copyObject(e[a]):Array.isArray(e[a])?r[a]=e[a].slice():r[a]=e[a]);return r}function copyRequest(e,t=[]){t.includes("signal")||t.push("signal");const r=copyObject(e,t);return r.signal=e.signal,r}function setFileChunk(e,t,r,a){const n=(a=a||0)+r>t.length?t.length%r:r;let i;i=t.slice(a,a+n),e.data=i,e.contentRange="bytes "+a+"-"+(a+n-1)+"/"+t.length}function convertToFileBuffer(e){return Buffer.from(e,"binary")}function toAbsoluteUrl(e,t){return`${e.config.dataApi.url}${removeLeadingSlash(t)}`}var ErrorHelper,init_Utility=__esm({"src/utils/Utility.ts"(){init_Crypto(),init_Regex(),downloadChunkSize=4194304}});function throwParameterError(e,t,r){throw new Error(r?`${e} requires a ${t} parameter to be of type ${r}.`:`${e} requires a ${t} parameter.`)}var _a,_b,_DWA,DWA,init_ErrorHelper=__esm({"src/helpers/ErrorHelper.ts"(){init_Regex(),ErrorHelper=class e{static handleErrorResponse(e){throw new Error(`Error: ${e.status}: ${e.message}`)}static parameterCheck(e,t,r,a){null!=e&&""!==e||throwParameterError(t,r,a)}static stringParameterCheck(e,t,r){"string"!=typeof e&&throwParameterError(t,r,"String")}static maxLengthStringParameterCheck(e,t,r,a){if(e&&e.length>a)throw new Error(`${r} has a ${a} character limit.`)}static arrayParameterCheck(e,t,r){e.constructor!==Array&&throwParameterError(t,r,"Array")}static stringOrArrayParameterCheck(e,t,r){e.constructor!==Array&&"string"!=typeof e&&throwParameterError(t,r,"String or Array")}static numberParameterCheck(e,t,r){if("number"!=typeof e){if("string"==typeof e&&e&&!isNaN(parseInt(e)))return;throwParameterError(t,r,"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(e,t){const r=new Error;return Object.keys(e).forEach((t=>{r[t]=e[t]})),t&&Object.keys(t).forEach((e=>{r[e]=t[e]})),r}static boolParameterCheck(e,t,r){"boolean"!=typeof e&&throwParameterError(t,r,"Boolean")}static guidParameterCheck(e,t,r){const a=extractUuid(e);return a||throwParameterError(t,r,"GUID String"),a}static keyParameterCheck(t,r,a){try{e.stringParameterCheck(t,r,a);const n=extractUuid(t);if(n)return n;const i=t.split(",");if(i.length)for(let e=0;e<i.length;e++)i[e]=i[e].trim().replace(/"/g,"'"),/^[\w\d\_]+\=(.+)$/i.exec(i[e])[0];return i.join(",")}catch(e){throwParameterError(r,a,"String representing GUID or Alternate Key")}}static callbackParameterCheck(e,t,r){"function"!=typeof e&&throwParameterError(t,r,"Function")}static throwBatchIncompatible(e,t){if(t)throw t=!1,new Error(e+" cannot be used in a BATCH request.")}static throwBatchNotStarted(e){if(!e)throw new Error("Batch operation has not been started. Please call a DynamicsWebApi.startBatch() function prior to calling DynamicsWebApi.executeBatch() to perform a batch request correctly.")}}}}),init_dwa=__esm({"src/dwa.ts"(){(_DWA=class{}).Prefer=((_b=class{static get(e){return`${_DWA.Prefer.IncludeAnnotations}="${e}"`}}).ReturnRepresentation="return=representation",_b.Annotations=((_a=class{}).AssociatedNavigationProperty="Microsoft.Dynamics.CRM.associatednavigationproperty",_a.LookupLogicalName="Microsoft.Dynamics.CRM.lookuplogicalname",_a.All="*",_a.FormattedValue="OData.Community.Display.V1.FormattedValue",_a.FetchXmlPagingCookie="Microsoft.Dynamics.CRM.fetchxmlpagingcookie",_a),_b.IncludeAnnotations="odata.include-annotations",_b),DWA=_DWA}});function dateReviver(e,t){if("string"==typeof t){const e=DATE_FORMAT_REGEX.exec(t);if(e)return new Date(Date.UTC(+e[1],+e[2]-1,+e[3],+e[4],+e[5],+e[6]))}return t}var init_dateReviver=__esm({"src/client/helpers/dateReviver.ts"(){init_Regex()}});function parseBatchHeaders(e){const t={position:0},r={};let a,n,i;do{if(i=t.position,n=readLine(e,t),!n)break;a=BATCH_RESPONSE_HEADERS_REGEX.exec(n),null!==a?r[a[1].toLowerCase()]=a[2]:t.position=i}while(n&&a);return r}function readLine(e,t){return readTo(e,t,LINE_ENDING_REGEX)}function readTo(e,t,r){const a=t.position||0,n=e.slice(a),i=r.exec(n);if(!i)return null;const o=a+i.index;return t.position=o+i[0].length,e.substring(a,o)}function getHttpStatus(e){const t=HTTP_STATUS_REGEX.exec(e);return{httpStatusString:t[0],httpStatus:parseInt(t[1]),httpStatusMessage:t[2].trim()}}function getPlainContent(e){HTTP_STATUS_REGEX.lastIndex=0;const t=TEXT_REGEX.exec(e.trim());return(null==t?void 0:t.length)?t[0]:void 0}function handlePlainContent(e,t,r){return handlePlainResponse(getPlainContent(e))}function handleEmptyContent(e,t,r){var a;if(void 0!==(null==(a=null==t?void 0:t[r])?void 0:a.valueIfEmpty))return t[r].valueIfEmpty;{const t=ODATA_ENTITYID_REGEX.exec(e);return extractUuidFromUrl(null==t?void 0:t[0])??void 0}}function processBatchPart(e,t,r){const{httpStatusString:a,httpStatus:n,httpStatusMessage:i}=getHttpStatus(e),o=e.substring(e.indexOf("{"),e.lastIndexOf("}")+1);if(!o)return CONTENT_TYPE_PLAIN_REGEX.test(e)?handlePlainContent(e,t,r):handleEmptyContent(e,t,r);const s=handleJsonResponse(o,t,r);if(n<400)return s;const c=parseBatchHeaders(e.substring(e.indexOf(a)+a.length+1,e.indexOf("{")));return ErrorHelper.handleHttpError(s,{status:n,statusText:i,statusMessage:i,headers:c})}function parseBatchResponse(e,t,r=0){const a=e.substring(0,e.search(LINE_ENDING_REGEX)),n=e.split(a);n.shift(),n.pop();let i=[];for(let e of n){if(-1===e.indexOf("--changesetresponse_")){i.push(processBatchPart(e,t,r++));continue}e=e.trim();const a=e.substring(e.search(LINE_ENDING_REGEX)+1).trim();i=i.concat(parseBatchResponse(a,t,r++))}return i}var init_parseBatchResponse=__esm({"src/client/helpers/parseBatchResponse.ts"(){init_ErrorHelper(),init_Regex(),init_parseResponse()}});function getFormattedKeyValue(e,t){let r=null;if(-1!==e.indexOf("@")){const a=e.split("@");switch(a[1]){case"odata.context":r="oDataContext";break;case"odata.count":r="oDataCount",t=null!=t?parseInt(t):0;break;case"odata.nextLink":r="oDataNextLink";break;case"odata.deltaLink":r="oDataDeltaLink";break;case DWA.Prefer.Annotations.FormattedValue:r=a[0]+"_Formatted";break;case DWA.Prefer.Annotations.AssociatedNavigationProperty:r=a[0]+"_NavigationProperty";break;case DWA.Prefer.Annotations.LookupLogicalName:r=a[0]+"_LogicalName"}}return[r,t]}function parseData(e,t){if(t){if(t.isRef&&null!=e["@odata.id"])return convertToReferenceObject(e);if(t.toCount)return getFormattedKeyValue("@odata.count",e["@odata.count"])[1]||0}for(const t in e){if(null!=e[t])if(Array.isArray(e[t]))for(var r=0;r<e[t].length;r++)e[t][r]=parseData(e[t][r]);else"object"==typeof e[t]&&parseData(e[t]);let a=getFormattedKeyValue(t,e[t]);if(a[0]&&(e[a[0]]=a[1]),-1!==t.indexOf("_x002e_")){const r=t.split("_x002e_");if(e.hasOwnProperty(r[0])){if("object"!=typeof e[r[0]]||"object"==typeof e[r[0]]&&!e[r[0]].hasOwnProperty("_dwaType"))throw new Error("The alias name of the linked entity must be unique!")}else e[r[0]]={_dwaType:"alias"};e[r[0]][r[1]]=e[t],a=getFormattedKeyValue(r[1],e[t]),a[0]&&(e[r[0]][a[0]]=a[1])}}return t&&t.hasOwnProperty("pageNumber")&&null!=e["@"+DWA.Prefer.Annotations.FetchXmlPagingCookie]&&(e.PagingInfo=getFetchXmlPagingCookie(e["@"+DWA.Prefer.Annotations.FetchXmlPagingCookie],t.pageNumber)),e}function base64ToString(e){return Buffer.from(e,"base64").toString("binary")}function parseFileResponse(e,t,r){let a=e;(null==r?void 0:r.hasOwnProperty("parse"))&&(a=JSON.parse(a).value,a=base64ToString(a));const n={value:a};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"]));const i=getHeader(t,"Location");return i&&(n.location=i),n}function isBatchResponse(e){return e.indexOf("--batchresponse_")>-1}function isFileResponse(e){return hasHeader(e,"Content-Disposition")}function isJsonResponse(e){const t=getHeader(e,"Content-Type");return 1==(null==t?void 0:t.startsWith("application/json"))}function handleBatchResponse(e,t){const r=parseBatchResponse(e,t);return(null==t?void 0:t[0].convertedToBatch)?r[0]:r}function handleFileResponse(e,t,r){return parseFileResponse(e,t,r[0])}function handleJsonResponse(e,t,r=0){return parseData(JSON.parse(e,dateReviver),t[r])}function handlePlainResponse(e){const t=Number(e);return isFinite(t)?t:e}function handleEmptyResponse(e,t){var r;if(void 0!==(null==(r=null==t?void 0:t[0])?void 0:r.valueIfEmpty))return t[0].valueIfEmpty;const a=getHeader(e,"OData-EntityId");if(a)return extractUuidFromUrl(a)??void 0;const n=getHeader(e,"Location");if(n){const t={location:n};return e["x-ms-chunk-size"]&&(t.chunkSize=parseInt(e["x-ms-chunk-size"])),e["x-ms-dyn-backgroundoperationid"]&&(t.backgroundOperationId=e["x-ms-dyn-backgroundoperationid"]),t}}function parseResponse(e,t,r){return e.length?isBatchResponse(e)?handleBatchResponse(e,r):isFileResponse(t)?handleFileResponse(e,t,r):isJsonResponse(t)?handleJsonResponse(e,r):handlePlainResponse(e):handleEmptyResponse(t,r)}var http,https,import_http_proxy_agent,import_https_proxy_agent,agents,getAgent,init_parseResponse=__esm({"src/client/helpers/parseResponse.ts"(){init_dwa(),init_Utility(),init_dateReviver(),init_Regex(),init_parseBatchResponse()}}),http_exports={};function executeRequest(e){return new Promise(((t,r)=>{_executeRequest(e,t,r)}))}function _executeRequest(e,t,r){var a;const n=e.data,i=e.headers,o=e.responseParams,s=e.abortSignal,c={};n&&(c["Content-Type"]=i["Content-Type"],c["Content-Length"]=n.length,delete i["Content-Type"]);for(let e in i)c[e]=i[e];const l=new URL(e.uri),p=(null==(a=l.protocol)?void 0:a.slice(0,-1))||"https",u="http"===p?http:https,E={hostname:l.hostname,port:l.port,path:l.pathname+l.search,method:e.method,timeout:e.timeout||0,headers:c,signal:s};if(!e.proxy&&process.env[`${p}_proxy`]&&(e.proxy={url:process.env[`${p}_proxy`]}),E.agent=getAgent(e,p),e.proxy){const t=new URL(e.proxy.url).host;t&&(c.host=t)}const _=u.request(E,(function(a){let n="";a.setEncoding("utf8"),a.on("data",(function(e){n+=e})),a.on("end",(function(){if(a.statusCode&&(a.statusCode>=200&&a.statusCode<300||304===a.statusCode)){let r={data:parseResponse(n,a.headers,o[e.requestId]),headers:a.headers,status:a.statusCode};t(r)}else{let t;try{var i=parseResponse(n,a.headers,o[e.requestId]);if(Array.isArray(i))return void r(i);t=i.hasOwnProperty("error")&&i.error?i.error:{message:i.Message}}catch(e){t=n.length>0?{message:n}:{message:"Unexpected Error"}}r(ErrorHelper.handleHttpError(t,{status:a.statusCode,statusText:"",statusMessage:a.statusMessage,headers:a.headers}))}}))}));E.timeout&&_.setTimeout(E.timeout,(function(){_.destroy()})),_.on("error",(function(e){r(e)})),n&&_.write(n),_.end()}__export(http_exports,{executeRequest:()=>executeRequest});var init_http=__esm({"src/client/http.ts"(){http=__toESM(require("http")),https=__toESM(require("https")),import_http_proxy_agent=__toESM(require("http-proxy-agent")),import_https_proxy_agent=__toESM(require("https-proxy-agent")),init_ErrorHelper(),init_parseResponse(),agents={},getAgent=(e,t)=>{const r="http"===t,a=e.proxy,n=a?a.url:t;if(!agents[n])if(a){const e=new URL(a.url),t=r?import_http_proxy_agent.default.HttpProxyAgent:import_https_proxy_agent.default.HttpsProxyAgent,i={host:e.hostname,port:e.port,protocol:e.protocol};a.auth?i.auth=a.auth.username+":"+a.auth.password:e.username&&e.password&&(i.auth=`${e.username}:${e.password}`),agents[n]=new t(i)}else{const e=r?http:https;agents[n]=new e.Agent({keepAlive:!0,maxSockets:1/0})}return agents[n]}}}),dynamics_web_api_exports={};__export(dynamics_web_api_exports,{DynamicsWebApi:()=>DynamicsWebApi}),module.exports=__toCommonJS(dynamics_web_api_exports),init_Utility(),init_ErrorHelper();var LIBRARY_NAME="DynamicsWebApi",FUNCTION_NAME=`${LIBRARY_NAME}.setConfig`,apiConfigs=["dataApi","searchApi","serviceApi"],getApiUrl=(e,t)=>{if(isRunningWithinPortals())return new URL("_api",global.window.location.origin).toString()+"/";{e||(e=getClientUrl());let r="api";return t.path&&(r+=`/${t.path}`),t.version&&(r+=`/v${t.version}`),new URL(r,e).toString()+"/"}},mergeSearchApiOptions=(e,t)=>{t&&(null!=t.escapeSpecialCharacters&&(ErrorHelper.boolParameterCheck(t.escapeSpecialCharacters,FUNCTION_NAME,"config.searchApi.options.escapeSpecialCharacters"),e.escapeSpecialCharacters=t.escapeSpecialCharacters),null!=t.enableResponseCompatibility&&(ErrorHelper.boolParameterCheck(t.enableResponseCompatibility,FUNCTION_NAME,"config.searchApi.options.enableResponseCompatibility"),e.enableSearchApiResponseCompatibility=t.enableResponseCompatibility))},mergeApiConfig=(e,t,r)=>{const a=e[t],n=null==r?void 0:r[t];(null==n?void 0:n.version)&&(ErrorHelper.stringParameterCheck(n.version,FUNCTION_NAME,`config.${t}.version`),a.version=n.version),(null==n?void 0:n.path)&&(ErrorHelper.stringParameterCheck(n.path,FUNCTION_NAME,`config.${t}.path`),a.path=n.path),"searchApi"===t&&mergeSearchApiOptions(a,null==n?void 0:n.options),a.url=getApiUrl(e.serverUrl,a)};function mergeConfig(e,t){(null==t?void 0:t.serverUrl)&&(ErrorHelper.stringParameterCheck(t.serverUrl,FUNCTION_NAME,"config.serverUrl"),e.serverUrl=t.serverUrl),apiConfigs.forEach((r=>{mergeApiConfig(e,r,t)})),(null==t?void 0:t.impersonate)&&(e.impersonate=ErrorHelper.guidParameterCheck(t.impersonate,FUNCTION_NAME,"config.impersonate")),(null==t?void 0:t.impersonateAAD)&&(e.impersonateAAD=ErrorHelper.guidParameterCheck(t.impersonateAAD,FUNCTION_NAME,"config.impersonateAAD")),(null==t?void 0:t.onTokenRefresh)&&(ErrorHelper.callbackParameterCheck(t.onTokenRefresh,FUNCTION_NAME,"config.onTokenRefresh"),e.onTokenRefresh=t.onTokenRefresh),(null==t?void 0:t.includeAnnotations)&&(ErrorHelper.stringParameterCheck(t.includeAnnotations,FUNCTION_NAME,"config.includeAnnotations"),e.includeAnnotations=t.includeAnnotations),(null==t?void 0:t.timeout)&&(ErrorHelper.numberParameterCheck(t.timeout,FUNCTION_NAME,"config.timeout"),e.timeout=t.timeout),(null==t?void 0:t.maxPageSize)&&(ErrorHelper.numberParameterCheck(t.maxPageSize,FUNCTION_NAME,"config.maxPageSize"),e.maxPageSize=t.maxPageSize),null!=(null==t?void 0:t.returnRepresentation)&&(ErrorHelper.boolParameterCheck(t.returnRepresentation,FUNCTION_NAME,"config.returnRepresentation"),e.returnRepresentation=t.returnRepresentation),null!=(null==t?void 0:t.useEntityNames)&&(ErrorHelper.boolParameterCheck(t.useEntityNames,FUNCTION_NAME,"config.useEntityNames"),e.useEntityNames=t.useEntityNames),(null==t?void 0:t.headers)&&(e.headers=t.headers),(null==t?void 0:t.proxy)&&(ErrorHelper.parameterCheck(t.proxy,FUNCTION_NAME,"config.proxy"),t.proxy.url&&(ErrorHelper.stringParameterCheck(t.proxy.url,FUNCTION_NAME,"config.proxy.url"),t.proxy.auth&&(ErrorHelper.parameterCheck(t.proxy.auth,FUNCTION_NAME,"config.proxy.auth"),ErrorHelper.stringParameterCheck(t.proxy.auth.username,FUNCTION_NAME,"config.proxy.auth.username"),ErrorHelper.stringParameterCheck(t.proxy.auth.password,FUNCTION_NAME,"config.proxy.auth.password"))),e.proxy=t.proxy)}function defaultConfig(){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:""}}}init_Utility(),init_Utility();var entityNames=null,setEntityNames=e=>{entityNames=e},findCollectionName=e=>{if(isNull(entityNames))return null;const t=entityNames[e];if(!t)for(const t in entityNames)if(entityNames[t]===e)return e;return t};async function executeRequest2(e){return(init_http(),__toCommonJS(http_exports)).executeRequest(e)}init_ErrorHelper(),init_ErrorHelper(),init_Regex(),init_Utility();var composeUrl=(e,t,r="",a="&")=>{var n,i,o;const s=[];if(e){if(e.navigationProperty){if(ErrorHelper.stringParameterCheck(e.navigationProperty,`DynamicsWebApi.${e.functionName}`,"request.navigationProperty"),r+="/"+e.navigationProperty,e.navigationPropertyKey){r+="("+ErrorHelper.keyParameterCheck(e.navigationPropertyKey,`DynamicsWebApi.${e.functionName}`,"request.navigationPropertyKey")+")"}"Attributes"===e.navigationProperty&&e.metadataAttributeType&&(ErrorHelper.stringParameterCheck(e.metadataAttributeType,`DynamicsWebApi.${e.functionName}`,"request.metadataAttributeType"),r+="/"+e.metadataAttributeType)}if((null==(n=e.select)?void 0:n.length)&&(ErrorHelper.arrayParameterCheck(e.select,`DynamicsWebApi.${e.functionName}`,"request.select"),"retrieve"==e.functionName&&1==e.select.length&&e.select[0].endsWith("/$ref")?r+="/"+e.select[0]:(e.select[0].startsWith("/")&&"retrieve"==e.functionName&&(null==e.navigationProperty?r+=e.select.shift():e.select.shift()),e.select.length&&s.push("$select="+e.select.join(",")))),e.filter){ErrorHelper.stringParameterCheck(e.filter,`DynamicsWebApi.${e.functionName}`,"request.filter");const t=safelyRemoveCurlyBracketsFromUrl(e.filter);s.push("$filter="+encodeURIComponent(t))}if(e.fieldName&&(ErrorHelper.stringParameterCheck(e.fieldName,`DynamicsWebApi.${e.functionName}`,"request.fieldName"),e.property||(e.property=e.fieldName),delete e.fieldName),e.property&&(ErrorHelper.stringParameterCheck(e.property,`DynamicsWebApi.${e.functionName}`,"request.property"),r+="/"+e.property),e.savedQuery&&s.push("savedQuery="+ErrorHelper.guidParameterCheck(e.savedQuery,`DynamicsWebApi.${e.functionName}`,"request.savedQuery")),e.userQuery&&s.push("userQuery="+ErrorHelper.guidParameterCheck(e.userQuery,`DynamicsWebApi.${e.functionName}`,"request.userQuery")),e.apply&&(ErrorHelper.stringParameterCheck(e.apply,`DynamicsWebApi.${e.functionName}`,"request.apply"),s.push("$apply="+e.apply)),e.count&&(ErrorHelper.boolParameterCheck(e.count,`DynamicsWebApi.${e.functionName}`,"request.count"),s.push("$count="+e.count)),e.top&&e.top>0&&(ErrorHelper.numberParameterCheck(e.top,`DynamicsWebApi.${e.functionName}`,"request.top"),s.push("$top="+e.top)),null!=e.orderBy&&e.orderBy.length&&(ErrorHelper.arrayParameterCheck(e.orderBy,`DynamicsWebApi.${e.functionName}`,"request.orderBy"),s.push("$orderby="+e.orderBy.join(","))),e.partitionId&&(ErrorHelper.stringParameterCheck(e.partitionId,`DynamicsWebApi.${e.functionName}`,"request.partitionId"),s.push("partitionid='"+e.partitionId+"'")),e.downloadSize&&(ErrorHelper.stringParameterCheck(e.downloadSize,`DynamicsWebApi.${e.functionName}`,"request.downloadSize"),s.push("size="+e.downloadSize)),e.tag&&(ErrorHelper.stringParameterCheck(e.tag,`DynamicsWebApi.${e.functionName}`,"request.tag"),s.push("tag="+encodeURIComponent(e.tag))),(null==(i=e.queryParams)?void 0:i.length)&&(ErrorHelper.arrayParameterCheck(e.queryParams,`DynamicsWebApi.${e.functionName}`,"request.queryParams"),s.push(e.queryParams.join("&"))),e.fileName&&(ErrorHelper.stringParameterCheck(e.fileName,`DynamicsWebApi.${e.functionName}`,"request.fileName"),s.push("x-ms-file-name="+e.fileName)),e.data&&ErrorHelper.parameterCheck(e.data,`DynamicsWebApi.${e.functionName}`,"request.data"),e.isBatch&&ErrorHelper.boolParameterCheck(e.isBatch,`DynamicsWebApi.${e.functionName}`,"request.isBatch"),e.fetchXml&&(ErrorHelper.stringParameterCheck(e.fetchXml,`DynamicsWebApi.${e.functionName}`,"request.fetchXml"),s.push("fetchXml="+encodeURIComponent(e.fetchXml))),isNull(e.inChangeSet)||ErrorHelper.boolParameterCheck(e.inChangeSet,`DynamicsWebApi.${e.functionName}`,"request.inChangeSet"),e.isBatch&&isNull(e.inChangeSet)&&(e.inChangeSet=!0),e.timeout&&ErrorHelper.numberParameterCheck(e.timeout,`DynamicsWebApi.${e.functionName}`,"request.timeout"),null==(o=e.expand)?void 0:o.length)if(ErrorHelper.stringOrArrayParameterCheck(e.expand,`DynamicsWebApi.${e.functionName}`,"request.expand"),"string"==typeof e.expand)s.push("$expand="+e.expand);else{const r=[];for(const{property:a,...n}of e.expand){if(!a)continue;const i={functionName:`${e.functionName} $expand`,...n};let o=composeUrl(i,t,"",";");o&&(o=`(${o})`),r.push(a+o)}r.length&&s.push("$expand="+r.join(","))}}return s.length?("&"===a&&(r+="?"),r+s.join(a)):r};init_ErrorHelper(),init_ErrorHelper(),init_Regex();var composePreferHeader=(e,t)=>{var r,a;const n=`DynamicsWebApi.${e.functionName}`,i={respondAsync:e.respondAsync,backgroundOperationCallbackUrl:e.backgroundOperationCallbackUrl??(null==t?void 0:t.backgroundOperationCallbackUrl),returnRepresentation:e.returnRepresentation??(null==t?void 0:t.returnRepresentation),includeAnnotations:e.includeAnnotations??(null==t?void 0:t.includeAnnotations),maxPageSize:e.maxPageSize??(null==t?void 0:t.maxPageSize),trackChanges:e.trackChanges,continueOnError:e.continueOnError},o=new Set;if(null==(r=e.prefer)?void 0:r.length){ErrorHelper.stringOrArrayParameterCheck(e.prefer,n,"request.prefer");const t="string"==typeof e.prefer?e.prefer.split(","):e.prefer;for(const e of t){const t=e.trim();t.includes("respond-async")?i.respondAsync=!0:t.startsWith("odata.callback")?i.backgroundOperationCallbackUrl=extractPreferCallbackUrl(t):"return=representation"===t?i.returnRepresentation=!0:t.includes("odata.include-annotations=")?i.includeAnnotations=removeDoubleQuotes(t.replace("odata.include-annotations=","")):t.startsWith("odata.maxpagesize=")?i.maxPageSize=Number(removeDoubleQuotes(t.replace("odata.maxpagesize=","")))||0:t.includes("odata.track-changes")?i.trackChanges=!0:t.includes("odata.continue-on-error")?i.continueOnError=!0:o.add(t)}}for(const e in i){const t=preferOptionsFactory[e];t&&i[e]&&(null==(a=t.validator)||a.call(t,i[e],n,`request.${e}`),t.condition(i[e],i)&&o.add(t.formatter(i[e],i)))}return Array.from(o).join(",")},preferOptionsFactory={respondAsync:{validator:ErrorHelper.boolParameterCheck,condition:e=>!!e,formatter:()=>"respond-async"},backgroundOperationCallbackUrl:{validator:ErrorHelper.stringParameterCheck,condition:(e,t)=>e&&t.respondAsync,formatter:e=>`odata.callback;url="${e}"`},returnRepresentation:{validator:ErrorHelper.boolParameterCheck,condition:e=>!!e,formatter:()=>"return=representation"},includeAnnotations:{validator:ErrorHelper.stringParameterCheck,condition:e=>!!e,formatter:e=>`odata.include-annotations="${e}"`},maxPageSize:{validator:(e,t)=>e>0?ErrorHelper.numberParameterCheck(e,t,"request.maxPageSize"):void 0,condition:e=>e>0,formatter:e=>`odata.maxpagesize=${e}`},trackChanges:{validator:ErrorHelper.boolParameterCheck,condition:e=>!!e,formatter:()=>"odata.track-changes"},continueOnError:{validator:ErrorHelper.boolParameterCheck,condition:e=>!!e,formatter:()=>"odata.continue-on-error"}},composeHeaders=(e,t)=>{const r={...t.headers,...e.userHeaders},a=composePreferHeader(e,t);if(a.length&&(r.Prefer=a),"$metadata"===e.collection&&(r.Accept="application/xml"),e.transferMode&&(r["x-ms-transfer-mode"]=e.transferMode),null!=e.ifmatch&&null!=e.ifnonematch)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&&(ErrorHelper.stringParameterCheck(e.ifmatch,`DynamicsWebApi.${e.functionName}`,"request.ifmatch"),r["If-Match"]=e.ifmatch),e.ifnonematch&&(ErrorHelper.stringParameterCheck(e.ifnonematch,`DynamicsWebApi.${e.functionName}`,"request.ifnonematch"),r["If-None-Match"]=e.ifnonematch),e.impersonate&&(ErrorHelper.stringParameterCheck(e.impersonate,`DynamicsWebApi.${e.functionName}`,"request.impersonate"),r.MSCRMCallerID=ErrorHelper.guidParameterCheck(e.impersonate,`DynamicsWebApi.${e.functionName}`,"request.impersonate")),e.impersonateAAD&&(ErrorHelper.stringParameterCheck(e.impersonateAAD,`DynamicsWebApi.${e.functionName}`,"request.impersonateAAD"),r.CallerObjectId=ErrorHelper.guidParameterCheck(e.impersonateAAD,`DynamicsWebApi.${e.functionName}`,"request.impersonateAAD")),e.token&&(ErrorHelper.stringParameterCheck(e.token,`DynamicsWebApi.${e.functionName}`,"request.token"),r.Authorization="Bearer "+e.token),e.duplicateDetection&&(ErrorHelper.boolParameterCheck(e.duplicateDetection,`DynamicsWebApi.${e.functionName}`,"request.duplicateDetection"),r["MSCRM.SuppressDuplicateDetection"]="false"),e.bypassCustomPluginExecution&&(ErrorHelper.boolParameterCheck(e.bypassCustomPluginExecution,`DynamicsWebApi.${e.functionName}`,"request.bypassCustomPluginExecution"),r["MSCRM.BypassCustomPluginExecution"]="true"),e.noCache&&(ErrorHelper.boolParameterCheck(e.noCache,`DynamicsWebApi.${e.functionName}`,"request.noCache"),r["Cache-Control"]="no-cache"),e.mergeLabels&&(ErrorHelper.boolParameterCheck(e.mergeLabels,`DynamicsWebApi.${e.functionName}`,"request.mergeLabels"),r["MSCRM.MergeLabels"]="true"),e.contentId&&(ErrorHelper.stringParameterCheck(e.contentId,`DynamicsWebApi.${e.functionName}`,"request.contentId"),e.contentId.startsWith("$")||(r["Content-ID"]=e.contentId)),e.contentRange&&(ErrorHelper.stringParameterCheck(e.contentRange,`DynamicsWebApi.${e.functionName}`,"request.contentRange"),r["Content-Range"]=e.contentRange),e.range&&(ErrorHelper.stringParameterCheck(e.range,`DynamicsWebApi.${e.functionName}`,"request.range"),r.Range=e.range),r};init_ErrorHelper();var composeRequest=(e,t)=>(e.path="",e.functionName=e.functionName||"",e.url?(ErrorHelper.stringParameterCheck(e.url,`DynamicsWebApi.${e.functionName}`,"request.url"),e.path=e.url.replace(t.dataApi.url,"")):(e._isUnboundRequest||e.contentId||e.collection||ErrorHelper.parameterCheck(e.collection,`DynamicsWebApi.${e.functionName}`,"request.collection"),e.contentId&&(ErrorHelper.stringParameterCheck(e.contentId,`DynamicsWebApi.${e.functionName}`,"request.contentId"),e.contentId.startsWith("$")&&(e.path=e.contentId)),null!=e.collection&&(ErrorHelper.stringParameterCheck(e.collection,`DynamicsWebApi.${e.functionName}`,"request.collection"),e.path+=e.path?`/${e.collection}`:e.collection,e.key&&(e.key=ErrorHelper.keyParameterCheck(e.key,`DynamicsWebApi.${e.functionName}`,"request.key"),e.path+=`(${e.key})`)),e.addPath&&(e.path&&(e.path+="/"),e.path+=e.addPath),e.path=composeUrl(e,t,e.path)),e.hasOwnProperty("async")&&null!=e.async?ErrorHelper.boolParameterCheck(e.async,`DynamicsWebApi.${e.functionName}`,"request.async"):e.async=!0,e.headers=composeHeaders(e,t),e);init_Regex(),init_Utility(),init_dateReviver(),init_parseBatchResponse(),init_parseResponse();var processData=(e,t)=>{if(!e)return null;if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint32Array)return e;return escapeUnicodeSymbols(JSON.stringify(e,((e,r)=>{if("@odata.id"===e||e.endsWith("@odata.bind"))"string"!=typeof r||r.startsWith("$")||(r=removeCurlyBracketsFromUuid(r),t.useEntityNames&&(r=(e=>{const t=SEARCH_FOR_ENTITY_NAME_REGEX.exec(e);if(t&&t.length>2){const r=findCollectionName(t[1]);if(!isNull(r))return e.replace(SEARCH_FOR_ENTITY_NAME_REGEX,`${r}$2`)}return e})(r)),"@odata.id"!==e&&(r=((e,r)=>(r.startsWith(t.dataApi.url)||(e.endsWith("@odata.bind")?r.startsWith("/")||(r=`/${r}`):r=`${t.dataApi.url}${removeLeadingSlash(r)}`),r))(e,r)));else if(e.startsWith("oData")||e.endsWith("_Formatted")||e.endsWith("_NavigationProperty")||e.endsWith("_LogicalName"))return;return r})))},setStandardHeaders=(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);init_Utility();var _config,_isBatch,_batchRequestId,convertToBatch=(e,t,r)=>{const a=`dwa_batch_${generateUUID()}`,n=[];let i=null,o=1e5;e.forEach((e=>{var s;e.functionName="executeBatch",!1===(null==r?void 0:r.inChangeSet)&&(e.inChangeSet=!1);const c="GET"!==e.method&&!!e.inChangeSet;if(!c&&i&&(n.push(`\r\n--${i}--`),i=null,o=1e5),i||(n.push(`\r\n--${a}`),c&&(i=`changeset_${generateUUID()}`,n.push("Content-Type: multipart/mixed;boundary="+i))),c&&n.push(`\r\n--${i}`),n.push("Content-Type: application/http"),n.push("Content-Transfer-Encoding: binary"),c){const t=e.headers.hasOwnProperty("Content-ID")?e.headers["Content-ID"]:++o;n.push(`Content-ID: ${t}`)}(null==(s=e.path)?void 0:s.startsWith("$"))?n.push(`\r\n${e.method} ${e.path} HTTP/1.1`):n.push(`\r\n${e.method} ${t.dataApi.url}${e.path} HTTP/1.1`),"GET"===e.method?n.push("Accept: application/json"):n.push("Content-Type: application/json"),e.headers&&((e,t)=>{for(const r in e)"Authorization"!==r&&"Content-ID"!==r&&t.push(`${r}: ${e[r]}`)})(e.headers,n),e.data&&n.push(`\r\n${processData(e.data,t)}`)})),i&&n.push(`\r\n--${i}--`),n.push(`\r\n--${a}--\r\n`);const s=setStandardHeaders(null==r?void 0:r.userHeaders,null==r?void 0:r.data);return s["Content-Type"]=`multipart/mixed;boundary=${a}`,{headers:s,body:n.join("\r\n")}},_addResponseParams=(e,t)=>{_responseParseParams[e]?_responseParseParams[e].push(t):_responseParseParams[e]=[t]},_addRequestToBatchCollection=(e,t)=>{_batchRequestCollection[e]?_batchRequestCollection[e].push(t):_batchRequestCollection[e]=[t]},_clearRequestData=e=>{delete _responseParseParams[e],_batchRequestCollection.hasOwnProperty(e)&&delete _batchRequestCollection[e]},_runRequest=async(e,t)=>{try{const r=await sendRequest(e,t);return _clearRequestData(e.requestId),r}catch(t){throw _clearRequestData(e.requestId),t}finally{_clearRequestData(e.requestId)}},_batchRequestCollection={},_responseParseParams={},_nameExceptions=["$metadata","EntityDefinitions","RelationshipDefinitions","GlobalOptionSetDefinitions","ManagedPropertyDefinitions","query","suggest","autocomplete"],_isEntityNameException=e=>_nameExceptions.indexOf(e)>-1,_getCollectionNames=async(e,t)=>{if(!isNull(entityNames))return findCollectionName(e)||e;const r=composeRequest({method:"GET",collection:"EntityDefinitions",select:["EntitySetName","LogicalName"],noCache:!0,functionName:"retrieveMultiple"},t),a=await _runRequest(r,t);setEntityNames({});for(let e=0;e<a.data.value.length;e++)entityNames[a.data.value[e].LogicalName]=a.data.value[e].EntitySetName;return findCollectionName(e)||e},_checkCollectionName=async(e,t)=>{if(!e||_isEntityNameException(e))return e;if(e=e.toLowerCase(),!t.useEntityNames)return e;try{return await _getCollectionNames(e,t)}catch(e){throw new Error("Unable to fetch Collection Names. Error: "+e.message)}},sendRequest=async(e,t)=>{var r;e.headers=e.headers||{},e.responseParameters=e.responseParameters||{},e.requestId=e.requestId||generateUUID(),_addResponseParams(e.requestId,e.responseParameters);let a=null;const n=null==(r=e.responseParameters)?void 0:r.convertedToBatch;if("$batch"!==e.path||n)a=n?e.data:processData(e.data,t),n||!1===e.includeDefaultDataverseHeaders||(e.headers=setStandardHeaders(e.headers,e.data));else{const r=_batchRequestCollection[e.requestId];if(!r)throw ErrorHelper.batchIsEmpty();const n=convertToBatch(r,t,e);a=n.body,e.headers={...n.headers,...e.headers},delete _batchRequestCollection[e.requestId]}t.impersonate&&!e.headers.MSCRMCallerID&&(e.headers.MSCRMCallerID=t.impersonate),t.impersonateAAD&&!e.headers.CallerObjectId&&(e.headers.CallerObjectId=t.impersonateAAD);let i=null;if(t.onTokenRefresh&&(!e.headers||e.headers&&!e.headers.Authorization)&&(i=await t.onTokenRefresh(),!i))throw new Error("Token is empty. Request is aborted.");i&&(e.headers.Authorization="Bearer "+(i.hasOwnProperty("accessToken")?i.accessToken:i)),isRunningWithinPortals()&&(e.headers.__RequestVerificationToken=await global.window.shell.getTokenDeferred());const o=e.apiConfig?e.apiConfig.url:t.dataApi.url;return await executeRequest2({method:e.method,uri:o.toString()+e.path,data:a,proxy:t.proxy,isAsync:e.async,headers:e.headers,requestId:e.requestId,abortSignal:e.signal,responseParams:_responseParseParams,timeout:e.timeout||t.timeout})},makeRequest=async(e,t)=>{if(e.responseParameters=e.responseParameters||{},e.userHeaders=e.headers,delete e.headers,!e.isBatch){const r=await _checkCollectionName(e.collection,t);if(e.collection=r,composeRequest(e,t),e.responseParameters.convertedToBatch=!1,e.path.length>2e3){const r=convertToBatch([e],t);e.headers.Authorization&&(r.headers.Authorization=e.headers.Authorization),e.method="POST",e.path="$batch",e.data=r.body,e.headers={...r.headers,...e.userHeaders},e.responseParameters.convertedToBatch=!0}return _runRequest(e,t)}composeRequest(e,t),_addResponseParams(e.requestId,e.responseParameters),_addRequestToBatchCollection(e.requestId,e)},getCollectionName=e=>findCollectionName(e),DataverseClient=class{constructor(e){__privateAdd(this,_config,defaultConfig()),__privateAdd(this,_isBatch,!1),__privateAdd(this,_batchRequestId,null),this.setConfig=e=>mergeConfig(__privateGet(this,_config),e),this.makeRequest=e=>(e.isBatch=__privateGet(this,_isBatch),__privateGet(this,_batchRequestId)&&(e.requestId=__privateGet(this,_batchRequestId)),makeRequest(e,__privateGet(this,_config))),mergeConfig(__privateGet(this,_config),e)}get batchRequestId(){return __privateGet(this,_batchRequestId)}set batchRequestId(e){__privateSet(this,_batchRequestId,e)}get config(){return __privateGet(this,_config)}get isBatch(){return __privateGet(this,_isBatch)}set isBatch(e){__privateSet(this,_isBatch,e)}};_config=new WeakMap,_isBatch=new WeakMap,_batchRequestId=new WeakMap,init_ErrorHelper(),init_Utility();var FUNCTION_NAME2="associate",REQUEST_NAME=`${LIBRARY_NAME}.${FUNCTION_NAME2}`,associate=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME,"request"),ErrorHelper.parameterCheck(e.relatedKey,REQUEST_NAME,"request.relatedKey"),ErrorHelper.stringParameterCheck(e.relationshipName,REQUEST_NAME,"request.relationshipName");let r=e.relatedKey,a=e.relatedKey;(!t.isBatch||t.isBatch&&!e.relatedKey.startsWith("$"))&&(ErrorHelper.stringParameterCheck(e.relatedCollection,REQUEST_NAME,"request.relatedCollection"),r=ErrorHelper.keyParameterCheck(e.relatedKey,REQUEST_NAME,"request.relatedKey"),a=`${t.config.dataApi.url}${e.relatedCollection}(${r})`);let n=copyRequest(e,["primaryKey"]);n.method="POST",n.functionName=FUNCTION_NAME2,n.navigationProperty=e.relationshipName+"/$ref",n.key=e.primaryKey,n.data={"@odata.id":a},await t.makeRequest(n)};init_ErrorHelper(),init_Utility();var FUNCTION_NAME3="associateSingleValued",REQUEST_NAME2=`${LIBRARY_NAME}.${FUNCTION_NAME3}`,associateSingleValued=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME2,"request"),ErrorHelper.parameterCheck(e.relatedKey,REQUEST_NAME2,"request.relatedKey"),ErrorHelper.stringParameterCheck(e.navigationProperty,REQUEST_NAME2,"request.navigationProperty");let r=e.relatedKey,a=e.relatedKey;(!t.isBatch||t.isBatch&&!e.relatedKey.startsWith("$"))&&(ErrorHelper.stringParameterCheck(e.relatedCollection,REQUEST_NAME2,"request.relatedCollection"),r=ErrorHelper.keyParameterCheck(e.relatedKey,REQUEST_NAME2,"request.relatedKey"),a=`${t.config.dataApi.url}${e.relatedCollection}(${r})`);let n=copyRequest(e,["primaryKey"]);n.method="PUT",n.functionName=FUNCTION_NAME3,n.navigationProperty+="/$ref",n.key=e.primaryKey,n.data={"@odata.id":a},await t.makeRequest(n)};init_ErrorHelper(),init_Utility();var FUNCTION_NAME4="callAction",REQUEST_NAME3=`${LIBRARY_NAME}.${FUNCTION_NAME4}`,callAction=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME3,"request"),ErrorHelper.stringParameterCheck(e.actionName,REQUEST_NAME3,"request.actionName");const r=copyRequest(e,["action"]);r.method="POST",r.functionName=FUNCTION_NAME4,r.addPath=e.actionName,r._isUnboundRequest=!r.collection,r.data=e.action;const a=await t.makeRequest(r);return null==a?void 0:a.data};init_ErrorHelper(),init_Utility();var FUNCTION_NAME5="callFunction",REQUEST_NAME4=`${LIBRARY_NAME}.${FUNCTION_NAME5}`,callFunction=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME4,"request");const r="string"!=typeof e,a=r?(n=e).name||n.functionName:e;var n;const i=r?"request.name":"name",o=r?copyObject(e,["name"]):{functionName:a};ErrorHelper.stringParameterCheck(a,REQUEST_NAME4,i);const s=buildFunctionParameters(o.parameters);o.method="GET",o.addPath=a+s.key,o.queryParams=s.queryParams,o._isUnboundRequest=!o.collection,o.functionName=FUNCTION_NAME5;const c=await t.makeRequest(o);return null==c?void 0:c.data};init_ErrorHelper(),init_Utility();var FUNCTION_NAME6="create",REQUEST_NAME5=`${LIBRARY_NAME}.${FUNCTION_NAME6}`,create=async(e,t)=>{let r;ErrorHelper.parameterCheck(e,REQUEST_NAME5,"request"),e.functionName?r=e:(r=copyRequest(e),r.functionName=FUNCTION_NAME6),r.method="POST";const a=await t.makeRequest(r);return null==a?void 0:a.data};init_ErrorHelper(),init_Utility();var FUNCTION_NAME7="count",REQUEST_NAME6=`${LIBRARY_NAME}.${FUNCTION_NAME7}`,count=async(e,t)=>{var r;ErrorHelper.parameterCheck(e,REQUEST_NAME6,"request");const a=copyRequest(e);a.method="GET",a.functionName=FUNCTION_NAME7,(null==(r=a.filter)?void 0:r.length)?a.count=!0:a.navigationProperty="$count",a.responseParameters={toCount:a.count};const n=await t.makeRequest(a);return null==n?void 0:n.data};init_ErrorHelper(),init_ErrorHelper(),init_ErrorHelper(),init_Utility();var FUNCTION_NAME8="retrieveMultiple",REQUEST_NAME7=`${LIBRARY_NAME}.${FUNCTION_NAME8}`,retrieveMultiple=async(e,t,r)=>{let a;ErrorHelper.parameterCheck(e,REQUEST_NAME7,"request"),e.functionName?a=e:(a=copyRequest(e),a.functionName=FUNCTION_NAME8),a.method="GET",r&&(ErrorHelper.stringParameterCheck(r,REQUEST_NAME7,"nextPageLink"),a.url=r);const n=await t.makeRequest(a);return null==n?void 0:n.data},FUNCTION_NAME9="retrieveAll",REQUEST_NAME8=`${LIBRARY_NAME}.${FUNCTION_NAME9}`,retrieveAllRequest=async(e,t,r,a=[])=>{const n=await retrieveMultiple(e,t,r);a=a.concat(n.value);const i=n.oDataNextLink;if(i)return retrieveAllRequest(e,t,i,a);const o={value:a};return n.oDataDeltaLink&&(o["@odata.deltaLink"]=n.oDataDeltaLink,o.oDataDeltaLink=n.oDataDeltaLink),o},retrieveAll=(e,t)=>(ErrorHelper.throwBatchIncompatible(REQUEST_NAME8,t.isBatch),retrieveAllRequest(e,t)),FUNCTION_NAME10="countAll",REQUEST_NAME9=`${LIBRARY_NAME}.${FUNCTION_NAME10}`,countAll=async(e,t)=>{ErrorHelper.throwBatchIncompatible(REQUEST_NAME9,t.isBatch),ErrorHelper.parameterCheck(e,REQUEST_NAME9,"request");return(await retrieveAllRequest(e,t)).value.length};init_ErrorHelper(),init_Utility();var FUNCTION_NAME11="disassociate",REQUEST_NAME10=`${LIBRARY_NAME}.${FUNCTION_NAME11}`,disassociate=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME10,"request");let r=copyRequest(e);r.method="DELETE",r.functionName=FUNCTION_NAME11,ErrorHelper.stringParameterCheck(e.relationshipName,REQUEST_NAME10,"request.relationshipName");const a=ErrorHelper.keyParameterCheck(e.primaryKey,REQUEST_NAME10,"request.primaryKey"),n=ErrorHelper.keyParameterCheck(e.relatedKey,REQUEST_NAME10,"request.relatedId");r.key=a,r.navigationProperty=`${e.relationshipName}(${n})/$ref`,await t.makeRequest(r)};init_ErrorHelper(),init_Utility();var FUNCTION_NAME12="disassociateSingleValued",REQUEST_NAME11=`${LIBRARY_NAME}.${FUNCTION_NAME12}`,disassociateSingleValued=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME11,"request");let r=copyRequest(e);r.method="DELETE",r.functionName=FUNCTION_NAME12,ErrorHelper.stringParameterCheck(e.navigationProperty,REQUEST_NAME11,"request.navigationProperty");const a=ErrorHelper.keyParameterCheck(e.primaryKey,REQUEST_NAME11,"request.primaryKey");r.navigationProperty+="/$ref",r.key=a,await t.makeRequest(r)};init_ErrorHelper(),init_Utility();var FUNCTION_NAME13="retrieve",REQUEST_NAME12=`${LIBRARY_NAME}.${FUNCTION_NAME13}`,retrieve=async(e,t)=>{var r;let a;ErrorHelper.parameterCheck(e,REQUEST_NAME12,"request"),e.functionName?a=e:(a=copyRequest(e),a.functionName=FUNCTION_NAME13),a.method="GET",a.responseParameters={isRef:1===(null==(r=a.select)?void 0:r.length)&&a.select[0].endsWith("/$ref")};const n=await t.makeRequest(a);return null==n?void 0:n.data};init_ErrorHelper(),init_Regex(),init_Utility();var FUNCTION_NAME14="fetch",REQUEST_NAME13=`${LIBRARY_NAME}.${FUNCTION_NAME14}`,fetchXml=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME13,"request");const r=copyRequest(e);if(r.method="GET",r.functionName=FUNCTION_NAME14,ErrorHelper.stringParameterCheck(r.fetchXml,REQUEST_NAME13,"request.fetchXml"),r.fetchXml&&!FETCH_XML_TOP_REGEX.test(r.fetchXml)){let e="";FETCH_XML_PAGE_REGEX.test(r.fetchXml)||(r.pageNumber=r.pageNumber||1,ErrorHelper.numberParameterCheck(r.pageNumber,REQUEST_NAME13,"request.pageNumber"),e=`$1 page="${r.pageNumber}"`),null!=r.pagingCookie&&(ErrorHelper.stringParameterCheck(r.pagingCookie,REQUEST_NAME13,"request.pagingCookie"),e+=` paging-cookie="${r.pagingCookie}"`),e&&(r.fetchXml=r.fetchXml.replace(FETCH_XML_REPLACE_REGEX,e))}r.responseParameters={pageNumber:r.pageNumber};const a=await t.makeRequest(r);return null==a?void 0:a.data};init_ErrorHelper();var FUNCTION_NAME15="fetchAll",REQUEST_NAME14=`${LIBRARY_NAME}.${FUNCTION_NAME15}`,executeFetchXmlAll=async(e,t,r=[])=>{const a=await fetchXml(e,t);return r=r.concat(a.value),a.PagingInfo?(e.pageNumber=a.PagingInfo.nextPage,e.pagingCookie=a.PagingInfo.cookie,executeFetchXmlAll(e,t,r)):{value:r}},fetchXmlAll=async(e,t)=>(ErrorHelper.parameterCheck(e,REQUEST_NAME14,"request"),ErrorHelper.throwBatchIncompatible(REQUEST_NAME14,t.isBatch),executeFetchXmlAll(e,t));init_ErrorHelper(),init_Regex(),init_Utility();var FUNCTION_NAME16="update",REQUEST_NAME15=`${LIBRARY_NAME}.${FUNCTION_NAME16}`,update=async(e,t)=>{let r;ErrorHelper.parameterCheck(e,REQUEST_NAME15,"request"),e.functionName?r=e:(r=copyRequest(e),r.functionName=FUNCTION_NAME16),r.method??(r.method=getUpdateMethod(r.collection)),r.responseParameters={valueIfEmpty:!0},r.ifmatch??(r.ifmatch="*");const a=r.ifmatch;try{const e=await t.makeRequest(r);return null==e?void 0:e.data}catch(e){if(a&&412===e.status)return!1;throw e}};init_ErrorHelper(),init_Utility();var FUNCTION_NAME17="updateSingleProperty",REQUEST_NAME16=`${LIBRARY_NAME}.${FUNCTION_NAME17}`,updateSingleProperty=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME16,"request"),ErrorHelper.parameterCheck(e.fieldValuePair,REQUEST_NAME16,"request.fieldValuePair");var r=Object.keys(e.fieldValuePair)[0],a=e.fieldValuePair[r];const n=copyRequest(e);n.navigationProperty=r,n.data={value:a},n.functionName=FUNCTION_NAME17,n.method="PUT",delete n.fieldValuePair;const i=await t.makeRequest(n);return null==i?void 0:i.data};init_ErrorHelper(),init_Utility();var FUNCTION_NAME18="upsert",REQUEST_NAME17=`${LIBRARY_NAME}.${FUNCTION_NAME18}`,upsert=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME17,"request");const r=copyRequest(e);r.method="PATCH",r.functionName=FUNCTION_NAME18;const a=r.ifnonematch,n=r.ifmatch;try{const e=await t.makeRequest(r);return null==e?void 0:e.data}catch(e){if(a&&412===e.status)return null;if(n&&404===e.status)return null;throw e}};init_ErrorHelper(),init_Utility();var FUNCTION_NAME19="deleteRecord",REQUEST_NAME18=`${LIBRARY_NAME}.${FUNCTION_NAME19}`,deleteRecord=async(e,t)=>{let r;ErrorHelper.parameterCheck(e,REQUEST_NAME18,"request"),e.functionName?r=e:(r=copyRequest(e),r.functionName=FUNCTION_NAME19),r.method="DELETE",r.responseParameters={valueIfEmpty:!0};const a=r.ifmatch;try{const e=await t.makeRequest(r);return null==e?void 0:e.data}catch(e){if(a&&412===e.status)return!1;throw e}};init_ErrorHelper(),init_Utility();var FUNCTION_NAME20="uploadFile",REQUEST_NAME19=`${LIBRARY_NAME}.${FUNCTION_NAME20}`,_uploadFileChunk=async(e,t,r,a,n=0)=>{if(setFileChunk(e,r,a,n),await t.makeRequest(e),(n+=a)<=r.length)return _uploadFileChunk(e,t,r,a,n)},uploadFile=async(e,t)=>{ErrorHelper.throwBatchIncompatible(REQUEST_NAME19,t.isBatch),ErrorHelper.parameterCheck(e,REQUEST_NAME19,"request");const r=copyRequest(e,["data"]);r.method="PATCH",r.functionName=FUNCTION_NAME20,r.transferMode="chunked";const a=await t.makeRequest(r);return r.url=null==a?void 0:a.data.location,delete r.transferMode,delete r.fieldName,delete r.property,delete r.fileName,_uploadFileChunk(r,t,e.data,null==a?void 0:a.data.chunkSize)};init_ErrorHelper(),init_Utility();var FUNCTION_NAME21="downloadFile",REQUEST_NAME20=`${LIBRARY_NAME}.${FUNCTION_NAME21}`,downloadFileChunk=async(e,t,r=0,a="")=>{e.range="bytes="+r+"-"+(r+downloadChunkSize-1),e.downloadSize="full";const n=await t.makeRequest(e);return e.url=null==n?void 0:n.data.location,a+=null==n?void 0:n.data.value,(r+=downloadChunkSize)<=(null==n?void 0:n.data.fileSize)?downloadFileChunk(e,t,r,a):{fileName:null==n?void 0:n.data.fileName,fileSize:null==n?void 0:n.data.fileSize,data:convertToFileBuffer(a)}},downloadFile=(e,t)=>{ErrorHelper.throwBatchIncompatible(REQUEST_NAME20,t.isBatch),ErrorHelper.parameterCheck(e,REQUEST_NAME20,"request");const r=copyRequest(e);return r.method="GET",r.functionName=FUNCTION_NAME21,r.responseParameters={parse:!0},downloadFileChunk(r,t)};init_Utility(),init_ErrorHelper();var FUNCTION_NAME22="executeBatch",REQUEST_NAME21=`${LIBRARY_NAME}.${FUNCTION_NAME22}`;async function executeBatch(e,t){ErrorHelper.throwBatchNotStarted(t.isBatch);const r=e?copyRequest(e):{};r.collection="$batch",r.method="POST",r.functionName=REQUEST_NAME21,r.requestId=t.batchRequestId,t.batchRequestId=null,t.isBatch=!1;const a=await t.makeRequest(r);return null==a?void 0:a.data}function startBatch(e){e.isBatch=!0,e.batchRequestId=generateUUID()}init_ErrorHelper(),init_Utility();var FUNCTION_NAME23="createEntity",REQUEST_NAME22=`${LIBRARY_NAME}.${FUNCTION_NAME23}`,createEntity=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME22,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME22,"request.data");const r=copyRequest(e);return r.collection="EntityDefinitions",r.functionName=FUNCTION_NAME23,create(r,t)};init_ErrorHelper(),init_Utility();var FUNCTION_NAME24="updateEntity",REQUEST_NAME23=`${LIBRARY_NAME}.${FUNCTION_NAME24}`,updateEntity=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME23,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME23,"request.data");const r=copyRequest(e);return r.collection="EntityDefinitions",r.functionName=FUNCTION_NAME24,r.key=r.data.MetadataId,r.method="PUT",await update(r,t)};init_ErrorHelper(),init_Utility();var FUNCTION_NAME25="retrieveEntity",REQUEST_NAME24=`${LIBRARY_NAME}.${FUNCTION_NAME25}`,retrieveEntity=async(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME24,"request"),ErrorHelper.keyParameterCheck(e.key,REQUEST_NAME24,"request.key");const r=copyRequest(e);return r.collection="EntityDefinitions",r.functionName="retrieveEntity",await retrieve(r,t)};init_Utility();var FUNCTION_NAME26="retrieveEntities",retrieveEntities=(e,t)=>{const r=t?copyRequest(t):{};return r.collection="EntityDefinitions",r.functionName=FUNCTION_NAME26,retrieveMultiple(r,e)};init_Utility(),init_ErrorHelper();var FUNCTION_NAME27="createAttribute",REQUEST_NAME25=`${LIBRARY_NAME}.${FUNCTION_NAME27}`,createAttribute=(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME25,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME25,"request.data"),ErrorHelper.keyParameterCheck(e.entityKey,REQUEST_NAME25,"request.entityKey");const r=copyRequest(e);return r.collection="EntityDefinitions",r.functionName=FUNCTION_NAME27,r.navigationProperty="Attributes",r.key=e.entityKey,create(r,t)};init_Utility(),init_ErrorHelper();var FUNCTION_NAME28="updateAttribute",REQUEST_NAME26=`${LIBRARY_NAME}.${FUNCTION_NAME28}`,updateAttribute=(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME26,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME26,"request.data"),ErrorHelper.keyParameterCheck(e.entityKey,REQUEST_NAME26,"request.entityKey"),ErrorHelper.guidParameterCheck(e.data.MetadataId,REQUEST_NAME26,"request.data.MetadataId");const r=copyRequest(e);return r.collection="EntityDefinitions",r.functionName=FUNCTION_NAME28,r.navigationProperty="Attributes",r.navigationPropertyKey=e.data.MetadataId,r.metadataAttributeType=e.castType,r.key=e.entityKey,r.method="PUT",update(r,t)};init_Utility(),init_ErrorHelper();var FUNCTION_NAME29="retrieveAttributes",REQUEST_NAME27=`${LIBRARY_NAME}.${FUNCTION_NAME29}`,retrieveAttributes=(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME27,"request"),ErrorHelper.keyParameterCheck(e.entityKey,REQUEST_NAME27,"request.entityKey"),e.castType&&ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME27,"request.castType");const r=copyRequest(e);return r.collection="EntityDefinitions",r.functionName=FUNCTION_NAME29,r.navigationProperty="Attributes",r.key=e.entityKey,r.metadataAttributeType=e.castType,retrieveMultiple(r,t)};init_Utility(),init_ErrorHelper();var FUNCTION_NAME30="retrieveAttributes",REQUEST_NAME28=`${LIBRARY_NAME}.${FUNCTION_NAME30}`,retrieveAttribute=(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME28,"request"),ErrorHelper.keyParameterCheck(e.entityKey,REQUEST_NAME28,"request.entityKey"),ErrorHelper.keyParameterCheck(e.attributeKey,REQUEST_NAME28,"request.attributeKey"),e.castType&&ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME28,"request.castType");const r=copyRequest(e);return r.collection="EntityDefinitions",r.navigationProperty="Attributes",r.navigationPropertyKey=e.attributeKey,r.metadataAttributeType=e.castType,r.key=e.entityKey,r.functionName=FUNCTION_NAME30,retrieve(r,t)};init_Utility(),init_ErrorHelper();var FUNCTION_NAME31="createRelationship",REQUEST_NAME29=`${LIBRARY_NAME}.${FUNCTION_NAME31}`,createRelationship=(e,t)=>{ErrorHelper.parameterCheck(e,REQUEST_NAME29,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME29,"request.data");const r=copyRequest(e);return r.collection="RelationshipDefinitions",r.functionName=FUNCTION_NAME31,create(r,t)};init_Utility(),init_ErrorHelper();var FUNCTION_NAME32="updateRelationship",REQUEST_NAME30=`${LIBRARY_NAME}.${FUNCTION_NAME32}`;function updateRelationship(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME30,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME30,"request.data"),ErrorHelper.guidParameterCheck(e.data.MetadataId,REQUEST_NAME30,"request.data.MetadataId"),e.castType&&ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME30,"request.castType");const r=copyRequest(e);return r.collection="RelationshipDefinitions",r.key=e.data.MetadataId,r.navigationProperty=e.castType,r.functionName=FUNCTION_NAME32,r.method="PUT",update(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME33="deleteRelationship",REQUEST_NAME31=`${LIBRARY_NAME}.${FUNCTION_NAME33}`;async function deleteRelationship(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME31,"request"),ErrorHelper.keyParameterCheck(e.key,REQUEST_NAME31,"request.key");const r=copyRequest(e);return r.collection="RelationshipDefinitions",r.functionName=FUNCTION_NAME33,deleteRecord(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME34="retrieveRelationships",REQUEST_NAME32=`DynamicsWebApi.${FUNCTION_NAME34}`;async function retrieveRelationships(e,t){const r=e?copyRequest(e):{};return r.collection="RelationshipDefinitions",r.functionName=FUNCTION_NAME34,e&&e.castType&&(ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME32,"request.castType"),r.navigationProperty=e.castType),retrieveMultiple(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME35="retrieveRelationship",REQUEST_NAME33=`DynamicsWebApi.${FUNCTION_NAME35}`;async function retrieveRelationship(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME33,"request"),ErrorHelper.keyParameterCheck(e.key,REQUEST_NAME33,"request.key"),e.castType&&ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME33,"request.castType");const r=copyRequest(e);return r.collection="RelationshipDefinitions",r.navigationProperty=e.castType,r.functionName=FUNCTION_NAME35,retrieve(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME36="createGlobalOptionSet",REQUEST_NAME34=`DynamicsWebApi.${FUNCTION_NAME36}`;async function createGlobalOptionSet(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME34,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME34,"request.data");const r=copyRequest(e);return r.collection="GlobalOptionSetDefinitions",r.functionName=FUNCTION_NAME36,create(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME37="updateGlobalOptionSet",REQUEST_NAME35=`DynamicsWebApi.${FUNCTION_NAME37}`;async function updateGlobalOptionSet(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME35,"request"),ErrorHelper.parameterCheck(e.data,REQUEST_NAME35,"request.data"),ErrorHelper.guidParameterCheck(e.data.MetadataId,REQUEST_NAME35,"request.data.MetadataId"),e.castType&&ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME35,"request.castType");const r=copyRequest(e);return r.collection="GlobalOptionSetDefinitions",r.key=e.data.MetadataId,r.functionName=FUNCTION_NAME37,r.method="PUT",update(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME38="deleteGlobalOptionSet",REQUEST_NAME36=`DynamicsWebApi.${FUNCTION_NAME38}`;async function deleteGlobalOptionSet(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME36,"request");const r=copyRequest(e);return r.collection="GlobalOptionSetDefinitions",r.functionName=FUNCTION_NAME38,deleteRecord(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME39="retrieveGlobalOptionSet",REQUEST_NAME37=`DynamicsWebApi.${FUNCTION_NAME39}`;async function retrieveGlobalOptionSet(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME37,"request"),e.castType&&ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME37,"request.castType");const r=copyRequest(e);return r.collection="GlobalOptionSetDefinitions",r.navigationProperty=e.castType,r.functionName=FUNCTION_NAME39,retrieve(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME40="retrieveGlobalOptionSets",REQUEST_NAME38=`DynamicsWebApi.${FUNCTION_NAME40}`;async function retrieveGlobalOptionSets(e,t){const r=e?copyRequest(e):{};return r.collection="GlobalOptionSetDefinitions",r.functionName=FUNCTION_NAME40,(null==e?void 0:e.castType)&&(ErrorHelper.stringParameterCheck(e.castType,REQUEST_NAME38,"request.castType"),r.navigationProperty=e.castType),retrieveMultiple(r,t)}init_Utility(),init_ErrorHelper();var FUNCTION_NAME41="retrieveCsdlMetadata",REQUEST_NAME39=`DynamicsWebApi.${FUNCTION_NAME41}`;async function retrieveCsdlMetadata(e,t){const r=e?copyRequest(e):{};r.collection="$metadata",r.functionName=FUNCTION_NAME41,(null==e?void 0:e.addAnnotations)&&(ErrorHelper.boolParameterCheck(e.addAnnotations,REQUEST_NAME39,"request.addAnnotations"),r.includeAnnotations="*");const a=await t.makeRequest(r);return null==a?void 0:a.data}function convertSearchQuery(e,t,r){var a;if(!e)return e;if(!0===(null==r?void 0:r.escapeSpecialCharacters)&&(e.search=escapeSearchSpecialCharacters(e.search)),(null==(a=e.entities)?void 0:a.length)&&(e.entities=convertEntitiesProperty(e.entities,null==r?void 0:r.version)),"query"===t)convertQuery(e,null==r?void 0:r.version);else convertSuggestOrAutocompleteQuery(e,null==r?void 0:r.version);return e}function convertEntitiesProperty(e,t="1.0"){if(!e)return e;if("string"==typeof e){if("1.0"!==t)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.")}const r=e.map((e=>"1.0"===t?(e=>"string"==typeof e?e:e.name)(e):(e=>"string"==typeof e?{name:e}:e)(e)));return"1.0"!==t?JSON.stringify(r):r}function convertQuery(e,t="1.0"){var r;"1.0"===t?(e=>{if(null!=e.count&&(null==e.returnTotalRecordCount&&(e.returnTotalRecordCount=e.count),delete e.count),e.options){if("string"==typeof e.options)try{e.options=JSON.parse(e.options,searchOptionsReviver)}catch{throw new Error("The 'query.options' property must be a valid JSON string.")}e.searchMode||(e.searchMode=e.options.searchMode),e.searchType||(e.searchType="lucene"===e.options.queryType?"full":e.options.queryType),delete e.options}for(const t of specialProperties)if(e[t]&&"string"==typeof e[t])try{e[t]=JSON.parse(e[t])}catch{throw new Error(`The 'query.${t}' property must be a valid JSON string.`)}})(e):(null!=(r=e).returnTotalRecordCount&&(null==r.count&&(r.count=r.returnTotalRecordCount),delete r.returnTotalRecordCount),(r.searchMode||r.searchType)&&("string"!=typeof r.options&&(r.options||(r.options={}),r.options.searchMode||(r.options.searchMode=r.searchMode),r.options.queryType||(r.options.queryType="full"===r.searchType?"lucene":r.searchType)),delete r.searchMode,delete r.searchType),r.orderBy&&"string"!=typeof r.orderBy&&(r.orderby=JSON.stringify(r.orderBy),delete r.orderBy),r.facets&&"string"!=typeof r.facets&&(r.facets=JSON.stringify(r.facets)),r.options&&"string"!=typeof r.options&&(r.options=JSON.stringify(convertOptionKeysToLowerCase(r.options))))}function convertSuggestOrAutocompleteQuery(e,t="1.0"){var r;"1.0"===t?(e=>{if(null!=e.fuzzy&&(null==e.useFuzzy&&(e.useFuzzy=e.fuzzy),delete e.fuzzy),delete e.options,e.orderBy&&"string"==typeof e.orderBy)try{e.orderBy=JSON.parse(e.orderBy)}catch{throw new Error("The 'query.orderBy' property must be a valid JSON string.")}})(e):(null!=(r=e).useFuzzy&&(null==r.fuzzy&&(r.fuzzy=r.useFuzzy),delete r.useFuzzy),r.orderBy&&"string"!=typeof r.orderBy&&(r.orderby=JSON.stringify(r.orderBy),delete r.orderBy),r.options&&"string"!=typeof r.options&&(r.options=JSON.stringify(convertOptionKeysToLowerCase(r.options))))}function convertOptionKeysToLowerCase(e){const t={};for(const r in e)t[r.toLowerCase()]=e[r];return t}function searchOptionsReviver(e,t){switch(e){case"searchmode":this.searchMode=t;break;case"querytype":this.queryType=t;break;default:return t}}init_Utility(),init_ErrorHelper(),init_Regex();var specialProperties=["orderBy","facets"];function parseQueryResponse(e,t){if(!e)return e;return"2.0"===(null==t?void 0:t.version)?(()=>{const r=JSON.parse(e.response,dateReviver),a={...e,response:r};return t.enableSearchApiResponseCompatibility&&(a.value=r.Value,a.facets=r.Facets,a.totalrecordcount=r.Count,a.querycontext=r.QueryContext),a})():(()=>{const r={...e};return t.enableSearchApiResponseCompatibility&&(r.response={Count:e.totalrecordcount,Value:e.value,Facets:e.facets,QueryContext:e.querycontext,Error:null}),r})()}var FUNCTION_NAME42="query",REQUEST_NAME40=`${LIBRARY_NAME}.${FUNCTION_NAME42}`;async function query(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME40,"request");const r="string"!=typeof e,a=r?"request.query.search":"term",n=r?copyObject(e):{query:{search:e}};ErrorHelper.parameterCheck(n.query,REQUEST_NAME40,"request.query"),ErrorHelper.stringParameterCheck(n.query.search,REQUEST_NAME40,a),ErrorHelper.maxLengthStringParameterCheck(n.query.search,REQUEST_NAME40,a,100),n.collection="query",n.functionName=FUNCTION_NAME42,n.method="POST",n.data=convertSearchQuery(n.query,FUNCTION_NAME42,t.config.searchApi),n.apiConfig=t.config.searchApi,delete n.query;return parseQueryResponse((await t.makeRequest(n)).data,t.config.searchApi)}function parseSuggestResponse(e,t){if(!e)return e;return"2.0"===(null==t?void 0:t.version)?(()=>{var r;const a=JSON.parse(e.response,dateReviver);t.enableSearchApiResponseCompatibility&&(null==(r=a.Value)||r.forEach((e=>{e.document=e.Document,e.text=e.Text})));const n={...e,response:a};return t.enableSearchApiResponseCompatibility&&(n.value=a.Value,n.querycontext=a.QueryContext),n})():(()=>{var r;t.enableSearchApiResponseCompatibility&&(null==(r=e.value)||r.forEach((e=>{e.Document=e.document,e.Text=e.text})));const a={...e};return t.enableSearchApiResponseCompatibility&&(a.response={Value:e.value,QueryContext:e.querycontext,Error:null}),a})()}init_Utility(),init_ErrorHelper();var FUNCTION_NAME43="suggest",REQUEST_NAME41=`${LIBRARY_NAME}.${FUNCTION_NAME43}`;async function suggest(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME41,"request");const r="string"!=typeof e,a=r?"request.query.search":"term",n=r?copyObject(e):{query:{search:e}};ErrorHelper.parameterCheck(n.query,REQUEST_NAME41,"request.query"),ErrorHelper.stringParameterCheck(n.query.search,REQUEST_NAME41,a),ErrorHelper.maxLengthStringParameterCheck(n.query.search,REQUEST_NAME41,a,100),n.functionName=n.collection=FUNCTION_NAME43,n.method="POST",n.data=convertSearchQuery(n.query,FUNCTION_NAME43,t.config.searchApi),n.apiConfig=t.config.searchApi,delete n.query;return parseSuggestResponse((await t.makeRequest(n)).data,t.config.searchApi)}function parseAutocompleteResponse(e,t){if(!e)return e;return"2.0"===(null==t?void 0:t.version)?(()=>{const r=JSON.parse(e.response,dateReviver),a={...e,response:r};return t.enableSearchApiResponseCompatibility&&(a.value=r.Value,a.querycontext=r.QueryContext),a})():(()=>{const r={...e};return t.enableSearchApiResponseCompatibility&&(r.response={Value:e.value,QueryContext:e.querycontext,Error:null}),r})()}init_Utility(),init_ErrorHelper();var FUNCTION_NAME44="autocomplete",REQUEST_NAME42=`${LIBRARY_NAME}.${FUNCTION_NAME44}`;async function autocomplete(e,t){ErrorHelper.parameterCheck(e,REQUEST_NAME42,"request");const r="string"!=typeof e,a=r?"request.query.search":"term",n=r?copyObject(e):{query:{search:e}};r&&ErrorHelper.parameterCheck(n.query,REQUEST_NAME42,"request.query"),ErrorHelper.stringParameterCheck(n.query.search,REQUEST_NAME42,a),ErrorHelper.maxLengthStringParameterCheck(n.query.search,REQUEST_NAME42,a,100),n.functionName=n.collection=FUNCTION_NAME44,n.method="POST",n.data=convertSearchQuery(n.query,FUNCTION_NAME44,t.config.searchApi),n.apiConfig=t.config.searchApi,delete n.query;return parseAutocompleteResponse((await t.makeRequest(n)).data,t.config.searchApi)}init_ErrorHelper();var FUNCTION_NAME45="getBackgroundOperationStatus",REQUEST_NAME43=`${LIBRARY_NAME}.${FUNCTION_NAME45}`;async function getBackgroundOperationStatus(e,t){ErrorHelper.throwBatchIncompatible(REQUEST_NAME43,t.isBatch),ErrorHelper.keyParameterCheck(e,REQUEST_NAME43,"backgroundOperationId");const r={method:"GET",addPath:`backgroundoperation/${e}`,functionName:FUNCTION_NAME45,apiConfig:t.config.serviceApi,includeDefaultDataverseHeaders:!1,headers:{"Content-Type":"application/json"},_isUnboundRequest:!0},a=await t.makeRequest(r);return null==a?void 0:a.data}init_ErrorHelper();var _client,FUNCTION_NAME46="cancelBackgroundOperation",REQUEST_NAME44=`${LIBRARY_NAME}.${FUNCTION_NAME46}`;async function cancelBackgroundOperation(e,t){ErrorHelper.throwBatchIncompatible(REQUEST_NAME44,t.isBatch),ErrorHelper.keyParameterCheck(e,REQUEST_NAME44,"backgroundOperationId");const r={method:"DELETE",addPath:`backgroundoperation/${e}`,functionName:FUNCTION_NAME46,apiConfig:t.config.serviceApi,includeDefaultDataverseHeaders:!1,headers:{"Content-Type":"application/json"},_isUnboundRequest:!0},a=await t.makeRequest(r);return null==a?void 0:a.data}init_Utility();var _DynamicsWebApi=class e{constructor(t){__privateAdd(this,_client),this.setConfig=e=>__privateGet(this,_client).setConfig(e),this.create=async e=>create(e,__privateGet(this,_client)),this.retrieve=async e=>retrieve(e,__privateGet(this,_client)),this.update=async e=>update(e,__privateGet(this,_client)),this.updateSingleProperty=async e=>updateSingleProperty(e,__privateGet(this,_client)),this.deleteRecord=async e=>deleteRecord(e,__privateGet(this,_client)),this.upsert=async e=>upsert(e,__privateGet(this,_client)),this.uploadFile=async e=>uploadFile(e,__privateGet(this,_client)),this.downloadFile=e=>downloadFile(e,__privateGet(this,_client)),this.retrieveMultiple=async(e,t)=>retrieveMultiple(e,__privateGet(this,_client),t),this.retrieveAll=e=>retrieveAll(e,__privateGet(this,_client)),this.count=async e=>count(e,__privateGet(this,_client)),this.countAll=async e=>countAll(e,__privateGet(this,_client)),this.fetch=async e=>fetchXml(e,__privateGet(this,_client)),this.fetchAll=async e=>fetchXmlAll(e,__privateGet(this,_client)),this.associate=async e=>associate(e,__privateGet(this,_client)),this.disassociate=async e=>disassociate(e,__privateGet(this,_client)),this.associateSingleValued=async e=>associateSingleValued(e,__privateGet(this,_client)),this.disassociateSingleValued=async e=>disassociateSingleValued(e,__privateGet(this,_client)),this.callFunction=async e=>callFunction(e,__privateGet(this,_client)),this.callAction=async e=>callAction(e,__privateGet(this,_client)),this.createEntity=e=>createEntity(e,__privateGet(this,_client)),this.updateEntity=e=>updateEntity(e,__privateGet(this,_client)),this.retrieveEntity=e=>retrieveEntity(e,__privateGet(this,_client)),this.retrieveEntities=e=>retrieveEntities(__privateGet(this,_client),e),this.createAttribute=e=>createAttribute(e,__privateGet(this,_client)),this.updateAttribute=e=>updateAttribute(e,__privateGet(this,_client)),this.retrieveAttributes=e=>retrieveAttributes(e,__privateGet(this,_client)),this.retrieveAttribute=e=>retrieveAttribute(e,__privateGet(this,_client)),this.createRelationship=e=>createRelationship(e,__privateGet(this,_client)),this.updateRelationship=e=>updateRelationship(e,__privateGet(this,_client)),this.deleteRelationship=e=>deleteRelationship(e,__privateGet(this,_client)),this.retrieveRelationships=e=>retrieveRelationships(e,__privateGet(this,_client)),this.retrieveRelationship=e=>retrieveRelationship(e,__privateGet(this,_client)),this.createGlobalOptionSet=e=>createGlobalOptionSet(e,__privateGet(this,_client)),this.updateGlobalOptionSet=e=>updateGlobalOptionSet(e,__privateGet(this,_client)),this.deleteGlobalOptionSet=e=>deleteGlobalOptionSet(e,__privateGet(this,_client)),this.retrieveGlobalOptionSet=e=>retrieveGlobalOptionSet(e,__privateGet(this,_client)),this.retrieveGlobalOptionSets=e=>retrieveGlobalOptionSets(e,__privateGet(this,_client)),this.retrieveCsdlMetadata=async e=>retrieveCsdlMetadata(e,__privateGet(this,_client)),this.search=async e=>query(e,__privateGet(this,_client)),this.query=async e=>query(e,__privateGet(this,_client)),this.suggest=async e=>suggest(e,__privateGet(this,_client)),this.autocomplete=async e=>autocomplete(e,__privateGet(this,_client)),this.getBackgroundOperationStatus=async e=>getBackgroundOperationStatus(e,__privateGet(this,_client)),this.cancelBackgroundOperation=async e=>cancelBackgroundOperation(e,__privateGet(this,_client)),this.startBatch=()=>startBatch(__privateGet(this,_client)),this.executeBatch=async e=>executeBatch(e,__privateGet(this,_client)),this.initializeInstance=t=>new e(t||__privateGet(this,_client).config),this.Utility={getCollectionName:e=>getCollectionName(e),toAbsoluteUrl:e=>toAbsoluteUrl(__privateGet(this,_client),e)},__privateSet(this,_client,new DataverseClient(t))}};_client=new WeakMap;var DynamicsWebApi=_DynamicsWebApi;
//# sourceMappingURL=/sm/4851a7a11a32eb1d99fbb8694fd31a6b4028ecc641a257c5e29d6d55209d18c1.map